Browse Source

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

master
jianjun 4 years ago
parent
commit
e8466901a3
  1. 1
      epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/constant/TopicConstant.java
  2. 6
      epmet-module/resi-group/resi-group-server/pom.xml
  3. 194
      epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/StatsAchievementServiceImpl.java
  4. 1
      epmet-module/resi-group/resi-group-server/src/main/resources/mapper/group/ResiGroupAchievementStatsDao.xml

1
epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/constant/TopicConstant.java

@ -119,4 +119,5 @@ public interface TopicConstant {
String FIELD_TOPIC_ATTACHMENT_TYPE = "ATTACHMENT_TYPE";
String RESOLVED = "resolved";
String MEMBER = "member";
}

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

@ -118,6 +118,12 @@
<artifactId>epmet-commons-rocketmq</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.epmet</groupId>
<artifactId>oper-crm-client</artifactId>
<version>2.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>

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

@ -4,6 +4,9 @@ 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.commons.tools.utils.Result;
import com.epmet.dto.CustomerDTO;
import com.epmet.feign.OperCrmOpenFeignClient;
import com.epmet.modules.enums.AchievementTypeEnum;
import com.epmet.modules.group.dao.ResiGroupDao;
import com.epmet.modules.group.entity.ResiGroupAchievementConfigEntity;
@ -12,6 +15,7 @@ import com.epmet.modules.group.entity.ResiGroupEntity;
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.member.entity.ResiGroupMemberEntity;
import com.epmet.modules.topic.dao.ResiTopicDao;
import com.epmet.modules.topic.entity.ResiTopicEntity;
import com.epmet.resi.group.constant.TopicConstant;
@ -25,6 +29,7 @@ import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* desc:
@ -42,6 +47,8 @@ public class StatsAchievementServiceImpl extends AbstractStatsAchievementService
private ResiTopicDao resiTopicDao;
@Autowired
private ResiGroupDao resiGroupDao;
@Autowired
private OperCrmOpenFeignClient operCrmOpenFeignClient;
/**
@ -52,30 +59,84 @@ public class StatsAchievementServiceImpl extends AbstractStatsAchievementService
* @date 2021/4/20
*/
@Override
public Boolean initAllGroupAchievement(String customerId) {
public Boolean initAllGroupAchievement(String cId) {
//计算所有类型的 小组人数、话题数、转议题数、小组内问题解决数
QueryWrapper<ResiGroupEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(ResiGroupEntity::getDelFlag, '0');
if (StringUtils.isNotBlank(customerId)) {
queryWrapper.lambda().eq(ResiGroupEntity::getCustomerId, customerId);
//1。获取客户
List<String> customerIdList = getCustomerIds(cId);
if (CollectionUtils.isEmpty(customerIdList)) {
throw new RenException("没有需要初始化的客户数据");
}
List<ResiGroupEntity> groupEntities = resiGroupDao.selectList(queryWrapper);
groupEntities.forEach(group -> {
AchievementTypeEnum[] achievementTypeEnum = AchievementTypeEnum.values();
for (AchievementTypeEnum anEnum : achievementTypeEnum) {
try {
Thread.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
for (String customerId : customerIdList) {
//2。获取小组数据
List<ResiGroupEntity> groupEntities = getCustomerGroupList(customerId);
if (CollectionUtils.isEmpty(groupEntities)) {
log.warn("没有需要初始化的小组数据,customerId:{}", customerId);
continue;
}
for (ResiGroupEntity groupEntity : groupEntities) {
//2.1 获取小组成员数据
String groupId = groupEntity.getId();
List<ResiGroupMemberEntity> groupMemberList = getGroupMemberList(customerId, groupId);
if (CollectionUtils.isEmpty(groupMemberList)) {
log.warn("没有需要初始化的小组成员数据,customerId:{},groupId:{}", customerId, groupId);
//初始化小组的前4个成就
calculateGroupAchievement(customerId, groupId, NumConstant.ZERO, AchievementTypeEnum.MEMBER.getCode());
} else {
//2.2 计算出 组成员 达到的成就
List<ResiGroupAchievementStatsEntity> memberArriveList = new ArrayList<>();
buildAchievementEntityList(customerId, groupId, AchievementTypeEnum.MEMBER.getCode(), groupMemberList.size(), null, memberArriveList);
//设置实际达到成就时间 最后一条为未实现 所以-1
for (int j = 0; j < memberArriveList.size() - 1; j++) {
memberArriveList.get(j).setArriveTime(groupEntities.get(j).getCreatedTime());
}
saveOrUpdate(memberArriveList, true);
}
//2.3 获取小组话题数据
List<ResiTopicEntity> groupTopicList = getGroupTopicList(customerId, groupId);
if (CollectionUtils.isEmpty(groupTopicList)) {
log.warn("没有需要初始化的小组话题数据,customerId:{},groupId:{}", customerId, groupId);
continue;
}
calculateAcm(group.getCustomerId(), group.getId(), anEnum.getCode());
//2.4 计算出 话题 达到的成就
List<ResiGroupAchievementStatsEntity> topicArriveList = new ArrayList<>();
buildAchievementEntityList(customerId, groupId, AchievementTypeEnum.TOPIC.getCode(), groupTopicList.size(), null, topicArriveList);
//设置实际达到成就时间 最后一条为未实现 所以-1
for (int j = 0; j < topicArriveList.size() - 1; j++) {
topicArriveList.get(j).setArriveTime(groupTopicList.get(j).getCreatedTime());
}
//2.5 计算出 转议题 达到的成就
List<ResiTopicEntity> toIssueTopicList = groupTopicList.stream().filter(ResiTopicEntity::getShiftIssue).collect(Collectors.toList());
List<ResiGroupAchievementStatsEntity> toIssueArriveList = new ArrayList<>();
buildAchievementEntityList(customerId, groupId, AchievementTypeEnum.TOISSUE.getCode(), toIssueTopicList.size(), null, toIssueArriveList);
//设置实际达到成就时间 最后一条为未实现 所以-1
for (int j = 0; j < toIssueArriveList.size() - 1; j++) {
toIssueArriveList.get(j).setArriveTime(toIssueTopicList.get(j).getCreatedTime());
}
//2.6 计算出 话题被解决 达到的成就
List<ResiTopicEntity> resolveTopicList = groupTopicList.stream()
.filter(o -> TopicConstant.CLOSED.equals(o.getStatus()) && TopicConstant.RESOLVED.equals(o.getClosedStatus())).collect(Collectors.toList());
List<ResiGroupAchievementStatsEntity> resolveTopicArriveList = new ArrayList<>();
buildAchievementEntityList(customerId, groupId, AchievementTypeEnum.RESOVLE_TOPIC.getCode(), resolveTopicList.size(), null, resolveTopicArriveList);
//设置实际达到成就时间 最后一条为未实现 所以-1
for (int j = 0; j < resolveTopicArriveList.size() - 1; j++) {
resolveTopicArriveList.get(j).setArriveTime(resolveTopicList.get(j).getCreatedTime());
}
saveOrUpdate(topicArriveList, true);
saveOrUpdate(toIssueArriveList, true);
saveOrUpdate(resolveTopicArriveList, true);
}
});
}
return true;
}
/**
* desc: 根据小组Id计算小组成就 入口
*
@ -99,7 +160,7 @@ public class StatsAchievementServiceImpl extends AbstractStatsAchievementService
QueryWrapper<ResiTopicEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(ResiTopicEntity::getCustomerId, customerId)
.eq(ResiTopicEntity::getGroupId, groupId)
.eq(ResiTopicEntity::getDelFlag, NumConstant.ZERO);
.eq(ResiTopicEntity::getDelFlag, NumConstant.ZERO_STR);
currentValue = resiTopicDao.selectCount(queryWrapper);
break;
case MEMBER:
@ -111,7 +172,7 @@ public class StatsAchievementServiceImpl extends AbstractStatsAchievementService
queryWrapper.lambda().eq(ResiTopicEntity::getCustomerId, customerId)
.eq(ResiTopicEntity::getGroupId, groupId)
.eq(ResiTopicEntity::getShiftIssue, NumConstant.ONE)
.eq(ResiTopicEntity::getDelFlag, NumConstant.ZERO);
.eq(ResiTopicEntity::getDelFlag, NumConstant.ZERO_STR);
currentValue = resiTopicDao.selectCount(queryWrapper);
break;
case RESOVLE_TOPIC:
@ -122,7 +183,7 @@ public class StatsAchievementServiceImpl extends AbstractStatsAchievementService
.eq(ResiTopicEntity::getStatus, TopicConstant.CLOSED)
.eq(ResiTopicEntity::getClosedStatus, TopicConstant.RESOLVED)
.eq(ResiTopicEntity::getShiftIssue, NumConstant.ONE)
.eq(ResiTopicEntity::getDelFlag, NumConstant.ZERO);
.eq(ResiTopicEntity::getDelFlag, NumConstant.ZERO_STR);
currentValue = resiTopicDao.selectCount(queryWrapper);
break;
default:
@ -165,14 +226,15 @@ public class StatsAchievementServiceImpl extends AbstractStatsAchievementService
//改为已实现
if (currentValue >= targetValue) {
isBatch = true;
buildAchievementEntityList(customerId, groupId, achievementType, currentValue, one.getTargetValue(), haveArrive);
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);
// 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) {
@ -195,6 +257,14 @@ public class StatsAchievementServiceImpl extends AbstractStatsAchievementService
*/
private void initAchievementStat(String customerId, String groupId, String achievementType, int currentValue, List<ResiGroupAchievementStatsEntity> haveArrive) {
buildAchievementEntityList(customerId, groupId, achievementType, currentValue, null, haveArrive);
if (CollectionUtils.isEmpty(haveArrive)) {
throw new RenException("小组达成成就失败");
}
}
private void buildAchievementEntityList(String customerId, String groupId, String achievementType,
Integer currentValue, Integer targetValue, List<ResiGroupAchievementStatsEntity> haveArrive) {
boolean isContinue;
int pageNum = NumConstant.ONE;
int pageSize = NumConstant.TEN;
@ -205,11 +275,8 @@ public class StatsAchievementServiceImpl extends AbstractStatsAchievementService
log.error("calculateMember get config fail");
throw new RenException(EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getCode());
}
isContinue = buildArriveList(customerId, groupId, achievementType, currentValue, null, haveArrive, list);
isContinue = buildArriveList(customerId, groupId, achievementType, currentValue, targetValue, haveArrive, list);
} while (isContinue);
if (CollectionUtils.isEmpty(haveArrive)) {
throw new RenException("小组达成成就失败");
}
}
private boolean buildArriveList(String customerId, String groupId, String achievementType, int currentValue, Integer targetValue,
@ -257,4 +324,71 @@ public class StatsAchievementServiceImpl extends AbstractStatsAchievementService
}
return list;
}
/**
* desc:获取小组List 按创建时间升序
*
* @param customerId
* @return
*/
private List<ResiGroupEntity> getCustomerGroupList(String customerId) {
QueryWrapper<ResiGroupEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda()
.eq(ResiGroupEntity::getDelFlag, NumConstant.ZERO_STR)
.eq(ResiGroupEntity::getCustomerId, customerId)
.orderByAsc(ResiGroupEntity::getCreatedTime);
return resiGroupDao.selectList(queryWrapper);
}
/**
* desc:获取小组成员(非组长)List 按创建时间升序
*
* @param customerId
* @return
*/
private List<ResiGroupMemberEntity> getGroupMemberList(String customerId, String groupId) {
QueryWrapper<ResiGroupMemberEntity> memberQuery = new QueryWrapper<>();
memberQuery.lambda()
.eq(ResiGroupMemberEntity::getCustomerId, customerId)
.eq(ResiGroupMemberEntity::getResiGroupId, groupId)
.eq(ResiGroupMemberEntity::getDelFlag, NumConstant.ZERO_STR)
.eq(ResiGroupMemberEntity::getGroupLeaderFlag, TopicConstant.MEMBER)
.orderByAsc(ResiGroupMemberEntity::getCreatedTime);
return resiGroupMemberDao.selectList(memberQuery);
}
/**
* desc:获取小组话题List 按创建时间升序
*
* @param customerId
* @return
*/
private List<ResiTopicEntity> getGroupTopicList(String customerId, String groupId) {
QueryWrapper<ResiTopicEntity> memberQuery = new QueryWrapper<>();
memberQuery.lambda()
.eq(ResiTopicEntity::getCustomerId, customerId)
.eq(ResiTopicEntity::getGroupId, groupId)
.eq(ResiTopicEntity::getDelFlag, NumConstant.ZERO_STR)
.orderByAsc(ResiTopicEntity::getCreatedTime);
return resiTopicDao.selectList(memberQuery);
}
/**
* desc:获取客户IdList
*
* @param customerId
* @return
*/
private List<String> getCustomerIds(String customerId) {
List<String> customerIdList = new ArrayList<>();
if (StringUtils.isBlank(customerId)) {
Result<List<CustomerDTO>> allCustomerList = operCrmOpenFeignClient.getAllCustomerList();
if (allCustomerList != null && !CollectionUtils.isEmpty(allCustomerList.getData())) {
customerIdList.addAll(allCustomerList.getData().stream().map(CustomerDTO::getId).collect(Collectors.toList()));
}
} else {
customerIdList.add(customerId);
}
return customerIdList;
}
}

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

@ -92,6 +92,7 @@
<if test="updateAll">
CURRENT_VALUE = values(CURRENT_VALUE),
TARGET_VALUE = values(TARGET_VALUE),
ARRIVE_TIME = if(IS_ARRIVE,ARRIVE_TIME,values(ARRIVE_TIME)),
IS_ARRIVE = VALUES(IS_ARRIVE),
UPDATED_TIME = VALUES(UPDATED_TIME),
</if>

Loading…
Cancel
Save