|
|
|
@ -1,7 +1,10 @@
|
|
|
|
|
package com.hnac.hzims.message.service.impl; |
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.hnac.hzims.message.MessageConstants; |
|
|
|
|
import com.hnac.hzims.message.config.MessageFactory; |
|
|
|
|
import com.hnac.hzims.message.entity.MessagePushRecordEntity; |
|
|
|
|
import com.hnac.hzims.message.enums.PushStatEnum; |
|
|
|
@ -11,12 +14,16 @@ import com.hnac.hzims.message.service.IMessageService;
|
|
|
|
|
import com.hnac.hzims.message.vo.msgpushrecord.*; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
|
import org.springblade.core.mp.support.Condition; |
|
|
|
|
import org.springblade.core.mp.support.Query; |
|
|
|
|
import org.springblade.core.tool.utils.Func; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.time.YearMonth; |
|
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
@ -39,25 +46,62 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRec
|
|
|
|
|
return this.page(Condition.getPage(query), this.getQueryWrapper(request)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Boolean send(String id) { |
|
|
|
|
MessagePushRecordEntity record = this.getById(id); |
|
|
|
|
IMessageService messageSend = MessageFactory.getMessageSend(record.getType()); |
|
|
|
|
return messageSend.send(record); |
|
|
|
|
} |
|
|
|
|
@Override |
|
|
|
|
public Boolean send(Long id) { |
|
|
|
|
MessagePushRecordEntity record = this.getById(id); |
|
|
|
|
IMessageService messageSend = MessageFactory.getMessageSend(record.getType()); |
|
|
|
|
Boolean result = messageSend.send(record); |
|
|
|
|
Assert.isTrue(result , ()-> { |
|
|
|
|
throw new ServiceException("发送消息失败!"); |
|
|
|
|
}); |
|
|
|
|
// 更新推送状态以及推送时间
|
|
|
|
|
LambdaUpdateWrapper<MessagePushRecordEntity> luw = Wrappers.<MessagePushRecordEntity>lambdaUpdate() |
|
|
|
|
.set(MessagePushRecordEntity::getPushTime, LocalDateTime.now()) |
|
|
|
|
.set(MessagePushRecordEntity::getStatus, MessageConstants.PUSH_SUCCESS) |
|
|
|
|
.eq(MessagePushRecordEntity::getId, id); |
|
|
|
|
return this.update(luw); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public Boolean saveAndSend(MessagePushRecordEntity request) { |
|
|
|
|
if(Func.isEmpty(request.getPlanTime())) { |
|
|
|
|
request.setPlanTime(LocalDateTime.now()); |
|
|
|
|
} |
|
|
|
|
if(this.save(request) && Func.isNotEmpty(request.getId())) { |
|
|
|
|
return this.send(request.getId()); |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取 QueryWrapper |
|
|
|
|
* @param request 查询条件 |
|
|
|
|
* @return QueryWrapper |
|
|
|
|
*/ |
|
|
|
|
private LambdaQueryWrapper<MessagePushRecordEntity> getQueryWrapper(MessagePushRecordEntity request) { |
|
|
|
|
LambdaQueryWrapper<MessagePushRecordEntity> lambda = Condition.getQueryWrapper(request).lambda(); |
|
|
|
|
if(Func.isNotEmpty(request.getStartTime())) { |
|
|
|
|
lambda.ge(MessagePushRecordEntity::getPushTime,request.getStartTime()); |
|
|
|
|
} |
|
|
|
|
if(Func.isNotEmpty(request.getEndTime())) { |
|
|
|
|
lambda.le(MessagePushRecordEntity::getPushTime,request.getEndTime()); |
|
|
|
|
} |
|
|
|
|
lambda.orderByDesc(MessagePushRecordEntity::getPushTime); |
|
|
|
|
return lambda; |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 短信推送统计 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public List<MessagePushRecordTypeVo> smsPushStat() { |
|
|
|
|
public List<MessagePushRecordTypeVo> smsPushStat(MessagePushRecordEntityVo vo) { |
|
|
|
|
//根据type统计数量
|
|
|
|
|
List<MessagePushRecordVo> messagePushRecordVos = baseMapper.smsPushStat(); |
|
|
|
|
List<MessagePushRecordVo> messagePushRecordVos = baseMapper.smsPushStat(vo); |
|
|
|
|
messagePushRecordVos.forEach(item -> { |
|
|
|
|
String strMonth = item.getStrMonth(); |
|
|
|
|
YearMonth strMonth = item.getStrMonth(); |
|
|
|
|
// 字符串转localDate 获取月份
|
|
|
|
|
int month = this.getCurrentMonth(strMonth); |
|
|
|
|
item.setMonth(month); |
|
|
|
|
item.setMonth(strMonth.getMonthValue()); |
|
|
|
|
item.setYear(strMonth.getYear()); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
//按类型分组
|
|
|
|
@ -81,8 +125,8 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRec
|
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public List<BusinessTypeStatVo> businessTypeStat() { |
|
|
|
|
List<BusinessTypeStatVo> businessTypeStatVos = baseMapper.businessTypeStat(); |
|
|
|
|
public List<BusinessTypeStatVo> businessTypeStat(MessagePushRecordEntityVo vo) { |
|
|
|
|
List<BusinessTypeStatVo> businessTypeStatVos = baseMapper.businessTypeStat(vo); |
|
|
|
|
businessTypeStatVos.forEach(item -> { |
|
|
|
|
String businessClassifyByName = this.getBusinessClassifyByName(item.getBusinessClassify()); |
|
|
|
|
item.setBusinessClassifyName(businessClassifyByName); |
|
|
|
@ -96,8 +140,8 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRec
|
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public List<UserPushStatTypeVo> userPushStat() { |
|
|
|
|
List<UserPushStatTypeVo> userPushStatTypeVos = baseMapper.userPushStat(); |
|
|
|
|
public List<UserPushStatTypeVo> userPushStat(MessagePushRecordEntityVo vo) { |
|
|
|
|
List<UserPushStatTypeVo> userPushStatTypeVos = baseMapper.userPushStat(vo); |
|
|
|
|
//添加业务类型名称
|
|
|
|
|
userPushStatTypeVos.forEach(item -> { |
|
|
|
|
List<UserPushStatVo> pushStatList = item.getPushStatList(); |
|
|
|
@ -117,8 +161,8 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRec
|
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public List<PushStatTypeVo> pushStat() { |
|
|
|
|
List<PushStatTypeVo> pushStatTypeVos = baseMapper.pushStat(); |
|
|
|
|
public List<PushStatTypeVo> pushStat(MessagePushRecordEntityVo vo) { |
|
|
|
|
List<PushStatTypeVo> pushStatTypeVos = baseMapper.pushStat(vo); |
|
|
|
|
pushStatTypeVos.forEach(item -> { |
|
|
|
|
//业务类型名称
|
|
|
|
|
String businessClassify = item.getBusinessClassify(); |
|
|
|
@ -141,21 +185,6 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRec
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取 QueryWrapper |
|
|
|
|
* |
|
|
|
|
* @param request 查询条件 |
|
|
|
|
* @return QueryWrapper |
|
|
|
|
*/ |
|
|
|
|
private LambdaQueryWrapper<MessagePushRecordEntity> getQueryWrapper(MessagePushRecordEntity request) { |
|
|
|
|
LambdaQueryWrapper<MessagePushRecordEntity> lambda = Condition.getQueryWrapper(request).lambda(); |
|
|
|
|
if (Func.isNotEmpty(request.getStatus())) { |
|
|
|
|
lambda.eq(MessagePushRecordEntity::getStatus, request.getStatus()); |
|
|
|
|
} |
|
|
|
|
return lambda; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 状态 ===> 状态名称 |
|
|
|
|
* |
|
|
|
|
* @param key 状态 |
|
|
|
@ -220,8 +249,8 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRec
|
|
|
|
|
//获取年月
|
|
|
|
|
YearMonth yearMonth = YearMonth.parse(strMonth, dateTimeFormatter); |
|
|
|
|
//减去3个月
|
|
|
|
|
YearMonth month = yearMonth.minusMonths(3); |
|
|
|
|
return month.getMonthValue(); |
|
|
|
|
//YearMonth month = yearMonth.minusMonths(3);
|
|
|
|
|
return yearMonth.getMonthValue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|