服务端的请求计算接口

dev-active
lensfrex 2 years ago
parent 17f90ce524
commit cdba2e4a76
Signed by: lensfrex
GPG Key ID: 0F69A0A2FBEE98A0
  1. 13
      dscape-cache/src/main/java/net/lensfrex/dscape/cache/UserBasicCache.java
  2. 18
      dscape-compute/pom.xml
  3. 13
      dscape-compute/src/main/java/net/lensfrex/dscape/ComputeMain.java
  4. 2
      dscape-dao/src/main/java/net/lensfrex/dscape/dao/service/ComputeHistoryService.java
  5. 3
      dscape-dao/src/main/java/net/lensfrex/dscape/dao/service/PatientDataService.java
  6. 6
      dscape-dao/src/main/java/net/lensfrex/dscape/dao/service/impl/ComputeHistoryServiceImpl.java
  7. 7
      dscape-dao/src/main/java/net/lensfrex/dscape/dao/service/impl/PatientDataServiceImpl.java
  8. 9
      dscape-entities/pom.xml
  9. 7
      dscape-entities/src/main/java/net/lensfrex/dscape/dao/entity/ComputeHistory.java
  10. 6
      dscape-entities/src/main/java/net/lensfrex/dscape/dao/entity/PatientData.java
  11. 10
      dscape-entities/src/main/java/net/lensfrex/dscape/dto/request/compute/ComputeRequestBody.java
  12. 8
      dscape-entities/src/main/java/net/lensfrex/dscape/dto/response/data/compute/ComputeHistoryResponseData.java
  13. 10
      dscape-entities/src/main/java/net/lensfrex/dscape/dto/response/data/compute/ComputeResponseData.java
  14. 24
      dscape-entities/src/main/java/net/lensfrex/dscape/enums/compute/ComputeStatusEnum.java
  15. 24
      dscape-web/message-queue/pom.xml
  16. 29
      dscape-web/pom.xml
  17. 10
      dscape-web/src/main/java/net/lensfrex/dscape/ServerMain.java
  18. 22
      dscape-web/src/main/java/net/lensfrex/dscape/configure/RabbitConfigure.java
  19. 5
      dscape-web/src/main/java/net/lensfrex/dscape/mq/MessageQueueProducer.java
  20. 21
      dscape-web/src/main/java/net/lensfrex/dscape/web/controllers/compute/ComputeController.java
  21. 64
      dscape-web/src/main/java/net/lensfrex/dscape/web/service/compute/ComputeService.java
  22. 2
      dscape-web/src/main/java/net/lensfrex/dscape/web/service/data/HistoryService.java

@ -10,6 +10,10 @@
* Class created by lensfrex.
*/
/*
* Class created by lensfrex.
*/
package net.lensfrex.dscape.cache;
import net.lensfrex.dscape.configure.GlobalConstant;
@ -27,12 +31,9 @@ public class UserBasicCache {
private static final String USERNAME_UID_CACHE_KEY = GlobalConstant.USERNAME_UID_CACHE_KEY;
private final ObjectJsonSerializer objectJsonSerializer;
private final RedisTemplate<String, String> redis;
public UserBasicCache(ObjectJsonSerializer objectJsonSerializer, RedisTemplate<String, String> redis) {
this.objectJsonSerializer = objectJsonSerializer;
public UserBasicCache(RedisTemplate<String, String> redis) {
this.redis = redis;
}
@ -40,7 +41,7 @@ public class UserBasicCache {
try {
String cacheData = (String) redis.opsForHash().get(USER_INFO_CACHE_KEY, uid);
if (cacheData != null) {
return objectJsonSerializer.deserialize(cacheData, UserBasic.class);
return ObjectJsonSerializer.deserialize(cacheData, UserBasic.class);
} else {
log.debug("缓存中没有用户信息");
return null;
@ -69,7 +70,7 @@ public class UserBasicCache {
}
public void save(UserBasic userBasic) {
redis.opsForHash().put(USER_INFO_CACHE_KEY, userBasic.getUid(), objectJsonSerializer.serialize(userBasic));
redis.opsForHash().put(USER_INFO_CACHE_KEY, userBasic.getUid(), ObjectJsonSerializer.serialize(userBasic));
redis.opsForHash().put(USERNAME_UID_CACHE_KEY, userBasic.getUserName(), userBasic.getUid());
}

@ -24,5 +24,23 @@
<artifactId>dscape-dao</artifactId>
<version>0.0.1-dev</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.yannrichet/Rsession -->
<dependency>
<groupId>com.github.yannrichet</groupId>
<artifactId>Rsession</artifactId>
<version>3.1.6</version>
<exclusions>
<exclusion>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>

@ -0,0 +1,13 @@
/*
* Class created by lensfrex.
*/
package net.lensfrex.dscape;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan("net.lensfrex.dscape.dao.mapper")
public class ComputeMain {
}

@ -26,7 +26,7 @@ public interface ComputeHistoryService extends IService<ComputeHistory> {
List<ComputeHistory> getHistory(String uid, int page, int limit);
List<Long> getHistoryIds(String uid, int page, int limit);
List<Long> getHistoryDataIds(String uid, int page, int limit);
boolean remove(Long id);

@ -12,6 +12,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import net.lensfrex.dscape.dao.entity.PatientData;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List;
/**
@ -21,7 +22,7 @@ import java.util.List;
*/
@Service
public interface PatientDataService extends IService<PatientData> {
List<PatientData> getData(List<Long> ids);
List<PatientData> getData(Collection<Long> ids);
PatientData getData(Long id);

@ -45,7 +45,7 @@ public class ComputeHistoryServiceImpl extends ServiceImpl<ComputeHistoryMapper,
}
@Override
public List<Long> getHistoryIds(String uid, int page, int limit) {
public List<Long> getHistoryDataIds(String uid, int page, int limit) {
QueryWrapper<ComputeHistory> wrapper = new QueryWrapper<>();
wrapper.lambda()
.select(ComputeHistory::getRid)
@ -60,10 +60,10 @@ public class ComputeHistoryServiceImpl extends ServiceImpl<ComputeHistoryMapper,
}
@Override
public boolean remove(Long id) {
public boolean remove(Long rid) {
QueryWrapper<ComputeHistory> wrapper = new QueryWrapper<>();
wrapper.lambda()
.eq(ComputeHistory::getRid, id);
.eq(ComputeHistory::getRid, rid);
return this.remove(wrapper);
}

@ -20,12 +20,13 @@ import net.lensfrex.dscape.dao.mapper.PatientDataMapper;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@Service
public class PatientDataServiceImpl extends ServiceImpl<PatientDataMapper, PatientData> implements PatientDataService {
@Override
public List<PatientData> getData(List<Long> ids) {
public List<PatientData> getData(Collection<Long> ids) {
if (ids == null || ids.isEmpty()) {
return new ArrayList<>();
}
@ -39,10 +40,10 @@ public class PatientDataServiceImpl extends ServiceImpl<PatientDataMapper, Patie
}
@Override
public PatientData getData(Long id) {
public PatientData getData(Long rid) {
QueryWrapper<PatientData> wrapper = new QueryWrapper<>();
wrapper.lambda()
.eq(PatientData::getId, id);
.eq(PatientData::getId, rid);
return this.getOne(wrapper);
}

@ -28,6 +28,15 @@
<version>3.5.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
</dependencies>
<build>

@ -1,7 +1,12 @@
/*
* Class created by lensfrex.
*/
package net.lensfrex.dscape.dao.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.io.Serializable;
@ -21,7 +26,7 @@ public class ComputeHistory implements Serializable {
/**
* id
*/
private Integer id;
private Long id;
/**
* 计算数据记录对应的用户uid

@ -6,11 +6,16 @@
* Class created by lensfrex.
*/
/*
* Class created by lensfrex.
*/
package net.lensfrex.dscape.dao.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
@ -40,6 +45,7 @@ public class PatientData implements Serializable {
/**
* ctdna长度
*/
private Integer ctdnaLength;
/**

@ -0,0 +1,10 @@
package net.lensfrex.dscape.dto.request.compute;
import lombok.Data;
@Data
public class ComputeRequestBody{
private int pid;
private int cpg;
private int ctdna;
}

@ -10,6 +10,10 @@
* Class created by lensfrex.
*/
/*
* Class created by lensfrex.
*/
package net.lensfrex.dscape.dto.response.data.compute;
import com.fasterxml.jackson.annotation.JsonProperty;
@ -17,6 +21,8 @@ import lombok.Data;
@Data
public class ComputeHistoryResponseData {
private long id;
private long cpg;
private long ctdna;
@ -26,8 +32,6 @@ public class ComputeHistoryResponseData {
@JsonProperty("hcc_infer")
private Boolean hccInfer;
private long id;
private long pid;
private String time;

@ -0,0 +1,10 @@
package net.lensfrex.dscape.dto.response.data.compute;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class ComputeResponseData{
private Long id;
}

@ -0,0 +1,24 @@
/*
* Class created by lensfrex.
*/
package net.lensfrex.dscape.enums.compute;
import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.Data;
import lombok.Getter;
@Getter
public enum ComputeStatusEnum {
FINISHED(0, "完成"),
PROCESSING(1, "处理中");
@EnumValue
private final int code;
private final String name;
ComputeStatusEnum(int code, String name) {
this.code = code;
this.name = name;
}
}

@ -1,24 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Class created by lensfrex.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>dscape-web</artifactId>
<groupId>net.lensfrex</groupId>
<version>0.0.1-dev</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>message-queue</artifactId>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

@ -9,10 +9,6 @@
<version>0.0.1-dev</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<modules>
<module>message-queue</module>
</modules>
<artifactId>dscape-web</artifactId>
<description>dscape后端主服务</description>
@ -43,11 +39,6 @@
<artifactId>dscape-utils</artifactId>
<version>0.0.1-dev</version>
</dependency>
<dependency>
<groupId>net.lensfrex</groupId>
<artifactId>message-queue</artifactId>
<version>0.0.1-dev</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@ -74,12 +65,6 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
@ -116,6 +101,20 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!-- 雪花id算法生成库(改进过的) -->
<dependency>
<groupId>com.github.yitter</groupId>
<artifactId>yitter-idgenerator</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
<version>2.7.3</version>
</dependency>
</dependencies>
<build>

@ -4,16 +4,26 @@
package net.lensfrex.dscape;
import com.github.yitter.contract.IdGeneratorOptions;
import com.github.yitter.idgen.YitIdHelper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import java.util.TimeZone;
@SpringBootApplication
@MapperScan("net.lensfrex.dscape.dao.mapper")
public class ServerMain extends SpringBootServletInitializer {
public static void main(String[] args) {
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
IdGeneratorOptions options = new IdGeneratorOptions((short) 12);
options.WorkerIdBitLength = 4;
YitIdHelper.setIdGenerator(options);
SpringApplication.run(ServerMain.class, args);
}
}

@ -2,6 +2,14 @@
* Class created by lensfrex.
*/
/*
* Class created by lensfrex.
*/
/*
* Class created by lensfrex.
*/
package net.lensfrex.dscape.configure;
import org.springframework.amqp.core.Binding;
@ -12,16 +20,22 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class RabbitMqConfigure {
public class RabbitConfigure {
public static final String QUEUE_NAME = "net.lensfrex.dscape.mq.queue";
public static final String EXCHANGE_NAME = "net.lensfrex.dscape.mq.exchange";
public static final String ROUTING_KEY = "net.lensfrex.dscape.mq.routing";
@Bean
public Queue queue() {
return new Queue("dscape-compute-queue", true, false, false);
return new Queue(QUEUE_NAME, true, false, false);
}
@Bean
public DirectExchange directExchange() {
return new DirectExchange("dscape-compute-exchange", true, false);
return new DirectExchange(EXCHANGE_NAME, true, false);
}
@Bean
@ -29,6 +43,6 @@ public class RabbitMqConfigure {
return BindingBuilder
.bind(this.queue())
.to(this.directExchange())
.with("dscape-compute");
.with(ROUTING_KEY);
}
}

@ -4,9 +4,12 @@
package net.lensfrex.dscape.mq;
import lombok.extern.slf4j.Slf4j;
import net.lensfrex.dscape.configure.RabbitConfigure;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class MessageQueueProducer {
private final RabbitTemplate rabbit;
@ -16,6 +19,6 @@ public class MessageQueueProducer {
}
public void sendObject(Object data) {
rabbit.convertAndSend(data);
rabbit.convertAndSend(RabbitConfigure.EXCHANGE_NAME, RabbitConfigure.ROUTING_KEY, data);
}
}

@ -16,24 +16,35 @@
package net.lensfrex.dscape.web.controllers.compute;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.annotation.SaCheckLogin;
import net.lensfrex.dscape.dto.request.compute.ComputeRequestBody;
import net.lensfrex.dscape.dto.response.data.compute.ComputeResponseData;
import net.lensfrex.dscape.dto.response.general.Response;
import net.lensfrex.dscape.dto.response.general.ResponseCode;
import net.lensfrex.dscape.web.service.compute.ComputeService;
import org.springframework.web.bind.annotation.*;
@SaCheckLogin
@RestController
@RequestMapping("/compute")
public class ComputeController {
private final ComputeService computeService;
public ComputeController(ComputeService computeService) {
this.computeService = computeService;
}
@GetMapping(value = "/status/{tid}", produces = "application/json")
public Response status(@PathVariable String tid,
@RequestHeader String token) {
StpUtil.hasPermission("jsejdjjd");
return Response.error(ResponseCode.API_NOT_IMPLEMENT);
}
@PostMapping(value = "/add", produces = "application/json")
public Response addComputeTask(@RequestBody String body,
@RequestHeader String token) {
return Response.error(ResponseCode.API_NOT_IMPLEMENT);
public Response<ComputeResponseData> addComputeTask(@RequestBody ComputeRequestBody request) {
long rid = computeService.addTask(request);
return Response.success(new ComputeResponseData(rid));
}
}

@ -0,0 +1,64 @@
/*
* Class created by lensfrex.
*/
package net.lensfrex.dscape.web.service.compute;
import cn.dev33.satoken.stp.StpUtil;
import com.github.yitter.idgen.YitIdHelper;
import net.lensfrex.dscape.configure.RabbitConfigure;
import net.lensfrex.dscape.dao.entity.ComputeHistory;
import net.lensfrex.dscape.dao.entity.PatientData;
import net.lensfrex.dscape.dao.service.ComputeHistoryService;
import net.lensfrex.dscape.dao.service.PatientDataService;
import net.lensfrex.dscape.dto.request.compute.ComputeRequestBody;
import net.lensfrex.dscape.enums.compute.ComputeStatusEnum;
import net.lensfrex.dscape.mq.MessageQueueProducer;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class ComputeService {
private final PatientDataService patientDataService;
private final ComputeHistoryService computeHistoryService;
private final MessageQueueProducer messageQueueProducer;
public ComputeService(PatientDataService patientDataService,
ComputeHistoryService computeHistoryService,
MessageQueueProducer messageQueueProducer) {
this.patientDataService = patientDataService;
this.computeHistoryService = computeHistoryService;
this.messageQueueProducer = messageQueueProducer;
}
@Transactional
public long addTask(ComputeRequestBody request) {
long rid = YitIdHelper.nextId();
String uid = StpUtil.getLoginIdAsString();
ComputeHistory computeHistory = new ComputeHistory();
computeHistory.setUid(uid);
computeHistory.setRid(rid);
computeHistory.setStatus(ComputeStatusEnum.PROCESSING.getCode());
PatientData patientData = new PatientData();
patientData.setId(rid);
patientData.setCpg(request.getCpg());
patientData.setPid(request.getPid());
patientData.setCtdnaLength(request.getCtdna());
computeHistoryService.save(computeHistory);
patientDataService.save(patientData);
this.addMessageQueue(patientData);
return rid;
}
private void addMessageQueue(PatientData patientData) {
messageQueueProducer.sendObject(patientData);
}
}

@ -45,7 +45,7 @@ public class HistoryService {
}
public List<Long> getUserHistoryId(String uid, int page, int limit) {
return computeHistoryService.getHistoryIds(uid, page, limit);
return computeHistoryService.getHistoryDataIds(uid, page, limit);
}
public List<PatientData> getUserHistoryData(String uid, int page, int limit) {

Loading…
Cancel
Save