diff --git a/cola-cloud-config/src/main/resources/shared/application.yml b/cola-cloud-config/src/main/resources/shared/application.yml index f5d90091f36374e0649a8f525dfd05cdc99e2e2d..a0e6c6711a48299c34adf2073e0b4454c943a636 100644 --- a/cola-cloud-config/src/main/resources/shared/application.yml +++ b/cola-cloud-config/src/main/resources/shared/application.yml @@ -47,7 +47,9 @@ spring: max-wait: 1 max-idle: 50 min-idle: 0 - + redisson: + address: redis://cola-redis:6379 + password: ${REDIS_SERVER_PASSWORD:} cola: swagger2: enable: true diff --git a/cola-cloud-dependencies/pom.xml b/cola-cloud-dependencies/pom.xml index 7f971783daf3db069c0d551266c78f8d920ec3c5..657b8d2ff7a8baa37862f81841a6bf14f2e8e6e0 100644 --- a/cola-cloud-dependencies/pom.xml +++ b/cola-cloud-dependencies/pom.xml @@ -156,6 +156,11 @@ aliyun-sdk-oss 2.8.2 + + org.redisson + redisson + 3.6.5 + \ No newline at end of file diff --git a/cola-cloud-framework/cola-cloud-framework-lock/pom.xml b/cola-cloud-framework/cola-cloud-framework-lock/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..2fffc6c5ded3a1235bf32155001827ecc5c53300 --- /dev/null +++ b/cola-cloud-framework/cola-cloud-framework-lock/pom.xml @@ -0,0 +1,43 @@ + + + + cola-cloud-framework + com.honvay.cola + 1.0.0-SNAPSHOT + + 4.0.0 + 1.0.0-SNAPSHOT + cola-cloud-framework-lock + + + org.apache.commons + commons-lang3 + + + org.slf4j + log4j-over-slf4j + + + com.google.guava + guava + + + org.springframework + spring-aop + + + org.springframework + spring-expression + + + org.aspectj + aspectjrt + + + org.redisson + redisson + + + \ No newline at end of file diff --git a/cola-cloud-framework/cola-cloud-framework-lock/src/main/java/com/honvay/cola/cloud/framework/lock/DistributedLock.java b/cola-cloud-framework/cola-cloud-framework-lock/src/main/java/com/honvay/cola/cloud/framework/lock/DistributedLock.java new file mode 100644 index 0000000000000000000000000000000000000000..ec3bf8a351103844e33deabf602445af78a066a0 --- /dev/null +++ b/cola-cloud-framework/cola-cloud-framework-lock/src/main/java/com/honvay/cola/cloud/framework/lock/DistributedLock.java @@ -0,0 +1,25 @@ +package com.honvay.cola.cloud.framework.lock; + +import org.redisson.api.RLock; + +import java.util.concurrent.TimeUnit; + +/** + * 分布式锁接口 + * @author hamst + * @date 2018-04-20 + */ +public interface DistributedLock { + + RLock lock(String lockKey); + + RLock lock(String lockKey, int timeout); + + RLock lock(String lockKey, TimeUnit unit, int timeout); + + boolean tryLock(String lockKey, long waitTime, long leaseTime, TimeUnit unit); + + void unlock(String lockKey); + + void unlock(RLock lock); +} \ No newline at end of file diff --git a/cola-cloud-framework/cola-cloud-framework-lock/src/main/java/com/honvay/cola/cloud/framework/lock/RedissonDistributedLock.java b/cola-cloud-framework/cola-cloud-framework-lock/src/main/java/com/honvay/cola/cloud/framework/lock/RedissonDistributedLock.java new file mode 100644 index 0000000000000000000000000000000000000000..097983eb79f31caf9192f4f5ad57704b0df6cc60 --- /dev/null +++ b/cola-cloud-framework/cola-cloud-framework-lock/src/main/java/com/honvay/cola/cloud/framework/lock/RedissonDistributedLock.java @@ -0,0 +1,62 @@ +package com.honvay.cola.cloud.framework.lock; + +import org.redisson.api.RLock; +import org.redisson.api.RedissonClient; + +import java.util.concurrent.TimeUnit; + +/** + * 分布式锁Redission实现 + * @author hamst + * @date 2018-04-20 + */ +public class RedissonDistributedLock implements DistributedLock { + + private RedissonClient redissonClient; + + @Override + public RLock lock(String lockKey) { + RLock lock = redissonClient.getLock(lockKey); + lock.lock(); + return lock; + } + + @Override + public RLock lock(String lockKey, int leaseTime) { + RLock lock = redissonClient.getLock(lockKey); + lock.lock(leaseTime, TimeUnit.SECONDS); + return lock; + } + + @Override + public RLock lock(String lockKey, TimeUnit unit ,int timeout) { + RLock lock = redissonClient.getLock(lockKey); + lock.lock(timeout, unit); + return lock; + } + + @Override + public boolean tryLock(String lockKey, long waitTime, long leaseTime, TimeUnit unit) { + RLock lock = redissonClient.getLock(lockKey); + try { + return lock.tryLock(waitTime, leaseTime, unit); + } catch (InterruptedException e) { + return false; + } + } + + @Override + public void unlock(String lockKey) { + RLock lock = redissonClient.getLock(lockKey); + lock.unlock(); + } + + @Override + public void unlock(RLock lock) { + lock.unlock(); + } + + public void setRedissonClient(RedissonClient redissonClient) { + this.redissonClient = redissonClient; + } +} \ No newline at end of file diff --git a/cola-cloud-framework/cola-cloud-framework-lock/src/main/java/com/honvay/cola/cloud/framework/lock/annotation/DistributedLocker.java b/cola-cloud-framework/cola-cloud-framework-lock/src/main/java/com/honvay/cola/cloud/framework/lock/annotation/DistributedLocker.java new file mode 100644 index 0000000000000000000000000000000000000000..323ea714eeb898f45df26a42d83fbe52d75435d8 --- /dev/null +++ b/cola-cloud-framework/cola-cloud-framework-lock/src/main/java/com/honvay/cola/cloud/framework/lock/annotation/DistributedLocker.java @@ -0,0 +1,52 @@ +package com.honvay.cola.cloud.framework.lock.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.concurrent.TimeUnit; + +/** + * 分布式锁注解 + * @DistributedLocker(key={"moduleXXX", "#{model.userId}"}) + * public void test(Model model) { + * .... + * } + * @author hamst + * @date 2018-04-20 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface DistributedLocker { + + /** + * 锁的key可以写spel表达式,不写的话key默认就是方法签名,否则是方法签名+key + * @return + */ + String[] key() default ""; + + /** + * 最大等待时间 + * @return + */ + long maximumWaitTime() default 2000; + + /** + * 超时时间 + * @return + */ + long expirationTime() default 1500; + + /** + * 时间单位 + * @return + */ + TimeUnit timeUnit() default TimeUnit.MILLISECONDS; + + /** + * 是否忽略方法签名 + * 默认是方法签名+key + * @return + */ + boolean ignoreSignature() default false; +} \ No newline at end of file diff --git a/cola-cloud-framework/cola-cloud-framework-lock/src/main/java/com/honvay/cola/cloud/framework/lock/aspect/DistributedLockerAspect.java b/cola-cloud-framework/cola-cloud-framework-lock/src/main/java/com/honvay/cola/cloud/framework/lock/aspect/DistributedLockerAspect.java new file mode 100644 index 0000000000000000000000000000000000000000..73ac576679b43e33b460854a2fbd4493767e423e --- /dev/null +++ b/cola-cloud-framework/cola-cloud-framework-lock/src/main/java/com/honvay/cola/cloud/framework/lock/aspect/DistributedLockerAspect.java @@ -0,0 +1,98 @@ +package com.honvay.cola.cloud.framework.lock.aspect; + +import com.google.common.base.Joiner; +import com.honvay.cola.cloud.framework.lock.DistributedLock; +import com.honvay.cola.cloud.framework.lock.annotation.DistributedLocker; +import com.honvay.cola.cloud.framework.lock.exception.DistributedLockException; +import org.apache.commons.lang3.StringUtils; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.aspectj.lang.reflect.MethodSignature; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.LocalVariableTableParameterNameDiscoverer; +import org.springframework.expression.EvaluationContext; +import org.springframework.expression.Expression; +import org.springframework.expression.spel.standard.SpelExpressionParser; +import org.springframework.expression.spel.support.StandardEvaluationContext; + +import java.lang.reflect.Method; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.Lock; + +/** + * 分布式锁拦截器 + * @author hamst + * @date 2018-04-20 + */ +@Aspect +public class DistributedLockerAspect { + + @Autowired + private DistributedLock distributedLock; + + protected Lock getLock(String key){ + return distributedLock.lock(key); + }; + + protected boolean tryLock(String key, long waitTime, long leaseTime, TimeUnit timeUnit, Lock lock) throws InterruptedException{ + return distributedLock.tryLock(key, waitTime, leaseTime, timeUnit); + } + + @Pointcut("@annotation(com.honvay.cola.cloud.framework.lock.annotation.DistributedLocker)") + public void pointcut(){} + + @Around("pointcut()") + public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable{ + Method method = ((MethodSignature)joinPoint.getSignature()).getMethod(); + if (method != null && method.isAnnotationPresent(DistributedLocker.class)) { + DistributedLocker distributedLocker = method.getAnnotation(DistributedLocker.class); + String lockKey = getLockKey(joinPoint, distributedLocker); + Lock lock = this.getLock(lockKey); + boolean isLock = this.tryLock(lockKey, distributedLocker.maximumWaitTime(), distributedLocker.expirationTime(), distributedLocker.timeUnit(), lock); + if(isLock) { + try { + return joinPoint.proceed(); + } finally { + lock.unlock(); + } + } else { + throw new DistributedLockException(); + } + } + + return joinPoint.proceed(); + } + + private String getLockKey(ProceedingJoinPoint joinPoint, DistributedLocker locker) { + StringBuilder sb = new StringBuilder(); + sb.append("lock."); + String keyStr = null; + if(locker.key() != null) { + keyStr = Joiner.on(".").skipNulls().join(locker.key()); + } + if (StringUtils.isBlank(keyStr) || !locker.ignoreSignature()){ + sb.append(joinPoint.getTarget().getClass().getName()).append(".").append(joinPoint.getSignature().getName()); + } + if(!StringUtils.isBlank(keyStr)) { + Method method = ((MethodSignature)joinPoint.getSignature()).getMethod(); + String[] parameters = new LocalVariableTableParameterNameDiscoverer().getParameterNames(method); + Expression expression = new SpelExpressionParser().parseExpression(keyStr); + EvaluationContext context = new StandardEvaluationContext(); + int length = parameters.length; + Object[] arguments = joinPoint.getArgs(); + if (length > 0) { + for (int i = 0; i < length; i++) { + context.setVariable(parameters[i], arguments[i]); + } + } + String keysValue = expression.getValue(context, String.class); + sb.append("#").append(keysValue); + } + return sb.toString(); + } + + + +} \ No newline at end of file diff --git a/cola-cloud-framework/cola-cloud-framework-lock/src/main/java/com/honvay/cola/cloud/framework/lock/exception/DistributedLockException.java b/cola-cloud-framework/cola-cloud-framework-lock/src/main/java/com/honvay/cola/cloud/framework/lock/exception/DistributedLockException.java new file mode 100644 index 0000000000000000000000000000000000000000..179cf657da30c51a0d795f3d97b67e99a3f59170 --- /dev/null +++ b/cola-cloud-framework/cola-cloud-framework-lock/src/main/java/com/honvay/cola/cloud/framework/lock/exception/DistributedLockException.java @@ -0,0 +1,9 @@ +package com.honvay.cola.cloud.framework.lock.exception; + +/** + * 分布式锁异常 + * @author hamst + * @date 2018-04-20 + */ +public class DistributedLockException extends RuntimeException { +} diff --git a/cola-cloud-framework/cola-cloud-framework-lock/src/main/java/com/honvay/cola/cloud/framework/lock/util/DistributedLockUtil.java b/cola-cloud-framework/cola-cloud-framework-lock/src/main/java/com/honvay/cola/cloud/framework/lock/util/DistributedLockUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..6f5a9a166d1b0c010d21a1fe3b351dd345b5b35c --- /dev/null +++ b/cola-cloud-framework/cola-cloud-framework-lock/src/main/java/com/honvay/cola/cloud/framework/lock/util/DistributedLockUtil.java @@ -0,0 +1,48 @@ +package com.honvay.cola.cloud.framework.lock.util; + +import com.honvay.cola.cloud.framework.lock.DistributedLock; +import org.redisson.api.RLock; + +import java.util.concurrent.TimeUnit; + +/** + * 分布式锁Util + * @author hamst + * @date 2018-04-20 + */ +public class DistributedLockUtil { + private static DistributedLock redissLock; + + public static void setLocker(DistributedLock locker) { + redissLock = locker; + } + + public static RLock lock(String lockKey) { + return redissLock.lock(lockKey); + } + + public static void unlock(String lockKey) { + redissLock.unlock(lockKey); + } + + public static void unlock(RLock lock) { + redissLock.unlock(lock); + } + + public static RLock lock(String lockKey, int timeout) { + return redissLock.lock(lockKey, timeout); + } + + + public static RLock lock(String lockKey, TimeUnit unit ,int timeout) { + return redissLock.lock(lockKey, unit, timeout); + } + + public static boolean tryLock(String lockKey, int waitTime, int leaseTime) { + return redissLock.tryLock(lockKey, waitTime, leaseTime, TimeUnit.SECONDS); + } + + public static boolean tryLock(String lockKey, int waitTime, int leaseTime, TimeUnit timeUnit) { + return redissLock.tryLock(lockKey, waitTime, leaseTime, timeUnit); + } +} \ No newline at end of file diff --git a/cola-cloud-framework/cola-cloud-framework-starter/cola-cloud-framework-starter-lock/pom.xml b/cola-cloud-framework/cola-cloud-framework-starter/cola-cloud-framework-starter-lock/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..82f7099c185dfa9b9d1efdd8d1e31a6caa8cbe23 --- /dev/null +++ b/cola-cloud-framework/cola-cloud-framework-starter/cola-cloud-framework-starter-lock/pom.xml @@ -0,0 +1,19 @@ + + + 4.0.0 + + com.honvay.cola + cola-cloud-framework-starter + 1.0.0-SNAPSHOT + + cola-cloud-framework-starter-lock + jar + ${project.artifactId} + + + com.honvay.cola + cola-cloud-framework-lock + + + diff --git a/cola-cloud-framework/cola-cloud-framework-starter/cola-cloud-framework-starter-lock/src/main/java/com/honvay/cola/cloud/framework/starter/lock/RedissonAutoConfiguration.java b/cola-cloud-framework/cola-cloud-framework-starter/cola-cloud-framework-starter-lock/src/main/java/com/honvay/cola/cloud/framework/starter/lock/RedissonAutoConfiguration.java new file mode 100644 index 0000000000000000000000000000000000000000..89a7cf658edf5980d60c0de3cbdfb9b6816b9772 --- /dev/null +++ b/cola-cloud-framework/cola-cloud-framework-starter/cola-cloud-framework-starter-lock/src/main/java/com/honvay/cola/cloud/framework/starter/lock/RedissonAutoConfiguration.java @@ -0,0 +1,92 @@ +package com.honvay.cola.cloud.framework.starter.lock; + +import com.honvay.cola.cloud.framework.lock.DistributedLock; +import com.honvay.cola.cloud.framework.lock.RedissonDistributedLock; +import com.honvay.cola.cloud.framework.lock.aspect.DistributedLockerAspect; +import com.honvay.cola.cloud.framework.lock.util.DistributedLockUtil; +import com.honvay.cola.cloud.framework.starter.lock.properties.RedissonProperties; +import org.apache.commons.lang3.StringUtils; +import org.redisson.Redisson; +import org.redisson.api.RedissonClient; +import org.redisson.config.Config; +import org.redisson.config.SentinelServersConfig; +import org.redisson.config.SingleServerConfig; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.EnableAspectJAutoProxy; + +/** + * 分布式锁配置 + * @author hamst + * @date 2018-04-20 + */ +@Configuration +@ConditionalOnClass(Config.class) +@EnableConfigurationProperties(RedissonProperties.class) +@EnableAspectJAutoProxy +public class RedissonAutoConfiguration { + + @Autowired + private RedissonProperties redssionProperties; + + /** + * 哨兵模式自动装配 + * @return + */ + @Bean + @ConditionalOnProperty(name="spring.redisson.master-name") + RedissonClient redissonSentinel() { + Config config = new Config(); + SentinelServersConfig serverConfig = config.useSentinelServers().addSentinelAddress(redssionProperties.getSentinelAddresses()) + .setMasterName(redssionProperties.getMasterName()) + .setTimeout(redssionProperties.getTimeout()) + .setMasterConnectionPoolSize(redssionProperties.getMasterConnectionPoolSize()) + .setSlaveConnectionPoolSize(redssionProperties.getSlaveConnectionPoolSize()); + + if(StringUtils.isNotBlank(redssionProperties.getPassword())) { + serverConfig.setPassword(redssionProperties.getPassword()); + } + return Redisson.create(config); + } + + /** + * 单机模式自动装配 + * @return + */ + @Bean + @ConditionalOnProperty(name="spring.redisson.address") + RedissonClient redissonSingle() { + Config config = new Config(); + SingleServerConfig serverConfig = config.useSingleServer() + .setAddress(redssionProperties.getAddress()) + .setTimeout(redssionProperties.getTimeout()) + .setConnectionPoolSize(redssionProperties.getConnectionPoolSize()) + .setConnectionMinimumIdleSize(redssionProperties.getConnectionMinimumIdleSize()); + + if(StringUtils.isNotBlank(redssionProperties.getPassword())) { + serverConfig.setPassword(redssionProperties.getPassword()); + } + + return Redisson.create(config); + } + + @Bean + @ConditionalOnBean(RedissonClient.class) + DistributedLock distributedLock(RedissonClient redissonClient) { + RedissonDistributedLock locker = new RedissonDistributedLock(); + locker.setRedissonClient(redissonClient); + DistributedLockUtil.setLocker(locker); + return locker; + } + + @Bean + @ConditionalOnBean(DistributedLock.class) + DistributedLockerAspect distributedLockerAspect() { + return new DistributedLockerAspect(); + } +} \ No newline at end of file diff --git a/cola-cloud-framework/cola-cloud-framework-starter/cola-cloud-framework-starter-lock/src/main/java/com/honvay/cola/cloud/framework/starter/lock/properties/RedissonProperties.java b/cola-cloud-framework/cola-cloud-framework-starter/cola-cloud-framework-starter-lock/src/main/java/com/honvay/cola/cloud/framework/starter/lock/properties/RedissonProperties.java new file mode 100644 index 0000000000000000000000000000000000000000..cb8ed0ca7169ee7bbb437d22444a39667630ccf4 --- /dev/null +++ b/cola-cloud-framework/cola-cloud-framework-starter/cola-cloud-framework-starter-lock/src/main/java/com/honvay/cola/cloud/framework/starter/lock/properties/RedissonProperties.java @@ -0,0 +1,102 @@ +package com.honvay.cola.cloud.framework.starter.lock.properties; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * 分布式锁属性 + * @author hamst + * @date 2018-04-20 + */ +@ConfigurationProperties(prefix = "spring.redisson") +public class RedissonProperties { + + private int timeout = 3000; + + private String address; + + private String password; + + private int connectionPoolSize = 64; + + private int connectionMinimumIdleSize = 10; + + private int slaveConnectionPoolSize = 250; + + private int masterConnectionPoolSize = 250; + + private String[] sentinelAddresses; + + private String masterName; + + public int getTimeout() { + return timeout; + } + + public void setTimeout(int timeout) { + this.timeout = timeout; + } + + public int getSlaveConnectionPoolSize() { + return slaveConnectionPoolSize; + } + + public void setSlaveConnectionPoolSize(int slaveConnectionPoolSize) { + this.slaveConnectionPoolSize = slaveConnectionPoolSize; + } + + public int getMasterConnectionPoolSize() { + return masterConnectionPoolSize; + } + + public void setMasterConnectionPoolSize(int masterConnectionPoolSize) { + this.masterConnectionPoolSize = masterConnectionPoolSize; + } + + public String[] getSentinelAddresses() { + return sentinelAddresses; + } + + public void setSentinelAddresses(String sentinelAddresses) { + this.sentinelAddresses = sentinelAddresses.split(","); + } + + public String getMasterName() { + return masterName; + } + + public void setMasterName(String masterName) { + this.masterName = masterName; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public int getConnectionPoolSize() { + return connectionPoolSize; + } + + public void setConnectionPoolSize(int connectionPoolSize) { + this.connectionPoolSize = connectionPoolSize; + } + + public int getConnectionMinimumIdleSize() { + return connectionMinimumIdleSize; + } + + public void setConnectionMinimumIdleSize(int connectionMinimumIdleSize) { + this.connectionMinimumIdleSize = connectionMinimumIdleSize; + } +} \ No newline at end of file diff --git a/cola-cloud-framework/cola-cloud-framework-starter/cola-cloud-framework-starter-lock/src/main/resources/META-INF/spring.factories b/cola-cloud-framework/cola-cloud-framework-starter/cola-cloud-framework-starter-lock/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000000000000000000000000000000000000..7cd6d143924ad71f6fbaa74a513e5b2c094f832b --- /dev/null +++ b/cola-cloud-framework/cola-cloud-framework-starter/cola-cloud-framework-starter-lock/src/main/resources/META-INF/spring.factories @@ -0,0 +1,3 @@ +# Auto Configure +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +com.honvay.cola.cloud.framework.starter.mail.MailAutoConfiguration \ No newline at end of file diff --git a/cola-cloud-framework/cola-cloud-framework-starter/pom.xml b/cola-cloud-framework/cola-cloud-framework-starter/pom.xml index 16baed7af9fb8c1c4b1f476cea50b76675ff85ea..3b16af59325d149b03b53b360dbb6ce9fb903de3 100644 --- a/cola-cloud-framework/cola-cloud-framework-starter/pom.xml +++ b/cola-cloud-framework/cola-cloud-framework-starter/pom.xml @@ -16,6 +16,7 @@ cola-cloud-framework-starter-storage cola-cloud-framework-starter-swagger cola-cloud-framework-starter-miniapp + cola-cloud-framework-starter-lock diff --git a/cola-cloud-framework/pom.xml b/cola-cloud-framework/pom.xml index 0168addf3d778854de8f2d10dfed4c0eac84a6c8..c663057cd1c46c7e32a4aabe3b6fe7bd026db0bd 100644 --- a/cola-cloud-framework/pom.xml +++ b/cola-cloud-framework/pom.xml @@ -22,5 +22,6 @@ cola-cloud-framework-util cola-cloud-framework-starter cola-cloud-framework-criteria + cola-cloud-framework-lock \ No newline at end of file diff --git a/cola-cloud-platform/cola-cloud-message/cola-cloud-message-service/src/main/java/com/honvay/cola/cloud/notification/service/service/impl/MessageServiceImpl.java b/cola-cloud-platform/cola-cloud-message/cola-cloud-message-service/src/main/java/com/honvay/cola/cloud/notification/service/service/impl/MessageServiceImpl.java index f77b6fa0c9e8bd15ef0e8c97413f2ecdb0950c5c..0ade5fad717ace3c91d2d8378c266456bed62174 100644 --- a/cola-cloud-platform/cola-cloud-message/cola-cloud-message-service/src/main/java/com/honvay/cola/cloud/notification/service/service/impl/MessageServiceImpl.java +++ b/cola-cloud-platform/cola-cloud-message/cola-cloud-message-service/src/main/java/com/honvay/cola/cloud/notification/service/service/impl/MessageServiceImpl.java @@ -11,7 +11,7 @@ import com.honvay.cola.cloud.notification.model.SmsNotification; import com.honvay.cola.cloud.notification.service.entity.Message; import com.honvay.cola.cloud.notification.service.service.MessageService; import com.honvay.cola.cloud.uc.client.SysUserClient; -import com.honvay.cola.cloud.uc.model.SysUserDTO; +import com.honvay.cola.cloud.uc.model.SysUserVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -63,25 +63,24 @@ public class MessageServiceImpl extends BaseServiceImpl implements Mess @Override public boolean add(MessageDTO messageDTO){ - SysUserDTO sysUserDTO = null; Message message = new Message(); BeanUtils.copy(messageDTO,message); message.setSmsStatus(NO_SEND_STATUS); message.setEmailStatus(NO_SEND_STATUS); //发送邮件,发送短信 if (messageDTO.getSendSms() || messageDTO.getSendEmail()) { - sysUserDTO = sysUserClient.findUserById(messageDTO.getSysUserId()); + SysUserVO sysUserVO = sysUserClient.findUserById(messageDTO.getSysUserId()); if(messageDTO.getSendSms()){ message.setSmsStatus(WAIT_SEND_STATUS); Assert.hasText(message.getTemplateCode(), "站内信的参数是发送短信,短信模板不能为空"); - if (sendSms(messageDTO, sysUserDTO)) { + if (sendSms(messageDTO, sysUserVO)) { message.setSmsStatus(FINISH_SEND_STATUS); } } if(messageDTO.getSendEmail()){ message.setEmailStatus(WAIT_SEND_STATUS); - if (sendMail(messageDTO, sysUserDTO)) { + if (sendMail(messageDTO, sysUserVO)) { message.setEmailStatus(FINISH_SEND_STATUS); } } @@ -113,19 +112,19 @@ public class MessageServiceImpl extends BaseServiceImpl implements Mess return super.updateById(message); } - public boolean sendMail(MessageDTO messageDTO, SysUserDTO sysUserDTO) { + public boolean sendMail(MessageDTO messageDTO, SysUserVO sysUserVO) { EmailNotification emailNotification = new EmailNotification(); emailNotification.setContent(messageDTO.getContent()); - emailNotification.setReceiver(sysUserDTO.getEmail()); + emailNotification.setReceiver(sysUserVO.getEmail()); emailNotification.setTitle(messageDTO.getTitle()); notificationClient.send(emailNotification); //TODO 邮件发送异常未捕获 return true; } - public boolean sendSms(MessageDTO messageDTO, SysUserDTO sysUserDTO) { + public boolean sendSms(MessageDTO messageDTO, SysUserVO sysUserVO) { SmsNotification smsNotification = new SmsNotification(); - smsNotification.setPhoneNumber(sysUserDTO.getPhoneNumber()); + smsNotification.setPhoneNumber(sysUserVO.getPhoneNumber()); smsNotification.setSignName(messageDTO.getSignName()); smsNotification.setParams(messageDTO.getSmsParams()); smsNotification.setTemplateCode(messageDTO.getTemplateCode()); diff --git a/pom.xml b/pom.xml index 674180c18c52abc26d07ff752a5b0a968911e81b..eb79c6c6e3c7e321dfd07829f27cb2e8d6014aa9 100644 --- a/pom.xml +++ b/pom.xml @@ -74,6 +74,11 @@ cola-cloud-framework-storage ${project.version} + + com.honvay.cola + cola-cloud-framework-lock + ${project.version} + com.honvay.cola cola-cloud-framework-starter-storage @@ -99,6 +104,11 @@ cola-cloud-framework-starter-miniapp ${project.version} + + com.honvay.cola + cola-cloud-framework-starter-lock + ${project.version} + com.honvay.cola