From 878b6958363308a7d07b7b8197dc19662f3e1198 Mon Sep 17 00:00:00 2001
From: sgj <1442489573@qq.com>
Date: 星期五, 27 三月 2026 15:40:22 +0800
Subject: [PATCH] 获取出入库id,逻辑优化调整
---
fzzy-igdss-core/src/main/java/com/fzzy/igds/service/InoutRecordService.java | 93 ++++++++++++++++++++++++++++++++++------------
1 files changed, 69 insertions(+), 24 deletions(-)
diff --git a/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/InoutRecordService.java b/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/InoutRecordService.java
index e3ae15f..b2c65db 100644
--- a/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/InoutRecordService.java
+++ b/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/InoutRecordService.java
@@ -24,7 +24,6 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.BeanUtils;
-import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -137,13 +136,13 @@
queryWrapper.eq("settle_tag", param.getSettleTag());
}
if (null != param.getStart()) {
- queryWrapper.ge("create_time", DateUtil.getCurZero(param.getStart()));
+ queryWrapper.ge("complete_time", DateUtil.getCurZero(param.getStart()));
}
if (null != param.getEnd()) {
- queryWrapper.le("create_time", DateUtil.getNextZero(param.getEnd()));
+ queryWrapper.le("complete_time", DateUtil.getNextZero(param.getEnd()));
}
queryWrapper.ne("record_status", Constant.RECORD_STATUS_DEL); //涓嶆槸鍒犻櫎鐨勫崟瀛愶紝鍗虫甯哥殑鍗曞瓙
- queryWrapper.orderByDesc("create_time");
+ queryWrapper.orderByDesc("complete_time");
return queryWrapper;
}
@@ -245,7 +244,7 @@
InoutRecord record = new InoutRecord();
BeanUtils.copyProperties(data, record);
//淇濆瓨
- int num = this.addInoutRecord(record);
+ int num = this.addInoutRecord(record,true);
//闄勪欢澶勭悊
fileService.saveInoutFiles(data.getFiles(), record.getId(), null, "INOUT");
@@ -263,13 +262,13 @@
* @param list
* @return
*/
- public String addInoutRecordList(List<InoutRecord> list) {
+ public String addInoutRecordList(List<InoutRecord> list,boolean isCache) {
if (null == list || list.isEmpty()) {
return "鏂板澶辫触";
}
for (InoutRecord inoutRecord : list) {
- addInoutRecord(inoutRecord);
+ addInoutRecord(inoutRecord,isCache);
}
return null;
@@ -281,10 +280,10 @@
* @param data
* @return
*/
- public int addInoutRecord(InoutRecord data) {
+ public int addInoutRecord(InoutRecord data,boolean isCache) {
if (StringUtils.isBlank(data.getId())) {
- String id = this.createId(data.getRegisterTime(), data.getCompanyId());
+ String id = this.createId(data.getRegisterTime(), data.getCompanyId(),isCache);
if (Constant.TYPE_IN.equals(data.getType())) {
data.setId("R_" + id);
} else if (Constant.TYPE_OUT.equals(data.getType())) {
@@ -596,7 +595,7 @@
* @param companyId
* @return
*/
- public String createId(Date registerTime, String companyId) {
+ public String createId(Date registerTime, String companyId,boolean isCache) {
// 鏃堕棿鎴虫爣绛�
String timeKey = DateFormatUtils.format(registerTime, "yyyyMMdd");
@@ -604,7 +603,10 @@
// 浠庣紦瀛樹腑鑾峰彇宸叉湁鐨勭粍缁囩紪鐮�
String cacheKey = RedisConst.buildKey(companyId, Constant.CACHE_RECORD_ID);
- String cacheId = (String) redisCache.getCacheObject(cacheKey);
+ String cacheId = null;
+ if (isCache) {
+ cacheId=(String) redisCache.getCacheObject(cacheKey);
+ }
if (null != cacheId && cacheId.indexOf(timeKey) >= 0) {
String temp = cacheId.substring(cacheId.length() - 4);
@@ -647,10 +649,52 @@
}
}
+
+ // 鏁版嵁搴� ID 閲嶅鏍¢獙锛岀‘淇濇柊鐢熸垚鐨� ID 鍦ㄦ暟鎹簱涓笉瀛樺湪
+ while (this.checkIdExists(companyId, cacheId)) {
+ String temp = cacheId.substring(cacheId.length() - 4);
+ Integer i = Integer.valueOf(temp);
+ i++;
+ temp = String.valueOf(i);
+ if (temp.length() == 1) {
+ cacheId = timeKey + "000" + temp;
+ }
+ if (temp.length() == 2) {
+ cacheId = timeKey + "00" + temp;
+ }
+ if (temp.length() == 3) {
+ cacheId = timeKey + "0" + temp;
+ }
+ if (temp.length() == 4) {
+ cacheId = timeKey + temp;
+ }
+ }
+
// 鏇存柊缂撳瓨
- redisCache.setCacheObject(cacheKey, cacheId);
+ if(isCache){
+ redisCache.setCacheObject(cacheKey, cacheId);
+ }
return cacheId;
+ }
+
+ /**
+ * 妫�鏌� ID 鏄惁鍦ㄦ暟鎹簱涓凡瀛樺湪
+ *
+ * @param companyId
+ * @param id
+ * @return true-宸插瓨鍦紝false-涓嶅瓨鍦�
+ */
+ public boolean checkIdExists(String companyId, String id) {
+ QueryWrapper<InoutRecord> queryWrapper = new QueryWrapper<>();
+ queryWrapper.eq("company_id", companyId);
+ //浣跨敤likeleft
+ queryWrapper.likeLeft("id", id);
+ List<InoutRecord> inoutRecords = inoutRecordMapper.selectList(queryWrapper);
+ if( null != inoutRecords && inoutRecords.size() > 0){
+ return true;
+ }
+ return false;
}
/**
@@ -669,8 +713,7 @@
queryWrapper.eq("company_id", companyId);
queryWrapper.like("id", timeKey);
- queryWrapper.orderByDesc("create_time");
-
+ queryWrapper.orderByDesc("register_time");
List<InoutRecord> inoutRecords = inoutRecordMapper.selectList(queryWrapper);
if (null == inoutRecords || inoutRecords.isEmpty()) {
return null;
@@ -688,10 +731,10 @@
public String inWeightBill(InoutRecord data) {
// 鑾峰彇琛ㄥ崟鏁版嵁
- InoutPrintBill bill = this.createBillData(data, "-鍏ュ簱鍗�");
+ InoutPrintBill bill = this.createBillData(data, "鍏ュ簱鍗�");
// 璋冩暣妯$増鏁版嵁骞惰繑鍥�
- String htmlStr = InoutBill.IN_WEIGHT_DEFAULT;
+ String htmlStr = InoutBill.IN_WEIGHT_DEFAULT_NEW;
htmlStr = htmlStr.replace("billTitle", bill.getBillTitle());
@@ -749,7 +792,7 @@
htmlStr = htmlStr.replace("handleEnd", "");
htmlStr = htmlStr.replace("noticeId", bill.getNoticeId() == null ? "" : bill.getNoticeId());
htmlStr = htmlStr.replace("phone", data.getUserContact() == null ? "" : data.getUserContact() + "");
- htmlStr = htmlStr.replace("printTime", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm"));
+ htmlStr = htmlStr.replace("printTime", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
htmlStr = htmlStr.replaceAll("weightUser",
bill.getWeightUser() == null ? "" : bill.getWeightUser());
@@ -757,7 +800,7 @@
bill.getHandleUser() == null ? "" : bill.getHandleUser());
htmlStr = htmlStr.replaceAll("keeperName",
bill.getKeeperUser() == null ? "" : bill.getKeeperUser());
-
+ htmlStr = htmlStr.replaceAll("createUser",ContextUtil.getLoginUserName());
return htmlStr;
}
@@ -770,10 +813,10 @@
*/
public String outWeightBill(InoutRecord data) {
// 鑾峰彇琛ㄥ崟鏁版嵁
- InoutPrintBill bill = this.createBillData(data, "-鍑哄簱鍗�");
+ InoutPrintBill bill = this.createBillData(data, "鍑哄簱鍗�");
//榛樿妯$増
- String htmlStr = InoutBill.OUT_WEIGHT_DEFAULT;
+ String htmlStr = InoutBill.OUT_WEIGHT_DEFAULT_NEW;
htmlStr = htmlStr.replace("billTitle", bill.getBillTitle());
@@ -822,11 +865,13 @@
htmlStr = htmlStr.replace("handleEnd", "");
htmlStr = htmlStr.replace("noticeId", bill.getNoticeId() == null ? "" : bill.getNoticeId());
htmlStr = htmlStr.replace("phone", data.getUserContact() == null ? "" : data.getUserContact() + "");
- htmlStr = htmlStr.replace("printTime", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm"));
+ htmlStr = htmlStr.replace("printTime", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
htmlStr = htmlStr.replaceAll("weightUser", getValue(bill.getWeightUser()));
htmlStr = htmlStr.replace("handleUser", getValue(bill.getHandleUser()));
htmlStr = htmlStr.replaceAll("keeperName", getValue(bill.getKeeperUser()));
+ htmlStr = htmlStr.replaceAll("createUser",ContextUtil.getLoginUserName());
+
return htmlStr;
}
@@ -862,13 +907,13 @@
data.setRegisterTime(new Date());
}
bill.setRegisterTime(DateFormatUtils.format(data.getRegisterTime(),
- "yyyy-MM-dd HH:mm"));
+ "yyyy-MM-dd HH:mm:ss"));
if (null == data.getCompleteTime()) {
data.setCompleteTime(new Date());
}
bill.setCompleteTime(DateFormatUtils.format(data.getCompleteTime(),
- "yyyy-MM-dd HH:mm"));
+ "yyyy-MM-dd HH:mm:ss"));
bill.setEmptyTime(DateFormatUtils.format(data.getEmptyWeightTime(),
"yyyy-MM-dd HH:mm:ss"));
@@ -922,7 +967,7 @@
data.setSettleMoney(NumberUtil.keepPrecision(data.getPrice() * data.getRecordWeight(), 2));
}
}
- bill.setSettleMoney(data.getSettleMoney() == null ? "" : data.getSettleMoney() + "");
+ bill.setSettleMoney(data.getSettleMoney() == null ? "" : String.format("%.2f", data.getSettleMoney()));
bill.setRemark(data.getRemarks() == null ? "" : data.getRemarks());
if (Constant.TYPE_IN.equals(data.getType())) {
--
Gitblit v1.9.3