package com.hxhq.business.service.impl;

import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
        import com.hxhq.common.core.utils.DateUtils;
import com.hxhq.common.security.utils.SecurityUtils;
import org.springframework.stereotype.Service;
import com.hxhq.business.mapper.RoleChangeMapper;
import com.hxhq.business.domain.RoleChange;
import com.hxhq.business.service.IRoleChangeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 角色变更历史Service业务层处理
 *
 * @author hxhq
 * @date 2026-02-04
 */
@Service
public class RoleChangeServiceImpl extends ServiceImpl<RoleChangeMapper, RoleChange> implements IRoleChangeService
{
    /**
     * 查询角色变更历史列表
     *
     * @param roleChange 角色变更历史
     * @return 角色变更历史
     */
    @Override
    public List<RoleChange> queryList(RoleChange roleChange)
    {
        QueryWrapper<RoleChange> queryWrapper = Wrappers.query();
        if(roleChange.getUserId()!=null && roleChange.getUserId().longValue()>0){
            queryWrapper.eq("user_id",roleChange.getUserId());
        }
        queryWrapper.orderByDesc("id");
        return this.list(queryWrapper);
    }

    @Override
    public void saveInfo(Long userId, String bgq, String bgh, String remark) {
        RoleChange roleChange = new RoleChange();
        roleChange.setUserId(userId);
        roleChange.setBgq(bgq);
        roleChange.setBgh(bgh);
        roleChange.setRemark(remark);

        roleChange.setJcmc("分配角色");
        roleChange.setJcmcEn("Role Change");
        roleChange.setQmrId(SecurityUtils.getUserId());
        roleChange.setQmrMc(SecurityUtils.getNickName());
        roleChange.setQmrMcEn(SecurityUtils.getUsername());
        save(roleChange);
    }

    @Override
    public void saveList(List<RoleChange> list) {
        for(RoleChange roleChange : list){
            roleChange.setJcmc("分配角色");
            roleChange.setJcmcEn("Role Change");
            roleChange.setQmrId(SecurityUtils.getUserId());
            roleChange.setQmrMc(SecurityUtils.getNickName());
            roleChange.setQmrMcEn(SecurityUtils.getUsername());
        }
        if(list.size()>0){
            saveBatch(list);
        }
    }
}
