ShippingCombinationService.java
6.93 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
package com.huaheng.pc.shipment.shippingCombination.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.pc.config.FilterConfigDetail.domain.FilterConfigDetail;
import com.huaheng.pc.config.FilterConfigDetail.service.FilterConfigDetailService;
import com.huaheng.pc.config.configValue.domain.ConfigValue;
import com.huaheng.pc.config.configValue.service.ConfigValueService;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialServiceImpl;
import com.huaheng.pc.config.materialType.domain.MaterialType;
import com.huaheng.pc.config.materialType.service.MaterialTypeService;
import com.huaheng.pc.config.shipmentPreference.domain.ShipmentPreference;
import com.huaheng.pc.config.shipmentPreference.service.ShipmentPreferenceService;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import com.huaheng.pc.shipment.shippingCombination.mapper.ShippingCombinationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service
public class ShippingCombinationService {
@Resource
private ShippingCombinationMapper shippingCombinationMapper;
@Autowired
InventoryDetailService inventoryDetailService;
@Autowired
ConfigValueService configValueService;
@Autowired
FilterConfigDetailService filterConfigDetailService;
@Autowired
ShipmentPreferenceService shipmentPreferenceService;
@Autowired
MaterialServiceImpl materialService;
@Autowired
MaterialTypeService materialTypeService;
//根据分配规则查找库存
public List<InventoryDetail> getInventorys(ShipmentDetail shipmentDetail) {
LambdaQueryWrapper<ConfigValue> configValueLambdaQueryWrapper=Wrappers.lambdaQuery();
configValueLambdaQueryWrapper.eq(ConfigValue::getModuleType,"shipment")
.eq(ConfigValue::getWarehouseCode,shipmentDetail.getWarehouseCode());
ConfigValue configValue=configValueService.getOne(configValueLambdaQueryWrapper);
if(configValue==null){
throw new ServiceException("仓库的出库配置不存在");
}
//查找出库首选项
LambdaQueryWrapper<ShipmentPreference> slam=Wrappers.lambdaQuery();
slam.eq(ShipmentPreference::getCode,configValue.getIdentifier())
.eq(ShipmentPreference::getWarehouseCode,configValue.getWarehouseCode());
ShipmentPreference shipmentPreference=shipmentPreferenceService.getOne(slam);
if(shipmentPreference==null){
throw new ServiceException("仓库的出库配置中出库首选项不存在");
}
List<InventoryDetail> list=new ArrayList<>();
FilterConfigDetail filterConfigDetail=new FilterConfigDetail();
LambdaQueryWrapper<FilterConfigDetail> filterConfigDetailLambdaQueryWrapper= Wrappers.lambdaQuery();
filterConfigDetailLambdaQueryWrapper.eq(FilterConfigDetail::getWarehouseCode,shipmentDetail.getWarehouseCode());
//出库子单的分配规则有时,优先出库子单的分配规则
if(StringUtils.isNotEmpty(shipmentDetail.getAllocationRule())){
filterConfigDetailLambdaQueryWrapper.eq(FilterConfigDetail::getCode,shipmentDetail.getAllocationRule());
filterConfigDetail=filterConfigDetailService.getOne(filterConfigDetailLambdaQueryWrapper);
if(filterConfigDetail==null){
throw new ServiceException("出库子单出库规则配置不存在");
}
//根据sql查库存
try {
list = inventoryDetailService.selectBysql(filterConfigDetail.getStatement(),shipmentDetail,filterConfigDetail.getStatements(),shipmentPreference);
}catch (Exception e){
throw new ServiceException("sql错误");
}
return list;
}
//出库子单的分配规则没有时,优先物料的分配规则
LambdaQueryWrapper<Material> materialLambdaQueryWrapper=Wrappers.lambdaQuery();
materialLambdaQueryWrapper.eq(Material::getCode,shipmentDetail.getMaterialCode())
.eq(Material::getWarehouseCode,shipmentDetail.getWarehouseCode());
Material material=materialService.getOne(materialLambdaQueryWrapper);
if(StringUtils.isNotEmpty(material.getAllocationRule())){
filterConfigDetailLambdaQueryWrapper.eq(FilterConfigDetail::getCode,material.getAllocationRule());
filterConfigDetail=filterConfigDetailService.getOne(filterConfigDetailLambdaQueryWrapper);
if(filterConfigDetail==null){
throw new ServiceException("物料出库规则配置不存在");
}
//根据sql查库存
list=inventoryDetailService.selectBysql(filterConfigDetail.getStatement(),shipmentDetail,filterConfigDetail.getStatements(),shipmentPreference);
return list;
}
//物料的分配规则没有时,优先物料种类的分配规则
LambdaQueryWrapper<MaterialType> materialTypelam=Wrappers.lambdaQuery();
materialTypelam.eq(MaterialType::getCode,material.getType())
.eq(MaterialType::getWarehouseCode,shipmentDetail.getWarehouseCode());
MaterialType materialType=materialTypeService.getOne(materialTypelam);
if(StringUtils.isNotEmpty(materialType.getAllocationRule())){
filterConfigDetailLambdaQueryWrapper.eq(FilterConfigDetail::getCode,materialType.getAllocationRule());
filterConfigDetail=filterConfigDetailService.getOne(filterConfigDetailLambdaQueryWrapper);
if(filterConfigDetail==null){
throw new ServiceException("物料种类出库规则配置不存在");
}
//根据sql查库存
list=inventoryDetailService.selectBysql(filterConfigDetail.getStatement(),shipmentDetail,filterConfigDetail.getStatements(),shipmentPreference);
return list;
}
//都没有时,默认仓库的分配规则
//查找分配规则
filterConfigDetailLambdaQueryWrapper.eq(FilterConfigDetail::getCode,shipmentPreference.getAllocationRule());
filterConfigDetail=filterConfigDetailService.getOne(filterConfigDetailLambdaQueryWrapper);
if(filterConfigDetail==null){
throw new ServiceException("出库首选项中出库规则配置不存在");
}
//根据sql查库存
list=inventoryDetailService.selectBysql(filterConfigDetail.getStatement(),shipmentDetail,filterConfigDetail.getStatements(),shipmentPreference);
return list;
}
}