package com.ruoyi.project.plant.controller.weekMeeting;

import java.util.Date;
import java.util.List;

import com.ruoyi.framework.interceptor.annotation.RepeatSubmit;
import com.ruoyi.project.plant.controller.TMtMeetingController;
import com.ruoyi.project.plant.domain.TMtInterlock;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.service.ISysUserService;
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.project.plant.domain.TMtOpextrack;
import com.ruoyi.project.plant.service.ITMtOpextrackService;
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;

/**
 * OpEx项目跟踪Controller
 *
 * @author ruoyi
 * @date 2021-01-04
 */
@RestController
@RequestMapping("/plant/opextrack")
public class TMtOpextrackController extends BaseController
{
    @Autowired
    private ITMtOpextrackService tMtOpextrackService;
    @Autowired
    private TMtMeetingController tMtMeetingController;
    @Autowired
    private ISysUserService sysUserService;
    /**
     * 查询OpEx项目跟踪列表
     */
    @PreAuthorize("@ss.hasPermi('plant:meeting:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMtOpextrack tMtOpextrack)
    {
        startPage();
        List<TMtOpextrack> list = tMtOpextrackService.selectTMtOpextrackList(tMtOpextrack);
        for (TMtOpextrack t:list
        ) {
            if (t.getUpdaterCode() != null) {
                SysUser updater = sysUserService.selectUserById( Long.parseLong(t.getUpdaterCode()));
                t.setUpdaterCode(updater.getNickName());
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出OpEx项目跟踪列表
     */
    @PreAuthorize("@ss.hasPermi('plant:meeting:export')")
    @Log(title = "OpEx项目跟踪", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TMtOpextrack tMtOpextrack)
    {
        List<TMtOpextrack> list = tMtOpextrackService.selectTMtOpextrackList(tMtOpextrack);
        ExcelUtil<TMtOpextrack> util = new ExcelUtil<TMtOpextrack>(TMtOpextrack.class);
        return util.exportExcel(list, "opextrack");
    }

    /**
     * 获取OpEx项目跟踪详细信息
     */
    @PreAuthorize("@ss.hasPermi('plant:meeting:list')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tMtOpextrackService.selectTMtOpextrackById(id));
    }

    /**
     * 新增OpEx项目跟踪
     */
    @PreAuthorize("@ss.hasPermi('plant:opextrack:edit')")
    @Log(title = "OpEx项目跟踪", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping
    public AjaxResult add(@RequestBody TMtOpextrack tMtOpextrack)
    {
        tMtOpextrack.setUpdatedate(new Date());
        tMtOpextrack.setUpdaterCode(getUserId() + "");
        tMtOpextrack.setCreaterCode(getUserId() + "");
        if (tMtOpextrack.getIsHis() != null && tMtOpextrack.getIsHis() == 1) {

                tMtMeetingController.getReport(null,tMtOpextrack.getMeetingId());
        }
        return toAjax(tMtOpextrackService.insertTMtOpextrack(tMtOpextrack));
    }

    /**
     * 修改OpEx项目跟踪
     */
    @PreAuthorize("@ss.hasPermi('plant:opextrack:edit')")
    @Log(title = "OpEx项目跟踪", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping
    public AjaxResult edit(@RequestBody TMtOpextrack tMtOpextrack)
    {
        tMtOpextrack.setUpdatedate(new Date());
        tMtOpextrack.setUpdaterCode(getUserId() + "");
        if (tMtOpextrack.getIsHis() != null && tMtOpextrack.getIsHis() == 1) {

            tMtMeetingController.getReport(null,tMtOpextrack.getMeetingId());
        }
        return toAjax(tMtOpextrackService.updateTMtOpextrack(tMtOpextrack));
    }

    /**
     * 删除OpEx项目跟踪
     */
    @PreAuthorize("@ss.hasPermi('plant:opextrack:edit')")
    @Log(title = "OpEx项目跟踪", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tMtOpextrackService.deleteTMtOpextrackByIds(ids));
    }
}
