Authored by wangshusheng

提交

... ... @@ -2,6 +2,7 @@ package com.yoho.rfid.controller;
import JW.UHF.JWReader;
import com.yoho.rfid.model.RfidClient;
import com.yoho.rfid.model.SkuInfo;
import com.yoho.rfid.model.SkuResult;
import com.yoho.rfid.service.RfidConfig;
import com.yoho.rfid.service.RfidInit;
... ... @@ -47,25 +48,20 @@ public class RfidController {
return new ApiResponse.ApiResponseBuilder().code(200).message("query leave sku").data(null).build();
}
long currentTime = System.currentTimeMillis();
// List<String> skuList = new ArrayList<String>();
// for(Map.Entry<String, Long> entry : skuMap.entrySet()){
// // sku离开时间 >1.5s <30min
// if(System.currentTimeMillis()-entry.getValue() < SocketConstant.SKU_NOTBELONG_TIMEOUT){
// skuList.add(entry.getKey());
// skuNewMap.put()
// }
// }
Iterator<Map.Entry<String, Long>> it = skuMap.entrySet().iterator();
while(it.hasNext()){
Map.Entry<String, Long> skuEntry=it.next();
if(currentTime-skuEntry.getValue() > SocketConstant.SKU_NOTBELONG_TIMEOUT){
it.remove();
List<SkuInfo> skuList = new ArrayList<SkuInfo>();
for(Map.Entry<String, Long> entry : skuMap.entrySet()){
// sku离开时间 >1.5s <30min
if(System.currentTimeMillis()-entry.getValue() < SocketConstant.SKU_NOTBELONG_TIMEOUT){
SkuInfo skuInfo = new SkuInfo();
skuInfo.setSku(entry.getKey());
skuInfo.setTime(entry.getValue());
skuList.add(skuInfo);
}
}
SkuResult skuResult = new SkuResult();
skuResult.setSkuMap(skuMap);
skuResult.setSkuInfo(skuList);
skuResult.setCurrentTime(currentTime);
logger.info("out RfidController.queryLeaveSku. ip is: {}, skuResult is: {}, count is:{}", ip, skuResult, skuMap.size());
//组织返回
return new ApiResponse.ApiResponseBuilder().code(200).message("query leave sku").data(skuResult).build();
... ...
package com.yoho.rfid.model;
import java.util.Map;
public class SkuInfo {
private String sku;
private long time;
public String getSku() {
return sku;
}
public void setSku(String sku) {
this.sku = sku;
}
public long getTime() {
return time;
}
public void setTime(long time) {
this.time = time;
}
@Override
public String toString() {
return "SkuInfo{" +
"sku='" + sku + '\'' +
", time=" + time +
'}';
}
}
... ...
package com.yoho.rfid.model;
import java.util.List;
import java.util.Map;
public class SkuResult {
private Map<String, Long> skuMap;
private List<SkuInfo> skuInfo;
private long currentTime;
public Map<String, Long> getSkuMap() {
return skuMap;
}
public void setSkuMap(Map<String, Long> skuMap) {
this.skuMap = skuMap;
}
public long getCurrentTime() {
return currentTime;
}
... ... @@ -23,11 +16,20 @@ public class SkuResult {
this.currentTime = currentTime;
}
public List<SkuInfo> getSkuInfo() {
return skuInfo;
}
public void setSkuInfo(List<SkuInfo> skuInfo) {
this.skuInfo = skuInfo;
}
@Override
public String toString() {
return "SkuResult{" +
"skuMap=" + skuMap +
"skuInfo=" + skuInfo +
", currentTime=" + currentTime +
'}';
}
}
... ...