package com.ruoyi.web.controller.project;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.project.BmProject;
import com.ruoyi.system.domain.project.BmProjectStatus;
import com.ruoyi.system.service.project.IBmProjectService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目(添加线索)Controller
 *
 * @author bm
 * @date 2021-03-03
 */
@RestController
@RequestMapping("/bmProject/project")
public class BmProjectController extends BaseController {
    @Autowired
    private IBmProjectService bmProjectService;

    /**
     * 查询项目(添加线索)列表
     */
    @PreAuthorize("@ss.hasPermi('bmProject:project:list')")
    @GetMapping("/list")
    public TableDataInfo list(BmProject bmProject) {
        startPage();
        List<BmProject> list = bmProjectService.selectBmProjectList(bmProject);
        return getDataTable(list);
    }

    /**
     * 导出项目(添加线索)列表
     */
    @PreAuthorize("@ss.hasPermi('bmProject:project:export')")
    @Log(title = "项目(添加线索)", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BmProject bmProject) {
        List<BmProject> list = bmProjectService.selectBmProjectList(bmProject);
        ExcelUtil<BmProject> util = new ExcelUtil<BmProject>(BmProject.class);
        return util.exportExcel(list, "project");
    }

    /**
     * 获取项目(添加线索)详细信息
     */
    @PreAuthorize("@ss.hasPermi('bmProject:project:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(bmProjectService.selectBmProjectById(id));
    }

    /**
     * 新增项目(添加线索)
     */
    @PreAuthorize("@ss.hasPermi('bmProject:project:add')")
    @Log(title = "项目(添加线索)", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BmProject bmProject) {
        return bmProjectService.insertBmProject(bmProject);
    }

    /**
     * 修改项目(修改线索)
     */
    @PreAuthorize("@ss.hasPermi('bmProject:project:edit')")
    @Log(title = "项目(添加线索)", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BmProject bmProject) {
        return toAjax(bmProjectService.updateBmProject(bmProject));
    }

    /**
     * 删除项目(添加线索)
     */
    @PreAuthorize("@ss.hasPermi('bmProject:project:remove')")
    @Log(title = "项目(添加线索)", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bmProjectService.deleteBmProjectByIds(ids));
    }


    /**
     * 审核/提交
     * @param bmProjectStatus
     * @return
     */
    @PreAuthorize("@ss.hasPermi('bmProject:project:examine')")
    @PostMapping("/examine")
    public AjaxResult examine(@RequestBody BmProjectStatus bmProjectStatus) {
        return bmProjectService.examine(bmProjectStatus);
    }

    /**
     * 驳回项目
     * @param bmProjectStatus
     * @return
     */
    @PreAuthorize("@ss.hasPermi('bmProject:project:reject')")
    @PostMapping("/reject")
    public AjaxResult reject(@RequestBody BmProjectStatus bmProjectStatus) {
        return bmProjectService.examine(bmProjectStatus);
    }

    /**
     * 首页查询待审核列表
     */
    //@PreAuthorize("@ss.hasPermi('bmProject:project:toBeReviewedList')")
    @GetMapping("/toBeReviewedList")
    public TableDataInfo toBeReviewedList(BmProject bmProject) {
        startPage();
        List<BmProject> list = bmProjectService.selectToBeReviewedList(bmProject);
        return getDataTable(list);
    }

    /**
     * 统计分析公共查询列表
     */
    //@PreAuthorize("@ss.hasPermi('bmProject:project:statistics')")
    @GetMapping("/statistics/{projectStatus}")
    public TableDataInfo statisticsList(@PathVariable Long[] projectStatus) {
        startPage();
        List<BmProject> list = bmProjectService.selectStatisticsList(projectStatus);
        return getDataTable(list);
    }

    /**
     * 统计分析-在谈线索-柱状图
     */
    @GetMapping("/projectEharts")
    public AjaxResult projectEharts(String year) {
        Map<String, Object> stringObjectMap = bmProjectService.selectProjectEharts(year);
        return AjaxResult.success(stringObjectMap);
    }

    /**
     * 统计分析-签约项目-柱状图
     */
    @GetMapping("/projectContractEharts")
    public AjaxResult projectContractEharts(String year) {
        Map<String, Object> stringObjectMap = bmProjectService.selectProjectContractEharts(year);
        return AjaxResult.success(stringObjectMap);
    }
}
