文件修改
This commit is contained in:
@@ -15,6 +15,8 @@ import org.nl.wql.util.WqlUtil;
|
|||||||
import org.springframework.cache.annotation.CacheConfig;
|
import org.springframework.cache.annotation.CacheConfig;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -80,79 +82,80 @@ public class GenCodeServiceImpl implements GenCodeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(propagation= Propagation.REQUIRES_NEW)
|
||||||
public String codeDemo(Map form) {
|
public String codeDemo(Map form) {
|
||||||
String code = (String) form.get("code");
|
String code = (String) form.get("code");
|
||||||
String id = this.queryIdByCode(code);
|
String id = this.queryIdByCode(code);
|
||||||
//如果flag=1就执行更新数据库的操作
|
//如果flag=1就执行更新数据库的操作
|
||||||
String flag = (String) form.get("flag");
|
String flag = (String) form.get("flag");
|
||||||
WQLObject wo = WQLObject.getWQLObject("sys_code_rule_detail");
|
WQLObject wo = WQLObject.getWQLObject("sys_code_rule_detail");
|
||||||
JSONArray ja = wo.query("code_rule_id = '" + id + "' order by sort_num,type").getResultJSONArray(0);
|
JSONArray ja = wo.query("code_rule_id = '" + id + "' order by sort_num,type").getResultJSONArray(0);
|
||||||
String demo = "";
|
String demo = "";
|
||||||
boolean is_same = true;
|
boolean is_same = true;
|
||||||
for (int i = 0; i < ja.size(); i++) {
|
for (int i = 0; i < ja.size(); i++) {
|
||||||
String value = "";
|
String value = "";
|
||||||
JSONObject jo = ja.getJSONObject(i);
|
JSONObject jo = ja.getJSONObject(i);
|
||||||
//固定直接取值
|
//固定直接取值
|
||||||
if (jo.optString("type").equals("01")) {
|
if (jo.optString("type").equals("01")) {
|
||||||
value = jo.optString("init_value");
|
value = jo.optString("init_value");
|
||||||
}
|
}
|
||||||
//日期判断数据库的值与当前值是否相同来决定顺序的值
|
//日期判断数据库的值与当前值是否相同来决定顺序的值
|
||||||
if (jo.optString("type").equals("02")) {
|
if (jo.optString("type").equals("02")) {
|
||||||
String current_value = jo.optString("current_value");
|
String current_value = jo.optString("current_value");
|
||||||
Date date = DateUtil.date();
|
Date date = DateUtil.date();
|
||||||
String format = jo.optString("format");
|
String format = jo.optString("format");
|
||||||
String now_date = DateUtil.format(date, format);
|
String now_date = DateUtil.format(date, format);
|
||||||
if (!now_date.equals(current_value)) {
|
if (!now_date.equals(current_value)) {
|
||||||
is_same = false;
|
is_same = false;
|
||||||
}
|
}
|
||||||
if (flag.equals("1")) {
|
if (flag.equals("1")) {
|
||||||
jo.put("init_value", now_date);
|
jo.put("init_value", now_date);
|
||||||
jo.put("current_value", now_date);
|
jo.put("current_value", now_date);
|
||||||
}
|
}
|
||||||
value = now_date;
|
value = now_date;
|
||||||
}
|
}
|
||||||
//顺序的值:如果日期一样就+步长,等于最大值就归为初始值;日期不一样就归为初始值
|
//顺序的值:如果日期一样就+步长,等于最大值就归为初始值;日期不一样就归为初始值
|
||||||
if (jo.optString("type").equals("03")) {
|
if (jo.optString("type").equals("03")) {
|
||||||
String num_value = "";
|
String num_value = "";
|
||||||
int step = jo.optInt("step");
|
int step = jo.optInt("step");
|
||||||
int max_value = jo.optInt("max_value");
|
int max_value = jo.optInt("max_value");
|
||||||
if (!is_same || (jo.optInt("current_value") + step > max_value)) {
|
if (!is_same || (jo.optInt("current_value") + step > max_value)) {
|
||||||
num_value = jo.optString("init_value");
|
num_value = jo.optString("init_value");
|
||||||
} else {
|
} else {
|
||||||
num_value = (jo.optInt("current_value") + step) + "";
|
num_value = (jo.optInt("current_value") + step) + "";
|
||||||
}
|
}
|
||||||
int size = num_value.length();
|
int size = num_value.length();
|
||||||
int length = jo.optInt("length");
|
int length = jo.optInt("length");
|
||||||
String fillchar = jo.optString("fillchar");
|
String fillchar = jo.optString("fillchar");
|
||||||
for (int m = 0; m < (length - size); m++) {
|
for (int m = 0; m < (length - size); m++) {
|
||||||
value += fillchar;
|
value += fillchar;
|
||||||
}
|
}
|
||||||
value += num_value;
|
value += num_value;
|
||||||
if (flag.equals("1")) {
|
if (flag.equals("1")) {
|
||||||
if (!is_same) {
|
if (!is_same) {
|
||||||
int init_value = jo.optInt("init_value");
|
int init_value = jo.optInt("init_value");
|
||||||
if (StrUtil.isEmpty((init_value + ""))) {
|
if (StrUtil.isEmpty((init_value + ""))) {
|
||||||
throw new BadRequestException("请完善编码数值的初始值!");
|
throw new BadRequestException("请完善编码数值的初始值!");
|
||||||
}
|
}
|
||||||
jo.put("current_value", init_value + "");
|
jo.put("current_value", init_value + "");
|
||||||
} else {
|
} else {
|
||||||
int num_curr = jo.optInt("current_value");
|
int num_curr = jo.optInt("current_value");
|
||||||
if (num_curr >= max_value) {
|
if (num_curr >= max_value) {
|
||||||
num_curr = jo.optInt("init_value");
|
num_curr = jo.optInt("init_value");
|
||||||
jo.put("current_value", num_curr + "");
|
jo.put("current_value", num_curr + "");
|
||||||
}else{
|
}else{
|
||||||
jo.put("current_value", (num_curr + step) + "");
|
jo.put("current_value", (num_curr + step) + "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
demo += value;
|
demo += value;
|
||||||
if (flag.equals("1")) {
|
if (flag.equals("1")) {
|
||||||
wo.update(jo);
|
wo.update(jo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return demo;
|
return demo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String queryIdByCode(String code) {
|
public String queryIdByCode(String code) {
|
||||||
|
|||||||
@@ -7,13 +7,16 @@ import java.util.HashMap;
|
|||||||
|
|
||||||
public class CodeUtil {
|
public class CodeUtil {
|
||||||
|
|
||||||
public static synchronized String getNewCode(String ruleCode){
|
public static String getNewCode(String ruleCode) {
|
||||||
GenCodeService service=new GenCodeServiceImpl();
|
synchronized (ruleCode) {
|
||||||
String flag = "1";
|
GenCodeService service = new GenCodeServiceImpl();
|
||||||
HashMap<String,String> map = new HashMap<>();
|
String flag = "1";
|
||||||
map.put("flag",flag);
|
HashMap<String, String> map = new HashMap<>();
|
||||||
map.put("code",ruleCode);
|
map.put("flag", flag);
|
||||||
return service.codeDemo(map);
|
map.put("code", ruleCode);
|
||||||
|
return service.codeDemo(map);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ https://juejin.cn/post/6844903775631572999
|
|||||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>${log.pattern}</pattern>
|
<pattern>${log.pattern}</pattern>
|
||||||
<charset>${log.charset}</charset>
|
<!-- <charset>${log.charset}</charset>-->
|
||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ https://juejin.cn/post/6844903775631572999
|
|||||||
|
|
||||||
<!--开发环境:打印控制台-->
|
<!--开发环境:打印控制台-->
|
||||||
<springProfile name="dev">
|
<springProfile name="dev">
|
||||||
<root level="info">
|
<root level="off">
|
||||||
<appender-ref ref="CONSOLE"/>
|
<appender-ref ref="CONSOLE"/>
|
||||||
</root>
|
</root>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user