package com.ruoyi.project.sems.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.sems.domain.TMeasureLoop;
import com.ruoyi.project.sems.mapper.TMeasureLoopMapper;
import com.ruoyi.project.sems.service.ITMeasureLoopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 腐蚀回路图管理Controller
 *
 * @author ly
 * @date 2024-12-16
 */
@RestController
@RequestMapping("/sems/loop")
public class TMeasureLoopController extends BaseController
{
    @Autowired
    private ITMeasureLoopService tMeasureLoopService;
    @Resource
    private TMeasureLoopMapper tMeasureLoopMapper;
    /**
     * 查询腐蚀回路图管理列表
     */
    @PreAuthorize("@ss.hasPermi('sems:loop:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMeasureLoop tMeasureLoop)
    {
        startPage();
        List<TMeasureLoop> list = tMeasureLoopService.selectTMeasureLoopList(tMeasureLoop);
        return getDataTable(list);
    }

    /**
     * 查询腐蚀回路图管理列表
     */
    @GetMapping("/getLoopByPlant")
    public AjaxResult getLoopByPlant(TMeasureLoop tMeasureLoop)
    {
        List<TMeasureLoop> list = tMeasureLoopMapper.selectTMeasureLoopByPlant(tMeasureLoop);
        return AjaxResult.success(list);
    }

    @GetMapping("/queryUrl")
    public AjaxResult queryUrl(TMeasureLoop tMeasureLoop)
    {
        List<TMeasureLoop> list = tMeasureLoopService.selectTMeasureLoopUrl(tMeasureLoop);
        if (list.size() > 0) {
            return AjaxResult.success(list.get(0));
        }else {
            return AjaxResult.error("无匹配文件");
        }
    }

    /**
     * 导出腐蚀回路图管理列表
     */
    @PreAuthorize("@ss.hasPermi('sems:loop:export')")
    @Log(title = "腐蚀回路图管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TMeasureLoop tMeasureLoop)
    {
        List<TMeasureLoop> list = tMeasureLoopService.selectTMeasureLoopList(tMeasureLoop);
        ExcelUtil<TMeasureLoop> util = new ExcelUtil<TMeasureLoop>(TMeasureLoop.class);
        return util.exportExcel(list, "loop");
    }

    /**
     * 获取腐蚀回路图管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('sems:loop:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tMeasureLoopService.selectTMeasureLoopById(id));
    }

    /**
     * 新增腐蚀回路图管理
     */
    @PreAuthorize("@ss.hasPermi('sems:loop:add')")
    @Log(title = "腐蚀回路图管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMeasureLoop tMeasureLoop)
    {
        return toAjax(tMeasureLoopService.insertTMeasureLoop(tMeasureLoop));
    }

    /**
     * 修改腐蚀回路图管理
     */
    @PreAuthorize("@ss.hasPermi('sems:loop:edit')")
    @Log(title = "腐蚀回路图管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMeasureLoop tMeasureLoop)
    {
        return toAjax(tMeasureLoopService.updateTMeasureLoop(tMeasureLoop));
    }

    /**
     * 删除腐蚀回路图管理
     */
    @PreAuthorize("@ss.hasPermi('sems:loop:remove')")
    @Log(title = "腐蚀回路图管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tMeasureLoopService.deleteTMeasureLoopByIds(ids));
    }
}
