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


import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.hzs.activity.people.service.IAcPeopleServiceService;
import com.hzs.activity.people.vo.AcPeopleGiftPackVO;
import com.hzs.activity.people.vo.AcPeopleGiftProductVO;
import com.hzs.common.core.constant.msg.CommonMsgConstants;
import com.hzs.common.core.domain.R;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.domain.member.base.CuMember;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.common.core.utils.TransactionUtils;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 新人礼包活动业务表 前端控制器
 * </p>
 *
 * @author hzs
 * @since 2023-04-26
 */
@RestController
@RequestMapping("/api/people-service")
public class ApiAcPeopleServiceController {

    @Autowired
    private IAcPeopleServiceService iAcPeopleServiceService;
    @DubboReference
    private IMemberServiceApi iMemberServiceApi;

    /**
     * @description: 查询新人礼包活动方案
     * @author: zhang jing
     * @date: 2023/5/9 20:54
     * @param: [plsVO]
     * @return: com.hzs.common.core.web.domain.AjaxResult
     **/
    @PostMapping("/getGiftPack")
    public AjaxResult getGiftPack(@RequestBody AcPeopleGiftPackVO giftPackVO) {
        if (ObjectUtil.emptyCount(
                giftPackVO.getPkBaseId()) > 0) {
            return AjaxResult.error(TransactionUtils.getContent(CommonMsgConstants.MISSING_PARAM));
        }
        Long  userId=SecurityUtils.getUserId();
        R<CuMember> cumember=iMemberServiceApi.getMember(userId);
        giftPackVO.setPkGrade(cumember.getData().getPkSettleGrade());
        List<AcPeopleGiftPackVO> giftPackList=  iAcPeopleServiceService.getGiftPackList(giftPackVO);
        if(CollectionUtil.isNotEmpty(giftPackList)){
            giftPackList.forEach(itm->{
               List<AcPeopleGiftProductVO> pgpList=iAcPeopleServiceService.getGiftPackProductList(itm.getPkNewPeople());
                itm.setPgpList(pgpList);
            });
        }
        return AjaxResult.success(giftPackList);
    }

}
