package com.ld.igds.quantity.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.common.CoreCommonService;
|
import com.ld.igds.constant.RespCodeEnum;
|
import com.ld.igds.data.PageResponse;
|
import com.ld.igds.file.CoreFileService;
|
import com.ld.igds.file.dto.FileData;
|
import com.ld.igds.io.constant.OrderRespEnum;
|
import com.ld.igds.io.request.QuantityRequest;
|
import com.ld.igds.io.response.BaseResponse;
|
import com.ld.igds.models.Depot;
|
import com.ld.igds.models.QuantityConf;
|
import com.ld.igds.quantity.dto.QuantityConfDto;
|
import com.ld.igds.quantity.dto.QuantityData;
|
import com.ld.igds.quantity.dto.QuantityParam;
|
import com.ld.igds.quantity.io.QuantityRemoteManager;
|
import com.ld.igds.quantity.io.RemoteQuantityService;
|
import com.ld.igds.quantity.service.CoreQuantityService;
|
import com.ld.igds.util.ContextUtil;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import java.io.File;
|
import java.util.List;
|
|
/**
|
* 逻辑管理,用于实现控制层的逻辑
|
*/
|
@Component
|
public class QuantityManager {
|
|
@Autowired
|
private CoreCommonService coreCommonService;
|
@Autowired
|
private CoreQuantityService coreQuantityService;
|
|
@Autowired
|
private QuantityRemoteManager remoteManager;
|
@Autowired
|
private ApiCameraManager apiCameraManager;
|
|
@Autowired
|
private CoreFileService fileService;
|
|
/**
|
* 保存数据
|
*
|
* @param data
|
*/
|
@SuppressWarnings("rawtypes")
|
public PageResponse saveData(QuantityData data) {
|
coreQuantityService.saveData(data);
|
return new PageResponse<>(RespCodeEnum.CODE_0000, null);
|
}
|
|
/**
|
* 根据仓库编号获取最新一条数据
|
*
|
* @param param
|
* @return
|
*/
|
public PageResponse<QuantityData> getLastData(QuantityParam param) {
|
|
if (StringUtils.isEmpty(param.getDepotId())) {
|
return new PageResponse<>(RespCodeEnum.CODE_1007.getCode(), "仓库编号为空!");
|
}
|
|
if (StringUtils.isEmpty(param.getCompanyId())) {
|
param.setCompanyId(ContextUtil.getCompanyId());
|
}
|
|
Depot depot = coreCommonService.getCacheDepot(param.getCompanyId(), param.getDepotId());
|
if (depot == null) {
|
return new PageResponse<>(RespCodeEnum.CODE_1007.getCode(), "没有获取到当前仓库信息");
|
}
|
|
QuantityData quantityData = coreQuantityService.getLastData(param);
|
if (quantityData == null) {
|
quantityData = new QuantityData();
|
}
|
quantityData.setDepotData(depot);
|
|
return new PageResponse<>(RespCodeEnum.CODE_0000, quantityData);
|
}
|
|
|
/**
|
* 单仓检测
|
*
|
* @param param
|
* @return
|
*/
|
public BaseResponse checkSingle(QuantityParam param) {
|
if (param == null || StringUtils.isEmpty(param.getDepotId())) {
|
return new BaseResponse(RespCodeEnum.CODE_1007.getCode(), RespCodeEnum.CODE_1007.getMsg());
|
}
|
|
if (StringUtils.isEmpty(param.getCompanyId())) {
|
param.setCompanyId(ContextUtil.getCompanyId());
|
}
|
|
QuantityConf conf = coreQuantityService.getCacheQuantityConf(param.getCompanyId(), param.getDepotId());
|
if (conf == null) {
|
return new BaseResponse(RespCodeEnum.CODE_1007.getCode(), RespCodeEnum.CODE_1007.getMsg());
|
}
|
|
Depot depot = coreCommonService.getCacheDepot(param.getCompanyId(), conf.getDepotId());
|
|
if (depot.getBulkWeight() == null || depot.getBulkWeight() <= 0) {
|
return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(),
|
"当前仓库没有配置容重,取消检测!");
|
}
|
|
RemoteQuantityService remoteQuantityService = remoteManager.getRemoteQuantityService(conf.getProtocol());
|
|
if (null == remoteQuantityService) {
|
return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(),
|
"系统没有" + conf.getProtocol() + "的协议实现,执行被拒绝!");
|
}
|
|
QuantityRequest request = new QuantityRequest();
|
BeanUtils.copyProperties(conf, request);
|
request.setDensity(depot.getBulkWeight());
|
request.setDepotId(conf.getDepotId());
|
request.setYtIp(conf.getYtIp());
|
request.setIp(conf.getIp());
|
request.setPort(conf.getPort());
|
request.setCompanyId(conf.getCompanyId());
|
request.setDeptId(conf.getDeptId());
|
request.setDepotType(depot.getDepotType());
|
request.setSn(conf.getSn());
|
request.setLength(conf.getLength());
|
|
request.setBatchId(ContextUtil.getDefaultBatchId());
|
|
return remoteQuantityService.checkStart(request);
|
}
|
|
public BaseResponse remoteConf(QuantityConf conf) {
|
|
Depot depot = coreCommonService.getCacheDepot(conf.getCompanyId(), conf.getDepotId());
|
|
if (depot.getBulkWeight() == null || depot.getBulkWeight() <= 0) {
|
return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(),
|
"当前仓库没有配置容重,取消检测!");
|
}
|
|
RemoteQuantityService remoteQuantityService = remoteManager.getRemoteQuantityService(conf.getProtocol());
|
|
if (null == remoteQuantityService) {
|
return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(),
|
"系统没有" + conf.getProtocol() + "的协议实现,执行被拒绝!");
|
}
|
|
|
QuantityRequest request = new QuantityRequest();
|
BeanUtils.copyProperties(conf, request);
|
request.setDensity(depot.getBulkWeight());
|
request.setDepotId(conf.getDepotId());
|
request.setIp(conf.getIp());
|
request.setPort(conf.getPort());
|
request.setCompanyId(conf.getCompanyId());
|
request.setDeptId(conf.getDeptId());
|
request.setDepotType(depot.getDepotType());
|
request.setSn(conf.getSn());
|
request.setLength(conf.getLength());
|
|
return remoteQuantityService.remoteConf(request);
|
}
|
|
|
public BaseResponse closeWarn(QuantityParam param) {
|
if (param == null || StringUtils.isEmpty(param.getDepotId())) {
|
return new BaseResponse(RespCodeEnum.CODE_1007.getCode(), RespCodeEnum.CODE_1007.getMsg());
|
}
|
|
if (StringUtils.isEmpty(param.getCompanyId())) {
|
param.setCompanyId(ContextUtil.getCompanyId());
|
}
|
|
QuantityConf conf = coreQuantityService.getCacheQuantityConf(param.getCompanyId(), param.getDepotId());
|
if (conf == null) {
|
return new BaseResponse(RespCodeEnum.CODE_1007.getCode(), RespCodeEnum.CODE_1007.getMsg());
|
}
|
|
RemoteQuantityService remoteQuantityService = remoteManager.getRemoteQuantityService(conf.getProtocol());
|
|
if (null == remoteQuantityService) {
|
return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(),
|
"系统没有" + conf.getProtocol() + "的协议实现,执行被拒绝!");
|
}
|
|
QuantityRequest request = new QuantityRequest();
|
request.setCompanyId(conf.getCompanyId());
|
request.setIp(conf.getIp());
|
request.setPort(conf.getPort());
|
request.setSn(conf.getSn());
|
request.setDeptId(conf.getDeptId());
|
request.setDepotId(conf.getDepotId());
|
|
return remoteQuantityService.closeWarn(request);
|
}
|
|
public BaseResponse checkStop(QuantityParam param) {
|
if (param == null || StringUtils.isEmpty(param.getDepotId())) {
|
return new BaseResponse(RespCodeEnum.CODE_1007.getCode(), RespCodeEnum.CODE_1007.getMsg());
|
}
|
|
if (StringUtils.isEmpty(param.getCompanyId())) {
|
param.setCompanyId(ContextUtil.getCompanyId());
|
}
|
|
QuantityConf conf = coreQuantityService.getCacheQuantityConf(param.getCompanyId(), param.getDepotId());
|
if (conf == null) {
|
return new BaseResponse(RespCodeEnum.CODE_1007.getCode(), RespCodeEnum.CODE_1007.getMsg());
|
}
|
|
RemoteQuantityService remoteQuantityService = remoteManager.getRemoteQuantityService(conf.getProtocol());
|
|
if (null == remoteQuantityService) {
|
return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(),
|
"系统没有" + conf.getProtocol() + "的协议实现,执行被拒绝!");
|
}
|
|
QuantityRequest request = new QuantityRequest();
|
request.setCompanyId(conf.getCompanyId());
|
request.setIp(conf.getIp());
|
request.setPort(conf.getPort());
|
request.setSn(conf.getSn());
|
request.setDeptId(conf.getDeptId());
|
request.setDepotId(conf.getDepotId());
|
|
return remoteQuantityService.checkStop(request);
|
}
|
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
public PageResponse<QuantityConfDto> quantityCamera(@RequestBody QuantityParam param) {
|
if (param == null) {
|
return new PageResponse(RespCodeEnum.CODE_1007.getCode(), RespCodeEnum.CODE_1007.getMsg());
|
}
|
if (StringUtils.isEmpty(param.getDepotId())) {
|
return new PageResponse(RespCodeEnum.CODE_1007.getCode(), RespCodeEnum.CODE_1007.getMsg());
|
}
|
if (StringUtils.isEmpty(param.getCompanyId())) {
|
param.setCompanyId(ContextUtil.getCompanyId());
|
}
|
QuantityConf conf = coreQuantityService.getCacheQuantityConf(param.getCompanyId(), param.getDepotId());
|
if (conf == null) {
|
return new PageResponse(RespCodeEnum.CODE_1007.getCode(), RespCodeEnum.CODE_1007.getMsg());
|
}
|
|
QuantityConfDto quantityConfDto = new QuantityConfDto();
|
BeanUtils.copyProperties(conf, quantityConfDto);
|
|
//判断播放方式,如果为vlc则直接返回
|
if (CameraUtil.PLAY_TYPE_VLC.equals(conf.getPlayType())) {
|
//更新列媒体地址
|
String mediaAddr = CameraUtil.updateMediaAddr(quantityConfDto.getMediaAddr(), quantityConfDto.getLoginId(),
|
quantityConfDto.getPwd(), quantityConfDto.getIp(), quantityConfDto.getPortCtrl(), 1);
|
quantityConfDto.setMediaAddr(mediaAddr);
|
|
return new PageResponse<QuantityConfDto>(RespCodeEnum.CODE_0000, quantityConfDto);
|
}
|
|
quantityConfDto = updateMediaInfo(quantityConfDto);
|
if (StringUtils.isNotEmpty(quantityConfDto.getMsg())) {
|
return new PageResponse(RespCodeEnum.CODE_1007.getCode(), "获取播放地址失败!");
|
}
|
|
return new PageResponse<QuantityConfDto>(RespCodeEnum.CODE_0000, quantityConfDto);
|
}
|
|
|
public QuantityConfDto updateMediaInfo(QuantityConfDto conf) {
|
if (StringUtils.isEmpty(conf.getCameraSn())
|
&& StringUtils.isEmpty(conf.getIp())) {
|
conf.setMsg("没有获取到当前摄像机IP/SN,不支持云台控制");
|
return conf;
|
}
|
|
//通过接口获取播放地址
|
ApiCameraData apiCameraData = new ApiCameraData();
|
apiCameraData.setCompanyId(conf.getCompanyId());
|
apiCameraData.setSn(conf.getSn());
|
apiCameraData.setPlayType(conf.getPlayType());
|
apiCameraData.setMediaAddr(CameraUtil.updateMediaAddr(conf.getMediaAddr(), conf.getLoginId(), conf.getPwd(), conf.getIp(), conf.getPortCtrl(), conf.getChanNum()));
|
ApiCameraResp result = apiCameraManager.getApiCameraService(conf.getPlayType()).getPlayAddr(apiCameraData);
|
|
if (null != result && ApiCameraResp.CODE_SUCCESS.equals(result.getCode())) {
|
conf.setPlayAddr(result.getPlayAddr());
|
}
|
|
return conf;
|
}
|
|
/**
|
* 获取图片列表
|
*
|
* @param param
|
* @return
|
*/
|
public PageResponse<List<FileData>> listSnapImg(QuantityParam param) {
|
|
if (null == param) {
|
return new PageResponse<>(RespCodeEnum.CODE_1007.getCode(), "参数异常!");
|
}
|
|
if (StringUtils.isEmpty(param.getCompanyId())) {
|
param.setCompanyId(ContextUtil.getCompanyId());
|
}
|
|
List<FileData> list = fileService.listFile(ContextUtil.getCompanyId(), param.getBatchId());
|
if (null == list || list.isEmpty()) {
|
return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(), "响应数据为空!");
|
}
|
String bathPath;
|
File imgFile;
|
for (FileData dto : list) {
|
if (StringUtils.isNotEmpty(dto.getFileName())) {
|
bathPath = fileService.getCommonFilePath(dto.getCreateTime());
|
imgFile = new File(bathPath + dto.getFileName());
|
if (imgFile.exists()) {
|
dto.setFilePath(bathPath + dto.getFileName());
|
}
|
}
|
}
|
return new PageResponse<>(RespCodeEnum.CODE_0000, list);
|
}
|
|
|
/**
|
* 根据仓库编码获取最近的5条检测记录信息
|
*
|
* @param param
|
* @return
|
*/
|
public PageResponse<List<QuantityData>> getRecordData(QuantityParam param) {
|
if (StringUtils.isEmpty(param.getDepotId())) {
|
return new PageResponse<>(RespCodeEnum.CODE_1007.getCode(), "仓库编号为空!");
|
}
|
|
if (StringUtils.isEmpty(param.getCompanyId())) {
|
param.setCompanyId(ContextUtil.getCompanyId());
|
}
|
//指定获取5条
|
param.setLimit(5);
|
List<QuantityData> list = coreQuantityService.getDataByLimit(param);
|
if (null == list || list.isEmpty()) {
|
return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(), "获取数据为空!");
|
}
|
return new PageResponse<>(RespCodeEnum.CODE_0000, list);
|
}
|
}
|