|
|
package com.yohoufo.user.service.impl;
|
|
|
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yohoufo.dal.user.IStoredSellerDao;
|
|
|
import com.yohoufo.dal.user.model.StoredSeller;
|
|
|
import com.yohoufo.user.cache.CacheService;
|
|
|
import com.yohoufo.user.service.IStoredSellerService;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneOffset;
|
|
|
|
|
|
@Service
|
|
|
public class StoredSellerServiceImpl implements IStoredSellerService {
|
|
|
private Logger logger = LoggerFactory.getLogger(StoredSellerServiceImpl.class);
|
|
|
|
|
|
@Autowired
|
|
|
private CacheService cacheService;
|
|
|
|
|
|
@Autowired
|
|
|
private IStoredSellerDao storedSellerDao;
|
|
|
|
|
|
public boolean isStoredSeller(Integer uid){
|
|
|
StoredSeller storedSeller = getValidStoredSeller(uid);
|
|
|
if(storedSeller!=null&&storedSeller.getUid()!=null){
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
private StoredSeller getValidStoredSeller(Integer uid){
|
|
|
//从缓存中获取
|
|
|
logger.info("StoredSellerServiceImpl isStoredSeller uid is {} ",uid);
|
|
|
StoredSeller storedSeller = cacheService.getStoredSeller(uid);
|
|
|
logger.info("StoredSellerServiceImpl valid store seller uid is {} ,redis info is {} ",uid,storedSeller);
|
|
|
if(null != storedSeller){
|
|
|
return storedSeller;
|
|
|
}
|
|
|
|
|
|
//如果不存在,则从数据库获取
|
|
|
storedSeller= storedSellerDao.selectValidByUid(uid);
|
|
|
logger.info("StoredSellerServiceImpl get valid store seller uid is {} ,database info is {} ",uid,storedSeller);
|
|
|
if(storedSeller!=null){
|
|
|
//保存到redis
|
|
|
cacheService.setStoredSeller( storedSeller);
|
|
|
}
|
|
|
return storedSeller;
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void addUserAsStoredSeller(Integer uid){
|
|
|
logger.info("StoredSellerServiceImpl addUserAsStoredSeller enter uid is {} ",uid);
|
|
|
LocalDateTime now=LocalDateTime.now();
|
|
|
long ts=now.toEpochSecond(ZoneOffset.of("+8"));
|
|
|
StoredSeller storedSeller=new StoredSeller();
|
|
|
storedSeller.setUid(uid);
|
|
|
storedSeller.setValidStatus(1);
|
|
|
storedSeller.setCreateTime(ts);
|
|
|
storedSeller.setUpdateTime(ts);
|
|
|
logger.info("StoredSellerServiceImpl addUserAsStoredSeller insert uid is {} , storedSeller {} ",uid,storedSeller);
|
|
|
int num=storedSellerDao.insert(storedSeller);
|
|
|
if(num<0){
|
|
|
logger.error("StoredSellerServiceImpl addUserAsStoredSeller error uid is {} , storedSeller {} ,insert num {} ",uid,storedSeller,num);
|
|
|
throw new ServiceException(400,"更新入驻用户信息错误");
|
|
|
}
|
|
|
|
|
|
//保存到redis
|
|
|
cacheService.setStoredSeller( storedSeller);
|
|
|
|
|
|
|
|
|
}
|
|
|
} |
...
|
...
|
|