package com.shlanbao.tzsc.pms.sys.sourceDataMonitoring.service.impl;
|
|
import com.shlanbao.tzsc.base.model.DataGrid;
|
import com.shlanbao.tzsc.pms.sys.sourceDataMonitoring.beans.RedisBean;
|
import com.shlanbao.tzsc.pms.sys.sourceDataMonitoring.beans.SysSourceDataBean;
|
import com.shlanbao.tzsc.pms.sys.sourceDataMonitoring.beans.SysSourceDateParamBean;
|
import com.shlanbao.tzsc.pms.sys.sourceDataMonitoring.service.MonitoringServiceI;
|
import com.shlanbao.tzsc.utils.tools.RedisUtil;
|
import com.shlanbao.tzsc.utils.tools.StringUtil;
|
import org.springframework.stereotype.Service;
|
import redis.clients.jedis.Jedis;
|
|
import java.util.*;
|
|
@Service
|
public class MonitoringServiceImpl implements MonitoringServiceI {
|
|
/**
|
* 查询源数据信息
|
* @author sunzhen
|
* @create 2019年9月16日下午15:30:05
|
* @param
|
* @throws Exception
|
*/
|
@Override
|
public DataGrid getAllDatas(SysSourceDateParamBean sourceDateParamBean) {
|
//总记录数
|
long total=0;
|
//存放源数据bean的list
|
List<RedisBean> lastRows = new ArrayList<>();
|
RedisBean bean=null;
|
|
Map<String,String> map = RedisUtil.getMap(sourceDateParamBean.getName());
|
Set<String> keys = map.keySet();
|
for(String key : keys){
|
bean = new RedisBean();
|
bean.setKey(key);
|
bean.setValue(map.get(key));
|
lastRows.add(bean);
|
}
|
total=lastRows.size();
|
|
return new DataGrid(lastRows, total);
|
}
|
|
/**
|
* 查询源数据列表信息
|
* @author sunzhen
|
* @create 2019年9月16日下午15:30:05
|
* @param
|
* @throws Exception
|
*/
|
@Override
|
public DataGrid querySourceDateList(SysSourceDateParamBean sourceDateParamBean) {
|
//从Redis中获取所有的key值
|
Set<String> keys = RedisUtil.keys("*");
|
System.out.println(keys);
|
|
//总记录数
|
long total=0;
|
//存放源数据bean的list
|
List<SysSourceDataBean> lastRows = new ArrayList<SysSourceDataBean>();
|
SysSourceDataBean bean = null;
|
|
//遍历所有的key值赋值到bean中并存放到lastRows中去
|
for (String key : keys) {
|
//筛选符合查询条件的key值
|
if(checkEqpType(key,sourceDateParamBean.getEqpType())&&key.contains(sourceDateParamBean.getName())){
|
bean = new SysSourceDataBean();
|
bean.setName(key);
|
bean.setDes(codeParsing(key));
|
lastRows.add(bean);
|
}
|
}
|
total=lastRows.size();
|
|
return new DataGrid(lastRows, total);
|
}
|
|
/**
|
* 将key值的解释从符号转换成中文
|
* @param key
|
* @return
|
*/
|
private String codeParsing(String key) {
|
/*
|
目前有以下几种种类:
|
-----------4位数字-------------
|
1. 1101
|
2101
|
1401
|
-----------4位数字+1个字母-------------
|
2. 1102C
|
3. 1102J
|
4. 1102M
|
5. 1202G
|
6. 1401F
|
7. 1401Z
|
8. 1502X
|
-----------3位数字+2个字母-------------
|
9. 101CC
|
102CC
|
-----------其他-------------
|
10. converted-preview-pdf-file
|
11. converted-preview-pdfimgs-file
|
12. outputInput
|
13. shift
|
14. workorder
|
15. \xAC\xED\x00\x05t\x00\x04123M
|
|
*/
|
String des="";
|
switch(key.length()){
|
case 4:
|
|
switch(key.substring(0,1)){
|
case "1":
|
des+="早班"+key.substring(2,4)+"号";
|
des = parseEqpName(key, des, 1, 2);
|
return des;
|
case "2":
|
des+="中班"+key.substring(2,4)+"号";
|
des = parseEqpName(key, des, 1, 2);
|
return des;
|
case "3":
|
des+="晚班"+key.substring(2,4)+"号";
|
des = parseEqpName(key, des, 1, 2);
|
return des;
|
}
|
|
break;
|
case 5:
|
|
if(key.endsWith("CC")){ //先对以CC结尾的key进行筛选,因为下面有以C结尾的情况
|
|
des+=key.substring(1,3)+"号";
|
des = parseEqpName(key, des, 0, 1);
|
des+="辅料转换系数";
|
return des;
|
|
}else{ //这里shift会进来,但下面会筛选掉
|
String str = key.substring(4, 5);
|
if(str.equals("C")|| str.equals("J")|| str.equals("M")
|
|| str.equals("Z")|| str.equals("F")|| str.equals("G")||
|
str.equals("X")){
|
|
switch(key.substring(0,1)){
|
case "1":
|
des+="早班"+key.substring(2,4)+"号";
|
des = parseEqpName(key, des, 1, 2);
|
des+= str;
|
return des;
|
case "2":
|
des+="中班"+key.substring(2,4)+"号";
|
des = parseEqpName(key, des, 1, 2);
|
des+= str;
|
return des;
|
case "3":
|
des+="晚班"+key.substring(2,4)+"号";
|
des = parseEqpName(key, des, 1, 2);
|
des+= str;
|
return des;
|
}
|
}
|
}
|
|
break;
|
default:
|
return "暂无信息";
|
}
|
|
return "暂无信息";
|
}
|
|
private String parseEqpName(String key, String des, int start, int end) {
|
switch(key.substring(start,end)){
|
case "1":
|
des+="卷烟机组";
|
break;
|
case "2":
|
des+="包装机组";
|
break;
|
case "3":
|
des+="装箱机组";
|
break;
|
case "4":
|
des+="成型机组";
|
break;
|
case "5":
|
des+="发射机组";
|
break;
|
case "6":
|
des+="提升机组";
|
break;
|
}
|
return des;
|
}
|
|
/**
|
* 检查key值是否属于eqpType的机器类型
|
* @param key key值为被检查的值
|
* @param eqpType 机器类型为匹配的条件
|
* @return
|
*/
|
public boolean checkEqpType(String key,String eqpType){
|
/*
|
目前有以下几种种类:
|
-----------4位数字-------------
|
1. 1101
|
2101
|
1401
|
-----------4位数字+1个字母-------------
|
2. 1102C
|
3. 1102J
|
4. 1102M
|
5. 1202G
|
6. 1401F
|
7. 1401Z
|
8. 1502X
|
-----------3位数字+2个字母-------------
|
9. 101CC
|
102CC
|
-----------其他-------------
|
10. converted-preview-pdf-file
|
11. converted-preview-pdfimgs-file
|
12. outputInput
|
13. shift
|
14. workorder
|
15. \xAC\xED\x00\x05t\x00\x04123M
|
|
*/
|
|
// 当机器类型为空时则满足所有任何条件,返回true
|
if(!StringUtil.notNull(eqpType)){
|
return true;
|
}
|
|
//1. 首先根据机器类别筛选,分为六种类型:卷烟机、包装机、装封箱机、发射机、成型机、提升机
|
//2. 然后根据key值的长度进行筛选,分为两种情况:key值长度=4、key值长度=5
|
//3. 当key值长度=5时还分两种情况:以CC结尾的、不以CC结尾的
|
//4. 最后根据不同的情况,用key值中的某一位与代表机器类型的值进行匹配
|
switch(eqpType){
|
case "卷烟机":
|
|
switch (key.length()){
|
case 4:
|
if(key.charAt(1)=='1') return true;
|
case 5:
|
if(key.endsWith("CC")){
|
if(key.charAt(0)=='1') return true;
|
}else{
|
if(key.charAt(1)=='1') return true;
|
}
|
}
|
|
return false;
|
case "包装机":
|
|
switch (key.length()){
|
case 4:
|
if(key.charAt(1)=='2') return true;
|
case 5:
|
if(key.endsWith("CC")){
|
if(key.charAt(0)=='2') return true;
|
}else{
|
if(key.charAt(1)=='2') return true;
|
}
|
}
|
|
return false;
|
case "装封箱机":
|
|
switch (key.length()){
|
case 4:
|
if(key.charAt(1)=='3') return true;
|
case 5:
|
if(key.endsWith("CC")){
|
if(key.charAt(0)=='3') return true;
|
}else{
|
if(key.charAt(1)=='3') return true;
|
}
|
}
|
|
return false;
|
case "发射机":
|
|
switch (key.length()){
|
case 4:
|
if(key.charAt(1)=='5') return true;
|
case 5:
|
if(key.endsWith("CC")){
|
if(key.charAt(0)=='5') return true;
|
}else{
|
if(key.charAt(1)=='5') return true;
|
}
|
}
|
|
return false;
|
case "成型机":
|
|
switch (key.length()){
|
case 4:
|
if(key.charAt(1)=='4') return true;
|
case 5:
|
if(key.endsWith("CC")){
|
if(key.charAt(0)=='4') return true;
|
}else{
|
if(key.charAt(1)=='4') return true;
|
}
|
}
|
|
return false;
|
case "提升机":
|
|
switch (key.length()){
|
case 4:
|
if(key.charAt(1)=='6') return true;
|
case 5:
|
if(key.endsWith("CC")){
|
if(key.charAt(0)=='6') return true;
|
}else{
|
if(key.charAt(1)=='6') return true;
|
}
|
}
|
|
return false;
|
}
|
|
return false;
|
}
|
|
}
|