k94314517
2024-10-30 47a53d22a025c0ed095c9c4ed2e1ce35ce54184e
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncPlatformsServiceImpl.java
@@ -1,7 +1,9 @@
package com.doumee.service.business.impl.hksync;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.haikang.model.HKConstants;
@@ -12,21 +14,22 @@
import com.doumee.core.haikang.service.HKService;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.DateUtil;
import com.doumee.dao.business.DeviceMapper;
import com.doumee.dao.business.PlatformDeviceMapper;
import com.doumee.dao.business.PlatformJobMapper;
import com.doumee.dao.business.PlatformMapper;
import com.doumee.dao.business.model.Device;
import com.doumee.dao.business.model.Platform;
import com.doumee.dao.business.model.PlatformDevice;
import com.doumee.dao.business.model.PlatformJob;
import com.github.xiaoymin.knife4j.core.util.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
 * 设备信息表Service实现
@@ -35,11 +38,16 @@
 */
@Service
public class HkSyncPlatformsServiceImpl extends HkSyncBaseServiceImpl {
    @Autowired
    private PlatformMapper platformMapper;
    @Autowired
    private PlatformJobMapper platformJobMapper;
    @Autowired
    private PlatformDeviceMapper platformDeviceMapper;
    @Autowired
    @Lazy
    private SystemDictDataBiz systemDictDataBiz;
    /**
     * 同步海康月台数据
@@ -60,7 +68,7 @@
            List<PlatformDevice> deviceList = new ArrayList<>();
            Date date = new Date();
            //查询全部门禁设备数据
            List<Platform> allList = platformMapper.selectList(null);
            List<Platform> allList = platformMapper.selectList(new QueryWrapper<Platform>().lambda().eq(Platform::getIsdeleted,Constants.ZERO));
            List<PlatformListInfoResponse> allHkList = getAllHkList(param);
            /**
             * 获取增删改数据集合
@@ -68,9 +76,24 @@
            getDataChangeList(allList,allHkList,addList,deviceList,editList,deleteList,date);
            if(deleteList.size()>0){
                //逻辑删除
                List<Integer> platIds = new ArrayList<>();
                for(Platform d : deleteList){
                    platformMapper.updateById(d);
                    platIds.add(d.getId());
                }
                //更新删除的月台信息删正在执行的作业状态为【待签到】状态
                platformJobMapper.update(null,  new UpdateWrapper<PlatformJob>().lambda()
                        .eq(PlatformJob::getIsdeleted,Constants.ZERO)
                        .notIn(PlatformJob::getStatus,Constants.PlatformJobStatus.WART_SIGN_IN.getKey()
                                ,Constants.PlatformJobStatus.WAIT_CONFIRM.getKey()
                                ,Constants.PlatformJobStatus.DONE.getKey()
                                ,Constants.PlatformJobStatus.LEAVED.getKey()
                                ,Constants.PlatformJobStatus.CANCEL.getKey() )
                        .in(PlatformJob::getPlatformId,platIds)
                        .set(PlatformJob::getPlatformId,null)
                        .set(PlatformJob::getPlatforms,null)
                        .set(PlatformJob::getStatus,Constants.PlatformJobStatus.WART_SIGN_IN.getKey())
                );
            }
            if(deviceList.size()>0){
                platformDeviceMapper.insert(deviceList);
@@ -165,7 +188,9 @@
                    editList.add(model);
                    //清空监控点数据
                    platformDeviceMapper.delete(new UpdateWrapper<PlatformDevice>().lambda()
                            .eq(PlatformDevice::getPlatformId,model.getId()));
                            .eq(PlatformDevice::getPlatformId,model.getId())
                            .eq(PlatformDevice::getType,Constants.ONE)
                    );
                    deviceList.addAll(getCameraList(device.getCameras(),model));
                }else{
                    //如果不存在,则新增数据
@@ -183,13 +208,13 @@
    private List<PlatformDevice> getCameraList(List<PlatformCameraInfoResponse> cameras, Platform model) {
        List<PlatformDevice> list = new ArrayList<>();
        if(cameras!=null || cameras.size()>0){
        if(cameras!=null && cameras.size()>0){
            for(PlatformCameraInfoResponse param :cameras){
                PlatformDevice d = new PlatformDevice();
                d.setCreateDate(model.getCreateDate());
                d.setPlatformId(model.getId());
                d.setIsdeleted(Constants.ZERO);
                d.setDeviceId(param.getCameraIdompan());
                d.setDeviceId(param.getCameraId());
                d.setName(param.getCameraName());
                d.setType(Constants.ONE);
                list.add(d);
@@ -255,7 +280,48 @@
            }
        }
        return  true;
    }
    public  List<Integer> getMenuConfig(String userId){
        try {
            List<Integer> resultList= new ArrayList<>();
            Map<String,String> param = new HashMap<>();
            param.put("userId",userId);
            BaseResponse<MenuDataResponse> result = HKService.getMenuConfig(param);
            if(result !=null){
                if(!StringUtils.equals(result.getCode(),HKConstants.RESPONSE_SUCCEE)){
                    throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),result.getMsg());
                }
                MenuDataResponse menuDataResponse = result.getData();
                List<String> list = menuDataResponse.getList();
                if(CollectionUtils.isNotEmpty(list)){
                    //分别判断4个菜单
                    if(list.stream().filter(i->i.equals("Infovision iPark Platform_"+HKConstants.MenuPageId.afzx)).collect(Collectors.toList()).size()>Constants.ZERO){
                        resultList.add(0);
                    }
                    if(list.stream().filter(i->i.equals("Infovision iPark Platform_"+HKConstants.MenuPageId.xkzx)).collect(Collectors.toList()).size()>Constants.ZERO){
                        resultList.add(1);
                    }
                    if(list.stream().filter(i->i.equals("Infovision iPark Platform_"+HKConstants.MenuPageId.ngzx)).collect(Collectors.toList()).size()>Constants.ZERO){
                        resultList.add(2);
                    }
                    if(list.stream().filter(i->i.equals("Infovision iPark Platform_"+HKConstants.MenuPageId.jsc)).collect(Collectors.toList()).size()>Constants.ZERO){
                        resultList.add(3);
                    }
                    if(list.stream().filter(i->i.equals("Infovision iPark Platform_"+HKConstants.MenuPageId.kqgzt)).collect(Collectors.toList()).size()>Constants.ZERO){
                        resultList.add(4);
                    }
                }
                return resultList;
            }else{
                throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,获取菜单失败!");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,获取菜单失败,请稍后重试!");
    }
}