From 735c6ad13463f5f77969b393324b4afa32cca2fc Mon Sep 17 00:00:00 2001 From: liuxiaoxu <1793812695@qq.com> Date: Mon, 15 Jul 2024 15:54:27 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=20=E5=A7=94=E5=A4=96=E5=8A=A0=E5=B7=A5?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E5=A7=94=E5=A4=96=E5=B7=A5=E5=BA=8F?= =?UTF-8?q?=E7=9A=84=E6=96=B0=E5=A2=9E=E5=90=8E=E7=AB=AF=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=8C=E4=BD=BF=E7=94=A8redis=E8=87=AA=E5=8A=A8=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=A7=94=E5=A4=96=E5=B7=A5=E5=BA=8FID=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90=E5=A7=94=E5=A4=96?= =?UTF-8?q?=E5=B7=A5=E5=BA=8F=E7=BC=96=E5=8F=B7=E5=90=8E=E7=AB=AF=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OutsourceProcessController.java | 12 ++++ .../service/IOutsourceProcessService.java | 7 +++ .../impl/OutsourceProcessServiceImpl.java | 58 ++++++++----------- .../system/outsource_process/add.html | 54 ++++++++++------- 4 files changed, 75 insertions(+), 56 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/controller/OutsourceProcessController.java b/ruoyi-admin/src/main/java/com/ruoyi/system/controller/OutsourceProcessController.java index be7c0f1e..1d1e3a11 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/controller/OutsourceProcessController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/controller/OutsourceProcessController.java @@ -150,4 +150,16 @@ public class OutsourceProcessController extends BaseController { return toAjax(outsourceProcessService.deleteOutsourceProcessByOutsourceProcessIds(ids)); } + + /** + * 自动生成委外工序编号 + * + */ + @GetMapping("/generateOutsourceProcessNo") + @ResponseBody + public String generateOutsourceProcessNo(){ + + String result = outsourceProcessService.generateOutsourceProcessNo(); + return result; + } } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/service/IOutsourceProcessService.java b/ruoyi-admin/src/main/java/com/ruoyi/system/service/IOutsourceProcessService.java index cd9daa3a..c9800a11 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/service/IOutsourceProcessService.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/service/IOutsourceProcessService.java @@ -36,6 +36,13 @@ public interface IOutsourceProcessService */ public List selectOutsourceProcessList(OutsourceProcess outsourceProcess); + + /** + * 自动生成委外工序编号 + * + */ + public String generateOutsourceProcessNo(); + /** * 新增委外工序 * diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/OutsourceProcessServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/OutsourceProcessServiceImpl.java index 70414f83..f029e5c6 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/OutsourceProcessServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/OutsourceProcessServiceImpl.java @@ -4,7 +4,10 @@ import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; + +import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.common.utils.ShiroUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.system.domain.OutsourceProcess; import com.ruoyi.system.mapper.OutsourceProcessMapper; @@ -12,6 +15,7 @@ import com.ruoyi.system.service.IOutsourceProcessService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.common.core.text.Convert; +import org.springframework.transaction.annotation.Transactional; /** * 委外工序Service业务层处理 @@ -25,6 +29,9 @@ public class OutsourceProcessServiceImpl implements IOutsourceProcessService @Autowired private OutsourceProcessMapper outsourceProcessMapper; + + @Autowired + private RedisCache redisCache; /** * 查询委外工序 * @@ -55,55 +62,36 @@ public class OutsourceProcessServiceImpl implements IOutsourceProcessService return outsourceProcessMapper.selectOutsourceProcessList(outsourceProcess); } + + /** + * 自动生成委外工序编号 + * + */ + @Override + public String generateOutsourceProcessNo() + { + return redisCache.generateNo("OS"); + } + /** * 新增委外工序 * * @param outsourceProcess 委外工序 * @return 结果 */ + @Transactional(rollbackFor = Exception.class) @Override public int insertOutsourceProcess(OutsourceProcess outsourceProcess) { + String loginName = ShiroUtils.getLoginName(); + String outsourceProcessCode = redisCache.generateNo("WWGX"); + outsourceProcess.setOutsourceProcessCode(outsourceProcessCode); - //更改日期格式,以提高可读性 - SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); - String dataPart = df.format(new Date()); - - //移除日期中的分隔符以便于后续处理 - String prefix = "WWGX"+dataPart.replace("-",""); - - //查询数据库中最大的编号 - String maxCode = outsourceProcessMapper.findMaxRoundCode(prefix); - String newCode = generateNewCode(prefix,maxCode); - -// outsourceProcess.setOutsourceProcessId(); - outsourceProcess.setOutsourceProcessCode(newCode); - System.out.println(outsourceProcess.toString()); - + outsourceProcess.setCreateBy(loginName); outsourceProcess.setCreateTime(DateUtils.getNowDate()); return outsourceProcessMapper.insertOutsourceProcess(outsourceProcess); } - /** - *委外工序ID生产规则 - *系统自动生成,按照特定编码,编码暂用【ZCGX+年月日+001】, - *自增长,如:ZCGX20231111001,ZCGX20231111002 - * - */ - private String generateNewCode(String prefix, String maxCode) { - if (StringUtils.isEmpty(maxCode)){ - return prefix+"001"; - } - //解析并递增编号 - int sequence = Integer.parseInt(maxCode.substring(4)) + 1 ; -// //检查序列号是否溢出 -// if (sequence > 999){ -// throw new BusinessException("当日编号已达到最大值999,请检查或调整策略"); -// } - //格式化序列号,自动补零至三位 - DecimalFormat df = new DecimalFormat("000"); - return prefix + df.format(sequence); - } /** * 校验委外工序编号是否唯一 * diff --git a/ruoyi-admin/src/main/resources/templates/system/outsource_process/add.html b/ruoyi-admin/src/main/resources/templates/system/outsource_process/add.html index a8ef480d..40b45e3f 100644 --- a/ruoyi-admin/src/main/resources/templates/system/outsource_process/add.html +++ b/ruoyi-admin/src/main/resources/templates/system/outsource_process/add.html @@ -10,7 +10,7 @@
- +
@@ -35,27 +35,39 @@