package com.ruoyi.project.intact.his.controller;

import java.util.List;

import com.ruoyi.project.intact.his.domain.TIntactHiPump;
import com.ruoyi.project.intact.his.service.ITIntactHiPumpService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
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.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 设备完整性泵台账历史记录Controller
 *
 * @author ruoyi
 * @date 2022-06-29
 */
@RestController
@RequestMapping("/his/pump")
public class TIntactHiPumpController extends BaseController
{
    @Autowired
    private ITIntactHiPumpService tIntactHiPumpService;

    /**
     * 查询设备完整性泵台账历史记录列表
     */
    @PreAuthorize("@ss.hasPermi('intact:pump:list')")
    @GetMapping("/list")
    public TableDataInfo list(TIntactHiPump tIntactHiPump)
    {
        startPage();
        List<TIntactHiPump> list = tIntactHiPumpService.selectTIntactHiPumpList(tIntactHiPump);
        return getDataTable(list);
    }

    /**
     * 导出设备完整性泵台账历史记录列表
     */
    @PreAuthorize("@ss.hasPermi('intact:pump:export')")
    @Log(title = "设备完整性泵台账历史记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TIntactHiPump tIntactHiPump)
    {
        List<TIntactHiPump> list = tIntactHiPumpService.selectTIntactHiPumpList(tIntactHiPump);
        ExcelUtil<TIntactHiPump> util = new ExcelUtil<TIntactHiPump>(TIntactHiPump.class);
        return util.exportExcel(list, "pump");
    }

    /**
     * 获取设备完整性泵台账历史记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('intact:pump:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tIntactHiPumpService.selectTIntactHiPumpById(id));
    }


    /**
     * 获取泵台账历史改造历史
     */
    @PreAuthorize("@ss.hasPermi('sems:specYlrq:query')")
    @GetMapping(value = "/reform/{devId}")
    public AjaxResult getReform(@PathVariable("devId") Long devId)
    {

        return AjaxResult.success(tIntactHiPumpService.selectTIntactHiPumpByReform(devId));
    }

    /**
     * 新增设备完整性泵台账历史记录
     */
    @PreAuthorize("@ss.hasPermi('intact:pump:add')")
    @Log(title = "设备完整性泵台账历史记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TIntactHiPump tIntactHiPump)
    {

        tIntactHiPumpService.deleteTIntactHiPumpByDevId(tIntactHiPump.getId());
        tIntactHiPump.setDevId(tIntactHiPump.getId());
        tIntactHiPump.setHiType((long)1);
        tIntactHiPumpService.insertTIntactHiPump(tIntactHiPump);
        return AjaxResult.success("id" , tIntactHiPump.getId());
    }

    /**
     * 修改设备完整性泵台账历史记录
     */
    @PreAuthorize("@ss.hasPermi('intact:pump:edit')")
    @Log(title = "设备完整性泵台账历史记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TIntactHiPump tIntactHiPump)
    {
        return toAjax(tIntactHiPumpService.updateTIntactHiPump(tIntactHiPump));
    }

    /**
     * 删除设备完整性泵台账历史记录
     */
    @PreAuthorize("@ss.hasPermi('intact:pump:remove')")
    @Log(title = "设备完整性泵台账历史记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tIntactHiPumpService.deleteTIntactHiPumpByIds(ids));
    }
}
