|
@ -20,6 +20,7 @@ import com.yihu.wlyy.util.ElasticsearchUtil;
|
|
|
import com.yihu.wlyy.web.quota.vo.SaveModel;
|
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.hibernate.type.StringClobType;
|
|
|
import org.json.JSONArray;
|
|
|
import org.json.JSONObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@ -5573,15 +5574,15 @@ public class StatisticsESService {
|
|
|
int map1value = 0;
|
|
|
int map2value = 0;
|
|
|
if(sortType==1){
|
|
|
map1value = (int) o1.get("allNum");
|
|
|
map2value = (int) o2.get("allNum");
|
|
|
map1value = Integer.valueOf(o1.get("allNum").toString());
|
|
|
map2value = Integer.valueOf(o2.get("allNum").toString());
|
|
|
|
|
|
}else if(sortType==2){
|
|
|
map1value = (int) o1.get("bindingNum");
|
|
|
map2value = (int) o2.get("bindingNum");
|
|
|
map1value = Integer.valueOf(o1.get("bindingNum").toString());
|
|
|
map2value = Integer.valueOf(o2.get("bindingNum").toString());
|
|
|
}else {
|
|
|
map1value = (int) o1.get("rateNum");
|
|
|
map2value = (int) o2.get("rateNum");
|
|
|
map1value = Integer.valueOf(o1.get("rateNum").toString());
|
|
|
map2value = Integer.valueOf(o2.get("rateNum").toString());
|
|
|
}
|
|
|
if (map1value - map2value > 0) {
|
|
|
return sort == 1 ? -1 : 1;
|
|
@ -5616,14 +5617,16 @@ public class StatisticsESService {
|
|
|
}
|
|
|
|
|
|
if (hospitals != null && hospitals.size() > 0) {
|
|
|
int amount = 0;
|
|
|
int allNum = 0;
|
|
|
for (Hospital hos : hospitals) {
|
|
|
if (hos.getCode().length() > 10) {
|
|
|
continue;
|
|
|
}
|
|
|
// String sql = " select count(DISTINCT p.doctor,p.device_sn) AS amount,p.doctor as doctorCode,r.name as doctorName from wlyy.wlyy_patient_device p JOIN wlyy.wlyy_doctor r on p.doctor is not null and p.doctor =r.code LEFT JOIN device.wlyy_devices d on p.device_sn=d.device_code where p.del=0 and p.doctor is not null and d.grant_org_code ='" + hos.getCode() + "' group by p.doctor,r.name";
|
|
|
String sql = " select count(*) as amount,if(a.doctor is null,'other',a.doctor) as doctorCode,if(a.NAME is null,'其他',a.NAME) as doctorName " +
|
|
|
" from (select DISTINCT p.doctor,r.name,p.device_sn FROM wlyy.wlyy_patient_device p left join device.wlyy_devices d on p.device_sn=d.device_code left JOIN wlyy.wlyy_doctor r ON p.doctor = r. CODE " +
|
|
|
"where p.del=0 and d.is_binding in (1,2) and d.grant_org_code ='" + hos.getCode() + "') a " +
|
|
|
" from (select DISTINCT p.doctor,r.name,p.device_sn FROM wlyy.wlyy_patient_device p RIGHT join device.wlyy_devices d on p.device_sn=d.device_code left JOIN wlyy.wlyy_doctor r ON p.doctor = r. CODE " +
|
|
|
"where p.del=0 and d.is_binding in (1,2) and p.category_code in('1','2') and d.grant_org_code ='" + hos.getCode() + "') a " +
|
|
|
" GROUP BY a.doctor,a.name";
|
|
|
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
for (Map<String, Object> one : list) {
|
|
@ -5632,9 +5635,23 @@ public class StatisticsESService {
|
|
|
obj.put("name", one.get("doctorName"));
|
|
|
obj.put("amount", one.get("amount"));
|
|
|
obj = deviceRateList(obj,hos);
|
|
|
if("other".equals(one.get("doctorCode")+"")){
|
|
|
amount += Integer.valueOf(obj.get("amount")+"");
|
|
|
allNum += Integer.valueOf(obj.get("allNum")+"");
|
|
|
continue;
|
|
|
}
|
|
|
resultList.add(obj);
|
|
|
}
|
|
|
}
|
|
|
Map<String, Object> otherObj = new HashMap<>();
|
|
|
otherObj.put("code", "other");
|
|
|
otherObj.put("name", "其他");
|
|
|
otherObj.put("amount", amount);
|
|
|
otherObj.put("allNum", allNum);
|
|
|
otherObj.put("bindingNum", amount);
|
|
|
otherObj.put("rate", getRange(amount, allNum, 2));//续签率是 续签量/去年的签约数
|
|
|
otherObj.put("rateNum", getRangeNum(amount, allNum, 2));//续签率是 续签量/去年的签约数
|
|
|
resultList.add(otherObj);
|
|
|
}
|
|
|
// }
|
|
|
return resultList;
|
|
@ -5754,7 +5771,7 @@ public class StatisticsESService {
|
|
|
String temp = "other".equals(reMap.get("code"))? " and p.doctor is null ":" and p.doctor='"+reMap.get("code")+"' ";
|
|
|
String sql = " select count(1) as amount " +
|
|
|
" from (select DISTINCT p.doctor,r.name,p.device_sn FROM wlyy.wlyy_patient_device p left join device.wlyy_devices d on p.device_sn=d.device_code left JOIN wlyy.wlyy_doctor r ON p.doctor = r. CODE " +
|
|
|
" where d.is_binding in (1,2) and d.grant_org_code ='" + hos.getCode() + "' "+temp+") a " +
|
|
|
" where d.is_binding in (1,2) and p.category_code in('1','2') and d.grant_org_code ='" + hos.getCode() + "' "+temp+") a " +
|
|
|
" GROUP BY a.doctor,a.name";
|
|
|
// Map<String, Object> map = jdbcTemplate.queryForMap(sql);
|
|
|
List<Map<String,Object>> result = jdbcTemplate.queryForList(sql);
|
|
@ -6159,14 +6176,6 @@ public class StatisticsESService {
|
|
|
// }
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 查询签约
|
|
|
*
|
|
|
* @param type 0 按周,1 按月
|
|
|
* @param startDate
|
|
|
* @param endDate
|
|
|
* @return
|
|
|
*/
|
|
|
/*public JSONArray getDeviceLine(String doctor, String type, String startDate, String endDate) throws Exception {
|
|
|
|
|
|
AdminTeam admin = adminTeamDao.findByLeaderCode(doctor);
|
|
@ -6194,7 +6203,7 @@ public class StatisticsESService {
|
|
|
return rsJs;
|
|
|
}*/
|
|
|
|
|
|
public JSONArray getDeviceLowLevelTotal(String date, String area, int level, String index, int sort, String lowLevel, String year) throws Exception {
|
|
|
/*public JSONArray getDeviceLowLevelTotal(String date, String area, int level, String index, int sort, String lowLevel, String year) throws Exception {
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
String low_level = String.valueOf(org.springframework.util.StringUtils.isEmpty(lowLevel) ? (level + 1) : lowLevel);
|
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
@ -6204,7 +6213,8 @@ public class StatisticsESService {
|
|
|
List<SaveModel> esModelList = new ArrayList<>();
|
|
|
|
|
|
if ((level == 2 && "5".equals(lowLevel)) || (level == 4) || (level == 3 && "5".equals(lowLevel))) {
|
|
|
String time = DateUtil.getStringDateShort();
|
|
|
//String time = DateUtil.getStringDateShort();
|
|
|
String time= elasticsearchUtil.getQuotaTime();
|
|
|
String sql ="SELECT" +
|
|
|
" pd.doctor team," +
|
|
|
" pd.doctor_name teamName," +
|
|
@ -6217,8 +6227,8 @@ public class StatisticsESService {
|
|
|
" AND pd.del = 0" +
|
|
|
" AND pd.category_code IN (1, 2)" +
|
|
|
" AND pd.czrq>='2018-06-30 17:00:00'"+
|
|
|
" AND pd.czrq < '"+time+" 17:00:00'" +
|
|
|
" AND LEFT(pd.czrq,4)= '"+year+"'";
|
|
|
" AND pd.czrq <= '"+time+"'" +
|
|
|
" AND LEFT(pd.czrq,4)= '"+year+"' AND grant_admin_team NOT IN(SELECT id FROM wlyy_admin_team WHERE LENGTH(org_code)!=10)";
|
|
|
if(level==3){
|
|
|
sql +=" AND LEFT(dw.grant_org_code,6)= '"+area+"'";
|
|
|
}else if (level==4){
|
|
@ -6227,7 +6237,7 @@ public class StatisticsESService {
|
|
|
sql +=" GROUP BY team";
|
|
|
esModelList = jdbcTemplate.query(sql,new BeanPropertyRowMapper(SaveModel.class));
|
|
|
}else {
|
|
|
esModelList = (List<SaveModel>) elasticsearchUtil.findListDateQuotaLevel0(date, area, level, index, SaveModel.timeLevel_DDL, low_level);
|
|
|
esModelList = (List<SaveModel>) elasticsearchUtil.findListDateQuotaLevel0("2018-07-01",date, area, level, index, SaveModel.timeLevel_ZL, low_level);
|
|
|
}
|
|
|
|
|
|
if (esModelList != null && esModelList.size() > 0) {
|
|
@ -6259,10 +6269,135 @@ public class StatisticsESService {
|
|
|
}
|
|
|
|
|
|
// 结果为空时,自建结果集
|
|
|
if (resultList == null || resultList.size() < 1) {
|
|
|
*//*if (resultList == null || resultList.size() < 1) {
|
|
|
resultList = getLowLevelMapKey(level, low_level, area);
|
|
|
}*//*
|
|
|
|
|
|
if (resultList != null) {
|
|
|
DecimalFormat df = new DecimalFormat("0.0000");
|
|
|
for (Map<String, Object> map : resultList) {
|
|
|
map.put("amount", map.get("amount") != null ? Long.valueOf(map.get("amount").toString()) : 0L);
|
|
|
|
|
|
if (!low_level.equals("5")) {
|
|
|
PopulationBase peopleNum = getPopulationBase(area, year);
|
|
|
if (peopleNum != null) {
|
|
|
map.put("rate", df.format(((long) map.get("amount") * 1.0000) / peopleNum.getNum() * 100));
|
|
|
map.put("taskRate", df.format(((long) map.get("amount") * 1.0000) / peopleNum.getTaskNum() * 100));
|
|
|
map.put("targetRate", df.format(peopleNum.getTaskNum() * 1.0000 / peopleNum.getNum() * 100));
|
|
|
map.put("rateString", map.get("amount") + "/" + peopleNum.getNum());
|
|
|
map.put("taskRateString", map.get("amount") + "/" + peopleNum.getTaskNum());
|
|
|
map.put("targetRateString", peopleNum.getTaskNum() + "/" + peopleNum.getNum());
|
|
|
map.put("num", peopleNum.getNum());
|
|
|
map.put("task", peopleNum.getTaskNum());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
*//*if ((level == 2 && "5".equals(lowLevel)) || (level == 4) || (level == 3 && "5".equals(lowLevel))) {
|
|
|
translateTeamLeaderName(resultList);
|
|
|
}*//*
|
|
|
|
|
|
Collections.sort(resultList, new Comparator<Map<String, Object>>() {
|
|
|
public int compare(Map<String, Object> o1, Map<String, Object> o2) {
|
|
|
long map1value = (long) o1.get("amount");
|
|
|
long map2value = (long) o2.get("amount");
|
|
|
|
|
|
if (map1value - map2value > 0) {
|
|
|
return sort == 1 ? -1 : 1;
|
|
|
} else if (map1value - map2value < 0) {
|
|
|
return sort == 1 ? 1 : -1;
|
|
|
} else {
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return new JSONArray(resultList);
|
|
|
} else {
|
|
|
return new JSONArray();
|
|
|
}
|
|
|
}*/
|
|
|
|
|
|
public JSONArray getDeviceLowLevelTotal(String date, String area, int level, String index, int sort, String lowLevel, String year) throws Exception {
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
String low_level = String.valueOf(org.springframework.util.StringUtils.isEmpty(lowLevel) ? (level + 1) : lowLevel);
|
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
if (date.compareTo(dateFormat.format(new Date())) >= 0) {
|
|
|
date = elasticsearchUtil.getQuotaTime();
|
|
|
}
|
|
|
List<SaveModel> esModelList = new ArrayList<>();
|
|
|
List<Map<String,Object>> sqlList = new ArrayList<>();
|
|
|
|
|
|
if ((level == 2 && "5".equals(lowLevel)) || (level == 4) || (level == 3 && "5".equals(lowLevel))) {
|
|
|
//String time = DateUtil.getStringDateShort();
|
|
|
String time= redisTemplate.opsForValue().get("quota:date");
|
|
|
String sql ="SELECT" +
|
|
|
" d.device_code," +
|
|
|
" pd.doctor," +
|
|
|
" pd.doctor_name," +
|
|
|
" pd.user_type" +
|
|
|
" FROM" +
|
|
|
" device.wlyy_devices d" +
|
|
|
" LEFT JOIN wlyy.wlyy_patient_device pd ON d.device_code = pd.device_sn" +
|
|
|
" WHERE" +
|
|
|
" d.is_binding IN (1, 2)" +
|
|
|
" AND pd.category_code IN ('1', '2')" +
|
|
|
" AND d.grant_time <= '"+time+"'" +
|
|
|
" AND d.grant_admin_team NOT IN(SELECT id FROM wlyy_admin_team WHERE LENGTH(org_code)!=10)"+
|
|
|
" ";
|
|
|
if(level==3){
|
|
|
sql +=" AND d.grant_admin_team IN(SELECT id FROM wlyy_admin_team WHERE LEFT(org_code,6) = '"+area+"'AND available = 1) AND LEFT(d.grant_org_code,6)= '"+area+"'";
|
|
|
}else if (level==4){
|
|
|
sql +=" AND d.grant_admin_team IN(SELECT id FROM wlyy_admin_team WHERE org_code = '"+area+"'AND available = 1) AND d.grant_org_code = '"+area+"'";
|
|
|
}else if (level==2){
|
|
|
sql +=" AND d.grant_admin_team IN(SELECT id FROM wlyy_admin_team WHERE available = 1)";
|
|
|
}
|
|
|
sqlList = jdbcTemplate.queryForList(sql);
|
|
|
}else {
|
|
|
esModelList = (List<SaveModel>) elasticsearchUtil.findListDateQuotaLevel0(year+"-07-01",date, area, level, index, SaveModel.timeLevel_ZL, low_level);
|
|
|
}
|
|
|
|
|
|
esModelList = getDeviceBindToTeam(sqlList);
|
|
|
|
|
|
//到绑定人的封装数据
|
|
|
if (esModelList != null && esModelList.size() > 0) {
|
|
|
for (SaveModel one : esModelList) {
|
|
|
Map<String, Object> maps = new HashMap<String, Object>();
|
|
|
maps.put("amount", one.getResult1().intValue());
|
|
|
if (low_level.equals("3")) {
|
|
|
maps.put("code", one.getTown());
|
|
|
maps.put("name", one.getTownName());
|
|
|
} else if (low_level.equals("4")) {
|
|
|
maps.put("code", one.getHospital());
|
|
|
maps.put("name", one.getHospitalName());
|
|
|
} else if (low_level.equals("5")) {
|
|
|
if (StringUtils.isNotEmpty(one.getTeam())){
|
|
|
maps.put("code", one.getTeam());
|
|
|
if (StringUtils.isEmpty(one.getTeamName())){
|
|
|
Doctor doctor = doctorDao.findByCode(one.getTeam());
|
|
|
if (doctor!=null){
|
|
|
maps.put("name", doctor.getName());
|
|
|
}
|
|
|
}else {
|
|
|
maps.put("name", one.getTeamName());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isEmpty(one.getTeam())){
|
|
|
maps.put("code","0");
|
|
|
maps.put("name", "其他");
|
|
|
}
|
|
|
}
|
|
|
resultList.add(maps);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 结果为空时,自建结果集
|
|
|
/*if (resultList == null || resultList.size() < 1) {
|
|
|
resultList = getLowLevelMapKey(level, low_level, area);
|
|
|
}*/
|
|
|
|
|
|
if (resultList != null) {
|
|
|
DecimalFormat df = new DecimalFormat("0.0000");
|
|
|
for (Map<String, Object> map : resultList) {
|
|
@ -6307,4 +6442,80 @@ public class StatisticsESService {
|
|
|
return new JSONArray();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public List<SaveModel> getDeviceBindToTeam(List<Map<String,Object>> dataList) throws Exception{
|
|
|
if (dataList==null && dataList.size()==0){
|
|
|
return null;
|
|
|
}
|
|
|
Map<String,Object> resultMap = new HashedMap();
|
|
|
List<SaveModel> resultList = new ArrayList<>();
|
|
|
|
|
|
//如果有两个键,则取a键
|
|
|
for (Map<String,Object> map : dataList){
|
|
|
String deviceSn = String.valueOf(map.get("device_code"));
|
|
|
List<Map<String,Object>> deviceList = null;
|
|
|
if (resultMap.containsKey(deviceSn)){
|
|
|
deviceList = (List<Map<String,Object>>)resultMap.get(deviceSn);
|
|
|
String userType = String.valueOf(deviceList.get(0).get("user_type"));
|
|
|
if (Integer.parseInt(String.valueOf(map.get("user_type")))<Integer.parseInt(userType)){
|
|
|
deviceList.clear();
|
|
|
deviceList.add(map);
|
|
|
}
|
|
|
}else {
|
|
|
deviceList = new ArrayList<>();
|
|
|
deviceList.add(map);
|
|
|
}
|
|
|
resultMap.put(deviceSn,deviceList);
|
|
|
}
|
|
|
|
|
|
//遍历map
|
|
|
List<Map<String,Object>> mapList = new ArrayList<>();
|
|
|
resultMap.forEach((key, value) -> {
|
|
|
mapList.addAll((List<Map<String,Object>>)value);
|
|
|
});
|
|
|
|
|
|
//根据医生code聚合返回页面所需要结果
|
|
|
Map<String,Object> doctorMap = new HashedMap();
|
|
|
for (Map<String,Object> map2 : mapList){
|
|
|
String key = "";
|
|
|
String doctor = "";
|
|
|
String doctorName = "";
|
|
|
if (map2.get("doctor")!= null){
|
|
|
doctor = String.valueOf(map2.get("doctor"));
|
|
|
}
|
|
|
if (map2.get("doctor_name")!=null){
|
|
|
doctorName = String.valueOf(map2.get("doctor_name"));
|
|
|
}
|
|
|
if (StringUtils.isEmpty(doctor)){
|
|
|
key ="qita,";
|
|
|
}else if (StringUtils.isNotBlank(doctor)){
|
|
|
key =doctor+","+doctorName;
|
|
|
}
|
|
|
|
|
|
int count = 0;
|
|
|
if (doctorMap.containsKey(key)){
|
|
|
count = Integer.valueOf(String.valueOf(doctorMap.get(key)));
|
|
|
}
|
|
|
count++;
|
|
|
doctorMap.put(key,count);
|
|
|
}
|
|
|
|
|
|
//遍历map
|
|
|
for (Map.Entry<String,Object> entry : doctorMap.entrySet()){
|
|
|
SaveModel saveModel = new SaveModel();
|
|
|
String key = entry.getKey();
|
|
|
String[] keyStr = key.split(",");
|
|
|
if(keyStr[0].equals("qita")){
|
|
|
saveModel.setTeam("");
|
|
|
}else {
|
|
|
saveModel.setTeam(keyStr[0]);
|
|
|
}
|
|
|
if (keyStr.length>1){
|
|
|
saveModel.setTeamName(keyStr[1]);
|
|
|
}
|
|
|
saveModel.setResult1(Double.valueOf(String.valueOf(entry.getValue())));
|
|
|
resultList.add(saveModel);
|
|
|
}
|
|
|
return resultList;
|
|
|
}
|
|
|
}
|