From b1d639d80b8a1a2ead391e7fda681900d6ff3ca7 Mon Sep 17 00:00:00 2001 From: 18516761980 <tqsxp@163.com> Date: 星期六, 07 一月 2023 10:03:47 +0800 Subject: [PATCH] # --- src/main/java/com/zy/ints/task/scheduler/ErpPrdtSchedulerNew.java | 177 +++++++++++++++++++++++++++++++++++ src/main/java/com/zy/ints/entity/Prdt.java | 9 + src/main/resources/application.yml | 3 src/main/java/com/zy/ints/task/scheduler/ErpPrdtScheduler.java | 71 +++++++++---- 4 files changed, 234 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/zy/ints/entity/Prdt.java b/src/main/java/com/zy/ints/entity/Prdt.java index b9cca72..6c3d851 100644 --- a/src/main/java/com/zy/ints/entity/Prdt.java +++ b/src/main/java/com/zy/ints/entity/Prdt.java @@ -11,7 +11,7 @@ import java.io.Serializable; @Data -@TableName("erp_prdt") +@TableName("PRDT") public class Prdt implements Serializable { private static final long serialVersionUID = 1L; @@ -21,37 +21,42 @@ */ @ApiModelProperty(value = "鍝佸彿") @TableId(value = "prd_no", type = IdType.INPUT) - @TableField("prd_no") + @TableField("PRD_NO") private String prdNo; /** * 鍝佸悕 */ @ApiModelProperty(value = "鍝佸悕") + @TableField("NAME") private String name; /** * 鍗曚綅 */ @ApiModelProperty(value = "鍗曚綅") + @TableField("UT") private String ut; /** * 瑙勬牸 */ @ApiModelProperty(value = "瑙勬牸") + @TableField("SPC") private String spc; /** * 绫诲瀷 */ @ApiModelProperty(value = "绫诲瀷") + @TableField("TYPE") private Integer type; /** * 鐘舵�� */ @ApiModelProperty(value = "鐘舵��") + @TableField("STATUS") private Integer status; public Prdt() { diff --git a/src/main/java/com/zy/ints/task/scheduler/ErpPrdtScheduler.java b/src/main/java/com/zy/ints/task/scheduler/ErpPrdtScheduler.java index 0231f2b..94b508d 100644 --- a/src/main/java/com/zy/ints/task/scheduler/ErpPrdtScheduler.java +++ b/src/main/java/com/zy/ints/task/scheduler/ErpPrdtScheduler.java @@ -44,14 +44,14 @@ 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="; + String sqlSelectPrdt = "select PRD_NO as prdNo,NAME as name,UT as ut,SPC as spc from PRDT where 1=1"; + String sqlUpDatePrdtOne = "update PRDT set STATUS=1 where PRD_NO="; + String sqlUpDatePrdtTwo = "update PRDT set STATUS=2 where PRD_NO="; try { Tag tag = tagService.selectByName("鍏ㄩ儴", 1); @@ -59,6 +59,31 @@ if (prdts.size() > 0) { for (Prdt prdt : prdts) { Date date = new Date(); + Integer type = prdt.getType(); + 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);//9999琛ㄧずerp涓嬪彂 + matNew.setCreateTime(date); + matNew.setUpdateBy(9999L);//9999琛ㄧずerp涓嬪彂 + matNew.setUpdateTime(date); + if (matService.insert(matNew)) { +// erpSqlServer.update(sqlUpDatePrdtOne + "'" + prdt.getPrdNo() + "'"); + callApiLogSave(prdt, "PRDT", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅鎴愬姛锛佹坊鍔犲晢鍝佷俊鎭垚鍔燂紒", true); + } else { +// erpSqlServer.update(sqlUpDatePrdtTwo + "'" + prdt.getPrdNo() + "'"); + callApiLogSave(prdt, "PRDT", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅澶辫触锛侊紒锛佹坊鍔犲晢鍝佷俊鎭け璐ワ紒锛侊紒", false); + } + } else { +// erpSqlServer.update(sqlUpDatePrdtTwo + "'" + prdt.getPrdNo() + "'"); + callApiLogSave(prdt, "PRDT", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅澶辫触锛侊紒锛佸晢鍝佸凡瀛樺湪锛侊紒锛�", false); + } + /*Date date = new Date(); if (prdt.getStatus() == 0) { Integer type = prdt.getType(); if (type == 1) { @@ -76,14 +101,14 @@ matNew.setUpdateTime(date); if (matService.insert(matNew)) { erpSqlServer.update(sqlUpDatePrdtOne + "'" + prdt.getPrdNo() + "'"); - callApiLogSave(prdt, "erp_prdt", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅鎴愬姛锛佹坊鍔犲晢鍝佷俊鎭垚鍔燂紒", true); + callApiLogSave(prdt, "PRDT", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅鎴愬姛锛佹坊鍔犲晢鍝佷俊鎭垚鍔燂紒", true); } else { erpSqlServer.update(sqlUpDatePrdtTwo + "'" + prdt.getPrdNo() + "'"); - callApiLogSave(prdt, "erp_prdt", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅澶辫触锛侊紒锛佹坊鍔犲晢鍝佷俊鎭け璐ワ紒锛侊紒", false); + callApiLogSave(prdt, "PRDT", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅澶辫触锛侊紒锛佹坊鍔犲晢鍝佷俊鎭け璐ワ紒锛侊紒", false); } } else { erpSqlServer.update(sqlUpDatePrdtTwo + "'" + prdt.getPrdNo() + "'"); - callApiLogSave(prdt, "erp_prdt", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅澶辫触锛侊紒锛佸晢鍝佸凡瀛樺湪锛侊紒锛�", false); + callApiLogSave(prdt, "PRDT", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅澶辫触锛侊紒锛佸晢鍝佸凡瀛樺湪锛侊紒锛�", false); } } else if (type == 2) { Mat mat = matService.selectByMatnr(prdt.getPrdNo()); @@ -93,10 +118,10 @@ mat.setSpecs(prdt.getSpc()); if (matService.updateById(mat)) { erpSqlServer.update(sqlUpDatePrdtOne + "'" + prdt.getPrdNo() + "'"); - callApiLogSave(prdt, "erp_prdt", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅鎴愬姛锛佷慨鏀瑰晢鍝佷俊鎭垚鍔燂紒", true); + callApiLogSave(prdt, "PRDT", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅鎴愬姛锛佷慨鏀瑰晢鍝佷俊鎭垚鍔燂紒", true); } else { erpSqlServer.update(sqlUpDatePrdtTwo + "'" + prdt.getPrdNo() + "'"); - callApiLogSave(prdt, "erp_prdt", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅澶辫触锛侊紒锛佷慨鏀瑰晢鍝佷俊鎭け璐ワ紒锛侊紒", false); + callApiLogSave(prdt, "PRDT", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅澶辫触锛侊紒锛佷慨鏀瑰晢鍝佷俊鎭け璐ワ紒锛侊紒", false); } } } else if (type == 3) { @@ -104,38 +129,38 @@ if (!Cools.isEmpty(mat)) { if (matService.deleteById(mat.getId())) { erpSqlServer.update(sqlUpDatePrdtOne + "'" + prdt.getPrdNo() + "'"); - callApiLogSave(prdt, "erp_prdt", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅鎴愬姛锛佸垹闄ゅ晢鍝佷俊鎭垚鍔燂紒", true); + callApiLogSave(prdt, "PRDT", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅鎴愬姛锛佸垹闄ゅ晢鍝佷俊鎭垚鍔燂紒", true); } else { erpSqlServer.update(sqlUpDatePrdtTwo + "'" + prdt.getPrdNo() + "'"); - callApiLogSave(prdt, "erp_prdt", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅鎴愬姛锛佸垹闄ゅ晢鍝佷俊鎭け璐ワ紒", false); + callApiLogSave(prdt, "PRDT", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅鎴愬姛锛佸垹闄ゅ晢鍝佷俊鎭け璐ワ紒", false); } } } else { - callApiLogSave(prdt, "erp_prdt", "鍟嗗搧淇℃伅鍑虹幇寮傚父璧勬枡鏈鐞嗭紒", false); + callApiLogSave(prdt, "PRDT", "鍟嗗搧淇℃伅鍑虹幇寮傚父璧勬枡鏈鐞嗭紒", false); } - } else if (prdt.getStatus() == 1) { + }*/ /*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() + "'"); + 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(PrdtBak.class, condition); // callApiLogSave(prdt, "erp_prdt_bak", "ERP涓嬪彂鍟嗗搧淇℃伅澶囦唤鎴愬姛锛�", true); HashMap<String, String> condition2 = new HashMap<>(); condition2.put("prd_no", "'" + prdt.getPrdNo() + "'"); erpSqlServer.delete(Prdt.class, condition2); -// callApiLogSave(prdt, "erp_prdt_bak", "ERP涓嬪彂鍟嗗搧淇℃伅澶囦唤鍚庡垹闄ゆ垚鍔燂紒", true); +// callApiLogSave(prdt, "erp_prdt", "ERP涓嬪彂鍟嗗搧淇℃伅澶囦唤鍚庡垹闄ゆ垚鍔燂紒", true); } else { - callApiLogSave(prdt, "erp_prdt", "鍟嗗搧淇℃伅鍑虹幇寮傚父璧勬枡鏈鐞嗭紒", false); - } + callApiLogSave(prdt, "PRDT", "鍟嗗搧淇℃伅鍑虹幇寮傚父璧勬枡鏈鐞嗭紒", false); + }*/ } } } catch (Exception e) { Date date = new Date(); - log.error(date + ": 琛ㄥ悕锛歟rp_prdt :" + e); + log.error(date + ": 琛ㄥ悕锛歅RDT :" + e); } } diff --git a/src/main/java/com/zy/ints/task/scheduler/ErpPrdtSchedulerNew.java b/src/main/java/com/zy/ints/task/scheduler/ErpPrdtSchedulerNew.java new file mode 100644 index 0000000..1cab6f2 --- /dev/null +++ b/src/main/java/com/zy/ints/task/scheduler/ErpPrdtSchedulerNew.java @@ -0,0 +1,177 @@ +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.ApiLogService; +import com.zy.asrs.service.MatService; +import com.zy.asrs.service.TagService; +import com.zy.ints.entity.Prdt; +import com.zy.ints.entity.PrdtBak; +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 ErpPrdtSchedulerNew { + + /** + * ERP鎺ュ彛鏄惁鍚敤 + */ + @Value("${erp.enabled}") + private Boolean erpEnabled; + @Value("${erp.enabledNew}") + private Boolean erpEnabledNew; + @Value("${erp.useName.ip}") + private String ip; + @Autowired + private ApiLogService apiLogService; + @Autowired + private TagService tagService; + @Autowired + private ErpSqlServer erpSqlServer; + @Autowired + private MatService matService; + + /** + * 鑾峰彇鍟嗗搧淇℃伅琛ㄨ祫鏂� + */ + @Scheduled(cron = "${erp.refreshtime}") + public void obtainPedt() { + if (!erpEnabledNew) return; + String sqlSelectPrdt = "select PRD_NO as prdNo,NAME as name,UT as ut,SPC as spc from PRDT where 1=1"; + String sqlUpDatePrdtOne = "update PRDT set STATUS=1 where PRD_NO="; + String sqlUpDatePrdtTwo = "update PRDT set STATUS=2 where PRD_NO="; + try { + Tag tag = tagService.selectByName("鍏ㄩ儴", 1); + + List<Prdt> prdts = erpSqlServer.select(sqlSelectPrdt, Prdt.class); + Date date = new Date(); + if (prdts.size() > 0) { + for (Prdt prdt : prdts) { + 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);//9999琛ㄧずerp涓嬪彂 + matNew.setCreateTime(date); + matNew.setUpdateBy(9999L);//9999琛ㄧずerp涓嬪彂 + matNew.setUpdateTime(date); + if (matService.insert(matNew)) { +// erpSqlServer.update(sqlUpDatePrdtOne + "'" + prdt.getPrdNo() + "'"); + callApiLogSave(prdt, "PRDT", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅鎴愬姛锛佹坊鍔犲晢鍝佷俊鎭垚鍔燂紒", true); + } else { +// erpSqlServer.update(sqlUpDatePrdtTwo + "'" + prdt.getPrdNo() + "'"); + callApiLogSave(prdt, "PRDT", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅澶辫触锛侊紒锛佹坊鍔犲晢鍝佷俊鎭け璐ワ紒锛侊紒", false); + } + } else { +// erpSqlServer.update(sqlUpDatePrdtTwo + "'" + prdt.getPrdNo() + "'"); + callApiLogSave(prdt, "PRDT", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅澶辫触锛侊紒锛佸晢鍝佸凡瀛樺湪锛侊紒锛�", false); + } + } + } + /*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);//9999琛ㄧずerp涓嬪彂 + matNew.setCreateTime(date); + matNew.setUpdateBy(9999L);//9999琛ㄧずerp涓嬪彂 + matNew.setUpdateTime(date); + if (matService.insert(matNew)) { + erpSqlServer.update(sqlUpDatePrdtOne + "'" + prdt.getPrdNo() + "'"); + callApiLogSave(prdt, "PRDT", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅鎴愬姛锛佹坊鍔犲晢鍝佷俊鎭垚鍔燂紒", true); + } else { + erpSqlServer.update(sqlUpDatePrdtTwo + "'" + prdt.getPrdNo() + "'"); + callApiLogSave(prdt, "PRDT", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅澶辫触锛侊紒锛佹坊鍔犲晢鍝佷俊鎭け璐ワ紒锛侊紒", false); + } + } else { + erpSqlServer.update(sqlUpDatePrdtTwo + "'" + prdt.getPrdNo() + "'"); + callApiLogSave(prdt, "PRDT", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅澶辫触锛侊紒锛佸晢鍝佸凡瀛樺湪锛侊紒锛�", false); + } + } 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() + "'"); + callApiLogSave(prdt, "PRDT", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅鎴愬姛锛佷慨鏀瑰晢鍝佷俊鎭垚鍔燂紒", true); + } else { + erpSqlServer.update(sqlUpDatePrdtTwo + "'" + prdt.getPrdNo() + "'"); + callApiLogSave(prdt, "PRDT", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅澶辫触锛侊紒锛佷慨鏀瑰晢鍝佷俊鎭け璐ワ紒锛侊紒", false); + } + } + } else if (type == 3) { + Mat mat = matService.selectByMatnr(prdt.getPrdNo()); + if (!Cools.isEmpty(mat)) { + if (matService.deleteById(mat.getId())) { + erpSqlServer.update(sqlUpDatePrdtOne + "'" + prdt.getPrdNo() + "'"); + callApiLogSave(prdt, "PRDT", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅鎴愬姛锛佸垹闄ゅ晢鍝佷俊鎭垚鍔燂紒", true); + } else { + erpSqlServer.update(sqlUpDatePrdtTwo + "'" + prdt.getPrdNo() + "'"); + callApiLogSave(prdt, "PRDT", "鎺ユ敹ERP涓嬪彂鍟嗗搧淇℃伅鎴愬姛锛佸垹闄ゅ晢鍝佷俊鎭け璐ワ紒", false); + } + } + } else { + callApiLogSave(prdt, "PRDT", "鍟嗗搧淇℃伅鍑虹幇寮傚父璧勬枡鏈鐞嗭紒", false); + } + } 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(PrdtBak.class, condition); +// callApiLogSave(prdt, "erp_prdt_bak", "ERP涓嬪彂鍟嗗搧淇℃伅澶囦唤鎴愬姛锛�", true); + + HashMap<String, String> condition2 = new HashMap<>(); + condition2.put("prd_no", "'" + prdt.getPrdNo() + "'"); + erpSqlServer.delete(Prdt.class, condition2); +// callApiLogSave(prdt, "erp_prdt", "ERP涓嬪彂鍟嗗搧淇℃伅澶囦唤鍚庡垹闄ゆ垚鍔燂紒", true); + } else { + callApiLogSave(prdt, "PRDT", "鍟嗗搧淇℃伅鍑虹幇寮傚父璧勬枡鏈鐞嗭紒", false); + } + }*/ +// } + } catch (Exception e) { + Date date = new Date(); + log.error(date + ": 琛ㄥ悕锛歅RDT :" + e); + } + } + + public void callApiLogSave(Prdt prdt, String tableName, String response, Boolean bool) { + apiLogService.save("ERP涓嬪彂鍟嗗搧淇℃伅", tableName, "null", ip, + "鍝佸彿锛�" + prdt.getPrdNo() + "銆佸搧鍚嶏細" + prdt.getName() + "銆佺被鍨嬶細" + prdt.getType() + "銆佺姸鎬侊細" + prdt.getStatus$(), + response, bool); + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index a934298..7e1195f 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -51,7 +51,8 @@ groupCount: 4 #ERP鎺ュ彛 erp: - enabled: true + enabled: false + enabledNew: true # enabled: false #鏌ョ湅ERP涓棿琛ㄩ棿闅� refreshtime: 0/5 * * * * ? -- Gitblit v1.9.1