Commit ed6f5ec1 authored by zhangfeng's avatar zhangfeng

Merge branch 'release-bugfix-zhangfeng' into 'release'

Release bugfix zhangfeng

See merge request !15
parents 2d917bd9 74783bc5
package cn.iocoder.yudao.module.member.controller.admin.job;
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import cn.iocoder.yudao.module.member.util.ScoreRuleGenCodeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* 积分规则编号刷新任务
* @author zhaobiyan
*/
@Component
@Slf4j
public class ScoreRuleCodeFlushTask implements JobHandler {
@Resource
private ScoreRuleGenCodeUtils scoreRuleGenCodeUtils;
@Override
public String execute(String param) throws Exception {
scoreRuleGenCodeUtils.historyScoreRuleCodeFlush();
return "success";
}
}
\ No newline at end of file
......@@ -24,6 +24,10 @@ public class ScoreRuleDO extends BaseDO {
*/
@TableId
private Long id;
/**
* 规则编号
*/
private String code;
/**
* 指标类型
*/
......
......@@ -11,6 +11,8 @@ import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO;
import cn.iocoder.yudao.module.member.enums.RelationSymbolEnum;
import cn.iocoder.yudao.module.member.vo.scoreRule.ScoreRuleQueryVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
/**
* 积分规则 Mapper
......@@ -69,4 +71,7 @@ public interface ScoreRuleMapper extends AbstractMapper<ScoreRuleDO> {
}
return null;
}
@ResultType(String.class)
@Select({"select code from score_rule order by code desc limit 1"})
String getCurrentMaxScoreRuleCode();
}
......@@ -86,11 +86,11 @@ public class OrderVStrategy extends AbstractScoreRuleStrategy {
log.info("Order in shipping listener: No score rule match,orderID:{}", orderId);
return;
}
// 规则是否包含目的地提货点
// 规则是否包含目的地提货点,0代表所有提货点
OrderObjectiveApiDO orderObjectiveDO = order.getOrderObjectiveDO();
ScoreRuleOrderVExtraVO extraInfo = JSONUtil.toBean(scoreRuleDO.getExtra(), ScoreRuleOrderVExtraVO.class);
String[] warehouseIds = extraInfo.getReceiveAddr().split(",");
if (!ArrayUtil.contains(warehouseIds, orderObjectiveDO.getObjectiveWarehouseId().toString())) {
if (!Objects.equals(warehouseIds[0], "0") && !ArrayUtil.contains(warehouseIds, orderObjectiveDO.getObjectiveWarehouseId().toString())) {
log.info("Order in shipping listener: The rule does not contain the order destination warehouse,orderID:{},warehouseId:{}", orderId, orderObjectiveDO.getObjectiveWarehouseId().toString());
return;
}
......
......@@ -21,6 +21,7 @@ import cn.iocoder.yudao.module.member.enums.ScoreRuleStatusEnum;
import cn.iocoder.yudao.module.member.enums.ScoreRuleTypeEnum;
import cn.iocoder.yudao.module.member.enums.TransportTypeEnum;
import cn.iocoder.yudao.module.member.enums.YesOrNoTypeEnum;
import cn.iocoder.yudao.module.member.util.ScoreRuleGenCodeUtils;
import cn.iocoder.yudao.module.member.vo.scoreRule.*;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleOrderVExtraVO;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleRegisterExtraVO;
......@@ -60,6 +61,8 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
private WarehouseService warehouseService;
@Resource
private AdminUserApi adminUserApi;
@Resource
private ScoreRuleGenCodeUtils scoreRuleGenCodeUtils;
@Override
public Long createScoreRule(ScoreRuleCreateReqVO createReqVO) {
......@@ -70,6 +73,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
verifyCommon(createReqVO);
Integer scoreRuleType = scoreRule.getType();
verifyAndSetExtraDO(createReqVO, scoreRuleType, scoreRule);
scoreRule.setCode(scoreRuleGenCodeUtils.generateScoreRuleCode());
scoreRuleMapper.insert(scoreRule);
scoreRuleRedisDao.deleteEnableScoreRule(scoreRule.getType());
// 返回
......@@ -367,6 +371,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
scoreRuleDO.setCreateTime(null);
scoreRuleDO.setUpdateTime(null);
scoreRuleDO.setUpdater(null);
scoreRuleDO.setCode(scoreRuleGenCodeUtils.generateScoreRuleCode());
scoreRuleMapper.insert(scoreRuleDO);
return scoreRuleDO.getId();
}
......@@ -449,8 +454,9 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
case RECOMMEND:
case REGISTER:
return getEnableScoreRuleByType(scoreRuleType);
default:
return null;
}
return null;
}
@Override
......
package cn.iocoder.yudao.module.member.util;
import cn.iocoder.yudao.framework.redis.helper.RedisHelper;
import cn.iocoder.yudao.module.member.dal.dataobject.scoreRule.ScoreRuleDO;
import cn.iocoder.yudao.module.member.dal.mysql.scoreRule.ScoreRuleMapper;
import com.alibaba.excel.util.DateUtils;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.GET_LOCK_FAILED;
/**
* 根据规则生成各种code
*/
@Component
public class ScoreRuleGenCodeUtils {
@Resource
private RedisHelper redisHelper;
@Resource
private RedissonClient redissonClient;
@Resource
private ScoreRuleMapper scoreRuleMapper;
/**
* 生成积分规则编号
*/
public String generateScoreRuleCode() {
// 编号规则为PR+年份+5位数,例如PR2400001
String key = "scoreRule:max:number";
StringBuilder code = new StringBuilder();
code.append("PR");
code.append(DateUtils.format(new Date(), "yy"));
Long codeNum;
if (redisHelper.hasKey(key)) {
codeNum = redisHelper.incrBy(key, 1);
} else {
RLock lock = redissonClient.getLock("next:scoreRule:code:lock");
try {
boolean lockSuccess = lock.tryLock(2, 2, TimeUnit.SECONDS);
if (!lockSuccess) {
throw exception(GET_LOCK_FAILED);
}
String currentMaxScoreRuleCode = scoreRuleMapper.getCurrentMaxScoreRuleCode();
if (currentMaxScoreRuleCode == null){
codeNum = 1L;
} else {
codeNum = Long.parseLong(currentMaxScoreRuleCode.substring(4)) + 1;
}
redisHelper.set(key, String.valueOf(codeNum),10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw exception(GET_LOCK_FAILED);
} finally {
lock.unlock();
}
}
// 获得5位序列号,不足位前面补0
code.append(String.format("%05d", codeNum));
return code.toString();
}
public void historyScoreRuleCodeFlush() {
long start = 1L;
redisHelper.delete("scoreRule:max:number");
List<ScoreRuleDO> scoreRuleDOS = scoreRuleMapper.selectList();
for (ScoreRuleDO scoreRuleDO : scoreRuleDOS) {
StringBuilder code = new StringBuilder();
code.append("PR");
code.append(DateUtils.format(new Date(), "yy"));
code.append(String.format("%05d", start));
scoreRuleDO.setCode(code.toString());
scoreRuleMapper.updateById(scoreRuleDO);
start += 1;
}
}
}
......@@ -22,6 +22,10 @@ public class ScoreRuleBackVO {
@ApiModelProperty(value = "主键", required = true)
private Long id;
@ExcelProperty("编号")
@ApiModelProperty(value = "编号", required = true)
private String code;
@ExcelProperty("指标类型")
@ApiModelProperty(value = "指标类型", required = true)
private Integer type;
......
package cn.iocoder.yudao.module.member.vo.scoreRule;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleOrderVExtraVO;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleRegisterExtraVO;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleShareExtraVO;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRulerRecommendExtraVO;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
import javax.validation.constraints.*;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Data
@ToString(callSuper = true)
......
......@@ -10,6 +10,8 @@ import java.util.Date;
@Data
@ApiModel("管理后台 - 礼品兑换记录查询 VO")
public class RewardRedeemPageReqVO extends PageParam {
@ApiModelProperty(value = "兑换记录编号")
private String redemptionNumber;
@ApiModelProperty(value = "礼品名称")
private String rewardTitle;
@ApiModelProperty(value = "会员名称")
......
......@@ -166,5 +166,8 @@
<if test="req.memberId != null">
and err.member_id = #{req.memberId}
</if>
<if test="req.redemptionNumber != null and req.redemptionNumber !=''">
and err.redemption_number = #{req.redemptionNumber}
</if>
</sql>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment