Authored by chenchao

Merge branch 'hotfix_多次入驻申请设计不合理' into test6.8.6

@@ -75,10 +75,11 @@ public class SellerEnterApplyService { @@ -75,10 +75,11 @@ public class SellerEnterApplyService {
75 * @param uid 75 * @param uid
76 * @param orderCode 76 * @param orderCode
77 */ 77 */
78 - public void applySuperEntry(Integer uid, Long orderCode, EntrySellerType targetEST){ 78 + public SellerEnterApply applySuperEntry(Integer uid, Long orderCode, EntrySellerType targetEST){
79 logger.info("in applySuperEntry uid {} orderCode {} targetEST {}", uid, orderCode, targetEST); 79 logger.info("in applySuperEntry uid {} orderCode {} targetEST {}", uid, orderCode, targetEST);
80 -  
81 - if (Objects.isNull(orderCode)){ 80 + SellerEnterApply sea = null;
  81 + boolean orderCodeIsNull;
  82 + if (orderCodeIsNull = Objects.isNull(orderCode)){
82 logger.warn("in applySuperEntry uid {} orderCode is null targetEST {}", uid, targetEST); 83 logger.warn("in applySuperEntry uid {} orderCode is null targetEST {}", uid, targetEST);
83 //throw new UfoServiceException(400, "orderCode is null"); 84 //throw new UfoServiceException(400, "orderCode is null");
84 } 85 }
@@ -90,7 +91,7 @@ public class SellerEnterApplyService { @@ -90,7 +91,7 @@ public class SellerEnterApplyService {
90 ||Objects.equals(targetEST, EntrySellerType.SPECIAL_SUPER)){ 91 ||Objects.equals(targetEST, EntrySellerType.SPECIAL_SUPER)){
91 logger.warn("in applySuperEntry no need apply uid {} orderCode {} targetEST {}", 92 logger.warn("in applySuperEntry no need apply uid {} orderCode {} targetEST {}",
92 uid, orderCode, targetEST); 93 uid, orderCode, targetEST);
93 - return; 94 + return sea;
94 } 95 }
95 96
96 SellerWrapper sellerWrapper = new SellerWrapper(uid,logger) 97 SellerWrapper sellerWrapper = new SellerWrapper(uid,logger)
@@ -105,7 +106,7 @@ public class SellerEnterApplyService { @@ -105,7 +106,7 @@ public class SellerEnterApplyService {
105 if(Objects.equals(estCode=currentEST.getCode(), targetEST.getCode())){ 106 if(Objects.equals(estCode=currentEST.getCode(), targetEST.getCode())){
106 logger.info("applySuperEntry own same level uid {} orderCode {} current EST {} target EST {}", 107 logger.info("applySuperEntry own same level uid {} orderCode {} current EST {} target EST {}",
107 uid, orderCode, currentEST, targetEST); 108 uid, orderCode, currentEST, targetEST);
108 - return; 109 + return sea;
109 } 110 }
110 111
111 StoredSeller storedSeller = sellerWrapper.getStoredSeller(); 112 StoredSeller storedSeller = sellerWrapper.getStoredSeller();
@@ -128,22 +129,26 @@ public class SellerEnterApplyService { @@ -128,22 +129,26 @@ public class SellerEnterApplyService {
128 condition.setUid(uid); 129 condition.setUid(uid);
129 condition.setPreEnterType(estCode); 130 condition.setPreEnterType(estCode);
130 condition.setEnterType(targetEST.getCode()); 131 condition.setEnterType(targetEST.getCode());
  132 + //查询 当前身份和目标身份一致的申请
131 List<SellerEnterApply> seaList = sellerEnterApplyMapper.selectByUOCET(condition); 133 List<SellerEnterApply> seaList = sellerEnterApplyMapper.selectByUOCET(condition);
132 //是否已经申请 134 //是否已经申请
133 if (CollectionUtils.isNotEmpty(seaList)){ 135 if (CollectionUtils.isNotEmpty(seaList)){
134 //有记录 136 //有记录
135 SellerEnterApply msea = findSellerEnterApply(uid, orderCode, targetEST, seaList); 137 SellerEnterApply msea = findSellerEnterApply(uid, orderCode, targetEST, seaList);
136 - addOrUpdate(msea, uid, orderCode, currentEST, targetEST); 138 + sea = addOrUpdate(msea, uid, orderCode, currentEST, targetEST);
137 }else{ 139 }else{
138 //没有申请过 => 第一次申请 140 //没有申请过 => 第一次申请
139 logger.info("applySuperEntry no one apply of waiting audit then add new, uid {} orderCode {} targetEST {} ", 141 logger.info("applySuperEntry no one apply of waiting audit then add new, uid {} orderCode {} targetEST {} ",
140 uid, orderCode, targetEST); 142 uid, orderCode, targetEST);
141 //create new apply 143 //create new apply
142 - add(uid, orderCode, currentEST, targetEST); 144 + sea = add(uid, orderCode, currentEST, targetEST);
143 } 145 }
  146 + return sea;
144 } 147 }
145 148
146 - private int addOrUpdate(SellerEnterApply msea,Integer uid, Long orderCode, 149 + private SellerEnterApply addOrUpdate(SellerEnterApply msea,
  150 + Integer uid,
  151 + Long orderCode,
147 EntrySellerType currentEST, EntrySellerType targetEST){ 152 EntrySellerType currentEST, EntrySellerType targetEST){
148 if (Objects.isNull(msea)){ 153 if (Objects.isNull(msea)){
149 logger.info("addOrUpdate no one apply of waiting audit then add new, uid {} orderCode {} targetEST {} ", 154 logger.info("addOrUpdate no one apply of waiting audit then add new, uid {} orderCode {} targetEST {} ",
@@ -154,7 +159,7 @@ public class SellerEnterApplyService { @@ -154,7 +159,7 @@ public class SellerEnterApplyService {
154 //update matched one 159 //update matched one
155 logger.info("addOrUpdate one apply waiting audit then update uid {} orderCode {} targetEST {} matched SellerEnterApply {}", 160 logger.info("addOrUpdate one apply waiting audit then update uid {} orderCode {} targetEST {} matched SellerEnterApply {}",
156 uid, orderCode, targetEST, msea); 161 uid, orderCode, targetEST, msea);
157 - return update(msea.getId(),orderCode, currentEST, targetEST); 162 + return update(msea);
158 } 163 }
159 } 164 }
160 165
@@ -173,22 +178,27 @@ public class SellerEnterApplyService { @@ -173,22 +178,27 @@ public class SellerEnterApplyService {
173 seac.setUid(uid); 178 seac.setUid(uid);
174 seac.setOrderCode(orderCode); 179 seac.setOrderCode(orderCode);
175 List<SellerEnterApply> seaList = sellerEnterApplyMapper.selectByUOCET(seac); 180 List<SellerEnterApply> seaList = sellerEnterApplyMapper.selectByUOCET(seac);
176 - doAudit(uid, orderCode, left, seaList); 181 + if (seaList.size() > 1) {
  182 + logger.warn("in audit one orderCode mapped multiple apply,uid {} orderCode {}", uid, orderCode);
  183 + }
  184 + SellerEnterApply msea = seaList.get(0);
  185 + doAudit(uid, orderCode, left, msea);
177 } 186 }
178 187
179 188
180 - public void doAudit(int uid, Long orderCode, BigDecimal left, List<SellerEnterApply> seaList){ 189 + private void doAudit(int uid, Long orderCode, BigDecimal left, SellerEnterApply msea){
181 190
182 //卖家包装类 191 //卖家包装类
183 SellerWrapper sellerWrapper = new SellerWrapper(uid,logger) 192 SellerWrapper sellerWrapper = new SellerWrapper(uid,logger)
184 .storedSellerDataSource(storedSellerMapper::selectByUid) 193 .storedSellerDataSource(storedSellerMapper::selectByUid)
185 .addSpecialSuperFunc(sellerService::isSpecialSuper) 194 .addSpecialSuperFunc(sellerService::isSpecialSuper)
186 .buildBase(); 195 .buildBase();
187 - upgradeLevel(sellerWrapper, orderCode, left, seaList); 196 + upgradeLevel(sellerWrapper, orderCode, left, msea);
188 } 197 }
189 198
190 public void upgradeLevel(SellerWrapper sellerWrapper, 199 public void upgradeLevel(SellerWrapper sellerWrapper,
191 - Long orderCode, BigDecimal left, List<SellerEnterApply> seaList){ 200 + Long orderCode, BigDecimal left,
  201 + SellerEnterApply msea){
192 int uid = sellerWrapper.getUid(); 202 int uid = sellerWrapper.getUid();
193 //是否有申请记录 203 //是否有申请记录
194 //有两种: 204 //有两种:
@@ -197,29 +207,41 @@ public class SellerEnterApplyService { @@ -197,29 +207,41 @@ public class SellerEnterApplyService {
197 // 1.2 普通充值没有申请记录 207 // 1.2 普通充值没有申请记录
198 // 2. client 直接升级,根据请求的目标身份 208 // 2. client 直接升级,根据请求的目标身份
199 //existApply 为false 只会是普通充值订单 209 //existApply 为false 只会是普通充值订单
200 - boolean existApply = CollectionUtils.isNotEmpty(seaList); 210 + boolean existApply = Objects.nonNull(msea);
201 logger.info("in upgradeLevel uid {} orderCode {} left wallet {} existApply {}", 211 logger.info("in upgradeLevel uid {} orderCode {} left wallet {} existApply {}",
202 uid, orderCode, left, existApply ); 212 uid, orderCode, left, existApply );
203 if (existApply){ 213 if (existApply){
204 - processApplyOrder(sellerWrapper, left, orderCode, seaList); 214 + processApplyOrder(sellerWrapper, left, orderCode, msea);
205 }else { 215 }else {
206 processCommonChargeOrder(sellerWrapper, orderCode); 216 processCommonChargeOrder(sellerWrapper, orderCode);
207 } 217 }
208 } 218 }
209 219
210 /** 220 /**
  221 + * 当卖家钱包余额充足时,直接升级
  222 + * @param sellerWrapper
  223 + * @param orderCode
  224 + * @param targetEST
  225 + */
  226 + public void upgradeLevelIfFatWallet(SellerWrapper sellerWrapper, Long orderCode,
  227 + EntrySellerType targetEST){
  228 + Integer uid = sellerWrapper.getUid();
  229 + BigDecimal leftInWallet = sellerWrapper.getLeftInWallet();
  230 + SellerEnterApply sea = this.applySuperEntry(uid, orderCode, targetEST);
  231 + this.upgradeLevel(sellerWrapper, orderCode, leftInWallet, sea);
  232 + }
  233 +
  234 + /**
211 * 充值订单处理 235 * 充值订单处理
212 * @param sellerWrapper 236 * @param sellerWrapper
213 * @param left 237 * @param left
214 * @param orderCode 238 * @param orderCode
215 - * @param seaList 239 + * @param msea
216 */ 240 */
217 private void processApplyOrder(SellerWrapper sellerWrapper,BigDecimal left, 241 private void processApplyOrder(SellerWrapper sellerWrapper,BigDecimal left,
218 - Long orderCode, List<SellerEnterApply> seaList){ 242 + Long orderCode, SellerEnterApply msea){
219 int uid = sellerWrapper.getUid(); 243 int uid = sellerWrapper.getUid();
220 - if (seaList.size() > 1) {  
221 - logger.warn("in upgradeLevel one orderCode mapped multiple apply,uid {} orderCode {}", uid, orderCode);  
222 - } 244 +
223 //持久化的入驻信息 245 //持久化的入驻信息
224 StoredSeller pss = sellerWrapper.getStoredSeller(); 246 StoredSeller pss = sellerWrapper.getStoredSeller();
225 boolean noStoredSeller = Objects.isNull(pss); 247 boolean noStoredSeller = Objects.isNull(pss);
@@ -230,7 +252,6 @@ public class SellerEnterApplyService { @@ -230,7 +252,6 @@ public class SellerEnterApplyService {
230 //身份等级配置 252 //身份等级配置
231 Map<EntrySellerType,EntryThreshold> estMap = metaConfigService.getEntryThreshold(); 253 Map<EntrySellerType,EntryThreshold> estMap = metaConfigService.getEntryThreshold();
232 254
233 - SellerEnterApply msea = seaList.get(0);  
234 //目标身份 255 //目标身份
235 EntrySellerType targetEst = EntrySellerType.getEntrySellerType(msea.getEnterType()); 256 EntrySellerType targetEst = EntrySellerType.getEntrySellerType(msea.getEnterType());
236 //申请是否已经通过 257 //申请是否已经通过
@@ -366,7 +387,7 @@ public class SellerEnterApplyService { @@ -366,7 +387,7 @@ public class SellerEnterApplyService {
366 return result; 387 return result;
367 } 388 }
368 389
369 - public int doUpgradeSuper(EntrySellerType targetEst,Integer currentLevel, Integer level, Integer uid){ 390 + private int doUpgradeSuper(EntrySellerType targetEst,Integer currentLevel, Integer level, Integer uid){
370 logger.info("doUpgradeSuper uid {} targetEst {} currentLevel {} target level {}", 391 logger.info("doUpgradeSuper uid {} targetEst {} currentLevel {} target level {}",
371 uid, targetEst, currentLevel, level); 392 uid, targetEst, currentLevel, level);
372 SellerLevelFuncBo slfb = sellerFuncService.getSellerLevelFunc(targetEst.getCode(), level); 393 SellerLevelFuncBo slfb = sellerFuncService.getSellerLevelFunc(targetEst.getCode(), level);
@@ -376,7 +397,7 @@ public class SellerEnterApplyService { @@ -376,7 +397,7 @@ public class SellerEnterApplyService {
376 } 397 }
377 398
378 399
379 - public void processWithLevel(Integer currentLevel, Integer targetLevel, Integer uid){ 400 + private void processWithLevel(Integer currentLevel, Integer targetLevel, Integer uid){
380 logger.info("processWithLevel currentLevel {} targetLevel {} uid {}",currentLevel, targetLevel, uid); 401 logger.info("processWithLevel currentLevel {} targetLevel {} uid {}",currentLevel, targetLevel, uid);
381 if (SellerConfig.ENTER_TYPE_DEFAULT_LEVEL == currentLevel || 402 if (SellerConfig.ENTER_TYPE_DEFAULT_LEVEL == currentLevel ||
382 currentLevel== SuperEnterStageLevel.DISABLE.getCode()){ 403 currentLevel== SuperEnterStageLevel.DISABLE.getCode()){
@@ -444,18 +465,30 @@ public class SellerEnterApplyService { @@ -444,18 +465,30 @@ public class SellerEnterApplyService {
444 } 465 }
445 466
446 467
447 -  
448 -  
449 - private SellerEnterApply findSellerEnterApply(Integer uid, Long orderCode, EntrySellerType targetEST,List<SellerEnterApply> seaList){ 468 + /**
  469 + * 需要排除已经通过申请,和订单号不匹配
  470 + * @param uid
  471 + * @param orderCode
  472 + * @param targetEST
  473 + * @param seaList 只是当前和目标身份匹配出来的申请集合
  474 + * @return
  475 + */
  476 + private SellerEnterApply findSellerEnterApply(Integer uid,
  477 + Long orderCode,
  478 + EntrySellerType targetEST,
  479 + List<SellerEnterApply> seaList){
450 SellerEnterApply msea = null; 480 SellerEnterApply msea = null;
451 for(SellerEnterApply sea : seaList){ 481 for(SellerEnterApply sea : seaList){
452 // 异常情况:已经通过 482 // 异常情况:已经通过
453 if (Objects.equals(sea.getStatus(), SellerEnterApplyStatus.PASS.getCode())){ 483 if (Objects.equals(sea.getStatus(), SellerEnterApplyStatus.PASS.getCode())){
454 logger.warn("findSellerEnterApply pass one apply, uid {} orderCode {} targetEST {} SellerEnterApply {}", 484 logger.warn("findSellerEnterApply pass one apply, uid {} orderCode {} targetEST {} SellerEnterApply {}",
455 uid, orderCode, targetEST, sea); 485 uid, orderCode, targetEST, sea);
  486 + continue;
456 } 487 }
457 - // 没有通过  
458 - if (Objects.equals(sea.getStatus(),SellerEnterApplyStatus.WAITING_AUDIT.getCode())){ 488 + // 没有通过 + 充值订单号已申请
  489 + boolean waitingAudit = Objects.equals(sea.getStatus(),SellerEnterApplyStatus.WAITING_AUDIT.getCode());
  490 + boolean matchOrderCode = Objects.nonNull(orderCode) && orderCode.equals(sea.getOrderCode());
  491 + if (waitingAudit && matchOrderCode){
459 msea = sea; 492 msea = sea;
460 logger.info("findSellerEnterApply one apply waiting audit, uid {} orderCode {} targetEST {} matched SellerEnterApply {}", 493 logger.info("findSellerEnterApply one apply waiting audit, uid {} orderCode {} targetEST {} matched SellerEnterApply {}",
461 uid, orderCode, targetEST, msea); 494 uid, orderCode, targetEST, msea);
@@ -465,6 +498,11 @@ public class SellerEnterApplyService { @@ -465,6 +498,11 @@ public class SellerEnterApplyService {
465 return msea; 498 return msea;
466 } 499 }
467 500
  501 +
  502 +
  503 +
  504 +
  505 +
468 public int passApply(SellerEnterApply sea){ 506 public int passApply(SellerEnterApply sea){
469 if (Objects.equals(SellerEnterApplyStatus.PASS.getCode(), sea.getStatus())){ 507 if (Objects.equals(SellerEnterApplyStatus.PASS.getCode(), sea.getStatus())){
470 logger.info("passApply apply was passed, sea {}", sea); 508 logger.info("passApply apply was passed, sea {}", sea);
@@ -478,19 +516,20 @@ public class SellerEnterApplyService { @@ -478,19 +516,20 @@ public class SellerEnterApplyService {
478 return sellerEnterApplyMapper.updateByPrimaryKeySelective(wpOfSea); 516 return sellerEnterApplyMapper.updateByPrimaryKeySelective(wpOfSea);
479 } 517 }
480 518
481 - public int update(Integer id,Long orderCode, EntrySellerType currentEST, EntrySellerType targetEST){ 519 + private SellerEnterApply update(SellerEnterApply msea){
  520 + Integer id = msea.getId();
482 SellerEnterApply wpOfSea = new SellerEnterApply(); 521 SellerEnterApply wpOfSea = new SellerEnterApply();
483 wpOfSea.setId(id); 522 wpOfSea.setId(id);
484 Integer cdt = DateUtil.getCurrentTimeSecond(); 523 Integer cdt = DateUtil.getCurrentTimeSecond();
485 wpOfSea.setUpdateTime(cdt); 524 wpOfSea.setUpdateTime(cdt);
486 - wpOfSea.setOrderCode(orderCode);  
487 - wpOfSea.setPreEnterType(currentEST.getCode());  
488 - wpOfSea.setEnterType(targetEST.getCode());  
489 - return sellerEnterApplyMapper.updateByPrimaryKeySelective(wpOfSea); 525 + if(sellerEnterApplyMapper.updateByPrimaryKeySelective(wpOfSea) > 0){
  526 + msea.setUpdateTime(cdt);
  527 + }
  528 + return msea;
490 } 529 }
491 530
492 531
493 - public int add(int uid, Long orderCode, EntrySellerType currentEST, EntrySellerType targetEST){ 532 + private SellerEnterApply add(int uid, Long orderCode, EntrySellerType currentEST, EntrySellerType targetEST){
494 SellerEnterApply wpOfSea = new SellerEnterApply(); 533 SellerEnterApply wpOfSea = new SellerEnterApply();
495 wpOfSea.setUid(uid); 534 wpOfSea.setUid(uid);
496 wpOfSea.setOrderCode(orderCode); 535 wpOfSea.setOrderCode(orderCode);
@@ -500,6 +539,7 @@ public class SellerEnterApplyService { @@ -500,6 +539,7 @@ public class SellerEnterApplyService {
500 wpOfSea.setCreateTime(cdt); 539 wpOfSea.setCreateTime(cdt);
501 wpOfSea.setUpdateTime(cdt); 540 wpOfSea.setUpdateTime(cdt);
502 wpOfSea.setStatus(SellerEnterApplyStatus.WAITING_AUDIT.getCode()); 541 wpOfSea.setStatus(SellerEnterApplyStatus.WAITING_AUDIT.getCode());
503 - return sellerEnterApplyMapper.insertSelective(wpOfSea); 542 + sellerEnterApplyMapper.insertSelective(wpOfSea);
  543 + return wpOfSea;
504 } 544 }
505 } 545 }
@@ -215,6 +215,7 @@ public class SellerService { @@ -215,6 +215,7 @@ public class SellerService {
215 } 215 }
216 //left enter type is 入驻非超级 216 //left enter type is 入驻非超级
217 BigDecimal leftInWallet = merchantOrderPaymentService.getWalletLeftAmount(uid); 217 BigDecimal leftInWallet = merchantOrderPaymentService.getWalletLeftAmount(uid);
  218 + sellerWrapper.setLeftInWallet(leftInWallet);
218 //前提:1. 当前卖家是 普通个人 or 入驻非超级 2. 钱包余额大于等于超级的阈值 219 //前提:1. 当前卖家是 普通个人 or 入驻非超级 2. 钱包余额大于等于超级的阈值
219 Map<EntrySellerType,EntryThreshold> entryThreshold = getEntryThreshold(); 220 Map<EntrySellerType,EntryThreshold> entryThreshold = getEntryThreshold();
220 EntryThreshold set = entryThreshold.get(EntrySellerType.SUPER_ENTRY); 221 EntryThreshold set = entryThreshold.get(EntrySellerType.SUPER_ENTRY);
@@ -224,14 +225,7 @@ public class SellerService { @@ -224,14 +225,7 @@ public class SellerService {
224 //申请记录(新增 or 修改) 入驻卖家(enter_type level_func 功能菜单) 225 //申请记录(新增 or 修改) 入驻卖家(enter_type level_func 功能菜单)
225 if (isFatWallet){ 226 if (isFatWallet){
226 //insert apply 227 //insert apply
227 - sellerEnterApplyService.applySuperEntry(uid, null, targetEST);  
228 - //  
229 - SellerEnterApply seac = new SellerEnterApply();  
230 - seac.setUid(uid);  
231 - seac.setPreEnterType(currentEST.getCode());  
232 - seac.setEnterType(targetEST.getCode());  
233 - List<SellerEnterApply> seaList = sellerEnterApplyMapper.selectByUOCET(seac);  
234 - sellerEnterApplyService.upgradeLevel(sellerWrapper, null, leftInWallet, seaList); 228 + sellerEnterApplyService.upgradeLevelIfFatWallet(sellerWrapper, null, targetEST);
235 } 229 }
236 return isFatWallet; 230 return isFatWallet;
237 } 231 }
@@ -8,8 +8,10 @@ import com.yohoufo.common.exception.UfoServiceException; @@ -8,8 +8,10 @@ import com.yohoufo.common.exception.UfoServiceException;
8 import com.yohoufo.dal.order.model.SellerLevelFunc; 8 import com.yohoufo.dal.order.model.SellerLevelFunc;
9 import com.yohoufo.dal.order.model.StoredSeller; 9 import com.yohoufo.dal.order.model.StoredSeller;
10 import lombok.Getter; 10 import lombok.Getter;
  11 +import lombok.Setter;
11 import org.slf4j.Logger; 12 import org.slf4j.Logger;
12 13
  14 +import java.math.BigDecimal;
13 import java.util.Objects; 15 import java.util.Objects;
14 import java.util.function.Function; 16 import java.util.function.Function;
15 17
@@ -22,6 +24,9 @@ public class SellerWrapper { @@ -22,6 +24,9 @@ public class SellerWrapper {
22 @Getter 24 @Getter
23 Integer uid; 25 Integer uid;
24 26
  27 + @Getter@Setter
  28 + BigDecimal leftInWallet;
  29 +
25 private Logger logger; 30 private Logger logger;
26 31
27 Function<Integer,StoredSeller> storedSellerFunc; 32 Function<Integer,StoredSeller> storedSellerFunc;