Commit 53a6a1a1 authored by zhaobiyan's avatar zhaobiyan

新增会员编码字段,刷新历史数据

parent 6f32cb16
......@@ -26,6 +26,7 @@ public class SecurityConfiguration {
registry.antMatchers("/swagger-ui.html").anonymous()
.antMatchers("/swagger-resources/**").anonymous()
.antMatchers("/webjars/**").anonymous()
.antMatchers("/doc.html#/**").anonymous()
.antMatchers("/*/api-docs").anonymous();
// Spring Boot Actuator 的安全配置
registry.antMatchers("/actuator").anonymous()
......
......@@ -36,6 +36,7 @@ import cn.iocoder.yudao.module.member.vo.userCardAuth.UserCardAuthCreateReqVO;
import cn.iocoder.yudao.module.member.vo.userEnterpriseAuth.UserEnterpriseAuthBackVO;
import cn.iocoder.yudao.module.member.vo.userEnterpriseAuth.UserEnterpriseAuthCreateReqVO;
import cn.iocoder.yudao.module.member.vo.userOperationLog.UserOperationLogBackVO;
import com.alibaba.excel.util.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
......@@ -459,5 +460,12 @@ public class MemberUserController {
return success(null);
}
@PutMapping("/history/code/flush")
@ApiOperation("历史会员编码刷新")
@PreAuthorize("@ss.hasPermission('member:user:info')")
public CommonResult<Boolean> historyCodeFlush() {
userService.historyCodeFlush();
return success(true);
}
}
......@@ -234,6 +234,6 @@ public class MemberUserDO extends TenantBaseDO {
*/
private Boolean isDeal;
private String code;
}
......@@ -171,8 +171,10 @@ public interface MemberUserMapper extends BaseMapperX<MemberUserDO> {
"</script>"
})
MemberUserDO info(@Param("id") Long id);
@Update("update ecw_customer_contacts set userid = null where userid = #{userId}")
void unbindingCustomer(@Param("userId") Long userId);
String getCurrentMaxMemberCode();
void updateMemberCodeById(@Param("code")String memberCode, @Param("id")Long id);
}
......@@ -218,4 +218,7 @@ public interface MemberUserService {
void memberCancellation(Long userId);
List<MemberUserDO> getByCursor(Long startUserId, long limit);
void historyCodeFlush();
}
......@@ -12,6 +12,7 @@ import cn.iocoder.yudao.framework.i18n.core.I18nMessage;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils;
import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO;
import cn.iocoder.yudao.framework.redis.helper.RedisHelper;
import cn.iocoder.yudao.module.ecw.api.customer.CustomerApi;
import cn.iocoder.yudao.module.ecw.api.internalMessage.ClientInternalMessageApi;
import cn.iocoder.yudao.module.ecw.api.internalMessage.dto.InternalMessageCreateDto;
......@@ -32,15 +33,18 @@ import cn.iocoder.yudao.module.member.dal.mysql.userEnterpriseAuth.UserEnterpris
import cn.iocoder.yudao.module.member.enums.UserOperationLogTypeEnum;
import cn.iocoder.yudao.module.member.enums.UserQueryAuthTypeEnum;
import cn.iocoder.yudao.module.member.service.userOperationLog.UserOperationLogService;
import cn.iocoder.yudao.module.member.util.MemberUserCodeUtils;
import cn.iocoder.yudao.module.member.vo.member.MemberUpdateReqVO;
import cn.iocoder.yudao.module.member.vo.userOperationLog.UserOperationLogCreateReqVO;
import cn.iocoder.yudao.module.product.service.coupon.CouponService;
import cn.iocoder.yudao.module.system.api.sms.SmsCodeApi;
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO;
import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum;
import com.alibaba.excel.util.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.annotations.VisibleForTesting;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
......@@ -53,6 +57,7 @@ import javax.annotation.Resource;
import javax.validation.Valid;
import java.io.InputStream;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
......@@ -102,6 +107,9 @@ public class MemberUserServiceImpl implements MemberUserService {
@Resource
private ParamValidatorApi paramValidatorApi;
@Resource
private RedisHelper redisHelper;
@Override
public MemberUserDO getUserByMobile(String mobile) {
......@@ -524,4 +532,51 @@ public class MemberUserServiceImpl implements MemberUserService {
memberUserMapper.unbindingCustomer(userId);
}
@Override
public List<MemberUserDO> getByCursor(Long startUserId, long limit) {
if (startUserId == null) {
return Collections.emptyList();
}
LambdaQueryWrapper<MemberUserDO> wrapper = Wrappers.lambdaQuery();
wrapper.gt(MemberUserDO::getId, startUserId);
wrapper.orderByAsc(MemberUserDO::getId);
wrapper.last("limit " + limit);
return memberUserMapper.getList(wrapper);
}
@Override
public void historyCodeFlush() {
Long startUserId = 0L;
long limit = 500;
while(true) {
List<MemberUserDO> result = this.getByCursor(startUserId, limit);
if (CollectionUtils.isEmpty(result)) {
break;
}
result.forEach(memberUserDO -> {
String memberCode = getNextMemberCode();
memberUserMapper.updateMemberCodeById(memberCode, memberUserDO.getId());
});
startUserId = result.stream().mapToLong(MemberUserDO::getId).max().orElse(Long.MAX_VALUE);
}
}
private String getNextMemberCode() {
String key = "memberCode:max:number";
Boolean hasMemberCodeMaxNumber = redisHelper.hasKey(key);
if (hasMemberCodeMaxNumber) {
return MemberUserCodeUtils.generateMemberCode(redisHelper.incrBy(key, 1));
}
synchronized(this) {
hasMemberCodeMaxNumber = redisHelper.hasKey(key);
if (hasMemberCodeMaxNumber) {
return MemberUserCodeUtils.generateMemberCode(redisHelper.incrBy(key, 1));
}
String currentMaxMemberCode = memberUserMapper.getCurrentMaxMemberCode();
Long memberCodeMaxNumber = MemberUserCodeUtils.getMemberCodeNumber(currentMaxMemberCode);
redisHelper.set(key, String.valueOf(memberCodeMaxNumber), 5, TimeUnit.MINUTES);
return MemberUserCodeUtils.generateMemberCode(redisHelper.incrBy(key, 1));
}
}
}
package cn.iocoder.yudao.module.member.util;
import org.apache.commons.lang.StringUtils;
import org.json.JSONObject;
/**
* @author zhaobiyan
*/
public class MemberUserCodeUtils {
private static final String MEMBER_CODE_PREFIX = "EC";
private static final int DEFAULT_LENGTH = 6;
public static String generateMemberCode(Long codeNumber) {
StringBuilder codeNumberStr = new StringBuilder(String.valueOf(codeNumber));
if (codeNumberStr.length() >= DEFAULT_LENGTH) {
return MEMBER_CODE_PREFIX + codeNumberStr;
}
int supplyCount = DEFAULT_LENGTH - codeNumberStr.length();
for (int i = 0; i < supplyCount; i++) {
codeNumberStr.insert(0, "0");
}
return MEMBER_CODE_PREFIX + codeNumberStr;
}
public static Long getMemberCodeNumber(String currentMaxMemberCode) {
if (StringUtils.isBlank(currentMaxMemberCode)) {
return 0L;
}
String[] split = currentMaxMemberCode.split(MEMBER_CODE_PREFIX);
return Long.parseLong(split[1]);
}
}
......@@ -83,4 +83,12 @@
) as t
${ew.customSqlSegment}
</select>
<select id="getCurrentMaxMemberCode" resultType="String">
select code from member_user order by code desc limit 1
</select>
<update id="updateMemberCodeById" >
update member_user set code = #{code} where id = #{id}
</update>
</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