package com.liquidnet.service.service.impl;

import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.service.goblin.constant.SmileRedisConst;
import com.liquidnet.service.goblin.dto.vo.SmileUserVO;
import com.liquidnet.service.goblin.service.manage.SmileFrontService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
@Slf4j
public class SmileFrontServiceImpl implements SmileFrontService {
    @Autowired
    private RedisUtil redisUtil;

    public boolean saveOrUpdateUser(SmileUserVO smileUserVO,SmileUserVO redisVo,String type){
        //redis里面更新
        if(null==redisVo){
            smileUserVO.setCreatedDate(LocalDateTime.now());
            redisUtil.set(SmileRedisConst.SMILE_USER.concat(smileUserVO.getUid()),smileUserVO);
            //插入
        }else{
            //update
            setUser(smileUserVO,redisVo,type);
            redisUtil.set(SmileRedisConst.SMILE_USER.concat(redisVo.getUid()),redisVo);
        }
        return true;
    }
    public void setUser(SmileUserVO smileUserVO,SmileUserVO redisVo,String type){
        if(type.equals("1")){
            redisVo.setImg(smileUserVO.getImg());
            redisVo.setSex(smileUserVO.getSex());
            redisVo.setProvinceKey(smileUserVO.getProvinceKey());
            redisVo.setProvince(smileUserVO.getProvince());
            redisVo.setCity(smileUserVO.getCity());
            redisVo.setCityKey(smileUserVO.getCityKey());
            redisVo.setArea(smileUserVO.getArea());
            redisVo.setAreaKey(smileUserVO.getAreaKey());
            redisVo.setAddress(smileUserVO.getAddress());
            redisVo.setWechat(smileUserVO.getWechat());
            redisVo.setSchoolName(smileUserVO.getSchoolName());
            redisVo.setSchoolMajor(smileUserVO.getSchoolMajor());
            redisVo.setIdentity(smileUserVO.getIdentity());
            redisVo.setTag(smileUserVO.getTag());
            redisVo.setUpdatedDate(LocalDateTime.now());
            redisVo.setUid(smileUserVO.getUid());

        }else if (type.equals("2")){
            redisVo.setName(smileUserVO.getName());
            redisVo.setIdCard(smileUserVO.getIdCard());
            redisVo.setUpdatedDate(LocalDateTime.now());
            redisVo.setUid(smileUserVO.getUid());
        }else if(type.equals("3")){
            redisVo.setIntroduce(smileUserVO.getIntroduce());
            redisVo.setSpecialty1(smileUserVO.getSpecialty1());
            redisVo.setSpecialty2(smileUserVO.getSpecialty2());
            redisVo.setSpecialty3(smileUserVO.getSpecialty2());
            redisVo.setUpdatedDate(LocalDateTime.now());
            redisVo.setUid(smileUserVO.getUid());
        }
    }


}
