From f227e6ac3439116a0f8cc185bce053e19bd65307 Mon Sep 17 00:00:00 2001
From: wl <173@qq.com>
Date: 星期三, 28 十二月 2022 11:50:16 +0800
Subject: [PATCH] fix: 优化code
---
src/main/java/com/example/jz/controller/ReportController.java | 45 +++++++++++++++++++++++++++++++++++++--------
1 files changed, 37 insertions(+), 8 deletions(-)
diff --git a/src/main/java/com/example/jz/controller/ReportController.java b/src/main/java/com/example/jz/controller/ReportController.java
index 2734a05..aa13342 100644
--- a/src/main/java/com/example/jz/controller/ReportController.java
+++ b/src/main/java/com/example/jz/controller/ReportController.java
@@ -1,24 +1,33 @@
package com.example.jz.controller;
+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.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.jz.modle.R;
import com.example.jz.modle.dto.AddReportDto;
import com.example.jz.modle.dto.ReportParamDto;
+import com.example.jz.modle.entity.GroupUser;
+import com.example.jz.modle.entity.Message;
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.service.GroupUserService;
+import com.example.jz.service.MessageService;
import com.example.jz.service.ReportService;
+import com.example.jz.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.Serializable;
-import java.util.Date;
/**
* 鎶ユ琛�(Report)琛ㄦ帶鍒跺眰
@@ -35,6 +44,12 @@
*/
@Resource
private ReportService reportService;
+ @Resource
+ GroupUserService groupUserService;
+ @Resource
+ MessageService messageService;
+ @Autowired
+ UserService userService;
/**
* 鍒嗛〉鏌ヨ鎵�鏈夋暟鎹�
@@ -64,13 +79,12 @@
/**
* 鎶ユ
*
- * @param AddReportDto 瀹炰綋瀵硅薄
+ * @param addReportDto 瀹炰綋瀵硅薄
* @return 鏂板缁撴灉
*/
@PostMapping
@ApiOperation(value = "鎶ユ")
public R<Boolean> insert(@RequestBody AddReportDto addReportDto) {
-
return R.ok(reportService.addReport(addReportDto));
}
@@ -86,15 +100,28 @@
return R.ok(reportService.audit(report));
}
- @ApiOperation(httpMethod = "PUT", value = "鎶ユ浜虹紪杈�")
+ @ApiOperation(httpMethod = "PUT", value = "妗堜欢鍙�-鎶ユ浜哄憳-缂栬緫")
@PutMapping("/updateReport")
@ApiResponse(message = "鎵ц鎴愬姛", code = 200)
- public R updateReport(@RequestBody Report report) {
+ @Transactional(rollbackFor = Exception.class)
+ public R updateReport(@RequestBody AddReportDto report) {
+ int imgIndexFirst = report.getPic().indexOf("/img");
+ int imgIndexEnd = report.getPic().indexOf("?");
+ String pic = report.getPic().substring(imgIndexFirst + 5, imgIndexEnd);
+ report.setPic(pic);
reportService.updateById(report);
+ Report one = reportService.getOne(new LambdaQueryWrapper<Report>().eq(Report::getId, report.getId()));
+ User user = new User();
+ user.setRealName(report.getReporterName());
+ user.setUserIdcard(report.getIdcard());
+ user.setUserMobile(report.getMobile());
+ user.setPic(pic);
+ user.setId(one.getUserId());
+ userService.updateById(user);
return R.ok();
}
- @ApiOperation(httpMethod = "DELETE", value = "鎶ユ浜轰汉鍛橀��缇�")
+ @ApiOperation(httpMethod = "DELETE", value = "妗堜欢鍙�-鎶ユ浜哄憳-閫�缇�")
@DeleteMapping("/leaveGroup")
@ApiResponse(message = "鎵ц鎴愬姛", code = 200)
public R leaveGroup(@RequestParam(value = "id") Integer id, @RequestParam(value = "groupId") Integer groupId) {
@@ -102,15 +129,17 @@
return R.ok();
}
- @ApiOperation(httpMethod = "DELETE", value = "鍒犻櫎鎶ユ浜�")
+ @ApiOperation(httpMethod = "DELETE", value = "妗堜欢鍙�-鎶ユ浜哄憳-鍒犻櫎")
@DeleteMapping("/deleteReporter")
@ApiResponse(message = "鎵ц鎴愬姛", code = 200)
public R deleteReporter(@RequestParam(value = "id") Integer id) {
+ groupUserService.remove(new LambdaQueryWrapper<GroupUser>().eq(GroupUser::getUserId, id));
+ messageService.remove(new LambdaQueryWrapper<Message>().eq(Message::getUserId, id));
reportService.removeById(id);
return R.ok();
}
- @ApiOperation(httpMethod = "POST", value = "瀵煎嚭鏉愭枡")
+ @ApiOperation(httpMethod = "POST", value = "妗堜欢鍙�-鎶ユ浜哄憳-鎶ユ鏉愭枡瀵煎嚭")
@PostMapping("/exportReporter")
@ApiResponse(message = "鎵ц鎴愬姛", code = 200)
public void exportReport(@RequestParam(value = "id") Integer id, HttpServletResponse response) {
--
Gitblit v1.8.0