消息推送修改

This commit is contained in:
zhangheng 2024-07-31 14:10:09 +08:00
parent 46f2696f05
commit a8050ed6fe
5 changed files with 71 additions and 4 deletions

View File

@ -101,7 +101,7 @@ public class SubscribeMessageSendRecord extends BaseEntity {
* 推送结果状态码0表示成功 * 推送结果状态码0表示成功
*/ */
@ApiModelProperty(value = "推送结果状态码") @ApiModelProperty(value = "推送结果状态码")
@Excel(name = "推送结果状态码", readConverterExp = "0=表示成功") @Excel(name = "推送结果状态码", readConverterExp = "0表示成功")
private Integer errorCode; private Integer errorCode;
/** /**

View File

@ -1,6 +1,8 @@
package com.xinelu.manage.mapper.subscribemessagesendrecord; package com.xinelu.manage.mapper.subscribemessagesendrecord;
import com.xinelu.manage.domain.subscribemessagesendrecord.SubscribeMessageSendRecord; import com.xinelu.manage.domain.subscribemessagesendrecord.SubscribeMessageSendRecord;
import com.xinelu.manage.vo.subscribemessagesendrecord.RecordNum;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
@ -66,4 +68,12 @@ public interface SubscribeMessageSendRecordMapper {
* @return int * @return int
**/ **/
int insertSubscribeMessageSendRecordList(List<SubscribeMessageSendRecord> subscribeMessageSendRecordList); int insertSubscribeMessageSendRecordList(List<SubscribeMessageSendRecord> subscribeMessageSendRecordList);
/**
* 节点推送数量
*
* @param manageRouteNodeIds 节点id
* @return RecordNum
*/
List<RecordNum> selectRecordCountByManageRouteNodeIds(@Param("manageRouteNodeIds") List<Long> manageRouteNodeIds);
} }

View File

@ -0,0 +1,23 @@
package com.xinelu.manage.vo.subscribemessagesendrecord;
import lombok.Data;
/**
* 微信小程序订阅消息发送结果记录数量
*
* @author zh
* @date 2024-07-31
*/
@Data
public class RecordNum {
/*
*推送数量
*/
private Long num;
/**
* 节点id
*/
private Long manageRouteNodeId;
}

View File

@ -231,4 +231,17 @@
) )
</foreach> </foreach>
</insert> </insert>
<select id="selectRecordCountByManageRouteNodeIds"
resultType="com.xinelu.manage.vo.subscribemessagesendrecord.RecordNum">
select
manage_route_node_id,
COUNT(1) num
from subscribe_message_send_record
where manage_route_node_id IN
<foreach item="manageRouteNodeId" collection="manageRouteNodeId" open="(" separator="," close=")">
#{manageRouteNodeId}
</foreach>
</select>
</mapper> </mapper>

View File

@ -6,6 +6,7 @@ import com.xinelu.common.enums.*;
import com.xinelu.common.utils.SecurityUtils; import com.xinelu.common.utils.SecurityUtils;
import com.xinelu.manage.domain.subscribemessagesendrecord.SubscribeMessageSendRecord; import com.xinelu.manage.domain.subscribemessagesendrecord.SubscribeMessageSendRecord;
import com.xinelu.manage.mapper.subscribemessagesendrecord.SubscribeMessageSendRecordMapper; import com.xinelu.manage.mapper.subscribemessagesendrecord.SubscribeMessageSendRecordMapper;
import com.xinelu.manage.vo.subscribemessagesendrecord.RecordNum;
import com.xinelu.mobile.domain.TemplateContent; import com.xinelu.mobile.domain.TemplateContent;
import com.xinelu.mobile.mapper.homepage.HomePageMapper; import com.xinelu.mobile.mapper.homepage.HomePageMapper;
import com.xinelu.mobile.utils.WeChatOfficialAccountUtils; import com.xinelu.mobile.utils.WeChatOfficialAccountUtils;
@ -53,6 +54,9 @@ public class subscribeTaskServiceImpl implements SubscribeTaskService {
} }
// 患者节点表 // 患者节点表
List<PatientVO> signPatientManageRouteNodes = homePageMapper.selectSignPatientManageRouteNode(patientIdList); List<PatientVO> signPatientManageRouteNodes = homePageMapper.selectSignPatientManageRouteNode(patientIdList);
if (CollectionUtils.isEmpty(signPatientManageRouteNodes)) {
return;
}
// PatientVO 包含签约路径节点相关属性后面用于推送消息 // PatientVO 包含签约路径节点相关属性后面用于推送消息
List<PatientVO> patientVOList = new ArrayList<>(); List<PatientVO> patientVOList = new ArrayList<>();
//发送消息到期节点id集合 //发送消息到期节点id集合
@ -138,11 +142,19 @@ public class subscribeTaskServiceImpl implements SubscribeTaskService {
// } // }
// } // }
// } // }
//发送 if (CollectionUtils.isEmpty(patientVOList)) {
//发送失败id集合 return;
}
//节点推送数量
List<Long> collect = patientVOList.stream().filter(Objects::nonNull).map(PatientVO::getSignPatientManageRouteNodeId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
List<RecordNum> recordNums = subscribeMessageSendRecordMapper.selectRecordCountByManageRouteNodeIds(collect);
//发送成功id集合
List<Long> signPatientManageRouteNodeIds = new ArrayList<>(); List<Long> signPatientManageRouteNodeIds = new ArrayList<>();
//发送失败
List<Long> failSignPatientManageRouteNodeIds = new ArrayList<>();
for (PatientVO patientVO : patientVOList) { for (PatientVO patientVO : patientVOList) {
try { try {
//判断推送内容格式是否符合
JSON.parseArray(patientVO.getAppletNodeContent(), TemplateContent.class); JSON.parseArray(patientVO.getAppletNodeContent(), TemplateContent.class);
} catch (Exception e) { } catch (Exception e) {
continue; continue;
@ -150,13 +162,18 @@ public class subscribeTaskServiceImpl implements SubscribeTaskService {
// 开始推送消息 // 开始推送消息
Integer integer = weChatOfficialAccountUtils.sendAppletTemplateMessage(patientVO); Integer integer = weChatOfficialAccountUtils.sendAppletTemplateMessage(patientVO);
SubscribeMessageSendRecord subscribeMessageSendRecord = new SubscribeMessageSendRecord(); SubscribeMessageSendRecord subscribeMessageSendRecord = new SubscribeMessageSendRecord();
//推送结果
if (integer == 0) { if (integer == 0) {
signPatientManageRouteNodeIds.add(patientVO.getSignPatientManageRouteNodeId()); signPatientManageRouteNodeIds.add(patientVO.getSignPatientManageRouteNodeId());
subscribeMessageSendRecord.setErrorCode(0); subscribeMessageSendRecord.setErrorCode(0);
subscribeMessageSendRecord.setErrorStatus(ErrorStatusEnum.success.getValue()); subscribeMessageSendRecord.setErrorStatus(ErrorStatusEnum.success.getValue());
} else { } else {
subscribeMessageSendRecord.setErrorCode(1); subscribeMessageSendRecord.setErrorCode(integer);
subscribeMessageSendRecord.setErrorStatus(ErrorStatusEnum.fail.getValue()); subscribeMessageSendRecord.setErrorStatus(ErrorStatusEnum.fail.getValue());
RecordNum recordNum = recordNums.stream().filter(Objects::nonNull).filter(item -> Objects.nonNull(item.getManageRouteNodeId()) && item.getManageRouteNodeId().equals(patientVO.getSignPatientManageRouteNodeId())).findFirst().orElse(new RecordNum());
if (Objects.nonNull(recordNum.getNum()) && recordNum.getNum() >= 2) {
failSignPatientManageRouteNodeIds.add(patientVO.getSignPatientManageRouteNodeId());
}
} }
subscribeMessageSendRecord.setPatientId(patientVO.getPatientId()); subscribeMessageSendRecord.setPatientId(patientVO.getPatientId());
subscribeMessageSendRecord.setManageRouteNodeId(patientVO.getSignPatientManageRouteNodeId()); subscribeMessageSendRecord.setManageRouteNodeId(patientVO.getSignPatientManageRouteNodeId());
@ -172,5 +189,9 @@ public class subscribeTaskServiceImpl implements SubscribeTaskService {
if (CollectionUtils.isNotEmpty(signPatientManageRouteNodeIds)) { if (CollectionUtils.isNotEmpty(signPatientManageRouteNodeIds)) {
homePageMapper.updateNodeExecuteStatusByIds(signPatientManageRouteNodeIds, NodeExecuteStatusEnum.EXECUTED.getInfo(), NodeExecuteResultStatusEnum.SUCCESS.getInfo()); homePageMapper.updateNodeExecuteStatusByIds(signPatientManageRouteNodeIds, NodeExecuteStatusEnum.EXECUTED.getInfo(), NodeExecuteResultStatusEnum.SUCCESS.getInfo());
} }
//更改失败执行状态
if (CollectionUtils.isNotEmpty(failSignPatientManageRouteNodeIds)) {
homePageMapper.updateNodeExecuteStatusByIds(failSignPatientManageRouteNodeIds, NodeExecuteStatusEnum.EXECUTED.getInfo(), NodeExecuteResultStatusEnum.FAILURE.getInfo());
}
} }
} }