|
@@ -1,28 +1,36 @@
|
|
|
package com.rongwei.bscommon.sys.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ArrayUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.aspose.cells.*;
|
|
|
import com.rongwei.bscommon.sys.dao.LuckysheetDao;
|
|
|
-import com.rongwei.bscommon.sys.service.ZhcxItpProjectNodesService;
|
|
|
-import com.rongwei.bscommon.sys.service.ZhcxProjectDeviceNumberService;
|
|
|
+import com.rongwei.bscommon.sys.service.*;
|
|
|
import com.rongwei.bscommon.sys.utils.ProjectSummaryExcelHelp;
|
|
|
+import com.rongwei.bsentity.domain.ZhcxProjectDeviceNumberDo;
|
|
|
import com.rongwei.bsentity.domain.ZhcxProjectManageDo;
|
|
|
import com.rongwei.bscommon.sys.dao.ZhcxProjectManageDao;
|
|
|
-import com.rongwei.bscommon.sys.service.ZhcxProjectManageService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.rongwei.bsentity.dto.project.CellChangeInfoDto;
|
|
|
-import com.rongwei.bsentity.dto.project.ProjectSummaryParamExcelDto;
|
|
|
-import com.rongwei.bsentity.dto.project.WorksheetSummaryDto;
|
|
|
+import com.rongwei.bsentity.domain.ZhcxProjectRectifyDo;
|
|
|
+import com.rongwei.bsentity.domain.ZhcxProjectRectifyMachineDo;
|
|
|
+import com.rongwei.bsentity.dto.project.*;
|
|
|
import com.rongwei.rwcommon.base.exception.CustomException;
|
|
|
+import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
import com.rongwei.rwcommoncomponent.excel.aspose.ExcelUtils;
|
|
|
import com.rongwei.rwcommoncomponent.file.dto.SysFileItemParamDto;
|
|
|
import com.rongwei.rwcommoncomponent.file.service.SysFileItemService;
|
|
|
import com.rongwei.rwcommonentity.commonservers.domain.SysFileItemDo;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -33,6 +41,7 @@ import java.util.List;
|
|
|
* @since 2024-06-28
|
|
|
*/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class ZhcxProjectManageServiceImpl extends ServiceImpl<ZhcxProjectManageDao, ZhcxProjectManageDo> implements ZhcxProjectManageService {
|
|
|
|
|
|
@Autowired
|
|
@@ -46,7 +55,13 @@ public class ZhcxProjectManageServiceImpl extends ServiceImpl<ZhcxProjectManageD
|
|
|
private ZhcxItpProjectNodesService itpProjectNodesService;
|
|
|
|
|
|
@Autowired
|
|
|
- private LuckysheetDao dao;
|
|
|
+ private LuckysheetDao luckysheetDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ZhcxProjectRectifyService projectRectifyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ZhcxProjectRectifyMachineService projectRectifyMachineService;
|
|
|
|
|
|
/**
|
|
|
* 生成汇总文件
|
|
@@ -99,6 +114,411 @@ public class ZhcxProjectManageServiceImpl extends ServiceImpl<ZhcxProjectManageD
|
|
|
return excelDto;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 保存汇总数据
|
|
|
+ *
|
|
|
+ * @param dto
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void saveSummaryData(SavePorjectSummaryDto dto) {
|
|
|
+
|
|
|
+ //单元格数据
|
|
|
+ JSONArray celldatas = dto.getSheetList().get(0).getJSONArray("celldata");
|
|
|
+ //标题
|
|
|
+ JSONObject prjTitle = getPrjTitle(celldatas);
|
|
|
+
|
|
|
+ //保存参数
|
|
|
+ SaveSummaryDataBo summaryDataBo = assembleSaveSummaryDataParam(dto);
|
|
|
+
|
|
|
+ //持久化
|
|
|
+ saveSummaryData2Db(prjTitle, celldatas, summaryDataBo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 持久化数据
|
|
|
+ *
|
|
|
+ * @param prjTitle
|
|
|
+ * @param celldatas
|
|
|
+ * @param summaryDataBo
|
|
|
+ */
|
|
|
+ private void saveSummaryData2Db(JSONObject prjTitle, JSONArray celldatas, SaveSummaryDataBo summaryDataBo) {
|
|
|
+
|
|
|
+ //1、删除已存在数据
|
|
|
+ projectRectifyService.delByPrjId(summaryDataBo.getProject().getId());
|
|
|
+
|
|
|
+ //2、组装数据并保存
|
|
|
+ //解析数据
|
|
|
+ Map<String, JSONObject> rowMap = cellMerge2Row(prjTitle, celldatas);
|
|
|
+ //保存
|
|
|
+ saveSummaryDataByRow(rowMap, summaryDataBo);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存
|
|
|
+ *
|
|
|
+ * @param rowMap
|
|
|
+ * @param summaryDataBo
|
|
|
+ */
|
|
|
+ private void saveSummaryDataByRow(Map<String, JSONObject> rowMap, SaveSummaryDataBo summaryDataBo) {
|
|
|
+
|
|
|
+ List<ZhcxProjectRectifyDo> mainList = new ArrayList<>();
|
|
|
+ List<ZhcxProjectRectifyMachineDo> slaveList = new ArrayList<>();
|
|
|
+ for (String rowIndex : rowMap.keySet()) {
|
|
|
+ JSONObject row = rowMap.get(rowIndex);
|
|
|
+ //主表
|
|
|
+ ZhcxProjectRectifyDo main = new ZhcxProjectRectifyDo();
|
|
|
+ main.setId(SecurityUtil.getUUID());
|
|
|
+ main.setDeleted("0");
|
|
|
+ //项目
|
|
|
+ main.setPrjid(summaryDataBo.getProject().getId());
|
|
|
+ main.setPrjcode(summaryDataBo.getProject().getProjectCode());
|
|
|
+ main.setPrjname(summaryDataBo.getProject().getProjectEname());
|
|
|
+
|
|
|
+ main.setSeqsort(row.getString("总序号"));
|
|
|
+ main.setSupervisorcode(row.getString("监理编号"));
|
|
|
+ main.setArcposition(row.getString("部位"));
|
|
|
+ main.setArccontent(row.getString("内容"));
|
|
|
+ main.setMainstatus(row.getString("总状态"));
|
|
|
+ main.setReqdate(row.getDate("提出日期"));
|
|
|
+ main.setRequser(row.getString("提出者"));
|
|
|
+ main.setRectifydate(row.getDate("整改日期"));
|
|
|
+ main.setRemark1(row.getString("备注1"));
|
|
|
+ main.setRemark2(row.getString("备注2"));
|
|
|
+
|
|
|
+ mainList.add(main);
|
|
|
+
|
|
|
+ JSONObject children = row.getJSONObject("children");
|
|
|
+ if(ObjectUtil.isNull(children)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //从表
|
|
|
+ for(String machineNo : children.keySet()) {
|
|
|
+
|
|
|
+ JSONObject machineObj = children.getJSONObject(machineNo);
|
|
|
+
|
|
|
+ ZhcxProjectRectifyMachineDo machine = new ZhcxProjectRectifyMachineDo();
|
|
|
+ machine.setPrjid(main.getPrjid());
|
|
|
+ machine.setRectifyid(main.getId());
|
|
|
+ machine.setDeleted("0");
|
|
|
+
|
|
|
+ machine.setMachineno(machineNo);
|
|
|
+ ZhcxProjectDeviceNumberDo numberDo = summaryDataBo.getPrjDeviceNumMap().get(machineNo);
|
|
|
+ machine.setMachineid(numberDo.getId());
|
|
|
+
|
|
|
+ machine.setFinishdate(machineObj.getDate("完成日期"));
|
|
|
+ machine.setStatus(machineObj.getString("状态"));
|
|
|
+
|
|
|
+ Map<String, JSONObject> orgMap = summaryDataBo.getOrgMap();
|
|
|
+
|
|
|
+ //责任部门
|
|
|
+ String departName = machineObj.getString("施工部门");
|
|
|
+ if(ObjectUtil.isNotEmpty(departName)
|
|
|
+ && (departName.contains(",") || departName.contains(",") || departName.contains("、"))) {
|
|
|
+ String[] departNames = null;
|
|
|
+ if(departName.contains(",")) {
|
|
|
+ departNames = departName.split(",");
|
|
|
+ } else if(departName.contains(",")) {
|
|
|
+ departNames = departName.split(",");
|
|
|
+ } else if(departName.contains("、")) {
|
|
|
+ departNames = departName.split("、");
|
|
|
+ }
|
|
|
+
|
|
|
+ for(String departNameTemp : departNames) {
|
|
|
+
|
|
|
+ ZhcxProjectRectifyMachineDo machineEntity = new ZhcxProjectRectifyMachineDo();
|
|
|
+ BeanUtil.copyProperties(machine, machineEntity);
|
|
|
+
|
|
|
+ JSONObject org = orgMap.get(departNameTemp);
|
|
|
+ machineEntity.setDeptid(org.getString("ID"));
|
|
|
+ machineEntity.setDeptname(departNameTemp);
|
|
|
+
|
|
|
+ machineEntity.setFirstdeptid(org.getString("PID"));
|
|
|
+ machineEntity.setFirstdeptname(org.getString("pshortName"));
|
|
|
+
|
|
|
+ machineEntity.setDutydeptid(org.getString("ID"));
|
|
|
+ machineEntity.setDutydeptname(departNameTemp);
|
|
|
+
|
|
|
+ machineEntity.setId(SecurityUtil.getUUID());
|
|
|
+ slaveList.add(machineEntity);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ //施工部门
|
|
|
+ if(ObjectUtil.isNotEmpty(departName)) {
|
|
|
+ JSONObject org = orgMap.get(departName);
|
|
|
+ machine.setDeptid(org.getString("ID"));
|
|
|
+ machine.setDeptname(departName);
|
|
|
+
|
|
|
+ machine.setFirstdeptid(org.getString("PID"));
|
|
|
+ machine.setFirstdeptname(org.getString("pshortName"));
|
|
|
+ }
|
|
|
+
|
|
|
+ //责任部门
|
|
|
+ String dutyDepartName = machineObj.getString("责任部门");
|
|
|
+ if(ObjectUtil.isNotEmpty(dutyDepartName)) {
|
|
|
+ JSONObject org = orgMap.get(dutyDepartName);
|
|
|
+ machine.setDutydeptid(org.getString("ID"));
|
|
|
+ machine.setDutydeptname(dutyDepartName);
|
|
|
+ }
|
|
|
+
|
|
|
+ machine.setId(SecurityUtil.getUUID());
|
|
|
+ slaveList.add(machine);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ObjectUtil.isNotEmpty(mainList)) {
|
|
|
+ projectRectifyService.saveBatch(mainList);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ObjectUtil.isNotEmpty(slaveList)) {
|
|
|
+ projectRectifyMachineService.saveBatch(slaveList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析数据
|
|
|
+ * {
|
|
|
+ * 总序号:'6'
|
|
|
+ * 部位: ''
|
|
|
+ * children: {
|
|
|
+ * 1#: {
|
|
|
+ * 状态: ''
|
|
|
+ * },
|
|
|
+ * 2#{
|
|
|
+ * 状态: ''
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * @param prjTitle
|
|
|
+ * @param celldatas
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Map<String, JSONObject> cellMerge2Row(JSONObject prjTitle, JSONArray celldatas) {
|
|
|
+ /**
|
|
|
+ * {
|
|
|
+ * 总序号:'6'
|
|
|
+ * 部位: ''
|
|
|
+ * children: {
|
|
|
+ * 1#: {
|
|
|
+ * 状态: ''
|
|
|
+ * },
|
|
|
+ * 2#{
|
|
|
+ * 状态: ''
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ */
|
|
|
+ Map<String, JSONObject> rows = new HashMap<>();
|
|
|
+ //遍历数据
|
|
|
+ for(int m = 0, n = celldatas.size(); m < n; m++) {
|
|
|
+ JSONObject cellData = celldatas.getJSONObject(m);
|
|
|
+
|
|
|
+ //从第4行开始为数据行
|
|
|
+ //行下标
|
|
|
+ int rowIdnex = cellData.getIntValue("r");
|
|
|
+ if(rowIdnex < 3) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //无值单元格不做任何处理
|
|
|
+ JSONObject v = cellData.getJSONObject("v");
|
|
|
+ if(ObjectUtil.isNull(v)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject row = rows.get(String.valueOf(rowIdnex));
|
|
|
+ if(ObjectUtil.isNull(row)) {
|
|
|
+ rows.put(String.valueOf(rowIdnex), new JSONObject());
|
|
|
+ row = rows.get(String.valueOf(rowIdnex));
|
|
|
+ }
|
|
|
+
|
|
|
+ //显示值
|
|
|
+ String m1 = v.getString("m");
|
|
|
+
|
|
|
+ //列下标
|
|
|
+ String colIndex = cellData.getString("c");
|
|
|
+ JSONObject titleInfo = prjTitle.getJSONObject(colIndex);
|
|
|
+ if("-1".equals(titleInfo.getString("parent"))) {
|
|
|
+ row.put(titleInfo.getString("value"), m1);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //机号下列表
|
|
|
+ JSONObject childrenRow = row.getJSONObject("children");
|
|
|
+ JSONObject deviceNumRow;
|
|
|
+ if(ObjectUtil.isNull(childrenRow)) {
|
|
|
+ row.put("children", new JSONObject());
|
|
|
+ childrenRow = row.getJSONObject("children");
|
|
|
+ childrenRow.put(titleInfo.getString("parent"), new JSONObject());
|
|
|
+ }
|
|
|
+
|
|
|
+ deviceNumRow = childrenRow.getJSONObject(titleInfo.getString("parent"));
|
|
|
+ if(ObjectUtil.isNull(deviceNumRow)) {
|
|
|
+ childrenRow.put(titleInfo.getString("parent"), new JSONObject());
|
|
|
+ deviceNumRow = childrenRow.getJSONObject(titleInfo.getString("parent"));
|
|
|
+ }
|
|
|
+
|
|
|
+ deviceNumRow.put(titleInfo.getString("value"), m1);
|
|
|
+ }
|
|
|
+
|
|
|
+ return rows;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存数据封装
|
|
|
+ *
|
|
|
+ * @param dto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private SaveSummaryDataBo assembleSaveSummaryDataParam(SavePorjectSummaryDto dto) {
|
|
|
+ //机号列表
|
|
|
+ List<ZhcxProjectDeviceNumberDo> deviceNumList = projectDeviceNumberService.getByProjectId(dto.getProjectId());
|
|
|
+ Map<String, ZhcxProjectDeviceNumberDo> deviceNumMap = new HashMap<>();
|
|
|
+ deviceNumList.forEach(item -> deviceNumMap.put(item.getDeviceNumber(), item));
|
|
|
+
|
|
|
+ //组织机构
|
|
|
+ List<JSONObject> workshopList = getWorkshop();
|
|
|
+ Map<String, JSONObject> workshopMap = new HashMap<>();
|
|
|
+ workshopList.forEach(item -> workshopMap.put(item.getString("SHORTNAME"), item));
|
|
|
+
|
|
|
+ //项目
|
|
|
+ ZhcxProjectManageDo project = getById(dto.getProjectId());
|
|
|
+
|
|
|
+ return SaveSummaryDataBo.builder()
|
|
|
+ .prjDeviceNumMap(deviceNumMap)
|
|
|
+ .orgMap(workshopMap)
|
|
|
+ .project(project)
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取项目标题
|
|
|
+ * 主要遍历前三行
|
|
|
+ *
|
|
|
+ * {
|
|
|
+ * 单元格列下标1: {
|
|
|
+ * parent: '-1',
|
|
|
+ * value: '总序号'
|
|
|
+ * },
|
|
|
+ * 单元格列下标2: {
|
|
|
+ * parent: '1#',
|
|
|
+ * value: '1#'
|
|
|
+ * }
|
|
|
+ * 单元格列下标3: {
|
|
|
+ * parent: '1#'
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * @param celldatas
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private JSONObject getPrjTitle(JSONArray celldatas) {
|
|
|
+ //项目
|
|
|
+ JSONObject prjTitle = new JSONObject();
|
|
|
+
|
|
|
+ String[] mainCols = { "总状态","提出日期","整改期限","提出者","备注1","备注2" };
|
|
|
+
|
|
|
+ //每个单元格
|
|
|
+ for(int m = 0, n = celldatas.size(); m < n; m++) {
|
|
|
+ //单元格
|
|
|
+ JSONObject celdata = celldatas.getJSONObject(m);
|
|
|
+
|
|
|
+ //行下标
|
|
|
+ int rowIndex = celdata.getIntValue("r"); //单元格列表
|
|
|
+
|
|
|
+ //第一行为数据标题,大于3行的为数据行,其他位置处理
|
|
|
+ if(rowIndex > 2 || rowIndex == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //列下标
|
|
|
+ String colIndex = celdata.getString("c");
|
|
|
+ //值
|
|
|
+ JSONObject v = celdata.getJSONObject("v");
|
|
|
+
|
|
|
+ //第二行
|
|
|
+ /**
|
|
|
+ * 第一行封装结构
|
|
|
+ * {
|
|
|
+ * 单元格列下标1: {
|
|
|
+ * parent: '-1',
|
|
|
+ * value: '总序号'
|
|
|
+ * },
|
|
|
+ * 单元格列下标2: {
|
|
|
+ * parent: '1#',
|
|
|
+ * value: '1#'
|
|
|
+ * }
|
|
|
+ * 单元格列下标3: {
|
|
|
+ * parent: '1#'
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ */
|
|
|
+ if(rowIndex == 1) {
|
|
|
+ //显示值
|
|
|
+ String m1 = v.getString("m");
|
|
|
+ JSONObject mc = v.getJSONObject("mc");
|
|
|
+
|
|
|
+ if(ObjectUtil.isNull(m1) && ObjectUtil.isNull(mc)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String mcc = mc.getString("c");
|
|
|
+ int mccs = mc.getIntValue("cs");
|
|
|
+
|
|
|
+ JSONObject titleValue = new JSONObject();
|
|
|
+ if(ObjectUtil.isNotEmpty(m1)) {
|
|
|
+ if(mccs > 1) {
|
|
|
+ titleValue.put("parent", m1);
|
|
|
+ } else {
|
|
|
+ titleValue.put("parent", "-1");
|
|
|
+ }
|
|
|
+ titleValue.put("value", m1);
|
|
|
+ } else {
|
|
|
+ String parent = prjTitle.getJSONObject(mcc).getString("value");
|
|
|
+ titleValue.put("parent", parent);
|
|
|
+ }
|
|
|
+ prjTitle.put(colIndex, titleValue);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //第三行标题
|
|
|
+ if(rowIndex == 2) {
|
|
|
+ //合并行
|
|
|
+ JSONObject mc = v.getJSONObject("mc");
|
|
|
+ if(ObjectUtil.isNotNull(mc)) {
|
|
|
+ int mcrInt = mc.getIntValue("r");
|
|
|
+ //合并行下标和当前行下标不一致,不做处理
|
|
|
+ if(mcrInt != rowIndex) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //显示值
|
|
|
+ String m1 = v.getString("m");
|
|
|
+
|
|
|
+ //最后几个主表字段处理
|
|
|
+ //跟第一行主表字段处理方式一致
|
|
|
+ if(ArrayUtil.contains(mainCols, m1)) {
|
|
|
+ JSONObject titleValue = new JSONObject();
|
|
|
+ titleValue.put("parent", "-1");
|
|
|
+ titleValue.put("value", m1);
|
|
|
+
|
|
|
+ prjTitle.put(colIndex, titleValue);
|
|
|
+ } else {
|
|
|
+ //单元格数据处理
|
|
|
+ prjTitle.getJSONObject(colIndex).put("value", m1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return prjTitle;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取车间列表
|
|
|
*
|
|
@@ -107,10 +527,10 @@ public class ZhcxProjectManageServiceImpl extends ServiceImpl<ZhcxProjectManageD
|
|
|
private List<JSONObject> getWorkshop() {
|
|
|
|
|
|
//正常组织结构
|
|
|
- List<JSONObject> workshopList = dao.getWorkshop();
|
|
|
+ List<JSONObject> workshopList = luckysheetDao.getWorkshop();
|
|
|
|
|
|
//额外数据字典中配置
|
|
|
- List<JSONObject> workshopDictList = dao.getWorkshopDict();
|
|
|
+ List<JSONObject> workshopDictList = luckysheetDao.getWorkshopDict();
|
|
|
|
|
|
workshopList.addAll(workshopDictList);
|
|
|
|