添加生成唯一单据编号功能
This commit is contained in:
@@ -61,6 +61,16 @@ public class BusinessConstants {
|
||||
* 批量插入sql时最大的数据条数
|
||||
* */
|
||||
public static final int BATCH_INSERT_MAX_NUMBER = 500;
|
||||
/**
|
||||
* sequence名称
|
||||
* */
|
||||
//sequence返回字符串的最小长度
|
||||
public static final Long SEQ_TO_STRING_MIN_LENGTH = 1000000L;
|
||||
//sequence长度小于基准长度时前追加基础值
|
||||
public static final String SEQ_TO_STRING_LESS_INSERT = "0";
|
||||
//单据编号
|
||||
public static final String DEPOT_NUMBER_SEQ = "depot_number_seq";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -77,7 +77,8 @@ public class DepotHeadController {
|
||||
BaseResponseInfo res = new BaseResponseInfo();
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
try {
|
||||
String number = depotHeadService.buildNumber(type, subType, beginTime, endTime);
|
||||
// String number = depotHeadService.buildNumber(type, subType, beginTime, endTime);
|
||||
String number = depotHeadService.buildOnlyNumber();
|
||||
map.put("DefaultNumber", number);
|
||||
res.code = 200;
|
||||
res.data = map;
|
||||
|
||||
@@ -107,4 +107,9 @@ public interface DepotHeadMapperEx {
|
||||
* 更新单据主表信息
|
||||
* */
|
||||
void updatedepotHead(DepotHead depotHead);
|
||||
|
||||
/**
|
||||
* 获得一个全局唯一的数作为订单号的追加
|
||||
* */
|
||||
Long getBuildOnlyNumber(@Param("seq_name") String seq_name);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.jsh.erp.service.supplier.SupplierService;
|
||||
import com.jsh.erp.service.user.UserService;
|
||||
import com.jsh.erp.utils.StringUtil;
|
||||
import com.jsh.erp.utils.Tools;
|
||||
import lombok.Synchronized;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
@@ -153,6 +154,26 @@ public class DepotHeadService {
|
||||
example.createCriteria().andIdIn(ids);
|
||||
return depotHeadMapper.updateByExampleSelective(depotHead, example);
|
||||
}
|
||||
/**
|
||||
* 创建一个唯一的序列号
|
||||
* */
|
||||
public String buildOnlyNumber(){
|
||||
Long buildOnlyNumber=null;
|
||||
synchronized (this){
|
||||
buildOnlyNumber= depotHeadMapperEx.getBuildOnlyNumber(BusinessConstants.DEPOT_NUMBER_SEQ);
|
||||
}
|
||||
if(buildOnlyNumber<BusinessConstants.SEQ_TO_STRING_MIN_LENGTH){
|
||||
StringBuffer sb=new StringBuffer(buildOnlyNumber.toString());
|
||||
int len=BusinessConstants.SEQ_TO_STRING_MIN_LENGTH.toString().length()-sb.length();
|
||||
for(int i=0;i<len;i++){
|
||||
sb.insert(0,BusinessConstants.SEQ_TO_STRING_LESS_INSERT);
|
||||
}
|
||||
return sb.toString();
|
||||
}else{
|
||||
return buildOnlyNumber.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String buildNumber(String type, String subType, String beginTime, String endTime) {
|
||||
String newNumber = "0001"; //新编号
|
||||
|
||||
Reference in New Issue
Block a user