Quellcode durchsuchen

完成公告部分功能

刘一凡 vor 4 Jahren
Ursprung
Commit
5b3f1f6cce

+ 56 - 6
src/main/java/com/chuanghai/repair/controller/NoticeController.java

@@ -1,18 +1,16 @@
 package com.chuanghai.repair.controller;
 package com.chuanghai.repair.controller;
 
 
+import com.chuanghai.repair.entity.RepairsNotice;
 import com.chuanghai.repair.service.RepairsNoticeService;
 import com.chuanghai.repair.service.RepairsNoticeService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.bind.annotation.RestController;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
+import java.util.Date;
 
 
-/**
- * @Author: bingo
- * @Date: 2022/2/26 星期六 16:09
- * @Description: com.chuanghai.repair.controller
- * @version: 1.0
- */
 @Api(tags = "公告管理")
 @Api(tags = "公告管理")
 @RestController
 @RestController
 @RequestMapping("/notice")
 @RequestMapping("/notice")
@@ -20,4 +18,56 @@ public class NoticeController {
 
 
     @Resource(name = "repairsNoticeService")
     @Resource(name = "repairsNoticeService")
     private RepairsNoticeService repairsNoticeService;
     private RepairsNoticeService repairsNoticeService;
+
+//    @ApiOperation("添加公告")
+//    @PostMapping(value = "/addNotice")
+//    public Boolean addNotice(String noticeContent, Date noticeTime, Integer adminId){
+//
+//    }
+
+    @ApiOperation("发布公告")
+    @PostMapping(value = "/releaseNotice")
+    public RepairsNotice releaseNotice(){
+        RepairsNotice repairsNotice = null;
+        try {
+            repairsNotice = repairsNoticeService.releaseNotice();
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return repairsNotice;
+    }
+
+    @ApiOperation("删除公告")
+    @PostMapping(value = "/updateNotice")
+    public Boolean updateNotice(String noticeId){
+        Boolean flag = Boolean.FALSE;
+        try {
+            if(repairsNoticeService.updateNotice(noticeId) == null){
+                flag = Boolean.TRUE;
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return flag;
+    }
+
+//    @ApiOperation("修改公告")
+//    @PostMapping(value = "/alterNotice")
+//    public Boolean alterNotice(String noticeContent, Date noticeTime, Integer noticeId){
+//
+//    }
+
+    @ApiOperation("查询全部公告")
+    @PostMapping(value = "/queryAllNotice")
+    public RepairsNotice queryAllNotice(String noticeStatus){
+        RepairsNotice repairsNotice = null;
+        try {
+            if(noticeStatus!="" && noticeStatus!=null){
+                repairsNotice =  repairsNoticeService.queryAllNotice(noticeStatus);
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return repairsNotice;
+    }
 }
 }

+ 45 - 0
src/main/java/com/chuanghai/repair/mapper/RepairsNoticeMapper.java

@@ -3,6 +3,51 @@ package com.chuanghai.repair.mapper;
 import com.chuanghai.repair.entity.RepairsNotice;
 import com.chuanghai.repair.entity.RepairsNotice;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Mapper;
 
 
+import java.util.Date;
+
 @Mapper
 @Mapper
 public interface RepairsNoticeMapper  {
 public interface RepairsNoticeMapper  {
+    /**
+     * 添加公告
+     * @param noticeContent
+     * @param noticeTime
+     * @param adminId
+     * @return
+     * @throws Exception
+     */
+    Boolean addNotice(String noticeContent, Date noticeTime, Integer adminId) throws Exception;
+
+    /**
+     * 发布公告
+     *
+     * @return
+     * @throws Exception
+     */
+    RepairsNotice releaseNotice() throws Exception;
+
+    /**
+     * 逻辑删除公告
+     * @param noticeId
+     * @return
+     * @throws Exception
+     */
+    Integer updateNotice(String noticeId) throws Exception;
+
+    /**
+     * 修改公告
+     * @param noticeContent
+     * @param noticeTime
+     * @param noticeId
+     * @return
+     * @throws Exception
+     */
+    RepairsNotice alterNotice(String noticeContent, Date noticeTime, Integer noticeId) throws Exception;
+
+    /**
+     * 查询全部公告
+     * @param noticeStatus
+     * @return
+     * @throws Exception
+     */
+    RepairsNotice queryAllNotice(String noticeStatus) throws Exception;
 }
 }

+ 51 - 0
src/main/java/com/chuanghai/repair/service/RepairsNoticeService.java

@@ -1,5 +1,9 @@
 package com.chuanghai.repair.service;
 package com.chuanghai.repair.service;
 
 
+import com.chuanghai.repair.entity.RepairsNotice;
+
+import java.util.Date;
+
 /**
 /**
  * @Author: bingo
  * @Author: bingo
  * @Date: 2022/2/23 星期三 17:28
  * @Date: 2022/2/23 星期三 17:28
@@ -7,4 +11,51 @@ package com.chuanghai.repair.service;
  * @version: 1.0
  * @version: 1.0
  */
  */
 public interface RepairsNoticeService {
 public interface RepairsNoticeService {
+    /**
+     * 添加公告
+     *
+     * @param noticeContent
+     * @param noticeTime
+     * @param adminId
+     * @return
+     * @throws Exception
+     */
+    Boolean addNotice(String noticeContent, Date noticeTime, Integer adminId) throws Exception;
+
+    /**
+     * 发布公告
+     *
+     * @return
+     * @throws Exception
+     */
+    RepairsNotice releaseNotice() throws Exception;
+
+    /**
+     * 逻辑删除公告
+     *
+     * @param noticeId
+     * @return
+     * @throws Exception
+     */
+    Integer updateNotice(String noticeId) throws Exception;
+
+    /**
+     * 修改公告
+     *
+     * @param noticeContent
+     * @param noticeTime
+     * @param noticeId
+     * @return
+     * @throws Exception
+     */
+    RepairsNotice alterNotice(String noticeContent, Date noticeTime, Integer noticeId) throws Exception;
+
+    /**
+     * 查询全部公告
+     *
+     * @param noticeStatus
+     * @return
+     * @throws Exception
+     */
+    RepairsNotice queryAllNotice(String noticeStatus) throws Exception;
 }
 }

+ 64 - 2
src/main/java/com/chuanghai/repair/service/ServiceImpl/RepairsNoticeServiceImpl.java

@@ -1,11 +1,12 @@
 package com.chuanghai.repair.service.ServiceImpl;
 package com.chuanghai.repair.service.ServiceImpl;
 
 
+import com.chuanghai.repair.entity.RepairsNotice;
 import com.chuanghai.repair.mapper.RepairsNoticeMapper;
 import com.chuanghai.repair.mapper.RepairsNoticeMapper;
 import com.chuanghai.repair.service.RepairsNoticeService;
 import com.chuanghai.repair.service.RepairsNoticeService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
-import javax.annotation.Resource;
+import java.util.Date;
 
 
 
 
 /**
 /**
@@ -17,6 +18,67 @@ import javax.annotation.Resource;
 @Service("repairsNoticeService")
 @Service("repairsNoticeService")
 public class RepairsNoticeServiceImpl implements RepairsNoticeService {
 public class RepairsNoticeServiceImpl implements RepairsNoticeService {
 
 
-    @Resource
+    @Autowired
     private RepairsNoticeMapper repairsNoticeMapper;
     private RepairsNoticeMapper repairsNoticeMapper;
+
+    /**
+     * 添加公告
+     *
+     * @param noticeContent
+     * @param noticeTime
+     * @param adminId
+     * @return
+     * @throws Exception
+     */
+    @Override
+    public Boolean addNotice(String noticeContent, Date noticeTime, Integer adminId) throws Exception {
+        return repairsNoticeMapper.addNotice(noticeContent, noticeTime, adminId);
+    }
+
+    /**
+     * 发布公告
+     *
+     * @return
+     * @throws Exception
+     */
+    @Override
+    public RepairsNotice releaseNotice() throws Exception {
+        System.out.println(repairsNoticeMapper.releaseNotice());
+        return repairsNoticeMapper.releaseNotice();
+    }
+
+    /**
+     * 逻辑删除公告
+     * @param noticeId
+     * @return
+     * @throws Exception
+     */
+    @Override
+    public Integer updateNotice(String noticeId) throws Exception {
+        return repairsNoticeMapper.updateNotice(noticeId);
+    }
+
+    /**
+     * 修改公告
+     * @param noticeContent
+     * @param noticeTime
+     * @param noticeId
+     * @return
+     * @throws Exception
+     */
+    @Override
+    public RepairsNotice alterNotice(String noticeContent, Date noticeTime, Integer noticeId) throws Exception{
+        return repairsNoticeMapper.alterNotice(noticeContent,noticeTime,noticeId);
+    }
+
+    /**
+     * 查询全部公告
+     * @param noticeStatus
+     * @return
+     * @throws Exception
+     */
+    @Override
+    public RepairsNotice queryAllNotice(String noticeStatus) throws Exception{
+        return repairsNoticeMapper.queryAllNotice(noticeStatus);
+    }
 }
 }

+ 45 - 1
src/main/resources/mapper/RepairsNoticeMapper.xml

@@ -9,6 +9,50 @@
         <result column="notice_content" property="noticeContent" jdbcType="VARCHAR"/>
         <result column="notice_content" property="noticeContent" jdbcType="VARCHAR"/>
         <result column="notice_time" property="noticeTime" jdbcType="TIMESTAMP"/>
         <result column="notice_time" property="noticeTime" jdbcType="TIMESTAMP"/>
         <result column="notice_status" property="noticeStatus" jdbcType="VARCHAR"/>
         <result column="notice_status" property="noticeStatus" jdbcType="VARCHAR"/>
-        <result column="admin_id" property="adminId" jdbcType="INTEGER"/>
+        <!--        公告与管理员之间是  N:1 关系-->
+        <association  property="repairsAdmin"  javaType="com.chuanghai.repair.entity.RepairsAdmin">
+            <id column="admin_id" property="adminId"></id>
+            <result column="admin_name" property="adminName" jdbcType="VARCHAR"/>
+        </association >
     </resultMap>
     </resultMap>
+
+
+    <!--    添加公告-->
+    <select id="addNotice" parameterType="com.chuanghai.repair.entity.RepairsNotice"
+            resultType="Boolean">
+        insert into repairs_notice(notice_content,notice_time,notice_status,admin_id)
+        values(#{noticeContent},#{noticeTime},#{noticeStatus},#{adminId});
+    </select>
+
+    <!--    发布公告-->
+    <select id="releaseNotice" resultMap="BaseResultMap">
+        select notice_content,notice_time,no.admin_id,admin_name from repairs_notice no ,repairs_admin ad
+        where no.admin_id = ad.admin_id and notice_id = (select max(notice_id) from repairs_notice);
+    </select>
+
+    <!--    逻辑删除公告-->
+    <select id="updateNotice" parameterType="java.lang.String" resultType="Integer">
+        update repairs_notice no set no.notice_status = 0
+        <trim prefix="where" prefixOverrides="and" suffix="" suffixOverrides="">
+            <if test="noticeId!='' and noticeId!=null">
+                and no.notice_id = #{noticeId}
+            </if>
+        </trim>
+    </select>
+
+    <!--    修改公告-->
+    <select id="alterNotice" parameterType="com.chuanghai.repair.entity.RepairsNotice"
+            resultType="com.chuanghai.repair.entity.RepairsNotice">
+        update repairs_notice no set no.notice_content = #{noticeContent},no.notice_time = #{noticeTime}
+        <trim prefix="where" prefixOverrides="and" suffix="" suffixOverrides="">
+            <if test="noticeId!='' and noticeId!=null">
+                and notice_id = #{noticeId}
+            </if>
+        </trim>
+    </select>
+
+    <!--    查询全部公告-->
+    <select id="queryAllNotice" resultType="com.chuanghai.repair.entity.RepairsNotice">
+        select * from repairs_notice no where notice_status = 1;
+    </select>
 </mapper>
 </mapper>