示例#1
0
        public JsonResult GetList(string queryJson)
        {
            var result = new ReturnMessage(false)
            {
                Message = "加载列表失败!"
            };

            try
            {
                int type = 1;
                InsuranceCommpayEntity para = new InsuranceCommpayEntity();
                if (!string.IsNullOrWhiteSpace(queryJson))
                {
                    var queryParam = queryJson.ToJObject();
                    if (!queryParam["lat"].IsEmpty())
                    {
                        para.Lat = decimal.Parse(queryParam["lat"].ToString());
                    }
                    if (!queryParam["lng"].IsEmpty())
                    {
                        para.Lng = decimal.Parse(queryParam["lng"].ToString());
                    }
                    if (!queryParam["type"].IsEmpty())
                    {
                        type = int.Parse(queryParam["type"].ToString());
                    }
                }
                para.Status = (int)Model.Enums.UseStatus.启用;

                var pageList = InsuranceCommpayBLL.Instance.GetList(para).OrderBy(o => o.SortNum).ToList();
                if (pageList != null)
                {
                    pageList.ForEach((page) =>
                    {
                        if (page.FaceImage != null)
                        {
                            var imageHost  = System.Configuration.ConfigurationManager.AppSettings["ImageHost"] == "" ? string.Format("http://{0}{1}", Request.Url.Host, Request.Url.Port == 80 ? "" : ":" + Request.Url.Port) : System.Configuration.ConfigurationManager.AppSettings["ImageHost"];
                            page.FaceImage = imageHost + page.FaceImage;
                        }
                        if (page.ProvinceId != null)
                        {
                            page.ProvinceName = AreaBLL.Instance.GetEntity(page.ProvinceId).AreaName;
                        }
                        if (page.CityId != null)
                        {
                            page.CityName = AreaBLL.Instance.GetEntity(page.CityId).AreaName;
                        }
                        if (page.CountyId != null)
                        {
                            page.CountyName = AreaBLL.Instance.GetEntity(page.CountyId).AreaName;
                        }
                        page.AddressInfo = page.ProvinceName + page.CityName + page.CountyName + page.AddressInfo;

                        if (page.Lat != null && page.Lng != null && para.Lat != null && para.Lng != null)
                        {
                            page.HowLong = HarvenSin.GetDistance(
                                new Point2D()
                            {
                                Lng = (double)para.Lng,
                                Lat = (double)para.Lat
                            },
                                new Point2D()
                            {
                                Lng = (double)page.Lng,
                                Lat = (double)page.Lat
                            }).ToString("f2");
                        }
                        else
                        {
                            page.HowLong = "未知";
                        }
                    });
                }
                switch (type)
                {
                case 1:    //按距离
                    pageList = pageList.OrderBy(i => i.HowLong).ThenBy(i => i.HowLong).ToList();
                    break;

                case 2:    //按默认排序
                    pageList = pageList.OrderBy(i => i.CreateTime).ThenBy(i => i.CreateTime).ToList();
                    break;
                }
                result.IsSuccess          = true;
                result.Message            = "加载列表成功!";
                result.ResultData["List"] = pageList;
            }
            catch (Exception ex)
            {
                ex.Data["Method"] = "VsInsuranceController>>List";
                new ExceptionHelper().LogException(ex);
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// 导出EXCEL
        /// </summary>
        public void ExportExcel(string queryJson)
        {
            string cacheKey = Request["cacheid"] as string;

            HttpRuntime.Cache[cacheKey + "-state"] = "processing";
            HttpRuntime.Cache[cacheKey + "-row"]   = "0";
            try
            {
                //这里要url解码
                var queryParam = Server.UrlDecode(queryJson).ToJObject();
                InsuranceCommpayEntity para = new InsuranceCommpayEntity();
                //类型
                if (!queryParam["condition"].IsEmpty() && !queryParam["keyword"].IsEmpty())
                {
                    //类型
                    if (!queryParam["condition"].IsEmpty() && !queryParam["keyword"].IsEmpty())
                    {
                        var condition = queryParam["condition"].ToString().ToLower();
                        switch (condition)
                        {
                        case "name":
                            para.Name = queryParam["keyword"].ToString();
                            break;

                        case "conecttel":
                            para.ConectTel = queryParam["keyword"].ToString();
                            break;

                        case "addressinfo":
                            para.AddressInfo = queryParam["keyword"].ToString();
                            break;
                        }
                    }
                }

                var list = InsuranceCommpayBLL.Instance.GetList(para);
                if (list != null)
                {
                    list.ForEach((o) =>
                    {
                        if (o.ProvinceId != null)
                        {
                            o.ProvinceName = AreaBLL.Instance.GetEntity(o.ProvinceId).AreaName;
                        }
                        if (o.CityId != null)
                        {
                            o.CityName = AreaBLL.Instance.GetEntity(o.CityId).AreaName;
                        }
                        if (o.CountyId != null)
                        {
                            o.CountyName = AreaBLL.Instance.GetEntity(o.CountyId).AreaName;
                        }
                        o.AddressInfo = o.ProvinceName + o.CityName + o.CountyName + o.AddressInfo;

                        o.WeekInsuranceOrderCount = InsuranceOrderBLL.Instance.GetList(new InsuranceOrderEntity()
                        {
                            InsuranceId = o.InsuranceCommpayId,
                            StartTime   = Util.Time.CalculateFirstDateOfWeek(DateTime.Now).ToString(),
                            EndTime     = Util.Time.CalculateLastDateOfWeek(DateTime.Now).ToString()
                        }).Count();

                        o.TotalInsuranceOrderCount = InsuranceOrderBLL.Instance.GetList(new InsuranceOrderEntity()
                        {
                            InsuranceId = o.InsuranceCommpayId
                        }).Count();
                        if (o.Status != null)
                        {
                            o.StatusName = ((RCHL.Model.Enums.UseStatus)o.Status).ToString();
                        }
                    });

                    //设置导出格式
                    ExcelConfig excelconfig = new ExcelConfig();
                    excelconfig.Title           = "保险公司信息";
                    excelconfig.TitleFont       = "微软雅黑";
                    excelconfig.TitlePoint      = 10;
                    excelconfig.FileName        = "保险公司信息.xls";
                    excelconfig.IsAllSizeColumn = true;
                    //每一列的设置,没有设置的列信息,系统将按datatable中的列名导出
                    List <ColumnEntity> listColumnEntity = new List <ColumnEntity>();
                    excelconfig.ColumnEntity = listColumnEntity;
                    ColumnEntity columnentity = new ColumnEntity();
                    excelconfig.ColumnEntity.Add(new ColumnEntity()
                    {
                        Column = "Name", ExcelColumn = "公司名称", Width = 20
                    });
                    excelconfig.ColumnEntity.Add(new ColumnEntity()
                    {
                        Column = "AddressInfo", ExcelColumn = "地址", Width = 20
                    });
                    excelconfig.ColumnEntity.Add(new ColumnEntity()
                    {
                        Column = "ConectName", ExcelColumn = "联系人", Width = 15
                    });
                    excelconfig.ColumnEntity.Add(new ColumnEntity()
                    {
                        Column = "ConectTel", ExcelColumn = "联系电话", Width = 15
                    });
                    excelconfig.ColumnEntity.Add(new ColumnEntity()
                    {
                        Column = "WeekInsuranceOrderCount", ExcelColumn = "本周预约订单数", Width = 15
                    });
                    excelconfig.ColumnEntity.Add(new ColumnEntity()
                    {
                        Column = "TotalInsuranceOrderCount", ExcelColumn = "总预约订单数", Width = 15
                    });
                    excelconfig.ColumnEntity.Add(new ColumnEntity()
                    {
                        Column = "StatusName", ExcelColumn = "状态", Width = 15
                    });
                    //需合并索引
                    //excelconfig.MergeRangeIndexArr = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 };

                    //调用导出方法
                    ExcelHelper <InsuranceCommpayEntity> .ExcelDownload(list, excelconfig);

                    HttpRuntime.Cache[cacheKey + "-state"] = "done";
                }
            }
            catch (Exception)
            {
                HttpRuntime.Cache[cacheKey + "-state"] = "error";
            }
        }
        public ActionResult GetPageListJson(Pagination pagination, string queryJson)
        {
            var watch = CommonHelper.TimerStart();
            InsuranceCommpayEntity para = new InsuranceCommpayEntity();

            if (!string.IsNullOrWhiteSpace(queryJson))
            {
                var queryParam = queryJson.ToJObject();

                //类型
                if (!queryParam["condition"].IsEmpty() && !queryParam["keyword"].IsEmpty())
                {
                    var condition = queryParam["condition"].ToString().ToLower();
                    switch (condition)
                    {
                    case "name":
                        para.Name = queryParam["keyword"].ToString();
                        break;

                    case "conecttel":
                        para.ConectTel = queryParam["keyword"].ToString();
                        break;

                    case "addressinfo":
                        para.AddressInfo = queryParam["keyword"].ToString();
                        break;
                    }
                }
            }

            var pageList = InsuranceCommpayBLL.Instance.GetPageList(para, ref pagination);

            if (pageList != null)
            {
                pageList.ForEach((o) =>
                {
                    if (o.ProvinceId != null)
                    {
                        o.ProvinceName = AreaBLL.Instance.GetEntity(o.ProvinceId).AreaName;
                    }
                    if (o.CityId != null)
                    {
                        o.CityName = AreaBLL.Instance.GetEntity(o.CityId).AreaName;
                    }
                    if (o.CountyId != null)
                    {
                        o.CountyName = AreaBLL.Instance.GetEntity(o.CountyId).AreaName;
                    }
                    o.AddressInfo = o.ProvinceName + o.CityName + o.CountyName + o.AddressInfo;

                    o.WeekInsuranceOrderCount = InsuranceOrderBLL.Instance.GetList(new InsuranceOrderEntity()
                    {
                        InsuranceId = o.InsuranceCommpayId,
                        StartTime   = Util.Time.CalculateFirstDateOfWeek(DateTime.Now).ToString(),
                        EndTime     = Util.Time.CalculateLastDateOfWeek(DateTime.Now).ToString()
                    }).Count();

                    o.TotalInsuranceOrderCount = InsuranceOrderBLL.Instance.GetList(new InsuranceOrderEntity()
                    {
                        InsuranceId = o.InsuranceCommpayId
                    }).Count();
                });
            }
            var JsonData = new
            {
                rows     = pageList,
                total    = pagination.total,
                page     = pagination.page,
                records  = pagination.records,
                costtime = CommonHelper.TimerEnd(watch)
            };

            return(Content(JsonData.ToJson()));
        }
        public ActionResult SaveForm(string keyValue, InsuranceCommpayEntity entity)
        {
            try
            {
                var result = new ReturnMessage(false)
                {
                    Message = "编辑失败!"
                };
                if (string.IsNullOrWhiteSpace(entity.Name))
                {
                    result.Message = "名称不能为空";
                    return(Json(result));
                }
                if (keyValue == "")
                {
                    entity.InsuranceCommpayId = Util.Util.NewUpperGuid();
                    entity.CreateTime         = DateTime.Now;
                    entity.CreateId           = LoginUser.UserId;
                    entity.Content            = entity.Content == null ? "" : entity.Content.Replace("&amp;", "&").Replace("&gt;", ">").Replace("&lt;", "<");
                    InsuranceCommpayBLL.Instance.Add(entity);
                    if (entity.ImageListStr != null)
                    {
                        //删除
                        AttachmentPicBLL.Instance.DeleteByObjectId(entity.InsuranceCommpayId);
                        //插入
                        var imags = JsonConvert.DeserializeObject <List <string> >(entity.ImageListStr);
                        int index = 0;
                        foreach (string item in imags)
                        {
                            if (item != "")
                            {
                                AttachmentPicEntity pic = new AttachmentPicEntity();
                                pic.PicId    = Util.Util.NewUpperGuid();
                                pic.PicName  = item;
                                pic.SortNum  = index;
                                pic.ObjectId = entity.InsuranceCommpayId;
                                pic.Type     = (int)RCHL.Model.Enums.AttachmentPicType.保险机构;
                                AttachmentPicBLL.Instance.Add(pic);
                            }
                            index++;
                        }
                    }
                }
                else
                {
                    entity.InsuranceCommpayId = keyValue;
                    entity.Content            = entity.Content == null ? "" : entity.Content.Replace("&amp;", "&").Replace("&gt;", ">").Replace("&lt;", "<");
                    InsuranceCommpayBLL.Instance.Update(entity);
                    if (entity.ImageListStr != null)
                    {
                        //删除
                        AttachmentPicBLL.Instance.DeleteByObjectId(entity.InsuranceCommpayId);
                        //插入
                        var imags = JsonConvert.DeserializeObject <List <string> >(entity.ImageListStr);
                        int index = 0;
                        foreach (string item in imags)
                        {
                            if (item != "")
                            {
                                AttachmentPicEntity pic = new AttachmentPicEntity();
                                pic.PicId    = Util.Util.NewUpperGuid();
                                pic.PicName  = item;
                                pic.SortNum  = index;
                                pic.ObjectId = entity.InsuranceCommpayId;
                                pic.Type     = (int)RCHL.Model.Enums.AttachmentPicType.保险机构;
                                AttachmentPicBLL.Instance.Add(pic);
                            }
                            index++;
                        }
                    }
                }

                return(Success("保存成功"));
            }
            catch (Exception ex)
            {
                ex.Data["Method"] = "InsuranceCommpayController>>SaveForm";
                new ExceptionHelper().LogException(ex);
                return(Error("保存失败"));
            }
        }