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.WellTube;
import cn.com.victorysoft.business.technology.service.WellTubeService;
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/wellTube")
public class WellTubeController {
    @Resource
    private WellTubeService wellTubeService;

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

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

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

    }

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

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

}
