From 7ea5eece501c98a91555a5358931367e78e9d23b Mon Sep 17 00:00:00 2001
From: baizonghao <1719256278@qq.com>
Date: 星期四, 25 五月 2023 15:40:09 +0800
Subject: [PATCH] 11
---
src/main/java/com/example/jz/controller/CommonQuestionController.java | 77 ++++++++++++++++++++++++++++++++++----
1 files changed, 69 insertions(+), 8 deletions(-)
diff --git a/src/main/java/com/example/jz/controller/CommonQuestionController.java b/src/main/java/com/example/jz/controller/CommonQuestionController.java
index a8256a0..f0bc12a 100644
--- a/src/main/java/com/example/jz/controller/CommonQuestionController.java
+++ b/src/main/java/com/example/jz/controller/CommonQuestionController.java
@@ -3,18 +3,26 @@
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.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)琛ㄦ帶鍒跺眰
@@ -24,13 +32,15 @@
*/
@RestController
@RequestMapping("commonQuestion")
-@Api(tags = "甯歌闂琛�(CommonQuestion)琛ㄦ帴鍙�")
+@Api(tags = "甯歌闂鎺ュ彛")
public class CommonQuestionController extends ApiController {
/**
* 鏈嶅姟瀵硅薄
*/
@Resource
private CommonQuestionService commonQuestionService;
+ @Resource
+ UserDao userDao;
/**
* 鍒嗛〉鏌ヨ鎵�鏈夋暟鎹�
@@ -41,8 +51,24 @@
*/
@GetMapping
@ApiOperation("鍒嗛〉鏌ヨ鎵�鏈夋暟鎹�")
- public R<IPage<CommonQuestion>> selectAll(PageParam<CommonQuestion> page, CommonQuestion commonQuestion) {
- return R.ok(commonQuestionService.page(page, new QueryWrapper<>(commonQuestion)));
+ 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);
}
/**
@@ -66,6 +92,9 @@
@PostMapping
@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));
}
@@ -78,18 +107,50 @@
@PutMapping
@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
@ApiOperation(value = "鍒犻櫎鏁版嵁", notes = "鍒犻櫎鏁版嵁")
- public R<Boolean> delete(@RequestParam("idList") List<Long> idList) {
- return R.ok(commonQuestionService.removeByIds(idList));
+ 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