package com.hzs.member.base.controller.api;

import com.hzs.common.core.enums.EYesNo;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.core.web.page.TableDataInfo;
import com.hzs.common.domain.member.ext.CuHonorWallExt;
import com.hzs.common.domain.member.ext.CuMemberHonorWallExt;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.member.base.service.ICuHonorWallService;
import com.hzs.member.base.service.ICuMemberHonorWallService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @BelongsProject: hzs_cloud
 * @BelongsPackage: com.hzs.member.base.controller.api
 * @Author: yh
 * @CreateTime: 2023-04-26  20:30
 * @Description: TODO
 * @Version: 1.0
 */
@RequestMapping("/api/member")
@RestController
public class ApiHonorWallController extends BaseController {

    @Autowired
    private ICuMemberHonorWallService memberHonorWallService;
    @Autowired
    private ICuHonorWallService honorWallService;

    /**
     * 查询会员荣誉墙信息
     *
     * @return
     */
    @GetMapping("member-honor-wall")
    public AjaxResult memberHonorWall() {
        //查询会员荣誉墙
        //     startPage();
        List<CuMemberHonorWallExt> resultList = memberHonorWallService.getByMemberHonorWall(SecurityUtils.getUserId());
        return AjaxResult.success(resultList);
    }


    /**
     * 查询会员荣誉墙
     *
     * @return
     */
    @GetMapping("member-honor-wall-all")
    public TableDataInfo memberHonorWallAll() {
        Integer pkCountry = SecurityUtils.getPkCountry();
        Long pkMember = SecurityUtils.getUserId();
        startPage();
        List<CuHonorWallExt> resultList = honorWallService.queryAll(pkCountry, pkMember);
        for (CuHonorWallExt cuHonorWallExt : resultList) {
            if (cuHonorWallExt.getPkMember() == null) {
                // 未拥有
                cuHonorWallExt.setIsHave(EYesNo.NO.getIntValue());
            } else {
                // 已拥有
                cuHonorWallExt.setIsHave(EYesNo.YES.getIntValue());
            }
        }
        return getDataTable(resultList);
    }

}
