using Tiobon.Core.IServices; using Tiobon.Core.Model.Models; using Tiobon.Core.Services.BASE; using Tiobon.Core.IRepository.Base; using Tiobon.Core.Common.Caches; using System.Collections.Generic; using MySqlX.XDevAPI.Relational; using Microsoft.EntityFrameworkCore.Metadata.Internal; using NPOI.POIFS.NIO; namespace Tiobon.Core.Services { /// /// 人员群组 (服务) /// public class Ghra_StaffGroupServices : BaseServices, IGhra_StaffGroupServices { private readonly IBaseRepository _dal; private IGhra_StaffGroupDetailServices _StaffGroupDetailServices; public Ghra_StaffGroupServices(ICaching caching, IBaseRepository dal, IGhra_StaffGroupDetailServices StaffGroupDetailServices ) { this._dal = dal; base.BaseDal = dal; base._caching = caching; _StaffGroupDetailServices = StaffGroupDetailServices; } public override async Task Add(InsertGhra_StaffGroupInput entity) { var result = await base.Add(entity); entity.StaffGroupDetail.ForEach(x => { x.StaffGroupID = result; }); await _StaffGroupDetailServices.Add(entity.StaffGroupDetail); return result; } public override async Task Update(long Id, EditGhra_StaffGroupInput editModel) { await _StaffGroupDetailServices.Delete(x => x.StaffGroupID == Id); editModel.StaffGroupDetail.ForEach(x => { x.StaffGroupID = Id; }); await _StaffGroupDetailServices.Add(editModel.StaffGroupDetail); return await base.Update(Id, editModel); } public override async Task> QueryForm(QueryForm body) { var result = await base.QueryForm(body); var StaffGroupDetail = await _StaffGroupDetailServices.Query(x => x.StaffGroupID == body.id); result.result.DT_TableDataT1[0].StaffGroupDetail = StaffGroupDetail.OrderBy(x => x.SortNo).ToList(); result.result.DT_TableDataT1[0].StaffGroupDetail.ForEach((x) => { if (x.FieldValue != null) { if (JsonHelper.IsJson(x.FieldValue.ToString())) { try { x.FieldValue = JsonHelper.JsonToObj>(x.FieldValue.ToString()); } catch (Exception) { x.FieldValue = JsonHelper.JsonToObj>(x.FieldValue.ToString()); } } } }); if (body.doType == "Copy") { result.result.DT_TableDataT1[0].StaffGroupNo = null; result.result.DT_TableDataT1[0].StaffGroupName = null; } return result; } public override async Task> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true) { var result = await base.QueryFilterPage(filter, condition, IsEnable); result.result.DT_TableDataT1.ForEach(async x => { x.DetailInfo = Db.Ado.SqlQuerySingle($@"select stuff((select distinct ',' + (select top 1 dbo.FLangKeyToValue(MKey,1,StaffInfoColumnName) from Ghra_StaffInfoColumn where IsEnable=1 and StaffInfoGroupId = 1 and IsRelease = 1 and StaffInfoColumnNo=a.StaffField) from Ghra_StaffGroupDetail a where StaffGroupID = {x.Id} for XML path(''),type).value('.','nvarchar(max)'),1,1,'')"); }); return result; } public async Task> GetStaffInfoColumnData() { string sql = @$"select StaffInfoColumnNo, dbo.FLangKeyToValue(MKey,1,StaffInfoColumnName) StaffInfoColumnName, ColumnType elementType, DataType dataType, case when ColumnType in ('OrgTreeSelect','ApiSelect','StaffSelect') then 'dict' else '' end dataSourceType, dbo.FS_GetdataSourceBySet('',DataSourceType, DataSource) dataSource , case when ColumnType in ('OrgTreeSelect','ApiSelect','StaffSelect') then 1 else 0 end multipleSelectInt, (select ParaDetailNo operatorNo,ParaDetailName operatorDesc,SqlFunction operatorIcon,SortNo from Ghrs_ParaDetail where IsEnable= 1 and ParaDetailNo in (select value from dbo.Fs1_GHR30_SplitString(case when ColumnType in ('OrgTreeSelect','ApiSelect','StaffSelect') then 'EqualAny,NotEqualAny' when ColumnType in ('Input') then 'Include,NotInclude,Equal,NotEqual' when ColumnType in ('InputNumber') then 'Equal,NotEqual,Greater,GreaterOrEqual,Less,LessOrEqual' when ColumnType in ('GDatePicker') then 'Greater,GreaterOrEqual,Less,LessOrEqual' when ColumnType in ('Switch') then 'Equal,NotEqual' else 'Equal,NotEqual,Include,NotInclude,EqualAny,NotEqualAny,IsNull,NotNull,Greater,GreaterOrEqual,Less,LessOrEqual,Range' end,',')) and ParaMasterNo = 'DataQueryOperator' and ParaTypeNo='GHRPara' order by SortNo for JSON path ) OperatorDataStr from Ghra_StaffInfoColumn where IsEnable = 1 and StaffInfoGroupId = 1 and IsRelease = 1 and StaffInfoColumnNo != 'AttachmentIDs' "; var result = Db.Ado.SqlQuery(sql); result.ForEach(x => { x.operatorData = JsonConvert.DeserializeObject>(x.OperatorDataStr); }); return ServiceResult.OprateSuccess("查询成功!", result); } public class StaffInfoColumn() { public string StaffInfoColumnNo { get; set; } public string StaffInfoColumnName { get; set; } public string elementType { get; set; } public string dataType { get; set; } public string dataSourceType { get; set; } public string dataSource { get; set; } public int multipleSelectInt { get; set; } public bool multipleSelect => multipleSelectInt == 1 ? true : false; public string OperatorDataStr { get; set; } public List operatorData { get; set; } } public class OperatorData() { public string operatorNo { get; set; } public string ParaDetailName { get; set; } public string operatorIcon { get; set; } public string SortNo { get; set; } } } }