parent
17f90ce524
commit
cdba2e4a76
@ -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 { |
||||||
|
} |
@ -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; |
||||||
|
} |
@ -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> |
|
@ -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); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue