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