From 1bb55039e42042aad3433a12b2d48c5a91234210 Mon Sep 17 00:00:00 2001
From: CZT <czt18638530771@163.com>
Date: 星期一, 04 三月 2024 18:08:57 +0800
Subject: [PATCH] 增加账面库存同步功能

---
 src/main/java/com/fzzy/async/fzzy40/entity/Fz40DepotBookStore.java    |   90 ++++++++++++++++++
 src/main/java/com/fzzy/api/entity/Api1211.java                        |   21 ++--
 src/main/java/com/fzzy/async/fzzy40/impl/Fzzy40Sync1211.java          |  113 ++++++++++++++++++++++
 src/main/java/com/fzzy/api/view/repository/Api1211Rep.java            |    7 +
 src/main/java/com/fzzy/async/fzzy40/repository/Fzzy40Sync1211Rep.java |   22 ++++
 src/main/java/com/fzzy/async/fzzy40/Fzzy40SyncService12.java          |   18 ++-
 6 files changed, 251 insertions(+), 20 deletions(-)

diff --git a/src/main/java/com/fzzy/api/entity/Api1211.java b/src/main/java/com/fzzy/api/entity/Api1211.java
index fe9d9dd..39103b2 100644
--- a/src/main/java/com/fzzy/api/entity/Api1211.java
+++ b/src/main/java/com/fzzy/api/entity/Api1211.java
@@ -34,9 +34,8 @@
 	
 	@JSONField(serialize = false)
 	@Id
-	@GeneratedValue(strategy = GenerationType.IDENTITY)
-	@Column(name = "id")
-	private Integer id;
+    @Column(name = "bizId", length = 60)
+	private String id;
 
     @JSONField(serialize = false)
     @PropertyDef(label = "涓氬姟id")
@@ -55,33 +54,33 @@
     @Column(name = "lsxzdm", length = 7)
     private String lsxzdm;
 
-    @PropertyDef(label = "绮鍝佺浠g爜",required=true)
+    @PropertyDef(label = "绮鍝佺浠g爜")
     @Column(name = "lspzdm", length = 7)
     private String lspzdm;
 
-    @PropertyDef(label = "骞村害" ,required=true)
+    @PropertyDef(label = "骞村害" )
     @Column(name = "nd", length = 4)
     private String nd;
 
-    @PropertyDef(label = "鏈堜唤" ,required=true)
+    @PropertyDef(label = "鏈堜唤" )
     @Column(name = "yf", length = 2)
     private String yf;
 
-    @PropertyDef(label = "鏈熷垵鏁伴噺(鍏枻)",required=true )
+    @PropertyDef(label = "鏈熷垵鏁伴噺(鍏枻)" )
     @Column(name = "qcsl", precision = 20, scale = 6)
-    private double qcsl;
+    private Double qcsl;
 
     @PropertyDef(label = "鏈湡鏀跺叆鏁伴噺(鍏枻)" )
     @Column(name = "bqsrsl", precision = 20, scale = 6)
-    private double bqsrsl;
+    private Double bqsrsl;
 
     @PropertyDef(label = "鏈湡鏀嚭鏁伴噺(鍏枻)" )
     @Column(name = "bqzcsl", precision = 20, scale = 6)
-    private double bqzcsl;
+    private Double bqzcsl;
 
     @PropertyDef(label = "鏈熸湯鏁伴噺(鍏枻)" )
     @Column(name = "qmye", precision = 20, scale = 6)
-    private double qmye;
+    private Double qmye;
 
     @PropertyDef(label = "鏈堢粨鏍囧織" )
     @Column(name = "yjbz")
diff --git a/src/main/java/com/fzzy/api/view/repository/Api1211Rep.java b/src/main/java/com/fzzy/api/view/repository/Api1211Rep.java
index 7b4a244..78309b9 100644
--- a/src/main/java/com/fzzy/api/view/repository/Api1211Rep.java
+++ b/src/main/java/com/fzzy/api/view/repository/Api1211Rep.java
@@ -10,12 +10,15 @@
 import java.util.Date;
 import java.util.List;
 
-public interface Api1211Rep extends JpaRepository<Api1211, Integer>, JpaSpecificationExecutor<Api1211> {
+public interface Api1211Rep extends JpaRepository<Api1211, String>, JpaSpecificationExecutor<Api1211> {
     @Transactional
     @Modifying
     @Query("update Api1211 set czbz =:czbz where id=:id")
-    void updateStatus(@Param("id") Integer id, @Param("czbz") String czbz);
+    void updateStatus(@Param("id") String id, @Param("czbz") String czbz);
 
     @Query("from Api1211 where kqdm=:kqdm and zhgxsj >=:start and zhgxsj <:end order by zhgxsj ")
     List<Api1211> findPushDataByTime(@Param("kqdm") String kqdm, @Param("start") Date start, @Param("end") Date end);
+
+    @Query("from Api1211 where bizId =:bizId ")
+    List<Api1211> getDataByBizId(@Param("bizId") String bizId);
 }
diff --git a/src/main/java/com/fzzy/async/fzzy40/Fzzy40SyncService12.java b/src/main/java/com/fzzy/async/fzzy40/Fzzy40SyncService12.java
index abac48f..4154085 100644
--- a/src/main/java/com/fzzy/async/fzzy40/Fzzy40SyncService12.java
+++ b/src/main/java/com/fzzy/async/fzzy40/Fzzy40SyncService12.java
@@ -23,23 +23,25 @@
     @Autowired
     private Fzzy40Sync1202 fzzySync1202;
     @Autowired
-    private Fzzy40Sync1205 fzzySync1205;
-    @Autowired
-    private Fzzy40Sync1212 fzzySync1212;
-    @Autowired
-    private Fzzy40Sync1208 fzzySync1208;
-    @Autowired
     private Fzzy40Sync1203 fzzySync1203;
     @Autowired
     private Fzzy40Sync1204 fzzySync1204;
+    @Autowired
+    private Fzzy40Sync1205 fzzySync1205;
     @Autowired
     private Fzzy40Sync1206 fzzySync1206;
     @Autowired
     private Fzzy40Sync1207 fzzySync1207;
     @Autowired
+    private Fzzy40Sync1208 fzzySync1208;
+    @Autowired
     private Fzzy40Sync1209 fzzySync1209;
     @Autowired
+    private Fzzy40Sync1211 fzzySync1211;
+    @Autowired
     private Fzzy40Sync1210 fzzySync1210;
+    @Autowired
+    private Fzzy40Sync1212 fzzySync1212;
     @Autowired
     private Fzzy40Sync1109 fzzySync1109;
     @Autowired
@@ -95,6 +97,9 @@
         //绮鎬ц川杞彉淇℃伅鍚屾
         fzzySync1210.syncData(kqdm, deptId, start, end);
 
+        //璐﹂潰搴撳瓨淇℃伅鍚屾
+        fzzySync1211.syncData(kqdm, deptId, start, end);
+
         /*-----鍚勭渷鐙湁鎺ュ彛淇℃伅鍚屾-----*/
         //涓婃捣甯傚钩鍙�2023鐗�
         if (StringUtils.isNotEmpty(param.getPushProtocol()) && PushProtocol.SB_SH_2023.getCode().equals(param.getPushProtocol())) {
@@ -105,7 +110,6 @@
 //            //鍚屾甯傚偍椹宠繍鍗�
 //            fzzySync2104.syncData(param.getKqdm(), param.getDeptId(), param.getStart(), param.getEnd());
         }
-        //璐﹂潰搴撳瓨淇℃伅鍚屾  TODO
 
     }
 
diff --git a/src/main/java/com/fzzy/async/fzzy40/entity/Fz40DepotBookStore.java b/src/main/java/com/fzzy/async/fzzy40/entity/Fz40DepotBookStore.java
new file mode 100644
index 0000000..72c555e
--- /dev/null
+++ b/src/main/java/com/fzzy/async/fzzy40/entity/Fz40DepotBookStore.java
@@ -0,0 +1,90 @@
+package com.fzzy.async.fzzy40.entity;
+
+import com.alibaba.fastjson.annotation.JSONField;
+import com.bstek.dorado.annotation.PropertyDef;
+import lombok.Data;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @author czt
+ *
+ * 鎸変粨搴撹繘琛岀粺璁★紝姣忎釜鏈堝簳缁熻涓�娆�(鍥犱笂娴峰競璐﹂潰搴撳瓨鎺ュ彛涓烘寜璐т綅缁熻锛岃浆鎹㈡帴鍙f湇鍔℃椂鏍规嵁鐪佷唤瑕佹眰缁熻鎴愬搴旂殑璐﹂潰搴撳瓨)
+ **/
+@Data
+@Entity
+@Table(name = "D_DEPOT_BOOK_STORE")
+public class Fz40DepotBookStore implements Serializable {
+    /**
+     *
+     */
+    private static final long serialVersionUID = 1L;
+
+    @Id
+    @Column(name = "ID_", length = 40)
+    @PropertyDef(label = "涓婚敭", description = "瑙勫垯锛氫粨搴撶紪鐮乢yyyyMMdd")
+    private String id;
+
+    @Column(name = "COMPANY_ID_", length = 10)
+    @PropertyDef(label = "缁勭粐缂栫爜")
+    private String companyId;
+
+    @Column(name = "DEPT_ID_", length = 20)
+    @PropertyDef(label = "搴撳尯浠g爜")
+    private String deptId;
+
+    @Column(name = "DEPOT_ID_", length = 30)
+    @PropertyDef(label = "浠撳簱缂栫爜")
+    private String depotId;
+
+    @Column(name = "lspzdm", length = 7)
+    @PropertyDef(label = "绮鍝佺浠g爜")
+    private String lspzdm;
+
+    @PropertyDef(label = "绮鎬ц川浠g爜", description = "鐩墠涓婃捣浣跨敤")
+    @Column(name = "lsxzdm", length = 7)
+    private String lsxzdm;
+
+    @Column(name = "nd", length = 4)
+    @PropertyDef(label = "骞村害")
+    private String nd;
+
+    @Column(name = "yf", length = 2)
+    @PropertyDef(label = "鏈堜唤")
+    private String yf;
+
+    @Column(name = "qcsl", precision = 20, scale = 3)
+    @PropertyDef(label = "鏈熷垵鏁伴噺", description = "鍗曚綅锛氬叕鏂�")
+    private Double qcsl = 0.0;
+
+    @Column(name = "bqsrsl", precision = 20, scale = 3)
+    @PropertyDef(label = "鏈湡鏀跺叆鏁伴噺", description = "鍗曚綅锛氬叕鏂�")
+    private Double bqsrsl = 0.0;
+
+    @Column(name = "bqzcsl", precision = 20, scale = 3)
+    @PropertyDef(label = "鏈湡鏀嚭鏁伴噺", description = "鍗曚綅锛氬叕鏂�")
+    private Double bqzcsl = 0.0;
+
+    @Column(name = "qmye", precision = 20, scale = 3)
+    @PropertyDef(label = "鏈熸湯鏁伴噺", description = "鍗曚綅锛氬叕鏂�")
+    private Double qmye = 0.0;
+
+    @Column(name = "yjbz")
+    @PropertyDef(label = "鏈堢粨鏍囧織", description = "0锛氭湀缁擄紱1 鏈湀缁�")
+    private Integer yjbz;
+
+    @Column(name = "ywrq")
+    @PropertyDef(label = "涓氬姟鏃ユ湡")
+    private Date ywrq;
+
+    @Column(name = "zhgxsj")
+    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
+    @PropertyDef(label = "鏈�鍚庢洿鏂版椂闂�")
+    private Date zhgxsj;
+
+}
diff --git a/src/main/java/com/fzzy/async/fzzy40/impl/Fzzy40Sync1211.java b/src/main/java/com/fzzy/async/fzzy40/impl/Fzzy40Sync1211.java
new file mode 100644
index 0000000..7f3bf5d
--- /dev/null
+++ b/src/main/java/com/fzzy/async/fzzy40/impl/Fzzy40Sync1211.java
@@ -0,0 +1,113 @@
+package com.fzzy.async.fzzy40.impl;
+
+import com.fzzy.api.Constant;
+import com.fzzy.api.entity.*;
+import com.fzzy.api.service.ApiCommonService;
+import com.fzzy.api.service.ApiTriggerService;
+import com.fzzy.api.utils.ContextUtil;
+import com.fzzy.api.view.repository.*;
+import com.fzzy.async.fzzy40.entity.Fz40DepotBookStore;
+import com.fzzy.async.fzzy40.repository.Fzzy40Sync1211Rep;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author czt
+ * 璐﹂潰搴撳瓨
+ */
+@Slf4j
+@Component
+public class Fzzy40Sync1211 {
+
+    @Autowired
+    private Fzzy40Sync1211Rep fzzy40Sync1211Rep;
+    @Autowired
+    private ApiTriggerService apiTriggerService;
+    @Autowired
+    private Api1211Rep api1211Rep;
+    @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("-------------1211鎺ュ彛鏁版嵁寮�濮嬪悓姝�------------------");
+
+        //鍚屾鏁版嵁锛屽彧璁板綍澶辫触鐨勪俊鎭�
+        ApiLog apiLog = new ApiLog();
+        apiLog.setType(ApiLog.TYPE_SYNC);
+        apiLog.setKqdm(deptId);
+        apiLog.setUploadTime(new Date());
+        apiLog.setInteId(Constant.API_CODE_1208);
+        apiLog.setStatus(99);
+        apiLog.setId(ContextUtil.getUUID());
+        try {
+            List<Fz40DepotBookStore> list = fzzy40Sync1211Rep.listDepot(deptId, start, end);
+            if (null == list || list.isEmpty()) {
+                log.info("-------------娌℃湁鑾峰彇鍒拌处闈㈠簱瀛樹俊鎭�------------------");
+                return;
+            }
+
+            Api1211 apiData;
+            Api1105 api1105;
+            List<Api1211> api1211List;
+            for (Fz40DepotBookStore fz40DepotBookStore : list) {
+
+                //鑾峰彇璐т綅淇℃伅
+                api1105 = commonService.getApi1105Cache(fz40DepotBookStore.getDepotId());
+                if (null == api1105) {
+                    continue;
+                }
+
+                apiData = new Api1211();
+                apiData.setId(fz40DepotBookStore.getId());
+                apiData.setBizId(fz40DepotBookStore.getId());
+                apiData.setKqdm(kqdm);
+                apiData.setHwdm(api1105.getHwdm());
+
+                //绮鍝佺
+                String mappingCode = apiTriggerService.getMappingCode(Constant.TRIGGER_P_LSPZ, fz40DepotBookStore.getLspzdm().substring(0, 3));
+                apiData.setLspzdm(mappingCode);
+
+                //绮鎬ц川
+                mappingCode = apiTriggerService.getMappingCode(Constant.TRIGGER_P_LSXZ, fz40DepotBookStore.getLsxzdm());
+                apiData.setLsxzdm(mappingCode);
+                apiData.setNd(fz40DepotBookStore.getNd());
+                apiData.setYf(fz40DepotBookStore.getYf());
+                apiData.setQcsl(fz40DepotBookStore.getQcsl() == null ? 0.0 : fz40DepotBookStore.getQcsl());
+                apiData.setBqsrsl(fz40DepotBookStore.getBqsrsl() == null ? 0.0 : fz40DepotBookStore.getBqsrsl());
+                apiData.setBqzcsl(fz40DepotBookStore.getBqzcsl() == null ? 0.0 : fz40DepotBookStore.getBqzcsl());
+                apiData.setQmye(fz40DepotBookStore.getQmye() == null ? 0.0 : fz40DepotBookStore.getQmye());
+                apiData.setYjbz(fz40DepotBookStore.getYjbz());
+                apiData.setYwrq(fz40DepotBookStore.getYwrq());
+                apiData.setZhgxsj(new Date());
+
+                api1211List = api1211Rep.getDataByBizId(apiData.getBizId());
+                if (null == api1211List || api1211List.isEmpty()) {
+                    apiData.setCzbz(Constant.CZBZ_I);
+                } else {
+                    apiData.setCzbz(api1211List.get(0).getCzbz());
+                }
+
+                //淇濆瓨鏁版嵁
+                api1211Rep.save(apiData);
+            }
+
+        } catch (Exception e) {
+            log.error("---鍚屾澶辫触----{}", e);
+            apiLog.setResult("鍚屾澶辫触锛�" + e.getMessage());
+            apiLogRep.save(apiLog);
+        }
+    }
+}
\ No newline at end of file
diff --git a/src/main/java/com/fzzy/async/fzzy40/repository/Fzzy40Sync1211Rep.java b/src/main/java/com/fzzy/async/fzzy40/repository/Fzzy40Sync1211Rep.java
new file mode 100644
index 0000000..dea8c34
--- /dev/null
+++ b/src/main/java/com/fzzy/async/fzzy40/repository/Fzzy40Sync1211Rep.java
@@ -0,0 +1,22 @@
+package com.fzzy.async.fzzy40.repository;
+
+import com.fzzy.async.fzzy40.entity.Fz40DepotBookStore;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 绮璐攢-璐﹂潰搴撳瓨
+ */
+public interface Fzzy40Sync1211Rep extends JpaRepository<Fz40DepotBookStore, String> {
+
+    /**
+     * 鏍规嵁搴撳尯缂栫爜鍙婃椂闂磋幏鍙栬处闈㈠簱瀛樹俊鎭�
+     *
+     * @return
+     */
+    @Query("from Fz40DepotBookStore where deptId=:deptId and zhgxsj >=:start and zhgxsj <:end order by zhgxsj ")
+    List<Fz40DepotBookStore> listDepot(@Param("deptId") String deptId, @Param("start") Date start, @Param("end") Date end);
+}

--
Gitblit v1.9.3