diff --git a/bonus-modules/bonus-system/src/main/java/com/bonus/system/basic/controller/SysNoticeController.java b/bonus-modules/bonus-system/src/main/java/com/bonus/system/basic/controller/SysNoticeController.java index 303b32c..75e239b 100644 --- a/bonus-modules/bonus-system/src/main/java/com/bonus/system/basic/controller/SysNoticeController.java +++ b/bonus-modules/bonus-system/src/main/java/com/bonus/system/basic/controller/SysNoticeController.java @@ -7,14 +7,18 @@ import com.bonus.common.log.annotation.Log; import com.bonus.common.log.enums.BusinessType; import com.bonus.common.security.annotation.RequiresPermissions; import com.bonus.common.security.utils.SecurityUtils; +import com.bonus.system.api.domain.SysRole; import com.bonus.system.api.domain.SysUser; +import com.bonus.system.basic.dao.SysUserMapper; import com.bonus.system.basic.domain.SysNotice; import com.bonus.system.basic.service.SysNoticeService; +import com.bonus.system.holiday.dao.WorkReportDao; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; @@ -29,11 +33,44 @@ public class SysNoticeController extends BaseController { @Autowired private SysNoticeService noticeService; + @Resource(name = "WorkReportDao") + private WorkReportDao dao; + + @Resource + private SysUserMapper userMapper; + @RequiresPermissions("system:notice:list") @GetMapping("/list") @Log(title = "系统管理->我的消息->查询消息列表", businessType = BusinessType.QUERY) public TableDataInfo list(SysNotice bean) { try{ + Long userId = SecurityUtils.getUserId(); + List sysRoleList = dao.getRoleListByUserId(userId); + int roleCount = 0; + if(!sysRoleList.isEmpty()){ + for (SysRole sysRole : sysRoleList) { + if(sysRole.getRoleName().contains("管理员")){ + roleCount = 1; + break; + }else if(sysRole.getRoleName().contains("部门负责人")){ + roleCount = 2; + break; + } + } + } + if(roleCount==2){ + String ids = userMapper.getOrg(userId); + String userIdList = userMapper.getUserIdList(ids); + bean.setRoleType("2"); + String[] split = userIdList.split(","); + bean.setUserIdList(split); + }else if(roleCount==1){ + bean.setRoleType("1"); + } else{ + bean.setRoleType("3"); + bean.setUserId(userId); + } + List list = noticeService.selectNoticeList(bean); return endPage(list); }catch (Exception e){ diff --git a/bonus-modules/bonus-system/src/main/java/com/bonus/system/basic/dao/SysNoticeMapper.java b/bonus-modules/bonus-system/src/main/java/com/bonus/system/basic/dao/SysNoticeMapper.java index f618af2..28485a7 100644 --- a/bonus-modules/bonus-system/src/main/java/com/bonus/system/basic/dao/SysNoticeMapper.java +++ b/bonus-modules/bonus-system/src/main/java/com/bonus/system/basic/dao/SysNoticeMapper.java @@ -10,6 +10,7 @@ import com.bonus.system.basic.domain.SysUserPost; import com.bonus.system.basic.domain.SysUserRole; import com.bonus.system.holiday.entity.HolidayKeyBean; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -27,7 +28,7 @@ public interface SysNoticeMapper * @param bean * @return */ - List selectNoticeList(SysNotice bean); + List selectNoticeList(@Param("bean") SysNotice bean); /** * 新增我的消息 @@ -62,4 +63,6 @@ public interface SysNoticeMapper List getUserIdByOrgId(Long orgId); List getAttUserIdByOrgId(List orgList); + + int delNotice(SysNotice bean); } diff --git a/bonus-modules/bonus-system/src/main/java/com/bonus/system/basic/dao/SysUserMapper.java b/bonus-modules/bonus-system/src/main/java/com/bonus/system/basic/dao/SysUserMapper.java index 726b84d..a1afaa5 100644 --- a/bonus-modules/bonus-system/src/main/java/com/bonus/system/basic/dao/SysUserMapper.java +++ b/bonus-modules/bonus-system/src/main/java/com/bonus/system/basic/dao/SysUserMapper.java @@ -230,4 +230,6 @@ public interface SysUserMapper List getRoleListById(SysUser user); String getOrg(Long userId); + + String getUserIdList(String userIdList); } diff --git a/bonus-modules/bonus-system/src/main/java/com/bonus/system/basic/domain/SysNotice.java b/bonus-modules/bonus-system/src/main/java/com/bonus/system/basic/domain/SysNotice.java index 73714a6..df466f1 100644 --- a/bonus-modules/bonus-system/src/main/java/com/bonus/system/basic/domain/SysNotice.java +++ b/bonus-modules/bonus-system/src/main/java/com/bonus/system/basic/domain/SysNotice.java @@ -62,4 +62,16 @@ public class SysNotice * 参数 */ private String value; + + /** + * 请假申请id + */ + private long leaveApplyId; + + /** + * 角色类型 1:人资专员和管理员;2:考勤员 + */ + private String roleType; + + private String[] userIdList; } diff --git a/bonus-modules/bonus-system/src/main/java/com/bonus/system/basic/service/SysNoticeService.java b/bonus-modules/bonus-system/src/main/java/com/bonus/system/basic/service/SysNoticeService.java index 802983f..ce66c27 100644 --- a/bonus-modules/bonus-system/src/main/java/com/bonus/system/basic/service/SysNoticeService.java +++ b/bonus-modules/bonus-system/src/main/java/com/bonus/system/basic/service/SysNoticeService.java @@ -3,6 +3,7 @@ package com.bonus.system.basic.service; import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.system.basic.domain.SysNotice; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -54,4 +55,10 @@ public interface SysNoticeService { * @return */ List getAttUserIdByOrgId(List orgList); + + /** + * 先删除之前的推送消息 + * @param bean + */ + AjaxResult delNotice(SysNotice bean); } diff --git a/bonus-modules/bonus-system/src/main/java/com/bonus/system/basic/service/impl/SysNoticeServiceImpl.java b/bonus-modules/bonus-system/src/main/java/com/bonus/system/basic/service/impl/SysNoticeServiceImpl.java index c091c9f..38e1a7e 100644 --- a/bonus-modules/bonus-system/src/main/java/com/bonus/system/basic/service/impl/SysNoticeServiceImpl.java +++ b/bonus-modules/bonus-system/src/main/java/com/bonus/system/basic/service/impl/SysNoticeServiceImpl.java @@ -51,6 +51,7 @@ public class SysNoticeServiceImpl implements SysNoticeService SysNotice notice = new SysNotice(); notice.setUserId(userId1); notice.setNoticeId(bean.getNoticeId()); + notice.setLeaveApplyId(bean.getLeaveApplyId()); list.add(notice); } result = noticeMapper.insertUserNotice(list); @@ -89,4 +90,16 @@ public class SysNoticeServiceImpl implements SysNoticeService public List getAttUserIdByOrgId(List orgList) { return noticeMapper.getAttUserIdByOrgId(orgList); } + + @Override + public AjaxResult delNotice(SysNotice bean) { + try { + int re = noticeMapper.delNotice(bean); + return re > 0 ? AjaxResult.success() : AjaxResult.error(); + }catch (Exception e){ + e.printStackTrace(); + log.error(e.toString(),e); + return AjaxResult.error(); + } + } } diff --git a/bonus-modules/bonus-system/src/main/java/com/bonus/system/holiday/service/HolidayServiceImpl.java b/bonus-modules/bonus-system/src/main/java/com/bonus/system/holiday/service/HolidayServiceImpl.java index 6e9552c..c3f1c52 100644 --- a/bonus-modules/bonus-system/src/main/java/com/bonus/system/holiday/service/HolidayServiceImpl.java +++ b/bonus-modules/bonus-system/src/main/java/com/bonus/system/holiday/service/HolidayServiceImpl.java @@ -86,12 +86,18 @@ public class HolidayServiceImpl implements HolidayService { List userList = noticeService.getUserIdByOrgId(o.getOrgId()); // 将 List 转换为数组 if(!userList.isEmpty()){ + if (userList.size() > 1) { // 检查是否有多个元素 + // 如果有多个元素,检查并移除值为1的元素 + while (userList.contains(userId)) { + userList.remove(Long.valueOf(userId)); + } + } Long[] userIds = userList.toArray(new Long[0]); //发送审批消息 SysNotice bean = new SysNotice(); bean.setUserIds(userIds); bean.setUserId(userId); - if("轮休".equals(o.getLeaveType())){ + /*if("轮休".equals(o.getLeaveType())){ bean.setTitle("轮休申请"); bean.setContent("轮休申请"); bean.setType("65"); @@ -99,8 +105,19 @@ public class HolidayServiceImpl implements HolidayService { bean.setTitle("临时外出申请"); bean.setContent("临时外出申请"); bean.setType("66"); + }*/ + if("轮休".equals(o.getLeaveType())){ + bean.setTitle("轮休审批提醒"); + bean.setContent("轮休审批提醒"); + bean.setType("67"); + }else{ + bean.setTitle("临时外出审批提醒"); + bean.setContent("临时外出审批提醒"); + bean.setType("68"); } + bean.setValue(""); + bean.setLeaveApplyId(o.getId()); //推送消息 noticeService.insertNotice(bean); } @@ -117,12 +134,54 @@ public class HolidayServiceImpl implements HolidayService { public int updateHoliday(HolidayBean o) { o.setUpdateUserId(SecurityUtils.getLoginUser().getSysUser().getUserId()); o.setExamineStatus("0"); - return holidayDao.updateHoliday(o); + int i = holidayDao.updateHoliday(o); + Long userId = SecurityUtils.getLoginUser().getSysUser().getUserId(); + if (i > 0) { + //获取部门负责人 + List userList = noticeService.getUserIdByOrgId(o.getOrgId()); + // 将 List 转换为数组 + if(!userList.isEmpty()){ + if (userList.size() > 1) { // 检查是否有多个元素 + // 如果有多个元素,检查并移除值为1的元素 + while (userList.contains(userId)) { + userList.remove(Long.valueOf(userId)); + } + } + Long[] userIds = userList.toArray(new Long[0]); + //发送审批消息 + SysNotice bean = new SysNotice(); + bean.setUserIds(userIds); + bean.setUserId(userId); + if("轮休".equals(o.getLeaveType())){ + bean.setTitle("轮休审批提醒"); + bean.setContent("轮休审批提醒"); + bean.setType("67"); + }else{ + bean.setTitle("临时外出审批提醒"); + bean.setContent("临时外出审批提醒"); + bean.setType("68"); + } + bean.setValue(""); + bean.setLeaveApplyId(o.getId()); + //先删除之前的推送消息 + noticeService.delNotice(bean); + //推送消息 + noticeService.insertNotice(bean); + } + } + return i; } @Override public int deleteHolidayById(Long id) { - return holidayDao.deleteHolidayById(id); + int i = holidayDao.deleteHolidayById(id); + if(i>0){ + SysNotice bean = new SysNotice(); + bean.setLeaveApplyId(id); + //先删除之前的推送消息 + noticeService.delNotice(bean); + } + return i ; } /** @@ -160,6 +219,12 @@ public class HolidayServiceImpl implements HolidayService { List userList =holidayDao.getUserIdById(o.getId()); // 将 List 转换为数组 if(!userList.isEmpty()){ + if (userList.size() > 1) { // 检查是否有多个元素 + // 如果有多个元素,检查并移除值为1的元素 + while (userList.contains(updateUserId)) { + userList.remove(Long.valueOf(updateUserId)); + } + } Long[] userIds = userList.toArray(new Long[0]); //发送审批消息 SysNotice bean = new SysNotice(); diff --git a/bonus-modules/bonus-system/src/main/resources/mapper/basic/SysNoticeMapper.xml b/bonus-modules/bonus-system/src/main/resources/mapper/basic/SysNoticeMapper.xml index 716386a..fe794c2 100644 --- a/bonus-modules/bonus-system/src/main/resources/mapper/basic/SysNoticeMapper.xml +++ b/bonus-modules/bonus-system/src/main/resources/mapper/basic/SysNoticeMapper.xml @@ -1,7 +1,7 @@ + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> insert into sys_notice( @@ -10,6 +10,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" content, type, value, + leave_apply_id, create_time ) values( #{userId}, @@ -17,21 +18,31 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{content}, #{type}, #{value}, + #{leaveApplyId}, sysdate() -) + ) - insert into sys_notice_user(notice_id, user_id) values + insert into sys_notice_user(notice_id, user_id,leave_apply_id) values - (#{item.noticeId},#{item.userId}) + (#{item.noticeId},#{item.userId},#{item.leaveApplyId}) - update sys_notice_user set is_read='1' where notice_id = #{noticeId} and user_id = #{userId} and is_active = 1 + update sys_notice_user + set is_read='1' + where notice_id = #{noticeId} + and user_id = #{userId} + and is_active = 1 - + SELECT DISTINCT snu.notice_id as noticeId, sn.title, sn.content, @@ -45,49 +56,49 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" LEFT JOIN sys_notice sn on sn.id=snu.notice_id and sn.is_active=1 LEFT JOIN sys_user su on su.user_id=sn.user_id and su.is_active=1 LEFT JOIN sys_dict_data sdd on sdd.dict_code=sn.type and sdd.`status`=0 - WHERE - snu.user_id=#{userId} - and snu.is_active=1 - - and snu.is_read=#{isRead} + WHERE snu.is_active=1 + + and sn.user_id=#{bean.userId} + + + and snu.is_read=#{bean.isRead} + + + + and sn.user_id in + + #{userId} + + order by sn.create_time desc + + \ No newline at end of file diff --git a/bonus-modules/bonus-system/src/main/resources/mapper/holiday/HolidayMapper.xml b/bonus-modules/bonus-system/src/main/resources/mapper/holiday/HolidayMapper.xml index a261d3c..0496cbb 100644 --- a/bonus-modules/bonus-system/src/main/resources/mapper/holiday/HolidayMapper.xml +++ b/bonus-modules/bonus-system/src/main/resources/mapper/holiday/HolidayMapper.xml @@ -3,7 +3,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + INSERT INTO leave_apply(user_id,user_name,org_id,org_name,leave_type,leave_reason, leave_start_date,leave_start_interval,leave_end_date,leave_end_interval, leave_duration,examine_status,source,create_user_id,is_agree, location, host_user_id, remark,type)