perf: 异步保存rawReport加快速度

dev
huangfeng 11 months ago
parent 9f768a8a18
commit 48d7522555

@ -13,6 +13,7 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@ -22,8 +23,9 @@ import org.springframework.scheduling.annotation.EnableScheduling;
@EnableConfigurationProperties
@ComponentScan(basePackages = {"com.shxy"})
@EnableCaching
@EnableAsync
@EnableScheduling
public class XymanagerAdminApplication extends SpringBootServletInitializer{
public class XymanagerAdminApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
try {
@ -38,8 +40,9 @@ public class XymanagerAdminApplication extends SpringBootServletInitializer{
log.error("error>>>>>>>>>>>>>>>>>>>>>>>>>>>", e);
}
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application){
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(XymanagerAdminApplication.class);
}
}

@ -11,7 +11,7 @@ public class TaskSchedulerConfig {
@Bean
public TaskScheduler taskScheduler() {
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.setPoolSize(5);
scheduler.setPoolSize(10);
return scheduler;
}
}

@ -18,6 +18,7 @@ import com.shxy.xymanager_service.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@ -847,4 +848,17 @@ public class CmdServiceImpl implements CmdService {
cmdsMapper.insert(cmd);
}
}
@Async
@Override
public void addRawReport(Integer termId, String ip, HashMap<String, Object> data) {
String json = JSONUtil.object2Json(data);
MntnRawReports item = new MntnRawReports();
item.setTermId(termId);
item.setContent(json);
item.setIp(ip);
item.setCreateTime(System.currentTimeMillis() / 1000);
rawReportsMapper.insert(item);
}
}

@ -5,6 +5,7 @@ import com.shxy.xymanager_common.entity.*;
import com.shxy.xymanager_common.exception.ApiException;
import com.shxy.xymanager_common.util.JSONUtil;
import com.shxy.xymanager_dao.dao.*;
import com.shxy.xymanager_service.service.CmdService;
import com.shxy.xymanager_service.service.TerminalExtService;
import com.shxy.xymanager_service.service.MntnService;
import lombok.extern.slf4j.Slf4j;
@ -30,11 +31,11 @@ public class MntnServiceImpl implements MntnService {
@Resource
MntnStatusMapper statusMapper;
@Resource
MntnRawReportsMapper rawReportsMapper;
@Resource
TerminalExtService terminalExtService;
@Resource
MntnCmdResultsMapper resultsMapper;
@Resource
CmdService cmdService;
@Override
public HashMap<String, Object> sync(String cmdid, String ip, String multi, HashMap<String, Object> data) throws Exception {
@ -43,7 +44,7 @@ public class MntnServiceImpl implements MntnService {
throw new ApiException("该装置不存在");
}
this.insertReport(term.getId(), ip, data);
cmdService.addRawReport(term.getId(), ip, data);
MntnStatus status = statusMapper.selectByPrimaryKey(term.getId());
@ -118,16 +119,6 @@ public class MntnServiceImpl implements MntnService {
return result;
}
private void insertReport(Integer termId, String ip, HashMap<String, Object> data) {
String json = JSONUtil.object2Json(data);
MntnRawReports item = new MntnRawReports();
item.setTermId(termId);
item.setContent(json);
item.setIp(ip);
item.setCreateTime(System.currentTimeMillis() / 1000);
rawReportsMapper.insert(item);
}
private void moveToHistory(MntnCmds cmd) {
MntnCmdHistory history = new MntnCmdHistory();
history.setId(cmd.getId());

@ -6,6 +6,8 @@ import com.shxy.xymanager_common.entity.MntnCmdHistory;
import com.shxy.xymanager_common.entity.MntnCmds;
import com.shxy.xymanager_common.model.CmdModel;
import java.util.HashMap;
public interface CmdService {
@ -16,4 +18,6 @@ public interface CmdService {
Integer pageNum, Integer pageSize);
void send(CmdModel model) throws Exception;
void addRawReport(Integer termId, String ip, HashMap<String, Object> data);
}

Loading…
Cancel
Save