Browse Source

Merge remote-tracking branch 'origin/dev'

master
zxc 3 years ago
parent
commit
e0934e91ce
  1. 27
      epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/config/MybatisPlusConfig.java
  2. 2
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenProjectDataServiceImpl.java
  3. 2
      epmet-module/data-statistical/data-statistical-server/src/main/resources/bootstrap.yml
  4. 9
      epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/mq/listener/OpenDataPatrolChangeEventListener.java
  5. 2
      epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/BaseDisputeProcessServiceImpl.java
  6. 13
      epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/UserPatrolRecordServiceImpl.java
  7. 3
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserBadgeServiceImpl.java
  8. 214
      epmet-user/epmet-user-server/src/main/java/com/epmet/util/MySequence.java
  9. 3
      epmet-user/epmet-user-server/src/main/resources/bootstrap.yml
  10. 17
      epmet-user/epmet-user-server/src/test/java/com/epmet/epmetuser/test/UserControllerTest.java

27
epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/config/MybatisPlusConfig.java

@ -1,29 +1,38 @@
/**
* Copyright (c) 2018 人人开源 All rights reserved.
*
* <p>
* https://www.renren.io
*
* <p>
* 版权所有侵权必究
*/
package com.epmet.commons.mybatis.config;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.epmet.commons.mybatis.interceptor.DataFilterInterceptor;
import com.epmet.commons.tools.redis.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import java.util.Random;
/**
* mybatis-plus配置
*
* @author Mark sunlightcs@gmail.com
* @since 1.0.0
*/
@Slf4j
@Configuration
public class MybatisPlusConfig {
@Autowired
private RedisUtils redisUtils;
/**
* 配置数据权限
@ -45,4 +54,18 @@ public class MybatisPlusConfig {
return interceptor;
}
/**
* id生成器指定2个参数 防止id重复
*/
@Bean
@Order(0)
public DefaultIdentifierGenerator myIdentifierGenerator() {
Random random = new Random();
int workerId = random.nextInt(30) + 1;
int dataCenterId = random.nextInt(30) + 1;
DefaultIdentifierGenerator interceptor = new DefaultIdentifierGenerator(workerId, dataCenterId);
log.info("workerId:{},dataCenterId:{}", workerId, dataCenterId);
return interceptor;
}
}

2
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenProjectDataServiceImpl.java

@ -306,7 +306,7 @@ public class ScreenProjectDataServiceImpl extends BaseServiceImpl<ScreenProjectD
*/
@Override
public List<ScreenProjectDataDTO> getProjectList(String customerId, List<String> projectId, Integer pageNo, Integer pageSize) {
PageHelper.startPage(pageNo, pageSize);
PageHelper.startPage(pageNo, pageSize, false);
return baseDao.selectProjectList(customerId, projectId);
}

2
epmet-module/data-statistical/data-statistical-server/src/main/resources/bootstrap.yml

@ -28,6 +28,7 @@ spring:
url: @datasource.druid.stats.url@
username: @datasource.druid.stats.username@
password: @datasource.druid.stats.password@
max-active: 100
cloud:
nacos:
discovery:
@ -173,6 +174,7 @@ dynamic:
url: @datasource.druid.evaluationIndex.url@
username: @datasource.druid.evaluationIndex.username@
password: @datasource.druid.evaluationIndex.password@
max-active: 100
partyMember:
driver-class-name: com.mysql.cj.jdbc.Driver
url: @datasource.druid.partyMember.url@

9
epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/mq/listener/OpenDataPatrolChangeEventListener.java

@ -6,6 +6,8 @@ import com.epmet.commons.rocketmq.messages.StaffPatrolMQMsg;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.distributedlock.DistributedLock;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.EpmetException;
import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.redis.RedisKeys;
@ -77,10 +79,6 @@ public class OpenDataPatrolChangeEventListener implements MessageListenerConcurr
if (!StrConstant.PY_CUSTOMER.equals(msgObj.getCustomerId())) {
return;
}
if (msgObj == null) {
log.warn("consumeMessage msg body is blank");
return;
}
RLock lock = null;
try {
lock = distributedLock.getLock(String.format("lock:open_data_patrol:%s:%s",tags, msgObj.getObjectId()),
@ -104,6 +102,9 @@ public class OpenDataPatrolChangeEventListener implements MessageListenerConcurr
log.error("错误的消息类型:{}", tags);
}
if (aBoolean == null || !aBoolean){
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"消费失败!");
}
} catch (RenException e) {
// 如果是我们手动抛出的异常,说明在业务可控范围内。目前不需要MQ重试

2
epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/BaseDisputeProcessServiceImpl.java

@ -72,8 +72,10 @@ public class BaseDisputeProcessServiceImpl extends BaseServiceImpl<BaseDisputePr
@Override
public void getEventinfo(EventInfoFormDTO formDTO) {
formDTO.setPageSize(1000);
long start = System.currentTimeMillis();
Result<List<EventInfoResultDTO>> result = dataStatisticalOpenFeignClient.getEventInfo(formDTO);
if (!result.success()) {
log.error("getEventinfo cost:{}ms",System.currentTimeMillis()-start);
throw new RenException(result.getInternalMsg());
}
Map<String, Integer> deptMap = exDeptService.getDeptDTOMap();

13
epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/UserPatrolRecordServiceImpl.java

@ -71,12 +71,8 @@ public class UserPatrolRecordServiceImpl extends BaseServiceImpl<UserPatrolRecor
}
List<MidPatrolRecordResult> data = record.getData();
if (CollectionUtils.isEmpty(data)) {
//数据已被删除了
//暂时设置error 用于排错
log.error("insertPatrolRecord获取巡查记录返回为空,param:{}", JSON.toJSONString(midPatrolFormDTO));
int effectRow = baseDao.deleteById(patrolRecordForm.getId());
log.warn("del effectRow:{}", effectRow);
throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode());
//数据还未被插入
throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode(),"获取巡查记录返回为空,param:"+ JSON.toJSONString(midPatrolFormDTO));
}
List<UserPatrolRecordEntity> insertList = new ArrayList<>();
data.forEach(o-> insertList.add(buildEntity(o)));
@ -103,10 +99,7 @@ public class UserPatrolRecordServiceImpl extends BaseServiceImpl<UserPatrolRecor
if (CollectionUtils.isEmpty(data)) {
//数据已被删除了
//暂时设置error 用于排错
log.error("updatePatrolRecord 获取巡查记录返回为空,param:{}", JSON.toJSONString(midPatrolFormDTO));
int effectRow = baseDao.deleteById(patrolRecordForm.getId());
log.warn("del effectRow:{}", effectRow);
throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode());
throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode(),"获取巡查记录返回为空,param:"+ JSON.toJSONString(midPatrolFormDTO));
}
data.forEach(o->{
UserPatrolRecordEntity recordEntity = buildEntity(o);

3
epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserBadgeServiceImpl.java

@ -279,7 +279,8 @@ public class UserBadgeServiceImpl implements UserBadgeService {
userBadgeDao.insertUserBadgeCertificateRecord(form);
//TODO 站内信发送
String badgeName = badgeDao.selectBadgeName(form.getCustomerId(), form.getBadgeId());
String msg = String.format(BadgeConstant.MESSAGE_CONTENT, userBaseInfoResultDTOS.get(NumConstant.ZERO).getDistrict().concat(userBaseInfoResultDTOS.get(NumConstant.ZERO).getRealName()), badgeName);
String s = StringUtils.isBlank(userBaseInfoResultDTOS.get(NumConstant.ZERO).getDistrict()) ? userBaseInfoResultDTOS.get(NumConstant.ZERO).getRealName() : userBaseInfoResultDTOS.get(NumConstant.ZERO).getDistrict().concat(userBaseInfoResultDTOS.get(NumConstant.ZERO).getRealName());
String msg = String.format(BadgeConstant.MESSAGE_CONTENT, s, badgeName);
// 记录待审核id,和消息类型
sendMessage(BadgeConstant.AUTH_TITLE,msg,form.getGridId(),form.getUserId(),form.getCustomerId(),
UserMessageTypeConstant.BADGE_AUTH_APPLY,

214
epmet-user/epmet-user-server/src/main/java/com/epmet/util/MySequence.java

@ -0,0 +1,214 @@
/*
* Copyright (c) 2011-2021, baomidou (jobob@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.epmet.util;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.SystemClock;
import com.epmet.commons.tools.utils.HttpClientManager;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;
import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.concurrent.ThreadLocalRandom;
/**
* 分布式高效有序 ID 生产黑科技(sequence)
*
* <p>优化开源项目https://gitee.com/yu120/sequence</p>
*
* @author hubin
* @since 2016-08-18
*/
@Slf4j
public class MySequence {
private static final Log logger = LogFactory.getLog(MySequence.class);
/**
* 时间起始标记点作为基准一般取系统的最近时间一旦确定不能变动
*/
private final long twepoch = 1288834974657L;
/**
* 机器标识位数
*/
private final long workerIdBits = 5L;
private final long datacenterIdBits = 5L;
private final long maxWorkerId = -1L ^ (-1L << workerIdBits);
private final long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
/**
* 毫秒内自增位
*/
private final long sequenceBits = 12L;
private final long workerIdShift = sequenceBits;
private final long datacenterIdShift = sequenceBits + workerIdBits;
/**
* 时间戳左移动位
*/
private final long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
private final long sequenceMask = -1L ^ (-1L << sequenceBits);
private final long workerId;
/**
* 数据标识 ID 部分
*/
private final long datacenterId;
/**
* 并发控制
*/
private long sequence = 0L;
/**
* 上次生产 ID 时间戳
*/
private long lastTimestamp = -1L;
public MySequence() {
this.datacenterId = getDatacenterId(maxDatacenterId);
this.workerId = getMaxWorkerId(datacenterId, maxWorkerId);
String msg = "MySequence datacenterId:" + this.datacenterId + ";workerId:" + this.workerId;
log.info(msg);
HttpClientManager.getInstance().sendAlarmMsg(msg);
}
/**
* 有参构造器
*
* @param workerId 工作机器 ID
* @param datacenterId 序列号
*/
public MySequence(long workerId, long datacenterId) {
Assert.isFalse(workerId > maxWorkerId || workerId < 0,
String.format("MySequence worker Id can't be greater than %d or less than 0", maxWorkerId));
Assert.isFalse(datacenterId > maxDatacenterId || datacenterId < 0,
String.format("MySequence datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
this.workerId = workerId;
this.datacenterId = datacenterId;
}
/**
* 获取 maxWorkerId
*/
protected static long getMaxWorkerId(long datacenterId, long maxWorkerId) {
StringBuilder mpid = new StringBuilder();
mpid.append(datacenterId);
String name = ManagementFactory.getRuntimeMXBean().getName();
String msg = "MySequence getMaxWorkerId name:" + name;
log.info(msg);
HttpClientManager.getInstance().sendAlarmMsg(msg);
if (StringUtils.isNotBlank(name)) {
/*
* GET jvmPid
*/
mpid.append(name.split(StringPool.AT)[0]);
}
/*
* MAC + PID hashcode 获取16个低位
*/
return (mpid.toString().hashCode() & 0xffff) % (maxWorkerId + 1);
}
/**
* 数据标识id部分
*/
protected static long getDatacenterId(long maxDatacenterId) {
long id = 0L;
try {
InetAddress ip = InetAddress.getLocalHost();
NetworkInterface network = NetworkInterface.getByInetAddress(ip);
String msg = "MySequence ip:" + JSON.toJSONString(ip) + ";network: " + JSON.toJSONString(network);
log.info(msg);
HttpClientManager.getInstance().sendAlarmMsg(msg);
if (network == null) {
id = 1L;
log.info("MySequen cenetwork ==null ");
} else {
byte[] mac = network.getHardwareAddress();
if (null != mac) {
id = ((0x000000FF & (long) mac[mac.length - 2]) | (0x0000FF00 & (((long) mac[mac.length - 1]) << 8))) >> 6;
id = id % (maxDatacenterId + 1);
}
}
} catch (Exception e) {
logger.warn(" getDatacenterId: " + e.getMessage());
}
return id;
}
/**
* 获取下一个 ID
*
* @return 下一个 ID
*/
public synchronized long nextId() {
long timestamp = timeGen();
//闰秒
if (timestamp < lastTimestamp) {
long offset = lastTimestamp - timestamp;
if (offset <= 5) {
try {
wait(offset << 1);
timestamp = timeGen();
if (timestamp < lastTimestamp) {
throw new RuntimeException(String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", offset));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
throw new RuntimeException(String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", offset));
}
}
if (lastTimestamp == timestamp) {
// 相同毫秒内,序列号自增
sequence = (sequence + 1) & sequenceMask;
if (sequence == 0) {
// 同一毫秒的序列数已经达到最大
timestamp = tilNextMillis(lastTimestamp);
}
} else {
// 不同毫秒内,序列号置为 1 - 3 随机数
sequence = ThreadLocalRandom.current().nextLong(1, 3);
}
lastTimestamp = timestamp;
// 时间戳部分 | 数据中心部分 | 机器标识部分 | 序列号部分
return ((timestamp - twepoch) << timestampLeftShift)
| (datacenterId << datacenterIdShift)
| (workerId << workerIdShift)
| sequence;
}
protected long tilNextMillis(long lastTimestamp) {
long timestamp = timeGen();
while (timestamp <= lastTimestamp) {
timestamp = timeGen();
}
return timestamp;
}
protected long timeGen() {
return SystemClock.now();
}
}

3
epmet-user/epmet-user-server/src/main/resources/bootstrap.yml

@ -106,6 +106,9 @@ mybatis-plus:
field-strategy: NOT_NULL
#驼峰下划线转换
column-underline: true
worker-id: ${random.int(1,31)}
datacenter-id: ${random.int(1,31)}
banner: false
#原生配置
configuration:

17
epmet-user/epmet-user-server/src/test/java/com/epmet/epmetuser/test/UserControllerTest.java

@ -1,7 +1,10 @@
package com.epmet.epmetuser.test;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.epmet.commons.tools.constant.AppClientConstant;
import com.epmet.dao.UserDao;
import com.epmet.dto.result.LoginUserDetailsResultDTO;
import com.epmet.entity.UserEntity;
import com.epmet.service.UserService;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -15,11 +18,25 @@ public class UserControllerTest {
@Autowired
private UserService userService;
@Autowired
private UserDao userDao;
@Test
public void getLoginUserDetails() {
LoginUserDetailsResultDTO loginUserDetails = userService.getLoginUserDetails(AppClientConstant.APP_GOV, AppClientConstant.CLIENT_WXMP, "4aaab913d9f11d90a2cb4dd21b075259");
System.out.println(loginUserDetails);
}
@Test
public void insertUser() {
UserEntity entity = new UserEntity();
entity.setCustomerId("test_ljj");
String idStr = IdWorker.getIdStr();
System.out.println(idStr);
//int insert = userDao.insert(entity);
//System.out.println(insert);
}
}

Loading…
Cancel
Save