|
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
+import cn.hutool.core.util.ReflectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.db.Entity;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
@@ -22,9 +23,11 @@ import com.github.jfcloud.gene.sample.vo.CheckItemSerumVo;
|
|
|
import com.github.jfcloud.gene.sample.vo.SampleAnimalVo;
|
|
|
import com.github.jfcloud.gene.sample.vo.SampleCheckSerumVo;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.lang.reflect.Field;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -81,32 +84,40 @@ public class LisSyncService {
|
|
|
List<HtScienceApplyItem> applyItemList = new ArrayList<>();
|
|
|
for (CheckItemSerumVo item : serum.getItems()) {
|
|
|
HtScienceApply scienceApply = new HtScienceApply();
|
|
|
- if (serum.getSendOrgId() != null) {
|
|
|
- scienceApply.setHspId(depMap.get(serum.getSendOrgId()).getStr("hsp_id"));
|
|
|
- }
|
|
|
scienceApply.setPetType(item.getLisPetTypeId());
|
|
|
- scienceApply.setEmail(serum.getApplyUserEmail());
|
|
|
- scienceApply.setPhone(serum.getApplyUserMobile());
|
|
|
- scienceApply.setCreateName(sampleInfo.getApplicantName());
|
|
|
scienceApply.setCreateId(applyUser.getStr("user_id"));
|
|
|
- scienceApply.setCreateTime(checkOrder.getCreateTime());
|
|
|
- scienceApply.setSex(item.getLisSexId());
|
|
|
- scienceApply.setAge(Integer.parseInt(item.getAge()));
|
|
|
- scienceApply.setAgeUnit("hdmy".indexOf(item.getAgeUnit().charAt(0)));
|
|
|
- JSONObject ageObj = JSONObject.parseObject(scienceApply.getAgeDisplay());
|
|
|
- if (scienceApply.getAgeUnit() == 3) {
|
|
|
- ageObj.put("Year", item.getAge());
|
|
|
- } else if (scienceApply.getAgeUnit() == 2) {
|
|
|
- ageObj.put("Month", item.getAge());
|
|
|
- } else if (scienceApply.getAgeUnit() == 1) {
|
|
|
- ageObj.put("Day", item.getAge());
|
|
|
- }
|
|
|
- scienceApply.setAgeDisplay(ageObj.toJSONString());
|
|
|
- scienceApply.setSampleId(item.getLisSampleTypeId().toString());
|
|
|
- scienceApply.setFastFlag(Integer.parseInt(item.getQuick()));
|
|
|
+ scienceApply.setCreateName(sampleInfo.getApplicantName());
|
|
|
+ scienceApply.setEmail(StrUtil.nullToDefault(serum.getApplyUserEmail(), sampleInfo.getApplicantEmail()));
|
|
|
+ scienceApply.setPhone(StrUtil.nullToDefault(serum.getApplyUserMobile(), sampleInfo.getApplicantPhone()));
|
|
|
+
|
|
|
if (serum.getSendOrgId() != null) {
|
|
|
+ scienceApply.setHspId(depMap.get(serum.getSendOrgId()).getStr("hsp_id"));
|
|
|
scienceApply.setApplyDep(serum.getSendOrgId().toString());
|
|
|
}
|
|
|
+ if (item.getLisSampleTypeId() != null) {
|
|
|
+ scienceApply.setSampleId(item.getLisSampleTypeId().toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (item.getLisSexId() != null) {
|
|
|
+ scienceApply.setSex(item.getLisSexId());
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(item.getAge())) {
|
|
|
+ scienceApply.setAge(Integer.parseInt(item.getAge()));
|
|
|
+ scienceApply.setAgeUnit("hdmy".indexOf(item.getAgeUnit().charAt(0)));
|
|
|
+ JSONObject ageObj = JSONObject.parseObject(scienceApply.getAgeDisplay());
|
|
|
+ if (scienceApply.getAgeUnit() == 3) {
|
|
|
+ ageObj.put("Year", item.getAge());
|
|
|
+ } else if (scienceApply.getAgeUnit() == 2) {
|
|
|
+ ageObj.put("Month", item.getAge());
|
|
|
+ } else if (scienceApply.getAgeUnit() == 1) {
|
|
|
+ ageObj.put("Day", item.getAge());
|
|
|
+ }
|
|
|
+ scienceApply.setAgeDisplay(ageObj.toJSONString());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StrUtil.isNotBlank(item.getQuick())) {
|
|
|
+ scienceApply.setFastFlag(Integer.parseInt(item.getQuick()));
|
|
|
+ }
|
|
|
if (serum.getSendUserId() != null) {
|
|
|
scienceApply.setApplyDocId(serum.getSendUserId().toString());
|
|
|
scienceApply.setDeliverOperId(serum.getSendUserId().toString());
|
|
@@ -136,7 +147,7 @@ public class LisSyncService {
|
|
|
applyId = Long.parseLong(String.format("%s%07d", idPrefix, 1));
|
|
|
|
|
|
//查询当前最大的id与编号(编号格式HKYBKY20250326-14-15)
|
|
|
- String sql = String.format("select top 1 id, SampleNo from dbo.HT_SCIENCE_APPLY where id like '%s%%' order by id desc ", idPrefix);
|
|
|
+ String sql = String.format("select top 1 id, SampleNo from dbo.HT_SCIENCE_APPLY where id like '%s%%' order by SampleNo desc ", idPrefix);
|
|
|
Entity idEntity = lisDb.queryOne(sql);
|
|
|
if (idEntity != null) {
|
|
|
applyId = idEntity.getLong("id") + 1;
|
|
@@ -153,6 +164,7 @@ public class LisSyncService {
|
|
|
int endNo = beginNo + scienceApply.getSampleCount() - 1;
|
|
|
applyEndNoMap.put(noPrefix, endNo);
|
|
|
scienceApply.setSampleNo(noPrefix + "-" + beginNo + "-" + endNo);
|
|
|
+ fillNullWithDefault(scienceApply);
|
|
|
applyList.add(scienceApply);
|
|
|
|
|
|
//检测指标
|
|
@@ -180,6 +192,7 @@ public class LisSyncService {
|
|
|
applyItem.setId(itemPrimaryId++);
|
|
|
applyItem.setApplyId(scienceApply.getId());
|
|
|
applyItem.setItemId(Long.parseLong(itemId));
|
|
|
+ fillNullWithDefault(applyItem);
|
|
|
applyItemList.add(applyItem);
|
|
|
}
|
|
|
itemIdMap.put(idPrefix, itemPrimaryId);
|
|
@@ -203,22 +216,39 @@ public class LisSyncService {
|
|
|
db.insert(applyEntities);
|
|
|
List<Entity> applyItemEntities = applyItemList.stream().map(x -> Entity.create("dbo.HT_SCIENCE_APPLY_ITEM").parseBean(x, true, false)).collect(Collectors.toList());
|
|
|
db.insert(applyItemEntities);
|
|
|
-
|
|
|
- //保存id
|
|
|
- List<Long> applyIdList = applyList.stream().map(HtScienceApply::getId).collect(Collectors.toList());
|
|
|
- finalExtObj.put("lisId", applyIdList);
|
|
|
- SampleCheckOrder co = new SampleCheckOrder();
|
|
|
- co.setId(checkOrder.getId());
|
|
|
- co.setExtData(finalExtObj.toString());
|
|
|
- co.updateById();
|
|
|
-
|
|
|
- log.info("同步lis数据库完成 sampleId={} ", sampleId);
|
|
|
} catch (Exception e) {
|
|
|
log.error("同步LIS失败", e);
|
|
|
+ throw new RuntimeException("同步LIS失败");
|
|
|
}
|
|
|
+
|
|
|
+ //保存id
|
|
|
+ List<Long> applyIdList = applyList.stream().map(HtScienceApply::getId).collect(Collectors.toList());
|
|
|
+ finalExtObj.put("lisId", applyIdList);
|
|
|
+ SampleCheckOrder co = new SampleCheckOrder();
|
|
|
+ co.setId(checkOrder.getId());
|
|
|
+ co.setExtData(finalExtObj.toString());
|
|
|
+ co.updateById();
|
|
|
+
|
|
|
+ log.info("同步lis数据库完成 sampleId={} ", sampleId);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 使用默认值填充对象属性为null的字段
|
|
|
+ */
|
|
|
+ @SneakyThrows
|
|
|
+ private void fillNullWithDefault(Object o) {
|
|
|
+ Object defaultObject = o.getClass().newInstance();
|
|
|
+
|
|
|
+ Field[] fields = ReflectUtil.getFields(o.getClass());
|
|
|
+ for (Field field : fields) {
|
|
|
+ field.setAccessible(true);
|
|
|
+ if (field.get(o) == null && field.get(defaultObject) != null) {
|
|
|
+ field.set(o, field.get(defaultObject));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 取消同步LIS
|
|
|
*/
|
|
@@ -242,15 +272,16 @@ public class LisSyncService {
|
|
|
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);
|
|
|
-
|
|
|
- extObj.remove("lisId");
|
|
|
- SampleCheckOrder co = new SampleCheckOrder();
|
|
|
- co.setId(checkOrder.getId());
|
|
|
- co.setExtData(extObj.toString());
|
|
|
- co.updateById();
|
|
|
} catch (Exception e) {
|
|
|
log.error("取消同步LIS失败", e);
|
|
|
+ throw new RuntimeException("取消同步LIS失败");
|
|
|
}
|
|
|
+
|
|
|
+ extObj.remove("lisId");
|
|
|
+ SampleCheckOrder co = new SampleCheckOrder();
|
|
|
+ co.setId(checkOrder.getId());
|
|
|
+ co.setExtData(extObj.toString());
|
|
|
+ co.updateById();
|
|
|
});
|
|
|
}
|
|
|
}
|