Administrator
2023-03-31 0620759090646bf58a7e786c55cfe07ce1984e45
提交 | 用户 | 时间
58d006 1 package com.mandi.fendan.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.penum.PrefixEnum;
9ce4bb 8 import com.mandi.basicconfig.persist.Nckh;
58d006 9 import com.mandi.common.*;
A 10 import com.mandi.common.ParamFileter.Fileoperation;
11 import com.mandi.common.ParamFileter.RegexCheck;
12 import com.mandi.dao.common.Daomethod;
13 import com.mandi.dao.common.ObjectResult;
14 import com.mandi.dao.common.PageRequest;
15 import com.mandi.dao.common.PageResult;
16 import com.mandi.fendan.mapper.*;
17 import com.mandi.fendan.persist.*;
18 import com.mandi.fendan.service.IErpService;
19 import com.mandi.fendan.util.Contants;
20 import com.mandi.fendan.util.ConvertTool;
21 import com.mandi.fendan.util.FdtoNc;
22 import com.mandi.fendan.util.persist.*;
9ce4bb 23 import com.mandi.springmvc.logs.OpLogs;
58d006 24 import com.mandi.system.persist.Login;
9ce4bb 25 import com.mandi.system.persist.ModuleEnum;
58d006 26 import com.mandi.system.persist.UserType;
A 27 import org.apache.commons.beanutils.BeanUtils;
28 import org.apache.commons.collections.map.HashedMap;
29 import org.apache.commons.lang3.StringUtils;
30 import org.apache.ibatis.session.ExecutorType;
31 import org.apache.ibatis.session.SqlSession;
32 import org.apache.ibatis.session.SqlSessionFactory;
33 import org.apache.log4j.Logger;
34 import org.apache.poi.util.StringUtil;
35 import org.springframework.stereotype.Service;
36 import org.springframework.transaction.annotation.Transactional;
37
38 import javax.annotation.Resource;
39 import java.io.UnsupportedEncodingException;
40 import java.lang.reflect.InvocationTargetException;
41 import java.net.URLEncoder;
42 import java.text.SimpleDateFormat;
43 import java.util.*;
44 import java.util.Map.Entry;
45 import java.util.stream.Collectors;
46
47 @Service
48 public class ErpService implements IErpService {
49     private Logger log = Logger.getLogger(ErpService.class);
50
51     @Resource(name = "dtf")
52     private SimpleDateFormat sdf;
53     @Resource(name = "ydf")
54     private SimpleDateFormat ydf;
55     @Resource(name = "df")
56     private SimpleDateFormat df;
57     @Resource
58     private Fd_BsheetMapper fdbsper;
59     @Resource
60     private Fd_VehicleMapper vhper;
61     @Resource
62     private VehicleXSTDMapper vhxper;
63     @Resource
64     private Fd_CompanyMapper fdcper;
65     @Resource
66     private Fd_ComVehicleMapper fdvcper;
67     @Resource
68     private Fd_XSTDMapper tdper;
69     @Resource
70     private Fd_XSTDMXMapper tdmxper;
71     @Resource
72     private Fd_GbxstdMapper gbtdper;
73     @Resource
74     private Fd_GbxstdmxMapper gbtdmxper;
75     @Resource
76     private Fd_fhdqMapper dqper;
77
78     @Resource
79     private BusinessMapper bsper;
80     @Resource
81     private Fd_YKTMapper yktmper;
82     @Resource
83     private FdtoNc fdtonc;
84     @Resource
85     private fd_errsheetMapper errPer;
86     @Resource
87     private FdMxWlgsMapper fdMxWlgsMapper;
88
89     @Resource
90     private SqlSessionFactory sqlSessionFactory;
91
062075 92     @Resource
1c4e40 93     private FdVehicleRemarkMapper fdVehicleRemarkMapper;
A 94
58d006 95     @Override
A 96     public ObjectResult<String> tzPrint(Login lg, String bssNo, String ipadd) {
97         ObjectResult<String> orr = new ObjectResult<String>();
98         if (lg == null) {
99             orr.setCode(1);
100             orr.setErrmsg("请登录账号!");
101             return orr;
102         }
103         if (StringUtils.isEmpty(bssNo)) {
104             orr.setCode(1);
105             orr.setErrmsg("业务参数为空!");
106             return orr;
107         }
108         Fd_Bsheet fd_b = this.fdbsper.getbybsNo(bssNo);// this.fdbsper.getbyVehicleId(vehicleId, Serviceenum.在办);
109         if (fd_b == null) {
110             orr.setCode(1);
111             orr.setErrmsg("车辆业务单未找到,不能打印!");
112             return orr;
113         }
114         if (fd_b.getStatus() != Serviceenum.在办) {
115             orr.setCode(1);
116             orr.setErrmsg("车辆业务单不是在办状态,不能打印!");
117             return orr;
118         }
119         String comNo = "";
120         if (!UserType.admin.toString().equals(lg.getWorkerno())) {
121             // List<Vehicle_XSTD>
122             // ll=this.vhxper.getlistbyVehandcompanyNo(vehicleId,lg.getDepartno());
123             // if(ll!=null){
124             // for (Vehicle_XSTD vhx : ll) {
125             // if(StringUtils.isEmpty(comNo)){
126             // comNo+=vhx.getXstdNo();
127             // }else{
128             // comNo+=(","+vhx.getXstdNo());
129             // }
130             // }
131             // }
132             if (StringUtils.isNotBlank(lg.getDepartno())) {
133                 comNo = lg.getDepartno();
134             }
135         }
136         // Map<String, Object> mp=this.bsper.getBsheet(fd_b.getBsNo());
137         // if(mp==null){
138         // orr.setCode(1);
139         // orr.setErrmsg("业务单未找到!");
140         // return orr;
141         // }
142         String dyAdd = this.bsper.getUsedbyAdd();
143         if (StringUtils.isBlank(dyAdd)) {
144             orr.setCode(1);
145             orr.setErrmsg("系统未设置打印地址!");
146             return orr;
147         }
148         try {
149             orr.setItem("http://" + dyAdd + Contants.GYPrintAdd + "&vehicleId="
150                     + URLEncoder.encode(fd_b.getVehicleId(), "utf-8") + "&bsNo=" + fd_b.getBsNo() + "&phone="
151                     + fd_b.getPhone() + "&comNo=" + comNo);
152             // log.info("::::::::::;"+orr.getItem());
153         } catch (UnsupportedEncodingException e) {
154             e.printStackTrace();
155         }
156
157         orr.setCode(0);
158         return orr;
159     }
160     // 暂时没有使用
161     public PageResult<Map<String, Object>> getBillofLadingList(Login lg, String type, String searchStr, String companyNo,
162                                                                Date sdate, Date edate, int wcSign, PageRequest pr, String sortStr, String cqNo) {
163         PageResult<Map<String, Object>> prr = new PageResult<Map<String, Object>>();
164         // 销售提单查询值不为空
165         if (lg == null) {
166             prr.setCode(1);
167             prr.setErrmsg("请登录账号!");
168             return prr;
169         }
170         if (StringUtils.isEmpty(companyNo)) {
171             if (!UserType.admin.toString().equals(lg.getWorkerno())) {
172                 companyNo = lg.getDepartno();
173             }
174         }
175         if (pr == null) {
176             pr = new PageRequest(0, 30, null);
177             pr.setNeedPages(true);
178         }
179
180         // 查询参数
181         Map<String, Object> pmp = new HashMap<String, Object>();
182         // 查询值 type
183         if (StringUtils.isNotBlank(searchStr)) {
184             pmp.put(type, searchStr);
185         }
186         if (sdate != null) {
187             Date now = new Date();
188             Calendar theCa = Calendar.getInstance();
189             theCa.setTime(now);
190             theCa.add(Calendar.DATE, -Contants.XSTDlastSearchday);
191             Date csdate = theCa.getTime();
192             if (csdate.after(sdate)) {
193                 sdate = csdate;
194             }
195             pmp.put("sdate", df.format(sdate));
196         } else {
197             Date now = new Date();
198             Calendar theCa = Calendar.getInstance();
199             theCa.setTime(now);
200             theCa.add(Calendar.DATE, -Contants.XSTDlastSearchday);
201             sdate = theCa.getTime();
202             pmp.put("sdate", df.format(sdate));
203         }
204         if (edate != null) {
205             pmp.put("edate", df.format(edate));
206         }
207         if (!StringUtils.isEmpty(companyNo)) {
208             pmp.put("companyNo", companyNo);
209             Fd_Company fdc = this.fdcper.getByCompanyNo(companyNo);
210             if (fdc != null) {
211                 pmp.put("ztbz", fdc.isHasSPR() ? 1 : 0);
212             }
213         }
214         pmp.put("page", pr.getStart());
215         pmp.put("pagesize", pr.getPageSize());
216         pmp.put("wcSign", wcSign);
217         if(StringUtils.isNotBlank(cqNo))
218             pmp.put("cqV", cqNo);
219         // 排序字段
220         pmp.put("sort", sortStr);
221         if (pr.isNeedPages()) {
222             int count = this.tdper.countPage(pmp);
223             int pages = Daomethod.countpages(count, pr.getPageSize());
224             prr.setPages(pages);
225         }
226
227         List<WaitXSTD> l = this.tdper.getList(pmp);
228         List<Map<String, Object>> rl = new ArrayList<Map<String, Object>>();
229         if (l != null) {
230             for (WaitXSTD wt : l) {
231                 String fhdqbh = wt.getTd_shddbh();
232                 String ztbz = wt.getTd_ztbz();
233                 Map<String, Object> mm = new HashMap<String, Object>();
234                 try {
235                     mm = BeanUtils.describe(wt);
236                 } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
237                     prr.setCode(1);
238                     prr.setErrmsg("对象转Map出错,出错提单编号::" + wt.getTd_tdbh());
239                     return prr;
240                 }
241                 if (!"自提".equals(ztbz)) {
242                     /*List<Fd_Company> fcl = this.dqper.getCbyNoandsNo(fhdqbh, wt.getTd_ywdybh(),
243                             *//*wt.getTd_ywdybh().equals(Contants.nc_ywdy_ZZ) ? Contants.nc_ywdy_ZZ :
244                                 wt.getTd_ywdybh().equals(Contants.nc_ywdy_MS) ? Contants.nc_ywdy_MS :
245                                     Contants.nc_ywdy_KJ*//*
246                             ConvertTool.ncGetDefault(wt.getTd_ywdybh())
247                     );
248                     if (fcl != null) {
249                         for (Fd_Company fdc : fcl) {
250                             if (StringUtils
251                                     .isNotBlank(mm.get("companyNo") == null ? "" : mm.get("companyNo").toString())) {
252                                 mm.put("companyName", mm.get("companyName") + "," + fdc.getName());
253                                 mm.put("companyNo", mm.get("companyNo") + "," + fdc.getCompanyNo());
254                             } else {
255                                 mm.put("companyName", fdc.getName());
256                                 mm.put("companyNo", fdc.getCompanyNo());
257                             }
258                         }
259                     }*/
260                 }
261                 try {
262                     mm.put("td_wfdsl", wt.getTd_wfdsl());
263                     mm.put("td_wfdzl", BigDecimalfiter.addscal(0, wt.getTd_wfdzl(), Contants.scale));
264                 } catch (Exception e) {
265                     // TODO: handle exception
266                 }
267                 rl.add(mm);
268             }
269         }
270         prr.setCode(0);
271         prr.setList(rl);
272         return prr;
273     }
274     @Override
275     public PageResult<Map<String, Object>> getXSTDList(Login lg, String type, String searchStr, String companyNo,
276             Date sdate, Date edate, int wcSign, String fdAdmin,PageRequest pr, String sortStr, String cqNo) {
277         PageResult<Map<String, Object>> prr = new PageResult<Map<String, Object>>();
278         // 销售提单查询值不为空
279         if (lg == null) {
280             prr.setCode(1);
281             prr.setErrmsg("请登录账号!");
282             return prr;
283         }
284         // 如果是管理员或者非提单更物流公司的操作
285         boolean isAdminOrFdAdmin = UserType.admin.toString().equals(lg.getWorkerno())  || StringUtils.isNotBlank(fdAdmin);
286         if (StringUtils.isEmpty(companyNo)) {
287             if (!isAdminOrFdAdmin) { // 如果不是更改车辆分单管理员和也不是系统管理员,需要加上公司no
288                 companyNo = lg.getDepartno();
289             }
290         }
291         if (pr == null) {
292             pr = new PageRequest(0, 30, null);
293             pr.setNeedPages(true);
294         }
295
296         // 查询参数
297         Map<String, Object> pmp = new HashMap<String, Object>();
298         // 查询值 type
299         if (StringUtils.isNotBlank(searchStr)) {
300             pmp.put(type, searchStr);
301         }
302         if (sdate != null) {
303             Date now = new Date();
304             Calendar theCa = Calendar.getInstance();
305             theCa.setTime(now);
306             theCa.add(Calendar.DATE, -Contants.XSTDlastSearchday);
307             Date csdate = theCa.getTime();
308             if (csdate.after(sdate)) {
309                 sdate = csdate;
310             }
311             pmp.put("sdate", df.format(sdate));
312         } else {
313             Date now = new Date();
314             Calendar theCa = Calendar.getInstance();
315             theCa.setTime(now);
316             theCa.add(Calendar.DATE, -Contants.XSTDlastSearchday);
317             sdate = theCa.getTime();
318             pmp.put("sdate", df.format(sdate));
319         }
320         if (edate != null) {
321             pmp.put("edate", df.format(edate));
322         }
323         if (!StringUtils.isEmpty(companyNo)) {
324             pmp.put("companyNo", companyNo);
325             Fd_Company fdc = this.fdcper.getByCompanyNo(companyNo);
326             if (fdc != null) {
327                 pmp.put("ztbz", fdc.isHasSPR() ? 1 : 0);
328             }
329         }
330         pmp.put("page", pr.getStart());
331         pmp.put("pagesize", pr.getPageSize());
332         pmp.put("wcSign", wcSign);
333         pmp.put("fdAdmin", fdAdmin);
334
335         if(StringUtils.isNotBlank(cqNo))
336             pmp.put("cqV", cqNo);
337         // 排序字段
338         pmp.put("sort", sortStr);
339         if (pr.isNeedPages()) {
340             int count = this.tdper.countPage(pmp);
341             int pages = Daomethod.countpages(count, pr.getPageSize());
342             prr.setPages(pages);
343         }
344
345         List<WaitXSTD> l = this.tdper.getList(pmp);
346         List<Map<String, Object>> rl = new ArrayList<Map<String, Object>>();
347         if (l != null) {
348             for (WaitXSTD wt : l) {
349                 String fhdqbh = wt.getTd_shddbh();
350                 String ztbz = wt.getTd_ztbz();
351                 Map<String, Object> mm = new HashMap<String, Object>();
352                 try {
353                     mm = BeanUtils.describe(wt);
354                 } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
355                     prr.setCode(1);
356                     prr.setErrmsg("对象转Map出错,出错提单编号::" + wt.getTd_tdbh());
357                     return prr;
358                 }
359                 if (!"自提".equals(ztbz)) {
360                     /*List<Fd_Company> fcl = this.dqper.getCbyNoandsNo(fhdqbh, wt.getTd_ywdybh(),
361                             wt.getTd_ywdybh().equals(Contants.nc_ywdy_ZZ) ? Contants.nc_ywdy_ZZ :
362                                 *//*wt.getTd_ywdybh().equals(Contants.nc_ywdy_MS) ? Contants.nc_ywdy_MS :
363                                     Contants.nc_ywdy_KJ*//*
364                             ConvertTool.ncGetDefault(wt.getTd_ywdybh())
365                     );
366                     if (fcl != null) {
367                         for (Fd_Company fdc : fcl) {
368                             if (StringUtils
369                                     .isNotBlank(mm.get("companyNo") == null ? "" : mm.get("companyNo").toString())) {
370                                 mm.put("companyName", mm.get("companyName") + "," + fdc.getName());
371                                 mm.put("companyNo", mm.get("companyNo") + "," + fdc.getCompanyNo());
372                             } else {
373                                 mm.put("companyName", fdc.getName());
374                                 mm.put("companyNo", fdc.getCompanyNo());
375                             }
376                         }
377                     }*/
378                 }
379                 try {
380                     mm.put("td_wfdsl", wt.getTd_wfdsl());
381                     mm.put("td_wfdzl", BigDecimalfiter.addscal(0, wt.getTd_wfdzl(), Contants.scale));
382                 } catch (Exception e) {
383                     // TODO: handle exception
384                 }
385                 rl.add(mm);
386             }
387         }
388         prr.setCode(0);
389         prr.setList(rl);
390         return prr;
391     }
392
393     @Override
394     public PageResult<Map<String, Object>> getCloseXSTDlist(Login lg, String type, String searchStr, String companyNo,
395             Date sdate, Date edate, int wcSign, PageRequest pr, List<String> sortc) {
396         // type 只有两种类型 提单编号/关闭人 sdate 关闭开始时间 edate 关闭结束时间 companyNo 运输公司 查询值
397         PageResult<Map<String, Object>> prr = new PageResult<Map<String, Object>>();
398         if (lg == null) {
399             prr.setCode(1);
400             prr.setErrmsg("请登录账号!");
401             return prr;
402         }
403         if (pr == null) {
404             pr = new PageRequest(0, 30, null);
405             pr.setNeedPages(true);
406         }
407         Map<String, Object> pmp = new HashMap<String, Object>();
408         pmp.put("page", pr.getStart());
409         pmp.put("pagesize", pr.getPageSize());
410         if (sdate != null) {
411             pmp.put("stime", sdate);
412         }
413         if (edate != null) {
414             pmp.put("etime", edate);
415         }
416         if (UserType.admin.toString().equals(lg.getWorkerno())) {
417             if (!StringUtils.isEmpty(companyNo)) {
418                 pmp.put("companyNo", companyNo);
419             }
420         } else {
421             Fd_Company fdc = this.fdcper.getByCompanyNo(lg.getDepartno());
422             if (fdc != null) {
423                 if (fdc.isHasSPR()) {
424                     pmp.put("isHSR", true);
425                 } else {
426                     pmp.put("companyNo", lg.getDepartno());
427                 }
428             } else {
429                 pmp.put("companyNo", "aaaaa");
430             }
431
432         }
433         // 提单号 模糊查询
434         if (StringUtils.isNotBlank(searchStr)) {
435             pmp.put(type, searchStr);
436         }
437         // if(!StringUtils.isEmpty(searchStr)&&"tdbh".equals(type)){
438         // if(!StringUtils.isEmpty(searchStr)){
439         // pmp.put("tdbh", searchStr);
440         // }
441         // }else if(){
442         // if(!StringUtils.isEmpty(searchStr)){
443         // pmp.put("td_gbr", searchStr);
444         // }
445         // }else
446         if (pr.isNeedPages()) {
447             int count = gbtdper.counts(pmp);
448             int pages = Daomethod.countpages(count, pr.getPageSize());
449             prr.setPages(pages);
450         }
451
452         List<Fd_Company> llc = this.fdcper.getall();
453         Map<String, Object> fdcmp = new HashMap<String, Object>();
454         if (llc != null) {
455             for (Fd_Company fd_Company : llc) {
456                 fdcmp.put(fd_Company.getCompanyNo() + "", fd_Company.getName());
457             }
458         }
459         List<Map<String, Object>> tdl = gbtdper.getList(pmp);
460         // List<Map<String, Object>> rel=new ArrayList<Map<String,Object>>();
461         // if(tdl!=null){
462         // for (Fd_Gbxstd gbtd : tdl) {
463         // Map<String, Object> rmp=this.tdper.getGBXSTD(gbtd.getXstdNo());
464         // rel.add(rmp);
465         // }
466         // }
467         List<Map<String, Object>> rl = new ArrayList<Map<String, Object>>();
468         if (tdl != null) {
469             for (Map<String, Object> wt : tdl) {
470                 String fhdqbh = wt.get("td_shddbh") == null ? "" : wt.get("td_shddbh").toString();
471                 String td_ywdybh = wt.get("td_ywdybh") == null ? "" : wt.get("td_ywdybh").toString();
472                 // String td_tdbh=wt.get("td_tdbh")==null?"":wt.get("td_tdbh").toString();
473                 String ztbz = wt.get("td_ztbz") == null ? "" : wt.get("td_ztbz").toString();
474                 Map<String, Object> mm = wt;
475                 mm.put("companyName", "");
476                 mm.put("companyNo", "");
477                 // try {
478                 // mm=BeanUtils.describe(wt);
479                 // } catch (IllegalAccessException | InvocationTargetException|
480                 // NoSuchMethodException e) {
481                 // prr.setCode(1);
482                 // prr.setErrmsg("对象转Map出错,出错提单编号::"+td_tdbh);
483                 // return prr;
484                 // }
485                 if (!"自提".equals(ztbz)) {
486                     /*List<Fd_Company> fcl = this.dqper.getCbyNoandsNo(fhdqbh, td_ywdybh,
487                             *//*td_ywdybh.equals(Contants.nc_ywdy_ZZ) ? Contants.nc_ywdy_ZZ :
488                                 td_ywdybh.equals(Contants.nc_ywdy_MS) ? Contants.nc_ywdy_MS :
489                                     Contants.nc_ywdy_KJ*//*
490                             ConvertTool.ncGetDefault(td_ywdybh)
491                                 );// getCbyNo(fhdqbh);
492                     if (fcl != null) {
493                         for (Fd_Company fdc : fcl) {
494                             if (StringUtils
495                                     .isNotBlank(mm.get("companyNo") == null ? "" : mm.get("companyNo").toString())) {
496                                 mm.put("companyName", mm.get("companyName") + "," + fdc.getName());
497                                 mm.put("companyNo", mm.get("companyNo") + "," + fdc.getCompanyNo());
498                             } else {
499                                 mm.put("companyName", fdc.getName());
500                                 mm.put("companyNo", fdc.getCompanyNo());
501                             }
502                         }
503                     }*/
504                 }
505                 // try {
506                 // mm.put("td_wfdsl",wt.getTd_wfdsl());
507                 // mm.put("td_wfdzl",BigDecimalfiter.addscal(0, wt.getTd_wfdzl(),
508                 // Contants.scale));
509                 // } catch (Exception e) {
510                 // // TODO: handle exception
511                 // }
512                 rl.add(mm);
513             }
514         }
515         prr.setCode(0);
516         prr.setList(rl);
517         return prr;
518     }
519
520     /**
521      * @param lg
522      * @param XSTD
523      * @return
524      */
525     @Override
526     public Map<String, Object> getXSTD(Login lg, String XSTD) {
527         Map<String, Object> mp = new HashMap<String, Object>();
528         if (lg == null) {
529             mp.put("code", 1);
530             mp.put("errmsg", "请登录账号!");
531             return mp;
532         }
533         if (StringUtils.isBlank(XSTD)) {
534             mp.put("code", 1);
535             mp.put("errmsg", "查询值:提单号 为空!");
536             return mp;
537         }
538
539         Fd_XSTD xstd = this.tdper.getbyttdbh(XSTD);
540         if (xstd == null) {
541             mp.put("code", 1);
542             mp.put("errmsg", "提单查询为空!");
543             return mp;
544         }
545         String companyNo = null;
546         if (!UserType.admin.toString().equals(lg.getWorkerno())) {
547             Fd_Company fdc = this.fdcper.getByCompanyNo(lg.getDepartno());
548             companyNo = fdc.getCompanyNo();
549         }
550
551         String shdqbh = xstd.getTd_shddbh();
552         // 自提
553         if (xstd.getTd_ztbz() == 2) {
554             if (!UserType.admin.toString().equals(lg.getWorkerno())) {
555                 Fd_Company fdc = this.fdcper.getByCompanyNo(lg.getDepartno());
556                 if (fdc != null) {
557                     if (!fdc.isHasSPR()) {
558                         mp.put("code", 1);
559                         mp.put("errmsg", "没有查看该提单的权限!");
560                         return mp;
561                     }
562                 } else {
563                     mp.put("code", 1);
564                     mp.put("errmsg", "物流公司未找到!");
565                     return mp;
566                 }
567             }
568         } else {
569             if (!UserType.admin.toString().equals(lg.getWorkerno())) {
570                 Fd_wlgs_fhdq ccr = this.dqper.getbyNos(lg.getDepartno(), shdqbh,
571                         /*xstd.getTd_ywdybh().equals(Contants.nc_ywdy_ZZ) ? Contants.nc_ywdy_ZZ:
572                                 xstd.getTd_ywdybh().equals(Contants.nc_ywdy_MS) ? Contants.nc_ywdy_MS
573                                 : Contants.nc_ywdy_KJ*/
574                         ConvertTool.ncGetDefault(xstd.getTd_ywdybh())
575                 );
576                 // 这个地方改一下,允许fd_mx_wlgs中存在的单查看
577                 int total = fdMxWlgsMapper.selectCountByTdTdls(xstd.getTd_tdls());
578                 if (ccr == null && total == 0) {
579                     mp.put("code", 1);
580                     mp.put("errmsg", "没有查看该提单的权限!");
581                     return mp;
582                 }
583             }
584         }
585
586         // 编号转名字
587         // 转watiXSTD对象
588         // 查找明细:未装车
589         // 过滤掉已经配车并且配车车辆不是该公司的: 虽然两个物流公司可以使用同一个销售发货单,但是两个物流公司的分单时间是错开的
590         WaitXSTD wxt = this.tdper.getWaitXSTD(XSTD);
591
592         Map<String, Object> mxpmp = new HashMap<String, Object>();
593
594         // 过滤条件
595         mxpmp.put("tdls", wxt.getTd_tdls());
596         mxpmp.put("zcbz", 0);
597         mxpmp.put("pagesize", 0);
598         mxpmp.put("page", 0);
599         if(StringUtils.isNotBlank(companyNo)) {
600             mxpmp.put("companyNo", companyNo);
601         }
602         List<Map<String, Object>> XSTDMX_list = this.tdmxper.getList(mxpmp);
603
604         mp.put("code", 0);
605         mp.put("item", wxt);
606         mp.put("list", XSTDMX_list);
607         return mp;
608     }
609     @Override
610     public Map<String, Object>  getBillofLadingXSTD(Login lg,String XSTD){
611         String companyNo = null;
612         boolean isFdAdmin = lg.isFdAdmin();
613         // 是否为管理员或分单管理员
614         boolean isAdminOrFdAdmin = UserType.admin.toString().equals(lg.getWorkerno()) || isFdAdmin;
615         if (!isAdminOrFdAdmin) {
616             Fd_Company fdc = this.fdcper.getByCompanyNo(lg.getDepartno());
617             companyNo = fdc.getCompanyNo();
618         }
619         Map<String, Object> mp = new HashMap<String, Object>();
620         if (lg == null) {
621             mp.put("code", 1);
622             mp.put("errmsg", "请登录账号!");
623             return mp;
624         }
625         if (StringUtils.isBlank(XSTD)) {
626             mp.put("code", 1);
627             mp.put("errmsg", "查询值:提单号 为空!");
628             return mp;
629         }
630
631         Fd_XSTD xstd = this.tdper.getbyttdbh(XSTD);
632         if (xstd == null) {
633             mp.put("code", 1);
634             mp.put("errmsg", "提单查询为空!");
635             return mp;
636         }
637         String shdqbh = xstd.getTd_shddbh();
638         // 自提
639         if (xstd.getTd_ztbz() == 2) {
640             if (!isAdminOrFdAdmin) {
641                 Fd_Company fdc = this.fdcper.getByCompanyNo(lg.getDepartno());
642                 if (fdc != null) {
643                     if (!fdc.isHasSPR()) {
644                         mp.put("code", 1);
645                         mp.put("errmsg", "没有查看该提单的权限!");
646                         return mp;
647                     }
648                 } else {
649                     mp.put("code", 1);
650                     mp.put("errmsg", "物流公司未找到!");
651                     return mp;
652                 }
653             }
654         } else {
655             if (!isAdminOrFdAdmin) {
656                 Fd_wlgs_fhdq ccr = this.dqper.getbyNos(lg.getDepartno(), shdqbh,
657                         /*xstd.getTd_ywdybh().equals(Contants.nc_ywdy_ZZ) ? Contants.nc_ywdy_ZZ:
658                                 xstd.getTd_ywdybh().equals(Contants.nc_ywdy_MS) ? Contants.nc_ywdy_MS
659                                 : Contants.nc_ywdy_KJ*/
660                         ConvertTool.ncGetDefault(xstd.getTd_ywdybh())
661                 );
662                 int total = fdMxWlgsMapper.selectCountByTdTdls(xstd.getTd_tdls());
663                 if (ccr == null && total == 0) {
664                     mp.put("code", 1);
665                     mp.put("errmsg", "没有查看该提单的权限!");
666                     return mp;
667                 }
668             }
669         }
670
671         // 编号转名字
672         // 转watiXSTD对象
673         // 查找明细:未装车
674         // 过滤掉已经配车并且配车车辆不是该公司的: 虽然两个物流公司可以使用同一个销售发货单,但是两个物流公司的分单时间是错开的
675         WaitXSTD wxt = this.tdper.getWaitXSTD(XSTD);
676
677         Map<String, Object> mxpmp = new HashMap<String, Object>();
678
679         // 过滤条件
680         mxpmp.put("tdls", wxt.getTd_tdls());
681         // 已经装车的也要显示,方便调整
682         // mxpmp.put("zcbz", 0);
683         mxpmp.put("pagesize", 0);
684         mxpmp.put("page", 0);
685         if(StringUtils.isNotBlank(companyNo)) {
686             mxpmp.put("companyNo", companyNo);
687         }
688         List<Map<String, Object>> XSTDMX_list = this.tdmxper.getList(mxpmp);
689
690         mp.put("code", 0);
691         mp.put("item", wxt);
692         mp.put("list", XSTDMX_list);
693         return mp;
694     }
695     @Override
696     public PageResult<Map<String, Object>> getFdlist(Login lg, String companyNo, String vehicleId, PageRequest pr,
697             String cqV) {
698         PageResult<Map<String, Object>> prr = new PageResult<Map<String, Object>>();
699         if (pr == null) {
700             pr = new PageRequest(0, 30, null);
701             pr.setNeedPages(true);
702         }
703         if (lg == null) {
704             prr.setCode(1);
705             prr.setErrmsg("请登录账号!");
706             return prr;
707         }
708         Map<String, Object> mp = new HashMap<String, Object>();
709         // 按公司划分
710         String crc = "";
711         if (StringUtils.isNotBlank(companyNo)) {
712             mp.put("companyNo", companyNo);
713             crc = companyNo;
714         } else {
715             if (lg.getWorkerno().equals(UserType.admin.toString())) {
716                 mp.put("companyNo", "");
717                 crc = "";
718             } else {
719                 mp.put("companyNo", lg.getDepartno());
720                 crc = lg.getDepartno();
721             }
722         }
723         if (!StringUtils.isEmpty(vehicleId)) {
724             mp.put("vehicleId", vehicleId);
725         }
726         mp.put("pagesize", pr.getPageSize());
727         mp.put("page", pr.getStart());
728         if(StringUtils.isNotBlank(cqV)) {
729             mp.put("cqV",/*Contants.nc_ywdy_ZZ.equals(cqV)?Contants.zzSdepartNo:
730                 Contants.nc_ywdy_MS.equals(cqV)?Contants.msSdepartNo:Contants.kjSdepartNo*/
731                     ConvertTool.ncCovertToYkt(cqV)
732             );
733         }
734         if (pr.isNeedPages()) {
735             int count = bsper.getbspages(mp);
736             int pages = Daomethod.countpages(count, pr.getPageSize());
737             prr.setPages(pages);
738         }
739         List<Map<String, Object>> list = bsper.getbslist(mp);
740         List<Map<String, Object>> relist = new ArrayList<Map<String, Object>>();
741         if (list != null && list.size() > 0) {
742             List<Vehicle_XSTD> vxlist = StringUtils.isBlank(crc) ? this.vhxper.getlistAll()
743                     : this.vhxper.getlistbycomNo(crc);
744             // List<Fd_Company> cl=this.vhxper.getAllCom();
745             for (Map<String, Object> map : list) {
746                 Map<String, Object> remp = map;
747                 String bsNo = remp.get("bussinessNo") + "";
748                 String vc = remp.get("vehicleId") + "";
749                 // 销售分单值: 本单位分单数量和重量 其他单位分车数量和重量
750                 if (vxlist != null) {
751                     for (Vehicle_XSTD vehicle_XSTD : vxlist) {
752                         try {
753                             if (vehicle_XSTD.getVehicleId().equals(vc)) {
754                                 remp.put("fdCnum",
755                                         Integer.parseInt(
756                                                 remp.get("fdCnum") == null ? "0" : remp.get("fdCnum").toString())
757                                                 + vehicle_XSTD.getFd_num());
758                                 remp.put("fdCweight", BigDecimalfiter.addscal(
759                                         Double.parseDouble(
760                                                 remp.get("fdCweight") == null ? "0" : remp.get("fdCweight").toString()),
761                                         vehicle_XSTD.getFd_weight(), 4));
762                                 if (lg.getDepartno() != null && lg.getDepartno().equals(vehicle_XSTD.getCompanyNo())) {
763                                     remp.put("fdnum",
764                                             Double.parseDouble(
765                                                     remp.get("fdnum") == null ? "0" : remp.get("fdnum").toString())
766                                                     + vehicle_XSTD.getFd_num());
767                                     remp.put("fdweight",
768                                             BigDecimalfiter.addscal(
769                                                     Double.parseDouble(remp.get("fdweight") == null ? "0"
770                                                             : remp.get("fdweight").toString()),
771                                                     vehicle_XSTD.getFd_weight(), 4));
772                                 }
773                             }
774                         } catch (Exception e) {
775                             prr.setCode(1);
776                             prr.setErrmsg("数据转换错误,请刷新页面重新获取数据!");
777                             return prr;
778                         }
779                     }
780                 }
781                 // 销售分单单位值:
782                 List<Fd_Company> cl = vhxper.getCompany(vc, bsNo);
783                 if (cl != null && cl.size() > 1) {
784                     remp.remove("companyName");
785                     remp.remove("companyNo");
786                     for (Fd_Company fd_Company : cl) {
787                         remp.put("companyName", fd_Company.getName()
788                                 + (remp.get("companyName") == null ? "" : "," + remp.get("companyName").toString()));
789                         remp.put("companyNo", fd_Company.getCompanyNo()
790                                 + (remp.get("companyNo") == null ? "" : "," + remp.get("companyNo").toString()));
791                     }
792                 }
793                 relist.add(remp);
794             }
795         }
796         prr.setCode(0);
797         prr.setList(relist);
798         return prr;
799     }
800
801     @Override
9ce4bb 802     @Transactional
58d006 803     public ObjectResult<Boolean> delFdsheet(Login lg, String bsNo) throws Exception{
A 804         ObjectResult<Boolean> or = new ObjectResult<Boolean>();
805         if (lg == null) {
806             or.setCode(1);
807             or.setErrmsg("请登录账号!");
808             return or;
809         }
810         if (UserType.admin.toString().equals(lg.getWorkerno())) {
811             or.setCode(1);
812             or.setErrmsg("管理员不能执行分单操作!");
813             return or;
814         }
815         Fd_Company fdc = fdcper.getByCompanyNo(lg.getDepartno());
816         if (fdc == null) {
817             or.setCode(1);
818             or.setErrmsg("登录账号所属的物流公司不存在!");
819             return or;
820         }
821         Fd_Bsheet fb = fdbsper.getbybsNo(bsNo);
822         if (fb == null) {
823             or.setCode(1);
824             or.setErrmsg("分单业务单未找到!");
825             return or;
826         }
827         if (fb.getStatus() != Serviceenum.在办) {
828             or.setCode(1);
829             or.setErrmsg("分单业务单状态不是在办状态!");
830             return or;
831         }
832         String vehicleId = fb.getVehicleId();
833         Fd_Vehicle fdv = vhper.getByVehicleId(vehicleId);
834         if (fdv == null) {
835             or.setCode(1);
836             or.setErrmsg("分单系统未找到车牌号:" + vehicleId + " 车辆信息!");
837             return or;
838         }
839         int zcsl = this.tdmxper.getbyBsNowith(bsNo,vehicleId);
840         if (zcsl > 0) {
841             or.setCode(1);
842             or.setErrmsg("该车已经扫码装车,请先联系成品库删除装车记录并解绑磅单!");
843             return or;
844         }
845         int wdNum = this.bsper.getweightDoc(vehicleId, bsNo);
846         if (wdNum > 0) {
847             or.setCode(1);
848             or.setErrmsg("车辆:" + vehicleId + " 已经过磅,请先联系成品库解绑磅单!");
849             return or;
850         }
851         List<Vehicle_XSTD> fdvcl = this.vhxper.getlistbyVehicleIdandbsNoGp(vehicleId, bsNo);
852
853         // 判断是否删除业务单:如果两个物流公司使用同一辆车,不删除业务单,只修改该物流公司分单的信息
854         String sdNo = fb.getSdepartNo();
855         boolean delYWD = true;
856         List<Vehicle_XSTD> vxl = new ArrayList<Vehicle_XSTD>();
857         if (fdvcl != null) {
858             for (Vehicle_XSTD vhxstd : fdvcl) {
859                 // 同一个业务单
860                 if (bsNo.equals(vhxstd.getBsNo())) {
861                     if (lg.getDepartno().equals(vhxstd.getCompanyNo())) {
862                         vxl.add(vhxstd);
863                     } else {
864                         delYWD = false;
865                     }
866                 }
867             }
868         } else {
869             or.setCode(1);
870             or.setErrmsg("该业务单未找到分单记录!");
871             return or;
872         }
873
874         // 发送NC
875         List<Fd_XSTD> tdl = new ArrayList<Fd_XSTD>();
876         Map<String, List<Fd_XSTDMX>> mxMp = new HashMap<String, List<Fd_XSTDMX>>();
877
878         if (vxl != null && vxl.size() > 0) {
879             Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(),"取消配车业务单  vheicle_xstd ::" + Jacksonmethod.tojson(vxl, false));
880             for (Vehicle_XSTD VX : vxl) {
881                 String xstdNo = VX.getXstdNo();
882                 List<Fd_XSTDMX> mxl = new ArrayList<Fd_XSTDMX>();
883                 Fd_XSTD xstd = this.tdper.getbyTDBH(xstdNo);
884                 List<Fd_XSTDMX> MXL = this.tdmxper.getbyBsNoandcmNo(xstd.getTd_tdls(), bsNo, lg.getDepartno());
885                 double ZZL = 0;
886                 int ZZS = 0;
887                 for (Fd_XSTDMX MX : MXL) {
888 //                    // 已经关闭的不做处理
889 //                    if (MX.getTdmx_gbbz() != 0) {
890 //                        continue;
891 //                    }
892                     // 没有分单的跳过
893 //                    if (MX.getTdmx_fdbz() == 0) {
894 //                        MX.setTdmx_fdcph(null);
895 //                        MX.setTdmx_fdwlgsbh(null);
896 //                        MX.setTdmx_fdywbh(null);
897 //                        this.tdmxper.updateFD(MX);
898 //                        continue;
899 //                    }
900                     // 已经装车的不做处理
901 //                    if (MX.getTdmx_zcbz() != 0) {
902 //                        or.setCode(1);
903 //                        or.setErrmsg("提单:" + xstd.getTd_tdbh() + " 明细:" + MX.getTdmx_pch() + " 已经装车不能取消配车!");
904 //                        return or;
905 //                    }
906                     // 提单流水号
907                     ZZL = BigDecimalfiter.addscal(ZZL, MX.getTdmx_mz(), Contants.scale);
908                     ZZS++;
909                     MX.setTdmx_fdbz(0);
910                     MX.setTdmx_fdcph(null);
911                     MX.setTdmx_fdwlgsbh(null);
912                     MX.setTdmx_fdywbh(null);
913 //                    this.tdmxper.updateFD(MX);
914                     mxl.add(MX);
915                 }
916                 this.tdmxper.updatebyBsNoandcmNo(xstd.getTd_tdls(), bsNo, lg.getDepartno());
917
918                 this.vhxper.delbyIDs(vehicleId, xstdNo, lg.getDepartno());
919
920                 xstd.setTd_wfdsl(xstd.getTd_wfdsl() + ZZS);
921                 xstd.setTd_wfdzl(BigDecimalfiter.addscal(xstd.getTd_wfdzl(), ZZL, Contants.scale));
922                 this.tdper.updateFD(xstd);
923                 if (ZZS > 0) {
924                     tdl.add(xstd);
925                     mxMp.put(xstdNo, mxl);
926                 }
927             }
928         } else {
929             Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(),
930                     "取消配车业务单  vehicleId ::" + vehicleId + "::::dNo::::" + lg.getDepartno());
931             sdNo = fb.getSdepartNo();
932         }
933         if (StringUtils.isBlank(sdNo)) {
934             or.setCode(1);
935             or.setErrmsg("业务单元未找到不能删除一卡通业务单");
936             return or;
937         }
938
939         this.fdvcper.del(vehicleId, lg.getDepartno(), fb.getSdepartNo());
940
941         // 发送NC系统删除分单信息
942         if (tdl != null && tdl.size() > 0) {
943             Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(),
944                     "取消配车业务单  请求提单 ::" + Jacksonmethod.tojson(tdl, false));
945             Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(),
946                     "取消配车业务单  请求提单明细 ::" + Jacksonmethod.tojson(mxMp, false));
947             String fdhx = this.fdtonc.getNcdata(tdl, mxMp);
948             Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "取消配车业务单  请求参数 ::" + fdhx);
949             JsonObject joADDYWD = Wxhtmethod.postJsonStr(Contants.NCfdhx_url, fdhx);
950             Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "取消配车业务单 返回值 ::" + joADDYWD);
951             if (joADDYWD == null || JSONobj.getint(joADDYWD, "code") != 0) {
952                 throw new Exception(
953                         (joADDYWD.get("msg")==null||StringUtils.isBlank(joADDYWD.get("msg").getAsString())) ? "分单回写NC系统出错!"
954                         : joADDYWD.get("msg").getAsString());
955             } else {
956                 String restult = joADDYWD.get("result").getAsString();
957                 JsonParser jp = new JsonParser();
958                 JsonObject jr = jp.parse(restult).getAsJsonObject();
959                 if (jr == null || JSONobj.getint(jr, "respcode") != 111) {
960                     throw new Exception(jr.get("respmsg").getAsString());
961                 }
962             }
963         }
964
965         if (delYWD) {
966             if (fdv.getType() == VehicleType.临时车) {
967                 Fd_Bsheet fdbb=this.fdbsper.getbyVehicleWithNoSdepartNo(vehicleId, fb.getSdepartNo());
968                 if(fdbb==null)
969                     this.vhper.delByVehicleId(vehicleId);
970             } else {
971                 fdv.setStatus(VehicleStatus.未配车);
972                 this.vhper.update(fdv);
973             }
974             this.fdbsper.delbybsNo(bsNo);
975
976             // 发送一卡通服务删除表头信息
977             JsonObject jo = new JsonObject();
978             jo.addProperty("bussinessNo", bsNo);
979             jo.addProperty("sdepartNo", sdNo);
980             JsonObject pfob = Wxhtmethod.postJsonStr(Contants.YKTdelYwd_url, jo.toString());
981             int code = JSONobj.getint(pfob, "code");
982             if (code != 0) {
983                 throw new Exception(JSONobj.getstring(pfob, "errmsg"));
984             }
985
986         }
1c4e40 987         // 删除车辆分单的备注remark
A 988         fdVehicleRemarkMapper.deleteByBusinessNo(bsNo);
58d006 989         or.setCode(0);
A 990         or.setItem(true);
991         return or;
992     }
993
994     @Override
995     public PageResult<WaitXSTDMX> getVehicleDetails(Login lg, String bsNo) {
996         PageResult<WaitXSTDMX> pr = new PageResult<WaitXSTDMX>();
997         if (lg == null) {
998             pr.setCode(1);
999             pr.setErrmsg("请登录账号!");
1000             return pr;
1001         }
1002         if (StringUtils.isBlank(bsNo)) {
1003             pr.setCode(1);
1004             pr.setErrmsg("查询参数不能为空!");
1005             return pr;
1006         }
1007         Fd_Bsheet fb = this.fdbsper.getbybsNo(bsNo);// fdbsper.getbyVehicleId(vehicleId,Serviceenum.在办);
1008         if (fb == null) {
1009             pr.setCode(1);
1010             pr.setErrmsg("该车辆没有在办的业务单!");
1011             return pr;
1012         }
1013         if (fb.getStatus() != Serviceenum.在办) {
1014             pr.setCode(1);
1015             pr.setErrmsg("车辆业务单不是在办状态,不能打印!");
1016             return pr;
1017         }
1018         Fd_Company fdc = null;
1019         List<WaitXSTDMX> mxl = new ArrayList<WaitXSTDMX>();
1020         if (!UserType.admin.toString().equals(lg.getWorkerno())) {
1021             fdc = fdcper.getByCompanyNo(lg.getDepartno());
1022             if (fdc == null) {
1023                 pr.setCode(1);
1024                 pr.setErrmsg("物流公司不存在!");
1025                 return pr;
1026             }
1027             // 直接根据业务单号 车牌号 分单标志查找 fd_xstdmx表
1028             mxl = this.tdmxper.getwaitMXbyBsNoandcmNo(fb.getBsNo(), lg.getDepartno());
1029         } else {
1030             mxl = this.tdmxper.getwaitMXbyBsNo(fb.getBsNo());
1031         }
1032         pr.setCode(0);
1033         pr.setList(mxl);
1034         return pr;
1035     }
1036
1037     @Override
1038     @Transactional(rollbackFor = Exception.class)
1039     public ObjectResult<Boolean> doBindByList(Login lg, String tdlist, String vehicleInfo) throws Exception {
1040         ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
1041         if (StringUtils.isBlank(tdlist)) {
1042             orr.setCode(1);
1043             orr.setErrmsg("提单编号参数为空!");
1044             return orr;
1045         }
1046         if (StringUtils.isBlank(vehicleInfo)) {
1047             orr.setCode(1);
1048             orr.setErrmsg("车辆信息参数为空!");
1049             return orr;
1050         }
1051         if (lg == null) {
1052             orr.setCode(1);
1053             orr.setErrmsg("账号未登录,请登录账号!");
1054             return orr;
1055         }
1056         if (UserType.admin.toString().equals(lg.getWorkerno())) {
1057             orr.setCode(1);
1058             orr.setErrmsg("管理员账号没有分单权限!");
1059             return orr;
1060         }
1061         Fd_Company fdc = null;
1062         if (StringUtils.isNotBlank(lg.getDepartno())) {
1063             fdc = fdcper.getByCompanyNo(lg.getDepartno());
1064             if (fdc == null) {
1065                 orr.setCode(1);
1066                 orr.setErrmsg("登录账号没有配置物流公司,请联系管理员配置!");
1067                 return orr;
1068             }
1069         }
1070         JsonParser jp = new JsonParser();
1071         Fd_Vehicle fdv1 = new Fd_Vehicle();
1072         // 检查车辆信息
1073         try {
1074             JsonElement je = jp.parse(vehicleInfo);
1075             JsonObject jo = je.getAsJsonObject();
1076             String vehicleId =JSONobj.getstring(jo, "vehicleId")==null?"":
1077                 JSONobj.getstring(jo, "vehicleId").trim().toUpperCase();
1078             String driver = JSONobj.getstring(jo, "driver");
1079             String phone = JSONobj.getstring(jo, "phone");
1080             double vehicleweight = JSONobj.getdouble(jo, "vehicleweight");
1081             double loadweight = JSONobj.getdouble(jo, "loadweight");
1082             String feature = JSONobj.getstring(jo, "feature");
1083             String note = JSONobj.getstring(jo, "note");
1084             String IDNum = JSONobj.getstring(jo, "IDNum");
1085             if (StringUtils.isBlank(vehicleId) || StringUtils.isBlank(driver) || StringUtils.isBlank(IDNum)
1086                     || StringUtils.isBlank(phone)) {
1087                 orr.setCode(1);
1088                 orr.setErrmsg("车辆信息必填项:车牌号,司机姓名,身份证号,手机号不能为空!");
1089                 return orr;
1090             }
1091             fdv1.setCompanyNo(lg.getDepartno());
1092             fdv1.setDriver(driver);
1093             fdv1.setFeature(feature);
1094             fdv1.setId(UUID.randomUUID() + "");
1095             fdv1.setIDNum(IDNum);
1096             fdv1.setLoadweight(loadweight);
1097             fdv1.setNote(note);
1098             fdv1.setPhone(phone);
1099             fdv1.setState(true);
1100             fdv1.setStatus(VehicleStatus.未配车);
1101             fdv1.setType(VehicleType.临时车);
1102             fdv1.setVehicleId(vehicleId);
1103             fdv1.setVehicleweight(vehicleweight);
1104         } catch (Exception e) {
1105             orr.setCode(1);
1106             orr.setErrmsg("车辆信息解析出错,请重新操作!");
1107             return orr;
1108         }
1109
1110         String Rcompany = "";// 收货单位
1111         String bsDE = "";// 系统部门
1112         String ziti = "";// 是否自提
1113         List<Fd_XSTD> tdl = new ArrayList<Fd_XSTD>();
1114
1115         //校验提单信息数据是否合法:1.提单是否存在 2.当前账号是否可以操作该提单
1116         JsonArray tdja = jp.parse(tdlist).getAsJsonArray();
1117         for (JsonElement tdje : tdja) {
1118             String tdNo = tdje.getAsString();
1119             if (StringUtils.isNotBlank(tdNo)) {
1120                 Fd_XSTD td = this.tdper.getbyTDBH(tdNo);
5694bb 1121                 if (td == null || td.getTd_wfdsl()<=0 ) {
58d006 1122                     continue;
A 1123                 }
1124
1125                 // 这一块是判断用户有没有这个提单的操作权限 :
1126                 //1.在页面获取提单列表的时候已经加过校验,同一厂区的提单可以同时显示不同厂区的提单不能同时显示,用户只能同时操作同一厂区的提单
1127                 //当前用户只能看到可以操作的提单  不可以操作的提单看不到
1128                 //所有以下else操作去掉
1129                 if (StringUtils.isBlank(bsDE)) {
1130                     bsDE = ConvertTool.ncCovertToYkt(td.getTd_cqNo());
1131                 }
1132                 if (StringUtils.isBlank(ziti)) {
1133                     ziti = td.getTd_ztbz() == 2 ? "自提" : "非自提";
1134                 }
1135                 if (StringUtils.isBlank(Rcompany)) {
1136                     Map<String, Object> mm = this.dqper.getKH(td.getTd_khbh());
1137                     /*
1138                     * 1、外贸有发票编号,内贸没有发票编号
1139                     * 2、内贸取实际公司名称,外贸取相应组织的公司简称+‘报关’
1140                     * */
1141                     if (StringUtils.isBlank(td.getTd_fpbh())) {
1142                         if (mm != null) {
1143                             Rcompany = mm.get("name") == null ? "" : mm.get("name").toString();
1144                         }
5694bb 1145                         if(mm == null || mm.size() == 0) { // 客户必须存在,否则无法分单
A 1146                             orr.setCode(1);
1147                             orr.setErrmsg("该提单客户不存在,请检查数据!");
1148                             return orr;
1149                         }
58d006 1150                     } else {
A 1151                         Rcompany = ConvertTool.covertToCustoms(td.getTd_ywdybh());
1152                     }
1153                 }
1154                 tdl.add(td);
1155             }
1156         }
1157
1158         // 系统部门未找到
1159         if (StringUtils.isBlank(bsDE)) {
1160             orr.setCode(1);
1161             orr.setErrmsg("提单未找到系统部门字段,请重新操作!");
1162             return orr;
1163         }
1164
1165
1166         boolean saveBT = false;// 保存一卡通业务单表头信息
1167         String bsNo="";
1168         // 保存表相关信息
1169         try {
1170             // 保存业务单
1171             Fd_Bsheet fb = this.fdbsper.getbyVehicleId(fdv1.getVehicleId(), Serviceenum.在办, bsDE);
1172             if (fb == null) {
1173 //                // 获取业务单号  建议加上 记录一下开始时间和结束时间 判断地方的请求时间
1174                 JsonObject pfob = Wxhtmethod.postJsonStr(Contants.YKTgetPrefix_url, PrefixEnum.productsale.toString());
1175                 ObjectResult<String> pfor = new ObjectResult<String>();
1176                 String bssNo = JSONobj.getstring(pfob, "item");
1177                 int code = JSONobj.getint(pfob, "code");
1178                 String errmsg = JSONobj.getstring(pfob, "errmsg");
1179                 pfor.setCode(code);
1180                 pfor.setErrmsg(errmsg);
1181                 pfor.setItem(bssNo);
1182                 if (pfor == null || pfor.getCode() != 0) {
1183                     orr.setCode(1);
1184                     orr.setErrmsg(pfor.getErrmsg());
1185                     return orr;
1186                 }
1187                 fb = new Fd_Bsheet();
1188                 fb.setBsNo(pfor.getItem());
1189                 fb.setCompanyName(lg.getDepartname());
1190                 fb.setCompanyNo(lg.getDepartno());
1191                 fb.setCreateid(lg.getUserid());
1192                 fb.setCreateName(lg.getWorkername());
1193                 fb.setCtime(new Date());
1194                 fb.setDriver(fdv1.getDriver());
1195                 fb.setFdsheetNo(pfor.getItem());
1196                 fb.setId(UUID.randomUUID() + "");
1197                 fb.setPhone(fdv1.getPhone());
1198                 fb.setSendmsg(false);
1199                 fb.setStatus(Serviceenum.在办);
1200                 fb.setVehicleId(fdv1.getVehicleId());
1201                 fb.setSdepartNo(bsDE);
1202                 fb.setShdw(StringUtils.isBlank(Rcompany) ? "未知发货单位" : Rcompany);
1203                 fb.setUpdateTime(new Date());
1204                 this.fdbsper.insertAll(fb);
1205                 saveBT=true;
1206                 bsNo=bssNo;
1207             } else {
1208                 fb.setDriver(fdv1.getDriver());
1209                 fb.setPhone(fdv1.getPhone());
1210                 fb.setUpdateTime(new Date());
1211                 fdbsper.update(fb);
1212                 bsNo=fb.getBsNo();
1213             }
1214
1215             // 保存车辆信息
1216             Fd_Vehicle fdv = this.vhper.getByVehicleId(fdv1.getVehicleId());
1217             if (fdv == null) {
1218                 vhper.insert(fdv1);
1219             } else {
1220                 if (fdv.getType() == VehicleType.临时车) {
1221                     fdv.setDriver(fdv1.getDriver());
1222                     fdv.setPhone(fdv1.getPhone());
1223                     fdv.setIDNum(fdv1.getIDNum());
1224                     vhper.update(fdv);
1225                 }
1226             }
1227             Fd_Company_Vehicle fdcv = fdvcper.getbyIDs(fdv1.getVehicleId(), lg.getDepartno(), bsDE);
1228             if (fdcv == null) {
1229                 fdcv = new Fd_Company_Vehicle();
1230                 fdcv.setCompanyNo(lg.getDepartno());
1231                 fdcv.setVehicleId(fdv1.getVehicleId());
1232                 fdcv.setSdepartNo(bsDE);
1233                 fdvcper.insertIDs(fdcv);
1234             }
1235
1236             // 保存分单表相关信息
1237             Map<String, List<Fd_XSTDMX>> mxMp = new HashMap<String, List<Fd_XSTDMX>>();
1238             if(tdl!=null&&!tdl.isEmpty()) {
1239                 for (Fd_XSTD td : tdl) {
1240                     int fdsl = 0;
1241                     double fdmz = 0;
1242                     List<Fd_XSTDMX> mxl = this.tdmxper.getNOZCandFD(td.getTd_tdls());
1243                     if (mxl == null || mxl.isEmpty()) {
1244                         continue;
1245                     }
1246                     for (Fd_XSTDMX tdmx : mxl) {
1247                         fdsl++;
1248                         fdmz = BigDecimalfiter.addscal(fdmz, tdmx.getTdmx_mz(), Contants.scale);
1249                         tdmx.setTdmx_fdbz(1);
1250                         tdmx.setTdmx_fdcph(fdv1.getVehicleId());
1251                         tdmx.setTdmx_fdywbh(bsNo);
1252                         tdmx.setTdmx_fdwlgsbh(lg.getDepartno());
1253                     }
1254
1255                     Fd_XSTDMX tdmx=mxl.get(0);
1256                     tdmx.setTdmx_fdbz(1);
1257                     tdmx.setTdmx_fdcph(fdv1.getVehicleId());
1258                     tdmx.setTdmx_fdywbh(bsNo);
1259                     tdmx.setTdmx_fdwlgsbh(lg.getDepartno());
1260                     tdmx.setTdmx_tdls(td.getTd_tdls());
1261                     this.tdmxper.updateFDBatch(tdmx);
1262
1263                     Vehicle_XSTD vhx=this.vhxper.getbyIDs(fdv1.getVehicleId(), td.getTd_tdbh(),lg.getDepartno());
1264                     if(vhx==null){
1265                         vhx=new Vehicle_XSTD();
1266                         vhx.setBsNo(bsNo);
1267                         vhx.setCompanyNo(lg.getDepartno());
1268                         vhx.setFd_num(fdsl);
1269                         vhx.setFd_weight(fdmz);
1270                         vhx.setVehicleId(fdv1.getVehicleId());
1271                         vhx.setXstdNo(td.getTd_tdbh());
1272                          this.vhxper.insert(vhx);
1273                     }else{
1274                         vhx.setBsNo(bsNo);
1275                         vhx.setCompanyNo(lg.getDepartno());
1276                         vhx.setFd_num(vhx.getFd_num()+fdsl);
1277                         vhx.setFd_weight(BigDecimalfiter.add(vhx.getFd_weight(),fdmz));
1278                         vhx.setVehicleId(fdv1.getVehicleId());
1279                         vhx.setXstdNo(td.getTd_tdbh());
1280                         this.vhxper.updatewithIDs(vhx);
1281                     }
1282                     td.setTd_wfdsl(td.getTd_wfdsl() - fdsl);
1283                     td.setTd_wfdzl(BigDecimalfiter.subscal(td.getTd_wfdzl(), fdmz, Contants.scale));
1284                     this.tdper.updateFD(td);
1285                     mxMp.put(td.getTd_tdbh(), mxl);
1286                 }
1287             }
1288
1289             if (saveBT) {
1290                 YktBsheet bs = new YktBsheet();
1291                 bs.setSdepartNo(bsDE);
1292                 /*bs.setDcompany(
1293                         bsDE.equals(Contants.kjSdepartNo) ? "明泰科技"
1294                         :bsDE.equals(Contants.msSdepartNo) ? "河南明晟新材料"
1295                         : "郑州眀泰");*/
1296                 bs.setDcompany(ConvertTool.covertToFactoryName(bsDE));
1297                 bs.setDriver(fdv1.getDriver());
1298
1299                 bs.setNumberplates(StringUtils.upperCase(fdv1.getVehicleId()));
1300                 bs.setPhone(fdv1.getPhone());
1301                 bs.setRcompany(StringUtils.isBlank(Rcompany) ? "未知发货单位" : Rcompany);
1302                 bs.setBussinessNo(fb.getBsNo());
1303                 bs.setNote(ziti + ";" + lg.getDepartname() + ":" + lg.getWorkername() + "; 分单系统自动生成");
1304                 String bsStr = Jacksonmethod.tojson(bs, false);
1305                 JsonObject joADDYWD = Wxhtmethod.postJsonStr(Contants.YKTaddYwd_url, bsStr);
1306                 ObjectResult<String> ors = new ObjectResult<String>();
1307                 ors = JSONobj.getobj(joADDYWD, ors);
1308                 if (ors.getCode() != 0) {
1309                     throw new Exception(ors.getErrmsg());
1310                 }
1311             }else {
1312                 List<WaitXSTD> l=this.fdbsper.getAllKH(bsNo, fb.getId());
1313                 if(l!=null) {
1314                     boolean iscz=false;//收货单位在明细中是否存在
1315                     WaitXSTD wt=null;
1316                     for (WaitXSTD waitXSTD : l) {
1317                         if(fb.getShdw().equals(waitXSTD.getTd_khmc())) {
1318                             iscz=true;
1319                             break;
1320                         }else {
1321                             if(wt==null&&StringUtils.isNotBlank(waitXSTD.getTd_khmc())) {
1322                                 wt=waitXSTD;
1323                             }
1324                         }
1325                     }
1326                     if(!iscz&&wt!=null) {
1327                         fb.setShdw(wt.getTd_khmc());
1328                         this.yktmper.updateshcompany(bsNo, wt.getTd_khmc(),wt.getTd_shdd());
1329                     }
1330                 }
1331
1332             }
1333
1334             if (tdl != null && tdl.size() > 0 ) {
1335                 String fdhx = this.fdtonc.getNcdata(tdl, mxMp);
1336                 Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "整单配车 请求参数 ::" + fdhx);
1337                 JsonObject joADDYWD = Wxhtmethod.postJsonStr(Contants.NCfdhx_url, fdhx);
1338                 Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "整单配车 返回值 ::" + joADDYWD);
1339                 if (joADDYWD == null || JSONobj.getint(joADDYWD, "code") != 0) {
1340                     throw new Exception(
1341                             (joADDYWD.get("msg")==null||StringUtils.isBlank(joADDYWD.get("msg").getAsString())) ? "分单回写NC系统出错!"
1342                             : joADDYWD.get("msg").getAsString());
1343                 } else {
1344                     String restult = joADDYWD.get("result").getAsString();
1345                     JsonObject jr = jp.parse(restult).getAsJsonObject();
1346                     if (jr == null || JSONobj.getint(jr, "respcode") != 111) {
1347                         throw new Exception(jr.get("respmsg").getAsString());
1348                     }
1349                 }
1350             }
1351         } catch (Exception e) {
1352             if (saveBT) {
1353                 JsonObject jo = new JsonObject();
1354                 jo.addProperty("bussinessNo", bsNo);
1355                 jo.addProperty("sdepartNo", bsDE);
1356                 Wxhtmethod.postJsonStr(Contants.YKTdelYwd_url, jo.toString());
1357             }
1358             e.printStackTrace();
1359             throw new Exception(e.getMessage());
1360         }
1361         orr.setCode(0);
1362         orr.setItem(true);
1363         return orr;
1364     }
1365
1366     @Override
1367     @Transactional(rollbackFor = Exception.class)
1368     public ObjectResult<Boolean> dounBindByList(Login lg, String tdbhlist) throws Exception {
1369         ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
1370         if (lg == null) {
1371             orr.setCode(1);
1372             orr.setErrmsg("请登录账号!");
1373             return orr;
1374         }
1375         if (StringUtils.isBlank(tdbhlist)) {
1376             orr.setCode(1);
1377             orr.setErrmsg("业务参数为空,请选择提单!");
1378             return orr;
1379         }
1380         if (UserType.admin.toString().equals(lg.getWorkerno())) {
1381             orr.setCode(1);
1382             orr.setErrmsg("管理员不能操作分单!");
1383             return orr;
1384         }
1385         Fd_Company fdc = null;
1386         if (StringUtils.isNotBlank(lg.getDepartno())) {
1387             fdc = fdcper.getByCompanyNo(lg.getDepartno());
1388             if (fdc == null) {
1389                 orr.setCode(1);
1390                 orr.setErrmsg("账号没有配置物流公司,请联系管理员进行配置!");
1391                 return orr;
1392             }
1393         }
1394
1395         // for循环 tdbhlist
1396         // 查找td_xstd 对象 筛选是否有操作权限
1397         // 修改 td_xstdmx 表 修改 td_xstd 表 修改 vehicle_xstd表
1398         JsonParser jp = new JsonParser();
1399         JsonArray tdja = jp.parse(tdbhlist).getAsJsonArray();
1400         List<Fd_XSTD> tdl = new ArrayList<Fd_XSTD>();
1401         Map<String, List<Fd_XSTDMX>> mxMp = new HashMap<String, List<Fd_XSTDMX>>();
1402         for (JsonElement tdje : tdja) {
1403             String tdNo = tdje.getAsString();
1404             Fd_XSTD td = this.tdper.getbyTDBH(tdNo);
1405             if (td == null) {
1406                 continue;
1407             }
1408             // 这一块是判断用户有没有这个提单的操作权限 :
1409             //页面获取提单里诶包信息的时候已经加过校验  当前用户只能看到可以操作的提单  不可以操作的提单看不到
1410             // 这一块可以省略
1411             // 自提
1412 //            if (td.getTd_ztbz() == 2) {
1413 //                if (fdc != null) {
1414 //                    if (!fdc.isHasSPR()) {
1415 //                        continue;
1416 //                    }
1417 //                }
1418 //            } else {
1419 //                Fd_wlgs_fhdq dq = this.dqper.getbyNos(lg.getDepartno(), td.getTd_shddbh(),
1420 //                        td.getTd_ywdybh().equals(Contants.zzywdyNo) ? Contants.zzywdyNo : "103");
1421 //                if (dq == null) {
1422 //                    continue;
1423 //                }
1424 //            }
1425
1426
1427             // 如果该业务单已经装车 过滤掉不处理
1428             //这一块应该在页面中提示出来:提示:销售提单:XXXX 部分明细已经装车,请进入提单明细取消配车!
1429             List<Vehicle_XSTD> vxl = this.vhxper.getbyxstdNoandcmNo(tdNo, lg.getDepartno());
1430             if (vxl != null) {
1431                 boolean sffd=false;
1432                 for (Vehicle_XSTD vx : vxl) {
1433                     int zcsl = this.tdmxper.getbyBsNowithZC(vx.getBsNo(),td.getTd_tdls(),vx.getVehicleId());
1434                     if (zcsl > 0) {
1435                         sffd=true;
1436                         break;
1437                     }
1438                     Fd_Bsheet fb=this.fdbsper.getbyVehicleId(vx.getVehicleId(), Serviceenum.在办, lg.getSdepartNo());
1439                     if(fb !=null) {
1440                         fb.setUpdateTime(new Date());
1441                         this.fdbsper.update(fb);
1442                     }
1443                 }
1444                 if(sffd) {
1445                     continue;
1446                 }
1447             } else {
1448                 continue;
1449             }
1450
1451
1452             List<Fd_XSTDMX> mxl = this.tdmxper.getbytdlsandcmNo(td.getTd_tdls(), lg.getDepartno());
1453             List<Fd_XSTDMX> rels = new ArrayList<Fd_XSTDMX>();
1454             if (mxl != null) {
1455                 int wfdsl = 0;
1456                 double wfdzl = 0;
1457                 for (Fd_XSTDMX mx : mxl) {
1458                     // 提单明细未关闭的做处理
1459                     wfdsl++;
1460                     wfdzl = BigDecimalfiter.addscal(wfdzl, mx.getTdmx_mz(), Contants.scale);
1461                     mx.setTdmx_fdbz(0);
1462                     mx.setTdmx_fdcph(null);
1463                     mx.setTdmx_fdwlgsbh(null);
1464                     mx.setTdmx_fdywbh(null);
1465                     rels.add(mx);
1466                 }
1467
1468                 this.tdmxper.updatebytdlsandcmNo(td.getTd_tdls(), lg.getDepartno());
1469
1470                 this.vhxper.delbyIDandcomNo(td.getTd_tdbh(),lg.getDepartno());
1471
1472                 td.setTd_wfdsl(td.getTd_wfdsl() + wfdsl);
1473                 td.setTd_wfdzl(BigDecimalfiter.addscal(td.getTd_wfdzl(), wfdzl, Contants.scale));
1474                 this.tdper.updateFD(td);
1475                 if (wfdsl > 0) {
1476                     tdl.add(td);
1477                     mxMp.put(tdNo, rels);
1478                 }
1479             }
1480         }
1481
1482
1483         // 发送NC系统
1484         if (tdl != null && tdl.size() > 0) {
1485             String fdhx = this.fdtonc.getNcdata(tdl, mxMp);
1486             Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "整单取消配车 请求参数 ::" + fdhx);
1487             JsonObject joADDYWD = Wxhtmethod.postJsonStr(Contants.NCfdhx_url, fdhx);
1488             Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "整单取消配车 返回值 ::" + joADDYWD);
1489             if (joADDYWD == null || JSONobj.getint(joADDYWD, "code") != 0) {
1490                 throw new Exception(
1491                         (joADDYWD.get("msg")==null||StringUtils.isBlank(joADDYWD.get("msg").getAsString())) ? "分单回写NC系统出错!"
1492                         : joADDYWD.get("msg").getAsString());
1493             } else {
1494                 String restult = joADDYWD.get("result").getAsString();
1495                 JsonObject jr = jp.parse(restult).getAsJsonObject();
1496                 if (jr == null || JSONobj.getint(jr, "respcode") != 111) {
1497                     throw new Exception(jr.get("respmsg").getAsString());
1498                 }
1499             }
1500         }
1501         orr.setCode(0);
1502         return orr;
1503     }
1504
1505     @Override
1506     @Transactional(rollbackFor = Exception.class)
1507     public ObjectResult<Boolean> sxccCheck(String bsNo, String vehicleId, String ZZ) throws Exception {
1508         ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
1509         Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(),"出门检查 业务参数:::: ::ZZ::" + ZZ + "::bsNo::" + bsNo + "::vehicleId::" + vehicleId);
1510         if (StringUtils.isBlank(vehicleId)) {
1511             orr.setCode(1);
1512             orr.setErrmsg("车牌号为空!");
1513             return orr;
1514         }
1515         if (StringUtils.isBlank(bsNo)) {
1516             orr.setCode(1);
1517             orr.setErrmsg("一卡通业务单号为空!");
1518             return orr;
1519         }
1520         //先删除错误信息
1521         errPer.delBybsNo(bsNo);
1522         try {
1523             Fd_Bsheet fdb = fdbsper.getbybsNo(bsNo);
1524             if (fdb != null) {
1525                 fdb.setStatus(Serviceenum.结束);
1526                 fdbsper.update(fdb);
1527             }
1528             Fd_Vehicle fdv = vhper.getByVehicleId(vehicleId);
1529             if (fdv != null) {
1530                 if (fdv.getType() == VehicleType.临时车) {
1531                     Fd_Bsheet fdbb=this.fdbsper.getbyVehicleWithNoSdepartNo(vehicleId,fdb.getSdepartNo());
1532                     if(fdbb==null) {
1533                         vhper.delByVehicleId(vehicleId);
1534                     }
1535                     this.fdvcper.delbyID(vehicleId, fdb.getSdepartNo());
1536                 } else {
1537                     fdv.setStatus(VehicleStatus.未配车);
1538                     vhper.update(fdv);
1539                     this.fdvcper.delIDandNoC(vehicleId, fdv.getCompanyNo(), fdb.getSdepartNo());
1540                 }
1541             }
1542             // 查找fd_vehicle 判断车辆信息是否正确 修改 fd_vehicle 修改fd_vehicle_company
1543             // 查找fd_bsheet 判断业务状态 修改 fd_bsheet
1544             // 查找fd_xstdmx 表 按照业务单号,车牌号,查找已分单未装车的
1545             // 修改 fd_xstdmx fd_xstd fd_vehicle_xstd
1546
1547             List<Fd_XSTDMX> mxl = this.tdmxper.getbybsNoandNOZCandFD(fdb == null ? "" : fdb.getBsNo());
1548             List<Fd_XSTD> tdl = new ArrayList<Fd_XSTD>();
1549             Map<String, Fd_XSTD> tdM = new HashMap<String, Fd_XSTD>();
1550             Map<String, List<Fd_XSTDMX>> mxMp = new HashMap<String, List<Fd_XSTDMX>>();
1551
1552 //            Map<String, Fd_XSTD> rmtd = new HashMap<String, Fd_XSTD>();
1553             if (mxl != null) {
1554                 for (Fd_XSTDMX mx : mxl) {
1555                     // 已经关闭的明细不做处理
1556                     if (mx.getTdmx_gbbz() != 0) {
1557                         continue;
1558                     }
1559 //                    Fd_XSTD td = this.tdper.get(mx.getTdmx_tdls());
1560 //                    if (td != null) {
1561 //                        td.setTd_wfdsl(td.getTd_wfdsl() + 1);
1562 //                        td.setTd_wfdzl(BigDecimalfiter.addscal(td.getTd_wfdzl(), mx.getTdmx_mz(), Contants.scale));
1563 //                        tdper.updateFD(td);
1564 //                        tdM.put(td.getTd_tdbh(), td);
1565 //                    }
1566                     Fd_XSTD tdtt=tdM.get(mx.getTdmx_tdls());
1567                     if(tdtt==null) {
1568                         tdtt = this.tdper.get(mx.getTdmx_tdls());
1569                         if(tdtt==null) {
1570                             continue;
1571                         }
1572                     }
1573                     tdtt.setTd_wfdsl(tdtt.getTd_wfdsl()+1);
1574                     tdtt.setTd_wfdzl(BigDecimalfiter.addscal(tdtt.getTd_wfdzl(), mx.getTdmx_mz(), Contants.scale));
1575                     tdM.put(mx.getTdmx_tdls(), tdtt);
1576
1577                     mx.setTdmx_fdbz(0);
1578                     mx.setTdmx_fdcph(null);
1579                     mx.setTdmx_fdwlgsbh(null);
1580                     mx.setTdmx_fdywbh(null);
1581 //                    this.tdmxper.updateFD(mx);
1582                     if (mxMp.get(tdtt.getTd_tdbh()) != null) {
1583                         List<Fd_XSTDMX> lr = mxMp.get(tdtt.getTd_tdbh());
1584                         lr.add(mx);
1585                         mxMp.put(tdtt.getTd_tdbh(), lr);
1586                     } else {
1587                         List<Fd_XSTDMX> lr = new ArrayList<Fd_XSTDMX>();
1588                         lr.add(mx);
1589                         mxMp.put(tdtt.getTd_tdbh(), lr);
1590                     }
1591                 }
1592                 this.tdmxper.updatebybsNoandNOZCandFD(fdb.getBsNo());
1593
1594                 this.vhxper.delbyVehicleId(vehicleId,fdb.getBsNo() );
1595
1596                 if (tdM != null && tdM.size() > 0) {
1597                     for (Entry<String, Fd_XSTD> ff : tdM.entrySet()) {
1598                         tdl.add(ff.getValue());
1599                         this.tdper.updateFD(ff.getValue());
1600                     }
1601                 }
1602             }
1603
1604
1605 //            List<Vehicle_XSTD> vxls = this.vhxper.getlistbyVehicleId(vehicleId);
1606 //            if (vxls != null) {
1607 //                for (Vehicle_XSTD vxx : vxls) {
1608 //                    this.vhxper.delbyIDs(vehicleId, vxx.getXstdNo());
1609 //                }
1610 //            }
1611             // 发送NC系统
1612             if (tdl != null && tdl.size() > 0) {
1613                 String fdhx = this.fdtonc.getNcdata(tdl, mxMp);
1614                 Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "出门检查 请求参数 ::" + fdhx);
1615                 JsonObject joADDYWD = Wxhtmethod.postJsonStr(Contants.NCfdhx_url, fdhx);
1616                 Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "出门检查 返回值 ::" + joADDYWD);
1617                 if (joADDYWD == null || JSONobj.getint(joADDYWD, "code") != 0) {
1618                     throw new Exception(
1619                             (joADDYWD.get("msg")==null||StringUtils.isBlank(joADDYWD.get("msg").getAsString())) ? "分单回写NC系统出错!"
1620                             : joADDYWD.get("msg").getAsString());
1621                 } else {
1622                     String restult = joADDYWD.get("result").getAsString();
1623                     JsonParser jp = new JsonParser();
1624                     JsonObject jr = jp.parse(restult).getAsJsonObject();
1625                     if (jr == null || JSONobj.getint(jr, "respcode") != 111) {
1626                         throw new Exception(jr.get("respmsg").getAsString());
1627                     }
1628                 }
1629             }
1630         } catch (Exception e) {
867641 1631             log.error("销售业务车辆出厂程序" + e.getMessage(),e);
58d006 1632             throw new Exception(StringUtils.isEmpty(e.getMessage()) ? "销售业务车辆出厂程序出错!" : e.getMessage());
A 1633         }
1634         orr.setCode(0);
1635         return orr;
1636     }
1637
1638     @Override
1639     @Transactional(rollbackFor = Exception.class)
1640     public ObjectResult<Boolean> doUnbind(Login lg, String mlist, String tdNo) throws Exception {
1641         ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
1642         if (lg == null) {
1643             orr.setCode(1);
1644             orr.setErrmsg("请登录账号!");
1645             return orr;
1646         }
1647         if (StringUtils.isEmpty(mlist)) {
1648             orr.setCode(1);
1649             orr.setErrmsg("业务参数为空!");
1650             return orr;
1651         }
1652         if (StringUtils.isEmpty(tdNo)) {
1653             orr.setCode(1);
1654             orr.setErrmsg("提单编号为空!");
1655             return orr;
1656         }
1657         if (UserType.admin.toString().equals(lg.getWorkerno())) {
1658             orr.setCode(1);
1659             orr.setErrmsg("管理员没有分单权限!");
1660             return orr;
1661         }
1662         Fd_Company fdc = fdcper.getByCompanyNo(lg.getDepartno());
1663         if (fdc == null) {
1664             orr.setCode(1);
1665             orr.setErrmsg("该账号没有配置物流公司!");
1666             return orr;
1667         }
1668
1669         // 查找fd_xstd表 判断物流公司是否有操作权限 如果有装车明细不让删除完
1670         // for循环mlist 判断 fd_xstdmx是否符合条件
1671         // 修改fd_xstdmx 表 修改 vehicle_xstd表 修改fd_company_xstd表:只在取消分单和出门的时候删除
1672         // 修改 fd_xstd 表
1673
1674         Fd_XSTD td = this.tdper.getbyTDBH(tdNo);
1675         if (td == null) {
1676             orr.setCode(1);
1677             orr.setErrmsg("提单未找到!");
1678             return orr;
1679         }
1680         if (td.isTd_zcwcbz()) {
1681             orr.setCode(1);
1682             orr.setErrmsg("该提单已经完成装车,不能分单!");
1683             return orr;
1684         }
1685         // 自提
1686         if (td.getTd_ztbz() == 2) {
1687             if (fdc != null) {
1688                 if (!fdc.isHasSPR()) {
1689                     orr.setCode(1);
1690                     orr.setErrmsg("该账号没有自提权限!");
1691                     return orr;
1692                 }
1693             }
1694         } else {
1695             Fd_wlgs_fhdq wldq = this.dqper.getbyNos(lg.getDepartno(), td.getTd_shddbh(),
1696                     /*td.getTd_ywdybh().equals(Contants.nc_ywdy_ZZ) ? Contants.nc_ywdy_ZZ
1697                             :td.getTd_ywdybh().equals(Contants.nc_ywdy_MS) ? Contants.nc_ywdy_MS
1698                             : Contants.nc_ywdy_KJ*/
1699                     ConvertTool.ncGetDefault(td.getTd_ywdybh())
1700             );
1701
1702             int total = fdMxWlgsMapper.selectCountByTdTdls(td.getTd_tdls());
1703             if (wldq == null && total == 0) {
1704                 orr.setCode(1);
1705                 orr.setErrmsg("当前账号所属物流公司没有配置该地区的分单权限!");
1706                 return orr;
1707             }
1708         }
1709         JsonParser jp = new JsonParser();
1710         JsonArray mArr = jp.parse(mlist).getAsJsonArray();
1711         // 分单数量和毛重
1712         int fdsl = 0;
1713         double fdmz = 0;
1714         List<Fd_XSTD> tdl = new ArrayList<Fd_XSTD>();
1715         Map<String, List<Fd_XSTDMX>> mxMp = new HashMap<String, List<Fd_XSTDMX>>();
1716         List<Fd_XSTDMX> tdmxl = new ArrayList<Fd_XSTDMX>();
1717         Map<String, Fd_XSTD> rm=new HashMap<String, Fd_XSTD>();
1718         for (JsonElement mJe : mArr) {
1719             JsonObject jo = mJe.getAsJsonObject();
1720             // 提单分录号
1721             String tdfl = JSONobj.getstring(jo, "tdfl");
1722             String vehicleId = JSONobj.getstring(jo, "vehicleId");
1723             Fd_XSTDMX mx = this.tdmxper.get(tdfl);
1724             if (mx != null) {
1725                 // 没有分单的跳过
1726                 if (mx.getTdmx_fdbz() == 0) {
1727                     continue;
1728                 }
1729                 // 已经装车的报错
1730                 if (mx.getTdmx_zcbz() != 0) {
1731                     continue;
1732                 }
1733                 // 没有关闭明细做处理
1734                 if (mx.getTdmx_gbbz() == 0) {
1735                     fdsl++;
1736                     fdmz = BigDecimalfiter.addscal(fdmz, mx.getTdmx_mz(), Contants.scale);
1737
1738                     Fd_XSTD ttr=rm.get(vehicleId+"_"+mx.getTdmx_fdwlgsbh());
1739                     if(ttr!=null) {
1740                         ttr.setTd_wfdsl(ttr.getTd_wfdsl()+1);
1741                         ttr.setTd_wfdzl(BigDecimalfiter.addscal(ttr.getTd_wfdzl(), mx.getTdmx_mz(), Contants.scale));
1742                         rm.put(vehicleId+"_"+mx.getTdmx_fdwlgsbh(), ttr);
1743                     }else {
1744                         ttr=new Fd_XSTD();
1745                         ttr.setTd_wfdsl(1);
1746                         ttr.setTd_wfdzl(BigDecimalfiter.addscal(0, mx.getTdmx_mz(), Contants.scale));
1747                         rm.put(vehicleId+"_"+mx.getTdmx_fdwlgsbh(), ttr);
1748                     }
1749                 }
1750
1751                 mx.setTdmx_fdbz(0);
1752                 mx.setTdmx_fdcph(null);
1753                 mx.setTdmx_fdwlgsbh(null);
1754                 mx.setTdmx_fdywbh(null);
1755                 this.tdmxper.updateFD(mx);
1756                 tdmxl.add(mx);
1757
1758             }
1759         }
1760         Iterator<Entry<String, Fd_XSTD>> entries = rm.entrySet().iterator();
1761         while (entries.hasNext()) {
1762           Entry<String, Fd_XSTD> entry = entries.next();
1763           Vehicle_XSTD vxs = this.vhxper.getbyIDs(entry.getKey().split("_")[0], td.getTd_tdbh(),entry.getKey().split("_")[1]);
1764           if (vxs != null) {
1765               if (vxs.getFd_num() == 1) {
1766                   this.vhxper.delbyIDs(entry.getKey().split("_")[0], td.getTd_tdbh(),entry.getKey().split("_")[1]);
1767               } else {
1768                   vxs.setFd_num(vxs.getFd_num() - entry.getValue().getTd_wfdsl());
1769                   vxs.setFd_weight(BigDecimalfiter.subscal(vxs.getFd_weight(), entry.getValue().getTd_wfdzl(), Contants.scale));
1770                   this.vhxper.updatewithIDs(vxs);
1771               }
1772               Fd_Bsheet fb=this.fdbsper.getbyVehicleId(vxs.getVehicleId(), Serviceenum.在办, lg.getSdepartNo());
1773               if(fb !=null) {
1774                 fb.setUpdateTime(new Date());
1775                 this.fdbsper.update(fb);
1776              }
1777           }
1778         }
1779         td.setTd_wfdsl(td.getTd_wfdsl() + fdsl);
1780         td.setTd_wfdzl(BigDecimalfiter.addscal(td.getTd_wfdzl(), fdmz, Contants.scale));
1781         this.tdper.updateFD(td);
1782         if (fdsl > 0) {
1783             tdl.add(td);
1784             mxMp.put(td.getTd_tdbh(), tdmxl);
1785         }
1786
1787         // 发送NC
1788         if (tdl != null && tdl.size() > 0) {
1789             String fdhx = this.fdtonc.getNcdata(tdl, mxMp);
1790             Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "明细取消配车 请求参数 ::" + fdhx);
1791             JsonObject joADDYWD = Wxhtmethod.postJsonStr(Contants.NCfdhx_url, fdhx);
1792             Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "明细取消配车 返回值 ::" + joADDYWD);
1793             if (joADDYWD == null || JSONobj.getint(joADDYWD, "code") != 0) {
1794                 throw new Exception(
1795                         (joADDYWD.get("msg")==null||StringUtils.isBlank(joADDYWD.get("msg").getAsString())) ? "分单回写NC系统出错!"
1796                         : joADDYWD.get("msg").getAsString());
1797             } else {
1798                 String restult = joADDYWD.get("result").getAsString();
1799                 JsonObject jr = jp.parse(restult).getAsJsonObject();
1800                 if (jr == null || JSONobj.getint(jr, "respcode") != 111) {
1801                     throw new Exception(jr.get("respmsg").getAsString());
1802                 }
1803             }
1804         }
1805
1806         orr.setCode(0);
1807         orr.setItem(true);
1808         return orr;
1809     }
1810
1811     @Override
1812     public ObjectResult<String> tzPrint(String cardno, String ipadda,String cqNo) {
1813         ObjectResult<String> orr = new ObjectResult<String>();
1814         if (StringUtils.isBlank(cardno)) {
1815             orr.setCode(1);
1816             orr.setErrmsg("提单编号为空!");
1817             return orr;
1818         }
1819         if (StringUtils.isBlank(ipadda)) {
1820             orr.setCode(1);
1821             orr.setErrmsg("批次号为空!");
1822             return orr;
1823         }
1824         Map<String, Object> cardinuse = this.yktmper.getcardinuse(cardno);
1825         if (cardinuse == null) {
1826             orr.setCode(1);
1827             orr.setErrmsg("在用卡未找到!");
1828             return orr;
1829         }
1830         Fd_Vehicle fd_v = this.vhper.getByVehicleId(cardinuse.get("numberplates") + "");
1831         if (fd_v == null) {
1832             orr.setCode(1);
1833             orr.setErrmsg("车辆" + cardinuse.get("numberplates").toString() + "分单系统未找到!");
1834             return orr;
1835         }
1836         Fd_Bsheet fd_b = this.fdbsper.getbyVehicleId(fd_v.getVehicleId(), Serviceenum.在办, cqNo);
1837         if (fd_b == null) {
1838             orr.setCode(1);
1839             orr.setErrmsg("车辆未找到在办分单!");
1840             return orr;
1841         }
1842         String dyAdd = this.bsper.getUsedbyAdd();
1843         if (StringUtils.isBlank(dyAdd)) {
1844             orr.setCode(1);
1845             orr.setErrmsg("系统未设置打印地址!");
1846             return orr;
1847         }
1848         try {
1849             orr.setItem("http://" + dyAdd + Contants.GYPrintAdd + "&vehicleId="
1850                     + URLEncoder.encode(fd_v.getVehicleId(), "utf-8") + "&bsNo=" + fd_b.getBsNo() + "&phone="
1851                     + fd_b.getPhone() + "&comNo=");
1852             // log.info("::::::::::;"+orr.getItem());
1853         } catch (UnsupportedEncodingException e) {
1854             e.printStackTrace();
1855         }
1856         // 存打印日志:方便以后查找
1857
1858         orr.setCode(0);
1859         return orr;
1860
1861     }
1862
1863     @Override
1864     @Transactional(rollbackFor = Exception.class)
1865     public ObjectResult<Boolean> delbyPCH(Login lg, String tdNo, String pch, String cph,String bsNo) throws Exception {
1866         ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
1867         if (lg == null) {
1868             orr.setCode(1);
1869             orr.setErrmsg("请登录账号!");
1870             return orr;
1871         }
1872         if (StringUtils.isEmpty(tdNo)) {
1873             orr.setCode(1);
1874             orr.setErrmsg("提单编号为空!");
1875             return orr;
1876         }
1877         if (StringUtils.isEmpty(pch)) {
1878             orr.setCode(1);
1879             orr.setErrmsg("批次号为空!");
1880             return orr;
1881         }
1882         Fd_Bsheet fdb = this.fdbsper.getbybsNo(bsNo);//getbyVehicleId(cph, Serviceenum.在办);
1883         if (fdb == null) {
1884             orr.setCode(1);
1885             orr.setErrmsg("车牌号:" + cph + " 业务单未找到!");
1886             return orr;
1887         }
1888         if (fdb.getStatus()!=Serviceenum.在办) {
1889             orr.setCode(1);
1890             orr.setErrmsg("车牌号:" + cph + " 业务单不是在办状态!");
1891             return orr;
1892         }
1893         Fd_Company fdc = fdcper.getByCompanyNo(lg.getDepartno());
1894         if (fdc == null) {
1895             orr.setCode(1);
1896             orr.setErrmsg("账号没有配置物流公司!");
1897             return orr;
1898         }
1899         // 根据提单号找到 fd_xstd 判断xstd数据
1900         // 根据批次号和提单流水号找到 fd_xstdmx 判断xstdmx数据
1901         // 如果是已经装车了 至少保留一件
1902         // 修改fd_xstdmx vehicle_xstd表
1903         Fd_XSTD td = this.tdper.getbyTDBH(tdNo);
1904         if (td == null) {
1905             orr.setCode(1);
1906             orr.setErrmsg("提单号:" + tdNo + " 未找到!");
1907             return orr;
1908         }
1909         // Fd_XSTDMX mx=this.tdmxper.getbyPCH(pch);
1910         Fd_XSTDMX mx = this.tdmxper.getbyPCHandTDNOONE(pch, td.getTd_tdbh());
1911         if (mx == null) {
1912             orr.setCode(1);
1913             orr.setErrmsg("提单明细未找到!");
1914             return orr;
1915         }
1916         if (mx.getTdmx_zcbz() != 0) {
1917             orr.setCode(1);
1918             orr.setErrmsg("明细已经装车不能删除!");
1919             return orr;
1920         }
1921         if (!mx.getTdmx_tdls().equals(td.getTd_tdls())) {
1922             orr.setCode(1);
1923             orr.setErrmsg("参数错误,明细不属于该提单!");
1924             return orr;
1925         }
1926         // 已经分单了未关闭
1927         if (mx.getTdmx_fdbz() != 0 && mx.getTdmx_gbbz() == 0) {
1928             fdb.setUpdateTime(new Date());
1929             this.fdbsper.update(fdb);
1930             List<Fd_XSTD> tdl = new ArrayList<Fd_XSTD>();
1931             Map<String, List<Fd_XSTDMX>> mxMp = new HashMap<String, List<Fd_XSTDMX>>();
1932             List<Fd_XSTDMX> mxl = new ArrayList<Fd_XSTDMX>();
1933
1934             mx.setTdmx_fdbz(0);
1935             mx.setTdmx_fdcph(null);
1936             mx.setTdmx_fdwlgsbh(null);
1937             mx.setTdmx_fdywbh(null);
1938             this.tdmxper.updateFD(mx);
1939             Vehicle_XSTD vx = this.vhxper.getbyIDs(cph, tdNo,lg.getDepartno());
1940             if (vx != null) {
1941                 if (vx.getFd_num() > 1) {
1942                     vx.setFd_num(vx.getFd_num() - 1);
1943                     vx.setFd_weight(BigDecimalfiter.subscal(vx.getFd_weight(), mx.getTdmx_mz(), Contants.scale));
1944                     this.vhxper.updatewithIDs(vx);
1945                 } else {
1946                     this.vhxper.delbyIDs(cph, tdNo,lg.getDepartno());
1947                 }
1948             }
1949             td.setTd_wfdsl(td.getTd_wfdsl() + 1);
1950             td.setTd_wfdzl(BigDecimalfiter.addscal(td.getTd_wfdzl(), mx.getTdmx_mz(), Contants.scale));
1951             this.tdper.updateFD(td);
1952             tdl.add(td);
1953             mxl.add(mx);
1954             mxMp.put(tdNo, mxl);
1955             // 发送NC
1956             if (tdl != null && tdl.size() > 0) {
1957                 String fdhx = this.fdtonc.getNcdata(tdl, mxMp);
1958                 Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "批次号取消配车 请求参数 ::" + fdhx);
1959                 JsonObject joADDYWD = Wxhtmethod.postJsonStr(Contants.NCfdhx_url, fdhx);
1960                 Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "批次号取消配车 返回值 ::" + joADDYWD);
1961                 if (joADDYWD == null || JSONobj.getint(joADDYWD, "code") != 0) {
1962                     throw new Exception(
1963                             (joADDYWD.get("msg")==null||StringUtils.isBlank(joADDYWD.get("msg").getAsString())) ? "分单回写NC系统出错!"
1964                             : joADDYWD.get("msg").getAsString());
1965                 } else {
1966                     String restult = joADDYWD.get("result").getAsString();
1967                     JsonParser jp = new JsonParser();
1968                     JsonObject jr = jp.parse(restult).getAsJsonObject();
1969                     if (jr == null || JSONobj.getint(jr, "respcode") != 111) {
1970                         throw new Exception(jr.get("respmsg").getAsString());
1971                     }
1972                 }
1973             }
1974
1975         }
1976
1977         orr.setCode(0);
1978         orr.setItem(true);
1979         return orr;
1980     }
1981
1982     @Override
1983     @Transactional(rollbackFor = Exception.class)
1984     public ObjectResult<Boolean> closeXstd(String vehicleId, String driver, String phone, String xstdNo, Login lg)
1985             throws Exception {
1986         ObjectResult<Boolean> or = new ObjectResult<Boolean>();
1987         if (lg == null) {
1988             or.setCode(1);
1989             or.setErrmsg("请重新登录账号!");
1990             return or;
1991         }
1992         // 根据xstdNo查找fd_xstd信息 vehicle_xstd
1993         // 判断vehicle_xstd的销售提单的状态
1994         // 查找fd_xstdmx
1995         // for循环 list<fd_xstdmx> 获取未分单未装车
1996         // 修改fd_xstdmx 修改Fd_Gbxstd, Fd_Gbxstdmx,修改fd_xstd
1997         if (StringUtils.isEmpty(xstdNo)) {
1998             or.setCode(1);
1999             or.setErrmsg("销售提单号为空,不能执行该操作!");
2000             return or;
2001         }
2002         if (!StringUtils.isEmpty(vehicleId)) {
2003             if (!RegexCheck.isVehicleID(vehicleId)) {
2004                 or.setCode(1);
2005                 or.setErrmsg("请输入正确的车牌号!");
2006                 return or;
2007             }
2008         }
2009         if (!StringUtils.isEmpty(phone)) {
2010             if (!RegexCheck.checkphone(phone)) {
2011                 or.setCode(1);
2012                 or.setErrmsg("请输入正确的手机号!");
2013                 return or;
2014             }
2015         }
2016
2017         Fd_Gbxstd gbtd = gbtdper.get(xstdNo);
2018         if (gbtd != null) {
2019             or.setCode(1);
2020             or.setErrmsg("销售提单:" + xstdNo + " 已经有关闭记录,不能保存重复的关闭记录!");
2021             return or;
2022         }
2023         List<Vehicle_XSTD> vxl = vhxper.getlistbytdNo(xstdNo);
2024         if (vxl != null && vxl.size() > 0) {
2025             or.setCode(1);
2026             or.setErrmsg("销售提单:" + xstdNo + " 已经分单给:" + vxl.get(0).getVehicleId() + ",不能执行该操作!");
2027             return or;
2028         }
2029         Fd_XSTD tdx = this.tdper.getbyttdbh(xstdNo);
2030         if (tdx == null) {
2031             or.setCode(1);
2032             or.setErrmsg("销售提单:" + xstdNo + "未找到,不能执行该操作!");
2033             return or;
2034         }
2035         Fd_Company fdc = new Fd_Company();
2036         if (!UserType.admin.toString().equals(lg.getWorkerno())) {
2037             fdc = fdcper.getByCompanyNo(lg.getDepartno());
2038             if (fdc == null) {
2039                 or.setCode(1);
2040                 or.setErrmsg("登录账号未指定物流公司!");
2041                 return or;
2042             }
2043             // 自提
2044             if (tdx.getTd_ztbz() == 2) {
2045                 if (!fdc.isHasSPR()) {
2046                     or.setCode(1);
2047                     or.setErrmsg("该账号没有操作该提单的权限!");
2048                     return or;
2049                 }
2050             } else {
2051                 String shdqbh = tdx.getTd_shddbh();
2052                 Fd_wlgs_fhdq acb = this.dqper.getbyNos(lg.getDepartno(), shdqbh,
2053                         /*tdx.getTd_ywdybh().equals(Contants.nc_ywdy_ZZ) ? Contants.nc_ywdy_ZZ
2054                                 :tdx.getTd_ywdybh().equals(Contants.nc_ywdy_MS) ? Contants.nc_ywdy_MS
2055                                 : Contants.nc_ywdy_KJ*/
2056                     ConvertTool.ncGetDefault(tdx.getTd_ywdybh())
2057                 );
2058
2059                 int total = fdMxWlgsMapper.selectCountByTdTdls(tdx.getTd_tdls());
2060                 if (acb == null && total == 0) {
2061                     or.setCode(1);
2062                     or.setErrmsg("账号没有操作该提单的权限!");
2063                     return or;
2064                 }
2065             }
2066         }
2067
2068         List<Fd_XSTDMX> mxL = this.tdmxper.getforClose(tdx.getTd_tdls());
2069         int dd = 0;
2070         double cc = 0;
2071         if (mxL != null) {
2072             for (Fd_XSTDMX mx : mxL) {
2073                 dd++;
2074                 cc = BigDecimalfiter.addscal(cc, mx.getTdmx_mz(), Contants.scale);
2075                 mx.setTdmx_zcbz(1);
2076                 mx.setTdmx_zccph(vehicleId);
2077                 mx.setTdmx_zcdriver(driver);
2078                 mx.setTdmx_zcphone(phone);
2079                 mx.setTdmx_zcwlgsName(lg.getDepartname());
2080                 this.tdmxper.updateZCANDFD(mx);
2081                 Fd_Gbxstdmx gb = this.gbtdmxper.get(mx.getTdmx_tdfl());
2082                 if (gb == null) {
2083                     gb = new Fd_Gbxstdmx();
2084                     gb.setId(mx.getTdmx_tdfl());
2085                     gb.setTdfl(mx.getTdmx_tdfl());
2086                     gb.setPch(mx.getTdmx_pch());
2087                     gb.setTdNo(tdx.getTd_tdbh());
2088                     this.gbtdmxper.insert(gb);
2089                 }
2090             }
2091         }
2092         tdx.setTd_wfdsl(0);
2093         tdx.setTd_wfdzl(0);
2094         this.tdper.updateFD(tdx);
2095         if (dd > 0) {
2096             gbtd = new Fd_Gbxstd();
2097             gbtd.setCompanyNo(lg.getDepartname() == null ? "管理员关闭" : lg.getDepartname());
2098             gbtd.setHSR(tdx.getTd_ztbz() == 2);
2099             gbtd.setTd_gbr(lg.getWorkername());
2100             gbtd.setTd_gbsj(new Date());
2101             gbtd.setTd_gbsl(dd);
2102             gbtd.setTd_gbzl(cc);
2103             gbtd.setVehicleId(vehicleId);
2104             gbtd.setXstdNo(xstdNo);
2105             this.gbtdper.insert(gbtd);
2106         }
2107
2108         or.setCode(0);
2109         return or;
2110     }
2111
2112     @Override
2113     @Transactional(rollbackFor = Exception.class)
2114     public ObjectResult<Boolean> openXstd(String xstdNo, Login lg) throws Exception {
2115
2116         ObjectResult<Boolean> or = new ObjectResult<Boolean>();
2117         if (lg == null) {
2118             or.setCode(1);
2119             or.setErrmsg("请重新登录账号!");
2120             return or;
2121         }
2122         if (StringUtils.isEmpty(xstdNo)) {
2123             or.setCode(1);
2124             or.setErrmsg("销售提单号为空,不能执行该操作!");
2125             return or;
2126         }
2127         // 关闭之后不让打开了
2128
2129         // 根据xstdNo查找fd_xstd信息 vehicle_xstd
2130         // 判断vehicle_xstd的销售提单的状态
2131         // 查找fd_xstdmx
2132         // for循环 list<fd_xstdmx> 获取未分单未装车
2133         // 修改fd_xstdmx 修改Fd_Gbxstd, Fd_Gbxstdmx,修改fd_xstd
2134
2135         Fd_Gbxstd gbtd = gbtdper.get(xstdNo);
2136         if (gbtd == null) {
2137             or.setCode(1);
2138             or.setErrmsg("销售提单:" + xstdNo + " 未找到关闭记录,不能恢复销售提单!");
2139             return or;
2140         }
2141         if (BasicMethod.after(gbtd.getTd_gbsj(), 7)) {
2142             or.setCode(1);
2143             or.setErrmsg("已关闭超过7天,不能恢复提单!");
2144             return or;
2145         }
2146         List<Vehicle_XSTD> vxl = vhxper.getlistbytdNo(xstdNo);
2147         if (vxl != null && vxl.size() > 0) {
2148             or.setCode(1);
2149             or.setErrmsg("销售提单:" + xstdNo + " 有在办的分车单,不能执行该操作!");
2150             return or;
2151         }
2152         Fd_XSTD tdx = this.tdper.getbyttdbh(xstdNo);
2153         if (tdx == null) {
2154             or.setCode(1);
2155             or.setErrmsg("销售提单:" + xstdNo + "未找到,不能执行该操作!");
2156             return or;
2157         }
2158         Fd_Company fdc = new Fd_Company();
2159         if (!UserType.admin.toString().equals(lg.getWorkerno())) {
2160             fdc = fdcper.getByCompanyNo(lg.getDepartno());
2161             if (fdc == null) {
2162                 or.setCode(1);
2163                 or.setErrmsg("登录账号未指定物流公司!");
2164                 return or;
2165             }
2166             // 自提
2167             if (tdx.getTd_ztbz() == 2) {
2168                 if (!fdc.isHasSPR()) {
2169                     or.setCode(1);
2170                     or.setErrmsg("该账号没有操作该提单的权限!");
2171                     return or;
2172                 }
2173             } else {
2174                 String shdqbh = tdx.getTd_shddbh();
2175                 Fd_wlgs_fhdq acb = this.dqper.getbyNos(lg.getDepartno(), shdqbh,
2176                         /*tdx.getTd_ywdybh().equals(Contants.nc_ywdy_ZZ) ? Contants.nc_ywdy_ZZ
2177                                 :tdx.getTd_ywdybh().equals(Contants.nc_ywdy_MS) ? Contants.nc_ywdy_MS
2178                                 : Contants.nc_ywdy_KJ*/
2179                         ConvertTool.ncGetDefault(tdx.getTd_ywdybh())
2180                 );
2181                 int total = fdMxWlgsMapper.selectCountByTdTdls(tdx.getTd_tdls());
2182                 if (acb == null && total == 0) {
2183                     or.setCode(1);
2184                     or.setErrmsg("该账号没有操作该提单的权限!");
2185                     return or;
2186                 }
2187             }
2188         }
2189
2190         List<Fd_Gbxstdmx> mxL = this.gbtdmxper.getList(xstdNo);
2191         int dd = 0;
2192         if (mxL != null) {
2193             for (Fd_Gbxstdmx mx : mxL) {
2194                 Fd_XSTDMX tdmx = this.tdmxper.getbytdflAndtdls(mx.getId(), tdx.getTd_tdls());
2195                 tdmx.setTdmx_zcbz(0);
2196                 tdmx.setTdmx_zccph(null);
2197                 tdmx.setTdmx_zcdriver(null);
2198                 tdmx.setTdmx_zcphone(null);
2199                 tdmx.setTdmx_zcwlgsName(null);
2200                 dd++;
2201                 this.tdmxper.updateZCANDFD(tdmx);
2202                 this.gbtdmxper.delbyId(mx.getId());
2203             }
2204         }
2205         if (dd > 0) {
2206             tdx.setTd_wfdsl(gbtd.getTd_gbsl());
2207             tdx.setTd_wfdzl(gbtd.getTd_gbzl());
2208             this.tdper.updateFD(tdx);
2209             this.gbtdper.del(xstdNo);
2210         }
2211
2212         or.setCode(0);
2213         return or;
2214     }
2215
2216     @Override
2217     @Transactional(rollbackFor = Exception.class)
2218     @Deprecated
2219     public ObjectResult<Boolean> changeVehicle(Login lg, String bsNo, String vehicleInfo) throws Exception {
2220         ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
2221         if (lg == null) {
2222             orr.setCode(1);
2223             orr.setErrmsg("请登录账号!");
2224             return orr;
2225         }
2226         if (true) {
2227             orr.setCode(1);
2228             orr.setErrmsg("该方法不可用!");
2229             return orr;
2230         }
2231         if (UserType.admin.toString().equals(lg.getWorkerno())) {
2232             orr.setCode(1);
2233             orr.setErrmsg("管理员不能执行该操作!");
2234             return orr;
2235         }
2236         if (StringUtils.isEmpty(bsNo) || StringUtils.isEmpty(vehicleInfo)) {
2237             orr.setCode(1);
2238             orr.setErrmsg("业务参数为空!");
2239             return orr;
2240         }
2241         Fd_Bsheet fdb = fdbsper.getbybsNo(bsNo);
2242         if (fdb == null) {
2243             orr.setCode(1);
2244             orr.setErrmsg("业务单未找到!");
2245             return orr;
2246         }
2247         String vehicleId = fdb.getVehicleId();
2248         Fd_Vehicle fdv = vhper.getByVehicleId(vehicleId);
2249         if (fdv == null) {
2250             orr.setCode(1);
2251             orr.setErrmsg("原来的车牌未找到!");
2252             return orr;
2253         }
2254         JsonParser jp = new JsonParser();
2255         JsonElement je = jp.parse(vehicleInfo);
2256         JsonObject jo = je.getAsJsonObject();
2257         String nvehicleId = JSONobj.getstring(jo, "vehicleId");
2258         String driver = JSONobj.getstring(jo, "driver");
2259         String phone = JSONobj.getstring(jo, "phone");
2260         double vehicleweight = JSONobj.getdouble(jo, "vehicleweight");
2261         double loadweight = JSONobj.getdouble(jo, "loadweight");
2262         String feature = JSONobj.getstring(jo, "feature");
2263         String note = JSONobj.getstring(jo, "note");
2264         String IDNum = JSONobj.getstring(jo, "IDNum");
2265         if (StringUtils.isEmpty(vehicleId) || StringUtils.isEmpty(driver) || StringUtils.isEmpty(IDNum)
2266                 || StringUtils.isEmpty(phone)) {
2267             orr.setCode(1);
2268             orr.setErrmsg("车辆必填信息不能为空!");
2269             return orr;
2270         }
2271         Fd_Vehicle nfdv = vhper.getByVehicleId(nvehicleId);
2272         if (nfdv != null && nfdv.getStatus() != VehicleStatus.未配车) {
2273             orr.setCode(1);
2274             orr.setErrmsg("车辆:" + nvehicleId + "状态不是未配车状态,不能使用!");
2275             return orr;
2276         }
2277
2278         // 临时车直接删除
2279         if (fdv.getType() == VehicleType.临时车) {
2280             vhper.delByVehicleId(fdv.getVehicleId());
2281         } else {
2282             fdv.setStatus(VehicleStatus.未配车);
2283             vhper.update(fdv);
2284         }
2285
2286         // 修改vehicle_xstd表
2287         List<Vehicle_XSTD> lc = vhxper.getlistbycomNo(lg.getDepartno());
2288         // List<Vehicle_XSTD> lc=vhxper.getlistbyVehicleId(fdv.getVehicleId());
2289         if (lc != null) {
2290             for (Vehicle_XSTD vx : lc) {
2291                 if (vx.getVehicleId().equals(fdv.getVehicleId())) {
2292                     vx.setVehicleId(nvehicleId);
2293                     vhxper.updatewithIDs(vx);
2294                 }
2295             }
2296         }
2297         if (nfdv == null) {
2298             nfdv = new Fd_Vehicle();
2299             nfdv.setCompanyNo(lg.getDepartno());
2300             nfdv.setDriver(driver);
2301             nfdv.setId(UUID.randomUUID() + "");
2302             nfdv.setLoadweight(loadweight);
2303             nfdv.setNote(note);
2304             nfdv.setPhone(phone);
2305             nfdv.setState(true);
2306             nfdv.setFeature(feature);
2307             nfdv.setStatus(VehicleStatus.已配车);
2308             nfdv.setType(VehicleType.临时车);
2309             nfdv.setVehicleId(nvehicleId);
2310             nfdv.setVehicleweight(vehicleweight);
2311             nfdv.setIDNum(IDNum);
2312             vhper.insert(nfdv);
2313         }
2314
2315         // 换车用不用发送短信
2316
2317         orr.setCode(0);
2318         orr.setItem(true);
2319         return orr;
2320     }
2321
2322     @Override
2323     @Transactional(rollbackFor = Exception.class)
2324     @Deprecated
2325     public ObjectResult<Boolean> saveZcInfo(Scxt_zcInfo zc) throws Exception {
2326         ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
2327         if (zc == null) {
2328             orr.setCode(1);
2329             orr.setErrmsg("参数为空不能保存!");
2330             return orr;
2331         }
2332         if (true) {
2333             orr.setCode(1);
2334             orr.setErrmsg("该方法已作废!");
2335             return orr;
2336         }
2337         String zcvehicleID = zc.getCph();// 车牌号
2338         String pch = zc.getPch();// 批次号
2339         String tdbh = zc.getTdbh();// 提单编号
2340         Fd_Vehicle fdv = vhper.getByVehicleId(zcvehicleID);
2341         if (fdv == null) {
2342             orr.setCode(1);
2343             orr.setErrmsg("分单系统未找到该车牌号!");
2344             return orr;
2345         }
2346         Map<String, Object> bsmp =null;// bsper.getbsbyBt(zcvehicleID, Contants.cpxsBtNo, Serviceenum.在办,Contants.kjSdepartNo);
2347         if (bsmp == null) {
2348             orr.setCode(1);
2349             orr.setErrmsg("该车辆没有找到一卡通业务单!");
2350             return orr;
2351         }
2352         String dbsign = tdbh.split("-")[0];
2353         // Fd_Erpconfig erpdb=erpper.getbySign(dbsign);
2354         // if(erpdb==null){
2355         // orr.setCode(1);
2356         // orr.setErrmsg("根据提单编号未找到配置的数据库数据源!");
2357         // return orr;
2358         // }
2359         // Map<String, Object> bsim=bsper.getbsi(pch, bsmp.get("bussinessNo")+"" );
2360         // if(bsim!=null){
2361         // orr.setCode(1);
2362         // orr.setErrmsg("该成品已经装车!");
2363         // return orr;
2364         // }
2365         // try {
2366         // String
2367         // url="jdbc:jtds:sqlserver://"+erpdb.getUri()+":"+erpdb.getPost()+";databaseName="+erpdb.getDb();
2368         // Connection con=ddbdao.open(url, erpdb.getUsername(),
2369         // erpdb.getPwd(),erpdb.getDbsign());
2370         // if(con==null){
2371         // ddbdao.close();
2372         // orr.setCode(1);
2373         // orr.setErrmsg("erp数据库链接失败,请查询erp配置是否正确!");
2374         // return orr;
2375         // }
2376         // String sql=SqlTxt.GYErpXSTDsql+" where EXISTS (SELECT 1 FROM XSTDMX WHERE
2377         // XSTDMX_TDLS=XSTD_TDLS AND XSTDMX_CKBZ='0') and a.XSTD_TDBH='"+tdbh+"' and
2378         // a.XSTD_SHBZ=1 and a.XSTD_TDBZ='LD' ";
2379         // Map<String, Object> tdmp=ddbdao.getmapnoclose(sql,erpdb.getDbsign());
2380         // if(tdmp==null){
2381         // orr.setCode(1);
2382         // orr.setErrmsg("销售提单未找到!");
2383         // ddbdao.close();
2384         // return orr;
2385         // }
2386         // WaitXSTD wt=new WaitXSTD();
2387         // BeanUtils.populate(wt, tdmp);
2388         //
2389         // //判断该车辆有没有操作该提单的权限
2390         // if(true){
2391         //
2392         // }
2393         // sql=SqlTxt.GYErpXSTDMXsql+" where b.XSTDMX_CKBZ='0' and
2394         // a.XSTD_TDBH='"+tdbh+"' and b.XSTDMX_PCH='"+pch+"' ";//销售提单明细
2395         // Map<String, Object> mxmp=ddbdao.getmapnoclose(sql,erpdb.getDbsign());
2396         // if(mxmp==null){
2397         // orr.setCode(1);
2398         // orr.setErrmsg("根据提单号和批次号Erp未找到销售提单明细!");
2399         // ddbdao.close();
2400         // return orr;
2401         // }
2402         // WaitXSTDMX wtdmx=new WaitXSTDMX();
2403         // BeanUtils.populate(wtdmx, mxmp);
2404         // String hj=mxmp.get("hj")==null?"":mxmp.get("hj")+"";
2405         // String zt=mxmp.get("zt")==null?"":mxmp.get("zt")+"";
2406         // wtdmx.setTdmx_hjzt(hj+"/"+zt);
2407         // //如果扫的是没有分单的
2408         // if(wtdmx.getTdmx_fdbz()==0){
2409         // sql=SqlTxt.XGGYErpXSTDMXsql+" where a.XSTDMX_CKBZ='0' and
2410         // b.XSTD_TDBH='"+tdbh+"' and a.XSTDMX_PCH='"+pch+"' ";//修改销售提单明细
2411         // List<Object> ll=new ArrayList<Object>();
2412         // ll.add(zcvehicleID);//车牌号
2413         // ll.add(2);//分单标志
2414         // ll.add(bsmp.get("bussinessNo")+"");//分单单据编号
2415         // ddbdao.modifySql(sql, ll,erpdb.getDbsign());
2416         //
2417         // sql=SqlTxt.XGGYErpXSTDsql;//修改销售提单
2418         // ll.clear();
2419         // ll.add(wt.getTd_wfdsl()-1);//未分单数量
2420         // ll.add(BigDecimalfiter.subscal(wt.getTd_wfdzl(), wtdmx.getTdmx_mz(),
2421         // Contants.scale));//未分单毛重
2422         // ll.add(tdbh);
2423         // ddbdao.modifySql(sql, ll,erpdb.getDbsign());
2424         // }
2425         //
2426         // if(fdv.getStatus()!=VehicleStatus.已装车){
2427         // fdv.setStatus(VehicleStatus.已装车);
2428         // vhper.update(fdv);
2429         // }
2430         // Fd_Bsheetitem fbi=bsiper.getbyLsandFl(wtdmx.getTdmx_tdls(),
2431         // wtdmx.getTdmx_tdfl(),tdbh);
2432         // //该车辆有没有添加
2433         // Vehicle_XSTD vhx=vhxper.getbyIDs(zcvehicleID, tdbh);
2434         // //已经分单
2435         // if(fbi!=null){
2436         // //未分到当前车辆
2437         // if(!fbi.getTdmx_cph().equals(zcvehicleID)){
2438         // Vehicle_XSTD vhx1=vhxper.getbyIDs(zcvehicleID, tdbh);
2439         // //该车辆已添加销售提单
2440         // if(vhx!=null){
2441         // vhx.setFd_num(vhx.getFd_num()+1);
2442         // vhx.setFd_weight(BigDecimalfiter.addscal(vhx.getFd_weight(),wtdmx.getTdmx_mz()
2443         // ,Contants.scale ));
2444         // vhxper.update(vhx);
2445         // }else{
2446         // vhx=new Vehicle_XSTD();
2447         // vhx.setFd_num(1);
2448         // vhx.setFd_weight(BigDecimalfiter.addscal(wtdmx.getTdmx_mz(), 0,
2449         // Contants.scale));
2450         // vhx.setVehicleId(zcvehicleID);
2451         // vhx.setXstdNo(tdbh);
2452         // vhx.setBsNo( bsmp.get("bussinessNo")+"");
2453         // vhxper.insert(vhx);
2454         // }
2455         // if(vhx1.getFd_num()==1){
2456         // vhxper.delbyIDs(vhx1.getVehicleId(), vhx1.getXstdNo());
2457         // }else{
2458         // vhx1.setFd_num(vhx1.getFd_num()-1);
2459         // vhx1.setFd_weight(BigDecimalfiter.subscal(vhx1.getFd_weight(),
2460         // wtdmx.getTdmx_mz(), Contants.scale));
2461         // vhxper.update(vhx1);
2462         // }
2463         // fbi.setTdmx_cph(zcvehicleID);
2464         // }
2465         //// fbi.setTdmx_cph(zcvehicleID);
2466         // fbi.setTdmx_tdbh(tdbh);
2467         // fbi.setTdmx_fdbz(2);
2468         // fbi.setTdmx_fdywbh(bsmp.get("bussinessNo")+"" );
2469         // fbi.setTdmx_zccph(zcvehicleID);
2470         // fbi.setTdmx_sfzc(1);
2471         // fbi.setBarcode(zc.getTmh());
2472         // bsiper.update(fbi);
2473         // }else{
2474         // fbi=new Fd_Bsheetitem();
2475         // fbi.setId(UUID.randomUUID()+"");
2476         // fbi.setCompanyName("");
2477         // fbi.setCompanyNo("");
2478         // fbi.setCreateid("");
2479         // fbi.setBarcode(zc.getTmh());
2480         // fbi.setCtime(new Date());
2481         // fbi.setTdmx_cph(zcvehicleID);
2482         // fbi.setTdmx_tdbh(tdbh);
2483         // fbi.setTdmx_fdbz(2);
2484         // fbi.setTdmx_fdywbh(bsmp.get("bussinessNo")+"" );
2485         // fbi.setTdmx_zccph(zcvehicleID);
2486         // fbi.setTdmx_sfzc(1);
2487         // bsiper.insert(fbi);
2488         // //该装车车辆添加了这个提单的分单
2489         // if(vhx!=null){
2490         // vhx.setFd_num(vhx.getFd_num()+1);
2491         // vhx.setFd_weight(BigDecimalfiter.addscal(vhx.getFd_weight(),wtdmx.getTdmx_mz()
2492         // ,Contants.scale ));
2493         // vhxper.update(vhx);
2494         // }else{
2495         // vhx=new Vehicle_XSTD();
2496         // vhx.setFd_num(1);
2497         // vhx.setFd_weight(BigDecimalfiter.addscal(wtdmx.getTdmx_mz(), 0,
2498         // Contants.scale));
2499         // vhx.setVehicleId(zcvehicleID);
2500         // vhx.setXstdNo(tdbh);
2501         // vhxper.insert(vhx);
2502         // }
2503         // }
2504         //
2505         //
2506         //
2507         // //添加一卡通明细;
2508         // Map<String, Object> mm=new HashMap<String, Object>();
2509         // mm.put("id", UUID.randomUUID()+"");
2510         // mm.put("bussinessNo",bsmp.get("bussinessNo")+"" );
2511         // mm.put("name", wtdmx.getTdmx_wlmc());
2512         // mm.put("materielNo",wtdmx.getTdmx_wlbh() );
2513         // mm.put("norms",wtdmx.getTdmx_ggxh() );
2514         // mm.put("unitname", "Kg");
2515         // mm.put("num", 1);
2516         // mm.put("note", null);
2517         // mm.put("weight", BigDecimalfiter.mulcon(wtdmx.getTdmx_jz(), 1000,
2518         // Contants.scale));
2519         // mm.put("price", 0);
2520         // mm.put("preweight",BigDecimalfiter.mulcon(wtdmx.getTdmx_jz(), 1000,
2521         // Contants.scale));
2522         // mm.put("pici", pch);
2523         // mm.put("hejin", wtdmx.getTdmx_hjzt());
2524         // mm.put("gross",BigDecimalfiter.mulcon(wtdmx.getTdmx_mz(), 1000,
2525         // Contants.scale) );
2526         // mm.put("taotong","" );
2527         // mm.put("taotongWeight", BigDecimalfiter.subscal(wtdmx.getTdmx_mz()*1000,
2528         // wtdmx.getTdmx_jz()*1000, Contants.scale));
2529         // mm.put("money", 0);
2530         //
2531         //// mm.put("createid", );
2532         //// mm.put("cname", );
2533         //// mm.put("createid", 0);
2534         // mm.put("cdepartid", 0);
2535         //// mm.put("cdepart", );
2536         // mm.put("ctime", new Date());
2537         //
2538         // mm.put("loadbuild", false);
2539         // mm.put("factory", false);
2540         // mm.put("fachang", true);
2541         // mm.put("fcnum", 0);
2542         // mm.put("product_billNo", tdbh);
2543         // mm.put("product_serialNo",wtdmx.getTdmx_tdls());
2544         // mm.put("product_otherNo", null);
2545         //// mm.put("product_ywrq",wtdmx.gettdmx_ );
2546         // mm.put("product_flh", wtdmx.getTdmx_tdfl());
2547         // mm.put("recompany",wtdmx.getTdmx_shdw() );
2548         //// mm.put("reID", "");
2549         // mm.put("decompany", wtdmx.getTdmx_fhdw()==null?"明泰科技":wtdmx.getTdmx_fhdw());
2550         //// mm.put("deID", "");
2551         // mm.put("rcompany",wtdmx.getTdmx_shdw() );
2552         //// mm.put("rID", );
2553         // mm.put("frombatch", "ERP系统");
2554         // mm.put("forshowindx",1 );
2555         // mm.put("barcode",zc.getTmh());
2556         // mm.put("reserved11",0 );
2557         // mm.put("reserved12",0 );
2558         // mm.put("reserved13",0 );
2559         // mm.put("jsnum",0 );
2560         //
2561         // bsper.insertBsi(mm);
2562         // } catch (Exception e) {
2563         // ddbdao.robackclose();
2564         // throw new
2565         // Exception(StringUtils.isEmpty(e.getMessage())?"添加装车信息出错!":e.getMessage());
2566         // }finally{
2567         // ddbdao.close();
2568         // }
2569
2570         orr.setCode(0);
2571         orr.setItem(true);
2572         return orr;
2573     }
2574
2575     @Override
2576     @Transactional(rollbackFor = Exception.class)
2577     @Deprecated
2578     public ObjectResult<Boolean> sxinCheck(String bsNo, String vehicleId) throws Exception {
2579         ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
2580         if (StringUtils.isEmpty(vehicleId)) {
2581             orr.setCode(1);
2582             orr.setErrmsg("车牌号为空!");
2583             return orr;
2584         }
2585         if (StringUtils.isEmpty(bsNo)) {
2586             orr.setCode(1);
2587             orr.setErrmsg("一卡通业务单号为空!");
2588             return orr;
2589         }
2590         if (true) {
2591             orr.setCode(1);
2592             orr.setErrmsg("该方法已经弃用!");
2593             return orr;
2594         }
2595         Fd_Bsheet fdb = fdbsper.getbybsNo(bsNo);
2596         if (fdb == null) {
2597             orr.setCode(1);
2598             orr.setErrmsg("业务单未找到!");
2599             return orr;
2600         }
2601         Fd_Vehicle fdv = vhper.getByVehicleId(vehicleId);
2602         if (fdv == null) {
2603             orr.setCode(1);
2604             orr.setErrmsg("业务车辆未找到!");
2605             return orr;
2606         }
2607         try {
2608         } catch (Exception e) {
2609             throw new Exception(StringUtils.isEmpty(e.getMessage()) ? "销售业务车辆进厂程序出错!" : e.getMessage());
2610         }
2611         orr.setCode(0);
2612         orr.setItem(true);
2613         return orr;
2614     }
2615
2616     @Override
2617     @Deprecated
2618     public ObjectResult<Boolean> delZcInfo(Scxt_zcInfo zc) throws Exception {
2619         ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
2620         if (zc == null) {
2621             orr.setCode(1);
2622             orr.setErrmsg("业务参数为空!");
2623             return orr;
2624         }
2625         if (true) {
2626             orr.setCode(1);
2627             orr.setErrmsg("该方法已经弃用!");
2628             return orr;
2629         }
2630         String tmh = zc.getTmh();// 条码号
2631         String cph = zc.getCph();// 车牌号
2632         String cardno = zc.getYktkh();// 一卡通卡号
2633         Map<String, Object> cdi = yktmper.getcardinuse(cardno);
2634         if (cdi == null) {
2635             orr.setCode(1);
2636             orr.setErrmsg("该卡一卡通未找到,请确认该卡是否正确!");
2637             return orr;
2638         }
2639         if (cdi.get("numberplates") == null) {
2640             orr.setCode(1);
2641             orr.setErrmsg("该卡没有配置车牌号,请确认该卡是否可用!");
2642             return orr;
2643         }
2644         Fd_Vehicle fdv = vhper.getByVehicleId(cph);
2645         if (fdv == null) {
2646             orr.setCode(1);
2647             orr.setErrmsg("未找到该分单车牌号!");
2648             return orr;
2649         }
2650         Map<String, Object> bsmp = null;//bsper.getbsbyBt(cph, Contants.cpxsBtNo, Serviceenum.在办, Contants.kjSdepartNo);
2651         if (bsmp == null) {
2652             orr.setCode(1);
2653             orr.setErrmsg("该车辆没有找到在办的一卡通业务单!");
2654             return orr;
2655         }
2656         if (StringUtils.isEmpty(bsmp.get("bussinessNo") + "")) {
2657             orr.setCode(1);
2658             orr.setErrmsg("一卡通业务单未找到!");
2659             return orr;
2660         }
2661         int wdi = yktmper.getweight_doc(bsmp.get("bussinessNo") + "");
2662         if (wdi <= 0) {
2663             orr.setCode(1);
2664             orr.setErrmsg("该车辆还未称重,请先去磅房称重!");
2665             return orr;
2666         }
2667         // Fd_Bsheetitem fd_b=bsiper.getbyNoandCode(tmh, bsmp.get("bussinessNo")+"" );
2668         // if(fd_b!=null){
2669         // String tdNo=fd_b.getTdmx_tdbh();//提单编号
2670         // bsper.delbysibyBarcode(tmh, bsmp.get("bussinessNo")+"" );
2671         // Vehicle_XSTD v_x=vhxper.getbyIDs(cph, tdNo);
2672         // if(v_x!=null){
2673         // if(v_x.getFd_num()>1){
2674         // v_x.setFd_num(v_x.getFd_num()-1);
2675         // v_x.setFd_weight(BigDecimalfiter.subscal(v_x.getFd_weight(),
2676         // fd_b.getTdmx_mz(), Contants.scale));
2677         // vhxper.update(v_x);
2678         // fdv.setStatus(VehicleStatus.已装车);
2679         // vhper.update(fdv);
2680         // }else{
2681         // Map<String, Object> cc=vhxper.getbyVehcleId(cph, v_x.getBsNo());
2682         // if(cc!=null){
2683         // if(cc.get("fd_nums")!=null){
2684         // int fd_nums=Integer.parseInt(cc.get("fd_nums")+"");
2685         // if(fd_nums>1){
2686         // fdv.setStatus(VehicleStatus.已装车);
2687         // vhper.update(fdv);
2688         // }else{
2689         // vhxper.delbyIDs(cph, tdNo);
2690         // fdv.setStatus(VehicleStatus.已进厂);
2691         // vhper.update(fdv);
2692         // }
2693         // }else{
2694         // vhxper.delbyIDs(cph, tdNo);
2695         // fdv.setStatus(VehicleStatus.已进厂);
2696         // vhper.update(fdv);
2697         // }
2698         // }else{
2699         // vhxper.delbyIDs(cph, tdNo);
2700         // fdv.setStatus(VehicleStatus.已进厂);
2701         // vhper.update(fdv);
2702         // }
2703         // }
2704         // }else{
2705         // fdv.setStatus(VehicleStatus.已进厂);
2706         // vhper.update(fdv);
2707         // }
2708         // }
2709
2710         orr.setCode(0);
2711         orr.setItem(true);
2712         return orr;
2713     }
2714
2715     @Override
2716     @Deprecated
2717     public Map<String, Object> getClInfo(String cardno) {
2718         Map<String, Object> mp = new HashMap<String, Object>();
2719         Map<String, Object> cdi = yktmper.getcardinuse(cardno);
2720         if (cdi == null) {
2721             mp.put("code", 1);
2722             mp.put("errmsg", "该卡一卡通未找到,请确认该卡是否发放!");
2723             return mp;
2724         }
2725         if (cdi.get("numberplates") == null) {
2726             mp.put("code", 1);
2727             mp.put("errmsg", "该卡没有配置车牌号,请确认该卡是否可用!");
2728             return mp;
2729         }
2730         String vehicleId = cdi.get("numberplates") + "";
2731         Map<String, Object> bsmap = yktmper.getBsheet(vehicleId, Contants.cpxsBtNo, Serviceenum.在办, "04");
2732         if (bsmap == null) {
2733             mp.put("code", 1);
2734             mp.put("errmsg", "该卡没有在办的一卡通销售业务单!");
2735             return mp;
2736         }
2737         Fd_Bsheet fb =null ;//fdbsper.getbyVehicleId(vehicleId, Serviceenum.在办);
2738         if (fb == null) {
2739             mp.put("code", 1);
2740             mp.put("errmsg", "在办分车业务单未找到!");
2741             return mp;
2742         }
2743         int c = this.yktmper.getweight_doc(fb.getBsNo());
2744         if (c <= 0) {
2745             mp.put("code", 1);
2746             mp.put("errmsg", "业务单未找到磅单,请先去过磅!");
2747             return mp;
2748         }
2749         List<Vehicle_XSTD> vxl = new ArrayList<Vehicle_XSTD>();
2750         // List<Vehicle_XSTD> vxl=this.vhxper.getlistbyVehicleId(vehicleId);
2751         mp.put("tdbhs", null);
2752         if (vxl == null || vxl.size() <= 0) {
2753             mp.put("code", 1);
2754             mp.put("errmsg", "未找到销售提单!");
2755             return mp;
2756         } else {
2757             String cc = "";
2758             for (Vehicle_XSTD vx : vxl) {
2759                 if (StringUtils.isEmpty(cc)) {
2760                     cc += vx.getXstdNo();
2761                 } else {
2762                     cc += "," + vx.getXstdNo();
2763                 }
2764             }
2765             mp.put("tdbhs", cc);
2766         }
2767
2768         mp.put("code", 0);
2769         mp.put("cph", fb.getVehicleId());
2770         mp.put("sjmc", fb.getDriver());
2771         mp.put("dh", fb.getPhone());
2772         mp.put("ywdh", fb.getBsNo());
2773         return mp;
2774     }
2775
2776     @Override
2777     @Transactional(rollbackFor = Exception.class)
2778     @Deprecated
2779     public ObjectResult<Boolean> batchSaveZcInfo(String zclist) throws Exception {
2780
2781         ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
2782         if (StringUtils.isEmpty(zclist)) {
2783             orr.setCode(1);
2784             orr.setErrmsg("参数为空不能保存!");
2785             return orr;
2786         }
2787         if (true) {
2788             orr.setCode(1);
2789             orr.setErrmsg("方法已经弃用!");
2790             return orr;
2791         }
2792         // String Lcuuid=UUID.randomUUID()+"";
2793         // try {
2794         // JsonParser jp=new JsonParser();
2795         // JsonArray ja=jp.parse(zclist).getAsJsonArray();
2796         // int eachline=0;
2797         // //是否检查车辆
2798         // boolean checkVehicle=true;
2799         // String bussinessNo="";
2800         // Fd_Vehicle fdv=null;
2801         // Fd_Bsheet fdb=null;
2802         // Map<String, Fd_Erpconfig> dberpmp=new HashMap<String, Fd_Erpconfig>();
2803         // double mzweight=0;
2804         // String instanceID="";
2805         // Map<String, Object> lm=new HashMap<String, Object>();
2806         // for (JsonElement tdje : ja) {
2807         // if(lm.size()>1){
2808         // break;
2809         // }
2810         // JsonObject jo=tdje.getAsJsonObject();
2811         // Scxt_zcInfo zc=new Scxt_zcInfo();
2812         // eachline++;
2813         // zc=JSONobj.getobj(jo, zc);
2814         // if(zc==null){
2815         // continue;
2816         // }
2817         // String tdNo=zc.getTdbh();
2818         // if(!StringUtils.isEmpty(tdNo)){
2819         // String tdsign=tdNo.split("-")[0];
2820         // if(lm.get(tdsign)==null){
2821         // lm.put(tdsign, "abc");
2822         // }
2823         // }
2824         // }
2825         // if(lm.size()>1){
2826         //// boolean lcboo=ddbdao.getLcmps(Lcuuid);
2827         // String dbcheck=DBchecksingleton.setDbc(Lcuuid,false);
2828         // if(!Lcuuid.equals(dbcheck)){
2829         // throw new Exception("ERP数据库正在被占用,请重新操作!");
2830         // }
2831         // }
2832         // List<Fd_Company> fdcl=this.fdcper.getall();
2833         // Map<String, String> fdcm=new HashMap<String, String>();
2834         // if(fdcl!=null){
2835         // for (Fd_Company fdc : fdcl) {
2836         // if(!fdc.isHasSPR()){
2837         // fdcm.put(fdc.getCompanyNo(), fdc.getName());
2838         // }
2839         // }
2840         // }
2841         // for (JsonElement je : ja) {
2842         // JsonObject jo=je.getAsJsonObject();
2843         // Scxt_zcInfo zc=new Scxt_zcInfo();
2844         // eachline++;
2845         // zc=JSONobj.getobj(jo, zc);
2846         // if(zc==null){
2847         // continue;
2848         // }
2849         //
2850         //
2851         // if(StringUtils.isEmpty(zc.getCph())||StringUtils.isEmpty(zc.getTdbh())||StringUtils.isEmpty(zc.getPch())){
2852         // continue;
2853         // }
2854         // String dbsign=zc.getTdbh().split("-")[0];
2855         // Fd_Erpconfig erpdb=null;
2856         // if(dberpmp.get(dbsign)==null){
2857         // erpdb=erpper.getbySign(dbsign);
2858         // if(erpdb==null){
2859         // throw new Exception("提单编号是"+dbsign+"-******* 类型的未配置ERP数据库!");
2860         // }
2861         // dberpmp.put(dbsign, erpdb);
2862         // }else{
2863         // erpdb=dberpmp.get(dbsign);
2864         // }
2865         // if(checkVehicle){
2866         // fdv=vhper.getByVehicleId(zc.getCph());
2867         // if(fdv==null){
2868         // throw new Exception("分单系统车牌号:"+zc.getCph()+" 未找到,请确认车辆信息是否正确!");
2869         // }
2870         // Map<String, Object> bsmp=bsper.getbsbyBt(zc.getCph(), Contants.cpxsBtNo,
2871         // Serviceenum.在办, Contants.ssdepartNo);
2872         // if(bsmp==null){
2873         // throw new Exception("车牌号:"+zc.getCph()+" 未找到一卡通业务单!");
2874         // }
2875         // bussinessNo=bsmp.get("bussinessNo")+"";
2876         // instanceID=bsmp.get("instanceID")==null?"":bsmp.get("instanceID")+"";
2877         // fdb=fdbsper.getbybsNo(bussinessNo);
2878         // if(fdb==null){
2879         // throw new Exception("车牌号:"+zc.getCph()+" 未找到分单业务单!");
2880         // }else{
2881         // if(!fdb.getVehicleId().equals(zc.getCph())){
2882         // throw new Exception("车牌号:"+zc.getCph()+"与 分单车牌号不一致!");
2883         // }
2884         // }
2885         // checkVehicle=false;
2886         // }
2887         //
2888         // Vehicle_XSTD vhx=vhxper.getbyIDs(zc.getCph(), zc.getTdbh());
2889         // if(vhx==null){
2890         // throw new Exception("提单编号:"+zc.getTdbh()+"没有分单给车牌号:"+zc.getCph()+" !");
2891         // }
2892         // String
2893         // url="jdbc:jtds:sqlserver://"+erpdb.getUri()+":"+erpdb.getPost()+";databaseName="+erpdb.getDb();
2894         // Connection con=ddbdao.open(url, erpdb.getUsername(),
2895         // erpdb.getPwd(),erpdb.getDbsign());
2896         // if(con==null){
2897         // throw new Exception("ERP数据库链接失败,请检查分单系统ERP配置是否正确!");
2898         // }
2899         // String sql=SqlTxt.GYErpXSTDsql+" where EXISTS (SELECT 1 FROM XSTDMX WHERE
2900         // XSTDMX_TDLS=XSTD_TDLS AND XSTDMX_CKBZ='0') and a.XSTD_TDBH='"+zc.getTdbh()+"'
2901         // and a.XSTD_SHBZ=1 and a.XSTD_TDBZ='LD' ";
2902         // Map<String, Object> tdmp=ddbdao.getmapnoclose(sql,erpdb.getDbsign());
2903         // if(tdmp==null){
2904         // throw new Exception("第"+eachline+"行 ,销售提单未找到!");
2905         // }
2906         // WaitXSTD wt=new WaitXSTD();
2907         // BeanUtils.populate(wt, tdmp);
2908         //
2909         // sql=SqlTxt.GYErpXSTDMXsql+" where b.XSTDMX_CKBZ='0' and
2910         // a.XSTD_TDBH='"+zc.getTdbh()+"' and b.XSTDMX_PCH='"+zc.getPch()+"' ";//销售提单明细
2911         // Map<String, Object> mxmp=ddbdao.getmapnoclose(sql,erpdb.getDbsign());
2912         // if(mxmp==null){
2913         // throw new Exception("第"+eachline+"行 根据提单号和批次号Erp未找到销售提单明细!");
2914         // }
2915         // WaitXSTDMX wtdmx=new WaitXSTDMX();
2916         // BeanUtils.populate(wtdmx, mxmp);
2917         // String hj=mxmp.get("hj")==null?"":mxmp.get("hj")+"";
2918         // String zt=mxmp.get("zt")==null?"":mxmp.get("zt")+"";
2919         // wtdmx.setTdmx_hjzt(hj+"/"+zt);
2920         // //如果扫的是没有分单的
2921         // if(wtdmx.getTdmx_fdbz()==0){
2922         // sql=SqlTxt.XGGYErpXSTDMXsql1+" where a.XSTDMX_CKBZ='0' and
2923         // b.XSTD_TDBH='"+zc.getTdbh()+"' and a.XSTDMX_PCH='"+zc.getPch()+"'
2924         // ";//修改销售提单明细
2925         // List<Object> ll=new ArrayList<Object>();
2926         // ll.add(zc.getCph());//车牌号
2927         // ll.add(2);//分单标志
2928         // ll.add(bussinessNo);//分单单据编号
2929         // ll.add(fdv.getDriver());//司机姓名
2930         // ll.add(fdv.getPhone());//司机联系方式
2931         // ll.add(fdcm.get(vhx.getCompanyNo())==null?"":fdcm.get(vhx.getCompanyNo()));//物流公司名称
2932         //// ll.add(fdcm.get(fdv.getCompanyNo())==null?"":fdcm.get(fdv.getCompanyNo()));//物流公司名称
2933         // ddbdao.modifySql(sql, ll,erpdb.getDbsign());
2934         //
2935         // sql=SqlTxt.XGGYErpXSTDsql;//修改销售提单
2936         // ll.clear();
2937         // ll.add(wt.getTd_wfdsl()-1);//未分单数量
2938         // ll.add(BigDecimalfiter.subscal(wt.getTd_wfdzl(), wtdmx.getTdmx_mz(),
2939         // Contants.scale));//未分单毛重
2940         // ll.add(zc.getTdbh());
2941         // ddbdao.modifySql(sql, ll,erpdb.getDbsign());
2942         //
2943         // //修改vhx
2944         // vhx.setFd_num(vhx.getFd_num()+1);
2945         // vhx.setFd_weight(BigDecimalfiter.addscal(vhx.getFd_weight(),
2946         // wtdmx.getTdmx_mz(), Contants.scale));
2947         // vhxper.update(vhx);
2948         // }else{
2949         // sql=SqlTxt.XGGYErpXSTDMXsql2+" where a.XSTDMX_CKBZ='0' and
2950         // b.XSTD_TDBH='"+zc.getTdbh()+"' and a.XSTDMX_PCH='"+zc.getPch()+"'
2951         // ";//修改销售提单明细
2952         // List<Object> ll=new ArrayList<Object>();
2953         // ll.add(fdv.getDriver());//司机姓名
2954         // ll.add(fdv.getPhone());//司机联系方式
2955         // ll.add(fdcm.get(vhx.getCompanyNo())==null?"":fdcm.get(vhx.getCompanyNo()));//物流公司名称
2956         //// ll.add(fdcm.get(fdv.getCompanyNo())==null?"":fdcm.get(fdv.getCompanyNo()));//物流公司名称
2957         // ddbdao.modifySql(sql, ll,erpdb.getDbsign());
2958         //
2959         // if(!zc.getCph().equals(wtdmx.getTdmx_cph())){
2960         // Vehicle_XSTD vhx1=this.vhxper.getbyIDs(wtdmx.getTdmx_cph(), zc.getTdbh());
2961         // if(vhx1!=null){
2962         // vhx1.setFd_num(vhx1.getFd_num()-1);
2963         // vhx1.setFd_weight(BigDecimalfiter.subscal(vhx1.getFd_weight(),
2964         // wtdmx.getTdmx_mz(), Contants.scale));
2965         // vhxper.update(vhx1);
2966         // }
2967         // //修改vhx
2968         // vhx.setFd_num(vhx.getFd_num()+1);
2969         // vhx.setFd_weight(BigDecimalfiter.addscal(vhx.getFd_weight(),
2970         // wtdmx.getTdmx_mz(), Contants.scale));
2971         // vhxper.update(vhx);
2972         // }
2973         // }
2974         // //修改fbi
2975         // Fd_Bsheetitem fbi=bsiper.getbyLsandFl(wtdmx.getTdmx_tdls(),
2976         // wtdmx.getTdmx_tdfl(),zc.getTdbh());
2977         // if(fbi!=null){
2978         // fbi.setTdmx_cph(zc.getCph());
2979         // fbi.setTdmx_tdbh(zc.getTdbh());
2980         // fbi.setTdmx_fdbz(2);
2981         // fbi.setTdmx_fdywbh(fdb.getFdsheetNo());
2982         // fbi.setTdmx_zccph(zc.getCph());
2983         // fbi.setTdmx_sfzc(1);
2984         // fbi.setBarcode(zc.getTmh());
2985         // bsiper.update(fbi);
2986         // }else{
2987         // fbi=new Fd_Bsheetitem();
2988         // fbi.setId(UUID.randomUUID()+"");
2989         // fbi.setCompanyName(fdb.getCompanyName());
2990         // fbi.setCompanyNo(fdb.getCompanyNo());
2991         // fbi.setCreateid(fdb.getCreateid());
2992         // fbi.setBarcode(zc.getTmh());
2993         // fbi.setCtime(new Date());
2994         // fbi.setTdmx_cph(zc.getCph());
2995         // fbi.setTdmx_tdbh(zc.getTdbh());
2996         // fbi.setTdmx_fdbz(2);
2997         // fbi.setTdmx_fdywbh(fdb.getFdsheetNo());
2998         // fbi.setTdmx_zccph(zc.getCph());
2999         // fbi.setTdmx_sfzc(1);
3000         // bsiper.insert(fbi);
3001         // }
3002         // if(fdv.getStatus()!=VehicleStatus.已进厂){
3003         // fdv.setStatus(VehicleStatus.已进厂);
3004         // vhper.update(fdv);
3005         // }
3006         //
3007         // //添加一卡通明细;
3008         // Map<String, Object> mm=new HashMap<String, Object>();
3009         // mm.put("id", UUID.randomUUID()+"");
3010         // mm.put("bussinessNo",bussinessNo);
3011         // mm.put("name", wtdmx.getTdmx_wlmc());
3012         // mm.put("materielNo",wtdmx.getTdmx_wlbh() );
3013         // mm.put("norms",wtdmx.getTdmx_ggxh() );
3014         // mm.put("unitname", "Kg");
3015         // mm.put("num", 1);
3016         // mm.put("note", null);
3017         // mm.put("weight", BigDecimalfiter.mulcon(wtdmx.getTdmx_jz(), 1000,
3018         // Contants.scale));
3019         // mm.put("price", 0);
3020         // mm.put("preweight",BigDecimalfiter.mulcon(wtdmx.getTdmx_jz(), 1000,
3021         // Contants.scale));
3022         // mm.put("pici", zc.getPch());
3023         // mm.put("hejin", wtdmx.getTdmx_hjzt());
3024         // mm.put("gross",BigDecimalfiter.mulcon(wtdmx.getTdmx_mz(), 1000,
3025         // Contants.scale) );
3026         // mm.put("taotong","" );
3027         // mm.put("taotongWeight", BigDecimalfiter.subscal(wtdmx.getTdmx_mz()*1000,
3028         // wtdmx.getTdmx_jz()*1000, Contants.scale));
3029         // mm.put("money", 0);
3030         //// mm.put("createid", );
3031         //// mm.put("cname", );
3032         //// mm.put("createid", 0);
3033         // mm.put("cdepartid", 0);
3034         //// mm.put("cdepart", );
3035         // mm.put("ctime", new Date());
3036         // mm.put("loadbuild", false);
3037         // mm.put("factory", false);
3038         // mm.put("fachang", true);
3039         // mm.put("fcnum", 0);
3040         // mm.put("product_billNo", zc.getTdbh());
3041         // mm.put("product_serialNo",wtdmx.getTdmx_tdls());
3042         // mm.put("product_otherNo", null);
3043         //// mm.put("product_ywrq",wtdmx.gettdmx_ );
3044         // mm.put("product_flh", wtdmx.getTdmx_tdfl());
3045         // mm.put("recompany",wtdmx.getTdmx_shdw() );
3046         //// mm.put("reID", "");
3047         // mm.put("decompany", wtdmx.getTdmx_fhdw()==null?"明泰科技":wtdmx.getTdmx_fhdw());
3048         //// mm.put("deID", "");
3049         // mm.put("rcompany",wtdmx.getTdmx_shdw() );
3050         //// mm.put("rID", );
3051         // mm.put("frombatch", "ERP系统");
3052         // mm.put("forshowindx",1 );
3053         // mm.put("barcode",zc.getTmh());
3054         // mm.put("reserved11",0 );
3055         // mm.put("reserved12",0 );
3056         // mm.put("reserved13",0 );
3057         // mm.put("jsnum",0 );
3058         // Map<String, Object> mrc=this.bsper.getbsi(zc.getPch(), bussinessNo);
3059         // if(mrc==null){
3060         // bsper.insertBsi(mm);
3061         // }else{
3062         // mm.put("id", mrc.get("id")+"");
3063         // bsper.updateBsi(mm);
3064         // }
3065         // mzweight=BigDecimalfiter.addscal(mzweight,
3066         // BigDecimalfiter.mulcon(wtdmx.getTdmx_mz(), 1000, Contants.scale),
3067         // Contants.scale);
3068         // }
3069         //
3070         // if(mzweight>0&&!StringUtils.isEmpty(instanceID)){
3071         // Map<String, Object> mm=this.yktmper.getweight_docgt(bussinessNo);
3072         // if(mm!=null){
3073         // double gross=Double.parseDouble(mm.get("gross")+"");
3074         // double tare=Double.parseDouble(mm.get("tare")+"");
3075         // if(gross>0&& tare>0){
3076         // Task tk=this.acpser.findTaskByInstanceID(instanceID,
3077         // Contants.weightTaskName);
3078         // Map<String, Object> mcm=new HashMap<String,Object>();
3079         // if(tk!=null){
3080         // if(((gross-tare)-mzweight>Contants.upweight)||(mzweight-(gross-tare))<Contants.loawweight){
3081         // mcm.put("ckbc",1);
3082         // }else{
3083         // mcm.put("ckbc",0);
3084         // }
3085         // this.acpser.completeTask(tk.getId(), "admin", mcm);
3086         // }
3087         // }
3088         // }
3089         //
3090         // }
3091         //
3092         //
3093         // } catch (Exception e) {
3094         // ddbdao.robackclose();
3095         // throw new
3096         // Exception(StringUtils.isEmpty(e.getMessage())?"装车批量保存出错!":e.getMessage());
3097         // }finally{
3098         // ddbdao.close();
3099         //// ddbdao.removeLc(Lcuuid);
3100         // DBchecksingleton.setDbc(Lcuuid,true);
3101         // }
3102
3103         orr.setCode(0);
3104         orr.setItem(true);
3105         return orr;
3106     }
3107
3108     @Override
3109     @Transactional(rollbackFor = Exception.class)
3110     @Deprecated
3111     public ObjectResult<Boolean> batchdelZcInfo(String zcist) throws Exception {
3112         ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
3113         if (zcist == null) {
3114             orr.setCode(1);
3115             orr.setErrmsg("业务参数为空!");
3116             return orr;
3117         }
3118         if (true) {
3119             orr.setCode(1);
3120             orr.setErrmsg("该方法已经弃用!");
3121             return orr;
3122         }
3123
3124         // try {
3125         // JsonParser jp=new JsonParser();
3126         // JsonArray ja=jp.parse(zcist).getAsJsonArray();
3127         // boolean checkvehicle=true;
3128         // Fd_Vehicle fdv=null;
3129         // String bussinessNo="";
3130         // Fd_Bsheet fdb=null;
3131         // for (JsonElement je : ja) {
3132         // JsonObject jo=je.getAsJsonObject();
3133         // Scxt_zcInfo zc=new Scxt_zcInfo();
3134         // zc=JSONobj.getobj(jo, zc);
3135         // if(zc==null){
3136         // continue;
3137         // }
3138         // if(StringUtils.isEmpty(zc.getCph())||StringUtils.isEmpty(zc.getYktkh())||StringUtils.isEmpty(zc.getPch())){
3139         // continue;
3140         // }
3141         // String vehicleId=zc.getCph();//车牌号
3142         // String cardno=zc.getYktkh();//卡号
3143         // String pch=zc.getPch();//批次号
3144         // if(checkvehicle){
3145         // Map<String, Object> cdi=yktmper.getcardinuse(cardno);
3146         // if(cdi==null){
3147         // throw new Exception("卡号一卡通未找到,请确认该卡是否正确!");
3148         // }else if(!vehicleId.equals(cdi.get("numberplates"+""))){
3149         // throw new Exception("卡号与车牌号不对应,请确认卡号或者车牌号是否正确!");
3150         // }
3151         // fdv=vhper.getByVehicleId(zc.getCph());
3152         // if(fdv==null){
3153         // throw new Exception("分单系统车牌号:"+zc.getCph()+" 未找到,请确认车辆信息是否正确!");
3154         // }
3155         // Map<String, Object> bsmp=bsper.getbsbyBt(zc.getCph(), Contants.cpxsBtNo,
3156         // Serviceenum.在办, Contants.ssdepartNo);
3157         // if(bsmp==null){
3158         // throw new Exception("车牌号:"+zc.getCph()+" 未找到一卡通业务单!");
3159         // }
3160         // bussinessNo=bsmp.get("bussinessNo")+"";
3161         // fdb=fdbsper.getbybsNo(bussinessNo);
3162         // if(fdb==null){
3163         // throw new Exception("车牌号:"+zc.getCph()+" 未找到分单业务单!");
3164         // }else{
3165         // if(!fdb.getVehicleId().equals(zc.getCph())){
3166         // throw new Exception("车牌号:"+zc.getCph()+"与 分单车牌号不一致!");
3167         // }
3168         // }
3169         // checkvehicle=false;
3170         // }
3171         // bsper.delbypchandNo(pch, bussinessNo);
3172         // Fd_Bsheetitem fdbi=bsiper.getbypchandNo(bussinessNo, pch);
3173         // if(fdbi!=null){
3174         // fdbi.setTdmx_sfzc(0);
3175         // fdbi.setTdmx_zccph("");
3176         // bsiper.update(fdbi);
3177         // }
3178         // }
3179         //
3180         // //修改车辆信息
3181         // List<Map<String, Object>> bsill=bsper.getbsibyNo(bussinessNo);
3182         // if(bsill==null||bsill.size()<=0){
3183         // fdv.setStatus(VehicleStatus.已进厂);
3184         // vhper.update(fdv);
3185         // }
3186         // } catch (Exception e) {
3187         // throw new
3188         // Exception(StringUtils.isEmpty(e.getMessage())?"分单系统批量删除装车出错!":e.getMessage());
3189         // }
3190         orr.setCode(0);
3191         orr.setItem(true);
3192         return orr;
3193     }
3194
3195     @Override
3196     public void changeMxWlgs(List<FdMxWlgs> fdMxWlgsList) throws Exception {
3197         // if(1==1) throw new Exception("就是一个提示!---");
3198         if(fdMxWlgsList!=null) {
3199             List<Fd_XSTDMX> updateFd_XSTDMX = new ArrayList<>();
3200             String tdmx_tdfls = fdMxWlgsList.stream().map(FdMxWlgs::getTdmxTdfl).collect(Collectors.joining("','"));
3201             List<Fd_XSTDMX>  fd_xstdmxes = null;
3202             // 提单流水为主键的Map,存放去掉的数量和重量,需要还回去
3203             Map<String,Map<String,Object>> tdlsMap = new HashedMap();
3204             if(StringUtils.isNotBlank(tdmx_tdfls)) {
3205                 // 根据单号查找已派车的业务单,判断业务单是否发卡,已发卡不能修改,返回错误;前端应该也做限制
3206                 tdmx_tdfls = "'" + tdmx_tdfls + "'";
3207                 fd_xstdmxes = fd_xstdmxMapper.gets(tdmx_tdfls);
3208                 String fdywbhs = fd_xstdmxes.stream().map(Fd_XSTDMX::getTdmx_fdywbh).collect(Collectors.joining("','"));
3209                 if(StringUtils.isNotBlank(fdywbhs) && !"'null'".equals(fdywbhs))  {
3210                     fdywbhs =  "'" + fdywbhs + "'";
3211                     // 如果已经发卡,请联系一卡通
3212                     Map<String, Object> map = businessMapper.existsIssueCardByNos(fdywbhs);
3213                     if (map != null) {
3214                         throw  new Exception("存在已发卡单,请刷新页面后重试!");
3215                     }
3216                 }
3217                 // 删了单,要把重量和数量还回去;在此遍历一下,下面在session中统一更新
3218                 fd_xstdmxes.forEach(fd_xstdmx -> {
3219                     // 装车标志都是 0
3220                     // if(fd_xstdmx.getTdmx_zcbz() == 0)  return;
3221                     // 不存在业务号,则任务没有分单;采用装车标志有问题,不采用。
3222                     if(StringUtils.isBlank(fd_xstdmx.getTdmx_fdywbh()))   return;
3223                     if(tdlsMap.get(fd_xstdmx.getTdmx_tdls())  == null ) {
3224                         tdlsMap.put(fd_xstdmx.getTdmx_tdls(), new HashedMap());
3225                         tdlsMap.get(fd_xstdmx.getTdmx_tdls()).put("addFdsl",0);
3226                         tdlsMap.get(fd_xstdmx.getTdmx_tdls()).put("addFdmz",0d);
3227                     }
3228                     Map map = tdlsMap.get(fd_xstdmx.getTdmx_tdls());
3229                     int addFdsl = (Integer) map.get("addFdsl");
3230                     double addFdmz = (Double) map.get("addFdmz");
3231
3232                     addFdsl ++;
3233                     addFdmz = BigDecimalfiter.addscal(addFdmz, fd_xstdmx.getTdmx_mz(), Contants.scale);
3234                     map.put("addFdsl",addFdsl);
3235                     map.put("addFdmz",addFdmz);
3236                 });
3237             }
3238             fdMxWlgsList.forEach(fdMxWlgs -> {
3239                 Fd_XSTDMX  fd_xstdmx = new Fd_XSTDMX();
3240                 fd_xstdmx.setTdmx_fdcph(null);
3241                 fd_xstdmx.setTdmx_zcwlgsName(null);
3242                 fd_xstdmx.setTdmx_zcphone(null);
3243                 fd_xstdmx.setTdmx_zcdriver(null);
3244                 fd_xstdmx.setTdmx_fdwlgsbh(null);
3245                 fd_xstdmx.setTdmx_fdywbh(null);
3246                 fd_xstdmx.setTdmx_fdbz(0);
3247                 fd_xstdmx.setTdmx_zcbz(0);
3248                 fd_xstdmx.setTdmx_tdfl(fdMxWlgs.getTdmxTdfl());
3249                 fd_xstdmx.setTdmx_fdwlgsbh(fdMxWlgs.getWlgsNo());
3250                 updateFd_XSTDMX.add(fd_xstdmx);
3251             });
3252             try(SqlSession sqlSession =  sqlSessionFactory.openSession(ExecutorType.BATCH,false)){
3253                 // 删除明细和物流公司关系,并新增
3254                 FdMxWlgsMapper mapper = sqlSession.getMapper(FdMxWlgsMapper.class);
3255                 fdMxWlgsList.forEach(fdMxWlgs -> { // 需要删除相关信息(删除该业务单、删除车辆提单)
3256                     mapper.delete(fdMxWlgs.getTdmxTdfl());
3257                     mapper.insert(fdMxWlgs);
3258                 });
3259                 if(updateFd_XSTDMX != null) {
3260                     // 更新分单明细项为未分单
3261                     Fd_XSTDMXMapper fd_xstdmxMapper = sqlSession.getMapper(Fd_XSTDMXMapper.class);
3262                     updateFd_XSTDMX.forEach(fd_xstdmx -> fd_xstdmxMapper.updateZCnoFD(fd_xstdmx));
3263                 }
3264                 if(fd_xstdmxes!=null && fd_xstdmxes.size() > 0 ) {
3265                     Fd_BsheetMapper fd_bsheetMapper = sqlSession.getMapper(Fd_BsheetMapper.class);
3266                     VehicleXSTDMapper vehicleXSTDMapper =  sqlSession.getMapper(VehicleXSTDMapper.class);
3267                     for (Fd_XSTDMX fd_xstdmx : fd_xstdmxes) {
3268                         // 根据车牌号和业务号删除分单车辆,如果是拼单的情况;是否是拼单,取消这个就行,其他不管。
3269                         // 如果配车数量为0可以删除,其他情况,可以-1,把重量也减掉
3270                         if(StringUtils.isNotBlank(fd_xstdmx.getTdmx_fdcph()) && StringUtils.isNotBlank(fd_xstdmx.getTdmx_fdywbh())) {
3271                             List<Vehicle_XSTD> vehicleXSTDs = vehicleXSTDMapper.getlistbyVehicleIdandbsNoGp(fd_xstdmx.getTdmx_fdcph(), fd_xstdmx.getTdmx_fdywbh());
3272                             if (vehicleXSTDs != null && vehicleXSTDs.size() == 1) {
3273                                 Vehicle_XSTD vehicleXSTD = vehicleXSTDs.get(0);
3274                                 int num = vehicleXSTD.getFd_num();
3275                                 if (num <= 1) {
3276                                     vehicleXSTDMapper.delbyVehicleId(fd_xstdmx.getTdmx_fdcph(), fd_xstdmx.getTdmx_fdywbh());
3277                                 } else {
3278                                     vehicleXSTD.setFd_num(vehicleXSTD.getFd_num() - 1);
3279                                     vehicleXSTD.setFd_weight(BigDecimalfiter.subscal(vehicleXSTD.getFd_weight(), fd_xstdmx.getTdmx_mz(), Contants.scale));
3280                                     vehicleXSTDMapper.updatewithIDs(vehicleXSTD);
3281                                 }
3282                             } else {
3283                                 throw new Exception("出现同一辆车的同一业务单出现多个,请检查数据");
3284                             }
3285                         }
3286                         // vehicleXSTDMapper.delbyVehicleId(fd_xstdmx.getTdmx_fdcph(), fd_xstdmx.getTdmx_fdywbh());
3287                         Fd_Bsheet fd_bsheet = fd_bsheetMapper.getbybsNo(fd_xstdmx.getTdmx_fdywbh());
3288                         // 删除分单业务
3289                         fd_bsheetMapper.delbybsNo(fd_xstdmx.getTdmx_fdywbh());
3290                         // 远程删除数量
3291                         if(fd_bsheet!=null) {
3292                             JsonObject jo = new JsonObject();
3293                             jo.addProperty("bussinessNo", fd_xstdmx.getTdmx_fdywbh());
3294                             jo.addProperty("sdepartNo", fd_bsheet.getSdepartNo());
3295                             // 通过接口删除业务单
3296                             JsonObject pfob = Wxhtmethod.postJsonStr(Contants.YKTdelYwd_url, jo.toString());
3297                             int code = JSONobj.getint(pfob, "code");
3298                             if (code != 0) {
3299                                 throw new Exception(JSONobj.getstring(pfob, "errmsg"));
3300                             }
3301                         }
3302                     }
3303                     // 需要更新提单的重量和数量
3304                     Fd_XSTDMapper fdXstdMapper = sqlSession.getMapper(Fd_XSTDMapper.class);
3305                     tdlsMap.forEach((k, v) -> {
3306                         Fd_XSTD xstd =  fdXstdMapper.get(k);
3307                         int addFdsl_1 = (Integer) v.get("addFdsl");
3308                         double addFdmz_1 = (Double) v.get("addFdmz");
3309                         xstd.setTd_tdls(k);
3310                         xstd.setTd_wfdsl(xstd.getTd_wfdsl() + addFdsl_1);
3311                         xstd.setTd_wfdzl(BigDecimalfiter.addscal(xstd.getTd_wfdzl(), addFdmz_1, Contants.scale));
3312                         fdXstdMapper.updateFD(xstd);
3313                     });
3314                 }
3315                 sqlSession.commit();
3316             }
3317         }
3318     }
3319
3320
3321     @Resource
3322     Fd_XSTDMXMapper fd_xstdmxMapper;
3323     @Resource
3324     BusinessMapper businessMapper;
3325
3326
3327 }