From 8b26fa15912e355e57990946ac52f699130788c2 Mon Sep 17 00:00:00 2001 From: wl <173@qq.com> Date: 星期二, 27 十二月 2022 11:15:21 +0800 Subject: [PATCH] fix: 删除管理删除用户删除案件 --- src/main/java/com/example/jz/controller/ReportController.java | 11 +++++ src/main/java/com/example/jz/controller/UserController.java | 50 ++++++++++++++++++------- src/main/java/com/example/jz/service/impl/CauseServiceImpl.java | 32 +++++++++------ 3 files changed, 66 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/example/jz/controller/ReportController.java b/src/main/java/com/example/jz/controller/ReportController.java index 0b17490..4908e4f 100644 --- a/src/main/java/com/example/jz/controller/ReportController.java +++ b/src/main/java/com/example/jz/controller/ReportController.java @@ -1,14 +1,19 @@ package com.example.jz.controller; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.vo.ReportListVo; +import com.example.jz.service.GroupUserService; +import com.example.jz.service.MessageService; import com.example.jz.service.ReportService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -34,6 +39,10 @@ */ @Resource private ReportService reportService; + @Resource + GroupUserService groupUserService; + @Resource + MessageService messageService; /** * 鍒嗛〉鏌ヨ鎵�鏈夋暟鎹� @@ -105,6 +114,8 @@ @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(); } diff --git a/src/main/java/com/example/jz/controller/UserController.java b/src/main/java/com/example/jz/controller/UserController.java index d5a65b6..73e162d 100644 --- a/src/main/java/com/example/jz/controller/UserController.java +++ b/src/main/java/com/example/jz/controller/UserController.java @@ -1,5 +1,6 @@ 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.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.StringUtils; @@ -7,8 +8,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.example.jz.modle.R; import com.example.jz.modle.dto.ManagerDto; -import com.example.jz.modle.entity.User; -import com.example.jz.service.UserService; +import com.example.jz.modle.entity.*; +import com.example.jz.service.*; import com.example.jz.utils.Md5Utils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -32,6 +33,15 @@ private UserService userService; @Autowired + ReportService reportService; + @Autowired + GroupUserService groupUserService; + @Autowired + MessageService messageService; + @Autowired + CauseService causeService; + + @Autowired public void setUserService(UserService userService) { this.userService = userService; } @@ -48,15 +58,15 @@ public R selectAll(Page<User> page, User user) { return R.ok(this.userService.page(page, new QueryWrapper<User>() .eq("role", 0) - .and(StringUtils.isNotBlank(user.getNickName()) && StringUtils.isNotBlank(user.getRealName()), new Consumer<QueryWrapper<User>>() { - @Override - public void accept(QueryWrapper<User> userQueryWrapper) { - userQueryWrapper.like("real_name", user.getRealName()).or().like("nick_name", user.getNickName()); - } - }) - .like(StringUtils.isNotBlank(user.getNickName())&&StringUtils.isBlank(user.getRealName()), "nick_name", user.getNickName()) + .and(StringUtils.isNotBlank(user.getNickName()) && StringUtils.isNotBlank(user.getRealName()), new Consumer<QueryWrapper<User>>() { + @Override + public void accept(QueryWrapper<User> userQueryWrapper) { + userQueryWrapper.like("real_name", user.getRealName()).or().like("nick_name", user.getNickName()); + } + }) + .like(StringUtils.isNotBlank(user.getNickName()) && StringUtils.isBlank(user.getRealName()), "nick_name", user.getNickName()) .or() - .like(StringUtils.isNotBlank(user.getRealName())&&StringUtils.isBlank(user.getNickName()), "real_name", user.getRealName()) + .like(StringUtils.isNotBlank(user.getRealName()) && StringUtils.isBlank(user.getNickName()), "real_name", user.getRealName()) .orderByDesc("ctime"))); } @@ -93,6 +103,14 @@ @DeleteMapping @ApiOperation("鍒犻櫎鐢ㄦ埛鏁版嵁") public R delete(@RequestParam("id") Integer id) { + reportService + .list(new LambdaQueryWrapper<Report>().eq(Report::getUserId, id)) + .stream() + .forEach(item -> { + groupUserService.remove(new LambdaQueryWrapper<GroupUser>().eq(GroupUser::getUserId, item.getId())); + messageService.remove(new LambdaQueryWrapper<Message>().eq(Message::getUserId, item.getId())); + }); + reportService.remove(new LambdaQueryWrapper<Report>().eq(Report::getUserId, id)); return R.ok(this.userService.removeById(id)); } @@ -112,23 +130,27 @@ @DeleteMapping("/manager") @ApiOperation("鍒犻櫎绠$悊") public R removeManager(@RequestParam Integer id) { + causeService.list(new LambdaQueryWrapper<Cause>().eq(Cause::getUserId, id)).forEach(item -> { + causeService.deleteCause(item.getId()); + }); + messageService.remove(new LambdaQueryWrapper<Message>().eq(Message::getCopId, id)); return R.ok(userService.removeById(id)); } @GetMapping("/manager") @ApiOperation("鍒嗛〉鏌ヨ鎵�鏈夋暟鎹�") public R selectManager(Page<User> page, User user) { - return R.ok( userService.page(page, new QueryWrapper<User>() + return R.ok(userService.page(page, new QueryWrapper<User>() .eq("role", 1) - .and( StringUtils.isNotBlank(user.getUserMobile()) && StringUtils.isNotBlank(user.getRealName()) ,new Consumer<QueryWrapper<User>>() { + .and(StringUtils.isNotBlank(user.getUserMobile()) && StringUtils.isNotBlank(user.getRealName()), new Consumer<QueryWrapper<User>>() { @Override public void accept(QueryWrapper<User> userQueryWrapper) { userQueryWrapper.like("real_name", user.getRealName()).or().like("user_mobile", user.getUserMobile()); } }) - .like(StringUtils.isNotBlank(user.getUserMobile())&&StringUtils.isBlank(user.getRealName()), "user_mobile", user.getUserMobile()) + .like(StringUtils.isNotBlank(user.getUserMobile()) && StringUtils.isBlank(user.getRealName()), "user_mobile", user.getUserMobile()) .or() - .like(StringUtils.isNotBlank(user.getRealName())&&StringUtils.isBlank(user.getUserMobile()), "real_name", user.getRealName()) + .like(StringUtils.isNotBlank(user.getRealName()) && StringUtils.isBlank(user.getUserMobile()), "real_name", user.getRealName()) .orderByDesc("ctime"))); } 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 a36d140..c59dd88 100644 --- a/src/main/java/com/example/jz/service/impl/CauseServiceImpl.java +++ b/src/main/java/com/example/jz/service/impl/CauseServiceImpl.java @@ -58,7 +58,8 @@ UserService userService; @Resource ReportService reportService; - + @Resource + MessageDao messageDao; @Resource AnnouncementDao announcementDao; @@ -115,7 +116,7 @@ } @Override - public PageParam<CauseVo> getCauserListByCondition(String cause, Integer status, Integer size, Integer current,Integer id) { + public PageParam<CauseVo> getCauserListByCondition(String cause, Integer status, Integer size, Integer current, Integer id) { QueryWrapper<Cause> causeQueryWrapper = new QueryWrapper<>(); if (StringUtils.isNotBlank(cause)) { causeQueryWrapper.and(a -> a.like(StringUtils.isNotBlank(cause), "number", cause) @@ -125,7 +126,7 @@ if (status != null) { causeQueryWrapper.eq("status", status); } - causeQueryWrapper.eq("user_id",id); + causeQueryWrapper.eq("user_id", id); causeQueryWrapper.orderByDesc("ctime"); PageParam<Cause> causePageParam = new PageParam<>(); if (size != null) { @@ -174,7 +175,7 @@ PageParam<Report> reportPageParam = reportDao.selectPage(PageParam, new QueryWrapper<Report>().eq("cause_id", causeId).orderByDesc("ctime")); PageParam<CauseReportVo> causeReportVoPageParam = new PageParam<>(); BeanUtils.copyProperties(reportPageParam, causeReportVoPageParam); - if (!reportPageParam.getRecords().isEmpty()){ + if (!reportPageParam.getRecords().isEmpty()) { List<CauseReportVo> causeReportVos = reportPageParam.getRecords().stream() .map( a -> { @@ -184,8 +185,8 @@ causeReportVo.setMobile(user.getUserMobile()); causeReportVo.setIdcard(user.getUserIdcard().replaceAll("(?<=[\\d]{3})\\d(?=[\\d]{4})", "*")); causeReportVo.setReporterName(user.getRealName()); - if (causeReportVo.getIsInGroup()==1) { - causeReportVo.setGroupId(groupDao.selectOne(new QueryWrapper<Group>().eq("cause_id",causeId)).getId()); + if (causeReportVo.getIsInGroup() == 1) { + causeReportVo.setGroupId(groupDao.selectOne(new QueryWrapper<Group>().eq("cause_id", causeId)).getId()); } return causeReportVo; } @@ -203,6 +204,11 @@ @Override public void deleteCause(Integer id) { causeDao.deleteById(id); + Group group = groupDao.selectOne(new LambdaQueryWrapper<Group>().eq(Group::getCauseId, id)); + if (group!=null){ + messageDao.delete(new LambdaQueryWrapper<Message>().eq(Message::getGroupId,group.getId())); + groupUserDao.delete(new LambdaQueryWrapper<GroupUser>().eq(GroupUser::getGroupId,group.getId())); + } groupDao.delete(new QueryWrapper<Group>().eq("cause_id", id)); } @@ -279,21 +285,21 @@ } Group group = groupDao.selectOne(new QueryWrapper<Group>().eq("cause_id", addReportDto.getCauseId())); // 娣诲姞浜哄憳杩涚兢缁� - // groupUserDao.insert(new GroupUser().setGroupId(group.getId()).setUserId(user.getId()).setCtime(new Date()).setBanSpeech(0)); + // groupUserDao.insert(new GroupUser().setGroupId(group.getId()).setUserId(user.getId()).setCtime(new Date()).setBanSpeech(0)); // 娣诲姞鎶ユ淇℃伅 Report report = new Report(); BeanUtils.copyProperties(addReportDto, report); report .setIsInGroup(1) - .setCreator(userDao.selectOne(new QueryWrapper<User>().eq("login_username", SecurityContextHolder.getContext().getAuthentication().getPrincipal())).getId()) + .setCreator(userDao.selectOne(new QueryWrapper<User>().eq("login_username", SecurityContextHolder.getContext().getAuthentication().getPrincipal())).getId()) .setUserId(user.getId()) .setCtime(new Date()) - .setStatus(0) + .setStatus(1) .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; + return groupUserDao.insert(new GroupUser().setGroupId(group.getId()).setUserId(report.getId()).setCtime(new Date()).setBanSpeech(0)) > 0; } @Override @@ -310,13 +316,13 @@ @Override @SneakyThrows - public void loadFileReport(MultipartFile multipartFile,Integer causeId) { + 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 (StringUtils.isNotBlank(data.getReporterName())&&StringUtils.isNotBlank(data.getIdcard())){ + if (StringUtils.isNotBlank(data.getReporterName()) && StringUtils.isNotBlank(data.getIdcard())) { AddReportDto addReportDto = new AddReportDto(); - BeanUtils.copyProperties(data,addReportDto); + BeanUtils.copyProperties(data, addReportDto); addReportDto.setCauseId(causeId); addReportPeople(addReportDto); } -- Gitblit v1.8.0