|
@@ -23,6 +23,7 @@ import com.rongwei.bsentity.dto.RectifyDto;
|
|
|
import com.rongwei.bsentity.dto.RectifyMachineDto;
|
|
|
import com.rongwei.bsentity.dto.RectifyReportDto;
|
|
|
import com.rongwei.bsentity.dto.project.*;
|
|
|
+import com.rongwei.bsentity.vo.ZhcxProjectRectifyMachineVo;
|
|
|
import com.rongwei.rwcommon.base.R;
|
|
|
import com.rongwei.rwcommon.base.exception.CustomException;
|
|
|
import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
@@ -43,6 +44,7 @@ import java.io.ByteArrayOutputStream;
|
|
|
import java.io.File;
|
|
|
import java.io.InputStream;
|
|
|
import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -77,6 +79,8 @@ public class ZhcxProjectManageServiceImpl extends ServiceImpl<ZhcxProjectManageD
|
|
|
private ZhcxProjectRectifyMachineService projectRectifyMachineService;
|
|
|
@Autowired
|
|
|
private ExcelUtils excelUtils;
|
|
|
+ @Autowired
|
|
|
+ private ZhcxProjectManageDao zhcxProjectManageDao;
|
|
|
|
|
|
/**
|
|
|
* 生成汇总文件
|
|
@@ -152,96 +156,177 @@ public class ZhcxProjectManageServiceImpl extends ServiceImpl<ZhcxProjectManageD
|
|
|
@Override
|
|
|
public R getRectifyReportData(Map<String, Object> map) {
|
|
|
Object projectIdObj = map.get("projectId");
|
|
|
- if(ObjectUtil.isEmpty(projectIdObj)){
|
|
|
+ if (ObjectUtil.isEmpty(projectIdObj)) {
|
|
|
return R.error("");
|
|
|
}
|
|
|
String projectId = (String) projectIdObj;
|
|
|
- LambdaQueryWrapper<ZhcxProjectRectifyDo> queryWrapper = Wrappers.lambdaQuery();
|
|
|
- queryWrapper.and(i -> i.eq(ZhcxProjectRectifyDo::getPrjid, projectId));
|
|
|
- queryWrapper.and(i -> i.eq(ZhcxProjectRectifyDo::getDeleted, "0"));
|
|
|
- List<ZhcxProjectRectifyDo> rectifyDos = projectRectifyService.list(queryWrapper);
|
|
|
- if (rectifyDos != null && rectifyDos.size() > 0) {
|
|
|
- RectifyReportDto rectifyReportDto = new RectifyReportDto();
|
|
|
- String machineno = rectifyDos.get(0).getMachineno();
|
|
|
- if (StringUtils.isNotBlank(machineno)) {
|
|
|
- List<String> machineNoList = Arrays.asList(machineno .split(","));
|
|
|
- //这里要存机号列表
|
|
|
- rectifyReportDto.setNoList(machineNoList);
|
|
|
- QueryWrapper<ZhcxProjectRectifyMachineDo> wrapper = new QueryWrapper<>();
|
|
|
- wrapper.eq("PRJID", rectifyDos.get(0).getPrjid());
|
|
|
- wrapper.isNotNull("DEPTID");
|
|
|
- wrapper.isNotNull("STATUS");
|
|
|
- wrapper.orderByAsc("FIRSTDEPTID");
|
|
|
- //wrapper.last("NULLS LAST");
|
|
|
- List<ZhcxProjectRectifyMachineDo> list = projectRectifyMachineService.list(wrapper);
|
|
|
- //根据施工部门分组
|
|
|
- Map<String, List<ZhcxProjectRectifyMachineDo>> groupDeptList
|
|
|
- = list.stream().collect(Collectors.groupingBy(ZhcxProjectRectifyMachineDo::getDeptname));
|
|
|
- //根据一级部门分组
|
|
|
- Map<String, List<ZhcxProjectRectifyMachineDo>> groupFirstDeptList
|
|
|
- = list.stream().filter(e -> Objects.nonNull(e.getFirstdeptname()))
|
|
|
- .collect(Collectors.groupingBy(ZhcxProjectRectifyMachineDo::getFirstdeptname));
|
|
|
- List<RectifyDto> rectifyDtoList = new ArrayList<>();
|
|
|
- groupDeptList.forEach((k, v) ->{
|
|
|
- RectifyDto rectifyDto = new RectifyDto();
|
|
|
- rectifyDto.setFirstdeptid(v.get(0).getFirstdeptid());
|
|
|
- rectifyDto.setFirstdeptname(v.get(0).getFirstdeptname());
|
|
|
- rectifyDto.setDeptid(v.get(0).getDeptid());
|
|
|
- rectifyDto.setDeptname(v.get(0).getDeptname());
|
|
|
- //根据机号分组
|
|
|
- Map<String, List<ZhcxProjectRectifyMachineDo>> groupMachineList
|
|
|
- = v.stream().collect(Collectors.groupingBy(ZhcxProjectRectifyMachineDo::getMachineno));
|
|
|
- List<RectifyMachineDto> rectifyMachineDtoList = new ArrayList<>();
|
|
|
- groupMachineList.forEach((k2, v2) ->{
|
|
|
- RectifyMachineDto rectifyMachine = new RectifyMachineDto();
|
|
|
- //设置机号
|
|
|
- rectifyMachine.setNo(v2.get(0).getMachineno());
|
|
|
- List<ZhcxProjectRectifyMachineDo> distinctEntities = v2.stream()
|
|
|
- .collect(Collectors.toMap(
|
|
|
- e -> Arrays.asList(e.getRectifyid(), e.getDeptid()), // key extractor
|
|
|
- e -> e,
|
|
|
- (e1, e2) -> e1))
|
|
|
- .values().stream()
|
|
|
- .collect(Collectors.toList());
|
|
|
- //设置整改总数
|
|
|
- rectifyMachine.setTotalCount(distinctEntities.size());
|
|
|
- Map<String, Long> collect = distinctEntities.stream().collect(Collectors.groupingBy(
|
|
|
- ZhcxProjectRectifyMachineDo::getStatus, Collectors.counting()));
|
|
|
- //关闭数量
|
|
|
- int ok = collect.getOrDefault("OK", 0L).intValue();
|
|
|
- rectifyMachine.setClosedCount(ok);
|
|
|
- //待确认数量
|
|
|
- int i = collect.getOrDefault("√", 0L).intValue();
|
|
|
- rectifyMachine.setTbcCount(i);
|
|
|
- //未完成数量
|
|
|
- int x = collect.getOrDefault("X", 0L).intValue();
|
|
|
- rectifyMachine.setUnfinishedCount(x);
|
|
|
- //完成率1
|
|
|
- int rateOne = divideAndRoundUp((ok + i),distinctEntities.size());
|
|
|
- rectifyMachine.setFinishRateOne(rateOne+"%");
|
|
|
- //完成率2
|
|
|
- int rateTwo = divideAndRoundUp(ok,distinctEntities.size());
|
|
|
- rectifyMachine.setFinishRateTwo(rateTwo+"%");
|
|
|
- rectifyMachineDtoList.add(rectifyMachine);
|
|
|
- });
|
|
|
-
|
|
|
- rectifyDto.setData(rectifyMachineDtoList);
|
|
|
- rectifyDtoList.add(rectifyDto);
|
|
|
- });
|
|
|
- rectifyDtoList.sort(Comparator.comparing(RectifyDto::getFirstdeptid,Comparator.nullsLast(String::compareTo)));
|
|
|
- rectifyDtoList.forEach(ev -> {
|
|
|
- machineNoList.forEach(no -> {
|
|
|
- if (!ev.getData().stream().anyMatch(data -> data.getNo().equals(no))) {
|
|
|
- ev.getData().add(new RectifyMachineDto(no));
|
|
|
- }
|
|
|
- });
|
|
|
- ev.getData().sort(Comparator.comparingInt(a -> machineNoList.indexOf(a.getNo())));
|
|
|
- });
|
|
|
- rectifyReportDto.setData(rectifyDtoList);
|
|
|
- return R.ok(rectifyReportDto);
|
|
|
- }
|
|
|
+ //整改清单
|
|
|
+ List<ZhcxProjectRectifyDo> rectifyDos = projectRectifyService.list(
|
|
|
+ Wrappers.<ZhcxProjectRectifyDo>lambdaQuery()
|
|
|
+ .eq(ZhcxProjectRectifyDo::getPrjid, projectId)
|
|
|
+ .eq(ZhcxProjectRectifyDo::getDeleted, "0"));
|
|
|
+
|
|
|
+ if (rectifyDos == null || rectifyDos.isEmpty()) {
|
|
|
+ return R.ok();
|
|
|
}
|
|
|
- return R.ok();
|
|
|
+ //获取机号
|
|
|
+ RectifyReportDto rectifyReportDto = new RectifyReportDto();
|
|
|
+ String machineno = rectifyDos.get(0).getMachineno();
|
|
|
+ if (StringUtils.isBlank(machineno)) {
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> machineNoList = Arrays.asList(machineno.split(","));
|
|
|
+ rectifyReportDto.setNoList(machineNoList);
|
|
|
+
|
|
|
+ List<ZhcxProjectRectifyMachineVo> list = this.getListData(rectifyDos.get(0).getPrjid());
|
|
|
+ // 根据一级部门分组
|
|
|
+ Map<String, List<ZhcxProjectRectifyMachineVo>> groupFirstDeptList = list.stream()
|
|
|
+ .filter(e -> Objects.nonNull(e.getFirstdeptid()))
|
|
|
+ .collect(Collectors.groupingBy(ZhcxProjectRectifyMachineVo::getFirstdeptname));
|
|
|
+ //汇总一级部门数据
|
|
|
+ List<RectifyDto> firstDeptRectifyList = new ArrayList<>();
|
|
|
+ groupFirstDeptList.forEach((firstDeptName, machines) -> {
|
|
|
+ RectifyDto rectifyDto = new RectifyDto();
|
|
|
+ rectifyDto.setFirstdeptsort(machines.get(0).getFirstdeptsort());
|
|
|
+ rectifyDto.setFirstdeptid(machines.get(0).getFirstdeptid());
|
|
|
+ rectifyDto.setFirstdeptname(machines.get(0).getFirstdeptname());
|
|
|
+ rectifyDto.setData(createRectifyMachineDtoList(machines, ZhcxProjectRectifyMachineVo::getFirstdeptid));
|
|
|
+ firstDeptRectifyList.add(rectifyDto);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 根据施工部门分组
|
|
|
+ Map<String, List<ZhcxProjectRectifyMachineVo>> groupDeptList = list.stream()
|
|
|
+ .collect(Collectors.groupingBy(ZhcxProjectRectifyMachineVo::getDeptname));
|
|
|
+
|
|
|
+ List<RectifyDto> rectifyDtoList = new ArrayList<>();
|
|
|
+ Set<String> processedFirstDeptIds = new HashSet<>();
|
|
|
+ //汇总施工部门数据
|
|
|
+ groupDeptList.forEach((deptName, machines) -> {
|
|
|
+ String firstDeptId = machines.get(0).getFirstdeptid();
|
|
|
+ if (processedFirstDeptIds.add(firstDeptId)) {
|
|
|
+ List<RectifyDto> collect = firstDeptRectifyList.stream()
|
|
|
+ .filter(ev -> ev.getFirstdeptid().equals(firstDeptId))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ rectifyDtoList.addAll(collect);
|
|
|
+ }
|
|
|
+
|
|
|
+ RectifyDto rectifyDto = new RectifyDto();
|
|
|
+ rectifyDto.setFirstdeptsort(machines.get(0).getFirstdeptsort());
|
|
|
+ rectifyDto.setFirstdeptid(firstDeptId);
|
|
|
+ rectifyDto.setFirstdeptname(machines.get(0).getFirstdeptname());
|
|
|
+ rectifyDto.setDeptsort(machines.get(0).getDeptsort());
|
|
|
+ rectifyDto.setOutsidedeptsort(machines.get(0).getOutsidedeptsort());
|
|
|
+ rectifyDto.setDeptid(machines.get(0).getDeptid());
|
|
|
+ rectifyDto.setDeptname(deptName);
|
|
|
+ rectifyDto.setData(createRectifyMachineDtoList(machines,ZhcxProjectRectifyMachineDo::getDeptid));
|
|
|
+ rectifyDtoList.add(rectifyDto);
|
|
|
+ });
|
|
|
+ //排序
|
|
|
+ //rectifyDtoList.sort(Comparator.comparing(RectifyDto::getFirstdeptid, Comparator.nullsLast(String::compareTo)));
|
|
|
+ rectifyDtoList.sort((d1, d2) -> {
|
|
|
+ // 先按一级部门排序,空的排到最后
|
|
|
+ int firstDeptCompare = Comparator.comparing(RectifyDto::getFirstdeptsort, Comparator.nullsLast(Integer::compareTo)).compare(d1, d2);
|
|
|
+ if (firstDeptCompare != 0) {
|
|
|
+ return firstDeptCompare;
|
|
|
+ }
|
|
|
+ // 再按施工部门排序,空的排前面
|
|
|
+ int secondDeptCompare = Comparator.comparing(RectifyDto::getDeptsort, Comparator.nullsFirst(Integer::compareTo)).compare(d1, d2);
|
|
|
+ if (secondDeptCompare != 0) {
|
|
|
+ return secondDeptCompare;
|
|
|
+ }
|
|
|
+ // 最后按基地外排序
|
|
|
+ return Comparator.comparing(RectifyDto::getOutsidedeptsort, Comparator.nullsLast(Integer::compareTo)).compare(d1, d2);
|
|
|
+ });
|
|
|
+ //基地内合计
|
|
|
+ List<ZhcxProjectRectifyMachineVo> collect = list.stream()
|
|
|
+ .filter(e -> Objects.nonNull(e.getFirstdeptid())).collect(Collectors.toList());
|
|
|
+ List<ZhcxProjectRectifyMachineVo> collect2 = list.stream()
|
|
|
+ .filter(e -> "b0bd3ed27bfb4af08535c39f464b3d3a".equals(e.getDeptid())).collect(Collectors.toList());
|
|
|
+ collect.addAll(collect2);
|
|
|
+ RectifyDto rectifyDto = new RectifyDto();
|
|
|
+ rectifyDto.setDeptid(null);
|
|
|
+ rectifyDto.setDeptname("基地内合计");
|
|
|
+ rectifyDto.setData(createRectifyMachineDtoList(collect,null));
|
|
|
+ rectifyDtoList.add(rectifyDto);
|
|
|
+ //基地外合计
|
|
|
+ List<ZhcxProjectRectifyMachineVo> collect3 = list.stream()
|
|
|
+ .filter(e -> !"b0bd3ed27bfb4af08535c39f464b3d3a".equals(e.getDeptid())
|
|
|
+ && Objects.isNull(e.getFirstdeptid())).collect(Collectors.toList());
|
|
|
+ RectifyDto outSideRectifyDto = new RectifyDto();
|
|
|
+ outSideRectifyDto.setDeptid(null);
|
|
|
+ outSideRectifyDto.setDeptname("基地外合计");
|
|
|
+ outSideRectifyDto.setData(createRectifyMachineDtoList(collect3,null));
|
|
|
+ rectifyDtoList.add(outSideRectifyDto);
|
|
|
+ //全部
|
|
|
+ RectifyDto AllRectifyDto = new RectifyDto();
|
|
|
+ AllRectifyDto.setDeptid(null);
|
|
|
+ AllRectifyDto.setDeptname("总合计");
|
|
|
+ AllRectifyDto.setData(createRectifyMachineDtoList(list,null));
|
|
|
+ rectifyDtoList.add(AllRectifyDto);
|
|
|
+ rectifyDtoList.forEach(ev -> {
|
|
|
+ machineNoList.forEach(no -> {
|
|
|
+ if (ev.getData().stream().noneMatch(data -> data.getNo().equals(no))) {
|
|
|
+ ev.getData().add(new RectifyMachineDto(no));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ ev.getData().sort(Comparator.comparingInt(a -> machineNoList.indexOf(a.getNo())));
|
|
|
+ });
|
|
|
+ rectifyReportDto.setData(rectifyDtoList);
|
|
|
+ return R.ok(rectifyReportDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<ZhcxProjectRectifyMachineVo> getListData(String prjid) {
|
|
|
+ return zhcxProjectManageDao.getListData(prjid);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据机号和动态传入参数分组 统计
|
|
|
+ * @param machines
|
|
|
+ * @param idExtractor
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<RectifyMachineDto> createRectifyMachineDtoList(List<ZhcxProjectRectifyMachineVo> machines, Function<ZhcxProjectRectifyMachineVo, Object> idExtractor) {
|
|
|
+ //根据机号和动态传入参数分组 统计
|
|
|
+ return machines.stream()
|
|
|
+ .collect(Collectors.groupingBy(ZhcxProjectRectifyMachineVo::getMachineno))
|
|
|
+ .entrySet().stream()
|
|
|
+ .map(entry -> {
|
|
|
+ String machineno = entry.getKey();
|
|
|
+ List<ZhcxProjectRectifyMachineVo> machineList = entry.getValue();
|
|
|
+
|
|
|
+ List<ZhcxProjectRectifyMachineDo> distinctEntities = machineList.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ e -> idExtractor != null ? Arrays.asList(e.getRectifyid(), idExtractor.apply(e)) : Arrays.asList(e.getRectifyid()), // key extractor
|
|
|
+ e -> e,
|
|
|
+ (e1, e2) -> e1))
|
|
|
+ .values().stream()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ Map<String, Long> statusCount = distinctEntities.stream()
|
|
|
+ .collect(Collectors.groupingBy(ZhcxProjectRectifyMachineDo::getStatus, Collectors.counting()));
|
|
|
+
|
|
|
+ int okCount = statusCount.getOrDefault("OK", 0L).intValue();
|
|
|
+ int tbcCount = statusCount.getOrDefault("√", 0L).intValue();
|
|
|
+ int unfinishedCount = statusCount.getOrDefault("X", 0L).intValue();
|
|
|
+ int totalCount = distinctEntities.size();
|
|
|
+
|
|
|
+ RectifyMachineDto rectifyMachine = new RectifyMachineDto();
|
|
|
+ rectifyMachine.setNo(machineno);
|
|
|
+ rectifyMachine.setTotalCount(totalCount);
|
|
|
+ rectifyMachine.setClosedCount(okCount);
|
|
|
+ rectifyMachine.setTbcCount(tbcCount);
|
|
|
+ rectifyMachine.setUnfinishedCount(unfinishedCount);
|
|
|
+ rectifyMachine.setFinishRateOne(calculateRate(okCount + tbcCount, totalCount) + "%");
|
|
|
+ rectifyMachine.setFinishRateTwo(calculateRate(okCount, totalCount) + "%");
|
|
|
+
|
|
|
+ return rectifyMachine;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ private int calculateRate(int part, int total) {
|
|
|
+ return total == 0 ? 0 : (int) Math.ceil((double) part / total * 100);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -349,6 +434,7 @@ public class ZhcxProjectManageServiceImpl extends ServiceImpl<ZhcxProjectManageD
|
|
|
style.setBorder(BorderType.BOTTOM_BORDER, CellBorderType.THIN, Color.getBlack());
|
|
|
style.setBorder(BorderType.LEFT_BORDER, CellBorderType.THIN, Color.getBlack());
|
|
|
style.setBorder(BorderType.RIGHT_BORDER, CellBorderType.THIN, Color.getBlack());
|
|
|
+ Color color = Color.fromArgb(255, 221, 155);
|
|
|
for (int i = 0; i < colIndex; i++) {
|
|
|
//cells.get(1, i).setStyle(style);
|
|
|
for (int x = 0; x < rowIndex; x++) {
|