package com.ruoyi.project.ehs.controller;

import java.util.Date;
import java.util.List;
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.ehs.domain.TEhskpinew;
import com.ruoyi.project.ehs.service.ITEhskpinewService;
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;

/**
 * KPI统计及格Controller
 *
 * @author ruoyi
 * @date 2020-12-01
 */
@RestController
@RequestMapping("/ehs/ehskpinew")
public class TEhskpinewController extends BaseController
{
    @Autowired
    private ITEhskpinewService tEhskpinewService;

    /**
     * 查询KPI统计及格列表
     */
    @PreAuthorize("@ss.hasPermi('ehs:ehskpinew:list')")
    @GetMapping("/list")
    public TableDataInfo list(TEhskpinew tEhskpinew)
    {
        startPage();
        List<TEhskpinew> list = tEhskpinewService.selectTEhskpinewList(tEhskpinew);
        return getDataTable(list);
    }

    /**
     * 导出KPI统计及格列表
     */
    @PreAuthorize("@ss.hasPermi('ehs:ehskpinew:export')")
    @Log(title = "KPI统计及格", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TEhskpinew tEhskpinew)
    {
        List<TEhskpinew> list = tEhskpinewService.selectTEhskpinewList(tEhskpinew);
        ExcelUtil<TEhskpinew> util = new ExcelUtil<TEhskpinew>(TEhskpinew.class);
        return util.exportExcel(list, "ehskpinew");
    }

    /**
     * 获取KPI统计及格详细信息
     */
    @PreAuthorize("@ss.hasPermi('ehs:ehskpinew:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tEhskpinewService.selectTEhskpinewById(id));
    }

    /**
     * 新增KPI统计及格
     */
    @PreAuthorize("@ss.hasPermi('ehs:ehskpinew:add')")
    @Log(title = "KPI统计及格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TEhskpinew tEhskpinew)
    {
        if (tEhskpinew.toString() == null) {
            tEhskpinew.setFirstquarterStatus(null);
        }else if (tEhskpinew.getFirstquarterStatus() != null) {
        }else {
            tEhskpinew.setFirstquarterStatus("2");
        }
        if (tEhskpinew.getSummer() == null) {
            tEhskpinew.setSecondquarterStatus(null);
        }else if (tEhskpinew.getSecondquarterStatus() != null) {
        }else {
            tEhskpinew.setSecondquarterStatus("2");
        }
        if (tEhskpinew.getAutumn() == null) {
            tEhskpinew.setThreequarterStatus(null);
        }else if (tEhskpinew.getThreequarterStatus() != null) {
        }else {
            tEhskpinew.setThreequarterStatus("2");
        }
        if (tEhskpinew.getWinter() == null) {
            tEhskpinew.setFourquarterStatus(null);
        }else if (tEhskpinew.getFourquarterStatus() != null) {
        }else {
            tEhskpinew.setFourquarterStatus("2");
        }
        if (tEhskpinew.getAnnual() == null) {
            tEhskpinew.setAnnualStatus(null);
        }else if (tEhskpinew.getAnnualStatus() != null) {
        }else {
            tEhskpinew.setAnnualStatus("2");
        }
        tEhskpinew.setCreaterCode(getUserId().toString());
        return toAjax(tEhskpinewService.insertTEhskpinew(tEhskpinew));
    }

    /**
     * 修改KPI统计及格
     */
    @PreAuthorize("@ss.hasPermi('ehs:ehskpinew:edit')")
    @Log(title = "KPI统计及格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TEhskpinew tEhskpinew)
    {
        tEhskpinew.setUpdaterCode(getUserId().toString());
        tEhskpinew.setUpdatedate(new Date());
        if (tEhskpinew.getSpring() == null) {
            tEhskpinew.setFirstquarterStatus(null);
        }else if (tEhskpinew.getFirstquarterStatus() != null) {
        }else {
            tEhskpinew.setFirstquarterStatus("2");
        }
        if (tEhskpinew.getSummer() == null) {
            tEhskpinew.setSecondquarterStatus(null);
        }else if (tEhskpinew.getSecondquarterStatus() != null) {
        }else {
            tEhskpinew.setSecondquarterStatus("2");
        }
        if (tEhskpinew.getAutumn() == null) {
            tEhskpinew.setThreequarterStatus(null);
        }else if (tEhskpinew.getThreequarterStatus() != null) {
        }else {
            tEhskpinew.setThreequarterStatus("2");
        }
        if (tEhskpinew.getWinter() == null) {
            tEhskpinew.setFourquarterStatus(null);
        }else if (tEhskpinew.getFourquarterStatus() != null) {
        }else {
            tEhskpinew.setFourquarterStatus("2");
        }
        if (tEhskpinew.getAnnual() == null) {
            tEhskpinew.setAnnualStatus(null);
        }else if (tEhskpinew.getAnnualStatus() != null) {
        }else {
            tEhskpinew.setAnnualStatus("2");
        }
        return toAjax(tEhskpinewService.updateTEhskpinew(tEhskpinew));
    }

    /**
     * 删除KPI统计及格
     */
    @PreAuthorize("@ss.hasPermi('ehs:ehskpinew:remove')")
    @Log(title = "KPI统计及格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tEhskpinewService.deleteTEhskpinewByIds(ids));
    }
}
