You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

333 lines
13 KiB
Plaintext

using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web;
using BP.DA;
using BP.Sys;
using BP.Web;
using BP.Port;
using BP.En;
using BP.WF;
using BP.WF.Template;
using System.Collections;
using System.Linq;
using LitJson;
namespace BP.Cloud.HttpHandler
{
/// <summary>
/// 页面功能实体
/// </summary>
public class CCMobilePortal : BP.WF.HttpHandler.DirectoryPageBase
{
/// <summary>
/// 构造函数
/// </summary>
public CCMobilePortal()
{
}
public string Home_EditUserName()
{
string name = this.GetRequestVal("Name");
Emp emp = new Emp(WebUser.OrgNo+"_"+WebUser.No);
emp.Name = name;
emp.Update();
//更改登录人的名字.
BP.Web.WebUser.Name = name;
return "修改成功.";
}
/// <summary>
/// 修改部门名字
/// </summary>
/// <returns></returns>
public string Home_EditDeptName()
{
string name = this.GetRequestVal("Name");
Dept dept=new Dept(WebUser.FK_Dept);
dept.Name = name;
dept.Update();
//更改登录人的名字.
BP.Web.WebUser.FK_DeptName = name;
return "修改成功.";
}
/// <summary>
/// 获取首页中草稿、待办、已完成的数据
/// </summary>
/// <returns></returns>
public string Home_Init()
{
Hashtable ht = new Hashtable();
//我发起的草稿
ht.Add("Todolist_Draft", BP.WF.Dev2Interface.Todolist_Draft);
////我发起在处理的流程
ht.Add("MyStart_Runing", BP.WF.Dev2Interface.MyStart_Runing);
////我发起已完成的流程
ht.Add("MyStart_Complete", BP.WF.Dev2Interface.MyStart_Complete);
//我处理的待办数量
ht.Add("Todolist_EmpWorks", BP.WF.Dev2Interface.Todolist_EmpWorks);
return BP.Tools.Json.ToJson(ht);
}
/// <summary>
/// 获取当前用户最近使用的流程表单
/// </summary>
/// <returns></returns>
public string GetUseFlowByUserNo()
{
string sql = "";
int top = GetRequestValInt("Top");
if (top == 0) top=8;
switch (BP.Difference.SystemConfig.AppCenterDBType)
{
case DBType.MSSQL:
sql = " SELECT TOP "+top+ " FK_Flow,FlowName,F.Icon FROM WF_GenerWorkFlow G ,WF_Flow F WHERE F.No=G.FK_Flow AND Starter='" + WebUser.No+ "' GROUP BY FK_Flow,FlowName,ICON ORDER By Max(SendDT) DESC";
break;
case DBType.MySQL:
case DBType.PostgreSQL:
case DBType.UX:
sql = " SELECT DISTINCT FK_Flow,FlowName,F.Icon FROM WF_GenerWorkFlow G ,WF_Flow F WHERE F.No=G.FK_Flow AND Starter='" + WebUser.No + "' Order By SendDT limit "+top;
break;
case DBType.Oracle:
case DBType.DM:
case DBType.KingBaseR3:
case DBType.KingBaseR6:
sql = " SELECT * From (SELECT DISTINCT FK_Flow as \"FK_Flow\",FlowName as \"FlowName\",F.Icon ,max(SendDT) SendDT FROM WF_GenerWorkFlow G ,WF_Flow F WHERE F.No=G.FK_Flow AND Starter='" + WebUser.No + "' GROUP BY FK_Flow,FlowName,ICON Order By SendDT) WHERE rownum <="+top;
break;
default:
throw new Exception("err@系统暂时还未开发使用"+BP.Difference.SystemConfig.AppCenterDBType+"数据库");
}
DataTable dt = DBAccess.RunSQLReturnTable(sql);
return BP.Tools.Json.ToJson(dt);
}
/// <summary>
/// 获取当前用户 待处理,已处理,抄送给的消息
/// </summary>
/// <returns></returns>
public string GetGenerWorks()
{
DataSet ds = new DataSet();
//待办列表
DataTable dt = BP.WF.Dev2Interface.DB_GenerEmpWorksOfDataTable(WebUser.No, 0);
dt.TableName = "Todolist";
ds.Tables.Add(dt);
//获取审批过未完成的
dt = new DataTable();
dt = BP.Cloud.Dev2Interface.DB_GenerRuningNotMyStart(WebUser.No);
dt.TableName = "Running";
ds.Tables.Add(dt);
//获取完成的
dt = new DataTable();
dt = BP.Cloud.Dev2Interface.DB_FlowCompleteNotMyStart(WebUser.No);
dt.TableName = "Complte";
ds.Tables.Add(dt);
//获取抄送当前登陆人的列表
dt = new DataTable();
dt = BP.WF.Dev2Interface.DB_CCList();
dt.TableName = "CC";
ds.Tables.Add(dt);
//返回json格式
return BP.Tools.Json.DataSetToJson(ds);
}
/// <summary>
/// 获取当前用户发起流程的草稿,处理中,已完成的数据
/// </summary>
/// <returns></returns>
public string GetMyStartGenerWorks()
{
DataSet ds = new DataSet();
//流程处理中的
//DataTable dt = BP.WF.Dev2Interface.DB_GenerRuning(WebUser.No, null, true);
DataTable dt = BP.Cloud.Dev2Interface.DB_GenerRuning(WebUser.No,null, true, this.Domain);
dt.TableName = "Running";
ds.Tables.Add(dt);
//流程已完成
dt = BP.WF.Dev2Interface.DB_FlowComplete(WebUser.No, true);
dt.TableName = "Complete";
ds.Tables.Add(dt);
//获取草稿中的流程
dt = BP.WF.Dev2Interface.DB_GenerDraftDataTable();
dt.TableName = "Draflist";
ds.Tables.Add(dt);
return BP.Tools.Json.DataSetToJson(ds);
}
/// <summary>
/// 查询流程的
/// </summary>
/// <returns></returns>
public string Search_Init()
{
DataSet ds = new DataSet();
GenerWorkFlows gwfs = new GenerWorkFlows();
QueryObject qo = new QueryObject(gwfs);
//关键字查询
string keyWord = this.GetRequestVal("SearchKey");
//流程状态
string wfstate = this.GetRequestVal("WFState");
if (DataType.IsNullOrEmpty(wfstate) == true)
qo.AddWhere(GenerWorkFlowAttr.WFState, "!=", 0);
else
qo.AddWhere(GenerWorkFlowAttr.WFState, int.Parse(wfstate));
//查询我发起的,我参与的
qo.addAnd();
qo.addLeftBracket();
qo.AddWhere(GenerWorkFlowAttr.StarterName, WebUser.No);
qo.addOr();
qo.AddWhere(GenerWorkFlowAttr.Emps, "like", "'%@" + WebUser.No + "@%'");
qo.addOr();
qo.AddWhere(GenerWorkFlowAttr.Emps, "like", "'%@" + WebUser.No + ",%'");
qo.addRightBracket();
if (DataType.IsNullOrEmpty(keyWord) == false)
{
qo.addAnd();
//模糊查询流程标题,流程名称,发起人,处理人
qo.addLeftBracket();
if (BP.Difference.SystemConfig.AppCenterDBVarStr == "@" || BP.Difference.SystemConfig.AppCenterDBVarStr == "?")
qo.AddWhere(GenerWorkFlowAttr.Title, " LIKE ", BP.Difference.SystemConfig.AppCenterDBType == DBType.MySQL ? (" CONCAT('%'," + BP.Difference.SystemConfig.AppCenterDBVarStr + "SKey, '%')") : (" '%'+" + BP.Difference.SystemConfig.AppCenterDBVarStr + "SKey+'%'"));
else
qo.AddWhere(GenerWorkFlowAttr.Title, " LIKE ", " '%'||" + BP.Difference.SystemConfig.AppCenterDBVarStr + "SKey|| '%'");
qo.addOr();
if (BP.Difference.SystemConfig.AppCenterDBVarStr == "@" || BP.Difference.SystemConfig.AppCenterDBVarStr == "?")
qo.AddWhere(GenerWorkFlowAttr.FlowName, " LIKE ", BP.Difference.SystemConfig.AppCenterDBType == DBType.MySQL ? (" CONCAT('%'," + BP.Difference.SystemConfig.AppCenterDBVarStr + "SKey, '%')") : (" '%'+" + BP.Difference.SystemConfig.AppCenterDBVarStr + "SKey+'%'"));
else
qo.AddWhere(GenerWorkFlowAttr.FlowName, " LIKE ", " '%'||" + BP.Difference.SystemConfig.AppCenterDBVarStr + "SKey|| '%'");
//qo.addOr();
//if (BP.Difference.SystemConfig.AppCenterDBVarStr == "@" || BP.Difference.SystemConfig.AppCenterDBVarStr == "?")
// qo.AddWhere(GenerWorkFlowAttr.Emps, " LIKE ", BP.Difference.SystemConfig.AppCenterDBType == DBType.MySQL ? (" CONCAT('%'," + BP.Difference.SystemConfig.AppCenterDBVarStr + "SKey, '%')") : (" '%'+" + BP.Difference.SystemConfig.AppCenterDBVarStr + "SKey+'%'"));
//else
// qo.AddWhere(GenerWorkFlowAttr.Emps, " LIKE ", " '%'||" + BP.Difference.SystemConfig.AppCenterDBVarStr + "SKey|| '%'");
qo.MyParas.Add("SKey", keyWord);
qo.addRightBracket();
}
//时间段查询
int tspan = this.GetRequestValInt("TSpan");
if (tspan != 3)
{
qo.addAnd();
qo.AddWhere(GenerWorkFlowAttr.TSpan, tspan);
}
//发起时间
string dtFrom = this.GetRequestVal("DTFrom");
string dtTo = this.GetRequestVal("DTTo");
if (DataType.IsNullOrEmpty(dtFrom) == true && DataType.IsNullOrEmpty(dtTo)==false)
{
qo.addAnd();
qo.addLeftBracket();
qo.SQL = GenerWorkFlowAttr.SendDT + " <= '" + dtTo + "'";
qo.addRightBracket();
}
else if (DataType.IsNullOrEmpty(dtFrom) == false && DataType.IsNullOrEmpty(dtTo) == true)
{
qo.addAnd();
qo.addLeftBracket();
qo.SQL = GenerWorkFlowAttr.SendDT + " >= '" + dtFrom + "'";
qo.addRightBracket();
}
else if (DataType.IsNullOrEmpty(dtFrom) == false && DataType.IsNullOrEmpty(dtTo) == false)
{
qo.addAnd();
qo.addLeftBracket();
dtTo += " 23:59:59";
qo.SQL = GenerWorkFlowAttr.SendDT + " >= '" + dtFrom + "'";
qo.addAnd();
qo.SQL = GenerWorkFlowAttr.SendDT + " <= '" + dtTo + "'";
qo.addRightBracket();
}
//增加当前用户所在的组织
qo.addAnd();
qo.AddWhere(GenerWorkFlowAttr.OrgNo, WebUser.OrgNo);
qo.DoQuery();
DataTable dt = gwfs.ToDataTableField("WF_GenerWorkFlows");
ds.Tables.Add(dt);
dt = new DataTable("Todolist_EmpWorks");
dt.Columns.Add("EmpWorks");
DataRow dr = dt.NewRow();
dr["EmpWorks"] = BP.WF.Dev2Interface.Todolist_EmpWorks;
dt.Rows.Add(dr);
ds.Tables.Add(dt);
return BP.Tools.Json.ToJson(ds);
}
public string JS_SDK_Signature()
{
string htmlPage = this.GetRequestVal("htmlPage");
Hashtable ht = new Hashtable();
//生成签名的时间戳
string timestamp = DateTime.Now.ToString("yyyyMMDDHHmmss");
//生成签名的随机串
string nonceStr = BP.DA.DBAccess.GenerGUID();
string url1 = htmlPage;
//获取 AccessToken CorpID
string url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx5c371647cecd1db2&secret=d9db5f92622436dde57bf254b1664ac3";
string res = new HttpWebResponseUtility().HttpResponseGet(url);
JsonData jd = JsonMapper.ToObject(res);
if (res.Contains("errcode") == true)
{
Object errcode = jd["errcode"];
if (errcode != null)
throw new Exception("err@获取token信息失败");
}
string access_token = (string)jd["access_token"];
//获取jsapi_ticket
url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + access_token + "&type=jsapi";
res = new HttpWebResponseUtility().HttpResponseGet(url);
jd = JsonMapper.ToObject(res);
if (res.Contains("errcode") == true)
{
string errcode1 = jd["errcode"].ToString();
if (errcode1.Equals("0") == false)
throw new Exception("err@获取jsapi_ticket失败");
}
string ticket = (string)jd["ticket"];
ht.Add("timestamp", timestamp);
ht.Add("nonceStr", nonceStr);
//企业微信的corpID
ht.Add("AppID", "wx5c371647cecd1db2");
//生成签名算法
string str1 = "jsapi_ticket=" + ticket + "&noncestr=" + nonceStr + "&timestamp=" + timestamp + "&url=" + url1 + "";
ht.Add("signature", BP.WF.Difference.Glo.Sha1Signature(str1));
ht.Add("str", str1);
return BP.Tools.Json.ToJson(ht);
}
}
}