package com.srs.stureg.service.impl;

import java.util.List;

import com.srs.common.core.domain.entity.SysUser;
import com.srs.common.exception.ServiceException;
import com.srs.common.utils.DateUtils;
import com.srs.common.utils.SecurityUtils;
import com.srs.common.utils.StringUtils;
import com.srs.common.utils.bean.BeanValidators;
import com.srs.stureg.domain.SrsRegInfo;
import com.srs.stureg.mapper.SrsRegInfoMapper;
import com.srs.stureg.service.ISrsRegInfoService;
import com.srs.stureg.tools.FaceRecognition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 注册信息
Service业务层处理
 * 
 * @author srs
 * @date 2023-05-19
 */
@Service
public class SrsRegInfoServiceImpl implements ISrsRegInfoService
{
    @Autowired
    private SrsRegInfoMapper srsRegInfoMapper;

    /**
     * 查询注册信息

     * 
     * @param registerId 注册信息
主键
     * @return 注册信息

     */
    @Override
    public SrsRegInfo selectSrsRegInfoByRegisterId(Long registerId)
    {
        return srsRegInfoMapper.selectSrsRegInfoByRegisterId(registerId);
    }

    /**
     * 查询注册信息
列表
     * 
     * @param srsRegInfo 注册信息

     * @return 注册信息

     */
    @Override
    public List<SrsRegInfo> selectSrsRegInfoList(SrsRegInfo srsRegInfo)
    {
        return srsRegInfoMapper.selectSrsRegInfoList(srsRegInfo);
    }

    /**
     * 新增注册信息

     * 
     * @param srsRegInfo 注册信息

     * @return 结果
     */
    @Override
    public int insertSrsRegInfo(SrsRegInfo srsRegInfo)
    {
        srsRegInfo.setCreateTime(DateUtils.getNowDate());
        return srsRegInfoMapper.insertSrsRegInfo(srsRegInfo);
    }

    /**
     * 修改注册信息

     * 
     * @param srsRegInfo 注册信息

     * @return 结果
     */
    @Override
    public int updateSrsRegInfo(SrsRegInfo srsRegInfo)
    {
        srsRegInfo.setUpdateTime(DateUtils.getNowDate());
        return srsRegInfoMapper.updateSrsRegInfo(srsRegInfo);
    }

    /**
     * 批量删除注册信息

     * 
     * @param registerIds 需要删除的注册信息
主键
     * @return 结果
     */
    @Override
    public int deleteSrsRegInfoByRegisterIds(Long[] registerIds)
    {
        return srsRegInfoMapper.deleteSrsRegInfoByRegisterIds(registerIds);
    }

    /**
     * 删除注册信息
信息
     * 
     * @param registerId 注册信息
主键
     * @return 结果
     */
    @Override
    public int deleteSrsRegInfoByRegisterId(Long registerId)
    {
        return srsRegInfoMapper.deleteSrsRegInfoByRegisterId(registerId);
    }

    @Override
    public String importRegUser(List<SrsRegInfo> srsRegInfo) {
        if (StringUtils.isNull(srsRegInfo) || srsRegInfo.size() == 0)
        {
            throw new ServiceException("导入用户数据不能为空！");
        }
        StringBuilder successMsg = new StringBuilder();
        int successNum = 0;
        int failureNum = 0;
        for (SrsRegInfo user : srsRegInfo)
        {
            try
            {
                SrsRegInfo srsRegInfo1=new SrsRegInfo();
                srsRegInfo1.setIdentyNo(user.getIdentyNo());
                // 验证是否存在这个用户
                List<SrsRegInfo> list= srsRegInfoMapper.selectSrsRegInfoList(srsRegInfo1);
                if (list.size()<1)
                {
                    this.insertSrsRegInfo(user);
                    successNum++;
                    successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 导入成功");
                }
                else{
                    String msg = "<br/>" + failureNum + "、身份证账号已存在， " + user.getUserName() + " 导入失败：";
                    return msg;
                }
            }
            catch (Exception e)
            {
                e.printStackTrace();
                failureNum++;
                String msg = "<br/>" + failureNum + "、账号 " + user.getUserName() + " 导入失败：";
                return msg;
            }
        }

        return successMsg.toString();
    }

    @Override
    public boolean faceVetify(String pathSource, String pathLogin) {
        FaceRecognition faceRecognition=new FaceRecognition();
        Double m=faceRecognition.faceVetify(pathSource,pathLogin);
        if(m>85){
            return true;
        }
        return false;
    }
}
