package com.sptg.estate.biz.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.common.core.constant.OperationConstant;
import com.sptg.estate.api.dto.ThirdUserDto;
import com.sptg.estate.api.entity.ThirdUser;
import com.sptg.estate.biz.mapper.ThirdUserMapper;
import com.sptg.estate.biz.service.*;
import com.sptg.permissions.api.feigns.ConfFeign;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * title: UserServiceImpl
 * package: com.sptg.estate.biz.security.impl
 * description: 住户 服务层实现类
 *
 *
 *
 */
@Service
@RequiredArgsConstructor
public class ThirdUserServiceImpl extends ServiceImpl<ThirdUserMapper, ThirdUser> implements ThirdUserServiceInterface {

    private final RoomServiceInterface roomServiceInterface;
    private final FloorServiceInterface floorServiceInterface;
    private final UnitServiceInterface unitServiceInterface;
    private final BuildingServiceInterface buildingServiceInterface;
    private final ResidentialServiceInterface residentialServiceInterface;
    private final MemberAndUserInterface memberAndUserInterface;
    private final RedisTemplate<String,String> redisTemplate;
    private final VideoCallAccountServiceInterface videoCallAccountServiceInterface;
    private final ConfFeign confFeign;
    private final AccessFacePushRecordsServiceInterface accessFacePushRecordsServiceInterface;
    private final AccessCardPushRecordsServiceInterface accessCardPushRecordsServiceInterface;

    /**
     * 特殊 防止循环依赖问题 MemberServiceInterface中依赖了UserServiceInterface
     */
    @Autowired
    @Lazy
    private  MemberServiceInterface memberServiceInterface;

    @Autowired
    @Lazy
    private  AccessCardServiceInterface accessCardServiceInterface;

    private final static String IMPORT_CACHE_USER_NMAE = "sptg:import:card:user:name";


    @Override
    public ResultBean<Boolean> addUser(ThirdUserDto userDto) {
        if(this.insert(userDto)){
            return new ResultBean<>(ResultEnum.SUCCESS);
        }
        return new ResultBean<>(ResultEnum.ERROR);
    }

    @Override
    public ThirdUser findUserById(Long id) {
        return null;
    }

    @Override
    public boolean updateEntity(ThirdUser user) {
        return this.updateById(user);
    }

    @Override
    public List<ThirdUser> getListByCondition(ThirdUserDto dto) {
        Wrapper<ThirdUser> wrapper = new EntityWrapper<>();
        //过滤删除
        wrapper.notIn("i_status", OperationConstant.MINUS_ONE);
        //过滤已同步的数据
        wrapper.eq("i_sign", 0);
        if (StringUtils.isNotBlank(dto.getImageName())){
            wrapper.eq("s_image_name", dto.getImageName());
        }
        return this.selectList(wrapper);
    }

    @Override
    public ResultBean<Boolean> updateUser(ThirdUserDto userDto) {
        return null;
    }

    @Override
    public ResultBean<Boolean> deleteUser(ThirdUserDto userDto) {
        return null;
    }
}
