fei.wang
7 天以前 e15f561a1f9eddfde503d59baf45a860b131928e
src/main/java/com/flow/controller/IndexController.java
@@ -8,29 +8,47 @@
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.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.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
@RestController
@@ -40,6 +58,15 @@
    CardService cardService;
    @Autowired
    CompanyService companyService;
    @Autowired
    CardMapper cardMapper;
    @Autowired
    OperationLogMapper operationLogMapper;
    @Autowired
    OperationLogService operationLogService;
    public IndexController() {
    }
@@ -52,45 +79,53 @@
        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 {
        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());
        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));
                    }
                    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).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));
                    }
                }
            }
        }
@@ -102,40 +137,39 @@
        return this.companyService.chaZi(Zong);
    }
    @GetMapping({"FindCardZi"})
    public result<List<Card>> FindCardZi(String Zong, Integer page, Integer limit) throws Exception {
        PageInfo<Card> cz = this.cardService.FindCardaZi(Zong, 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());
    @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){
                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 ((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 (!((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) {
        return this.cardService.DeleteCard(num);
    public int DeleteCard(String num, String caozuoname) {
        return this.cardService.DeleteCard(num, caozuoname);
    }
    @PostMapping({"Update"})
@@ -148,23 +182,114 @@
    @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().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());
        int i;
        Card card1;
        if (str.length > 1 && str1.length > 1) {
            for(i = 0; i < str.length; ++i) {
            for (i = 0; i < str.length; ++i) {
                card1 = new Card();
                card1.setCompany(card.getCompany());
                card1.setCardnumber(str[i]);
@@ -176,10 +301,12 @@
                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) {
            for (i = 0; i < str.length; ++i) {
                card1 = new Card();
                card1.setCompany(card.getCompany());
                card1.setCardnumber(str[i]);
@@ -191,10 +318,12 @@
                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) {
            for (i = 0; i < str.length; ++i) {
                card1 = new Card();
                card1.setCompany(card.getCompany());
                card1.setCardnumber(str[i]);
@@ -202,14 +331,16 @@
                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 {
            if (card.getCardnumber()!=null){
            if (card.getCardnumber() != null && card.getCardnumber() != "") {
                card.setCompany(card.getCompany());
                this.cardService.addCard(card);
            }
@@ -223,26 +354,35 @@
    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) {
            ((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);
        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));
            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));
                    }
                }
            }
        }
@@ -271,7 +411,7 @@
        int length = 30;
        Random random = new Random();
        for(int i = length; i > 0; --i) {
        for (int i = length; i > 0; --i) {
            int index = random.nextInt(str.length());
            nonce = nonce + str.charAt(index);
        }
@@ -284,7 +424,7 @@
        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();
        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");
@@ -297,7 +437,7 @@
        StringBuilder response1 = new StringBuilder();
        String line;
        while((line = reader.readLine()) != null) {
        while ((line = reader.readLine()) != null) {
            response1.append(line);
        }
@@ -310,7 +450,7 @@
        int total1 = result.getInt("total");
        JSONArray list = result.getJSONArray("list");
        for(int i = 0; i < list.size(); ++i) {
        for (int i = 0; i < list.size(); ++i) {
            JSONObject item = list.getJSONObject(i);
            String msisdn = item.getStr("msisdn");
            String iccid = item.getStr("iccid");
@@ -339,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;
    }
}