package com.tofly.feesapi.cbgl.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.tofly.feesapi.common.core.ResultRespone;
import com.tofly.feesapi.cbgl.entity.ZnbZlLog;
import com.tofly.feesapi.cbgl.entity.dto.ZnbFkFilter;
import com.tofly.feesapi.cbgl.entity.dto.ZnbZlLogFilter;
import com.tofly.feesapi.cbgl.entity.vo.ZnbZlLogSelect;
import com.tofly.feesapi.cbgl.service.IZnbZlLogService;
import com.tofly.feesapi.common.core.dto.PageDto;
import com.tofly.feesapi.common.core.vo.PageResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/cbgl/znbZlLog")
@Api(tags = "智能表指令明细")
public class ZnbZlLogController {

    @Autowired
    private IZnbZlLogService znbZlLogService;

    @ApiOperationSupport(order = 1)
    @GetMapping("/page")
    @ApiOperation(value = "查询智能表指令明细（分页）",tags = "智能表")
    public ResultRespone<PageResult<ZnbZlLogSelect>> getPage(@ModelAttribute PageDto pageDto,
                                                             @ModelAttribute ZnbZlLogFilter filter) {
        return ResultRespone.success(znbZlLogService.getPage(pageDto, filter));
    }

    /**
     * 新增智能表指令明细
     *
     * @param znbZlLog 智能表指令明细
     * @return ResultRespone
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "新增智能表指令明细",tags = "智能表")
    @PostMapping("/save")
    public ResultRespone save(@RequestBody ZnbZlLog znbZlLog) {
        return ResultRespone.success(znbZlLogService.save(znbZlLog));
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "智能表阀控" ,tags = "智能表")
    @PostMapping
    public ResultRespone<Boolean> ZnbFk(@RequestBody ZnbFkFilter filter) {
        boolean result = znbZlLogService.ZnbFk(filter);
        return result ? ResultRespone.success(true, "指令下发成功") : ResultRespone.failed(false, "指令下发失败");
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "智能表指令重发",tags = "智能表")
    @PostMapping("reznbzlsend")
    public ResultRespone<Boolean> reznbzlsend(@RequestBody ZnbZlLogFilter filter){
        return  znbZlLogService.reZnbZlSend(filter)?ResultRespone.success(true, "指令下发成功") : ResultRespone.failed(false, "指令下发失败");
    }


//    @ApiOperationSupport(order = 2)
//    @GetMapping("/export")
//    @ApiOperation(value = "导出智能表指令明细")
//    public void export(HttpServletResponse response, @ModelAttribute ZnbCbLogFilter filter) throws IOException {
//        List<ZnbZlLogSelect> list = znbZlLogService.getList(filter);
//        if (!list.isEmpty()) {
//            ExcleFileUtil.exportExcel(response, list, ZnbZlLogSelect.class, "智能表指令明细.xlsx");
//        }
//    }
}
