fix:修改添加入库单据相关审批接口

main
HuangHuiKang 1 week ago
parent d6879bb617
commit 9907ec6c7c

@ -6,36 +6,22 @@ import lombok.RequiredArgsConstructor;
import java.util.Arrays; import java.util.Arrays;
/**
* ERP
*
* TODO 稿==退
*
* @author
*/
@RequiredArgsConstructor @RequiredArgsConstructor
@Getter @Getter
public enum ErpAuditStatus implements IntArrayValuable { public enum ErpAuditStatus implements IntArrayValuable {
DRAFT(0, "草稿"), // 审核中 DRAFT(0, "待提交"),
UN_APPROVE(1, "驳回"), // 审核通过 UN_APPROVE(1, "已驳回"),
PROCESS(10, "审核"), // 审核中 PROCESS(10, "审核中"),
APPROVE(20, "审核"); // 审核通过 APPROVE(20, "审核通过");
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ErpAuditStatus::getStatus).toArray(); public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ErpAuditStatus::getStatus).toArray();
/**
*
*/
private final Integer status; private final Integer status;
/**
*
*/
private final String name; private final String name;
@Override @Override
public int[] array() { public int[] array() {
return ARRAYS; return ARRAYS;
} }
} }

@ -109,6 +109,14 @@ public interface ErrorCodeConstants {
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, "生成入库单失败,请重新提交"); ErrorCode STOCK_IN_NO_EXISTS = new ErrorCode(1_030_401_004, "生成入库单失败,请重新提交");
ErrorCode STOCK_IN_UPDATE_FAIL_APPROVE = new ErrorCode(1_030_401_005, "其它入库单({})已审核,无法修改"); ErrorCode STOCK_IN_UPDATE_FAIL_APPROVE = new ErrorCode(1_030_401_005, "其它入库单({})已审核,无法修改");
ErrorCode STOCK_IN_UPDATE_FAIL_PROCESS = new ErrorCode(1_030_401_006, "其它入库单({})审核中,无法修改");
ErrorCode STOCK_IN_DELETE_FAIL_PROCESS = new ErrorCode(1_030_401_007, "其它入库单({})审核中,无法删除");
ErrorCode STOCK_IN_SUBMIT_FAIL_STATUS = new ErrorCode(1_030_401_008, "提交审核失败,只有待提交或已驳回的入库单才能提交");
ErrorCode STOCK_IN_SUBMIT_FAIL_USER = new ErrorCode(1_030_401_009, "提交审核失败,只有创建人才能提交审核");
ErrorCode STOCK_IN_SUBMIT_FAIL_AUDIT_USER_EMPTY = new ErrorCode(1_030_401_010, "提交审核失败,请选择审核人");
ErrorCode STOCK_IN_AUDIT_FAIL_STATUS = new ErrorCode(1_030_401_011, "审核失败,只有审核中的入库单才能审核");
ErrorCode STOCK_IN_AUDIT_FAIL_USER = new ErrorCode(1_030_401_012, "审核失败,当前用户不是指定审核人");
ErrorCode STOCK_IN_AUDIT_FAIL_RESULT = new ErrorCode(1_030_401_013, "审核失败,审核结果只支持通过或驳回");
ErrorCode STOCK_ALERADY_IN = new ErrorCode(1_030_401_005, "模具({})已经入库,无法继续操作入库"); ErrorCode STOCK_ALERADY_IN = new ErrorCode(1_030_401_005, "模具({})已经入库,无法继续操作入库");
ErrorCode STOCK_ALERADY_OUT = new ErrorCode(1_030_401_005, "模具({})已经出库,无法继续操作出库"); ErrorCode STOCK_ALERADY_OUT = new ErrorCode(1_030_401_005, "模具({})已经出库,无法继续操作出库");

@ -6,17 +6,23 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.ratelimiter.core.annotation.RateLimiter; import cn.iocoder.yudao.framework.ratelimiter.core.annotation.RateLimiter;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldBrandDO; import cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldBrandDO;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO; import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInApproveRecordRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInAuditReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInPageReqVO; import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInRespVO; import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInSaveReqVO; import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInSaveReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInSubmitReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.StockInTypeEnum; import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.StockInTypeEnum;
import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpSupplierDO; import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpSupplierDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO; import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInApproveRecordDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInDO; 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.dataobject.stock.ErpWarehouseDO; import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO;
@ -46,15 +52,17 @@ import javax.validation.Valid;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertListByFlatMap;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
@Tag(name = "管理后台 - ERP 其它入库单") @Tag(name = "管理后台 - ERP 其它入库单")
@ -75,12 +83,10 @@ public class ErpStockInController {
private ErpWarehouseService warehouseService; private ErpWarehouseService warehouseService;
@Resource @Resource
private WarehouseAreaService warehouseAreaService; private WarehouseAreaService warehouseAreaService;
@Resource @Resource
private MoldBrandService moldBrandService; private MoldBrandService moldBrandService;
@Resource @Resource
private MoldService moldService; private MoldService moldService;
@Resource @Resource
private AdminUserApi adminUserApi; private AdminUserApi adminUserApi;
@ -105,11 +111,36 @@ public class ErpStockInController {
@RateLimiter(count = 1, timeUnit = TimeUnit.SECONDS) @RateLimiter(count = 1, timeUnit = TimeUnit.SECONDS)
public CommonResult<Boolean> updateStockInStatus(@RequestParam("id") Long id, public CommonResult<Boolean> updateStockInStatus(@RequestParam("id") Long id,
@RequestParam("status") Integer status, @RequestParam("status") Integer status,
@RequestParam(name = "status",required = false) Integer bizType) { @RequestParam(name = "bizType", required = false) Integer bizType) {
stockInService.updateStockInStatus(id, status,bizType); stockInService.updateStockInStatus(id, status, bizType);
return success(true);
}
@PutMapping("/submit")
@Operation(summary = "提交其它入库单审核")
@PreAuthorize("@ss.hasPermission('erp:stock-in:update')")
@RateLimiter(count = 1, timeUnit = TimeUnit.SECONDS)
public CommonResult<Boolean> submitStockInAudit(@Valid @RequestBody ErpStockInSubmitReqVO submitReqVO) {
stockInService.submitStockInAudit(submitReqVO);
return success(true); return success(true);
} }
@PutMapping("/audit")
@Operation(summary = "审核其它入库单")
@PreAuthorize("@ss.hasPermission('erp:stock-in:update-status')")
@RateLimiter(count = 1, timeUnit = TimeUnit.SECONDS)
public CommonResult<Boolean> auditStockIn(@Valid @RequestBody ErpStockInAuditReqVO auditReqVO) {
stockInService.auditStockIn(auditReqVO);
return success(true);
}
@GetMapping("/approve-record-list")
@Operation(summary = "获得其它入库单审核记录")
@PreAuthorize("@ss.hasPermission('erp:stock-in:query')")
public CommonResult<List<ErpStockInApproveRecordRespVO>> getApproveRecordList(@RequestParam("id") Long id) {
return success(buildApproveRecordRespList(stockInService.getStockInApproveRecordList(id)));
}
@DeleteMapping("/delete") @DeleteMapping("/delete")
@Operation(summary = "删除其它入库单") @Operation(summary = "删除其它入库单")
@Parameter(name = "ids", description = "编号数组", required = true) @Parameter(name = "ids", description = "编号数组", required = true)
@ -128,67 +159,17 @@ public class ErpStockInController {
if (stockIn == null) { if (stockIn == null) {
return success(null); return success(null);
} }
List<ErpStockInItemDO> stockInItemList = stockInService.getStockInItemListByInId(id); return success(buildStockInRespVO(stockIn,
Map<Long, ErpWarehouseDO> warehouseMap = warehouseService.getWarehouseMap( stockInService.getStockInItemListByInId(id),
convertSet(stockInItemList, ErpStockInItemDO::getWarehouseId)); stockInService.getStockInApproveRecordList(id)));
Map<Long, WarehouseAreaDO> areaMap = warehouseAreaService.getWarehouseAreaMap(
convertSet(stockInItemList, ErpStockInItemDO::getAreaId));
if (Objects.equals(stockIn.getInType(), "模具入库")) {
Map<Long, MoldBrandDO> moldMap = moldBrandService.getMoldVOMap(
convertSet(stockInItemList, ErpStockInItemDO::getMoldSetId));
Map<Long, List<cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldDO>> moldListMap = moldService.getMoldListMapByBrandIds(
convertSet(stockInItemList, ErpStockInItemDO::getMoldSetId));
return success(BeanUtils.toBean(stockIn, ErpStockInRespVO.class, stockInVO -> {
stockInVO.setItems(convertList(stockInItemList, source -> {
ErpStockInRespVO.Item item = BeanUtils.toBean(source, ErpStockInRespVO.Item.class);
item.setMoldSetId(source.getMoldSetId());
item.setMoldSetName(source.getMoldSetName());
ErpStockDO stock = stockService.getStock(source.getMoldSetId(), source.getWarehouseId());
item.setStockCount(stock != null ? stock.getCount() : BigDecimal.ZERO);
item.setMoldList(moldListMap.getOrDefault(source.getMoldSetId(), new ArrayList<>()));
fillWarehouseInfo(item, source, warehouseMap, areaMap);
MapUtils.findAndThen(moldMap, source.getMoldSetId(), mold -> item.setMoldSetName(mold.getName())
.setProductName(mold.getName())
.setProductBarCode(mold.getCode()));
return item;
}));
stockInVO.setMoldSetNames(CollUtil.join(stockInVO.getItems(), ",", ErpStockInRespVO.Item::getMoldSetName));
stockInVO.setProductNames(stockInVO.getMoldSetNames());
}));
} else {
Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap(
convertSet(stockInItemList, ErpStockInItemDO::getProductId));
return success(BeanUtils.toBean(stockIn, ErpStockInRespVO.class, stockInVO ->
stockInVO.setItems(BeanUtils.toBean(stockInItemList, ErpStockInRespVO.Item.class, item -> {
ErpStockDO stock = stockService.getStock(item.getProductId(), item.getWarehouseId());
item.setStockCount(stock != null ? stock.getCount() : BigDecimal.ZERO);
if (StringUtils.isBlank(item.getWarehouseName())) {
MapUtils.findAndThen(warehouseMap, item.getWarehouseId(), warehouse -> item.setWarehouseName(warehouse.getName()));
}
if (StringUtils.isBlank(item.getAreaName())) {
MapUtils.findAndThen(areaMap, item.getAreaId(), area -> item.setAreaName(area.getAreaName()));
}
MapUtils.findAndThen(productMap, item.getProductId(), product -> item.setProductName(product.getName())
.setProductBarCode(product.getBarCode()).setProductUnitName(product.getUnitName()));
}))));
}
} }
@GetMapping("/page") @GetMapping("/page")
@Operation(summary = "获得其它入库单分页") @Operation(summary = "获得其它入库单分页")
@PreAuthorize("@ss.hasPermission('erp:stock-in:query')") @PreAuthorize("@ss.hasPermission('erp:stock-in:query')")
public CommonResult<PageResult<ErpStockInRespVO>> getStockInPage(@Valid ErpStockInPageReqVO pageReqVO) { public CommonResult<PageResult<ErpStockInRespVO>> getStockInPage(@Valid ErpStockInPageReqVO pageReqVO) {
if(StringUtils.isEmpty(pageReqVO.getInType())){ fillPageReqDefault(pageReqVO);
List<String> list = new ArrayList<>(); return success(buildStockInVOPageResult(stockInService.getStockInPage(pageReqVO)));
list.add(StockInTypeEnum..getValue());
list.add(StockInTypeEnum..getValue());
list.add(StockInTypeEnum..getValue());
list.add(StockInTypeEnum..getValue());
pageReqVO.setInTypeList(list);
}
PageResult<ErpStockInDO> pageResult = stockInService.getStockInPage(pageReqVO);
return success(buildStockInVOPageResult(pageResult));
} }
@GetMapping("/export-excel") @GetMapping("/export-excel")
@ -196,68 +177,108 @@ public class ErpStockInController {
@PreAuthorize("@ss.hasPermission('erp:stock-in:export')") @PreAuthorize("@ss.hasPermission('erp:stock-in:export')")
@ApiAccessLog(operateType = EXPORT) @ApiAccessLog(operateType = EXPORT)
public void exportStockInExcel(@Valid ErpStockInPageReqVO pageReqVO, public void exportStockInExcel(@Valid ErpStockInPageReqVO pageReqVO,
HttpServletResponse response) throws IOException { HttpServletResponse response) throws IOException {
fillPageReqDefault(pageReqVO);
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<ErpStockInRespVO> list = buildStockInVOPageResult(stockInService.getStockInPage(pageReqVO)).getList(); List<ErpStockInRespVO> list = buildStockInVOPageResult(stockInService.getStockInPage(pageReqVO)).getList();
// 导出 Excel
ExcelUtils.write(response, "其它入库单.xls", "数据", ErpStockInRespVO.class, list); ExcelUtils.write(response, "其它入库单.xls", "数据", ErpStockInRespVO.class, list);
} }
private void fillPageReqDefault(ErpStockInPageReqVO pageReqVO) {
if (Boolean.TRUE.equals(pageReqVO.getRelatedToMe())) {
pageReqVO.setCurrentUserId(SecurityFrameworkUtils.getLoginUserId());
}
if (StringUtils.isEmpty(pageReqVO.getInType())) {
List<String> list = new ArrayList<>();
list.add(StockInTypeEnum..getValue());
list.add(StockInTypeEnum..getValue());
list.add(StockInTypeEnum..getValue());
list.add(StockInTypeEnum..getValue());
pageReqVO.setInTypeList(list);
}
}
private PageResult<ErpStockInRespVO> buildStockInVOPageResult(PageResult<ErpStockInDO> pageResult) { private PageResult<ErpStockInRespVO> buildStockInVOPageResult(PageResult<ErpStockInDO> pageResult) {
if (CollUtil.isEmpty(pageResult.getList())) { if (CollUtil.isEmpty(pageResult.getList())) {
return PageResult.empty(pageResult.getTotal()); return PageResult.empty(pageResult.getTotal());
} }
List<ErpStockInItemDO> stockInItemList = stockInService.getStockInItemListByInIds( List<ErpStockInRespVO> list = convertList(pageResult.getList(), stockIn -> buildStockInRespVO(
convertSet(pageResult.getList(), ErpStockInDO::getId)); stockIn, stockInService.getStockInItemListByInId(stockIn.getId()), Collections.emptyList()));
Map<Long, List<ErpStockInItemDO>> stockInItemMap = convertMultiMap(stockInItemList, ErpStockInItemDO::getInId); return new PageResult<>(list, pageResult.getTotal());
Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap( }
convertSet(stockInItemList, ErpStockInItemDO::getProductId));
Map<Long, ErpSupplierDO> supplierMap = supplierService.getSupplierMap( private ErpStockInRespVO buildStockInRespVO(ErpStockInDO stockIn, List<ErpStockInItemDO> stockInItemList,
convertSet(pageResult.getList(), ErpStockInDO::getSupplierId)); List<ErpStockInApproveRecordDO> approveRecords) {
ErpStockInRespVO stockInVO = BeanUtils.toBean(stockIn, ErpStockInRespVO.class);
Map<Long, ErpWarehouseDO> warehouseMap = warehouseService.getWarehouseMap( Map<Long, ErpWarehouseDO> warehouseMap = warehouseService.getWarehouseMap(
convertSet(stockInItemList, ErpStockInItemDO::getWarehouseId)); convertSet(stockInItemList, ErpStockInItemDO::getWarehouseId));
Map<Long, WarehouseAreaDO> areaMap = warehouseAreaService.getWarehouseAreaMap( Map<Long, WarehouseAreaDO> areaMap = warehouseAreaService.getWarehouseAreaMap(
convertSet(stockInItemList, ErpStockInItemDO::getAreaId)); convertSet(stockInItemList, ErpStockInItemDO::getAreaId));
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap( Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertListByFlatMap(
convertSet(pageResult.getList(), stockIn -> Long.parseLong(stockIn.getCreator()))); Collections.singletonList(stockIn), item -> Stream.of(NumberUtils.parseLong(item.getCreator()),
Map<Long, MoldBrandDO> moldMap = moldBrandService.getMoldVOMap( item.getStockUserId(), item.getAuditUserId())));
convertSet(stockInItemList, ErpStockInItemDO::getMoldSetId)); MapUtils.findAndThen(userMap, NumberUtils.parseLong(stockIn.getCreator()), user -> stockInVO.setCreatorName(user.getNickname()));
Map<Long, List<cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldDO>> moldListMap = moldService.getMoldListMapByBrandIds( MapUtils.findAndThen(userMap, stockIn.getStockUserId(), user -> stockInVO.setStockUserName(user.getNickname()));
convertSet(stockInItemList, ErpStockInItemDO::getMoldSetId)); MapUtils.findAndThen(userMap, stockIn.getAuditUserId(), user -> stockInVO.setAuditUserName(user.getNickname()));
return BeanUtils.toBean(pageResult, ErpStockInRespVO.class, stockIn -> { if (Objects.equals(stockIn.getInType(), "模具入库")) {
if (Objects.equals(stockIn.getInType(), "模具入库")) { Map<Long, MoldBrandDO> moldMap = moldBrandService.getMoldVOMap(
List<ErpStockInItemDO> itemDOS = stockInItemMap.get(stockIn.getId()); convertSet(stockInItemList, ErpStockInItemDO::getMoldSetId));
stockIn.setItems(convertList(itemDOS, source -> { Map<Long, List<cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldDO>> moldListMap = moldService.getMoldListMapByBrandIds(
ErpStockInRespVO.Item item = BeanUtils.toBean(source, ErpStockInRespVO.Item.class); convertSet(stockInItemList, ErpStockInItemDO::getMoldSetId));
item.setMoldSetId(source.getMoldSetId()); stockInVO.setItems(convertList(stockInItemList, source -> {
item.setMoldSetName(source.getMoldSetName()); ErpStockInRespVO.Item item = BeanUtils.toBean(source, ErpStockInRespVO.Item.class);
item.setMoldList(moldListMap.getOrDefault(source.getMoldSetId(), new ArrayList<>())); ErpStockDO stock = stockService.getStock(source.getMoldSetId(), source.getWarehouseId());
fillWarehouseInfo(item, source, warehouseMap, areaMap); item.setStockCount(stock != null ? stock.getCount() : BigDecimal.ZERO);
MapUtils.findAndThen(moldMap, source.getMoldSetId(), mold -> item.setMoldSetName(mold.getName()) item.setMoldList(moldListMap.getOrDefault(source.getMoldSetId(), new ArrayList<>()));
.setProductName(mold.getName()) fillWarehouseInfo(item, source, warehouseMap, areaMap);
.setProductBarCode(mold.getCode())); MapUtils.findAndThen(moldMap, source.getMoldSetId(), mold -> {
return item; item.setMoldSetName(mold.getName());
})); item.setProductName(mold.getName());
stockIn.setMoldSetNames(CollUtil.join(stockIn.getItems(), ",", ErpStockInRespVO.Item::getMoldSetName)); item.setProductBarCode(mold.getCode());
stockIn.setProductNames(stockIn.getMoldSetNames());
} else {
stockIn.setItems(BeanUtils.toBean(stockInItemMap.get(stockIn.getId()), ErpStockInRespVO.Item.class,
item -> MapUtils.findAndThen(productMap, item.getProductId(), product -> item.setProductName(product.getName())
.setProductBarCode(product.getBarCode()).setProductUnitName(product.getUnitName()))));
stockIn.getItems().forEach(item -> {
if (StringUtils.isBlank(item.getWarehouseName())) {
MapUtils.findAndThen(warehouseMap, item.getWarehouseId(), warehouse -> item.setWarehouseName(warehouse.getName()));
}
if (StringUtils.isBlank(item.getAreaName())) {
MapUtils.findAndThen(areaMap, item.getAreaId(), area -> item.setAreaName(area.getAreaName()));
}
}); });
stockIn.setProductNames(CollUtil.join(stockIn.getItems(), ",", ErpStockInRespVO.Item::getProductName)); return item;
}));
stockInVO.setMoldSetNames(CollUtil.join(stockInVO.getItems(), ",", ErpStockInRespVO.Item::getMoldSetName));
stockInVO.setProductNames(stockInVO.getMoldSetNames());
} else {
Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap(
convertSet(stockInItemList, ErpStockInItemDO::getProductId));
stockInVO.setItems(BeanUtils.toBean(stockInItemList, ErpStockInRespVO.Item.class, item -> {
ErpStockDO stock = stockService.getStock(item.getProductId(), item.getWarehouseId());
item.setStockCount(stock != null ? stock.getCount() : BigDecimal.ZERO);
if (StringUtils.isBlank(item.getWarehouseName())) {
MapUtils.findAndThen(warehouseMap, item.getWarehouseId(), warehouse -> item.setWarehouseName(warehouse.getName()));
}
if (StringUtils.isBlank(item.getAreaName())) {
MapUtils.findAndThen(areaMap, item.getAreaId(), area -> item.setAreaName(area.getAreaName()));
}
MapUtils.findAndThen(productMap, item.getProductId(), product -> {
item.setProductName(product.getName());
item.setProductBarCode(product.getBarCode());
item.setProductUnitName(product.getUnitName());
});
}));
stockInVO.setProductNames(CollUtil.join(stockInVO.getItems(), ",", ErpStockInRespVO.Item::getProductName));
}
} if (stockIn.getSupplierId() != null) {
MapUtils.findAndThen(supplierMap, stockIn.getSupplierId(), supplier -> stockIn.setSupplierName(supplier.getName())); Map<Long, ErpSupplierDO> supplierMap = supplierService.getSupplierMap(Collections.singleton(stockIn.getSupplierId()));
MapUtils.findAndThen(userMap, Long.parseLong(stockIn.getCreator()), user -> stockIn.setCreatorName(user.getNickname())); MapUtils.findAndThen(supplierMap, stockIn.getSupplierId(), supplier -> stockInVO.setSupplierName(supplier.getName()));
}
stockInVO.setApproveRecords(buildApproveRecordRespList(approveRecords));
return stockInVO;
}
private List<ErpStockInApproveRecordRespVO> buildApproveRecordRespList(List<ErpStockInApproveRecordDO> records) {
if (CollUtil.isEmpty(records)) {
return new ArrayList<>();
}
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertListByFlatMap(records,
record -> Stream.of(NumberUtils.parseLong(record.getCreator()), record.getTargetUserId())));
return BeanUtils.toBean(records, ErpStockInApproveRecordRespVO.class, record -> {
MapUtils.findAndThen(userMap, NumberUtils.parseLong(record.getCreator()), user -> record.setCreatorName(user.getNickname()));
MapUtils.findAndThen(userMap, record.getTargetUserId(), user -> record.setTargetUserName(user.getNickname()));
}); });
} }
@ -281,24 +302,25 @@ public class ErpStockInController {
createReqVO.setInType(StockInTypeEnum..getValue()); createReqVO.setInType(StockInTypeEnum..getValue());
return success(stockInService.createStockIn(createReqVO)); return success(stockInService.createStockIn(createReqVO));
} }
@GetMapping("/pageMesStockIn") @GetMapping("/pageMesStockIn")
@Operation(summary = "获得生产入库单分页") @Operation(summary = "获得生产入库单分页")
@PreAuthorize("@ss.hasPermission('erp:stock-in:query')") @PreAuthorize("@ss.hasPermission('erp:stock-in:query')")
public CommonResult<PageResult<ErpStockInRespVO>> pageMesStockIn(@Valid ErpStockInPageReqVO pageReqVO) { public CommonResult<PageResult<ErpStockInRespVO>> pageMesStockIn(@Valid ErpStockInPageReqVO pageReqVO) {
pageReqVO.setInType(StockInTypeEnum..getValue()); pageReqVO.setInType(StockInTypeEnum..getValue());
PageResult<ErpStockInDO> pageResult = stockInService.getStockInPage(pageReqVO); fillPageReqDefault(pageReqVO);
return success(buildStockInVOPageResult(pageResult)); return success(buildStockInVOPageResult(stockInService.getStockInPage(pageReqVO)));
} }
@GetMapping("/pageComponent") @GetMapping("/pageComponent")
@Operation(summary = "获得备件入库单分页") @Operation(summary = "获得备件入库单分页")
@PreAuthorize("@ss.hasPermission('erp:stock-in:query')") @PreAuthorize("@ss.hasPermission('erp:stock-in:query')")
public CommonResult<PageResult<ErpStockInRespVO>> pageComponent(@Valid ErpStockInPageReqVO pageReqVO) { public CommonResult<PageResult<ErpStockInRespVO>> pageComponent(@Valid ErpStockInPageReqVO pageReqVO) {
pageReqVO.setInType(StockInTypeEnum..getValue()); pageReqVO.setInType(StockInTypeEnum..getValue());
PageResult<ErpStockInDO> pageResult = stockInService.getStockInPage(pageReqVO); fillPageReqDefault(pageReqVO);
return success(buildStockInVOPageResult(pageResult)); return success(buildStockInVOPageResult(stockInService.getStockInPage(pageReqVO)));
} }
@PutMapping("/update-mold-status") @PutMapping("/update-mold-status")
@Operation(summary = "更新模具入库单的状态") @Operation(summary = "更新模具入库单的状态")
@PreAuthorize("@ss.hasPermission('erp:stock-out:update-status')") @PreAuthorize("@ss.hasPermission('erp:stock-out:update-status')")

@ -0,0 +1,44 @@
package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - ERP 其它入库单审核记录 Response VO")
@Data
public class ErpStockInApproveRecordRespVO {
@Schema(description = "编号", example = "1")
private Long id;
@Schema(description = "入库单编号", example = "1")
private Long stockInId;
@Schema(description = "操作类型", example = "SUBMIT")
private String actionType;
@Schema(description = "变更前状态", example = "0")
private Integer fromStatus;
@Schema(description = "变更后状态", example = "10")
private Integer toStatus;
@Schema(description = "目标审核人编号", example = "1")
private Long targetUserId;
@Schema(description = "目标审核人名称", example = "李四")
private String targetUserName;
@Schema(description = "备注", example = "请审核")
private String remark;
@Schema(description = "操作人", example = "1")
private String creator;
@Schema(description = "操作人名称", example = "张三")
private String creatorName;
@Schema(description = "创建时间")
private LocalDateTime createTime;
}

@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - ERP 其它入库单审核 Request VO")
@Data
public class ErpStockInAuditReqVO {
@Schema(description = "入库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11756")
@NotNull(message = "入库编号不能为空")
private Long id;
@Schema(description = "审核结果 20-通过 1-驳回", requiredMode = Schema.RequiredMode.REQUIRED, example = "20")
@NotNull(message = "审核结果不能为空")
private Integer status;
@Schema(description = "审核备注", example = "审核通过")
private String remark;
}

@ -34,23 +34,33 @@ public class ErpStockInPageReqVO extends PageParam {
@InEnum(ErpAuditStatus.class) @InEnum(ErpAuditStatus.class)
private Integer status; private Integer status;
@Schema(description = "入库类型", example = "随便") @Schema(description = "入库类型", example = "其它入库")
private String inType; private String inType;
@Schema(description = "入库类型", example = "随便")
@Schema(description = "入库类型集合")
private List<String> inTypeList; private List<String> inTypeList;
@Schema(description = "备注", example = "随便") @Schema(description = "备注", example = "随便")
private String remark; private String remark;
@Schema(description = "创建") @Schema(description = "创建")
private String creator; private String creator;
@Schema(description = "审核人编号", example = "1")
private Long auditUserId;
@Schema(description = "仅看当前登录人提交和待审批的数据", example = "true")
private Boolean relatedToMe;
@Schema(hidden = true)
private Long currentUserId;
@Schema(description = "产品编号", example = "1") @Schema(description = "产品编号", example = "1")
private Long productId; private Long productId;
@Schema(description = "仓库编号", example = "1") @Schema(description = "仓库编号", example = "1")
private Long warehouseId; private Long warehouseId;
@Schema(description = "id集合导出用") @Schema(description = "id 集合导出使用")
private String ids; private String ids;
} }

@ -1,8 +1,8 @@
package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in; package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldDO;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldDO;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
@ -29,6 +29,7 @@ public class ErpStockInRespVO {
@Schema(description = "供应商编号", example = "3113") @Schema(description = "供应商编号", example = "3113")
private Long supplierId; private Long supplierId;
@Schema(description = "供应商名称", example = "芋道") @Schema(description = "供应商名称", example = "芋道")
@ExcelProperty("供应商名称") @ExcelProperty("供应商名称")
private String supplierName; private String supplierName;
@ -37,11 +38,26 @@ public class ErpStockInRespVO {
@ExcelProperty("入库时间") @ExcelProperty("入库时间")
private LocalDateTime inTime; private LocalDateTime inTime;
@Schema(description = "经办人编号", example = "1888")
private Long stockUserId;
@Schema(description = "经办人名称", example = "张三")
private String stockUserName;
@Schema(description = "是否需要审核", example = "true")
private Boolean needAudit;
@Schema(description = "审核人编号", example = "1888")
private Long auditUserId;
@Schema(description = "审核人名称", example = "李四")
private String auditUserName;
@Schema(description = "合计数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15663") @Schema(description = "合计数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15663")
@ExcelProperty("合计数量") @ExcelProperty("合计数量")
private BigDecimal totalCount; private BigDecimal totalCount;
@Schema(description = "合计金额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "24906") @Schema(description = "合计金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "24906")
@ExcelProperty("合计金额") @ExcelProperty("合计金额")
private BigDecimal totalPrice; private BigDecimal totalPrice;
@ -54,7 +70,7 @@ public class ErpStockInRespVO {
@ExcelProperty("备注") @ExcelProperty("备注")
private String remark; private String remark;
@Schema(description = "入库类型", example = "随便") @Schema(description = "入库类型", example = "其它入库")
@ExcelProperty("入库类型") @ExcelProperty("入库类型")
private String inType; private String inType;
@ -63,6 +79,7 @@ public class ErpStockInRespVO {
@Schema(description = "创建人", example = "芋道") @Schema(description = "创建人", example = "芋道")
private String creator; private String creator;
@Schema(description = "创建人名称", example = "芋道") @Schema(description = "创建人名称", example = "芋道")
private String creatorName; private String creatorName;
@ -80,6 +97,9 @@ public class ErpStockInRespVO {
@Schema(description = "模具组名称") @Schema(description = "模具组名称")
private String moldSetNames; private String moldSetNames;
@Schema(description = "审核记录")
private List<ErpStockInApproveRecordRespVO> approveRecords;
@Data @Data
public static class Item { public static class Item {
@ -101,22 +121,31 @@ public class ErpStockInRespVO {
@Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
private Long productId; private Long productId;
@Schema(description = "产品单价", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") @Schema(description = "产品单价", example = "100.00")
private BigDecimal productPrice; private BigDecimal productPrice;
@Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") @Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
private BigDecimal count; private BigDecimal count;
@Schema(description = "包装方案 ID", example = "1")
private Long packagingSchemeId;
@Schema(description = "单位输入方式", example = "包")
private String inputUnitType;
@Schema(description = "录入数量", example = "10.00")
private BigDecimal inputCount;
@Schema(description = "备注", example = "随便") @Schema(description = "备注", example = "随便")
private String remark; private String remark;
// ========== 关联字段 ========== @Schema(description = "产品名称", example = "巧克力")
@Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "巧克力")
private String productName; private String productName;
@Schema(description = "产品条码", requiredMode = Schema.RequiredMode.REQUIRED, example = "A9985")
@Schema(description = "产品条码", example = "A9985")
private String productBarCode; private String productBarCode;
@Schema(description = "产品单位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "盒")
@Schema(description = "产品单位名称", example = "盒")
private String productUnitName; private String productUnitName;
@Schema(description = "仓库名称", example = "A仓") @Schema(description = "仓库名称", example = "A仓")
@ -125,12 +154,10 @@ public class ErpStockInRespVO {
@Schema(description = "库区名称", example = "A-01") @Schema(description = "库区名称", example = "A-01")
private String areaName; private String areaName;
@Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") @Schema(description = "库存数量", example = "100.00")
private BigDecimal stockCount; private BigDecimal stockCount;
@Schema(description = "子模具详情") @Schema(description = "子模具详情")
private List<MoldDO> moldList; private List<MoldDO> moldList;
} }
} }

@ -1,6 +1,5 @@
package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in; package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
@ -15,7 +14,7 @@ import java.util.List;
@Data @Data
public class ErpStockInSaveReqVO { public class ErpStockInSaveReqVO {
@Schema(description = "入库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11756") @Schema(description = "入库编号", example = "11756")
private Long id; private Long id;
@Schema(description = "供应商编号", example = "3113") @Schema(description = "供应商编号", example = "3113")
@ -25,9 +24,18 @@ public class ErpStockInSaveReqVO {
@NotNull(message = "入库时间不能为空") @NotNull(message = "入库时间不能为空")
private LocalDateTime inTime; private LocalDateTime inTime;
@Schema(description = "入库类型", example = "随便") @Schema(description = "入库类型", example = "其它入库")
private String inType; private String inType;
@Schema(description = "经办人编号", example = "1888")
private Long stockUserId;
@Schema(description = "是否需要审核", example = "true")
private Boolean needAudit;
@Schema(description = "审核人编号", example = "1888")
private Long auditUserId;
@Schema(description = "备注", example = "随便") @Schema(description = "备注", example = "随便")
private String remark; private String remark;
@ -39,29 +47,26 @@ public class ErpStockInSaveReqVO {
@Valid @Valid
private List<Item> items; private List<Item> items;
@Schema(description = "仓库编号", example = "3113") @Schema(description = "仓库编号", example = "3113")
private Long warehouseId; private Long warehouseId;
@Data @Data
public static class Item { public static class Item {
@Schema(description = "????????????????", example = "11756") @Schema(description = "子项 id", example = "11756")
private Long id; private Long id;
@Schema(description = "??? ID?????????", example = "101") @Schema(description = "模具组 id", example = "101")
private Long moldSetId; private Long moldSetId;
@Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") @Schema(description = "仓库编号", example = "3113")
// @NotNull(message = "仓库编号不能为空")
private Long warehouseId; private Long warehouseId;
@Schema(description = "库区编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") @Schema(description = "库区编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
@NotNull(message = "库区编号不能为空") @NotNull(message = "库区编号不能为空")
private Long areaId; private Long areaId;
@Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") @Schema(description = "产品编号", example = "3113")
private Long productId; private Long productId;
@Schema(description = "产品单价", example = "100.00") @Schema(description = "产品单价", example = "100.00")
@ -71,11 +76,19 @@ public class ErpStockInSaveReqVO {
@NotNull(message = "产品数量不能为空") @NotNull(message = "产品数量不能为空")
private BigDecimal count; private BigDecimal count;
@Schema(description = "包装方案 ID", example = "1")
private Long packagingSchemeId;
@Schema(description = "单位输入方式", example = "包")
private String inputUnitType;
@Schema(description = "录入数量", example = "10.00")
private BigDecimal inputCount;
@Schema(description = "备注", example = "随便") @Schema(description = "备注", example = "随便")
private String remark; private String remark;
@Schema(description = "设备id", example = "100.00") @Schema(description = "设备 id", example = "100")
private Long deviceId; private Long deviceId;
} }
} }

@ -0,0 +1,21 @@
package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - ERP 其它入库单提交审核 Request VO")
@Data
public class ErpStockInSubmitReqVO {
@Schema(description = "入库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11756")
@NotNull(message = "入库编号不能为空")
private Long id;
@Schema(description = "审核人编号", example = "1888")
private Long auditUserId;
@Schema(description = "提交备注", example = "请审核")
private String remark;
}

@ -0,0 +1,39 @@
package cn.iocoder.yudao.module.erp.dal.dataobject.stock;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
@TableName("erp_stock_in_approve_record")
@KeySequence("erp_stock_in_approve_record_seq")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ErpStockInApproveRecordDO extends BaseDO {
@TableId
private Long id;
private Long stockInId;
private String actionType;
private Integer fromStatus;
private Integer toStatus;
private Long targetUserId;
private String remark;
}

@ -44,6 +44,10 @@ public class ErpStockInDO extends BaseDO {
* *
*/ */
private LocalDateTime inTime; private LocalDateTime inTime;
/**
*
*/
private Long stockUserId;
/** /**
* *
*/ */
@ -58,6 +62,14 @@ public class ErpStockInDO extends BaseDO {
* {@link cn.iocoder.yudao.module.erp.enums.ErpAuditStatus} * {@link cn.iocoder.yudao.module.erp.enums.ErpAuditStatus}
*/ */
private Integer status; private Integer status;
/**
*
*/
private Boolean needAudit;
/**
*
*/
private Long auditUserId;
/** /**
* *
*/ */
@ -71,4 +83,4 @@ public class ErpStockInDO extends BaseDO {
*/ */
private String fileUrl; private String fileUrl;
} }

@ -66,6 +66,18 @@ public class ErpStockInItemDO extends BaseDO {
* *
*/ */
private BigDecimal count; private BigDecimal count;
/**
* ID
*/
private Long packagingSchemeId;
/**
* //
*/
private String inputUnitType;
/**
*
*/
private BigDecimal inputCount;
/** /**
* *
*/ */

@ -0,0 +1,23 @@
package cn.iocoder.yudao.module.erp.dal.mysql.stock;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInApproveRecordDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface ErpStockInApproveRecordMapper extends BaseMapperX<ErpStockInApproveRecordDO> {
default List<ErpStockInApproveRecordDO> selectListByStockInId(Long stockInId) {
return selectList(new LambdaQueryWrapperX<ErpStockInApproveRecordDO>()
.eq(ErpStockInApproveRecordDO::getStockInId, stockInId)
.orderByAsc(ErpStockInApproveRecordDO::getId));
}
default int deleteByStockInId(Long stockInId) {
return delete(ErpStockInApproveRecordDO::getStockInId, stockInId);
}
}

@ -14,11 +14,6 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/**
* ERP Mapper
*
* @author
*/
@Mapper @Mapper
public interface ErpStockInMapper extends BaseMapperX<ErpStockInDO> { public interface ErpStockInMapper extends BaseMapperX<ErpStockInDO> {
@ -32,15 +27,17 @@ public interface ErpStockInMapper extends BaseMapperX<ErpStockInDO> {
.inIfPresent(ErpStockInDO::getInType, reqVO.getInTypeList()) .inIfPresent(ErpStockInDO::getInType, reqVO.getInTypeList())
.likeIfPresent(ErpStockInDO::getRemark, reqVO.getRemark()) .likeIfPresent(ErpStockInDO::getRemark, reqVO.getRemark())
.eqIfPresent(ErpStockInDO::getCreator, reqVO.getCreator()) .eqIfPresent(ErpStockInDO::getCreator, reqVO.getCreator())
.eqIfPresent(ErpStockInDO::getAuditUserId, reqVO.getAuditUserId())
.orderByDesc(ErpStockInDO::getId); .orderByDesc(ErpStockInDO::getId);
query.and(Boolean.TRUE.equals(reqVO.getRelatedToMe()) && reqVO.getCurrentUserId() != null,
w -> w.eq(ErpStockInDO::getCreator, String.valueOf(reqVO.getCurrentUserId()))
.or().eq(ErpStockInDO::getAuditUserId, reqVO.getCurrentUserId()));
if (reqVO.getWarehouseId() != null || reqVO.getProductId() != null) { if (reqVO.getWarehouseId() != null || reqVO.getProductId() != null) {
query.leftJoin(ErpStockInItemDO.class, ErpStockInItemDO::getInId, ErpStockInDO::getId) query.leftJoin(ErpStockInItemDO.class, ErpStockInItemDO::getInId, ErpStockInDO::getId)
.eq(reqVO.getWarehouseId() != null, ErpStockInItemDO::getWarehouseId, reqVO.getWarehouseId()) .eq(reqVO.getWarehouseId() != null, ErpStockInItemDO::getWarehouseId, reqVO.getWarehouseId())
.eq(reqVO.getProductId() != null, ErpStockInItemDO::getProductId, reqVO.getProductId()) .eq(reqVO.getProductId() != null, ErpStockInItemDO::getProductId, reqVO.getProductId())
.groupBy(ErpStockInDO::getId); // 避免 1 对多查询,产生相同的 1 .groupBy(ErpStockInDO::getId);
} }
// 单独处理 ids 条件
if (StringUtils.isNotBlank(reqVO.getIds())) { if (StringUtils.isNotBlank(reqVO.getIds())) {
List<Long> idList = Arrays.stream(reqVO.getIds().split(",")) List<Long> idList = Arrays.stream(reqVO.getIds().split(","))
.map(String::trim) .map(String::trim)
@ -48,19 +45,17 @@ public interface ErpStockInMapper extends BaseMapperX<ErpStockInDO> {
.collect(Collectors.toList()); .collect(Collectors.toList());
query.in(ErpStockInDO::getId, idList); query.in(ErpStockInDO::getId, idList);
} }
return selectJoinPage(reqVO, ErpStockInDO.class, query); return selectJoinPage(reqVO, ErpStockInDO.class, query);
} }
default int updateByIdAndStatus(Long id, Integer status, ErpStockInDO updateObj) { default int updateByIdAndStatus(Long id, Integer status, ErpStockInDO updateObj) {
return update(updateObj, new LambdaUpdateWrapper<ErpStockInDO>() return update(updateObj, new LambdaUpdateWrapper<ErpStockInDO>()
.eq(ErpStockInDO::getId, id).eq(ErpStockInDO::getStatus, status)); .eq(ErpStockInDO::getId, id)
.eq(ErpStockInDO::getStatus, status));
} }
default ErpStockInDO selectByNo(String no) { default ErpStockInDO selectByNo(String no) {
return selectOne(ErpStockInDO::getNo, no); return selectOne(ErpStockInDO::getNo, no);
} }
} }

@ -1,8 +1,11 @@
package cn.iocoder.yudao.module.erp.service.stock; package cn.iocoder.yudao.module.erp.service.stock;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInAuditReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInPageReqVO; import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInSaveReqVO; import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInSaveReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInSubmitReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInApproveRecordDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInDO; 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;
@ -10,76 +13,29 @@ import javax.validation.Valid;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
/**
* ERP Service
*
* @author
*/
public interface ErpStockInService { public interface ErpStockInService {
/**
*
*
* @param createReqVO
* @return
*/
Long createStockIn(@Valid ErpStockInSaveReqVO createReqVO); Long createStockIn(@Valid ErpStockInSaveReqVO createReqVO);
/**
*
*
* @param updateReqVO
*/
void updateStockIn(@Valid ErpStockInSaveReqVO updateReqVO); void updateStockIn(@Valid ErpStockInSaveReqVO updateReqVO);
/** void updateStockInStatus(Long id, Integer status, Integer bizType);
*
* void submitStockInAudit(@Valid ErpStockInSubmitReqVO submitReqVO);
* @param id
* @param status void auditStockIn(@Valid ErpStockInAuditReqVO auditReqVO);
*/
void updateStockInStatus(Long id, Integer status,Integer bizType);
/**
*
*
* @param ids
*/
void deleteStockIn(List<Long> ids); void deleteStockIn(List<Long> ids);
/**
*
*
* @param id
* @return
*/
ErpStockInDO getStockIn(Long id); ErpStockInDO getStockIn(Long id);
/**
*
*
* @param pageReqVO
* @return
*/
PageResult<ErpStockInDO> getStockInPage(ErpStockInPageReqVO pageReqVO); PageResult<ErpStockInDO> getStockInPage(ErpStockInPageReqVO pageReqVO);
// ==================== 入库项 ====================
/**
*
*
* @param inId
* @return
*/
List<ErpStockInItemDO> getStockInItemListByInId(Long inId); List<ErpStockInItemDO> getStockInItemListByInId(Long inId);
/**
* List
*
* @param inIds
* @return List
*/
List<ErpStockInItemDO> getStockInItemListByInIds(Collection<Long> inIds); List<ErpStockInItemDO> getStockInItemListByInIds(Collection<Long> inIds);
List<ErpStockInApproveRecordDO> getStockInApproveRecordList(Long stockInId);
void updateMoldStatus(Long id, Integer status); void updateMoldStatus(Long id, Integer status);
} }

@ -3,19 +3,23 @@ package cn.iocoder.yudao.module.erp.service.stock;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.common.controller.admin.mold.vo.MoldBrandSaveReqVO; import cn.iocoder.yudao.module.common.controller.admin.mold.vo.MoldBrandSaveReqVO;
import cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldBrandDO; import cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldBrandDO;
import cn.iocoder.yudao.module.common.enums.MoldBrandStatusEnum;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInAuditReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInPageReqVO; import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInSaveReqVO; import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInSaveReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutSaveReqVO; import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInSubmitReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO; import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO; import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInApproveRecordDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInDO; 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.dataobject.stock.ErpStockOutDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO; import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.warehousearea.WarehouseAreaDO; import cn.iocoder.yudao.module.erp.dal.dataobject.warehousearea.WarehouseAreaDO;
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInApproveRecordMapper;
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.mysql.stock.ErpStockMapper; import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockMapper;
@ -27,40 +31,62 @@ 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 com.baomidou.mybatisplus.core.toolkit.Wrappers; 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;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.*; import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
// TODO 芋艿:记录操作日志 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
/** import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue;
* ERP Service import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.STOCK_ALERADY_IN;
* import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.STOCK_IN_APPROVE_FAIL;
* @author import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.STOCK_IN_AUDIT_FAIL_RESULT;
*/ import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.STOCK_IN_AUDIT_FAIL_STATUS;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.STOCK_IN_AUDIT_FAIL_USER;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.STOCK_IN_DELETE_FAIL_APPROVE;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.STOCK_IN_DELETE_FAIL_PROCESS;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.STOCK_IN_NOT_EXISTS;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.STOCK_IN_NO_EXISTS;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.STOCK_IN_PROCESS_FAIL;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.STOCK_IN_SUBMIT_FAIL_AUDIT_USER_EMPTY;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.STOCK_IN_SUBMIT_FAIL_STATUS;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.STOCK_IN_SUBMIT_FAIL_USER;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.STOCK_IN_UPDATE_FAIL_APPROVE;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.STOCK_IN_UPDATE_FAIL_PROCESS;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.WAREHOUSE_AREA_NOT_EXISTS;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.WAREHOUSE_LOCATION_WAREHOUSE_AREA_NOT_MATCH;
@Service @Service
@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
private ErpStockInItemMapper stockInItemMapper; private ErpStockInItemMapper stockInItemMapper;
@Resource
private ErpStockInApproveRecordMapper stockInApproveRecordMapper;
@Resource @Resource
private ErpStockMapper erpStockMapper; private ErpStockMapper erpStockMapper;
@Resource @Resource
private ErpNoRedisDAO noRedisDAO; private ErpNoRedisDAO noRedisDAO;
@Resource @Resource
private ErpProductService productService; private ErpProductService productService;
@Resource @Resource
@ -73,154 +99,325 @@ public class ErpStockInServiceImpl implements ErpStockInService {
private MoldBrandService moldBrandService; private MoldBrandService moldBrandService;
@Resource @Resource
private WarehouseAreaService warehouseAreaService; private WarehouseAreaService warehouseAreaService;
@Resource
private AdminUserApi adminUserApi;
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Long createStockIn(ErpStockInSaveReqVO createReqVO) { public Long createStockIn(ErpStockInSaveReqVO createReqVO) {
// 1.1 校验入库项的有效性 List<ErpStockInItemDO> stockInItems = validateStockInItems(createReqVO.getItems(), createReqVO.getInType());
List<ErpStockInItemDO> stockInItems = validateStockInItems(createReqVO.getItems(),createReqVO.getInType()); if (createReqVO.getStockUserId() != null) {
// 1.2 校验供应商 adminUserApi.validateUser(createReqVO.getStockUserId());
//supplierService.validateSupplier(createReqVO.getSupplierId()); }
// 1.3 生成入库单号,并校验唯一性 if (createReqVO.getAuditUserId() != null) {
adminUserApi.validateUser(createReqVO.getAuditUserId());
}
String no = noRedisDAO.generate(ErpNoRedisDAO.STOCK_IN_NO_PREFIX); String no = noRedisDAO.generate(ErpNoRedisDAO.STOCK_IN_NO_PREFIX);
if (stockInMapper.selectByNo(no) != null) { if (stockInMapper.selectByNo(no) != null) {
throw exception(STOCK_IN_NO_EXISTS); throw exception(STOCK_IN_NO_EXISTS);
} }
// 2.1 插入入库单 boolean needAudit = !Boolean.FALSE.equals(createReqVO.getNeedAudit());
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).setStatus(ErpAuditStatus.PROCESS.getStatus()) .setNo(no)
.setNeedAudit(needAudit)
.setStatus(status)
.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);
// 2.2 插入入库单项 stockInItems.forEach(item -> item.setInId(stockIn.getId()));
stockInItems.forEach(o -> {
o.setInId(stockIn.getId());
o.setCount(o.getCount());
});
stockInItemMapper.insertBatch(stockInItems); stockInItemMapper.insertBatch(stockInItems);
// for (ErpStockInItemDO item : stockInItems) {
// MoldDO moldDO = moldService.getMold(item.getProductId()); if (!needAudit) {
// moldDO.setStatus(ErpAuditStatus.PROCESS.getStatus()); // 未审核 applyStockInEffect(stockIn, stockInItems, null);
// moldService.updateMold(BeanUtils.toBean(moldDO, MoldSaveReqVO.class)); createApproveRecord(stockIn.getId(), ACTION_AUTO_APPROVE, null,
// } ErpAuditStatus.APPROVE.getStatus(), null, "无需审核,系统自动入库");
}
return stockIn.getId(); return stockIn.getId();
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void updateStockIn(ErpStockInSaveReqVO updateReqVO) { public void updateStockIn(ErpStockInSaveReqVO updateReqVO) {
// 1.1 校验存在
ErpStockInDO stockIn = validateStockInExists(updateReqVO.getId()); ErpStockInDO stockIn = validateStockInExists(updateReqVO.getId());
if (ErpAuditStatus.APPROVE.getStatus().equals(stockIn.getStatus())) { if (ErpAuditStatus.APPROVE.getStatus().equals(stockIn.getStatus())) {
throw exception(STOCK_IN_UPDATE_FAIL_APPROVE, stockIn.getNo()); throw exception(STOCK_IN_UPDATE_FAIL_APPROVE, stockIn.getNo());
} }
// 1.2 校验供应商 if (ErpAuditStatus.PROCESS.getStatus().equals(stockIn.getStatus())) {
//supplierService.validateSupplier(updateReqVO.getSupplierId()); throw exception(STOCK_IN_UPDATE_FAIL_PROCESS, stockIn.getNo());
// 1.3 校验入库项的有效性 }
List<ErpStockInItemDO> stockInItems = validateStockInItems(updateReqVO.getItems(),updateReqVO.getInType()); if (updateReqVO.getStockUserId() != null) {
adminUserApi.validateUser(updateReqVO.getStockUserId());
// 2.1 更新入库单 }
if (updateReqVO.getAuditUserId() != null) {
adminUserApi.validateUser(updateReqVO.getAuditUserId());
}
List<ErpStockInItemDO> stockInItems = validateStockInItems(updateReqVO.getItems(), updateReqVO.getInType());
boolean needAudit = !Boolean.FALSE.equals(updateReqVO.getNeedAudit());
ErpStockInDO updateObj = BeanUtils.toBean(updateReqVO, ErpStockInDO.class, in -> in ErpStockInDO updateObj = BeanUtils.toBean(updateReqVO, ErpStockInDO.class, in -> in
.setNeedAudit(needAudit)
.setTotalCount(getSumValue(stockInItems, ErpStockInItemDO::getCount, BigDecimal::add)) .setTotalCount(getSumValue(stockInItems, ErpStockInItemDO::getCount, BigDecimal::add))
.setTotalPrice(getSumValue(stockInItems, ErpStockInItemDO::getTotalPrice, BigDecimal::add))); .setTotalPrice(getSumValue(stockInItems, ErpStockInItemDO::getTotalPrice, BigDecimal::add, BigDecimal.ZERO)));
stockInMapper.updateById(updateObj); stockInMapper.updateById(updateObj);
// 2.2 更新入库单项
updateStockInItemList(updateReqVO.getId(), stockInItems); updateStockInItemList(updateReqVO.getId(), stockInItems);
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void updateStockInStatus(Long id, Integer status,Integer bizType) { public void updateStockInStatus(Long id, Integer status, Integer bizType) {
boolean approve = ErpAuditStatus.APPROVE.getStatus().equals(status);
ErpStockInDO stockIn = validateStockInExists(id); ErpStockInDO stockIn = validateStockInExists(id);
if (stockIn.getStatus().equals(status)) { boolean approve = ErpAuditStatus.APPROVE.getStatus().equals(status);
if (approve) {
if (!ErpAuditStatus.PROCESS.getStatus().equals(stockIn.getStatus())) {
throw exception(STOCK_IN_APPROVE_FAIL);
}
} else {
if (!ErpAuditStatus.APPROVE.getStatus().equals(stockIn.getStatus())) {
throw exception(STOCK_IN_PROCESS_FAIL);
}
}
int updateCount = stockInMapper.updateByIdAndStatus(id, stockIn.getStatus(), new ErpStockInDO().setStatus(status));
if (updateCount == 0) {
throw exception(approve ? STOCK_IN_APPROVE_FAIL : STOCK_IN_PROCESS_FAIL); throw exception(approve ? STOCK_IN_APPROVE_FAIL : STOCK_IN_PROCESS_FAIL);
} }
List<ErpStockInItemDO> stockInItems = stockInItemMapper.selectListByInId(id);
if (approve) {
applyStockInEffect(stockIn, stockInItems, bizType);
} else {
cancelStockInEffect(stockIn, stockInItems, bizType);
}
}
int updateCount = stockInMapper.updateByIdAndStatus(id, stockIn.getStatus(), @Override
new ErpStockInDO().setStatus(status)); @Transactional(rollbackFor = Exception.class)
public void submitStockInAudit(ErpStockInSubmitReqVO submitReqVO) {
ErpStockInDO stockIn = validateStockInExists(submitReqVO.getId());
Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
if (!Objects.equals(NumberUtils.parseLong(stockIn.getCreator()), loginUserId)) {
throw exception(STOCK_IN_SUBMIT_FAIL_USER);
}
if (!ErpAuditStatus.DRAFT.getStatus().equals(stockIn.getStatus())
&& !ErpAuditStatus.UN_APPROVE.getStatus().equals(stockIn.getStatus())) {
throw exception(STOCK_IN_SUBMIT_FAIL_STATUS);
}
Long auditUserId = submitReqVO.getAuditUserId() != null ? submitReqVO.getAuditUserId() : stockIn.getAuditUserId();
if (auditUserId == null) {
throw exception(STOCK_IN_SUBMIT_FAIL_AUDIT_USER_EMPTY);
}
adminUserApi.validateUser(auditUserId);
Integer fromStatus = stockIn.getStatus();
ErpStockInDO updateObj = new ErpStockInDO()
.setAuditUserId(auditUserId)
.setNeedAudit(true)
.setStatus(ErpAuditStatus.PROCESS.getStatus());
int updateCount = stockInMapper.updateByIdAndStatus(stockIn.getId(), fromStatus, updateObj);
if (updateCount == 0) { if (updateCount == 0) {
throw exception(approve ? STOCK_IN_APPROVE_FAIL : STOCK_IN_PROCESS_FAIL); throw exception(STOCK_IN_SUBMIT_FAIL_STATUS);
}
createApproveRecord(stockIn.getId(), ACTION_SUBMIT, fromStatus,
ErpAuditStatus.PROCESS.getStatus(), auditUserId, submitReqVO.getRemark());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void auditStockIn(ErpStockInAuditReqVO auditReqVO) {
ErpStockInDO stockIn = validateStockInExists(auditReqVO.getId());
if (!ErpAuditStatus.PROCESS.getStatus().equals(stockIn.getStatus())) {
throw exception(STOCK_IN_AUDIT_FAIL_STATUS);
}
Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
if (!Objects.equals(stockIn.getAuditUserId(), loginUserId)) {
throw exception(STOCK_IN_AUDIT_FAIL_USER);
}
if (!ErpAuditStatus.APPROVE.getStatus().equals(auditReqVO.getStatus())
&& !ErpAuditStatus.UN_APPROVE.getStatus().equals(auditReqVO.getStatus())) {
throw exception(STOCK_IN_AUDIT_FAIL_RESULT);
} }
List<ErpStockInItemDO> stockInItems = stockInItemMapper.selectListByInId(id); Integer fromStatus = stockIn.getStatus();
int updateCount = stockInMapper.updateByIdAndStatus(stockIn.getId(), fromStatus,
new ErpStockInDO().setStatus(auditReqVO.getStatus()));
if (updateCount == 0) {
throw exception(STOCK_IN_AUDIT_FAIL_STATUS);
}
List<ErpStockInItemDO> stockInItems = stockInItemMapper.selectListByInId(stockIn.getId());
if (ErpAuditStatus.APPROVE.getStatus().equals(auditReqVO.getStatus())) {
applyStockInEffect(stockIn, stockInItems, null);
}
Long targetUserId = NumberUtils.parseLong(stockIn.getCreator());
createApproveRecord(stockIn.getId(), ErpAuditStatus.APPROVE.getStatus().equals(auditReqVO.getStatus())
? ACTION_APPROVE : ACTION_REJECT,
fromStatus, auditReqVO.getStatus(), targetUserId, auditReqVO.getRemark());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteStockIn(List<Long> ids) {
List<ErpStockInDO> stockIns = stockInMapper.selectBatchIds(ids);
if (CollUtil.isEmpty(stockIns)) {
return;
}
stockIns.forEach(stockIn -> {
if (ErpAuditStatus.APPROVE.getStatus().equals(stockIn.getStatus())) {
throw exception(STOCK_IN_DELETE_FAIL_APPROVE, stockIn.getNo());
}
if (ErpAuditStatus.PROCESS.getStatus().equals(stockIn.getStatus())) {
throw exception(STOCK_IN_DELETE_FAIL_PROCESS, stockIn.getNo());
}
});
stockIns.forEach(stockIn -> {
stockInMapper.deleteById(stockIn.getId());
stockInItemMapper.deleteByInId(stockIn.getId());
stockInApproveRecordMapper.deleteByStockInId(stockIn.getId());
});
}
private ErpStockInDO validateStockInExists(Long id) {
ErpStockInDO stockIn = stockInMapper.selectById(id);
if (stockIn == null) {
throw exception(STOCK_IN_NOT_EXISTS);
}
return stockIn;
}
@Override
public ErpStockInDO getStockIn(Long id) {
return stockInMapper.selectById(id);
}
@Override
public PageResult<ErpStockInDO> getStockInPage(ErpStockInPageReqVO pageReqVO) {
return stockInMapper.selectPage(pageReqVO);
}
@Override
public List<ErpStockInItemDO> getStockInItemListByInId(Long inId) {
return stockInItemMapper.selectListByInId(inId);
}
@Override
public List<ErpStockInItemDO> getStockInItemListByInIds(Collection<Long> inIds) {
if (CollUtil.isEmpty(inIds)) {
return Collections.emptyList();
}
return stockInItemMapper.selectListByInIds(inIds);
}
@Override
public List<ErpStockInApproveRecordDO> getStockInApproveRecordList(Long stockInId) {
return stockInApproveRecordMapper.selectListByStockInId(stockInId);
}
@Override
public void updateMoldStatus(Long id, Integer status) {
ErpStockInDO stockIn = validateStockInExists(id);
stockIn.setStatus(status);
stockInMapper.updateById(stockIn);
}
private void applyStockInEffect(ErpStockInDO stockIn, List<ErpStockInItemDO> stockInItems, Integer bizType) {
operateStockInEffect(stockIn, stockInItems, true, bizType);
}
private void cancelStockInEffect(ErpStockInDO stockIn, List<ErpStockInItemDO> stockInItems, Integer bizType) {
operateStockInEffect(stockIn, stockInItems, false, bizType);
}
private void operateStockInEffect(ErpStockInDO stockIn, List<ErpStockInItemDO> stockInItems,
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
: (approve ? ErpStockRecordBizTypeEnum.OTHER_IN.getType()
: ErpStockRecordBizTypeEnum.OTHER_IN_CANCEL.getType());
stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO( stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO(
stockInItem.getProductId(), moldDO.getId(), stockInItem.getWarehouseId(), count, stockInItem.getProductId(), moldDO.getId(), stockInItem.getWarehouseId(), count,
ErpStockRecordBizTypeEnum.OTHER_IN.getType(), stockInItem.getInId(), stockInItem.getId(), stockIn.getNo(), stockIn.getInTime())); recordBizType, stockInItem.getInId(), stockInItem.getId(), stockIn.getNo(), stockIn.getInTime()));
if (approve && itemNeedUpdateMoldStatus(moldDO)) {
moldDO.setStatus(MoldBrandStatusEnum.STANDBY.getStatus());
moldBrandService.updateMoldBrand(BeanUtils.toBean(moldDO, MoldBrandSaveReqVO.class));
}
} else { } else {
ErpProductDO productDO = productService.getProduct(stockInItem.getProductId()); ErpProductDO productDO = productService.getProduct(stockInItem.getProductId());
Integer recordBizType = bizType != null ? bizType
: (approve ? ErpStockRecordBizTypeEnum.getTypeByName(stockIn.getInType())
: ErpStockRecordBizTypeEnum.getTypeByName(stockIn.getInType(), 10));
stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO( stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO(
stockInItem.getProductId(), productDO.getCategoryId(), stockInItem.getWarehouseId(), count, stockInItem.getProductId(), productDO.getCategoryId(), stockInItem.getWarehouseId(), count,
ErpStockRecordBizTypeEnum.getTypeByName(stockIn.getInType(), status), stockInItem.getInId(), stockInItem.getId(), stockIn.getNo(), stockIn.getInTime())); recordBizType, stockInItem.getInId(), stockInItem.getId(), stockIn.getNo(), stockIn.getInTime()));
} }
}); });
}
if (Objects.equals(stockIn.getInType(), "模具入库")) { private boolean itemNeedUpdateMoldStatus(MoldBrandDO moldDO) {
for (ErpStockInItemDO item : stockInItems) { if (Objects.equals(moldDO.getStatus(), MoldBrandStatusEnum.STANDBY.getStatus())) {
if (item.getMoldSetId() != null) { throw exception(STOCK_ALERADY_IN, moldDO.getCode() + "-" + moldDO.getName());
MoldBrandDO moldDO = moldBrandService.getMoldBrand(item.getMoldSetId());
if (Objects.equals(moldDO.getStatus(), 1)) {
throw exception(STOCK_ALERADY_IN, moldDO.getCode() + "-" + moldDO.getName());
}
moldDO.setStatus(1);
moldBrandService.updateMoldBrand(BeanUtils.toBean(moldDO, MoldBrandSaveReqVO.class));
}
}
} }
return true;
}
private void createApproveRecord(Long stockInId, String actionType, Integer fromStatus,
Integer toStatus, Long targetUserId, String remark) {
stockInApproveRecordMapper.insert(ErpStockInApproveRecordDO.builder()
.stockInId(stockInId)
.actionType(actionType)
.fromStatus(fromStatus)
.toStatus(toStatus)
.targetUserId(targetUserId)
.remark(remark)
.build());
} }
private List<ErpStockInItemDO> validateStockInItems(List<ErpStockInSaveReqVO.Item> list,String outType) { private List<ErpStockInItemDO> validateStockInItems(List<ErpStockInSaveReqVO.Item> list, String inType) {
validateWarehouseAreas(list); validateWarehouseAreas(list);
if (Objects.equals(outType, "模具入库")) { if (Objects.equals(inType, "妯″叿鍏ュ簱")) {
List<MoldBrandDO> moldList = moldBrandService.validMoldList( List<MoldBrandDO> moldList = moldBrandService.validMoldList(convertSet(list, ErpStockInSaveReqVO.Item::getMoldSetId));
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(
warehouseService.getWarehouseList(convertSet(list, ErpStockInSaveReqVO.Item::getWarehouseId)), warehouseService.getWarehouseList(convertSet(list, ErpStockInSaveReqVO.Item::getWarehouseId)),
ErpWarehouseDO::getId); ErpWarehouseDO::getId);
Map<Long, WarehouseAreaDO> areaMap = warehouseAreaService.getWarehouseAreaMap( Map<Long, WarehouseAreaDO> areaMap = warehouseAreaService.getWarehouseAreaMap(
convertSet(list, ErpStockInSaveReqVO.Item::getAreaId)); convertSet(list, ErpStockInSaveReqVO.Item::getAreaId));
return convertList(list, o -> { return convertList(list, item -> {
MoldBrandDO moldBrand = moldMap.get(o.getMoldSetId()); MoldBrandDO moldBrand = moldMap.get(item.getMoldSetId());
return ErpStockInItemDO.builder() return ErpStockInItemDO.builder()
.id(null) .id(item.getId())
.moldSetId(moldBrand.getId()) .moldSetId(moldBrand.getId())
.moldSetName(moldBrand.getName()) .moldSetName(moldBrand.getName())
.warehouseId(o.getWarehouseId()) .warehouseId(item.getWarehouseId())
.warehouseName(warehouseMap.containsKey(o.getWarehouseId()) ? warehouseMap.get(o.getWarehouseId()).getName() : null) .warehouseName(warehouseMap.containsKey(item.getWarehouseId()) ? warehouseMap.get(item.getWarehouseId()).getName() : null)
.areaId(o.getAreaId()) .areaId(item.getAreaId())
.areaName(areaMap.containsKey(o.getAreaId()) ? areaMap.get(o.getAreaId()).getAreaName() : null) .areaName(areaMap.containsKey(item.getAreaId()) ? areaMap.get(item.getAreaId()).getAreaName() : null)
.productId(moldBrand.getId()) .productId(moldBrand.getId())
.productUnitId(null) .productUnitId(null)
.productPrice(o.getProductPrice()) .productPrice(item.getProductPrice())
.count(o.getCount()) .count(item.getCount())
.totalPrice(MoneyUtils.priceMultiply(o.getProductPrice(), o.getCount())) .packagingSchemeId(item.getPackagingSchemeId())
.remark(o.getRemark()) .inputUnitType(item.getInputUnitType())
.deviceId(o.getDeviceId()) .inputCount(item.getInputCount())
.totalPrice(MoneyUtils.priceMultiply(item.getProductPrice(), item.getCount()))
.remark(item.getRemark())
.deviceId(item.getDeviceId())
.build(); .build();
}); });
} else {
List<ErpProductDO> productList = productService.validProductList(
convertSet(list, ErpStockInSaveReqVO.Item::getProductId));
Map<Long, ErpProductDO> productMap = convertMap(productList, ErpProductDO::getId);
Map<Long, ErpWarehouseDO> warehouseMap = convertMap(
warehouseService.getWarehouseList(convertSet(list, ErpStockInSaveReqVO.Item::getWarehouseId)),
ErpWarehouseDO::getId);
Map<Long, WarehouseAreaDO> areaMap = warehouseAreaService.getWarehouseAreaMap(
convertSet(list, ErpStockInSaveReqVO.Item::getAreaId));
return convertList(list, o -> BeanUtils.toBean(o, ErpStockInItemDO.class, item -> item
.setWarehouseName(warehouseMap.containsKey(item.getWarehouseId()) ? warehouseMap.get(item.getWarehouseId()).getName() : null)
.setAreaName(areaMap.containsKey(item.getAreaId()) ? areaMap.get(item.getAreaId()).getAreaName() : null)
.setProductUnitId(productMap.get(item.getProductId()).getUnitId())
.setTotalPrice(MoneyUtils.priceMultiply(item.getProductPrice(), item.getCount()))));
} }
List<ErpProductDO> productList = productService.validProductList(convertSet(list, ErpStockInSaveReqVO.Item::getProductId));
Map<Long, ErpProductDO> productMap = convertMap(productList, ErpProductDO::getId);
Map<Long, ErpWarehouseDO> warehouseMap = convertMap(
warehouseService.getWarehouseList(convertSet(list, ErpStockInSaveReqVO.Item::getWarehouseId)),
ErpWarehouseDO::getId);
Map<Long, WarehouseAreaDO> areaMap = warehouseAreaService.getWarehouseAreaMap(
convertSet(list, ErpStockInSaveReqVO.Item::getAreaId));
return convertList(list, item -> BeanUtils.toBean(item, ErpStockInItemDO.class, target -> target
.setWarehouseName(warehouseMap.containsKey(target.getWarehouseId()) ? warehouseMap.get(target.getWarehouseId()).getName() : null)
.setAreaName(areaMap.containsKey(target.getAreaId()) ? areaMap.get(target.getAreaId()).getAreaName() : null)
.setProductUnitId(productMap.get(target.getProductId()).getUnitId())
.setTotalPrice(MoneyUtils.priceMultiply(target.getProductPrice(), target.getCount()))));
} }
private void validateWarehouseAreas(List<ErpStockInSaveReqVO.Item> list) { private void validateWarehouseAreas(List<ErpStockInSaveReqVO.Item> list) {
@ -246,9 +443,9 @@ public class ErpStockInServiceImpl implements ErpStockInService {
&& newList.stream().anyMatch(item -> item.getMoldSetId() != null); && newList.stream().anyMatch(item -> item.getMoldSetId() != null);
if (moldStockIn) { if (moldStockIn) {
stockInItemMapper.deleteByInId(id); stockInItemMapper.deleteByInId(id);
newList.forEach(o -> { newList.forEach(item -> {
o.setId(null); item.setId(null);
o.setInId(id); item.setInId(id);
}); });
stockInItemMapper.insertBatch(newList); stockInItemMapper.insertBatch(newList);
return; return;
@ -256,9 +453,9 @@ public class ErpStockInServiceImpl implements ErpStockInService {
List<ErpStockInItemDO> oldList = stockInItemMapper.selectListByInId(id); List<ErpStockInItemDO> oldList = stockInItemMapper.selectListByInId(id);
List<List<ErpStockInItemDO>> diffList = diffList(oldList, newList, List<List<ErpStockInItemDO>> diffList = diffList(oldList, newList,
(oldVal, newVal) -> oldVal.getId().equals(newVal.getId())); (oldVal, newVal) -> Objects.equals(oldVal.getId(), newVal.getId()));
if (CollUtil.isNotEmpty(diffList.get(0))) { if (CollUtil.isNotEmpty(diffList.get(0))) {
diffList.get(0).forEach(o -> o.setInId(id)); diffList.get(0).forEach(item -> item.setInId(id));
stockInItemMapper.insertBatch(diffList.get(0)); stockInItemMapper.insertBatch(diffList.get(0));
} }
if (CollUtil.isNotEmpty(diffList.get(1))) { if (CollUtil.isNotEmpty(diffList.get(1))) {
@ -268,68 +465,5 @@ public class ErpStockInServiceImpl implements ErpStockInService {
stockInItemMapper.deleteBatchIds(convertList(diffList.get(2), ErpStockInItemDO::getId)); stockInItemMapper.deleteBatchIds(convertList(diffList.get(2), ErpStockInItemDO::getId));
} }
} }
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteStockIn(List<Long> ids) {
// 1. 校验不处于已审批
List<ErpStockInDO> stockIns = stockInMapper.selectBatchIds(ids);
if (CollUtil.isEmpty(stockIns)) {
return;
}
stockIns.forEach(stockIn -> {
if (ErpAuditStatus.APPROVE.getStatus().equals(stockIn.getStatus())) {
throw exception(STOCK_IN_DELETE_FAIL_APPROVE, stockIn.getNo());
}
});
// 2. 遍历删除,并记录操作日志
stockIns.forEach(stockIn -> {
// 2.1 删除入库单
stockInMapper.deleteById(stockIn.getId());
// 2.2 删除入库单项
stockInItemMapper.deleteByInId(stockIn.getId());
});
}
private ErpStockInDO validateStockInExists(Long id) {
ErpStockInDO stockIn = stockInMapper.selectById(id);
if (stockIn == null) {
throw exception(STOCK_IN_NOT_EXISTS);
}
return stockIn;
}
@Override
public ErpStockInDO getStockIn(Long id) {
return stockInMapper.selectById(id);
}
@Override
public PageResult<ErpStockInDO> getStockInPage(ErpStockInPageReqVO pageReqVO) {
return stockInMapper.selectPage(pageReqVO);
}
// ==================== 入库项 ====================
@Override
public List<ErpStockInItemDO> getStockInItemListByInId(Long inId) {
return stockInItemMapper.selectListByInId(inId);
}
@Override
public List<ErpStockInItemDO> getStockInItemListByInIds(Collection<Long> inIds) {
if (CollUtil.isEmpty(inIds)) {
return Collections.emptyList();
}
return stockInItemMapper.selectListByInIds(inIds);
}
@Override
public void updateMoldStatus(Long id, Integer status) {
ErpStockInDO stockIn = validateStockInExists(id);
stockIn.setStatus(status);
stockInMapper.updateById(stockIn);
}
} }

Loading…
Cancel
Save