From 60afdf733c42f4c5519af8dfdd24efae2dd5877b Mon Sep 17 00:00:00 2001 From: liuxiaoxu <1793812695@qq.com> Date: Mon, 13 May 2024 17:17:04 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=E5=93=81=E8=B4=A8=E7=AE=A1=E7=90=86:=20?= =?UTF-8?q?=E5=88=B6=E7=A8=8B=E6=A3=80=E9=AA=8C=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=88=B6=E7=A8=8B=E6=A3=80=E9=AA=8C=E5=88=B6=E7=A8=8B=E6=A3=80?= =?UTF-8?q?=E9=AA=8C=E5=8D=95=E5=8F=B7=E6=A0=B9=E6=8D=AE=E4=B8=80=E5=AE=9A?= =?UTF-8?q?=E8=A7=84=E5=88=99=E8=87=AA=E5=A2=9E=E5=8A=9F=E8=83=BD=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=B6=E7=A8=8B=E5=B7=A5=E5=BA=8F=E5=8D=95?= =?UTF-8?q?=E5=8F=B7=E6=9C=80=E5=A4=A7=E5=80=BC=E5=88=A4=E6=96=AD=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../QualityManufacturingCheckoutMapper.java | 6 +++ ...alityManufacturingCheckoutServiceImpl.java | 41 +++++++++++++++++++ ...ualityManufacturingProcessServiceImpl.java | 2 +- .../QualityManufacturingCheckoutMapper.xml | 4 ++ 4 files changed, 52 insertions(+), 1 deletion(-) 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