using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using FangYar.Common;
namespace FangYar.WebUI.ashx
{
///
/// SysEmpMoveHandle 人员信息调整审核表
///
public class SysEmpMoveHandle : IHttpHandler
{
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 "list":
returnstr = getEmpMoveList(context);
break;
case "approval":
returnstr = approval(context);
break;
case "getModelById":
returnstr = getModelById(context);
break;
}
context.Response.Write(returnstr);
}
private string getEmpMoveList(HttpContext context)
{
string returnstr = "";
try
{
string userUid = context.Request.Params["userUid"];
string empId = context.Request.Params["empId"];
string isAdmin = context.Request.Params["isAdmin"];
string orgId = context.Request.Params["orgId"];
string cacheType = context.Request.Params["cacheType"];
string sTime = context.Request.Params["sTime"];
string eTime = context.Request.Params["eTime"];
string approvalRank = context.Request.Params["approvalRank"];
string sql = "select c.CACHE_REMARK,c.PC_CODE,c.PC_FILE_NAME,c.PC_FILE_URL,c.id as cid,c.USERS_UID,c.EMP_NAME,c.IDNUMBER,(select o.org_name from fire_org o where o.org_id = c.org_id) org_name,(select o.org_name from fire_org o where o.org_id = c.new_org_id) new_org_name,m.id as mid,m.APPROVAL_RANK,m.SENDERTIME,c.Cache_Type from tbl_sys_emp_move m left join tbl_sys_emp_cache c on m.INSTANCEID = c.ID where ";
sql += " m.OP_STATUS = '0'";
if (!string.IsNullOrEmpty(approvalRank))
{
sql += " and m.APPROVAL_RANK = '" + approvalRank + "'";
}
else
{
returnstr = "{\"code\":-1,\"msg\":\"查询信息有误!\",\"count\":0,\"data\":[]}";
}
if (isAdmin == "1")
{
sql += " and m.RECEIVE_ORG_ID = '" + orgId + "'";
}
else
{
sql += " and m.RECEIVEID = '" + empId + "'";
}
if (!string.IsNullOrEmpty(cacheType))
{
sql += " and c.Cache_Type = '" + cacheType + "'";
}
if (!string.IsNullOrEmpty(sTime) && !string.IsNullOrEmpty(eTime))
{
sql += " and m.SENDERTIME >= '" + sTime + " 00:00:00' and SENDERTIME <= '" + eTime + " 23:59:59'";
}
sql += " ORDER BY SENDERNAME DESC ";
DataTable dt = FangYar.Common.MySqlHelper.QueryTable(sql);
returnstr = "{\"code\":0,\"msg\":\"操作成功!\",\"data\":";
returnstr += FangYar.Common.JsonHelper.ToJson(dt);
returnstr += "}";
}
catch (Exception e)
{
returnstr = "{\"code\":-1,\"msg\":\"" + e.Message + "\",\"count\":0,\"data\":[]}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "人员审核操作请求", "查询异常:" + e);
}
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "人员审核操作请求", "查询");
return returnstr;
}
///
/// 信息处理
///
///
///
private string approval(HttpContext context)
{
string returnstr = "";
try
{
string cid = context.Request.Params["cid"];
string mid = context.Request.Params["mid"];
string userUid = context.Request.Params["userUid"];
string empId = context.Request.Params["empId"];
string userName = context.Request.Params["userName"];
string completedTime = DateTime.Now.ToString();
string opComment = context.Request.Params["opComment"];
//信息类型
string opStatus = context.Request.Params["opStatus"];
string nextStepUid = context.Request.Params["nextStepUid"];
string nextStepName = context.Request.Params["nextStepName"];
string nextStepOrgId = context.Request.Params["nextStepOrgId"];
string nextStepOrgName = context.Request.Params["nextStepOrgName"];
string orgId = context.Request.Params["orgId"];
string orgName = context.Request.Params["orgName"];
string cacheType = context.Request.Params["cacheType"];
string empName = context.Request.Params["empName"];
Boolean isAgree = false, isSubmit = false;
string cacheState = "0";
List ht = new List();
string upOpStatus = "2";
switch (opStatus)
{
case "1":// 提交上级处理
isSubmit = true;
cacheState = "1";
break;
case "2":// 同意
isAgree = true;
cacheState = "2";
break;
case "3":// 不同意
upOpStatus = "3";
cacheState = "3";
break;
default:
break;
}
FangYar.Model.OA.CommonSql currentStepSql = new FangYar.Model.OA.CommonSql();
currentStepSql.sql = "update tbl_sys_emp_move set COMPLETEDID = '" + empId + "',COMPLETEDNAME = '" + userName + "',COMPLETEDTIME = '" + completedTime + "',OP_COMMENT = '" + opComment + "',OP_STATUS = '" + upOpStatus + "' where ID = '" + mid + "' ";// 当前步骤办结
ht.Add(currentStepSql);
if (isSubmit)
{
string newMid = Guid.NewGuid().ToString("N");
FangYar.Model.OA.CommonSql nextStepSql = new FangYar.Model.OA.CommonSql();
nextStepSql.sql = "insert into tbl_sys_emp_move(ID,INSTANCEID,APPROVAL_RANK,SENDERID,SENDERNAME,SEND_ORG_ID,SEND_ORG_NAME,SENDERTIME,RECEIVEID,RECEIVENAME,RECEIVE_ORG_ID,RECEIVE_ORG_NAME,OP_STATUS,Cache_Type) values ('" + newMid + "','" + cid + "','1','" + empId + "','" + userName + "','" + orgId + "','" + orgName + "','" + completedTime + "','" + nextStepUid + "','" + nextStepName + "','" + nextStepOrgId + "','" + nextStepOrgName + "','0','" + cacheType + "')";// 下一步骤生成
ht.Add(nextStepSql);
}
if (isAgree)
{
FangYar.Model.OA.CommonSql empSql = new FangYar.Model.OA.CommonSql();
FangYar.Model.OA.CommonSql userSql = new FangYar.Model.OA.CommonSql();
switch (cacheType)
{
case "1":// 新增
empSql.sql = "insert into tbl_sys_emp (ID,USERS_UID,EMP_NAME,EMP_NUM,EMP_SEX,ORG_ID,DEPT_ID,EMP_EMAIL,EMP_MOBILE,IS_DEL,IDNUMBER,FIRE_PRO,CERT,NATION,FACE,MAR,IS_WORK,PROF,POL,PHOTO,IS_LEADER,ENLISTED_TIME,IS_ACCESS,DURING_ACCESS_PERIOD,ISDRIVER,FILENUM,PERMISSIONNUM,FIRSTCARD,EFFECTIVETIME,PERMITTEDORGAN,BIRTHDAY,FAMILYADDR,ALL_ANNUAL_LEAVE,AVAILABLE_ANNUAL_LEAVE,CID,POSTS,TAGS,IS_TRAIN,IS_ADMIN,IS_ADMIN_DB,TAGS_BAK,createtime,IS_VISITOR_CHECK,OPENID,DURING_ACCESS_PERIOD2,ACCESSALLOWEDMODE,IS_SUBCAMPVIDEO,ADMIN_LEVEL,BLOOD_TYPE) select ID,USERS_UID,EMP_NAME,EMP_NUM,EMP_SEX,ORG_ID,DEPT_ID,EMP_EMAIL,EMP_MOBILE,IS_DEL,IDNUMBER,FIRE_PRO,CERT,NATION,FACE,MAR,IS_WORK,PROF,POL,PHOTO,IS_LEADER,ENLISTED_TIME,IS_ACCESS,DURING_ACCESS_PERIOD,ISDRIVER,FILENUM,PERMISSIONNUM,FIRSTCARD,EFFECTIVETIME,PERMITTEDORGAN,BIRTHDAY,FAMILYADDR,ALL_ANNUAL_LEAVE,AVAILABLE_ANNUAL_LEAVE,CID,POSTS,TAGS,IS_TRAIN,IS_ADMIN,IS_ADMIN_DB,TAGS_BAK,createtime,IS_VISITOR_CHECK,OPENID,DURING_ACCESS_PERIOD2,ACCESSALLOWEDMODE,IS_SUBCAMPVIDEO,ADMIN_LEVEL,BLOOD_TYPE from tbl_sys_emp_cache where id = '" + cid + "'";
ht.Add(empSql);
string newId = Guid.NewGuid().ToString("N");
//初始密码
var InitPassword = System.Configuration.ConfigurationManager.AppSettings["InitPassword"] + "";
if (string.IsNullOrWhiteSpace(InitPassword))
{
InitPassword = "119";
}
var UsersPwd = FangYar.Common.Md5.GetMD5String(InitPassword);
userSql.sql = "insert into tbl_sys_users(ID,USERS_UID,USERS_PWD,USERS_NAME,USERS_WEEK,USERS_TIME,USERS_STATE,USERS_EMAIL,USERS_MOBILE,ORG_ID,EMP_ID,IS_THIS,IS_SUPER) select '" + newId + "',USERS_UID,'" + UsersPwd + "',EMP_NAME,'1,2,3,4,5,6,0','00:00:00 - 23:59:59','0',EMP_EMAIL,EMP_MOBILE,ORG_ID,EMPID,'0','1,5' from tbl_sys_emp_cache where id = '" + cid + "'";
ht.Add(userSql);
break;
case "2":// 跨营区调整
empSql.sql = "update tbl_sys_emp e set e.org_id = (select new_org_id from tbl_sys_emp_cache where id = '" + cid + "'),e.dept_id = (select new_dept_id from tbl_sys_emp_cache where id = '" + cid + "') where e.id = (select empid from tbl_sys_emp_cache where id = '" + cid + "')";
ht.Add(empSql);
userSql.sql = "update tbl_sys_users u set u.org_id = (select new_org_id from tbl_sys_emp_cache where id = '" + cid + "') where u.users_uid = (select users_uid from tbl_sys_emp_cache where id = '" + cid + "')";
ht.Add(userSql);
try
{
//发件人名称
var EmailFormName = System.Configuration.ConfigurationManager.AppSettings["EmailFormName"] + "";
//收件人邮箱集合
var EmailReceiveInfo = System.Configuration.ConfigurationManager.AppSettings["EmailReceiveInfo"] + "";
//邮件标题
var EmailTitleName = System.Configuration.ConfigurationManager.AppSettings["EmailTitleName"] + "";
string sql2 = "select USERS_UID,EMP_MOBILE,EMP_NAME,o1.ORG_NAME,o2.ORG_NAME newOrgName from tbl_sys_emp_cache ec " +
" LEFT JOIN fire_org o1 on ec.ORG_ID =o1.ORG_ID LEFT JOIN fire_org o2 on o2.ORG_ID = ec.NEW_ORG_ID WHERE ec.id = '" + cid + "'";
var dt2 = FangYar.Common.MySqlHelper.QueryTable(sql2);
string bodyData = "人员调整:";
if (dt2.Rows.Count > 0)
{
bodyData += dt2.Rows[0]["EMP_NAME"] + "从营区【" + dt2.Rows[0]["ORG_NAME"] + "】调整到" + "【" + dt2.Rows[0]["newOrgName"] +
"】手机号【" + dt2.Rows[0]["EMP_MOBILE"] + "】";
}
// WebCommon.EmailHelp.SendEmail(new WebCommon.EmailMo() { BodyData = bodyData, FormName = EmailFormName, ReceiveInfo = EmailReceiveInfo, TitleName = EmailTitleName });
}
catch (Exception ex) { }
//调用ICC人员信息处理功能
try
{
string sqlQuery = " select empid from tbl_sys_emp_cache where id = '" + cid + "' ";
var dt = FangYar.Common.MySqlHelper.QueryTable(sqlQuery);
var eid = dt.Rows[0]["empid"] + "";
///调用人员一键删除功能
EmpSyncIccHelper.EmpImgDel(eid);
System.Threading.Thread.Sleep(1000 * 5);
///调用人员一键新增功能
EmpSyncIccHelper.EmpInfoAdd(eid);
}
catch (Exception ex)
{
}
break;
case "3":// 删除
empSql.sql = "update tbl_sys_emp e set e.IS_DEL = '1' where e.id = (select empid from tbl_sys_emp_cache where id = '" + cid + "')";
ht.Add(empSql);
userSql.sql = "update tbl_sys_users u set u.users_state = '9' where u.users_uid = (select users_uid from tbl_sys_emp_cache where id = '" + cid + "')";
ht.Add(userSql);
//调用ICC人员信息处理功能
try
{
///调用人员一键删除功能
EmpSyncIccHelper.EmpImgDel(cid);
}
catch (Exception ex)
{
}
break;
}
}
FangYar.Model.OA.CommonSql cacheSql = new FangYar.Model.OA.CommonSql();
cacheSql.sql = "update tbl_sys_emp_cache set Cache_State = '" + cacheState + "' where id = '" + cid + "'";// 修改临时表状态
ht.Add(cacheSql);
if (FangYar.Common.MySqlHelper.ExecuteSqlTranBool(ht))
{
returnstr = "{\"code\":0,\"msg\":\"" + empName + ":操作成功!\"}";
}
else
{
returnstr = "{\"code\":-1,\"msg\":\"操作失败!\"}";
}
}
catch (Exception e)
{
returnstr = "{\"code\":-1,\"msg\":\"" + e.Message + "\",\"count\":0,\"data\":[]}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "人员审核操作请求", "审批异常:" + e);
}
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "人员审核操作请求", "审批");
return returnstr;
}
private string getModelById(HttpContext context)
{
string returnstr = "";
try
{
string id = context.Request.Params["id"];
if (!string.IsNullOrEmpty(id))
{
string sql = "select t.*,(select o.org_name from fire_org o where o.org_id = t.org_id) org_name,(select o.org_name from fire_org o where o.org_id = t.dept_id) dept_name,(select dic_text from tbl_sys_dicdetail where mod_code = 'POLTYPE' and dic_value = t.POL) POL_NAME,(select dic_text from tbl_sys_dicdetail where mod_code = 'CERTTYPE' and dic_value = t.CERT) CERT_NAME,(select dic_text from tbl_sys_dicdetail where mod_code = 'NATIONTYPE' and dic_value = t.NATION) NATION_NAME, (select dic_text from tbl_sys_dicdetail where mod_code = 'FACETYPE' and dic_value = t.FACE) FACE_NAME,(select dic_text from tbl_sys_dicdetail where mod_code = 'MARTYPE' and dic_value = t.MAR) MAR_NAME, (select dic_text from tbl_sys_dicdetail where mod_code = 'IS_WORKTYPE' and dic_value = t.is_work) is_work_name,(select dic_text from tbl_sys_dicdetail where mod_code = 'PROFTYPE' and dic_value = t.prof) prof_name from tbl_sys_emp_cache t where id = '" + id + "'";
DataTable dt = FangYar.Common.MySqlHelper.QueryTable(sql);
returnstr = "{\"code\":0,\"msg\":\"操作成功!\",\"data\":";
returnstr += FangYar.Common.JsonHelper.ToJson(dt);
returnstr += "}";
}
else
{
returnstr = "{\"code\":-1,\"msg\":\"id不能为空!\",\"count\":0,\"data\":[]}";
}
}
catch (Exception e)
{
returnstr = "{\"code\":-1,\"msg\":\"" + e.Message + "\",\"count\":0,\"data\":[]}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "人员审核操作请求", "审批异常:" + e);
}
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "人员审核操作请求", "审批");
return returnstr;
}
public bool IsReusable
{
get
{
return false;
}
}
}
}