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 symbol, String patten) {
|
String date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
String date2 = LocalDate.now().format(DateTimeFormatter.ofPattern(patten));
|
int num;
|
if (tableName.equals("ins_order")) {
|
num = systemLogMapper.countRowsByNow2(tableName, LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))) + 1;
|
} else {
|
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 + (date2 == null ? date : date2) + symbol + nums;
|
}
|
|
//检验单委托单号的生成规则
|
public String giveCode2(String code, Long companyId, String laboratory, String tableName, String symbol, String patten) {
|
String date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
String date2 = LocalDate.now().format(DateTimeFormatter.ofPattern(patten));
|
int num;
|
num = systemLogMapper.countRowsByNow3(tableName, companyId, laboratory, 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 + (date2 == null ? date : date2) + symbol + nums;
|
}
|
|
}
|