package com.miaxis.pc.controller;

import com.miaxis.common.constant.Constants;
import java.util.List;
import java.util.Arrays;
import io.swagger.annotations.*;
import com.miaxis.common.core.domain.Response;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.miaxis.common.annotation.Log;
import com.miaxis.common.core.controller.BaseController;
import com.miaxis.common.enums.BusinessTypeEnum;
import com.miaxis.fdj.domain.Fdj50hzInfo;
import com.miaxis.fdj.service.IFdj50hzInfoService;
import com.miaxis.common.utils.poi.ExcelUtil;
import com.miaxis.common.core.page.ResponsePageInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 【发电机50hz报价】Controller
 *
 * @author miaxis
 * @date 2023-02-09
 */
@RestController
@RequestMapping("/fdj50/info")
@Api(tags={"【pc-发电机50hz报价】"})
public class Fdj50hzInfoController extends BaseController{
    @Autowired
    private IFdj50hzInfoService fdj50hzInfoService;

    /**
     * 查询发电机50hz报价列表
     */

    @GetMapping("/list")
    @ApiOperation("查询发电机50hz报价列表")
        @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
    })
    public ResponsePageInfo<Fdj50hzInfo> list(@ModelAttribute Fdj50hzInfo fdj50hzInfo){
        startPage();
        List<Fdj50hzInfo> list = fdj50hzInfoService.selectFdj50hzInfoList(fdj50hzInfo);
        return toResponsePageInfo(list);
    }

    /**
     * 导出发电机50hz报价列表
     */

    @Log(title = "发电机50hz报价", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出发电机50hz报价列表Excel")
    public Response<String> export(@ModelAttribute Fdj50hzInfo fdj50hzInfo){
        List<Fdj50hzInfo> list = fdj50hzInfoService.selectFdj50hzInfoList(fdj50hzInfo);
        ExcelUtil<Fdj50hzInfo> util = new ExcelUtil<Fdj50hzInfo>(Fdj50hzInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 获取发电机50hz报价详细信息
     */

    @GetMapping(value = "/{id}")
    @ApiOperation("获取发电机50hz报价详细信息")
    public Response<Fdj50hzInfo> getInfo(
            @ApiParam(name = "id", value = "发电机50hz报价参数", required = true)
            @PathVariable("id") Long id
    ){
        return Response.success(fdj50hzInfoService.getById(id));
    }
    @Log(title = "报价", businessType = BusinessTypeEnum.IMPORT)
    @PostMapping("/import")
    @ApiOperation("导入报价列表Excel")
    public Response<String> importPrice(@RequestPart("file") MultipartFile file) throws Exception {
        ExcelUtil<Fdj50hzInfo> util = new ExcelUtil<Fdj50hzInfo>(Fdj50hzInfo.class);
        List<Fdj50hzInfo> list = util.importExcel(file.getInputStream(),8,true);
        fdj50hzInfoService.saveBatch(list);
        return Response.success();
    }
    /**
     * 新增发电机50hz报价
     */

    @Log(title = "发电机50hz报价", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation("新增发电机50hz报价")
    public Response<Integer> add(@RequestBody Fdj50hzInfo fdj50hzInfo){
        return toResponse(fdj50hzInfoService.save(fdj50hzInfo) ? 1 : 0);
    }

    /**
     * 修改发电机50hz报价
     */

    @Log(title = "发电机50hz报价", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改发电机50hz报价")
    public Response<Integer> edit(@RequestBody Fdj50hzInfo fdj50hzInfo){
        return toResponse(fdj50hzInfoService.updateById(fdj50hzInfo) ? 1 : 0);
    }

    /**
     * 删除发电机50hz报价
     */

    @Log(title = "发电机50hz报价", businessType = BusinessTypeEnum.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除发电机50hz报价")
    public  Response<Integer> remove(
            @ApiParam(name = "ids", value = "发电机50hz报价ids参数", required = true)
            @PathVariable Long[] ids
    ){
        return toResponse(fdj50hzInfoService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
