|
@@ -21,9 +21,7 @@ import com.rongwei.bsentity.domain.*;
|
|
|
import com.rongwei.bsentity.dto.PersistentDeptDto;
|
|
|
import com.rongwei.bsentity.dto.ZhcxPersistentManageDto;
|
|
|
import com.rongwei.bsentity.dto.ZhcxPersistentReportDto;
|
|
|
-import com.rongwei.bsentity.vo.FormDataVO;
|
|
|
-import com.rongwei.bsentity.vo.OrganizationVo;
|
|
|
-import com.rongwei.bsentity.vo.PersistentVo;
|
|
|
+import com.rongwei.bsentity.vo.*;
|
|
|
import com.rongwei.rwadmincommon.system.domain.SysOrganizationDo;
|
|
|
import com.rongwei.rwadmincommon.system.service.SysOrganizationService;
|
|
|
import com.rongwei.rwcommon.base.R;
|
|
@@ -83,6 +81,15 @@ public class ZhcxPersistentManageServiceImpl extends ServiceImpl<ZhcxPersistentM
|
|
|
private static final String DEPT_CODE = "0900";
|
|
|
private static final Color[] COLORS = {Color.fromArgb(205, 223, 242),
|
|
|
Color.fromArgb(249, 214, 194)};
|
|
|
+ private static final Map<String, Integer> defaultSortMap = new HashMap<>();
|
|
|
+ static {
|
|
|
+ defaultSortMap.put("钢构制造部", 2);
|
|
|
+ defaultSortMap.put("机电安装部", 3);
|
|
|
+ defaultSortMap.put("涂装管理部", 4);
|
|
|
+ defaultSortMap.put("调试管理部", 5);
|
|
|
+ defaultSortMap.put("重装项目部", 6);
|
|
|
+ defaultSortMap.put("供应链管理部", 7);
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public void wordExport(Map<String, Object> map, HttpServletResponse response) {
|
|
@@ -101,7 +108,7 @@ public class ZhcxPersistentManageServiceImpl extends ServiceImpl<ZhcxPersistentM
|
|
|
String period = (String) periodObj;
|
|
|
String year = (String) yearObj;
|
|
|
map.put("period", "第" + period + "期");
|
|
|
- List<ZhcxPersistentManageDo> list = zhcxPersistentManageDao.listData(map);
|
|
|
+ List<ZhcxPersistentManageVo> list = zhcxPersistentManageDao.listWzData(map);
|
|
|
if (list.size() == 0) {
|
|
|
throw new CustomException("当前周期暂无数据");
|
|
|
}
|
|
@@ -144,52 +151,53 @@ public class ZhcxPersistentManageServiceImpl extends ServiceImpl<ZhcxPersistentM
|
|
|
mainMap.put("leftDate",reStartDate);
|
|
|
mainMap.put("rightDate",reEndTime);
|
|
|
mainMap.put("year",year);
|
|
|
- Map<String, List<ZhcxPersistentManageDo>> collect =
|
|
|
+
|
|
|
+ // 1. 默认部门列表(ID → 名称)
|
|
|
+ Map<String, String> defaultDepts = new LinkedHashMap<>();
|
|
|
+ defaultDepts.put("1189640a3ef7407fa7c55e2a5903b356", "供应链管理部");
|
|
|
+ defaultDepts.put("7f6e7b9de969466fbea20aa86ab689c0", "重装项目部");
|
|
|
+ defaultDepts.put("4b1c0de60d84436696721b49d35b7f81", "调试管理部");
|
|
|
+ defaultDepts.put("13c7fc90d0b04eb199d7820e781866e8", "涂装管理部");
|
|
|
+ defaultDepts.put("25e37034d08f452682d957ab97154920", "机电安装部");
|
|
|
+ defaultDepts.put("060a72b5f74a4b44828d6149e296258d", "钢构制造部");
|
|
|
+
|
|
|
+ // 2. 实际数据分组
|
|
|
+ Map<String, List<ZhcxPersistentManageVo>> collect =
|
|
|
list.stream().collect(Collectors.groupingBy(ZhcxPersistentManageDo::getFirstorgid));
|
|
|
+
|
|
|
+ Set<String> handledDeptIds = new HashSet<>();
|
|
|
List<PersistentDeptDto> deptDtoList = new ArrayList<>();
|
|
|
- collect.forEach((k,v)->{
|
|
|
- long param1 = v.stream()
|
|
|
- .filter(item -> !"0f11e70cd21843ee998a1ce5279028eb".equals(item.getBelongorgid()))
|
|
|
- .count();
|
|
|
- long param2 = v.stream()
|
|
|
- .filter(item -> !"0f11e70cd21843ee998a1ce5279028eb".equals(item.getBelongorgid()))
|
|
|
- .filter(item -> "处罚".equals(item.getType()))
|
|
|
- .filter(item -> item.getAmount() != null && item.getAmount().compareTo(BigDecimal.ZERO) > 0)
|
|
|
- .count();
|
|
|
- long param3 = v.stream()
|
|
|
- .filter(item -> "0f11e70cd21843ee998a1ce5279028eb".equals(item.getBelongorgid()))
|
|
|
- .count();
|
|
|
- long param4 = v.stream()
|
|
|
- .filter(item -> "0f11e70cd21843ee998a1ce5279028eb".equals(item.getBelongorgid()))
|
|
|
- .filter(item -> "处罚".equals(item.getType()))
|
|
|
- .filter(item -> item.getAmount() != null && item.getAmount().compareTo(BigDecimal.ZERO) > 0)
|
|
|
- .count();
|
|
|
- BigDecimal param5 = v.stream()
|
|
|
- .filter(item -> "处罚".equals(item.getType()))
|
|
|
- .map(ZhcxPersistentManageDo::getAmount)
|
|
|
- .filter(Objects::nonNull)
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- PersistentDeptDto dto = new PersistentDeptDto();
|
|
|
- dto.setDutyDeptName(v.get(0).getFirstorgname());
|
|
|
- dto.setSelfDeptCount(param1);
|
|
|
- dto.setSelfDeptPunishCount(param2);
|
|
|
- dto.setProductionCount(param3);
|
|
|
- dto.setProductionPunishCount(param4);
|
|
|
- dto.setPunishmentAmount(param5);
|
|
|
- BigDecimal ratio = BigDecimal.ZERO;
|
|
|
- ratio = BigDecimal.valueOf(param2)
|
|
|
- .divide(BigDecimal.valueOf(param1), 4, RoundingMode.HALF_UP)
|
|
|
- .multiply(BigDecimal.valueOf(100))
|
|
|
- .setScale(2, RoundingMode.HALF_UP);
|
|
|
- dto.setRate(ratio);
|
|
|
- deptDtoList.add(dto);
|
|
|
- });
|
|
|
+
|
|
|
+ // 3. 先处理默认的6个
|
|
|
+ for (Map.Entry<String, String> entry : defaultDepts.entrySet()) {
|
|
|
+ String deptId = entry.getKey();
|
|
|
+ String deptName = entry.getValue();
|
|
|
+
|
|
|
+ List<ZhcxPersistentManageVo> v = collect.getOrDefault(deptId, Collections.emptyList());
|
|
|
+ deptDtoList.add(buildDeptDto(v, deptName));
|
|
|
+ handledDeptIds.add(deptId);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 再处理“额外的有数据的部门”
|
|
|
+ for (Map.Entry<String, List<ZhcxPersistentManageVo>> entry : collect.entrySet()) {
|
|
|
+ String deptId = entry.getKey();
|
|
|
+ if (handledDeptIds.contains(deptId)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ZhcxPersistentManageVo> v = entry.getValue();
|
|
|
+ String deptName = v.get(0).getFirstorgname(); // 假设firstorgname都一致
|
|
|
+ deptDtoList.add(buildDeptDto(v, deptName));
|
|
|
+ }
|
|
|
String deptNames = deptDtoList.stream()
|
|
|
.sorted(Comparator.comparing(PersistentDeptDto::getRate))
|
|
|
.limit(3)
|
|
|
.map(PersistentDeptDto::getDutyDeptName)
|
|
|
.collect(Collectors.joining("、"));
|
|
|
mainMap.put("checkDept",deptNames);
|
|
|
+ deptDtoList = deptDtoList.stream()
|
|
|
+ .sorted(Comparator.comparing(PersistentDeptDto::getSort, Comparator.nullsLast(Integer::compareTo)))
|
|
|
+ .collect(Collectors.toList());
|
|
|
if (deptDtoList.size() > 0) {
|
|
|
PersistentDeptDto totalDto = new PersistentDeptDto();
|
|
|
totalDto.setDutyDeptName("合计");
|
|
@@ -235,9 +243,9 @@ public class ZhcxPersistentManageServiceImpl extends ServiceImpl<ZhcxPersistentM
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- List<ZhcxPersistentManageDo> collect3 = list.stream().filter(item -> "0f11e70cd21843ee998a1ce5279028eb".equals(item.getBelongorgid())
|
|
|
+ List<ZhcxPersistentManageVo> collect3 = list.stream().filter(item -> "0f11e70cd21843ee998a1ce5279028eb".equals(item.getBelongorgid())
|
|
|
&& "处罚".equals(item.getType()) && item.getAmount() != null && item.getAmount().compareTo(BigDecimal.ZERO) > 0)
|
|
|
- .sorted(Comparator.comparing(ZhcxPersistentManageDo::getFirstorgid))
|
|
|
+ .sorted(Comparator.comparing(ZhcxPersistentManageVo::getFirstorgid))
|
|
|
.collect(Collectors.toList());
|
|
|
if(collect3.size() >0){
|
|
|
try {
|
|
@@ -254,40 +262,66 @@ public class ZhcxPersistentManageServiceImpl extends ServiceImpl<ZhcxPersistentM
|
|
|
}
|
|
|
try {
|
|
|
|
|
|
- Map<String, List<ZhcxPersistentManageDo>> collect1 = list.stream().filter(item -> !"0f11e70cd21843ee998a1ce5279028eb".equals(item.getBelongorgid())
|
|
|
+ Map<String, List<ZhcxPersistentManageVo>> collect1 = list.stream().filter(item -> !"0f11e70cd21843ee998a1ce5279028eb".equals(item.getBelongorgid())
|
|
|
&& "处罚".equals(item.getType())
|
|
|
&& item.getAmount() != null && item.getAmount().compareTo(BigDecimal.ZERO) > 0)
|
|
|
.collect(Collectors.groupingBy(ZhcxPersistentManageDo::getFirstorgid));
|
|
|
SysFileItemDo fileItemDo3 = sysFileItemService.getById("b0c5f7b64f9a43bd88711c3c62d870ab");
|
|
|
- collect1.forEach((k2,v2)->{
|
|
|
- Document doc3 = WordHelpUtils.getDoc(fileItemDo3.getFullpath());
|
|
|
- String firstorgname = v2.get(0).getFirstorgname();
|
|
|
+ List<DeptDocWrapperVo> docWrappers = new ArrayList<>();
|
|
|
+
|
|
|
+ // 默认 6 个
|
|
|
+ for (Map.Entry<String, String> entry : defaultDepts.entrySet()) {
|
|
|
+ String deptId = entry.getKey();
|
|
|
+ String deptName = entry.getValue();
|
|
|
+ List<ZhcxPersistentManageVo> v2 = collect1.getOrDefault(deptId, Collections.emptyList());
|
|
|
+ int sort = defaultSortMap.getOrDefault(deptName, 9999);
|
|
|
+ docWrappers.add(new DeptDocWrapperVo(deptId, deptName, v2, sort));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 额外的有数据的部门(排除已处理)
|
|
|
+ for (Map.Entry<String, List<ZhcxPersistentManageVo>> entry : collect1.entrySet()) {
|
|
|
+ String deptId = entry.getKey();
|
|
|
+ if (defaultDepts.containsKey(deptId)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ZhcxPersistentManageVo> v2 = entry.getValue();
|
|
|
+ String deptName = v2.get(0).getFirstorgname();
|
|
|
+ int sort = 9999; // 非默认的部门放后面
|
|
|
+
|
|
|
+ docWrappers.add(new DeptDocWrapperVo(deptId, deptName, v2, sort));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 排序
|
|
|
+ docWrappers.sort(Comparator.comparingInt(DeptDocWrapperVo::getSort));
|
|
|
+ for (DeptDocWrapperVo wrapper : docWrappers) {
|
|
|
try {
|
|
|
- long pcount2 = v2.stream()
|
|
|
- .filter(item -> "处罚".equals(item.getType())
|
|
|
- && item.getAmount() != null && item.getAmount().compareTo(BigDecimal.ZERO) > 0
|
|
|
- && StringUtils.isNotBlank(item.getSitepic())).count();
|
|
|
- BigDecimal ppunishAmount2 = v2.stream()
|
|
|
- .filter(item -> "处罚".equals(item.getType()))
|
|
|
+ Document doc3 = WordHelpUtils.getDoc(fileItemDo3.getFullpath());
|
|
|
+
|
|
|
+ long pcount2 = wrapper.getData().stream()
|
|
|
+ .filter(item -> StringUtils.isNotBlank(item.getSitepic()))
|
|
|
+ .count();
|
|
|
+
|
|
|
+ BigDecimal ppunishAmount2 = wrapper.getData().stream()
|
|
|
.map(ZhcxPersistentManageDo::getAmount)
|
|
|
.filter(Objects::nonNull)
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+
|
|
|
doc3.getMailMerge().execute(
|
|
|
- new String[]{"picCount", "punishAmount",
|
|
|
- "period", "topTime",
|
|
|
- "year", "leftDate",
|
|
|
- "rightDate", "checkStartDate", "checkEndDate","firstOrgName","bottomTime"},
|
|
|
- new Object[]{pcount2, ppunishAmount2,period,topTime,year,reStartDate,reEndTime,reStartTime,reEndTime,firstorgname,bottomTime}
|
|
|
+ new String[]{"picCount", "punishAmount", "period", "topTime", "year",
|
|
|
+ "leftDate", "rightDate", "checkStartDate", "checkEndDate", "firstOrgName", "bottomTime"},
|
|
|
+ new Object[]{pcount2, ppunishAmount2, period, topTime, year, reStartDate,
|
|
|
+ reEndTime, reStartTime, reEndTime, wrapper.getDeptName(), bottomTime}
|
|
|
);
|
|
|
+
|
|
|
DocumentBuilder builder = new DocumentBuilder(doc3);
|
|
|
builder.moveToDocumentEnd();
|
|
|
- createTable(builder,doc3,v2);
|
|
|
- doc.appendDocument(doc3,ImportFormatMode.KEEP_DIFFERENT_STYLES);
|
|
|
+ createTable(builder, doc3, wrapper.getData());
|
|
|
+ doc.appendDocument(doc3, ImportFormatMode.KEEP_DIFFERENT_STYLES);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- });
|
|
|
-
|
|
|
+ }
|
|
|
|
|
|
doc.updateFields();
|
|
|
response.setContentType("application/octet-stream;charset=ISO8859-1");
|
|
@@ -299,7 +333,55 @@ public class ZhcxPersistentManageServiceImpl extends ServiceImpl<ZhcxPersistentM
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ private PersistentDeptDto buildDeptDto(List<ZhcxPersistentManageVo> v, String deptName) {
|
|
|
+
|
|
|
+
|
|
|
+ long param1 = v.stream()
|
|
|
+ .filter(item -> !"0f11e70cd21843ee998a1ce5279028eb".equals(item.getBelongorgid()))
|
|
|
+ .count();
|
|
|
+ long param2 = v.stream()
|
|
|
+ .filter(item -> !"0f11e70cd21843ee998a1ce5279028eb".equals(item.getBelongorgid()))
|
|
|
+ .filter(item -> "处罚".equals(item.getType()))
|
|
|
+ .filter(item -> item.getAmount() != null && item.getAmount().compareTo(BigDecimal.ZERO) > 0)
|
|
|
+ .count();
|
|
|
+ long param3 = v.stream()
|
|
|
+ .filter(item -> "0f11e70cd21843ee998a1ce5279028eb".equals(item.getBelongorgid()))
|
|
|
+ .count();
|
|
|
+ long param4 = v.stream()
|
|
|
+ .filter(item -> "0f11e70cd21843ee998a1ce5279028eb".equals(item.getBelongorgid()))
|
|
|
+ .filter(item -> "处罚".equals(item.getType()))
|
|
|
+ .filter(item -> item.getAmount() != null && item.getAmount().compareTo(BigDecimal.ZERO) > 0)
|
|
|
+ .count();
|
|
|
+ BigDecimal param5 = v.stream()
|
|
|
+ .filter(item -> "处罚".equals(item.getType()))
|
|
|
+ .map(ZhcxPersistentManageDo::getAmount)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+
|
|
|
+ BigDecimal ratio = BigDecimal.ZERO;
|
|
|
+ if (param1 > 0) {
|
|
|
+ ratio = BigDecimal.valueOf(param2)
|
|
|
+ .divide(BigDecimal.valueOf(param1), 4, RoundingMode.HALF_UP)
|
|
|
+ .multiply(BigDecimal.valueOf(100))
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+
|
|
|
+ PersistentDeptDto dto = new PersistentDeptDto();
|
|
|
+ if (!v.isEmpty()) {
|
|
|
+ dto.setSort(v.get(0).getSort());
|
|
|
+ } else {
|
|
|
+ dto.setSort(defaultSortMap.getOrDefault(deptName, 9999)); // 未知的默认到最后
|
|
|
+ }
|
|
|
+ dto.setDutyDeptName(deptName);
|
|
|
+ dto.setSelfDeptCount(param1);
|
|
|
+ dto.setSelfDeptPunishCount(param2);
|
|
|
+ dto.setProductionCount(param3);
|
|
|
+ dto.setProductionPunishCount(param4);
|
|
|
+ dto.setPunishmentAmount(param5);
|
|
|
+ dto.setRate(ratio);
|
|
|
|
|
|
+ return dto;
|
|
|
+ }
|
|
|
@Override
|
|
|
public void syncWzPlatform(List<String> ids) {
|
|
|
//zhcxPersistentManageDao.syncWzDataUrl
|
|
@@ -827,7 +909,7 @@ public class ZhcxPersistentManageServiceImpl extends ServiceImpl<ZhcxPersistentM
|
|
|
public static int I = 0;
|
|
|
public static int Q = 0;
|
|
|
|
|
|
- private void createTable(DocumentBuilder builder, Document doc, List<ZhcxPersistentManageDo> dataList) throws Exception {
|
|
|
+ private void createTable(DocumentBuilder builder, Document doc, List<ZhcxPersistentManageVo> dataList) throws Exception {
|
|
|
// 动态复制模板表格
|
|
|
|
|
|
int idx2 = 0;
|
|
@@ -854,7 +936,7 @@ public class ZhcxPersistentManageServiceImpl extends ServiceImpl<ZhcxPersistentM
|
|
|
* @Description: 向已有表格模板插入数据
|
|
|
* @Param: doc、index、List<GxyItemData>
|
|
|
*/
|
|
|
- private void addexcel(Document doc, String k, int index, List<ZhcxPersistentManageDo> staff) throws Exception {
|
|
|
+ private void addexcel(Document doc, String k, int index, List<ZhcxPersistentManageVo> staff) throws Exception {
|
|
|
Table table = (Table) doc.getChild(NodeType.TABLE, index, true);
|
|
|
Range titleRange = table.getFirstRow().getRange();
|
|
|
|