cuilei
2025-05-28 62ad99ee2a374c1726730146335ed82cbcfacebb
工具管理-新增方式出库接口及部分查询调整
已添加1个文件
已修改8个文件
199 ■■■■■ 文件已修改
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/controller/OutboundOrderController.java 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/entity/dto/OutBoundAddDto.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/entity/dto/OutBoundRequestDto.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/mapper/xml/OutStoreDetailMapper.xml 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/IOutboundOrderService.java 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/OutStoreDetailServiceImpl.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/OutboundDetailServiceImpl.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/OutboundOrderServiceImpl.java 122 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/ToolLedgerDetailServiceImpl.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/controller/OutboundOrderController.java
@@ -12,6 +12,7 @@
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.TranslateDictTextUtils;
import org.jeecg.modules.tms.entity.dto.OutBoundAddDto;
import org.jeecg.modules.tms.entity.dto.OutBoundOrderFlowDto;
import org.jeecg.modules.tms.entity.dto.OutBoundRequestDto;
import org.jeecg.modules.tms.entity.dto.OutboundOrderAndDetailDto;
@@ -180,9 +181,17 @@
     @AutoLog(value = "申请单方式出库")
     @ApiOperation(value = "申请单方式出库", notes = "申请单方式出库")
     @PostMapping(value = "/outBound")
     public Result<?> outBound(@RequestBody List<OutBoundRequestDto> outBoundRequestList) {
        outboundOrderService.outBound(outBoundRequestList);
     @PostMapping(value = "/outBoundByApply")
     public Result<?> outBoundByApply(@RequestBody List<OutBoundRequestDto> outBoundRequestList) {
        outboundOrderService.outBoundByApply(outBoundRequestList);
        return Result.OK("出库成功");
     }
     @AutoLog(value = "新增方式出库")
     @ApiOperation(value = "新增方式出库", notes = "新增方式出库")
     @PostMapping(value = "/outBoundByAdd")
     public Result<?> outBoundByAdd(@RequestBody List<OutBoundAddDto> boundAddList) {
        outboundOrderService.outBoundByAdd(boundAddList);
        return Result.OK("出库成功");
     }
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/entity/dto/OutBoundAddDto.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,31 @@
package org.jeecg.modules.tms.entity.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
/**
 * æ–°å¢žæ–¹å¼å‡ºåº“参数封装
 */
@Data
public class OutBoundAddDto {
    //台账明细id
    @ApiModelProperty(value = "台账明细id")
    private String toolLedgerDetailId;
    //工具编码(tms_base_tool表主键id)
    @ApiModelProperty(value = "工具编码(tms_base_tool表主键id)")
    private String toolCode;
    //工具编号(唯一编号,管到把的属性)
    @ApiModelProperty(value = "工具编号(唯一编号,管到把的属性)")
    private String toolId;
    //出库方式
    @ApiModelProperty(value = "出库方式")
    private String outStorehouseType;
    //出库数量
    @ApiModelProperty(value = "出库数量")
    private BigDecimal outboundQuantity;
    //库位号
    @ApiModelProperty(value = "库位号")
    private String outboundLocation;
}
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/entity/dto/OutBoundRequestDto.java
@@ -5,6 +5,9 @@
import java.math.BigDecimal;
/**
 * ç”³è¯·å•方式出库参数封装
 */
@Data
public class OutBoundRequestDto {
    //出库申请单id
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/mapper/xml/OutStoreDetailMapper.xml
@@ -49,8 +49,7 @@
        </choose>
        FROM tms_out_store_detail t1
        LEFT JOIN tms_base_tools t2 on t1.tool_code = t2.id
        LEFT JOIN tms_tools_config_property t3 on t3.tool_code = t2.id
        LEFT JOIN tms_tools_classify t11 on t11.id = t2.classify_id
        LEFT JOIN tms_tools_config_property t3 on t3.tool_code = t1.tool_code
        <choose>
            <when test="ew.paramNameValuePairs.paramaTableName == '1'">
                LEFT JOIN tms_para_common_tool t4 on t4.tool_code = t2.id
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/IOutboundOrderService.java
@@ -5,6 +5,7 @@
import org.jeecg.modules.tms.entity.OutboundDetail;
import org.jeecg.modules.tms.entity.OutboundOrder;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.tms.entity.dto.OutBoundAddDto;
import org.jeecg.modules.tms.entity.dto.OutBoundOrderFlowDto;
import org.jeecg.modules.tms.entity.dto.OutBoundRequestDto;
import org.jeecg.modules.tms.entity.dto.OutboundOrderAndDetailDto;
@@ -47,5 +48,7 @@
    void approvalProcess(OutBoundOrderFlowDto outBoundOrderFlowDto);
    void outBound(List<OutBoundRequestDto> outBoundRequestList);
    void outBoundByApply(List<OutBoundRequestDto> outBoundRequestList);
    void outBoundByAdd(List<OutBoundAddDto> boundAddList);
}
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/OutStoreDetailServiceImpl.java
@@ -28,9 +28,9 @@
        QueryWrapper<OutStoreDetailVo> queryWrapper = Wrappers.query();
        String[] classifyIds = parameterMap.get("classifyId");
        if (classifyIds != null && classifyIds.length > 0) {
            queryWrapper.eq("t11.classify_id", classifyIds[0]);
            queryWrapper.eq("t2.classify_id", classifyIds[0]);
        }
        queryWrapper.orderByDesc("create_time");
        queryWrapper.orderByDesc("t1.create_time");
        return this.baseMapper.queryPageList(page, queryWrapper);
    }
}
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/OutboundDetailServiceImpl.java
@@ -4,11 +4,14 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.tms.entity.OutboundDetail;
import org.jeecg.modules.tms.entity.vo.OutboundDetailVo;
import org.jeecg.modules.tms.mapper.OutboundDetailMapper;
import org.jeecg.modules.tms.service.IOutboundDetailService;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@@ -39,6 +42,11 @@
        if (outStorehouseIds != null && outStorehouseIds.length > 0) {
            queryWrapper.eq("t1.out_storehouse_id", outStorehouseIds[0]);
        }
        String[] statuses = parameterMap.get("status");
        if (statuses != null && statuses.length > 0) {
            String[] statusArr = statuses[0].split(",");
            queryWrapper.in("t1.status", statusArr);
        }
        return this.baseMapper.queryPageList(page, queryWrapper);
    }
}
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/OutboundOrderServiceImpl.java
@@ -7,6 +7,7 @@
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -27,6 +28,7 @@
import org.jeecg.modules.flowable.service.IFlowTaskService;
import org.jeecg.modules.system.service.ISysBusinessCodeRuleService;
import org.jeecg.modules.tms.entity.*;
import org.jeecg.modules.tms.entity.dto.OutBoundAddDto;
import org.jeecg.modules.tms.entity.dto.OutBoundOrderFlowDto;
import org.jeecg.modules.tms.entity.dto.OutBoundRequestDto;
import org.jeecg.modules.tms.entity.dto.OutboundOrderAndDetailDto;
@@ -64,6 +66,8 @@
    private IToolLedgerDetailService toolLedgerDetailService;
    @Autowired
    private IOutStoreDetailService outStoreDetailService;
    @Autowired
    private IBaseToolsService baseToolsService;
    @Autowired
    private ISysBusinessCodeRuleService businessCodeRuleService;
    @Autowired
@@ -125,9 +129,13 @@
        if (outStorehouseTypes != null && outStorehouseTypes.length > 0) {
            queryWrapper.eq("t.out_storehouse_type", outStorehouseTypes[0]);
        }
        String[] statuses = parameterMap.get("orderStatus");
        if (statuses != null && statuses.length > 0) {
            queryWrapper.eq("t.order_status", statuses[0]);
        String[] orderStatuses = parameterMap.get("orderStatus");
        if (orderStatuses != null && orderStatuses.length > 0) {
            queryWrapper.eq("t.order_status", orderStatuses[0]);
        }
        String[] outStatuses = parameterMap.get("outStatus");
        if (outStatuses != null && outStatuses.length > 0) {
            queryWrapper.eq("t.out_status", outStatuses[0]);
        }
        String[] startTimes = parameterMap.get("startTime");
        if (startTimes != null && startTimes.length > 0) {
@@ -219,6 +227,11 @@
            if (OutBillStatus.APPROVED.getValue().equals(outBoundOrderFlowDto.getStatus())) {
                outboundOrder.setOutStatus(OutBoundStatusEnum.NOT_OUTBOUND.getValue());
                outboundOrder.setOrderStatus(OutBillStatus.APPROVED.getValue());
                //初始化申请明细信息的出库状态/实际出库数量字段
                outboundDetailService.update(new LambdaUpdateWrapper<OutboundDetail>()
                        .eq(OutboundDetail::getOutStorehouseId, outboundOrder.getId())
                        .set(OutboundDetail::getStatus, OutBoundStatusEnum.NOT_OUTBOUND.getValue())
                        .set(OutboundDetail::getOutActualCount, BigDecimal.ZERO));
            }
            if (OutBillStatus.REJECTED.getValue().equals(outBoundOrderFlowDto.getStatus())) {
                //如果驳回,审批单状态回到草稿
@@ -232,7 +245,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void outBound(List<OutBoundRequestDto> outBoundRequestList) {
    public void outBoundByApply(List<OutBoundRequestDto> outBoundRequestList) {
        //校验是否来自一个申请单
        if (!fromOneApply(outBoundRequestList)) {
            throw new JeecgBootException("出库明细必须来自同一出库申请单!");
@@ -259,7 +272,7 @@
                queryWrapper.or();
            }
            OutboundDetail detail = outboundDetailList.get(i);
            queryWrapper.and(wrapper ->
            queryWrapper.or(wrapper ->
                    wrapper.eq(ToolLedgerDetail::getToolCode, detail.getToolCode())
                            .eq(ToolLedgerDetail::getToolId, detail.getToolId()) //如果不管到把,该字段为空
            );
@@ -362,6 +375,105 @@
        updateById(outboundOrder);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void outBoundByAdd(List<OutBoundAddDto> boundAddList) {
        //校验台账主表库存数量
        Map<String, BigDecimal> toolBoundQuantityMap = boundAddList.stream()
                .collect(Collectors.groupingBy(OutBoundAddDto::getToolCode,
                        Collectors.mapping(OutBoundAddDto::getOutboundQuantity, Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
        Map<String, ToolLedger> toolLedgerMap = toolLedgerService.list(new LambdaQueryWrapper<ToolLedger>().in(ToolLedger::getToolId, toolBoundQuantityMap.keySet()))
                .stream().collect(Collectors.toMap(ToolLedger::getToolId, item -> item, (k1, k2) -> k1));
        List<ToolLedger> toolLedgerUpdateList = CollectionUtil.newArrayList();
        for (String toolCode : toolBoundQuantityMap.keySet()) {
            ToolLedger toolLedger = toolLedgerMap.get(toolCode);
            BigDecimal outBoundQuantity = toolBoundQuantityMap.get(toolCode);
            if (Objects.isNull(toolLedger) || toolLedger.getAvailableCount().compareTo(outBoundQuantity) < 0) {
                BaseTools tools = baseToolsService.getById(toolCode);
                throw new JeecgBootException("编码为【" + tools.getToolCode() + "】的工具,库存不足!");
            } else {
                OutStorehouseType outStorehouseType = OutStorehouseType.getByValue(boundAddList.get(0).getOutStorehouseType());
                switch (outStorehouseType) {
                    case TOOL_BORROW:
                        toolLedger.setLendCount(toolLedger.getLendCount().add(outBoundQuantity));
                        break;
                    case MAINTENANCE_OUTBOUND:
                        toolLedger.setRepairCount(toolLedger.getRepairCount().add(outBoundQuantity));
                        break;
                    case CALIBRATION_OUTBOUND:
                        toolLedger.setDetectionCount(toolLedger.getDetectionCount().add(outBoundQuantity));
                        break;
                    case GRINDING_OUTBOUND:
                        toolLedger.setSharpeningCount(toolLedger.getSharpeningCount().add(outBoundQuantity));
                        break;
                    default:
                        throw new JeecgBootException("未知的出库类型!");
                }
                //扣减台账主表可用库存
                toolLedger.setAvailableCount(toolLedger.getAvailableCount().subtract(outBoundQuantity));
                toolLedgerUpdateList.add(toolLedger);
            }
        }
        //校验台账明细库存数量
        Map<String, OutBoundAddDto> boundAddDtoMap = boundAddList.stream().collect(Collectors
                .toMap(OutBoundAddDto::getToolLedgerDetailId, item -> item, (k1, k2) -> k1));
        Map<String, ToolLedgerDetail> toolLedgerDetailMap = toolLedgerDetailService.listByIds(boundAddDtoMap.keySet()).stream()
                .collect(Collectors.toMap(ToolLedgerDetail::getId, item -> item, (k1, k2) -> k1));
        List<ToolLedgerDetail> toolLedgerDetailUpdateList = CollectionUtil.newArrayList();
        for (String toolLedgerDetailId : boundAddDtoMap.keySet()) {
            OutBoundAddDto outBoundAddDto = boundAddDtoMap.get(toolLedgerDetailId);
            BigDecimal outboundQuantity = outBoundAddDto.getOutboundQuantity();
            ToolLedgerDetail toolLedgerDetail = toolLedgerDetailMap.get(toolLedgerDetailId);
            if (Objects.isNull(toolLedgerDetail) || toolLedgerDetail.getQuantity().compareTo(outboundQuantity) < 0) {
                BaseTools tools = baseToolsService.getById(outBoundAddDto.getToolCode());
                throw new JeecgBootException("编码为【" + tools.getToolCode() + "】的工具,库存不足!");
            } else {
                //扣减台账明细库存
                if (StrUtil.isBlank(toolLedgerDetail.getToolId())) {
                    //没有唯一编码,不管到把的
                    toolLedgerDetail.setQuantity(toolLedgerDetail.getQuantity().subtract(outboundQuantity));
                } else {
                    //有唯一编码,管道把的
                    toolLedgerDetail.setQuantity(BigDecimal.ZERO);//数量只会是0和1
                    OutStorehouseType outStorehouseType = OutStorehouseType.getByValue(boundAddList.get(0).getOutStorehouseType());
                    switch (outStorehouseType) {
                        case TOOL_BORROW:
                            toolLedgerDetail.setStatus(ToolCirculationStatus.BORROWED.getValue());
                            break;
                        case MAINTENANCE_OUTBOUND:
                            toolLedgerDetail.setStatus(ToolCirculationStatus.REPAIRING.getValue());
                            break;
                        case CALIBRATION_OUTBOUND:
                            toolLedgerDetail.setStatus(ToolCirculationStatus.INSPECTING.getValue());
                            break;
                        case GRINDING_OUTBOUND:
                            toolLedgerDetail.setStatus(ToolCirculationStatus.GRINDING.getValue());
                            break;
                        default:
                            throw new JeecgBootException("未知的出库类型!");
                    }
                }
                toolLedgerDetailUpdateList.add(toolLedgerDetail);
            }
        }
        toolLedgerService.updateBatchById(toolLedgerUpdateList);
        toolLedgerDetailService.updateBatchById(toolLedgerDetailUpdateList);
        //记录出库流水
        List<OutStoreDetail> outStoreAddList = CollectionUtil.newArrayList();
        for (OutBoundAddDto outBoundAddDto : boundAddList) {
            OutStoreDetail outStoreDetail = new OutStoreDetail()
                    .setToolCode(outBoundAddDto.getToolCode())
                    .setToolId(outBoundAddDto.getToolId())
                    .setOutStorehouseType(outBoundAddDto.getOutStorehouseType())
                    .setGoodsShelvesCode(outBoundAddDto.getOutboundLocation())
                    .setOutNumber(outBoundAddDto.getOutboundQuantity())
                    .setOperateType("2");//2:手工操作
            outStoreAddList.add(outStoreDetail);
        }
        outStoreDetailService.saveBatch(outStoreAddList);
    }
    private boolean fromOneApply(List<OutBoundRequestDto> outBoundRequestList) {
        long count = outBoundRequestList.stream().map(OutBoundRequestDto::getOutBoundOrderId).distinct().count();
        if (count > 1) {
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/ToolLedgerDetailServiceImpl.java
@@ -31,6 +31,14 @@
        if (statuses != null && statuses.length > 0) {
            queryWrapper.eq("t.status", statuses[0]);
        }
        String[] quantities = parameterMap.get("quantity");
        if (quantities != null && quantities.length > 0) {
            queryWrapper.gt("t.quantity", quantities[0]);
        }
        String[] classifyIds = parameterMap.get("classifyId");
        if (classifyIds != null && classifyIds.length > 0) {
            queryWrapper.eq("p.classify_id", classifyIds[0]);
        }
        String[] excludeIds = parameterMap.get("excludeIds");
        if (excludeIds != null && excludeIds.length > 0) {
            String[] idArray = excludeIds[0].split(",");