package com.hzs.common.service.impl;

import com.hzs.common.core.constant.CacheConstants;
import com.hzs.common.core.constant.MagicNumberConstants;
import com.hzs.common.core.service.RedisService;
import com.hzs.common.domain.member.base.CuMember;
import com.hzs.common.domain.system.sys.SysUser;
import com.hzs.common.service.IBusinessCommonService;
import com.hzs.member.base.IMemberServiceApi;
import com.hzs.system.sys.IUserServiceApi;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Description:
 * Author: sui q
 * Time: 2022/9/29 13:48
 * Classname: BusinessCommonServiceImpl
 * PackageName: com.hzs.common.service
 */
@Service
public class BusinessCommonServiceImpl implements IBusinessCommonService {

    @DubboReference
    private IUserServiceApi userServiceApi;

    @DubboReference
    private IMemberServiceApi memberServiceApi;

    private RedisService redisService;

    @Autowired
    public void setRedisService(RedisService redisService) {
        this.redisService = redisService;
    }

//    @Override
//    public <T> Object convertIdToObject(Long pkId) {
//        if (pkId < MagicNumberConstants.SYS_USER_ID) {
//            SysUser sysUser = redisService.getCacheObject(CacheConstants.USER + pkId);
//            if (sysUser == null) {
//                sysUser = userServiceApi.selectUserById(pkId).getData();
//            }
//            return sysUser;
//        } else {
//            CuMember cuMember = redisService.getCacheObject(CacheConstants.MEMBER_ID + pkId);
//            if (cuMember == null) {
//                cuMember = memberServiceApi.getMember(pkId).getData();
//            }
//            return cuMember;
//        }
//    }
//
//    @Override
//    public String convertIdToString(Long pkId) {
//        if (null == pkId) {
//            return "";
//        }
//        if (pkId < MagicNumberConstants.SYS_USER_ID) {
//            SysUser sysUser = redisService.getCacheObject(CacheConstants.USER + pkId);
//            if (sysUser == null) {
//                sysUser = userServiceApi.selectUserById(pkId).getData();
//            }
//            return sysUser.getUserName();
//        } else {
//            CuMember cuMember = redisService.getCacheObject(CacheConstants.MEMBER_ID + pkId);
//            if (cuMember == null) {
//                cuMember = memberServiceApi.getMember(pkId).getData();
//            }
//            return cuMember.getMemberCode();
//        }
//    }

}
