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