//


        public CustomJsonResult UploadImage(string fileInputName, string path, string oldFileName)
        {
            ILog log = LogManager.GetLogger(this.GetType());

            log.Info("测试上传服务");
            CustomJsonResult rm = new CustomJsonResult();

            // rm.ContentType = "text/html";
            try
            {
                HttpPostedFileBase file_upload = Request.Files[fileInputName];

                if (file_upload == null)
                {
                    return(Json("text/html", ResultType.Failure, "上传失败"));
                }

                System.IO.FileInfo file = new System.IO.FileInfo(file_upload.FileName);
                if (file.Extension != ".jpg" && file.Extension != ".png" && file.Extension != ".gif" && file.Extension != ".bmp")
                {
                    return(Json("text/html", ResultType.Failure, "上传的文件不是图片格式(jpg,png,gif,bmp)"));
                }


                string strUrl = System.Configuration.ConfigurationManager.AppSettings["custom:ImagesServerUploadUrl"] + "?date=" + DateTime.Now.ToString("yyyyMMddhhmmssfff");


                byte[] bytes = null;
                using (var binaryReader = new BinaryReader(file_upload.InputStream))
                {
                    bytes = binaryReader.ReadBytes(file_upload.ContentLength);
                }
                string           fileExt = Path.GetExtension(file_upload.FileName).ToLower();
                UploadFileEntity entity  = new UploadFileEntity();
                entity.FileName     = DateTime.Now.ToString("yyyyMMddhhmmssfff") + fileExt;//自定义文件名称,这里以当前时间为例
                entity.FileData     = bytes;
                entity.UploadFolder = path;
                rm = HttpClientOperate.Post <CustomJsonResult>(path, strUrl, entity);//封装的POST提交方
                //rm.ContentType = "text/html";
                if (rm.Result == ResultType.Exception || rm.Result == ResultType.Unknown)
                {
                    rm.Message = "上传图片发生异常";
                }
            }
            catch (Exception ex)
            {
                log.Error("上传图片发生异常", ex);
                rm.Result  = ResultType.Exception;
                rm.Message = "上传图片发生异常";

                throw (ex);
            }
            return(rm);
        }
        public ActionResult CkEditorUpLoadFile()
        {
            Log.Info("调用上传图片接口(CkEditorUpLoadFile)");
            string CKEditorFuncNum = Request.QueryString["CKEditorFuncNum"];

            try
            {
                HttpPostedFileBase file_upload   = Request.Files["upload"];
                string             type          = Request.QueryString["type"].ToString();
                string             fileName      = file_upload.FileName;
                string             fileExtension = System.IO.Path.GetExtension(fileName).ToLower();
                StringBuilder      sb            = new StringBuilder();
                if (fileExtension != ".jpg" && fileExtension != ".gif" && fileExtension != ".png" && fileExtension != ".bmp")
                {
                    return(Content(CkEditorUpLoadCallFunction(CKEditorFuncNum, "上传的文件格式不正确,请重新选择!")));
                }

                string strUrl = System.Configuration.ConfigurationManager.AppSettings["custom:UploadServerUrl"];

                Log.Info("调用上传图片接口" + strUrl);

                byte[] bytes = null;
                using (var binaryReader = new BinaryReader(Request.Files[0].InputStream))
                {
                    bytes = binaryReader.ReadBytes(Request.Files[0].ContentLength);
                }
                string           fileExt = Path.GetExtension(Request.Files[0].FileName).ToLower();
                UploadFileEntity entity  = new UploadFileEntity();
                entity.FileName     = DateTime.Now.ToString("yyyyMMddHHmmss") + fileExt;//自定义文件名称,这里以当前时间为例
                entity.FileData     = bytes;
                entity.UploadFolder = "CkEditorFile";
                entity.GenerateSize = false;

                CustomJsonResult rm = HttpClientOperate.Post <CustomJsonResult>("", strUrl, entity);//封装的POST提交方
                if (rm.Result == ResultType.Exception || rm.Result == ResultType.Unknown)
                {
                    rm.Message = "上传图片发生异常";
                    Log.Error("调用api上传图片失败");

                    return(Content(CkEditorUpLoadCallFunction(CKEditorFuncNum, "远程上传图片发生异常")));
                }

                ImageUpload imageUpload = Newtonsoft.Json.JsonConvert.DeserializeObject <ImageUpload>(rm.Data.ToString());

                return(Content(CkEditorUpLoadCallFunction(CKEditorFuncNum, "", imageUpload.OriginalPath)));
            }
            catch (Exception ex)
            {
                Log.Error("调用上传图片接口(CkEditorUpLoadFile)", ex);
                return(Content(CkEditorUpLoadCallFunction(CKEditorFuncNum, ex.Message)));
            }
        }
        public string GetUploadImageUrl(ImageModel imagemodel, string savepath)
        {
            ILog log = LogManager.GetLogger(this.GetType());

            if (imagemodel == null)
            {
                return(null);
            }

            if (string.IsNullOrEmpty(imagemodel.Data))
            {
                return(null);
            }

            string fileExt  = imagemodel.Type;
            string basedata = imagemodel.Data;


            string imageUrl = "";

            try
            {
                string strUrl = System.Configuration.ConfigurationManager.AppSettings["custom:UploadServerUrl"];


                byte[] bytes = Convert.FromBase64String(basedata);

                UploadFileEntity entity = new UploadFileEntity();
                entity.FileName     = DateTime.Now.ToString("yyyyMMddHHmmss") + fileExt;//自定义文件名称,这里以当前时间为例
                entity.FileData     = bytes;
                entity.UploadFolder = savepath;
                CustomJsonResult rm = HttpClientOperate.Post <CustomJsonResult>(savepath, strUrl, entity);//封装的POST提交方

                if (rm.Result == ResultType.Success)
                {
                    ImageUpload imageUpload = Newtonsoft.Json.JsonConvert.DeserializeObject <ImageUpload>(rm.Data.ToString());

                    imageUrl = imageUpload.OriginalPath;
                }
                else
                {
                    rm.Message = "上传图片发生异常";
                    log.Error("调用API上传图片发生异常");
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
            return(imageUrl);
        }
        public JsonResult UploadImage(string fileinputname, string path, string oldfilename, bool generateSize)
        {
            CustomJsonResult rm = new CustomJsonResult();

            rm.ContentType = "text/html";
            try
            {
                Log.Info("调用上传图片接口");

                HttpPostedFileBase file_upload = Request.Files[fileinputname];

                if (file_upload == null)
                {
                    return(Json("text/html", ResultType.Failure, "找不到上传的对象"));
                }

                if (file_upload.ContentLength == 0)
                {
                    return(Json("text/html", ResultType.Failure, "文件内容为空,请重新选择"));
                }

                if (file_upload.ContentLength > (10 * 1024 * 1024))
                {
                    return(Json("text/html", ResultType.Failure, "图片大小不能超过10M,请重新选择"));
                }


                System.IO.FileInfo file = new System.IO.FileInfo(file_upload.FileName);
                string             ext  = file.Extension.ToLower();
                if (ext != ".jpg" && ext != ".jpeg" && ext != ".png" && ext != ".gif" && ext != ".bmp")
                {
                    return(Json("text/html", ResultType.Failure, "上传的文件不是图片格式(jpg,png,gif,bmp)"));
                }


                string strUrl = System.Configuration.ConfigurationManager.AppSettings["custom:UploadServerUrl"];
                Log.Info("调用上传图片接口" + strUrl);

                byte[] bytes = null;
                using (var binaryReader = new BinaryReader(Request.Files[0].InputStream))
                {
                    bytes = binaryReader.ReadBytes(Request.Files[0].ContentLength);
                }
                string           fileExt = Path.GetExtension(Request.Files[0].FileName).ToLower();
                UploadFileEntity entity  = new UploadFileEntity();
                entity.FileName     = DateTime.Now.ToString("yyyyMMddHHmmss") + fileExt;//自定义文件名称,这里以当前时间为例
                entity.FileData     = bytes;
                entity.UploadFolder = path;
                entity.GenerateSize = generateSize;
                rm             = HttpClientOperate.Post <CustomJsonResult>(path, strUrl, entity);//封装的POST提交方
                rm.ContentType = "text/html";
                if (rm.Result == ResultType.Exception || rm.Result == ResultType.Unknown)
                {
                    rm.Message = "上传图片发生异常.";
                    Log.Error("调用api上传图片失败");
                }
            }
            catch (Exception ex)
            {
                rm.Result  = ResultType.Exception;
                rm.Message = "上传图片发生异常..";
                Log.Error(ex);
            }
            return(rm);
        }
        public static CustomJsonResult GetCarInsOffer(OrderToCarInsure order, List <OrderToCarInsureOfferCompany> offerCompany, List <OrderToCarInsureOfferKind> kinds)
        {
            CustomJsonResult result = new CustomJsonResult();

            List <YdtInscarInquiryOffer> offerList = new List <YdtInscarInquiryOffer>();

            order.RecipientAddress     = "测试地址";
            order.RecipientPhoneNumber = "13800138000";


            var    au     = YdtUtils.GetToken();
            YdtApi ydtApi = new YdtApi();

            InscarAddbaseModel model = new InscarAddbaseModel();

            model.auto = 1;

            //todo 新车怎么标识
            switch (order.CarVechicheType)
            {
            case Enumeration.CarVechicheType.HC:
                model.carType = 3;
                break;

            default:
                model.carType = 1;
                break;
            }


            switch (order.CarUserCharacter)
            {
            case Enumeration.CarUserCharacter.JTZYQC:
                model.belong = 1;
                break;

            default:
                model.belong = 2;
                break;
            }

            #region 车辆信息
            InsCarInfoModel carInfo = new InsCarInfoModel();
            carInfo.licensePlateNo    = order.CarPlateNo;
            carInfo.vin               = order.CarVin;
            carInfo.engineNo          = order.CarEngineNo;
            carInfo.modelCode         = order.CarModel;
            carInfo.modelName         = order.CarModelName;
            carInfo.firstRegisterDate = order.CarRegisterDate;
            // carInfo.displacement = ;
            // carInfo.marketYear = ;

            //switch (order.CarSeat)
            //{
            //    case Enumeration.CarSeat.S6:
            carInfo.ratedPassengerCapacity = order.CarSeat;
            //        break;
            //    case Enumeration.CarSeat.S10:
            //        carInfo.ratedPassengerCapacity = 10;
            //        break;
            //    case Enumeration.CarSeat.S12:
            //        carInfo.ratedPassengerCapacity = 12;
            //        break;
            //    case Enumeration.CarSeat.S30:
            //        carInfo.ratedPassengerCapacity = 30;
            //        break;
            //    case Enumeration.CarSeat.S36:
            //        carInfo.ratedPassengerCapacity = 36;
            //        break;
            //    default:
            //        carInfo.ratedPassengerCapacity = 9;
            //        break;
            //}

            carInfo.ratedPassengerCapacity = order.CarSeat;
            carInfo.replacementValue       = order.CarPurchasePrice.Value;
            carInfo.licensePlateNo         = order.CarPlateNo;

            //todo
            carInfo.replacementValue = 0;
            carInfo.chgownerType     = "0";



            model.car = carInfo;

            #endregion



            #region 被保人,投保人,车主
            List <InsCustomers> customers = new List <InsCustomers>();

            InsCustomers insured = new InsCustomers();
            insured.insuredFlag = 1;
            insured.name        = order.CarOwner;
            insured.certNo      = order.CarOwnerIdNumber;
            insured.mobile      = order.RecipientPhoneNumber;
            insured.address     = order.RecipientAddress;

            YdtUpload ydtUpdate_SFZ       = new YdtUpload(au.token, au.session, "1", order.CZ_SFZ_ImgUrl);
            var       ydtUpdateResult_SFZ = ydtApi.DoPostFile(ydtUpdate_SFZ, Path.GetFileName(order.CZ_SFZ_ImgUrl));

            if (ydtUpdateResult_SFZ.code != 0)
            {
                return(new CustomJsonResult(ResultType.Failure, ydtUpdateResult_SFZ.msg));
            }

            insured.identityFacePic = ydtUpdateResult_SFZ.data.file.key;
            insured.identityBackPic = ydtUpdateResult_SFZ.data.file.key;

            InsCustomers holder = new InsCustomers();
            holder.insuredFlag     = 2;
            holder.name            = insured.name;
            holder.certNo          = insured.certNo;
            holder.mobile          = insured.mobile;
            holder.address         = insured.address;
            holder.identityFacePic = insured.identityFacePic;
            holder.identityBackPic = insured.identityBackPic;

            InsCustomers carOwner = new InsCustomers();
            carOwner.insuredFlag     = 3;
            carOwner.name            = insured.name;
            carOwner.certNo          = insured.certNo;
            carOwner.mobile          = insured.mobile;
            carOwner.address         = insured.address;
            carOwner.identityFacePic = insured.identityFacePic;
            carOwner.identityBackPic = insured.identityBackPic;


            customers.Add(insured);
            customers.Add(holder);
            customers.Add(carOwner);
            #endregion


            model.customers = customers;


            var ydtUpdate       = new YdtUpload(au.token, au.session, "1", order.CZ_SFZ_ImgUrl);
            var ydtUpdateResult = ydtApi.DoPostFile(ydtUpdate, Path.GetFileName(order.CZ_SFZ_ImgUrl));
            if (ydtUpdateResult.code != 0)
            {
                return(new CustomJsonResult(ResultType.Failure, ydtUpdateResult.msg));
            }

            #region pic
            InsPicModel insPic = new InsPicModel();
            insPic.licensePic      = ydtUpdateResult.data.file.key;
            insPic.licenseOtherPic = "";
            insPic.carCertPic      = "";
            insPic.carInvoicePic   = "";

            model.pic = insPic;
            #endregion



            YdtInscarAddbase ydtInscarAddbase = new YdtInscarAddbase(au.token, au.session, YdtPostDataType.Json, model);
            var ydtInscarCarResult            = ydtApi.DoPost(ydtInscarAddbase);

            if (ydtInscarCarResult.code != 0)
            {
                return(new CustomJsonResult(ResultType.Failure, ydtInscarCarResult.msg));
            }

            var insCarAdvicevalueModel = new InsCarAdvicevalueModel();
            insCarAdvicevalueModel.startDate        = order.PeriodStart.Value.ToString("yyyy-MM-dd");
            insCarAdvicevalueModel.registDate       = order.CarRegisterDate;
            insCarAdvicevalueModel.replacementValue = order.CarPurchasePrice.Value;
            var ydtInscarAdvicevalue       = new YdtInscarAdvicevalue(au.token, au.session, YdtPostDataType.Json, insCarAdvicevalueModel);
            var ydtInscarAdvicevalueResult = ydtApi.DoPost(ydtInscarAdvicevalue);

            if (ydtInscarAdvicevalueResult.code != 0)
            {
                return(new CustomJsonResult(ResultType.Failure, ydtInscarAdvicevalueResult.msg));
            }

            InsCarInquiryModel insCarInquiryModel = new InsCarInquiryModel();
            insCarInquiryModel.auto     = 1;
            insCarInquiryModel.orderSeq = ydtInscarCarResult.data.orderSeq;
            insCarInquiryModel.risk     = YdtDataMap.GetRisk(kinds);

            if (insCarInquiryModel.risk == 2 || insCarInquiryModel.risk == 3)
            {
                insCarInquiryModel.ciStartDate = order.PeriodStart.Value.ToString("yyyy-MM-dd");
            }

            if (insCarInquiryModel.risk == 1 || insCarInquiryModel.risk == 3)
            {
                insCarInquiryModel.biStartDate = order.PeriodStart.Value.ToString("yyyy-MM-dd");
            }


            insCarInquiryModel.coverages = YdtDataMap.GetCoverages(kinds, ydtInscarAdvicevalueResult.data.actualPrice, order.CarSeat);



            foreach (var company in offerCompany)
            {
                var insCompany = YdtDataMap.GetCompanyCode(company.InsuranceCompanyId);
                insCarInquiryModel.companyCode = insCompany.YdtCode;//"006000";
                YdtInscarInquiry ydtInscarInquiry = new YdtInscarInquiry(au.token, au.session, YdtPostDataType.Json, insCarInquiryModel);
                var ydtInscarInquiryResult        = ydtApi.DoPost(ydtInscarInquiry);

                YdtInscarInquiryOffer offer = new YdtInscarInquiryOffer();



                offer.UplinkInsCompanyId = company.InsuranceCompanyId;
                offer.YdtInsCompanyId    = insCarInquiryModel.companyCode;
                offer.Inquiry            = ydtInscarInquiryResult;

                if (ydtInscarInquiryResult.code == 0)
                {
                    OfferImgModel offerImgModel = new OfferImgModel();
                    offerImgModel.Company   = insCompany.PrintName;
                    offerImgModel.OfferTime = DateTime.Now;
                    offerImgModel.Offerer   = "";

                    OfferImgCarInfo offerImgCarInfo = new OfferImgCarInfo();
                    offerImgCarInfo.CarOwner     = order.CarOwner;
                    offerImgCarInfo.CarPlateNo   = order.CarPlateNo;
                    offerImgCarInfo.CarEngineNo  = order.CarEngineNo;
                    offerImgCarInfo.CarVin       = order.CarVin;
                    offerImgCarInfo.CarModelName = order.CarModelName;

                    offerImgModel.CarInfo = offerImgCarInfo;

                    string postData = "";
                    if (offer.Inquiry != null)
                    {
                        if (offer.Inquiry.data != null)
                        {
                            if (offer.Inquiry.data.coverages != null)
                            {
                                var coverages = offer.Inquiry.data.coverages;
                                foreach (var coverage in coverages)
                                {
                                    OfferImgCoverage offerImgCoverage = new OfferImgCoverage();
                                    offerImgCoverage.Name     = coverage.name;
                                    offerImgCoverage.Discount = coverage.discount;
                                    offerImgCoverage.Premium  = coverage.standardPremium;

                                    if (coverage.code == "006")
                                    {
                                        if (coverage.glassType != null)
                                        {
                                            if (coverage.glassType.Value == 1)
                                            {
                                                offerImgCoverage.Coverage = "国产";
                                            }
                                            else
                                            {
                                                offerImgCoverage.Coverage = "进口";
                                            }
                                        }
                                    }
                                    else if (coverage.name.IndexOf("不计免赔") > -1)
                                    {
                                        offerImgCoverage.Coverage = "";
                                    }
                                    else
                                    {
                                        if (coverage.amount != null)
                                        {
                                            offerImgCoverage.Coverage = coverage.amount.Value.ToF2Price();
                                        }
                                    }

                                    offerImgModel.CommercialCoverageInfo.Coverages.Add(offerImgCoverage);
                                }
                                offerImgModel.CommercialCoverageInfo.PeriodStart = order.PeriodStart;
                                offerImgModel.CommercialCoverageInfo.PeriodEnd   = order.PeriodEnd;
                            }

                            if (offer.Inquiry.data.inquirys != null)
                            {
                                var commercial = offer.Inquiry.data.inquirys.Where(m => m.risk == 1).FirstOrDefault();
                                if (commercial != null)
                                {
                                    offerImgModel.CommercialCoverageInfo.SumPremium = commercial.standardPremium;
                                }

                                var compulsory = offer.Inquiry.data.inquirys.Where(m => m.risk == 2).FirstOrDefault();

                                if (compulsory != null)
                                {
                                    offerImgModel.CompulsoryInfo.PeriodStart = order.PeriodStart;
                                    offerImgModel.CompulsoryInfo.PeriodEnd   = order.PeriodEnd;
                                    offerImgModel.CompulsoryInfo.Premium     = compulsory.standardPremium - compulsory.sumPayTax;
                                    offerImgModel.TravelTax = compulsory.sumPayTax;
                                }
                            }

                            offerImgModel.SumPremium = offer.Inquiry.data.inquirys.Sum(m => m.standardPremium);
                        }
                    }

                    postData = Newtonsoft.Json.JsonConvert.SerializeObject(offerImgModel);

                    int height = 840;
                    if (offer.Inquiry.data.coverages != null)
                    {
                        if (offer.Inquiry.data.coverages.Count > 5)
                        {
                            height = height + (offer.Inquiry.data.coverages.Count - 5) * 40;
                        }
                    }



                    Bitmap m_Bitmap = WebSnapshotsHelper.GetWebSiteThumbnail("http://localhost:12060/App/CarInsureOffer/OfferImg", 1280, height, 1280, height, postData); //宽高根据要获取快照的网页决定

                    byte[] bytes = Bitmap2Byte(m_Bitmap);

                    string           fileExt = ".jpg";
                    UploadFileEntity entity  = new UploadFileEntity();
                    entity.FileName     = DateTime.Now.ToString("yyyyMMddHHmmss") + fileExt;//自定义文件名称,这里以当前时间为例
                    entity.FileData     = bytes;
                    entity.UploadFolder = "offerImg";
                    entity.GenerateSize = false;
                    var rm = HttpClientOperate.Post <CustomJsonResult>(entity.UploadFolder, ConfigurationManager.AppSettings["custom:UploadServerUrl"], entity);//封装的POST提交方
                    if (rm.Result == ResultType.Success)
                    {
                        ImageUpload imageUpload = Newtonsoft.Json.JsonConvert.DeserializeObject <ImageUpload>(rm.Data.ToString());
                        offer.OfferImgUrl = imageUpload.OriginalPath;
                    }
                }


                offerList.Add(offer);
            }

            result.Result = ResultType.Success;
            result.Code   = ResultCode.Success;
            result.Data   = offerList;

            return(result);
        }