package cn.wisenergy.web.admin.controller.app;

import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.app.User;
import cn.wisenergy.service.app.*;
import cn.wisenergy.service.app.impl.AerialDeliveryUserServiceImpl;
import cn.wisenergy.service.app.impl.UserServiceImpl;
import com.youzan.cloud.open.sdk.common.exception.SDKException;
import com.youzan.cloud.open.sdk.gen.v4_0_0.model.YouzanTradesSoldGetResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "用户等级管理")
@RestController
@RequestMapping("/user")
@Slf4j
public class UserLevelController {

    @Autowired
    private UserLevelService userLevelService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private UserService userService;
    @Autowired
    private AerialDeliveryUserService aerialDeliveryUserService;
    @Autowired
    private AerialDeliveryUserServiceImpl AerialDeliveryUserServiceImpl;
    @Autowired
    private LastMonthUserInfoService lastMonthUserInfoService;
    @Autowired
    private UserLevelTaskService userLevelTaskService;

    @ApiOperation(value = "用户升级接口测试", notes = "用户升级接口测试扫描订单", httpMethod = "GET")
    @GetMapping("/test")
    public R<String> userLevel(){
//        userLevelService.userLevelUpgrade(userId);
        userLevelTaskService.userLevelUp();
        return R.ok();
    }

    @ApiOperation(value = "用户升级接口测试", notes = "用户升级接口测试不扫描订单", httpMethod = "GET")
    @GetMapping("/test1")
    public R<String> userLevel1(String userId){

        userLevelService.userLevelUpgrade(userId);
//        userLevelService.userLevelUp();
        return R.ok();
    }

    @ApiOperation(value = "根据订单创建时间获取订单数据", notes = "根据订单创建时间获取订单数据", httpMethod = "GET")
    @GetMapping("/order")
    public void getyouzanorder() throws SDKException {

        orderService.getYouZanOrdersForCreateTime();
    }

    @ApiOperation(value = "根据订单修改时间获取订单数据", notes = "根据订单修改时间获取订单数据", httpMethod = "GET")
    @GetMapping("orders")
    public void getyouzanOrdersByUpdateTime() throws SDKException {
        orderService.getYouZanOrdersForUpdateTime();
    }

    @ApiOperation(value = "空投池用户随机分配", notes = "空投池用户随机分配", httpMethod = "GET")
    @GetMapping("/aerialDeliveryUserRand")
    public void aerialDeliveryUserRand(){
        aerialDeliveryUserService.aerialDeliveryUserRand();
    }

    @ApiOperation(value = "注册100个用户", notes = "注册100个用户", httpMethod = "GET")
    @GetMapping("/registerController")
    public void registerController(){
        for (int i = 0; i <= 9; i++) {

            String userid = "1393377000"+i;

            userService.userByZx(userid,null);
        }
    }

    @ApiOperation(value = "注册系统透明用户5个", notes = "注册系统透明用户5个", httpMethod = "GET")
    @GetMapping("/registerSysUSerController")
    public void registerSysUSerController(){
        for (int i = 0; i <= 4; i++) {

            String userid = "13933770741"+i;

            userService.userByZx(userid,null);
        }
    }

    @ApiOperation(value = "获取顶级用户", notes = "获取顶级用户", httpMethod = "GET")
    @GetMapping("/getHighUser")
    public User getHighUser(String userId){
        User user = AerialDeliveryUserServiceImpl.highUser(userId);
        return user ;

    }

    @ApiOperation(value = "用户表镜像", notes = "用户表镜像", httpMethod = "GET")
    @GetMapping("/userInfoMirrorImage")
    public void userInfoMirrorImageController(){
        lastMonthUserInfoService.userInfoMirrorImage();
    }

    @ApiOperation(value = "月度定时任务执行测试", notes = "月度定时任务执行测试", httpMethod = "GET")
    @GetMapping("/monthUserlevelTask")
    public void monthUserlevelTask(){
        userLevelTaskService.monthUserLevelUp();
    }
}
