通知公告

This commit is contained in:
mashuai 2025-03-12 14:52:48 +08:00
parent f2e39fd91a
commit 92f51eb9c0
9 changed files with 500 additions and 28 deletions

View File

@ -0,0 +1,26 @@
package com.bonus.common.biz.enums;
import lombok.Getter;
/**
* @author : 阮世耀
* @version : 1.0
* @PackagePath: com.bonus.common.biz.enums
* @CreateTime: 2024-10-15 10:28
* @Description: 通知公告是否发送短信状态枚举类
*/
@Getter
public enum NoticeSmsEnum {
SENDSMS_ENABLED("0", "发送短信"),
SENDSMS_DISABLED("1", "不发送短信");
private final String code;
private final String msg;
NoticeSmsEnum(String code, String msg) {
this.code = code;
this.msg = msg;
}
}

View File

@ -113,7 +113,9 @@ public class LargeScreenController {
Integer repairingDevNum = devInfoMapper.getRepairingDevNum();
orderData.setDevRepairingNum(repairingDevNum);
DevInfo devInfo = devInfoMapper.getDevUsageRatio();
orderData.setDevUsageRatio(MathUtil.calculatePercentage(devInfo.getTotalLeaseDay(), devInfo.getTotalUpDay() + devInfo.getTotalLeaseDay()));
if(devInfo != null){
orderData.setDevUsageRatio(MathUtil.calculatePercentage(devInfo.getTotalLeaseDay(), devInfo.getTotalUpDay() + devInfo.getTotalLeaseDay()));
}
return AjaxResult.success(orderData);
}
@ -123,10 +125,10 @@ public class LargeScreenController {
OrderData orderData = new OrderData();
Integer leaseNum = leaseInfoMapper.getLeaseCount();
Integer leaseOrderNum = leaseInfoMapper.getLeaseOrderCount();
Integer maTypeCountFromLease = leaseInfoMapper.getMaTypeCountFromLease();
//Integer maTypeCountFromLease = leaseInfoMapper.getMaTypeCountFromLease();
String topPopularTypeName = leaseInfoMapper.getTopPopularTypeName();
orderData.setLeaseNum(leaseNum);
orderData.setMaTypeCountFromLease(maTypeCountFromLease);
//orderData.setMaTypeCountFromLease(maTypeCountFromLease);
orderData.setLeaseOrderRatio(MathUtil.calculatePercentage(leaseOrderNum, leaseNum));
orderData.setTopPopularTypeName(topPopularTypeName);
return AjaxResult.success(orderData);

View File

@ -2,14 +2,16 @@ package com.bonus.material.notice.controller;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.log.enums.OperaType;
import com.bonus.common.security.utils.SecurityUtils;
import com.bonus.material.notice.entity.Notice;
import com.bonus.material.notice.service.NoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@ -35,6 +37,58 @@ public class NoticeController extends BaseController {
return AjaxResult.success(getDataTable(sysNotices));
}
/**
* 新增通知公告
* @param notice
* @return
*/
@PostMapping
@SysLog(title = "通知公告", businessType = OperaType.INSERT,logType = 0,module = "系统管理->通知公告")
public AjaxResult add(@Validated @RequestBody Notice notice) {
try{
notice.setCreateBy(SecurityUtils.getUsername());
return noticeService.insertNotice(notice);
}catch (Exception e){
log.error(e.toString(),e);
}
return error("系统异常");
}
/**
* 修改通知公告
* @param notice
* @return
*/
@PostMapping("/edit")
@SysLog(title = "通知公告", businessType = OperaType.UPDATE,logType = 0,module = "系统管理->通知公告")
public AjaxResult edit(@Validated @RequestBody Notice notice) {
try{
notice.setUpdateBy(SecurityUtils.getUsername());
return noticeService.updateNotice(notice);
}catch (Exception e){
log.error(e.toString(),e);
}
return error("系统异常");
}
/**
* 删除通知公告
* @param noticeIds
* @return
*/
@PostMapping("/delete/{noticeIds}")
@SysLog(title = "通知公告", businessType = OperaType.DELETE,logType = 0,module = "系统管理->通知公告")
public AjaxResult remove(@PathVariable Long[] noticeIds) {
try{
return noticeService.deleteNoticeByIds(noticeIds);
}catch (Exception e){
log.error(e.toString(),e);
}
return error("系统异常");
}
/* @GetMapping("/noticeList")
@ApiOperation(value = "系统公告app")
public AjaxResult noticeList(Notice notice) {

View File

@ -12,6 +12,12 @@ import java.util.Date;
*/
@Data
public class Notice {
/**
* 是否后台后台全部展示 (1)
*/
private Integer isHome;
/**
* 公告ID
*/
@ -25,7 +31,7 @@ public class Notice {
/**
* 公告类型1通知 2公告 3质检到期提醒
*/
private Integer noticeType;
private String noticeType;
/**
* 公告内容
@ -70,4 +76,51 @@ public class Notice {
* 装备质检到期所属公司
*/
private Integer ownCo;
/**
* 组织id
*/
private Long deptId;
/**
* 部门名称
*/
private String deptName;
/**
* 角色id
*/
private Long roleId;
/**
* 角色名称
*/
private String roleName;
/**
* 是否短信通知(0 1 )
*/
private String isSms;
/**
* 公告有效期
*/
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date expiryDate;
/**
* 用户id
*/
private Long userId;
/**
* 用户名
*/
private String userName;
/**
* 手机号
*/
private String phoneNumber;
}

View File

@ -1,7 +1,6 @@
package com.bonus.material.notice.mapper;
import com.bonus.material.notice.entity.Notice;
import com.bonus.system.api.domain.SysNotice;
import java.util.List;
@ -10,11 +9,44 @@ import java.util.List;
* @Date2024/12/20 - 19:25
*/
public interface NoticeMapper {
/**
* 查询通知公告列表
* @param notice
* @return
*/
List<Notice> selectNoticeList(Notice notice);
void addNotice(Notice notice);
int addNotice(Notice notice);
List<Notice> noticeList(Notice notice);
List<Notice> messageList(Notice notice);
/**
* 修改通知公告
* @param notice
* @return
*/
int updateNotice(Notice notice);
/**
* 批量删除通知公告
* @param noticeIds
* @return
*/
int deleteNoticeByIds(Long[] noticeIds);
/**
* 查询短信通知人员列表
* @param notice
* @return
*/
List<Notice> getSmsList(Notice notice);
/**
* 根据userId查询角色id
* @param userId
* @return
*/
List<Notice> selectRoleId(Long userId);
}

View File

@ -1,7 +1,7 @@
package com.bonus.material.notice.service;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.material.notice.entity.Notice;
import com.bonus.system.api.domain.SysNotice;
import java.util.List;
@ -10,9 +10,36 @@ import java.util.List;
* @Date2024/12/20 - 19:22
*/
public interface NoticeService {
/**
* 查询公告列表
* @param notice
* @return
*/
List<Notice> selectNoticeList(Notice notice);
List<Notice> noticeList(Notice notice);
List<Notice> messageList(Notice notice);
/**
* 新增通知公告
* @param notice
* @return
*/
AjaxResult insertNotice(Notice notice);
/**
* 修改通知公告
* @param notice
* @return
*/
AjaxResult updateNotice(Notice notice);
/**
* 删除通知公告
* @param noticeIds
* @return
*/
AjaxResult deleteNoticeByIds(Long[] noticeIds);
}

View File

@ -1,14 +1,24 @@
package com.bonus.material.notice.service.impl;
import com.bonus.common.biz.enums.HttpCodeEnum;
import com.bonus.common.biz.enums.NoticeSmsEnum;
import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.core.utils.StringUtils;
import com.bonus.common.core.utils.encryption.Sm4Utils;
import com.bonus.common.core.utils.sms.SmsUtils;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.security.utils.SecurityUtils;
import com.bonus.material.notice.entity.Notice;
import com.bonus.material.notice.mapper.NoticeMapper;
import com.bonus.material.notice.service.NoticeService;
import com.bonus.system.api.domain.SysNotice;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
/**
* @Authorliang.chao
@ -19,9 +29,65 @@ public class NoticeServiceImpl implements NoticeService {
@Resource
private NoticeMapper noticeMapper;
/**
* 查询通知公告列表
* @param notice
* @return
*/
@Override
public List<Notice> selectNoticeList(Notice notice) {
return noticeMapper.selectNoticeList(notice);
Long userId = SecurityUtils.getUserId();
// 根据userId查询角色id
List<Notice> dtoList = noticeMapper.selectRoleId(userId);
// 从dtoList中取出roleId集合
List<Long> roleIdList = new ArrayList<>();
for (Notice info : dtoList) {
roleIdList.add(info.getRoleId());
}
Long deptId = SecurityUtils.getLoginUser().getSysUser().getDeptId();
List<Notice> list = noticeMapper.selectNoticeList(notice);
if (!CollectionUtils.isEmpty(list)) {
// 后台默认全部展示
if (notice.getIsHome() != null && notice.getIsHome() == 1) {
return list;
}
Iterator<Notice> iterator = list.iterator();
while (iterator.hasNext()) {
Notice info = iterator.next();
// 过滤关闭公告
if ("1".equals(info.getStatus())) {
iterator.remove();
continue;
}
// 过期公告过滤
if (info.getExpiryDate() != null) {
if (info.getExpiryDate().before(DateUtils.getNowDate())) {
iterator.remove();
continue;
}
}
// 根据角色和部门进行过滤
if (info.getDeptId() != null && info.getRoleId() == null) {
if (!info.getDeptId().equals(deptId)) {
iterator.remove();
continue;
}
}
if (info.getRoleId() != null && info.getDeptId() == null) {
if (!roleIdList.contains(info.getRoleId())) {
iterator.remove();
continue;
}
}
if (info.getDeptId() != null && info.getRoleId() != null) {
if (!info.getDeptId().equals(deptId) || !roleIdList.contains(info.getRoleId())) {
iterator.remove();
}
}
}
}
return list;
}
@Override
@ -34,4 +100,132 @@ public class NoticeServiceImpl implements NoticeService {
notice.setOwnCo(SecurityUtils.getLoginUser().getSysUser().getCompanyId().intValue());
return noticeMapper.messageList(notice);
}
/**
* 新增通知公告
* @param notice
* @return
*/
@Override
public AjaxResult insertNotice(Notice notice) {
if (notice == null) {
return AjaxResult.error(HttpCodeEnum.TO_PARAM_NULL.getCode(), HttpCodeEnum.TO_PARAM_NULL.getMsg());
}
// 针对于短信通告进行短信人员通知
if (NoticeSmsEnum.SENDSMS_ENABLED.getCode().equals(notice.getIsSms())) {
if (NoticeSmsEnum.SENDSMS_DISABLED.getCode().equals(notice.getStatus())) {
return AjaxResult.error("通知公告状态为关闭,无法进行发送短信通知公告服务");
}
List<Notice> smsList = noticeMapper.getSmsList(notice);
if (CollectionUtils.isEmpty(smsList)) {
return AjaxResult.error("所选组织机构及角色下属人员信息为空,无法进行发送短信通知公告服务");
}
if (!CollectionUtils.isEmpty(smsList)) {
for (Notice info : smsList) {
if (StringUtils.isBlank(info.getPhoneNumber())) {
continue;
}
String phoneNumber = info.getPhoneNumber();
if (Objects.nonNull(info.getPhoneNumber()) && info.getPhoneNumber().length() > 11) {
phoneNumber = Sm4Utils.decrypt(info.getPhoneNumber());
}
// 根据电话号码数量发送短信
//JSONObject sendResult = SmsTool.sendSms(new SmsParam(phoneNumber, notice.getNoticeContent()), BmConfigItems.ANHUI_COMPANY_SMS_KEY);
String sendResult = SmsUtils.smsToken(phoneNumber, notice.getNoticeContent(), "");
if (StringUtils.isBlank(sendResult)) {
return AjaxResult.error("短信发送失败");
} else {
System.out.println("短信发送成功:" + sendResult);
}
}
}
}
notice.setCreateTime(DateUtils.getNowDate());
int result = noticeMapper.addNotice(notice);
if (result == 0) {
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
}
return AjaxResult.success(HttpCodeEnum.SUCCESS.getMsg());
}
/**
* 修改通知公告
* @param notice
* @return
*/
@Override
public AjaxResult updateNotice(Notice notice) {
if (notice == null || notice.getNoticeId() == null) {
return AjaxResult.error(HttpCodeEnum.TO_PARAM_NULL.getCode(), HttpCodeEnum.TO_PARAM_NULL.getMsg());
}
// 查询通知公告
List<Notice> list = noticeMapper.selectNoticeList(notice);
List<Notice> smsList = new ArrayList<>();
Notice info = new Notice();
if (!CollectionUtils.isEmpty(list)) {
info = list.get(0);
if (NoticeSmsEnum.SENDSMS_ENABLED.getCode().equals(info.getIsSms())) {
// 查询上一次已经发送的短信人员
smsList = noticeMapper.getSmsList(info);
}
}
// 进行短信通知公告
if (NoticeSmsEnum.SENDSMS_ENABLED.getCode().equals(notice.getIsSms())) {
if (NoticeSmsEnum.SENDSMS_DISABLED.getCode().equals(notice.getStatus())) {
return AjaxResult.error("通知公告状态为关闭,无法进行发送短信通知公告服务");
}
// 查询待短信通知公告人员
List<Notice> newSmsList = noticeMapper.getSmsList(notice);
if (CollectionUtils.isEmpty(newSmsList)) {
return AjaxResult.error("所选组织机构及角色下属人员信息为空,无法进行发送短信通知公告服务");
}
if (notice.getNoticeContent().equals(info.getNoticeContent()) && !CollectionUtils.isEmpty(smsList)) {
// 移出已经发送的短信人员
for (Notice smsInfo : smsList) {
newSmsList.removeIf(newSmsInfo -> smsInfo.getUserId().equals(newSmsInfo.getUserId()));
}
}
if (!CollectionUtils.isEmpty(newSmsList)) {
for (Notice notice1 : newSmsList) {
if (StringUtils.isBlank(notice1.getPhoneNumber())) {
continue;
}
String phoneNumber = notice1.getPhoneNumber();
if (Objects.nonNull(notice1.getPhoneNumber()) && notice1.getPhoneNumber().length() > 11) {
phoneNumber = Sm4Utils.decrypt(notice1.getPhoneNumber());
}
// 根据电话号码数量发送短信
//JSONObject sendResult = SmsTool.sendSms(new SmsParam(phoneNumber, notice.getNoticeContent()), BmConfigItems.ANHUI_COMPANY_SMS_KEY);
String sendResult = SmsUtils.smsToken(phoneNumber, notice.getNoticeContent(), "");
if (StringUtils.isBlank(sendResult)) {
return AjaxResult.error("短信发送失败");
} else {
System.out.println("短信发送成功:" + sendResult);
}
}
}
}
int result = noticeMapper.updateNotice(notice);
if (result == 0) {
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
}
return AjaxResult.success(HttpCodeEnum.SUCCESS.getMsg());
}
/**
* 删除通知公告
* @param noticeIds
* @return
*/
@Override
public AjaxResult deleteNoticeByIds(Long[] noticeIds) {
if (noticeIds == null || noticeIds.length == 0) {
return AjaxResult.error(HttpCodeEnum.TO_PARAM_NULL.getCode(), HttpCodeEnum.TO_PARAM_NULL.getMsg());
}
int result = noticeMapper.deleteNoticeByIds(noticeIds);
if (result == 0) {
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
}
return AjaxResult.success(HttpCodeEnum.SUCCESS.getMsg());
}
}

View File

@ -999,12 +999,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<update id="updateTotalDevUpDay">
update ma_dev_info set total_up_day = total_up_day + 1
update ma_dev_info set total_up_day = IFNULL(total_up_day, 0) + 1
where is_active = '1' and ma_status = '2'
</update>
<update id="updateTotalDevLeaseDay">
update ma_dev_info set total_lease_day = total_lease_day + 1
update ma_dev_info set total_lease_day = IFNULL(total_lease_day, 0) + 1
where is_active = '1' and ma_status = '3'
</update>

View File

@ -14,7 +14,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update_by,
update_time,
remark,
own_co
own_co,
dept_id,
role_id,
is_sms,
expiry_date
)
values(
#{noticeTitle},
@ -26,22 +30,77 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{updateBy},
#{updateTime},
#{remark},
#{ownCo},
#{deptId},
#{roleId},
#{isSms},
#{expiryDate}
)
</insert>
<update id="updateNotice">
update sys_notice
<set>
<if test="noticeTitle != null and noticeTitle != ''">notice_title = #{noticeTitle}, </if>
<if test="noticeType != null and noticeType != ''">notice_type = #{noticeType}, </if>
<if test="noticeContent != null">notice_content = #{noticeContent}, </if>
<if test="status != null and status != ''">status = #{status}, </if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="ownCo != null">own_co = #{ownCo},</if>
<if test="deptId != null">dept_id = #{deptId},</if>
<if test="roleId != null">role_id = #{roleId},</if>
<if test="isSms != null and isSms != ''">is_sms = #{isSms},</if>
<if test="expiryDate != null">expiry_date = #{expiryDate},</if>
update_time = sysdate()
</set>
where notice_id = #{noticeId}
</update>
<delete id="deleteNoticeByIds">
delete from sys_notice where notice_id in
<foreach item="noticeId" collection="array" open="(" separator="," close=")">
#{noticeId}
</foreach>
</delete>
<select id="selectNoticeList" resultType="com.bonus.material.notice.entity.Notice">
select
notice_id,
notice_title,
notice_type,
notice_content,
status,
create_by,
create_time,
update_by,
update_time,
remark
from sys_notice
SELECT
sn.notice_id as noticeId,
sn.notice_title as noticeTitle,
sn.notice_type as noticeType,
sn.notice_content as noticeContent,
sn.STATUS as status,
sn.create_by as createBy,
sn.create_time as createTime,
sn.update_by as updateBy,
sn.update_time as updateTime,
sn.remark as remark,
sn.own_co as ownCo,
sn.dept_id as deptId,
sn.role_id as roleId,
sn.is_sms as isSms,
sn.expiry_date as expiryDate,
sd.dept_name as deptName,
sr.role_name as roleName
FROM
sys_notice sn
LEFT JOIN sys_dept sd ON sn.dept_id = sd.dept_id
LEFT JOIN sys_role sr ON sn.role_id = sr.role_id
<where>
<if test="noticeId != null">
AND sn.notice_id = #{noticeId}
</if>
<if test="noticeTitle != null and noticeTitle != ''">
AND sn.notice_title like concat('%', #{noticeTitle}, '%')
</if>
<if test="noticeType != null and noticeType != ''">
AND sn.notice_type = #{noticeType}
</if>
<if test="createBy != null and createBy != ''">
AND sn.create_by like concat('%', #{createBy}, '%')
</if>
</where>
</select>
<select id="noticeList" resultType="com.bonus.material.notice.entity.Notice">
select
@ -74,4 +133,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
(notice_type = 1 and own_co is null) or
(notice_type = 1 and own_co = #{ownCo})
</select>
<select id="getSmsList" resultType="com.bonus.material.notice.entity.Notice">
SELECT
su.user_id as userId,
su.nick_name as userName,
su.phonenumber as phoneNumber
FROM
sys_user su
LEFT JOIN sys_dept sd ON su.dept_id = sd.dept_id
LEFT JOIN sys_user_role sur ON su.user_id = sur.user_id
WHERE
1 = 1
<if test="deptId != null">
and sd.dept_id = #{deptId}
</if>
<if test="roleId != null">
and sur.role_id = #{roleId}
</if>
GROUP BY
su.user_id
</select>
<select id="selectRoleId" resultType="com.bonus.material.notice.entity.Notice">
select role_id as roleId from sys_user_role where user_id = #{userId}
</select>
</mapper>