@ -1,74 +1,57 @@
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 ;
using static Microsoft . Extensions . Logging . EventSource . LoggingEventSource ;
using MySqlX.XDevAPI.Common ;
using System.Text ;
using Microsoft.AspNetCore.Identity ;
using System.Linq ;
using Amazon.Runtime.Internal.Transform ;
namespace Tiobon.Core.Services ;
namespace Tiobon.Core.Services
/// <summary>
/// 人员群组 (服务)
/// </summary>
public class Ghra_StaffGroupServices : BaseServices < Ghra_StaffGroup , Ghra_StaffGroupDto , InsertGhra_StaffGroupInput , EditGhra_StaffGroupInput > , IGhra_StaffGroupServices
{
/// <summary>
/// 人员群组 (服务)
/// </summary>
public class Ghra_StaffGroupServices : BaseServices < Ghra_StaffGroup , Ghra_StaffGroupDto , InsertGhra_StaffGroupInput , EditGhra_StaffGroupInput > , IGhra_StaffGroupServices
private readonly IBaseRepository < Ghra_StaffGroup > _d al ;
private IGhra_StaffGroupDetailServices _ StaffGroupDetailServices ;
public Ghra_StaffGroupServices ( ICaching caching , IBaseRepository < Ghra_StaffGroup > dal ,
IGhra_StaffGroupDetailServices StaffGroupDetailServices
)
{
private readonly IBaseRepository < Ghra_StaffGroup > _d al ;
private IGhra_StaffGroupDetailServices _ StaffGroupDetailServices ;
public Ghra_StaffGroupServices ( ICaching caching , IBaseRepository < Ghra_StaffGroup > dal ,
IGhra_StaffGroupDetailServices StaffGroupDetailServices
)
{
this . _d al = dal ;
base . BaseDal = dal ;
base . _ caching = caching ;
_ StaffGroupDetailServices = StaffGroupDetailServices ;
}
this . _d al = dal ;
base . BaseDal = dal ;
base . _ caching = caching ;
_ StaffGroupDetailServices = StaffGroupDetailServices ;
}
public override async Task < long > Add ( InsertGhra_StaffGroupInput entity )
public override async Task < long > Add ( InsertGhra_StaffGroupInput entity )
{
var result = await base . Add ( entity ) ;
entity . StaffGroupDetail . ForEach ( x = >
{
x . StaffGroupID = result ;
} ) ;
var result = await base . Add ( entity ) ;
entity . StaffGroupDetail . ForEach ( x = >
{
x . StaffGroupID = result ;
} ) ;
await _ StaffGroupDetailServices . Add ( entity . StaffGroupDetail ) ;
await _ StaffGroupDetailServices . Add ( entity . StaffGroupDetail ) ;
return result ;
}
return result ;
}
public override async Task < bool > Update ( long Id , EditGhra_StaffGroupInput editModel )
{
await _ StaffGroupDetailServices . Delete ( x = > x . StaffGroupID = = Id ) ;
public override async Task < bool > Update ( long Id , EditGhra_StaffGroupInput editModel )
editModel . StaffGroupDetail . ForEach ( x = >
{
await _ StaffGroupDetailServices . Delete ( x = > x . StaffGroupID = = Id ) ;
editModel . StaffGroupDetail . ForEach ( x = >
{
x . StaffGroupID = Id ;
} ) ;
await _ StaffGroupDetailServices . Add ( editModel . StaffGroupDetail ) ;
x . StaffGroupID = Id ;
} ) ;
await _ StaffGroupDetailServices . Add ( editModel . StaffGroupDetail ) ;
return await base . Update ( Id , editModel ) ;
}
public override async Task < bool > DeleteById1 ( object id )
{
var entity = await BaseDal . QueryById ( id ) ;
BasePoco ent = entity as BasePoco ;
ent . IsEnable = 0 ;
HttpRequest request = UserContext . Context . Request ;
var api = request . Path . ObjToString ( ) . TrimEnd ( '/' ) . ToLower ( ) ;
var ip = GetUserIp ( UserContext . Context ) ;
string sql = @ $ "update Ghra_StaffGroupDetail
return await base . Update ( Id , editModel ) ;
}
public override async Task < bool > DeleteById1 ( object id )
{
var entity = await BaseDal . QueryById ( id ) ;
BasePoco ent = entity as BasePoco ;
ent . IsEnable = 0 ;
HttpRequest request = UserContext . Context . Request ;
var api = request . Path . ObjToString ( ) . TrimEnd ( '/' ) . ToLower ( ) ;
var ip = GetUserIp ( UserContext . Context ) ;
string sql = @ $ "update Ghra_StaffGroupDetail
set IsEnable = 0 ,
UpdateBy = { App . User . ID . ToString ( ) } ,
UpdateIP = { ip } ,
@ -77,58 +60,58 @@ namespace Tiobon.Core.Services
where StaffGroupID = { id . ToString ( ) }
and IsEnable = 1 ";
return await BaseDal . Update ( entity ) ;
}
return await BaseDal . Update ( entity ) ;
}
public override async Task < ServiceFormResult < Ghra_StaffGroupDto > > QueryForm ( QueryForm body )
{
var result = await base . QueryForm ( body ) ;
public override async Task < ServiceFormResult < Ghra_StaffGroupDto > > 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 ) = >
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 ( x . FieldValue ! = null )
if ( JsonHelper . IsJson ( x . FieldValue . ToString ( ) ) )
{
if ( JsonHelper . IsJson ( x . FieldValue . ToString ( ) ) )
try
{
x . FieldValue = JsonHelper . JsonToObj < List < int > > ( x . FieldValue . ToString ( ) ) ;
}
catch ( Exception )
{
try
{
x . FieldValue = JsonHelper . JsonToObj < List < int > > ( x . FieldValue . ToString ( ) ) ;
}
catch ( Exception )
{
x . FieldValue = JsonHelper . JsonToObj < List < string > > ( x . FieldValue . ToString ( ) ) ;
}
x . FieldValue = JsonHelper . JsonToObj < List < string > > ( 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 < ServicePageResult < Ghra_StaffGroupDto > > QueryFilterPage ( QueryBody filter , string condition , bool? IsEnable = true )
} ) ;
if ( body . doType = = "Copy" )
{
result . result . DT_TableDataT1 [ 0 ] . StaffGroupNo = null ;
result . result . DT_TableDataT1 [ 0 ] . StaffGroupName = null ;
}
return result ;
}
public override async Task < ServicePageResult < Ghra_StaffGroupDto > > QueryFilterPage ( QueryBody filter , string condition , bool? IsEnable = true )
{
var result = await base . QueryFilterPage ( filter , condition , IsEnable ) ;
var result = await base . QueryFilterPage ( filter , condition , IsEnable ) ;
result . result . DT_TableDataT1 . ForEach ( async x = >
{
x . DetailInfo = Db . Ado . SqlQuerySingle < string > ( $ @ "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)
result . result . DT_TableDataT1 . ForEach ( async x = >
{
x . DetailInfo = Db . Ado . SqlQuerySingle < string > ( $ @ "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 ;
}
return result ;
}
public async Task < ServiceResult < object > > GetStaffInfoColumnData ( )
{
string sql = @ $ "select StaffInfoColumnNo,
public async Task < ServiceResult < object > > GetStaffInfoColumnData ( )
{
string sql = @ $ "select StaffInfoColumnNo,
dbo . FLangKeyToValue ( MKey , 1 , StaffInfoColumnName ) StaffInfoColumnName ,
ColumnType elementType ,
DataType dataType ,
@ -160,20 +143,20 @@ namespace Tiobon.Core.Services
and IsRelease = 1
and StaffInfoColumnNo ! = ' AttachmentIDs ' ";
var result = Db . Ado . SqlQuery < StaffInfoColumn > ( sql ) ;
result . ForEach ( x = >
{
x . operatorData = JsonConvert . DeserializeObject < List < OperatorData > > ( x . OperatorDataStr ) ;
} ) ;
return ServiceResult < object > . OprateSuccess ( "查询成功!" , result ) ;
}
public async Task < ServiceResult < Dictionary < string , object > > > GetStaffGroupInfoByID ( long Id , JObject FBody )
var result = Db . Ado . SqlQuery < StaffInfoColumn > ( sql ) ;
result . ForEach ( x = >
{
string LangID = App . User . GetLangId ( ) . ToString ( ) ;
string BaseDate = FBody [ "BaseDate" ] ? . Value < string > ( ) ? ? DateTime . Now . ToString ( "yyyy-MM-dd" ) ;
if ( LangID = = "0" ) LangID = "1" ;
string sql = @ $ "select case when Operator not in ('IsNull','NotNull') then iif(IsChangeColumn = 1,'b.','a.')+StaffField
x . operatorData = JsonConvert . DeserializeObject < List < OperatorData > > ( x . OperatorDataStr ) ;
} ) ;
return ServiceResult < object > . OprateSuccess ( "查询成功!" , result ) ;
}
public async Task < ServiceResult < Dictionary < string , object > > > GetStaffGroupInfoByID ( long Id , JObject FBody )
{
string LangID = App . User . GetLangId ( ) . ToString ( ) ;
string BaseDate = FBody [ "BaseDate" ] ? . Value < string > ( ) ? ? DateTime . Now . ToString ( "yyyy-MM-dd" ) ;
if ( LangID = = "0" ) LangID = "1" ;
string sql = @ $ "select case when Operator not in ('IsNull','NotNull') then iif(IsChangeColumn = 1,'b.','a.')+StaffField
+ case when Operator = ' Equal '
then ' = '+' ''' + ISNULL ( FieldValue , ' ' ) + ''' '
when Operator = ' NotEqual '
@ -231,31 +214,31 @@ namespace Tiobon.Core.Services
and StaffGroupID = ' { Id } '
order by b . SortNo ";
DataTable dt = await Db . Ado . GetDataTableAsync ( sql ) ;
string WhereSQL = string . Empty ;
string SqlStr = string . Empty ;
List < StaffInfoColumn > staffInfoColumns = new List < StaffInfoColumn > ( ) ;
staffInfoColumns . Add ( new StaffInfoColumn ( ) { StaffInfoColumnNo = "StaffID" , StaffInfoColumnName = "ID" , isHidden = true } ) ;
staffInfoColumns . Add ( new StaffInfoColumn ( ) { StaffInfoColumnNo = "StaffNo" , StaffInfoColumnName = "工号" } ) ;
staffInfoColumns . Add ( new StaffInfoColumn ( ) { StaffInfoColumnNo = "StaffName" , StaffInfoColumnName = "姓名" } ) ;
staffInfoColumns . Add ( new StaffInfoColumn ( ) { StaffInfoColumnNo = "DeptFullPateName" , StaffInfoColumnName = "全部门" } ) ;
foreach ( DataRow dr in dt . Rows )
{
WhereSQL + = " and " + dr [ "WhereStr" ] . ToString ( ) ;
DataTable dt = await Db . Ado . GetDataTableAsync ( sql ) ;
string WhereSQL = string . Empty ;
string SqlStr = string . Empty ;
StaffInfoColumn staffInfo = new StaffInfoColumn ( ) ;
staffInfo . StaffInfoColumnNo = dr [ "ColumnNo" ] . ToString ( ) ;
staffInfo . StaffInfoColumnName = dr [ "ColumnName" ] . ToString ( ) ;
; if ( ! staffInfoColumns . Any ( x = > x . StaffInfoColumnNo = = dr [ "ColumnNo" ] . ToString ( ) ) )
{
staffInfoColumns . Add ( staffInfo ) ;
SqlStr + = "," + dr [ "SqlStr" ] . ToString ( ) ;
}
List < StaffInfoColumn > staffInfoColumns = new List < StaffInfoColumn > ( ) ;
staffInfoColumns . Add ( new StaffInfoColumn ( ) { StaffInfoColumnNo = "StaffID" , StaffInfoColumnName = "ID" , isHidden = true } ) ;
staffInfoColumns . Add ( new StaffInfoColumn ( ) { StaffInfoColumnNo = "StaffNo" , StaffInfoColumnName = "工号" } ) ;
staffInfoColumns . Add ( new StaffInfoColumn ( ) { StaffInfoColumnNo = "StaffName" , StaffInfoColumnName = "姓名" } ) ;
staffInfoColumns . Add ( new StaffInfoColumn ( ) { StaffInfoColumnNo = "DeptFullPateName" , StaffInfoColumnName = "全部门" } ) ;
foreach ( DataRow dr in dt . Rows )
{
WhereSQL + = " and " + dr [ "WhereStr" ] . ToString ( ) ;
StaffInfoColumn staffInfo = new StaffInfoColumn ( ) ;
staffInfo . StaffInfoColumnNo = dr [ "ColumnNo" ] . ToString ( ) ;
staffInfo . StaffInfoColumnName = dr [ "ColumnName" ] . ToString ( ) ;
; if ( ! staffInfoColumns . Any ( x = > x . StaffInfoColumnNo = = dr [ "ColumnNo" ] . ToString ( ) ) )
{
staffInfoColumns . Add ( staffInfo ) ;
SqlStr + = "," + dr [ "SqlStr" ] . ToString ( ) ;
}
}
string StaffSql = @ $ "select a.StaffID,a.StaffNo,a.StaffName,
string StaffSql = @ $ "select a.StaffID,a.StaffNo,a.StaffName,
dbo . FA_StaffInfoRepItemStaffInfo ( a . StaffID , null , { LangID } , ' DeptFullPateName ' ) DeptFullPateName
{ SqlStr }
from Ghra_Staff a inner join ( select * from Ghra_StaffChange where IsEnable = 1 and ChangeDate = [ dbo ] . [ FLatestStaffChangeDate ] ( StaffID , ' { BaseDate } ' ) ) b
@ -263,39 +246,36 @@ namespace Tiobon.Core.Services
where a . IsEnable = 1
and a . InDate < = ' { BaseDate } '
and ( a . OutDate is null or a . OutDate > = ' { BaseDate } ' ) "
+ WhereSQL ;
+ WhereSQL ;
DataTable staffTable = await Db . Ado . GetDataTableAsync ( StaffSql ) ;
Dictionary < string , object > result = new Dictionary < string , object > ( )
{
["TableColumns"] = staffInfoColumns ,
["TableData"] = staffTable
} ;
return ServiceResult < Dictionary < string , object > > . OprateSuccess ( "查询成功!" , result ) ;
}
public class StaffInfoColumn ( )
{
public string StaffInfoColumnNo { get ; set ; }
public string StaffInfoColumnName { get ; set ; }
public bool isHidden { get ; set ; } = false ;
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 > operatorData { get ; set ; }
}
public class OperatorData ( )
DataTable staffTable = await Db . Ado . GetDataTableAsync ( StaffSql ) ;
Dictionary < string , object > result = new Dictionary < string , object > ( )
{
public string operatorNo { get ; set ; }
public string ParaDetailName { get ; set ; }
public string operatorIcon { get ; set ; }
public string SortNo { get ; set ; }
}
["TableColumns"] = staffInfoColumns ,
["TableData"] = staffTable
} ;
return ServiceResult < Dictionary < string , object > > . OprateSuccess ( "查询成功!" , result ) ;
}
public class StaffInfoColumn ( )
{
public string StaffInfoColumnNo { get ; set ; }
public string StaffInfoColumnName { get ; set ; }
public bool isHidden { get ; set ; } = false ;
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 > 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 ; }
}
}