/// <summary>
        ///
        /// </summary>
        /// <param name="uploadManagement">传入上传管理者实体</param>
        /// <returns>返回可以用来上传的json对象</returns>
        public ServiceResult GetServiceResult(UploadManagement uploadManagement)
        {
            //service返回结果对象
            ServiceResult serviceResult = new ServiceResult();

            //bdl_activity表
            if (uploadManagement.UM_DataTable == "bdl_activity")
            {
                //uploadManagement.Pk_UM_Type = "ActivityEntity";
                ActivityDAO activityDAO = new ActivityDAO();
                var         result      = activityDAO.Load(uploadManagement.UM_DataId);
                if (result == null)
                {
                    return(null);
                }

                ActivityDTO activityDTO = new ActivityDTO(result);
                serviceResult.Data = JsonTools.Obj2JSONStrNew <ActivityDTO>(activityDTO);
            }

            //bdl_member表
            else if (uploadManagement.UM_DataTable == "bdl_member")
            {
                MemberDAO memberDAO = new MemberDAO();


                var result = memberDAO.Load(uploadManagement.UM_DataId);
                if (result == null)
                {
                    return(null);
                }

                MemberDTO memberDTO = new MemberDTO(result);
                serviceResult.Data = JsonTools.Obj2JSONStrNew <MemberDTO>(memberDTO);
            }


            //bdl_personal_setting表
            else if (uploadManagement.UM_DataTable == "bdl_personal_setting")
            {
                PersonalSettingDAO personalSettingDAO = new PersonalSettingDAO();

                //Tr devicePrescriptionDAO = new DevicePrescriptionDAO();
                var result = personalSettingDAO.Load(uploadManagement.UM_DataId);
                if (result == null)
                {
                    return(null);
                }
                PersonalSettingDTO personalSettingDTO = new PersonalSettingDTO(result);

                serviceResult.Data = JsonTools.Obj2JSONStrNew <PersonalSettingDTO>(personalSettingDTO);
            }

            //bdl_skeleton_length表
            else if (uploadManagement.UM_DataTable == "bdl_skeleton_length")
            {
                SkeletonLengthDAO skeletonLengthDAO = new SkeletonLengthDAO();

                //Tr devicePrescriptionDAO = new DevicePrescriptionDAO();
                var result = skeletonLengthDAO.Load(uploadManagement.UM_DataId);
                if (result == null)
                {
                    return(null);
                }
                SkeletonLengthDTO skeletonLengthDTO = new SkeletonLengthDTO(result);
                serviceResult.Data = JsonTools.Obj2JSONStrNew <SkeletonLengthDTO>(skeletonLengthDTO);
            }

            //bdl_system_setting表
            else if (uploadManagement.UM_DataTable == "bdl_system_setting")
            {
                SystemSettingDAO systemSettingDAO = new SystemSettingDAO();

                //Tr devicePrescriptionDAO = new DevicePrescriptionDAO();
                var result = systemSettingDAO.Load(uploadManagement.UM_DataId);
                if (result == null)
                {
                    return(null);
                }

                SystemSettingDTO systemSettingDTO = new SystemSettingDTO(result);

                serviceResult.Data = JsonTools.Obj2JSONStrNew <SystemSettingDTO>(systemSettingDTO);
            }

            //bdl_training_activity_record表
            else if (uploadManagement.UM_DataTable == "bdl_training_activity_record")
            {
                TrainingActivityRecordDAO trainingActivityRecordDAO = new TrainingActivityRecordDAO();

                //Tr devicePrescriptionDAO = new DevicePrescriptionDAO();
                var result = trainingActivityRecordDAO.Load(uploadManagement.UM_DataId);
                if (result == null)
                {
                    return(null);
                }
                TrainingActivityRecordDTO trainingActivityRecordDTO = new TrainingActivityRecordDTO(result);

                serviceResult.Data = JsonTools.Obj2JSONStrNew <TrainingActivityRecordDTO>(trainingActivityRecordDTO);
            }

            //bdl_training_course表
            else if (uploadManagement.UM_DataTable == "bdl_training_course")
            {
                TrainingCourseDAO trainingCourseDAO = new TrainingCourseDAO();

                //Tr devicePrescriptionDAO = new DevicePrescriptionDAO();
                var result = trainingCourseDAO.Load(uploadManagement.UM_DataId);
                if (result == null)
                {
                    return(null);
                }

                TrainingCourseDTO trainingCourseDTO = new TrainingCourseDTO(result);

                serviceResult.Data = JsonTools.Obj2JSONStrNew <TrainingCourseDTO>(trainingCourseDTO);
            }


            //bdl_training_device_record表
            else if (uploadManagement.UM_DataTable == "bdl_training_device_record")
            {
                TrainingDeviceRecordDAO trainingDeviceRecordDAO = new TrainingDeviceRecordDAO();

                //Tr devicePrescriptionDAO = new DevicePrescriptionDAO();
                var result = trainingDeviceRecordDAO.Load(uploadManagement.UM_DataId);
                if (result == null)
                {
                    return(null);
                }

                TrainingDeviceRecordDTO trainingDeviceRecordDTO = new TrainingDeviceRecordDTO(result);
                serviceResult.Data = JsonTools.Obj2JSONStrNew <TrainingDeviceRecordDTO>(trainingDeviceRecordDTO);
            }
            //bdl_training_plan表
            else if (uploadManagement.UM_DataTable == "bdl_training_plan")
            {
                TrainingPlanDAO trainingPlanDAO = new TrainingPlanDAO();

                //Tr devicePrescriptionDAO = new DevicePrescriptionDAO();
                var result = trainingPlanDAO.Load(uploadManagement.UM_DataId);
                if (result == null)
                {
                    return(null);
                }



                TrainingPlanDTO trainingPlanDTO = new TrainingPlanDTO(result);
                serviceResult.Data = JsonTools.Obj2JSONStrNew <TrainingPlanDTO>(trainingPlanDTO);
            }
            return(serviceResult);
        }
Пример #2
0
        /// <summary>
        /// 处理上传训练结果请求
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public UploadResponse UploadRequest(UploadRequest request)
        {
            UploadResponse response = new UploadResponse
            {
                Uid          = request.Uid,
                DeviceType   = request.DeviceType,
                ActivityType = request.ActivityType,
                DataId       = request.DataId
            };

            response.Finished = true;
            response.Success  = true;
            //插入训练设备记录表
            var deviceRecord = new TrainingDeviceRecordEntity
            {
                Id        = KeyGenerator.GetNextKeyValueLong("bdl_training_device_record"),
                Member_id = request.Uid,
                Fk_training_activity_record_id = request.ActivityRecordId,
                Activity_type    = ((int)request.ActivityType).ToString(),
                Device_code      = ((int)request.DeviceType).ToString(),
                Training_mode    = ((int)request.TrainMode).ToString(),
                Consequent_force = request.ForwardForce,
                Reverse_force    = request.ReverseForce,
                Power            = request.Power,
                Count            = request.FinishCount,
                Distance         = request.FinalDistance,
                Energy           = request.Calorie,
                Training_time    = request.TrainTime,
                Avg_heart_rate   = request.HeartRateAvg,
                Max_heart_rate   = request.HeartRateMax,
                Min_heart_rate   = request.HeartRateMin,
                Gmt_create       = DateTime.Now
            };

            using (TransactionScope ts = new TransactionScope()) //使整个代码块成为事务性代码
            {
                //更新顺向力反向力和功率
                personalSettingDAO.UpdateSettingByUid(request.ForwardForce, request.ReverseForce, request.Power, request.Uid, request.DeviceType);
                trainingDeviceRecordDAO.Insert(deviceRecord);
                //查一下是否是该循环最后一个设备,是的话更新课程表数量加一并看一下是否已完成,训练活动记录表标志位已完成 修改传入的fk_activity_id和course_count参数为活动记录表主键activityRecordId  --ByCQZ 4.7
                List <DeviceType> todoList = this.GenToDoDevices(request.Uid, request.ActivityType, request.DefatModeEnable, request.ActivityRecordId);
                if (todoList.Count == 0)//训练完毕一个循环,
                {
                    //更新记录完成状态
                    trainingActivityRecordDAO.UpdateCompleteState(request.ActivityRecordId, true);
                    //训练活动伦次数量加一
                    ActivityEntity activity = activityDAO.Load(request.ActivityId);
                    //测试时出现了活动对象为NULL的异常 于是加此判断 byCQZ
                    if (activity != null)
                    {
                        activity.current_turn_number += 1;
                        if (activity.current_turn_number >= activity.Target_turn_number)//完成这一次活动的话
                        {
                            activity.Is_complete  = true;
                            activity.Gmt_modified = DateTime.Now;
                        }
                        activityDAO.UpdateByPrimaryKey(activity);

                        //判断是否完成了这一次课程,即该课程ID下的所有Activity是否都为完成状态
                        if (activity.Is_complete == true)
                        {
                            int?count = activityDAO.CountByCourseId(request.CourseId, false);
                            if (count == 0)//此课时下的活动都完成了 更新课时计数+1
                            {
                                //课时完成,必须要更新活动的当前次数为0 状态为未完成 ByCQZ 4.8
                                activityDAO.ResetCourseByCourseId(request.CourseId);

                                TrainingCourseEntity courseEntity = trainingCourseDAO.Load(request.CourseId);
                                courseEntity.Current_course_count += 1;
                                if (courseEntity.Current_course_count >= courseEntity.Target_course_count)//课程完成的话,这里用>=防止并发被击穿目标次数
                                {
                                    courseEntity.Current_end_date = DateTime.Now;
                                    courseEntity.Is_complete      = true;
                                }
                                //else//只是完成了一个课时,将Activity的complete置零,current_turn_number置零 updateByCQZ
                                //{
                                //    activityDAO.ResetCourseByCourseId(request.CourseId);
                                //}
                                trainingCourseDAO.UpdateByPrimaryKey(courseEntity);
                            }
                        }
                    }
                }
                else
                {
                    response.Finished = false;
                }
                ts.Complete();
            }
            return(response);
        }