package com.ruoyi.web.controller.project;

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

import com.ruoyi.system.domain.project.BmDeptPlan;
import com.ruoyi.system.domain.vo.BmDeptPlanVo;
import com.ruoyi.system.service.project.IBmDeptPlanService;
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.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 部门招商计划Controller
 *
 * @author ruoyi
 * @date 2021-03-09
 */
@RestController
@RequestMapping("/deptPlan/plan")
public class BmDeptPlanController extends BaseController {
    @Autowired
    private IBmDeptPlanService bmDeptPlanService;

    /**
     * 查询 部门招商计划列表
     */
    @PreAuthorize("@ss.hasPermi('deptPlan:Plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(BmDeptPlan bmDeptPlan) {
        startPage();
        List<BmDeptPlan> list = bmDeptPlanService.selectBmDeptPlanList(bmDeptPlan);
        return getDataTable(list);
    }

    /**
     * 导出 部门招商计划列表
     */
    @PreAuthorize("@ss.hasPermi('deptPlan:Plan:export')")
    @Log(title = " 部门招商计划", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BmDeptPlan bmDeptPlan) {
        List<BmDeptPlan> list = bmDeptPlanService.selectBmDeptPlanList(bmDeptPlan);
        ExcelUtil<BmDeptPlan> util = new ExcelUtil<BmDeptPlan>(BmDeptPlan.class);
        return util.exportExcel(list, "Plan");
    }

    /**
     * 获取 部门招商计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('deptPlan:Plan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(bmDeptPlanService.selectBmDeptPlanById(id));
    }

    /**
     * 新增 部门招商计划
     */
    @PreAuthorize("@ss.hasPermi('deptPlan:Plan:add')")
    @Log(title = " 部门招商计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BmDeptPlan bmDeptPlan) {
        return toAjax(bmDeptPlanService.insertBmDeptPlan(bmDeptPlan));
    }

    /**
     * 修改 部门招商计划
     */
    @PreAuthorize("@ss.hasPermi('deptPlan:Plan:edit')")
    @Log(title = " 部门招商计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BmDeptPlan bmDeptPlan) {
        return toAjax(bmDeptPlanService.updateBmDeptPlan(bmDeptPlan));
    }

    /**
     * 删除 部门招商计划
     */
    @PreAuthorize("@ss.hasPermi('deptPlan:Plan:remove')")
    @Log(title = " 部门招商计划", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bmDeptPlanService.deleteBmDeptPlanByIds(ids));
    }

    /**
     * 首页-单位榜单
     */
    @PreAuthorize("@ss.hasPermi('deptPlan:Plan:unitList')")
    @Log(title = " 单位榜单", businessType = BusinessType.INSERT)
    @PostMapping("/unitList")
    public TableDataInfo unitList() {
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanService.selectUnitList();
        return getDataTable(bmDeptPlanVos);
    }

    /**
     * 首页-单位榜单资金
     */
    @PreAuthorize("@ss.hasPermi('deptPlan:Plan:unitAmountList')")
    @Log(title = " 单位榜单资金", businessType = BusinessType.INSERT)
    @PostMapping("/unitAmountList")
    public TableDataInfo unitAmountList() {
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanService.selectUnitAmountList();
        return getDataTable(bmDeptPlanVos);
    }

    /**
     * 统计分析-合同金额
     */
    @PreAuthorize("@ss.hasPermi('deptPlan:Plan:totAmtList')")
    @Log(title = " 统计分析-合同金额", businessType = BusinessType.INSERT)
    @PostMapping("/totAmtList")
    public TableDataInfo totAmtList() {
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanService.selectTotAmtList();
        return getDataTable(bmDeptPlanVos);
    }


    /**
     * 统计分析-在建项目-柱状图
     */
    @GetMapping("/projectUnitAmountEharts")
    public AjaxResult projectUnitAmountEharts(String year) {
        Map<String, Object> map = bmDeptPlanService.selectProjectUnitAmountEharts(year);
        return AjaxResult.success(map);
    }

    /**
     * 统计分析-入归榜单
     */
    //@PreAuthorize("@ss.hasPermi('deptPlan:Plan:totAmtList')")
    @PostMapping("/investmentList")
    public TableDataInfo investmentList() {
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanService.selectInvestmentList();
        return getDataTable(bmDeptPlanVos);
    }

    /**
     * 统计分析-投产项目-柱状图
     */
    @GetMapping("/projectInvestmentEharts")
    public AjaxResult projectInvestmentEharts(String year) {
        Map<String, Object> map = bmDeptPlanService.selectProjectInvestmentEharts(year);
        return AjaxResult.success(map);
    }
}
