fix:修改入库单据问题

main
HuangHuiKang 1 week ago
parent 623c14fd99
commit a3634e88dd

@ -0,0 +1,17 @@
package cn.iocoder.yudao.module.erp.enums.stock;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
@Getter
public enum ErpStockInApproveActionEnum {
SUBMIT("SUBMIT"),
APPROVE("APPROVE"),
REJECT("REJECT"),
AUTO_APPROVE("AUTO_APPROVE");
private final String actionType;
}

@ -27,6 +27,11 @@
<artifactId>yudao-module-erp-api</artifactId> <artifactId>yudao-module-erp-api</artifactId>
<version>${revision}</version> <version>${revision}</version>
</dependency> </dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-infra-api</artifactId>
<version>${revision}</version>
</dependency>
<!-- 业务组件 --> <!-- 业务组件 -->
@ -76,4 +81,4 @@
</dependencies> </dependencies>
</project> </project>

@ -30,9 +30,6 @@ public class ErpStockInSaveReqVO {
@Schema(description = "经办人编号", example = "1888") @Schema(description = "经办人编号", example = "1888")
private Long stockUserId; private Long stockUserId;
@Schema(description = "是否需要审核", example = "true")
private Boolean needAudit;
@Schema(description = "审核人编号", example = "1888") @Schema(description = "审核人编号", example = "1888")
private Long auditUserId; private Long auditUserId;

@ -529,10 +529,16 @@ public class ErpProductServiceImpl implements ErpProductService {
Map<Long, ErpProductUnitDO> unitMap = productUnitService.getProductUnitMap( Map<Long, ErpProductUnitDO> unitMap = productUnitService.getProductUnitMap(
convertSet(list, ErpProductDO::getUnitId)); convertSet(list, ErpProductDO::getUnitId));
return BeanUtils.toBean(list, ErpProductRespVO.class, product -> { return BeanUtils.toBean(list, ErpProductRespVO.class, product -> {
MapUtils.findAndThen(categoryMap, product.getCategoryId(), MapUtils.findAndThen(categoryMap, product.getCategoryId(), category -> {
category -> product.setCategoryName(category.getName())); product.setCategoryName(category.getName());
MapUtils.findAndThen(subCategoryMap, product.getSubCategoryId(), if (product.getCategoryType() == null) {
subCategory -> product.setSubCategoryName(subCategory.getName())); product.setCategoryType(category.getType());
}
});
MapUtils.findAndThen(subCategoryMap, product.getSubCategoryId(), subCategory -> {
product.setSubCategoryName(subCategory.getName());
product.setCategoryType(subCategory.getType());
});
MapUtils.findAndThen(unitMap, product.getUnitId(), MapUtils.findAndThen(unitMap, product.getUnitId(),
unit -> product.setUnitName(unit.getName())); unit -> product.setUnitName(unit.getName()));
if (Boolean.TRUE.equals(product.getDeleted())) { if (Boolean.TRUE.equals(product.getDeleted())) {

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

@ -22,6 +22,7 @@ import cn.iocoder.yudao.module.erp.service.mold.MoldService;
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.sale.ErpCustomerService; import cn.iocoder.yudao.module.erp.service.sale.ErpCustomerService;
import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockRecordCreateReqBO; import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockRecordCreateReqBO;
import cn.iocoder.yudao.module.infra.api.config.ConfigApi;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -47,6 +48,10 @@ import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*;
@Validated @Validated
public class ErpStockOutServiceImpl implements ErpStockOutService { public class ErpStockOutServiceImpl implements ErpStockOutService {
private static final String AUDIT_CONFIG_CATEGORY = "biz";
private static final String AUDIT_CONFIG_KEY = "isAudit";
private static final String AUDIT_CONFIG_DISABLE_VALUE = "0";
@Resource @Resource
private ErpStockOutMapper stockOutMapper; private ErpStockOutMapper stockOutMapper;
@Resource @Resource
@ -67,6 +72,8 @@ public class ErpStockOutServiceImpl implements ErpStockOutService {
private ErpCustomerService customerService; private ErpCustomerService customerService;
@Resource @Resource
private ErpStockRecordService stockRecordService; private ErpStockRecordService stockRecordService;
@Resource
private ConfigApi configApi;
@Override @Override
@ -83,8 +90,10 @@ public class ErpStockOutServiceImpl implements ErpStockOutService {
} }
// 2.1 插入出库单 // 2.1 插入出库单
boolean needAudit = needAudit();
Integer status = needAudit ? ErpAuditStatus.PROCESS.getStatus() : ErpAuditStatus.APPROVE.getStatus();
ErpStockOutDO stockOut = BeanUtils.toBean(createReqVO, ErpStockOutDO.class, in -> in ErpStockOutDO stockOut = BeanUtils.toBean(createReqVO, ErpStockOutDO.class, in -> in
.setNo(no).setStatus(ErpAuditStatus.PROCESS.getStatus()) .setNo(no).setStatus(status)
.setTotalCount(getSumValue(stockOutItems, ErpStockOutItemDO::getCount, BigDecimal::add)) .setTotalCount(getSumValue(stockOutItems, ErpStockOutItemDO::getCount, BigDecimal::add))
.setTotalPrice(getSumValue(stockOutItems, ErpStockOutItemDO::getTotalPrice, BigDecimal::add, BigDecimal.ZERO))); .setTotalPrice(getSumValue(stockOutItems, ErpStockOutItemDO::getTotalPrice, BigDecimal::add, BigDecimal.ZERO)));
stockOutMapper.insert(stockOut); stockOutMapper.insert(stockOut);
@ -96,6 +105,9 @@ public class ErpStockOutServiceImpl implements ErpStockOutService {
// moldDO.setStatus(ErpAuditStatus.PROCESS.getStatus()); // 未审核 // moldDO.setStatus(ErpAuditStatus.PROCESS.getStatus()); // 未审核
// moldService.updateMold(BeanUtils.toBean(moldDO, MoldSaveReqVO.class)); // moldService.updateMold(BeanUtils.toBean(moldDO, MoldSaveReqVO.class));
// } // }
if (!needAudit) {
operateStockOutEffect(stockOut, stockOutItems, true, ErpAuditStatus.APPROVE.getStatus());
}
return stockOut.getId(); return stockOut.getId();
} }
@ -137,6 +149,11 @@ public class ErpStockOutServiceImpl implements ErpStockOutService {
} }
List<ErpStockOutItemDO> stockOutItems = stockOutItemMapper.selectListByOutId(id); List<ErpStockOutItemDO> stockOutItems = stockOutItemMapper.selectListByOutId(id);
operateStockOutEffect(stockOut, stockOutItems, approve, status);
}
private void operateStockOutEffect(ErpStockOutDO stockOut, List<ErpStockOutItemDO> stockOutItems,
boolean approve, Integer status) {
stockOutItems.forEach(stockOutItem -> { stockOutItems.forEach(stockOutItem -> {
BigDecimal count = approve ? stockOutItem.getCount().negate() : stockOutItem.getCount(); BigDecimal count = approve ? stockOutItem.getCount().negate() : stockOutItem.getCount();
if (Objects.equals(stockOut.getOutType(), "模具出库")) { if (Objects.equals(stockOut.getOutType(), "模具出库")) {
@ -166,6 +183,10 @@ public class ErpStockOutServiceImpl implements ErpStockOutService {
} }
} }
private boolean needAudit() {
return !AUDIT_CONFIG_DISABLE_VALUE.equals(configApi.getConfigValueByCategoryAndKey(AUDIT_CONFIG_CATEGORY, AUDIT_CONFIG_KEY));
}
private List<ErpStockOutItemDO> validateStockOutItems(List<ErpStockOutSaveReqVO.Item> list,String outType) { private List<ErpStockOutItemDO> validateStockOutItems(List<ErpStockOutSaveReqVO.Item> list,String outType) {
if (Objects.equals(outType, "模具出库")) { if (Objects.equals(outType, "模具出库")) {
List<MoldBrandDO> moldList = moldBrandService.validMoldList( List<MoldBrandDO> moldList = moldBrandService.validMoldList(
@ -293,4 +314,4 @@ public class ErpStockOutServiceImpl implements ErpStockOutService {
} }
} }

@ -15,4 +15,6 @@ public interface ConfigApi {
*/ */
String getConfigValueByKey(String key); String getConfigValueByKey(String key);
String getConfigValueByCategoryAndKey(String category, String key);
} }

@ -25,4 +25,10 @@ public class ConfigApiImpl implements ConfigApi {
return config != null ? config.getValue() : null; return config != null ? config.getValue() : null;
} }
@Override
public String getConfigValueByCategoryAndKey(String category, String key) {
ConfigDO config = configService.getConfigByCategoryAndKey(category, key);
return config != null ? config.getValue() : null;
}
} }

@ -14,6 +14,10 @@ public interface ConfigMapper extends BaseMapperX<ConfigDO> {
return selectOne(ConfigDO::getConfigKey, key); return selectOne(ConfigDO::getConfigKey, key);
} }
default ConfigDO selectByCategoryAndKey(String category, String key) {
return selectOne(ConfigDO::getCategory, category, ConfigDO::getConfigKey, key);
}
default PageResult<ConfigDO> selectPage(ConfigPageReqVO reqVO) { default PageResult<ConfigDO> selectPage(ConfigPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ConfigDO>() return selectPage(reqVO, new LambdaQueryWrapperX<ConfigDO>()
.likeIfPresent(ConfigDO::getName, reqVO.getName()) .likeIfPresent(ConfigDO::getName, reqVO.getName())

@ -52,6 +52,8 @@ public interface ConfigService {
*/ */
ConfigDO getConfigByKey(String key); ConfigDO getConfigByKey(String key);
ConfigDO getConfigByCategoryAndKey(String category, String key);
/** /**
* *
* *

@ -74,6 +74,11 @@ public class ConfigServiceImpl implements ConfigService {
return configMapper.selectByKey(key); return configMapper.selectByKey(key);
} }
@Override
public ConfigDO getConfigByCategoryAndKey(String category, String key) {
return configMapper.selectByCategoryAndKey(category, key);
}
@Override @Override
public PageResult<ConfigDO> getConfigPage(ConfigPageReqVO pageReqVO) { public PageResult<ConfigDO> getConfigPage(ConfigPageReqVO pageReqVO) {
return configMapper.selectPage(pageReqVO); return configMapper.selectPage(pageReqVO);

@ -158,10 +158,10 @@ public class MoldOperateServiceImpl implements MoldOperateService {
moldOperate.setDeviceId(deviceLedgerDO.getId()); moldOperate.setDeviceId(deviceLedgerDO.getId());
moldOperate.setDeviceName(deviceLedgerDO.getDeviceName()); moldOperate.setDeviceName(deviceLedgerDO.getDeviceName());
moldOperate.setLineId(lineId); moldOperate.setLineId(lineId);
OrganizationDO organizationDO = organizationMapper.selectById(lineId); // OrganizationDO organizationDO = organizationMapper.selectById(lineId);
if (organizationDO != null) { // if (organizationDO != null) {
moldOperate.setLineName(organizationDO.getName()); // moldOperate.setLineName(organizationDO.getName());
} // }
} }

Loading…
Cancel
Save