Authored by chenchao

add apply 2 enter seller

... ... @@ -2,6 +2,8 @@ package com.yohoufo.dal.order;
import com.yohoufo.dal.order.model.SellerEnterApply;
import java.util.List;
public interface SellerEnterApplyMapper {
int deleteByPrimaryKey(Integer id);
... ... @@ -14,4 +16,6 @@ public interface SellerEnterApplyMapper {
int updateByPrimaryKeySelective(SellerEnterApply record);
int updateByPrimaryKey(SellerEnterApply record);
List<SellerEnterApply> selectByUidEnterType(SellerEnterApply condition);
}
\ No newline at end of file
... ...
... ... @@ -20,6 +20,14 @@
from seller_enter_apply
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectByUidEnterType" parameterType="com.yohoufo.dal.order.model.SellerEnterApply" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from seller_enter_apply
where uid = #{uid,jdbcType=INTEGER}
enter_type = #{enterType,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from seller_enter_apply
where id = #{id,jdbcType=INTEGER}
... ...
package com.yohoufo.order.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yohobuy.ufo.model.order.common.EntrySellerType;
import com.yohobuy.ufo.model.order.common.MetaConfigKey;
import com.yohobuy.ufo.model.order.resp.EntryThreshold;
import com.yohoufo.common.cache.CacheClient;
import com.yohoufo.dal.order.MetaConfigMapper;
import com.yohoufo.dal.order.model.MetaConfig;
... ... @@ -15,6 +18,9 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
... ... @@ -58,4 +64,36 @@ public class MetaConfigService {
return bp;
}
private Map<EntrySellerType,EntryThreshold> buildDefaultEntryThreshold(){
Map<EntrySellerType,EntryThreshold> map = new HashMap<>(2);
EntryThreshold commonET = new EntryThreshold();
commonET.setEntrySellerType(EntrySellerType.COMMON);
commonET.setPrepaymentAmount(new BigDecimal(999));
map.put(commonET.getEntrySellerType(), commonET);
EntryThreshold superET = new EntryThreshold();
superET.setEntrySellerType(EntrySellerType.SUPER_ENTRY);
superET.setPrepaymentAmount(new BigDecimal(5000));
superET.setGoodsOnOffShelveAmount(new BigDecimal(3000));
superET.setHiddenGoodsAmount(new BigDecimal(1000));
map.put(superET.getEntrySellerType(), superET);
return map;
}
public Map<EntrySellerType,EntryThreshold> getEntryThreshold(){
Map<EntrySellerType,EntryThreshold> map = new HashMap<>(2);
String key = MetaConfigKey.SELLER_ENTER_THRESHOLD;
MetaConfig metaConfig = metaConfigMapper.selectByCode(key);
logger.info("in getEntryThreshold from DB {}", metaConfig);
String configVal = null;
try {
map = JSONObject.parseObject(configVal=metaConfig.getValue(), new TypeReference<Map<EntrySellerType,EntryThreshold>>(){});
}catch (Exception ex){
map = buildDefaultEntryThreshold();
logger.warn("in getEntryThreshold parse value fail,configVal {} use default {}", configVal, map, ex);
}
return map;
}
}
... ...
package com.yohoufo.order.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.yohobuy.ufo.model.order.bo.SellerBo;
import com.yohobuy.ufo.model.order.common.EntrySellerType;
import com.yohobuy.ufo.model.order.common.SellerEnterApplyStatus;
import com.yohobuy.ufo.model.order.common.SuperEnterStageLevel;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.SellerEnterApplyMapper;
import com.yohoufo.dal.order.model.SellerEnterApply;
import com.yohoufo.dal.order.model.StoredSeller;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
/**
* Created by chao.chen on 2019/1/14.
*/
@Service
public class SellerEnterApplyService {
private static final Logger logger = LoggerUtils.getSellerOrderLogger();
@Autowired
private SellerEnterApplyMapper sellerEnterApplyMapper;
/**
* 申请成为超级卖家
* 对于未支付的某一种身份申请做订单号替换
* @param uid
* @param orderCode
*/
public void applySuperEntry(Integer uid, Long orderCode, EntrySellerType targetEST){
logger.info("in applySuperEntry uid {} orderCode {} targetEST {}", uid, orderCode, targetEST);
if (Objects.isNull(orderCode)){
logger.warn("in applySuperEntry uid {} orderCode is null targetEST {}", uid, targetEST);
throw new UfoServiceException(400, "orderCode is null");
}
if (Objects.isNull(targetEST)){
logger.warn("in applySuperEntry uid {} orderCode {} targetEST is null", uid, orderCode);
throw new UfoServiceException(400, "EntrySellerType is null");
}
SellerService.SellerWrapper sellerWrapper = new SellerService().new SellerWrapper(uid).buildBase();
SellerBo sellerBo = sellerWrapper.build();
StoredSeller storedSeller = sellerWrapper.getStoredSeller();
EntrySellerType currentEST = sellerBo.getEntrySellerType();
//入驻卖家表没有记录
if (Objects.isNull(storedSeller)){
SellerEnterApply condition = new SellerEnterApply();
condition.setUid(uid);
condition.setEnterType(targetEST.getCode());
List<SellerEnterApply> seaList = sellerEnterApplyMapper.selectByUidEnterType(condition);
//是否已经申请
if (CollectionUtils.isNotEmpty(seaList)){
//有记录
SellerEnterApply msea = findSellerEnterApply(uid, orderCode, targetEST, seaList);
if (Objects.isNull(msea)){
logger.info("applySuperEntry no one apply of waiting audit then add new, uid {} orderCode {} targetEST {} ",
uid, orderCode, targetEST);
//create new apply
add(uid, orderCode, currentEST, targetEST);
}else{
//update matched one
logger.info("applySuperEntry one apply waiting audit then update uid {} orderCode {} targetEST {} matched SellerEnterApply {}",
uid, orderCode, targetEST, msea);
update(msea.getId(),orderCode, currentEST, targetEST);
}
}else{
//没有申请过 => 第一次申请
logger.info("applySuperEntry no one apply of waiting audit then add new, uid {} orderCode {} targetEST {} ",
uid, orderCode, targetEST);
//create new apply
add(uid, orderCode, currentEST, targetEST);
}
}
//入驻卖家表有记录
//检查合法标识
//检查当前身份
if (Objects.nonNull(storedSeller)){
sellerWrapper.buildSuperEnterStageLevel();
Integer entryType = sellerBo.getEntryTypeCode();
if(Objects.equals(entryType, EntrySellerType.SUPER_ENTRY.getCode())){
SuperEnterStageLevel sesl = sellerBo.getSuperEnterStageLevel();
}
}
}
private SellerEnterApply findSellerEnterApply(Integer uid, Long orderCode, EntrySellerType targetEST,List<SellerEnterApply> seaList){
SellerEnterApply msea = null;
for(SellerEnterApply sea : seaList){
// 异常情况:已经通过
if (Objects.equals(sea.getStatus(), SellerEnterApplyStatus.PASS.getCode())){
logger.warn("findSellerEnterApply pass one apply, uid {} orderCode {} targetEST {} SellerEnterApply {}",
uid, orderCode, targetEST, sea);
}
// 没有通过
if (Objects.equals(sea.getStatus(),SellerEnterApplyStatus.WAITING_AUDIT.getCode())){
msea = sea;
logger.info("findSellerEnterApply one apply waiting audit, uid {} orderCode {} targetEST {} matched SellerEnterApply {}",
uid, orderCode, targetEST, msea);
break;
}
}
return msea;
}
public int update(Integer id,Long orderCode, EntrySellerType currentEST, EntrySellerType targetEST){
SellerEnterApply wpOfSea = new SellerEnterApply();
wpOfSea.setId(id);
Integer cdt = DateUtil.getCurrentTimeSecond();
wpOfSea.setUpdateTime(cdt);
wpOfSea.setOrderCode(orderCode);
wpOfSea.setPreEnterType(currentEST.getCode());
wpOfSea.setEnterType(targetEST.getCode());
return sellerEnterApplyMapper.updateByPrimaryKeySelective(wpOfSea);
}
public int add(int uid, Long orderCode, EntrySellerType currentEST, EntrySellerType targetEST){
SellerEnterApply wpOfSea = new SellerEnterApply();
wpOfSea.setUid(uid);
wpOfSea.setOrderCode(orderCode);
wpOfSea.setPreEnterType(currentEST.getCode());
wpOfSea.setEnterType(targetEST.getCode());
Integer cdt = DateUtil.getCurrentTimeSecond();
wpOfSea.setCreateTime(cdt);
wpOfSea.setUpdateTime(cdt);
wpOfSea.setStatus(SellerEnterApplyStatus.WAITING_AUDIT.getCode());
return sellerEnterApplyMapper.insertSelective(wpOfSea);
}
}
... ...
package com.yohoufo.order.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.yohoufo.dal.order.model.StoredSeller;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Created by chao.chen on 2019/1/14.
*/
@Service
public class SellerFuncService {
private final Logger logger = LoggerUtils.getSellerOrderLogger();
public List getFuncList(StoredSeller pss){
Integer uid = pss.getUid();
String lflStr = pss.getLevelFuncList();
List<Integer> funcIds = null;
if (StringUtils.isNotBlank(lflStr)){
try {
funcIds = JSONObject.parseArray(lflStr, Integer.class);
}catch (Exception ex){
logger.warn("in getFuncList parse storedSeller.LevelFuncList fail uid {} funcIds {}",
uid, lflStr);
}
}
return funcIds;
}
}
... ...
package com.yohoufo.order.service.impl;
import com.yohobuy.ufo.model.enums.StoredSellerStatusEnum;
import com.yohobuy.ufo.model.order.bo.SellerBo;
import com.yohobuy.ufo.model.order.common.EntrySellerType;
import com.yohobuy.ufo.model.order.common.SellerEnterApplyStatus;
import com.yohobuy.ufo.model.order.common.SuperEnterStageLevel;
import com.yohobuy.ufo.model.order.resp.EntryThreshold;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.SellerEnterApplyMapper;
import com.yohoufo.dal.order.SellerLevelFuncMapper;
import com.yohoufo.dal.order.StoredSellerMapper;
import com.yohoufo.dal.order.SuperEntrySellerMapper;
import com.yohoufo.dal.order.model.SellerEnterApply;
import com.yohoufo.dal.order.model.SellerLevelFunc;
import com.yohoufo.dal.order.model.StoredSeller;
import com.yohoufo.dal.order.model.SuperEntrySeller;
import com.yohoufo.order.common.SurperEntrySellerStatus;
... ... @@ -14,6 +22,7 @@ import com.yohoufo.order.service.MerchantOrderPaymentService;
import com.yohoufo.order.service.cache.StoredSellerCacheService;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.user.cache.CacheKeyEnum;
import lombok.Getter;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -35,7 +44,7 @@ import java.util.stream.Collectors;
@Service
public class SellerService {
private final Logger logger = LoggerUtils.getSellerOrderLogger();
private static final Logger logger = LoggerUtils.getSellerOrderLogger();
@Autowired
private StoredSellerCacheService storedSellerCacheService;
... ... @@ -51,6 +60,11 @@ public class SellerService {
@Autowired
private MerchantOrderPaymentService merchantOrderPaymentService;
@Autowired
private SellerLevelFuncMapper sellerLevelFuncMapper;
/**更低出价提醒
* 1)当有新卖家出价成功或调价成功时,给所有正在出售该sku(尺码)的其他卖家推送一条消息(push+消息盒子)
*2)同一卖家的同一SKU 1小时内仅推送一条提醒(最先推送的那条)
... ... @@ -115,6 +129,87 @@ public class SellerService {
return false;
}
public class SellerWrapper{
@Getter
StoredSeller storedSeller;
Integer uid;
SellerBo sellerBo = new SellerBo();
SellerWrapper(int uid){
this.uid = uid;
this.sellerBo.setUid(uid);
}
SellerWrapper buildBase(){
logger.info("buildBase uid {}", uid);
if (uid <= 0){
logger.warn("buildBase illegal uid {}", uid);
throw new UfoServiceException(401, "uid is not legal");
}
EntrySellerType est = null;
//case 1 : not entry
this.storedSeller = storedSellerMapper.selectByUid(uid);
if (Objects.isNull(storedSeller)){
est = EntrySellerType.NOT_ENTRY;
logger.info("buildBase storedSeller is null uid {} entryType {}",
uid, est);
}else {
//case 2:exit entry
Integer validStatus = storedSeller.getValidStatus();
Integer entryType = storedSeller.getEntryType();
logger.info("buildBase uid {} validStatus {} entryType {}",
uid, validStatus, entryType);
if (Objects.equals(StoredSellerStatusEnum.quit.getId(), validStatus)) {
est = EntrySellerType.NOT_ENTRY;
} else if (isSpecialSuper(uid)) {
//case 3:valid ok and in white list
est = EntrySellerType.SPECIAL_SUPER;
} else if (Objects.equals(StoredSellerStatusEnum.entered.getId(), validStatus)) {
//case 4: left common or super
est = EntrySellerType.getEntrySellerType(entryType);
}
Integer funcId;
if (Objects.nonNull(funcId = storedSeller.getLevelFuncId())){
sellerBo.setLevelFuncId(funcId);
}
}
logger.info("buildBase uid {} EntrySellerType {}", uid, est);
if (Objects.nonNull(est)) {
sellerBo.setEntrySellerType(est);
sellerBo.setEntryTypeCode(est.getCode());
}
return this;
}
SellerWrapper buildSuperEnterStageLevel(){
EntrySellerType entrySellerType = sellerBo.getEntrySellerType();
if (Objects.nonNull(entrySellerType)){
//
Integer entryType = sellerBo.getEntryTypeCode();
if(Objects.equals(entryType, EntrySellerType.SUPER_ENTRY.getCode())){
Integer levelFuncId = sellerBo.getLevelFuncId();
if(Objects.nonNull(levelFuncId)){
SellerLevelFunc slf = sellerLevelFuncMapper.selectByPrimaryKey(levelFuncId);
logger.info("buildSuperEnterStageLevel SellerLevelFunc uid {} levelFuncId {} SellerLevelFunc {}",
uid, levelFuncId, slf);
Integer level = slf.getLevel();
SuperEnterStageLevel sesl = SuperEnterStageLevel.getSuperEnterStageLevel(level);
sellerBo.setSuperEnterStageLevel(sesl);
}
}
}
return this;
}
SellerBo build(){
return sellerBo;
}
}
/**
* 获取入驻商家类型
... ... @@ -123,46 +218,13 @@ public class SellerService {
*/
public EntrySellerType getEntrySellerType(int uid){
logger.info("getEntrySellerType uid {}", uid);
if (uid<=0){
logger.warn("getEntrySellerType illegal uid {}", uid);
throw new UfoServiceException(401, "uid is not legal");
}
EntrySellerType est = null;
//case 1 : not entry
StoredSeller storedSeller = storedSellerMapper.selectByUid(uid);
if (Objects.isNull(storedSeller)){
est = EntrySellerType.NOT_ENTRY;
logger.info("getEntrySellerType storedSeller is null uid {} entryType {}",
uid, est);
return est;
}
//case 2:exit entry
Integer validStatus = storedSeller.getValidStatus();
Integer entryType = storedSeller.getEntryType();
logger.info("getEntrySellerType uid {} validStatus {} entryType {}",
uid, validStatus, entryType);
if (Objects.equals(StoredSellerStatusEnum.quit.getId(), validStatus)){
est = EntrySellerType.NOT_ENTRY;
}else if(isSpecialSuper(uid)){
//case 3:valid ok and in white list
est = EntrySellerType.SPECIAL_SUPER;
}else if (Objects.equals(StoredSellerStatusEnum.entered.getId(), validStatus)){
//case 4: left common or super
est = EntrySellerType.getEntrySellerType(entryType);
}
SellerBo sellerBo = new SellerWrapper(uid).buildBase().build();
EntrySellerType est = sellerBo.getEntrySellerType();
logger.info("getEntrySellerType uid {} EntrySellerType {}", uid, est);
return est;
}
/**
* 申请成为超级卖家
* 对于未支付的某一种身份申请做订单号替换
* @param uid
* @param orderCode
*/
public void applySuperEntry(Integer uid, Long orderCode, EntrySellerType targetEST){
}
/**
* 支付成功后回调
... ... @@ -183,22 +245,11 @@ public class SellerService {
}
public Map<EntrySellerType,EntryThreshold> getEntryThreshold(){
Map<EntrySellerType,EntryThreshold> map = new HashMap<>(2);
EntryThreshold commonET = new EntryThreshold();
commonET.setEntrySellerType(EntrySellerType.COMMON);
commonET.setPrepaymentAmount(new BigDecimal(999));
map.put(commonET.getEntrySellerType(), commonET);
EntryThreshold superET = new EntryThreshold();
superET.setEntrySellerType(EntrySellerType.SUPER_ENTRY);
superET.setPrepaymentAmount(new BigDecimal(5000));
superET.setGoodsOnOffShelveAmount(new BigDecimal(3000));
superET.setHiddenGoodsAmount(new BigDecimal(1000));
map.put(superET.getEntrySellerType(), superET);
@Autowired
private MetaConfigService metaConfigService;
return map;
public Map<EntrySellerType,EntryThreshold> getEntryThreshold(){
return metaConfigService.getEntryThreshold();
}
public Boolean applySuperEnter(Integer uid){
... ...
... ... @@ -78,6 +78,9 @@ public class StoredSellerDepositServiceImpl implements IStoredSellerDepositServi
@Autowired
private SellerService sellerService;
@Autowired
private SellerEnterApplyService sellerEnterApplyService;
/**
* 充值保证金
*/
... ... @@ -195,7 +198,7 @@ public class StoredSellerDepositServiceImpl implements IStoredSellerDepositServi
}
private void markAsSuper(long orderCode, Integer uid, EntrySellerType sellerType) {
sellerService.applySuperEntry(uid, orderCode, sellerType);
sellerEnterApplyService.applySuperEntry(uid, orderCode, sellerType);
}
/**
... ...