Commit 49ba4c57 authored by 赵建伟's avatar 赵建伟

update codes

parent 6ff8b6a8
......@@ -17,6 +17,11 @@ public class PfrRecentInfo implements java.lang.Comparable<PfrRecentInfo>{
this.lastUpdateTime = lastUpdateTime;
}
public PfrRecentInfo(String pfrName, Integer pfrCount) {
this.pfrName = pfrName;
this.pfrCount = pfrCount;
}
public PfrRecentInfo() {
}
......
......@@ -133,21 +133,21 @@ public class CtrPfrRctMysqlSink extends RichSinkFunction<CtrPfrRctBean> {
LinkedList<PfrRecentInfo> secondPositionsPfrQueue10 = getNewQueue(pfrRecent10QueueBean.getSecondPositionsPfrQueue(),secondPositionsPfr,timeStr,10);
LinkedList<PfrRecentInfo> secondSolutionsPfrQueue10 = getNewQueue(pfrRecent10QueueBean.getSecondSolutionsPfrQueue(),secondSolutionsPfr,timeStr,10);
String projectPfrRecent3 = StringUtil.transPfrRecentInfoList2String(projectPfrQueue3);
String firstDemandsPfrRecent3 = StringUtil.transPfrRecentInfoList2String(firstDemandsPfrQueue3);
String firstPositionsPfrRecent3 = StringUtil.transPfrRecentInfoList2String(firstPositionsPfrQueue3);
String firstSolutionsPfrRecent3 = StringUtil.transPfrRecentInfoList2String(firstSolutionsPfrQueue3);
String secondDemandsPfrRecent3 = StringUtil.transPfrRecentInfoList2String(secondDemandsPfrQueue3);
String secondPositionsPfrRecent3 = StringUtil.transPfrRecentInfoList2String(secondPositionsPfrQueue3);
String secondSolutionsPfrRecent3 = StringUtil.transPfrRecentInfoList2String(secondSolutionsPfrQueue3);
String projectPfrRecent3 = StringUtil.transPfrRecentInfoList2SplitedPairedString(projectPfrQueue3);
String firstDemandsPfrRecent3 = StringUtil.transPfrRecentInfoList2SplitedPairedString(firstDemandsPfrQueue3);
String firstPositionsPfrRecent3 = StringUtil.transPfrRecentInfoList2SplitedPairedString(firstPositionsPfrQueue3);
String firstSolutionsPfrRecent3 = StringUtil.transPfrRecentInfoList2SplitedPairedString(firstSolutionsPfrQueue3);
String secondDemandsPfrRecent3 = StringUtil.transPfrRecentInfoList2SplitedPairedString(secondDemandsPfrQueue3);
String secondPositionsPfrRecent3 = StringUtil.transPfrRecentInfoList2SplitedPairedString(secondPositionsPfrQueue3);
String secondSolutionsPfrRecent3 = StringUtil.transPfrRecentInfoList2SplitedPairedString(secondSolutionsPfrQueue3);
String projectPfrRecent10 = StringUtil.transPfrRecentInfoList2String(projectPfrQueue10);
String firstDemandsPfrRecent10 = StringUtil.transPfrRecentInfoList2String(firstDemandsPfrQueue10);
String firstPositionsPfrRecent10 = StringUtil.transPfrRecentInfoList2String(firstPositionsPfrQueue10);
String firstSolutionsPfrRecent10 = StringUtil.transPfrRecentInfoList2String(firstSolutionsPfrQueue10);
String secondDemandsPfrRecent10 = StringUtil.transPfrRecentInfoList2String(secondDemandsPfrQueue10);
String secondPositionsPfrRecent10 = StringUtil.transPfrRecentInfoList2String(secondPositionsPfrQueue10);
String secondSolutionsPfrRecent10 = StringUtil.transPfrRecentInfoList2String(secondSolutionsPfrQueue10);
String projectPfrRecent10 = StringUtil.transPfrRecentInfoList2SplitedPairedString(projectPfrQueue10);
String firstDemandsPfrRecent10 = StringUtil.transPfrRecentInfoList2SplitedPairedString(firstDemandsPfrQueue10);
String firstPositionsPfrRecent10 = StringUtil.transPfrRecentInfoList2SplitedPairedString(firstPositionsPfrQueue10);
String firstSolutionsPfrRecent10 = StringUtil.transPfrRecentInfoList2SplitedPairedString(firstSolutionsPfrQueue10);
String secondDemandsPfrRecent10 = StringUtil.transPfrRecentInfoList2SplitedPairedString(secondDemandsPfrQueue10);
String secondPositionsPfrRecent10 = StringUtil.transPfrRecentInfoList2SplitedPairedString(secondPositionsPfrQueue10);
String secondSolutionsPfrRecent10 = StringUtil.transPfrRecentInfoList2SplitedPairedString(secondSolutionsPfrQueue10);
pfrRecent10QueueBean = new PfrRecent10QueueBean(
deviceId,
......@@ -314,20 +314,23 @@ public class CtrPfrRctMysqlSink extends RichSinkFunction<CtrPfrRctBean> {
private LinkedList<PfrRecentInfo> getNewQueue(LinkedList<PfrRecentInfo> oldQueue, String pfrStr, String timeStr, Integer queueSize ){
LinkedList<PfrRecentInfo> newQueue = new LinkedList<>();
Map<String,Integer> pfrMap = StringUtil.transString2Map(pfrStr);
// Map<String,Integer> pfrMap = StringUtil.transString2Map(pfrStr);
for (PfrRecentInfo pfrRecentInfo : oldQueue) {
String sevenDaysAgoTimeStr = DateUtil.getSevenDaysAgoTimeStr(new Date());
String lastUpdateTime = pfrRecentInfo.getLastUpdateTime();
if(DateUtil.getTimestampByDateStr(lastUpdateTime) > DateUtil.getTimestampByDateStr(sevenDaysAgoTimeStr)){
String pfrName = pfrRecentInfo.getPfrName();
Integer pfrCount = pfrRecentInfo.getPfrCount();
if(pfrMap.keySet().contains(pfrName)){
newQueue.add(new PfrRecentInfo(pfrName,pfrCount + 1 ,timeStr));
}else{
newQueue.add(pfrRecentInfo);
}
// String pfrName = pfrRecentInfo.getPfrName();
// Integer pfrCount = pfrRecentInfo.getPfrCount();
newQueue.add(pfrRecentInfo);
// if(pfrMap.keySet().contains(pfrName)){
// newQueue.add(new PfrRecentInfo(pfrName,pfrCount + 1 ,timeStr));
// }else{
// newQueue.add(pfrRecentInfo);
// }
}
}
newQueue.add(new PfrRecentInfo(pfrStr,1 ,timeStr));
while(newQueue.size() > queueSize){
Collections.sort(newQueue);
newQueue.removeLast();
......
......@@ -70,6 +70,35 @@ public class StringUtil {
return str.substring(0,str.length() -1);
}
public static String transPfrRecentInfoList2SplitedPairedString(LinkedList<PfrRecentInfo> list){
LinkedList<PfrRecentInfo> newList = new LinkedList<>();
for (PfrRecentInfo pfrRecentInfo: list) {
String pfrName = pfrRecentInfo.getPfrName();
if(pfrName.contains(",")){
String[] splits = pfrName.split(",");
for(String split : splits){
newList.add(new PfrRecentInfo(split,1));
}
}else{
newList.add(new PfrRecentInfo(pfrName,1));
}
}
Map<String,Integer> map = new HashMap<>();
for (PfrRecentInfo pfrRecentInfo: newList) {
String pfrName = pfrRecentInfo.getPfrName();
if(map.keySet().contains(pfrRecentInfo.getPfrName())){
Integer rs = map.get(pfrName);
map.put(pfrName,pfrRecentInfo.getPfrCount() + rs);
}else{
map.put(pfrName,pfrRecentInfo.getPfrCount());
}
}
return transMap2PairedString(map);
}
public static Map<String,Integer> increaseByKey(Map<String,Integer> oldMap,String str){
Map<String, Integer> stringIntegerMap = transString2Map(str);
for(Map.Entry<String,Integer> entry : oldMap.entrySet()){
......@@ -97,23 +126,29 @@ public class StringUtil {
}
public static void main(String[] args) {
String str = "xx:1,yy:2,zz:3";
String newPfr = "xx,yy,zz";
String s = increasePfr(str, newPfr);
System.out.println(s);
System.out.println(transString2PairedString(newPfr));
JSONArray ja = new JSONArray();
LinkedList<String> list = new LinkedList<String>();
list.add("c");
list.add("b");
list.add("d");
list.add("a");
Collections.sort(list);
list.removeLast();
for (String ss: list) {
System.out.println(ss);
}
// String str = "xx:1,yy:2,zz:3";
// String newPfr = "xx,yy,zz";
// String s = increasePfr(str, newPfr);
// System.out.println(s);
// System.out.println(transString2PairedString(newPfr));
//
// JSONArray ja = new JSONArray();
//
// LinkedList<String> list = new LinkedList<String>();
// list.add("c");
// list.add("b");
// list.add("d");
// list.add("a");
// Collections.sort(list);
// list.removeLast();
// for (String ss: list) {
// System.out.println(ss);
// }
LinkedList<PfrRecentInfo> list = new LinkedList<>();
list.add(new PfrRecentInfo("xx,yy",1));
list.add(new PfrRecentInfo("xx",1));
list.add(new PfrRecentInfo("yy",1));
String rs = transPfrRecentInfoList2SplitedPairedString(list);
System.out.println(rs);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment