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

import cn.com.victorysoft.business.condition.entity.FlushRecord;
import cn.com.victorysoft.business.condition.service.FlushRecordService;
import cn.com.victorysoft.business.sys.entity.ExportResult;
import cn.com.victorysoft.business.sys.param.UnitDatePageExportParam;
import cn.com.victorysoft.business.sys.param.UnitDatePageParam;
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/flushRecord")
public class FlushRecordController {
    @Resource
    private FlushRecordService flushRecordService;

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

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

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

    }


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

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

}
