ChmConsignmentDetailService.java
15.7 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
package com.erry.iclear.dateInterface.service;
import com.erry.iclear.dateInterface.api.request.BasfMawbDetail;
import com.erry.iclear.dateInterface.api.request.MawbDetail;
import com.erry.iclear.dateInterface.common.Constant;
import com.erry.iclear.dateInterface.entity.*;
import com.erry.iclear.dateInterface.repository.ChmConsignmentDetailRepository;
import com.erry.iclear.dateInterface.repository.ChmConsignmentRepository;
import com.erry.iclear.dateInterface.util.NumberUtils;
import com.erry.iclear.dateInterface.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* @author Administrator
*/
@Service
@Slf4j
public class ChmConsignmentDetailService {
@Autowired
private ChmConsignmentDetailRepository chmConsignmentDetailRepository;
/**
* 转换运单明细
* @param mawbDetail
* @return
*/
public ChmConsignmentDetail convertToChmConsignmentDetail(MawbDetail mawbDetail,ChmConsignment chmConsignment){
ChmConsignmentDetail result = new ChmConsignmentDetail();
try{
result.setChmConsignment(chmConsignment);
//归类标志
//商品编号
result.setSkuCode(mawbDetail.getCodeTS());
//申报单价
result.setOriRegion(mawbDetail.getDeclPrice());
//申报总价
result.setAmount(mawbDetail.getDeclTotal());
//征免方式
DictionaryEntries levyTypeDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.LEVY_TYPE+mawbDetail.getDutyMode());
if(!Objects.equals(levyTypeDictionaryEntries,null)){
result.setLevyTypeDic(levyTypeDictionaryEntries);
result.setLevyType(levyTypeDictionaryEntries.getChineseName());
}
//货号
//版本号
//第一计量单位(法定单位)
DictionaryEntries firstUnitDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.TRANSACTION_UNIT+ mawbDetail.getFirstUnit());
if(!Objects.equals(firstUnitDictionaryEntries,null)){
result.setUnitLegalFirstId(firstUnitDictionaryEntries);
result.setUnitLegalFirst(firstUnitDictionaryEntries.getChineseName());
}
//第一法定数量
result.setQtyLegalFirst(BigDecimal.valueOf(mawbDetail.getFirstQty().doubleValue()));
//成交计量单位
//2021年7月8日 成交单位有修改,原取值第一法定计量单位,先取值成交单位。xjq
DictionaryEntries knockdownUnitEntries = Constant.dictionaryEntriesCache.get(Constant.TRANSACTION_UNIT+ mawbDetail.getGunit());
if(!Objects.equals(knockdownUnitEntries,null)){
result.setKnockdownUnitDic(knockdownUnitEntries);
result.setKnockdownUnit(knockdownUnitEntries.getChineseName());
}
//商品规格、型号
result.setModel(mawbDetail.getGmodel());
//商品名称
result.setSkuName(mawbDetail.getGname());
//商品序号
//成交数量
result.setKnockdownNumber(BigDecimal.valueOf(mawbDetail.getGqty().doubleValue()));
//原产国
DictionaryEntries habitatDictonaryEntries = Constant.dictionaryEntriesCache.get(Constant.COUNTRY+ mawbDetail.getOriginCountry());
if(!Objects.equals(habitatDictonaryEntries,null)){
result.setHabitatDic(habitatDictonaryEntries);
result.setHabitat(habitatDictonaryEntries.getChineseName());
}
//第二计量单位
DictionaryEntries secondUnitDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.TRANSACTION_UNIT+ mawbDetail.getSecondUnit());
if(!Objects.equals(secondUnitDictionaryEntries,null)){
result.setUnitLegalSecondId(secondUnitDictionaryEntries);
result.setUnitLegalSecond(secondUnitDictionaryEntries.getChineseName());
}
//第二法定数量
result.setQtyLegalSecond(BigDecimal.valueOf(mawbDetail.getSecondQty().doubleValue()));
//成交币制
DictionaryEntries currencyDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.CURRENCY_SYSTEM+ mawbDetail.getTradeCurr());
if(!Objects.equals(currencyDictionaryEntries,null)){
result.setCurrencyDic(currencyDictionaryEntries);
result.setCurrency(currencyDictionaryEntries.getChineseName());
}
//用途/生产厂家
//工缴费
//最终目的国
DictionaryEntries destinationCountryDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.COUNTRY+ mawbDetail.getDestinationCountry());
if(!Objects.equals(destinationCountryDictionaryEntries,null)){
result.setDestinationCountryDic(destinationCountryDictionaryEntries);
result.setDestinationCountry(destinationCountryDictionaryEntries.getChineseName());
}
//检验检疫编码
//申报货物英文名称
result.setContentDescription(mawbDetail.getDeclGoodsEname());
//目的地代码
if(StringUtils.isNotBlank(mawbDetail.getDestCode())){
OrigplacecodeMapping origplacecodeMapping = Constant.origplacecodeMappingCache.get(mawbDetail.getDestCode());
result.setOrigplacecodeMapping(origplacecodeMapping);
result.setOrigplacecode(Objects.equals(origplacecodeMapping,null)?"":origplacecodeMapping.getOrigplaceName());
}
//境内目的地/境内货源地
DomesticDestinationMapping domesticDestinationDictionaryEntries = Constant.domesticDestinationMappingCache.get(mawbDetail.getDistrictCode());
if(!Objects.equals(domesticDestinationDictionaryEntries,null)){
result.setDomesticDestinationMapping(domesticDestinationDictionaryEntries);
result.setDomesticDestination(Objects.equals(destinationCountryDictionaryEntries,null)?"":destinationCountryDictionaryEntries.getChineseName());
}
result.setDetailId(mawbDetail.getDetailId());
//录入品名
result.setInputItem(StringUtil.isEmptyWithTrim(mawbDetail.getGname()) == true ? "" : mawbDetail.getGname());
}catch (Exception e){
log.error("convertToChmConsignmentDetail() error:"+e.getMessage());
}
return result;
}
/**
* 转换运单明细
* @param mawbDetail
* @return
*/
public ChmConsignmentDetail convertToChmConsignmentDetailBasf(BasfMawbDetail mawbDetail, ChmConsignment chmConsignment){
ChmConsignmentDetail result = new ChmConsignmentDetail();
try{
result.setChmConsignment(chmConsignment);
//商品编号
result.setSkuCode(mawbDetail.getCodeTS());
//申报总价
result.setAmount(bigDecimalFormat(mawbDetail.getDeclTotal()));
//第一计量单位(法定单位)
DictionaryEntries firstUnitDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.TRANSACTION_UNIT+ mawbDetail.getFirstUnit());
if(!Objects.equals(firstUnitDictionaryEntries,null)){
result.setUnitLegalFirstId(firstUnitDictionaryEntries);
result.setUnitLegalFirst(firstUnitDictionaryEntries.getChineseName());
}
//第一法定数量
result.setQtyLegalFirst(bigDecimalFormat(BigDecimal.valueOf(mawbDetail.getFirstQty().doubleValue())));
//成交计量单位
//2021年7月8日 成交单位有修改,原取值第一法定计量单位,先取值成交单位。xjq
DictionaryEntries knockdownUnitEntries = Constant.dictionaryEntriesCache.get(Constant.TRANSACTION_UNIT+ mawbDetail.getGunit());
if(!Objects.equals(knockdownUnitEntries,null)){
result.setKnockdownUnitDic(knockdownUnitEntries);
result.setKnockdownUnit(knockdownUnitEntries.getChineseName());
}
//商品规格、型号
result.setModel(mawbDetail.getGmodel());
//商品名称
result.setSkuName(mawbDetail.getGname());
//成交数量
result.setKnockdownNumber(bigDecimalFormat(BigDecimal.valueOf(mawbDetail.getGqty().doubleValue())));
//第二计量单位
DictionaryEntries secondUnitDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.TRANSACTION_UNIT+ mawbDetail.getSecondUnit());
if(!Objects.equals(secondUnitDictionaryEntries,null)){
result.setUnitLegalSecondId(secondUnitDictionaryEntries);
result.setUnitLegalSecond(secondUnitDictionaryEntries.getChineseName());
//第二法定数量
result.setQtyLegalSecond(bigDecimalFormat(mawbDetail.getSecondQty()));
}
//成交币制
DictionaryEntries currencyDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.CURRENCY_SYSTEM+ mawbDetail.getTradeCurr());
if(!Objects.equals(currencyDictionaryEntries,null)){
result.setCurrencyDic(currencyDictionaryEntries);
result.setCurrency(currencyDictionaryEntries.getChineseName());
}
result.setDeclaredWeight(bigDecimalFormat(mawbDetail.getDeclaredWeight()));
result.setDetailId(mawbDetail.getDetailId());
}catch (Exception e){
log.error("convertToChmConsignmentDetailBasf() error:"+e.getMessage());
}
return result;
}
/**
* 转换运单明细
* @param detail
* @param gno
* @return
*/
public MawbDetail convertToChmConsignmentDetail(ChmConsignmentDetail detail,String gno){
MawbDetail result = new MawbDetail();
try{
//明细ID
result.setDetailId(detail.getId().toString());
//归类标志
result.setClassMark("");
//商品编号 必须是十位,不足的后补 00
result.setCodeTS(detail.getSkuCode());
//申报单价 小数点保留4位
result.setDeclPrice(NumberUtils.bigDecimalFormat(detail.getOriRegion(),4));
//申报总价 小数点保留2位
result.setDeclTotal(bigDecimalFormatD(NumberUtils.bigDecimalFormat(detail.getAmount(),2)));
//征免方式 数字一字码,0~9
if(!Objects.equals(detail.getLevyTypeDic(),null)){
result.setDutyMode(detail.getLevyTypeDic().getExt2());
}
//货号 有值传值,无值填空值
result.setExgNo("");
//版本号 有值传值,无值填空值
result.setExgVersion("");
//第一计量单位(法定单位) 数字三字码
if(!Objects.equals(detail.getUnitLegalFirstId(),null)){
result.setFirstUnit(detail.getUnitLegalFirstId().getExt2());
}
//第一法定数量
result.setFirstQty(NumberUtils.bigDecimalToIntger(bigDecimalFormatD(detail.getQtyLegalFirst())));
//成交计量单位 数字三字码
if(!Objects.equals(detail.getKnockdownUnitDic(),null)){
result.setGunit(detail.getKnockdownUnitDic().getExt2());
}
//商品规格、型号
result.setGmodel(detail.getModel());
//商品名称 品名必填且必须包含中文字符
result.setGname(detail.getSkuName());
//商品序号
result.setGno(gno);
//成交数量
result.setGqty(bigDecimalFormatD(detail.getKnockdownNumber()));
//原产国 英文三字码
if(!Objects.equals(detail.getHabitatDic(),null)){
result.setOriginCountry(detail.getHabitatDic().getExt3());
}
//第二计量单位 数字三字码
if(!Objects.equals(detail.getUnitLegalSecondId(),null)){
result.setSecondUnit(detail.getUnitLegalSecondId().getExt2());
}
//第二法定数量
result.setSecondQty(NumberUtils.bigDecimalToIntger(bigDecimalFormatD(detail.getQtyLegalSecond())));
//成交币制 英文三字码
if(!Objects.equals(detail.getCurrencyDic(),null)){
result.setTradeCurr(detail.getCurrencyDic().getExt2());
}
//用途/生产厂家
result.setUseTo("");
//工缴费
result.setWorkUsd(new BigDecimal(0));
//最终目的国 英文三字码
if(!Objects.equals(detail.getDestinationCountryDic(),null)){
result.setDestinationCountry(detail.getDestinationCountryDic().getExt3());
}
//检验检疫编码
result.setCiqCode("");
//申报货物英文名称
result.setDeclGoodsEname(detail.getContentDescription());
//目的地代码 有值传值,无值填空值
if(!Objects.equals(detail.getOrigplacecodeMapping(),null)){
result.setDestCode(detail.getOrigplacecodeMapping().getOrigplaceCode());
}else{
result.setDestCode("");
}
//境内目的地/境内货源地
if(!Objects.equals(detail.getDomesticDestinationMapping(),null)){
result.setDistrictCode(detail.getDomesticDestinationMapping().getDistrictCode());
}
result.setDetailId(detail.getDetailId());
}catch (Exception e){
log.error("convertToChmConsignmentDetail() error:"+e.getMessage());
}
return result;
}
public BigDecimal bigDecimalFormat(BigDecimal num){
BigDecimal bdForMat = null;
if(num !=null){
bdForMat = num.setScale(2, BigDecimal.ROUND_HALF_UP);
if(bdForMat.compareTo(BigDecimal.ZERO) == 0){
bdForMat = new BigDecimal(0.01).setScale(2,BigDecimal.ROUND_HALF_UP);
}
}
return bdForMat;
}
/**
* D类运单小数处理
* @param num
* @return
*/
public BigDecimal bigDecimalFormatD(BigDecimal num){
BigDecimal bdForMat = null;
if(num !=null){
bdForMat = num.setScale(5, BigDecimal.ROUND_HALF_UP);
/*if(bdForMat.compareTo(BigDecimal.ZERO) == 0){
bdForMat = new BigDecimal(0.00001).setScale(5,BigDecimal.ROUND_HALF_UP);
}*/
}
return bdForMat;
}
public List<ChmConsignmentDetail> findChmConsignmentDetailListByConsignmentCode(Long consignmentId){
List<ChmConsignmentDetail> result = new ArrayList<>();
try{
result= chmConsignmentDetailRepository.findChmConsignmentDetailByConsignmentCode(consignmentId);
}catch (Exception e){
log.error("findChmConsignmentDetailListByConsignmentCode() error:"+e.getMessage());
}
return result;
}
public void saveDetailList(List<ChmConsignmentDetail> chmConsignmentDetailList){
chmConsignmentDetailRepository.saveAll(chmConsignmentDetailList);
}
public void saveChmConsignmentDetail(ChmConsignmentDetail consignmentDetail){
chmConsignmentDetailRepository.save(consignmentDetail);
}
public void deleteChmConsignmentDetail(Long id){
chmConsignmentDetailRepository.deleteById(id);
}
public void deleteChmConsignmentDetailBatch(List<Long> idList){
chmConsignmentDetailRepository.deleteChmConsignmentDetailByChnConIdList(idList);
}
}