package com.agri.system.controller;

import com.agri.common.annotation.Log;
import com.agri.common.core.controller.BaseController;
import com.agri.common.core.domain.AjaxResult;
import com.agri.common.core.page.TableDataInfo;
import com.agri.common.enums.BusinessType;
import com.agri.common.utils.poi.ExcelUtil;
import com.agri.system.domain.SysAgriLimit;
import com.agri.system.service.ISysAgriLimitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 执行时间限位管理Controller
 * 
 * @author agri
 * @date 2026-01-08
 */
@RestController
@RequestMapping("/assets/limit")
public class SysAgriLimitController extends BaseController
{
    @Autowired
    private ISysAgriLimitService sysAgriLimitService;

    /**
     * 查询执行时间限位管理列表
     */
    @PreAuthorize("@ss.hasPermi('assets:limit:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAgriLimit sysAgriLimit)
    {
        startPage();
        List<SysAgriLimit> list = sysAgriLimitService.selectSysAgriLimitList(sysAgriLimit);
        return getDataTable(list);
    }

    /**
     * 导出执行时间限位管理列表
     */
    @PreAuthorize("@ss.hasPermi('assets:limit:export')")
    @Log(title = "执行时间限位管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAgriLimit sysAgriLimit)
    {
        List<SysAgriLimit> list = sysAgriLimitService.selectSysAgriLimitList(sysAgriLimit);
        ExcelUtil<SysAgriLimit> util = new ExcelUtil<SysAgriLimit>(SysAgriLimit.class);
        util.exportExcel(response, list, "执行时间限位管理数据");
    }

    /**
     * 获取执行时间限位管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('assets:limit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(sysAgriLimitService.selectSysAgriLimitById(id));
    }

    /**
     * 新增执行时间限位管理
     */
    @PreAuthorize("@ss.hasPermi('assets:limit:add')")
    @Log(title = "执行时间限位管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAgriLimit sysAgriLimit)
    {
        return toAjax(sysAgriLimitService.insertSysAgriLimit(sysAgriLimit));
    }

    /**
     * 修改执行时间限位管理
     */
    @PreAuthorize("@ss.hasPermi('assets:limit:edit')")
    @Log(title = "执行时间限位管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAgriLimit sysAgriLimit)
    {
        return toAjax(sysAgriLimitService.updateSysAgriLimit(sysAgriLimit));
    }

    /**
     * 删除执行时间限位管理
     */
    @PreAuthorize("@ss.hasPermi('assets:limit:remove')")
    @Log(title = "执行时间限位管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(sysAgriLimitService.deleteSysAgriLimitByIds(ids));
    }

    @Log(title = "大棚运行时间限位查询", businessType = BusinessType.SELECT)
    @GetMapping("/getAgriByImei/{imei}")
    public AjaxResult getAgriByImei(@PathVariable String imei)
    {
        SysAgriLimit agriLimit = sysAgriLimitService.lambdaQuery().eq(SysAgriLimit::getImei, imei).one();

        return success(agriLimit);
    }

}
