ソースを参照

实现通知公告

Signed-off-by: hamjin <335908093@qq.com>
hamjin 2 年 前
コミット
ea5f5a5651

+ 83 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/PoNoticeController.java

@@ -0,0 +1,83 @@
+package com.ruoyi.web.controller.system;
+
+import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.page.TableDataInfo;
+import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.system.domain.PoNotice;
+import com.ruoyi.system.service.IPoNoticeService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * 公告 信息操作处理
+ *
+ * @author ruoyi
+ */
+@RestController
+@RequestMapping("/system/poNotice")
+public class PoNoticeController extends BaseController {
+    @Autowired
+    private IPoNoticeService poNoticeService;
+
+    /**
+     * 获取通知公告列表
+     */
+    @PreAuthorize("@ss.hasPermi('system:notice:list')")
+    @GetMapping("/list")
+    public TableDataInfo list(PoNotice poNotice) {
+        startPage();
+        List<PoNotice> list = poNoticeService.selectPoNoticeList(poNotice);
+        return getDataTable(list);
+    }
+
+    /**
+     * 根据通知公告编号获取详细信息
+     */
+    @PreAuthorize("@ss.hasPermi('system:notice:query')")
+    @GetMapping(value = "/{poNoticeId}")
+    public AjaxResult getInfo(@PathVariable Long poNoticeId) {
+        return success(poNoticeService.selectPoNoticeById(poNoticeId));
+    }
+
+    /**
+     * 新增通知公告
+     */
+    @PreAuthorize("@ss.hasPermi('system:notice:add')")
+    @Log(title = "通知公告", businessType = BusinessType.INSERT)
+    @PostMapping
+    public AjaxResult add(@Validated @RequestBody PoNotice poNotice) {
+        System.out.println(poNotice);
+        return toAjax(poNoticeService.insertPoNotice(poNotice));
+    }
+
+    /**
+     * 修改通知公告
+     */
+    @PreAuthorize("@ss.hasPermi('system:notice:edit')")
+    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
+    @PutMapping
+    public AjaxResult edit(@Validated @RequestBody PoNotice poNotice) {
+        List<PoNotice> poNotice1 = poNoticeService.selectPoNoticeList(poNotice);
+        if (poNotice1 == null || poNotice1.isEmpty())
+            return toAjax(false);
+        poNotice.setUpdateBy(getUsername());
+        poNotice.setPublisherId(getUserId());
+        return toAjax(poNoticeService.updatePoNotice(poNotice));
+    }
+
+    /**
+     * 删除通知公告
+     */
+    @PreAuthorize("@ss.hasPermi('system:notice:remove')")
+    @Log(title = "通知公告", businessType = BusinessType.DELETE)
+    @DeleteMapping("/{poNoticeIds}")
+    public AjaxResult remove(@PathVariable Long[] poNoticeIds) {
+        return toAjax(poNoticeService.deletePoNoticeByIds(poNoticeIds));
+    }
+}

+ 37 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/sql/List2VarcharHandler.java

@@ -0,0 +1,37 @@
+package com.ruoyi.common.utils.sql;
+
+import com.ruoyi.common.utils.StringUtils;
+import org.apache.ibatis.type.JdbcType;
+import org.apache.ibatis.type.TypeHandler;
+
+import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+
+public class List2VarcharHandler implements TypeHandler<List<String>> {
+    @Override
+    public void setParameter(PreparedStatement preparedStatement, int i, List<String> strings, JdbcType jdbcType) throws SQLException {
+        StringBuilder sb = new StringBuilder();
+        for (String userId : strings) {
+            sb.append(userId).append(",");
+        }
+        preparedStatement.setString(i, sb.toString());
+    }
+
+    @Override
+    public List<String> getResult(ResultSet rs, String s) throws SQLException {
+        return StringUtils.str2List(rs.getString(s), ",", true, true);
+    }
+
+    @Override
+    public List<String> getResult(ResultSet rs, int i) throws SQLException {
+        return StringUtils.str2List(rs.getString(i), ",", true, true);
+    }
+
+    @Override
+    public List<String> getResult(CallableStatement cs, int i) throws SQLException {
+        return StringUtils.str2List(cs.getString(i), ",", true, true);
+    }
+}

+ 142 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/PoNotice.java

@@ -0,0 +1,142 @@
+package com.ruoyi.system.domain;
+
+import com.ruoyi.common.annotation.Excel;
+import com.ruoyi.common.core.domain.BaseEntity;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+
+import java.util.List;
+
+/**
+ * 通知公告表 po_notice
+ *
+ * @author blue
+ */
+
+public class PoNotice extends BaseEntity {
+    private static final long serialVersionUID = 1L;
+    /**
+     * 通知公告ID
+     */
+    @Excel(name = "通知公告ID", cellType = Excel.ColumnType.NUMERIC)
+    private Long noticeId;
+
+    /**
+     * 通知公告标题
+     */
+    @Excel(name = "通知公告标题")
+    private String noticeTitle;
+
+    /**
+     * 通知公告内容
+     */
+    @Excel(name = "通知公告内容")
+    private String noticeContent;
+
+    /**
+     * 通知公告类型 1通知 2公告
+     */
+    @Excel(name = "通知公告类型", readConverterExp = "1通知,2公告")
+    private Integer noticeType;
+
+    /**
+     * 通知公告状态 0正常 1关闭
+     */
+    @Excel(name = "通知公告状态", readConverterExp = "0=正常,1=关闭")
+    private Integer status;
+
+    /**
+     * 通知公告发布人ID
+     */
+    @Excel(name = "通知公告发布人ID", cellType = Excel.ColumnType.NUMERIC)
+    private Long publisherId;
+
+    /**
+     * 通知公告接收人ID
+     */
+    @Excel(name = "通知公告接收人ID")
+    private List<String> userId;
+
+    /**
+     * 通知公告逻辑删除状态 0未删除 1删除
+     */
+    @Excel(name = "逻辑删除状态", readConverterExp = "0未删除,1删除")
+    private Boolean delFlag;
+
+    public Long getNoticeId() {
+        return noticeId;
+    }
+
+    public void setNoticeId(Long noticeId) {
+        this.noticeId = noticeId;
+    }
+
+    public String getNoticeTitle() {
+        return noticeTitle;
+    }
+
+    public void setNoticeTitle(String noticeTitle) {
+        this.noticeTitle = noticeTitle;
+    }
+
+    public String getNoticeContent() {
+        return noticeContent;
+    }
+
+    public void setNoticeContent(String noticeContent) {
+        this.noticeContent = noticeContent;
+    }
+
+    public Integer getNoticeType() {
+        return noticeType;
+    }
+
+    public void setNoticeType(Integer noticeType) {
+        this.noticeType = noticeType;
+    }
+
+    public Integer getStatus() {
+        return status;
+    }
+
+    public void setStatus(Integer status) {
+        this.status = status;
+    }
+
+    public Long getPublisherId() {
+        return publisherId;
+    }
+
+    public void setPublisherId(Long publisherId) {
+        this.publisherId = publisherId;
+    }
+
+    public List<String> getUserId() {
+        return userId;
+    }
+
+    public void setUserId(List<String> userId) {
+        this.userId = userId;
+    }
+
+    public Boolean getDelFlag() {
+        return delFlag;
+    }
+
+    public void setDelFlag(Boolean delFlag) {
+        this.delFlag = delFlag;
+    }
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this)
+                .append("noticeId", noticeId)
+                .append("noticeTitle", noticeTitle)
+                .append("noticeContent", noticeContent)
+                .append("noticeType", noticeType)
+                .append("status", status)
+                .append("publisherId", publisherId)
+                .append("userId", userId)
+                .append("delFlag", delFlag)
+                .toString();
+    }
+}

+ 60 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/PoNoticeMapper.java

@@ -0,0 +1,60 @@
+package com.ruoyi.system.mapper;
+
+import com.ruoyi.system.domain.PoNotice;
+
+import java.util.List;
+
+/**
+ * 通知公告表 数据层
+ *
+ * @author blue
+ */
+public interface PoNoticeMapper {
+    /**
+     * 查询公告信息
+     *
+     * @param newsId 公告ID
+     * @return 公告信息
+     */
+    PoNotice selectPoNoticeById(Long newsId);
+
+    /**
+     * 查询公告列表
+     *
+     * @param news 公告信息
+     * @return 公告集合
+     */
+    List<PoNotice> selectPoNoticeList(PoNotice news);
+
+    /**
+     * 新增公告
+     *
+     * @param news 公告信息
+     * @return 结果
+     */
+    int insertPoNotice(PoNotice news);
+
+    /**
+     * 修改公告
+     *
+     * @param news 公告信息
+     * @return 结果
+     */
+    int updatePoNotice(PoNotice news);
+
+    /**
+     * 批量删除公告
+     *
+     * @param newsId 公告ID
+     * @return 结果
+     */
+    int deletePoNoticeById(Long newsId);
+
+    /**
+     * 批量删除公告信息
+     *
+     * @param newsIds 需要删除的公告ID
+     * @return 结果
+     */
+    int deletePoNoticeByIds(Long[] newsIds);
+}

+ 60 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/IPoNoticeService.java

@@ -0,0 +1,60 @@
+package com.ruoyi.system.service;
+
+import com.ruoyi.system.domain.PoNotice;
+
+import java.util.List;
+
+/**
+ * 公告 服务层
+ *
+ * @author ruoyi
+ */
+public interface IPoNoticeService {
+    /**
+     * 查询公告信息
+     *
+     * @param newsId 公告ID
+     * @return 公告信息
+     */
+    PoNotice selectPoNoticeById(Long newsId);
+
+    /**
+     * 查询公告列表
+     *
+     * @param news 公告信息
+     * @return 公告集合
+     */
+    List<PoNotice> selectPoNoticeList(PoNotice news);
+
+    /**
+     * 新增公告
+     *
+     * @param news 公告信息
+     * @return 结果
+     */
+    int insertPoNotice(PoNotice news);
+
+    /**
+     * 修改公告
+     *
+     * @param news 公告信息
+     * @return 结果
+     */
+    int updatePoNotice(PoNotice news);
+
+    /**
+     * 删除公告信息
+     *
+     * @param newsId 公告ID
+     * @return 结果
+     */
+    int deletePoNoticeById(Long newsId);
+
+    /**
+     * 批量删除公告信息
+     *
+     * @param newsIds 需要删除的公告ID
+     * @return 结果
+     */
+    int deletePoNoticeByIds(Long[] newsIds);
+}

+ 86 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PoNoticeServiceImpl.java

@@ -0,0 +1,86 @@
+package com.ruoyi.system.service.impl;
+
+import com.ruoyi.system.domain.PoNotice;
+import com.ruoyi.system.mapper.PoNoticeMapper;
+import com.ruoyi.system.service.IPoNoticeService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * 公告 服务层实现
+ *
+ * @author blue
+ */
+@Service
+public class PoNoticeServiceImpl implements IPoNoticeService {
+    @Autowired
+    private PoNoticeMapper noticeMapper;
+
+    /**
+     * 查询公告信息
+     *
+     * @param noticeId 公告ID
+     * @return 公告信息
+     */
+    @Override
+    public PoNotice selectPoNoticeById(Long noticeId) {
+        return noticeMapper.selectPoNoticeById(noticeId);
+    }
+
+    /**
+     * 查询公告列表
+     *
+     * @param notice 公告信息
+     * @return 公告集合
+     */
+    @Override
+    public List<PoNotice> selectPoNoticeList(PoNotice notice) {
+        return noticeMapper.selectPoNoticeList(notice);
+    }
+
+    /**
+     * 新增公告
+     *
+     * @param notice 公告信息
+     * @return 结果
+     */
+    @Override
+    public int insertPoNotice(PoNotice notice) {
+        return noticeMapper.insertPoNotice(notice);
+    }
+
+    /**
+     * 修改公告
+     *
+     * @param notice 公告信息
+     * @return 结果
+     */
+    @Override
+    public int updatePoNotice(PoNotice notice) {
+        return noticeMapper.updatePoNotice(notice);
+    }
+
+    /**
+     * 删除公告对象
+     *
+     * @param noticeId 公告ID
+     * @return 结果
+     */
+    @Override
+    public int deletePoNoticeById(Long noticeId) {
+        return noticeMapper.deletePoNoticeById(noticeId);
+    }
+
+    /**
+     * 批量删除公告信息
+     *
+     * @param noticeIds 需要删除的公告ID
+     * @return 结果
+     */
+    @Override
+    public int deletePoNoticeByIds(Long[] noticeIds) {
+        return noticeMapper.deletePoNoticeByIds(noticeIds);
+    }
+}

+ 122 - 0
ruoyi-system/src/main/resources/mapper/system/PoNoticeMapper.xml

@@ -0,0 +1,122 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ruoyi.system.mapper.PoNoticeMapper">
+
+    <resultMap type="PoNotice" id="PoNoticeResult">
+        <result property="noticeId" column="notice_id"/>
+        <result property="noticeTitle" column="notice_title"/>
+        <result property="noticeContent" column="notice_content"/>
+        <result property="noticeType" column="notice_type"/>
+        <result property="status" column="status"/>
+        <result property="createBy" column="create_by"/>
+        <result property="createTime" column="create_time"/>
+        <result property="updateBy" column="update_by"/>
+        <result property="updateTime" column="update_time"/>
+        <result property="remark" column="remark"/>
+        <result property="publisherId" column="publisher_id"/>
+        <result property="userId" column="user_id" typeHandler="com.ruoyi.common.utils.sql.List2VarcharHandler"/>
+        <result property="delFlag" column="del_flag"/>
+    </resultMap>
+
+    <sql id="selectPoNoticeVo">
+        select notice_id,
+               notice_title,
+               cast(notice_content as char) as notice_content,
+               notice_type,
+               status,
+               create_by,
+               create_time,
+               update_by,
+               update_time,
+               remark,
+               publisher_id,
+               user_id,
+               del_flag
+        from po_notice
+    </sql>
+
+    <select id="selectPoNoticeById" parameterType="Long" resultMap="PoNoticeResult">
+        <include refid="selectPoNoticeVo"/>
+        where notice_id = #{noticeId}
+    </select>
+
+    <select id="selectPoNoticeList" parameterType="PoNotice" resultMap="PoNoticeResult">
+        <include refid="selectPoNoticeVo"/>
+        <where>
+            <if test="noticeTitle != null and noticeTitle != ''">
+                AND notice_title like concat('%', #{noticeTitle}, '%')
+            </if>
+            <if test="createBy != null and createBy != ''">
+                AND create_by like concat('%', #{createBy}, '%')
+            </if>
+            <if test="publisherId != null and publisherId != ''">
+                AND publisher_id like concat('%', #{publisherId}, '%')
+            </if>
+            <if test="delFlag != null and delFlag != ''">
+                AND del_flag like concat('%', #{delFlag}, '%')
+            </if>
+            <if test="noticeType != null and noticeType != ''">
+                AND notice_type like concat('%', #{noticeType}, '%')
+            </if>
+        </where>
+    </select>
+
+    <insert id="insertPoNotice" parameterType="PoNotice">
+        insert into po_notice (
+        <if test="noticeTitle != null and noticeTitle != '' ">notice_title,</if>
+        <if test="noticeContent != null and noticeContent != '' ">notice_content,</if>
+        <if test="noticeType != null and noticeType != '' ">notice_type,</if>
+        <if test="status != null and status != '' ">status,</if>
+        <if test="remark != null and remark != ''">remark,</if>
+        <if test="createBy != null and createBy != ''">create_by,</if>
+        <if test="publisherId != null and publisherId != ''">publisher_id,</if>
+        <if test="userId != null and userId != ''">user_id,</if>
+        del_flag,
+        create_time
+        )values(
+        <if test="noticeTitle != null and noticeTitle != ''">#{noticeTitle},</if>
+        <if test="noticeContent != null and noticeContent != ''">#{noticeContent},</if>
+        <if test="noticeType != null and noticeType != ''">#{noticeType},</if>
+        <if test="status != null and status != ''">#{status},</if>
+        <if test="remark != null and remark != ''">#{remark},</if>
+        <if test="createBy != null and createBy != ''">#{createBy},</if>
+        <if test="publisherId != null and publisherId != ''">#{publisher_id},</if>
+        <if test="userId != null and userId != ''">#{user_id},</if>
+        0,
+        sysdate()
+        )
+    </insert>
+
+    <update id="updatePoNotice" parameterType="PoNotice">
+        update po_notice
+        <set>
+            <if test="noticeTitle != null and noticeTitle != ''">notice_title = #{noticeTitle},</if>
+            <if test="noticeContent != null">notice_content = #{noticeContent},</if>
+            <if test="noticeType != null and noticeType != ''">notice_type = #{noticeType},</if>
+            <if test="status != null and status != ''">status = #{status},</if>
+            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
+            <if test="remark != null and remark != ''">remark = #{remark},</if>
+            <if test="publisherId != null and publisherId != ''">publisher_id = #{publisherId},</if>
+            <if test="userId != null and userId != ''">user_id = #{userId},</if>
+            <if test="delFlag != null and delFlag != ''">del_flag = #{del_flag},</if>
+            update_time = sysdate()
+        </set>
+        where notice_id = #{noticeId}
+    </update>
+
+    <delete id="deletePoNoticeById" parameterType="Long">
+        delete
+        from po_notice
+        where notice_id = #{noticeId}
+    </delete>
+
+    <delete id="deletePoNoticeByIds" parameterType="Long">
+        delete from po_notice where notice_id in
+        <foreach item="noticeId" collection="array" open="(" separator="," close=")">
+            #{noticeId}
+        </foreach>
+    </delete>
+
+</mapper>