package com.stylefeng.guns.modular.code.controller; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.stylefeng.guns.modular.system.dto.FindCommentQuery; import com.stylefeng.guns.modular.system.dto.FindQuery; import com.stylefeng.guns.modular.system.dto.FindReportQuery; import com.stylefeng.guns.modular.system.model.*; import com.stylefeng.guns.modular.system.service.*; import com.stylefeng.guns.modular.system.util.RedisUtil; import com.stylefeng.guns.modular.system.util.ResultUtil; import com.stylefeng.guns.modular.system.util.UUIDUtil; import com.stylefeng.guns.modular.system.vo.*; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.aspectj.weaver.ast.Var; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import java.util.Date; import java.util.List; import java.util.stream.Collectors; /** * @author 无关风月 * @Date 2024/2/6 18:25 */ @RestController @RequestMapping("") public class FindController { @Autowired private IAppUserService appUserService; @Autowired private RedisUtil redisUtil; @Autowired private IProtocolService protocolService; @Autowired private IPageService pageService; @Autowired private IFindService findService; @Autowired private IFindCommentService findCommentService; @Autowired private IFindReportService reportService; @Autowired private IMessageService messageService; @ResponseBody @PostMapping("/base/find/selectReport") @ApiOperation(value = "举报列表查询", tags = {"发现管理"}) public ResultUtil> selectReport(FindReportQuery req) { List res= reportService.selectReport(req); // PageHelper.startPage(req.getPageNum(),req.getPageSize()); PageInfo info=new PageInfo<>(res); return ResultUtil.success(info); } @ResponseBody @PostMapping("/base/find/reportDetail") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "举报id"), }) @ApiOperation(value = "举报详情", tags = {"发现管理"}) public ResultUtil handle(Integer id) { FindReportDetailVO findReportDetailVO = new FindReportDetailVO(); FindReport findReport = reportService.selectById(id); Integer findId = findReport.getFindId(); Find find = findService.selectById(findId); // 说明是举报评论 if (findReport.getCommentId()!=null){ String content = findCommentService.selectById(findReport.getCommentId()).getContent(); findReportDetailVO.setContent(content); }else{ findReportDetailVO.setContent(find.getContent()); } Integer userId = find.getUserId(); AppUser appUser = appUserService.selectById(userId); findReportDetailVO.setImage(find.getImg()); findReportDetailVO.setVideo(find.getVideo()); findReportDetailVO.setUserName(appUser.getName()); findReportDetailVO.setPhone(appUser.getPhone()); findReportDetailVO.setInsertTime(find.getInsertTime()); findReportDetailVO.setLikeCount(find.getLikeCount()); findReportDetailVO.setTitle(find.getTitle()); findReportDetailVO.setState(findReport.getState()); findReportDetailVO.setReportContent(findReport.getContent()); return ResultUtil.success(findReportDetailVO); } @ResponseBody @PostMapping("/base/find/handle") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "举报id"), @ApiImplicitParam(name = "state", value = "状态2=忽略 3-下架") }) @ApiOperation(value = "处理举报", tags = {"发现管理"}) public ResultUtil handle(Integer id,Integer state) { FindReport findReport = reportService.selectById(id); findReport.setState(state); if (state==3){ // 下架动态 if (findReport.getCommentId()!=null){ // 下架评论 FindComment findComment = findCommentService.selectById(findReport.getCommentId()); findComment.setIsShow(0); findCommentService.updateById(findComment); Message message = new Message(); message.setUserId(findComment.getUserId()); message.setType(1); message.setContent("你的评论\""+findComment.getContent()+"\""+"已被下架"); message.setInsertTime(new Date()); messageService.insert(message); }else{ // 下架动态 Find find = findService.selectById(findReport.getFindId()); find.setState(2); findService.updateById(find); Message message = new Message(); message.setUserId(find.getUserId()); message.setType(1); message.setContent("你的动态\""+find.getTitle()+"\""+"已被下架"); message.setInsertTime(new Date()); messageService.insert(message); } } reportService.updateById(findReport); return ResultUtil.success(); } @ResponseBody @PostMapping("/base/find/selectFind") @ApiOperation(value = "发现列表查询", tags = {"发现管理"}) public ResultUtil> findList(FindQuery req) { List res = findService.selectFind(req); for (FindVO re : res) { int findId = findCommentService.selectList(new EntityWrapper() .eq("findId", re.getId())).size(); re.setComment(findId); } // PageHelper.startPage(req.getPageNum(),req.getPageSize()); PageInfo info=new PageInfo<>(res); return ResultUtil.success(info); } @ResponseBody @PostMapping("/base/find/selectFindComment") @ApiOperation(value = "动态详情-查看评论", tags = {"发现管理"}) public ResultUtil> selectFindComment(FindCommentQuery req) { List res = findCommentService.selectFindComment(req); // PageHelper.startPage(req.getPageNum(),req.getPageSize()); PageInfo info=new PageInfo<>(res); return ResultUtil.success(info); } @ResponseBody @PostMapping("/base/find/shield") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "评论id"), @ApiImplicitParam(name = "isShow", value = "是否展示 0否1是") }) @ApiOperation(value = "屏蔽/展示评论", tags = {"发现管理"}) public ResultUtil shield(Integer id,Integer isShow) { FindComment findComment = findCommentService.selectById(id); findComment.setIsShow(isShow); findCommentService.updateById(findComment); return ResultUtil.success(); } @ResponseBody @PostMapping("/base/find/findDetail") @ApiOperation(value = "动态详情", tags = {"发现管理"}) @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"), @ApiImplicitParam(name = "id", value = "动态id") }) public ResultUtil findDetail(Integer id) { Find find1 = findService.selectById(id); FindVO findVO = new FindVO(); findVO.setId(find1.getId()); findVO.setUserId(find1.getUserId()); findVO.setInsertTime(find1.getInsertTime()); findVO.setLikeCount(find1.getLikeCount()); findVO.setTitle(find1.getTitle()); findVO.setContent(find1.getContent()); findVO.setImg(find1.getImg()); findVO.setVideo(find1.getVideo()); findVO.setIsTop(find1.getIsTop()); findVO.setIsDelete(find1.getIsDelete()); findVO.setPhone(appUserService.selectById(find1.getUserId()).getPhone()); // 计算每个动态的评论数量 int size = findCommentService.selectList(new EntityWrapper() .eq("findId", find1.getId()) .eq("isShow", 1)).size(); findVO.setComment(size); AppUser appUser = appUserService.selectById(find1.getUserId()); findVO.setHeadImg(appUser.getHeadImg()); findVO.setUserName(appUser.getName()); findVO.setClockIn(appUser.getClockIn()); // // 查询一级评论 // List one = findCommentService.getCommentOne(id); // for (CommentVO comment : one) { // // 查询这条评论下面的子评论 // List two = findCommentService.getCommentTwo(comment.getId()); // comment.setCommentList(two); // } // findVO.setCommentList(one); return ResultUtil.success(findVO); } @ResponseBody @PostMapping("/base/find/updateState") @ApiOperation(value = "上架/下架/删除/置顶/修改点赞数", tags = {"发现管理"}) @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "动态id", required = true), @ApiImplicitParam(name = "type", value = "类型 1 = 上架 2 = 下架 3=删除 4=是否置顶(0否1是) 5=修改点赞数", required = true), @ApiImplicitParam(name = "temp", value = "当type为4时该字段是否置顶填0否或者1是 type=5该字段填点赞数 type=123该字段不填") }) public ResultUtil Like(Integer id,Integer type,Integer temp) { Find find = findService.selectById(id); if (type == 2){ // 还需要发送一条消息给用户 Message message = new Message(); message.setUserId(find.getUserId()); message.setType(1); message.setContent("您的动态\""+find.getTitle()+"\"已被下架"); message.setInsertTime(new Date()); message.setIsRead(0); messageService.insert(message); } if (type==1||type==2){ find.setState(type); } if (type == 3){ find.setIsDelete(1); } if (type==4){ find.setIsTop(temp); } if (type==5){ find.setLikeCount(temp); } findService.updateById(find); return ResultUtil.success(); } }