package com.gree.mall.manager.controller.big;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gree.mall.manager.annotation.ApiNotAuth;
import com.gree.mall.manager.bean.big.*;
import com.gree.mall.manager.exception.RemoteServiceException;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.ExpressLogic;
import com.gree.mall.manager.logic.big.BigLogic;
import com.gree.mall.manager.logic.common.CommonLogic;
import com.gree.mall.manager.logic.common.WechatLogic;
import com.gree.mall.manager.logic.common.kuaidi100.response.SubscribeResp;
import com.gree.mall.manager.plus.entity.*;
import com.gree.mall.manager.plus.service.AdminCompanyWechatService;
import com.gree.mall.manager.plus.service.OrderDetailService;
import com.gree.mall.manager.plus.service.OrderInfoService;
import com.gree.mall.manager.utils.CommonUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotBlank;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Slf4j
@RestController
@Api(value = "大屏API", tags ={"大屏API"} )
@RequestMapping(value = "/big", produces = "application/json; charset=utf-8")
public class BigController {

    @Autowired
    BigLogic bigLogic;



    @ApiNotAuth
    @ApiOperation("天气预报")
    @GetMapping("/water/get")
    public ResponseHelper<Map<String,Object>> getWater(
            @ApiParam(value = "city",required = true) @RequestParam(required = true) String city
    ){
        Map<String, Object> water = bigLogic.getWater(city);
        return ResponseHelper.success(water);
    }



    @PostMapping("/getRegion")
    @ApiOperation(value = "获得区域坐标")
    public ResponseHelper<String> getRegion(
            @ApiParam(required = false, value = "国家") @RequestParam(required = false) String country,
            @ApiParam(required = false, value = "省") @RequestParam(required = false) String province,
            @ApiParam(required = false, value = "市") @RequestParam(required = false) String city,
            @ApiParam(required = false, value = "区") @RequestParam(required = false) String area
    ) throws IOException, RemoteServiceException {
        String region = bigLogic.getRegion(country,province,city,area);
        return ResponseHelper.success(region);
    }



    @PostMapping("/getLarge1")
    @ApiOperation(value = "平台获得地图总数据")
    public ResponseHelper<LargeOneBean> getLarge1(
            @ApiParam(required = false, value = "省") @RequestParam(required = false) String province
    ) throws IOException, RemoteServiceException {
        LargeOneBean largeOneBean = bigLogic.getLarge1(province);
        return ResponseHelper.success(largeOneBean);
    }


    @PostMapping("/getLarge2")
    @ApiOperation(value = "商户获得地图总数据")
    public ResponseHelper<LargeOneBean> getLarge2(
    ) throws IOException, RemoteServiceException {
        LargeOneBean largeOneBean = bigLogic.getLarge2();
        return ResponseHelper.success(largeOneBean);
    }


    @PostMapping("/getLarge3")
    @ApiOperation(value = "浏览量，访客量")
    public ResponseHelper<List<largeSeeLogin>> getLarge3(
    ) throws IOException, RemoteServiceException {
        List<largeSeeLogin> largeOneBean = bigLogic.getLarge3();
        return ResponseHelper.success(largeOneBean);
    }



    @PostMapping("/getLarge4")
    @ApiOperation(value = "近30天辅配件统计")
    public ResponseHelper<LargeMpBean> getLarge4(
    ) throws IOException, RemoteServiceException {
        LargeMpBean largeMpBean = bigLogic.getLarge4();
        return ResponseHelper.success(largeMpBean);
    }



    @PostMapping("/getLarge5")
    @ApiOperation(value = "近30天累计工单数量")
    public ResponseHelper<LargeWorkerOrderBean> getLarge5(
    ) throws IOException, RemoteServiceException {
        LargeWorkerOrderBean largeMpBean = bigLogic.getLarge5();
        return ResponseHelper.success(largeMpBean);
    }


    @PostMapping("/getLarge6")
    @ApiOperation(value = "近30天工单趋势")
    public ResponseHelper<List<LargeWorkerOrderDateBean>> getLarge6(
    ) throws IOException, RemoteServiceException {
        List<LargeWorkerOrderDateBean> largeMpBean = bigLogic.getLarge6();
        return ResponseHelper.success(largeMpBean);
    }



    @PostMapping("/getLarge7")
    @ApiOperation(value = "近30天累计订单统计")
    public ResponseHelper<LargeOrderBean> getLarge7(
    ) throws IOException, RemoteServiceException {
        LargeOrderBean largeMpBean = bigLogic.getLarge7();
        return ResponseHelper.success(largeMpBean);
    }


    @PostMapping("/getLarge8")
    @ApiOperation(value = "近30天订单趋势")
    public ResponseHelper<List<LargeOrderBean>> getLarge8(
    ) throws IOException, RemoteServiceException {
        List<LargeOrderBean> largeMpBean = bigLogic.getLarge8();
        return ResponseHelper.success(largeMpBean);
    }


    @GetMapping("/list")
    @ApiOperation(value = "商户街道完工数据")
    public ResponseHelper<Page<LargeWorkerOrderList>> page(
            HttpServletRequest request,
            @ApiParam(value = "市",required = false) @RequestParam(required = false) String city,
            @ApiParam(value = "省",required = false) @RequestParam(required = false) String province,
            @ApiParam(value = "区",required = false) @RequestParam(required = false) String area,

            @ApiParam(value = "页号",required = true) @RequestParam(required = true) Integer pageNum,
            @ApiParam(value = "页大小",required = true) @RequestParam(required = true) Integer pageSize
    ){
        IPage<LargeWorkerOrderList> list = bigLogic.list(request,city, province,area, pageNum, pageSize);
        return ResponseHelper.success(list);
    }


    @PostMapping("/getLarge9")
    @ApiOperation(value = "数据省份获得")
    public ResponseHelper<List<String>> getLarge9(
    ) throws IOException, RemoteServiceException {
        List<String> largeMpBean = bigLogic.getLarge9();
        return ResponseHelper.success(largeMpBean);
    }


    @GetMapping("/getLarge10")
    @ApiOperation(value = "区工单台数")
    public ResponseHelper<List<LargeNumCity>> getLarge10(
            HttpServletRequest request,
            @ApiParam(value = "市",required = false) @RequestParam(required = false) String city,
            @ApiParam(value = "省",required = false) @RequestParam(required = false) String province

    ){
        List<LargeNumCity> list = bigLogic.getLarge10(city, province);
        return ResponseHelper.success(list);
    }


    @GetMapping("/getLarge11")
    @ApiOperation(value = "市工单台数")
    public ResponseHelper<LargeNumCity> getLarge11(
            HttpServletRequest request,
            @ApiParam(value = "市",required = false) @RequestParam(required = false) String city,
            @ApiParam(value = "省",required = false) @RequestParam(required = false) String province

    ){
        LargeNumCity list = bigLogic.getLarge11(city, province);
        return ResponseHelper.success(list);
    }


}
