|
@@ -1,29 +1,64 @@
|
|
|
package com.huashe.park.core.service.impl;
|
|
|
|
|
|
+import java.io.BufferedInputStream;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.huashe.common.exception.ServiceException;
|
|
|
import com.huashe.park.common.EnhancedIDGenerator;
|
|
|
+import com.huashe.park.common.consts.enums.ConsStatus;
|
|
|
+import com.huashe.park.common.excel.CsvAlias;
|
|
|
import com.huashe.park.common.i18n.MessageUtils;
|
|
|
import com.huashe.park.core.mapper.ConsUnitInfoMapper;
|
|
|
import com.huashe.park.core.service.IConsPileHoleInfoService;
|
|
|
import com.huashe.park.core.service.IConsUnitInfoService;
|
|
|
import com.huashe.park.core.service.IConsUnitMachineRelService;
|
|
|
+import com.huashe.park.core.service.IMachineProcessResultService;
|
|
|
+import com.huashe.park.core.service.IPileMachineInfoService;
|
|
|
+import com.huashe.park.core.service.IProjectInfoService;
|
|
|
+import com.huashe.park.core.service.ISysCustConfigService;
|
|
|
+import com.huashe.park.domain.dto.cons.CADJson;
|
|
|
import com.huashe.park.domain.dto.cons.ConsUnitMachine;
|
|
|
+import com.huashe.park.domain.dto.cons.ResultCADCsv;
|
|
|
import com.huashe.park.domain.entity.ConsPileHoleInfo;
|
|
|
import com.huashe.park.domain.entity.ConsUnitInfo;
|
|
|
import com.huashe.park.domain.entity.ConsUnitMachineRel;
|
|
|
+import com.huashe.park.domain.entity.CustSysConfig;
|
|
|
+import com.huashe.park.domain.entity.PileMachineInfo;
|
|
|
+import com.huashe.park.domain.entity.ProjectInfo;
|
|
|
+import com.huashe.park.infrastructure.cfg.forest.CADForestCfg;
|
|
|
import com.huashe.park.infrastructure.excel.ExcelHandle;
|
|
|
import com.ruoyi.common.config.RuoYiConfig;
|
|
|
+import com.ruoyi.common.utils.file.FileUtils;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.ListUtil;
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.text.csv.CsvUtil;
|
|
|
+import cn.hutool.core.text.csv.CsvWriteConfig;
|
|
|
+import cn.hutool.core.text.csv.CsvWriter;
|
|
|
+import cn.hutool.core.util.CharsetUtil;
|
|
|
+import cn.hutool.core.util.ReflectUtil;
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
/**
|
|
|
* 施工单元Service业务层处理
|
|
@@ -32,6 +67,7 @@ import com.ruoyi.common.config.RuoYiConfig;
|
|
|
* @date 2025-02-14
|
|
|
*/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class ConsUnitInfoServiceImpl implements IConsUnitInfoService {
|
|
|
|
|
|
@Autowired
|
|
@@ -41,6 +77,12 @@ public class ConsUnitInfoServiceImpl implements IConsUnitInfoService {
|
|
|
private IConsUnitMachineRelService consUnitMachineRelService;
|
|
|
|
|
|
@Autowired
|
|
|
+ private IPileMachineInfoService pileMachineInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IMachineProcessResultService machineProcessResultService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private IConsPileHoleInfoService pileHoleInfoService;
|
|
|
|
|
|
@Autowired
|
|
@@ -51,6 +93,15 @@ public class ConsUnitInfoServiceImpl implements IConsUnitInfoService {
|
|
|
@Autowired
|
|
|
private EnhancedIDGenerator byte8Id;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISysCustConfigService sysCustConfigService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CADForestCfg cadForestCfg;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IProjectInfoService projectInfoService;
|
|
|
+
|
|
|
/**
|
|
|
* 查询施工单元
|
|
|
*
|
|
@@ -170,14 +221,82 @@ public class ConsUnitInfoServiceImpl implements IConsUnitInfoService {
|
|
|
int lastIndex = RuoYiConfig.getUploadPath().lastIndexOf("/");
|
|
|
String filePath = consUnitHole.getFileId().replaceFirst(PROFILE,
|
|
|
RuoYiConfig.getUploadPath().substring(0, lastIndex));
|
|
|
+ consUnitHole.setFileId(filePath);
|
|
|
consUnitInfoMapper.updateConsUnitInfo(consUnitHole);
|
|
|
+ // filePath 读取成 File
|
|
|
+ File file = new File(filePath);
|
|
|
+
|
|
|
+ CustSysConfig custSysConfig = sysCustConfigService.selectConfigObjByKey(cadForestCfg.getCadBizParam());
|
|
|
+ HttpRequest form = HttpRequest.post(cadForestCfg.getCadServer() + "/upload").form("dwg_file", file)
|
|
|
+ .form("param", custSysConfig.getCfgJson());
|
|
|
+ log.info(">>>>>>>>>>>>{}", form.toString());
|
|
|
+ String json = form.execute().body();
|
|
|
+ List<CADJson> cadJsons = JSONArray.parseArray(json, CADJson.class);
|
|
|
pileHoleInfoService.deleteConsPileHoleInfoByConsUnitId(consUnitHole.getId());
|
|
|
- excelHandle.importExcel(filePath, ConsPileHoleInfo.class, (data) -> {
|
|
|
- data.forEach((d) -> {
|
|
|
- d.setConsUnitId(consUnitHole.getId());
|
|
|
+ List<ConsPileHoleInfo> consPileHoleInfo = new ArrayList<>(cadJsons.size());
|
|
|
+ cadJsons.stream().filter(Objects::nonNull).forEach(item -> {
|
|
|
+ consPileHoleInfo.add(new ConsPileHoleInfo() {
|
|
|
+ {
|
|
|
+ setConsUnitId(consUnitHole.getId());
|
|
|
+ setDeltaX(item.getCoordX());
|
|
|
+ setDeltaY(item.getCoordY());
|
|
|
+ setLng(item.getEarthCoordX());
|
|
|
+ setLat(item.getEarthCoordY());
|
|
|
+ setHoleNum(item.getPileNumber());
|
|
|
+ setConsStatus(ConsStatus.CONS_STATUS_01.getCode());
|
|
|
+ setDesDept(40L);
|
|
|
+ }
|
|
|
});
|
|
|
- pileHoleInfoService.importConsPileHole(data);
|
|
|
});
|
|
|
+ // 将 cadJsons,分拆成 100个 List<ConsPileHoleInfo>,批量插入
|
|
|
+ List<List<ConsPileHoleInfo>> data = ListUtil.partition(consPileHoleInfo, 100);
|
|
|
+ for (List<ConsPileHoleInfo> datum : data) {
|
|
|
+ pileHoleInfoService.importConsPileHole(datum);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void exportConsUnitHole(ConsUnitInfo consUnitHole, HttpServletResponse response) {
|
|
|
+ ConsUnitInfo consUnitInfo = consUnitInfoMapper.selectConsUnitInfoById(consUnitHole.getId());
|
|
|
+ // String filePath = consUnitHole.getFileId().replaceFirst(PROFILE,
|
|
|
+ // RuoYiConfig.getUploadPath().substring(0, lastIndex));
|
|
|
+ // consUnitHole.setFileId(filePath);
|
|
|
+ // consUnitInfoMapper.updateConsUnitInfo(consUnitHole);
|
|
|
+ // filePath 读取成 File
|
|
|
+ File file = new File(consUnitInfo.getFileId());
|
|
|
+ File csvFile = new File(
|
|
|
+ "E:\\opt\\project\\ruoyi\\ruoyi-backend\\upload-file-path\\upload\\2025\\03\\10\\1.csv");
|
|
|
+ response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
+ InputStream dwgFile = HttpRequest.post(cadForestCfg.getCadServer() + "/download").form("dwg_file", file)
|
|
|
+ .form("csv_file", csvFile).execute().bodyStream();
|
|
|
+ // 创建一个BufferedInputStream来缓冲输入流,提高读取效率
|
|
|
+ BufferedInputStream bis = new BufferedInputStream(dwgFile);
|
|
|
+ try {
|
|
|
+
|
|
|
+ FileUtils.setAttachmentResponseHeader(response, file.getName());
|
|
|
+ ServletOutputStream outputStream = response.getOutputStream();
|
|
|
+ byte[] buffer = new byte[1024]; // 定义一个缓冲区
|
|
|
+ int bytesRead;
|
|
|
+
|
|
|
+ // 读取数据并写入到response的输出流中
|
|
|
+ while ((bytesRead = bis.read(buffer)) != -1) {
|
|
|
+ outputStream.write(buffer, 0, bytesRead);
|
|
|
+ }
|
|
|
+ // 刷新并关闭流
|
|
|
+ outputStream.flush();
|
|
|
+ }
|
|
|
+ catch (IOException e) {
|
|
|
+ log.error("download input stream: {}", e.getMessage());
|
|
|
+ }
|
|
|
+ finally {
|
|
|
+ try {
|
|
|
+ // 确保关闭输入流
|
|
|
+ bis.close();
|
|
|
+ }
|
|
|
+ catch (IOException e) {
|
|
|
+ log.error("Error closing input stream: {}", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -217,4 +336,56 @@ public class ConsUnitInfoServiceImpl implements IConsUnitInfoService {
|
|
|
consUnitMachineRelService.insertConsUnitMachineRelList(consUnitMachineRel);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private void generatePileHoleFile(ConsUnitInfo consUnitInfo) {
|
|
|
+ List<ProjectInfo> projectInfos = projectInfoService.selectProjectInfoList(new ProjectInfo());
|
|
|
+
|
|
|
+ ProjectInfo projectInfo = projectInfos.get(0);
|
|
|
+ CsvWriteConfig csvWriteConfig = new CsvWriteConfig();
|
|
|
+ Field[] fields = ReflectUtil.getFields(ConsUnitInfo.class);
|
|
|
+ for (Field field : fields) {
|
|
|
+ CsvAlias annotation = field.getAnnotation(CsvAlias.class);
|
|
|
+ if (annotation != null) {
|
|
|
+ csvWriteConfig.addHeaderAlias(field.getName(), annotation.alias());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ CsvWriter writer = CsvUtil.getWriter(FileUtil.file("e:/testWrite.csv"), CharsetUtil.CHARSET_UTF_8, true,
|
|
|
+ csvWriteConfig);
|
|
|
+ List<String[]> header = new ArrayList<>();
|
|
|
+ // 按行写出
|
|
|
+ header.add(new String[] {
|
|
|
+ "Project Name :", projectInfo.getName()
|
|
|
+ });
|
|
|
+
|
|
|
+ List<PileMachineInfo> pileMachineInfos = pileMachineInfoService.qryUnitMachine(consUnitInfo.getId());
|
|
|
+ if (!CollectionUtils.isEmpty(pileMachineInfos)) {
|
|
|
+ List<String> machineNum = pileMachineInfos.stream().map(PileMachineInfo::getMachineNum)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ header.add(new String[] {
|
|
|
+ "Machine Number :", String.join("|", machineNum)
|
|
|
+ });
|
|
|
+ List<String> equipment = pileMachineInfos.stream().map(PileMachineInfo::getEquipment)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ header.add(new String[] {
|
|
|
+ "Equipment Number :", String.join("|", equipment)
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ header.add(new String[] {
|
|
|
+ "Machine Number :", ""
|
|
|
+ });
|
|
|
+ header.add(new String[] {
|
|
|
+ "Equipment Number :", ""
|
|
|
+ });
|
|
|
+ }
|
|
|
+ header.add(new String[] {
|
|
|
+ "Cluster Number :", ""
|
|
|
+ });
|
|
|
+ header.add(new String[] {
|
|
|
+ "Operator Name :", ""
|
|
|
+ });
|
|
|
+ writer.write(header);
|
|
|
+ List<ResultCADCsv> resultCADCsvs = machineProcessResultService.qeyConsUnitResult(consUnitInfo.getId());
|
|
|
+ writer.writeBeans(resultCADCsvs);
|
|
|
+ }
|
|
|
}
|