Commit 7b8fd244 authored by Smile's avatar Smile Committed by wux

会员默认等级定时任务

parent 6b577fa3
......@@ -35,6 +35,8 @@ public interface MemberUserMapper extends BaseMapperX<MemberUserDO> {
List<MemberUserDO> getList(@Param(Constants.WRAPPER) Wrapper<MemberUserDO> queryWrapper);
List<MemberUserDO> getUserByNoLevelDetail();
long memberUserCount(@Param(Constants.WRAPPER) Wrapper<MemberUserDO> queryWrapper);
@ResultType(Integer.class)
......
package cn.iocoder.yudao.module.member.job;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQuery;
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberUserLevelConfigDO;
import cn.iocoder.yudao.module.member.dal.dataobject.levelOperatLog.MemberUserLevelOperateLogDO;
import cn.iocoder.yudao.module.member.dal.dataobject.memberUserLevelDetail.MemberUserLevelDetailsDO;
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
import cn.iocoder.yudao.module.member.enums.MemberLevelStatusEnum;
import cn.iocoder.yudao.module.member.service.level.MemberUserLevelConfigService;
import cn.iocoder.yudao.module.member.service.levelDetails.MemberUserLevelDetailsService;
import cn.iocoder.yudao.module.member.service.levelOperateLog.MemberUserLevelOperateLogService;
import cn.iocoder.yudao.module.member.service.scoreLog.MemberUserScoreLogService;
import cn.iocoder.yudao.module.member.service.user.MemberUserService;
import cn.iocoder.yudao.module.member.vo.userLevelDetails.MemberUserLevelDetailsBackVO;
import cn.iocoder.yudao.module.member.vo.userLevelDetails.MemberUserLevelDetailsQueryVO;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
/**
* 会员等级详情定时任务
*/
@Component
@Slf4j
public class userLevelDefaultDetailsTask implements JobHandler {
/**
* 每天凌晨00:00AM和12:00AM 分别执行一次
* @param param 参数
* @return
* @throws Exception
*/
@Resource
private MemberUserLevelConfigService memberUserLevelConfigService;
@Resource
private MemberUserService userService;
@Resource
private MemberUserLevelDetailsService memberUserLevelDetailsService;
@Resource
private AdminUserApi adminUserApi;
@Resource
private MemberUserLevelOperateLogService memberUserLevelOperateService;
@Lazy
@Resource
private MemberUserScoreLogService memberUserScoreLogService;
@Override
public String execute(String param) throws Exception {
log.info("level default details task running");
//查找默认的蓝卡等级,等级为1
LambdaQuery<MemberUserLevelConfigDO> userLevelConfigDoLambdaQuery = new LambdaQuery<>();
userLevelConfigDoLambdaQuery.eq(MemberUserLevelConfigDO::getStatus, MemberLevelStatusEnum.ENABLED.getValue());
userLevelConfigDoLambdaQuery.eq(MemberUserLevelConfigDO::getLevel, 1);
List<MemberUserLevelConfigDO> todoList = memberUserLevelConfigService.selectList(userLevelConfigDoLambdaQuery);
log.info("level default details task, rule count :{}", todoList.size());
if (CollectionUtils.isEmpty(todoList)) {
return "success";
} else {
MemberUserLevelConfigDO memberUserLevelConfigDO=todoList.get(0);
log.info("level default details task, rule name :{}", memberUserLevelConfigDO.getRuleNumber());
List<MemberUserDO> userByNoLevelDetailList = userService.getUserByNoLevelDetail();
if (CollectionUtils.isEmpty(userByNoLevelDetailList)){
return "success";
}else {
userByNoLevelDetailList.stream().forEach(memberUserDO -> {
setConfigDetails(memberUserDO, memberUserLevelConfigDO);
});
}
log.info("定时任务完成");
}
return "success";
}
private void setConfigDetails(MemberUserDO memberUserDO, MemberUserLevelConfigDO memberUserLevelConfigDO) {
//获取用户是否有详情
MemberUserLevelDetailsQueryVO queryVO=new MemberUserLevelDetailsQueryVO();
queryVO.setMemberId(memberUserDO.getId());
PageResult<MemberUserLevelDetailsBackVO> page = memberUserLevelDetailsService.getPage(queryVO);
AdminUserRespDTO user = adminUserApi.getUser(1L);
List<MemberUserLevelDetailsBackVO> list = page.getList();
if (CollectionUtils.isEmpty(list)){
//没有详情,新增一条
MemberUserLevelDetailsDO memberUserLevelDetailsDO = new MemberUserLevelDetailsDO();
memberUserLevelDetailsDO.setMemberId(memberUserDO.getId());
memberUserLevelDetailsDO.setLevel(memberUserLevelConfigDO.getLevel());
memberUserLevelDetailsDO.setSpecificSettings(false);
if (memberUserLevelConfigDO.getValidityPeriod() != null) {
memberUserLevelDetailsDO.setValidityPeriod(DateUtils.getNextNDayStart(new Date(), memberUserLevelConfigDO.getValidityPeriod()));
}
memberUserLevelDetailsDO.setRemarks(memberUserLevelConfigDO.getDescription());
memberUserLevelDetailsDO.setConfigId(memberUserLevelConfigDO.getId());
memberUserLevelDetailsDO.setCreator(String.valueOf(user.getId()));
memberUserLevelDetailsDO.setUpdater(String.valueOf(user.getId()));
memberUserLevelDetailsService.save(memberUserLevelDetailsDO);
log.info("设置默认等级,客户没有等级详情,增加等级详情进入升级操作,规则id:{},用户id:{}", memberUserLevelConfigDO.getRuleNumber(), memberUserDO.getId());
//设置用户为admin
//插入一条日志 升级日志
MemberUserLevelOperateLogDO memberUserLevelOperateLogDo = MemberUserLevelOperateLogDO.builder()
.configId(memberUserLevelDetailsDO.getConfigId())
.configName(memberUserLevelConfigDO.getName())
.memberId(memberUserLevelDetailsDO.getMemberId())
.operator(user.getNickname())
.remarks(memberUserLevelDetailsDO.getRemarks())
.level(memberUserLevelDetailsDO.getLevel())
.operateType(1)
.build();
memberUserLevelOperateService.save(memberUserLevelOperateLogDo);
}
}
}
......@@ -128,6 +128,12 @@ public interface MemberUserService {
*/
List<MemberUserDO> getUserList(UserQueryVO query);
/**
* 获取没有等级的会员用户列表
* @return
*/
List<MemberUserDO> getUserByNoLevelDetail();
/**
* 根据id更新用户
*
......
......@@ -471,6 +471,11 @@ public class MemberUserServiceImpl implements MemberUserService {
return memberUserMapper.getList(wrapper);
}
@Override
public List<MemberUserDO> getUserByNoLevelDetail() {
return memberUserMapper.getUserByNoLevelDetail();
}
@Override
public int updateById(MemberUserDO memberUserDO) {
return memberUserMapper.updateById(memberUserDO);
......
......@@ -37,6 +37,36 @@
and uca.deleted = 0 or uca.deleted is null
</sql>
<sql id="queryTableByNoConfigDetail">
select u.*,
uca.`status` as identity_audit_status,
uca.`audit_remark` as identity_audit_remark,
uca.`name` as identity_name,
uca.`create_time` as identity_audit_create_time,
uca.`audit_time` as identity_audit_time,
uea.`status` as enterprise_audit_status,
uea.`name` as enterprise_name,
uea.`create_time` as enterprise_audit_create_time,
uea.`audit_time` as enterprise_audit_time,
uea.`audit_remark` as enterprise_audit_remark,
ec.id as customerId,
ec.number as customerCode,
u.code as memberCode
from member_user u
left join member_user_card_auth uca on u.id = uca.user_id
left join member_user_enterprise_auth uea on u.id = uea.user_id
left join ecw_customer_contacts ecc on u.id = ecc.userid
left join ecw_customer ec on ec.id = ecc.customer_id
left join member_user_level_details muld on muld.member_id = u.id
where 1 = 1
and muld.level is null
and (uca.deleted = 0 or uca.deleted is null)
</sql>
<select id="getWaitApproveUserPage" resultType="cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO">
select * from (
select u.*,
......@@ -78,6 +108,12 @@
${ew.customSqlSegment}
</select>
<select id="getUserByNoLevelDetail" resultType="cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO">
select * from (
<include refid="queryTableByNoConfigDetail"/>
) as t
</select>
<select id="get7daysCount" parameterType="java.lang.String" resultType="cn.iocoder.yudao.module.member.controller.admin.user.vo.UserBackVO">
select DATE_FORMAT(t.create_time,'%y-%m-%d') as registDate,count(1) as groupCount from member_user t where t.create_time>=#{format} GROUP BY DATE_FORMAT(t.create_time,'%y-%m-%d')
</select>
......
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