From a800938e10736b81762cd98e207600690d7044b5 Mon Sep 17 00:00:00 2001
From: 安瑾然 <107107765@qq.com>
Date: 星期四, 21 七月 2022 17:37:54 +0800
Subject: [PATCH] commit

---
 src/main/java/com/example/jz/dao/ReportDao.java                  |    2 
 src/main/java/com/example/jz/service/ReportService.java          |    1 
 src/main/java/com/example/jz/controller/ReportController.java    |   10 ---
 src/main/java/com/example/jz/controller/UserController.java      |   70 +++++++++++++++++-----
 src/main/java/com/example/jz/controller/CauseController.java     |    7 ++
 src/main/java/com/example/jz/service/impl/CauseServiceImpl.java  |   24 +++++--
 src/main/java/com/example/jz/service/CauseService.java           |    3 +
 src/main/java/com/example/jz/service/impl/ReportServiceImpl.java |   23 ++++++-
 8 files changed, 102 insertions(+), 38 deletions(-)

diff --git a/src/main/java/com/example/jz/controller/CauseController.java b/src/main/java/com/example/jz/controller/CauseController.java
index f3c288e..55f3170 100644
--- a/src/main/java/com/example/jz/controller/CauseController.java
+++ b/src/main/java/com/example/jz/controller/CauseController.java
@@ -132,5 +132,12 @@
         }
         return R.ok(causeService.addReportPeople(addReportDto));
     }
+
+    @ApiOperation(httpMethod = "GET", value = "鑾峰彇妗堜欢鐨刬d鍜屽悕绉板垪琛�")
+    @GetMapping("/getCauseIdAndName")
+    @ApiResponse(message = "鎵ц鎴愬姛", code = 200)
+    public R getCauseIdAndName() {
+        return R.ok(causeService.getCauseIdAndName());
+    }
 }
 
diff --git a/src/main/java/com/example/jz/controller/ReportController.java b/src/main/java/com/example/jz/controller/ReportController.java
index 6ea3049..ec097f7 100644
--- a/src/main/java/com/example/jz/controller/ReportController.java
+++ b/src/main/java/com/example/jz/controller/ReportController.java
@@ -72,7 +72,6 @@
     @PostMapping
     @ApiOperation(value = "鎶ユ")
     public R<Boolean> insert(@RequestBody AddReportDto addReportDto) {
-
         return R.ok(reportService.addReport(addReportDto));
     }
 
@@ -117,15 +116,6 @@
     @ApiResponse(message = "鎵ц鎴愬姛", code = 200)
     public void exportReport(@RequestParam(value = "id") Integer id, HttpServletResponse response) {
         reportService.exportReporter(id, response);
-    }
-
-    @ApiOperation(httpMethod = "POST", value = "妗堜欢鍙�-鎶ユ浜哄憳-鎶ユ浜哄憳瀵煎叆")
-    @PostMapping("/upload")
-    @ApiResponse(message = "鎵ц鎴愬姛", code = 200)
-    @SneakyThrows
-    public R upload(@RequestParam(value = "multipartFile") MultipartFile multipartFile) {
-        reportService.loadFile(multipartFile);
-        return R.ok();
     }
 }
 
diff --git a/src/main/java/com/example/jz/controller/UserController.java b/src/main/java/com/example/jz/controller/UserController.java
index 6b2c106..20d0031 100644
--- a/src/main/java/com/example/jz/controller/UserController.java
+++ b/src/main/java/com/example/jz/controller/UserController.java
@@ -3,9 +3,16 @@
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.api.ApiController;
 import com.baomidou.mybatisplus.extension.api.R;
+import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.example.jz.modle.entity.User;
 import com.example.jz.service.UserService;
+import com.example.jz.utils.Md5Utils;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
@@ -15,17 +22,19 @@
 /**
  * 鐢ㄦ埛琛�(User)琛ㄦ帶鍒跺眰
  *
- * @author makejava
+ * @author 瀹夌懢鐒�
  * @since 2022-07-11 16:35:57
  */
 @RestController
 @RequestMapping("user")
+@Api(tags = "鐢ㄦ埛绠$悊")
 public class UserController extends ApiController {
-    /**
-     * 鏈嶅姟瀵硅薄
-     */
-    @Resource
     private UserService userService;
+
+    @Autowired
+    public void setUserService(UserService userService) {
+        this.userService = userService;
+    }
 
     /**
      * 鍒嗛〉鏌ヨ鎵�鏈夋暟鎹�
@@ -35,6 +44,7 @@
      * @return 鎵�鏈夋暟鎹�
      */
     @GetMapping
+    @ApiOperation("鍒嗛〉鏌ヨ鎵�鏈夋暟鎹�")
     public R selectAll(Page<User> page, User user) {
         return success(this.userService.page(page, new QueryWrapper<>(user)));
     }
@@ -46,19 +56,9 @@
      * @return 鍗曟潯鏁版嵁
      */
     @GetMapping("{id}")
+    @ApiOperation("閫氳繃涓婚敭鏌ヨ鍗曟潯鏁版嵁")
     public R selectOne(@PathVariable Serializable id) {
         return success(this.userService.getById(id));
-    }
-
-    /**
-     * 鏂板鏁版嵁
-     *
-     * @param user 瀹炰綋瀵硅薄
-     * @return 鏂板缁撴灉
-     */
-    @PostMapping
-    public R insert(@RequestBody User user) {
-        return success(this.userService.save(user));
     }
 
     /**
@@ -68,8 +68,9 @@
      * @return 淇敼缁撴灉
      */
     @PutMapping
+    @ApiOperation("淇敼鐢ㄦ埛鏁版嵁")
     public R update(@RequestBody User user) {
-        return success(this.userService.updateById(user));
+        return success(userService.updateById(user));
     }
 
     /**
@@ -79,7 +80,42 @@
      * @return 鍒犻櫎缁撴灉
      */
     @DeleteMapping
+    @ApiOperation("鍒犻櫎鐢ㄦ埛鏁版嵁")
     public R delete(@RequestParam("idList") List<Long> idList) {
         return success(this.userService.removeByIds(idList));
     }
+
+    /**
+     * 娣诲姞绠$悊鍛�
+     *
+     * @param id       鐢ㄦ埛id
+     * @param username 绠$悊鍛樼敤鎴峰悕
+     * @param password 绠$悊鍛樺瘑鐮�
+     * @return
+     */
+    @PostMapping("/addAdmin/{id}")
+    @ApiOperation("娣诲姞绠$悊鍛�")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "password", value = "瀵嗙爜", required = true, dataType = "String"),
+            @ApiImplicitParam(name = "username", value = "鐢ㄦ埛鍚�", required = true, dataType = "String")
+    })
+    public R addAdmin(@PathVariable Serializable id, String username, String password) {
+        User user = userService.getById(id).setLoginUsername(username).setLoginPassword(Md5Utils.md5(password)).setRole(1);
+        return success(userService.updateById(user));
+    }
+
+    /**
+     * 閲嶇疆绠$悊鍛樺瘑鐮�
+     *
+     * @param id 鐢ㄦ埛id
+     * @return
+     */
+    @GetMapping("/resetPassword/{id}")
+    @ApiOperation("閲嶇疆绠$悊鍛樺瘑鐮�")
+    public R resetPassword(@PathVariable Serializable id) {
+        User user = userService.getById(id);
+        // 閲嶇疆鍒濆瀵嗙爜涓鸿韩浠借瘉鍚庡叚浣�
+        user.setLoginPassword(Md5Utils.md5(user.getUserIdcard().substring(user.getUserIdcard().length() - 6)));
+        return success(userService.updateById(user));
+    }
 }
diff --git a/src/main/java/com/example/jz/dao/ReportDao.java b/src/main/java/com/example/jz/dao/ReportDao.java
index 53fd686..eee3b7d 100644
--- a/src/main/java/com/example/jz/dao/ReportDao.java
+++ b/src/main/java/com/example/jz/dao/ReportDao.java
@@ -19,7 +19,7 @@
 @Mapper
 public interface ReportDao extends BaseMapper<Report> {
 
-    Page<ReportListVo> getPage(Page<ReportListVo> page,@Param("reportDto") ReportParamDto reportParamDto);
+    Page<ReportListVo> getPage(Page<ReportListVo> page,@Param("reportParamDto") ReportParamDto reportParamDto);
 
     ReportListVo getReportListVoById(Serializable id);
 
diff --git a/src/main/java/com/example/jz/service/CauseService.java b/src/main/java/com/example/jz/service/CauseService.java
index 769f683..5cdaf1a 100644
--- a/src/main/java/com/example/jz/service/CauseService.java
+++ b/src/main/java/com/example/jz/service/CauseService.java
@@ -13,6 +13,7 @@
 import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 妗堜欢琛�(Cause)琛ㄦ湇鍔℃帴鍙�
@@ -79,5 +80,7 @@
     void loadFile(MultipartFile multipartFile);
 
     Boolean addReportPeople(AddReportDto addReportDto);
+
+    List<Map<String,String>> getCauseIdAndName();
 }
 
diff --git a/src/main/java/com/example/jz/service/ReportService.java b/src/main/java/com/example/jz/service/ReportService.java
index c0141d7..b99cbef 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;
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 f5156b6..40f186f 100644
--- a/src/main/java/com/example/jz/service/impl/CauseServiceImpl.java
+++ b/src/main/java/com/example/jz/service/impl/CauseServiceImpl.java
@@ -26,9 +26,7 @@
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -158,7 +156,7 @@
     @Transactional(rollbackFor = BusinessException.class)
     public void loadFile(MultipartFile multipartFile) {
         ArrayList<CauseLoadDto> causeLoadDtos = new ArrayList<>();
-        EasyExcel.read(multipartFile.getInputStream(),CauseLoadDto.class, new AnalysisEventListener<CauseLoadDto>() {
+        EasyExcel.read(multipartFile.getInputStream(), CauseLoadDto.class, new AnalysisEventListener<CauseLoadDto>() {
                     @Override
                     public void invoke(CauseLoadDto data, AnalysisContext context) {
                         if (StringUtils.isNotBlank(data.getName())&&StringUtils.isNotBlank(data.getUserName())){
@@ -177,7 +175,7 @@
                 a -> {
                     Cause cause = new Cause();
                     BeanUtils.copyProperties(a, cause);
-                    if (StringUtils.isBlank(a.getStatus())){
+                    if (StringUtils.isBlank(a.getStatus())) {
                         throw new BusinessException("鐘舵�佷笉鑳戒负绌�");
                     }
                     if (a.getStatus().equals(CauseEnums.UNCHECKED.getMsg())) {
@@ -196,10 +194,10 @@
                         cause.setStatus(CauseEnums.HASBEENDROPPED.value());
                     }
                     cause.setCtime(new Date());
-                    if (StringUtils.isBlank(a.getUserName())){
+                    if (StringUtils.isBlank(a.getUserName())) {
                         throw new BusinessException("璐熻矗浜轰笉鍏佽涓虹┖");
                     }
-                    if (userDao.selectOne(new QueryWrapper<User>().eq("real_name", a.getUserName()))==null){
+                    if (userDao.selectOne(new QueryWrapper<User>().eq("real_name", a.getUserName())) == null) {
                         throw new BusinessException("璐熻矗浜轰笉瀛樺湪");
                     }
                     Integer id = userDao.selectOne(new QueryWrapper<User>().eq("real_name", a.getUserName())).getId();
@@ -238,4 +236,16 @@
                 .setCauseId(groupDao.selectOne(new QueryWrapper<Group>().eq("id", addReportDto.getGroupId())).getCauseId());
         return reportDao.insert(report) > 0;
     }
+
+    @Override
+    public List<Map<String, String>> getCauseIdAndName() {
+        ArrayList<Map<String, String>> maps = new ArrayList<>();
+        causeDao.selectList(null).stream().forEach(a -> {
+            Map<String, String> map = new HashMap<>();
+            map.put("id", a.getId().toString());
+            map.put("name", a.getName());
+            maps.add(map);
+        });
+        return maps;
+    }
 }
\ No newline at end of file
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 d6f26ba..3fa340e 100644
--- a/src/main/java/com/example/jz/service/impl/ReportServiceImpl.java
+++ b/src/main/java/com/example/jz/service/impl/ReportServiceImpl.java
@@ -3,6 +3,7 @@
 import com.alibaba.excel.EasyExcel;
 import com.alibaba.excel.metadata.data.ImageData;
 import com.alibaba.excel.metadata.data.WriteCellData;
+import com.alibaba.excel.support.ExcelTypeEnum;
 import com.alibaba.excel.util.IoUtils;
 import com.alibaba.excel.util.StringUtils;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -12,12 +13,19 @@
 import com.example.jz.dao.*;
 import com.example.jz.modle.dto.AddReportDto;
 import com.example.jz.modle.dto.ReportParamDto;
+import com.example.jz.modle.entity.Group;
+import com.example.jz.modle.entity.GroupUser;
+import com.example.jz.modle.entity.Report;
+import com.example.jz.modle.entity.User;
+import com.example.jz.modle.vo.ReportListVo;
+import com.example.jz.dao.*;
 import com.example.jz.modle.entity.*;
 import com.example.jz.modle.vo.ExportExcelReportVo;
 import com.example.jz.modle.vo.ReportListVo;
 import com.example.jz.service.MinIOService;
 import com.example.jz.service.ReportService;
 import lombok.SneakyThrows;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -28,9 +36,11 @@
 import java.io.Serializable;
 import java.net.URL;
 import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
+import java.io.Serializable;
 import java.util.Date;
 import java.util.List;
 
@@ -168,15 +178,22 @@
                     .setModifyTime(new Date()).setUserRegtime(new Date()).setPic(addReportDto.getPic());
             userDao.insert(user);
         }
+        // 娣诲姞浜哄憳杩涚兢缁�
+        groupUserDao.insert(new GroupUser()
+                .setGroupId(groupDao.selectOne(new QueryWrapper<Group>().eq("cause_id", addReportDto.getCauseId())).getId())
+                .setUserId(user.getId()).setCtime(new Date())
+                .setBanSpeech(0));
         // 娣诲姞鎶ユ淇℃伅
         Report report = new Report();
         BeanUtils.copyProperties(addReportDto, report);
         report
                 .setUserId(user.getId())
                 .setCtime(new Date())
-                .setStatus(0)
+                .setStatus(1)
                 .setReportMethod("鐜板満褰曞叆")
-                .setIsCommission("0").setReportTime(new Date());
+                .setIsCommission("0").setReportTime(new Date())
+                .setCauseId(addReportDto.getCauseId());
         return reportDao.insert(report) > 0;
     }
-}
\ No newline at end of file
+}
+

--
Gitblit v1.8.0