package com.ld.igds.inout.manager;
|
|
import com.ld.igds.camera.ApiCameraManager;
|
import com.ld.igds.camera.CameraUtil;
|
import com.ld.igds.camera.data.ApiCameraData;
|
import com.ld.igds.camera.data.ApiCameraResp;
|
import com.ld.igds.camera.data.ApiSnapReq;
|
import com.ld.igds.data.SnapImgDto;
|
import com.ld.igds.file.CoreFileService;
|
import com.ld.igds.inout.ApiInoutManager;
|
import com.ld.igds.inout.InoutConstant;
|
import com.ld.igds.inout.dto.ApiInoutData;
|
import com.ld.igds.inout.dto.InoutCameraDto;
|
import com.ld.igds.inout.dto.InoutData;
|
import com.ld.igds.inout.ApiInoutService;
|
import com.ld.igds.io.constant.ProtocolEnum;
|
import com.ld.igds.m.service.InoutCommonService;
|
import com.ld.igds.models.InoutConf;
|
import com.ld.igds.models.SnapSer;
|
import com.ld.igds.util.ContextUtil;
|
import com.ld.igds.view.service.SnapSerService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.Resource;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
|
/**
|
* @Desc: 出入库相关设备操作,业务逻辑包括摄像头操作,地磅,扦样机等所有设备
|
* @author: Andy
|
* @update-time: 2022/11/24
|
*/
|
@Slf4j
|
@Component
|
public class InoutDeviceManager {
|
|
@Resource
|
private SnapSerService snapSerService;
|
@Resource
|
private InoutCommonService inoutCommonService;
|
@Resource
|
private CoreFileService fileService;
|
@Resource
|
private ApiInoutManager apiInoutManager;
|
@Resource
|
private ApiCameraManager apiCameraManager;
|
|
|
public ApiInoutData getPlateNum(ApiInoutData param) {
|
|
//如果使用的是地磅插件获取,则需要调整设备为地磅插件信息
|
if (ProtocolEnum.TCP_FZZY_WEIGHT.getCode().equals(param.getProtocol())) {
|
|
InoutConf conf = this.getInoutConf(param.getCompanyId(), param.getDeptId(), param.getSort(), InoutConstant.CONF_TYPE_70);
|
if (null == conf) {
|
param.setErrorMsg("没有获取到当前协议插件配置配置信息,获取失败");
|
return param;
|
}
|
|
ApiInoutData pluginWeight = new ApiInoutData();
|
pluginWeight = param;
|
pluginWeight.setIp(conf.getIp());
|
pluginWeight.setPort(conf.getPort());
|
pluginWeight.setProtocol(conf.getProtocol());
|
|
return apiInoutManager.getApiService(param.getProtocol()).getPlateNum(pluginWeight);
|
|
}
|
|
|
return apiInoutManager.getApiService(param.getProtocol()).getPlateNum(param);
|
}
|
|
public ApiInoutData getIcCardNum(ApiInoutData param) {
|
|
return apiInoutManager.getApiService(param.getProtocol()).getIcCardNum(param);
|
}
|
|
/**
|
* 获取称重插件配置信息
|
*
|
* @param companyId
|
* @param deptId
|
* @param sort
|
* @param type
|
* @return
|
*/
|
public InoutConf getInoutConf(String companyId, String deptId, String sort, String type) {
|
|
// 获取出入库配置信息
|
List<InoutConf> listInoutConf = inoutCommonService.getCacheInoutConf(companyId, deptId);
|
|
if (null == listInoutConf) return null;
|
|
InoutConf result = null;
|
|
for (InoutConf conf : listInoutConf) {
|
if (sort.equals(conf.getSort()) && type.equals(conf.getType())) {
|
result = conf;
|
break;
|
}
|
}
|
|
if (null == result) return null;
|
|
return result;
|
}
|
|
|
/**
|
* 初始化车牌识别
|
*
|
* @param conf
|
*/
|
public void initLpr(InoutConf conf) {
|
|
if (null == conf) return;
|
|
ApiInoutData lprData = new ApiInoutData(conf);
|
|
apiInoutManager.getApiService(conf.getProtocol()).initLpr(lprData);
|
}
|
|
|
/**
|
* @param param
|
* @return
|
*/
|
public String noticeWeightDone(ApiInoutData param) {
|
//获取称重主控器配置
|
InoutConf conf = getWeightGateway(param.getCompanyId(), param.getDeptId(), param.getSort());
|
|
if (null == conf) {
|
return "称重主控未配置,支持失败";
|
}
|
|
ApiInoutData apiData = new ApiInoutData(conf);
|
apiData.setPlateNum(param.getPlateNum());
|
apiData.setTime(new Date());
|
|
ApiInoutService inoutApiService = apiInoutManager.getApiService(conf.getProtocol());
|
|
// return inoutApiService.noticeWeightDone(apiData); TODO
|
return null;
|
}
|
|
/**
|
* 出入库抓拍
|
*
|
* @param param
|
* @return
|
*/
|
public SnapImgDto snapImg(SnapImgDto param) {
|
try {
|
InoutConf conf;
|
|
//登记时候抓拍
|
if (InoutConstant.PROGRESS_REGISTER.equals(param.getProgress())) {
|
this.noticeGatewayAddWhitePlate(param);
|
}
|
|
//点击称重完成
|
if (InoutConstant.PROGRESS_WEIGHT_TAG.equals(param.getProgress())
|
|| InoutConstant.PROGRESS_WEIGHT_FULL.equals(param.getProgress()) ||
|
InoutConstant.PROGRESS_WEIGHT_EMPTY.equals(param.getProgress())) {
|
|
this.noticeGatewayWeightInfo(param);
|
}
|
|
SnapSer ser = snapSerService.getCacheByDeptId(param.getDeptId());
|
|
if (StringUtils.isNotEmpty(param.getId1())) {
|
conf = inoutCommonService.getCacheInoutConf(param.getCompanyId(), param.getDeptId(), param.getId1());
|
param.setFileName1(this.snapImgByConf(conf, param, ser));
|
Thread.sleep(600);
|
}
|
|
if (StringUtils.isNotEmpty(param.getId2())) {
|
conf = inoutCommonService.getCacheInoutConf(param.getCompanyId(), param.getDeptId(), param.getId2());
|
param.setFileName2(this.snapImgByConf(conf, param, ser));
|
Thread.sleep(600);
|
}
|
|
if (StringUtils.isNotEmpty(param.getId3())) {
|
conf = inoutCommonService.getCacheInoutConf(param.getCompanyId(), param.getDeptId(), param.getId3());
|
param.setFileName3(this.snapImgByConf(conf, param, ser));
|
}
|
} catch (Exception e) {
|
log.error("---------------------出入库抓拍出现异常--------------------{}", e);
|
}
|
|
return param;
|
}
|
|
/**
|
* 通知主控器-通知称重信息和称重完成信息
|
*
|
* @param snapImgDto
|
*/
|
private void noticeGatewayWeightInfo(SnapImgDto snapImgDto) {
|
|
log.debug("-------------用户确认称重----通知称重网关----{}", snapImgDto.getWeight());
|
InoutConf conf = this.getWeightGateway(snapImgDto.getCompanyId(), snapImgDto.getDeptId(), snapImgDto.getSort());
|
|
if (null == conf) {
|
log.info("-------------用户确认称重----通知称重网关---未配置网关----");
|
return;
|
}
|
|
ApiInoutData apiData = new ApiInoutData(conf);
|
apiData.setTime(new Date());
|
apiData.setRepeat(2);
|
apiData.setWeight(snapImgDto.getWeight());
|
apiData.setPlateNum(snapImgDto.getPlateNum());
|
//称重信息暂时取消播放
|
// apiData.setMsg("当前称重:" + apiData.getWeight() + "千克");
|
apiData.setMsg("称重已完成");
|
|
// apiInoutManager.getApiService(apiData.getProtocol()).noticeWeightDone(apiData);
|
apiInoutManager.getApiService(apiData.getProtocol()).noticeRadio(apiData);
|
}
|
|
/**
|
* 新增白名单给住控制器,需要注意的是,登记时候不确认使用哪个地磅系统,如果系统配置多个主控器,需要同步全部推送
|
*
|
* @param imgDto
|
*/
|
private void noticeGatewayAddWhitePlate(SnapImgDto imgDto) {
|
|
List<InoutConf> list = this.getWeightGateway(imgDto.getCompanyId(), imgDto.getDeptId());
|
|
if (null == list || list.isEmpty()) {
|
log.info("-------------称重网关增加白名单----没有获取到网关配置-----取消执行---");
|
return;
|
}
|
|
log.debug("-------------登记完成,增加车牌白名单-----------{}", imgDto.getPlateNum());
|
|
ApiInoutService inoutApiService = apiInoutManager.getApiService(list.get(0).getProtocol());
|
|
ApiInoutData apiData;
|
for (InoutConf conf : list) {
|
apiData = new ApiInoutData(conf);
|
apiData.setPlateNum(imgDto.getPlateNum());
|
// inoutApiService.addWhitePlate(apiData);
|
}
|
}
|
|
public void noticeProgressComplete(InoutData data) {
|
log.debug("-----------------通知称重主控--------流程结束删除白名单");
|
List<InoutConf> list = this.getWeightGateway(data.getCompanyId(), data.getDeptId());
|
|
if (null == list || list.isEmpty()) {
|
return;
|
}
|
|
ApiInoutService inoutApiService = apiInoutManager.getApiService(list.get(0).getProtocol());
|
|
ApiInoutData apiData;
|
for (InoutConf conf : list) {
|
apiData = new ApiInoutData(conf);
|
apiData.setPlateNum(data.getPlateNum());
|
|
// inoutApiService.delWhitePlate(apiData); TODO
|
}
|
}
|
|
/**
|
* 调用接口进行抓拍
|
*
|
* @param conf
|
* @param param
|
* @param snapSer
|
* @return
|
*/
|
private String snapImgByConf(InoutConf conf, SnapImgDto param, SnapSer snapSer) {
|
if (null == conf) return null;
|
|
if (null == conf.getSnapType()) {
|
log.error("-----------抓拍执行失败:没有配置抓拍方式-----{}", conf.getName());
|
return null;
|
}
|
|
ApiSnapReq req = new ApiSnapReq();
|
req.setCompanyId(conf.getCompanyId());
|
req.setDeptId(conf.getDeptId());
|
req.setSn(conf.getSn());
|
req.setSnapType(conf.getSnapType());
|
req.setPlayType(conf.getPlayType());
|
req.setSerSn(null == snapSer ? null : snapSer.getSn());
|
req.setBizId(param.getBizId());
|
req.setCameraName(conf.getName());
|
|
req.setMediaAddr(CameraUtil.updateMediaAddr(conf.getMediaAddr(), conf.getLoginId(),
|
conf.getPwd(), conf.getIp(), conf.getPortCtrl(), conf.getChanNum()));
|
|
String filePath = fileService.getInoutFilePath(new Date());
|
|
req.setFilePath(filePath);
|
|
//调整附件名称,避免出现中文
|
String fileName = ContextUtil.getTimeId(100) + "_" + conf.getInoutProgress() + ".jpg";
|
req.setFileName(fileName);
|
|
//执行抓拍
|
ApiCameraResp resp = apiCameraManager.getApiCameraService(conf.getPlayType()).snapImg(req);
|
|
if (ApiCameraResp.CODE_ERROR.equals(resp.getCode())) {
|
log.error("---------抓拍执行失败:{}-----{}", resp.getMsg(), conf.getName());
|
|
return null;
|
}
|
|
return fileName;
|
}
|
|
|
/**
|
* 出入库视频 -- 根据播放方式获取不同的播放地址
|
*
|
* @param param
|
* @return
|
*/
|
public InoutCameraDto inoutVideoPlay(InoutCameraDto param) {
|
|
//没有配置播放方式
|
if (StringUtils.isEmpty(param.getPlayType())) {
|
param.setErrorMsg("没有配置播放方式,无法播放!");
|
return param;
|
}
|
|
if (StringUtils.isEmpty(param.getCompanyId())) {
|
param.setCompanyId(ContextUtil.getCompanyId());
|
}
|
|
//通过接口获取播放地址
|
ApiCameraData apiCameraData = new ApiCameraData();
|
apiCameraData.setCompanyId(param.getCompanyId());
|
apiCameraData.setSn(param.getSn());
|
apiCameraData.setCameraId(param.getId());
|
apiCameraData.setPlayType(param.getPlayType());
|
apiCameraData.setMediaAddr(CameraUtil.updateMediaAddr(param.getMediaAddr(),
|
param.getLoginId(), param.getPwd(), param.getIp(), param.getPortCtrl(), param.getChanNum()));
|
|
ApiCameraResp result = apiCameraManager.getApiCameraService(param.getPlayType()).getPlayAddr(apiCameraData);
|
|
if (null == result) {
|
return param;
|
}
|
|
if (ApiCameraResp.CODE_SUCCESS.equals(result.getCode())) {
|
param.setPlayAddr(result.getPlayAddr());
|
}
|
if (ApiCameraResp.CODE_ERROR.equals(result.getCode())) {
|
param.setErrorMsg(result.getMsg());
|
}
|
return param;
|
}
|
|
public String videoKeepLive(InoutCameraDto param) {
|
|
ApiCameraData apiCameraData = new ApiCameraData();
|
apiCameraData.setSn(param.getSn());
|
apiCameraData.setCameraId(param.getId());
|
apiCameraData.setPlayType(param.getPlayType());
|
|
apiCameraManager.getApiCameraService(param.getPlayType()).keepAlive(apiCameraData);
|
|
return null;
|
}
|
|
|
/**
|
* 根据id获取出入库设备信息
|
*
|
* @param id
|
* @return
|
*/
|
public InoutConf getInoutConf(String id) {
|
//没有配置播放方式
|
if (StringUtils.isEmpty(id)) {
|
return null;
|
}
|
return inoutCommonService.getCacheInoutConf(ContextUtil.getCompanyId(), ContextUtil.subDeptId(null), id);
|
}
|
|
|
/**
|
* @Desc: 获取称重网关设备
|
* @author: Andy
|
* @update-time: 2022/11/26
|
*/
|
public List<InoutConf> getWeightGateway(String companyId, String deptId) {
|
List<InoutConf> list = inoutCommonService.getCacheInoutConf(companyId, deptId);
|
if (null == list || list.isEmpty()) return null;
|
|
List<InoutConf> result = new ArrayList<>();
|
|
for (InoutConf conf : list) {
|
if (InoutConstant.CONF_TYPE_70.equals(conf.getType())) {
|
result.add(conf);
|
}
|
}
|
return result;
|
}
|
|
/**
|
* @Desc: 获取称重网关设备
|
* @author: Andy
|
* @update-time: 2022/11/26
|
*/
|
public InoutConf getWeightGateway(String companyId, String deptId, String sort) {
|
if (null == sort) sort = "1";
|
List<InoutConf> list = inoutCommonService.getCacheInoutConf(companyId, deptId);
|
if (null == list || list.isEmpty()) return null;
|
|
for (InoutConf conf : list) {
|
if (InoutConstant.CONF_TYPE_70.equals(conf.getType()) && sort.equals(conf.getSort())) {
|
return conf;
|
}
|
}
|
return null;
|
}
|
|
|
/**
|
* 根据出入库信息,控制出入库控制器
|
*
|
* @param data
|
* @param curProgress
|
* @param nextProgress
|
*/
|
public void controlWeight(InoutData data, String curProgress, String nextProgress) {
|
|
//TODO
|
|
}
|
}
|