From 7784091caf4dd841dbf731a6c5b3635d8eedd982 Mon Sep 17 00:00:00 2001
From: LSH
Date: 星期二, 03 一月 2023 15:00:49 +0800
Subject: [PATCH] #中间表获取商品信息
---
src/main/java/com/zy/ints/task/scheduler/ErpDetTbScheduler.java | 19 +
src/main/java/com/zy/ints/entity/ErpLk.java | 96 ++++++
src/main/java/com/zy/ints/erp/ErpDbProperties.java | 30 ++
src/main/java/com/zy/ints/entity/Prdt.java | 78 +++++
src/main/java/com/zy/ints/entity/DetTb.java | 142 +++++++++
src/main/java/com/zy/ints/erp/ErpSqlServer.java | 364 ++++++++++++++++++++++++
src/main/resources/application.yml | 17 +
src/main/java/com/zy/ints/task/scheduler/ErpPrdtScheduler.java | 122 ++++++++
8 files changed, 867 insertions(+), 1 deletions(-)
diff --git a/src/main/java/com/zy/ints/entity/DetTb.java b/src/main/java/com/zy/ints/entity/DetTb.java
new file mode 100644
index 0000000..4c901c5
--- /dev/null
+++ b/src/main/java/com/zy/ints/entity/DetTb.java
@@ -0,0 +1,142 @@
+package com.zy.ints.entity;
+
+import com.core.common.Cools;import com.baomidou.mybatisplus.annotations.TableId;
+import com.baomidou.mybatisplus.enums.IdType;
+import com.baomidou.mybatisplus.annotations.TableField;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import com.baomidou.mybatisplus.annotations.TableName;
+import java.io.Serializable;
+
+@Data
+@TableName("erp_det_tb")
+public class DetTb implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * 鍗曟嵁鍙风爜
+ */
+ @ApiModelProperty(value= "鍗曟嵁鍙风爜")
+ @TableId(value = "bill_no", type = IdType.INPUT)
+ @TableField("bill_no")
+ private String billNo;
+
+ /**
+ * 鍝佸彿
+ */
+ @ApiModelProperty(value= "鍝佸彿")
+ @TableId(value = "prd_no", type = IdType.INPUT)
+ @TableField("prd_no")
+ private String prdNo;
+
+ /**
+ * 鍗曟嵁绫诲埆
+ */
+ @ApiModelProperty(value= "鍗曟嵁绫诲埆")
+ private String iokindid;
+
+ /**
+ * 澧炲噺绗﹀彿:1锛堝姞锛屽叆搴擄級銆�2锛堝噺锛屽嚭搴擄級
+ */
+ @ApiModelProperty(value= "澧炲噺绗﹀彿:1锛堝姞锛屽叆搴擄級銆�2锛堝噺锛屽嚭搴擄級")
+ @TableField("add_id")
+ private String addId;
+
+ /**
+ * 鏁伴噺
+ */
+ @ApiModelProperty(value= "鏁伴噺")
+ private Double qty;
+
+ /**
+ * 璐у搧鐗瑰緛
+ */
+ @ApiModelProperty(value= "璐у搧鐗瑰緛")
+ @TableId(value = "prd_mark", type = IdType.INPUT)
+ @TableField("prd_mark")
+ private String prdMark;
+
+ /**
+ * 浠撳簱
+ */
+ @ApiModelProperty(value= "浠撳簱")
+ private String wh;
+
+ /**
+ * 鏃ユ湡
+ */
+ @ApiModelProperty(value= "鏃ユ湡")
+ @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+ private Date billdate;
+
+ /**
+ * 鐘舵��:0锛堝垵濮嬬姸鎬侊級銆�1锛堝凡鎺ユ敹锛夈��2锛堝紓甯革級
+ */
+ @ApiModelProperty(value= "鐘舵��:0锛堝垵濮嬬姸鎬侊級銆�1锛堝凡鎺ユ敹锛夈��2锛堝紓甯革級")
+ private Integer status;
+
+ /**
+ * 澶囩敤瀛楁1
+ */
+ @ApiModelProperty(value= "澶囩敤瀛楁1")
+ private String temp1;
+
+ /**
+ * 澶囩敤瀛楁2
+ */
+ @ApiModelProperty(value= "澶囩敤瀛楁2")
+ private String temp2;
+
+ /**
+ * 澶囩敤瀛楁3
+ */
+ @ApiModelProperty(value= "澶囩敤瀛楁3")
+ private String temp3;
+
+ public DetTb() {}
+
+ public DetTb(String billNo,String prdNo,String iokindid,String addId,Double qty,String prdMark,String wh,Date billdate,Integer status,String temp1,String temp2,String temp3) {
+ this.billNo = billNo;
+ this.prdNo = prdNo;
+ this.iokindid = iokindid;
+ this.addId = addId;
+ this.qty = qty;
+ this.prdMark = prdMark;
+ this.wh = wh;
+ this.billdate = billdate;
+ this.status = status;
+ this.temp1 = temp1;
+ this.temp2 = temp2;
+ this.temp3 = temp3;
+ }
+
+// DetTb detTb = new DetTb(
+// null, // id[闈炵┖]
+// null, // 鍗曟嵁鍙风爜[闈炵┖]
+// null, // 鍝佸彿[闈炵┖]
+// null, // 鍗曟嵁绫诲埆[闈炵┖]
+// null, // 澧炲噺绗﹀彿:1锛堝姞锛屽叆搴擄級銆�2锛堝噺锛屽嚭搴擄級[闈炵┖]
+// null, // 鏁伴噺[闈炵┖]
+// null, // 璐у搧鐗瑰緛[闈炵┖]
+// null, // 浠撳簱
+// null, // 鏃ユ湡[闈炵┖]
+// null, // 鐘舵��:0锛堝垵濮嬬姸鎬侊級銆�1锛堝凡鎺ユ敹锛夈��2锛堝紓甯革級[闈炵┖]
+// null, // 澶囩敤瀛楁1
+// null, // 澶囩敤瀛楁2
+// null // 澶囩敤瀛楁3
+// );
+
+ public String getBilldate$(){
+ if (Cools.isEmpty(this.billdate)){
+ return "";
+ }
+ return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.billdate);
+ }
+
+
+}
diff --git a/src/main/java/com/zy/ints/entity/ErpLk.java b/src/main/java/com/zy/ints/entity/ErpLk.java
new file mode 100644
index 0000000..31cffe7
--- /dev/null
+++ b/src/main/java/com/zy/ints/entity/ErpLk.java
@@ -0,0 +1,96 @@
+package com.zy.ints.entity;
+
+import com.core.common.Cools;import com.baomidou.mybatisplus.annotations.TableId;
+import com.baomidou.mybatisplus.enums.IdType;
+import com.baomidou.mybatisplus.annotations.TableField;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import com.baomidou.mybatisplus.annotations.TableName;
+import java.io.Serializable;
+
+@Data
+@TableName("bas_erp_lk")
+public class ErpLk implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * 鍝佸彿
+ */
+ @ApiModelProperty(value= "鍝佸彿")
+ @TableId(value = "prd_no", type = IdType.INPUT)
+ @TableField("prd_no")
+ private String prdNo;
+
+ /**
+ * 璐у搧鐗瑰緛
+ */
+ @ApiModelProperty(value= "璐у搧鐗瑰緛")
+ @TableId(value = "prd_mark", type = IdType.INPUT)
+ @TableField("prd_mark")
+ private String prdMark;
+
+ /**
+ * 鏁伴噺
+ */
+ @ApiModelProperty(value= "鏁伴噺")
+ private Double qty;
+
+ /**
+ * 浠撳簱
+ */
+ @ApiModelProperty(value= "浠撳簱")
+ private String wh;
+
+ /**
+ * 鐘舵��:0锛堝垵濮嬬姸鎬侊級銆�1锛堝凡鎺ユ敹锛夈��2锛堝紓甯革級
+ */
+ @ApiModelProperty(value= "鐘舵��:0锛堝垵濮嬬姸鎬侊級銆�1锛堝凡鎺ユ敹锛夈��2锛堝紓甯革級")
+ private Integer status;
+
+ /**
+ * 澶囩敤瀛楁1
+ */
+ @ApiModelProperty(value= "澶囩敤瀛楁1")
+ private String temp1;
+
+ /**
+ * 澶囩敤瀛楁2
+ */
+ @ApiModelProperty(value= "澶囩敤瀛楁2")
+ private String temp2;
+
+ /**
+ * 澶囩敤瀛楁3
+ */
+ @ApiModelProperty(value= "澶囩敤瀛楁3")
+ private String temp3;
+
+ public ErpLk() {}
+
+ public ErpLk(String prdNo,String prdMark,Double qty,String wh,Integer status,String temp1,String temp2,String temp3) {
+ this.prdNo = prdNo;
+ this.prdMark = prdMark;
+ this.qty = qty;
+ this.wh = wh;
+ this.status = status;
+ this.temp1 = temp1;
+ this.temp2 = temp2;
+ this.temp3 = temp3;
+ }
+
+// ErpLk erpLk = new ErpLk(
+// null, // id[闈炵┖]
+// null, // 鍝佸彿[闈炵┖]
+// null, // 璐у搧鐗瑰緛[闈炵┖]
+// null, // 鏁伴噺[闈炵┖]
+// null, // 浠撳簱
+// null, // 鐘舵��:0锛堝垵濮嬬姸鎬侊級銆�1锛堝凡鎺ユ敹锛夈��2锛堝紓甯革級[闈炵┖]
+// null, // 澶囩敤瀛楁1
+// null, // 澶囩敤瀛楁2
+// null // 澶囩敤瀛楁3
+// );
+
+
+}
diff --git a/src/main/java/com/zy/ints/entity/Prdt.java b/src/main/java/com/zy/ints/entity/Prdt.java
new file mode 100644
index 0000000..5f65135
--- /dev/null
+++ b/src/main/java/com/zy/ints/entity/Prdt.java
@@ -0,0 +1,78 @@
+package com.zy.ints.entity;
+
+import com.core.common.Cools;import com.baomidou.mybatisplus.annotations.TableId;
+import com.baomidou.mybatisplus.enums.IdType;
+import com.baomidou.mybatisplus.annotations.TableField;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import com.baomidou.mybatisplus.annotations.TableName;
+import java.io.Serializable;
+
+@Data
+@TableName("erp_prdt")
+public class Prdt implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * 鍝佸彿
+ */
+ @ApiModelProperty(value= "鍝佸彿")
+ @TableId(value = "prd_no", type = IdType.INPUT)
+ @TableField("prd_no")
+ private String prdNo;
+
+ /**
+ * 鍝佸悕
+ */
+ @ApiModelProperty(value= "鍝佸悕")
+ private String name;
+
+ /**
+ * 鍗曚綅
+ */
+ @ApiModelProperty(value= "鍗曚綅")
+ private String ut;
+
+ /**
+ * 瑙勬牸
+ */
+ @ApiModelProperty(value= "瑙勬牸")
+ private String spc;
+
+ /**
+ * 绫诲瀷
+ */
+ @ApiModelProperty(value= "绫诲瀷")
+ private Integer type;
+
+ /**
+ * 鐘舵��
+ */
+ @ApiModelProperty(value= "鐘舵��")
+ private Integer status;
+
+ public Prdt() {}
+
+ public Prdt(String prdNo,String name,String ut,String spc,Integer type,Integer status) {
+ this.prdNo = prdNo;
+ this.name = name;
+ this.ut = ut;
+ this.spc = spc;
+ this.type = type;
+ this.status = status;
+ }
+
+// Prdt prdt = new Prdt(
+// null, // id[闈炵┖]
+// null, // 鍝佸彿[闈炵┖]
+// null, // 鍝佸悕[闈炵┖]
+// null, // 鍗曚綅
+// null, // 瑙勬牸
+// null, // 绫诲瀷[闈炵┖]
+// null // 鐘舵�乕闈炵┖]
+// );
+
+
+}
diff --git a/src/main/java/com/zy/ints/erp/ErpDbProperties.java b/src/main/java/com/zy/ints/erp/ErpDbProperties.java
new file mode 100644
index 0000000..30df009
--- /dev/null
+++ b/src/main/java/com/zy/ints/erp/ErpDbProperties.java
@@ -0,0 +1,30 @@
+package com.zy.ints.erp;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+/**
+ * Created by vincent on 2020/11/26
+ */
+@Data
+@ConfigurationProperties(prefix = "erp.db")
+@Component
+public class ErpDbProperties {
+
+ private String driver_class_name;
+
+ private String url;
+
+ private String username;
+
+ private String password;
+
+// {
+// driver_class_name = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
+// ur = "jdbc:sqlserver://127.0.0.1:1433;databasename=byrk";
+// username = "sa";
+// password = "sa@123";
+// }
+
+}
diff --git a/src/main/java/com/zy/ints/erp/ErpSqlServer.java b/src/main/java/com/zy/ints/erp/ErpSqlServer.java
new file mode 100644
index 0000000..78b7ed8
--- /dev/null
+++ b/src/main/java/com/zy/ints/erp/ErpSqlServer.java
@@ -0,0 +1,364 @@
+package com.zy.ints.erp;
+
+import com.baomidou.mybatisplus.annotations.TableField;
+import com.baomidou.mybatisplus.annotations.TableName;
+import com.core.common.Cools;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.sql.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 绠�鍗曟寔涔呭眰妗嗘灦
+ * Created by vincent on 2020/11/26
+ */
+@Slf4j
+@Service
+public class ErpSqlServer {
+
+ // 鏁版嵁搴撹繛鎺�
+// private Connection conn;
+ // 鍒涘缓棰勭紪璇戣鍙ュ璞★紝涓�鑸兘鏄敤杩欎釜鑰屼笉鐢⊿tatement
+ private PreparedStatement pstm = null;
+ // 鍒涘缓涓�涓粨鏋滈泦瀵硅薄
+ private ResultSet rs = null;
+
+ @Autowired
+ private ErpDbProperties erpDbProperties;
+
+ /*****************************************************************************/
+ /********************************** 灏佽 **********************************/
+ /*****************************************************************************/
+
+ /**
+ * 鏌ヨ
+ */
+ public <T> List<T> select(String sql, Class<T> cls) {
+ List<Map<String, Object>> result = executeQuery(sql);
+ List<T> list = new ArrayList<>();
+ if (null != result) {
+ for (Map<String, Object> entity : result) {
+ list.add(Cools.conver(entity, cls));
+ }
+ }
+ return list;
+ }
+
+
+ /**
+ * 鎵弿鎵�鏈夊疄鍔涚被灞炴�ч噷鐨凾ableField娉ㄨВ,骞跺皢閲岄潰鐨勫�间綔涓篶olumn
+ * @param cls
+ * @param <T>
+ * @return
+ */
+ public <T> String selectFrontPart(Class<T> cls){
+ String tableName = cls.getDeclaredAnnotation(TableName.class).value();
+ List<HashMap<String,String>> columnAndField = new ArrayList<>();
+ String sql = "SELECT ";
+ if (Cools.isEmpty(tableName)) {
+ return null;
+ }
+ Field[] allFields = Cools.getAllFields(cls);
+ for (Field f : allFields) {
+ if (Modifier.isFinal(f.getModifiers())
+ || Modifier.isStatic(f.getModifiers())
+ || Modifier.isTransient(f.getModifiers())){
+ continue;
+ }
+ String column = null;
+ if (f.isAnnotationPresent(TableField.class)) {
+ column = f.getAnnotation(TableField.class).value();
+ }
+ if (Cools.isEmpty(column)) {
+ column = f.getName();
+ }
+ String name = f.getName();
+ HashMap<String, String> container = new HashMap<>();
+ container.put(column,name);
+ columnAndField.add(container);
+ }
+ for (int i = 0; i < columnAndField.size(); i++) {
+ HashMap<String, String> stringStringHashMap = columnAndField.get(i);
+ if (i == columnAndField.size() - 1){
+ for (String s : stringStringHashMap.keySet()) {
+ sql = sql + s + " AS " + stringStringHashMap.get(s);
+ }
+ }else {
+ for (String s : stringStringHashMap.keySet()) {
+ sql = sql + s + " AS " + stringStringHashMap.get(s) + ", ";
+ }
+ }
+ }
+ sql = sql + " FROM " + tableName;
+ return sql;
+ }
+
+ public String addWhere(String sql, Map<String,String> condition){
+ int conditionSize = 1;
+ sql = sql + " WHERE ";
+ for (String s : condition.keySet()) {
+ if (conditionSize == condition.keySet().size()){
+ sql = sql + s + " = " + condition.get(s);
+ }else {
+ sql = sql + s + " = " + condition.get(s) + " and ";
+ }
+ conditionSize = conditionSize + 1;
+ }
+ return sql;
+ }
+
+ /**
+ * map鐨勯敭鏄垪鍚�, 鍊肩瓑鍚屼簬鍊�
+ * key: id, value: 1 绛夊悓浜� WHERE id = 1
+ * 濡傛灉瑕佹煡璇㈠瓧绗︿覆闇�瑕佽嚜琛屽姞涓�''
+ * key:name, value: 'zhs'绛夊悓浜� WHERE name = 'zhs'
+ * @param cls
+ * @param condition
+ * @param <T>
+ * @return
+ */
+ public <T> List<T> selectList(Class<T> cls, Map<String,String> condition){
+ String sql = selectFrontPart(cls);
+ String finalSQL = addWhere(sql, condition);
+ return select(finalSQL,cls);
+ }
+
+ public <T> List<T> selectAll(Class<T> cls){
+ String sql = selectFrontPart(cls);
+ return select(sql,cls);
+ }
+
+ public List<Map<String, Object>> select(String sql) {
+ return executeQuery(sql);
+ }
+
+ /**
+ * 淇敼
+ */
+ public int update(String sql) {
+ return executeUpdate(sql);
+ }
+
+ public <T> int delete(Class<T> cls, Map<String,String> condition) {
+ String tableName = cls.getDeclaredAnnotation(TableName.class).value();
+ if (Cools.isEmpty(tableName)) {
+ return 0;
+ }
+ String sql = "DELETE FROM " + tableName;
+ String finalSQL = addWhere(sql, condition);
+ return executeUpdate(finalSQL);
+ }
+
+ public <T> int insert(Class<T> cls, Map<String,Object> condition){
+ String tableName = cls.getDeclaredAnnotation(TableName.class).value();
+ if (Cools.isEmpty(tableName)) {
+ return 0;
+ }
+ String sql = "INSERT INTO " + tableName + " (";
+ int conditionSize = 1;
+ for (String s : condition.keySet()) {
+ if (conditionSize == condition.keySet().size()){
+ sql = sql +s+")";
+ }else {
+ sql = sql + s + ",";
+ }
+ conditionSize = conditionSize + 1;
+ }
+ sql = sql + " VALUES(";
+ int valuesSize = 1;
+ for (String s : condition.keySet()) {
+ if (valuesSize == condition.keySet().size()){
+
+ sql = sql + condition.get(s)+")";
+ }else {
+ sql = sql + condition.get(s) + ",";
+ }
+ valuesSize = valuesSize + 1;
+ }
+
+ return executeUpdate(sql);
+ }
+
+
+
+ /*****************************************************************************/
+ /********************************* 鏍稿績灞� *********************************/
+ /*****************************************************************************/
+
+
+
+ private List<Map<String, Object>> executeQuery(String sql) {
+ Connection conn = null;
+ try {
+ conn = getConn();
+ pstm = conn.prepareStatement(sql);
+ rs = pstm.executeQuery();
+// List<Map<String, Object>> maps = convertList(rs);
+ return convertList(rs);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ } finally {
+ release();
+ if (conn != null) {
+ try {
+ conn.close();
+ conn = null;
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ public Number executeQueryCount(String sql, String column) {
+ Number value = 0;
+ Connection conn = null;
+ try {
+ conn = getConn();
+ pstm = conn.prepareStatement(sql);
+ rs = pstm.executeQuery();
+// ResultSetMetaData metaData = rs.getMetaData();
+ while (rs.next()) {
+ value = (Number) rs.getInt(column);
+ }
+ return value;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return 0;
+ } finally {
+ release();
+ if (conn != null) {
+ try {
+ conn.close();
+ conn = null;
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ private int executeUpdate(String sql) {
+ Connection conn = null;
+ try {
+ conn = getConn();
+ if(null != conn)
+ {
+ pstm = conn.prepareStatement(sql);
+ } else {
+ log.error("鏇存柊ERP涓棿琛ㄥけ璐�===>>鏁版嵁搴撹繛鎺onn涓虹┖");
+ log.error("鏇存柊ERP涓棿琛ㄥけ璐�===>>" + sql);
+ }
+ return pstm.executeUpdate();
+ } catch (Exception e) {
+ e.printStackTrace();
+ log.error("鏇存柊ERP涓棿琛ㄥけ璐�===>>" + sql);
+ log.error("鏇存柊ERP涓棿琛ㄥけ璐�===>>" + e);
+ return 0;
+ } finally {
+ release();
+ if (conn != null) {
+ try {
+ conn.close();
+ conn = null;
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ private static List<Map<String, Object>> convertList(ResultSet rs) throws SQLException {
+ List<Map<String, Object>> list = new ArrayList<>();
+ ResultSetMetaData md = rs.getMetaData();
+ int columnCount = md.getColumnCount();
+ while (rs.next()) {
+ Map<String, Object> rowData = new HashMap<>();
+ for (int i = 1; i <= columnCount; i++) {
+ rowData.put(md.getColumnName(i), rs.getObject(i));
+ }
+ list.add(rowData);
+ }
+ return list;
+ }
+
+ //synchronized
+ public Connection getConn() throws SQLException {
+ Connection conn = null;
+ try {
+ Class.forName(erpDbProperties.getDriver_class_name()).newInstance();
+ conn = DriverManager.getConnection(erpDbProperties.getUrl(), erpDbProperties.getUsername(), erpDbProperties.getPassword());
+ } catch (Exception e) {
+ log.error("鑾峰彇ERP鏁版嵁搴撹繛鎺ュけ璐�");
+ e.printStackTrace();
+ throw new RuntimeException("鑾峰彇ERP鏁版嵁搴撹繛鎺ュけ璐�");
+ }
+ return conn;
+// if (null == this.conn || this.conn.isClosed()) {
+// try {
+// Class.forName(erpDbProperties.getDriver_class_name()).newInstance();
+// this.conn = DriverManager.getConnection(erpDbProperties.getUr(), erpDbProperties.getUsername(), erpDbProperties.getPassword());
+// } catch (Exception e) {
+// log.error("鑾峰彇ERP鏁版嵁搴撹繛鎺ュけ璐�");
+// e.printStackTrace();
+// throw new RuntimeException("鑾峰彇ERP鏁版嵁搴撹繛鎺ュけ璐�");
+// }
+// }
+// return this.conn;
+ }
+
+ private void release() {
+ if (rs != null) {
+ try {
+ rs.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ if (pstm != null) {
+ try {
+ pstm.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+// if (conn != null) {
+// try {
+// conn.close();
+// conn = null;
+// } catch (SQLException e) {
+// e.printStackTrace();
+// }
+// }
+ }
+
+ /**
+ * 娣辨嫹璐�
+ */
+ public ArrayList deepClone(List list) throws Exception {
+ // 搴忓垪鍖�
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(bos);
+
+ oos.writeObject(list);
+
+ // 鍙嶅簭鍒楀寲
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(bis);
+
+ return (ArrayList) ois.readObject();
+ }
+
+}
diff --git a/src/main/java/com/zy/ints/task/scheduler/ErpDetTbScheduler.java b/src/main/java/com/zy/ints/task/scheduler/ErpDetTbScheduler.java
new file mode 100644
index 0000000..2310230
--- /dev/null
+++ b/src/main/java/com/zy/ints/task/scheduler/ErpDetTbScheduler.java
@@ -0,0 +1,19 @@
+package com.zy.ints.task.scheduler;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+/**
+ * erp浠诲姟鎺у埗鍣�
+ * Created by vincent on 2020/11/27
+ */
+@Slf4j
+@Component
+public class ErpDetTbScheduler {
+ /**
+ * ERP鎺ュ彛鏄惁鍚敤
+ */
+ @Value("${erp.enabled}")
+ private Boolean erpEnabled;
+}
diff --git a/src/main/java/com/zy/ints/task/scheduler/ErpPrdtScheduler.java b/src/main/java/com/zy/ints/task/scheduler/ErpPrdtScheduler.java
new file mode 100644
index 0000000..3ac1b0c
--- /dev/null
+++ b/src/main/java/com/zy/ints/task/scheduler/ErpPrdtScheduler.java
@@ -0,0 +1,122 @@
+package com.zy.ints.task.scheduler;
+
+import com.core.common.Cools;
+import com.zy.asrs.entity.Mat;
+import com.zy.asrs.entity.Tag;
+import com.zy.asrs.service.MatService;
+import com.zy.asrs.service.TagService;
+import com.zy.ints.entity.Prdt;
+import com.zy.ints.erp.ErpSqlServer;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * erp浠诲姟鎺у埗鍣�
+ * Created by vincent on 2020/11/27
+ */
+@Slf4j
+@Component
+public class ErpPrdtScheduler {
+
+ /**
+ * ERP鎺ュ彛鏄惁鍚敤
+ */
+ @Value("${erp.enabled}")
+ private Boolean erpEnabled;
+ @Autowired
+ private TagService tagService;
+ @Autowired
+ private ErpSqlServer erpSqlServer;
+ @Autowired
+ private MatService matService;
+ /**
+ * 鑾峰彇鍟嗗搧淇℃伅琛ㄨ祫鏂�
+ */
+ @Scheduled(cron = "${erp.refreshtime}")
+ public void obtainPedt() {
+ if (!erpEnabled) return;
+ String sqlSelectPrdt = "select prd_no as prdNo,name,ut,spc,type,status from erp_prdt where 1=1";
+ String sqlUpDatePrdtOne = "update erp_prdt set status=1 where prd_no=";
+ String sqlUpDatePrdtTwo = "update erp_prdt set status=2 where prd_no=";
+ Tag tag = tagService.selectByName("鍏ㄩ儴", 1);
+
+ List<Prdt> prdts = erpSqlServer.select(sqlSelectPrdt,Prdt.class);
+ if (prdts.size() > 0){
+ for (Prdt prdt : prdts) {
+ Date date = new Date();
+ if (prdt.getStatus()==0) {
+ Integer type = prdt.getType();
+ if (type==1){
+ Mat mat = matService.selectByMatnr(prdt.getPrdNo());
+ if (Cools.isEmpty(mat)){
+ Mat matNew = new Mat();
+ matNew.setTagId(tag.getId());
+ matNew.setMatnr(prdt.getPrdNo());
+ matNew.setMaktx(prdt.getName());
+ matNew.setUnit(prdt.getUt());
+ matNew.setSpecs(prdt.getSpc());
+ matNew.setCreateBy(9999L);
+ matNew.setCreateTime(date);
+ matNew.setUpdateBy(9999L);
+ matNew.setUpdateTime(date);
+ if (matService.insert(matNew)){
+ erpSqlServer.update(sqlUpDatePrdtOne+"'" + prdt.getPrdNo() + "'");
+ }else {
+ erpSqlServer.update(sqlUpDatePrdtTwo+"'" + prdt.getPrdNo() + "'");
+ }
+ }
+ }else if (type==2){
+ Mat mat = matService.selectByMatnr(prdt.getPrdNo());
+ if (!Cools.isEmpty(mat)){
+ mat.setMaktx(prdt.getName());
+ mat.setUnit(prdt.getUt());
+ mat.setSpecs(prdt.getSpc());
+ if (matService.updateById(mat)){
+ erpSqlServer.update(sqlUpDatePrdtOne+"'" + prdt.getPrdNo() + "'");
+ }else {
+ erpSqlServer.update(sqlUpDatePrdtTwo+"'" + prdt.getPrdNo() + "'");
+ }
+ }
+ }else if (type==3){
+ Mat mat = matService.selectByMatnr(prdt.getPrdNo());
+ if (!Cools.isEmpty(mat)){
+ if (matService.deleteById(mat.getId())){
+ erpSqlServer.update(sqlUpDatePrdtOne+"'" + prdt.getPrdNo() + "'");
+ }else {
+ erpSqlServer.update(sqlUpDatePrdtTwo+"'" + prdt.getPrdNo() + "'");
+ }
+ }
+ }else {
+
+ }
+ }else if (prdt.getStatus()==1){
+// HashMap<String, Object> condition = new HashMap<>();
+// condition.put("prd_no","'" + prdt.getPrdNo() + "'");
+// condition.put("name","'" + prdt.getName() + "'");
+// condition.put("ut","'" + prdt.getUt() + "'");
+// condition.put("spc","'" + prdt.getSpc() + "'");
+// condition.put("type","'" + prdt.getType() + "'");
+// condition.put("status","'" + prdt.getStatus() + "'");
+// erpSqlServer.insert(Prdt.class, condition);
+//
+// HashMap<String, String> condition2 = new HashMap<>();
+// condition2.put("prd_no","'" + prdt.getPrdNo() + "'");
+// erpSqlServer.delete(Prdt.class,condition2);
+ }else if (prdt.getStatus()==2){
+
+ }else {
+
+ }
+
+ }
+ }
+
+ }
+}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index af4d271..61d3643 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -48,4 +48,19 @@
# 鍙屾繁搴撲綅鎺掑彿
doubleLocs: 9,12,15,18
# 涓�涓爢鍨涙満璐熻矗鐨勮揣鏋舵帓鏁�
- groupCount: 4
\ No newline at end of file
+ groupCount: 4
+#ERP鎺ュ彛
+erp:
+ enabled: true
+ # enabled: false
+ #鏌ョ湅ERP涓棿琛ㄩ棿闅�
+ refreshtime: 0/5 * * * * ?
+ db:
+ driver_class_name: com.microsoft.sqlserver.jdbc.SQLServerDriver
+ url: jdbc:sqlserver://127.0.0.1:1433;databasename=lfdasrs
+ username: sa
+ password: sa@123
+
+
+comb:
+ limit: 5000
\ No newline at end of file
--
Gitblit v1.9.1