|
|
|
|
@ -25,12 +25,14 @@ import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockMapper;
|
|
|
|
|
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.stock.ErpStockInApproveActionEnum;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.enums.stock.ErpStockRecordBizTypeEnum;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.service.mold.MoldBrandService;
|
|
|
|
|
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.stock.bo.ErpStockRecordCreateReqBO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.service.warehousearea.WarehouseAreaService;
|
|
|
|
|
import cn.iocoder.yudao.module.infra.api.config.ConfigApi;
|
|
|
|
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@ -72,11 +74,6 @@ import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.WAREHOUSE_LOC
|
|
|
|
|
@Validated
|
|
|
|
|
public class ErpStockInServiceImpl implements ErpStockInService {
|
|
|
|
|
|
|
|
|
|
private static final String ACTION_SUBMIT = "SUBMIT";
|
|
|
|
|
private static final String ACTION_APPROVE = "APPROVE";
|
|
|
|
|
private static final String ACTION_REJECT = "REJECT";
|
|
|
|
|
private static final String ACTION_AUTO_APPROVE = "AUTO_APPROVE";
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private ErpStockInMapper stockInMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
@ -101,6 +98,8 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
|
|
|
|
private WarehouseAreaService warehouseAreaService;
|
|
|
|
|
@Resource
|
|
|
|
|
private AdminUserApi adminUserApi;
|
|
|
|
|
@Resource
|
|
|
|
|
private ConfigApi configApi;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
@ -117,7 +116,7 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
|
|
|
|
throw exception(STOCK_IN_NO_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean needAudit = !Boolean.FALSE.equals(createReqVO.getNeedAudit());
|
|
|
|
|
boolean needAudit = needAudit();
|
|
|
|
|
Integer status = needAudit ? ErpAuditStatus.DRAFT.getStatus() : ErpAuditStatus.APPROVE.getStatus();
|
|
|
|
|
ErpStockInDO stockIn = BeanUtils.toBean(createReqVO, ErpStockInDO.class, in -> in
|
|
|
|
|
.setNo(no)
|
|
|
|
|
@ -131,7 +130,7 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
|
|
|
|
|
|
|
|
|
if (!needAudit) {
|
|
|
|
|
applyStockInEffect(stockIn, stockInItems, null);
|
|
|
|
|
createApproveRecord(stockIn.getId(), ACTION_AUTO_APPROVE, null,
|
|
|
|
|
createApproveRecord(stockIn.getId(), ErpStockInApproveActionEnum.AUTO_APPROVE, null,
|
|
|
|
|
ErpAuditStatus.APPROVE.getStatus(), null, "无需审核,系统自动入库");
|
|
|
|
|
}
|
|
|
|
|
return stockIn.getId();
|
|
|
|
|
@ -154,7 +153,7 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
|
|
|
|
adminUserApi.validateUser(updateReqVO.getAuditUserId());
|
|
|
|
|
}
|
|
|
|
|
List<ErpStockInItemDO> stockInItems = validateStockInItems(updateReqVO.getItems(), updateReqVO.getInType());
|
|
|
|
|
boolean needAudit = !Boolean.FALSE.equals(updateReqVO.getNeedAudit());
|
|
|
|
|
boolean needAudit = needAudit();
|
|
|
|
|
ErpStockInDO updateObj = BeanUtils.toBean(updateReqVO, ErpStockInDO.class, in -> in
|
|
|
|
|
.setNeedAudit(needAudit)
|
|
|
|
|
.setTotalCount(getSumValue(stockInItems, ErpStockInItemDO::getCount, BigDecimal::add))
|
|
|
|
|
@ -215,7 +214,7 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
|
|
|
|
if (updateCount == 0) {
|
|
|
|
|
throw exception(STOCK_IN_SUBMIT_FAIL_STATUS);
|
|
|
|
|
}
|
|
|
|
|
createApproveRecord(stockIn.getId(), ACTION_SUBMIT, fromStatus,
|
|
|
|
|
createApproveRecord(stockIn.getId(), ErpStockInApproveActionEnum.SUBMIT, fromStatus,
|
|
|
|
|
ErpAuditStatus.PROCESS.getStatus(), auditUserId, submitReqVO.getRemark());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -248,7 +247,7 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
|
|
|
|
}
|
|
|
|
|
Long targetUserId = NumberUtils.parseLong(stockIn.getCreator());
|
|
|
|
|
createApproveRecord(stockIn.getId(), ErpAuditStatus.APPROVE.getStatus().equals(auditReqVO.getStatus())
|
|
|
|
|
? ACTION_APPROVE : ACTION_REJECT,
|
|
|
|
|
? ErpStockInApproveActionEnum.APPROVE : ErpStockInApproveActionEnum.REJECT,
|
|
|
|
|
fromStatus, auditReqVO.getStatus(), targetUserId, auditReqVO.getRemark());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -329,7 +328,7 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
|
|
|
|
boolean approve, Integer bizType) {
|
|
|
|
|
stockInItems.forEach(stockInItem -> {
|
|
|
|
|
BigDecimal count = approve ? stockInItem.getCount() : stockInItem.getCount().negate();
|
|
|
|
|
if (Objects.equals(stockIn.getInType(), "妯″叿鍏ュ簱")) {
|
|
|
|
|
if (Objects.equals(stockIn.getInType(), "模具入库")) {
|
|
|
|
|
MoldBrandDO moldDO = moldBrandService.getMoldBrand(stockInItem.getMoldSetId());
|
|
|
|
|
Integer recordBizType = bizType != null ? bizType
|
|
|
|
|
: (approve ? ErpStockRecordBizTypeEnum.OTHER_IN.getType()
|
|
|
|
|
@ -360,11 +359,15 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void createApproveRecord(Long stockInId, String actionType, Integer fromStatus,
|
|
|
|
|
private boolean needAudit() {
|
|
|
|
|
return !"0".equals(configApi.getConfigValueByCategoryAndKey("biz", "isAudit"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void createApproveRecord(Long stockInId, ErpStockInApproveActionEnum action, Integer fromStatus,
|
|
|
|
|
Integer toStatus, Long targetUserId, String remark) {
|
|
|
|
|
stockInApproveRecordMapper.insert(ErpStockInApproveRecordDO.builder()
|
|
|
|
|
.stockInId(stockInId)
|
|
|
|
|
.actionType(actionType)
|
|
|
|
|
.actionType(action.getActionType())
|
|
|
|
|
.fromStatus(fromStatus)
|
|
|
|
|
.toStatus(toStatus)
|
|
|
|
|
.targetUserId(targetUserId)
|
|
|
|
|
@ -374,7 +377,7 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
|
|
|
|
|
|
|
|
|
private List<ErpStockInItemDO> validateStockInItems(List<ErpStockInSaveReqVO.Item> list, String inType) {
|
|
|
|
|
validateWarehouseAreas(list);
|
|
|
|
|
if (Objects.equals(inType, "妯″叿鍏ュ簱")) {
|
|
|
|
|
if (Objects.equals(inType, "模具入库")) {
|
|
|
|
|
List<MoldBrandDO> moldList = moldBrandService.validMoldList(convertSet(list, ErpStockInSaveReqVO.Item::getMoldSetId));
|
|
|
|
|
Map<Long, MoldBrandDO> moldMap = convertMap(moldList, MoldBrandDO::getId);
|
|
|
|
|
Map<Long, ErpWarehouseDO> warehouseMap = convertMap(
|
|
|
|
|
@ -466,4 +469,3 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|