package com.fjx.wechat.base.admin.service;

import java.util.ArrayList;
import java.util.List;

import com.fjx.wechat.base.admin.entity.WechatPublicAccountEntity;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.fjx.common.framework.base.service.impl.BaseAbstractService;
import com.fjx.common.framework.system.pagination.Pagination;
import com.fjx.common.utils.CommonUtils;
import com.fjx.wechat.base.admin.entity.WechatUserEntity;



/**
 * 微信用户管理
 * @author fengjx xd-fjx@qq.com
 * @date 2014年11月2日
 */
@Service
public class WechatUserServiceImpl extends BaseAbstractService<WechatUserEntity> implements WechatUserService {
	
	
	/*
	 * (non-Javadoc)
	 * @see com.fjx.wechat.base.web.admin.service.WechatUserService#pageList(com.fjx.wechat.base.web.admin.entity.WechatUserEntity, com.fjx.wechat.base.web.admin.entity.WechatPublicAccountEntity)
	 */
	@Override
	public Pagination<WechatUserEntity> pageList(WechatUserEntity user, String group_id,WechatPublicAccountEntity publicAccoun) {
		List<Object> params = new ArrayList<Object>();
		StringBuilder hql = new StringBuilder(" from WechatUserEntity u where 1=1 ");
		if(StringUtils.isNotBlank(user.getOpenid())){
			hql.append(" and u.openid = ?");
			params.add(user.getOpenid());
		}
		if(StringUtils.isNotBlank(user.getStart_time())){
			hql.append(" and u.subscribe_time > ?");
			params.add(CommonUtils.String2Date(user.getStart_time()+" 00:00:00"));
		}
		if(StringUtils.isNotBlank(user.getEnd_time())){
			hql.append(" and u.subscribe_time < ?");
			params.add(CommonUtils.String2Date(user.getEnd_time()+" 23:59:59"));
		}
		if(null != group_id){
			if("" == group_id){
				hql.append(" and (u.wechatUserGroupEntity.id = null or u.wechatUserGroupEntity.id = '') ");
			}else{
				hql.append(" and u.wechatUserGroupEntity.id = ?");
				params.add(group_id);
			}
		}
		return pageByHql(hql.toString(), params);
	}
	
	
	/*
	 * (non-Javadoc)
	 * @see com.fjx.wechat.base.web.admin.service.WechatUserService#updateGroup(java.lang.String, java.lang.String)
	 */
	@Override
	public void updateGroup(String user_id, String group_id) {
		StringBuilder hql = new StringBuilder("update WechatUserEntity u set u.wechatUserGroupEntity.id = ?");
		hql.append(" where u.id = ?");
		bulkUpdate(hql.toString(), true, group_id,user_id);
	}

	
	
}

@@ -1640,51 +1640,45 @@
 %09if(
-null != group_id)%7B%0A%09%09%09if(%22%22 == group_id)%7B%0A%09
+%22%22.equals(group_id))%7B%09//%E7%A9%BA%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%A1%A8%E7%A4%BA%E6%9F%A5%E6%9C%AA%E5%88%86%E7%BB%84%E7%94%A8%E6%88%B7%0A
 %09%09%09h
@@ -1774,17 +1774,36 @@
 ;%0A%09%09
-%09
 %7Delse
+ if(group_id != null)
 %7B%0A
-%09
 %09%09%09h
@@ -1855,17 +1855,16 @@
 ?%22);%0A%09%09%09
-%09
 params.a
@@ -1881,13 +1881,8 @@
 d);%0A
-%09%09%09%7D%0A
 %09%09%7D%0A

修改BUG：查未分组用户