hjg
2023-10-16 a92547a2e458ca159b4877fb901f27227b941acf
提交 | 用户 | 时间
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         }
a966b5 418
cc0cbf 419         // yktywdh = fdb.getBsNo();
58d006 420
A 421         int wcnum=this.bsper.getweightDoc(vehicleId, fdb.getBsNo());
422         if(wcnum<=0){
423             prr.setCode(1);
424             prr.setErrmsg("车辆:"+vehicleId+" 未找到过磅单,请先过磅!");
425             return prr;
426         }
427         yktywdh=fdb.getBsNo();
428         //是否郑州厂区
429         boolean iszz=false;
430
431         //检查是否装车完成
432         Map<String, Object> mmr=this.bsper.selectTaskTime(fdb.getBsNo());
433         try {
434             if(mmr!=null&&mmr.get("zcWc")!=null&&Boolean.valueOf(mmr.get("zcWc").toString())) {
435                 prr.setCode(1);
436                 prr.setErrmsg("联系成品库办公室取消装车完成!");
437                 return prr;
438             }
439         } catch (Exception e) {
440             // TODO: handle exception
441         }
442
4c64dc 443         String currPch="";// 当前批次号
58d006 444         //第一次添加装卸记录发送装车信息
A 445         int sfzc=this.fbper.getbsitembyNo(fdb.getBsNo());
446         if(sfzc<=0) {
447             //发送微信公众号提醒信息
448             String url=Contants.yktLocalAdd+"/routine/sendZcMsg.htm";
cc0cbf 449             Map<String, String> paramMp=new HashMap<String, String>();
58d006 450             mp.put("sdepartNo", fdb.getSdepartNo());
A 451             mp.put("vehicleId", vehicleId);
452             mp.put("businessNo", fdb.getBsNo());
cc0cbf 453             Wxhtmethod.postJson(url, paramMp);
58d006 454         }
cc0cbf 455         // 现场过完毛重后出现扫码装车的,必须重新过磅
58d006 456         int grossNum=this.bsper.getgrosstDoc(vehicleId, fdb.getBsNo());
a966b5 457         List tdmxPchList = new ArrayList();
H 458         for (JsonElement je : dataArr) {
459             JsonObject jo=je.getAsJsonObject();
460             String tdmx_pch = jo.get("tdmx_pch").getAsString();
461             tdmxPchList.add(tdmx_pch);
462         }
a92547 463         if("08".equals(fdb.getSdepartNo())) { // 只是义瑞厂区有效
f6c2f1 464             // 检查是否当前区域已经排队
H 465             Map paramMap = new HashMap();
466             paramMap.put("vehicleId", vehicleId);
467             paramMap.put("tdmxPchList", tdmxPchList);
468             String jsonStr = Jacksonmethod.tojson(paramMap, false);
469             JsonObject jsonObject = Wxhtmethod.postJsonStr(Contants.yr_canDoScanUrl, jsonStr);
470             if (jsonObject.get("code").getAsInt() != 0) {
a966b5 471                 prr.setCode(1);
H 472                 prr.setErrmsg(jsonObject.get("errmsg").getAsString());
473                 return prr;
f6c2f1 474             }
a92547 475         }
58d006 476         for (JsonElement je : dataArr) {
A 477             JsonObject jo=je.getAsJsonObject();
478             String tdmx_pch = jo.get("tdmx_pch").getAsString();
479 //            Fd_XSTDMX tdmx=this.tdmxper.getbyPCH(tdmx_pch);
480             Fd_XSTDMX tdmx=this.tdmxper.getbyPCHONE(tdmx_pch,vehicleId);
481             if(tdmx==null){
482                 prr.setCode(1);
483                 prr.setErrmsg("车辆:"+vehicleId+"没有该明细的分单记录或已关闭,不能添加装车!");
484                 return prr;
485             }
486             // 下面部分注释掉,改为sql语句中判断是否为未关闭
487             /*if(tdmx.getTdmx_gbbz()!=0){
488                 prr.setCode(1);
489                 prr.setErrmsg("明细:"+tdmx.getTdmx_pch()+" 在NC是已关闭状态,不能添加装车!");
490                 return prr;
491             }*/
492
493
494 //            boolean booff=false;
495 //            if(tdmx.getTdmx_zcbz()!=0){
496 //                booff=true;
497 //                throw new Exception("批次号:"+tdmx_pch+" 已经提交装车,不能重复提交装车!");
498 //            }
499             Fd_XSTD xstd=this.tdper.get(tdmx.getTdmx_tdls());
500             if(Contants.nc_ywdy_ZZ.equals(xstd.getTd_cqNo())&&!iszz){
501                 iszz=true;
502             }
503             Vehicle_XSTD vxs=this.vhxper.getVhicleByIDs(vehicleId, xstd.getTd_tdbh());
504             if(vxs==null) {
505                 prr.setCode(1);
506                 prr.setErrmsg("未找到配车关联记录,不能添加装车!");
507                 return prr;
508             }
509             //修改提单的未分单数量和重量
510             //修改提单vehicle_XSTD表
511             Fd_Company fdc=null;
512             //是否分单
513             if(tdmx.getTdmx_fdbz()==0){
514                 fdc=this.cmper.getByCompanyNo(vxs.getCompanyNo());
515                 tdmx.setTdmx_fdbz(1);
516                 tdmx.setTdmx_fdcph(vehicleId);
517                 tdmx.setTdmx_fdywbh(yktywdh);
518                 tdmx.setTdmx_fdwlgsbh(vxs.getCompanyNo());
519                 xstd.setTd_wfdsl(xstd.getTd_wfdsl()-1);
520                 xstd.setTd_wfdzl(xstd.getTd_wfdzl()-tdmx.getTdmx_mz());
521                 this.tdper.updateFD(xstd);
522                 vxs.setFd_num(vxs.getFd_num()+1);
523                 vxs.setFd_weight(vxs.getFd_weight()+tdmx.getTdmx_mz());
524                 this.vhxper.updatewithIDs(vxs);
525             }else {
526                 fdc=this.cmper.getByCompanyNo(tdmx.getTdmx_fdwlgsbh());
527             }
528             tdmx.setTdmx_zcbz(1);
529             tdmx.setTdmx_zccph(vehicleId);
530             tdmx.setTdmx_zcwlgsName(fdc.getName());
531             tdmx.setTdmx_zcdriver(fdb.getDriver());
532             tdmx.setTdmx_zcphone(fdb.getPhone());
533             this.tdmxper.updateZCnoFD(tdmx);
534
535             WaitXSTDMX wx=this.fbper.getWaittdmx(tdmx.getTdmx_tdls(), tdmx.getTdmx_tdfl());
536             this.fbper.delbsitem(tdmx.getTdmx_pch(), fdb.getBsNo());
537             Yktbsitem bsi=new Yktbsitem();
538             bsi.setId(UUID.randomUUID()+"");
539             bsi.setBussinessNo(fdb.getBsNo());
540             bsi.setName(wx.getTdmx_wlmc());
541             bsi.setMaterielNo(tdmx.getTdmx_wlbh());
542             bsi.setNorms(wx.getTdmx_ggxh());
543             bsi.setUnitname("Kg");
544             bsi.setNum(1);
545             bsi.setWeight(BigDecimalfiter.mulcon(tdmx.getTdmx_jz(), 1000, Contants.scale));
546             bsi.setPrice(0);
547             bsi.setPreweight(BigDecimalfiter.mulcon(tdmx.getTdmx_jz(), 1000, Contants.scale));
548             bsi.setPici(tdmx.getTdmx_pch());
549             bsi.setHejin(wx.getTdmx_hjzt());
550             bsi.setGross(BigDecimalfiter.mulcon(tdmx.getTdmx_mz(), 1000, Contants.scale));
551             bsi.setTaotongWeight(0);
552             bsi.setMoney(0);
553             bsi.setCdepart("");
554             bsi.setCdepartid(0);
555             bsi.setCname("");
556             bsi.setCreateid("");
557             bsi.setCtime(new Date());
558             bsi.setLoadbuild(false);
559             bsi.setFachang(false);
560             bsi.setFachang(true);
561             bsi.setFcnum(0);
562             if(StringUtils.isBlank(xstd.getTd_fpbh())){
563                 bsi.setRecompany(wx.getTdmx_shdw());
564             }else{
565                 bsi.setRecompany(
566                           ConvertTool.covertToCustoms(xstd.getTd_ywdybh())
567                             );
568             }
569             bsi.setReID("");
570             bsi.setDecompany(ConvertTool.ncCovertToFactoryName(xstd.getTd_ywdybh()));
571             bsi.setDeID("");
572             bsi.setFrombatch("ERP系统");
573             bsi.setForshowindx(1);
574             bsi.setReserved11(0);
575             bsi.setReserved12(0);
576             bsi.setReserved13(0);
577             bsi.setJsnum(0);
578             this.fbper.insertbsitem(bsi);
579             Map<String, Object> remp=new HashMap<String, Object>();
580             remp.put("tdmx_pch",tdmx.getTdmx_pch());
581             remp.put("td_tdls",tdmx.getTdmx_tdls());
582             remp.put("tdmx_tdfl",tdmx.getTdmx_tdfl());
583             relist.add(remp);
4c64dc 584             currPch  = tdmx.getTdmx_pch();
58d006 585         }
A 586
587         if(grossNum>0) {
588             Map<String, Object> xstm=new HashMap<String, Object>();
589             xstm.put("canCm",false);
590             xstm.put("businessNo",fdb.getBsNo());
591             this.bsper.updateCanCm(xstm);
592             this.bsper.updatecanFb(vehicleId, fdb.getBsNo());
593         }
594
595         //如果是郑州的销售业务单删除排队信息
596         if(iszz){
597             int ca=this.bsper.getvehicleQ(vehicleId);
598             if(ca>0){
599 //                this.bsper.delvehicleQ(vehicleId);
600                 //删除车辆排队信息
601                 String url=Contants.yktLocalAdd+"/search/vehicleQueue/delItem.htm";
cc0cbf 602                 Map<String, String> paramMp=new HashMap<String, String>();
58d006 603                 mp.put("vehicleID", vehicleId);
cc0cbf 604                 Wxhtmethod.postJson(url, paramMp);
58d006 605             }
A 606         }
607
cc0cbf 608          // 此处异步触发一下明晟发车
A 609         if("06".equals(fdb.getSdepartNo())) {
4c64dc 610             final String cph = currPch;
195945 611             final String finalVehicleId = vehicleId;
63fbfd 612             ThreadPoolUtil.getInstance().execute(()->{
195945 613                 synchronized (FdXSTDService.refreshMsLedLock) {
A 614                     if (FdXSTDService.refreshMsLedLock) { // 系统繁忙
615                         log.info(finalVehicleId + "" + cph + "系统繁忙!");
616                         return;
617                     }
618                 }
63fbfd 619                 try {
A 620                     synchronized (FdXSTDService.refreshMsLedLock) {
621                         FdXSTDService.refreshMsLedLock = true;
622                     }
623                     sendToMsLed(cph);
624                 } catch (Exception e) {
195945 625                     log.error("出现异常:"+ e.getMessage(),e);
63fbfd 626                 } finally {
A 627                     synchronized (FdXSTDService.refreshMsLedLock) {
628                         FdXSTDService.refreshMsLedLock = false;
629                     }
630                 }
631             });
632         }
633         if("08".equals(fdb.getSdepartNo())) {
634             final String cph = currPch;
635             ThreadPoolUtil.getInstance().execute(()->{
a966b5 636
H 637                 Map scanCodeParamMap = new HashMap();
638                 scanCodeParamMap.put("pch",cph);
639                 Wxhtmethod.post(Contants.yr_scanCodeNoticeUrl, scanCodeParamMap);
640
63fbfd 641                 try {
A 642                     synchronized (FdXSTDService.refreshYrLedLock) {
643                         if (FdXSTDService.refreshYrLedLock) { // 系统繁忙
644                             return  ;
645                         }
646                         FdXSTDService.refreshYrLedLock = true;
647                     }
648                     sendToYrLed(cph);
649                 } catch (Exception e) {
650                     log.error(e);
651                 } finally {
652                     synchronized (FdXSTDService.refreshYrLedLock) {
653                         FdXSTDService.refreshYrLedLock = false;
654                     }
655                 }
656             });
cc0cbf 657         }
58d006 658         prr.setCode(0);
A 659         prr.setErrmsg("装车操作成功!");
660         prr.setList(relist);
661         return prr;
662     }
663
4c64dc 664     /**
A 665      *
666      * @param currPch 当前批次号
667      */
668     public void sendToMsLed(String currPch){
cc0cbf 669         //A区  76-86 +  99-1
A 670         //B区  14-33 +  99-2
671         //C区  53-67 +  99-3
63fbfd 672         log.info("LED-ABC当前扫码批次号:" + currPch);
cc0cbf 673         List<Map> totalList =  tdmxper.getHwList("06"); // 获取明晟所有在办业务单的信息
63fbfd 674         log.info("LED-ABC获取信息条数:" + totalList.size());
cc0cbf 675         Map<String,List<Map>> ywbhListMap = new HashMap<>();
A 676         for (Map map : totalList) {
677             String ywdw = (String) map.get("tdmx_fdywbh");
195945 678             if(ywdw == null) {
A 679                 log.info("出现业务单号为null的情况:" + Jacksonmethod.tojson(map,false));
680                 continue;
681             }
cc0cbf 682             if(ywbhListMap.get(ywdw) == null) {
A 683                 ywbhListMap.put(ywdw, new ArrayList<>());
684             }
685             ywbhListMap.get(ywdw).add(map);
686         }
4c64dc 687         String str1 = " 车号  A区  B区  C区" + "\r\n", str2="";
cc0cbf 688         //"(车牌号)\\-(A区已装车)/(A区总计)\\-(B区已装车)/(B区总计)\\-(C区已装车)/(C区总计)\\r\\n";
4c64dc 689         String formatStr = "%s %s/%s %s/%s %s/%s\r\n";
A 690         // 只有1个区
195945 691
4c64dc 692         Map speakParam = new HashMap(1);
63fbfd 693         for (Map.Entry<String, List<Map>> entry : ywbhListMap.entrySet()) {
A 694             // 遍历每个业务单的
4c64dc 695             // 当前装车A、B、C区
A 696             boolean currA = false,currB = false, currC = false;
cc0cbf 697             boolean hasZcwc = false; // 保证已经完成了
195945 698             String ywhb = entry.getKey();
cc0cbf 699             List<Map> vehicleIdTotalList = entry.getValue();
A 700             Map<String, Integer> totalAbcMap = new HashMap(3); // 总计信息
701             totalAbcMap.put("A", 0);
702             totalAbcMap.put("B", 0);
703             totalAbcMap.put("C", 0);
704             Map<String, Integer> abcMap = new HashMap(3); // 已装信息
705             abcMap.put("A", 0);
706             abcMap.put("B", 0);
707             abcMap.put("C", 0);
708             String cph = ""; // 车牌号
709             for (Map map : vehicleIdTotalList) {
710                 String hw = (String) map.get("tdmx_hwmc");
4c64dc 711                 String pch = (String) map.get("tdmx_pch");
195945 712                 if(StringUtils.isBlank(cph))  cph = (String) map.get("tdmx_fdcph");
cc0cbf 713                 Integer zcbz = (Integer) map.get("tdmx_zcbz");
A 714                 String hh = hw.replaceAll("\\-.*","");
715                 hh = hh.substring(hh.length()-2); // 取最后两位
716                 int num = Integer.parseInt(hh);
717                 if (num >= 76 && num <= 86 || hw.lastIndexOf("99-1") >= 0) { // A区
4c64dc 718                     totalAbcMap.put("A",totalAbcMap.get("A") + 1);
cc0cbf 719                     if (zcbz != null && zcbz == 1) { // 装车完成
A 720                         abcMap.put("A", abcMap.get("A") + 1);
721                         hasZcwc = true;
722                     }
4c64dc 723                     if(pch.equals(currPch)) {
A 724                         currA = true; currB = false;currC =false;
725                     }
cc0cbf 726                 } else if (num >= 14 && num <= 33 || hw.lastIndexOf("99-2") >= 0) { // B区
4c64dc 727                     totalAbcMap.put("B", totalAbcMap.get("B") + 1);
cc0cbf 728                     if (zcbz != null && zcbz == 1) {
A 729                         abcMap.put("B", abcMap.get("B") + 1);
730                         hasZcwc = true;
731                     }
4c64dc 732                     if(pch.equals(currPch)) {
A 733                         currA = false; currB = true;currC =false;
734                     }
cc0cbf 735                 } else if (num >= 53 && num <= 67 || hw.lastIndexOf("99-3") >= 0) { // C区
4c64dc 736                     totalAbcMap.put("C", totalAbcMap.get("C") + 1);
cc0cbf 737                     if (zcbz != null && zcbz == 1) {
A 738                         abcMap.put("C", abcMap.get("C") + 1);
739                         hasZcwc = true;
740                     }
4c64dc 741                     if(pch.equals(currPch)) {
A 742                         currA = false; currB = false; currC =true;
743                     }
cc0cbf 744                 }
A 745             }
63fbfd 746             // if (!hasZcwc) continue; //没有装车完成的也跳过
A 747             /*if (!(currA || currB || currC) && abcMap.get("A") + abcMap.get("B") + abcMap.get("C") ==
4c64dc 748                     totalAbcMap.get("A") + totalAbcMap.get("B") + totalAbcMap.get("C")) { // 非当前车牌号,已经装车完成但是未出厂
A 749                 continue;
63fbfd 750             }*/
195945 751             if(totalAbcMap.get("B")==0 && totalAbcMap.get("C")==0 && totalAbcMap.get("A")==0) {
A 752                 continue;
753             }
63fbfd 754             str2 += String.format(formatStr, cph, fillWithZero(abcMap.get("A")), fillWithZero(totalAbcMap.get("A")),
A 755                     fillWithZero(abcMap.get("B")), fillWithZero(totalAbcMap.get("B")),
756                     fillWithZero(abcMap.get("C")), fillWithZero(totalAbcMap.get("C")));
195945 757             log.info(ywhb +  "投屏准备完成,开始准备语音。");
4c64dc 758             // 开始准备语音
A 759             int total = 0;
195945 760             if(currA && abcMap.get("A") == totalAbcMap.get("A") && totalAbcMap.get("A")>0) { // 当前车在A区装车完成
4c64dc 761                 total = totalAbcMap.get("A");
A 762             }
195945 763             if(currB && abcMap.get("B") == totalAbcMap.get("B") && totalAbcMap.get("B")>0) {// 当前车在B区装车完成
4c64dc 764                 total = totalAbcMap.get("B");
A 765             }
195945 766             if(currC && abcMap.get("C") == totalAbcMap.get("C") && totalAbcMap.get("C")>0) {// 当前车在C区装车完成
4c64dc 767                 total = totalAbcMap.get("C");
A 768             }
195945 769             try {
A 770                 String speakTxt = startToSpeak(cph,total,abcMap,totalAbcMap);
771                 if(StringUtils.isNotBlank(speakTxt)) {
772                     log.info("SpeakTxt:"+ speakTxt);
773                     speakParam.put("SpeakTxt", speakTxt);
4c64dc 774                 }
195945 775             }catch (Exception e){
A 776                 log.error("准备语音出错!" + e.getMessage(),e);
4c64dc 777             }
195945 778
A 779             // 准备语音结束
cc0cbf 780             // 单辆车的单个业务单的信息结束
A 781         }
63fbfd 782         if(StringUtils.isBlank(str2)) {
A 783             str2 = "无车辆";
784         }
cc0cbf 785         Map paramMap = new HashMap();
4c64dc 786         paramMap.put("strTitle",str1);
A 787         paramMap.put("strContent",str2);
788         try {
63fbfd 789             log.info("LED-ABC webServiceAddrss:"+Contants.msLedServiceAddr+"st1::" +str1+";;;;;str2::"+str2);
A 790             String re = Wxhtmethod.post(Contants.msLedServiceAddr + "/SendLED",paramMap);
791             log.info("LED-ABC result:"+re);
792             // 语音只播一条
793             String re1 = Wxhtmethod.post(Contants.msLedServiceAddr + "/Speak",speakParam);
4c64dc 794         }catch (Exception e){}
A 795
796
797     }
63fbfd 798
195945 799     /**
A 800      * 准备语音
801      * @param cph 车牌号
802      * @param total 当前区总数
803      * @param abcMap A、B、C为key的区已装数目
804      * @param totalAbcMap A、B、C为key的区总数
805      * @return
806      */
807     String startToSpeak(String cph, int total,Map<String,Integer> abcMap,Map<String,Integer> totalAbcMap) {
808         String speakTxt=null ;
809         if(total > 0) { // 播放语音,请离开区域
810             String speakTxtFormatStr1 = "车号%s ,装货%d件已完成,请司机清点货物后尽快驶离装货区。";
811             // 只有2个区
812             String speakTxtFormatStr2 = "车号%s,%s区装货%d件已全部扫描完成,请司机清点货物后去%s区装货。";
813             // 只有3个区
814             String speakTxtFormatStr3 = "车号%s,%s区装货%d件已全部扫描完成,请司机清点货物后去%s区%s区装货。";
815
816             if( (abcMap.get("A")>0  && totalAbcMap.get("B")==0 && totalAbcMap.get("C")==0) ||
817                     (abcMap.get("B")>0  && totalAbcMap.get("A")==0 && totalAbcMap.get("C")==0)  ||
818                     (abcMap.get("C")>0  && totalAbcMap.get("B")==0 && totalAbcMap.get("D")==0)
819             ) { // 只有一个区域有货物
820                 speakTxt= String.format(speakTxtFormatStr1, cph, total);
821             }else  if(totalAbcMap.get("A")>0 && totalAbcMap.get("B")>0 &&
822                     (totalAbcMap.get("C")==0 || totalAbcMap.get("C") == abcMap.get("C"))){ // AB都有货 C区已完或无货
823                 if(totalAbcMap.get("C")>0 && abcMap.get("A")< totalAbcMap.get("A") && abcMap.get("B")< totalAbcMap.get("B")) { // C装完AB未装完
824                     speakTxt= String.format(speakTxtFormatStr3, cph,"C", total,"A","B");
825                 } else if(abcMap.get("A")== totalAbcMap.get("A") && abcMap.get("B")< totalAbcMap.get("B")) { //A完B未完
826                     speakTxt = String.format(speakTxtFormatStr2, cph, "A", total, "B");
827                 }else if(abcMap.get("B")== totalAbcMap.get("B") && abcMap.get("A")< totalAbcMap.get("A")) {//B完A未完
828                     speakTxt = String.format(speakTxtFormatStr2, cph, "B", total, "A");
829                 }else { // 全部装完
830                     speakTxt= String.format(speakTxtFormatStr1, cph, total);
831                 }
832             }else if(totalAbcMap.get("C")>0 && totalAbcMap.get("B")>0 &&
833                     (totalAbcMap.get("A")==0 || totalAbcMap.get("A") == abcMap.get("A")) ){ //BC有货 A区已完或无货
834                 if(totalAbcMap.get("A")>0 && abcMap.get("C")< totalAbcMap.get("C") && abcMap.get("B")< totalAbcMap.get("B")) {  // A装完BC未装完
835                     speakTxt= String.format(speakTxtFormatStr3, cph,"A", total,"B","C");
836                 } else if(abcMap.get("C")== totalAbcMap.get("C") && abcMap.get("B")< totalAbcMap.get("B")) { // C完B未装完
837                     speakTxt = String.format(speakTxtFormatStr2, cph, "C", total, "B");
838                 }else if(abcMap.get("B")== totalAbcMap.get("B") && abcMap.get("C")< totalAbcMap.get("C")) {// B完C未装完
839                     speakTxt = String.format(speakTxtFormatStr2, cph, "B", total, "C");
840                 }else { // 全部装完
841                     speakTxt= String.format(speakTxtFormatStr1, cph, total);
842                 }
843             }else  if (totalAbcMap.get("A")>0 && totalAbcMap.get("C")>0 &&
844                     (totalAbcMap.get("B")==0 || totalAbcMap.get("B") == abcMap.get("B")) ) { //AC有货
845                 if(totalAbcMap.get("B")>0 && abcMap.get("A")< totalAbcMap.get("A") && abcMap.get("C")< totalAbcMap.get("C")) {
846                     speakTxt= String.format(speakTxtFormatStr3, cph,"B", total,"A","C");
847                 } else if(abcMap.get("A")== totalAbcMap.get("A") && abcMap.get("C")< totalAbcMap.get("C")) { // A装完C未装完
848                     speakTxt = String.format(speakTxtFormatStr2, cph, "A", total, "C");
849                 }else if(abcMap.get("C")== totalAbcMap.get("C") && abcMap.get("A")< totalAbcMap.get("A")) {// C装完A未装完
850                     speakTxt = String.format(speakTxtFormatStr2, cph, "C", total, "A");
851                 }else { // 全部装完
852                     speakTxt= String.format(speakTxtFormatStr1, cph, total);
853                 }
854             }else if(totalAbcMap.get("A")>0 && totalAbcMap.get("B")>0 && totalAbcMap.get("C")>0) { // 3区都有货物,且只有一个取装完了
855                 if(abcMap.get("A")>0 && abcMap.get("B")<totalAbcMap.get("B") && abcMap.get("C")<totalAbcMap.get("C")) {
856                     speakTxt= String.format(speakTxtFormatStr3, cph,"A", total,"B","C");
857                 } else if(abcMap.get("B")>0 && abcMap.get("C")==0 && abcMap.get("A")==0) {
858                     speakTxt= String.format(speakTxtFormatStr3, cph,"B", total,"A","C");
859                 } else if(abcMap.get("C")>0 && abcMap.get("A")==0 && abcMap.get("B")==0) {
860                     speakTxt= String.format(speakTxtFormatStr3, cph,"C", total,"A","B");
861                 } else { // 全部装完
862                     speakTxt= String.format(speakTxtFormatStr1, cph, total);
863                 }
864             } else {
865                 speakTxt= String.format(speakTxtFormatStr1, cph, total);
866             }
867         }
868         return speakTxt;
869     }
870
63fbfd 871     @Override
A 872     public void sendToYrLed(String currPch) {
873             // 状态 一磅后,待装;PDA扫码 在装; 二次过磅后消失
874             // 装车区 两个汉字加两个英文或数字
eeb08a 875             String strTitle="序号  车号   装车区  状态\r\n";
63fbfd 876             String strContent = "";
A 877             String contentFormatStr = "%s   %s  %s   %s\r\n";
878             List<Map> list = tdmxper.yRZcList("08");
879             int index = 1;
880             for (Map map : list) {
881                 String numberplates = (String) map.get("numberplates"); // 车牌号
882                 String zcWz = (String) map.get("zcWz"); // 装车位置
883                 if(StringUtils.isNotBlank(zcWz)){
884                     zcWz = zcWz.substring(0,4);
eeb08a 885                 } else { // 空是6个位置
A 886                     zcWz = "      ";
63fbfd 887                 }
A 888                 String zcStatus = (String) map.get("zcStatus"); // 装车位置 在办/待办
889                 strContent += String.format(contentFormatStr, fillWithZero(index++), numberplates, zcWz, zcStatus);
890             }
891             Map paramMap = new HashMap();
892             paramMap.put("strTitle",strTitle);
893             paramMap.put("strContent",strContent);
894             Wxhtmethod.post(Contants.yr_zcLedUrl + "/SendLED",paramMap);
895             log.info("yr_zcLedUrl: " + Contants.yr_zcLedUrl + ";title:" + strTitle + ",content:" + strContent);
896     }
897
898     String fillWithZero(int str){
4c64dc 899         String s;
A 900         if(str<10 && str>=0) s= "0" + str;
901         else s=String.valueOf(str);
902         return s;
cc0cbf 903     }
A 904
58d006 905     @Override
A 906     @Transactional(rollbackFor=Exception.class)
907     public ObjectResult<Boolean> delZCMX(String cardID, String yktywdh,JsonArray dataArr) throws Exception {
908         ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
909         //根据卡号判断分单信息
910         //循环批次号 如果没有分单 修改为分单和装车
911         Fd_Bsheet fdb=this.fbper.getbybsNo(StringUtils.isNotBlank(yktywdh)?yktywdh:"");
912         String vehicleId="";
913         if(fdb==null){
914             orr.setCode(1);
915             orr.setErrmsg("一卡通业务单未找到,请确认单号是否正确!");
916             return orr;
917         }else{
918             if(fdb.getStatus()!=Serviceenum.在办){
919                 orr.setCode(1);
920                 orr.setErrmsg("一卡通业务单不是在办状态,系统不做处理!");
921                 return orr;
922             }
923             if(StringUtils.isBlank(cardID)){
924                 orr.setCode(1);
925                 orr.setErrmsg("参数:一卡通卡号为空!");
926                 return orr;
927             }
928             if(dataArr==null){
929                 orr.setCode(1);
930                 orr.setErrmsg("参数:批次号为空!");
931                 return orr;
932             }
933
934             Map<String, Object> mp=this.yktper.getcardinuse(cardID);
935             if(mp==null){
936                 throw new Exception("卡号不正确未找到在用卡!");
937             }
938             vehicleId=mp.get("numberplates")==null?"":mp.get("numberplates").toString();
939             if(!vehicleId.equals(fdb.getVehicleId())){
940                 orr.setCode(1);
941                 orr.setErrmsg("参数:卡号关联的车牌号和业务单关联的车牌号不一致");
942                 return orr;
943             }
944             yktywdh=fdb.getBsNo();
945         }
946         //检查是否装车完成
947         Map<String, Object> mmr=this.bsper.selectTaskTime(fdb.getBsNo());
948         try {
949             if(mmr!=null&&mmr.get("zcWc")!=null&&Boolean.valueOf(mmr.get("zcWc").toString())) {
950                 orr.setCode(1);
951                 orr.setErrmsg("联系成品库办公室取消装车完成!");
952                 return orr;
953             }
954         } catch (Exception e) {
955             // TODO: handle exception
956         }
957 //        Fd_Bsheet nr=this.fbper.getbyVehicleId(vehicleId, Serviceenum.在办);
958 //        if(nr==null){
959 //            orr.setCode(1);
960 //            orr.setErrmsg("卡号:"+cardID+" 未找到在办销售发货单!");
961 //            return orr;
962 //        }
963
964 //        Fd_Vehicle fdv=this.vhper.getByVehicleId(vehicleId);
965 //        if(fdv==null){
966 //            orr.setCode(1);
967 //            orr.setErrmsg("车牌号:"+cardID+" 未录入车辆信息!");
968 //            return orr;
969 //        }
970         //现场过完毛重后出现扫码装车的,必须重新过磅
971         int grossNum=this.bsper.getgrosstDoc(vehicleId, fdb.getBsNo());
972         if(grossNum>0) {
973             Map<String, Object> xstm=new HashMap<String, Object>();
974             xstm.put("canCm",false);
975             xstm.put("businessNo",fdb.getBsNo());
976             this.bsper.updateCanCm(xstm);
977             this.bsper.updatecanFb(vehicleId, fdb.getBsNo());
978         }
979         for (JsonElement je : dataArr) {
980             JsonObject jo=je.getAsJsonObject();
981             String tdmx_pch=jo.get("tdmx_pch").getAsString();
982 //            Fd_XSTDMX tdmx=this.tdmxper.getbyPCH(tdmx_pch);
983             Fd_XSTDMX tdmx=this.tdmxper.getbyPCHONE(tdmx_pch,vehicleId);
23f938 984             if(tdmx == null) {
A 985                 String errMsg = "一卡通卸车失败,请查看【" + tdmx_pch +"】出库关闭标志!";
986                 throw  new Exception(errMsg);
987             }
58d006 988 //            if(tdmx.getTdmx_zcbz()!=1){
A 989 ////                throw new Exception("批次号:"+tdmx_pch+" 已经提交装车,不能重复提交装车!");
990 //                continue;
991 //            }
992 //            Fd_XSTD xstd=this.tdper.get(tdmx.getTdmx_tdls());
993 //            if(xstd==null){
994 //                continue;
995 //            }
996             //修改Fd_Bsheetitem表  这张表去掉了
997             this.fbper.delbsitem(tdmx.getTdmx_pch(), yktywdh);
998 //            //修改一卡通明细表bsitem
999 //            if(tdmx.getTdmx_zcbz()==0){
1000 //                continue;
1001 //            }
1002             tdmx.setTdmx_zcbz(0);
1003             tdmx.setTdmx_zccph(null);
1004             tdmx.setTdmx_zcdriver(null);
1005             tdmx.setTdmx_zcphone(null);
1006             tdmx.setTdmx_zcwlgsName(null);
1007             this.tdmxper.updateZCnoFD(tdmx);
1008         }
1009
1010         orr.setCode(0);
1011         orr.setErrmsg("取消装车操作成功!");
1012         return orr;
1013     }
1014
1015     @Override
1016     public ObjectResult<Map<String, Object>> getcInfo(String cardID) {
1017         ObjectResult<Map<String, Object>> orr=new ObjectResult<Map<String,Object>>();
1018         Map<String, Object> rem=new HashMap<String, Object>();
1019         Map<String, Object> mp=this.yktper.getcardinuse(cardID);
1020         if(mp==null){
1021             orr.setCode(1);
1022             orr.setErrmsg("卡号不正确未找到在用卡!");
1023             return orr;
1024         }
1025         String vehicleId=mp.get("numberplates")==null?"":mp.get("numberplates").toString();
5aa407 1026
A 1027         String type = (String)mp.get("type");
1028         String sdepartNo = null;
1029         if(type.equals("外来车辆卡")) {
1030             sdepartNo = (String) mp.get("sdepartNo");
1031         }
1032
58d006 1033         List<Fd_Bsheet> fd_bList = this.fbper.getListbyVehicleId(vehicleId, Serviceenum.在办);
A 1034         if (fd_bList == null||fd_bList.isEmpty()) {
1035             orr.setCode(1);
1036             orr.setErrmsg("车辆未找到在办分单!");
1037             return orr;
1038         }
1039         Fd_Bsheet fd_b=null;
1040         if(fd_bList.size()>1) {
1041             for (Fd_Bsheet fd_Bsheet : fd_bList) {
1042                 int wd=this.bsper.getweightDoc(vehicleId, fd_Bsheet.getBsNo());
1043                 if(wd>0) {
1044                     fd_b=fd_Bsheet;
1045                     break;
1046                 }
1047             }
1048             if(fd_b==null) {
1049                 orr.setCode(1);
1050                 orr.setErrmsg("车辆:"+vehicleId+" 当前业务未找到绑定的过磅单,请先过磅或者重绑磅单!");
1051                 return orr;
1052             }
1053         }else {
1054             fd_b=fd_bList.get(0);
1055             int wcnum=this.bsper.getweightDoc(vehicleId, fd_b.getBsNo());
1056             if(wcnum<=0){
1057                 orr.setCode(1);
1058                 orr.setErrmsg("车辆:"+vehicleId+" 当前业务未找到绑定的过磅单,请先过磅或者重绑磅单!");
1059                 return orr;
1060             }
1061         }
5aa407 1062         // 改成使用在用卡的卡号、车牌号码、厂区来确认是否有销售的业务单 btid=3 businesstype00002
A 1063         String businessNo = bsper.getBusinessNoByCardNo(cardID,vehicleId,sdepartNo);
58d006 1064         if(StringUtils.isBlank(businessNo)) {
A 1065             orr.setCode(1);
1066             orr.setErrmsg("未找到该卡的在办业务单!");
1067             return orr;
1068         }
1069 //        List<Vehicle_XSTD> vxl=this.vhxper.getlistbyVehicleId(vehicleId);
1070         List<Vehicle_XSTD> vxl= this.vhxper.getlistbyVehicleIdandbsNoGp(vehicleId, businessNo);
1071         List<Map<String, Object>> datamp=new ArrayList<Map<String, Object>>();
5aa407 1072         Map<String,Fd_XSTD> xstdMap = new HashMap(); // 缓存Fd_XSTD,避免多查
58d006 1073         for (Vehicle_XSTD vx : vxl) {
A 1074             String tdbh=vx.getXstdNo();
1075             Fd_XSTD td=this.tdper.getbyTDBH(tdbh);
1076             String wlgsbh=vx.getCompanyNo();
1077             Fd_Company fd_c=this.cmper.getByCompanyNo(wlgsbh);
1078             Map<String, Object> tdm=new HashMap<String, Object>();
1079             if(fd_c!=null){
1080                 tdm.put("td_wlgs", fd_c.getName());//物流公司
1081             }else{
1082                 tdm.put("td_wlgs", "");//物流公司
1083             }
1084             if(td==null){
1085                 continue;
1086             }
1087             // List<Fd_XSTDMX> tdmxl=this.tdmxper.getbytdls(td.getTd_tdls());
1088             List<Fd_XSTDMX> tdmxl= tdmxper.getListByTdlsAndCph(td.getTd_tdls(),vehicleId);
1089             if(tdmxl==null||tdmxl.size()<=0){
1090                 continue;
1091             }
1092             Map<String, Object> mm=new HashMap<String, Object>();
1093             tdm.put("td_tdbh", td.getTd_tdbh());
1094             tdm.put("td_tdls", td.getTd_tdls());
1095             tdm.put("td_jylx", td.getTd_jylx());
5aa407 1096             Fd_XSTD fd_xstd = xstdMap.get(td.getTd_tdbh());
A 1097             if(xstdMap.get(td.getTd_tdbh())==null) { // 保证同一个提单只查一遍
1098                 fd_xstd = tdper.getbyttdbh(td.getTd_tdbh());
1099             }
1100             //增加客户名称 备注
1101             if(StringUtils.isBlank(fd_xstd.getTd_fpbh())){
1102                 Nckh nckh = zsjper.getNckhbyCode(fd_xstd.getTd_khbh());// 客户不存在的特殊情况是不应该存在的,以防万一,加判空。
1103                 tdm.put("td_khmc",nckh!=null?nckh.getName():"");
1104             }else {
1105                 String name = ConvertTool.covertToCustoms(fd_xstd.getTd_ywdybh());
1106                 tdm.put("td_khmc", name);
1107             }
1108             tdm.put("td_bz",fd_xstd.getTd_bz());
58d006 1109             mm.put("td", tdm);
A 1110             mm.put("tdmx", tdmxl);
1111             datamp.add(mm);
1112         }
5aa407 1113
A 1114
58d006 1115         rem.put("cph", vehicleId);
A 1116         rem.put("sjmc", fd_b.getDriver());
1117         rem.put("dh", fd_b.getPhone());
1118 //        rem.put("sjmc", fdv.getDriver());
1119 //        rem.put("dh", fdv.getPhone());
1120         rem.put("ywdh", fd_b.getBsNo());
1121         rem.put("respcode", 111);
1122         rem.put("data", datamp);
1123
1124         //修改装车记录
1125         Map<String, Object> mr=this.bsper.selectTaskTime(fd_b.getBsNo());
1126         if(mr!=null) {
1127             if(mr.get("firstzxhtime")!=null) {
1128                 mr.put("lastzxhtime", new Date());
1129             }else {
1130                 mr.put("firstzxhtime", new Date());
1131             }
1132             this.bsper.updateTaskTime(mr);
1133         }else {
1134             orr.setCode(1);
1135             orr.setErrmsg("未找到装车记录");
1136             return orr;
1137         }
1138
1139         orr.setCode(0);
1140         orr.setItem(rem);
1141         return orr;
1142     }
1143
1144     @Override
1145     public ObjectResult<Map<String, Object>> getxstdInfo(String xstdNo) {
1146         ObjectResult<Map<String, Object>> orr=new ObjectResult<Map<String,Object>>();
1147         Fd_XSTD xstd=this.tdper.getbyTDBH(xstdNo);
1148         if(xstd==null){
1149             orr.setCode(1);
1150             orr.setErrmsg("提单未找到!");
1151             return orr;
1152         }
1153         Map<String, Object> rm=new HashMap<String, Object>();
1154         List<Fd_XSTDMX> tdmxlist=this.tdmxper.getListbytdls(xstd.getTd_tdls());
1155         rm.put("code", 0);
1156         rm.put("item", xstd);
1157         rm.put("itemList", tdmxlist);
1158         orr.setCode(0);
1159         orr.setItem(rm);
1160         return orr;
1161     }
1162
1163     @Override
1164     @Transactional(rollbackFor=Exception.class)
1165     public ObjectResult<Boolean> savewdControl(JsonArray dataArr)throws Exception {
1166         ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
1167         if(dataArr==null){
1168             orr.setCode(0);
1169             orr.setErrmsg("添加过磅控制成功!");
1170             return orr;
1171         }
1172         for (JsonElement je : dataArr) {
1173             JsonObject jo=je.getAsJsonObject();
1174             String bsNo=jo.get("yktywdh").getAsString();
1175             BsheetEcgb be=this.beper.getbyNo(bsNo);
1176             if(be==null){
1177                 be=new BsheetEcgb();
1178                 be.setBsNo(bsNo);
1179                 be.setCtime(new Date());
1180                 be.setCname("生产系统添加");
1181                 be.setSate(1);
1182                 this.beper.insert(be);
1183             }
1184         }
1185         orr.setCode(0);
1186         orr.setErrmsg("添加过磅控制成功!");
1187         return orr;
1188     }
1189
1190
1191
1192
1193 }