Browse Source

同步部门和用户

hnzxyjhyy
zhangye 2 weeks ago
parent
commit
564b395482
  1. 10
      ruisi_java/ruisi-cc-common/src/main/java/com/ccsens/common/core/domain/entity/SysDept.java
  2. 138
      ruisi_java/ruisi-system/src/main/java/com/ccsens/system/service/impl/DockServiceImpl.java
  3. 3
      ruisi_java/ruisi-system/src/main/resources/mapper/system/SysDeptMapper.xml
  4. 5
      ruisi_java/ruisi-web-client/src/main/java/com/ccsens/client/controller/scheduled/SyncHospitalData.java
  5. 2
      ruisi_java/ruisi-web-client/src/main/resources/application-dev.yml
  6. 2
      ruisi_java/ruisi-web-client/src/main/resources/application-prod.yml

10
ruisi_java/ruisi-cc-common/src/main/java/com/ccsens/common/core/domain/entity/SysDept.java

@ -74,6 +74,8 @@ public class SysDept extends BaseEntity {
*/ */
private String parentName; private String parentName;
private String deptCode;
/** /**
* 子部门 * 子部门
*/ */
@ -181,6 +183,14 @@ public class SysDept extends BaseEntity {
this.children = children; this.children = children;
} }
public String getDeptCode() {
return deptCode;
}
public void setDeptCode(String deptCode) {
this.deptCode = deptCode;
}
@Override @Override
public String toString() { public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)

138
ruisi_java/ruisi-system/src/main/java/com/ccsens/system/service/impl/DockServiceImpl.java

@ -8,8 +8,11 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.pinyin.PinyinUtil; import cn.hutool.extra.pinyin.PinyinUtil;
import com.ccsens.common.annotation.DataSource; import com.ccsens.common.annotation.DataSource;
import com.ccsens.common.constant.ErrorConstant; import com.ccsens.common.constant.ErrorConstant;
import com.ccsens.common.core.domain.entity.SysDept;
import com.ccsens.common.core.domain.entity.SysUser;
import com.ccsens.common.enums.DataSourceType; import com.ccsens.common.enums.DataSourceType;
import com.ccsens.common.exception.base.BaseException; import com.ccsens.common.exception.base.BaseException;
import com.ccsens.common.utils.SecurityUtils;
import com.ccsens.system.domain.dto.DockDto; import com.ccsens.system.domain.dto.DockDto;
import com.ccsens.system.domain.po.*; import com.ccsens.system.domain.po.*;
import com.ccsens.system.persist.dao.DockDao; import com.ccsens.system.persist.dao.DockDao;
@ -17,11 +20,13 @@ import com.ccsens.system.persist.mapper.*;
import com.ccsens.system.service.DmsDataValueService; import com.ccsens.system.service.DmsDataValueService;
import com.ccsens.system.service.DockService; import com.ccsens.system.service.DockService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -62,6 +67,13 @@ public class DockServiceImpl implements DockService {
private PmsPatientDiagnosisMapper pmsPatientDiagnosisMapper; private PmsPatientDiagnosisMapper pmsPatientDiagnosisMapper;
@Resource @Resource
private PmsPatientParentIllnessMapper pmsPatientParentIllnessMapper; private PmsPatientParentIllnessMapper pmsPatientParentIllnessMapper;
@Resource
private SysDeptMapper sysDeptMapper;
@Resource
private SysUserMapper sysUserMapper;
@Value("${hospitalId:}")
private Long hospitalId;
@Override @Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
@ -289,32 +301,127 @@ public class DockServiceImpl implements DockService {
public void syncDeptAndUserData() { public void syncDeptAndUserData() {
//部门信息 //部门信息
try { try {
syncUmsDeptMaster(); List<SysDept> sysDepts = syncUmsDeptSlave();
syncUmsDeptSlave(); syncUmsDeptMaster(sysDepts);
}catch (Exception e){ }catch (Exception e){
log.error("用药信息同步失败",e); log.error("部门信息同步失败",e);
}
//用户信息
try {
List<SysUser> sysUsers = syncUmsUserSlave();
syncUmsUserMaster(sysUsers);
}catch (Exception e){
log.error("用户信息同步失败",e);
} }
} }
@DataSource(value = DataSourceType.MASTER) @DataSource(value = DataSourceType.MASTER)
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class) @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void syncUmsDeptMaster() { public void syncUmsUserMaster(List<SysUser> sysUsers) {
if(CollUtil.isNotEmpty(sysUsers)){
for (SysUser sysUser : sysUsers) {
//根据code查找用户
SysUser user = new SysUser();
user.setEmplCode(sysUser.getEmplCode());
List<SysUser> users = sysUserMapper.selectUserList(user);
if (CollUtil.isEmpty(users)) {
sysUserMapper.insertUser(sysUser);
}
}
}
}
@DataSource(value = DataSourceType.SLAVE)
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public List<SysUser> syncUmsUserSlave() {
List<SysUser> returnUsers = new ArrayList<>();
DockEmplExample dockEmplExample = new DockEmplExample();
dockEmplExample.createCriteria().andSyncEqualTo("0").andDelFlagEqualTo("0");
List<DockEmpl> dockEmpls = dockEmplMapper.selectByExample(dockEmplExample);
if (CollUtil.isEmpty(dockEmpls)) {
return returnUsers;
}
for (DockEmpl dockEmpl : dockEmpls) {
//根据code查找部门信息
SysDept sysDept = new SysDept();
sysDept.setDeptCode(dockEmpl.getDeptCode());
List<SysDept> sysDepts = sysDeptMapper.selectDeptList(sysDept);
if (CollUtil.isEmpty(sysDepts)) {
continue;
}else {
sysDept = sysDepts.get(0);
}
SysUser sysUser = new SysUser();
sysUser.setEmplCode(dockEmpl.getEmplCode());
List<SysUser> sysUsers = sysUserMapper.selectUserList(sysUser);
if (CollUtil.isEmpty(sysUsers)) {
sysUser.setDeptId(sysDept.getDeptId());
sysUser.setUserName(dockEmpl.getEmplCode());
sysUser.setNickName(dockEmpl.getEmplName());
sysUser.setEmplCode(dockEmpl.getEmplCode());
sysUser.setPassword(SecurityUtils.encryptPassword("hnzxyjhyy"));
sysUserMapper.insertUser(sysUser);
returnUsers.add(sysUser);
}
}
return returnUsers;
}
@DataSource(value = DataSourceType.SLAVE)
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public List<SysDept> syncUmsDeptSlave() {
List<SysDept> returnDepts = new ArrayList<>();
//查找同步表中的部门信息 //查找同步表中的部门信息
DockDeptExample dockDeptExample = new DockDeptExample(); DockDeptExample dockDeptExample = new DockDeptExample();
dockDeptExample.createCriteria().andSyncEqualTo("0").andDelFlagEqualTo("0"); dockDeptExample.createCriteria().andSyncEqualTo("0").andDelFlagEqualTo("0");
List<DockDept> dockDepts = dockDeptMapper.selectByExample(dockDeptExample); List<DockDept> dockDepts = dockDeptMapper.selectByExample(dockDeptExample);
if (CollUtil.isEmpty(dockDepts)) { if (CollUtil.isEmpty(dockDepts)) {
return; return returnDepts;
} }
for (DockDept dockDept : dockDepts) { for (DockDept dockDept : dockDepts) {
//根据code查找系统的部门信息
SysDept sysDept = new SysDept();
sysDept.setDeptCode(dockDept.getDeptCode());
List<SysDept> sysDepts = sysDeptMapper.selectDeptList(sysDept);
if (CollUtil.isEmpty(sysDepts)) {
sysDept.setParentId(hospitalId);
sysDept.setAncestors("0," + hospitalId);
sysDept.setDeptName(dockDept.getDeptName());
sysDept.setDeptCode(dockDept.getDeptCode());
sysDeptMapper.insertDept(sysDept);
returnDepts.add(sysDept);
}else {
sysDept = sysDepts.get(0);
sysDept.setParentId(hospitalId);
sysDept.setAncestors("0," + hospitalId);
sysDept.setDeptName(dockDept.getDeptName());
sysDept.setDeptCode(dockDept.getDeptCode());
sysDeptMapper.updateDept(sysDept);
returnDepts.add(sysDept);
} }
} }
return returnDepts;
}
@DataSource(value = DataSourceType.SLAVE) @DataSource(value = DataSourceType.MASTER)
private void syncUmsDeptSlave() { @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void syncUmsDeptMaster(List<SysDept> sysDepts) {
if(CollUtil.isNotEmpty(sysDepts)){
sysDepts.forEach(sysDept -> {
//根据code查找系统的部门信息
SysDept dept = new SysDept();
dept.setDeptCode(sysDept.getDeptCode());
List<SysDept> depts = sysDeptMapper.selectDeptList(dept);
if (CollUtil.isEmpty(depts)) {
sysDeptMapper.insertDept(sysDept);
}else {
SysDept sysDept1 = depts.get(0);
sysDept.setDeptId(sysDept1.getDeptId());
sysDeptMapper.updateDept(sysDept);
}
});
}
} }
@ -348,6 +455,9 @@ public class DockServiceImpl implements DockService {
disposePmsPatient(dockPatientBaseInfo, pmsPatient); disposePmsPatient(dockPatientBaseInfo, pmsPatient);
pmsPatientMapper.insertSelective(pmsPatient); pmsPatientMapper.insertSelective(pmsPatient);
} }
//修改同步表数据的状态
dockPatientBaseInfo.setSync("1");
dockPatientBaseInfoMapper.updateByPrimaryKeySelective(dockPatientBaseInfo);
} }
} }
@ -361,6 +471,9 @@ public class DockServiceImpl implements DockService {
} }
for (DockPatientVisitInfo dockPatientVisitInfo : dockPatientVisitInfos) { for (DockPatientVisitInfo dockPatientVisitInfo : dockPatientVisitInfos) {
savePatientBady(dockPatientVisitInfo); savePatientBady(dockPatientVisitInfo);
//修改同步表数据的状态
dockPatientVisitInfo.setSync("1");
dockPatientVisitInfoMapper.updateByPrimaryKeySelective(dockPatientVisitInfo);
} }
} }
@ -458,6 +571,8 @@ public class DockServiceImpl implements DockService {
pmsPatientDiagnosis.setDiagnosisName(dockPatientDiagnosis.getDiagnosisName()); pmsPatientDiagnosis.setDiagnosisName(dockPatientDiagnosis.getDiagnosisName());
pmsPatientDiagnosis.setDiagnosisDate(DateUtil.format(dockPatientDiagnosis.getDiagnosisDate(), "yyyy-MM-dd HH:mm:ss")); pmsPatientDiagnosis.setDiagnosisDate(DateUtil.format(dockPatientDiagnosis.getDiagnosisDate(), "yyyy-MM-dd HH:mm:ss"));
pmsPatientDiagnosisMapper.insertSelective(pmsPatientDiagnosis); pmsPatientDiagnosisMapper.insertSelective(pmsPatientDiagnosis);
dockPatientDiagnosis.setSync("1");
dockPatientDiagnosisMapper.updateByPrimaryKeySelective(dockPatientDiagnosis);
} }
} }
} }
@ -510,6 +625,9 @@ public class DockServiceImpl implements DockService {
pmsPatientParentIllness.setUnit(dockPatientMedicationInfo.getUnit()); pmsPatientParentIllness.setUnit(dockPatientMedicationInfo.getUnit());
pmsPatientParentIllness.setFrequency(dockPatientMedicationInfo.getFrequency()); pmsPatientParentIllness.setFrequency(dockPatientMedicationInfo.getFrequency());
pmsPatientParentIllnessMapper.insertSelective(pmsPatientParentIllness); pmsPatientParentIllnessMapper.insertSelective(pmsPatientParentIllness);
//修改同步表数据的状态
dockPatientMedicationInfo.setSync("1");
dockPatientMedicationInfoMapper.updateByPrimaryKeySelective(dockPatientMedicationInfo);
} }
} }
} }

3
ruisi_java/ruisi-system/src/main/resources/mapper/system/SysDeptMapper.xml

@ -42,6 +42,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="status != null and status != ''"> <if test="status != null and status != ''">
AND status = #{status} AND status = #{status}
</if> </if>
<if test="deptCode != null and deptCode != ''">
AND dept_code = #{deptCode}
</if>
<!-- 数据范围过滤 --> <!-- 数据范围过滤 -->
${params.dataScope} ${params.dataScope}
order by d.parent_id, d.order_num order by d.parent_id, d.order_num

5
ruisi_java/ruisi-web-client/src/main/java/com/ccsens/client/controller/scheduled/SyncHospitalData.java

@ -24,4 +24,9 @@ public class SyncHospitalData {
dockService.syncHospitalData(); dockService.syncHospitalData();
} }
@Scheduled(cron = "0 */3 * * * ?")
public void syncDeptAndUserData() {
dockService.syncDeptAndUserData();
}
} }

2
ruisi_java/ruisi-web-client/src/main/resources/application-dev.yml

@ -124,3 +124,5 @@ informed:
#clientVersion: v1.8.1.0 #clientVersion: v1.8.1.0
#clientVersion: v1.8.2.0 #clientVersion: v1.8.2.0
clientVersion: v1.8.3.0 clientVersion: v1.8.3.0
hospitalId: 174

2
ruisi_java/ruisi-web-client/src/main/resources/application-prod.yml

@ -129,3 +129,5 @@ informed:
#clientVersion: v1.8.1.0 #clientVersion: v1.8.1.0
#clientVersion: v1.8.2.0 #clientVersion: v1.8.2.0
clientVersion: v1.8.3.0 clientVersion: v1.8.3.0
hospitalId: 174
Loading…
Cancel
Save