精准医疗基因、方剂

This commit is contained in:
wuchunlei
2025-06-04 17:09:45 +08:00
parent 8dfd150e2c
commit 6852c64984
10 changed files with 426 additions and 0 deletions

View File

@@ -0,0 +1,101 @@
package com.peanut.modules.taihumed.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.peanut.common.utils.R;
import com.peanut.modules.common.entity.PrecisionMedicineGene;
import com.peanut.modules.common.service.PrecisionMedicineGeneService;
import com.peanut.modules.common.service.PrecisionMedicinePrescriptionService;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.*;
@Slf4j
@RestController("taihumedPrecisionMedicine")
@RequestMapping("taihumed/precisionMedicine")
public class PrecisionMedicineController {
@Autowired
private PrecisionMedicineGeneService geneService;
@Autowired
private PrecisionMedicinePrescriptionService prescriptionService;
@RequestMapping("/getPrecisionMedicineGenes")
public R getPrecisionMedicineGenes(@RequestBody Map<String,Object> params){
List<PrecisionMedicineGene> genes = geneService.list(new LambdaQueryWrapper<PrecisionMedicineGene>()
.and(t->t.like(PrecisionMedicineGene::getName,params.get("name"))
.or().like(PrecisionMedicineGene::getAlias,params.get("name"))));
return R.ok().put("genes",genes);
}
@RequestMapping("/getGenes")
public void getPrescriptions(HttpServletResponse response){
List<PrecisionMedicineGene> genes = geneService.list();
XSSFWorkbook wb = new XSSFWorkbook();
//创建一张表
Sheet sheet = wb.createSheet("Student");
//创建第一行起始为0
Row titleRow = sheet.createRow(0);
titleRow.createCell(0).setCellValue("基因名称");
titleRow.createCell(1).setCellValue("基因中文名");
titleRow.createCell(2).setCellValue("描述");
titleRow.createCell(3).setCellValue("关联药材名");
titleRow.createCell(4).setCellValue("关联方剂");
//序号默认为1
int cell = 1;
//遍历
for (PrecisionMedicineGene gene:genes){
Map<String,Object> geneInfo = geneService.getGeneInfo(gene.getId().toString());
List<Map<String,Object>> prescriptionList = (List<Map<String, Object>>) geneInfo.get("prescriptionList");
String prescriptionStr = "";
for (Map<String, Object> prescription:prescriptionList) {
prescriptionStr+="匹配方剂:"+prescription.get("name")+",方剂组成:"+prescription.get("compose")+"出处:"+prescription.get("source")+";";
}
Row row = sheet.createRow(cell);
row.createCell(0).setCellValue(gene.getName());
row.createCell(1).setCellValue(gene.getNamecn());
row.createCell(2).setCellValue(gene.getDescription());
row.createCell(3).setCellValue(gene.getTcmName());
row.createCell(4).setCellValue(prescriptionStr);
//序号自增
cell++;
}
String fileName = "基因药材方剂.xlsx";
OutputStream outputStream =null;
try {
//文件名编码格式
fileName = URLEncoder.encode(fileName,"UTF-8");
//设置ContentType请求信息格式
response.setContentType("application/vnd.ms-excel");
//设置标头
response.setHeader("Content-disposition", "attachment;filename=" + fileName);
outputStream = response.getOutputStream();
wb.write(outputStream);
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
outputStream.flush();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
// return R.ok().put("genes",genes);
}
}