package cn.ezhizao.project.business.controller;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import cn.ezhizao.common.utils.SecurityUtils;
import cn.ezhizao.common.utils.poi.ExcelUtil;
import cn.ezhizao.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.framework.web.page.TableDataInfo;
import cn.ezhizao.project.system.domain.SysRole;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.ezhizao.project.business.domain.BizCheckCategory;
import cn.ezhizao.project.business.service.IBizCheckCategoryService;

/**
 * 检查类别Controller
 *
 * @author ezhizao
 * @date 2024-08-07
 */
@RestController
@RequestMapping("/business/check")
public class BizCheckCategoryController extends BaseController
{
    @Resource
    private IBizCheckCategoryService bizCheckCategoryService;

    /**
     * 查询检查类别列表
     */
    @GetMapping("/list")
    @Log(title = "查询检查类别列表", businessType = BusinessType.SELECT)
    public TableDataInfo list(BizCheckCategory bizCheckCategory) throws NoSuchFieldException, IllegalAccessException
    {
        startPage();
        List<BizCheckCategory> list = bizCheckCategoryService.getList(bizCheckCategory);
        return getDataTable(list);
    }

    @GetMapping("/roleList")
    @Log(title = "查询检查类别", businessType = BusinessType.SELECT)
    public AjaxResult roleList(BizCheckCategory bizCheckCategory) throws NoSuchFieldException, IllegalAccessException
    {
        //此处应该查询所有的类别信息
        List<BizCheckCategory> list = bizCheckCategoryService.getList(bizCheckCategory);
        return success(list);

    }

    /**
     * 导出检查类别列表
     */
    @Log(title = "导出检查类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizCheckCategory bizCheckCategory) throws NoSuchFieldException, IllegalAccessException
    {
        List<BizCheckCategory> list = bizCheckCategoryService.getList(bizCheckCategory);
        ExcelUtil<BizCheckCategory> util = new ExcelUtil<BizCheckCategory>(BizCheckCategory.class);
        util.exportExcel(response, list, "检查类别数据");
    }

    /**
     * 获取检查类别详细信息
     */
    @GetMapping(value = "/{id}")
    @Log(title = "获取检查类别", businessType = BusinessType.SELECT)
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizCheckCategoryService.getById(id));
    }

    /**
     * 新增检查类别
     */
    @Log(title = "新增检查类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizCheckCategory bizCheckCategory) throws NoSuchFieldException, IllegalAccessException
    {
        return toAjax(bizCheckCategoryService.save(bizCheckCategory));
    }

    /**
     * 修改检查类别
     */
    @Log(title = "修改检查类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizCheckCategory bizCheckCategory) throws NoSuchFieldException, IllegalAccessException
    {
        return toAjax(bizCheckCategoryService.updateById(bizCheckCategory));
    }

    /**
     * 删除检查类别
     */
    @Log(title = "删除检查类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizCheckCategoryService.removeBatchByIds(ids));
    }
}
