Blame view

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


    /**
     * 1、找出出库首选项
     * 2、查看出库首选项的出库流程
     * 3、找到该状态流的出库流程明细
     * 4、判断单据是否按出库流程操作
     *
     * @param ids 出库单id
49
     * @param status 状态流
50
51
52
     * @return
     */
    @Override
53
    public List<ShipmentHeader> checkShipmentProcess(String ids, Integer status,String code) {
pengcheng authored
54
55
56
57
58
59
60
61
62

        LambdaQueryWrapper<ConfigValue> configValueLambdaQueryWrapper=Wrappers.lambdaQuery();
        configValueLambdaQueryWrapper.eq(ConfigValue::getModuleType,"shipment")
                .eq(ConfigValue::getWarehouseCode,ShiroUtils.getWarehouseCode());
        ConfigValue configValue=configValueService.getOne(configValueLambdaQueryWrapper);
        if(configValue==null){
            throw new ServiceException("仓库的出库配置不存在");
        }
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
        //查找出库首选项
        ShipmentPreference shipmentPreference = shipmentPreferenceService.list().get(0);
        if(shipmentPreference == null){
            throw new ServiceException("系统没有设置出库首选");
        }
        if(StringUtils.isEmpty(shipmentPreference.getShippingFlow())){
            throw new ServiceException("出库首选没有绑定出库流程");
        }

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

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

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

        lambdaQueryWrapper = Wrappers.lambdaQuery();
mahuandong authored
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
        lambdaQueryWrapper.eq(ShipmentPreference::getWarehouseCode, warehouseCode);
        List<ShipmentPreference> shipmentPreferenceList = this.list(lambdaQueryWrapper);

        for ( ShipmentPreference shipmentPreference : shipmentPreferenceList) {
            shipmentPreference.setId(null);
            shipmentPreference.setWarehouseCode(newWarehouseCode);
        }

        if ( this.saveBatch(shipmentPreferenceList) ){
            log.trace("复制出库首选项成功,新仓库编码是:"+newWarehouseCode);
            return true;
        } else {
            return false;
        }
    }
pengcheng authored
148
}