Commit 2a61f141 by liangkaiping

copy

parent 4ecb777c
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.yizhi</groupId>
<artifactId>cloud-newMessage</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.yizhi</groupId>
<artifactId>cloud-newMessage-api</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-util</artifactId>
<scope>provided</scope>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-orm</artifactId>
<scope>provided</scope>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-common-api</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-core</artifactId>
<scope>provided</scope>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.yizhi.message.application.constans;
public interface Constans {
/**
* 未删除
*/
public static final Integer NOT_DELETED = 0;
/**
* 已删除
*/
public static final Integer DELETED = 1;
/**
* 平台可见
*/
public static final Integer PUBLIC_SITE = 0;
/**
* 指定范围
*/
public static final Integer VISIBLE_RANGE = 1;
/**
* job的Group
*/
public static final String JOBGROUP = "newMessage";
/**
* 部门类型
*/
public static final Integer ORG = 1;
/**
* 用户类型
*/
public static final Integer ACCOUNT = 2;
/**
* 已读
*/
public static final Integer READED = 1;
/**
* 未读
*/
public static final Integer NOT_READ = 0;
public static final String MESSAGE_QUEUE = "newMessage";
}
package com.yizhi.message.application.enums;
import java.util.Arrays;
import java.util.List;
/**
*
*/
public enum EvenType {
COURSE_UP(1L,Arrays.asList(1,2)),//"课程上架通知"
COURSE_FINISH(2L, Arrays.asList(1,2)),//课程完成通知
ENROLL_START(3L, Arrays.asList(1,3,4,5)),//报名开始
TRAINING_AUDIT_PASS(4L, Arrays.asList(1,3,4,5)),//项目审核通过通知
TRAINING_AUDIT_FAIL(5L, Arrays.asList(1,3,4,5)),//项目审核不通过通知
SIGN_SUCCESS(6L, Arrays.asList(1,3,4,5)),//签到成功通知
TRAINING_FINISH(7L, Arrays.asList(1,3,4,5)),//项目完成通知
ASSIGNMENT_AUDIT_FINISH(8L, Arrays.asList(1,6,7,8)),//作业已被批阅通知
EXAM_AUDIT_FINISH(9L, Arrays.asList(1,9,10,11)),//考试已被批阅通知
POINT_CHANGE(10L, Arrays.asList(1,12,13,14));//积分变动原因
//数据库message表的id
private Long key;
//数据库message_parameter表的field_type
private List<Integer> fieldType;
private EvenType(Long key, List<Integer> fieldType) {
this.key = key;
this.fieldType = fieldType;
}
public Long getKey() {
return key;
}
public List<Integer> getName() {
return fieldType;
}
}
package com.yizhi.message.application.enums;
public enum MessageParameterEnums {
accountName(1,"【accountName】"),
courseName(2,"【courseName】"),
projectTime(3,"【projectTime】"),
projectName(4,"【projectName】"),
enrollEndTime(5,"【enrollEndTime】"),
assignmentName(6,"【assignmentName】"),
assignmentTime(7,"【assignmentTime】"),
assignmentScore(8,"【assignmentScore】"),
examName(9,"【examName】"),
examTime(10,"【examTime】"),
examScore(11,"【examScore】"),
changeReason(12,"【changeReason】"),
changePoint(13,"【changePoint】"),
changeTime(14,"【changeTime】"),
researchTime(15,"【researchTime】"),
researchName(16,"【researchName】"),
liveTime(17,"【liveTime】");
private Integer code;
private String name;
MessageParameterEnums(Integer code, String name) {
this.code = code;
this.name = name;
}
public Integer getCode() {
return code;
}
public String getName() {
return name;
}
}
package com.yizhi.message.application.enums;
public enum MessageStatus {
DRAFT(1,"草稿"),
TO_SEND(2,"待发送"),
SEND_ING(3,"发送中"),
SEND_ED(4,"已发送"),
DOWN(6,"下架"),
UP(7,"上架"),
SEND_ED_CANCEl(8,"已发送被撤回");
private Integer code;
private String name;
MessageStatus(Integer code, String name) {
this.code = code;
this.name = name;
}
public Integer getCode() {
return code;
}
public String getName() {
return name;
}
}
package com.yizhi.message.application.enums;
import org.springframework.stereotype.Component;
/**
* 应用场景或者是活动名称的枚举类
*/
public enum RelationType {
ZDY(0,"自定义消息"),
XX(1,"学习计划"),
KS(2,"考试"),
DY(3,"调研"),
TP(4,"投票"),
BM(5,"报名"),
ZY(6,"作业"),
QD(7,"签到"),
XM(8,"项目"),
ZB(9,"直播"),
JF(10,"积分"),
KC(11,"课程");
private Integer key;
private String name;
private RelationType(Integer key, String name){
this.key = key;
this.name = name;
}
public Integer getKey() {
return key;
}
public String getName() {
return name;
}
}
package com.yizhi.message.application.enums;
public enum ReturnParameterEnums {
accountName("【用户名】","【accountName】"),
courseName("【课程名称】","【courseName】"),
projectTime("【项目时间】","【projectTime】"),
projectName("【项目名称】","【projectName】"),
enrollEndTime("【报名截止时间】","【enrollEndTime】"),
assignmentName("【作业名称】","【assignmentName】"),
assignmentTime("【作业时间】","【assignmentTime】"),
assignmentScore("【作业分数】","【assignmentScore】"),
examName("【考试名称】","【examName】"),
examTime("【考试时间】","【examTime】"),
examScore("【考试分数】","【examScore】"),
changeReason("【积分变动原因】","【changeReason】"),
changePoint("【积分变动分值】","【changePoint】"),
changeTime("【积分获得时间】","【changeTime】"),
researchTime("【调研时间】","【researchTime】"),
researchName("【调研名称】","【researchName】"),
liveTime("【直播时间】","【liveTime】");
private String code;
private String name;
ReturnParameterEnums(String code, String name) {
this.code = code;
this.name = name;
}
public String getCode() {
return code;
}
public String getName() {
return name;
}
}
package com.yizhi.message.application.enums;
public enum SendType {
MAIL("1","邮件"),
INSITE("2","站内"),
APPPUSH("3","app推送");
private String code;
private String name;
SendType(String code,String name) {
this.code = code;
this.name = name;
}
public String getCode() {
return code;
}
public String getName() {
return name;
}
}
package com.yizhi.message.application.enums;
public enum TimeType {
ONTIME(0,"时间发生时"),
FMIN(1,"5分钟前"),
TMIN(2,"10分钟前"),
THMIN(3,"30分钟前"),
OHOUR(4,"1小时前"),
THOUR(5,"2小时前"),
ODAY(6,"1天前"),
TDAY(7,"2天前");
private Integer code;
private String name;
TimeType(Integer code, String name) {
this.code = code;
this.name = name;
}
public Integer getCode() {
return code;
}
public String getName() {
return name;
}
}
package com.yizhi.message.application.feign.remote;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
/**
* <p>
* 前端控制器
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@FeignClient(name = "newMessage", contextId = "RemoteJobHandleClient")
public interface RemoteJobHandleClient {
/**
* 定时任务业务逻辑处理
*
* @param
* @return
*/
@GetMapping("/remote/messageRemind/messageHandle")
public void sendMessageHandle();
}
package com.yizhi.message.application.feign.remote;
import com.yizhi.message.application.vo.domain.MessageAccountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
/**
* <p>
* 前端控制器 用户消息记录表
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Api(tags = "管理端用户消息接口")
@FeignClient(name = "newMessage", contextId = "RemoteMessageAccountClient")
public interface RemoteMessageAccountClient {
/**
* 用于触发事件,直接发送消息
*
* @return
*/
@GetMapping("/remote/manage/messageAccount/batchSave")
@ApiOperation(value = "用于触发事件,直接发送消息", response = Integer.class)
public Boolean save(@RequestBody List<MessageAccountVo> messageAccount);
@GetMapping("/remote/manage/messageAccount/getList")
public List<MessageAccountVo> getList(@RequestParam("taskType") Integer taskType,
@RequestParam("taskId") Long taskId);
@GetMapping("/remote/manage/messageAccount/getOne")
public MessageAccountVo getOne(@RequestParam("accountId") Long accountId,
@RequestParam("taskType") Integer taskType,
@RequestParam("taskId") Long taskId);
}
package com.yizhi.message.application.feign.remote;
import com.yizhi.message.application.vo.MessageVo;
import com.yizhi.message.application.vo.domain.MessageRemindVo;
import com.yizhi.message.application.vo.domain.MessageVisibleRangeVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@FeignClient(name = "newMessage", contextId = "RemoteMessageClient")
public interface RemoteMessageClient {
/**
* 业务那边需要系统消息列表
* (应用场景)1:学习计划、2:考试、3:调研、4、投票5:报名、6:作业、7:签到、8:项目、9:直播、10:积分
*
* @param relationType
* @return
*/
@PostMapping("/remote/message/getList")
@ApiOperation(value = "单条消息查询", response = MessageVo.class)
public List<MessageVo> getListByRelationType(@ApiParam("relationType 必传") @RequestParam("relationType") Integer relationType,
@ApiParam("siteId 必传") @RequestParam("siteId") Long siteId);
@PostMapping("/remote/message/getOne")
@ApiOperation(value = "", response = MessageVo.class)
public MessageVo getOne(@ApiParam("id") @RequestParam("id") Long id);
@GetMapping("/remote/message/getAuthorize")
public List<MessageVisibleRangeVo> getAuthorize(@ApiParam("id 必传") @RequestParam("id") Long id);
@GetMapping("/remote/message/getMessage")
public MessageRemindVo getMessageRemind(@ApiParam("id 必传") @RequestParam("id") Long id);
}
package com.yizhi.message.application.feign.remote;
import com.yizhi.message.application.vo.MessageRemindVo;
import com.yizhi.util.application.domain.Response;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
/**
* <p>
* 前端控制器
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@FeignClient(name = "newMessage", contextId = "RemoteMessageRemindClient")
public interface RemoteMessageRemindClient {
@PostMapping("/remote/messageRemind/insert")
@ApiOperation(value = "保存待发消息(提醒)",response = String.class)
public Response insert(@ApiParam("messageRemindVo") @RequestBody MessageRemindVo messageRemindVo);
@GetMapping("/remote/messageRemind/get")
@ApiOperation(value = "回显各业务的消息提醒",response = MessageRemindVo.class)
public Response get(@ApiParam("relationType")@RequestParam("relationType") Integer relationType,
@ApiParam("relationId")@RequestParam("relationId") Long relationId,
@ApiParam("siteId")@RequestParam("siteId") Long siteId);
}
\ No newline at end of file
package com.yizhi.message.application.util;
import com.yizhi.message.application.enums.TimeType;
import com.yizhi.util.application.date.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
/**
* 根据时间发生时间和提前发送消息的类型,计算消息确切的发送时间
*
* @author yinyuyan
*/
public class DateConvertor {
private static final Logger logger = LoggerFactory.getLogger(DateConvertor.class);
private DateConvertor() {}
public static Date calSendTime(Date current, Integer aheadType) {
if (TimeType.FMIN.getCode().equals(aheadType)) {
return DateUtil.add(current, 12, -5);
} else if (TimeType.TMIN.getCode().equals(aheadType)) {
return DateUtil.add(current, 12, -10);
} else if (TimeType.THMIN.getCode().equals(aheadType)) {
return DateUtil.add(current, 12, -30);
} else if (TimeType.OHOUR.getCode().equals(aheadType)) {
return DateUtil.add(current, 10, -1);
} else if (TimeType.THOUR.getCode().equals(aheadType)) {
return DateUtil.add(current, 10, -2);
} else if (TimeType.ODAY.getCode().equals(aheadType)) {
return DateUtil.add(current, 5, -1);
} else if (TimeType.TDAY.getCode().equals(aheadType)) {
return DateUtil.add(current, 5, -2);
} else {
return current;
}
}
}
package com.yizhi.message.application.vo;
import com.yizhi.core.application.context.RequestContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* <p>
* 消息
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Data
@Api(tags = "CancelSendMessageVo", description = "消息参数对象")
public class CancelSendMessageVo {
@ApiModelProperty(value = "id 消息id 必传")
private Long id;
@ApiModelProperty(value = "type: 1、取消发送: 2、撤回 取消发送或者撤回操作必传")
private Integer type;
@ApiModelProperty(value = "状态 6:下架、7:上架 上下架操作必传 ")
private Integer status;
@ApiModelProperty(value = "消息类型:1、自定义消息;2、系统消息;3、事件触发消息 ")
private Integer messageType;
private RequestContext context;
}
package com.yizhi.message.application.vo;
import com.yizhi.core.application.context.RequestContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* <p>
* 消息
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Data
@Api(tags = "JobHandleVo", description = "Job执行参数对象")
public class JobHandleVo {
@ApiModelProperty(value = "待发消息messageRemindId 必传")
private Long messageRemindId;
@ApiModelProperty(value = "上下文")
private RequestContext requestContext;
}
package com.yizhi.message.application.vo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* <p>
* 消息
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Data
@Api(tags = "MessageManageVo", description = "管理端返回消息对象")
public class MessageManageVo {
@ApiModelProperty(value = "id 主体消息表")
private Long id;
@ApiModelProperty(value = "编号")
private Integer num;
@ApiModelProperty(value = "可变参数id")
private Long messageParameterId;
@ApiModelProperty(value = "消息类型:1、自定义消息;2、系统消息;3、事件触发消息")
private Integer messageType;
@ApiModelProperty(value = "消息标题")
private String title;
@ApiModelProperty(value = "模板名称 (系统消息需要)")
private String templateName;
@ApiModelProperty(value = "事件名称 (触发消息需要)")
private String eventName;
@ApiModelProperty(value = "状态 1:草稿、2:待发送、3:发送中、4:已发送、、6:下架、7:上架、8:已发送被撤回 (没有发送失败,直接发送中)")
private Integer status;
@ApiModelProperty(value = "状态String 比如: 草稿、上架")
private String statusString;
@ApiModelProperty(value = "发送方式:1、站内信;2、短信;3、邮件")
private Integer sendType;
@ApiModelProperty(value = "(应用场景或者活动名称) 只记录数字 --1:学习计划、2:考试、3:调研、4、投票5:报名、6:作业、7:签到、8:项目、9:直播、10:积分 ")
private Integer relationType;
@ApiModelProperty(value = "(应用场景或者活动名称)String 比如:学习计划、考试")
private String relationTypeString;
@ApiModelProperty(value = "发送时间 (新增自定义消息需要)")
private Date sendTime;
@ApiModelProperty(value = "创建时间 ")
private Date createTime;
@ApiModelProperty(value = "站点id ")
private Long siteId;
}
package com.yizhi.message.application.vo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* <p>
*
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Data
@Api(tags = "MessageParameterVo", description = "可选参数对象")
public class MessageParameterVo {
private Long id;
@ApiModelProperty(value = "可变参数名称")
private String name;
@ApiModelProperty(value = "消息类型:比如: 1、自定义消息 2、系统消息 3、事件触发消息")
private Integer messageType;
@ApiModelProperty(value = "可变参数类型 :1、用户姓名;2、课程名称;3、项目时间;4、项目名称;5、报名截止时间;更多请看数据库")
private Integer fieldType;
@ApiModelProperty(value = "关联模块对应的字段")
private String relationField;
@ApiModelProperty(value = "关联模块类型(0:自定义消息、1:学习计划、2:考试、3:调研、4、投票5:报名、6:作业、7:签到、8:项目、9:直播、10:积分)")
private Integer relationType;
}
package com.yizhi.message.application.vo;
import com.yizhi.core.application.context.RequestContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* <p>
*
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Data
@Api(tags = "MessageRemindVo", description = "各个业务设置提醒时的数据")
public class MessageRemindVo implements Serializable {
private static final long serialVersionUID = -7621642684091133619l;
@ApiModelProperty(value = "提醒id ")
private Long id;
@ApiModelProperty(value = "消息id")
private Long messageId;
@ApiModelProperty(value = "消息类型:1、自定义消息;2、系统消息;3、事件触发消息")
private Integer messageType;
@ApiModelProperty(value = "用户id 主要用于触发消息 个人完成发消息类型")
private Long accountId;
@ApiModelProperty(value = "消息内容(完整版)")
private String messageContext;
@ApiModelProperty(value = "关联模块类型(1:学习计划、2:考试、3:调研、4、投票5:报名、6:作业、7:签到、8:项目、9:直播、10:积分)")
private Integer relationType;
@ApiModelProperty(value = "关联的业务id: 比如调研id")
private Long relationId;
@ApiModelProperty(value = "发送方式:1、站内信;2、短信;3、邮件")
private Integer sendType;
@ApiModelProperty(value = "该业务提醒是被关闭,关闭则为true,默认false")
private Boolean hasDeleted = false;
@ApiModelProperty(value = "该业务提醒是否有变化,有则为true,默认false")
private Boolean isChangge = false;
@ApiModelProperty(value = "专门存放提醒时间设置")
private List<MessageTaskRemindVo> messageTaskRemindVos = new ArrayList<>();
@ApiModelProperty(value = "目前只有培训项目需要,计划同步项目可见范围")
private Boolean visibleRangeUpdate = false;
@ApiModelProperty(value = "指定范围(0:全平台,1:指定用户)")
private Integer visibleRange;
@ApiModelProperty(value = "业务参数对象")
private TaskVo taskVo;
@ApiModelProperty(value = "触发消息专用 发送时间")
private Date sendTime;
@ApiModelProperty(value = "是否设置为上架状态")
private Boolean hasUp = false;
@ApiModelProperty(value = "是否是 修改业务状态 ")
private Boolean taskStatusUpdate = false;
@ApiModelProperty(value = "业务状态 1:才允上架许发送(业务上架)0:不允许发送(业务非上架) 仅针对于系统消息")
private Integer taskStatus;
@ApiModelProperty(value = "上下文 必传,主要需要 siteId companyId accountId accountName 都不能是空")
private RequestContext requestContext;
@ApiModelProperty(value = "调研是否为复制类型")
private Boolean isCopy = false;
@ApiModelProperty(value = "复制调研时,旧的调研id")
private Long oldRelationId;
}
package com.yizhi.message.application.vo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
*
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Data
@Api(tags = "MessageTaskRemindVo", description = "各个业务设置提醒时的数据")
public class MessageTaskRemindVo implements Serializable {
@ApiModelProperty(value = "待发消息id")
private Long messageRemindId;
@ApiModelProperty(value = "提醒时间事件类型 1:业务开始时间、 2:业务结束时间、3:自定义时间")
private Integer timeEventType;
@ApiModelProperty(value = "发生时间枚举:1:五分钟前、2:十分钟前、3:三十分钟前、4:一个小时前、5:两个小时前、6:一天前、7:两天前")
private Integer timeType;
@ApiModelProperty(value = "最终发送时间")
private Date sendTime;
}
package com.yizhi.message.application.vo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* <p>
*
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Data
@Api(tags = "MessageVisibleRangeVo", description = "消息可见范围对象")
public class MessageVisibleRangeVo {
@ApiModelProperty(value = "id")
private Long id;
@ApiModelProperty(value = "消息id")
private Long messageId;
@ApiModelProperty(value = "待发消息id")
private Long messageRemindId;
@ApiModelProperty(value = "类型(1、部门;2、用户)")
private Integer type;
@ApiModelProperty(value = "可能是部门id 也可能是用户id")
private Long relationId;
@ApiModelProperty(value = "关联模块类型(、1:学习计划、2:考试、3:调研、4、投票5:报名、6:作业、7:签到、8:项目、9:直播、10:积分)")
private Integer relationType;
@ApiModelProperty(value = "关联的业务id: 比如调研id")
private Long taskId;
@ApiModelProperty(value = "用户名或 部门名称")
private String name;
@ApiModelProperty(value = "用户真实姓名")
private String fullName;
@ApiModelProperty(value = "工号")
private String workNum;
}
package com.yizhi.message.application.vo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* <p>
* 消息
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Data
@Api(tags = "MessageVo", description = "消息主体表")
public class MessageVo {
@ApiModelProperty(value = "id 主体消息表")
private Long id;
@ApiModelProperty(value = "消息内容id")
private Long messageContextId;
@ApiModelProperty(value = "消息类型:1、自定义消息;2、系统消息;3、事件触发消息 必传")
private Integer messageType;
@ApiModelProperty(value = "消息标题")
private String title;
@ApiModelProperty(value = "消息内容")
private String context;
@ApiModelProperty(value = "伪消息内容")
private String fakeContext;
@ApiModelProperty(value = "消息状态")
private Integer status;
@ApiModelProperty(value = "模板名称 (系统消息需要)")
private String templateName;
@ApiModelProperty(value = "事件名称 (触发消息需要)")
private String eventName;
@ApiModelProperty(value = "发送方式:1、站内信;2、短信;3、邮件")
private Integer sendType;
@ApiModelProperty(value = "关联模块类型(应用场景)1:学习计划、2:考试、3:调研、4、投票5:报名、6:作业、7:签到、8:项目、9:直播、10:积分 ")
private Integer relationType;
@ApiModelProperty(value = "(应用场景或者活动名称)String 比如:学习计划、考试")
private String relationTypeString;
@ApiModelProperty(value = "指定范围(0:全平台,1:指定用户)")
private Integer visibleRange;
@ApiModelProperty(value = "发送时间 (新增自定义消息需要)")
private Date sendTime;
@ApiModelProperty(value = "可见范围")
private List<MessageVisibleRangeVo> messageVisibleRange;
@ApiModelProperty(value = "可变参数id集合")
private List<Long> messageParameterIds;
@ApiModelProperty(value = "专门存放提醒时间设置")
private List<MessageTaskRemindVo> messageTaskRemindVos = new ArrayList<>();
}
package com.yizhi.message.application.vo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* <p>
*
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Data
@Api(tags = "TaskVisibleRangeVo", description = "用于保存到待发消息时,业务可见范围对象")
public class TaskVisibleRangeVo {
@ApiModelProperty(value = "部门id集合")
private List<Long> orgIds;
@ApiModelProperty(value = "用户id集合")
private List<Long> accountIds;
}
package com.yizhi.message.application.vo;
import com.yizhi.message.application.enums.EvenType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* 消息
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Data
@Api(tags = "TaskVo", description = "业务参数对象")
public class TaskVo implements Serializable {
@ApiModelProperty(value = "业务名称")
private String taskName;
@ApiModelProperty(value = "业务开始时间")
private Date taskStratTime;
@ApiModelProperty(value = "业务结束时间")
private Date taskEndTime;
@ApiModelProperty(value = "业务得分")
private Double taskScore;
@ApiModelProperty(value = "业务发生原因(主要用于积分)")
private String reason;
@ApiModelProperty(value = "业务时间(主要用于积分)")
private Date taskTime;
@ApiModelProperty(value = "事件类型")
private EvenType evenType;
}
package com.yizhi.message.application.vo.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
*
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Data
@Api(tags = "MessageAccountVo", description = "学员收到消息记录表")
public class MessageAccountVo extends Model<MessageAccountVo> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id 学员收到消息记录表")
private Long id;
@ApiModelProperty(value = "消息id")
private Long messageId;
@ApiModelProperty(value = "待发消息id")
private Long messageRemindId;
@ApiModelProperty(value = "账号id")
private Long accountId;
@ApiModelProperty(value = "消息内容")
private String context;
@ApiModelProperty(value = "关联模块类型(、1:学习计划、2:考试、3:调研、4、投票5:报名、6:作业、7:签到、8:项目、9:直播、10:积分)")
private Integer relationType;
@ApiModelProperty(value = "关联的业务id: 比如调研id")
private Long relationId;
@ApiModelProperty(value = "指定范围指定范围(0:全平台,1:指定用户)")
private Integer visibleRange;
@ApiModelProperty(value = "是否已读(0:否,1:是)")
private Integer readed;
@ApiModelProperty(value = "读取时间")
private Date readTime;
@ApiModelProperty(value = "是否删除")
private Integer deleted;
@ApiModelProperty(value = "消息标题")
private String title;
@ApiModelProperty(value = "站点id")
private Long siteId;
@ApiModelProperty(value = "公司id")
private Long companyId;
@ApiModelProperty(value = "创建人id")
private Long createById;
@ApiModelProperty(value = "创建人账号")
private String createByName;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "修改人id")
private Long updateById;
@ApiModelProperty(value = "修改人账号")
private String updateByName;
@ApiModelProperty(value = "修改时间")
private Date updateTime;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.message.application.vo.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
*
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Data
@Api(tags = "MessageContextVo", description = "消息内容表")
public class MessageContextVo extends Model<MessageContextVo> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id")
private Long id;
@ApiModelProperty(value = "消息id")
private Long messageId;
@ApiModelProperty(value = "消息内容(带可变参数,不完整)")
private String context;
@ApiModelProperty(value = "创建人id")
private Long createById;
@ApiModelProperty(value = "创建人姓名")
private String createByName;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "修改人id")
private Long updateById;
@ApiModelProperty(value = "修改人账号")
private String updateByName;
@ApiModelProperty(value = "修改时间")
private Date updateTime;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.message.application.vo.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
*
* </p>
*
* @author hutao123
* @since 2019-09-12
*/
@Data
@Api(tags = "MessageParamRelationVo", description = "")
public class MessageParamRelationVo extends Model<MessageParamRelationVo> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "消息与可选参数关联表")
private Long id;
@ApiModelProperty(value = "消息id")
private Long messageId;
@ApiModelProperty(value = "可选参数id")
private Long messageParameterId;
@ApiModelProperty(value = "可变参数类型 :1、用户姓名;2、课程名称;3、项目时间;4、项目名称;5、报名截止时间;更多请看数据库")
private Integer fieldType;
@ApiModelProperty(value = "是否删除")
private Integer deleted;
@ApiModelProperty(value = "创建人id")
private Long createById;
@ApiModelProperty(value = "创建人账号")
private String createByName;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "修改人id")
private Long updateById;
@ApiModelProperty(value = "修改人账号")
private String updateByName;
@ApiModelProperty(value = "修改时间")
private Date updateTime;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.message.application.vo.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
*
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Data
@Api(tags = "MessageParameterVo", description = "可选参数表")
public class MessageParameterVo extends Model<MessageParameterVo> {
private static final long serialVersionUID = 1L;
private Long id;
@ApiModelProperty(value = "可变参数名称")
private String name;
@ApiModelProperty(value = "消息类型:比如: 1、自定义消息 2、系统消息 3、事件触发消息")
private Integer messageType;
@ApiModelProperty(value = "可变参数类型 :1、用户姓名;2、课程名称;3、项目时间;4、项目名称;5、报名截止时间;更多请看数据库")
private Integer fieldType;
@ApiModelProperty(value = "关联模块对应的字段")
private String relationField;
@ApiModelProperty(value = "关联模块类型(0:自定义消息、1:学习计划、2:考试、3:调研、4、投票5:报名、6:作业、7:签到、8:项目、9:直播、10:积分)")
private Integer relationType;
@ApiModelProperty(value = "是否删除")
private Integer deleted;
@ApiModelProperty(value = "站点id")
private Long siteId;
@ApiModelProperty(value = "公司id")
private Long companyId;
@ApiModelProperty(value = "创建人id")
private Long createById;
@ApiModelProperty(value = "创建人账号")
private String createByName;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "修改人id")
private Long updateById;
@ApiModelProperty(value = "修改人账号")
private String updateByName;
@ApiModelProperty(value = "修改时间")
private Date updateTime;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.message.application.vo.domain;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* <p>
*
* </p>
*
* @author taoge123
* @since 2020-03-29
*/
@Data
@ApiModel(value = "MessageReadRecordVo", description = "")
public class MessageReadRecordVo {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id 学员收到消息记录表")
private Long id;
@ApiModelProperty(value = "用户消息id")
private Long messageAccountId;
@ApiModelProperty(value = "账号id")
private Long accountId;
@ApiModelProperty(value = "指定范围指定范围(0:全平台,1:指定用户)")
private Integer visibleRange;
@ApiModelProperty(value = "是否已读(0:否,1:是)")
private Integer readed;
@ApiModelProperty(value = "读取时间")
private Date readTime;
@ApiModelProperty(value = "创建人id")
private Long createById;
@ApiModelProperty(value = "创建人账号")
private String createByName;
@ApiModelProperty(value = "创建时间")
private Date createTime;
}
package com.yizhi.message.application.vo.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
*
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Data
@Api(tags = "MessageRemindVo", description = "各个业务设置提醒时的数据")
public class MessageRemindVo extends Model<MessageRemindVo> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "提醒id ") private Long id;
@ApiModelProperty(value = "消息类型:1、自定义消息;2、系统消息;3、事件触发消息")
private Integer messageType;
@ApiModelProperty(value = "消息id")
private Long messageId;
@ApiModelProperty(value = "消息内容(完整版)")
private String messageContext;
@ApiModelProperty(value = "关联模块类型(、1:学习计划、2:考试、3:调研、4、投票5:报名、6:作业、7:签到、8:项目、9:直播、10:积分)")
private Integer relationType;
private Long relationId;
@ApiModelProperty(value = "提醒时间事件类型 1:业务开始时间、 2:业务结束时间、3:自定义时间")
private Integer timeEventType;
@ApiModelProperty(value = "发生时间枚举:1:五分钟前、2:十分钟前、3:三十分钟前、4:一个小时前、5:两个小时前、6:一天前、7:两天前")
private Integer timeType;
@ApiModelProperty(value = "最终发送时间")
private Date sendTime;
@ApiModelProperty(value = "状态 1:草稿、2:待发送、3:发送中、4:已发送、、6:下架、7:上架 (没有发送失败,直接发送中)")
private Integer status;
@ApiModelProperty(value = "业务状态:1代表上架状态,0:代表非上架状态(只有1才允许发送消息)")
private Integer taskStatus;
@ApiModelProperty(value = "指定范围指定范围(0:全平台,1:指定用户)")
private Integer visibleRange;
@ApiModelProperty(value = "发送方式:1、站内信;2、短信;3、邮件")
private Integer sendType;
@ApiModelProperty(value = "用户id 主要用于触发消息 个人完成发消息类型")
private Long accountId;
@ApiModelProperty(value = "是否删除(0:否,1:是)")
private Integer deleted;
@ApiModelProperty(value = "站点id")
private Long siteId;
@ApiModelProperty(value = "公司id")
private Long companyId;
@ApiModelProperty(value = "创建人id")
private Long createById;
@ApiModelProperty(value = "创建人账号")
private String createByName;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "修改人id")
private Long updateById;
@ApiModelProperty(value = "修改人账号")
private String updateByName;
@ApiModelProperty(value = "修改时间")
private Date updateTime;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.message.application.vo.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
*
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Data
@Api(tags = "MessageVisibleRangeVo", description = "")
public class MessageVisibleRangeVo extends Model<MessageVisibleRangeVo> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id")
private Long id;
@ApiModelProperty(value = "消息id")
private Long messageId;
@ApiModelProperty(value = "类型(1、部门;2、用户)")
private Integer type;
@ApiModelProperty(value = "可能是部门id 也可能是用户id")
private Long relationId;
@ApiModelProperty(value = "是否删除(0:否,1:是)")
private Integer deleted;
@ApiModelProperty(value = "创建人")
private Long createById;
@ApiModelProperty(value = "创建人姓名")
private String createByName;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "修改人id")
private Long updateById;
@ApiModelProperty(value = "修改人账号")
private String updateByName;
@ApiModelProperty(value = "修改时间")
private Date updateTime;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.message.application.vo.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* 消息
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Data
@Api(tags = "MessageVo", description = "消息主体表")
public class MessageVo extends Model<MessageVo> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id 主体消息表")
private Long id;
@ApiModelProperty(value = "消息类型:1、自定义消息;2、系统消息;3、事件触发消息")
private Integer messageType;
@ApiModelProperty(value = "消息标题")
private String title;
@ApiModelProperty(value = "模板名称 (系统消息需要)")
private String templateName;
@ApiModelProperty(value = "事件名称 (触发消息需要)")
private String eventName;
@ApiModelProperty(value = "发送方式:1、站内信;2、短信;3、邮件")
private Integer sendType;
@ApiModelProperty(value = "关联模块类型(应用场景)1:学习计划、2:考试、3:调研、4、投票5:报名、6:作业、7:签到、8:项目、9:直播、10:积分 ")
private Integer relationType;
@ApiModelProperty(value = "状态 1:草稿、2:待发送、3:发送中、4:已发送、、6:下架、7:上架、8:已发送被撤回 (没有发送失败,直接发送中)")
private Integer status;
@ApiModelProperty(value = "指定范围(0:全平台,1:指定用户)")
private Integer visibleRange;
@ApiModelProperty(value = "是否删除(0:否,1:是)")
private Integer deleted;
@ApiModelProperty(value = "发送时间 (新增自定义消息需要)")
private Date sendTime;
@ApiModelProperty(value = "站点id")
private Long siteId;
@ApiModelProperty(value = "公司id")
private Long companyId;
@ApiModelProperty(value = "触发消息类型")
private Long evenType;
@ApiModelProperty(value = "创建人id")
private Long createById;
@ApiModelProperty(value = "创建人账号")
private String createByName;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "修改人id")
private Long updateById;
@ApiModelProperty(value = "修改人账号")
private String updateByName;
@ApiModelProperty(value = "修改时间")
private Date updateTime;
@Override
protected Serializable pkVal() {
return this.id;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.yizhi</groupId>
<artifactId>cloud-newMessage</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.yizhi</groupId>
<artifactId>cloud-newMessage-service</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-system-api</artifactId>
<scope>provided</scope>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-job-api</artifactId>
<scope>provided</scope>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-newMessage-api</artifactId><scope>provided</scope>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-course-api</artifactId><scope>provided</scope>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-training-project-api</artifactId>
<scope>provided</scope>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-exam-api</artifactId>
<scope>provided</scope>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-research-api</artifactId>
<scope>provided</scope>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-live-api</artifactId>
<scope>provided</scope>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-assignment-api</artifactId>
<scope>provided</scope>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-course-studyLog-api</artifactId>
<scope>provided</scope>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- deploy 时跳过该模块 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.yizhi.message.application;
import com.yizhi.message.application.constans.Constans;
import org.springframework.amqp.core.Queue;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
/**
* @Author: hutao
* @Date: 2019
*/
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients(basePackages = {"com.yizhi"})
@ComponentScan(basePackages = {"com.yizhi"})
public class CloudMessageApplication {
public static void main(String[] args) {
SpringApplication.run(CloudMessageApplication.class, args);
}
@Bean
public Queue createMessageEventQueue() {
return new Queue(Constans.MESSAGE_QUEUE, true, false, false);
}
}
package com.yizhi.message.application;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* @Author:
* @Date:
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig extends WebMvcConfigurerAdapter {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("消息接口")
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.fulan.application"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("消息接口")
//版本
.version("1.0")
.build();
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("docs.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
package com.yizhi.message.application.controller.api;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.application.orm.id.IdGenerator;
import com.yizhi.core.application.context.ContextHolder;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.message.application.constans.Constans;
import com.yizhi.message.application.controller.util.MessageUtil;
import com.yizhi.message.application.domain.Message;
import com.yizhi.message.application.domain.MessageAccount;
import com.yizhi.message.application.domain.MessageReadRecord;
import com.yizhi.message.application.mapper.MessageAccountMapper;
import com.yizhi.message.application.service.IMessageReadRecordService;
import com.yizhi.message.application.service.MessageAccountService;
import com.yizhi.message.application.service.MessageRemindService;
import com.yizhi.message.application.service.MessageService;
import com.yizhi.util.application.domain.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* <p>
* 前端控制器 用户消息记录表
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@RestController
@Api(tags = "学员端消息接口")
@RequestMapping("/api/messageAccount")
public class MessageAccountComtroller {
@Autowired
private MessageAccountService messageAccountService;
@Autowired
private MessageRemindService messageRemindService;
@Autowired
private MessageService messageService;
@Autowired
private IMessageReadRecordService messageReadRecordService;
@Autowired
private MessageUtil messageUtil;
@Autowired
private IdGenerator idGenerator;
@Autowired
private MessageAccountMapper messageAccountMapper;
/**
* 获取用户未读消息的个数
*
* @return
*/
@GetMapping("/unread/count")
@ApiOperation(value = "获取用户未读消息的个数", response = Integer.class)
public Response unread() {
RequestContext context = ContextHolder.get();
Integer unReadNum = 0;
EntityWrapper wrapper = new EntityWrapper();
wrapper.eq("deleted", Constans.NOT_DELETED)
.eq("site_id", context.getSiteId())
.eq("account_id", context.getAccountId())
.eq("readed", Constans.NOT_READ);
unReadNum = messageAccountService.selectCount(wrapper);
if (unReadNum > 0) {
return Response.ok(unReadNum);
} else {
EntityWrapper wrapper1 = new EntityWrapper();
wrapper1.eq("deleted", Constans.NOT_DELETED)
.eq("site_id", context.getSiteId())
.eq("visible_range", Constans.PUBLIC_SITE);
unReadNum = messageAccountService.selectCount(wrapper1);
}
Integer readNum = messageReadRecordService.getReadNum();
unReadNum = unReadNum - readNum;
return Response.ok(unReadNum > 0 ? unReadNum : 0);
}
/**
* 获取用户消息列表 弃用
*
* @return
*/
@GetMapping("/list")
@ApiOperation(value = "获取用户消息列表", response = Integer.class)
@Deprecated
public Response list() {
RequestContext context = ContextHolder.get();
EntityWrapper wrapper = new EntityWrapper();
wrapper.eq("deleted", Constans.NOT_DELETED)
.eq("site_id", context.getSiteId())
.eq("account_id", context.getAccountId())
.orderBy("create_time", false);
return Response.ok(messageAccountService.selectList(wrapper));
}
/**
* 获取用户消息列表
*
* @return
*/
@GetMapping("/page")
@ApiOperation(value = "获取用户消息列表(分页)", response = Integer.class)
public Response page(@ApiParam("当前页数") @RequestParam(value = "pageNo", defaultValue = "1", required = false) Integer pageNo,
@ApiParam("页内条数") @RequestParam(value = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
RequestContext context = ContextHolder.get();
Page<MessageAccount> page = new Page(pageNo, pageSize);
List<MessageAccount> messageAccounts = messageAccountMapper.getList(context.getSiteId(), context.getAccountId(), page);
page.setRecords(messageAccounts);
page.setTotal(messageAccountMapper.getListNum(context.getSiteId(),context.getAccountId()));
if (CollectionUtils.isNotEmpty(messageAccounts)) {
List<Long> messageAccountIds = page.getRecords().parallelStream().map(a -> a.getId()).collect(Collectors.toList());
List<Long> messageIds = page.getRecords().parallelStream().map(a -> a.getMessageId()).collect(Collectors.toList());
//方便判断该消息是否已读
Map<Long, Long> readRecordsMap = messageReadRecordService.getMap(messageAccountIds);
//获取消息title
Map<Long, String> titleMap = messageService.getMessageTitleMap(messageIds);
for (MessageAccount a : page.getRecords()) {
// 用户名称给赋值,业务参数赋值已在业务保存待发消息时已处理
String completeContext = messageUtil.getCompleteContext(a.getContext(), context);
a.setContext(completeContext);
if (titleMap != null) {
a.setTitle(titleMap.get(a.getMessageId()));
}
if (readRecordsMap != null) {
if (a.getVisibleRange().equals(Constans.PUBLIC_SITE)) {
a.setReaded(readRecordsMap.containsKey(a.getId()) == true ? 1 : 0);
}
}
}
}
return Response.ok(page);
}
/**
* 点击,使之全部已读
*
* @return
*/
@GetMapping("/read")
@ApiOperation(value = "一键已读功能", response = Integer.class)
public Response read() {
RequestContext context = ContextHolder.get();
MessageAccount messageAccount = new MessageAccount();
messageAccount.setReaded(Constans.READED);
messageAccount.setReadTime(new Date());
EntityWrapper wrapper = new EntityWrapper();
wrapper.setSqlSelect("id,visible_range");
wrapper.eq("deleted", Constans.NOT_DELETED)
.eq("site_id", context.getSiteId())
.andNew()
.eq("account_id", context.getAccountId())
.eq("readed", Constans.NOT_READ)
.or()
.eq("visible_range", Constans.PUBLIC_SITE);
List<MessageAccount> list = messageAccountService.selectList(wrapper);
//先查询到未读记录的集合
if (CollectionUtils.isNotEmpty(list)) {
messageAccountService.update(messageAccount, wrapper);
List<Long> messageAccountIds = list.parallelStream().map(a -> a.getId()).collect(Collectors.toList());
//方便判断该消息是否已读
Map<Long, Long> readRecordsMap = messageReadRecordService.getMap(messageAccountIds);
List<MessageReadRecord> readRecords = new ArrayList<>(list.size());
for (MessageAccount a : list) {
if (readRecordsMap != null) {
if (!readRecordsMap.containsKey(a.getId())) {
buildReadRecords(readRecords, a, context);
}
} else {
buildReadRecords(readRecords, a, context);
}
}
//插入阅读记录
messageReadRecordService.batchInsertReadRecord(readRecords);
}
return Response.ok();
}
/**
* 构建阅读记录
*
* @param readRecords
* @param messageAccount
* @param context
*/
public void buildReadRecords(List<MessageReadRecord> readRecords, MessageAccount messageAccount, RequestContext context) {
MessageReadRecord readRecord = new MessageReadRecord();
readRecord.setId(idGenerator.generate());
readRecord.setMessageAccountId(messageAccount.getId());
readRecord.setVisibleRange(messageAccount.getVisibleRange());
readRecord.setAccountId(context.getAccountId());
readRecord.setCreateByName(context.getAccountName());
readRecord.setReaded(Constans.READED);
readRecord.setReadTime(new Date());
readRecords.add(readRecord);
}
@GetMapping("/getOne")
@ApiOperation(value = "获取单条消息", response = MessageAccount.class)
public Response<MessageAccount> getOne(@ApiParam("id必传") @RequestParam("id") Long id) {
MessageAccount a = messageAccountService.selectById(id);
if (a != null) {
MessageAccount messageAccount = new MessageAccount();
messageAccount.setId(id);
messageAccount.setReaded(Constans.READED);
messageAccount.setReadTime(new Date());
messageAccountService.updateById(messageAccount);
//增加阅读记录
messageReadRecordService.insertReadRecord(messageAccount);
Message message = messageService.selectById(a.getMessageId());
if (message != null) {
a.setTitle(message.getTitle());
// 用户名称给赋值,业务参数赋值已在业务保存待发消息时已处理
String completeContext = messageUtil.getCompleteContext(a.getContext(), ContextHolder.get());
a.setContext(completeContext);
}
}
return Response.ok(a);
}
}
package com.yizhi.message.application.controller.api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
* 前端控制器
* </p>
*
* @author taoge123
* @since 2020-03-29
*/
@RestController
@RequestMapping("/messageReadRecord")
public class MessageReadRecordController {
}
package com.yizhi.message.application.controller.jobHandle;
import com.yizhi.message.application.controller.util.BuildJob;
import com.yizhi.message.application.service.MessageRemindService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
/**
* <p>
* 前端控制器
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@RestController
@Api(tags = "消息涉及job接口")
@RequestMapping("/remote/messageRemind")
public class RemoteJobHandleComtroller {
@Autowired
private MessageRemindService messageRemindService;
@Autowired
private BuildJob buildJob;
private Logger logger = LoggerFactory.getLogger(RemoteJobHandleComtroller.class);
/**
* 定时任务执行实际的处理逻辑类
* 定时任务业务逻辑处理
*
* @param
* @return
*/
@GetMapping("/messageHandle")
@ApiOperation(value = "定时发送消息", response = String.class)
public void sendMessageHandle() {
logger.info("我今天就看有没有调用!!!");
try {
logger.info("开始处理定时任务");
messageRemindService.sendMessageHandle();
} catch (Exception e) {
e.printStackTrace();
logger.info("定时任务处理异常");
}
}
@GetMapping("/buildJob")
@ApiOperation(value = "构建一个job任务,默认每五分钟处理,也可指定cron表达式", response = String.class)
public void buildJob(@RequestParam(value = "hanldeTime",required = false)Date hanldeTime ) throws Exception {
if (hanldeTime == null){
buildJob.buildJobDefault("消息处理,默认每五分钟处理一次");
}else {
buildJob.buildJob(new Date().toString(),hanldeTime);
}
}
}
package com.yizhi.message.application.controller.manage;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.message.application.domain.Message;
import com.yizhi.message.application.enums.MessageStatus;
import com.yizhi.message.application.service.MessageService;
import com.yizhi.message.application.vo.CancelSendMessageVo;
import com.yizhi.message.application.vo.MessageManageVo;
import com.yizhi.message.application.vo.MessageVo;
import com.yizhi.util.application.domain.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* <p>
* 消息 前端控制器 消息主体表
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@RestController
@Api(tags = "主体消息管理端接口")
@RequestMapping("/manage/message")
public class MessageComtroller {
@Autowired
private MessageService messageService;
/**
* 保存消息
*
* @param messageVo
* @return
*/
@PostMapping("/save")
@ApiOperation(value = "新增消息", response = String.class)
public Response save(@ApiParam("messageVo") @RequestBody MessageVo messageVo) {
if (messageVo.getMessageType() == null || messageVo.getTitle() == null || messageVo.getContext() == null) {
return Response.fail("参数不全!");
} else if (messageVo.getTitle().trim() == "" || messageVo.getContext().trim() == "") {
return Response.fail("消息标题或内容不可为空!");
} else {
switch (messageVo.getMessageType()) {
case 1:
if (messageVo.getSendType() == null || messageVo.getSendTime() == null || messageVo.getVisibleRange() == null) {
return Response.fail("必填项必填!");
}
break;
case 2:
if (messageVo.getTemplateName() == null || messageVo.getTemplateName().trim() == "") {
return Response.fail("消息模板名称不可为空!");
}
break;
case 3:
if (messageVo.getEventName() == null || messageVo.getEventName().trim() == "") {
return Response.fail("触发事件名称不可为空!");
}
break;
}
}
switch (messageService.save(messageVo)) {
case 1:
return Response.ok("消息保存成功");
case -1:
return Response.fail("消息保存失败");
case -2:
return Response.fail("保存主体消息异常");
case -3:
return Response.fail("保存消息内容异常");
}
return Response.fail("消息保存失败");
}
/**
* 分页查询
*
* @param messageType
* @param title
* @param pageNo
* @param pageSize
* @return
*/
@ApiOperation(value = "消息分页查询", response = MessageManageVo.class)
@GetMapping("/page")
public Response<Page<MessageManageVo>> getPage(@ApiParam("消息类型") @RequestParam(value = "messageType", required = false) Integer messageType,
@ApiParam("消息标题 ") @RequestParam(value = "title", required = false) String title,
@ApiParam("当前页码") @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
@ApiParam("页内条数") @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
Page<MessageManageVo> page = new Page<>(pageNo, pageSize);
if (StringUtils.isBlank(title)) {
if (messageType == null) {
return Response.fail("分页查询,缺少messageType参数!");
}
}
return Response.ok(messageService.getPage(messageType, title, page));
}
/**
* 回显需要
*
* @param id
* @return
*/
@GetMapping("/get")
@ApiOperation(value = "单条消息查询", response = MessageVo.class)
public Response<MessageVo> get(@ApiParam("消息id 必传") @RequestParam("id") Long id) {
return Response.ok(messageService.get(id));
}
/**
* 修改消息
*
* @param messageVo
* @return
*/
@PostMapping("/update")
@ApiOperation(value = "消息修改", response = String.class)
public Response update(@ApiParam("messageVo") @RequestBody MessageVo messageVo) {
if (messageVo.getId() == null) {
return Response.fail("消息id必传!");
}
if (messageVo.getMessageType() == null) {
return Response.fail("消息类型必传");
}
switch (messageService.update(messageVo)) {
case 1:
return Response.ok("消息修改成功");
case -1:
return Response.fail("消息修改失败");
case -2:
return Response.fail("修改消息内容异常");
case -3:
return Response.fail("数据库没有该消息");
case -4:
return Response.fail("非草稿状态的自定义消息则无法修改!");
}
return Response.fail("消息修改失败");
}
/**
* 上下架
*
* @param vo
* @return
*/
@PostMapping("/upOrDown")
@ApiOperation(value = "消息上下架", response = String.class)
public Response upOrDown(@ApiParam("vo") @RequestBody CancelSendMessageVo vo) {
if (vo.getId() == null || vo.getStatus() == null) {
return Response.fail("缺少必要参数!");
}
if (MessageStatus.UP.getCode() != (vo.getStatus()) && MessageStatus.DOWN.getCode() != (vo.getStatus())) {
return Response.fail("status值不合理!");
}
Integer num = messageService.upOrDown(vo);
if (num == 1) {
if (MessageStatus.DOWN.equals(vo.getStatus())) {
return Response.ok("下架成功");
}
return Response.ok("上架成功");
} else if (num == -2) {
return Response.fail("该消息不支持上下架!");
}
return Response.fail("操作失败");
}
/**
* 取消发送或者撤回
* 取消发送需要删除定时任务
*
* @param vo
* @return
*/
@PostMapping("/cancel")
@ApiOperation(value = "取消发送或者撤回", response = String.class)
public Response cancel(@ApiParam("vo") @RequestBody CancelSendMessageVo vo) {
if (vo.getId() == null || vo.getType() == null) {
return Response.fail("缺少必要参数!");
}
Integer cancel = messageService.cancel(vo);
if (cancel == 1) {
return Response.ok("操作成功");
} else if (cancel == -3) {
return Response.fail("数据库没有该数据!");
} else if (cancel == -2) {
return Response.fail("该消息类型不支持撤回或取消发送");
} else if (cancel == -5) {
return Response.fail("没有查询到对应待发消息");
}
return Response.fail("操作失败");
}
/**
* 主要用到vo内的id必传
*
* @param vo
* @return
*/
@PostMapping("/send")
@ApiOperation(value = "发送消息", response = String.class)
public Response send(@ApiParam("vo") @RequestBody CancelSendMessageVo vo) {
if (vo.getId() == null) {
return Response.fail("缺少必要参数!");
}
Integer send = messageService.send(vo);
if (send == 1) {
return Response.ok("成功添加定时发送消息任务");
} else if (send == -2) {
return Response.fail("该消息类型不支持发送");
} else if (send == -3) {
return Response.fail("请选择未来的时间!");
} else if (send == -4) {
return Response.fail("数据库没有该数据!");
}
return Response.fail("操作失败");
}
/**
* 主要用到vo内的id必传
* 删除自定义任务
*
* @param vo
* @return
*/
@PostMapping("/deleted")
@ApiOperation(value = "删除消息", response = String.class)
public Response deleted(@ApiParam("vo") @RequestBody CancelSendMessageVo vo) {
if (vo.getId() == null) {
return Response.fail("id不能为空!");
}
Message message = this.messageService.selectById(vo.getId());
if (message == null) {
return Response.fail("删除失败,数据库没有该数据!");
}
if (message.getMessageType() == 1 && message.getStatus() == MessageStatus.DRAFT.getCode()) {
message.setDeleted(1);
if (this.messageService.updateById(message)) {
return Response.ok("操作成功");
}
} else {
return Response.fail("非草稿状态的自定义消息则无法删除!");
}
return Response.fail("操作失败");
}
/**
* 业务那边需要系统消息列表
* (应用场景)1:学习计划、2:考试、3:调研、4、投票5:报名、6:作业、7:签到、8:项目、9:直播、10:积分
*
* @param relationType
* @return
*/
@GetMapping("/getList")
@ApiOperation(value = "业务新增时,模板消息列表查询", response = MessageVo.class)
public Response<List<MessageVo>> getListByRelationType(@ApiParam("relationType 必传")
@RequestParam("relationType") Integer relationType) {
return Response.ok(messageService.getListByRelationType(relationType));
}
}
package com.yizhi.message.application.controller.manage;
import com.yizhi.message.application.service.MessageParameterService;
import com.yizhi.message.application.vo.MessageParameterVo;
import com.yizhi.util.application.domain.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* <p>
* 前端控制器
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@RestController
@Api(tags = "消息可选参数接口")
@RequestMapping("/manage/messageParameter")
public class MessageParameterComtroller {
@Autowired
private MessageParameterService messageParameterService;
/**
* @param messageType 消息类型:比如: 1、自定义消息 2、系统消息 3、事件触发消息
* @param relationType 应用场景(关联模块类型)(0:通用、1:学习计划、2:考试、3:调研、4、投票5:报名、6:作业、7:签到、8:项目、9:直播 、10积分)
* @return
*/
@GetMapping("/getList")
@ApiOperation(value = "获取可选参数列表", response = MessageParameterVo.class)
public Response<List<MessageParameterVo>> getList(@RequestParam("messageType") Integer messageType,
@RequestParam("relationType") Integer relationType) {
return Response.ok(messageParameterService.getList(messageType, relationType));
}
}
package com.yizhi.message.application.controller.manage;
import com.yizhi.message.application.service.MessageRemindService;
import com.yizhi.message.application.vo.MessageRemindVo;
import com.yizhi.message.application.vo.MessageVo;
import com.yizhi.util.application.domain.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* <p>
* 前端控制器
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@RestController
@Api(tags = "待发消息接口")
@RequestMapping("/manage/messageRemind")
public class MessageRemindComtroller {
@Autowired
private MessageRemindService messageRemindService;
/**
* 保存各业务设置的提醒
*
* @param vo
* @return
*/
@PostMapping("/insert")
@ApiOperation(value = "保存待发消息(提醒)", response = String.class)
public Response insert(@ApiParam("vo") @RequestBody MessageRemindVo vo) {
if (vo.getMessageContext() == null || vo.getRelationType() == null
|| vo.getRelationId() == null || vo.getMessageId() == null
|| vo.getSendType() == null || vo.getVisibleRange() == null) {
return Response.fail("缺少必要参数");
}
Integer integer = messageRemindService.insertMessageRemind(vo);
if (integer == 1) {
return Response.ok("保存成功");
}
return Response.fail("操作失败");
}
/**
* 给各业务回显已设置的提醒
*
* @param relationType
* @param relationId
* @return
*/
@GetMapping("/get")
@ApiOperation(value = "回显各业务的消息提醒", response = MessageVo.class)
public Response get(@ApiParam("relationType") @RequestParam("relationType") Integer relationType,
@ApiParam("relationId") @RequestParam("relationId") Long relationId) {
return Response.ok(messageRemindService.get(relationType, relationId));
}
/**
* 修改消息提醒(包含删除提醒)
*
* @param vo
* @return
*/
@PostMapping("/update")
@ApiOperation(value = "修改待发消息(提醒)", response = String.class)
public Response update(@ApiParam("vo") @RequestBody MessageRemindVo vo) {
if (vo.getIsChangge() == true) {
if (vo.getMessageContext() == null || vo.getRelationType() == null
|| vo.getRelationId() == null || vo.getMessageId() == null
|| vo.getSendType() == null || vo.getVisibleRange() == null) {
return Response.fail("缺少必要参数");
}
}
Integer integer = messageRemindService.updateMessageRemind(vo);
if (integer == 1) {
return Response.ok("修改成功");
}
return Response.fail("操作失败");
}
}
package com.yizhi.message.application.controller.remote;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.yizhi.message.application.constans.Constans;
import com.yizhi.message.application.domain.MessageAccount;
import com.yizhi.message.application.service.MessageAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* <p>
* 前端控制器 用户消息记录表
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@RestController
@Api(tags = "用户消息接口,后端内部调用接口,不给前端用")
@RequestMapping("/remote/manage/messageAccount")
public class RemoteMessageAccountComtroller {
@Autowired
private MessageAccountService messageAccountService;
/**
* 用于触发事件,直接发送消息
*
* @return
*/
@GetMapping("/batchSave")
@ApiOperation(value = "用于触发事件,直接发送消息", response = Integer.class)
public Boolean save(@RequestBody List<MessageAccount> messageAccounts) {
if (!CollectionUtils.isEmpty(messageAccounts)) {
return messageAccountService.insertBatch(messageAccounts);
}
return false;
}
@GetMapping("/getList")
@ApiOperation(value = "获取列表", response = Integer.class)
public List<MessageAccount> getList(@RequestParam("taskType") Integer taskType, @RequestParam("taskId") Long taskId) {
EntityWrapper wrapper = new EntityWrapper();
wrapper.eq("deleted", Constans.NOT_DELETED);
wrapper.eq("relation_id", taskId);
wrapper.eq("relation_type", taskType);
wrapper.setSqlSelect("account_id");
return messageAccountService.selectList(wrapper);
}
@GetMapping("/getOne")
@ApiOperation(value = "获取单条消息", response = Integer.class)
public MessageAccount getOne(@RequestParam("accountId") Long accountId, @RequestParam("taskType") Integer taskType, @RequestParam("taskId") Long taskId) {
EntityWrapper wrapper = new EntityWrapper();
wrapper.eq("deleted", Constans.NOT_DELETED);
wrapper.eq("relation_id", taskId);
wrapper.eq("relation_type", taskType);
wrapper.eq("account_id",accountId);
wrapper.setSqlSelect("account_id");
return messageAccountService.selectOne(wrapper);
}
}
package com.yizhi.message.application.controller.remote;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.yizhi.message.application.domain.MessageAccount;
import com.yizhi.message.application.domain.MessageRemind;
import com.yizhi.message.application.domain.MessageVisibleRange;
import com.yizhi.message.application.service.MessageAccountService;
import com.yizhi.message.application.service.MessageRemindService;
import com.yizhi.message.application.service.MessageService;
import com.yizhi.message.application.service.MessageVisibleRangeService;
import com.yizhi.message.application.vo.MessageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* <p>
* 消息 前端控制器 消息主体表
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@RestController
@Api(tags = "主体消息接口,后端内部调用接口,不给前端用")
@RequestMapping("/remote/message")
public class RemoteMessageComtroller {
@Autowired
private MessageService messageService;
@Autowired
private MessageVisibleRangeService messageVisibleRangeService;
@Autowired
private MessageAccountService messageAccountService;
@Autowired
private MessageRemindService messageRemindService;
/**
* 业务那边需要系统消息列表
* (应用场景)1:学习计划、2:考试、3:调研、4、投票5:报名、6:作业、7:签到、8:项目、9:直播、10:积分
*
* @param relationType
* @return
*/
@PostMapping("/getList")
@ApiOperation(value = "业务新增时,模板消息列表查询", response = MessageVo.class)
public List<MessageVo> getListByRelationType(@ApiParam("relationType 必传")
@RequestParam("relationType") Integer relationType) {
return messageService.getListByRelationType(relationType);
}
/**
* 业务那边需要系统消息列表
* (应用场景)1:学习计划、2:考试、3:调研、4、投票5:报名、6:作业、7:签到、8:项目、9:直播、10:积分
*
* @param id 消息id
* @return
*/
@PostMapping("/getOne")
@ApiOperation(value = "", response = MessageVo.class)
public MessageVo getOne(@ApiParam("id 必传") @RequestParam("id") Long id) {
return messageService.get(id);
}
@GetMapping("/getAuthorize")
public List<MessageVisibleRange> getAuthorize(@ApiParam("id 必传") @RequestParam("id") Long id) {
MessageVisibleRange range = new MessageVisibleRange();
range.setMessageId(id);
range.setDeleted(0);
EntityWrapper<MessageVisibleRange> wrapper = new EntityWrapper<MessageVisibleRange>(range);
List<MessageVisibleRange> list = messageVisibleRangeService.selectList(wrapper);
return list;
}
@GetMapping("/getMessage")
public MessageRemind getMessageRemind(@ApiParam("id 必传") @RequestParam("id") Long id) {
MessageAccount messageAccount = messageAccountService.selectById(id);
MessageRemind messageRemind = null;
if (messageAccount != null) {
messageRemind = messageRemindService.selectById(messageAccount.getMessageRemindId());
}
return messageRemind;
}
}
package com.yizhi.message.application.controller.remote;
import com.yizhi.message.application.service.MessageRemindService;
import com.yizhi.message.application.vo.MessageRemindVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
* 前端控制器
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@RestController
@Api(tags = "待发消息接口,后端内部调用接口,不给前端用")
@RequestMapping("/remote/messageRemind")
public class RemoteMessageRemindComtroller {
@Autowired
private MessageRemindService messageRemindService;
private Logger logger = LoggerFactory.getLogger(RemoteMessageRemindComtroller.class);
@PostMapping("/insert")
@ApiOperation(value = "保存待发消息(提醒)", response = String.class)
public Integer insert(@ApiParam("messageRemindVo") @RequestBody MessageRemindVo messageRemindVo) {
return messageRemindService.insertMessageRemind(messageRemindVo);
}
}
package com.yizhi.message.application.controller.util;
import com.yizhi.application.job.remote.JobClient;
import com.yizhi.application.job.remote.vo.VmyJobVO;
import com.yizhi.message.application.constans.Constans;
import com.yizhi.util.application.date.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
@Component
public class BuildJob {
@Autowired
private JobClient jobClient;
private static final Logger logger = LoggerFactory.getLogger(BuildJob.class);
/**
* 构建一个定时任务
* @param jobName
* @param sendTime
* @throws Exception
*/
public void buildJob(String jobName,Date sendTime) throws Exception {
VmyJobVO job = new VmyJobVO();
job.setGroup(Constans.JOBGROUP);
job.setJobName(jobName);
job.setJobClassName("com.fulan.application.handle.quartz.job.SendNewMessageJob");
logger.info("********************************上架消息的发送时间={},时间戳={}",
sendTime, sendTime.getTime());
logger.info("**************************************当前系统时间={}", (new Date()).getTime());
String cron = DateUtil.getCron(sendTime);
logger.info("**************************************cron={}", cron);
String[] cronArr = cron.split(" ");
job.setSecond(cronArr[0]);
job.setMinute(cronArr[1]);
job.setHour(cronArr[2]);
job.setDay(cronArr[3]);
job.setMonth(cronArr[4]);
job.setWeek(cronArr[5]);
job.setYear(cronArr[6]);
jobClient.insert(job);
}
public void buildJobDefault(String jobName) throws Exception {
VmyJobVO job = new VmyJobVO();
job.setGroup(Constans.JOBGROUP);
job.setJobName(jobName);
job.setJobClassName("com.fulan.application.handle.quartz.job.SendNewMessageJob");
logger.info("**************************************当前系统时间={}", (new Date()).getTime());
job.setSecond("0");
job.setMinute("0/5");
job.setHour("*");
job.setDay("*");
job.setMonth("*");
job.setWeek("?");
job.setYear("*");
jobClient.insert(job);
}
}
\ No newline at end of file
package com.yizhi.message.application.controller.util;
import com.yizhi.assignment.application.feign.AssignmentClient;
import com.yizhi.assignment.application.vo.entity.Assignment;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.exam.application.feign.ExamClient;
import com.yizhi.exam.application.vo.domain.Exam;
import com.yizhi.live.application.feign.LiveActivityClient;
import com.yizhi.live.application.vo.LiveActivityVO;
import com.yizhi.message.application.constans.Constans;
import com.yizhi.message.application.enums.EvenType;
import com.yizhi.message.application.enums.MessageParameterEnums;
import com.yizhi.message.application.enums.ReturnParameterEnums;
import com.yizhi.message.application.vo.TaskVo;
import com.yizhi.message.application.enums.*;
import com.yizhi.research.application.feign.ResearchClient;
import com.yizhi.research.application.vo.domain.ResearchVo;
import com.yizhi.system.application.vo.AccountVO;
import com.yizhi.training.application.feign.TpPlanClient;
import com.yizhi.training.application.feign.TrainingProjectClient;
import com.yizhi.training.application.vo.domain.TpPlanVo;
import com.yizhi.training.application.vo.domain.TrainingProjectVo;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Component
public class MessageUtil {
private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private Logger logger = LoggerFactory.getLogger(MessageUtil.class);
@Autowired
private LiveActivityClient liveActivityClient;
@Autowired
private ResearchClient researchClient;
@Autowired
private ExamClient examClient;
@Autowired
private AssignmentClient assignmentClient;
@Autowired
private TrainingProjectClient trainingProjectClient;
@Autowired
private TpPlanClient tpPlanClient;
private MessageUtil() {
}
public String getRelationType(Integer key) {
if (key != null) {
String relationType = "";
switch (key) {
// "关联模块类型(、1:学习计划、2:考试、3:调研、4、投票5:报名、6:作业、7:签到、8:项目、9:直播、10:积分、11课程)"
case 0:
relationType = RelationType.ZDY.getName();
break;
case 1:
relationType = RelationType.XX.getName();
break;
case 2:
relationType = RelationType.KS.getName();
break;
case 3:
relationType = RelationType.DY.getName();
break;
case 4:
relationType = RelationType.TP.getName();
break;
case 5:
relationType = RelationType.BM.getName();
break;
case 6:
relationType = RelationType.ZY.getName();
break;
case 7:
relationType = RelationType.QD.getName();
break;
case 8:
relationType = RelationType.XM.getName();
break;
case 9:
relationType = RelationType.ZB.getName();
break;
case 10:
relationType = RelationType.JF.getName();
break;
case 11:
relationType = RelationType.KC.getName();
break;
default:
break;
}
return relationType;
}
return null;
}
public String getMessageStatus(Integer key) {
if (key != null) {
String messageStatus = "";
switch (key) {
//状态 1:草稿、2:待发送、3:发送中、4:已发送、、6:下架、7:上架 (没有发送失败,直接发送中)
case 0:
messageStatus = MessageStatus.DRAFT.getName();
break;
case 1:
messageStatus = MessageStatus.DRAFT.getName();
break;
case 2:
messageStatus = MessageStatus.TO_SEND.getName();
break;
case 3:
messageStatus = MessageStatus.SEND_ING.getName();
break;
case 4:
messageStatus = MessageStatus.SEND_ED.getName();
break;
case 6:
messageStatus = MessageStatus.DOWN.getName();
break;
case 7:
messageStatus = MessageStatus.UP.getName();
break;
case 8:
messageStatus = MessageStatus.SEND_ED_CANCEl.getName();
break;
default:
break;
}
return messageStatus;
}
return null;
}
// /**
// * 直接根据可见范围发消息
// *
// * @param accountVOS 各个业务可见范围
// * @param context
// * @param taskVo 业务参数对象
// * @return
// */
// public Boolean insertAccountMessage(String messageContext, List<AccountVO> accountVOS, RequestContext context, TaskVo taskVo) {
//
// if (!CollectionUtils.isEmpty(accountVOS)) {
// List<AccountVO> accountVOList = new ArrayList<>(accountVOS.size());
// //目前不对消息做唯一性限制
//// if (taskVo.getRelationId() != null && taskVo.getRelationType() != null) {
//// //对于单个用户,判断是否已经收到消息,避免重复发送消息
//// if (accountVOS.size() == 1) {
//// MessageAccountVo one = remoteMessageAccountClient.getOne(accountVOS.get(0).getId(), taskVo.getRelationType(), taskVo.getRelationId());
//// if (one != null) {
//// return false;
//// }
//// } else {
//// //对于多个用户,判断是否已经收到消息,避免重复发送消息
//// List<MessageAccountVo> messageAccounts = remoteMessageAccountClient.getList(taskVo.getRelationType(), taskVo.getRelationId());
//// if (!CollectionUtils.isEmpty(messageAccounts)) {
//// Set<Long> accountIds = new HashSet<>(messageAccounts.size());
//// messageAccounts.forEach(a -> {
//// accountIds.add(a.getAccountId());
//// });
//// accountVOS.forEach(a -> {
//// if (!accountIds.contains(a.getId())) {
//// accountVOList.add(a);
//// }
//// });
//// }
//// }
//// }
//
// List<MessageAccountVo> messageAccounts = new ArrayList<>(accountVOList.size());
// for (AccountVO vo : accountVOList) {
// MessageAccountVo messageAccount = new MessageAccountVo();
// messageAccount.setId(idGenerator.generate());
// messageAccount.setReaded(Constans.NOT_READ);
// messageAccount.setAccountId(vo.getId());
// messageAccount.setRelationType(taskVo.getRelationType());
// messageAccount.setRelationId(taskVo.getRelationId());
// messageAccount.setSiteId(context.getSiteId());
// messageAccount.setCompanyId(context.getCompanyId());
// messageAccount.setCreateByName(context.getAccountName());
// messageAccount.setCreateTime(taskVo.getNow());
// messageAccount.setCreateById(context.getAccountId());
// messageContext = getCompleteContext(messageContext, vo);
// messageAccount.setContext(messageContext);
// messageAccounts.add(messageAccount);
// }
// return remoteMessageAccountClient.save(messageAccounts);
// }
// return false;
// }
/**
* 把带用户姓名参数的消息解析,成完整消息
*
* @param context
* @param accounId
* @param map
* @return
*/
public String getCompleteContext(String context, Long accounId, Map<Long, AccountVO> map) {
if (!StringUtils.isBlank(context)) {
String accountName = "默认";
if (map != null) {
AccountVO accountVO = map.get(accounId);
if (accountVO != null) {
accountName = (accountVO.getFullName() == null ? (accountVO.getName() == null ? "默认" : accountVO.getName()) : accountVO.getFullName());
//必须赋值给context
context = context.replace(MessageParameterEnums.accountName.getName(), accountName);
}
}
}
return context;
}
/**
* 把带用户姓名参数的消息解析,成完整消息 这个适用于单个用户
*
* @param context
* @param content
* @return
*/
public String getCompleteContext(String content, RequestContext context) {
if (!StringUtils.isBlank(content)) {
String accountName = "默认";
if (context != null) {
String fullName = context.getAccountFullName();
String name = context.getAccountName();
accountName = (fullName == null ? (name == null ? "默认" : name) : (fullName.equals("") ? name : fullName));
//必须赋值给context
content = content.replace(MessageParameterEnums.accountName.getName(), accountName);
} else {
logger.info("下上文!!!!!!!!!");
}
}
return content;
}
/**
* 组建消息内容 目前此处只解析业务参数 不对用户名称做解析
*
* @param fieldType 可选参数类型 详情见MessageParameterEnums
* @param messageContext 原始消息内容
* @param taskVo 业务参数对象
* @return
*/
public String buildMessageContext(Integer fieldType, String messageContext, TaskVo taskVo) {
if (fieldType == null || StringUtils.isBlank(messageContext)) {
return messageContext;
}
StringBuffer nameBuffer = new StringBuffer("");
StringBuffer timeBuffer = new StringBuffer("");
StringBuffer scoreBuffer = new StringBuffer("");
StringBuffer reasonBuffer = new StringBuffer("");
String taskName = taskVo.getTaskName();
Date taskStartTime = taskVo.getTaskStratTime();
Date taskEndTime = taskVo.getTaskEndTime();
Double taskScore = taskVo.getTaskScore();
String reason = taskVo.getReason();
if (taskName != null) {
nameBuffer = new StringBuffer("【").append(taskName).append("】");
}
if (taskStartTime != null && taskEndTime != null) {
timeBuffer = new StringBuffer("【").append(format.format(taskStartTime))
.append("--").append(format.format(taskEndTime)).append("】");
}else {
if (taskStartTime != null) {
timeBuffer = new StringBuffer("【").append(format.format(taskStartTime)).append("】");
}
if (taskEndTime != null) {
timeBuffer.append("【").append(format.format(taskEndTime)).append("】");
}
}
if (taskScore != null) {
scoreBuffer.append("【").append(taskScore).append("】");
}
if (reasonBuffer != null) {
reasonBuffer.append("【").append(reason).append("】");
}
switch (fieldType) {
case 1:
return messageContext;
case 2:
return messageContext.replace(MessageParameterEnums.courseName.getName(), nameBuffer);
case 3:
return messageContext.replace(MessageParameterEnums.projectTime.getName(), timeBuffer);
case 4:
return messageContext.replace(MessageParameterEnums.projectName.getName(), nameBuffer);
case 5:
return messageContext.replace(MessageParameterEnums.enrollEndTime.getName(), timeBuffer);
case 6:
return messageContext.replace(MessageParameterEnums.assignmentName.getName(), nameBuffer);
case 7:
return messageContext.replace(MessageParameterEnums.assignmentTime.getName(), timeBuffer);
case 8:
return messageContext.replace(MessageParameterEnums.assignmentScore.getName(), scoreBuffer);
case 9:
return messageContext.replace(MessageParameterEnums.examName.getName(), nameBuffer);
case 10:
return messageContext.replace(MessageParameterEnums.examTime.getName(), timeBuffer);
case 11:
return messageContext.replace(MessageParameterEnums.examScore.getName(), scoreBuffer);
case 12:
return messageContext.replace(MessageParameterEnums.changeReason.getName(), reasonBuffer);
case 13:
return messageContext.replace(MessageParameterEnums.changePoint.getName(), scoreBuffer);
case 14:
return messageContext.replace(MessageParameterEnums.changeTime.getName(), timeBuffer);
case 15:
return messageContext.replace(MessageParameterEnums.researchTime.getName(), timeBuffer);
case 16:
return messageContext.replace(MessageParameterEnums.researchName.getName(), nameBuffer);
case 17:
return messageContext.replace(MessageParameterEnums.liveTime.getName(), timeBuffer);
}
return messageContext;
}
/**
* 统一可见范围类型,由于业务的可见范围类型不统一,这里集中处理
*
* @param relationType 业务类型
* @param scope 可见范围类型
* @return
*/
public Integer getVisibleRange(Integer relationType, Integer scope) {
if (relationType == null || scope == null) {
logger.info("可见范围条件为空!!!");
return -1;
}
switch (relationType) {
// "关联模块类型(、1:学习计划、2:考试、3:调研、4、投票5:报名、6:作业、7:签到、8:项目、9:直播、10:积分、11课程)"
case 1:
if (scope == 0) {
return Constans.VISIBLE_RANGE;
} else {
return Constans.PUBLIC_SITE;
}
case 2:
if (scope == 2) {
return Constans.VISIBLE_RANGE;
} else {
return Constans.PUBLIC_SITE;
}
case 3:
if (scope == 2) {
return Constans.VISIBLE_RANGE;
} else {
return Constans.PUBLIC_SITE;
}
case 4:
break;
case 5:
if (scope == 0) {
return Constans.VISIBLE_RANGE;
} else {
return Constans.PUBLIC_SITE;
}
case 6:
if (scope == 2) {
return Constans.VISIBLE_RANGE;
} else {
return Constans.PUBLIC_SITE;
}
case 7:
break;
case 8:
if (scope == 0) {
return Constans.VISIBLE_RANGE;
} else {
return Constans.PUBLIC_SITE;
}
case 9:
if (scope == 1) {
return Constans.VISIBLE_RANGE;
} else {
return Constans.PUBLIC_SITE;
}
case 10:
break;
case 11:
if (scope == 1) {
return Constans.PUBLIC_SITE;
} else {
return Constans.VISIBLE_RANGE;
}
}
return null;
}
/**
* 用于触发事件消息 根据触发类型 解析业务参数,组装消息内容
* 根据
*
* @param evenType
* @return
*/
public String getContextByEvenType(EvenType evenType, String messageContext, TaskVo taskVo) {
if (!StringUtils.isBlank(messageContext)) {
List<Integer> fieldTypes = new ArrayList<>(20);
switch (evenType) {
case COURSE_UP:
fieldTypes = EvenType.COURSE_UP.getName();
for (Integer a : fieldTypes) {
messageContext = buildMessageContext(a, messageContext, taskVo);
}
break;
case COURSE_FINISH:
fieldTypes = EvenType.COURSE_UP.getName();
for (Integer a : fieldTypes) {
messageContext = buildMessageContext(a, messageContext, taskVo);
}
break;
case ENROLL_START:
fieldTypes = EvenType.COURSE_UP.getName();
for (Integer a : fieldTypes) {
messageContext = buildMessageContext(a, messageContext, taskVo);
}
break;
case TRAINING_AUDIT_PASS:
fieldTypes = EvenType.COURSE_UP.getName();
for (Integer a : fieldTypes) {
messageContext = buildMessageContext(a, messageContext, taskVo);
}
break;
case TRAINING_AUDIT_FAIL:
fieldTypes = EvenType.COURSE_UP.getName();
for (Integer a : fieldTypes) {
messageContext = buildMessageContext(a, messageContext, taskVo);
}
break;
case SIGN_SUCCESS:
fieldTypes = EvenType.COURSE_UP.getName();
for (Integer a : fieldTypes) {
messageContext = buildMessageContext(a, messageContext, taskVo);
}
break;
case TRAINING_FINISH:
fieldTypes = EvenType.COURSE_UP.getName();
for (Integer a : fieldTypes) {
messageContext = buildMessageContext(a, messageContext, taskVo);
}
break;
case ASSIGNMENT_AUDIT_FINISH:
fieldTypes = EvenType.COURSE_UP.getName();
for (Integer a : fieldTypes) {
messageContext = buildMessageContext(a, messageContext, taskVo);
}
break;
case EXAM_AUDIT_FINISH:
fieldTypes = EvenType.COURSE_UP.getName();
for (Integer a : fieldTypes) {
messageContext = buildMessageContext(a, messageContext, taskVo);
}
break;
case POINT_CHANGE:
fieldTypes = EvenType.COURSE_UP.getName();
for (Integer a : fieldTypes) {
messageContext = buildMessageContext(a, messageContext, taskVo);
}
break;
}
}
return messageContext;
}
public String returnParameter(Integer relationType, String content) {
if (relationType != null) {
content = content.replace(MessageParameterEnums.accountName.getName(), ReturnParameterEnums.accountName.getCode());
switch (relationType) {
// "关联模块类型(0自定义消息、1:学习计划、2:考试、3:调研、4、投票5:报名、6:作业、7:签到、8:项目、9:直播、10:积分、11课程)"
case 0:
break;
case 1:
content = content.replace(MessageParameterEnums.projectName.getName(), ReturnParameterEnums.projectName.getCode());
break;
case 2:
content = content.replace(MessageParameterEnums.examTime.getName(), ReturnParameterEnums.examTime.getCode());
content = content.replace(MessageParameterEnums.examName.getName(), ReturnParameterEnums.examName.getCode());
break;
case 3:
content = content.replace(MessageParameterEnums.researchTime.getName(), ReturnParameterEnums.researchTime.getCode());
content = content.replace(MessageParameterEnums.researchName.getName(), ReturnParameterEnums.researchName.getCode());
break;
case 4:
break;
case 5:
content = content.replace(MessageParameterEnums.projectTime.getName(), ReturnParameterEnums.projectTime.getCode());
content = content.replace(MessageParameterEnums.enrollEndTime.getName(), ReturnParameterEnums.enrollEndTime.getCode());
content = content.replace(MessageParameterEnums.projectName.getName(), ReturnParameterEnums.projectName.getCode());
break;
case 6:
content = content.replace(MessageParameterEnums.assignmentTime.getName(), ReturnParameterEnums.assignmentTime.getCode());
content = content.replace(MessageParameterEnums.assignmentName.getName(), ReturnParameterEnums.assignmentName.getCode());
content = content.replace(MessageParameterEnums.assignmentScore.getName(), ReturnParameterEnums.assignmentScore.getCode());
break;
case 7:
content = content.replace(MessageParameterEnums.projectTime.getName(), ReturnParameterEnums.projectTime.getCode());
content = content.replace(MessageParameterEnums.projectName.getName(), ReturnParameterEnums.projectName.getCode());
break;
case 8:
content = content.replace(MessageParameterEnums.projectTime.getName(), ReturnParameterEnums.projectTime.getCode());
content = content.replace(MessageParameterEnums.projectName.getName(), ReturnParameterEnums.projectName.getCode());
content = content.replace(MessageParameterEnums.enrollEndTime.getName(), ReturnParameterEnums.enrollEndTime.getCode());
break;
case 9:
content = content.replace(MessageParameterEnums.liveTime.getName(), ReturnParameterEnums.liveTime.getCode());
break;
case 10:
content = content.replace(MessageParameterEnums.changePoint.getName(), ReturnParameterEnums.changePoint.getCode());
content = content.replace(MessageParameterEnums.changeReason.getName(), ReturnParameterEnums.changeReason.getCode());
content = content.replace(MessageParameterEnums.changeTime.getName(), ReturnParameterEnums.changeTime.getCode());
break;
case 11:
content = content.replace(MessageParameterEnums.courseName.getName(), ReturnParameterEnums.courseName.getCode());
break;
default:
break;
}
} else {
logger.info("relationType为空!!!");
}
return content;
}
public Boolean isUp(Long relationId, Integer relationType) {
if (relationType != null) {
switch (relationType) {
// "关联模块类型(0自定义消息、1:学习计划、2:考试、3:调研、4、投票5:报名、6:作业、7:签到、8:项目、9:直播、10:积分、11课程)"
case 0:
break;
case 1:
TpPlanVo tpPlan = tpPlanClient.getOne(relationId);
if (tpPlan != null) {
TrainingProjectVo one = trainingProjectClient.getOne(tpPlan.getTrainingProjectId());
if (one != null) {
if (one.getStatus() == 1) {
return true;
}
}
}
break;
case 2:
Exam exam = examClient.examViewInfo(relationId);
if (exam != null) {
if (exam.getState() == 2) {
return true;
}
}
break;
case 3:
ResearchVo research = researchClient.viewOne(relationId);
if (research != null) {
if (research.getState() == 1) {
return true;
}
}
break;
case 4:
break;
case 5:
break;
case 6:
Assignment assignment = assignmentClient.get(relationId);
if (assignment != null) {
if (assignment.getStatus() == 2) {
return true;
}
}
break;
case 7:
break;
case 8:
TrainingProjectVo one = trainingProjectClient.getOne(relationId);
if (one != null) {
if (one.getStatus() == 1) {
return true;
}
}
break;
case 9:
LiveActivityVO live = liveActivityClient.getLive(relationId);
if (live != null) {
if (live.getShelves() == 1) {
return true;
}
}
break;
case 10:
break;
case 11:
break;
}
}
return false;
}
}
\ No newline at end of file
package com.yizhi.message.application.controller.util;
import com.yizhi.assignment.application.feign.AssignmentClient;
import com.yizhi.course.application.feign.CourseClient;
import com.yizhi.exam.application.feign.ExamAuthorizeClient;
import com.yizhi.exam.application.vo.exam.VisibleRangeExport;
import com.yizhi.live.application.feign.LiveActivityClient;
import com.yizhi.message.application.constans.Constans;
import com.yizhi.message.application.domain.MessageVisibleRange;
import com.yizhi.research.application.feign.ResearchAuthorizeClient;
import com.yizhi.system.application.system.remote.AccountClient;
import com.yizhi.system.application.system.remote.OrganizationClient;
import com.yizhi.system.application.vo.AccountVO;
import com.yizhi.system.application.vo.OrgVO;
import com.yizhi.training.application.feign.TrainingProjectClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
public class QueryAccount {
@Autowired
private AccountClient accountClient;
@Autowired
private OrganizationClient organizationClient;
@Autowired
private CourseClient courseClient;
@Autowired
private TrainingProjectClient trainingProjectClient;
@Autowired
private ExamAuthorizeClient examAuthorizeClient;
@Autowired
private ResearchAuthorizeClient researchAuthorizeClient;
@Autowired
private AssignmentClient assignmentClient;
@Autowired
private LiveActivityClient liveActivityClient;
private QueryAccount() {
}
/**
* 返回《accountId,account》的map
*
* @param accountIds
* @return
*/
public Map<Long, AccountVO> queryAccountByIds(List<Long> accountIds) {
if (!CollectionUtils.isEmpty(accountIds)) {
Map<Long, AccountVO> map = new HashMap<>(accountIds.size());
List<AccountVO> accountVOS = accountClient.findByIds(accountIds);
//组装map 以免双重循环
if (!CollectionUtils.isEmpty(accountVOS)) {
accountVOS.forEach(a -> {
if (!map.containsKey(a.getId())) {
map.put(a.getId(), a);
}
});
}
return map;
}
return null;
}
/**
* 返回《orgId,org》的map
*
* @param orgIds
* @return
*/
public Map<Long, OrgVO> queryOrgByIds(List<Long> orgIds) {
if (!CollectionUtils.isEmpty(orgIds)) {
Map<Long, OrgVO> map = new HashMap<>(orgIds.size());
List<OrgVO> orgVOS = null;
try {
orgVOS = organizationClient.listByOrgIds(orgIds);
} catch (Exception e) {
e.printStackTrace();
return null;
}
//组装map 以免双重循环
if (!CollectionUtils.isEmpty(orgVOS)) {
orgVOS.forEach(a -> {
if (!map.containsKey(a.getId())) {
map.put(a.getId(), a);
}
});
}
return map;
}
return null;
}
/**
* 全平台可见 根据站点id查询用户
*
* @param siteId
* @return
*/
public List<AccountVO> getAccountBySiteId(Long siteId) {
List<AccountVO> accounts = new ArrayList<>();
List<AccountVO> list = accountClient.findBySiteId(siteId);
if (!CollectionUtils.isEmpty(list)) {
accounts.addAll(list);
}
return accounts;
}
/**
* 给定orgIds accountIds 获取用户集合
*
* @param accountIds
* @param orgIds
* @param companyId
* @return
*/
public List<AccountVO> getAllAccounts(List<Long> accountIds, List<Long> orgIds, Long companyId) {
List<AccountVO> accountVOS = new ArrayList<>();
if (!CollectionUtils.isEmpty(orgIds)) {
for (Long orgId : orgIds) {
accountVOS.addAll(getAccountByOrgId(orgId, companyId));
}
}
if (!CollectionUtils.isEmpty(accountIds)) {
accountVOS.addAll(getAccountByIds(accountIds));
}
return accountVOS;
}
/**
* 获取指定范围的人
* 返回accountVo
*/
public List<AccountVO> getMessageAccounts(List<MessageVisibleRange> list, Long companyId) {
List<Long> orgIds = new ArrayList<>();
List<Long> accountIds = new ArrayList<>();
for (MessageVisibleRange range : list) {
if (range.getType() == Constans.ORG) {
orgIds.add(range.getRelationId());
} else {
accountIds.add(range.getRelationId());
}
}
return getAllAccounts(accountIds, orgIds, companyId);
}
/**
* 根据部门id 查询部门下所有人
*
* @param
* @return
*/
public List<AccountVO> getAccountByOrgId(Long orgId, Long companyId) {
List<AccountVO> accounts = new ArrayList<>();
List<AccountVO> list = accountClient.findByOrgId(orgId, companyId);
if (!CollectionUtils.isEmpty(list)) {
accounts.addAll(list);
}
return accounts;
}
/**
* 根据用户id,查询用户对象
*
* @param accountIds
* @return
*/
public List<AccountVO> getAccountByIds(List<Long> accountIds) {
List<AccountVO> accounts = new ArrayList<>();
List<AccountVO> list = accountClient.findByIds(accountIds);
if (!CollectionUtils.isEmpty(list)) {
accounts.addAll(list);
}
return accounts;
}
/**
* 根据业务获取相应用户信息
*
* @param taskType
* @param taskId
* @param companyId
* @return
*/
public List<AccountVO> getVisibleRangeByTask(Integer taskType, Long taskId, Long companyId) {
switch (taskType) {
// "关联模块类型(、1:学习计划、2:考试、3:调研、4、投票 5:报名、6:作业、7:签到、8:项目、9:直播、10:积分、11课程)"
case 1:
getVisibleRangeByTask(8, taskId, companyId);
break;
case 2:
VisibleRangeExport examRange = examAuthorizeClient.exportVisibleRange(taskId);
if (examRange != null) {
return getAllAccounts(examRange.getAccountIds(), examRange.getOrgIds(), companyId);
}
case 3:
com.yizhi.research.application.vo.VisibleRangeExport researchRange = researchAuthorizeClient.exportVisibleRange(taskId);
if (researchRange != null) {
return getAllAccounts(researchRange.getAccountIds(), researchRange.getOrgIds(), companyId);
}
case 4:
break;
case 5:
getVisibleRangeByTask(8, taskId, companyId);
break;
case 6:
com.yizhi.assignment.application.vo.VisibleRangeExport assignRange = assignmentClient.exportVisibleRange(taskId);
if (assignRange != null) {
return getAllAccounts(assignRange.getAccountIds(), assignRange.getOrgIds(), companyId);
}
case 7:
break;
case 8:
com.yizhi.training.application.vo.manage.VisibleRangeExport trainingRange = trainingProjectClient.exportVisibleRange(taskId);
if (trainingRange != null) {
return getAllAccounts(trainingRange.getAccountIds(), trainingRange.getOrgIds(), companyId);
}
case 9:
com.yizhi.live.application.vo.VisibleRangeExport liveRange = liveActivityClient.getListToMessage(taskId);
if (liveRange != null) {
return getAllAccounts(liveRange.getAccountIds(), liveRange.getOrgIds(), companyId);
}
case 10:
break;
case 11:
com.yizhi.course.application.vo.VisibleRangeExport courseRange = courseClient.vsibleRangeExport(taskId);
if (courseRange != null) {
return getAllAccounts(courseRange.getAccountIds(), courseRange.getOrgIds(), companyId);
}
}
return new ArrayList();
}
}
package com.yizhi.message.application.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* 消息
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Data
@Api(tags = "MessageVo", description = "消息主体表")
@TableName("message")
public class Message extends Model<Message> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id 主体消息表")
@TableId("id")
private Long id;
@ApiModelProperty(value = "消息类型:1、自定义消息;2、系统消息;3、事件触发消息")
@TableField("message_type")
private Integer messageType;
@ApiModelProperty(value = "消息标题")
@TableField("title")
private String title;
@ApiModelProperty(value = "模板名称 (系统消息需要)")
@TableField("template_name")
private String templateName;
@ApiModelProperty(value = "事件名称 (触发消息需要)")
@TableField("event_name")
private String eventName;
@ApiModelProperty(value = "发送方式:1、站内信;2、短信;3、邮件")
@TableField("send_type")
private Integer sendType;
@ApiModelProperty(value = "关联模块类型(应用场景)1:学习计划、2:考试、3:调研、4、投票5:报名、6:作业、7:签到、8:项目、9:直播、10:积分 ")
@TableField("relation_type")
private Integer relationType;
@ApiModelProperty(value = "状态 1:草稿、2:待发送、3:发送中、4:已发送、、6:下架、7:上架、8:已发送被撤回 (没有发送失败,直接发送中)")
@TableField("status")
private Integer status;
@ApiModelProperty(value = "指定范围(0:全平台,1:指定用户)")
@TableField("visible_range")
private Integer visibleRange;
@ApiModelProperty(value = "是否删除(0:否,1:是)")
@TableField("deleted")
private Integer deleted;
@ApiModelProperty(value = "发送时间 (新增自定义消息需要)")
@TableField("send_time")
private Date sendTime;
@ApiModelProperty(value = "站点id")
@TableField("site_id")
private Long siteId;
@ApiModelProperty(value = "公司id")
@TableField("company_id")
private Long companyId;
@ApiModelProperty(value = "触发消息类型")
@TableField("even_type")
private Long evenType;
@ApiModelProperty(value = "创建人id")
@TableField(value = "create_by_id", fill = FieldFill.INSERT)
private Long createById;
@ApiModelProperty(value = "创建人账号")
@TableField(value = "create_by_name", fill = FieldFill.INSERT)
private String createByName;
@ApiModelProperty(value = "创建时间")
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
@ApiModelProperty(value = "修改人id")
@TableField(value = "update_by_id", fill = FieldFill.INSERT)
private Long updateById;
@ApiModelProperty(value = "修改人账号")
@TableField(value = "update_by_name", fill = FieldFill.INSERT)
private String updateByName;
@ApiModelProperty(value = "修改时间")
@TableField(value = "update_time", fill = FieldFill.INSERT)
private Date updateTime;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.message.application.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
*
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Data
@Api(tags = "MessageAccountVo", description = "学员收到消息记录表")
@TableName("message_account")
public class MessageAccount extends Model<MessageAccount> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id 学员收到消息记录表")
@TableId("id")
private Long id;
@ApiModelProperty(value = "消息id")
@TableField("message_id")
private Long messageId;
@ApiModelProperty(value = "待发消息id")
@TableField("message_remind_id")
private Long messageRemindId;
@ApiModelProperty(value = "账号id")
@TableField("account_id")
private Long accountId;
@ApiModelProperty(value = "消息内容")
@TableField("context")
private String context;
@ApiModelProperty(value = "关联模块类型(、1:学习计划、2:考试、3:调研、4、投票5:报名、6:作业、7:签到、8:项目、9:直播、10:积分)")
@TableField("relation_type")
private Integer relationType;
@ApiModelProperty(value = "关联的业务id: 比如调研id")
@TableField("relation_id")
private Long relationId;
@ApiModelProperty(value = "指定范围指定范围(0:全平台,1:指定用户)")
@TableField("visible_range")
private Integer visibleRange;
@ApiModelProperty(value = "是否已读(0:否,1:是)")
@TableField("readed")
private Integer readed;
@ApiModelProperty(value = "读取时间")
@TableField("read_time")
private Date readTime;
@ApiModelProperty(value = "是否删除")
@TableField("deleted")
private Integer deleted;
@ApiModelProperty(value = "消息标题")
@TableField(exist = false)
private String title;
@ApiModelProperty(value = "站点id")
@TableField("site_id")
private Long siteId;
@ApiModelProperty(value = "公司id")
@TableField("company_id")
private Long companyId;
@ApiModelProperty(value = "创建人id")
@TableField(value = "create_by_id", fill = FieldFill.INSERT)
private Long createById;
@ApiModelProperty(value = "创建人账号")
@TableField(value = "create_by_name", fill = FieldFill.INSERT)
private String createByName;
@ApiModelProperty(value = "创建时间")
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
@ApiModelProperty(value = "修改人id")
@TableField(value = "update_by_id", fill = FieldFill.INSERT)
private Long updateById;
@ApiModelProperty(value = "修改人账号")
@TableField(value = "update_by_name", fill = FieldFill.INSERT)
private String updateByName;
@ApiModelProperty(value = "修改时间")
@TableField(value = "update_time", fill = FieldFill.INSERT)
private Date updateTime;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.message.application.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
*
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Data
@Api(tags = "MessageContextVo", description = "消息内容表")
@TableName("message_context")
public class MessageContext extends Model<MessageContext> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id")
@TableField("id")
private Long id;
@ApiModelProperty(value = "消息id")
@TableField("message_id")
private Long messageId;
@ApiModelProperty(value = "消息内容(带可变参数,不完整)")
@TableField("context")
private String context;
@ApiModelProperty(value = "创建人id")
@TableField(value = "create_by_id", fill = FieldFill.INSERT)
private Long createById;
@ApiModelProperty(value = "创建人姓名")
@TableField(value = "create_by_name", fill = FieldFill.INSERT)
private String createByName;
@ApiModelProperty(value = "创建时间")
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
@ApiModelProperty(value = "修改人id")
@TableField(value = "update_by_id", fill = FieldFill.INSERT)
private Long updateById;
@ApiModelProperty(value = "修改人账号")
@TableField(value = "update_by_name", fill = FieldFill.INSERT)
private String updateByName;
@ApiModelProperty(value = "修改时间")
@TableField(value = "update_time", fill = FieldFill.INSERT)
private Date updateTime;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.message.application.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
*
* </p>
*
* @author hutao123
* @since 2019-09-12
*/
@Data
@Api(tags = "MessageParamRelationVo", description = "")
@TableName("message_param_relation")
public class MessageParamRelation extends Model<MessageParamRelation> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "消息与可选参数关联表")
@TableId("id")
private Long id;
@ApiModelProperty(value = "消息id")
@TableField("message_id")
private Long messageId;
@ApiModelProperty(value = "可选参数id")
@TableField("message_parameter_id")
private Long messageParameterId;
@ApiModelProperty(value = "可变参数类型 :1、用户姓名;2、课程名称;3、项目时间;4、项目名称;5、报名截止时间;更多请看数据库")
@TableField("field_type")
private Integer fieldType;
@ApiModelProperty(value = "是否删除")
@TableField("deleted")
private Integer deleted;
@ApiModelProperty(value = "创建人id")
@TableField(value = "create_by_id", fill = FieldFill.INSERT)
private Long createById;
@ApiModelProperty(value = "创建人账号")
@TableField(value = "create_by_name", fill = FieldFill.INSERT)
private String createByName;
@ApiModelProperty(value = "创建时间")
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
@ApiModelProperty(value = "修改人id")
@TableField(value = "update_by_id", fill = FieldFill.INSERT)
private Long updateById;
@ApiModelProperty(value = "修改人账号")
@TableField(value = "update_by_name", fill = FieldFill.INSERT)
private String updateByName;
@ApiModelProperty(value = "修改时间")
@TableField(value = "update_time", fill = FieldFill.INSERT)
private Date updateTime;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.message.application.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
*
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Data
@Api(tags = "MessageParameterVo", description = "可选参数表")
@TableName("message_parameter")
public class MessageParameter extends Model<MessageParameter> {
private static final long serialVersionUID = 1L;
@TableId("id")
private Long id;
@ApiModelProperty(value = "可变参数名称")
@TableField("name")
private String name;
@ApiModelProperty(value = "消息类型:比如: 1、自定义消息 2、系统消息 3、事件触发消息")
@TableField("message_type")
private Integer messageType;
@ApiModelProperty(value = "可变参数类型 :1、用户姓名;2、课程名称;3、项目时间;4、项目名称;5、报名截止时间;更多请看数据库")
@TableField("field_type")
private Integer fieldType;
@ApiModelProperty(value = "关联模块对应的字段")
@TableField("relation_field")
private String relationField;
@ApiModelProperty(value = "关联模块类型(0:自定义消息、1:学习计划、2:考试、3:调研、4、投票5:报名、6:作业、7:签到、8:项目、9:直播、10:积分)")
@TableField("relation_type")
private Integer relationType;
@ApiModelProperty(value = "是否删除")
@TableField("deleted")
private Integer deleted;
@ApiModelProperty(value = "站点id")
@TableField("site_id")
private Long siteId;
@ApiModelProperty(value = "公司id")
@TableField("company_id")
private Long companyId;
@ApiModelProperty(value = "创建人id")
@TableField(value = "create_by_id", fill = FieldFill.INSERT)
private Long createById;
@ApiModelProperty(value = "创建人账号")
@TableField(value = "create_by_name", fill = FieldFill.INSERT)
private String createByName;
@ApiModelProperty(value = "创建时间")
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
@ApiModelProperty(value = "修改人id")
@TableField(value = "update_by_id", fill = FieldFill.INSERT)
private Long updateById;
@ApiModelProperty(value = "修改人账号")
@TableField(value = "update_by_name", fill = FieldFill.INSERT)
private String updateByName;
@ApiModelProperty(value = "修改时间")
@TableField(value = "update_time", fill = FieldFill.INSERT)
private Date updateTime;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.message.application.domain;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* <p>
*
* </p>
*
* @author taoge123
* @since 2020-03-29
*/
@Data
@ApiModel(value = "MessageReadRecordVo", description = "")
@TableName("message_read_record")
public class MessageReadRecord {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id 学员收到消息记录表")
private Long id;
@ApiModelProperty(value = "用户消息id")
@TableField("message_account_id")
private Long messageAccountId;
@ApiModelProperty(value = "账号id")
@TableField("account_id")
private Long accountId;
@ApiModelProperty(value = "指定范围指定范围(0:全平台,1:指定用户)")
@TableField("visible_range")
private Integer visibleRange;
@ApiModelProperty(value = "是否已读(0:否,1:是)")
private Integer readed;
@ApiModelProperty(value = "读取时间")
@TableField("read_time")
private Date readTime;
@ApiModelProperty(value = "创建人id")
@TableField(value = "create_by_id", fill = FieldFill.INSERT)
private Long createById;
@ApiModelProperty(value = "创建人账号")
@TableField(value = "create_by_name", fill = FieldFill.INSERT)
private String createByName;
@ApiModelProperty(value = "创建时间")
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
}
package com.yizhi.message.application.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
*
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Data
@Api(tags = "MessageRemindVo", description = "各个业务设置提醒时的数据")
@TableName("message_remind")
public class MessageRemind extends Model<MessageRemind> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "提醒id ")
@TableId("id")
private Long id;
@ApiModelProperty(value = "消息类型:1、自定义消息;2、系统消息;3、事件触发消息")
@TableField("message_type")
private Integer messageType;
@ApiModelProperty(value = "消息id")
@TableField("message_id")
private Long messageId;
@ApiModelProperty(value = "消息内容(完整版)")
@TableField("message_context")
private String messageContext;
@ApiModelProperty(value = "关联模块类型(、1:学习计划、2:考试、3:调研、4、投票5:报名、6:作业、7:签到、8:项目、9:直播、10:积分)")
@TableField("relation_type")
private Integer relationType;
@ApiModelProperty(value = "关联的业务id: 比如调研id")
@TableField("relation_id")
private Long relationId;
@ApiModelProperty(value = "提醒时间事件类型 1:业务开始时间、 2:业务结束时间、3:自定义时间")
@TableField("time_event_type")
private Integer timeEventType;
@ApiModelProperty(value = "发生时间枚举:1:五分钟前、2:十分钟前、3:三十分钟前、4:一个小时前、5:两个小时前、6:一天前、7:两天前")
@TableField("time_type")
private Integer timeType;
@ApiModelProperty(value = "最终发送时间")
@TableField("send_time")
private Date sendTime;
@ApiModelProperty(value = "状态 1:草稿、2:待发送、3:发送中、4:已发送、、6:下架、7:上架 (没有发送失败,直接发送中)")
@TableField("status")
private Integer status;
@ApiModelProperty(value = "业务状态:1代表上架状态,0:代表非上架状态(只有1才允许发送消息)")
@TableField("task_status")
private Integer taskStatus;
@ApiModelProperty(value = "指定范围指定范围(0:全平台,1:指定用户)")
@TableField("visible_range")
private Integer visibleRange;
@ApiModelProperty(value = "发送方式:1、站内信;2、短信;3、邮件")
@TableField("send_type")
private Integer sendType;
@ApiModelProperty(value = "用户id 主要用于触发消息 个人完成发消息类型")
@TableField("account_id")
private Long accountId;
@ApiModelProperty(value = "是否删除(0:否,1:是)")
@TableField("deleted")
private Integer deleted;
@ApiModelProperty(value = "站点id")
@TableField("site_id")
private Long siteId;
@ApiModelProperty(value = "公司id")
@TableField("company_id")
private Long companyId;
@ApiModelProperty(value = "创建人id")
@TableField(value = "create_by_id", fill = FieldFill.INSERT)
private Long createById;
@ApiModelProperty(value = "创建人账号")
@TableField(value = "create_by_name", fill = FieldFill.INSERT)
private String createByName;
@ApiModelProperty(value = "创建时间")
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
@ApiModelProperty(value = "修改人id")
@TableField(value = "update_by_id", fill = FieldFill.INSERT)
private Long updateById;
@ApiModelProperty(value = "修改人账号")
@TableField(value = "update_by_name", fill = FieldFill.INSERT)
private String updateByName;
@ApiModelProperty(value = "修改时间")
@TableField(value = "update_time", fill = FieldFill.INSERT)
private Date updateTime;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.message.application.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
*
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Data
@Api(tags = "MessageVisibleRangeVo", description = "")
@TableName("message_visible_range")
public class MessageVisibleRange extends Model<MessageVisibleRange> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id")
@TableId("id")
private Long id;
@ApiModelProperty(value = "消息id")
@TableField("message_id")
private Long messageId;
@ApiModelProperty(value = "类型(1、部门;2、用户)")
@TableField("type")
private Integer type;
@ApiModelProperty(value = "可能是部门id 也可能是用户id")
@TableField("relation_id")
private Long relationId;
@ApiModelProperty(value = "是否删除(0:否,1:是)")
@TableField("deleted")
private Integer deleted;
@ApiModelProperty(value = "创建人")
@TableField(value = "create_by_id", fill = FieldFill.INSERT)
private Long createById;
@ApiModelProperty(value = "创建人姓名")
@TableField(value = "create_by_name", fill = FieldFill.INSERT)
private String createByName;
@ApiModelProperty(value = "创建时间")
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
@ApiModelProperty(value = "修改人id")
@TableField(value = "update_by_id", fill = FieldFill.INSERT)
private Long updateById;
@ApiModelProperty(value = "修改人账号")
@TableField(value = "update_by_name", fill = FieldFill.INSERT)
private String updateByName;
@ApiModelProperty(value = "修改时间")
@TableField(value = "update_time", fill = FieldFill.INSERT)
private Date updateTime;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.message.application.event;
import com.yizhi.application.orm.id.IdGenerator;
import com.yizhi.core.application.event.EventWrapper;
import com.yizhi.message.application.service.MessageRemindService;
import com.yizhi.message.application.controller.util.MessageUtil;
import com.yizhi.message.application.vo.MessageRemindVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* 各个微服务业务处理完后向培训过项目微服务发送业务消息
* 的处理器
*
* @Author: shengchenglong
* @Date: 2018/4/18 11:19
*/
@Service
@Transactional
public class MessageEventHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(MessageEventHandler.class);
@Autowired
private IdGenerator idGenerator;
@Autowired
private MessageUtil messageUtil;
@Autowired
private MessageRemindService messageRemindService;
public void handle(EventWrapper<MessageRemindVo> ew) {
MessageRemindVo remindVo = ew.getData();
LOGGER.info("收到消息,开始保存待发消息,其remindVo:"+ remindVo);
if (remindVo != null) {
messageRemindService.insertMessageRemind(remindVo);
}else {
LOGGER.info("remindVo"+remindVo+"接到的消息内容为空!!!");
}
}
}
package com.yizhi.message.application.event;
import com.yizhi.core.application.event.EventWrapper;
import com.yizhi.message.application.constans.Constans;
import com.yizhi.message.application.vo.MessageRemindVo;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @Author: shengchenglong
* @Date: 2018/4/18 11:14
*/
@Component
@RabbitListener(queues = Constans.MESSAGE_QUEUE)
public class MessageEventListener {
@Autowired
private MessageEventHandler messageEventHandler;
@RabbitHandler
public void processBizEvent(EventWrapper<MessageRemindVo> ew) {
messageEventHandler.handle(ew);
}
}
package com.yizhi.message.application.mapper;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.message.application.domain.MessageAccount;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* <p>
* Mapper 接口
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Mapper
public interface MessageAccountMapper extends BaseMapper<MessageAccount> {
List<MessageAccount> getList(@Param("siteId") Long siteId, @Param("accountId") Long accountId, Page<MessageAccount> page);
Integer getListNum(@Param("siteId") Long siteId, @Param("accountId") Long accountId);
}
package com.yizhi.message.application.mapper;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.yizhi.message.application.domain.MessageContext;
/**
* <p>
* Mapper 接口
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
public interface MessageContextMapper extends BaseMapper<MessageContext> {
}
package com.yizhi.message.application.mapper;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.message.application.domain.Message;
import com.yizhi.message.application.vo.MessageManageVo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* <p>
* 消息 Mapper 接口
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
public interface MessageMapper extends BaseMapper<Message> {
/**
* 分页获取消息
*
* @param title
* @param page
* @return
*/
public List<MessageManageVo> getPage(@Param("messageType") Integer messageType, @Param("title") String title,@Param("siteId") Long siteId, Page<MessageManageVo> page);
public Integer getPageNum(@Param("messageType") Integer messageType, @Param("title") String title,@Param("siteId") Long siteId);
public List<Message> getList(@Param("messageType") Integer messageType,@Param("siteId") Long siteId);
}
package com.yizhi.message.application.mapper;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.yizhi.message.application.domain.MessageParamRelation;
/**
* <p>
* Mapper 接口
* </p>
*
* @author hutao123
* @since 2019-09-12
*/
public interface MessageParamRelationMapper extends BaseMapper<MessageParamRelation> {
}
package com.yizhi.message.application.mapper;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.yizhi.message.application.domain.MessageParameter;
import com.yizhi.message.application.vo.MessageParameterVo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* <p>
* Mapper 接口
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
public interface MessageParameterMapper extends BaseMapper<MessageParameter> {
/**
* @param messageType 消息类型:比如: 1、自定义消息 2、系统消息 3、事件触发消息
* @param relationType 应用场景(关联模块类型)(0:通用、1:学习计划、2:考试、3:调研、4、投票5:报名、6:作业、7:签到、8:项目、9:直播 、10积分)
* @return
*/
List<MessageParameterVo> getList(@Param("messageType") Integer messageType, @Param("relationType") Integer relationType,@Param("siteId")Long siteId);
}
package com.yizhi.message.application.mapper;
import com.yizhi.message.application.domain.MessageReadRecord;
import com.baomidou.mybatisplus.mapper.BaseMapper;
/**
* <p>
* Mapper 接口
* </p>
*
* @author taoge123
* @since 2020-03-29
*/
public interface MessageReadRecordMapper extends BaseMapper<MessageReadRecord> {
}
package com.yizhi.message.application.mapper;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.yizhi.message.application.domain.MessageRemind;
import java.util.List;
/**
* <p>
* Mapper 接口
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
public interface MessageRemindMapper extends BaseMapper<MessageRemind> {
List<MessageRemind> getListByTime();
}
package com.yizhi.message.application.mapper;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.yizhi.message.application.domain.MessageVisibleRange;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* <p>
* Mapper 接口
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
public interface MessageVisibleRangeMapper extends BaseMapper<MessageVisibleRange> {
public List<MessageVisibleRange> getList(@Param("messageIds") List<Long> messageIds);
}
package com.yizhi.message.application.service;
import com.yizhi.message.application.domain.MessageAccount;
import com.yizhi.message.application.domain.MessageReadRecord;
import com.baomidou.mybatisplus.service.IService;
import java.util.List;
import java.util.Map;
/**
* <p>
* 服务类
* </p>
*
* @author taoge123
* @since 2020-03-29
*/
public interface IMessageReadRecordService extends IService<MessageReadRecord> {
Integer insertReadRecord(MessageAccount messageAccount);
//<messageAccountId,accountId>
Map<Long,Long> getMap(List<Long> messageAccountIds);
Integer getReadNum();
Integer batchInsertReadRecord(List<MessageReadRecord> messageReadRecords);
}
package com.yizhi.message.application.service;
import com.baomidou.mybatisplus.service.IService;
import com.yizhi.message.application.domain.MessageAccount;
/**
* <p>
* 服务类
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
public interface MessageAccountService extends IService<MessageAccount> {
}
package com.yizhi.message.application.service;
import com.baomidou.mybatisplus.service.IService;
import com.yizhi.message.application.domain.MessageContext;
/**
* <p>
* 服务类
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
public interface MessageContextService extends IService<MessageContext> {
}
package com.yizhi.message.application.service;
import com.baomidou.mybatisplus.service.IService;
import com.yizhi.message.application.domain.MessageParamRelation;
/**
* <p>
* 服务类
* </p>
*
* @author hutao123
* @since 2019-09-12
*/
public interface MessageParamRelationService extends IService<MessageParamRelation> {
}
package com.yizhi.message.application.service;
import com.baomidou.mybatisplus.service.IService;
import com.yizhi.message.application.domain.MessageParameter;
import com.yizhi.message.application.vo.MessageParameterVo;
import java.util.List;
/**
* <p>
* 服务类
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
public interface MessageParameterService extends IService<MessageParameter> {
List<MessageParameterVo> getList(Integer messageType, Integer relationType);
}
package com.yizhi.message.application.service;
import com.baomidou.mybatisplus.service.IService;
import com.yizhi.message.application.domain.MessageRemind;
import com.yizhi.message.application.vo.MessageRemindVo;
import com.yizhi.message.application.vo.MessageVo;
/**
* <p>
* 服务类
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
public interface MessageRemindService extends IService<MessageRemind> {
void sendMessageHandle();
Integer insertMessageRemind(MessageRemindVo messageRemindVo);
MessageVo get(Integer relationType, Long relationId);
Integer updateMessageRemind(MessageRemindVo messageRemindVo);
}
package com.yizhi.message.application.service;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.IService;
import com.yizhi.message.application.domain.Message;
import com.yizhi.message.application.vo.CancelSendMessageVo;
import com.yizhi.message.application.vo.MessageManageVo;
import com.yizhi.message.application.vo.MessageVo;
import java.util.List;
import java.util.Map;
/**
* <p>
* 消息 服务类
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
public interface MessageService extends IService<Message> {
public Integer save(MessageVo message);
public Page<MessageManageVo> getPage(Integer messageType, String title, Page<MessageManageVo> page);
public MessageVo get(Long id);
public Integer update(MessageVo messageVo);
Integer upOrDown(CancelSendMessageVo vo);
Integer cancel(CancelSendMessageVo vo);
/**
* 点击发送时,保存到提醒表,以及添加定时任务
*
* @param vo
* @return
*/
Integer send(CancelSendMessageVo vo);
List<MessageVo> getListByRelationType(Integer relationType);
Map<Long, String> getMessageTitleMap(List<Long> messageIds);
}
package com.yizhi.message.application.service;
import com.baomidou.mybatisplus.service.IService;
import com.yizhi.message.application.domain.MessageVisibleRange;
/**
* <p>
* 服务类
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
public interface MessageVisibleRangeService extends IService<MessageVisibleRange> {
}
package com.yizhi.message.application.service.impl;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yizhi.message.application.domain.MessageAccount;
import com.yizhi.message.application.mapper.MessageAccountMapper;
import com.yizhi.message.application.service.MessageAccountService;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Service
public class MessageAccountServiceImple extends ServiceImpl<MessageAccountMapper, MessageAccount> implements MessageAccountService {
}
package com.yizhi.message.application.service.impl;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yizhi.message.application.domain.MessageContext;
import com.yizhi.message.application.mapper.MessageContextMapper;
import com.yizhi.message.application.service.MessageContextService;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Service
public class MessageContextServiceImple extends ServiceImpl<MessageContextMapper, MessageContext> implements MessageContextService {
}
package com.yizhi.message.application.service.impl;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yizhi.message.application.domain.MessageParamRelation;
import com.yizhi.message.application.mapper.MessageParamRelationMapper;
import com.yizhi.message.application.service.MessageParamRelationService;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author hutao123
* @since 2019-09-12
*/
@Service
public class MessageParamRelationServiceImple extends ServiceImpl<MessageParamRelationMapper, MessageParamRelation> implements MessageParamRelationService {
}
package com.yizhi.message.application.service.impl;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yizhi.core.application.context.ContextHolder;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.message.application.domain.MessageParameter;
import com.yizhi.message.application.mapper.MessageParameterMapper;
import com.yizhi.message.application.service.MessageParameterService;
import com.yizhi.message.application.vo.MessageParameterVo;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 服务实现类
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Service
public class MessageParameterServiceImple extends ServiceImpl<MessageParameterMapper, MessageParameter> implements MessageParameterService {
@Override
public List<MessageParameterVo> getList(Integer messageType, Integer relationType) {
RequestContext context = ContextHolder.get();
List<MessageParameterVo> list = this.baseMapper.getList(messageType, relationType, context.getSiteId());
return list;
}
}
package com.yizhi.message.application.service.impl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yizhi.application.orm.id.IdGenerator;
import com.yizhi.core.application.context.ContextHolder;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.core.application.task.AbstractTaskHandler;
import com.yizhi.core.application.task.TaskExecutor;
import com.yizhi.message.application.constans.Constans;
import com.yizhi.message.application.domain.MessageAccount;
import com.yizhi.message.application.domain.MessageReadRecord;
import com.yizhi.message.application.mapper.MessageReadRecordMapper;
import com.yizhi.message.application.service.IMessageReadRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* <p>
* 服务实现类
* </p>
*
* @author taoge123
* @since 2020-03-29
*/
@Service
public class MessageReadRecordServiceImpl extends ServiceImpl<MessageReadRecordMapper, MessageReadRecord> implements IMessageReadRecordService {
@Autowired
private TaskExecutor taskExecutor;
@Autowired
private IdGenerator idGenerator;
@Autowired
private MessageReadRecordMapper messageReadRecordMapper;
@Autowired
private IMessageReadRecordService messageReadRecordService;
@Override
public Integer insertReadRecord(MessageAccount messageAccount) {
RequestContext context = ContextHolder.get();
taskExecutor.asynExecute(new AbstractTaskHandler() {
@Override
public void handle() {
MessageReadRecord readRecord1 = new MessageReadRecord();
readRecord1.setReaded(1);
readRecord1.setAccountId(context.getAccountId());
readRecord1.setMessageAccountId(messageAccount.getId());
Integer readNum = messageReadRecordMapper.selectCount(new EntityWrapper<>(readRecord1));
if (readNum == 0) {
MessageReadRecord readRecord = new MessageReadRecord();
readRecord.setId(idGenerator.generate());
readRecord.setMessageAccountId(messageAccount.getId());
readRecord.setVisibleRange(messageAccount.getVisibleRange());
readRecord.setAccountId(context.getAccountId());
readRecord.setCreateByName(context.getAccountName());
readRecord.setReaded(1);
readRecord.setReadTime(new Date());
messageReadRecordMapper.insert(readRecord);
}
}
});
return 1;
}
@Override
public Map<Long, Long> getMap(List<Long> messageAccountIds) {
Map<Long, Long> map = null;
if (!CollectionUtils.isEmpty(messageAccountIds)) {
map = new HashMap<>();
RequestContext context = ContextHolder.get();
MessageReadRecord readRecord = new MessageReadRecord();
readRecord.setReaded(1);
readRecord.setAccountId(context.getAccountId());
EntityWrapper wrapper = new EntityWrapper(readRecord);
wrapper.in("message_account_id", messageAccountIds);
List<MessageReadRecord> readRecords = this.selectList(wrapper);
if (!CollectionUtils.isEmpty(readRecords)) {
for (MessageReadRecord a : readRecords) {
if (!map.containsKey(a.getMessageAccountId())) {
map.put(a.getMessageAccountId(), a.getAccountId());
}
}
}
}
return map;
}
@Override
public Integer getReadNum() {
RequestContext context = ContextHolder.get();
MessageReadRecord readRecord = new MessageReadRecord();
readRecord.setReaded(1);
readRecord.setAccountId(context.getAccountId());
readRecord.setVisibleRange(Constans.PUBLIC_SITE);
EntityWrapper wrapper = new EntityWrapper(readRecord);
return this.selectCount(wrapper);
}
@Override
public Integer batchInsertReadRecord(List<MessageReadRecord> messageReadRecords) {
if (CollectionUtils.isEmpty(messageReadRecords)) {
return null;
}
taskExecutor.asynExecute(new AbstractTaskHandler() {
@Override
public void handle() {
messageReadRecordService.insertBatch(messageReadRecords);
}
});
return 1;
}
}
package com.yizhi.message.application.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yizhi.application.orm.id.IdGenerator;
import com.yizhi.core.application.context.ContextHolder;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.message.application.constans.Constans;
import com.yizhi.message.application.controller.util.MessageUtil;
import com.yizhi.message.application.controller.util.QueryAccount;
import com.yizhi.message.application.domain.*;
import com.yizhi.message.application.enums.MessageStatus;
import com.yizhi.message.application.service.MessageAccountService;
import com.yizhi.message.application.service.MessageParamRelationService;
import com.yizhi.message.application.service.MessageRemindService;
import com.yizhi.message.application.service.MessageVisibleRangeService;
import com.yizhi.message.application.util.DateConvertor;
import com.yizhi.message.application.vo.MessageVo;
import com.yizhi.message.application.vo.TaskVo;
import com.yizhi.message.application.mapper.*;
import com.yizhi.system.application.vo.AccountVO;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/**
* <p>
* 服务实现类
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Service
public class MessageRemindServiceImple extends ServiceImpl<MessageRemindMapper, MessageRemind> implements MessageRemindService {
@Autowired
private MessageRemindMapper messageRemindMapper;
@Autowired
private MessageVisibleRangeMapper messageVisibleRangeMapper;
@Autowired
private MessageMapper messageMapper;
@Autowired
private QueryAccount queryAccount;
@Autowired
private MessageAccountMapper messageAccountMapper;
@Autowired
private MessageAccountService messageAccountService;
@Autowired
private IdGenerator idGenerator;
@Autowired
private MessageUtil messageUtil;
@Autowired
private MessageContextMapper messageContextMapper;
@Autowired
private MessageVisibleRangeService messageVisibleRangeService;
@Autowired
private MessageParamRelationService messageParamRelationService;
private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
private static final Logger logger = LoggerFactory.getLogger(MessageRemindServiceImple.class);
@Override
// @Transactional(rollbackFor = Exception.class)
public void sendMessageHandle() {
List<MessageRemind> messageReminds = messageRemindMapper.getListByTime();
List<AccountVO> accountVOS = null;
if (CollectionUtils.isNotEmpty(messageReminds)) {
for (MessageRemind remind : messageReminds) {
logger.info("-----------messageReming:-------------" + remind.toString());
if (remind.getMessageType() != 1) {
//非自定义消息需要判断业务状态,
Boolean up = null;
try {
up = messageUtil.isUp(remind.getRelationId(), remind.getRelationType());
} catch (Exception e) {
e.printStackTrace();
logger.info("判断业务是否为上架状态时,出现异常!!");
continue;
}
if (!up) {
logger.info("业务为非上架状态,不允许发消息!!!");
}
}
Message message = messageMapper.selectById(remind.getMessageId());
if (message != null) {
try {
if (!MessageStatus.DOWN.getCode().equals(message.getStatus())) {
updateMessageRemindStatus(remind.getId(), MessageStatus.SEND_ING.getCode());
logger.info("更新待发消息的状态为发送中");
Integer num = 0;
//如果有accountId,则不用管可见范围类型,直接发
if (remind.getAccountId() != null) {
//有用户id直接发消息;
accountVOS = queryAccount.getAccountByIds(Arrays.asList(remind.getAccountId()));
} else {
//修改逻辑为 若为全站点发消息,则只插入一条数据,用户参数则在查询的时候替换
if (Constans.PUBLIC_SITE.equals(remind.getVisibleRange())) {
num = insertMessageAccountByPublic(remind);
} else {
//获取指定范围内的用户
accountVOS = getAllAccounts(remind);
}
}
//开始发消息
if (CollectionUtils.isNotEmpty(accountVOS)) {
logger.info("获取到用户数为:" + accountVOS.size());
num = insertMessageAccount(accountVOS, remind);
} else {
if (remind.getAccountId() != null || (remind.getAccountId() == null && !Constans.PUBLIC_SITE.equals(remind.getVisibleRange()))) {
logger.info("用户查询为空!!!");
}
}
if (num > 0) {
if (remind.getMessageType() == 1) {
logger.info("更新主体消息的状态为已发送");
//更新消息的状态为已发送
updateMessageStatus(remind.getMessageId(), MessageStatus.SEND_ED.getCode());
}
logger.info("更新待发消息的状态为已发送");
//更新待发消息的状态为已发送
updateMessageRemindStatus(remind.getId(), MessageStatus.SEND_ED.getCode());
}
logger.info("处理完毕!!!!");
} else {
logger.info("下架状态不执行!!!");
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
} else {
logger.info("数据库没有该主体消息");
}
}
} else {
logger.info("数据库没有该待发消息");
}
}
/**
* 解析参数,获取只含用户名称参数的消息内容
*
* @param messageId
* @param taskVo
* @return
*/
public String getContext(com.yizhi.message.application.vo.MessageRemindVo vo, TaskVo taskVo) {
String messageContext = "";
Long siteId = vo.getRequestContext().getSiteId();
if (vo.getMessageId() == null) {
logger.info("查询消息内容时,id为空!");
return messageContext;
}
if (null != vo.getMessageType() && vo.getMessageType() == 3) {
if (siteId == null) {
logger.info("siteId为空!!");
return messageContext;
}
Message message = new Message();
message.setEvenType(vo.getMessageId());
message.setSiteId(siteId);
message.setDeleted(Constans.NOT_DELETED);
message = messageMapper.selectOne(message);
if (message != null) {
vo.setMessageId(message.getId());
logger.info("接收到触发消息:messageId||" + message.getId());
}
}
MessageContext context = new MessageContext();
context.setMessageId(vo.getMessageId());
context = messageContextMapper.selectOne(context);
if (context != null) {
logger.info("数据库查询出来的消息内容伪:" + JSON.toJSONString(context));
if (!StringUtils.isBlank(context.getContext())) {
messageContext = context.getContext();
MessageParamRelation paramRelation = new MessageParamRelation();
paramRelation.setMessageId(vo.getMessageId());
paramRelation.setDeleted(Constans.NOT_DELETED);
EntityWrapper wrapper = new EntityWrapper(paramRelation);
List<MessageParamRelation> list = messageParamRelationService.selectList(wrapper);
if (CollectionUtils.isNotEmpty(list)) {
for (MessageParamRelation a : list) {
messageContext = messageUtil.buildMessageContext(a.getFieldType(), messageContext, taskVo);
}
}
}
}
logger.info("解析完的消息内容为:" + messageContext);
return messageContext;
}
/**
* 根据可见范围类型获取相应人员集合
*
* @param remind
* @param
* @return
*/
public List<AccountVO> getAllAccounts(MessageRemind remind) {
List<Long> messageIds = new ArrayList<>();
if (Constans.PUBLIC_SITE.equals(remind.getVisibleRange())) {
//获取全平台的人
//如果站点下人数太多会导致查询用户接口超时,故已弃用
// return queryAccount.getAccountBySiteId(remind.getSiteId());
//按道理不可能到这一步
return new ArrayList<>();
} else {
if (remind.getMessageType() == 1) {
//消息类型为自定义
messageIds.add(remind.getMessageId());
}
//获取业务指定范围的人
return getVisibleAccounts(messageIds, remind.getRelationType(), remind.getRelationId(), remind.getCompanyId());
}
}
/**
* 根据业务类型获取指定范围相应人员集合
*
* @param messageIds
* @param taskType
* @param taskId
* @param companyId
* @return
*/
public List<AccountVO> getVisibleAccounts(List<Long> messageIds, Integer taskType, Long taskId, Long companyId) {
if (CollectionUtils.isNotEmpty(messageIds)) {
List<MessageVisibleRange> ranges = messageVisibleRangeMapper.getList(messageIds);
if (CollectionUtils.isNotEmpty(ranges)) {
return queryAccount.getMessageAccounts(ranges, companyId);
}
} else {
logger.info("taskType= " + taskType + "||taskId:" + taskId + "||companyId:" + companyId);
//获取各业务的可见范围人员
if (taskType != null && taskId != null) {
return queryAccount.getVisibleRangeByTask(taskType, taskId, companyId);
}
}
return new ArrayList<>();
}
/**
* 更新待发消息状态
*
* @param messageRemindId
* @param messageStatus 消息状态
*/
public void updateMessageRemindStatus(Long messageRemindId, Integer messageStatus) {
MessageRemind messageRemind = new MessageRemind();
messageRemind.setStatus(messageStatus);
messageRemind.setId(messageRemindId);
try {
messageRemind.updateById();
} catch (Exception e) {
e.printStackTrace();
logger.info("更新待发消息状态异常");
throw e;
}
}
/**
* 更新主体消息状态
*
* @param messageId
* @param messageStatus 消息状态
*/
public void updateMessageStatus(Long messageId, Integer messageStatus) {
Message message = new Message();
message.setId(messageId);
message.setStatus(messageStatus);
try {
message.updateById();
} catch (Exception e) {
e.printStackTrace();
logger.info("更新主体消息状态异常");
throw e;
}
}
/**
* 开始给用户发消息
*
* @param accountVOS 可见范围用户
* @param messageRemind 待发消息对象
*/
public Integer insertMessageAccount(List<AccountVO> accountVOS, MessageRemind messageRemind) {
if (CollectionUtils.isNotEmpty(accountVOS)) {
List<MessageAccount> messageAccounts = new ArrayList<>(accountVOS.size());
for (AccountVO a : accountVOS) {
MessageAccount messageAccount = new MessageAccount();
messageAccount.setId(idGenerator.generate());
messageAccount.setDeleted(Constans.NOT_DELETED);
messageAccount.setMessageId(messageRemind.getMessageId());
messageAccount.setMessageRemindId(messageRemind.getId());
messageAccount.setVisibleRange(messageRemind.getVisibleRange());
messageAccount.setSiteId(messageRemind.getSiteId());
messageAccount.setCompanyId(messageRemind.getCompanyId());
messageAccount.setCreateById(messageRemind.getCreateById());
messageAccount.setCreateByName(messageRemind.getCreateByName());
messageAccount.setCreateTime(messageRemind.getSendTime());
messageAccount.setReaded(Constans.NOT_READ);
messageAccount.setAccountId(a.getId());
//修改为在查询的时候对用户名参数进行赋值
// // 这里只是为了把用户名称给赋值,业务参数赋值已在业务保存待发消息时已处理
// String completeContext = messageUtil.getCompleteContext(messageRemind.getMessageContext(), a);
messageAccount.setContext(messageRemind.getMessageContext());
messageAccount.setRelationId(messageRemind.getRelationId());
messageAccount.setRelationType(messageRemind.getRelationType());
messageAccounts.add(messageAccount);
}
try {
if (messageAccountService.insertBatch(messageAccounts)) {
return 1;
}
} catch (Exception e) {
e.printStackTrace();
logger.info("发消息异常");
throw e;
}
} else {
logger.info("用户为空!!!");
}
return -1;
}
/**
* 开始给用户发消息 全平台
*
* @param messageRemind 待发消息对象
*/
public Integer insertMessageAccountByPublic(MessageRemind messageRemind) {
MessageAccount messageAccount = new MessageAccount();
messageAccount.setId(idGenerator.generate());
messageAccount.setDeleted(Constans.NOT_DELETED);
messageAccount.setMessageId(messageRemind.getMessageId());
messageAccount.setMessageRemindId(messageRemind.getId());
messageAccount.setVisibleRange(messageRemind.getVisibleRange());
messageAccount.setSiteId(messageRemind.getSiteId());
messageAccount.setCompanyId(messageRemind.getCompanyId());
messageAccount.setCreateById(messageRemind.getCreateById());
messageAccount.setCreateByName(messageRemind.getCreateByName());
messageAccount.setCreateTime(messageRemind.getSendTime());
messageAccount.setReaded(Constans.NOT_READ);
messageAccount.setContext(messageRemind.getMessageContext());
messageAccount.setRelationId(messageRemind.getRelationId());
messageAccount.setRelationType(messageRemind.getRelationType());
try {
if (messageAccountService.insert(messageAccount)) {
return 1;
}
} catch (Exception e) {
e.printStackTrace();
logger.info("发消息异常");
throw e;
}
return -1;
}
@Override
@Transactional(rollbackFor = Exception.class)
public Integer insertMessageRemind(com.yizhi.message.application.vo.MessageRemindVo vo) {
RequestContext context = vo.getRequestContext();
String messageContext = "";
Date date = new Date();
if (vo != null) {
//先判断是否是修改待发消息的状态
if (vo.getTaskStatusUpdate()) {
updateMessageRemindByTaskId(vo);
return 0;
}
//判断是否是调研复制场景
if (null != vo.getIsCopy() && vo.getIsCopy()) {
copyMessage(vo);
return 0;
}
//计划同步培训的可见范围
if (vo.getVisibleRangeUpdate()) {
updateMessageRemindByTaskId(vo);
return 0;
}
//如果业务关闭了消息提醒,则删除对应待发消息
if (vo.getHasDeleted()) {
deleteMessageRemind(vo);
return 0;
}
//如果业务只是修改了,则先删除再添加
if (vo.getIsChangge()) {
deleteMessageRemind(vo);
}
//自定义消息不需要解析业务参数
messageContext = vo.getMessageContext();
if (vo.getMessageType() != 1) {
//先组装好消息内容
messageContext = getContext(vo, vo.getTaskVo());
}
if (vo.getMessageType() == 2) {
try {
Integer num = 0;
if (CollectionUtils.isNotEmpty(vo.getMessageTaskRemindVos())) {
List<com.yizhi.message.application.vo.MessageTaskRemindVo> messageTaskRemindVos = vo.getMessageTaskRemindVos();
//保存待发消息
for (com.yizhi.message.application.vo.MessageTaskRemindVo vo1 : messageTaskRemindVos) {
//作业没有开始时间,如果有该数据,则过滤
if (vo1.getTimeEventType() == 1 && vo.getRelationType().equals(6)) {
continue;
}
insertMessageRemind(vo, messageContext, context, vo1, date);
num++;
}
if (num == vo.getMessageTaskRemindVos().size()) {
return 1;
}
} else {
logger.info("提醒时间设置为空!!!!");
}
} catch (Exception e) {
e.printStackTrace();
logger.info("保存待发消息异常");
throw e;
}
} else {
insertMessageRemind(vo, messageContext, context, null, date);
}
}
return -1;
}
/**
* 复制调研时需要
*
* @param vo
* @return
*/
public Integer copyMessage(com.yizhi.message.application.vo.MessageRemindVo vo) {
if (vo.getRelationType() == null || vo.getRelationId() == null || vo.getOldRelationId() == null) {
logger.info("copy待发消息时,缺少必要参数");
return -1;
}
MessageRemind remind = new MessageRemind();
RequestContext requestContext = vo.getRequestContext();
remind.setRelationType(vo.getRelationType());
remind.setRelationId(vo.getOldRelationId());
EntityWrapper<MessageRemind> wrapper = new EntityWrapper(remind);
List<MessageRemind> messageReminds = messageRemindMapper.selectList(wrapper);
if (CollectionUtils.isNotEmpty(messageReminds)) {
messageReminds.forEach(a -> {
a.setId(idGenerator.generate());
a.setRelationId(vo.getRelationId());
a.setCreateTime(new Date());
a.setCreateByName(requestContext.getAccountName());
a.setCreateById(requestContext.getAccountId());
a.setUpdateByName(null);
a.setUpdateById(null);
a.insert();
});
}
return 1;
}
/**
* 修改待发消息业务状态根据业务id
*
* @param vo
* @return
*/
public Integer updateMessageRemindByTaskId(com.yizhi.message.application.vo.MessageRemindVo vo) {
if (vo.getRelationType() == null || vo.getRelationId() == null) {
logger.info("修改待发消息时,缺少必要参数");
return -1;
}
RequestContext requestContext = vo.getRequestContext();
MessageRemind messageRemind = new MessageRemind();
if (vo.getTaskStatusUpdate()) {
messageRemind.setTaskStatus(vo.getTaskStatus());
logger.info("修改待发消息业务状态成功!!!!");
}
if (vo.getVisibleRangeUpdate()) {
messageRemind.setVisibleRange(messageUtil.getVisibleRange(vo.getRelationType(), vo.getVisibleRange()));
logger.info("修改待发消息可见范围成功!!!!");
}
messageRemind.setUpdateById(requestContext.getAccountId());
messageRemind.setUpdateTime(new Date());
messageRemind.setUpdateByName(requestContext.getAccountName());
EntityWrapper wrapper = new EntityWrapper();
wrapper.eq("deleted", 0)
.ne("status", 4)
.eq("relation_type", vo.getRelationType())
.eq("relation_id", vo.getRelationId())
.eq("message_type", 2);
return messageRemindMapper.update(messageRemind, wrapper);
}
/**
* 保存待发消息
*
* @param vo
* @param messageContext
* @param context
* @param vo1
* @param date
* @return
*/
public Integer insertMessageRemind(com.yizhi.message.application.vo.MessageRemindVo vo, String messageContext, RequestContext context, com.yizhi.message.application.vo.MessageTaskRemindVo vo1, Date date) {
MessageRemind messageRemind = new MessageRemind();
Long messageRemindId = idGenerator.generate();
BeanUtils.copyProperties(vo, messageRemind);
messageRemind.setId(messageRemindId);
messageRemind.setMessageContext(messageContext);
messageRemind.setSiteId(context.getSiteId());
messageRemind.setStatus(MessageStatus.TO_SEND.getCode());
messageRemind.setCompanyId(context.getCompanyId());
messageRemind.setCreateById(context.getAccountId());
messageRemind.setCreateByName(context.getAccountName());
messageRemind.setCreateTime(date);
if (vo.getMessageType() == 2) {
messageRemind.setTaskStatus(vo.getTaskStatus());
}
//统一可见范围类型
if (vo.getMessageType() == 1) {
messageRemind.setVisibleRange(vo.getVisibleRange());
} else {
messageRemind.setVisibleRange(messageUtil.getVisibleRange(vo.getRelationType(), vo.getVisibleRange()));
}
if (vo1 != null) {
messageRemind.setTimeEventType(vo1.getTimeEventType());
messageRemind.setTimeType(vo1.getTimeType());
if (vo1.getTimeEventType() != 3) {
//计算最终发送时间
Date sendTime = getSendTime(vo1.getTimeEventType(), vo1.getTimeType(), vo.getTaskVo().getTaskStratTime(), vo.getTaskVo().getTaskEndTime());
messageRemind.setSendTime(sendTime);
} else {
messageRemind.setSendTime(vo1.getSendTime());
}
} else {
messageRemind.setSendTime(vo.getSendTime());
}
try {
messageRemind.insert();
} catch (Exception e) {
e.printStackTrace();
logger.info("保存待发消息异常");
throw e;
}
return 0;
}
/**
* 计算最终的发送时间
*
* @param timeEvenType 1:业务开始时间 2:业务结束时间 3:自定义时间
* @param timeType 详情请看TimeType类
* @param taskStartTime 业务开始时间
* @param taskEndTime 业务结束时间
* @return
*/
public static Date getSendTime(Integer timeEvenType, Integer timeType, Date taskStartTime, Date taskEndTime) {
//只有不为自定义才需要计算发送时间
logger.info("获取到的参数为:" + "timeEvenType:" + timeEvenType + "||timeType:" + timeType
+ "||taskStartTime:" + taskStartTime
+ "||taskEndTime:" + taskEndTime);
Date sendTime = null;
if (timeEvenType == 1 && taskStartTime != null) {
sendTime = DateConvertor.calSendTime(taskStartTime, timeType);
} else if (timeEvenType == 2 && taskEndTime != null) {
sendTime = DateConvertor.calSendTime(taskEndTime, timeType);
}
logger.info("解析后发送时间为:" + sendTime);
return sendTime;
}
public static void main(String[] args) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long time = System.currentTimeMillis();//获取当前系统时间
Date date = new Date();
date.setTime(time);
System.out.println(format.format(getSendTime(1, 5, date, null)));
;
}
@Override
public MessageVo get(Integer relationType, Long relationId) {
MessageVo messageVo = null;
EntityWrapper wrapper = new EntityWrapper();
wrapper.eq("relation_type", relationType);
wrapper.eq("relation_id", relationId);
wrapper.eq("site_id", ContextHolder.get().getSiteId());
wrapper.eq("deleted", Constans.NOT_DELETED);
List<MessageRemind> list = messageRemindMapper.selectList(wrapper);
if (CollectionUtils.isNotEmpty(list)) {
//获取主体消息id、发送方式
MessageRemind messageRemind = list.get(0);
messageVo = new MessageVo();
//获取模板名称
Message message = messageMapper.selectById(messageRemind.getMessageId());
MessageContext messageContext = new MessageContext();
messageContext.setMessageId(messageRemind.getMessageId());
//获取原始消息内容
messageContext = messageContextMapper.selectOne(messageContext);
messageVo.setSendType(messageRemind.getSendType());
messageVo.setTemplateName(message.getTemplateName());
messageVo.setContext(messageContext.getContext());
messageVo.setId(message.getId());
for (MessageRemind remind : list) {
com.yizhi.message.application.vo.MessageTaskRemindVo taskRemindVo = new com.yizhi.message.application.vo.MessageTaskRemindVo();
taskRemindVo.setSendTime(remind.getSendTime());
taskRemindVo.setTimeEventType(remind.getTimeEventType());
taskRemindVo.setTimeType(remind.getTimeType());
taskRemindVo.setMessageRemindId(remind.getId());
messageVo.getMessageTaskRemindVos().add(taskRemindVo);
}
}
return messageVo;
}
/**
* 删除对应待发消息
*
* @param messageRemindVo
*/
public void deleteMessageRemind(com.yizhi.message.application.vo.MessageRemindVo messageRemindVo) {
if (messageRemindVo.getMessageType() != 1 && (messageRemindVo.getRelationId() == null || messageRemindVo.getRelationType() == null)) {
logger.info("删除待发消息需要的参数缺少!");
return;
}
RequestContext requestContext = messageRemindVo.getRequestContext();
EntityWrapper wrapper = new EntityWrapper();
wrapper.eq("deleted", Constans.NOT_DELETED);
if (messageRemindVo.getMessageType() != 1 && messageRemindVo.getRelationId() != null && messageRemindVo.getRelationType() != null) {
wrapper.eq("relation_type", messageRemindVo.getRelationType());
wrapper.eq("relation_id", messageRemindVo.getRelationId());
} else {
wrapper.eq("message_id", messageRemindVo.getMessageId());
}
MessageRemind messageRemind = new MessageRemind();
messageRemind.setDeleted(Constans.DELETED);
if (null != requestContext) {
messageRemind.setUpdateById(requestContext.getAccountId());
messageRemind.setUpdateTime(new Date());
messageRemind.setUpdateByName(requestContext.getAccountName());
}
messageRemindMapper.update(messageRemind, wrapper);
logger.info("删除或修改待发消息状态成功!!!!");
}
@Override
@Transactional(rollbackFor = Exception.class)
public Integer updateMessageRemind(com.yizhi.message.application.vo.MessageRemindVo messageRemindVo) {
RequestContext context = ContextHolder.get();
Date date = new Date();
try {
//业务关闭了提醒
if (messageRemindVo.getIsChangge() == true) {
EntityWrapper wrapper = new EntityWrapper();
wrapper.eq("relation_type", messageRemindVo.getRelationType());
wrapper.eq("relation_id", messageRemindVo.getRelationId());
wrapper.eq("deleted", Constans.NOT_DELETED);
List<MessageRemind> list = messageRemindMapper.selectList(wrapper);
if (CollectionUtils.isNotEmpty(list)) {
//先删除该业务的待发消息
MessageRemind messageRemind = new MessageRemind();
messageRemind.setDeleted(Constans.DELETED);
if (messageRemindMapper.update(messageRemind, wrapper) < 1) {
logger.info("删除业务待发消息失败");
}
}
try {
return insertMessageRemind(messageRemindVo);
} catch (Exception e) {
e.printStackTrace();
logger.info("保存待发消息异常");
throw e;
}
}
} catch (Exception e) {
e.printStackTrace();
logger.info("业务提醒修改异常");
throw e;
}
return -1;
}
}
package com.yizhi.message.application.service.impl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yizhi.application.job.remote.JobClient;
import com.yizhi.application.orm.id.IdGenerator;
import com.yizhi.core.application.context.ContextHolder;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.core.application.event.EventWrapper;
import com.yizhi.core.application.publish.CloudEventPublisher;
import com.yizhi.message.application.constans.Constans;
import com.yizhi.message.application.controller.util.MessageUtil;
import com.yizhi.message.application.controller.util.QueryAccount;
import com.yizhi.message.application.domain.*;
import com.yizhi.message.application.enums.MessageStatus;
import com.yizhi.message.application.mapper.MessageMapper;
import com.yizhi.message.application.vo.*;
import com.yizhi.message.application.service.*;
import com.yizhi.message.application.vo.MessageRemindVo;
import com.yizhi.system.application.vo.AccountVO;
import com.yizhi.system.application.vo.OrgVO;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;
/**
* <p>
* 消息 服务实现类
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Service
public class MessageServiceImple extends ServiceImpl<MessageMapper, Message> implements MessageService {
@Autowired
private JobClient jobClient;
@Autowired
private IdGenerator idGenerator;
@Autowired
private MessageService messageService;
@Autowired
private MessageContextService messageContextService;
@Autowired
private MessageVisibleRangeService messageVisibleRangeService;
@Autowired
private MessageUtil messageUtil;
@Autowired
private MessageAccountService messageAccountService;
@Autowired
private MessageRemindService messageRemindService;
@Autowired
private QueryAccount queryAccount;
@Autowired
private MessageParamRelationService messageParamRelationService;
@Autowired
private MessageParameterService messageParameterService;
@Autowired
private CloudEventPublisher cloudEventPublisher;
private static final Logger logger = LoggerFactory.getLogger(MessageServiceImple.class);
@Override
@Transactional(rollbackFor = Exception.class)
public Integer save(MessageVo messageVo) {
try {
RequestContext context = ContextHolder.get();
Date date = new Date();
Long messageId = idGenerator.generate();
//插入主体消息
Message message = null;
Integer i = null;
boolean y = false;
try {
message = new Message();
BeanUtils.copyProperties(messageVo, message);
message.setId(messageId);
if (messageVo.getMessageType() != 1) {
message.setStatus(MessageStatus.DOWN.getCode());
} else {
message.setStatus(MessageStatus.DRAFT.getCode());
}
message.setDeleted(Constans.NOT_DELETED);
message.setCreateById(context.getAccountId());
message.setCreateByName(context.getAccountName());
message.setCreateTime(date);
message.setCompanyId(context.getCompanyId());
message.setSiteId(context.getSiteId());
i = this.baseMapper.insert(message);
//把消息内容插入
MessageContext messageContext = new MessageContext();
messageContext.setId(idGenerator.generate());
messageContext.setContext(messageVo.getContext());
messageContext.setMessageId(message.getId());
messageContext.setCreateById(context.getAccountId());
messageContext.setCreateByName(context.getAccountName());
messageContext.setCreateTime(date);
y = messageContextService.insert(messageContext);
} catch (Exception e) {
e.printStackTrace();
logger.info("保存主体消息异常");
throw e;
}
try {
//若为自定义消息 且指定可见范围,则插入数据
List<MessageVisibleRangeVo> visibleRangeVos = messageVo.getMessageVisibleRange();
boolean b = false;
if (messageVo.getMessageType() == 1) {
if (messageVo.getVisibleRange().equals(Constans.VISIBLE_RANGE)
&& CollectionUtils.isNotEmpty(visibleRangeVos)) {
insertVisibleRange(visibleRangeVos, messageId, context, date);
}
}
} catch (Exception e) {
e.printStackTrace();
logger.info("保存可见范围异常");
throw e;
}
try {
//插入消息与可选参数的关联关系
insertMessageParamRelation(messageId, messageVo.getMessageParameterIds(), context, date);
} catch (Exception e) {
e.printStackTrace();
logger.info("保存可选参数关联关系异常");
throw e;
}
if (i == 1 && y == true) {
return 1;
} else if (i != 1) {
return -2;//保存主体消息异常
} else if (y != true) {
return -3;//保存消息内容异常
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
return -1;//消息保存失败
}
@Override
public Page<MessageManageVo> getPage(Integer messageType, String title, Page<MessageManageVo> page) {
List<MessageManageVo> messageVoList = this.baseMapper.getPage(messageType, title, ContextHolder.get().getSiteId(), page);
//如果是触发消息没有查到当前站点的触发消息,则取初始化消息(siteID为0)
if (messageType == 3 && CollectionUtils.isEmpty(messageVoList)) {
initData(ContextHolder.get(), new Date());
messageVoList = this.baseMapper.getPage(messageType, title, ContextHolder.get().getSiteId(), page);
page.setTotal(this.baseMapper.getPageNum(messageType, title, ContextHolder.get().getSiteId()));
}
Integer num = page.getOffset() + 1;
if (CollectionUtils.isNotEmpty(messageVoList)) {
for (MessageManageVo vo : messageVoList) {
vo.setNum(num);
num++;
//设置
vo.setRelationTypeString(messageUtil.getRelationType(vo.getRelationType()));
vo.setStatusString(messageUtil.getMessageStatus(vo.getStatus()));
}
}
page.setRecords(messageVoList);
return page;
}
@Override
public MessageVo get(Long id) {
Message message = this.baseMapper.selectById(id);
MessageVo messageVo = new MessageVo();
if (message != null) {
BeanUtils.copyProperties(message, messageVo);
EntityWrapper wrapper = new EntityWrapper();
wrapper.eq("message_id", id);
MessageContext messageContext = messageContextService.selectOne(wrapper);
if (messageContext != null) {
messageVo.setContext(messageContext.getContext());
messageVo.setFakeContext(messageUtil.returnParameter(message.getRelationType(), messageContext.getContext()));
messageVo.setMessageContextId(messageContext.getId());
}
//获取消息已选的参数列表
EntityWrapper<MessageParamRelation> wrapper1 = new EntityWrapper<>();
wrapper1.eq("message_id", message.getId());
wrapper1.eq("deleted", Constans.NOT_DELETED);
List<MessageParamRelation> relations = messageParamRelationService.selectList(wrapper1);
if (CollectionUtils.isNotEmpty(relations)) {
List<Long> messageParameterIds = new ArrayList<>(relations.size());
relations.forEach(a -> {
messageParameterIds.add(a.getMessageParameterId());
});
messageVo.setMessageParameterIds(messageParameterIds);
}
//自定义消息需要回显可见范围 需要实时获取真实姓名等功能
if (message.getMessageType() == 1) {
Map<String, Object> map = new HashMap<>(2);
map.put("message_id", message.getId());
List<MessageVisibleRange> visibleRanges = messageVisibleRangeService.selectByMap(map);
if (CollectionUtils.isNotEmpty(visibleRanges)) {
List<Long> accountIds = new ArrayList<>(visibleRanges.size());
List<Long> orgIds = new ArrayList<>(visibleRanges.size());
List<MessageVisibleRangeVo> vos = new ArrayList<>(visibleRanges.size());
for (MessageVisibleRange a : visibleRanges) {
MessageVisibleRangeVo vo = new MessageVisibleRangeVo();
BeanUtils.copyProperties(a, vo);
vos.add(vo);
if (a.getType().equals(1)) {
orgIds.add(a.getRelationId());
} else {
accountIds.add(a.getRelationId());
}
}
Map<Long, AccountVO> accountMap = queryAccount.queryAccountByIds(accountIds);
Map<Long, OrgVO> orgMap = queryAccount.queryOrgByIds(orgIds);
for (MessageVisibleRangeVo a : vos) {
if (null != accountMap) {
AccountVO accountVO = accountMap.get(a.getRelationId());
if (null != accountVO && a.getType().equals(2)) {
a.setWorkNum(accountVO.getWorkNum());
a.setFullName(accountVO.getFullName());
a.setName(accountVO.getName());
}
}
if (null != orgMap) {
OrgVO orgVO = orgMap.get(a.getRelationId());
if (null != orgVO && a.getType().equals(1)) {
a.setName(orgVO.getName());
}
}
}
messageVo.setMessageVisibleRange(vos);
}
} else {
messageVo.setRelationTypeString(messageUtil.getRelationType(message.getRelationType()));
}
}
return messageVo;
}
/**
* 插入可见范围
*
* @param visibleRangeVos
* @param messageId
* @param requestContext
* @param date
* @return
*/
public Boolean insertVisibleRange(List<MessageVisibleRangeVo> visibleRangeVos, Long messageId, RequestContext requestContext, Date date) {
List<MessageVisibleRange> visibleRanges = new ArrayList<>(visibleRangeVos.size());
for (MessageVisibleRangeVo vo : visibleRangeVos) {
MessageVisibleRange visibleRange = new MessageVisibleRange();
visibleRange.setId(idGenerator.generate());
visibleRange.setType(vo.getType());
visibleRange.setMessageId(messageId);
visibleRange.setRelationId(vo.getRelationId());
visibleRange.setCreateById(requestContext.getAccountId());
visibleRange.setCreateByName(requestContext.getAccountName());
visibleRange.setCreateTime(date);
visibleRanges.add(visibleRange);
}
return messageVisibleRangeService.insertBatch(visibleRanges);
}
/**
* 清空可见范围
*
* @param messageId
* @param requestContext
* @param date
* @return
*/
public boolean deleteVisibleRange(Long messageId, RequestContext requestContext, Date date) {
EntityWrapper wrapper = new EntityWrapper();
wrapper.eq("message_id", messageId);
MessageVisibleRange visibleRange = new MessageVisibleRange();
visibleRange.setDeleted(Constans.DELETED);
visibleRange.setUpdateById(requestContext.getAccountId());
visibleRange.setUpdateByName(requestContext.getAccountName());
visibleRange.setUpdateTime(date);
return this.messageVisibleRangeService.update(visibleRange, wrapper);
}
/**
* 插入消息 与可选参数的关联关系
*
* @param messageid
* @param messageParameterIds
* @param context
* @param date
* @return
*/
public boolean insertMessageParamRelation(Long messageid, List<Long> messageParameterIds, RequestContext context, Date date) {
if (CollectionUtils.isNotEmpty(messageParameterIds)) {
List<MessageParamRelation> relations = new ArrayList<>();
for (Long parameterId : messageParameterIds) {
MessageParameter parameter = messageParameterService.selectById(parameterId);
if (parameter != null) {
MessageParamRelation relation = new MessageParamRelation();
relation.setId(idGenerator.generate());
relation.setMessageId(messageid);
relation.setFieldType(parameter.getFieldType());
relation.setMessageParameterId(parameterId);
relation.setCreateById(context.getAccountId());
relation.setCreateByName(context.getAccountName());
relation.setCreateTime(date);
relations.add(relation);
} else {
logger.info("parameterId:" + parameterId + "--数据库没有该参数对象");
}
}
if (CollectionUtils.isNotEmpty(relations)) {
return messageParamRelationService.insertBatch(relations);
}
}
return false;
}
/**
* 清空消息与可选参数的关联关系
*
* @param messageId
* @param context
* @param date
* @return
*/
public boolean deleteMessageParamRelation(Long messageId, RequestContext context, Date date) {
EntityWrapper wrapper = new EntityWrapper();
wrapper.eq("message_id", messageId);
MessageParamRelation messageParamRelation = new MessageParamRelation();
messageParamRelation.setDeleted(Constans.DELETED);
messageParamRelation.setUpdateById(context.getAccountId());
messageParamRelation.setUpdateByName(context.getAccountName());
messageParamRelation.setUpdateTime(date);
return messageParamRelationService.update(messageParamRelation, wrapper);
}
@Override
@Transactional(rollbackFor = Exception.class)
public Integer update(MessageVo messageVo) {
if (messageVo != null) {
Date date = new Date();
RequestContext requestContext = ContextHolder.get();
MessageContext context = new MessageContext();
Message tem = this.baseMapper.selectById(messageVo.getId());
if (tem == null) {
return -3;
}
Message message = new Message();
BeanUtils.copyProperties(messageVo, message);
Long updateMessageId = idGenerator.generate();
boolean b = false;
boolean canUpdate = false;
if ((messageVo.getId() >= 10 || messageVo.getId() <= 1)) {
canUpdate = true;
}
try {
try {
//如果是自定义消息,判断可见范围是否有变化
if (tem.getMessageType() == 1) {
List<MessageVisibleRangeVo> visibleRangeVos = messageVo.getMessageVisibleRange();
if (!MessageStatus.DRAFT.getCode().equals(tem.getStatus())) {
return -4;
}
if (Constans.VISIBLE_RANGE.equals(messageVo.getVisibleRange())
&& CollectionUtils.isNotEmpty(visibleRangeVos)) {
deleteVisibleRange(messageVo.getId(), requestContext, date);
insertVisibleRange(visibleRangeVos, messageVo.getId(), requestContext, date);
} else {
deleteVisibleRange(messageVo.getId(), requestContext, date);
}
}
} catch (Exception e) {
e.printStackTrace();
logger.info("保存可见范围异常");
throw e;
}
try {
//消息的可选参数发生改变
if (CollectionUtils.isNotEmpty(messageVo.getMessageParameterIds())) {
//防止误修改默认触发消息
if (canUpdate) {
deleteMessageParamRelation(messageVo.getId(), requestContext, date);
insertMessageParamRelation(messageVo.getId(), messageVo.getMessageParameterIds(), requestContext, date);
}
}
} catch (Exception e) {
e.printStackTrace();
logger.info("保存可选参数关联关系异常");
throw e;
}
//防止误修改默认触发消息
if (canUpdate) {
b = message.updateById();
}
try {
//消息内容发生改变
if (messageVo.getContext() != null) {
//防止误修改默认触发消息
if (canUpdate) {
context.setId(messageVo.getMessageContextId());
context.setContext(messageVo.getContext());
boolean c = context.updateById();
}
}
} catch (Exception e) {
e.printStackTrace();
logger.info("保存消息内容异常");
throw e;
}
} catch (Exception e) {
e.printStackTrace();
logger.info("修改消息内容异常");
throw e;
}
if (b) {
return 1;
}
}
return -1;//修改失败
}
public void initData(RequestContext requestContext, Date date) {
//如果id在1-10之间,说明此站点需要新增自己的触发消息
List<Message> messages = new ArrayList<>();
messages = this.baseMapper.getList(3, 0L);
if (CollectionUtils.isNotEmpty(messages)) {
for (Message a : messages) {
Long oldMessageId = a.getId();
Long messageId = idGenerator.generate();
//把消息内容插入
MessageContext messageContext1 = new MessageContext();
messageContext1.setMessageId(oldMessageId);
EntityWrapper<MessageContext> wrapper = new EntityWrapper<>(messageContext1);
messageContext1 = messageContextService.selectOne(wrapper);
if (messageContext1 != null) {
messageContext1.setId(idGenerator.generate());
messageContext1.setContext(messageContext1.getContext());
messageContext1.setMessageId(messageId);
messageContext1.setCreateById(requestContext.getAccountId());
messageContext1.setCreateByName(requestContext.getAccountName());
messageContext1.setCreateTime(date);
messageContextService.insert(messageContext1);
}
//插入消息与可选参数的关联关系
MessageParamRelation relation = new MessageParamRelation();
relation.setDeleted(0);
relation.setMessageId(oldMessageId);
EntityWrapper<MessageParamRelation> wrapper1 = new EntityWrapper<>(relation);
List<MessageParamRelation> relations = messageParamRelationService.selectList(wrapper1);
if (CollectionUtils.isNotEmpty(relations)) {
for (MessageParamRelation paramRelation : relations) {
paramRelation.setId(idGenerator.generate());
paramRelation.setMessageId(messageId);
paramRelation.setCreateById(requestContext.getAccountId());
paramRelation.setCreateByName(requestContext.getAccountName());
paramRelation.setCreateTime(date);
}
messageParamRelationService.insertBatch(relations);
}
//插入主体消息
a.setId(messageId);
a.setSiteId(requestContext.getSiteId());
a.setDeleted(Constans.NOT_DELETED);
a.setCompanyId(requestContext.getCompanyId());
a.setCreateById(requestContext.getAccountId());
a.setCreateByName(requestContext.getAccountName());
a.setCreateTime(date);
a.setStatus(MessageStatus.DOWN.getCode());
}
messageService.insertBatch(messages);
}
}
@Override
public Integer upOrDown(CancelSendMessageVo vo) {
if (vo != null) {
Message tem = this.baseMapper.selectById(vo.getId());
if (tem != null) {
if (tem.getMessageType() != 1) {
Message message = new Message();
message.setId(vo.getId());
message.setStatus(vo.getStatus());
if (message.updateById()) {
return 1;
}
} else {
return -2;//该消息不支持上下架
}
}
}
return -1;
}
@Override
@Transactional(rollbackFor = Exception.class)
public Integer cancel(CancelSendMessageVo vo) {
Message tem = this.baseMapper.selectById(vo.getId());
if (tem != null) {
try {
//只有自定义消息才有取消与撤回功能
if (tem.getMessageType() == 1) {
Message message = new Message();
message.setId(vo.getId());
//查询是否存在对应待发消息
EntityWrapper wrapper = new EntityWrapper();
wrapper.eq("message_id", message.getId());
MessageRemind messageRemind = messageRemindService.selectOne(wrapper);
if (messageRemind != null) {
//取消发送操作,更新自定义消息的状态
if (vo.getType() == 1) {
//顺便更新一下主体消息状态
message.setStatus(MessageStatus.DRAFT.getCode());
//删除待发消息
try {
messageRemind.setDeleted(Constans.DELETED);
messageRemind.setStatus(MessageStatus.DRAFT.getCode());
messageRemindService.updateById(messageRemind);
} catch (Exception e) {
e.printStackTrace();
logger.error("删除待发消息异常" + "错误消息={}", e);
throw e;
}
}
//撤回操作
if (vo.getType().equals(2)) {
RequestContext context = ContextHolder.get();
//更新主体消息状态为已发送被撤回
message.setStatus(MessageStatus.SEND_ED_CANCEl.getCode());
//删除用户收到的消息
try {
MessageAccount messageAccount = new MessageAccount();
messageAccount.setDeleted(Constans.DELETED);
wrapper = new EntityWrapper();
wrapper.eq("message_remind_id", messageRemind.getId());
wrapper.eq("site_id", context.getSiteId());
wrapper.eq("company_id", context.getCompanyId());
messageAccountService.update(messageAccount, wrapper);
} catch (Exception e) {
e.printStackTrace();
logger.info("删除用户消息异常");
throw e;
}
try {
//更新待发消息状态
messageRemind.setStatus(MessageStatus.SEND_ED_CANCEl.getCode());
messageRemindService.updateById(messageRemind);
} catch (Exception e) {
e.printStackTrace();
logger.info("更新待发消息异常");
throw e;
}
}
//更新主体消息状态
if (message.updateById()) {
return 1;
}
} else {
logger.info("没有查询到对应待发消息!");
return -5;
}
} else {
return -2;
}
} catch (Exception e) {
e.printStackTrace();
logger.info("操作异常");
throw e;
}
} else {
return -3;
}
return -1;
}
@Override
@Transactional(rollbackFor = Exception.class)
public Integer send(CancelSendMessageVo vo) {
Message message = this.baseMapper.selectById(vo.getId());
boolean d = false;
if (message != null) {
RequestContext context = ContextHolder.get();
Date date = new Date();
if (message.getSendTime().getTime() < date.getTime()) {
return -3;
}
//只有自定义消息且草稿状态才能发送
if (message.getMessageType().equals(1) && MessageStatus.DRAFT.getCode().equals(message.getStatus())) {
EntityWrapper wrapper = new EntityWrapper();
wrapper.eq("message_id", message.getId());
MessageContext messageContext = messageContextService.selectOne(wrapper);
if (messageContext != null) {
String context1 = messageContext.getContext();
com.yizhi.message.application.vo.MessageRemindVo vo1 = new com.yizhi.message.application.vo.MessageRemindVo();
vo1.setVisibleRange(message.getVisibleRange());
vo1.setRelationType(message.getRelationType());
vo1.setMessageId(message.getId());
vo1.setMessageContext(context1);
vo1.setMessageType(message.getMessageType());
vo1.setSendType(message.getSendType());
vo1.setSendTime(message.getSendTime());
vo1.setRequestContext(context);
try {
cloudEventPublisher.publish(Constans.MESSAGE_QUEUE, new EventWrapper<MessageRemindVo>(null, vo1));
d = true;
} catch (Exception e) {
e.printStackTrace();
logger.error("发送消息失败=====================", e);
}
if (d) {
//顺便把自定义消息状态改为 待发送
message = new Message();
message.setId(vo.getId());
message.setStatus(MessageStatus.TO_SEND.getCode());
message.updateById();
return 1;
}
}
} else {
return -2;
}
} else {
return -4;
}
return -1;
}
@Override
public List<MessageVo> getListByRelationType(Integer relationType) {
RequestContext context = ContextHolder.get();
List<MessageVo> messageVoList = new ArrayList<>();
EntityWrapper wrapper = new EntityWrapper();
wrapper.eq("deleted", Constans.NOT_DELETED);
wrapper.eq("status", MessageStatus.UP.getCode());
wrapper.eq("message_type", 2);
wrapper.eq("relation_type", relationType)
.andNew().eq("site_id", context.getSiteId())
.or().eq("site_id", 0);
List<Message> messages = this.baseMapper.selectList(wrapper);
if (CollectionUtils.isNotEmpty(messages)) {
for (Message message : messages) {
MessageVo vo = new MessageVo();
vo.setMessageType(message.getMessageType());
vo.setId(message.getId());
vo.setRelationType(message.getRelationType());
vo.setRelationTypeString(messageUtil.getRelationType(message.getRelationType()));
vo.setTemplateName(message.getTemplateName());
vo.setTitle(message.getTitle());
vo.setEventName(message.getEventName());
wrapper = new EntityWrapper();
wrapper.eq("message_id", message.getId());
MessageContext messageContext = messageContextService.selectOne(wrapper);
if (messageContext != null) {
vo.setContext(messageContext.getContext());
}
messageVoList.add(vo);
}
}
return messageVoList;
}
@Override
public Map<Long, String> getMessageTitleMap(List<Long> messageIds) {
Map<Long, String> map = null;
if (CollectionUtils.isNotEmpty(messageIds)) {
List<Message> messages = this.selectBatchIds(messageIds);
if (CollectionUtils.isNotEmpty(messages)) {
map = messages.parallelStream().collect(Collectors.toMap(Message::getId, Message::getTitle));
}
}
return map;
}
}
\ No newline at end of file
package com.yizhi.message.application.service.impl;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yizhi.message.application.domain.MessageVisibleRange;
import com.yizhi.message.application.mapper.MessageVisibleRangeMapper;
import com.yizhi.message.application.service.MessageVisibleRangeService;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Service
public class MessageVisibleRangeServiceImple extends ServiceImpl<MessageVisibleRangeMapper, MessageVisibleRange> implements MessageVisibleRangeService {
}
server.port=35012
spring.application.name=newMessage
ACTIVE=${spring.profiles.active}
spring.profiles.active=wmy401
# nacos
spring.cloud.nacos.config.shared-dataids=common-${spring.profiles.active}.properties
spring.cloud.nacos.config.namespace=${spring.profiles.active}
spring.cloud.nacos.config.prefix=${spring.application.name}
spring.cloud.nacos.config.file-extension=properties
spring.cloud.nacos.config.server-addr=192.168.1.7:3333;192.168.1.7:4444;192.168.1.7:5555
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yizhi.message.application.mapper.MessageMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.yizhi.message.application.domain.Message">
<id column="id" property="id" />
<result column="message_type" property="messageType" />
<result column="title" property="title" />
<result column="template_name" property="templateName" />
<result column="event_name" property="eventName" />
<result column="send_type" property="sendType" />
<result column="relation_type" property="relationType" />
<result column="status" property="status" />
<result column="visible_range" property="visibleRange" />
<result column="even_type" property="evenType" />
<result column="deleted" property="deleted" />
<result column="send_time" property="sendTime" />
<result column="site_id" property="siteId" />
<result column="company_id" property="companyId" />
<result column="create_by_id" property="createById" />
<result column="create_by_name" property="createByName" />
<result column="create_time" property="createTime" />
<result column="update_by_id" property="updateById" />
<result column="update_by_name" property="updateByName" />
<result column="update_time" property="updateTime" />
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id AS id,message_type AS messageType, title AS title, even_type AS evenType,template_name AS templateName, event_name AS eventName, send_type AS sendType, relation_type AS relationType, status AS status, visible_range AS visibleRange, deleted AS deleted, send_time AS sendTime, site_id AS siteId, company_id AS companyId, create_by_id AS createById, create_by_name AS createByName, create_time AS createTime, update_by_id AS updateById, update_by_name AS updateByName, update_time AS updateTime
</sql>
<select id="getPage" resultType="com.yizhi.message.application.vo.MessageManageVo">
select id AS id, message_type AS messageType,title AS title, template_name AS templateName,
event_name AS eventName, send_type AS sendType,relation_type AS relationType, status AS status
,update_time AS createTime,send_time AS sendTime,site_id AS siteId from message
where 1=1 and deleted = 0
<if test="messageType !=null and messageType !=''">
and message_type = #{messageType}
</if>
<if test="title !=null and title !=''">
and title like concat('%',#{title},'%')
</if>
<if test="messageType == 3">
and (site_id =#{siteId})
</if>
<if test="messageType != 3">
and (site_id =#{siteId} or site_id = 0)
</if>
order by update_time desc;
</select>
<select id="getPageNum" resultType="Integer">
select count(1) from message
where 1=1 and deleted = 0
<if test="messageType !=null and messageType !=''">
and message_type = #{messageType}
</if>
<if test="title !=null and title !=''">
and title like concat('%',#{title},'%')
</if>
<if test="messageType == 3">
and (site_id =#{siteId})
</if>
<if test="messageType != 3">
and (site_id =#{siteId} or site_id = 0)
</if>
</select>
<select id="getList" resultMap="BaseResultMap">
select * from message
where 1=1 and deleted = 0 and message_type = #{messageType}
<if test="messageType == 3">
and (site_id =#{siteId})
</if>
order by update_time desc;
</select>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yizhi.message.application.mapper.MessageAccountMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.yizhi.message.application.domain.MessageAccount">
<id column="id" property="id"/>
<result column="message_id" property="messageId"/>
<result column="message_remind_id" property="messageRemindId"/>
<result column="account_id" property="accountId"/>
<result column="relation_type" property="relationType"/>
<result column="relation_id" property="relationId"/>
<result column="context" property="context"/>
<result column="readed" property="readed"/>
<result column="visible_range" property="visibleRange"/>
<result column="read_time" property="readTime"/>
<result column="deleted" property="deleted"/>
<result column="site_id" property="siteId"/>
<result column="company_id" property="companyId"/>
<result column="create_by_id" property="createById"/>
<result column="create_by_name" property="createByName"/>
<result column="create_time" property="createTime"/>
<result column="update_by_id" property="updateById"/>
<result column="update_by_name" property="updateByName"/>
<result column="update_time" property="updateTime"/>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id AS id, message_remind_id AS messageRemindId,visible_range,visibleRange, context AS context,account_id AS accountId, relation_type AS relationType, relation_id AS relationId, readed AS readed, read_time AS readTime, deleted AS deleted, site_id AS siteId, company_id AS companyId, create_by_id AS createById, create_by_name AS createByName, create_time AS createTime, update_by_id AS updateById, update_by_name AS updateByName, update_time AS updateTime
</sql>
<select id="getList" resultMap="BaseResultMap">
SELECT * FROM message_account
WHERE deleted = 0
AND site_id = #{siteId}
AND account_id = #{accountId}
union all
SELECT * FROM message_account
WHERE deleted = 0
AND site_id = #{siteId}
AND visible_range = 0
ORDER BY create_time DESC
</select>
<select id="getListNum" resultType="Integer">
SELECT sum(b.num) from (SELECT count(1) num FROM message_account
WHERE deleted = 0
AND site_id = #{siteId}
AND account_id = #{accountId}
union all
SELECT count(1) num FROM message_account
WHERE deleted = 0
AND site_id = #{siteId}
AND visible_range = 0
)b
</select>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yizhi.message.application.mapper.MessageContextMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.yizhi.message.application.domain.MessageContext">
<result column="id" property="id" />
<result column="message_id" property="messageId" />
<result column="context" property="context" />
<result column="create_by_id" property="createById" />
<result column="create_by_name" property="createByName" />
<result column="create_time" property="createTime" />
<result column="update_by_id" property="updateById" />
<result column="update_by_name" property="updateByName" />
<result column="update_time" property="updateTime" />
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id AS id, message_id AS messageId, context AS context, create_by_id AS createById, create_by_name AS createByName, create_time AS createTime, update_by_id AS updateById, update_by_name AS updateByName, update_time AS updateTime
</sql>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yizhi.message.application.mapper.MessageParamRelationMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.yizhi.message.application.domain.MessageParamRelation">
<id column="id" property="id" />
<result column="message_id" property="messageId" />
<result column="message_parameter_id" property="messageParameterId" />
<result column="field_type" property="fieldType" />
<result column="deleted" property="deleted" />
<result column="create_by_id" property="createById" />
<result column="create_by_name" property="createByName" />
<result column="create_time" property="createTime" />
<result column="update_by_id" property="updateById" />
<result column="update_by_name" property="updateByName" />
<result column="update_time" property="updateTime" />
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id AS id, message_id AS messageId,field_type AS fieldType, message_parameter_id AS messageParameterId, deleted AS deleted, create_by_id AS createById, create_by_name AS createByName, create_time AS createTime, update_by_id AS updateById, update_by_name AS updateByName, update_time AS updateTime
</sql>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yizhi.message.application.mapper.MessageParameterMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.yizhi.message.application.domain.MessageParameter">
<id column="id" property="id" />
<result column="name" property="name" />
<result column="message_type" property="messageType" />
<result column="field_type" property="fieldType" />
<result column="relation_field" property="relationField" />
<result column="relation_type" property="relationType" />
<result column="deleted" property="deleted" />
<result column="site_id" property="siteId" />
<result column="company_id" property="companyId" />
<result column="create_by_id" property="createById" />
<result column="create_by_name" property="createByName" />
<result column="create_time" property="createTime" />
<result column="update_by_id" property="updateById" />
<result column="update_by_name" property="updateByName" />
<result column="update_time" property="updateTime" />
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id AS id, name AS name,message_type AS messageType, field_type AS fieldType, relation_field AS relationField, relation_type AS relationType, deleted AS deleted, site_id AS siteId, company_id AS companyId, create_by_id AS createById, create_by_name AS createByName, create_time AS createTime, update_by_id AS updateById, update_by_name AS updateByName, update_time AS updateTime
</sql>
<select id="getList" resultType="com.yizhi.message.application.vo.MessageParameterVo">
select id AS id, name AS name,message_type AS messageType, field_type AS fieldType,
relation_field AS relationField, relation_type AS relationType
from message_parameter
where 1=1 and deleted = 0 and message_type= #{messageType} and (site_id = #{siteId} or site_id = 0 )
<if test="relationType !=null">
and (relation_type = #{relationType} or relation_type = 0)
</if>
</select>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yizhi.message.application.mapper.MessageReadRecordMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.yizhi.message.application.domain.MessageReadRecord">
<id column="id" property="id" />
<result column="message_account_id" property="messageAccountId" />
<result column="account_id" property="accountId" />
<result column="readed" property="readed" />
<result column="read_time" property="readTime" />
<result column="create_by_id" property="createById" />
<result column="create_by_name" property="createByName" />
<result column="create_time" property="createTime" />
<result column="visible_range" property="visibleRange"/>
</resultMap>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yizhi.message.application.mapper.MessageRemindMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.yizhi.message.application.domain.MessageRemind">
<id column="id" property="id"/>
<result column="message_type" property="messageType"/>
<result column="message_id" property="messageId"/>
<result column="message_context" property="messageContext"/>
<result column="relation_type" property="relationType"/>
<result column="relation_id" property="relationId"/>
<result column="time_event_type" property="timeEventType"/>
<result column="time_type" property="timeType"/>
<result column="send_time" property="sendTime"/>
<result column="deleted" property="deleted"/>
<result column="task_status" property="taskStatus"/>
<result column="status" property="status"/>
<result column="account_id" property="accountId"/>
<result column="visible_range" property="visibleRange"/>
<result column="send_type" property="sendType"/>
<result column="site_id" property="siteId"/>
<result column="company_id" property="companyId"/>
<result column="create_by_id" property="createById"/>
<result column="create_by_name" property="createByName"/>
<result column="create_time" property="createTime"/>
<result column="update_by_id" property="updateById"/>
<result column="update_by_name" property="updateByName"/>
<result column="update_time" property="updateTime"/>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id AS id, message_id AS messageId,message_type AS messageType,task_status AS taskStatus ,message_context AS messageContext,deleted AS deleted, relation_type AS relationType, relation_id AS relationId, time_event_type AS timeEventType,account_id AS accountId, time_type AS timeType, send_time AS sendTime, status AS status, send_type AS sendType,visible_range AS visibleRange, site_id AS siteId, company_id AS companyId, create_by_id AS createById, create_by_name AS createByName, create_time AS createTime, update_by_id AS updateById, update_by_name AS updateByName, update_time AS updateTime
</sql>
<sql id="Base_Column_List1">
id AS id, message_id AS messageId,message_type AS messageType,task_status AS taskStatus ,message_context AS messageContext,deleted AS deleted, relation_type AS relationType, relation_id AS relationId, time_event_type AS timeEventType,account_id AS accountId, time_type AS timeType, send_time AS sendTime, status AS status, send_type AS sendType,visible_range AS visibleRange, site_id AS siteId, company_id AS companyId
</sql>
<select id="getListByTime" resultType="com.yizhi.message.application.domain.MessageRemind">
SELECT <include refid="Base_Column_List"/> FROM message_remind
WHERE
deleted = 0
and task_status = 1
and status not in(4,8)
and
(<![CDATA[
DATE_FORMAT( send_time, '%Y-%m-%d %H:%i' ) <= DATE_FORMAT(now(), '%Y-%m-%d %H:%i' )
]]> )
</select>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yizhi.message.application.mapper.MessageVisibleRangeMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.yizhi.message.application.domain.MessageVisibleRange">
<id column="id" property="id" />
<result column="message_id" property="messageId" />
<result column="type" property="type" />
<result column="relation_id" property="relationId" />
<result column="deleted" property="deleted" />
<result column="create_by_id" property="createById" />
<result column="create_by_name" property="createByName" />
<result column="create_time" property="createTime" />
<result column="update_by_id" property="updateById" />
<result column="update_by_name" property="updateByName" />
<result column="update_time" property="updateTime" />
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id AS id,message_id AS messageId, type AS type, deleted As deleted, create_by_id AS createById, create_by_name AS createByName, create_time AS createTime, update_by_id AS updateById, update_by_name AS updateByName, update_time AS updateTime
</sql>
<select id="getList" resultMap="BaseResultMap">
select id ,type,relation_id from message_visible_range
where 1=1 and deleted =0
<if test="messageIds!=null and messageIds.size()>0">
and message_id in (<foreach collection="messageIds" item="i" separator=","> #{i}</foreach>)
</if>
</select>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.yizhi</groupId>
<artifactId>wmy-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath/>
</parent>
<groupId>com.yizhi</groupId>
<artifactId>cloud-newMessage</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>cloud-newMessage-api</module>
<module>cloud-newMessage-service</module>
</modules>
<name>cloud-newMessage</name>
<packaging>pom</packaging>
<repositories>
<repository>
<id>wmy4.0</id>
<url>http://mvn.km365.pw/nexus/content/groups/wmy4.0-group/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</project>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment