Browse Source

查询消息

master
zhizhi wu 5 years ago
parent
commit
15f367c0cd
  1. 9
      tall/src/main/java/com/ccsens/tall/bean/vo/UserVo.java
  2. 9
      tall/src/main/java/com/ccsens/tall/persist/dao/SysAuthDao.java
  3. 41
      tall/src/main/java/com/ccsens/tall/service/ProjectMessageService.java
  4. 2
      tall/src/main/resources/application-dev.yml
  5. 15
      tall/src/main/resources/mapper_dao/SysAuthDao.xml
  6. 2
      tall/src/main/resources/mapper_dao/SysOperationDao.xml

9
tall/src/main/java/com/ccsens/tall/bean/vo/UserVo.java

@ -81,4 +81,13 @@ public class UserVo {
@ApiModelProperty("语言")
private String language;
}
@Data
@ApiModel("公众号用户")
public static class Oauth2WX{
@ApiModelProperty("openid")
private String openid;
@ApiModelProperty("用户id")
private Long userId;
}
}

9
tall/src/main/java/com/ccsens/tall/persist/dao/SysAuthDao.java

@ -1,8 +1,17 @@
package com.ccsens.tall.persist.dao;
import com.ccsens.tall.bean.vo.UserVo;
import com.ccsens.tall.persist.mapper.SysAuthMapper;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface SysAuthDao extends SysAuthMapper {
/**
* 查询关注了公众号的用户的openid
* @param userIds
* @return
*/
List<UserVo.Oauth2WX> queryOauth2WX(List<Long> userIds);
}

41
tall/src/main/java/com/ccsens/tall/service/ProjectMessageService.java

@ -11,7 +11,9 @@ import com.ccsens.tall.bean.po.SysOperation;
import com.ccsens.tall.bean.po.SysOperationMessage;
import com.ccsens.tall.bean.vo.MessageVo;
import com.ccsens.tall.bean.vo.ProjectMessageVo;
import com.ccsens.tall.bean.vo.UserVo;
import com.ccsens.tall.persist.dao.ProMemberDao;
import com.ccsens.tall.persist.dao.SysAuthDao;
import com.ccsens.tall.persist.dao.SysMessageSendDao;
import com.ccsens.tall.persist.dao.SysOperationDao;
import com.ccsens.tall.persist.mapper.SysOperationMessageMapper;
@ -56,6 +58,8 @@ public class ProjectMessageService implements IProjectMessageService {
private SysOperationMessageMapper sysOperationMessageMapper;
@Resource
private SysMessageSendDao sysMessageSendDao;
@Resource
private SysAuthDao sysAuthDao;
@Resource
private AmqpTemplate rabbitTemplate;
@ -75,10 +79,16 @@ public class ProjectMessageService implements IProjectMessageService {
log.info("模板:{}", newMessages);
// 查询项目内所有成员ID
List<Long> userIds = proMemberDao.queryUserIdsByProjectId(inform.getProjectId());
if (CollectionUtil.isEmpty(userIds)) {
log.info("项目{}下没有用户,未发送消息", inform.getProjectId());
return;
}
//保存消息记录
Long operationId = initMessage(operateType, inform, newMessages, userIds);
//mq-->ws
// 操作发送
initMessageSend(userIds, operationId, WebConstant.Message.SEND_WS);
InMessage inMessage = new InMessage();
inMessage.setTos(InMessage.transTos(userIds));
inMessage.setData(JSONObject.toJSONString(newMessages));
@ -86,6 +96,26 @@ public class ProjectMessageService implements IProjectMessageService {
log.info("mq通知消息:{}", inMessage);
//更新ws消息发送成功
updateStatus(operationId, WebConstant.Message.SEND_WS);
//查询关注公众号的用户
List<UserVo.Oauth2WX> oauths = sysAuthDao.queryOauth2WX(userIds);
if (CollectionUtil.isEmpty(oauths)) {
log.info("项目{}下没有关注公众号的用户,未发送公众号关注", inform.getProjectId());
return;
}
List<String> openids = new ArrayList<>();
List<Long> oauthUserIds = new ArrayList<>();
oauths.forEach(oauth2WX -> {
openids.add(oauth2WX.getOpenid());
oauthUserIds.add(oauth2WX.getUserId());
});
initMessageSend(oauthUserIds, operationId, WebConstant.Message.SEND_WX_OFFICIAL);
//TODO 公众号通知消息
//更新ws消息发送成功
updateStatus(operationId, WebConstant.Message.SEND_WX_OFFICIAL);
}
/**
@ -135,10 +165,7 @@ public class ProjectMessageService implements IProjectMessageService {
sysOperationMessageMapper.insertSelective(operationMessage);
}
}
// 操作发送
if (CollectionUtil.isNotEmpty(userIds)) {
initMessageSend(userIds, operation.getId());
}
return operation.getId();
}
@ -147,7 +174,7 @@ public class ProjectMessageService implements IProjectMessageService {
* @param userIds
* @param operationId
*/
private void initMessageSend(List<Long> userIds, Long operationId) {
private void initMessageSend(List<Long> userIds, Long operationId, byte sendType) {
TransactionStatus transactionStatus = TransactionUtil.getTransactionStatus(transactionManager);
int length = userIds.size() -1;
try {
@ -158,7 +185,7 @@ public class ProjectMessageService implements IProjectMessageService {
send.setId(snowflake.nextId());
send.setOperationId(operationId);
send.setReceiverId(userId);
send.setSendType(WebConstant.Message.SEND_WS);
send.setSendType(sendType);
sysMessageSendDao.insertSelective(send);
log.info("消息发送:{}", send);
// 判断是否需要提交事务,并开启新事务

2
tall/src/main/resources/application-dev.yml

@ -11,7 +11,7 @@ spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
rabbitmq:
host: 49.233.89.188
host: 192.168.0.99
password: 111111
port: 5672
username: admin

15
tall/src/main/resources/mapper_dao/SysAuthDao.xml

@ -0,0 +1,15 @@
<?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.ccsens.tall.persist.dao.SysAuthDao">
<select id="queryOauth2WX" resultType="com.ccsens.tall.bean.vo.UserVo$Oauth2WX">
select identifier as openid, user_id as userId
from t_sys_auth
where identify_type = 4
and user_id in
<foreach collection="list" open="(" close=")" separator="," item="item">
#{item}
</foreach>
and rec_status = 0
</select>
</mapper>

2
tall/src/main/resources/mapper_dao/SysOperationDao.xml

@ -1,6 +1,6 @@
<?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.ccsens.tall.persist.dao.SysOperationDao" xmlns:c="http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ccsens.tall.persist.dao.SysOperationDao">
<resultMap id="MessageQuery" type="com.ccsens.tall.bean.vo.ProjectMessageVo$Query">
<result column="id" jdbcType="BIGINT" property="id"></result>

Loading…
Cancel
Save