package com.ld.igds.protocol.quantity.shuhan;
|
|
import com.ld.igds.camera.CameraUtil;
|
import com.ld.igds.camera.data.ApiSnapReq;
|
import com.ld.igds.constant.BizType;
|
import com.ld.igds.constant.RedisConst;
|
import com.ld.igds.io.request.QuantityRequest;
|
import com.ld.igds.models.QuantityConf;
|
import com.ld.igds.models.SnapSer;
|
import com.ld.igds.protocol.quantity.shuhan.command.BaseRemoteImpl;
|
import com.ld.igds.protocol.quantity.shuhan.command.RemoteQuantityServiceImpl;
|
import com.ld.igds.protocol.snap.SnapPluginService;
|
import com.ld.igds.quantity.service.CoreQuantityService;
|
import com.ld.igds.util.DateUtil;
|
import com.ld.igds.util.RedisUtil;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.time.DateUtils;
|
|
import java.util.Date;
|
import java.util.concurrent.Callable;
|
|
/**
|
*
|
* @author andy.jia
|
*/
|
@Slf4j
|
public class QueryStatusTask extends BaseRemoteImpl implements Callable<String> {
|
|
|
private RedisUtil redisUtil;
|
|
private CoreQuantityService coreQuantityService;
|
|
private String redisKey;
|
|
private String queryMsg;
|
|
private RemoteQuantityServiceImpl remoteQuantityService;
|
|
private SnapPluginService snapService;
|
|
public QueryStatusTask() {
|
super();
|
}
|
|
public QueryStatusTask(RedisUtil redisUtil, RemoteQuantityServiceImpl remoteQuantityService, CoreQuantityService coreQuantityService, SnapPluginService snapService, String redisKey, String queryMsg) {
|
super();
|
this.redisUtil = redisUtil;
|
this.coreQuantityService = coreQuantityService;
|
this.remoteQuantityService = remoteQuantityService;
|
this.snapService = snapService;
|
this.redisKey = redisKey;
|
this.queryMsg = queryMsg;
|
}
|
|
@Override
|
public String call() throws Exception {
|
//记录抓拍次数
|
int num = 1;
|
//记录抓拍时间间隔
|
Date lastTime = new Date();
|
Date curTime = null;
|
|
boolean flag = true;
|
QuantityConf conf = null;
|
while (flag){
|
Thread.sleep(1000 * 60 * 2 );
|
//发起状态查询命令
|
try{
|
QuantityRequest res = (QuantityRequest) redisUtil.get(redisKey);
|
if(res != null ){
|
conf = coreQuantityService.getCacheQuantityConf(res.getCompanyId(),res.getDepotId());
|
if(conf == null )return "子流程结束,没有获取到分机。";
|
log.info("发送数量检测查询命令:" + res.toString());
|
remoteQuantityService.send(conf.getIp(),conf.getPort(),queryMsg.getBytes(ShuHanUtils.CHARSET));
|
|
//调用抓拍
|
if(num <= 3){
|
curTime = new Date();
|
if(DateUtil.difMin(lastTime, curTime) >= 4){
|
lastTime = curTime;
|
num ++;
|
this.snapImg(conf, res.getBatchId());
|
}
|
}
|
}else{
|
flag = false;
|
log.info("检测流程结束,子线程关闭!");
|
}
|
}catch (Exception e){
|
log.error("子线程查询进度出现异常。");
|
log.error(e.getMessage(),e);
|
}
|
|
}
|
return "子任务执行完成,数量结果应该已经正确解析。 ";
|
}
|
|
/**
|
* 调用抓拍
|
* @param conf
|
* @return
|
*/
|
private String snapImg(QuantityConf conf, String batchId) {
|
if(null == conf){
|
log.error("---配置参数为空,不抓拍---");
|
return null;
|
}
|
if(StringUtils.isEmpty(conf.getDeptId()) || StringUtils.isEmpty(conf.getDepotId()) || StringUtils.isEmpty(conf.getMediaAddr())){
|
log.error("---配置参数为空,不抓拍---,{}", conf);
|
return null;
|
}
|
|
if(StringUtils.isEmpty(batchId)){
|
log.error("---未获取到批次号,不抓拍---");
|
return null;
|
}
|
|
String mediaAddr = CameraUtil.updateMediaAddr(conf.getMediaAddr(), conf.getLoginId(),
|
conf.getPwd(), conf.getYtIp(), conf.getYtPort(), 1);
|
|
ApiSnapReq req = new ApiSnapReq();
|
req.setCompanyId(conf.getCompanyId());
|
req.setDeptId(conf.getDeptId());
|
req.setMediaAddr(mediaAddr);
|
req.setBizId(batchId);
|
req.setCameraName(BizType.QUANTITY.getCode());
|
snapService.snapImg(req);
|
return null;
|
}
|
}
|