package com.yanzhu.jh.project.controller;

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

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.enums.SysRoleEnum;
import com.ruoyi.system.service.ISysDeptService;
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.SurProject;
import com.yanzhu.jh.project.service.ISurProjectService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目管理Controller
 * 
 * @author JiangYuQi
 * @date 2023-07-29
 */
@RestController
@RequestMapping("/project/surProject")
public class SurProjectController extends BaseController
{
    @Autowired
    private ISurProjectService surProjectService;

    @Autowired
    private ISysDeptService sysDeptService;

    /**
     * 查询项目管理列表
     */
    @PreAuthorize("@ss.hasPermi('project:surProject:list')")
    @GetMapping("/list")
    public TableDataInfo list(SurProject surProject)
    {

        surProject.setNowRole(Convert.toStr(getUserFirstRole()));
        if(SysRoleEnum.ZGS.getCode().equals(surProject.getNowRole())){
            surProject.setNowDept(Convert.toStr(sysDeptService.getZGSDeptId(getDeptId())));
        }else{
            surProject.setNowDept(Convert.toStr(getDeptId()));
        }
        surProject.setNowUser(Convert.toStr(getUserId()));
        startPage();
        List<SurProject> list = surProjectService.selectSurProjectList(surProject);
        return getDataTable(list);
    }

    /**
     * 导出项目管理列表
     */
    @PreAuthorize("@ss.hasPermi('project:surProject:export')")
    @Log(title = "项目管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SurProject surProject)
    {
        surProject.setNowRole(Convert.toStr(getUserFirstRole()));
        if(SysRoleEnum.ZGS.getCode().equals(surProject.getNowRole())){
            surProject.setNowDept(Convert.toStr(sysDeptService.getZGSDeptId(getDeptId())));
        }else{
            surProject.setNowDept(Convert.toStr(getDeptId()));
        }
        surProject.setNowUser(Convert.toStr(getUserId()));
        List<SurProject> list = surProjectService.selectSurProjectList(surProject);
        ExcelUtil<SurProject> util = new ExcelUtil<SurProject>(SurProject.class);
        util.exportExcel(response, list, "项目管理数据");
    }

    /**
     * 获取项目管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:surProject:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(surProjectService.selectSurProjectById(id));
    }

    /**
     * 新增项目管理
     */
    @PreAuthorize("@ss.hasPermi('project:surProject:add')")
    @Log(title = "项目管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SurProject surProject)
    {
        return toAjax(surProjectService.insertSurProject(surProject));
    }

    /**
     * 修改项目管理
     */
    @PreAuthorize("@ss.hasPermi('project:surProject:edit')")
    @Log(title = "项目管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SurProject surProject)
    {
        return toAjax(surProjectService.updateSurProject(surProject));
    }

    /**
     * 删除项目管理
     */
    @PreAuthorize("@ss.hasPermi('project:surProject:remove')")
    @Log(title = "项目管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(surProjectService.deleteSurProjectByIds(ids));
    }

    /**
     * 修改项目形象进度展示
     */
    @PreAuthorize("@ss.hasPermi('project:surProject:progressVisible')")
    @Log(title = "项目管理", businessType = BusinessType.UPDATE)
    @PostMapping("/editProgressVisible")
    public AjaxResult editProgressVisible(@RequestBody SurProject surProject)
    {
        return toAjax(surProjectService.updateSurProject(surProject));
    }

    /**
     * 修改项目排序
     */
    @PreAuthorize("@ss.hasPermi('project:surProject:projectSort')")
    @Log(title = "项目管理", businessType = BusinessType.UPDATE)
    @PostMapping("/editProjectSort")
    public AjaxResult editProjectSort(@RequestBody SurProject surProject)
    {
        return toAjax(surProjectService.updateSurProject(surProject));
    }
}
