package com.ruoyi.web.controller.project;

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

import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
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
    @RepeatSubmit
    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));
    }

    /**
     * 首页-市值榜单
     */
    @Log(title = "市值榜单", businessType = BusinessType.INSERT)
    @PostMapping("/unitList")
    public TableDataInfo unitList(String year) {
        if (StringUtils.isBlank(year)){
            year = DateUtils.getYear();
        }
        List<BmDeptPlan> bmDeptPlanList = bmDeptPlanService.selectUnitList(year);
        return getDataTable(bmDeptPlanList);
    }

    /**
     * 统计分析-在谈线索-两区及乡镇
     */
    @Log(title = " 两区及乡镇榜单", businessType = BusinessType.INSERT)
    @PostMapping("/unitClueList")
    public TableDataInfo unitClueList( String year) {
        if (StringUtils.isBlank(year)){
            year = DateUtils.getYear();
        }
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanService.selectUnitClueList(year);
        return getDataTable(bmDeptPlanVos);
    }


    /**
     * 统计分析-在谈线索-市直榜单
     */
    @Log(title = " 市直榜单", businessType = BusinessType.INSERT)
    @PostMapping("/unitClueListCity")
    public TableDataInfo unitClueListCity( String year) {
        if (StringUtils.isBlank(year)){
            year = DateUtils.getYear();
        }
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanService.selectUnitClueCityList(year);
        return getDataTable(bmDeptPlanVos);
    }


    /**
     * 统计分析-签约项目-两区及乡镇榜单
     */
    @Log(title = " 目标签约数", businessType = BusinessType.INSERT)
    @PostMapping("/targetSigningList")
    public TableDataInfo targetSigningList(String year) {
        if (StringUtils.isBlank(year)){
            year = DateUtils.getYear();
        }
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanService.selectTargetSigningList(year);
        return getDataTable(bmDeptPlanVos);
    }

    /**
     * 统计分析-签约项目-市直榜单
     */
    @Log(title = " 统计分析-合同金额", businessType = BusinessType.INSERT)
    @PostMapping("/totAmtList")
    public TableDataInfo totAmtList( String year) {
        if (StringUtils.isBlank(year)){
            year = DateUtils.getYear();
        }
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanService.selectTotAmtList(year);
        return getDataTable(bmDeptPlanVos);
    }

    /**
     * 统计分析-在建项目-市直榜单
     */
    @PostMapping("/projectUnitAmountUnit")
    public AjaxResult projectUnitAmountUnit( String year) {
        if (StringUtils.isBlank(year)){
            year = DateUtils.getYear();
        }
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanService.selectProjectUnitAmountUnit(year);
        return AjaxResult.success(bmDeptPlanVos);
    }

    /**
     * 统计分析-在建项目-两区及乡镇
     */
    @PostMapping("/projectAreaAmountUnit")
    public AjaxResult projectAreaAmountUnit( String year) {
        if (StringUtils.isBlank(year)){
            year = DateUtils.getYear();
        }
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanService.selectProjectAreaAmountUnit(year);
        return AjaxResult.success(bmDeptPlanVos);
    }

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

    /**
     * 统计分析-投产项目-两区及乡镇入归榜单
     */
    @PostMapping("/investmentList")
    public TableDataInfo investmentList( String year) {
        if (StringUtils.isBlank(year)){
            year = DateUtils.getYear();
        }
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanService.selectInvestmentList(year);
        return getDataTable(bmDeptPlanVos);
    }

    /**
     * 统计分析-投产项目-市直榜单
     */
    @PostMapping("/investmentCityList")
    public TableDataInfo investmentCityList( String year) {
        if (StringUtils.isBlank(year)){
            year = DateUtils.getYear();
        }
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanService.selectInvestmentCityList(year);
        return getDataTable(bmDeptPlanVos);
    }

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