|
@@ -1,9 +1,11 @@
|
|
|
package com.github.jfcloud.gene.lis.service;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.db.Entity;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.github.jfcloud.gene.lis.config.LisDb;
|
|
|
import com.github.jfcloud.gene.lis.entity.HtScienceApply;
|
|
@@ -57,9 +59,10 @@ public class LisSyncService {
|
|
|
Assert.isFalse(extObj.containsKey("lisId"), "同步LIS失败,已同步过");
|
|
|
}
|
|
|
|
|
|
- SampleInfo sampleInfo = sampleInfoMapper.selectById(sampleId);
|
|
|
+ log.info("开始同步lis数据库 sample={}", sampleId);
|
|
|
|
|
|
//HT_SCIENCE_APPLY主键非自增,为年份2位+月份2位+日期2位+483+7位序列号,为了避免冲突,这里使用480
|
|
|
+ SampleInfo sampleInfo = sampleInfoMapper.selectById(sampleId);
|
|
|
String idPrefix = sampleInfo.getApplyTime().format(DateTimeFormatter.ofPattern("yyMMdd")) + "480";
|
|
|
long firstId = Long.parseLong(String.format("%s%07d", idPrefix, 1));
|
|
|
long itemFirstId = Long.parseLong(String.valueOf(firstId).replace("480", "481"));
|
|
@@ -75,6 +78,7 @@ public class LisSyncService {
|
|
|
String[] split = sampleNo.split("-");
|
|
|
beginNo = Integer.parseInt(split[2]) + 1;
|
|
|
}
|
|
|
+ log.info("同步lis数据库 HT_SCIENCE_APPLY起始id={} HT_SCIENCE_APPLY_ITEM起始id={} ", firstId, itemFirstId);
|
|
|
|
|
|
//查询当天的样本编号
|
|
|
String noPrefix = "HKYBKY" + sampleInfo.getApplyTime().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
|
@@ -149,6 +153,8 @@ public class LisSyncService {
|
|
|
co.setId(checkOrder.getId());
|
|
|
co.setExtData(finalExtObj.toString());
|
|
|
co.updateById();
|
|
|
+
|
|
|
+ log.info("同步lis数据库完成 sampleId={} ", sampleId);
|
|
|
} catch (Exception e) {
|
|
|
log.error("同步LIS失败", e);
|
|
|
}
|
|
@@ -159,6 +165,28 @@ public class LisSyncService {
|
|
|
* 取消同步LIS
|
|
|
*/
|
|
|
public void cancelSyncLis(Long sampleId) {
|
|
|
- log.info("取消同步LIS");
|
|
|
+ SampleAnimalVo animalDetail = sampleAnimalService.getDetail(sampleId);
|
|
|
+ Assert.notNull(animalDetail, "取消同步LIS失败,动物样本检测不存在");
|
|
|
+ SampleCheckSerumVo serum = animalDetail.getOrder().getSerum();
|
|
|
+
|
|
|
+ SampleCheckOrder checkOrder = checkOrderMapper.selectById(serum.getId());
|
|
|
+ Assert.notEmpty(checkOrder.getExtData(), "取消同步LIS失败,未同步");
|
|
|
+ JSONObject extObj = JSON.parseObject(checkOrder.getExtData());
|
|
|
+ Assert.isTrue(extObj.containsKey("lisId"), "取消同步LIS失败,未同步");
|
|
|
+
|
|
|
+ log.info("开始取消同步lis数据库 sample={}", sampleId);
|
|
|
+ JSONArray array = extObj.getJSONArray("lisId");
|
|
|
+ List<Long> applyIdList = JSON.parseArray(array.toJSONString(), Long.class);
|
|
|
+
|
|
|
+ lisDb.execute(db -> {
|
|
|
+ try {
|
|
|
+ String applyIdJoin = CollUtil.join(applyIdList, ",");
|
|
|
+ db.execute("delete from dbo.HT_SCIENCE_APPLY where id in (" + applyIdJoin + ")");
|
|
|
+ db.execute("delete from dbo.HT_SCIENCE_APPLY_ITEM where apply_id in (" + applyIdJoin + ")");
|
|
|
+ log.info("取消同步lis数据库完成 sampleId={} ", sampleId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("取消同步LIS失败", e);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
}
|