hjg
2024-07-05 a0879b60391616bb077b53815114af74ec7a77cd
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
package com.mandi.webservice.service.impl;
 
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.mandi.common.JSONobj;
import com.mandi.common.Jacksonmethod;
import com.mandi.common.ParamFileter.Fileoperation;
import com.mandi.dao.common.ObjectResult;
import com.mandi.dao.common.PageResult;
import com.mandi.fendan.mapper.BusinessMapper;
import com.mandi.fendan.mapper.Fd_BsheetMapper;
import com.mandi.fendan.mapper.Fd_YKTMapper;
import com.mandi.fendan.persist.Fd_Bsheet;
import com.mandi.fendan.util.Contants;
import com.mandi.fendan.util.persist.Serviceenum;
import com.mandi.fendan.util.persist.WaitXSTD;
import com.mandi.servlet.file.impl.FileLoadImpl;
import com.mandi.webservice.service.IFdXSTDService;
import com.mandi.webservice.service.IInvoiceService;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Service
public class InvoiceService implements IInvoiceService{
    @Resource
    private IFdXSTDService fdser;
    @Resource
    private BusinessMapper bsPer;
    @Resource
    private Fd_BsheetMapper fdbPer;
    @Resource
    private Fd_YKTMapper yktmper;
 
    private Logger log= Logger.getLogger(FileLoadImpl.class);
 
    @Override
    public String action(HttpServletRequest r,String jsonParam) {
        Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "请求ip::::"+r.getRemoteAddr());
        Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "数据值::b::"+jsonParam);
        String action="";
        String dataArr="";
        try {
            JsonParser jp=new JsonParser();
            JsonObject jo=jp.parse(jsonParam).getAsJsonObject();
            action=JSONobj.getstring(jo, "action");
            dataArr=jo.get("data").toString();
        } catch (Exception e) {
 
        }
//        Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "参数action::::"+action);
//        Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "参数dataArr::::"+dataArr);
        Map<String, Object> mm=new HashMap<String, Object>();
        ObjectResult<Boolean> orr=null;
        if(!StringUtils.isEmpty(action)){
            try {
                if(Contants.NcactionCode_add.equals(action)){
                    orr=fdser.saveFd_xstd(dataArr);
                }else if(Contants.NcactionCode_del.equals(action)){
                    orr=fdser.delFd_xstd(dataArr);
                }else if(Contants.NcactionCode_open.equals(action)){
                    orr=fdser.openFd_xstd(dataArr);
                }else if(Contants.NcactionCode_close.equals(action)){
                    orr=fdser.closeFd_xstd(dataArr);
                }else{
                    mm.put("respcode", 999);
                    mm.put("respmsg", "动作参数不正确!");
                }
                if(orr!=null){
                    if(orr.getCode()==0){
                        mm.put("respcode", 111);
                        mm.put("respmsg", orr.getErrmsg());
                    }else{
                        mm.put("respcode", 999);
                        mm.put("respmsg", orr.getErrmsg());
                    }
                }
            } catch (Exception e) {
                mm.put("respcode", 999);
                mm.put("respmsg", "错误:"+e.getMessage());
            }
        }else{
            mm.put("respcode", 999);
            mm.put("respmsg", "动作参数未找到!");
        }
        String str=Jacksonmethod.tojson(mm, false);
        return str;
    }
 
    @Override
    public String delLoading(HttpServletRequest r,String jsonParam) {
        Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "请求ip::::"+r.getRemoteAddr());
        Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "参数metaid::b::"+jsonParam);
        String cardID="";
        String yktywdh="";
        JsonArray dataArr=null;
        Map<String, Object> mm=new HashMap<String, Object>();
        try {
            JsonParser jp=new JsonParser();
            JsonObject jo=jp.parse(jsonParam).getAsJsonObject();
            cardID=JSONobj.getstring(jo, "cardID");
            yktywdh=JSONobj.getstring(jo, "yktywdh");
            dataArr=JSONobj.getJsonArray(jo, "data");
        } catch (Exception e) {
            mm.put("respcode", 999);
            mm.put("respmsg", "数据解析出错!");
            String str=Jacksonmethod.tojson(mm, false);
            return str;
        }
        ObjectResult<Boolean> prs=new ObjectResult<Boolean>();
        try {
            prs=fdser.delZCMX(cardID, yktywdh, dataArr);
            Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "delLoading返回值::::"+Jacksonmethod.tojson(prs, false));
        } catch (Exception e) {
            mm.put("respcode", 999);
            mm.put("respmsg", e.getMessage());
            Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "delLoading返回值::::"+Jacksonmethod.tojson(mm, false));
            String str=Jacksonmethod.tojson(mm, false);
            return str;
        }
        if(prs!=null){
            if(prs.getCode()==0){
                mm.put("respcode", 111);
                mm.put("respmsg", "操作成功!");
            }else{
                if(prs.getCode()==2){
                    mm.put("respcode", 222);
                    mm.put("respmsg", prs.getErrmsg());
                }else{
                    mm.put("respcode", 999);
                    mm.put("respmsg", prs.getErrmsg());
                }
            }
        }
        String str=Jacksonmethod.tojson(mm, false);
        return str;
    }
 
    @Override
    public String addLoading(HttpServletRequest r,String jsonParam) {
        Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "请求ip::::"+r.getRemoteAddr());
        Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "参数metaid::b::"+jsonParam);
        String cardID="";
        String yktywdh="";
        JsonArray dataArr=null;
        Map<String, Object> mm=new HashMap<String, Object>();
        try {
            JsonParser jp=new JsonParser();
            JsonObject jo=jp.parse(jsonParam).getAsJsonObject();
            cardID=JSONobj.getstring(jo, "cardID");
            yktywdh=JSONobj.getstring(jo, "yktywdh");
            dataArr=JSONobj.getJsonArray(jo, "data");
//            System.err.println("ddata::::"+dataArr);
        } catch (Exception e) {
            mm.put("respcode", 999);
            mm.put("respmsg", "数据解析出错!");
            String str=Jacksonmethod.tojson(mm, false);
            return str;
        }
        PageResult<Map<String, Object>> prs=new PageResult<Map<String, Object>>();
        try {
            prs=fdser.addZCMX(cardID, yktywdh, dataArr);
            Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "addLoading返回值::::"+Jacksonmethod.tojson(prs, false));
        } catch (Exception e) {
            mm.put("respcode", 999);
            mm.put("respmsg", e.getMessage());
            Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "addLoading返回值::::"+Jacksonmethod.tojson(mm, false));
            String str=Jacksonmethod.tojson(mm, false);
            return str;
        }
        if(prs!=null){
            if(prs.getCode()==0){
                mm.put("respcode", 111);
                mm.put("respmsg", "操作成功!");
                mm.put("data", prs.getList());
            }else{
//                mm.put("respcode", 999);
//                mm.put("respmsg", prs.getErrmsg());
                if(prs.getCode()==2){
                    mm.put("respcode", 222);
                    mm.put("respmsg", prs.getErrmsg());
                }else{
                    mm.put("respcode", 999);
                    mm.put("respmsg", prs.getErrmsg());
                }
            }
        }
        String str=Jacksonmethod.tojson(mm, false);
        return str;
    }
 
    @Override
    public String zcFinish(HttpServletRequest r, String jsonParam) {
        Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "zcFinish参数map::::" + jsonParam);
        Map<String, Object> mm = new HashMap<String, Object>();
        String businessNo = "";
        boolean zcWc = false;
        try {
            JsonParser jp = new JsonParser();
            JsonObject jo = jp.parse(jsonParam).getAsJsonObject();
            businessNo = JSONobj.getstring(jo, "businessNo");
            zcWc = JSONobj.getbool(jo, "isWc");
        } catch (Exception e) {
            mm.put("respcode", 999);
            mm.put("respmsg", "数据解析出错!");
            String str = Jacksonmethod.tojson(mm, false);
            return str;
        }
        if (StringUtils.isBlank(businessNo)) {
            mm.put("respcode", 999);
            mm.put("respmsg", "业务单号参数为空!");
            String str = Jacksonmethod.tojson(mm, false);
            return str;
        }
        Fd_Bsheet fb = this.fdbPer.getbybsNo(businessNo);
        if (fb == null && fb.getStatus() != Serviceenum.在办) {
            mm.put("respcode", 999);
            mm.put("respmsg", "未找到在办业务单!");
            String str = Jacksonmethod.tojson(mm, false);
            return str;
        }
        Map<String, Object> xsTask = bsPer.selectTaskTime(businessNo);
        if (xsTask != null) {
            Map<String, Object> xstm = new HashMap<String, Object>();
            xstm.put("businessNo", businessNo);
            xstm.put("zcWc", zcWc);
            if (zcWc)
                xstm.put("zcwcTime", new Date());
            else
                xstm.put("zcwcTime", null);
            bsPer.updateZcWcTime(xstm);
 
            if (zcWc) {
                List<WaitXSTD> l = this.fdbPer.getAllKH(fb.getBsNo(), fb.getId());
                if (l != null) {
                    boolean iscz = false;//收货单位在明细中是否存在
                    WaitXSTD wt = null;
                    for (WaitXSTD waitXSTD : l) {
                        if (fb.getShdw().equals(waitXSTD.getTd_khmc())) {
                            iscz = true;
                            break;
                        } else {
                            if (wt == null && StringUtils.isNotBlank(waitXSTD.getTd_khmc())) {
                                wt = waitXSTD;
                            }
                        }
                    }
                    if (!iscz && wt != null) {
                        fb.setShdw(wt.getTd_khmc());
                        this.yktmper.updateshcompany(fb.getBsNo(), wt.getTd_khmc(), wt.getTd_shdd());
                    }
                }
            }
            mm.put("respcode", 111);
            mm.put("respmsg", "完成装车操作成功!");
        } else {
            mm.put("respcode", 999);
            mm.put("respmsg", "业务单号参数错误!");
        }
        String str = Jacksonmethod.tojson(mm, false);
        return str;
    }
 
    @Override
    public String getVInfo(HttpServletRequest r,String jsonParam) {
 
        Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "getVInfo参数map::::"+jsonParam);
//        Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "参数yktkh::::"+RequestParam.getString(r, "yktkh"));
 
        String cardID="";
        boolean needRecord=true;
        Map<String, Object> mm=new HashMap<String, Object>();
        try {
            JsonParser jp=new JsonParser();
            JsonObject jo=jp.parse(jsonParam).getAsJsonObject();
            cardID=JSONobj.getstring(jo, "yktkh");
            if(jo.has("needRecord")) {
                needRecord = JSONobj.getbool(jo, "needRecord");
            }
        } catch (Exception e) {
            mm.put("respcode", 999);
            mm.put("respmsg", "数据解析出错!");
            String str=Jacksonmethod.tojson(mm, false);
            return str;
        }
        ObjectResult<Map<String, Object>> prs=fdser.getcInfo(cardID,needRecord);
        if(prs.getCode() == 1) {
            log.info("卡号:" + cardID + "---- 错误:"+ prs.getErrmsg());
        }
        if(prs!=null){
            if(prs.getCode()==0){
                mm=prs.getItem();
            }else{
                mm.put("respcode", 999);
                mm.put("respmsg", prs.getErrmsg());
            }
        }
        String str=Jacksonmethod.tojson(mm, false);
        return str;
    }
 
    @Override
    public String getxstdInfo(HttpServletRequest r, String jsonParam) {
        String xstdNo="";
        Map<String, Object> mm=new HashMap<String, Object>();
        try {
            JsonParser jp=new JsonParser();
            JsonObject jo=jp.parse(jsonParam).getAsJsonObject();
            xstdNo=JSONobj.getstring(jo, "xstdNo");
        } catch (Exception e) {
            mm.put("respcode", 999);
            mm.put("respmsg", "数据解析出错!");
            String str=Jacksonmethod.tojson(mm, false);
            return str;
        }
        ObjectResult<Map<String, Object>> or=fdser.getxstdInfo(xstdNo);
        String str="";
        if(or.getCode()!=0){
            str=Jacksonmethod.tojson(or, false);
        }else{
            str=Jacksonmethod.tojson(or.getItem(), false);
        }
        return str;
    }
 
    @Override
    public String savewdControl(HttpServletRequest r, String jsonParam) {
        Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "请求ip::::"+r.getRemoteAddr());
        Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "参数savewdControl::b::"+jsonParam);
        JsonArray dataArr=null;
        Map<String, Object> mm=new HashMap<String, Object>();
        try {
            JsonParser jp=new JsonParser();
            JsonObject jo=jp.parse(jsonParam).getAsJsonObject();
            dataArr=JSONobj.getJsonArray(jo, "data");
            System.err.println("savewdControl ddata::::"+dataArr);
        } catch (Exception e) {
            mm.put("respcode", 999);
            mm.put("respmsg", "数据解析出错!");
            String str=Jacksonmethod.tojson(mm, false);
            return str;
        }
        ObjectResult<Boolean> prs=new ObjectResult<Boolean>();
        try {
            prs=fdser.savewdControl(dataArr);
            Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "savewdControl返回值::::"+Jacksonmethod.tojson(prs, false));
        } catch (Exception e) {
            mm.put("respcode", 999);
            mm.put("respmsg", e.getMessage());
            Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "savewdControl返回值::::"+Jacksonmethod.tojson(mm, false));
            String str=Jacksonmethod.tojson(mm, false);
            return str;
        }
        if(prs!=null){
            if(prs.getCode()==0){
                mm.put("respcode", 111);
                mm.put("respmsg", "操作成功!");
            }else{
                mm.put("respcode", 999);
                mm.put("respmsg", prs.getErrmsg());
            }
        }
        String str=Jacksonmethod.tojson(mm, false);
        return str;
    }
 
    @Override
    public String receiveCurrWeight(HttpServletRequest r, String jsonParam) { // 获取业务单号 一次称重 二次称重
        JsonParser jp=new JsonParser();
        JsonObject jo=jp.parse(jsonParam).getAsJsonObject();
        String businessNo = JSONobj.getstring(jo, "businessNo");
        boolean firstWeighing = JSONobj.getbool(jo, "firstWeighing");
        boolean secondWeighing = JSONobj.getbool(jo, "secondWeighing");
        String sdepartNo = JSONobj.getstring(jo, "sdepartNo");
        if(StringUtils.isBlank(businessNo) || businessNo.indexOf("XS")!=0 || StringUtils.isBlank(sdepartNo)
        ) {
            return null;
        }
        // 刷新
        if(firstWeighing || secondWeighing) { // 称重需要刷新一下
            if ("06".equals(sdepartNo)) { // 明晟
                synchronized (FdXSTDService.refreshMsLedLock) {
                    if (FdXSTDService.refreshMsLedLock) { // 系统繁忙
                        return null;
                    }
                }
                try {
                    synchronized (FdXSTDService.refreshMsLedLock) {
                        FdXSTDService.refreshMsLedLock = true;
                    }
                    fdser.sendToMsLed(null);
                } finally {
                    synchronized (FdXSTDService.refreshMsLedLock) {
                        FdXSTDService.refreshMsLedLock = false;
                    }
                }
            } else if ("08".equals(sdepartNo)) { // 义瑞
                synchronized (FdXSTDService.refreshYrLedLock) {
                    if (FdXSTDService.refreshYrLedLock) { // 系统繁忙
                        return null;
                    }
                }
                try {
                    synchronized (FdXSTDService.refreshYrLedLock) {
                        FdXSTDService.refreshYrLedLock = true;
                    }
                    fdser.sendToYrLed(null);
                }finally {
                    synchronized (FdXSTDService.refreshYrLedLock) {
                        FdXSTDService.refreshYrLedLock = false;
                    }
                }
            }
        } else if ("04".equals(sdepartNo)) { // 科技
            synchronized (FdXSTDService.refreshYrLedLock) {
                if (FdXSTDService.refreshKjLedLock) { // 系统繁忙
                    return null;
                }
            }
            try {
                synchronized (FdXSTDService.refreshKjLedLock) {
                    FdXSTDService.refreshKjLedLock = true;
                }
                fdser.sendToKjLed(null);
            } finally {
                synchronized (FdXSTDService.refreshKjLedLock) {
                    FdXSTDService.refreshKjLedLock = false;
                }
            }
        }
        return null;
    }
 
 
}