using DS.Module.Core;
using DS.Module.Core.Extensions;
using DS.Module.UserModule;
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 DS.WMS.Core.Sys.Interface;
using Mapster;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
namespace DS.WMS.Core.Flow.Method;
///
///
///
public class ClientFlowTemplateService : IClientFlowTemplateService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly IUser user;
private readonly ICommonService _commonService;
///
///
///
///
public ClientFlowTemplateService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService();
user = _serviceProvider.GetRequiredService();
_commonService = _serviceProvider.GetRequiredService();
}
public DataResult> GetListByPage(PageRequest request)
{
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = db.Queryable()
.LeftJoin((a, b) => a.PermissionId == b.Id)
.Select()
.Where(whereList).ToQueryPage(request.PageCondition);
return data;
}
public DataResult EditClientFlowTemplate(FlowTemplateReq req)
{
//if (req.Id == 0)
//{
// return DataResult.Failed("非法请求!",MultiLanguageConst.IllegalRequest);
//}
//else
//{
// var info = db.Queryable().Where(x => x.Id == req.Id).First();
// info = req.Adapt(info);
// db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
// return DataResult.Successed("更新成功!",MultiLanguageConst.DataUpdateSuccess);
//}
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();
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);
db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
return DataResult.Successed("更新成功!");
}
}
public DataResult GetClientFlowTemplateInfo(string id)
{
var data = db.Queryable()
.Where(a => a.Id == long.Parse(id))
.Select()
.First();
return DataResult.Success(data,MultiLanguageConst.DataQuerySuccess);
}
public DataResult ImportFlowTemplate(string id)
{
var info = db.Queryable().Where(x => x.Id == long.Parse(id)).First();
if (info == null)
{
return DataResult.Failed("流程模板不存在!",MultiLanguageConst.FlowTemplateImportNotExist);
}
var data = info.Adapt();
data.Id = 0;
db.Insertable(data).ExecuteCommand();
return DataResult.Successed("引入成功!",MultiLanguageConst.DataImportSuccess);
}
public DataResult DelFlowTemplate(string id)
{
var info = db.Queryable().Where(x => x.Id == long.Parse(id)).First();
if (info == null)
{
return DataResult.Failed("流程模板不存在!",MultiLanguageConst.FlowTemplateNotExist);
}
if (db.Queryable().Where(x=>x.TemplateId == long.Parse(id)).Any())
{
return DataResult.Failed("工作流实例存在引用的流程模板不能删除!",MultiLanguageConst.FlowTemplateDelExistImport);
}
db.Deleteable(info).ExecuteCommand();
return DataResult.Successed("删除成功!",MultiLanguageConst.DataDelSuccess);
}
public DataResult> GetFlowTemplateList(PageRequest request)
{
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = db.Queryable().Where(a=>a.Status == StatusEnum.Enable)
.LeftJoin((a, b) => a.PermissionId == b.Id)
.Select()
.Where(whereList).ToQueryPage(request.PageCondition);
return data;
}
}