Procházet zdrojové kódy

更新报表导出接口

liu před 2 roky
rodič
revize
45b445fed5

+ 7 - 0
src/main/java/com/template/api/SmartFaceDiscernControllerAPI.java

@@ -0,0 +1,7 @@
+package com.template.api;
+
+import org.springframework.web.bind.annotation.RequestMapping;
+
+@RequestMapping("/auto/smart-face-discern")
+public interface SmartFaceDiscernControllerAPI {
+}

+ 22 - 0
src/main/java/com/template/common/utils/ExcelUtil3.java

@@ -0,0 +1,22 @@
+package com.template.common.utils;
+
+
+
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.support.ExcelTypeEnum;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.util.List;
+
+public class ExcelUtil3 {
+
+    public static void process(String fileName, List target, Class clazs , HttpServletResponse response) throws IOException {
+        response.setCharacterEncoding("UTF-8");
+        response.setContentType("application/vnd.ms-excel");
+        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "utf-8"));
+        EasyExcel.write(response.getOutputStream(), clazs).excelType(ExcelTypeEnum.XLS).autoCloseStream(Boolean.TRUE)
+                .sheet("预警报表").doWrite(target);
+    }
+}

+ 54 - 0
src/main/java/com/template/common/utils/Md5Utils.java

@@ -0,0 +1,54 @@
+package com.template.common.utils;
+
+import com.alibaba.druid.util.Utils;
+
+import java.math.BigInteger;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+public class Md5Utils {
+
+    public static String md5One(String passWord) {
+        byte[] secretBytes = null;
+        try {
+            secretBytes = MessageDigest.getInstance("md5").digest(
+                    passWord.getBytes());
+        } catch (NoSuchAlgorithmException e) {
+            throw new RuntimeException("没有md5这个算法!");
+        }
+        String md5code = new BigInteger(1, secretBytes).toString(16);// 16进制数字
+        // 如果生成数字未满32位,需要前面补0
+        for (int i = 0; i < 32 - md5code.length(); i++) {
+            md5code = "0" + md5code;
+        }
+        return md5code;
+    }
+
+    /**
+     * 工具类md5加密
+     * @param password
+     * @return
+     */
+    public static  String md5Two(String password){
+        String s = Utils.md5(password);
+        return s;
+    }
+
+    /**
+     * 可逆的的加密解密方法;两次是解密,一次是加密
+     * @param inStr
+     * @return
+     */
+    public static String convertMD5(String inStr){
+
+        char[] a = inStr.toCharArray();
+        for (int i = 0; i < a.length; i++){
+            a[i] = (char) (a[i] ^ 't');
+        }
+        String s = new String(a);
+        return s;
+
+    }
+
+
+}

+ 30 - 0
src/main/java/com/template/common/utils/WarningEntity.java

@@ -0,0 +1,30 @@
+package com.template.common.utils;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import lombok.Data;
+
+@Data
+public class WarningEntity {
+
+    @ExcelProperty("姓名")
+    private String name;
+
+    @ExcelProperty("事件")
+    private String type;
+
+    @ExcelProperty("地点")
+    private String location;
+
+    @ExcelProperty("时间")
+    private String dateTime;
+
+    @ExcelProperty("备注")
+    private String remark;
+
+    @ExcelProperty("状态")
+    private String state;
+
+    @ExcelProperty("图片")
+    private String image;
+
+}

+ 55 - 3
src/main/java/com/template/controller/SmartFaceDiscernController.java

@@ -1,21 +1,73 @@
 package com.template.controller;
 
 
+import com.alibaba.fastjson.JSONObject;
+import com.template.api.SmartFaceDiscernControllerAPI;
+import com.template.common.utils.Md5Utils;
+import com.template.services.SmartFaceDiscernService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestMapping;
 
 import org.springframework.web.bind.annotation.RestController;
 
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+
 /**
  * <p>
- *  前端控制器
+ * 前端控制器
  * </p>
  *
  * @author ceshi
  * @since 2024-01-18
  */
 @RestController
-@RequestMapping("/auto/smart-face-discern")
-public class SmartFaceDiscernController {
+public class SmartFaceDiscernController implements SmartFaceDiscernControllerAPI {
+
+    @Autowired
+    SmartFaceDiscernService smartFaceDiscernService;
+
+    static String appid = "sc1eb792c1ea3237e9";
+    static String appSecret = "61afd794ed3244e995c5e894e5788193";
+    static String schoolCode = "SL1704880825203963";
+
+    public void a() {
+        String url = "http://schoolopenapi.szymzh.com/openapi/record/searchrecord";
+
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("appid",appid);
+        jsonObject.put("timestamp", "20240122162820000");
+        jsonObject.put("schoolno", schoolCode);
+        JSONObject data = new JSONObject();
+        data.put("pageindex", "1");
+        data.put("pagesize", "10");
+        String dataString = data.toJSONString();
+
+
+        jsonObject.put("data", data);
+
+        String stringA="appid="+appid+"&data="+dataString+"&schoolno="+schoolCode+"&timestamp="+"20240122162820000"+"&";
+
+        String stringSignTemp=stringA+"key="+appSecret;
+
+        String sign = Md5Utils.md5One(stringSignTemp);
+
+        jsonObject.put("sign", sign);
+
+
+
+    }
+
+    public static void main(String[] args) {
+        String s = String.valueOf(LocalDateTime.now(ZoneOffset.UTC).toInstant(ZoneOffset.of("+8")).toEpochMilli());
+        System.out.println("s = " + s);
+        JSONObject data = new JSONObject();
+        data.put("pageindex", "1");
+        data.put("pagesize", "10");
+        String s1 = data.toJSONString();
+        System.out.println("s1 = " + s1);
+
+    }
 
 }
 

+ 45 - 27
src/main/java/com/template/controller/SmartWarningController.java

@@ -1,15 +1,14 @@
 package com.template.controller;
 
 
+import cn.hutool.poi.excel.ExcelUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.template.api.SmartWarningControllerAPI;
 import com.template.common.result.ResponseStatusEnum;
-import com.template.common.utils.ExcelUtils;
-import com.template.common.utils.ExcelUtils2;
-import com.template.common.utils.paramUtils;
+import com.template.common.utils.*;
 import com.template.model.dto.OperationWarningDto;
 import com.template.model.dto.WarningSavePushDto;
 import com.template.model.pojo.SmartDepartment;
@@ -31,6 +30,8 @@ import org.springframework.web.bind.annotation.RestController;
 import org.yaml.snakeyaml.events.Event;
 
 import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -144,10 +145,14 @@ public class SmartWarningController implements SmartWarningControllerAPI {
     @Override
     public void excelSmartWarning(HttpServletResponse response, String location, String state) {
         // 表头数据
-        List<Object> head = Arrays.asList("姓名", "事件", "地点", "时间", "备注", "状态", "图片");
+//        List<Object> head = Arrays.asList("姓名","事件","地点","时间","备注","状态","图片");
+//
+//        List<List<Object>> sheetDataList = new ArrayList<>();
+//        sheetDataList.add(head);
 
-        List<List<Object>> sheetDataList = new ArrayList<>();
-        sheetDataList.add(head);
+
+        String fileName = "预警.xls";
+        List<WarningEntity> warningEntities = new ArrayList<>();
 
 //        获取数据
         LambdaQueryWrapper<SmartWarning> queryWrapper = new LambdaQueryWrapper<>();
@@ -155,31 +160,44 @@ public class SmartWarningController implements SmartWarningControllerAPI {
                 .eq(ObjectUtils.isNotEmpty(state), SmartWarning::getStatu, state);
         List<SmartWarning> list = smartWarningService.list(queryWrapper);
 
-        if (ObjectUtils.isNotEmpty(list) && list.size() > 0) {
-            for (SmartWarning smartWarning : list) {
-                List<Object> user = new ArrayList<>();
-                user.add(smartWarning.getWarningName());
-                user.add(smartWarning.getType());
-                user.add(smartWarning.getLocation());
-                user.add(smartWarning.getDateTime());
-                user.add(smartWarning.getRemark());
-                Integer statu = smartWarning.getStatu();
-                String status = "";
-                if (statu == 0) {
-                    status = "未处理";
-                } else if (statu == 1) {
-                    status = "已处理";
-                }
-                user.add(status);
-                user.add(smartWarning.getImage());
-                // 将数据汇总
-                sheetDataList.add(user);
+
+        for (SmartWarning smartWarning : list) {
+            WarningEntity warning = new WarningEntity();
+//                if (ObjectUtils.isNotEmpty(smartWarning.getWarningName())) {
+            warning.setName(smartWarning.getWarningName());
+//                }else {
+//                    user.add("无");
+//                }
+
+            warning.setType(smartWarning.getType());
+
+            warning.setLocation(smartWarning.getLocation());
+
+            warning.setDateTime(smartWarning.getDateTime());
+
+            warning.setRemark(smartWarning.getRemark());
+
+            Integer statu = smartWarning.getStatu();
+            String status = "";
+            if (statu == 0) {
+                status = "未处理";
+            } else if (statu == 1) {
+                status = "已处理";
             }
+            warning.setState(status);
+
+            warning.setImage(smartWarning.getImage());
 
+            // 将数据汇总
+            warningEntities.add(warning);
         }
 
-        // 导出数据
-        ExcelUtils2.export(response, "预警表", sheetDataList);
+
+        try {
+            ExcelUtil3.process(fileName, warningEntities, WarningEntity.class, response);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
 
     }