รายงานลัญชี 1-2-3 และรายงาน กพ7
This commit is contained in:
parent
1dc973cc73
commit
a15f2a1081
16 changed files with 1893 additions and 585 deletions
404
Services/OrganizationReportService.cs
Normal file
404
Services/OrganizationReportService.cs
Normal file
|
|
@ -0,0 +1,404 @@
|
|||
using Amazon.Internal;
|
||||
using BMA.EHR.Extensions;
|
||||
using BMA.EHR.Profile.Service.Services;
|
||||
using BMA.EHR.Report.Service.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BMA.EHR.Report.Service.Services
|
||||
{
|
||||
public class OrganizationReportService
|
||||
{
|
||||
#region " Fields "
|
||||
|
||||
private readonly EHRDbContext _context;
|
||||
private readonly EHRDbContext _applicationDbContext;
|
||||
private readonly ProfileService _profileService;
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Constructor and Destructor "
|
||||
|
||||
public OrganizationReportService(EHRDbContext context,
|
||||
EHRDbContext applicationDbContext,
|
||||
ProfileService profileService)
|
||||
{
|
||||
_context = context;
|
||||
_applicationDbContext = applicationDbContext;
|
||||
_profileService = profileService;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Methods "
|
||||
|
||||
#region " Report Query "
|
||||
|
||||
public async Task<List<Account1ResultItem>> GetReport1Query(Guid ocId)
|
||||
{
|
||||
var ocIdList = _profileService.GetAllIdByRoot(ocId);
|
||||
var RootOcName = _profileService.GetOrganizationNameFullPath(ocId, false, false);
|
||||
|
||||
var organizationPositions = await _context.OrganizationPositions.ToListAsync();
|
||||
var positionMasters = await _context.PositionMasters.ToListAsync();
|
||||
var organizations = await _context.Organizations.ToListAsync();
|
||||
var organizationOrganizations = await _applicationDbContext.OrganizationOrganizations.ToListAsync();
|
||||
var organizationShortNames = await _applicationDbContext.OrganizationShortNames.ToListAsync();
|
||||
var positionNumbers = await _context.PositionNumbers.ToListAsync();
|
||||
var executivePositions = await _applicationDbContext.PositionExecutives.ToListAsync();
|
||||
var executivePositionSide = await _applicationDbContext.PositionExecutiveSides.ToListAsync();
|
||||
var positionPaths = await _applicationDbContext.PositionPaths.ToListAsync();
|
||||
var positionPathSides = await _applicationDbContext.PositionPathSides.ToListAsync();
|
||||
var positionTypes = await _applicationDbContext.PositionTypes.ToListAsync();
|
||||
|
||||
var data = (from op in organizationPositions
|
||||
join pm in positionMasters on op.PositionMasterId equals pm.Id
|
||||
join oc in organizations on op.OrganizationId equals oc.Id
|
||||
join oc_n in organizationOrganizations on oc.OrganizationOrganizationId equals oc_n.Id
|
||||
join sn in organizationShortNames on oc.OrganizationShortNameId equals sn.Id
|
||||
join pn in positionNumbers on op.PositionNumberId equals pn.Id
|
||||
join pp in positionPaths on pm.PositionPathId equals pp.Id
|
||||
join pps in positionPathSides on pm.PositionPathSideId equals pps.Id into pp_pps_join
|
||||
from pp_pps in pp_pps_join.DefaultIfEmpty()
|
||||
join ex_p in executivePositions on pm.PositionExecutiveId equals ex_p.Id into pm_exp_join
|
||||
from pm_exp in pm_exp_join.DefaultIfEmpty()
|
||||
join ex_p_s in executivePositionSide on pm.PositionExecutiveSideId equals ex_p_s.Id into pm_exp_s_join
|
||||
from pm_exp_s in pm_exp_s_join.DefaultIfEmpty()
|
||||
join pt in positionTypes on pm.PositionTypeId equals pt.Id
|
||||
where ocIdList.Contains((Guid)op.OrganizationId)
|
||||
select new Account1ResultItem
|
||||
{
|
||||
Id = op.Id,
|
||||
RootOcId = ocId,
|
||||
RootOcName = RootOcName,
|
||||
OcId = op.OrganizationId.Value,
|
||||
OcFullName = _profileService.FindOCFullPathWithNewLine(op.OrganizationId.Value, false, suppress: RootOcName),
|
||||
OcName = _profileService.GetOrganizationName(op.OrganizationId.Value),
|
||||
ShortName = sn.Name,
|
||||
PositionNumber = pn.Name,
|
||||
PositionLevel = _profileService.GetPositionLevel(pm.Id),
|
||||
PositionName = pp.Name,
|
||||
PositionSide = pp_pps == null ? "" : $"({pp_pps.Name})",
|
||||
PositionExecutive = pm_exp == null ? "" : pm_exp.Name,
|
||||
PositionExecutiveSide = pm_exp_s == null ? "" : $"({pm_exp_s.Name})",
|
||||
Remark = op.PositionUserNote,
|
||||
OcOrder = oc.OrganizationOrder.Value,
|
||||
PositionType = pt.Name
|
||||
}).ToList();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<List<Account2ResultItem>> GetReport2Query(Guid ocId)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
var ocIdList = _profileService.GetAllIdByRoot(ocId);
|
||||
var RootOcName = _profileService.GetOrganizationNameFullPath(ocId, false, false);
|
||||
|
||||
var organizationPositions = await _context.OrganizationPositions.ToListAsync();
|
||||
var positionMasters = await _context.PositionMasters.ToListAsync();
|
||||
var organizations = await _context.Organizations.ToListAsync();
|
||||
var organizationOrganizations = await _applicationDbContext.OrganizationOrganizations.ToListAsync();
|
||||
var organizationShortNames = await _applicationDbContext.OrganizationShortNames.ToListAsync();
|
||||
var positionNumbers = await _context.PositionNumbers.ToListAsync();
|
||||
var executivePositions = await _applicationDbContext.PositionExecutives.ToListAsync();
|
||||
var executivePositionSide = await _applicationDbContext.PositionExecutiveSides.ToListAsync();
|
||||
var positionPaths = await _applicationDbContext.PositionPaths.ToListAsync();
|
||||
var positionPathSides = await _applicationDbContext.PositionPathSides.ToListAsync();
|
||||
var positionTypes = await _applicationDbContext.PositionTypes.ToListAsync();
|
||||
var profilePositions = await _context.ProfilePositions.ToListAsync();
|
||||
var prefixes = await _context.Prefixes.ToListAsync();
|
||||
var profiles = await _context.Profiles.ToListAsync();
|
||||
var report2 = await _context.Report2s.ToListAsync();
|
||||
|
||||
var profile_data = (from p in _context.Profiles
|
||||
join pf in _context.Prefixes on p.PrefixId equals pf.Id
|
||||
select new
|
||||
{
|
||||
p.Id,
|
||||
p.CitizenId,
|
||||
Prefix = pf.Name,
|
||||
p.FirstName,
|
||||
p.LastName,
|
||||
p.PositionLine,
|
||||
p.Position,
|
||||
p.PositionPathSide,
|
||||
p.PositionType,
|
||||
p.PositionLevel,
|
||||
p.PositionExecutive,
|
||||
p.PositionExecutiveSide,
|
||||
p.PosNo,
|
||||
p.OrganizationShortName,
|
||||
Degree = p.Educations == null || p.Educations.Count == 0 ? "" : $"{p.Educations.OrderBy(x => x.StartDate).Last().Degree}\r\n({p.Educations.OrderBy(x => x.StartDate).Last().Field})",
|
||||
Salary = p.Salaries == null || p.Salaries.Count == 0 ? 0 : p.Salaries.OrderBy(x => x.Date).Last().Amount,
|
||||
SalaryPosition = p.Salaries == null || p.Salaries.Count == 0 ? 0 : p.Salaries.OrderBy(x => x.Date).Last().PositionSalaryAmount,
|
||||
|
||||
}).ToList();
|
||||
|
||||
|
||||
var report2_data = (from org_pos in _context.OrganizationPositions.ToList()
|
||||
join ppos in _context.ProfilePositions.ToList() on org_pos.Id equals ppos.OrganizationPositionId
|
||||
join pf in profile_data.ToList() on ppos.ProfileId equals pf.Id
|
||||
join r_raw in _context.Report2s.ToList() on ppos.Id equals r_raw.ProfilePositionId into r_join
|
||||
from r in r_join.DefaultIfEmpty()
|
||||
select new
|
||||
{
|
||||
//Id = r.Id,
|
||||
ProfilePositionId = ppos.Id,
|
||||
CitizenId = pf.CitizenId,
|
||||
Prefix = pf.Prefix,
|
||||
FirstName = pf.FirstName,
|
||||
LastName = pf.LastName,
|
||||
OrganizationName = r == null ? "" : r.OrganizationOrganization,
|
||||
ShortName = r == null ? pf.OrganizationShortName : r.OrganizationShortName,
|
||||
PositionNumber = r == null ? pf.PosNo : r.PositionNum,
|
||||
PositionPath = r == null ? pf.Position : r.PositionPath,
|
||||
PositionPathSide = r == null ? pf.PositionPathSide : r.PositionPathSide,
|
||||
PositionType = r == null ? pf.PositionType : r.PositionType,
|
||||
PositionLevel = r == null ? pf.PositionLevel : r.PositionLevel,
|
||||
PositionExecutive = r == null ? pf.PositionExecutive : r.PositionExecutive,
|
||||
PositionExecutiveSide = r == null ? pf.PositionExecutiveSide : r.PositionExecutiveSide,
|
||||
OcId = org_pos.Id,
|
||||
OrganizationPositionId = ppos.OrganizationPositionId,
|
||||
Degree = pf.Degree,
|
||||
Salary = pf.Salary,
|
||||
SalaryPosition = pf.SalaryPosition,
|
||||
}).ToList();
|
||||
|
||||
//var report2_data = (from r in _context.Report2s.ToList()
|
||||
// join ppos in _context.ProfilePositions.ToList() on r.ProfilePositionId equals ppos.Id
|
||||
// join org_pos in _context.OrganizationPositions.ToList() on ppos.OrganizationPositionId equals org_pos.Id
|
||||
// join pf in profile_data.ToList() on ppos.ProfileId equals pf.Id
|
||||
// select new
|
||||
// {
|
||||
// Id = r.Id,
|
||||
// ProfilePositionId = r.ProfilePositionId,
|
||||
// CitizenId = pf.CitizenId,
|
||||
// Prefix = pf.Prefix,
|
||||
// FirstName = pf.FirstName,
|
||||
// LastName = pf.LastName,
|
||||
// OrganizationName = r.OrganizationOrganization,
|
||||
// ShortName = r.OrganizationShortName,
|
||||
// PositionNumber = r.PositionNum,
|
||||
// PositionPath = r.PositionPath,
|
||||
// PositionPathSide = r.PositionPathSide,
|
||||
// PositionType = r.PositionType,
|
||||
// PositionLevel = r.PositionLevel,
|
||||
// PositionExecutive = r.PositionExecutive,
|
||||
// PositionExecutiveSide = r.PositionExecutiveSide,
|
||||
// OcId = org_pos.Id,
|
||||
// OrganizationPositionId = ppos.OrganizationPositionId,
|
||||
// Degree = pf.Degree,
|
||||
// Salary = pf.Salary,
|
||||
// SalaryPosition = pf.SalaryPosition,
|
||||
// }).ToList();
|
||||
|
||||
|
||||
|
||||
var data = (from op in organizationPositions
|
||||
join pm in positionMasters on op.PositionMasterId equals pm.Id
|
||||
join oc in organizations on op.OrganizationId equals oc.Id
|
||||
join oc_n in organizationOrganizations on oc.OrganizationOrganizationId equals oc_n.Id
|
||||
join sn in organizationShortNames on oc.OrganizationShortNameId equals sn.Id
|
||||
join pn in positionNumbers on op.PositionNumberId equals pn.Id
|
||||
join pp in positionPaths on pm.PositionPathId equals pp.Id
|
||||
join pps in positionPathSides on pm.PositionPathSideId equals pps.Id into pp_pps_join
|
||||
from pp_pps in pp_pps_join.DefaultIfEmpty()
|
||||
join ex_p in executivePositions on pm.PositionExecutiveId equals ex_p.Id into pm_exp_join
|
||||
from pm_exp in pm_exp_join.DefaultIfEmpty()
|
||||
join ex_p_s in executivePositionSide on pm.PositionExecutiveSideId equals ex_p_s.Id into pm_exp_s_join
|
||||
from pm_exp_s in pm_exp_s_join.DefaultIfEmpty()
|
||||
join pt in positionTypes on pm.PositionTypeId equals pt.Id
|
||||
join rp2 in report2_data.ToList() on op.Id equals rp2.OrganizationPositionId into rp2_join
|
||||
from rp2_dt in rp2_join.DefaultIfEmpty()
|
||||
|
||||
where ocIdList.Contains((Guid)op.OrganizationId)
|
||||
select new Account2ResultItem
|
||||
{
|
||||
Id = op.Id,
|
||||
RootOcId = ocId,
|
||||
RootOcName = RootOcName,
|
||||
OcId = op.OrganizationId.Value,
|
||||
OcFullName = _profileService.FindOCFullPathWithNewLine(op.OrganizationId.Value, false, suppress: RootOcName),
|
||||
OcName = _profileService.GetOrganizationName(op.OrganizationId.Value),
|
||||
ShortName = sn.Name,
|
||||
PositionNumber = pn.Name,
|
||||
PositionLevel = rp2_dt == null ? _profileService.GetPositionLevel(pm.Id) : rp2_dt.PositionLevel,
|
||||
|
||||
PositionName = pp.Name,
|
||||
PositionSide = pp_pps == null ? "" : $"({pp_pps.Name})",
|
||||
PositionExecutive = pm_exp == null ? "" : pm_exp.Name,
|
||||
PositionExecutiveSide = pm_exp_s == null ? "" : $"({pm_exp_s.Name})",
|
||||
Remark = op.PositionUserNote,
|
||||
OcOrder = oc.OrganizationOrder.Value,
|
||||
PositionType = pt.Name,
|
||||
|
||||
|
||||
OcIdNew = rp2_dt == null ? op.OrganizationId.Value : rp2_dt.OcId,
|
||||
OcFullNameNew = _profileService.FindOCFullPathWithNewLine(op.OrganizationId.Value, false, suppress: RootOcName),
|
||||
OcNameNew = rp2_dt == null ? _profileService.GetOrganizationName(op.OrganizationId.Value) : _profileService.GetOrganizationName(rp2_dt.OcId),
|
||||
ShortNameNew = rp2_dt == null ? "" : rp2_dt.ShortName,
|
||||
PositionNumberNew = rp2_dt == null ? "" : rp2_dt.PositionNumber,
|
||||
PositionLevelNew = rp2_dt == null ? "" : rp2_dt.PositionLevel,
|
||||
PositionNameNew = rp2_dt == null ? "" : rp2_dt.PositionPath,
|
||||
PositionSideNew = rp2_dt == null ? "" : rp2_dt.PositionPathSide,
|
||||
PositionExecutiveNew = rp2_dt == null ? "" : rp2_dt.PositionExecutive,
|
||||
PositionExecutiveSideNew = rp2_dt == null ? "" : rp2_dt.PositionExecutiveSide,
|
||||
PositionTypeNew = rp2_dt == null ? "" : rp2_dt.PositionType,
|
||||
|
||||
Prefix = rp2_dt == null ? "" : rp2_dt.Prefix,
|
||||
FirstName = rp2_dt == null ? "" : rp2_dt.FirstName,
|
||||
LastName = rp2_dt == null ? "" : rp2_dt.LastName,
|
||||
Degree = rp2_dt == null ? "" : rp2_dt.Degree,
|
||||
|
||||
Salary = rp2_dt == null ? 0 : (int)rp2_dt.Salary.Value,
|
||||
SalaryPosition = rp2_dt == null ? 0 : (int)rp2_dt.SalaryPosition.Value,
|
||||
|
||||
|
||||
}).ToList();
|
||||
|
||||
return data;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class Account1ResultItem
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public Guid RootOcId { get; set; }
|
||||
|
||||
public string RootOcName { get; set; } = string.Empty;
|
||||
|
||||
public Guid OcId { get; set; }
|
||||
|
||||
public string OcFullName { get; set; } = string.Empty;
|
||||
|
||||
public string OcName { get; set; } = string.Empty;
|
||||
|
||||
public string ShortName { get; set; } = string.Empty;
|
||||
|
||||
public string PositionNumber { get; set; } = string.Empty;
|
||||
|
||||
public string PositionName { get; set; } = string.Empty;
|
||||
|
||||
public string PositionSide { get; set; } = string.Empty;
|
||||
|
||||
public string PositionLevel { get; set; } = string.Empty;
|
||||
|
||||
public string PositionExecutive { get; set; } = string.Empty;
|
||||
|
||||
public string PositionExecutiveSide { get; set; } = string.Empty;
|
||||
|
||||
public string Remark { get; set; } = string.Empty;
|
||||
|
||||
public int OcOrder { get; set; } = 0;
|
||||
|
||||
public int PositionNumberInt { get; set; } = 0;
|
||||
|
||||
public string PositionType { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class Account2ResultItem
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public Guid RootOcId { get; set; }
|
||||
|
||||
public string RootOcName { get; set; } = string.Empty;
|
||||
|
||||
public Guid OcId { get; set; }
|
||||
|
||||
public string OcFullName { get; set; } = string.Empty;
|
||||
|
||||
public string OcName { get; set; } = string.Empty;
|
||||
|
||||
public string ShortName { get; set; } = string.Empty;
|
||||
|
||||
public string PositionNumber { get; set; } = string.Empty;
|
||||
|
||||
public string PositionName { get; set; } = string.Empty;
|
||||
|
||||
public string PositionSide { get; set; } = string.Empty;
|
||||
|
||||
public string PositionLevel { get; set; } = string.Empty;
|
||||
|
||||
public string PositionExecutive { get; set; } = string.Empty;
|
||||
|
||||
public string PositionExecutiveSide { get; set; } = string.Empty;
|
||||
|
||||
public string Remark { get; set; } = string.Empty;
|
||||
|
||||
public int OcOrder { get; set; } = 0;
|
||||
|
||||
public int PositionNumberInt { get; set; } = 0;
|
||||
|
||||
public string PositionType { get; set; } = string.Empty;
|
||||
|
||||
// new
|
||||
public Guid RootOcIdNew { get; set; }
|
||||
|
||||
public string RootOcNameNew { get; set; } = string.Empty;
|
||||
|
||||
public Guid OcIdNew { get; set; }
|
||||
|
||||
public string OcFullNameNew { get; set; } = string.Empty;
|
||||
|
||||
public string OcNameNew { get; set; } = string.Empty;
|
||||
|
||||
public string ShortNameNew { get; set; } = string.Empty;
|
||||
|
||||
public string PositionNumberNew { get; set; } = string.Empty;
|
||||
|
||||
public string PositionNameNew { get; set; } = string.Empty;
|
||||
|
||||
public string PositionSideNew { get; set; } = string.Empty;
|
||||
|
||||
public string PositionLevelNew { get; set; } = string.Empty;
|
||||
|
||||
public string PositionExecutiveNew { get; set; } = string.Empty;
|
||||
|
||||
public string PositionExecutiveSideNew { get; set; } = string.Empty;
|
||||
|
||||
public int PositionNumberIntNew { get; set; } = 0;
|
||||
|
||||
public string PositionTypeNew { get; set; } = string.Empty;
|
||||
|
||||
// name
|
||||
public string Prefix { get; set; } = string.Empty;
|
||||
|
||||
public string FirstName { get; set; } = string.Empty;
|
||||
|
||||
public string LastName { get; set; } = string.Empty;
|
||||
|
||||
public string Degree { get; set; } = string.Empty;
|
||||
|
||||
public int Salary { get; set; } = 0;
|
||||
|
||||
public int SalaryPosition { get; set; } = 0;
|
||||
|
||||
public string FullName { get; set; } = string.Empty;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class OrganizationItem
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public int Order { get; set; } = 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using BMA.EHR.Profile.Service.Models;
|
||||
using Amazon.S3.Model.Internal.MarshallTransformations;
|
||||
using BMA.EHR.Profile.Service.Models;
|
||||
using BMA.EHR.Report.Service.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Text.RegularExpressions;
|
||||
|
|
@ -115,6 +116,33 @@ namespace BMA.EHR.Profile.Service.Services
|
|||
}
|
||||
}
|
||||
|
||||
public string GetOrganizationName(Guid id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var organizations = _context.Organizations.ToList();
|
||||
var organizationOrganizations = _context.OrganizationOrganizations.ToList();
|
||||
|
||||
|
||||
var oc = (from o in organizations
|
||||
join oc_name in organizationOrganizations on o.OrganizationOrganizationId equals oc_name.Id
|
||||
select new
|
||||
{
|
||||
Id = o.Id,
|
||||
Name = oc_name.Name,
|
||||
//o.IsActive,
|
||||
o.ParentId,
|
||||
IsRoot = o.ParentId == null
|
||||
}).FirstOrDefault(x => x.Id == id);
|
||||
|
||||
return oc == null ? "" : oc.Name;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public string GetOrganizationNameFullPath(Guid id, bool showRoot = false, bool descending = false)
|
||||
{
|
||||
try
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue