package com.bonus.sgzb.base.controller;


import com.bonus.sgzb.base.domain.BmProjectInfo;
import com.bonus.sgzb.base.domain.BmUnitInfo;
import com.bonus.sgzb.base.service.BmProjectInfoService;
import com.bonus.sgzb.common.core.utils.poi.ExcelUtil;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.core.web.page.TableDataInfo;
import com.bonus.sgzb.common.log.enums.BusinessType;
import com.bonus.sgzb.common.security.annotation.RequiresPermissions;
import com.bonus.sgzb.common.security.utils.SecurityUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.bonus.sgzb.common.log.annotation.Log;
import java.util.List;

import com.bonus.sgzb.common.core.web.controller.BaseController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * 基础管理  工程项目
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/bmProjectInfo")
public class BmProjectInfoController extends BaseController{

    @Autowired
    private BmProjectInfoService bmProjectInfoService;


    /**
     * 获取工程项目管理列表
     */
    @ApiOperation("获取工程项目管理列表")
    @GetMapping("/projectInfoAll")
    public TableDataInfo getProjectInfoAll()
    {
        startPage();
        List<BmProjectInfo> list = bmProjectInfoService.getProjectInfoAll();
        return getDataTable(list);

    }

    /**
     * 根据条件进行查询
     */
    @ApiOperation("根据条件进行工程项目查询")
    @PostMapping ("/getProjectInfo")
    public TableDataInfo getProjectInfo(@Validated @RequestBody BmProjectInfo bmProjectInfo)
    {
        startPage();
        List<BmProjectInfo> list = bmProjectInfoService.getProjectInfo(bmProjectInfo);
        return getDataTable(list);


    }


    /**
     * 新增项目管理
     */
    @ApiOperation("新增项目管理")
    @Log(title = "参数管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult projectInfoAdd(@Validated @RequestBody BmProjectInfo bmProjectInfo)
    {
        return toAjax(bmProjectInfoService.projectInfoAdd(bmProjectInfo));
    }

    /**
     * 删除项目管理
     */
    @ApiOperation("删除项目管理")
    @Log(title = "参数管理", businessType = BusinessType.DELETE)
    @DeleteMapping ("/{proId}")
    public AjaxResult deleteProjectInfoById(@PathVariable Long proId)
    {
        bmProjectInfoService.deleteProjectInfoById(proId);
        return success();
    }

    /**
     * 修改项目管理
     */
    @ApiOperation("修改项目管理")
    @Log(title = "参数管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody BmProjectInfo bmProjectInfo)
    {

        return toAjax(bmProjectInfoService.updateBmProjectInfo(bmProjectInfo));
    }

    @Log(title = "项目管理导出", businessType = BusinessType.EXPORT)
    @RequiresPermissions("system:user:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, BmProjectInfo bmProjectInfo)
    {
        List<BmProjectInfo> list = bmProjectInfoService.getProjectInfoAll();
        ExcelUtil<BmProjectInfo> util = new ExcelUtil<BmProjectInfo>(BmProjectInfo.class);
        util.exportExcel(response, list, "往来单位");
    }

    @Log(title = "项目管理导入", businessType = BusinessType.IMPORT)
    @RequiresPermissions("system:user:import")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<BmProjectInfo> util = new ExcelUtil<BmProjectInfo>(BmProjectInfo.class);
        List<BmProjectInfo> bmProjectInfoList = util.importExcel(file.getInputStream());
        String message = bmProjectInfoService.importBmProjectInfo(bmProjectInfoList, updateSupport);
        return success(message);
    }

}
