| | |
| | | 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){ |
| | | 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()); |
| | | BaseCodeIndexing codeIndexing = |
| | | get(sql, new SqlParameter().put("CODE_PREFIX", CODE_PREFIX), new BaseCodeIndexing()); |
| | | if (codeIndexing == null){ |
| | | codeIndexing = new BaseCodeIndexing(); |
| | | codeIndexing.setId(NumberGenerator.getLongSequenceNumber()); |
| | |
| | | prefix += days[2] < 9 ? "0" + Integer.valueOf(days[2]).toString() : days[2]; |
| | | return createCodeByPrefix(prefix,4); |
| | | } |
| | | |
| | | |
| | | } |