李林
2024-03-19 825da6ff9fbab76ca933930e35575cc8b0e811bd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.yuanchu.mom.utils;
 
import com.yuanchu.mom.mapper.SystemLogMapper;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
 
@Component
public class GiveCode {
 
    @Resource
    private SystemLogMapper systemLogMapper;
 
    public String giveCode(String code, String tableName){
        String date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
        int num = systemLogMapper.countRowsByNow(tableName, LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))) + 1;
        String nums = num + "";
        if(nums.length() == 1) nums = "00" + num;
        else if(nums.length() == 2) nums = "0" + num;
        return code + date + "-" + nums;
    }
 
}