package com.zhongzheng.controller.user;

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

import cn.hutool.core.lang.Validator;
import com.zhongzheng.common.utils.ServletUtils;
import com.zhongzheng.framework.web.service.WxTokenService;
import com.zhongzheng.modules.user.bo.OrderPossessUserQueryBo;
import com.zhongzheng.modules.user.entity.ClientLoginUser;
import com.zhongzheng.modules.user.service.IOrderPossessUserService;
import com.zhongzheng.modules.user.vo.OrderPossessUserVo;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhongzheng.common.annotation.Log;
import com.zhongzheng.common.core.controller.BaseController;
import com.zhongzheng.common.core.domain.AjaxResult;
import com.zhongzheng.common.enums.BusinessType;

import com.zhongzheng.common.utils.poi.ExcelUtil;
import com.zhongzheng.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 【请填写功能名称】Controller
 *
 * @author change
 * @date 2021-06-25
 */
@Api(value = "【用户拥有课程或题库】控制器", tags = {"【用户拥有课程或题库】管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/user")
public class OrderPossessUserController extends BaseController {

    private final IOrderPossessUserService iOrderPossessUserService;

    private final com.zhongzheng.framework.web.service.WxTokenService WxTokenService;

    /**
     * 查询【请填写功能名称】列表
     */
    @ApiOperation("查询用户拥有课程列表")
    @GetMapping("/list")
    public AjaxResult<OrderPossessUserVo> list(OrderPossessUserQueryBo bo) {
        ClientLoginUser loginUser = WxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        OrderPossessUserVo list = iOrderPossessUserService.queryList(bo);
        return  AjaxResult.success(list);
    }

    @ApiOperation("查询是否拥有该项目")
    @GetMapping("/owner")
    public AjaxResult owner(OrderPossessUserQueryBo bo) {
        ClientLoginUser loginUser = WxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        Integer i = Validator.isNotNull(iOrderPossessUserService.queryByTypeAndId(bo.getPossessId(),bo.getTypeId(),bo.getUserId()))?1:0;
        Map<String,Integer> map = new HashMap<>();
        map.put("payStatus",i);
        return  AjaxResult.success(map);
    }

}
