소스 검색

错误提交

huangzhiyong 6 년 전
부모
커밋
2288c730e3

+ 0 - 28
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/cache/Receiver.java

@ -1,28 +0,0 @@
package com.yihu.jw.healthyhouse.cache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.concurrent.CountDownLatch;
/**
 * @author HZY
 * @created 2018/10/8 15:05
 */
public class Receiver {
    private static final Logger LOGGER = LoggerFactory.getLogger(Receiver.class);
    private CountDownLatch latch;
    @Autowired
    public Receiver(CountDownLatch latch) {
        this.latch = latch;
    }
    public void receiveMessage(String message) {
        LOGGER.info("Received <" + message + ">");
        latch.countDown();
    }
    }

+ 0 - 68
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/config/RedisConfig.java

@ -1,68 +0,0 @@
package com.yihu.jw.healthyhouse.config;
import com.yihu.jw.healthyhouse.cache.Receiver;
import org.springframework.boot.SpringApplication;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
import java.util.concurrent.CountDownLatch;
/**
 * @author HZY
 * @created 2018/10/8 15:12
 */
@Configuration
public class RedisConfig  {
    /*
     * Redis消息监听器容器
     * 这个容器加载了RedisConnectionFactory和消息监听器
     */
    @Bean
    RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory,
                                            MessageListenerAdapter listenerAdapter){
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        container.addMessageListener(listenerAdapter, new PatternTopic("sprinboot-redis-messaage"));
        return container;
    }
    /*
     * 将Receiver注册为一个消息监听器,并指定消息接收的方法(receiveMessage)
     * 如果不指定消息接收的方法,消息监听器会默认的寻找Receiver中的handleMessage这个方法作为消息接收的方法
     */
    @Bean
    MessageListenerAdapter listenerAdapter(Receiver receiver){
        return new MessageListenerAdapter(receiver, "receiveMessage");
    }
    /*
     * Receiver实例
     */
    @Bean
    Receiver receiver(CountDownLatch latch){
        return new Receiver(latch);
    }
    @Bean
    CountDownLatch latch(){
        return new CountDownLatch(1);
    }
    /*
     * Redis Template 用来发送消息
     */
    @Bean
    StringRedisTemplate template(RedisConnectionFactory connectionFactory){
        return new StringRedisTemplate(connectionFactory);
    }
}

+ 2 - 1
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/controller/facilities/FacilitiesController.java

@ -303,7 +303,8 @@ public class FacilitiesController extends EnvelopRestEndpoint {
            }
        } catch (Exception e) {
            return failed("导入异常");
            e.printStackTrace();
            return failed("导入异常,请检查导入文件格式"+e.getMessage());
        }
        return failed("导入失败");
    }

+ 2 - 2
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/controller/user/UserController.java

@ -157,7 +157,7 @@ public class UserController  extends EnvelopRestEndpoint {
        try {
            //验证码
            if (wlyyRedisVerifyCodeService.verification(clientId, oldPhone, captcha)) {
            if (wlyyRedisVerifyCodeService.verification(clientId, newPhone, captcha)) {
                userService.updateSecurePhone(userId, newPhone);
                return success("更新安全手机号码成功");
            } else {
@ -284,7 +284,7 @@ public class UserController  extends EnvelopRestEndpoint {
            @RequestParam(value = "userId") String userId) {
        try {
              userService.setUserActivated(userId, 60);
              userService.setUserActivated(userId, 10);
            return success("心跳正常");
        } catch (Exception e) {
            return failed("心跳异常");

+ 2 - 1
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/dao/user/UserDao.java

@ -41,7 +41,8 @@ public interface UserDao extends PagingAndSortingRepository<User, String>, JpaSp
    Long countAllByUserTypeAndCreateTimeBetween(String userType,Date start,Date end);
    User findByLoginCodeAndUserType(String loginCode,String userType);
    @Query("from User u where u.userType=?1 and (u.telephone=?2 or u.loginCode=?3 ) ")
    User findByUserTypeAndTelephoneOrLoginCode(String userType,String telephone,String loginCode);
    User findByTelephoneAndUserType(String telephone,String userType);
}

+ 5 - 2
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/listener/MyKeyExpirationEventMessageListener.java

@ -8,9 +8,9 @@ import org.springframework.data.redis.listener.RedisMessageListenerContainer;
 * @author HZY
 * @created 2018/10/8 15:11
 */
public class MyKeyExpirationEventMessageListener extends KeyExpirationEventMessageListener {
public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {
    public MyKeyExpirationEventMessageListener(RedisMessageListenerContainer listenerContainer) {
    public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
        super(listenerContainer);
    }
@ -20,6 +20,9 @@ public class MyKeyExpirationEventMessageListener extends KeyExpirationEventMessa
//      System.out.println(new String(message.getChannel()));
//      System.out.println(new String(pattern));
//      super.onMessage(message, pattern);
        // 用户做自己的业务处理即可,注意message.toString()可以获取失效的key
        String expiredKey = message.toString();
        System.out.println(expiredKey);
    }
}

+ 8 - 9
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/service/user/UserService.java

@ -3,12 +3,9 @@ package com.yihu.jw.healthyhouse.service.user;
import com.yihu.jw.exception.business.ManageException;
import com.yihu.jw.healthyhouse.constant.LoginInfo;
import com.yihu.jw.healthyhouse.constant.UserConstant;
import com.yihu.jw.healthyhouse.dao.facility.FacilityDao;
import com.yihu.jw.healthyhouse.dao.user.UserDao;
import com.yihu.jw.healthyhouse.model.facility.Facility;
import com.yihu.jw.healthyhouse.model.user.User;
import com.yihu.jw.healthyhouse.util.poi.ExcelUtils;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.wlyy.HouseUserContant;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.date.DateUtil;
@ -35,7 +32,6 @@ import javax.transaction.Transactional;
import java.io.OutputStream;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
/**
 * @author HZY
@ -43,15 +39,18 @@ import java.util.regex.Pattern;
 */
@Service
public class UserService extends BaseJpaService<User, UserDao> {
    private final String KEY_PREFIX = ":healthyHouse";
    private final String KEY_PREFIX = "healthyHouse:";
    private final String KEY_SUFFIX = ":activated";
    private final RedisTemplate redisTemplate;
    @Autowired
    private UserDao userDao;
    @Autowired
    private FacilityUsedRecordService facilityUsedRecordService;
    @Autowired
    private  RedisTemplate redisTemplate;
    public UserService(RedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
    }
    /**
     * 设置用户在线状态
@ -73,7 +72,7 @@ public class UserService extends BaseJpaService<User, UserDao> {
    }
    public User findByLoginCodeAndUserType(String loginCode,String userType) {
        return userDao.findByLoginCodeAndUserType(loginCode,userType);
        return userDao.findByUserTypeAndTelephoneOrLoginCode(userType,loginCode,loginCode);
    }
    public User findByTelephoneAndUserType(String telephone,String userType) {