添加展示名称

This commit is contained in:
2024-08-19 23:25:47 +08:00
parent 799dd5f9a9
commit 0ecc9107a1
3 changed files with 153 additions and 9 deletions

View File

@@ -74,6 +74,55 @@ public class FreeMakerUtils {
cfg.setSharedVariable("where", new MyBatisTrim("where", "AND |OR "));
cfg.setSharedVariable("set", new MyBatisTrim("set", ","));
cfg.setSharedVariable("foreach", new MyBatisForeach());
cfg.setSharedVariable(
"underScore",
new TemplateMethodModel() {
@Override
public Object exec(List arguments) throws TemplateModelException {
if (arguments.size() != 1) {
throw new TemplateModelException("underScore need 1 argument");
}
Object o = arguments.get(0);
if (o instanceof String s) {
return cn.lihongjie.coal.common.StringUtils.toUnderScoreCase(
s);
} else {
throw new TemplateModelException(
"underScore argument must be string");
}
}
});
cfg.setSharedVariable(
"camelCase",
new TemplateMethodModel() {
@Override
public Object exec(List arguments) throws TemplateModelException {
if (arguments.size() != 1) {
throw new TemplateModelException("camelCase need 1 argument");
}
Object o = arguments.get(0);
if (o instanceof String s) {
return cn.lihongjie.coal.common.StringUtils.toCamelCase(
s);
} else {
throw new TemplateModelException(
"camelCase argument must be string");
}
}
});
}
private static String getString(Map params, String key) throws TemplateModelException {

View File

@@ -0,0 +1,77 @@
package cn.lihongjie.coal.common;
import java.util.*;
public class StringUtils {
public static List<String> toUnderScoreCase(List<String> list) {
if (list == null) {
return new ArrayList<>();
}
List<String> result = new ArrayList<>();
for (String s : list) {
result.add(toUnderScoreCase(s));
}
return result;
}
public static String toUnderScoreCase(String camelCase) {
if (camelCase == null || camelCase.length() == 0) {
return "";
}
StringBuilder result = new StringBuilder();
if (camelCase != null && camelCase.length() > 0) {
result.append(camelCase.substring(0, 1).toLowerCase());
for (int i = 1; i < camelCase.length(); i++) {
String s = camelCase.substring(i, i + 1);
if (s.equals(s.toUpperCase()) && !Character.isDigit(s.charAt(0))) {
result.append("_");
}
result.append(s.toLowerCase());
}
}
return result.toString();
}
public static String toCamelCase(String underScoreCase) {
if (underScoreCase == null || underScoreCase.length() == 0) {
return "";
}
StringBuilder result = new StringBuilder();
if (underScoreCase != null && underScoreCase.length() > 0) {
boolean flag = false;
for (int i = 0; i < underScoreCase.length(); i++) {
char s = underScoreCase.charAt(i);
if (s == '_') {
flag = true;
} else {
if (flag) {
result.append(Character.toUpperCase(s));
flag = false;
} else {
result.append(Character.toLowerCase(s));
}
}
}
}
return result.toString();
}
public static List<String> toCamelCase(List<String> list) {
if (list == null) {
return new ArrayList<>();
}
List<String> result = new ArrayList<>();
for (String s : list) {
result.add(toCamelCase(s));
}
return result;
}
}

View File

@@ -86,18 +86,36 @@ public class EmpSalaryService extends BaseService<EmpSalaryEntity, EmpSalaryRepo
public Object report(EmpSalaryReportRequest request) {
if (CollectionUtils.isEmpty(request.getFieldInfos())){
request.setFieldInfos(new ArrayList<>());
}
String sql =
FreeMakerUtils.render(
"""
select date_trunc(${timeDimension}, batchYearMonth) as time,
select to_char(date_trunc('${timeDimension}', batch_year_month), 'YYYY-MM-DD') as time,
array_agg(id) as ids
<#list reportField as field>
<#list reportFields as field>
<#if field?is_first> ,</#if>
${field}
${underScore(field)} as ${underScore(field)}
<#if field == 'employeeId'>, max(emp_name) as emp_name, max(emp_code) as emp_code </#if>
<#if field == 'departmentId'>, max(department_name) as department_name, max(department_code) as department_code </#if>
<#if field == 'jobPostId'>, max(job_post_name) as job_post_name, max(job_post_code) as job_post_code </#if>
<#if field == 'sex'>, max(sex_name) as sex_name </#if>
<#if field == 'nation'>, max(nation_name) as nation_name </#if>
<#if field == 'politicalStatus'>, max(political_status_name) as political_status_name </#if>
<#if field == 'marriage'>, max(marriage_name) as marriage_name </#if>
<#if field == 'education'>, max(education_name) as education_name </#if>
<#if field?has_next>,</#if>
</#list>
@@ -105,7 +123,7 @@ public class EmpSalaryService extends BaseService<EmpSalaryEntity, EmpSalaryRepo
<#if field?is_first> ,</#if>
${field.function}(${field.fieldName}) as ${field.fieldName}
${field.function}(${underScore(field.fieldName)}) as ${underScore(field.fieldName)}_${field.function}
<#if field?has_next>,</#if>
@@ -116,9 +134,9 @@ public class EmpSalaryService extends BaseService<EmpSalaryEntity, EmpSalaryRepo
where 1=1
<#if startTime??> and batchYearMonth >= :startTime </#if>
<#if startTime??> and batch_year_month >= :startTime </#if>
<#if endTime??> and batchYearMonth <= :endTime </#if>
<#if endTime??> and batch_year_month <= :endTime </#if>
<#if employeeIds??> and employee_id in :employeeIds </#if>
@@ -143,12 +161,12 @@ public class EmpSalaryService extends BaseService<EmpSalaryEntity, EmpSalaryRepo
group by 1, date_trunc(${timeDimension}, batchYearMonth)
<#list reportField as field>
group by 1, date_trunc('${timeDimension}', batch_year_month)
<#list reportFields as field>
<#if field?is_first> ,</#if>
${field}
${underScore(field)}
<#if field?has_next>,</#if>
</#list>