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.estate.api.entity.ServerUserFaceImage;
import com.sptg.estate.biz.mapper.ServerUserFaceImageMapper;
import com.sptg.estate.biz.service.ServerUserFaceImageServiceInterface;
import com.sptg.permissions.api.feigns.ConfFeign;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * title: ServerUserFaceImageImpl
 * package: com.sptg.estate.biz.security.impl
 * description: 服务人员人脸图片-服务层实现
 *
 *
 *
 */
@Service
@RequiredArgsConstructor
public class ServerUserFaceImageServiceImpl extends ServiceImpl<ServerUserFaceImageMapper, ServerUserFaceImage> implements ServerUserFaceImageServiceInterface {

    private final ConfFeign confFeign;
    @Override
    public boolean deleteServerUserFaceImageByServerUserId(long serverUserId){
        EntityWrapper<ServerUserFaceImage> wrapper=new EntityWrapper<>();
        wrapper.eq("l_server_user_id",serverUserId);
        return this.delete(wrapper);
    }

    @Override
    public List<Map<String,Object>> selectFaceCodeByUserId(Long userId) {
        Wrapper<ServerUserFaceImage> wrapper = new EntityWrapper<>();
        wrapper.eq("l_server_user_id",userId);
        wrapper.setSqlSelect("distinct s_image_uri imageUri,s_face_code faceCode");
        List<ServerUserFaceImage> objList = this.selectList(wrapper);
        List<Map<String, Object>> list = new ArrayList<>(objList.size());
        if (objList.size() > 0) {
            objList.forEach(obj -> {
                ServerUserFaceImage faceImage = obj;
                Map<String, Object> map = new HashMap<>(3);
                String imgHost = this.confFeign.getFileServerHost();
                map.put("imgSrc", imgHost+faceImage.getImageUri());
                map.put("imgMd5", faceImage.getFaceCode());
                list.add(map);
            });
        }
        return list;
    }

    @Override
    public List<ServerUserFaceImage> selectByServerUserId(Long serverUserId) {
        EntityWrapper<ServerUserFaceImage> wrapper = new EntityWrapper<>();
        wrapper.eq("l_server_user_id", serverUserId);
        return this.selectList(wrapper);
    }
}
