hjg
2024-07-05 a0879b60391616bb077b53815114af74ec7a77cd
提交 | 用户 | 时间
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;
bb48ed 70     public static Boolean refreshKjLedLock = false;
58d006 71     @Override
A 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         }
441
4c64dc 442         String currPch="";// 当前批次号
301115 443         List<String> pchList = new ArrayList<>();
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();
301115 585             pchList.add(tdmx.getTdmx_pch());
58d006 586         }
A 587
588         if(grossNum>0) {
589             Map<String, Object> xstm=new HashMap<String, Object>();
590             xstm.put("canCm",false);
591             xstm.put("businessNo",fdb.getBsNo());
592             this.bsper.updateCanCm(xstm);
593             this.bsper.updatecanFb(vehicleId, fdb.getBsNo());
594         }
595
596         //如果是郑州的销售业务单删除排队信息
597         if(iszz){
598             int ca=this.bsper.getvehicleQ(vehicleId);
599             if(ca>0){
600 //                this.bsper.delvehicleQ(vehicleId);
601                 //删除车辆排队信息
602                 String url=Contants.yktLocalAdd+"/search/vehicleQueue/delItem.htm";
cc0cbf 603                 Map<String, String> paramMp=new HashMap<String, String>();
58d006 604                 mp.put("vehicleID", vehicleId);
cc0cbf 605                 Wxhtmethod.postJson(url, paramMp);
58d006 606             }
A 607         }
608
cc0cbf 609          // 此处异步触发一下明晟发车
A 610         if("06".equals(fdb.getSdepartNo())) {
301115 611             final String pch = currPch;
195945 612             final String finalVehicleId = vehicleId;
301115 613             ThreadPoolUtil.getInstance().execute(()->{
H 614                 Map paramMap = new HashMap();
615                 paramMap.put("vehicleId", finalVehicleId);
616                 paramMap.put("tdmxPchList", tdmxPchList);
617                 String jsonStr = Jacksonmethod.tojson(paramMap, false);
618                 JsonObject jsonObject = Wxhtmethod.postJsonStr(Contants.ms_DoScanUrl, jsonStr);
619                 if (jsonObject.get("code").getAsInt() != 0) {
620                     prr.setCode(1);
621                     prr.setErrmsg(jsonObject.get("errmsg").getAsString());
622                     // return prr;
623                 }
624             });
625             // 延迟1.5秒执行,保证数据执行完了
63fbfd 626             ThreadPoolUtil.getInstance().execute(()->{
195945 627                 synchronized (FdXSTDService.refreshMsLedLock) {
A 628                     if (FdXSTDService.refreshMsLedLock) { // 系统繁忙
301115 629                         log.info(finalVehicleId + "" + pch + "系统繁忙!");
195945 630                         return;
A 631                     }
632                 }
63fbfd 633                 try {
A 634                     synchronized (FdXSTDService.refreshMsLedLock) {
635                         FdXSTDService.refreshMsLedLock = true;
636                     }
301115 637                     sendToMsLed(pch);
63fbfd 638                 } catch (Exception e) {
195945 639                     log.error("出现异常:"+ e.getMessage(),e);
63fbfd 640                 } finally {
A 641                     synchronized (FdXSTDService.refreshMsLedLock) {
642                         FdXSTDService.refreshMsLedLock = false;
643                     }
644                 }
301115 645             },1500);
63fbfd 646         }
A 647         if("08".equals(fdb.getSdepartNo())) {
648             final String cph = currPch;
649             ThreadPoolUtil.getInstance().execute(()->{
975c04 650                 // 这个地方不再请求
H 651                 /*Map scanCodeParamMap = new HashMap();
a966b5 652                 scanCodeParamMap.put("pch",cph);
975c04 653                 Wxhtmethod.post(Contants.yr_scanCodeNoticeUrl, scanCodeParamMap);*/
63fbfd 654                 try {
A 655                     synchronized (FdXSTDService.refreshYrLedLock) {
656                         if (FdXSTDService.refreshYrLedLock) { // 系统繁忙
657                             return  ;
658                         }
659                         FdXSTDService.refreshYrLedLock = true;
660                     }
661                     sendToYrLed(cph);
662                 } catch (Exception e) {
663                     log.error(e);
664                 } finally {
665                     synchronized (FdXSTDService.refreshYrLedLock) {
666                         FdXSTDService.refreshYrLedLock = false;
bb48ed 667                     }
H 668                 }
669             });
670         } else if("04".equals(fdb.getSdepartNo())) { // 科技
671             final String cph = currPch;
672             ThreadPoolUtil.getInstance().execute(()->{
673                 try {
674                     synchronized (FdXSTDService.refreshKjLedLock) {
675                         if (FdXSTDService.refreshKjLedLock) { // 系统繁忙
676                             return  ;
677                         }
678                         FdXSTDService.refreshKjLedLock = true;
679                     }
680                     sendToKjLed(cph);
681                 } catch (Exception e) {
682                     log.error(e);
683                 } finally {
684                     synchronized (FdXSTDService.refreshKjLedLock) {
685                         FdXSTDService.refreshKjLedLock = false;
63fbfd 686                     }
A 687                 }
688             });
cc0cbf 689         }
58d006 690         prr.setCode(0);
A 691         prr.setErrmsg("装车操作成功!");
692         prr.setList(relist);
693         return prr;
694     }
695
4c64dc 696     /**
301115 697      *  挪到一卡通
4c64dc 698      * @param currPch 当前批次号
A 699      */
700     public void sendToMsLed(String currPch){
cc0cbf 701         //A区  76-86 +  99-1
A 702         //B区  14-33 +  99-2
703         //C区  53-67 +  99-3
301115 704         // 2024年改
H 705         //A区  73-88 +  99-1 +  40-45
706         //B区  14-27 +  99-2 +  46-49
707         //C区  50-65 +  99-3
708         //D区  28-39 +    69-72    + 89-98
63fbfd 709         log.info("LED-ABC当前扫码批次号:" + currPch);
cc0cbf 710         List<Map> totalList =  tdmxper.getHwList("06"); // 获取明晟所有在办业务单的信息
63fbfd 711         log.info("LED-ABC获取信息条数:" + totalList.size());
cc0cbf 712         Map<String,List<Map>> ywbhListMap = new HashMap<>();
A 713         for (Map map : totalList) {
714             String ywdw = (String) map.get("tdmx_fdywbh");
195945 715             if(ywdw == null) {
A 716                 log.info("出现业务单号为null的情况:" + Jacksonmethod.tojson(map,false));
717                 continue;
718             }
cc0cbf 719             if(ywbhListMap.get(ywdw) == null) {
A 720                 ywbhListMap.put(ywdw, new ArrayList<>());
721             }
722             ywbhListMap.get(ywdw).add(map);
723         }
4c64dc 724         String str1 = " 车号  A区  B区  C区" + "\r\n", str2="";
cc0cbf 725         //"(车牌号)\\-(A区已装车)/(A区总计)\\-(B区已装车)/(B区总计)\\-(C区已装车)/(C区总计)\\r\\n";
4c64dc 726         String formatStr = "%s %s/%s %s/%s %s/%s\r\n";
A 727         // 只有1个区
195945 728
4c64dc 729         Map speakParam = new HashMap(1);
63fbfd 730         for (Map.Entry<String, List<Map>> entry : ywbhListMap.entrySet()) {
A 731             // 遍历每个业务单的
301115 732             // 当前装车A、B、C区; D区只参与记录,不参与LED显示和语言播报
H 733             boolean currA = false,currB = false, currC = false, currD = false;
cc0cbf 734             boolean hasZcwc = false; // 保证已经完成了
195945 735             String ywhb = entry.getKey();
cc0cbf 736             List<Map> vehicleIdTotalList = entry.getValue();
301115 737             // 总计信息
H 738             Map<String, Integer> totalAbcMap = new HashMap(3);
cc0cbf 739             totalAbcMap.put("A", 0);
A 740             totalAbcMap.put("B", 0);
741             totalAbcMap.put("C", 0);
301115 742             /* 已装信息 */
H 743             Map<String, Integer> abcMap = new HashMap(3);
cc0cbf 744             abcMap.put("A", 0);
A 745             abcMap.put("B", 0);
746             abcMap.put("C", 0);
747             String cph = ""; // 车牌号
748             for (Map map : vehicleIdTotalList) {
749                 String hw = (String) map.get("tdmx_hwmc");
4c64dc 750                 String pch = (String) map.get("tdmx_pch");
195945 751                 if(StringUtils.isBlank(cph))  cph = (String) map.get("tdmx_fdcph");
cc0cbf 752                 Integer zcbz = (Integer) map.get("tdmx_zcbz");
A 753                 String hh = hw.replaceAll("\\-.*","");
754                 hh = hh.substring(hh.length()-2); // 取最后两位
755                 int num = Integer.parseInt(hh);
301115 756                 if (num >= 73 && num <= 88 || hw.lastIndexOf("99-1") >= 0) { // A区
4c64dc 757                     totalAbcMap.put("A",totalAbcMap.get("A") + 1);
cc0cbf 758                     if (zcbz != null && zcbz == 1) { // 装车完成
A 759                         abcMap.put("A", abcMap.get("A") + 1);
760                         hasZcwc = true;
761                     }
4c64dc 762                     if(pch.equals(currPch)) {
301115 763                         currA = true; currB = false;currC =false;currD=false;
4c64dc 764                     }
301115 765                 } else if (num >= 14 && num <= 27 || hw.lastIndexOf("99-2") >= 0) { // B区
4c64dc 766                     totalAbcMap.put("B", totalAbcMap.get("B") + 1);
cc0cbf 767                     if (zcbz != null && zcbz == 1) {
A 768                         abcMap.put("B", abcMap.get("B") + 1);
769                         hasZcwc = true;
770                     }
4c64dc 771                     if(pch.equals(currPch)) {
301115 772                         currA = false; currB = true;currC =false;currD=false;
4c64dc 773                     }
301115 774                 } else if (num >= 50 && num <= 65 || hw.lastIndexOf("99-3") >= 0) { // C区
4c64dc 775                     totalAbcMap.put("C", totalAbcMap.get("C") + 1);
cc0cbf 776                     if (zcbz != null && zcbz == 1) {
A 777                         abcMap.put("C", abcMap.get("C") + 1);
778                         hasZcwc = true;
779                     }
4c64dc 780                     if(pch.equals(currPch)) {
301115 781                         currA = false; currB = false; currC =true; currD=false;
H 782                     }
783                 } else if(num>=28 && num<=39 ||    (num>=69 && num<=72) || (num>=89 && num<=98)) {
784                     if(pch.equals(currPch)) {
785                         currA = false; currB = false;currC =false;currD=true;
4c64dc 786                     }
cc0cbf 787                 }
A 788             }
63fbfd 789             // if (!hasZcwc) continue; //没有装车完成的也跳过
A 790             /*if (!(currA || currB || currC) && abcMap.get("A") + abcMap.get("B") + abcMap.get("C") ==
4c64dc 791                     totalAbcMap.get("A") + totalAbcMap.get("B") + totalAbcMap.get("C")) { // 非当前车牌号,已经装车完成但是未出厂
A 792                 continue;
63fbfd 793             }*/
195945 794             if(totalAbcMap.get("B")==0 && totalAbcMap.get("C")==0 && totalAbcMap.get("A")==0) {
A 795                 continue;
796             }
63fbfd 797             str2 += String.format(formatStr, cph, fillWithZero(abcMap.get("A")), fillWithZero(totalAbcMap.get("A")),
A 798                     fillWithZero(abcMap.get("B")), fillWithZero(totalAbcMap.get("B")),
799                     fillWithZero(abcMap.get("C")), fillWithZero(totalAbcMap.get("C")));
195945 800             log.info(ywhb +  "投屏准备完成,开始准备语音。");
4c64dc 801             // 开始准备语音
A 802             int total = 0;
195945 803             if(currA && abcMap.get("A") == totalAbcMap.get("A") && totalAbcMap.get("A")>0) { // 当前车在A区装车完成
4c64dc 804                 total = totalAbcMap.get("A");
A 805             }
195945 806             if(currB && abcMap.get("B") == totalAbcMap.get("B") && totalAbcMap.get("B")>0) {// 当前车在B区装车完成
4c64dc 807                 total = totalAbcMap.get("B");
A 808             }
195945 809             if(currC && abcMap.get("C") == totalAbcMap.get("C") && totalAbcMap.get("C")>0) {// 当前车在C区装车完成
4c64dc 810                 total = totalAbcMap.get("C");
A 811             }
195945 812             try {
A 813                 String speakTxt = startToSpeak(cph,total,abcMap,totalAbcMap);
814                 if(StringUtils.isNotBlank(speakTxt)) {
815                     log.info("SpeakTxt:"+ speakTxt);
816                     speakParam.put("SpeakTxt", speakTxt);
4c64dc 817                 }
195945 818             }catch (Exception e){
A 819                 log.error("准备语音出错!" + e.getMessage(),e);
4c64dc 820             }
195945 821
A 822             // 准备语音结束
cc0cbf 823             // 单辆车的单个业务单的信息结束
A 824         }
63fbfd 825         if(StringUtils.isBlank(str2)) {
A 826             str2 = "无车辆";
827         }
cc0cbf 828         Map paramMap = new HashMap();
4c64dc 829         paramMap.put("strTitle",str1);
A 830         paramMap.put("strContent",str2);
831         try {
63fbfd 832             log.info("LED-ABC webServiceAddrss:"+Contants.msLedServiceAddr+"st1::" +str1+";;;;;str2::"+str2);
A 833             String re = Wxhtmethod.post(Contants.msLedServiceAddr + "/SendLED",paramMap);
834             log.info("LED-ABC result:"+re);
835             // 语音只播一条
836             String re1 = Wxhtmethod.post(Contants.msLedServiceAddr + "/Speak",speakParam);
4c64dc 837         }catch (Exception e){}
A 838
839
840     }
63fbfd 841
195945 842     /**
301115 843      * 准备语音 ,挪到一卡通
195945 844      * @param cph 车牌号
A 845      * @param total 当前区总数
846      * @param abcMap A、B、C为key的区已装数目
847      * @param totalAbcMap A、B、C为key的区总数
848      * @return
849      */
850     String startToSpeak(String cph, int total,Map<String,Integer> abcMap,Map<String,Integer> totalAbcMap) {
851         String speakTxt=null ;
852         if(total > 0) { // 播放语音,请离开区域
853             String speakTxtFormatStr1 = "车号%s ,装货%d件已完成,请司机清点货物后尽快驶离装货区。";
854             // 只有2个区
855             String speakTxtFormatStr2 = "车号%s,%s区装货%d件已全部扫描完成,请司机清点货物后去%s区装货。";
856             // 只有3个区
857             String speakTxtFormatStr3 = "车号%s,%s区装货%d件已全部扫描完成,请司机清点货物后去%s区%s区装货。";
858
859             if( (abcMap.get("A")>0  && totalAbcMap.get("B")==0 && totalAbcMap.get("C")==0) ||
860                     (abcMap.get("B")>0  && totalAbcMap.get("A")==0 && totalAbcMap.get("C")==0)  ||
861                     (abcMap.get("C")>0  && totalAbcMap.get("B")==0 && totalAbcMap.get("D")==0)
862             ) { // 只有一个区域有货物
863                 speakTxt= String.format(speakTxtFormatStr1, cph, total);
864             }else  if(totalAbcMap.get("A")>0 && totalAbcMap.get("B")>0 &&
865                     (totalAbcMap.get("C")==0 || totalAbcMap.get("C") == abcMap.get("C"))){ // AB都有货 C区已完或无货
866                 if(totalAbcMap.get("C")>0 && abcMap.get("A")< totalAbcMap.get("A") && abcMap.get("B")< totalAbcMap.get("B")) { // C装完AB未装完
867                     speakTxt= String.format(speakTxtFormatStr3, cph,"C", total,"A","B");
868                 } else if(abcMap.get("A")== totalAbcMap.get("A") && abcMap.get("B")< totalAbcMap.get("B")) { //A完B未完
869                     speakTxt = String.format(speakTxtFormatStr2, cph, "A", total, "B");
870                 }else if(abcMap.get("B")== totalAbcMap.get("B") && abcMap.get("A")< totalAbcMap.get("A")) {//B完A未完
871                     speakTxt = String.format(speakTxtFormatStr2, cph, "B", total, "A");
872                 }else { // 全部装完
873                     speakTxt= String.format(speakTxtFormatStr1, cph, total);
874                 }
875             }else if(totalAbcMap.get("C")>0 && totalAbcMap.get("B")>0 &&
876                     (totalAbcMap.get("A")==0 || totalAbcMap.get("A") == abcMap.get("A")) ){ //BC有货 A区已完或无货
877                 if(totalAbcMap.get("A")>0 && abcMap.get("C")< totalAbcMap.get("C") && abcMap.get("B")< totalAbcMap.get("B")) {  // A装完BC未装完
878                     speakTxt= String.format(speakTxtFormatStr3, cph,"A", total,"B","C");
879                 } else if(abcMap.get("C")== totalAbcMap.get("C") && abcMap.get("B")< totalAbcMap.get("B")) { // C完B未装完
880                     speakTxt = String.format(speakTxtFormatStr2, cph, "C", total, "B");
881                 }else if(abcMap.get("B")== totalAbcMap.get("B") && abcMap.get("C")< totalAbcMap.get("C")) {// B完C未装完
882                     speakTxt = String.format(speakTxtFormatStr2, cph, "B", total, "C");
883                 }else { // 全部装完
884                     speakTxt= String.format(speakTxtFormatStr1, cph, total);
885                 }
886             }else  if (totalAbcMap.get("A")>0 && totalAbcMap.get("C")>0 &&
887                     (totalAbcMap.get("B")==0 || totalAbcMap.get("B") == abcMap.get("B")) ) { //AC有货
888                 if(totalAbcMap.get("B")>0 && abcMap.get("A")< totalAbcMap.get("A") && abcMap.get("C")< totalAbcMap.get("C")) {
889                     speakTxt= String.format(speakTxtFormatStr3, cph,"B", total,"A","C");
890                 } else if(abcMap.get("A")== totalAbcMap.get("A") && abcMap.get("C")< totalAbcMap.get("C")) { // A装完C未装完
891                     speakTxt = String.format(speakTxtFormatStr2, cph, "A", total, "C");
892                 }else if(abcMap.get("C")== totalAbcMap.get("C") && abcMap.get("A")< totalAbcMap.get("A")) {// C装完A未装完
893                     speakTxt = String.format(speakTxtFormatStr2, cph, "C", total, "A");
894                 }else { // 全部装完
895                     speakTxt= String.format(speakTxtFormatStr1, cph, total);
896                 }
897             }else if(totalAbcMap.get("A")>0 && totalAbcMap.get("B")>0 && totalAbcMap.get("C")>0) { // 3区都有货物,且只有一个取装完了
898                 if(abcMap.get("A")>0 && abcMap.get("B")<totalAbcMap.get("B") && abcMap.get("C")<totalAbcMap.get("C")) {
899                     speakTxt= String.format(speakTxtFormatStr3, cph,"A", total,"B","C");
900                 } else if(abcMap.get("B")>0 && abcMap.get("C")==0 && abcMap.get("A")==0) {
901                     speakTxt= String.format(speakTxtFormatStr3, cph,"B", total,"A","C");
902                 } else if(abcMap.get("C")>0 && abcMap.get("A")==0 && abcMap.get("B")==0) {
903                     speakTxt= String.format(speakTxtFormatStr3, cph,"C", total,"A","B");
904                 } else { // 全部装完
905                     speakTxt= String.format(speakTxtFormatStr1, cph, total);
906                 }
907             } else {
908                 speakTxt= String.format(speakTxtFormatStr1, cph, total);
909             }
910         }
911         return speakTxt;
912     }
913
63fbfd 914     @Override
A 915     public void sendToYrLed(String currPch) {
916             // 状态 一磅后,待装;PDA扫码 在装; 二次过磅后消失
917             // 装车区 两个汉字加两个英文或数字
eeb08a 918             String strTitle="序号  车号   装车区  状态\r\n";
63fbfd 919             String strContent = "";
A 920             String contentFormatStr = "%s   %s  %s   %s\r\n";
921             List<Map> list = tdmxper.yRZcList("08");
922             int index = 1;
923             for (Map map : list) {
924                 String numberplates = (String) map.get("numberplates"); // 车牌号
925                 String zcWz = (String) map.get("zcWz"); // 装车位置
926                 if(StringUtils.isNotBlank(zcWz)){
927                     zcWz = zcWz.substring(0,4);
eeb08a 928                 } else { // 空是6个位置
A 929                     zcWz = "      ";
63fbfd 930                 }
A 931                 String zcStatus = (String) map.get("zcStatus"); // 装车位置 在办/待办
932                 strContent += String.format(contentFormatStr, fillWithZero(index++), numberplates, zcWz, zcStatus);
933             }
934             Map paramMap = new HashMap();
935             paramMap.put("strTitle",strTitle);
936             paramMap.put("strContent",strContent);
937             Wxhtmethod.post(Contants.yr_zcLedUrl + "/SendLED",paramMap);
938             log.info("yr_zcLedUrl: " + Contants.yr_zcLedUrl + ";title:" + strTitle + ",content:" + strContent);
939     }
bb48ed 940     @Override
H 941     public void sendToKjLed(String currPch) {
942         // 状态 一磅后,待装;PDA扫码 在装; 二次过磅后消失
943         // 装车区 两个汉字加两个英文或数字
944         String strTitle="序号  车号   装车区  状态\r\n";
945         String strContent = "";
946         String contentFormatStr = "%s   %s  %s   %s\r\n";
947         List<Map> list = tdmxper.yRZcList("04");
948         int index = 1;
949         for (Map map : list) {
950             String numberplates = (String) map.get("numberplates"); // 车牌号
951             String zcWz = (String) map.get("zcWz"); // 装车位置
952             if(StringUtils.isNotBlank(zcWz)) {
953                 zcWz = zcWz.substring(0,4);
954             } else { // 空是6个位置
955                 zcWz = "      ";
956             }
957             String zcStatus = (String) map.get("zcStatus"); // 装车位置 在办/待办
958             strContent += String.format(contentFormatStr, fillWithZero(index++), numberplates, zcWz, zcStatus);
959         }
960         Map paramMap = new HashMap();
961         paramMap.put("strTitle",strTitle);
962         paramMap.put("strContent",strContent);
975c04 963         String re = Wxhtmethod.post(Contants.kj_zcLedUrl + "/SendLED",paramMap);
H 964         log.info("回复:" + re +";kj_zcLedUrl: " + Contants.kj_zcLedUrl + ";title:" + strTitle + ",content:" + strContent);
bb48ed 965     }
63fbfd 966
A 967     String fillWithZero(int str){
4c64dc 968         String s;
A 969         if(str<10 && str>=0) s= "0" + str;
970         else s=String.valueOf(str);
971         return s;
cc0cbf 972     }
A 973
58d006 974     @Override
A 975     @Transactional(rollbackFor=Exception.class)
976     public ObjectResult<Boolean> delZCMX(String cardID, String yktywdh,JsonArray dataArr) throws Exception {
977         ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
978         //根据卡号判断分单信息
979         //循环批次号 如果没有分单 修改为分单和装车
980         Fd_Bsheet fdb=this.fbper.getbybsNo(StringUtils.isNotBlank(yktywdh)?yktywdh:"");
981         String vehicleId="";
982         if(fdb==null){
983             orr.setCode(1);
984             orr.setErrmsg("一卡通业务单未找到,请确认单号是否正确!");
985             return orr;
986         }else{
987             if(fdb.getStatus()!=Serviceenum.在办){
988                 orr.setCode(1);
989                 orr.setErrmsg("一卡通业务单不是在办状态,系统不做处理!");
990                 return orr;
991             }
992             if(StringUtils.isBlank(cardID)){
993                 orr.setCode(1);
994                 orr.setErrmsg("参数:一卡通卡号为空!");
995                 return orr;
996             }
997             if(dataArr==null){
998                 orr.setCode(1);
999                 orr.setErrmsg("参数:批次号为空!");
1000                 return orr;
1001             }
1002
1003             Map<String, Object> mp=this.yktper.getcardinuse(cardID);
1004             if(mp==null){
1005                 throw new Exception("卡号不正确未找到在用卡!");
1006             }
1007             vehicleId=mp.get("numberplates")==null?"":mp.get("numberplates").toString();
1008             if(!vehicleId.equals(fdb.getVehicleId())){
1009                 orr.setCode(1);
1010                 orr.setErrmsg("参数:卡号关联的车牌号和业务单关联的车牌号不一致");
1011                 return orr;
1012             }
1013             yktywdh=fdb.getBsNo();
1014         }
1015         //检查是否装车完成
1016         Map<String, Object> mmr=this.bsper.selectTaskTime(fdb.getBsNo());
1017         try {
1018             if(mmr!=null&&mmr.get("zcWc")!=null&&Boolean.valueOf(mmr.get("zcWc").toString())) {
1019                 orr.setCode(1);
1020                 orr.setErrmsg("联系成品库办公室取消装车完成!");
1021                 return orr;
1022             }
1023         } catch (Exception e) {
1024         }
1025 //        Fd_Bsheet nr=this.fbper.getbyVehicleId(vehicleId, Serviceenum.在办);
1026 //        if(nr==null){
1027 //            orr.setCode(1);
1028 //            orr.setErrmsg("卡号:"+cardID+" 未找到在办销售发货单!");
1029 //            return orr;
1030 //        }
1031
1032 //        Fd_Vehicle fdv=this.vhper.getByVehicleId(vehicleId);
1033 //        if(fdv==null){
1034 //            orr.setCode(1);
1035 //            orr.setErrmsg("车牌号:"+cardID+" 未录入车辆信息!");
1036 //            return orr;
1037 //        }
1038         //现场过完毛重后出现扫码装车的,必须重新过磅
1039         int grossNum=this.bsper.getgrosstDoc(vehicleId, fdb.getBsNo());
1040         if(grossNum>0) {
1041             Map<String, Object> xstm=new HashMap<String, Object>();
1042             xstm.put("canCm",false);
1043             xstm.put("businessNo",fdb.getBsNo());
1044             this.bsper.updateCanCm(xstm);
1045             this.bsper.updatecanFb(vehicleId, fdb.getBsNo());
1046         }
1047         for (JsonElement je : dataArr) {
1048             JsonObject jo=je.getAsJsonObject();
1049             String tdmx_pch=jo.get("tdmx_pch").getAsString();
1050 //            Fd_XSTDMX tdmx=this.tdmxper.getbyPCH(tdmx_pch);
1051             Fd_XSTDMX tdmx=this.tdmxper.getbyPCHONE(tdmx_pch,vehicleId);
23f938 1052             if(tdmx == null) {
A 1053                 String errMsg = "一卡通卸车失败,请查看【" + tdmx_pch +"】出库关闭标志!";
1054                 throw  new Exception(errMsg);
1055             }
58d006 1056 //            if(tdmx.getTdmx_zcbz()!=1){
A 1057 ////                throw new Exception("批次号:"+tdmx_pch+" 已经提交装车,不能重复提交装车!");
1058 //                continue;
1059 //            }
1060 //            Fd_XSTD xstd=this.tdper.get(tdmx.getTdmx_tdls());
1061 //            if(xstd==null){
1062 //                continue;
1063 //            }
1064             //修改Fd_Bsheetitem表  这张表去掉了
1065             this.fbper.delbsitem(tdmx.getTdmx_pch(), yktywdh);
1066 //            //修改一卡通明细表bsitem
1067 //            if(tdmx.getTdmx_zcbz()==0){
1068 //                continue;
1069 //            }
1070             tdmx.setTdmx_zcbz(0);
1071             tdmx.setTdmx_zccph(null);
1072             tdmx.setTdmx_zcdriver(null);
1073             tdmx.setTdmx_zcphone(null);
1074             tdmx.setTdmx_zcwlgsName(null);
1075             this.tdmxper.updateZCnoFD(tdmx);
1076         }
1077
1078         orr.setCode(0);
1079         orr.setErrmsg("取消装车操作成功!");
1080         return orr;
1081     }
1082
1083     @Override
a0879b 1084     public ObjectResult<Map<String, Object>> getcInfo(String cardID,boolean needRecord) {
58d006 1085         ObjectResult<Map<String, Object>> orr=new ObjectResult<Map<String,Object>>();
A 1086         Map<String, Object> rem=new HashMap<String, Object>();
1087         Map<String, Object> mp=this.yktper.getcardinuse(cardID);
1088         if(mp==null){
1089             orr.setCode(1);
1090             orr.setErrmsg("卡号不正确未找到在用卡!");
1091             return orr;
1092         }
1093         String vehicleId=mp.get("numberplates")==null?"":mp.get("numberplates").toString();
5aa407 1094
A 1095         String type = (String)mp.get("type");
1096         String sdepartNo = null;
1097         if(type.equals("外来车辆卡")) {
1098             sdepartNo = (String) mp.get("sdepartNo");
1099         }
1100
58d006 1101         List<Fd_Bsheet> fd_bList = this.fbper.getListbyVehicleId(vehicleId, Serviceenum.在办);
A 1102         if (fd_bList == null||fd_bList.isEmpty()) {
1103             orr.setCode(1);
1104             orr.setErrmsg("车辆未找到在办分单!");
1105             return orr;
1106         }
1107         Fd_Bsheet fd_b=null;
1108         if(fd_bList.size()>1) {
1109             for (Fd_Bsheet fd_Bsheet : fd_bList) {
1110                 int wd=this.bsper.getweightDoc(vehicleId, fd_Bsheet.getBsNo());
1111                 if(wd>0) {
1112                     fd_b=fd_Bsheet;
1113                     break;
1114                 }
1115             }
1116             if(fd_b==null) {
1117                 orr.setCode(1);
1118                 orr.setErrmsg("车辆:"+vehicleId+" 当前业务未找到绑定的过磅单,请先过磅或者重绑磅单!");
1119                 return orr;
1120             }
1121         }else {
1122             fd_b=fd_bList.get(0);
1123             int wcnum=this.bsper.getweightDoc(vehicleId, fd_b.getBsNo());
1124             if(wcnum<=0){
1125                 orr.setCode(1);
1126                 orr.setErrmsg("车辆:"+vehicleId+" 当前业务未找到绑定的过磅单,请先过磅或者重绑磅单!");
1127                 return orr;
1128             }
1129         }
5aa407 1130         // 改成使用在用卡的卡号、车牌号码、厂区来确认是否有销售的业务单 btid=3 businesstype00002
A 1131         String businessNo = bsper.getBusinessNoByCardNo(cardID,vehicleId,sdepartNo);
58d006 1132         if(StringUtils.isBlank(businessNo)) {
A 1133             orr.setCode(1);
1134             orr.setErrmsg("未找到该卡的在办业务单!");
1135             return orr;
1136         }
1137 //        List<Vehicle_XSTD> vxl=this.vhxper.getlistbyVehicleId(vehicleId);
1138         List<Vehicle_XSTD> vxl= this.vhxper.getlistbyVehicleIdandbsNoGp(vehicleId, businessNo);
1139         List<Map<String, Object>> datamp=new ArrayList<Map<String, Object>>();
5aa407 1140         Map<String,Fd_XSTD> xstdMap = new HashMap(); // 缓存Fd_XSTD,避免多查
58d006 1141         for (Vehicle_XSTD vx : vxl) {
A 1142             String tdbh=vx.getXstdNo();
1143             Fd_XSTD td=this.tdper.getbyTDBH(tdbh);
1144             String wlgsbh=vx.getCompanyNo();
1145             Fd_Company fd_c=this.cmper.getByCompanyNo(wlgsbh);
1146             Map<String, Object> tdm=new HashMap<String, Object>();
1147             if(fd_c!=null){
1148                 tdm.put("td_wlgs", fd_c.getName());//物流公司
1149             }else{
1150                 tdm.put("td_wlgs", "");//物流公司
1151             }
1152             if(td==null){
1153                 continue;
1154             }
1155             // List<Fd_XSTDMX> tdmxl=this.tdmxper.getbytdls(td.getTd_tdls());
1156             List<Fd_XSTDMX> tdmxl= tdmxper.getListByTdlsAndCph(td.getTd_tdls(),vehicleId);
1157             if(tdmxl==null||tdmxl.size()<=0){
1158                 continue;
1159             }
1160             Map<String, Object> mm=new HashMap<String, Object>();
1161             tdm.put("td_tdbh", td.getTd_tdbh());
1162             tdm.put("td_tdls", td.getTd_tdls());
1163             tdm.put("td_jylx", td.getTd_jylx());
5aa407 1164             Fd_XSTD fd_xstd = xstdMap.get(td.getTd_tdbh());
A 1165             if(xstdMap.get(td.getTd_tdbh())==null) { // 保证同一个提单只查一遍
1166                 fd_xstd = tdper.getbyttdbh(td.getTd_tdbh());
1167             }
1168             //增加客户名称 备注
1169             if(StringUtils.isBlank(fd_xstd.getTd_fpbh())){
1170                 Nckh nckh = zsjper.getNckhbyCode(fd_xstd.getTd_khbh());// 客户不存在的特殊情况是不应该存在的,以防万一,加判空。
1171                 tdm.put("td_khmc",nckh!=null?nckh.getName():"");
1172             }else {
1173                 String name = ConvertTool.covertToCustoms(fd_xstd.getTd_ywdybh());
1174                 tdm.put("td_khmc", name);
1175             }
1176             tdm.put("td_bz",fd_xstd.getTd_bz());
58d006 1177             mm.put("td", tdm);
A 1178             mm.put("tdmx", tdmxl);
1179             datamp.add(mm);
1180         }
5aa407 1181
A 1182
58d006 1183         rem.put("cph", vehicleId);
A 1184         rem.put("sjmc", fd_b.getDriver());
1185         rem.put("dh", fd_b.getPhone());
1186 //        rem.put("sjmc", fdv.getDriver());
1187 //        rem.put("dh", fdv.getPhone());
1188         rem.put("ywdh", fd_b.getBsNo());
1189         rem.put("respcode", 111);
1190         rem.put("data", datamp);
1191
1192         //修改装车记录
1193         Map<String, Object> mr=this.bsper.selectTaskTime(fd_b.getBsNo());
1194         if(mr!=null) {
1195             if(mr.get("firstzxhtime")!=null) {
1196                 mr.put("lastzxhtime", new Date());
1197             }else {
1198                 mr.put("firstzxhtime", new Date());
1199             }
a0879b 1200             if(needRecord) { // 为true 则更新第一次扫卡时间,否则不记录
H 1201                 this.bsper.updateTaskTime(mr);
1202             }
58d006 1203         }else {
A 1204             orr.setCode(1);
1205             orr.setErrmsg("未找到装车记录");
1206             return orr;
1207         }
1208
1209         orr.setCode(0);
1210         orr.setItem(rem);
1211         return orr;
1212     }
1213
1214     @Override
1215     public ObjectResult<Map<String, Object>> getxstdInfo(String xstdNo) {
1216         ObjectResult<Map<String, Object>> orr=new ObjectResult<Map<String,Object>>();
1217         Fd_XSTD xstd=this.tdper.getbyTDBH(xstdNo);
1218         if(xstd==null){
1219             orr.setCode(1);
1220             orr.setErrmsg("提单未找到!");
1221             return orr;
1222         }
1223         Map<String, Object> rm=new HashMap<String, Object>();
1224         List<Fd_XSTDMX> tdmxlist=this.tdmxper.getListbytdls(xstd.getTd_tdls());
1225         rm.put("code", 0);
1226         rm.put("item", xstd);
1227         rm.put("itemList", tdmxlist);
1228         orr.setCode(0);
1229         orr.setItem(rm);
1230         return orr;
1231     }
1232
1233     @Override
1234     @Transactional(rollbackFor=Exception.class)
1235     public ObjectResult<Boolean> savewdControl(JsonArray dataArr)throws Exception {
1236         ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
1237         if(dataArr==null){
1238             orr.setCode(0);
1239             orr.setErrmsg("添加过磅控制成功!");
1240             return orr;
1241         }
1242         for (JsonElement je : dataArr) {
1243             JsonObject jo=je.getAsJsonObject();
1244             String bsNo=jo.get("yktywdh").getAsString();
1245             BsheetEcgb be=this.beper.getbyNo(bsNo);
1246             if(be==null){
1247                 be=new BsheetEcgb();
1248                 be.setBsNo(bsNo);
1249                 be.setCtime(new Date());
1250                 be.setCname("生产系统添加");
1251                 be.setSate(1);
1252                 this.beper.insert(be);
1253             }
1254         }
1255         orr.setCode(0);
1256         orr.setErrmsg("添加过磅控制成功!");
1257         return orr;
1258     }
1259
1260
1261
1262
1263 }