Browse Source

Merge branch 'release_toaliyun_real_20230403' of https://git.malls.iformall.com/server/formallProject into release_toaliyun_real_20230403

release_toaliyun_real
xhxu 3 years ago
parent
commit
c7e8dce535
7 changed files with 108 additions and 72 deletions
  1. +3
    -0
      mallinkAdmin/src/main/java/com/iformall/controller/mem/WxScoreRulesController.java
  2. +1
    -0
      mallinkAdmin/src/main/java/com/iformall/controller/sys/WxBusinessController.java
  3. +1
    -1
      mallinkCApi/src/main/java/com/iformall/controller/WxBusinessController.java
  4. +45
    -25
      mallinkService/src/main/java/com/iformall/domain/po/WxScoreRules.java
  5. +1
    -1
      mallinkService/src/main/java/com/iformall/service/impl/WxCreditHistoryServiceImpl.java
  6. +56
    -45
      mallinkService/src/main/java/com/iformall/service/impl/WxScoreRulesServiceImpl.java
  7. +1
    -0
      mallinkService/src/main/java/com/iformall/utils/Constant.java

+ 3
- 0
mallinkAdmin/src/main/java/com/iformall/controller/mem/WxScoreRulesController.java View File

@@ -68,6 +68,9 @@ public class WxScoreRulesController extends BaseController {
}else{
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"type");
}
if (!wxScoreRules.checkRules()) {
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"规则内容有项重复");
}
wxScoreRulesService.saveOrUpdate(wxScoreRules);
return new ResultData();
}


+ 1
- 0
mallinkAdmin/src/main/java/com/iformall/controller/sys/WxBusinessController.java View File

@@ -85,6 +85,7 @@ public class WxBusinessController extends BaseController {
return new ResultData(Result.ERROR,"不能修改系统默认业态");
}
}
wxBusiness.setTitle(wxBusiness.getTitle().replaceAll("\\\\", ""));
wxBusinessService.saveOrUpdate(wxBusiness);
return new ResultData();
}


+ 1
- 1
mallinkCApi/src/main/java/com/iformall/controller/WxBusinessController.java View File

@@ -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) {


+ 45
- 25
mallinkService/src/main/java/com/iformall/domain/po/WxScoreRules.java View File

@@ -5,12 +5,16 @@ 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;


import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* 1. 每天登录首次给成长值
@@ -30,22 +34,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+",\"title\":\""+Constant.default_business_name+"\",\"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 +58,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+",\"title\":\""+Constant.default_business_name+"\",\"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 +139,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<JSONObject> list = JSONObject.parseArray(rules, JSONObject.class);
List<JSONObject> list = JSONObject.parseArray(ruleContent, JSONObject.class);
if (list == null)
return null;
if (list.size() == 0)
@@ -168,5 +159,34 @@ public class WxScoreRules extends BaseTenantEntity {
return null;
}

public static JSONObject createBusinessDefaultJson(Integer businessId,String businessNme) {
String json = "{\"businessId\":"+businessId+",\"title\":\""+businessNme+"\",\"limit\":"+DEFAULT_LIMIT+",\"step\":"+DEFAULT_STEP+",\"score\":"+DEFAULT_SCORE+" ,\"desc\":\"线上交易1元\"}" ;
return JSONObject.parseObject(json);
}
public boolean checkRules() {
if (rules == null)
return true;

List<JSONObject> list = JSONObject.parseArray(rules, JSONObject.class);
if (list == null)
return true;
if (list.size() == 0)
return true;

Map<Integer,Integer> rootIdCount = new HashMap<Integer,Integer>();
for (JSONObject jo:list) {
Integer id = jo.getInteger(WxScoreRules.ID);
if ( id!= null){
Integer idcont = rootIdCount.get(id);
if (null != idcont && idcont > 0) {
return false;
}else {
rootIdCount.put(id, 1);
}
}
}
return true;
}

}

+ 1
- 1
mallinkService/src/main/java/com/iformall/service/impl/WxCreditHistoryServiceImpl.java View File

@@ -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;


+ 56
- 45
mallinkService/src/main/java/com/iformall/service/impl/WxScoreRulesServiceImpl.java View File

@@ -1,5 +1,6 @@
package com.iformall.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.iformall.common.ErrorCode;
@@ -9,6 +10,7 @@ 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;
@@ -17,11 +19,15 @@ 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.Iterator;
import java.util.List;
import java.util.Map;

@Service
public class WxScoreRulesServiceImpl implements WxScoreRulesService {
@@ -44,6 +50,10 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService {

@Autowired
WxMerchantMapper wxMerchantMapper;
@Lazy
@Autowired
WxBusinessService wxBusinessService;

@Override
public void wxScoreRulesInit(String tenantId) {
@@ -89,7 +99,7 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService {
List<WxScoreRules> 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,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();
newJSONObject.put("id",EnumScoreType.CONSUMPTION.getCode());
newJSONObject.put("childs",childsJsonArray);
//移除下标为1的JSONArray 即:EnumScoreType.CONSUMPTION(2, "消费")
originalJSONArray.remove(1);
originalJSONArray.add(1,newJSONObject);
originalJSONArray.add(newJSONObject);
return originalJSONArray.toJSONString();
}
return scoreRules;
}
@Override
public WxScoreRules getCreditRules(String tenantId) {
// String tenantId = "";
@@ -177,15 +182,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<WxScoreRules> 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);
}
@@ -200,6 +208,9 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService {

@Override
public void saveOrUpdate(WxScoreRules record) {
//校验规则不能重复
Date date = new Date();
record.setUpdateDate(date);
if (record.getId() == null) {
@@ -324,7 +335,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;


+ 1
- 0
mallinkService/src/main/java/com/iformall/utils/Constant.java View File

@@ -128,6 +128,7 @@ public class Constant {
//默认业态
public static final Integer default_business = 6;
public static final String default_business_name = "其他";
public static final Integer dy_business = 2;

}

Loading…
Cancel
Save