ShipmentICSmomOrder.java
10.3 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package com.huaheng.pc.shipment.shipmentHeader.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.http.HttpUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.aspectj.lang.annotation.Log;
import com.huaheng.framework.aspectj.lang.constant.BusinessType;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.address.domain.Address;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.config.company.domain.Company;
import com.huaheng.pc.config.company.domain.CompanyU8;
import com.huaheng.pc.config.company.service.CompanyU8Service;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
import com.huaheng.pc.u8.domain.*;
import com.huaheng.pc.u8.service.ICSReceiptDetailService;
import com.huaheng.pc.u8.service.ICSReceiptHeaderService;
import com.huaheng.pc.u8.service.ICSShipmentDetailService;
import com.huaheng.pc.u8.service.ICSShipmentHeaderService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@Controller
@RequestMapping("/shipment/shipmentICSmomOrder")
public class ShipmentICSmomOrder extends BaseController {
@Autowired
private ShipmentHeaderService shipmentHeaderService;
@Autowired
private ShipmentDetailService shipmentDetailService;
@Autowired
private ICSReceiptHeaderService icsReceiptHeaderService;
@Autowired
private ICSReceiptDetailService icsReceiptDetailService;
@Resource
private ICSShipmentHeaderService icsShipmentHeaderService;
@Resource
private ICSShipmentDetailService icsShipmentDetailService;
@Resource
private CompanyU8Service companyU8Service;
@Autowired
private AddressService addressService;
private String prefix = "shipment/shipmentICSmomOrder";
@RequiresPermissions("shipment:bill:view")
@GetMapping()
public String shipmentHeader()
{
return prefix + "/shipmentICSmomOrder";
}
/**
* 查询生产订单表
*/
@RequiresPermissions("shipment:bill:list")
@Log(title = "生产订单表", operating="查看生产订单表", action = BusinessType.GRANT)
@PostMapping("/getICSmomOrder")
@ResponseBody
public AjaxResult list(ICSShipmentHeader shipmentHeader)
{
AjaxResult ajaxResult=AjaxResult.success();
CompanyU8 one = companyU8Service.getOne(new LambdaQueryWrapper<CompanyU8>()
.eq(CompanyU8::getCompanyCode, ShiroUtils.getCompanyCode())
.eq(CompanyU8::getWarehouseCode, ShiroUtils.getWarehouseCode()));
shipmentHeader.setType("OO");
List<ICSShipmentHeader> icsShipmentHeaders = icsShipmentHeaderService.list(new LambdaQueryWrapper<ICSShipmentHeader>()
.eq(ICSShipmentHeader::getType, shipmentHeader.getType())
.eq(StringUtils.isNotNull(shipmentHeader.getMoId()),ICSShipmentHeader::getMoId, shipmentHeader.getMoId())
.eq(!StringUtils.isEmpty(shipmentHeader.getMoCode()),ICSShipmentHeader::getMoCode, shipmentHeader.getMoCode())
.eq(!StringUtils.isEmpty(shipmentHeader.getCMaker()),ICSShipmentHeader::getCMaker, shipmentHeader.getCMaker())
.eq(ICSShipmentHeader::getCompanyCode,one.getUCompanyCode()));
ajaxResult.setData(icsShipmentHeaders);
return ajaxResult;
}
/**
* 获取库存详情
* @param
* @return
*/
@ApiOperation("获取生产订单明细")
@Log(title = "获取生产订单明细", action = BusinessType.OTHER)
@PostMapping("/getICSmomOrderDetail")
@ResponseBody
public AjaxResult getICSmomOrderDetail(ICSShipmentDetail icsShipmentDetail){
AjaxResult ajaxResult = AjaxResult.success();
List<ICSShipmentDetail> list;
try {
list = icsShipmentDetailService.list(new LambdaQueryWrapper<ICSShipmentDetail>()
.eq(ICSShipmentDetail::getMoId,icsShipmentDetail.getMoId())
.eq(ICSShipmentDetail::getMoCode,icsShipmentDetail.getMoCode()));
} catch (Exception e) {
return AjaxResult.error(e.getMessage());
}
ajaxResult.setData(list);
return ajaxResult;
}
@ApiOperation("成品入库")
@Log(title = "成品入库", action = BusinessType.OTHER)
@GetMapping("/inStorage")
@ResponseBody
public AjaxResult inStorage(String parameters){
try {
if (StringUtils.isEmpty(parameters)){
throw new Exception("请勿提交空数据!");
}
final JSONObject jsonObject1 = JSONObject.parseObject(parameters);
ICSReceiptModel icsReceiptModel=new ICSReceiptModel();
final JSONArray list = jsonObject1.getJSONArray("list");
if(StringUtils.isNotNull(list)){
for(int i=0;i<list.size();i++){
final JSONObject jsonObject = list.getJSONObject(i);
entitySetParameter(jsonObject, icsReceiptModel);
}
return setToU8(icsReceiptModel);
}else {
entitySetParameter(jsonObject1,icsReceiptModel);
return setToU8(icsReceiptModel);
}
} catch (Exception e) {
return AjaxResult.error(e.getMessage());
}
}
//获取U8产成品入库的接口路径
public String getInStorageURL() throws Exception {
String url = addressService.selectAddress("U8",ShiroUtils.getWarehouseCode());
if (StringUtils.isEmpty(url)){
throw new Exception("未获取到出库URL,请检查url地址配置是否完整!");
}
return url;
}
//实体参数
public void entitySetParameter(JSONObject jsonObject,ICSReceiptModel icsReceiptModel) throws Exception{
final Integer moId = jsonObject.getInteger("MoId");
final String moCode = jsonObject.getString("MoCode");
final Integer modID = jsonObject.getInteger("modID");
final BigDecimal qty = jsonObject.getBigDecimal("qty");
CompanyU8 companyU8 = companyU8Service.getCompanyU8ByCode(ShiroUtils.getCompanyCode(), ShiroUtils.getWarehouseCode());
List<ICSReceiptDetail> icsReceiptDetails=new ArrayList<>();
if(moId!=null && moCode!=null &&modID!=null &&qty!=null) {
if(StringUtils.isNull(icsReceiptModel.getIcsReceiptHeader())){
ICSShipmentHeader icsShipmentHeader = icsShipmentHeaderService.getOne(new LambdaQueryWrapper<ICSShipmentHeader>()
.eq(ICSShipmentHeader::getMoCode,moCode)
.eq(ICSShipmentHeader::getMoId,moId));
ICSReceiptHeader icsReceiptHeader=new ICSReceiptHeader();
icsReceiptHeader.setCBusType("产品入库");
icsReceiptHeader.setVoucherType("CreateICSRdRecord_10");
icsReceiptHeader.setCompanyCode(companyU8.getUCompanyCode());
icsReceiptHeader.setCMaker(icsShipmentHeader.getCMaker());
icsReceiptHeader.setCMemo(icsShipmentHeader.getCMemo());
icsReceiptHeader.setCDepCode(icsShipmentHeader.getCDepCode());
icsReceiptHeader.setDPODate(icsShipmentHeader.getDDate());
if (StringUtils.isNotEmpty(icsShipmentHeader.getCWHCode())) {
icsReceiptHeader.setCWHCode(icsShipmentHeader.getCWHCode());
}else {
icsReceiptHeader.setCWHCode("20");
}
icsReceiptModel.setIcsReceiptHeader(icsReceiptHeader);
}
if(StringUtils.isNotNull(icsReceiptModel.getIcsReceiptDetails())){
for(ICSReceiptDetail i:icsReceiptModel.getIcsReceiptDetails()){
icsReceiptDetails.add(i);
}
}
List<ICSShipmentDetail> icsShipmentDetails = icsShipmentDetailService.list(new LambdaQueryWrapper<ICSShipmentDetail>()
.eq(ICSShipmentDetail::getMoId,moId)
.eq(ICSShipmentDetail::getMoCode,moCode)
.eq(ICSShipmentDetail::getMoDId,modID));
for (ICSShipmentDetail icsShipmentDetail1 : icsShipmentDetails) {
ICSReceiptDetail icsReceiptDetail=new ICSReceiptDetail();
icsReceiptDetail.setIMPoIds(modID);
icsReceiptDetail.setIQuantity(qty);
icsReceiptDetail.setCItemName(icsShipmentDetail1.getCInvName());
icsReceiptDetail.setCInvCode(icsShipmentDetail1.getCInvCode());
icsReceiptDetails.add(icsReceiptDetail);
}
icsReceiptModel.setIcsReceiptDetails(icsReceiptDetails);
}
}
//发送请求
public AjaxResult setToU8(ICSReceiptModel icsShipmentModel) throws Exception {
String jsonString = JSONObject.toJSONString(icsShipmentModel);
final String inStorageURL = getInStorageURL();
String r = HttpUtils.bodypost(inStorageURL, jsonString, ShiroUtils.getWarehouseCode());
System.out.println(jsonString);
if (StringUtils.isEmpty(r)) {
throw new Exception("入库失败!");
}
AjaxResult ajaxResult = JSON.parseObject(r,AjaxResult.class);
// JSONObject json = JSONObject.parseObject(r);
// String code = json.getString("code");
// String msg = json.getString("msg");
if (ajaxResult.hasErr()) {
throw new Exception(ajaxResult.getMsg());
}
return AjaxResult.success("成品入库成功!");
}
}