From 60c17b3fec421a6d40f81301bebc25cdab33ad4c Mon Sep 17 00:00:00 2001 From: lin <642018748@qq.com> Date: Sat, 25 Mar 2023 12:26:53 +0800 Subject: [PATCH] fix business --- .../controller/WxBusinessController.java | 2 +- .../com/iformall/domain/po/WxScoreRules.java | 43 ++++----- .../impl/WxCreditHistoryServiceImpl.java | 2 +- .../service/impl/WxScoreRulesServiceImpl.java | 91 ++++++++++--------- 4 files changed, 67 insertions(+), 71 deletions(-) diff --git a/mallinkCApi/src/main/java/com/iformall/controller/WxBusinessController.java b/mallinkCApi/src/main/java/com/iformall/controller/WxBusinessController.java index fb0534eef..93be7abf1 100644 --- a/mallinkCApi/src/main/java/com/iformall/controller/WxBusinessController.java +++ b/mallinkCApi/src/main/java/com/iformall/controller/WxBusinessController.java @@ -22,7 +22,7 @@ public class WxBusinessController extends BaseController { @Autowired private WxBusinessService wxBusinessService; - @RedisCache + @RedisCache(expireTime = 600) @ApiOperation("业态全列表接口") @GetMapping("listAll") public ResultData listAll(Integer filter) { diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxScoreRules.java b/mallinkService/src/main/java/com/iformall/domain/po/WxScoreRules.java index 5a4cf1795..e5b9c84e4 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxScoreRules.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxScoreRules.java @@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.iformall.domain.po.base.BaseTenantEntity; import com.iformall.enums.EnumScoreType; +import com.iformall.utils.Constant; + import lombok.Data; import lombok.EqualsAndHashCode; @@ -30,22 +32,19 @@ public class WxScoreRules extends BaseTenantEntity { @TableField(exist = false) public static final int DEFAULT_SCALE = 10; + @TableField(exist = false) + public static final int DEFAULT_LIMIT = 0; + @TableField(exist = false) + public static final int DEFAULT_STEP = 1; + @TableField(exist = false) + public static final int DEFAULT_SCORE = 0; + @TableField(exist = false) private static final String scoreDefaultRules = "[" + "{\"id\":1,\"limit\":0,\"step\":1,\"score\":0 ,\"desc\":\"每日登陆\"}," + "{\"id\":2,\"childs\":[" + - " {\"businessId\":1,\"limit\":0,\"step\":1,\"score\":0 ,\"desc\":\"线上交易1元\"}," + - " {\"businessId\":2,\"limit\":0,\"step\":1,\"score\":0 ,\"desc\":\"线上交易1元\"}," + - " {\"businessId\":3,\"limit\":0,\"step\":1,\"score\":0 ,\"desc\":\"线上交易1元\"}," + - " {\"businessId\":4,\"limit\":0,\"step\":1,\"score\":0 ,\"desc\":\"线上交易1元\"}," + - " {\"businessId\":5,\"limit\":0,\"step\":1,\"score\":0 ,\"desc\":\"线上交易1元\"}," + - " {\"businessId\":7,\"limit\":0,\"step\":1,\"score\":0 ,\"desc\":\"线上交易1元\"}," + - " {\"businessId\":8,\"limit\":0,\"step\":1,\"score\":0 ,\"desc\":\"线上交易1元\"}," + - " {\"businessId\":9,\"limit\":0,\"step\":1,\"score\":0 ,\"desc\":\"线上交易1元\"}," + - " {\"businessId\":10,\"limit\":0,\"step\":1,\"score\":0 ,\"desc\":\"线上交易1元\"}," + - " {\"businessId\":11,\"limit\":0,\"step\":1,\"score\":0 ,\"desc\":\"线上交易1元\"}," + - " {\"businessId\":6,\"limit\":0,\"step\":1,\"score\":0 ,\"desc\":\"线上交易1元\"}" + + " {\"businessId\":"+Constant.default_business+",\"limit\":"+DEFAULT_LIMIT+",\"step\":"+DEFAULT_STEP+",\"score\":"+DEFAULT_SCORE+" ,\"desc\":\"线上交易1元\"}" + "]}," + "{\"id\":3,\"limit\":1,\"step\":1,\"score\":0,\"desc\":\"绑定车牌1个\"}," + "{\"id\":6,\"limit\":1,\"step\":1,\"score\":0,\"desc\":\"授权手机号\"}," + @@ -57,17 +56,7 @@ public class WxScoreRules extends BaseTenantEntity { "[" + // "{\"id\":1,\"limit\":0,\"step\":1,\"score\":0 ,\"desc\":\"每日登陆\"}," + "{\"id\":2,\"childs\":[" + - " {\"businessId\":1,\"limit\":0,\"step\":1,\"score\":0 ,\"desc\":\"线上交易1元\"}," + - " {\"businessId\":2,\"limit\":0,\"step\":1,\"score\":0 ,\"desc\":\"线上交易1元\"}," + - " {\"businessId\":3,\"limit\":0,\"step\":1,\"score\":0 ,\"desc\":\"线上交易1元\"}," + - " {\"businessId\":4,\"limit\":0,\"step\":1,\"score\":0 ,\"desc\":\"线上交易1元\"}," + - " {\"businessId\":5,\"limit\":0,\"step\":1,\"score\":0 ,\"desc\":\"线上交易1元\"}," + - " {\"businessId\":7,\"limit\":0,\"step\":1,\"score\":0 ,\"desc\":\"线上交易1元\"}," + - " {\"businessId\":8,\"limit\":0,\"step\":1,\"score\":0 ,\"desc\":\"线上交易1元\"}," + - " {\"businessId\":9,\"limit\":0,\"step\":1,\"score\":0 ,\"desc\":\"线上交易1元\"}," + - " {\"businessId\":10,\"limit\":0,\"step\":1,\"score\":0 ,\"desc\":\"线上交易1元\"}," + - " {\"businessId\":11,\"limit\":0,\"step\":1,\"score\":0 ,\"desc\":\"线上交易1元\"}," + - " {\"businessId\":6,\"limit\":0,\"step\":1,\"score\":0 ,\"desc\":\"线上交易1元\"}" + + " {\"businessId\":"+Constant.default_business+",\"limit\":"+DEFAULT_LIMIT+",\"step\":"+DEFAULT_STEP+",\"score\":"+DEFAULT_SCORE+" ,\"desc\":\"线上交易1元\"}" + "]}," + "{\"id\":3,\"limit\":1,\"step\":1,\"score\":0,\"desc\":\"绑定车牌1个\"}," + "{\"id\":6,\"limit\":1,\"step\":1,\"score\":0,\"desc\":\"授权手机号\"}," + @@ -148,11 +137,11 @@ public class WxScoreRules extends BaseTenantEntity { return null; } - public JSONObject getRuleObj(EnumScoreType scoreType) { - if (rules == null) + public static JSONObject getRuleObj(String ruleContent,EnumScoreType scoreType) { + if (ruleContent == null) return null; - List list = JSONObject.parseArray(rules, JSONObject.class); + List list = JSONObject.parseArray(ruleContent, JSONObject.class); if (list == null) return null; if (list.size() == 0) @@ -168,5 +157,9 @@ public class WxScoreRules extends BaseTenantEntity { return null; } + public static JSONObject createBusinessDefaultJson(Integer businessId) { + String json = "{\"businessId\":"+businessId+",\"limit\":"+DEFAULT_LIMIT+",\"step\":"+DEFAULT_STEP+",\"score\":"+DEFAULT_SCORE+" ,\"desc\":\"线上交易1元\"}" ; + return JSONObject.parseObject(json); + } } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCreditHistoryServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCreditHistoryServiceImpl.java index d0f3b3b35..2efd74dc6 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCreditHistoryServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCreditHistoryServiceImpl.java @@ -957,7 +957,7 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { WxScoreRules scoreRules = wxScoreRulesService.getCreditRules(record.getTenantId()); // 2. 获取成长值 by id - JSONObject payRule = scoreRules.getRuleObj(EnumScoreType.CONSUMPTION); + JSONObject payRule = WxScoreRules.getRuleObj(scoreRules.getRules(),EnumScoreType.CONSUMPTION); // 3. 获取成长值 by 业态 JSONObject busRule = null; JSONObject busRuleOther = null; diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxScoreRulesServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxScoreRulesServiceImpl.java index 6b336b509..e2ca3bf36 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxScoreRulesServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxScoreRulesServiceImpl.java @@ -9,19 +9,24 @@ import com.iformall.domain.po.base.TenantEntity; import com.iformall.enums.*; import com.iformall.exception.MallinkException; import com.iformall.mapper.*; +import com.iformall.service.WxBusinessService; import com.iformall.service.WxCUserService; import com.iformall.service.WxScoreRulesService; import com.iformall.utils.Constant; import org.apache.commons.lang3.StringUtils; +import org.apache.ibatis.javassist.bytecode.Descriptor.Iterator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Lazy; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; @Service public class WxScoreRulesServiceImpl implements WxScoreRulesService { @@ -44,6 +49,10 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { @Autowired WxMerchantMapper wxMerchantMapper; + + @Lazy + @Autowired + WxBusinessService wxBusinessService; @Override public void wxScoreRulesInit(String tenantId) { @@ -89,7 +98,7 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { List list = wxScoreRulesMapper.findList(scoreRules); if (list.size() > 0) { scoreRules = list.get(0); - scoreRules.setRules(getScoreRulesNew(scoreRules.getRules(),EnumScoreRules.SCORE)); + scoreRules.setRules(getScoreRulesNew(tenantEntity,scoreRules.getRules(),EnumScoreRules.SCORE)); } else { // 如果成长值规则不存在,启用默认值 @@ -108,49 +117,40 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { } //当成长值或积分规则新增时,将新增的数据一并返回给接口调用端 - private String getScoreRulesNew(String scoreRules,EnumScoreRules enumScoreRules){ - //getJSONObject(1) 为EnumScoreType.CONSUMPTION(2, "消费")的下标值 - JSONArray jsonArrayOld = new JSONArray(); - JSONArray jsonArrayDefault = new JSONArray(); - if(enumScoreRules.equals(EnumScoreRules.SCORE)){ - jsonArrayOld = JSONArray.parseArray(scoreRules).getJSONObject(1).getJSONArray("childs"); - String defaultRules = WxScoreRules.getScoreDefaultRules(); - jsonArrayDefault = JSONArray.parseArray(defaultRules).getJSONObject(1).getJSONArray("childs"); - }else if(enumScoreRules.equals(EnumScoreRules.CREDIT)){ - jsonArrayOld = JSONArray.parseArray(scoreRules).getJSONObject(0).getJSONArray("childs"); - String defaultRules = WxScoreRules.getCreditDefaultRules(); - jsonArrayDefault = JSONArray.parseArray(defaultRules).getJSONObject(0).getJSONArray("childs"); - } - - if (jsonArrayOld.size() < jsonArrayDefault.size()) { - JSONArray childsJsonArray = new JSONArray(); - JSONObject otherJSONObject = new JSONObject(); - //组装新的childs - for (int i = 0; i < jsonArrayDefault.size(); i++) { - JSONObject defaultJSONObject = jsonArrayDefault.getJSONObject(i); - if (i < jsonArrayOld.size()) { - JSONObject oldJSONObject = jsonArrayOld.getJSONObject(i); - if (defaultJSONObject.getString("businessId").equals(oldJSONObject.getString("businessId"))) { - childsJsonArray.add(oldJSONObject); - }else { - childsJsonArray.add(defaultJSONObject); - otherJSONObject = oldJSONObject; - } - } else { - childsJsonArray.add(defaultJSONObject); - } - } - //businessId为6的是其它需要放到最后 - childsJsonArray.remove(childsJsonArray.size()-1); - childsJsonArray.add(otherJSONObject); - //将变更后的childs替换 - JSONArray originalJSONArray = JSONArray.parseArray(scoreRules); + private String getScoreRulesNew(TenantEntity tenantEntity,String scoreRules,EnumScoreRules enumScoreRules){ + JSONObject businessObject = WxScoreRules.getRuleObj(scoreRules, EnumScoreType.CONSUMPTION); + Map businessRuleMap = new HashMap(); + if (null != businessObject) { + JSONArray jsonArrayOld = businessObject.getJSONArray("childs"); + if (null != jsonArrayOld && jsonArrayOld.size() > 0 ) { + for (int i = 0 ; i < jsonArrayOld.size(); i++) { + JSONObject o = jsonArrayOld.getJSONObject(i); + Integer bussinessId = o.getInteger("businessId"); + businessRuleMap.put(bussinessId, o); + } + } + } + //根据业态来匹配 + List rootBusiness = wxBusinessService.findListAll(tenantEntity, null, null); + if (null != rootBusiness && rootBusiness.size() > 0 ) { + for (int i = 0 ; i < rootBusiness.size(); i++){ + WxBusiness bu = rootBusiness.get(i); + if (!businessRuleMap.containsKey(bu.getId())){ + businessRuleMap.put(bu.getId(), WxScoreRules.createBusinessDefaultJson(bu.getId())); + } + } + } + + if (businessRuleMap.size() > 0 ) { + JSONArray childsJsonArray = new JSONArray(); + for (Iterator it = (Iterator) businessRuleMap.keySet().iterator();it.hasNext();) { + Integer businessId = it.next(); + childsJsonArray.add(businessRuleMap.get(businessId)); + } + JSONArray originalJSONArray = JSONArray.parseArray(scoreRules); JSONObject newJSONObject = new JSONObject(); newJSONObject.put("id",EnumScoreType.CONSUMPTION.getCode()); newJSONObject.put("childs",childsJsonArray); - //移除下标为1的JSONArray 即:EnumScoreType.CONSUMPTION(2, "消费") - originalJSONArray.remove(1); - originalJSONArray.add(1,newJSONObject); return originalJSONArray.toJSONString(); } return scoreRules; @@ -177,15 +177,18 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { WxScoreRules scoreRules = new WxScoreRules(); scoreRules.setTenantId(tenantId); scoreRules.setType(EnumScoreRules.CREDIT.getCode()); + + TenantEntity baseTenantEntity = new TenantEntity(); + baseTenantEntity.setTenantId(tenantId); List list = wxScoreRulesMapper.findList(scoreRules); if (list.size() > 0) { scoreRules = list.get(0); - scoreRules.setRules(getScoreRulesNew(scoreRules.getRules(),EnumScoreRules.CREDIT)); + scoreRules.setRules(getScoreRulesNew(baseTenantEntity,scoreRules.getRules(),EnumScoreRules.CREDIT)); } else { // 如果积分规则不存在,启用默认值 final IdWorker idWorker = IdWorker.get(); scoreRules.setId(idWorker.nextId()); - scoreRules.setRules(WxScoreRules.getCreditDefaultRules()); + scoreRules.setRules(getScoreRulesNew(baseTenantEntity,null,EnumScoreRules.CREDIT)); scoreRules.setScale(WxScoreRules.DEFAULT_SCALE); wxScoreRulesMapper.insert(scoreRules); } @@ -324,7 +327,7 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { WxScoreRules scoreRules = getScoreRules(order); // 2. 获取成长值 by id - JSONObject payRule = scoreRules.getRuleObj(EnumScoreType.CONSUMPTION); + JSONObject payRule = WxScoreRules.getRuleObj(scoreRules.getRules(),EnumScoreType.CONSUMPTION); // 3. 获取成长值 by 业态 JSONObject busRule = null; JSONObject busRuleOther = null;