/// <summary> /// EditActity页活动分组Expnder中的个人设置查询 分组是前端根据活动类型分 /// </summary> /// <returns></returns> public List <ActivityGroupDTO> ListActivitysGroupAndPersonalSetting() { //当前正在进行和训练课程ID long courseId = ParseIntegerUtil.ParseInt(CommUtil.GetSettingString("trainingCourseId")); return(activityDAO.ListActivitysGroupAndPersonalSetting(courseId)); }
/// <summary> /// 批量插入训练活动 /// </summary> /// <param name="activities"></param> /// <returns></returns> public long BatchSaveActivity(List <ActivityEntity> activities) { using (TransactionScope ts = new TransactionScope()) { UploadManagementDAO uploadManagementDao2 = new UploadManagementDAO(); long result = 0; //判断登陆用户,是教练自己锻炼。还是教练为用户进行设置。决定传哪个参数 string currentMemberPK = CommUtil.GetSettingString("memberPrimarykey"); string currentCoachId = CommUtil.GetSettingString("coachId"); if ((currentMemberPK == null || currentMemberPK == "") && (currentCoachId != null && currentCoachId != "")) { //无用户登陆。教练单独登陆时对教练进行设置 foreach (var activity in activities) { activity.Id = KeyGenerator.GetNextKeyValueLong("bdl_activity"); activity.Member_id = CommUtil.GetSettingString("memberId"); activity.Fk_member_id = ParseIntegerUtil.ParseInt(CommUtil.GetSettingString("coachId")); activity.Fk_training_course_id = ParseIntegerUtil.ParseInt(CommUtil.GetSettingString("trainingCourseId")); activity.Gmt_create = System.DateTime.Now; activity.Is_complete = false; activity.current_turn_number = 0; //插入至上传表 uploadManagementDao2.Insert(new UploadManagement(activity.Id, "bdl_activity", 0)); } //批量插入训练活动 result = activityDAO.BatchInsert(activities); //根据训练活动批量插入个人设置记录 传入教练的主键id personalSettingService.SavePersonalSettings(ParseIntegerUtil.ParseInt(CommUtil.GetSettingString("coachId"))); } else { //只要用户登录,为用户进行设置 foreach (var activity in activities) { activity.Id = KeyGenerator.GetNextKeyValueLong("bdl_activity"); activity.Member_id = CommUtil.GetSettingString("memberId"); activity.Fk_member_id = ParseIntegerUtil.ParseInt(CommUtil.GetSettingString("memberPrimarykey")); activity.Fk_training_course_id = ParseIntegerUtil.ParseInt(CommUtil.GetSettingString("trainingCourseId")); activity.Gmt_create = System.DateTime.Now; activity.Is_complete = false; activity.current_turn_number = 0; //插入至上传表 uploadManagementDao2.Insert(new UploadManagement(activity.Id, "bdl_activity", 0)); } //批量插入训练活动 result = activityDAO.BatchInsert(activities); //根据训练活动批量插入个人设置记录 传入会员的主键id personalSettingService.SavePersonalSettings(ParseIntegerUtil.ParseInt(CommUtil.GetSettingString("memberPrimarykey"))); } ts.Complete(); return(result); } }
/// <summary> /// 添加训练课程 /// </summary> /// <param name="trainingCourseEntity"></param> /// <returns></returns> public void SaveTrainingCourse(DateTime?startDate) { TrainingCourseEntity trainingCourseEntity = new TrainingCourseEntity(); //主键id trainingCourseEntity.Id = KeyGenerator.GetNextKeyValueLong("bdl_training_course"); //设置外键训练计划id trainingCourseEntity.Fk_training_plan_id = ParseIntegerUtil.ParseInt(CommUtil.GetSettingString("trainingPlanId")); //设置会员卡号 trainingCourseEntity.Member_id = CommUtil.GetSettingString("memberId"); //当前创建时间 trainingCourseEntity.Gmt_create = System.DateTime.Now; //6.创建一个默认的训练课程 // 课程开始时间 = 训练计划的开始时间 trainingCourseEntity.Start_date = startDate; // 默认暂停时间是4天 trainingCourseEntity.Rest_days = 2; // 默认课程天数是16天 trainingCourseEntity.Target_course_count = 16; // 默认结束日期 = 开始日期 + (暂停时间*(课程天数 - 1)) 减一是因为当天算第一天 trainingCourseEntity.End_date = trainingCourseEntity.Start_date.Value.AddDays(trainingCourseEntity.Rest_days.Value * (trainingCourseEntity.Target_course_count.Value - 1)); // 状态未完成 trainingCourseEntity.Is_complete = false; // 当前计数默认0 trainingCourseEntity.Current_course_count = 0; // 保存课程 //这个插入基类有BUG 明明插入进入了 但是返回的结果为0,所以不要返回值了。反正如果插入失败也报异常,返回值也没啥用 trainingCourseDAO.Insert(trainingCourseEntity); //插入至上传表 UploadManagementDAO uploadManagementDao = new UploadManagementDAO(); uploadManagementDao.Insert(new UploadManagement(trainingCourseEntity.Id, "bdl_training_course", 0)); //更新配置中的课程id CommUtil.UpdateSettingString("trainingCourseId", (trainingCourseEntity.Id).ToString()); //训练课程目标天数 CommUtil.UpdateSettingString("targetCourseCount", (trainingCourseEntity.Target_course_count).ToString()); }
/// <summary> /// 根据训练课程ID查询出对应的训练活动 /// </summary> /// <returns></returns> public List <ActivityEntity> ListActivitysByCourseId() { return(activityDAO.ListActivitysByCourseId(ParseIntegerUtil.ParseInt(CommUtil.GetSettingString("trainingCourseId")))); }
/// <summary> /// 添加训练活动后,自动根据数据库中的训练活动记录,往个人设置表插入记录 /// </summary> /// <returns></returns> public bool SavePersonalSettings(long userPK) { //上传表 UploadManagementDAO uploadManagementDao = new UploadManagementDAO(); //使整个代码块成为事务性代码 using (TransactionScope ts = new TransactionScope()) { //1.先查询当前训练课程对应的训练活动集合 List <ActivityEntity> activities = activityDAO.ListActivitysByCourseId(ParseIntegerUtil.ParseInt(CommUtil.GetSettingString("trainingCourseId"))); //遍历每一条活动 foreach (var activity in activities) { //先查询判断个人设置表是否有该会员ID,该活动类型的记录,传入会员id和活动类型 string memberID = CommUtil.GetSettingString("memberId"); List <PersonalSettingEntity> personalSettingEntities = personalSettingDAO.ListSettingByMemberIdActivityType(memberID, activity.Activity_type); //若个人设置表无该会员该训练活动的记录,则每个设备往个人设置表插入一条记录 if (personalSettingEntities.Count == 0) { //查询出每个活动类型对应着哪些设备 List <DatacodeEntity> datacodeEntities = datacodeDao.ListByTypeIdAndExtValue("DEVICE", activity.Activity_type); //批量插入 构建集合 var personalSettingList = new List <PersonalSettingEntity>(); foreach (var item in datacodeEntities) { var personalSetting = new PersonalSettingEntity(); personalSetting.Id = KeyGenerator.GetNextKeyValueLong("bdl_personal_setting"); personalSetting.Activity_type = activity.Activity_type; //默认标准模式 personalSetting.Training_mode = "0"; personalSetting.Device_code = item.Code_s_value; personalSetting.Device_order_number = item.Code_xh; //主键设置为传入的主键,因为传入前判断是登陆的教练单独训练还是有用户登录 personalSetting.Fk_member_id = userPK; personalSetting.Member_id = CommUtil.GetSettingString("memberId"); personalSetting.Gmt_create = System.DateTime.Now; //这个外键id用于展示的时候联查活动表和设置表。能够根据当前存在的训练活动查出相应的设置。根据活动id联查是最简单的方法。 //否则如果根据会员卡号查有可能出现没选这个训练活动却因为以前添加过设置查出来了。如果再根据类型判断查询也很麻烦。添加活动的时候更新个人设置里这个外键活动id是最好的办法。 personalSetting.Fk_training_activity_id = activity.Id; //分别设置力度和功率 单车跑步机只设置功率 其他设置力度 if ("12".Equals(item.Code_s_value) || "16".Equals(item.Code_s_value)) { personalSetting.Power = 30; } else { //设置各个属性的默认值 personalSetting.Consequent_force = 21; //顺向力 personalSetting.Reverse_force = 21; //反向力 personalSetting.Front_limit = 100; //前方限制 personalSetting.Back_limit = 0; //后方限制 } //添加进集合 personalSettingList.Add(personalSetting); //插入至上传表 uploadManagementDao.Insert(new UploadManagement(personalSetting.Id, "bdl_personal_setting", 0)); } //使用基本DAO 批量插入数据库 personalSettingDAO.BatchInsert(personalSettingList); } //如果有记录就更新记录的外键活动id else if (personalSettingEntities.Count > 0) { PersonalSettingEntity personalSetting = new PersonalSettingEntity(); personalSetting.Fk_training_activity_id = activity.Id; personalSetting.Member_id = CommUtil.GetSettingString("memberId"); personalSetting.Activity_type = activity.Activity_type; personalSettingDAO.UpdateSettingActivityId(personalSetting); } } ts.Complete(); } return(true); }
/// <summary> /// 添加新的训练计划,需要先删除旧的训练计划 /// </summary> /// <param name="trainingPlan"></param> /// <returns></returns> public void SaveNewTrainingPlan(TrainingPlanEntity trainingPlan) { //使整个代码块成为事务性代码 using (TransactionScope ts = new TransactionScope()) { UploadManagementDAO uploadManagementDao = new UploadManagementDAO(); //会员卡号ID string memberId = CommUtil.GetSettingString("memberId"); //1.删除旧的训练计划 trainingPlanDAO.DeletePlanByMemberId(memberId); //2.完成旧的训练课程 trainingCourseDAO.UpdateCompleteState(memberId, true); List <long> listId1 = new List <long>(); listId1 = trainingCourseDAO.ListIdByMemeberId(memberId); foreach (var id in listId1) { //数据上传 uploadManagementDao.Insert(new UploadManagement(id, "bdl_training_course", 1)); } //3.完成旧的训练活动 activityDAO.UpdateCompleteState(memberId, true); List <long> listId = new List <long>(); //通过memberId获取主键id listId = activityDAO.ListIdByMemeberId(memberId); foreach (var id in listId) { //数据上传 uploadManagementDao.Insert(new UploadManagement(id, "bdl_activity", 1)); } //4.新增训练计划 trainingPlan.Id = KeyGenerator.GetNextKeyValueLong("bdl_training_plan"); //判断登陆用户,是教练自己锻炼。还是教练为用户进行设置。决定传哪个主键设置 string currentMemberPK = CommUtil.GetSettingString("memberPrimarykey"); string currentCoachId = CommUtil.GetSettingString("coachId"); if ((currentMemberPK == null || currentMemberPK == "") && (currentCoachId != null && currentCoachId != "")) { //无用户登陆。教练单独登陆时 // 从app.config中取id,转成int赋值 trainingPlan.Fk_member_id = ParseIntegerUtil.ParseInt(currentCoachId); } else { //只要用户登录,就是为用户进行设置 // 从app.config中取id,转成int赋值 trainingPlan.Fk_member_id = ParseIntegerUtil.ParseInt(currentMemberPK); } // 设置会员卡号 trainingPlan.Member_id = CommUtil.GetSettingString("memberId"); // 设置状态为未删除 trainingPlan.Is_deleted = false; // 创建时间 trainingPlan.Gmt_create = System.DateTime.Now; // 插入新训练计划 trainingPlanDAO.Insert(trainingPlan); //插入至上传表 uploadManagementDao.Insert(new UploadManagement(trainingPlan.Id, "bdl_training_plan", 0)); //5.更新App.config中训练计划id CommUtil.UpdateSettingString("trainingPlanId", (trainingPlan.Id).ToString()); //插入默认训练课程 课程开始时间 = 训练计划开始时间 trainingCourseService.SaveTrainingCourse(trainingPlan.Start_date); ts.Complete(); } }
/// <summary> /// 新增保存会员信息 /// </summary> /// <param name="memberEntity"></param> /// <returns></returns> public long InsertMember(MemberEntity memberEntity) { //使整个代码块成为事务性代码 using (TransactionScope ts = new TransactionScope()) { //计算最大心率 = 220 - 年龄 //memberEntity.Max_heart_rate = 220 - memberEntity.Age; //计算最宜心率 = (最大心率 * 76.5%)然后四舍五入为整数 memberEntity.Suitable_heart_rate = (int?)Math.Round(memberEntity.Max_heart_rate.Value * 0.765); //设置主键id memberEntity.Id = KeyGenerator.GetNextKeyValueLong("bdl_member"); //设置创建时间 memberEntity.Gmt_create = System.DateTime.Now; //默认不开启减脂模式 memberEntity.Is_open_fat_reduction = false; //设置会员ID StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(memberEntity.Member_familyName); stringBuilder.Append(memberEntity.Member_firstName); //用户名3个字符以内 写入时UTF-8编码每个汉字占3个字节 if (stringBuilder.ToString().Length > 3) { string subMemberId = stringBuilder.ToString().Substring(0, 3); stringBuilder.Clear(); stringBuilder.Append(subMemberId); } //手机号不为空则拼接手机号后四位 if (memberEntity.Mobile_phone != null && memberEntity.Mobile_phone != "") { stringBuilder.Append(memberEntity.Mobile_phone.Substring(memberEntity.Mobile_phone.Length - 4)); } else { logger.Warn("拼接用户id时,用户手机号为空。用户名:" + memberEntity.Member_familyName + memberEntity.Member_firstName); } Console.WriteLine("用户名+手机号码后4位:" + stringBuilder.ToString()); //添加CRC校验 //string fullName = memberEntity.Member_familyName + memberEntity.Member_firstName; //string phone = memberEntity.Mobile_phone.Substring(memberEntity.Mobile_phone.Length - 2); //byte[] dataCRC = new byte[12]; //Encoding.GetEncoding("GBK").GetBytes(fullName, 0, fullName.Length, dataCRC, 0); //Encoding.GetEncoding("ASCII").GetBytes(phone, 0, phone.Length, dataCRC, 10); //string lowStrCRC = SerialPortUtil.CRC16(dataCRC)[0].ToString(); //string highStrCRC = SerialPortUtil.CRC16(dataCRC)[1].ToString(); //string fullCRC = lowStrCRC + highStrCRC; //stringBuilder.Append(fullCRC); //设置用户id memberEntity.Member_id = stringBuilder.ToString(); if (memberEntity.Role_id == 1)//只有添加的角色是用户才设置教练外键 { //当前登陆的教练Id memberEntity.Fk_coach_id = ParseIntegerUtil.ParseInt(CommUtil.GetSettingString("coachId")); } //使用基类插入新会员 long resultCode = memberDAO.Insert(memberEntity); //更新APP中会员设置,让新增的该会员登陆 强制更新配置类,将当前登陆用户踢出 //1.更新会员卡号ID CommUtil.UpdateSettingString("memberId", memberEntity.Member_id); //3.更新当前登陆用户的训练计划id CommUtil.UpdateSettingString("trainingPlanId", ""); //4.更新当前登陆用户的训练课程id CommUtil.UpdateSettingString("trainingCourseId", ""); //5.更新当前登陆用户的当前课程记录id current_course_count CommUtil.UpdateSettingString("currentCourseCount", ""); //5.更新当前登陆用户的目标课程记录id CommUtil.UpdateSettingString("targetCourseCount", ""); //6.更新当前登陆会员的主键 CommUtil.UpdateSettingString("memberPrimarykey", memberEntity.Id.ToString()); ts.Complete(); //使用基类插入新会员 return(resultCode); } }