安全工器具短信推送接口开发
This commit is contained in:
parent
90a7ec357f
commit
9575294561
|
|
@ -926,7 +926,10 @@ public class RepairServiceImpl implements RepairService {
|
|||
}
|
||||
repairApplyRecord.setCreateBy(loginUser.getUsername());
|
||||
repairApplyRecord.setStatus(0L);
|
||||
repairApplyRecord.setRemark(StringUtils.isNotBlank(bean.getInRepairList().get(0).getRemark()) ? bean.getInRepairList().get(0).getRemark() : "");
|
||||
if(bean.getInRepairList()!=null){
|
||||
repairApplyRecord.setRemark(StringUtils.isNotBlank(bean.getInRepairList().get(0).getRemark()) ? bean.getInRepairList().get(0).getRemark() : "");
|
||||
}
|
||||
|
||||
if ((null != partDetails.getId() || null != partDetails.getPartId()) && null != partDetails.getPartNum()) {
|
||||
partDetails.setPartId(null != partDetails.getPartId() ? partDetails.getPartId() : partDetails.getId());
|
||||
// 有维修配件时,如果价格为空,设置为0
|
||||
|
|
|
|||
|
|
@ -0,0 +1,173 @@
|
|||
package com.bonus.material.warning;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.ah.sbd.SmsTool;
|
||||
import com.ah.sbd.utils.param.BatchSmsByContentParam;
|
||||
import com.ah.sbd.utils.param.SmsParam;
|
||||
import com.alibaba.nacos.common.utils.CollectionUtils;
|
||||
import com.bonus.common.biz.constant.BmConfigItems;
|
||||
import com.bonus.common.biz.domain.lease.LeaseApplyInfo;
|
||||
import com.bonus.common.core.utils.StringUtils;
|
||||
import com.bonus.material.back.domain.BackApplyInfo;
|
||||
import com.bonus.material.back.service.IBackApplyInfoService;
|
||||
import com.bonus.material.warningAnalysis.domain.UseMaintenanceWarningBean;
|
||||
import com.bonus.material.warningAnalysis.mapper.UseMaintenanceWarningMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
import org.springframework.scheduling.support.CronTrigger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 任务定时推送相关人员任务控制器
|
||||
* @author ma_sh
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ScheduledCheckWarning {
|
||||
|
||||
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
@Resource
|
||||
private UseMaintenanceWarningMapper mapper;
|
||||
|
||||
@Resource
|
||||
private ScheduledTaskRegistrar scheduledTaskRegistrar;
|
||||
|
||||
/**
|
||||
* 定时任务执行频率,每周三/五天上午9点执行一次
|
||||
*/
|
||||
private String cronExpression = "0 0 9 ? * WED,FRI";
|
||||
|
||||
|
||||
/**
|
||||
* 初始化定时任务
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
cronExpression = getCronFromDatabase();
|
||||
updateCronTask();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新定时任务
|
||||
*/
|
||||
private void updateCronTask() {
|
||||
scheduledTaskRegistrar.getScheduler().schedule(() -> {
|
||||
taskWithFixedRate();
|
||||
}, new CronTrigger(cronExpression));
|
||||
}
|
||||
|
||||
/**
|
||||
* 从数据库中获取 cron 表达式
|
||||
* @return
|
||||
*/
|
||||
private String getCronFromDatabase() {
|
||||
// 这里假设从数据库中获取 cron 表达式
|
||||
//return "0 */1 * * * ?";
|
||||
return "0 0 9 ? * WED,FRI";
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时任务执行频率,每周三/五天上午9点执行一次安全工器具预警短信推送,
|
||||
* 临检30天推送所在工程(项目经理、总工、材料员),频率为每周五进行推送;
|
||||
* 临检15天推送工程所在分公司(施工管理科副科长、分公司分管领导),每周三、五进行推送。
|
||||
* 每三天的上午9点执行
|
||||
*/
|
||||
public void taskWithFixedRate() {
|
||||
log.info("开始执行安全工器具预警短信推送任务");
|
||||
//查询各个工程预警的设备总数,分别推送给各工程负责人
|
||||
|
||||
//截止当天XX工程,速差器、安全带等X件工器具已临检检验有效期30天,请尽快退回机具(物流)分公司复检,明细请登录机具管理系统查看
|
||||
List<UseMaintenanceWarningBean> monthList = mapper.getWarningLastMonthList(new UseMaintenanceWarningBean());
|
||||
// 发送短信
|
||||
try {
|
||||
|
||||
if(monthList !=null && monthList.size()>0){
|
||||
for (UseMaintenanceWarningBean bean : monthList) {
|
||||
//根据皖送平台工程id查询项目经理、总工,获取手机号
|
||||
UseMaintenanceWarningBean projectManager = mapper.getProjectManager(bean);
|
||||
String leaderPhone = projectManager.getLeaderPhone();
|
||||
String engPhone = projectManager.getEngPhone();
|
||||
String content = "截止当天" + bean.getProjectName() +","+ bean.getTypeName() +"共" +bean.getWarnNum() + "件工器具已临检检验有效期30天,请尽快退回机具(物流)分公司复检,明细请登录机具管理系统查看";
|
||||
|
||||
// 省公司短信发送
|
||||
List<String> mobileList = new ArrayList();
|
||||
List<UseMaintenanceWarningBean> userList = mapper.getUserList(bean);
|
||||
|
||||
if(userList !=null && userList.size()>0){
|
||||
for (UseMaintenanceWarningBean item : userList){
|
||||
UseMaintenanceWarningBean item1 = mapper.getUserPhoneById(item);
|
||||
mobileList.add(item1.getClzPhone());
|
||||
}
|
||||
}
|
||||
|
||||
mobileList.add(leaderPhone);
|
||||
mobileList.add(engPhone);
|
||||
if (CollectionUtils.isNotEmpty(mobileList)){
|
||||
JSONObject sendResult = SmsTool.sendSms(new BatchSmsByContentParam(mobileList, content), BmConfigItems.ANHUI_COMPANY_SMS_KEY);
|
||||
if (sendResult != null && !sendResult.isEmpty()) {
|
||||
log.info("短信发送成功: {}", sendResult);
|
||||
System.out.println("短信发送成功: " + sendResult);
|
||||
} else {
|
||||
log.error("短信发送失败,发送结果为空!");
|
||||
System.out.println("短信发送失败,发送结果为空!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//截止当天XX工程,速差器、安全带等X件工器具已临检检验有效期15天,请尽快退回机具(物流)分公司复检,明细请登录机具管理系统查看
|
||||
List<UseMaintenanceWarningBean> dayList = mapper.getWarningLastDayList(new UseMaintenanceWarningBean());
|
||||
if(dayList !=null && dayList.size()>0){
|
||||
for (UseMaintenanceWarningBean bean2 : dayList) {
|
||||
//根据工程所属分公司查询施工管理科副科长、分公司分管领导,获取手机号
|
||||
|
||||
String content2 = "截止当天" + bean2.getProjectName() +","+ bean2.getTypeName() +"共"+ bean2.getWarnNum() + "件工器具已临检检验有效期15天,请尽快退回机具(物流)分公司复检,明细请登录机具管理系统查看";
|
||||
|
||||
// 省公司短信发送
|
||||
List<String> mobileList2 = new ArrayList();
|
||||
List<UseMaintenanceWarningBean> userManger = mapper.getUserManger(bean2);
|
||||
|
||||
if(userManger !=null && userManger.size()>0){
|
||||
for (UseMaintenanceWarningBean item : userManger){
|
||||
UseMaintenanceWarningBean item1 = mapper.getUserPhoneById(item);
|
||||
mobileList2.add(item1.getFkzPhone());
|
||||
}
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(mobileList2)){
|
||||
JSONObject sendResult = SmsTool.sendSms(new BatchSmsByContentParam(mobileList2, content2), BmConfigItems.ANHUI_COMPANY_SMS_KEY);
|
||||
if (sendResult != null && !sendResult.isEmpty()) {
|
||||
log.info("短信发送成功: {}", sendResult);
|
||||
System.out.println("短信发送成功: " + sendResult);
|
||||
} else {
|
||||
log.error("短信发送失败,发送结果为空!");
|
||||
System.out.println("短信发送失败,发送结果为空!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("短信发送过程中发生异常: {}", e.getMessage());
|
||||
System.out.println("短信发送过程中发生异常: " + e.getMessage());
|
||||
}
|
||||
// 记录任务执行时间
|
||||
log.info("执行安全工器具预警短信推送任务执行时间:" + LocalDateTime.now().format(FORMATTER));
|
||||
System.out.println("执行安全工器具预警短信推送任务任务执行时间:" + LocalDateTime.now().format(FORMATTER));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -108,4 +108,22 @@ public class UseMaintenanceWarningBean extends BaseEntity {
|
|||
|
||||
@ApiModelProperty(value = "类型id")
|
||||
private Long typeId;
|
||||
|
||||
@ApiModelProperty(value = "预警数量")
|
||||
private Long warnNum;
|
||||
|
||||
@ApiModelProperty(value = "项目经理手机号")
|
||||
private String leaderPhone;
|
||||
|
||||
@ApiModelProperty(value = "项目总工手机号")
|
||||
private String engPhone;
|
||||
|
||||
@ApiModelProperty(value = "材料员手机号")
|
||||
private String clzPhone;
|
||||
|
||||
@ApiModelProperty(value = "施工管理科副科长")
|
||||
private String fkzPhone;
|
||||
|
||||
@ApiModelProperty(value = "所属分公司")
|
||||
private Long deptId;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,4 +19,16 @@ public interface UseMaintenanceWarningMapper
|
|||
*/
|
||||
public List<UseMaintenanceWarningBean> getList(UseMaintenanceWarningBean bean);
|
||||
|
||||
|
||||
List<UseMaintenanceWarningBean> getWarningLastMonthList(UseMaintenanceWarningBean useMaintenanceWarningBean);
|
||||
|
||||
UseMaintenanceWarningBean getProjectManager(UseMaintenanceWarningBean bean);
|
||||
|
||||
List<UseMaintenanceWarningBean> getUserList(UseMaintenanceWarningBean bean);
|
||||
|
||||
UseMaintenanceWarningBean getUserPhoneById(UseMaintenanceWarningBean item);
|
||||
|
||||
List<UseMaintenanceWarningBean> getWarningLastDayList(UseMaintenanceWarningBean useMaintenanceWarningBean);
|
||||
|
||||
List<UseMaintenanceWarningBean> getUserManger(UseMaintenanceWarningBean bean);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
AND bp.del_flag = '0'
|
||||
LEFT JOIN sys_dept sd on sd.dept_id = bp.imp_unit
|
||||
WHERE
|
||||
mm.ma_status='2'
|
||||
mm.ma_status='2' and sai.is_slt = 0
|
||||
and bp.pro_name is not null
|
||||
AND mm.next_check_time BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 1 MONTH)
|
||||
<if test="keyWord != null and keyWord != ''">
|
||||
|
|
@ -59,4 +59,144 @@
|
|||
ORDER BY mm.next_check_time ASC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
|
||||
<select id="getWarningLastMonthList"
|
||||
resultType="com.bonus.material.warningAnalysis.domain.UseMaintenanceWarningBean">
|
||||
|
||||
|
||||
|
||||
SELECT
|
||||
proId as projectId,
|
||||
projectName,
|
||||
GROUP_CONCAT(DISTINCT typeName) as typeName ,
|
||||
COUNT(DISTINCT maId) as warnNum
|
||||
FROM
|
||||
(
|
||||
|
||||
SELECT
|
||||
bp.external_id as proId,
|
||||
mm.ma_id as maId,
|
||||
mm.next_check_time as nextCheckTime,
|
||||
mt3.type_name as materialType,
|
||||
mt2.type_name as typeName,
|
||||
mt.type_name as typeModelName,
|
||||
mm.ma_code as maCode,
|
||||
bu.unit_name as unitName,
|
||||
bp.pro_name as projectName,
|
||||
DATEDIFF(mm.next_check_time, CURDATE()) AS overDays
|
||||
FROM
|
||||
ma_machine mm
|
||||
LEFT JOIN ma_type mt on mt.type_id=mm.type_id
|
||||
LEFT JOIN ma_type mt2 on mt2.type_id=mt.parent_id
|
||||
LEFT JOIN ma_type mt3 on mt3.type_id=mt2.parent_id
|
||||
LEFT JOIN ma_type mt4 on mt4.type_id=mt3.parent_id
|
||||
LEFT JOIN slt_agreement_info sai on sai.ma_id=mm.ma_id and mm.type_id=sai.type_id
|
||||
LEFT JOIN bm_agreement_info bai on bai.agreement_id=sai.agreement_id
|
||||
LEFT JOIN bm_unit bu ON bai.unit_id = bu.unit_id
|
||||
AND bu.del_flag = '0'
|
||||
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
|
||||
AND bp.del_flag = '0'
|
||||
LEFT JOIN sys_dept sd on sd.dept_id = bp.imp_unit
|
||||
WHERE
|
||||
sai.`status` = 0 and sai.is_slt = 0 and
|
||||
mm.ma_status='2'
|
||||
and bp.external_id is not null
|
||||
AND mt.jiju_type =2
|
||||
AND mm.next_check_time BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 1 MONTH)
|
||||
) res
|
||||
GROUP BY proId
|
||||
|
||||
</select>
|
||||
|
||||
<select id="getProjectManager" resultType="com.bonus.material.warningAnalysis.domain.UseMaintenanceWarningBean">
|
||||
|
||||
SELECT
|
||||
dc.id as projectId,
|
||||
du1.mobile as leaderPhone,
|
||||
du2.mobile as engPhone
|
||||
FROM
|
||||
`data_center`.dx_fb_son dc
|
||||
LEFT JOIN `data_center`.dc_user du1 ON dc.project_leader_id = du1.id
|
||||
LEFT JOIN `data_center`.dc_user du2 ON dc.project_engineer_id = du2.id
|
||||
WHERE dc.id = #{projectId}
|
||||
</select>
|
||||
|
||||
<select id="getUserList" resultType="com.bonus.material.warningAnalysis.domain.UseMaintenanceWarningBean">
|
||||
SELECT
|
||||
sgp.cno
|
||||
FROM
|
||||
bm_project bp
|
||||
LEFT JOIN `data_center`.dx_fb_son dfs on bp.external_id = dfs.id
|
||||
LEFT JOIN `sbd_audit`.sg_project_post_personnel sgp on sgp.depart_id = dfs.project_dept_id
|
||||
|
||||
WHERE sgp.post_id = '3de0eb390f3611efa1940242ac130004'
|
||||
|
||||
AND bp.pro_id = #{leaseProjectId}
|
||||
</select>
|
||||
|
||||
<select id="getUserPhoneById" resultType="com.bonus.material.warningAnalysis.domain.UseMaintenanceWarningBean">
|
||||
select
|
||||
user_id,
|
||||
phonenumber AS clzPhone
|
||||
from
|
||||
sys_user
|
||||
where user_name = #{cno}
|
||||
</select>
|
||||
|
||||
<select id="getWarningLastDayList" resultType="com.bonus.material.warningAnalysis.domain.UseMaintenanceWarningBean">
|
||||
|
||||
SELECT
|
||||
proId as projectId,
|
||||
deptId,
|
||||
projectName,
|
||||
GROUP_CONCAT(DISTINCT typeName) as typeName ,
|
||||
COUNT(DISTINCT maId) as warnNum
|
||||
FROM
|
||||
(
|
||||
|
||||
SELECT
|
||||
bp.external_id as proId,
|
||||
bp.imp_unit as deptId,
|
||||
mm.ma_id as maId,
|
||||
mm.next_check_time as nextCheckTime,
|
||||
mt3.type_name as materialType,
|
||||
mt2.type_name as typeName,
|
||||
mt.type_name as typeModelName,
|
||||
mm.ma_code as maCode,
|
||||
bu.unit_name as unitName,
|
||||
bp.pro_name as projectName,
|
||||
DATEDIFF(mm.next_check_time, CURDATE()) AS overDays
|
||||
FROM
|
||||
ma_machine mm
|
||||
LEFT JOIN ma_type mt on mt.type_id=mm.type_id
|
||||
LEFT JOIN ma_type mt2 on mt2.type_id=mt.parent_id
|
||||
LEFT JOIN ma_type mt3 on mt3.type_id=mt2.parent_id
|
||||
LEFT JOIN ma_type mt4 on mt4.type_id=mt3.parent_id
|
||||
LEFT JOIN slt_agreement_info sai on sai.ma_id=mm.ma_id and mm.type_id=sai.type_id
|
||||
LEFT JOIN bm_agreement_info bai on bai.agreement_id=sai.agreement_id
|
||||
LEFT JOIN bm_unit bu ON bai.unit_id = bu.unit_id
|
||||
AND bu.del_flag = '0'
|
||||
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
|
||||
AND bp.del_flag = '0'
|
||||
LEFT JOIN sys_dept sd on sd.dept_id = bp.imp_unit
|
||||
WHERE
|
||||
sai.`status` = 0 and sai.is_slt = 0 and
|
||||
mm.ma_status='2'
|
||||
and bp.external_id is not null
|
||||
AND mt.jiju_type =2
|
||||
AND mm.next_check_time BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 15 day)
|
||||
) res
|
||||
GROUP BY proId
|
||||
</select>
|
||||
|
||||
<select id="getUserManger" resultType="com.bonus.material.warningAnalysis.domain.UseMaintenanceWarningBean">
|
||||
SELECT
|
||||
su.user_id,
|
||||
su.phonenumber
|
||||
FROM
|
||||
sys_user su
|
||||
LEFT JOIN sys_user_role sr on su.user_id = sr.user_id
|
||||
WHERE sr.role_id in (59,81) and dept_id =#{deptId}
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue