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 @@