package com.njcn.device.pms.controller.gwPush;

import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.device.pms.pojo.param.MonitorParam;
import com.njcn.device.pms.service.gwPush.MonitorSendService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;

/**
 *
 */
@RestController
@RequestMapping("/monitorSend")
@Api(tags = "台账类国网上送")
@RequiredArgsConstructor
public class MonitorSendController extends BaseController {

    private final MonitorSendService monitorSendService;

    @PostMapping("/sendType")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("国网上送接口")
    @ApiImplicitParam(name = "param",value = "请求体",required = true)
    public HttpResult<String> windSend(@RequestBody @Validated MonitorParam.Info param){
        String methodDescribe = getMethodDescribe("windSend");
        String s = monitorSendService.sendType(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, s, methodDescribe);
    }



    @PostMapping("/exportSend")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation(value ="国网上送台账导出", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    public HttpResult<Boolean> tractionStationSend(HttpServletResponse response) throws IOException {
        String methodDescribe = getMethodDescribe("tractionStationSend");
        response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("国网上送台账", "UTF-8") + ".xlsx");
        monitorSendService.exportSend(response);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }



}
