|
|
@@ -3,7 +3,12 @@ package com.nb.web.service.bus.service;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.crypto.digest.DigestUtil;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
@@ -13,6 +18,7 @@ import com.nb.auth.utils.SecurityUtil;
|
|
|
import com.nb.web.api.bean.GeoPoint;
|
|
|
import com.nb.web.api.entity.BusHospitalConfigEntity;
|
|
|
import com.nb.web.api.feign.IHospitalClient;
|
|
|
+import com.nb.web.api.feign.result.AppHospitalVO;
|
|
|
import com.nb.web.api.feign.result.HospitalResult;
|
|
|
import com.nb.web.service.bus.entity.*;
|
|
|
import com.nb.web.service.bus.enums.ConstantMixEnum;
|
|
|
@@ -21,6 +27,7 @@ import com.nb.web.service.bus.hospital.his.strategy.HisStrategyEnum;
|
|
|
import com.nb.web.service.bus.mapper.BusHospitalMapper;
|
|
|
import com.nb.web.service.bus.service.constant.LocalBusConAlarmService;
|
|
|
import com.nb.web.service.bus.service.constant.LocalBusConMixService;
|
|
|
+import com.nb.web.service.bus.service.dto.IotHospitalAddDTO;
|
|
|
import com.nb.web.service.bus.utils.CodeUtils;
|
|
|
import com.nb.core.cache.ConfigStorage;
|
|
|
import com.nb.core.cache.manager.ConfigStorageManager;
|
|
|
@@ -32,6 +39,7 @@ import com.nb.core.exception.CustomException;
|
|
|
import com.nb.web.service.system.entity.SysRole;
|
|
|
import com.nb.web.service.system.service.impl.SysRoleServiceImpl;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.boot.CommandLineRunner;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.jdbc.BadSqlGrammarException;
|
|
|
@@ -40,6 +48,8 @@ import org.springframework.web.context.request.RequestContextHolder;
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Optional;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
@@ -60,6 +70,7 @@ public class LocalBusHospitalService extends BaseService<BusHospitalMapper, BusH
|
|
|
|
|
|
private ConfigStorage nameCache;
|
|
|
|
|
|
+ private HashMap<String,String> codeMap=new HashMap<>();
|
|
|
@Autowired
|
|
|
@Lazy
|
|
|
private LocalBusConMixService conMixService;
|
|
|
@@ -68,6 +79,9 @@ public class LocalBusHospitalService extends BaseService<BusHospitalMapper, BusH
|
|
|
@Lazy
|
|
|
private LocalBusConAlarmService conAlarmService;
|
|
|
|
|
|
+ @Value("${spring.profiles.active}")
|
|
|
+ private String env;
|
|
|
+
|
|
|
@Autowired
|
|
|
@Lazy
|
|
|
private SysRoleServiceImpl sysRoleService;
|
|
|
@@ -78,6 +92,8 @@ public class LocalBusHospitalService extends BaseService<BusHospitalMapper, BusH
|
|
|
@Autowired
|
|
|
@Lazy
|
|
|
private LocalBusHospitalConfigService configService;
|
|
|
+ @Autowired
|
|
|
+ private BusHospitalMapper hospitalMapper;
|
|
|
@PostConstruct
|
|
|
public void init(){
|
|
|
nameCache =configStorageManager.getStorage("hospital_name");
|
|
|
@@ -142,61 +158,79 @@ public class LocalBusHospitalService extends BaseService<BusHospitalMapper, BusH
|
|
|
|
|
|
@Override
|
|
|
public void postSave(BusHospitalEntity entity) {
|
|
|
- CompletableFuture.runAsync(()->{
|
|
|
- List<BusHospitalConfigEntity> configs =
|
|
|
- configService.list(new QueryWrapper<BusHospitalConfigEntity>().lambda()
|
|
|
- .or()
|
|
|
- .eq(BusHospitalConfigEntity::getTenantId, 1));
|
|
|
- configs.forEach(config->{
|
|
|
- config.setId(null);
|
|
|
- config.setTenantId(entity.getId());
|
|
|
- });
|
|
|
- configService.saveBatch(configs);
|
|
|
-
|
|
|
- //设置默认更新策略
|
|
|
- HisUpdateEntity updateConfig = entity.getUpdateConfig();
|
|
|
- if(updateConfig!=null){
|
|
|
- hospitalManagerRegister.get(entity.getId()).refreshUpdateConfig(updateConfig);
|
|
|
- }
|
|
|
|
|
|
- //设置默认管理员角色
|
|
|
- SysRole sysRole = new SysRole();
|
|
|
- sysRole.setTenantId(entity.getId());
|
|
|
- sysRole.setRoleName("超级管理员");
|
|
|
- sysRole.setDataScope("1");
|
|
|
- sysRole.setRoleCode("admin");
|
|
|
- sysRole.setRemarks("超级管理员角色,不可编辑,不可删除");
|
|
|
- sysRoleService.save(sysRole);
|
|
|
- nameCache.setConfig(entity.getId(),entity.getName());
|
|
|
+ List<BusHospitalConfigEntity> configs =
|
|
|
+ configService.list(new QueryWrapper<BusHospitalConfigEntity>().lambda()
|
|
|
+ .or()
|
|
|
+ .eq(BusHospitalConfigEntity::getTenantId, 1));
|
|
|
+ configs.forEach(config->{
|
|
|
+ config.setId(null);
|
|
|
+ config.setTenantId(entity.getId());
|
|
|
+ });
|
|
|
+ configService.saveBatch(configs);
|
|
|
|
|
|
- //设置默认常量信息
|
|
|
- List<BusConMixEntity> drugCons = conMixService.list(new QueryWrapper<BusConMixEntity>()
|
|
|
- .lambda().eq(BusConMixEntity::getTenantId, "1")
|
|
|
- .eq(BusConMixEntity::getType, ConstantMixEnum.drugCate));
|
|
|
- if(CollUtil.isNotEmpty(drugCons)){
|
|
|
- conMixService.saveBatch(drugCons.stream().peek(mix->{
|
|
|
- mix.setId(null);
|
|
|
- mix.setTenantId(entity.getId());
|
|
|
- }).collect(Collectors.toSet()));
|
|
|
- }
|
|
|
+ //设置默认更新策略
|
|
|
+ HisUpdateEntity updateConfig = entity.getUpdateConfig();
|
|
|
+ if(updateConfig!=null){
|
|
|
+ hospitalManagerRegister.get(entity.getId()).refreshUpdateConfig(updateConfig);
|
|
|
+ }
|
|
|
|
|
|
- //设置默认报警原因
|
|
|
- List<BusConAlarmEntity> alarmCauses = conAlarmService.list(new QueryWrapper<BusConAlarmEntity>()
|
|
|
- .lambda().eq(BusConAlarmEntity::getTenantId, "1"));
|
|
|
- if (CollUtil.isNotEmpty(alarmCauses)) {
|
|
|
- conAlarmService.saveBatch(alarmCauses.stream().peek(alarmCause->{
|
|
|
- alarmCause.setId(null);
|
|
|
- alarmCause.setTenantId(entity.getId());
|
|
|
- }).collect(Collectors.toSet()));
|
|
|
- }
|
|
|
- })
|
|
|
- .whenComplete((i,e)->{
|
|
|
- if(e!=null){
|
|
|
- log.error("新增医院默认配置失败,",e);
|
|
|
- }
|
|
|
- });
|
|
|
+ //设置默认管理员角色
|
|
|
+ SysRole sysRole = new SysRole();
|
|
|
+ sysRole.setTenantId(entity.getId());
|
|
|
+ sysRole.setRoleName("超级管理员");
|
|
|
+ sysRole.setDataScope("1");
|
|
|
+ sysRole.setRoleCode("admin");
|
|
|
+ sysRole.setRemarks("超级管理员角色,不可编辑,不可删除");
|
|
|
+ sysRoleService.save(sysRole);
|
|
|
+ nameCache.setConfig(entity.getId(),entity.getName());
|
|
|
+
|
|
|
+ //设置默认常量信息
|
|
|
+ List<BusConMixEntity> drugCons = conMixService.list(new QueryWrapper<BusConMixEntity>()
|
|
|
+ .lambda().eq(BusConMixEntity::getTenantId, "1")
|
|
|
+ .eq(BusConMixEntity::getType, ConstantMixEnum.drugCate));
|
|
|
+ if(CollUtil.isNotEmpty(drugCons)){
|
|
|
+ conMixService.saveBatch(drugCons.stream().peek(mix->{
|
|
|
+ mix.setId(null);
|
|
|
+ mix.setTenantId(entity.getId());
|
|
|
+ }).collect(Collectors.toSet()));
|
|
|
+ }
|
|
|
+
|
|
|
+ //设置默认报警原因
|
|
|
+ List<BusConAlarmEntity> alarmCauses = conAlarmService.list(new QueryWrapper<BusConAlarmEntity>()
|
|
|
+ .lambda().eq(BusConAlarmEntity::getTenantId, "1"));
|
|
|
+ if (CollUtil.isNotEmpty(alarmCauses)) {
|
|
|
+ conAlarmService.saveBatch(alarmCauses.stream().peek(alarmCause->{
|
|
|
+ alarmCause.setId(null);
|
|
|
+ alarmCause.setTenantId(entity.getId());
|
|
|
+ }).collect(Collectors.toSet()));
|
|
|
+ };
|
|
|
+ if(StrUtil.equalsAny("prod",env)){
|
|
|
+ sendIotAddHospital(entity);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ private void sendIotAddHospital(BusHospitalEntity source){
|
|
|
+ IotHospitalAddDTO sendMsg = new IotHospitalAddDTO();
|
|
|
+ sendMsg.setCode(source.getCode());
|
|
|
+ sendMsg.setUsername(source.getName());
|
|
|
+ sendMsg.setMobile(RandomUtil.randomNumbers(11));
|
|
|
+ sendMsg.setEmail(source.getEmail());
|
|
|
+ sendMsg.setRegionCode(source.getAreaCode());
|
|
|
+ String content= new StringBuffer(sendMsg.getUsername()).append("&").append("yunzhineng").toString();
|
|
|
+ sendMsg.setMd5(DigestUtil.md5Hex(content));
|
|
|
+ try {
|
|
|
+ String post = HttpUtil.post("https://iot.tuoren.com/forward-service/open/addUser", JSONUtil.toJsonStr(sendMsg));
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(post);
|
|
|
+ if("1".equals(jsonObject.getStr("code"))){
|
|
|
+ throw new RuntimeException("新增失败,"+jsonObject.getStr("msg"));
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("iot.tuoren.com : 医院["+ source.getName()+"]新增失败",e);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
@Override
|
|
|
public void postUpdate(BusHospitalEntity entity) {
|
|
|
hospitalManagerRegister.refresh(entity.getId(),true,null!=entity.getScript());
|
|
|
@@ -216,7 +250,7 @@ public class LocalBusHospitalService extends BaseService<BusHospitalMapper, BusH
|
|
|
|
|
|
@Override
|
|
|
public void run(String... args) {
|
|
|
-// saveDefaultHospital();
|
|
|
+ saveDefaultHospital();
|
|
|
List<BusHospitalEntity> list = list();
|
|
|
list.parallelStream().forEach(entity -> {
|
|
|
entity.setScriptOnline(false);
|
|
|
@@ -224,7 +258,7 @@ public class LocalBusHospitalService extends BaseService<BusHospitalMapper, BusH
|
|
|
this.baseMapper.updateById(entity);
|
|
|
});
|
|
|
configService.saveDefaultConfig();
|
|
|
- list.parallelStream().forEach(hospital-> hospitalManagerRegister.refresh(hospital.getId(),true,true,true,true));
|
|
|
+// list.parallelStream().forEach(hospital-> hospitalManagerRegister.refresh(hospital.getId(),true,true,true,true));
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -237,7 +271,6 @@ public class LocalBusHospitalService extends BaseService<BusHospitalMapper, BusH
|
|
|
private void saveDefaultHospital(){
|
|
|
BusHospitalEntity hospital = new BusHospitalEntity();
|
|
|
hospital.setId("1");
|
|
|
- hospital.setCode("1000");
|
|
|
hospital.setName("驼人医疗器械有限公司");
|
|
|
hospital.setRemark("系统级医院,不可删除、修改");
|
|
|
GeoPoint geoPoint = new GeoPoint();
|
|
|
@@ -306,12 +339,19 @@ public class LocalBusHospitalService extends BaseService<BusHospitalMapper, BusH
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public HospitalResult findById(String tenantId) {
|
|
|
- return BeanUtil.copyProperties(getById(tenantId),HospitalResult.class);
|
|
|
+ public List<AppHospitalVO> selectUserHospitalList(String username) {
|
|
|
+ return hospitalMapper.selectUserHospitalListByUsername(username);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String selectHospitalCode(String id) {
|
|
|
- return getName(id);
|
|
|
+ return codeMap.computeIfAbsent(id,k->{
|
|
|
+ BusHospitalEntity busHospitalEntity = hospitalMapper.selectById(id);
|
|
|
+ if(busHospitalEntity==null){
|
|
|
+ return "";
|
|
|
+ }else {
|
|
|
+ return busHospitalEntity.getCode();
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
}
|