Selaa lähdekoodia

蝌蚪文对接AGV系统需求代码

ChenYang 1 vuosi sitten
vanhempi
commit
67d9fd0163

+ 29 - 29
doc/金川镍盐蝌蚪文.sql

@@ -1,35 +1,35 @@
 
-## 蝌蚪文需求建表语句
-    CREATE TABLE `fct_agv1` (
-        `ID` varchar(50) NOT NULL COMMENT 'ID',
-        `SLOT` varchar(50) NOT NULL COMMENT '生产批号',
-        `SPLT` varchar(50) NOT NULL COMMENT '产品托盘号',
-        `SPROD` varchar(50) NOT NULL COMMENT '产品',
-        `SSHIFT` varchar(50) NOT NULL COMMENT '班组',
-        `CREATEDATE` date NOT NULL COMMENT '创建时间',
-        `CREATEBY` varchar(50) NOT NULL COMMENT '创建人',
-        `STATUS` varchar(10) NOT NULL COMMENT '状态 0-未处理 1-AGV处理 2-人工处理',
-        PRIMARY KEY (`ID`)
-    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='批号相关信息表(BMS系统直连)';
+-- 蝌蚪文需求建表语句
+CREATE TABLE `fct_agv1` (
+    `ID` varchar(50) NOT NULL COMMENT 'ID',
+    `SLOT` varchar(50) NOT NULL COMMENT '生产批号',
+    `SPLT` varchar(50) NOT NULL COMMENT '产品托盘号',
+    `SPROD` varchar(50) NOT NULL COMMENT '产品',
+    `SSHIFT` varchar(50) NOT NULL COMMENT '班组',
+    `CREATEDATE` datetime NOT NULL COMMENT '创建时间',
+    `CREATEBY` varchar(50) NOT NULL COMMENT '创建人',
+    `STATUS` varchar(10) NOT NULL COMMENT '状态 0-未处理 1-AGV处理 2-人工处理 默认传0',
+    `SPRODTYPE` varchar(10) NOT NULL COMMENT '类型 硫酸镍-LSN 氯化镍-LHN',
+    PRIMARY KEY (`ID`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='批号相关信息表(BMS系统直连)';
 
 
-    CREATE TABLE `fct_agv2` (
-        `ID` varchar(50) NOT NULL COMMENT 'ID',
-        `SLOT` varchar(50) NOT NULL COMMENT '生产批号',
-        `ISQCL` varchar(10) NOT NULL COMMENT '是否质检(Y:已质检  N:未质检)',
-        `DSQCDATE` date NOT NULL COMMENT '质检时间',
-        `PROCESSFLAG` varchar(10) NOT NULL COMMENT '是否已处理(Y:已处理  N:未处理)由AGV更新',
-        `CREATEDATE` date NOT NULL COMMENT '创建时间',
-        `CREATEBY` varchar(50) NOT NULL COMMENT '创建人',
-        `STATUS` varchar(10) NOT NULL COMMENT '状态 0-未处理 1-AGV处理 2-人工处理',
-        PRIMARY KEY (`ID`)
-    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='质检相关信息(BMS系统直连)';
+CREATE TABLE `fct_agv2` (
+    `ID` varchar(50) NOT NULL COMMENT 'ID',
+    `SLOT` varchar(50) NOT NULL COMMENT '生产批号',
+    `ISQCL` varchar(10) NOT NULL COMMENT '是否质检(Y:已质检  N:未质检)',
+    `DSQCDATE` date NOT NULL COMMENT '质检时间',
+    `PROCESSFLAG` varchar(10) NOT NULL COMMENT '是否已处理(Y:已处理  N:未处理)由AGV更新',
+    `CREATEDATE` date NOT NULL COMMENT '创建时间',
+    `CREATEBY` varchar(50) NOT NULL,
+    PRIMARY KEY (`ID`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='质检相关信息(BMS系统直连)';
 
 
 
-## 给蝌蚪文系统账号赋权限
-CREATE USER `KDW`@`%` IDENTIFIED WITH mysql_native_password;
-GRANT Delete, Insert, Select, Update ON TABLE `warewms-jnmc-jinco`.`fct_agv1` TO `KDW`@`%`;
-GRANT Delete, Insert, Select, Update ON TABLE `warewms-jnmc-jinco`.`fct_agv2` TO `KDW`@`%`;
-ALTER USER `KDW`@`%` IDENTIFIED WITH mysql_native_password BY 'kdwadmin';
-FLUSH PRIVILEGES;
+-- 给蝌蚪文系统账号赋权限
+    CREATE USER `KDW`@`%` IDENTIFIED WITH mysql_native_password;
+    GRANT Delete, Insert, Select, Update ON TABLE `warewms-jnmc-jinco`.`fct_agv1` TO `KDW`@`%`;
+    GRANT Delete, Insert, Select, Update ON TABLE `warewms-jnmc-jinco`.`fct_agv2` TO `KDW`@`%`;
+    ALTER USER `KDW`@`%` IDENTIFIED WITH mysql_native_password BY 'kdwadmin';
+    FLUSH PRIVILEGES;

+ 15 - 0
ruoyi-admin/src/main/java/com/ruoyi/init/StartService.java

@@ -4,12 +4,16 @@ import com.ruoyi.ams.agv.ndc.AciService;
 import com.ruoyi.ams.agv.ndc.config.InitTaskConfig;
 import com.ruoyi.ams.agv.ndc.thread.*;
 import com.ruoyi.ams.business.IBusinessService;
+import com.ruoyi.ams.nieyan.service.impl.QcInfoFctAgvService;
 import com.ruoyi.base.service.IBaseLocationInfoService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.CommandLineRunner;
 import org.springframework.stereotype.Component;
 
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
 @Slf4j
 @Component
 public class StartService implements CommandLineRunner {
@@ -33,6 +37,13 @@ public class StartService implements CommandLineRunner {
     @Autowired
     private AutoPhotoelectricTask autoPhotoelectricTask;
 
+    @Autowired
+    private ScheduledExecutorService executorService;
+
+    @Autowired
+    private QcInfoFctAgvService qcInfoFctAgvService;
+
+
 
     @Override
     public void run(String... args) throws Exception {
@@ -47,6 +58,10 @@ public class StartService implements CommandLineRunner {
             Thread thread = new Thread(new AciServiceThread(aciService));
             thread.start();
         }
+
+        executorService.scheduleAtFixedRate(()->{
+            qcInfoFctAgvService.syncQcStatusTask();
+        },10 , 15*60, TimeUnit.SECONDS);
     }
 
     /**

+ 8 - 26
ruoyi-admin/src/main/java/com/ruoyi/nieyan/controller/pda/PdaDocQcController.java

@@ -2,6 +2,7 @@ package com.ruoyi.nieyan.controller.pda;
 
 import cn.hutool.core.lang.Assert;
 import com.ruoyi.ams.nieyan.dto.LotInfoFctAgvDTO;
+import com.ruoyi.ams.nieyan.dto.QcInfoFctAgvDTO;
 import com.ruoyi.ams.nieyan.entity.QcInfoFctAgvEntity;
 import com.ruoyi.ams.nieyan.service.ILotInfoFctAgvService;
 import com.ruoyi.ams.nieyan.service.IQcInfoFctAgvService;
@@ -113,27 +114,24 @@ public class PdaDocQcController {
 
     /**
      * 对接BMS获取批次列表
-     * @param lotNo 批次号
-     * @param spltNo 托盘号
      * @return
      */
     @GetMapping("/getLotInfoList")
-    public AjaxResult getLotInfoList(@RequestParam(required = false) String lotNo, @RequestParam(required = false) String spltNo) {
-        Assert.isTrue(StringUtils.isNotBlank(lotNo) || StringUtils.isNotBlank(spltNo), "lotNo or spltNo is null");
-        List<LotInfoFctAgvDTO>  lotInfoList = iLotInfoFctAgvService.getLotInfoList(lotNo, spltNo);
+    public AjaxResult getLotInfoList(@RequestParam(required = false) String status) {
+        List<LotInfoFctAgvDTO> lotInfoList = iLotInfoFctAgvService.getLotInfoList(status);
         return AjaxResult.success("success", lotInfoList);
     }
 
     /**
-     * 对接BMS获取质检列表
+     * 对接BMS获取质检信息
      * @param lotNo 批次号
      * @return
      */
-    @GetMapping("/getQcInfoList")
-    public AjaxResult getQcInfoList(@RequestParam(required = false) String lotNo) {
+    @GetMapping("/getQcInfo")
+    public AjaxResult getQcInfo(@RequestParam(required = false) String lotNo) {
         Assert.isTrue(StringUtils.isNotBlank(lotNo), "lotNo is null");
-        List<QcInfoFctAgvEntity> qcInfoList = iQcInfoFctAgvService.getQcInfoList(lotNo);
-        return AjaxResult.success("success", qcInfoList);
+        QcInfoFctAgvDTO qcInfo = iQcInfoFctAgvService.getQcInfo(lotNo);
+        return AjaxResult.success("success", qcInfo);
     }
 
 
@@ -149,22 +147,6 @@ public class PdaDocQcController {
         return AjaxResult.success("success", iLotInfoFctAgvService.updateLotInfoStatus(id, status));
     }
 
-    /**
-     * 更新质检的信息
-     * @param id 业务id
-     * @param status 质检状态 0-未处理 1-AGV处理 2-人工处理
-     * @return
-     */
-    @PostMapping("/updateQcInfoStatus")
-    public AjaxResult updateQcInfoStatus(@RequestParam("id") String id, @RequestParam("status") String status) {
-        Assert.isTrue(StringUtils.isNotBlank(id) && StringUtils.isNotBlank(status), "id or status is null");
-        return AjaxResult.success("success", iQcInfoFctAgvService.updateQcInfoStatus(id, status));
-    }
-
-    //TODO agv搬货完成之后要反馈给wms 这一块逻辑怎么交互
-
-
-
 
 
 

+ 9 - 2
warewms-ams/src/main/java/com/ruoyi/ams/config/domain/dto/LotattDTO.java

@@ -1,8 +1,12 @@
 package com.ruoyi.ams.config.domain.dto;
 
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.map.MapUtil;
 import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.springframework.beans.BeanUtils;
 
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.Map;
 
 /**
@@ -10,11 +14,11 @@ import java.util.Map;
  */
 public class LotattDTO {
 
-    private String lotatt01;
+    private String lotatt01;//生产批次号
     private String lotatt02;
     private String lotatt03;
     private String lotatt04;
-    private String lotatt05;
+    private String lotatt05;//质检状态
     private String lotatt06;
     private String lotatt07;
     private String lotatt08;
@@ -176,6 +180,7 @@ public class LotattDTO {
     }
 
     public Map<String, String> getAttr() {
+        //return (LinkedHashMap)BeanUtil.beanToMap(this);
         Map<String, String> map = new HashMap<>();
         map.put("lotatt01", this.lotatt01);
         map.put("lotatt02", this.lotatt02);
@@ -199,6 +204,7 @@ public class LotattDTO {
     }
 
     public String getAttr(String id) {
+        //return (String)BeanUtil.beanToMap(this).get(id);
         if (id.equals("lotatt01")) {
             return this.lotatt01;
         }
@@ -257,6 +263,7 @@ public class LotattDTO {
     }
 
     public void setAttr(String id, String value) {
+        //BeanUtil.setFieldValue(this, id, value);
         if (id.equals("lotatt01")) {
             this.lotatt01 = value;
         }

+ 5 - 5
warewms-ams/src/main/java/com/ruoyi/ams/inv/mapper/InvLotLocIdMapper.java

@@ -1,9 +1,6 @@
 package com.ruoyi.ams.inv.mapper;
 
-import java.math.BigDecimal;
-import java.util.List;
-
-import com.ruoyi.ams.asn.vo.StockingListVO;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.ruoyi.ams.config.domain.dto.LotattDTO;
 import com.ruoyi.ams.inv.domain.InvLotAtt;
 import com.ruoyi.ams.inv.domain.InvLotLocId;
@@ -13,13 +10,16 @@ import com.ruoyi.base.domain.vo.BaseLocationLotattVO;
 import com.ruoyi.common.core.domain.AjaxResult;
 import org.apache.ibatis.annotations.Param;
 
+import java.math.BigDecimal;
+import java.util.List;
+
 /**
  * 库位库存信息Mapper接口
  *
  * @author andy
  * @date 2022-03-03
  */
-public interface InvLotLocIdMapper {
+public interface InvLotLocIdMapper extends BaseMapper<InvLotAtt> {
     /**
      * 查询库位库存信息
      *

+ 7 - 0
warewms-ams/src/main/java/com/ruoyi/ams/inv/service/IInvLotLocIdService.java

@@ -298,4 +298,11 @@ public interface IInvLotLocIdService {
      * @return
      */
     AjaxResult insertWeighingData(String taskNo,int weight);
+
+    /**
+     * 根据批次号更新质检状态
+     * @param lotNo 批次号
+     * @param qcStatus 质检状态 HG-合格  DCL-待处理 BHG-不合格 DJ-待检
+     */
+    Boolean updateQcStatusByLotNo(String lotNo, String qcStatus);
 }

+ 10 - 0
warewms-ams/src/main/java/com/ruoyi/ams/inv/service/impl/InvLotLocIdServiceImpl.java

@@ -1,5 +1,6 @@
 package com.ruoyi.ams.inv.service.impl;
 
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.ruoyi.ams.box.domain.WmsBoxInfo;
 import com.ruoyi.ams.box.service.IWmsBoxInfoService;
 import com.ruoyi.ams.business.IBusinessService;
@@ -32,6 +33,7 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.Assert;
 
 import java.math.BigDecimal;
 import java.util.ArrayList;
@@ -716,4 +718,12 @@ public class InvLotLocIdServiceImpl implements IInvLotLocIdService {
         iWeighDataService.insertWeighData(weighData);
         return AjaxResult.success();
     }
+
+    @Override
+    public Boolean updateQcStatusByLotNo(String lotNo, String qcStatus) {
+        Assert.isTrue(StringUtils.isNotBlank(lotNo) && StringUtils.isNotBlank(qcStatus), "lotNo or qcStatus is null");
+        return invLotLocIdMapper.update(null, Wrappers.<InvLotAtt>lambdaUpdate()
+                .set(InvLotAtt::getLotatt05, qcStatus).eq(InvLotAtt::getLotatt01, lotNo)) > 0;
+
+    }
 }

+ 7 - 0
warewms-ams/src/main/java/com/ruoyi/ams/nieyan/dto/LotInfoFctAgvDTO.java

@@ -15,6 +15,13 @@ public class LotInfoFctAgvDTO {
 
     private String sshift;
 
+    private String status;
+
+    /**
+     * 类型 硫酸镍-LSN 氯化镍-LHN
+     */
+    private String sprodType;
+
     private String createBy;
 
     private String createDate;

+ 0 - 2
warewms-ams/src/main/java/com/ruoyi/ams/nieyan/dto/QcInfoFctAgvDTO.java

@@ -14,8 +14,6 @@ public class QcInfoFctAgvDTO {
 
     private String dsqcDate;
 
-    private String processFlag;
-
     private String createBy;
 
     private String createDate;

+ 13 - 0
warewms-ams/src/main/java/com/ruoyi/ams/nieyan/entity/LotInfoFctAgvEntity.java

@@ -43,4 +43,17 @@ public class LotInfoFctAgvEntity extends BaseBMSEntity {
     @TableField("SSHIFT")
     private String sshift;
 
+
+    /**
+     * 状态  0-未处理 1-AGV处理 2-人工处理
+     */
+    @TableField("STATUS")
+    private String status;
+
+    /**
+     * 类型 硫酸镍-LSN 氯化镍-LHN
+     */
+    @TableField("SPRODTYPE")
+    private String sprodType;
+
 }

+ 12 - 0
warewms-ams/src/main/java/com/ruoyi/ams/nieyan/entity/QcInfoFctAgvEntity.java

@@ -19,15 +19,27 @@ public class QcInfoFctAgvEntity extends BaseBMSEntity {
     @TableId
     private String id;
 
+    /**
+     * 生产批号
+     */
     @TableField("SLOT")
     private String slot;
 
+    /**
+     * 是否质检(Y:已质检  N:未质检)
+     */
     @TableField("ISQCL")
     private String isQcl;
 
+    /**
+     * 质检时间
+     */
     @TableField("DSQCDATE")
     private String dsqcDate;
 
+    /**
+     * 是否已处理(Y:已处理  N:未处理)由AGV更新
+     */
     @TableField("PROCESSFLAG")
     private String processFlag;
 

+ 0 - 5
warewms-ams/src/main/java/com/ruoyi/ams/nieyan/entity/base/BaseBMSEntity.java

@@ -9,11 +9,6 @@ import java.io.Serializable;
 public class BaseBMSEntity implements Serializable {
 
     private static final long serialVersionUID = 1965773431626512523L;
-    /**
-     * 状态
-     */
-    @TableField("STATUS")
-    private String status;
 
     @TableField("CREATEBY")
     private String createBy;

+ 4 - 4
warewms-ams/src/main/java/com/ruoyi/ams/nieyan/service/ILotInfoFctAgvService.java

@@ -9,12 +9,11 @@ import java.util.List;
 public interface ILotInfoFctAgvService extends CrudService<LotInfoFctAgvEntity, LotInfoFctAgvDTO> {
 
     /**
-     * 根据批次号托盘号获取批次信息列表
-     * @param lotNo 批次号
-     * @param spltNo 托盘号
+     * 根据批次号状态获取批次信息列表
+     * @param status 批次号状态 0-未处理 1-AGV处理 2-人工处理
      * @return
      */
-    List<LotInfoFctAgvDTO> getLotInfoList(String lotNo, String spltNo);
+    List<LotInfoFctAgvDTO> getLotInfoList(String status);
 
     /**
      * 更新批次号的状态
@@ -23,4 +22,5 @@ public interface ILotInfoFctAgvService extends CrudService<LotInfoFctAgvEntity,
      * @return
      */
     Boolean updateLotInfoStatus(String id, String status);
+
 }

+ 12 - 6
warewms-ams/src/main/java/com/ruoyi/ams/nieyan/service/IQcInfoFctAgvService.java

@@ -10,17 +10,23 @@ public interface IQcInfoFctAgvService extends CrudService<QcInfoFctAgvEntity, Qc
 
 
     /**
-     * 根据批号获取质检信息列表
+     * 根据批号获取质检信息
      * @param lotNo 批次号
      * @return
      */
-    List<QcInfoFctAgvEntity> getQcInfoList(String lotNo);
+    QcInfoFctAgvDTO getQcInfo(String lotNo);
 
     /**
-     * 更新质检信息的状态
-     * @param id 信息的id
-     * @param status 信息的状态 0-未处理 1-AGV处理 2-人工处理
+     * 更新质检信息的处理状态
+     * @param lotNo 质检信息的批次号
+     * @param processFlag 是否已处理(Y:已处理  N:未处理)
      * @return
      */
-    Boolean updateQcInfoStatus(String id, String status);
+    Boolean updateQcInfoStatus(String lotNo, String processFlag);
+
+
+    /**
+     * 同步质检的状态
+     */
+    void syncQcStatusTask();
 }

+ 8 - 9
warewms-ams/src/main/java/com/ruoyi/ams/nieyan/service/impl/LotInfoFctAgvService.java

@@ -2,7 +2,6 @@ package com.ruoyi.ams.nieyan.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.toolkit.Constants;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.ruoyi.ams.nieyan.dao.LotInfoFctAgvDao;
@@ -11,9 +10,7 @@ import com.ruoyi.ams.nieyan.entity.LotInfoFctAgvEntity;
 import com.ruoyi.ams.nieyan.service.ILotInfoFctAgvService;
 import com.ruoyi.common.utils.ConvertUtils;
 import com.ruoyi.framework.service.impl.CrudServiceImpl;
-import org.apache.commons.collections4.SetUtils;
 import org.apache.commons.compress.utils.Lists;
-import org.apache.commons.compress.utils.Sets;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
@@ -24,24 +21,25 @@ import java.util.Map;
 public class LotInfoFctAgvService extends CrudServiceImpl<LotInfoFctAgvDao, LotInfoFctAgvEntity, LotInfoFctAgvDTO> implements ILotInfoFctAgvService  {
 
 
+    private static final String NOT_PROCESS = "0";
 
 
     /**
-     * 根据批次号托盘号获取批次信息列表
-     * @param lotNo 批次号
-     * @param spltNo 托盘号
+     * 获取批次信息列表
+     * @param status 状态
      * @return
      */
     @Override
-    public List<LotInfoFctAgvDTO> getLotInfoList(String lotNo, String spltNo) {
+    public List<LotInfoFctAgvDTO> getLotInfoList(String status) {
+        status = StringUtils.isBlank(status) ? NOT_PROCESS : status;
         Wrapper<LotInfoFctAgvEntity> lambdaQueryWrapper = Wrappers.<LotInfoFctAgvEntity>lambdaQuery()
-                .eq(StringUtils.isNotBlank(lotNo), LotInfoFctAgvEntity::getSlot, lotNo)
-                .eq(StringUtils.isNotBlank(spltNo), LotInfoFctAgvEntity::getSplt, spltNo);
+                .eq(LotInfoFctAgvEntity::getStatus, status).orderByDesc(LotInfoFctAgvEntity::getCreateDate);
         List<LotInfoFctAgvEntity> lotInfoFctAgvEntities = baseDao.selectList(lambdaQueryWrapper);
         return CollectionUtils.isEmpty(lotInfoFctAgvEntities)
                 ? Lists.newArrayList() : ConvertUtils.sourceToTarget(lotInfoFctAgvEntities, LotInfoFctAgvDTO.class);
     }
 
+
     /**
      * 更新批次号的状态
      * @param id 业务id
@@ -55,6 +53,7 @@ public class LotInfoFctAgvService extends CrudServiceImpl<LotInfoFctAgvDao, LotI
         return baseDao.updateById(lotInfoFctAgvEntity) == 1;
     }
 
+
     @Override
     public QueryWrapper<LotInfoFctAgvEntity> getWrapper(Map<String, Object> params) {
         QueryWrapper<LotInfoFctAgvEntity> queryWrapper = new QueryWrapper();

+ 47 - 20
warewms-ams/src/main/java/com/ruoyi/ams/nieyan/service/impl/QcInfoFctAgvService.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.ruoyi.ams.inv.service.IInvLotLocIdService;
 import com.ruoyi.ams.nieyan.dao.QcInfoFctAgvDao;
 import com.ruoyi.ams.nieyan.dto.QcInfoFctAgvDTO;
 import com.ruoyi.ams.nieyan.entity.QcInfoFctAgvEntity;
@@ -12,49 +13,75 @@ import com.ruoyi.ams.nieyan.service.IQcInfoFctAgvService;
 import com.ruoyi.common.constant.Constants;
 import com.ruoyi.common.utils.ConvertUtils;
 import com.ruoyi.framework.service.impl.CrudServiceImpl;
-import org.apache.commons.compress.utils.Lists;
-import org.apache.commons.compress.utils.Sets;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
 import java.util.Map;
 
 @Service
+@Slf4j
 public class QcInfoFctAgvService extends CrudServiceImpl<QcInfoFctAgvDao, QcInfoFctAgvEntity, QcInfoFctAgvDTO> implements IQcInfoFctAgvService {
 
 
-    private static final String AVG_PROCESS = "1";
-
-    private static final String PERSON_PROCESS = "2";
+    @Autowired
+    private IInvLotLocIdService invLotLocIdService;
 
     /**
-     * 根据批号获取质检信息列表
+     * 根据批号获取质检信息
      * @param lotNo 批次号
      * @return
      */
     @Override
-    public List<QcInfoFctAgvEntity> getQcInfoList(String lotNo) {
+    public QcInfoFctAgvDTO getQcInfo(String lotNo) {
         LambdaQueryWrapper<QcInfoFctAgvEntity> queryWrapper = Wrappers.<QcInfoFctAgvEntity>lambdaQuery()
-                .eq(StringUtils.isNotBlank(lotNo), QcInfoFctAgvEntity::getSlot, lotNo);
+                .eq(QcInfoFctAgvEntity::getSlot, lotNo).orderByDesc(QcInfoFctAgvEntity::getCreateDate);
         List<QcInfoFctAgvEntity> qcInfoFctAgvEntities = baseDao.selectList(queryWrapper);
-        return CollectionUtils.isEmpty(qcInfoFctAgvEntities) ?
-                Lists.newArrayList() : ConvertUtils.sourceToTarget(qcInfoFctAgvEntities, QcInfoFctAgvEntity.class);
+        return CollectionUtils.isEmpty(qcInfoFctAgvEntities) || qcInfoFctAgvEntities.size() > 1
+                ? new QcInfoFctAgvDTO(): ConvertUtils.sourceToTarget(qcInfoFctAgvEntities.get(0), QcInfoFctAgvDTO.class);
     }
 
     /**
-     * 更新质检信息的状态
-     * @param id 质检信息的id
-     * @param status 信息的状态 0-未处理 1-AGV处理 2-人工处理
+     * 同步质检的状态
+     */
+    @Override
+    @Transactional(rollbackFor = RuntimeException.class)
+    public void syncQcStatusTask() {
+        try{
+            //1.查询FCT_AGV2质检表中的已质检且未处理的状态
+            LambdaQueryWrapper<QcInfoFctAgvEntity> queryWrapper = Wrappers.<QcInfoFctAgvEntity>lambdaQuery()
+                    .eq(QcInfoFctAgvEntity::getIsQcl, Constants.YES).eq(QcInfoFctAgvEntity::getProcessFlag, Constants.NO);
+            List<QcInfoFctAgvEntity> qcInfoFctAgvEntities = baseDao.selectList(queryWrapper);
+            if(CollectionUtils.isEmpty(qcInfoFctAgvEntities)){
+                log.warn("Qc info records are not found");
+                return;
+            }
+            //2.以批次号为关联更新inv_lot_att中的字段lotatt05(质检结果)为HG (合格)
+            //3.根据批号查询FCT_AGV2质检表中的未处理的状态改为已处理
+            for(QcInfoFctAgvEntity qcInfoFctAgvEntity : qcInfoFctAgvEntities){
+                if(StringUtils.isBlank(qcInfoFctAgvEntity.getSlot())) continue;
+                if(invLotLocIdService.updateQcStatusByLotNo(qcInfoFctAgvEntity.getSlot(), "HG")){
+                    updateQcInfoStatus(qcInfoFctAgvEntity.getSlot(), Constants.YES);
+                }
+            }
+        }catch (RuntimeException ex){
+            log.warn("syncQcStatusTask error is hanppened, causeby:{}", ex);
+        }
+    }
+
+    /**
+     * 更新质检信息的处理状态
+     * @param lotNo 质检信息的批次号
+     * @param processFlag 是否已处理(Y:已处理  N:未处理)
      * @return
      */
     @Override
-    public Boolean updateQcInfoStatus(String id, String status) {
-        QcInfoFctAgvEntity qcInfoFctAgvEntity = new QcInfoFctAgvEntity();
-        String processFlag = Sets.newHashSet(AVG_PROCESS, PERSON_PROCESS).add(status)
-                ? Constants.NO : Constants.YES;
-        qcInfoFctAgvEntity.setId(id).setProcessFlag(processFlag).setStatus(status);
-        baseDao.updateById(qcInfoFctAgvEntity);
-        return baseDao.updateById(qcInfoFctAgvEntity) == 1;
+    public Boolean updateQcInfoStatus(String lotNo, String processFlag) {
+        return baseDao.update(null,  Wrappers.<QcInfoFctAgvEntity>lambdaUpdate()
+                .set(QcInfoFctAgvEntity::getProcessFlag, processFlag).eq(QcInfoFctAgvEntity::getSlot, lotNo)) > 0;
+
     }