package com.hzs.system.config.controller.api;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hzs.common.core.annotation.Log;
import com.hzs.common.core.enums.EOperationBusiness;
import com.hzs.common.core.enums.EOperationMethod;
import com.hzs.common.core.enums.EOperationModule;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.domain.system.config.BdGrade;
import com.hzs.common.domain.system.config.ext.BdGradeExt;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.member.base.IMemberServiceApi;
import com.hzs.system.config.service.IBdGradeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 等级配置表 前端控制器
 * </p>
 *
 * @author zhangjing
 * @since 2022-09-08
 */
@Slf4j
@RestController
@RequestMapping("/api/grade")
public class ApiBdGradeController extends BaseController {

    @Autowired
    private IBdGradeService gradeService;
    @DubboReference
    private IMemberServiceApi memberServiceApi;
    /**
     * @description: 等级(直推)范围列表
     * @author: zhang jing
     * @date: 2022/10/26 13:36
     * @param: [grade]
     * @return: com.hzs.common.core.web.page.TableDataInfo
     **/
    @Log(module = EOperationModule.LEVEL_CONFIG,business = EOperationBusiness.GRADE, method = EOperationMethod.SELECT)
    @GetMapping("/list")
    public AjaxResult list() {
        QueryWrapper<BdGrade> queryWrapper = new QueryWrapper();
        queryWrapper.eq("PK_COUNTRY", SecurityUtils.getPkCountry());
        queryWrapper.orderByAsc("GRADE_VALUE");
        List<BdGrade> grList = gradeService.list(queryWrapper);
        List<BdGradeExt> list= new ArrayList<>();
        for(BdGrade gr:grList){
            BdGradeExt gre=new BdGradeExt();
            gre.setPkId(gr.getPkId());
            gre.setGradeName(gr.getGradeName());
            gre.setGradeValue(gr.getGradeValue());
            list.add(gre);
        }
        return AjaxResult.success(list);
    }

}
