/// <summary>
            /// 胸部推举机上报解析
            /// </summary>
            /// <param name="body"></param>
            public void PaserXall(byte[] body, string idCard, DeviceType deviceType)
            {
                //运动强度
                byte strength = ProtocolUtil.BcdToInt(body[1]);
                //运动时间 1/100秒
                Int32 time = BitConverter.ToInt32(body, 2);

                time = IPAddress.NetworkToHostOrder(time);
                //总移动距离 毫米
                Int32 distance = BitConverter.ToInt32(body, 6);

                distance = IPAddress.NetworkToHostOrder(distance);
                //总功 1/100 焦耳
                Int32 energy = BitConverter.ToInt32(body, 10);

                energy = IPAddress.NetworkToHostOrder(energy);

                //消耗热量 1/100 卡路里
                Int32 heat = BitConverter.ToInt32(body, 14);

                heat = IPAddress.NetworkToHostOrder(heat);
                //指数标识 0 正数 1 负数
                //指数值 1/100
                Int32 singer = BitConverter.ToInt32(body, 19);

                singer = IPAddress.NetworkToHostOrder(singer);
                singer = body[18] == 0x00 ? singer : -1 * singer;
                //动作节奏 0没问题 1 有些许问题 2 有问题
                byte rhythem = body[23];
                //使用者感想
                string think = ProtocolUtil.GetEndString(body, 24);

                PrescriptionResult result = new PrescriptionResult();

                //自觉运动强度
                result.PR_SportStrength     = (byte)(strength - 5);
                result.PR_Time1             = time / 100.0;
                result.PR_Distance          = distance;
                result.PR_CountWorkQuantity = energy / 100.0;
                result.PR_Cal          = heat / 100.0;
                result.PR_Index        = singer / 100.0;
                result.PR_Evaluate     = rhythem;
                result.PR_UserThoughts = think;
                result.Gmt_Create      = DateTime.Now;
                result.Gmt_Modified    = result.Gmt_Create;

                StringBuilder sb = new StringBuilder();

                sb.Append("运动强度:").Append(strength).Append("运动时间:").Append(time).Append("总移动距离:").Append(distance).Append("总功:").Append(energy)
                .Append("消耗热量").Append(heat).Append("指数值:").Append(singer).Append("动作节奏:").Append(rhythem);
                logger.Info("训练上报的解析结果:" + sb.ToString());
                TrainService trainService = new TrainService();

                // 存数据库
                trainService.AddPrescriptionResult(idCard, result, deviceType);
            }
Beispiel #2
0
        public TrainDTO(TrainInfo trainInfo, DevicePrescription devicePrescription, PrescriptionResult prescriptionResult)
        {
            if (trainInfo != null)
            {
                this.ID      = trainInfo.Pk_TI_Id;
                this.DateStr = trainInfo.Gmt_Create.ToString();
            }
            this.trainInfo          = trainInfo;
            this.devicePrescription = devicePrescription;
            this.prescriptionResult = prescriptionResult;
            moveway = prescriptionResult != null?DataCodeCache.GetInstance()
                      .GetCodeDValue(DataCodeTypeEnum.MoveWay, devicePrescription.dp_moveway.ToString()) : "";

            evaluate = prescriptionResult != null?DataCodeCache.GetInstance()
                       .GetCodeDValue(DataCodeTypeEnum.Evaluate, prescriptionResult.PR_Evaluate.ToString()) : "";
        }
Beispiel #3
0
        /// <summary>
        /// 添加训练结果,设备上报上来的结果
        /// </summary>
        /// <param name="idCard"></param>
        /// <param name="result"></param>
        public void AddPrescriptionResult(string idCard, PrescriptionResult result, DeviceType deviceType)
        {
            using (TransactionScope ts = new TransactionScope()) //使整个代码块成为事务性代码
            {
                DevicePrescription p = GetDevicePrescriptionByIdCardDeviceType(idCard, deviceType, (byte)DevicePrescription.UNDO);
                if (p == null)
                {
                    return;
                }
                //插入训练结果
                result.Fk_DP_Id = p.Pk_DP_Id;
                if (p.Gmt_Modified != null && result.Gmt_Create != null)
                {
                    TimeSpan ts0 = (DateTime)result.Gmt_Create - (DateTime)p.Gmt_Modified;
                    result.PR_Time2 = ts0.TotalSeconds;
                }

                prescriptionResultDAO.Insert(result);
                //插入至上传表
                UploadManagementDAO uploadManagementDao = new UploadManagementDAO();
                uploadManagementDao.Insert(new UploadManagement(result.Fk_DP_Id, "bdl_prescriptionresult", 0));
                //查询是否还有没完成的训练处方,如果都完成了就更新TrinInfo
                var unDoItemList = devicePrescriptionDAO.ListUnDoByTIId(p.Fk_TI_Id);
                if (unDoItemList.Count == 1)
                {
                    if (unDoItemList[0].Pk_DP_Id == p.Pk_DP_Id)//未完成的项目恰好是一个且为上报上来的这个项目就说明该大处方已经完成了,更新状态
                    {
                        var t = trainInfoDao.Load(p.Fk_TI_Id);
                        t.Pk_TI_Id = p.Fk_TI_Id;
                        t.Status   = (byte)TrainInfoStatus.Finish;
                        trainInfoDao.UpdateByPrimaryKey(t);
                        //插入至上传表
                        UploadManagementDAO uploadManagementDao1 = new UploadManagementDAO();
                        uploadManagementDao.Insert(new UploadManagement(t.FK_User_Id, "bdl_traininfo", 1));
                    }
                }

                //更新该设备处方已完成状态
                p.Dp_status = DevicePrescription.DOWN;
                devicePrescriptionDAO.UpdateByPrimaryKey(p);
                //插入至上传表
                UploadManagementDAO uploadManagementDao2 = new UploadManagementDAO();
                uploadManagementDao.Insert(new UploadManagement(p.Pk_DP_Id, "bdl_deviceprescription", 1));

                ts.Complete();
            }
        }
Beispiel #4
0
        public Dictionary <int, List <TrainDTO> > getTrainDTOByUserA(User user)
        {
            TrainInfoDAO          trainInfoDao          = new TrainInfoDAO();
            DevicePrescriptionDAO devicePrescriptionDao = new DevicePrescriptionDAO();
            PrescriptionResultDAO prescriptionResultDao = new PrescriptionResultDAO();
            DeviceSortDAO         deviceSortDao         = new DeviceSortDAO();

            Dictionary <int, List <TrainDTO> > dic = new Dictionary <int, List <TrainDTO> >();

            //找到该用户训练记录(训练记录状态为0或2)
            List <TrainInfo> trainInfos = trainInfoDao.GetFinishOrNormalTrainInfoByUserId(user.Pk_User_Id);

            foreach (TrainInfo trainInfo in trainInfos)
            {
                //根据训练信息id查找处方
                List <DevicePrescription> devicePrescriptions = devicePrescriptionDao.GetByTIId(trainInfo.Pk_TI_Id);
                foreach (DevicePrescription devicePrescription in devicePrescriptions)
                {
                    int devId = devicePrescription.Fk_DS_Id;

                    //根据处方查找训练结果
                    PrescriptionResult prescriptionResult =
                        prescriptionResultDao.GetByDPId(devicePrescription.Pk_DP_Id);
                    if (prescriptionResult == null)
                    {
                        //如果没有训练结果,
                        continue;
                    }

                    //查找字典是否有以此设备名字命名的key,不存在则先创建
                    if (!dic.ContainsKey(devId))
                    {
                        List <TrainDTO> trainDtos = new List <TrainDTO>();
                        dic.Add(devId, trainDtos);
                    }
                    //                    Console.WriteLine(prescriptionResult.PR_Evaluate);
                    //PR_Evaluate 总是1????
                    dic[devId].Add(new TrainDTO(trainInfo, devicePrescription, prescriptionResult));
                }
            }

            return(dic);

            return(null);
        }
Beispiel #5
0
        /// <summary>
        /// 添加训练结果,返回主键
        /// </summary>
        public void AddPrescriptionResult(object siId, TrainInfo trainInfo,
                                          Dictionary <DevicePrescription, PrescriptionResult> prescriptionDic)
        {
            UploadManagementDAO   uploadManagementDao   = new UploadManagementDAO();
            DevicePrescriptionDAO devicePrescriptionDao = new DevicePrescriptionDAO();
            PrescriptionResultDAO prescriptionResultDao = new PrescriptionResultDAO();

            using (TransactionScope ts = new TransactionScope()) //使整个代码块成为事务性代码
            {
                //插入训练信息和上传表
                int tiId = (int)new TrainInfoDAO().Insert(trainInfo);
                uploadManagementDao.Insert(new UploadManagement(tiId, "bdl_traininfo", 0));
                if (siId != null)
                {
                    //改变症状表外键关联
                    var symptomInfo = symptomInfoDao.Load((int)siId);
                    symptomInfo.Fk_TI_Id = tiId;
                    symptomInfoDao.UpdateByPrimaryKey(symptomInfo);
                    //将更新信息插入至上传表
                    uploadManagementDao.Insert(new UploadManagement(tiId, "bdl_traininfo", 1));
                }
                if (prescriptionDic != null)
                {
                    int dpId;
                    int prId;
                    foreach (KeyValuePair <DevicePrescription, PrescriptionResult> prescription in prescriptionDic)
                    {
                        DevicePrescription devicePrescription = prescription.Key;
                        PrescriptionResult prescriptionResult = prescription.Value;
                        //插入设备处方、上传表
                        devicePrescription.Fk_TI_Id = tiId;
                        dpId = (int)devicePrescriptionDao.Insert(devicePrescription);
                        uploadManagementDao.Insert(new UploadManagement(dpId, "bdl_deviceprescription", 0));

                        //插入设备处方结果、上传表
                        prescriptionResult.Fk_DP_Id = dpId;
                        prId = (int)prescriptionResultDao.Insert(prescriptionResult);
                        uploadManagementDao.Insert(new UploadManagement(prId, "bdl_prescriptionresult", 0));
                    }
                }

                ts.Complete();
            }
        }
        public PrescriptionResultDTO(PrescriptionResult prescriptionResult, string mac)
        {
            this.clientId = mac;
            this.fkDpId   = prescriptionResult.Fk_DP_Id.ToString();

            this.gmtCreate           = prescriptionResult.Gmt_Create.ToString().Replace("/", "-");
            this.gmtModified         = prescriptionResult.Gmt_Modified.ToString().Replace("/", "-");
            this.pkPrId              = prescriptionResult.Pk_PR_Id.ToString();
            this.prAttentionpoint    = prescriptionResult.PR_AttentionPoint.ToString();
            this.prCal               = prescriptionResult.PR_Cal.ToString();
            this.prCountworkquantity = prescriptionResult.PR_CountWorkQuantity.ToString();
            this.prDistance          = prescriptionResult.PR_Distance.ToString();
            this.prEvaluate          = prescriptionResult.PR_Evaluate.ToString();
            this.prFinishgroup       = prescriptionResult.PR_FinishGroup.ToString();
            this.prIndex             = prescriptionResult.PR_Index.ToString();
            this.prMemo              = prescriptionResult.PR_Memo == null?"": prescriptionResult.PR_Memo.ToString();
            this.prSportstrength     = prescriptionResult.PR_SportStrength.ToString();
            this.prTime1             = prescriptionResult.PR_Time1.ToString();
            this.prTime2             = prescriptionResult.PR_Time2.ToString();
            this.prUserthoughts      = prescriptionResult.PR_UserThoughts.ToString();
        }