| | |
| | | package com.consum.base.core; |
| | | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import com.consum.base.core.utils.SqlParameter; |
| | | import com.consum.model.po.BaseCodeIndexing; |
| | | import com.walker.infrastructure.utils.DateUtils; |
| | | import com.walker.infrastructure.utils.NumberGenerator; |
| | | import com.walker.jdbc.service.BaseServiceImpl; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | /** |
| | | * 编码统一生成服务 |
| | |
| | | @Transactional(propagation = Propagation.NOT_SUPPORTED) |
| | | public class CodeGeneratorService extends BaseServiceImpl { |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | String prefix = "RK"; |
| | | int[] days = DateUtils.getCurrentYearMonthDay(); |
| | | prefix += StringUtils.removeStart(Integer.valueOf(days[0]).toString(),"20"); |
| | | prefix += days[1] < 9 ? "0" + Integer.valueOf(days[1]).toString() : days[1]; |
| | | prefix += days[2] < 9 ? "0" + Integer.valueOf(days[2]).toString() : days[2]; |
| | | System.out.println(prefix); |
| | | } |
| | | |
| | | private String createCodeByPrefix(String prefix,int length){ |
| | | private String createCodeByPrefix(String prefix, int length) { |
| | | String CODE_PREFIX = prefix; |
| | | String sql = "SELECT * from BASE_CODE_INDEXING where CODE_PREFIX=:CODE_PREFIX"; |
| | | |
| | | BaseCodeIndexing codeIndexing = get(sql,new SqlParameter().put("CODE_PREFIX",CODE_PREFIX),new BaseCodeIndexing()); |
| | | if (codeIndexing == null){ |
| | | BaseCodeIndexing codeIndexing = |
| | | get(sql, new SqlParameter().put("CODE_PREFIX", CODE_PREFIX), new BaseCodeIndexing()); |
| | | if (codeIndexing == null) { |
| | | codeIndexing = new BaseCodeIndexing(); |
| | | codeIndexing.setId(NumberGenerator.getLongSequenceNumber()); |
| | | codeIndexing.setCodePrefix(CODE_PREFIX); |
| | | codeIndexing.setCodeIndex(1); |
| | | insert(codeIndexing); |
| | | } else { |
| | | codeIndexing.setCodeIndex(codeIndexing.getCodeIndex()+1); |
| | | codeIndexing.setCodeIndex(codeIndexing.getCodeIndex() + 1); |
| | | update(codeIndexing); |
| | | } |
| | | |
| | | String index = codeIndexing.getCodeIndex().toString(); |
| | | String intPrefix = "0"; |
| | | for (int i=1;i<(length-index.length());i++){ |
| | | for (int i = 1; i < (length - index.length()); i++) { |
| | | intPrefix += "0"; |
| | | } |
| | | return CODE_PREFIX+intPrefix+index; |
| | | return CODE_PREFIX + intPrefix + index; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return 仓库编码规则为:WH+四位数字连号(0001) |
| | | */ |
| | | public synchronized String createWarehouseCode() { |
| | | /* |
| | | /* |
| | | 1.SELECT CODE_INDEX from BASE_CODE_INDEXING where CODE_PREFIX=:CODE_PREFIX |
| | | CODE_PREFIX是"WH" |
| | | 如果获取不到,就从1开始,但需要补全前面的"0"返回 "0001";同时需要插入数据库 |
| | |
| | | 2.如果能够获取到,则将CODE_INDEX=CODE_INDEX+1后更新到数据库,补全前面的"0"返回 "0001" |
| | | */ |
| | | String CODE_PREFIX = CodeGeneratorEnum.Warehouse.getValue(); |
| | | return createCodeByPrefix(CODE_PREFIX,4); |
| | | return createCodeByPrefix(CODE_PREFIX, 4); |
| | | } |
| | | |
| | | /** |
| | |
| | | 2.如果能够获取到,则将CODE_INDEX=CODE_INDEX+1后更新到数据库,补全前面的"0"返回 "000001" |
| | | */ |
| | | String prefix = classify; |
| | | return createCodeByPrefix(prefix,6); |
| | | return createCodeByPrefix(prefix, 6); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | String prefix = codeGeneratorEnum.getValue(); |
| | | int[] days = DateUtils.getCurrentYearMonthDay(); |
| | | prefix += StringUtils.removeStart(Integer.valueOf(days[0]).toString(),"20"); |
| | | prefix += StringUtils.removeStart(Integer.valueOf(days[0]).toString(), "20"); |
| | | prefix += days[1] < 9 ? "0" + Integer.valueOf(days[1]).toString() : days[1]; |
| | | prefix += days[2] < 9 ? "0" + Integer.valueOf(days[2]).toString() : days[2]; |
| | | return createCodeByPrefix(prefix,4); |
| | | return createCodeByPrefix(prefix, 4); |
| | | } |
| | | |
| | | |
| | | } |