package com.yuchen.saas.park.service.service.security.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yuchen.saas.park.api.entity.security.SaasParkFaceDetectEvent;
import com.yuchen.saas.park.service.mapper.security.SaasParkFaceDetectEventMapper;
import com.yuchen.saas.park.service.service.security.ISaasParkFaceDetectEventService;
import org.nest.springwrap.core.mp.base.BaseServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 宇视人脸检测事件表 服务实现类
 * </p>
 *
 * @author 洪铭铭
 * @since 2024-09-12
 */
@Service
public class SaasParkFaceDetectEventServiceImpl extends BaseServiceImpl<SaasParkFaceDetectEventMapper, SaasParkFaceDetectEvent> implements ISaasParkFaceDetectEventService {

    public List<SaasParkFaceDetectEvent> getAll() {

        LambdaQueryWrapper<SaasParkFaceDetectEvent> qw = new LambdaQueryWrapper<>();
        List<SaasParkFaceDetectEvent> saasParkFaceDetectEventList = baseMapper.selectList(qw);

        return saasParkFaceDetectEventList;
    }


//    @Autowired
//    private IntegratedClient integratedClient;
//    @Autowired
//    PmgBatSmartEquipmentService equipmentService;
//
//    @Autowired
//    private SubscribeConfiguration subscribeConfiguration;
//
//    @Autowired
//    MinioUtils minioUtils;
//
//    @Override
//    public R personTrack(PersonTrackDTO personTrackDTO) {
//        //  ISCResult subResult = ISCClient.callApi2(personTrackDTO,"/api/frs/v1/application/captureSearch");
//        ISCResult subResult = ISCClient.callApi3(personTrackDTO,"/api/frs/v1/application/captureSearch",subscribeConfiguration.getIpApiEndpoint());
//        PersonTrackVo personTrackVo = GsonUtils.fromJson(JSONPrint.printObject(subResult.getData()),
//                PersonTrackVo.class);
//        if(personTrackVo!=null){
//            if(personTrackVo.getList() != null && personTrackVo.getList().size()>0){
//                for (PersonTrackVo.FaceList face:personTrackVo.getList()
//                ) {
//
//                    IotBatIntegratedDevice iotBatIntegratedDevice= integratedClient.getDeviceByCameraCode(face.getCameraIndexCode()).getData();
//
//                    if(iotBatIntegratedDevice!=null){
//                        PmgBatSmartEquipment pmgBatSmartEquipment = equipmentService.getOne(Wrappers.<PmgBatSmartEquipment>lambdaQuery()
//                                .select(PmgBatSmartEquipment::getParkId, PmgBatSmartEquipment::getTenantId,PmgBatSmartEquipment::getPlanePosition)
//                                .eq(PmgBatSmartEquipment::getProductKey, iotBatIntegratedDevice.getProductKey())
//                                .eq(PmgBatSmartEquipment::getDeviceName, iotBatIntegratedDevice.getDeviceName()));
//                        //  PmgBatSmartEquipment      pmgBatSmartEquipment     =  pmgBatSmartEquipmentClient.getDeviceByPKandDn(iotBatIntegratedDevice.getDeviceName(),iotBatIntegratedDevice.getProductKey());
//                        if(pmgBatSmartEquipment!=null){
//                            face.setPlanePosition(pmgBatSmartEquipment.getPlanePosition());
//                            face.setName(pmgBatSmartEquipment.getName());
//                        }
//                    }
//                    Map<String, Object> subscribeParams = new HashMap<>();
//                    List<String> list= new ArrayList<>();
//                    list.add(face.getCameraIndexCode());
//                    subscribeParams.put("resourceType", "camera");
//                    subscribeParams.put("resourceIndexCodes", list);
//                    //subscribeParams.put("pageSize", 100);
//                    //    ISCResult subResult = ISCClient.callApi(subscribeParams,"/api/irds/v2/resource/resourcesByParams");
//                    ISCResult subResult2 = ISCClient.callApi(subscribeParams,"/api/resource/v1/resource/indexCodes/search");
//                    CameraVo cameraVo = GsonUtils.fromJson(JSONPrint.printObject(subResult2.getData()),
//                            CameraVo.class);
//
//                    CameraVo.CameraInfo cameraInfo= cameraVo.getList().get(0);
//                    face.setName(cameraInfo.getName());
//                    face.setLongitude(cameraInfo.getLongitude());
//                    face.setLatitude(cameraInfo.getLatitude());
//                    face.setElevation(cameraInfo.getElevation());
//                }
//            }
//        }
//        return R.data(personTrackVo);
//    }
//
//    @Override
//    public R uploadImage(MultipartFile file) {
//        try {
//            String images=  Base64.getEncoder().encodeToString(file.getBytes());
//            //  System.out.println(images);
//            return R.data(images);
//            //  personTrackDTO.setFacePicBinaryData(images);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//
//        return null;
//    }
//
//    @Override
//    public R faceSingleAddition(FaceSingleAdditionDTO faceSingleAdditionDTO) {
//        //添加人员黑名单
//        faceSingleAdditionDTO.setFaceGroupIndexCode("2881f9a58ac74687bbdf2d20d2035430");
//        byte[] bytes= Base64.getDecoder().decode(faceSingleAdditionDTO.getFacePic().getFaceBinaryData());
//        String images=  Base64.getEncoder().encodeToString(PicUploadUtils.compressPicForScale(bytes,200,faceSingleAdditionDTO.getFaceInfo().getName()));
//        faceSingleAdditionDTO.getFacePic().setFaceBinaryData(images);
//        // ISCResult subResult = ISCClient.callApi2(faceSingleAdditionDTO,"/api/frs/v1/face/single/addition");
//        ISCResult subResult = ISCClient.callApi3(faceSingleAdditionDTO,"/api/frs/v1/face/single/addition",subscribeConfiguration.getIpApiEndpoint());
//        return R.data(subResult);
//    }
//
//    @Override
//    public R faceGroupList(FaceGroupListDTO faceGroupListDTO) {
//        //获取人员黑名单
//        faceGroupListDTO.setFaceGroupIndexCode("2881f9a58ac74687bbdf2d20d2035430");
//        ISCResult subResult = ISCClient.callApi3(faceGroupListDTO,"/api/frs/v1/face",subscribeConfiguration.getIpApiEndpoint());
//        if(Func.isNotEmpty(subResult.getData())){
//            Map resultMap= JSON.parseObject(JSON.toJSONString( subResult.getData()), Map.class);
//            List<Map> maps = JSON.parseArray(JSON.toJSONString(resultMap.get("list")), Map.class);
//            if(Func.isNotEmpty(maps)){
//                for (Map item:maps) {
//                    if(item.containsKey("facePic")){
//                        Map urlMap=JSON.parseObject(JSON.toJSONString( item.get("facePic")), Map.class);
//                        if(urlMap.containsKey("faceUrl")){
//                            String pictureName= StringUtils.EMPTY;
//                            if(item.containsKey("indexCode")){
//                                pictureName=MapUtils.getString(item,"indexCode");
//                            }
//                            String facePicUrl = PicUploadUtils.uploadMinioPic(MapUtils.getString(urlMap,"faceUrl"), "face_match", minioUtils,pictureName);
//                            urlMap.put("faceUrl",facePicUrl);
//                            item.put("facePic",urlMap);
//                        }
//                    }
//                }
//            }
//            resultMap.put("list",maps);
//            return R.data(resultMap);
//        }
//        return R.data(subResult.getData());
//    }
//
//    @Override
//    public R faceGroups(String name, ArrayList<String> list) {
//        Map<String, Object> params = new HashMap<>();
//        //获取人员黑名单
//        params.put("indexCodes",list);
//     /*   ArrayList<String> list=new ArrayList<>();
//        list.add()*/
//        params.put("name",name);
//
//        ISCResult subResult = ISCClient.callApi(params,"/api/frs/v1/face/group");
//        return R.data(subResult.getData());
//    }
//
//
//    @Override
//    public R getPictureByUrl(String url) {
//        Map<String, Object> params = new HashMap<>();
//        //获取人员黑名单
//        params.put("url",url);
//        ISCResult subResult = ISCClient.callApi(params,"/api/frs/v1/application/picture");
//        return R.data(subResult.getData());
//    }
//
//    @Override
//    public R personInfo(String param, ArrayList<String> list) {
//        Map<String, Object> params = new HashMap<>();
//        //获取人员黑名单
//        params.put("paramName",param);
//     /*   ArrayList<String> list=new ArrayList<>();
//        list.add()*/
//        params.put("paramValue",list);
//        ISCResult subResult = ISCClient.callApi(params,"/api/resource/v1/person/condition/personInfo");
//        return R.data(subResult.getData());
//    }
//
//    /**
//     * 人员布控删除
//     * @param map
//     * @return
//     */
//    @Override
//    public R deleteFace(Map<String,Object> map) {
//        Map<String, Object> params = new HashMap<>();
//        ISCResult subResult = ISCClient.callApi(map,"/api/frs/v1/face/deletion");
//        if(subResult != null && "0".equals(subResult.getCode())){
//            return R.data(subResult.getData());
//        }else{
//            return R.fail(subResult.getMsg());
//        }
//
//    }


}
