mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-27 01:32:03 +08:00
✨ ERP:增加入库单号的自动生成
This commit is contained in:
parent
593e1fd59c
commit
f6d3290426
@ -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, "产品不存在");
|
||||||
|
@ -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>
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -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:";
|
||||||
|
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user