From 25945cec9a4d25ad09d7ccb73b1c42c11aa3e8a4 Mon Sep 17 00:00:00 2001 From: baizonghao <1719256278@qq.com> Date: 星期三, 22 三月 2023 16:57:21 +0800 Subject: [PATCH] 2222 --- src/main/java/com/example/jz/controller/CommonQuestionController.java | 102 ++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 85 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/example/jz/controller/CommonQuestionController.java b/src/main/java/com/example/jz/controller/CommonQuestionController.java index c99d745..f0bc12a 100644 --- a/src/main/java/com/example/jz/controller/CommonQuestionController.java +++ b/src/main/java/com/example/jz/controller/CommonQuestionController.java @@ -1,18 +1,28 @@ package com.example.jz.controller; - import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.extension.api.ApiController; -import com.baomidou.mybatisplus.extension.api.R; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; + +import com.example.jz.dao.UserDao; +import com.example.jz.modle.PageParam; +import com.example.jz.modle.R; import com.example.jz.modle.entity.CommonQuestion; +import com.example.jz.modle.entity.User; +import com.example.jz.modle.vo.QuestionVo; import com.example.jz.service.CommonQuestionService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.BeanUtils; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.io.Serializable; -import java.util.List; +import java.util.ArrayList; +import java.util.Date; /** * 甯歌闂琛�(CommonQuestion)琛ㄦ帶鍒跺眰 @@ -22,23 +32,43 @@ */ @RestController @RequestMapping("commonQuestion") +@Api(tags = "甯歌闂鎺ュ彛") public class CommonQuestionController extends ApiController { /** * 鏈嶅姟瀵硅薄 */ @Resource private CommonQuestionService commonQuestionService; + @Resource + UserDao userDao; /** * 鍒嗛〉鏌ヨ鎵�鏈夋暟鎹� * - * @param page 鍒嗛〉瀵硅薄 + * @param page 鍒嗛〉瀵硅薄 * @param commonQuestion 鏌ヨ瀹炰綋 * @return 鎵�鏈夋暟鎹� */ @GetMapping - public R selectAll(Page<CommonQuestion> page, CommonQuestion commonQuestion) { - return success(this.commonQuestionService.page(page, new QueryWrapper<>(commonQuestion))); + @ApiOperation("鍒嗛〉鏌ヨ鎵�鏈夋暟鎹�") + public R<IPage<QuestionVo>> selectAll(PageParam<CommonQuestion> page, CommonQuestion commonQuestion) { + ArrayList<QuestionVo> QuestionVos = new ArrayList<>(); + PageParam<CommonQuestion> CommonQuestionPageParam ; + if (commonQuestion.getStatus()!=null ){ + CommonQuestionPageParam = commonQuestionService.page(page, new QueryWrapper<CommonQuestion>().like(StringUtils.isNotBlank(commonQuestion.getQuestionTitle()),"question_title",commonQuestion.getQuestionTitle()).eq("status",commonQuestion.getStatus()).orderByDesc("ctime")); + }else { + CommonQuestionPageParam = commonQuestionService.page(page, new QueryWrapper<CommonQuestion>().like(StringUtils.isNotBlank(commonQuestion.getQuestionTitle()),"question_title",commonQuestion.getQuestionTitle()).orderByDesc("ctime")); + } + CommonQuestionPageParam.getRecords().forEach(item->{ + QuestionVo QuestionVo = new QuestionVo(); + BeanUtils.copyProperties(item,QuestionVo); + QuestionVo.setUserName(userDao.selectOne(new QueryWrapper<User>().eq("id",item.getCreator())).getRealName()); + QuestionVos.add(QuestionVo); + }); + PageParam<QuestionVo> QuestionVoPageParam = new PageParam<>(); + BeanUtils.copyProperties(CommonQuestionPageParam,QuestionVoPageParam); + QuestionVoPageParam.setRecords(QuestionVos); + return R.ok(QuestionVoPageParam); } /** @@ -48,8 +78,9 @@ * @return 鍗曟潯鏁版嵁 */ @GetMapping("{id}") - public R selectOne(@PathVariable Serializable id) { - return success(this.commonQuestionService.getById(id)); + @ApiOperation(value = "閫氳繃涓婚敭鏌ヨ鍗曟潯鏁版嵁", notes = "閫氳繃涓婚敭鏌ヨ鍗曟潯鏁版嵁") + public R<CommonQuestion> selectOne(@PathVariable Serializable id) { + return R.ok(commonQuestionService.getById(id)); } /** @@ -59,8 +90,12 @@ * @return 鏂板缁撴灉 */ @PostMapping - public R insert(@RequestBody CommonQuestion commonQuestion) { - return success(this.commonQuestionService.save(commonQuestion)); + @ApiOperation(value = "鏂板鏁版嵁", notes = "鏂板鏁版嵁") + public R<Boolean> insert(@RequestBody CommonQuestion commonQuestion) { + commonQuestion.setStatus(0); + commonQuestion.setCtime(new Date()); + commonQuestion.setCreator(userDao.selectOne(new QueryWrapper<User>().eq("login_username", SecurityContextHolder.getContext().getAuthentication().getPrincipal())).getId()); + return R.ok(commonQuestionService.save(commonQuestion)); } /** @@ -70,19 +105,52 @@ * @return 淇敼缁撴灉 */ @PutMapping - public R update(@RequestBody CommonQuestion commonQuestion) { - return success(this.commonQuestionService.updateById(commonQuestion)); + @ApiOperation(value = "淇敼鏁版嵁", notes = "淇敼鏁版嵁") + public R<Boolean> update(@RequestBody CommonQuestion commonQuestion) { + if (commonQuestion.getId() == 1) { + commonQuestion.setReleaseTime(new Date()); + } + return R.ok(commonQuestionService.updateById(commonQuestion)); } /** * 鍒犻櫎鏁版嵁 * - * @param idList 涓婚敭缁撳悎 + * @param id 涓婚敭 * @return 鍒犻櫎缁撴灉 */ @DeleteMapping - public R delete(@RequestParam("idList") List<Long> idList) { - return success(this.commonQuestionService.removeByIds(idList)); + @ApiOperation(value = "鍒犻櫎鏁版嵁", notes = "鍒犻櫎鏁版嵁") + public R<Boolean> delete(@RequestParam("id") Serializable id) { + return R.ok(commonQuestionService.removeById(id)); + } + + /** + * 鍙戝竷 + * + * @param id 涓婚敭 + * @return 鍙戝竷缁撴灉 + */ + @ApiOperation(value = "鍙戝竷", notes = "鍙戝竷") + @GetMapping("release/{id}") + public R<Boolean> release(@PathVariable Serializable id) { + CommonQuestion commonQuestion = commonQuestionService.getById(id); + commonQuestion.setReleaseTime(new Date()); + commonQuestion.setStatus(1); + return R.ok(commonQuestionService.updateById(commonQuestion)); + } + + /** + * 涓嬫灦 + * + * @param id 涓婚敭 + * @return 鍙戝竷缁撴灉 + */ + @ApiOperation(value = "涓嬫灦", notes = "涓嬫灦") + @GetMapping("offline/{id}") + public R<Boolean> offline(@PathVariable Serializable id) { + CommonQuestion commonQuestion = commonQuestionService.getById(id); + commonQuestion.setStatus(2); + return R.ok(commonQuestionService.updateById(commonQuestion)); } } - -- Gitblit v1.8.0