diff --git a/blade-service-api/logpm-basicdata-api/src/main/java/com/logpm/basicdata/entity/BasicdataCodeRecordEntity.java b/blade-service-api/logpm-basicdata-api/src/main/java/com/logpm/basicdata/entity/BasicdataCodeRecordEntity.java new file mode 100644 index 000000000..e46a15b4c --- /dev/null +++ b/blade-service-api/logpm-basicdata-api/src/main/java/com/logpm/basicdata/entity/BasicdataCodeRecordEntity.java @@ -0,0 +1,23 @@ +package com.logpm.basicdata.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.tenant.mp.TenantEntity; + +@Data +@TableName("logpm_basicdata_code_record") +@ApiModel(value = "生成码值表", description = "生成码值表") +@EqualsAndHashCode(callSuper = true) +public class BasicdataCodeRecordEntity extends TenantEntity { + + private Integer codeType; + private Long warehouseId; + private String warehouseName; + private String warehouseCode; + private String year; + private String month; + private Integer num; + +} diff --git a/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/mapper/BasicdataCodeRecordMapper.java b/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/mapper/BasicdataCodeRecordMapper.java new file mode 100644 index 000000000..a8995ba32 --- /dev/null +++ b/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/mapper/BasicdataCodeRecordMapper.java @@ -0,0 +1,9 @@ +package com.logpm.basicdata.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.logpm.basicdata.entity.BasicdataCodeRecordEntity; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BasicdataCodeRecordMapper extends BaseMapper { +} diff --git a/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/mapper/BasicdataCodeRecordMapper.xml b/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/mapper/BasicdataCodeRecordMapper.xml new file mode 100644 index 000000000..7fc06e2f6 --- /dev/null +++ b/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/mapper/BasicdataCodeRecordMapper.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/service/IBasicdataCodeRecordService.java b/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/service/IBasicdataCodeRecordService.java new file mode 100644 index 000000000..3cbf815e6 --- /dev/null +++ b/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/service/IBasicdataCodeRecordService.java @@ -0,0 +1,8 @@ +package com.logpm.basicdata.service; + +import com.logpm.basicdata.entity.BasicdataCodeRecordEntity; +import org.springblade.core.mp.base.BaseService; + +public interface IBasicdataCodeRecordService extends BaseService { + BasicdataCodeRecordEntity findEntityByCodeTypeAndWarehouseCodeAndYearAndMonth(Integer type, String warehouseCode, String year, String month); +} diff --git a/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/service/impl/BasicdataCodeRecordServiceImpl.java b/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/service/impl/BasicdataCodeRecordServiceImpl.java new file mode 100644 index 000000000..86d074435 --- /dev/null +++ b/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/service/impl/BasicdataCodeRecordServiceImpl.java @@ -0,0 +1,15 @@ +package com.logpm.basicdata.service.impl; + +import com.logpm.basicdata.entity.BasicdataCodeRecordEntity; +import com.logpm.basicdata.mapper.BasicdataCodeRecordMapper; +import com.logpm.basicdata.service.IBasicdataCodeRecordService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +@AllArgsConstructor +public class BasicdataCodeRecordServiceImpl extends BaseServiceImpl implements IBasicdataCodeRecordService { +} diff --git a/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/service/impl/BasicdataCodeServiceImpl.java b/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/service/impl/BasicdataCodeServiceImpl.java index f5389a9e4..ab35a8cbe 100644 --- a/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/service/impl/BasicdataCodeServiceImpl.java +++ b/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/service/impl/BasicdataCodeServiceImpl.java @@ -2,10 +2,12 @@ package com.logpm.basicdata.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.logpm.basic.feign.IBasicTenantCodeClient; +import com.logpm.basicdata.entity.BasicdataCodeRecordEntity; import com.logpm.basicdata.entity.BasicdataTrayEntity; import com.logpm.basicdata.entity.BasicdataWarehouseEntity; import com.logpm.basicdata.feign.IBasicdataWarehouseClient; import com.logpm.basicdata.mapper.BasicdataTrayMapper; +import com.logpm.basicdata.service.IBasicdataCodeRecordService; import com.logpm.basicdata.service.IBasicdataCodeService; import com.logpm.basicdata.service.IBasicdataWarehouseService; import lombok.AllArgsConstructor; @@ -18,6 +20,7 @@ import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.utils.StringUtil; import org.springframework.stereotype.Service; +import java.util.Calendar; import java.util.Date; import java.util.Objects; @@ -36,6 +39,8 @@ public class BasicdataCodeServiceImpl implements IBasicdataCodeService { private final BasicdataTrayMapper basicdataTrayMapper; + private final IBasicdataCodeRecordService basicdataCodeRecordService; + /** * 根据类型生成编号 * @param type @@ -285,17 +290,37 @@ public class BasicdataCodeServiceImpl implements IBasicdataCodeService { log.warn("############getWayBillNo: 仓库编码为空warehouseCode={}",warehouseCode); return null; } - //运单 仓库拼音+年月+(仓库当月数量+1) - //获得年月日短字符串 - String dateShort = CommonUtil.dateToStringShortYM(new Date()); - String key = warehouseCode + ":" +dateShort; - //获得序号 - Long incr = bladeRedis.incr(key); - if(1 == incr){ - //如果为1就是刚刚才建立,给他一个过期时间 - bladeRedis.expireAt(key,CommonUtil.getMonthDayEnd()); + + BasicdataWarehouseEntity basicdataWarehouseEntity = basicdataWarehouseService.getWarehouseEntityByWarehouseCode(warehouseCode); + if(Objects.isNull(basicdataWarehouseEntity)){ + log.warn("############getWayBillNo: 仓库信息不存在 warehouseCode={}",warehouseCode); + return null; + } + + Calendar calendar = Calendar.getInstance(); + //获取年份 + int year = calendar.get(Calendar.YEAR); + + // 获取月份(注意月份从0开始计数) + int month = calendar.get(Calendar.MONTH) + 1; + + + BasicdataCodeRecordEntity basicdataCodeRecordEntity = basicdataCodeRecordService.findEntityByCodeTypeAndWarehouseCodeAndYearAndMonth(type,warehouseCode,year+"",month+""); + + if(Objects.isNull(basicdataCodeRecordEntity)){ + basicdataCodeRecordEntity = new BasicdataCodeRecordEntity(); + basicdataCodeRecordEntity.setCodeType(type); + basicdataCodeRecordEntity.setWarehouseId(basicdataWarehouseEntity.getId()); + basicdataCodeRecordEntity.setWarehouseName(basicdataWarehouseEntity.getName()); + basicdataCodeRecordEntity.setWarehouseCode(warehouseCode); + basicdataCodeRecordEntity.setYear(year+""); + basicdataCodeRecordEntity.setMonth(month+""); + basicdataCodeRecordEntity.setNum(0); + basicdataCodeRecordService.save(basicdataCodeRecordEntity); } - return warehouseCode+dateShort+CommonUtil.geFourNumber(incr,5); + Integer inrc = basicdataCodeRecordEntity.getNum() + 1; + + return warehouseCode+year+month+CommonUtil.geFourNumber(inrc.longValue(),5); } diff --git a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/OpenOrderServiceImpl.java b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/OpenOrderServiceImpl.java index 5b12cc6d6..1d301de07 100644 --- a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/OpenOrderServiceImpl.java +++ b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/OpenOrderServiceImpl.java @@ -252,6 +252,10 @@ public class OpenOrderServiceImpl implements IOpenOrderService { //如果运单号为空则自动生成运单号 if(StringUtil.isBlank(waybillNo)){ waybillNo = basicdataCodeClient.getCodeByType(CodeNumConstant.WAYBILL, warehouseCode, ""); + WarehouseWaybillEntity warehouseWaybillEntity = warehouseWaybillClient.findByWaybillNo(waybillNo); + while(!Objects.isNull(warehouseWaybillEntity)){ + waybillNo = basicdataCodeClient.getCodeByType(CodeNumConstant.WAYBILL, warehouseCode, ""); + } } Long departureWarehouseId = openOrderDTO.getDepartureWarehouseId(); Long destinationWarehouseId = openOrderDTO.getDestinationWarehouseId();