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

import cn.com.victorysoft.business.condition.entity.ConditionWell;
import cn.com.victorysoft.business.condition.param.ConditionWellExportParam;
import cn.com.victorysoft.business.condition.param.ConditionWellParam;
import cn.com.victorysoft.business.condition.service.ConditionWellService;
import cn.com.victorysoft.business.sys.entity.ExportResult;
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/conditionWell")
public class ConditionWellController {
    @Resource
    private ConditionWellService conditionWellService;

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

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

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

    }

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

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

}
