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

import cn.com.victorysoft.business.condition.entity.AbnormalWell;
import cn.com.victorysoft.business.condition.param.AbnormalWellExportParam;
import cn.com.victorysoft.business.condition.param.AbnormalWellParam;
import cn.com.victorysoft.business.condition.service.AbnormalWellService;
import cn.com.victorysoft.business.condition.service.AbnormalWellService;
import cn.com.victorysoft.business.sys.entity.ExportResult;
import cn.com.victorysoft.business.sys.param.UnitBlockDateWellExportParam;
import cn.com.victorysoft.business.sys.param.UnitBlockDateWellPageParam;
import cn.com.victorysoft.business.util.ExcelUtils;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

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

@Api(tags = "异常井")
@RestController
@RequestMapping("condition/abnormalWell")
public class AbnormalWellController {
    @Resource
    private AbnormalWellService abnormalWellService;

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

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

    @PostMapping("/insert")
    @ApiOperation("更新")
    public int insert(@RequestBody AbnormalWell param) {
        AbnormalWell record = abnormalWellService.selectByPrimaryKey(param);
        if (record != null) {
            return -1;
        }else {
            return abnormalWellService.insert(param);
        }

    }

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

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

}
