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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hzs.common.core.constant.CacheConstants;
import com.hzs.common.core.constant.SystemFieldConstants;
import com.hzs.common.core.enums.EYesNo;
import com.hzs.common.core.service.RedisService;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.domain.system.config.BdRegisterPage;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.system.config.service.IBdRegisterPageService;
import com.hzs.system.config.vo.RegisterPageVO;
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.ArrayList;
import java.util.List;

/**
 * @Description: 前端注册页面配置控制器
 * @Author: jiang chao
 * @Time: 2022/10/19 9:44
 * @Classname: ApiBdRegisterPageController
 * @PackageName: com.hzs.system.config.controller.api
 */
@RestController
@RequestMapping("/api/register-page")
public class ApiBdRegisterPageController {

    @Autowired
    private IBdRegisterPageService iBdRegisterPageService;
    @Autowired
    private RedisService redisService;

    /**
     * 获取菜单权限列表
     *
     * @return
     */
    @Deprecated
    @GetMapping("/list")
    public AjaxResult list(Integer pkCountry) {
        if (null == pkCountry) {
            pkCountry = SecurityUtils.getPkCountry();
        }
        QueryWrapper<BdRegisterPage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(SystemFieldConstants.PK_COUNTRY, pkCountry);
        queryWrapper.eq("DISPLAY", EYesNo.YES.getIntValue());
        queryWrapper.orderByAsc(SystemFieldConstants.PK_ID);
        List<BdRegisterPage> list = iBdRegisterPageService.list(queryWrapper);

        List<RegisterPageVO> resultList = new ArrayList<>();
        for (BdRegisterPage bdRegisterPage : list) {
            resultList.add(RegisterPageVO.builder()
                    .field(bdRegisterPage.getField())
                    .build());
        }

        return AjaxResult.success(resultList);
    }

    /**
     * 注册权限控制
     *
     * @return
     */
    @GetMapping("/config")
    public AjaxResult registerConfig() {
//        if (redisService.hasKey(CacheConstants.REGISTER_BANK_FLAG + SecurityUtils.getPkCountry())) {
            // 缓存中存在注册银行控制KEY，则不需要必填银行信息
            return AjaxResult.success("", EYesNo.NO.getIntValue());
//        }
//        // 缓存中不存在注册银行控制KEY，则需要必填银行信息
//        return AjaxResult.success("", EYesNo.YES.getIntValue());
    }

}
