12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package com.jsh.erp.service.impl;
- import com.jsh.erp.constants.BusinessConstants;
- import com.jsh.erp.datasource.mappers.*;
- import com.jsh.erp.exception.JshException;
- import com.jsh.erp.service.SequenceService;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import javax.annotation.Resource;
- /**
- * Description
- *
- * @Author: longyong
- * @Date: 2021/3/16 16:33
- */
- @Service
- public class SequenceServiceImpl implements SequenceService {
- private Logger logger = LoggerFactory.getLogger(SequenceServiceImpl.class);
- @Resource
- private SequenceMapperEx sequenceMapperEx;
- /**
- * 创建一个唯一的序列号
- * */
- @Transactional(value = "transactionManager", rollbackFor = Exception.class)
- @Override
- public String buildOnlyNumber()throws Exception{
- Long buildOnlyNumber=null;
- synchronized (this){
- try{
- sequenceMapperEx.updateBuildOnlyNumber(BusinessConstants.DEPOT_NUMBER_SEQ); //编号+1
- buildOnlyNumber= sequenceMapperEx.getBuildOnlyNumber(BusinessConstants.DEPOT_NUMBER_SEQ);
- }catch(Exception e){
- JshException.writeFail(logger, e);
- }
- }
- 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();
- }
- }
- /**
- * 构建供应商编号
- */
- @Override
- public String buildSupplierNumber() {
- Long buildOnlyNumber = null;
- synchronized (this){
- sequenceMapperEx.updateBuildOnlyNumber(BusinessConstants.SUPPLIER_NUMBER_SEQ); //编号+1
- buildOnlyNumber = sequenceMapperEx.getBuildOnlyNumber(BusinessConstants.SUPPLIER_NUMBER_SEQ);
- }
- if(buildOnlyNumber < BusinessConstants.SUPPLIER_SEQ_TO_STRING_MIN_LENGTH){
- StringBuffer sb = new StringBuffer(buildOnlyNumber.toString());
- int len = BusinessConstants.SUPPLIER_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();
- }
- }
- }
|