14 changed files with 286 additions and 27 deletions
@ -0,0 +1,54 @@
|
||||
package org.springblade.common.constant; |
||||
|
||||
/** |
||||
* 编码摘要映射类型 |
||||
*/ |
||||
public enum CodeDesEnum { |
||||
|
||||
WAYBILL(1,"YD"), |
||||
ORDER(2,"OD"), |
||||
PSCC(3,"PSCC"), |
||||
PSJH(4,"PSJJ"), |
||||
LOCATION(5,"KW"), |
||||
TRAYS(6,"TP"), |
||||
PACKAGE(7,"BJ"), |
||||
SHELF(8,"HJ"), |
||||
PSKH(9,"PSKH"); |
||||
|
||||
|
||||
private Integer codeNum; |
||||
private String typeMes; |
||||
|
||||
CodeDesEnum(Integer codeNum, String typeMes) { |
||||
this.codeNum = codeNum; |
||||
this.typeMes = typeMes; |
||||
} |
||||
|
||||
|
||||
public Integer getCodeNum() { |
||||
return codeNum; |
||||
} |
||||
|
||||
public void setCodeNum(Integer codeNum) { |
||||
this.codeNum = codeNum; |
||||
} |
||||
|
||||
public String getTypeMes() { |
||||
return typeMes; |
||||
} |
||||
|
||||
public void setTypeMes(String typeMes) { |
||||
this.typeMes = typeMes; |
||||
} |
||||
|
||||
public static String getMes(Integer codeNum){ |
||||
CodeDesEnum[] values = CodeDesEnum.values(); |
||||
for(CodeDesEnum codeDesEnum:values){ |
||||
if(codeDesEnum.getCodeNum().equals(codeNum)){ |
||||
return codeDesEnum.getTypeMes(); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,15 @@
|
||||
package org.springblade.common.constant; |
||||
|
||||
public class CodeNumConstant { |
||||
|
||||
public final static int WAYBILL = 1; |
||||
public final static int ORDER = 2; |
||||
public final static int PSCC = 3; |
||||
public final static int PSJH = 4; |
||||
public final static int LOCATION = 5; |
||||
public final static int TRAYS = 6; |
||||
public final static int PACKAGE = 7; |
||||
public final static int SHELF = 8; |
||||
public final static int PSKH = 9; |
||||
|
||||
} |
@ -0,0 +1,6 @@
|
||||
package org.springblade.common.constant; |
||||
|
||||
public class RedisKeyConstant { |
||||
|
||||
|
||||
} |
@ -0,0 +1,18 @@
|
||||
package com.logpm.basicdata.feign; |
||||
|
||||
import org.springblade.common.constant.ModuleNameConstant; |
||||
import org.springframework.cloud.openfeign.FeignClient; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
|
||||
@FeignClient( |
||||
value = ModuleNameConstant.APPLICATION_BASICDATA_NAME+"-zhy" |
||||
) |
||||
public interface IBasicdataCodeClient { |
||||
|
||||
String API_PREFIX = "/client"; |
||||
|
||||
@GetMapping(API_PREFIX+"/getCodeByType") |
||||
String getCodeByType(@RequestParam Integer type,@RequestParam String warehouseCode); |
||||
|
||||
} |
@ -0,0 +1,19 @@
|
||||
package com.logpm.basicdata.feign; |
||||
|
||||
import com.logpm.basicdata.service.IBasicdataCodeService; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
import springfox.documentation.annotations.ApiIgnore; |
||||
|
||||
@ApiIgnore() |
||||
@RestController |
||||
@AllArgsConstructor |
||||
public class BasicdataCodeClient implements IBasicdataCodeClient { |
||||
|
||||
private final IBasicdataCodeService basicdataCodeService; |
||||
|
||||
@Override |
||||
public String getCodeByType(Integer type,String warehouseCode) { |
||||
return basicdataCodeService.getCodeByType(type,warehouseCode); |
||||
} |
||||
} |
@ -0,0 +1,7 @@
|
||||
package com.logpm.basicdata.service; |
||||
|
||||
public interface IBasicdataCodeService { |
||||
|
||||
String getCodeByType(Integer type,String warehouseCode); |
||||
|
||||
} |
@ -0,0 +1,105 @@
|
||||
package com.logpm.basicdata.service.impl; |
||||
|
||||
import com.logpm.basic.feign.IBasicTenantCodeClient; |
||||
import com.logpm.basicdata.service.IBasicdataCodeService; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.extern.log4j.Log4j2; |
||||
import org.springblade.common.constant.CodeDesEnum; |
||||
import org.springblade.common.constant.CodeNumConstant; |
||||
import org.springblade.common.utils.CommonUtil; |
||||
import org.springblade.core.redis.cache.BladeRedis; |
||||
import org.springblade.core.secure.utils.AuthUtil; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.Date; |
||||
|
||||
@Service |
||||
@AllArgsConstructor |
||||
@Log4j2 |
||||
public class BasicdataCodeServiceImpl implements IBasicdataCodeService { |
||||
|
||||
private final BladeRedis bladeRedis; |
||||
|
||||
private final IBasicTenantCodeClient basicTenantCodeClient; |
||||
|
||||
// private final IWarehouseClient warehouseClient;
|
||||
|
||||
/** |
||||
* 根据类型生成编号 |
||||
* @param type |
||||
* @return |
||||
*/ |
||||
@Override |
||||
public String getCodeByType(Integer type,String warehouseCode) { |
||||
String code = null; |
||||
switch (type){ |
||||
// case CodeNumConstant.WAYBILL:
|
||||
// break;
|
||||
// case CodeNumConstant.ORDER:
|
||||
// break;
|
||||
case CodeNumConstant.PSCC: |
||||
code = generateDeliveryTrainNumber(type,warehouseCode); |
||||
break; |
||||
// case CodeNumConstant.PSJH:
|
||||
// break;
|
||||
// case CodeNumConstant.LOCATION:
|
||||
// break;
|
||||
// case CodeNumConstant.TRAYS:
|
||||
// break;
|
||||
// case CodeNumConstant.PACKAGE:
|
||||
// break;
|
||||
// case CodeNumConstant.SHELF:
|
||||
// break;
|
||||
case CodeNumConstant.PSKH: |
||||
code = generateDeliveryCustomOrder(type,warehouseCode); |
||||
break; |
||||
default: |
||||
log.info("##################getCodeByType: 暂不支持的编码类型 type={}", CodeDesEnum.getMes(type)); |
||||
} |
||||
return code; |
||||
} |
||||
|
||||
private String generateDeliveryCustomOrder(Integer type, String warehouseCode) { |
||||
//查询租户编码
|
||||
String des = CodeDesEnum.getMes(type);//摘要
|
||||
String tenantId = AuthUtil.getTenantId();//租户id
|
||||
// String tenantId = "627683";//租户号
|
||||
|
||||
String tenantCode = basicTenantCodeClient.shelfCode(tenantId, String.valueOf(type));//租户编码
|
||||
//获得年月日短字符串
|
||||
String dateShort = CommonUtil.dateToStringShort(new Date()); |
||||
String key = tenantId + ":" + warehouseCode + ":" + des+":"+dateShort; |
||||
//获得序号
|
||||
Long incr = bladeRedis.incr(key); |
||||
if(1 == incr){ |
||||
//如果为1就是刚刚才建立,给他一个过期时间
|
||||
bladeRedis.expireAt(key,CommonUtil.getDayEnd()); |
||||
} |
||||
|
||||
return tenantCode+warehouseCode+dateShort+CommonUtil.geFourNumber(incr); |
||||
} |
||||
|
||||
/** |
||||
* 生成配送车次号编码 |
||||
* @param type |
||||
*/ |
||||
private String generateDeliveryTrainNumber(Integer type,String warehouseCode) { |
||||
String des = CodeDesEnum.getMes(type);//摘要
|
||||
String tenantId = AuthUtil.getTenantId();//租户号
|
||||
// String tenantId = "627683";//租户号
|
||||
|
||||
//获得年月日短字符串
|
||||
String dateShort = CommonUtil.dateToStringShort(new Date()); |
||||
|
||||
//redis的key
|
||||
String key = tenantId + ":" + warehouseCode + ":" + des+":"+dateShort; |
||||
//获得序号
|
||||
Long incr = bladeRedis.incr(key); |
||||
if(1 == incr){ |
||||
//如果为1就是刚刚才建立,给他一个过期时间
|
||||
bladeRedis.expireAt(key,CommonUtil.getDayEnd()); |
||||
} |
||||
|
||||
return warehouseCode + des + dateShort + CommonUtil.geFourNumber(incr); |
||||
} |
||||
} |
@ -1,29 +1,17 @@
|
||||
package com.logpm.factory; |
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||
import com.logpm.factory.mt.service.impl.MtFactoryDataServiceImpl; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.api.extension.ExtendWith; |
||||
import org.springblade.core.test.BladeBootTest; |
||||
import org.springblade.core.test.BladeSpringExtension; |
||||
import org.springblade.core.tool.utils.StringUtil; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
||||
import java.util.List; |
||||
import java.util.Random; |
||||
|
||||
//@ExtendWith(BladeSpringExtension.class)
|
||||
//@BladeBootTest(appName = "logpm-factory", enableLoader = true)
|
||||
public class TestService { |
||||
|
||||
@Autowired |
||||
private MtFactoryDataServiceImpl mtFactoryDataService; |
||||
@Test |
||||
public void contextLoads() { |
||||
|
||||
String tolk =mtFactoryDataService.getMtToken(); |
||||
System.out.println(tolk); |
||||
|
||||
} |
||||
// @Autowired
|
||||
// private MtFactoryDataServiceImpl mtFactoryDataService;
|
||||
// @Test
|
||||
// public void contextLoads() {
|
||||
//
|
||||
// String tolk =mtFactoryDataService.getMtToken();
|
||||
// System.out.println(tolk);
|
||||
//
|
||||
// }
|
||||
|
||||
} |
||||
|
Loading…
Reference in new issue