using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data; using System.Text; using System.Collections; using System.Reflection; using System.Web.Script.Serialization; using FangYar.Model; using FangYar.BLL; using Newtonsoft.Json.Linq; namespace FangYar.WebUI.ashx { /// /// OaLeaveHandler 的摘要说明 /// public class OaPerformancePublishHandler : IHttpHandler { private FangYar.BLL.OA.OA_PERFORMANCE_PUBLISH bll = new FangYar.BLL.OA.OA_PERFORMANCE_PUBLISH(); public void ProcessRequest(HttpContext context) { // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Other, "绩效公示操作请求", ""); context.Response.ContentType = "text/plain"; string action = context.Request.Params["Action"]; string returnstr = ""; switch (action) { case "getPublishListByTime": returnstr = getPublishListByTime(context); break; case "getRecordListByTime2": returnstr = getRecordListByTime2(context); break; case "getAddPublishByDate": returnstr = getAddPublishByDate(context); break; case "getPublishListByPID": returnstr = getPublishListByPID(context); break; case "getPublishListByDateRange": returnstr = getPublishListByDateRange(context); break; case "exists": returnstr = ExistsByOidPdate(context); break; case "add": returnstr = Add(context); break; case "edit": returnstr = Edit(context); break; case "del": returnstr = Del(context); break; case "expList": expList(context); break; } context.Response.Write(returnstr); } //获取公示列表 private string getPublishListByTime(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; string data = ""; int count = 0; string where = " PID = '-1' "; try { string orgId = context.Request.Params["orgId"]; string startDate = context.Request.Params["startDate"]; string endDate = context.Request.Params["endDate"]; string is_content = context.Request.Params["is_content"]; if (string.IsNullOrEmpty(orgId)) { return "{\"code\":" + code + ",\"msg\":\"所属机构不能为空\",\"data\":" + data + "}"; } if (is_content == "1") { where += " and p.org_id in (select o.org_id from fire_org o,(select get_Org_child_list('" + orgId + "') cids ) s where o.type = '0' and find_in_set(org_id,cids) ) "; } else { where += " and p.org_id = '" + orgId + "' "; } if (!string.IsNullOrEmpty(startDate)) { where += " and date_format(p.REPORT_TIME, '%Y-%m-%d') >= date_format('" + startDate + "-01', '%Y-%m-%d') "; } if (!string.IsNullOrEmpty(endDate)) { where += " and date_format(p.REPORT_TIME, '%Y-%m-%d') < date_format('" + endDate + "-01', '%Y-%m-%d') "; } where += " order by REPORT_TIME desc"; DataTable dt = bll.getPublishListByTime(where); code = 0; count = dt.Rows.Count; data = FangYar.Common.JsonHelper.ToJson(dt); } catch (Exception e) { msg = "获取失败!"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "绩效公示操作请求", "获取公示列表异常:" + e); } returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\",\"count\":" + count + ",\"data\":" + data + "}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "绩效公示操作请求", "获取公示列表"); return returnstr; } //查询公示人员分数 private string getRecordListByTime2(HttpContext context) { string returnstr = ""; try { string pid = context.Request.Params["pid"]; 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 = null; if (pid != null && pid != "") { where = " pid = '" + pid + "' "; } returnstr = "{\"code\":0,\"msg\":\"\","; int count = bll.GetRecordCount(where); returnstr += "\"count\":" + count + ",\"data\":"; if (count == 0) { returnstr += "[]"; } else { where += " order by CREATIONTIME "; List list = bll.QueryList(pageIndex, pageSize, where, ""); returnstr += FangYar.Common.JsonHelper.ToJson(list); } returnstr += "}"; } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "绩效公示操作请求", "查询公示人员分数异常:" + e); } // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "绩效公示操作请求", "查询公示人员分数"); return returnstr; } //获取公示列表(公示日期) private string getAddPublishByDate(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; string data = ""; int count = 0; try { string orgId = context.Request.Params["orgId"]; string publishDate = context.Request.Params["publishDate"]; if (string.IsNullOrEmpty(orgId) || string.IsNullOrEmpty(publishDate)) { return "{\"code\":" + code + ",\"msg\":\"参数错误\",\"data\":" + data + "}"; } if (publishDate.IndexOf("-") > -1) { var startDate_s = publishDate.Split('-'); var starty = startDate_s[0]; var startm = "" + int.Parse(startDate_s[1]); var endy = starty; var endm = "" + (int.Parse(startm) + 1); if (startm == "12") { endy = "" + int.Parse(starty) + 1; endm = "1"; } string startDate = starty + '-' + (int.Parse(startm) < 10 ? "0" + startm : startm); string endDate = endy + '-' + (int.Parse(endm) < 10 ? "0" + endm : endm); DataTable dt = bll.GetAddPublishByDate(orgId, startDate + "-01", endDate + "-01"); code = 0; count = dt.Rows.Count; data = FangYar.Common.JsonHelper.ToJson(dt); } else { return "{\"code\":" + code + ",\"msg\":\"参数错误\",\"data\":" + data + "}"; } } catch (Exception e) { msg = "获取失败!"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "绩效公示操作请求", "获取公示列表(公示日期)异常:" + e); } returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\",\"count\":" + count + ",\"data\":" + data + "}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "绩效公示操作请求", "获取公示列表(公示日期)"); return returnstr; } //获取公示列表(PID) private string getPublishListByPID(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; string data = ""; int count = 0; try { string pid = context.Request.Params["pid"]; if (string.IsNullOrEmpty(pid)) { return "{\"code\":" + code + ",\"msg\":\"参数错误\",\"data\":" + data + "}"; } DataTable dt = bll.getPublishPerListByPID(pid); code = 0; count = dt.Rows.Count; data = FangYar.Common.JsonHelper.ToJson(dt); } catch (Exception e) { msg = "获取失败!"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "绩效公示操作请求", "获取公示列表(PID)异常:" + e); } returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\",\"count\":" + count + ",\"data\":" + data + "}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "绩效公示操作请求", "获取公示列表(PID)"); return returnstr; } //获取成绩列表(日期范围内的成绩总和) private string getPublishListByDateRange(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; string data = ""; int count = 0; try { string orgId = context.Request.Params["orgId"]; string startDate = context.Request.Params["startDate"]; string endDate = context.Request.Params["endDate"]; if (string.IsNullOrEmpty(orgId) || string.IsNullOrEmpty(startDate) || string.IsNullOrEmpty(endDate)) { return "{\"code\":" + code + ",\"msg\":\"参数错误\",\"data\":" + data + "}"; } DataTable dt = bll.getPublishListByDateRange(orgId, startDate + "-01", endDate + "-01"); code = 0; count = dt.Rows.Count; data = FangYar.Common.JsonHelper.ToJson(dt); } catch (Exception e) { msg = "获取失败!"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "绩效公示操作请求", "获取公示列表(日期范围内的成绩总和)异常:" + e); } returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\",\"count\":" + count + ",\"data\":" + data + "}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "绩效公示操作请求", "获取公示列表(日期范围内的成绩总和)"); return returnstr; } //根据机构ID、公示日期 判断是否存在该记录 private string ExistsByOidPdate(HttpContext context) { string ORG_ID = context.Request.Params["ORG_ID"]; string REPORT_TIME = context.Request.Params["REPORT_TIME"]; FangYar.Model.OA.OA_PERFORMANCE_PUBLISH pmodel = bll.GetModelByOrgIdAndDate(ORG_ID, REPORT_TIME); if (pmodel != null) { if (pmodel.STATE == "1") { return "{\"msg\":\"查询到【" + REPORT_TIME + "】已有公示记录!\",\"code\":2}"; } else { return "{\"msg\":\"查询到【" + REPORT_TIME + "】已有保存记录,是否替换\",\"code\":3,\"pid\":\"" + pmodel.ID + "\"}"; } } else { return "{\"msg\":\"\",\"code\":1}"; } } //添加 private string Add(HttpContext context) { int code = -1; string msg = ""; try { string publishArry = context.Request.Params["publishArry"]; string ID = Guid.NewGuid().ToString("N"); string STATE = context.Request.Params["STATE"]; string REPORT_TIME = context.Request.Params["REPORT_TIME"]; string ORG_ID = context.Request.Params["ORG_ID"]; string ORG_NAME = context.Request.Params["ORG_NAME"]; string APPEAL_DAYS = context.Request.Params["APPEAL_DAYS"]; string TITLE = context.Request.Params["TITLE"]; string PUBLISH_UID = context.Request.Params["PUBLISH_UID"]; string PUBLISH_NAME = context.Request.Params["PUBLISH_NAME"]; List ht = new List(); FangYar.Model.OA.OA_PERFORMANCE_PUBLISH modelf = new Model.OA.OA_PERFORMANCE_PUBLISH(); modelf.ID = ID; modelf.STATE = STATE; modelf.REPORT_TIME = REPORT_TIME; modelf.ORG_ID = ORG_ID; modelf.ORG_NAME = ORG_NAME; modelf.APPEAL_DAYS = APPEAL_DAYS; modelf.TITLE = TITLE; modelf.PUBLISH_UID = PUBLISH_UID; modelf.PUBLISH_NAME = PUBLISH_NAME; modelf.PID = "-1"; FangYar.Model.OA.CommonSql staModelf = bll.getInsertStaSql(modelf); ht.Add(staModelf); JArray jArray = JArray.Parse(publishArry); foreach (JObject obj in jArray) { FangYar.Model.OA.OA_PERFORMANCE_PUBLISH model = new Model.OA.OA_PERFORMANCE_PUBLISH(); model.ID = Guid.NewGuid().ToString("N"); model.USERUID = obj["USERUID"].ToString(); model.USERNAME = obj["USERNAME"].ToString(); string FRACTION_str = obj["FRACTION_SUM"].ToString(); if (!string.IsNullOrEmpty(FRACTION_str)) { model.FRACTION = decimal.Parse(FRACTION_str); } model.REPORT_TIME = REPORT_TIME; model.ORG_ID = ORG_ID; model.ORG_NAME = ORG_NAME; model.APPEAL_DAYS = APPEAL_DAYS; model.PUBLISH_UID = PUBLISH_UID; model.PUBLISH_NAME = PUBLISH_NAME; model.PID = ID; FangYar.Model.OA.CommonSql staModel = bll.getInsertStaSql(model); ht.Add(staModel); } if (FangYar.Common.MySqlHelper.ExecuteSqlTranBool(ht)) { code = 1; msg = "操作成功"; } else { code = 0; msg = "操作失败"; } } catch (Exception e) { msg = "添加失败!"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "绩效公示操作请求", "添加异常:" + e); } // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Add, "绩效公示操作请求", "添加"); return "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; } //修改 private string Edit(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string publishArry = context.Request.Params["publishArry"]; string pid = context.Request.Params["pid"]; string STATE = context.Request.Params["STATE"]; string REPORT_TIME = context.Request.Params["REPORT_TIME"]; string ORG_ID = context.Request.Params["ORG_ID"]; string ORG_NAME = context.Request.Params["ORG_NAME"]; string APPEAL_DAYS = context.Request.Params["APPEAL_DAYS"]; string TITLE = context.Request.Params["TITLE"]; string PUBLISH_UID = context.Request.Params["PUBLISH_UID"]; string PUBLISH_NAME = context.Request.Params["PUBLISH_NAME"]; List ht = new List(); //事务删除 FangYar.Model.OA.CommonSql delModel = bll.getDeleteStaSql(pid); ht.Add(delModel); FangYar.Model.OA.OA_PERFORMANCE_PUBLISH modelf = new Model.OA.OA_PERFORMANCE_PUBLISH(); modelf.ID = pid; modelf.STATE = STATE; modelf.REPORT_TIME = REPORT_TIME; modelf.ORG_ID = ORG_ID; modelf.ORG_NAME = ORG_NAME; modelf.APPEAL_DAYS = APPEAL_DAYS; modelf.TITLE = TITLE; modelf.PUBLISH_UID = PUBLISH_UID; modelf.PUBLISH_NAME = PUBLISH_NAME; modelf.PID = "-1"; FangYar.Model.OA.CommonSql staModelf = bll.getInsertStaSql(modelf); ht.Add(staModelf); //事务添加 JArray jArray = JArray.Parse(publishArry); foreach (JObject obj in jArray) { FangYar.Model.OA.OA_PERFORMANCE_PUBLISH model = new Model.OA.OA_PERFORMANCE_PUBLISH(); model.ID = Guid.NewGuid().ToString("N"); model.USERUID = obj["USERUID"].ToString(); model.USERNAME = obj["USERNAME"].ToString(); string FRACTION_str = obj["FRACTION_SUM"].ToString(); if (!string.IsNullOrEmpty(FRACTION_str)) { model.FRACTION = decimal.Parse(FRACTION_str); } model.REPORT_TIME = REPORT_TIME; model.ORG_ID = ORG_ID; model.ORG_NAME = ORG_NAME; model.APPEAL_DAYS = APPEAL_DAYS; model.PUBLISH_UID = PUBLISH_UID; model.PUBLISH_NAME = PUBLISH_NAME; model.PID = pid; FangYar.Model.OA.CommonSql staModel = bll.getInsertStaSql(model); ht.Add(staModel); } if (FangYar.Common.MySqlHelper.ExecuteSqlTranBool(ht)) { code = 1; msg = "操作成功"; } else { code = 0; msg = "操作失败"; } } catch (Exception e) { msg = e.Message; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "绩效公示操作请求", "修改异常:" + e); } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Update, "绩效公示操作请求", "修改"); return returnstr; } //删除 private string Del(HttpContext context) { int code = -1; string msg = ""; try { string id = context.Request.Params["id"]; if (bll.Delete(id)) { msg = "删除成功!"; code = 1; } else { msg = "删除失败!"; } } catch (Exception e) { msg = "删除失败!"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "绩效公示操作请求", "删除异常:" + e); } // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Delete, "绩效公示操作请求", "删除"); return "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; } //导出绩效成绩 private void expList(HttpContext context) { try { string orgId = context.Request.Params["orgId"]; string startDate = context.Request.Params["startDate"]; string endDate = context.Request.Params["endDate"]; if (!string.IsNullOrEmpty(orgId) && !string.IsNullOrEmpty(startDate) && !string.IsNullOrEmpty(endDate)) { DataTable dt = bll.expList(orgId, startDate + "-01", endDate + "-01"); if (dt.Rows.Count > 0) { System.Collections.Generic.Dictionary cellHeaders = new System.Collections.Generic.Dictionary(); cellHeaders.Add("ORG_NAME", "所属机构"); cellHeaders.Add("DEPT_NAME", "所属部门"); cellHeaders.Add("USERNAME", "姓名"); cellHeaders.Add("L_REASON", "加减分项目"); cellHeaders.Add("FRACTION", "加扣分合计"); cellHeaders.Add("FRACTION_SUM", "绩效分值"); // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "绩效公示操作请求", "导出绩效成绩"); FangYar.Common.NPOIExcelHelper.ExportByWeb(dt, null, cellHeaders, dt.Rows[0]["ORG_NAME"].ToString() + "_" + startDate + "-" + endDate + "绩效统计.xls"); } } } catch (Exception e) { // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "绩效公示操作请求", "导出绩效成绩异常:" + e); } } public bool IsReusable { get { return false; } } } }