From 23e8b1d1a54c724ad67b79681675f7ec7162492a Mon Sep 17 00:00:00 2001 From: zhangzq Date: Fri, 14 Feb 2025 14:24:05 +0800 Subject: [PATCH] =?UTF-8?q?opt:=E4=BC=98=E5=8C=96=E8=8E=B7=E5=8F=96code?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/StIvtIostorinvServiceImpl.java | 7 +- .../java/org/nl/common/utils/CodeUtil.java | 5 +- .../coderule/SysCodeRuleDetailController.java | 8 +- .../coderule/ISysCodeRuleDetailService.java | 4 + .../impl/SysCodeRuleDetailServiceImpl.java | 84 +++++++++++++++++++ .../coderule/impl/SysCodeRuleServiceImpl.java | 10 ++- .../main/resources/config/application-dev.yml | 2 +- .../resources/config/application-prod.yml | 2 +- .../src/main/resources/config/application.yml | 1 + 9 files changed, 114 insertions(+), 9 deletions(-) diff --git a/lms/nladmin-system/src/main/java/org/nl/b_lms/storage_manage/ios/service/iostorInv/impl/StIvtIostorinvServiceImpl.java b/lms/nladmin-system/src/main/java/org/nl/b_lms/storage_manage/ios/service/iostorInv/impl/StIvtIostorinvServiceImpl.java index c2b11d9e9..8a92a0780 100644 --- a/lms/nladmin-system/src/main/java/org/nl/b_lms/storage_manage/ios/service/iostorInv/impl/StIvtIostorinvServiceImpl.java +++ b/lms/nladmin-system/src/main/java/org/nl/b_lms/storage_manage/ios/service/iostorInv/impl/StIvtIostorinvServiceImpl.java @@ -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 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("系统繁忙,稍后在试!"); } diff --git a/lms/nladmin-system/src/main/java/org/nl/system/controller/coderule/SysCodeRuleDetailController.java b/lms/nladmin-system/src/main/java/org/nl/system/controller/coderule/SysCodeRuleDetailController.java index 6a40a1ff9..149bed7e5 100644 --- a/lms/nladmin-system/src/main/java/org/nl/system/controller/coderule/SysCodeRuleDetailController.java +++ b/lms/nladmin-system/src/main/java/org/nl/system/controller/coderule/SysCodeRuleDetailController.java @@ -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 update(@RequestBody SysCodeRuleDetail json) { codeDetailService.update(json); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } + @GetMapping("getNewCode") + @SaIgnore + public ResponseEntity getCode(String code,String flag) { + String newCode = codeDetailService.getNewCode(code, flag); + return new ResponseEntity<>(newCode,HttpStatus.OK); + } } diff --git a/lms/nladmin-system/src/main/java/org/nl/system/service/coderule/ISysCodeRuleDetailService.java b/lms/nladmin-system/src/main/java/org/nl/system/service/coderule/ISysCodeRuleDetailService.java index 3f349b7ee..da451eb7b 100644 --- a/lms/nladmin-system/src/main/java/org/nl/system/service/coderule/ISysCodeRuleDetailService.java +++ b/lms/nladmin-system/src/main/java/org/nl/system/service/coderule/ISysCodeRuleDetailService.java @@ -45,4 +45,8 @@ public interface ISysCodeRuleDetailService extends IService { * @param json */ void update(SysCodeRuleDetail json); + /** + * http获取code + */ + String getNewCode(String code,String flag); } diff --git a/lms/nladmin-system/src/main/java/org/nl/system/service/coderule/impl/SysCodeRuleDetailServiceImpl.java b/lms/nladmin-system/src/main/java/org/nl/system/service/coderule/impl/SysCodeRuleDetailServiceImpl.java index 4cf4df144..817050f92 100644 --- a/lms/nladmin-system/src/main/java/org/nl/system/service/coderule/impl/SysCodeRuleDetailServiceImpl.java +++ b/lms/nladmin-system/src/main/java/org/nl/system/service/coderule/impl/SysCodeRuleDetailServiceImpl.java @@ -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; /** *

@@ -32,6 +38,9 @@ public class SysCodeRuleDetailServiceImpl extends ServiceImpl queryAll(CodeRuleDetailQuery form, PageQuery page) { LambdaQueryWrapper lam = new LambdaQueryWrapper<>(); @@ -77,4 +86,79 @@ public class SysCodeRuleDetailServiceImpl extends ServiceImpl().eq(SysCodeRule::getCode, code)).getId(); + // 如果flag = 1就执行更新数据库的操作 + List ruleDetails = codeRuleDetailMapper.selectList(new LambdaQueryWrapper() + .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; + } } diff --git a/lms/nladmin-system/src/main/java/org/nl/system/service/coderule/impl/SysCodeRuleServiceImpl.java b/lms/nladmin-system/src/main/java/org/nl/system/service/coderule/impl/SysCodeRuleServiceImpl.java index e143efb7a..113159408 100644 --- a/lms/nladmin-system/src/main/java/org/nl/system/service/coderule/impl/SysCodeRuleServiceImpl.java +++ b/lms/nladmin-system/src/main/java/org/nl/system/service/coderule/impl/SysCodeRuleServiceImpl.java @@ -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().eq(SysCodeRule::getCode, code)).getId(); @@ -131,7 +134,10 @@ public class SysCodeRuleServiceImpl extends ServiceImpl{ + codeRuleDetailMapper.updateById(detail); + }) + .start(); } log.info("更新成功:更新数据{}", detail); } diff --git a/lms/nladmin-system/src/main/resources/config/application-dev.yml b/lms/nladmin-system/src/main/resources/config/application-dev.yml index 6ecc95097..36cc2f6fd 100644 --- a/lms/nladmin-system/src/main/resources/config/application-dev.yml +++ b/lms/nladmin-system/src/main/resources/config/application-dev.yml @@ -1,5 +1,5 @@ server: - port: 9999 + port: 8011 #配置数据源 spring: shardingsphere: diff --git a/lms/nladmin-system/src/main/resources/config/application-prod.yml b/lms/nladmin-system/src/main/resources/config/application-prod.yml index 116aa3756..7e8d0523b 100644 --- a/lms/nladmin-system/src/main/resources/config/application-prod.yml +++ b/lms/nladmin-system/src/main/resources/config/application-prod.yml @@ -1,5 +1,5 @@ server: - port: 8013 + port: 8011 #配置数据源 spring: shardingsphere: diff --git a/lms/nladmin-system/src/main/resources/config/application.yml b/lms/nladmin-system/src/main/resources/config/application.yml index 1aacdc663..4ffd005e7 100644 --- a/lms/nladmin-system/src/main/resources/config/application.yml +++ b/lms/nladmin-system/src/main/resources/config/application.yml @@ -126,6 +126,7 @@ security: - /api/param/getValueByCode - /plumelog/** - /api/esLog/** + - /api/codeDetail/getNewCode # Sa-Token配置 sa-token: # token 名称 (同时也是cookie名称)