| 
					
				 | 
			
			
				@ -2352,6 +2352,12 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            int inStock = jdbcTemplate.queryForObject(tempSql, Integer.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //在架库存数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            stringObjectMap.put("shangPinKuCun", inStock); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //商品庫存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Integer inventoryNum = inventoryDao.sumInventoryWithEquNum(stringObjectMap.get("equNum")+"", new String[]{"1", "21"}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(inventoryNum == null) inventoryNum = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            stringObjectMap.put("inventoryNum", inventoryNum); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            stringObjectMap.put("warningNum", getEarlyWaringNum(stringObjectMap.get("equNum") + "")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String countSql = " select " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "     COUNT(DISTINCT (t.id)) as count " + 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -2575,6 +2581,43 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 获取设备预警品类数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param equNum 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public Integer getEarlyWaringNum(String equNum) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //该设备库存预警规则 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<MedicineWarrayRule> rules = medicineWarrayRuleDao.findMedicineWarrayRulesByEquNumAndDel(equNum, 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String, Integer>> drugIds = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //设备中所有药品列表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String, Object>> collect = inventoryDao.selectsomethingBysomeConditionWithEquNum(equNum, new String[]{"1", "21"}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Integer number = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //获取了所有缺货的药品id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        for (MedicineWarrayRule rule : rules) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (Map<String, Object> stringObjectMap : collect) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Integer ratedInventory = Integer.parseInt(stringObjectMap.get("ratedInventory") + ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (ratedInventory > rule.getLower() && ratedInventory < rule.getUpper()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Integer tempQty = Integer.parseInt(stringObjectMap.get("qty") + ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if ("%".equals(rule.getMatchUnit())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        Integer matchValue = (int) Math.ceil((rule.getUpper() * rule.getMatchValue()) / 100.0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (tempQty <= matchValue) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            number++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if ("件".equals(rule.getMatchUnit())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (tempQty <= rule.getMatchValue()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            number++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return number; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public PageEnvelop selectInventoryRecordByDeviceId(String id ,String deviceId, String layerNo, String wayerNo, String type, String startTime, String endTime, String drugName, int page, int size){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        PageEnvelop listEnvelop = new PageEnvelop(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "SELECT\n" + 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -2990,9 +3033,9 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "tmd.quantity_unit AS quantityUnit,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "tmd.pack_unit AS packUnit,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "tmd.spell_code AS spellCode,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "\tsum(tmi.qty) AS qty,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "\tIFNULL(sum(tmi.qty), 0) AS qty,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "\t(\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "\t\ttmi.rated_inventory - CAST(tmi.qty AS UNSIGNED)\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "\t\tIFNULL(tmi.rated_inventory - CAST(tmi.qty AS UNSIGNED), 0)\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "\t) AS daibukucun\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "FROM\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "\tt_mediicinecabinet_inventory tmi LEFT JOIN t_mediicine_drugs tmd ON tmi.drug_id = tmd.id\n" + 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -3023,6 +3066,9 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "\torg_code"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Logger.getAnonymousLogger().info("finalCountSql="+countSql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        int count = jdbcTemplate.queryForObject(countSql,Integer.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (count == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            list = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("count", count); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("msg", JavaBeanUtils.getInstance().mapListJson(list)); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -4504,121 +4550,61 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 预警详情 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param deviceId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param page 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param size 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @throws Exception 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject getEaringWarringInfoByDeviceWithPage(String deviceId, int page, int size) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject getMedicineWarrayRuleByDeviceId(String deviceId) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject result = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        Mediicinedevice mediicinedevice = deviceDao.findOne(deviceId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        //该设备库存预警规则 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        List<MedicineWarrayRule> rules = medicineWarrayRuleDao.findMedicineWarrayRulesByEquNumAndDel(mediicinedevice.getEquNum(), 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        List<Map<String, Integer>> drugIds = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        List<Map<String, Object>> collect = inventoryDao.selectsomethingBysomeConditionWithEquNum(mediicinedevice.getEquNum(), new String[]{"1", "21"}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        //获取了所有缺货的药品id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        for (MedicineWarrayRule rule : rules) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            for (Map<String, Object> stringObjectMap : collect) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                Integer ratedInventory = Integer.parseInt(stringObjectMap.get("ratedInventory") + ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                if (ratedInventory > rule.getLower() && ratedInventory < rule.getUpper()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    Integer tempQty = Integer.parseInt(stringObjectMap.get("qty") + ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    if ("%".equals(rule.getMatchUnit())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                        Integer matchValue = (int) Math.ceil((rule.getUpper() * rule.getMatchValue()) / 100.0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                        if (tempQty <= matchValue) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                            Map<String, Integer> tempMap = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                            tempMap.put(stringObjectMap.get("drugId") + "", Integer.parseInt(stringObjectMap.get("qty") + "")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                            drugIds.add(tempMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    if ("件".equals(rule.getMatchUnit())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                        if (tempQty <= rule.getMatchValue()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                            Map<String, Integer> tempMap = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                            tempMap.put(stringObjectMap.get("drugId") + "", Integer.parseInt(stringObjectMap.get("qty") + "")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                            drugIds.add(tempMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        String sql = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            sql = "SELECT\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.id,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.approval_num,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.barcode,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.brand,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.dos_form,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.state,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.drug_bar_code,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.drug_class,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.drug_class_code,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.drug_code,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.drug_name,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.drug_name_alies,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.drug_short_code,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.drug_type_code,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.earlywarningcate,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.inventory,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.manufactor,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.med_cabinet,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.pic,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.price,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.sale_volume,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.self_code,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.specif,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.unit,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.create_time,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.create_user,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.create_user_name,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.update_time,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.update_user,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.update_user_name,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.drug_sku,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.drug_num,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.use_num,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.use_way,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.use_rate,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.use_dose,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.use_way_add,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.org_code,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.org_name,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.quantity_unit,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.pack_unit,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "tmd.spell_code\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "FROM\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    "t_mediicine_drugs AS tmd\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				////                    "WHERE ',"+ drugIds.stream().map(item->item.keySet()).collect(Collectors.joining(",")) +",' LIKE CONCAT('%,',t.belong_community,',%')\n"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        List<Map<String, Object>> list = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        list = hibenateUtils.createSQLQuery(sql,page,size); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        String countSql = "SELECT\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                "COUNT(DISTINCT(id))" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                "FROM\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                "\tt_mediicinecabinet_inventory\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                "WHERE" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                "\tid_device = '" + deviceId + "'\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                "AND CAST(qty as UNSIGNED) < rated_inventory\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                "AND drug_code IS NOT NULL\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                "AND org_code IS NOT NULL\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                "AND (state = 1 OR state = 21)\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                "ORDER BY\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                "\tdrug_code,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                "\torg_code"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        Logger.getAnonymousLogger().info("finalCountSql="+countSql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        int count = jdbcTemplate.queryForObject(countSql,Integer.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        result.put("count", count); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        result.put("msg", JavaBeanUtils.getInstance().mapListJson(list)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Mediicinedevice mediicinedevice = deviceDao.findOne(deviceId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("msg", JavaBeanUtils.getInstance().mapListJson(medicineWarrayRuleDao.findMedicineWarrayRulesByEquNumAndDel(mediicinedevice.getEquNum(), 1))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public List<Map<String, Object>> getDrugInventoryCount(String content, Integer lowerQty, Integer upperQty, String deviceId) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject result = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "SELECT\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "\ttmd.specif as specif,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "\ttmi.drug_name AS drugName,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "\tsum(tmi.qty) AS qty,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "\ttmi.drug_id AS drugId,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "\ttmi.drug_code AS drugCode,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "\ttmi.org_code AS orgCode,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "\tIFNULL(sum(tmi.rated_inventory), 0) AS ratedInventory\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "FROM\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "\tt_mediicinecabinet_inventory tmi LEFT JOIN t_mediicine_drugs tmd on tmi.drug_id = tmd.id\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "WHERE\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "\ttmi.id_device = '" + deviceId + "'\n"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (content != null && !StringUtils.isEmpty(content)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql += "AND tmi.drug_name like '%" + content + "%'\n"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        sql += "AND (tmi.state = '1' OR tmi.state = '21')\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "AND tmi.drug_code IS NOT NULL\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "AND tmi.org_code IS NOT NULL\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "GROUP BY\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "\ttmi.drug_code,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "\ttmi.org_code\n"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (lowerQty != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql += "HAVING  SUM(tmi.qty) >= " + lowerQty + "\n"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (upperQty != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (lowerQty != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                sql += "AND SUM(tmi.qty) <= " + upperQty + "\n"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                sql += "HAVING SUM(tmi.qty) <= " + upperQty + "\n"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//         List<Map<String, Object>> collect = inventoryDao.selectsomethingBysomeCondition(deviceId, new String[]{"1", "21"}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String, Object>> collect = hibenateUtils.createSQLQuery(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        for (Map<String, Object> stringObjectMap : collect) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            stringObjectMap.put("detail", inventoryDao.getMediicinecabinetInventoriesByOrgCodeAndDurgCode( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    stringObjectMap.get("orgCode") + "", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    stringObjectMap.get("drugCode") + "", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    deviceId, new String[]{"1", "21"})); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return collect; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |