Blame view

src/main/java/com/huaheng/pc/config/shipmentPreference/service/ShipmentPreferenceServiceImpl.java 7.37 KB
pengcheng authored
1
2
package com.huaheng.pc.config.shipmentPreference.service;
3
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
周鸿 authored
4
import com.huaheng.common.utils.Wrappers;
pengcheng authored
5
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
pengcheng authored
6
import com.huaheng.common.constant.QuantityConstant;
7
8
9
10
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
pengcheng authored
11
12
import com.huaheng.pc.config.configValue.domain.ConfigValue;
import com.huaheng.pc.config.configValue.service.ConfigValueService;
pengcheng authored
13
14
import com.huaheng.pc.config.shipmentPreference.domain.ShipmentPreference;
import com.huaheng.pc.config.shipmentPreference.mapper.ShipmentPreferenceMapper;
15
16
17
18
19
20
21
import com.huaheng.pc.config.statusFlow.domain.StatusFlowDetail;
import com.huaheng.pc.config.statusFlow.domain.StatusFlowHeader;
import com.huaheng.pc.config.statusFlow.service.StatusFlowDetailService;
import com.huaheng.pc.config.statusFlow.service.StatusFlowHeaderService;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
import org.springframework.beans.factory.annotation.Autowired;
pengcheng authored
22
import org.springframework.stereotype.Service;
pengcheng authored
23
import org.springframework.transaction.annotation.Transactional;
pengcheng authored
24
25
26
27
import java.util.ArrayList;
import java.util.List;
28
@Service("shipmentPreference")
pengcheng authored
29
30
public class ShipmentPreferenceServiceImpl extends ServiceImpl<ShipmentPreferenceMapper, ShipmentPreference> implements ShipmentPreferenceService {
31
32
33
34
35
36
37
38
    @Autowired
    private ShipmentPreferenceService shipmentPreferenceService;
    @Autowired
    private StatusFlowHeaderService statusFlowHeaderService;
    @Autowired
    private StatusFlowDetailService statusFlowDetailService;
    @Autowired
    private ShipmentHeaderService shipmentHeaderService;
pengcheng authored
39
40
    @Autowired
    private ConfigValueService configValueService;
41
42
43
44
45
46
47
48


    /**
     * 1、找出出库首选项
     * 2、查看出库首选项的出库流程
     * 3、找到该状态流的出库流程明细
     * 4、判断单据是否按出库流程操作
     *
49
     * @param ids    出库单id
50
     * @param status 状态流
51
52
53
     * @return
     */
    @Override
54
    public List<ShipmentHeader> checkShipmentProcess(String ids, Integer status, String code) {
pengcheng authored
55
56
57
58
59
60
        LambdaQueryWrapper<ConfigValue> configValueLambdaQueryWrapper = Wrappers.lambdaQuery();
        configValueLambdaQueryWrapper.eq(ConfigValue::getModuleType, "shipment")
                .eq(ConfigValue::getWarehouseCode, ShiroUtils.getWarehouseCode());
        ConfigValue configValue = configValueService.getOne(configValueLambdaQueryWrapper);
        if (configValue == null) {
pengcheng authored
61
62
63
            throw new ServiceException("仓库的出库配置不存在");
        }
64
65
        //查找出库首选项
        ShipmentPreference shipmentPreference = shipmentPreferenceService.list().get(0);
66
        if (shipmentPreference == null) {
67
68
            throw new ServiceException("系统没有设置出库首选");
        }
69
        if (StringUtils.isEmpty(shipmentPreference.getShippingFlow())) {
70
71
72
73
74
            throw new ServiceException("出库首选没有绑定出库流程");
        }

        //查看出库流程
        LambdaQueryWrapper<StatusFlowHeader> statusFlowHeaderLam = Wrappers.lambdaQuery();
75
        statusFlowHeaderLam.eq(StatusFlowHeader::getCode, shipmentPreference.getShippingFlow())
76
77
                .eq(StatusFlowHeader::getWarehouseCode, ShiroUtils.getWarehouseCode());
        StatusFlowHeader statusFlowHeader = statusFlowHeaderService.getOne(statusFlowHeaderLam);
78
        if (statusFlowHeader == null) {
79
80
81
82
            throw new ServiceException("出库首选绑定的出库流程不在系统中");
        }
        //查看流程明细
        LambdaQueryWrapper<StatusFlowDetail> statusFlowDetailLamb = Wrappers.lambdaQuery();
83
84
85
        statusFlowDetailLamb.eq(StatusFlowDetail::getHeaderId, statusFlowHeader.getId())
                .eq(StatusFlowDetail::getWarehouseCode, ShiroUtils.getWarehouseCode())
                .eq(StatusFlowDetail::getFlowCode, status.toString());
86
87
88
        StatusFlowDetail statusFlowDetail = statusFlowDetailService.getOne(statusFlowDetailLamb);

        List<ShipmentHeader> shipmentHeaderList = new ArrayList<>();
89
        if (statusFlowDetail != null  && statusFlowDetail.getNessary().intValue() == 1) {
90
91
92
93
            if (StringUtils.isNotEmpty(ids)) {
                for (Integer id : Convert.toIntArray(ids)) {
                    //判断单据是否按出库流程操作
                    ShipmentHeader shipmentHeader = shipmentHeaderService.getById(id);
94
95
                    if (shipmentHeader == null || shipmentHeader.getFirstStatus() < status && statusFlowDetail.getNessary() == 1) {
                        throw new ServiceException("出库单ID为" + id + "的单据状态不对,请按照出库流程先审核单据");
pengcheng authored
96
                    }
97
98
                    if (shipmentHeader.getLastStatus() > QuantityConstant.SHIPMENT_HEADER_WAVE) {
                        throw new ServiceException("出库单ID为" + id + "的单据无法加入波次");
99
100
101
                    }
                    shipmentHeaderList.add(shipmentHeader);
                }
102
            } else {
103
                LambdaQueryWrapper<ShipmentHeader> lam = Wrappers.lambdaQuery();
104
105
                lam.eq(ShipmentHeader::getCode, code)
                        .eq(ShipmentHeader::getWarehouseCode, ShiroUtils.getWarehouseCode());
106
107
                ShipmentHeader shipmentHeader = shipmentHeaderService.getOne(lam);
                if (shipmentHeader == null || shipmentHeader.getFirstStatus() < status) {
108
109
                    throw new ServiceException("单据状态不对,此操作不符合出库流程,请按照出库流程出库");
                }
110
111
                if (shipmentHeader.getLastStatus() > QuantityConstant.SHIPMENT_HEADER_WAVE) {
                    throw new ServiceException("出库单" + code + "的单据无法加入波次");
pengcheng authored
112
                }
113
114
115
                shipmentHeaderList.add(shipmentHeader);
            }
        }
116
117
118
        return shipmentHeaderList;
    }
mahuandong authored
119
120
121
122
123
124
125
126
127

    /**
     * 复制出库首选项表
     *
     * @param warehouseCode    原仓库编码
     * @param newWarehouseCode 新仓库编码
     * @return 是否复制成功
     */
    @Override
pengcheng authored
128
    @Transactional
mahuandong authored
129
130
131
132
    public boolean shipmentPreferenceCopy(String warehouseCode, String newWarehouseCode) {
        log.trace("开始复制出库首选项表");
        LambdaQueryWrapper<ShipmentPreference> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(ShipmentPreference::getWarehouseCode, newWarehouseCode);
133
        if (!this.list(lambdaQueryWrapper).isEmpty()) {
mahuandong authored
134
135
136
            log.error("该仓库已存在");
            return false;
        }
mahuandong authored
137
138

        lambdaQueryWrapper = Wrappers.lambdaQuery();
mahuandong authored
139
140
141
        lambdaQueryWrapper.eq(ShipmentPreference::getWarehouseCode, warehouseCode);
        List<ShipmentPreference> shipmentPreferenceList = this.list(lambdaQueryWrapper);
142
        for (ShipmentPreference shipmentPreference : shipmentPreferenceList) {
mahuandong authored
143
144
145
146
            shipmentPreference.setId(null);
            shipmentPreference.setWarehouseCode(newWarehouseCode);
        }
147
148
        if (this.saveBatch(shipmentPreferenceList)) {
            log.trace("复制出库首选项成功,新仓库编码是:" + newWarehouseCode);
mahuandong authored
149
150
151
152
153
            return true;
        } else {
            return false;
        }
    }
pengcheng authored
154
}