From db11361d175266a95c4cc058f1daf25c08b7dc12 Mon Sep 17 00:00:00 2001
From: WS <1143478319@qq.com>
Date: 星期二, 15 八月 2023 11:09:13 +0800
Subject: [PATCH] V4.0版本入库质检数据同步

---
 src/main/java/com/fzzy/async/fzzy40/entity/Fz40CheckItem.java         |  112 ++++++++++++++++++
 src/main/java/com/fzzy/async/fzzy40/impl/Fzzy40Sync1203.java          |  200 +++++++++++++++++++++++++++++++++
 src/main/java/com/fzzy/async/fzzy40/entity/Fz40CheckItemKey.java      |   18 +++
 src/main/java/com/fzzy/async/fzzy40/repository/Fzzy40Sync1203Rep.java |   23 +++
 src/main/java/com/fzzy/async/fzzy40/Fzzy40SyncService12.java          |    4 
 5 files changed, 357 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/fzzy/async/fzzy40/Fzzy40SyncService12.java b/src/main/java/com/fzzy/async/fzzy40/Fzzy40SyncService12.java
index 6aa894c..11947f2 100644
--- a/src/main/java/com/fzzy/async/fzzy40/Fzzy40SyncService12.java
+++ b/src/main/java/com/fzzy/async/fzzy40/Fzzy40SyncService12.java
@@ -3,6 +3,7 @@
 import com.fzzy.api.data.ApiParam;
 import com.fzzy.api.data.SyncProtocol;
 import com.fzzy.api.service.SyncService12;
+import com.fzzy.async.fzzy35.impl.Fzzy35Sync1203;
 import com.fzzy.async.fzzy35.impl.Fzzy35Sync1208;
 import com.fzzy.async.fzzy40.impl.*;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -27,6 +28,8 @@
     private Fzzy40Sync1212 fzzySync1212;
     @Autowired
     private Fzzy40Sync1208 fzzySync1208;
+    @Autowired
+    private Fzzy40Sync1203 fzzySync1203;
 
     @Override
     public String getProtocol() {
@@ -51,6 +54,7 @@
         fzzySync1202.syncData(kqdm, deptId, start, end);
 
         //绮鍏ュ簱璐ㄦ  TODO
+        fzzySync1203.syncData(kqdm, deptId, start, end);
 
         //绮鍏ュ簱缁撶畻  TODO
 
diff --git a/src/main/java/com/fzzy/async/fzzy40/entity/Fz40CheckItem.java b/src/main/java/com/fzzy/async/fzzy40/entity/Fz40CheckItem.java
new file mode 100644
index 0000000..6fff5fd
--- /dev/null
+++ b/src/main/java/com/fzzy/async/fzzy40/entity/Fz40CheckItem.java
@@ -0,0 +1,112 @@
+package com.fzzy.async.fzzy40.entity;
+
+import com.bstek.dorado.annotation.PropertyDef;
+import com.fzzy.async.fzzy35.entity.Fz35CheckItemKey;
+import lombok.Data;
+
+import javax.persistence.*;
+import java.io.Serializable;
+
+/**
+ * 鐢ㄤ簬鍑哄叆搴撹川妫�璇︾粏椤瑰拰鏃ュ父宸℃鐨勮缁嗛」璁板綍
+ *
+ * @author: andy.jia
+ * @description:
+ * @version:
+ * @data:2020骞�4鏈�7鏃�
+ */
+@Data
+@Entity
+@Table(name = "D_CHECK_ITEM")
+@IdClass(Fz40CheckItemKey.class)
+public class Fz40CheckItem implements Serializable {
+
+    /**
+     *
+     */
+    private static final long serialVersionUID = 1L;
+
+    @Id
+    @Column(name = "CHECK_ID_", length = 40)
+    @PropertyDef(label = "妫�娴嬬紪鐮�")
+    private String checkId;
+
+    @Id
+    @Column(name = "COMPANY_ID_", length = 10)
+    @PropertyDef(label = "缁勭粐缂栫爜")
+    private String companyId;
+
+    @Id
+    @Column(name = "STANDARD_ID_", length = 10)
+    @PropertyDef(label = "妫�娴嬮」缂栫爜")
+    private String standardId;
+
+    @Column(name = "STANDARD_NAME_", length = 50)
+    @PropertyDef(label = "鍖栭獙椤�")
+    private String standardName;
+
+    @Column(name = "UNIT_", length = 20)
+    @PropertyDef(label = "鍗曚綅")
+    private String unit;
+
+    @Column(name = "UPPER_LIMIT_")
+    @PropertyDef(label = "鏍囧噯浼愬��")
+    private Double upperLimit;
+
+    @Column(name = "OPERA_SYMBOL_", length = 4)
+    @PropertyDef(label = "杩愮畻绗﹀彿")
+    private String operaSymbol;
+
+    @Column(name = "RULE_NUM_")
+    @PropertyDef(label = "鎵i噸绯绘暟")
+    private Double ruleNum;
+
+    @Column(name = "RULE_ADD_")
+    @PropertyDef(label = "澧為噸%")
+    private Double ruleAdd;
+
+    @Column(name = "RULE_ADD_END_")
+    @PropertyDef(label = "澧為噸涓婇檺%")
+    private Double ruleAddEnd;
+
+    @Column(name = "RULE_REDUCE_")
+    @PropertyDef(label = "鎵i噸鍊�%")
+    private Double ruleReduce;
+
+    @Column(name = "VALUE_", length = 40)
+    @PropertyDef(label = "妫�娴嬪��")
+    private String value;
+
+    @Column(name = "RULE_PRICE_")
+    @PropertyDef(label = "鎵h垂绯绘暟")
+    private Double rulePrice;
+
+    @Column(name = "RULE_REDUCE_PRICE_")
+    @PropertyDef(label = "鎵h垂")
+    private Double ruleReducePrice;
+
+    @Column(name = "ADD_NUM_")
+    @PropertyDef(label = "澧為噸", description = "鍗曚綅锛歬G")
+    private Double addNum;
+
+    @Column(name = "DE_NUM_")
+    @PropertyDef(label = "鎵i噸", description = "鍗曚綅锛歬G")
+    private Double deNum;
+
+    @Column(name = "ADD_PRICE_")
+    @PropertyDef(label = "澧炰环", description = "鍗曚綅锛氬厓")
+    private Double addPrice;
+
+    @Column(name = "DE_PRICE_")
+    @PropertyDef(label = "鎵d环", description = "鍗曚綅锛氬厓")
+    private Double dePrice;
+
+    @Column(name = "RESULT_", length = 2)
+    @PropertyDef(label = "妫�楠岀粨鏋�", description = "0=涓嶅悎鏍� 1=鍚堟牸")
+    private String result;
+
+    @Column(name = "REMARKS_", length = 50)
+    @PropertyDef(label = "澶囨敞")
+    private String remarks;
+
+}
diff --git a/src/main/java/com/fzzy/async/fzzy40/entity/Fz40CheckItemKey.java b/src/main/java/com/fzzy/async/fzzy40/entity/Fz40CheckItemKey.java
new file mode 100644
index 0000000..b6c995d
--- /dev/null
+++ b/src/main/java/com/fzzy/async/fzzy40/entity/Fz40CheckItemKey.java
@@ -0,0 +1,18 @@
+package com.fzzy.async.fzzy40.entity;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+@AllArgsConstructor
+public class Fz40CheckItemKey implements Serializable {
+        private String checkId;
+        private String companyId;
+        private String standardId;
+
+    public Fz40CheckItemKey(){
+            super();
+        }
+    }
\ No newline at end of file
diff --git a/src/main/java/com/fzzy/async/fzzy40/impl/Fzzy40Sync1203.java b/src/main/java/com/fzzy/async/fzzy40/impl/Fzzy40Sync1203.java
new file mode 100644
index 0000000..ded0330
--- /dev/null
+++ b/src/main/java/com/fzzy/async/fzzy40/impl/Fzzy40Sync1203.java
@@ -0,0 +1,200 @@
+package com.fzzy.async.fzzy40.impl;
+
+import com.fzzy.api.Constant;
+import com.fzzy.api.entity.Api1105;
+import com.fzzy.api.entity.Api1203;
+import com.fzzy.api.entity.ApiLog;
+import com.fzzy.api.entity.GbCheckItem;
+import com.fzzy.api.service.ApiCommonService;
+import com.fzzy.api.service.ApiTriggerService;
+import com.fzzy.api.utils.ContextUtil;
+import com.fzzy.api.view.repository.Api1203Rep;
+import com.fzzy.api.view.repository.ApiLogRep;
+import com.fzzy.api.view.repository.GbCheckItemRep;
+import com.fzzy.async.fzzy40.entity.Fz40CheckItem;
+import com.fzzy.async.fzzy40.entity.Fz40InoutRecord;
+import com.fzzy.async.fzzy40.repository.Fzzy40Sync1202Rep;
+import com.fzzy.async.fzzy40.repository.Fzzy40Sync1203Rep;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.time.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 绮鍏ュ簱妫�楠屼俊鎭�
+ */
+@Slf4j
+@Component
+public class Fzzy40Sync1203 {
+
+    /**
+     * 鍏ュ簱绫诲瀷
+     */
+    private final static String INOUT_TYPE_IN = "IN";
+
+    @Autowired
+    private Fzzy40Sync1202Rep fzzySync1202Rep;
+    @Autowired
+    private Fzzy40Sync1203Rep fzzySync1203Rep;
+
+    @Autowired
+    private ApiTriggerService apiTriggerService;
+    @Autowired
+    private Api1203Rep api1203Rep;
+    @Autowired
+    private GbCheckItemRep gbCheckItemRep;
+    @Autowired
+    private ApiCommonService commonService;
+    @Autowired
+    private ApiLogRep apiLogRep;
+
+    /**
+     * 绮鍏ュ簱妫�楠屼俊鎭�
+     *
+     * @param deptId
+     * @param start
+     * @param end
+     */
+    public void syncData(String kqdm, String deptId, Date start, Date end) {
+
+        log.info("-------------1203鎺ュ彛鏁版嵁寮�濮嬪悓姝�------------------");
+
+        //鍚屾鏁版嵁锛屽彧璁板綍澶辫触鐨勪俊鎭�
+        ApiLog apiLog = new ApiLog();
+        apiLog.setType(ApiLog.TYPE_SYNC);
+        apiLog.setKqdm(deptId);
+        apiLog.setUploadTime(new Date());
+        apiLog.setInteId(Constant.API_CODE_1203);
+        apiLog.setStatus(99);
+        apiLog.setId(ContextUtil.getUUID());
+        try {
+            //鑾峰彇绮鍏ュ簱璁板綍淇℃伅
+            List<Fz40InoutRecord> list = fzzySync1202Rep.listInoutRecord(deptId, INOUT_TYPE_IN, start, end);
+
+            if (null == list || list.isEmpty()) {
+                log.info("-------------娌℃湁鑾峰彇鍒扮伯椋熷叆搴撲俊鎭�------------------");
+                return;
+            }
+
+            Api1203 apiData;
+            Api1105 api1105;
+            List<Fz40CheckItem> fz40CheckItems;
+            List<GbCheckItem> gbCheckList;
+            String jyxm;
+            String jyz;
+            String zkj;
+            String zkl;
+            List<Api1203> api1203List;
+            for (Fz40InoutRecord sysData : list) {
+                if(null == sysData.getRecordWeight() || sysData.getRecordWeight() == 0){
+                    sysData.setRecordWeight(sysData.getSettleWeight());
+                }
+                //鍒ゆ柇鍑�閲嶆槸鍚﹀ぇ浜�0锛岀瓑浜�0琛ㄧず涓嶅悎鏍硷紝涓嶈繘琛屽悓姝ヤ笂浼�
+                if(null == sysData.getRecordWeight() || sysData.getRecordWeight() == 0){
+                    continue;
+                }
+
+                //鑾峰彇鍏ュ簱璐ㄦ淇℃伅
+                fz40CheckItems = fzzySync1203Rep.listInoutCheckItem(sysData.getCheckId(), deptId.substring(0, 4));
+                if (null == fz40CheckItems || fz40CheckItems.isEmpty()) {
+                    log.info("-------------娌℃湁鑾峰彇鍒板綋鍓嶅叆搴撹川妫�淇℃伅--------------");
+                    continue;
+                }
+
+                //鑾峰彇璐т綅淇℃伅
+                api1105 = commonService.getApi1105Cache(sysData.getDepotId());
+                if (null == api1105) {
+                    continue;
+                }
+
+                apiData = new Api1203();
+
+                apiData.setRkjydh(Constant.INOUT_TYPE_14 + sysData.getId().substring(4));
+
+                //璐т綅浠g爜
+                apiData.setHwdm(api1105.getHwdm());
+                apiData.setRkywdh(apiData.getRkjydh());
+                if(null == sysData.getFullWeightTime()){
+                    sysData.setFullWeightTime(DateUtils.addMinutes(sysData.getRegisterTime(), 5));
+                }
+                apiData.setQysj(sysData.getFullWeightTime());
+                apiData.setQyrxm(sysData.getCheckUser());
+                //鎵︽牱鏂瑰紡 2-鏅鸿兘闅忔満
+                apiData.setQyfs("2");
+
+                //妫�娴嬮」锛屾娴嬪�硷紝澧炴墸浠峰強澧炴墸閲�
+                jyxm = "";
+                jyz = "";
+                zkj = "";
+                zkl = "";
+                for (Fz40CheckItem fz40CheckItem : fz40CheckItems) {
+                    gbCheckList = gbCheckItemRep.findByBizCode(fz40CheckItem.getStandardId());
+
+                    if (gbCheckList == null || gbCheckList.isEmpty()) {
+                        continue;
+                    }
+                    if (StringUtils.isEmpty(fz40CheckItem.getValue())) {
+                        continue;
+                    }
+                    jyxm += gbCheckList.get(0).getCode() + ",";
+                    jyz += fz40CheckItem.getValue() + ",";
+                    zkj += ",0.0";
+                    zkl += ",0.0";
+                }
+
+                apiData.setJyxm(jyxm);
+                apiData.setJyz(jyz);
+                apiData.setZkj(zkj.substring(1));
+                apiData.setZkl(zkl.substring(1));
+                if("UNPASS".equals(sysData.getCheckStatus())){
+                    apiData.setJyjg("0");
+                }
+                if("PASS".equals(sysData.getCheckStatus())){
+                    apiData.setJyjg("1");
+                }
+                apiData.setJyrxm(sysData.getCheckUser());
+                apiData.setJysj(DateUtils.addMinutes(sysData.getFullWeightTime(), 5));
+
+                //绮鍝佺
+                String mappingCode = apiTriggerService.getMappingCode(Constant.TRIGGER_P_LSPZ, sysData.getFoodVariety());
+                apiData.setLspzdm(mappingCode);
+
+                //绮瀹氱瓑
+
+                //淇濈鍛樺鏍�
+
+
+                //绮绛夌骇
+                mappingCode = apiTriggerService.getMappingCode(Constant.TRIGGER_P_LSDJ, sysData.getFoodLevel());
+                apiData.setLsdd(mappingCode);
+
+                //鎿嶄綔鏍囧織鍙婃渶鍚庢洿鏂版椂闂�
+                apiData.setZhgxsj(sysData.getCompleteTime());
+
+                //涓氬姟id銆佸簱鍖虹紪鐮併�佸悓姝ユ椂闂�
+                apiData.setBizId(sysData.getId());
+                apiData.setKqdm(kqdm);
+                apiData.setSyncTime(new Date());
+
+                api1203List = api1203Rep.getDataById(apiData.getRkjydh());
+                if(null == api1203List || api1203List.isEmpty()){
+                    apiData.setCzbz(Constant.CZBZ_I);
+                }else {
+                    apiData.setCzbz(api1203List.get(0).getCzbz());
+                }
+
+                //淇濆瓨鏁版嵁
+                api1203Rep.save(apiData);
+                log.info("1203---鍚屾鏁版嵁锛歿}", apiData.toString());
+            }
+        } catch (Exception e) {
+            log.error("---鍚屾澶辫触----{}", e);
+            apiLog.setResult("鍚屾澶辫触锛�" + e.getMessage());
+            apiLogRep.save(apiLog);
+        }
+    }
+}
diff --git a/src/main/java/com/fzzy/async/fzzy40/repository/Fzzy40Sync1203Rep.java b/src/main/java/com/fzzy/async/fzzy40/repository/Fzzy40Sync1203Rep.java
new file mode 100644
index 0000000..374137f
--- /dev/null
+++ b/src/main/java/com/fzzy/async/fzzy40/repository/Fzzy40Sync1203Rep.java
@@ -0,0 +1,23 @@
+package com.fzzy.async.fzzy40.repository;
+
+import com.fzzy.async.fzzy40.entity.Fz40CheckItem;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+
+import java.util.List;
+
+/**
+ * 绮鍏ュ簱璐ㄦ
+ */
+public interface Fzzy40Sync1203Rep extends JpaRepository<Fz40CheckItem, String> {
+
+    /**
+     * 鏍规嵁鍏ュ簱妫�楠岀紪鐮佽幏鍙栨楠屼俊鎭�
+     *
+     * @param checkId
+     * @return
+     */
+    @Query("from Fz40CheckItem where checkId=:checkId and companyId=:companyId order by standardId")
+    List<Fz40CheckItem> listInoutCheckItem(@Param("checkId") String checkId, @Param("companyId") String companyId);
+}

--
Gitblit v1.9.3