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

/**
 * 行李系统PLC缓冲电池生命周期Controller
 * 
 * @author Yinq
 * @date 2025-06-05
 */
@RestController
@RequiredArgsConstructor

@RequestMapping("/ems/info/plcBufferBatteryLifecycle")
public class LuggageSystemPlcBufferBatteryLifecycleController extends EmsBaseController
{
    
    private final ILuggageSystemPlcBufferBatteryLifecycleService luggageSystemPlcBufferBatteryLifecycleService;

    /**
     * 查询行李系统PLC缓冲电池生命周期列表
     */
    @SaCheckPermission("ems/info:plcBufferBatteryLifecycle:list")
    @GetMapping("/list")
    public TableDataInfo list(LuggageSystemPlcBufferBatteryLifecycle luggageSystemPlcBufferBatteryLifecycle)
    {
        startPage();
        List<LuggageSystemPlcBufferBatteryLifecycle> list = luggageSystemPlcBufferBatteryLifecycleService.selectLuggageSystemPlcBufferBatteryLifecycleList(luggageSystemPlcBufferBatteryLifecycle);
        return getDataTable(list);
    }

    /**
     * 导出行李系统PLC缓冲电池生命周期列表
     */
    @SaCheckPermission("ems/info:plcBufferBatteryLifecycle:export")
    @Log(title = "行李系统PLC缓冲电池生命周期", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LuggageSystemPlcBufferBatteryLifecycle luggageSystemPlcBufferBatteryLifecycle)
    {
        List<LuggageSystemPlcBufferBatteryLifecycle> list = luggageSystemPlcBufferBatteryLifecycleService.selectLuggageSystemPlcBufferBatteryLifecycleList(luggageSystemPlcBufferBatteryLifecycle);
        ExcelUtil.exportExcel(list, "行李系统PLC缓冲电池生命周期数据", LuggageSystemPlcBufferBatteryLifecycle.class, response);
    }

    /**
     * 获取行李系统PLC缓冲电池生命周期详细信息
     */
    @SaCheckPermission("ems/info:plcBufferBatteryLifecycle:query")
    @GetMapping(value = "/{objid}")
    public R<?> getInfo(@PathVariable("objid") Long objid)
    {
        return success(luggageSystemPlcBufferBatteryLifecycleService.selectLuggageSystemPlcBufferBatteryLifecycleByObjid(objid));
    }

    /**
     * 新增行李系统PLC缓冲电池生命周期
     */
    @SaCheckPermission("ems/info:plcBufferBatteryLifecycle:add")
    @Log(title = "行李系统PLC缓冲电池生命周期", businessType = BusinessType.INSERT)
    @PostMapping
    public R<?> add(@RequestBody LuggageSystemPlcBufferBatteryLifecycle luggageSystemPlcBufferBatteryLifecycle)
    {
        return toAjax(luggageSystemPlcBufferBatteryLifecycleService.insertLuggageSystemPlcBufferBatteryLifecycle(luggageSystemPlcBufferBatteryLifecycle));
    }

    /**
     * 修改行李系统PLC缓冲电池生命周期
     */
    @SaCheckPermission("ems/info:plcBufferBatteryLifecycle:edit")
    @Log(title = "行李系统PLC缓冲电池生命周期", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<?> edit(@RequestBody LuggageSystemPlcBufferBatteryLifecycle luggageSystemPlcBufferBatteryLifecycle)
    {
        return toAjax(luggageSystemPlcBufferBatteryLifecycleService.updateLuggageSystemPlcBufferBatteryLifecycle(luggageSystemPlcBufferBatteryLifecycle));
    }

    /**
     * 删除行李系统PLC缓冲电池生命周期
     */
    @SaCheckPermission("ems/info:plcBufferBatteryLifecycle:remove")
    @Log(title = "行李系统PLC缓冲电池生命周期", businessType = BusinessType.DELETE)
	@DeleteMapping("/{objids}")
    public R<?> remove(@PathVariable Long[] objids)
    {
        return toAjax(luggageSystemPlcBufferBatteryLifecycleService.deleteLuggageSystemPlcBufferBatteryLifecycleByObjids(objids));
    }

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

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