using System; using System.Collections.Generic; using System.Linq; using System.Web; using FangYar.Common; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System.Data; namespace FangYar.WebUI.ashx { /// /// CarApplyHandler 的摘要说明 /// public class CarApplyHandler : IHttpHandler { private FangYar.BLL.TBL_SYS_CARAPPLY bll = new FangYar.BLL.TBL_SYS_CARAPPLY(); private FangYar.BLL.TBL_SYS_CAR car_bll = new FangYar.BLL.TBL_SYS_CAR(); public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string action = context.Request.Params["Action"];// string returnstr = ""; switch (action) { case "List": returnstr = GetList(context); break; case "UseList": returnstr = GetUseList(context); break; case "Add": returnstr = Add(context); break; case "getWaitList": returnstr = getWaitList(context); break; case "editWait": returnstr = editWait(context); break; case "AppList": returnstr = AppList(context); break; case "ReturnCar": returnstr = ReturnCar(context); break; case "ApprovalRegression": returnstr = ApprovalRegression(context); break; case "getCarApply": returnstr = getCarApply(context); break; case "homeApplySta": returnstr = homeApplySta(context); break; case "getCarApplySta2": returnstr = getCarApplySta2(context); break; } context.Response.Write(returnstr); } //查询 private string GetUseList(HttpContext context) { string returnstr = ""; try { string uid = context.Request.Params["uid"]; string keyword = context.Request.Params["keywords"]; string treeID = context.Request.Params["treeID"]; string OrgList = context.Request.Params["OrgList"]; string id = context.Request.Params["id"]; string Orgid = context.Request.Params["OrgId"]; string page = context.Request.Params["page"]; string limit = context.Request.Params["limit"]; string is_content = context.Request.Params["is_content"]; string stime = context.Request.Params["stime"]; string etime = context.Request.Params["etime"]; int pageIndex = 1; int pageSize = 10; if (!string.IsNullOrEmpty(page)) { pageIndex = int.Parse(page); } if (!string.IsNullOrEmpty(limit)) { pageSize = int.Parse(limit); } string strOrg = "1=1 "; if (!string.IsNullOrEmpty(treeID) && treeID != Orgid) { if (is_content == "1") { strOrg = "( org_id in ( select o.org_id from fire_org o,(select get_Org_child_list('" + treeID + "') cids ) s where find_in_set(o.org_id,cids)) "; strOrg += " or DEPT_ID in ( select o.org_id from fire_org o,(select get_Org_child_list('" + treeID + "') cids ) s where find_in_set(o.org_id,cids))) "; } else { strOrg = "( ORG_ID = '" + treeID + "'"; strOrg += " or DEPT_ID = '" + treeID + "')"; } } else { if (is_content == "1") { strOrg = " (org_id in ( select o.org_id from fire_org o,(select get_Org_child_list('" + Orgid + "') cids ) s where find_in_set(o.org_id,cids)) "; strOrg += " or DEPT_ID in ( select o.org_id from fire_org o,(select get_Org_child_list('" + Orgid + "') cids ) s where find_in_set(o.org_id,cids))) "; } else { strOrg = "(ORG_ID = '" + Orgid + "'"; strOrg += " or DEPT_ID = '" + Orgid + "')"; } } string where = " carnum in (select car_num from tbl_sys_car where " + strOrg + ") "; if (!string.IsNullOrEmpty(keyword)) { where += " and ( USERNAME like '%" + keyword + "%' or USERPHONE like '%" + keyword + "%' or CARNUM like '%" + keyword + "%' )"; } if (!string.IsNullOrEmpty(id)) { where += " and ( ID ='" + id + "' )"; } if (!string.IsNullOrEmpty(stime) && !string.IsNullOrEmpty(etime)) { where += " and (date_format(STARTTIME,'%Y-%m-%d') >= date_format('" + stime + "','%Y-%m-%d') and date_format(FINISHTIME,'%Y-%m-%d') <= date_format('" + etime + "','%Y-%m-%d'))"; } string where1 = " and state = '1' order by starttime desc"; //and ( extendcode2 = '2' or extendcode2 = '2') returnstr = "{\"code\":0,\"msg\":\"\","; int count = bll.GetRecordCount(where + where1); returnstr += "\"count\":" + count + ",\"data\":"; if (count == 0) { returnstr += "[]"; } else { //string where2 = " and t.state = '1' and t.extendcode2 = '2' order by starttime desc"; string where2 = " and t.state = '1' order by starttime desc"; DataTable dt = bll.QueryTable(pageIndex, pageSize, where + where2, ""); returnstr += FangYar.Common.JsonHelper.ToJson(dt); } returnstr += "}"; } catch { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]"; } return returnstr; } //查询 private string GetList(HttpContext context) { string returnstr = ""; try { string uid = context.Request.Params["uid"]; string keyword = context.Request.Params["keywords"]; //string treeID = context.Request.Params["treeID"]; //string type = context.Request.Params["type"]; string id = context.Request.Params["id"]; string page = context.Request.Params["page"]; string limit = context.Request.Params["limit"]; int pageIndex = 1; int pageSize = 10; if (!string.IsNullOrEmpty(page)) { pageIndex = int.Parse(page); } if (!string.IsNullOrEmpty(limit)) { pageSize = int.Parse(limit); } string where = " (USERID = '" + uid + "' or USERID = 'u_" + uid + "') "; if (!string.IsNullOrEmpty(keyword)) { where += " and ( USERNAME like '%" + keyword + "%' or USERPHONE like '%" + keyword + "%' or CARNUM like '%" + keyword + "%' )"; } if (!string.IsNullOrEmpty(id)) { where += " and ( ID ='" + id + "' )"; } where += "order by starttime desc"; returnstr = "{\"code\":0,\"msg\":\"\","; int count = bll.GetRecordCount(where); returnstr += "\"count\":" + count + ",\"data\":"; if (count == 0) { returnstr += "[]"; } else { DataTable dt = bll.QueryTable(pageIndex, pageSize, where, ""); returnstr += FangYar.Common.JsonHelper.ToJson(dt); } returnstr += "}"; } catch { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]"; } return returnstr; } //添加 private string Add(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string userid = context.Request.Params["userid"];//申请人ID string username = context.Request.Params["username"];//申请人姓名 string userphone = context.Request.Params["userphone"];//申请人电话 string carid = context.Request.Params["carid"];//车辆号牌 string userman = context.Request.Params["userman"];//用车人 string dept = context.Request.Params["dept"];//单位 string ridenum = context.Request.Params["ridenum"];//乘车时间 string ridemans = context.Request.Params["ridemans"];////乘车人员 string ridepurpose = context.Request.Params["ridepurpose"];//用车目的 string startpoint = context.Request.Params["startpoint"];//起点 string destination = context.Request.Params["destination"];//目的地 string starttime = context.Request.Params["starttime"]; //其实时间 string finishtime = context.Request.Params["finishtime"]; //结束时间 string app_pplId = context.Request.Params["app_pplId"];//审批人员 //申请用车 FangYar.Model.TBL_SYS_CARAPPLY model = new Model.TBL_SYS_CARAPPLY(); model.ID = Guid.NewGuid().ToString("N"); model.USERID = userid; model.USERNAME = username; model.USERPHONE = userphone; model.CARID = carid; FangYar.BLL.TBL_SYS_CAR car_bll = new BLL.TBL_SYS_CAR(); FangYar.Model.TBL_SYS_CAR car_model = car_bll.GetModel(carid); model.CARNUM = ""; if (car_model != null) { model.CARNUM = car_model.CAR_NUM; } model.CARNUM = car_model.CAR_NUM; model.USERMAN = userman; //获取申请人信息 FangYar.BLL.TBL.SysEmpBLL emp_bll = new BLL.TBL.SysEmpBLL(); FangYar.Model.TBL.TBL_SYS_EMP_Model empmodel = emp_bll.GetModelByID(userid); model.DEPT = dept; //if (car_model != null) //{ // model.DEPT = empmodel.DEPT_ID; //} model.TYPE = ""; if (!string.IsNullOrEmpty(ridenum)) { model.RIDENUM = Int32.Parse(ridenum); } else { model.RIDENUM = 1; } model.RIDEMANS = ridemans; model.RIDEPURPOSE = ridepurpose; model.STARTPOINT = startpoint; model.DESTINATION = destination; model.STARTTIME = DateTime.Parse(starttime); model.FINISHTIME = DateTime.Parse(finishtime); model.STATE = "0"; model.EXTENDCODE2 = ""; if (bll.Add(model)) { //添加到流程中 //{"data":[{"ppl_Id":"cscj01","ppl_Name":"昌吉支队测试账号01"}]} JObject jObj = JObject.Parse(app_pplId); var datas = jObj["data"]; int i = 1; bool result = false; FangYar.BLL.OA_WAITPROCESSED wbll = new BLL.OA_WAITPROCESSED(); foreach (var data in datas) { JObject jObj2 = JObject.Parse(data.ToString()); string ppl_Id = jObj2["ppl_Id"].ToString(); string ppl_Name = jObj2["ppl_Name"].ToString(); FangYar.Model.OA_WAITPROCESSED wmodel = new FangYar.Model.OA_WAITPROCESSED(); wmodel.ID = Guid.NewGuid().ToString("N"); wmodel.TASK_ID = model.ID; wmodel.TASK_TYPE = "carApply"; wmodel.PPL_ID = ppl_Id; wmodel.PPL_NAME = ppl_Name; wmodel.R_TIME = DateTime.Now.ToString(); wmodel.SORT = i; wmodel.APPLE_ID = userid; wmodel.APPLE_NAME = username; string state = "0"; if (i == 1) { state = "1"; } wmodel.STATE = state; result = wbll.Add(wmodel); if (i == 1) { FangYar.BLL.TBL.SysUsersBLL ubll = new BLL.TBL.SysUsersBLL(); Model.TBL.TBL_SYS_USERS_Model usersModel = ubll.CheckLoginByUserID(ppl_Id); cwsService.CwsClient cws = new cwsService.CwsClient(); cws.yqMessageSend(usersModel.USERS_MOBILE, ppl_Name, "用车", "待审批"); } i++; if (result) { car_model.ISAPPLY = "1"; bool result_car = car_bll.Update(car_model); if (result_car) { msg = "添加成功!"; code = 1; } else { return returnstr = "{\"msg\":\"添加失败!\",\"code\":-1}"; } } else { return returnstr = "{\"msg\":\"添加失败!\",\"code\":-1}"; } } msg = "添加成功!"; code = 1; } else { msg = "添加失败!"; } } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]"; } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; return returnstr; } private string getWaitList(HttpContext context) { string returnstr = ""; try { string taskid = context.Request.Params["id"];//tsakID int count = 0; string strWhere = ""; //TASK_ID //申请用车流转信息 //select* from WORKFLOWTASK t where instanceid = '" + leaveId + "' order by sort FangYar.BLL.OA_WAITPROCESSED waitbll = new BLL.OA_WAITPROCESSED(); strWhere = " TASK_ID='" + taskid + "' order by SORT asc"; returnstr += "{\"code\":1,\"msg\":\"error\","; count = waitbll.GetRecordCount(strWhere); if (count == 0) { FangYar.BLL.OA_ALREADYPROCESSED alreadybll = new BLL.OA_ALREADYPROCESSED(); count = alreadybll.GetRecordCount(strWhere); returnstr += "\"count\":" + count + ",\"data\":"; if (count == 0) { returnstr += "[]"; } else { List list = alreadybll.GetModelList(strWhere); returnstr += FangYar.Common.JsonHelper.ToJson(list); } } else { returnstr += "\"count\":" + count + ",\"data\":"; List list = waitbll.GetModelList(strWhere); returnstr += FangYar.Common.JsonHelper.ToJson(list); } returnstr += "}"; } catch { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; } return returnstr; } //车辆申请审批 private string editWait(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; string usercode = ""; try { string leaveId = context.Request.Params["leaveId"]; string waitId = context.Request.Params["waitId"]; string state = context.Request.Params["state"]; string sort = context.Request.Params["sort"]; string aOpinion = context.Request.Params["a_opinion"]; string isOver = context.Request.Params["isOver"]; FangYar.Model.OA_WAITPROCESSED model = new Model.OA_WAITPROCESSED(); model.ID = waitId; model.TASK_ID = leaveId; model.STATE = state; model.SORT = Convert.ToInt32(sort); model.A_OPINION = aOpinion; usercode = bll.editWait(model, isOver); if (!string.IsNullOrEmpty(usercode)) { msg = "审批成功!"; code = 1; cwsService.CwsClient cws = new cwsService.CwsClient(); FangYar.BLL.TBL.SysUsersBLL ubll = new BLL.TBL.SysUsersBLL(); Model.TBL.TBL_SYS_USERS_Model usersModel = ubll.CheckLoginByUserID(usercode); string org3 = "已审批"; //发送给下一位待办人 if (state == "2" && isOver == "0") org3 = "待审批"; cws.yqMessageSend(usersModel.USERS_MOBILE, usersModel.USERS_NAME, "用车", org3); } else { msg = "审批失败!"; } } catch { msg = "审批失败!"; } returnstr = "{\"msg\":\"" + msg + "\",\"code\":\"" + code + "\",\"usercode\":\"" + usercode + "\"}"; return returnstr; } //查询 private string AppList(HttpContext context) { string returnstr = ""; try { string id = context.Request.Params["id"]; string where = "1=1"; if (!string.IsNullOrEmpty(id)) { where += " and ( ID ='" + id + "' )"; } returnstr = "{\"code\":0,\"msg\":\"\","; int count = bll.GetRecordCount(where); returnstr += "\"count\":" + count + ",\"data\":"; if (count == 0) { returnstr += "[]"; } else { Model.TBL_SYS_CARAPPLY mcarapply = bll.GetModel(id); returnstr += FangYar.Common.JsonHelper.ToJson(mcarapply); //获取流转信息 try { int count3 = 0, count2 = 0; string strWhere = ""; //申请用车 FangYar.BLL.OA_WAITPROCESSED waitbll = new BLL.OA_WAITPROCESSED(); strWhere = " TASK_ID='" + id + "' order by SORT asc"; count3 = waitbll.GetRecordCount(strWhere); if (count3 == 0) { FangYar.BLL.OA_ALREADYPROCESSED alreadybll = new BLL.OA_ALREADYPROCESSED(); count2 = alreadybll.GetRecordCount(strWhere); returnstr += ",\"data2\":"; if (count2 == 0) { returnstr += "[]"; } else { List list = alreadybll.GetModelList(strWhere); returnstr += FangYar.Common.JsonHelper.ToJson(list); } } else { returnstr += ",\"data2\":"; List list = waitbll.GetModelList(strWhere); returnstr += FangYar.Common.JsonHelper.ToJson(list); } } catch { returnstr = ",\"data2\":[]"; } } returnstr += "}"; } catch { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]"; } return returnstr; } //还车申请 private string ReturnCar(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; string usercode = ""; try { string Id = context.Request.Params["Id"]; //请假表 FangYar.Model.TBL_SYS_CARAPPLY model = new Model.TBL_SYS_CARAPPLY(); model.ID = Id; usercode = bll.ReturnCar(model); if (!string.IsNullOrEmpty(usercode)) { msg = "申请成功!"; code = 1; } else { msg = "申请失败!"; } } catch { msg = "申请失败!"; } returnstr = "{\"msg\":\"" + msg + "\",\"code\":\"" + code + "\",\"usercode\":\"" + usercode + "\"}"; return returnstr; } //还车审批 private string ApprovalRegression(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string TASK_ID = context.Request.Params["TASK_ID"]; string waitId = context.Request.Params["waitId"]; string state = context.Request.Params["state"]; //待办表 FangYar.Model.OA_WAITPROCESSED model = new Model.OA_WAITPROCESSED(); model.ID = waitId; model.TASK_ID = TASK_ID; model.STATE = state; if (bll.ApprovalRegression(model)) { msg = "审批成功!"; code = 1; } else { msg = "审批失败!"; } } catch { msg = "审批失败!"; } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; return returnstr; } //获取用车信息、流转记录 private string getCarApply(HttpContext context) { string returnstr = ""; try { string id = context.Request.Params["id"]; returnstr = "{\"code\":0,\"msg\":\"\",\"applyData\":"; List data = bll.getCarApply(id); returnstr += FangYar.Common.JsonHelper.ToJson(data[0]); returnstr += ",\"waitData\":"; returnstr += FangYar.Common.JsonHelper.ToJson(data[1]); returnstr += "}"; } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"leaveData\":[],\"waitData\":[] }"; } return returnstr; } //首页用车七天统计 private string homeApplySta(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; string data = ""; string strWhere = " 1=1"; try { string ORG_ID = context.Request.Params["Org_Id"]; if (!string.IsNullOrEmpty(ORG_ID)) { code = 1; strWhere += " and ORG_ID='" + ORG_ID + "'"; DataTable dt = bll.homeApplySta(strWhere); data = FangYar.Common.JsonHelper.ToJson(dt); } } catch { msg = "获取失败!"; } returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\",\"data\":" + data + "}"; return returnstr; } //车辆在岗统计 private string getCarApplySta2(HttpContext context) { string returnstr = ""; try { string ORG_ID = context.Request.Params["OrgId"]; string findDate = context.Request.Params["findDate"]; if (!string.IsNullOrEmpty(ORG_ID) && !string.IsNullOrEmpty(findDate)) { returnstr = "{\"code\":0,\"msg\":\"\",\"data\":"; DataTable list = bll.getCarApplySta2(ORG_ID, findDate); returnstr += FangYar.Common.JsonHelper.ToJson(list); returnstr += "}"; } else { return "{\"code\":-1,\"msg\":\"参数有误\",\"data\":[]}"; } } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; } return returnstr; } public bool IsReusable { get { return false; } } } }