ERP:增加入库单号的自动生成

This commit is contained in:
YunaiV 2024-02-07 00:37:42 +08:00
parent 593e1fd59c
commit f6d3290426
7 changed files with 85 additions and 6 deletions

View File

@ -25,7 +25,7 @@ public interface ErrorCodeConstants {
ErrorCode STOCK_IN_DELETE_FAIL_APPROVE = new ErrorCode(1_030_401_001, "其它入库单({})已审核,无法删除"); ErrorCode STOCK_IN_DELETE_FAIL_APPROVE = new ErrorCode(1_030_401_001, "其它入库单({})已审核,无法删除");
ErrorCode STOCK_IN_PROCESS_FAIL = new ErrorCode(1_030_401_002, "反审核失败,只有已审核的入库单才能反审核"); ErrorCode STOCK_IN_PROCESS_FAIL = new ErrorCode(1_030_401_002, "反审核失败,只有已审核的入库单才能反审核");
ErrorCode STOCK_IN_APPROVE_FAIL = new ErrorCode(1_030_401_003, "审核失败,只有未审核的入库单才能审核"); ErrorCode STOCK_IN_APPROVE_FAIL = new ErrorCode(1_030_401_003, "审核失败,只有未审核的入库单才能审核");
ErrorCode STOCK_IN_NO_EXISTS = new ErrorCode(1_030_401_004, "生成入库单失败,请重新提交");
// ========== ERP 产品 1-030-500-000 ========== // ========== ERP 产品 1-030-500-000 ==========
ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(1_030_500_000, "产品不存在"); ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(1_030_500_000, "产品不存在");

View File

@ -51,6 +51,11 @@
<artifactId>yudao-spring-boot-starter-mybatis</artifactId> <artifactId>yudao-spring-boot-starter-mybatis</artifactId>
</dependency> </dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-redis</artifactId>
</dependency>
<!-- 工具类相关 --> <!-- 工具类相关 -->
<dependency> <dependency>
<groupId>cn.iocoder.boot</groupId> <groupId>cn.iocoder.boot</groupId>

View File

@ -17,10 +17,6 @@ public class ErpStockInSaveReqVO {
@Schema(description = "入库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11756") @Schema(description = "入库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11756")
private Long id; private Long id;
@Schema(description = "入库单号", requiredMode = Schema.RequiredMode.REQUIRED, example = "S123")
@NotEmpty(message = "入库单号不能为空")
private String no;
@Schema(description = "供应商编号", example = "3113") @Schema(description = "供应商编号", example = "3113")
private Long supplierId; private Long supplierId;

View File

@ -40,4 +40,8 @@ public interface ErpStockInMapper extends BaseMapperX<ErpStockInDO> {
.eq(ErpStockInDO::getId, id).eq(ErpStockInDO::getStatus, status)); .eq(ErpStockInDO::getId, id).eq(ErpStockInDO::getStatus, status));
} }
default ErpStockInDO selectByNo(String no) {
return selectOne(ErpStockInDO::getNo, no);
}
} }

View File

@ -0,0 +1,18 @@
package cn.iocoder.yudao.module.erp.dal.redis;
/**
* ERP Redis Key 枚举类
*
* @author 芋道源码
*/
public interface RedisKeyConstants {
/**
* 序号的缓存
*
* KEY 格式trade_no:{prefix}
* VALUE 数据格式编号自增
*/
String NO = "seq_no:";
}

View File

@ -0,0 +1,47 @@
package cn.iocoder.yudao.module.erp.dal.redis.no;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.iocoder.yudao.module.erp.dal.redis.RedisKeyConstants;
import jakarta.annotation.Resource;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Repository;
import java.time.Duration;
import java.time.LocalDateTime;
/**
* 订单序号的 Redis DAO
*
* @author HUIHUI
*/
@Repository
public class ErpNoRedisDAO {
/**
* 其它入库 STOCK_IN
*/
public static final String STOCK_IN_NO_PREFIX = "QTRK";
@Resource
private StringRedisTemplate stringRedisTemplate;
/**
* 生成序号使用当前日期格式为 {PREFIX} + yyyyMMdd + 6 位自增
* 例如说QTRK 202109 000001 没有中间空格
*
* @param prefix 前缀
* @return 序号
*/
public String generate(String prefix) {
// 递增序号
String noPrefix = prefix + DateUtil.format(LocalDateTime.now(), DatePattern.PURE_DATE_PATTERN);
String key = RedisKeyConstants.NO + noPrefix;
Long no = stringRedisTemplate.opsForValue().increment(key);
// 设置过期时间
stringRedisTemplate.expire(key, Duration.ofMinutes(1L));
return noPrefix + String.format("%06d", no);
}
}

View File

@ -11,6 +11,7 @@ import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInItemDO; import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInItemDO;
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInItemMapper; import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInItemMapper;
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInMapper; import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInMapper;
import cn.iocoder.yudao.module.erp.dal.redis.no.ErpNoRedisDAO;
import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus; import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus;
import cn.iocoder.yudao.module.erp.service.product.ErpProductService; import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
import cn.iocoder.yudao.module.erp.service.purchase.ErpSupplierService; import cn.iocoder.yudao.module.erp.service.purchase.ErpSupplierService;
@ -44,6 +45,9 @@ public class ErpStockInServiceImpl implements ErpStockInService {
@Resource @Resource
private ErpStockInItemMapper stockInItemMapper; private ErpStockInItemMapper stockInItemMapper;
@Resource
private ErpNoRedisDAO noRedisDAO;
@Resource @Resource
private ErpProductService productService; private ErpProductService productService;
@Resource @Resource
@ -58,10 +62,15 @@ public class ErpStockInServiceImpl implements ErpStockInService {
List<ErpStockInItemDO> stockInItems = validateStockInItems(createReqVO.getItems()); List<ErpStockInItemDO> stockInItems = validateStockInItems(createReqVO.getItems());
// 1.2 校验供应商 // 1.2 校验供应商
supplierService.validateSupplier(createReqVO.getSupplierId()); supplierService.validateSupplier(createReqVO.getSupplierId());
// 1.3
String no = noRedisDAO.generate(ErpNoRedisDAO.STOCK_IN_NO_PREFIX);
if (stockInMapper.selectByNo(no) != null) {
throw exception(STOCK_IN_NO_EXISTS);
}
// 2.1 插入入库单 // 2.1 插入入库单
ErpStockInDO stockIn = BeanUtils.toBean(createReqVO, ErpStockInDO.class, in -> in ErpStockInDO stockIn = BeanUtils.toBean(createReqVO, ErpStockInDO.class, in -> in
.setStatus(ErpAuditStatus.PROCESS.getStatus()) .setNo(no).setStatus(ErpAuditStatus.PROCESS.getStatus())
.setTotalCount(getSumValue(stockInItems, ErpStockInItemDO::getCount, BigDecimal::add)) .setTotalCount(getSumValue(stockInItems, ErpStockInItemDO::getCount, BigDecimal::add))
.setTotalPrice(getSumValue(stockInItems, ErpStockInItemDO::getTotalPrice, BigDecimal::add, BigDecimal.ZERO))); .setTotalPrice(getSumValue(stockInItems, ErpStockInItemDO::getTotalPrice, BigDecimal::add, BigDecimal.ZERO)));
stockInMapper.insert(stockIn); stockInMapper.insert(stockIn);