|
@@ -11,15 +11,14 @@ 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.*;
|
|
|
import com.rongwei.bscommon.sys.utils.LuckySheet4SummaryHelp;
|
|
|
import com.rongwei.bscommon.sys.utils.ProjectSummaryExcelHelp;
|
|
|
import com.rongwei.bscommon.sys.utils.XlsSheetUtil;
|
|
|
+import com.rongwei.bscommon.sys.utils.ZhcxCommon;
|
|
|
import com.rongwei.bsentity.domain.*;
|
|
|
import com.rongwei.bscommon.sys.dao.ZhcxProjectManageDao;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -30,6 +29,7 @@ import com.rongwei.bsentity.vo.RectifySnapVo;
|
|
|
import com.rongwei.bsentity.vo.ZhcxProjectRectifyMachineVo;
|
|
|
import com.rongwei.bsentity.vo.ZhcxProjectRectifySnapVo;
|
|
|
import com.rongwei.bsentity.vo.ZhcxProjectRectifyVo;
|
|
|
+import com.rongwei.rwadmincommon.system.vo.SysUserVo;
|
|
|
import com.rongwei.rwcommon.base.R;
|
|
|
import com.rongwei.rwcommon.base.exception.CustomException;
|
|
|
import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
@@ -76,6 +76,8 @@ public class ZhcxProjectManageServiceImpl extends ServiceImpl<ZhcxProjectManageD
|
|
|
@Autowired
|
|
|
@Lazy
|
|
|
private SysFileItemService fileItemService;
|
|
|
+ @Autowired
|
|
|
+ private ZhcxProjectManageService serice;
|
|
|
|
|
|
@Autowired
|
|
|
private ZhcxProjectDeviceNumberService projectDeviceNumberService;
|
|
@@ -103,6 +105,8 @@ public class ZhcxProjectManageServiceImpl extends ServiceImpl<ZhcxProjectManageD
|
|
|
private ZhcxProjectRectifySnapService zhcxProjectRectifySnapService;
|
|
|
@Autowired
|
|
|
private ZhcxProjectDeviceIndicatorService zhcxProjectDeviceIndicatorService;
|
|
|
+ @Autowired
|
|
|
+ private ZhcxCommon zhcxCommon;
|
|
|
|
|
|
@Value("${file.writeRootPath}")
|
|
|
private String writeRootPath;
|
|
@@ -2524,6 +2528,318 @@ public class ZhcxProjectManageServiceImpl extends ServiceImpl<ZhcxProjectManageD
|
|
|
return R.ok(rectifySnapDto);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void exportPrjDataByQA(Map<String, Object> map, HttpServletResponse response) {
|
|
|
+ Object fileIdObj = map.get("fileId");
|
|
|
+ if( ObjectUtil.isEmpty(fileIdObj)){
|
|
|
+ throw new CustomException("缺少参数,请联系管理员");
|
|
|
+ }
|
|
|
+ String fileId = (String) fileIdObj;
|
|
|
+ SysFileItemDo fileItemDo = fileItemService.getById(fileId);
|
|
|
+ if (!excelUtils.GetLicense()) {
|
|
|
+ log.info("缺少license");
|
|
|
+ throw new CustomException("导出错误,请联系系统管理员");
|
|
|
+ }
|
|
|
+ if(fileItemDo == null){
|
|
|
+ log.info("缺少QA模板");
|
|
|
+ throw new CustomException("导出失败,请联系管理员");
|
|
|
+ }
|
|
|
+
|
|
|
+ Workbook book = null;
|
|
|
+ try {
|
|
|
+ book = new Workbook(fileItemDo.getFullpath());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("导出失败{}",e);
|
|
|
+ throw new CustomException("导出失败,请联系管理员");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ SysUserVo currentUser = zhcxCommon.getCurrentUser();
|
|
|
+// LambdaQueryWrapper<ZhcxProjectManageDo> wrapper = new LambdaQueryWrapper<>();
|
|
|
+// wrapper.eq(ZhcxProjectManageDo::getTenantid,currentUser.getTenantid());
|
|
|
+// wrapper.eq(ZhcxProjectManageDo::getDeleted,"0");
|
|
|
+// List<ZhcxProjectManageDo> list = serice.list(wrapper);
|
|
|
+ map.put("tenantid",currentUser.getTenantid());
|
|
|
+ List<ProjectByQaDto> list = zhcxProjectManageDao.getPrjListData(map);
|
|
|
+// list.sort(Comparator.comparing(
|
|
|
+// (ProjectByQaDto p) -> {
|
|
|
+// String qa = p.getQamanager();
|
|
|
+// return (qa == null || qa.trim().isEmpty()) ? null : qa;
|
|
|
+// },
|
|
|
+// Comparator.nullsLast(String::compareTo)
|
|
|
+// ).thenComparing(
|
|
|
+// ProjectByQaDto::getNumber,
|
|
|
+// Comparator.nullsLast(Comparator.reverseOrder())
|
|
|
+// ));
|
|
|
+ String EMPTY_QA = "<EMPTY>";
|
|
|
+ Map<String, Long> qaCountMap = list.stream()
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ p -> {
|
|
|
+ String qa = p.getQamanager();
|
|
|
+ return (qa == null || qa.trim().isEmpty()) ? EMPTY_QA : qa.trim();
|
|
|
+ },
|
|
|
+ Collectors.counting()
|
|
|
+ ));
|
|
|
+ list.sort(
|
|
|
+ Comparator.<ProjectByQaDto, Long>comparing(
|
|
|
+ p -> qaCountMap.get(
|
|
|
+ (p.getQamanager() == null || p.getQamanager().trim().isEmpty())
|
|
|
+ ? EMPTY_QA
|
|
|
+ : p.getQamanager().trim()
|
|
|
+ ),
|
|
|
+ Comparator.nullsLast(Comparator.reverseOrder()) // 数量多的在前,空的排最后
|
|
|
+ ).thenComparing(
|
|
|
+ p -> {
|
|
|
+ String qa = p.getQamanager();
|
|
|
+ return (qa == null || qa.trim().isEmpty()) ? EMPTY_QA : qa.trim();
|
|
|
+ },
|
|
|
+ Comparator.nullsLast(String::compareTo) // qamanager 升序(空排最后)
|
|
|
+ )
|
|
|
+ );
|
|
|
+ WorksheetCollection worksheets = book.getWorksheets();
|
|
|
+ Worksheet worksheet = worksheets.get(0);
|
|
|
+ Cells cells = worksheet.getCells();
|
|
|
+ // 定义样式
|
|
|
+ Style style = book.createStyle();
|
|
|
+ style.setHorizontalAlignment(TextAlignmentType.CENTER); // 水平居中
|
|
|
+ style.setVerticalAlignment(TextAlignmentType.CENTER); // 垂直居中
|
|
|
+ style.setTextWrapped(true); // 自动换行(可选)
|
|
|
+
|
|
|
+ // 设置边框
|
|
|
+ style.setBorder(BorderType.TOP_BORDER, CellBorderType.THIN, Color.getBlack());
|
|
|
+ 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());
|
|
|
+
|
|
|
+ // 定义样式标记
|
|
|
+ StyleFlag styleFlag = new StyleFlag();
|
|
|
+ styleFlag.setBorders(true);
|
|
|
+ styleFlag.setHorizontalAlignment(true);
|
|
|
+ styleFlag.setVerticalAlignment(true);
|
|
|
+ styleFlag.setWrapText(true);
|
|
|
+ int i = 2;
|
|
|
+ String lastQaManager = null;
|
|
|
+ int mergeStartRow = 2;
|
|
|
+ for (ProjectByQaDto projectManageDo :list) {
|
|
|
+ String currentQaManager = projectManageDo.getQamanager();
|
|
|
+ cells.get(i, 0).putValue(i-1);
|
|
|
+ cells.get(i, 1).putValue(projectManageDo.getProjectcode());
|
|
|
+ cells.get(i, 2).putValue(projectManageDo.getProjectname());
|
|
|
+ cells.get(i, 3).putValue(projectManageDo.getNumber());
|
|
|
+ cells.get(i, 4).putValue(projectManageDo.getQamanager());
|
|
|
+ cells.get(i, 5).putValue(projectManageDo.getSupervisionnames());
|
|
|
+ cells.get(i, 7).putValue(projectManageDo.getRemark());
|
|
|
+ // 给当前行所有已填单元格设置样式(0~7列)
|
|
|
+ for (int col = 0; col <= 7; col++) {
|
|
|
+ cells.get(i, col).setStyle(style, styleFlag);
|
|
|
+ }
|
|
|
+ if (lastQaManager == null) {
|
|
|
+ // 第一次
|
|
|
+ lastQaManager = currentQaManager;
|
|
|
+ mergeStartRow = i;
|
|
|
+ } else if (!lastQaManager.equals(currentQaManager)) {
|
|
|
+ // QaManager 发生变化 → 合并上一段
|
|
|
+ if (i - mergeStartRow > 1) {
|
|
|
+ cells.merge(mergeStartRow, 4, i - mergeStartRow, 1);
|
|
|
+ cells.get(mergeStartRow, 4).setStyle(style, styleFlag);
|
|
|
+ }
|
|
|
+ // 更新起点
|
|
|
+ mergeStartRow = i;
|
|
|
+ lastQaManager = currentQaManager;
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ if (i - mergeStartRow > 1) {
|
|
|
+ cells.merge(mergeStartRow, 4, i - mergeStartRow, 1);
|
|
|
+ cells.get(mergeStartRow, 4).setStyle(style, styleFlag);
|
|
|
+ }
|
|
|
+
|
|
|
+ response.addHeader("Pargam", "no-cache");
|
|
|
+ response.addHeader("Cache-Control", "no-cache");
|
|
|
+ response.setContentType("application/octet-stream;charset=ISO8859-1");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=从QA导出.xlsx");
|
|
|
+ book.save(response.getOutputStream(), SaveFormat.XLSX);
|
|
|
+ book.dispose();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("导出失败{}",e);
|
|
|
+ throw new CustomException("导出失败,请联系管理员");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void exportPrjDataBySupervisor(Map<String, Object> map, HttpServletResponse response) {
|
|
|
+ Object fileIdObj = map.get("fileId");
|
|
|
+ if( ObjectUtil.isEmpty(fileIdObj)){
|
|
|
+ throw new CustomException("缺少参数,请联系管理员");
|
|
|
+ }
|
|
|
+ String fileId = (String) fileIdObj;
|
|
|
+ SysFileItemDo fileItemDo = fileItemService.getById(fileId);
|
|
|
+ if (!excelUtils.GetLicense()) {
|
|
|
+ log.info("缺少license");
|
|
|
+ throw new CustomException("导出错误,请联系系统管理员");
|
|
|
+ }
|
|
|
+ if(fileItemDo == null){
|
|
|
+ log.info("缺少监理模板");
|
|
|
+ throw new CustomException("导出失败,请联系管理员");
|
|
|
+ }
|
|
|
+
|
|
|
+ Workbook book = null;
|
|
|
+ try {
|
|
|
+ book = new Workbook(fileItemDo.getFullpath());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("导出失败{}",e);
|
|
|
+ throw new CustomException("导出失败,请联系管理员");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ SysUserVo currentUser = zhcxCommon.getCurrentUser();
|
|
|
+ map.put("tenantid",currentUser.getTenantid());
|
|
|
+ List<ProjectBySupervisorDto> list = zhcxProjectManageDao.getDataBySupervisor(map);
|
|
|
+// list.sort(
|
|
|
+// Comparator.comparing(
|
|
|
+// (ProjectBySupervisorDto p) -> {
|
|
|
+// String qa = p.getSupervisionnames();
|
|
|
+// return (qa == null || qa.trim().isEmpty()) ? null : qa;
|
|
|
+// },
|
|
|
+// Comparator.nullsLast(String::compareTo)
|
|
|
+// )
|
|
|
+// .thenComparing(
|
|
|
+// (ProjectBySupervisorDto p) -> {
|
|
|
+// String manager = p.getQamanager();
|
|
|
+// return (manager == null || manager.trim().isEmpty()) ? null : manager;
|
|
|
+// },
|
|
|
+// Comparator.nullsLast(String::compareTo)
|
|
|
+// ).thenComparing(
|
|
|
+// ProjectBySupervisorDto::getNumber,
|
|
|
+// Comparator.nullsLast(Comparator.reverseOrder())
|
|
|
+// )
|
|
|
+// );
|
|
|
+ String EMPTY_JL = "<EMPTY>";
|
|
|
+ Map<String, Long> supervisionCountMap = list.stream()
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ p -> {
|
|
|
+ String sup = p.getSupervisionnames();
|
|
|
+ return (sup == null || sup.trim().isEmpty()) ? EMPTY_JL : sup.trim();
|
|
|
+ },
|
|
|
+ Collectors.counting()
|
|
|
+ ));
|
|
|
+
|
|
|
+// 排序
|
|
|
+ list.sort(
|
|
|
+ Comparator.<ProjectBySupervisorDto, Long>comparing(
|
|
|
+ p -> supervisionCountMap.get(
|
|
|
+ (p.getSupervisionnames() == null || p.getSupervisionnames().trim().isEmpty())
|
|
|
+ ? EMPTY_JL
|
|
|
+ : p.getSupervisionnames().trim()
|
|
|
+ ),
|
|
|
+ Comparator.nullsLast(Comparator.reverseOrder()) // 数量多的在前,空的排最后
|
|
|
+ ).thenComparing(
|
|
|
+ p -> {
|
|
|
+ String qa = p.getQamanager();
|
|
|
+ return (qa == null || qa.trim().isEmpty()) ? null : qa.trim();
|
|
|
+ },
|
|
|
+ Comparator.nullsLast(String::compareTo) // qamanager 升序(空排最后)
|
|
|
+ )
|
|
|
+ );
|
|
|
+ WorksheetCollection worksheets = book.getWorksheets();
|
|
|
+ Worksheet worksheet = worksheets.get(0);
|
|
|
+ Cells cells = worksheet.getCells();
|
|
|
+ // 定义样式
|
|
|
+ Style style = book.createStyle();
|
|
|
+ style.setHorizontalAlignment(TextAlignmentType.CENTER); // 水平居中
|
|
|
+ style.setVerticalAlignment(TextAlignmentType.CENTER); // 垂直居中
|
|
|
+ style.setTextWrapped(true); // 自动换行(可选)
|
|
|
+
|
|
|
+ // 设置边框
|
|
|
+ style.setBorder(BorderType.TOP_BORDER, CellBorderType.THIN, Color.getBlack());
|
|
|
+ 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());
|
|
|
+
|
|
|
+ // 定义样式标记
|
|
|
+ StyleFlag styleFlag = new StyleFlag();
|
|
|
+ styleFlag.setBorders(true);
|
|
|
+ styleFlag.setHorizontalAlignment(true);
|
|
|
+ styleFlag.setVerticalAlignment(true);
|
|
|
+ styleFlag.setWrapText(true);
|
|
|
+ int i = 2;
|
|
|
+ int startRowCol2 = i; // supervisionnames 起始行
|
|
|
+ int startRowCol3 = i; // prjcount/设备数 起始行
|
|
|
+ int startRowCol6 = i; // qaManager 起始行
|
|
|
+
|
|
|
+ String lastSupervisionnames = null;
|
|
|
+ String lastPrjCountDevice = null;
|
|
|
+ String lastQaManager = null;
|
|
|
+ for (ProjectBySupervisorDto projectManageDo :list) {
|
|
|
+ int count = projectManageDo.getDevicecnout() == null ? 0 : projectManageDo.getDevicecnout();
|
|
|
+ String prjCountDevice = projectManageDo.getPrjcount() + "个\n(" + count+ ")台机";
|
|
|
+ cells.get(i, 0).putValue(i-1);
|
|
|
+ cells.get(i, 1).putValue(projectManageDo.getSupervisionnames());
|
|
|
+ cells.get(i, 2).putValue(prjCountDevice);
|
|
|
+ cells.get(i, 3).putValue(projectManageDo.getProjectname());
|
|
|
+ cells.get(i, 4).putValue(projectManageDo.getProjectcode());
|
|
|
+ cells.get(i, 5).putValue(projectManageDo.getNumber());
|
|
|
+ cells.get(i, 6).putValue(projectManageDo.getQamanager());
|
|
|
+ cells.get(i, 7).putValue(projectManageDo.getManagers());
|
|
|
+ cells.get(i, 8).putValue(projectManageDo.getStatus());
|
|
|
+// 设置样式
|
|
|
+ for (int col = 0; col <= 8; col++) {
|
|
|
+ cells.get(i, col).setStyle(style, styleFlag);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理第2列(supervisionnames)合并
|
|
|
+ if (lastSupervisionnames != null && !lastSupervisionnames.equals(projectManageDo.getSupervisionnames())) {
|
|
|
+ if (i - startRowCol2 > 1) {
|
|
|
+ worksheet.getCells().merge(startRowCol2, 1, i - startRowCol2, 1);
|
|
|
+ }
|
|
|
+ startRowCol2 = i;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理第3列(项目数/设备数)合并
|
|
|
+ if (lastPrjCountDevice != null && !lastPrjCountDevice.equals(prjCountDevice)) {
|
|
|
+ if (i - startRowCol3 > 1) {
|
|
|
+ worksheet.getCells().merge(startRowCol3, 2, i - startRowCol3, 1);
|
|
|
+ }
|
|
|
+ startRowCol3 = i;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理第6列(qaManager)合并
|
|
|
+ if (lastQaManager != null && !lastQaManager.equals(projectManageDo.getQamanager())) {
|
|
|
+ if (i - startRowCol6 > 1) {
|
|
|
+ worksheet.getCells().merge(startRowCol6, 6, i - startRowCol6, 1);
|
|
|
+ }
|
|
|
+ startRowCol6 = i;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新上一次的值
|
|
|
+ lastSupervisionnames = projectManageDo.getSupervisionnames();
|
|
|
+ lastPrjCountDevice = prjCountDevice;
|
|
|
+ lastQaManager = projectManageDo.getQamanager();
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ if (i - startRowCol2 > 1) {
|
|
|
+ worksheet.getCells().merge(startRowCol2, 1, i - startRowCol2, 1);
|
|
|
+ }
|
|
|
+ if (i - startRowCol3 > 1) {
|
|
|
+ worksheet.getCells().merge(startRowCol3, 2, i - startRowCol3, 1);
|
|
|
+ }
|
|
|
+ if (i - startRowCol6 > 1) {
|
|
|
+ worksheet.getCells().merge(startRowCol6, 6, i - startRowCol6, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ response.addHeader("Pargam", "no-cache");
|
|
|
+ response.addHeader("Cache-Control", "no-cache");
|
|
|
+ response.setContentType("application/octet-stream;charset=ISO8859-1");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=从QA导出.xlsx");
|
|
|
+ book.save(response.getOutputStream(), SaveFormat.XLSX);
|
|
|
+ book.dispose();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("导出失败{}",e);
|
|
|
+ throw new CustomException("导出失败,请联系管理员");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private static Integer extractNumber(String machineNo) {
|
|
|
if (machineNo == null || machineNo.isEmpty()) {
|
|
|
return Integer.MAX_VALUE; // Null 或空字符串视为最大值
|