package com.liquidnet.service.chime.biz;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.chime.vo.mongo.ChimeUserTagsMappingVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

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

/**
 * @author AnJiabin <anjiabin@zhengzai.tv>
 * @version V1.0
 * @Description: TODO
 * @class: ChimeUserBiz
 * @Package com.liquidnet.service.chime.biz
 * @Copyright: LightNet @ Copyright (c) 2021
 * @date 2021/9/11 16:16
 */
@Slf4j
@Component
public class ChimeUserBiz {
    /**
     * Json转换list
     * @param tags
     * @return
     */
    public List<ChimeUserTagsMappingVo> buildUserTagVoList(String userId,String tags){
        List<ChimeUserTagsMappingVo> userTagList = new ArrayList<>();
        if(StringUtil.isNotEmpty(tags)){
            ObjectMapper mapper = new ObjectMapper();
            try {
                userTagList = mapper.readValue(tags, new TypeReference<List<ChimeUserTagsMappingVo>>() {});
            } catch (JsonProcessingException e) {
                e.printStackTrace();
                log.error("createChimeUserInfo msg:{}",e.getMessage());
                log.error("createChimeUserInfo error : ",e);
                return null;
            }
        }
        //设置用户id
        userTagList.stream().forEach(vo -> vo.setUserId(userId));
        return userTagList;
    }
}
