生成年份+5位流水码

本文介绍了如何在Java中生成包含年份和5位流水号的编码。首先讲解了编码位数的初始化,接着详细阐述了业务逻辑的实现过程,最后讨论了相关的SQL操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、初始化编码位数
private final static String FORMAT_CODE = "00000";
2、业务逻辑

public PmEmployeeInfoVo selectPmEmployeeInfoById(String id)
    {
        PmEmployeeInfoVo pmEmployeeInfoVo = new PmEmployeeInfoVo();
        PmEmployeeInfo pmEmployeeInfo = pmEmployeeInfoMapper.selectPmEmployeeInfoById(id);
        if (pmEmployeeInfo.getEmpCode() == null ||  "".equals(pmEmployeeInfo.getEmpCode())){
            String empCode = pmEmployeeInfoMapper.selectPmEmployeeInfoEmpCode();
            if(empCode == null){
                int count = 1; // 流水号
                DecimalFormat dft = new DecimalFormat(FORMAT_CODE);
                String code = dft.format(count); // 格式化为四位流水号 code: 0001
                Calendar calendar = Calendar.getInstance();
                int year = calendar.get(Calendar.YEAR);
                String str = String.valueOf(year).substring(2,4);
                String codeEnd = str + code;
                pmEmployeeInfo.setEmpCode(codeEnd);
            }else {
                String empCodeOne = pmEmployeeInfoMapper.selectPmEmployeeInfoEmpCode();
                int code = parseInt(empCodeOne)+1;
                String codeONe = String.valueOf(code);
                pmEmployeeInfo.setEmpCode(codeONe);
            }
        }

3、SQL

select MAX(emp_code) from pm_employee_info
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值