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.SysDtuRemark;
import com.agri.system.service.ISysDtuRemarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * dtu设备备注Controller
 *
 * @author lld
 * @date 2026-01-21
 */
@RestController
@RequestMapping("/assets/remark")
public class SysDtuRemarkController extends BaseController
{
    @Autowired
    private ISysDtuRemarkService sysDtuRemarkService;

    /**
     * 查询dtu设备备注列表
     */
    @PreAuthorize("@ss.hasPermi('assets:remark:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysDtuRemark sysDtuRemark)
    {
        startPage();
        List<SysDtuRemark> list = sysDtuRemarkService.selectSysDtuRemarkList(sysDtuRemark);
        return getDataTable(list);
    }

    /**
     * 导出dtu设备备注列表
     */
    @PreAuthorize("@ss.hasPermi('assets:remark:export')")
    @Log(title = "dtu设备备注", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysDtuRemark sysDtuRemark)
    {
        List<SysDtuRemark> list = sysDtuRemarkService.selectSysDtuRemarkList(sysDtuRemark);
        ExcelUtil<SysDtuRemark> util = new ExcelUtil<SysDtuRemark>(SysDtuRemark.class);
        util.exportExcel(response, list, "dtu设备备注数据");
    }

    /**
     * 获取dtu设备备注详细信息
     */
    @PreAuthorize("@ss.hasPermi('assets:remark:list')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysDtuRemarkService.selectSysDtuRemarkById(id));
    }

    /**
     * 新增dtu设备备注
     */
    @PreAuthorize("@ss.hasPermi('assets:remark:add')")
    @Log(title = "dtu设备备注", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDtuRemark sysDtuRemark)
    {
        return toAjax(sysDtuRemarkService.insertSysDtuRemark(sysDtuRemark));
    }

    /**
     * 修改dtu设备备注
     */
    @PreAuthorize("@ss.hasPermi('assets:remark:edit')")
    @Log(title = "dtu设备备注", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDtuRemark sysDtuRemark)
    {
        return toAjax(sysDtuRemarkService.updateSysDtuRemark(sysDtuRemark));
    }

    /**
     * 删除dtu设备备注
     */
    @PreAuthorize("@ss.hasPermi('assets:remark:remove')")
    @Log(title = "dtu设备备注", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysDtuRemarkService.deleteSysDtuRemarkByIds(ids));
    }


    /**
     * 获取dtu设备备注详细信息
     */
    @PreAuthorize("@ss.hasPermi('assets:remark:list')")
    @GetMapping(value = "/getDtuByImei")
    public AjaxResult getDtuByImei(@RequestParam("imei") String imei)
    {
        SysDtuRemark sysDtuRemark = sysDtuRemarkService.lambdaQuery().eq(SysDtuRemark::getImei, imei).one();
        return success(sysDtuRemark);
    }



}
