hjg
2024-02-05 301115d5e96b56cd093eee3fcff2d60a15184162
提交 | 用户 | 时间
58d006 1 package com.mandi.fendan.controller;
A 2
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.InputStreamReader;
6 import java.util.ArrayList;
7 import java.util.Date;
8 import java.util.List;
9 import java.util.Map;
10
11 import javax.annotation.Resource;
12 import javax.servlet.ServletInputStream;
13 import javax.servlet.http.HttpServletRequest;
14 import javax.servlet.http.HttpServletResponse;
15
16 import com.fasterxml.jackson.databind.JavaType;
17 import com.fasterxml.jackson.databind.ObjectMapper;
18 import com.mandi.fendan.persist.FdMxWlgs;
19 import com.mandi.springmvc.logs.OpLogs;
20 import com.mandi.system.persist.ModuleEnum;
21 import org.apache.commons.lang3.StringUtils;
22 import org.apache.log4j.Logger;
23 import org.springframework.stereotype.Controller;
24 import org.springframework.web.bind.annotation.RequestBody;
25 import org.springframework.web.bind.annotation.RequestMapping;
26 import org.springframework.web.bind.annotation.RequestMethod;
27 import org.springframework.web.bind.annotation.ResponseBody;
28
29 import com.google.gson.JsonArray;
30 import com.google.gson.JsonElement;
31 import com.google.gson.JsonObject;
32 import com.google.gson.JsonParser;
33 import com.mandi.common.JSONobj;
34 import com.mandi.common.Jacksonmethod;
35 import com.mandi.common.RequestParam;
36 import com.mandi.common.SessionMethod;
37 import com.mandi.dao.common.ObjectResult;
38 import com.mandi.dao.common.PageRequest;
39 import com.mandi.dao.common.PageResult;
40 import com.mandi.dao.common.Sort;
41 import com.mandi.fendan.service.IErpService;
42 import com.mandi.fendan.service.Ifd_bsheetService;
43 import com.mandi.fendan.service.Ifd_vehicleService;
44 import com.mandi.system.persist.Login;
45
46 @Controller("fd_businesscon")
47 @RequestMapping(value="/business",method={RequestMethod.POST})
48 public class Fd_businessCon {
49     Logger log = Logger.getLogger(Fd_businessCon.class);
50
51     @Resource
52     private IErpService erpser;
53     @Resource
54     private Ifd_bsheetService bsser;
55     @Resource
56     private Ifd_vehicleService fdvser;
57
58     /**
59      * 获取已分配的销售提单
60      * @param r
61      * @param re
62      * @return
63      */
64     @RequestMapping(value="/getList.htm",method={RequestMethod.POST})
65     @ResponseBody
66     public String getXSTDList(HttpServletRequest r,HttpServletResponse re){
67         //tdbh--提单编号,khmc--客户,shdd--收货地点,zdbm--制单部门,zdr--制单人
68         String type=RequestParam.getSqlString(r, "type");
69         String keyword=RequestParam.getSqlString(r, "keyword");
70         String companyNo=RequestParam.getSqlString(r, "companyNo");
71         String sort=RequestParam.getString(r, "sort");
72         int wcSign=RequestParam.getInt(r, "wcSign");
73 //        [{name, value: asc/desc}] tdbh--提单编,khmc--客户名称,shdd--收货地点,wfds--未分单数,wfdl--未分单量,
74 //        shsj--审核时间,zdbm--制单部门,zdr--制单人,ywrq--业务日期,tdlx--提单类型
75         int page=RequestParam.getInt(r, "page");
76         int pagesize=RequestParam.getInt(r, "pagesize");
77         int pages=RequestParam.getInt(r, "pages");
78         Date sdate=RequestParam.getDate(r, "sdate");
79         Date edate=RequestParam.getDate(r, "edate");
80         String cqV=RequestParam.getSqlString(r, "cqV");//厂区
81         Login lg=SessionMethod.getlogin(r.getSession());
82         PageRequest pr=new PageRequest(page, pagesize, null);
83         if(pages>0)
84             pr.setNeedPages(true);
85         else
86              pr.setNeedPages(false);
87         List<String> sortc=new ArrayList<String>();
88         String sortStr="";
89         if(!StringUtils.isEmpty(sort)){
90             Sort st=new Sort();
91             JsonParser jp=new JsonParser();
92             JsonElement je=jp.parse(sort);
93             if(je!=null&&je.isJsonArray()){
94                 JsonArray ja=je.getAsJsonArray();
95 //                Map<String, String> sortmp=SortMap.getXSTDsortMap();
96                 for (JsonElement je1 : ja) {
97                     JsonObject jo=je1.getAsJsonObject();
98                     if(jo!=null){
99                         String name=JSONobj.getstring(jo, "name");
100                         String value=JSONobj.getstring(jo, "value");
101                         if(StringUtils.isEmpty(sortStr)){
102                             sortStr+=(" "+name+" "+value);
103                         }else{
104                             sortStr+=(","+name+" "+value);
105                         }
106                     }
107                 }
108             }
109             if(!StringUtils.isEmpty(st.toString())){
110                 pr.setSort(st);
111             }
112         }
113         if(!StringUtils.isEmpty(sortStr)){
114             sortStr+=" ";
115         }
116         String str="";
117         if(wcSign==2){//已关闭销售提单
118             PageResult<Map<String, Object>> prrc=erpser.getCloseXSTDlist(lg,type,keyword, companyNo, sdate, edate,wcSign, pr,sortc);
119             str=Jacksonmethod.tojson(prrc, false);
120         }else{
121             PageResult<Map<String, Object>> prr=erpser.getXSTDList(lg,type,keyword, companyNo, sdate, edate,wcSign,null, pr,sortStr,cqV);
122             str=Jacksonmethod.tojson(prr, false);
123         }
124         SessionMethod.writeresp(re, str);
125         return null;
126     }
127
128     /***
129      *  改变明细的物流公司
130      * @return
131      */
132     @OpLogs(module = ModuleEnum.业务模块, name = "更改提单的物流公司")
133     @RequestMapping(value="/changeWlgs.htm",method= RequestMethod.POST,consumes = "application/json")
134     @ResponseBody
135     public String  changeCompany(HttpServletRequest request, HttpServletResponse response){ // json 解析
136         PageResult<Map<String, Object>> prr = new PageResult<Map<String, Object>>();
137         // 开始解析JSON,接收的类型为List<FdMxWlgs>;主要为了解决这个框架使用@RequestBody时415问题
138         StringBuilder sb = new StringBuilder();
139         try(BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream(),"utf-8"))) {
140             String line = null;
141             while ((line = br.readLine()) != null) {
142                 sb.append(line);
143             }
144         } catch (IOException e) { e.printStackTrace(); }
145         ObjectMapper objectMapper =new ObjectMapper();
146         List<FdMxWlgs> fdMxWlgsList = null;
147         try {
148             JavaType javaType = objectMapper.getTypeFactory().constructParametricType(ArrayList.class, FdMxWlgs.class);
149             fdMxWlgsList = objectMapper.readValue(sb.toString(), javaType);
150         } catch (IOException e) {
151             prr.setCode(1);
152             prr.setErrmsg(e.getMessage());
153             SessionMethod.writeresp(response, Jacksonmethod.tojson(prr, false));
154             return null;
155         }
156         // 解析JSON结束
157         log.info("更改提单的物流公司:" + sb.toString());
158         try {
159             erpser.changeMxWlgs(fdMxWlgsList);
160             prr.setCode(0);
161         } catch (Exception e) {
162             log.error(e.getMessage(),e);
163             prr.setCode(1);
164             prr.setErrmsg(e.getMessage());
165         }
166         SessionMethod.writeresp(response, Jacksonmethod.tojson(prr, false));
167         return null;
168     }
169     /***
170      * 提单列表
171      * @param r
172      * @param re
173      * @return
174      */
175     @RequestMapping(value="/billofLadingList.htm",method={RequestMethod.POST})
176     @ResponseBody
177     public String billofLadingList(HttpServletRequest r,HttpServletResponse re){
178         //tdbh--提单编号,khmc--客户,shdd--收货地点,zdbm--制单部门,zdr--制单人
179         String type=RequestParam.getSqlString(r, "type");
180         String keyword=RequestParam.getSqlString(r, "keyword");
181         // String companyNo=RequestParam.getSqlString(r, "companyNo");
182         String companyNo = ""; // 不要限定公司
183         String sort=RequestParam.getString(r, "sort");
184         int wcSign=RequestParam.getInt(r, "wcSign");
185 //        [{name, value: asc/desc}] tdbh--提单编,khmc--客户名称,shdd--收货地点,wfds--未分单数,wfdl--未分单量,
186 //        shsj--审核时间,zdbm--制单部门,zdr--制单人,ywrq--业务日期,tdlx--提单类型
187         int page=RequestParam.getInt(r, "page");
188         int pagesize=RequestParam.getInt(r, "pagesize");
189         int pages=RequestParam.getInt(r, "pages");
190         Date sdate=RequestParam.getDate(r, "sdate");
191         Date edate=RequestParam.getDate(r, "edate");
192         String cqV=RequestParam.getSqlString(r, "cqV");//厂区
193         Login lg=SessionMethod.getlogin(r.getSession());
194         PageRequest pr=new PageRequest(page, pagesize, null);
195         if(pages>0)
196             pr.setNeedPages(true);
197         else
198             pr.setNeedPages(false);
199         List<String> sortc=new ArrayList<String>();
200         String sortStr="";
201         if(!StringUtils.isEmpty(sort)){
202             Sort st=new Sort();
203             JsonParser jp=new JsonParser();
204             JsonElement je=jp.parse(sort);
205             if(je!=null&&je.isJsonArray()){
206                 JsonArray ja=je.getAsJsonArray();
207 //                Map<String, String> sortmp=SortMap.getXSTDsortMap();
208                 for (JsonElement je1 : ja) {
209                     JsonObject jo=je1.getAsJsonObject();
210                     if(jo!=null){
211                         String name=JSONobj.getstring(jo, "name");
212                         String value=JSONobj.getstring(jo, "value");
213                         if(StringUtils.isEmpty(sortStr)){
214                             sortStr+=(" "+name+" "+value);
215                         }else{
216                             sortStr+=(","+name+" "+value);
217                         }
218                     }
219                 }
220             }
221             if(!StringUtils.isEmpty(st.toString())){
222                 pr.setSort(st);
223             }
224         }
225         if(!StringUtils.isEmpty(sortStr)){
226             sortStr+=" ";
227         }
228         String str="";
229         PageResult<Map<String, Object>> prr=erpser.getXSTDList(lg,type,keyword, companyNo, sdate, edate,wcSign,"fdAdmin" ,pr,sortStr,cqV);
230         str=Jacksonmethod.tojson(prr, false);
231
232         SessionMethod.writeresp(re, str);
233         return null;
234     }
235
236
237     /**
238      *获取全部公司可用车
239      * @param r
240      * @param re
241      * @return
242      */
243     @RequestMapping(value="/getVehicleList.htm",method={RequestMethod.POST})
244     @ResponseBody
245     public String getVehicleList(HttpServletRequest r,HttpServletResponse re){
246         String companyNo=RequestParam.getSqlString(r, "companyNo");
247         String vehicleId=RequestParam.getSqlString(r, "vehicleId");
248         Login lg=SessionMethod.getlogin(r.getSession());
249         PageResult<Map<String, Object>> prr=fdvser.getalllist(lg,companyNo,vehicleId);
250         String str=Jacksonmethod.tojson(prr, false);
251         SessionMethod.writeresp(re, str);
252         return null;
253     }
254
255     /**
256      *验证临时车车牌号
257      * @param r
258      * @param re
259      * @return
260      */
261     @RequestMapping(value="/validVehicle.htm",method={RequestMethod.POST})
262     @ResponseBody
263     public String validVehicle(HttpServletRequest r,HttpServletResponse re){
264         String vehicleId=RequestParam.getSqlString(r, "vehicleId");
265         Login lg=SessionMethod.getlogin(r.getSession());
266         ObjectResult<Boolean> orr=fdvser.validVehicle(lg, vehicleId);
267         String str=Jacksonmethod.tojson(orr, false);
268         SessionMethod.writeresp(re, str);
269         return null;
270     }
271     /**
272      *获取单个销售提单信息
273      * @param r
274      * @param re
275      * @return
276      */
277     @RequestMapping(value="/getItem.htm",method={RequestMethod.POST})
278     @ResponseBody
279     public String getItem(HttpServletRequest r,HttpServletResponse re){
280         String XSTD=RequestParam.getSqlString(r, "keyword");
281         Login lg=SessionMethod.getlogin(r.getSession());
282         Map<String, Object> mp=erpser.getXSTD(lg, XSTD);
283         String str=Jacksonmethod.tojson(mp, false);
284         SessionMethod.writeresp(re, str);
285         return null;
286     }
287     /**
288      *获取提单列表进入的单个销售提单信息
289      * @param r
290      * @param re
291      * @return
292      */
293     @RequestMapping(value="/getBillofLadingItem.htm",method={RequestMethod.POST})
294     @ResponseBody
295     public String getBillofLadingItem(HttpServletRequest r,HttpServletResponse re) {
296         String XSTD=RequestParam.getSqlString(r, "keyword");
297         Login lg=SessionMethod.getlogin(r.getSession());
298         Map<String, Object> mp = erpser.getBillofLadingXSTD(lg, XSTD);
299         String str=Jacksonmethod.tojson(mp, false);
300         SessionMethod.writeresp(re, str);
301         return null;
302     }
303     /**
304      * 按单配车:拼单
305      * @param r
306      * @param re
307      * @return
308      */
309     @RequestMapping(value="/doBindByList.htm",method={RequestMethod.POST})
310     @ResponseBody
9ce4bb 311     @OpLogs(name="整单配车",module = ModuleEnum.业务模块)
58d006 312     public String doBindByList(HttpServletRequest r,HttpServletResponse re){
A 313         String list=RequestParam.getString(r, "list");
314         String vehicle=RequestParam.getString(r, "vehicle");
315         Login lg=SessionMethod.getlogin(r.getSession());
316         ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
317         try {
318             orr = erpser.doBindByList(lg, list, vehicle);
319         } catch (Exception e) {
320             e.printStackTrace();
321             orr.setCode(1);
322             orr.setErrmsg(StringUtils.isEmpty(e.getMessage())?"配车程序出错!":e.getMessage());
323         }
324         String str=Jacksonmethod.tojson(orr, false);
325         SessionMethod.writeresp(re, str);
326         return null;
327     }
328
329     /**
330      * 按车配单取消
331      * @param r
332      * @param re
333      * @return
334      */
9ce4bb 335     @OpLogs(name="整单取消配车",module = ModuleEnum.业务模块)
58d006 336     @RequestMapping(value="/doUnbindByList.htm",method={RequestMethod.POST})
A 337     @ResponseBody
338     public String doUnbindByList(HttpServletRequest r,HttpServletResponse re){
339         String tdbhlist=RequestParam.getString(r, "list");//[TD-0040130, TD-0040132,...]
340         Login lg=SessionMethod.getlogin(r.getSession());
341         ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
342         try {
343             orr = erpser.dounBindByList(lg, tdbhlist);
344         } catch (Exception e) {
345             e.printStackTrace();
346             orr.setCode(1);
347             orr.setErrmsg(StringUtils.isEmpty(e.getMessage())?"配车取消程序出错!":e.getMessage());
348         }
349         String str=Jacksonmethod.tojson(orr, false);
350         SessionMethod.writeresp(re, str);
351         return null;
352     }
353
354     /**
355      * 取消分单
356      * @param r
357      * @param re
358      * @return
359      */
360     @RequestMapping(value="/doUnbind.htm",method={RequestMethod.POST})
361     @ResponseBody
9ce4bb 362     @OpLogs(name="明细取消配车", module = ModuleEnum.业务模块)
58d006 363     public String doUnbind(HttpServletRequest r,HttpServletResponse re){
A 364         String list=RequestParam.getString(r, "list");//[{"tdls":,"tdfl":}]
365         String tdbh=RequestParam.getSqlString(r, "tdbh");//提单编号
366 //        String cph=RequestParam.getSqlString(r, "vehicle");//车牌号
367         Login lg=SessionMethod.getlogin(r.getSession());
368         ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
369         try {
370             orr = erpser.doUnbind(lg, list,tdbh);
371         } catch (Exception e) {
372             e.printStackTrace();
373             orr.setCode(1);
374             orr.setErrmsg(StringUtils.isEmpty(e.getMessage())?"取消分单操作失败!":e.getMessage());
375         }
376         String str=Jacksonmethod.tojson(orr, false);
377         SessionMethod.writeresp(re, str);
378         return null;
379     }
380
381     /**
382      * 分单
383      * @param r
384      * @param re
385      * @return
386      */
387     @RequestMapping(value="/doBind.htm",method={RequestMethod.POST})
388     @ResponseBody
9ce4bb 389     @OpLogs(name="分单配车",module = ModuleEnum.业务模块)
58d006 390     public String doBind(HttpServletRequest r,HttpServletResponse re){
A 391         String list=RequestParam.getString(r, "list");//[{"tdls":,"tdfl":}]
392         String vehicle=RequestParam.getString(r, "vehicle");//[{"tdls":,"tdfl":}]
393         String xstdNo=RequestParam.getSqlString(r, "tdbh");//[{"tdls":,"tdfl":}]
394         Login lg=SessionMethod.getlogin(r.getSession());
395         ObjectResult<Map<String, Object>> orr=new ObjectResult<Map<String, Object>>();
396         try {
397             orr=bsser.saveFd_Bsheet(vehicle, xstdNo, list, lg);
398         } catch (Exception e) {
399             e.printStackTrace();
400             orr.setCode(1);
401             orr.setErrmsg(StringUtils.isEmpty(e.getMessage())?"业务单保存出错!":e.getMessage());
402         }
403         String str="";
404         if(orr.getCode()!=0){
405             str=Jacksonmethod.tojson(orr, false);
406         }else{
407             str=Jacksonmethod.tojson(orr, false);
408         }
409         SessionMethod.writeresp(re, str);
410         return null;
411     }
412
413     /**
414      * 关闭分单
415      * @param r
416      * @param re
417      * @return
418      */
419     @RequestMapping(value="/closexstd.htm",method={RequestMethod.POST})
420     @ResponseBody
9ce4bb 421     @OpLogs(name="关闭分单",module = ModuleEnum.业务模块)
58d006 422     public String closeXstd(HttpServletRequest r,HttpServletResponse re){
A 423         String vehicleId=RequestParam.getSqlString(r, "vehicleId")==null?"":RequestParam.getSqlString(r, "vehicleId").trim();
424         String driver=RequestParam.getSqlString(r, "driver")==null?"":RequestParam.getSqlString(r, "driver").trim();
425         String phone=RequestParam.getSqlString(r, "phone")==null?"":RequestParam.getSqlString(r, "phone").trim();
426         String xstdNo=RequestParam.getSqlString(r, "tdNo")==null?"":RequestParam.getSqlString(r, "tdNo").trim();//提单编号
427         Login lg=SessionMethod.getlogin(r.getSession());
428         ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
429         try {
430             orr = erpser.closeXstd(vehicleId,driver,phone,xstdNo, lg);
431         } catch (Exception e) {
432             e.printStackTrace();
433             orr.setCode(1);
434             orr.setErrmsg(StringUtils.isEmpty(e.getMessage())?"关闭分单程序出错!":e.getMessage());
435         }
436         String str=Jacksonmethod.tojson(orr, false);
437         SessionMethod.writeresp(re, str);
438         return null;
439     }
440     /**
441      * 打开分单
442      * @param r
443      * @param re
444      * @return
445      */
446     @RequestMapping(value="/openxstd.htm",method={RequestMethod.POST})
447     @ResponseBody
9ce4bb 448     @OpLogs(name="打开分单",module = ModuleEnum.业务模块)
58d006 449     public String openXSTD(HttpServletRequest r,HttpServletResponse re){
A 450         String xstdNo=RequestParam.getSqlString(r, "tdNo");//提单编号
451         Login lg=SessionMethod.getlogin(r.getSession());
452         ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
453         try {
454             orr = erpser.openXstd(xstdNo, lg);
455         } catch (Exception e) {
456             e.printStackTrace();
457             orr.setCode(1);
458             orr.setErrmsg(StringUtils.isEmpty(e.getMessage())?"恢复分单程序出错!":e.getMessage());
459         }
460         String str=Jacksonmethod.tojson(orr, false);
461         SessionMethod.writeresp(re, str);
462         return null;
463     }
464 }