12417 3 жил өмнө
parent
commit
ba50a19625

+ 113 - 0
master/src/main/java/com/ruoyi/project/system/controller/SysUserNoticeController.java

@@ -0,0 +1,113 @@
+package com.ruoyi.project.system.controller;
+
+import java.util.List;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import com.ruoyi.framework.aspectj.lang.annotation.Log;
+import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
+import com.ruoyi.project.system.domain.SysUserNotice;
+import com.ruoyi.project.system.service.ISysUserNoticeService;
+import com.ruoyi.framework.web.controller.BaseController;
+import com.ruoyi.framework.web.domain.AjaxResult;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.framework.web.page.TableDataInfo;
+
+/**
+ * 用户通知关联Controller
+ *
+ * @author ruoyi
+ * @date 2021-10-13
+ */
+@RestController
+@RequestMapping("/system/noticeUser")
+public class SysUserNoticeController extends BaseController
+{
+    @Autowired
+    private ISysUserNoticeService sysUserNoticeService;
+
+    /**
+     * 查询用户通知关联列表
+     */
+    @PreAuthorize("@ss.hasPermi('system:noticeUser:list')")
+    @GetMapping("/list")
+    public TableDataInfo list(SysUserNotice sysUserNotice)
+    {
+        startPage();
+        List<SysUserNotice> list = sysUserNoticeService.selectSysUserNoticeList(sysUserNotice);
+        return getDataTable(list);
+    }
+
+    //根据用户id获取用户关联列表
+    @PreAuthorize("@ss.hasPermi('system:noticeUser:query')")
+    @GetMapping(value = "/{userId}")
+    public TableDataInfo listByUserId(@PathVariable("userId")Long userId)
+    {
+        startPage();
+        List<SysUserNotice> list = sysUserNoticeService.selectSysUserNoticeListByUserId(userId);
+        return getDataTable(list);
+    }
+
+    /**
+     * 导出用户通知关联列表
+     */
+    /*@PreAuthorize("@ss.hasPermi('system:noticeUser:export')")
+    @Log(title = "用户通知关联", businessType = BusinessType.EXPORT)
+    @GetMapping("/export")
+    public AjaxResult export(SysUserNotice sysUserNotice)
+    {
+        List<SysUserNotice> list = sysUserNoticeService.selectSysUserNoticeList(sysUserNotice);
+        ExcelUtil<SysUserNotice> util = new ExcelUtil<SysUserNotice>(SysUserNotice.class);
+        return util.exportExcel(list, "notice");
+    }*/
+
+    /**
+     * 获取用户通知关联详细信息
+     */
+    /*@PreAuthorize("@ss.hasPermi('system:noticeUser:query')")
+    @GetMapping(value = "/{id}")
+    public AjaxResult getInfo(@PathVariable("id") Long id)
+    {
+        return AjaxResult.success(sysUserNoticeService.selectSysUserNoticeById(id));
+    }*/
+
+    /**
+     * 新增用户通知关联
+     */
+    @PreAuthorize("@ss.hasPermi('system:noticeUser:add')")
+    @Log(title = "用户通知关联", businessType = BusinessType.INSERT)
+    @PostMapping
+    public AjaxResult add(@RequestBody SysUserNotice sysUserNotice)
+    {
+        return toAjax(sysUserNoticeService.insertSysUserNotice(sysUserNotice));
+    }
+
+    /**
+     * 修改用户通知关联
+     */
+    /*@PreAuthorize("@ss.hasPermi('system:noticeUser:edit')")
+    @Log(title = "用户通知关联", businessType = BusinessType.UPDATE)
+    @PutMapping
+    public AjaxResult edit(@RequestBody SysUserNotice sysUserNotice)
+    {
+        return toAjax(sysUserNoticeService.updateSysUserNotice(sysUserNotice));
+    }
+*/
+    /**
+     * 删除用户通知关联
+     */
+    /*@PreAuthorize("@ss.hasPermi('system:noticeUser:remove')")
+    @Log(title = "用户通知关联", businessType = BusinessType.DELETE)
+	@DeleteMapping("/{ids}")
+    public AjaxResult remove(@PathVariable Long[] ids)
+    {
+        return toAjax(sysUserNoticeService.deleteSysUserNoticeByIds(ids));
+    }*/
+}

+ 98 - 0
master/src/main/java/com/ruoyi/project/system/domain/SysUserNotice.java

@@ -0,0 +1,98 @@
+package com.ruoyi.project.system.domain;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.ruoyi.framework.aspectj.lang.annotation.Excel;
+import com.ruoyi.framework.web.domain.BaseEntity;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+
+import java.util.Date;
+
+/**
+ * 用户通知关联对象 sys_user_notice
+ *
+ * @author ruoyi
+ * @date 2021-10-13
+ */
+public class SysUserNotice extends BaseEntity
+{
+    private static final long serialVersionUID = 1L;
+
+    /** 序号 */
+    private Long id;
+
+    /** 用户编号 */
+    @Excel(name = "用户编号")
+    private Long userId;
+
+    /** 公告编号 */
+    @Excel(name = "公告编号")
+    private Long noticeId;
+
+    /** 是否阅读(是 : 1 ; 否 : 0;) */
+    @Excel(name = "是否阅读(是 : 1 ; 否 : 0;)")
+    private Long read;
+
+    public Date getCreatetime() {
+        return createtime;
+    }
+
+    public void setCreatetime(Date createtime) {
+        this.createtime = createtime;
+    }
+
+    /** 创建时间 */
+    @JsonFormat(pattern = "yyyy-MM-dd" , timezone = "GMT+8")
+    @Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd")
+    private Date createtime;
+
+    public void setId(Long id)
+    {
+        this.id = id;
+    }
+
+    public Long getId()
+    {
+        return id;
+    }
+    public void setUserId(Long userId)
+    {
+        this.userId = userId;
+    }
+
+    public Long getUserId()
+    {
+        return userId;
+    }
+    public void setNoticeId(Long noticeId)
+    {
+        this.noticeId = noticeId;
+    }
+
+    public Long getNoticeId()
+    {
+        return noticeId;
+    }
+    public void setRead(Long read)
+    {
+        this.read = read;
+    }
+
+    public Long getRead()
+    {
+        return read;
+    }
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
+            .append("id", getId())
+            .append("userId", getUserId())
+            .append("noticeId", getNoticeId())
+            .append("read", getRead())
+            .append("createtime", getCreatetime())
+            .toString();
+    }
+
+
+}

+ 72 - 0
master/src/main/java/com/ruoyi/project/system/mapper/SysUserNoticeMapper.java

@@ -0,0 +1,72 @@
+package com.ruoyi.project.system.mapper;
+
+import java.util.List;
+import com.ruoyi.framework.aspectj.lang.annotation.DataScope;
+import com.ruoyi.project.system.domain.SysUserNotice;
+
+/**
+ * 用户通知关联Mapper接口
+ * 
+ * @author ruoyi
+ * @date 2021-10-13
+ */
+public interface SysUserNoticeMapper 
+{
+    /**
+     * 查询用户通知关联
+     * 
+     * @param id 用户通知关联ID
+     * @return 用户通知关联
+     */
+    public SysUserNotice selectSysUserNoticeById(Long id);
+
+    /**
+     * 查询用户通知关联列表
+     *
+     * @param sysUserNotice 用户通知关联
+     * @return 用户通知关联集合
+     */
+    @DataScope(deptAlias = "d")
+    public List<SysUserNotice> selectSysUserNoticeList(SysUserNotice sysUserNotice);
+
+    /**
+     * 根据用户id,查询用户通知关联列表
+     *
+     * @param userId 用户编号
+     * @return 用户通知关联集合
+     */
+    @DataScope(deptAlias = "d")
+    public List<SysUserNotice> selectSysUserNoticeListByUserId(Long userId);
+
+    /**
+     * 新增用户通知关联
+     * 
+     * @param sysUserNotice 用户通知关联
+     * @return 结果
+     */
+    public int insertSysUserNotice(SysUserNotice sysUserNotice);
+
+    /**
+     * 修改用户通知关联
+     * 
+     * @param sysUserNotice 用户通知关联
+     * @return 结果
+     */
+    public int updateSysUserNotice(SysUserNotice sysUserNotice);
+
+    /**
+     * 删除用户通知关联
+     * 
+     * @param id 用户通知关联ID
+     * @return 结果
+     */
+    public int deleteSysUserNoticeById(Long id);
+
+    /**
+     * 批量删除用户通知关联
+     * 
+     * @param ids 需要删除的数据ID
+     * @return 结果
+     */
+    public int deleteSysUserNoticeByIds(Long[] ids);
+}

+ 98 - 0
master/src/main/java/com/ruoyi/project/system/service/impl/SysUserNoticeServiceImpl.java

@@ -0,0 +1,98 @@
+package com.ruoyi.project.system.service.impl;
+
+import java.util.List;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import com.ruoyi.project.system.mapper.SysUserNoticeMapper;
+import com.ruoyi.project.system.domain.SysUserNotice;
+import com.ruoyi.project.system.service.ISysUserNoticeService;
+
+/**
+ * 用户通知关联Service业务层处理
+ *
+ * @author ruoyi
+ * @date 2021-10-13
+ */
+@Service
+public class SysUserNoticeServiceImpl implements ISysUserNoticeService
+{
+    @Autowired
+    private SysUserNoticeMapper sysUserNoticeMapper;
+
+    /**
+     * 查询用户通知关联
+     *
+     * @param id 用户通知关联ID
+     * @return 用户通知关联
+     */
+    @Override
+    public SysUserNotice selectSysUserNoticeById(Long id)
+    {
+        return sysUserNoticeMapper.selectSysUserNoticeById(id);
+    }
+
+    /**
+     * 查询用户通知关联列表
+     *
+     * @param sysUserNotice 用户通知关联
+     * @return 用户通知关联
+     */
+    @Override
+    public List<SysUserNotice> selectSysUserNoticeList(SysUserNotice sysUserNotice)
+    {
+        return sysUserNoticeMapper.selectSysUserNoticeList(sysUserNotice);
+    }
+
+    @Override
+    public List<SysUserNotice> selectSysUserNoticeListByUserId(Long userId) {
+        return sysUserNoticeMapper.selectSysUserNoticeListByUserId(userId);
+    }
+
+    /**
+     * 新增用户通知关联
+     *
+     * @param sysUserNotice 用户通知关联
+     * @return 结果
+     */
+    @Override
+    public int insertSysUserNotice(SysUserNotice sysUserNotice)
+    {
+        return sysUserNoticeMapper.insertSysUserNotice(sysUserNotice);
+    }
+
+    /**
+     * 修改用户通知关联
+     *
+     * @param sysUserNotice 用户通知关联
+     * @return 结果
+     */
+    @Override
+    public int updateSysUserNotice(SysUserNotice sysUserNotice)
+    {
+        return sysUserNoticeMapper.updateSysUserNotice(sysUserNotice);
+    }
+
+    /**
+     * 批量删除用户通知关联
+     *
+     * @param ids 需要删除的用户通知关联ID
+     * @return 结果
+     */
+    @Override
+    public int deleteSysUserNoticeByIds(Long[] ids)
+    {
+        return sysUserNoticeMapper.deleteSysUserNoticeByIds(ids);
+    }
+
+    /**
+     * 删除用户通知关联信息
+     *
+     * @param id 用户通知关联ID
+     * @return 结果
+     */
+    @Override
+    public int deleteSysUserNoticeById(Long id)
+    {
+        return sysUserNoticeMapper.deleteSysUserNoticeById(id);
+    }
+}

+ 87 - 0
master/src/main/resources/mybatis/system/SysUserNoticeMapper.xml

@@ -0,0 +1,87 @@
+<?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.project.system.mapper.SysUserNoticeMapper">
+    
+    <resultMap type="SysUserNotice" id="SysUserNoticeResult">
+        <result property="id"    column="id"    />
+        <result property="userId"    column="user_id"    />
+        <result property="noticeId"    column="notice_id"    />
+        <result property="read"    column="read"    />
+        <result property="createtime"    column="createtime"    />
+        <result property="deptName" column="dept_name" />
+    </resultMap>
+
+    <sql id="selectSysUserNoticeVo">
+        select d.id, d.user_id, d.notice_id, d.read, d.createtime ,s.dept_name from sys_user_notice d
+      left join sys_dept s on s.dept_id = d.dept_id
+    </sql>
+
+    <select id="selectSysUserNoticeList" parameterType="SysUserNotice" resultMap="SysUserNoticeResult">
+        <include refid="selectSysUserNoticeVo"/>
+        <where>  
+            <if test="userId != null "> and user_id = #{userId}</if>
+            <if test="noticeId != null "> and notice_id = #{noticeId}</if>
+            <if test="read != null "> and read = #{read}</if>
+            <if test="createtime != null "> and createtime = #{createtime}</if>
+            and d.del_flag = 0
+        </where>
+        <!-- 数据范围过滤 -->
+        ${params.dataScope}
+    </select>
+    
+    <select id="selectSysUserNoticeById" parameterType="Long" resultMap="SysUserNoticeResult">
+        <include refid="selectSysUserNoticeVo"/>
+        where id = #{id}
+    </select>
+
+    <select id="selectSysUserNoticeByUserId" parameterType="Long" resultMap="SysUserNoticeResult">
+        <include refid="selectSysUserNoticeVo"/>
+        where USER_ID = #{userId}
+    </select>
+        
+    <insert id="insertSysUserNotice" parameterType="SysUserNotice">
+        <selectKey keyProperty="id" resultType="long" order="BEFORE">
+            SELECT seq_sys_user_notice.NEXTVAL as id FROM DUAL
+        </selectKey>
+        insert into sys_user_notice
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="id != null">id,</if>
+            <if test="userId != null">user_id,</if>
+            <if test="noticeId != null">notice_id,</if>
+            <if test="read != null">read,</if>
+            <if test="createtime != null">createtime,</if>
+         </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="id != null">#{id},</if>
+            <if test="userId != null">#{userId},</if>
+            <if test="noticeId != null">#{noticeId},</if>
+            <if test="read != null">#{read},</if>
+            <if test="createtime != null">#{createtime},</if>
+         </trim>
+    </insert>
+
+    <update id="updateSysUserNotice" parameterType="SysUserNotice">
+        update sys_user_notice
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="userId != null">user_id = #{userId},</if>
+            <if test="noticeId != null">notice_id = #{noticeId},</if>
+            <if test="read != null">read = #{read},</if>
+            <if test="createtime != null">createtime = #{createtime},</if>
+        </trim>
+        where id = #{id}
+    </update>
+
+    <update id="deleteSysUserNoticeById" parameterType="Long">
+        update sys_user_notice set del_flag = 2 where id = #{id}
+    </update>
+
+    <update id="deleteSysUserNoticeByIds" parameterType="String">
+        update sys_user_notice set del_flag = 2 where id in
+        <foreach item="id" collection="array" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </update>
+    
+</mapper>

+ 20 - 1
ui/src/api/system/notice.js

@@ -17,6 +17,25 @@ export function getNotice(noticeId) {
   })
 }
 
+//新增已读记录
+export function insertReadHis(data) {
+  return request({
+    url: '/system/noticeUser/add',
+    method: 'post',
+    data: data
+  })
+}
+
+// 根据用户id查询用户公告关联记录
+export function getNoticeUser(userId) {
+  return request({
+    url: '/system/noticeUser/' + userId,
+    method: 'get'
+  })
+}
+
+
+
 // 新增公告
 export function addNotice(data) {
   return request({
@@ -41,4 +60,4 @@ export function delNotice(noticeId) {
     url: '/system/notice/' + noticeId,
     method: 'delete'
   })
-}
+}

+ 8 - 1
ui/src/views/system/notice/index.vue

@@ -93,12 +93,17 @@
         :formatter="statusFormat"
         width="100"
       />
+
+      <el-table-column :label="$t('阅览状态')" align="center" prop="" width="100" />
+
       <el-table-column :label="$t('创建人')" align="center" prop="createBy" width="100" />
       <el-table-column :label="$t('创建时间')" align="center" prop="createTime" width="100">
         <template slot-scope="scope">
           <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
         </template>
       </el-table-column>
+
+
       <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width">
         <template slot-scope="scope">
           <el-button
@@ -224,7 +229,7 @@
 </template>
 
 <script>
-import { listNotice, getNotice, delNotice, addNotice, updateNotice } from "@/api/system/notice";
+import {listNotice, getNotice, delNotice, addNotice, updateNotice, insertReadHis} from "@/api/system/notice";
 import Editor from '@/components/Editor';
 
 export default {
@@ -371,6 +376,8 @@ export default {
         this.title = this.$t('查看') + " " + this.$t('公告');
       });
 
+      insertReadHis(row.noticeId,userId);
+
     },
     /** 提交按钮 */
     submitForm: function() {