|
@ -1,9 +1,12 @@
|
|
|
package com.yihu.wlyy.web.data;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.yihu.device.entity.DeviceDetail;
|
|
|
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.device.PatientDeviceLog;
|
|
|
import com.yihu.wlyy.entity.doctor.profile.Doctor;
|
|
|
import com.yihu.wlyy.entity.manage.User;
|
|
|
import com.yihu.wlyy.entity.patient.Patient;
|
|
@ -11,22 +14,26 @@ 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.Base64Utils;
|
|
|
import com.yihu.wlyy.util.ElasticsearchUtil;
|
|
|
import com.yihu.wlyy.util.LatitudeUtils;
|
|
|
import com.yihu.wlyy.util.MD5;
|
|
|
import com.yihu.wlyy.repository.patient.PatientDeviceLogDao;
|
|
|
import com.yihu.wlyy.service.app.device.DeviceDetailService;
|
|
|
import com.yihu.wlyy.service.app.device.PatientDeviceService;
|
|
|
import com.yihu.wlyy.util.*;
|
|
|
import net.sf.json.JSONArray;
|
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
|
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.jdbc.core.BatchPreparedStatementSetter;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.jdbc.core.RowMapper;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.sql.PreparedStatement;
|
|
|
import java.sql.ResultSet;
|
|
|
import java.sql.SQLException;
|
|
|
import java.util.*;
|
|
@ -49,6 +56,10 @@ public class DataHandingService {
|
|
|
@Autowired
|
|
|
private PatientDeviceDao patientDeviceDao;
|
|
|
@Autowired
|
|
|
private PatientDeviceLogDao patientDeviceLogDao;
|
|
|
@Autowired
|
|
|
private DeviceDetailService deviceDetailService;
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
@Transactional
|
|
@ -118,7 +129,7 @@ public class DataHandingService {
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
|
private void saveUser(Doctor doctor) {
|
|
|
public void saveUser(Doctor doctor) {
|
|
|
User userTemp = new User();
|
|
|
userTemp.setCode(doctor.getCode());
|
|
|
userTemp.setMobile(doctor.getMobile());
|
|
@ -230,4 +241,112 @@ public class DataHandingService {
|
|
|
}
|
|
|
return flag;
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void updateToPaitentDevcieLog()throws Exception{
|
|
|
List<PatientDevice> patientDeviceList = patientDeviceDao.findAll();
|
|
|
List<PatientDeviceLog> patientDeviceLogList = new ArrayList<>();
|
|
|
for (PatientDevice patientDevice : patientDeviceList){
|
|
|
PatientDeviceLog patientDeviceLog = new PatientDeviceLog();
|
|
|
patientDeviceLog.setDeviceId(patientDevice.getDeviceId());
|
|
|
patientDeviceLog.setAgreementPhoto(patientDevice.getAgreementPhoto());
|
|
|
if (!StringUtils.isEmpty(patientDevice.getDoctor())){
|
|
|
patientDeviceLog.setOperator(patientDevice.getDoctor());
|
|
|
patientDeviceLog.setOperatorName(patientDevice.getDoctorName());
|
|
|
patientDeviceLog.setRole(1);
|
|
|
}else if (!StringUtils.isEmpty(patientDevice.getAgent())){
|
|
|
patientDeviceLog.setOperator(patientDevice.getAgent());
|
|
|
patientDeviceLog.setOperatorName(patientDevice.getAgentName());
|
|
|
patientDeviceLog.setRole(2);
|
|
|
}
|
|
|
patientDeviceLog.setCreateTime(patientDevice.getCzrq());
|
|
|
patientDeviceLog.setDeviceSn(patientDevice.getDeviceSn());
|
|
|
patientDeviceLog.setDeviceName(patientDevice.getDeviceName());
|
|
|
patientDeviceLog.setCategoryCode(patientDevice.getCategoryCode());
|
|
|
patientDeviceLog.setPatient(patientDevice.getUser());
|
|
|
patientDeviceLog.setOperateCode(1);
|
|
|
patientDeviceLog.setIsDel(1);
|
|
|
patientDeviceLogList.add(patientDeviceLog);
|
|
|
}
|
|
|
patientDeviceLogDao.save(patientDeviceLogList);
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void updateDevice()throws Exception{
|
|
|
String patientDeviceSql = "SELECT pd.*,sf.admin_team_code,sf.hospital FROM wlyy_patient_device pd LEFT JOIN wlyy_sign_family sf ON pd.`user` = sf.patient where sf.`status`>0 GROUP BY pd.id";
|
|
|
List<Map<String,Object>> patientDeviceList = jdbcTemplate.queryForList(patientDeviceSql);
|
|
|
String deviceSql = "SELECT * FROM device.wlyy_devices";
|
|
|
List<DeviceDetail> deviceDetailList = jdbcTemplate.query(deviceSql,new BeanPropertyRowMapper<>(DeviceDetail.class));
|
|
|
List<String> sqlList = new ArrayList<>();
|
|
|
Map<String,List<String>> map = new HashedMap();
|
|
|
for (Map<String,Object> patientDeviceMap : patientDeviceList) {
|
|
|
List<String> userTypeList = null;
|
|
|
if (map.containsKey(String.valueOf(patientDeviceMap.get("device_sn")))) {
|
|
|
userTypeList = map.get(String.valueOf(patientDeviceMap.get("device_sn")));
|
|
|
if (userTypeList == null) {
|
|
|
userTypeList = new ArrayList<>();
|
|
|
userTypeList.add(String.valueOf(patientDeviceMap.get("user_type")));
|
|
|
map.put(String.valueOf(patientDeviceMap.get("device_sn")), userTypeList);
|
|
|
} else {
|
|
|
boolean flag = false;
|
|
|
if (!userTypeList.contains(String.valueOf(patientDeviceMap.get("user_type")))) {
|
|
|
flag = true;
|
|
|
}
|
|
|
if (flag) {
|
|
|
userTypeList.add(String.valueOf(patientDeviceMap.get("user_type")));
|
|
|
map.put(String.valueOf(patientDeviceMap.get("device_sn")), userTypeList);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
for (Map<String,Object> patientDeviceMap : patientDeviceList) {
|
|
|
String deviceSn = String.valueOf(patientDeviceMap.get("device_sn"));
|
|
|
int i = 0;
|
|
|
for (DeviceDetail deviceDetail: deviceDetailList){
|
|
|
if (deviceDetail.getDeviceCode().equals(deviceSn)){
|
|
|
i++;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
PatientDevice patientDevice = MapListUtils.convertMap2Bean(patientDeviceMap,PatientDevice.class);
|
|
|
if (i==1){
|
|
|
List<String> userTypeList = map.get(patientDevice.getDeviceSn());
|
|
|
String bindCount = "";
|
|
|
int size = userTypeList.size();
|
|
|
if (size==1){
|
|
|
if (Integer.valueOf(patientDevice.getUserType())>0 && Integer.valueOf(patientDevice.getUserType())==1){
|
|
|
bindCount = "{\"1\":\"1\",\"2\":\"0\"}";
|
|
|
}else if (Integer.valueOf(patientDevice.getUserType())>0 && Integer.valueOf(patientDevice.getUserType())==2){
|
|
|
bindCount = "{\"1\":\"0\",\"2\":\"1\"}";
|
|
|
}else if (Integer.valueOf(patientDevice.getUserType())<0){
|
|
|
bindCount = "{\"1\":\"1\"}";
|
|
|
}
|
|
|
}else if (size>1){
|
|
|
if (Integer.valueOf(patientDevice.getUserType())>0){
|
|
|
bindCount = "{\"1\":\"1\",\"2\":\"1\"}";
|
|
|
}else if (Integer.valueOf(patientDevice.getUserType())<0){
|
|
|
bindCount = "{\"1\":\"2\"}";
|
|
|
}
|
|
|
}
|
|
|
String sql = "UPDATE device.wlyy_devices SET is_grant=1,grant_admin_team='"+String.valueOf(patientDeviceMap.get
|
|
|
("admin_team_code"))+"',grant_org_code='"+String.valueOf(patientDeviceMap.get("hospital"))+"',is_binding="+size+",binding_count='"+bindCount
|
|
|
+"',grant_time="+patientDevice.getCzrq()+" where device_code='"+patientDevice.getDeviceSn()+"'";
|
|
|
jdbcTemplate.update(sql);
|
|
|
}
|
|
|
//如果wlyy_devices表里没有对应的数据 则增加一条。
|
|
|
if (i==0){
|
|
|
String bindCount = "";
|
|
|
if (Integer.valueOf(patientDevice.getUserType())>0 && Integer.valueOf(patientDevice.getUserType())==1){
|
|
|
bindCount = "{\"1\":\"1\",\"2\":\"0\"}";
|
|
|
}else if (Integer.valueOf(patientDevice.getUserType())>0 && Integer.valueOf(patientDevice.getUserType())==2){
|
|
|
bindCount = "{\"1\":\"0\",\"2\":\"1\"}";
|
|
|
}else if (Integer.valueOf(patientDevice.getUserType())<0){
|
|
|
bindCount = "{\"1\":\"1\"}";
|
|
|
}
|
|
|
deviceDetailService.insertDevice(patientDevice,String.valueOf(patientDeviceMap.get("admin_team_code")),String.valueOf(patientDeviceMap.get("hospital_name")),String.valueOf(patientDeviceMap.get("hospital")),bindCount);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|