提交 a2093f05 authored 作者: 孙洁清's avatar 孙洁清

df

上级 da9becd6
package com.zjty.autotest.config;
import com.zjty.autotest.mq.PushBlockQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
@Component
public class ProjectInitRun implements CommandLineRunner {
@Autowired
private PushBlockQueue pushBlockQueue;
@Override
public void run(String... args) throws Exception {
pushBlockQueue.start();
}
}
......@@ -42,6 +42,7 @@ public class AutoResultSetController {
public ResponseResult delete(@PathVariable String id ){
return autoResultSetService.deleteByid(id);
}
@ApiOperation("新增")
@RequestMapping(method=RequestMethod.POST)
public ResponseResult add(@RequestBody TestChannel testChannel ){
......
......@@ -5,9 +5,10 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
public interface AutoResultSetDao extends JpaRepository<AutoResultSet,String>, JpaSpecificationExecutor<AutoResultSet> {
@Modifying
@Query("update AutoResultSet set status=1 where id=:id")
int updateStatus(String id);
int updateStatus(@Param("id") String id);
}
......@@ -5,6 +5,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
/**
* 数据访问接口
......@@ -13,12 +14,12 @@ import org.springframework.data.jpa.repository.Query;
*/
public interface TestReportDao extends JpaRepository<TestReport,String>, JpaSpecificationExecutor<TestReport> {
@Query(value = "SELECT input_report FROM test_report WHERE result_id = :resultId",nativeQuery = true)
String findByInResultId(String resultId);
String findByInResultId(@Param("resultId") String resultId);
@Query(value = "select out_report from test_report where result_id =:resultId",nativeQuery = true)
String findByOutResultId(String resultId);
String findByOutResultId(@Param("resultId") String resultId);
@Query(value = "select * from test_report where result_id=:resultId",nativeQuery = true)
TestReport findByResultId(String resultId);
TestReport findByResultId(@Param("resultId") String resultId);
@Modifying
int deleteByResultId(String resultId);
int deleteByResultId(@Param("resultId") String resultId);
}
......@@ -2,6 +2,7 @@ package com.zjty.autotest.mq;
import com.alibaba.fastjson.JSON;
import com.zjty.autotest.pojo.sjq.*;
import com.zjty.autotest.service.AsyncService;
import com.zjty.autotest.service.AutoResultSetService;
import com.zjty.autotest.service.TestReportService;
import com.zjty.autotest.util.TimeUtil;
......@@ -17,13 +18,7 @@ import java.util.List;
@Component
public class PushBlockQueueHandler implements Runnable {
@Autowired
private TestReportService testReportService;
@Autowired
private AutoResultSetService autoResultSetService;
@PostConstruct
public void init(){
new Thread(this).start();
}
private AsyncService asyncService;
//消费的对象
private Object obj;
......@@ -37,12 +32,12 @@ public class PushBlockQueueHandler implements Runnable {
//消费线程
@Override
public void run() {
doBusiness();
// doBusiness();
}
//消费行为
private void doBusiness() {
String id = (String) obj;
/* String id = (String) obj;
System.out.println("id:" + id);
TestChannel testChannel = (TestChannel) CacheManager.getCache(id);
if (testChannel != null) {
......@@ -123,7 +118,7 @@ public class PushBlockQueueHandler implements Runnable {
e.printStackTrace();
}
}
}*/
System.out.println(Thread.currentThread().getName() + "-收到消息:" + obj);
}
}
......@@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.beans.Transient;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -22,6 +23,8 @@ public class AsyncServiceImpl implements AsyncService {
private TestReportService testReportService;
@Override
@Async("asyncServiceExecutor")
@Transient
public void executeAsync(String id) {
System.out.println("id:" + id);
TestChannel testChannel = (TestChannel) CacheManager.getCache(id);
......
......@@ -22,10 +22,12 @@ import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import javax.persistence.RollbackException;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.beans.Transient;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -36,7 +38,7 @@ public class AutoResultSetServiceImpl implements AutoResultSetService {
@Autowired
private AutoResultSetDao autoResultSetDao;
@Autowired
private PushBlockQueue pushBlockQueue;
private AsyncService asyncService;
@Autowired
private TestReportService testReportService;
@Autowired
......@@ -69,7 +71,7 @@ public class AutoResultSetServiceImpl implements AutoResultSetService {
}
@Transient
@Override
public ResponseResult deleteByid(String id) {
try {
......@@ -81,7 +83,7 @@ public class AutoResultSetServiceImpl implements AutoResultSetService {
return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
}
@Transient
@Override
public ResponseResult updateByid(String id) {
int i = autoResultSetDao.updateStatus(id);
......@@ -90,7 +92,7 @@ public class AutoResultSetServiceImpl implements AutoResultSetService {
}
return ResponseResult.errorResult(AppHttpCodeEnum.UPDATE_ERROR);
}
@Transient
@Override
public ResponseResult addResultSet(TestChannel testChannel) {
String tid=idWorker.nextId()+"";
......@@ -106,7 +108,7 @@ public class AutoResultSetServiceImpl implements AutoResultSetService {
CacheManager.putCache(tid,testChannel);
//将数据保存到队列
try {
pushBlockQueue.put(tid);
asyncService.executeAsync(tid);
// PushBlockQueue.getInstance().put(tid);
return ResponseResult.okResult(save);
} catch (Exception e) {
......
package com.zjty.autotest.service.impl;
import java.beans.Transient;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -63,11 +64,12 @@ public class TestReportServiceImpl implements TestReportService {
* 增加
* @param testReport
*/
@Transient
public void add(TestReport testReport) {
testReport.setId( idWorker.nextId()+"" );
testReportDao.save(testReport);
}
@Transient
/**
* 修改
* @param testReport
......@@ -80,11 +82,12 @@ public class TestReportServiceImpl implements TestReportService {
* 删除
* @param resultId
*/
@Transient
public ResponseResult deleteByResultId(String resultId) {
int i = testReportDao.deleteByResultId(resultId);
return ResponseResult.okResult(i);
}
@Transient
@Override
public ResponseResult save(TestReport testReport) {
System.out.println(testReport);
......@@ -98,7 +101,7 @@ public class TestReportServiceImpl implements TestReportService {
}
return ResponseResult.errorResult(AppHttpCodeEnum.ERROR);
}
@Transient
@Override
public ResponseResult addInReport(String id, String inReport) {
TestReport testReport=new TestReport();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论