package com.td.boss.sys.sysGame.controller;

import com.td.boss.annotation.Decrypt;
import com.td.boss.annotation.Encrypt;
import com.td.boss.common.controller.CommonController;
import com.td.boss.common.pojo.PageInfo;
import com.td.boss.common.pojo.Result;
import com.td.boss.game.comcntorder.service.ComCntOrderService;
import com.td.boss.game.comcntorder.vo.ComCntOrderPayTypeSumVo;
import com.td.boss.game.comcntorder.vo.ComCntOrderVo;
import com.td.boss.game.complayergoods.pojo.ComPlayerGoods;
import com.td.boss.game.complayergoods.service.ComPlayerGoodsService;
import com.td.boss.game.complayergoods.vo.ComPlayerGoodsVo;
import com.td.boss.game.complayerland.pojo.ComPlayerLand;
import com.td.boss.game.complayerland.service.ComPlayerLandService;
import com.td.boss.game.complayerland.vo.ComPlayerLandVo;
import com.td.boss.game.complayerlog.service.ComPlayerLogService;
import com.td.boss.game.complayerlog.vo.ComPlayerLogVo;
import com.td.boss.game.complayerprofit.service.ComPlayerProfitService;
import com.td.boss.game.complayerprofit.vo.ComPlayerProfitVo;
import com.td.boss.game.comsnbtran.service.ComSnbTranService;
import com.td.boss.game.comsnbtran.vo.ComSnbTranVo;
import com.td.boss.game.comusers.pojo.ComUsers;
import com.td.boss.game.comusers.service.ComUsersService;
import com.td.boss.game.comusers.vo.ComUsersVo;
import com.td.boss.sys.sysuser.vo.SysUserVo;
import com.td.boss.util.JwtTokenUtil;
import lombok.extern.slf4j.Slf4j;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/sys/sysComUsers/")
public class sysGameUsersController extends CommonController<ComUsersVo, ComUsers, String> {
    @Autowired
    private ComUsersService comUsersService;

    @Autowired
    private ComSnbTranService comSnbTranService;

    @Autowired
    private ComCntOrderService comCntOrderService;

    @Autowired
    private ComPlayerLogService comPlayerLogService;

    @Autowired
    private ComPlayerProfitService comPlayerProfitService;

    @Autowired
    private ComPlayerLandService comPlayerLandService;

    @Autowired
    private ComPlayerGoodsService comPlayerGoodsService;

    @Autowired
    private JwtTokenUtil jwtTokenUtil;

    @Value("${spring.profiles.active}")
    private String active;

    @GetMapping("user")
    public ModelAndView user(){
        return new ModelAndView("sys/aComUser/user");
    }

    @PostMapping("findGameUserByAddress")
    @Decrypt
    @Encrypt
    public Result<PageInfo<ComUsersVo>> findGameUserByAddress(ComUsersVo comUsersVo){
        ComUsersVo comUsersVo1 = new ComUsersVo();
        ArrayList<ComUsersVo> comUsersVoList = new ArrayList<>();
        if(comUsersVo.getAddress() != null){
            comUsersVo1 = comUsersService.findByAddress(comUsersVo.getAddress());
            comUsersVoList.add(comUsersVo1);
        }
        PageInfo<ComUsersVo> pageInfo = new PageInfo<>();
        pageInfo.setPage(1);//页码
        pageInfo.setPageSize(2);//页面大小
        pageInfo.setRows(comUsersVoList);//分页结果
        pageInfo.setRecords(comUsersVoList.size());//总记录数
        pageInfo.setTotal(1);//总页数
        return Result.of(pageInfo);
    }

    @PostMapping("findSNBTranByUserId")
    @Decrypt
    @Encrypt
    public Result<PageInfo<ComSnbTranVo>> findSNBTranByUserId(ComSnbTranVo comSnbTranVo){
        return comSnbTranService.page(comSnbTranVo);
    }


    @PostMapping("findCNTTranByUserId")
    @Decrypt
    @Encrypt
    public Result<PageInfo<ComCntOrderVo>> findCNTTranByUserId(ComCntOrderVo comCntOrderVo){
        return comCntOrderService.page(comCntOrderVo);
    }

    @PostMapping("findPlayerLogPage")
    @Decrypt
    @Encrypt
    public Result<PageInfo<ComPlayerLogVo>> findCNTTranByUserId(ComPlayerLogVo comPlayerLogVo){
        return comPlayerLogService.page(comPlayerLogVo);
    }

    @PostMapping("findPlayerProfitPage")
    @Decrypt
    @Encrypt
    public Result<PageInfo<ComPlayerProfitVo>> findPlayerProfitByUserId(ComPlayerProfitVo comPlayerProfitVo){
        return comPlayerProfitService.page(comPlayerProfitVo);
    }




    @GetMapping("userPlayerGoods")
    public ModelAndView userPlayerGoods(){
        return new ModelAndView("sys/aComUser/userPlayerGoods");
    }


    @PostMapping("findPlayerGoodsByAddress")
    @Decrypt
    @Encrypt
    public Result<PageInfo<ComPlayerGoodsVo>> findPlayerGoodsByAddress(ComUsersVo comUsersVo){

        if(comUsersVo.getAddress() != null){
            //查询用户id
            ComUsersVo _comUsersVo = comUsersService.findByAddress(comUsersVo.getAddress());
            if(!_comUsersVo.equals(null)){
                //如果存在用户数据，继续查询背包
                ComPlayerGoodsVo comPlayerGoodsVo = new ComPlayerGoodsVo();
                comPlayerGoodsVo.setUserId(_comUsersVo.getUserId());
                comPlayerGoodsVo.setPage(comUsersVo.getPage());
                comPlayerGoodsVo.setRows(comUsersVo.getRows());
                comPlayerGoodsVo.setSidx(comUsersVo.getSidx());
                comPlayerGoodsVo.setSord(comUsersVo.getSord());
                return comPlayerGoodsService.page(comPlayerGoodsVo);
            }
        }
        //没数据随便返回一个空的
        ArrayList<ComPlayerGoodsVo> comPlayerGoodsVos = new ArrayList<>();
        PageInfo<ComPlayerGoodsVo> pageInfo = new PageInfo<>();
        pageInfo.setPage(1);//页码
        pageInfo.setPageSize(1);//页面大小
        pageInfo.setRows(comPlayerGoodsVos);//分页结果
        pageInfo.setRecords(comPlayerGoodsVos.size());//总记录数
        pageInfo.setTotal(1);//总页数
        return Result.of(pageInfo);
    }
    @PostMapping("playerGoodsSave")
    @Decrypt
    @Encrypt
    public Result<ComPlayerGoodsVo> playerGoodsSave(ComPlayerGoodsVo comPlayerGoodsVo){
        return comPlayerGoodsService.save(comPlayerGoodsVo);
    }

    @GetMapping("userPlayerLands")
    public ModelAndView userPlayerLands(){
        return new ModelAndView("sys/aComUser/userPlayerLands");
    }

    @PostMapping("findPlayerLandByAddress")
    @Decrypt
    @Encrypt
    public Result<PageInfo<ComPlayerLandVo>> findPlayerLandByAddress(ComUsersVo comUsersVo){
        if(comUsersVo.getAddress() != null){
            //查询用户id
            ComUsersVo _comUsersVo = comUsersService.findByAddress(comUsersVo.getAddress());
            if(!_comUsersVo.equals(null)){
                //如果存在用户数据，继续查询背包
                ComPlayerLandVo comPlayerLandVo = new ComPlayerLandVo();
                comPlayerLandVo.setUserId(_comUsersVo.getUserId());
                comPlayerLandVo.setPage(comUsersVo.getPage());
                comPlayerLandVo.setRows(comUsersVo.getRows());
                comPlayerLandVo.setSidx(comUsersVo.getSidx());
                comPlayerLandVo.setSord(comUsersVo.getSord());
                return comPlayerLandService.page(comPlayerLandVo);
            }
        }

        //没数据随便返回一个空的
        ArrayList<ComPlayerLandVo> comPlayerLandVos = new ArrayList<>();
        PageInfo<ComPlayerLandVo> pageInfo = new PageInfo<>();
        pageInfo.setPage(1);//页码
        pageInfo.setPageSize(1);//页面大小
        pageInfo.setRows(comPlayerLandVos);//分页结果
        pageInfo.setRecords(comPlayerLandVos.size());//总记录数
        pageInfo.setTotal(1);//总页数
        return Result.of(pageInfo);
    }
    @PostMapping("playerLandSave")
    @Decrypt
    @Encrypt
    public Result<ComPlayerLandVo> playerLandSave(ComPlayerLandVo comPlayerLandVo){
        return comPlayerLandService.save(comPlayerLandVo);
    }

    @PostMapping("findPlayerLandByUserId")
    @Decrypt
    @Encrypt
    public Result<PageInfo<ComPlayerLandVo>> findPlayerLandByUserId(ComPlayerLandVo comPlayerLandVo){
        return comPlayerLandService.page(comPlayerLandVo);
    }

    @PostMapping("findPlayerGoodsByUserId")
    @Decrypt
    @Encrypt
    public Result<PageInfo<ComPlayerGoodsVo>> findPlayerGoodsByUserId(ComPlayerGoodsVo comPlayerGoodsVo){
        return comPlayerGoodsService.page(comPlayerGoodsVo);
    }

}
