String areaNode = request.getParameter("areaNode");
RunTimeUser rtUser = RunTimeUser.getRunTimeUser(request);
ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IUserDao userDao = (IUserDao) ac.getBean("userDao");
IMessageRecordDao messageRecordDao = (IMessageRecordDao) ac.getBean("messageRecordDao");
if("1".equals(sendType))
{
String[] mbs = mobiles.split(",");
for(String sendMobile : mbs)
{
SendSms.sendSms(sendMobile, content);
}
}else if("2".equals(sendType))
{
List<User> us = userDao.listUser(" from User u where u.id in ("+userIds+")");
for(User u : us)
{
SendSms.sendSms(u.getMobile(), content);
if(!StringUtil.isEmptyStr(mobiles))mobiles += ",";
mobiles += u.getMobile();
}
}else if("3".equals(sendType))
{
String[] mids = merchantIds.split(",");
for(int i =0 ; i < mids.length; i++)
{
List<User> us = userDao.listUser(" from User u where u.id in ("+userIds+") and u.usertype = " + uts.split(",")[i] +" and u.organizationid = " + mids[i]);
for(User u : us)
{
SendSms.sendSms(u.getMobile(), content);
if(!StringUtil.isEmptyStr(mobiles))mobiles += ",";
mobiles += u.getMobile();
}
}
}else if("4".equals(sendType))
{
String hql = " from User u where u.enabled = true and u.locked = false";
String hql1 = "";
String hql2 = "";
if(rtUser.isMerchant())
{
hql1 += " and u.usertype = 2 and u.organizationid = " +rtUser.getOrganizationid() ;
if(!StringUtil.isEmptyStr(areaNode))
{
hql1 += " and exists(from Merchant m where m.id = "+rtUser.getOrganizationid()+" and m.areaNode = '"+areaNode+"')";
}
hql += hql1;
}else if(rtUser.isOrganization())
{
hql2 += " and u.usertype = 3 and u.organizationid = " +rtUser.getOrganizationid() ;
if(!StringUtil.isEmptyStr(areaNode))
{
hql2 += " and exists(from Organization o where o.id = "+rtUser.getOrganizationid()+" and o.JGSZQY = '"+areaNode+"')";
}
hql += hql2;
}else
{
hql1 += " and u.usertype = 2 ";
if(!StringUtil.isEmptyStr(areaNode))
{
hql1 += " and exists(from Merchant m where m.id = u.organizationid and m.areaNode = '"+areaNode+"')";
}
hql2 += " and u.usertype = 3 ";
if(!StringUtil.isEmptyStr(areaNode))
{
hql2 += " and exists(from Organization o where o.id = u.organizationid and o.JGSZQY = '"+areaNode+"')";
}
hql = hql + hql1 + " union " +hql + hql2;
}
List<User> us = userDao.listUser(hql);
for(User u : us)
{
SendSms.sendSms(u.getMobile(), content);
if(!StringUtil.isEmptyStr(mobiles))mobiles += ",";
mobiles += u.getMobile();
if(!StringUtil.isEmptyStr(users))users += ",";
users += u.getTruename();
}
}else if("5".equals(sendType))
{
String hql = " from User u where u.enabled = true and u.locked = false and u.sex = 1";
String hql1 = "";
String hql2 = "";
if(rtUser.isMerchant())
{
hql1 += " and u.usertype = 2 and u.organizationid = " +rtUser.getOrganizationid() ;
if(!StringUtil.isEmptyStr(areaNode))
{
hql1 += " and exists(from Merchant m where m.id = "+rtUser.getOrganizationid()+" and m.areaNode = '"+areaNode+"')";
}
hql += hql1;
}else if(rtUser.isOrganization())
{
hql2 += " and u.usertype = 3 and u.organizationid = " +rtUser.getOrganizationid() ;
if(!StringUtil.isEmptyStr(areaNode))
{
hql2 += " and exists(from Organization o where o.id = "+rtUser.getOrganizationid()+" and o.JGSZQY = '"+areaNode+"')";
}
hql += hql2;
}else
{
hql1 += " and u.usertype = 2 ";
if(!StringUtil.isEmptyStr(areaNode))
{
hql1 += " and exists(from Merchant m where m.id = u.organizationid and m.areaNode = '"+areaNode+"')";
}
hql2 += " and u.usertype = 3 ";
if(!StringUtil.isEmptyStr(areaNode))
{
hql2 += " and exists(from Organization o where o.id = u.organizationid and o.JGSZQY = '"+areaNode+"')";
}
hql = hql + hql1 + " union " +hql + hql2;
}
List<User> us = userDao.listUser(hql);
for(User u : us)
{
SendSms.sendSms(u.getMobile(), content);
if(!StringUtil.isEmptyStr(mobiles))mobiles += ",";
mobiles += u.getMobile();
if(!StringUtil.isEmptyStr(users))users += ",";
users += u.getTruename();
}
}else if("6".equals(sendType))
{
String hql = " from User u where u.enabled = true and u.locked = false and u.sex = 2";
String hql1 = "";
String hql2 = "";
if(rtUser.isMerchant())
{
hql1 += " and u.usertype = 2 and u.organizationid = " +rtUser.getOrganizationid() ;
if(!StringUtil.isEmptyStr(areaNode))
{
hql1 += " and exists(from Merchant m where m.id = "+rtUser.getOrganizationid()+" and m.areaNode = '"+areaNode+"')";
}
hql += hql1;
}else if(rtUser.isOrganization())
{
hql2 += " and u.usertype = 3 and u.organizationid = " +rtUser.getOrganizationid() ;
if(!StringUtil.isEmptyStr(areaNode))
{
hql2 += " and exists(from Organization o where o.id = "+rtUser.getOrganizationid()+" and o.JGSZQY = '"+areaNode+"')";
}
hql += hql2;
}else
{
hql1 += " and u.usertype = 2 ";
if(!StringUtil.isEmptyStr(areaNode))
{
hql1 += " and exists(from Merchant m where m.id = u.organizationid and m.areaNode = '"+areaNode+"')";
}
hql2 += " and u.usertype = 3 ";
if(!StringUtil.isEmptyStr(areaNode))
{
hql2 += " and exists(from Organization o where o.id = u.organizationid and o.JGSZQY = '"+areaNode+"')";
}
hql = hql + hql1 + " union " +hql + hql2;
}
List<User> us = userDao.listUser(hql);
for(User u : us)
{
SendSms.sendSms(u.getMobile(), content);
if(!StringUtil.isEmptyStr(mobiles))mobiles += ",";
mobiles += u.getMobile();
if(!StringUtil.isEmptyStr(users))users += ",";
users += u.getTruename();
}
}else
{
String hql = "";
if("7".equals(sendType))
{
hql = " from User u where u.enabled = true and u.locked = false ";
hql += " and u.usertype = 4 ";
if(!StringUtil.isEmptyStr(areaNode))
{
hql += " and exists(from Organization o where o.jgfzr.id = u.id and o.JGSZQY = '"+areaNode+"')";
}else
{
hql += " and exists (from Organization o where o.jgfzr.id = u.id)";
}
}else if("8".equals(sendType))
{
hql = " from User u where u.enabled = true and u.locked = false ";
hql += " and u.usertype = 3 ";
if(!StringUtil.isEmptyStr(areaNode))
{
hql += " and exists(from Organization o where o.jgfzr.id = u.id and o.JGSZQY = '"+areaNode+"')";
}else
{
hql += " and exists (from Organization o where o.jgfzr.id = u.id)";
}
}else if("9".equals(sendType))
{
hql = " from User u where u.enabled = true and u.locked = false ";
if(!StringUtil.isEmptyStr(areaNode))
{
hql += " and exists(from Merchant m where m.SJFRDB.id = u.id and m.areaNode = '"+areaNode+"')";
}else
{
hql += " and exists (from Merchant m where m.SJFRDB.id = u.id)";
}
}
if(!StringUtil.isEmptyStr(hql))
{
List<User> us = userDao.listUser(hql);
for(User u : us)
{
SendSms.sendSms(u.getMobile(), content);
if(!StringUtil.isEmptyStr(mobiles))mobiles += ",";
mobiles += u.getMobile();