package com.yanzhu.project.controller;

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

import com.yanzhu.common.core.domain.entity.SysUser;
import com.yanzhu.common.core.text.Convert;
import com.yanzhu.common.enums.ShiFouEnum;
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.yanzhu.common.annotation.Log;
import com.yanzhu.common.core.controller.BaseController;
import com.yanzhu.common.core.domain.AjaxResult;
import com.yanzhu.common.enums.BusinessType;
import com.yanzhu.project.domain.ProProjectInfo;
import com.yanzhu.project.service.IProProjectInfoService;
import com.yanzhu.common.utils.poi.ExcelUtil;
import com.yanzhu.common.core.page.TableDataInfo;

/**
 * 项目信息Controller
 * 
 * @author yanZhu
 * @date 2024-02-23
 */
@RestController
@RequestMapping("/project/projectInfo")
public class ProProjectInfoController extends BaseController
{
    @Autowired
    private IProProjectInfoService proProjectInfoService;

    /**
     * 查询项目信息列表
     */
    @PreAuthorize("@ss.hasPermi('project:projectInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProProjectInfo proProjectInfo)
    {
        startPage();
        List<ProProjectInfo> list = proProjectInfoService.selectProProjectInfoList(proProjectInfo);
        return getDataTable(list);
    }

    /**
     * 导出项目信息列表
     */
    @PreAuthorize("@ss.hasPermi('project:projectInfo:export')")
    @Log(title = "项目信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProProjectInfo proProjectInfo)
    {
        List<ProProjectInfo> list = proProjectInfoService.selectProProjectInfoList(proProjectInfo);
        ExcelUtil<ProProjectInfo> util = new ExcelUtil<ProProjectInfo>(ProProjectInfo.class);
        util.exportExcel(response, list, "项目信息数据");
    }

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

    /**
     * 新增项目信息
     */
    @PreAuthorize("@ss.hasPermi('project:projectInfo:add')")
    @Log(title = "项目信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProProjectInfo proProjectInfo)
    {
        return toAjax(proProjectInfoService.insertProProjectInfo(proProjectInfo));
    }

    /**
     * 修改项目信息
     */
    @PreAuthorize("@ss.hasPermi('project:projectInfo:edit')")
    @Log(title = "项目信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProProjectInfo proProjectInfo)
    {
        return toAjax(proProjectInfoService.updateProProjectInfo(proProjectInfo));
    }

    /**
     * 删除项目信息
     */
    @PreAuthorize("@ss.hasPermi('project:projectInfo:remove')")
    @Log(title = "项目信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(proProjectInfoService.deleteProProjectInfoByIds(ids));
    }

    /**
     * 获取项目信息详细信息
     */
    @GetMapping(value = "/findMyDeptProject")
    public AjaxResult findMyDeptProject()
    {
        ProProjectInfo proProjectInfo = new ProProjectInfo();
        //超管查询所有数据
        if(!SysUser.isAdmin(super.getUserId())){
            proProjectInfo.setDeptId(Convert.toLong(super.getLoginUser().getUser().getDept().getAncestors().split(",")[2]));
        }
        proProjectInfo.setIsDel(ShiFouEnum.FOU.getCode());
        List<ProProjectInfo> list = proProjectInfoService.selectProProjectInfoList(proProjectInfo);
        return success(list);
    }
}
