/// <summary>
        /// 取得特巡点检详细信息
        /// </summary>
        /// <param name="source"></param>
        /// <param name="header"></param>
        /// <returns></returns>
        private static List <PatrolReportDetail> getDetailList(ReqUploadPatrolInformation source, PatrolReportHeader header, String dirName)
        {
            List <PatrolReportDetail> list = new List <PatrolReportDetail>();

            if (source != null && source.check_list != null && source.check_list.Count > 0 && header != null)
            {
                for (int i = 0; i < source.check_list.Count; i++)
                {
                    PicInfo            item     = source.check_list[i];
                    PatrolReportDetail instance = new PatrolReportDetail();
                    //前端获取
                    instance.IsImportant   = item.is_important;
                    instance.LocationCode  = item.location_code;
                    instance.SpotCode      = item.spot_code;
                    instance.Status        = item.spot_status_code;
                    instance.Remarks       = item.part_remarks;
                    instance.QuestionLevel = item.level_code;
                    instance.PicUrl        = dirName + "/" + item.pic_url;
                    Console.WriteLine(instance.PicUrl);
                    //自动设置
                    instance.PatrolNO   = header.PatrolNO;
                    instance.SubNO      = i;
                    instance.IsSelected = "0";

                    //加入列表
                    list.Add(instance);
                }
            }
            return(list);
        }
        /// <summary>
        /// 取得特巡报告头部数据
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        private static PatrolReportHeader getHeader(ReqUploadPatrolInformation source)
        {
            PatrolReportHeader ret = new PatrolReportHeader();

            //前端获取
            ret.Province       = source.province;
            ret.City           = source.city;
            ret.Address        = source.address;
            ret.Contaction1    = source.phone_number1;
            ret.Contaction2    = source.phone_number2;
            ret.ContactorName1 = source.contactor_name1;
            ret.ContactorName2 = source.contactor_name2;
            ret.ContactorType1 = source.contact_type_code1;
            ret.ContactorType2 = source.contact_type_code2;
            ret.ContactType1   = source.phone_type_code1;
            ret.ContactType2   = source.phone_type_code2;

            DateTime date = DateTime.Now;

            ret.Creator       = source.user_id;
            ret.IsEmergency   = source.is_urgent;
            ret.MachineNO     = source.model_id;
            ret.MachineStatus = source.model_status_code;
            ret.MachineType   = source.model_code;
            ret.Remarks       = source.remarks;
            ret.Reporter      = source.user_id;
            ret.ReportUri     = "";
            ret.WorkedTimes   = Convert.ToDouble(source.worked_times);

            //自动设置
            ret.PatrolNO     = PatrolReportHeaderRule.GenerateNO();
            ret.IsAvailable  = "1";
            ret.MakerCD      = "01";
            ret.ReportStatus = "0";
            ret.ReportDate   = date.ToString("yyyyMMdd");
            ret.CreatedAt    = date;

            return(ret);
        }
        /// <summary>
        /// 上传特巡报告
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public Stream UploadPatrolInformation(Stream data)
        {
            #region 查找数据
            ResUploadPatrolInformation response = new ResUploadPatrolInformation();
            bool success = false;
            try
            {
                DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(ReqUploadPatrolInformation));
                //读取器
                StreamReader sr         = new StreamReader(data);
                string       dataString = String.Empty;
                while (!sr.EndOfStream)
                {
                    dataString = sr.ReadToEnd();
                    Console.WriteLine(dataString);

                    #region 日志输出
                    CommonInfo.Log(dataString);
                    #endregion

                    //反序列化json为对象注意顺序很重要
                    ReqUploadPatrolInformation request = new ReqUploadPatrolInformation();
                    MemoryStream temp = new MemoryStream(Encoding.UTF8.GetBytes(dataString));
                    request = json.ReadObject(temp) as ReqUploadPatrolInformation;

                    //关闭临时流
                    temp.Close();

                    //调用用户更新密码接口
                    if (request != null)
                    {
                        #region **********(此处加入代码) 根据查询条件 加入业务逻辑代码*************
                        // 身份验证
                        if (request.user_id != String.Empty && request.token != String.Empty)
                        {
                            PatrolReportHeader        header     = ReportService.getHeader(request);
                            List <PatrolReportDetail> detailList = ReportService.getDetailList(request, header, request.dir_name);

                            success = PatrolEntity.InsertPatrol(header, detailList);
                            if (success)
                            {
                                //将点检图片存到正式文件夹
                                if (request.dir_name != null && request.dir_name != String.Empty)
                                {
                                    string saveDir = CommonInfo.ImageSaveUrl + "/" + request.dir_name;
                                    string tempDir = CommonInfo.ImageTempUrl + "/" + request.dir_name;
                                    if (Directory.Exists(tempDir))
                                    {
                                        if (success)
                                        {
                                            //将临时文件夹拷贝到正式文件夹
                                            Directory.Move(tempDir, saveDir);
                                            success = true;
                                            //事务成功完成
                                            response.patrol_id = request.patrol_id;
                                        }
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                }
                sr.Close();
                Console.WriteLine(data);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                #region 日志输出
                CommonInfo.Error("上传特巡报告错误" + ex.Message);
                #endregion
            }

            //返回消息体
            if (success)
            {
                response.SetSuccess();
            }
            else
            {
                ////默认是失败
                //response.SetFailed();
            }
            //将消息序列化为Json格式数据
            DataContractJsonSerializer obj2Json = new DataContractJsonSerializer(typeof(ResUploadPatrolInformation));
            MemoryStream ms = new MemoryStream();
            obj2Json.WriteObject(ms, response);

            //注意一定要设置流的位置到开始位置,否则没有消息输出
            ms.Position = 0;
            return(ms);

            #endregion
        }