新增消息企业交易修改状态
This commit is contained in:
parent
36ae695fe1
commit
54e3900797
@ -0,0 +1,103 @@
|
||||
package cn.axzo.msg.center.inside.notices.service.impl;
|
||||
|
||||
import cn.axzo.basics.common.exception.ServiceException;
|
||||
import cn.axzo.msg.center.api.InsideMessageBusinessApi;
|
||||
import cn.axzo.msg.center.api.enums.MsgStateEnum;
|
||||
import cn.axzo.msg.center.api.response.RelationRes;
|
||||
import cn.axzo.msg.center.api.response.TemplateRes;
|
||||
import cn.axzo.msg.center.common.utils.CustomBeanUtils;
|
||||
import cn.axzo.msg.center.domain.entity.MessageRelation;
|
||||
import cn.axzo.msg.center.domain.entity.MessageTemplate;
|
||||
import cn.axzo.msg.center.inside.notices.service.MessageRecordService;
|
||||
import cn.axzo.msg.center.inside.notices.service.MessageRelationService;
|
||||
import cn.axzo.msg.center.inside.notices.service.MessageTemplateService;
|
||||
import cn.azxo.framework.common.model.CommonResponse;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class InsideMessageBusinessApiImpl implements InsideMessageBusinessApi {
|
||||
|
||||
@Resource
|
||||
private MessageRecordService messageRecordService;
|
||||
@Resource
|
||||
private MessageTemplateService messageTemplateService;
|
||||
@Resource
|
||||
private MessageRelationService messageRelationService;
|
||||
|
||||
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(
|
||||
"yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
|
||||
@Override
|
||||
public CommonResponse<Boolean> changeMessageState(List<Long> msgIds, Integer state) {
|
||||
if (CollectionUtils.isEmpty(msgIds)) {
|
||||
throw new ServiceException("msgIds 不能为空");
|
||||
}
|
||||
MsgStateEnum stateEnum = MsgStateEnum.getByCode(state);
|
||||
Boolean aBoolean = messageRecordService.changeMessageState(msgIds, stateEnum);
|
||||
return CommonResponse.success(aBoolean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResponse<Boolean> changeMessageState(Long toId, Long relationId, Long bizId, Integer state) {
|
||||
log.info("修改消息状态入参: toId:{}, relationId: {}, bizId: {}, state: {}", toId, relationId,
|
||||
bizId, state);
|
||||
if (Objects.isNull(toId) || Objects.isNull(relationId) || Objects.isNull(bizId)) {
|
||||
log.warn("缺失必要参数");
|
||||
throw new ServiceException("修改消息状态失败,缺失必要参数");
|
||||
}
|
||||
MsgStateEnum code = MsgStateEnum.getByCode(state);
|
||||
if (Objects.isNull(code)) {
|
||||
throw new ServiceException("非法消息状态");
|
||||
}
|
||||
try {
|
||||
return CommonResponse.success(messageRecordService.changeMessageState(toId, relationId, bizId, code));
|
||||
}catch (IllegalStateException e){
|
||||
// 由于 starter 内部判断重试有结合code,所以这里统一返回 200 的状态码
|
||||
return CommonResponse.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResponse<List<TemplateRes>> getTemplates(String lastUpdate) {
|
||||
log.info("获取模板列表: {}", lastUpdate);
|
||||
List<TemplateRes> result;
|
||||
if (!messageTemplateService.hasTemplateGtUpdateAt(LocalDateTime.parse(lastUpdate, formatter))) {
|
||||
result = Lists.newArrayList();
|
||||
} else {
|
||||
List<MessageTemplate> templates = messageTemplateService.getAllTemplates();
|
||||
if (CollectionUtils.isEmpty(templates)) {
|
||||
result = Lists.newArrayList();
|
||||
} else {
|
||||
result = CustomBeanUtils.copyListProperties(templates, TemplateRes::new);
|
||||
}
|
||||
}
|
||||
return CommonResponse.success(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResponse<List<RelationRes>> getRelations(String lastUpdate) {
|
||||
List<RelationRes> result;
|
||||
if (!messageRelationService.hasRelationGtUpdateAt(LocalDateTime.parse(lastUpdate, formatter))) {
|
||||
result = Lists.newArrayList();
|
||||
} else {
|
||||
List<MessageRelation> relations = messageRelationService.getAllRelations();
|
||||
if (CollectionUtils.isEmpty(relations)) {
|
||||
result = Lists.newArrayList();
|
||||
} else {
|
||||
result = CustomBeanUtils.copyListProperties(relations, RelationRes::new);
|
||||
}
|
||||
}
|
||||
return CommonResponse.success(result);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
package cn.axzo.msg.center.api;
|
||||
|
||||
import cn.axzo.msg.center.api.response.RelationRes;
|
||||
import cn.axzo.msg.center.api.response.TemplateRes;
|
||||
import cn.azxo.framework.common.model.CommonResponse;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface InsideMessageBusinessApi {
|
||||
|
||||
/**
|
||||
* 变更执行消息的状态
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("api/message/state/change")
|
||||
CommonResponse<Boolean> changeMessageState(@RequestParam(value = "msgIds") List<Long> msgIds,
|
||||
@RequestParam(value = "state") Integer state);
|
||||
|
||||
|
||||
@PostMapping("api/message/state/change4Biz")
|
||||
CommonResponse<Boolean> changeMessageState(@RequestParam(value = "toId") Long toId,
|
||||
@RequestParam(value = "relationId") Long relationId,
|
||||
@RequestParam(value = "bizId") Long bizId,
|
||||
@RequestParam(value = "state") Integer state);
|
||||
/**
|
||||
* 获取所有模板数据集合
|
||||
*
|
||||
* @return 模板信息集合
|
||||
*/
|
||||
@GetMapping("api/message/templates/{time}")
|
||||
CommonResponse<List<TemplateRes>> getTemplates(
|
||||
@PathVariable("time") String lastUpdate);
|
||||
|
||||
|
||||
/**
|
||||
* 获取所有的模块与模板的关系数据集合
|
||||
*
|
||||
* @return 模块与模板关系集合
|
||||
*/
|
||||
@GetMapping("api/message/relations{time}")
|
||||
CommonResponse<List<RelationRes>> getRelations(
|
||||
@PathVariable("time") String lastUpdate);
|
||||
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
package cn.axzo.msg.center.api.fallback;
|
||||
|
||||
import cn.axzo.msg.center.api.InsideMessageBusinessApi;
|
||||
import cn.axzo.msg.center.api.response.RelationRes;
|
||||
import cn.axzo.msg.center.api.response.TemplateRes;
|
||||
import cn.azxo.framework.common.model.CommonResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class InsideMessageBusinessServiceFallBack implements InsideMessageBusinessApi {
|
||||
@Override
|
||||
public CommonResponse<Boolean> changeMessageState(List<Long> msgIds, Integer state) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResponse<Boolean> changeMessageState(Long toId, Long relationId, Long bizId, Integer state) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResponse<List<TemplateRes>> getTemplates(String lastUpdate) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResponse<List<RelationRes>> getRelations(String lastUpdate) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
package cn.axzo.msg.center.api.response;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author: wangli
|
||||
* @date: 2022/3/24 16:09
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class RelationRes {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* TypeId 原始消息配置
|
||||
*/
|
||||
private Integer typeId;
|
||||
|
||||
/**
|
||||
* 模块 ID
|
||||
*/
|
||||
private Long moduleId;
|
||||
|
||||
/**
|
||||
* 模板 ID
|
||||
*/
|
||||
private Long templateId;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateAt;
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
package cn.axzo.msg.center.api.response;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 消息模板内容定义
|
||||
*
|
||||
* @author: wangli
|
||||
* @date: 2022/3/21 14:45
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class TemplateRes {
|
||||
|
||||
/**
|
||||
* 消息模板主键ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 关联的音频文件名称
|
||||
*/
|
||||
private String audioFileName;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateAt;
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user