using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace VRS.Handler { /// /// App 的摘要说明 /// public class App : BaseHandler, IHttpHandler { DataService.BLL.pro_app bll_app = new DataService.BLL.pro_app(); DataService.BLL.pro_app_view bll_app_view = new DataService.BLL.pro_app_view(); DataService.BLL.pro_app_favor bll_app_favor = new DataService.BLL.pro_app_favor(); public void ProcessRequest(HttpContext context) { baseContext = context; context.Response.ContentType = "text/plain"; CrossDomain(); if (null == context.Request["action"]) { var result = GetResult(false, "缺少参数:action"); context.Response.Write(result); context.Response.End(); } string action = context.Request["action"]; switch (action) { //所有线路 //case "all": // QueryALL(context); // break; case "queryapp": QueryApp(context); break; //查询单个软件、课程 case "queryappone": QueryAppOne(context); break; case "viewapp": ViewApp(context); break; //查询收藏 case "appfavorquery": AppFavorQuery(context); break; //添加收藏 case "appfavoradd": AppFavorAdd(context); break; //删除收藏 case "appfavordel": AppFavorDel(context); break; default: var result = GetResult(false, "方法名不存在:" + action); context.Response.Write(result); break; } } /// /// 应用收藏添加接口 /// /// public void AppFavorAdd(HttpContext context) { string app_id = context.Request["app_id"]; if (string.IsNullOrEmpty(app_id)) { var result = GetResult(false, "缺少参数:app_id"); context.Response.Write(result); context.Response.End(); } var model = bll_app.GetModel(app_id); if (null == model) { var result = GetResult(false, "应用不存在:app_id " + app_id); context.Response.Write(result); context.Response.End(); } string user_id = context.Request["user_id"]; if (string.IsNullOrEmpty(app_id)) { var result = GetResult(false, "缺少参数:user_id"); context.Response.Write(result); context.Response.End(); } var qry = string.Format("app_id='{0}' and user_id='{1}' ", app_id, user_id); var list = bll_app_favor.GetModelList(qry); if (list.Count > 0) { var result = GetResult(false, "收藏记录已经存在:时间 " + list[0].favor_time.Value.ToString("yyyy-MM-dd HH:mm:ss")); context.Response.Write(result); context.Response.End(); } else { var add = new DataService.Model.pro_app_favor(); add.id = BasePage.GetId(); add.app_id = app_id; add.user_id = user_id; add.favor_time = DateTime.Now; if (bll_app_favor.Add(add)) { var result = GetResult(true, null, ""); context.Response.Write(result); context.Response.End(); } else { var result = GetResult(false, null, "添加收藏记录失败"); context.Response.Write(result); context.Response.End(); } } } /// /// 应用收藏查询接口 /// /// public void AppFavorQuery(HttpContext context) { string user_id = context.Request["user_id"]; if (string.IsNullOrEmpty(user_id)) { var result = GetResult(false, "缺少参数:user_id"); context.Response.Write(result); context.Response.End(); } string str_page_size = context.Request["page_size"]; string str_page_index = context.Request["page_index"]; int page_size = 10; int page_index = 1; if (int.TryParse(str_page_size, out int i_page_size)) { page_size = i_page_size; } if (int.TryParse(str_page_index, out int i_page_index)) { page_index = i_page_index; } int recordCount = 0; var qry = string.Format(" id in (select app_id from pro_app_favor where user_id='{0}' ) ", user_id); var list = bll_app.GetModelPageList(qry, page_index, page_size, ref recordCount); foreach(var item in list) { bll_app.GetSoftMajorDetails(item); } if (true) { var obj = new { total = recordCount, list = list }; var result = GetResult(true, obj, ""); context.Response.Write(result); context.Response.End(); } } /// /// 应用收藏删除接口 /// /// public void AppFavorDel(HttpContext context) { string app_id = context.Request["app_id"]; if (string.IsNullOrEmpty(app_id)) { var result = GetResult(false, "缺少参数:app_id"); context.Response.Write(result); context.Response.End(); } string user_id = context.Request["user_id"]; if (string.IsNullOrEmpty(app_id)) { var result = GetResult(false, "缺少参数:user_id"); context.Response.Write(result); context.Response.End(); } var qry = string.Format("app_id='{0}' and user_id='{1}' ", app_id, user_id); var model = bll_app_favor.GetModelList(qry).FirstOrDefault(); if (null== model) { var result = GetResult(false, "收藏记录不存在 "); context.Response.Write(result); context.Response.End(); } else { var id = model.id; if (bll_app_favor.Delete(id)) { var result = GetResult(true, null, ""); context.Response.Write(result); context.Response.End(); } else { var result = GetResult(false, null, "删除收藏记录失败"); context.Response.Write(result); context.Response.End(); } } } /// /// 应用浏览接口 /// /// public void ViewApp(HttpContext context) { string app_id = context.Request["app_id"]; if (string.IsNullOrEmpty(app_id)) { var result = GetResult(false, "缺少参数:app_id"); context.Response.Write(result); context.Response.End(); } var model = bll_app.GetModel(app_id); if (null== model) { var result = GetResult(false, "应用不存在:app_id "+ app_id); context.Response.Write(result); context.Response.End(); } var ip =HttpContext.Current.Request.UserHostAddress; var qry = string.Format("app_id='{0}' and view_ip='{1}' ", app_id, ip); var list = bll_app_view.GetModelList(qry); if (list.Count>0) { var result = GetResult(false, "浏览记录已经存在:时间 " + list[0].view_time.Value.ToString("yyyy-MM-dd HH:mm:ss")); context.Response.Write(result); context.Response.End(); } else { var add = new DataService.Model.pro_app_view(); add.id = BasePage.GetId(); add.app_id = app_id; add.view_ip = ip; add.view_time = DateTime.Now; if (bll_app_view.Add(add)) { var result = GetResult(true, null,""); context.Response.Write(result); context.Response.End(); } else { var result = GetResult(false, null, "添加浏览记录失败"); context.Response.Write(result); context.Response.End(); } } } /// /// 查询单个软件、课程 /// /// public void QueryAppOne(HttpContext context) { string app_id = context.Request["app_id"]; if (string.IsNullOrEmpty(app_id)) { context.Response.Write(GetResult(false, "参数app_id不能为空")); context.Response.End(); } DataService.BLL.pro_app bll = new DataService.BLL.pro_app(); var model = bll.GetModel(app_id); if (null != model) { bll.GetSoftMajorDetails(model); var result = GetResult(true, model, ""); context.Response.Write(result); context.Response.End(); } else { var result = GetResult(false, null, "记录不存在:"+ app_id); context.Response.Write(result); context.Response.End(); } } /// /// 应用查询 /// /// public void QueryApp(HttpContext context) { string name = context.Request["name"]; string str_page_size = context.Request["page_size"]; string str_page_index = context.Request["page_index"]; int page_size = 10; int page_index = 1; /* `type` COMMENT '类型:软件、课程', `subject_id` COMMENT '科目ID', `major_id` COMMENT '专业ID', `soft_id` '软件类型ID', is_hot 热门 是、否 */ if (int.TryParse(str_page_size, out int i_page_size)) { page_size = i_page_size; } if (int.TryParse(str_page_index, out int i_page_index)) { page_index = i_page_index; } int start = (page_index - 1) * page_size; int end = start + page_size; var qry = " 1=1 "; if (!string.IsNullOrEmpty(name)) { qry = qry + string.Format(" and app_name like '%{0}%'", name); //月份 } string type = context.Request["type"]; string subject_id = context.Request["subject_id"]; string major_id = context.Request["major_id"]; string soft_id = context.Request["soft_id"]; string is_hot = context.Request["is_hot"]; if (!string.IsNullOrEmpty(type)) { qry = qry + string.Format(" and type = '{0}' ", type); //月份 } if (!string.IsNullOrEmpty(subject_id)) { qry = qry + string.Format(" and subject_id = '{0}' ", subject_id); //月份 } if (!string.IsNullOrEmpty(major_id)) { qry = qry + string.Format(" and major_id = '{0}' ", major_id); // } if (!string.IsNullOrEmpty(soft_id)) { qry = qry + string.Format(" and soft_id = '{0}' ", soft_id); // } if (!string.IsNullOrEmpty(is_hot)) { qry = qry + string.Format(" and is_hot = '{0}' ", is_hot); //热门 } int recordCount = 0; var list = bll_app.GetModelPageList(qry, page_index, page_size, ref recordCount); foreach (var item in list) { /* var Authority = context.Request.Url.Authority; if (!string.IsNullOrEmpty(item.video_url)) { var new_url = "http://" + Authority + item.video_url.Replace("~", ""); item.video_url = new_url; } */ bll_app.GetSoftMajorDetails(item); } var obj = new { total = recordCount, list = list }; var result = GetResult(true, obj); context.Response.Write(result); context.Response.End(); } /* /// /// 告警信息 /// /// public void QueryAlarmInfo(HttpContext context) { var list = bll_alarm_info.GetModelList(""); var result = GetResult(true, list); context.Response.Write(result); context.Response.End(); } */ public bool IsReusable { get { return false; } } } }