|
@ -0,0 +1,95 @@
|
|
|
package com.yihu.iot.service.monitorPlatform;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
import com.yihu.iot.dao.platform.WlyyCopdXeekLungDao;
|
|
|
import com.yihu.iot.dao.platform.WlyyCopdXeekLungDetailDao;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* Created by Bing on 2021/4/14.
|
|
|
*
|
|
|
*/
|
|
|
@Service
|
|
|
public class CopdXeekDeviceService {
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
@Autowired
|
|
|
private WlyyCopdXeekLungDetailDao lungDetailDao;
|
|
|
@Autowired
|
|
|
private WlyyCopdXeekLungDao lungDao;
|
|
|
|
|
|
public JSONObject getDeviceData(String patient,String deviceSN, String reportType, String parameter, String time, String begin, String end){
|
|
|
List<Map<String,Object>> detailList = new ArrayList<>();
|
|
|
StringBuilder sql = new StringBuilder(" select de.*,dict.name,lu.inspect_time from xmiot.wlyy_copd_xeek_lung_detail de," +
|
|
|
"xmiot.wlyy_copd_xeek_lung lu, xmiot.wlyy_iot_tz_dict dict where de.code = lu.id and dict.del=1 " +
|
|
|
"and dict.code='COPD_PARAMETER' and dict.value = de.parameter ");
|
|
|
|
|
|
if (StringUtils.isNotBlank(patient)){
|
|
|
sql.append(" and lu.patient='"+patient+"' ");
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(deviceSN)){
|
|
|
sql.append(" and lu.device_sn='"+deviceSN+"' ");
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(reportType)){
|
|
|
sql.append(" and lu.report_type='"+reportType+"' ");
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(parameter)){
|
|
|
sql.append(" and de.parameter='"+parameter+"' ");
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(begin)){
|
|
|
sql.append(" and lu.inspect_time>='"+begin+"' ");
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(end)){
|
|
|
sql.append(" and lu.inspect_time<='"+end+"' ");
|
|
|
}
|
|
|
sql.append(" order by de.parameter, lu.inspect_time asc ");
|
|
|
detailList = jdbcTemplate.queryForList(sql.toString());
|
|
|
StringBuilder sqlIn= new StringBuilder("select count(de.id) test1_value ,'次' unit,'吸气训练数据' name,'inCount' parameter from xmiot.wlyy_copd_xeek_lung_detail de,xmiot.wlyy_copd_xeek_lung lu," +
|
|
|
" xmiot.wlyy_iot_tz_dict dict where de.code = lu.id and dict.del=1 \n" +
|
|
|
"and dict.code='COPD_PARAMETER' and dict.value = de.parameter and de.parameter='MIP' GROUP BY LEFT(inspect_time,10) ");
|
|
|
|
|
|
|
|
|
StringBuilder sqlOut= new StringBuilder("select count(de.id) test1_value ,'次' unit,'呼气训练数据' name,'outCount' parameter from xmiot.wlyy_copd_xeek_lung_detail de,xmiot.wlyy_copd_xeek_lung lu," +
|
|
|
" xmiot.wlyy_iot_tz_dict dict where de.code = lu.id and dict.del=1 \n" +
|
|
|
"and dict.code='COPD_PARAMETER' and dict.value = de.parameter and de.parameter='FVC' GROUP BY LEFT(inspect_time,10)");
|
|
|
sql = new StringBuilder("");
|
|
|
if (StringUtils.isNotBlank(patient)){
|
|
|
sql.append(" and lu.patient='"+patient+"' ");
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(deviceSN)){
|
|
|
sql.append(" and lu.device_sn='"+deviceSN+"' ");
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(reportType)){
|
|
|
sql.append(" and lu.report_type='"+reportType+"' ");
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(begin)){
|
|
|
sql.append(" and lu.inspect_time>='"+begin+"' ");
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(end)){
|
|
|
sql.append(" and lu.inspect_time<='"+end+"' ");
|
|
|
}
|
|
|
|
|
|
if ((StringUtils.isNotBlank(parameter)&¶meter.equals("inCount"))||StringUtils.isBlank(parameter)){//吸气训练次数 MIP
|
|
|
List<Map<String,Object>> tmp = jdbcTemplate.queryForList(sqlIn.append(sql).toString());
|
|
|
detailList.addAll(tmp);
|
|
|
}
|
|
|
if ((StringUtils.isNotBlank(parameter)&¶meter.equals("outCount"))||StringUtils.isBlank(parameter)){//呼气训练次数 FVC
|
|
|
List<Map<String,Object>> tmp = jdbcTemplate.queryForList(sqlOut.append(sql).toString());
|
|
|
detailList.addAll(tmp);
|
|
|
}
|
|
|
Map<String,List<Map<String,Object>>> filterMap = detailList.stream().collect(Collectors.groupingBy(e -> e.get("parameter").toString()));
|
|
|
|
|
|
String jsonStr = JSON.toJSONString(filterMap, SerializerFeature.WriteMapNullValue);
|
|
|
return JSONObject.parseObject(jsonStr);
|
|
|
}
|
|
|
}
|