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

df

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