Browse Source

新增室内点位推送模拟系统

konghl 4 years ago
parent
commit
2342540f30

+ 86 - 34
indoor-mock-service/src/main/java/com/ai/bss/mock/controller/MockController.java

@ -1,17 +1,21 @@
1 1
package com.ai.bss.mock.controller;
2 2
3
3
import java.sql.Timestamp;
4
import java.util.HashMap;
4 5
import java.util.Map;
5 6
6
import org.slf4j.Logger;
7
import org.slf4j.LoggerFactory;
7
import org.apache.commons.lang3.StringUtils;
8 8
import org.springframework.beans.factory.annotation.Autowired;
9 9
import org.springframework.stereotype.Controller;
10
import org.springframework.web.bind.annotation.RequestBody;
10 11
import org.springframework.web.bind.annotation.RequestMapping;
11 12
import org.springframework.web.bind.annotation.RequestParam;
12 13
import org.springframework.web.bind.annotation.ResponseBody;
13 14
15
import com.ai.bss.mock.model.KakfaMsgData;
16
import com.ai.bss.mock.model.LocationBean;
14 17
import com.ai.bss.mock.service.interfaces.MockManageService;
18
import com.alibaba.fastjson.JSON;
15 19
16 20
/**
17 21
 * mock
@ -20,37 +24,85 @@ import com.ai.bss.mock.service.interfaces.MockManageService;
20 24
@RequestMapping("/mock")
21 25
public class MockController {
22 26
23
    @Autowired
24
    private MockManageService mockManageService;
25
26
    private static final Logger logger = LoggerFactory.getLogger(MockController.class);
27
28
    /**
29
     * 查询mock执行状态
30
     */
31
    @ResponseBody
32
    @RequestMapping("/getMockStatus")
33
    public Map getMockStatus(){
34
        return mockManageService.findMockStatusByScenarioId();
35
    }
36
37
    /**
38
     * 查询历史轨迹查询
39
     */
40
    @ResponseBody
41
    @RequestMapping("/startMackData")
42
    public Object startMackData(@RequestParam Long sId,@RequestParam Long f,@RequestParam(required = false) String topic0 ,@RequestParam(required = false) String topic1 ) {
43
        return mockManageService.startMackData(sId,f,topic0,topic1);
44
    }
45
46
    /**
47
     * 查询历史轨迹查询
48
     */
49
    @ResponseBody
50
    @RequestMapping("/stopMackData")
51
    public Object stopMackData(@RequestParam Long sId){
52
        return mockManageService.stopMackData(sId);
53
    }
27
	@Autowired
28
	private MockManageService mockManageService;
29
30
	/**
31
	 * 查询当前正在 的场景
32
	 */
33
	@ResponseBody
34
	@RequestMapping("/getMockStatus")
35
	public Map<Long, String> getMockStatus() {
36
		return mockManageService.findMockStatusByScenarioId();
37
	}
38
39
	/**
40
	 * 开始执行模拟数据
41
	 */
42
	@ResponseBody
43
	@RequestMapping("/startMackData")
44
	public Object startMackData(@RequestParam Long sId, @RequestParam Long f,
45
			@RequestParam(required = false) String topic) {
46
		return mockManageService.startMackData(sId, f, topic);
47
	}
48
49
	/**
50
	 * 停止执行模拟数据
51
	 */
52
	@ResponseBody
53
	@RequestMapping("/stopMackData")
54
	public Object stopMackData(@RequestParam Long sId) {
55
		return mockManageService.stopMackData(sId);
56
	}
57
58
	/**
59
	 * 发送点的数据
60
	 * @param x
61
	 * @param y
62
	 * @param z
63
	 * @param topic
64
	 * @return
65
	 */
66
	@ResponseBody
67
	@RequestMapping("/sendPointData")
68
	public Object sendPointData(KakfaMsgData msgData) {
69
		if (StringUtils.isEmpty(msgData.getId()))
70
			return "error:id is null";
71
		if (StringUtils.isEmpty(msgData.getX()))
72
			return "error:x is null";
73
		if (StringUtils.isEmpty(msgData.getY()))
74
			return "error:y is null";
75
76
		LocationBean locationBean = new LocationBean(msgData.getId(), Double.valueOf(msgData.getX()),
77
				Double.valueOf(msgData.getY()));
78
79
		if (StringUtils.isNotBlank(msgData.getFloor()))
80
			locationBean.setFloor(Long.valueOf(msgData.getFloor()));
81
82
		if (StringUtils.isNotBlank(msgData.getZ()))
83
			locationBean.setZAxis(Double.valueOf(msgData.getZ()));
54 84
85
		String msgBean = JSON.toJSONString(locationBean);
86
		
87
		// {"resourceId":"XBG_AC67B2C23CFC","eventTime":1615897930463,"detailInfo":"{\"floor\":1,\"mac\":\"d3e656a4573d\",\"timeStamp\":1615897929680,\"xAxis\":21.32,\"yAxis\":5.67}","productKey":"abc"}
88
		Map<String, Object> msgMap=new HashMap<String, Object>();
89
		msgMap.put("resourceId", msgData.getId());
90
		msgMap.put("eventTime", System.currentTimeMillis());
91
		msgMap.put("detailInfo", msgBean);
92
		msgMap.put("productKey", "abc");
93
		
94
		return mockManageService.sendMsgData(JSON.toJSONString(msgMap), msgData.getTopic());
95
	}
55 96
97
	/**
98
	 * 发送kafka消息
99
	 * @param msg
100
	 * @param topic
101
	 * @return
102
	 */
103
	@ResponseBody
104
	@RequestMapping("/sendData")
105
	public Object sendMsgData(@RequestParam String msg, @RequestParam(required = false) String topic) {
106
		return mockManageService.sendMsgData(msg, topic);
107
	}
56 108
}

+ 13 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/model/KakfaMsgData.java

@ -0,0 +1,13 @@
1
package com.ai.bss.mock.model;
2
3
import lombok.Data;
4
5
@Data
6
public class KakfaMsgData {
7
	private String id;
8
	private String x;
9
	private String y;
10
	private String z;
11
	private String floor;
12
	private String topic;
13
}

+ 35 - 72
indoor-mock-service/src/main/java/com/ai/bss/mock/model/LocationBean.java

@ -1,107 +1,70 @@
1 1
package com.ai.bss.mock.model;
2 2
3 3
import java.io.Serializable;
4
import java.sql.Timestamp;
4
import java.util.Date;
5
6
import lombok.Data;
5 7
6 8
/**
7
 * created on 2016年8月25日
8
 *
9
 * 定位结果bean
10
 *
11
 * @author  megagao
12
 * @version  0.0.1
9
 * 定位结果
10
 * 
11
 * @author konghl
12
 * @Date 2021-3-23
13 13
 */
14
@Data
14 15
public class LocationBean implements Serializable {
15 16
16 17
	private static final long serialVersionUID = 1L;
17 18
18
	/*员工id*/
19
	private String mac;
19
	// 设备mac
20
	private String terminalId;
21
22
	// 楼id
23
	private String buildingId;
20 24
21
	/*楼层*/
22
	private Integer floor;
25
	// 楼层
26
	private Long floor;
23 27
24
	/*x轴坐标*/
28
	// x轴坐标
25 29
	private Double xAxis;
26 30
27
	/*y轴坐标*/
31
	// y轴坐标
28 32
	private Double yAxis;
29 33
30
	/*z轴坐标*/
34
	// z轴坐标
31 35
	private Double zAxis;
32 36
33
	/*时间戳*/
34
	private Timestamp timeStamp;
35
36
	public LocationBean(String mac, int floor, double xAxis, double yAxis, Timestamp timeStamp) {
37
		this.mac = mac;
38
		this.floor = floor;
39
		this.xAxis = xAxis;
40
		this.yAxis = yAxis;
41
		this.zAxis = 0d;
42
		this.timeStamp = timeStamp;
43
	}
37
	// 时间戳
38
	private Date timeStamp;
44 39
45 40
	public LocationBean() {
46
		this.floor = 0;
41
		this.buildingId = "1";
42
		this.floor = 1L;
47 43
		this.xAxis = 0d;
48 44
		this.yAxis = 0d;
49 45
		this.zAxis = 0d;
50
		this.timeStamp = new Timestamp(System.currentTimeMillis());
46
		this.timeStamp = new Date();
51 47
	}
52 48
53
	public Integer getFloor() {
54
		return floor;
49
	public LocationBean(String terminalId, Double xAxis, Double yAxis) {
50
		this.terminalId = terminalId;
51
		this.buildingId = "1";
52
		this.floor = 1L;
53
		this.xAxis = xAxis;
54
		this.yAxis = yAxis;
55
		this.zAxis = 0d;
56
		this.timeStamp = new Date();
55 57
	}
56 58
57
	public void setFloor(Integer floor) {
59
	public LocationBean(String terminalId, String buildingId, Long floor, Double xAxis, Double yAxis, Double zAxis,
60
			Date timeStamp) {
61
		this.terminalId = terminalId;
62
		this.buildingId = buildingId;
58 63
		this.floor = floor;
59
	}
60
61
	public String getMac() {
62
		return mac;
63
	}
64
65
	public void setMac(String mac) {
66
		this.mac = mac;
67
	}
68
69
	public Double getxAxis() {
70
		return xAxis;
71
	}
72
73
	public void setxAxis(Double xAxis) {
74 64
		this.xAxis = xAxis;
75
	}
76
77
	public Double getyAxis() {
78
		return yAxis;
79
	}
80
81
	public void setyAxis(Double yAxis) {
82 65
		this.yAxis = yAxis;
83
	}
84
85
	public Double getzAxis() {
86
		return zAxis;
87
	}
88
89
	public void setzAxis(Double zAxis) {
90 66
		this.zAxis = zAxis;
91
	}
92
93
	public Timestamp getTimeStamp() {
94
		return timeStamp;
95
	}
96
97
	public void setTimeStamp(Timestamp timeStamp) {
98 67
		this.timeStamp = timeStamp;
99 68
	}
100 69
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 70
}

+ 18 - 26
indoor-mock-service/src/main/java/com/ai/bss/mock/model/MockScenarioData.java

@ -1,14 +1,17 @@
1 1
package com.ai.bss.mock.model;
2 2
3
import java.io.Serializable;
4
5
import javax.persistence.Column;
6
import javax.persistence.Entity;
7
import javax.persistence.GeneratedValue;
8
import javax.persistence.GenerationType;
9
import javax.persistence.Id;
10
import javax.persistence.Table;
11
3 12
import lombok.Getter;
4 13
import lombok.NoArgsConstructor;
5 14
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 15
13 16
14 17
@Entity
@ -18,8 +21,9 @@ import java.sql.Timestamp;
18 21
@Setter
19 22
public class MockScenarioData implements Serializable {
20 23
24
	private static final long serialVersionUID = -1L;
21 25
22
    @Id
26
	@Id
23 27
    @GeneratedValue(strategy = GenerationType.AUTO)
24 28
    @Column(name="ID")
25 29
    private long id;
@ -44,25 +48,13 @@ public class MockScenarioData implements Serializable {
44 48
    @Column(name="LATITUDE")
45 49
    private String latitude;
46 50
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;
51
    //
52
    @Column(name="HEIGHT")
53
    private String height;
54
    
55
    //楼层
56
    @Column(name="FLOOR")
57
    private String floor;
66 58
67 59
    //模拟数据-扩展json格式
68 60
    @Column(name="MOCK_DATA")

+ 93 - 84
indoor-mock-service/src/main/java/com/ai/bss/mock/service/impl/MockManageServiceImpl.java

@ -6,6 +6,7 @@ import java.util.HashMap;
6 6
import java.util.List;
7 7
import java.util.Map;
8 8
9
import org.apache.commons.lang3.StringUtils;
9 10
import org.springframework.beans.factory.annotation.Autowired;
10 11
import org.springframework.stereotype.Service;
11 12
import org.springframework.util.CollectionUtils;
@ -16,96 +17,104 @@ import com.ai.bss.mock.repository.MockScenarioDataRepository;
16 17
import com.ai.bss.mock.service.interfaces.MockManageService;
17 18
import com.ai.bss.mock.service.interfaces.MockProcess;
18 19
19
import lombok.extern.slf4j.Slf4j;
20
21
@Slf4j
22 20
@Service
23 21
public class MockManageServiceImpl implements MockManageService {
24 22
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连接服务模拟
23
	protected static Map<Long, Long> MACK_STATUS = new HashMap();
24
25
	@Autowired
26
	private MockScenarioDataRepository mockScenarioDataRepository;
27
	@Autowired
28
	private MockProcess mockProcess;
29
30
	@Override
31
	public Map<Long, String> findMockStatusByScenarioId() {
32
		List<Long> result = new ArrayList<Long>(MACK_STATUS.keySet());
33
		Map<Long, String> tempmap = new HashMap<Long, String>();
34
		for (Long sid : result) {
35
			tempmap.put(sid, "场景 " + sid + " 执行中...");
36
		}
37
		return tempmap;
38
	}
39
40
	@Override
41
	public String startMackData(Long sId, Long frequency, String topic) {
42
		// 验证场景是否正在执行
43
		if (MACK_STATUS.get(sId) != null) {
44
			return "场景" + sId + " 正在执行,请耐心等待...";
45
		}
46
		// 根据场景ID从数据库中查询模拟数据
47
		List<MockScenarioData> mockScenarioDataList = mockScenarioDataRepository.findByScenarioIdOrderByOrderNo(sId);
48
49
		List<Long> orderNoList = mockScenarioDataRepository.findByOrderNoByScenarioId(sId);
50
		if (CollectionUtils.isEmpty(mockScenarioDataList) || CollectionUtils.isEmpty(orderNoList)) {
51
			return "场景" + sId + " 没有配置模拟 ,请在数据库中添加数据再执行...";
52
		}
53
54
		// 记录场景执行状态
55
		MACK_STATUS.put(sId, frequency);
56
		// 异步执行模拟场景 通过IOT-DMP连接服务模拟
61 57
//        mockProcess.processMock(sId,mockScenarioDataList,frequency);
62 58
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 {
59
		Map<Long, List<LocationBean>> dataMap = getMapListData(mockScenarioDataList);
60
61
		// 异步执行模拟场景 直接模拟最终数据发送到kafka
62
		mockProcess.processMockKafka(sId, dataMap, orderNoList, frequency, topic);
63
64
		return "场景" + sId + " 开始执行...";
65
	}
66
67
	@Override
68
	public String stopMackData(Long sId) {
69
		MACK_STATUS.remove(sId);
70
		return "场景" + sId + " 终止执行...";
71
	}
72
73
	/**
74
	      * 按orderNo分组
75
	 * @param mockScenarioDataList
76
	 * @return
77
	 */
78
	private Map<Long, List<LocationBean>> getMapListData(List<MockScenarioData> mockScenarioDataList) {
79
		Map<Long, List<LocationBean>> map = new HashMap<Long, List<LocationBean>>();
80
81
		for (MockScenarioData mockScenarioData : mockScenarioDataList) {
82
			LocationBean locationBean = new LocationBean(mockScenarioData.getDeviceId(),
83
					Double.valueOf(mockScenarioData.getLongitude()), Double.valueOf(mockScenarioData.getLatitude()));
84
			
85
			if (StringUtils.isNotBlank(mockScenarioData.getFloor()))
86
				locationBean.setFloor(Long.valueOf(mockScenarioData.getFloor()));
87
88
			if (StringUtils.isNotBlank(mockScenarioData.getHeight()))
89
				locationBean.setZAxis(Double.valueOf(mockScenarioData.getHeight()));
90
			
91
			long orderNo = mockScenarioData.getOrderNo();
92
93
			List<LocationBean> list = map.get(orderNo);
94
			if (list == null) {
95
				list = new ArrayList<LocationBean>();
96
				list.add(locationBean);
97
				map.put(orderNo, list);
98
			} else {
104 99
				list.add(locationBean);
105 100
			}
106 101
		}
107
    	
108
    	return map;
109
    }
110
    
102
103
		return map;
104
	}
105
106
	@Override
107
	public String sendMsgData(String msg, String topic) {
108
		String result = "";
109
110
		try {
111
			mockProcess.sendKafkaData(topic, msg);
112
			result = "消息发送成功:" + msg;
113
		} catch (Exception e) {
114
			result = "消息发送失败:" + msg + ",原因:" + e.getMessage();
115
		}
116
117
		return result;
118
	}
119
111 120
}

+ 34 - 19
indoor-mock-service/src/main/java/com/ai/bss/mock/service/impl/MockProcessImpl.java

@ -1,8 +1,5 @@
1 1
package com.ai.bss.mock.service.impl;
2 2
3
import java.sql.Timestamp;
4
import java.util.ArrayList;
5
import java.util.Date;
6 3
import java.util.HashMap;
7 4
import java.util.List;
8 5
import java.util.Map;
@ -10,17 +7,14 @@ import java.util.concurrent.ExecutorService;
10 7
import java.util.concurrent.Executors;
11 8
import java.util.concurrent.TimeUnit;
12 9
10
import org.apache.commons.lang3.StringUtils;
13 11
import org.slf4j.Logger;
14 12
import org.slf4j.LoggerFactory;
15 13
import org.springframework.beans.factory.annotation.Value;
16 14
import org.springframework.kafka.core.KafkaTemplate;
17 15
import org.springframework.scheduling.annotation.Async;
18 16
import org.springframework.stereotype.Service;
19
import org.springframework.util.StringUtils;
20 17
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 18
import com.ai.bss.mock.model.LocationBean;
25 19
import com.ai.bss.mock.model.MockScenarioData;
26 20
import com.ai.bss.mock.service.interfaces.MockProcess;
@ -28,7 +22,6 @@ import com.ai.bss.mock.utils.KafkaProducerConfig;
28 22
import com.ai.bss.mock.utils.tcp.IpuTcpLongConnectClient;
29 23
import com.ailk.common.data.impl.DataMap;
30 24
import com.alibaba.fastjson.JSON;
31
import com.alibaba.fastjson.JSONObject;
32 25
33 26
import lombok.extern.slf4j.Slf4j;
34 27
@ -38,17 +31,16 @@ import lombok.extern.slf4j.Slf4j;
38 31
public class MockProcessImpl implements MockProcess {
39 32
	private static final Logger logger = LoggerFactory.getLogger(MockProcessImpl.class);
40 33
41
//    EBC设备tcp连接服务地址
42
    private static final String HOST = "47.105.130.83";
43
    private static final int PORT = 8042;
34
	@Value("${kafka.servers.host}")
35
    private String HOST ;
36
	@Value("${kafka.servers.port}")
37
    private int PORT;
44 38
45
    private static String kafkaServers = "47.105.160.21:9091";
46
47
    @Value("${kafka.producer.servers}")
48
    private static String servers;
39
    @Value("${kafka.bootstrap-servers}")
40
    private String kafkaServers;
49 41
    
50
    @Value("${kafka.producer.topic}")
51
    private String topic;
42
    @Value("${kafka.topic.request}")
43
    private String requestTopic;
52 44
53 45
    @Async
54 46
    @Override
@ -68,10 +60,10 @@ public class MockProcessImpl implements MockProcess {
68 60
    
69 61
    @Async
70 62
    @Override
71
    public void processMockKafka(Long sId,Map<Long, List<LocationBean>> dataMap,List<Long> orderNoList, Long frequency,String topic0,String topic1){
63
    public void processMockKafka(Long sId,Map<Long, List<LocationBean>> dataMap,List<Long> orderNoList, Long frequency,String myTopic){
72 64
    	String clientId="XBG_AC67B2C23CFC";
73 65
		String userName="abc";
74
		topic="uploadInfoTest";
66
		String topic=StringUtils.isNotBlank(myTopic)?myTopic:requestTopic;
75 67
		
76 68
    	try {
77 69
            for (Long orderNo : orderNoList) {
@ -133,4 +125,27 @@ public class MockProcessImpl implements MockProcess {
133 125
		}
134 126
	}
135 127
    
128
    @Async
129
    @Override
130
    public void sendKafkaData(String topic, String msgStr) throws Exception{
131
		KafkaTemplate kafkaTemplate = kafkaTemplateMap.get(kafkaServers);
132
133
		if (kafkaTemplate == null) {
134
			// new 实例
135
			KafkaProducerConfig kafkaProducerConfig = new KafkaProducerConfig(kafkaServers);
136
			kafkaTemplate = kafkaProducerConfig.kafkaTemplate();
137
			kafkaTemplateMap.put(kafkaServers, kafkaTemplate);
138
		}
139
140
		if (kafkaTemplate == null) {
141
			log.error("kafkaTemplate is null");
142
			 throw new RuntimeException("kafkaTemplate is null");
143
		}
144
145
			log.info("发送kafka消息:kafkaServers="+kafkaServers+", topic=" + topic + ", msg=" + msgStr);
146
			kafkaTemplate.send(topic, msgStr);
147
148
			kafkaTemplate.flush();
149
			log.info("发送kafka消息成功");
150
	}
136 151
}

+ 10 - 2
indoor-mock-service/src/main/java/com/ai/bss/mock/service/interfaces/MockManageService.java

@ -8,7 +8,7 @@ public interface MockManageService {
8 8
     * 查询当前正在 的场景
9 9
     * @return
10 10
     */
11
    Map findMockStatusByScenarioId();
11
    Map<Long,String> findMockStatusByScenarioId();
12 12
13 13
    /**
14 14
     * 开始执行模拟数据
@ -16,7 +16,7 @@ public interface MockManageService {
16 16
     * @param f
17 17
     * @return
18 18
     */
19
    String  startMackData(Long sId,  Long f,String topic0,String topic1) ;
19
    String  startMackData(Long sId,  Long f,String topic) ;
20 20
21 21
    /**
22 22
     * 停止执行模拟数据
@ -24,4 +24,12 @@ public interface MockManageService {
24 24
     * @return
25 25
     */
26 26
    String  stopMackData(Long sId);
27
    
28
    /**
29
     * 发送kafka消息
30
     * @param msg
31
     * @param topic
32
     * @return
33
     */
34
    String  sendMsgData(String msg,String topic);
27 35
}

+ 3 - 1
indoor-mock-service/src/main/java/com/ai/bss/mock/service/interfaces/MockProcess.java

@ -10,5 +10,7 @@ public interface MockProcess {
10 10
    void processMock(Long sId,List<MockScenarioData> mockScenarioDataList, Long frequency);
11 11
12 12
13
    void processMockKafka(Long sId,Map<Long, List<LocationBean>> dataMap,List<Long> orderNoList, Long frequency,String topic0,String topic1);
13
    void processMockKafka(Long sId,Map<Long, List<LocationBean>> dataMap,List<Long> orderNoList, Long frequency,String myTopic);
14
15
    void sendKafkaData(String topic, String msgStr) throws Exception;
14 16
}

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

@ -1,6 +1,7 @@
1 1
package com.ai.bss.mock.utils.makedata;
2 2
3 3
import java.sql.Timestamp;
4
import java.util.Date;
4 5
5 6
import com.ai.bss.mock.model.LocationBean;
6 7
import com.alibaba.fastjson.JSON;
@ -13,14 +14,9 @@ public class MakeBluetoothData {
13 14
	 * @param yAxis
14 15
	 */
15 16
	public static String sendBluetoothKafka(double xAxis,double yAxis) {
16
		String clientId="XBG_AC67B2C23CFC";
17
		 String userName="abc";
18
		
19
		 String mac="d3e656a4573d";
17
		 String id="d3e656a4573d";
20 18
		 
21
		 Integer floor=1;
22
		 Timestamp timeStamp=new Timestamp(System.currentTimeMillis());
23
		 LocationBean location=new LocationBean(mac, floor, xAxis, yAxis, timeStamp);
19
		 LocationBean location=new LocationBean(id, xAxis, yAxis);
24 20
		 
25 21
		 String msg=JSON.toJSONString(location);
26 22
		 

+ 48 - 19
indoor-mock-service/src/main/resources/application.properties

@ -1,5 +1,5 @@
1 1
spring.application.name=WorkTaskSpec
2
server.port=8086
2
server.port=8090
3 3
4 4
# DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
5 5
#spring.datasource.url=jdbc:mysql://localhost:3306/cmp
@ -15,10 +15,15 @@ server.port=8086
15 15
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
16 16
#spring.datasource.username=cmp
17 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
18
#spring.datasource.url=jdbc:mysql://10.19.90.34:3307/indoor?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
spring.datasource.url=jdbc:mysql://8.130.50.1:6000/indoor?useUnicode=true&ampcharacterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
19 23
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
20
spring.datasource.username=ebc
21
spring.datasource.password=ebc@123
24
spring.datasource.username=cmp
25
spring.datasource.password=cmp@123
26
22 27
23 28
# JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration)
24 29
#spring.jpa.database=default
@ -41,19 +46,43 @@ logging.level.org.springframework.data=info
41 46
42 47
43 48
#============== 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
49
#kafka.consumer.zookeeper.connect=47.105.160.21:2100
50
#kafka.consumer.servers=47.105.160.21:9090
51
#kafka.consumer.enable.auto.commit=true
52
#kafka.consumer.session.timeout=6000
53
#kafka.consumer.auto.commit.interval=100
54
#kafka.consumer.auto.offset.reset=latest
55
#kafka.consumer.topic=productMessage
56
#kafka.consumer.group.id=productMessage
57
#kafka.consumer.concurrency=10
58
59
#kafka.producer.servers=47.105.160.21:9091
60
#kafka.producer.retries=0
61
#kafka.producer.batch.size=4096
62
#kafka.producer.linger=1
63
#kafka.producer.buffer.memory=40960
64
#kafka.producer.topic=uploadInfoTest1
65
66
kafka.servers.host=8.130.50.1
67
kafka.servers.port=9091
68
kafka.bootstrap-servers=8.130.50.1:9091
69
70
#kafka.topic=bluetoothTopic
71
#kafka.topic=uwbTopic
72
kafka.topic.request=locationTopic
73
74
kafka.producer.batch-size=16785
75
kafka.producer.retries=1
76
kafka.producer.buffer-memory=33554432
57 77
kafka.producer.linger=1
58
kafka.producer.buffer.memory=40960
59
kafka.producer.topic=uploadInfoTest
78
kafka.consumer.auto-offset-reset=latest
79
kafka.consumer.max-poll-records=3100
80
kafka.consumer.enable-auto-commit=false
81
kafka.consumer.auto-commit-interval=1000
82
kafka.consumer.session-timeout=20000
83
kafka.consumer.max-poll-interval=15000
84
kafka.consumer.max-partition-fetch-bytes=15728640
85
kafka.listener.batch-listener=true
86
kafka.listener.concurrencys=3,6
87
kafka.listener.poll-timeout=1500
88