From b4a8d50e3d97fc9e893b554a60134e4eceb012eb Mon Sep 17 00:00:00 2001
From: zhou zhou <3272660260@qq.com>
Date: 星期一, 05 一月 2026 08:58:08 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/common/service/erp/ErpService.java | 214 ++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 145 insertions(+), 69 deletions(-)
diff --git a/src/main/java/com/zy/common/service/erp/ErpService.java b/src/main/java/com/zy/common/service/erp/ErpService.java
index 0408c57..4a27748 100644
--- a/src/main/java/com/zy/common/service/erp/ErpService.java
+++ b/src/main/java/com/zy/common/service/erp/ErpService.java
@@ -1,8 +1,10 @@
package com.zy.common.service.erp;
+import com.baomidou.mybatisplus.MybatisSqlSessionTemplate;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.core.common.DateUtils;
+import com.core.exception.CoolException;
import com.zy.asrs.service.OutStockMainService;
import com.zy.asrs.service.OutStockService;
import com.zy.common.service.erp.dto.InStockDto;
@@ -10,6 +12,7 @@
import com.zy.common.service.erp.entity.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
@@ -27,6 +30,8 @@
@Autowired
private ErpSqlServer erpSqlServer;
+ @Autowired
+ private JdbcTemplate jdbcTemplate;
public List<StockEntryCensus> get(){
return erpSqlServer.select("select * from StockEntryCensus where 1=1",StockEntryCensus.class);
@@ -64,20 +69,35 @@
}
/**
+ * 鏌ヨ鍚屼竴鍗曞彿鏄惁瀛樺湪鐩稿悓鐗╂枡鐨勬渶澶ф暟閲忓�硷紝
+ * @return
+ */
+ public Number QueryFnumberInCount(Integer FInterID) {
+ String sql = "select top 1 qty from (\n" +
+ "select Fnumber,count(*) as qty from InStockbill a,InStockbillEntry b\n" +
+ "where a.FInterID=b.FInterID and a.FInterID=" + FInterID +
+ " group by Fnumber\n" +
+ ") a\n" +
+ "order by qty desc";
+ return erpSqlServer.executeQueryCount(sql,"qty");
+ }
+
+ /**
* 鑾峰彇鍏ュ簱鐗╂祦鏄庣粏
* @param fInterID 鍗曟嵁鍐呯爜
*/
private List<InStockBillEntry> getInStockBillEntry(Integer fInterID) {
- String sql = "select * from InStockBillEntry where 1=1 and FSourceBillNo!='' and FAuxCommitQty=0 and FInterID = " + fInterID;
+// String sql = "select * from InStockBillEntry where 1=1 and FSourceBillNo!='' and FAuxCommitQty=0 and FInterID = " + fInterID;
+ String sql = "select * from InStockBillEntry where 1=1 and FAuxCommitQty=0 and FInterID = " + fInterID;
return erpSqlServer.select(sql, InStockBillEntry.class);
}
/**
* 灏嗘湭璇荤殑鍘熸潗鏂欏叆搴撳崟鎹缃负宸茶
*/
- public boolean haveReadInStock(String FBillNo){
- String sql = "update InStockBill set Fflag_rw = 1 where FBillNo = ''{0}''";
- sql = MessageFormat.format(sql, FBillNo);
+ public boolean haveReadInStock(String FBillNo, Integer value){
+ String sql = "update InStockBill set Fflag_rw = {1,number,#} where FBillNo = ''{0}''";
+ sql = MessageFormat.format(sql, FBillNo, value);
return erpSqlServer.update(sql) > 0;
}
@@ -85,16 +105,31 @@
* 鎻愬彇涓棿琛ㄦ垚鍝佸叆搴撳崟鎹�
*/
public List<CPICMO> getReadyCPICMO() {
- String sql = "select * from CPICMO where 1=1 and FSourceBillNo!='' and FAuxCommitQty=0 and Fflag_rw = 0";
+// String sql = "select * from CPICMO where 1=1 and FSourceBillNo!='' and FAuxCommitQty=0 and Fflag_rw = 0";
+ String sql = "select * from CPICMO where 1=1 and FAuxCommitQty=0 and Fflag_rw = 0";
return erpSqlServer.select(sql, CPICMO.class);
+ }
+
+ /**
+ * 鏌ヨ鍚屼竴鍗曞彿鏄惁瀛樺湪鐩稿悓鐗╂枡鐨勬渶澶ф暟閲忓�硷紝
+ * @return
+ */
+ public Number QueryFnumberCPICMOCount(Integer FInterID) {
+ String sql = "select top 1 qty from (\n" +
+ "select count(*) as qty from CPICMO\n" +
+ "where FInterID=" + FInterID +
+ " group by Fnumber\n" +
+ ") a\n" +
+ "order by qty desc";
+ return erpSqlServer.executeQueryCount(sql,"qty");
}
/**
* 灏嗘湭璇荤殑鎴愬搧鍏ュ簱鍗曟嵁璁剧疆涓哄凡璇�
*/
- public boolean haveReadCPICMO(String FBillNo){
- String sql = "update CPICMO set Fflag_rw = 1 where FBillNo = ''{0}''";
- sql = MessageFormat.format(sql, FBillNo);
+ public boolean haveReadCPICMO(Integer FInterID, Integer value){
+ String sql = "update CPICMO set Fflag_rw = {1,number,#} where FInterID = ''{0,number,#}''";
+ sql = MessageFormat.format(sql, FInterID, value);
return erpSqlServer.update(sql) > 0;
}
////////////////////////////////////////////////////////////////////////////////////////
@@ -110,20 +145,37 @@
}
/**
+ * 鏌ヨ鍚屼竴鍗曞彿鏄惁瀛樺湪鐩稿悓鐗╂枡鐨勬渶澶ф暟閲忓�硷紝
+ * @return
+ */
+ public Number QueryFnumberOutCount(Integer FInterID) {
+ String sql = "select top 1 qty from (\n" +
+ "select Fnumber,count(*) as qty from OutStockbill a,OutStockbillEntry b\n" +
+ "where a.FInterID=b.FInterID and a.FInterID=" + FInterID +
+ " group by Fnumber\n" +
+ ") a\n" +
+ "order by qty desc";
+ return erpSqlServer.executeQueryCount(sql,"qty");
+ }
+
+
+ /**
* 鏌ヨerp涓棿琛ㄨ〃浣揙utStockbillEntry鏁版嵁
* @param FInterID
* @return
*/
public List<OutStockBillEntry> syncOutStockDetail(Integer FInterID) {
- return erpSqlServer.select("SELECT * FROM xtyasrs_dual.dbo.OutStockBillEntry where FSourceBillNo!='' and FAuxCommitQty=0 and FInterID=" + FInterID, OutStockBillEntry.class);
+// String sql = "SELECT * FROM xtyasrs_dual.dbo.OutStockBillEntry where FSourceBillNo!='' and FAuxCommitQty=0 and FInterID=" + FInterID;
+ String sql = "SELECT * FROM xtyasrs_dual.dbo.OutStockBillEntry where FAuxCommitQty=0 and FInterID=" + FInterID;
+ return erpSqlServer.select(sql, OutStockBillEntry.class);
}
/**
* 灏嗘彁鍙栧畬鎴愮殑鎴愬搧鍑哄簱閫氱煡鍗曟嵁璁剧疆涓哄凡璇�
*/
- public boolean haveReadOutBill(String FBrNo, Integer FInterID){
- String sql = "update OutStockbill set Fflag_rw = 1 where FBillNo = ''{0}'' and FInterID = {1,number,#} ";
- sql = MessageFormat.format(sql, FBrNo, FInterID);
+ public boolean haveReadOutBill(String FBrNo, Integer FInterID, Integer value){
+ String sql = "update OutStockbill set Fflag_rw = {2,number,#} where FBillNo = ''{0}'' and FInterID = {1,number,#} ";
+ sql = MessageFormat.format(sql, FBrNo, FInterID, value);
return erpSqlServer.update(sql) > 0;
}
////////////////////////////////////////////////////////////////////////////////////////////
@@ -146,9 +198,9 @@
/**
* 鍘熸潗鏂欏閲忓叆搴�
*/
- public boolean incrementPakIn(String FBillNo, String Fnumbers, Double increment) {
- String[] arrays = Fnumbers.split("|");
- String Fnumber="",sBillNo=""; //浜у搧浠g爜,鐢熶骇鍗曞彿
+ public boolean incrementPakIn(String FBillNo, String Fnumber, Double increment) {
+// String[] arrays = Fnumbers.split("|");
+// String Fnumber="",sBillNo=""; //浜у搧浠g爜,鐢熶骇鍗曞彿
String sql = "update ise \n" +
"set ise.FAuxCommitQty = (ise.FAuxCommitQty + {0,number,#}) \n" +
@@ -157,15 +209,16 @@
"where 1=1 \n" +
"and ise.Fnumber = ''{1}''\n" +
"and isb.FBillNo= ''{2}''\n";
+ sql = MessageFormat.format(sql, increment, Fnumber, FBillNo);
- Fnumber = arrays[0];
- if(arrays.length>1){
- sBillNo = arrays[1];
- sql = sql + "and ise.FSourceBillNo= ''{3}''";
- sql = MessageFormat.format(sql, increment, Fnumber, FBillNo, sBillNo);
- } else {
- sql = MessageFormat.format(sql, increment, Fnumber, FBillNo);
- }
+// Fnumber = arrays[0];
+// if(arrays.length>1){
+// sBillNo = arrays[1];
+// sql = sql + "and ise.FSourceBillNo= ''{3}''";
+// sql = MessageFormat.format(sql, increment, Fnumber, FBillNo, sBillNo);
+// } else {
+// sql = MessageFormat.format(sql, increment, Fnumber, FBillNo);
+// }
if (erpSqlServer.update(sql) > 0) {
// log.error("鏇存柊ERP涓棿琛ㄦ垚鍔�===>>[FBillNo:{},Fnumber:{},increment:{}]",FBillNo,Fnumber,increment);
@@ -193,7 +246,7 @@
}
return true;
} else {
- log.error("鏇存柊ERP涓棿琛ㄥけ璐�===>>[FBillNo:{},Fnumber:{},increment:{}]",FBillNo,Fnumbers,increment);
+ log.error("鏇存柊ERP涓棿琛ㄥけ璐�===>>[FBillNo:{},Fnumber:{},increment:{}]",FBillNo,Fnumber,increment);
return false;
}
}
@@ -201,29 +254,30 @@
/**
* 鎴愬搧澧為噺鍏ュ簱
*/
- public boolean incrementCPakIn(String FBillNo, String Fnumbers, Double increment) {
- String[] arrays = Fnumbers.split("|");
- String Fnumber="",sBillNo=""; //浜у搧浠g爜,鐢熶骇鍗曞彿
+ public boolean incrementCPakIn(String FBillNo, String Fnumber, Double increment) {
+// String[] arrays = Fnumbers.split("|");
+// String Fnumber="",sBillNo=""; //浜у搧浠g爜,鐢熶骇鍗曞彿
String sql = "update CPICMO set FAuxCommitQty = (FAuxCommitQty + {0,number,#}) where 1=1 and Fnumber = ''{1}'' and FBillNo = ''{2}'' ";
+ sql = MessageFormat.format(sql, increment, Fnumber, FBillNo);
- Fnumber = arrays[0];
- if(arrays.length>1){
- sBillNo = arrays[1];
- sql = sql + " and FSourceBillNo= ''{3}''";
- sql = MessageFormat.format(sql, increment, Fnumber, FBillNo, sBillNo);
- } else {
- sql = MessageFormat.format(sql, increment, Fnumber, FBillNo);
- }
+// Fnumber = arrays[0];
+// if(arrays.length>1){
+// sBillNo = arrays[1];
+// sql = sql + " and FSourceBillNo= ''{3}''";
+// sql = MessageFormat.format(sql, increment, Fnumber, FBillNo, sBillNo);
+// } else {
+// sql = MessageFormat.format(sql, increment, Fnumber, FBillNo);
+// }
if (erpSqlServer.update(sql) > 0) {
- if(arrays.length>1) {
- sql = "select * from CPICMO where 1=1 and Fnumber = ''{0}'' and FBillNo = ''{1}'' and FSourceBillNo= ''{2}''";
- sql = MessageFormat.format(sql, Fnumber, FBillNo, sBillNo);
- } else {
+// if(arrays.length>1) {
+// sql = "select * from CPICMO where 1=1 and Fnumber = ''{0}'' and FBillNo = ''{1}'' and FSourceBillNo= ''{2}''";
+// sql = MessageFormat.format(sql, Fnumber, FBillNo, sBillNo);
+// } else {
sql = "select * from CPICMO where 1=1 and Fnumber = ''{0}'' and FBillNo = ''{1}''";
sql = MessageFormat.format(sql, Fnumber, FBillNo);
- }
+// }
List<CPICMO> select = erpSqlServer.select(sql, CPICMO.class);
CPICMO cpicmo = select.get(0);
boolean complete = false;
@@ -237,7 +291,7 @@
}
}
if (complete) {
- if (!completeCPakIn(FBillNo, Fnumber, sBillNo)) {
+ if (!completeCPakIn(FBillNo, Fnumber)) {
log.error("{}鍏ュ簱鍗曟爣璁板畬鎴愬け璐�", FBillNo);
}
}
@@ -306,8 +360,8 @@
* @param qty 鏁伴噺锛堟琛ㄧず鐩樼泩銆佽礋琛ㄧず鐩樹簭锛�
*/
public boolean checkStockEntity(String FNumber, Double qty){
- String[] arrays = FNumber.split("|");
- FNumber = arrays[0];
+// String[] arrays = FNumber.split("|");
+// FNumber = arrays[0];
String sql = "insert [dbo].[StockCheckRecord] ([FNumber],[CheckQty],[Fflag_rw],[Fflag_finish],[sync_id]) values (''{0}'', {1,number,#}, 0, 0, -1);";
sql = MessageFormat.format(sql, FNumber, qty);
if (erpSqlServer.update(sql) == 0) {
@@ -336,16 +390,16 @@
/**
* 鎴愬搧鍏ュ簱鍗曟爣璁板畬鎴�
*/
- private boolean completeCPakIn(String FBillNo, String Fnumber, String sBillNo){
- if(Cools.isEmpty(sBillNo)) {
+ private boolean completeCPakIn(String FBillNo, String Fnumber){
+// if(Cools.isEmpty(sBillNo)) {
String sql = "update CPICMO set Fflag_finish = 1 where FBillNo = ''{0}'' and Fnumber = ''{1}''";
sql = MessageFormat.format(sql, FBillNo, Fnumber);
return erpSqlServer.update(sql) > 0;
- } else {
- String sql = "update CPICMO set Fflag_finish = 1 where FBillNo = ''{0}'' and Fnumber = ''{1}'' and FSourceBillNo= ''{2}'' ";
- sql = MessageFormat.format(sql, FBillNo, Fnumber, sBillNo);
- return erpSqlServer.update(sql) > 0;
- }
+// } else {
+// String sql = "update CPICMO set Fflag_finish = 1 where FBillNo = ''{0}'' and Fnumber = ''{1}'' and FSourceBillNo= ''{2}'' ";
+// sql = MessageFormat.format(sql, FBillNo, Fnumber, sBillNo);
+// return erpSqlServer.update(sql) > 0;
+// }
}
@@ -359,29 +413,31 @@
// }
/* 鎴愬搧澧為噺鍑哄簱 */
- public boolean incrementCPakOut(Integer FInterID, String Fnumbers, Double increment, String FBillNo) {
- String[] arrays = Fnumbers.split("|");
- String Fnumber="",sBillNo=""; //浜у搧浠g爜,鐢熶骇鍗曞彿
+ public boolean incrementCPakOut(Integer FInterID, String Fnumber, Double increment, String FBillNo) {
+// String[] arrays = Fnumbers.split("|");
+// String Fnumber="",sBillNo=""; //浜у搧浠g爜,鐢熶骇鍗曞彿
String sql = "update OutStockbillEntry set FAuxCommitQty = (FAuxCommitQty + {0,number,#}) where 1=1 and Fnumber = ''{1}'' and FInterID = {2,number,#} ";
- Fnumber = arrays[0];
- if(arrays.length>1){
- sBillNo = arrays[1];
- sql = sql + " and FSourceBillNo= ''{3}''";
- sql = MessageFormat.format(sql, increment, Fnumber, FInterID, sBillNo);
- } else {
- sql = MessageFormat.format(sql, increment, Fnumber, FInterID);
- }
+ sql = MessageFormat.format(sql, increment, Fnumber, FInterID);
+
+// Fnumber = arrays[0];
+// if(arrays.length>1){
+// sBillNo = arrays[1];
+// sql = sql + " and FSourceBillNo= ''{3}''";
+// sql = MessageFormat.format(sql, increment, Fnumber, FInterID, sBillNo);
+// } else {
+// sql = MessageFormat.format(sql, increment, Fnumber, FInterID);
+// }
try {
if (erpSqlServer.update(sql) > 0) {
- if(arrays.length>1) {
- sql = "select * from OutStockbillEntry where 1=1 and Fnumber = ''{0}'' and FInterID = {1,number,#} and FSourceBillNo= ''{2}''";
- sql = MessageFormat.format(sql, Fnumber, FInterID, sBillNo);
- } else {
+// if(arrays.length>1) {
+// sql = "select * from OutStockbillEntry where 1=1 and Fnumber = ''{0}'' and FInterID = {1,number,#} and FSourceBillNo= ''{2}''";
+// sql = MessageFormat.format(sql, Fnumber, FInterID, sBillNo);
+// } else {
sql = "select * from OutStockbillEntry where 1=1 and Fnumber = ''{0}'' and FInterID = {1,number,#}";
sql = MessageFormat.format(sql, Fnumber, FInterID);
- }
+// }
List<OutStockBillEntry> select = erpSqlServer.select(sql, OutStockBillEntry.class);
OutStockBillEntry outStockBillEntry = select.get(0);
@@ -396,8 +452,25 @@
}
}
if (complete) {
- if (!completeCPakOut(FBillNo)) {
- log.error("{}鍑哄簱鍗曟爣璁板畬鎴愬け璐�", FBillNo);
+ sql = "select * from OutStockbillEntry where 1=1 and FInterID = {1,number,#}";
+ sql = MessageFormat.format(sql, Fnumber, FInterID);
+ List<OutStockBillEntry> select1 = erpSqlServer.select(sql, OutStockBillEntry.class);
+
+ boolean flag = true;
+ for(OutStockBillEntry outStockBillEntry1 : select1){
+ if (outStockBillEntry1.getFAuxCommitQty().compareTo(outStockBillEntry1.getFQty()) == -1) {
+ flag = false;
+ }
+ }
+
+ if(flag){
+ if (!completeCPakOut(FBillNo) ) {
+ log.error("{}鍑哄簱鍗曟爣璁板畬鎴愬け璐�", FBillNo);
+ }
+ int updateCount = jdbcTemplate.update("update OutStockbill set Fflag_finish=1 where FBillNo='" + FBillNo + "'");
+ if(updateCount<=0){
+ throw new CoolException("鏇存柊鍑哄簱閫氱煡妗e畬鎴愭爣璁板け璐FBillNo="+FBillNo+"]");
+ }
}
}
return true;
@@ -405,7 +478,10 @@
return false;
}
}catch (Exception e){
- e.printStackTrace();
+ String msg = "incrementCPakOut鎴愬搧澧為噺鍑哄簱澶辫触[FInterID={0},Fnumber={1},FBillNo={2}]\n";
+ msg = MessageFormat.format(msg,FInterID,Fnumber,FBillNo);
+ log.error(msg, e);
+// e.printStackTrace();
log.error("incrementCPakOut----" + sql);
return false;
}
--
Gitblit v1.9.1