|
@ -1,25 +1,30 @@
|
|
|
package com.yihu.wlyy.web.data;
|
|
|
|
|
|
import com.yihu.es.entity.HealthEduArticleES;
|
|
|
import com.yihu.es.entity.MapDataDTO;
|
|
|
import com.yihu.wlyy.config.es.ElastricSearchSave;
|
|
|
import com.yihu.wlyy.entity.device.PatientDevice;
|
|
|
import com.yihu.wlyy.entity.doctor.profile.Doctor;
|
|
|
import com.yihu.wlyy.entity.manage.User;
|
|
|
import com.yihu.wlyy.entity.patient.Patient;
|
|
|
import com.yihu.wlyy.repository.doctor.DoctorDao;
|
|
|
import com.yihu.wlyy.repository.manage.UserDao;
|
|
|
import com.yihu.wlyy.repository.patient.PatientDao;
|
|
|
import com.yihu.wlyy.repository.patient.PatientDeviceDao;
|
|
|
import com.yihu.wlyy.util.ElasticsearchUtil;
|
|
|
import com.yihu.wlyy.util.LatitudeUtils;
|
|
|
import com.yihu.wlyy.util.MD5;
|
|
|
import net.sf.json.JSONArray;
|
|
|
import org.json.JSONObject;
|
|
|
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.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.UUID;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* Created by Administrator on 2016.10.17.
|
|
@ -36,43 +41,46 @@ public class DataHandingService {
|
|
|
private ElasticsearchUtil elasticsearchUtil;
|
|
|
@Autowired
|
|
|
private ElastricSearchSave elastricSearchSave;
|
|
|
@Autowired
|
|
|
private PatientDeviceDao patientDeviceDao;
|
|
|
|
|
|
@Transactional
|
|
|
public String producePatientAndDoctorPassword() {
|
|
|
int patientCount=0;
|
|
|
int patientErrorCount=0;
|
|
|
int doctorCount=0;
|
|
|
int doctorErrorCount=0;
|
|
|
List<Patient> patients= patientDao.findAllIdCardPatientAndNoPassword();
|
|
|
for (Patient patient:patients){
|
|
|
String idcard=patient.getIdcard();
|
|
|
if(!StringUtils.isEmpty(patient.getPassword())||StringUtils.isEmpty(idcard)||(idcard.length()!=15&&idcard.length()!=18)){
|
|
|
int patientCount = 0;
|
|
|
int patientErrorCount = 0;
|
|
|
int doctorCount = 0;
|
|
|
int doctorErrorCount = 0;
|
|
|
List<Patient> patients = patientDao.findAllIdCardPatientAndNoPassword();
|
|
|
for (Patient patient : patients) {
|
|
|
String idcard = patient.getIdcard();
|
|
|
if (!StringUtils.isEmpty(patient.getPassword()) || StringUtils.isEmpty(idcard) || (idcard.length() != 15 && idcard.length() != 18)) {
|
|
|
patientErrorCount++;
|
|
|
continue;
|
|
|
}
|
|
|
String password=idcard.substring(idcard.length()-6);
|
|
|
String salt= UUID.randomUUID().toString().replace("-","");
|
|
|
String password = idcard.substring(idcard.length() - 6);
|
|
|
String salt = UUID.randomUUID().toString().replace("-", "");
|
|
|
patient.setSalt(salt);
|
|
|
patient.setPassword(MD5.GetMD5Code(password+salt));
|
|
|
patient.setPassword(MD5.GetMD5Code(password + salt));
|
|
|
patientCount++;
|
|
|
}
|
|
|
patientDao.save(patients);
|
|
|
List<Doctor> doctors= doctorDao.findAllDoctors();
|
|
|
for (Doctor doctor:doctors){
|
|
|
String phone= doctor.getMobile();
|
|
|
if(!StringUtils.isEmpty(doctor.getPassword())||StringUtils.isEmpty(phone)||phone.length()!=11){
|
|
|
List<Doctor> doctors = doctorDao.findAllDoctors();
|
|
|
for (Doctor doctor : doctors) {
|
|
|
String phone = doctor.getMobile();
|
|
|
if (!StringUtils.isEmpty(doctor.getPassword()) || StringUtils.isEmpty(phone) || phone.length() != 11) {
|
|
|
doctorErrorCount++;
|
|
|
continue;
|
|
|
}
|
|
|
String password=phone.substring(5);
|
|
|
String salt= UUID.randomUUID().toString().replace("-","");
|
|
|
String password = phone.substring(5);
|
|
|
String salt = UUID.randomUUID().toString().replace("-", "");
|
|
|
doctor.setSalt(salt);
|
|
|
doctor.setPassword(MD5.GetMD5Code(password+salt));
|
|
|
doctor.setPassword(MD5.GetMD5Code(password + salt));
|
|
|
doctorCount++;
|
|
|
}
|
|
|
doctorDao.save(doctors);
|
|
|
return "更新患者(默认身份证后六位):"+patientCount+",有身份证异常的患者:"+patientErrorCount+",更新医生(默认电话后六位):"+doctorCount+",有电话号码异常的医生:"+doctorErrorCount;
|
|
|
return "更新患者(默认身份证后六位):" + patientCount + ",有身份证异常的患者:" + patientErrorCount + ",更新医生(默认电话后六位):" + doctorCount + ",有电话号码异常的医生:" + doctorErrorCount;
|
|
|
}
|
|
|
|
|
|
public String initWLyyDoctorTable2WLyyUserTable() {
|
|
|
JSONObject returnjo = new JSONObject();
|
|
|
List<Doctor> doctors = doctorDao.findAllDoctors();
|
|
@ -113,9 +121,73 @@ public class DataHandingService {
|
|
|
userDao.save(userTemp);
|
|
|
}
|
|
|
|
|
|
public Boolean esToEs(){
|
|
|
public Boolean esToEs() {
|
|
|
String sql = " SELECT * FROM health_edu_article_patient_test ";
|
|
|
List<HealthEduArticleES> esList = elasticsearchUtil.excute(sql, HealthEduArticleES.class, "health_edu_article_patient_test", "health_edu_article_patient_test");
|
|
|
return elastricSearchSave.save(esList, "health_edu_article_patient", "health_edu_article_patient");
|
|
|
return elastricSearchSave.save(esList, "health_edu_article_patient", "health_edu_article_patient");
|
|
|
}
|
|
|
|
|
|
@Value("${es.index.patientDevice}")
|
|
|
private String patientDeviceIndex;
|
|
|
@Value("${es.type.patientDevice}")
|
|
|
private String patientDeviceType;
|
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(DataHandingService.class);
|
|
|
|
|
|
public net.sf.json.JSONObject deviceData2Es() {
|
|
|
net.sf.json.JSONObject jo = new net.sf.json.JSONObject();
|
|
|
try {
|
|
|
//得到已经已经绑定的体征设备
|
|
|
List<PatientDevice> patientDevices = patientDeviceDao.findWithArrdess();
|
|
|
|
|
|
List<MapDataDTO> dataDTOs = new ArrayList<>();
|
|
|
|
|
|
Integer error = 0;
|
|
|
for (int i = 0; i < patientDevices.size(); i++) {
|
|
|
PatientDevice one = patientDevices.get(i);
|
|
|
MapDataDTO mapDataDTO = new MapDataDTO();
|
|
|
mapDataDTO.setCreateTime(new Date());
|
|
|
mapDataDTO.setDeviceTime(one.getCzrq());
|
|
|
mapDataDTO.setDeviceId(one.getDeviceId());
|
|
|
mapDataDTO.setDeviceSn(one.getDeviceSn());
|
|
|
mapDataDTO.setIdCard(one.getUserIdcard());
|
|
|
if (StringUtils.isEmpty(one.getAddress())) {
|
|
|
error++;
|
|
|
continue;
|
|
|
}
|
|
|
Map<String, String> json = LatitudeUtils.getGeocoderLatitude(one.getAddress().replace("G.", "").replace("(糖友网)", "").replace("(高友网)", ""));
|
|
|
if (json == null) {
|
|
|
error++;
|
|
|
continue;
|
|
|
}
|
|
|
logger.info("地址:," + one.getAddress() + "坐标" + json.toString());
|
|
|
mapDataDTO.setLocation(Double.valueOf(json.get("lat")), Double.valueOf(json.get("lng")));
|
|
|
dataDTOs.add(mapDataDTO);
|
|
|
}
|
|
|
elastricSearchSave.save(dataDTOs, patientDeviceIndex, patientDeviceType);
|
|
|
return jo;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
return jo;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public JSONArray getAllDeviceData() {
|
|
|
JSONArray ja = new JSONArray();
|
|
|
List<Map<String, Object>> returnData = elasticsearchUtil.excuteDataModel("SELECT location,idCard FROM wlyy_patient_device");
|
|
|
returnData.stream().forEach(one->{
|
|
|
net.sf.json.JSONObject jo=new net.sf.json.JSONObject();
|
|
|
jo.put("idcard",one.get("idCard"));
|
|
|
|
|
|
net.sf.json.JSONObject locatio=new net.sf.json.JSONObject();
|
|
|
locatio.put("lat",one.get("location.lat")); //纬度 -90 ~~ 90
|
|
|
locatio.put("lon",one.get("location.lon")); //经度 -180 ~~ 180
|
|
|
jo.put("location",locatio);
|
|
|
|
|
|
|
|
|
ja.add(jo);
|
|
|
});
|
|
|
return ja;
|
|
|
}
|
|
|
}
|