| @@ -45,8 +45,7 @@ public class WxCreditHistoryController extends BaseController | |||
| @ApiOperation("新增接口") | |||
| @PostMapping("add") | |||
| public ResultData add(@RequestBody WxCreditHistory wxCreditHistory) { | |||
| //Assert.notNull(wxCreditHistory.getName(), "角色名不能为空"); | |||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||
| wxCreditHistory.setTenantId(getTenantId()); | |||
| wxCreditHistoryService.saveOrUpdate(wxCreditHistory); | |||
| return new ResultData(); | |||
| } | |||
| @@ -17,7 +17,7 @@ import org.springframework.web.bind.annotation.*; | |||
| @RestController | |||
| @RequestMapping("wxScoreRules") | |||
| @Api(description = "成长值规则相关接口") | |||
| @Api(description = "成长值积分规则相关接口") | |||
| public class WxScoreRulesController extends BaseController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @@ -35,11 +35,20 @@ public class WxScoreRulesController extends BaseController { | |||
| @ApiOperation("新增接口") | |||
| @PostMapping("add") | |||
| @SystemControllerLog(description = "成长值-配置-新增") | |||
| @SystemControllerLog(description = "成长值-积分-配置-新增") | |||
| public ResultData add(@RequestBody WxScoreRules wxScoreRules) { | |||
| logger.debug("[" + getIpAddr() + "] WxScoreRulesController::add"); | |||
| wxScoreRules.setTenantId(getTenantId()); | |||
| wxScoreRulesService.saveOrUpdate(wxScoreRules); | |||
| return new ResultData(); | |||
| } | |||
| @ApiOperation("积分配置") | |||
| @GetMapping("/credit_rules") | |||
| @SystemControllerLog(description = "积分-配置") | |||
| public ResultData creditRulesList() { | |||
| logger.debug("[" + getIpAddr() + "] WxScoreRulesController::list"); | |||
| WxScoreRules scoreRules = wxScoreRulesService.getCreditRules(getTenantId()); | |||
| return new ResultData(scoreRules); | |||
| } | |||
| } | |||
| @@ -274,6 +274,8 @@ public enum ErrorCode{ | |||
| */ | |||
| MEM_IMPORT_ERR(13000, "模板导入失败,请检查数据,尝试重新导入"), | |||
| MEM_SCORE_NOT_ENOUGH(13001, "成长值不够扣减值"), | |||
| CREDIT_ZERO(13100,"本次操作积分为零"), | |||
| CREDIT_NOT_ENOUGH(13101, "积分不够扣减值"), | |||
| /** | |||
| * 标签 | |||
| @@ -157,6 +157,9 @@ public class WxCUser implements Serializable { | |||
| private Date subsSubscribeTime; | |||
| @io.swagger.annotations.ApiModelProperty(value="关注订阅号Scene",name="subsSubscribeScene") | |||
| private String subsSubscribeScene; | |||
| /**积分**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="积分",name="credit") | |||
| private Integer credit; | |||
| //渠道名称 | |||
| @@ -488,7 +491,15 @@ public class WxCUser implements Serializable { | |||
| this.subsSubscribeScene = subsSubscribeScene; | |||
| } | |||
| public static enum Field | |||
| public Integer getCredit() { | |||
| return credit; | |||
| } | |||
| public void setCredit(Integer credit) { | |||
| this.credit = credit; | |||
| } | |||
| public static enum Field | |||
| { | |||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | |||
| ,TenantId_ASC("`tenant_id` ASC"),TenantId_DESC("`tenant_id` DESC") | |||
| @@ -520,7 +531,9 @@ public class WxCUser implements Serializable { | |||
| ,LoginCount_ASC("`login_count` ASC"),LoginCount_DESC("`login_count` DESC") | |||
| ,ExtraInfo_ASC("`extra_info` ASC"),ExtraInfo_DESC("`extra_info` DESC") | |||
| ,IsSubscribe_ASC("`is_subscribe` ASC"),IsSubscribe_DESC("`is_subscribe` DESC") | |||
| ; | |||
| ,Credit_ASC("`credit` ASC"),Credit_DESC("`credit` DESC") | |||
| ; | |||
| private String value; | |||
| Field(String value){ | |||
| this.value = value; | |||
| @@ -114,6 +114,9 @@ public class WxCUserBasicInfo implements Serializable { | |||
| @io.swagger.annotations.ApiModelProperty(value="会员等级",name="level") | |||
| private String level; | |||
| /**积分**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="积分",name="credit") | |||
| private Integer credit; | |||
| @Transient | |||
| @Excel(name="标签",width = 50,orderNum = "10") | |||
| @@ -304,6 +307,14 @@ public class WxCUserBasicInfo implements Serializable { | |||
| this.carCount = carCount; | |||
| } | |||
| public Integer getCredit() { | |||
| return credit; | |||
| } | |||
| public void setCredit(Integer credit) { | |||
| this.credit = credit; | |||
| } | |||
| public static enum Field | |||
| { | |||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | |||
| @@ -319,7 +330,9 @@ public class WxCUserBasicInfo implements Serializable { | |||
| ,UpdateDate_ASC("`update_date` ASC"),UpdateDate_DESC("`update_date` DESC") | |||
| ,TenantId_ASC("`tenant_id` ASC"),TenantId_DESC("`tenant_id` DESC") | |||
| ,Name_ASC("`name` ASC"),Name_DESC("`name` DESC") | |||
| ; | |||
| ,Credit_ASC("`credit` ASC"),Credit_DESC("`credit` DESC") | |||
| ; | |||
| private String value; | |||
| Field(String value){ | |||
| this.value = value; | |||
| @@ -2,6 +2,7 @@ package com.iformall.domain.po; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.enums.EnumScoreType; | |||
| import lombok.Data; | |||
| import javax.persistence.*; | |||
| import java.util.*; | |||
| @@ -21,6 +22,7 @@ import java.io.Serializable; | |||
| */ | |||
| @Table(name = "wx_score_rules") | |||
| @Data | |||
| public class WxScoreRules implements Serializable { | |||
| private static final long serialVersionUID = 1L; | |||
| @@ -36,6 +38,10 @@ public class WxScoreRules implements Serializable { | |||
| " {\"businessId\":4,\"limit\":0,\"step\":1,\"score\":50 ,\"desc\":\"线上交易1元\"}," + | |||
| " {\"businessId\":5,\"limit\":0,\"step\":1,\"score\":50 ,\"desc\":\"线上交易1元\"}," + | |||
| " {\"businessId\":6,\"limit\":0,\"step\":1,\"score\":50 ,\"desc\":\"线上交易1元\"}" + | |||
| " {\"businessId\":7,\"limit\":0,\"step\":1,\"score\":50 ,\"desc\":\"线上交易1元\"}" + | |||
| " {\"businessId\":8,\"limit\":0,\"step\":1,\"score\":50 ,\"desc\":\"线上交易1元\"}" + | |||
| " {\"businessId\":9,\"limit\":0,\"step\":1,\"score\":50 ,\"desc\":\"线上交易1元\"}" + | |||
| " {\"businessId\":10,\"limit\":0,\"step\":1,\"score\":50 ,\"desc\":\"线上交易1元\"}" + | |||
| "]}," + | |||
| "{\"id\":3,\"limit\":1,\"step\":1,\"score\":100,\"desc\":\"绑定车牌1个\"}," + | |||
| "{\"id\":4,\"limit\":0,\"step\":1,\"score\":10 ,\"desc\":\"连接WIFI1次\"}," + | |||
| @@ -95,6 +101,11 @@ public class WxScoreRules implements Serializable { | |||
| @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") | |||
| private Date updateDate; | |||
| @io.swagger.annotations.ApiModelProperty(value="1成长值 2积分",name="type") | |||
| private Integer type; | |||
| @io.swagger.annotations.ApiModelProperty(value="清除前多少年积分",name="clearYear") | |||
| private Integer clearYear; | |||
| public String getTenantId() { | |||
| return tenantId; | |||
| @@ -12,7 +12,12 @@ public enum EnumBusiness { | |||
| BUSINESS_ID3(3, "服饰"), | |||
| BUSINESS_ID4(4, "亲子"), | |||
| BUSINESS_ID5(5, "超市"), | |||
| BUSINESS_ID6(6, "其他"), | |||
| BUSINESS_ID6(6, "家居"), | |||
| BUSINESS_ID7(7, "美妆"), | |||
| BUSINESS_ID8(8, "珠宝"), | |||
| BUSINESS_ID9(9, "服务"), | |||
| BUSINESS_ID10(10, "其他") | |||
| ; | |||
| public static EnumBusiness getEnum(Integer code) { | |||
| @@ -13,7 +13,9 @@ public enum EnumScoreType { | |||
| WECHAT_PHONE(6, "微信用户手机授权"), | |||
| COMPLETE_INFO(7, "完善个人信息"), | |||
| MEM_IMPORT(8, "会员导入"), | |||
| MEM_REDUCE(9, "会员成长值扣减"); | |||
| MEM_REDUCE(9, "会员成长值扣减"), | |||
| SPEND_CREDIT(10, "消费积分"), | |||
| CHANGE_CREDIT(11, "积分兑换"); | |||
| public static EnumScoreType getEnum(Integer code) { | |||
| for (EnumScoreType value : values()) { | |||
| @@ -2,6 +2,7 @@ package com.iformall.mapper; | |||
| import java.util.*; | |||
| import com.iformall.common.CommonMapper; | |||
| import com.iformall.domain.po.WxScoreHistory; | |||
| import com.iformall.domain.vo.WxCreditHistoryVo; | |||
| import com.iformall.domain.po.WxCreditHistory; | |||
| @@ -11,5 +12,10 @@ public interface WxCreditHistoryMapper extends CommonMapper<WxCreditHistory, Lon | |||
| List<WxCreditHistoryVo> findListMore(WxCreditHistory wxCreditHistory); | |||
| int loginCount(WxCreditHistory wxCreditHistory); | |||
| int creditAmount(Long cUserId); | |||
| int countList(WxCreditHistory wxCreditHistory); | |||
| } | |||
| @@ -2,6 +2,7 @@ package com.iformall.service; | |||
| import java.util.*; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.dto.WxCreditHistoryDto; | |||
| import com.iformall.domain.po.WxCreditHistory; | |||
| import com.iformall.domain.vo.WxCreditHistoryVo; | |||
| @@ -41,7 +42,7 @@ public interface WxCreditHistoryService { | |||
| * | |||
| * @param record | |||
| */ | |||
| void saveOrUpdate(WxCreditHistory record); | |||
| ResultData saveOrUpdate(WxCreditHistory record); | |||
| /** | |||
| * 根据Id删除实体 | |||
| @@ -11,6 +11,13 @@ public interface WxScoreRulesService { | |||
| * @return | |||
| */ | |||
| WxScoreRules getScoreRules(String tenantId); | |||
| /** | |||
| * 获取租户的积分规则 | |||
| * @param tenantId | |||
| * @return | |||
| */ | |||
| WxScoreRules getCreditRules(String tenantId); | |||
| /** | |||
| * 保存或更新实体 | |||
| * | |||
| @@ -3,20 +3,29 @@ package com.iformall.service.impl; | |||
| import java.util.*; | |||
| import java.util.stream.Collectors; | |||
| import com.alibaba.fastjson.JSONArray; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.google.common.collect.Lists; | |||
| import com.iformall.domain.dto.WxCreditHistoryDto; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.vo.WxCreditHistoryVo; | |||
| import com.iformall.enums.EnumBusiness; | |||
| import com.iformall.enums.EnumScoreType; | |||
| import com.iformall.enums.EnumUserType; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.service.WxCreditHistoryService; | |||
| import com.iformall.service.WxScoreRulesService; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import com.iformall.common.IdWorker; | |||
| @Service | |||
| @Slf4j | |||
| public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { | |||
| @Autowired | |||
| @@ -34,6 +43,9 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { | |||
| @Autowired | |||
| MallUserInfoMapper mallUserInfoMapper; | |||
| @Autowired | |||
| WxScoreRulesService wxScoreRulesService; | |||
| @Override | |||
| public PageInfo<WxCreditHistory> listAsPage(WxCreditHistory record, Integer pageIndex, Integer pageSize) { | |||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCreditHistoryMapper.findList(record)); | |||
| @@ -113,27 +125,202 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { | |||
| } | |||
| @Override | |||
| public void saveOrUpdate(WxCreditHistory record) { | |||
| public ResultData saveOrUpdate(WxCreditHistory record) { | |||
| WxCUser wxCUser = wxCUserMapper.selectByPrimaryKey(record.getCUserId()); | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoMapper.selectByPrimaryKey(record.getCUserId()); | |||
| if (wxCUser == null && wxCUserBasicInfo == null) { | |||
| //验证此用户是否存在 | |||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | |||
| } | |||
| //获取当前用户总积分 | |||
| int currentCreditAmount = wxCreditHistoryMapper.creditAmount(record.getCUserId()); | |||
| //计算出需要新增或减少的积分 | |||
| int creditChangeNum = creditIncrement(record); | |||
| if (creditChangeNum == 0) { | |||
| return new ResultData(ErrorCode.CREDIT_ZERO); | |||
| } | |||
| if (currentCreditAmount + creditChangeNum < 0) { | |||
| return new ResultData(ErrorCode.CREDIT_NOT_ENOUGH); | |||
| } | |||
| record.setCreditNum(creditChangeNum); | |||
| record.setCreditAmount(currentCreditAmount + creditChangeNum); | |||
| if (record.getId() == null) { | |||
| //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| record.setId(idWorker.nextId()); | |||
| wxCreditHistoryMapper.insertSelective(record); | |||
| //将计算出来新的总积分 更新到两张用户表里 | |||
| updateCredit(wxCUser,wxCUserBasicInfo,record.getCreditAmount()); | |||
| } else { | |||
| wxCreditHistoryMapper.updateByPrimaryKeySelective(record); | |||
| //wxCreditHistoryMapper.updateByPrimaryKeySelective(record); | |||
| } | |||
| return new ResultData(Result.SUCCESS, "积分操作成功"); | |||
| } | |||
| @Override | |||
| public void deleteById(Long id) { | |||
| wxCreditHistoryMapper.deleteByPrimaryKey(id); | |||
| } | |||
| //根据积分类型计算"增加积分" | |||
| private int creditIncrement(WxCreditHistory record) { | |||
| if (record.getCreditType() == EnumScoreType.LOGIN.getCode()) { | |||
| return loginAddCredit(record); | |||
| } | |||
| if (record.getCreditType() == EnumScoreType.BIND_CAR.getCode()) { | |||
| return bindCarAddCredit(record); | |||
| } | |||
| if (record.getCreditType() == EnumScoreType.WIFI_CONNECTION.getCode()) { | |||
| return wifiAddCredit(); | |||
| } | |||
| if (record.getCreditType() == EnumScoreType.WECHAT_PERSION.getCode()) { | |||
| return personAddCredit(record); | |||
| } | |||
| if (record.getCreditType() == EnumScoreType.WECHAT_PHONE.getCode()) { | |||
| return phoneAddCredit(record); | |||
| } | |||
| if (record.getCreditType() == EnumScoreType.COMPLETE_INFO.getCode()) { | |||
| return infoAddCredit(record); | |||
| } | |||
| if (record.getCreditType() == EnumScoreType.SPEND_CREDIT.getCode()) { | |||
| return spendCredit(record); | |||
| } | |||
| if (record.getCreditType() == EnumScoreType.CHANGE_CREDIT.getCode()) { | |||
| //TODO 待实现 | |||
| return changeCredit(record); | |||
| } | |||
| if (record.getCreditType() == EnumScoreType.CONSUMPTION.getCode()) { | |||
| return payAddCredit(record); | |||
| } | |||
| return 0; | |||
| } | |||
| private int loginAddCredit(WxCreditHistory record) { | |||
| //如果当天已经登录过则跳过 | |||
| if (wxCreditHistoryMapper.loginCount(record) > 0) { | |||
| return 0; | |||
| } | |||
| // 1. 获取当前租户下积分的增加规则 | |||
| WxScoreRules wxScoreRules = wxScoreRulesService.getCreditRules(record.getTenantId()); | |||
| // 2. 增长的积分 | |||
| return wxScoreRules.getRule(EnumScoreType.LOGIN,WxScoreRules.SCORE); | |||
| } | |||
| private int bindCarAddCredit(WxCreditHistory record) { | |||
| // 1. 获取score rules | |||
| WxScoreRules wxScoreRules = wxScoreRulesService.getCreditRules(record.getTenantId()); | |||
| // 2. 增长的积分 | |||
| return wxScoreRules.getRule(EnumScoreType.BIND_CAR,WxScoreRules.SCORE); | |||
| } | |||
| private int wifiAddCredit() { | |||
| int addCreditNumber = 0; | |||
| return addCreditNumber; | |||
| } | |||
| private int personAddCredit(WxCreditHistory record) { | |||
| // 1. 获取score rules | |||
| WxScoreRules wxScoreRules = wxScoreRulesService.getCreditRules(record.getTenantId()); | |||
| // 2. 增长的积分 | |||
| return wxScoreRules.getRule(EnumScoreType.WECHAT_PERSION,WxScoreRules.SCORE); | |||
| } | |||
| private int phoneAddCredit(WxCreditHistory record) { | |||
| // 1. 获取score rules | |||
| WxScoreRules wxScoreRules = wxScoreRulesService.getCreditRules(record.getTenantId()); | |||
| // 2. 获取成长值 | |||
| return wxScoreRules.getRule(EnumScoreType.WECHAT_PERSION,WxScoreRules.SCORE); | |||
| } | |||
| private int checkCompleteInfoScoreCount(WxCUser cUser) { | |||
| WxCreditHistory wxCreditHistory = new WxCreditHistory(); | |||
| wxCreditHistory.setTenantId(cUser.getTenantId()); | |||
| wxCreditHistory.setCUserId(cUser.getId()); | |||
| wxCreditHistory.setCreditType(EnumScoreType.COMPLETE_INFO.getCode()); | |||
| return wxCreditHistoryMapper.countList(wxCreditHistory); | |||
| } | |||
| private int infoAddCredit(WxCreditHistory record) { | |||
| WxCUser user = wxCUserMapper.selectByPrimaryKey(record.getCUserId()); | |||
| if (user == null || checkCompleteInfoScoreCount(user) > 0) | |||
| return 0; | |||
| // 1. 获取score rules | |||
| WxScoreRules scoreRules = wxScoreRulesService.getCreditRules(user.getTenantId()); | |||
| // 2. 获取成长值 | |||
| return scoreRules.getRule(EnumScoreType.COMPLETE_INFO,WxScoreRules.SCORE); | |||
| } | |||
| private int spendCredit(WxCreditHistory record){ | |||
| int spendCredit = record.getCreditNum(); | |||
| return -spendCredit; | |||
| } | |||
| private int changeCredit(WxCreditHistory record){ | |||
| //TODO 积分兑换扣减规则 | |||
| return 0; | |||
| } | |||
| private int payAddCredit(WxCreditHistory record) { | |||
| int addCreditNumber = 0; | |||
| // 订单金额为0时不计入 | |||
| if (record.getCreditNum() == 0) | |||
| return 0; | |||
| // 1. 获取score rules | |||
| WxScoreRules scoreRules = wxScoreRulesService.getCreditRules(record.getTenantId()); | |||
| // 2. 获取成长值 by id | |||
| JSONObject payRule = scoreRules.getRuleObj(EnumScoreType.CONSUMPTION); | |||
| // 3. 获取成长值 by 业态 | |||
| JSONObject busRule = null; | |||
| JSONObject busRuleOther = null; | |||
| JSONArray busRules = payRule.getJSONArray("childs"); | |||
| if (busRules != null) { | |||
| for (int i = 0; i < busRules.size(); i++) { | |||
| JSONObject bus = (JSONObject) busRules.get(i); | |||
| Integer businessId1 = bus.getInteger("businessId"); | |||
| if (record.getBusinessId().equals(businessId1)) { | |||
| busRule = bus; | |||
| } | |||
| if (businessId1.equals(EnumBusiness.BUSINESS_ID10.getCode())) { | |||
| busRuleOther = bus; | |||
| } | |||
| } | |||
| if (busRule == null) { | |||
| busRule = busRuleOther; | |||
| } | |||
| } | |||
| if (busRule == null) { | |||
| busRule = payRule; | |||
| } | |||
| Double priceCondition = busRule.getDouble(WxScoreRules.STEP) * 100; // 元->分 | |||
| int baseScore = busRule.getInteger(WxScoreRules.SCORE); // 消费增长积分 | |||
| // 4. 计算积分 | |||
| Double dScoreT = Math.floor(record.getSpend() * 1.0D / priceCondition * baseScore); | |||
| addCreditNumber = dScoreT.intValue(); | |||
| log.info("CREDIT:" + busRule.toJSONString() + "\nAddCredit: " + addCreditNumber); | |||
| return addCreditNumber; | |||
| } | |||
| /** | |||
| * 更新两个表中的最新总积分 | |||
| * @param creditAmount 用户最新总积分 | |||
| */ | |||
| private void updateCredit(WxCUser wxCUser, WxCUserBasicInfo wxCUserBasicInfo, int creditAmount) { | |||
| if (wxCUser != null) { | |||
| wxCUser.setCredit(creditAmount); | |||
| wxCUserMapper.updateByPrimaryKeySelective(wxCUser); | |||
| } | |||
| if (wxCUserBasicInfo != null) { | |||
| wxCUserBasicInfo.setCredit(creditAmount); | |||
| wxCUserBasicInfoMapper.updateByPrimaryKeySelective(wxCUserBasicInfo); | |||
| } | |||
| } | |||
| } | |||
| @@ -28,6 +28,8 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||
| private String keyPrev = "setting:scorerules:"; | |||
| private String creditKeyPrev = "setting:creditrules:"; | |||
| @Autowired | |||
| WxScoreRulesMapper wxScoreRulesMapper; | |||
| @Autowired | |||
| @@ -57,6 +59,7 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||
| WxScoreRules scoreRules = new WxScoreRules(); | |||
| scoreRules.setTenantId(tenantId); | |||
| scoreRules.setType(1); | |||
| List<WxScoreRules> list = wxScoreRulesMapper.findList(scoreRules); | |||
| if (list.size() > 0) { | |||
| scoreRules = list.get(0); | |||
| @@ -76,6 +79,39 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||
| return scoreRules; | |||
| } | |||
| @Override | |||
| public WxScoreRules getCreditRules(String tenantId) { | |||
| // get pushLime from cache | |||
| String key = creditKeyPrev + tenantId; | |||
| // 缓存存在 | |||
| if (scoreRulesRedisTemplate.hasKey(key)) { | |||
| WxScoreRules wScoreRules = scoreRulesRedisTemplate.opsForValue().get(key); | |||
| logger.info("WxScoreRulesServiceImpl.getScoreRules() : 从缓存中获取了积分值设置 >> " + wScoreRules.toString()); | |||
| return wScoreRules; | |||
| } | |||
| WxScoreRules scoreRules = new WxScoreRules(); | |||
| scoreRules.setTenantId(tenantId); | |||
| scoreRules.setType(2); | |||
| List<WxScoreRules> list = wxScoreRulesMapper.findList(scoreRules); | |||
| if (list.size() > 0) { | |||
| scoreRules = list.get(0); | |||
| } else { | |||
| // 如果积分规则不存在,启用默认值 | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| scoreRules.setId(idWorker.nextId()); | |||
| scoreRules.setRules(WxScoreRules.getDefaultRules()); | |||
| wxScoreRulesMapper.insertSelective(scoreRules); | |||
| } | |||
| // 插入缓存 | |||
| scoreRulesRedisTemplate.opsForValue().set(key, scoreRules); | |||
| logger.info("WxScoreRulesServiceImpl.getScoreRules() : 积分设置插入缓存 >> " + scoreRules.toString()); | |||
| return scoreRules; | |||
| } | |||
| @Override | |||
| @@ -89,12 +125,23 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||
| wxScoreRulesMapper.updateByPrimaryKeySelective(record); | |||
| } | |||
| // 缓存存在,删除缓存 | |||
| String key = keyPrev + record.getTenantId(); | |||
| boolean hasKey = scoreRulesRedisTemplate.hasKey(key); | |||
| if (hasKey) { | |||
| scoreRulesRedisTemplate.delete(key); | |||
| logger.info("WxScoreRulesServiceImpl.saveOrUpdate() : 从缓存中删除成长值设置 >> " + record.toString()); | |||
| if (record != null && record.getType() == 1) { | |||
| // 缓存存在,删除缓存 | |||
| String key = keyPrev + record.getTenantId(); | |||
| boolean hasKey = scoreRulesRedisTemplate.hasKey(key); | |||
| if (hasKey) { | |||
| scoreRulesRedisTemplate.delete(key); | |||
| logger.info("WxScoreRulesServiceImpl.saveOrUpdate() : 从缓存中删除成长值设置 >> " + record.toString()); | |||
| } | |||
| } | |||
| if (record != null && record.getType() == 2) { | |||
| // 缓存存在,删除缓存 | |||
| String key = creditKeyPrev + record.getTenantId(); | |||
| boolean hasKey = scoreRulesRedisTemplate.hasKey(key); | |||
| if (hasKey) { | |||
| scoreRulesRedisTemplate.delete(key); | |||
| logger.info("WxScoreRulesServiceImpl.saveOrUpdate() : 从缓存中删除积分设置 >> " + record.toString()); | |||
| } | |||
| } | |||
| } | |||
| @@ -123,6 +170,8 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||
| } | |||
| } | |||
| private void resetBasicUserScore(Long userId, int scoreNumber) { | |||
| // 1. basicUser | |||
| WxCUserBasicInfo user = wxCUserBasicInfoMapper.selectByPrimaryKey(userId); | |||
| @@ -216,7 +265,7 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||
| if (businessId.equals(businessId1)) { | |||
| busRule = bus; | |||
| } | |||
| if (businessId1.equals(EnumBusiness.BUSINESS_ID6.getCode())) { | |||
| if (businessId1.equals(EnumBusiness.BUSINESS_ID10.getCode())) { | |||
| busRuleOther = bus; | |||
| } | |||
| } | |||
| @@ -17,11 +17,12 @@ | |||
| <result column="name" jdbcType="VARCHAR" property="name"/> | |||
| <result column="level" jdbcType="VARCHAR" property="level"/> | |||
| <result column="nick_name" jdbcType="VARCHAR" property="nickName"/> | |||
| <result column="credit" jdbcType="INTEGER" property="credit"/> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`phone`,`birthdate`,`education`,`sex`,`email`,`address`,`poins`,`tag_id`, | |||
| `create_date`,`update_date`,`tenant_id`,`name`,`level`,`nick_name` | |||
| `create_date`,`update_date`,`tenant_id`,`name`,`level`,`nick_name`,`credit` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| @@ -63,6 +64,10 @@ | |||
| and `poins` = #{poins} | |||
| </if> | |||
| <if test=" null != credit "> | |||
| and `credit` = #{credit} | |||
| </if> | |||
| <if test=" null != tagId "> | |||
| and `tag_id` = #{tagId} | |||
| </if> | |||
| @@ -43,6 +43,7 @@ | |||
| <result column="subs_subscribe" jdbcType="TINYINT" property="subsSubscribe"/> | |||
| <result column="subs_subscribe_time" jdbcType="TIMESTAMP" property="subsSubscribeTime"/> | |||
| <result column="subs_subscribe_scene" jdbcType="VARCHAR" property="subsSubscribeScene"/> | |||
| <result column="credit" jdbcType="INTEGER" property="credit"/> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| @@ -53,7 +54,7 @@ | |||
| `login_count`, `extra_info`, `is_subscribe`, | |||
| `open_app_id`, | |||
| `mp_open_id`,`mp_app_id`,`mp_subscribe`,`mp_subscribe_time`,`mp_subscribe_scene`, | |||
| `subs_open_id`,`subs_app_id`,`subs_subscribe`,`subs_subscribe_time`,`subs_subscribe_scene` | |||
| `subs_open_id`,`subs_app_id`,`subs_subscribe`,`subs_subscribe_time`,`subs_subscribe_scene`,`credit` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| @@ -199,6 +200,10 @@ | |||
| and `subs_app_id` = #{subsAppId} | |||
| </if> | |||
| <if test=" null != credit "> | |||
| and `credit` = #{credit} | |||
| </if> | |||
| <if test=" null != ids "> | |||
| and id in | |||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||
| @@ -118,5 +118,53 @@ | |||
| credit.id DESC | |||
| </select> | |||
| <select id="loginCount" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="java.lang.Integer"> | |||
| select COUNT(0) from wx_credit_history | |||
| where 1=1 | |||
| <if test=" null != tenantId "> | |||
| and `tenant_id` = #{tenantId} | |||
| </if> | |||
| <if test=" null != cUserId "> | |||
| and `c_user_id` = #{cUserId} | |||
| </if> | |||
| <if test=" null != scoreType "> | |||
| and `credit_type` = #{creditType} | |||
| </if> | |||
| and DATEDIFF(`create_date`,now())=0 | |||
| </select> | |||
| <select id="countTodayList" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="java.lang.Integer"> | |||
| select count(0) | |||
| from wx_credit_history | |||
| where 1=1 | |||
| <if test=" null != tenantId "> | |||
| and `tenant_id` = #{tenantId} | |||
| </if> | |||
| <if test=" null != cUserId "> | |||
| and `c_user_id` = #{cUserId} | |||
| </if> | |||
| <if test=" null != scoreType "> | |||
| and `credit_type` = #{creditType} | |||
| </if> | |||
| and DATEDIFF(`create_date`,now())=0 | |||
| </select> | |||
| <select id="creditAmount" parameterType="java.lang.Integer" resultType="java.lang.Integer"> | |||
| SELECT credit_amount FROM wx_credit_history where tenant_id = #{tenantId} ORDER BY create_date desc limit 1 | |||
| </select> | |||
| <select id="countList" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="java.lang.Integer"> | |||
| select count(0) | |||
| from wx_credit_history | |||
| where 1=1 | |||
| <if test=" null != tenantId "> | |||
| and `tenant_id` = #{tenantId} | |||
| </if> | |||
| <if test=" null != cUserId "> | |||
| and `c_user_id` = #{cUserId} | |||
| </if> | |||
| <if test=" null != scoreType "> | |||
| and `credit_type` = #{creditType} | |||
| </if> | |||
| </select> | |||
| </mapper> | |||
| @@ -7,6 +7,8 @@ | |||
| <result column="rules" jdbcType="VARCHAR" property="rules"/> | |||
| <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/> | |||
| <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/> | |||
| <result column="type" jdbcType="INTEGER" property="type"/> | |||
| <result column="clear_year" jdbcType="INTEGER" property="clearYear"/> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| @@ -29,6 +31,12 @@ | |||
| <if test=" null != updateDate "> | |||
| and `update_date` = #{updateDate} | |||
| </if> | |||
| <if test=" null != type "> | |||
| and `type` = #{type} | |||
| </if> | |||
| <if test=" null != clearYear "> | |||
| and `clear_year` = #{clearYear} | |||
| </if> | |||
| <if test=" null != ids "> | |||
| and id in | |||