浏览代码

Merge remote-tracking branch 'origin/master'

徐明浩 3 年之前
父节点
当前提交
b6be1a48d4

+ 24 - 29
master/src/main/java/com/ruoyi/project/system/controller/SysUserNoticeController.java

@@ -1,5 +1,6 @@
 package com.ruoyi.project.system.controller;
 
+import java.util.Date;
 import java.util.List;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -24,10 +25,10 @@ import com.ruoyi.framework.web.page.TableDataInfo;
  * 用户通知关联Controller
  *
  * @author ruoyi
- * @date 2021-10-13
+ * @date 2021-10-15
  */
 @RestController
-@RequestMapping("/system/noticeUser")
+@RequestMapping("/system/userNotice")
 public class SysUserNoticeController extends BaseController
 {
     @Autowired
@@ -36,7 +37,7 @@ public class SysUserNoticeController extends BaseController
     /**
      * 查询用户通知关联列表
      */
-    @PreAuthorize("@ss.hasPermi('system:noticeUser:list')")
+    @PreAuthorize("@ss.hasPermi('system:userNotice:list')")
     @GetMapping("/list")
     public TableDataInfo list(SysUserNotice sysUserNotice)
     {
@@ -45,69 +46,63 @@ public class SysUserNoticeController extends BaseController
         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')")
+    /*@PreAuthorize("@ss.hasPermi('system:userNotice: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");
+        return util.exportExcel(list, "userNotice");
     }*/
 
     /**
      * 获取用户通知关联详细信息
      */
-    /*@PreAuthorize("@ss.hasPermi('system:noticeUser:query')")
-    @GetMapping(value = "/{id}")
-    public AjaxResult getInfo(@PathVariable("id") Long id)
+    /*@PreAuthorize("@ss.hasPermi('system:userNotice:query')")
+    @GetMapping(value = "/{userId}")
+    public AjaxResult getInfo(@PathVariable("userId") Long userId)
     {
-        return AjaxResult.success(sysUserNoticeService.selectSysUserNoticeById(id));
+        return AjaxResult.success(sysUserNoticeService.selectSysUserNoticeById(userId));
     }*/
 
     /**
      * 新增用户通知关联
      */
-    @PreAuthorize("@ss.hasPermi('system:noticeUser:add')")
+    @PreAuthorize("@ss.hasPermi('system:userNotice:add')")
     @Log(title = "用户通知关联", businessType = BusinessType.INSERT)
-    @PostMapping
-    public AjaxResult add(@RequestBody SysUserNotice sysUserNotice)
+    @GetMapping
+    public AjaxResult add(@RequestBody Long noticeId)
     {
+        SysUserNotice sysUserNotice = new SysUserNotice();
+        sysUserNotice.setNoticeId(noticeId);
+        sysUserNotice.setUserId(this.getUserId());
+        sysUserNotice.setCreateTime(new Date());
         return toAjax(sysUserNoticeService.insertSysUserNotice(sysUserNotice));
     }
 
     /**
      * 修改用户通知关联
      */
-    /*@PreAuthorize("@ss.hasPermi('system:noticeUser:edit')")
+    /*@PreAuthorize("@ss.hasPermi('system:userNotice:edit')")
     @Log(title = "用户通知关联", businessType = BusinessType.UPDATE)
     @PutMapping
     public AjaxResult edit(@RequestBody SysUserNotice sysUserNotice)
     {
         return toAjax(sysUserNoticeService.updateSysUserNotice(sysUserNotice));
-    }
-*/
+    }*/
+
     /**
      * 删除用户通知关联
      */
-    /*@PreAuthorize("@ss.hasPermi('system:noticeUser:remove')")
+    /*@PreAuthorize("@ss.hasPermi('system:userNotice:remove')")
     @Log(title = "用户通知关联", businessType = BusinessType.DELETE)
-	@DeleteMapping("/{ids}")
-    public AjaxResult remove(@PathVariable Long[] ids)
+	@DeleteMapping("/{userIds}")
+    public AjaxResult remove(@PathVariable Long[] userIds)
     {
-        return toAjax(sysUserNoticeService.deleteSysUserNoticeByIds(ids));
+        return toAjax(sysUserNoticeService.deleteSysUserNoticeByIds(userIds));
     }*/
 }

+ 8 - 40
master/src/main/java/com/ruoyi/project/system/domain/SysUserNotice.java

@@ -1,6 +1,5 @@
 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;
@@ -12,15 +11,12 @@ import java.util.Date;
  * 用户通知关联对象 sys_user_notice
  *
  * @author ruoyi
- * @date 2021-10-13
+ * @date 2021-10-15
  */
 public class SysUserNotice extends BaseEntity
 {
     private static final long serialVersionUID = 1L;
 
-    /** 序号 */
-    private Long id;
-
     /** 用户编号 */
     @Excel(name = "用户编号")
     private Long userId;
@@ -29,32 +25,17 @@ public class SysUserNotice extends BaseEntity
     @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;
+    private Date createTime;
 
-    public void setId(Long id)
-    {
-        this.id = id;
+    public Date getCreateTime() {
+        return createTime;
     }
 
-    public Long getId()
-    {
-        return id;
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
     }
+
     public void setUserId(Long userId)
     {
         this.userId = userId;
@@ -73,26 +54,13 @@ public class SysUserNotice extends BaseEntity
     {
         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())
+            .append("createTime", getCreateTime())
             .toString();
     }
-
-
 }

+ 8 - 17
master/src/main/java/com/ruoyi/project/system/mapper/SysUserNoticeMapper.java

@@ -8,36 +8,27 @@ import com.ruoyi.project.system.domain.SysUserNotice;
  * 用户通知关联Mapper接口
  * 
  * @author ruoyi
- * @date 2021-10-13
+ * @date 2021-10-15
  */
 public interface SysUserNoticeMapper 
 {
     /**
      * 查询用户通知关联
      * 
-     * @param id 用户通知关联ID
+     * @param userId 用户通知关联ID
      * @return 用户通知关联
      */
-    public SysUserNotice selectSysUserNoticeById(Long id);
+    public SysUserNotice selectSysUserNoticeById(Long userId);
 
     /**
      * 查询用户通知关联列表
-     *
+     * 
      * @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);
-
     /**
      * 新增用户通知关联
      * 
@@ -57,16 +48,16 @@ public interface SysUserNoticeMapper
     /**
      * 删除用户通知关联
      * 
-     * @param id 用户通知关联ID
+     * @param userId 用户通知关联ID
      * @return 结果
      */
-    public int deleteSysUserNoticeById(Long id);
+    public int deleteSysUserNoticeById(Long userId);
 
     /**
      * 批量删除用户通知关联
      * 
-     * @param ids 需要删除的数据ID
+     * @param userIds 需要删除的数据ID
      * @return 结果
      */
-    public int deleteSysUserNoticeByIds(Long[] ids);
+    public int deleteSysUserNoticeByIds(Long[] userIds);
 }

+ 7 - 15
master/src/main/java/com/ruoyi/project/system/service/ISysUserNoticeService.java

@@ -7,17 +7,17 @@ import com.ruoyi.project.system.domain.SysUserNotice;
  * 用户通知关联Service接口
  * 
  * @author ruoyi
- * @date 2021-10-13
+ * @date 2021-10-15
  */
 public interface ISysUserNoticeService 
 {
     /**
      * 查询用户通知关联
      * 
-     * @param id 用户通知关联ID
+     * @param userId 用户通知关联ID
      * @return 用户通知关联
      */
-    public SysUserNotice selectSysUserNoticeById(Long id);
+    public SysUserNotice selectSysUserNoticeById(Long userId);
 
     /**
      * 查询用户通知关联列表
@@ -27,14 +27,6 @@ public interface ISysUserNoticeService
      */
     public List<SysUserNotice> selectSysUserNoticeList(SysUserNotice sysUserNotice);
 
-    /**
-     * 查询用户通知关联列表
-     *
-     * @param userId 用户编号
-     * @return 用户通知关联集合
-     */
-    public List<SysUserNotice> selectSysUserNoticeListByUserId(Long userId);
-
     /**
      * 新增用户通知关联
      * 
@@ -54,16 +46,16 @@ public interface ISysUserNoticeService
     /**
      * 批量删除用户通知关联
      * 
-     * @param ids 需要删除的用户通知关联ID
+     * @param userIds 需要删除的用户通知关联ID
      * @return 结果
      */
-    public int deleteSysUserNoticeByIds(Long[] ids);
+    public int deleteSysUserNoticeByIds(Long[] userIds);
 
     /**
      * 删除用户通知关联信息
      * 
-     * @param id 用户通知关联ID
+     * @param userId 用户通知关联ID
      * @return 结果
      */
-    public int deleteSysUserNoticeById(Long id);
+    public int deleteSysUserNoticeById(Long userId);
 }

+ 10 - 15
master/src/main/java/com/ruoyi/project/system/service/impl/SysUserNoticeServiceImpl.java

@@ -11,7 +11,7 @@ import com.ruoyi.project.system.service.ISysUserNoticeService;
  * 用户通知关联Service业务层处理
  *
  * @author ruoyi
- * @date 2021-10-13
+ * @date 2021-10-15
  */
 @Service
 public class SysUserNoticeServiceImpl implements ISysUserNoticeService
@@ -22,13 +22,13 @@ public class SysUserNoticeServiceImpl implements ISysUserNoticeService
     /**
      * 查询用户通知关联
      *
-     * @param id 用户通知关联ID
+     * @param userId 用户通知关联ID
      * @return 用户通知关联
      */
     @Override
-    public SysUserNotice selectSysUserNoticeById(Long id)
+    public SysUserNotice selectSysUserNoticeById(Long userId)
     {
-        return sysUserNoticeMapper.selectSysUserNoticeById(id);
+        return sysUserNoticeMapper.selectSysUserNoticeById(userId);
     }
 
     /**
@@ -43,11 +43,6 @@ public class SysUserNoticeServiceImpl implements ISysUserNoticeService
         return sysUserNoticeMapper.selectSysUserNoticeList(sysUserNotice);
     }
 
-    @Override
-    public List<SysUserNotice> selectSysUserNoticeListByUserId(Long userId) {
-        return sysUserNoticeMapper.selectSysUserNoticeListByUserId(userId);
-    }
-
     /**
      * 新增用户通知关联
      *
@@ -75,24 +70,24 @@ public class SysUserNoticeServiceImpl implements ISysUserNoticeService
     /**
      * 批量删除用户通知关联
      *
-     * @param ids 需要删除的用户通知关联ID
+     * @param userIds 需要删除的用户通知关联ID
      * @return 结果
      */
     @Override
-    public int deleteSysUserNoticeByIds(Long[] ids)
+    public int deleteSysUserNoticeByIds(Long[] userIds)
     {
-        return sysUserNoticeMapper.deleteSysUserNoticeByIds(ids);
+        return sysUserNoticeMapper.deleteSysUserNoticeByIds(userIds);
     }
 
     /**
      * 删除用户通知关联信息
      *
-     * @param id 用户通知关联ID
+     * @param userId 用户通知关联ID
      * @return 结果
      */
     @Override
-    public int deleteSysUserNoticeById(Long id)
+    public int deleteSysUserNoticeById(Long userId)
     {
-        return sysUserNoticeMapper.deleteSysUserNoticeById(id);
+        return sysUserNoticeMapper.deleteSysUserNoticeById(userId);
     }
 }

+ 14 - 0
master/src/main/resources/mybatis/system/SysNoticeMapper.xml

@@ -15,6 +15,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="updateBy"       column="update_by"       />
         <result property="updateTime"     column="update_time"     />
         <result property="remark"         column="remark"          />
+        <!--<result property="readFlag"       column="read_flag"       />-->
     </resultMap>
 
     <sql id="selectNoticeVo">
@@ -91,4 +92,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </foreach>
     </delete>
 
+
+    <!--设置公告已读公告-->
+    <update id="">
+        update sys_notice
+        <set>
+            <if test="readFlag != null and readFlag != ''">read_flag = #{readFlag},</if>
+        </set>
+        where notice_id = 1
+    </update>
+
+
+
+
 </mapper>

+ 14 - 28
master/src/main/resources/mybatis/system/SysUserNoticeMapper.xml

@@ -5,16 +5,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 <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
+        select d.user_id, d.notice_id, d.createtime ,s.dept_name from sys_user_notice d
       left join sys_dept s on s.dept_id = d.dept_id
     </sql>
 
@@ -23,7 +21,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <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>
@@ -33,55 +30,44 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     
     <select id="selectSysUserNoticeById" parameterType="Long" resultMap="SysUserNoticeResult">
         <include refid="selectSysUserNoticeVo"/>
-        where id = #{id}
+        where user_id = #{userId}
     </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 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>
+        where user_id = #{userId}
+    </update>-->
 
-    <update id="deleteSysUserNoticeById" parameterType="Long">
-        update sys_user_notice set del_flag = 2 where id = #{id}
+   <!-- <update id="deleteSysUserNoticeById" parameterType="Long">
+        update sys_user_notice set del_flag = 2 where user_id = #{userId}
     </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}
+        update sys_user_notice set del_flag = 2 where user_id in
+        <foreach item="userId" collection="array" open="(" separator="," close=")">
+            #{userId}
         </foreach>
-    </update>
+    </update>-->
     
 </mapper>

+ 13 - 7
ui/src/api/system/notice.js

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

+ 1 - 2
ui/src/store/modules/user.js

@@ -66,7 +66,7 @@ const user = {
         })
       })
     },
-    
+
     // 退出系统
     LogOut({ commit, state }) {
       return new Promise((resolve, reject) => {
@@ -81,7 +81,6 @@ const user = {
         })
       })
     },
-
     // 前端 登出
     FedLogOut({ commit }) {
       return new Promise(resolve => {

+ 19 - 4
ui/src/views/system/notice/index.vue

@@ -229,7 +229,15 @@
 </template>
 
 <script>
-import {listNotice, getNotice, delNotice, addNotice, updateNotice, insertReadHis} from "@/api/system/notice";
+import {
+  listNotice,
+  getNotice,
+  delNotice,
+  addNotice,
+  updateNotice,
+  insertReadHis,
+  listByUserId
+} from "@/api/system/notice";
 import Editor from '@/components/Editor';
 
 export default {
@@ -298,6 +306,10 @@ export default {
     });
   },
   methods: {
+
+    //查询公告是否已读
+
+
     /** 查询公告列表 */
     getList() {
       this.loading = true;
@@ -367,6 +379,7 @@ export default {
     },
     /** 查看 **/
     handleSelect(row) {
+      debugger;
       this.reset();
       const noticeId = row.noticeId || this.ids
       getNotice(noticeId).then(response => {
@@ -375,9 +388,11 @@ export default {
         this.check= true;
         this.title = this.$t('查看') + " " + this.$t('公告');
       });
-
-      insertReadHis(row.noticeId,userId);
-
+      //点击查询,判断是否已有该条数据若已有则不添加,没有则向关联表添加一条数据
+      insertReadHis(row.noticeId).then(response => {
+        this.msgSuccess(this.$t('已读'));
+        this.getList();
+      });
     },
     /** 提交按钮 */
     submitForm: function() {