span>
	public void setTimeStamp(Timestamp timeStamp) {
98
		this.timeStamp = timeStamp;
99
	}
100
101
	@Override
102
	public String toString() {
103
		return "LocationBean [mac=" + mac + ", floor=" + floor + ", xAxis=" + xAxis + ", yAxis=" + yAxis + ", zAxis="
104
				+ zAxis + ", timeStamp=" + timeStamp + "]";
105
	}
106
107
}

+ 71 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/model/MockScenarioData.java

@ -0,0 +1,71 @@
1
package com.ai.bss.mock.model;
2
3
import lombok.Getter;
4
import lombok.NoArgsConstructor;
5
import lombok.Setter;
6
import org.hibernate.annotations.SQLDelete;
7
import org.hibernate.annotations.Where;
8
9
import javax.persistence.*;
10
import java.io.Serializable;
11
import java.sql.Timestamp;
12
13
14
@Entity
15
@Table( name="mock_scenario_data")
16
@NoArgsConstructor
17
@Getter
18
@Setter
19
public class MockScenarioData implements Serializable {
20
21
22
    @Id
23
    @GeneratedValue(strategy = GenerationType.AUTO)
24
    @Column(name="ID")
25
    private long id;
26
27
    //场景ID
28
    @Column(name="SCENARIO_ID")
29
    private long scenarioId;
30
31
    //场景ID
32
    @Column(name="DEVICE_ID")
33
    private String deviceId;
34
35
    //执行顺序
36
    @Column(name="ORDER_NO")
37
    private long orderNo;
38
39
    //经度
40
    @Column(name="LONGITUDE")
41
    private String longitude;
42
43
    //纬度
44
    @Column(name="LATITUDE")
45
    private String latitude;
46
47
    //速度
48
    @Column(name="SPEED")
49
    private String speed;
50
51
    //方位
52
    @Column(name="ORIENTATION")
53
    private String orientation;
54
55
    //时间
56
    @Column(name="TIME")
57
    private String time;
58
59
    //类型(0 定位;1 自动报警;2手动报警;4离线)
60
    @Column(name="TYPE")
61
    private String type;
62
63
    //类型(0 定位;1 自动报警;2手动报警;4离线)
64
    @Column(name="TOPIC")
65
    private String topic;
66
67
    //模拟数据-扩展json格式
68
    @Column(name="MOCK_DATA")
69
    private String mock_data;
70
71
}

+ 22 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/repository/MockScenarioDataRepository.java

@ -0,0 +1,22 @@
1
package com.ai.bss.mock.repository;
2
3
import com.ai.bss.mock.model.MockScenarioData;
4
import org.springframework.data.jpa.repository.JpaRepository;
5
import org.springframework.data.jpa.repository.Modifying;
6
import org.springframework.data.jpa.repository.Query;
7
import org.springframework.data.repository.query.Param;
8
import org.springframework.stereotype.Repository;
9
10
import java.io.Serializable;
11
import java.util.List;
12
13
@Repository
14
public interface MockScenarioDataRepository extends JpaRepository<MockScenarioData, Serializable> {
15
16
    List<MockScenarioData> findByScenarioIdOrderByOrderNo(Long scenarioId);
17
18
    @Modifying
19
    @Query(value = "select DISTINCT order_no from mock_scenario_data where scenario_id = :scenarioId order by order_no\n", nativeQuery = true)
20
    List<Long> findByOrderNoByScenarioId(@Param("scenarioId") Long scenarioId);
21
22
}

+ 111 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/service/impl/MockManageServiceImpl.java

@ -0,0 +1,111 @@
1
package com.ai.bss.mock.service.impl;
2
3
import java.sql.Timestamp;
4
import java.util.ArrayList;
5
import java.util.HashMap;
6
import java.util.List;
7
import java.util.Map;
8
9
import org.springframework.beans.factory.annotation.Autowired;
10
import org.springframework.stereotype.Service;
11
import org.springframework.util.CollectionUtils;
12
13
import com.ai.bss.mock.model.LocationBean;
14
import com.ai.bss.mock.model.MockScenarioData;
15
import com.ai.bss.mock.repository.MockScenarioDataRepository;
16
import com.ai.bss.mock.service.interfaces.MockManageService;
17
import com.ai.bss.mock.service.interfaces.MockProcess;
18
19
import lombok.extern.slf4j.Slf4j;
20
21
@Slf4j
22
@Service
23
public class MockManageServiceImpl implements MockManageService {
24
25
	protected static Map MACK_STATUS = new HashMap();
26
	
27
    @Autowired
28
    private MockScenarioDataRepository mockScenarioDataRepository;
29
    @Autowired
30
    private MockProcess mockProcess;
31
32
//    @Value("${kafka.producer.servers:Empty}")
33
    private static String kafkaServers = "47.105.160.21:9090";
34
35
    @Override
36
    public Map findMockStatusByScenarioId()  {
37
        List<Long> result = new ArrayList(MACK_STATUS.keySet());
38
        Map  tempmap = new HashMap();
39
        for(Long sid:result){
40
            tempmap.put(sid,"场景 "+sid+" 执行中...");
41
        }
42
        return tempmap;
43
    }
44
    @Override
45
    public String  startMackData(Long sId,  Long frequency,String topic0,String topic1)  {
46
        //        验证场景是否正在执行
47
        if(MACK_STATUS.get(sId)!=null){
48
            return "场景" + sId + " 正在执行,请耐心等待...";
49
        }
50
        //根据场景ID从数据库中查询模拟数据
51
        List<MockScenarioData>  mockScenarioDataList = mockScenarioDataRepository.findByScenarioIdOrderByOrderNo(sId);
52
53
        List<Long> orderNoList = mockScenarioDataRepository.findByOrderNoByScenarioId(sId);
54
        if(CollectionUtils.isEmpty(mockScenarioDataList) || CollectionUtils.isEmpty(orderNoList)){
55
            return "场景" + sId + " 没有配置模拟 ,请在数据库中添加数据再执行...";
56
        }
57
        
58
        //记录场景执行状态
59
        MACK_STATUS.put(sId,frequency);
60
        //异步执行模拟场景 通过IOT-DMP连接服务模拟
61
//        mockProcess.processMock(sId,mockScenarioDataList,frequency);
62
63
        Map<Long, List<LocationBean>> dataMap=getMapListData(mockScenarioDataList);
64
        
65
        //异步执行模拟场景  直接模拟最终数据发送到kafka
66
        mockProcess.processMockKafka(sId,dataMap,orderNoList,frequency,topic0, topic1);
67
68
        return "场景" + sId + " 开始执行...";
69
    }
70
71
72
    @Override
73
    public String  stopMackData(Long sId){
74
        MACK_STATUS.remove(sId);
75
        return "场景" + sId + " 终止执行...";
76
    }
77
78
    /**
79
          * 按orderNo分组
80
     * @param mockScenarioDataList
81
     * @return
82
     */
83
    private Map<Long, List<LocationBean>> getMapListData(List<MockScenarioData> mockScenarioDataList) {
84
    	Map<Long, List<LocationBean>> map=new HashMap<Long, List<LocationBean>>();
85
    	
86
    	for (MockScenarioData mockScenarioData : mockScenarioDataList) {
87
    		LocationBean locationBean=new LocationBean();
88
        	locationBean.setFloor(1);
89
        	locationBean.setMac(mockScenarioData.getDeviceId());
90
        	locationBean.setxAxis(Double.valueOf(mockScenarioData.getLongitude()));
91
        	locationBean.setyAxis(Double.valueOf(mockScenarioData.getLatitude()));
92
        	locationBean.setzAxis(0d);
93
        	locationBean.setTimeStamp(new Timestamp(System.currentTimeMillis()));
94
    		
95
        	
96
    		long orderNo=mockScenarioData.getOrderNo();
97
    		
98
    		List<LocationBean> list=map.get(orderNo);
99
    		if (list==null) {
100
    			list=new ArrayList<LocationBean>();
101
    			list.add(locationBean);
102
    			map.put(orderNo, list);
103
			}else {
104
				list.add(locationBean);
105
			}
106
		}
107
    	
108
    	return map;
109
    }
110
    
111
}

+ 136 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/service/impl/MockProcessImpl.java

@ -0,0 +1,136 @@
1
package com.ai.bss.mock.service.impl;
2
3
import java.sql.Timestamp;
4
import java.util.ArrayList;
5
import java.util.Date;
6
import java.util.HashMap;
7
import java.util.List;
8
import java.util.Map;
9
import java.util.concurrent.ExecutorService;
10
import java.util.concurrent.Executors;
11
import java.util.concurrent.TimeUnit;
12
13
import org.slf4j.Logger;
14
import org.slf4j.LoggerFactory;
15
import org.springframework.beans.factory.annotation.Value;
16
import org.springframework.kafka.core.KafkaTemplate;
17
import org.springframework.scheduling.annotation.Async;
18
import org.springframework.stereotype.Service;
19
import org.springframework.util.StringUtils;
20
21
import com.ai.bss.mock.model.Data;
22
import com.ai.bss.mock.model.DataPoint;
23
import com.ai.bss.mock.model.EBCData;
24
import com.ai.bss.mock.model.LocationBean;
25
import com.ai.bss.mock.model.MockScenarioData;
26
import com.ai.bss.mock.service.interfaces.MockProcess;
27
import com.ai.bss.mock.utils.KafkaProducerConfig;
28
import com.ai.bss.mock.utils.tcp.IpuTcpLongConnectClient;
29
import com.ailk.common.data.impl.DataMap;
30
import com.alibaba.fastjson.JSON;
31
import com.alibaba.fastjson.JSONObject;
32
33
import lombok.extern.slf4j.Slf4j;
34
35
36
@Slf4j
37
@Service
38
public class MockProcessImpl implements MockProcess {
39
	private static final Logger logger = LoggerFactory.getLogger(MockProcessImpl.class);
40
41
//    EBC设备tcp连接服务地址
42
    private static final String HOST = "47.105.130.83";
43
    private static final int PORT = 8042;
44
45
    private static String kafkaServers = "47.105.160.21:9091";
46
47
    @Value("${kafka.producer.servers}")
48
    private static String servers;
49
    
50
    @Value("${kafka.producer.topic}")
51
    private String topic;
52
53
    @Async
54
    @Override
55
    public void processMock(Long sId,List<MockScenarioData> mockScenarioDataList, Long frequency){
56
        try {
57
            IpuTcpLongConnectClient.getInstance(HOST, PORT).sendMockData(sId,mockScenarioDataList, frequency);
58
59
            MockManageServiceImpl.MACK_STATUS.remove(sId);
60
        }catch (Exception e){
61
        	logger.error("processMock is error:"+e.getMessage());
62
            //e.printStackTrace();
63
        }
64
    }
65
66
    //线程池
67
    private ExecutorService cachedThreadPool = Executors.newCachedThreadPool();
68
    
69
    @Async
70
    @Override
71
    public void processMockKafka(Long sId,Map<Long, List<LocationBean>> dataMap,List<Long> orderNoList, Long frequency,String topic0,String topic1){
72
    	String clientId="XBG_AC67B2C23CFC";
73
		String userName="abc";
74
		topic="uploadInfoTest";
75
		
76
    	try {
77
            for (Long orderNo : orderNoList) {
78
            	List<LocationBean> dataList=dataMap.get(orderNo);
79
            	
80
            	for (LocationBean locationBean : dataList) {
81
            		cachedThreadPool.execute(new Runnable() {
82
            			@Override
83
            			public void run() {
84
            				String msg=JSON.toJSONString(locationBean);
85
                   		 
86
                    		System.out.println("推送消息:"+msg);
87
                    		 
88
                        	sendKafkaDataPoint(clientId, userName, topic, msg);
89
            			}
90
            		});
91
				}
92
93
                TimeUnit.MILLISECONDS.sleep(frequency * 1000);
94
            }
95
96
97
            MockManageServiceImpl.MACK_STATUS.remove(sId);
98
        }catch (Exception e){
99
        	logger.error("processMockKafka is error:"+e.getMessage());
100
        }
101
    }
102
103
    private Map<String, KafkaTemplate> kafkaTemplateMap = new HashMap<>();
104
105
    private void sendKafkaDataPoint(String deviceId, String userName, String topic, String msg) {
106
		KafkaTemplate kafkaTemplate = kafkaTemplateMap.get(kafkaServers);
107
		if (kafkaTemplate == null) {
108
			// new 实例
109
			KafkaProducerConfig kafkaProducerConfig = new KafkaProducerConfig(kafkaServers);
110
			kafkaTemplate = kafkaProducerConfig.kafkaTemplate();
111
			kafkaTemplateMap.put(kafkaServers, kafkaTemplate);
112
		}
113
		
114
		if (kafkaTemplate == null) {
115
			log.error("kafkaTemplate is null");
116
			return;
117
		}
118
		
119
		DataMap dataMap = new DataMap();
120
		dataMap.put("resourceId", deviceId);
121
		dataMap.put("productKey", userName);
122
		dataMap.put("detailInfo", msg);
123
		dataMap.put("eventTime", System.currentTimeMillis());
124
		try {
125
			String msgStr=JSON.toJSONString(dataMap);
126
			log.info("发送kafka消息:topic=" + topic + ", msg=" + msgStr );
127
			kafkaTemplate.send(topic, deviceId, msgStr);
128
			
129
			kafkaTemplate.flush();
130
			log.info("发送kafka消息成功");
131
		} catch (Exception e) {
132
			log.error(topic + " send error");
133
		}
134
	}
135
    
136
}

+ 27 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/service/interfaces/MockManageService.java

@ -0,0 +1,27 @@
1
package com.ai.bss.mock.service.interfaces;
2
3
import java.util.Map;
4
5
public interface MockManageService {
6
7
    /**
8
     * 查询当前正在 的场景
9
     * @return
10
     */
11
    Map findMockStatusByScenarioId();
12
13
    /**
14
     * 开始执行模拟数据
15
     * @param sId
16
     * @param f
17
     * @return
18
     */
19
    String  startMackData(Long sId,  Long f,String topic0,String topic1) ;
20
21
    /**
22
     * 停止执行模拟数据
23
     * @param sId
24
     * @return
25
     */
26
    String  stopMackData(Long sId);
27
}

+ 14 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/service/interfaces/MockProcess.java

@ -0,0 +1,14 @@
1
package com.ai.bss.mock.service.interfaces;
2
3
import com.ai.bss.mock.model.LocationBean;
4
import com.ai.bss.mock.model.MockScenarioData;
5
6
import java.util.List;
7
import java.util.Map;
8
9
public interface MockProcess {
10
    void processMock(Long sId,List<MockScenarioData> mockScenarioDataList, Long frequency);
11
12
13
    void processMockKafka(Long sId,Map<Long, List<LocationBean>> dataMap,List<Long> orderNoList, Long frequency,String topic0,String topic1);
14
}

+ 48 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/utils/HexStringUtil.java

@ -0,0 +1,48 @@
1
package com.ai.bss.mock.utils;
2
3
/**
4
 * 16进制转换工具类
5
 * */
6
public class HexStringUtil {
7
8
	/**
9
	 * 将16进制字符串转换为byte[]
10
	 */
11
	public static byte[] decodeHextoByte(String str) {
12
		if (str == null || str.trim().equals("")) {
13
			return new byte[0];
14
		}
15
		byte[] bytes = new byte[str.length() / 2];
16
		for (int i = 0; i < str.length() / 2; i++) {
17
			String subStr = str.substring(i * 2, i * 2 + 2);
18
			bytes[i] = (byte) Integer.parseInt(subStr, 16);
19
		}
20
		return bytes;
21
	}
22
23
	/**
24
	 * 将byte转换为16进制字符串
25
	 * @param b
26
	 * @return
27
	 */
28
	public static String decodeBytetoHexString(byte b) {
29
		return Integer.toHexString(b & 0xff);
30
	}
31
32
	/**
33
	 * 将byte数组转换为16进制字符串
34
	 * @param bs
35
	 * @return
36
	 */
37
	public static String decodeByteArraytoHexString(byte[] bs) {
38
		StringBuilder builder = new StringBuilder();
39
		for (int i = 0; i < bs.length; i++) {
40
			if (bs[i]<0x10 && bs[i]>=0) {
41
				builder.append("0");
42
			}
43
			builder.append(decodeBytetoHexString(bs[i]));
44
		}
45
		return builder.toString();
46
	}
47
48
}

+ 113 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/utils/KafkaProducerConfig.java

@ -0,0 +1,113 @@
1
package com.ai.bss.mock.utils;
2
3
import com.alibaba.fastjson.JSONObject;
4
import lombok.NoArgsConstructor;
5
import lombok.extern.slf4j.Slf4j;
6
import org.apache.kafka.clients.producer.ProducerConfig;
7
import org.apache.kafka.common.serialization.StringSerializer;
8
import org.springframework.beans.factory.annotation.Value;
9
import org.springframework.context.annotation.Bean;
10
import org.springframework.context.annotation.Configuration;
11
import org.springframework.kafka.annotation.EnableKafka;
12
import org.springframework.kafka.core.DefaultKafkaProducerFactory;
13
import org.springframework.kafka.core.KafkaTemplate;
14
import org.springframework.kafka.core.ProducerFactory;
15
import org.springframework.stereotype.Component;
16
17
import java.util.HashMap;
18
import java.util.Map;
19
20
@Slf4j
21
@Configuration
22
@EnableKafka
23
@NoArgsConstructor
24
@Component
25
public class KafkaProducerConfig {
26
27
    @Value("${kafka.producer.servers:Empty}")
28
//    private static String servers = "47.105.160.21:9090";
29
    private static String servers = "10.19.90.34:9090";
30
    @Value("${kafka.producer.retries:0}")
31
    private  int retries;
32
    @Value("${kafka.producer.batch.size:4096}")
33
    private  int batchSize;
34
    @Value("${kafka.producer.linger:1}")
35
    private  int linger;
36
    @Value("${kafka.producer.buffer.memory:40960}")
37
    private  int bufferMemory;
38
39
    private  int maxBlockTime = 60000;
40
41
    public KafkaProducerConfig(String inputServers){
42
        servers = inputServers;
43
        this.retries = 0;
44
        this.batchSize = 16384;
45
        this.linger = 1;
46
        this.bufferMemory = 33554432;
47
        this.maxBlockTime = 6000;
48
49
    }
50
51
    public Map<String, Object> producerConfigs() {
52
        Map<String, Object> props = new HashMap<>();
53
        props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, servers);
54
        props.put(ProducerConfig.RETRIES_CONFIG, retries);
55
        props.put(ProducerConfig.BATCH_SIZE_CONFIG, batchSize);
56
        props.put(ProducerConfig.LINGER_MS_CONFIG, linger);
57
        props.put(ProducerConfig.BUFFER_MEMORY_CONFIG, bufferMemory);
58
        props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
59
        props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
60
        props.put(ProducerConfig.MAX_BLOCK_MS_CONFIG,maxBlockTime);
61
        return props;
62
    }
63
64
    public ProducerFactory<String, String> producerFactory() {
65
        return new DefaultKafkaProducerFactory<>(producerConfigs());
66
    }
67
68
    @Bean
69
    public KafkaTemplate<String, String> kafkaTemplate() {
70
        return new KafkaTemplate<String, String>(producerFactory());
71
    }
72
//
73
74
75
    private static Map<String, KafkaTemplate>  kafkaTemplateMap = new HashMap<>();
76
    static KafkaTemplate  kafkaTemplate = null;
77
    /**
78
     * 推送消息到订阅的KAFKA服务器地址以及topic
79
     * @param kafkaTopic  订阅的kafka topic
80
     * @param content  消息内容
81
     * @return
82
     */
83
    public static Boolean sendForKafka(String kafkaTopic,String content) {
84
//        KafkaProducerConfig kafkaProducerConfig = new KafkaProducerConfig(servers);
85
//        KafkaTemplate kafkaTemplate =  kafkaProducerConfig.kafkaTemplate();
86
87
88
        kafkaTemplate = kafkaTemplateMap.get(servers);
89
        if(kafkaTemplate == null){
90
            //new 实例
91
//            KafkaProducerConfig kafkaProducerConfig = new KafkaProducerConfig(servers);
92
            KafkaProducerConfig kafkaProducerConfig = new KafkaProducerConfig();
93
            kafkaTemplate = kafkaProducerConfig.kafkaTemplate();
94
            kafkaTemplateMap.put(servers,kafkaTemplate);
95
        }
96
97
98
        try {
99
            System.out.println("send msg to Kafka:" + servers + "服务器地址以及topic:" + kafkaTopic + " 内容:" + content );
100
            Object result = kafkaTemplate.send(kafkaTopic,content ).get();
101
            log.debug("It's successful send msg to Kafka:" + servers + "服务器地址以及topic:" + kafkaTopic + " 内容:" + content + " 结果" + result);
102
103
            kafkaTemplate.flush();
104
        } catch (InterruptedException e) {
105
            log.error(e.getMessage());
106
            return false;
107
        } catch (Exception e) {
108
            log.error(e.getMessage());
109
            return false;
110
        }
111
        return true;
112
    }
113
}

+ 19 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/utils/MessageUtil.java

@ -0,0 +1,19 @@
1
package com.ai.bss.mock.utils;
2
3
4
public class MessageUtil {
5
    private MessageUtil() {
6
    }
7
8
    public static String getMessageKeyWord(String strContent) {
9
        return null;//  CommonConfig.hasBase64Flag() ? JSON.parseObject(new String(Base64.getDecoder().decode(strContent), StandardCharsets.UTF_8)).getString(CommonConfig.getMessageKeyWord()) : JSON.parseObject(strContent).getString(CommonConfig.getMessageKeyWord());
10
    }
11
12
    public static String getDecodeContent(String strContentEncode) {
13
        return null;//  CommonConfig.hasBase64Flag() ? new String(Base64.getDecoder().decode(strContentEncode), StandardCharsets.UTF_8) : strContentEncode;
14
    }
15
16
    public static String getEncodeContent(String strContent) {
17
        return null;// CommonConfig.hasBase64Flag() ? new String(Base64.getEncoder().encode(strContent.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8) : strContent;
18
    }
19
}

+ 19 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/utils/SecurityConfigSEVEN.java

@ -0,0 +1,19 @@
1
package com.ai.bss.mock.utils;
2
3
import org.springframework.context.annotation.Configuration;
4
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
5
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
6
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
7
8
@Configuration
9
@EnableWebSecurity
10
public class SecurityConfigSEVEN extends WebSecurityConfigurerAdapter {
11
12
    @Override
13
    protected void configure(HttpSecurity http) throws Exception {
14
        //super.configure(http);
15
        //配置不需要登陆验证
16
        http.authorizeRequests().anyRequest().permitAll().and().logout().permitAll();
17
    }
18
}
19

+ 31 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/utils/makedata/MakeBluetoothData.java

@ -0,0 +1,31 @@
1
package com.ai.bss.mock.utils.makedata;
2
3
import java.sql.Timestamp;
4
5
import com.ai.bss.mock.model.LocationBean;
6
import com.alibaba.fastjson.JSON;
7
8
public class MakeBluetoothData {
9
10
	/**
11
	 * 经纬度坐标单位为米
12
	 * @param xAxis
13
	 * @param yAxis
14
	 */
15
	public static String sendBluetoothKafka(double xAxis,double yAxis) {
16
		String clientId="XBG_AC67B2C23CFC";
17
		 String userName="abc";
18
		
19
		 String mac="d3e656a4573d";
20
		 
21
		 Integer floor=1;
22
		 Timestamp timeStamp=new Timestamp(System.currentTimeMillis());
23
		 LocationBean location=new LocationBean(mac, floor, xAxis, yAxis, timeStamp);
24
		 
25
		 String msg=JSON.toJSONString(location);
26
		 
27
		 System.out.println(msg);
28
		 
29
		 return msg;
30
	}
31
}

+ 56 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/utils/tcp/IpuTcpLongConnectClient.java

@ -0,0 +1,56 @@
1
package com.ai.bss.mock.utils.tcp;
2
3
import java.util.List;
4
5
import org.slf4j.Logger;
6
import org.slf4j.LoggerFactory;
7
8
import com.ai.bss.mock.model.MockScenarioData;
9
import com.ai.bss.mock.utils.tcp.message.MessageGenerationManager;
10
11
/**
12
 * Ipu Tcp长连接测试
13
 *
14
 * @author lilb3@asiainfo.com
15
 * @since 2020-06-23
16
 **/
17
@SuppressWarnings("unused")
18
public class IpuTcpLongConnectClient {
19
	private static final Logger logger = LoggerFactory.getLogger(IpuTcpLongConnectClient.class);
20
21
	
22
    private static IpuTcpLongConnectClient ipuClient;
23
    private TcpLongConnectClient nettyClient;
24
25
    private IpuTcpLongConnectClient() {
26
27
    }
28
29
    public static IpuTcpLongConnectClient getInstance(String host, int serverPort) {
30
        if (ipuClient == null) {
31
            ipuClient = new IpuTcpLongConnectClient();
32
            ipuClient.nettyClient = new TcpLongConnectClient(host, serverPort, MessageGenerationManager.getMessage());
33
        }
34
        return ipuClient;
35
    }
36
37
    /**
38
     * Tcp长连接方式发送消息
39
     * @throws Exception 
40
     */
41
    public void test() throws Exception {
42
        //nettyClient.test();
43
    	logger.info("test");
44
    }
45
    
46
47
    /**
48
     * Tcp长连接方式发送消息
49
     * @throws Exception
50
     */
51
    public void sendMockData(Long sId,List<MockScenarioData> mockScenarioDataList,Long frequency) throws Exception {
52
        //nettyClient.sendMockData(sId,mockScenarioDataList,frequency);
53
    	logger.info("sendMockData");
54
    }
55
    
56
}

+ 42 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/utils/tcp/TcpLongConnectClient.java

@ -0,0 +1,42 @@
1
package com.ai.bss.mock.utils.tcp;
2
3
import io.netty.bootstrap.Bootstrap;
4
import io.netty.channel.Channel;
5
import io.netty.channel.ChannelFuture;
6
import lombok.extern.slf4j.Slf4j;
7
8
/**
9
 * Tcp长连接客户端
10
 *
11
 * @author lilb3@asiainfo.com
12
 * @since 2019-10-16
13
 **/
14
@Slf4j
15
class TcpLongConnectClient {
16
	// private static final int PERIOD = 1;
17
	static final long PER_SLEEP_TIME = 2000L;
18
	// private static final int SEND_TIMES = 6;
19
	private final String host;
20
	private final int port;
21
	private final String message;
22
	private Channel channel;
23
	private ChannelFuture channelFuture;
24
	private Bootstrap bootstrap;
25
26
	TcpLongConnectClient(String host, int port, String message) {
27
		this.host = host;
28
		this.port = port;
29
		this.message = message;
30
	}
31
32
	/**
33
	 * 抽取出该方法 (断线重连时使用)
34
	 *
35
	 * @throws InterruptedException 异常
36
	 */
37
	void doConnect() throws InterruptedException {
38
		channelFuture = bootstrap.connect(host, port).sync();
39
		channel = channelFuture.channel();
40
	}
41
42
}

+ 73 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/utils/tcp/TcpLongConnectClientHandler.java

@ -0,0 +1,73 @@
1
package com.ai.bss.mock.utils.tcp;
2
3
import java.nio.charset.StandardCharsets;
4
5
import io.netty.buffer.ByteBuf;
6
import io.netty.channel.ChannelHandlerContext;
7
import io.netty.channel.ChannelInboundHandlerAdapter;
8
import io.netty.handler.timeout.IdleStateEvent;
9
import lombok.extern.slf4j.Slf4j;
10
11
/**
12
 * Tcp长连接客户端处理类
13
 *
14
 * @author lilb3@asiainfo.com
15
 * @since 2020-04-09
16
 **/
17
@Slf4j
18
class TcpLongConnectClientHandler extends ChannelInboundHandlerAdapter {
19
    private static final long SLEEP_TIME = 10 * 1000L;
20
    private final TcpLongConnectClient tcpLongConnectClient;
21
22
    TcpLongConnectClientHandler(TcpLongConnectClient tcpLongConnectClient) {
23
        this.tcpLongConnectClient = tcpLongConnectClient;
24
    }
25
26
    @Override
27
    public void channelActive(ChannelHandlerContext ctx) {
28
        log.info("TCP长连接客户端接入成功");
29
    }
30
31
    @Override
32
    public void channelInactive(ChannelHandlerContext ctx) {
33
    	log.info("连接断开");
34
    	//System.out.println("连接断开");
35
		/*LOGGER.debug("连接断开,10s之后尝试重新连接服务器。");
36
		try {
37
		    TimeUnit.MILLISECONDS.sleep(SLEEP_TIME);
38
		} catch (InterruptedException e) {
39
		    LOGGER.error(e.getMessage(), e);
40
		    Thread.currentThread().interrupt();
41
		}
42
		try {
43
		    tcpLongConnectClient.doConnect();
44
		} catch (InterruptedException e) {
45
		    LOGGER.error(e.getMessage(), e);
46
		    Thread.currentThread().interrupt();
47
		}*/
48
    }
49
50
    @Override
51
    public void channelRead(ChannelHandlerContext ctx, Object msg) {
52
        ByteBuf byteBuf = (ByteBuf) msg;
53
        byte[] content = new byte[byteBuf.readableBytes()];
54
        byteBuf.readBytes(content);
55
        String strContentEncode = new String(content, StandardCharsets.UTF_8);
56
//            String strContentDecode = MessageUtil.getDecodeContent(strContentEncode);
57
        log.debug(String.format("长连接TCP客户端收到的信息: %s", strContentEncode));
58
    }
59
60
    @Override
61
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
62
        log.error("客户端捕获到异常。", cause);
63
    }
64
65
    @Override
66
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
67
        if (evt instanceof IdleStateEvent) {
68
            //如果规定时内没有读写时间,则触发一个消息
69
            //ctx.writeAndFlush((CommonConfig.getTcpHeartBeat() + TCP_DELIMITER).getBytes(StandardCharsets.UTF_8));
70
        	
71
        }
72
    }
73
}

+ 27 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/utils/tcp/message/DefaultMessageGeneration.java

@ -0,0 +1,27 @@
1
package com.ai.bss.mock.utils.tcp.message;
2
3
import com.ai.bss.mock.utils.MessageUtil;
4
import com.alibaba.fastjson.JSONObject;
5
6
/**
7
 * 消息测试
8
 *
9
 * @author lilb3@asiainfo.com
10
 * @since 2020-03-30
11
 **/
12
public class DefaultMessageGeneration implements IMessageGeneration {
13
    private static final String IMEI = "imeiTest";
14
15
    private static String getMessage0(String topic) {
16
        JSONObject jsonObject = new JSONObject();
17
        jsonObject.put("topic", topic);
18
        jsonObject.put("imei", IMEI);
19
        jsonObject.put("sendTime", System.currentTimeMillis() + "");
20
        return jsonObject.toString();
21
    }
22
23
    @Override
24
    public String getMessage(String topic) {
25
        return MessageUtil.getEncodeContent(getMessage0(topic));
26
    }
27
}

+ 19 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/utils/tcp/message/IMessageGeneration.java

@ -0,0 +1,19 @@
1
package com.ai.bss.mock.utils.tcp.message;
2
3
/**
4
 * 消息发送接口
5
 *
6
 * @author lilb3@asiainfo.com
7
 * @since 2020-06-22
8
 **/
9
@SuppressWarnings("unused")
10
public interface IMessageGeneration {
11
12
    /**
13
     * 获取测试消息
14
     *
15
     * @param topic 消息主题
16
     * @return 测试消息
17
     */
18
    String getMessage(String topic);
19
}

+ 73 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/utils/tcp/message/MessageGenerationManager.java

@ -0,0 +1,73 @@
1
package com.ai.bss.mock.utils.tcp.message;
2
3
import com.ai.bss.mock.constants.MockConstant;
4
import com.ai.ipu.basic.instance.InstanceManager;
5
6
import java.util.HashMap;
7
import java.util.Map;
8
9
10
/**
11
 * 增加message默认处理类,分离消息消费逻辑
12
 *
13
 * @author lilb3@asiainfo.com
14
 * @since 2020-06-22
15
 **/
16
@SuppressWarnings("unused")
17
public class MessageGenerationManager {
18
    private static final String SPLIT_DASH = MockConstant.SPLIT_DASH;
19
    private static final Map<String, IMessageGeneration> INSTANCES = new HashMap<>();
20
    private static IMessageGeneration defaultMessageGeneration;
21
22
    private MessageGenerationManager() {
23
        throw new RuntimeException("MessageGenerationManager无法被实例化");
24
    }
25
26
    @SuppressWarnings("unchecked")
27
    private static IMessageGeneration createMessageGeneration(String className) throws Exception {
28
        IMessageGeneration messageGeneration = INSTANCES.get(className);
29
        if (messageGeneration == null) {
30
            synchronized (INSTANCES) {
31
                if (INSTANCES.get(className) == null) {
32
                    Class<?> clazz = Class.forName(className);
33
                    messageGeneration = InstanceManager.createBean((Class<IMessageGeneration>) clazz);
34
                    INSTANCES.put(className, messageGeneration);
35
                }
36
            }
37
        }
38
        return INSTANCES.get(className);
39
    }
40
41
//    public static <Type> Type createBean(Class<Type> clazz) throws Exception {
42
//        return createBean(clazz, true);
43
//    }
44
45
    private static IMessageGeneration getDefaultMessageGeneration() {
46
        if (defaultMessageGeneration == null) {
47
            defaultMessageGeneration = new DefaultMessageGeneration();
48
        }
49
        return defaultMessageGeneration;
50
    }
51
52
    public static void setDefaultMessageGeneration(IMessageGeneration defaultMessageGeneration) {
53
        MessageGenerationManager.defaultMessageGeneration = defaultMessageGeneration;
54
    }
55
56
    public static String getMessage() {
57
    	//String topic = CommonConfig.getTopics()[new Random().nextInt(CommonConfig.getTopics().length)];
58
        String topic = "networkPacket";
59
        return getMessage(topic);
60
    }
61
62
    public static String getMessage(String topic) {
63
        try {
64
            IMessageGeneration messageGeneration = MessageGenerationManager.getDefaultMessageGeneration();;
65
            if (messageGeneration != null) {
66
                return messageGeneration.getMessage(topic);
67
            }
68
        } catch (Exception e) {
69
//            LOGGER.error("Test Message生成异常", e);
70
        }
71
        return "";
72
    }
73
}

+ 59 - 0
indoor-mock-service/src/main/resources/application.properties

@ -0,0 +1,59 @@
1
spring.application.name=WorkTaskSpec
2
server.port=8086
3
4
# DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
5
#spring.datasource.url=jdbc:mysql://localhost:3306/cmp
6
#spring.datasource.url=jdbc:mysql://10.19.14.28:3306/work_order?useUnicode=true&ampcharacterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
7
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
8
#spring.datasource.username=aibp
9
#spring.datasource.password=Aibp@123
10
#spring.datasource.url=jdbc:mysql://10.11.20.120:3306/common_frm?useUnicode=true&ampcharacterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
11
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
12
#spring.datasource.username=comon_frm
13
#spring.datasource.password=1qaz@WSX
14
#spring.datasource.url=jdbc:mysql://47.105.160.21:3309/dmp?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
15
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
16
#spring.datasource.username=cmp
17
#spring.datasource.password=cmp@123
18
spring.datasource.url=jdbc:mysql://10.19.90.34:3307/energy?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
19
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
20
spring.datasource.username=ebc
21
spring.datasource.password=ebc@123
22
23
# JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration)
24
#spring.jpa.database=default
25
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
26
spring.jpa.hibernate.ddl-auto=update
27
spring.jpa.show-sql=true
28
spring.jpa.properties.hibernate.format_sql=true
29
spring.jpa.properties.hibernate.generate_statistics=false
30
spring.main.allow-bean-definition-overriding=true
31
32
# CACHE
33
#spring.cache.type=ehcache
34
#spring.cache.ehcache.config=ehcache.xml
35
36
# LOGGING
37
logging.level.com.ai=info
38
logging.level.org.springframework.data=info
39
40
41
42
43
#============== kafka ===================
44
kafka.consumer.zookeeper.connect=47.105.160.21:2100
45
kafka.consumer.servers=47.105.160.21:9090
46
kafka.consumer.enable.auto.commit=true
47
kafka.consumer.session.timeout=6000
48
kafka.consumer.auto.commit.interval=100
49
kafka.consumer.auto.offset.reset=latest
50
kafka.consumer.topic=productMessage
51
kafka.consumer.group.id=productMessage
52
kafka.consumer.concurrency=10
53
54
kafka.producer.servers=47.105.160.21:9091
55
kafka.producer.retries=0
56
kafka.producer.batch.size=4096
57
kafka.producer.linger=1
58
kafka.producer.buffer.memory=40960
59
kafka.producer.topic=uploadInfoTest

+ 34 - 0
indoor-mock-service/src/test/resources/application.properties

@ -0,0 +1,34 @@
1
spring.application.name=WorkTaskSpec
2
server.port=8086
3
4
# DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
5
#spring.datasource.url=jdbc:mysql://localhost:3306/cmp
6
#spring.datasource.url=jdbc:mysql://10.19.14.28:3306/work_order?useUnicode=true&ampcharacterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
7
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
8
#spring.datasource.username=aibp
9
#spring.datasource.password=Aibp@123
10
#spring.datasource.url=jdbc:mysql://10.11.20.120:3306/common_frm?useUnicode=true&ampcharacterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
11
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
12
#spring.datasource.username=comon_frm
13
#spring.datasource.password=1qaz@WSX
14
spring.datasource.url=jdbc:mysql://10.19.90.34:3307/energy?useUnicode=true&ampcharacterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
15
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
16
spring.datasource.username=ebc
17
spring.datasource.password=ebc@123
18
19
# JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration)
20
#spring.jpa.database=default
21
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
22
spring.jpa.hibernate.ddl-auto=update
23
spring.jpa.show-sql=true
24
spring.jpa.properties.hibernate.format_sql=true
25
spring.jpa.properties.hibernate.generate_statistics=false
26
spring.main.allow-bean-definition-overriding=true
27
28
# CACHE
29
#spring.cache.type=ehcache
30
#spring.cache.ehcache.config=ehcache.xml
31
32
# LOGGING
33
logging.level.com.ai=info
34
logging.level.org.springframework.data=info

+ 7 - 13
indoor-service/src/main/java/com/ai/bss/location/util/DateUtil.java

@ -161,22 +161,16 @@ public class DateUtil {
161 161
	 * @throws Exception 
162 162
	 */
163 163
	public static int compareDate(String dateStr0, String dateStr1) throws Exception {
164
		if (dateStr0 == null || "".equals(dateStr0)) {
165
			if (dateStr1 == null || "".equals(dateStr1)) {
166
				return 0;
167
			} else {
168
				return -1;
169
			}
170
		}
164
		Date date0 = convertDate(dateStr0);
165
		Date date1 = convertDate(dateStr1);
166
167
		if (date0 == null)
168
			return (date1 == null) ? 0 : -1;
171 169
172
		if (dateStr1 == null || "".equals(dateStr1)) {
170
		if (date1 == null)
173 171
			return 1;
174
		}
175 172
176
		Date date1 = convertDate(dateStr0);
177
		Date date2 = convertDate(dateStr1);
178
		int result = date1.compareTo(date2);
179
		return result;
173
		return date0.compareTo(date1);
180 174
	}
181 175
182 176
	/**

android-share - Nuosi Git Service

ipu的trunk版的android工程和服务端工程。

wangkang3 bd8dd01639 SONAR扫描问题 4 anos atrás
..
db 381dc7f09d 集群推送消息第一版提交 8 anos atrás
src bd8dd01639 SONAR扫描问题 4 anos atrás
.gitignore 3685925741 push管理工程配置文件提交 7 anos atrás
.project 3685925741 push管理工程配置文件提交 7 anos atrás
pom.xml 3685925741 push管理工程配置文件提交 7 anos atrás