package com.yanzhu.jh.project.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

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.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.yanzhu.jh.project.domain.SmzProjectQuarterlyAssess;
import com.yanzhu.jh.project.service.ISmzProjectQuarterlyAssessService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目季度考核Controller
 * 
 * @author ruoyi
 * @date 2023-08-05
 */
@RestController
@RequestMapping("/project/assess")
public class SmzProjectQuarterlyAssessController extends BaseController
{
    @Autowired
    private ISmzProjectQuarterlyAssessService smzProjectQuarterlyAssessService;

    /**
     * 查询项目季度考核列表
     */
    @PreAuthorize("@ss.hasPermi('project:assess:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmzProjectQuarterlyAssess smzProjectQuarterlyAssess)
    {
        //startPage();
        List<SmzProjectQuarterlyAssess> list = smzProjectQuarterlyAssessService.selectSmzProjectQuarterlyAssessList(smzProjectQuarterlyAssess);
        return getDataTable(list);
    }

    /**
     * 导出项目季度考核列表
     */
    @PreAuthorize("@ss.hasPermi('project:assess:export')")
    @Log(title = "项目季度考核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmzProjectQuarterlyAssess smzProjectQuarterlyAssess)
    {
        List<SmzProjectQuarterlyAssess> list = smzProjectQuarterlyAssessService.selectSmzProjectQuarterlyAssessList(smzProjectQuarterlyAssess);
        ExcelUtil<SmzProjectQuarterlyAssess> util = new ExcelUtil<SmzProjectQuarterlyAssess>(SmzProjectQuarterlyAssess.class);
        util.exportExcel(response, list, "项目季度考核数据");
    }

    /**
     * 获取项目季度考核详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:assess:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(smzProjectQuarterlyAssessService.selectSmzProjectQuarterlyAssessById(id));
    }

    /**
     * 新增项目季度考核
     */
    @PreAuthorize("@ss.hasPermi('project:assess:add')")
    @Log(title = "项目季度考核", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmzProjectQuarterlyAssess smzProjectQuarterlyAssess)
    {
        return toAjax(smzProjectQuarterlyAssessService.insertSmzProjectQuarterlyAssess(smzProjectQuarterlyAssess));
    }

    /**
     * 修改项目季度考核
     */
    @PreAuthorize("@ss.hasPermi('project:assess:edit')")
    @Log(title = "项目季度考核", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmzProjectQuarterlyAssess smzProjectQuarterlyAssess)
    {
        return toAjax(smzProjectQuarterlyAssessService.updateSmzProjectQuarterlyAssess(smzProjectQuarterlyAssess));
    }

    /**
     * 删除项目季度考核
     */
    @PreAuthorize("@ss.hasPermi('project:assess:remove')")
    @Log(title = "项目季度考核", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smzProjectQuarterlyAssessService.deleteSmzProjectQuarterlyAssessByIds(ids));
    }


    @PreAuthorize("@ss.hasPermi('project:assess:add')")
    @Log(title = "项目季度考核-增加年份", businessType = BusinessType.INSERT)
    @PostMapping("/addYear")
    public AjaxResult addYear(@RequestBody SmzProjectQuarterlyAssess smzProjectQuarterlyAssess){
        List list=smzProjectQuarterlyAssessService.selectSmzProjectQuarterlyAssessList(smzProjectQuarterlyAssess);
        if(list.size()>0){
            return AjaxResult.error(500,"此年份已有数据!");
        }

        smzProjectQuarterlyAssessService.addYear(smzProjectQuarterlyAssess);
        return AjaxResult.success("成功");
    }



}
