diff --git a/ruoyi-admin/src/main/java/com/ruoyi/aftersales/mapper/AftersalesComplaintNoticeMapper.java b/ruoyi-admin/src/main/java/com/ruoyi/aftersales/mapper/AftersalesComplaintNoticeMapper.java index 749d324b..303d2ac1 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/aftersales/mapper/AftersalesComplaintNoticeMapper.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/aftersales/mapper/AftersalesComplaintNoticeMapper.java @@ -85,11 +85,9 @@ public interface AftersalesComplaintNoticeMapper */ public int restoreAftersalesComplaintNoticeById(Long complaintNoticeId); - /** * 获取今天已经生成的最大序号 - * @param dateStr 日期字符串,格式为yyyyMMdd * @return 最大序号 */ - int getMaxSequenceForToday(@Param("dateStr") String dateStr); + String maxRoundCode(@Param("code") String code); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/aftersales/service/impl/AftersalesComplaintNoticeServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/aftersales/service/impl/AftersalesComplaintNoticeServiceImpl.java index 33359ed3..b07295de 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/aftersales/service/impl/AftersalesComplaintNoticeServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/aftersales/service/impl/AftersalesComplaintNoticeServiceImpl.java @@ -1,7 +1,10 @@ package com.ruoyi.aftersales.service.impl; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.format.DateTimeFormatter; +import java.util.Date; import java.util.List; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.ShiroUtils; @@ -68,9 +71,21 @@ public class AftersalesComplaintNoticeServiceImpl implements IAftersalesComplain public int insertAftersalesComplaintNotice(AftersalesComplaintNotice aftersalesComplaintNotice) { + + SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd"); + String code = "KS"+df.format(new Date()); + //模糊查询当前最大的编码 + String maxCode = aftersalesComplaintNoticeMapper.maxRoundCode(code); + String newCode = null; + if (StringUtils.isEmpty(maxCode)){ + newCode= code+"001"; + }else { + //切割字符串,取查到编号后三位 + String getMaxCode = maxCode.substring(11, 13); + newCode = code+getNum(getMaxCode); + } // 生成complaintNoticeCode - String complaintNoticeCode = generateComplainNoticeCode(); - aftersalesComplaintNotice.setComplaintNoticeCode(complaintNoticeCode); + aftersalesComplaintNotice.setComplaintNoticeCode(newCode); String loginName = ShiroUtils.getLoginName(); aftersalesComplaintNotice.setCreateBy(loginName); aftersalesComplaintNotice.setCreateTime(DateUtils.getNowDate()); @@ -154,15 +169,26 @@ public class AftersalesComplaintNoticeServiceImpl implements IAftersalesComplain } /** - * 按照特定编码生成complaintNoticeCode - * */ - private String generateComplainNoticeCode(){ - LocalDate currentDate = LocalDate.now(); - String formatDate = currentDate.format(DateTimeFormatter.ofPattern("yyyyMMdd")); - //查询今天已经生成的最大序号 - int maxSequenceForToday = aftersalesComplaintNoticeMapper.getMaxSequenceForToday(formatDate); - //序号自增如果是当天第一条,则序号为001 - String sequence =String.format("%03d",maxSequenceForToday+1); - return "KS"+formatDate+sequence; + *客诉单号生成规则: + *系统自动生成,按照特定编码,编码暂用【KS+年月日+001】, + *自增长,如:KS20231111001,KS20231111002 + * + * @param code 当前最大编码 + */ + public static String getNum(String code){ + String roundCode="001"; + if (code!=null && !code.isEmpty()){ + int intCode= Integer.parseInt(code)+1; + if (intCode <999){ + roundCode =String.format(String.valueOf(intCode)); + }else { + throw new RuntimeException("当日编号达到最大"); + } + } + + //编号前面补0 + DecimalFormat df = new DecimalFormat("000"); + String newCode = df.format(Integer.parseInt(roundCode)); + return newCode; } } diff --git a/ruoyi-admin/src/main/resources/mapper/aftersales/AftersalesComplaintNoticeMapper.xml b/ruoyi-admin/src/main/resources/mapper/aftersales/AftersalesComplaintNoticeMapper.xml index 3b31d3c8..cdc8b5c1 100644 --- a/ruoyi-admin/src/main/resources/mapper/aftersales/AftersalesComplaintNoticeMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/aftersales/AftersalesComplaintNoticeMapper.xml @@ -137,20 +137,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" update aftersales_complaint_notice set del_flag = '0' where complaint_notice_id = #{complaintNoticeId} - - - - - - - - - + SELECT max(complaint_notice_code) from aftersales_complaint_notice where complaint_notice_code like concat(#{code},'%') \ No newline at end of file