完成同步更新三个逻辑

This commit is contained in:
czx 2020-12-17 16:13:51 +08:00
parent bb88724e20
commit 9dc5505422
7 changed files with 124 additions and 12 deletions

View File

@ -1,5 +1,6 @@
package com.ruoyi.system.fantang.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
@ -43,6 +44,9 @@ public class FtOrderDao implements Serializable {
@Excel(name = "订单类型")
private Integer orderType;
@TableField(exist = false)
private String orderTypeString;
/**
* 员工 id
*/

View File

@ -2,6 +2,7 @@ package com.ruoyi.system.fantang.mapper;
import com.ruoyi.system.fantang.domain.FtNotifyDao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
/**
* 系统信息Mapper接口
@ -9,6 +10,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* @author ft
* @date 2020-12-17
*/
@Repository
public interface FtNotifyDaoMapper extends BaseMapper<FtNotifyDao> {
}

View File

@ -2,10 +2,14 @@ package com.ruoyi.system.fantang.mapper;
import com.ruoyi.system.fantang.domain.FtPatientDao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.system.fantang.vo.ftSyncConflictVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* 病人管理Mapper接口
*
@ -17,10 +21,16 @@ public interface FtPatientDaoMapper extends BaseMapper<FtPatientDao> {
@Update("update ft_patient set sync_flag = 0 where off_flag = 0")
public int initForSync();
@Update("update ft_patient a, ft_sync b set a.name= b.name, a.bed_id = b.bed_id, a.sync_flag = 1 where a.hospital_id = b.hospital_id and a.name = b.name and a.bed_id = b.bed_id and a.depart_name = b.depart_name")
public int syncEqual();
@Update("update ft_patient a, ft_sync b set a.name= b.name, a.bed_id = b.bed_id, a.sync_flag = 1 where a.hospital_id = b.hospital_id and a.name = b.name")
int syncEqualForHospitalAndName();
@Update("update ft_patient a, ft_sync b set a.name= b.name, a.bed_id = b.bed_id, a.sync_flag = 1 where a.hospital_id = b.hospital_id")
public int syncEqualHospitalId();
@Insert("Insert into ft_patient (name, bed_id, hospital_id, sync_flag) select name, bed_id, hospital_id, 2 from ft_sync where hospital_id not in (select hospital_id from ft_patient)")
@Insert("Insert into ft_patient (hospital_id, name, depart_id, bed_id, sync_flag) select a.hospital_id, a.name, c.depart_id, a.bed_id,2 from ft_sync a LEFT JOIN ft_depart c on a.depart_name = c.depart_name LEFT JOIN ft_patient b on a.`name` = b.`name` and c.depart_id = b.depart_id where a.hospital_id not in (select hospital_id from ft_patient d)")
public int syncNewHospitalId();
@Update("update ft_patient set off_flag = 1 where sync_flag = 0")
@ -30,4 +40,6 @@ public interface FtPatientDaoMapper extends BaseMapper<FtPatientDao> {
public int updateDepartIDToNewPatient();
@Select("select a.hospital_id, a.name, a.depart_name, a.bed_id, b.depart_id, c.hospital_id as old_hospital_id, c.name as old_name, a.depart_name as old_depart_name, c.bed_id as old_bed_id, c.depart_id as old_depart_id from ft_sync a LEFT JOIN ft_depart b on a.depart_name = b.depart_name LEFT JOIN ft_patient c on a.hospital_id = c.hospital_id where b.depart_id = c.depart_id and a.bed_id = c.bed_id and a.name != c.name")
List<ftSyncConflictVo> syncConflictOnlyHospitalEqual();
}

View File

@ -0,0 +1,9 @@
package com.ruoyi.system.fantang.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.system.fantang.vo.ftSyncConflictVo;
import org.springframework.stereotype.Repository;
@Repository
public interface FtSyncConflictDaoMapper extends BaseMapper<ftSyncConflictVo> {
}

View File

@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
/**
* 订单管理Service业务层处理
@ -32,7 +33,11 @@ public class FtOrderDaoServiceImpl extends ServiceImpl<FtOrderDaoMapper, FtOrder
QueryWrapper<FtOrderDao> wrapper = new QueryWrapper<>();
wrapper.eq("staff_id", staffId);
wrapper.between("order_date", DateUtil.beginOfDay(new Date()), DateUtil.endOfDay(new Date()));
return AjaxResult.success(this.baseMapper.selectList(wrapper));
List<FtOrderDao> daos = this.baseMapper.selectList(wrapper);
for (FtOrderDao dao : daos) {
dao.setOrderTypeString(dao.getOrderType().toString());
}
return AjaxResult.success(daos);
}
@Override

View File

@ -0,0 +1,52 @@
package com.ruoyi.system.fantang.vo;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ruoyi.system.fantang.domain.FtSyncPatientDao;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* 远程病患数据冲突数据实体类
*
* @author 陈智兴
* @date 2020-12-17
*/
@Data
@ToString
@EqualsAndHashCode
@NoArgsConstructor
@Accessors(chain = true)
public class ftSyncConflictVo extends FtSyncPatientDao implements Serializable {
private static final long serialVersionUID=1L;
/** 本地住院号 */
@TableField(value = "old_hospital_id")
private String oldHospitalid;
/** 本地姓名 */
@TableField(value = "old_name")
private String oldName;
// 本地科室名称
@TableField("old_depart_name")
private String oldDepartName;
// 本地床号
@TableField("old_bed_id")
private String oldDedId;
@TableField("depart_id")
private String departId;
@TableField("old_depart_id")
private String oldDepartId;
}

View File

@ -4,12 +4,10 @@ import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.system.fantang.domain.FtRemotePatientDao;
import com.ruoyi.system.fantang.domain.FtSyncLogDao;
import com.ruoyi.system.fantang.mapper.FtPatientDaoMapper;
import com.ruoyi.system.fantang.mapper.FtSyncLogDaoMapper;
import com.ruoyi.system.fantang.mapper.FtSyncPatientDaoMapper;
import com.ruoyi.system.fantang.mapper.*;
import com.ruoyi.system.fantang.vo.ftSyncConflictVo;
import com.ruoyi.system.service.ISyncPatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.Transient;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -28,10 +26,26 @@ public class SyncPatientServiceImpl implements ISyncPatientService {
@Autowired
private FtSyncLogDaoMapper syncLogDaoMapper;
// 从远程数据源插上病患数据
@Autowired
private FtNotifyDaoMapper notifyDaoMapper;
@Autowired
private FtSyncConflictDaoMapper syncConflictDaoMapper;
/**
* 从远程数据源插上病患数据
* 业务逻辑
* 1本地同步表将标志位置 0 等待同步状态
* 2
*
* @param remotePatientDaoList
* @return
*/
@Transactional
@Override
public Integer insertToLocalSync(List<FtRemotePatientDao> remotePatientDaoList) {
StringBuilder syncMessage = new StringBuilder();
syncMessage.append("同步信息:");
// 清空本地中间表数据准备接收同步数据
syncPatientDaoMapper.delete(null);
@ -42,13 +56,27 @@ public class SyncPatientServiceImpl implements ISyncPatientService {
// 初始化本地病患表准备同步将标志位置0
int ret = patientDaoMapper.initForSync();
syncMessage.append(String.format("本地初始化记录:%d 条",ret));
// 更新住院号相同的记录并标注flag=1
int syncCount = patientDaoMapper.syncEqualHospitalId();
// 从中间表添加新增病患数据并标注flag=2
ret = patientDaoMapper.syncNewHospitalId();
System.out.println(ret);
// 同步逻辑1更新住院号科室床号姓名全部相同的记录并标注flag=1
int syncCount = patientDaoMapper.syncEqual();
syncMessage.append(String.format("更新逻辑1 %d 条", syncCount));
// 同步逻辑2更新住院号姓名相同的记录并标注flag=1
syncCount = patientDaoMapper.syncEqualForHospitalAndName();
syncMessage.append(String.format("更新逻辑2 %d 条", syncCount));
// 同步逻辑3新增住院号科室床号相同的记录作为新病患同步并标注flag=2
syncCount = patientDaoMapper.syncNewHospitalId();
syncMessage.append(String.format("更新逻辑3 %d 条", syncCount));
// 冲突逻辑1住院号相同科室床号姓名都不相同的记录作为冲突数据并标注flag=3
List<ftSyncConflictVo> syncPatientVos = patientDaoMapper.syncConflictOnlyHospitalEqual();
syncMessage.append(String.format("冲突逻辑1 %d 条", syncPatientVos.size()));
for (ftSyncConflictVo vo : syncPatientVos) {
syncConflictDaoMapper.insert(vo);
}
// 将没有同步的病患数据设置为出院状态, off_flag=1
patientDaoMapper.updateOffHospitalFlag();