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.PowerEnergySparePartsRegistration;
import org.dromara.ems.info.service.IPowerEnergySparePartsRegistrationService;
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-06
 */
@RestController
@RequiredArgsConstructor

@RequestMapping("/ems/info/sparePartsRegistration")
public class PowerEnergySparePartsRegistrationController extends EmsBaseController
{
    
    private final IPowerEnergySparePartsRegistrationService powerEnergySparePartsRegistrationService;

    /**
     * 查询动力能源部行输科废旧备件登记列表
     */
    @SaCheckPermission("ems/info:sparePartsRegistration:list")
    @GetMapping("/list")
    public TableDataInfo list(PowerEnergySparePartsRegistration powerEnergySparePartsRegistration)
    {
        startPage();
        List<PowerEnergySparePartsRegistration> list = powerEnergySparePartsRegistrationService.selectPowerEnergySparePartsRegistrationList(powerEnergySparePartsRegistration);
        return getDataTable(list);
    }

    /**
     * 导出动力能源部行输科废旧备件登记列表
     */
    @SaCheckPermission("ems/info:sparePartsRegistration:export")
    @Log(title = "动力能源部行输科废旧备件登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PowerEnergySparePartsRegistration powerEnergySparePartsRegistration)
    {
        List<PowerEnergySparePartsRegistration> list = powerEnergySparePartsRegistrationService.selectPowerEnergySparePartsRegistrationList(powerEnergySparePartsRegistration);
        ExcelUtil.exportExcel(list, "动力能源部行输科废旧备件登记数据", PowerEnergySparePartsRegistration.class, response);
    }

    /**
     * 获取动力能源部行输科废旧备件登记详细信息
     */
    @SaCheckPermission("ems/info:sparePartsRegistration:query")
    @GetMapping(value = "/{objid}")
    public R<?> getInfo(@PathVariable("objid") Long objid)
    {
        return success(powerEnergySparePartsRegistrationService.selectPowerEnergySparePartsRegistrationByObjid(objid));
    }

    /**
     * 新增动力能源部行输科废旧备件登记
     */
    @SaCheckPermission("ems/info:sparePartsRegistration:add")
    @Log(title = "动力能源部行输科废旧备件登记", businessType = BusinessType.INSERT)
    @PostMapping
    public R<?> add(@RequestBody PowerEnergySparePartsRegistration powerEnergySparePartsRegistration)
    {
        return toAjax(powerEnergySparePartsRegistrationService.insertPowerEnergySparePartsRegistration(powerEnergySparePartsRegistration));
    }

    /**
     * 修改动力能源部行输科废旧备件登记
     */
    @SaCheckPermission("ems/info:sparePartsRegistration:edit")
    @Log(title = "动力能源部行输科废旧备件登记", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<?> edit(@RequestBody PowerEnergySparePartsRegistration powerEnergySparePartsRegistration)
    {
        return toAjax(powerEnergySparePartsRegistrationService.updatePowerEnergySparePartsRegistration(powerEnergySparePartsRegistration));
    }

    /**
     * 删除动力能源部行输科废旧备件登记
     */
    @SaCheckPermission("ems/info:sparePartsRegistration:remove")
    @Log(title = "动力能源部行输科废旧备件登记", businessType = BusinessType.DELETE)
	@DeleteMapping("/{objids}")
    public R<?> remove(@PathVariable Long[] objids)
    {
        return toAjax(powerEnergySparePartsRegistrationService.deletePowerEnergySparePartsRegistrationByObjids(objids));
    }

    /**
     * 导入动力能源部行输科废旧备件登记数据
     */
    @SaCheckPermission("ems/info:sparePartsRegistration:add")
    @Log(title = "动力能源部行输科废旧备件登记", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public R<?> importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        List<PowerEnergySparePartsRegistration> registrationList = ExcelUtil.importExcel(file.getInputStream(), PowerEnergySparePartsRegistration.class);
        String operName = getUsername();
        String message = powerEnergySparePartsRegistrationService.importPowerEnergySparePartsRegistration(registrationList, updateSupport, operName);
        return R.ok(message);
    }

    /**
     * 获取动力能源部行输科废旧备件登记导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil.exportExcel(new ArrayList<>(), "动力能源部行输科废旧备件登记数据", PowerEnergySparePartsRegistration.class, response);
    }
}
