Browse Source

mock工程修改提交

chenxr3 4 years ago
parent
commit
2a254499de

+ 3 - 2
ebc-mock-service/src/main/java/com/ai/bss/mock/MockApp.java

6
import org.springframework.context.annotation.ComponentScan;
6
import org.springframework.context.annotation.ComponentScan;
7
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
7
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
8
import org.springframework.scheduling.annotation.EnableAsync;
8
import org.springframework.scheduling.annotation.EnableAsync;
9
import org.springframework.scheduling.annotation.EnableScheduling;
9
10
10
/**
11
/**
11
 * @author wangdong
12
 * @author wangdong
16
@ComponentScan(basePackages = {"com.ai.bss","com.ai.abc","com.ai.ipu"})
17
@ComponentScan(basePackages = {"com.ai.bss","com.ai.abc","com.ai.ipu"})
17
@EnableAsync
18
@EnableAsync
18
@SpringBootApplication
19
@SpringBootApplication
19
20
@EnableScheduling
20
public class MockApp {
21
public class MockApp {
21
22
22
    public static void main(String[] args) throws Exception {
23
    public static void main(String[] args) throws Exception {
23
        SpringApplication.run(MockApp.class, args);
24
        SpringApplication.run(MockApp.class, args);
24
    }
25
    }
25
}
26
}

+ 6 - 0
ebc-mock-service/src/main/java/com/ai/bss/mock/controller/MockController.java

6
import org.slf4j.Logger;
6
import org.slf4j.Logger;
7
import org.slf4j.LoggerFactory;
7
import org.slf4j.LoggerFactory;
8
import org.springframework.beans.factory.annotation.Autowired;
8
import org.springframework.beans.factory.annotation.Autowired;
9
import org.springframework.scheduling.annotation.Scheduled;
9
import org.springframework.stereotype.Controller;
10
import org.springframework.stereotype.Controller;
10
import org.springframework.web.bind.annotation.RequestMapping;
11
import org.springframework.web.bind.annotation.RequestMapping;
11
import org.springframework.web.bind.annotation.RequestParam;
12
import org.springframework.web.bind.annotation.RequestParam;
43
        return mockManageService.startMackData(sId,f,topic0,topic1);
44
        return mockManageService.startMackData(sId,f,topic0,topic1);
44
    }
45
    }
45
46
47
    @Scheduled(cron = "*/30 * * * * ?")
48
    public void startMackData() {
49
        mockManageService.startMackData();
50
    }
51
46
    /**
52
    /**
47
     * 查询历史轨迹查询
53
     * 查询历史轨迹查询
48
     */
54
     */

+ 43 - 1
ebc-mock-service/src/main/java/com/ai/bss/mock/service/impl/MockManageServiceImpl.java

5
import java.util.List;
5
import java.util.List;
6
import java.util.Map;
6
import java.util.Map;
7
7
8
import org.slf4j.Logger;
9
import org.slf4j.LoggerFactory;
8
import org.springframework.beans.factory.annotation.Autowired;
10
import org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.beans.factory.annotation.Value;
9
import org.springframework.stereotype.Service;
12
import org.springframework.stereotype.Service;
10
13
11
import com.ai.bss.mock.model.MockScenarioData;
14
import com.ai.bss.mock.model.MockScenarioData;
19
@Service
22
@Service
20
public class MockManageServiceImpl implements MockManageService {
23
public class MockManageServiceImpl implements MockManageService {
21
24
25
    private static final Logger logger = LoggerFactory.getLogger(MockManageServiceImpl.class);
26
27
    @Value("${mack.data.sids}")
28
    private String sIds;
29
30
    @Value("${mack.data.frequency}")
31
    private String frequency;
32
22
	protected static Map MACK_STATUS = new HashMap();
33
	protected static Map MACK_STATUS = new HashMap();
23
	
34
24
    @Autowired
35
    @Autowired
25
    private MockScenarioDataRepository mockScenarioDataRepository;
36
    private MockScenarioDataRepository mockScenarioDataRepository;
26
    @Autowired
37
    @Autowired
64
75
65
76
66
    @Override
77
    @Override
78
    public void startMackData()  {
79
        Long fre = Long.valueOf(frequency);
80
        String[] sIdArr = sIds.split(",");
81
        for (int i = 0; i < sIdArr.length; i++) {
82
            Long sId = Long.valueOf(sIdArr[i]);
83
            //        验证场景是否正在执行
84
            if(MACK_STATUS.get(sId)!=null){
85
                logger.error("场景" + sId + " 正在执行,请耐心等待...");
86
                continue;
87
            }
88
            //根据场景ID从数据库中查询模拟数据
89
            List<MockScenarioData>  mockScenarioDataList = mockScenarioDataRepository.findByScenarioIdOrderByOrderNo(sId);
90
91
            List<Long> orderNoList = mockScenarioDataRepository.findByOrderNoByScenarioId(sId);
92
            if(mockScenarioDataList==null || mockScenarioDataList.size()==0){
93
                logger.error("场景" + sId + "没有配置模拟 ,请在数据库中添加数据再执行...");
94
                continue;
95
            }
96
            //记录场景执行状态
97
            MACK_STATUS.put(sId,2);
98
            //异步执行模拟场景 通过IOT-DMP连接服务模拟
99
//        mockProcess.processMock(sId,mockScenarioDataList,frequency);
100
101
            //异步执行模拟场景  直接模拟最终数据发送到kafka
102
            mockProcess.processMockKafka(sId,mockScenarioDataList,orderNoList,fre,null, null);
103
        }
104
105
    }
106
107
108
    @Override
67
    public String  stopMackData(Long sId){
109
    public String  stopMackData(Long sId){
68
        MACK_STATUS.remove(sId);
110
        MACK_STATUS.remove(sId);
69
        return "场景" + sId + " 终止执行...";
111
        return "场景" + sId + " 终止执行...";

+ 2 - 0
ebc-mock-service/src/main/java/com/ai/bss/mock/service/interfaces/MockManageService.java

18
     */
18
     */
19
    String  startMackData(Long sId,  Long f,String topic0,String topic1) ;
19
    String  startMackData(Long sId,  Long f,String topic0,String topic1) ;
20
20
21
    void  startMackData() ;
22
21
    /**
23
    /**
22
     * 停止执行模拟数据
24
     * 停止执行模拟数据
23
     * @param sId
25
     * @param sId

+ 4 - 0
ebc-mock-service/src/main/resources/application.properties

63
kafka.producer.linger=1
63
kafka.producer.linger=1
64
kafka.producer.buffer.memory=40960
64
kafka.producer.buffer.memory=40960
65
kafka.producer.topic=67message
65
kafka.producer.topic=67message
66
67
68
mack.data.sids=22,25,26
69
mack.data.frequency=2