package com.bonus.sgzb.base.controller;

import com.bonus.sgzb.base.domain.BmProjectInfo;
import com.bonus.sgzb.base.service.BmProjectInfoService;
import com.bonus.sgzb.common.core.utils.poi.ExcelUtil;
import com.bonus.sgzb.common.core.web.controller.BaseController;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.core.web.page.TableDataInfo;
import com.bonus.sgzb.common.log.annotation.Log;
import com.bonus.sgzb.common.log.enums.BusinessType;
import com.bonus.sgzb.common.security.annotation.RequiresPermissions;
import io.swagger.annotations.Api;
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 org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

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

    @Autowired
    private BmProjectInfoService bmProjectInfoService;


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

    }

    /**
     * 获取工程项目下拉选
     */
    @ApiOperation(value = "获取工程项目下拉选")
    @GetMapping("/getProjectSelect")
    public AjaxResult getProjectSelect(BmProjectInfo bmProjectInfo)
    {
        List<BmProjectInfo> list = bmProjectInfoService.getProjectInfoAll(bmProjectInfo);
        return AjaxResult.success(list);

    }

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

    /**
     * 新增项目管理
     */
    @ApiOperation("新增项目管理")
    @Log(title = "参数管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult projectInfoAdd(@Validated @RequestBody BmProjectInfo bmProjectInfo)
    {
        return 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 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(bmProjectInfo);
        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);
    }

}
