package com.bonus.sgzb.base.controller;

import com.bonus.sgzb.base.domain.BmProjectLot;
import com.bonus.sgzb.base.domain.vo.BmProjectLotImport;
import com.bonus.sgzb.base.service.BmProjectLotService;
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/bmProjectLot")
public class BmProjectLotController extends BaseController {

    @Autowired
    private BmProjectLotService bmProjectLotService;

    /**
     * 获取标段工程项
     */
    @ApiOperation(value = "获取标段工程项目")
    @GetMapping("/projectLotAll")
    @RequiresPermissions("section:list")
    public TableDataInfo getProjectLotAll(BmProjectLot bmProjectLot) {
        startPage();
        List<BmProjectLot> list = bmProjectLotService.getProjectLotAll(bmProjectLot);
        return getDataTable(list);

    }

    /**
     * 获取标段工程项
     */
    @ApiOperation(value = "导出标段工程项目")
    @PostMapping("/export")
    public void export(HttpServletResponse response, BmProjectLot bmProjectLot) {
        startPage();
        List<BmProjectLot> list = bmProjectLotService.getProjectLotAll(bmProjectLot);
        ExcelUtil<BmProjectLot> util = new ExcelUtil<BmProjectLot>(BmProjectLot.class);
        util.exportExcel(response, list, "标段工程");

    }

    /**
     * 新增项目管理
     */
    @ApiOperation("新增标段工程项目")
    @Log(title = "参数管理", businessType = BusinessType.INSERT)
    @PostMapping
    @RequiresPermissions("section:list:add")
    public AjaxResult projectLotAdd(@Validated @RequestBody BmProjectLot bmProjectLot) {
        return bmProjectLotService.projectLotAdd(bmProjectLot);
    }

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

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

        return bmProjectLotService.updateBmProjectLot(bmProjectLot);
    }

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

}
