1、新增单据号生成自增工具类

This commit is contained in:
zhengyf 2025-08-25 16:07:00 +08:00
parent a43c03e681
commit 469a277797
7 changed files with 372 additions and 0 deletions

View File

@ -3,6 +3,8 @@ package com.hzya.frame.finance.bd;
import cn.hutool.core.lang.Assert;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hzya.frame.finance.claim.entity.ClaimVO;
import com.hzya.frame.finance.utils.ClaimBillCodeUtil;
import com.hzya.frame.mdm.mdmModule.dao.IMdmModuleDao;
import com.hzya.frame.mdm.mdmModule.entity.MdmModuleEntity;
import com.hzya.frame.mdm.mdmModule.service.IMdmModuleService;
@ -338,6 +340,44 @@ public class BdController extends DefaultController {
}
}
@Autowired
private ClaimBillCodeUtil claimBillCodeUtil;
/**
* 根据类型获取当前最大编码
*/
@RequestMapping(value = "/queryMaxBillCodeByType", method = RequestMethod.POST)
public JsonResultEntity queryMaxBillCodeByType (@RequestBody ClaimVO claimVO) {
try {
Assert.notNull(claimVO.getBillType(),"获取最大单据号时:单据类型不能为空");
String s = claimBillCodeUtil.queryMaxBillCodeByType(claimVO.getBillType());
return getSuccessMessageEntity("请求成功", s);
} catch (Exception e) {
e.printStackTrace();
return getFailureMessageEntity(e.getMessage());
}
}
/**
* 根据类型获取当前最大编码
*/
@RequestMapping(value = "/saveBillCodeByTypeAndSourceCode", method = RequestMethod.POST)
public JsonResultEntity saveBillCodeByTypeAndSourceCode (@RequestBody ClaimVO claimVO) {
try {
Assert.notNull(claimVO.getBillType(),"获取最大单据号时:单据类型不能为空");
Assert.notNull(claimVO.getSourceCode(),"获取最大单据号时:来源单据号不能为空");
String s = claimBillCodeUtil.saveBillCodeByTypeAndSourceCode(claimVO.getBillType(),claimVO.getSourceCode());
return getSuccessMessageEntity("请求成功", s);
} catch (Exception e) {
e.printStackTrace();
return getFailureMessageEntity(e.getMessage());
}
}
// /**
// *
// */

View File

@ -0,0 +1,12 @@
package com.hzya.frame.finance.claim.entity;
import lombok.Data;
/**
* Created by zydd on 2025-08-25 14:35
*/
@Data
public class ClaimVO {
private String billType;
private String sourceCode;
}

View File

@ -0,0 +1,15 @@
package com.hzya.frame.finance.conf.billcode.dao;
import com.hzya.frame.finance.conf.billcode.entity.FeConfBillcodeRuleEntity;
import com.hzya.frame.basedao.dao.IBaseDao;
/**
* 财资事项(finance_event)-配置-编码规则(fe_conf_billcode_rule: table)表数据库访问层
*
* @author zydd
* @since 2025-08-25 15:06:03
*/
public interface IFeConfBillcodeRuleDao extends IBaseDao<FeConfBillcodeRuleEntity, String> {
}

View File

@ -0,0 +1,17 @@
package com.hzya.frame.finance.conf.billcode.dao.impl;
import com.hzya.frame.finance.conf.billcode.entity.FeConfBillcodeRuleEntity;
import com.hzya.frame.finance.conf.billcode.dao.IFeConfBillcodeRuleDao;
import org.springframework.stereotype.Repository;
import com.hzya.frame.basedao.dao.MybatisGenericDao;
/**
* 财资事项(finance_event)-配置-编码规则(FeConfBillcodeRule)表数据库访问层
*
* @author zydd
* @since 2025-08-25 15:06:03
*/
@Repository
public class FeConfBillcodeRuleDaoImpl extends MybatisGenericDao<FeConfBillcodeRuleEntity, String> implements IFeConfBillcodeRuleDao{
}

View File

@ -0,0 +1,28 @@
package com.hzya.frame.finance.conf.billcode.entity;
import com.hzya.frame.web.entity.BaseEntity;
import lombok.Data;
/**
* 财资事项(finance_event)-配置-编码规则(FeConfBillcodeRule)实体类
*
* @author zydd
* @since 2025-08-25 15:06:03
*/
@Data
public class FeConfBillcodeRuleEntity extends BaseEntity {
/** 年 */
private String year;
/** 月 */
private String month;
/** 日 */
private String day;
/** 单据类型 */
private String type;
/** 当前编码 */
private String currentcode;
/** 来源单号 */
private String sourcecode;
}

View File

@ -0,0 +1,183 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hzya.frame.finance.conf.billcode.dao.impl.FeConfBillcodeRuleDaoImpl">
<resultMap id="get-FeConfBillcodeRuleEntity-result"
type="com.hzya.frame.finance.conf.billcode.entity.FeConfBillcodeRuleEntity">
<result property="id" column="id" jdbcType="INTEGER"/>
<result property="year" column="year" jdbcType="VARCHAR"/>
<result property="month" column="month" jdbcType="VARCHAR"/>
<result property="day" column="day" jdbcType="VARCHAR"/>
<result property="type" column="type" jdbcType="VARCHAR"/>
<result property="currentcode" column="currentcode" jdbcType="VARCHAR"/>
<result property="sourcecode" column="sourcecode" jdbcType="VARCHAR"/>
</resultMap>
<!-- 查询的字段-->
<sql id="FeConfBillcodeRuleEntity_Base_Column_List">
id
,year
,month
,day
,type
,currentcode
,sourcecode
</sql>
<!-- 查询 采用==查询 -->
<select id="entity_list_base" resultMap="get-FeConfBillcodeRuleEntity-result"
parameterType="com.hzya.frame.finance.conf.billcode.entity.FeConfBillcodeRuleEntity">
select
<include refid="FeConfBillcodeRuleEntity_Base_Column_List"/>
from fe_conf_billcode_rule
<trim prefix="where" prefixOverrides="and">
<if test="id != null">and id = #{id}</if>
<if test="year != null and year != ''">and year = #{year}</if>
<if test="month != null and month != ''">and month = #{month}</if>
<if test="day != null and day != ''">and day = #{day}</if>
<if test="type != null and type != ''">and type = #{type}</if>
<if test="currentcode != null and currentcode != ''">and currentcode = #{currentcode}</if>
<if test="sourcecode != null and sourcecode != ''">and sourcecode = #{sourcecode}</if>
</trim>
</select>
<!-- 查询符合条件的数量 -->
<select id="entity_count" resultType="Integer"
parameterType="com.hzya.frame.finance.conf.billcode.entity.FeConfBillcodeRuleEntity">
select count(1) from fe_conf_billcode_rule
<trim prefix="where" prefixOverrides="and">
<if test="id != null">and id = #{id}</if>
<if test="year != null and year != ''">and year = #{year}</if>
<if test="month != null and month != ''">and month = #{month}</if>
<if test="day != null and day != ''">and day = #{day}</if>
<if test="type != null and type != ''">and type = #{type}</if>
<if test="currentcode != null and currentcode != ''">and currentcode = #{currentcode}</if>
<if test="sourcecode != null and sourcecode != ''">and sourcecode = #{sourcecode}</if>
</trim>
</select>
<!-- 分页查询列表 采用like格式 -->
<select id="entity_list_like" resultMap="get-FeConfBillcodeRuleEntity-result"
parameterType="com.hzya.frame.finance.conf.billcode.entity.FeConfBillcodeRuleEntity">
select
<include refid="FeConfBillcodeRuleEntity_Base_Column_List"/>
from fe_conf_billcode_rule
<trim prefix="where" prefixOverrides="and">
<if test="id != null">and id like concat('%',#{id},'%')</if>
<if test="year != null and year != ''">and year like concat('%',#{year},'%')</if>
<if test="month != null and month != ''">and month like concat('%',#{month},'%')</if>
<if test="day != null and day != ''">and day like concat('%',#{day},'%')</if>
<if test="type != null and type != ''">and type like concat('%',#{type},'%')</if>
<if test="currentcode != null and currentcode != ''">and currentcode like concat('%',#{currentcode},'%')
</if>
<if test="sourcecode != null and sourcecode != ''">and sourcecode like concat('%',#{sourcecode},'%')</if>
</trim>
</select>
<!-- 查询列表 字段采用or格式 -->
<select id="FeConfBillcodeRuleentity_list_or" resultMap="get-FeConfBillcodeRuleEntity-result"
parameterType="com.hzya.frame.finance.conf.billcode.entity.FeConfBillcodeRuleEntity">
select
<include refid="FeConfBillcodeRuleEntity_Base_Column_List"/>
from fe_conf_billcode_rule
<trim prefix="where" prefixOverrides="and">
<if test="id != null">or id = #{id}</if>
<if test="year != null and year != ''">or year = #{year}</if>
<if test="month != null and month != ''">or month = #{month}</if>
<if test="day != null and day != ''">or day = #{day}</if>
<if test="type != null and type != ''">or type = #{type}</if>
<if test="currentcode != null and currentcode != ''">or currentcode = #{currentcode}</if>
<if test="sourcecode != null and sourcecode != ''">or sourcecode = #{sourcecode}</if>
</trim>
</select>
<!--新增所有列-->
<insert id="entity_insert" parameterType="com.hzya.frame.finance.conf.billcode.entity.FeConfBillcodeRuleEntity"
keyProperty="id" useGeneratedKeys="true">
insert into fe_conf_billcode_rule(
<trim suffix="" suffixOverrides=",">
<if test="id != null">id ,</if>
<if test="year != null and year != ''">year ,</if>
<if test="month != null and month != ''">month ,</if>
<if test="day != null and day != ''">day ,</if>
<if test="type != null and type != ''">type ,</if>
<if test="currentcode != null and currentcode != ''">currentcode ,</if>
<if test="sourcecode != null and sourcecode != ''">sourcecode ,</if>
</trim>
)values(
<trim suffix="" suffixOverrides=",">
<if test="id != null">#{id} ,</if>
<if test="year != null and year != ''">#{year} ,</if>
<if test="month != null and month != ''">#{month} ,</if>
<if test="day != null and day != ''">#{day} ,</if>
<if test="type != null and type != ''">#{type} ,</if>
<if test="currentcode != null and currentcode != ''">#{currentcode} ,</if>
<if test="sourcecode != null and sourcecode != ''">#{sourcecode} ,</if>
</trim>
)
</insert>
<!-- 批量新增 -->
<insert id="entityInsertBatch" keyProperty="id" useGeneratedKeys="true">
insert into fe_conf_billcode_rule(year, month, day, type, currentcode, sourcecode)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.year},#{entity.month},#{entity.day},#{entity.type},#{entity.currentcode},#{entity.sourcecode})
</foreach>
</insert>
<!-- 批量新增或者修改-->
<insert id="entityInsertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
insert into fe_conf_billcode_rule(year, month, day, type, currentcode, sourcecode)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.year},#{entity.month},#{entity.day},#{entity.type},#{entity.currentcode},#{entity.sourcecode})
</foreach>
on duplicate key update
year = values(year),
month = values(month),
day = values(day),
type = values(type),
currentcode = values(currentcode),
sourcecode = values(sourcecode)
</insert>
<!--通过主键修改方法-->
<update id="entity_update" parameterType="com.hzya.frame.finance.conf.billcode.entity.FeConfBillcodeRuleEntity">
update fe_conf_billcode_rule set
<trim suffix="" suffixOverrides=",">
<if test="year != null and year != ''">year = #{year},</if>
<if test="month != null and month != ''">month = #{month},</if>
<if test="day != null and day != ''">day = #{day},</if>
<if test="type != null and type != ''">type = #{type},</if>
<if test="currentcode != null and currentcode != ''">currentcode = #{currentcode},</if>
<if test="sourcecode != null and sourcecode != ''">sourcecode = #{sourcecode},</if>
</trim>
where id = #{id}
</update>
<!-- 逻辑删除 -->
<update id="entity_logicDelete"
parameterType="com.hzya.frame.finance.conf.billcode.entity.FeConfBillcodeRuleEntity">
update fe_conf_billcode_rule
set modify_time = #{modify_time},
modify_user_id = #{modify_user_id}
where id = #{id}
</update>
<!-- 多条件逻辑删除 -->
<update id="entity_logicDelete_Multi_Condition"
parameterType="com.hzya.frame.finance.conf.billcode.entity.FeConfBillcodeRuleEntity">
update fe_conf_billcode_rule set sts= 'N' ,modify_time = #{modify_time},modify_user_id = #{modify_user_id}
<trim prefix="where" prefixOverrides="and">
<if test="id != null">and id = #{id}</if>
<if test="year != null and year != ''">and year = #{year}</if>
<if test="month != null and month != ''">and month = #{month}</if>
<if test="day != null and day != ''">and day = #{day}</if>
<if test="type != null and type != ''">and type = #{type}</if>
<if test="currentcode != null and currentcode != ''">and currentcode = #{currentcode}</if>
<if test="sourcecode != null and sourcecode != ''">and sourcecode = #{sourcecode}</if>
</trim>
</update>
<!--通过主键删除-->
<delete id="entity_delete">
delete
from fe_conf_billcode_rule
where id = #{id}
</delete>
</mapper>

View File

@ -0,0 +1,77 @@
package com.hzya.frame.finance.utils;
import cn.hutool.core.lang.Assert;
import com.hzya.frame.finance.conf.billcode.dao.IFeConfBillcodeRuleDao;
import com.hzya.frame.finance.conf.billcode.entity.FeConfBillcodeRuleEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.time.LocalDate;
import java.time.Month;
import java.util.List;
/**
* Created by zydd on 2025-08-25 14:52
* 认领单 单号 工具类
*/
@Repository
public class ClaimBillCodeUtil {
@Autowired
private IFeConfBillcodeRuleDao billcodeRuleDao;
public String queryMaxBillCodeByType(String billType){
Assert.notNull(billType,"获取最大单据号时:单据类型不能为空");
//获取当前年月日
LocalDate now = LocalDate.now();
String year = now.toString().substring(0, 4);
String month = now.toString().substring(5, 7);
String day = now.toString().substring(8, 10);
FeConfBillcodeRuleEntity feConfBillcodeRuleEntity = new FeConfBillcodeRuleEntity();
feConfBillcodeRuleEntity.setType(billType);
feConfBillcodeRuleEntity.setYear(year);
feConfBillcodeRuleEntity.setMonth(month);
feConfBillcodeRuleEntity.setDay(day);
List<FeConfBillcodeRuleEntity> query = billcodeRuleDao.query(feConfBillcodeRuleEntity);
if(query.size()==0){
return "000000";
}
int size = query.size();
String result = String.format("%06d", size);
return result;
}
public String saveBillCodeByTypeAndSourceCode(String billType,String sourceCode){
//获取当前年月日
LocalDate now = LocalDate.now();
String year = now.toString().substring(0, 4);
String month = now.toString().substring(5, 7);
String day = now.toString().substring(8, 10);
FeConfBillcodeRuleEntity feConfBillcodeRuleEntity = new FeConfBillcodeRuleEntity();
feConfBillcodeRuleEntity.setType(billType);
feConfBillcodeRuleEntity.setYear(year);
feConfBillcodeRuleEntity.setMonth(month);
feConfBillcodeRuleEntity.setDay(day);
List<FeConfBillcodeRuleEntity> query = billcodeRuleDao.query(feConfBillcodeRuleEntity);
if(query.size()==0){
//新增单号
String billCode= billType+year+month+day+"000001";
feConfBillcodeRuleEntity.setSourcecode(sourceCode);
feConfBillcodeRuleEntity.setCurrentcode("000001");
billcodeRuleDao.save(feConfBillcodeRuleEntity);
return billCode;
}
//获取个数+1
int size = query.size();
size+=1;
String result = String.format("%06d", size);
System.out.println(result);
String billCode= billType+year+month+day+result;
feConfBillcodeRuleEntity.setCurrentcode(result);
feConfBillcodeRuleEntity.setSourcecode(sourceCode);
billcodeRuleDao.save(feConfBillcodeRuleEntity);
return billCode;
}
}