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

import java.util.List;

import com.ruoyi.project.intact.his.domain.TIntactHiGj;
import com.ruoyi.project.intact.his.service.ITIntactHiGjService;
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/gj")
public class TIntactHiGjController extends BaseController
{
    @Autowired
    private ITIntactHiGjService tIntactHiGjService;

    /**
     * 查询设备完整性-管件台账变更历史记录列表
     */
    @PreAuthorize("@ss.hasPermi('intact:gj:list')")
    @GetMapping("/list")
    public TableDataInfo list(TIntactHiGj tIntactHiGj)
    {
        startPage();
        List<TIntactHiGj> list = tIntactHiGjService.selectTIntactHiGjList(tIntactHiGj);
        return getDataTable(list);
    }

    /**
     * 导出设备完整性-管件台账变更历史记录列表
     */
    @PreAuthorize("@ss.hasPermi('intact:gj:export')")
    @Log(title = "设备完整性-管件台账变更历史记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TIntactHiGj tIntactHiGj)
    {
        List<TIntactHiGj> list = tIntactHiGjService.selectTIntactHiGjList(tIntactHiGj);
        ExcelUtil<TIntactHiGj> util = new ExcelUtil<TIntactHiGj>(TIntactHiGj.class);
        return util.exportExcel(list, "gj");
    }

    /**
     * 获取设备完整性-管件台账变更历史记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('intact:gj:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tIntactHiGjService.selectTIntactHiGjById(id));
    }


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

        return AjaxResult.success(tIntactHiGjService.selectTIntactHiGjByReform(devId));
    }

    /**
     * 新增设备完整性-管件台账变更历史记录
     */
    @PreAuthorize("@ss.hasPermi('intact:gj:add')")
    @Log(title = "设备完整性-管件台账变更历史记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TIntactHiGj tIntactHiGj)
    {
        tIntactHiGjService.deleteTIntactHiGjByDevId(tIntactHiGj.getId());
        tIntactHiGj.setDevId(tIntactHiGj.getId());
        tIntactHiGj.setHiType((long)1);
        tIntactHiGjService.insertTIntactHiGj(tIntactHiGj);
        return AjaxResult.success("id" , tIntactHiGj.getId());
    }

    /**
     * 修改设备完整性-管件台账变更历史记录
     */
    @PreAuthorize("@ss.hasPermi('intact:gj:edit')")
    @Log(title = "设备完整性-管件台账变更历史记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TIntactHiGj tIntactHiGj)
    {
        return toAjax(tIntactHiGjService.updateTIntactHiGj(tIntactHiGj));
    }

    /**
     * 删除设备完整性-管件台账变更历史记录
     */
    @PreAuthorize("@ss.hasPermi('intact:gj:remove')")
    @Log(title = "设备完整性-管件台账变更历史记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tIntactHiGjService.deleteTIntactHiGjByIds(ids));
    }
}
