package com.ruoyi.web.controller.project;

import java.util.List;

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

/**
 * 两区及乡镇单位部门招商计划Controller
 * 
 * @author ruoyi
 * @date 2021-07-05
 */
@RestController
@RequestMapping("/dept/area")
public class BmDeptPlanAreaController extends BaseController
{
    @Autowired
    private IBmDeptPlanAreaService bmDeptPlanAreaService;

    /**
     * 查询两区及乡镇单位部门招商计划列表
     */
    @PreAuthorize("@ss.hasPermi('dept:area:list')")
    @GetMapping("/list")
    public TableDataInfo list(BmDeptPlanArea bmDeptPlanArea)
    {
        startPage();
        List<BmDeptPlanArea> list = bmDeptPlanAreaService.selectBmDeptPlanAreaList(bmDeptPlanArea);
        return getDataTable(list);
    }

    /**
     * 导出两区及乡镇单位部门招商计划列表
     */
    @PreAuthorize("@ss.hasPermi('dept:area:export')")
    @Log(title = "两区及乡镇单位部门招商计划", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BmDeptPlanArea bmDeptPlanArea)
    {
        List<BmDeptPlanArea> list = bmDeptPlanAreaService.selectBmDeptPlanAreaList(bmDeptPlanArea);
        ExcelUtil<BmDeptPlanArea> util = new ExcelUtil<BmDeptPlanArea>(BmDeptPlanArea.class);
        return util.exportExcel(list, "area");
    }

    /**
     * 获取两区及乡镇单位部门招商计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('dept:area:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bmDeptPlanAreaService.selectBmDeptPlanAreaById(id));
    }

    /**
     * 新增两区及乡镇单位部门招商计划
     */
    @PreAuthorize("@ss.hasPermi('dept:area:add')")
    @Log(title = "两区及乡镇单位部门招商计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BmDeptPlanArea bmDeptPlanArea)
    {
        return toAjax(bmDeptPlanAreaService.insertBmDeptPlanArea(bmDeptPlanArea));
    }

    /**
     * 修改两区及乡镇单位部门招商计划
     */
    @PreAuthorize("@ss.hasPermi('dept:area:edit')")
    @Log(title = "两区及乡镇单位部门招商计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BmDeptPlanArea bmDeptPlanArea)
    {
        return toAjax(bmDeptPlanAreaService.updateBmDeptPlanArea(bmDeptPlanArea));
    }

    /**
     * 删除两区及乡镇单位部门招商计划
     */
    @PreAuthorize("@ss.hasPermi('dept:area:remove')")
    @Log(title = "两区及乡镇单位部门招商计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bmDeptPlanAreaService.deleteBmDeptPlanAreaByIds(ids));
    }


    /**
     * 首页-两区及乡镇榜单
     */
    @Log(title = "市值榜单", businessType = BusinessType.INSERT)
    @PostMapping("/areaList")
    public TableDataInfo areaList(String year) {
        if (StringUtils.isBlank(year)){
            year = DateUtils.getYear();
        }
        List<BmDeptPlanArea> bmDeptPlanAreaList = bmDeptPlanAreaService.selectAreaList(year);
        return getDataTable(bmDeptPlanAreaList);
    }
}
