opt:优化获取code代码
This commit is contained in:
@@ -60,8 +60,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
@@ -590,7 +594,7 @@ public class StIvtIostorinvServiceImpl extends ServiceImpl<StIvtIostorinvMapper,
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation=Propagation.REQUIRES_NEW)
|
||||
@Transactional
|
||||
public void reIssueTask(Map whereJson) {
|
||||
|
||||
String task_id = MapUtil.getStr(whereJson, "task_id");
|
||||
@@ -737,7 +741,6 @@ public class StIvtIostorinvServiceImpl extends ServiceImpl<StIvtIostorinvMapper,
|
||||
.syscompanyid(SecurityUtils.getDeptId())
|
||||
.sysdeptid(SecurityUtils.getDeptId())
|
||||
.build();
|
||||
|
||||
if (ObjectUtil.isNotEmpty(MapUtil.getStr(whereJson, "out_stor_id"))) {
|
||||
mstDao.setOut_stor_id(Long.parseLong(MapUtil.getStr(whereJson, "out_stor_id")));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.nl.common.utils;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import lombok.SneakyThrows;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.wql.util.SpringContextHolder;
|
||||
@@ -27,8 +28,8 @@ public class CodeUtil {
|
||||
String flag = "1";
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("flag", flag);
|
||||
map.put("code", ruleCode);
|
||||
return SpringContextHolder.getBean(ISysCodeRuleService.class).codeDemo(map);
|
||||
String code = HttpUtil.get("http://127.0.0.1:8011/api/codeDetail/getNewCode?code=" + ruleCode + "&flag" + flag);
|
||||
return code;
|
||||
} else {
|
||||
throw new BadRequestException("系统繁忙,稍后在试!");
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.nl.system.controller.coderule;
|
||||
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import org.nl.common.TableDataInfo;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.logging.annotation.Log;
|
||||
@@ -55,12 +56,17 @@ public class SysCodeRuleDetailController {
|
||||
}
|
||||
|
||||
@Log("修改编码明细")
|
||||
|
||||
@PutMapping
|
||||
@SaCheckPermission("genCode:edit")
|
||||
public ResponseEntity<Object> update(@RequestBody SysCodeRuleDetail json) {
|
||||
codeDetailService.update(json);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
@GetMapping("getNewCode")
|
||||
@SaIgnore
|
||||
public ResponseEntity<Object> getCode(String code,String flag) {
|
||||
String newCode = codeDetailService.getNewCode(code, flag);
|
||||
return new ResponseEntity<>(newCode,HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,4 +45,8 @@ public interface ISysCodeRuleDetailService extends IService<SysCodeRuleDetail> {
|
||||
* @param json
|
||||
*/
|
||||
void update(SysCodeRuleDetail json);
|
||||
/**
|
||||
* http获取code
|
||||
*/
|
||||
String getNewCode(String code,String flag);
|
||||
}
|
||||
|
||||
@@ -2,22 +2,28 @@ package org.nl.system.service.coderule.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.common.utils.SecurityUtils;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.system.service.coderule.ISysCodeRuleDetailService;
|
||||
import org.nl.system.service.coderule.dao.SysCodeRule;
|
||||
import org.nl.system.service.coderule.dao.SysCodeRuleDetail;
|
||||
import org.nl.system.service.coderule.dao.mapper.SysCodeRuleDetailMapper;
|
||||
import org.nl.system.service.coderule.dao.mapper.SysCodeRuleMapper;
|
||||
import org.nl.system.service.coderule.dto.CodeRuleDetailQuery;
|
||||
import org.nl.system.service.coderule.utils.CodeRuleTypeEnum;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -32,6 +38,9 @@ public class SysCodeRuleDetailServiceImpl extends ServiceImpl<SysCodeRuleDetailM
|
||||
@Autowired
|
||||
private SysCodeRuleDetailMapper codeRuleDetailMapper;
|
||||
|
||||
@Resource
|
||||
private SysCodeRuleMapper codeRuleMapper;
|
||||
|
||||
@Override
|
||||
public IPage<SysCodeRuleDetail> queryAll(CodeRuleDetailQuery form, PageQuery page) {
|
||||
LambdaQueryWrapper<SysCodeRuleDetail> lam = new LambdaQueryWrapper<>();
|
||||
@@ -77,4 +86,79 @@ public class SysCodeRuleDetailServiceImpl extends ServiceImpl<SysCodeRuleDetailM
|
||||
public void update(SysCodeRuleDetail json) {
|
||||
codeRuleDetailMapper.updateById(json);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public String getNewCode(String code, String flag) {
|
||||
String id = codeRuleMapper.selectOne(new LambdaQueryWrapper<SysCodeRule>().eq(SysCodeRule::getCode, code)).getId();
|
||||
// 如果flag = 1就执行更新数据库的操作
|
||||
List<SysCodeRuleDetail> ruleDetails = codeRuleDetailMapper.selectList(new LambdaQueryWrapper<SysCodeRuleDetail>()
|
||||
.eq(SysCodeRuleDetail::getCode_rule_id, id)
|
||||
.orderByAsc(SysCodeRuleDetail::getSort_num));
|
||||
String demo = "";
|
||||
boolean isSame = true;
|
||||
for (SysCodeRuleDetail detail : ruleDetails) {
|
||||
String value = "";
|
||||
String type = detail.getType();
|
||||
//固定直接取值
|
||||
if (type.equals(CodeRuleTypeEnum.FIXED.getType())) {
|
||||
value = detail.getInit_value();
|
||||
}
|
||||
//日期判断数据库的值与当前值是否相同来决定顺序的值
|
||||
if (type.equals(CodeRuleTypeEnum.DATE.getType())) {
|
||||
String currentValue = detail.getCurrent_value();
|
||||
Date date = DateUtil.date();
|
||||
String format = detail.getFormat();
|
||||
String nowDate = DateUtil.format(date, format);
|
||||
if (!nowDate.equals(currentValue)) {
|
||||
isSame = false;
|
||||
}
|
||||
if ("1".equals(flag)) {
|
||||
detail.setInit_value(nowDate);
|
||||
detail.setCurrent_value(nowDate);
|
||||
}
|
||||
value = nowDate;
|
||||
}
|
||||
//顺序的值:如果日期一样就+步长,等于最大值就归为初始值;日期不一样就归为初始值
|
||||
if (type.equals(CodeRuleTypeEnum.ORDER.getType())) {
|
||||
String numValue = "";
|
||||
int step = Integer.parseInt(detail.getStep());
|
||||
Long maxValue = Long.valueOf(detail.getMax_value());
|
||||
if (!isSame || (Long.valueOf(detail.getCurrent_value()) + step) > maxValue) {
|
||||
numValue = detail.getInit_value();
|
||||
} else {
|
||||
numValue = Integer.parseInt(detail.getCurrent_value()) + step + "";
|
||||
}
|
||||
int size = numValue.length();
|
||||
int length = detail.getLength();
|
||||
String fillchar = detail.getFillchar();
|
||||
for (int m = 0; m < (length - size); m++) {
|
||||
value += fillchar;
|
||||
}
|
||||
value += numValue;
|
||||
if ("1".equals(flag)) {
|
||||
if (!isSame) {
|
||||
int initValue = Integer.parseInt(detail.getInit_value());
|
||||
if (StrUtil.isEmpty((initValue + ""))) {
|
||||
throw new BadRequestException("请完善编码数值的初始值!");
|
||||
}
|
||||
detail.setCurrent_value(String.valueOf(initValue));
|
||||
} else {
|
||||
int numCurr = Integer.parseInt(detail.getCurrent_value());
|
||||
if (numCurr >= maxValue) {
|
||||
numCurr = Integer.parseInt(detail.getInit_value());
|
||||
detail.setCurrent_value(String.valueOf(numCurr));
|
||||
} else {
|
||||
detail.setCurrent_value(String.valueOf(numCurr + step));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
demo += value;
|
||||
if ("1".equals(flag)) {
|
||||
codeRuleDetailMapper.updateById(detail);
|
||||
}
|
||||
}
|
||||
return demo;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@@ -14,6 +17,7 @@ import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.common.utils.MapOf;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.common.utils.SecurityUtils;
|
||||
import org.nl.modules.common.utils.ElAdminConstant;
|
||||
import org.nl.system.service.coderule.ISysCodeRuleService;
|
||||
import org.nl.system.service.coderule.dao.SysCodeRule;
|
||||
import org.nl.system.service.coderule.dao.SysCodeRuleDetail;
|
||||
@@ -61,7 +65,6 @@ public class SysCodeRuleServiceImpl extends ServiceImpl<SysCodeRuleMapper, SysCo
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
|
||||
public String codeDemo(Map form) {
|
||||
String code = (String) form.get("code");
|
||||
String id = codeRuleMapper.selectOne(new LambdaQueryWrapper<SysCodeRule>().eq(SysCodeRule::getCode, code)).getId();
|
||||
@@ -131,7 +134,10 @@ public class SysCodeRuleServiceImpl extends ServiceImpl<SysCodeRuleMapper, SysCo
|
||||
}
|
||||
demo += value;
|
||||
if ("1".equals(flag)) {
|
||||
codeRuleDetailMapper.updateById(detail);
|
||||
new Thread(()->{
|
||||
codeRuleDetailMapper.updateById(detail);
|
||||
})
|
||||
.start();
|
||||
}
|
||||
log.info("更新成功:更新数据{}", detail);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
server:
|
||||
port: 9999
|
||||
port: 8011
|
||||
#配置数据源
|
||||
spring:
|
||||
shardingsphere:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
server:
|
||||
port: 8013
|
||||
port: 8011
|
||||
#配置数据源
|
||||
spring:
|
||||
shardingsphere:
|
||||
|
||||
@@ -126,6 +126,7 @@ security:
|
||||
- /api/param/getValueByCode
|
||||
- /plumelog/**
|
||||
- /api/esLog/**
|
||||
- /api/codeDetail/getNewCode
|
||||
# Sa-Token配置
|
||||
sa-token:
|
||||
# token 名称 (同时也是cookie名称)
|
||||
|
||||
Reference in New Issue
Block a user