Commit 2b37ca2a by zhu.zewen

修复Excel解析

parent c8e54fb7
...@@ -13,10 +13,7 @@ import com.jmai.physic.vo.PhysicRecordVO; ...@@ -13,10 +13,7 @@ import com.jmai.physic.vo.PhysicRecordVO;
import com.jmai.physic.vo.PhysicVO; import com.jmai.physic.vo.PhysicVO;
import com.jmai.sys.AbstractService; import com.jmai.sys.AbstractService;
import com.jmai.sys.aop.Auth; import com.jmai.sys.aop.Auth;
import com.jmai.sys.doc.importer.DefaultImporter; import com.jmai.sys.doc.importer.*;
import com.jmai.sys.doc.importer.ImportField;
import com.jmai.sys.doc.importer.ImportItemBatchHandler;
import com.jmai.sys.doc.importer.ImportResult;
import com.jmai.sys.dto.ResponseData; import com.jmai.sys.dto.ResponseData;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -80,6 +77,31 @@ public class PhysicRecordController extends AbstractService { ...@@ -80,6 +77,31 @@ public class PhysicRecordController extends AbstractService {
new ImportField("diseaseName", "*疾病名称", true, false) new ImportField("diseaseName", "*疾病名称", true, false)
); );
private static final PrescriptionConverter PRESCRIPTION_CONVERTER = new PrescriptionConverter();
private static class PrescriptionConverter extends DefaultImportConverter<PrescriptionDTO> {
public PrescriptionConverter() {
super(PrescriptionDTO.class);
}
@Override
public PrescriptionDTO convert(Map<String, Object> item) {
String sex = (String) item.remove("sickSex");
if (ObjectUtil.isNotEmpty(sex)) {
// 1 - 男、2 - 女、0 - 其他
sex = ObjectUtil.equals(sex, "男") ? "1" :
ObjectUtil.equals(sex, "女") ? "2" :
"0";
item.put("sickSex", sex);
}
PrescriptionDTO prescription = new PrescriptionDTO();
copyTo(item, prescription);
return prescription;
}
}
@ApiOperation("解析处方(患者)信息") @ApiOperation("解析处方(患者)信息")
@PostMapping("/parsePrescription") @PostMapping("/parsePrescription")
public ResponseData<Collection<PrescriptionDTO>> parsePrescription(@RequestParam(value = "file") MultipartFile file) { public ResponseData<Collection<PrescriptionDTO>> parsePrescription(@RequestParam(value = "file") MultipartFile file) {
...@@ -88,19 +110,16 @@ public class PhysicRecordController extends AbstractService { ...@@ -88,19 +110,16 @@ public class PhysicRecordController extends AbstractService {
ConcurrentLinkedQueue<PrescriptionDTO> prescriptions = new ConcurrentLinkedQueue<>(); ConcurrentLinkedQueue<PrescriptionDTO> prescriptions = new ConcurrentLinkedQueue<>();
ImportItemBatchHandler<PrescriptionDTO> itemBatchHandler = items -> { ImportItemBatchHandler<PrescriptionDTO> itemBatchHandler = items -> {
prescriptions.addAll(items); prescriptions.addAll(items);
return items.stream() return Collections.emptyMap();
.collect(Collectors.toMap(
PrescriptionDTO::getPrescriptionNumber,
e -> ""
));
}; };
DefaultImporter<PrescriptionDTO> importer = new DefaultImporter<>(bizKey, DefaultImporter<PrescriptionDTO> importer = new DefaultImporter<>(bizKey,
PrescriptionDTO.class, PRESCRIPTION_FIELDS, itemBatchHandler, file, ac); PrescriptionDTO.class, PRESCRIPTION_FIELDS, PRESCRIPTION_CONVERTER, itemBatchHandler, file, ac);
ImportResult result = execWithLock(bizKey, importer::run); ImportResult result = execWithLock(bizKey, importer::run);
if (ObjectUtil.equals(result.getStat().getSuccessNum().get(), result.getStat().getTotalNum().get())) { if (ObjectUtil.equals(result.getStat().getSuccessNum().get(), result.getStat().getTotalNum().get())) {
// 成功 // 成功
log.debug("解析结果:result={},prescriptions={}", toJSONString(result), toJSONString(prescriptions));
return ResponseData.ok(prescriptions); return ResponseData.ok(prescriptions);
} else { } else {
throw new ServiceException("解析失败:" + toJSONString(result)); throw new ServiceException("解析失败:" + toJSONString(result));
......
...@@ -106,6 +106,32 @@ public class DefaultImporter<T> extends ExcelImporter<Map, String> { ...@@ -106,6 +106,32 @@ public class DefaultImporter<T> extends ExcelImporter<Map, String> {
String bizKey, String bizKey,
Class<T> itemType, Class<T> itemType,
List<ImportField> itemFields, List<ImportField> itemFields,
DefaultImportConverter<T> itemConverter,
ImportItemBatchHandler<T> itemBatchHandler,
MultipartFile importFile,
ApplicationContext ac) {
super(Map.class);
this.bizKey = bizKey;
this.importFile = importFile;
this.itemFields = new ArrayList<>(itemFields.size() + 1);
this.itemFields.addAll(itemFields);
this.itemFields.add(new ImportField(RESULT_FIELD_CODE, RESULT_FIELD_NAME, false, false));
this.itemConverter = itemConverter;
this.itemHandler = null;
this.itemBatchHandler = itemBatchHandler;
checkInit();
// 自动装载依赖
ac.getAutowireCapableBeanFactory().autowireBean(this);
}
public DefaultImporter(
String bizKey,
Class<T> itemType,
List<ImportField> itemFields,
ImportItemBatchHandler<T> itemBatchHandler, ImportItemBatchHandler<T> itemBatchHandler,
MultipartFile importFile, MultipartFile importFile,
ApplicationContext ac) { ApplicationContext ac) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment