fei.wang
2024-05-13 b9b58b9ef261cb290d93465f88a2cbd814b576f0
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
//
// 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.result;
import com.flow.util.resultutil;
import com.github.pagehelper.PageInfo;
 
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.temporal.ChronoUnit;
import java.util.*;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
 
@RestController
@RequestMapping({"/hxzk"})
public class IndexController {
    @Autowired
    CardService cardService;
    @Autowired
    CompanyService companyService;
 
    @Autowired
    CardMapper cardMapper;
 
    @Autowired
    OperationLogMapper operationLogMapper;
 
    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;
    }
 
    @GetMapping({"FindCard"})
    public result<List<Card>> FindCard(Integer page, Integer limit) throws Exception {
        PageInfo<Card> cz = this.cardService.FindCarda(page, limit);
 
        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));
                    }
                    System.out.println(cz.getList().get(i).getEnddate());
                    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({"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) throws Exception {
        PageInfo<Card> cz = this.cardService.FindCardaZi(card, page, limit);
 
        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) {
        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.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;
    }
 
    @PostMapping({"addCard"})
    public ModelAndView addCard(Card card) throws Exception {
        String[] str = card.getCardnumber().split(";");
        String[] str1 = card.getBindid().split(";");
        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());
                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());
                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(String.valueOf(str1));
                card1.setLocation(card.getLocation());
                card1.setNotes(card.getNotes());
                card1.setEnterdate(card.getEnddate());
                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();
            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());
    }
 
    @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);
    }
}