Authored by qinchao

商家入驻接口

package com.yohoufo.dal.user;
import com.yohoufo.dal.user.model.StoredSeller;
public interface IStoredSellerDao {
//获取生效的信息
StoredSeller selectValidByUid(int uid);
int insert(StoredSeller storedSeller);
}
... ...
package com.yohoufo.dal.user.model;
import lombok.Data;
import lombok.ToString;
@Data
@ToString
public class StoredSeller {
//主键
private Integer id;
//uid ,索引
private Integer uid;
//生效状态:1 生效 ; 0 不生效
private Integer validStatus;
private long createTime;
private long updateTime;
}
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yohoufo.dal.user.IStoredSellerDao" >
<resultMap id="BaseResultMap" type="com.yohoufo.dal.user.model.StoredSeller" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="uid" property="uid" jdbcType="INTEGER" />
<result column="valid_status" property="validStatus" jdbcType="INTEGER" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, uid, valid_status, create_time, update_time
</sql>
<select id="selectValidByUid" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from stored_seller
where uid = #{uid} and valid_status = 1
order by id desc limit 1
</select>
<insert id="insert" parameterType="com.yohoufo.dal.user.model.StoredSeller" >
insert into stored_seller (uid, valid_status, create_time, update_time)
values (#{uid},#{validStatus},
#{createTime},#{updateTime})
</insert>
</mapper>
\ No newline at end of file
... ...
... ... @@ -20,6 +20,8 @@ public enum CacheKeyEnum {
ZHI_MA_CERT_KEY("ufo:user:zhiMaCert:","芝麻认证信息", 2, TimeUnit.HOURS),
STORED_SELLER_KEY("ufo:user:storedSeller:","商家入驻信息", 2, TimeUnit.HOURS),
USER_PRODUCT_FAVORITE_ZSET_KEY("ufo:user:product:favorite:","用户商品收藏集合", 180, TimeUnit.DAYS),
;
... ...
... ... @@ -5,6 +5,7 @@ import com.yoho.core.redis.cluster.operations.nosync.YHRedisTemplate;
import com.yoho.core.redis.cluster.operations.nosync.YHValueOperations;
import com.yoho.core.redis.cluster.operations.nosync.YHZSetOperations;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yohoufo.dal.user.model.StoredSeller;
import com.yohoufo.dal.user.model.UserAuthorizeInfo;
import com.yohoufo.dal.user.model.UserFavorite;
import com.yohoufo.dal.user.model.ZhiMaCert;
... ... @@ -52,6 +53,9 @@ public class CacheService {
return RedisKeyBuilder.newInstance().appendFixed(CacheKeyEnum.ZHI_MA_CERT_KEY.getCacheKey()).appendVar(uid);
}
public static RedisKeyBuilder getStoredSellerRedisKeyBuilder(Integer uid){
return RedisKeyBuilder.newInstance().appendFixed(CacheKeyEnum.STORED_SELLER_KEY.getCacheKey()).appendVar(uid);
}
/**************************************************************************
* 商品收藏相关
*************************************************************************/
... ... @@ -199,6 +203,17 @@ public class CacheService {
set(getZhiMaCertRedisKeyBuilder(zhiMaCert.getUid()),zhiMaCert,CacheKeyEnum.ZHI_MA_CERT_KEY.getDefaultExpireTime(),CacheKeyEnum.ZHI_MA_CERT_KEY.getTimeUnit());
}
/**************************************************************************
* 商家入驻相关
*************************************************************************/
public StoredSeller getStoredSeller(Integer uid){
return get(getStoredSellerRedisKeyBuilder(uid),StoredSeller.class);
}
public void setStoredSeller(StoredSeller storedSeller){
set(getStoredSellerRedisKeyBuilder(storedSeller.getUid()),storedSeller,CacheKeyEnum.STORED_SELLER_KEY.getDefaultExpireTime(),CacheKeyEnum.STORED_SELLER_KEY.getTimeUnit());
}
/**************************************************************************
* 通用
... ...
... ... @@ -109,20 +109,6 @@ public class RealNameAuthorizeController {
}
/**
* 是否入住商户
*/
@RequestMapping(params = "method=ufo.user.isStoredSeller")
public ApiResponse isStoredSeller(RealNameAuthorizeReqVO reqVO) throws GatewayException {
logger.info("enter realNameAuthorize.isStoredSeller param reqVO is {}", reqVO);
//(1) 优先校验请求的参数
if (reqVO == null || reqVO.getUid() <=0 ){
throw new GatewayException(400, "参数错误,uid不存在!");
}
return new ApiResponse(true);
}
/**
* 是否已经芝麻认证
*/
@RequestMapping(params = "method=ufo.user.isRealNameCert")
... ...
package com.yohoufo.user.controller.passport;
import com.yoho.tools.common.beans.ApiResponse;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
import com.yohoufo.user.service.IStoredSellerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 入驻商户接口
* Created by craig.qin on 2018/9/11.
*/
@RestController
public class StoredSellerController {
private Logger logger = LoggerFactory.getLogger(StoredSellerController.class);
@Autowired
private IStoredSellerService storedSellerService;
/**
* 是否入驻商户
*/
@RequestMapping(params = "method=ufo.user.isStoredSeller")
public ApiResponse isStoredSeller(RealNameAuthorizeReqVO reqVO) throws GatewayException {
logger.info("enter StoredSellerController isStoredSeller param reqVO is {}", reqVO);
//(1) 优先校验请求的参数
if (reqVO == null || reqVO.getUid() <=0 ){
throw new GatewayException(400, "参数错误,uid不存在!");
}
boolean isStoredSeller=storedSellerService.isStoredSeller(reqVO.getUid());
return new ApiResponse(isStoredSeller);
}
/**
* 更新商户为入驻商户
*/
@RequestMapping(params = "method=ufo.user.updateAsStoredSeller")
public ApiResponse updateAsStoredSeller(RealNameAuthorizeReqVO reqVO) throws GatewayException {
logger.info("enter StoredSellerController updateAsStoredSeller param reqVO is {}", reqVO);
//(1) 优先校验请求的参数
if (reqVO == null || reqVO.getUid() <=0 ){
throw new GatewayException(400, "参数错误,uid不存在!");
}
return new ApiResponse(true);
}
}
... ...
package com.yohoufo.user.service;
public interface IStoredSellerService {
boolean isStoredSeller(Integer uid);
void addUserAsStoredSeller(Integer uid);
}
... ...
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);
}
}
... ...