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