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