Browse Source

Merge remote-tracking branch 'remotes/origin/dev_group_point' into dev_temp

# Conflicts:
#	epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/ResiGroupServiceImpl.java
#	epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/member/dao/ResiGroupMemberDao.java
#	epmet-module/resi-group/resi-group-server/src/main/resources/mapper/member/ResiGroupMemberDao.xml
dev_shibei_match
jianjun 4 years ago
parent
commit
7f3c93de50
  1. 7
      epmet-commons/epmet-commons-rocketmq/pom.xml
  2. 5
      epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/constants/ConsomerGroupConstants.java
  3. 7
      epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/constants/TopicConstants.java
  4. 27
      epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/messages/GroupAchievementMQMsg.java
  5. 5
      epmet-module/epmet-message/epmet-message-client/pom.xml
  6. 5
      epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/constant/SystemMessageType.java
  7. 68
      epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/send/SendMqMsgUtil.java
  8. 3
      epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/impl/SystemMessageServiceImpl.java
  9. 21
      epmet-module/resi-group/resi-group-server/pom.xml
  10. 32
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/dao/ResiGroupAchievementConfigDao.java
  11. 30
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/dao/ResiGroupAchievementStatsDao.java
  12. 9
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/entity/ResiGroupAchievementStatsEntity.java
  13. 103
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/AbstractStatsAchievementService.java
  14. 65
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/ResiGroupAchievementConfigService.java
  15. 25
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/ResiGroupAchievementStatsService.java
  16. 51
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/StatsAchievementService.java
  17. 64
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/ResiGroupAchievementConfigServiceImpl.java
  18. 12
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/ResiGroupAchievementStatsServiceImpl.java
  19. 10
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/ResiGroupServiceImpl.java
  20. 218
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/StatsAchievementServiceImpl.java
  21. 11
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/member/dao/ResiGroupMemberDao.java
  22. 34
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/support/GroupAchievementUtils.java
  23. 1
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/topic/controller/ResiTopicController.java
  24. 15
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/topic/service/impl/ResiTopicServiceImpl.java
  25. 15
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/topic/service/impl/TopicDraftServiceImpl.java
  26. 37
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/mq/GroupAchieventConsumerListener.java
  27. 77
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/mq/type1/GroupAchievementCustomListener.java
  28. 63
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/mq/type1/RocketMQConsumerRegister.java
  29. 5
      epmet-module/resi-group/resi-group-server/src/main/resources/bootstrap.yml
  30. 39
      epmet-module/resi-group/resi-group-server/src/main/resources/mapper/group/ResiGroupAchievementConfigDao.xml
  31. 63
      epmet-module/resi-group/resi-group-server/src/main/resources/mapper/group/ResiGroupAchievementStatsDao.xml
  32. 12
      epmet-module/resi-group/resi-group-server/src/main/resources/mapper/member/ResiGroupMemberDao.xml
  33. 31
      epmet-module/resi-group/resi-group-server/src/test/com/epmet/modules/group/service/impl/StatsAchievementServiceImplTest.java

7
epmet-commons/epmet-commons-rocketmq/pom.xml

@ -16,6 +16,11 @@
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-starter</artifactId>
<version>2.0.1</version>
<!--<version>2.2.0</version>-->
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
</project>
</project>

5
epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/constants/ConsomerGroupConstants.java

@ -22,4 +22,9 @@ public interface ConsomerGroupConstants {
*/
String ISSUE_PROJECT_CATEGORY_TAG = "issue_project_category_tag";
/**
* 小组成就消费者组
*/
String GROUP_ACHIEVEMENT_COMPONENTS_GROUP = "group_achievement_components_group";
}

7
epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/constants/TopicConstants.java

@ -1,5 +1,12 @@
package com.epmet.commons.rocketmq.constants;
public interface TopicConstants {
/**
* 初始化客户
*/
String INIT_CUSTOMER = "init_customer";
/**
* 小组成就
*/
String GROUP_ACHIEVEMENT = "group_achievement";
}

27
epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/messages/GroupAchievementMQMsg.java

@ -0,0 +1,27 @@
package com.epmet.commons.rocketmq.messages;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.io.Serializable;
/**
* desc:小组成就mq消息类
*
* @author LiuJanJun
* @date 2021/4/22 8:35 下午
*/
@Data
@AllArgsConstructor
public class GroupAchievementMQMsg implements Serializable {
private String customerId;
private String groupId;
/**
* 成就类型
* @see com.epmet.modules.enums.AchievementTypeEnum
*/
private String achievementType;
}

5
epmet-module/epmet-message/epmet-message-client/pom.xml

@ -26,6 +26,11 @@
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-commons-rocketmq</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
<build>

5
epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/constant/SystemMessageType.java

@ -10,4 +10,9 @@ public interface SystemMessageType {
*/
String INIT_CUSTOMER = "init_customer";
/**
* 小组成就
*/
String GROUP_ACHIEVEMENT = "group_achievement";
}

68
epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/send/SendMqMsgUtil.java

@ -0,0 +1,68 @@
package com.epmet.send;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.rocketmq.messages.GroupAchievementMQMsg;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.utils.Result;
import com.epmet.constant.SystemMessageType;
import com.epmet.dto.form.SystemMsgFormDTO;
import com.epmet.feign.EpmetMessageOpenFeignClient;
import lombok.extern.slf4j.Slf4j;
/**
* desc: 发送mq消息直接到rocketMq 系统
*
* @author: LiuJanJun
* @date: 2021/4/23 2:39 下午
* @versio: 1.0
*/
@Slf4j
public class SendMqMsgUtil {
private static final SendMqMsgUtil INSTANCE = new SendMqMsgUtil();
private SendMqMsgUtil() {
}
private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient;
public static SendMqMsgUtil build() {
return INSTANCE;
}
public SendMqMsgUtil openFeignClient(EpmetMessageOpenFeignClient epmetMessageOpenFeignClient) {
this.epmetMessageOpenFeignClient = epmetMessageOpenFeignClient;
return this;
}
/**
* desc: 发送小组成就消息,计算小组成就
*
* @param msgContent
* @return boolean
* @author LiuJanJun
* @date 2021/4/23 3:01 下午
* @remark 失败重试1次
*/
public boolean sendGroupAchievementMqMsg(GroupAchievementMQMsg msgContent) {
try {
SystemMsgFormDTO systemMsgFormDTO = new SystemMsgFormDTO();
systemMsgFormDTO.setMessageType(SystemMessageType.GROUP_ACHIEVEMENT);
systemMsgFormDTO.setContent(msgContent);
Result sendMsgResult = null;
int retryTime = 1;
do {
sendMsgResult = epmetMessageOpenFeignClient.sendSystemMsgByMQ(systemMsgFormDTO);
} while ((sendMsgResult == null || !sendMsgResult.success()) && retryTime++ < NumConstant.TWO);
if (sendMsgResult != null && sendMsgResult.success()) {
return true;
}
log.error("发送(小组成就)系统消息到message服务失败:{},msg:{}", JSON.toJSONString(sendMsgResult), JSON.toJSONString(systemMsgFormDTO));
} catch (Exception e) {
log.error("sendMqMsg exception", e);
}
return false;
}
}

3
epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/impl/SystemMessageServiceImpl.java

@ -64,6 +64,9 @@ public class SystemMessageServiceImpl implements SystemMessageService {
case SystemMessageType.INIT_CUSTOMER:
topic = TopicConstants.INIT_CUSTOMER;
break;
case SystemMessageType.GROUP_ACHIEVEMENT:
topic = TopicConstants.GROUP_ACHIEVEMENT;
break;
}
return topic;
}

21
epmet-module/resi-group/resi-group-server/pom.xml

@ -112,6 +112,12 @@
<version>2.0.0</version>
<scope>compile</scope>
</dependency>
<!--rocketmq-->
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-commons-rocketmq</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
<build>
@ -185,6 +191,10 @@
</dingTalk.robot.webHook>
<dingTalk.robot.secret>SEC080aac67ff78e79fdaba132aa51e3fb3f6060dec99492feaac82cabf9f8b6a19
</dingTalk.robot.secret>
<!--rocketmq-->
<rocketmq.nameserver>192.168.1.130:9876;192.168.1.132:9876</rocketmq.nameserver>
<rocketmq.producer.group>epmet_message</rocketmq.producer.group>
</properties>
</profile>
<profile>
@ -237,6 +247,9 @@
</dingTalk.robot.webHook>
<dingTalk.robot.secret>SEC080aac67ff78e79fdaba132aa51e3fb3f6060dec99492feaac82cabf9f8b6a19
</dingTalk.robot.secret>
<!--rocketmq-->
<rocketmq.nameserver>192.168.1.130:9876;192.168.1.132:9876</rocketmq.nameserver>
<rocketmq.producer.group>epmet_message</rocketmq.producer.group>
</properties>
</profile>
<profile>
@ -288,6 +301,10 @@
</dingTalk.robot.webHook>
<dingTalk.robot.secret>SEC080aac67ff78e79fdaba132aa51e3fb3f6060dec99492feaac82cabf9f8b6a19
</dingTalk.robot.secret>
<!--rocketmq-->
<rocketmq.nameserver>192.168.10.161:9876</rocketmq.nameserver>
<rocketmq.producer.group>epmet_message</rocketmq.producer.group>
</properties>
</profile>
<profile>
@ -336,6 +353,10 @@
</dingTalk.robot.webHook>
<dingTalk.robot.secret>SEC95f4f40b533ad379ea6a6d1af6dd37029383cfe1b7cd96dfac2678be2c1c3ed1
</dingTalk.robot.secret>
<!--rocketmq-->
<rocketmq.nameserver>192.168.11.187:9876;192.168.11.184:9876</rocketmq.nameserver>
<rocketmq.producer.group>epmet_message</rocketmq.producer.group>
</properties>
</profile>
</profiles>

32
epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/dao/ResiGroupAchievementConfigDao.java

@ -1,4 +1,4 @@
/**
package com.epmet.modules.group.dao; /**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
@ -15,11 +15,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.modules.group.dao;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.modules.group.entity.ResiGroupAchievementConfigEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 小组成就配置表
@ -29,5 +32,26 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface ResiGroupAchievementConfigDao extends BaseDao<ResiGroupAchievementConfigEntity> {
}
/**
* desc: 获取成就配置 比targetValue
*
* @param achievementType
* @param offset
* @param pageSize
* @return java.util.List<com.epmet.modules.group.entity.ResiGroupAchievementConfigEntity>
* @author LiuJanJun
* @date 2021/4/21 10:04 下午
*/
List<ResiGroupAchievementConfigEntity> selectMoreThanOneByValue(@Param("achievementType") String achievementType, @Param("offset") int offset, @Param("pageSize") int pageSize);
/**
* desc: 获取最后一条配置
*
* @param achievementType
* @return com.epmet.modules.group.entity.ResiGroupAchievementConfigEntity
* @author LiuJanJun
* @date 2021/4/22 1:58 下午
*/
ResiGroupAchievementConfigEntity getLastOne(@Param("achievementType") String achievementType);
}

30
epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/dao/ResiGroupAchievementStatsDao.java

@ -35,10 +35,34 @@ import java.util.List;
public interface ResiGroupAchievementStatsDao extends BaseDao<ResiGroupAchievementStatsEntity> {
/**
* 获取未完成的成就
* @author zhaoqifeng
* @date 2021/4/19 15:52
*
* @param groupId
* @return java.util.List<com.epmet.resi.group.dto.group.ResiGroupMilestoneStatsDTO>
* @author zhaoqifeng
* @date 2021/4/19 15:52
*/
List<ResiGroupAchievementStatsDTO> selectUnAchieved(@Param("groupId") String groupId);
}
/**
* desc: 获取最后一个为实现的成就
*
* @param customerId
* @param groupId
* @param achievementType
* @return com.epmet.modules.group.entity.ResiGroupAchievementStatsEntity
* @author LiuJanJun
* @date 2021/4/21 8:34 下午
*/
ResiGroupAchievementStatsEntity selectLastUnAchieved(@Param("customerId") String customerId, @Param("groupId") String groupId, @Param("achievementType") String achievementType);
/**
* desc: 插入或更新成就
*
* @param haveArrive
* @param updateAll
* @return int
* @author LiuJanJun
* @date 2021/4/22 3:03 下午
*/
int saveOrUpdate(@Param("list") List<ResiGroupAchievementStatsEntity> list, @Param("updateAll") boolean updateAll);
}

9
epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/entity/ResiGroupAchievementStatsEntity.java

@ -49,15 +49,20 @@ public class ResiGroupAchievementStatsEntity extends BaseEpmetEntity {
private String groupId;
/**
* 里程ID
* 成就ID
*/
private String achievementId;
/**
* 里程名称
* 成就名称
*/
private String achievementName;
/**
* 成就类型
*/
private String achievementType;
/**
* 实现时间
*/

103
epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/AbstractStatsAchievementService.java

@ -0,0 +1,103 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.modules.group.service;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.modules.enums.AchievementTypeEnum;
import com.epmet.modules.group.entity.ResiGroupAchievementConfigEntity;
import com.epmet.modules.support.GroupAchievementUtils;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.List;
/**
* desc实时计算小组成就完成情况
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2021-04-19
*/
public abstract class AbstractStatsAchievementService {
@Autowired
public ResiGroupAchievementConfigService achievementConfigService;
@Autowired
public ResiGroupAchievementStatsService achievementStatsService;
/**
* desc: 根据成绩类型 分页获取成就配置 按targetValue 升序
*
* @param offset
* @param pageSize
* @return java.util.List<com.epmet.modules.group.entity.ResiGroupAchievementConfigEntity>
* @author LiuJanJun
* @date 2021/4/22 1:36 下午
*/
/**
* desc: 根据成绩类型 分页获取成就配置 按targetValue 升序
*
* @param pageNum
* @param pageSize
* @return java.util.List<com.epmet.modules.group.entity.ResiGroupAchievementConfigEntity>
* @author LiuJanJun
* @date 2021/4/22 1:36 下午
*/
protected List<ResiGroupAchievementConfigEntity> getAchievemnetConfigPage(int pageNum, int pageSize, String achievementType) {
return achievementConfigService.selectMoreThanOneByValue(achievementType, (pageNum - NumConstant.ONE) * pageSize, pageSize);
}
/**
* desc:初始化配置5条
*
* @param achievementType
* @return
*/
protected List<ResiGroupAchievementConfigEntity> initAchievementConfig(String achievementType) {
AchievementTypeEnum anEnum = AchievementTypeEnum.getEnum(achievementType);
if (anEnum == null) {
throw new RenException(EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getCode());
}
if (AchievementTypeEnum.MEMBER.getCode().equals(anEnum.getCode())) {
throw new RenException("小组人数都到10000啦?");
}
ResiGroupAchievementConfigEntity lastOne = achievementConfigService.getLastOne(achievementType);
List<ResiGroupAchievementConfigEntity> newConfigList = new ArrayList<>();
Integer nextTargetValue = null;
int preValue = lastOne.getTargetValue();
String oldName = lastOne.getAchievementName().replace(String.valueOf(lastOne.getTargetValue()), StrConstant.UNDER_LINE);
for (int i = 0; i < 5; i++) {
nextTargetValue = GroupAchievementUtils.getNextTargetValue(achievementType, preValue);
ResiGroupAchievementConfigEntity next = new ResiGroupAchievementConfigEntity();
next.setCustomerId(lastOne.getCustomerId());
next.setAchievementName(oldName.replace(StrConstant.UNDER_LINE, String.valueOf(nextTargetValue)));
//todo 把这个字段去掉
next.setPreValue(preValue);
preValue = nextTargetValue;
next.setTargetValue(nextTargetValue);
next.setAchievementType(lastOne.getAchievementType());
newConfigList.add(next);
}
achievementConfigService.insertBatch(newConfigList);
return newConfigList;
}
}

65
epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/ResiGroupAchievementConfigService.java

@ -18,12 +18,9 @@
package com.epmet.modules.group.service;
import com.epmet.commons.mybatis.service.BaseService;
import com.epmet.commons.tools.page.PageData;
import com.epmet.modules.group.entity.ResiGroupAchievementConfigEntity;
import com.epmet.resi.group.dto.group.ResiGroupAchievementConfigDTO;
import java.util.List;
import java.util.Map;
/**
* 小组成就配置表
@ -33,63 +30,7 @@ import java.util.Map;
*/
public interface ResiGroupAchievementConfigService extends BaseService<ResiGroupAchievementConfigEntity> {
/**
* 默认分页
*
* @param params
* @return PageData<ResiGroupMilestoneConfigDTO>
* @author generator
* @date 2021-04-19
*/
PageData<ResiGroupAchievementConfigDTO> page(Map<String, Object> params);
ResiGroupAchievementConfigEntity getLastOne(String achievementType);
/**
* 默认查询
*
* @param params
* @return java.util.List<ResiGroupMilestoneConfigDTO>
* @author generator
* @date 2021-04-19
*/
List<ResiGroupAchievementConfigDTO> list(Map<String, Object> params);
/**
* 单条查询
*
* @param id
* @return ResiGroupMilestoneConfigDTO
* @author generator
* @date 2021-04-19
*/
ResiGroupAchievementConfigDTO get(String id);
/**
* 默认保存
*
* @param dto
* @return void
* @author generator
* @date 2021-04-19
*/
void save(ResiGroupAchievementConfigDTO dto);
/**
* 默认更新
*
* @param dto
* @return void
* @author generator
* @date 2021-04-19
*/
void update(ResiGroupAchievementConfigDTO dto);
/**
* 批量删除
*
* @param ids
* @return void
* @author generator
* @date 2021-04-19
*/
void delete(String[] ids);
}
List<ResiGroupAchievementConfigEntity> selectMoreThanOneByValue(String achievementType,int offset,int pageSize);
}

25
epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/ResiGroupAchievementStatsService.java

@ -110,4 +110,27 @@ public interface ResiGroupAchievementStatsService extends BaseService<ResiGroupA
* @return java.util.List<com.epmet.resi.group.dto.group.ResiGroupMilestoneStatsDTO>
*/
List<ResiGroupAchievementStatsDTO> getUnAchieved(String groupId);
}
/**
* desc: 获取最后未实现的成就 实际每种类型 数据库只存在一条未实现的成就
*
* @param customerId
* @param groupId
* @param achievementType
* @return com.epmet.modules.group.entity.ResiGroupAchievementStatsEntity
* @author LiuJanJun
* @date 2021/4/22 2:35 下午
*/
ResiGroupAchievementStatsEntity selectLastUnAchieved(String customerId, String groupId, String achievementType);
/**
* desc: 插入或更新成就
*
* @param haveArrive
* @param updateAll
* @return int
* @author LiuJanJun
* @date 2021/4/22 3:03 下午
*/
int saveOrUpdate(List<ResiGroupAchievementStatsEntity> haveArrive, boolean updateAll);
}

51
epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/StatsAchievementService.java

@ -0,0 +1,51 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.modules.group.service;
/**
* desc实时计算小组成就完成情况
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2021-04-19
*/
public interface StatsAchievementService{
/**
* desc: 计算小组成就 统一入口
*
* @param achievementType 成就类型 小组人数话题数转议题数小组内问题解决数
* @return java.lang.Boolean
* @author LiuJanJun
* @date 2021/4/20
*/
Boolean calculateAcm(String achievementType);
/**
* desc: 根据小组Id计算小组成就 入口
*
* @param customerId
* @param groupId
* @param achievementType 成就类型 小组人数话题数转议题数小组内问题解决数
* @return java.lang.Boolean
* @author LiuJanJun
* @date 2021/4/20
*/
Boolean calculateAcm(String customerId, String groupId, String achievementType);
}

64
epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/ResiGroupAchievementConfigServiceImpl.java

@ -17,23 +17,13 @@
package com.epmet.modules.group.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.modules.group.dao.ResiGroupAchievementConfigDao;
import com.epmet.modules.group.entity.ResiGroupAchievementConfigEntity;
import com.epmet.modules.group.service.ResiGroupAchievementConfigService;
import com.epmet.resi.group.dto.group.ResiGroupAchievementConfigDTO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* 小组成就配置表
@ -44,57 +34,13 @@ import java.util.Map;
@Service
public class ResiGroupAchievementConfigServiceImpl extends BaseServiceImpl<ResiGroupAchievementConfigDao, ResiGroupAchievementConfigEntity> implements ResiGroupAchievementConfigService {
@Override
public PageData<ResiGroupAchievementConfigDTO> page(Map<String, Object> params) {
IPage<ResiGroupAchievementConfigEntity> page = baseDao.selectPage(
getPage(params, FieldConstant.CREATED_TIME, false),
getWrapper(params)
);
return getPageData(page, ResiGroupAchievementConfigDTO.class);
}
@Override
public List<ResiGroupAchievementConfigDTO> list(Map<String, Object> params) {
List<ResiGroupAchievementConfigEntity> entityList = baseDao.selectList(getWrapper(params));
return ConvertUtils.sourceToTarget(entityList, ResiGroupAchievementConfigDTO.class);
}
private QueryWrapper<ResiGroupAchievementConfigEntity> getWrapper(Map<String, Object> params){
String id = (String)params.get(FieldConstant.ID_HUMP);
QueryWrapper<ResiGroupAchievementConfigEntity> wrapper = new QueryWrapper<>();
wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id);
return wrapper;
public ResiGroupAchievementConfigEntity getLastOne(String achievementType) {
return baseDao.getLastOne(achievementType);
}
@Override
public ResiGroupAchievementConfigDTO get(String id) {
ResiGroupAchievementConfigEntity entity = baseDao.selectById(id);
return ConvertUtils.sourceToTarget(entity, ResiGroupAchievementConfigDTO.class);
public List<ResiGroupAchievementConfigEntity> selectMoreThanOneByValue(String achievementType,int offset,int pageSize) {
return baseDao.selectMoreThanOneByValue(achievementType,offset,pageSize);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void save(ResiGroupAchievementConfigDTO dto) {
ResiGroupAchievementConfigEntity entity = ConvertUtils.sourceToTarget(dto, ResiGroupAchievementConfigEntity.class);
insert(entity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(ResiGroupAchievementConfigDTO dto) {
ResiGroupAchievementConfigEntity entity = ConvertUtils.sourceToTarget(dto, ResiGroupAchievementConfigEntity.class);
updateById(entity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(String[] ids) {
// 逻辑删除(@TableLogic 注解)
baseDao.deleteBatchIds(Arrays.asList(ids));
}
}
}

12
epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/ResiGroupAchievementStatsServiceImpl.java

@ -131,4 +131,14 @@ public class ResiGroupAchievementStatsServiceImpl extends BaseServiceImpl<ResiGr
return baseDao.selectUnAchieved(groupId);
}
}
@Override
public ResiGroupAchievementStatsEntity selectLastUnAchieved(String customerId, String groupId, String achievementType) {
return baseDao.selectLastUnAchieved(customerId,groupId,achievementType);
}
@Override
public int saveOrUpdate(List<ResiGroupAchievementStatsEntity> haveArrive, boolean updateAll) {
return baseDao.saveOrUpdate(haveArrive, updateAll);
}
}

10
epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/ResiGroupServiceImpl.java

@ -21,6 +21,7 @@ import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.rocketmq.messages.GroupAchievementMQMsg;
import com.epmet.commons.tools.constant.*;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.RenException;
@ -44,6 +45,7 @@ import com.epmet.feign.EpmetMessageOpenFeignClient;
import com.epmet.group.constant.GroupConstant;
import com.epmet.feign.EpmetUserOpenFeignClient;
import com.epmet.modules.constant.UserMessageConstant;
import com.epmet.modules.enums.AchievementTypeEnum;
import com.epmet.modules.feign.EpmetMessageFeignClient;
import com.epmet.modules.feign.EpmetUserFeignClient;
import com.epmet.modules.feign.GovOrgFeignClient;
@ -75,6 +77,7 @@ import com.epmet.resi.group.dto.member.ResiGroupMemberInfoRedisDTO;
import com.epmet.resi.group.dto.member.form.EditAuditSwitchFormDTO;
import com.epmet.resi.group.dto.member.result.AchievementResultDTO;
import com.epmet.resi.group.dto.member.result.GroupAchievementDTO;
import com.epmet.send.SendMqMsgUtil;
import com.github.pagehelper.PageHelper;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@ -676,6 +679,13 @@ public class ResiGroupServiceImpl extends BaseServiceImpl<ResiGroupDao, ResiGrou
List<WxSubscribeMessageFormDTO> msgList = new ArrayList<>();
msgList.add(wxSubscribeMessageFormDTO);
epmetMessageOpenFeignClient.sendWxSubscribeMessage(msgList);
//发送小组成就消息
boolean flag = SendMqMsgUtil.build().openFeignClient(epmetMessageOpenFeignClient)
.sendGroupAchievementMqMsg(new GroupAchievementMQMsg(resiGroupDTO.getCustomerId(),resiGroupDTO.getId(),AchievementTypeEnum.MEMBER.getCode()));
if (!flag) {
logger.error("发送(小组成就)系统消息到message服务失败");
}
return new Result();
}

218
epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/StatsAchievementServiceImpl.java

@ -0,0 +1,218 @@
package com.epmet.modules.group.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.modules.enums.AchievementTypeEnum;
import com.epmet.modules.group.entity.ResiGroupAchievementConfigEntity;
import com.epmet.modules.group.entity.ResiGroupAchievementStatsEntity;
import com.epmet.modules.group.service.AbstractStatsAchievementService;
import com.epmet.modules.group.service.StatsAchievementService;
import com.epmet.modules.member.dao.ResiGroupMemberDao;
import com.epmet.modules.topic.dao.ResiTopicDao;
import com.epmet.modules.topic.entity.ResiTopicEntity;
import com.epmet.resi.group.constant.TopicConstant;
import com.epmet.resi.group.dto.group.ResiGroupAchievementStatsDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* desc:
*
* @author: LiuJanJun
* @date: 2021/4/20 5:48 下午
* @version: 1.0
*/
@Slf4j
@Service
public class StatsAchievementServiceImpl extends AbstractStatsAchievementService implements StatsAchievementService {
@Autowired
private ResiGroupMemberDao resiGroupMemberDao;
@Autowired
private ResiTopicDao resiTopicDao;
/**
* desc: 计算小组成就 统一入口
*
* @param achievementType 成就类型
* @return java.lang.Boolean
* @author LiuJanJun
* @date 2021/4/20
*/
@Override
public Boolean calculateAcm(String achievementType) {
if (StringUtils.isBlank(achievementType)) {
//计算所有类型的 小组人数、话题数、转议题数、小组内问题解决数
}
return null;
}
/**
* desc: 根据小组Id计算小组成就 入口
*
* @param customerId
* @param groupId
* @param achievementType 成就类型 小组人数话题数转议题数小组内问题解决数
* @return java.lang.Boolean
* @author LiuJanJun
* @date 2021/4/20
*/
@Override
public Boolean calculateAcm(String customerId, String groupId, String achievementType) {
AchievementTypeEnum anEnum = AchievementTypeEnum.getEnum(achievementType);
if (StringUtils.isBlank(customerId) || StringUtils.isBlank(groupId) || anEnum == null) {
return false;
}
Integer currentValue = null;
switch (anEnum) {
case TOPIC:
//查询话题数
QueryWrapper<ResiTopicEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(ResiTopicEntity::getCustomerId,customerId)
.eq(ResiTopicEntity::getGroupId,groupId)
.eq(ResiTopicEntity::getDelFlag,NumConstant.ZERO);
currentValue = resiTopicDao.selectCount(queryWrapper);
break;
case MEMBER:
currentValue = resiGroupMemberDao.countMembers(customerId, groupId);
break;
case TOISSUE:
//查询已经转议题的话题数
queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(ResiTopicEntity::getCustomerId,customerId)
.eq(ResiTopicEntity::getGroupId,groupId)
.eq(ResiTopicEntity::getShiftIssue, NumConstant.ONE)
.eq(ResiTopicEntity::getDelFlag,NumConstant.ZERO);
currentValue = resiTopicDao.selectCount(queryWrapper);
break;
case RESOVLE_TOPIC:
//查询已经关闭且为已解决的话题数
queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(ResiTopicEntity::getCustomerId,customerId)
.eq(ResiTopicEntity::getGroupId,groupId)
.eq(ResiTopicEntity::getStatus, TopicConstant.CLOSED)
.eq(ResiTopicEntity::getClosedStatus, TopicConstant.RESOLVED)
.eq(ResiTopicEntity::getShiftIssue, NumConstant.ONE)
.eq(ResiTopicEntity::getDelFlag,NumConstant.ZERO);
currentValue = resiTopicDao.selectCount(queryWrapper);
break;
default:
log.info("calculateAcm error");
}
calculateGroupAchievement(customerId, groupId, currentValue, achievementType);
return true;
}
/**
* desc: 计算小组的人数等级
*
* @param customerId
* @param groupId
*/
private void calculateGroupAchievement(String customerId, String groupId, int currentValue, String achievementType) {
ResiGroupAchievementStatsEntity one = super.achievementStatsService.selectLastUnAchieved(customerId, groupId, achievementType);
List<ResiGroupAchievementStatsEntity> haveArrive = new ArrayList<>();
//如果没有实现的额成就则说明是初始化
if (one == null) {
initAchievementStat(customerId, groupId, achievementType, currentValue, haveArrive);
super.achievementStatsService.saveOrUpdate(haveArrive,false);
return;
}
boolean isBatch = false;
Integer targetValue = one.getTargetValue();
//改为已实现
if (currentValue >= targetValue) {
isBatch = true;
boolean isContinue;
int pageNum = NumConstant.ONE;
int pageSize = NumConstant.TEN;
do {
List<ResiGroupAchievementConfigEntity> list = getConfigByType(achievementType,pageNum++,pageSize);
isContinue = buildArriveList(customerId, groupId, achievementType, currentValue, one.getTargetValue(), haveArrive, list);
}while (isContinue);
}
if (isBatch) {
super.achievementStatsService.saveOrUpdate(haveArrive,true);
} else {
//未实现 只更新当前值
ResiGroupAchievementStatsDTO newStat = new ResiGroupAchievementStatsDTO();
newStat.setId(one.getId());
newStat.setCurrentValue(currentValue);
super.achievementStatsService.update(newStat);
}
}
private void initAchievementStat(String customerId, String groupId, String achievementType, int currentValue, List<ResiGroupAchievementStatsEntity> haveArrive) {
boolean isContinue;
int pageNum = NumConstant.ONE;
int pageSize = NumConstant.TEN;
do { //没有任何数据说明是初始化
List<ResiGroupAchievementConfigEntity> list = getConfigByType(achievementType,pageNum++,pageSize);
//查询和初始化都失败啦
if (CollectionUtils.isEmpty(list)) {
log.error("calculateMember get config fail");
throw new RenException(EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getCode());
}
isContinue = buildArriveList(customerId, groupId, achievementType, currentValue, null, haveArrive, list);
}while (isContinue);
if (CollectionUtils.isEmpty(haveArrive)) {
throw new RenException("小组达成成就失败");
}
}
private boolean buildArriveList(String customerId, String groupId, String achievementType, int currentValue, Integer targetValue, List<ResiGroupAchievementStatsEntity> haveArrive, List<ResiGroupAchievementConfigEntity> list) {
boolean isContinue = true;
for (ResiGroupAchievementConfigEntity configEntity : list) {
if (targetValue != null) {
//筛选出已经完成的成就
if (configEntity.getTargetValue()<targetValue){
continue;
}
}
ResiGroupAchievementStatsEntity statsEntity = new ResiGroupAchievementStatsEntity();
statsEntity.setCustomerId(customerId);
statsEntity.setGroupId(groupId);
statsEntity.setAchievementId(configEntity.getId());
statsEntity.setAchievementName(configEntity.getAchievementName());
statsEntity.setArriveTime(new Date());
statsEntity.setAchievementType(achievementType);
statsEntity.setCurrentValue(currentValue);
statsEntity.setTargetValue(configEntity.getTargetValue());
haveArrive.add(statsEntity);
if (currentValue >= configEntity.getTargetValue()) {
statsEntity.setIsArrive(NumConstant.ONE);
} else {
//如果没有达到则 放入这一条后 退出
statsEntity.setIsArrive(NumConstant.ZERO);
isContinue = false;
break;
}
}
return isContinue;
}
private List<ResiGroupAchievementConfigEntity> getConfigByType(String achievementType,int pageNum,int pageSize) {
List<ResiGroupAchievementConfigEntity> list = super.getAchievemnetConfigPage(pageNum, pageSize, achievementType);
if (CollectionUtils.isEmpty(list)) {
log.warn("获取小组成就配置错误,{} 开始进行初始化规则", achievementType);
list = super.initAchievementConfig(achievementType);
}
return list;
}
}

11
epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/member/dao/ResiGroupMemberDao.java

@ -168,4 +168,15 @@ public interface ResiGroupMemberDao extends BaseDao<ResiGroupMemberEntity> {
* @date 2021/4/20 下午4:03
*/
String selectUserRole(@Param("groupId")String groupId, @Param("userId")String userId);
/**
* desc: 仅统计除组长之外的成员数
*
* @param customerId
* @param groupId
* @return int
* @author LiuJanJun
* @date 2021/4/23 3:14 下午
*/
int countMembers(@Param("customerId") String customerId, @Param("groupId") String groupId);
}

34
epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/support/GroupAchievementUtils.java

@ -3,6 +3,7 @@ package com.epmet.modules.support;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.modules.enums.AchievementTypeEnum;
/**
* desc:小组成就下一等级规则工具类
@ -20,7 +21,7 @@ public class GroupAchievementUtils {
*
* @param currentValue
*/
public static Integer getNextTopicTargetValue(Integer currentValue) {
private static Integer getNextTopicTargetValue(Integer currentValue) {
if (currentValue < NumConstant.FIVE_HUNDRED) {
throw new RenException(EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getCode());
}
@ -32,7 +33,7 @@ public class GroupAchievementUtils {
*
* @param currentValue
*/
public static Integer getNextToIssueTargetValue(Integer currentValue) {
private static Integer getNextToIssueTargetValue(Integer currentValue) {
if (currentValue < NumConstant.ONE_HUNDRED) {
throw new RenException(EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getCode());
}
@ -44,10 +45,37 @@ public class GroupAchievementUtils {
*
* @param currentValue
*/
public static Integer getNextResolveTopicTargetValue(Integer currentValue) {
private static Integer getNextResolveTopicTargetValue(Integer currentValue) {
if (currentValue < NumConstant.ONE_HUNDRED) {
throw new RenException(EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getCode());
}
return currentValue + NumConstant.ONE_HUNDRED;
}
/**
* desc:获取下一等级的话题数目标值 步长500 起始值 500
*
* @param currentValue
*/
public static Integer getNextTargetValue(String achievementType, Integer currentValue) {
AchievementTypeEnum anEnum = AchievementTypeEnum.getEnum(achievementType);
if (anEnum == null){
throw new RenException(EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getCode());
}
Integer next = null;
switch (anEnum){
case TOPIC:
next = getNextTopicTargetValue(currentValue);
break;
case TOISSUE:
next = getNextToIssueTargetValue(currentValue);
break;
case RESOVLE_TOPIC:
next = getNextResolveTopicTargetValue(currentValue);
break;
default:
}
return next;
}
}

1
epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/topic/controller/ResiTopicController.java

@ -47,6 +47,7 @@ public class ResiTopicController {
* @Author wangc
* @Date 2020.03.31 13:15
**/
@Deprecated
@PostMapping("createtopic")
public Result createTopic(@LoginUser TokenDto tokenDto, @RequestBody ResiTopicPublishFormDTO topicPublishFormDTO){

15
epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/topic/service/impl/ResiTopicServiceImpl.java

@ -22,6 +22,7 @@ import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.rocketmq.messages.GroupAchievementMQMsg;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.constant.MqConstant;
import com.epmet.commons.tools.constant.NumConstant;
@ -54,6 +55,7 @@ import com.epmet.feign.GovOrgOpenFeignClient;
import com.epmet.modules.constant.GroupMemberConstant;
import com.epmet.modules.constant.ResiGroupRedisKeys;
import com.epmet.modules.constant.WxmpSubscribeConstant;
import com.epmet.modules.enums.AchievementTypeEnum;
import com.epmet.modules.feign.EpmetUserFeignClient;
import com.epmet.modules.feign.GovIssueFeignClient;
import com.epmet.modules.feign.GovOrgFeignClient;
@ -100,9 +102,11 @@ import com.epmet.resi.group.dto.topic.form.*;
import com.epmet.resi.group.dto.topic.result.CheckTopicPublisherResultDTO;
import com.epmet.resi.group.dto.topic.result.GovTopicIssueInfoResultDTO;
import com.epmet.resi.group.dto.topic.result.*;
import com.epmet.send.SendMqMsgUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.base.CharMatcher;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
@ -124,6 +128,7 @@ import java.util.stream.Collectors;
* @author generator generator@elink-cn.com
* @since v1.0.0 2020-03-31
*/
@Data
@Service
@Slf4j
public class ResiTopicServiceImpl extends BaseServiceImpl<ResiTopicDao, ResiTopicEntity> implements ResiTopicService {
@ -794,6 +799,11 @@ public class ResiTopicServiceImpl extends BaseServiceImpl<ResiTopicDao, ResiTopi
if(!SendMqMsgUtils.sendMsg(mqBaseMsgDTO).success()){
log.error("组长解决话题事件发送失败,参数:{}",JSON.toJSONString(closeFormDTO));
}
//发送小组成就消息
boolean flag = SendMqMsgUtil.build().openFeignClient(epmetMessageOpenFeignClient).sendGroupAchievementMqMsg(new GroupAchievementMQMsg(topic.getCustomerId(), topic.getGroupId(), AchievementTypeEnum.RESOVLE_TOPIC.getCode()));
if (!flag) {
log.error("发送(小组成就)系统消息到message服务失败");
}
}
//2021.4.22 start sun 因业务调整,新增组内消息记录表,话题状态变化时相应的修改数据状态
@ -1791,6 +1801,11 @@ public class ResiTopicServiceImpl extends BaseServiceImpl<ResiTopicDao, ResiTopi
if(!SendMqMsgUtils.sendMsg(mqBaseMsgDTO).success()){
log.error("话题转议题事件发送失败,参数:{}",JSON.toJSONString(topicTurnIssueFromDTO));
}
//发送小组成就消息
boolean flag = SendMqMsgUtil.build().openFeignClient(epmetMessageOpenFeignClient).sendGroupAchievementMqMsg(new GroupAchievementMQMsg(group.getCustomerId(), group.getGroupId(), AchievementTypeEnum.TOISSUE.getCode()));
if (!flag) {
log.error("发送(小组成就)系统消息到message服务失败");
}
}
else {
ValidatorUtils.validateEntity(result, FirstTopicShiftedToIssueApplicationResultDTO.AllowAuditionGroup.class);

15
epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/topic/service/impl/TopicDraftServiceImpl.java

@ -21,6 +21,7 @@ import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.rocketmq.messages.GroupAchievementMQMsg;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.constant.MqConstant;
import com.epmet.commons.tools.constant.NumConstant;
@ -40,7 +41,9 @@ import com.epmet.commons.tools.utils.*;
import com.epmet.dto.form.CommonGridIdFormDTO;
import com.epmet.dto.result.AllGridsByUserIdResultDTO;
import com.epmet.dto.result.CommonDataFilterResultDTO;
import com.epmet.feign.EpmetMessageOpenFeignClient;
import com.epmet.feign.GovOrgOpenFeignClient;
import com.epmet.modules.enums.AchievementTypeEnum;
import com.epmet.modules.feign.EpmetUserFeignClient;
import com.epmet.modules.feign.GovOrgFeignClient;
import com.epmet.modules.group.dao.GroupMessageDao;
@ -77,6 +80,7 @@ import com.epmet.resi.group.dto.topic.form.*;
import com.epmet.resi.group.dto.topic.result.DraftDetailResultDTO;
import com.epmet.resi.group.dto.topic.result.MyAuditingListResultDTO;
import com.epmet.resi.group.dto.topic.result.TopicAuditResultDTO;
import com.epmet.send.SendMqMsgUtil;
import com.google.common.base.CharMatcher;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import lombok.extern.slf4j.Slf4j;
@ -140,6 +144,8 @@ public class TopicDraftServiceImpl extends BaseServiceImpl<TopicDraftDao, TopicD
private TopicDraftScanTaskService topicDraftScanTaskService;
@Autowired
private GovOrgFeignClient govOrgFeignClient;
@Autowired
private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient;
@Value("${openapi.scan.server.url}")
private String scanApiUrl;
@ -990,6 +996,13 @@ public class TopicDraftServiceImpl extends BaseServiceImpl<TopicDraftDao, TopicD
if(!mqResult.success()){
logger.error("发表话题积分添加失败");
}
//发送小组成就消息
boolean flag = SendMqMsgUtil.build().openFeignClient(epmetMessageOpenFeignClient)
.sendGroupAchievementMqMsg(new GroupAchievementMQMsg(customerId,groupId,AchievementTypeEnum.TOPIC.getCode()));
if (!flag) {
log.error("发送(小组成就)系统消息到message服务失败");
}
}
@ -1056,4 +1069,4 @@ public class TopicDraftServiceImpl extends BaseServiceImpl<TopicDraftDao, TopicD
}
}
}
}

37
epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/mq/GroupAchieventConsumerListener.java

@ -0,0 +1,37 @@
package com.epmet.mq;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.rocketmq.messages.GroupAchievementMQMsg;
import com.epmet.modules.group.service.StatsAchievementService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
/**
* desc: 小组成就mq监听
*
* @author: LiuJanJun
* @date: 2021/4/22 10:10 下午
* @version: 1.0
*/
@Slf4j
//@Component
//@RocketMQMessageListener(topic = "group_achievement", consumerGroup = ConsomerGroupConstants.GROUP_ACHIEVEMENT_COMPONENTS_GROUP)
//@Component
public class GroupAchieventConsumerListener implements RocketMQListener<GroupAchievementMQMsg> {
@Autowired
private StatsAchievementService statsAchievementService;
@Override
public void onMessage(GroupAchievementMQMsg msg) {
log.info("receive msg:{}", JSON.toJSONString(msg));
if (StringUtils.isBlank(msg.getAchievementType()) || StringUtils.isBlank(msg.getCustomerId())
|| StringUtils.isBlank(msg.getGroupId())) {
log.error("consumer fail,msg:{}", msg);
return;
}
Boolean aBoolean = statsAchievementService.calculateAcm(msg.getCustomerId(), msg.getGroupId(), msg.getAchievementType());
log.info("consumer msg success,{}", aBoolean);
}
}

77
epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/mq/type1/GroupAchievementCustomListener.java

@ -0,0 +1,77 @@
package com.epmet.mq.type1;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.rocketmq.messages.GroupAchievementMQMsg;
import com.epmet.commons.tools.distributedlock.DistributedLock;
import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.utils.SpringContextUtils;
import com.epmet.modules.group.service.StatsAchievementService;
import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.common.message.MessageExt;
import org.redisson.api.RLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* @Description 小组成就-监听器
* @return
* @author wxz
* @date 2021.03.03 16:10
*/
public class GroupAchievementCustomListener implements MessageListenerConcurrently {
private Logger logger = LoggerFactory.getLogger(getClass());
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
try {
msgs.forEach(this::consumeMessage);
} catch (Exception e) {
logger.error("consumeMessage fail,msg:{}",e.getMessage());
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
private void consumeMessage(MessageExt messageExt) {
String msg = new String(messageExt.getBody());
logger.info("receive msg:{}", JSON.toJSONString(msg));
GroupAchievementMQMsg msgObj = JSON.parseObject(msg, GroupAchievementMQMsg.class);
DistributedLock distributedLock = null;
RLock lock = null;
try {
distributedLock = SpringContextUtils.getBean(DistributedLock.class);
lock = distributedLock.getLock(String.format("lock:init_customer_org:%s", msgObj.getCustomerId()),
30l, 30l, TimeUnit.SECONDS);
if (StringUtils.isBlank(msgObj.getAchievementType()) || StringUtils.isBlank(msgObj.getCustomerId())
|| StringUtils.isBlank(msgObj.getGroupId())){
logger.error("consumer fail,msg:{}",msgObj);
return;
}
Boolean aBoolean = SpringContextUtils.getBean(StatsAchievementService.class).calculateAcm(msgObj.getCustomerId(), msgObj.getGroupId(), msgObj.getAchievementType());
logger.info("consumer msg success,{}",aBoolean);
} catch (RenException e) {
// 如果是我们手动抛出的异常,说明在业务可控范围内。目前不需要MQ重试
logger.error("【RocketMQ】初始化客户组织失败:".concat(ExceptionUtils.getErrorStackTrace(e)));
} catch (Exception e) {
// 不是我们自己抛出的异常,可以让MQ重试
logger.error("【RocketMQ】初始化客户组织失败:".concat(ExceptionUtils.getErrorStackTrace(e)));
throw e;
} finally {
if (distributedLock != null){
distributedLock.unLock(lock);
}
}
}
}

63
epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/mq/type1/RocketMQConsumerRegister.java

@ -0,0 +1,63 @@
package com.epmet.mq.type1;
import com.epmet.commons.rocketmq.constants.ConsomerGroupConstants;
import com.epmet.commons.rocketmq.constants.TopicConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.MessageListener;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.protocol.heartbeat.MessageModel;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@Slf4j
@Component
public class RocketMQConsumerRegister {
@Value("${rocketmq.name-server}")
private String nameServer;
/**
* @return
* @Description 注册监听器
* @author wxz
* @date 2021.03.03 16:09
*/
@PostConstruct
public void registerAllListeners() {
try {
register(ConsomerGroupConstants.GROUP_ACHIEVEMENT_COMPONENTS_GROUP, MessageModel.CLUSTERING, TopicConstants.GROUP_ACHIEVEMENT, "*", new GroupAchievementCustomListener());
} catch (MQClientException e) {
log.error("registerAllListeners exception", e);
}
}
public void register(String group, MessageModel messageModel, String topic, String subException, MessageListener listener) throws MQClientException {
// 实例化消费者
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(group);
// 设置NameServer的地址
consumer.setNamesrvAddr(nameServer);
consumer.setMessageModel(messageModel);
consumer.setInstanceName(buildInstanceName());
// 订阅一个或者多个Topic,以及Tag来过滤需要消费的消息
consumer.subscribe(topic, subException);
// 注册回调实现类来处理从broker拉取回来的消息
consumer.registerMessageListener(listener);
// 启动消费者实例
consumer.start();
}
private String buildInstanceName() {
String instanceName = "";
for (int i = 0; i < 4; i++) {
int t = (int) (Math.random() * 10);
instanceName = instanceName.concat(t + "");
}
return instanceName;
}
}

5
epmet-module/resi-group/resi-group-server/src/main/resources/bootstrap.yml

@ -166,3 +166,8 @@ shutdown:
graceful:
enable: true #是否开启优雅停机
waitTimeSecs: 30 # 优雅停机等待时间,每超过30秒,打印一次错误日志
rocketmq:
name-server: @rocketmq.nameserver@
producer:
group: @rocketmq.producer.group@

39
epmet-module/resi-group/resi-group-server/src/main/resources/mapper/group/ResiGroupAchievementConfigDao.xml

@ -3,20 +3,29 @@
<mapper namespace="com.epmet.modules.group.dao.ResiGroupAchievementConfigDao">
<resultMap type="com.epmet.modules.group.entity.ResiGroupAchievementConfigEntity" id="resiGroupAchievementConfigMap">
<result property="id" column="ID"/>
<result property="customerId" column="CUSTOMER_ID"/>
<result property="achievementName" column="ACHIEVEMENT_NAME"/>
<result property="preValue" column="PRE_VALUE"/>
<result property="targetValue" column="TARGET_VALUE"/>
<result property="achievementType" column="ACHIEVEMENT_TYPE"/>
<result property="delFlag" column="DEL_FLAG"/>
<result property="revision" column="REVISION"/>
<result property="createdBy" column="CREATED_BY"/>
<result property="createdTime" column="CREATED_TIME"/>
<result property="updatedBy" column="UPDATED_BY"/>
<result property="updatedTime" column="UPDATED_TIME"/>
</resultMap>
</mapper>
<select id="selectMoreThanOneByValue" resultType="com.epmet.modules.group.entity.ResiGroupAchievementConfigEntity">
SELECT
id, customer_id, achievement_name, pre_value, target_value, achievement_type
FROM resi_group_achievement_config
WHERE
ACHIEVEMENT_TYPE = #{achievementType}
AND DEL_FLAG = '0'
order by TARGET_VALUE
LIMIT #{offset},#{pageSize}
</select>
<select id="getLastOne" resultType="com.epmet.modules.group.entity.ResiGroupAchievementConfigEntity">
SELECT
id, customer_id, achievement_name, pre_value, target_value, achievement_type
FROM resi_group_achievement_config
WHERE
ACHIEVEMENT_TYPE = #{achievementType}
AND DEL_FLAG = '0'
order by TARGET_VALUE DESC
LIMIT 1
</select>
</mapper>

63
epmet-module/resi-group/resi-group-server/src/main/resources/mapper/group/ResiGroupAchievementStatsDao.xml

@ -35,6 +35,67 @@
CURRENT_VALUE / TARGET_VALUE ASC
LIMIT 3
</select>
<select id="selectLastUnAchieved" resultMap="resiGroupAchievementStatsMap">
SELECT
ID, CUSTOMER_ID, GROUP_ID, ACHIEVEMENT_ID, ACHIEVEMENT_NAME, ACHIEVEMENT_TYPE, ARRIVE_TIME, CURRENT_VALUE, TARGET_VALUE, IS_ARRIVE
FROM
resi_group_achievement_stats
WHERE DEL_FLAG = '0'
AND GROUP_ID = #{groupId}
AND CUSTOMER_ID = #{customerId}
AND ACHIEVEMENT_TYPE = #{achievementType}
AND IS_ARRIVE = 0
</select>
<insert id="saveOrUpdate">
INSERT INTO resi_group_achievement_stats
(
ID,
CUSTOMER_ID,
GROUP_ID,
ACHIEVEMENT_ID,
ACHIEVEMENT_NAME,
ACHIEVEMENT_TYPE,
ARRIVE_TIME,
CURRENT_VALUE,
TARGET_VALUE,
IS_ARRIVE,
DEL_FLAG,
REVISION,
CREATED_BY,
CREATED_TIME,
UPDATED_BY,
UPDATED_TIME
)
VALUES
<foreach collection="list" item="item" separator=",">
(
#{item.id},
#{item.customerId},
#{item.groupId},
#{item.achievementId},
#{item.achievementName},
#{item.achievementType},
#{item.arriveTime},
#{item.currentValue},
#{item.targetValue},
#{item.isArrive},
#{item.delFlag},
#{item.revision},
#{item.createdBy},
#{item.createdTime},
#{item.updatedBy},
#{item.updatedTime}
)
</foreach>
ON DUPLICATE KEY UPDATE
<if test="updateAll">
CURRENT_VALUE = values(CURRENT_VALUE),
TARGET_VALUE = values(TARGET_VALUE),
IS_ARRIVE = VALUES(IS_ARRIVE),
UPDATED_TIME = VALUES(UPDATED_TIME),
</if>
UPDATED_BY = VALUES(UPDATED_BY)
</insert>
</mapper>
</mapper>

12
epmet-module/resi-group/resi-group-server/src/main/resources/mapper/member/ResiGroupMemberDao.xml

@ -191,6 +191,18 @@
ORDER BY
rgm.CREATED_TIME DESC
</select>
<select id="countMembers" resultType="int">
SELECT
count(*)
FROM
resi_group_member rgm
WHERE
rgm.RESI_GROUP_ID = #{groupId}
AND rgm.CUSTOMER_ID = #{customerId}
and rgm.STATUS = 'approved'
AND rgm.GROUP_LEADER_FLAG = 'member'
</select>
<select id="getMemberList" resultType="com.epmet.resi.group.dto.member.ResiGroupMemberDTO">
SELECT

31
epmet-module/resi-group/resi-group-server/src/test/com/epmet/modules/group/service/impl/StatsAchievementServiceImplTest.java

@ -0,0 +1,31 @@
package com.epmet.modules.group.service.impl;
import com.epmet.modules.group.service.StatsAchievementService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class StatsAchievementServiceImplTest {
@Autowired
private StatsAchievementService statsAchievementService;
@Test
public void calculateAcm() {
// String customerId = "test_cid";
// String groupId = "test_groupId";
// String achievementType = "member";
// Boolean aBoolean = statsAchievementService.calculateAcm(customerId, groupId, achievementType);
// System.out.println(aBoolean);
String customerId = "test_cid";
String groupId = "test_groupId";
String achievementType = "toissue";
Boolean aBoolean = statsAchievementService.calculateAcm(customerId, groupId, achievementType);
System.out.println(aBoolean);
}
}
Loading…
Cancel
Save