using DS.Module.Core;
using DS.Module.Core.Extensions;
using DS.WMS.Core.Flow.Dtos;
using DS.WMS.Core.Flow.Entity;
using DS.WMS.Core.Flow.Interface;
using DS.WMS.Core.Sys.Entity;
using Mapster;
using Newtonsoft.Json.Linq;
namespace DS.WMS.Core.Flow.Method;
///
/// 工作流模板
///
public class FlowTemplateService : ServiceBase, IFlowTemplateService
{
///
/// 初始化
///
///
public FlowTemplateService(IServiceProvider serviceProvider) : base(serviceProvider)
{
}
public DataResult> GetListByPage(PageRequest request)
{
//序列化查询条件
var whereList = request.GetConditionalModels(Db);
var data = Db.Queryable()
.LeftJoin((a, b) => a.PermissionId == b.Id)
.Select()
.Where(whereList).ToQueryPage(request.PageCondition);
return data;
}
static string EnsureJsonCorrect(string json)
{
//JObject jsonObj = JObject.Parse(json);
//var children = jsonObj["child"]["children"] as JArray;
//if (children != null && children.HasValues)
//{
// foreach (var item in children)
// {
// }
//}
//return jsonObj.ToString();
return json;
}
public DataResult EditFlowTemplate(FlowTemplateReq req)
{
if (req.Id == 0)
{
var isExist = Db.Queryable().Where(x => x.Name == req.Name).First();
if (isExist != null)
return DataResult.Failed("流程模板名称已存在!");
var data = req.Adapt();
data.Content = EnsureJsonCorrect(data.Content);
var entity = Db.Insertable(data).ExecuteReturnEntity();
return DataResult.Successed("添加成功!", entity.Id);
}
else
{
var info = Db.Queryable().Where(x => x.Id == req.Id).First();
info = req.Adapt(info);
info.Content = EnsureJsonCorrect(info.Content);
Db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
return DataResult.Successed("更新成功!");
}
}
public DataResult GetFlowTemplateInfo(string id)
{
var data = Db.Queryable()
// .LeftJoin((a, b) => a.PermissionId == b.Id)
.Where(a => a.Id == long.Parse(id))
.Select()
.First();
return DataResult.Success(data);
}
}