//重置
function reset(){
$("#issuedtype").combobox('setValue','');
$("#isOrganiz").combobox('setValue','');
$("#industryType").combobox('setValue','');
$("#unitId").combotree('setValue','');
$("#name").val("");
$("#comp").val("");
$("#phone").val("");
$("#time").val("");
}
//改进重置,用选择器进行选择
function reset(){
$(":select selected").combobox('setValue','');
$("select[0]").combobox('setValue','');
$(":input").val("");
}
//查看过往短信
function checkMessage(id){
var d = $.dialog({
content : "url:lhRegisteredController.do?checkMessages&id="+id,
lock : true,
title : "查看过往短信",
zIndex : 100,
width : 700,
height : 350,
parent : windowapi,
close:function(){
//刷新列表
window.location.href=window.location.href;
}
});
}
//发短信给经办人(跳转界面)
function sendMessagesToFunctionary(){
if($('#dg').datagrid('getSelections').length>0){
//获取表中的UnitId字段值
var UnitIDs = [];
var rows = $('#dg').datagrid('getSelections');
for(var i=0; i<rows.length; i++){
UnitIDs.push(rows[i].id);
}
var ids = UnitIDs.join(',');
$.dialog({
content : "url:lhInformationController.do?getFunctionary¶m="+ids,
lock : true,
title : "发短信给经办人",
zIndex : 100,
width : 700,
height : 460,
parent : windowapi,
close:function(){
//刷新列表
window.location.href=window.location.href;
}
});
}else{
alert("请先在表格中选中单位,然后再点我");
}
}
//发短信给业务经办部门负责人(跳转界面)
function sendMessagesToAgent(){
if($('#dg').datagrid('getSelections').length>0){
//放手机号的数组
var ids = [];
//放表中UnitId的数组
var UnitIds=[];
var rows = $('#dg').datagrid('getSelections');
for(var j=0;j<rows.length;j++){
UnitIds.push(rows[j].id);
}
//把数组转换成字符串,并用,分隔
var Uids = UnitIds.join(',');
for(var i=0; i<rows.length; i++){
ids.push(rows[i].phone);
}
//把数组转换成字符串,并用,分隔
var str = ids.join(',');
$.dialog({
content : "url:lhInformationController.do?ToAgent&pphone="+str+"&Uids="+Uids,
lock : true,
title : "发短信给业务经办部门负责人",
zIndex : 100,
width : 700,
height : 460,
parent : windowapi,
close:function(){
//刷新列表
window.location.href=window.location.href;
}
});
}else{
alert("请先在表格中选中单位,然后再点我");
}
}
<!-- 这是一个树形结构的下拉框,不知道怎么获取的数据-->
<div class="col-3 pd-r-5">
<div class="form-group">
<label class="control-label col-4">区域名称</label>
<div class="col-8" >
<select class="form-control" title="区域名称" style="width: 100%;" id="unitId" >
</select>
</div>
</div>
<%@page pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html lang="zh-CN">
<head>
<meta charset=UTF-8>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="keys" content="">
<meta name="author" content="">
<link rel="stylesheet" href="plug-in/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="plug-in/css/font-awesome.min.css">
<link rel="stylesheet" href="plug-in/css/login.css">
<style>
</style>
</head>
<body>
<!-- <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container" >
<div class="navbar-header">
<div><a class="navbar-brand" href="#" style="font-size:32px;">短信发送界面</a></div>
</div>
</div>
</nav> -->
<div class="container">
<form class="form-signin" role="form">
<%-- <h2 class="form-signin-heading"><i class="glyphicon glyphicon-leaf" style="color:green"></i><c:if test="${not empty param.pphone }">给业务经办部门负责人发送短信</c:if><c:if test="${not empty phones }">给经办人发送短信</c:if> </h2>
--%>
<input name="Uids" value="${param.Uids }" id="Uids" type="hidden">
<input name="ids" value="${param.param }" id="ids" type="hidden">
<label style="font-size:20px;" for="content" class="required">短信内容</label> <textarea
type="text" class="form-control" datatype="*" id="content"
name="content" placeholder="请输入短信内容" rows="11" cols="20"></textarea>
<p id="message"></p>
<div style="display:none"><label for="phones" class="required">手机号码(<font color="red">支持多人发送,手机号码用逗号隔开</font>)</label></div>
<div style="display:none"><textarea type="text" class="form-control" datatype="*" id="phones"
name="phones" rows="4" cols="40"
placeholder="请输入手机号码" ><c:if test="${not empty param.pphone }">${param.pphone }</c:if><c:if test="${not empty phones }">${phones }</c:if></textarea></div>
<p id="code1"></p>
<a class="btn btn-lg btn-success btn-block" href="javascript:send()"> 发送</a>
</form>
</div>
<script src="plug-in/jquery/jquery-2.1.1.min.js"></script>
<script src="plug-in/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript">
//发送短信(支持多人群发)
function send() {
$("#code1").html("");
var reg = /^1[34578][0-9]{9}$/;
//获取公司名唯一标识unitId
var ids = $("#ids").val();
//获取公司名唯一标识unitId
var Uids = $("#Uids").val();
// 短信内容
var content = $("#content").val();
alert(content);
//手机号码
var phones = $("#phones").val();
//获取到的手机号打散
var ArrayPhone = phones.split(",");
//循环进行遍历
for(var i=0;i<ArrayPhone.length;i++){
if(!reg.test(ArrayPhone[i])){
alert("请正确输入手机号码,"+ArrayPhone[i]+"格式不正确");
return;
};
}
var len = document.getElementById("content").value.length;
if (content == "" || content == null) {
$("#message").html("<span style='color:red'>请输入短信内容</span>");
return;
}
if (phones == "" || phones == null) {
$("#code1").html("<span style='color:red'>请输入手机号码</span>");
return;
}else {
$("#code1").html("");
}
if(ids == "" || ids == null){
//负责人
$.ajax({
url : "lhInformationController.do?sendMessg",
data : {
'ids':ids,
'phones' : phones,
'content' : content,
'Uids':Uids
},
type : "POST",
dataType : "JSON",
success : function(data) {
if (data.success == "true" || data.success == true) {
alert(data.msg);
if(data.msg=="发送成功"){
$("#content").val("");
$("#phones").val("");
}
$("#message").html("");
} else {
alert("短信发送失败!");
}
},
error : function() {
alert("服务异常,稍后再试!");
}
});
}else{
//经办人
$.ajax({
url : "lhInformationController.do?sendMessg2",
data : {
'ids':ids,
'phones' : phones,
'content' : content,
'Uids':Uids
},
type : "POST",
dataType : "JSON",
success : function(data) {
if (data.success == "true" || data.success == true) {
alert(data.msg);
if(data.msg=="发送成功"){
$("#content").val("");
$("#phones").val("");
}
$("#message").html("");
} else {
alert("短信发送失败!");
}
},
error : function() {
alert("服务异常,稍后再试!");
}
});
}
}
window.onload = function() {
var oDiv = document.getElementById("div1");
var oP = oDiv.getElementsByTagName('p')[0];
var oT = oDiv.getElementsByTagName('textarea')[0];
var timer = null;
var ie = !-[ 1, ];
var bBtn = true;
var iNum = 0;
oT.onfocus = function() {
if (bBtn) {
oP.innerHTML = '已输入<span>0</span>字,还可以输入<span>350</span>字,最多350个字。';
bBtn = false;
}
};
oT.onblur = function() {
if (oT.value == '') {
oP.innerHTML = '';
bBtn = true;
}
};
//ie下的兼容
if (ie) {
oT.onpropertychange = toChange;
} else {
oT.oninput = toChange;
}
[]
function toChange() {
var num = Math.ceil(getLength(oT.value) / 2);
var oSpan1 = oDiv.getElementsByTagName('span')[0];
var oSpan = oDiv.getElementsByTagName('span')[1];
if (num <= 350) {
oSpan1.innerHTML = num;
oSpan.innerHTML = 350 - num;
oSpan.style.color = '';
} else {
alert("您输入的文字长度达到最多350个字已超出,请酌情删减!");
// oSpan.innerHTML = '-'+num - 350+'字,请酌情删减!';
// oSpan.style.color = 'red';
}
}
function getLength(str) {
return String(str).replace(/[^\x00-\xff]/g, 'aa').length;
}
}
</script>
@RequestMapping(params="sendMessg2")
@ResponseBody
public AjaxJson sendMessg2(HttpServletRequest request){
AjaxJson j = new AjaxJson();
Boolean success=true;//短信发送成功
message = "短信发送成功";
try {
String content=com.sinosoft.app.util.StringUtil.convertToString(request.getParameter("content"));
//String phones=com.sinosoft.app.util.StringUtil.convertToString(request.getParameter("phones"));
String ids=com.sinosoft.app.util.StringUtil.convertToString(request.getParameter("ids"));
if(!StringUtil.isEmpty(content)&&!StringUtil.isEmpty(ids)){
System.out.println(ids);
//调用查询的sql,统计每个UnitID有几个经办人手机号
lhInformationService.getPhoneNumber(ids,content);
}
} catch (Exception e) {
log.error("发送短信失败:"+e.getMessage(),e);
success=false;//短信发送失败
message="短信发送失败";
}
j.setObj(success);
j.setMsg(message);
return j;
}
//通过实体插入数据
@Override
public void intsertSendTask(String phones, String content,String Uids) {
String[] Pphones = phones.split(",");
String[] UUids = Uids.split(",");
// //查询表中的id的最大值
// String IdMax="select Max(TaskID) as TaskID from T_SendTask with(nolock)";
// List<Map> listMax = appCommonDao.findBySql(IdMax);
// BigInteger bi=(BigInteger) listMax.get(0).get("TaskID");
// Integer valueOf = Integer.valueOf(bi.toString());
// int max = valueOf.intValue();
for(int i=0;i<Pphones.length;i++) {
//创建TSendTask实体
// max++;
TSendTaskEntity tsend=new TSendTaskEntity();
//tsend.setTaskID(max);
tsend.setDestNumber(StringUtil.convertToString(Pphones[i]));
tsend.setSendTime(new Date());
tsend.setProcess("用人单位");
tsend.setContent(content);
tsend.setSendPriority(0);
tsend.setGroupId(UUids[i]);
tsend.setBatchId(UUids[i]);
appCommonDao.save(tsend);
}
}
@Override
public void getPhoneNumber(String ids,String content) {
String[] split = ids.split(",");
for(int i=0;i<split.length;i++) {
//定义SQL语句
String strSql="SELECT u.companuy,m.phoneNo FROM lh_regist_unit u with(nolock) left join lh_regist_manager m with(nolock) on m.unitid=u.id where u.id=?";
List<Map<String, Object>> findBySql = appCommonDao.findForJdbc(strSql, split[i]);
for(int j=0;j<findBySql.size();j++) {
Map map = findBySql.get(j);
Object object = map.get("companuy");
Object object2 = map.get("phoneNo");
String companuy = String.valueOf(object);
String phoneNo = String.valueOf(object2);
TSendTaskEntity send=new TSendTaskEntity();
send.setDestNumber(StringUtil.convertToString(phoneNo));
send.setSendTime(new Date());
send.setProcess("用人单位");
send.setContent(content);
send.setSendPriority(0);
send.setGroupId(companuy);
send.setBatchId(companuy);
appCommonDao.save(send);
}
}
}
//跳转到查询短信内容的界面
@RequestMapping(params="checkMessages")
public ModelAndView checkMessages(){
return new ModelAndView("com/sinosoft/lh/web/base/unitregismanag/checkMessages");
}
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/tags.jsp"%>
<t:base type="jquery"></t:base>
<app:template title="数据表格" plugins="jeasyui-extensions">
<input name="Uids" value="${param.id }" id="Uids" type="hidden" >
<div >
<table id="dg" class="easyui-datagrid" style="width: 700px; height: 100px"></table>
</div>
<script type="text/javascript">
$(function() {
var id = '${param.id}';
$('#dg').datagrid({
url:"lhRegisteredController.do?getOldMessages&id="+id,
fitColumns : true, //真正的自动展开/收缩列的大小,以适应网格的宽度,防止水平滚动。
rownumbers :true, //如果为true,则显示一个行号列。
striped : true, //是否显示斑马线效果。
singleSelect:false, //如果为true,则只允许选择一行。
pagination : true,//是否分页
pageSize: 10,//每页显示的记录条数,默认为10
pageList:[10,50,100],//在设置分页属性的时候 初始化页面大小选择列表。
nowrap: true,//提高加载性能
columns:[[
{field:'DestTel',title:'手机号',width:100},
{field:'smsContent',title:'短信内容',width:400},
{field:'SentTime',title:'发送时间',width:200}
]]
});
})
</script>
</app:template>
@RequestMapping(params="getOldMessages")
@ResponseBody
public void getOldMessages(HttpServletRequest request, HttpServletResponse response){
String id = request.getParameter("id");
log.debug("查询过往短信内容");
DataGrid da = new DataGrid();
try {
da = lhRegisteredService.getOldMessage(id);
} catch (Exception e) {
log.error("查询过往短信内容失败"+e.getMessage(),e);
}
saveJsonToResponse(da);
// outPrint(response, da);
log.debug("查询过往短信内容结束");
}
@Override
public DataGrid getOldMessage(String id) {
HashMap<String,Object> map = new HashMap<String,Object>();
String sql = "select DestTel,smsContent,SentTime,batchId,Process from T_SentRecord with(nolock) where batchId = :id";
map.put("id", id);
DataGrid dg = appCommonDao.getDataGridBySql(sql, map);
return dg;
}
模拟主键插入数据
//查询表中的id的最大值
String IdMax="select Max(TaskID) as TaskID from T_SendTask with(nolock)";
List<Map> listMax = appCommonDao.findBySql(IdMax);
BigInteger bi=(BigInteger) listMax.get(0).get("TaskID");
Integer valueOf = Integer.valueOf(bi.toString());
int max = valueOf.intValue();