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
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
package common.controller;
import common.model.*;
import common.service.ContractService;
import common.service.DmpIncomeService;
import common.service.ShareIncomeService;
import dic.AuthMenuEnmm;
import dic.ContractStatusEnum;
import dic.OperateObjectTypeEnum;
import offline.model.TrackFlowVO;
import org.apache.commons.io.IOUtils;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import security.annotation.AuthKey;
import security.annotation.CurrentAccount;
import util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.util.*;
/**
* Created by mxq on 17/12/21.
* 优先测试账号查询
*/
@Controller
@RequestMapping("{platform}/contract")
public class ContractController {
private static final Logger logger = LoggerFactory.getLogger(ContractController.class);
private static final Map<String, String> CONTRACT_STATUS = new HashMap<String, String>() {{
putdata(this, ContractStatusEnum.WAIT);
putdata(this, ContractStatusEnum.EXECUTING);
putdata(this, ContractStatusEnum.END);
putdata(this, ContractStatusEnum.CANCEL);
putdata(this, ContractStatusEnum.NFORMAL);
putdata(this, ContractStatusEnum.SUSPEND);
putdata(this, ContractStatusEnum.LATE);
putdata(this, ContractStatusEnum.BACK_ALL);
putdata(this, ContractStatusEnum.BACK_NONE);
putdata(this, ContractStatusEnum.BACK_PART);
putdata(this, ContractStatusEnum.MONEY_BACK_FIRST);
putdata(this, ContractStatusEnum.DELETE);
putdata(this, ContractStatusEnum.FIRST_SIGNING);
putdata(this, ContractStatusEnum.RENEWAL);
putdata(this, ContractStatusEnum.SUPPLEMENTARY_AGREEMENT);
}};
private static void putdata(Map map, ContractStatusEnum a) {
map.put(a.getKey(), a.getValue());
}
@Autowired
private ContractService service;
@Autowired
private ShareIncomeService shareIncomeService;
@Autowired
private DmpIncomeService dmpIncomeService;
@RequestMapping(value = "find", method = RequestMethod.GET)
@ResponseBody
@AuthKey(AuthMenuEnmm.CONTRACTMNG_V)
public ResultModel findAll(@CurrentAccount User loginAccount, @PathVariable String platform,
@RequestParam String startDate, @RequestParam String endDate, String contractId) {
return ResultModel.OK(service.findAll(loginAccount, startDate, endDate, platform, contractId));
}
@RequestMapping(value = "contractid/find", method = RequestMethod.GET)
@ResponseBody
public ResultModel findOne(@CurrentAccount User loginAccount, @PathVariable String platform,
String startDate, String endDate, String contractId) {
return ResultModel.OK(service.findOne(loginAccount, startDate, endDate, platform, contractId));
}
@RequestMapping(value = "export", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@ResponseBody
@AuthKey(AuthMenuEnmm.CONTRACTMNG_EX)
public void export(@CurrentAccount User loginAccount, @PathVariable String platform, @RequestParam String startDate
, @RequestParam String endDate, HttpServletRequest request, HttpServletResponse response) {
List<Contract> contractList = service.findAll(loginAccount, startDate, endDate, platform, null);
/*StringBuilder sb = new StringBuilder();
//录入时间 合同编号 客户账号 我方签约主体 签约方 行业分类 销售 开始日期 结束日期 套餐类型 合同金额 签约类型 合同状态 回款状态 关联合同
sb.append("录入时间,合同编号,客户账号,我方签约主体,签约方,行业分类,销售,开始日期,结束日期,套餐类型,合同金额,签约类型,合同状态,回款状态,关联合同\r\n");
if (ValidateUtil.isValid(contractList)) {
for (Contract c : contractList) {
sb.append(c.getDs()).append(",").
append(c.getContractCode()).append(",")
.append(c.getEmail() == null ? "无" : c.getEmail()).append(",")
.append(c.getMyBodyName()).append(",")
.append(c.getCustomerBody()).append(",")
.append(c.getTradeName()).append(",")
.append(c.getSaleName()).append(",")
.append(c.getStartDate()).append(",")
.append(c.getEndDate()).append(",")
.append(c.getPriceLevelName()).append(",")
.append(c.getMoney()).append(",")
.append(CONTRACT_STATUS.get(c.getContractType())).append(",")
.append(CONTRACT_STATUS.get(c.getStatus())).append(",")
.append(CONTRACT_STATUS.get(c.getBackStatus() + "_back")).append(",")
.append(c.getRelationCode() == null ? "" : c.getRelationCode()).append(",")
.append("\r\n");
}
}
String fileName = "合同管理_" + new DateTime(startDate).toString("yyyyMMdd") + "_" + new DateTime(endDate).toString("yyyyMMdd")
+ ".csv";
this.exportWrite(fileName, sb.toString(), "合同管理", response);*/
//创建工作薄对象
HSSFWorkbook workbook = new HSSFWorkbook();//这里也可以设置sheet的Name
//创建工作表对象
HSSFSheet sheet = workbook.createSheet();
//创建工作表的行
HSSFRow row = sheet.createRow(0);
List<String> title;
if (platform.equals("tkio")) {
title = Arrays.asList("录入时间,合同编号,客户账号,我方签约主体,签约方,行政区域,隶属集团,行业分类,销售,开始日期,结束日期,套餐类型,合同流量(万次),赠送流量(万次),合同金额,签约类型,合同状态,回款状态,关联合同,关联合同编号,补充协议签订日期"
.split(","));
} else if (platform.equals("cas")) {
title = Arrays.asList("录入时间,合同编号,客户账号,我方签约主体,签约方,行政区域,隶属集团,行业分类,销售,开始日期,结束日期,套餐类型,有效期开始日有效期结束日,合同金额,签约类型,合同状态,回款状态,关联合同"
.split(","));
} else {
title = Arrays.asList("录入时间,合同编号,客户账号,我方签约主体,签约方,行政区域,隶属集团,行业分类,销售,开始日期,结束日期,套餐类型,合同金额,签约类型,合同状态,回款状态,关联合同"
.split(","));
}
int lineSize = title.size();
for (int i = 0; i < lineSize; i++) {
row.createCell(i).setCellValue(title.get(i));
}
for (int i = 0; i < contractList.size(); i++) {
Contract contract = contractList.get(i);
HSSFRow rowBody = sheet.createRow(i + 1);
rowBody.createCell(0).setCellValue(new DateTime(contract.getCreateTime()).toString("yyyy-MM-dd"));
rowBody.createCell(1).setCellValue(contract.getContractCode());
rowBody.createCell(2).setCellValue(contract.getEmail() == null ? "无" : contract.getEmail());
rowBody.createCell(3).setCellValue(contract.getMyBodyName());
rowBody.createCell(4).setCellValue(contract.getCustomerBody());
rowBody.createCell(5).setCellValue(contract.getBarrioName());
rowBody.createCell(6).setCellValue(contract.getBelongGroup());
rowBody.createCell(7).setCellValue(contract.getTradeName());
rowBody.createCell(8).setCellValue(contract.getSaleName());
rowBody.createCell(9).setCellValue(contract.getStartDate());
rowBody.createCell(10).setCellValue(contract.getEndDate());
rowBody.createCell(11).setCellValue(contract.getPriceLevelName());
if (platform.equals("tkio")) {
rowBody.createCell(12).setCellValue(contract.getTrackFlow() == null ? 0 : contract.getTrackFlow());
rowBody.createCell(13).setCellValue(contract.getExtraFlow() == null ? 0 : contract.getExtraFlow());
rowBody.createCell(14).setCellValue(contract.getMoney() == null ? 0 : contract.getMoney());
rowBody.createCell(15).setCellValue(CONTRACT_STATUS.get(contract.getContractType()));
rowBody.createCell(16).setCellValue(CONTRACT_STATUS.get(contract.getStatus()));
rowBody.createCell(17).setCellValue(CONTRACT_STATUS.get(contract.getBackStatus() + "_back"));
rowBody.createCell(18).setCellValue(contract.getRelationCode() == null ? "无" : "有");
rowBody.createCell(19).setCellValue(contract.getRelationCode() == null ? "" : contract.getRelationCode());
rowBody.createCell(20).setCellValue(contract.getSignedDate() == null ? "" : contract.getSignedDate());
} else {
if (platform.equals("cas")) {
rowBody.createCell(12).setCellValue(contract.getValidStartDate());
rowBody.createCell(13).setCellValue(contract.getValidEndDate());
rowBody.createCell(14).setCellValue(contract.getMoney() == null ? 0 : contract.getMoney());
rowBody.createCell(15).setCellValue(CONTRACT_STATUS.get(contract.getContractType()));
rowBody.createCell(16).setCellValue(CONTRACT_STATUS.get(contract.getStatus()));
rowBody.createCell(17).setCellValue(CONTRACT_STATUS.get(contract.getBackStatus() + "_back"));
rowBody.createCell(18).setCellValue(contract.getRelationCode() == null ? "" : contract.getRelationCode());
} else {
rowBody.createCell(12).setCellValue(contract.getMoney() == null ? 0 : contract.getMoney());
rowBody.createCell(13).setCellValue(CONTRACT_STATUS.get(contract.getContractType()));
rowBody.createCell(14).setCellValue(CONTRACT_STATUS.get(contract.getStatus()));
rowBody.createCell(15).setCellValue(CONTRACT_STATUS.get(contract.getBackStatus() + "_back"));
rowBody.createCell(16).setCellValue(contract.getRelationCode() == null ? "" : contract.getRelationCode());
}
}
}
String fileName = "合同管理_" + new DateTime(startDate).toString("yyyyMMdd")
+ "_" + new DateTime(endDate).toString("yyyyMMdd") + ".xls";
this.exportWrite(fileName, workbook, "合同管理_", response);
NewUserLogThread userlog = new NewUserLogThread(loginAccount.getEmail(), loginAccount.getName(), OperateObjectTypeEnum.CUSTOMER.getKey(), platform, "导出合同", startDate, endDate, request, platform);
userlog.start();
//返回文件字符串
// return new ResponseEntity<byte[]>(content, headers, HttpStatus.CREATED);
}
@RequestMapping(value = "pay/export", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@ResponseBody
@AuthKey(AuthMenuEnmm.COLLECTBILLLIST_EX)
public void exportPay(@CurrentAccount User loginAccount, @RequestParam String startDate, @RequestParam String endDate,
HttpServletRequest request, HttpServletResponse response, @PathVariable String platform,
String moneyType, String packageTypeSearch, String money_ids) {
List<ContractMoney> moneyList = service.findPayAll(loginAccount, startDate, endDate, platform, moneyType, packageTypeSearch, money_ids);
Map<String, String> map = new HashMap<>();
map.put("pay", "收款");
map.put("invoice", "开票");
byte[] content = new byte[0];
StringBuilder sb = new StringBuilder();
Double parseSum = 0d;
if (ValidateUtil.isValid(moneyList)) {
for (ContractMoney c : moneyList) {
sb.append(c.getDs()).append(",")
.append(c.getContractCode() == null ? "" : c.getContractCode()).append(",")
.append(c.getEmail() == null ? "" : c.getEmail()).append(",")
.append(c.getCompany() == null ? "" : c.getCompany()).append(",")
.append(c.getPackageName() == null ? "" : c.getPackageName()).append(",")
.append(c.getSalseName() == null ? "" : c.getSalseName()).append(",")
.append(map.get(c.getType() == null ? "" : c.getType())).append(",")
.append(c.getMoney() == null ? "" : c.getMoney()).append(",")
.append(c.getCreateName() == null ? "" : c.getCreateName()).append("\r\n");
if ("pay".equals(c.getType())) {
// 付款
parseSum += c.getMoney();
} else {
parseSum -= c.getMoney();
}
}
}
StringBuffer titlebuffer = new StringBuffer();
titlebuffer.append("日期, 合同编号 ,客户账号 ,签约方名称 ,套餐类型, 销售, 事项 ,金额 ,操作人 \r\n");
titlebuffer.append("汇总, - , - , - , - , - , - ,").append(parseSum).append(" , - \r\n");
titlebuffer.append(sb);
String fileName = "收款开票_" + new DateTime(startDate).toString("yyyyMMdd")
+ "_" + new DateTime(endDate).toString("yyyyMMdd") + ".csv";
this.exportWrite(fileName, titlebuffer.toString(), "收款开票", response);
NewUserLogThread userlog = new NewUserLogThread(loginAccount.getEmail(), loginAccount.getName(), OperateObjectTypeEnum.CUSTOMER.getKey(), platform, "导出收款开票", startDate, endDate, request, platform);
userlog.start();
//返回文件字符串
// return new ResponseEntity<byte[]>(content, headers, HttpStatus.CREATED);
}
@RequestMapping(value = "findone", method = RequestMethod.GET)
@ResponseBody
public ResultModel findOne(@CurrentAccount User loginAccount, @RequestParam String code) {
return ResultModel.OK(service.findOne(code));
}
@RequestMapping(value = "checkAccount", method = RequestMethod.GET)
@ResponseBody
public ResultModel checkAccount(@CurrentAccount User loginAccount, @RequestParam String email, @PathVariable String platform) {
return ResultModel.OK(service.checkAccount(email, platform));
}
@RequestMapping(value = "checkTime", method = RequestMethod.GET)
@ResponseBody
public ResultModel checkTime(@RequestParam String type, @RequestParam String email,
@RequestParam String platform, @RequestParam(required = false) String product) {
return ResultModel.OK(service.checkTime(email, platform, type, product));
}
@RequestMapping(value = "find/body", method = RequestMethod.GET)
@ResponseBody
public ResultModel findBody(@CurrentAccount User loginAccount, @PathVariable String platform, String dropall) {
if ("all".equals(dropall)) {
platform = dropall;
}
return ResultModel.OK(service.findBody(platform, loginAccount));
}
@RequestMapping(value = "find/code", method = RequestMethod.GET)
@ResponseBody
public ResultModel findCode(@CurrentAccount User loginAccount, @RequestParam String code, @PathVariable String platform, String company) {
return ResultModel.OK(service.getContractCode(code, platform, company));
}
@RequestMapping(value = "find/pricelevel", method = RequestMethod.GET)
@ResponseBody
public ResultModel findPricelevel(@CurrentAccount User loginAccount, @PathVariable String platform) {
return ResultModel.OK(service.findSetmeal(platform));
}
@RequestMapping(value = "find/increment", method = RequestMethod.GET)
@ResponseBody
public ResultModel findIncrement(@CurrentAccount User loginAccount) {
return ResultModel.OK(service.findIncrement());
}
@RequestMapping(value = "find/rebat", method = RequestMethod.GET)
@ResponseBody
public ResultModel rebat(@CurrentAccount User loginAccount, @RequestParam String product, @RequestParam Integer level, @RequestParam Double money) {
return ResultModel.OK(service.getRebat(product, level, money));
}
@RequestMapping(value = "find/sale", method = RequestMethod.GET)
@ResponseBody
public ResultModel rebat(@CurrentAccount User loginAccount) {
return ResultModel.OK(service.getSales());
}
@RequestMapping(value = "create", method = RequestMethod.POST)
@ResponseBody
public ResultModel create(@CurrentAccount User loginAccount, @RequestBody Contract contract, HttpServletRequest request, @PathVariable String platform) {
Contract contract1 = service.create(loginAccount, contract);
NewUserLogThread userlog = new NewUserLogThread(loginAccount.getEmail(), loginAccount.getName(), OperateObjectTypeEnum.CUSTOMER.getKey(), contract1.getContractCode(), "新建合同", "", contract1.toString(), request, platform);
userlog.start();
// ContractSendEmailThread email = new ContractSendEmailThread(contract);
// email.start();
return ResultModel.OK(contract1);
}
@RequestMapping(value = "update", method = RequestMethod.PUT)
@ResponseBody
@AuthKey(AuthMenuEnmm.CONTRACTMNG_M)
public ResultModel update(@CurrentAccount User loginAccount, @RequestBody Contract contract, HttpServletRequest request, @PathVariable String platform) {
String ip = IPAddrUtil.getIpAddrNew(request);
Contract contract1 = service.update(loginAccount, contract, ip);
NewUserLogThread userlog = new NewUserLogThread(loginAccount.getEmail(), loginAccount.getName(), OperateObjectTypeEnum.CUSTOMER.getKey(), contract1.getContractCode(), "修改合同", "", contract1.toString(), request, platform);
userlog.start();
return ResultModel.OK(contract1);
}
@RequestMapping(value = "pay", method = RequestMethod.POST)
@ResponseBody
public ResultModel pay(@CurrentAccount User loginAccount, @RequestBody ContractMoney contract, HttpServletRequest request, @PathVariable String platform) {
ContractMoney contract1 = service.pay(loginAccount, contract);
NewUserLogThread userlog = new NewUserLogThread(loginAccount.getEmail(), loginAccount.getName(), OperateObjectTypeEnum.CUSTOMER.getKey(), contract1.getContractCode(), "收款开票", "", contract1.toString(), request, platform);
userlog.start();
return ResultModel.OK(contract1);
}
@RequestMapping(value = "change", method = RequestMethod.POST)
@ResponseBody
public ResultModel change(@CurrentAccount User loginAccount,
@RequestBody ContractChange contract, HttpServletRequest request, @PathVariable String platform) {
contract.setPlatform(platform);
Contract contract1 = service.change(loginAccount, contract, null);
NewUserLogThread userlog = new NewUserLogThread(loginAccount.getEmail(), loginAccount.getName(), OperateObjectTypeEnum.CUSTOMER.getKey(), contract1.getContractCode(), "修改套餐", "", contract1.toString(), request, platform);
userlog.start();
return ResultModel.OK(contract1);
}
/**
* @param loginAccount
* @param startDate
* @param endDate
* @param code
* @return
*/
@RequestMapping(value = "find/pay", method = RequestMethod.GET)
@ResponseBody
public ResultModel findPay(@CurrentAccount User loginAccount, @RequestParam String startDate,
@RequestParam String endDate, @RequestParam String code) {
return ResultModel.OK(service.findPay(startDate, endDate, code));
}
@RequestMapping(value = "find/change", method = RequestMethod.GET)
@ResponseBody
public ResultModel findChange(@CurrentAccount User loginAccount, @RequestParam String startDate,
@RequestParam String endDate, @RequestParam String code) {
return ResultModel.OK(service.findChange(startDate, endDate, code));
}
@RequestMapping(value = "find/flowchange", method = RequestMethod.GET)
@ResponseBody
public ResultModel flowchange(@CurrentAccount User loginAccount, @RequestParam String startDate,
@RequestParam String endDate, @RequestParam String code) {
return ResultModel.OK(service.findflowChange(startDate, endDate, code));
}
@RequestMapping(value = "update/pay", method = RequestMethod.PUT)
@ResponseBody
public ResultModel updatePay(@CurrentAccount User loginAccount, @RequestBody ContractMoney contract, HttpServletRequest request,
@PathVariable String platform) {
String ip = IPAddrUtil.getIpAddrNew(request);
Contract contract1 = service.updatePay(loginAccount, contract, ip);
NewUserLogThread userlog = new NewUserLogThread(loginAccount.getEmail(), loginAccount.getName(), OperateObjectTypeEnum.CUSTOMER.getKey(), contract1.getContractCode(), "修改收款开票", "", contract1.toString(), request, platform);
userlog.start();
return ResultModel.OK(contract1);
}
@RequestMapping(value = "find/payall", method = RequestMethod.GET)
@ResponseBody
@AuthKey(AuthMenuEnmm.COLLECTBILLLIST_V)
public ResultModel findPayAll(@CurrentAccount User loginAccount, @RequestParam String startDate,
@RequestParam String endDate, @PathVariable String platform,
String moneyType, String packageTypeSearch, String money_ids) {
return ResultModel.OK(service.findPayAll(loginAccount, startDate, endDate, platform, moneyType, packageTypeSearch, money_ids));
}
@RequestMapping(value = "build", method = RequestMethod.POST)
@ResponseBody
public ResultModel build(@RequestBody Contract contract, HttpServletRequest request) {
logger.error("tkiio---------------" + contract);
return ResultModel.OK(service.build(contract));
}
@RequestMapping(value = "trade", method = RequestMethod.GET)
@ResponseBody
public ResultModel baseCreate(@PathVariable String platform) {
return ResultModel.OK(service.getTradeData(platform));
}
@RequestMapping(value = "code/all", method = RequestMethod.GET)
@ResponseBody
public ResultModel contractCodeAll(@PathVariable String platform, String contractId) {
return ResultModel.OK(service.contractCodeAll(platform, contractId));
}
@RequestMapping(value = "setstaus", method = RequestMethod.GET)
@ResponseBody
@AuthKey(AuthMenuEnmm.CONTRACTMNG_D)
public ResultModel contractStatusUpdate(@PathVariable String platform, @CurrentAccount User loginUser,
String contractId, String status, HttpServletRequest request) {
String ip = IPAddrUtil.getIpAddrNew(request);
return ResultModel.OK(service.contractStatusUpdate(platform, contractId, status, ip, loginUser));
}
@RequestMapping(value = "codecheck", method = RequestMethod.GET)
@ResponseBody
public ResultModel codeCheck(@PathVariable String platform, String contractCode) {
return ResultModel.OK(service.contractCodeCheck(platform, contractCode));
}
/**
* 删除记录
*
* @param platform
* @param
* @return
*/
@RequestMapping(value = "change/del", method = RequestMethod.GET)
@ResponseBody
public ResultModel changesDel(@PathVariable String platform, @CurrentAccount User loginAccount,
String id, String type, HttpServletRequest request) {
return ResultModel.OK(service.changesDel(platform, id, type, IPAddrUtil.getIpAddrNew(request), loginAccount));
}
@RequestMapping(value = "/upload", method = RequestMethod.POST)
@ResponseBody
public ResultModel fileUpload2(@RequestParam("file") MultipartFile file, @PathVariable String platform, @CurrentAccount User loginAccount) {
//
if (!"dmp".equals(platform)) {
return ResultModel.ERROR("导入功能暂时关闭");
}
return service.uploadBatchInfo(file, platform, loginAccount);
}
@RequestMapping(value = "/upload/tempurl", method = RequestMethod.GET)
@ResponseBody
public ResultModel fileTempUrl() {
return ResultModel.OK(Constant.importTempUrl);
}
/**
* 分摊收入
*
* @param loginAccount
* @param platform
* @param startDate
* @param endDate
* @param serchName
* @return
*/
@RequestMapping(value = "/shareincome/list", method = RequestMethod.GET)
@ResponseBody
@AuthKey(AuthMenuEnmm.SHARED_INCOME_V)
public ResultModel shareIncome(@CurrentAccount User loginAccount, @PathVariable String platform,
@RequestParam String startDate, @RequestParam String endDate,
String bodyCode, String serchName) {
if (platform.equals("dmp")) {
//展示dmp上传的收入相关数据
return ResultModel.OK(dmpIncomeService.listByDs(startDate, endDate));
}
return ResultModel.OK(shareIncomeService.shareIncomeList(loginAccount, startDate, endDate, platform, bodyCode, serchName));
}
@RequestMapping(value = "/shareincome/export", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@ResponseBody
@AuthKey(AuthMenuEnmm.SHARED_INCOME_E)
public void shareIncomeExport(@CurrentAccount User loginAccount, @PathVariable String platform,
@RequestParam String startDate, @RequestParam String endDate,
String bodyCode, String serchName, HttpServletResponse response, HttpServletRequest request) {
String fileName = "分摊收入报表_" + new DateTime(startDate).toString("yyyyMMdd")
+ "_" + new DateTime(endDate).toString("yyyyMMdd") + ".xls";
if (platform.equals("dmp")) {
//dmp 分摊报表导出
HSSFWorkbook workbook = dmpIncomeService.exportIncomeList(startDate,endDate,bodyCode,serchName);
this.exportWrite(fileName, workbook, "分摊收入报表", response);
}
List<Contract> contracts = shareIncomeService.shareIncomeList(loginAccount, startDate, endDate, platform, bodyCode, serchName);
HSSFWorkbook workbook;
if (platform.equals("tkio")) {
workbook = createTKIOExcel(contracts);
} else if (platform.equals("adi")) {
workbook = createADIExcel(contracts);
} else if (platform.equals("cas")) {
workbook = createCASExcel(contracts);
} else {
workbook = createCommonExcel(contracts);
}
this.exportWrite(fileName, workbook, "分摊收入报表", response);
}
private HSSFWorkbook createCASExcel(List<Contract> contracts) {
DecimalFormat df = new DecimalFormat("##,##0.00");
//创建工作薄对象
HSSFWorkbook workbook = new HSSFWorkbook();//这里也可以设置sheet的Name
//创建工作表对象
HSSFSheet sheet = workbook.createSheet();
//创建工作表的行
HSSFRow row = sheet.createRow(0);
List<String> title = Arrays.asList("我方签约主体,签约方,合同编号,行政区域,隶属集团,合同状态,合同金额,不含税收入,合同开始日期,合同截止日期,套餐类型,有效期开始日,有效期结束日,一次性确认收入,区间使用天数,区间分摊收入,调整额,分摊总收入"
.split(","));
int lineSize = title.size();
for (int i = 0; i < lineSize; i++) {
row.createCell(i).setCellValue(title.get(i));
}
for (int i = 0; i < contracts.size(); i++) {
Contract contract = contracts.get(i);
HSSFRow rowBody = sheet.createRow(i + 1);
rowBody.createCell(0).setCellValue(contract.getMyBodyName());
rowBody.createCell(1).setCellValue(contract.getCustomerBody());
rowBody.createCell(2).setCellValue(contract.getContractCode());
rowBody.createCell(3).setCellValue(contract.getBarrioName());
rowBody.createCell(4).setCellValue(contract.getBelongGroup());
rowBody.createCell(5).setCellValue(CONTRACT_STATUS.get(contract.getStatus()));
rowBody.createCell(6).setCellValue(df.format(contract.getMoney()));
rowBody.createCell(7).setCellValue(df.format(contract.getIncomeExcludingTax() * 1.0 / 100));
rowBody.createCell(8).setCellValue(contract.getStartDate());
rowBody.createCell(9).setCellValue(contract.getEndDate());
rowBody.createCell(10).setCellValue(contract.getPriceLevelName());
rowBody.createCell(11).setCellValue(contract.getValidStartDate());
rowBody.createCell(12).setCellValue(contract.getValidEndDate());
rowBody.createCell(13).setCellValue(contract.getOneTimeRecognizedRevenue());
rowBody.createCell(14).setCellValue(contract.getIntervalUseDays());
rowBody.createCell(15).setCellValue(df.format(contract.getIntervaIncomeShare() * 1.0 / 100));
rowBody.createCell(16).setCellValue(df.format(contract.getAdjustmentFund() * 1.0 / 100));
rowBody.createCell(17).setCellValue(df.format(contract.getIncomeShareAll() * 1.0 / 100));
}
return workbook;
}
private HSSFWorkbook createADIExcel(List<Contract> contracts) {
DecimalFormat df = new DecimalFormat("##,##0.00");
//创建工作薄对象
HSSFWorkbook workbook = new HSSFWorkbook();//这里也可以设置sheet的Name
//创建工作表对象
HSSFSheet sheet = workbook.createSheet();
//创建工作表的行
HSSFRow row = sheet.createRow(0);
List<String> title = Arrays.asList("我方签约主体,签约方,合同编号,行政区域,隶属集团,合同状态,合同金额,不含税收入,合同开始日期,合同截止日期,套餐类型,区间使用天数,区间分摊收入,调整额,分摊总收入"
.split(","));
int lineSize = title.size();
for (int i = 0; i < lineSize; i++) {
row.createCell(i).setCellValue(title.get(i));
}
for (int i = 0; i < contracts.size(); i++) {
Contract contract = contracts.get(i);
HSSFRow rowBody = sheet.createRow(i + 1);
rowBody.createCell(0).setCellValue(contract.getMyBodyName());
rowBody.createCell(1).setCellValue(contract.getCustomerBody());
rowBody.createCell(2).setCellValue(contract.getContractCode());
rowBody.createCell(3).setCellValue(contract.getBarrioName());
rowBody.createCell(4).setCellValue(contract.getBelongGroup());
rowBody.createCell(5).setCellValue(CONTRACT_STATUS.get(contract.getStatus()));
rowBody.createCell(6).setCellValue(df.format(contract.getMoney()));
rowBody.createCell(7).setCellValue(df.format(contract.getIncomeExcludingTax() * 1.0 / 100));
rowBody.createCell(8).setCellValue(contract.getStartDate());
rowBody.createCell(9).setCellValue(contract.getEndDate());
rowBody.createCell(10).setCellValue(contract.getPriceLevelName());
rowBody.createCell(11).setCellValue(contract.getIntervalUseDays());
rowBody.createCell(12).setCellValue(df.format(contract.getIntervaIncomeShare() * 1.0 / 100));
rowBody.createCell(13).setCellValue(df.format(contract.getAdjustmentFund() * 1.0 / 100));
rowBody.createCell(14).setCellValue(df.format(contract.getIncomeShareAll() * 1.0 / 100));
}
return workbook;
}
private HSSFWorkbook createCommonExcel(List<Contract> contracts) {
DecimalFormat df = new DecimalFormat("##,##0.00");
//创建工作薄对象
HSSFWorkbook workbook = new HSSFWorkbook();//这里也可以设置sheet的Name
//创建工作表对象
HSSFSheet sheet = workbook.createSheet();
//创建工作表的行
HSSFRow row = sheet.createRow(0);
List<String> title = Arrays.asList("我方签约主体,签约方,合同编号,行政区域,隶属集团,合同状态,合同金额,不含税收入,合同开始日期,合同截止日期,区间使用天数,区间分摊收入,调整额,分摊总收入"
.split(","));
int lineSize = title.size();
for (int i = 0; i < lineSize; i++) {
row.createCell(i).setCellValue(title.get(i));
}
for (int i = 0; i < contracts.size(); i++) {
Contract contract = contracts.get(i);
HSSFRow rowBody = sheet.createRow(i + 1);
rowBody.createCell(0).setCellValue(contract.getMyBodyName());
rowBody.createCell(1).setCellValue(contract.getCustomerBody());
rowBody.createCell(2).setCellValue(contract.getContractCode());
rowBody.createCell(3).setCellValue(contract.getBarrioName());
rowBody.createCell(4).setCellValue(contract.getBelongGroup());
rowBody.createCell(5).setCellValue(CONTRACT_STATUS.get(contract.getStatus()));
rowBody.createCell(6).setCellValue(df.format(contract.getMoney()));
rowBody.createCell(7).setCellValue(df.format(contract.getIncomeExcludingTax() * 1.0 / 100));
rowBody.createCell(8).setCellValue(contract.getStartDate());
rowBody.createCell(9).setCellValue(contract.getEndDate());
rowBody.createCell(10).setCellValue(contract.getIntervalUseDays());
rowBody.createCell(11).setCellValue(df.format(contract.getIntervaIncomeShare() * 1.0 / 100));
rowBody.createCell(12).setCellValue(df.format(contract.getAdjustmentFund() * 1.0 / 100));
rowBody.createCell(13).setCellValue(df.format(contract.getIncomeShareAll() * 1.0 / 100));
}
return workbook;
}
private HSSFWorkbook createTKIOExcel(List<Contract> contracts) {
DecimalFormat df = new DecimalFormat("##,##0.00");
DecimalFormat df2 = new DecimalFormat("##,##0.0000");
//创建工作薄对象
HSSFWorkbook workbook = new HSSFWorkbook();//这里也可以设置sheet的Name
//创建工作表对象
HSSFSheet sheet = workbook.createSheet();
//创建工作表的行
HSSFRow row = sheet.createRow(0);
List<String> title = Arrays.asList("我方签约主体,签约方,合同编号,行政区域,隶属集团,合同开始日期,合同截止日期,合同状态,合同金额(元),合同流量(万次),单价(元/万次),区间点击数(万次),区间分摊收入(元),区间调整金额(元),区间总收入(元),累计总收入(元),赠送点击量(万次),关联合同编号,补充协议签订日期"
.split(","));
int lineSize = title.size();
for (int i = 0; i < lineSize; i++) {
row.createCell(i).setCellValue(title.get(i));
}
for (int i = 0; i < contracts.size(); i++) {
Contract contract = contracts.get(i);
HSSFRow rowBody = sheet.createRow(i + 1);
rowBody.createCell(0).setCellValue(contract.getMyBodyName());
rowBody.createCell(1).setCellValue(contract.getCustomerBody());
rowBody.createCell(2).setCellValue(contract.getContractCode());
rowBody.createCell(3).setCellValue(contract.getBarrioName());
rowBody.createCell(4).setCellValue(contract.getBelongGroup());
rowBody.createCell(5).setCellValue(contract.getStartDate());
rowBody.createCell(6).setCellValue(contract.getEndDate());
rowBody.createCell(7).setCellValue(CONTRACT_STATUS.get(contract.getStatus()));
rowBody.createCell(8).setCellValue(df.format(contract.getMoney()));
rowBody.createCell(9).setCellValue(contract.getTrackFlow());
rowBody.createCell(10).setCellValue(contract.getUnitPrice() == null ? 0 : contract.getUnitPrice());
rowBody.createCell(11).setCellValue(contract.getClickFlow() == null ? 0.0 : contract.getClickFlow());
rowBody.createCell(12).setCellValue(df.format(contract.getIntervaIncomeShare() == null ? 0 : contract.getIntervaIncomeShare() / 100.0));
rowBody.createCell(13).setCellValue(df.format(contract.getAdjustmentFund() == null ? 0 : contract.getAdjustmentFund() / 100.0));
rowBody.createCell(14).setCellValue(df.format(contract.getIncomeShareAll() == null ? 0 : contract.getIncomeShareAll() / 100.0));
rowBody.createCell(15).setCellValue(df.format(contract.getIncomeGross() == null ? 0 : contract.getIncomeGross() / 100.0));
rowBody.createCell(16).setCellValue(df2.format(contract.getExtraFlow() == null ? 0 : contract.getExtraFlow() / 10000.0));
rowBody.createCell(17).setCellValue(contract.getRelationCode() == null ? "" : contract.getRelationCode());
rowBody.createCell(18).setCellValue(contract.getSignedDate() == null ? "" : contract.getSignedDate());
}
return workbook;
}
private void exportWrite(String fileName, HSSFWorkbook workbook, String exportName, HttpServletResponse response) {
OutputStream os = null;
try {
fileName = URLEncoder.encode(fileName, "UTF-8");
response.setHeader("filename", fileName);
response.setHeader("content-disposition", "attachment; filename=" + fileName);
response.setHeader("Content-Type", "text/xls");
response.setContentType("APPLICATION/OCTET-STREAM");
response.setCharacterEncoding("UTF-8");
os = response.getOutputStream();
workbook.write(os);
os.flush();
} catch (Exception e) {
logger.error(exportName + "报错", e);
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
logger.error(exportName + "导出,关闭流报错", e);
}
}
}
}
private void exportWrite(String fileName, String text, String exportName, HttpServletResponse response) {
OutputStream os = null;
try {
fileName = URLEncoder.encode(fileName, "UTF-8");
response.setHeader("filename", fileName);
response.setHeader("content-disposition", "attachment; filename=" + fileName);
response.setHeader("Content-Type", "text/csv");
response.setContentType("APPLICATION/OCTET-STREAM");
response.setCharacterEncoding("UTF-8");
os = response.getOutputStream();
os.write(new byte[]{(byte) 0xEF, (byte) 0xBB, (byte) 0xBF});
os.write(text.getBytes("UTF-8"));
os.flush();
} catch (Exception e) {
logger.error(exportName + "报错", e);
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
logger.error(exportName + "导出,关闭流报错", e);
}
}
}
}
/**
* 功能描述:新建合同回显、获取行政区域列表
*
* @author liyin
* @date 2020/9/23
*/
@GetMapping("/getBarrioCities")
@ResponseBody
public ResultModel getBarrioCities() {
return ResultModel.OK(service.getBarrioCities());
}
@GetMapping("/getDate")
@ResponseBody
public ResultModel getDate() {
HashMap<String, Object> map = new HashMap<>();
map.put("new date", new Date().getTime());
map.put("getBeforeDays(1)", DateUtil.getBeforeDays(1));
map.put("getBeforeDays(0)", DateUtil.getBeforeDays(0));
map.put("getCurrentDateStr", DateUtil.getCurrentDateStr());
return ResultModel.OK(map);
}
/**
* 试用流量
*/
@GetMapping(value = "/trialFlow")
@ResponseBody
@AuthKey(AuthMenuEnmm.SHARED_INCOME_V)
public ResultModel trialFlow(@CurrentAccount User loginAccount, @PathVariable String platform,
@RequestParam String startDate, @RequestParam String endDate,
String email) {
return ResultModel.OK(shareIncomeService.trialFlow(loginAccount, startDate, endDate, platform, email));
}
/**
* 试用流量导出
*/
@GetMapping(value = "trialFlowExport", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@AuthKey(AuthMenuEnmm.CONTRACTMNG_EX)
public void trialFlowExport(@CurrentAccount User loginAccount, @PathVariable String platform,
@RequestParam String startDate, @RequestParam String endDate, String email, HttpServletRequest request, HttpServletResponse response) {
List<TrackFlowVO> list = shareIncomeService.trialFlow(loginAccount, startDate, endDate, platform, email);
List<String> title = Arrays.asList("主账号,流量(万次)".split(","));
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet();
HSSFRow row = sheet.createRow(0);
int lineSize = title.size();
for (int i = 0; i < lineSize; i++) {
row.createCell(i).setCellValue(title.get(i));
}
for (int i = 0; i < list.size(); i++) {
TrackFlowVO flow = list.get(i);
HSSFRow rowBody = sheet.createRow(i + 1);
rowBody.createCell(0).setCellValue(flow.getEmail());
rowBody.createCell(1).setCellValue(flow.getTrackFlow());
}
String fileName = "试用流量_" + new DateTime(startDate).toString("yyyyMMdd") + "_" + new DateTime(endDate).toString("yyyyMMdd") + ".xls";
this.exportWrite(fileName, workbook, "试用流量_", response);
}
}