From e15f561a1f9eddfde503d59baf45a860b131928e Mon Sep 17 00:00:00 2001
From: fei.wang <wf18701153496@163.com>
Date: 星期三, 13 八月 2025 14:22:50 +0800
Subject: [PATCH] 更新最新版代码

---
 src/main/java/com/flow/controller/IndexController.java |  522 +++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 467 insertions(+), 55 deletions(-)

diff --git a/src/main/java/com/flow/controller/IndexController.java b/src/main/java/com/flow/controller/IndexController.java
index 03e3ba8..22f23ce 100644
--- a/src/main/java/com/flow/controller/IndexController.java
+++ b/src/main/java/com/flow/controller/IndexController.java
@@ -17,28 +17,38 @@
 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.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.bind.annotation.*;
 import org.springframework.web.servlet.ModelAndView;
 
 @RestController
@@ -55,6 +65,9 @@
     @Autowired
     OperationLogMapper operationLogMapper;
 
+    @Autowired
+    OperationLogService operationLogService;
+
     public IndexController() {
     }
 
@@ -66,10 +79,10 @@
         return modelAndView;
     }
 
-    @GetMapping({"FindCard"})
-    public result<List<Card>> FindCard(Integer page, Integer limit) throws Exception {
-        PageInfo<Card> cz = this.cardService.FindCarda(page, limit);
+    @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);
@@ -82,33 +95,37 @@
                 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));
-                        }
-                    }
+//                    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));
+                    }
                 }
-
-
             }
         }
 
@@ -121,9 +138,8 @@
     }
 
     @PostMapping({"FindCardZi"})
-    public result<List<Card>> FindCardZi(Card card, Integer page, Integer limit) throws Exception {
-        PageInfo<Card> cz = this.cardService.FindCardaZi(card, page, limit);
-
+    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);
@@ -147,14 +163,13 @@
                 }
             }
         }
-
         return resultutil.returnSuccess(cz.getTotal(), cz.getList());
     }
 
     @PostMapping({"DeleteCard"})
-    public int DeleteCard(String num ,String caozuoname) {
+    public int DeleteCard(String num, String caozuoname) {
 
-        return this.cardService.DeleteCard(num,caozuoname);
+        return this.cardService.DeleteCard(num, caozuoname);
     }
 
     @PostMapping({"Update"})
@@ -167,13 +182,14 @@
 
     @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());
+        operationLog.setCaozuocontent("淇敼鍗″彿锛�" + tbFuwuqi1.getCardnumber());
 //        operationLogMapper.addOperationLog(operationLog);
         operationLog.setCaozuoname(card.getCaozuoname());
         Date date = new Date();
@@ -185,13 +201,15 @@
         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());
+        operationLog.setCaozuocontent("淇敼鍗″彿锛�" + card.getCardnumber());
         Date date = new Date();
         SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         operationLog.setCaozuodate(formatter.format(date));
@@ -202,10 +220,69 @@
         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鏈塯etField1()鏂规硶
+            dataRow.createCell(1).setCellValue(data.getCardnumber()); // 鍋囪YourData鏈塯etField2()鏂规硶
+            dataRow.createCell(2).setCellValue(data.getStatus()); // 鍋囪YourData鏈塯etField3()鏂规硶
+            dataRow.createCell(3).setCellValue(data.getFlow()); // 鍋囪YourData鏈塯etField3()鏂规硶
+            dataRow.createCell(4).setCellValue(data.getRemainingdays()); // 鍋囪YourData鏈塯etField3()鏂规硶
+            dataRow.createCell(5).setCellValue(data.getCarddate()); // 鍋囪YourData鏈塯etField3()鏂规硶
+            dataRow.createCell(6).setCellValue(data.getOperator()); // 鍋囪YourData鏈塯etField3()鏂规硶
+            dataRow.createCell(7).setCellValue(data.getUnitprice()); // 鍋囪YourData鏈塯etField3()鏂规硶
+            dataRow.createCell(8).setCellValue(data.getBindid()); // 鍋囪YourData鏈塯etField3()鏂规硶
+            dataRow.createCell(9).setCellValue(data.getEnddate()); // 鍋囪YourData鏈塯etField3()鏂规硶
+            dataRow.createCell(10).setCellValue(data.getEnterdate()); // 鍋囪YourData鏈塯etField3()鏂规硶
+            dataRow.createCell(11).setCellValue(data.getRechargedate()); // 鍋囪YourData鏈塯etField3()鏂规硶
+            dataRow.createCell(12).setCellValue(data.getRechargemoney()); // 鍋囪YourData鏈塯etField3()鏂规硶
+            dataRow.createCell(13).setCellValue(data.getNotes()); // 鍋囪YourData鏈塯etField3()鏂规硶
+            // 鏍规嵁瀹為檯鎯呭喌濉厖鍏朵粬瀛楁
+        }
+
+        // 璁剧疆鍝嶅簲绫诲瀷鍜屽唴瀹瑰缃�
+        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"));
+
+
+        // 灏咵xcel鍐欏叆鍝嶅簲杈撳嚭娴�
+        try (ServletOutputStream outputStream = response.getOutputStream()) {
+            workbook.write(outputStream);
+        }
+
+        // 鍏抽棴宸ヤ綔绨�
+//        workbook.close();
+    }
+
     @PostMapping({"addCard"})
     public ModelAndView addCard(Card card) throws Exception {
-        String[] str = card.getCardnumber().split(";");
+        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());
@@ -224,6 +301,8 @@
                 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] == "") {
@@ -239,6 +318,8 @@
                 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) {
@@ -250,10 +331,12 @@
                 card1.setOperator(card.getOperator());
                 card1.setFlow(card.getFlow());
                 card1.setUnitprice(card.getUnitprice());
-                card1.setBindid(String.valueOf(str1));
+                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 {
@@ -272,7 +355,7 @@
         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("鍗庢槦鏅烘帶")){
+            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);
@@ -280,20 +363,26 @@
 //            ((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));
+            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));
+                    }
                 }
             }
+
 
         }
 
@@ -390,4 +479,327 @@
     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;
+    }
 }

--
Gitblit v1.9.3