| @@ -53,6 +53,7 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||||
| // 缓存存在 | // 缓存存在 | ||||
| if (scoreRulesRedisTemplate.hasKey(key)) { | if (scoreRulesRedisTemplate.hasKey(key)) { | ||||
| WxScoreRules wScoreRules = scoreRulesRedisTemplate.opsForValue().get(key); | WxScoreRules wScoreRules = scoreRulesRedisTemplate.opsForValue().get(key); | ||||
| wScoreRules.setRules(getScoreRulesNew(wScoreRules.getRules())); | |||||
| logger.info("WxScoreRulesServiceImpl.getScoreRules() : 从缓存中获取了成长值设置 >> " + wScoreRules.toString()); | logger.info("WxScoreRulesServiceImpl.getScoreRules() : 从缓存中获取了成长值设置 >> " + wScoreRules.toString()); | ||||
| return wScoreRules; | return wScoreRules; | ||||
| } | } | ||||
| @@ -63,6 +64,8 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||||
| List<WxScoreRules> list = wxScoreRulesMapper.findList(scoreRules); | List<WxScoreRules> list = wxScoreRulesMapper.findList(scoreRules); | ||||
| if (list.size() > 0) { | if (list.size() > 0) { | ||||
| scoreRules = list.get(0); | scoreRules = list.get(0); | ||||
| scoreRules.setRules(getScoreRulesNew(scoreRules.getRules())); | |||||
| } else { | } else { | ||||
| // 如果成长值规则不存在,启用默认值 | // 如果成长值规则不存在,启用默认值 | ||||
| final IdWorker idWorker = IdWorker.get(); | final IdWorker idWorker = IdWorker.get(); | ||||
| @@ -71,7 +74,6 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||||
| wxScoreRulesMapper.insertSelective(scoreRules); | wxScoreRulesMapper.insertSelective(scoreRules); | ||||
| } | } | ||||
| // 插入缓存 | // 插入缓存 | ||||
| scoreRulesRedisTemplate.opsForValue().set(key, scoreRules); | scoreRulesRedisTemplate.opsForValue().set(key, scoreRules); | ||||
| logger.info("WxScoreRulesServiceImpl.getScoreRules() : 成长值设置插入缓存 >> " + scoreRules.toString()); | logger.info("WxScoreRulesServiceImpl.getScoreRules() : 成长值设置插入缓存 >> " + scoreRules.toString()); | ||||
| @@ -79,6 +81,43 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||||
| return scoreRules; | return scoreRules; | ||||
| } | } | ||||
| //当成长值或积分规则新增时,将新增的数据一并返回给接口调用端 | |||||
| private String getScoreRulesNew(String scoreRules){ | |||||
| JSONArray jsonArrayOld = JSONArray.parseArray(scoreRules).getJSONObject(1).getJSONArray("childs"); | |||||
| JSONArray jsonArrayDefault = JSONArray.parseArray(WxScoreRules.getDefaultRules()).getJSONObject(1).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); | |||||
| JSONObject newJSONObject = new JSONObject(); | |||||
| newJSONObject.put("id",2); | |||||
| newJSONObject.put("childs",childsJsonArray); | |||||
| originalJSONArray.remove(1); | |||||
| originalJSONArray.add(1,newJSONObject); | |||||
| return originalJSONArray.toJSONString(); | |||||
| } | |||||
| return scoreRules; | |||||
| } | |||||
| @Override | @Override | ||||
| public WxScoreRules getCreditRules(String tenantId) { | public WxScoreRules getCreditRules(String tenantId) { | ||||
| // get pushLime from cache | // get pushLime from cache | ||||
| @@ -87,6 +126,7 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||||
| // 缓存存在 | // 缓存存在 | ||||
| if (scoreRulesRedisTemplate.hasKey(key)) { | if (scoreRulesRedisTemplate.hasKey(key)) { | ||||
| WxScoreRules wScoreRules = scoreRulesRedisTemplate.opsForValue().get(key); | WxScoreRules wScoreRules = scoreRulesRedisTemplate.opsForValue().get(key); | ||||
| wScoreRules.setRules(getScoreRulesNew(wScoreRules.getRules())); | |||||
| logger.info("WxScoreRulesServiceImpl.getScoreRules() : 从缓存中获取了积分值设置 >> " + wScoreRules.toString()); | logger.info("WxScoreRulesServiceImpl.getScoreRules() : 从缓存中获取了积分值设置 >> " + wScoreRules.toString()); | ||||
| return wScoreRules; | return wScoreRules; | ||||
| } | } | ||||
| @@ -97,6 +137,7 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||||
| List<WxScoreRules> list = wxScoreRulesMapper.findList(scoreRules); | List<WxScoreRules> list = wxScoreRulesMapper.findList(scoreRules); | ||||
| if (list.size() > 0) { | if (list.size() > 0) { | ||||
| scoreRules = list.get(0); | scoreRules = list.get(0); | ||||
| scoreRules.setRules(getScoreRulesNew(scoreRules.getRules())); | |||||
| } else { | } else { | ||||
| // 如果积分规则不存在,启用默认值 | // 如果积分规则不存在,启用默认值 | ||||
| final IdWorker idWorker = IdWorker.get(); | final IdWorker idWorker = IdWorker.get(); | ||||