package cn.com.victorysoft.business.technology.controller;

import cn.com.victorysoft.business.sys.entity.ExportResult;
import cn.com.victorysoft.business.sys.param.UnitWellExportParam;
import cn.com.victorysoft.business.sys.param.UnitWellMonthExportParam;
import cn.com.victorysoft.business.sys.param.UnitWellMonthPageParam;
import cn.com.victorysoft.business.sys.param.UnitWellPageParam;
import cn.com.victorysoft.business.technology.entity.WellTool;
import cn.com.victorysoft.business.technology.service.WellToolService;
import cn.com.victorysoft.business.util.ExcelUtils;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "井下工具")
@RestController
@RequestMapping("technology/wellTool")
public class WellToolController {
    @Resource
    private WellToolService wellToolService;

    @GetMapping("/page")
    @ApiOperation("查询分页数据")
    public PageInfo<WellTool> Page(UnitWellMonthPageParam param) {
        return wellToolService.selectPage(param);
    }

    @SneakyThrows
    @PostMapping("/export")
    @ApiOperation("导出数据")
    public ExportResult selectListExport(@RequestBody UnitWellMonthExportParam param) {
        List<WellTool> list = wellToolService.selectList(param);
        return ExcelUtils.export(param.getColumnConfig(), list, param.getFileName());
    }

    @PostMapping("/insert")
    @ApiOperation("插入")
    public int insert(@RequestBody WellTool param) {
        WellTool record = wellToolService.selectByPrimaryKey(param);
        if (record != null) {
            return -1;
        }else {
            return wellToolService.insert(param);
        }

    }

    @PutMapping("/update")
    @ApiOperation("更新")
    public int update(@RequestBody WellTool param) {
        return wellToolService.update(param);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除")
    public int delete(WellTool param) {
        return wellToolService.delete(param);
    }

}
