package org.dromara.ems.info.controller;

import org.dromara.common.log.annotation.Log;
import org.dromara.ems.common.web.EmsBaseController;
import org.dromara.common.core.domain.R;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.ems.info.domain.PowerEnergySupervisionChecklist;
import org.dromara.ems.info.service.IPowerEnergySupervisionChecklistService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

/**
 * 动力能源部监督检查清单Controller
 * 
 * @author Yinq
 * @date 2025-06-05
 */
@RestController
@RequiredArgsConstructor

@RequestMapping("/ems/info/supervisionChecklist")
public class PowerEnergySupervisionChecklistController extends EmsBaseController
{

    private final IPowerEnergySupervisionChecklistService powerEnergySupervisionChecklistService;

    /**
     * 查询动力能源部监督检查清单列表
     */
    @SaCheckPermission("ems/info:supervisionChecklist:list")
    @GetMapping("/list")
    public TableDataInfo list(PowerEnergySupervisionChecklist powerEnergySupervisionChecklist)
    {
        startPage();
        List<PowerEnergySupervisionChecklist> list = powerEnergySupervisionChecklistService.selectPowerEnergySupervisionChecklistList(powerEnergySupervisionChecklist);
        return getDataTable(list);
    }

    /**
     * 导出动力能源部监督检查清单列表
     */
    @SaCheckPermission("ems/info:supervisionChecklist:export")
    @Log(title = "动力能源部监督检查清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PowerEnergySupervisionChecklist powerEnergySupervisionChecklist)
    {
        List<PowerEnergySupervisionChecklist> list = powerEnergySupervisionChecklistService.selectPowerEnergySupervisionChecklistList(powerEnergySupervisionChecklist);
        ExcelUtil.exportExcel(list, "动力能源部监督检查清单数据", PowerEnergySupervisionChecklist.class, response);
    }

    /**
     * 获取动力能源部监督检查清单详细信息
     */
    @SaCheckPermission("ems/info:supervisionChecklist:query")
    @GetMapping(value = "/{id}")
    public R<?> getInfo(@PathVariable("id") Long id)
    {
        return success(powerEnergySupervisionChecklistService.selectPowerEnergySupervisionChecklistById(id));
    }

    /**
     * 新增动力能源部监督检查清单
     */
    @SaCheckPermission("ems/info:supervisionChecklist:add")
    @Log(title = "动力能源部监督检查清单", businessType = BusinessType.INSERT)
    @PostMapping
    public R<?> add(@RequestBody PowerEnergySupervisionChecklist powerEnergySupervisionChecklist)
    {
        return toAjax(powerEnergySupervisionChecklistService.insertPowerEnergySupervisionChecklist(powerEnergySupervisionChecklist));
    }

    /**
     * 修改动力能源部监督检查清单
     */
    @SaCheckPermission("ems/info:supervisionChecklist:edit")
    @Log(title = "动力能源部监督检查清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<?> edit(@RequestBody PowerEnergySupervisionChecklist powerEnergySupervisionChecklist)
    {
        return toAjax(powerEnergySupervisionChecklistService.updatePowerEnergySupervisionChecklist(powerEnergySupervisionChecklist));
    }

    /**
     * 删除动力能源部监督检查清单
     */
    @SaCheckPermission("ems/info:supervisionChecklist:remove")
    @Log(title = "动力能源部监督检查清单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public R<?> remove(@PathVariable Long[] ids)
    {
        return toAjax(powerEnergySupervisionChecklistService.deletePowerEnergySupervisionChecklistByIds(ids));
    }

    /**
     * 下载模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil.exportExcel(new ArrayList<>(), "动力能源部监督检查清单数据", PowerEnergySupervisionChecklist.class, response);
    }

    /**
     * 导入数据
     */
    @Log(title = "动力能源部监督检查清单", businessType = BusinessType.IMPORT)
    @SaCheckPermission("ems/info:supervisionChecklist:add")
    @PostMapping("/importData")
    public R<?> importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        List<PowerEnergySupervisionChecklist> recordList = ExcelUtil.importExcel(file.getInputStream(), PowerEnergySupervisionChecklist.class);
        String operName = getUsername();
        String message = powerEnergySupervisionChecklistService.importPowerEnergySupervisionChecklist(recordList, updateSupport, operName);
        return success(message);
    }
}
