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

import cn.com.victorysoft.business.condition.entity.AdjustRecord;
import cn.com.victorysoft.business.condition.service.AdjustRecordService;
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.sys.param.UnitBlockWellExportParam;
import cn.com.victorysoft.business.sys.param.UnitBlockWellPageParam;
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/adjustRecord")
public class AdjustRecordController {
    @Resource
    private AdjustRecordService adjustRecordService;

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

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

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

    }

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

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

}
