| 
					
				 | 
			
			
				@ -4,9 +4,13 @@ package com.yihu.jw.base.service.a3service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.fasterxml.jackson.databind.ObjectMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.base.dao.a2dao.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.base.dao.role.RoleDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.base.dao.user.UserDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.base.util.ConstantUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.base.util.JavaBeanUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.a1entity.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.role.RoleDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.user.UserDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.date.DateUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.utils.hibernate.HibenateUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.mysql.query.BaseJpaService; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -46,6 +50,11 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private MediicineDeviceDao deviceDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private UserDao userDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private RoleDao roleDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private MediicinedrugsDao drugsDao; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -149,17 +158,71 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //orderNum, equNum, contact, startTime, endTime, sellState, orderState, dispensingWindow 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject queryOrderListFullInfo(String orderNum, String equNum, String contact, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                            String startTime, String endTime, String sellState, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                            String orderState, String dispensingWindow, int page, int size,String wechatId) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                            String orderState, String dispensingWindow, String community, String userId, int page, int size,String wechatId) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject result = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        /*String orgCodeVale = null == orgCode ? "" : orgCode; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String del = null == docStatus ? "" : docStatus; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String nameOrIdcardValue = null == nameOrIdcard ? "" : "%" + nameOrIdcard + "%"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        int start = 0 == page ? page++ : (page - 1) * size; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        int end = 0 == size ? 15 : page * size;*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (StringUtils.isEmpty(userId)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("msg", "userId is empty"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("response", ConstantUtils.FAIL); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Date sTime = DateUtil.strToDate(startTime); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Date eTime = DateUtil.strToDate(endTime); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql="SELECT\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        UserDO user = userDao.findOne(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        RoleDO role = roleDao.findOne(user.getRoleId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //订单列表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String, Object>> orderList = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String conditionSql = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String belongCommunitys = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //获取社区id,串 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //市管理员 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if ("saasAdmin".equals(role.getCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                sql = "SELECT\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "\tid\tas community\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "FROM\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "\tdm_hospital\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "WHERE\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "\tdel = 1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //区域管理员 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if ("regionAdmin".equals(role.getCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                sql = "SELECT\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "\tdh.id 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()) || "replenisher".equals(role.getCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                sql = "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(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            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(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sencodSql = "SELECT\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "    t.id as id,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "    t.address as address,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "    t.age as age,\n" + 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -207,11 +270,18 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "    t.doctor_advice AS doctorAdvice,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "    t.allergy_info AS allergyInfo,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "    t.info AS info,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "    t.social_security_card_num AS socialSecurityCardNum\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "    t.social_security_card_num AS socialSecurityCardNum,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "    t.belong_community AS belongCommunity\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "FROM\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "    t_mediicine_order AS t where 1=1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "    t_mediicine_order AS t where 1=1 \n"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String conditionSql = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (!StringUtils.isEmpty(belongCommunitys)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            conditionSql += " and ',"+ belongCommunitys +",' LIKE CONCAT('%,',t.belong_community,',%')\n"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (!StringUtils.isEmpty(community)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            conditionSql += " and t.belong_community = '" + community + "'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (!StringUtils.isEmpty(orderNum)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            conditionSql += " and t.order_num = '" + orderNum + "'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -222,8 +292,6 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            conditionSql += " and t.contact like '%" + contact + "%'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (org.apache.commons.lang.StringUtils.isNotBlank(startTime)&& org.apache.commons.lang.StringUtils.isNotBlank(endTime)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            conditionSql += "  AND  t.prescribe_time BETWEEN to_date('" + startTime +"','yyyy-mm-dd hh24:mi:ss') " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    " AND to_date('" + endTime + "','yyyy-mm-dd hh24:mi:ss')"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            conditionSql += "  AND  t.prescribe_time >= '" + startTime +"'" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    " AND t.prescribe_time <= '" + endTime + "'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -236,11 +304,9 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (!StringUtils.isEmpty(dispensingWindow)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            conditionSql += " and t.dispensing_window = '" + dispensingWindow + "'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        sencodSql = sencodSql + conditionSql; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        sql = sql + conditionSql; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String,Object>> list=null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        list = hibenateUtils.createSQLQuery(sql,page,size); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        orderList = hibenateUtils.createSQLQuery(sencodSql, page, size); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String countSql = " select " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "     COUNT(DISTINCT (t.id)) as count " + 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -251,7 +317,7 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                conditionSql; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Logger.getAnonymousLogger().info("finalCountSql="+countSql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        int count = jdbcTemplate.queryForObject(countSql,Integer.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        for (Map<String, Object> stringObjectMap : list) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        for (Map<String, Object> stringObjectMap : orderList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (stringObjectMap.get("sellState") != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (!StringUtils.isEmpty(stringObjectMap.get("sellState").toString())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if ("0".equals(stringObjectMap.get("sellState").toString())) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -263,8 +329,9 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("response", ConstantUtils.SUCCESS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("count", count); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("msg", JavaBeanUtils.getInstance().mapListJson(list)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("msg", JavaBeanUtils.getInstance().mapListJson(orderList)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 |