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.UpsBatteryLifecycle;
import org.dromara.ems.info.service.IUpsBatteryLifecycleService;
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;

/**
 * 行李系统UPS电池生命周期Controller
 * 
 * @author Yinq
 * @date 2024-12-13
 */
@RestController
@RequiredArgsConstructor

@RequestMapping("/ems/info/upsBatteryLifecycle")
public class UpsBatteryLifecycleController extends EmsBaseController
{

    private final IUpsBatteryLifecycleService upsBatteryLifecycleService;

    /**
     * 查询行李系统UPS电池生命周期列表
     */
    @SaCheckPermission("ems/info:upsBatteryLifecycle:list")
    @GetMapping("/list")
    public TableDataInfo list(UpsBatteryLifecycle upsBatteryLifecycle)
    {
        startPage();
        List<UpsBatteryLifecycle> list = upsBatteryLifecycleService.selectUpsBatteryLifecycleList(upsBatteryLifecycle);
        return getDataTable(list);
    }

    /**
     * 导出行李系统UPS电池生命周期列表
     */
    @SaCheckPermission("ems/info:upsBatteryLifecycle:export")
    @Log(title = "行李系统UPS电池生命周期", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UpsBatteryLifecycle upsBatteryLifecycle)
    {
        List<UpsBatteryLifecycle> list = upsBatteryLifecycleService.selectUpsBatteryLifecycleList(upsBatteryLifecycle);
        ExcelUtil.exportExcel(list, "行李系统UPS电池生命周期数据", UpsBatteryLifecycle.class, response);
    }

    /**
     * 获取行李系统UPS电池生命周期详细信息
     */
    @SaCheckPermission("ems/info:upsBatteryLifecycle:query")
    @GetMapping(value = "/{id}")
    public R<?> getInfo(@PathVariable("id") Long id)
    {
        return success(upsBatteryLifecycleService.selectUpsBatteryLifecycleById(id));
    }

    /**
     * 新增行李系统UPS电池生命周期
     */
    @SaCheckPermission("ems/info:upsBatteryLifecycle:add")
    @Log(title = "行李系统UPS电池生命周期", businessType = BusinessType.INSERT)
    @PostMapping
    public R<?> add(@RequestBody UpsBatteryLifecycle upsBatteryLifecycle)
    {
        return toAjax(upsBatteryLifecycleService.insertUpsBatteryLifecycle(upsBatteryLifecycle));
    }

    /**
     * 修改行李系统UPS电池生命周期
     */
    @SaCheckPermission("ems/info:upsBatteryLifecycle:edit")
    @Log(title = "行李系统UPS电池生命周期", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<?> edit(@RequestBody UpsBatteryLifecycle upsBatteryLifecycle)
    {
        return toAjax(upsBatteryLifecycleService.updateUpsBatteryLifecycle(upsBatteryLifecycle));
    }

    /**
     * 删除行李系统UPS电池生命周期
     */
    @SaCheckPermission("ems/info:upsBatteryLifecycle:remove")
    @Log(title = "行李系统UPS电池生命周期", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public R<?> remove(@PathVariable Long[] ids)
    {
        return toAjax(upsBatteryLifecycleService.deleteUpsBatteryLifecycleByIds(ids));
    }

    /**
     * 导入行李系统UPS电池生命周期数据
     */
    @SaCheckPermission("ems/info:upsBatteryLifecycle:add")
    @Log(title = "行李系统UPS电池生命周期", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public R<?> importData(MultipartFile file, @RequestParam(value = "updateSupport", defaultValue = "false") boolean updateSupport) throws Exception
    {
        List<UpsBatteryLifecycle> dataList = ExcelUtil.importExcel(file.getInputStream(), UpsBatteryLifecycle.class);
        String message = upsBatteryLifecycleService.importUpsBatteryLifecycle(dataList, updateSupport, getUsername());
        return R.ok(message);
    }

    /**
     * 获取行李系统UPS电池生命周期导入模板
     */
    @SaCheckPermission("ems/info:upsBatteryLifecycle:add")
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil.exportExcel(new ArrayList<>(), "行李系统UPS电池生命周期数据", UpsBatteryLifecycle.class, response);
    }
}
