|
@ -274,37 +274,82 @@ public class DataHandingService {
|
|
|
patientDeviceLogDao.save(patientDeviceLogList);
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean updateDeviceDefalut(){
|
|
|
boolean flag = true;
|
|
|
try{
|
|
|
String deviceSql = "SELECT wd.*,dd.category_code,dd.is_multi_user FROM device.wlyy_devices wd LEFT JOIN wlyy.dm_device dd ON wd.device_model = dd.model";
|
|
|
List<Map<String,Object>> deviceDetailList = jdbcTemplate.queryForList(deviceSql);
|
|
|
//把wlyy_devices库里bindCount先补充默认值
|
|
|
List<String> deviceSqlList = new ArrayList<>();
|
|
|
for (Map<String,Object> deviceMap : deviceDetailList){
|
|
|
String bindingCount="";
|
|
|
if (StringUtils.isEmpty(String.valueOf(deviceMap.get("binding_count"))) || StringUtils.pathEquals("null",String.valueOf(deviceMap.get("binding_count")))){
|
|
|
if (org.apache.commons.lang3.StringUtils.isNotEmpty(String.valueOf(deviceMap.get("is_multi_user"))) && StringUtils.pathEquals("0",String.valueOf(deviceMap.get("is_multi_user")))){
|
|
|
bindingCount="{\"1\":\"0\"}";
|
|
|
}else if (org.apache.commons.lang3.StringUtils.isNotEmpty(String.valueOf(deviceMap.get("is_multi_user"))) && StringUtils.pathEquals("1",String.valueOf(deviceMap.get("is_multi_user")))){
|
|
|
bindingCount="{\"1\":\"0\",\"2\":\"0\"}";
|
|
|
}else if (StringUtils.isEmpty(String.valueOf(deviceMap.get("is_multi_user"))) || StringUtils.pathEquals("null",String.valueOf(deviceMap.get("is_multi_user")))){
|
|
|
if (String.valueOf(deviceMap.get("device_name")).contains("血糖")){
|
|
|
bindingCount="{\"1\":\"0\"}";
|
|
|
}
|
|
|
if (String.valueOf(deviceMap.get("device_name")).contains("血压")){
|
|
|
bindingCount="{\"1\":\"0\",\"2\":\"0\"}";
|
|
|
}
|
|
|
}
|
|
|
//String updateDeviceSql = ;
|
|
|
deviceSqlList.add("UPDATE device.wlyy_devices SET binding_count='"+bindingCount +"' where device_code='"+String.valueOf(deviceMap.get("device_code"))+"'");
|
|
|
}
|
|
|
}
|
|
|
String deviceStr[] = new String[deviceSqlList.size()];
|
|
|
deviceStr = deviceSqlList.toArray(deviceStr);
|
|
|
jdbcTemplate.batchUpdate(deviceStr);
|
|
|
}catch (Exception e){
|
|
|
flag = false;
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return flag;
|
|
|
}
|
|
|
|
|
|
@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";
|
|
|
//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";
|
|
|
String patientDeviceSql = "SELECT pd.id,pd.device_id AS deviceId,pd.category_code categoryCode,pd.device_name deviceName,pd.device_sn deviceSn,pd.`user`,pd.user_type userType,pd.czrq,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));
|
|
|
|
|
|
//封装设备与患者表的数据,一个设备多键
|
|
|
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 (map.containsKey(String.valueOf(patientDeviceMap.get("deviceSn")))) {
|
|
|
userTypeList = map.get(String.valueOf(patientDeviceMap.get("deviceSn")));
|
|
|
if (userTypeList == null) {
|
|
|
userTypeList = new ArrayList<>();
|
|
|
userTypeList.add(String.valueOf(patientDeviceMap.get("user_type")));
|
|
|
map.put(String.valueOf(patientDeviceMap.get("device_sn")), userTypeList);
|
|
|
userTypeList.add(String.valueOf(patientDeviceMap.get("userType")));
|
|
|
map.put(String.valueOf(patientDeviceMap.get("deviceSn")), userTypeList);
|
|
|
} else {
|
|
|
boolean flag = false;
|
|
|
if (!userTypeList.contains(String.valueOf(patientDeviceMap.get("user_type")))) {
|
|
|
if (!userTypeList.contains(String.valueOf(patientDeviceMap.get("userType")))) {
|
|
|
flag = true;
|
|
|
}
|
|
|
if (flag) {
|
|
|
userTypeList.add(String.valueOf(patientDeviceMap.get("user_type")));
|
|
|
map.put(String.valueOf(patientDeviceMap.get("device_sn")), userTypeList);
|
|
|
userTypeList.add(String.valueOf(patientDeviceMap.get("userType")));
|
|
|
map.put(String.valueOf(patientDeviceMap.get("deviceSn")), userTypeList);
|
|
|
}
|
|
|
}
|
|
|
}else {
|
|
|
userTypeList = new ArrayList<>();
|
|
|
userTypeList.add(String.valueOf(patientDeviceMap.get("userType")));
|
|
|
map.put(String.valueOf(patientDeviceMap.get("deviceSn")), userTypeList);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
List<String> sqlList = new ArrayList<>();
|
|
|
for (Map<String,Object> patientDeviceMap : patientDeviceList) {
|
|
|
String deviceSn = String.valueOf(patientDeviceMap.get("device_sn"));
|
|
|
String deviceSn = String.valueOf(patientDeviceMap.get("deviceSn"));
|
|
|
int i = 0;
|
|
|
for (DeviceDetail deviceDetail: deviceDetailList){
|
|
|
if (deviceDetail.getDeviceCode().equals(deviceSn)){
|
|
@ -334,8 +379,8 @@ public class DataHandingService {
|
|
|
}
|
|
|
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);
|
|
|
+"',grant_time='"+DateUtil.dateToStr(patientDevice.getCzrq(),"yyyy-MM-dd HH:mm:ss")+"' where device_code='"+patientDevice.getDeviceSn()+"'";
|
|
|
sqlList.add(sql);
|
|
|
}
|
|
|
//如果wlyy_devices表里没有对应的数据 则增加一条。
|
|
|
if (i==0){
|
|
@ -350,6 +395,9 @@ public class DataHandingService {
|
|
|
deviceDetailService.insertDevice(patientDevice,String.valueOf(patientDeviceMap.get("admin_team_code")),String.valueOf(patientDeviceMap.get("hospital_name")),String.valueOf(patientDeviceMap.get("hospital")),bindCount);
|
|
|
}
|
|
|
}
|
|
|
String[] sqlStr = new String[sqlList.size()];
|
|
|
sqlStr = sqlList.toArray(sqlStr);
|
|
|
jdbcTemplate.batchUpdate(sqlStr);
|
|
|
}
|
|
|
|
|
|
public void addPointOldDeviceBind()throws Exception{
|