using Furion;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using Myshipping.Core;
using Myshipping.FlowCenter.Entity;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
namespace Myshipping.FlowCenter.Service;
///
/// 表单管理
///
[ApiDescriptionSettings("FlowCenter", Name = "FormManage", Order = 100)]
public class FlcFormManageService : IFlcFormManageService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _flcFormRep;
public FlcFormManageService(SqlSugarRepository flcFormRep)
{
_flcFormRep = flcFormRep;
}
///
/// 分页查询表单
///
///
///
[HttpGet("/flcForm/page")]
public async Task QueryFormPageList([FromQuery] PageFlcFormInput input)
{
var orgs = await _flcFormRep.AsQueryable()
.WhereIF(!string.IsNullOrWhiteSpace(input.Name), u => u.Name.Contains(input.Name.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.Id), u => u.Id == long.Parse(input.Id.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.OrgId), u => u.OrgId == long.Parse(input.OrgId) || u.OrgId == null || u.OrgId == 0)
.Where(u => u.Status != CommonStatus.DELETED)
.OrderBy(u => u.Sort)
.Select()
.ToPagedListAsync(input.PageNo, input.PageSize);
return orgs.XnPagedResult();
}
///
/// 获取表单列表
///
///
///
[HttpGet("/flcForm/list")]
public async Task> GetFormList([FromQuery] FlcFormInput input)
{
var dataScopeList = await DataFilterExtensions.GetDataScopeIdList(FilterType.Org);
var forms = await _flcFormRep.AsQueryable()
.WhereIF(!string.IsNullOrWhiteSpace(input.OrgId), u => u.OrgId == long.Parse(input.OrgId) || u.OrgId == null || u.OrgId == 0)
.WhereIF(dataScopeList.Any(), u => dataScopeList.Contains(u.OrgId??0)|| u.OrgId == null || u.OrgId == 0)
.Where(u => u.Status == CommonStatus.ENABLE)
.OrderBy(u => u.Sort)
.ToListAsync();
return forms.Adapt>();
}
///
/// 增加表单
///
///
///
[HttpPost("/flcForm/add")]
public async Task AddForm(AddFlcFormInput input)
{
var isExist = await _flcFormRep.AnyAsync(u => u.Name == input.Name);
if (isExist)
throw Oops.Oh(ErrorCode.D2002);
var flcForm = input.Adapt();
flcForm.Status = CommonStatus.ENABLE;
//反射获取这个表单的所有参数和备注,排除主键
if (flcForm.FrmType == FormType.CUSTOMFORM)
{
var dataname = input.WebId.Substring(0, 1).ToUpper() + input.WebId.Substring(1);
var t = App.Assemblies
.SelectMany(a => a.GetTypes().Where(t => t.FullName.Contains("Myshipping.FlowCenter.Entity") && t.FullName.Contains("." + dataname))).First();
List list = new List();
List