init commit
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Furion.FriendlyException;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using RoadFlow.Data;
|
||||
using RoadFlow.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.RoadFlowLite.Serivce.Applibrary
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 工作流字典服务
|
||||
/// </summary>
|
||||
[Route("/api/roadflow/Applibrary/")]
|
||||
[ApiDescriptionSettings("RoadFlow")]
|
||||
public class ApplibraryService : IDynamicApiController, ITransient
|
||||
{
|
||||
IApplibrary _appLibrary;
|
||||
public ApplibraryService(IApplibrary applibrary)
|
||||
{
|
||||
_appLibrary = applibrary;
|
||||
}
|
||||
/// <summary>
|
||||
/// 得到一个分类下的应用
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("GetTreeChildsJson")]
|
||||
public dynamic GetTreeChildsJson(string parentId)
|
||||
{
|
||||
|
||||
|
||||
|
||||
if (!parentId.IsGuid(out Guid parentGuid))
|
||||
{
|
||||
return new JArray();
|
||||
// return RoadFlowCommon.Tools.GetReturnJsonString(jArray: new JArray());
|
||||
}
|
||||
var apps = _appLibrary.GetListByType(parentId);
|
||||
string lang = RoadFlow.Utility.Tools.GetCurrentLanguage(Furion.App.HttpContext);
|
||||
JArray jArray = new JArray();
|
||||
foreach (var app in apps)
|
||||
{
|
||||
JObject appJson = new JObject() {
|
||||
{ "value", app.Id },
|
||||
{ "title", _appLibrary.GetLanguageTitle(app, lang) },
|
||||
};
|
||||
jArray.Add(appJson);
|
||||
}
|
||||
return jArray;
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(jArray: jArray);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
using Ewide.Core;
|
||||
using Ewide.RoadFlowLite.Utility;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Furion.FriendlyException;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using RoadFlow.Data;
|
||||
using RoadFlow.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.RoadFlowLite.Serivce.DbConnection
|
||||
{
|
||||
/// <summary>
|
||||
/// 工作流字典服务
|
||||
/// </summary>
|
||||
[Route("/api/roadflow/DbConnection/")]
|
||||
[ApiDescriptionSettings("RoadFlow")]
|
||||
public class DbConnectionService : IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly IDbConnection _dbConnection;
|
||||
private readonly ILog _log;
|
||||
private readonly IUserManager _userManager;
|
||||
public DbConnectionService(IDbConnection dbConnection,ILog log, IUserManager userManager)
|
||||
{
|
||||
_dbConnection = dbConnection;
|
||||
_log = log;
|
||||
_userManager = userManager;
|
||||
}
|
||||
/// <summary>
|
||||
/// 测试一个SQL是否正确
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("TestSql")]
|
||||
public string TestSql([FromBody] JObject args)
|
||||
{
|
||||
string connId = args.GetJsonValue("connid");
|
||||
string sql = args.GetJsonValue("sql");
|
||||
if (!connId.IsGuid(out Guid connGuid))
|
||||
{
|
||||
throw Oops.Oh("数据库连接ID错误");
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(false, localizer["ConnectionIdError"].Value);
|
||||
}
|
||||
if (sql.IsNullOrWhiteSpace())
|
||||
{
|
||||
throw Oops.Oh("测试sql为空");
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(false, localizer["TestSqlEmpty"].Value);
|
||||
}
|
||||
|
||||
string msg =_dbConnection.TestSQL(connId, sql);
|
||||
|
||||
if (msg.IsInt())
|
||||
return msg;
|
||||
else
|
||||
throw Oops.Oh(msg);
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(msg.IsInt(), msg);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("GetList")]
|
||||
public dynamic GetList()
|
||||
{
|
||||
var dbconns = _dbConnection.GetAll();
|
||||
JArray jArray = new JArray();
|
||||
foreach (var dbconn in dbconns.OrderBy(p => p.Sort))
|
||||
{
|
||||
JObject jObject = new JObject()
|
||||
{
|
||||
{ "Id", dbconn.Id },
|
||||
{ "Name", dbconn.Name },
|
||||
{ "ConnType", dbconn.ConnType },
|
||||
{ "ConnString", dbconn.ConnString },
|
||||
{ "Note", dbconn.Note },
|
||||
{ "Sort", dbconn.Sort },
|
||||
};
|
||||
jArray.Add(jObject);
|
||||
}
|
||||
return jArray;// RoadFlowCommon.Tools.GetReturnJsonString(jArray: jArray);
|
||||
}
|
||||
|
||||
[HttpGet("Get")]
|
||||
public dynamic Get(string id)
|
||||
{
|
||||
|
||||
// string id = args.GetJsonValue("id");
|
||||
if (!id.IsGuid(out Guid guid))
|
||||
{
|
||||
return new JObject();
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(jObject: new JObject());
|
||||
}
|
||||
var connModel = _dbConnection.GetOneById(id);
|
||||
if (connModel == null)
|
||||
{
|
||||
return new JObject();
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(jObject: new JObject());
|
||||
}
|
||||
return connModel.ToJObject();
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(jObject: connModel.ToJObject());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到数据类型选项
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("GetDbConnTypeOptions")]
|
||||
public dynamic GetDbConnTypeOptions()
|
||||
{
|
||||
return _dbConnection.GetConnTypeOptionsVue();//RoadFlowCommon.Tools.GetReturnJsonString(jArray: new RoadFlow.Business.DbConnection().GetConnTypeOptionsVue());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("Save")]
|
||||
|
||||
public string Save([FromBody]RoadFlow.Model.rf_dbconnection dbConnectionModel)
|
||||
{
|
||||
|
||||
string id = dbConnectionModel.Id;
|
||||
if (id.IsGuid(out Guid connId))
|
||||
{
|
||||
var oldModel = _dbConnection.GetOneById(id);
|
||||
_dbConnection.Update(dbConnectionModel);
|
||||
_log.Add("修改了数据连接-" + dbConnectionModel.Name, type: LogType.系统管理, oldContents: oldModel.ToString(), newContents: dbConnectionModel.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
dbConnectionModel.Id = GuidExtensions.NewGuid().ToString();
|
||||
_dbConnection.Add(dbConnectionModel);
|
||||
_log.Add("添加了数据连接-" + dbConnectionModel.Name,_userManager.UserId, dbConnectionModel.ToString(), LogType.系统管理);
|
||||
}
|
||||
return "保存成功";
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(true, localizer["SaveSuccess"].Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("Delete")]
|
||||
public string Delete([FromBody] JObject args)
|
||||
{
|
||||
string ids = args.GetJsonValue("ids");
|
||||
|
||||
List<RoadFlow.Model.rf_dbconnection> dbConnections = new List<RoadFlow.Model.rf_dbconnection>();
|
||||
foreach (string id in ids.Split(','))
|
||||
{
|
||||
if (!id.IsGuid(out Guid guid))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var connModel = _dbConnection.GetOneById(id);
|
||||
if (null == connModel)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
dbConnections.Add(connModel);
|
||||
}
|
||||
_dbConnection.Delete(dbConnections);
|
||||
_log.Add("删除了数据连接", _userManager.UserId,dbConnections.Serialize(), LogType.系统管理);
|
||||
return "共计删除了 " + dbConnections.Count + " 条";
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(true, localizer["TotalDelete"].Value + dbConnections.Count.ToString() + localizer["DeleteItems"].Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试一个连接是否正确
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("TestConn")]
|
||||
|
||||
public string TestConn(string connId)
|
||||
{
|
||||
|
||||
if (!connId.IsGuid(out Guid connGuid))
|
||||
{
|
||||
throw Oops.Oh("连接ID错误");
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(false, localizer["ConnectionIdError"].Value);
|
||||
}
|
||||
string msg = _dbConnection.TestConnection(connId, null);// localizer);
|
||||
if (msg == "1")
|
||||
return "连接成功";
|
||||
else
|
||||
throw Oops.Oh(msg);
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString("1".Equals(msg), "1".Equals(msg) ? localizer["ConnSuccess"].Value : msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,690 @@
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using RoadFlow.Utility;
|
||||
using Furion;
|
||||
using RoadFlow.Data;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Ewide.RoadFlowLite.Utility;
|
||||
using Furion.FriendlyException;
|
||||
using Ewide.Core;
|
||||
|
||||
namespace Ewide.RoadFlowLite.Serivce.Dictionary
|
||||
{
|
||||
/// <summary>
|
||||
/// 工作流字典服务
|
||||
/// </summary>
|
||||
[Route("/api/roadflow/Dictionary/")]
|
||||
[ApiDescriptionSettings("RoadFlow")]
|
||||
public class DictionaryService : IDictionaryService, IDynamicApiController, ITransient
|
||||
{
|
||||
|
||||
private readonly IDictionary _repo;
|
||||
private readonly ILog _log;
|
||||
private readonly IUserManager _userManager;
|
||||
public DictionaryService(IDictionary repo ,ILog log, IUserManager userManager)
|
||||
{
|
||||
_repo = repo;
|
||||
_log = log;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据字典树
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("GetTreeJson")]
|
||||
[AllowAnonymous]
|
||||
public async Task<dynamic> GetTreeJson([FromBody] JObject args)
|
||||
{
|
||||
string rootId = (string)args["rootid"];
|
||||
bool showRoot = ((string)args["showroot"]).IsNullOrWhiteSpace() || "1".Equals((string)args["showroot"]);//是否显示根节点
|
||||
bool isEle = "1".Equals((string)args["isele"]);//是否是ELE,ELE只返回根一级,返回两级
|
||||
rootId = rootId.IsGuid(out Guid rid) ? rootId : _repo.GetIdByCode(rootId);
|
||||
var dict = string.IsNullOrWhiteSpace(rootId) ? _repo.GetRoot() : _repo.GetOneById(rootId);
|
||||
if (dict == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
string language = RoadFlow.Utility.Tools.GetCurrentLanguage(App.HttpContext);
|
||||
|
||||
JArray jArray = new JArray();
|
||||
JObject rootJson = new JObject
|
||||
{
|
||||
{ "id", dict.Id },
|
||||
{ "parentId", dict.ParentId },
|
||||
{ "title", _repo.GetLanguageTitle(dict, language) },
|
||||
{ "open", true },
|
||||
{ "current", false },
|
||||
{ "ico", "icon-wallet" },
|
||||
{ "code", dict.Code },
|
||||
{ "value", dict.Value },
|
||||
{ "note", dict.Note },
|
||||
{ "other", dict.Other },
|
||||
{ "status", dict.Status },
|
||||
{ "slots", new JObject() { { "icon", "custom" } } }
|
||||
};
|
||||
JArray childsArray = new JArray();
|
||||
var dictChilds = _repo.GetChilds(dict.Id);
|
||||
if (!isEle)
|
||||
{
|
||||
foreach (var dictChild in dictChilds)
|
||||
{
|
||||
JObject dictJson = new JObject
|
||||
{
|
||||
{ "id", dictChild.Id },
|
||||
{ "parentId", dictChild.ParentId },
|
||||
{ "title", _repo.GetLanguageTitle(dictChild, language) },
|
||||
{ "current", false },
|
||||
{ "ico", "" },
|
||||
{ "code", dictChild.Code },
|
||||
{ "value", dictChild.Value },
|
||||
{ "note", dictChild.Note },
|
||||
{ "other", dictChild.Other },
|
||||
{ "status", dictChild.Status },
|
||||
{ "slots", new JObject() { { "icon", "custom" } } }
|
||||
};
|
||||
if (_repo.HasChilds(dictChild.Id))
|
||||
{
|
||||
dictJson.Add("open", false);
|
||||
dictJson.Add("childs", new JArray());
|
||||
dictJson.Add("isLeaf", false);
|
||||
}
|
||||
else
|
||||
{
|
||||
dictJson.Add("isLeaf", true);
|
||||
}
|
||||
childsArray.Add(dictJson);
|
||||
}
|
||||
}
|
||||
rootJson.Add("childs", childsArray);
|
||||
rootJson.Add("isLeaf", dictChilds.Count == 0);
|
||||
jArray.Add(rootJson);
|
||||
|
||||
return showRoot ? jArray : childsArray;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("GetTreeChildsJson")]
|
||||
|
||||
public dynamic GetTreeChildsJson(string parentid)
|
||||
{
|
||||
string parentGuid = parentid;//(string)args["parentid"];
|
||||
var dictChilds = _repo.GetChilds(parentGuid);
|
||||
JArray jArray = new JArray();
|
||||
foreach (var dictChild in dictChilds)
|
||||
{
|
||||
JObject dictJson = new JObject() {
|
||||
{ "id", dictChild.Id },
|
||||
{ "parentId", dictChild.ParentId },
|
||||
{ "title", dictChild.Title },
|
||||
{ "current", false },
|
||||
{ "ico", "" },
|
||||
{ "code", dictChild.Code },
|
||||
{ "value", dictChild.Value },
|
||||
{ "note", dictChild.Note },
|
||||
{ "other", dictChild.Other },
|
||||
{ "status", dictChild.Status },
|
||||
{ "slots", new JObject() { { "icon", "custom" } } }
|
||||
};
|
||||
if (_repo.HasChilds(dictChild.Id))
|
||||
{
|
||||
dictJson.Add("open", false);
|
||||
dictJson.Add("childs", new JArray());
|
||||
dictJson.Add("isLeaf", false);
|
||||
}
|
||||
else
|
||||
{
|
||||
dictJson.Add("isLeaf", true);
|
||||
}
|
||||
jArray.Add(dictJson);
|
||||
}
|
||||
return jArray;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据值得到标题
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("GetText")]
|
||||
//[ApiValidate]
|
||||
public dynamic GetText([FromBody] JObject args)
|
||||
{
|
||||
string value = (string)args["value"];
|
||||
JArray jArray = new JArray();
|
||||
|
||||
foreach (string val in value.Split(','))
|
||||
{
|
||||
if (!val.IsGuid(out Guid vId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
jArray.Add(new JObject() { { "value", val }, { "title", _repo.GetTitle(val, "") } });
|
||||
}
|
||||
|
||||
return jArray;
|
||||
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("hello")]
|
||||
[AllowAnonymous]
|
||||
public dynamic Hello()
|
||||
{
|
||||
string hello = "hello".DESEncrypt();
|
||||
return hello+":"+hello.DESDecrypt();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// antd版获取字典树json
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("GetTreeJsonEle")]
|
||||
public dynamic GetTreeJsonEle(string rootId, string showroot)
|
||||
{
|
||||
|
||||
bool showRoot = showroot.IsNullOrEmpty() || showroot == "1";//是否显示根节点
|
||||
string rootGuid = rootId.IsGuid() ? rootId : _repo.GetIdByCode(rootId.Trim());
|
||||
var dict = rootGuid.IsNullOrEmpty() ? _repo.GetRoot() : _repo.GetOneById(rootGuid);
|
||||
if (dict == null)
|
||||
{
|
||||
return new JArray();
|
||||
// return RoadFlowCommon.Tools.GetReturnJsonString(jArray: new JArray());
|
||||
}
|
||||
string language = RoadFlow.Utility.Tools.GetCurrentLanguage(Furion.App.HttpContext);
|
||||
|
||||
JArray jArray = new JArray();
|
||||
JObject rootJson = new JObject
|
||||
{
|
||||
{ "id", dict.Id },
|
||||
{ "parentId", dict.ParentId },
|
||||
{ "title", _repo.GetLanguageTitle(dict, language) },
|
||||
{ "code", dict.Code },
|
||||
{ "value", dict.Value },
|
||||
{ "note", dict.Note },
|
||||
{ "other", dict.Other },
|
||||
{ "status", dict.Status },
|
||||
};
|
||||
JArray childsArray = new JArray();
|
||||
var dictChilds = _repo.GetChilds(dict.Id);
|
||||
if (!showRoot)
|
||||
{
|
||||
foreach (var dictChild in dictChilds)
|
||||
{
|
||||
JObject dictJson = new JObject
|
||||
{
|
||||
{ "id", dictChild.Id },
|
||||
{ "parentId", dictChild.ParentId },
|
||||
{ "title", _repo.GetLanguageTitle(dictChild, language) },
|
||||
{ "code", dictChild.Code },
|
||||
{ "value", dictChild.Value },
|
||||
{ "note", dictChild.Note },
|
||||
{ "other", dictChild.Other },
|
||||
{ "status", dictChild.Status },
|
||||
};
|
||||
dictJson.Add("leaf", !_repo.HasChilds(dictChild.Id));
|
||||
childsArray.Add(dictJson);
|
||||
}
|
||||
}
|
||||
//rootJson.Add("childs", childsArray);
|
||||
rootJson.Add("leaf", dictChilds.Count == 0);
|
||||
jArray.Add(rootJson);
|
||||
return showRoot ? jArray : childsArray;
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(jArray: showRoot ? jArray : childsArray);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// antd版获取字典下级json
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("GetTreeChildsJsonEle")]
|
||||
|
||||
public dynamic GetTreeChildsJsonEle(string parentId)
|
||||
{
|
||||
|
||||
|
||||
if (!parentId.IsGuid(out Guid parentGuid))
|
||||
{
|
||||
return new JArray();
|
||||
// return RoadFlowCommon.Tools.GetReturnJsonString(jArray: new JArray());
|
||||
}
|
||||
string language = RoadFlow.Utility.Tools.GetCurrentLanguage(Furion.App.HttpContext);
|
||||
var dictChilds = _repo.GetChilds(parentId);
|
||||
JArray jArray = new JArray();
|
||||
foreach (var dictChild in dictChilds)
|
||||
{
|
||||
JObject dictJson = new JObject() {
|
||||
{ "id", dictChild.Id },
|
||||
{ "parentId", dictChild.ParentId },
|
||||
{ "title", _repo.GetLanguageTitle(dictChild, language) },
|
||||
{ "code", dictChild.Code },
|
||||
{ "value", dictChild.Value },
|
||||
{ "note", dictChild.Note },
|
||||
{ "other", dictChild.Other },
|
||||
{ "status", dictChild.Status },
|
||||
};
|
||||
dictJson.Add("leaf", !_repo.HasChilds(dictChild.Id));
|
||||
jArray.Add(dictJson);
|
||||
}
|
||||
return jArray;
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(jArray: jArray);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// antd版得到select选项
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("GetSelectOptions")]
|
||||
public dynamic GetSelectOptions([FromBody] JObject args)
|
||||
{
|
||||
string param = args.GetJsonValue("params");
|
||||
if (param.IsNullOrWhiteSpace())
|
||||
{
|
||||
return new JObject();
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(jObject: new JObject());
|
||||
}
|
||||
JArray paramArray = param.ToJArray();
|
||||
if (paramArray.IsEmptyJArray())
|
||||
{
|
||||
return new JObject();
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(jObject: new JObject());
|
||||
}
|
||||
|
||||
JObject returnObject = new JObject();
|
||||
int i = 0;
|
||||
foreach (JObject jObject in paramArray)
|
||||
{
|
||||
string id = jObject.Value<string>("id");//字典id或code
|
||||
string key = jObject.Value<string>("key");//返回json key
|
||||
string type = jObject.Value<string>("type");//类型 select(下拉选择), cascader(级联选择器)
|
||||
string valueField = jObject.Value<string>("valuefield");//值字段
|
||||
bool childs = jObject.Value<string>("childs").ToInt(0) == 1;//是否加载所有下级
|
||||
bool isRoot = jObject.Value<string>("root").ToInt(0) == 1;//是否包含根节点
|
||||
key = key.IsNullOrWhiteSpace() ? "options" + i++.ToString() : key;
|
||||
if (returnObject.ContainsKey(key))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (id.IsNullOrWhiteSpace())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (type.IsNullOrWhiteSpace())
|
||||
{
|
||||
type = "select";
|
||||
}
|
||||
if (valueField.IsNullOrWhiteSpace())
|
||||
{
|
||||
valueField = "id";
|
||||
}
|
||||
if (!id.IsGuid(out Guid guid))
|
||||
{
|
||||
guid = _repo.GetIdByCode(id).ToGuid();
|
||||
}
|
||||
string lang = RoadFlow.Utility.Tools.GetCurrentLanguage(Furion.App.HttpContext);
|
||||
if (type.EqualsIgnoreCase("select"))
|
||||
{
|
||||
JArray jArray = _repo.GetArrayOptionsByID(guid.ToString(), _repo.GetValueField(valueField), string.Empty, childs);
|
||||
returnObject.Add(key, jArray);
|
||||
}
|
||||
else if (type.EqualsIgnoreCase("cascader"))
|
||||
{
|
||||
JArray jArray = _repo.GetAllChildsArray(guid.ToString(), _repo.GetValueField(valueField), isRoot, lang);
|
||||
returnObject.Add(key, jArray);
|
||||
}
|
||||
}
|
||||
return returnObject;
|
||||
;//RoadFlowCommon.Tools.GetReturnJsonString(jObject: returnObject);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到select下拉选项
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("GetOptions")]
|
||||
public dynamic GetOptions([FromBody] JObject args)
|
||||
{
|
||||
string dictId = args.GetJsonValue("dictid");
|
||||
string childs = args.GetJsonValue("childs");
|
||||
string valueField = args.GetJsonValue("valuefield");
|
||||
string value = args.GetJsonValue("value");
|
||||
string parentValue = args.GetJsonValue("parentvalue");//上一个选择的值,联动的时候获取
|
||||
string selectParent = args.GetJsonValue("selectparent");//是否可以选择上级
|
||||
JArray optionsArray = new JArray();
|
||||
foreach (string pValue in (parentValue.IsNullOrWhiteSpace() ? dictId : parentValue).Split(','))
|
||||
{
|
||||
if (!pValue.IsGuid(out Guid dictGuid))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
JArray jArray = _repo.GetArrayOptionsByID(dictGuid.ToString(), _repo.GetValueField(valueField), value, "1".Equals(childs), "1".Equals(selectParent));
|
||||
foreach (JObject jObject in jArray)
|
||||
{
|
||||
optionsArray.Add(jObject);
|
||||
}
|
||||
}
|
||||
return optionsArray;
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(jArray: optionsArray);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到combox下拉选项
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("GetComboxOptions")]
|
||||
|
||||
public dynamic GetComboxOptions([FromBody] JObject args)
|
||||
{
|
||||
|
||||
string dictId = args.GetJsonValue("dictid");
|
||||
string childs = args.GetJsonValue("childs");
|
||||
string valueField = args.GetJsonValue("valuefield");
|
||||
string value = args.GetJsonValue("value");
|
||||
string parentValue = args.GetJsonValue("parentvalue");//上一个选择的值,联动的时候获取
|
||||
string selectParent = args.GetJsonValue("selectparent");//是否可以选择上级
|
||||
JArray optionsArray = new JArray();
|
||||
foreach (string pValue in (parentValue.IsNullOrWhiteSpace() ? dictId : parentValue).Split(','))
|
||||
{
|
||||
if (!pValue.IsGuid(out Guid dictGuid))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
JArray jArray = _repo.GetArrayComboxsByID(dictGuid.ToString(), _repo.GetValueField(valueField), value, "1".Equals(childs), "1".Equals(selectParent));
|
||||
foreach (JObject jObject in jArray)
|
||||
{
|
||||
optionsArray.Add(jObject);
|
||||
}
|
||||
}
|
||||
return optionsArray;// RoadFlowCommon.Tools.GetReturnJsonString(jArray: optionsArray);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到单选按钮组选项
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("GetRadioOrCheckboxItems")]
|
||||
public dynamic GetRadioOrCheckboxItems([FromBody] JObject args)
|
||||
{
|
||||
|
||||
string dictId = args.GetJsonValue("dictid");
|
||||
string valueField = args.GetJsonValue("valuefield");
|
||||
JArray jArray = _repo.GetRadioOrCheckboxItems(dictId, _repo.GetValueField(valueField));
|
||||
return jArray;
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(jArray: jArray);
|
||||
}
|
||||
/*
|
||||
/// <summary>
|
||||
/// 根据值得到标题
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("GetText")]
|
||||
|
||||
public dynamic GetText([FromBody] JObject args)
|
||||
{
|
||||
string value = args.GetJsonValue("value");
|
||||
JArray jArray = new JArray();
|
||||
|
||||
string lang = RoadFlow.Utility.Tools.GetCurrentLanguage(Furion.App.HttpContext);
|
||||
foreach (string val in value.Split(','))
|
||||
{
|
||||
if (!val.IsGuid(out Guid vId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
jArray.Add(new JObject() { { "value", val }, { "title", _repo.GetTitle(vId, lang) } });
|
||||
}
|
||||
return jArray;
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(jArray: jArray);
|
||||
}
|
||||
*/
|
||||
/// <summary>
|
||||
/// 验证Code是否重复
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("ValidCode")]
|
||||
|
||||
public dynamic ValidCode([FromBody] JObject args)
|
||||
{
|
||||
string id = args.GetJsonValue("id");
|
||||
int type = args.GetJsonValue("type").ToInt(1);//0保存 1保存为下级
|
||||
string code = args.GetJsonValue("value");
|
||||
if (code.IsNullOrWhiteSpace())
|
||||
{
|
||||
throw Oops.Oh("编码不能为空");
|
||||
// return RoadFlowCommon.Tools.GetReturnJsonString(false, localizer["CodeEmpty"].Value);
|
||||
}
|
||||
var dictModel = _repo.GetOneById(code.Trim());
|
||||
if (dictModel == null)
|
||||
{
|
||||
return new JObject() { { "success", true }, { "msg", string.Empty } };
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(jObject: new JObject() { { "success", true }, { "msg", string.Empty } });
|
||||
}
|
||||
if (dictModel.Id == id && type == 0)
|
||||
{
|
||||
return new JObject() { { "success", true }, { "msg", string.Empty } };
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(jObject: new JObject() { { "success", true }, { "msg", string.Empty } });
|
||||
}
|
||||
return new JObject() { { "success", false }, { "msg", "编码重复" } };
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(jObject: new JObject() { { "success", false }, { "msg", localizer["CodeDuplicate"].Value } });
|
||||
}
|
||||
|
||||
[HttpGet("Get")]
|
||||
public dynamic Get(string id)
|
||||
{
|
||||
|
||||
if (!id.IsGuid(out Guid guid))
|
||||
{
|
||||
return new JObject();
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(jObject: new JObject());
|
||||
}
|
||||
var dictModel = _repo.GetOneById(id);
|
||||
if (null == dictModel)
|
||||
{
|
||||
return new JObject();
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(jObject: new JObject());
|
||||
}
|
||||
return JObject.FromObject(dictModel);
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(jObject: JObject.FromObject(dictModel));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到排序的项
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("GetSortItems")]
|
||||
public dynamic GetSortItems(string id)
|
||||
{
|
||||
|
||||
if (!id.IsGuid(out Guid dictId))
|
||||
{
|
||||
|
||||
throw Oops.Oh("ID错误");
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(false, localizer["IdError"].Value);
|
||||
}
|
||||
|
||||
var dictChilds = _repo.GetChilds(id);
|
||||
string lang = RoadFlow.Utility.Tools.GetCurrentLanguage(Furion.App.HttpContext);
|
||||
JArray jArray = new JArray();
|
||||
foreach (var dictChild in dictChilds)
|
||||
{
|
||||
JObject jObject = new JObject()
|
||||
{
|
||||
{ "id", dictChild.Id },
|
||||
{ "title", _repo.GetLanguageTitle(dictChild, lang) }
|
||||
};
|
||||
jArray.Add(jObject);
|
||||
}
|
||||
return jArray;
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(jArray: jArray);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("Save")]
|
||||
|
||||
public string Save(RoadFlow.Model.rf_dictionary dictModel)
|
||||
{
|
||||
|
||||
int type = Furion.App.HttpContext.Request.Querys("type").ToInt();
|
||||
string id = Furion.App.HttpContext.Request.Querys("id");
|
||||
//保存为下级
|
||||
if (type == 1)
|
||||
{
|
||||
dictModel.ParentId = dictModel.Id;
|
||||
dictModel.Id = GuidExtensions.NewGuid().ToString();
|
||||
dictModel.Sort = _repo.GetMaxSort(dictModel.ParentId);
|
||||
}
|
||||
//检查唯一代码
|
||||
if (!_repo.CheckCode(dictModel.Id, dictModel.Code))
|
||||
{
|
||||
throw Oops.Oh("编码重复");
|
||||
// return RoadFlowCommon.Tools.GetReturnJsonString(false, localizer["CodeDuplicate"].Value);
|
||||
}
|
||||
if (id.IsGuid(out Guid dictId) && type == 0)
|
||||
{
|
||||
var oldModel = _repo.GetOneById(id);
|
||||
_repo.Update(dictModel);
|
||||
_log.Add("修改了数据字典-" + dictModel.Title, type: LogType.系统管理, oldContents: oldModel.ToString(), newContents: dictModel.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
_repo.Add(dictModel);
|
||||
_log.Add("添加了数据字典-" + dictModel.Title,_userManager.UserId ,dictModel.ToString(),LogType.系统管理);
|
||||
}
|
||||
return "保存成功";
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(true, localizer["SaveSuccess"].Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存排序
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("SaveSort")]
|
||||
public string SaveSort([FromBody] JObject args)
|
||||
{
|
||||
|
||||
string[] ids = args.GetJsonValue("ids").Split(',');
|
||||
List<RoadFlow.Model.rf_dictionary> dictionaries = new List<RoadFlow.Model.rf_dictionary>();
|
||||
for (int i = 0; i < ids.Length; i++)
|
||||
{
|
||||
if (!ids[i].IsGuid(out Guid dictId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var dictModel = _repo.GetOneById(ids[i]);
|
||||
if (null == dictModel)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
dictModel.Sort = (i + 1) * 5;
|
||||
dictionaries.Add(dictModel);
|
||||
}
|
||||
_repo.Update(dictionaries);
|
||||
return "保存成功";
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(true, localizer["SaveSuccess"].Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("Delete")]
|
||||
|
||||
public string Delete([FromBody] JObject args)
|
||||
{
|
||||
string id = args.GetJsonValue("id");
|
||||
if (!id.IsGuid(out Guid dictId))
|
||||
{
|
||||
throw Oops.Oh("ID错误");
|
||||
// return RoadFlowCommon.Tools.GetReturnJsonString(false, localizer["IdError"].Value);
|
||||
}
|
||||
|
||||
if (id == _repo.GetRootId())
|
||||
{
|
||||
throw Oops.Oh("不能删除根对象");
|
||||
// return RoadFlowCommon.Tools.GetReturnJsonString(false, localizer["CannotDeleteRoot"].Value);
|
||||
}
|
||||
var dictModel = _repo.GetOneById(id);
|
||||
if (null == dictModel)
|
||||
{
|
||||
throw Oops.Oh("未找到字典对象");
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(false, localizer["NotFoundDict"].Value);
|
||||
}
|
||||
|
||||
var list =_repo.GetAllChilds(id,true);
|
||||
|
||||
var count = _repo.DeleteBy(x=>x.Id==id);
|
||||
count += _repo.DeleteBy(x => x.ParentId == id);
|
||||
_log.Add("删除了数据字典-共" + count + "项",_userManager.UserId ,list.Serialize(), LogType.系统管理);
|
||||
return "成功删除" + count + "条";
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(true, localizer["DeleteSuccess"].Value + dictList.Count + localizer["DeleteItems"].Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导入数据字典
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("Import")]
|
||||
|
||||
public string Import([FromBody] JObject args)
|
||||
{
|
||||
var files = args.GetJsonValue("files");
|
||||
if (files.IsNullOrWhiteSpace())
|
||||
{
|
||||
throw Oops.Oh("未选择要导入的文件");
|
||||
// return RoadFlowCommon.Tools.GetReturnJsonString(false, localizer["NoSelectImportFile"].Value);
|
||||
}
|
||||
|
||||
System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
|
||||
foreach (string file in files.Split(','))
|
||||
{
|
||||
string filePath = RoadFlow.Utility.Config.FilePath + file.DESDecrypt();
|
||||
if (!System.IO.File.Exists(filePath))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var stream = System.IO.File.OpenRead(filePath);
|
||||
int count = (int)stream.Length;
|
||||
byte[] b = new byte[count];
|
||||
stream.Read(b, 0, count);
|
||||
string json = System.Text.Encoding.UTF8.GetString(b);
|
||||
string msg = _repo.Import(json, null);//localizer);
|
||||
stream.Close();
|
||||
stream.DisposeAsync();
|
||||
try
|
||||
{
|
||||
System.IO.File.Delete(filePath);
|
||||
}
|
||||
catch (System.IO.IOException err)
|
||||
{
|
||||
_log.Add(err);
|
||||
}
|
||||
if (!"1".Equals(msg))
|
||||
{
|
||||
stringBuilder.Append(msg + ",");
|
||||
}
|
||||
}
|
||||
string msg1 = stringBuilder.ToString().TrimEnd(',');
|
||||
if (msg1.IsNullOrWhiteSpace())
|
||||
return "导入成功";
|
||||
else
|
||||
throw Oops.Oh(msg1);
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(msg1.IsNullOrWhiteSpace(), msg1.IsNullOrWhiteSpace() ? localizer["ImportSuccess"].Value : msg1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.RoadFlowLite.Serivce.Dictionary
|
||||
{
|
||||
public interface IDictionaryService
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
425
20220330_Vote/Ewide.RoadFlow/Serivce/Files/FilesService.cs
Normal file
425
20220330_Vote/Ewide.RoadFlow/Serivce/Files/FilesService.cs
Normal file
@@ -0,0 +1,425 @@
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.RoadFlowLite.Serivce.Files
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件读写
|
||||
/// </summary>
|
||||
[Route("/api/roadflow/Files/")]
|
||||
[ApiDescriptionSettings("RoadFlow")]
|
||||
public class FilesService: IDynamicApiController, ITransient
|
||||
{
|
||||
|
||||
/*
|
||||
/// <summary>
|
||||
/// 保存CKEDITOR编辑器上传的文件
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string SaveCKEditorFiles()
|
||||
{
|
||||
var files = Request.Form.Files;
|
||||
JObject jObject = new JObject();
|
||||
if (files.Count == 0)
|
||||
{
|
||||
jObject.Add("number", -1);
|
||||
jObject.Add("message", localizer["NotUploadFile"].Value);
|
||||
return new JObject() { { "error", jObject } }.ToString();
|
||||
}
|
||||
var file = files[0];
|
||||
string extName = Path.GetExtension(file.FileName).TrimStart('.');
|
||||
if (!IsUpload(extName))
|
||||
{
|
||||
jObject.Add("number", -1);
|
||||
jObject.Add("message", localizer["CannotUploadThisType"].Value);
|
||||
return new JObject() { { "error", jObject } }.ToString();
|
||||
}
|
||||
Guid userId = Current.GetUserId(Request);
|
||||
if (userId.IsEmptyGuid())
|
||||
{
|
||||
jObject.Add("number", -1);
|
||||
jObject.Add("message", localizer["UserNotLogin"].Value);
|
||||
return new JObject() { { "error", jObject } }.ToString();
|
||||
}
|
||||
DateTime date = DateExtensions.Now;
|
||||
string attachmentPath = "/files/" + userId.ToLowerString() + "/uploads/";
|
||||
string dateString = date.Year.ToString() + "/" + date.ToString("MM") + "/" + date.ToString("dd");
|
||||
string saveDir = rootPath + attachmentPath + dateString + "/";
|
||||
string fileName = file.FileName.Replace(" ", "");
|
||||
string newFileName = GetUploadFileName(saveDir, fileName);
|
||||
if (!Directory.Exists(saveDir))
|
||||
{
|
||||
Directory.CreateDirectory(saveDir);
|
||||
}
|
||||
using (FileStream fs = System.IO.File.Create(saveDir + newFileName))
|
||||
{
|
||||
file.CopyTo(fs);
|
||||
fs.Flush();
|
||||
}
|
||||
JObject jObject1 = new JObject
|
||||
{
|
||||
{ "fileName", newFileName },
|
||||
{ "uploaded", 1 },
|
||||
{ "url", (Request.IsHttps ? "https://" : "http://") + Request.Host.Value + Url.Content("~/RoadFlowWeb/Files/Show?file=") + (attachmentPath + dateString + "/" + newFileName).DESEncrypt() }
|
||||
};
|
||||
return jObject1.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存控件上传的文件
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string SaveFiles()
|
||||
{
|
||||
DateTime dateTime = DateExtensions.Now;
|
||||
string year = dateTime.ToString("yyyy");
|
||||
string month = dateTime.ToString("MM");
|
||||
string day = dateTime.ToString("dd");
|
||||
var files = Request.Form.Files;
|
||||
string filetype = Request.Forms("filetype");
|
||||
JObject jObject = new JObject();
|
||||
if (files.Count > 0)
|
||||
{
|
||||
var file = files[0];
|
||||
string extName = Path.GetExtension(file.FileName).TrimStart('.');
|
||||
if (!IsUpload(extName))
|
||||
{
|
||||
jObject.Add("error", localizer["CannotUploadThisType"].Value);
|
||||
return jObject.ToString();
|
||||
}
|
||||
if (!filetype.IsNullOrWhiteSpace() && !("," + filetype + ",").ContainsIgnoreCase("," + extName + ","))
|
||||
{
|
||||
jObject.Add("error", localizer["CannotUploadThisType"].Value);
|
||||
return jObject.ToString();
|
||||
}
|
||||
Guid userId = Current.GetUserId(Request);
|
||||
if (userId.IsEmptyGuid())
|
||||
{
|
||||
jObject.Add("error", localizer["UserNotLogin"].Value);
|
||||
return jObject.ToString();
|
||||
}
|
||||
string attachmentPath = "/files/" + userId.ToLowerString() + "/uploads/";
|
||||
string saveDir = rootPath + attachmentPath + year + "/" + month + "/" + day + "/";
|
||||
string fileName = file.FileName.Replace(" ", "");
|
||||
string newFileName = GetUploadFileName(saveDir, fileName);
|
||||
if (!Directory.Exists(saveDir))
|
||||
{
|
||||
Directory.CreateDirectory(saveDir);
|
||||
}
|
||||
using (FileStream fs = System.IO.File.Create(saveDir + newFileName))
|
||||
{
|
||||
file.CopyTo(fs);
|
||||
//fs.Flush();
|
||||
}
|
||||
jObject.Add("id", (attachmentPath + year + "/" + month + "/" + day + "/" + newFileName).DESEncrypt());
|
||||
jObject.Add("size", file.Length.ToFileSize());
|
||||
}
|
||||
return jObject.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存用户上传的签章图片
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string SaveUserSign()
|
||||
{
|
||||
var files = Request.Form.Files;
|
||||
JObject jObject = new JObject();
|
||||
if (files.Count > 0)
|
||||
{
|
||||
var file = files[0];
|
||||
string extName = Path.GetExtension(file.FileName).TrimStart('.');
|
||||
if (!IsUpload(extName))
|
||||
{
|
||||
jObject.Add("error", localizer["CannotUploadThisType"].Value);
|
||||
return jObject.ToString();
|
||||
}
|
||||
Guid userId = Current.GetUserId(Request);
|
||||
if (userId.IsEmptyGuid())
|
||||
{
|
||||
jObject.Add("error", localizer["UserNotLogin"].Value);
|
||||
return jObject.ToString();
|
||||
}
|
||||
string saveDir = Config.ContentRootPath + "/wwwroot/roadflow-files/user-signs/" + userId.ToLowerString() + "/";
|
||||
if (!Directory.Exists(saveDir))
|
||||
{
|
||||
Directory.CreateDirectory(saveDir);
|
||||
}
|
||||
using (FileStream fs = System.IO.File.Create(saveDir + "default.png"))
|
||||
{
|
||||
file.CopyTo(fs);
|
||||
fs.Flush();
|
||||
}
|
||||
jObject.Add("id", "/roadflow-files/user-signs/" + userId.ToLowerString() + "/" + "default.png?v=" + GuidExtensions.NewGuid().ToLowerNString());
|
||||
}
|
||||
return jObject.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存用户上传的头像图片
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string SaveUserHeader()
|
||||
{
|
||||
var files = Request.Form.Files;
|
||||
JObject jObject = new JObject();
|
||||
if (files.Count > 0)
|
||||
{
|
||||
var file = files[0];
|
||||
string extName = Path.GetExtension(file.FileName).TrimStart('.');
|
||||
if (!IsUpload(extName))
|
||||
{
|
||||
jObject.Add("error", localizer["CannotUploadThisType"].Value);
|
||||
return jObject.ToString();
|
||||
}
|
||||
Guid userId = Current.GetUserId(Request);
|
||||
if (userId.IsEmptyGuid())
|
||||
{
|
||||
jObject.Add("error", localizer["UserNotLogin"].Value);
|
||||
return jObject.ToString();
|
||||
}
|
||||
string saveDir = Config.ContentRootPath + "/wwwroot/roadflow-files/user-headers/" + userId.ToLowerString() + "/";
|
||||
if (!Directory.Exists(saveDir))
|
||||
{
|
||||
Directory.CreateDirectory(saveDir);
|
||||
}
|
||||
string fileName = file.FileName.Replace(" ", "");
|
||||
string newFileName = GetUploadFileName(saveDir, fileName);
|
||||
using (FileStream fs = System.IO.File.Create(saveDir + newFileName))
|
||||
{
|
||||
file.CopyTo(fs);
|
||||
fs.Flush();
|
||||
}
|
||||
jObject.Add("id", "/roadflow-files/user-headers/" + userId.ToLowerString() + "/" + newFileName + "?v=" + GuidExtensions.NewGuid().ToLowerNString());
|
||||
}
|
||||
return jObject.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存文件管理上传的文件
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
|
||||
public string SaveFileManaeFiles()
|
||||
{
|
||||
var files = Request.Form.Files;
|
||||
JObject jObject = new JObject();
|
||||
if (files.Count > 0)
|
||||
{
|
||||
var file = files[0];
|
||||
string extName = Path.GetExtension(file.FileName).TrimStart('.');
|
||||
if (!IsUpload(extName))
|
||||
{
|
||||
jObject.Add("error", localizer["CannotUploadThisType"].Value);
|
||||
return jObject.ToString();
|
||||
}
|
||||
Guid userId = Current.GetUserId(Request);
|
||||
if (userId.IsEmptyGuid())
|
||||
{
|
||||
jObject.Add("error", localizer["UserNotLogin"].Value);
|
||||
return jObject.ToString();
|
||||
}
|
||||
string dir = Request.Forms("dir").DESDecrypt();
|
||||
string saveDir = dir.IsNullOrWhiteSpace() ? rootPath + "/files/" + userId.ToLowerString() + "/files/" : dir + "/";
|
||||
string fileName = file.FileName.Replace(" ", "");
|
||||
string newFileName = GetUploadFileName(saveDir, fileName);
|
||||
if (!Directory.Exists(saveDir))
|
||||
{
|
||||
Directory.CreateDirectory(saveDir);
|
||||
}
|
||||
using (FileStream fs = System.IO.File.Create(saveDir + newFileName))
|
||||
{
|
||||
file.CopyTo(fs);
|
||||
fs.Flush();
|
||||
}
|
||||
jObject.Add("id", (saveDir + newFileName).DESEncrypt());
|
||||
jObject.Add("size", file.Length.ToFileSize());
|
||||
}
|
||||
return jObject.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查文件是否可以上传
|
||||
/// </summary>
|
||||
/// <param name="extName"></param>
|
||||
/// <returns></returns>
|
||||
private bool IsUpload(string extName)
|
||||
{
|
||||
return RoadFlow.Utility.Config.UploadFileExtNames.IsNullOrWhiteSpace()
|
||||
? !",exe,msi,bat,cshtml,html,asp,aspx,ashx,ascx,cs,dll,js,vbs,css,".ContainsIgnoreCase("," + extName + ",")
|
||||
: ("," + RoadFlow.Utility.Config.UploadFileExtNames + ",").ContainsIgnoreCase("," + extName + ",");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到上传文件名,如果重名要重新命名
|
||||
/// </summary>
|
||||
/// <param name="saveDir"></param>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
private string GetUploadFileName(string saveDir, string fileName)
|
||||
{
|
||||
if (System.IO.File.Exists(saveDir + fileName))
|
||||
{
|
||||
string extName = Path.GetExtension(fileName);
|
||||
string fName = Path.GetFileNameWithoutExtension(fileName) + "_" + Tools.GetRandomString(3).ToLower();
|
||||
return GetUploadFileName(saveDir, fName + extName);
|
||||
}
|
||||
return fileName.Replace(" ", "");//去掉文件名中的空格(LibreOffice转为pdf时文件名有空格转换不了)
|
||||
}
|
||||
|
||||
private (string, string) GetHeadType(string extName)
|
||||
{
|
||||
if (extName.IsNullOrWhiteSpace())
|
||||
{
|
||||
return ("attachment", "application/octet-stream");
|
||||
}
|
||||
string ext = extName.Trim().ToLower();
|
||||
if (",jpg,jpeg,png,gif,tif,tiff,".Contains("," + ext + ","))
|
||||
{
|
||||
return ("inline", "image/" + ("jpg".Equals(ext) ? "jpeg" : ext));
|
||||
}
|
||||
else if (",txt,inf,log,ini,conf,cnf,".Contains("," + ext + ","))
|
||||
{
|
||||
return ("inline", "text/plain;charset=gb2312");//text/plain;charset=utf-8
|
||||
}
|
||||
else if (",pdf,".Contains("," + ext + ","))
|
||||
{
|
||||
return ("inline", "application/pdf");
|
||||
}
|
||||
else if (",json,".Contains("," + ext + ","))
|
||||
{
|
||||
return ("inline", "application/json");
|
||||
}
|
||||
else if (",doc,docx,dot,".Contains("," + ext + ","))
|
||||
{
|
||||
return ("attachment", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
|
||||
}
|
||||
else if (",xls,xlsx,".Contains("," + ext + ","))
|
||||
{
|
||||
return ("attachment", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
}
|
||||
else if (",ppt,pptx,pps,pot,ppa,".Contains("," + ext + ","))
|
||||
{
|
||||
return ("attachment", "application/vnd.openxmlformats-officedocument.presentationml.presentation");
|
||||
}
|
||||
return ("attachment", "application/octet-stream");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断是否是office文件
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
private bool IsOfficeFile(string file)
|
||||
{
|
||||
string extName = Path.GetExtension(file);
|
||||
return ",.doc,.docx,.xls,.xlsx,.ppt,.pptx,.wps,.dps,.et,".ContainsIgnoreCase("," + extName + ",");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 显示文件
|
||||
/// </summary>
|
||||
[WebValidate]
|
||||
public IActionResult Show()
|
||||
{
|
||||
string fileId = Request.Querys("file");
|
||||
if (fileId.IsNullOrWhiteSpace())
|
||||
{
|
||||
fileId = Request.Querys("id");
|
||||
}
|
||||
|
||||
if (fileId.IsNullOrWhiteSpace())
|
||||
{
|
||||
return new ContentResult() { Content = "文件不存在!", ContentType = "text/html;charset=utf-8" };
|
||||
}
|
||||
string file = fileId.DESDecrypt();
|
||||
bool fullPath = "1".Equals(Request.Querys("fullpath"));//是否是完整路径(个人文件管理中传过来的路径就是文件完整路径)
|
||||
|
||||
FileInfo tmpFile = new FileInfo(fullPath ? file : rootPath + file);
|
||||
if (!tmpFile.Exists)
|
||||
{
|
||||
return new ContentResult() { Content = "文件不存在!", ContentType = "text/html;charset=utf-8" };
|
||||
}
|
||||
//检查如果路径不是规定的路径,否则不能访问
|
||||
if (fullPath && !RoadFlow.Business.UserFile.HasAccess(tmpFile.DirectoryName, Guid.Empty))
|
||||
{
|
||||
return new ContentResult() { Content = "不能访问!", ContentType = "text/html;charset=utf-8" };
|
||||
}
|
||||
|
||||
bool isDownload = "1".Equals(Request.Querys("download"));//是否是下载文件
|
||||
|
||||
#region 如果是office文件转换为pdf显示
|
||||
if (!isDownload && IsOfficeFile(file))
|
||||
{
|
||||
string tempDirectory = tmpFile.DirectoryName.Replace("\\", "/").Substring(rootPath.Replace("\\", "/").Length).TrimStart('/');
|
||||
string pdfDirectory = rootPath + "/tmpfiles/" + tempDirectory + "/";
|
||||
string pdfFileName = pdfDirectory + Path.GetFileNameWithoutExtension(tmpFile.FullName) + ".pdf";
|
||||
if (!System.IO.File.Exists(pdfFileName))
|
||||
{
|
||||
pdfFileName = RoadFlow.Utility.DocExtensions.ToPdf(tmpFile.FullName, pdfDirectory);
|
||||
if (!pdfFileName.IsNullOrWhiteSpace() && System.IO.File.Exists(pdfFileName))
|
||||
{
|
||||
tmpFile = new FileInfo(pdfFileName);
|
||||
file = pdfFileName;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tmpFile = new FileInfo(pdfFileName);
|
||||
file = pdfFileName;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
var tmpContentType = isDownload ? ("attachment", "application/octet-stream") : GetHeadType(Path.GetExtension(file).TrimStart('.'));
|
||||
string fileName = tmpFile.Name.UrlEncode();
|
||||
Response.Headers.Add("Accept-Ranges", new StringValues("bytes"));
|
||||
Response.Headers.Add("Server-FileName", new StringValues(fileName));
|
||||
//Response.Headers.Add("Content-Encoding", new StringValues("utf-8"));
|
||||
//Response.Headers.Add("Vary", new StringValues("Accept-Encoding"));
|
||||
Response.ContentType = tmpContentType.Item2;
|
||||
Response.Headers.Add("Content-Disposition", new StringValues(tmpContentType.Item1 + ";filename=" + fileName));
|
||||
Response.Headers.Add("Content-Length", new StringValues(tmpFile.Length.ToString()));
|
||||
|
||||
//using (var tmpRead = tmpFile.OpenRead())
|
||||
//{
|
||||
// var tmpByte = new byte[2048];
|
||||
// var i = tmpRead.Read(tmpByte, 0, tmpByte.Length);
|
||||
// while (i > 0)
|
||||
// {
|
||||
// Response.Body.WriteAsync(tmpByte, 0, i);
|
||||
// Response.Body.FlushAsync();
|
||||
// i = tmpRead.Read(tmpByte, 0, tmpByte.Length);
|
||||
// }
|
||||
//}
|
||||
//Response.Body.FlushAsync();
|
||||
//Response.Body.DisposeAsync();
|
||||
//return new EmptyResult();
|
||||
return File(tmpFile.OpenRead(), tmpContentType.Item2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证码
|
||||
/// </summary>
|
||||
public void ValidCode()
|
||||
{
|
||||
string guid = Request.Querys("guid");
|
||||
string bgImg = RoadFlow.Utility.Tools.GetWebRootPath() + "/vcodebg.png";
|
||||
System.IO.MemoryStream ms = RoadFlow.Utility.Tools.GetValidateImg(out string code, bgImg);
|
||||
RoadFlow.Cache.IO.Insert("rf_vue_validcode_" + guid, code, DateExtensions.Now.AddMinutes(30));
|
||||
Response.Clear();
|
||||
Response.ContentType = "image/png";
|
||||
Response.Body.WriteAsync(ms.GetBuffer(), 0, (int)ms.Length);
|
||||
Response.Body.DisposeAsync();
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
}
|
||||
}
|
||||
1280
20220330_Vote/Ewide.RoadFlow/Serivce/FlowDesign/FlowDesignSerivce.cs
Normal file
1280
20220330_Vote/Ewide.RoadFlow/Serivce/FlowDesign/FlowDesignSerivce.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,16 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.RoadFlowLite.Serivce.FlowDesign
|
||||
{
|
||||
public interface IFlowDesignService
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
3361
20220330_Vote/Ewide.RoadFlow/Serivce/FlowRun/FlowRunService.cs
Normal file
3361
20220330_Vote/Ewide.RoadFlow/Serivce/FlowRun/FlowRunService.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.RoadFlowLite.Serivce.FlowRun
|
||||
{
|
||||
public interface IFlowRunService
|
||||
{
|
||||
}
|
||||
}
|
||||
574
20220330_Vote/Ewide.RoadFlow/Serivce/Form/FormService.cs
Normal file
574
20220330_Vote/Ewide.RoadFlow/Serivce/Form/FormService.cs
Normal file
@@ -0,0 +1,574 @@
|
||||
using Ewide.Core;
|
||||
using Ewide.RoadFlowLite.Utility;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Furion.FriendlyException;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
using RoadFlow.Data;
|
||||
using RoadFlow.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.RoadFlowLite.Serivce.Form
|
||||
{
|
||||
[Route("/api/roadflow/Form/")]
|
||||
[ApiDescriptionSettings("RoadFlow")]
|
||||
public class FormService : IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly IDictionary _dic;
|
||||
private readonly ILog _log;
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly IForm _form;
|
||||
private readonly IApplibrary _appLibrary;
|
||||
public FormService( ILog log, IUserManager userManager,IForm form, IDictionary dictionary,IApplibrary applibrary)
|
||||
{
|
||||
_form = form;
|
||||
_log = log;
|
||||
_userManager = userManager;
|
||||
_dic = dictionary;
|
||||
_appLibrary = applibrary;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询表单列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("GetList")]
|
||||
public dynamic GetList([FromBody] JObject args)
|
||||
{
|
||||
string name = args.GetJsonValue("name");
|
||||
string typeId = args.GetJsonValue("type");
|
||||
int number = args.GetJsonValue("number").ToInt();
|
||||
int size = args.GetJsonValue("size").ToInt();
|
||||
string order = args.GetJsonValue("order");
|
||||
if (order.IsNullOrWhiteSpace())
|
||||
{
|
||||
order = "CreateDate DESC";
|
||||
}
|
||||
if (typeId.IsGuid(out Guid typeGuidId))
|
||||
{
|
||||
var childsId = _dic.GetAllChildsId(typeId);
|
||||
|
||||
typeId = childsId.JoinSqlIn(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
typeId = string.Empty;
|
||||
}
|
||||
string userId = _userManager.UserId;
|
||||
|
||||
var forms = _form.GetPagerList(out int total, size, number, userId, name, typeId, order);
|
||||
JArray jArray = new JArray();
|
||||
foreach (var dr in forms)
|
||||
{
|
||||
JObject jObject = new JObject()
|
||||
{
|
||||
{ "Id", dr.Id},
|
||||
{ "Name", dr.Name },
|
||||
{ "CreateDate", dr.CreateDate==null ? dr.CreateDate.ToDateTimeString() : string.Empty },
|
||||
{ "CreateUserName", dr.CreateUserName},
|
||||
};
|
||||
jArray.Add(jObject);
|
||||
}
|
||||
JObject jObject1 = new JObject
|
||||
{
|
||||
{ "total", total },
|
||||
{ "rows", jArray }
|
||||
};
|
||||
return jObject1;// RoadFlowCommon.Tools.GetReturnJsonString(jObject: jObject1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询已删除表单列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("GetRemoveList")]
|
||||
public dynamic GetRemoveList([FromBody] JObject args)
|
||||
{
|
||||
string name = args.GetJsonValue("name");
|
||||
int number = args.GetJsonValue("number").ToInt();
|
||||
int size = args.GetJsonValue("size").ToInt();
|
||||
string order = args.GetJsonValue("order");
|
||||
if (order.IsNullOrWhiteSpace())
|
||||
{
|
||||
order = "CreateDate DESC";
|
||||
}
|
||||
string userId = _userManager.UserId;
|
||||
|
||||
var forms = _form.GetPagerList(out int total, size, number, userId, name, string.Empty, order, 2);
|
||||
JArray jArray = new JArray();
|
||||
foreach (var dr in forms)
|
||||
{
|
||||
JObject jObject = new JObject()
|
||||
{
|
||||
{ "Id", dr.Id},
|
||||
{ "Name", dr.Name},
|
||||
{ "CreateDate", dr.CreateDate.ToShortDateString() },
|
||||
{ "CreateUserName", dr.CreateUserName},
|
||||
};
|
||||
jArray.Add(jObject);
|
||||
}
|
||||
JObject jObject1 = new JObject
|
||||
{
|
||||
{ "total", total },
|
||||
{ "rows", jArray }
|
||||
};
|
||||
return jObject1; //RoadFlowCommon.Tools.GetReturnJsonString(jObject: jObject1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到设计时HTML
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("GetDesignHtml")]
|
||||
|
||||
public dynamic GetDesignHtml(string formId)
|
||||
{
|
||||
|
||||
if (!formId.IsGuid(out Guid formGuid))
|
||||
{
|
||||
throw Oops.Oh("ID错误");
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(false, localizer["IdError"].Value);
|
||||
}
|
||||
var formModel = _form.GetOneById(formId);
|
||||
if (null == formModel)
|
||||
{
|
||||
throw Oops.Oh("未找到表格");
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(false, localizer["NotFoundForm"].Value);
|
||||
}
|
||||
JObject jObject = new JObject() {
|
||||
{ "success", true },
|
||||
{ "attr", formModel.attribute.ToJObject() },
|
||||
{ "html", formModel.Html },
|
||||
{ "event", formModel.EventJSON.ToJArray() },
|
||||
{ "subtable", formModel.SubtableJSON.ToJArray() }
|
||||
};
|
||||
|
||||
return jObject;//RoadFlowCommon.Tools.GetReturnJsonString(jObject: jObject);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存表单
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("Save")]
|
||||
public dynamic Save([FromBody] JObject args)
|
||||
{
|
||||
Console.WriteLine(args["attJSON"]);
|
||||
string attJSON = args.GetJsonValue("attJSON");
|
||||
string eventJSON = args.GetJsonValue("eventJSON");
|
||||
string subtableJSON = args.GetJsonValue("subtableJSON");
|
||||
string html = args.GetJsonValue("html");
|
||||
bool isNew = "1".Equals(args.GetJsonValue("isnew"));
|
||||
JObject jObject = attJSON.ToJObject();
|
||||
if (jObject.IsEmptyJObject())
|
||||
{
|
||||
throw Oops.Oh("表格属性错误");
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(false, jObject: new JObject() { { "msg", localizer["FormAttError"].Value }, { "id", "" } });
|
||||
}
|
||||
string id = jObject.Value<string>("id");
|
||||
string name = jObject.Value<string>("name");
|
||||
string formType = jObject.Value<string>("formType");
|
||||
string manageUser = jObject.Value<string>("manageUser");
|
||||
string userId = _userManager.UserId;
|
||||
if (!id.IsGuid(out Guid guid) && !isNew)
|
||||
{
|
||||
throw Oops.Oh("表格ID不能为空");
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(false, jObject: new JObject() { { "msg", localizer["FormIdCannotEmpty"].Value }, { "id", "" } });
|
||||
}
|
||||
if (name.IsNullOrWhiteSpace())
|
||||
{
|
||||
throw Oops.Oh("表格名不能为空");
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(false, jObject: new JObject() { { "msg", localizer["FormNameEmpty"].Value }, { "id", "" } });
|
||||
}
|
||||
if (!formType.IsGuid(out Guid typeId))
|
||||
{
|
||||
throw Oops.Oh("表格类型不能为空");
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(false, jObject: new JObject() { { "msg", localizer["FormTypeEmpty"].Value }, { "id", "" } });
|
||||
}
|
||||
if (manageUser.IsNullOrWhiteSpace())//如果没有指定管理者,则默认为创建人员
|
||||
{
|
||||
manageUser = IOrganize.PREFIX_USER + userId.ToString();
|
||||
}
|
||||
|
||||
var formModel = isNew ? null : _form.GetOneById(guid.ToString());
|
||||
if (null == formModel)
|
||||
{
|
||||
formModel = new RoadFlow.Model.rf_form
|
||||
{
|
||||
Id = GuidExtensions.NewGuid().ToString(),
|
||||
Status = 0,
|
||||
CreateDate = DateExtensions.Now,
|
||||
CreateUserId = userId,
|
||||
CreateUserName = _userManager.User.Name
|
||||
};
|
||||
if (jObject.ContainsKey("id"))
|
||||
{
|
||||
jObject["id"] = formModel.Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
jObject.Add("id", formModel.Id);
|
||||
}
|
||||
}
|
||||
formModel.Name = name.Trim();
|
||||
formModel.FormType = typeId.ToString();
|
||||
formModel.EventJSON = eventJSON;
|
||||
formModel.SubtableJSON = subtableJSON;
|
||||
formModel.attribute = isNew ? jObject.ToString(Newtonsoft.Json.Formatting.None) : attJSON;
|
||||
formModel.Html = html;
|
||||
formModel.EditDate = DateExtensions.Now;
|
||||
formModel.ManageUser = manageUser.ToLower();
|
||||
_ = isNew ? _form.Add(formModel) : _form.Update(formModel);
|
||||
_log.Add((isNew ? "新增" : "修改") + "了表单-" + name,_userManager.UserId, formModel.ToString(), LogType.流程管理);
|
||||
return new JObject() { { "msg","保存成功" }, { "id", formModel.Id } };
|
||||
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(true, jObject: new JObject() { { "msg", localizer["SaveSuccessfully"].Value }, { "id", formModel.Id } });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除表单(作删除标记)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("Delete")]
|
||||
public string Delete([FromBody] JObject args)
|
||||
{
|
||||
string ids = args.GetJsonValue("ids");
|
||||
foreach (string id in ids.Split(','))
|
||||
{
|
||||
if (!id.IsGuid(out Guid formId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var formModel = _form.GetOneById(id);
|
||||
if (null == formModel)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
_form.DeleteAndApplibrary(formModel, 0);
|
||||
_log.Add("删除了表单(作删除标记)-" + formModel.Name,_userManager.UserId ,formId.ToString(), LogType.流程管理);
|
||||
}
|
||||
return "删除成功";
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(true, localizer["DeleteSuccessfully"].Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 彻底删除表单
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("ThoroughDelete")]
|
||||
|
||||
public string ThoroughDelete([FromBody] JObject args)
|
||||
{
|
||||
string ids = args.GetJsonValue("ids");
|
||||
|
||||
foreach (string id in ids.Split(','))
|
||||
{
|
||||
if (!id.IsGuid(out Guid formId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var formModel = _form.GetOneById(id);
|
||||
if (null == formModel)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
_form.DeleteAndApplibrary(formModel, 1);
|
||||
_log.Add("彻底删除了表单-" + formModel.Name, _userManager.UserId,formModel.ToString(), LogType.流程管理);
|
||||
}
|
||||
return "删除成功";
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(true, localizer["DeleteSuccessfully"].Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 恢复删除表单
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Recovery")]
|
||||
|
||||
public string Recovery(string id)
|
||||
{
|
||||
|
||||
if (!id.IsGuid(out Guid formId))
|
||||
{
|
||||
throw Oops.Oh("Id错误");
|
||||
// return RoadFlowCommon.Tools.GetReturnJsonString(false, localizer["IdError"].Value);
|
||||
}
|
||||
var formModel = _form.GetOneById(id);
|
||||
if (null == formModel)
|
||||
{
|
||||
throw Oops.Oh("未找到待恢复表格");
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(false, localizer["NotFoundRecovery"].Value);
|
||||
}
|
||||
formModel.Status = 0;
|
||||
_form.Update(formModel);
|
||||
_log.Add("恢复了表单-" + formModel.Name,_userManager.UserId, formId.ToString(),LogType.流程管理);
|
||||
return "恢复成功";
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(true, localizer["RecoverySuccessfully"].Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发布表单
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("Publish")]
|
||||
public dynamic Publish([FromBody] JObject args)
|
||||
{
|
||||
string attJSON = args.GetJsonValue("attJSON");
|
||||
string eventJSON = args.GetJsonValue("eventJSON");
|
||||
string subtableJSON = args.GetJsonValue("subtableJSON");
|
||||
string html = args.GetJsonValue("html");
|
||||
string runHtml = args.GetJsonValue("runHtml");
|
||||
bool isNew = "1".Equals(args.GetJsonValue("isnew"));
|
||||
|
||||
#region 保存数据
|
||||
JObject jObject = attJSON.ToJObject();
|
||||
if (jObject.IsEmptyJObject())
|
||||
{
|
||||
throw Oops.Oh("表格属性错误");
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(false, jObject: new JObject() { { "msg", localizer["FormAttError"].Value }, { "id", "" } });
|
||||
}
|
||||
string id = jObject.Value<string>("id");
|
||||
string name = jObject.Value<string>("name");
|
||||
string formType = jObject.Value<string>("formType");
|
||||
string manageUser = jObject.Value<string>("manageUser");
|
||||
string userId = _userManager.UserId;
|
||||
if (!id.IsGuid(out Guid guid) && !isNew)
|
||||
{
|
||||
throw Oops.Oh("表格ID不能为空");
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(false, jObject: new JObject() { { "msg", localizer["FormIdCannotEmpty"].Value }, { "id", "" } });
|
||||
}
|
||||
if (name.IsNullOrWhiteSpace())
|
||||
{
|
||||
throw Oops.Oh("表格名不能为空");
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(false, jObject: new JObject() { { "msg", localizer["FormNameEmpty"].Value }, { "id", "" } });
|
||||
}
|
||||
if (!formType.IsGuid(out Guid typeId))
|
||||
{
|
||||
throw Oops.Oh("表格类型不能为空");
|
||||
// return RoadFlowCommon.Tools.GetReturnJsonString(false, jObject: new JObject() { { "msg", localizer["FormTypeEmpty"].Value }, { "id", "" } });
|
||||
}
|
||||
if (manageUser.IsNullOrWhiteSpace())//如果没有指定管理者,则默认为创建人员
|
||||
{
|
||||
manageUser = IOrganize.PREFIX_USER + userId.ToString();
|
||||
}
|
||||
|
||||
var formModel = isNew ? null : _form.GetOneById(guid.ToString());
|
||||
if (null == formModel)
|
||||
{
|
||||
formModel = new RoadFlow.Model.rf_form
|
||||
{
|
||||
Id = GuidExtensions.NewGuid().ToString(),
|
||||
Status = 0,
|
||||
CreateDate = DateExtensions.Now,
|
||||
CreateUserId = userId,
|
||||
CreateUserName = _userManager.User.Name
|
||||
};
|
||||
if (jObject.ContainsKey("id"))
|
||||
{
|
||||
jObject["id"] = formModel.Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
jObject.Add("id", formModel.Id);
|
||||
}
|
||||
}
|
||||
formModel.Name = name.Trim();
|
||||
formModel.FormType = typeId.ToString();
|
||||
formModel.EventJSON = eventJSON;
|
||||
formModel.SubtableJSON = subtableJSON;
|
||||
formModel.attribute = isNew ? jObject.ToString(Newtonsoft.Json.Formatting.None) : attJSON;
|
||||
formModel.Html = html;
|
||||
formModel.RunHtml = runHtml;
|
||||
formModel.EditDate = DateExtensions.Now;
|
||||
formModel.ManageUser = manageUser.ToLower();
|
||||
_ = isNew ? _form.Add(formModel) : _form.Update(formModel);
|
||||
#endregion
|
||||
|
||||
#region 加入应用程序库
|
||||
|
||||
var appModel = _appLibrary.GetByCode(formModel.Id.ToString());
|
||||
bool isAddAppModel = false;
|
||||
if (appModel == null)
|
||||
{
|
||||
isAddAppModel = true;
|
||||
appModel = new RoadFlow.Model.rf_applibrary()
|
||||
{
|
||||
Id = GuidExtensions.NewGuid().ToString(),
|
||||
Code = formModel.Id.ToString()
|
||||
};
|
||||
}
|
||||
appModel.Title = formModel.Name;
|
||||
appModel.Title_en = appModel.Title_en.IsNullOrEmpty() ? formModel.Name : appModel.Title_en;
|
||||
appModel.Title_zh = appModel.Title_zh.IsNullOrEmpty() ? formModel.Name : appModel.Title_zh;
|
||||
appModel.Type = formModel.FormType;
|
||||
appModel.Address = appModel.Code;//VUE不需要地址,这里填入表单ID,方便查看,直接从数据表加载HTML//formModel.Id.ToLowerString() + ".html";
|
||||
_ = isAddAppModel ? _appLibrary.Add(appModel) : _appLibrary.Update(appModel);
|
||||
#endregion
|
||||
|
||||
#region 更新缓存
|
||||
_form.ClearRunJObjectCache(formModel.Id);
|
||||
#endregion
|
||||
|
||||
_log.Add("发布了表单-" + name,_userManager.UserId ,formModel.ToString(), LogType.流程管理, others: appModel.ToString());
|
||||
return new JObject() { { "msg", "发布成功" }, { "id", formModel.Id } };
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(true, jObject: new JObject() { { "msg", localizer["PublishSuccessfully"].Value }, { "id", formModel.Id } });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 另存为
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("SaveAs")]
|
||||
|
||||
public string SaveAs([FromBody] JObject args)
|
||||
{
|
||||
string formId = args.GetJsonValue("id");
|
||||
string formName = args.GetJsonValue("name");
|
||||
if (!formId.IsGuid(out Guid formGuid))
|
||||
{
|
||||
throw Oops.Oh("Id错误");
|
||||
// return RoadFlowCommon.Tools.GetReturnJsonString(false, localizer["IdError"].Value);
|
||||
}
|
||||
if (formName.IsNullOrWhiteSpace())
|
||||
{
|
||||
throw Oops.Oh("名字不能为空");
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(false, localizer["NameEmpty"].Value);
|
||||
}
|
||||
|
||||
var formModel = _form.GetOneById(formId);
|
||||
if (null == formModel)
|
||||
{
|
||||
throw Oops.Oh("未找到源表格");
|
||||
// return RoadFlowCommon.Tools.GetReturnJsonString(false, localizer["SaveAsNotFound"].Value);
|
||||
}
|
||||
var userModel = _userManager.User;
|
||||
formModel.Id = GuidExtensions.NewGuid().ToString();
|
||||
formModel.Name = formName.Trim();
|
||||
formModel.CreateDate = DateExtensions.Now;
|
||||
formModel.EditDate = formModel.CreateDate;
|
||||
formModel.CreateUserId = userModel.Id;
|
||||
formModel.CreateUserName = userModel.Name;
|
||||
formModel.Status = 0;
|
||||
JObject jObject;
|
||||
try
|
||||
{
|
||||
jObject = JObject.Parse(formModel.attribute);
|
||||
jObject["id"] = formModel.Id;
|
||||
jObject["name"] = formModel.Name;
|
||||
formModel.attribute = jObject.ToString(Newtonsoft.Json.Formatting.None);
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
throw Oops.Oh(err.Message);
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(false, err.Message);
|
||||
}
|
||||
if (_form.Add(formModel) == 1)
|
||||
{
|
||||
return "保存成功";
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(true, localizer["SaveAsSuccessfully"].Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Oops.Oh("保存失败");
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(false, localizer["SaveAsFailed"].Value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据sql得到下拉选项
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("GetOpitonsBySql")]
|
||||
|
||||
public dynamic GetOpitonsBySql([FromBody] JObject args)
|
||||
{
|
||||
string connId = args.GetJsonValue("connid");
|
||||
string sql = args.GetJsonValue("sql");
|
||||
string value = args.GetJsonValue("value");
|
||||
|
||||
JArray jArray = _form.GetJArrayOptionsBySQL(connId, sql, value);
|
||||
return jArray;
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(jArray: jArray);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据url得到下拉选项
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("GetOpitonsByUrl")]
|
||||
|
||||
public dynamic GetOpitonsByUrl([FromBody] JObject args)
|
||||
{
|
||||
string url = args.GetJsonValue("url");
|
||||
string value = args.GetJsonValue("value");
|
||||
string parentvalue = args.GetJsonValue("parentvalue");
|
||||
string queryString = "value=" + value + "&parentvalue=" + parentvalue;
|
||||
url = url.Contains('?') ? url + "&" + queryString : url + "?" + queryString;
|
||||
string options = _form.GetOptionsByUrl(url);
|
||||
return options.ToJArray();
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(jArray: options.ToJArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导入表单
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("ImportForm")]
|
||||
|
||||
public string ImportForm([FromBody] JObject args)
|
||||
{
|
||||
var files = args.GetJsonValue("files");
|
||||
if (files.IsNullOrWhiteSpace())
|
||||
{
|
||||
|
||||
throw Oops.Oh("没有导入文件");
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(false, localizer["NoImportFile"].Value);
|
||||
}
|
||||
|
||||
System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
|
||||
foreach (string file in files.Split(','))
|
||||
{
|
||||
string filePath = RoadFlow.Utility.Config.FilePath + file.DESDecrypt();
|
||||
if (!System.IO.File.Exists(filePath))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var stream = System.IO.File.OpenRead(filePath);
|
||||
int count = (int)stream.Length;
|
||||
byte[] b = new byte[count];
|
||||
stream.Read(b, 0, count);
|
||||
string json = System.Text.Encoding.UTF8.GetString(b);
|
||||
string msg = _form.ImportForm(json, false);
|
||||
stream.Close();
|
||||
stream.DisposeAsync();
|
||||
try
|
||||
{
|
||||
System.IO.File.Delete(filePath);
|
||||
}
|
||||
catch (IOException err)
|
||||
{
|
||||
_log.Add(err);
|
||||
}
|
||||
if (!"1".Equals(msg))
|
||||
{
|
||||
stringBuilder.Append(msg + ",");
|
||||
}
|
||||
}
|
||||
string msg1 = stringBuilder.ToString();
|
||||
if (msg1.IsNullOrWhiteSpace())
|
||||
return "导入成功";
|
||||
else
|
||||
throw Oops.Oh(msg1);
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(msg1.IsNullOrWhiteSpace(), msg1.IsNullOrWhiteSpace() ? localizer["ImportSuccessfully"].Value : msg1);
|
||||
}
|
||||
}
|
||||
}
|
||||
265
20220330_Vote/Ewide.RoadFlow/Serivce/Message/MessageService.cs
Normal file
265
20220330_Vote/Ewide.RoadFlow/Serivce/Message/MessageService.cs
Normal file
@@ -0,0 +1,265 @@
|
||||
using Ewide.Core;
|
||||
using Ewide.RoadFlowLite.Utility;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Furion.FriendlyException;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using RoadFlow.Data;
|
||||
using RoadFlow.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.RoadFlowLite.Serivce.Message
|
||||
{
|
||||
[Route("/api/roadflow/Message/")]
|
||||
[ApiDescriptionSettings("RoadFlow")]
|
||||
public class MessageService : IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly ILog _log;
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly IMessage _message;
|
||||
private readonly IOrganize _organize;
|
||||
private readonly IMessageUser _messageUser;
|
||||
IRepository<SysUser> _sysUserRep;
|
||||
|
||||
public MessageService(
|
||||
ILog log,
|
||||
IUserManager userManager,
|
||||
IMessage message,
|
||||
IOrganize organize,
|
||||
IMessageUser messageUser,
|
||||
// IUserDummy userDummy,
|
||||
IRepository<SysUser> sysUserRep)
|
||||
{
|
||||
|
||||
_log = log;
|
||||
_userManager = userManager;
|
||||
_message = message;
|
||||
_organize = organize;
|
||||
_messageUser = messageUser;
|
||||
//_userDummy = userDummy;
|
||||
_sysUserRep = sysUserRep;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送消息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("Send")]
|
||||
public string Send([FromBody] JObject args)
|
||||
{
|
||||
string ReceiverIdString = args.GetJsonValue("ReceiverIdString");
|
||||
string SendType = args.GetJsonValue("SendType");
|
||||
string Contents = args.GetJsonValue("Contents");
|
||||
|
||||
if (ReceiverIdString.IsNullOrWhiteSpace() || SendType.IsNullOrWhiteSpace() || Contents.IsNullOrWhiteSpace())
|
||||
{
|
||||
throw Oops.Oh("参数错误");
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(false, localizer["ValidEmpty"].Value);
|
||||
}
|
||||
var userModel = _userManager.User;
|
||||
RoadFlow.Model.rf_message messageModel = new RoadFlow.Model.rf_message
|
||||
{
|
||||
Contents = Contents,
|
||||
Id = GuidExtensions.NewGuid().ToString(),
|
||||
ReceiverIdString = ReceiverIdString,
|
||||
SenderId = userModel.Id,
|
||||
SenderName = userModel.Name,
|
||||
SendType = SendType,
|
||||
SendTime = DateExtensions.Now,
|
||||
Type = 1
|
||||
};
|
||||
string msg = _message.VueSend(messageModel);
|
||||
if (msg == "1")
|
||||
return "发送成功";
|
||||
else
|
||||
throw Oops.Oh(msg);
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString("1".Equals(msg), "1".Equals(msg) ? localizer["SendSuccessfully"].Value : msg);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 得到记录
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("GetMessageList")]
|
||||
public dynamic GetMessageList([FromBody]JObject args)
|
||||
{
|
||||
string Contents = args.GetJsonValue("Contents");
|
||||
string SendTime1 = args.GetJsonValue("SendTime1");
|
||||
string SendTime2 = args.GetJsonValue("SendTime2");
|
||||
string status = args.GetJsonValue("status");//0自己发送的消息 1未读消息 2已读消息
|
||||
int number = args.GetJsonValue("number").ToInt(1);
|
||||
int size = args.GetJsonValue("size").ToInt();
|
||||
string order = args.GetJsonValue("order");
|
||||
if (order.IsNullOrWhiteSpace())
|
||||
{
|
||||
order = "SendTime desc";
|
||||
}
|
||||
string userId = _userManager.UserId;
|
||||
|
||||
var dt = _message.GetSendList(out int total, size, number, userId.ToString(), Contents, SendTime1, SendTime2, status, order);
|
||||
JArray jArray = new JArray();
|
||||
List<string> userids = new List<string>();
|
||||
foreach (var dr in dt)
|
||||
{
|
||||
JObject jObject = new JObject()
|
||||
{
|
||||
{ "Id", dr.Id },
|
||||
{ "Contents", dr.Contents.RemoveHTML() },
|
||||
{ "SenderName", dr.SenderName +","+dr.SenderId } ,//(dr.SenderId.IsGuid() ? "<span style=\"color:#999;\">-" + _organize.GetOrganizeMainShowHtml(dr.SenderId, false) + "</span>" : "") },
|
||||
{ "SendType", _message.GetSendTypeString(dr.SendType,null) },// localizer) },
|
||||
{ "SendTime", dr.SendTime.ToShortDateTimeString() },
|
||||
{ "LinkUrl", dr.Files},
|
||||
{ "Type", dr.Type},
|
||||
//{ "showLink", !dr["Files"].ToString().IsNullOrWhiteSpace() }
|
||||
};
|
||||
jArray.Add(jObject);
|
||||
userids.Add(dr.SenderId);
|
||||
}
|
||||
var dic =_organize.GetOrganizeMainShowHtml(userids, false);
|
||||
foreach (JObject obj in jArray)
|
||||
{
|
||||
string[] vals=obj["SenderName"].ToString().Split(",");
|
||||
if (!dic.ContainsKey(vals[1]))
|
||||
obj["SenderName"] = vals[0];
|
||||
else
|
||||
obj["SenderName"] = vals[0] + "<span style=\"color:#999;\">-" + dic[vals[1]] + "</span>";
|
||||
}
|
||||
JObject json = new JObject() {
|
||||
{ "total", total },
|
||||
};
|
||||
json.Add("rows", jArray);
|
||||
return json;
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(jObject: json);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到阅读记录
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("GetMessageUserList")]
|
||||
public dynamic GetMessageUserList([FromBody] JObject args )
|
||||
{
|
||||
string msgId = args.GetJsonValue("msgid");
|
||||
string order = args.GetJsonValue("order");
|
||||
if (order.IsNullOrWhiteSpace())
|
||||
{
|
||||
order = "IsRead asc";
|
||||
}
|
||||
|
||||
var dt = _messageUser.GetReadUserList(out int total, 100000, 1, msgId, order);
|
||||
JArray jArray = new JArray();
|
||||
int i = 0;
|
||||
List<string> userids = new List<string>();
|
||||
foreach (var dr in dt)
|
||||
{
|
||||
JObject jObject = new JObject()
|
||||
{
|
||||
{ "Id", i++.ToString() },
|
||||
{ "UserId", dr.UserId },//+ "<span style=\"color:#999;\"> - "+_organize.GetOrganizeMainShowHtml(dr.UserId,false)+"</span>" },
|
||||
{ "ReadTime", dr.ReadTime!=null ? dr.ReadTime.ToShortDateTimeString() : "<span class=\"roadui_liststatus roadui_liststatusdisabled\">未读</span>" },
|
||||
};
|
||||
jArray.Add(jObject);
|
||||
userids.Add(dr.UserId);
|
||||
}
|
||||
var usrList=_sysUserRep.DetachedEntities.Where(x => userids.Contains(x.Id)).ToList();
|
||||
var dic = _organize.GetOrganizeMainShowHtml(userids, false);
|
||||
|
||||
foreach (JObject obj in jArray)
|
||||
{
|
||||
string id = obj["UserId"].ToString();
|
||||
obj["UserId"] = usrList.FirstOrDefault(x => x.Id == id).Name?? "" + (dic.ContainsKey(id)?"<span style=\"color:#999;\"> - " + dic[id]+ "</span>":"") ;
|
||||
}
|
||||
JObject json = new JObject() {
|
||||
{ "total", total },
|
||||
};
|
||||
json.Add("rows", jArray);
|
||||
return json;
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(jObject: json);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询一条消息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("GetMessage")]
|
||||
|
||||
public dynamic GetMessage(string msgId, int type)
|
||||
{
|
||||
|
||||
var msgModel = _message.GetOneById(msgId);
|
||||
JObject jObject = new JObject();
|
||||
if (msgModel != null)
|
||||
{
|
||||
if (type == 1)//更新状态为已读
|
||||
{
|
||||
_messageUser.UpdateIsRead(msgModel.Id, _userManager.UserId);
|
||||
}
|
||||
jObject.Add("SenderName", msgModel.SenderName + (!msgModel.SenderId.IsNullOrWhiteSpace() ? "(" + _organize.GetOrganizeMainShowHtml(msgModel.SenderId, false) + ")" : ""));
|
||||
jObject.Add("SendTime", msgModel.SendTime.ToShortDateTimeString());
|
||||
jObject.Add("Contents", msgModel.Contents);
|
||||
}
|
||||
return jObject;
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(jObject: jObject);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 标记一条消息为已读
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("MarkAsReadOne")]
|
||||
public string MarkAsReadOne(string id)
|
||||
{
|
||||
if (!id.IsGuid(out Guid guid))
|
||||
{
|
||||
throw Oops.Oh("ID 错误");
|
||||
//return RoadFlowCommon.Tools.GetReturnJsonString(false, localizer["IdError"].Value);
|
||||
}
|
||||
_messageUser.UpdateIsRead(id,_userManager.UserId);
|
||||
return "标记成功";
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(true, localizer["MarkSuccessfully"].Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 标记为已读
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("MarkAsRead")]
|
||||
public string MarkAsRead()
|
||||
{
|
||||
_messageUser.UpdateAllIsRead();
|
||||
return "标注成功";
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(true, localizer["MarkSuccessfully"].Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除消息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("Delete")]
|
||||
public string Delete([FromBody] JObject args)
|
||||
{
|
||||
string ids = args.GetJsonValue("ids");
|
||||
List<string> guids = new List<string>();
|
||||
foreach (string id in ids.Split(','))
|
||||
{
|
||||
if (id.IsGuid())
|
||||
{
|
||||
guids.Add(id);
|
||||
}
|
||||
}
|
||||
_messageUser.Delete(guids, _userManager.UserId);
|
||||
return "删除成功";
|
||||
//RoadFlowCommon.Tools.GetReturnJsonString(true, localizer["DeleteSuccessfully"].Value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user