From 3510d2a3eea1c3addafd9b0cb47332706e815753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=B1=9F=E7=8E=AE?= Date: Wed, 29 Mar 2023 20:27:41 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E7=BC=96=E7=A0=81=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/GenCodeServiceImpl.java | 80 ++++++++++++++++++- .../org/nl/modules/system/util/CodeUtil.java | 11 ++- 2 files changed, 87 insertions(+), 4 deletions(-) diff --git a/wms/hd/nladmin-system/src/main/java/org/nl/modules/system/service/impl/GenCodeServiceImpl.java b/wms/hd/nladmin-system/src/main/java/org/nl/modules/system/service/impl/GenCodeServiceImpl.java index 33da0cb..672c5d8 100644 --- a/wms/hd/nladmin-system/src/main/java/org/nl/modules/system/service/impl/GenCodeServiceImpl.java +++ b/wms/hd/nladmin-system/src/main/java/org/nl/modules/system/service/impl/GenCodeServiceImpl.java @@ -15,6 +15,8 @@ import org.nl.wql.util.WqlUtil; import org.springframework.cache.annotation.CacheConfig; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import java.util.*; @@ -77,7 +79,8 @@ public class GenCodeServiceImpl implements GenCodeService { } @Override - public synchronized String codeDemo(Map form) { + @Transactional(propagation = Propagation.REQUIRES_NEW) + public String codeDemo(Map form) { String code = (String) form.get("code"); String id = this.queryIdByCode(code); //如果flag=1就执行更新数据库的操作 @@ -248,4 +251,79 @@ public class GenCodeServiceImpl implements GenCodeService { return id; } + @Transactional(propagation = Propagation.REQUIRES_NEW) + public String taskCode(Map form) { + String code = (String) form.get("code"); + String id = this.queryIdByCode(code); + //如果flag=1就执行更新数据库的操作 + String flag = (String) form.get("flag"); + WQLObject wo = WQLObject.getWQLObject("sys_code_rule_detail"); + JSONArray ja = wo.query("code_rule_id = '" + id + "'", " sort_num,type").getResultJSONArray(0); + String demo = ""; + boolean is_same = true; + for (int i = 0; i < ja.size(); i++) { + String value = ""; + JSONObject jo = ja.getJSONObject(i); + //固定直接取值 + if (jo.getString("type").equals("01")) { + value = jo.getString("init_value"); + } + //日期判断数据库的值与当前值是否相同来决定顺序的值 + if (jo.getString("type").equals("02")) { + String current_value = jo.getString("current_value"); + Date date = DateUtil.date(); + String format = jo.getString("format"); + String now_date = DateUtil.format(date, format); + if (!now_date.equals(current_value)) { + is_same = false; + } + if (flag.equals("1")) { + jo.put("init_value", now_date); + jo.put("current_value", now_date); + } + value = now_date; + } + //顺序的值:如果日期一样就+步长,等于最大值就归为初始值;日期不一样就归为初始值 + if (jo.getString("type").equals("03")) { + String num_value = ""; + int step = jo.getInteger("step"); + Long max_value = jo.getLong("max_value"); + if (!is_same || (jo.getLongValue("current_value") + step > max_value)) { + num_value = jo.getString("init_value"); + } else { + num_value = (jo.getInteger("current_value") + step) + ""; + } + int size = num_value.length(); + int length = jo.getInteger("length"); + String fillchar = jo.getString("fillchar"); + for (int m = 0; m < (length - size); m++) { + value += fillchar; + } + value += num_value; + if (flag.equals("1")) { + if (!is_same) { + int init_value = jo.getInteger("init_value"); + if (StrUtil.isEmpty((init_value + ""))) { + throw new BadRequestException("请完善编码数值的初始值!"); + } + jo.put("current_value", init_value + ""); + } else { + int num_curr = jo.getInteger("current_value"); + if (num_curr >= max_value) { + num_curr = jo.getInteger("init_value"); + jo.put("current_value", num_curr + ""); + }else{ + jo.put("current_value", (num_curr + step) + ""); + } + } + } + } + demo += value; + if (flag.equals("1")) { + wo.update(jo); + } + } + return demo; + } + } diff --git a/wms/hd/nladmin-system/src/main/java/org/nl/modules/system/util/CodeUtil.java b/wms/hd/nladmin-system/src/main/java/org/nl/modules/system/util/CodeUtil.java index 340cf84..b98011e 100644 --- a/wms/hd/nladmin-system/src/main/java/org/nl/modules/system/util/CodeUtil.java +++ b/wms/hd/nladmin-system/src/main/java/org/nl/modules/system/util/CodeUtil.java @@ -2,19 +2,24 @@ package org.nl.modules.system.util; import org.nl.modules.system.service.GenCodeService; import org.nl.modules.system.service.impl.GenCodeServiceImpl; +import org.nl.utils.SpringContextHolder; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import java.util.HashMap; import java.util.List; public class CodeUtil { - public static synchronized String getNewCode(String ruleCode) { - GenCodeService service = new GenCodeServiceImpl(); + public static String getNewCode(String ruleCode) { + synchronized (ruleCode){ String flag = "1"; HashMap map = new HashMap<>(); map.put("flag", flag); map.put("code", ruleCode); - return service.codeDemo(map); + GenCodeServiceImpl service = SpringContextHolder.getBean(GenCodeServiceImpl.class); + return service.taskCode(map); + } } public static synchronized List getNewCodes(String ruleCode, Integer number) {