fix:修改模具出库及模具入库接口

main
HuangHuiKang 1 week ago
parent 71e1e85bd5
commit 2a842d54f4

@ -20,6 +20,7 @@ import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO;
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.service.mold.MoldBrandService;
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.purchase.ErpSupplierService;
import cn.iocoder.yudao.module.erp.service.stock.ErpStockInService;
@ -47,6 +48,7 @@ import java.util.concurrent.TimeUnit;
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.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.convertSet;
@ -67,6 +69,8 @@ public class ErpStockInController {
@Resource
private MoldBrandService moldBrandService;
@Resource
private MoldService moldService;
@Resource
private AdminUserApi adminUserApi;
@ -118,14 +122,25 @@ public class ErpStockInController {
List<ErpStockInItemDO> stockInItemList = stockInService.getStockInItemListByInId(id);
if (Objects.equals(stockIn.getInType(), "模具入库")) {
Map<Long, MoldBrandDO> moldMap = moldBrandService.getMoldVOMap(
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);
MapUtils.findAndThen(moldMap, item.getProductId(), mold -> item.setProductName(mold.getName())
.setProductBarCode(mold.getCode()));
}))));
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<>()));
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));
@ -172,35 +187,40 @@ public class ErpStockInController {
if (CollUtil.isEmpty(pageResult.getList())) {
return PageResult.empty(pageResult.getTotal());
}
// 1.1 入库项
List<ErpStockInItemDO> stockInItemList = stockInService.getStockInItemListByInIds(
convertSet(pageResult.getList(), ErpStockInDO::getId));
Map<Long, List<ErpStockInItemDO>> stockInItemMap = convertMultiMap(stockInItemList, ErpStockInItemDO::getInId);
// 1.2 产品信息
Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap(
convertSet(stockInItemList, ErpStockInItemDO::getProductId));
// 1.3 供应商信息
Map<Long, ErpSupplierDO> supplierMap = supplierService.getSupplierMap(
convertSet(pageResult.getList(), ErpStockInDO::getSupplierId));
// 1.4 管理员信息
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
convertSet(pageResult.getList(), stockIn -> Long.parseLong(stockIn.getCreator())));
// 1.7 模具信息
Map<Long, MoldBrandDO> moldMap = moldBrandService.getMoldVOMap(
convertSet(stockInItemList, ErpStockInItemDO::getProductId));
convertSet(stockInItemList, ErpStockInItemDO::getMoldSetId));
Map<Long, List<cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldDO>> moldListMap = moldService.getMoldListMapByBrandIds(
convertSet(stockInItemList, ErpStockInItemDO::getMoldSetId));
// 2. 开始拼接
return BeanUtils.toBean(pageResult, ErpStockInRespVO.class, stockIn -> {
if (Objects.equals(stockIn.getInType(), "模具入库")) {
stockIn.setItems(BeanUtils.toBean(stockInItemMap.get(stockIn.getId()), ErpStockInRespVO.Item.class,
item -> MapUtils.findAndThen(moldMap, item.getProductId(), mold -> item.setProductName(mold.getName())
.setProductBarCode(mold.getCode()))));
stockIn.setProductNames(CollUtil.join(stockIn.getItems(), "", ErpStockInRespVO.Item::getProductName));
List<ErpStockInItemDO> itemDOS = stockInItemMap.get(stockIn.getId());
stockIn.setItems(convertList(itemDOS, source -> {
ErpStockInRespVO.Item item = BeanUtils.toBean(source, ErpStockInRespVO.Item.class);
item.setMoldSetId(source.getMoldSetId());
item.setMoldSetName(source.getMoldSetName());
item.setMoldList(moldListMap.getOrDefault(source.getMoldSetId(), new ArrayList<>()));
MapUtils.findAndThen(moldMap, source.getMoldSetId(), mold -> item.setMoldSetName(mold.getName())
.setProductName(mold.getName())
.setProductBarCode(mold.getCode()));
return item;
}));
stockIn.setMoldSetNames(CollUtil.join(stockIn.getItems(), ",", ErpStockInRespVO.Item::getMoldSetName));
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.setProductNames(CollUtil.join(stockIn.getItems(), "", ErpStockInRespVO.Item::getProductName));
stockIn.setProductNames(CollUtil.join(stockIn.getItems(), ",", ErpStockInRespVO.Item::getProductName));
}
MapUtils.findAndThen(supplierMap, stockIn.getSupplierId(), supplier -> stockIn.setSupplierName(supplier.getName()));
@ -232,4 +252,14 @@ public class ErpStockInController {
return success(buildStockInVOPageResult(pageResult));
}
@PutMapping("/update-mold-status")
@Operation(summary = "更新模具入库单的状态")
@PreAuthorize("@ss.hasPermission('erp:stock-out:update-status')")
@RateLimiter(count = 1, timeUnit = TimeUnit.SECONDS)
public CommonResult<Boolean> updateMoldStatus(@RequestParam("id") Long id,
@RequestParam("status") Integer status) {
stockInService.updateMoldStatus(id, status);
return success(true);
}
}

@ -9,7 +9,7 @@ import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.ratelimiter.core.annotation.RateLimiter;
import cn.iocoder.yudao.module.common.controller.admin.mold.vo.MoldRespVO;
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.stock.vo.out.ErpStockOutPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutRespVO;
@ -20,6 +20,7 @@ import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO;
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.ErpStockOutItemDO;
import cn.iocoder.yudao.module.erp.service.mold.MoldBrandService;
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.sale.ErpCustomerService;
@ -48,6 +49,7 @@ import java.util.concurrent.TimeUnit;
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.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.convertSet;
@ -66,6 +68,8 @@ public class ErpStockOutController {
@Resource
private ErpCustomerService customerService;
@Resource
private MoldBrandService moldBrandService;
@Resource
private MoldService moldService;
@ -98,6 +102,17 @@ public class ErpStockOutController {
return success(true);
}
@PutMapping("/update-mold-status")
@Operation(summary = "更新模具出库单的状态")
@PreAuthorize("@ss.hasPermission('erp:stock-out:update-status')")
@RateLimiter(count = 1, timeUnit = TimeUnit.SECONDS)
public CommonResult<Boolean> updateMoldStatus(@RequestParam("id") Long id,
@RequestParam("status") Integer status) {
stockOutService.updateMoldStatus(id, status);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除其它出库单")
@Parameter(name = "ids", description = "编号数组", required = true)
@ -118,15 +133,26 @@ public class ErpStockOutController {
}
List<ErpStockOutItemDO> stockOutItemList = stockOutService.getStockOutItemListByOutId(id);
if (Objects.equals(stockOut.getOutType(), "模具出库")) {
Map<Long, MoldRespVO> moldMap = moldService.getMoldVOMap(
convertSet(stockOutItemList, ErpStockOutItemDO::getProductId));
return success(BeanUtils.toBean(stockOut, ErpStockOutRespVO.class, stockOutVO ->
stockOutVO.setItems(BeanUtils.toBean(stockOutItemList, ErpStockOutRespVO.Item.class, item -> {
ErpStockDO stock = stockService.getStock(item.getProductId(), item.getWarehouseId());
item.setStockCount(stock != null ? stock.getCount() : BigDecimal.ZERO);
MapUtils.findAndThen(moldMap, item.getProductId(), mold -> item.setProductName(mold.getName())
.setProductBarCode(mold.getCode()).setProductUnitName(mold.getUnitName()));
}))));
Map<Long, MoldBrandDO> moldMap = moldBrandService.getMoldVOMap(
convertSet(stockOutItemList, ErpStockOutItemDO::getMoldSetId));
Map<Long, List<cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldDO>> moldListMap = moldService.getMoldListMapByBrandIds(
convertSet(stockOutItemList, ErpStockOutItemDO::getMoldSetId));
return success(BeanUtils.toBean(stockOut, ErpStockOutRespVO.class, stockOutVO -> {
stockOutVO.setItems(convertList(stockOutItemList, source -> {
ErpStockOutRespVO.Item item = BeanUtils.toBean(source, ErpStockOutRespVO.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<>()));
MapUtils.findAndThen(moldMap, source.getMoldSetId(), mold -> item.setMoldSetName(mold.getName())
.setProductName(mold.getName())
.setProductBarCode(mold.getCode()));
return item;
}));
stockOutVO.setMoldSetNames(CollUtil.join(stockOutVO.getItems(), "?", ErpStockOutRespVO.Item::getMoldSetName));
stockOutVO.setProductNames(stockOutVO.getMoldSetNames());
}));
} else {
Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap(
convertSet(stockOutItemList, ErpStockOutItemDO::getProductId));
@ -172,40 +198,44 @@ public class ErpStockOutController {
if (CollUtil.isEmpty(pageResult.getList())) {
return PageResult.empty(pageResult.getTotal());
}
// 1.1 出库项
List<ErpStockOutItemDO> stockOutItemList = stockOutService.getStockOutItemListByOutIds(
convertSet(pageResult.getList(), ErpStockOutDO::getId));
Map<Long, List<ErpStockOutItemDO>> stockOutItemMap = convertMultiMap(stockOutItemList, ErpStockOutItemDO::getOutId);
// 1.2 产品信息
Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap(
convertSet(stockOutItemList, ErpStockOutItemDO::getProductId));
// 1.3 客户信息
Map<Long, ErpCustomerDO> customerMap = customerService.getCustomerMap(
convertSet(pageResult.getList(), ErpStockOutDO::getCustomerId));
// 1.5 管理员信息
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
convertSet(pageResult.getList(), stockOut -> Long.parseLong(stockOut.getCreator())));
// 1.6 领料员信息
Map<Long, AdminUserRespDTO> responserMap = adminUserApi.getUserMap(
convertSet(pageResult.getList(), ErpStockOutDO::getResponserId));
// 1.7 模具信息
Map<Long, MoldRespVO> moldMap = moldService.getMoldVOMap(
convertSet(stockOutItemList, ErpStockOutItemDO::getProductId));
Map<Long, MoldBrandDO> moldMap = moldBrandService.getMoldVOMap(
convertSet(stockOutItemList, ErpStockOutItemDO::getMoldSetId));
Map<Long, List<cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldDO>> moldListMap = moldService.getMoldListMapByBrandIds(
convertSet(stockOutItemList, ErpStockOutItemDO::getMoldSetId));
// 2. 开始拼接
return BeanUtils.toBean(pageResult, ErpStockOutRespVO.class, stockOut -> {
if (Objects.equals(stockOut.getOutType(), "模具出库")) {
stockOut.setItems(BeanUtils.toBean(stockOutItemMap.get(stockOut.getId()), ErpStockOutRespVO.Item.class,
item -> MapUtils.findAndThen(moldMap, item.getProductId(), mold -> item.setProductName(mold.getName())
.setProductBarCode(mold.getCode()).setProductUnitName(mold.getUnitName()))));
stockOut.setProductNames(CollUtil.join(stockOut.getItems(), "", ErpStockOutRespVO.Item::getProductName));
List<ErpStockOutItemDO> itemDOS = stockOutItemMap.get(stockOut.getId());
stockOut.setItems(convertList(itemDOS, source -> {
ErpStockOutRespVO.Item item = BeanUtils.toBean(source, ErpStockOutRespVO.Item.class);
item.setMoldSetId(source.getMoldSetId());
item.setMoldSetName(source.getMoldSetName());
item.setMoldList(moldListMap.getOrDefault(source.getMoldSetId(), new ArrayList<>()));
MapUtils.findAndThen(moldMap, source.getMoldSetId(), mold -> item.setMoldSetName(mold.getName())
.setProductName(mold.getName())
.setProductBarCode(mold.getCode()));
return item;
}));
stockOut.setMoldSetNames(CollUtil.join(stockOut.getItems(), ",", ErpStockOutRespVO.Item::getMoldSetName));
stockOut.setProductNames(stockOut.getMoldSetNames());
} else {
stockOut.setItems(BeanUtils.toBean(stockOutItemMap.get(stockOut.getId()), ErpStockOutRespVO.Item.class,
item -> MapUtils.findAndThen(productMap, item.getProductId(), product -> item.setProductName(product.getName())
.setProductBarCode(product.getBarCode()).setProductUnitName(product.getUnitName()))));
stockOut.setProductNames(CollUtil.join(stockOut.getItems(), "", ErpStockOutRespVO.Item::getProductName));
stockOut.setProductNames(CollUtil.join(stockOut.getItems(), ",", ErpStockOutRespVO.Item::getProductName));
}
MapUtils.findAndThen(customerMap, stockOut.getCustomerId(), supplier -> stockOut.setCustomerName(supplier.getName()));
MapUtils.findAndThen(customerMap, stockOut.getCustomerId(), customer -> stockOut.setCustomerName(customer.getName()));
MapUtils.findAndThen(userMap, Long.parseLong(stockOut.getCreator()), user -> stockOut.setCreatorName(user.getNickname()));
MapUtils.findAndThen(responserMap, stockOut.getResponserId(), user -> stockOut.setResponserName(user.getNickname()));
});

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in;
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 com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
@ -76,6 +77,9 @@ public class ErpStockInRespVO {
@ExcelProperty("产品信息")
private String productNames;
@Schema(description = "模具组名称")
private String moldSetNames;
@Data
public static class Item {
@ -113,7 +117,10 @@ public class ErpStockInRespVO {
private String productUnitName;
@Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
private BigDecimal stockCount; // 该字段仅仅在“详情”和“编辑”时使用
private BigDecimal stockCount;
@Schema(description = "子模具详情")
private List<MoldDO> moldList;
}

@ -47,10 +47,10 @@ public class ErpStockInSaveReqVO {
@Data
public static class Item {
@Schema(description = "入库项编号", example = "11756")
@Schema(description = "????????????????", example = "11756")
private Long id;
@Schema(description = "模具组 ID模具入库时传入兼容旧前端仍可使用 id 传值)", example = "1")
@Schema(description = "??? ID?????????", example = "101")
private Long moldSetId;
@Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
@ -58,7 +58,6 @@ public class ErpStockInSaveReqVO {
private Long warehouseId;
@Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
@NotNull(message = "产品编号不能为空")
private Long productId;
@Schema(description = "产品单价", example = "100.00")

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out;
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 com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
@ -78,6 +79,9 @@ public class ErpStockOutRespVO {
@ExcelProperty("产品信息")
private String productNames;
@Schema(description = "模具组名字")
private String moldSetNames;
@Schema(description = "计划单Code", example = "随便")
private String planCode;
@ -88,6 +92,12 @@ public class ErpStockOutRespVO {
@Schema(description = "出库项编号", example = "11756")
private Long id;
@Schema(description = "??? ID", example = "1")
private Long moldSetId;
@Schema(description = "?????", example = "A?")
private String moldSetName;
@Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
private Long warehouseId;
@ -103,9 +113,7 @@ public class ErpStockOutRespVO {
@Schema(description = "备注", example = "随便")
private String remark;
// ========== 关联字段 ==========
@Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "巧克力")
@Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "???")
private String productName;
@Schema(description = "产品条码", requiredMode = Schema.RequiredMode.REQUIRED, example = "A9985")
private String productBarCode;
@ -113,7 +121,10 @@ public class ErpStockOutRespVO {
private String productUnitName;
@Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
private BigDecimal stockCount; // 该字段仅仅在“详情”和“编辑”时使用
private BigDecimal stockCount;
@Schema(description = "子模具列表")
private List<MoldDO> moldList;
}

@ -49,22 +49,23 @@ public class ErpStockOutSaveReqVO {
@Schema(description = "出库项编号", example = "11756")
private Long id;
@Schema(description = "模具组id", example = "101")
private Long moldSetId;
@Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
// @NotNull(message = "仓库编号不能为空")
private Long warehouseId;
@Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
@NotNull(message = "产品编号不能为空")
@Schema(description = "产品id", example = "3113")
private Long productId;
@Schema(description = "产品单价", example = "100.00")
private BigDecimal productPrice;
@Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
@NotNull(message = "产品数量不能为空")
// @NotNull(message = "产品数量不能为空")
private BigDecimal count;
@Schema(description = "备注", example = "随便")
@Schema(description = "备注", example = "??")
private String remark;
}

@ -29,6 +29,8 @@ public class ErpStockOutItemDO extends BaseDO {
*/
@TableId
private Long id;
private Long moldSetId;
private String moldSetName;
/**
*
*

@ -105,5 +105,7 @@ public interface MoldService {
List<MoldDO> getMoldListByIds(Collection<Long> ids);
Map<Long, List<MoldDO>> getMoldListMapByBrandIds(Collection<Long> brandIds);
}

@ -17,6 +17,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;
import cn.iocoder.yudao.module.common.controller.admin.mold.vo.*;
import cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
@ -142,5 +143,17 @@ public class MoldServiceImpl implements MoldService {
if (ids == null || ids.isEmpty()) {
return Collections.emptyList();
}
return moldMapper.selectBatchIds(ids); }
return moldMapper.selectBatchIds(ids);
}
@Override
public Map<Long, List<MoldDO>> getMoldListMapByBrandIds(Collection<Long> brandIds) {
if (CollUtil.isEmpty(brandIds)) {
return Collections.emptyMap();
}
List<MoldDO> moldList = moldMapper.selectList(new LambdaQueryWrapperX<MoldDO>()
.inIfPresent(MoldDO::getBrandId, brandIds)
.orderByDesc(MoldDO::getId));
return moldList.stream().collect(Collectors.groupingBy(MoldDO::getBrandId));
}
}

@ -81,4 +81,5 @@ public interface ErpStockInService {
*/
List<ErpStockInItemDO> getStockInItemListByInIds(Collection<Long> inIds);
void updateMoldStatus(Long id, Integer status);
}

@ -13,6 +13,7 @@ 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.ErpStockInDO;
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.mysql.stock.ErpStockInItemMapper;
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInMapper;
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockMapper;
@ -59,6 +60,7 @@ public class ErpStockInServiceImpl implements ErpStockInService {
@Resource
private ErpProductService productService;
@Resource
private ErpWarehouseService warehouseService;
@Resource
private ErpSupplierService supplierService;
@ -128,111 +130,96 @@ public class ErpStockInServiceImpl implements ErpStockInService {
@Transactional(rollbackFor = Exception.class)
public void updateStockInStatus(Long id, Integer status,Integer bizType) {
boolean approve = ErpAuditStatus.APPROVE.getStatus().equals(status);
// 1.1 校验存在
ErpStockInDO stockIn = validateStockInExists(id);
// 1.2 校验状态
if (stockIn.getStatus().equals(status)) {
throw exception(approve ? STOCK_IN_APPROVE_FAIL : STOCK_IN_PROCESS_FAIL);
}
// 2. 更新状态
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);
}
// 3. 变更库存
List<ErpStockInItemDO> stockInItems = stockInItemMapper.selectListByInId(id);
// Integer bizType = approve ? ErpStockRecordBizTypeEnum.OTHER_IN.getType()
// : ErpStockRecordBizTypeEnum.OTHER_IN_CANCEL.getType();
stockInItems.forEach(stockInItem -> {
BigDecimal count = approve ? stockInItem.getCount() : stockInItem.getCount().negate();
if (Objects.equals(stockIn.getInType(), "模具入库")) {
MoldBrandDO moldDO = moldBrandService.getMoldBrand(stockInItem.getProductId());
MoldBrandDO moldDO = moldBrandService.getMoldBrand(stockInItem.getMoldSetId());
stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO(
stockInItem.getProductId(), moldDO.getId(), stockInItem.getWarehouseId(), count,
ErpStockRecordBizTypeEnum.OTHER_IN.getType(), stockInItem.getInId(), stockInItem.getId(), stockIn.getNo(), stockIn.getInTime()));
} else {
ErpProductDO productDO = productService.getProduct(stockInItem.getProductId());
stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO(
stockInItem.getProductId(),productDO.getCategoryId(), stockInItem.getWarehouseId(), count,
ErpStockRecordBizTypeEnum.getTypeByName(stockIn.getInType(),status), stockInItem.getInId(), stockInItem.getId(), stockIn.getNo(), stockIn.getInTime()));
//更新库存
// erpStockMapper.updateStockCount(productDO.getId(), stockInItem.getWarehouseId(), stockInItem.getCount());
// ErpStockDO stock = erpStockMapper.selectByProductIdAndWarehouseId(productDO.getId(), stockInItem.getWarehouseId());
// stock.setCount(stock.getCount() + 1);
// erpStockMapper.updateById(stock);
stockInItem.getProductId(), productDO.getCategoryId(), stockInItem.getWarehouseId(), count,
ErpStockRecordBizTypeEnum.getTypeByName(stockIn.getInType(), status), stockInItem.getInId(), stockInItem.getId(), stockIn.getNo(), stockIn.getInTime()));
}
});
// 更改状态
if (Objects.equals(stockIn.getInType(), "模具入库")) {
for (ErpStockInItemDO item : stockInItems) {
if (item.getProductId() != null) {
MoldBrandDO moldDO = moldBrandService.getMoldBrand(item.getProductId());
// 已经在库
if (item.getMoldSetId() != null) {
MoldBrandDO moldDO = moldBrandService.getMoldBrand(item.getMoldSetId());
if (Objects.equals(moldDO.getStatus(), 1)) {
throw exception(STOCK_ALERADY_IN,moldDO.getCode() + "-" + moldDO.getName());
throw exception(STOCK_ALERADY_IN, moldDO.getCode() + "-" + moldDO.getName());
}
moldDO.setStatus(1); // 在库
moldDO.setStatus(1);
moldBrandService.updateMoldBrand(BeanUtils.toBean(moldDO, MoldBrandSaveReqVO.class));
}
}
}
}
private List<ErpStockInItemDO> validateStockInItems(List<ErpStockInSaveReqVO.Item> list,String outType) {
if (Objects.equals(outType, "模具入库")) {
// 1.1 校验模具存在
// List<MoldDO> moldList = moldService.validMoldList(
// convertSet(list, ErpStockInSaveReqVO.Item::getProductId));
// Map<Long, MoldDO> moldMap = convertMap(moldList, MoldDO::getId);
List<MoldBrandDO> moldList = moldBrandService.validMoldList(
convertSet(list, ErpStockInSaveReqVO.Item::getId));
convertSet(list, ErpStockInSaveReqVO.Item::getMoldSetId));
Map<Long, MoldBrandDO> moldMap = convertMap(moldList, MoldBrandDO::getId);
List<ErpProductDO> productList = productService.validProductList(
convertSet(moldList, MoldBrandDO::getProductId));
Map<Long, ErpProductDO> productMap = convertMap(productList, ErpProductDO::getId);
// 1.2 校验仓库存在
// warehouseService.validWarehouseList(convertSet(
// list, ErpStockInSaveReqVO.Item::getWarehouseId));
// 2. 转化为 ErpStockInItemDO 列表
return convertList(list, o -> BeanUtils.toBean(o, ErpStockInItemDO.class, item -> item
.setProductUnitId(productMap.get(item.getProductId()).getUnitId())
.setTotalPrice(MoneyUtils.priceMultiply(item.getProductPrice(), item.getCount()))));
return convertList(list, o -> {
MoldBrandDO moldBrand = moldMap.get(o.getMoldSetId());
return ErpStockInItemDO.builder()
.id(null)
.moldSetId(moldBrand.getId())
.moldSetName(moldBrand.getName())
.warehouseId(o.getWarehouseId())
.productId(moldBrand.getId())
.productUnitId(null)
.productPrice(o.getProductPrice())
.count(o.getCount())
.totalPrice(MoneyUtils.priceMultiply(o.getProductPrice(), o.getCount()))
.remark(o.getRemark())
.deviceId(o.getDeviceId())
.build();
});
} else {
// 1.1 校验产品存在
List<ErpProductDO> productList = productService.validProductList(
convertSet(list, ErpStockInSaveReqVO.Item::getProductId));
Map<Long, ErpProductDO> productMap = convertMap(productList, ErpProductDO::getId);
// 1.2 校验仓库存在
warehouseService.validWarehouseList(convertSet(
list, ErpStockInSaveReqVO.Item::getWarehouseId));
// 2. 转化为 ErpStockInItemDO 列表
return convertList(list, o -> BeanUtils.toBean(o, ErpStockInItemDO.class, item -> item
.setProductUnitId(productMap.get(item.getProductId()).getUnitId())
.setTotalPrice(MoneyUtils.priceMultiply(item.getProductPrice(), item.getCount()))));
}
}
private void updateStockInItemList(Long id, List<ErpStockInItemDO> newList) {
// 第一步,对比新老数据,获得添加、修改、删除的列表
boolean moldStockIn = CollUtil.isNotEmpty(newList)
&& newList.stream().anyMatch(item -> item.getMoldSetId() != null);
if (moldStockIn) {
stockInItemMapper.deleteByInId(id);
newList.forEach(o -> {
o.setId(null);
o.setInId(id);
});
stockInItemMapper.insertBatch(newList);
return;
}
List<ErpStockInItemDO> oldList = stockInItemMapper.selectListByInId(id);
List<List<ErpStockInItemDO>> diffList = diffList(oldList, newList, // id 不同,就认为是不同的记录
List<List<ErpStockInItemDO>> diffList = diffList(oldList, newList,
(oldVal, newVal) -> oldVal.getId().equals(newVal.getId()));
// 第二步,批量添加、修改、删除
if (CollUtil.isNotEmpty(diffList.get(0))) {
diffList.get(0).forEach(o -> o.setInId(id));
stockInItemMapper.insertBatch(diffList.get(0));
@ -301,4 +288,11 @@ public class ErpStockInServiceImpl implements ErpStockInService {
return stockInItemMapper.selectListByInIds(inIds);
}
@Override
public void updateMoldStatus(Long id, Integer status) {
ErpStockInDO stockIn = validateStockInExists(id);
stockIn.setStatus(status);
stockInMapper.updateById(stockIn);
}
}

@ -82,4 +82,5 @@ public interface ErpStockOutService {
List<ErpStockOutItemDO> getStockOutItemListByOutIds(Collection<Long> outIds);
List<ErpStockOutDO> selectByOutType(List<String> outTypes);
void updateMoldStatus(Long id, Integer status);
}

@ -4,15 +4,12 @@ import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.common.controller.admin.mold.vo.MoldSaveReqVO;
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.mysql.mold.MoldBrandMapper;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutSaveReqVO;
import cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
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.ErpStockOutItemDO;
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockOutItemMapper;
@ -128,55 +125,42 @@ public class ErpStockOutServiceImpl implements ErpStockOutService {
@Transactional(rollbackFor = Exception.class)
public void updateStockOutStatus(Long id, Integer status, Integer bizType) {
boolean approve = ErpAuditStatus.APPROVE.getStatus().equals(status);
// 1.1 校验存在
ErpStockOutDO stockOut = validateStockOutExists(id);
// 1.2 校验状态
if (stockOut.getStatus().equals(status)) {
throw exception(approve ? STOCK_OUT_APPROVE_FAIL : STOCK_OUT_PROCESS_FAIL);
}
// 2. 更新状态
int updateCount = stockOutMapper.updateByIdAndStatus(id, stockOut.getStatus(),
new ErpStockOutDO().setStatus(status));
if (updateCount == 0) {
throw exception(approve ? STOCK_OUT_APPROVE_FAIL : STOCK_OUT_PROCESS_FAIL);
}
// 3. 变更库存
List<ErpStockOutItemDO> stockOutItems = stockOutItemMapper.selectListByOutId(id);
// Integer bizType = approve ? ErpStockRecordBizTypeEnum.OTHER_OUT.getType()
// : ErpStockRecordBizTypeEnum.OTHER_OUT_CANCEL.getType();
stockOutItems.forEach(stockOutItem -> {
BigDecimal count = approve ? stockOutItem.getCount().negate() : stockOutItem.getCount();
if (Objects.equals(stockOut.getOutType(), "模具出库")) {
MoldDO moldDO = moldService.getMold(stockOutItem.getProductId());
MoldBrandDO moldDO = moldBrandService.getMoldBrand(stockOutItem.getMoldSetId());
stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO(
stockOutItem.getProductId(),moldDO.getBrandId(), stockOutItem.getWarehouseId(), count,
ErpStockRecordBizTypeEnum.OTHER_OUT.getType(), stockOutItem.getOutId(), stockOutItem.getId(), stockOut.getNo(),stockOut.getOutTime()));
stockOutItem.getProductId(), moldDO.getId(), stockOutItem.getWarehouseId(), count,
ErpStockRecordBizTypeEnum.OTHER_OUT.getType(), stockOutItem.getOutId(), stockOutItem.getId(), stockOut.getNo(), stockOut.getOutTime()));
} else {
ErpProductRespVO product = productService.getProduct(stockOutItem.getProductId());
stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO(
stockOutItem.getProductId(),product.getCategoryId(), stockOutItem.getWarehouseId(), count,
ErpStockRecordBizTypeEnum.getTypeByName(stockOut.getOutType(),status), stockOutItem.getOutId(), stockOutItem.getId(), stockOut.getNo(),stockOut.getOutTime()));
stockOutItem.getProductId(), product.getCategoryId(), stockOutItem.getWarehouseId(), count,
ErpStockRecordBizTypeEnum.getTypeByName(stockOut.getOutType(), status), stockOutItem.getOutId(), stockOutItem.getId(), stockOut.getNo(), stockOut.getOutTime()));
}
});
// 更改状态
if (Objects.equals(stockOut.getOutType(), "模具出库")) {
for (ErpStockOutItemDO item : stockOutItems) {
if (item.getProductId() != null) {
MoldDO moldDO = moldService.getMold(item.getProductId());
// 已经出库
if (item.getMoldSetId() != null) {
MoldBrandDO moldDO = moldBrandService.getMoldBrand(item.getMoldSetId());
if (Objects.equals(moldDO.getStatus(), 3)) {
throw exception(STOCK_ALERADY_OUT,moldDO.getCode() + "-" + moldDO.getName());
throw exception(STOCK_ALERADY_OUT, moldDO.getCode() + "-" + moldDO.getName());
}
moldDO.setStatus(3); // 在途
moldService.updateMold(BeanUtils.toBean(moldDO, MoldSaveReqVO.class));
moldDO.setStatus(3);
moldBrandService.updateMoldBrand(BeanUtils.toBean(moldDO, MoldBrandSaveReqVO.class));
}
}
}
@ -184,24 +168,28 @@ public class ErpStockOutServiceImpl implements ErpStockOutService {
private List<ErpStockOutItemDO> validateStockOutItems(List<ErpStockOutSaveReqVO.Item> list,String outType) {
if (Objects.equals(outType, "模具出库")) {
// 1.1 校验模具存在
List<MoldBrandDO> moldList = moldBrandService.validMoldList(
convertSet(list, ErpStockOutSaveReqVO.Item::getProductId));
convertSet(list, ErpStockOutSaveReqVO.Item::getMoldSetId));
Map<Long, MoldBrandDO> moldMap = convertMap(moldList, MoldBrandDO::getId);
// 1.2 校验仓库存在
// warehouseService.validWarehouseList(convertSet(list, ErpStockOutSaveReqVO.Item::getWarehouseId));
// 2. 转化为 ErpStockOutItemDO 列表
return convertList(list, o -> BeanUtils.toBean(o, ErpStockOutItemDO.class, item -> item
// .setProductUnitId(moldMap.get(item.getProductId()).getUnitId())
.setTotalPrice(MoneyUtils.priceMultiply(item.getProductPrice(), item.getCount()))));
return convertList(list, o -> {
MoldBrandDO moldBrand = moldMap.get(o.getMoldSetId());
return ErpStockOutItemDO.builder()
.id(null)
.moldSetId(moldBrand.getId())
.moldSetName(moldBrand.getName())
.warehouseId(o.getWarehouseId())
.productId(moldBrand.getId())
.productUnitId(null)
.productPrice(o.getProductPrice())
.count(o.getCount())
.totalPrice(MoneyUtils.priceMultiply(o.getProductPrice(), o.getCount()))
.remark(o.getRemark())
.build();
});
} else {
// 1.1 校验产品存在
List<ErpProductDO> productList = productService.validProductList(
convertSet(list, ErpStockOutSaveReqVO.Item::getProductId));
Map<Long, ErpProductDO> productMap = convertMap(productList, ErpProductDO::getId);
// 1.2 校验仓库存在
// warehouseService.validWarehouseList(convertSet(list, ErpStockOutSaveReqVO.Item::getWarehouseId));
// 2. 转化为 ErpStockOutItemDO 列表
return convertList(list, o -> BeanUtils.toBean(o, ErpStockOutItemDO.class, item -> item
.setProductUnitId(productMap.get(item.getProductId()).getUnitId())
.setTotalPrice(MoneyUtils.priceMultiply(item.getProductPrice(), item.getCount()))));
@ -209,12 +197,21 @@ public class ErpStockOutServiceImpl implements ErpStockOutService {
}
private void updateStockOutItemList(Long id, List<ErpStockOutItemDO> newList) {
// 第一步,对比新老数据,获得添加、修改、删除的列表
boolean moldStockOut = CollUtil.isNotEmpty(newList)
&& newList.stream().anyMatch(item -> item.getMoldSetId() != null);
if (moldStockOut) {
stockOutItemMapper.deleteByOutId(id);
newList.forEach(o -> {
o.setId(null);
o.setOutId(id);
});
stockOutItemMapper.insertBatch(newList);
return;
}
List<ErpStockOutItemDO> oldList = stockOutItemMapper.selectListByOutId(id);
List<List<ErpStockOutItemDO>> diffList = diffList(oldList, newList, // id 不同,就认为是不同的记录
List<List<ErpStockOutItemDO>> diffList = diffList(oldList, newList,
(oldVal, newVal) -> oldVal.getId().equals(newVal.getId()));
// 第二步,批量添加、修改、删除
if (CollUtil.isNotEmpty(diffList.get(0))) {
diffList.get(0).forEach(o -> o.setOutId(id));
stockOutItemMapper.insertBatch(diffList.get(0));
@ -288,5 +285,12 @@ public class ErpStockOutServiceImpl implements ErpStockOutService {
return stockOutMapper.selectByOutType(outTypes);
}
@Override
public void updateMoldStatus(Long id, Integer status) {
ErpStockOutDO stockOut = validateStockOutExists(id);
stockOut.setStatus(status);
stockOutMapper.updateById(stockOut);
}
}
Loading…
Cancel
Save