Administrator
2023-04-17 63fbfddabe08e353ad75e495c2ac8dc5203da88c
提交 | 用户 | 时间
58d006 1 package com.mandi.webservice.service.impl;
A 2
3 import com.google.gson.JsonArray;
4 import com.google.gson.JsonElement;
5 import com.google.gson.JsonObject;
6 import com.google.gson.JsonParser;
7 import com.mandi.basicconfig.mapper.FdRepertoryNexusMapper;
8 import com.mandi.basicconfig.mapper.NczsjMapper;
4c64dc 9 import com.mandi.basicconfig.persist.*;
58d006 10 import com.mandi.common.JSONobj;
A 11 import com.mandi.common.ParamFileter.BigDecimalfiter;
63fbfd 12 import com.mandi.common.SpringContext;
4c64dc 13 import com.mandi.common.Wxhtmethod;
58d006 14 import com.mandi.dao.common.ObjectResult;
A 15 import com.mandi.dao.common.PageResult;
4c64dc 16 import com.mandi.fendan.mapper.*;
A 17 import com.mandi.fendan.persist.*;
58d006 18 import com.mandi.fendan.util.Contants;
4c64dc 19 import com.mandi.fendan.util.ConvertTool;
A 20 import com.mandi.fendan.util.ThreadPoolUtil;
58d006 21 import com.mandi.fendan.util.persist.Serviceenum;
A 22 import com.mandi.fendan.util.persist.WaitXSTDMX;
23 import com.mandi.fendan.util.persist.Yktbsitem;
4c64dc 24 import com.mandi.servlet.file.impl.FileLoadImpl;
58d006 25 import com.mandi.webservice.service.IFdXSTDService;
4c64dc 26 import org.apache.commons.lang3.StringUtils;
A 27 import org.apache.log4j.Logger;
63fbfd 28 import org.springframework.context.ApplicationContext;
4c64dc 29 import org.springframework.stereotype.Service;
A 30 import org.springframework.transaction.annotation.Transactional;
31
32 import javax.annotation.Resource;
33 import java.util.*;
58d006 34
A 35 @Service
36 public class FdXSTDService implements IFdXSTDService{
37
38     @Resource
39     private Fd_XSTDMapper tdper;
40     @Resource
41     private Fd_XSTDMXMapper tdmxper;
42     @Resource
43     private Fd_YKTMapper yktper;
44     @Resource
45     private VehicleXSTDMapper vhxper;
46     @Resource
47     private Fd_VehicleMapper  vhper;
48     @Resource
49     private NczsjMapper zsjper;
50     @Resource
51     private Fd_BsheetMapper fbper;
52     @Resource
53     private Fd_CompanyMapper cmper;
54     @Resource
55     private Fd_GbxstdMapper gbper;
56     @Resource
57     private Fd_GbxstdmxMapper gbmxper;
58     @Resource
59     private BusinessMapper bsper;
60     @Resource
61     private BsheetEcgbMapper beper;
62     @Resource
63     private FdRepertoryNexusMapper reNxPer;
64
65     private Logger log= Logger.getLogger(FileLoadImpl.class);
63fbfd 66
A 67     public static Boolean refreshMsLedLock = false;
68     public static Boolean refreshYrLedLock = false;
58d006 69
A 70     @Override
71     @Transactional(rollbackFor=Exception.class)
72     public ObjectResult<Boolean> saveFd_xstd(String dataArr) throws Exception {
73         ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
74         JsonArray ja=null;
75         try {
76             JsonParser jp=new JsonParser();
77              ja=jp.parse(dataArr).getAsJsonArray();
78         } catch (Exception e) {
79             throw new Exception("数据解析错误,参数不是json数组!");
80         }
81         if(ja!=null){
82             for (JsonElement je : ja) {
83                 JsonObject jo=je.getAsJsonObject();
84                 JsonObject objJo=null;
85                 JsonArray tdmxArr=null;
86                 try {
87                      objJo=jo.getAsJsonObject("head");
88                      tdmxArr=jo.getAsJsonArray("body");
89                 } catch (Exception e) {
90                     throw new Exception("数据解析错误,数据格式不正确!");
91                 }
92                 String ztbz=JSONobj.getstring(objJo, "td_ztbz");
93                 Fd_XSTD xstd=new Fd_XSTD();
94                 xstd=JSONobj.getobj(objJo, xstd);
95                 if("01".equals(ztbz)){
96                     xstd.setTd_ztbz(2);
97                 }else if("02".equals(ztbz)){
98                     xstd.setTd_ztbz(1);
99                 }else if("03".equals(ztbz)){
100                     xstd.setTd_ztbz(3);
101                 }else{
102                     xstd.setTd_ztbz(1);
103                 }
104                 //明细业务单元
105                 String mxywyd="";
106                 //根据仓库查找对应的厂区编号
107                 String ckNo="";//明细仓库编号
108
109                 Ncywdy cn=this.zsjper.getNcywdybyCode(xstd.getTd_ywdybh());
110                 //系统部门找不到不做处理
111                 if(cn==null||cn.getYktCode()==null||StringUtils.isEmpty(cn.getYktCode())){
112                     continue;
113                 }
114                 Ncworker ncw=this.zsjper.getNcworkerbyCode(xstd.getTd_zdr());
115                 Ncdepart ncd=this.zsjper.getNcdepartbyCode(xstd.getTd_bmbh());
116                 if(ncw!=null)
117                     xstd.setTd_zdrmc(ncw.getName());
118                 if(ncd!=null)
119                     xstd.setTd_bmmc(ncd.getName());
120                 int td_wfdsl=0;//未分单数量
121                 double td_wfdzl=0;//未分单重量
122                 String td_tdls=xstd.getTd_tdls();//提单流水号
123                 for (int i = 0; i < tdmxArr.size(); i++) {
124                     objJo=tdmxArr.get(i).getAsJsonObject();
125                     String h=JSONobj.getstring(objJo, "h");
126                     String k=JSONobj.getstring(objJo, "k");
127                     String c=JSONobj.getstring(objJo, "c");
128                     Fd_XSTDMX xstdmx=new Fd_XSTDMX();
129                     xstdmx=JSONobj.getobj(objJo,xstdmx);
130                     double mz=xstdmx.getTdmx_mz();
131
132                     xstdmx.setTdmx_ggxh((h==null?"C":h)+"*"+(k==null?"C":k)+"*"+(c==null?"C":c));
133                     if(StringUtils.isEmpty(td_tdls)){
134                         td_tdls=xstdmx.getTdmx_tdls();
135                     }
136                     if(StringUtils.isBlank(mxywyd)){
137                         cn=this.zsjper.getNcywdybyCode(xstdmx.getTdmx_fhzz());
138                         //系统部门找不到不做处理
139                         if(cn!=null && StringUtils.isNotBlank(cn.getYktCode())){
140                             mxywyd=xstdmx.getTdmx_fhzz();
141                         }else{
142                             continue;
143                         }
144                         if(StringUtils.isBlank(ckNo)) {
145                             Ncck ck=this.zsjper.getNcckbyPkid(xstdmx.getTdmx_ck());
146                             if(ck!=null)
147                                 ckNo=ck.getCode();
148
149                         }
150                     }
151                     //有上次已装车记录
152                     Fd_XSTDMX ccr=this.tdmxper.get(xstdmx.getTdmx_tdfl());
153                     if(ccr!=null&&ccr.getTdmx_zcbz()>0){
154                         continue;
155                     }else{
156                         if(ccr!=null){
157                             this.tdmxper.del(xstdmx.getTdmx_tdfl());
158                         }
159                     }
160
161
162                     if(Contants.NcNosend.equals(mxywyd)){
163                         this.tdmxper.delbyTDLS(xstd.getTd_tdls());
164                         this.tdper.del(xstd.getTd_tdls());
165                         break;
166                     }
167                     this.tdmxper.insert(xstdmx);
168                     //如果这次推过来的是关闭的 明细保存  表头不增加未分单数量
169                     if(xstdmx.getTdmx_gbbz()==0){
170                         td_wfdsl++;
171                         td_wfdzl+=mz;
172                     }
173
174                 }
175
176                 if(!Contants.NcNosend.equals(mxywyd)){
177                     //获取生成厂区编号
178                     FdRepertoryNexus renx=this.reNxPer.getbyckNoAndYwdyNo(ckNo,mxywyd);
179                     if(renx!=null)
180                         xstd.setTd_cqNo(renx.getSdepartNo());
181                     xstd.setTd_wfdsl(td_wfdsl);
182                     xstd.setTd_wfdzl(td_wfdzl);
183                     xstd.setTd_ywdybh(mxywyd);
184                     this.tdper.insert(xstd);
185                 }
186             }
187         }
188         orr.setCode(0);
189         orr.setErrmsg("新增成功!");
190         return orr;
191     }
192
193     @Override
194     @Transactional(rollbackFor=Exception.class)
195     public ObjectResult<Boolean> delFd_xstd(String dataArr) throws Exception {
196         ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
197         JsonArray ja=null;
198         try {
199             JsonParser jp=new JsonParser();
200             ja=jp.parse(dataArr).getAsJsonArray();
201         } catch (Exception e) {
202             throw new Exception("数据解析错误,参数不是json数组!");
203         }
204         if(ja!=null){
205             for (JsonElement je : ja) {
206                 JsonObject jo=je.getAsJsonObject();
207                 JsonObject objJo=null;
208                 try {
209                      objJo=jo.getAsJsonObject("head");
210                 } catch (Exception e) {
211                     throw new Exception("数据解析错误,数据格式不正确!");
212                 }
213                 String td_tdls=JSONobj.getstring(objJo, "td_tdls");
214                 if(StringUtils.isBlank(td_tdls)){
215                     throw new Exception("数据解析错误,提单流水号不能为空!");
216                 }
217
218                 Fd_XSTD td_xstd=this.tdper.get(td_tdls);
219                 if(td_xstd!=null){
220                     int c=this.tdmxper.getbytdlswithZCorFD(td_tdls);
221                     if(c>0){
222                         throw new Exception("发货单:"+td_xstd.getTd_tdbh()+" 已经分单或装车,不能删除!");
223                     }
224 //                    //只删除标志是未装车的
225                     this.tdmxper.delbyTDLS(td_tdls);
226                     this.tdper.del(td_tdls);
227                     this.gbper.del(td_xstd.getTd_tdbh());
228                     this.gbmxper.del(td_xstd.getTd_tdbh());
229                 }
230             }
231         }
232         orr.setCode(0);
233         orr.setErrmsg("删除成功!");
234         return orr;
235     }
236
237     @Override
238     @Transactional(rollbackFor=Exception.class)
239     public ObjectResult<Boolean> closeFd_xstd(String dataArr) throws Exception {
240         ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
241         JsonArray ja=null;
242         try {
243             JsonParser jp=new JsonParser();
244             ja=jp.parse(dataArr).getAsJsonArray();
245         } catch (Exception e) {
246             throw new Exception("数据解析错误,参数不是json数组!");
247         }
248         if(ja!=null){
249             for (JsonElement je : ja) {
250                 JsonObject jo=je.getAsJsonObject();
251                 JsonObject objJo=null;
252                 JsonArray tdmxArr=null;
253                 try {
254                      objJo=jo.getAsJsonObject("head");
255                      tdmxArr=jo.getAsJsonArray("body");
256                 } catch (Exception e) {
257                     throw new Exception("数据解析错误,数据格式不正确!");
258                 }
259
260                 //提单流水号
261                 String td_tdls=objJo.get("td_tdls")==null?"":objJo.get("td_tdls").getAsString();
262                 Fd_XSTD xstd=this.tdper.get(td_tdls);
263                 if(xstd!=null){
264                     for (int i = 0; i < tdmxArr.size(); i++) {
265                         objJo=tdmxArr.get(i).getAsJsonObject();
266                         String tdmx_tdfl=objJo.get("tdmx_tdfl")==null?"":objJo.get("tdmx_tdfl").getAsString();
267                         String sfckgb=objJo.get("sfckgb")==null?"":objJo.get("sfckgb").getAsString();
268                         Fd_XSTDMX tdmx=this.tdmxper.get(tdmx_tdfl);
269                         if(tdmx!=null&&tdmx.getTdmx_gbbz()==0){
270                             tdmx.setTdmx_gbbz(1);
271                             this.tdmxper.updateGB(tdmx);
272 //                            if(tdmx.getTdmx_zcbz()!=0){
273 //                                continue;
274 //                            }
275                             if(tdmx.getTdmx_fdbz()!=0){
276                                 //已分单未装车
277                                 if("N".equals(sfckgb)){
278                                     if(tdmx.getTdmx_zcbz()==0){
279                                         throw new Exception("提单明细:批次号:"+tdmx.getTdmx_pch()+" 已分单未装车,请联系物流公司取消分单!");
280                                     }
281                                 }
282                             }
283 //                            if(tdmx.getTdmx_zcbz()!=0){
284 //                                throw new Exception("提单流水号:"+xstd.getTd_tdls()+" 已扫码装车,不能关闭!");
285 //                            }
286
287                             if(tdmx.getTdmx_fdbz()==0){
288                                 xstd.setTd_wfdsl(xstd.getTd_wfdsl()-1);
289                                 xstd.setTd_wfdzl(xstd.getTd_wfdzl()-tdmx.getTdmx_mz());
290                                 this.tdper.updateFD(xstd);
291                             }else{
292                                 if(tdmx.getTdmx_zcbz()==0){
293                                     tdmx.setTdmx_fdywbh(null);
294                                     tdmx.setTdmx_fdwlgsbh(null);
295                                     tdmx.setTdmx_fdbz(0);
296                                     tdmx.setTdmx_fdcph(null);
297                                     this.tdmxper.updateFD(tdmx);
298                                 }
299                             }
300
301                             //这个关闭记录表示的是一卡通里的关闭操作
302                             Fd_Gbxstdmx gbmx=this.gbmxper.get(tdmx_tdfl);
303                             if(gbmx!=null){
304                                 Fd_Gbxstd gb=this.gbper.get(xstd.getTd_tdbh());
305                                 if(gb!=null){
306                                     gb.setTd_gbsl(gb.getTd_gbsl()-1);
307                                     gb.setTd_gbzl(BigDecimalfiter.sub(gb.getTd_gbzl(),tdmx.getTdmx_mz()));
308                                     this.gbper.update(gb);
309                                 }
310                                 this.gbmxper.delbyId(tdmx_tdfl);
311                             }
312                         }
313                     }
314                 }
315             }
316         }
317         orr.setCode(0);
318         orr.setErrmsg("关闭成功!");
319         return orr;
320     }
321
322     @Override
323     @Transactional(rollbackFor=Exception.class)
324     public ObjectResult<Boolean> openFd_xstd(String dataArr) throws Exception {
325         ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
326         JsonArray ja=null;
327         try {
328             JsonParser jp=new JsonParser();
329              ja=jp.parse(dataArr).getAsJsonArray();
330         } catch (Exception e) {
331             throw new Exception("数据解析错误,参数不是json数组!");
332         }
333         if(ja!=null){
334             for (JsonElement je : ja) {
335                 JsonObject jo=je.getAsJsonObject();
336                 JsonObject objJo=null;
337                 JsonArray tdmxArr=null;
338                 try {
339                      objJo=jo.getAsJsonObject("head");
340                      tdmxArr=jo.getAsJsonArray("body");
341                 } catch (Exception e) {
342                     throw new Exception("数据解析错误,数据格式不正确!");
343                 }
344
345                 //提单流水号
346                 String td_tdls=objJo.get("td_tdls")==null?"":objJo.get("td_tdls").getAsString();
347                 Fd_XSTD xstd=this.tdper.get(td_tdls);
348                 if(xstd!=null){
349                     for (int i = 0; i < tdmxArr.size(); i++) {
350                         objJo=tdmxArr.get(i).getAsJsonObject();
351                         String tdmx_tdfl=objJo.get("tdmx_tdfl")==null?"":objJo.get("tdmx_tdfl").getAsString();
352                         Fd_XSTDMX tdmx=this.tdmxper.get(tdmx_tdfl);
353                         if(tdmx!=null&&tdmx.getTdmx_gbbz()==1){
354                             tdmx.setTdmx_gbbz(0);
355                             this.tdmxper.updateGB(tdmx);
356                             if(tdmx.getTdmx_fdbz()==0){
357                                 xstd.setTd_wfdsl(xstd.getTd_wfdsl()+1);
358                                 xstd.setTd_wfdzl(xstd.getTd_wfdzl()+tdmx.getTdmx_mz());
359                                 this.tdper.updateFD(xstd);
360                             }
361                         }
362                     }
363                 }
364             }
365         }
366         orr.setCode(0);
367         orr.setErrmsg("打开成功!");
368         return orr;
369     }
370
371     @Override
372     @Transactional(rollbackFor=Exception.class)
373     public PageResult<Map<String, Object>> addZCMX(String cardID,String yktywdh, JsonArray dataArr) throws Exception {
374         PageResult<Map<String, Object>> prr=new PageResult<Map<String,Object>>();
375         List<Map<String, Object>> relist=new ArrayList<Map<String,Object>>();
376         if(StringUtils.isEmpty(yktywdh)){
377             prr.setCode(1);
378             prr.setErrmsg("参数:一卡通业务单号为空!");
379             return prr;
380         }
381         //根据卡号判断分单信息
382         //循环批次号 如果没有分单 修改为分单和装车
383         Fd_Bsheet fdb=this.fbper.getbybsNo(StringUtils.isNotBlank(yktywdh)?yktywdh:"");
384         String vehicleId="";
385         if(fdb==null){
386             prr.setCode(1);
387             prr.setErrmsg("一卡通业务单未找到,请确认单号是否正确!");
388             return prr;
389         }
cc0cbf 390
A 391         if (fdb.getStatus() != Serviceenum.在办) {
392             prr.setCode(2);
393             prr.setErrmsg("一卡通业务单不是在办状态,系统不做处理!");
394             return prr;
395         }
396         if (StringUtils.isBlank(cardID)) {
397             prr.setCode(1);
398             prr.setErrmsg("参数:一卡通卡号为空!");
399             return prr;
400         }
401         if (dataArr == null) {
402             prr.setCode(1);
403             prr.setErrmsg("参数:批次号为空!");
404             return prr;
405         }
406
407         Map<String, Object> mp = this.yktper.getcardinuse(cardID);
408         if (mp == null) {
409             throw new Exception("卡号不正确未找到在用卡!");
410         }
411         vehicleId = mp.get("numberplates") == null ? "" : mp.get("numberplates").toString();
412         if (!vehicleId.equals(fdb.getVehicleId())) {
413             prr.setCode(1);
414             prr.setErrmsg("参数:卡号关联的车牌号和业务单关联的车牌号不一致");
415             return prr;
416         }
417         // yktywdh = fdb.getBsNo();
58d006 418
A 419         int wcnum=this.bsper.getweightDoc(vehicleId, fdb.getBsNo());
420         if(wcnum<=0){
421             prr.setCode(1);
422             prr.setErrmsg("车辆:"+vehicleId+" 未找到过磅单,请先过磅!");
423             return prr;
424         }
425         yktywdh=fdb.getBsNo();
426         //是否郑州厂区
427         boolean iszz=false;
428
429         //检查是否装车完成
430         Map<String, Object> mmr=this.bsper.selectTaskTime(fdb.getBsNo());
431         try {
432             if(mmr!=null&&mmr.get("zcWc")!=null&&Boolean.valueOf(mmr.get("zcWc").toString())) {
433                 prr.setCode(1);
434                 prr.setErrmsg("联系成品库办公室取消装车完成!");
435                 return prr;
436             }
437         } catch (Exception e) {
438             // TODO: handle exception
439         }
440
4c64dc 441         String currPch="";// 当前批次号
58d006 442         //第一次添加装卸记录发送装车信息
A 443         int sfzc=this.fbper.getbsitembyNo(fdb.getBsNo());
444         if(sfzc<=0) {
445             //发送微信公众号提醒信息
446             String url=Contants.yktLocalAdd+"/routine/sendZcMsg.htm";
cc0cbf 447             Map<String, String> paramMp=new HashMap<String, String>();
58d006 448             mp.put("sdepartNo", fdb.getSdepartNo());
A 449             mp.put("vehicleId", vehicleId);
450             mp.put("businessNo", fdb.getBsNo());
cc0cbf 451             Wxhtmethod.postJson(url, paramMp);
58d006 452         }
cc0cbf 453         // 现场过完毛重后出现扫码装车的,必须重新过磅
58d006 454         int grossNum=this.bsper.getgrosstDoc(vehicleId, fdb.getBsNo());
A 455
456         for (JsonElement je : dataArr) {
457             JsonObject jo=je.getAsJsonObject();
458             String tdmx_pch = jo.get("tdmx_pch").getAsString();
459 //            Fd_XSTDMX tdmx=this.tdmxper.getbyPCH(tdmx_pch);
460             Fd_XSTDMX tdmx=this.tdmxper.getbyPCHONE(tdmx_pch,vehicleId);
461             if(tdmx==null){
462                 prr.setCode(1);
463                 prr.setErrmsg("车辆:"+vehicleId+"没有该明细的分单记录或已关闭,不能添加装车!");
464                 return prr;
465             }
466             // 下面部分注释掉,改为sql语句中判断是否为未关闭
467             /*if(tdmx.getTdmx_gbbz()!=0){
468                 prr.setCode(1);
469                 prr.setErrmsg("明细:"+tdmx.getTdmx_pch()+" 在NC是已关闭状态,不能添加装车!");
470                 return prr;
471             }*/
472
473
474 //            boolean booff=false;
475 //            if(tdmx.getTdmx_zcbz()!=0){
476 //                booff=true;
477 //                throw new Exception("批次号:"+tdmx_pch+" 已经提交装车,不能重复提交装车!");
478 //            }
479             Fd_XSTD xstd=this.tdper.get(tdmx.getTdmx_tdls());
480             if(Contants.nc_ywdy_ZZ.equals(xstd.getTd_cqNo())&&!iszz){
481                 iszz=true;
482             }
483             Vehicle_XSTD vxs=this.vhxper.getVhicleByIDs(vehicleId, xstd.getTd_tdbh());
484             if(vxs==null) {
485                 prr.setCode(1);
486                 prr.setErrmsg("未找到配车关联记录,不能添加装车!");
487                 return prr;
488             }
489             //修改提单的未分单数量和重量
490             //修改提单vehicle_XSTD表
491             Fd_Company fdc=null;
492             //是否分单
493             if(tdmx.getTdmx_fdbz()==0){
494                 fdc=this.cmper.getByCompanyNo(vxs.getCompanyNo());
495                 tdmx.setTdmx_fdbz(1);
496                 tdmx.setTdmx_fdcph(vehicleId);
497                 tdmx.setTdmx_fdywbh(yktywdh);
498                 tdmx.setTdmx_fdwlgsbh(vxs.getCompanyNo());
499                 xstd.setTd_wfdsl(xstd.getTd_wfdsl()-1);
500                 xstd.setTd_wfdzl(xstd.getTd_wfdzl()-tdmx.getTdmx_mz());
501                 this.tdper.updateFD(xstd);
502                 vxs.setFd_num(vxs.getFd_num()+1);
503                 vxs.setFd_weight(vxs.getFd_weight()+tdmx.getTdmx_mz());
504                 this.vhxper.updatewithIDs(vxs);
505             }else {
506                 fdc=this.cmper.getByCompanyNo(tdmx.getTdmx_fdwlgsbh());
507             }
508             tdmx.setTdmx_zcbz(1);
509             tdmx.setTdmx_zccph(vehicleId);
510             tdmx.setTdmx_zcwlgsName(fdc.getName());
511             tdmx.setTdmx_zcdriver(fdb.getDriver());
512             tdmx.setTdmx_zcphone(fdb.getPhone());
513             this.tdmxper.updateZCnoFD(tdmx);
514
515             WaitXSTDMX wx=this.fbper.getWaittdmx(tdmx.getTdmx_tdls(), tdmx.getTdmx_tdfl());
516             this.fbper.delbsitem(tdmx.getTdmx_pch(), fdb.getBsNo());
517             Yktbsitem bsi=new Yktbsitem();
518             bsi.setId(UUID.randomUUID()+"");
519             bsi.setBussinessNo(fdb.getBsNo());
520             bsi.setName(wx.getTdmx_wlmc());
521             bsi.setMaterielNo(tdmx.getTdmx_wlbh());
522             bsi.setNorms(wx.getTdmx_ggxh());
523             bsi.setUnitname("Kg");
524             bsi.setNum(1);
525             bsi.setWeight(BigDecimalfiter.mulcon(tdmx.getTdmx_jz(), 1000, Contants.scale));
526             bsi.setPrice(0);
527             bsi.setPreweight(BigDecimalfiter.mulcon(tdmx.getTdmx_jz(), 1000, Contants.scale));
528             bsi.setPici(tdmx.getTdmx_pch());
529             bsi.setHejin(wx.getTdmx_hjzt());
530             bsi.setGross(BigDecimalfiter.mulcon(tdmx.getTdmx_mz(), 1000, Contants.scale));
531             bsi.setTaotongWeight(0);
532             bsi.setMoney(0);
533             bsi.setCdepart("");
534             bsi.setCdepartid(0);
535             bsi.setCname("");
536             bsi.setCreateid("");
537             bsi.setCtime(new Date());
538             bsi.setLoadbuild(false);
539             bsi.setFachang(false);
540             bsi.setFachang(true);
541             bsi.setFcnum(0);
542             if(StringUtils.isBlank(xstd.getTd_fpbh())){
543                 bsi.setRecompany(wx.getTdmx_shdw());
544             }else{
545                 bsi.setRecompany(
546                           ConvertTool.covertToCustoms(xstd.getTd_ywdybh())
547                             );
548             }
549             bsi.setReID("");
550             bsi.setDecompany(ConvertTool.ncCovertToFactoryName(xstd.getTd_ywdybh()));
551             bsi.setDeID("");
552             bsi.setFrombatch("ERP系统");
553             bsi.setForshowindx(1);
554             bsi.setReserved11(0);
555             bsi.setReserved12(0);
556             bsi.setReserved13(0);
557             bsi.setJsnum(0);
558             this.fbper.insertbsitem(bsi);
559             Map<String, Object> remp=new HashMap<String, Object>();
560             remp.put("tdmx_pch",tdmx.getTdmx_pch());
561             remp.put("td_tdls",tdmx.getTdmx_tdls());
562             remp.put("tdmx_tdfl",tdmx.getTdmx_tdfl());
563             relist.add(remp);
4c64dc 564             currPch  = tdmx.getTdmx_pch();
58d006 565         }
A 566
567         if(grossNum>0) {
568             Map<String, Object> xstm=new HashMap<String, Object>();
569             xstm.put("canCm",false);
570             xstm.put("businessNo",fdb.getBsNo());
571             this.bsper.updateCanCm(xstm);
572             this.bsper.updatecanFb(vehicleId, fdb.getBsNo());
573         }
574
575         //如果是郑州的销售业务单删除排队信息
576         if(iszz){
577             int ca=this.bsper.getvehicleQ(vehicleId);
578             if(ca>0){
579 //                this.bsper.delvehicleQ(vehicleId);
580                 //删除车辆排队信息
581                 String url=Contants.yktLocalAdd+"/search/vehicleQueue/delItem.htm";
cc0cbf 582                 Map<String, String> paramMp=new HashMap<String, String>();
58d006 583                 mp.put("vehicleID", vehicleId);
cc0cbf 584                 Wxhtmethod.postJson(url, paramMp);
58d006 585             }
A 586         }
587
cc0cbf 588          // 此处异步触发一下明晟发车
A 589         if("06".equals(fdb.getSdepartNo())) {
4c64dc 590             final String cph = currPch;
63fbfd 591             ThreadPoolUtil.getInstance().execute(()->{
A 592                 try {
593                     synchronized (FdXSTDService.refreshMsLedLock) {
594                         if (FdXSTDService.refreshMsLedLock) { // 系统繁忙
595                             return  ;
596                         }
597                         FdXSTDService.refreshMsLedLock = true;
598                     }
599                     sendToMsLed(cph);
600                 } catch (Exception e) {
601                     log.error(e);
602                 } finally {
603                     synchronized (FdXSTDService.refreshMsLedLock) {
604                         FdXSTDService.refreshMsLedLock = false;
605                     }
606                 }
607             });
608         }
609         if("08".equals(fdb.getSdepartNo())) {
610             final String cph = currPch;
611             ThreadPoolUtil.getInstance().execute(()->{
612                 try {
613                     synchronized (FdXSTDService.refreshYrLedLock) {
614                         if (FdXSTDService.refreshYrLedLock) { // 系统繁忙
615                             return  ;
616                         }
617                         FdXSTDService.refreshYrLedLock = true;
618                     }
619                     sendToYrLed(cph);
620                 } catch (Exception e) {
621                     log.error(e);
622                 } finally {
623                     synchronized (FdXSTDService.refreshYrLedLock) {
624                         FdXSTDService.refreshYrLedLock = false;
625                     }
626                 }
627             });
cc0cbf 628         }
58d006 629         prr.setCode(0);
A 630         prr.setErrmsg("装车操作成功!");
631         prr.setList(relist);
632         return prr;
633     }
634
4c64dc 635     /**
A 636      *
637      * @param currPch 当前批次号
638      */
639     public void sendToMsLed(String currPch){
cc0cbf 640         //A区  76-86 +  99-1
A 641         //B区  14-33 +  99-2
642         //C区  53-67 +  99-3
63fbfd 643         log.info("LED-ABC当前扫码批次号:" + currPch);
cc0cbf 644         List<Map> totalList =  tdmxper.getHwList("06"); // 获取明晟所有在办业务单的信息
63fbfd 645         log.info("LED-ABC获取信息条数:" + totalList.size());
cc0cbf 646         Map<String,List<Map>> ywbhListMap = new HashMap<>();
A 647         for (Map map : totalList) {
648             String ywdw = (String) map.get("tdmx_fdywbh");
649             if(ywbhListMap.get(ywdw) == null) {
650                 ywbhListMap.put(ywdw, new ArrayList<>());
651             }
652             ywbhListMap.get(ywdw).add(map);
653         }
4c64dc 654         String str1 = " 车号  A区  B区  C区" + "\r\n", str2="";
cc0cbf 655         //"(车牌号)\\-(A区已装车)/(A区总计)\\-(B区已装车)/(B区总计)\\-(C区已装车)/(C区总计)\\r\\n";
4c64dc 656         String formatStr = "%s %s/%s %s/%s %s/%s\r\n";
A 657         // 只有1个区
658         String speakTxtFormatStr1 = "车号%s ,装货%d件已完成,请司机清点货物后尽快驶离装货区。";
659         // 只有2个区
660         String speakTxtFormatStr2 = "车号%s,%s区装货%d件已全部扫描完成,请司机清点货物后去%s区装货。";
661         // 只有3个区
662         String speakTxtFormatStr3 = "车号%s,%s区装货%d件已全部扫描完成,请司机清点货物后去%s区%s区装货。";
663         Map speakParam = new HashMap(1);
63fbfd 664         for (Map.Entry<String, List<Map>> entry : ywbhListMap.entrySet()) {
A 665             // 遍历每个业务单的
4c64dc 666             // 当前装车A、B、C区
A 667             boolean currA = false,currB = false, currC = false;
cc0cbf 668             boolean hasZcwc = false; // 保证已经完成了
4c64dc 669             // String ywhb = entry.getKey();
cc0cbf 670             List<Map> vehicleIdTotalList = entry.getValue();
A 671             Map<String, Integer> totalAbcMap = new HashMap(3); // 总计信息
672             totalAbcMap.put("A", 0);
673             totalAbcMap.put("B", 0);
674             totalAbcMap.put("C", 0);
675             Map<String, Integer> abcMap = new HashMap(3); // 已装信息
676             abcMap.put("A", 0);
677             abcMap.put("B", 0);
678             abcMap.put("C", 0);
679             String cph = ""; // 车牌号
680             for (Map map : vehicleIdTotalList) {
681                 String hw = (String) map.get("tdmx_hwmc");
4c64dc 682                 String pch = (String) map.get("tdmx_pch");
A 683                 if("".equals(cph))  cph = (String) map.get("tdmx_fdcph");
cc0cbf 684                 Integer zcbz = (Integer) map.get("tdmx_zcbz");
A 685                 String hh = hw.replaceAll("\\-.*","");
686                 hh = hh.substring(hh.length()-2); // 取最后两位
687                 int num = Integer.parseInt(hh);
688                 if (num >= 76 && num <= 86 || hw.lastIndexOf("99-1") >= 0) { // A区
4c64dc 689                     totalAbcMap.put("A",totalAbcMap.get("A") + 1);
cc0cbf 690                     if (zcbz != null && zcbz == 1) { // 装车完成
A 691                         abcMap.put("A", abcMap.get("A") + 1);
692                         hasZcwc = true;
693                     }
4c64dc 694                     if(pch.equals(currPch)) {
A 695                         currA = true; currB = false;currC =false;
696                     }
cc0cbf 697                 } else if (num >= 14 && num <= 33 || hw.lastIndexOf("99-2") >= 0) { // B区
4c64dc 698                     totalAbcMap.put("B", totalAbcMap.get("B") + 1);
cc0cbf 699                     if (zcbz != null && zcbz == 1) {
A 700                         abcMap.put("B", abcMap.get("B") + 1);
701                         hasZcwc = true;
702                     }
4c64dc 703                     if(pch.equals(currPch)) {
A 704                         currA = false; currB = true;currC =false;
705                     }
cc0cbf 706                 } else if (num >= 53 && num <= 67 || hw.lastIndexOf("99-3") >= 0) { // C区
4c64dc 707                     totalAbcMap.put("C", totalAbcMap.get("C") + 1);
cc0cbf 708                     if (zcbz != null && zcbz == 1) {
A 709                         abcMap.put("C", abcMap.get("C") + 1);
710                         hasZcwc = true;
711                     }
4c64dc 712                     if(pch.equals(currPch)) {
A 713                         currA = false; currB = false; currC =true;
714                     }
cc0cbf 715                 }
A 716             }
63fbfd 717             // if (!hasZcwc) continue; //没有装车完成的也跳过
A 718             /*if (!(currA || currB || currC) && abcMap.get("A") + abcMap.get("B") + abcMap.get("C") ==
4c64dc 719                     totalAbcMap.get("A") + totalAbcMap.get("B") + totalAbcMap.get("C")) { // 非当前车牌号,已经装车完成但是未出厂
A 720                 continue;
63fbfd 721             }*/
A 722             str2 += String.format(formatStr, cph, fillWithZero(abcMap.get("A")), fillWithZero(totalAbcMap.get("A")),
723                     fillWithZero(abcMap.get("B")), fillWithZero(totalAbcMap.get("B")),
724                     fillWithZero(abcMap.get("C")), fillWithZero(totalAbcMap.get("C")));
4c64dc 725             // 开始准备语音
A 726             int total = 0;
727             if(currA && abcMap.get("A") == totalAbcMap.get("A")) { // 当前车在A区装车完成
728                 total = totalAbcMap.get("A");
729             }
730             if(currB && abcMap.get("B") == totalAbcMap.get("B")) {// 当前车在B区装车完成
731                 total = totalAbcMap.get("B");
732             }
733             if(currC && abcMap.get("C") == totalAbcMap.get("C")) {// 当前车在C区装车完成
734                 total = totalAbcMap.get("C");
735             }
736             if(total > 0) { // 播放语音,请离开区域
737                 speakParam.clear();
738                 String speakTxt=null ;
739                 if( (abcMap.get("A")>0  && totalAbcMap.get("B")==0 && totalAbcMap.get("C")==0) ||
740                         (abcMap.get("B")>0  && totalAbcMap.get("A")==0 && totalAbcMap.get("C")==0)  ||
741                         (abcMap.get("C")>0  && totalAbcMap.get("B")==0 && totalAbcMap.get("D")==0)
742                 ) { // 只有一个区域有货物
743                     speakTxt= String.format(speakTxtFormatStr1, cph, total);
744                 }else  if(totalAbcMap.get("A")>0 && totalAbcMap.get("B")>0 &&
745                         (totalAbcMap.get("C")==0 || totalAbcMap.get("C") == abcMap.get("C"))){ // AB都有货 C区已完或无货
746                     if(totalAbcMap.get("C")>0 && abcMap.get("A")< totalAbcMap.get("A") && abcMap.get("B")< totalAbcMap.get("B")) { // C装完AB未装完
747                         speakTxt= String.format(speakTxtFormatStr3, cph,"C", total,"A","B");
748                     } else if(abcMap.get("A")== totalAbcMap.get("A") && abcMap.get("B")< totalAbcMap.get("B")) { //A完B未完
749                         speakTxt = String.format(speakTxtFormatStr2, cph, "A", total, "B");
750                     }else if(abcMap.get("B")== totalAbcMap.get("B") && abcMap.get("A")< totalAbcMap.get("A")) {//B完A未完
751                         speakTxt = String.format(speakTxtFormatStr2, cph, "B", total, "A");
752                     }else { // 全部装完
753                         speakTxt= String.format(speakTxtFormatStr1, cph, total);
754                     }
755                 }else if(totalAbcMap.get("C")>0 && totalAbcMap.get("B")>0 &&
756                         (totalAbcMap.get("A")==0 || totalAbcMap.get("A") == abcMap.get("A")) ){ //BC有货 A区已完或无货
757                     if(totalAbcMap.get("A")>0 && abcMap.get("C")< totalAbcMap.get("C") && abcMap.get("B")< totalAbcMap.get("B")) {  // A装完BC未装完
758                         speakTxt= String.format(speakTxtFormatStr3, cph,"A", total,"B","C");
759                     } else if(abcMap.get("C")== totalAbcMap.get("C") && abcMap.get("B")< totalAbcMap.get("B")) { // C完B未装完
760                         speakTxt = String.format(speakTxtFormatStr2, cph, "C", total, "B");
761                     }else if(abcMap.get("B")== totalAbcMap.get("B") && abcMap.get("C")< totalAbcMap.get("C")) {// B完C未装完
762                         speakTxt = String.format(speakTxtFormatStr2, cph, "B", total, "C");
763                     }else { // 全部装完
764                         speakTxt= String.format(speakTxtFormatStr1, cph, total);
765                     }
766                 }else  if (totalAbcMap.get("A")>0 && totalAbcMap.get("C")>0 &&
767                         (totalAbcMap.get("B")==0 || totalAbcMap.get("B") == abcMap.get("B")) ) { //AC有货
768                     if(totalAbcMap.get("B")>0 && abcMap.get("A")< totalAbcMap.get("A") && abcMap.get("C")< totalAbcMap.get("C")) {
769                         speakTxt= String.format(speakTxtFormatStr3, cph,"B", total,"A","C");
770                     } else if(abcMap.get("A")== totalAbcMap.get("A") && abcMap.get("C")< totalAbcMap.get("C")) { // A装完C未装完
771                         speakTxt = String.format(speakTxtFormatStr2, cph, "A", total, "C");
772                     }else if(abcMap.get("C")== totalAbcMap.get("C") && abcMap.get("A")< totalAbcMap.get("A")) {// C装完A未装完
773                         speakTxt = String.format(speakTxtFormatStr2, cph, "C", total, "A");
774                     }else { // 全部装完
775                         speakTxt= String.format(speakTxtFormatStr1, cph, total);
776                     }
777                 }else if(totalAbcMap.get("A")>0 && totalAbcMap.get("B")>0 && totalAbcMap.get("C")>0) { // 3区都有货物,且只有一个取装完了
778                     if(abcMap.get("A")>0 && abcMap.get("B")<totalAbcMap.get("B") && abcMap.get("C")<totalAbcMap.get("C")) {
779                         speakTxt= String.format(speakTxtFormatStr3, cph,"A", total,"B","C");
780                     } else if(abcMap.get("B")>0 && abcMap.get("C")==0 && abcMap.get("A")==0) {
781                         speakTxt= String.format(speakTxtFormatStr3, cph,"B", total,"A","C");
782                     } else if(abcMap.get("C")>0 && abcMap.get("A")==0 && abcMap.get("B")==0) {
783                         speakTxt= String.format(speakTxtFormatStr3, cph,"C", total,"A","B");
784                     } else { // 全部装完
785                         speakTxt= String.format(speakTxtFormatStr1, cph, total);
786                     }
787                 } else {
788                     speakTxt= String.format(speakTxtFormatStr1, cph, total);
789                 }
790                 speakParam.put("SpeakTxt", speakTxt);
791                 log.info("SpeakTxt:"+ speakTxt);
792             }
cc0cbf 793             // 单辆车的单个业务单的信息结束
A 794         }
63fbfd 795         if(StringUtils.isBlank(str2)) {
A 796             str2 = "无车辆";
797         }
cc0cbf 798         Map paramMap = new HashMap();
4c64dc 799         paramMap.put("strTitle",str1);
A 800         paramMap.put("strContent",str2);
801         try {
63fbfd 802             log.info("LED-ABC webServiceAddrss:"+Contants.msLedServiceAddr+"st1::" +str1+";;;;;str2::"+str2);
A 803             String re = Wxhtmethod.post(Contants.msLedServiceAddr + "/SendLED",paramMap);
804             log.info("LED-ABC result:"+re);
805             // 语音只播一条
806             String re1 = Wxhtmethod.post(Contants.msLedServiceAddr + "/Speak",speakParam);
4c64dc 807         }catch (Exception e){}
A 808
809
810     }
63fbfd 811
A 812     @Override
813     public void sendToYrLed(String currPch) {
814             // 状态 一磅后,待装;PDA扫码 在装; 二次过磅后消失
815             // 装车区 两个汉字加两个英文或数字
816             String strTitle="序号   车号   装车区   状态\r\n";
817             String strContent = "";
818             String contentFormatStr = "%s   %s  %s   %s\r\n";
819             List<Map> list = tdmxper.yRZcList("08");
820             int index = 1;
821             for (Map map : list) {
822                 String numberplates = (String) map.get("numberplates"); // 车牌号
823                 String zcWz = (String) map.get("zcWz"); // 装车位置
824                 if(StringUtils.isNotBlank(zcWz)){
825                     zcWz = zcWz.substring(0,4);
826                 } else {
827                     zcWz = "    ";
828                 }
829                 String zcStatus = (String) map.get("zcStatus"); // 装车位置 在办/待办
830                 strContent += String.format(contentFormatStr, fillWithZero(index++), numberplates, zcWz, zcStatus);
831             }
832             Map paramMap = new HashMap();
833             paramMap.put("strTitle",strTitle);
834             paramMap.put("strContent",strContent);
835             Wxhtmethod.post(Contants.yr_zcLedUrl + "/SendLED",paramMap);
836             log.info("yr_zcLedUrl: " + Contants.yr_zcLedUrl + ";title:" + strTitle + ",content:" + strContent);
837     }
838
839     String fillWithZero(int str){
4c64dc 840         String s;
A 841         if(str<10 && str>=0) s= "0" + str;
842         else s=String.valueOf(str);
843         return s;
cc0cbf 844     }
A 845
58d006 846     @Override
A 847     @Transactional(rollbackFor=Exception.class)
848     public ObjectResult<Boolean> delZCMX(String cardID, String yktywdh,JsonArray dataArr) throws Exception {
849         ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
850         //根据卡号判断分单信息
851         //循环批次号 如果没有分单 修改为分单和装车
852         Fd_Bsheet fdb=this.fbper.getbybsNo(StringUtils.isNotBlank(yktywdh)?yktywdh:"");
853         String vehicleId="";
854         if(fdb==null){
855             orr.setCode(1);
856             orr.setErrmsg("一卡通业务单未找到,请确认单号是否正确!");
857             return orr;
858         }else{
859             if(fdb.getStatus()!=Serviceenum.在办){
860                 orr.setCode(1);
861                 orr.setErrmsg("一卡通业务单不是在办状态,系统不做处理!");
862                 return orr;
863             }
864             if(StringUtils.isBlank(cardID)){
865                 orr.setCode(1);
866                 orr.setErrmsg("参数:一卡通卡号为空!");
867                 return orr;
868             }
869             if(dataArr==null){
870                 orr.setCode(1);
871                 orr.setErrmsg("参数:批次号为空!");
872                 return orr;
873             }
874
875             Map<String, Object> mp=this.yktper.getcardinuse(cardID);
876             if(mp==null){
877                 throw new Exception("卡号不正确未找到在用卡!");
878             }
879             vehicleId=mp.get("numberplates")==null?"":mp.get("numberplates").toString();
880             if(!vehicleId.equals(fdb.getVehicleId())){
881                 orr.setCode(1);
882                 orr.setErrmsg("参数:卡号关联的车牌号和业务单关联的车牌号不一致");
883                 return orr;
884             }
885             yktywdh=fdb.getBsNo();
886         }
887         //检查是否装车完成
888         Map<String, Object> mmr=this.bsper.selectTaskTime(fdb.getBsNo());
889         try {
890             if(mmr!=null&&mmr.get("zcWc")!=null&&Boolean.valueOf(mmr.get("zcWc").toString())) {
891                 orr.setCode(1);
892                 orr.setErrmsg("联系成品库办公室取消装车完成!");
893                 return orr;
894             }
895         } catch (Exception e) {
896             // TODO: handle exception
897         }
898 //        Fd_Bsheet nr=this.fbper.getbyVehicleId(vehicleId, Serviceenum.在办);
899 //        if(nr==null){
900 //            orr.setCode(1);
901 //            orr.setErrmsg("卡号:"+cardID+" 未找到在办销售发货单!");
902 //            return orr;
903 //        }
904
905 //        Fd_Vehicle fdv=this.vhper.getByVehicleId(vehicleId);
906 //        if(fdv==null){
907 //            orr.setCode(1);
908 //            orr.setErrmsg("车牌号:"+cardID+" 未录入车辆信息!");
909 //            return orr;
910 //        }
911         //现场过完毛重后出现扫码装车的,必须重新过磅
912         int grossNum=this.bsper.getgrosstDoc(vehicleId, fdb.getBsNo());
913         if(grossNum>0) {
914             Map<String, Object> xstm=new HashMap<String, Object>();
915             xstm.put("canCm",false);
916             xstm.put("businessNo",fdb.getBsNo());
917             this.bsper.updateCanCm(xstm);
918             this.bsper.updatecanFb(vehicleId, fdb.getBsNo());
919         }
920         for (JsonElement je : dataArr) {
921             JsonObject jo=je.getAsJsonObject();
922             String tdmx_pch=jo.get("tdmx_pch").getAsString();
923 //            Fd_XSTDMX tdmx=this.tdmxper.getbyPCH(tdmx_pch);
924             Fd_XSTDMX tdmx=this.tdmxper.getbyPCHONE(tdmx_pch,vehicleId);
23f938 925             if(tdmx == null) {
A 926                 String errMsg = "一卡通卸车失败,请查看【" + tdmx_pch +"】出库关闭标志!";
927                 throw  new Exception(errMsg);
928             }
58d006 929 //            if(tdmx.getTdmx_zcbz()!=1){
A 930 ////                throw new Exception("批次号:"+tdmx_pch+" 已经提交装车,不能重复提交装车!");
931 //                continue;
932 //            }
933 //            Fd_XSTD xstd=this.tdper.get(tdmx.getTdmx_tdls());
934 //            if(xstd==null){
935 //                continue;
936 //            }
937             //修改Fd_Bsheetitem表  这张表去掉了
938             this.fbper.delbsitem(tdmx.getTdmx_pch(), yktywdh);
939 //            //修改一卡通明细表bsitem
940 //            if(tdmx.getTdmx_zcbz()==0){
941 //                continue;
942 //            }
943             tdmx.setTdmx_zcbz(0);
944             tdmx.setTdmx_zccph(null);
945             tdmx.setTdmx_zcdriver(null);
946             tdmx.setTdmx_zcphone(null);
947             tdmx.setTdmx_zcwlgsName(null);
948             this.tdmxper.updateZCnoFD(tdmx);
949         }
950
951         orr.setCode(0);
952         orr.setErrmsg("取消装车操作成功!");
953         return orr;
954     }
955
956     @Override
957     public ObjectResult<Map<String, Object>> getcInfo(String cardID) {
958         ObjectResult<Map<String, Object>> orr=new ObjectResult<Map<String,Object>>();
959         Map<String, Object> rem=new HashMap<String, Object>();
960         Map<String, Object> mp=this.yktper.getcardinuse(cardID);
961         if(mp==null){
962             orr.setCode(1);
963             orr.setErrmsg("卡号不正确未找到在用卡!");
964             return orr;
965         }
966         String vehicleId=mp.get("numberplates")==null?"":mp.get("numberplates").toString();
5aa407 967
A 968         String type = (String)mp.get("type");
969         String sdepartNo = null;
970         if(type.equals("外来车辆卡")) {
971             sdepartNo = (String) mp.get("sdepartNo");
972         }
973
58d006 974         List<Fd_Bsheet> fd_bList = this.fbper.getListbyVehicleId(vehicleId, Serviceenum.在办);
A 975         if (fd_bList == null||fd_bList.isEmpty()) {
976             orr.setCode(1);
977             orr.setErrmsg("车辆未找到在办分单!");
978             return orr;
979         }
980         Fd_Bsheet fd_b=null;
981         if(fd_bList.size()>1) {
982             for (Fd_Bsheet fd_Bsheet : fd_bList) {
983                 int wd=this.bsper.getweightDoc(vehicleId, fd_Bsheet.getBsNo());
984                 if(wd>0) {
985                     fd_b=fd_Bsheet;
986                     break;
987                 }
988             }
989             if(fd_b==null) {
990                 orr.setCode(1);
991                 orr.setErrmsg("车辆:"+vehicleId+" 当前业务未找到绑定的过磅单,请先过磅或者重绑磅单!");
992                 return orr;
993             }
994         }else {
995             fd_b=fd_bList.get(0);
996             int wcnum=this.bsper.getweightDoc(vehicleId, fd_b.getBsNo());
997             if(wcnum<=0){
998                 orr.setCode(1);
999                 orr.setErrmsg("车辆:"+vehicleId+" 当前业务未找到绑定的过磅单,请先过磅或者重绑磅单!");
1000                 return orr;
1001             }
1002         }
5aa407 1003         // 改成使用在用卡的卡号、车牌号码、厂区来确认是否有销售的业务单 btid=3 businesstype00002
A 1004         String businessNo = bsper.getBusinessNoByCardNo(cardID,vehicleId,sdepartNo);
58d006 1005         if(StringUtils.isBlank(businessNo)) {
A 1006             orr.setCode(1);
1007             orr.setErrmsg("未找到该卡的在办业务单!");
1008             return orr;
1009         }
1010 //        List<Vehicle_XSTD> vxl=this.vhxper.getlistbyVehicleId(vehicleId);
1011         List<Vehicle_XSTD> vxl= this.vhxper.getlistbyVehicleIdandbsNoGp(vehicleId, businessNo);
1012         List<Map<String, Object>> datamp=new ArrayList<Map<String, Object>>();
5aa407 1013         Map<String,Fd_XSTD> xstdMap = new HashMap(); // 缓存Fd_XSTD,避免多查
58d006 1014         for (Vehicle_XSTD vx : vxl) {
A 1015             String tdbh=vx.getXstdNo();
1016             Fd_XSTD td=this.tdper.getbyTDBH(tdbh);
1017             String wlgsbh=vx.getCompanyNo();
1018             Fd_Company fd_c=this.cmper.getByCompanyNo(wlgsbh);
1019             Map<String, Object> tdm=new HashMap<String, Object>();
1020             if(fd_c!=null){
1021                 tdm.put("td_wlgs", fd_c.getName());//物流公司
1022             }else{
1023                 tdm.put("td_wlgs", "");//物流公司
1024             }
1025             if(td==null){
1026                 continue;
1027             }
1028             // List<Fd_XSTDMX> tdmxl=this.tdmxper.getbytdls(td.getTd_tdls());
1029             List<Fd_XSTDMX> tdmxl= tdmxper.getListByTdlsAndCph(td.getTd_tdls(),vehicleId);
1030             if(tdmxl==null||tdmxl.size()<=0){
1031                 continue;
1032             }
1033             Map<String, Object> mm=new HashMap<String, Object>();
1034             tdm.put("td_tdbh", td.getTd_tdbh());
1035             tdm.put("td_tdls", td.getTd_tdls());
1036             tdm.put("td_jylx", td.getTd_jylx());
5aa407 1037             Fd_XSTD fd_xstd = xstdMap.get(td.getTd_tdbh());
A 1038             if(xstdMap.get(td.getTd_tdbh())==null) { // 保证同一个提单只查一遍
1039                 fd_xstd = tdper.getbyttdbh(td.getTd_tdbh());
1040             }
1041             //增加客户名称 备注
1042             if(StringUtils.isBlank(fd_xstd.getTd_fpbh())){
1043                 Nckh nckh = zsjper.getNckhbyCode(fd_xstd.getTd_khbh());// 客户不存在的特殊情况是不应该存在的,以防万一,加判空。
1044                 tdm.put("td_khmc",nckh!=null?nckh.getName():"");
1045             }else {
1046                 String name = ConvertTool.covertToCustoms(fd_xstd.getTd_ywdybh());
1047                 tdm.put("td_khmc", name);
1048             }
1049             tdm.put("td_bz",fd_xstd.getTd_bz());
58d006 1050             mm.put("td", tdm);
A 1051             mm.put("tdmx", tdmxl);
1052             datamp.add(mm);
1053         }
5aa407 1054
A 1055
58d006 1056         rem.put("cph", vehicleId);
A 1057         rem.put("sjmc", fd_b.getDriver());
1058         rem.put("dh", fd_b.getPhone());
1059 //        rem.put("sjmc", fdv.getDriver());
1060 //        rem.put("dh", fdv.getPhone());
1061         rem.put("ywdh", fd_b.getBsNo());
1062         rem.put("respcode", 111);
1063         rem.put("data", datamp);
1064
1065         //修改装车记录
1066         Map<String, Object> mr=this.bsper.selectTaskTime(fd_b.getBsNo());
1067         if(mr!=null) {
1068             if(mr.get("firstzxhtime")!=null) {
1069                 mr.put("lastzxhtime", new Date());
1070             }else {
1071                 mr.put("firstzxhtime", new Date());
1072             }
1073             this.bsper.updateTaskTime(mr);
1074         }else {
1075             orr.setCode(1);
1076             orr.setErrmsg("未找到装车记录");
1077             return orr;
1078         }
1079
1080         orr.setCode(0);
1081         orr.setItem(rem);
1082         return orr;
1083     }
1084
1085     @Override
1086     public ObjectResult<Map<String, Object>> getxstdInfo(String xstdNo) {
1087         ObjectResult<Map<String, Object>> orr=new ObjectResult<Map<String,Object>>();
1088         Fd_XSTD xstd=this.tdper.getbyTDBH(xstdNo);
1089         if(xstd==null){
1090             orr.setCode(1);
1091             orr.setErrmsg("提单未找到!");
1092             return orr;
1093         }
1094         Map<String, Object> rm=new HashMap<String, Object>();
1095         List<Fd_XSTDMX> tdmxlist=this.tdmxper.getListbytdls(xstd.getTd_tdls());
1096         rm.put("code", 0);
1097         rm.put("item", xstd);
1098         rm.put("itemList", tdmxlist);
1099         orr.setCode(0);
1100         orr.setItem(rm);
1101         return orr;
1102     }
1103
1104     @Override
1105     @Transactional(rollbackFor=Exception.class)
1106     public ObjectResult<Boolean> savewdControl(JsonArray dataArr)throws Exception {
1107         ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
1108         if(dataArr==null){
1109             orr.setCode(0);
1110             orr.setErrmsg("添加过磅控制成功!");
1111             return orr;
1112         }
1113         for (JsonElement je : dataArr) {
1114             JsonObject jo=je.getAsJsonObject();
1115             String bsNo=jo.get("yktywdh").getAsString();
1116             BsheetEcgb be=this.beper.getbyNo(bsNo);
1117             if(be==null){
1118                 be=new BsheetEcgb();
1119                 be.setBsNo(bsNo);
1120                 be.setCtime(new Date());
1121                 be.setCname("生产系统添加");
1122                 be.setSate(1);
1123                 this.beper.insert(be);
1124             }
1125         }
1126         orr.setCode(0);
1127         orr.setErrmsg("添加过磅控制成功!");
1128         return orr;
1129     }
1130
1131
1132
1133
1134 }