优化:1、查询员工通知时更新浏览量;2、删除多余的 NoticeMapper.xml 文件

This commit is contained in:
zhoumingfa 2024-08-04 15:37:44 +08:00
parent 8fd02fc519
commit 84b5d338b6
5 changed files with 30 additions and 73 deletions

View File

@ -114,4 +114,14 @@ public interface NoticeDao extends BaseMapper<NoticeEntity> {
*/ */
void updateViewRecord(@Param("noticeId")Long noticeId, @Param("employeeId")Long requestEmployeeId,@Param("ip") String ip, @Param("userAgent")String userAgent); void updateViewRecord(@Param("noticeId")Long noticeId, @Param("employeeId")Long requestEmployeeId,@Param("ip") String ip, @Param("userAgent")String userAgent);
/**
* 更新 浏览量
*
* @param noticeId 通知 id
* @param pageViewCountIncrement 页面浏览量的增量
* @param userViewCountIncrement 用户浏览量的增量
*/
void updateViewCount(@Param("noticeId")Long noticeId,@Param("pageViewCountIncrement") Integer pageViewCountIncrement, @Param("userViewCountIncrement")Integer userViewCountIncrement);
} }

View File

@ -52,10 +52,10 @@ public class NoticeEmployeeService {
public ResponseDTO<PageResult<NoticeEmployeeVO>> queryList(Long requestEmployeeId, NoticeEmployeeQueryForm noticeEmployeeQueryForm) { public ResponseDTO<PageResult<NoticeEmployeeVO>> queryList(Long requestEmployeeId, NoticeEmployeeQueryForm noticeEmployeeQueryForm) {
Page<?> page = SmartPageUtil.convert2PageQuery(noticeEmployeeQueryForm); Page<?> page = SmartPageUtil.convert2PageQuery(noticeEmployeeQueryForm);
//获取请求人的 部门及其子部门
List<Long> employeeDepartmentIdList = Lists.newArrayList(); List<Long> employeeDepartmentIdList = Lists.newArrayList();
EmployeeEntity employeeEntity = employeeService.getById(requestEmployeeId); EmployeeEntity employeeEntity = employeeService.getById(requestEmployeeId);
if (employeeEntity.getDepartmentId() != null) { // 如果不是管理员 则获取请求人的 部门及其子部门
if (!employeeEntity.getAdministratorFlag() && employeeEntity.getDepartmentId() != null) {
employeeDepartmentIdList = departmentService.selfAndChildrenIdList(employeeEntity.getDepartmentId()); employeeDepartmentIdList = departmentService.selfAndChildrenIdList(employeeEntity.getDepartmentId());
} }
@ -106,8 +106,15 @@ public class NoticeEmployeeService {
long viewCount = noticeDao.viewRecordCount(noticeId, requestEmployeeId); long viewCount = noticeDao.viewRecordCount(noticeId, requestEmployeeId);
if (viewCount == 0) { if (viewCount == 0) {
noticeDao.insertViewRecord(noticeId, requestEmployeeId, ip, userAgent, 1); noticeDao.insertViewRecord(noticeId, requestEmployeeId, ip, userAgent, 1);
// 该员工对于这个通知是第一次查看 页面浏览量+1 用户浏览量+1
noticeDao.updateViewCount(noticeId, 1, 1);
noticeDetailVO.setPageViewCount(noticeDetailVO.getPageViewCount() + 1);
noticeDetailVO.setUserViewCount(noticeDetailVO.getUserViewCount() + 1);
} else { } else {
noticeDao.updateViewRecord(noticeId, requestEmployeeId, ip, userAgent); noticeDao.updateViewRecord(noticeId, requestEmployeeId, ip, userAgent);
// 该员工对于这个通知不是第一次查看 页面浏览量+1 用户浏览量+0
noticeDao.updateViewCount(noticeId, 1, 0);
noticeDetailVO.setPageViewCount(noticeDetailVO.getPageViewCount() + 1);
} }
return ResponseDTO.ok(noticeDetailVO); return ResponseDTO.ok(noticeDetailVO);

View File

@ -60,8 +60,11 @@ public class EmployeeManager extends ServiceImpl<EmployeeDao, EmployeeEntity> {
// 保存员工 获得id // 保存员工 获得id
employeeDao.updateById(employee); employeeDao.updateById(employee);
if (CollectionUtils.isNotEmpty(roleIdList)) { if (CollectionUtils.isEmpty(roleIdList)) {
List<RoleEmployeeEntity> roleEmployeeList = roleIdList.stream().map(e -> new RoleEmployeeEntity(e, employee.getEmployeeId())).collect(Collectors.toList()); // 删除员工角色
this.updateEmployeeRole(employee.getEmployeeId(), null);
} else {
List<RoleEmployeeEntity> roleEmployeeList = roleIdList.stream().map(roleId -> new RoleEmployeeEntity(roleId, employee.getEmployeeId())).collect(Collectors.toList());
this.updateEmployeeRole(employee.getEmployeeId(), roleEmployeeList); this.updateEmployeeRole(employee.getEmployeeId(), roleEmployeeList);
} }
} }

View File

@ -1,69 +0,0 @@
<?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="net.lab1024.sa.admin.module.business.notice.NoticeDao">
<update id="updateWatchAmount">
UPDATE t_notice
SET watch_amount = watch_amount + 1
WHERE notice_id = #{noticeId}
</update>
<update id="batchDeleteNotice">
UPDATE t_notice
SET deleted_flag = #{deletedFlag}
WHERE notice_id IN
<foreach collection="noticeIdList" open="(" close=")" separator="," item="item">
#{item}
</foreach>
</update>
<update id="updateNotice">
UPDATE t_notice
SET notice_type = #{noticeType},
notice_belong_type = #{noticeBelongType},
notice_title = #{noticeTitle},
notice_content = #{noticeContent},
link_address = #{linkAddress},
cover_file_key = #{coverFileKey},
accessory_file_keys = #{accessoryFileKeys},
top_flag = #{topFlag},
publish_time = #{publishTime},
disabled_flag = #{disabledFlag}
WHERE notice_id = #{noticeId}
</update>
<select id="queryPage" resultType="net.lab1024.sa.admin.module.business.oa.notice.domain.vo.NoticeVO">
SELECT t_notice.*,
t_employee.actual_name AS createUserName
FROM t_notice
LEFT JOIN t_employee ON t_notice.create_user_id = t_employee.employee_id
<where>
t_notice.deleted_flag = #{queryForm.deletedFlag}
<if test="queryForm.keywords != null and queryForm.keywords != ''">
AND (INSTR(t_notice.notice_title,#{queryForm.keywords}) OR INSTR(t_employee.actual_name,#{queryForm.keywords}))
</if>
<if test="queryForm.noticeType != null">
AND t_notice.notice_type = #{queryForm.noticeType}
</if>
<if test="queryForm.noticeBelongType != null">
AND t_notice.notice_belong_type = #{queryForm.noticeBelongType}
</if>
<if test="queryForm.startTime != null">
AND DATE_FORMAT(t_notice.publish_time, '%Y-%m-%d') &gt;= #{queryForm.startTime}
</if>
<if test="queryForm.endTime != null">
AND DATE_FORMAT(t_notice.publish_time, '%Y-%m-%d') &lt;= #{queryForm.endTime}
</if>
<if test="queryForm.disabledFlag != null">
AND t_notice.disabled_flag = #{queryForm.disabledFlag}
</if>
</where>
<if test="queryForm.sortItemList == null or queryForm.sortItemList.size == 0">
ORDER BY t_notice.top_flag DESC,t_notice.publish_time DESC
</if>
</select>
<select id="getDetail" resultType="net.lab1024.sa.admin.module.business.oa.notice.domain.vo.NoticeVO">
SELECT tn.*,
e.actual_name AS createUserName
FROM t_notice tn
LEFT JOIN t_employee e ON tn.create_user_id = e.employee_id
WHERE tn.notice_id = #{noticeId}
AND tn.deleted_flag = #{deletedFlag}
</select>
</mapper>

View File

@ -242,5 +242,11 @@
where notice_id = #{noticeId} where notice_id = #{noticeId}
and employee_id = #{employeeId} and employee_id = #{employeeId}
</update> </update>
<update id="updateViewCount">
update t_notice
set page_view_count = page_view_count + #{pageViewCountIncrement},
user_view_count = user_view_count + #{userViewCountIncrement}
where notice_id = #{noticeId}
</update>
</mapper> </mapper>