| | |
| | | <%@ WebHandler Language="C#" Class="GwBlackMobileHandler" %> |
| | | |
| | | using com.softwee.smgw.common; |
| | | |
| | | //using App_Code; |
| | | using Common; |
| | | using Dao; |
| | | using Model; |
| | | using System; |
| | |
| | | |
| | | public class GwBlackMobileHandler : PageHandler<SysUser> |
| | | { |
| | | private HashSet<long> Map = new HashSet<long>(); |
| | | private GwBlackPoolDao _GwBlackPoolDao = new GwBlackPoolDao(); |
| | | private HashSet<long> Map = new HashSet<long>(); |
| | | private GwBlackPoolDao _GwBlackPoolDao = new GwBlackPoolDao(); |
| | | |
| | | public override JsonPageResult ProcessRequestInternal(PageContext<SysUser> context) |
| | | { |
| | | string @string = context.GetString("action"); |
| | | switch (@string) |
| | | public override JsonPageResult ProcessRequestInternal(PageContext<SysUser> context) |
| | | { |
| | | case "saveMobileSegMent": |
| | | return this.SaveMobileSegMent(context); |
| | | case "getMobileSegment": |
| | | return this.GetMobileSegment(context); |
| | | case "loadGwBlackPool": |
| | | return this.LoadGwBlackPool(context); |
| | | case "getGwBlackPool": |
| | | return this.GetGwBlackPool(context); |
| | | case "save": |
| | | return this.Save(context); |
| | | |
| | | //清除黑名单数据 |
| | | |
| | | case "truntateBlackMobile": |
| | | return this.truntateBlackMobile(context); |
| | | //清除黑名单数据END |
| | | |
| | | case "update": |
| | | return this.Update(context); |
| | | case "deletePool": |
| | | return this.DeletePool(context); |
| | | case "loadGwBlackMobile": |
| | | return this.LoadGwBlackMobile(context); |
| | | case "addGwBlackMobile": |
| | | return this.AddGwBlackMobile(context); |
| | | case "deleteMobile": |
| | | return this.DeleteMobile(context); |
| | | case "txtimportBlackMobile": |
| | | return this.ZipImportBlackMobile(context); |
| | | default: |
| | | throw new Exception("Invalid Action=" + @string); |
| | | string @string = context.GetString("action"); |
| | | switch (@string) |
| | | { |
| | | case "saveMobileSegMent": |
| | | return this.SaveMobileSegMent(context); |
| | | case "getMobileSegment": |
| | | return this.GetMobileSegment(context); |
| | | case "loadGwBlackPool": |
| | | return this.LoadGwBlackPool(context); |
| | | case "getGwBlackPool": |
| | | return this.GetGwBlackPool(context); |
| | | case "save": |
| | | return this.Save(context); |
| | | |
| | | //清除黑名单数据 |
| | | |
| | | case "truntateBlackMobile": |
| | | return this.truntateBlackMobile(context); |
| | | //清除黑名单数据END |
| | | |
| | | case "update": |
| | | return this.Update(context); |
| | | case "deletePool": |
| | | return this.DeletePool(context); |
| | | case "loadGwBlackMobile": |
| | | return this.LoadGwBlackMobile(context); |
| | | case "addGwBlackMobile": |
| | | return this.AddGwBlackMobile(context); |
| | | case "deleteMobile": |
| | | return this.DeleteMobile(context); |
| | | case "txtimportBlackMobile": |
| | | return this.ZipImportBlackMobile(context); |
| | | default: |
| | | throw new Exception("Invalid Action=" + @string); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private JsonPageResult SaveMobileSegMent(PageContext<SysUser> context) |
| | | { |
| | | int @int = context.GetInt("pid"); |
| | | string @string = context.GetString("mobileData"); |
| | | if (@int < 0) |
| | | throw new ArgumentException("参数PoolID获取失败"); |
| | | if (string.IsNullOrEmpty(@string)) |
| | | throw new ArgumentException("请填写号段"); |
| | | if (new GwBlackPoolDao().UpMobileSegMentdate(new GwBlackPool() |
| | | private JsonPageResult SaveMobileSegMent(PageContext<SysUser> context) |
| | | { |
| | | PoolID = @int, |
| | | MobileSegMent = SegmentHelper.Filrate(@string) |
| | | })) |
| | | return new JsonPageResult(true, (object) "号段修改成功"); |
| | | return new JsonPageResult(false, (object) "添加号段失败"); |
| | | } |
| | | |
| | | private JsonPageResult GetMobileSegment(PageContext<SysUser> context) |
| | | { |
| | | return new JsonPageResult(true, (object) new GwBlackPoolDao().GetGwBlackPool(context.GetInt("pid"))); |
| | | } |
| | | |
| | | private JsonPageResult LoadGwBlackPool(PageContext<SysUser> context) |
| | | { |
| | | string @string = context.GetString("poolName"); |
| | | int recordcount = 0; |
| | | int int1 = context.GetInt("pageIndex", 1); |
| | | int int2 = context.GetInt("pageSize", 20); |
| | | string str = ""; |
| | | using (GwBlackPoolDao gwBlackPoolDao = new GwBlackPoolDao()) |
| | | { |
| | | List<GwBlackPool> list = gwBlackPoolDao.LoadInfoList(@string, out recordcount, int1, int2); |
| | | if (list != null && list.Count > 0) |
| | | { |
| | | foreach (GwBlackPool gwBlackPool in list) |
| | | int @int = context.GetInt("pid"); |
| | | string @string = context.GetString("mobileData"); |
| | | if (@int < 0) |
| | | throw new ArgumentException("参数PoolID获取失败"); |
| | | if (string.IsNullOrEmpty(@string)) |
| | | throw new ArgumentException("请填写号段"); |
| | | if (new GwBlackPoolDao().UpMobileSegMentdate(new GwBlackPool() |
| | | { |
| | | str = str + (object) "<tr ><td>" + gwBlackPool.PoolName + "</td><td>" + (object) gwBlackPool.BlackPoolID + "</td>"; |
| | | str += "<td>"; |
| | | str += string.Format("<a class=\"btn btn-xs btn-primary btn-poolmobile\" href=\"javascript:;\" data-id=\"{0}\">", (object) gwBlackPool.PoolID); |
| | | str += " 查询</a> "; |
| | | str += string.Format("<a class=\"btn btn-xs btn-primary btn-mobile-segment\" href=\"javascript:;\" data-id=\"{0}\">", (object) gwBlackPool.PoolID); |
| | | str += "<i class=\"fa fa-edit\"></i> 黑名单号段</a> "; |
| | | str += string.Format("<a class=\"action-txtimportBlack btn btn-info btn-xs \" href=\"javascript:;\" data-id=\"{0}\" data-name=\"{1}\">", (object) gwBlackPool.PoolID, (object) gwBlackPool.PoolName); |
| | | str += " 黑名单导入</a> "; |
| | | if (gwBlackPool.PoolID > 0) |
| | | { |
| | | str += string.Format("<a class=\"action-modal-edit btn btn-success btn-xs \" href=\"javascript:;\" data-id=\"{0}\">", (object) gwBlackPool.PoolID); |
| | | str += "<i class='fa fa-edit'></i> 编辑"; |
| | | str += "</a> "; |
| | | str += string.Format("<a class=\"action-delete btnbtn btn btn-default btn-xs\" href=\"javascript:;\" data-id=\"{0}\">", (object) gwBlackPool.PoolID); |
| | | str += "<i class='fa fa-trash'></i> 删除"; |
| | | str += "</a> "; |
| | | } |
| | | str += "</td>"; |
| | | str += "</tr>"; |
| | | } |
| | | } |
| | | else |
| | | str += "<tr><td colspan=\"3\" style=\"text-align: center;\">暂无信息</td></tr>"; |
| | | PoolID = @int, |
| | | MobileSegMent = SegmentHelper.Filrate(@string) |
| | | })) |
| | | return new JsonPageResult(true, (object) "号段修改成功"); |
| | | return new JsonPageResult(false, (object) "添加号段失败"); |
| | | } |
| | | return new JsonPageResult(true, (object) new |
| | | |
| | | private JsonPageResult GetMobileSegment(PageContext<SysUser> context) |
| | | { |
| | | Table = str.ToString(), |
| | | TotalCount = recordcount |
| | | }); |
| | | } |
| | | |
| | | private JsonPageResult Save(PageContext<SysUser> context) |
| | | { |
| | | string @string = context.GetString("poolName"); |
| | | if (string.IsNullOrEmpty(@string)) |
| | | throw new ArgumentException("黑名单池名称不能为空!"); |
| | | if (this._GwBlackPoolDao.IsExitsPoolName(@string)) |
| | | throw new ArgumentException("黑名单池名称已存在!"); |
| | | this._GwBlackPoolDao.Add(new GwBlackPool() |
| | | { |
| | | PoolName = @string |
| | | }); |
| | | return new JsonPageResult(true, (object) "创建黑名单池成功!"); |
| | | } |
| | | |
| | | private JsonPageResult Update(PageContext<SysUser> context) |
| | | { |
| | | int @int = context.GetInt("poolID"); |
| | | string @string = context.GetString("poolName"); |
| | | if (string.IsNullOrEmpty(@string)) |
| | | throw new ArgumentException("黑名单池名称不能为空!"); |
| | | if (this._GwBlackPoolDao.IsExitsPoolName(@string, @int)) |
| | | throw new ArgumentException("黑名单池名称已存在!"); |
| | | this._GwBlackPoolDao.Update(new GwBlackPool() |
| | | { |
| | | PoolID = @int, |
| | | PoolName = @string |
| | | }); |
| | | return new JsonPageResult(true, (object) "修改黑名单池成功!"); |
| | | } |
| | | |
| | | private JsonPageResult DeletePool(PageContext<SysUser> context) |
| | | { |
| | | int @int = context.GetInt("poolID"); |
| | | if (this._GwBlackPoolDao.IsGwOpPortExits(@int)) |
| | | throw new Exception("通道信息配置中正在使用该黑名单池,不能删除!"); |
| | | this._GwBlackPoolDao.DeleteMobile(@int); |
| | | return new JsonPageResult(true, (object) "删除黑名单池成功!"); |
| | | } |
| | | |
| | | |
| | | // 清除黑名单数据成功 |
| | | |
| | | private JsonPageResult truntateBlackMobile(PageContext<SysUser> context) |
| | | { |
| | | this._GwBlackPoolDao.truntateBlackMobile(); |
| | | |
| | | return new JsonPageResult(true,"清除全部黑名单号码成功!"); |
| | | } |
| | | // 清除黑名单数据成功END |
| | | |
| | | |
| | | private JsonPageResult GetGwBlackPool(PageContext<SysUser> context) |
| | | { |
| | | return new JsonPageResult(true, (object) this._GwBlackPoolDao.GetGwBlackPool(context.GetInt("poolID"))); |
| | | } |
| | | |
| | | private JsonPageResult LoadGwBlackMobile(PageContext<SysUser> context) |
| | | { |
| | | string string1 = context.GetString("blackpool"); |
| | | string string2 = context.GetString("mobile"); |
| | | if (string.IsNullOrEmpty(string2)) |
| | | throw new ArgumentException("手机号码不能为空!"); |
| | | string str = ""; |
| | | using (GwBlackPoolDao gwBlackPoolDao = new GwBlackPoolDao()) |
| | | { |
| | | List<GwBlackPool> list = gwBlackPoolDao.LoadInfoList(string1, string2); |
| | | if (list != null && list.Count > 0) |
| | | { |
| | | foreach (GwBlackPool gwBlackPool in list) |
| | | { |
| | | str = str + (object) "<tr ><td>" + gwBlackPool.Mobile + "</td><td>" + gwBlackPool.PoolName + "</td><td>" + (object) gwBlackPool.ModifyTime + "</td>"; |
| | | str += "<td>"; |
| | | str += string.Format("<a class=\"action-mobile-delete btnbtn btn btn-default btn-xs\" href=\"javascript:;\" data-id=\"{0}\" data-moblie=\"{1}\">", (object) gwBlackPool.BlackPoolID, (object) gwBlackPool.Mobile); |
| | | str += "<i class='fa fa-trash'></i> 删除"; |
| | | str += "</a>"; |
| | | str += "</td>"; |
| | | str += "</tr>"; |
| | | } |
| | | } |
| | | else |
| | | str += "<tr><td colspan=\"4\" style=\"text-align: center;\">暂无信息</td></tr>"; |
| | | return new JsonPageResult(true, (object) new GwBlackPoolDao().GetGwBlackPool(context.GetInt("pid"))); |
| | | } |
| | | return new JsonPageResult(true, (object) new |
| | | { |
| | | Table = str.ToString() |
| | | }); |
| | | } |
| | | |
| | | private JsonPageResult AddGwBlackMobile(PageContext<SysUser> context) |
| | | { |
| | | string string1 = context.GetString("blackpool"); |
| | | string string2 = context.GetString("mobile"); |
| | | if (string.IsNullOrEmpty(string1)) |
| | | throw new ArgumentException("黑名单池不能为空!"); |
| | | if (string.IsNullOrEmpty(string2)) |
| | | throw new ArgumentException("手机号码不能为空!"); |
| | | if (!this._GwBlackPoolDao.IsPortExits(Convert.ToInt32(string1), string2)) |
| | | throw new Exception("黑名单号码已存在!"); |
| | | this._GwBlackPoolDao.AddMobile(Convert.ToInt32(string1), string2); |
| | | return new JsonPageResult(true, (object) "新增黑名单号码成功!"); |
| | | } |
| | | |
| | | private JsonPageResult DeleteMobile(PageContext<SysUser> context) |
| | | { |
| | | this._GwBlackPoolDao.DeleteMobile(context.GetInt("poolID"), context.GetString("mobile")); |
| | | return new JsonPageResult(true, (object) "删除黑名单号码成功!"); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | private JsonPageResult ZipImportBlackMobile(PageContext<SysUser> context) |
| | | { |
| | | Stopwatch stopwatch = new Stopwatch(); |
| | | stopwatch.Start(); |
| | | HttpPostedFile httpPostedFile = context.Files["certPath"]; |
| | | if (httpPostedFile == null || httpPostedFile.FileName == "") |
| | | throw new Exception("请选择要导入的zip文件,并检查文件大小!"); |
| | | string extension = Path.GetExtension(httpPostedFile.FileName); |
| | | if (!extension.Equals(".zip", StringComparison.OrdinalIgnoreCase) && !extension.Equals(".txt", StringComparison.OrdinalIgnoreCase)) |
| | | throw new Exception("导入文件格式不正确,只允许导入zip或txt文件!"); |
| | | if (httpPostedFile.ContentLength > 104857600) |
| | | throw new Exception("文件上传不能超过100M,请检查文件大小,是否有写权限!"); |
| | | string @string = context.GetString("ablackpool"); |
| | | if (string.IsNullOrEmpty(@string)) |
| | | throw new Exception("请选择黑名单池!"); |
| | | List<Stream> outputStreamList = new List<Stream>(); |
| | | if (extension.Equals(".txt", StringComparison.OrdinalIgnoreCase)) |
| | | outputStreamList.Add(httpPostedFile.InputStream); |
| | | else if (extension.Equals(".zip", StringComparison.OrdinalIgnoreCase)) |
| | | ZipUtils.Decompression(httpPostedFile.InputStream, ref outputStreamList, true); |
| | | HashSet<string> blackPoolMobile = this._GwBlackPoolDao.GetBlackPoolMobile(Convert.ToInt32(@string.ToString())); |
| | | HashSet<string> tempSet = new HashSet<string>(); |
| | | DataTable dt = new DataTable("GW_BLACKPOOL_MOBILE"); |
| | | dt.Columns.Add("MOBILE", typeof (string)); |
| | | DateTime now = DateTime.Now; |
| | | DataColumn column1 = new DataColumn("BLACKPOOL_ID", typeof (int)); |
| | | DataColumn column2 = new DataColumn("MODIFY_TIME", typeof (DateTime)); |
| | | DataColumn column3 = new DataColumn("IS_DELETED", typeof (int)); |
| | | column1.DefaultValue = (object) @string; |
| | | column2.DefaultValue = (object) now; |
| | | column3.DefaultValue = (object) 0; |
| | | dt.Columns.Add(column1); |
| | | dt.Columns.Add(column2); |
| | | dt.Columns.Add(column3); |
| | | StringBuilder errorBuilder = new StringBuilder(); |
| | | int count = 0; |
| | | foreach (Stream stream in outputStreamList) |
| | | private JsonPageResult LoadGwBlackPool(PageContext<SysUser> context) |
| | | { |
| | | stream.Seek(0L, SeekOrigin.Begin); |
| | | count += this.ProcessStream(blackPoolMobile, tempSet, dt, errorBuilder, stream); |
| | | } |
| | | int num = this.SaveDataTable(dt, now, count); |
| | | stopwatch.Stop(); |
| | | string str = "数量:" + (object) num + "个,耗时:" + (object) stopwatch.ElapsedMilliseconds + "ms"; |
| | | if (errorBuilder.Length > 0) |
| | | str = str + ",错误号码包含:" + errorBuilder.ToString(); |
| | | return new JsonPageResult(true, (object) new |
| | | { |
| | | Message = "全局黑名单导入成功!", |
| | | Msg = str |
| | | }); |
| | | } |
| | | |
| | | private int SaveDataTable(DataTable dt, DateTime dtime, int count) |
| | | { |
| | | if (dt != null) |
| | | { |
| | | if (dt.Rows.Count > 0) |
| | | { |
| | | try |
| | | string @string = context.GetString("poolName"); |
| | | int recordcount = 0; |
| | | int int1 = context.GetInt("pageIndex", 1); |
| | | int int2 = context.GetInt("pageSize", 20); |
| | | string str = ""; |
| | | using (GwBlackPoolDao gwBlackPoolDao = new GwBlackPoolDao()) |
| | | { |
| | | this._GwBlackPoolDao.Import(dt); |
| | | this._GwBlackPoolDao.Add_EventLog(dtime); |
| | | count += dt.Rows.Count; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception("写入数据出错:" + ex.Message); |
| | | } |
| | | } |
| | | } |
| | | return count; |
| | | } |
| | | |
| | | private int ProcessStream(HashSet<string> existsSet, HashSet<string> tempSet, DataTable dt, StringBuilder errorBuilder, Stream stream) |
| | | { |
| | | int count = 0; |
| | | using (StreamReader streamReader = new StreamReader(stream, Encoding.Default)) |
| | | { |
| | | Regex regex = new Regex("^1[34578]\\d{9}$"); |
| | | int num = 0; |
| | | while (!streamReader.EndOfStream) |
| | | { |
| | | string str1; |
| | | try |
| | | { |
| | | str1 = streamReader.ReadLine(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception("读取文件出错,手机号码请换行!"); |
| | | } |
| | | if (!string.IsNullOrEmpty(str1)) |
| | | { |
| | | string[] strArray; |
| | | try |
| | | { |
| | | strArray = str1.Split(new char[8] |
| | | List<GwBlackPool> list = gwBlackPoolDao.LoadInfoList(@string, out recordcount, int1, int2); |
| | | if (list != null && list.Count > 0) |
| | | { |
| | | foreach (GwBlackPool gwBlackPool in list) |
| | | { |
| | | str = str + (object) "<tr ><td>" + gwBlackPool.PoolName + "</td><td>" + (object) gwBlackPool.BlackPoolID + "</td>"; |
| | | str += "<td>"; |
| | | str += string.Format("<a class=\"btn btn-xs btn-primary btn-poolmobile\" href=\"javascript:;\" data-id=\"{0}\">", (object) gwBlackPool.PoolID); |
| | | str += " 查询</a> "; |
| | | str += string.Format("<a class=\"btn btn-xs btn-primary btn-mobile-segment\" href=\"javascript:;\" data-id=\"{0}\">", (object) gwBlackPool.PoolID); |
| | | str += "<i class=\"fa fa-edit\"></i> 黑名单号段</a> "; |
| | | str += string.Format("<a class=\"action-txtimportBlack btn btn-info btn-xs \" href=\"javascript:;\" data-id=\"{0}\" data-name=\"{1}\">", (object) gwBlackPool.PoolID, (object) gwBlackPool.PoolName); |
| | | str += " 黑名单导入</a> "; |
| | | if (gwBlackPool.PoolID > 0) |
| | | { |
| | | str += string.Format("<a class=\"action-modal-edit btn btn-success btn-xs \" href=\"javascript:;\" data-id=\"{0}\">", (object) gwBlackPool.PoolID); |
| | | str += "<i class='fa fa-edit'></i> 编辑"; |
| | | str += "</a> "; |
| | | str += string.Format("<a class=\"action-delete btnbtn btn btn-default btn-xs\" href=\"javascript:;\" data-id=\"{0}\">", (object) gwBlackPool.PoolID); |
| | | str += "<i class='fa fa-trash'></i> 删除"; |
| | | str += "</a> "; |
| | | } |
| | | str += "</td>"; |
| | | str += "</tr>"; |
| | | } |
| | | } |
| | | else |
| | | str += "<tr><td colspan=\"3\" style=\"text-align: center;\">暂无信息</td></tr>"; |
| | | } |
| | | return new JsonPageResult(true, (object) new |
| | | { |
| | | Table = str.ToString(), |
| | | TotalCount = recordcount |
| | | }); |
| | | } |
| | | |
| | | private JsonPageResult Save(PageContext<SysUser> context) |
| | | { |
| | | string @string = context.GetString("poolName"); |
| | | if (string.IsNullOrEmpty(@string)) |
| | | throw new ArgumentException("黑名单池名称不能为空!"); |
| | | if (this._GwBlackPoolDao.IsExitsPoolName(@string)) |
| | | throw new ArgumentException("黑名单池名称已存在!"); |
| | | this._GwBlackPoolDao.Add(new GwBlackPool() |
| | | { |
| | | PoolName = @string |
| | | }); |
| | | return new JsonPageResult(true, (object) "创建黑名单池成功!"); |
| | | } |
| | | |
| | | private JsonPageResult Update(PageContext<SysUser> context) |
| | | { |
| | | int @int = context.GetInt("poolID"); |
| | | string @string = context.GetString("poolName"); |
| | | if (string.IsNullOrEmpty(@string)) |
| | | throw new ArgumentException("黑名单池名称不能为空!"); |
| | | if (this._GwBlackPoolDao.IsExitsPoolName(@string, @int)) |
| | | throw new ArgumentException("黑名单池名称已存在!"); |
| | | this._GwBlackPoolDao.Update(new GwBlackPool() |
| | | { |
| | | PoolID = @int, |
| | | PoolName = @string |
| | | }); |
| | | return new JsonPageResult(true, (object) "修改黑名单池成功!"); |
| | | } |
| | | |
| | | private JsonPageResult DeletePool(PageContext<SysUser> context) |
| | | { |
| | | int @int = context.GetInt("poolID"); |
| | | if (this._GwBlackPoolDao.IsGwOpPortExits(@int)) |
| | | throw new Exception("通道信息配置中正在使用该黑名单池,不能删除!"); |
| | | this._GwBlackPoolDao.DeleteMobile(@int); |
| | | return new JsonPageResult(true, (object) "删除黑名单池成功!"); |
| | | } |
| | | |
| | | |
| | | // 清除黑名单数据成功 |
| | | |
| | | private JsonPageResult truntateBlackMobile(PageContext<SysUser> context) |
| | | { |
| | | this._GwBlackPoolDao.truntateBlackMobile(); |
| | | |
| | | return new JsonPageResult(true,"清除全部黑名单号码成功!"); |
| | | } |
| | | // 清除黑名单数据成功END |
| | | |
| | | |
| | | private JsonPageResult GetGwBlackPool(PageContext<SysUser> context) |
| | | { |
| | | return new JsonPageResult(true, (object) this._GwBlackPoolDao.GetGwBlackPool(context.GetInt("poolID"))); |
| | | } |
| | | |
| | | private JsonPageResult LoadGwBlackMobile(PageContext<SysUser> context) |
| | | { |
| | | string string1 = context.GetString("blackpool"); |
| | | string string2 = context.GetString("mobile"); |
| | | if (string.IsNullOrEmpty(string2)) |
| | | throw new ArgumentException("手机号码不能为空!"); |
| | | string str = ""; |
| | | using (GwBlackPoolDao gwBlackPoolDao = new GwBlackPoolDao()) |
| | | { |
| | | List<GwBlackPool> list = gwBlackPoolDao.LoadInfoList(string1, string2); |
| | | if (list != null && list.Count > 0) |
| | | { |
| | | foreach (GwBlackPool gwBlackPool in list) |
| | | { |
| | | str = str + (object) "<tr ><td>" + gwBlackPool.Mobile + "</td><td>" + gwBlackPool.PoolName + "</td><td>" + (object) gwBlackPool.ModifyTime + "</td>"; |
| | | str += "<td>"; |
| | | str += string.Format("<a class=\"action-mobile-delete btnbtn btn btn-default btn-xs\" href=\"javascript:;\" data-id=\"{0}\" data-moblie=\"{1}\">", (object) gwBlackPool.BlackPoolID, (object) gwBlackPool.Mobile); |
| | | str += "<i class='fa fa-trash'></i> 删除"; |
| | | str += "</a>"; |
| | | str += "</td>"; |
| | | str += "</tr>"; |
| | | } |
| | | } |
| | | else |
| | | str += "<tr><td colspan=\"4\" style=\"text-align: center;\">暂无信息</td></tr>"; |
| | | } |
| | | return new JsonPageResult(true, (object) new |
| | | { |
| | | Table = str.ToString() |
| | | }); |
| | | } |
| | | |
| | | private JsonPageResult AddGwBlackMobile(PageContext<SysUser> context) |
| | | { |
| | | string string1 = context.GetString("blackpool"); |
| | | string string2 = context.GetString("mobile"); |
| | | if (string.IsNullOrEmpty(string1)) |
| | | throw new ArgumentException("黑名单池不能为空!"); |
| | | if (string.IsNullOrEmpty(string2)) |
| | | throw new ArgumentException("手机号码不能为空!"); |
| | | if (!this._GwBlackPoolDao.IsPortExits(Convert.ToInt32(string1), string2)) |
| | | throw new Exception("黑名单号码已存在!"); |
| | | this._GwBlackPoolDao.AddMobile(Convert.ToInt32(string1), string2); |
| | | return new JsonPageResult(true, (object) "新增黑名单号码成功!"); |
| | | } |
| | | |
| | | private JsonPageResult DeleteMobile(PageContext<SysUser> context) |
| | | { |
| | | this._GwBlackPoolDao.DeleteMobile(context.GetInt("poolID"), context.GetString("mobile")); |
| | | return new JsonPageResult(true, (object) "删除黑名单号码成功!"); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | private JsonPageResult ZipImportBlackMobile(PageContext<SysUser> context) |
| | | { |
| | | Stopwatch stopwatch = new Stopwatch(); |
| | | stopwatch.Start(); |
| | | HttpPostedFile httpPostedFile = context.Files["certPath"]; |
| | | if (httpPostedFile == null || httpPostedFile.FileName == "") |
| | | throw new Exception("请选择要导入的zip文件,并检查文件大小!"); |
| | | string extension = Path.GetExtension(httpPostedFile.FileName); |
| | | if (!extension.Equals(".zip", StringComparison.OrdinalIgnoreCase) && !extension.Equals(".txt", StringComparison.OrdinalIgnoreCase)) |
| | | throw new Exception("导入文件格式不正确,只允许导入zip或txt文件!"); |
| | | if (httpPostedFile.ContentLength > 104857600) |
| | | throw new Exception("文件上传不能超过100M,请检查文件大小,是否有写权限!"); |
| | | string @string = context.GetString("ablackpool"); |
| | | if (string.IsNullOrEmpty(@string)) |
| | | throw new Exception("请选择黑名单池!"); |
| | | List<Stream> outputStreamList = new List<Stream>(); |
| | | if (extension.Equals(".txt", StringComparison.OrdinalIgnoreCase)) |
| | | outputStreamList.Add(httpPostedFile.InputStream); |
| | | else if (extension.Equals(".zip", StringComparison.OrdinalIgnoreCase)) |
| | | ZipUtils.Decompression(httpPostedFile.InputStream, ref outputStreamList, true); |
| | | HashSet<string> blackPoolMobile = this._GwBlackPoolDao.GetBlackPoolMobile(Convert.ToInt32(@string.ToString())); |
| | | HashSet<string> tempSet = new HashSet<string>(); |
| | | DataTable dt = new DataTable("GW_BLACKPOOL_MOBILE"); |
| | | dt.Columns.Add("MOBILE", typeof (string)); |
| | | DateTime now = DateTime.Now; |
| | | DataColumn column1 = new DataColumn("BLACKPOOL_ID", typeof (int)); |
| | | DataColumn column2 = new DataColumn("MODIFY_TIME", typeof (DateTime)); |
| | | DataColumn column3 = new DataColumn("IS_DELETED", typeof (int)); |
| | | column1.DefaultValue = (object) @string; |
| | | column2.DefaultValue = (object) now; |
| | | column3.DefaultValue = (object) 0; |
| | | dt.Columns.Add(column1); |
| | | dt.Columns.Add(column2); |
| | | dt.Columns.Add(column3); |
| | | StringBuilder errorBuilder = new StringBuilder(); |
| | | int count = 0; |
| | | foreach (Stream stream in outputStreamList) |
| | | { |
| | | stream.Seek(0L, SeekOrigin.Begin); |
| | | count += this.ProcessStream(blackPoolMobile, tempSet, dt, errorBuilder, stream); |
| | | } |
| | | int num = this.SaveDataTable(dt, now, count); |
| | | stopwatch.Stop(); |
| | | string str = "数量:" + (object) num + "个,耗时:" + (object) stopwatch.ElapsedMilliseconds + "ms"; |
| | | if (errorBuilder.Length > 0) |
| | | str = str + ",错误号码包含:" + errorBuilder.ToString(); |
| | | return new JsonPageResult(true, (object) new |
| | | { |
| | | Message = "全局黑名单导入成功!", |
| | | Msg = str |
| | | }); |
| | | } |
| | | |
| | | private int SaveDataTable(DataTable dt, DateTime dtime, int count) |
| | | { |
| | | if (dt != null) |
| | | { |
| | | if (dt.Rows.Count > 0) |
| | | { |
| | | try |
| | | { |
| | | this._GwBlackPoolDao.Import(dt); |
| | | this._GwBlackPoolDao.Add_EventLog(dtime); |
| | | count += dt.Rows.Count; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception("写入数据出错:" + ex.Message); |
| | | } |
| | | } |
| | | } |
| | | return count; |
| | | } |
| | | |
| | | private int ProcessStream(HashSet<string> existsSet, HashSet<string> tempSet, DataTable dt, StringBuilder errorBuilder, Stream stream) |
| | | { |
| | | int count = 0; |
| | | using (StreamReader streamReader = new StreamReader(stream, Encoding.Default)) |
| | | { |
| | | Regex regex = new Regex("^1[34578]\\d{9}$"); |
| | | int num = 0; |
| | | while (!streamReader.EndOfStream) |
| | | { |
| | | string str1; |
| | | try |
| | | { |
| | | str1 = streamReader.ReadLine(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception("读取文件出错,手机号码请换行!"); |
| | | } |
| | | if (!string.IsNullOrEmpty(str1)) |
| | | { |
| | | string[] strArray; |
| | | try |
| | | { |
| | | strArray = str1.Split(new char[8] |
| | | { |
| | | '\r', |
| | | '\n', |
| | | ',', |
| | |
| | | '|', |
| | | ';', |
| | | ',' |
| | | }, StringSplitOptions.RemoveEmptyEntries); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception("分割手机号码出错!"); |
| | | } |
| | | foreach (string str2 in strArray) |
| | | { |
| | | string input = str2.Trim(); |
| | | if (!regex.IsMatch(input)) |
| | | errorBuilder.AppendFormat("{0};", (object) input); |
| | | else if (!existsSet.Contains(input) && !tempSet.Contains(input)) |
| | | { |
| | | ++num; |
| | | DataRow row = dt.NewRow(); |
| | | row["MOBILE"] = (object) input; |
| | | dt.Rows.Add(row); |
| | | tempSet.Add(input); |
| | | }, StringSplitOptions.RemoveEmptyEntries); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception("分割手机号码出错!"); |
| | | } |
| | | foreach (string str2 in strArray) |
| | | { |
| | | string input = str2.Trim(); |
| | | if (!regex.IsMatch(input)) |
| | | errorBuilder.AppendFormat("{0};", (object) input); |
| | | else if (!existsSet.Contains(input) && !tempSet.Contains(input)) |
| | | { |
| | | ++num; |
| | | DataRow row = dt.NewRow(); |
| | | row["MOBILE"] = (object) input; |
| | | dt.Rows.Add(row); |
| | | tempSet.Add(input); |
| | | } |
| | | if (num == 1000000) |
| | | { |
| | | count = this.SaveDataTable(dt, DateTime.Now, count); |
| | | num = 0; |
| | | dt.Clear(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if (num == 1000000) |
| | | { |
| | | count = this.SaveDataTable(dt, DateTime.Now, count); |
| | | num = 0; |
| | | dt.Clear(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return count; |
| | | } |
| | | return count; |
| | | } |
| | | |
| | | private JsonPageResult TxtImportBlackMobile(PageContext<SysUser> context) |
| | | { |
| | | Stopwatch stopwatch = new Stopwatch(); |
| | | stopwatch.Start(); |
| | | HttpPostedFile httpPostedFile = context.Files["certPath"]; |
| | | if (httpPostedFile == null) |
| | | throw new Exception("未选择文件或上传文件超过10M!"); |
| | | if (httpPostedFile.FileName == "") |
| | | throw new Exception("请选择要导入的txt文件!"); |
| | | string extension = Path.GetExtension(httpPostedFile.FileName); |
| | | if (!extension.Equals(".txt") && !extension.Equals(".TXT")) |
| | | throw new Exception("导入文件格式不正确,只允许导入txt文件!"); |
| | | if (httpPostedFile.ContentLength > 10485760) |
| | | throw new Exception("文件上传不能超过10M,请检查文件大小,是否有写权限!"); |
| | | string @string = context.GetString("ablackpool"); |
| | | if (string.IsNullOrEmpty(@string)) |
| | | throw new Exception("请选择黑名单池!"); |
| | | HashSet<string> blackPoolMobile = this._GwBlackPoolDao.GetBlackPoolMobile(Convert.ToInt32(@string.ToString())); |
| | | HashSet<string> hashSet = new HashSet<string>(); |
| | | DataTable dt = new DataTable("GW_BLACKPOOL_MOBILE"); |
| | | dt.Columns.Add("MOBILE", typeof (string)); |
| | | DateTime dtime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); |
| | | DataColumn column1 = new DataColumn("BLACKPOOL_ID", typeof (int)); |
| | | DataColumn column2 = new DataColumn("MODIFY_TIME", typeof (DateTime)); |
| | | DataColumn column3 = new DataColumn("IS_DELETED", typeof (int)); |
| | | column1.DefaultValue = (object) @string; |
| | | column2.DefaultValue = (object) dtime; |
| | | column3.DefaultValue = (object) 0; |
| | | dt.Columns.Add(column1); |
| | | dt.Columns.Add(column2); |
| | | dt.Columns.Add(column3); |
| | | StringBuilder stringBuilder = new StringBuilder(); |
| | | using (StreamReader streamReader = new StreamReader(httpPostedFile.InputStream, Encoding.Default)) |
| | | private JsonPageResult TxtImportBlackMobile(PageContext<SysUser> context) |
| | | { |
| | | Regex regex = new Regex("^1[34578]\\d{9}$"); |
| | | string str1 = streamReader.ReadToEnd(); |
| | | if (!string.IsNullOrEmpty(str1)) |
| | | { |
| | | string str2 = str1; |
| | | char[] separator = new char[6] |
| | | Stopwatch stopwatch = new Stopwatch(); |
| | | stopwatch.Start(); |
| | | HttpPostedFile httpPostedFile = context.Files["certPath"]; |
| | | if (httpPostedFile == null) |
| | | throw new Exception("未选择文件或上传文件超过10M!"); |
| | | if (httpPostedFile.FileName == "") |
| | | throw new Exception("请选择要导入的txt文件!"); |
| | | string extension = Path.GetExtension(httpPostedFile.FileName); |
| | | if (!extension.Equals(".txt") && !extension.Equals(".TXT")) |
| | | throw new Exception("导入文件格式不正确,只允许导入txt文件!"); |
| | | if (httpPostedFile.ContentLength > 10485760) |
| | | throw new Exception("文件上传不能超过10M,请检查文件大小,是否有写权限!"); |
| | | string @string = context.GetString("ablackpool"); |
| | | if (string.IsNullOrEmpty(@string)) |
| | | throw new Exception("请选择黑名单池!"); |
| | | HashSet<string> blackPoolMobile = this._GwBlackPoolDao.GetBlackPoolMobile(Convert.ToInt32(@string.ToString())); |
| | | HashSet<string> hashSet = new HashSet<string>(); |
| | | DataTable dt = new DataTable("GW_BLACKPOOL_MOBILE"); |
| | | dt.Columns.Add("MOBILE", typeof (string)); |
| | | DateTime dtime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); |
| | | DataColumn column1 = new DataColumn("BLACKPOOL_ID", typeof (int)); |
| | | DataColumn column2 = new DataColumn("MODIFY_TIME", typeof (DateTime)); |
| | | DataColumn column3 = new DataColumn("IS_DELETED", typeof (int)); |
| | | column1.DefaultValue = (object) @string; |
| | | column2.DefaultValue = (object) dtime; |
| | | column3.DefaultValue = (object) 0; |
| | | dt.Columns.Add(column1); |
| | | dt.Columns.Add(column2); |
| | | dt.Columns.Add(column3); |
| | | StringBuilder stringBuilder = new StringBuilder(); |
| | | using (StreamReader streamReader = new StreamReader(httpPostedFile.InputStream, Encoding.Default)) |
| | | { |
| | | Regex regex = new Regex("^1[34578]\\d{9}$"); |
| | | string str1 = streamReader.ReadToEnd(); |
| | | if (!string.IsNullOrEmpty(str1)) |
| | | { |
| | | string str2 = str1; |
| | | char[] separator = new char[6] |
| | | { |
| | | '\r', |
| | | '\n', |
| | | ',', |
| | | ';', |
| | | ' ', |
| | | '|' |
| | | }; |
| | | int num = 1; |
| | | foreach (string str3 in str2.Split(separator, (StringSplitOptions) num)) |
| | | { |
| | | string input = str3.Trim(); |
| | | if (!regex.IsMatch(input)) |
| | | stringBuilder.AppendFormat("{0};", (object) input); |
| | | else if (!blackPoolMobile.Contains(input) && !hashSet.Contains(input)) |
| | | { |
| | | DataRow row = dt.NewRow(); |
| | | row["MOBILE"] = (object) input; |
| | | dt.Rows.Add(row); |
| | | hashSet.Add(input); |
| | | } |
| | | }; |
| | | int num = 1; |
| | | foreach (string str3 in str2.Split(separator, (StringSplitOptions) num)) |
| | | { |
| | | string input = str3.Trim(); |
| | | if (!regex.IsMatch(input)) |
| | | stringBuilder.AppendFormat("{0};", (object) input); |
| | | else if (!blackPoolMobile.Contains(input) && !hashSet.Contains(input)) |
| | | { |
| | | DataRow row = dt.NewRow(); |
| | | row["MOBILE"] = (object) input; |
| | | dt.Rows.Add(row); |
| | | hashSet.Add(input); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | int num1 = 0; |
| | | if (dt != null) |
| | | { |
| | | if (dt.Rows.Count > 0) |
| | | { |
| | | try |
| | | { |
| | | num1 = this._GwBlackPoolDao.Import(dt, dtime); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception("写入数据出错:" + ex.Message); |
| | | } |
| | | } |
| | | } |
| | | stopwatch.Stop(); |
| | | string str = "数量:" + (object) num1 + "个,耗时:" + (object) stopwatch.ElapsedMilliseconds + "ms"; |
| | | if (stringBuilder.Length > 0) |
| | | str = str + ",错误号码包含:" + stringBuilder.ToString(); |
| | | "".TrimEnd(','); |
| | | return new JsonPageResult(true, (object) new |
| | | { |
| | | Message = "全局黑名单导入成功!", |
| | | Msg = str |
| | | }); |
| | | } |
| | | int num1 = 0; |
| | | if (dt != null) |
| | | { |
| | | if (dt.Rows.Count > 0) |
| | | { |
| | | try |
| | | { |
| | | num1 = this._GwBlackPoolDao.Import(dt, dtime); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception("写入数据出错:" + ex.Message); |
| | | } |
| | | } |
| | | } |
| | | stopwatch.Stop(); |
| | | string str = "数量:" + (object) num1 + "个,耗时:" + (object) stopwatch.ElapsedMilliseconds + "ms"; |
| | | if (stringBuilder.Length > 0) |
| | | str = str + ",错误号码包含:" + stringBuilder.ToString(); |
| | | "".TrimEnd(','); |
| | | return new JsonPageResult(true, (object) new |
| | | { |
| | | Message = "全局黑名单导入成功!", |
| | | Msg = str |
| | | }); |
| | | } |
| | | } |