/// <summary>
        /// 根据用户名送短信
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public bool SendMessgae(SendMessgae request)
        {
            using (var db = DbFactory.Open())
            {
                if (string.IsNullOrEmpty(request.name))
                {
                    throw new Exception("用户名不能为空");
                }

                var builder = db.From <UserInfo>();
                if (!string.IsNullOrEmpty(request.name))
                {
                    builder.Where(x => x.UserName == request.name);
                }
                var checkCode = HostContext.AppHost.Resolve <ICacheClient>().Get <string>("checkCode");
                if (!string.IsNullOrEmpty(checkCode))
                {
                    HostContext.AppHost.Resolve <ICacheClient>().Remove("checkCode");
                }
                var info = db.Single(builder);
                if (info != null)
                {
                    if (!ValidatorHelper.IsMobile(info.UserName) && string.IsNullOrEmpty(info.Mobile))//|| ValidatorHelper.IsMobile(info.Mobile)
                    {
                        throw new Exception("该用户没有手机号码");
                    }
                    Random rd  = new Random();
                    int    num = rd.Next(100000, 1000000);

                    var content = "您正在登陆《浙江省基层防汛防台体系信息管理系统》,为防止他人登陆系统篡改信息千万不要告诉他人验证码 " + num.ToString() + "[五分钟内有效]。如不是您自己操作,请忽略。";
                    var msg     = SmsSend.SendSMS(info.UserName, content);
                    if (msg != "" && msg.IndexOf("-") > 0)
                    {
                        var message = new SaveSmsMessage();
                        message.adcd     = info.adcd;
                        message.Content  = content;
                        message.Mobile   = info.UserName;
                        message.UserName = info.UserName;
                        message.name     = info.RealName;
                        message.tm       = DateTime.Now;
                        MessageManager.SaveMessage(message);

                        HostContext.AppHost.Resolve <ICacheClient>().Add("checkCode", num.ToString());
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    throw new Exception("用户名不存在");
                }
            }
        }
        /// <summary>
        /// 保存镇级责任人
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public bool SaveTown(SaveTown request)
        {
            bool result = false;

            using (var db = DbFactory.Open())
            {
                if (string.IsNullOrEmpty(adcd))
                {
                    throw new Exception("请重新登录");
                }
                if (!ValidatorHelper.IsMobile(request.Mobile))
                {
                    throw new Exception("手机号码输入错误,请重新输入");
                }
                var info = new TownPersonLiable();
                var log  = new operateLog();
                log.userName    = RealName;
                log.operateTime = DateTime.Now;
                //判断是否已经存在数据
                if (request.Id != 0)
                {
                    var model = GetTownByName(request.name, request.Position, request.Post, request.Mobile, request.Remark, request.Id.ToString());
                    if (model != null)
                    {
                        throw new Exception("已存在");
                    }
                    info.Id        = request.Id;
                    log.operateMsg = "更新" + request.name + "的镇级责任人信息";
                }
                else
                {
                    var model = GetTownByName(request.name, request.Position, "", "", "", "");
                    if (model != null)
                    {
                        throw new Exception("已存在");
                    }
                    log.operateMsg = "新增" + request.name + "的镇级责任人信息";
                }

                info.adcd       = adcd;
                info.Name       = request.name.Trim();
                info.CreateTime = DateTime.Now;
                info.Mobile     = request.Mobile.Trim();
                info.Position   = request.Position;
                info.Post       = request.Post;
                info.Year       = DateTime.Now.Year;
                info.Remark     = request.Remark;
                //新数据
                List <TownPersonLiable> _newdata = new List <TownPersonLiable>();
                _newdata.Add(info);
                //
                var listLog = new List <operateLog>();
                listLog.Add(log);
                info.operateLog = JsonTools.ObjectToJson(listLog);
                if (request.Id != 0)
                {
                    #region 旧数据,新数据
                    //取出数据
                    //写入更新记录
                    var r = db.Single <TownPersonLiable>(w => w.Id == request.Id);
                    TownPersonLiable _olddata = new TownPersonLiable()
                    {
                        adcd       = r.adcd,
                        Name       = r.Name,
                        CreateTime = r.CreateTime,
                        Post       = r.Post,
                        Position   = r.Position,
                        Mobile     = r.Mobile,
                        Year       = r.Year,
                        Remark     = r.Remark
                    };
                    if (AuditNums != null)
                    {
                        List <TownPersonLiable> _listOldData = new List <TownPersonLiable>();
                        _listOldData.Add(_olddata);
                        info.AuditNums = AuditNums.Value + 1;
                        //旧数据写入实体
                        info.OldData = JsonTools.ObjectToJson(_listOldData);
                        //新数据写入实体
                        info.NewData = JsonTools.ObjectToJson(_newdata);
                    }
                    #endregion
                    #region 日志
                    StringBuilder sb       = new StringBuilder();
                    var           adcdInfo = db.Single <ADCDInfo>(w => w.adcd == _olddata.adcd);
                    sb.Append("在栏目{组织责任/乡(镇、街道)防汛防台责任人}下,更新数据{");
                    sb.Append("村ADCD:" + adcdInfo.adnm + ";");
                    sb.Append("姓名:" + _olddata.Name + ";");
                    sb.Append("创建时间:" + _olddata.CreateTime + ";");
                    sb.Append("手机:" + _olddata.Mobile + ";");
                    sb.Append("职务:" + _olddata.Position + ";");
                    sb.Append("岗位:" + _olddata.Post + ";");
                    sb.Append("年度:" + _olddata.Year + ";");
                    sb.Append("备注:" + _olddata.Remark + ";");
                    sb.Append("}为{");
                    sb.Append("村ADCD:" + adcdInfo.adnm + ";");
                    sb.Append("姓名:" + info.Name + ";");
                    sb.Append("创建时间:" + info.CreateTime + ";");
                    sb.Append("手机:" + info.Mobile + ";");
                    sb.Append("职务:" + info.Position + ";");
                    sb.Append("岗位:" + info.Post + ";");
                    sb.Append("年度:" + info.Year + ";");
                    sb.Append("备注:" + info.Remark + ";");
                    sb.Append("}");
                    _ILogHelper.WriteLog(sb.ToString(), OperationTypeEnums.更新);
                    #endregion
                    result = db.Update(info) == 1;
                    //if (result && (_olddata.Mobile.Trim() != info.Mobile || _olddata.Name.Trim() != info.Name || _olddata.adcd != info.adcd))
                    //{
                    //    _IAppRegPersonUpdate.AppRegPersonSaveOne(new AppRegPersonSaveOne() { adcdid = adcdInfo.Id, username= info.Name, hanphone = info.Mobile });
                    //}
                    return(result);
                }
                else
                {
                    #region 新增数据
                    //写入更新记录
                    if (AuditNums != null)
                    {
                        info.AuditNums = AuditNums.Value + 1;
                    }
                    #endregion
                    #region 日志
                    StringBuilder sb       = new StringBuilder();
                    var           adcdInfo = db.Single <ADCDInfo>(w => w.adcd == info.adcd);
                    sb.Append("在栏目{组织责任/乡(镇、街道)防汛防台责任人}下,新增数据{");
                    sb.Append("村ADCD:" + adcdInfo.adnm + ";");
                    sb.Append("姓名:" + info.Name + ";");
                    sb.Append("创建时间:" + info.CreateTime + ";");
                    sb.Append("手机:" + info.Mobile + ";");
                    sb.Append("职务:" + info.Position + ";");
                    sb.Append("岗位:" + info.Post + ";");
                    sb.Append("年度:" + info.Year + ";");
                    sb.Append("备注:" + info.Remark + ";");
                    sb.Append("}");
                    _ILogHelper.WriteLog(sb.ToString(), OperationTypeEnums.新增);
                    #endregion
                    result = db.Insert(info) == 1;
                    //if (result)
                    //{
                    //    _IAppRegPersonUpdate.AppRegPersonSaveOne(new AppRegPersonSaveOne() { adcdid = adcdInfo.Id, username=info.Name, hanphone = info.Mobile });
                    //}
                    return(result);
                }
            }
        }
Exemplo n.º 3
0
 public bool SaveCountryPerson(SaveCountryPerson requset)
 {
     using (var db = DbFactory.Open())
     {
         if (string.IsNullOrEmpty(adcd))
         {
             throw new Exception("请重新登录");
         }
         if (!ValidatorHelper.IsMobile(requset.Mobile))
         {
             throw new Exception("手机号码输入错误,请重新输入");
         }
         var info = new CountryPerson();
         var log  = new operateLog();
         log.userName    = RealName;
         log.operateTime = DateTime.Now;
         if (requset.Id != 0)
         {
             info.Id = requset.Id;
             //log.operateMsg = "更新" + requset.name + "的镇级责任人信息";
         }
         //else
         //{
         //    var model = GetCountryPersonInfo(requset.name);
         //    if (model != null)
         //        throw new Exception("已存在");
         //    //log.operateMsg = "新增" + requset.name + "的镇级责任人信息";
         //}
         info.UserName   = requset.name;
         info.CreateTime = DateTime.Now;
         info.Phone      = requset.Mobile;
         info.Position   = requset.Position;
         info.Post       = requset.Post;
         info.Year       = DateTime.Now.Year;
         info.Remark     = requset.Remark;
         info.Country    = RealName;
         info.UpdateName = requset.name;
         info.UpdateTime = DateTime.Now;
         info.CreateName = requset.name;
         info.adcd       = adcd;
         var oldInfo = db.Single <CountryPerson>(x => x.Id == requset.Id);
         if (requset.Id != 0)
         {
             info.AuditNums = oldInfo.AuditNums + 1;
             info.OldData   = JsonTools.ObjectToJson(oldInfo);
             info.NewData   = JsonTools.ObjectToJson(info);
             #region 日志
             try
             {
                 var           adcdInfo = db.Single <ADCDInfo>(w => w.adcd == oldInfo.adcd);
                 StringBuilder sb       = new StringBuilder();
                 sb.Append("在栏目{组织责任/县级防汛防台责任人}下,更新数据{");
                 sb.Append("县级adcd:" + adcdInfo.adnm + "");
                 sb.Append("姓名:" + oldInfo.UserName + "");
                 sb.Append("创建的时间:" + oldInfo.CreateTime + "");
                 sb.Append("电话:" + oldInfo.Phone + "");
                 sb.Append("岗位:" + oldInfo.Position + "");
                 sb.Append("职务:" + oldInfo.Post + "");
                 sb.Append("年份:" + oldInfo.Year + "");
                 sb.Append("标记:" + oldInfo.Remark + "");
                 sb.Append("县的名字:" + oldInfo.Country + "");
                 sb.Append("更改人的名字:" + oldInfo.UpdateName + "");
                 sb.Append("更改的时间:" + oldInfo.UpdateTime + "");
                 sb.Append("创建的人:" + oldInfo.CreateName + "");
                 sb.Append("}为{");
                 sb.Append("县级adcd:" + adcdInfo.adnm + "");
                 sb.Append("姓名:" + info.UserName + "");
                 sb.Append("创建的时间:" + info.CreateTime + "");
                 sb.Append("电话:" + info.Phone + "");
                 sb.Append("岗位:" + info.Position + "");
                 sb.Append("职务:" + info.Post + "");
                 sb.Append("年份:" + info.Year + "");
                 sb.Append("标记:" + info.Remark + "");
                 sb.Append("县的名字:" + info.Country + "");
                 sb.Append("更改人的名字:" + info.UpdateName + "");
                 sb.Append("更改的时间:" + info.UpdateTime + "");
                 sb.Append("创建的人:" + info.CreateName + "");
                 sb.Append("}");
                 logHelper.WriteLog(sb.ToString(), OperationTypeEnums.更新);
             }catch (Exception ex) { }
             #endregion
             //"select * from CountryPerson where Phone='" + info.Phone + "' and Position='" + info.Position + "' and UserName='******' and "
             var r = db.Single <CountryPerson>(w => w.Phone == requset.Mobile && w.Position == info.Position && w.UserName == info.UserName && w.Remark == info.Remark && w.Post == info.Post);
             if (r != null)
             {
                 return(false);
             }
             else
             {
                 return(db.Update(info) == 1);
             }
         }
         else
         {
             int count;
             var list = db.Select <AuditCounty>("select * from dbo.AuditCounty where CountyADCD='" + adcd + "' ");
             if (list.Count == 0)
             {
                 count = 1;
             }
             else
             {
                 count = Convert.ToInt32(list[0].AuditNums) + 1;
             }
             info.AuditNums = count;
             info.OldData   = "";
             info.NewData   = "";
             #region 日志
             try
             {
                 StringBuilder sb       = new StringBuilder();
                 var           adcdInfo = db.Single <ADCDInfo>(w => w.adcd == info.adcd);
                 sb.Append("在栏目{组织责任/县级防汛防台责任人}下,新增数据{");
                 sb.Append("县级adcd:" + adcdInfo.adnm + "");
                 sb.Append("姓名:" + info.UserName + "");
                 sb.Append("创建的时间:" + info.CreateTime + "");
                 sb.Append("电话:" + info.Phone + "");
                 sb.Append("岗位:" + info.Position + "");
                 sb.Append("职务:" + info.Post + "");
                 sb.Append("年份:" + info.Year + "");
                 sb.Append("标记:" + info.Remark + "");
                 sb.Append("县的名字:" + info.Country + "");
                 sb.Append("更改人的名字:" + info.UpdateName + "");
                 sb.Append("更改的时间:" + info.UpdateTime + "");
                 sb.Append("创建的人:" + info.CreateName + "");
                 sb.Append("}");
                 logHelper.WriteLog(sb.ToString(), OperationTypeEnums.新增);
             }catch (Exception ex)
             {
             }
             #endregion
             if (db.Select <CountryPerson>("select * from CountryPerson where Phone='" + info.Phone + "' and Position='" + info.Position + "' and UserName='******'").ToList().Count == 1)
             {
                 return(false);
             }
             else
             {
                 return(db.Insert(info) == 1);
             }
         }
     }
 }
        public BaseResult UploadWGFiles(NoVerifyUploadWGFiles request)
        {
            BaseResult _br = new BaseResult();

            if (string.IsNullOrEmpty(request.fpath))
            {
                throw new Exception("参数异常!");
            }
            var _year   = null == request.year ? DateTime.Now.Year : request.year;
            var newpath = System.Web.HttpContext.Current.Server.MapPath(request.fpath);

            try
            {
                //导入数据
                // var dt = Logic.Common.ExcelHelper.GetDataTable(newpath);
                Workbook workbook = new Workbook();
                workbook.Open(newpath);
                Cells cells = workbook.Worksheets[0].Cells;
                var   dt    = cells.ExportDataTable(0, 0, cells.MaxDataRow + 1, cells.MaxColumn + 1, true);
                //移出表头
                dt.Rows.RemoveAt(0);
                dt.Rows.RemoveAt(0);
                #region 基础数据集
                //取出岗位
                List <PostViewModel> postList = null;
                using (var dbpost = DbFactory.Open())
                {
                    var builderpost = dbpost.From <Model.Post.Post>();
                    postList = dbpost.Select <PostViewModel>(builderpost);
                }
                //取出adcd
                List <VillageViewModel> adcdList = null;
                using (var dbadcd = DbFactory.Open())
                {
                    var builderadcd = dbadcd.From <ADCDInfo>();
                    if (adcd.Length == 15 && adcd.IndexOf("000000") > 0)//登陆的是乡镇用户
                    {
                        builderadcd.Where <ADCDInfo>(x => x.adcd.StartsWith(adcd.Substring(0, 9)) && x.adcd != adcd.ToString());
                    }
                    else if (adcd.Length == 6 && adcd.IndexOf("00") < 0)//登陆的是县级用户
                    {
                        builderadcd.Where <ADCDInfo>(x => x.adcd.StartsWith(adcd.Substring(0, 6)));
                    }
                    else if (adcd == GrassrootsFloodCtrlEnums.AreaCode.省级编码.ToString())//管理员
                    {
                    }
                    else
                    {
                        throw new Exception("登陆用户的所属行政区划编码不正确");
                    }
                    adcdList = dbadcd.Select <VillageViewModel>(builderadcd);
                }
                //取出责任人
                List <VillageWorkingGroupViewModel> vlist = null;
                using (var db = DbFactory.Open())
                {
                    var builder = db.From <ADCDInfo>();
                    builder.LeftJoin <ADCDInfo, VillageWorkingGroup>((x, y) => x.adcd == y.VillageADCD);
                    if (adcd.Length == 15 && adcd.IndexOf("000000") > 0)//登陆的是乡镇用户
                    {
                        builder.Where <ADCDInfo>(x => x.adcd.StartsWith(adcd.Substring(0, 9)) && x.adcd != adcd.ToString());
                    }
                    else
                    {
                        throw new Exception("登陆用户的所属行政区划编码不正确");
                    }
                    builder.Where <VillageWorkingGroup>(y => y.VillageADCD != null && y.Year == _year);
                    builder.Select(" VillageWorkingGroup.*,ADCDInfo.adnm");
                    vlist = db.Select <VillageWorkingGroupViewModel>(builder);
                }
                #endregion
                #region 校验
                int            i       = 4;
                List <ErrList> _erlist = new List <ErrList>();
                foreach (DataRow dr in dt.Rows)
                {
                    ErrList _el = new ErrList();
                    _el.rowid = i;
                    bool _c = false;
                    //村名匹配
                    var villageName = dr[0].ToString().Trim();
                    if (string.IsNullOrEmpty(villageName))
                    {
                        _c      = false;
                        _el.msg = "第  " + i + "  行村名为空!";
                    }
                    else
                    {
                        var A = adcdList.Where <VillageViewModel>(w => w.adnm == villageName).FirstOrDefault();
                        if (null == A || string.IsNullOrEmpty(A.adcd))
                        {
                            _c      = false;
                            _el.msg = "第 " + i + " 行村名和系统里标注的村名不匹配!新增村名导入前请先标注<br/>";
                        }
                        else
                        {
                            _c = true;
                        }
                    }
                    //岗位匹配
                    var postName = dr[1].ToString().Trim();
                    if (string.IsNullOrEmpty(postName))
                    {
                        _c      = false;
                        _el.msg = "第  " + i + "  行岗位名为空!";
                    }
                    else
                    {
                        var B = postList.Where <PostViewModel>(w => w.PostName == postName).FirstOrDefault();
                        if (null == B || string.IsNullOrEmpty(B.PostName))
                        {
                            _c      = false;
                            _el.msg = "第 " + i + " 行岗位名称和系统里的岗位名称不匹配!新增岗位请先到“岗位管理”栏目设置后,重新下载模板";
                        }
                        else
                        {
                            _c = true;
                        }
                    }
                    //责任人
                    var personName = dr[2].ToString();
                    if (string.IsNullOrEmpty(personName))
                    {
                        _c      = false;
                        _el.msg = "第  " + i + "  行责任人为空!";
                    }
                    else
                    {
                        _c         = true;
                        personName = dr[2].ToString().Trim();
                    }
                    //手机
                    var handphone = dr[4].ToString();
                    if (string.IsNullOrEmpty(handphone))
                    {
                        _el.msg = "第  " + i + "  行责任人联系方式为空!";
                    }
                    else if (!ValidatorHelper.IsMobile(handphone) && !ValidatorHelper.IsTelephone(handphone))
                    {
                        _el.msg = "第  " + i + "  行责任人联系方式格式错误!手机或小灵通(格式:区号'-'号码)";
                    }
                    else
                    {
                    }
                    //同村,同岗,同责任人验证
                    if (_c)
                    {
                        var checkPerson = vlist.Where <VillageWorkingGroupViewModel>(w => w.adnm == villageName && w.Post == postName && w.PersonLiable == personName && w.Year == _year.ToString()).FirstOrDefault();
                        if (null != checkPerson)
                        {
                            _el.msg = "第  " + i + " 行有同村,同岗,同责任人的重复数据!";
                        }
                    }
                    if (!string.IsNullOrEmpty(_el.msg))
                    {
                        _erlist.Add(_el);
                    }
                    i++;
                }
                _br.ErrorList = _erlist;
                if (_br.ErrorList.Count > 0)
                {
                    _br.IsSuccess = false;
                    _br.ErrorMsg  = "数据异常,请查看数据异常提醒!";
                    return(_br);
                }
                #endregion
                #region 取出数据写入实体类
                foreach (DataRow dr in dt.Rows)
                {
                    //实例化责任人对象
                    VillageWorkingGroup item = new VillageWorkingGroup();
                    //获取组code
                    var A = adcdList.Where <VillageViewModel>(w => w.adnm == dr[0].ToString().Trim()).FirstOrDefault();
                    item.VillageADCD = A.adcd;
                    var B = postList.Where <PostViewModel>(w => w.PostName == dr[1].ToString().Trim()).FirstOrDefault();
                    item.Post         = B.PostName;
                    item.PersonLiable = string.IsNullOrEmpty(dr[2].ToString()) ? "" : dr[2].ToString().Trim();
                    item.Position     = string.IsNullOrEmpty(dr[3].ToString()) ? "" : dr[3].ToString().Trim();
                    item.HandPhone    = string.IsNullOrEmpty(dr[4].ToString()) ? "" : dr[4].ToString().Trim();
                    item.Remarks      = string.IsNullOrEmpty(dr[5].ToString()) ? "" : dr[5].ToString().Trim();
                    item.Year         = _year;
                    item.AddTime      = DateTime.Now;
                    #region 单条日志
                    operateLog log = new operateLog();
                    log.userName    = RealName;
                    log.operateTime = DateTime.Now;
                    log.operateMsg  = A.adcd + "村{" + _year + "}导入新增了工作组责任人{" + item.PersonLiable + "}的信息";
                    List <operateLog> listLog = new List <operateLog>();
                    listLog.Add(log);
                    item.operateLog = JsonTools.ObjectToJson(listLog);
                    #endregion
                    if (null != AuditNums && AuditNums.Value > 1)
                    {
                        item.AuditNums = AuditNums.Value + 1;
                    }
                    //写入数据库
                    using (var dbvwg = DbFactory.Open())
                    {
                        var builservwg = dbvwg.From <VillageWorkingGroup>();
                        if (dbvwg.Insert(item) == 1)
                        {
                            _br.IsSuccess = true;
                        }
                        else
                        {
                            throw new Exception("写入失败");
                        }
                    }
                }
                #region 日志
                StringBuilder sb = new StringBuilder();
                sb.Append("在栏目{组织责任/行政村防汛防台工作组}下,导入数据{" + dt.Rows.Count + "}条");
                _ILogHelper.WriteLog(sb.ToString(), OperationTypeEnums.新增);
                #endregion
                _br.IsSuccess = true;
                _br.ErrorMsg  = "";
                #endregion
            }
            catch (Exception ex)
            {
                _br.IsSuccess = false;
                _br.ErrorMsg  = "数据导入异常:" + ex.Message;
                File.Delete(newpath);
            }
            finally
            {
                File.Delete(newpath);
            }
            return(_br);
        }