xinyb
2022-06-21 b481f8c8b92930c72b5cc7106b5b4b8aa1b64ba8
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
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
package com.yc.MaintenanceFee.controller;
 
import com.yc.MaintenanceFee.entiy.*;
import com.yc.MaintenanceFee.entiy.Collection;
import com.yc.MaintenanceFee.service.InvoiceService;
import com.yc.MaintenanceFee.utils.BackMsg;
import com.yc.entity.DataSourceEntity;
import com.yc.multiData.MultiDataSource;
import com.yc.multiData.SpObserver;
import com.yc.sdk.shopping.util.SettingKey;
import com.yc.utils.SessionKey;
import org.apache.commons.lang3.StringUtils;
import org.commontemplate.util.MapSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Pattern;
 
/**
 * 发票操作
 *
 * @USER: xinyb_
 * @DATE: 2022-03-07 09:13
 */
@RestController
@RequestMapping("/invoice")
@CrossOrigin
public class InvoiceController {
    private static final String DBID = "_338";
 
    @Autowired
    InvoiceService invoiceService;
 
    /**
     * 获取已经在收款单生成发票单的信息(获取发票单)
     *
     * @param request
     * @return
     */
    @RequestMapping("/getInvoiceInfo.do")
    @ResponseBody
    public BackMsg getInvoiceInfo(String startDate, String endDate, String docCode, Integer page, Integer limit, HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.addHeader("Access-Control-Allow-Methods", "*");
        BackMsg msg = new BackMsg();
        List<InvoiceInfo> invoiceInfo = null;
        try {
            SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
            if (!StringUtils.isBlank(startDate)) {
                Date d1 = sdf1.parse(startDate);
                startDate = sdf1.format(d1);
            }
            if (!StringUtils.isBlank(endDate)) {
                Date d2 = sdf1.parse(endDate);
                endDate = sdf1.format(d2);
            }
            SpObserver.setDBtoInstance(DBID);
            HttpSession session = request.getSession();
            String dbId = (String) session.getAttribute(SessionKey.DATA_BASE_ID);
            //获取发票信息
            invoiceInfo = invoiceService.getInvoiceInfo(startDate, endDate, docCode, dbId);
            Integer count = 0;
            if (invoiceInfo == null || invoiceInfo.size() == 0) {
                invoiceInfo = new ArrayList<>();
            } else {
                count = invoiceInfo.size();
                Integer lim = page * limit >= count ? count : page * limit;
                invoiceInfo = invoiceInfo.subList((page - 1) * limit, lim);
            }
            msg.setPageData(invoiceInfo, count);
        } catch (Exception e) {
            msg.setError(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
 
    /**
     * 获取指定发票单号信息
     *
     * @param docCode
     * @param request
     * @return
     */
    @RequestMapping(value = "/getInvoice.do", method = RequestMethod.GET)
    public BackMsg getInvoice(String docCode, HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.addHeader("Access-Control-Allow-Methods", "*");
        BackMsg msg = new BackMsg();
        try {
            if (StringUtils.isBlank(docCode)) {
                msg.setError("发票单号不能为空值并且不能是null值");
                return msg;
            }
            SpObserver.setDBtoInstance(DBID);
            //获取发票信息
            InvoiceInfo invoiceInfo = invoiceService.getInvoice(docCode);
            msg.setOk(invoiceInfo);
        } catch (Exception e) {
            msg.setError(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
 
    /**
     * 收款列表
     *
     * @param startDate
     * @param endDate
     * @param docCode
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/collection.do", method = RequestMethod.GET)
    public BackMsg getCollection(String startDate, String endDate, String docCode, Integer page, Integer limit, HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.addHeader("Access-Control-Allow-Methods", "*");
        BackMsg msg = new BackMsg();
        List<Collection> collections = null;
        try {
            SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
            if (!StringUtils.isBlank(startDate)) {
                Date d1 = sdf1.parse(startDate);
                startDate = sdf1.format(d1);
            }
            if (!StringUtils.isBlank(endDate)) {
                Date d2 = sdf1.parse(endDate);
                endDate = sdf1.format(d2);
            }
            SpObserver.setDBtoInstance(DBID);
            HttpSession session = request.getSession();
            String dbId = (String) session.getAttribute(SessionKey.DATA_BASE_ID);
            collections = invoiceService.getCollection(startDate, endDate, docCode, dbId);
            int count = 0;
            if (collections == null || collections.size() == 0) {
                collections = new ArrayList<>();
            } else {
                count = collections.size();
                Integer lim = page * limit >= count ? count : page * limit;
                collections = collections.subList((page - 1) * limit, lim);
            }
            msg.setPageData(collections, count);
        } catch (Exception e) {
            msg.setError(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
 
    /**
     * 收款单合并生成发票单(创建发票单)
     *
     * @param param
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/createInvoice.do", method = RequestMethod.POST)
    public BackMsg createInvoice(@RequestBody FPParam param,
                                 HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.addHeader("Access-Control-Allow-Methods", "*");
        BackMsg msg = new BackMsg();
        try {
            if (param.getDocCode() == null || param.getDocCode().size() == 0) {
                msg.setError("消费数据单号不能为空,请选择开票消费数据");
                return msg;
            }
            if (StringUtils.isBlank(param.getInvoiceMedium())) {
                msg.setError("请选择发票介质");
                return msg;
            }
            if ("PaperInvoice".equals(param.getInvoiceMedium()) && (param.getSeq() == null || param.getSeq() == 0)) {
                msg.setError("请选择收件地址");
                return msg;
            }
            if(StringUtils.isNotBlank(param.getTel2())){//判断电话号是否正确
                Pattern pattern = Pattern.compile("^1[3|4|5|7|8][0-9]{9}$");
                if (!pattern.matcher(param.getTel2()).matches()){
                    msg.setError("请输入正确的收票电话号");
                }
            }
            if(StringUtils.isNotBlank(param.getEmail())){//判断邮箱号是否正确
                Pattern pattern = Pattern.compile("^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$");
                if (!pattern.matcher(param.getEmail()).matches()){
                    msg.setError("请输入正确的收票邮箱");
                }
            }
            param.setSeq(param.getSeq() == null ? 0 : param.getSeq());
            HttpSession session = request.getSession();
            param.setUserCode((String) session.getAttribute(SessionKey.USERCODE));
            param.setUserName((String) session.getAttribute(SessionKey.USERNAME));
            SpObserver.setDBtoInstance(DBID);
            String fpCode = invoiceService.createInvoice(param);
            if (StringUtils.isBlank(fpCode)) {
                msg.setError("创建发票单失败!");
            } else {
                String[] fp = fpCode.split(";");
                Map<String, Object> map = new HashMap<>();
                if (fp.length == 3) {
                    map.put("formId", fp[0]);
                    map.put("formType", fp[1]);
                    map.put("docCode", fp[2]);
                } else {
                    map.put("docCode", fpCode);
                }
                msg.setOk(map);
            }
            return msg;
        } catch (Exception e) {
            msg.setError(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
 
    /**
     * 获取发票抬头信息
     *
     * @param request
     * @return
     */
    @RequestMapping("/getInvoiceHeader.do")
    public BackMsg getInvoiceHeader(HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.addHeader("Access-Control-Allow-Methods", "*");
        BackMsg msg = new BackMsg();
        try {
            HttpSession session = request.getSession();
            String dbId = (String) session.getAttribute(SessionKey.DATA_BASE_ID);
            SpObserver.setDBtoInstance(DBID);
            Map<String, Object> map = invoiceService.getInvoiceHeader(dbId);
            if (map.get("invType") == null || "".equals(map.get("invType"))) {
                //没值的情况
                map = null;
            }else{
                DataSourceEntity dataSourceEntity=MultiDataSource.getDataSourceMap(dbId);
                //获取系统设置的开票单位(收取维护费的公司)
                map.put("billingCompany",dataSourceEntity.getMaintenanceFeeToDbId());
            }
            msg.setOk(map);
        } catch (Exception e) {
            msg.setError(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
 
    /**
     * 编辑发票抬头信息
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/invoiceHeader.do", method = RequestMethod.POST)
    public BackMsg saveInvoiceHeader(@RequestBody Header header, HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.addHeader("Access-Control-Allow-Methods", "*");
        BackMsg msg = new BackMsg();
        try {
            HttpSession session = request.getSession();
            String dbId = (String) session.getAttribute(SessionKey.DATA_BASE_ID);
            SpObserver.setDBtoInstance(DBID);
            int count = invoiceService.saveInvoiceHeader(header, dbId);
            if (count == 1) {
                msg.setOk(count);
            } else {
                msg.setOk(-1);
            }
        } catch (Exception e) {
            msg.setError(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
 
    /**
     * 编辑退票信息
     *
     * @param outTicket
     * @param request
     * @return
     */
    @RequestMapping("/saveOutTicket.do")
    public BackMsg saveOutTicket(@RequestBody OutTicket outTicket, HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.addHeader("Access-Control-Allow-Methods", "*");
        BackMsg msg = new BackMsg();
        try {
            String error = "";
            if (StringUtils.isBlank(outTicket.getReceivingName())) {
                error += "请填写收件人名字。\n";
            }
            if (StringUtils.isBlank(outTicket.getReceivingTel())) {
                error += "请填写收件人电话。\n";
            }
            if (StringUtils.isBlank(outTicket.getReceivingAddress())) {
                error += "请填写收件人地址。\n";
            }
            if (StringUtils.isBlank(outTicket.getReason())) {
                error += "请填写退票原因!\n";
            }
            if (StringUtils.isBlank(outTicket.getShipperCode())) {
                error += "请填写快递公司。\n";
            }
            if (StringUtils.isBlank(outTicket.getLogisticsCode())) {
                error += "请填写物流单号。\n";
            }
            if (StringUtils.isBlank(outTicket.getHDMemo())) {
                error += "请填写备注。\n";
            }
            if (StringUtils.isBlank(outTicket.getFpCode())) {
                error += "发票单号不能为空。";
            }
            if (outTicket.getFormId() == null || outTicket.getFormId() == 0) {
                outTicket.setFormId(150504);
            }
            if (!StringUtils.isBlank(error)) {
                msg.setError(error);
                return msg;
            }
            HttpSession session = request.getSession();
            String dbId = (String) session.getAttribute(SessionKey.DATA_BASE_ID);
            outTicket.setUserCode((String) session.getAttribute(SessionKey.USERCODE));
            outTicket.setUserName((String) session.getAttribute(SessionKey.USERNAME));
            SpObserver.setDBtoInstance(DBID);
            String doc = invoiceService.saveOutTicket(outTicket);
            if (!StringUtils.isBlank(doc)) {
                String[] fp = doc.split(";");
                Map<String, Object> map = new HashMap<>();
                if (fp.length == 3) {
                    map.put("formId", fp[0]);
                    map.put("formType", fp[1]);
                    map.put("docCode", fp[2]);
                    map.put("msg","退票提交成功");
                } else {
                    map.put("docCode", doc);
                }
                msg.setOk(map);
            } else {
                msg.setOk("已执行退票过程,但返回值是空值!");
            }
        } catch (Exception e) {
            msg.setError(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
 
 
    /**
     * 获取客户地址信息
     *
     * @param request
     * @return
     */
    @RequestMapping("/getAddress.do")
    public BackMsg getAddressInfo(HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.addHeader("Access-Control-Allow-Methods", "*");
        BackMsg msg = new BackMsg();
        List<Map<String, Object>> list = null;
        try {
            HttpSession session = request.getSession();
            String dbId = (String) session.getAttribute(SessionKey.DATA_BASE_ID);
            SpObserver.setDBtoInstance(DBID);
            list = invoiceService.getAddressInfo(dbId);
            if (list == null) {
                list = new ArrayList<>();
            }
            msg.setOk(list);
        } catch (Exception e) {
            msg.setError(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
 
    /**
     * 获取指定的地址信息
     *
     * @param seq
     * @param request
     * @return
     */
    @RequestMapping("/selectAddress.do")
    public BackMsg selectAddress(Integer seq, HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.addHeader("Access-Control-Allow-Methods", "*");
        BackMsg msg = new BackMsg();
        try {
            if (seq == null || seq == 0) {
                msg.setError("唯一编号不能为空");
                return msg;
            }
            HttpSession session = request.getSession();
            String dbId = (String) session.getAttribute(SessionKey.DATA_BASE_ID);
            SpObserver.setDBtoInstance(DBID);
            Map<String, Object> map = invoiceService.selectAddress(dbId, seq);
            msg.setOk(map);
        } catch (Exception e) {
            msg.setError(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
 
 
    /**
     * 编辑地址信息(保存,修改,删除)
     *
     * @param request
     * @return
     */
    @RequestMapping("/saveAddress.do")
    public BackMsg saveAddress(@RequestBody Address address, HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.addHeader("Access-Control-Allow-Methods", "*");
        BackMsg msg = new BackMsg();
        try {
            if (address.getOperation() == null || address.getOperation() < 0) {
                msg.setError("操作类型错误!");
                return msg;
            }
            if (address.getSeq() == null && (address.getOperation() == 0 || address.getOperation() == 2)) {
                msg.setError("seq值不能为空!");
                return msg;
            }
            HttpSession session = request.getSession();
            String dbId = (String) session.getAttribute(SessionKey.DATA_BASE_ID);
            SpObserver.setDBtoInstance(DBID);
            int cont = invoiceService.saveAddress(address, dbId);
            if (cont == 1) {
                msg.setOk(cont);
            } else {
                msg.setOk(-1);
            }
        } catch (Exception e) {
            msg.setError(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
 
    /**
     * 获取区域信息
     *
     * @param rowId
     * @param request
     * @return
     */
    @RequestMapping("/getRegion.do")
    public BackMsg getRegion(String rowId, HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.addHeader("Access-Control-Allow-Methods", "*");
        BackMsg msg = new BackMsg();
        List<Map<String, Object>> list = null;
        try {
            SpObserver.setDBtoInstance(DBID);
            list = invoiceService.getRegion(rowId);
            if (list == null) {
                list = new ArrayList<>();
            }
            msg.setOk(list);
        } catch (Exception e) {
            msg.setError(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
 
    /**
     * 返回收件人信息
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/getReceiving.do")
    public BackMsg getReceiving(HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.addHeader("Access-Control-Allow-Methods", "*");
        BackMsg msg = new BackMsg();
        try {
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);
            if (dataSourceEntity.getMaintenanceFeeToDbId() != null) {
                Map<String, Object> map = new HashMap<>();
                switch (dataSourceEntity.getMaintenanceFeeToDbId()) {
                    case 1624:
                        map.put("name", "王先生");
                        map.put("tel", "13827778996");
                        map.put("address", "佛山市禅城区华宝南路13号国家火炬创新创业园C座713室");//"广东省佛山市禅城区张槎街道华宝南路13号国家火炬创新创业园C座713");
                        break;
                    case 338:
                        map.put("name", "邱先生");
                        map.put("tel", "15151935628");
                        map.put("address", "江苏省常州市天宁区红梅街道竹林西路天宁时代广场B座1407");
                        break;
                    default:
                        break;
                }
                msg.setOk(map);
            } else {
                msg.setError("请在数据源设置选择【收取维护费所属公司】");
                return msg;
            }
        } catch (Exception e) {
            msg.setError(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        }
        return msg;
    }
 
    /**
     * 获取开票总金额
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/getInvoiceAmount.do")
    public BackMsg getInvoiceAmount(HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.addHeader("Access-Control-Allow-Methods", "*");
        BackMsg msg = new BackMsg();
        try {
            HttpSession session = request.getSession();
            String dbId = (String) session.getAttribute(SessionKey.DATA_BASE_ID);
            SpObserver.setDBtoInstance(DBID);
            double amount = invoiceService.getInvoiceAmount(dbId);
            if (amount > 0) {
                msg.setOk(amount);
            } else {
                msg.setOk(0);
            }
        } catch (Exception e) {
            msg.setError(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
 
    /**
     * 已经开票后的发票浏览
     *
     * @param fpDocCode
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/InvoiceViewData.do")
    public BackMsg getInvoiceViewData(String fpDocCode, HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.addHeader("Access-Control-Allow-Methods", "*");
        BackMsg msg = new BackMsg();
        try {
            if (StringUtils.isBlank(fpDocCode)) {
                msg.setError("预览发票单号不能为空。");
                return msg;
            }
            Map<String, Object> map = new HashMap<>();
            map.putAll(getView(request));
            SpObserver.setDBtoInstance(DBID);
            List<Map<String, Object>> list = invoiceService.getInvoiceViewData(fpDocCode);
            if (list != null && list.size() > 0) {
                map.put("data", list);
            }
            msg.setOk(map);
        } catch (Exception e) {
            msg.setError(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
 
    /**
     * 未生成发票的信息预览
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/getInvoiceView.do", method = RequestMethod.POST)
    public BackMsg getInvoiceView(@RequestBody List<String> docCode, HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.addHeader("Access-Control-Allow-Methods", "*");
        BackMsg msg = new BackMsg();
        try {
            HttpSession session = request.getSession();
            String dbId = (String) session.getAttribute(SessionKey.DATA_BASE_ID);
            SpObserver.setDBtoInstance(DBID);
            Map<String, Object> map = invoiceService.getInvoiceView(String.join(",", docCode), dbId);
            map.putAll(getView(request));
//            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);
//            if (dataSourceEntity.getMaintenanceFeeToDbId() != null) {
//                switch (dataSourceEntity.getMaintenanceFeeToDbId()) {
//                    case 338:
//                        map.put("invoiceName", "江苏增值税专用发票");
//                        map.put("name", "常州市巴士软件有限公司 ");
//                        map.put("identification", "91320402063290850X");
//                        map.put("addressTel", "江苏省常州市天宁区关河东路66号1018室 0519-83380880");
//                        map.put("bankNumber", "中国农业银行常州市九洲广场支行 611801040007777");
//                        map.put("seal1", SettingKey.getHostUrl(request) + "/images/seal/" + dataSourceEntity.getMaintenanceFeeToDbId() + "/jiangsu.png");
//                        map.put("seal2", SettingKey.getHostUrl(request) + "/images/seal/" + dataSourceEntity.getMaintenanceFeeToDbId() + "/jiangsuSeal.png");
//                        break;
//                    case 1624:
//                        map.put("invoiceName", "广东增值税普通发票");
//                        map.put("name", "佛山市盈晨软件有限公司 ");
//                        map.put("identification", "9144060478577219x6");
//                        map.put("addressTel", "佛山市禅城区华宝南路13号国家火炬创新创业园C座713室 0757-83384330");//"佛山市禅城区季华二路国家火炬创新创业园C栋713室 0757-83384330");
//                        map.put("bankNumber", "工商银行佛山明珠支行 2013020809100005421");
//                        map.put("seal1", SettingKey.getHostUrl(request) + "/images/seal/" + dataSourceEntity.getMaintenanceFeeToDbId() + "/guangdong.png");
//                        map.put("seal2", SettingKey.getHostUrl(request) + "/images/seal/" + dataSourceEntity.getMaintenanceFeeToDbId() + "/guangdongSeal.png");
//                        break;
//                    default:
//                        break;
//                }
//            } else {
//                msg.setError("请在数据源设置【收取维护费所属公司】");
//                return msg;
//            }
            map.put("uom", "元");
            map.put("digit", 1);
            map.put("taxRate", "3%");
            msg.setOk(map);
        } catch (Exception e) {
            msg.setError(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
 
    private Map<String, Object> getView(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        map.put("description", "*信息技术服务*软件维护");
        try {
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);
            if (dataSourceEntity.getMaintenanceFeeToDbId() != null) {
                switch (dataSourceEntity.getMaintenanceFeeToDbId()) {
                    case 338:
                        map.put("invoiceName", "江苏增值税专用发票");
                        map.put("name", "常州市巴士软件有限公司 ");
                        map.put("identification", "91320402063290850X");
                        map.put("addressTel", "江苏省常州市天宁区关河东路66号1018室 0519-83380880");
                        map.put("bankNumber", "中国农业银行常州市九洲广场支行 611801040007777");
                        map.put("seal1", SettingKey.getHostUrl(request) + "/images/seal/" + dataSourceEntity.getMaintenanceFeeToDbId() + "/jiangsu.png");
                        map.put("seal2", SettingKey.getHostUrl(request) + "/images/seal/" + dataSourceEntity.getMaintenanceFeeToDbId() + "/jiangsuSeal.png");
                        break;
                    case 1624:
                        map.put("invoiceName", "广东增值税普通发票");
                        map.put("name", "佛山市盈晨软件有限公司 ");
                        map.put("identification", "9144060478577219x6");
                        map.put("addressTel", "佛山市禅城区华宝南路13号国家火炬创新创业园C座713室 0757-83384330");//"佛山市禅城区季华二路国家火炬创新创业园C栋713室 0757-83384330");
                        map.put("bankNumber", "工商银行佛山明珠支行 2013020809100005421");
                        map.put("seal1", SettingKey.getHostUrl(request) + "/images/seal/" + dataSourceEntity.getMaintenanceFeeToDbId() + "/guangdong.png");
                        map.put("seal2", SettingKey.getHostUrl(request) + "/images/seal/" + dataSourceEntity.getMaintenanceFeeToDbId() + "/guangdongSeal.png");
                        break;
                    default:
                        break;
                }
            } else {
                throw new Exception("请在数据源设置【收取维护费所属公司】");
            }
            return map;
        } catch (Exception e) {
            return map;
        }
    }
 
    /**
     * 退票原因列 xin 2022-4-30 11:30:26
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/Reason.do", method = RequestMethod.GET)
    public BackMsg getReason(HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.addHeader("Access-Control-Allow-Methods", "*");
        BackMsg msg = new BackMsg();
        Map<String, Object> M = new HashMap<>();
        try {
            SpObserver.setDBtoInstance(DBID);
            List<Map<String, Object>> map = invoiceService.getReason();
            M.put("R", map);
            List<Map<String, Object>> lmap = invoiceService.getShipperCode();
            M.put("L", lmap);
            msg.setOk(M);
            return msg;
        } catch (Exception e) {
            msg.setError(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
}