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

import cn.com.victorysoft.business.condition.entity.AbnormalWellReason;
import cn.com.victorysoft.business.condition.param.AbnormalWellReasonExportParam;
import cn.com.victorysoft.business.condition.param.AbnormalWellReasonParam;
import cn.com.victorysoft.business.condition.service.AbnormalWellReasonService;
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/abnormalWellReason")
public class AbnormalWellReasonController {
    @Resource
    private AbnormalWellReasonService abnormalWellReasonService;

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

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

    @PostMapping("/save")
    @ApiOperation("保存")
    public int insert(@RequestBody AbnormalWellReason param) {
        AbnormalWellReason record = abnormalWellReasonService.selectByPrimaryKey(param);
        if (record != null) {
            return abnormalWellReasonService.update(param);
        }else {
            return abnormalWellReasonService.insert(param);
        }

    }

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

}
