diff --git a/platform-biz-service/src/main/java/com/lyms/platform/permission/model/UsersQuery.java b/platform-biz-service/src/main/java/com/lyms/platform/permission/model/UsersQuery.java index af18d63..bb90879 100644 --- a/platform-biz-service/src/main/java/com/lyms/platform/permission/model/UsersQuery.java +++ b/platform-biz-service/src/main/java/com/lyms/platform/permission/model/UsersQuery.java @@ -21,6 +21,11 @@ public class UsersQuery extends BaseQuery { private String publishName; private Integer yn; private Integer enable; + //大于修改时间 + private Date gteModified; + //大于创建时间 + private Date gteCreated; + private Date modified; private Date created; private String remarks; @@ -35,6 +40,21 @@ public class UsersQuery extends BaseQuery { return otherAccount; } + public Date getGteCreated() { + return gteCreated; + } + + public void setGteCreated(Date gteCreated) { + this.gteCreated = gteCreated; + } + + public Date getGteModified() { + return gteModified; + } + + public void setGteModified(Date gteModified) { + this.gteModified = gteModified; + } public List orgIds; //这些机构下的用户 diff --git a/platform-biz-service/src/main/resources/mainOrm/master/MasterUsers.xml b/platform-biz-service/src/main/resources/mainOrm/master/MasterUsers.xml index 900fe05..599d369 100644 --- a/platform-biz-service/src/main/resources/mainOrm/master/MasterUsers.xml +++ b/platform-biz-service/src/main/resources/mainOrm/master/MasterUsers.xml @@ -193,6 +193,13 @@ select id,logincenter_id,type,org_id,dept_id,name,account,pwd,phone,publish_id,p and created = #{created,jdbcType=TIMESTAMP} + + and modified >= #{gteModified,jdbcType=TIMESTAMP} + + + and created >= #{gteCreated,jdbcType=TIMESTAMP} + + and remarks = #{remarks,jdbcType=VARCHAR} diff --git a/platform-dal/src/main/java/com/lyms/platform/query/AntExChuQuery.java b/platform-dal/src/main/java/com/lyms/platform/query/AntExChuQuery.java index 58ace70..b1e09c4 100644 --- a/platform-dal/src/main/java/com/lyms/platform/query/AntExChuQuery.java +++ b/platform-dal/src/main/java/com/lyms/platform/query/AntExChuQuery.java @@ -24,9 +24,18 @@ public class AntExChuQuery extends BaseQuery implements IConvertToNativeQuery { private Date nextCheckTime; private Date nextCheckTimeStart; private Date nextCheckTimeEnd; - + //大于修改时间 + private Date gteModified; private String pid; + public Date getGteModified() { + return gteModified; + } + + public void setGteModified(Date gteModified) { + this.gteModified = gteModified; + } + public String getPid() { return pid; } @@ -135,6 +144,14 @@ public class AntExChuQuery extends BaseQuery implements IConvertToNativeQuery { } } + if(null!=gteModified){ + if (null != c) { + c = c.gte(gteModified); + } else { + c = Criteria.where("modified").gte(gteModified); + } + } + if (null != c) { condition = condition.andCondition(new MongoCondition(c)); } diff --git a/platform-dal/src/main/java/com/lyms/platform/query/PatientsQuery.java b/platform-dal/src/main/java/com/lyms/platform/query/PatientsQuery.java index a35d5e3..5a1d9a6 100644 --- a/platform-dal/src/main/java/com/lyms/platform/query/PatientsQuery.java +++ b/platform-dal/src/main/java/com/lyms/platform/query/PatientsQuery.java @@ -212,6 +212,18 @@ public class PatientsQuery extends BaseQuery implements IConvertToNativeQuery { private Date fmDateStart; private Date fmDateEnd; + //大于修改时间 + private Date gteModified; + //大于创建时间 + + public Date getGteModified() { + return gteModified; + } + + public void setGteModified(Date gteModified) { + this.gteModified = gteModified; + } + public List getBuildTypeList() { return buildTypeList; } @@ -663,6 +675,14 @@ public class PatientsQuery extends BaseQuery implements IConvertToNativeQuery { } } + if (null != gteModified) { + if (null!=c1) { + c1 = c1.gte(gteModified); + } else { + c1 = Criteria.where("modified").gte(gteModified); + } + } + // Criteria cr1 = Criteria.where("bookbuildingDate").gte(bookbuildingDateStart).lte(bookbuildingDateEnd); // Criteria cr = cr1.where("lastMenses").gte(lastMensesStart).lte(lastMensesEnd); diff --git a/platform-job-index/src/main/java/com/lyms/platform/job/index/TestSolr.java b/platform-job-index/src/main/java/com/lyms/platform/job/index/TestSolr.java index 784d043..191fcfa 100644 --- a/platform-job-index/src/main/java/com/lyms/platform/job/index/TestSolr.java +++ b/platform-job-index/src/main/java/com/lyms/platform/job/index/TestSolr.java @@ -34,5 +34,6 @@ public class TestSolr { doctorPatientsService.add(doctorUserPatentsMaps); } System.out.print(System.currentTimeMillis()-time); + } } \ No newline at end of file diff --git a/platform-job-index/src/main/java/com/lyms/platform/job/index/restore/data/SyncDataWork.java b/platform-job-index/src/main/java/com/lyms/platform/job/index/restore/data/SyncDataWork.java index c839190..772b6db 100644 --- a/platform-job-index/src/main/java/com/lyms/platform/job/index/restore/data/SyncDataWork.java +++ b/platform-job-index/src/main/java/com/lyms/platform/job/index/restore/data/SyncDataWork.java @@ -19,16 +19,21 @@ import com.lyms.platform.query.PatientsQuery; import com.lymsh.mommybaby.maindata.model.*; import com.lymsh.mommybaby.maindata.service.*; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.math.NumberUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; +import java.io.File; +import java.io.RandomAccessFile; import java.util.Date; import java.util.HashMap; import java.util.List; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -55,7 +60,8 @@ public class SyncDataWork { /** * 工作线程池 */ - private ThreadPoolExecutor workExecutor = new ThreadPoolExecutor(2, 5, 3, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(50)); + private ThreadPoolExecutor workExecutor = new ThreadPoolExecutor(5, 10, 1, TimeUnit.HOURS, new LinkedBlockingQueue(5000)); + @Autowired private AntenatalExaminationService antenatalExaminationService; @@ -70,8 +76,6 @@ public class SyncDataWork { * 妈咪贝比 */ @Autowired - private UsersService mamiUsersService; - @Autowired private com.lyms.platform.permission.service.UsersService usersService; /** * 省 市 区 @@ -86,7 +90,10 @@ public class SyncDataWork { private ReportsService reportsService; @Autowired private DoctorUsersPatientsMapsService doctorUsersPatientsMapsService; - + @Value("#{configProperties['file.path']}") + private String FILE_PATH; + //最后一次同步时间 + private long lastSyncTime=-1L; /** * */ @@ -99,6 +106,35 @@ public class SyncDataWork { */ public static final String CHINA_BASIC_ID = "f6c505dd-835a-43d7-b0bb-fdb9eb0b7b31"; + private long readLastSyncTime(){ + try { + if(-1!=lastSyncTime){ + return lastSyncTime; + } + RandomAccessFile randomAccessFile=new RandomAccessFile(new File(FILE_PATH),"rw"); + String line =randomAccessFile.readLine(); + if(StringUtils.isNotEmpty(line)){ + lastSyncTime = Long.valueOf(line); + } + }catch (Exception e){ + logger.error("read last sync time error.",e); + } + return lastSyncTime; + } + + /** + * 持久化最后一次同步时间 + */ + private void writeLastSyncTime(){ + try { + lastSyncTime=System.currentTimeMillis(); + RandomAccessFile randomAccessFile=new RandomAccessFile(new File(FILE_PATH),"rw"); + randomAccessFile.writeLong(lastSyncTime); + randomAccessFile.close(); + }catch (Exception e){ + logger.error("read last sync time error.",e); + } + } /** * 加载全部省市区的数据到内存里面 */ @@ -131,8 +167,33 @@ public class SyncDataWork { } } - public void sync() { + private Hospitals fullHospital(Organization organization){ + Hospitals hospitals = ConvertHelper.convertHospital(organization); + if (null != organization.getAreaId()) { + BasicConfig basicConfig = basicConfigService.getOneBasicConfigById(organization.getAreaId()); + if (null != basicConfig) { + hospitals.setAreaId(mamiRegions.get(basicConfig.getName())); + } + } + if (null != organization.getCityId()) { + BasicConfig basicConfig1 = basicConfigService.getOneBasicConfigById(organization.getCityId()); + if (null != basicConfig1) { + hospitals.setCityId(mamiRegions.get(basicConfig1.getName())); + } + } + if (null != organization.getProvinceId()) { + BasicConfig basicConfig2 = basicConfigService.getOneBasicConfigById(organization.getProvinceId()); + if (null != basicConfig2) { + hospitals.setProvinceId(mamiRegions.get(basicConfig2.getName())); + } + } + return hospitals; + } + + public void sync() throws InterruptedException { long l = System.currentTimeMillis(); + //获取最后一次同步的时间 如果为-1就表示是全量同步 + readLastSyncTime(); logger.info("start sync at " + DateUtil.getyyyy_MM_dd(new Date())); //先加载省市区 loadMamiAllRegion(); @@ -141,35 +202,21 @@ public class SyncDataWork { organizationQuery.setYn(YnEnums.YES.getId()); //查询符合条件的机构 List organizationList = organizationService.queryOrganization(organizationQuery); + CountDownLatch countDownLatch=null;; if (CollectionUtils.isNotEmpty(organizationList)) { Hospitals hospitals = null; + countDownLatch =new CountDownLatch(organizationList.size()); for (Organization organization : organizationList) { HospitalsQuery hospitalsQuery = new HospitalsQuery(); hospitalsQuery.setForeignId(organization.getId() + ""); hospitalsQuery.setYn(YnEnums.YES.getId()); List hospitalsList = hospitalsService.queryHospitals(hospitalsQuery); if (CollectionUtils.isNotEmpty(hospitalsList)) { - hospitals = hospitalsList.get(0); + hospitals = fullHospital(organization); + hospitals.setId(hospitalsList.get(0).getId()); + hospitalsService.updateHospitals(hospitals); } else { - hospitals = ConvertHelper.convertHospital(organization); - if (null != organization.getAreaId()) { - BasicConfig basicConfig = basicConfigService.getOneBasicConfigById(organization.getAreaId()); - if (null != basicConfig) { - hospitals.setAreaId(mamiRegions.get(basicConfig.getName())); - } - } - if (null != organization.getCityId()) { - BasicConfig basicConfig1 = basicConfigService.getOneBasicConfigById(organization.getCityId()); - if (null != basicConfig1) { - hospitals.setCityId(mamiRegions.get(basicConfig1.getName())); - } - } - if (null != organization.getProvinceId()) { - BasicConfig basicConfig2 = basicConfigService.getOneBasicConfigById(organization.getProvinceId()); - if (null != basicConfig2) { - hospitals.setProvinceId(mamiRegions.get(basicConfig2.getName())); - } - } + fullHospital(organization); hospitalsService.addHospitals(hospitals); } @@ -178,12 +225,13 @@ public class SyncDataWork { } else { logger.warn("add hospital don't id."); } - new SyncWork(organization.getId() + "").start(); + workExecutor.execute(new SyncWork(organization.getId() + "",countDownLatch)); } } - - - logger.info("sync end costTime:" + (System.currentTimeMillis() - l) + "ms."); + countDownLatch.await(); + //持久化最后一次同步时间 + writeLastSyncTime(); + logger.info("sync end costTime:" + (System.currentTimeMillis() - l) + " ms."); } /** @@ -192,102 +240,123 @@ public class SyncDataWork { private class SyncWork extends Thread { private String hospitalId; + private CountDownLatch countDownLatch; private java.util.Map userMapping = new HashMap<>(); - public SyncWork(String hospitalId) { + public SyncWork(String hospitalId,CountDownLatch countDownLatch) { this.hospitalId = hospitalId; + this.countDownLatch=countDownLatch; } @Override public void run() { - logger.info("begin sync work hospital:" + hospitalId + ",at time " + DateUtil.getyyyy_MM_dd(new Date())); - //查询出该医院所以的医生用户 - UsersQuery usersQuery = new UsersQuery(); - usersQuery.setYn(YnEnums.YES.getId()); - usersQuery.setOrgId(Integer.valueOf(hospitalId)); - List userses = usersService.queryUsers(usersQuery); - DoctorUsers doctorUsers = null; - if (CollectionUtils.isNotEmpty(userses)) { - for (Users users : userses) { - DoctorUsersQuery doctorUsersQuery = new DoctorUsersQuery(); - doctorUsersQuery.setForeignId(users.getId() + ""); - doctorUsersQuery.setYn(YnEnums.YES.getId()); - List doctorUsersList = doctorUsersService.queryDoctorUsers(doctorUsersQuery); - if (CollectionUtils.isNotEmpty(doctorUsersList)) { - doctorUsers = doctorUsersList.get(0); - } else { - //医生用户转换 - doctorUsers = ConvertHelper.convertUsers(users); - doctorUsers.setHospitalId(orgMapToId.get(hospitalId)); - } + try { + logger.info("begin sync work hospital:" + hospitalId + ",at time " + DateUtil.getyyyy_MM_dd(new Date())); + //查询出该医院所以的医生用户 + UsersQuery usersQuery = new UsersQuery(); + usersQuery.setYn(YnEnums.YES.getId()); + usersQuery.setOrgId(Integer.valueOf(hospitalId)); + if(-1!=lastSyncTime){ + usersQuery.setGteModified(new Date(lastSyncTime)); + } + List userses = usersService.queryUsers(usersQuery); + DoctorUsers doctorUsers = null; + if (CollectionUtils.isNotEmpty(userses)) { + for (Users users : userses) { + DoctorUsersQuery doctorUsersQuery = new DoctorUsersQuery(); + doctorUsersQuery.setForeignId(users.getId() + ""); + doctorUsersQuery.setYn(YnEnums.YES.getId()); + List doctorUsersList = doctorUsersService.queryDoctorUsers(doctorUsersQuery); + if (CollectionUtils.isNotEmpty(doctorUsersList)) { + doctorUsers = ConvertHelper.convertUsers(users); + doctorUsers.setHospitalId(orgMapToId.get(hospitalId)); + doctorUsersService.updateDoctorUsers(doctorUsers); + } else { + //医生用户转换 + doctorUsers = ConvertHelper.convertUsers(users); + doctorUsers.setHospitalId(orgMapToId.get(hospitalId)); + doctorUsersService.addDoctorUsers(doctorUsers); + } - if (null != doctorUsers) { - doctorUsersService.addDoctorUsers(doctorUsers); - userMapping.put(users.getId(), doctorUsers.getId()); + if (null != doctorUsers) { + userMapping.put(users.getId(), doctorUsers.getId()); + } } } - } - PatientsQuery patientsQuery1 = new PatientsQuery(); - patientsQuery1.setYn(YnEnums.YES.getId()); - patientsQuery1.setHospitalId(hospitalId); - patientsQuery1.setNeed("1"); - patientsQuery1.setLimit(100); - List patientses = yunBookbuildingService.queryPregnantWithQuery(patientsQuery1); - if (CollectionUtils.isNotEmpty(patientses)) { - for (Patients patients : patientses) { - com.lymsh.mommybaby.maindata.model.Patients mamiPatient = ConvertHelper.convertPatient(patients); - DoctorUsersPatientsMaps doctorUsersPatientsMaps = new DoctorUsersPatientsMaps(); - doctorUsersPatientsMaps.setCreated(new Date()); - doctorUsersPatientsMaps.setYn(YnEnums.YES.getId()); + PatientsQuery patientsQuery1 = new PatientsQuery(); + patientsQuery1.setYn(YnEnums.YES.getId()); + patientsQuery1.setHospitalId(hospitalId); + patientsQuery1.setNeed("1"); + patientsQuery1.setLimit(500); + if(-1!=lastSyncTime){ + patientsQuery1.setGteModified(new Date(lastSyncTime)); + } - //门诊患者 - doctorUsersPatientsMaps.setGroupId(4); - //设置为待处理 - doctorUsersPatientsMaps.setStatus(1); - doctorUsersPatientsMaps.setStatusName("待处理"); + List patientses = yunBookbuildingService.queryPregnantWithQuery(patientsQuery1); + while (CollectionUtils.isNotEmpty(patientses)) { + for (Patients patients : patientses) { + com.lymsh.mommybaby.maindata.model.Patients mamiPatient = ConvertHelper.convertPatient(patients); + DoctorUsersPatientsMaps doctorUsersPatientsMaps = new DoctorUsersPatientsMaps(); + doctorUsersPatientsMaps.setCreated(new Date()); + doctorUsersPatientsMaps.setYn(YnEnums.YES.getId()); - //增加建档记录 - patientsService.aouPatients(mamiPatient); - doctorUsersPatientsMaps.setPatientId(mamiPatient.getId()); - if (StringUtils.isNotEmpty(patients.getBookbuildingDoctor())) { - doctorUsersPatientsMaps.setDoctorUserId(userMapping.get(Integer.valueOf(patients.getBookbuildingDoctor()))); - doctorUsersPatientsMapsService.aouDoctorUsersPatientsMaps(doctorUsersPatientsMaps); - } + //门诊患者 + doctorUsersPatientsMaps.setGroupId(4); + //设置为待处理 + doctorUsersPatientsMaps.setStatus(1); + doctorUsersPatientsMaps.setStatusName("待处理"); - AntExChuQuery antExChuQuery = new AntExChuQuery(); - antExChuQuery.setYn(YnEnums.YES.getId()); - antExChuQuery.setParentId(patients.getId()); - List antExChuModel = antenatalExaminationService.queryAntExChu(antExChuQuery); - if (CollectionUtils.isEmpty(antExChuModel)) { - continue; - } - for (AntExChuModel antExChuModel1 : antExChuModel) { - Reports reports = ConvertHelper.convertAntExChu(antExChuModel1, patients.getLastMenses()); - if (NumberUtils.isNumber(antExChuModel1.getProdDoctor())) { - Users users = usersService.getUsers(Integer.valueOf(antExChuModel1.getProdDoctor())); - if (null != users) { - reports.setDoctorName(users.getName()); - } + //增加建档记录 + patientsService.aouPatients(mamiPatient); + doctorUsersPatientsMaps.setPatientId(mamiPatient.getId()); + if (StringUtils.isNotEmpty(patients.getBookbuildingDoctor())) { + doctorUsersPatientsMaps.setDoctorUserId(userMapping.get(Integer.valueOf(patients.getBookbuildingDoctor()))); + doctorUsersPatientsMapsService.aouDoctorUsersPatientsMaps(doctorUsersPatientsMaps); } - reports.setPatientId(mamiPatient.getId()); - reports.setAge(patients.getAge()); - reports.setRealName(patients.getUsername()); - if (StringUtils.isNotEmpty(patients.getHospitalId())) { - Organization organization = organizationService.getOrganization(NumberUtils.toInt(patients.getHospitalId())); - if (null != organization) { - reports.setHospitalName(organization.getName()); + + AntExChuQuery antExChuQuery = new AntExChuQuery(); + antExChuQuery.setYn(YnEnums.YES.getId()); + antExChuQuery.setParentId(patients.getId()); + if(-1!=lastSyncTime){ + antExChuQuery.setGteModified(new Date(lastSyncTime)); + } + + List antExChuModel = antenatalExaminationService.queryAntExChu(antExChuQuery); + if (CollectionUtils.isEmpty(antExChuModel)) { + continue; + } + for (AntExChuModel antExChuModel1 : antExChuModel) { + Reports reports = ConvertHelper.convertAntExChu(antExChuModel1, patients.getLastMenses()); + if (NumberUtils.isNumber(antExChuModel1.getProdDoctor())) { + Users users = usersService.getUsers(Integer.valueOf(antExChuModel1.getProdDoctor())); + if (null != users) { + reports.setDoctorName(users.getName()); + } + } + reports.setPatientId(mamiPatient.getId()); + reports.setAge(patients.getAge()); + reports.setRealName(patients.getUsername()); + if (StringUtils.isNotEmpty(patients.getHospitalId())) { + Organization organization = organizationService.getOrganization(NumberUtils.toInt(patients.getHospitalId())); + if (null != organization) { + reports.setHospitalName(organization.getName()); + } } + reportsService.aouReports(reports); + com.lymsh.mommybaby.maindata.model.Patients p = new com.lymsh.mommybaby.maindata.model.Patients(); + p.setLastReportId(reports.getId()); + p.setLastReportDoctorName(reports.getDoctorName()); + p.setId(mamiPatient.getId()); + patientsService.updatePatients(p); } - reportsService.aouReports(reports); - com.lymsh.mommybaby.maindata.model.Patients p = new com.lymsh.mommybaby.maindata.model.Patients(); - p.setLastReportId(reports.getId()); - p.setLastReportDoctorName(reports.getDoctorName()); - p.setId(mamiPatient.getId()); - patientsService.updatePatients(p); } } + } catch (Exception e) { + e.printStackTrace(); + } finally { + countDownLatch.countDown(); } } } diff --git a/platform-job-index/src/main/resources/conf.properties b/platform-job-index/src/main/resources/conf.properties index 766b16b..c18502b 100644 --- a/platform-job-index/src/main/resources/conf.properties +++ b/platform-job-index/src/main/resources/conf.properties @@ -47,4 +47,6 @@ redis.servers=localhost:6379 report.db.jdbcurl=jdbc:oracle:thin:@192.168.1.32:1521:orcl report.db.username=LYMS_ODS -report.db.password=Welcome1 \ No newline at end of file +report.db.password=Welcome1 + +file.path=c:// \ No newline at end of file