package com.miaxis.pc.controller;

import com.miaxis.common.annotation.Log;
import com.miaxis.common.core.controller.BaseController;
import com.miaxis.common.core.domain.Response;
import com.miaxis.common.core.page.ResponsePageInfo;
import com.miaxis.common.enums.BusinessTypeEnum;
import com.miaxis.common.utils.poi.ExcelUtil;
import com.miaxis.controller.domain.ControllerInfo;
import com.miaxis.controller.service.IControllerInfoService;
import com.miaxis.engine.domain.EngineInfo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;

/**
 * 【控制器报价】Controller
 *
 * @author miaxis
 * @date 2023-01-29
 */
@RestController
@RequestMapping("/controller/info")
@Api(tags={"【pc-控制器报价】"})
public class ControllerInfoController extends BaseController{
    @Autowired
    private IControllerInfoService controllerInfoService;

    /**
     * 查询控制器报价列表
     */
//    @PreAuthorize("@ss.hasPermi('controller:info:list')")
    @GetMapping("/list")
    @ApiOperation("查询控制器报价列表")
        @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
    })
    public ResponsePageInfo<ControllerInfo> list(@ModelAttribute ControllerInfo controllerInfo){
        startPage();
        List<ControllerInfo> list = controllerInfoService.selectControllerInfoList(controllerInfo);
        return toResponsePageInfo(list);
    }

    @Log(title = "报价", businessType = BusinessTypeEnum.IMPORT)
    @PostMapping("/import")
    @ApiOperation("导入报价列表Excel")
    public Response<String> importEngineInfo(@RequestPart("file") MultipartFile file) throws Exception {
        ExcelUtil<ControllerInfo> util = new ExcelUtil<ControllerInfo>(ControllerInfo.class);
        List<ControllerInfo> list = util.importExcel(file.getInputStream(),2,false);
        controllerInfoService.saveBatch(list);
        return Response.success();
    }

    /**
     * 导出控制器报价列表
     */
//    @PreAuthorize("@ss.hasPermi('controller:info:export')")
    @Log(title = "控制器报价", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出控制器报价列表Excel")
    public Response<String> export(@ModelAttribute ControllerInfo controllerInfo){
        List<ControllerInfo> list = controllerInfoService.selectControllerInfoList(controllerInfo);
        ExcelUtil<ControllerInfo> util = new ExcelUtil<ControllerInfo>(ControllerInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 获取控制器报价详细信息
     */
//    @PreAuthorize("@ss.hasPermi('controller:info:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取控制器报价详细信息")
    public Response<ControllerInfo> getInfo(
            @ApiParam(name = "id", value = "控制器报价参数", required = true)
            @PathVariable("id") Long id
    ){
        return Response.success(controllerInfoService.getById(id));
    }

    /**
     * 新增控制器报价
     */
//    @PreAuthorize("@ss.hasPermi('controller:info:add')")
    @Log(title = "控制器报价", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation("新增控制器报价")
    public Response<Integer> add(@RequestBody ControllerInfo controllerInfo){
        return toResponse(controllerInfoService.save(controllerInfo) ? 1 : 0);
    }

    /**
     * 修改控制器报价
     */
//    @PreAuthorize("@ss.hasPermi('controller:info:edit')")
    @Log(title = "控制器报价", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改控制器报价")
    public Response<Integer> edit(@RequestBody ControllerInfo controllerInfo){
        return toResponse(controllerInfoService.updateById(controllerInfo) ? 1 : 0);
    }

    /**
     * 删除控制器报价
     */
//    @PreAuthorize("@ss.hasPermi('controller:info:remove')")
    @Log(title = "控制器报价", businessType = BusinessTypeEnum.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除控制器报价")
    public  Response<Integer> remove(
            @ApiParam(name = "ids", value = "控制器报价ids参数", required = true)
            @PathVariable Long[] ids
    ){
        return toResponse(controllerInfoService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
