fei.wang
10 天以前 e15f561a1f9eddfde503d59baf45a860b131928e
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
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
 
package com.flow.controller;
 
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.flow.mapper.CardMapper;
import com.flow.mapper.OperationLogMapper;
import com.flow.pojo.Card;
import com.flow.pojo.OperationLog;
import com.flow.pojo.TbFuwuqi;
import com.flow.service.CardService;
import com.flow.service.CompanyService;
import com.flow.service.OperationLogService;
import com.flow.util.ExcelUtils;
import com.flow.util.result;
import com.flow.util.resultutil;
import com.github.pagehelper.PageInfo;
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.temporal.ChronoUnit;
import java.util.*;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
 
@RestController
@RequestMapping({"/hxzk"})
public class IndexController {
    @Autowired
    CardService cardService;
    @Autowired
    CompanyService companyService;
 
    @Autowired
    CardMapper cardMapper;
 
    @Autowired
    OperationLogMapper operationLogMapper;
 
    @Autowired
    OperationLogService operationLogService;
 
    public IndexController() {
    }
 
    @GetMapping({"index"})
    public ModelAndView index() throws Exception {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("suoshu", this.companyService.findSuoShu());
        modelAndView.setViewName("/page/index1.jsp");
        return modelAndView;
    }
 
    @PostMapping({"FindCard"})
    public result<List<Card>> FindCard(Integer page, Integer limit, String daoqi, String entry) throws Exception {
 
        PageInfo<Card> cz = this.cardService.FindCarda(page, limit, daoqi, entry);
        for (int i = 0; i < cz.getSize(); ++i) {
            if (((Card) cz.getList().get(i)).getCompany() != null) {
//                ((Card) cz.getList().get(i)).setZflow(((Card) cz.getList().get(i)).getZflow() / 1024);
//                ((Card) cz.getList().get(i)).setSyflow(((Card) cz.getList().get(i)).getSyflow() / 1024);
//                ((Card) cz.getList().get(i)).setSyll(((Card) cz.getList().get(i)).getZflow() - ((Card) cz.getList().get(i)).getSyflow());
 
                if (((Card) cz.getList().get(i)).getBindid() == null || ((Card) cz.getList().get(i)).getBindid().equals("undefined")) {
                    ((Card) cz.getList().get(i)).setBindid("未知");
                }
                SimpleDateFormat date2 = new SimpleDateFormat("yyyy-MM-dd");
                Date date = new Date();
                if (cz.getList().get(i).getEnddate() != null) {
//                    if (cz.getList().get(i).getFlow() == null) {
//                        ((Card) cz.getList().get(i)).setFlow("12G/年");
//                        this.cardService.UpdateCard((Card) cz.getList().get(i));
//                    }
//                    if (cz.getList().get(i).getUnitprice() == null) {
//                        ((Card) cz.getList().get(i)).setUnitprice(80);
//                        this.cardService.UpdateCard((Card) cz.getList().get(i));
//                    }
//                    double twoDecimalPlaces = Double.parseDouble(String.format("%.2f", ((Card) cz.getList().get(i)).getUnitprice()));
//                    System.out.println(twoDecimalPlaces);
 
                    double num = Double.parseDouble(((Card) cz.getList().get(i)).getUnitprice().toString());
                    DecimalFormat df = new DecimalFormat("#.00");
                    String result = df.format(num);
//                    System.out.println(result);
                    ((Card) cz.getList().get(i)).setUnitprice(Double.parseDouble(result));
                    Date endDay = date2.parse(cz.getList().get(i).getEnddate());//结束时间
                    Long starTime = date.getTime();
                    Long endTime = endDay.getTime();
                    Long num11 = endTime - starTime;//时间戳
                    if ((num11 / 24 / 60 / 60 / 1000) < 0) {
 
                        ((Card) cz.getList().get(i)).setRemainingdays("0天");
 
                    } else {
                        ((Card) cz.getList().get(i)).setRemainingdays(+num11 / 24 / 60 / 60 / 1000 + "天");
                    }
                    if (!((Card) cz.getList().get(i)).getRemainingdays().equals("0天") || !((Card) cz.getList().get(i)).getRemainingdays().equals(+num11 / 24 / 60 / 60 / 1000 + "天")) {
                        this.cardService.UpdateCard((Card) cz.getList().get(i));
                    }
                }
            }
        }
 
        return resultutil.returnSuccess(cz.getTotal(), cz.getList());
    }
 
    @PostMapping({"chaZi"})
    public String chaZi(String Zong) throws Exception {
        return this.companyService.chaZi(Zong);
    }
 
    @PostMapping({"FindCardZi"})
    public result<List<Card>> FindCardZi(Card card, Integer page, Integer limit, String daoqi) throws Exception {
        PageInfo<Card> cz = this.cardService.FindCardaZi(card, page, limit, daoqi);
        for (int i = 0; i < cz.getSize(); ++i) {
            if (((Card) cz.getList().get(i)).getCompany() != null) {
//                ((Card) cz.getList().get(i)).setZflow(((Card) cz.getList().get(i)).getZflow() / 1024);
//                ((Card) cz.getList().get(i)).setSyflow(((Card) cz.getList().get(i)).getSyflow() / 1024);
//                ((Card) cz.getList().get(i)).setSyll(((Card) cz.getList().get(i)).getZflow() - ((Card) cz.getList().get(i)).getSyflow());
                SimpleDateFormat date2 = new SimpleDateFormat("yyyy-MM-dd");
                Date date = new Date();
                if (cz.getList().get(i).getEnddate() != null) {
                    Date endDay = date2.parse(cz.getList().get(i).getEnddate());//结束时间
                    Long starTime = date.getTime();
                    Long endTime = endDay.getTime();
                    Long num11 = endTime - starTime;//时间戳
                    if ((num11 / 24 / 60 / 60 / 1000) < 0) {
                        ((Card) cz.getList().get(i)).setRemainingdays("0天");
                    } else {
                        ((Card) cz.getList().get(i)).setRemainingdays(+num11 / 24 / 60 / 60 / 1000 + "天");
                    }
                    if (!((Card) cz.getList().get(i)).getRemainingdays().equals("0天") || !((Card) cz.getList().get(i)).getRemainingdays().equals(+num11 / 24 / 60 / 60 / 1000 + "天")) {
                        this.cardService.UpdateCard((Card) cz.getList().get(i));
                    }
                }
            }
        }
        return resultutil.returnSuccess(cz.getTotal(), cz.getList());
    }
 
    @PostMapping({"DeleteCard"})
    public int DeleteCard(String num, String caozuoname) {
 
        return this.cardService.DeleteCard(num, caozuoname);
    }
 
    @PostMapping({"Update"})
    public ModelAndView UpdateCard(Card card) {
        this.cardService.UpdateCard(card);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/page/index1.jsp");
        return modelAndView;
    }
 
    @PostMapping({"UpdateChong"})
    public ModelAndView UpdateChong(Card card) {
        card.setCardnumber(card.getCardnumber().replaceAll(" ", ""));
        this.cardService.UpdateCardChong(card);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("cardnumber", card.getCardnumber());
        Card tbFuwuqi1 = cardMapper.selectOne(queryWrapper);
        OperationLog operationLog = new OperationLog();
        operationLog.setCaozuotype("修改");
        operationLog.setCaozuocontent("修改卡号:" + tbFuwuqi1.getCardnumber());
//        operationLogMapper.addOperationLog(operationLog);
        operationLog.setCaozuoname(card.getCaozuoname());
        Date date = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        operationLog.setCaozuodate(formatter.format(date));
        operationLogMapper.insert(operationLog);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/page/index1.jsp");
        modelAndView.addObject("operatornum", 2);
        return modelAndView;
    }
 
    @PostMapping({"updateBatchById"})
    @Transactional(rollbackFor = Exception.class)
    public ModelAndView updateBatchById(Card card) {
        this.cardService.updateBatchById(card);
        OperationLog operationLog = new OperationLog();
        operationLog.setCaozuoname(card.getCaozuoname());
        operationLog.setCaozuotype("修改");
        operationLog.setCaozuocontent("修改卡号:" + card.getCardnumber());
        Date date = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        operationLog.setCaozuodate(formatter.format(date));
        operationLogMapper.insert(operationLog);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/page/index1.jsp");
        modelAndView.addObject("operatornum", 2);
        return modelAndView;
    }
 
    /**
     * 导出excel
     */
    @RequestMapping("/excel")
//    @IgnoreAuth
    public void exportToExcel(HttpServletResponse response, Card card) throws IOException {
        // 获取需要导出的数据
        List<Card> dataList = this.cardService.FindCard();
 
        // 创建Excel文件
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet("卡片管理表");
 
        // 创建表头
        HSSFRow headerRow = sheet.createRow(0);
        String[] headers = {"所属公司", "卡号", "状态", "流量", "剩余天数", "开始日期", "运营商", "单价", "绑定设备", "结束日期", "录入日期", "最近充值日期", "充值金额", "备注"}; // 根据你的数据调整列名
        for (int i = 0; i < headers.length; i++) {
            HSSFCell headerCell = headerRow.createCell(i);
            headerCell.setCellValue(headers[i]);
        }
 
        // 填充数据
        for (int i = 0; i < dataList.size(); i++) {
            HSSFRow dataRow = sheet.createRow(i + 1);
            Card data = dataList.get(i);
 
            dataRow.createCell(0).setCellValue(data.getCompany()); // 假设YourData有getField1()方法
            dataRow.createCell(1).setCellValue(data.getCardnumber()); // 假设YourData有getField2()方法
            dataRow.createCell(2).setCellValue(data.getStatus()); // 假设YourData有getField3()方法
            dataRow.createCell(3).setCellValue(data.getFlow()); // 假设YourData有getField3()方法
            dataRow.createCell(4).setCellValue(data.getRemainingdays()); // 假设YourData有getField3()方法
            dataRow.createCell(5).setCellValue(data.getCarddate()); // 假设YourData有getField3()方法
            dataRow.createCell(6).setCellValue(data.getOperator()); // 假设YourData有getField3()方法
            dataRow.createCell(7).setCellValue(data.getUnitprice()); // 假设YourData有getField3()方法
            dataRow.createCell(8).setCellValue(data.getBindid()); // 假设YourData有getField3()方法
            dataRow.createCell(9).setCellValue(data.getEnddate()); // 假设YourData有getField3()方法
            dataRow.createCell(10).setCellValue(data.getEnterdate()); // 假设YourData有getField3()方法
            dataRow.createCell(11).setCellValue(data.getRechargedate()); // 假设YourData有getField3()方法
            dataRow.createCell(12).setCellValue(data.getRechargemoney()); // 假设YourData有getField3()方法
            dataRow.createCell(13).setCellValue(data.getNotes()); // 假设YourData有getField3()方法
            // 根据实际情况填充其他字段
        }
 
        // 设置响应类型和内容处置
        response.setContentType("application/vnd.ms-excel");
//        response.setHeader("Content-Disposition", "attachment; filename=学生评教数据导出表.xls");
        response.setHeader("Content-Disposition", "attachment;filename=" + java.net.URLEncoder.encode("卡片管理表.xls", "UTF-8"));
 
 
        // 将Excel写入响应输出流
        try (ServletOutputStream outputStream = response.getOutputStream()) {
            workbook.write(outputStream);
        }
 
        // 关闭工作簿
//        workbook.close();
    }
 
    @PostMapping({"addCard"})
    public ModelAndView addCard(Card card) throws Exception {
        String[] str = card.getCardnumber().replaceAll(" ", "").split(";");
        String[] str1 = card.getBindid().split(";");
        System.out.println(card.getEnddate());
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/page/index1.jsp");
        modelAndView.addObject("suoshu", this.companyService.findSuoShu());
        int i;
        Card card1;
        if (str.length > 1 && str1.length > 1) {
            for (i = 0; i < str.length; ++i) {
                card1 = new Card();
                card1.setCompany(card.getCompany());
                card1.setCardnumber(str[i]);
                card1.setCarddate(card.getCarddate());
                card1.setOperator(card.getOperator());
                card1.setFlow(card.getFlow());
                card1.setUnitprice(card.getUnitprice());
                card1.setBindid(str1[i]);
                card1.setLocation(card.getLocation());
                card1.setNotes(card.getNotes());
                card1.setEnterdate(card.getEnddate());
                card1.setEnddate(card.getEnddate());
                card1.setEntryclerk(card.getEntryclerk());
                this.cardService.addCard(card1);
            }
        } else if (str.length > 1 && str1[0] == "") {
            for (i = 0; i < str.length; ++i) {
                card1 = new Card();
                card1.setCompany(card.getCompany());
                card1.setCardnumber(str[i]);
                card1.setCarddate(card.getCarddate());
                card1.setOperator(card.getOperator());
                card1.setFlow(card.getFlow());
                card1.setUnitprice(card.getUnitprice());
                card1.setBindid("");
                card1.setLocation(card.getLocation());
                card1.setNotes(card.getNotes());
                card1.setEnterdate(card.getEnddate());
                card1.setEnddate(card.getEnddate());
                card1.setEntryclerk(card.getEntryclerk());
                this.cardService.addCard(card1);
            }
        } else if (str.length > 1 && str1.length == 1) {
            for (i = 0; i < str.length; ++i) {
                card1 = new Card();
                card1.setCompany(card.getCompany());
                card1.setCardnumber(str[i]);
                card1.setCarddate(card.getCarddate());
                card1.setOperator(card.getOperator());
                card1.setFlow(card.getFlow());
                card1.setUnitprice(card.getUnitprice());
                card1.setBindid(str1[i]);
                card1.setLocation(card.getLocation());
                card1.setNotes(card.getNotes());
                card1.setEnterdate(card.getEnddate());
                card1.setEnddate(card.getEnddate());
                card1.setEntryclerk(card.getEntryclerk());
                this.cardService.addCard(card1);
            }
        } else {
            if (card.getCardnumber() != null && card.getCardnumber() != "") {
                card.setCompany(card.getCompany());
                this.cardService.addCard(card);
            }
 
        }
 
        return modelAndView;
    }
 
    @PostMapping({"tableSearch"})
    public result<List<Card>> tableSearch(Card card, int page, int limit) throws Exception {
        PageInfo<Card> cz = this.cardService.tableSearch(card, page, limit);
 
        for (int i = 0; i < cz.getSize(); ++i) {
            if (((Card) cz.getList().get(i)).getCompany().equals("华星智控")) {
                ((Card) cz.getList().get(i)).setCompany("北京华星北斗智控技术有限公司");
            }
//            ((Card) cz.getList().get(i)).setZflow(((Card) cz.getList().get(i)).getZflow() / 1024);
//            ((Card) cz.getList().get(i)).setSyflow(((Card) cz.getList().get(i)).getSyflow() / 1024);
//            ((Card) cz.getList().get(i)).setSyll(((Card) cz.getList().get(i)).getSyll() / 1024);
            SimpleDateFormat date2 = new SimpleDateFormat("yyyy-MM-dd");
            Date date = new Date();
            System.out.println(cz.getList().get(i).getEnddate());
 
            if (cz.getList().get(i) != null) {
                if (cz.getList().get(i).getEnddate() != null && !Objects.equals(cz.getList().get(i).getEnddate(), "")) {
                    Date endDay = date2.parse(cz.getList().get(i).getEnddate());//结束时间
                    Long starTime = date.getTime();
                    Long endTime = endDay.getTime();
                    Long num11 = endTime - starTime;//时间戳
                    if ((num11 / 24 / 60 / 60 / 1000) < 0) {
                        ((Card) cz.getList().get(i)).setRemainingdays("0天");
                    } else {
                        ((Card) cz.getList().get(i)).setRemainingdays(+num11 / 24 / 60 / 60 / 1000 + "天");
                        System.out.println(num11 / 24 / 60 / 60 / 1000 + "天");
                    }
                    if (!((Card) cz.getList().get(i)).getRemainingdays().equals("0天") || !((Card) cz.getList().get(i)).getRemainingdays().equals(+num11 / 24 / 60 / 60 / 1000 + "天")) {
                        this.cardService.UpdateCard((Card) cz.getList().get(i));
                    }
                }
            }
 
 
        }
 
        return resultutil.returnSuccess(cz.getTotal(), cz.getList());
    }
 
    @GetMapping({"chawu"})
    public List chaWu() {
        return this.cardService.chaWu();
    }
 
    @PostMapping({"chawu1"})
    public List chaWu1(String qb) throws Exception {
        return this.cardService.chaWu1(qb);
    }
 
    @GetMapping({"proxyCardList"})
    public void proxyCardList() throws Exception {
        String accessKey = "448c2cedcdce41428a290d144e81ab6e";
        String str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String accessSecret = "RgoIWycMYGmQfrLwLuT2VWawAhwMO8w7P9zh2dZp";
        String nonce = "";
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String Timestamp = dateFormat.format(now);
        int length = 30;
        Random random = new Random();
 
        for (int i = length; i > 0; --i) {
            int index = random.nextInt(str.length());
            nonce = nonce + str.charAt(index);
        }
 
        String stringSignTemp = accessKey + nonce + Timestamp;
        Mac sha256Hmac = Mac.getInstance("HmacSHA256");
        SecretKeySpec secretKeySpec = new SecretKeySpec(accessSecret.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
        sha256Hmac.init(secretKeySpec);
        byte[] hmacBytes = sha256Hmac.doFinal(stringSignTemp.getBytes(StandardCharsets.UTF_8));
        String sign = Base64.getEncoder().encodeToString(hmacBytes);
        String targetUrl = "https://api.spruceiot.cn/api/v1/sim/list/query?pageIndex=1&pageSize=1";
        URL url = new URL(targetUrl);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestProperty("Accept-Charset", "UTF-8");
        connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
        connection.setRequestProperty("Access-Control-Allow-Origin", "http://localhost:8080");
        connection.setRequestProperty("AccessKey", accessKey);
        connection.setRequestProperty("Nonce", nonce);
        connection.setRequestProperty("Timestamp", Timestamp);
        connection.setRequestProperty("Sign", sign);
        connection.connect();
        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
        StringBuilder response1 = new StringBuilder();
 
        String line;
        while ((line = reader.readLine()) != null) {
            response1.append(line);
        }
 
        reader.close();
        connection.disconnect();
        JSONObject jsonObject = new JSONObject(response1);
        int code = jsonObject.getInt("code");
        String message = jsonObject.getStr("message");
        JSONObject result = jsonObject.getJSONObject("result");
        int total1 = result.getInt("total");
        JSONArray list = result.getJSONArray("list");
 
        for (int i = 0; i < list.size(); ++i) {
            JSONObject item = list.getJSONObject(i);
            String msisdn = item.getStr("msisdn");
            String iccid = item.getStr("iccid");
            String imsi = item.getStr("imsi");
            System.out.println("msisdn: " + msisdn + ", iccid: " + iccid + ", imsi: " + imsi);
        }
 
    }
 
    @PostMapping({"proxyCardcompanyUp"})
    public void proxyCardcompanyUp(String card, String name) throws Exception {
        this.cardService.proxyCardcompanyUp(card, name);
    }
 
    @PostMapping({"proxyfindCard"})
    public List proxyfindCard() {
        return this.cardService.proxyfindCard();
    }
 
    @PostMapping({"proxyupXinXi"})
    public int proxyupXinXi(Card card) {
        return this.cardService.proxyupXinXi(card);
    }
 
    @PostMapping({"ifCard"})
    public Card ifCard(Card card) {
        return this.cardService.ifCard(card);
    }
 
    @GetMapping({"getcardinfo"})
    public JSONObject getcardinfo(Integer id) throws Exception {
 
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("num", id);
        Card card = cardMapper.selectOne(queryWrapper);
        System.out.println();
        String accessKey = "448c2cedcdce41428a290d144e81ab6e";
        String str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String accessSecret = "RgoIWycMYGmQfrLwLuT2VWawAhwMO8w7P9zh2dZp";
        String nonce = "";
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String Timestamp = dateFormat.format(now);
        int length = 30;
        Random random = new Random();
 
        for (int i = length; i > 0; --i) {
            int index = random.nextInt(str.length());
            nonce = nonce + str.charAt(index);
        }
 
        String stringSignTemp = accessKey + nonce + Timestamp;
        Mac sha256Hmac = Mac.getInstance("HmacSHA256");
        SecretKeySpec secretKeySpec = new SecretKeySpec(accessSecret.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
        sha256Hmac.init(secretKeySpec);
        byte[] hmacBytes = sha256Hmac.doFinal(stringSignTemp.getBytes(StandardCharsets.UTF_8));
        String sign = Base64.getEncoder().encodeToString(hmacBytes);
        String targetUrl = "https://api.spruceiot.cn/api/v1/sim/detail/query?cNo=" + card.getCardnumber();
        URL url = new URL(targetUrl);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestProperty("Accept-Charset", "UTF-8");
        connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
        connection.setRequestProperty("Access-Control-Allow-Origin", "http://localhost:8080");
        connection.setRequestProperty("AccessKey", accessKey);
        connection.setRequestProperty("Nonce", nonce);
        connection.setRequestProperty("Timestamp", Timestamp);
        connection.setRequestProperty("Sign", sign);
        connection.connect();
        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
        StringBuilder response1 = new StringBuilder();
 
        String line;
        while ((line = reader.readLine()) != null) {
            response1.append(line);
        }
 
        reader.close();
        connection.disconnect();
        JSONObject jsonObject = new JSONObject(response1);
        int code = jsonObject.getInt("code");
        String message = jsonObject.getStr("message");
        JSONObject result = jsonObject.getJSONObject("result");
        if (code!=0){
 
        }else{
            result.set("eStatus", this.getEquipmentstatus(id));
            result.set("oStatus",  this.getcardonline(id));
        }
 
        return jsonObject;
    }
 
    public String getcardonline(Integer id) throws Exception {
 
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("num", id);
        Card card = cardMapper.selectOne(queryWrapper);
        System.out.println();
        String accessKey = "448c2cedcdce41428a290d144e81ab6e";
        String str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String accessSecret = "RgoIWycMYGmQfrLwLuT2VWawAhwMO8w7P9zh2dZp";
        String nonce = "";
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String Timestamp = dateFormat.format(now);
        int length = 30;
        Random random = new Random();
 
        for (int i = length; i > 0; --i) {
            int index = random.nextInt(str.length());
            nonce = nonce + str.charAt(index);
        }
 
        String stringSignTemp = accessKey + nonce + Timestamp;
        Mac sha256Hmac = Mac.getInstance("HmacSHA256");
        SecretKeySpec secretKeySpec = new SecretKeySpec(accessSecret.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
        sha256Hmac.init(secretKeySpec);
        byte[] hmacBytes = sha256Hmac.doFinal(stringSignTemp.getBytes(StandardCharsets.UTF_8));
        String sign = Base64.getEncoder().encodeToString(hmacBytes);
        String targetUrl = "https://api.spruceiot.cn/api/v1/sim/online/status/query?cNo=" + card.getCardnumber();
        URL url = new URL(targetUrl);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestProperty("Accept-Charset", "UTF-8");
        connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
        connection.setRequestProperty("Access-Control-Allow-Origin", "http://localhost:8080");
        connection.setRequestProperty("AccessKey", accessKey);
        connection.setRequestProperty("Nonce", nonce);
        connection.setRequestProperty("Timestamp", Timestamp);
        connection.setRequestProperty("Sign", sign);
        connection.connect();
        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
        StringBuilder response1 = new StringBuilder();
 
        String line;
        while ((line = reader.readLine()) != null) {
            response1.append(line);
        }
 
        reader.close();
        connection.disconnect();
        JSONObject jsonObject = new JSONObject(response1);
        int code = jsonObject.getInt("code");
        String message = jsonObject.getStr("message");
        JSONObject result = jsonObject.getJSONObject("result");
 
        if (code!=0){
            return "";
        }else{
            return result.get("status").toString();
        }
    }
 
 
    public String getEquipmentstatus(Integer id) throws Exception {
 
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("num", id);
        Card card = cardMapper.selectOne(queryWrapper);
        System.out.println();
        String accessKey = "448c2cedcdce41428a290d144e81ab6e";
        String str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String accessSecret = "RgoIWycMYGmQfrLwLuT2VWawAhwMO8w7P9zh2dZp";
        String nonce = "";
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String Timestamp = dateFormat.format(now);
        int length = 30;
        Random random = new Random();
 
        for (int i = length; i > 0; --i) {
            int index = random.nextInt(str.length());
            nonce = nonce + str.charAt(index);
        }
 
        String stringSignTemp = accessKey + nonce + Timestamp;
        Mac sha256Hmac = Mac.getInstance("HmacSHA256");
        SecretKeySpec secretKeySpec = new SecretKeySpec(accessSecret.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
        sha256Hmac.init(secretKeySpec);
        byte[] hmacBytes = sha256Hmac.doFinal(stringSignTemp.getBytes(StandardCharsets.UTF_8));
        String sign = Base64.getEncoder().encodeToString(hmacBytes);
        String targetUrl = "https://api.spruceiot.cn/api/v1/device/status/query?cNo=" + card.getCardnumber();
        URL url = new URL(targetUrl);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestProperty("Accept-Charset", "UTF-8");
        connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
        connection.setRequestProperty("Access-Control-Allow-Origin", "http://localhost:8080");
        connection.setRequestProperty("AccessKey", accessKey);
        connection.setRequestProperty("Nonce", nonce);
        connection.setRequestProperty("Timestamp", Timestamp);
        connection.setRequestProperty("Sign", sign);
        connection.connect();
        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
        StringBuilder response1 = new StringBuilder();
 
        String line;
        while ((line = reader.readLine()) != null) {
            response1.append(line);
        }
 
        reader.close();
        connection.disconnect();
        JSONObject jsonObject = new JSONObject(response1);
        int code = jsonObject.getInt("code");
        String message = jsonObject.getStr("message");
        JSONObject result = jsonObject.getJSONObject("result");
if (code!=0){
    return "";
}else{
    return result.get("status").toString();
}
 
    }
 
    @PostMapping({"rebind"})
    public JSONObject rebind(String iccid,Integer bindType) throws Exception {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("num", iccid);
        Card card = cardMapper.selectOne(queryWrapper);
        String accessKey = "448c2cedcdce41428a290d144e81ab6e";
        String str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String accessSecret = "RgoIWycMYGmQfrLwLuT2VWawAhwMO8w7P9zh2dZp";
        String nonce = "";
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String Timestamp = dateFormat.format(now);
        int length = 30;
        Random random = new Random();
 
        for (int i = length; i > 0; --i) {
            int index = random.nextInt(str.length());
            nonce = nonce + str.charAt(index);
        }
 
        String stringSignTemp = accessKey + nonce + Timestamp;
        Mac sha256Hmac = Mac.getInstance("HmacSHA256");
        SecretKeySpec secretKeySpec = new SecretKeySpec(accessSecret.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
        sha256Hmac.init(secretKeySpec);
        byte[] hmacBytes = sha256Hmac.doFinal(stringSignTemp.getBytes(StandardCharsets.UTF_8));
        String sign = Base64.getEncoder().encodeToString(hmacBytes);
        String targetUrl = "https://api.spruceiot.cn/api/v1/sim/rebind";
        URL url = new URL(targetUrl);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");
        connection.setDoOutput(true);
        connection.setRequestProperty("Accept-Charset", "UTF-8");
        connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
        connection.setRequestProperty("Access-Control-Allow-Origin", "http://localhost:8080");
        connection.setRequestProperty("AccessKey", accessKey);
        connection.setRequestProperty("Nonce", nonce);
        connection.setRequestProperty("Timestamp", Timestamp);
        connection.setRequestProperty("Sign", sign);
 
        // 构造请求体
        JSONObject requestBody = new JSONObject();
        requestBody.put("iccid",card.getCardnumber() );
        requestBody.put("bindType", bindType);
 
        // 将请求体写入输出流
        OutputStream os = connection.getOutputStream();
        os.write(requestBody.toString().getBytes("UTF-8"));
        os.flush();
        os.close();
 
        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
        StringBuilder response1 = new StringBuilder();
 
        String line;
        while ((line = reader.readLine()) != null) {
            response1.append(line);
        }
 
        reader.close();
        connection.disconnect();
        JSONObject jsonObject = new JSONObject(response1);
        int code = jsonObject.getInt("code");
        String message = jsonObject.getStr("message");
        JSONObject result = jsonObject.getJSONObject("result");
//        int total1 = result.getInt("total");
//        JSONArray list = result.getJSONArray("list");
 
//        for (int i = 0; i < list.size(); ++i) {
//            JSONObject item = list.getJSONObject(i);
//            String msisdn = item.getStr("msisdn");
//            String iccid = item.getStr("iccid");
//            String imsi = item.getStr("imsi");
//            System.out.println("msisdn: " + msisdn + ", iccid: " + iccid + ", imsi: " + imsi);
//        }
//        if (code!=0){
//            return message;
//        }else{
        return jsonObject;
//        }
 
    }
 
 
    @GetMapping({"conversioncard"})
    public JSONObject conversioncard(String id) throws Exception {
 
 
        System.out.println();
        String accessKey = "448c2cedcdce41428a290d144e81ab6e";
        String str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String accessSecret = "RgoIWycMYGmQfrLwLuT2VWawAhwMO8w7P9zh2dZp";
        String nonce = "";
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String Timestamp = dateFormat.format(now);
        int length = 30;
        Random random = new Random();
 
        for (int i = length; i > 0; --i) {
            int index = random.nextInt(str.length());
            nonce = nonce + str.charAt(index);
        }
 
        String stringSignTemp = accessKey + nonce + Timestamp;
        Mac sha256Hmac = Mac.getInstance("HmacSHA256");
        SecretKeySpec secretKeySpec = new SecretKeySpec(accessSecret.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
        sha256Hmac.init(secretKeySpec);
        byte[] hmacBytes = sha256Hmac.doFinal(stringSignTemp.getBytes(StandardCharsets.UTF_8));
        String sign = Base64.getEncoder().encodeToString(hmacBytes);
        String targetUrl = "https://api.spruceiot.cn/api/v1/sim/detail/query?cNo=" + id;
        URL url = new URL(targetUrl);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestProperty("Accept-Charset", "UTF-8");
        connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
        connection.setRequestProperty("Access-Control-Allow-Origin", "http://localhost:8080");
        connection.setRequestProperty("AccessKey", accessKey);
        connection.setRequestProperty("Nonce", nonce);
        connection.setRequestProperty("Timestamp", Timestamp);
        connection.setRequestProperty("Sign", sign);
        connection.connect();
        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
        StringBuilder response1 = new StringBuilder();
 
        String line;
        while ((line = reader.readLine()) != null) {
            response1.append(line);
        }
 
        reader.close();
        connection.disconnect();
        JSONObject jsonObject = new JSONObject(response1);
        int code = jsonObject.getInt("code");
        String message = jsonObject.getStr("message");
        JSONObject result = jsonObject.getJSONObject("result");
 
 
        return jsonObject;
    }
}