|
@@ -1,19 +1,50 @@
|
|
|
package org.springblade.business.controller;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import io.swagger.annotations.ApiParam;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.jsoup.Jsoup;
|
|
|
+import org.jsoup.nodes.Document;
|
|
|
+import org.springblade.business.dto.TrialSummaryRecordDTO;
|
|
|
+import org.springblade.business.dto.TrialSummaryRecordPageDTO;
|
|
|
+import org.springblade.business.entity.TrialSelfInspectionRecord;
|
|
|
+import org.springblade.business.entity.TrialSummaryRecord;
|
|
|
+import org.springblade.business.service.impl.TrialSelfInspectionRecordServiceImpl;
|
|
|
+import org.springblade.business.service.impl.TrialSummaryRecordServiceImpl;
|
|
|
+import org.springblade.business.utils.PdfGenerator;
|
|
|
+import org.springblade.business.vo.TrialSummaryRecordVO;
|
|
|
+import org.springblade.common.constant.CommonConstant;
|
|
|
+import org.springblade.common.utils.CommonUtil;
|
|
|
+import org.springblade.core.log.exception.ServiceException;
|
|
|
+import org.springblade.core.oss.model.BladeFile;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.core.tool.utils.*;
|
|
|
+import org.springblade.manager.entity.ContractInfo;
|
|
|
import org.springblade.manager.entity.TrialSummaryClassificationConfiguration;
|
|
|
+import org.springblade.manager.entity.TrialSummaryExcelTabReflection;
|
|
|
import org.springblade.resource.feign.NewIOSSClient;
|
|
|
+import org.springblade.system.cache.ParamCache;
|
|
|
+import org.springblade.system.entity.Dict;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.util.List;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@RestController
|
|
|
@AllArgsConstructor
|
|
@@ -23,12 +54,252 @@ public class TrialSummaryController {
|
|
|
|
|
|
private final JdbcTemplate jdbcTemplate;
|
|
|
private final NewIOSSClient newIOSSClient;
|
|
|
+ private final TrialSummaryRecordServiceImpl trialSummaryRecordServiceImpl;
|
|
|
+ private final TrialSelfInspectionRecordServiceImpl trialSelfInspectionRecordServiceImpl;
|
|
|
|
|
|
- @PostMapping("/list")
|
|
|
+ @GetMapping("/contract/list")
|
|
|
@ApiOperationSupport(order = 1)
|
|
|
+ @ApiOperation(value = "合同段下拉框", notes = "传入当前登陆选择的合同段id、项目id")
|
|
|
+ public R<Object> list(@RequestParam String contractId, @RequestParam String projectId) {
|
|
|
+ ContractInfo contractInfo = jdbcTemplate.query(
|
|
|
+ "SELECT * FROM m_contract_info WHERE is_deleted = 0 AND status = 1 AND id = ?",
|
|
|
+ new Object[]{contractId},
|
|
|
+ new BeanPropertyRowMapper<>(ContractInfo.class)
|
|
|
+ ).stream().findAny().orElse(null);
|
|
|
+ if (contractInfo != null && contractInfo.getContractType() == 4) {
|
|
|
+ List<ContractInfo> contractInfoList = jdbcTemplate.query(
|
|
|
+ "SELECT * FROM m_contract_info WHERE is_deleted = 0 AND status = 1 AND p_id = ? ORDER BY create_time",
|
|
|
+ new Object[]{projectId},
|
|
|
+ new BeanPropertyRowMapper<>(ContractInfo.class)
|
|
|
+ );
|
|
|
+ return R.data(contractInfoList);
|
|
|
+ }
|
|
|
+ return R.data(contractInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/list")
|
|
|
+ @ApiOperationSupport(order = 2)
|
|
|
@ApiOperation(value = "汇总分类列表", notes = "")
|
|
|
public R<List<TrialSummaryClassificationConfiguration>> list() {
|
|
|
return R.data(jdbcTemplate.query("SELECT * FROM m_trial_summary_classification_configuration WHERE is_deleted = 0 AND status = 1 ORDER BY sort,create_time", new BeanPropertyRowMapper<>(TrialSummaryClassificationConfiguration.class)));
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("/page")
|
|
|
+ @ApiOperationSupport(order = 3)
|
|
|
+ @ApiOperation(value = "分页查询", notes = "传入TrialSummaryRecordPageDTO")
|
|
|
+ public R<IPage<TrialSummaryRecordVO>> page(@RequestBody TrialSummaryRecordPageDTO dto) {
|
|
|
+ if (ObjectUtil.isEmpty(dto.getClassId()) || ObjectUtil.isEmpty(dto.getContractId())
|
|
|
+ || ObjectUtil.isEmpty(dto.getSize()) || ObjectUtil.isEmpty(dto.getCurrent())) {
|
|
|
+ throw new ServiceException("入参异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ int current = dto.getCurrent();
|
|
|
+ int size = dto.getSize();
|
|
|
+ List<Object> params = new ArrayList<>();
|
|
|
+ StringBuilder sqlString = new StringBuilder("SELECT * FROM u_trial_summary_record WHERE 1=1 AND is_deleted = 0 AND status = 1");
|
|
|
+ sqlString.append(" AND contract_id = ? AND class_id = ?");
|
|
|
+ params.add(dto.getContractId());
|
|
|
+ params.add(dto.getClassId());
|
|
|
+
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getDetectionType())) {
|
|
|
+ sqlString.append(" AND detection_type = ?");
|
|
|
+ params.add(dto.getDetectionType());
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getStartDate()) && ObjectUtil.isNotEmpty(dto.getEndDate())) {
|
|
|
+ sqlString.append(" AND start_date >= ? AND end_date <= ?");
|
|
|
+ params.add(dto.getStartDate());
|
|
|
+ params.add(dto.getEndDate());
|
|
|
+ }
|
|
|
+
|
|
|
+ String sqlCount = sqlString.toString().replace("*", "count(1)");
|
|
|
+ Optional<Integer> totalCountOptional = Optional.ofNullable(jdbcTemplate.queryForObject(sqlCount, Integer.class, params.toArray()));
|
|
|
+ int totalCount = totalCountOptional.orElse(0);
|
|
|
+
|
|
|
+ if (totalCount == 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlString.append(" ORDER BY create_time LIMIT ? OFFSET ?;");
|
|
|
+ params.add(size);
|
|
|
+ params.add((current - 1) * size);
|
|
|
+ String sqlPage = sqlString.toString();
|
|
|
+ List<TrialSummaryRecord> resultList = jdbcTemplate.query(
|
|
|
+ sqlPage,
|
|
|
+ new BeanPropertyRowMapper<>(TrialSummaryRecord.class),
|
|
|
+ params.toArray()
|
|
|
+ );
|
|
|
+
|
|
|
+ Map<Long, TrialSummaryClassificationConfiguration> classificationConfigurationMap = this.list().getData().stream().collect(Collectors.toMap(TrialSummaryClassificationConfiguration::getId, Function.identity()));
|
|
|
+ Map<String, Dict> dictMap = jdbcTemplate.query("SELECT dict_key,dict_value FROM blade_dict WHERE is_deleted = 0 AND code = 'trial_detection_category'", new BeanPropertyRowMapper<>(Dict.class)).stream().collect(Collectors.toMap(Dict::getDictKey, Function.identity()));
|
|
|
+
|
|
|
+ IPage<TrialSummaryRecordVO> page = new Page<>(current, size);
|
|
|
+ List<TrialSummaryRecordVO> collect = resultList.stream()
|
|
|
+ .map(obj -> {
|
|
|
+ TrialSummaryRecordVO vo = new TrialSummaryRecordVO();
|
|
|
+ BeanUtil.copyProperties(obj, vo);
|
|
|
+ vo.setClassIdName(classificationConfigurationMap.get(obj.getClassId()).getClassName());
|
|
|
+ vo.setDetectionTypeName(dictMap.get(obj.getDetectionType().toString()).getDictValue());
|
|
|
+ vo.setSummaryDateName(obj.getStartDate() + "~" + obj.getEndDate());
|
|
|
+ vo.setUnitTypeName(obj.getUnitType().equals(1) ? "施工" : "监理");
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ page.setRecords(collect);
|
|
|
+ page.setTotal(totalCount);
|
|
|
+ return R.data(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/save")
|
|
|
+ @ApiOperationSupport(order = 4)
|
|
|
+ @ApiOperation(value = "新增", notes = "传入TrialSummaryRecordDTO")
|
|
|
+ public R<Object> save(@RequestBody TrialSummaryRecordDTO dto) throws Exception {
|
|
|
+ if (ObjectUtil.isEmpty(dto.getClassId()) || ObjectUtil.isEmpty(dto.getContractId()) || ObjectUtil.isEmpty(dto.getDetectionType())
|
|
|
+ || ObjectUtil.isEmpty(dto.getUnitType()) || ObjectUtil.isEmpty(dto.getStartDate()) || ObjectUtil.isEmpty(dto.getEndDate())) {
|
|
|
+ throw new ServiceException("入参异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ String sn = this.build(dto);
|
|
|
+ if (ObjectUtil.isEmpty(sn)) {
|
|
|
+ throw new ServiceException("汇总编号构造异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ String sql_1 = "SELECT * FROM m_trial_summary_classification_configuration WHERE is_deleted = 0 AND status = 1 AND id = ?";
|
|
|
+ TrialSummaryClassificationConfiguration classC = jdbcTemplate.query(sql_1, new Object[]{dto.getClassId()}, new BeanPropertyRowMapper<>(TrialSummaryClassificationConfiguration.class)).stream().findAny().orElse(null);
|
|
|
+ if (classC != null && ObjectUtil.isNotEmpty(classC.getExcelId())
|
|
|
+ && ObjectUtil.isNotEmpty(classC.getHtmlUrl())
|
|
|
+ && ObjectUtil.isNotEmpty(classC.getTrialTreeIds())) {
|
|
|
+
|
|
|
+ LocalDate startDate = LocalDate.parse(dto.getStartDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ LocalDate endDate = LocalDate.parse(dto.getEndDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ List<TrialSelfInspectionRecord> records = trialSelfInspectionRecordServiceImpl.getBaseMapper().selectList(Wrappers.<TrialSelfInspectionRecord>lambdaQuery()
|
|
|
+ .in(TrialSelfInspectionRecord::getNodeId, Func.toLongList(classC.getTrialTreeIds()))
|
|
|
+ .eq(TrialSelfInspectionRecord::getContractId, dto.getContractId())
|
|
|
+ .eq(TrialSelfInspectionRecord::getDetectionCategory, dto.getDetectionType())
|
|
|
+ .between(TrialSelfInspectionRecord::getReportDate, startDate, endDate)
|
|
|
+ );
|
|
|
+
|
|
|
+ //TODO 会存在多个相同表,取数据应该取多组相同数据records的id对应实体表的group_id;生成的新的pdf数据还要入库,就是每个框框都要入库,后续其他接口还要使用
|
|
|
+
|
|
|
+
|
|
|
+ String sql_2 = "SELECT * FROM m_trial_summary_excel_tab_reflection WHERE excel_id = ?";
|
|
|
+ List<TrialSummaryExcelTabReflection> excelTabReflections = jdbcTemplate.query(sql_2, new Object[]{classC.getExcelId()}, new BeanPropertyRowMapper<>(TrialSummaryExcelTabReflection.class));
|
|
|
+ Map<String, List<TrialSummaryExcelTabReflection>> maps = excelTabReflections.stream()
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ reflection -> reflection.getTrialTabName() + "##" + reflection.getTrialTabId()
|
|
|
+ ));
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ for (Map.Entry<String, List<TrialSummaryExcelTabReflection>> entry : maps.entrySet()) {
|
|
|
+ String tabName = entry.getKey().split("##")[0];
|
|
|
+ String tabPkeyId = entry.getKey().split("##")[1];
|
|
|
+
|
|
|
+ List<TrialSummaryExcelTabReflection> value = entry.getValue();
|
|
|
+ Map<String, String> elementKeyWithHtmlKeyNameMap = value.stream().collect(Collectors.toMap(TrialSummaryExcelTabReflection::getElementKey, TrialSummaryExcelTabReflection::getHtmlKeyName));
|
|
|
+ Set<String> elementKeys = elementKeyWithHtmlKeyNameMap.keySet();
|
|
|
+
|
|
|
+ String sql_3 = "SELECT " + String.join(",", elementKeys) + " FROM " + tabName + " WHERE p_key_id = " + tabPkeyId + " ";
|
|
|
+ Map<String, Object> tabDataMap = jdbcTemplate.queryForMap(sql_3);
|
|
|
+
|
|
|
+ for (String elementKey : elementKeys) {
|
|
|
+ String htmlKeyName = elementKeyWithHtmlKeyNameMap.getOrDefault(elementKey, null);
|
|
|
+ if (ObjectUtil.isEmpty(htmlKeyName)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Object tabData = tabDataMap.getOrDefault(elementKey, null);
|
|
|
+ map.put(htmlKeyName, tabData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String htmlString = this.html(classC.getHtmlUrl());
|
|
|
+ String assign = this.replace(htmlString, map);
|
|
|
+ MultipartFile pdfFile = PdfGenerator.generatePdf(assign);
|
|
|
+ if (pdfFile != null) {
|
|
|
+ BladeFile bladeFile = newIOSSClient.uploadFileByInputStream(pdfFile);
|
|
|
+ if (bladeFile != null) {
|
|
|
+ TrialSummaryRecord obj = BeanUtil.copyProperties(dto, TrialSummaryRecord.class);
|
|
|
+ if (obj != null) {
|
|
|
+ obj.setSummaryNumber(sn);
|
|
|
+ obj.setPdfUrl(bladeFile.getLink());
|
|
|
+ if (trialSummaryRecordServiceImpl.save(obj)) {
|
|
|
+ return R.success("操作成功");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.fail("操作失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ private String html(String fileUrl) throws Exception {
|
|
|
+ String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
|
|
|
+ String sys_file_net_url = ParamCache.getValue(CommonConstant.SYS_FILE_NET_URL);
|
|
|
+ File file1 = ResourceUtil.getFile(fileUrl);
|
|
|
+ InputStream fileInputStream;
|
|
|
+ if (file1.exists()) {
|
|
|
+ fileInputStream = new FileInputStream(file1);
|
|
|
+ } else {
|
|
|
+ String path = sys_file_net_url + fileUrl.replaceAll("//", "/").replaceAll(file_path, "");
|
|
|
+ fileInputStream = CommonUtil.getOSSInputStream(path);
|
|
|
+ }
|
|
|
+ String htmlString = IoUtil.readToString(fileInputStream);
|
|
|
+ htmlString = htmlString.replaceAll("placeholder", "placeholderxx");
|
|
|
+ Document doc = Jsoup.parse(htmlString);
|
|
|
+ return doc.select("table").first() + "";
|
|
|
+ }
|
|
|
+
|
|
|
+ private String replace(String template, Map<String, Object> values) {
|
|
|
+ String patternString = "\\{(\\w+)}";
|
|
|
+ Pattern pattern = Pattern.compile(patternString);
|
|
|
+ Matcher matcher = pattern.matcher(template);
|
|
|
+ StringBuffer result = new StringBuffer();
|
|
|
+ while (matcher.find()) {
|
|
|
+ String key = matcher.group(1);
|
|
|
+ if (values.containsKey(key)) {
|
|
|
+ matcher.appendReplacement(result, values.get(key).toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ matcher.appendTail(result);
|
|
|
+ return result + "";
|
|
|
+ }
|
|
|
+
|
|
|
+ private String build(TrialSummaryRecordDTO dto) {
|
|
|
+ List<TrialSummaryRecord> trialSummaryRecords = trialSummaryRecordServiceImpl.getBaseMapper().selectList(Wrappers.<TrialSummaryRecord>lambdaQuery()
|
|
|
+ .select(TrialSummaryRecord::getSummaryNumber)
|
|
|
+ .eq(TrialSummaryRecord::getClassId, dto.getClassId())
|
|
|
+ .eq(TrialSummaryRecord::getContractId, dto.getContractId())
|
|
|
+ );
|
|
|
+
|
|
|
+ if (trialSummaryRecords.isEmpty()) {
|
|
|
+ return "HZ-0001";
|
|
|
+ }
|
|
|
+
|
|
|
+ Pattern pattern = Pattern.compile("HZ-(\\d+)");
|
|
|
+ int maxNumber = trialSummaryRecords.stream()
|
|
|
+ .map(TrialSummaryRecord::getSummaryNumber)
|
|
|
+ .map(pattern::matcher)
|
|
|
+ .filter(Matcher::find)
|
|
|
+ .map(matcher -> Integer.parseInt(matcher.group(1)))
|
|
|
+ .max(Integer::compareTo)
|
|
|
+ .orElse(0);
|
|
|
+ int newNumber = maxNumber + 1;
|
|
|
+ if (newNumber > 9999) {
|
|
|
+ throw new RuntimeException("已达到编号上限");
|
|
|
+ }
|
|
|
+ return String.format("HZ-%04d", newNumber);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/remove")
|
|
|
+ @ApiOperationSupport(order = 4)
|
|
|
+ @ApiOperation(value = "删除", notes = "传入page接口的id,英文逗号字符串拼接成ids")
|
|
|
+ public R<Object> remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
|
|
|
+ return R.status(trialSummaryRecordServiceImpl.deleteLogic(Func.toLongList(ids)));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/download")
|
|
|
+ @ApiOperationSupport(order = 5)
|
|
|
+ @ApiOperation(value = "下载", notes = "")
|
|
|
+ public R<Object> download() {
|
|
|
+ //TODO
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|