| 
					
				 | 
			
			
				@ -5724,26 +5724,109 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param day 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public List<Map<String,Object>> getPrescriptionStaticsRank(int level,String area,int day){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public List<Map<String,Object>> getPrescriptionStaticsRank(String userId,Integer day,String startTime,String endTime,Integer level,String area){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject object = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String condition = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (level==1){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            condition = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else if (level==2){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            condition = " o.belong_community IN (select h.code from dm_hospital h where h.town = '"+area+"') "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else if (level==3){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            condition = " o.belong_community = '"+area+"' "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        UserDO user = userDao.findOne(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        RoleDO role = roleDao.findOne(user.getRoleId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<String> deviceIds = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String conditionSql = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String orderConditionSql = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String oorderConditionSql = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if ("replenisher".equals(role.getCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            deviceIds = mediicineDeviceUserDao.getdevicesbyuserid(userId, "1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String ids  =""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (int i=0;i<deviceIds.size();i++){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Mediicinedevice mediicinedevice = deviceDao.findOne(deviceIds.get(i)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ids +="'"+mediicinedevice.getEquNum()+"',"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (org.apache.commons.lang3.StringUtils.isNoneBlank(ids)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ids = ids.substring(0,ids.length()-1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                condition  = " AND o.shipping_equ IN ("+ids+")"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String belongCommunitys = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String tempSql = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //获取管理员所在社区code字符串 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //市管理员 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if ("saasAdmin".equals(role.getCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    tempSql = "SELECT\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "\t`code`\tas community\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "FROM\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "\tdm_hospital\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "WHERE\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "\tdel = 1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //区域管理员 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if ("regionAdmin".equals(role.getCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    tempSql = "SELECT\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "\tdh.`code` AS community\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "FROM\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "\twlyy_user_area t\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "LEFT JOIN dm_hospital dh ON t.town = dh.town\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "WHERE\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "\tt.user_id = '" + userId + "'\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "AND t.del = 1\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "AND dh.del = 1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //社区管理员 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if ("communityAdmin".equals(role.getCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    tempSql = "SELECT\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "t.hospital AS community\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "FROM\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "wlyy_user_area AS t\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "WHERE\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "t.user_id = '" + userId + "'\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "AND t.del = 1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                List<Map<String, Object>> list = hibenateUtils.createSQLQuery(tempSql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                for (Map<String, Object> stringObjectMap : list) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (stringObjectMap.get("community") != null && !StringUtils.isEmpty(stringObjectMap.get("community").toString())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (StringUtils.isEmpty(belongCommunitys)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            belongCommunitys += stringObjectMap.get("community").toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            belongCommunitys += "," +  stringObjectMap.get("community").toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (!StringUtils.isEmpty(belongCommunitys)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                condition += "AND ',"+ belongCommunitys +",' LIKE CONCAT('%,',o.belong_community,',%')\n"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Date startDate = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (day==1){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            startDate = DateUtil.strToDateLong(DateUtil.getStringDateShort()+" 00:00:00"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            startDate = DateUtil.getPreDays(new Date(),-day); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String timeCondition = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String areaCondition = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (level!=null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(level==1){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                areaCondition = " and o.belong_community IN(select d.code from dm_hospital d where d.city='"+area+"')  "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            }else if(level==2){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                areaCondition = " and o.belong_community IN(select d.code from dm_hospital d where d.town='"+area+"')  "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            }else if(level==3){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                areaCondition = " and o.belong_community ='"+area+"'  "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (day != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (day == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                startDate = DateUtil.strToDateLong(DateUtil.getStringDateShort() + " 00:00:00"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                startDate = DateUtil.getPreDays(new Date(), -day); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            endTime = DateUtil.getStringDate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            timeCondition = " and o.create_time >='" + DateUtil.dateToStrLong(startDate) + "' and o.create_time <= '" + endTime + "'  "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (org.apache.commons.lang3.StringUtils.isNotBlank(startTime)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            timeCondition = " and o.create_time >='" + startTime + "' "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (org.apache.commons.lang3.StringUtils.isNotBlank(endTime)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            timeCondition += " and o.create_time <= '" + endTime + "'  "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String endTime = DateUtil.getStringDate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String timeCondition = " and o.create_time >='"+DateUtil.dateToStrLong(startDate)+"' and o.create_time <= '"+endTime+"'  "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "SELECT o.belong_community,o.community,count(o.id) 'orderTotal',count(IF(o.sell_state=1,1,null)) 'sellTotal'" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " FROM t_mediicine_order o WHERE 1=1 "+condition+ timeCondition; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " FROM t_mediicine_order o WHERE 1=1 "+condition+ timeCondition+areaCondition; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        sql += " group by o.belong_community order by orderTotal desc"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return jdbcTemplate.queryForList(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -6773,6 +6856,14 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        sql = "SELECT count(1) as 'count' FROM t_mediicine_order o WHERE 1=1 and order_source='厦门i健康' "+condition+ timeCondition+areaCondition; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Integer onlineTotal = jdbcTemplate.queryForObject(sql,Integer.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        sql = "SELECT count(1) as 'count' FROM t_mediicine_order o WHERE 1=1 and order_source='智业系统' "+condition+ timeCondition+areaCondition; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Integer offlineTotal = jdbcTemplate.queryForObject(sql,Integer.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        object.put("onlineTotal",onlineTotal); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        object.put("offlineTotal",offlineTotal); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        object.put("total",total); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String drugSql = "select sum(od.quantity) as quantity from t_mediicine_order_detail od where od.id_order IN (SELECT o.id as id  FROM t_mediicine_order o WHERE 1=1 "+condition+ timeCondition+areaCondition+")"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map<String,Object> drugTotalMap = jdbcTemplate.queryForMap(drugSql); 
			 |