package com.hzs.activity.tourism.controller.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hzs.activity.base.service.IAcGoalMemberConfigService;
import com.hzs.activity.tourism.service.IAcTourismDataService;
import com.hzs.common.core.enums.ERangeType;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.domain.activity.base.AcGoalMemberConfig;
import com.hzs.common.domain.activity.tourism.AcTourismData;
import com.hzs.common.domain.member.ext.CuMemberExt;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.member.base.IMemberServiceApi;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * @Description: 旅游活动会员端API
 * @Author: jiang chao
 * @Time: 2024/2/23 15:16
 * @Classname: ApiTourismController
 * @PackageName: com.hzs.activity.tourism.controller.api
 */
@RestController
@RequestMapping("/api/tourism")
public class ApiTourismController {

    @Autowired
    private IAcGoalMemberConfigService iAcGoalMemberConfigService;
    @Autowired
    private IAcTourismDataService iAcTourismDataService;

    @DubboReference
    IMemberServiceApi iMemberServiceApi;

    @GetMapping("/tourism-point/{pkBaseId}")
    public AjaxResult tourismPoint(@PathVariable Long pkBaseId) {
        CuMemberExt cuMemberExt = iMemberServiceApi.getMemberById(SecurityUtils.getUserId()).getData();

        // TODO 查询是否符合配置的奖衔（此处先暂时这么写，后续这个活动需要调整时，再进行修改）
        LambdaQueryWrapper<AcGoalMemberConfig> configQueryWrapper = new LambdaQueryWrapper<>();
        configQueryWrapper.eq(AcGoalMemberConfig::getPkCountry, SecurityUtils.getPkCountry());
        configQueryWrapper.eq(AcGoalMemberConfig::getPkBaseId, pkBaseId);
        configQueryWrapper.eq(AcGoalMemberConfig::getMemberType, ERangeType.AWARDS.getValue());
        configQueryWrapper.eq(AcGoalMemberConfig::getPkLevel, cuMemberExt.getPkAwards());
        AcGoalMemberConfig acGoalMemberConfig = iAcGoalMemberConfigService.getOne(configQueryWrapper);
        if (null == acGoalMemberConfig) {
            // 不符合当前活动，直接返回为空
            return AjaxResult.success();
        }

        // 返回积分
        BigDecimal point = BigDecimal.ZERO;

        // 查询返回数据
        LambdaQueryWrapper<AcTourismData> dataQueryWrapper = new LambdaQueryWrapper<>();
        dataQueryWrapper.eq(AcTourismData::getPkBaseId, pkBaseId);
        dataQueryWrapper.eq(AcTourismData::getPkMember, SecurityUtils.getUserId());
        AcTourismData acTourismData = iAcTourismDataService.getOne(dataQueryWrapper);
        if (null != acTourismData) {
            point = acTourismData.getPoint();
        }

        return AjaxResult.success(point);
    }

}
