|
@@ -11,7 +11,9 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.aspose.cells.*;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.rongwei.bscommon.sys.dao.LuckysheetDao;
|
|
|
import com.rongwei.bscommon.sys.feign.LuckySheetService;
|
|
|
import com.rongwei.bscommon.sys.service.*;
|
|
@@ -2079,16 +2081,13 @@ public class ZhcxProjectManageServiceImpl extends ServiceImpl<ZhcxProjectManageD
|
|
|
public R searchRectifyData(Map<String, Object> map) {
|
|
|
Object projectIdObj = map.get("projectId");
|
|
|
Object machineNoObj = map.get("machineNo");
|
|
|
-// Object currentObj = map.get("current");
|
|
|
-// Object sizeObj = map.get("size");
|
|
|
+
|
|
|
if (ObjectUtil.isEmpty(projectIdObj) || ObjectUtil.isEmpty(machineNoObj)) {
|
|
|
return R.error();
|
|
|
}
|
|
|
String projectId = (String) projectIdObj;
|
|
|
List<String> machineNos = (List<String>) machineNoObj;
|
|
|
-// int current = (Integer) currentObj;
|
|
|
-// int size = (Integer) sizeObj;
|
|
|
- //Page<ZhcxProjectRectifySnapDo> page = new Page<>(current, size);
|
|
|
+
|
|
|
LambdaQueryWrapper<ZhcxProjectRectifySnapDo> eq = Wrappers.<ZhcxProjectRectifySnapDo>lambdaQuery()
|
|
|
.eq(ZhcxProjectRectifySnapDo::getProjectid, projectId)
|
|
|
.in(ZhcxProjectRectifySnapDo::getMachineno, machineNos)
|
|
@@ -2096,11 +2095,7 @@ public class ZhcxProjectManageServiceImpl extends ServiceImpl<ZhcxProjectManageD
|
|
|
.between(ZhcxProjectRectifySnapDo::getDate,
|
|
|
Date.from(LocalDateTime.now().minusDays(29).toLocalDate().atStartOfDay(ZoneId.systemDefault()).toInstant())
|
|
|
, Date.from(LocalDateTime.now().toLocalDate().atTime(LocalTime.MAX).atZone(ZoneId.systemDefault()).toInstant()));
|
|
|
- //IPage<ZhcxProjectRectifySnapDo> pageData = zhcxProjectRectifySnapService.page(page, eq);
|
|
|
-// List<ZhcxProjectRectifySnapDo> list = pageData.getRecords();
|
|
|
-// Long total = pageData.getTotal(); // 总记录数
|
|
|
-// Long pages = pageData.getPages(); // 总页数
|
|
|
- //zhcxProjectManageDao.searchRectifyData();
|
|
|
+
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
|
|
|
List<ZhcxProjectRectifySnapVo> list = zhcxProjectRectifySnapService.list(eq).stream()
|
|
|
.map(record -> {
|
|
@@ -2109,42 +2104,9 @@ public class ZhcxProjectManageServiceImpl extends ServiceImpl<ZhcxProjectManageD
|
|
|
return vo;
|
|
|
})
|
|
|
.collect(Collectors.toList());;
|
|
|
-// Map<String, List<ZhcxProjectRectifySnapDo>> collect = list.stream()
|
|
|
-// .filter(e -> Objects.nonNull(e.getFirstorgid()))
|
|
|
-// .collect(Collectors.groupingBy(ZhcxProjectRectifySnapDo:: getFirstorgid));
|
|
|
+
|
|
|
RectifySnapDto rectifySnapDto = new RectifySnapDto();
|
|
|
Set<String> dateList = new HashSet<>();
|
|
|
- //List<RectifySnapVo> rectifySnapVos = new ArrayList<>();
|
|
|
-// collect.forEach((k, v) -> {
|
|
|
-//
|
|
|
-//// Map<String, List<ZhcxProjectRectifySnapDo>> collect2 = v.stream()
|
|
|
-//// .filter(e -> Objects.nonNull(e.getDate()))
|
|
|
-//// .collect(Collectors.groupingBy(e -> dateFormat.format(e.getDate())));
|
|
|
-//// collect2.forEach((k2, v2) -> {
|
|
|
-//// dateList.add(k2);
|
|
|
-//// data.addAll(v2);
|
|
|
-//// });
|
|
|
-// Map<String, List<ZhcxProjectRectifySnapDo>> collect2 = v.stream()
|
|
|
-// .filter(e -> Objects.nonNull(e.getMachineno()))
|
|
|
-// .collect(Collectors.groupingBy(e -> e.getMachineno()));
|
|
|
-// Map<String,List<RectifySnapVo>> machineNoData = new HashMap<>(16);
|
|
|
-// collect2.forEach((k2, v2) -> {
|
|
|
-// RectifySnapVo rectifySnapVo = new RectifySnapVo();
|
|
|
-// List<ZhcxProjectRectifySnapDo> data = new ArrayList<>();
|
|
|
-// rectifySnapVo.setFirstdeptname(v2.get(0).getFirstorgname());
|
|
|
-// Map<String, List<ZhcxProjectRectifySnapDo>> collect3 = v2.stream()
|
|
|
-// .filter(e -> Objects.nonNull(e.getDate()))
|
|
|
-// .collect(Collectors.groupingBy(e -> dateFormat.format(e.getDate())));
|
|
|
-// collect3.forEach((k3, v3) -> {
|
|
|
-// dateList.add(k3);
|
|
|
-//
|
|
|
-// });
|
|
|
-// //machineNoData.put(k2,)
|
|
|
-// rectifySnapVo.setData(data);
|
|
|
-// rectifySnapVos.add(rectifySnapVo);
|
|
|
-// });
|
|
|
-//
|
|
|
-// });
|
|
|
//根据机号分组
|
|
|
Map<String, List<ZhcxProjectRectifySnapVo>> collect = list.stream()
|
|
|
.filter(e -> Objects.nonNull(e.getMachineno()))
|
|
@@ -2235,23 +2197,7 @@ public class ZhcxProjectManageServiceImpl extends ServiceImpl<ZhcxProjectManageD
|
|
|
rectifySnapMachineDto.setSnapList(rectifySnapVos);
|
|
|
machineNoData.add(rectifySnapMachineDto);
|
|
|
});
|
|
|
-// Map<String, List<ZhcxProjectRectifySnapDo>> collect = list.stream()
|
|
|
-// .filter(e -> Objects.nonNull(e.getDate()))
|
|
|
-// .collect(Collectors.groupingBy(e -> dateFormat.format(e.getDate())));
|
|
|
-// collect.forEach((k, v) -> {
|
|
|
-//
|
|
|
-// dateList.add(k);
|
|
|
-// Map<String, List<ZhcxProjectRectifySnapDo>> collect2 = v.stream()
|
|
|
-// .filter(e -> Objects.nonNull(e.getFirstorgid()))
|
|
|
-// .collect(Collectors.groupingBy(ZhcxProjectRectifySnapDo:: getFirstorgid));
|
|
|
-// collect2.forEach((k2, v2) -> {
|
|
|
-// RectifySnapVo rectifySnapVo = new RectifySnapVo();
|
|
|
-// rectifySnapVo.setFirstdeptname(v2.get(0).getFirstorgname());
|
|
|
-// rectifySnapVo.setData(v2);
|
|
|
-// rectifySnapVos.add(rectifySnapVo);
|
|
|
-// });
|
|
|
-//
|
|
|
-// });
|
|
|
+
|
|
|
List<String> sortedDateList = dateList.stream()
|
|
|
.map(date -> {
|
|
|
try {
|
|
@@ -2314,30 +2260,179 @@ public class ZhcxProjectManageServiceImpl extends ServiceImpl<ZhcxProjectManageD
|
|
|
// 比较数字部分
|
|
|
return Integer.compare(num1, num2);
|
|
|
});
|
|
|
+ rectifySnapDto.setDateList(sortedDateList);
|
|
|
+ rectifySnapDto.setList(machineNoData);
|
|
|
+ return R.ok(rectifySnapDto);
|
|
|
+ }
|
|
|
|
|
|
-// rectifySnapVos.forEach(snapVo -> {
|
|
|
-// List<ZhcxProjectRectifySnapDo> dataList = snapVo.getData();
|
|
|
-// if (dataList != null) {
|
|
|
-// // 按 date 字段倒序排序
|
|
|
-// dataList.sort(Comparator.comparing(ZhcxProjectRectifySnapDo::getDate, Comparator.nullsLast(Comparator.reverseOrder())));
|
|
|
-// sortedDateList.forEach(date -> {
|
|
|
-// if (dataList.stream().noneMatch(data -> {
|
|
|
-// SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
|
|
|
-// String formattedDate = sdf.format(data.getDate());
|
|
|
-// return formattedDate.equals(date); // 假设 date 是一个字符串,格式为 "yyyy-MM-dd"
|
|
|
-// })) {
|
|
|
-// ZhcxProjectRectifySnapDo zhcxProjectRectifySnapDo = new ZhcxProjectRectifySnapDo();
|
|
|
-// zhcxProjectRectifySnapDo.setDate(new Date(date)); // 将字符串 date 转换为 Date 对象
|
|
|
-// dataList.add(zhcxProjectRectifySnapDo);
|
|
|
-// }
|
|
|
-// });
|
|
|
-// }
|
|
|
-// });
|
|
|
+ @Override
|
|
|
+ public R searchRectifyTabData(Map<String, Object> map) {
|
|
|
+ Object projectIdObj = map.get("projectId");
|
|
|
+ Object machineNoObj = map.get("machineNo");
|
|
|
+
|
|
|
+ if (ObjectUtil.isEmpty(projectIdObj) || ObjectUtil.isEmpty(machineNoObj)) {
|
|
|
+ return R.error();
|
|
|
+ }
|
|
|
+ String projectId = (String) projectIdObj;
|
|
|
+ List<String> machineNos = (List<String>) machineNoObj;
|
|
|
+
|
|
|
+ LambdaQueryWrapper<ZhcxProjectRectifySnapDo> eq = Wrappers.<ZhcxProjectRectifySnapDo>lambdaQuery()
|
|
|
+ .eq(ZhcxProjectRectifySnapDo::getProjectid, projectId)
|
|
|
+ .in(ZhcxProjectRectifySnapDo::getMachineno, machineNos)
|
|
|
+ .eq(ZhcxProjectRectifySnapDo::getDeleted, "0");
|
|
|
+
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
|
|
|
+ List<ZhcxProjectRectifySnapVo> list = zhcxProjectRectifySnapService.list(eq).stream()
|
|
|
+ .map(record -> {
|
|
|
+ ZhcxProjectRectifySnapVo vo = new ZhcxProjectRectifySnapVo();
|
|
|
+ BeanUtils.copyProperties(record, vo); // 使用 Spring 的工具类复制属性
|
|
|
+ return vo;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());;
|
|
|
+
|
|
|
+ RectifySnapDto rectifySnapDto = new RectifySnapDto();
|
|
|
+ Set<String> dateList = new HashSet<>();
|
|
|
+ //根据机号分组
|
|
|
+ Map<String, List<ZhcxProjectRectifySnapVo>> collect = list.stream()
|
|
|
+ .filter(e -> Objects.nonNull(e.getMachineno()))
|
|
|
+ .collect(Collectors.groupingBy(ZhcxProjectRectifySnapVo:: getMachineno));
|
|
|
+ //Map<String,List<RectifySnapVo>> machineNoData = new HashMap<>(16);
|
|
|
+ List<RectifySnapMachineDto> machineNoData = new ArrayList<>();
|
|
|
+ collect.forEach((k, v) -> {
|
|
|
+ List<RectifySnapVo> rectifySnapVos = new ArrayList<>();
|
|
|
+ //根据部门分组
|
|
|
+ Map<String, List<ZhcxProjectRectifySnapVo>> collect2 = v.stream()
|
|
|
+ .filter(e -> Objects.nonNull(e.getFirstorgid()))
|
|
|
+ .collect(Collectors.groupingBy(ZhcxProjectRectifySnapVo:: getFirstorgid));
|
|
|
+ collect2.forEach((k2, v2) -> {
|
|
|
+ RectifySnapVo rectifySnapVo = new RectifySnapVo();
|
|
|
+ List<ZhcxProjectRectifySnapVo> data = new ArrayList<>();
|
|
|
+ rectifySnapVo.setFirstdeptname(v2.get(0).getFirstorgname());
|
|
|
+ rectifySnapVo.setIfoutsidebase(v2.get(0).getIfoutsidebase());
|
|
|
+ //根据日期分组
|
|
|
+ Map<String, List<ZhcxProjectRectifySnapVo>> collect3 = v2.stream()
|
|
|
+ .filter(e -> Objects.nonNull(e.getDate()))
|
|
|
+ .collect(Collectors.groupingBy(e -> dateFormat.format(e.getDate())));
|
|
|
+ collect3.forEach((k3, v3) -> {
|
|
|
+ dateList.add(k3);
|
|
|
+ data.addAll(v3);
|
|
|
+ });
|
|
|
+ rectifySnapVo.setData(data);
|
|
|
+ rectifySnapVos.add(rectifySnapVo);
|
|
|
+ });
|
|
|
+ rectifySnapVos.sort((vo1, vo2) -> {
|
|
|
+ String base1 = vo1.getIfoutsidebase();
|
|
|
+ String base2 = vo2.getIfoutsidebase();
|
|
|
+
|
|
|
+ if (base1 == null && base2 == null) {
|
|
|
+ return 0; // 都是 null
|
|
|
+ }
|
|
|
+ if (base1 == null) {
|
|
|
+ return 1; // null 排最后
|
|
|
+ }
|
|
|
+ if (base2 == null) {
|
|
|
+ return -1; // null 排最后
|
|
|
+ }
|
|
|
+
|
|
|
+ // 自定义排序逻辑: inside < outside
|
|
|
+ if (base1.equals("inside") && !base2.equals("inside")) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ if (base1.equals("outside") && base2.equals("inside")) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ return base1.compareTo(base2); // 其他情况默认字典排序
|
|
|
+ });
|
|
|
+ Map<String, List<ZhcxProjectRectifySnapVo>> collect4 = v.stream()
|
|
|
+ .filter(e -> Objects.nonNull(e.getDate()))
|
|
|
+ .collect(Collectors.groupingBy(e -> dateFormat.format(e.getDate())));
|
|
|
+ List<ZhcxProjectRectifySnapVo> data = new ArrayList<>();
|
|
|
+ RectifySnapVo rectifySnapVo = new RectifySnapVo();
|
|
|
+ rectifySnapVo.setFirstdeptname("总合计");
|
|
|
+ collect4.forEach((k4, v4) -> {
|
|
|
+ // 汇总两个字段
|
|
|
+ int sumField1 = v4.stream().mapToInt(vo -> Optional.ofNullable(vo.getFinishnum()).orElse(0)).sum();
|
|
|
+ int sumField2 = v4.stream().mapToInt(vo -> Optional.ofNullable(vo.getRectifytotal()).orElse(0)).sum();
|
|
|
+ // 创建汇总对象
|
|
|
+ ZhcxProjectRectifySnapVo summaryVo = new ZhcxProjectRectifySnapVo();
|
|
|
+ summaryVo.setDate(v4.get(0).getDate()); // 设置分组的日期
|
|
|
+ summaryVo.setFinishnum(sumField1); // 设置字段1的总和
|
|
|
+ summaryVo.setRectifytotal(sumField2); // 设置字段2的总和
|
|
|
+ summaryVo.setFirstorgname("总合计");
|
|
|
+ data.add(summaryVo);
|
|
|
+ });
|
|
|
+ rectifySnapVo.setData(data);
|
|
|
+ rectifySnapVos.add(rectifySnapVo);
|
|
|
+ RectifySnapMachineDto rectifySnapMachineDto = new RectifySnapMachineDto();
|
|
|
+ rectifySnapMachineDto.setMachineNo(k);
|
|
|
+ rectifySnapMachineDto.setSnapList(rectifySnapVos);
|
|
|
+ machineNoData.add(rectifySnapMachineDto);
|
|
|
+ });
|
|
|
+
|
|
|
+ List<String> sortedDateList = dateList.stream()
|
|
|
+ .map(date -> {
|
|
|
+ try {
|
|
|
+ return dateFormat.parse(date);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .sorted(Collections.reverseOrder())
|
|
|
+ .map(dateFormat::format)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ for (int i = 0; i < machineNoData.size(); i++) {
|
|
|
+ List<RectifySnapVo> snapList = machineNoData.get(i).getSnapList();
|
|
|
+ snapList.forEach(snapVo -> {
|
|
|
+ List<ZhcxProjectRectifySnapVo> dataList = snapVo.getData();
|
|
|
+ if (dataList != null) {
|
|
|
+ // 按 date 字段倒序排序
|
|
|
+ dataList.sort(Comparator.comparing(ZhcxProjectRectifySnapVo::getDate, Comparator.nullsLast(Comparator.reverseOrder())));
|
|
|
+ sortedDateList.forEach(date -> {
|
|
|
+ if (dataList.stream().noneMatch(data -> {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
|
|
|
+ String formattedDate = sdf.format(data.getDate());
|
|
|
+ return formattedDate.equals(date); // 假设 date 是一个字符串,格式为 "yyyy-MM-dd"
|
|
|
+ })) {
|
|
|
+ ZhcxProjectRectifySnapVo zhcxProjectRectifySnapVo = new ZhcxProjectRectifySnapVo();
|
|
|
+ zhcxProjectRectifySnapVo.setDate(new Date(date)); // 将字符串 date 转换为 Date 对象
|
|
|
+ dataList.add(zhcxProjectRectifySnapVo);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ for (int j = dataList.size() -1; j >= 0; j--) {
|
|
|
+ ZhcxProjectRectifySnapVo current = dataList.get(j);
|
|
|
+ Integer rectifytotal = current.getRectifytotal() != null ? current.getRectifytotal() : 0;
|
|
|
+ Integer finishnum = current.getFinishnum() != null ? current.getFinishnum() : 0;
|
|
|
+ // 设置未完成数
|
|
|
+ current.setUnFinishNum(rectifytotal - finishnum);
|
|
|
+
|
|
|
+ // 设置当前完成数
|
|
|
+ if (j < dataList.size() - 1) {
|
|
|
+ // 前一个元素
|
|
|
+ ZhcxProjectRectifySnapVo previous = dataList.get(j + 1);
|
|
|
+ int i1 = previous.getUnFinishNum() == null ? 0 : previous.getUnFinishNum();
|
|
|
+ int i2 = current.getUnFinishNum() == null ? 0 : current.getUnFinishNum();
|
|
|
+ current.setNowFinishNum(i1 - i2);
|
|
|
+ } else {
|
|
|
+ // 第一条记录没有 "前一条" 数据
|
|
|
+ current.setNowFinishNum(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ machineNoData.sort((o1, o2) -> {
|
|
|
+ String machineNo1 = o1.getMachineNo();
|
|
|
+ String machineNo2 = o2.getMachineNo();
|
|
|
|
|
|
+ // 提取数字部分
|
|
|
+ Integer num1 = extractNumber(machineNo1);
|
|
|
+ Integer num2 = extractNumber(machineNo2);
|
|
|
+
|
|
|
+ // 比较数字部分
|
|
|
+ return Integer.compare(num1, num2);
|
|
|
+ });
|
|
|
rectifySnapDto.setDateList(sortedDateList);
|
|
|
rectifySnapDto.setList(machineNoData);
|
|
|
-// rectifySnapDto.setTotal(total.intValue());
|
|
|
-// rectifySnapDto.setPage(pages.intValue());
|
|
|
return R.ok(rectifySnapDto);
|
|
|
}
|
|
|
|