Browse Source

委托单页面填报表单信息的页面材料信息基本数据回显修改,修复试验检测记录编号和报告编号与客户填写的编号不一致的情况

DengLinLang 2 months ago
parent
commit
13e20c9bd4

+ 68 - 1
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/TrialSelfInspectionRecordServiceImpl.java

@@ -2,6 +2,7 @@ package org.springblade.business.service.impl;
 
 import cn.hutool.core.date.LocalDateTimeUtil;
 import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
@@ -13,6 +14,10 @@ import com.spire.xls.Workbook;
 import com.spire.xls.Worksheet;
 import lombok.AllArgsConstructor;
 import org.apache.commons.lang.time.DateUtils;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
 import org.springblade.business.dto.*;
 import org.springblade.business.entity.*;
 import org.springblade.business.mapper.EntrustInfoMapper;
@@ -59,6 +64,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import java.io.File;
 import java.io.FileNotFoundException;
+import java.io.InputStream;
 import java.util.*;
 import java.util.function.Function;
 import java.util.stream.Collectors;
@@ -981,7 +987,8 @@ public class TrialSelfInspectionRecordServiceImpl extends BaseServiceImpl<TrialS
         if (ObjectUtil.isNotEmpty(dto.getId())) {
             //------获取最新试验记录------
             TrialSelfInspectionRecord obj = baseMapper.selectById(dto.getId());
-
+            //如果传递了就修改对应记录的值
+            this.updateRecordNoOrReportNo(obj, dto);
             //------编辑时记录表编号或报告单编号为Null的重新生成------
             this.reBuildNumber(obj, dto);
 
@@ -1007,6 +1014,66 @@ public class TrialSelfInspectionRecordServiceImpl extends BaseServiceImpl<TrialS
         return dto.getId().toString();
     }
 
+    /**
+     * 取到传入的表单中的报告编号或者记录编号 修改记录表中相应字段的值
+     * @param obj
+     * @param dto
+     */
+    private void updateRecordNoOrReportNo(TrialSelfInspectionRecord obj, TrialSelfInspectionRecordDTO dto) {
+        JSONArray dataArray = dto.getDataInfo().getJSONArray("orderList");
+        for (int i = 0; i < dataArray.size(); i++) {
+            JSONObject jsonObject = dataArray.getJSONObject(i);
+            String pkeyId = jsonObject.getString("pkeyId");
+            String sql = "select * from m_wbs_tree_private where p_key_id =" + pkeyId;
+            WbsTreePrivate table = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(WbsTreePrivate.class));
+            String fileUrl = table.getHtmlUrl();
+            try {
+                InputStream fileInputStream = FileUtils.getInputStreamByUrl(fileUrl);
+                String htmlString = IoUtil.readToString(fileInputStream);
+                htmlString = htmlString.replaceAll("placeholder", "placeholderxx");
+                Document doc = Jsoup.parse(htmlString);
+                // 查找所有具有 placeholderxx 属性的元素
+                //表类型 1=记录表 2=报告单 ,字符串拼接
+                String tableType = dto.getTableType();
+                String[] singleTableType = tableType.split(",");
+                if("1".equals(singleTableType[i])){
+                    //记录表
+                    this.updateRecordNoOrReportNo(dto,jsonObject,doc,"记录编 号:","record_no");
+                }else if("2".equals(singleTableType[i])){
+                    //报告单
+                    this.updateRecordNoOrReportNo(dto,jsonObject,doc,"报告编号:","report_no");
+                }
+            } catch (Exception e) {
+
+            }
+
+        }
+    }
+
+    /**
+     * 修改记录编号或者报告编号的值
+     * @param dto
+     * @param jsonObject
+     * @param doc
+     * @param value
+     * @param fileVlue
+     */
+    private void updateRecordNoOrReportNo(TrialSelfInspectionRecord dto,JSONObject jsonObject,Document doc,String  value, String fileVlue) {
+        Elements elementsWithPlaceholderxx = doc.select("[placeholderxx="+value+"]");
+        if((elementsWithPlaceholderxx.size() == 0 ||elementsWithPlaceholderxx == null) && value.equals("报告编号:")){
+            value = "编号:";
+            elementsWithPlaceholderxx = doc.select("[placeholderxx="+value+"]");
+        }
+        Element first = elementsWithPlaceholderxx.first();
+        String key = first.attr("id");
+        //记录编号或者报告编号的值
+        String recordOrReportNo = jsonObject.getString(key);
+        if(!"".equals(recordOrReportNo) && !(recordOrReportNo == null)){
+            String updateSql = "update u_trial_self_inspection_record set " + fileVlue +"='" + recordOrReportNo + "' where id='" + dto.getId()+"'";
+            jdbcTemplate.execute(updateSql);
+        }
+    }
+
     public void initBuildNumber(TrialSelfInspectionRecordDTO dto) {
         if (ObjectUtil.isEmpty(dto.getId()) && StringUtils.isNotEmpty(dto.getTableType())) {
             //构建记录表编号、报告单编号

+ 15 - 5
blade-service/blade-business/src/main/java/org/springblade/business/utils/FileUtils.java

@@ -2,16 +2,15 @@ package org.springblade.business.utils;
 
 import com.drew.imaging.ImageMetadataReader;
 import com.drew.imaging.ImageProcessingException;
-import com.drew.metadata.Directory;
 import com.drew.metadata.Metadata;
 import com.drew.metadata.MetadataException;
 import com.drew.metadata.exif.ExifIFD0Directory;
-import com.drew.metadata.exif.ExifSubIFDDirectory;
 import com.itextpdf.text.Document;
 import com.itextpdf.text.pdf.PdfCopy;
 import com.itextpdf.text.pdf.PdfReader;
 import org.apache.commons.lang.StringUtils;
-import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.usermodel.ClientAnchor;
+import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.util.Units;
 import org.springblade.common.constant.CommonConstant;
@@ -25,10 +24,8 @@ import javax.imageio.IIOImage;
 import javax.imageio.ImageIO;
 import javax.imageio.ImageWriteParam;
 import javax.imageio.ImageWriter;
-import javax.imageio.stream.ImageOutputStream;
 import javax.servlet.http.HttpServletResponse;
 import java.awt.*;
-import java.awt.Color;
 import java.awt.geom.AffineTransform;
 import java.awt.image.AffineTransformOp;
 import java.awt.image.BufferedImage;
@@ -346,6 +343,19 @@ public class FileUtils {
         }
         return file_path;
     }
+    // 获取本地 或 远程工作流ParamCache
+    public static InputStream getInputStreamByUrl(String fileUrl) throws Exception {
+
+        File file1 = new File(fileUrl);
+        InputStream fileInputStream = null;
+        if (file1.exists()) {
+            fileInputStream = new FileInputStream(file1);
+        } else {
+            String path = getNetUrl(fileUrl);
+            fileInputStream = CommonUtil.getOSSInputStream(path);
+        }
+        return fileInputStream;
+    }
 
     public static String getNetUrl(String fileUrl){
         String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);

+ 2 - 2
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/ExcelTabController.java

@@ -3618,8 +3618,8 @@ public class ExcelTabController extends BladeController {
             @ApiImplicitParam(name = "id", value = "记录id-当做groupId", required = true),
             @ApiImplicitParam(name = "contractId", value = "合同段id", required = true)
     })
-    public R<List<Map<String, Object>>> getBussDataInfoTrial(Long id, Long pkeyId, Long contractId) {
-        List<Map<String, Object>> bussDataInfoTrial = excelTabService.getBussDataInfoTrial(id, pkeyId, contractId);
+    public R<List<Map<String, Object>>> getBussDataInfoTrial(Long id, Long pkeyId, Long contractId, Long entrustId) {
+        List<Map<String, Object>> bussDataInfoTrial = excelTabService.getBussDataInfoTrial(id, pkeyId, contractId, entrustId);
         return R.data(bussDataInfoTrial);
     }
 

+ 1 - 5
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/WbsTreePrivateController.java

@@ -1,14 +1,11 @@
 package org.springblade.manager.controller;
 
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import com.mixsmart.utils.StringUtils;
 import io.swagger.annotations.*;
 import lombok.AllArgsConstructor;
-import oracle.jdbc.proxy.annotation.Post;
-import org.springblade.business.entity.TrialSelfInspectionRecord;
 import org.springblade.business.vo.SaveLogContractVO;
 import org.springblade.common.utils.SnowFlakeUtil;
 import org.springblade.core.boot.ctrl.BladeController;
@@ -36,7 +33,6 @@ import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
-
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.*;
@@ -701,7 +697,7 @@ public class WbsTreePrivateController extends BladeController {
                 }
 
                 //表单数据
-                List<Map<String, Object>> bussDataInfoTrial = iExcelTabService.getBussDataInfoTrial(id, treePrivate.getPKeyId(), Long.parseLong(contractId));
+                List<Map<String, Object>> bussDataInfoTrial = iExcelTabService.getBussDataInfoTrial(id, treePrivate.getPKeyId(), Long.parseLong(contractId),null);
                 if (bussDataInfoTrial != null && bussDataInfoTrial.size() > 0) {
                     bussDataInfoTrial.get(0).remove("group_id");
                     treePrivate.setBussDataInfoTrial(bussDataInfoTrial.get(0));

+ 1 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/feign/WbsTreePrivateClientImpl.java

@@ -213,7 +213,7 @@ public class WbsTreePrivateClientImpl implements WbsTreePrivateClient {
 
     @Override
     public List<Map<String, Object>> getTrialDataInfo(String pKeyId, Long id) {
-        return excelTabServiceImpl.getBussDataInfoTrial(id, Long.parseLong(pKeyId), null);
+        return excelTabServiceImpl.getBussDataInfoTrial(id, Long.parseLong(pKeyId), null,null);
     }
 
     @Override

+ 1 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/service/IExcelTabService.java

@@ -136,7 +136,7 @@ public interface IExcelTabService extends BaseService<ExcelTab> {
     /**
      * 获取试验用户端 单个表单接口数据
      */
-    List<Map<String, Object>> getBussDataInfoTrial(Long id, Long pkeyId, Long contractId);
+    List<Map<String, Object>> getBussDataInfoTrial(Long id, Long pkeyId, Long contractId, Long entrustId);
 
     /**
      * 获取试验用户端 单个表单接口数据 - 关联施工

+ 53 - 33
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ExcelTabServiceImpl.java

@@ -2411,7 +2411,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
      * 试验 获取填报信息
      */
     @Override
-    public List<Map<String, Object>> getBussDataInfoTrial(Long groupId, Long pkeyId, Long contractId) {
+    public List<Map<String, Object>> getBussDataInfoTrial(Long groupId, Long pkeyId, Long contractId, Long entrustId) {
         String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
         String sys_file_net_url = ParamCache.getValue(CommonConstant.SYS_FILE_NET_URL);
         List<Map<String, Object>> list = new ArrayList<>();
@@ -2469,6 +2469,26 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
             htmlString = htmlString.replaceAll("placeholder", "placeholderxx");
             htmlString = htmlString.replaceAll("title", "titlexx");
             Document doc = Jsoup.parse(htmlString);
+            if(entrustId != null){
+                //有委托单信息是从实验报告关联委托单进来的 通过委托单查询到具体的样品id
+                String sql = "select * from u_entrust_info where id ="+entrustId;
+                EntrustInfo entrustInfo = jdbcTemplate.queryForObject(sql,new BeanPropertyRowMapper<>(EntrustInfo.class));
+                String  sampleId= entrustInfo.getSampleId().toString();
+                String querySql1 = "select * from u_trial_sample_info where id=" + sampleId ;
+                TrialSampleInfo sampleInfo = jdbcTemplate.queryForObject(querySql1, new BeanPropertyRowMapper<>(TrialSampleInfo.class));
+                //用sampleId查询出关联的材料对象
+                String querySql2 = "select * from u_trial_material_mobilization where id =(select mobilization_id from u_trial_sampling_record where sample_info_id = "+sampleId+") ";
+                TrialMaterialMobilization trialMaterialMobilization = null;
+                try {
+                    trialMaterialMobilization = jdbcTemplate.queryForObject(querySql2, new BeanPropertyRowMapper<>(TrialMaterialMobilization.class));
+                } catch (DataAccessException e) {
+                    trialMaterialMobilization = null;
+                }
+                //通过html获取页面上的key值 返回key值对应的数据
+                setBasicFormData(doc, reData, sampleInfo, trialMaterialMobilization,entrustInfo);
+            }
+
+
             //匹配
             Elements bgBH = doc.select("el-input[placeholderxx~=报告编号.*]");
             Elements cbdwBH = doc.select("el-input[placeholderxx~=承包单位.*]");
@@ -2872,7 +2892,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
         }
 
         //获取数据信息info
-        List<Map<String, Object>> bussDataInfoTrial = this.getBussDataInfoTrial(id, pkeyId, Long.parseLong(contractId));
+        List<Map<String, Object>> bussDataInfoTrial = this.getBussDataInfoTrial(id, pkeyId, Long.parseLong(contractId),null);
         Map<String, Object> DataInfo = new HashMap<>();
         if (bussDataInfoTrial.size() > 0) {
             DataInfo.putAll(bussDataInfoTrial.stream().findAny().orElse(null));
@@ -3949,7 +3969,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
         }
 
         //获取数据信息info
-        List<Map<String, Object>> bussDataInfoTrial = this.getBussDataInfoTrial(groupId, pkeyId, Long.parseLong(contractId));
+        List<Map<String, Object>> bussDataInfoTrial = this.getBussDataInfoTrial(groupId, pkeyId, Long.parseLong(contractId),null);
         Map<String, Object> DataInfo = new HashMap<>();
         if (bussDataInfoTrial.size() > 0) {
             DataInfo.putAll(bussDataInfoTrial.stream().findAny().orElse(null));
@@ -4411,7 +4431,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
             htmlString = htmlString.replaceAll("title", "titlexx");
             Document doc = Jsoup.parse(htmlString);
             //通过html获取页面上的key值 返回key值对应的数据
-            setBasicFormData(doc, reData, sampleInfo, trialMaterialMobilization);
+            setBasicFormData(doc, reData, sampleInfo, trialMaterialMobilization,null);
             if (dataIn.size() >= 1) {
                 Map<String, Object> mysqlData = dataIn.get(0);
                 for (String key : mysqlData.keySet()) {
@@ -4509,32 +4529,17 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
         return list;
     }
 
-    private static void setBasicFormData(Document doc, Map<String, Object> reData, TrialSampleInfo sampleInfo ,TrialMaterialMobilization trialMaterialMobilization) {
-//        //样品编号
-//        String specificationNumber = sampleInfo.getSpecificationNumber();
-//        Elements specificationNumberElements = doc.select("[placeholderxx=样品编号]");
-//        if (!specificationNumberElements.isEmpty()) {
-//            Element textareaElement = specificationNumberElements.first();
-//            String id = textareaElement.attr("id");
-//            reData.put(id, specificationNumber);
-//        } else {
-//            throw new RuntimeException("没有找到[placeholderxx=样品编号]的元素");
-//        }
-//        //取样地点
-//        String samplingLocation = sampleInfo.getSamplingLocation();
-//        Elements samplingLocationElements = doc.select("[placeholderxx=取样地点]");
-//        if (!samplingLocationElements.isEmpty()) {
-//            Element textareaElement = samplingLocationElements.first();
-//            String id = textareaElement.attr("id");
-//            reData.put(id, samplingLocation);
-//        } else {
-//            throw new RuntimeException("没有找到[placeholderxx=取样地点]的元素");
-//        }
+    private static void setBasicFormData(Document doc, Map<String, Object> reData, TrialSampleInfo sampleInfo ,TrialMaterialMobilization trialMaterialMobilization, EntrustInfo entrustInfo) {
+        setFirstData(doc,"委托编号",entrustInfo.getEntrustNo(),reData);
         setFirstData(doc,"样品编号",sampleInfo.getSpecificationNumber(),reData);
         setFirstData(doc,"取样地点",sampleInfo.getSamplingLocation(),reData);
+        setFirstData(doc,"样品描述",sampleInfo.getSampleDescription(),reData);
         setFirstData(doc,"取样时间",sampleInfo.getSamplingDate(),reData);
+        setFirstData(doc,"取样日期",sampleInfo.getSamplingDate(),reData);
         setFirstData(doc,"试样名称",sampleInfo.getMaterialName(),reData);
+        setFirstData(doc,"样品名称",sampleInfo.getMaterialName(),reData);
         setFirstData(doc,"规格 型号",sampleInfo.getSpecificationModel(),reData);
+        setFirstData(doc,"规格型号",sampleInfo.getSpecificationModel(),reData);
         setFirstData(doc,"试样 数量",sampleInfo.getMaterialCount(),reData);
         if(trialMaterialMobilization != null){
             setFirstData(doc,"生产厂家",trialMaterialMobilization.getPlaceOfProduction(),reData);
@@ -4550,18 +4555,33 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
     private static void setFirstData(Document doc, String elementValue,Object value,Map<String, Object> reData) {
 
         Elements select = doc.select("[placeholderxx=" + elementValue + "]");
+        if(select.isEmpty()){
+            elementValue = elementValue + ":";
+            select = doc.select("[placeholderxx=" + elementValue + "]");
+        }
         if (!select.isEmpty()) {
-            Element textareaElement = select.first();
-            String id = textareaElement.attr("id");
-            reData.put(id, value);
+            Element textareaElement = select.stream().filter(element -> element.tagName().equals("el-input")).findFirst().orElse(null);
+            if( (elementValue.contains("时间") || elementValue.contains("日期")) && textareaElement == null){
+                textareaElement = select.first();
+                String keyName = textareaElement.attr("keyName");
+                reData.put(keyName, value);
+                return;
+            }
+            if(textareaElement != null){
+                String id = textareaElement.attr("id");
+                reData.put(id, value);
+            }
         } else {
             if(elementValue.equals("进场日期代表数量")){
                 Elements select1 = doc.select("[titlexx=\"进场日期/ 代表数量\"]");
-                Element textareaElement = select1.first();
-                List<Node> nodes = textareaElement.childNodes();
-                Node node = nodes.get(1);
-                String id = node.attributes().get("id");
-                reData.put(id, value);
+                Element textareaElement = select1.stream().filter(element -> element.tagName().equals("el-input")).findFirst().orElse(null);
+                if(textareaElement != null){
+                    List<Node> nodes = textareaElement.childNodes();
+                    Node node = nodes.get(1);
+                    String id = node.attributes().get("id");
+                    reData.put(id, value);
+                }
+//                Element textareaElement = select1.first();
             }else {
                 System.out.println("没有找到[" + elementValue + "]的元素");
             }