ShipmentPreferenceServiceImpl.java
7.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package com.huaheng.pc.config.shipmentPreference.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.common.constant.QuantityConstant;
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;
import com.huaheng.pc.config.configValue.domain.ConfigValue;
import com.huaheng.pc.config.configValue.service.ConfigValueService;
import com.huaheng.pc.config.shipmentPreference.domain.ShipmentPreference;
import com.huaheng.pc.config.shipmentPreference.mapper.ShipmentPreferenceMapper;
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;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
@Service("shipmentPreference")
public class ShipmentPreferenceServiceImpl extends ServiceImpl<ShipmentPreferenceMapper, ShipmentPreference> implements ShipmentPreferenceService {
@Autowired
private ShipmentPreferenceService shipmentPreferenceService;
@Autowired
private StatusFlowHeaderService statusFlowHeaderService;
@Autowired
private StatusFlowDetailService statusFlowDetailService;
@Autowired
private ShipmentHeaderService shipmentHeaderService;
@Autowired
private ConfigValueService configValueService;
/**
* 1、找出出库首选项
* 2、查看出库首选项的出库流程
* 3、找到该状态流的出库流程明细
* 4、判断单据是否按出库流程操作
*
* @param ids 出库单id
* @param status 状态流
* @return
*/
@Override
public List<ShipmentHeader> checkShipmentProcess(String ids, Integer status, String code) {
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("仓库的出库配置不存在");
}
//查找出库首选项
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())
.eq(StatusFlowDetail::getFlowCode, status.toString());
StatusFlowDetail statusFlowDetail = statusFlowDetailService.getOne(statusFlowDetailLamb);
List<ShipmentHeader> shipmentHeaderList = new ArrayList<>();
if (statusFlowDetail != null && statusFlowDetail.getNessary().intValue() == 1) {
if (StringUtils.isNotEmpty(ids)) {
for (Integer id : Convert.toIntArray(ids)) {
//判断单据是否按出库流程操作
ShipmentHeader shipmentHeader = shipmentHeaderService.getById(id);
if (shipmentHeader == null || shipmentHeader.getFirstStatus() < status && statusFlowDetail.getNessary() == 1) {
throw new ServiceException("出库单ID为" + id + "的单据状态不对,请按照出库流程先审核单据");
}
if (shipmentHeader.getLastStatus() > QuantityConstant.SHIPMENT_HEADER_WAVE) {
throw new ServiceException("出库单ID为" + id + "的单据无法加入波次");
}
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) {
throw new ServiceException("单据状态不对,此操作不符合出库流程,请按照出库流程出库");
}
if (shipmentHeader.getLastStatus() > QuantityConstant.SHIPMENT_HEADER_WAVE) {
throw new ServiceException("出库单" + code + "的单据无法加入波次");
}
shipmentHeaderList.add(shipmentHeader);
}
}
return shipmentHeaderList;
}
/**
* 复制出库首选项表
*
* @param warehouseCode 原仓库编码
* @param newWarehouseCode 新仓库编码
* @return 是否复制成功
*/
@Override
@Transactional
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;
}
lambdaQueryWrapper = Wrappers.lambdaQuery();
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;
}
}
}