diff --git a/ruoyi-admin/src/main/java/com/ruoyi/quality/mapper/QualityManufacturingCheckoutMapper.java b/ruoyi-admin/src/main/java/com/ruoyi/quality/mapper/QualityManufacturingCheckoutMapper.java index 030d9eea..57ce33f6 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/quality/mapper/QualityManufacturingCheckoutMapper.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/quality/mapper/QualityManufacturingCheckoutMapper.java @@ -2,6 +2,7 @@ package com.ruoyi.quality.mapper; import java.util.List; import com.ruoyi.quality.domain.QualityManufacturingCheckout; +import org.apache.ibatis.annotations.Param; /** * 品质管理制程检验Mapper接口 @@ -74,4 +75,9 @@ public interface QualityManufacturingCheckoutMapper * @return 结果 */ public int restoreQualityManufacturingCheckoutById(Long manufacturingCheckoutId); + + /* + * 查询数据库中当前最大的编号 + * */ + public String findMaxRoundCode(@Param("prefix") String prefix); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/quality/service/impl/QualityManufacturingCheckoutServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/quality/service/impl/QualityManufacturingCheckoutServiceImpl.java index 3e0bae32..38ca14e7 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/quality/service/impl/QualityManufacturingCheckoutServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/quality/service/impl/QualityManufacturingCheckoutServiceImpl.java @@ -1,14 +1,21 @@ package com.ruoyi.quality.service.impl; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.List; + +import com.ruoyi.common.exception.BusinessException; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.ShiroUtils; +import com.ruoyi.common.utils.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.quality.mapper.QualityManufacturingCheckoutMapper; import com.ruoyi.quality.domain.QualityManufacturingCheckout; import com.ruoyi.quality.service.IQualityManufacturingCheckoutService; import com.ruoyi.common.core.text.Convert; +import org.springframework.transaction.annotation.Transactional; /** * 品质管理制程检验Service业务层处理 @@ -52,15 +59,49 @@ public class QualityManufacturingCheckoutServiceImpl implements IQualityManufact * @param qualityManufacturingCheckout 品质管理制程检验 * @return 结果 */ + @Transactional @Override public int insertQualityManufacturingCheckout(QualityManufacturingCheckout qualityManufacturingCheckout) { + //格式化日期格式 + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); + String formatDate = df.format(new Date()); + //去除多余的 - 时间格式转换为yyyyMMdd + String prefix = "ZCJY" +formatDate.replace("-", ""); + + + //查询数据库中当前最大的编号 + String maxCode = qualityManufacturingCheckoutMapper.findMaxRoundCode(prefix); + String newCode = generateNewCode(prefix, maxCode); + + qualityManufacturingCheckout.setManufacturingCheckoutCode(newCode); String loginName = ShiroUtils.getLoginName(); qualityManufacturingCheckout.setCreateBy(loginName); qualityManufacturingCheckout.setCreateTime(DateUtils.getNowDate()); return qualityManufacturingCheckoutMapper.insertQualityManufacturingCheckout(qualityManufacturingCheckout); } + /** + *制程检验单号生产规则 + *系统自动生成,按照特定编码,编码暂用【ZCJY+年月日+001】, + *自增长,如:ZCJY20231111001,ZCJY20231111002 + * + */ + 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/java/com/ruoyi/quality/service/impl/QualityManufacturingProcessServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/quality/service/impl/QualityManufacturingProcessServiceImpl.java index c6607d83..401dcb49 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/quality/service/impl/QualityManufacturingProcessServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/quality/service/impl/QualityManufacturingProcessServiceImpl.java @@ -102,7 +102,7 @@ public class QualityManufacturingProcessServiceImpl implements IQualityManufactu int sequence = Integer.parseInt(maxCode.substring(4)) + 1 ; //检查序列号是否溢出 - if (sequence>9999){ + if (sequence > 999){ throw new BusinessException("当日编号已达到最大值999,请检查或调整策略"); } diff --git a/ruoyi-admin/src/main/resources/mapper/quality/QualityManufacturingCheckoutMapper.xml b/ruoyi-admin/src/main/resources/mapper/quality/QualityManufacturingCheckoutMapper.xml index 9c073c77..d078829d 100644 --- a/ruoyi-admin/src/main/resources/mapper/quality/QualityManufacturingCheckoutMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/quality/QualityManufacturingCheckoutMapper.xml @@ -127,4 +127,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" update quality_manufacturing_checkout set del_flag = '0' where manufacturing_checkout_id = #{manufacturingCheckoutId} + + \ No newline at end of file