From d9022031db98d3f7a85ca457980f6fd30af7a693 Mon Sep 17 00:00:00 2001
From: zhaoxiaolin <khd@123>
Date: Wed, 10 Jan 2024 13:14:53 +0800
Subject: [PATCH] =?UTF-8?q?=E5=85=A5=E5=BA=93=E6=A3=80=E9=AA=8C=E4=BF=AE?=
 =?UTF-8?q?=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../QcCheckTaskWarehousingController.java     |  8 +++-
 .../op/quality/domain/QcCheckTaskDetail.java  | 18 +++++++
 .../op/quality/domain/QcCheckTaskIncome.java  | 10 ++++
 .../com/op/quality/mapper/QMSFileMapper.java  | 22 +++++++++
 .../impl/QcCheckTaskIncomeServiceImpl.java    | 23 +++++++++
 .../QcCheckTaskWarehousingServiceImpl.java    |  6 +--
 .../service/impl/QcProCheckServiceImpl.java   | 11 +++++
 .../mapper/quality/QMSFileMapper.xml          | 47 +++++++++++++++++++
 8 files changed, 140 insertions(+), 5 deletions(-)
 create mode 100644 op-modules/op-quality/src/main/java/com/op/quality/mapper/QMSFileMapper.java
 create mode 100644 op-modules/op-quality/src/main/resources/mapper/quality/QMSFileMapper.xml

diff --git a/op-modules/op-quality/src/main/java/com/op/quality/controller/QcCheckTaskWarehousingController.java b/op-modules/op-quality/src/main/java/com/op/quality/controller/QcCheckTaskWarehousingController.java
index f380a6db..f9e69bc6 100644
--- a/op-modules/op-quality/src/main/java/com/op/quality/controller/QcCheckTaskWarehousingController.java
+++ b/op-modules/op-quality/src/main/java/com/op/quality/controller/QcCheckTaskWarehousingController.java
@@ -3,6 +3,7 @@ package com.op.quality.controller;
 import java.time.LocalDate;
 import java.time.format.DateTimeFormatter;
 import java.util.List;
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import com.op.common.core.utils.DateUtils;
@@ -29,6 +30,8 @@ import com.op.common.core.web.controller.BaseController;
 import com.op.common.core.web.domain.AjaxResult;
 import com.op.common.core.utils.poi.ExcelUtil;
 import com.op.common.core.web.page.TableDataInfo;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
 
 /**
  * 成品入库检验任务Controller
@@ -99,6 +102,9 @@ public class QcCheckTaskWarehousingController extends BaseController {
 	@Log(title = "成品入库检验任务", businessType = BusinessType.INSERT)
 	@PostMapping
 	public AjaxResult add(@RequestBody QcCheckTaskWarehousing qcCheckTaskWarehousing) {
+		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
+		String key = "#header.poolName";
+		qcCheckTaskWarehousing.setFactoryCode(request.getHeader(key.substring(8)).replace("ds_",""));
 		int r = qcCheckTaskWarehousingService.insertQcCheckTaskWarehousing(qcCheckTaskWarehousing);
 		if(r>0){
 			return toAjax(r);
@@ -109,7 +115,7 @@ public class QcCheckTaskWarehousingController extends BaseController {
 	@PostMapping("/createProductTask")
 	public AjaxResult createProductTask(@RequestBody QcCheckTaskWarehousingDTO qcCheckTaskWarehousingDTO) {
 		QcCheckTaskWarehousing qcCheckTaskIncome = new QcCheckTaskWarehousing();
-		BeanUtils.copyProperties(qcCheckTaskIncome,qcCheckTaskWarehousingDTO);
+		BeanUtils.copyProperties(qcCheckTaskWarehousingDTO,qcCheckTaskIncome);
 		int r = qcCheckTaskWarehousingService.insertQcCheckTaskWarehousing(qcCheckTaskIncome);
 		if(r>0){
 			return toAjax(r);
diff --git a/op-modules/op-quality/src/main/java/com/op/quality/domain/QcCheckTaskDetail.java b/op-modules/op-quality/src/main/java/com/op/quality/domain/QcCheckTaskDetail.java
index 4517e562..3a941e21 100644
--- a/op-modules/op-quality/src/main/java/com/op/quality/domain/QcCheckTaskDetail.java
+++ b/op-modules/op-quality/src/main/java/com/op/quality/domain/QcCheckTaskDetail.java
@@ -96,6 +96,24 @@ public class QcCheckTaskDetail extends BaseEntity {
     private String typeProjectId;
     private String defectCode;
 	private String checkType;
+	private String fileListStr;
+	private List<BaseFile> files;
+
+	public List<BaseFile> getFiles() {
+		return files;
+	}
+
+	public void setFiles(List<BaseFile> files) {
+		this.files = files;
+	}
+
+	public String getFileListStr() {
+		return fileListStr;
+	}
+
+	public void setFileListStr(String fileListStr) {
+		this.fileListStr = fileListStr;
+	}
 
 	public String getCheckType() {
 		return checkType;
diff --git a/op-modules/op-quality/src/main/java/com/op/quality/domain/QcCheckTaskIncome.java b/op-modules/op-quality/src/main/java/com/op/quality/domain/QcCheckTaskIncome.java
index c67fd89b..148dc24a 100644
--- a/op-modules/op-quality/src/main/java/com/op/quality/domain/QcCheckTaskIncome.java
+++ b/op-modules/op-quality/src/main/java/com/op/quality/domain/QcCheckTaskIncome.java
@@ -137,6 +137,16 @@ public class QcCheckTaskIncome extends BaseEntity {
 	private BigDecimal bNoOkquality;
 	private BigDecimal cNoOkquality;
 
+	private String fileList;
+
+	public String getFileList() {
+		return fileList;
+	}
+
+	public void setFileList(String fileList) {
+		this.fileList = fileList;
+	}
+
 	public String getOrderType() {
 		return orderType;
 	}
diff --git a/op-modules/op-quality/src/main/java/com/op/quality/mapper/QMSFileMapper.java b/op-modules/op-quality/src/main/java/com/op/quality/mapper/QMSFileMapper.java
new file mode 100644
index 00000000..4e79ee5f
--- /dev/null
+++ b/op-modules/op-quality/src/main/java/com/op/quality/mapper/QMSFileMapper.java
@@ -0,0 +1,22 @@
+package com.op.quality.mapper;
+
+import com.op.common.core.domain.BaseFileData;
+import com.op.quality.domain.BaseFile;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * 附件Mapper接口
+ *
+ * @author Open Platform
+ * @date 2023-07-10
+ */
+@Mapper
+public interface QMSFileMapper {
+
+    int insertBaseFileBatch(@Param("baseFiles") List<BaseFileData> baseFiles);
+
+    List<BaseFile> getBaseFileBatch(String recordId);
+}
diff --git a/op-modules/op-quality/src/main/java/com/op/quality/service/impl/QcCheckTaskIncomeServiceImpl.java b/op-modules/op-quality/src/main/java/com/op/quality/service/impl/QcCheckTaskIncomeServiceImpl.java
index add37cbf..507d212b 100644
--- a/op-modules/op-quality/src/main/java/com/op/quality/service/impl/QcCheckTaskIncomeServiceImpl.java
+++ b/op-modules/op-quality/src/main/java/com/op/quality/service/impl/QcCheckTaskIncomeServiceImpl.java
@@ -6,6 +6,7 @@ import com.alibaba.fastjson2.JSONObject;
 import com.alibaba.fastjson2.JSONArray;
 import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
+import com.op.common.core.domain.BaseFileData;
 import com.op.common.core.utils.DateUtils;
 import com.op.common.core.utils.StringUtils;
 import com.op.common.core.utils.uuid.IdUtils;
@@ -66,6 +67,9 @@ public class QcCheckTaskIncomeServiceImpl implements IQcCheckTaskIncomeService {
 	@Autowired
 	private RemoteOpenService remoteOpenService;
 
+	@Autowired
+	private QMSFileMapper qmsFileMapper;
+
 	/**
 	 * 查询来料检验
 	 *
@@ -539,6 +543,25 @@ public class QcCheckTaskIncomeServiceImpl implements IQcCheckTaskIncomeService {
 		/**更新qc_check_task_detail**/
 		for(QcCheckTaskDetail detail:details){
 			detail.setUpdateTime(nowTime);
+			//上传附件
+			if (StringUtils.isNotEmpty(detail.getFileListStr())) {
+				String[] ids = detail.getFileListStr().split(",");
+				List<BaseFileData> files = new ArrayList<>();
+				BaseFileData file = null;
+				for (String id : ids) {
+					file = new BaseFileData();
+					file.setFileId(IdUtils.fastSimpleUUID());
+					file.setFileName(id.split("&fileName=")[1]);
+					file.setFileAddress(id);
+					file.setSourceId(detail.getRecordId());
+					file.setCreateBy(SecurityUtils.getUsername());
+					file.setCreateTime(nowTime);
+					files.add(file);
+				}
+				/**base_file**/
+				n = qmsFileMapper.insertBaseFileBatch(files);
+				System.out.println("base_file:"+n);
+			}
 		}
 		n= qcCheckTaskIncomeMapper.updateQcCheckTaskDetails(details);
 		logger.info("更新qc_check_task_detail:"+n);
diff --git a/op-modules/op-quality/src/main/java/com/op/quality/service/impl/QcCheckTaskWarehousingServiceImpl.java b/op-modules/op-quality/src/main/java/com/op/quality/service/impl/QcCheckTaskWarehousingServiceImpl.java
index 1d232d15..6321509c 100644
--- a/op-modules/op-quality/src/main/java/com/op/quality/service/impl/QcCheckTaskWarehousingServiceImpl.java
+++ b/op-modules/op-quality/src/main/java/com/op/quality/service/impl/QcCheckTaskWarehousingServiceImpl.java
@@ -100,10 +100,8 @@ public class QcCheckTaskWarehousingServiceImpl implements IQcCheckTaskWarehousin
 
 		String createBy = SecurityUtils.getUsername();
 		Date nowDate= DateUtils.getNowDate();
-		//获取当前所选工厂
-		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
-		String key = "#header.poolName";
-		String factoryCode = request.getHeader(key.substring(8)).replace("ds_","");
+
+		String factoryCode = qcCheckTaskWarehousing.getFactoryCode();
 
 		qcCheckTaskWarehousing.setCheckNo(bpDD+liushuiStr);
 
diff --git a/op-modules/op-quality/src/main/java/com/op/quality/service/impl/QcProCheckServiceImpl.java b/op-modules/op-quality/src/main/java/com/op/quality/service/impl/QcProCheckServiceImpl.java
index b8c739f9..9d13d63f 100644
--- a/op-modules/op-quality/src/main/java/com/op/quality/service/impl/QcProCheckServiceImpl.java
+++ b/op-modules/op-quality/src/main/java/com/op/quality/service/impl/QcProCheckServiceImpl.java
@@ -10,6 +10,7 @@ import com.op.common.core.utils.StringUtils;
 import com.op.common.core.utils.uuid.IdUtils;
 import com.op.common.security.utils.SecurityUtils;
 import com.op.quality.domain.*;
+import com.op.quality.mapper.QMSFileMapper;
 import com.op.quality.mapper.QcCheckTaskIncomeMapper;
 import com.op.quality.mapper.QcProCheckMapper;
 import com.op.quality.service.QcProCheckService;
@@ -36,6 +37,9 @@ public class QcProCheckServiceImpl implements QcProCheckService {
     @Autowired
     private QcCheckTaskIncomeMapper qcCheckTaskIncomeMapper;
 
+    @Autowired
+    private QMSFileMapper qmsFileMapper;
+
     @Override
     public R<Boolean> saveQcProCheck(QcProCheck qcProCheck) {
         DynamicDataSourceContextHolder.push("ds_" + qcProCheck.getFactoryCode());
@@ -133,6 +137,13 @@ public class QcProCheckServiceImpl implements QcProCheckService {
             defects =qcCheckTaskIncomeMapper.getDefectType(qcCheckTaskDetail);
         }
         dto.setDefects(defects);
+        for(QcCheckTaskDetail qcd:qcCheckTaskDetails){
+            List<BaseFile> files = qmsFileMapper.getBaseFileBatch(qcd.getRecordId());
+            if (CollectionUtils.isEmpty(files)) {
+                qcd.setFiles(files);
+            }
+        }
+
         return dto;
     }
 
diff --git a/op-modules/op-quality/src/main/resources/mapper/quality/QMSFileMapper.xml b/op-modules/op-quality/src/main/resources/mapper/quality/QMSFileMapper.xml
new file mode 100644
index 00000000..0edc2000
--- /dev/null
+++ b/op-modules/op-quality/src/main/resources/mapper/quality/QMSFileMapper.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.op.quality.mapper.QMSFileMapper">
+
+	<resultMap type="BaseFile" id="BaseFileResult">
+		<result property="fileId"	column="file_id"	/>
+		<result property="fileName"	column="file_name"	/>
+		<result property="fileAddress"	column="file_address"	/>
+		<result property="sourceId"	column="source_id"	/>
+		<result property="remark"	column="remark"	/>
+		<result property="attr1"	column="attr1"	/>
+		<result property="attr2"	column="attr2"	/>
+		<result property="attr3"	column="attr3"	/>
+		<result property="attr4"	column="attr4"	/>
+		<result property="createBy"	column="create_by"	/>
+		<result property="createTime"	column="create_time"	/>
+		<result property="updateBy"	column="update_by"	/>
+		<result property="updateTime"	column="update_time"	/>
+	</resultMap>
+	<sql id="selectBaseFileVo">
+		select file_id, file_name, file_address, source_id, remark, attr1,
+			   attr2, attr3, attr4, create_by, create_time, update_by,
+			   update_time from base_file
+	</sql>
+	<insert id="insertBaseFileBatch">
+		INSERT INTO base_file(file_id, file_name, file_address, source_id, remark, create_by, create_time)
+		VALUES
+		<foreach collection="baseFiles" index="" item="baseFile" separator=",">
+			(
+			 #{baseFile.fileId},
+			 #{baseFile.fileName},
+		     #{baseFile.fileAddress},
+			 #{baseFile.sourceId},
+			 #{baseFile.remark},
+			 #{baseFile.createBy},
+			 #{baseFile.createTime}
+			)
+		</foreach>
+	</insert>
+	<select id="getBaseFileBatch" resultMap="BaseFileResult">
+		<include refid="selectBaseFileVo"/>
+		where source_id = #{recordId}
+	</select>
+
+</mapper>