fix:修改出库单据显示锁定库存字段

main
HuangHuiKang 2 days ago
parent 74df3581ef
commit 20440ed330

@ -25,6 +25,7 @@ import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
@ -84,7 +85,10 @@ public class ErpPalletController {
PageResult<ErpPalletDO> pageResult = palletService.getPalletPage(pageReqVO);
Map<Long, String> qrcodeMap = qrcodeService.selectQrcodeUrlMapByBizTypeAndIds(QrcodeBizTypeEnum.PALLET.getCode(),
convertList(pageResult.getList(), ErpPalletDO::getId));
List<ErpPalletRespVO> list = convertList(pageResult.getList(), pallet -> buildPalletRespVO(pallet, qrcodeMap));
Map<Long, BigDecimal> lockedPackageCountMap = palletService.getLockedPackageCountMap(
convertList(pageResult.getList(), ErpPalletDO::getId));
List<ErpPalletRespVO> list = convertList(pageResult.getList(),
pallet -> buildPalletRespVO(pallet, qrcodeMap, lockedPackageCountMap));
return success(new PageResult<>(list, pageResult.getTotal()));
}
@ -98,7 +102,10 @@ public class ErpPalletController {
PageResult<ErpPalletDO> pageResult = palletService.getPalletPage(pageReqVO);
Map<Long, String> qrcodeMap = qrcodeService.selectQrcodeUrlMapByBizTypeAndIds(QrcodeBizTypeEnum.PALLET.getCode(),
convertList(pageResult.getList(), ErpPalletDO::getId));
List<ErpPalletRespVO> list = convertList(pageResult.getList(), pallet -> buildPalletRespVO(pallet, qrcodeMap));
Map<Long, BigDecimal> lockedPackageCountMap = palletService.getLockedPackageCountMap(
convertList(pageResult.getList(), ErpPalletDO::getId));
List<ErpPalletRespVO> list = convertList(pageResult.getList(),
pallet -> buildPalletRespVO(pallet, qrcodeMap, lockedPackageCountMap));
ExcelUtils.write(response, "托盘.xls", "数据", ErpPalletRespVO.class, list);
}
@ -151,6 +158,13 @@ public class ErpPalletController {
return respVO;
}
private ErpPalletRespVO buildPalletRespVO(ErpPalletDO pallet, Map<Long, String> qrcodeMap,
Map<Long, BigDecimal> lockedPackageCountMap) {
ErpPalletRespVO respVO = buildPalletRespVO(pallet, qrcodeMap);
respVO.setLockedPackageCount(lockedPackageCountMap.getOrDefault(pallet.getId(), BigDecimal.ZERO));
return respVO;
}
private void fillPackagingInfo(ErpPalletRespVO respVO) {
if (respVO == null) {
return;

@ -69,6 +69,9 @@ public class ErpPalletRespVO {
@Schema(description = "当前包数", example = "20")
private BigDecimal packageCount;
@Schema(description = "锁定包数", example = "5")
private BigDecimal lockedPackageCount;
@Schema(description = "二维码", example = "https://xxx.com/qrcode/pallet/1")
@ExcelProperty("二维码")
private String qrcode;

@ -17,6 +17,7 @@ import cn.iocoder.yudao.module.erp.dal.dataobject.pallet.ErpPalletDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO;
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.mysql.stock.ErpStockOutItemMapper;
import cn.iocoder.yudao.module.erp.service.pallet.ErpPalletService;
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
import cn.iocoder.yudao.module.erp.service.stock.ErpStockRecordService;
@ -70,6 +71,10 @@ public class ErpStockController {
private ErpStockRecordService stockRecordService;
@Resource
private ErpPalletService palletService;
@Resource
private ErpStockOutItemMapper stockOutItemMapper;
private static final List<Integer> LOCKED_STOCK_OUT_STATUSES = java.util.Arrays.asList(10, 0, 1);
@GetMapping("/get")
@Operation(summary = "获得产品库存")
@ -174,6 +179,8 @@ public class ErpStockController {
fillPackagingSnapshot(respVO, product);
}
fillDerivedFields(respVO);
respVO.setLockedStockCount(stockOutItemMapper.selectLockedStockCount(
respVO.getProductId(), respVO.getWarehouseId(), respVO.getAreaId(), LOCKED_STOCK_OUT_STATUSES));
respVO.setPalletCount(getPalletCount(respVO));
respVO.setPackagingRule(buildPackagingRule(respVO));
respVO.setStockDisplay(buildStockDisplay(respVO));

@ -39,6 +39,9 @@ public class ErpStockRespVO {
@ExcelProperty("库存数量")
private BigDecimal count;
@Schema(description = "锁定库存数量", example = "10")
private BigDecimal lockedStockCount;
@Schema(description = "产品分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11161")
private Long categoryId;

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.erp.dal.mysql.pallet;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.pallet.enums.ErpPalletStatusEnum;
import cn.iocoder.yudao.module.erp.controller.admin.pallet.vo.ErpPalletPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.pallet.ErpPalletDO;
import org.apache.ibatis.annotations.Mapper;
@ -16,19 +17,29 @@ import java.util.List;
public interface ErpPalletMapper extends BaseMapperX<ErpPalletDO> {
default PageResult<ErpPalletDO> selectPage(ErpPalletPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ErpPalletDO>()
LambdaQueryWrapperX<ErpPalletDO> query = new LambdaQueryWrapperX<ErpPalletDO>()
.likeIfPresent(ErpPalletDO::getCode, reqVO.getCode())
.eqIfPresent(ErpPalletDO::getPalletType, reqVO.getPalletType())
.eqIfPresent(ErpPalletDO::getStatus, reqVO.getStatus())
.neIfPresent(ErpPalletDO::getStatus, reqVO.getExcludeStatus())
.eqIfPresent(ErpPalletDO::getWarehouseId, reqVO.getWarehouseId())
.eqIfPresent(ErpPalletDO::getAreaId, reqVO.getAreaId())
.likeIfPresent(ErpPalletDO::getPlanCode, reqVO.getPlanCode())
.eqIfPresent(ErpPalletDO::getProductId, reqVO.getProductId())
.betweenIfPresent(ErpPalletDO::getPurchaseDate, reqVO.getPurchaseDate())
.betweenIfPresent(ErpPalletDO::getUseDate, reqVO.getUseDate())
.betweenIfPresent(ErpPalletDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(ErpPalletDO::getId));
.orderByDesc(ErpPalletDO::getId);
if (reqVO.getProductId() != null && reqVO.getExcludeStatus() != null && reqVO.getStatus() == null) {
query.and(wrapper -> wrapper
.and(productWrapper -> productWrapper
.eq(ErpPalletDO::getProductId, reqVO.getProductId())
.ne(ErpPalletDO::getStatus, reqVO.getExcludeStatus()))
.or()
.eq(ErpPalletDO::getStatus, ErpPalletStatusEnum.IDLE.getStatus()));
} else {
query.eqIfPresent(ErpPalletDO::getStatus, reqVO.getStatus())
.neIfPresent(ErpPalletDO::getStatus, reqVO.getExcludeStatus())
.eqIfPresent(ErpPalletDO::getProductId, reqVO.getProductId());
}
return selectPage(reqVO, query);
}
default ErpPalletDO selectByCode(String code) {

@ -21,6 +21,7 @@ import java.util.Collections;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
@ -85,11 +86,27 @@ public interface ErpStockMapper extends BaseMapperX<ErpStockDO> {
}
default ErpStockDO selectByProductIdAndWarehouseIdAndAreaId(Long productId, Long warehouseId, Long areaId) {
return selectOne(new LambdaQueryWrapperX<ErpStockDO>()
if (areaId != null) {
return selectOne(new LambdaQueryWrapperX<ErpStockDO>()
.eq(ErpStockDO::getProductId, productId)
.eq(ErpStockDO::getWarehouseId, warehouseId)
.eq(ErpStockDO::getAreaId, areaId));
}
List<ErpStockDO> stockList = selectList(new LambdaQueryWrapperX<ErpStockDO>()
.eq(ErpStockDO::getProductId, productId)
.eq(ErpStockDO::getWarehouseId, warehouseId)
.eq(areaId != null, ErpStockDO::getAreaId, areaId)
.isNull(areaId == null, ErpStockDO::getAreaId));
.eq(ErpStockDO::getWarehouseId, warehouseId));
if (CollUtil.isEmpty(stockList)) {
return null;
}
ErpStockDO stock = stockList.get(0);
stock.setId(null);
stock.setAreaId(null);
stock.setAreaName(null);
stock.setCount(stockList.stream()
.map(ErpStockDO::getCount)
.filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add));
return stock;
}
default ErpStockDO selectByProductIdAndWarehouseIdAndCategoryType(Long productId, Long warehouseId, Integer categoryType) {

@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutItemDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.List;
@ -30,4 +31,9 @@ public interface ErpStockOutItemMapper extends BaseMapperX<ErpStockOutItemDO> {
List<Long> selectOutIds(@Param("productId") Long productId, @Param("warehouseId") Long warehouseId);
BigDecimal selectLockedStockCount(@Param("productId") Long productId,
@Param("warehouseId") Long warehouseId,
@Param("areaId") Long areaId,
@Param("statuses") Collection<Integer> statuses);
}

@ -3,9 +3,15 @@ package cn.iocoder.yudao.module.erp.dal.mysql.stock;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutItemPalletDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Mapper
public interface ErpStockOutItemPalletMapper extends BaseMapperX<ErpStockOutItemPalletDO> {
@ -21,4 +27,42 @@ public interface ErpStockOutItemPalletMapper extends BaseMapperX<ErpStockOutItem
default int deleteByOutId(Long outId) {
return delete(ErpStockOutItemPalletDO::getOutId, outId);
}
default Map<Long, BigDecimal> selectLockedPackageCountMap(Collection<Long> palletIds,
Collection<Integer> statuses,
String outType) {
if (palletIds == null || palletIds.isEmpty()) {
return Collections.emptyMap();
}
List<Map<String, Object>> list = selectLockedPackageCountList(palletIds, statuses, outType);
if (list == null || list.isEmpty()) {
return Collections.emptyMap();
}
return list.stream().collect(Collectors.toMap(
item -> ((Number) item.get("palletId")).longValue(),
item -> item.get("lockedPackageCount") == null ? BigDecimal.ZERO
: new BigDecimal(item.get("lockedPackageCount").toString()),
(count1, count2) -> count1));
}
@Select({"<script>",
"SELECT item_pallet.pallet_id AS palletId, COALESCE(SUM(item_pallet.package_count), 0) AS lockedPackageCount",
"FROM erp_stock_out_item_pallet item_pallet",
"INNER JOIN erp_stock_out stock_out ON stock_out.id = item_pallet.out_id",
"WHERE item_pallet.pallet_id IN",
"<foreach collection='palletIds' item='palletId' open='(' separator=',' close=')'>",
"#{palletId}",
"</foreach>",
"AND stock_out.out_type = #{outType}",
"<if test='statuses != null and statuses.size() > 0'>",
"AND stock_out.status IN",
"<foreach collection='statuses' item='status' open='(' separator=',' close=')'>",
"#{status}",
"</foreach>",
"</if>",
"GROUP BY item_pallet.pallet_id",
"</script>"})
List<Map<String, Object>> selectLockedPackageCountList(@Param("palletIds") Collection<Long> palletIds,
@Param("statuses") Collection<Integer> statuses,
@Param("outType") String outType);
}

@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.erp.dal.dataobject.pallet.ErpPalletDO;
import javax.validation.Valid;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@ -34,4 +35,6 @@ public interface ErpPalletService {
void regenerateCode(Long id, String code) throws UnsupportedEncodingException;
String selectPrintTemplate();
Map<Long, BigDecimal> getLockedPackageCountMap(Collection<Long> palletIds);
}

@ -12,6 +12,8 @@ import cn.iocoder.yudao.module.erp.dal.dataobject.pallet.ErpPalletDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.warehousearea.WarehouseAreaDO;
import cn.iocoder.yudao.module.erp.dal.mysql.pallet.ErpPalletMapper;
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockOutItemPalletMapper;
import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus;
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
import cn.iocoder.yudao.module.erp.service.stock.ErpWarehouseService;
import cn.iocoder.yudao.module.erp.service.warehousearea.WarehouseAreaService;
@ -21,6 +23,8 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@ -40,10 +44,15 @@ import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.WAREHOUSE_LOC
public class ErpPalletServiceImpl implements ErpPalletService {
private static final int ERPPALLET_PRINT_TEMPLATE_TYPE = 8;
private static final String PRODUCT_STOCK_OUT_TYPE = "产品出库";
private static final List<Integer> LOCKED_STOCK_OUT_STATUSES = Arrays.asList(
ErpAuditStatus.PROCESS.getStatus(), ErpAuditStatus.DRAFT.getStatus(), ErpAuditStatus.UN_APPROVE.getStatus());
@Resource
private ErpPalletMapper palletMapper;
@Resource
private ErpStockOutItemPalletMapper stockOutItemPalletMapper;
@Resource
private AutoCodeUtil autoCodeUtil;
@Resource
private ErpWarehouseService warehouseService;
@ -149,6 +158,12 @@ public class ErpPalletServiceImpl implements ErpPalletService {
return palletMapper.selectPrintTemplate(ERPPALLET_PRINT_TEMPLATE_TYPE);
}
@Override
public Map<Long, BigDecimal> getLockedPackageCountMap(Collection<Long> palletIds) {
return stockOutItemPalletMapper.selectLockedPackageCountMap(
palletIds, LOCKED_STOCK_OUT_STATUSES, PRODUCT_STOCK_OUT_TYPE);
}
private ErpPalletDO validatePalletExists(Long id) {
ErpPalletDO pallet = palletMapper.selectById(id);
if (pallet == null) {

@ -51,6 +51,7 @@ import cn.iocoder.yudao.module.infra.api.config.ConfigApi;
import cn.iocoder.yudao.module.system.api.permission.PermissionApi;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.enums.permission.RoleCodeEnum;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@ -762,12 +763,15 @@ public class ErpStockOutServiceImpl implements ErpStockOutService {
if (approve) {
BigDecimal remainCount = defaultZero(pallet.getProductCount()).subtract(packageCount);
if (remainCount.compareTo(BigDecimal.ZERO) <= 0) {
pallet.setStatus(ErpPalletStatusEnum.IDLE.getStatus());
pallet.setProductId(null);
pallet.setProductName(null);
pallet.setProductCount(BigDecimal.ZERO);
pallet.setWarehouseId(null);
pallet.setAreaId(null);
palletMapper.update(null, new LambdaUpdateWrapper<ErpPalletDO>()
.eq(ErpPalletDO::getId, pallet.getId())
.set(ErpPalletDO::getStatus, ErpPalletStatusEnum.IDLE.getStatus())
.set(ErpPalletDO::getProductId, null)
.set(ErpPalletDO::getProductName, null)
.set(ErpPalletDO::getProductCount, BigDecimal.ZERO)
.set(ErpPalletDO::getWarehouseId, null)
.set(ErpPalletDO::getAreaId, null));
return;
} else {
pallet.setProductCount(remainCount);
}

@ -15,4 +15,27 @@
</where>
</select>
<select id="selectLockedStockCount" resultType="java.math.BigDecimal">
SELECT COALESCE(SUM(item.count), 0)
FROM erp_stock_out_item item
INNER JOIN erp_stock_out stock_out ON stock_out.id = item.out_id
<where>
<if test="productId != null">
AND item.product_id = #{productId}
</if>
<if test="warehouseId != null">
AND item.warehouse_id = #{warehouseId}
</if>
<if test="areaId != null">
AND item.area_id = #{areaId}
</if>
<if test="statuses != null and statuses.size() > 0">
AND stock_out.status IN
<foreach collection="statuses" item="status" open="(" separator="," close=")">
#{status}
</foreach>
</if>
</where>
</select>
</mapper>

Loading…
Cancel
Save