Administrator
2022-12-15 9ce4bb2b6bd1378ba7b0bd6681d22cb37a5e1452
提交 | 用户 | 时间
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);
1117                 if (td == null || td.getTd_wfdsl()<=0 ) {  //|| td.isTd_zcwcbz()  装车完成标志  不需要了
1118                     continue;
1119                 }
1120
1121                 // 这一块是判断用户有没有这个提单的操作权限 :
1122                 //1.在页面获取提单列表的时候已经加过校验,同一厂区的提单可以同时显示不同厂区的提单不能同时显示,用户只能同时操作同一厂区的提单
1123                 //当前用户只能看到可以操作的提单  不可以操作的提单看不到
1124                 //所有以下else操作去掉
1125                 if (StringUtils.isBlank(bsDE)) {
1126                     /*bsDE = td.getTd_cqNo().equals(Contants.nc_ywdy_ZZ) ? Contants.zzSdepartNo :
1127                             td.getTd_cqNo().equals(Contants.nc_ywdy_MS)? Contants.msSdepartNo :
1128                             td.getTd_cqNo().equals(Contants.nc_ywdy_YR)? Contants.yrSdepartNo :
1129                                     Contants.kjSdepartNo;*/
1130                     bsDE = ConvertTool.ncCovertToYkt(td.getTd_cqNo());
1131                 }
1132 //                else {
1133 //                    // 郑州
1134 //                    if (bsDE.equals(Contants.zzSdepartNo)) {
1135 //                        if (!td.getTd_ywdybh().equals(Contants.nc_ywdy_ZZ)) {
1136 //                            orr.setCode(1);
1137 //                            orr.setErrmsg("提单:"+td.getTd_ywdybh()+"不是郑州厂区的提单,不能同时配单!");
1138 //                            return orr;
1139 //                        }
1140 //                    } else if(bsDE.equals(Contants.msSdepartNo)) {
1141 //                        if (!td.getTd_ywdybh().equals(Contants.nc_ywdy_MS)) {
1142 //                            orr.setCode(1);
1143 //                            orr.setErrmsg("提单:"+td.getTd_ywdybh()+"不是明晟厂区的提单,不能同时配单!");
1144 //                            return orr;
1145 //                        }
1146 //                    }else {
1147 //                        if (!td.getTd_ywdybh().equals(Contants.nc_ywdy_KJ)) {
1148 //                            orr.setCode(1);
1149 //                            orr.setErrmsg("提单:"+td.getTd_ywdybh()+"不是明晟厂区的提单,不能同时配单!");
1150 //                            return orr;
1151 //                        }
1152 //                    }
1153 //                }
1154                 if (StringUtils.isBlank(ziti)) {
1155                     ziti = td.getTd_ztbz() == 2 ? "自提" : "非自提";
1156                 }
1157                 if (StringUtils.isBlank(Rcompany)) {
1158                     Map<String, Object> mm = this.dqper.getKH(td.getTd_khbh());
9ce4bb 1159                     if(mm == null || mm.size() == 0) { // 客户必须存在,否则无法分单
A 1160                         orr.setCode(1);
1161                         orr.setErrmsg("该提单客户不存在,请检查数据!");
1162                         return orr;
1163                     }
58d006 1164                     //
A 1165                     /*
1166                     * 1、外贸有发票编号,内贸没有发票编号
1167                     * 2、内贸取实际公司名称,外贸取相应组织的公司简称+‘报关’
1168                     * */
1169                     if (StringUtils.isBlank(td.getTd_fpbh())) {
1170                         if (mm != null) {
1171                             Rcompany = mm.get("name") == null ? "" : mm.get("name").toString();
1172                         }
1173                     } else {
1174                         /*Rcompany = (td.getTd_ywdybh().equals(Contants.nc_ywdy_ZZ)?"郑州报关":
1175                             td.getTd_ywdybh().equals(Contants.nc_ywdy_MT)?"河南报关":
1176                                 td.getTd_ywdybh().equals(Contants.nc_ywdy_MS)?"明晟报关":
1177                             "科技报关");*/
1178                         Rcompany = ConvertTool.covertToCustoms(td.getTd_ywdybh());
1179                     }
1180                 }
1181                 tdl.add(td);
1182             }
1183         }
1184
1185         // 系统部门未找到
1186         if (StringUtils.isBlank(bsDE)) {
1187             orr.setCode(1);
1188             orr.setErrmsg("提单未找到系统部门字段,请重新操作!");
1189             return orr;
1190         }
1191
1192
1193         boolean saveBT = false;// 保存一卡通业务单表头信息
1194         String bsNo="";
1195         // 保存表相关信息
1196         try {
1197             // 保存业务单
1198             Fd_Bsheet fb = this.fdbsper.getbyVehicleId(fdv1.getVehicleId(), Serviceenum.在办, bsDE);
1199             if (fb == null) {
1200 //                // 获取业务单号  建议加上 记录一下开始时间和结束时间 判断地方的请求时间
1201                 JsonObject pfob = Wxhtmethod.postJsonStr(Contants.YKTgetPrefix_url, PrefixEnum.productsale.toString());
1202                 ObjectResult<String> pfor = new ObjectResult<String>();
1203                 String bssNo = JSONobj.getstring(pfob, "item");
1204                 int code = JSONobj.getint(pfob, "code");
1205                 String errmsg = JSONobj.getstring(pfob, "errmsg");
1206                 pfor.setCode(code);
1207                 pfor.setErrmsg(errmsg);
1208                 pfor.setItem(bssNo);
1209                 if (pfor == null || pfor.getCode() != 0) {
1210                     orr.setCode(1);
1211                     orr.setErrmsg(pfor.getErrmsg());
1212                     return orr;
1213                 }
1214                 fb = new Fd_Bsheet();
1215                 fb.setBsNo(pfor.getItem());
1216                 fb.setCompanyName(lg.getDepartname());
1217                 fb.setCompanyNo(lg.getDepartno());
1218                 fb.setCreateid(lg.getUserid());
1219                 fb.setCreateName(lg.getWorkername());
1220                 fb.setCtime(new Date());
1221                 fb.setDriver(fdv1.getDriver());
1222                 fb.setFdsheetNo(pfor.getItem());
1223                 fb.setId(UUID.randomUUID() + "");
1224                 fb.setPhone(fdv1.getPhone());
1225                 fb.setSendmsg(false);
1226                 fb.setStatus(Serviceenum.在办);
1227                 fb.setVehicleId(fdv1.getVehicleId());
1228                 fb.setSdepartNo(bsDE);
1229                 fb.setShdw(StringUtils.isBlank(Rcompany) ? "未知发货单位" : Rcompany);
1230                 fb.setUpdateTime(new Date());
1231                 this.fdbsper.insertAll(fb);
1232                 saveBT=true;
1233                 bsNo=bssNo;
1234             } else {
1235                 fb.setDriver(fdv1.getDriver());
1236                 fb.setPhone(fdv1.getPhone());
1237                 fb.setUpdateTime(new Date());
1238                 fdbsper.update(fb);
1239                 bsNo=fb.getBsNo();
1240             }
1241
1242             // 保存车辆信息
1243             Fd_Vehicle fdv = this.vhper.getByVehicleId(fdv1.getVehicleId());
1244             if (fdv == null) {
1245                 vhper.insert(fdv1);
1246             } else {
1247                 if (fdv.getType() == VehicleType.临时车) {
1248                     fdv.setDriver(fdv1.getDriver());
1249                     fdv.setPhone(fdv1.getPhone());
1250                     fdv.setIDNum(fdv1.getIDNum());
1251                     vhper.update(fdv);
1252                 }
1253             }
1254             Fd_Company_Vehicle fdcv = fdvcper.getbyIDs(fdv1.getVehicleId(), lg.getDepartno(), bsDE);
1255             if (fdcv == null) {
1256                 fdcv = new Fd_Company_Vehicle();
1257                 fdcv.setCompanyNo(lg.getDepartno());
1258                 fdcv.setVehicleId(fdv1.getVehicleId());
1259                 fdcv.setSdepartNo(bsDE);
1260                 fdvcper.insertIDs(fdcv);
1261             }
1262
1263             // 保存分单表相关信息
1264             Map<String, List<Fd_XSTDMX>> mxMp = new HashMap<String, List<Fd_XSTDMX>>();
1265             if(tdl!=null&&!tdl.isEmpty()) {
1266                 for (Fd_XSTD td : tdl) {
1267                     int fdsl = 0;
1268                     double fdmz = 0;
1269                     List<Fd_XSTDMX> mxl = this.tdmxper.getNOZCandFD(td.getTd_tdls());
1270                     if (mxl == null || mxl.isEmpty()) {
1271                         continue;
1272                     }
1273                     for (Fd_XSTDMX tdmx : mxl) {
1274                         fdsl++;
1275                         fdmz = BigDecimalfiter.addscal(fdmz, tdmx.getTdmx_mz(), Contants.scale);
1276                         tdmx.setTdmx_fdbz(1);
1277                         tdmx.setTdmx_fdcph(fdv1.getVehicleId());
1278                         tdmx.setTdmx_fdywbh(bsNo);
1279                         tdmx.setTdmx_fdwlgsbh(lg.getDepartno());
1280                     }
1281
1282                     Fd_XSTDMX tdmx=mxl.get(0);
1283                     tdmx.setTdmx_fdbz(1);
1284                     tdmx.setTdmx_fdcph(fdv1.getVehicleId());
1285                     tdmx.setTdmx_fdywbh(bsNo);
1286                     tdmx.setTdmx_fdwlgsbh(lg.getDepartno());
1287                     tdmx.setTdmx_tdls(td.getTd_tdls());
1288                     this.tdmxper.updateFDBatch(tdmx);
1289
1290                     Vehicle_XSTD vhx=this.vhxper.getbyIDs(fdv1.getVehicleId(), td.getTd_tdbh(),lg.getDepartno());
1291                     if(vhx==null){
1292                         vhx=new Vehicle_XSTD();
1293                         vhx.setBsNo(bsNo);
1294                         vhx.setCompanyNo(lg.getDepartno());
1295                         vhx.setFd_num(fdsl);
1296                         vhx.setFd_weight(fdmz);
1297                         vhx.setVehicleId(fdv1.getVehicleId());
1298                         vhx.setXstdNo(td.getTd_tdbh());
1299                          this.vhxper.insert(vhx);
1300                     }else{
1301                         vhx.setBsNo(bsNo);
1302                         vhx.setCompanyNo(lg.getDepartno());
1303                         vhx.setFd_num(vhx.getFd_num()+fdsl);
1304                         vhx.setFd_weight(BigDecimalfiter.add(vhx.getFd_weight(),fdmz));
1305                         vhx.setVehicleId(fdv1.getVehicleId());
1306                         vhx.setXstdNo(td.getTd_tdbh());
1307                         this.vhxper.updatewithIDs(vhx);
1308                     }
1309                     td.setTd_wfdsl(td.getTd_wfdsl() - fdsl);
1310                     td.setTd_wfdzl(BigDecimalfiter.subscal(td.getTd_wfdzl(), fdmz, Contants.scale));
1311                     this.tdper.updateFD(td);
1312                     mxMp.put(td.getTd_tdbh(), mxl);
1313                 }
1314             }
1315
1316             if (saveBT) {
1317                 YktBsheet bs = new YktBsheet();
1318                 bs.setSdepartNo(bsDE);
1319                 /*bs.setDcompany(
1320                         bsDE.equals(Contants.kjSdepartNo) ? "明泰科技"
1321                         :bsDE.equals(Contants.msSdepartNo) ? "河南明晟新材料"
1322                         : "郑州眀泰");*/
1323                 bs.setDcompany(ConvertTool.covertToFactoryName(bsDE));
1324                 bs.setDriver(fdv1.getDriver());
1325
1326                 bs.setNumberplates(StringUtils.upperCase(fdv1.getVehicleId()));
1327                 bs.setPhone(fdv1.getPhone());
1328                 bs.setRcompany(StringUtils.isBlank(Rcompany) ? "未知发货单位" : Rcompany);
1329                 bs.setBussinessNo(fb.getBsNo());
1330                 bs.setNote(ziti + ";" + lg.getDepartname() + ":" + lg.getWorkername() + "; 分单系统自动生成");
1331                 String bsStr = Jacksonmethod.tojson(bs, false);
1332                 JsonObject joADDYWD = Wxhtmethod.postJsonStr(Contants.YKTaddYwd_url, bsStr);
1333                 ObjectResult<String> ors = new ObjectResult<String>();
1334                 ors = JSONobj.getobj(joADDYWD, ors);
1335                 if (ors.getCode() != 0) {
1336                     throw new Exception(ors.getErrmsg());
1337                 }
1338             }else {
1339                 List<WaitXSTD> l=this.fdbsper.getAllKH(bsNo, fb.getId());
1340                 if(l!=null) {
1341                     boolean iscz=false;//收货单位在明细中是否存在
1342                     WaitXSTD wt=null;
1343                     for (WaitXSTD waitXSTD : l) {
1344                         if(fb.getShdw().equals(waitXSTD.getTd_khmc())) {
1345                             iscz=true;
1346                             break;
1347                         }else {
1348                             if(wt==null&&StringUtils.isNotBlank(waitXSTD.getTd_khmc())) {
1349                                 wt=waitXSTD;
1350                             }
1351                         }
1352                     }
1353                     if(!iscz&&wt!=null) {
1354                         fb.setShdw(wt.getTd_khmc());
1355                         this.yktmper.updateshcompany(bsNo, wt.getTd_khmc(),wt.getTd_shdd());
1356                     }
1357                 }
1358
1359             }
1360
1361             if (tdl != null && tdl.size() > 0 ) {
1362                 String fdhx = this.fdtonc.getNcdata(tdl, mxMp);
1363                 Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "整单配车 请求参数 ::" + fdhx);
1364                 JsonObject joADDYWD = Wxhtmethod.postJsonStr(Contants.NCfdhx_url, fdhx);
1365                 Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "整单配车 返回值 ::" + joADDYWD);
1366                 if (joADDYWD == null || JSONobj.getint(joADDYWD, "code") != 0) {
1367                     throw new Exception(
1368                             (joADDYWD.get("msg")==null||StringUtils.isBlank(joADDYWD.get("msg").getAsString())) ? "分单回写NC系统出错!"
1369                             : joADDYWD.get("msg").getAsString());
1370                 } else {
1371                     String restult = joADDYWD.get("result").getAsString();
1372                     JsonObject jr = jp.parse(restult).getAsJsonObject();
1373                     if (jr == null || JSONobj.getint(jr, "respcode") != 111) {
1374                         throw new Exception(jr.get("respmsg").getAsString());
1375                     }
1376                 }
1377             }
1378         } catch (Exception e) {
1379             if (saveBT) {
1380                 JsonObject jo = new JsonObject();
1381                 jo.addProperty("bussinessNo", bsNo);
1382                 jo.addProperty("sdepartNo", bsDE);
1383                 Wxhtmethod.postJsonStr(Contants.YKTdelYwd_url, jo.toString());
1384             }
1385             e.printStackTrace();
1386             throw new Exception(e.getMessage());
1387         }
1388         orr.setCode(0);
1389         orr.setItem(true);
1390         return orr;
1391     }
1392
1393     @Override
1394     @Transactional(rollbackFor = Exception.class)
1395     public ObjectResult<Boolean> dounBindByList(Login lg, String tdbhlist) throws Exception {
1396         ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
1397         if (lg == null) {
1398             orr.setCode(1);
1399             orr.setErrmsg("请登录账号!");
1400             return orr;
1401         }
1402         if (StringUtils.isBlank(tdbhlist)) {
1403             orr.setCode(1);
1404             orr.setErrmsg("业务参数为空,请选择提单!");
1405             return orr;
1406         }
1407         if (UserType.admin.toString().equals(lg.getWorkerno())) {
1408             orr.setCode(1);
1409             orr.setErrmsg("管理员不能操作分单!");
1410             return orr;
1411         }
1412         Fd_Company fdc = null;
1413         if (StringUtils.isNotBlank(lg.getDepartno())) {
1414             fdc = fdcper.getByCompanyNo(lg.getDepartno());
1415             if (fdc == null) {
1416                 orr.setCode(1);
1417                 orr.setErrmsg("账号没有配置物流公司,请联系管理员进行配置!");
1418                 return orr;
1419             }
1420         }
1421
1422         // for循环 tdbhlist
1423         // 查找td_xstd 对象 筛选是否有操作权限
1424         // 修改 td_xstdmx 表 修改 td_xstd 表 修改 vehicle_xstd表
1425         JsonParser jp = new JsonParser();
1426         JsonArray tdja = jp.parse(tdbhlist).getAsJsonArray();
1427         List<Fd_XSTD> tdl = new ArrayList<Fd_XSTD>();
1428         Map<String, List<Fd_XSTDMX>> mxMp = new HashMap<String, List<Fd_XSTDMX>>();
1429         for (JsonElement tdje : tdja) {
1430             String tdNo = tdje.getAsString();
1431             Fd_XSTD td = this.tdper.getbyTDBH(tdNo);
1432             if (td == null) {
1433                 continue;
1434             }
1435             // 这一块是判断用户有没有这个提单的操作权限 :
1436             //页面获取提单里诶包信息的时候已经加过校验  当前用户只能看到可以操作的提单  不可以操作的提单看不到
1437             // 这一块可以省略
1438             // 自提
1439 //            if (td.getTd_ztbz() == 2) {
1440 //                if (fdc != null) {
1441 //                    if (!fdc.isHasSPR()) {
1442 //                        continue;
1443 //                    }
1444 //                }
1445 //            } else {
1446 //                Fd_wlgs_fhdq dq = this.dqper.getbyNos(lg.getDepartno(), td.getTd_shddbh(),
1447 //                        td.getTd_ywdybh().equals(Contants.zzywdyNo) ? Contants.zzywdyNo : "103");
1448 //                if (dq == null) {
1449 //                    continue;
1450 //                }
1451 //            }
1452
1453
1454             // 如果该业务单已经装车 过滤掉不处理
1455             //这一块应该在页面中提示出来:提示:销售提单:XXXX 部分明细已经装车,请进入提单明细取消配车!
1456             List<Vehicle_XSTD> vxl = this.vhxper.getbyxstdNoandcmNo(tdNo, lg.getDepartno());
1457             if (vxl != null) {
1458                 boolean sffd=false;
1459                 for (Vehicle_XSTD vx : vxl) {
1460                     int zcsl = this.tdmxper.getbyBsNowithZC(vx.getBsNo(),td.getTd_tdls(),vx.getVehicleId());
1461                     if (zcsl > 0) {
1462                         sffd=true;
1463                         break;
1464                     }
1465                     Fd_Bsheet fb=this.fdbsper.getbyVehicleId(vx.getVehicleId(), Serviceenum.在办, lg.getSdepartNo());
1466                     if(fb !=null) {
1467                         fb.setUpdateTime(new Date());
1468                         this.fdbsper.update(fb);
1469                     }
1470                 }
1471                 if(sffd) {
1472                     continue;
1473                 }
1474             } else {
1475                 continue;
1476             }
1477
1478
1479             List<Fd_XSTDMX> mxl = this.tdmxper.getbytdlsandcmNo(td.getTd_tdls(), lg.getDepartno());
1480             List<Fd_XSTDMX> rels = new ArrayList<Fd_XSTDMX>();
1481             if (mxl != null) {
1482                 int wfdsl = 0;
1483                 double wfdzl = 0;
1484                 for (Fd_XSTDMX mx : mxl) {
1485                     // 提单明细未关闭的做处理
1486                     wfdsl++;
1487                     wfdzl = BigDecimalfiter.addscal(wfdzl, mx.getTdmx_mz(), Contants.scale);
1488                     mx.setTdmx_fdbz(0);
1489                     mx.setTdmx_fdcph(null);
1490                     mx.setTdmx_fdwlgsbh(null);
1491                     mx.setTdmx_fdywbh(null);
1492                     rels.add(mx);
1493                 }
1494
1495                 this.tdmxper.updatebytdlsandcmNo(td.getTd_tdls(), lg.getDepartno());
1496
1497                 this.vhxper.delbyIDandcomNo(td.getTd_tdbh(),lg.getDepartno());
1498
1499                 td.setTd_wfdsl(td.getTd_wfdsl() + wfdsl);
1500                 td.setTd_wfdzl(BigDecimalfiter.addscal(td.getTd_wfdzl(), wfdzl, Contants.scale));
1501                 this.tdper.updateFD(td);
1502                 if (wfdsl > 0) {
1503                     tdl.add(td);
1504                     mxMp.put(tdNo, rels);
1505                 }
1506             }
1507         }
1508
1509
1510         // 发送NC系统
1511         if (tdl != null && tdl.size() > 0) {
1512             String fdhx = this.fdtonc.getNcdata(tdl, mxMp);
1513             Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "整单取消配车 请求参数 ::" + fdhx);
1514             JsonObject joADDYWD = Wxhtmethod.postJsonStr(Contants.NCfdhx_url, fdhx);
1515             Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "整单取消配车 返回值 ::" + joADDYWD);
1516             if (joADDYWD == null || JSONobj.getint(joADDYWD, "code") != 0) {
1517                 throw new Exception(
1518                         (joADDYWD.get("msg")==null||StringUtils.isBlank(joADDYWD.get("msg").getAsString())) ? "分单回写NC系统出错!"
1519                         : joADDYWD.get("msg").getAsString());
1520             } else {
1521                 String restult = joADDYWD.get("result").getAsString();
1522                 JsonObject jr = jp.parse(restult).getAsJsonObject();
1523                 if (jr == null || JSONobj.getint(jr, "respcode") != 111) {
1524                     throw new Exception(jr.get("respmsg").getAsString());
1525                 }
1526             }
1527         }
1528         orr.setCode(0);
1529         return orr;
1530     }
1531
1532     @Override
1533     @Transactional(rollbackFor = Exception.class)
1534     public ObjectResult<Boolean> sxccCheck(String bsNo, String vehicleId, String ZZ) throws Exception {
1535         ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
1536         Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(),"出门检查 业务参数:::: ::ZZ::" + ZZ + "::bsNo::" + bsNo + "::vehicleId::" + vehicleId);
1537         if (StringUtils.isBlank(vehicleId)) {
1538             orr.setCode(1);
1539             orr.setErrmsg("车牌号为空!");
1540             return orr;
1541         }
1542         if (StringUtils.isBlank(bsNo)) {
1543             orr.setCode(1);
1544             orr.setErrmsg("一卡通业务单号为空!");
1545             return orr;
1546         }
1547         //先删除错误信息
1548         errPer.delBybsNo(bsNo);
1549         try {
1550             Fd_Bsheet fdb = fdbsper.getbybsNo(bsNo);
1551             if (fdb != null) {
1552                 fdb.setStatus(Serviceenum.结束);
1553                 fdbsper.update(fdb);
1554             }
1555             Fd_Vehicle fdv = vhper.getByVehicleId(vehicleId);
1556             if (fdv != null) {
1557                 if (fdv.getType() == VehicleType.临时车) {
1558                     Fd_Bsheet fdbb=this.fdbsper.getbyVehicleWithNoSdepartNo(vehicleId,fdb.getSdepartNo());
1559                     if(fdbb==null) {
1560                         vhper.delByVehicleId(vehicleId);
1561                     }
1562                     this.fdvcper.delbyID(vehicleId, fdb.getSdepartNo());
1563                 } else {
1564                     fdv.setStatus(VehicleStatus.未配车);
1565                     vhper.update(fdv);
1566                     this.fdvcper.delIDandNoC(vehicleId, fdv.getCompanyNo(), fdb.getSdepartNo());
1567                 }
1568             }
1569             // 查找fd_vehicle 判断车辆信息是否正确 修改 fd_vehicle 修改fd_vehicle_company
1570             // 查找fd_bsheet 判断业务状态 修改 fd_bsheet
1571             // 查找fd_xstdmx 表 按照业务单号,车牌号,查找已分单未装车的
1572             // 修改 fd_xstdmx fd_xstd fd_vehicle_xstd
1573
1574             List<Fd_XSTDMX> mxl = this.tdmxper.getbybsNoandNOZCandFD(fdb == null ? "" : fdb.getBsNo());
1575             List<Fd_XSTD> tdl = new ArrayList<Fd_XSTD>();
1576             Map<String, Fd_XSTD> tdM = new HashMap<String, Fd_XSTD>();
1577             Map<String, List<Fd_XSTDMX>> mxMp = new HashMap<String, List<Fd_XSTDMX>>();
1578
1579 //            Map<String, Fd_XSTD> rmtd = new HashMap<String, Fd_XSTD>();
1580             if (mxl != null) {
1581                 for (Fd_XSTDMX mx : mxl) {
1582                     // 已经关闭的明细不做处理
1583                     if (mx.getTdmx_gbbz() != 0) {
1584                         continue;
1585                     }
1586 //                    Fd_XSTD td = this.tdper.get(mx.getTdmx_tdls());
1587 //                    if (td != null) {
1588 //                        td.setTd_wfdsl(td.getTd_wfdsl() + 1);
1589 //                        td.setTd_wfdzl(BigDecimalfiter.addscal(td.getTd_wfdzl(), mx.getTdmx_mz(), Contants.scale));
1590 //                        tdper.updateFD(td);
1591 //                        tdM.put(td.getTd_tdbh(), td);
1592 //                    }
1593                     Fd_XSTD tdtt=tdM.get(mx.getTdmx_tdls());
1594                     if(tdtt==null) {
1595                         tdtt = this.tdper.get(mx.getTdmx_tdls());
1596                         if(tdtt==null) {
1597                             continue;
1598                         }
1599                     }
1600                     tdtt.setTd_wfdsl(tdtt.getTd_wfdsl()+1);
1601                     tdtt.setTd_wfdzl(BigDecimalfiter.addscal(tdtt.getTd_wfdzl(), mx.getTdmx_mz(), Contants.scale));
1602                     tdM.put(mx.getTdmx_tdls(), tdtt);
1603
1604                     mx.setTdmx_fdbz(0);
1605                     mx.setTdmx_fdcph(null);
1606                     mx.setTdmx_fdwlgsbh(null);
1607                     mx.setTdmx_fdywbh(null);
1608 //                    this.tdmxper.updateFD(mx);
1609                     if (mxMp.get(tdtt.getTd_tdbh()) != null) {
1610                         List<Fd_XSTDMX> lr = mxMp.get(tdtt.getTd_tdbh());
1611                         lr.add(mx);
1612                         mxMp.put(tdtt.getTd_tdbh(), lr);
1613                     } else {
1614                         List<Fd_XSTDMX> lr = new ArrayList<Fd_XSTDMX>();
1615                         lr.add(mx);
1616                         mxMp.put(tdtt.getTd_tdbh(), lr);
1617                     }
1618                 }
1619                 this.tdmxper.updatebybsNoandNOZCandFD(fdb.getBsNo());
1620
1621                 this.vhxper.delbyVehicleId(vehicleId,fdb.getBsNo() );
1622
1623                 if (tdM != null && tdM.size() > 0) {
1624                     for (Entry<String, Fd_XSTD> ff : tdM.entrySet()) {
1625                         tdl.add(ff.getValue());
1626                         this.tdper.updateFD(ff.getValue());
1627                     }
1628                 }
1629             }
1630
1631
1632 //            List<Vehicle_XSTD> vxls = this.vhxper.getlistbyVehicleId(vehicleId);
1633 //            if (vxls != null) {
1634 //                for (Vehicle_XSTD vxx : vxls) {
1635 //                    this.vhxper.delbyIDs(vehicleId, vxx.getXstdNo());
1636 //                }
1637 //            }
1638             // 发送NC系统
1639             if (tdl != null && tdl.size() > 0) {
1640                 String fdhx = this.fdtonc.getNcdata(tdl, mxMp);
1641                 Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "出门检查 请求参数 ::" + fdhx);
1642                 JsonObject joADDYWD = Wxhtmethod.postJsonStr(Contants.NCfdhx_url, fdhx);
1643                 Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "出门检查 返回值 ::" + joADDYWD);
1644                 if (joADDYWD == null || JSONobj.getint(joADDYWD, "code") != 0) {
1645                     throw new Exception(
1646                             (joADDYWD.get("msg")==null||StringUtils.isBlank(joADDYWD.get("msg").getAsString())) ? "分单回写NC系统出错!"
1647                             : joADDYWD.get("msg").getAsString());
1648                 } else {
1649                     String restult = joADDYWD.get("result").getAsString();
1650                     JsonParser jp = new JsonParser();
1651                     JsonObject jr = jp.parse(restult).getAsJsonObject();
1652                     if (jr == null || JSONobj.getint(jr, "respcode") != 111) {
1653                         throw new Exception(jr.get("respmsg").getAsString());
1654                     }
1655                 }
1656             }
1657         } catch (Exception e) {
1658             throw new Exception(StringUtils.isEmpty(e.getMessage()) ? "销售业务车辆出厂程序出错!" : e.getMessage());
1659         }
1660         orr.setCode(0);
1661         return orr;
1662     }
1663
1664     @Override
1665     @Transactional(rollbackFor = Exception.class)
1666     public ObjectResult<Boolean> doUnbind(Login lg, String mlist, String tdNo) throws Exception {
1667         ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
1668         if (lg == null) {
1669             orr.setCode(1);
1670             orr.setErrmsg("请登录账号!");
1671             return orr;
1672         }
1673         if (StringUtils.isEmpty(mlist)) {
1674             orr.setCode(1);
1675             orr.setErrmsg("业务参数为空!");
1676             return orr;
1677         }
1678         if (StringUtils.isEmpty(tdNo)) {
1679             orr.setCode(1);
1680             orr.setErrmsg("提单编号为空!");
1681             return orr;
1682         }
1683         if (UserType.admin.toString().equals(lg.getWorkerno())) {
1684             orr.setCode(1);
1685             orr.setErrmsg("管理员没有分单权限!");
1686             return orr;
1687         }
1688         Fd_Company fdc = fdcper.getByCompanyNo(lg.getDepartno());
1689         if (fdc == null) {
1690             orr.setCode(1);
1691             orr.setErrmsg("该账号没有配置物流公司!");
1692             return orr;
1693         }
1694
1695         // 查找fd_xstd表 判断物流公司是否有操作权限 如果有装车明细不让删除完
1696         // for循环mlist 判断 fd_xstdmx是否符合条件
1697         // 修改fd_xstdmx 表 修改 vehicle_xstd表 修改fd_company_xstd表:只在取消分单和出门的时候删除
1698         // 修改 fd_xstd 表
1699
1700         Fd_XSTD td = this.tdper.getbyTDBH(tdNo);
1701         if (td == null) {
1702             orr.setCode(1);
1703             orr.setErrmsg("提单未找到!");
1704             return orr;
1705         }
1706         if (td.isTd_zcwcbz()) {
1707             orr.setCode(1);
1708             orr.setErrmsg("该提单已经完成装车,不能分单!");
1709             return orr;
1710         }
1711         // 自提
1712         if (td.getTd_ztbz() == 2) {
1713             if (fdc != null) {
1714                 if (!fdc.isHasSPR()) {
1715                     orr.setCode(1);
1716                     orr.setErrmsg("该账号没有自提权限!");
1717                     return orr;
1718                 }
1719             }
1720         } else {
1721             Fd_wlgs_fhdq wldq = this.dqper.getbyNos(lg.getDepartno(), td.getTd_shddbh(),
1722                     /*td.getTd_ywdybh().equals(Contants.nc_ywdy_ZZ) ? Contants.nc_ywdy_ZZ
1723                             :td.getTd_ywdybh().equals(Contants.nc_ywdy_MS) ? Contants.nc_ywdy_MS
1724                             : Contants.nc_ywdy_KJ*/
1725                     ConvertTool.ncGetDefault(td.getTd_ywdybh())
1726             );
1727
1728             int total = fdMxWlgsMapper.selectCountByTdTdls(td.getTd_tdls());
1729             if (wldq == null && total == 0) {
1730                 orr.setCode(1);
1731                 orr.setErrmsg("当前账号所属物流公司没有配置该地区的分单权限!");
1732                 return orr;
1733             }
1734         }
1735         JsonParser jp = new JsonParser();
1736         JsonArray mArr = jp.parse(mlist).getAsJsonArray();
1737         // 分单数量和毛重
1738         int fdsl = 0;
1739         double fdmz = 0;
1740         List<Fd_XSTD> tdl = new ArrayList<Fd_XSTD>();
1741         Map<String, List<Fd_XSTDMX>> mxMp = new HashMap<String, List<Fd_XSTDMX>>();
1742         List<Fd_XSTDMX> tdmxl = new ArrayList<Fd_XSTDMX>();
1743         Map<String, Fd_XSTD> rm=new HashMap<String, Fd_XSTD>();
1744         for (JsonElement mJe : mArr) {
1745             JsonObject jo = mJe.getAsJsonObject();
1746             // 提单分录号
1747             String tdfl = JSONobj.getstring(jo, "tdfl");
1748             String vehicleId = JSONobj.getstring(jo, "vehicleId");
1749             Fd_XSTDMX mx = this.tdmxper.get(tdfl);
1750             if (mx != null) {
1751                 // 没有分单的跳过
1752                 if (mx.getTdmx_fdbz() == 0) {
1753                     continue;
1754                 }
1755                 // 已经装车的报错
1756                 if (mx.getTdmx_zcbz() != 0) {
1757                     continue;
1758                 }
1759                 // 没有关闭明细做处理
1760                 if (mx.getTdmx_gbbz() == 0) {
1761                     fdsl++;
1762                     fdmz = BigDecimalfiter.addscal(fdmz, mx.getTdmx_mz(), Contants.scale);
1763
1764                     Fd_XSTD ttr=rm.get(vehicleId+"_"+mx.getTdmx_fdwlgsbh());
1765                     if(ttr!=null) {
1766                         ttr.setTd_wfdsl(ttr.getTd_wfdsl()+1);
1767                         ttr.setTd_wfdzl(BigDecimalfiter.addscal(ttr.getTd_wfdzl(), mx.getTdmx_mz(), Contants.scale));
1768                         rm.put(vehicleId+"_"+mx.getTdmx_fdwlgsbh(), ttr);
1769                     }else {
1770                         ttr=new Fd_XSTD();
1771                         ttr.setTd_wfdsl(1);
1772                         ttr.setTd_wfdzl(BigDecimalfiter.addscal(0, mx.getTdmx_mz(), Contants.scale));
1773                         rm.put(vehicleId+"_"+mx.getTdmx_fdwlgsbh(), ttr);
1774                     }
1775                 }
1776
1777                 mx.setTdmx_fdbz(0);
1778                 mx.setTdmx_fdcph(null);
1779                 mx.setTdmx_fdwlgsbh(null);
1780                 mx.setTdmx_fdywbh(null);
1781                 this.tdmxper.updateFD(mx);
1782                 tdmxl.add(mx);
1783
1784             }
1785         }
1786         Iterator<Entry<String, Fd_XSTD>> entries = rm.entrySet().iterator();
1787         while (entries.hasNext()) {
1788           Entry<String, Fd_XSTD> entry = entries.next();
1789           Vehicle_XSTD vxs = this.vhxper.getbyIDs(entry.getKey().split("_")[0], td.getTd_tdbh(),entry.getKey().split("_")[1]);
1790           if (vxs != null) {
1791               if (vxs.getFd_num() == 1) {
1792                   this.vhxper.delbyIDs(entry.getKey().split("_")[0], td.getTd_tdbh(),entry.getKey().split("_")[1]);
1793               } else {
1794                   vxs.setFd_num(vxs.getFd_num() - entry.getValue().getTd_wfdsl());
1795                   vxs.setFd_weight(BigDecimalfiter.subscal(vxs.getFd_weight(), entry.getValue().getTd_wfdzl(), Contants.scale));
1796                   this.vhxper.updatewithIDs(vxs);
1797               }
1798               Fd_Bsheet fb=this.fdbsper.getbyVehicleId(vxs.getVehicleId(), Serviceenum.在办, lg.getSdepartNo());
1799               if(fb !=null) {
1800                 fb.setUpdateTime(new Date());
1801                 this.fdbsper.update(fb);
1802              }
1803           }
1804         }
1805         td.setTd_wfdsl(td.getTd_wfdsl() + fdsl);
1806         td.setTd_wfdzl(BigDecimalfiter.addscal(td.getTd_wfdzl(), fdmz, Contants.scale));
1807         this.tdper.updateFD(td);
1808         if (fdsl > 0) {
1809             tdl.add(td);
1810             mxMp.put(td.getTd_tdbh(), tdmxl);
1811         }
1812
1813         // 发送NC
1814         if (tdl != null && tdl.size() > 0) {
1815             String fdhx = this.fdtonc.getNcdata(tdl, mxMp);
1816             Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "明细取消配车 请求参数 ::" + fdhx);
1817             JsonObject joADDYWD = Wxhtmethod.postJsonStr(Contants.NCfdhx_url, fdhx);
1818             Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "明细取消配车 返回值 ::" + joADDYWD);
1819             if (joADDYWD == null || JSONobj.getint(joADDYWD, "code") != 0) {
1820                 throw new Exception(
1821                         (joADDYWD.get("msg")==null||StringUtils.isBlank(joADDYWD.get("msg").getAsString())) ? "分单回写NC系统出错!"
1822                         : joADDYWD.get("msg").getAsString());
1823             } else {
1824                 String restult = joADDYWD.get("result").getAsString();
1825                 JsonObject jr = jp.parse(restult).getAsJsonObject();
1826                 if (jr == null || JSONobj.getint(jr, "respcode") != 111) {
1827                     throw new Exception(jr.get("respmsg").getAsString());
1828                 }
1829             }
1830         }
1831
1832         orr.setCode(0);
1833         orr.setItem(true);
1834         return orr;
1835     }
1836
1837     @Override
1838     public ObjectResult<String> tzPrint(String cardno, String ipadda,String cqNo) {
1839         ObjectResult<String> orr = new ObjectResult<String>();
1840         if (StringUtils.isBlank(cardno)) {
1841             orr.setCode(1);
1842             orr.setErrmsg("提单编号为空!");
1843             return orr;
1844         }
1845         if (StringUtils.isBlank(ipadda)) {
1846             orr.setCode(1);
1847             orr.setErrmsg("批次号为空!");
1848             return orr;
1849         }
1850         Map<String, Object> cardinuse = this.yktmper.getcardinuse(cardno);
1851         if (cardinuse == null) {
1852             orr.setCode(1);
1853             orr.setErrmsg("在用卡未找到!");
1854             return orr;
1855         }
1856         Fd_Vehicle fd_v = this.vhper.getByVehicleId(cardinuse.get("numberplates") + "");
1857         if (fd_v == null) {
1858             orr.setCode(1);
1859             orr.setErrmsg("车辆" + cardinuse.get("numberplates").toString() + "分单系统未找到!");
1860             return orr;
1861         }
1862         Fd_Bsheet fd_b = this.fdbsper.getbyVehicleId(fd_v.getVehicleId(), Serviceenum.在办, cqNo);
1863         if (fd_b == null) {
1864             orr.setCode(1);
1865             orr.setErrmsg("车辆未找到在办分单!");
1866             return orr;
1867         }
1868         String dyAdd = this.bsper.getUsedbyAdd();
1869         if (StringUtils.isBlank(dyAdd)) {
1870             orr.setCode(1);
1871             orr.setErrmsg("系统未设置打印地址!");
1872             return orr;
1873         }
1874         try {
1875             orr.setItem("http://" + dyAdd + Contants.GYPrintAdd + "&vehicleId="
1876                     + URLEncoder.encode(fd_v.getVehicleId(), "utf-8") + "&bsNo=" + fd_b.getBsNo() + "&phone="
1877                     + fd_b.getPhone() + "&comNo=");
1878             // log.info("::::::::::;"+orr.getItem());
1879         } catch (UnsupportedEncodingException e) {
1880             e.printStackTrace();
1881         }
1882         // 存打印日志:方便以后查找
1883
1884         orr.setCode(0);
1885         return orr;
1886
1887     }
1888
1889     @Override
1890     @Transactional(rollbackFor = Exception.class)
1891     public ObjectResult<Boolean> delbyPCH(Login lg, String tdNo, String pch, String cph,String bsNo) throws Exception {
1892         ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
1893         if (lg == null) {
1894             orr.setCode(1);
1895             orr.setErrmsg("请登录账号!");
1896             return orr;
1897         }
1898         if (StringUtils.isEmpty(tdNo)) {
1899             orr.setCode(1);
1900             orr.setErrmsg("提单编号为空!");
1901             return orr;
1902         }
1903         if (StringUtils.isEmpty(pch)) {
1904             orr.setCode(1);
1905             orr.setErrmsg("批次号为空!");
1906             return orr;
1907         }
1908         Fd_Bsheet fdb = this.fdbsper.getbybsNo(bsNo);//getbyVehicleId(cph, Serviceenum.在办);
1909         if (fdb == null) {
1910             orr.setCode(1);
1911             orr.setErrmsg("车牌号:" + cph + " 业务单未找到!");
1912             return orr;
1913         }
1914         if (fdb.getStatus()!=Serviceenum.在办) {
1915             orr.setCode(1);
1916             orr.setErrmsg("车牌号:" + cph + " 业务单不是在办状态!");
1917             return orr;
1918         }
1919         Fd_Company fdc = fdcper.getByCompanyNo(lg.getDepartno());
1920         if (fdc == null) {
1921             orr.setCode(1);
1922             orr.setErrmsg("账号没有配置物流公司!");
1923             return orr;
1924         }
1925         // 根据提单号找到 fd_xstd 判断xstd数据
1926         // 根据批次号和提单流水号找到 fd_xstdmx 判断xstdmx数据
1927         // 如果是已经装车了 至少保留一件
1928         // 修改fd_xstdmx vehicle_xstd表
1929         Fd_XSTD td = this.tdper.getbyTDBH(tdNo);
1930         if (td == null) {
1931             orr.setCode(1);
1932             orr.setErrmsg("提单号:" + tdNo + " 未找到!");
1933             return orr;
1934         }
1935         // Fd_XSTDMX mx=this.tdmxper.getbyPCH(pch);
1936         Fd_XSTDMX mx = this.tdmxper.getbyPCHandTDNOONE(pch, td.getTd_tdbh());
1937         if (mx == null) {
1938             orr.setCode(1);
1939             orr.setErrmsg("提单明细未找到!");
1940             return orr;
1941         }
1942         if (mx.getTdmx_zcbz() != 0) {
1943             orr.setCode(1);
1944             orr.setErrmsg("明细已经装车不能删除!");
1945             return orr;
1946         }
1947         if (!mx.getTdmx_tdls().equals(td.getTd_tdls())) {
1948             orr.setCode(1);
1949             orr.setErrmsg("参数错误,明细不属于该提单!");
1950             return orr;
1951         }
1952         // 已经分单了未关闭
1953         if (mx.getTdmx_fdbz() != 0 && mx.getTdmx_gbbz() == 0) {
1954             fdb.setUpdateTime(new Date());
1955             this.fdbsper.update(fdb);
1956             List<Fd_XSTD> tdl = new ArrayList<Fd_XSTD>();
1957             Map<String, List<Fd_XSTDMX>> mxMp = new HashMap<String, List<Fd_XSTDMX>>();
1958             List<Fd_XSTDMX> mxl = new ArrayList<Fd_XSTDMX>();
1959
1960             mx.setTdmx_fdbz(0);
1961             mx.setTdmx_fdcph(null);
1962             mx.setTdmx_fdwlgsbh(null);
1963             mx.setTdmx_fdywbh(null);
1964             this.tdmxper.updateFD(mx);
1965             Vehicle_XSTD vx = this.vhxper.getbyIDs(cph, tdNo,lg.getDepartno());
1966             if (vx != null) {
1967                 if (vx.getFd_num() > 1) {
1968                     vx.setFd_num(vx.getFd_num() - 1);
1969                     vx.setFd_weight(BigDecimalfiter.subscal(vx.getFd_weight(), mx.getTdmx_mz(), Contants.scale));
1970                     this.vhxper.updatewithIDs(vx);
1971                 } else {
1972                     this.vhxper.delbyIDs(cph, tdNo,lg.getDepartno());
1973                 }
1974             }
1975             td.setTd_wfdsl(td.getTd_wfdsl() + 1);
1976             td.setTd_wfdzl(BigDecimalfiter.addscal(td.getTd_wfdzl(), mx.getTdmx_mz(), Contants.scale));
1977             this.tdper.updateFD(td);
1978             tdl.add(td);
1979             mxl.add(mx);
1980             mxMp.put(tdNo, mxl);
1981             // 发送NC
1982             if (tdl != null && tdl.size() > 0) {
1983                 String fdhx = this.fdtonc.getNcdata(tdl, mxMp);
1984                 Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "批次号取消配车 请求参数 ::" + fdhx);
1985                 JsonObject joADDYWD = Wxhtmethod.postJsonStr(Contants.NCfdhx_url, fdhx);
1986                 Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "批次号取消配车 返回值 ::" + joADDYWD);
1987                 if (joADDYWD == null || JSONobj.getint(joADDYWD, "code") != 0) {
1988                     throw new Exception(
1989                             (joADDYWD.get("msg")==null||StringUtils.isBlank(joADDYWD.get("msg").getAsString())) ? "分单回写NC系统出错!"
1990                             : joADDYWD.get("msg").getAsString());
1991                 } else {
1992                     String restult = joADDYWD.get("result").getAsString();
1993                     JsonParser jp = new JsonParser();
1994                     JsonObject jr = jp.parse(restult).getAsJsonObject();
1995                     if (jr == null || JSONobj.getint(jr, "respcode") != 111) {
1996                         throw new Exception(jr.get("respmsg").getAsString());
1997                     }
1998                 }
1999             }
2000
2001         }
2002
2003         orr.setCode(0);
2004         orr.setItem(true);
2005         return orr;
2006     }
2007
2008     @Override
2009     @Transactional(rollbackFor = Exception.class)
2010     public ObjectResult<Boolean> closeXstd(String vehicleId, String driver, String phone, String xstdNo, Login lg)
2011             throws Exception {
2012         ObjectResult<Boolean> or = new ObjectResult<Boolean>();
2013         if (lg == null) {
2014             or.setCode(1);
2015             or.setErrmsg("请重新登录账号!");
2016             return or;
2017         }
2018         // 根据xstdNo查找fd_xstd信息 vehicle_xstd
2019         // 判断vehicle_xstd的销售提单的状态
2020         // 查找fd_xstdmx
2021         // for循环 list<fd_xstdmx> 获取未分单未装车
2022         // 修改fd_xstdmx 修改Fd_Gbxstd, Fd_Gbxstdmx,修改fd_xstd
2023         if (StringUtils.isEmpty(xstdNo)) {
2024             or.setCode(1);
2025             or.setErrmsg("销售提单号为空,不能执行该操作!");
2026             return or;
2027         }
2028         if (!StringUtils.isEmpty(vehicleId)) {
2029             if (!RegexCheck.isVehicleID(vehicleId)) {
2030                 or.setCode(1);
2031                 or.setErrmsg("请输入正确的车牌号!");
2032                 return or;
2033             }
2034         }
2035         if (!StringUtils.isEmpty(phone)) {
2036             if (!RegexCheck.checkphone(phone)) {
2037                 or.setCode(1);
2038                 or.setErrmsg("请输入正确的手机号!");
2039                 return or;
2040             }
2041         }
2042
2043         Fd_Gbxstd gbtd = gbtdper.get(xstdNo);
2044         if (gbtd != null) {
2045             or.setCode(1);
2046             or.setErrmsg("销售提单:" + xstdNo + " 已经有关闭记录,不能保存重复的关闭记录!");
2047             return or;
2048         }
2049         List<Vehicle_XSTD> vxl = vhxper.getlistbytdNo(xstdNo);
2050         if (vxl != null && vxl.size() > 0) {
2051             or.setCode(1);
2052             or.setErrmsg("销售提单:" + xstdNo + " 已经分单给:" + vxl.get(0).getVehicleId() + ",不能执行该操作!");
2053             return or;
2054         }
2055         Fd_XSTD tdx = this.tdper.getbyttdbh(xstdNo);
2056         if (tdx == null) {
2057             or.setCode(1);
2058             or.setErrmsg("销售提单:" + xstdNo + "未找到,不能执行该操作!");
2059             return or;
2060         }
2061         Fd_Company fdc = new Fd_Company();
2062         if (!UserType.admin.toString().equals(lg.getWorkerno())) {
2063             fdc = fdcper.getByCompanyNo(lg.getDepartno());
2064             if (fdc == null) {
2065                 or.setCode(1);
2066                 or.setErrmsg("登录账号未指定物流公司!");
2067                 return or;
2068             }
2069             // 自提
2070             if (tdx.getTd_ztbz() == 2) {
2071                 if (!fdc.isHasSPR()) {
2072                     or.setCode(1);
2073                     or.setErrmsg("该账号没有操作该提单的权限!");
2074                     return or;
2075                 }
2076             } else {
2077                 String shdqbh = tdx.getTd_shddbh();
2078                 Fd_wlgs_fhdq acb = this.dqper.getbyNos(lg.getDepartno(), shdqbh,
2079                         /*tdx.getTd_ywdybh().equals(Contants.nc_ywdy_ZZ) ? Contants.nc_ywdy_ZZ
2080                                 :tdx.getTd_ywdybh().equals(Contants.nc_ywdy_MS) ? Contants.nc_ywdy_MS
2081                                 : Contants.nc_ywdy_KJ*/
2082                     ConvertTool.ncGetDefault(tdx.getTd_ywdybh())
2083                 );
2084
2085                 int total = fdMxWlgsMapper.selectCountByTdTdls(tdx.getTd_tdls());
2086                 if (acb == null && total == 0) {
2087                     or.setCode(1);
2088                     or.setErrmsg("账号没有操作该提单的权限!");
2089                     return or;
2090                 }
2091             }
2092         }
2093
2094         List<Fd_XSTDMX> mxL = this.tdmxper.getforClose(tdx.getTd_tdls());
2095         int dd = 0;
2096         double cc = 0;
2097         if (mxL != null) {
2098             for (Fd_XSTDMX mx : mxL) {
2099                 dd++;
2100                 cc = BigDecimalfiter.addscal(cc, mx.getTdmx_mz(), Contants.scale);
2101                 mx.setTdmx_zcbz(1);
2102                 mx.setTdmx_zccph(vehicleId);
2103                 mx.setTdmx_zcdriver(driver);
2104                 mx.setTdmx_zcphone(phone);
2105                 mx.setTdmx_zcwlgsName(lg.getDepartname());
2106                 this.tdmxper.updateZCANDFD(mx);
2107                 Fd_Gbxstdmx gb = this.gbtdmxper.get(mx.getTdmx_tdfl());
2108                 if (gb == null) {
2109                     gb = new Fd_Gbxstdmx();
2110                     gb.setId(mx.getTdmx_tdfl());
2111                     gb.setTdfl(mx.getTdmx_tdfl());
2112                     gb.setPch(mx.getTdmx_pch());
2113                     gb.setTdNo(tdx.getTd_tdbh());
2114                     this.gbtdmxper.insert(gb);
2115                 }
2116             }
2117         }
2118         tdx.setTd_wfdsl(0);
2119         tdx.setTd_wfdzl(0);
2120         this.tdper.updateFD(tdx);
2121         if (dd > 0) {
2122             gbtd = new Fd_Gbxstd();
2123             gbtd.setCompanyNo(lg.getDepartname() == null ? "管理员关闭" : lg.getDepartname());
2124             gbtd.setHSR(tdx.getTd_ztbz() == 2);
2125             gbtd.setTd_gbr(lg.getWorkername());
2126             gbtd.setTd_gbsj(new Date());
2127             gbtd.setTd_gbsl(dd);
2128             gbtd.setTd_gbzl(cc);
2129             gbtd.setVehicleId(vehicleId);
2130             gbtd.setXstdNo(xstdNo);
2131             this.gbtdper.insert(gbtd);
2132         }
2133
2134         or.setCode(0);
2135         return or;
2136     }
2137
2138     @Override
2139     @Transactional(rollbackFor = Exception.class)
2140     public ObjectResult<Boolean> openXstd(String xstdNo, Login lg) throws Exception {
2141
2142         ObjectResult<Boolean> or = new ObjectResult<Boolean>();
2143         if (lg == null) {
2144             or.setCode(1);
2145             or.setErrmsg("请重新登录账号!");
2146             return or;
2147         }
2148         if (StringUtils.isEmpty(xstdNo)) {
2149             or.setCode(1);
2150             or.setErrmsg("销售提单号为空,不能执行该操作!");
2151             return or;
2152         }
2153         // 关闭之后不让打开了
2154
2155         // 根据xstdNo查找fd_xstd信息 vehicle_xstd
2156         // 判断vehicle_xstd的销售提单的状态
2157         // 查找fd_xstdmx
2158         // for循环 list<fd_xstdmx> 获取未分单未装车
2159         // 修改fd_xstdmx 修改Fd_Gbxstd, Fd_Gbxstdmx,修改fd_xstd
2160
2161         Fd_Gbxstd gbtd = gbtdper.get(xstdNo);
2162         if (gbtd == null) {
2163             or.setCode(1);
2164             or.setErrmsg("销售提单:" + xstdNo + " 未找到关闭记录,不能恢复销售提单!");
2165             return or;
2166         }
2167         if (BasicMethod.after(gbtd.getTd_gbsj(), 7)) {
2168             or.setCode(1);
2169             or.setErrmsg("已关闭超过7天,不能恢复提单!");
2170             return or;
2171         }
2172         List<Vehicle_XSTD> vxl = vhxper.getlistbytdNo(xstdNo);
2173         if (vxl != null && vxl.size() > 0) {
2174             or.setCode(1);
2175             or.setErrmsg("销售提单:" + xstdNo + " 有在办的分车单,不能执行该操作!");
2176             return or;
2177         }
2178         Fd_XSTD tdx = this.tdper.getbyttdbh(xstdNo);
2179         if (tdx == null) {
2180             or.setCode(1);
2181             or.setErrmsg("销售提单:" + xstdNo + "未找到,不能执行该操作!");
2182             return or;
2183         }
2184         Fd_Company fdc = new Fd_Company();
2185         if (!UserType.admin.toString().equals(lg.getWorkerno())) {
2186             fdc = fdcper.getByCompanyNo(lg.getDepartno());
2187             if (fdc == null) {
2188                 or.setCode(1);
2189                 or.setErrmsg("登录账号未指定物流公司!");
2190                 return or;
2191             }
2192             // 自提
2193             if (tdx.getTd_ztbz() == 2) {
2194                 if (!fdc.isHasSPR()) {
2195                     or.setCode(1);
2196                     or.setErrmsg("该账号没有操作该提单的权限!");
2197                     return or;
2198                 }
2199             } else {
2200                 String shdqbh = tdx.getTd_shddbh();
2201                 Fd_wlgs_fhdq acb = this.dqper.getbyNos(lg.getDepartno(), shdqbh,
2202                         /*tdx.getTd_ywdybh().equals(Contants.nc_ywdy_ZZ) ? Contants.nc_ywdy_ZZ
2203                                 :tdx.getTd_ywdybh().equals(Contants.nc_ywdy_MS) ? Contants.nc_ywdy_MS
2204                                 : Contants.nc_ywdy_KJ*/
2205                         ConvertTool.ncGetDefault(tdx.getTd_ywdybh())
2206                 );
2207                 int total = fdMxWlgsMapper.selectCountByTdTdls(tdx.getTd_tdls());
2208                 if (acb == null && total == 0) {
2209                     or.setCode(1);
2210                     or.setErrmsg("该账号没有操作该提单的权限!");
2211                     return or;
2212                 }
2213             }
2214         }
2215
2216         List<Fd_Gbxstdmx> mxL = this.gbtdmxper.getList(xstdNo);
2217         int dd = 0;
2218         if (mxL != null) {
2219             for (Fd_Gbxstdmx mx : mxL) {
2220                 Fd_XSTDMX tdmx = this.tdmxper.getbytdflAndtdls(mx.getId(), tdx.getTd_tdls());
2221                 tdmx.setTdmx_zcbz(0);
2222                 tdmx.setTdmx_zccph(null);
2223                 tdmx.setTdmx_zcdriver(null);
2224                 tdmx.setTdmx_zcphone(null);
2225                 tdmx.setTdmx_zcwlgsName(null);
2226                 dd++;
2227                 this.tdmxper.updateZCANDFD(tdmx);
2228                 this.gbtdmxper.delbyId(mx.getId());
2229             }
2230         }
2231         if (dd > 0) {
2232             tdx.setTd_wfdsl(gbtd.getTd_gbsl());
2233             tdx.setTd_wfdzl(gbtd.getTd_gbzl());
2234             this.tdper.updateFD(tdx);
2235             this.gbtdper.del(xstdNo);
2236         }
2237
2238         or.setCode(0);
2239         return or;
2240     }
2241
2242     @Override
2243     @Transactional(rollbackFor = Exception.class)
2244     @Deprecated
2245     public ObjectResult<Boolean> changeVehicle(Login lg, String bsNo, String vehicleInfo) throws Exception {
2246         ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
2247         if (lg == null) {
2248             orr.setCode(1);
2249             orr.setErrmsg("请登录账号!");
2250             return orr;
2251         }
2252         if (true) {
2253             orr.setCode(1);
2254             orr.setErrmsg("该方法不可用!");
2255             return orr;
2256         }
2257         if (UserType.admin.toString().equals(lg.getWorkerno())) {
2258             orr.setCode(1);
2259             orr.setErrmsg("管理员不能执行该操作!");
2260             return orr;
2261         }
2262         if (StringUtils.isEmpty(bsNo) || StringUtils.isEmpty(vehicleInfo)) {
2263             orr.setCode(1);
2264             orr.setErrmsg("业务参数为空!");
2265             return orr;
2266         }
2267         Fd_Bsheet fdb = fdbsper.getbybsNo(bsNo);
2268         if (fdb == null) {
2269             orr.setCode(1);
2270             orr.setErrmsg("业务单未找到!");
2271             return orr;
2272         }
2273         String vehicleId = fdb.getVehicleId();
2274         Fd_Vehicle fdv = vhper.getByVehicleId(vehicleId);
2275         if (fdv == null) {
2276             orr.setCode(1);
2277             orr.setErrmsg("原来的车牌未找到!");
2278             return orr;
2279         }
2280         JsonParser jp = new JsonParser();
2281         JsonElement je = jp.parse(vehicleInfo);
2282         JsonObject jo = je.getAsJsonObject();
2283         String nvehicleId = JSONobj.getstring(jo, "vehicleId");
2284         String driver = JSONobj.getstring(jo, "driver");
2285         String phone = JSONobj.getstring(jo, "phone");
2286         double vehicleweight = JSONobj.getdouble(jo, "vehicleweight");
2287         double loadweight = JSONobj.getdouble(jo, "loadweight");
2288         String feature = JSONobj.getstring(jo, "feature");
2289         String note = JSONobj.getstring(jo, "note");
2290         String IDNum = JSONobj.getstring(jo, "IDNum");
2291         if (StringUtils.isEmpty(vehicleId) || StringUtils.isEmpty(driver) || StringUtils.isEmpty(IDNum)
2292                 || StringUtils.isEmpty(phone)) {
2293             orr.setCode(1);
2294             orr.setErrmsg("车辆必填信息不能为空!");
2295             return orr;
2296         }
2297         Fd_Vehicle nfdv = vhper.getByVehicleId(nvehicleId);
2298         if (nfdv != null && nfdv.getStatus() != VehicleStatus.未配车) {
2299             orr.setCode(1);
2300             orr.setErrmsg("车辆:" + nvehicleId + "状态不是未配车状态,不能使用!");
2301             return orr;
2302         }
2303
2304         // 临时车直接删除
2305         if (fdv.getType() == VehicleType.临时车) {
2306             vhper.delByVehicleId(fdv.getVehicleId());
2307         } else {
2308             fdv.setStatus(VehicleStatus.未配车);
2309             vhper.update(fdv);
2310         }
2311
2312         // 修改vehicle_xstd表
2313         List<Vehicle_XSTD> lc = vhxper.getlistbycomNo(lg.getDepartno());
2314         // List<Vehicle_XSTD> lc=vhxper.getlistbyVehicleId(fdv.getVehicleId());
2315         if (lc != null) {
2316             for (Vehicle_XSTD vx : lc) {
2317                 if (vx.getVehicleId().equals(fdv.getVehicleId())) {
2318                     vx.setVehicleId(nvehicleId);
2319                     vhxper.updatewithIDs(vx);
2320                 }
2321             }
2322         }
2323         if (nfdv == null) {
2324             nfdv = new Fd_Vehicle();
2325             nfdv.setCompanyNo(lg.getDepartno());
2326             nfdv.setDriver(driver);
2327             nfdv.setId(UUID.randomUUID() + "");
2328             nfdv.setLoadweight(loadweight);
2329             nfdv.setNote(note);
2330             nfdv.setPhone(phone);
2331             nfdv.setState(true);
2332             nfdv.setFeature(feature);
2333             nfdv.setStatus(VehicleStatus.已配车);
2334             nfdv.setType(VehicleType.临时车);
2335             nfdv.setVehicleId(nvehicleId);
2336             nfdv.setVehicleweight(vehicleweight);
2337             nfdv.setIDNum(IDNum);
2338             vhper.insert(nfdv);
2339         }
2340
2341         // 换车用不用发送短信
2342
2343         orr.setCode(0);
2344         orr.setItem(true);
2345         return orr;
2346     }
2347
2348     @Override
2349     @Transactional(rollbackFor = Exception.class)
2350     @Deprecated
2351     public ObjectResult<Boolean> saveZcInfo(Scxt_zcInfo zc) throws Exception {
2352         ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
2353         if (zc == null) {
2354             orr.setCode(1);
2355             orr.setErrmsg("参数为空不能保存!");
2356             return orr;
2357         }
2358         if (true) {
2359             orr.setCode(1);
2360             orr.setErrmsg("该方法已作废!");
2361             return orr;
2362         }
2363         String zcvehicleID = zc.getCph();// 车牌号
2364         String pch = zc.getPch();// 批次号
2365         String tdbh = zc.getTdbh();// 提单编号
2366         Fd_Vehicle fdv = vhper.getByVehicleId(zcvehicleID);
2367         if (fdv == null) {
2368             orr.setCode(1);
2369             orr.setErrmsg("分单系统未找到该车牌号!");
2370             return orr;
2371         }
2372         Map<String, Object> bsmp =null;// bsper.getbsbyBt(zcvehicleID, Contants.cpxsBtNo, Serviceenum.在办,Contants.kjSdepartNo);
2373         if (bsmp == null) {
2374             orr.setCode(1);
2375             orr.setErrmsg("该车辆没有找到一卡通业务单!");
2376             return orr;
2377         }
2378         String dbsign = tdbh.split("-")[0];
2379         // Fd_Erpconfig erpdb=erpper.getbySign(dbsign);
2380         // if(erpdb==null){
2381         // orr.setCode(1);
2382         // orr.setErrmsg("根据提单编号未找到配置的数据库数据源!");
2383         // return orr;
2384         // }
2385         // Map<String, Object> bsim=bsper.getbsi(pch, bsmp.get("bussinessNo")+"" );
2386         // if(bsim!=null){
2387         // orr.setCode(1);
2388         // orr.setErrmsg("该成品已经装车!");
2389         // return orr;
2390         // }
2391         // try {
2392         // String
2393         // url="jdbc:jtds:sqlserver://"+erpdb.getUri()+":"+erpdb.getPost()+";databaseName="+erpdb.getDb();
2394         // Connection con=ddbdao.open(url, erpdb.getUsername(),
2395         // erpdb.getPwd(),erpdb.getDbsign());
2396         // if(con==null){
2397         // ddbdao.close();
2398         // orr.setCode(1);
2399         // orr.setErrmsg("erp数据库链接失败,请查询erp配置是否正确!");
2400         // return orr;
2401         // }
2402         // String sql=SqlTxt.GYErpXSTDsql+" where EXISTS (SELECT 1 FROM XSTDMX WHERE
2403         // XSTDMX_TDLS=XSTD_TDLS AND XSTDMX_CKBZ='0') and a.XSTD_TDBH='"+tdbh+"' and
2404         // a.XSTD_SHBZ=1 and a.XSTD_TDBZ='LD' ";
2405         // Map<String, Object> tdmp=ddbdao.getmapnoclose(sql,erpdb.getDbsign());
2406         // if(tdmp==null){
2407         // orr.setCode(1);
2408         // orr.setErrmsg("销售提单未找到!");
2409         // ddbdao.close();
2410         // return orr;
2411         // }
2412         // WaitXSTD wt=new WaitXSTD();
2413         // BeanUtils.populate(wt, tdmp);
2414         //
2415         // //判断该车辆有没有操作该提单的权限
2416         // if(true){
2417         //
2418         // }
2419         // sql=SqlTxt.GYErpXSTDMXsql+" where b.XSTDMX_CKBZ='0' and
2420         // a.XSTD_TDBH='"+tdbh+"' and b.XSTDMX_PCH='"+pch+"' ";//销售提单明细
2421         // Map<String, Object> mxmp=ddbdao.getmapnoclose(sql,erpdb.getDbsign());
2422         // if(mxmp==null){
2423         // orr.setCode(1);
2424         // orr.setErrmsg("根据提单号和批次号Erp未找到销售提单明细!");
2425         // ddbdao.close();
2426         // return orr;
2427         // }
2428         // WaitXSTDMX wtdmx=new WaitXSTDMX();
2429         // BeanUtils.populate(wtdmx, mxmp);
2430         // String hj=mxmp.get("hj")==null?"":mxmp.get("hj")+"";
2431         // String zt=mxmp.get("zt")==null?"":mxmp.get("zt")+"";
2432         // wtdmx.setTdmx_hjzt(hj+"/"+zt);
2433         // //如果扫的是没有分单的
2434         // if(wtdmx.getTdmx_fdbz()==0){
2435         // sql=SqlTxt.XGGYErpXSTDMXsql+" where a.XSTDMX_CKBZ='0' and
2436         // b.XSTD_TDBH='"+tdbh+"' and a.XSTDMX_PCH='"+pch+"' ";//修改销售提单明细
2437         // List<Object> ll=new ArrayList<Object>();
2438         // ll.add(zcvehicleID);//车牌号
2439         // ll.add(2);//分单标志
2440         // ll.add(bsmp.get("bussinessNo")+"");//分单单据编号
2441         // ddbdao.modifySql(sql, ll,erpdb.getDbsign());
2442         //
2443         // sql=SqlTxt.XGGYErpXSTDsql;//修改销售提单
2444         // ll.clear();
2445         // ll.add(wt.getTd_wfdsl()-1);//未分单数量
2446         // ll.add(BigDecimalfiter.subscal(wt.getTd_wfdzl(), wtdmx.getTdmx_mz(),
2447         // Contants.scale));//未分单毛重
2448         // ll.add(tdbh);
2449         // ddbdao.modifySql(sql, ll,erpdb.getDbsign());
2450         // }
2451         //
2452         // if(fdv.getStatus()!=VehicleStatus.已装车){
2453         // fdv.setStatus(VehicleStatus.已装车);
2454         // vhper.update(fdv);
2455         // }
2456         // Fd_Bsheetitem fbi=bsiper.getbyLsandFl(wtdmx.getTdmx_tdls(),
2457         // wtdmx.getTdmx_tdfl(),tdbh);
2458         // //该车辆有没有添加
2459         // Vehicle_XSTD vhx=vhxper.getbyIDs(zcvehicleID, tdbh);
2460         // //已经分单
2461         // if(fbi!=null){
2462         // //未分到当前车辆
2463         // if(!fbi.getTdmx_cph().equals(zcvehicleID)){
2464         // Vehicle_XSTD vhx1=vhxper.getbyIDs(zcvehicleID, tdbh);
2465         // //该车辆已添加销售提单
2466         // if(vhx!=null){
2467         // vhx.setFd_num(vhx.getFd_num()+1);
2468         // vhx.setFd_weight(BigDecimalfiter.addscal(vhx.getFd_weight(),wtdmx.getTdmx_mz()
2469         // ,Contants.scale ));
2470         // vhxper.update(vhx);
2471         // }else{
2472         // vhx=new Vehicle_XSTD();
2473         // vhx.setFd_num(1);
2474         // vhx.setFd_weight(BigDecimalfiter.addscal(wtdmx.getTdmx_mz(), 0,
2475         // Contants.scale));
2476         // vhx.setVehicleId(zcvehicleID);
2477         // vhx.setXstdNo(tdbh);
2478         // vhx.setBsNo( bsmp.get("bussinessNo")+"");
2479         // vhxper.insert(vhx);
2480         // }
2481         // if(vhx1.getFd_num()==1){
2482         // vhxper.delbyIDs(vhx1.getVehicleId(), vhx1.getXstdNo());
2483         // }else{
2484         // vhx1.setFd_num(vhx1.getFd_num()-1);
2485         // vhx1.setFd_weight(BigDecimalfiter.subscal(vhx1.getFd_weight(),
2486         // wtdmx.getTdmx_mz(), Contants.scale));
2487         // vhxper.update(vhx1);
2488         // }
2489         // fbi.setTdmx_cph(zcvehicleID);
2490         // }
2491         //// fbi.setTdmx_cph(zcvehicleID);
2492         // fbi.setTdmx_tdbh(tdbh);
2493         // fbi.setTdmx_fdbz(2);
2494         // fbi.setTdmx_fdywbh(bsmp.get("bussinessNo")+"" );
2495         // fbi.setTdmx_zccph(zcvehicleID);
2496         // fbi.setTdmx_sfzc(1);
2497         // fbi.setBarcode(zc.getTmh());
2498         // bsiper.update(fbi);
2499         // }else{
2500         // fbi=new Fd_Bsheetitem();
2501         // fbi.setId(UUID.randomUUID()+"");
2502         // fbi.setCompanyName("");
2503         // fbi.setCompanyNo("");
2504         // fbi.setCreateid("");
2505         // fbi.setBarcode(zc.getTmh());
2506         // fbi.setCtime(new Date());
2507         // fbi.setTdmx_cph(zcvehicleID);
2508         // fbi.setTdmx_tdbh(tdbh);
2509         // fbi.setTdmx_fdbz(2);
2510         // fbi.setTdmx_fdywbh(bsmp.get("bussinessNo")+"" );
2511         // fbi.setTdmx_zccph(zcvehicleID);
2512         // fbi.setTdmx_sfzc(1);
2513         // bsiper.insert(fbi);
2514         // //该装车车辆添加了这个提单的分单
2515         // if(vhx!=null){
2516         // vhx.setFd_num(vhx.getFd_num()+1);
2517         // vhx.setFd_weight(BigDecimalfiter.addscal(vhx.getFd_weight(),wtdmx.getTdmx_mz()
2518         // ,Contants.scale ));
2519         // vhxper.update(vhx);
2520         // }else{
2521         // vhx=new Vehicle_XSTD();
2522         // vhx.setFd_num(1);
2523         // vhx.setFd_weight(BigDecimalfiter.addscal(wtdmx.getTdmx_mz(), 0,
2524         // Contants.scale));
2525         // vhx.setVehicleId(zcvehicleID);
2526         // vhx.setXstdNo(tdbh);
2527         // vhxper.insert(vhx);
2528         // }
2529         // }
2530         //
2531         //
2532         //
2533         // //添加一卡通明细;
2534         // Map<String, Object> mm=new HashMap<String, Object>();
2535         // mm.put("id", UUID.randomUUID()+"");
2536         // mm.put("bussinessNo",bsmp.get("bussinessNo")+"" );
2537         // mm.put("name", wtdmx.getTdmx_wlmc());
2538         // mm.put("materielNo",wtdmx.getTdmx_wlbh() );
2539         // mm.put("norms",wtdmx.getTdmx_ggxh() );
2540         // mm.put("unitname", "Kg");
2541         // mm.put("num", 1);
2542         // mm.put("note", null);
2543         // mm.put("weight", BigDecimalfiter.mulcon(wtdmx.getTdmx_jz(), 1000,
2544         // Contants.scale));
2545         // mm.put("price", 0);
2546         // mm.put("preweight",BigDecimalfiter.mulcon(wtdmx.getTdmx_jz(), 1000,
2547         // Contants.scale));
2548         // mm.put("pici", pch);
2549         // mm.put("hejin", wtdmx.getTdmx_hjzt());
2550         // mm.put("gross",BigDecimalfiter.mulcon(wtdmx.getTdmx_mz(), 1000,
2551         // Contants.scale) );
2552         // mm.put("taotong","" );
2553         // mm.put("taotongWeight", BigDecimalfiter.subscal(wtdmx.getTdmx_mz()*1000,
2554         // wtdmx.getTdmx_jz()*1000, Contants.scale));
2555         // mm.put("money", 0);
2556         //
2557         //// mm.put("createid", );
2558         //// mm.put("cname", );
2559         //// mm.put("createid", 0);
2560         // mm.put("cdepartid", 0);
2561         //// mm.put("cdepart", );
2562         // mm.put("ctime", new Date());
2563         //
2564         // mm.put("loadbuild", false);
2565         // mm.put("factory", false);
2566         // mm.put("fachang", true);
2567         // mm.put("fcnum", 0);
2568         // mm.put("product_billNo", tdbh);
2569         // mm.put("product_serialNo",wtdmx.getTdmx_tdls());
2570         // mm.put("product_otherNo", null);
2571         //// mm.put("product_ywrq",wtdmx.gettdmx_ );
2572         // mm.put("product_flh", wtdmx.getTdmx_tdfl());
2573         // mm.put("recompany",wtdmx.getTdmx_shdw() );
2574         //// mm.put("reID", "");
2575         // mm.put("decompany", wtdmx.getTdmx_fhdw()==null?"明泰科技":wtdmx.getTdmx_fhdw());
2576         //// mm.put("deID", "");
2577         // mm.put("rcompany",wtdmx.getTdmx_shdw() );
2578         //// mm.put("rID", );
2579         // mm.put("frombatch", "ERP系统");
2580         // mm.put("forshowindx",1 );
2581         // mm.put("barcode",zc.getTmh());
2582         // mm.put("reserved11",0 );
2583         // mm.put("reserved12",0 );
2584         // mm.put("reserved13",0 );
2585         // mm.put("jsnum",0 );
2586         //
2587         // bsper.insertBsi(mm);
2588         // } catch (Exception e) {
2589         // ddbdao.robackclose();
2590         // throw new
2591         // Exception(StringUtils.isEmpty(e.getMessage())?"添加装车信息出错!":e.getMessage());
2592         // }finally{
2593         // ddbdao.close();
2594         // }
2595
2596         orr.setCode(0);
2597         orr.setItem(true);
2598         return orr;
2599     }
2600
2601     @Override
2602     @Transactional(rollbackFor = Exception.class)
2603     @Deprecated
2604     public ObjectResult<Boolean> sxinCheck(String bsNo, String vehicleId) throws Exception {
2605         ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
2606         if (StringUtils.isEmpty(vehicleId)) {
2607             orr.setCode(1);
2608             orr.setErrmsg("车牌号为空!");
2609             return orr;
2610         }
2611         if (StringUtils.isEmpty(bsNo)) {
2612             orr.setCode(1);
2613             orr.setErrmsg("一卡通业务单号为空!");
2614             return orr;
2615         }
2616         if (true) {
2617             orr.setCode(1);
2618             orr.setErrmsg("该方法已经弃用!");
2619             return orr;
2620         }
2621         Fd_Bsheet fdb = fdbsper.getbybsNo(bsNo);
2622         if (fdb == null) {
2623             orr.setCode(1);
2624             orr.setErrmsg("业务单未找到!");
2625             return orr;
2626         }
2627         Fd_Vehicle fdv = vhper.getByVehicleId(vehicleId);
2628         if (fdv == null) {
2629             orr.setCode(1);
2630             orr.setErrmsg("业务车辆未找到!");
2631             return orr;
2632         }
2633         try {
2634         } catch (Exception e) {
2635             throw new Exception(StringUtils.isEmpty(e.getMessage()) ? "销售业务车辆进厂程序出错!" : e.getMessage());
2636         }
2637         orr.setCode(0);
2638         orr.setItem(true);
2639         return orr;
2640     }
2641
2642     @Override
2643     @Deprecated
2644     public ObjectResult<Boolean> delZcInfo(Scxt_zcInfo zc) throws Exception {
2645         ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
2646         if (zc == null) {
2647             orr.setCode(1);
2648             orr.setErrmsg("业务参数为空!");
2649             return orr;
2650         }
2651         if (true) {
2652             orr.setCode(1);
2653             orr.setErrmsg("该方法已经弃用!");
2654             return orr;
2655         }
2656         String tmh = zc.getTmh();// 条码号
2657         String cph = zc.getCph();// 车牌号
2658         String cardno = zc.getYktkh();// 一卡通卡号
2659         Map<String, Object> cdi = yktmper.getcardinuse(cardno);
2660         if (cdi == null) {
2661             orr.setCode(1);
2662             orr.setErrmsg("该卡一卡通未找到,请确认该卡是否正确!");
2663             return orr;
2664         }
2665         if (cdi.get("numberplates") == null) {
2666             orr.setCode(1);
2667             orr.setErrmsg("该卡没有配置车牌号,请确认该卡是否可用!");
2668             return orr;
2669         }
2670         Fd_Vehicle fdv = vhper.getByVehicleId(cph);
2671         if (fdv == null) {
2672             orr.setCode(1);
2673             orr.setErrmsg("未找到该分单车牌号!");
2674             return orr;
2675         }
2676         Map<String, Object> bsmp = null;//bsper.getbsbyBt(cph, Contants.cpxsBtNo, Serviceenum.在办, Contants.kjSdepartNo);
2677         if (bsmp == null) {
2678             orr.setCode(1);
2679             orr.setErrmsg("该车辆没有找到在办的一卡通业务单!");
2680             return orr;
2681         }
2682         if (StringUtils.isEmpty(bsmp.get("bussinessNo") + "")) {
2683             orr.setCode(1);
2684             orr.setErrmsg("一卡通业务单未找到!");
2685             return orr;
2686         }
2687         int wdi = yktmper.getweight_doc(bsmp.get("bussinessNo") + "");
2688         if (wdi <= 0) {
2689             orr.setCode(1);
2690             orr.setErrmsg("该车辆还未称重,请先去磅房称重!");
2691             return orr;
2692         }
2693         // Fd_Bsheetitem fd_b=bsiper.getbyNoandCode(tmh, bsmp.get("bussinessNo")+"" );
2694         // if(fd_b!=null){
2695         // String tdNo=fd_b.getTdmx_tdbh();//提单编号
2696         // bsper.delbysibyBarcode(tmh, bsmp.get("bussinessNo")+"" );
2697         // Vehicle_XSTD v_x=vhxper.getbyIDs(cph, tdNo);
2698         // if(v_x!=null){
2699         // if(v_x.getFd_num()>1){
2700         // v_x.setFd_num(v_x.getFd_num()-1);
2701         // v_x.setFd_weight(BigDecimalfiter.subscal(v_x.getFd_weight(),
2702         // fd_b.getTdmx_mz(), Contants.scale));
2703         // vhxper.update(v_x);
2704         // fdv.setStatus(VehicleStatus.已装车);
2705         // vhper.update(fdv);
2706         // }else{
2707         // Map<String, Object> cc=vhxper.getbyVehcleId(cph, v_x.getBsNo());
2708         // if(cc!=null){
2709         // if(cc.get("fd_nums")!=null){
2710         // int fd_nums=Integer.parseInt(cc.get("fd_nums")+"");
2711         // if(fd_nums>1){
2712         // fdv.setStatus(VehicleStatus.已装车);
2713         // vhper.update(fdv);
2714         // }else{
2715         // vhxper.delbyIDs(cph, tdNo);
2716         // fdv.setStatus(VehicleStatus.已进厂);
2717         // vhper.update(fdv);
2718         // }
2719         // }else{
2720         // vhxper.delbyIDs(cph, tdNo);
2721         // fdv.setStatus(VehicleStatus.已进厂);
2722         // vhper.update(fdv);
2723         // }
2724         // }else{
2725         // vhxper.delbyIDs(cph, tdNo);
2726         // fdv.setStatus(VehicleStatus.已进厂);
2727         // vhper.update(fdv);
2728         // }
2729         // }
2730         // }else{
2731         // fdv.setStatus(VehicleStatus.已进厂);
2732         // vhper.update(fdv);
2733         // }
2734         // }
2735
2736         orr.setCode(0);
2737         orr.setItem(true);
2738         return orr;
2739     }
2740
2741     @Override
2742     @Deprecated
2743     public Map<String, Object> getClInfo(String cardno) {
2744         Map<String, Object> mp = new HashMap<String, Object>();
2745         Map<String, Object> cdi = yktmper.getcardinuse(cardno);
2746         if (cdi == null) {
2747             mp.put("code", 1);
2748             mp.put("errmsg", "该卡一卡通未找到,请确认该卡是否发放!");
2749             return mp;
2750         }
2751         if (cdi.get("numberplates") == null) {
2752             mp.put("code", 1);
2753             mp.put("errmsg", "该卡没有配置车牌号,请确认该卡是否可用!");
2754             return mp;
2755         }
2756         String vehicleId = cdi.get("numberplates") + "";
2757         Map<String, Object> bsmap = yktmper.getBsheet(vehicleId, Contants.cpxsBtNo, Serviceenum.在办, "04");
2758         if (bsmap == null) {
2759             mp.put("code", 1);
2760             mp.put("errmsg", "该卡没有在办的一卡通销售业务单!");
2761             return mp;
2762         }
2763         Fd_Bsheet fb =null ;//fdbsper.getbyVehicleId(vehicleId, Serviceenum.在办);
2764         if (fb == null) {
2765             mp.put("code", 1);
2766             mp.put("errmsg", "在办分车业务单未找到!");
2767             return mp;
2768         }
2769         int c = this.yktmper.getweight_doc(fb.getBsNo());
2770         if (c <= 0) {
2771             mp.put("code", 1);
2772             mp.put("errmsg", "业务单未找到磅单,请先去过磅!");
2773             return mp;
2774         }
2775         List<Vehicle_XSTD> vxl = new ArrayList<Vehicle_XSTD>();
2776         // List<Vehicle_XSTD> vxl=this.vhxper.getlistbyVehicleId(vehicleId);
2777         mp.put("tdbhs", null);
2778         if (vxl == null || vxl.size() <= 0) {
2779             mp.put("code", 1);
2780             mp.put("errmsg", "未找到销售提单!");
2781             return mp;
2782         } else {
2783             String cc = "";
2784             for (Vehicle_XSTD vx : vxl) {
2785                 if (StringUtils.isEmpty(cc)) {
2786                     cc += vx.getXstdNo();
2787                 } else {
2788                     cc += "," + vx.getXstdNo();
2789                 }
2790             }
2791             mp.put("tdbhs", cc);
2792         }
2793
2794         mp.put("code", 0);
2795         mp.put("cph", fb.getVehicleId());
2796         mp.put("sjmc", fb.getDriver());
2797         mp.put("dh", fb.getPhone());
2798         mp.put("ywdh", fb.getBsNo());
2799         return mp;
2800     }
2801
2802     @Override
2803     @Transactional(rollbackFor = Exception.class)
2804     @Deprecated
2805     public ObjectResult<Boolean> batchSaveZcInfo(String zclist) throws Exception {
2806
2807         ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
2808         if (StringUtils.isEmpty(zclist)) {
2809             orr.setCode(1);
2810             orr.setErrmsg("参数为空不能保存!");
2811             return orr;
2812         }
2813         if (true) {
2814             orr.setCode(1);
2815             orr.setErrmsg("方法已经弃用!");
2816             return orr;
2817         }
2818         // String Lcuuid=UUID.randomUUID()+"";
2819         // try {
2820         // JsonParser jp=new JsonParser();
2821         // JsonArray ja=jp.parse(zclist).getAsJsonArray();
2822         // int eachline=0;
2823         // //是否检查车辆
2824         // boolean checkVehicle=true;
2825         // String bussinessNo="";
2826         // Fd_Vehicle fdv=null;
2827         // Fd_Bsheet fdb=null;
2828         // Map<String, Fd_Erpconfig> dberpmp=new HashMap<String, Fd_Erpconfig>();
2829         // double mzweight=0;
2830         // String instanceID="";
2831         // Map<String, Object> lm=new HashMap<String, Object>();
2832         // for (JsonElement tdje : ja) {
2833         // if(lm.size()>1){
2834         // break;
2835         // }
2836         // JsonObject jo=tdje.getAsJsonObject();
2837         // Scxt_zcInfo zc=new Scxt_zcInfo();
2838         // eachline++;
2839         // zc=JSONobj.getobj(jo, zc);
2840         // if(zc==null){
2841         // continue;
2842         // }
2843         // String tdNo=zc.getTdbh();
2844         // if(!StringUtils.isEmpty(tdNo)){
2845         // String tdsign=tdNo.split("-")[0];
2846         // if(lm.get(tdsign)==null){
2847         // lm.put(tdsign, "abc");
2848         // }
2849         // }
2850         // }
2851         // if(lm.size()>1){
2852         //// boolean lcboo=ddbdao.getLcmps(Lcuuid);
2853         // String dbcheck=DBchecksingleton.setDbc(Lcuuid,false);
2854         // if(!Lcuuid.equals(dbcheck)){
2855         // throw new Exception("ERP数据库正在被占用,请重新操作!");
2856         // }
2857         // }
2858         // List<Fd_Company> fdcl=this.fdcper.getall();
2859         // Map<String, String> fdcm=new HashMap<String, String>();
2860         // if(fdcl!=null){
2861         // for (Fd_Company fdc : fdcl) {
2862         // if(!fdc.isHasSPR()){
2863         // fdcm.put(fdc.getCompanyNo(), fdc.getName());
2864         // }
2865         // }
2866         // }
2867         // for (JsonElement je : ja) {
2868         // JsonObject jo=je.getAsJsonObject();
2869         // Scxt_zcInfo zc=new Scxt_zcInfo();
2870         // eachline++;
2871         // zc=JSONobj.getobj(jo, zc);
2872         // if(zc==null){
2873         // continue;
2874         // }
2875         //
2876         //
2877         // if(StringUtils.isEmpty(zc.getCph())||StringUtils.isEmpty(zc.getTdbh())||StringUtils.isEmpty(zc.getPch())){
2878         // continue;
2879         // }
2880         // String dbsign=zc.getTdbh().split("-")[0];
2881         // Fd_Erpconfig erpdb=null;
2882         // if(dberpmp.get(dbsign)==null){
2883         // erpdb=erpper.getbySign(dbsign);
2884         // if(erpdb==null){
2885         // throw new Exception("提单编号是"+dbsign+"-******* 类型的未配置ERP数据库!");
2886         // }
2887         // dberpmp.put(dbsign, erpdb);
2888         // }else{
2889         // erpdb=dberpmp.get(dbsign);
2890         // }
2891         // if(checkVehicle){
2892         // fdv=vhper.getByVehicleId(zc.getCph());
2893         // if(fdv==null){
2894         // throw new Exception("分单系统车牌号:"+zc.getCph()+" 未找到,请确认车辆信息是否正确!");
2895         // }
2896         // Map<String, Object> bsmp=bsper.getbsbyBt(zc.getCph(), Contants.cpxsBtNo,
2897         // Serviceenum.在办, Contants.ssdepartNo);
2898         // if(bsmp==null){
2899         // throw new Exception("车牌号:"+zc.getCph()+" 未找到一卡通业务单!");
2900         // }
2901         // bussinessNo=bsmp.get("bussinessNo")+"";
2902         // instanceID=bsmp.get("instanceID")==null?"":bsmp.get("instanceID")+"";
2903         // fdb=fdbsper.getbybsNo(bussinessNo);
2904         // if(fdb==null){
2905         // throw new Exception("车牌号:"+zc.getCph()+" 未找到分单业务单!");
2906         // }else{
2907         // if(!fdb.getVehicleId().equals(zc.getCph())){
2908         // throw new Exception("车牌号:"+zc.getCph()+"与 分单车牌号不一致!");
2909         // }
2910         // }
2911         // checkVehicle=false;
2912         // }
2913         //
2914         // Vehicle_XSTD vhx=vhxper.getbyIDs(zc.getCph(), zc.getTdbh());
2915         // if(vhx==null){
2916         // throw new Exception("提单编号:"+zc.getTdbh()+"没有分单给车牌号:"+zc.getCph()+" !");
2917         // }
2918         // String
2919         // url="jdbc:jtds:sqlserver://"+erpdb.getUri()+":"+erpdb.getPost()+";databaseName="+erpdb.getDb();
2920         // Connection con=ddbdao.open(url, erpdb.getUsername(),
2921         // erpdb.getPwd(),erpdb.getDbsign());
2922         // if(con==null){
2923         // throw new Exception("ERP数据库链接失败,请检查分单系统ERP配置是否正确!");
2924         // }
2925         // String sql=SqlTxt.GYErpXSTDsql+" where EXISTS (SELECT 1 FROM XSTDMX WHERE
2926         // XSTDMX_TDLS=XSTD_TDLS AND XSTDMX_CKBZ='0') and a.XSTD_TDBH='"+zc.getTdbh()+"'
2927         // and a.XSTD_SHBZ=1 and a.XSTD_TDBZ='LD' ";
2928         // Map<String, Object> tdmp=ddbdao.getmapnoclose(sql,erpdb.getDbsign());
2929         // if(tdmp==null){
2930         // throw new Exception("第"+eachline+"行 ,销售提单未找到!");
2931         // }
2932         // WaitXSTD wt=new WaitXSTD();
2933         // BeanUtils.populate(wt, tdmp);
2934         //
2935         // sql=SqlTxt.GYErpXSTDMXsql+" where b.XSTDMX_CKBZ='0' and
2936         // a.XSTD_TDBH='"+zc.getTdbh()+"' and b.XSTDMX_PCH='"+zc.getPch()+"' ";//销售提单明细
2937         // Map<String, Object> mxmp=ddbdao.getmapnoclose(sql,erpdb.getDbsign());
2938         // if(mxmp==null){
2939         // throw new Exception("第"+eachline+"行 根据提单号和批次号Erp未找到销售提单明细!");
2940         // }
2941         // WaitXSTDMX wtdmx=new WaitXSTDMX();
2942         // BeanUtils.populate(wtdmx, mxmp);
2943         // String hj=mxmp.get("hj")==null?"":mxmp.get("hj")+"";
2944         // String zt=mxmp.get("zt")==null?"":mxmp.get("zt")+"";
2945         // wtdmx.setTdmx_hjzt(hj+"/"+zt);
2946         // //如果扫的是没有分单的
2947         // if(wtdmx.getTdmx_fdbz()==0){
2948         // sql=SqlTxt.XGGYErpXSTDMXsql1+" where a.XSTDMX_CKBZ='0' and
2949         // b.XSTD_TDBH='"+zc.getTdbh()+"' and a.XSTDMX_PCH='"+zc.getPch()+"'
2950         // ";//修改销售提单明细
2951         // List<Object> ll=new ArrayList<Object>();
2952         // ll.add(zc.getCph());//车牌号
2953         // ll.add(2);//分单标志
2954         // ll.add(bussinessNo);//分单单据编号
2955         // ll.add(fdv.getDriver());//司机姓名
2956         // ll.add(fdv.getPhone());//司机联系方式
2957         // ll.add(fdcm.get(vhx.getCompanyNo())==null?"":fdcm.get(vhx.getCompanyNo()));//物流公司名称
2958         //// ll.add(fdcm.get(fdv.getCompanyNo())==null?"":fdcm.get(fdv.getCompanyNo()));//物流公司名称
2959         // ddbdao.modifySql(sql, ll,erpdb.getDbsign());
2960         //
2961         // sql=SqlTxt.XGGYErpXSTDsql;//修改销售提单
2962         // ll.clear();
2963         // ll.add(wt.getTd_wfdsl()-1);//未分单数量
2964         // ll.add(BigDecimalfiter.subscal(wt.getTd_wfdzl(), wtdmx.getTdmx_mz(),
2965         // Contants.scale));//未分单毛重
2966         // ll.add(zc.getTdbh());
2967         // ddbdao.modifySql(sql, ll,erpdb.getDbsign());
2968         //
2969         // //修改vhx
2970         // vhx.setFd_num(vhx.getFd_num()+1);
2971         // vhx.setFd_weight(BigDecimalfiter.addscal(vhx.getFd_weight(),
2972         // wtdmx.getTdmx_mz(), Contants.scale));
2973         // vhxper.update(vhx);
2974         // }else{
2975         // sql=SqlTxt.XGGYErpXSTDMXsql2+" where a.XSTDMX_CKBZ='0' and
2976         // b.XSTD_TDBH='"+zc.getTdbh()+"' and a.XSTDMX_PCH='"+zc.getPch()+"'
2977         // ";//修改销售提单明细
2978         // List<Object> ll=new ArrayList<Object>();
2979         // ll.add(fdv.getDriver());//司机姓名
2980         // ll.add(fdv.getPhone());//司机联系方式
2981         // ll.add(fdcm.get(vhx.getCompanyNo())==null?"":fdcm.get(vhx.getCompanyNo()));//物流公司名称
2982         //// ll.add(fdcm.get(fdv.getCompanyNo())==null?"":fdcm.get(fdv.getCompanyNo()));//物流公司名称
2983         // ddbdao.modifySql(sql, ll,erpdb.getDbsign());
2984         //
2985         // if(!zc.getCph().equals(wtdmx.getTdmx_cph())){
2986         // Vehicle_XSTD vhx1=this.vhxper.getbyIDs(wtdmx.getTdmx_cph(), zc.getTdbh());
2987         // if(vhx1!=null){
2988         // vhx1.setFd_num(vhx1.getFd_num()-1);
2989         // vhx1.setFd_weight(BigDecimalfiter.subscal(vhx1.getFd_weight(),
2990         // wtdmx.getTdmx_mz(), Contants.scale));
2991         // vhxper.update(vhx1);
2992         // }
2993         // //修改vhx
2994         // vhx.setFd_num(vhx.getFd_num()+1);
2995         // vhx.setFd_weight(BigDecimalfiter.addscal(vhx.getFd_weight(),
2996         // wtdmx.getTdmx_mz(), Contants.scale));
2997         // vhxper.update(vhx);
2998         // }
2999         // }
3000         // //修改fbi
3001         // Fd_Bsheetitem fbi=bsiper.getbyLsandFl(wtdmx.getTdmx_tdls(),
3002         // wtdmx.getTdmx_tdfl(),zc.getTdbh());
3003         // if(fbi!=null){
3004         // fbi.setTdmx_cph(zc.getCph());
3005         // fbi.setTdmx_tdbh(zc.getTdbh());
3006         // fbi.setTdmx_fdbz(2);
3007         // fbi.setTdmx_fdywbh(fdb.getFdsheetNo());
3008         // fbi.setTdmx_zccph(zc.getCph());
3009         // fbi.setTdmx_sfzc(1);
3010         // fbi.setBarcode(zc.getTmh());
3011         // bsiper.update(fbi);
3012         // }else{
3013         // fbi=new Fd_Bsheetitem();
3014         // fbi.setId(UUID.randomUUID()+"");
3015         // fbi.setCompanyName(fdb.getCompanyName());
3016         // fbi.setCompanyNo(fdb.getCompanyNo());
3017         // fbi.setCreateid(fdb.getCreateid());
3018         // fbi.setBarcode(zc.getTmh());
3019         // fbi.setCtime(new Date());
3020         // fbi.setTdmx_cph(zc.getCph());
3021         // fbi.setTdmx_tdbh(zc.getTdbh());
3022         // fbi.setTdmx_fdbz(2);
3023         // fbi.setTdmx_fdywbh(fdb.getFdsheetNo());
3024         // fbi.setTdmx_zccph(zc.getCph());
3025         // fbi.setTdmx_sfzc(1);
3026         // bsiper.insert(fbi);
3027         // }
3028         // if(fdv.getStatus()!=VehicleStatus.已进厂){
3029         // fdv.setStatus(VehicleStatus.已进厂);
3030         // vhper.update(fdv);
3031         // }
3032         //
3033         // //添加一卡通明细;
3034         // Map<String, Object> mm=new HashMap<String, Object>();
3035         // mm.put("id", UUID.randomUUID()+"");
3036         // mm.put("bussinessNo",bussinessNo);
3037         // mm.put("name", wtdmx.getTdmx_wlmc());
3038         // mm.put("materielNo",wtdmx.getTdmx_wlbh() );
3039         // mm.put("norms",wtdmx.getTdmx_ggxh() );
3040         // mm.put("unitname", "Kg");
3041         // mm.put("num", 1);
3042         // mm.put("note", null);
3043         // mm.put("weight", BigDecimalfiter.mulcon(wtdmx.getTdmx_jz(), 1000,
3044         // Contants.scale));
3045         // mm.put("price", 0);
3046         // mm.put("preweight",BigDecimalfiter.mulcon(wtdmx.getTdmx_jz(), 1000,
3047         // Contants.scale));
3048         // mm.put("pici", zc.getPch());
3049         // mm.put("hejin", wtdmx.getTdmx_hjzt());
3050         // mm.put("gross",BigDecimalfiter.mulcon(wtdmx.getTdmx_mz(), 1000,
3051         // Contants.scale) );
3052         // mm.put("taotong","" );
3053         // mm.put("taotongWeight", BigDecimalfiter.subscal(wtdmx.getTdmx_mz()*1000,
3054         // wtdmx.getTdmx_jz()*1000, Contants.scale));
3055         // mm.put("money", 0);
3056         //// mm.put("createid", );
3057         //// mm.put("cname", );
3058         //// mm.put("createid", 0);
3059         // mm.put("cdepartid", 0);
3060         //// mm.put("cdepart", );
3061         // mm.put("ctime", new Date());
3062         // mm.put("loadbuild", false);
3063         // mm.put("factory", false);
3064         // mm.put("fachang", true);
3065         // mm.put("fcnum", 0);
3066         // mm.put("product_billNo", zc.getTdbh());
3067         // mm.put("product_serialNo",wtdmx.getTdmx_tdls());
3068         // mm.put("product_otherNo", null);
3069         //// mm.put("product_ywrq",wtdmx.gettdmx_ );
3070         // mm.put("product_flh", wtdmx.getTdmx_tdfl());
3071         // mm.put("recompany",wtdmx.getTdmx_shdw() );
3072         //// mm.put("reID", "");
3073         // mm.put("decompany", wtdmx.getTdmx_fhdw()==null?"明泰科技":wtdmx.getTdmx_fhdw());
3074         //// mm.put("deID", "");
3075         // mm.put("rcompany",wtdmx.getTdmx_shdw() );
3076         //// mm.put("rID", );
3077         // mm.put("frombatch", "ERP系统");
3078         // mm.put("forshowindx",1 );
3079         // mm.put("barcode",zc.getTmh());
3080         // mm.put("reserved11",0 );
3081         // mm.put("reserved12",0 );
3082         // mm.put("reserved13",0 );
3083         // mm.put("jsnum",0 );
3084         // Map<String, Object> mrc=this.bsper.getbsi(zc.getPch(), bussinessNo);
3085         // if(mrc==null){
3086         // bsper.insertBsi(mm);
3087         // }else{
3088         // mm.put("id", mrc.get("id")+"");
3089         // bsper.updateBsi(mm);
3090         // }
3091         // mzweight=BigDecimalfiter.addscal(mzweight,
3092         // BigDecimalfiter.mulcon(wtdmx.getTdmx_mz(), 1000, Contants.scale),
3093         // Contants.scale);
3094         // }
3095         //
3096         // if(mzweight>0&&!StringUtils.isEmpty(instanceID)){
3097         // Map<String, Object> mm=this.yktmper.getweight_docgt(bussinessNo);
3098         // if(mm!=null){
3099         // double gross=Double.parseDouble(mm.get("gross")+"");
3100         // double tare=Double.parseDouble(mm.get("tare")+"");
3101         // if(gross>0&& tare>0){
3102         // Task tk=this.acpser.findTaskByInstanceID(instanceID,
3103         // Contants.weightTaskName);
3104         // Map<String, Object> mcm=new HashMap<String,Object>();
3105         // if(tk!=null){
3106         // if(((gross-tare)-mzweight>Contants.upweight)||(mzweight-(gross-tare))<Contants.loawweight){
3107         // mcm.put("ckbc",1);
3108         // }else{
3109         // mcm.put("ckbc",0);
3110         // }
3111         // this.acpser.completeTask(tk.getId(), "admin", mcm);
3112         // }
3113         // }
3114         // }
3115         //
3116         // }
3117         //
3118         //
3119         // } catch (Exception e) {
3120         // ddbdao.robackclose();
3121         // throw new
3122         // Exception(StringUtils.isEmpty(e.getMessage())?"装车批量保存出错!":e.getMessage());
3123         // }finally{
3124         // ddbdao.close();
3125         //// ddbdao.removeLc(Lcuuid);
3126         // DBchecksingleton.setDbc(Lcuuid,true);
3127         // }
3128
3129         orr.setCode(0);
3130         orr.setItem(true);
3131         return orr;
3132     }
3133
3134     @Override
3135     @Transactional(rollbackFor = Exception.class)
3136     @Deprecated
3137     public ObjectResult<Boolean> batchdelZcInfo(String zcist) throws Exception {
3138         ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
3139         if (zcist == null) {
3140             orr.setCode(1);
3141             orr.setErrmsg("业务参数为空!");
3142             return orr;
3143         }
3144         if (true) {
3145             orr.setCode(1);
3146             orr.setErrmsg("该方法已经弃用!");
3147             return orr;
3148         }
3149
3150         // try {
3151         // JsonParser jp=new JsonParser();
3152         // JsonArray ja=jp.parse(zcist).getAsJsonArray();
3153         // boolean checkvehicle=true;
3154         // Fd_Vehicle fdv=null;
3155         // String bussinessNo="";
3156         // Fd_Bsheet fdb=null;
3157         // for (JsonElement je : ja) {
3158         // JsonObject jo=je.getAsJsonObject();
3159         // Scxt_zcInfo zc=new Scxt_zcInfo();
3160         // zc=JSONobj.getobj(jo, zc);
3161         // if(zc==null){
3162         // continue;
3163         // }
3164         // if(StringUtils.isEmpty(zc.getCph())||StringUtils.isEmpty(zc.getYktkh())||StringUtils.isEmpty(zc.getPch())){
3165         // continue;
3166         // }
3167         // String vehicleId=zc.getCph();//车牌号
3168         // String cardno=zc.getYktkh();//卡号
3169         // String pch=zc.getPch();//批次号
3170         // if(checkvehicle){
3171         // Map<String, Object> cdi=yktmper.getcardinuse(cardno);
3172         // if(cdi==null){
3173         // throw new Exception("卡号一卡通未找到,请确认该卡是否正确!");
3174         // }else if(!vehicleId.equals(cdi.get("numberplates"+""))){
3175         // throw new Exception("卡号与车牌号不对应,请确认卡号或者车牌号是否正确!");
3176         // }
3177         // fdv=vhper.getByVehicleId(zc.getCph());
3178         // if(fdv==null){
3179         // throw new Exception("分单系统车牌号:"+zc.getCph()+" 未找到,请确认车辆信息是否正确!");
3180         // }
3181         // Map<String, Object> bsmp=bsper.getbsbyBt(zc.getCph(), Contants.cpxsBtNo,
3182         // Serviceenum.在办, Contants.ssdepartNo);
3183         // if(bsmp==null){
3184         // throw new Exception("车牌号:"+zc.getCph()+" 未找到一卡通业务单!");
3185         // }
3186         // bussinessNo=bsmp.get("bussinessNo")+"";
3187         // fdb=fdbsper.getbybsNo(bussinessNo);
3188         // if(fdb==null){
3189         // throw new Exception("车牌号:"+zc.getCph()+" 未找到分单业务单!");
3190         // }else{
3191         // if(!fdb.getVehicleId().equals(zc.getCph())){
3192         // throw new Exception("车牌号:"+zc.getCph()+"与 分单车牌号不一致!");
3193         // }
3194         // }
3195         // checkvehicle=false;
3196         // }
3197         // bsper.delbypchandNo(pch, bussinessNo);
3198         // Fd_Bsheetitem fdbi=bsiper.getbypchandNo(bussinessNo, pch);
3199         // if(fdbi!=null){
3200         // fdbi.setTdmx_sfzc(0);
3201         // fdbi.setTdmx_zccph("");
3202         // bsiper.update(fdbi);
3203         // }
3204         // }
3205         //
3206         // //修改车辆信息
3207         // List<Map<String, Object>> bsill=bsper.getbsibyNo(bussinessNo);
3208         // if(bsill==null||bsill.size()<=0){
3209         // fdv.setStatus(VehicleStatus.已进厂);
3210         // vhper.update(fdv);
3211         // }
3212         // } catch (Exception e) {
3213         // throw new
3214         // Exception(StringUtils.isEmpty(e.getMessage())?"分单系统批量删除装车出错!":e.getMessage());
3215         // }
3216         orr.setCode(0);
3217         orr.setItem(true);
3218         return orr;
3219     }
3220
3221     @Override
3222     public void changeMxWlgs(List<FdMxWlgs> fdMxWlgsList) throws Exception {
3223         // if(1==1) throw new Exception("就是一个提示!---");
3224         if(fdMxWlgsList!=null) {
3225             List<Fd_XSTDMX> updateFd_XSTDMX = new ArrayList<>();
3226             String tdmx_tdfls = fdMxWlgsList.stream().map(FdMxWlgs::getTdmxTdfl).collect(Collectors.joining("','"));
3227             List<Fd_XSTDMX>  fd_xstdmxes = null;
3228             // 提单流水为主键的Map,存放去掉的数量和重量,需要还回去
3229             Map<String,Map<String,Object>> tdlsMap = new HashedMap();
3230             if(StringUtils.isNotBlank(tdmx_tdfls)) {
3231                 // 根据单号查找已派车的业务单,判断业务单是否发卡,已发卡不能修改,返回错误;前端应该也做限制
3232                 tdmx_tdfls = "'" + tdmx_tdfls + "'";
3233                 fd_xstdmxes = fd_xstdmxMapper.gets(tdmx_tdfls);
3234                 String fdywbhs = fd_xstdmxes.stream().map(Fd_XSTDMX::getTdmx_fdywbh).collect(Collectors.joining("','"));
3235                 if(StringUtils.isNotBlank(fdywbhs) && !"'null'".equals(fdywbhs))  {
3236                     fdywbhs =  "'" + fdywbhs + "'";
3237                     // 如果已经发卡,请联系一卡通
3238                     Map<String, Object> map = businessMapper.existsIssueCardByNos(fdywbhs);
3239                     if (map != null) {
3240                         throw  new Exception("存在已发卡单,请刷新页面后重试!");
3241                     }
3242                 }
3243                 // 删了单,要把重量和数量还回去;在此遍历一下,下面在session中统一更新
3244                 fd_xstdmxes.forEach(fd_xstdmx -> {
3245                     // 装车标志都是 0
3246                     // if(fd_xstdmx.getTdmx_zcbz() == 0)  return;
3247                     // 不存在业务号,则任务没有分单;采用装车标志有问题,不采用。
3248                     if(StringUtils.isBlank(fd_xstdmx.getTdmx_fdywbh()))   return;
3249                     if(tdlsMap.get(fd_xstdmx.getTdmx_tdls())  == null ) {
3250                         tdlsMap.put(fd_xstdmx.getTdmx_tdls(), new HashedMap());
3251                         tdlsMap.get(fd_xstdmx.getTdmx_tdls()).put("addFdsl",0);
3252                         tdlsMap.get(fd_xstdmx.getTdmx_tdls()).put("addFdmz",0d);
3253                     }
3254                     Map map = tdlsMap.get(fd_xstdmx.getTdmx_tdls());
3255                     int addFdsl = (Integer) map.get("addFdsl");
3256                     double addFdmz = (Double) map.get("addFdmz");
3257
3258                     addFdsl ++;
3259                     addFdmz = BigDecimalfiter.addscal(addFdmz, fd_xstdmx.getTdmx_mz(), Contants.scale);
3260                     map.put("addFdsl",addFdsl);
3261                     map.put("addFdmz",addFdmz);
3262                 });
3263             }
3264             fdMxWlgsList.forEach(fdMxWlgs -> {
3265                 Fd_XSTDMX  fd_xstdmx = new Fd_XSTDMX();
3266                 fd_xstdmx.setTdmx_fdcph(null);
3267                 fd_xstdmx.setTdmx_zcwlgsName(null);
3268                 fd_xstdmx.setTdmx_zcphone(null);
3269                 fd_xstdmx.setTdmx_zcdriver(null);
3270                 fd_xstdmx.setTdmx_fdwlgsbh(null);
3271                 fd_xstdmx.setTdmx_fdywbh(null);
3272                 fd_xstdmx.setTdmx_fdbz(0);
3273                 fd_xstdmx.setTdmx_zcbz(0);
3274                 fd_xstdmx.setTdmx_tdfl(fdMxWlgs.getTdmxTdfl());
3275                 fd_xstdmx.setTdmx_fdwlgsbh(fdMxWlgs.getWlgsNo());
3276                 updateFd_XSTDMX.add(fd_xstdmx);
3277             });
3278             try(SqlSession sqlSession =  sqlSessionFactory.openSession(ExecutorType.BATCH,false)){
3279                 // 删除明细和物流公司关系,并新增
3280                 FdMxWlgsMapper mapper = sqlSession.getMapper(FdMxWlgsMapper.class);
3281                 fdMxWlgsList.forEach(fdMxWlgs -> { // 需要删除相关信息(删除该业务单、删除车辆提单)
3282                     mapper.delete(fdMxWlgs.getTdmxTdfl());
3283                     mapper.insert(fdMxWlgs);
3284                 });
3285                 if(updateFd_XSTDMX != null) {
3286                     // 更新分单明细项为未分单
3287                     Fd_XSTDMXMapper fd_xstdmxMapper = sqlSession.getMapper(Fd_XSTDMXMapper.class);
3288                     updateFd_XSTDMX.forEach(fd_xstdmx -> fd_xstdmxMapper.updateZCnoFD(fd_xstdmx));
3289                 }
3290                 if(fd_xstdmxes!=null && fd_xstdmxes.size() > 0 ) {
3291                     Fd_BsheetMapper fd_bsheetMapper = sqlSession.getMapper(Fd_BsheetMapper.class);
3292                     VehicleXSTDMapper vehicleXSTDMapper =  sqlSession.getMapper(VehicleXSTDMapper.class);
3293                     for (Fd_XSTDMX fd_xstdmx : fd_xstdmxes) {
3294                         // 根据车牌号和业务号删除分单车辆,如果是拼单的情况;是否是拼单,取消这个就行,其他不管。
3295                         // 如果配车数量为0可以删除,其他情况,可以-1,把重量也减掉
3296                         if(StringUtils.isNotBlank(fd_xstdmx.getTdmx_fdcph()) && StringUtils.isNotBlank(fd_xstdmx.getTdmx_fdywbh())) {
3297                             List<Vehicle_XSTD> vehicleXSTDs = vehicleXSTDMapper.getlistbyVehicleIdandbsNoGp(fd_xstdmx.getTdmx_fdcph(), fd_xstdmx.getTdmx_fdywbh());
3298                             if (vehicleXSTDs != null && vehicleXSTDs.size() == 1) {
3299                                 Vehicle_XSTD vehicleXSTD = vehicleXSTDs.get(0);
3300                                 int num = vehicleXSTD.getFd_num();
3301                                 if (num <= 1) {
3302                                     vehicleXSTDMapper.delbyVehicleId(fd_xstdmx.getTdmx_fdcph(), fd_xstdmx.getTdmx_fdywbh());
3303                                 } else {
3304                                     vehicleXSTD.setFd_num(vehicleXSTD.getFd_num() - 1);
3305                                     vehicleXSTD.setFd_weight(BigDecimalfiter.subscal(vehicleXSTD.getFd_weight(), fd_xstdmx.getTdmx_mz(), Contants.scale));
3306                                     vehicleXSTDMapper.updatewithIDs(vehicleXSTD);
3307                                 }
3308                             } else {
3309                                 throw new Exception("出现同一辆车的同一业务单出现多个,请检查数据");
3310                             }
3311                         }
3312                         // vehicleXSTDMapper.delbyVehicleId(fd_xstdmx.getTdmx_fdcph(), fd_xstdmx.getTdmx_fdywbh());
3313                         Fd_Bsheet fd_bsheet = fd_bsheetMapper.getbybsNo(fd_xstdmx.getTdmx_fdywbh());
3314                         // 删除分单业务
3315                         fd_bsheetMapper.delbybsNo(fd_xstdmx.getTdmx_fdywbh());
3316                         // 远程删除数量
3317                         if(fd_bsheet!=null) {
3318                             JsonObject jo = new JsonObject();
3319                             jo.addProperty("bussinessNo", fd_xstdmx.getTdmx_fdywbh());
3320                             jo.addProperty("sdepartNo", fd_bsheet.getSdepartNo());
3321                             // 通过接口删除业务单
3322                             JsonObject pfob = Wxhtmethod.postJsonStr(Contants.YKTdelYwd_url, jo.toString());
3323                             int code = JSONobj.getint(pfob, "code");
3324                             if (code != 0) {
3325                                 throw new Exception(JSONobj.getstring(pfob, "errmsg"));
3326                             }
3327                         }
3328                     }
3329                     // 需要更新提单的重量和数量
3330                     Fd_XSTDMapper fdXstdMapper = sqlSession.getMapper(Fd_XSTDMapper.class);
3331                     tdlsMap.forEach((k, v) -> {
3332                         Fd_XSTD xstd =  fdXstdMapper.get(k);
3333                         int addFdsl_1 = (Integer) v.get("addFdsl");
3334                         double addFdmz_1 = (Double) v.get("addFdmz");
3335                         xstd.setTd_tdls(k);
3336                         xstd.setTd_wfdsl(xstd.getTd_wfdsl() + addFdsl_1);
3337                         xstd.setTd_wfdzl(BigDecimalfiter.addscal(xstd.getTd_wfdzl(), addFdmz_1, Contants.scale));
3338                         fdXstdMapper.updateFD(xstd);
3339                     });
3340                 }
3341                 sqlSession.commit();
3342             }
3343         }
3344     }
3345
3346
3347     @Resource
3348     Fd_XSTDMXMapper fd_xstdmxMapper;
3349     @Resource
3350     BusinessMapper businessMapper;
3351
3352
3353 }