package com.ensign.crm.module.crm.job;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ensign.crm.framework.common.enums.CommonStatusEnum;
import com.ensign.crm.framework.quartz.core.handler.JobHandler;
import com.ensign.crm.module.system.api.permission.PermissionApi;
import com.ensign.crm.module.system.dal.dataobject.user.AdminUserDO;
import com.ensign.crm.module.system.dal.mysql.user.AdminUserMapper;
import com.ensign.crm.module.system.service.permission.PermissionService;
import com.ensign.crm.module.system.service.permission.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description: TODO
 * @Date: 2024/10/15 11:38
 * @Created: by ZZSLL
 */

@Slf4j
@Component
public class UserAllocationTask implements JobHandler {

    @Autowired
    private AdminUserMapper userMapper;

    @Autowired
    private PermissionService permissionService;


    @Override
    public String execute(String param) {

        LambdaQueryWrapper<AdminUserDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AdminUserDO::getStatus, CommonStatusEnum.ENABLE.getStatus())
                .eq(AdminUserDO::getIsSyncKingdee, CommonStatusEnum.ENABLE.getStatus());
        List<AdminUserDO> users = userMapper.selectList(queryWrapper);

        for (AdminUserDO user : users) {
            permissionService.assignPermissions(user);
        }

        return "success";
    }
}
