package com.zd.forward.serivce;

import com.zd.common.core.domain.R;
import com.zd.forward.config.AlgorithmYml;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 视频源:人数结果解析
 * @Author: zhoupan
 * @Date: 2021/11/14/12:54
 * @Description:
 */
@Service
public class PeopleCheckResultValidImpl implements VideoCheckResultValid{

    @Autowired
    SendSginAccessLogService sendSginAccessLogService;

    @Autowired
    AlgorithmYml algorithmYml;

//    private void initAttr()
//    {
//        sendSginAccessLogService= SpringUtils.getBean(SendSginAccessLogService.class);
//        algorithmYml = SpringUtils.getBean(AlgorithmYml.class);
//    }

    public PeopleCheckResultValidImpl() {
    }

    @Override
    public R apply(Map<String, Object> map, Long subId) {
        try {
            Map<String, Object>  algorithm_data = (Map<String, Object>)map.get("algorithm_data");
            Boolean is_alert = (Boolean)algorithm_data.get("is_alert");
            //是不是先要判断人数？？？？？？target_count
            if(is_alert)
            {
                int target_count = (int)algorithm_data.get("target_count");
                if(target_count>0)
                {
                    Integer count = sendSginAccessLogService.getSubAccessCountBySubId(subId,algorithmYml.getLoginUri());
                    if(target_count>count)
                    {
                        return R.fail(300,"算法识别人数大于实验室人数!");
                    }
                }
            }
            //判断是否是多个目标等 返回详细失败结果
            return R.ok();
        } catch (Exception e) {
            return R.fail("结果解析错误！");
        }
    }
}
