package com.hxhq.business.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

import com.hxhq.common.core.utils.DateUtils;
import com.hxhq.common.core.utils.poi.ExcelUtil;
import com.hxhq.common.security.annotation.RequiresPermissions;
import com.hxhq.system.api.domain.SysUser;
import com.hxhq.system.dto.UserExportDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.hxhq.business.domain.RoleChange;
import com.hxhq.business.service.IRoleChangeService;
import com.hxhq.common.core.web.controller.BaseController;
import com.hxhq.common.core.web.domain.AjaxResult;
import com.hxhq.common.core.web.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;


/**
 * 角色变更历史Controller
 *
 * @author hxhq
 * @date 2026-02-04
 */
@RestController
@RequestMapping("/business/roleChange")
public class RoleChangeController extends BaseController
{
    @Autowired
    private IRoleChangeService roleChangeService;

    /**
     * 查询角色变更历史列表
     */
    @GetMapping("/list")
    @RequiresPermissions("system:user:roleChange")
    public TableDataInfo list(RoleChange roleChange)
    {
        startPage();
        List<RoleChange> list = roleChangeService.queryList(roleChange);
        return getDataTable(list);
    }

    /**
     * 新增角色变更历史导出
     * @param response
     * @param roleChange
     */
    @PostMapping("/export")
    @RequiresPermissions("system:user:roleChange:export")
    public void export(HttpServletResponse response, RoleChange roleChange)
    {
        List<RoleChange> list = roleChangeService.queryList(roleChange);
        for(RoleChange l : list){
            l.setCreateTimeText(l.getCreateTime()==null?"":DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,l.getCreateTime()));
        }
        ExcelUtil<RoleChange> util = new ExcelUtil<RoleChange>(RoleChange.class);
        util.exportExcel(response, list, "角色变更历史");
    }
}
