package com.hzs.activity.tree.controller.api;/**
 * @Description:
 * @Author: yuhui
 * @Time: 2023/7/18 16:32
 * @Classname: ApiTreeRuleConfigController
 * @PackageName: com.hzs.activity.tree.controller.api
 */

import com.hzs.activity.tree.param.TreeOrderParam;
import com.hzs.activity.tree.service.IAcTreeRuleConfigService;
import com.hzs.activity.tree.service.ISaTreeOrderService;
import com.hzs.common.core.domain.R;
import com.hzs.common.core.utils.DateUtils;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.page.TableDataInfo;
import com.hzs.common.domain.activity.ext.SaTreeOrderExt;
import com.hzs.common.domain.system.config.BdAwards;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.system.config.IAwardsServiceApi;
import com.hzs.system.config.IGradeServiceApi;
import com.hzs.system.config.dto.GradeDTO;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *@BelongsProject: hzs_cloud
 *@BelongsPackage: com.hzs.activity.tree.controller.api
 *@Author: yh
 *@CreateTime: 2023-07-18  16:32
 *@Description: TODO
 *@Version: 1.0
 */
@RequestMapping("/api/tree-rule-pick")
@RestController
public class ApiTreeRuleConfigController extends BaseController {

    @DubboReference
    private IGradeServiceApi gradeServiceApi;
    @DubboReference
    private IAwardsServiceApi awardsServiceApi;
    @Autowired
    private IAcTreeRuleConfigService treeRuleConfigService;

    @Autowired
    private ISaTreeOrderService treeOrderService;


    /**
     * 查询种植公益列表
     * @param treeOrderParam
     * @return
     */
    @GetMapping("member-info-list")
    public TableDataInfo list(TreeOrderParam treeOrderParam){
        if (null != treeOrderParam.getStartPayDate()) {
            treeOrderParam.setStartPayDate(DateUtils.getStartTime(treeOrderParam.getStartPayDate()));
        }
        if (null != treeOrderParam.getEndPayDate()) {
            treeOrderParam.setEndPayDate(DateUtils.getEndTime(treeOrderParam.getEndPayDate()));
        }

        // 奖衔
        R<List<BdAwards>> awardsDto = awardsServiceApi.queryAwards(SecurityUtils.getPkCountry());
        // 等级
        R<List<GradeDTO>> gradeDTO = gradeServiceApi.queryGradeList(SecurityUtils.getPkCountry());
        treeOrderParam.setMemberCode(SecurityUtils.getMemberCode());
        List<SaTreeOrderExt> treeOrderList = treeOrderService.selectByList(treeOrderParam);
        for (SaTreeOrderExt saTreeOrder : treeOrderList) {
            // 奖衔
            for (BdAwards awards : awardsDto.getData()) {
                if (saTreeOrder.getPkAwards().equals(awards.getPkId())){
                    saTreeOrder.setAwardsStr(awards.getAwardsName());
                }
            }
            // 等级
            for (GradeDTO grade : gradeDTO.getData()) {
                if (saTreeOrder.getPkSettleGrade().equals(grade.getPkId())){
                    saTreeOrder.setSettleGradeStr(grade.getGradeName());
                }
            }
        }
        return getDataTable(treeOrderList);
    }
}
