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.TMtOpextrack;
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.TMtRiskreminder;
import com.ruoyi.project.plant.service.ITMtRiskreminderService;
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 2021-01-04
 */
@RestController
@RequestMapping("/plant/riskreminder")
public class TMtRiskreminderController extends BaseController
{
    @Autowired
    private ITMtRiskreminderService tMtRiskreminderService;
    @Autowired
    private TMtMeetingController tMtMeetingController;
    @Autowired
    private ISysUserService sysUserService;
    /**
     * 查询风险提醒列表
     */
    @PreAuthorize("@ss.hasPermi('plant:meeting:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMtRiskreminder tMtRiskreminder)
    {
        startPage();
        List<TMtRiskreminder> list = tMtRiskreminderService.selectTMtRiskreminderList(tMtRiskreminder);
        for (TMtRiskreminder t:list
        ) {
            if (t.getUpdaterCode() != null) {
                SysUser updater = sysUserService.selectUserById( Long.parseLong(t.getUpdaterCode()));
                t.setUpdaterCode(updater.getNickName());
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出风险提醒列表
     */
    @PreAuthorize("@ss.hasPermi('plant:meeting:export')")
    @Log(title = "风险提醒", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TMtRiskreminder tMtRiskreminder)
    {
        List<TMtRiskreminder> list = tMtRiskreminderService.selectTMtRiskreminderList(tMtRiskreminder);
        ExcelUtil<TMtRiskreminder> util = new ExcelUtil<TMtRiskreminder>(TMtRiskreminder.class);
        return util.exportExcel(list, "riskreminder");
    }

    /**
     * 获取风险提醒详细信息
     */
    @PreAuthorize("@ss.hasPermi('plant:meeting:list')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tMtRiskreminderService.selectTMtRiskreminderById(id));
    }

    /**
     * 新增风险提醒
     */
    @PreAuthorize("@ss.hasPermi('plant:riskreminder:edit')")
    @Log(title = "风险提醒", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping
    public AjaxResult add(@RequestBody TMtRiskreminder tMtRiskreminder)
    {
        tMtRiskreminder.setUpdatedate(new Date());
        tMtRiskreminder.setUpdaterCode(getUserId() + "");
        tMtRiskreminder.setCreaterCode(getUserId() + "");
        if (tMtRiskreminder.getIsHis() != null && tMtRiskreminder.getIsHis() == 1) {
            tMtMeetingController.getReport(null,tMtRiskreminder.getMeetingId());
        }
        return toAjax(tMtRiskreminderService.insertTMtRiskreminder(tMtRiskreminder));
    }

    /**
     * 修改风险提醒
     */
    @PreAuthorize("@ss.hasPermi('plant:riskreminder:edit')")
    @Log(title = "风险提醒", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping
    public AjaxResult edit(@RequestBody TMtRiskreminder tMtRiskreminder)
    {
        tMtRiskreminder.setUpdatedate(new Date());
        tMtRiskreminder.setUpdaterCode(getUserId() + "");
        if (tMtRiskreminder.getIsHis() != null && tMtRiskreminder.getIsHis() == 1) {

            tMtMeetingController.getReport(null,tMtRiskreminder.getMeetingId());
        }
        return toAjax(tMtRiskreminderService.updateTMtRiskreminder(tMtRiskreminder));
    }

    /**
     * 删除风险提醒
     */
    @PreAuthorize("@ss.hasPermi('plant:riskreminder:edit')")
    @Log(title = "风险提醒", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tMtRiskreminderService.deleteTMtRiskreminderByIds(ids));
    }
}
