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 | 805 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 805 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/flow/controller/IndexController.java b/src/main/java/com/flow/controller/IndexController.java new file mode 100644 index 0000000..22f23ce --- /dev/null +++ b/src/main/java/com/flow/controller/IndexController.java @@ -0,0 +1,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鏈塯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().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; + } +} -- Gitblit v1.9.3