diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/UniqueIdGenerator.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/UniqueIdGenerator.java index fcefbdf2ca..a1c19557d1 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/UniqueIdGenerator.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/UniqueIdGenerator.java @@ -11,6 +11,8 @@ import java.util.concurrent.atomic.AtomicLong; * 唯一ID生成器 */ public class UniqueIdGenerator { + public final static String FORMAT_DMDHS = "yyyyMMddHHmmss"; + private static UniqueValue uniqueValue = new UniqueValue(); private static String middle; @@ -25,7 +27,7 @@ public class UniqueIdGenerator { private static class UniqueValue { private AtomicLong uniqueValue = new AtomicLong(0L); - private volatile String currentTime = DateUtils.format(new Date(), DateUtils.DATE_TIME_NO_SPLIT); + private volatile String currentTime = DateUtils.format(new Date(), FORMAT_DMDHS); private volatile String lastTime = currentTime; /** @@ -35,7 +37,7 @@ public class UniqueIdGenerator { * @return */ public String getCurrentTime() { - currentTime = DateUtils.format(new Date(), DateUtils.DATE_TIME_NO_SPLIT); + currentTime = DateUtils.format(new Date(), FORMAT_DMDHS); if (!currentTime.equals(lastTime)) { lastTime = currentTime; Random random = new Random(); @@ -51,31 +53,32 @@ public class UniqueIdGenerator { /** * 生成一个24位唯一ID - * 15位时间+2位中间值(防止多服务冲突)+2个线程code+5位秒级递增值 + * 14位时间+2位中间值(防止多服务冲突)+3个线程code+5位秒级递增值 * * @return */ - public static String generate() { + public static String generate24() { StringBuilder builder = new StringBuilder(32); builder.append(uniqueValue.getCurrentTime()) .append(middle) - .append(getUniqueThreadCode()) + .append(getUniqueThreadCode(3)) .append(uniqueValue.getCurrentValue()); return builder.toString(); } - public static String getUniqueThreadCode() { - String threadCode = StringUtils.left(String.valueOf(Thread.currentThread().hashCode()), 2); - return StringUtils.leftPad(threadCode, 2, "0"); + public static String getUniqueThreadCode(Integer length) { + String threadCode = StringUtils.left(String.valueOf(Thread.currentThread().hashCode()), length); + return StringUtils.leftPad(threadCode, length, "0"); } public static void main(String[] args) throws InterruptedException { System.out.println(UniqueIdGenerator.uniqueValue.currentTime); System.out.println(UniqueIdGenerator.middle); - System.out.println(UniqueIdGenerator.getUniqueThreadCode()); + System.out.println(UniqueIdGenerator.getUniqueThreadCode(2)); System.out.println(uniqueValue.getCurrentValue()); + System.out.println(UniqueIdGenerator.generate24()); } } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/IndexExcelDataListener.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/IndexExcelDataListener.java index 9870714357..3fe392276f 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/IndexExcelDataListener.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/IndexExcelDataListener.java @@ -157,7 +157,7 @@ public class IndexExcelDataListener extends AnalysisEventListener { group1 = new IndexGroupTemplateEntity(); group1.setIndexId(indexDictEntity.getId()); group1.setParentIndexGroupId("0"); - group1.setId(UniqueIdGenerator.generate()); + group1.setId(UniqueIdGenerator.generate24()); group1.setIndexCode(Pinyin4jUtil.getSpellPinYin(indexDictEntity.getIndexName(), true, 4)); group1.setAllIndexCodePath(index.getAllIndexCodePath(0)); indexGroupMap.put(index.getLevel1Index(), group1); @@ -173,7 +173,7 @@ public class IndexExcelDataListener extends AnalysisEventListener { group2 = new IndexGroupTemplateEntity(); group2.setIndexId(indexDictEntity.getId()); group2.setParentIndexGroupId(group1.getId()); - group2.setId(UniqueIdGenerator.generate()); + group2.setId(UniqueIdGenerator.generate24()); group2.setIndexCode(Pinyin4jUtil.getSpellPinYin(indexDictEntity.getIndexName(), false, 4)); group2.setAllIndexCodePath(index.getAllIndexCodePath(3)); indexGroupMap.put(level4IndexDetailKey, group2); @@ -184,7 +184,7 @@ public class IndexExcelDataListener extends AnalysisEventListener { templateEntity.setIndexGroupId(group1.getId()); templateEntity.setIndexId(indexDictEntity.getId()); templateEntity.setAllParentIndexCode(allIndexCodeSb.toString()); - templateEntity.setId(UniqueIdGenerator.generate()); + templateEntity.setId(UniqueIdGenerator.generate24()); templateEntity.setCorrelation(index.getCorrelation()); templateEntity.setAllIndexCodePath(index.getAllIndexCodePath(3)); buildIndexGroupDetail(templateEntity, indexDictEntity, index, 2); @@ -202,7 +202,7 @@ public class IndexExcelDataListener extends AnalysisEventListener { templateEntity.setIndexGroupId(group2.getId()); templateEntity.setIndexId(indexDictEntity.getId()); templateEntity.setAllParentIndexCode(allIndexCodeSb.toString()); - templateEntity.setId(UniqueIdGenerator.generate()); + templateEntity.setId(UniqueIdGenerator.generate24()); templateEntity.setCorrelation(index.getCorrelation()); templateEntity.setAllIndexCodePath(index.getAllIndexCodePath(4)); buildIndexGroupDetail(templateEntity, indexDictEntity, index, 5); @@ -217,7 +217,7 @@ public class IndexExcelDataListener extends AnalysisEventListener { group1 = new IndexGroupTemplateEntity(); group1.setIndexId(indexDictEntity.getId()); group1.setParentIndexGroupId("0"); - group1.setId(UniqueIdGenerator.generate()); + group1.setId(UniqueIdGenerator.generate24()); group1.setIndexCode(Pinyin4jUtil.getSpellPinYin(indexDictEntity.getIndexName(), false, 4)); group1.setAllIndexCodePath(index.getAllIndexCodePath(0)); indexGroupMap.put(index.getLevel1Index(), group1); @@ -232,7 +232,7 @@ public class IndexExcelDataListener extends AnalysisEventListener { group2 = new IndexGroupTemplateEntity(); group2.setIndexId(indexDictEntity.getId()); group2.setParentIndexGroupId(group1.getId()); - group2.setId(UniqueIdGenerator.generate()); + group2.setId(UniqueIdGenerator.generate24()); group2.setIndexCode(Pinyin4jUtil.getSpellPinYin(indexDictEntity.getIndexName(), false, 4)); group2.setAllIndexCodePath(index.getAllIndexCodePath(1)); indexGroupMap.put(level2IndexGroupKey, group2); @@ -243,7 +243,7 @@ public class IndexExcelDataListener extends AnalysisEventListener { templateEntity.setIndexGroupId(group2.getId()); templateEntity.setIndexId(indexDictEntity.getId()); templateEntity.setAllParentIndexCode(allIndexCodeSb.toString()); - templateEntity.setId(UniqueIdGenerator.generate()); + templateEntity.setId(UniqueIdGenerator.generate24()); templateEntity.setCorrelation(index.getCorrelation()); templateEntity.setAllIndexCodePath(index.getAllIndexCodePath(1)); buildIndexGroupDetail(templateEntity, indexDictEntity, index, 2); @@ -260,7 +260,7 @@ public class IndexExcelDataListener extends AnalysisEventListener { templateEntity.setIndexGroupId(group2.getId()); templateEntity.setIndexId(indexDictEntity.getId()); templateEntity.setAllParentIndexCode(allIndexCodeSb.toString()); - templateEntity.setId(UniqueIdGenerator.generate()); + templateEntity.setId(UniqueIdGenerator.generate24()); templateEntity.setCorrelation(index.getCorrelation()); templateEntity.setAllIndexCodePath(index.getAllIndexCodePath(4)); buildIndexGroupDetail(templateEntity, indexDictEntity, index, 5); @@ -289,7 +289,7 @@ public class IndexExcelDataListener extends AnalysisEventListener { private void buildIndexDicEntity(IndexModel data, IndexDictEntity entity, IndexDictEntity entity2, IndexDictEntity entity3, IndexDictEntity entity4, IndexDictEntity entity5) { if (!indexDicMap.containsKey(data.getLevel1Index())) { - entity.setId(UniqueIdGenerator.generate()); + entity.setId(UniqueIdGenerator.generate24()); entity.setIndexName(data.getLevel1Index()); entity.setCorrelation(data.getCorrelation()); entity.setLevel("1"); @@ -297,7 +297,7 @@ public class IndexExcelDataListener extends AnalysisEventListener { indexDicMap.put(data.getLevel1Index(), entity); } if (!indexDicMap.containsKey(data.getLevel2Index())) { - entity2.setId(UniqueIdGenerator.generate()); + entity2.setId(UniqueIdGenerator.generate24()); entity2.setIndexName(data.getLevel2Index()); entity2.setCorrelation(data.getCorrelation()); entity2.setLevel("2"); @@ -305,7 +305,7 @@ public class IndexExcelDataListener extends AnalysisEventListener { indexDicMap.put(data.getLevel2Index(), entity2); } if (!indexDicMap.containsKey(data.getLevel3Index())) { - entity3.setId(UniqueIdGenerator.generate()); + entity3.setId(UniqueIdGenerator.generate24()); entity3.setIndexName(data.getLevel3Index()); entity3.setCorrelation(data.getCorrelation()); entity3.setLevel("3"); @@ -313,7 +313,7 @@ public class IndexExcelDataListener extends AnalysisEventListener { indexDicMap.put(data.getLevel3Index(), entity3); } if (!indexDicMap.containsKey(data.getLevel4Index())) { - entity4.setId(UniqueIdGenerator.generate()); + entity4.setId(UniqueIdGenerator.generate24()); entity4.setIndexName(data.getLevel4Index()); entity4.setCorrelation(data.getCorrelation()); entity4.setLevel("4"); @@ -321,7 +321,7 @@ public class IndexExcelDataListener extends AnalysisEventListener { indexDicMap.put(data.getLevel4Index(), entity4); } if (!indexDicMap.containsKey(data.getLevel5Index())) { - entity5.setId(UniqueIdGenerator.generate()); + entity5.setId(UniqueIdGenerator.generate24()); entity5.setIndexName(data.getLevel5Index()); entity5.setCorrelation(data.getCorrelation()); entity5.setLevel("5"); diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/IndexGroupServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/IndexGroupServiceImpl.java index 50092d64db..00c019e1ff 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/IndexGroupServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/IndexGroupServiceImpl.java @@ -80,7 +80,7 @@ private IndexGroupTemplateDao indexGroupTemplateDao; List insertGroupList = new ArrayList<>(); groupMap.forEach((oldGroupTempId, o) -> { IndexGroupEntity newGroupEntity = ConvertUtils.sourceToTarget(o, IndexGroupEntity.class); - String newGroupId = UniqueIdGenerator.generate(); + String newGroupId = UniqueIdGenerator.generate24(); newGroupEntity.setId(newGroupId); newGroupEntity.setCustomerId(customerId); groupNewIdMap.put(oldGroupTempId, newGroupId); @@ -99,7 +99,7 @@ private IndexGroupTemplateDao indexGroupTemplateDao; IndexGroupDetailEntity entity = ConvertUtils.sourceToTarget(groupDetailTemp, IndexGroupDetailEntity.class); - entity.setId(UniqueIdGenerator.generate()); + entity.setId(UniqueIdGenerator.generate24()); String newGroupId = groupNewIdMap.get(oldIndexGroupId); if (StringUtils.isBlank(newGroupId)){ log.error("新旧id映射关系有误"); @@ -134,4 +134,4 @@ private IndexGroupTemplateDao indexGroupTemplateDao; });*/ return true; } -} \ No newline at end of file +} diff --git a/epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/send/SendMqMsgUtil.java b/epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/send/SendMqMsgUtil.java index 13fcfa4367..1880cb8bac 100644 --- a/epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/send/SendMqMsgUtil.java +++ b/epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/send/SendMqMsgUtil.java @@ -50,7 +50,7 @@ public class SendMqMsgUtil { systemMsgFormDTO.setMessageType(SystemMessageType.GROUP_ACHIEVEMENT); systemMsgFormDTO.setContent(msgContent); Result sendMsgResult = null; - int retryTime = 1; + int retryTime = 0; do { sendMsgResult = epmetMessageOpenFeignClient.sendSystemMsgByMQ(systemMsgFormDTO); } while ((sendMsgResult == null || !sendMsgResult.success()) && retryTime++ < NumConstant.TWO); diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/AbstractStatsAchievementService.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/AbstractStatsAchievementService.java index 03e6dbcb07..ff77d49289 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/AbstractStatsAchievementService.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/AbstractStatsAchievementService.java @@ -21,6 +21,7 @@ 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.commons.tools.utils.UniqueIdGenerator; import com.epmet.modules.enums.AchievementTypeEnum; import com.epmet.modules.group.entity.ResiGroupAchievementConfigEntity; import com.epmet.modules.group.entity.ResiGroupAchievementStatsEntity; @@ -83,6 +84,8 @@ public abstract class AbstractStatsAchievementService { for (int i = 0; i < 5; i++) { nextTargetValue = GroupAchievementUtils.getNextTargetValue(achievementType, preValue); ResiGroupAchievementConfigEntity next = new ResiGroupAchievementConfigEntity(); + //生成ID 自增 + next.setId(UniqueIdGenerator.generate24()); next.setCustomerId(lastOne.getCustomerId()); next.setAchievementName(oldName.replace(StrConstant.UNDER_LINE, String.valueOf(nextTargetValue))); preValue = nextTargetValue; diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/ResiGroupServiceImpl.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/ResiGroupServiceImpl.java index 2751959bd9..c4bcd63e3c 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/ResiGroupServiceImpl.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/ResiGroupServiceImpl.java @@ -686,11 +686,20 @@ public class ResiGroupServiceImpl extends BaseServiceImpl queryWrapper = new QueryWrapper<>(); - queryWrapper.lambda().eq(ResiGroupEntity::getDelFlag,'0'); - if (StringUtils.isNotBlank(customerId)){ - queryWrapper.lambda().eq(ResiGroupEntity::getCustomerId,customerId); - } - List groupEntities = resiGroupDao.selectList(queryWrapper); - groupEntities.forEach(group->{ - AchievementTypeEnum[] achievementTypeEnum = AchievementTypeEnum.values(); - for (AchievementTypeEnum anEnum : achievementTypeEnum) { - try { - Thread.sleep(2); - } catch (InterruptedException e) { - e.printStackTrace(); - } - calculateAcm(group.getCustomerId(),group.getId(),anEnum.getCode()); + //计算所有类型的 小组人数、话题数、转议题数、小组内问题解决数 + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(ResiGroupEntity::getDelFlag, '0'); + if (StringUtils.isNotBlank(customerId)) { + queryWrapper.lambda().eq(ResiGroupEntity::getCustomerId, customerId); + } + List groupEntities = resiGroupDao.selectList(queryWrapper); + groupEntities.forEach(group -> { + AchievementTypeEnum[] achievementTypeEnum = AchievementTypeEnum.values(); + for (AchievementTypeEnum anEnum : achievementTypeEnum) { + try { + Thread.sleep(2); + } catch (InterruptedException e) { + e.printStackTrace(); } - }); + calculateAcm(group.getCustomerId(), group.getId(), anEnum.getCode()); + } + }); return true; } diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/member/service/impl/ResiGroupMemberServiceImpl.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/member/service/impl/ResiGroupMemberServiceImpl.java index 746ff0dfb1..faeb200339 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/member/service/impl/ResiGroupMemberServiceImpl.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/member/service/impl/ResiGroupMemberServiceImpl.java @@ -86,6 +86,8 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.support.TransactionSynchronizationAdapter; +import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.CollectionUtils; import java.text.DateFormat; @@ -691,11 +693,20 @@ public class ResiGroupMemberServiceImpl extends BaseServiceImpl msgList = new ArrayList<>(); msgList.add(wxSubscribeMessageFormDTO); epmetMessageOpenFeignClient.sendWxSubscribeMessage(msgList); - //发送小组成就消息 - boolean flag = SendMqMsgUtil.build().openFeignClient(epmetMessageOpenFeignClient).sendGroupAchievementMqMsg(new GroupAchievementMQMsg(resiGroupMemberDTO.getCustomerId(), resiGroupMemberDTO.getResiGroupId(), AchievementTypeEnum.MEMBER.getCode())); - if (!flag) { - logger.error("发送(小组成就)系统消息到message服务失败"); - } + TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() { + @Override + public void afterCommit() { + try { + //发送小组成就消息 + boolean flag = SendMqMsgUtil.build().openFeignClient(epmetMessageOpenFeignClient).sendGroupAchievementMqMsg(new GroupAchievementMQMsg(resiGroupMemberDTO.getCustomerId(), resiGroupMemberDTO.getResiGroupId(), AchievementTypeEnum.MEMBER.getCode())); + if (!flag) { + logger.error("发送(小组成就)系统消息到message服务失败"); + } + }catch (Exception e){ + logger.error("afterCommit",e); + } + } + }); } /** diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/topic/service/impl/ResiTopicServiceImpl.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/topic/service/impl/ResiTopicServiceImpl.java index 87c8afe53c..8a67b7d7e7 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/topic/service/impl/ResiTopicServiceImpl.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/topic/service/impl/ResiTopicServiceImpl.java @@ -116,6 +116,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.support.TransactionSynchronizationAdapter; +import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.CollectionUtils; import javax.validation.constraints.NotBlank; @@ -805,10 +807,19 @@ public class ResiTopicServiceImpl extends BaseServiceImpl