From d759812b05ceffc6021dee9ebf61bc0c22472df3 Mon Sep 17 00:00:00 2001
From: wl <173@qq.com>
Date: 星期三, 28 十二月 2022 17:41:37 +0800
Subject: [PATCH] fix: 导入和报案方式

---
 src/test/java/com/example/jz/dao/UserDaoTest.java                |   19 ++++-----
 src/main/java/com/example/jz/modle/dto/CauseLoadDto.java         |   12 ++++--
 src/main/java/com/example/jz/service/ReportService.java          |    3 +
 src/main/java/com/example/jz/controller/ReportController.java    |   11 +++++
 src/main/java/com/example/jz/controller/WxAppController.java     |    2 
 src/main/java/com/example/jz/service/impl/CauseServiceImpl.java  |    5 +-
 src/main/java/com/example/jz/service/impl/ReportServiceImpl.java |   33 +++++++++++++++-
 7 files changed, 66 insertions(+), 19 deletions(-)

diff --git a/src/main/java/com/example/jz/controller/ReportController.java b/src/main/java/com/example/jz/controller/ReportController.java
index aa13342..f3ec50d 100644
--- a/src/main/java/com/example/jz/controller/ReportController.java
+++ b/src/main/java/com/example/jz/controller/ReportController.java
@@ -21,9 +21,11 @@
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiResponse;
+import lombok.SneakyThrows;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
@@ -139,6 +141,15 @@
         return R.ok();
     }
 
+    @ApiOperation(httpMethod = "POST", value = "妗堜欢鍙�-妗堜欢褰曞叆-鎶ユ浜哄憳-鎶ユ浜哄厓瀵煎叆")
+    @PostMapping("/reporterUpload")
+    @ApiResponse(message = "鎵ц鎴愬姛", code = 200)
+    @SneakyThrows
+    public R uploadReporter(@RequestParam(value = "multipartFile") MultipartFile multipartFile, Integer causeId) {
+        reportService.loadFileReport(multipartFile,causeId);
+        return R.ok();
+    }
+
     @ApiOperation(httpMethod = "POST", value = "妗堜欢鍙�-鎶ユ浜哄憳-鎶ユ鏉愭枡瀵煎嚭")
     @PostMapping("/exportReporter")
     @ApiResponse(message = "鎵ц鎴愬姛", code = 200)
diff --git a/src/main/java/com/example/jz/controller/WxAppController.java b/src/main/java/com/example/jz/controller/WxAppController.java
index b5965df..c936a00 100644
--- a/src/main/java/com/example/jz/controller/WxAppController.java
+++ b/src/main/java/com/example/jz/controller/WxAppController.java
@@ -164,7 +164,7 @@
         report.setIsInGroup(0);
         report.setCtime(new Date());
         report.setStatus(0);
-        report.setReportMethod("鐜板満褰曞叆");
+        report.setReportMethod("鎵爜鎶ユ");
         return R.ok(reportService.save(report));
     }
 
diff --git a/src/main/java/com/example/jz/modle/dto/CauseLoadDto.java b/src/main/java/com/example/jz/modle/dto/CauseLoadDto.java
index 9247020..6fcbd84 100644
--- a/src/main/java/com/example/jz/modle/dto/CauseLoadDto.java
+++ b/src/main/java/com/example/jz/modle/dto/CauseLoadDto.java
@@ -20,24 +20,28 @@
     @ExcelProperty(value = "妗堜欢鍚嶇О",index = 1)
     private String name;
 
+    @ApiModelProperty(dataType = "String", value = "妗堜欢鍚嶇О")
+    @ExcelProperty(value = "棰勪及鎬婚噾棰�",index = 2)
+    private String totalMoney;
+
     //鏈�鏃╂妗堝彂鏃堕棿
     @ApiModelProperty(dataType = "Date", value = "鏈�鏃╁彂妗堟椂闂�")
-    @ExcelProperty(value = "鏈�鏃╁彂妗堟椂闂�",index = 2)
+    @ExcelProperty(value = "鏈�鏃╁彂妗堟椂闂�",index = 3)
     private Date firstTime;
 
     //妗堜欢鐘舵��
     @ApiModelProperty(dataType = "String", value = "妗堜欢鐘舵��")
-    @ExcelProperty(value = "妗堜欢鐘舵��",index = 3)
+    @ExcelProperty(value = "妗堜欢鐘舵��",index = 4)
     private String status;
 
     //璐熻矗浜�
     @ApiModelProperty(dataType = "String", value = "璐熻矗浜�")
-    @ExcelProperty(value = "璐熻矗浜�",index = 4)
+    @ExcelProperty(value = "璐熻矗浜�",index = 5)
     private String userName;
 
     //妗堜欢鎻忚堪
     @ApiModelProperty(dataType = "String", value = "妗堜欢鎻忚堪")
-    @ExcelProperty(value = "妗堜欢鎻忚堪",index = 5)
+    @ExcelProperty(value = "妗堜欢鎻忚堪",index = 6)
     private String description;
 
 }
diff --git a/src/main/java/com/example/jz/service/ReportService.java b/src/main/java/com/example/jz/service/ReportService.java
index 0977624..9609883 100644
--- a/src/main/java/com/example/jz/service/ReportService.java
+++ b/src/main/java/com/example/jz/service/ReportService.java
@@ -6,6 +6,7 @@
 import com.example.jz.modle.dto.ReportParamDto;
 import com.example.jz.modle.entity.Report;
 import com.example.jz.modle.vo.ReportListVo;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.Serializable;
@@ -40,5 +41,7 @@
     Boolean addReport(AddReportDto addReportDto);
 
     List<Report> listGroup(Integer id);
+
+    void loadFileReport(MultipartFile multipartFile, Integer causeId);
 }
 
diff --git a/src/main/java/com/example/jz/service/impl/CauseServiceImpl.java b/src/main/java/com/example/jz/service/impl/CauseServiceImpl.java
index c59dd88..f30d942 100644
--- a/src/main/java/com/example/jz/service/impl/CauseServiceImpl.java
+++ b/src/main/java/com/example/jz/service/impl/CauseServiceImpl.java
@@ -295,8 +295,9 @@
                 .setUserId(user.getId())
                 .setCtime(new Date())
                 .setStatus(1)
-                .setReportMethod("鍚庡彴褰曞叆")
-                .setIsCommission("0").setReportTime(new Date())
+                .setReportMethod("鐜板満鎶ユ")
+                .setIsCommission("0")
+                .setReportTime(new Date())
                 .setCauseId(addReportDto.getCauseId());
         reportService.save(report);
         return groupUserDao.insert(new GroupUser().setGroupId(group.getId()).setUserId(report.getId()).setCtime(new Date()).setBanSpeech(0)) > 0;
diff --git a/src/main/java/com/example/jz/service/impl/ReportServiceImpl.java b/src/main/java/com/example/jz/service/impl/ReportServiceImpl.java
index 37e6ee6..5ae21e5 100644
--- a/src/main/java/com/example/jz/service/impl/ReportServiceImpl.java
+++ b/src/main/java/com/example/jz/service/impl/ReportServiceImpl.java
@@ -1,6 +1,8 @@
 package com.example.jz.service.impl;
 
 import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.context.AnalysisContext;
+import com.alibaba.excel.event.AnalysisEventListener;
 import com.alibaba.excel.metadata.data.ImageData;
 import com.alibaba.excel.metadata.data.WriteCellData;
 import com.alibaba.excel.util.IoUtils;
@@ -12,6 +14,7 @@
 import com.example.jz.dao.*;
 import com.example.jz.modle.PageParam;
 import com.example.jz.modle.dto.AddReportDto;
+import com.example.jz.modle.dto.AddReportLoadDto;
 import com.example.jz.modle.dto.ReportParamDto;
 import com.example.jz.modle.entity.*;
 import com.example.jz.modle.vo.ExportExcelReportVo;
@@ -25,6 +28,7 @@
 import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
@@ -206,8 +210,9 @@
                 .setCtime(new Date())
                 .setStatus(0)
                 .setIsInGroup(0)
-                .setReportMethod("鍚庡彴褰曞叆")
-                .setIsCommission("0").setReportTime(new Date())
+                .setReportMethod("鐜板満鎶ユ")
+                .setIsCommission("0")
+                .setReportTime(new Date())
                 .setCauseId(addReportDto.getCauseId());
         return reportService.save(report);
     }
@@ -216,4 +221,28 @@
     public List<Report> listGroup(Integer id) {
         return reportDao.selectListGroup(id);
     }
+
+    @Override
+    @SneakyThrows
+    public void loadFileReport(MultipartFile multipartFile, Integer causeId) {
+        EasyExcel.read(multipartFile.getInputStream(), AddReportLoadDto.class, new AnalysisEventListener<AddReportLoadDto>() {
+                    @Override
+                    public void invoke(AddReportLoadDto data, AnalysisContext context) {
+                        if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(data.getReporterName()) && com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(data.getIdcard())) {
+                            AddReportDto addReportDto = new AddReportDto();
+                            BeanUtils.copyProperties(data, addReportDto);
+                            addReportDto.setCauseId(causeId);
+                            addReport(addReportDto);
+                        }
+
+                    }
+
+                    @Override
+                    public void doAfterAllAnalysed(AnalysisContext context) {
+
+                    }
+                })
+                .autoCloseStream(true)
+                .doReadAll();
+    }
 }
\ No newline at end of file
diff --git a/src/test/java/com/example/jz/dao/UserDaoTest.java b/src/test/java/com/example/jz/dao/UserDaoTest.java
index 84eab22..11f6136 100644
--- a/src/test/java/com/example/jz/dao/UserDaoTest.java
+++ b/src/test/java/com/example/jz/dao/UserDaoTest.java
@@ -1,13 +1,8 @@
 package com.example.jz.dao;
 
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.example.jz.modle.entity.User;
-import com.example.jz.utils.Md5Utils;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
-
-import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * @author 瀹夌懢鐒�
@@ -20,11 +15,15 @@
     @Autowired
     private UserDao userDao;
 
+    @Test
     void updateUser() {
-        User user = userDao.selectOne(new LambdaQueryWrapper<>(User.class).eq(User::getId, 1));
-        System.out.println(user);
-        user.setLoginUsername("admin");
-        user.setLoginPassword(Md5Utils.md5("admin"));
-        userDao.updateById(user);
+        String str = "XXO";
+        int conut = 0;
+        for (char c : str.toCharArray()) {
+            if (c != 'O') {
+                conut++;
+            }
+        }
+        System.out.println(conut);
     }
 }
\ No newline at end of file

--
Gitblit v1.8.0