From c435158ed1ff587939314e84347ee6e38e8f25ec Mon Sep 17 00:00:00 2001
From: fangyuan <527392886@qq.com>
Date: 星期一, 21 十一月 2022 13:49:59 +0800
Subject: [PATCH] 接口调整及文件上传接口

---
 ycl-platform/src/main/java/com/ycl/controller/NewsInformationController.java |   77 +++++++++++++++++++++++++++++++++++---
 1 files changed, 70 insertions(+), 7 deletions(-)

diff --git a/ycl-platform/src/main/java/com/ycl/controller/NewsInformationController.java b/ycl-platform/src/main/java/com/ycl/controller/NewsInformationController.java
index 7813bbc..bc16c12 100644
--- a/ycl-platform/src/main/java/com/ycl/controller/NewsInformationController.java
+++ b/ycl-platform/src/main/java/com/ycl/controller/NewsInformationController.java
@@ -6,12 +6,22 @@
 import com.baomidou.mybatisplus.extension.api.ApiController;
 import com.baomidou.mybatisplus.extension.api.R;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ycl.entity.NewsColumnInformation;
 import com.ycl.entity.NewsInformation;
-import com.ycl.service.NewsInformationService;
+import com.ycl.entity.NewsInformationPolice;
+import com.ycl.entity.NewsPolice;
+import com.ycl.service.*;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.apache.commons.io.IOUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
+import sun.nio.ch.IOUtil;
 
 import javax.annotation.Resource;
 import java.io.Serializable;
+import java.sql.SQLException;
 import java.util.List;
 
 /**
@@ -22,6 +32,7 @@
  */
 @RestController
 @RequestMapping("newsInformation")
+@Api(tags = "璧勮绠$悊")
 public class NewsInformationController extends ApiController {
     /**
      * 鏈嶅姟瀵硅薄
@@ -29,16 +40,24 @@
     @Resource
     private NewsInformationService newsInformationService;
 
+    @Autowired
+    private NewsPoliceService policeService;
+
+    @Autowired
+    private NewsInformationPoliceService newsInformationPoliceService;
+
+    @Autowired
+    private NewsColumnInformationService newsColumnInformationService;
     /**
      * 鍒嗛〉鏌ヨ鎵�鏈夋暟鎹�
      *
-     * @param page 鍒嗛〉瀵硅薄
-     * @param newsInformation 鏌ヨ瀹炰綋
      * @return 鎵�鏈夋暟鎹�
      */
     @GetMapping
-    public R selectAll(Page<NewsInformation> page, NewsInformation newsInformation) {
-        return success(this.newsInformationService.page(page, new QueryWrapper<>(newsInformation)));
+    @ApiOperation(value = "鏌ヨ鎵�鏈夋暟鎹�")
+    public R selectAll() {
+        return success(this.newsInformationService.selectAllInformation());
+
     }
 
     /**
@@ -48,6 +67,7 @@
      * @return 鍗曟潯鏁版嵁
      */
     @GetMapping("{id}")
+    @ApiOperation(value = "鎸塱d鏌ヨ鏁版嵁")
     public R selectOne(@PathVariable Serializable id) {
         return success(this.newsInformationService.getById(id));
     }
@@ -58,9 +78,30 @@
      * @param newsInformation 瀹炰綋瀵硅薄
      * @return 鏂板缁撴灉
      */
+    @Transactional(rollbackFor = SQLException.class)
     @PostMapping
+    @ApiOperation(value = "鏂板鏁版嵁")
     public R insert(@RequestBody NewsInformation newsInformation) {
-        return success(this.newsInformationService.save(newsInformation));
+        Integer saveResult = this.newsInformationService.insertOneInformation(newsInformation);
+        Integer informationId=newsInformation.getId();
+        if (newsInformation.getIsSign()==0){
+            List<String> departmentIds = newsInformation.getDepartmentId();
+            for (String departmentId:departmentIds){
+                QueryWrapper<NewsPolice> wrapper = new QueryWrapper();
+                wrapper.eq("news_department_id",departmentId);
+                List<NewsPolice> list = policeService.list(wrapper);
+                if (!list.isEmpty()){
+                    for (NewsPolice newsPolice:list){
+                        newsInformationPoliceService.save(NewsInformationPolice.builder().newsPoliceId(newsPolice.getId()).newsInformationId(informationId).isSign(0).build());
+                    }
+                }
+            }
+        }
+
+        for (String columnId:newsInformation.getColumnId()){
+            newsColumnInformationService.save(NewsColumnInformation.builder().columnId(Integer.parseInt(columnId)).informationId(informationId).build());
+        }
+        return success(saveResult);
     }
 
     /**
@@ -70,8 +111,29 @@
      * @return 淇敼缁撴灉
      */
     @PutMapping
+    @ApiOperation(value = "淇敼鏁版嵁")
+    @Transactional
     public R update(@RequestBody NewsInformation newsInformation) {
-        return success(this.newsInformationService.updateById(newsInformation));
+        Integer informationId = newsInformation.getId();
+        if (newsInformation.getIsSign()==0){
+            newsInformationPoliceService.remove(new QueryWrapper<NewsInformationPolice>().eq("news_information_id",informationId));
+            List<String> departmentIds = newsInformation.getDepartmentId();
+            for (String departmentId:departmentIds){
+                QueryWrapper<NewsPolice> wrapper = new QueryWrapper();
+                wrapper.eq("news_department_id",departmentId);
+                List<NewsPolice> list = policeService.list(wrapper);
+                if (!list.isEmpty()){
+                    for (NewsPolice newsPolice:list){
+                        newsInformationPoliceService.save(NewsInformationPolice.builder().newsPoliceId(newsPolice.getId()).newsInformationId(informationId).isSign(0).build());
+                    }
+                }
+            }
+        }
+        newsColumnInformationService.remove(new QueryWrapper<NewsColumnInformation>().eq("information_id",informationId));
+        for (String columnId:newsInformation.getColumnId()){
+            newsColumnInformationService.save(NewsColumnInformation.builder().columnId(Integer.parseInt(columnId)).informationId(informationId).build());
+        }
+        return success(this.newsInformationService.updateInformationById(newsInformation));
     }
 
     /**
@@ -81,6 +143,7 @@
      * @return 鍒犻櫎缁撴灉
      */
     @DeleteMapping
+    @ApiOperation(value = "鍒犻櫎鏁版嵁")
     public R delete(@RequestParam("idList") List<Long> idList) {
         return success(this.newsInformationService.removeByIds(idList));
     }

--
Gitblit v1.8.0