|
|
@@ -1,5 +1,6 @@ |
|
|
package com.iformall.service.impl; |
|
|
package com.iformall.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.iformall.common.ErrorCode; |
|
|
import com.iformall.common.ErrorCode; |
|
|
@@ -9,6 +10,7 @@ import com.iformall.domain.po.base.TenantEntity; |
|
|
import com.iformall.enums.*; |
|
|
import com.iformall.enums.*; |
|
|
import com.iformall.exception.MallinkException; |
|
|
import com.iformall.exception.MallinkException; |
|
|
import com.iformall.mapper.*; |
|
|
import com.iformall.mapper.*; |
|
|
|
|
|
import com.iformall.service.WxBusinessService; |
|
|
import com.iformall.service.WxCUserService; |
|
|
import com.iformall.service.WxCUserService; |
|
|
import com.iformall.service.WxScoreRulesService; |
|
|
import com.iformall.service.WxScoreRulesService; |
|
|
import com.iformall.utils.Constant; |
|
|
import com.iformall.utils.Constant; |
|
|
@@ -17,11 +19,15 @@ import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Qualifier; |
|
|
import org.springframework.beans.factory.annotation.Qualifier; |
|
|
|
|
|
import org.springframework.context.annotation.Lazy; |
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
import java.util.Date; |
|
|
import java.util.Date; |
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
import java.util.Iterator; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
@Service |
|
|
@Service |
|
|
public class WxScoreRulesServiceImpl implements WxScoreRulesService { |
|
|
public class WxScoreRulesServiceImpl implements WxScoreRulesService { |
|
|
@@ -44,6 +50,10 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
WxMerchantMapper wxMerchantMapper; |
|
|
WxMerchantMapper wxMerchantMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Lazy |
|
|
|
|
|
@Autowired |
|
|
|
|
|
WxBusinessService wxBusinessService; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void wxScoreRulesInit(String tenantId) { |
|
|
public void wxScoreRulesInit(String tenantId) { |
|
|
@@ -89,7 +99,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(),EnumScoreRules.SCORE)); |
|
|
|
|
|
|
|
|
scoreRules.setRules(getScoreRulesNew(tenantEntity,scoreRules.getRules(),EnumScoreRules.SCORE)); |
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
// 如果成长值规则不存在,启用默认值 |
|
|
// 如果成长值规则不存在,启用默认值 |
|
|
@@ -108,54 +118,49 @@ 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<Integer,JSONObject> businessRuleMap = new HashMap<Integer,JSONObject>(); |
|
|
|
|
|
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<WxBusiness> 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(),bu.getTitle())); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (businessRuleMap.size() > 0 ) { |
|
|
|
|
|
JSONArray childsJsonArray = new JSONArray(); |
|
|
|
|
|
for (Iterator<Integer> it = businessRuleMap.keySet().iterator();it.hasNext();) { |
|
|
|
|
|
Integer businessId = it.next(); |
|
|
|
|
|
childsJsonArray.add(businessRuleMap.get(businessId)); |
|
|
|
|
|
} |
|
|
|
|
|
JSONArray originalJSONArray = JSONArray.parseArray(scoreRules); |
|
|
|
|
|
if (null != businessObject) { |
|
|
|
|
|
originalJSONArray.remove(businessObject); |
|
|
|
|
|
} |
|
|
JSONObject newJSONObject = new JSONObject(); |
|
|
JSONObject newJSONObject = new JSONObject(); |
|
|
newJSONObject.put("id",EnumScoreType.CONSUMPTION.getCode()); |
|
|
newJSONObject.put("id",EnumScoreType.CONSUMPTION.getCode()); |
|
|
newJSONObject.put("childs",childsJsonArray); |
|
|
newJSONObject.put("childs",childsJsonArray); |
|
|
//移除下标为1的JSONArray 即:EnumScoreType.CONSUMPTION(2, "消费") |
|
|
|
|
|
originalJSONArray.remove(1); |
|
|
|
|
|
originalJSONArray.add(1,newJSONObject); |
|
|
|
|
|
|
|
|
originalJSONArray.add(newJSONObject); |
|
|
return originalJSONArray.toJSONString(); |
|
|
return originalJSONArray.toJSONString(); |
|
|
} |
|
|
} |
|
|
return scoreRules; |
|
|
return scoreRules; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public WxScoreRules getCreditRules(String tenantId) { |
|
|
public WxScoreRules getCreditRules(String tenantId) { |
|
|
// String tenantId = ""; |
|
|
// String tenantId = ""; |
|
|
@@ -177,15 +182,18 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { |
|
|
WxScoreRules scoreRules = new WxScoreRules(); |
|
|
WxScoreRules scoreRules = new WxScoreRules(); |
|
|
scoreRules.setTenantId(tenantId); |
|
|
scoreRules.setTenantId(tenantId); |
|
|
scoreRules.setType(EnumScoreRules.CREDIT.getCode()); |
|
|
scoreRules.setType(EnumScoreRules.CREDIT.getCode()); |
|
|
|
|
|
|
|
|
|
|
|
TenantEntity baseTenantEntity = new TenantEntity(); |
|
|
|
|
|
baseTenantEntity.setTenantId(tenantId); |
|
|
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(),EnumScoreRules.CREDIT)); |
|
|
|
|
|
|
|
|
scoreRules.setRules(getScoreRulesNew(baseTenantEntity,scoreRules.getRules(),EnumScoreRules.CREDIT)); |
|
|
} else { |
|
|
} else { |
|
|
// 如果积分规则不存在,启用默认值 |
|
|
// 如果积分规则不存在,启用默认值 |
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
scoreRules.setId(idWorker.nextId()); |
|
|
scoreRules.setId(idWorker.nextId()); |
|
|
scoreRules.setRules(WxScoreRules.getCreditDefaultRules()); |
|
|
|
|
|
|
|
|
scoreRules.setRules(getScoreRulesNew(baseTenantEntity,null,EnumScoreRules.CREDIT)); |
|
|
scoreRules.setScale(WxScoreRules.DEFAULT_SCALE); |
|
|
scoreRules.setScale(WxScoreRules.DEFAULT_SCALE); |
|
|
wxScoreRulesMapper.insert(scoreRules); |
|
|
wxScoreRulesMapper.insert(scoreRules); |
|
|
} |
|
|
} |
|
|
@@ -200,6 +208,9 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void saveOrUpdate(WxScoreRules record) { |
|
|
public void saveOrUpdate(WxScoreRules record) { |
|
|
|
|
|
//校验规则不能重复 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date date = new Date(); |
|
|
Date date = new Date(); |
|
|
record.setUpdateDate(date); |
|
|
record.setUpdateDate(date); |
|
|
if (record.getId() == null) { |
|
|
if (record.getId() == null) { |
|
|
@@ -324,7 +335,7 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { |
|
|
WxScoreRules scoreRules = getScoreRules(order); |
|
|
WxScoreRules scoreRules = getScoreRules(order); |
|
|
|
|
|
|
|
|
// 2. 获取成长值 by id |
|
|
// 2. 获取成长值 by id |
|
|
JSONObject payRule = scoreRules.getRuleObj(EnumScoreType.CONSUMPTION); |
|
|
|
|
|
|
|
|
JSONObject payRule = WxScoreRules.getRuleObj(scoreRules.getRules(),EnumScoreType.CONSUMPTION); |
|
|
// 3. 获取成长值 by 业态 |
|
|
// 3. 获取成长值 by 业态 |
|
|
JSONObject busRule = null; |
|
|
JSONObject busRule = null; |
|
|
JSONObject busRuleOther = null; |
|
|
JSONObject busRuleOther = null; |
|
|
|