自定义报表代码提交

This commit is contained in:
2022-10-21 11:24:58 +08:00
parent 53389fb6f3
commit 225cefd1a5
4 changed files with 96 additions and 3 deletions

View File

@@ -0,0 +1,85 @@
package com.njcn.common.utils;
import java.lang.reflect.Field;
import java.util.*;
/**
* Description:
* 接口文档访问地址http://serverIP:port/swagger-ui.html
* Date: 2022/10/21 9:32【需求编号】
*
* @author clam
* @version V1.0.0
*/
public class NjcnBeanUtil {
/**
* beancopy
* 大小写可以忽略
* 下划线 _ 被忽略
*
* @param source
* @param target
* @param <T>
* @return
*/
public static <T> T copyPropertiesIgnoreCase(Object source, Object target) {
Map<String, Field> sourceMap = CacheFieldMap.getFieldMap (source.getClass ( ));
CacheFieldMap.getFieldMap (target.getClass ( )).values ( ).forEach ((it) -> {
Field field = sourceMap.get (it.getName ( ).toLowerCase ( ).replace ("_", ""));
if (field != null) {
it.setAccessible (true);
field.setAccessible (true);
try {
//忽略null和空字符串
// if(field.get(source)!=null&& StringUtils.isBlank(field.get(source).toString()))
it.set (target, field.get (source));
} catch (IllegalAccessException e) {
e.printStackTrace ( );
}
}
});
System.out.println (target.toString ( ));
return (T) target;
}
private static class CacheFieldMap {
private static Map<String, Map<String, Field>> cacheMap = new HashMap<> ( );
private static Map<String, Field> getFieldMap(Class clazz) {
Map<String, Field> result = cacheMap.get (clazz.getName ( ));
if (result == null) {
synchronized (CacheFieldMap.class) {
if (result == null) {
Map<String, Field> fieldMap = new HashMap<> ( );
for (Field field : getAllFields (clazz)) {
fieldMap.put (field.getName ( ).toLowerCase ( ).replace ("_", ""), field);
}
cacheMap.put (clazz.getName ( ), fieldMap);
result = cacheMap.get (clazz.getName ( ));
}
}
}
return result;
}
}
/**
* 获取本类及其父类的字段属性
*
* @param clazz 当前类对象
* @return 字段数组
*/
public static Field[] getAllFields(Class<?> clazz) {
List<Field> fieldList = new ArrayList<> ( );
while (clazz != null) {
fieldList.addAll (new ArrayList<> (Arrays.asList (clazz.getDeclaredFields ( ))));
clazz = clazz.getSuperclass ( );
}
Field[] fields = new Field[fieldList.size ( )];
return fieldList.toArray (fields);
}
}

View File

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.harmonic.pojo.param.ReportSearchParam; import com.njcn.harmonic.pojo.param.ReportSearchParam;
import com.njcn.harmonic.pojo.po.ExcelRptTemp; import com.njcn.harmonic.pojo.po.ExcelRptTemp;
import com.njcn.harmonic.pojo.vo.ReportTemplateVO; import com.njcn.harmonic.pojo.vo.ReportTemplateVO;
import com.njcn.user.pojo.dto.DeptDTO;
import com.njcn.web.pojo.param.BaseParam; import com.njcn.web.pojo.param.BaseParam;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@@ -22,5 +23,5 @@ public interface ExcelRptTempMapper extends BaseMapper<ExcelRptTemp> {
List<ReportTemplateVO> getReportTemplateList(@Param("reportSearchParam")ReportSearchParam reportSearchParam); List<ReportTemplateVO> getReportTemplateList(@Param("reportSearchParam")ReportSearchParam reportSearchParam);
List<ReportTemplateVO> getReportTemplateByDept(@Param("deptId")String deptId); List<ReportTemplateVO> getReportTemplateByDept(@Param("list") List<DeptDTO> list);
} }

View File

@@ -46,6 +46,9 @@
LEFT JOIN sys_dept_temp b ON a.Id = b.temp_id LEFT JOIN sys_dept_temp b ON a.Id = b.temp_id
WHERE WHERE
a.state = 1 a.state = 1
and b.dept_id = #{deptId} and b.dept_id in
<foreach collection="list" index="index" item="item" separator="," open="(" close=")">
#{item.id}
</foreach>
</select> </select>
</mapper> </mapper>

View File

@@ -31,6 +31,8 @@ import com.njcn.influxdb.param.InfluxDBTableConstant;
import com.njcn.influxdb.utils.InfluxDbUtils; import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.system.api.DicDataFeignClient; import com.njcn.system.api.DicDataFeignClient;
import com.njcn.user.api.DeptFeignClient; import com.njcn.user.api.DeptFeignClient;
import com.njcn.user.pojo.dto.DeptDTO;
import com.njcn.web.utils.WebUtil;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
@@ -150,7 +152,9 @@ public class CustomReportServiceImpl implements CustomReportService {
@Override @Override
public List<ReportTemplateVO> getTemplateByDept(String id) { public List<ReportTemplateVO> getTemplateByDept(String id) {
return excelRptTempMapper.getReportTemplateByDept(id); //获取子孙部门,去重
List<DeptDTO> depts = deptFeignClient.getDeptDescendantIndexes(id, WebUtil.filterDeptType()).getData().stream().distinct().collect(Collectors.toList());
return excelRptTempMapper.getReportTemplateByDept(depts);
} }
@Override @Override