Administrator
2022-12-12 5aa407dd55a0a8f37774308743bb0a593bd8da3c
提交 | 用户 | 时间
58d006 1 package com.mandi.webservice.service.impl;
A 2
3 import java.util.ArrayList;
4 import java.util.Date;
5 import java.util.HashMap;
6 import java.util.List;
7 import java.util.Map;
8 import java.util.UUID;
9
10 import javax.annotation.Resource;
11
5aa407 12 import com.mandi.basicconfig.persist.*;
58d006 13 import com.mandi.fendan.util.ConvertTool;
A 14 import com.mandi.servlet.file.impl.FileLoadImpl;
15 import org.apache.commons.lang3.StringUtils;
16 import org.apache.log4j.Logger;
17 import org.springframework.stereotype.Service;
18 import org.springframework.transaction.annotation.Transactional;
19
20 import com.google.gson.JsonArray;
21 import com.google.gson.JsonElement;
22 import com.google.gson.JsonObject;
23 import com.google.gson.JsonParser;
24 import com.mandi.basicconfig.mapper.FdRepertoryNexusMapper;
25 import com.mandi.basicconfig.mapper.NczsjMapper;
26 import com.mandi.common.JSONobj;
27 import com.mandi.common.Wxhtmethod;
28 import com.mandi.common.ParamFileter.BigDecimalfiter;
29 import com.mandi.dao.common.ObjectResult;
30 import com.mandi.dao.common.PageResult;
31 import com.mandi.fendan.mapper.BsheetEcgbMapper;
32 import com.mandi.fendan.mapper.BusinessMapper;
33 import com.mandi.fendan.mapper.Fd_BsheetMapper;
34 import com.mandi.fendan.mapper.Fd_CompanyMapper;
35 import com.mandi.fendan.mapper.Fd_GbxstdMapper;
36 import com.mandi.fendan.mapper.Fd_GbxstdmxMapper;
37 import com.mandi.fendan.mapper.Fd_VehicleMapper;
38 import com.mandi.fendan.mapper.Fd_XSTDMXMapper;
39 import com.mandi.fendan.mapper.Fd_XSTDMapper;
40 import com.mandi.fendan.mapper.Fd_YKTMapper;
41 import com.mandi.fendan.mapper.VehicleXSTDMapper;
42 import com.mandi.fendan.persist.BsheetEcgb;
43 import com.mandi.fendan.persist.Fd_Bsheet;
44 import com.mandi.fendan.persist.Fd_Company;
45 import com.mandi.fendan.persist.Fd_Gbxstd;
46 import com.mandi.fendan.persist.Fd_Gbxstdmx;
47 import com.mandi.fendan.persist.Fd_XSTD;
48 import com.mandi.fendan.persist.Fd_XSTDMX;
49 import com.mandi.fendan.persist.Vehicle_XSTD;
50 import com.mandi.fendan.util.Contants;
51 import com.mandi.fendan.util.persist.Serviceenum;
52 import com.mandi.fendan.util.persist.WaitXSTDMX;
53 import com.mandi.fendan.util.persist.Yktbsitem;
54 import com.mandi.webservice.service.IFdXSTDService;
55
56 @Service
57 public class FdXSTDService implements IFdXSTDService{
58
59     @Resource
60     private Fd_XSTDMapper tdper;
61     @Resource
62     private Fd_XSTDMXMapper tdmxper;
63     @Resource
64     private Fd_YKTMapper yktper;
65     @Resource
66     private VehicleXSTDMapper vhxper;
67     @Resource
68     private Fd_VehicleMapper  vhper;
69     @Resource
70     private NczsjMapper zsjper;
71     @Resource
72     private Fd_BsheetMapper fbper;
73     @Resource
74     private Fd_CompanyMapper cmper;
75     @Resource
76     private Fd_GbxstdMapper gbper;
77     @Resource
78     private Fd_GbxstdmxMapper gbmxper;
79     @Resource
80     private BusinessMapper bsper;
81     @Resource
82     private BsheetEcgbMapper beper;
83     @Resource
84     private FdRepertoryNexusMapper reNxPer;
85
86     private Logger log= Logger.getLogger(FileLoadImpl.class);
87
88     @Override
89     @Transactional(rollbackFor=Exception.class)
90     public ObjectResult<Boolean> saveFd_xstd(String dataArr) throws Exception {
91         ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
92         JsonArray ja=null;
93         try {
94             JsonParser jp=new JsonParser();
95              ja=jp.parse(dataArr).getAsJsonArray();
96         } catch (Exception e) {
97             throw new Exception("数据解析错误,参数不是json数组!");
98         }
99         if(ja!=null){
100             for (JsonElement je : ja) {
101                 JsonObject jo=je.getAsJsonObject();
102                 JsonObject objJo=null;
103                 JsonArray tdmxArr=null;
104                 try {
105                      objJo=jo.getAsJsonObject("head");
106                      tdmxArr=jo.getAsJsonArray("body");
107                 } catch (Exception e) {
108                     throw new Exception("数据解析错误,数据格式不正确!");
109                 }
110                 String ztbz=JSONobj.getstring(objJo, "td_ztbz");
111                 Fd_XSTD xstd=new Fd_XSTD();
112                 xstd=JSONobj.getobj(objJo, xstd);
113                 if("01".equals(ztbz)){
114                     xstd.setTd_ztbz(2);
115                 }else if("02".equals(ztbz)){
116                     xstd.setTd_ztbz(1);
117                 }else if("03".equals(ztbz)){
118                     xstd.setTd_ztbz(3);
119                 }else{
120                     xstd.setTd_ztbz(1);
121                 }
122                 //明细业务单元
123                 String mxywyd="";
124                 //根据仓库查找对应的厂区编号
125                 String ckNo="";//明细仓库编号
126
127                 Ncywdy cn=this.zsjper.getNcywdybyCode(xstd.getTd_ywdybh());
128                 //系统部门找不到不做处理
129                 if(cn==null||cn.getYktCode()==null||StringUtils.isEmpty(cn.getYktCode())){
130                     continue;
131                 }
132                 Ncworker ncw=this.zsjper.getNcworkerbyCode(xstd.getTd_zdr());
133                 Ncdepart ncd=this.zsjper.getNcdepartbyCode(xstd.getTd_bmbh());
134                 if(ncw!=null)
135                     xstd.setTd_zdrmc(ncw.getName());
136                 if(ncd!=null)
137                     xstd.setTd_bmmc(ncd.getName());
138                 int td_wfdsl=0;//未分单数量
139                 double td_wfdzl=0;//未分单重量
140                 String td_tdls=xstd.getTd_tdls();//提单流水号
141                 for (int i = 0; i < tdmxArr.size(); i++) {
142                     objJo=tdmxArr.get(i).getAsJsonObject();
143                     String h=JSONobj.getstring(objJo, "h");
144                     String k=JSONobj.getstring(objJo, "k");
145                     String c=JSONobj.getstring(objJo, "c");
146                     Fd_XSTDMX xstdmx=new Fd_XSTDMX();
147                     xstdmx=JSONobj.getobj(objJo,xstdmx);
148                     double mz=xstdmx.getTdmx_mz();
149
150                     xstdmx.setTdmx_ggxh((h==null?"C":h)+"*"+(k==null?"C":k)+"*"+(c==null?"C":c));
151                     if(StringUtils.isEmpty(td_tdls)){
152                         td_tdls=xstdmx.getTdmx_tdls();
153                     }
154                     if(StringUtils.isBlank(mxywyd)){
155                         cn=this.zsjper.getNcywdybyCode(xstdmx.getTdmx_fhzz());
156                         //系统部门找不到不做处理
157                         if(cn!=null && StringUtils.isNotBlank(cn.getYktCode())){
158                             mxywyd=xstdmx.getTdmx_fhzz();
159                         }else{
160                             continue;
161                         }
162                         if(StringUtils.isBlank(ckNo)) {
163                             Ncck ck=this.zsjper.getNcckbyPkid(xstdmx.getTdmx_ck());
164                             if(ck!=null)
165                                 ckNo=ck.getCode();
166
167                         }
168                     }
169                     //有上次已装车记录
170                     Fd_XSTDMX ccr=this.tdmxper.get(xstdmx.getTdmx_tdfl());
171                     if(ccr!=null&&ccr.getTdmx_zcbz()>0){
172                         continue;
173                     }else{
174                         if(ccr!=null){
175                             this.tdmxper.del(xstdmx.getTdmx_tdfl());
176                         }
177                     }
178
179
180                     if(Contants.NcNosend.equals(mxywyd)){
181                         this.tdmxper.delbyTDLS(xstd.getTd_tdls());
182                         this.tdper.del(xstd.getTd_tdls());
183                         break;
184                     }
185                     this.tdmxper.insert(xstdmx);
186                     //如果这次推过来的是关闭的 明细保存  表头不增加未分单数量
187                     if(xstdmx.getTdmx_gbbz()==0){
188                         td_wfdsl++;
189                         td_wfdzl+=mz;
190                     }
191
192                 }
193
194                 if(!Contants.NcNosend.equals(mxywyd)){
195                     //获取生成厂区编号
196                     FdRepertoryNexus renx=this.reNxPer.getbyckNoAndYwdyNo(ckNo,mxywyd);
197                     if(renx!=null)
198                         xstd.setTd_cqNo(renx.getSdepartNo());
199                     xstd.setTd_wfdsl(td_wfdsl);
200                     xstd.setTd_wfdzl(td_wfdzl);
201                     xstd.setTd_ywdybh(mxywyd);
202                     this.tdper.insert(xstd);
203                 }
204             }
205         }
206         orr.setCode(0);
207         orr.setErrmsg("新增成功!");
208         return orr;
209     }
210
211     @Override
212     @Transactional(rollbackFor=Exception.class)
213     public ObjectResult<Boolean> delFd_xstd(String dataArr) throws Exception {
214         ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
215         JsonArray ja=null;
216         try {
217             JsonParser jp=new JsonParser();
218             ja=jp.parse(dataArr).getAsJsonArray();
219         } catch (Exception e) {
220             throw new Exception("数据解析错误,参数不是json数组!");
221         }
222         if(ja!=null){
223             for (JsonElement je : ja) {
224                 JsonObject jo=je.getAsJsonObject();
225                 JsonObject objJo=null;
226                 try {
227                      objJo=jo.getAsJsonObject("head");
228                 } catch (Exception e) {
229                     throw new Exception("数据解析错误,数据格式不正确!");
230                 }
231                 String td_tdls=JSONobj.getstring(objJo, "td_tdls");
232                 if(StringUtils.isBlank(td_tdls)){
233                     throw new Exception("数据解析错误,提单流水号不能为空!");
234                 }
235
236                 Fd_XSTD td_xstd=this.tdper.get(td_tdls);
237                 if(td_xstd!=null){
238                     int c=this.tdmxper.getbytdlswithZCorFD(td_tdls);
239                     if(c>0){
240                         throw new Exception("发货单:"+td_xstd.getTd_tdbh()+" 已经分单或装车,不能删除!");
241                     }
242 //                    //只删除标志是未装车的
243                     this.tdmxper.delbyTDLS(td_tdls);
244                     this.tdper.del(td_tdls);
245                     this.gbper.del(td_xstd.getTd_tdbh());
246                     this.gbmxper.del(td_xstd.getTd_tdbh());
247                 }
248             }
249         }
250         orr.setCode(0);
251         orr.setErrmsg("删除成功!");
252         return orr;
253     }
254
255     @Override
256     @Transactional(rollbackFor=Exception.class)
257     public ObjectResult<Boolean> closeFd_xstd(String dataArr) throws Exception {
258         ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
259         JsonArray ja=null;
260         try {
261             JsonParser jp=new JsonParser();
262             ja=jp.parse(dataArr).getAsJsonArray();
263         } catch (Exception e) {
264             throw new Exception("数据解析错误,参数不是json数组!");
265         }
266         if(ja!=null){
267             for (JsonElement je : ja) {
268                 JsonObject jo=je.getAsJsonObject();
269                 JsonObject objJo=null;
270                 JsonArray tdmxArr=null;
271                 try {
272                      objJo=jo.getAsJsonObject("head");
273                      tdmxArr=jo.getAsJsonArray("body");
274                 } catch (Exception e) {
275                     throw new Exception("数据解析错误,数据格式不正确!");
276                 }
277
278                 //提单流水号
279                 String td_tdls=objJo.get("td_tdls")==null?"":objJo.get("td_tdls").getAsString();
280                 Fd_XSTD xstd=this.tdper.get(td_tdls);
281                 if(xstd!=null){
282                     for (int i = 0; i < tdmxArr.size(); i++) {
283                         objJo=tdmxArr.get(i).getAsJsonObject();
284                         String tdmx_tdfl=objJo.get("tdmx_tdfl")==null?"":objJo.get("tdmx_tdfl").getAsString();
285                         String sfckgb=objJo.get("sfckgb")==null?"":objJo.get("sfckgb").getAsString();
286                         Fd_XSTDMX tdmx=this.tdmxper.get(tdmx_tdfl);
287                         if(tdmx!=null&&tdmx.getTdmx_gbbz()==0){
288                             tdmx.setTdmx_gbbz(1);
289                             this.tdmxper.updateGB(tdmx);
290 //                            if(tdmx.getTdmx_zcbz()!=0){
291 //                                continue;
292 //                            }
293                             if(tdmx.getTdmx_fdbz()!=0){
294                                 //已分单未装车
295                                 if("N".equals(sfckgb)){
296                                     if(tdmx.getTdmx_zcbz()==0){
297                                         throw new Exception("提单明细:批次号:"+tdmx.getTdmx_pch()+" 已分单未装车,请联系物流公司取消分单!");
298                                     }
299                                 }
300                             }
301 //                            if(tdmx.getTdmx_zcbz()!=0){
302 //                                throw new Exception("提单流水号:"+xstd.getTd_tdls()+" 已扫码装车,不能关闭!");
303 //                            }
304
305                             if(tdmx.getTdmx_fdbz()==0){
306                                 xstd.setTd_wfdsl(xstd.getTd_wfdsl()-1);
307                                 xstd.setTd_wfdzl(xstd.getTd_wfdzl()-tdmx.getTdmx_mz());
308                                 this.tdper.updateFD(xstd);
309                             }else{
310                                 if(tdmx.getTdmx_zcbz()==0){
311                                     tdmx.setTdmx_fdywbh(null);
312                                     tdmx.setTdmx_fdwlgsbh(null);
313                                     tdmx.setTdmx_fdbz(0);
314                                     tdmx.setTdmx_fdcph(null);
315                                     this.tdmxper.updateFD(tdmx);
316                                 }
317                             }
318
319                             //这个关闭记录表示的是一卡通里的关闭操作
320                             Fd_Gbxstdmx gbmx=this.gbmxper.get(tdmx_tdfl);
321                             if(gbmx!=null){
322                                 Fd_Gbxstd gb=this.gbper.get(xstd.getTd_tdbh());
323                                 if(gb!=null){
324                                     gb.setTd_gbsl(gb.getTd_gbsl()-1);
325                                     gb.setTd_gbzl(BigDecimalfiter.sub(gb.getTd_gbzl(),tdmx.getTdmx_mz()));
326                                     this.gbper.update(gb);
327                                 }
328                                 this.gbmxper.delbyId(tdmx_tdfl);
329                             }
330                         }
331                     }
332                 }
333             }
334         }
335         orr.setCode(0);
336         orr.setErrmsg("关闭成功!");
337         return orr;
338     }
339
340     @Override
341     @Transactional(rollbackFor=Exception.class)
342     public ObjectResult<Boolean> openFd_xstd(String dataArr) throws Exception {
343         ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
344         JsonArray ja=null;
345         try {
346             JsonParser jp=new JsonParser();
347              ja=jp.parse(dataArr).getAsJsonArray();
348         } catch (Exception e) {
349             throw new Exception("数据解析错误,参数不是json数组!");
350         }
351         if(ja!=null){
352             for (JsonElement je : ja) {
353                 JsonObject jo=je.getAsJsonObject();
354                 JsonObject objJo=null;
355                 JsonArray tdmxArr=null;
356                 try {
357                      objJo=jo.getAsJsonObject("head");
358                      tdmxArr=jo.getAsJsonArray("body");
359                 } catch (Exception e) {
360                     throw new Exception("数据解析错误,数据格式不正确!");
361                 }
362
363                 //提单流水号
364                 String td_tdls=objJo.get("td_tdls")==null?"":objJo.get("td_tdls").getAsString();
365                 Fd_XSTD xstd=this.tdper.get(td_tdls);
366                 if(xstd!=null){
367                     for (int i = 0; i < tdmxArr.size(); i++) {
368                         objJo=tdmxArr.get(i).getAsJsonObject();
369                         String tdmx_tdfl=objJo.get("tdmx_tdfl")==null?"":objJo.get("tdmx_tdfl").getAsString();
370                         Fd_XSTDMX tdmx=this.tdmxper.get(tdmx_tdfl);
371                         if(tdmx!=null&&tdmx.getTdmx_gbbz()==1){
372                             tdmx.setTdmx_gbbz(0);
373                             this.tdmxper.updateGB(tdmx);
374                             if(tdmx.getTdmx_fdbz()==0){
375                                 xstd.setTd_wfdsl(xstd.getTd_wfdsl()+1);
376                                 xstd.setTd_wfdzl(xstd.getTd_wfdzl()+tdmx.getTdmx_mz());
377                                 this.tdper.updateFD(xstd);
378                             }
379                         }
380                     }
381                 }
382             }
383         }
384         orr.setCode(0);
385         orr.setErrmsg("打开成功!");
386         return orr;
387     }
388
389     @Override
390     @Transactional(rollbackFor=Exception.class)
391     public PageResult<Map<String, Object>> addZCMX(String cardID,String yktywdh, JsonArray dataArr) throws Exception {
392         PageResult<Map<String, Object>> prr=new PageResult<Map<String,Object>>();
393         List<Map<String, Object>> relist=new ArrayList<Map<String,Object>>();
394         if(StringUtils.isEmpty(yktywdh)){
395             prr.setCode(1);
396             prr.setErrmsg("参数:一卡通业务单号为空!");
397             return prr;
398         }
399         //根据卡号判断分单信息
400         //循环批次号 如果没有分单 修改为分单和装车
401         Fd_Bsheet fdb=this.fbper.getbybsNo(StringUtils.isNotBlank(yktywdh)?yktywdh:"");
402         String vehicleId="";
403         if(fdb==null){
404             prr.setCode(1);
405             prr.setErrmsg("一卡通业务单未找到,请确认单号是否正确!");
406             return prr;
407         }else{
408             if(fdb.getStatus()!=Serviceenum.在办){
409                 prr.setCode(2);
410                 prr.setErrmsg("一卡通业务单不是在办状态,系统不做处理!");
411                 return prr;
412             }
413             if(StringUtils.isBlank(cardID)){
414                 prr.setCode(1);
415                 prr.setErrmsg("参数:一卡通卡号为空!");
416                 return prr;
417             }
418             if(dataArr==null){
419                 prr.setCode(1);
420                 prr.setErrmsg("参数:批次号为空!");
421                 return prr;
422             }
423
424             Map<String, Object> mp=this.yktper.getcardinuse(cardID);
425             if(mp==null){
426                 throw new Exception("卡号不正确未找到在用卡!");
427             }
428             vehicleId=mp.get("numberplates")==null?"":mp.get("numberplates").toString();
429             if(!vehicleId.equals(fdb.getVehicleId())){
430                 prr.setCode(1);
431                 prr.setErrmsg("参数:卡号关联的车牌号和业务单关联的车牌号不一致");
432                 return prr;
433             }
434             yktywdh=fdb.getBsNo();
435         }
436
437         int wcnum=this.bsper.getweightDoc(vehicleId, fdb.getBsNo());
438         if(wcnum<=0){
439             prr.setCode(1);
440             prr.setErrmsg("车辆:"+vehicleId+" 未找到过磅单,请先过磅!");
441             return prr;
442         }
443         yktywdh=fdb.getBsNo();
444         //是否郑州厂区
445         boolean iszz=false;
446
447         //检查是否装车完成
448         Map<String, Object> mmr=this.bsper.selectTaskTime(fdb.getBsNo());
449         try {
450             if(mmr!=null&&mmr.get("zcWc")!=null&&Boolean.valueOf(mmr.get("zcWc").toString())) {
451                 prr.setCode(1);
452                 prr.setErrmsg("联系成品库办公室取消装车完成!");
453                 return prr;
454             }
455         } catch (Exception e) {
456             // TODO: handle exception
457         }
458
459
460         //第一次添加装卸记录发送装车信息
461         int sfzc=this.fbper.getbsitembyNo(fdb.getBsNo());
462         if(sfzc<=0) {
463             //发送微信公众号提醒信息
464             String url=Contants.yktLocalAdd+"/routine/sendZcMsg.htm";
465             Map<String, String> mp=new HashMap<String, String>();
466             mp.put("sdepartNo", fdb.getSdepartNo());
467             mp.put("vehicleId", vehicleId);
468             mp.put("businessNo", fdb.getBsNo());
469             Wxhtmethod.postJson(url, mp);
470         }
471         //现场过完毛重后出现扫码装车的,必须重新过磅
472         int grossNum=this.bsper.getgrosstDoc(vehicleId, fdb.getBsNo());
473
474         for (JsonElement je : dataArr) {
475             JsonObject jo=je.getAsJsonObject();
476             String tdmx_pch = jo.get("tdmx_pch").getAsString();
477 //            Fd_XSTDMX tdmx=this.tdmxper.getbyPCH(tdmx_pch);
478             Fd_XSTDMX tdmx=this.tdmxper.getbyPCHONE(tdmx_pch,vehicleId);
479             if(tdmx==null){
480                 prr.setCode(1);
481                 prr.setErrmsg("车辆:"+vehicleId+"没有该明细的分单记录或已关闭,不能添加装车!");
482                 return prr;
483             }
484             // 下面部分注释掉,改为sql语句中判断是否为未关闭
485             /*if(tdmx.getTdmx_gbbz()!=0){
486                 prr.setCode(1);
487                 prr.setErrmsg("明细:"+tdmx.getTdmx_pch()+" 在NC是已关闭状态,不能添加装车!");
488                 return prr;
489             }*/
490
491
492 //            boolean booff=false;
493 //            if(tdmx.getTdmx_zcbz()!=0){
494 //                booff=true;
495 //                throw new Exception("批次号:"+tdmx_pch+" 已经提交装车,不能重复提交装车!");
496 //            }
497             Fd_XSTD xstd=this.tdper.get(tdmx.getTdmx_tdls());
498             if(Contants.nc_ywdy_ZZ.equals(xstd.getTd_cqNo())&&!iszz){
499                 iszz=true;
500             }
501             Vehicle_XSTD vxs=this.vhxper.getVhicleByIDs(vehicleId, xstd.getTd_tdbh());
502             if(vxs==null) {
503                 prr.setCode(1);
504                 prr.setErrmsg("未找到配车关联记录,不能添加装车!");
505                 return prr;
506             }
507             //修改提单的未分单数量和重量
508             //修改提单vehicle_XSTD表
509             Fd_Company fdc=null;
510             //是否分单
511             if(tdmx.getTdmx_fdbz()==0){
512                 fdc=this.cmper.getByCompanyNo(vxs.getCompanyNo());
513                 tdmx.setTdmx_fdbz(1);
514                 tdmx.setTdmx_fdcph(vehicleId);
515                 tdmx.setTdmx_fdywbh(yktywdh);
516                 tdmx.setTdmx_fdwlgsbh(vxs.getCompanyNo());
517                 xstd.setTd_wfdsl(xstd.getTd_wfdsl()-1);
518                 xstd.setTd_wfdzl(xstd.getTd_wfdzl()-tdmx.getTdmx_mz());
519                 this.tdper.updateFD(xstd);
520                 vxs.setFd_num(vxs.getFd_num()+1);
521                 vxs.setFd_weight(vxs.getFd_weight()+tdmx.getTdmx_mz());
522                 this.vhxper.updatewithIDs(vxs);
523             }else {
524                 fdc=this.cmper.getByCompanyNo(tdmx.getTdmx_fdwlgsbh());
525             }
526             tdmx.setTdmx_zcbz(1);
527             tdmx.setTdmx_zccph(vehicleId);
528             tdmx.setTdmx_zcwlgsName(fdc.getName());
529             tdmx.setTdmx_zcdriver(fdb.getDriver());
530             tdmx.setTdmx_zcphone(fdb.getPhone());
531             this.tdmxper.updateZCnoFD(tdmx);
532
533             WaitXSTDMX wx=this.fbper.getWaittdmx(tdmx.getTdmx_tdls(), tdmx.getTdmx_tdfl());
534             this.fbper.delbsitem(tdmx.getTdmx_pch(), fdb.getBsNo());
535             Yktbsitem bsi=new Yktbsitem();
536             bsi.setId(UUID.randomUUID()+"");
537             bsi.setBussinessNo(fdb.getBsNo());
538             bsi.setName(wx.getTdmx_wlmc());
539             bsi.setMaterielNo(tdmx.getTdmx_wlbh());
540             bsi.setNorms(wx.getTdmx_ggxh());
541             bsi.setUnitname("Kg");
542             bsi.setNum(1);
543             bsi.setWeight(BigDecimalfiter.mulcon(tdmx.getTdmx_jz(), 1000, Contants.scale));
544             bsi.setPrice(0);
545             bsi.setPreweight(BigDecimalfiter.mulcon(tdmx.getTdmx_jz(), 1000, Contants.scale));
546             bsi.setPici(tdmx.getTdmx_pch());
547             bsi.setHejin(wx.getTdmx_hjzt());
548             bsi.setGross(BigDecimalfiter.mulcon(tdmx.getTdmx_mz(), 1000, Contants.scale));
549             bsi.setTaotongWeight(0);
550             bsi.setMoney(0);
551             bsi.setCdepart("");
552             bsi.setCdepartid(0);
553             bsi.setCname("");
554             bsi.setCreateid("");
555             bsi.setCtime(new Date());
556             bsi.setLoadbuild(false);
557             bsi.setFachang(false);
558             bsi.setFachang(true);
559             bsi.setFcnum(0);
560             if(StringUtils.isBlank(xstd.getTd_fpbh())){
561                 bsi.setRecompany(wx.getTdmx_shdw());
562             }else{
563                 bsi.setRecompany(
564                         /*xstd.getTd_ywdybh().equals(Contants.nc_ywdy_ZZ)?"郑州报关":
565                             xstd.getTd_ywdybh().equals(Contants.nc_ywdy_MT)?"河南报关":
566                                 xstd.getTd_ywdybh().equals(Contants.nc_ywdy_MS)?"明晟报关":
567                             "科技报关"*/
568                           ConvertTool.covertToCustoms(xstd.getTd_ywdybh())
569                             );
570             }
571             bsi.setReID("");
572             /*bsi.setDecompany(xstd.getTd_ywdybh().equals(Contants.nc_ywdy_ZZ)?"郑州明泰":
573                     xstd.getTd_ywdybh().equals(Contants.nc_ywdy_MS)?"河南明晟新材料":
574                 "眀泰科技");*/
575             bsi.setDecompany(ConvertTool.ncCovertToFactoryName(xstd.getTd_ywdybh()));
576             bsi.setDeID("");
577             bsi.setFrombatch("ERP系统");
578             bsi.setForshowindx(1);
579             bsi.setReserved11(0);
580             bsi.setReserved12(0);
581             bsi.setReserved13(0);
582             bsi.setJsnum(0);
583             this.fbper.insertbsitem(bsi);
584             Map<String, Object> remp=new HashMap<String, Object>();
585             remp.put("tdmx_pch",tdmx.getTdmx_pch());
586             remp.put("td_tdls",tdmx.getTdmx_tdls());
587             remp.put("tdmx_tdfl",tdmx.getTdmx_tdfl());
588             relist.add(remp);
589         }
590
591         if(grossNum>0) {
592             Map<String, Object> xstm=new HashMap<String, Object>();
593             xstm.put("canCm",false);
594             xstm.put("businessNo",fdb.getBsNo());
595             this.bsper.updateCanCm(xstm);
596             this.bsper.updatecanFb(vehicleId, fdb.getBsNo());
597         }
598
599         //如果是郑州的销售业务单删除排队信息
600         if(iszz){
601             int ca=this.bsper.getvehicleQ(vehicleId);
602             if(ca>0){
603 //                this.bsper.delvehicleQ(vehicleId);
604                 //删除车辆排队信息
605                 String url=Contants.yktLocalAdd+"/search/vehicleQueue/delItem.htm";
606                 Map<String, String> mp=new HashMap<String, String>();
607                 mp.put("vehicleID", vehicleId);
608                 Wxhtmethod.postJson(url, mp);
609             }
610         }
611
612         prr.setCode(0);
613         prr.setErrmsg("装车操作成功!");
614         prr.setList(relist);
615         return prr;
616     }
617
618     @Override
619     @Transactional(rollbackFor=Exception.class)
620     public ObjectResult<Boolean> delZCMX(String cardID, String yktywdh,JsonArray dataArr) throws Exception {
621         ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
622         //根据卡号判断分单信息
623         //循环批次号 如果没有分单 修改为分单和装车
624         Fd_Bsheet fdb=this.fbper.getbybsNo(StringUtils.isNotBlank(yktywdh)?yktywdh:"");
625         String vehicleId="";
626         if(fdb==null){
627             orr.setCode(1);
628             orr.setErrmsg("一卡通业务单未找到,请确认单号是否正确!");
629             return orr;
630         }else{
631             if(fdb.getStatus()!=Serviceenum.在办){
632                 orr.setCode(1);
633                 orr.setErrmsg("一卡通业务单不是在办状态,系统不做处理!");
634                 return orr;
635             }
636             if(StringUtils.isBlank(cardID)){
637                 orr.setCode(1);
638                 orr.setErrmsg("参数:一卡通卡号为空!");
639                 return orr;
640             }
641             if(dataArr==null){
642                 orr.setCode(1);
643                 orr.setErrmsg("参数:批次号为空!");
644                 return orr;
645             }
646
647             Map<String, Object> mp=this.yktper.getcardinuse(cardID);
648             if(mp==null){
649                 throw new Exception("卡号不正确未找到在用卡!");
650             }
651             vehicleId=mp.get("numberplates")==null?"":mp.get("numberplates").toString();
652             if(!vehicleId.equals(fdb.getVehicleId())){
653                 orr.setCode(1);
654                 orr.setErrmsg("参数:卡号关联的车牌号和业务单关联的车牌号不一致");
655                 return orr;
656             }
657             yktywdh=fdb.getBsNo();
658         }
659         //检查是否装车完成
660         Map<String, Object> mmr=this.bsper.selectTaskTime(fdb.getBsNo());
661         try {
662             if(mmr!=null&&mmr.get("zcWc")!=null&&Boolean.valueOf(mmr.get("zcWc").toString())) {
663                 orr.setCode(1);
664                 orr.setErrmsg("联系成品库办公室取消装车完成!");
665                 return orr;
666             }
667         } catch (Exception e) {
668             // TODO: handle exception
669         }
670 //        Fd_Bsheet nr=this.fbper.getbyVehicleId(vehicleId, Serviceenum.在办);
671 //        if(nr==null){
672 //            orr.setCode(1);
673 //            orr.setErrmsg("卡号:"+cardID+" 未找到在办销售发货单!");
674 //            return orr;
675 //        }
676
677 //        Fd_Vehicle fdv=this.vhper.getByVehicleId(vehicleId);
678 //        if(fdv==null){
679 //            orr.setCode(1);
680 //            orr.setErrmsg("车牌号:"+cardID+" 未录入车辆信息!");
681 //            return orr;
682 //        }
683         //现场过完毛重后出现扫码装车的,必须重新过磅
684         int grossNum=this.bsper.getgrosstDoc(vehicleId, fdb.getBsNo());
685         if(grossNum>0) {
686             Map<String, Object> xstm=new HashMap<String, Object>();
687             xstm.put("canCm",false);
688             xstm.put("businessNo",fdb.getBsNo());
689             this.bsper.updateCanCm(xstm);
690             this.bsper.updatecanFb(vehicleId, fdb.getBsNo());
691         }
692         for (JsonElement je : dataArr) {
693             JsonObject jo=je.getAsJsonObject();
694             String tdmx_pch=jo.get("tdmx_pch").getAsString();
695 //            Fd_XSTDMX tdmx=this.tdmxper.getbyPCH(tdmx_pch);
696             Fd_XSTDMX tdmx=this.tdmxper.getbyPCHONE(tdmx_pch,vehicleId);
23f938 697             if(tdmx == null) {
A 698                 String errMsg = "一卡通卸车失败,请查看【" + tdmx_pch +"】出库关闭标志!";
699                 throw  new Exception(errMsg);
700             }
58d006 701 //            if(tdmx.getTdmx_zcbz()!=1){
A 702 ////                throw new Exception("批次号:"+tdmx_pch+" 已经提交装车,不能重复提交装车!");
703 //                continue;
704 //            }
705 //            Fd_XSTD xstd=this.tdper.get(tdmx.getTdmx_tdls());
706 //            if(xstd==null){
707 //                continue;
708 //            }
709             //修改Fd_Bsheetitem表  这张表去掉了
710             this.fbper.delbsitem(tdmx.getTdmx_pch(), yktywdh);
711 //            //修改一卡通明细表bsitem
712 //            if(tdmx.getTdmx_zcbz()==0){
713 //                continue;
714 //            }
715             tdmx.setTdmx_zcbz(0);
716             tdmx.setTdmx_zccph(null);
717             tdmx.setTdmx_zcdriver(null);
718             tdmx.setTdmx_zcphone(null);
719             tdmx.setTdmx_zcwlgsName(null);
720             this.tdmxper.updateZCnoFD(tdmx);
721         }
722
723         orr.setCode(0);
724         orr.setErrmsg("取消装车操作成功!");
725         return orr;
726     }
727
728     @Override
729     public ObjectResult<Map<String, Object>> getcInfo(String cardID) {
730         ObjectResult<Map<String, Object>> orr=new ObjectResult<Map<String,Object>>();
731         Map<String, Object> rem=new HashMap<String, Object>();
732         Map<String, Object> mp=this.yktper.getcardinuse(cardID);
733         if(mp==null){
734             orr.setCode(1);
735             orr.setErrmsg("卡号不正确未找到在用卡!");
736             return orr;
737         }
738         String vehicleId=mp.get("numberplates")==null?"":mp.get("numberplates").toString();
5aa407 739
A 740         String type = (String)mp.get("type");
741         String sdepartNo = null;
742         if(type.equals("外来车辆卡")) {
743             sdepartNo = (String) mp.get("sdepartNo");
744         }
745
58d006 746         List<Fd_Bsheet> fd_bList = this.fbper.getListbyVehicleId(vehicleId, Serviceenum.在办);
A 747         if (fd_bList == null||fd_bList.isEmpty()) {
748             orr.setCode(1);
749             orr.setErrmsg("车辆未找到在办分单!");
750             return orr;
751         }
752         Fd_Bsheet fd_b=null;
753         if(fd_bList.size()>1) {
754             for (Fd_Bsheet fd_Bsheet : fd_bList) {
755                 int wd=this.bsper.getweightDoc(vehicleId, fd_Bsheet.getBsNo());
756                 if(wd>0) {
757                     fd_b=fd_Bsheet;
758                     break;
759                 }
760             }
761             if(fd_b==null) {
762                 orr.setCode(1);
763                 orr.setErrmsg("车辆:"+vehicleId+" 当前业务未找到绑定的过磅单,请先过磅或者重绑磅单!");
764                 return orr;
765             }
766         }else {
767             fd_b=fd_bList.get(0);
768             int wcnum=this.bsper.getweightDoc(vehicleId, fd_b.getBsNo());
769             if(wcnum<=0){
770                 orr.setCode(1);
771                 orr.setErrmsg("车辆:"+vehicleId+" 当前业务未找到绑定的过磅单,请先过磅或者重绑磅单!");
772                 return orr;
773             }
774         }
5aa407 775         // 改成使用在用卡的卡号、车牌号码、厂区来确认是否有销售的业务单 btid=3 businesstype00002
A 776         String businessNo = bsper.getBusinessNoByCardNo(cardID,vehicleId,sdepartNo);
58d006 777         if(StringUtils.isBlank(businessNo)) {
A 778             orr.setCode(1);
779             orr.setErrmsg("未找到该卡的在办业务单!");
780             return orr;
781         }
782 //        List<Vehicle_XSTD> vxl=this.vhxper.getlistbyVehicleId(vehicleId);
783         List<Vehicle_XSTD> vxl= this.vhxper.getlistbyVehicleIdandbsNoGp(vehicleId, businessNo);
784         List<Map<String, Object>> datamp=new ArrayList<Map<String, Object>>();
5aa407 785         Map<String,Fd_XSTD> xstdMap = new HashMap(); // 缓存Fd_XSTD,避免多查
58d006 786         for (Vehicle_XSTD vx : vxl) {
A 787             String tdbh=vx.getXstdNo();
788             Fd_XSTD td=this.tdper.getbyTDBH(tdbh);
789             String wlgsbh=vx.getCompanyNo();
790             Fd_Company fd_c=this.cmper.getByCompanyNo(wlgsbh);
791             Map<String, Object> tdm=new HashMap<String, Object>();
792             if(fd_c!=null){
793                 tdm.put("td_wlgs", fd_c.getName());//物流公司
794             }else{
795                 tdm.put("td_wlgs", "");//物流公司
796             }
797             if(td==null){
798                 continue;
799             }
800             // List<Fd_XSTDMX> tdmxl=this.tdmxper.getbytdls(td.getTd_tdls());
801             List<Fd_XSTDMX> tdmxl= tdmxper.getListByTdlsAndCph(td.getTd_tdls(),vehicleId);
802             if(tdmxl==null||tdmxl.size()<=0){
803                 continue;
804             }
805             Map<String, Object> mm=new HashMap<String, Object>();
806             tdm.put("td_tdbh", td.getTd_tdbh());
807             tdm.put("td_tdls", td.getTd_tdls());
808             tdm.put("td_jylx", td.getTd_jylx());
5aa407 809             Fd_XSTD fd_xstd = xstdMap.get(td.getTd_tdbh());
A 810             if(xstdMap.get(td.getTd_tdbh())==null) { // 保证同一个提单只查一遍
811                 fd_xstd = tdper.getbyttdbh(td.getTd_tdbh());
812             }
813             //增加客户名称 备注
814             if(StringUtils.isBlank(fd_xstd.getTd_fpbh())){
815                 Nckh nckh = zsjper.getNckhbyCode(fd_xstd.getTd_khbh());// 客户不存在的特殊情况是不应该存在的,以防万一,加判空。
816                 tdm.put("td_khmc",nckh!=null?nckh.getName():"");
817             }else {
818                 String name = ConvertTool.covertToCustoms(fd_xstd.getTd_ywdybh());
819                 tdm.put("td_khmc", name);
820             }
821             tdm.put("td_bz",fd_xstd.getTd_bz());
58d006 822             mm.put("td", tdm);
A 823             mm.put("tdmx", tdmxl);
824             datamp.add(mm);
825         }
5aa407 826
A 827
58d006 828         rem.put("cph", vehicleId);
A 829         rem.put("sjmc", fd_b.getDriver());
830         rem.put("dh", fd_b.getPhone());
831 //        rem.put("sjmc", fdv.getDriver());
832 //        rem.put("dh", fdv.getPhone());
833         rem.put("ywdh", fd_b.getBsNo());
834         rem.put("respcode", 111);
835         rem.put("data", datamp);
836
837         //修改装车记录
838         Map<String, Object> mr=this.bsper.selectTaskTime(fd_b.getBsNo());
839         if(mr!=null) {
840             if(mr.get("firstzxhtime")!=null) {
841                 mr.put("lastzxhtime", new Date());
842             }else {
843                 mr.put("firstzxhtime", new Date());
844             }
845             this.bsper.updateTaskTime(mr);
846         }else {
847             orr.setCode(1);
848             orr.setErrmsg("未找到装车记录");
849             return orr;
850         }
851
852         orr.setCode(0);
853         orr.setItem(rem);
854         return orr;
855     }
856
857     @Override
858     public ObjectResult<Map<String, Object>> getxstdInfo(String xstdNo) {
859         ObjectResult<Map<String, Object>> orr=new ObjectResult<Map<String,Object>>();
860         Fd_XSTD xstd=this.tdper.getbyTDBH(xstdNo);
861         if(xstd==null){
862             orr.setCode(1);
863             orr.setErrmsg("提单未找到!");
864             return orr;
865         }
866         Map<String, Object> rm=new HashMap<String, Object>();
867         List<Fd_XSTDMX> tdmxlist=this.tdmxper.getListbytdls(xstd.getTd_tdls());
868         rm.put("code", 0);
869         rm.put("item", xstd);
870         rm.put("itemList", tdmxlist);
871         orr.setCode(0);
872         orr.setItem(rm);
873         return orr;
874     }
875
876     @Override
877     @Transactional(rollbackFor=Exception.class)
878     public ObjectResult<Boolean> savewdControl(JsonArray dataArr)throws Exception {
879         ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
880         if(dataArr==null){
881             orr.setCode(0);
882             orr.setErrmsg("添加过磅控制成功!");
883             return orr;
884         }
885         for (JsonElement je : dataArr) {
886             JsonObject jo=je.getAsJsonObject();
887             String bsNo=jo.get("yktywdh").getAsString();
888             BsheetEcgb be=this.beper.getbyNo(bsNo);
889             if(be==null){
890                 be=new BsheetEcgb();
891                 be.setBsNo(bsNo);
892                 be.setCtime(new Date());
893                 be.setCname("生产系统添加");
894                 be.setSate(1);
895                 this.beper.insert(be);
896             }
897         }
898         orr.setCode(0);
899         orr.setErrmsg("添加过磅控制成功!");
900         return orr;
901     }
902
903
904
905
906 }