using Aspose.Cells;
using EyeSoft.Messanging;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.Extensions.Configuration.UserSecrets;
using OASystem.Domain;
using OASystem.Domain.Entities.Customer;
using OASystem.Domain.Entities.Financial;
using OASystem.Domain.Entities.Groups;
using Org.BouncyCastle.Asn1.Cmp;
using System.Collections;
using static OASystem.API.OAMethodLib.GeneralMethod;
using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
using static QRCoder.PayloadGenerator;
using static Quartz.Logging.OperationName;
using static OASystem.API.OAMethodLib.JWTHelper;
using System.Runtime.Intrinsics.Arm;
using OASystem.Domain.Dtos.Statistics;
using OASystem.Domain.AesEncryption;
namespace OASystem.API.Controllers
{
///
/// 系统设置
///
//[Authorize]
[Route("api/[controller]/[action]")]
public class SystemController : ControllerBase
{
private readonly CompanyRepository _syscomRep;
private readonly DepartmentRepository _sysDepRep;
private readonly UsersRepository _userRep;
private readonly IMapper _mapper;
private readonly SqlSugarClient _sqlSugar;
private readonly MessageRepository _messageRep;
private readonly SetDataRepository _setDataRepository;
private readonly SystemMenuPermissionRepository _SystemMenuPermissionRepository;
private readonly CompanyRepository _CompanyRepository;
private readonly PageFunctionPermissionRepository _PageFunctionPermissionRepository;
private readonly SystemMenuAndFunctionRepository _SystemMenuAndFunctionRepository;
private readonly JobPostAuthorityRepository _JobPostAuthorityRepository;
private readonly JobPostRepository _jobRep;
private readonly SetDataTypeRepository _setDataTypeRep;
private readonly UserAuthorityRepository _UserAuthorityRepository;
private readonly List _operationTypeList = new List() { 1, 2, 3, 4, 5 }; //操作通知所属类型
private readonly List _taskTypeList = new List() { 6 };//任务通知 TaskNotification
public SystemController(
CompanyRepository syscom,
DepartmentRepository sysDepRep,
UsersRepository userRep,
IMapper mapper,
SqlSugarClient sqlSugar,
SetDataRepository setDataRepository,
CompanyRepository companyRepository,
SystemMenuPermissionRepository systemMenuPermissionRepository,
PageFunctionPermissionRepository pageFunctionPermissionRepository,
SystemMenuAndFunctionRepository systemMenuAndFunctionRepository,
JobPostAuthorityRepository jobPostAuthorityRepository,
JobPostRepository jobRep,
UserAuthorityRepository userAuthorityRepository,
MessageRepository messageRep,
SetDataTypeRepository setDataTypeRep
)
{
_syscomRep = syscom;
_sysDepRep = sysDepRep;
_messageRep = messageRep;
_userRep = userRep;
_mapper = mapper;
_sqlSugar = sqlSugar;
_setDataRepository = setDataRepository;
_CompanyRepository = companyRepository;
_SystemMenuPermissionRepository = systemMenuPermissionRepository;
_PageFunctionPermissionRepository = pageFunctionPermissionRepository;
_SystemMenuAndFunctionRepository = systemMenuAndFunctionRepository;
_JobPostAuthorityRepository = jobPostAuthorityRepository;
_UserAuthorityRepository = userAuthorityRepository;
_jobRep = jobRep;
_setDataTypeRep = setDataTypeRep;
}
#region 消息
///
/// 获取消息列表-整合版
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task PsotMsgPageList(MsgDto dto)
{
var msgData = await _messageRep.GetMsgList(dto);
if (msgData.Code != 0)
{
return Ok(JsonView(false, msgData.Msg));
}
return Ok(JsonView(msgData.Data));
}
#region 消息列表 - 分开
///
/// 系统消息
/// 消息类型 2024-03-06 14:37
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task PotsMsgTypeData(MsgTypeDto dto)
{
if (dto.PortType < 1 || dto.PortType > 3)
{
return Ok(JsonView(false, "请输入有效的PortType参数。1 Web 2 Android 3 IOS"));
}
if (dto.UserId < 1)
{
return Ok(JsonView(false, "请输入有效的UserId参数。"));
}
var msgData = await _messageRep.PotsMsgTypeData(dto);
if (msgData.Code != 0)
{
return Ok(JsonView(400, msgData.Msg, new string[] { }));
}
return Ok(JsonView(true, msgData.Msg, msgData.Data));
}
///
/// 系统消息
/// 消息List 2024-03-06 14:54
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task PotsMessagePageList(PotsMessagePageListDto dto)
{
#region 参数验证
if (dto.PortType < 1 || dto.PortType > 3)
{
return Ok(JsonView(false, "请输入有效的PortType参数。1 Web 2 Android 3 IOS"));
}
var typeData = await _sqlSugar.Queryable().Where(it => it.STid == 77).Select(it => it.Id).ToListAsync();
if (typeData.Count < 0)
{
return Ok(JsonView(false, "消息类型不存在"));
}
if (!typeData.Contains(dto.Type))
{
return Ok(JsonView(false, "请输入有效的Type参数。1021 团组操作通知 1020 任务操作通知 "));
}
if (dto.UserId < 1)
{
return Ok(JsonView(false, "请输入有效的UserId参数。"));
}
if (dto.ReadStatus < 1 || dto.ReadStatus > 3)
{
return Ok(JsonView(false, "请输入有效的ReadStatus参数。1 全部(包含已读/未读) 2 未读 3 已读"));
}
#endregion
//userId
string msgSqlWhere = $" And smra.ReadableUId = {dto.UserId}";
//消息类型
string typeStr = "";
List messageTypeViews = AppSettingsHelper.Get("MessageNotificationType");
if (dto.Type == 1020) //任务操作通知
{
typeStr = String.Join(",", messageTypeViews.Where(it => it.TypeId == 1020).FirstOrDefault().MsgTypeIds.ToList());
}
else if (dto.Type == 1021)//团组操作通知
{
typeStr = String.Join(",", messageTypeViews.Where(it => it.TypeId == 1021).FirstOrDefault().MsgTypeIds.ToList());
}
else if (dto.Type == 1022)//公告通知
{
typeStr = String.Join(",", messageTypeViews.Where(it => it.TypeId == 1022).FirstOrDefault().MsgTypeIds.ToList());
}
if (!string.IsNullOrEmpty(typeStr))
{
msgSqlWhere += $" And sm.Type In ({typeStr})";
}
//是否已读处理 1 全部(包含已读/未读) 2 未读 3 已读
if (dto.ReadStatus == 1) msgSqlWhere += "";
else if (dto.ReadStatus == 2) msgSqlWhere += $" And smra.IsRead = {0}";
else if (dto.ReadStatus == 3) msgSqlWhere += $" And smra.IsRead = {1}";
string msgSql = string.Format(@"Select * From(
Select row_number() over(order by sm.ReleaseTime Desc) as RowNumber,
sm.Id,sm.Type,sm.Title,sm.Content,sd.DepName issuerDep,su.CnName issuerUser,
sm.ReleaseTime,smra.ReadableUId,smra.IsRead,sm.DiId,sm.Param
From Sys_Message sm
Inner Join Sys_MessageReadAuth smra On sm.Id = smra.MsgId
Inner Join Sys_Users su On sm.IssuerId = su.Id
Inner Join Sys_Department sd On su.DepId = sd.Id
Inner Join Sys_Users suAuth On smra.ReadableUId = suAuth.Id
Where sm.IsDel = 0
And smra.IsDel = 0 {0}
) Temp", msgSqlWhere);
try
{
RefAsync totalCount = 0;
var data = await _sqlSugar.SqlQueryable(msgSql).ToPageListAsync(dto.PageIndex, dto.PageSize, totalCount);
return Ok(JsonView(true, "操作成功!", data, totalCount));
}
catch (Exception ex)
{
return Ok(JsonView(false, ex.Message));
}
}
///
/// 系统消息
/// 获取消息未读条数
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task PotsMessageUnreadTotalCount(PotsMessageUnreadTotalCountDto dto)
{
#region 参数验证
if (dto.UserId < 1)
{
return Ok(JsonView(false, "请输入有效的UserId参数。"));
}
#endregion
try
{
int messageUnReadCount = 0;
int announcementUnReadCount = 0;
var data = await _messageRep.GetUnReadCount(dto.UserId);
if (data != null)
{
messageUnReadCount = data;
}
var data1 = await _messageRep.GetAnnouncementUnReadCount(dto.UserId);
if (data1 != null)
{
announcementUnReadCount = data1;
}
return Ok(JsonView(true, "操作成功!", new { messageUnReadCount = messageUnReadCount, announcementUnReadCount = announcementUnReadCount }));
}
catch (Exception ex)
{
return Ok(JsonView(false, ex.Message));
}
}
#endregion
///
/// 获取消息详细信息
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task PostMsgInfo(MsgInfoDto dto)
{
if (dto.PortType < 1 || dto.PortType > 3)
{
return Ok(JsonView(false, "请输入有效的PortType参数。1 Web 2 Android 3 IOS"));
}
var msgData = await _messageRep.GetMsgInfo(dto);
if (msgData.Code != 0)
{
return Ok(JsonView(false, msgData.Msg));
}
return Ok(JsonView(true, "操作成功!", msgData.Data));
}
///
/// 消息设置已读
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task SetMessageRead(MsgSetReadDto dto)
{
var msgData = await _messageRep.SetMsgRead(dto);
if (msgData.Code != 0)
{
return Ok(JsonView(false, msgData.Msg));
}
return Ok(JsonView(true));
}
///
/// 消息 删除
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task DeleMsg(MsgDeleteDto dto)
{
var msgData = await _messageRep.DelMsg(dto);
if (msgData.Code != 0)
{
return Ok(JsonView(false, msgData.Msg));
}
return Ok(JsonView(true));
}
#endregion
#region 数据类型资料
///
/// 根据类型查询数据
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task QuerySetData(SetDataDto dto)
{
try
{
if (dto.DataType == 0)
{
return Ok(JsonView(false, "请传类型Id!"));
}
var setData = _setDataRepository.QueryDto(s => s.STid == dto.DataType && s.IsDel == 0).ToList();
if (setData.Count == 0)
{
return Ok(JsonView(false, "暂无数据!"));
}
return Ok(JsonView(true, "查询成功!", setData));
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 根据类型查询数据(Array)
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public IActionResult QuerySetDataInitByArr(QuerySetDataInitByArr Dto)
{
var DbQuery = _setDataRepository.QueryDto(s => Dto.DataTypeArr.Contains(s.STid)).ToList();
var GroupResult = DbQuery.GroupBy(x => x.STid).Select(x => new
{
key = x.Key,
Arr = x.ToList()
});
return Ok(JsonView(true, "查询成功!", GroupResult));
}
///
/// 数据类型表查询
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task QuerySetDataType(SetDataTypeDto dto)
{
try
{
Result setDataType = await _setDataTypeRep.QuerySetDataType(dto);
if (setDataType.Code == 0)
{
return Ok(JsonView(true, "查询成功", setDataType.Data));
}
else
{
return Ok(JsonView(false, setDataType.Msg));
}
}
catch (Exception)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 数据类型表操作(Status:1.新增,2.修改)
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task OperationSetDataType(OperationSetDataTypeDto dto)
{
try
{
if (dto.Name == "")
{
return Ok(JsonView(false, "请检查类型名称是否填写!"));
}
Result result = await _setDataTypeRep.OperationSetDataType(dto);
if (result.Code != 0)
{
return Ok(JsonView(false, result.Msg));
}
return Ok(JsonView(true, result.Msg));
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 数据类型表操作删除
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task DelSetDataType(DelSetDataTypeDto dto)
{
try
{
var res = await _setDataTypeRep.SoftDeleteByIdAsync(dto.Id.ToString(), dto.DeleteUserId);
if (!res)
{
return Ok(JsonView(false, "删除失败"));
}
return Ok(JsonView(true, "删除成功!"));
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
#endregion
#region 数据类型板块
///
/// 数据类型板块表查询
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task QuerySetDataInfo(SetDataIDto dto)
{
try
{
Result setData = await _setDataRepository.QuerySetData(dto);
if (setData.Code == 0)
{
return Ok(JsonView(true, "查询成功", setData.Data));
}
else
{
return Ok(JsonView(false, setData.Msg));
}
}
catch (Exception)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 数据类型板块表操作(Status:1.新增,2.修改)
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task OperationSetData(OperationSetDataDto dto)
{
try
{
if (dto.Name == "")
{
return Ok(JsonView(false, "请检查板块名称是否填写!"));
}
Result result = await _setDataRepository.OperationSetData(dto);
if (result.Code != 0)
{
return Ok(JsonView(false, result.Msg));
}
return Ok(JsonView(true, result.Msg));
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 数据类型表操作删除
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task DelSetData(DelSetDataDto dto)
{
try
{
var res = await _setDataRepository.SoftDeleteByIdAsync(dto.Id.ToString(), dto.DeleteUserId);
if (!res)
{
return Ok(JsonView(false, "删除失败"));
}
return Ok(JsonView(true, "删除成功!"));
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
#endregion
#region 企业操作
///
/// 查询企业数据
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task getCompanyList(DtoBase dto)
{
if (dto.PortType == 1)
{
var CompanyDataResult = _CompanyRepository.GetCompanyData();
if (CompanyDataResult.Code != 0)
{
return Ok(JsonView(CompanyDataResult.Msg));
}
List companyListView = _mapper.Map>(CompanyDataResult.Data);
for (int i = 0; i < companyListView.Count; i++)
{
if (companyListView[i].ParentCompanyId != 0)
{
companyListView[i].ParentCompanyName = companyListView.Find(x => x.Id == companyListView[i].ParentCompanyId).CompanyName;
}
if (companyListView[i].ContactUserId != 0)
{
var user = _userRep.QueryDto(x => x.Id == companyListView[i].ContactUserId).ToList();
if (user.Count != 0)
{
companyListView[i].ContactUserName = user[0].CnName;
}
}
}
return Ok(JsonView(true, "查询成功!", companyListView));
}
else if (dto.PortType == 2)
{
var CompanyDataResult = _CompanyRepository.GetCompanyData();
if (CompanyDataResult.Code != 0)
{
return Ok(JsonView(CompanyDataResult.Msg));
}
return Ok(JsonView(true, "查询成功!", CompanyDataResult.Data));
}
else if (dto.PortType == 3)
{
return Ok(JsonView(false, "暂无数据!"));
}
else
{
return Ok(JsonView(false, "暂无数据!"));
}
}
///
/// 添加企业数据
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task AddCompany(AddCompanyDto dto)
{
if (string.IsNullOrWhiteSpace(dto.CompanyName) || dto.CreateUserId == 0 || string.IsNullOrWhiteSpace(dto.CompanyCode))
{
return Ok(JsonView(false, "请检查信息是否输入完整!"));
}
else if (string.IsNullOrWhiteSpace(dto.Tel))
{
return Ok(JsonView(false, "请检查联系方式是否输入正确!"));
}
else
{
Sys_Company _Company = _mapper.Map(dto);
Result data = await _syscomRep.AddCompany(_Company);
if (data.Code != 0)
{
return Ok(JsonView(false, "添加失败!"));
}
return Ok(JsonView(true, "添加成功"));
}
}
///
/// 企业修改
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task EditCompany(EditCompanyDto dto)
{
if (string.IsNullOrWhiteSpace(dto.CompanyName) || string.IsNullOrWhiteSpace(dto.CompanyCode) || string.IsNullOrWhiteSpace(dto.Address) || dto.ContactUserId == 0)
{
return Ok(JsonView(false, "请检查信息是否输入完整!"));
}
else if (string.IsNullOrWhiteSpace(dto.Tel))
{
return Ok(JsonView(false, "请检查联系方式是否输入正确!"));
}
else
{
bool res = await _syscomRep.UpdateAsync(a => a.Id == dto.Id, a => new Sys_Company
{
CompanyName = dto.CompanyName,
CompanyCode = dto.CompanyCode,
Address = dto.Address,
ParentCompanyId = dto.ParentCompanyId,
Tel = dto.Tel,
ContactUserId = dto.ContactUserId,
Remark = dto.Remark,
});
if (!res) { return Ok(JsonView(false, "修改失败")); }
return Ok(JsonView(true, "修改成功!"));
}
}
///
/// 企业删除
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task DelCompany(DelCompanyDto dto)
{
bool res = await _syscomRep.SoftDeleteAsync(dto.Id.ToString());
if (!res) { return Ok(JsonView(false, "删除失败")); }
return Ok(JsonView(true, "删除成功"));
}
#endregion
#region 部门操作
///
/// 查询部门数据
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task QueryDepartmentList(DepartmentDto dto)
{
try
{
if (dto.PortType == 1)
{
if (dto.CompanyId != 0)
{
var result = _sysDepRep.QueryDto(s => s.CompanyId == dto.CompanyId).ToList();
if (result.Count == 0)
{
return Ok(JsonView(false, "暂无数据!"));
}
for (int i = 0; i < result.Count; i++)
{
if (result[i].ParentDepId != 0)
{
result[i].ParentDepName = result.Find(x => x.Id == result[i].ParentDepId).ParentDepName;
}
var company = _sysDepRep.QueryDto(s => s.Id == result[i].CompanyId).ToList();
if (company.Count != 0)
{
result[i].CompanyName = company[0].CompanyName;
}
return Ok(JsonView(true, "查询成功!", result));
}
}
else
{
var result = _sysDepRep.QueryDto(s => s.IsDel <= 1).ToList();
if (result.Count == 0)
{
return Ok(JsonView(false, "暂无数据!"));
}
for (int i = 0; i < result.Count; i++)
{
if (result[i].ParentDepId != 0)
{
result[i].ParentDepName = result.Find(x => x.Id == result[i].ParentDepId).ParentDepName;
}
var company = _sysDepRep.QueryDto(s => s.Id == result[i].CompanyId).ToList();
if (company.Count != 0)
{
result[i].CompanyName = company[0].CompanyName;
}
}
return Ok(JsonView(true, "查询成功!", result));
}
return Ok(JsonView(false, "暂无数据!"));
}
else if (dto.PortType == 2)
{
var result = _sysDepRep.QueryDto(s => s.CompanyId == dto.CompanyId).ToList();
if (result.Count == 0)
{
return Ok(JsonView(400, "暂无数据!", new List()));
}
return Ok(JsonView(true, "查询成功!", result));
}
else if (dto.PortType == 3)
{
return Ok(JsonView(false, "暂无数据!"));
}
else
{
return Ok(JsonView(false, "暂无数据!"));
}
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 部门添加
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task AddDepartment(AddDepartmentDto dto)
{
try
{
if (dto.CreateUserId == 0 || string.IsNullOrWhiteSpace(dto.DepName) || dto.CompanyId == 0 || string.IsNullOrWhiteSpace(dto.DepCode))
{
return Ok(JsonView(false, "请检查信息是否输入完整!"));
}
else
{
Sys_Department _Department = _mapper.Map(dto);
int id = await _sysDepRep.AddAsyncReturnId(_Department);
if (id == 0)
{
return Ok(JsonView(false, "添加失败!"));
}
return Ok(JsonView(true, "添加成功!", new { Id = id }));
}
}
catch (Exception)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 部门修改
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task EditDepartment(EditDepartmentDto dto)
{
try
{
if (dto.Id == 0 || string.IsNullOrWhiteSpace(dto.DepName) || dto.CompanyId == 0 || string.IsNullOrWhiteSpace(dto.DepCode))
{
return Ok(JsonView(false, "请检查信息是否输入完整!"));
}
else
{
bool res = await _sysDepRep.UpdateAsync(a => a.Id == dto.Id, a => new Sys_Department
{
CompanyId = dto.CompanyId,
DepCode = dto.DepCode,
DepName = dto.DepName,
ParentDepId = dto.ParentDepId,
Remark = dto.Remark,
});
if (!res)
{
return Ok(JsonView(false, "修改失败!"));
}
return Ok(JsonView(true, "修改成功!"));
}
}
catch (Exception)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 部门删除
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task DelDepartment(DelDepartmentDto dto)
{
try
{
if (dto.Id == 0)
{
return Ok(JsonView(-1, "请检查信息是否输入完整!", null));
}
else
{
bool res = await _sysDepRep.SoftDeleteAsync(dto.Id.ToString());
if (!res)
{
return Ok(JsonView(false, "删除失败!"));
}
return Ok(JsonView(true, "删除成功!"));
}
}
catch (Exception)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
#endregion
#region 岗位板块
///
/// 岗位查询
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task QueryJobPost(QueryJobPostDto dto)
{
try
{
if (dto.PortType == 1)
{
string sqlWhere = string.Empty;
if (dto.CompanyId != 0)
{
sqlWhere += string.Format(@" And jp.CompanyId={0}", dto.CompanyId);
}
if (dto.DepId != 0)
{
sqlWhere += string.Format(@" And jp.DepId={0}", dto.DepId);
}
sqlWhere += string.Format(@" And jp.IsDel={0}", 0);
if (!string.IsNullOrEmpty(sqlWhere.Trim()))
{
Regex r = new Regex("And");
sqlWhere = r.Replace(sqlWhere, "Where", 1);
}
List jobList = await _jobRep.QueryJobPost(sqlWhere);
List List = _mapper.Map>(jobList);
if (jobList.Count == 0)
{
return Ok(JsonView(false, "暂无数据!"));
}
return Ok(JsonView(true, "查询成功!", jobList));
}
else if (dto.PortType == 2)
{
var result = _jobRep.QueryDto(s => s.CompanyId == dto.CompanyId && s.DepId == dto.DepId).ToList();
if (result.Count == 0)
{
return Ok(JsonView(false, "暂无数据!"));
}
return Ok(JsonView(true, "查询成功!", result));
}
else if (dto.PortType == 3)
{
return Ok(JsonView(false, "暂无数据!"));
}
else
{
return Ok(JsonView(false, "暂无数据!"));
}
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 添加岗位
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task AddJobPost(AddJobPostDto dto)
{
try
{
Sys_JobPost sys_Job = _mapper.Map(dto);
int id = await _jobRep.AddAsyncReturnId(sys_Job);
if (id == 0)
{
return Ok(JsonView(false, "添加失败"));
}
return Ok(JsonView(true, "添加成功", new { Id = id }));
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 修改岗位
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task EditJobPost(EditJobPostDto dto)
{
try
{
bool res = await _jobRep.UpdateAsync(a => a.Id == dto.Id, a => new Sys_JobPost
{
CompanyId = dto.CompanyId,
DepId = dto.DepId,
JobName = dto.JobName,
Remark = dto.Remark,
});
if (!res)
{
return Ok(JsonView(false, "修改失败"));
}
return Ok(JsonView(true, "修改成功"));
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 删除岗位
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task DelJobPost(DelJobPostDto dto)
{
try
{
bool res = await _jobRep.SoftDeleteAsync(dto.Id.ToString());
if (!res)
{
return Ok(JsonView(false, "删除失败!"));
}
return Ok(JsonView(true, "删除成功"));
}
catch (Exception)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
#endregion
#region 用户操作
/////
///// 用户表指定字段加密
/////
/////
/////
//[HttpPost]
//[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
//public async Task UserBatchEncryption()
//{
// var items = await _sqlSugar.Queryable().Select(x => new Sys_Users() { Id = x.Id, Phone = x.Phone, UrgentPhone = x.UrgentPhone, IDCard = x.IDCard }).ToListAsync();
// foreach (var item in items) EncryptionProcessor.EncryptProperties(item);
// var updItems = await _sqlSugar.Updateable(items).UpdateColumns(x => new { x.Phone, x.UrgentPhone, x.IDCard }).ExecuteCommandAsync();
// return Ok(JsonView(updItems));
//}
///
/// 查询所有员工名称
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task GetUserNameList(DtoBase dto)
{
var result = _userRep.GetUserNameList(dto.PortType);
if (result.Result.Code != 0)
{
return Ok(JsonView(false, "暂无数据!"));
}
return Ok(JsonView(true, "查询成功!", result.Result.Data));
}
///
/// 查询所有员工(web)
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task GetUserList(DtoBase dto)
{
var result = _userRep.GetUserList(dto.PortType, string.Empty);
if (result.Result.Code != 0)
{
return Ok(JsonView(false, "暂无数据!"));
}
return Ok(JsonView(true, "查询成功!", result.Result.Data));
}
///
/// 查询用户数据
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task QueryUserList(UserDto dto)
{
string sqlWhere = string.Format(" Where su.IsDel = 0 ");
if (dto.CompanyId != 0)
{
sqlWhere += string.Format(@" And su.CompanyId={0}", dto.CompanyId);
}
if (dto.DepId != 0)
{
sqlWhere += string.Format(@" And su.DepId={0}", dto.DepId);
}
if (dto.JobPostId != 0)
{
sqlWhere += string.Format(@" And su.JobPostId={0}", dto.JobPostId);
}
List _userList = await _userRep.QueryUser(sqlWhere);
if (_userList.Count == 0)
{
return Ok(JsonView(400, "暂无数据!", new List()));
}
foreach (var item in _userList) EncryptionProcessor.DecryptProperties(item);
List userList = _mapper.Map>(_userList);
return Ok(JsonView(true, "查询成功!", userList));
}
///
/// 员工信息 个人详细信息
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task UserInfo(UserInfoDto dto)
{
if (dto.Id < 1) return Ok(JsonView(false, "请选择有效的userId!"));
if (dto.PortType < 1 || dto.PortType > 3) return Ok(JsonView(false, MsgTips.Port));
var _view = await _sqlSugar.Queryable()
.Where(x => x.IsDel == 0 && x.Id == dto.Id)
.FirstAsync();
//解密
EncryptionProcessor.DecryptProperties(_view);
var data = new {
_view.Id,
_view.CnName,
_view.EnName,
_view.Number,
_view.CompanyId,
_view.DepId,
_view.JobPostId,
_view.Password,
_view.Sex,
_view.Ext,
_view.Phone,
_view.UrgentPhone,
_view.Email,
_view.Address,
_view.Edate,
//_view.Seniority,
_view.Birthday,
_view.IDCard,
_view.StartWorkDate,
_view.GraduateInstitutions,
_view.Professional,
_view.Education,
_view.TheOrAdultEducation,
_view.MaritalStatus,
_view.HomeAddress,
_view.UsePeriod,
_view.WorkExperience,
_view.Certificate,
//_view.QiyeChatUserId,
_view.Remark
};
return Ok(JsonView(true, "操作成功!", data));
}
///
/// 员工信息 All信息修改
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task EditUserInfo(EditUserInfoDto _dto)
{
EditUserInfoDtoValidator validator = new EditUserInfoDtoValidator();
var validatorRes = await validator.ValidateAsync(_dto);
if (!validatorRes.IsValid)
{
var errors = new StringBuilder();
foreach (var error in validatorRes.Errors) errors.AppendLine(error.ErrorMessage);
return Ok(JsonView(false, errors.ToString()));
}
var userInfo = _mapper.Map(_dto);
if (_dto.CurrUserId < 1) return Ok(JsonView(false, "暂无修改权限!"));
//修改权限验证 指定人员 信息部门(4)和人事部刘一茹( 230)、赖红燕(309)
List userIds = new List() {
4 ,//管理员
5 ,//杨俊霄
117 ,//人事审核号
208 ,//雷怡
230 ,//刘一茹
233 ,//刘华举
234 ,//蒋金辰
235 ,//袁榕烽
309 ,//赖红燕
};
if (!userIds.Contains(_dto.CurrUserId)) return Ok(JsonView(false, "暂无修改权限!"));
//加密
EncryptionProcessor.EncryptProperties(userInfo);
var res = await _sqlSugar.Updateable(userInfo)
.IgnoreColumns(x => new
{
x.QiyeChatUserId,
x.Rdate,
x.Seniority,
x.HrAudit,
x.CreateUserId,
x.CreateTime,
x.DeleteUserId,
x.DeleteTime,
x.IsDel
})
.Where(x => x.Id == _dto.Id)
.ExecuteCommandAsync();
if (res > 0) return Ok(JsonView(true, "操作成功!"));
return Ok(JsonView(false, "操作失败!"));
}
///
/// 修改用户信息(上级修改/分配 公司、部门、岗位、工号等信息)
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task EditUser(EditUserDto dto)
{
if(dto.CurrUserId < 1) return Ok(JsonView(false, "暂无修改权限!"));
//修改权限验证 指定人员 信息部门(4)和人事部刘一茹( 230)、赖红燕(309)
var userIds = new List() {
4 ,//管理员
5 ,//杨俊霄
117 ,//人事审核号
208 ,//雷怡
230 ,//刘一茹
233 ,//刘华举
234 ,//蒋金辰
235 ,//袁榕烽
309 ,//赖红燕
};
if (!userIds.Contains(dto.CurrUserId)) return Ok(JsonView(false, "暂无修改权限!"));
bool res = await _userRep.UpdateAsync(a => a.Id == dto.Id, a => new Sys_Users
{
Number = dto.Number,
CompanyId = dto.CompanyId,
DepId = dto.DepId,
JobPostId = dto.JobPostId,
Ext = dto.Ext,
UsePeriod = dto.UsePeriod,
//HrAudit = dto.HrAudit
});
if (!res)
{
return Ok(JsonView(false, "修改失败!"));
}
return Ok(JsonView(true, "修改成功!"));
}
///
/// 修改用户信息(登录用户修改个人信息)
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task EditMyUser(EditMyUserDto dto)
{
if (string.IsNullOrWhiteSpace(dto.CnName) ||
string.IsNullOrWhiteSpace(dto.Address) ||
string.IsNullOrWhiteSpace(dto.IDCard) ||
dto.Sex != 0 && dto.Sex != 1 ||
string.IsNullOrWhiteSpace(dto.MaritalStatus) ||
string.IsNullOrWhiteSpace(dto.HomeAddress) ||
dto.Birthday >= DateTime.Now.AddYears(-1))
{
return Ok(JsonView(false, "请完善你的个人信息!"));
}
else if (string.IsNullOrWhiteSpace(dto.GraduateInstitutions) ||
string.IsNullOrWhiteSpace(dto.Professional) ||
dto.Education == 0 ||
string.IsNullOrWhiteSpace(dto.GraduateInstitutions))
{
return Ok(JsonView(false, "请完善你的学历信息!"));
}
else if (string.IsNullOrWhiteSpace(dto.Phone) ||
string.IsNullOrWhiteSpace(dto.UrgentPhone) ||
string.IsNullOrWhiteSpace(dto.Email))
{
return Ok(JsonView(false, "请检查联系方式、紧急联系人及邮箱输写是否正确!"));
}
else
{
//指定字段加密
var phone = AesEncryptionHelper.Encrypt(dto.Phone);
var urgentPhone = AesEncryptionHelper.Encrypt(dto.UrgentPhone);
var IDCard = AesEncryptionHelper.Encrypt(dto.IDCard);
bool res = await _userRep.UpdateAsync(a => a.Id == dto.Id, a => new Sys_Users
{
CnName = dto.CnName,
EnName = dto.EnName,
Sex = dto.Sex,
Phone = phone,
UrgentPhone = urgentPhone,
Email = dto.Email,
Address = dto.Address,
Edate = dto.Edate,
Birthday = dto.Birthday,
IDCard = IDCard,
GraduateInstitutions = dto.GraduateInstitutions,
Professional = dto.Professional,
Education = dto.Education,
TheOrAdultEducation = dto.TheOrAdultEducation,
MaritalStatus = dto.MaritalStatus,
HomeAddress = dto.HomeAddress,
WorkExperience = dto.WorkExperience,
Certificate = dto.Certificate
});
if (!res)
{
return Ok(JsonView(false, "修改失败!"));
}
return Ok(JsonView(true, "修改成功!"));
}
}
///
/// 删除用户信息
/// 即为离职
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task PostUserDelById(UserDelDto dto)
{
if (dto == null)
{
return Ok(JsonView(false, "参数不能为空!"));
}
var _Users = _sqlSugar.Queryable().First(a => a.IsDel == 0 && a.Id == dto.Id);
if (_Users != null)
{
var sys_UsersList = _sqlSugar.Queryable().Where(a => a.IsDel == 0 && a.CompanyId == _Users.CompanyId).ToList();
if (sys_UsersList.Count == 1)
{
return Ok(JsonView(false, "该人员为公司最后一位,不可删除!"));
}
}
bool res = await _userRep.UpdateAsync(a => a.Id == dto.Id, a => new Sys_Users
{
IsDel = 1,
DeleteUserId = dto.OperateUserId,
DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
Rdate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
});
if (!res)
{
return Ok(JsonView(false, "操作失败!"));
}
return Ok(JsonView(true, "操作成功!"));
}
///
/// 员工信息
/// 人事审核
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task PersonnelAudit(PersonnelAuditDto dto)
{
if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数!"));
if (dto.Id < 1) return Ok(JsonView(false, "请传入有效的Id参数!"));
if (dto.IsAudit < 1 || dto.IsAudit > 2) return Ok(JsonView(false, "请传入有效的IsAudit参数!1:通过 2拒绝"));
bool res = await _userRep.UpdateAsync(a => a.Id == dto.Id, a => new Sys_Users { HrAudit = dto.IsAudit });
if (res)
{
//审核成功添加员工基础页面权限
var userData = _sqlSugar.Queryable().Where(it => it.Id == dto.Id).First();
int depId = 0, postId = 0;
if (userData != null) { depId = userData.DepId; postId = userData.JobPostId; }
bool s = DefaultPostAuth(depId, postId, dto.Id, dto.UserId);
string str = $"基础页面权限添加失败!";
if (s) str = $"基础页面权限添加成功!";
return Ok(JsonView(true, $"操作成功!{str}"));
}
return Ok(JsonView(false, "操作失败!"));
}
///
/// 部门查询员工
///
///
///
[HttpPost]
public IActionResult QueryUserByDepart(QueryUserByDepartDto dto)
{
var jw = JsonView(false);
if (dto.DepartId < 1)
{
jw.Msg = "请传入正确的部门id";
return Ok(jw);
}
string sql = $@"SELECT * FROM Sys_Users su WHERE su.JobPostId in (SELECT id FROM Sys_JobPost sj WHERE sj.IsDel = 0 AND sj.DepId = {dto.DepartId} )
AND su.IsDel = 0 ";
var result = _sqlSugar.SqlQueryable(sql).Select(x => new
{
x.Id,
x.CnName,
x.EnName
}).ToList();
jw.Data = result;
jw.Code = 200;
jw.Msg = "获取成功!";
return Ok(jw);
}
#endregion
#region 权限模块
///
/// 权限数据页面初始化
///
///
///
//[Authorize]
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task GetAuth(AuthDto dto)
{
Result result = new Result();
//模块数据
var setDataResult = await _setDataRepository.GetSySDefultModule();
if (setDataResult.Code != 0)
{
return Ok(JsonView(setDataResult.Msg));
}
//操作方式
var PageOperation = _PageFunctionPermissionRepository.QueryDto(x => x.IsEnable == 1).ToList();
//获取所有关联页面
var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto().ToList();
//页面数据
var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto(x => x.Mid == dto.moduleId && x.IsEnable == 1).ToList();
if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0)
{
return Ok(JsonView("暂无数据"));
}
ArrayList viewData = new ArrayList();
//组合页面数据
foreach (var item in SystemMenuPermissionData)
{
ArrayList ids = new ArrayList();
foreach (var viewop in PageOperation)
{
var op = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.SmId == item.Id && x.FId == viewop.Id);
if (op != null)
{
ids.Add(viewop.Id);
}
}
viewData.Add(new
{
Id = item.Id,
Mid = item.Mid,
Name = item.Name,
SystemMenuCode = item.SystemMenuCode,
opList = ids,
selList = new string[0]
});
}
//公司数据
var CompanyDataResult = _CompanyRepository.GetCompanyData();
if (CompanyDataResult.Code != 0)
{
return Ok(JsonView(CompanyDataResult.Msg));
}
result.Code = 0;
result.Msg = "成功!";
var Dyresult = new
{
setDataResult = setDataResult.Data,
CompanyDataResult = CompanyDataResult.Data,
SystemMenuPermissionData = viewData,
PageOperation = PageOperation,
};
return Ok(JsonView(200, "成功!", Dyresult));
}
///
/// 获取职务权限
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public IActionResult QueryJobAuth(QueryJobAuthDto dto)
{
//选中的操作权限
var DBdata = _JobPostAuthorityRepository.QueryDto(x => x.JpId == dto.jobid).ToList();
var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto(x => x.Mid == dto.moduleId).ToList();
if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0)
{
return Ok(JsonView("暂无数据"));
}
//所有操作
var PageOperation = _PageFunctionPermissionRepository.QueryDto().ToList();
//获取所有关联页面
var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto().ToList();
ArrayList viewData = new ArrayList();
//组合页面数据
foreach (var item in SystemMenuPermissionData)
{
ArrayList ids = new ArrayList();
foreach (var viewop in PageOperation)
{
var op = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.SmId == item.Id && x.FId == viewop.Id);
if (op != null)
{
ids.Add(viewop.Id);
}
}
//获取本职务的页面拥有的权限
var DBwhere = DBdata.Where(x => x.SmId == item.Id && x.JpId == dto.jobid).ToList();
viewData.Add(new
{
Id = item.Id,
Mid = item.Mid,
Name = item.Name,
SystemMenuCode = item.SystemMenuCode,
opList = ids,
selList = DBwhere.Select(x => x.FId)
});
}
return Ok(JsonView(200, "成功!", viewData));
}
///
/// 保存岗位权限
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task SaveJobAuth(SaveJobDto dto)
{
//获取所有关联页面
var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto().ToList();
var RemoveJobPostAuthList = _SystemMenuAndFunctionRepository._sqlSugar.SqlQueryable($@"
select a.* from Sys_JobPostAuthority a, Sys_SetData b ,Sys_SystemMenuPermission c
where a.SmId = c.Id and c.Mid = b.Id and JpId = {dto.Jpid} and c.Mid ={dto.modulId}
").ToList();
List adds = new List();
foreach (var item in dto.Savejobs)
{
foreach (var fid in item.FIds)
{
var whereobj = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.FId == fid && x.SmId == item.SmId);
if (whereobj != null)
{
adds.Add(new Sys_JobPostAuthority
{
CreateTime = DateTime.Now,
CreateUserId = dto.UserId,
FId = fid,
JpId = dto.Jpid,
SmId = item.SmId
});
}
}
}
_JobPostAuthorityRepository.BeginTran();
try
{ //删除岗位
bool isdel = await _JobPostAuthorityRepository.DeletesAsync(RemoveJobPostAuthList);
int UpRows = _JobPostAuthorityRepository.Adds(adds);
//获取所有职位员工
var jobUserAll = await QueryUserList(new UserDto { PortType = 2, JobPostId = dto.Jpid });
List users = null;
var QueryUserListApiResult = (((jobUserAll as OkObjectResult).Value) as OASystem.Domain.ViewModels.JsonView);
if (QueryUserListApiResult != null)
{
if (QueryUserListApiResult.Code == 200)
{
users = QueryUserListApiResult.Data as List;
}
}
if (users != null && users.Count > 0)
{
List userAuth = null;
var uids = string.Join(',', users.Select(x => x.Id)).TrimEnd(',');
var RemoveUserAuthorityListAndTemp = _UserAuthorityRepository._sqlSugar.SqlQueryable($@"
select a.* from Sys_UserAuthority a, Sys_SetData b ,Sys_SystemMenuPermission c
where a.SmId = c.Id and c.Mid = b.Id and uid in ({uids}) and c.Mid = {dto.modulId} and IsTemp = 1
").ToList();
foreach (var user in users)
{
//删除个人级岗位权限
isdel = await _UserAuthorityRepository.DeletesAsync
(RemoveUserAuthorityListAndTemp.FindAll(x => x.UId == user.Id));
userAuth = adds.Select(x => new Sys_UserAuthority
{
CreateTime = DateTime.Now,
CreateUserId = dto.UserId,
FId = x.FId,
SmId = x.SmId,
UId = user.Id,
IsTemp = 1,
}).ToList();
//添加个人级别岗位
int AddRows = _UserAuthorityRepository.Adds(userAuth);
}
}
}
catch (Exception ex)
{
_JobPostAuthorityRepository.RollbackTran();
return Ok(JsonView("系统错误!"));
}
_JobPostAuthorityRepository.CommitTran();
return Ok(JsonView(200, "成功", new { }));
}
///
/// 获取员工权限
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public IActionResult QueryUserAuth(QueryUserAuthDto dto)
{
//选中的员工操作权限
var DBdata = _UserAuthorityRepository.QueryDto(x => x.UId == dto.Userid).ToList();
var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto(x => x.Mid == dto.moduleId).ToList();
if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0)
{
return Ok(JsonView("暂无数据"));
}
//所有操作
var PageOperation = _PageFunctionPermissionRepository.QueryDto(x => x.IsEnable == 1).ToList();
//获取所有关联页面
var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto().ToList();
ArrayList viewData = new ArrayList();
//组合页面数据
foreach (var item in SystemMenuPermissionData)
{
ArrayList ids = new ArrayList();
foreach (var viewop in PageOperation)
{
var op = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.SmId == item.Id && x.FId == viewop.Id);
if (op != null)
{
ids.Add(viewop.Id);
}
}
//获取本员工拥有的权限
var DBwhere = DBdata.Where(x => x.SmId == item.Id && x.UId == dto.Userid).ToList();
viewData.Add(new
{
Id = item.Id,
Mid = item.Mid,
Name = item.Name,
SystemMenuCode = item.SystemMenuCode,
opList = ids,
selList = DBwhere.Select(x => x.FId)
});
}
return Ok(JsonView(200, "成功!", viewData));
}
///
/// 根据Id获取员工所有移动端查看权限
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public IActionResult QueryUserAuthByUserId(QueryUserAuthByUserIdDto dto)
{
string sql = string.Format(@" Select sd1.Id as ModuleId,sd1.Name as ModuleName,sm.Id as MenuId,sm.Name as MenuName From Sys_UserAuthority as u With(Nolock)
Inner Join Sys_SystemMenuPermission as sm With(Nolock) On u.SmId = sm.Id
Inner Join Sys_SetData as sd1 With(Nolock) On sm.Mid = sd1.Id
Where u.IsDel = 0 And sm.IsDel = 0
And u.UId = {0} And u.FId = 1 ", dto.UserId);
List _dataSource = _sqlSugar.SqlQueryable(sql).ToList();
List result = new List();
foreach (SystemModule_UserAuthSqlView item in _dataSource)
{
if (result.FirstOrDefault(s => s.ModuleId == item.ModuleId) == null)
{
List tempList = _dataSource.Where(s => s.ModuleId == item.ModuleId).ToList();
List menuList = new List();
foreach (SystemModule_UserAuthSqlView item2 in tempList)
{
SystemMenu_UserAuthView menu = new SystemMenu_UserAuthView() { MenuId = item2.MenuId, MenuName = item2.MenuName };
menuList.Add(menu);
}
SystemModule_UserAuthView module = new SystemModule_UserAuthView() { MenuList = menuList, ModuleId = item.ModuleId, ModuleName = item.ModuleName };
result.Add(module);
}
}
return Ok(JsonView(200, "成功!", result));
}
///
/// 保存员工权限
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task SaveUserAuth(SaveUserDto dto)
{
//获取所有关联页面
var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto().ToList();
//获取用户当前模块所有启用页面
var userpageList = _SystemMenuPermissionRepository._sqlSugar.SqlQueryable($@"
select a.* from Sys_UserAuthority a, Sys_SetData b ,Sys_SystemMenuPermission c
where a.SmId = c.Id and c.Mid = b.Id and uid = {dto.uid} and c.Mid ={dto.Modulid}
").ToList();
List adds = new List();
foreach (var item in dto.Savejobs)
{
foreach (var fid in item.FIds)
{
var whereobj = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.FId == fid && x.SmId == item.SmId);
if (whereobj != null)
{
adds.Add(new Sys_UserAuthority
{
CreateTime = DateTime.Now,
CreateUserId = dto.UserId,
FId = fid,
UId = dto.uid,
SmId = item.SmId,
IsTemp = 0
});
}
}
}
_JobPostAuthorityRepository.BeginTran();
try
{
List userAuth = null;
//删除个人级岗位权限
bool isdel = await _UserAuthorityRepository.DeletesAsync(userpageList);
userAuth = adds.Select(x => new Sys_UserAuthority
{
CreateTime = DateTime.Now,
CreateUserId = dto.UserId,
FId = x.FId,
SmId = x.SmId,
UId = dto.uid,
IsTemp = 0,
}).ToList();
//添加个人级别岗位
int AddRows = _UserAuthorityRepository.Adds(userAuth);
}
catch (Exception ex)
{
_JobPostAuthorityRepository.RollbackTran();
return Ok(JsonView("系统错误!"));
}
_JobPostAuthorityRepository.CommitTran();
return Ok(JsonView(200, "成功", new { }));
}
#endregion
#region 页面配置
///
/// 页面配置界面数据初始化
///
///
//[Authorize]
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task PageConfigInit()
{
ArrayList arr = new ArrayList();
var viewList = await _setDataRepository.GetSetDataAndPageInfoBySTId();
if (viewList.Code != 0)
{
return Ok(JsonView(viewList.Msg));
}
var ModList = await _setDataRepository.GetSySDefultModule();
return Ok(JsonView(new
{
viewList,
ModList,
}));
}
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task EditPageInfo(SetDataAndPageInfoDto dto)
{
JsonView view = null;
_SystemMenuPermissionRepository.BeginTran();
var istrue = await _SystemMenuPermissionRepository.UpdateAsync(x => x.Id == dto.Pageid, x => new Sys_SystemMenuPermission
{
AndroidUrl = dto.AndroidUrl,
CreateTime = DateTime.Now,
Icon = dto.Icon,
IosUrl = dto.IosUrl,
Name = dto.PageName,
PhoneIsEnable = dto.PagePhoneIsEnable,
CreateUserId = dto.UserId,
IsDel = 0,
IsEnable = dto.PageIsEnable,
Mid = dto.Modulid,
Remark = dto.PageRemark,
SystemMenuCode = dto.SystemMenuCode,
WebUrl = dto.WebUrl,
});
if (istrue)
{
//删除页面绑定的操作后重新绑定
await _SystemMenuAndFunctionRepository.DeleteAsync(x => x.SmId == dto.Pageid);
List binFun = new List();
foreach (var item in dto.FunArr)
{
binFun.Add(new Sys_SystemMenuAndFunction
{
CreateTime = DateTime.Now,
CreateUserId = dto.UserId,
FId = item,
SmId = dto.Pageid,
IsDel = 0,
});
}
int number = _SystemMenuAndFunctionRepository.Adds(binFun);
view = JsonView(istrue);
_SystemMenuPermissionRepository.CommitTran();
}
else
{
_SystemMenuPermissionRepository.RollbackTran();
view = JsonView("添加失败");
}
return Ok(view);
}
///
/// 添加一个页面
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task AddPageInfo(SetDataAndPageInfoDto dto)
{
JsonView view = null;
_SystemMenuPermissionRepository.BeginTran();
int number = await _SystemMenuPermissionRepository.AddAsyncReturnId(new Sys_SystemMenuPermission
{
AndroidUrl = dto.AndroidUrl,
CreateTime = DateTime.Now,
Icon = dto.Icon,
IosUrl = dto.IosUrl,
Name = dto.PageName,
PhoneIsEnable = dto.PagePhoneIsEnable,
CreateUserId = dto.UserId,
IsDel = 0,
IsEnable = dto.PageIsEnable,
Mid = dto.Modulid,
Remark = dto.PageRemark,
SystemMenuCode = dto.SystemMenuCode,
WebUrl = dto.WebUrl,
});
List binFun = new List();
foreach (var item in dto.FunArr)
{
binFun.Add(new Sys_SystemMenuAndFunction
{
CreateTime = DateTime.Now,
CreateUserId = dto.UserId,
FId = item,
SmId = number,
IsDel = 0,
});
}
number = _SystemMenuAndFunctionRepository.Adds(binFun);
if (number > 0)
{
view = JsonView(number);
_SystemMenuPermissionRepository.CommitTran();
}
else
{
_SystemMenuPermissionRepository.RollbackTran();
view = JsonView("添加失败");
}
return Ok(view);
}
///
/// 删除页面
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task DelPageInfo(List Dto)
{
JsonView view = new JsonView();
if (Dto.Count > 0)
{
try
{
_SystemMenuPermissionRepository.BeginTran();
bool istrue = false;
foreach (var item in Dto)
{
istrue = await _SystemMenuPermissionRepository.SoftDeleteAsync(item.Pageid.ToString());
if (!istrue)
{
throw new Exception("修改失败");
}
}
view.Code = 200;
view.Msg = "删除成功!";
view.Data = istrue;
_SystemMenuPermissionRepository.CommitTran();
}
catch (Exception)
{
_SystemMenuPermissionRepository.RollbackTran();
}
}
return Ok(JsonView(view));
}
///
/// 获取页面绑定的操作
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task QueryPageFunById(PageFunDto Dto)
{
//页面与操作关联表
var pageAndFunList = _SystemMenuAndFunctionRepository.QueryDto().ToList();
//页面功能表
var pageFunList = _PageFunctionPermissionRepository.QueryDto(x => x.IsEnable == 1).ToList();
ArrayList arr = new ArrayList();
foreach (var item in pageFunList)
{
var FindVal = pageAndFunList.Find(x => x.SmId == Dto.Pageid && x.FId == item.Id);
if (FindVal == null)
{
arr.Add(new
{
id = item.Id,
name = item.FunctionName,
value = false
});
}
else
{
arr.Add(new
{
id = item.Id,
name = item.FunctionName,
value = true
});
}
}
return Ok(JsonView(arr));
}
#endregion
#region 页面操作
///
/// 操作权限功能表
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task PageFunInit()
{
var PageFunInit = _PageFunctionPermissionRepository.QueryDto().ToList();
if (PageFunInit == null)
{
return Ok(JsonView(false, "暂无数据!"));
}
return Ok(JsonView(true, "查询成功!", PageFunInit));
}
///
/// 操作权限功能表操作(Status 1:添加,2:编辑)
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task OperationFun(OperationFunInitDta dto)
{
Result result = await _PageFunctionPermissionRepository.OperationFunInit(dto);
if (result.Code != 0)
{
return Ok(JsonView(false, result.Msg));
}
return Ok(JsonView(true, result.Msg));
}
///
/// 删除功能
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task DelFun(DelFunInitDta dto)
{
var res = await _PageFunctionPermissionRepository.SoftDeleteByIdAsync(dto.Id.ToString(), dto.DeleteUserId);
if (!res)
{
return Ok(JsonView(false, "删除失败"));
}
return Ok(JsonView(true, "删除成功!"));
}
#endregion
#region 各部门首页消息提示
///
/// 部门首页消息提示
///
///
[HttpGet("{portType}")]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task DepartmentHomePageMessagePrompts(int portType)
{
var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
var department = currUserInfo.Department;
if (portType < 1 || portType > 3) return Ok(JsonView(false, MsgTips.Port));
if (portType == 1 || portType == 2 || portType == 3) // web
{
//固定查询时间(当前月的上月)
var lastMoth = DateTime.Now.AddMonths(-1);
var (startDate, endDate) = CommonFun.GetMonthStartAndEndDates(lastMoth.Year, lastMoth.Month);
var startDateTime = Convert.ToDateTime(startDate.ToString("yyyy-MM-dd 00:00:00"));
var endDateTime = Convert.ToDateTime(endDate.ToString("yyyy-MM-dd 23:59:59"));
//固定查询时间(本年)
var currStartDate = Convert.ToDateTime($"{DateTime.Now.Year}-01-01 00:00:00");
var currEntDate = Convert.ToDateTime($"{DateTime.Now.Year}-12-31 23:59:59");
if (department.Equals("总经办")) //总经办
{
//1、资料数据(市场部客户资源、op地接导游、op地接车数据、商邀数据、团组收款数据)数据提示Range(固定上个月) -- Add
#region 市场部客户资源
//1.1 市场部客户资源
var users = await _sqlSugar.Queryable()
.LeftJoin((u, d) => u.DepId == d.Id)
.Where((u, d) => u.IsDel == 0 && (d.DepName.Contains("市场部") || u.Id == 21))
.Select((u, d) => new { u.Id, u.CnName })
.ToListAsync();
var marketData = await _sqlSugar.Queryable()
.LeftJoin((ncd, u) => ncd.CreateUserId == u.Id)
.Where((ncd, u) => ncd.IsDel == 0 && ncd.CreateTime >= startDateTime && ncd.CreateTime <= endDateTime)
.Select((ncd, u) => new
{
Area = ncd.Location,
ncd.Client,
ncd.Contact,
ncd.Job,
Tel = ncd.Telephone,
ncd.CreateUserId,
CreatleUserName = u.CnName,
ncd.CreateTime,
})
.ToListAsync();
foreach (var item in marketData) EncryptionProcessor.DecryptProperties(item);
var marketDataGroup = marketData.GroupBy(x => x.CreateUserId).Select(g => new { CreateUserId = g.Key, Items = g.ToList(), Count = g.Count() });
var marketData2 = new List();
foreach (var user in users)
{
var userMarketData = marketDataGroup.FirstOrDefault(x => user.Id == x.CreateUserId);
if (userMarketData != null)
{
marketData2.Add(new
{
uId = user.Id,
name = user.CnName,
count = userMarketData.Count,
msgTips = $"上月新增市场客户资源共{userMarketData.Count}条",
userMarketData = userMarketData.Items
});
}
else
{
marketData2.Add(new
{
uId = user.Id,
name = user.CnName,
count = 0,
msgTips = $"上月新增市场客户资源共{0}条",
userMarketData = new List() { },
});
}
}
var marketData1 = new
{
msgTips = $"上月新增市场客户资源共{marketData.Count}条",
Data = marketData2,
};
#endregion
#region op地接导游
//1.2 op地接导游
var opTourGuideData = await _sqlSugar.Queryable()
.LeftJoin((lgd, u) => lgd.CreateUserId == u.Id)
.Where((lgd, u) => lgd.IsDel == 0 && lgd.CreateTime >= startDateTime && lgd.CreateTime <= endDateTime)
.Select((lgd, u) => new
{
Area = lgd.UnitArea,
Client = lgd.UnitName,
lgd.Contact,
Job = "",
Tel = lgd.ContactTel,
lgd.CreateUserId,
CreatleUserName = u.CnName,
lgd.CreateTime,
})
.ToListAsync();
foreach (var item in opTourGuideData) EncryptionProcessor.DecryptProperties(item);
var opTourGuideDataGroups = opTourGuideData.GroupBy(x => x.CreateUserId)
.Select(g => new {
uId = g.Key,
name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
msgTips = $"上月新增OP地接导游资源共{g.Count()}条",
userTourGuideData = g.ToList(),
Count = g.Count()
});
var opTourGuideData1 = new
{
msgTips = $"上月新增OP地接导游资源共{opTourGuideData.Count}条",
Data = opTourGuideDataGroups,
};
#endregion
#region op车数据
//1.3 op车数据
var opCarData = await _sqlSugar.Queryable()
.LeftJoin((cd, u) => cd.CreateUserId == u.Id)
.Where((cd, u) => cd.IsDel == 0 && cd.CreateTime >= startDateTime && cd.CreateTime <= endDateTime)
.Select((cd, u) => new CarDataMsgTipsView()
{
Area = cd.UnitArea,
Client = cd.UnitName,
Contact = cd.Contact,
Job = "",
Tel = cd.ContactTel,
CreateUserId = cd.CreateUserId,
CreatleUserName = u.CnName,
CreateTime = cd.CreateTime,
})
.ToListAsync();
foreach (var item in opCarData) EncryptionProcessor.DecryptProperties(item);
var opCarDataGroups = opCarData.GroupBy(x => x.CreateUserId)
.Select(g => new {
uId = g.Key,
name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
msgTips = $"上月新增OP地接车资源共{g.Count()}条",
userTourGuideData = g.ToList(),
Count = g.Count()
});
var opCarData1 = new
{
msgTips = $"上月新增OP地接车资源共{opCarData.Count}条",
Data = opCarDataGroups,
};
#endregion
#region 商邀数据
//1.4 商邀数据
var invitationData = await _sqlSugar.Queryable()
.LeftJoin((ioa, u) => ioa.CreateUserId == u.Id)
.Where((ioa, u) => ioa.IsDel == 0 && ioa.CreateTime >= startDateTime && ioa.CreateTime <= endDateTime)
.Select((ioa, u) => new
{
//Area = string.Format("{0}{1}", ioa.Country, !string.IsNullOrEmpty(ioa.City) ? "" : "-" + ioa.City),
Area = string.Format("{0}{1}", ioa.Country, ioa.City),
Client = ioa.UnitName,
ioa.Contact,
ioa.Job,
ioa.Tel,
ioa.CreateUserId,
CreatleUserName = u.CnName,
ioa.CreateTime,
})
.ToListAsync();
var invitationGroups = invitationData.GroupBy(x => x.CreateUserId)
.Select(g => new {
uId = g.Key,
name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
msgTips = $"上月新增商邀资源共{g.Count()}条",
userTourGuideData = g.ToList(),
Count = g.Count()
});
var invitationData1 = new
{
msgTips = $"上月新增商邀资源共{invitationData.Count}条",
Data = invitationGroups,
};
#endregion
#region 团组收款数据
//1.5 团组收款数据
var groupCollectionData = await _sqlSugar.Queryable()
.LeftJoin((fr, u) => fr.CreateUserId == u.Id)
.LeftJoin((fr, u, di) => fr.Diid == di.Id)
.LeftJoin((fr, u, di, sd) => fr.Currency == sd.Id)
.Where((fr, u, di, sd) => fr.IsDel == 0 && fr.CreateTime >= startDateTime && fr.CreateTime <= endDateTime)
.Select((fr, u, di, sd) => new
{
fr.PriceName,
fr.Price,
fr.Count,
fr.Unit,
fr.ItemSumPrice,
Currency = sd.Name,
GroupName = di.TeamName,
fr.CreateUserId,
CreateUserName = u.CnName,
fr.CreateTime,
})
.ToListAsync();
var groupCollectionGroups = groupCollectionData.GroupBy(x => x.CreateUserId)
.Select(g => new
{
uId = g.Key,
name = g.ToList().FirstOrDefault()?.CreateUserName ?? "-",
msgTips = $"上月累计团组收款共{g.Count()}条",
userTourGuideData = g.ToList(),
Count = g.Count()
});
var groupCollectionData2 = new
{
msgTips = $"上月累计团组收款共{groupCollectionData.Count}条",
Data = groupCollectionGroups,
};
#endregion
var materialData = new
{
marketData = marketData1,
opTourGuideData = opTourGuideData1,
opCarData = opCarData1,
invitationData = invitationData1,
groupCollectionData = groupCollectionData2
};
//2、费用未审核(日付申请未审核数据、团组费用未审核数据)费用提示Range(固定本年)
#region 日付申请未审核数据
var dailyPaymentData = await _sqlSugar.Queryable()
.LeftJoin((dfp, u) => dfp.CreateUserId == u.Id)
.Where(dfp => dfp.IsDel == 0 &&
dfp.MAudit == 0 &&
dfp.CreateTime >= currStartDate &&
dfp.CreateTime <= currEntDate
)
.OrderBy(dfp => dfp.CreateTime, OrderByType.Desc)
//.OrderBy(dfp => dfp.FAudit, OrderByType.Desc)
.Select((dfp, u) => new
{
id = dfp.Id,
amountName = dfp.Instructions,
amount = dfp.SumPrice,
fAuditStatus = dfp.FAudit == 1 ? "审核通过" :
dfp.FAudit == 2 ? "审核未通过" : "未审核",
fAuditDate = dfp.FAuditDate,
dfp.CreateUserId,
CreateUserName = u.CnName,
dfp.CreateTime
})
.ToListAsync();
var dailyPaymentGroups = dailyPaymentData.GroupBy(x => x.CreateUserId)
.Select(g => new
{
uId = g.Key,
name = g.ToList().FirstOrDefault()?.CreateUserName ?? "-",
msgTips = $"本年有{g.Count()}条未审核日常付款申请条",
userTourGuideData = g.ToList(),
Count = g.Count()
});
var dailyPaymentData1 = new
{
msgTips = $"本年有{dailyPaymentData.Count()}条未审核日常付款申请条",
Data = dailyPaymentGroups,
};
#endregion
#region 团组费用未审核数据
var groupPaymentData = await _sqlSugar.Queryable()
.LeftJoin((ccp, di) => ccp.DIId == di.Id)
.Where((ccp, di) => ccp.IsDel == 0 &&
ccp.IsAuditGM == 0 &&
ccp.CreateTime >= currStartDate &&
ccp.CreateTime <= currEntDate
)
.Select((ccp, di) => new
{
ccp.Id,
ccp.DIId,
GroupName = di.TeamName,
ccp.CreateTime,
})
.ToListAsync();
var groupPaymentGroups = groupPaymentData.GroupBy(x => x.DIId)
.Select(g => new
{
uId = g.Key,
name = g.ToList().FirstOrDefault()?.GroupName ?? "-",
msgTips = $"本年有{g.Count()}条未审核团组费用申请条",
userTourGuideData = g.ToList(),
Count = g.Count()
});
var groupPaymentData1 = new
{
msgTips = $"本年有{groupPaymentData.Count()}条未审核团组费用申请条",
Data = groupPaymentGroups,
};
#endregion
var feeUnAuditData = new
{
dailyPaymentData = dailyPaymentData1,
groupPaymentData = groupPaymentData1
};
return Ok(JsonView(new { materialData = materialData, feeUnAuditData = feeUnAuditData }));
}
else if (department.Equals("国交部"))//国交部
{
#region 团组费用录入提示
/*
* 名称:团组费用录入提示
* 描述:团组费用录入提醒(根据团组结束时间 - 3天 如果对应的数据表里没有这个团组的费用信息)
* 条件:时间范围不限制、 根据团组结束时间 - 3天 == 当前天数
*/
var groupModlue = new List() {
76, //酒店预订
79, //车/导游地接
80, //签证
81, //邀请/公务活动
//82, //团组客户保险
85, //机票预订
98, //其他款项
//285 ,//收款退还
//1015,//超支费用
};
var crrDate = DateTime.Now.ToString("yyyy-MM-dd");
var groupModlueData = await _sqlSugar.Queryable().Where(x => groupModlue.Contains(x.Id)).ToListAsync();
var groupFeeData = await _sqlSugar.Queryable()
.LeftJoin((sd, ccp) => sd.Id == ccp.CTable)
.LeftJoin((sd, ccp, di) => ccp.DIId == di.Id)
.Where((sd, ccp, di) => ccp.IsDel == 0 &&
di.IsDel == 0 &&
groupModlue.Contains(ccp.CTable) &&
di.VisitEndDate.AddDays(-3).ToString("yyyy-MM-dd").Equals(crrDate)
)
.GroupBy((sd, ccp, di) => new { di.Id, di.TeamName, ccp.CTable, sd.Name }) //可以多字段
.Select((sd, ccp, di) => new {
diId = di.Id,
groupName = di.TeamName,
groupType = ccp.CTable,
groupTypeName = sd.Name,
//userId = ccp.CreateUserId,
count = SqlFunc.AggregateCount(ccp.CTable),
})
.ToListAsync();
var groupFeeData1 = groupFeeData.GroupBy(x => x.diId);
var groupNotFilledFeeData = new List();
foreach (var groupFee in groupFeeData1)
{
var diId = groupFee.Key;
var addData = groupFeeData.Where(x => x.diId == diId).Select(x => x.groupType).ToList();
if (addData.Count < 1) continue;
var unAddData = groupModlue.Except(addData).ToList();
if (unAddData.Count < 1) continue;
foreach (var typeId in unAddData)
{
groupNotFilledFeeData.Add(new
{
diId = diId,
groupName = groupFee.FirstOrDefault()?.groupName ?? "-",
groupType = typeId,
groupTypeName = groupModlueData.Find(x => x.Id == typeId)?.Name ?? "-",
count = 0
});
}
}
#endregion
#region 日付申请 -- 未审核数据
var depUserData = await _sqlSugar.Queryable()
.LeftJoin((u, d) => u.DepId == d.Id)
.LeftJoin((u, d, jp) => u.JobPostId == jp.Id)
.Where((u, d, jp) => u.IsDel == 0 && d.DepName.Contains("国交部"))
.Select((u, d, jp) => new
{
u.Id,
u.CnName,
u.DepId,
d.DepName,
u.JobPostId,
jp.JobName
})
.ToListAsync();
var depUserData1 = depUserData.Select(x => x.Id).ToList();
var unAuditDailyFeeData = await _sqlSugar.Queryable()
.LeftJoin((dfp, u) => dfp.CreateUserId == u.Id)
.Where((dfp, u) => dfp.IsDel == 0 &&
depUserData1.Contains(dfp.CreateUserId) &&
dfp.MAudit == 0 &&
dfp.CreateTime >= currStartDate &&
dfp.CreateTime <= currEntDate
)
.Select((dfp, u) => new
{
id = dfp.Id,
amountName = dfp.Instructions,
amount = dfp.SumPrice,
fAuditStatus = dfp.FAudit == 1 ? "审核通过" :
dfp.FAudit == 2 ? "审核未通过" : "未审核",
fAuditDate = dfp.FAuditDate,
dfp.CreateUserId,
CreateUserName = u.CnName,
dfp.CreateTime
})
.ToArrayAsync();
#endregion
var jobs = new List() { "经理", "主管" };
if (jobs.Contains( currUserInfo.Role)) //经理、主管
{
#region 经理、主管
//经理、主管(部门下所有人员) --> 日付(-:未审核提示)、团组费用录入提醒(根据团组结束时间-3天 如果对应的数据表里没有这个团组的费用信息)
var dailyPaymentData = new
{
msgTips = $"本年有{unAuditDailyFeeData.Count()}条未审核日常付款申请条",
Data = new
{
uId = currUserInfo.UserId,
name = currUserInfo.UserName,
msgTips = $"本年有{unAuditDailyFeeData.Count()}条未审核日常付款申请条",
userTourGuideData = unAuditDailyFeeData,
Count = unAuditDailyFeeData.Count()
}
};
var groupNotFilledFeeDataAll = groupNotFilledFeeData
.GroupBy(x => x.diId)
.Select(g => new
{
uId = g.Key,
name = g.ToList().FirstOrDefault()?.groupName ?? "-",
msgTips = $"-",
hotelFeeData = g.Select(x1 => new
{
x1.groupType,
x1.groupTypeName
}).ToList(),
Count = g.Count()
})
.ToList();
var groupNotFillEdFeeData1 = new
{
msgTips = $"今天有{groupNotFilledFeeDataAll.Count()}个团组费用未填写",
Data = groupNotFilledFeeDataAll,
};
#endregion
return Ok(JsonView(new { groupNotFillEdFeeData = groupNotFillEdFeeData1, dailyPaymentData = dailyPaymentData }));
}
else if (currUserInfo.Role.Equals("计调"))//计调
{
#region 计调
//计调(myself) --> 暂定
return Ok(JsonView(false, "国交部-->计调岗位消息提示正在开发中......"));
#endregion
}
else if (currUserInfo.Role.Equals("机票"))//机票
{
#region 机票
//机票(myself) --> 日付(-:未审核提示)、机票费用(-:未录入提示)
var airTicket_unAuditDailyFeeData = unAuditDailyFeeData.Where(x => x.CreateUserId == currUserInfo.UserId).ToList();
var dailyPaymentData = new
{
msgTips = $"本年有{airTicket_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
Data = new
{
uId = currUserInfo.UserId,
name = currUserInfo.UserName,
msgTips = $"本年有{airTicket_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
userTourGuideData = airTicket_unAuditDailyFeeData,
Count = airTicket_unAuditDailyFeeData.Count()
}
};
var airTicket_groupNotFilledData = groupNotFilledFeeData
.Where(x => x.groupType == 85)
.GroupBy(x => x.diId)
.Select(g => new
{
uId = g.Key,
name = g.ToList().FirstOrDefault()?.groupName ?? "-",
msgTips = $"-",
airTicketFeeData = g.Select(x1 => new
{
x1.groupType,
x1.groupTypeName
}).ToList(),
Count = g.Count()
})
.ToList();
var groupNotFillEdFeeData1 = new
{
msgTips = $"今天有{airTicket_groupNotFilledData.Count()}个团组费用未填写",
Data = airTicket_groupNotFilledData,
};
#endregion
return Ok(JsonView(new { groupNotFillEdFeeData = groupNotFillEdFeeData1, dailyPaymentData = dailyPaymentData }));
}
else if (currUserInfo.Role.Equals("酒店"))//酒店
{
#region 酒店
//酒店(myself) --> 日付(-:未审核提示)、酒店费用(-:未录入提示)
var hotle_unAuditDailyFeeData = unAuditDailyFeeData.Where(x => x.CreateUserId == currUserInfo.UserId).ToList();
var dailyPaymentData = new
{
msgTips = $"本年有{hotle_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
Data = new
{
uId = currUserInfo.UserId,
name = currUserInfo.UserName,
msgTips = $"本年有{hotle_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
hotelFeeData = hotle_unAuditDailyFeeData,
Count = hotle_unAuditDailyFeeData.Count()
}
};
var hotel_groupNotFilledData = groupNotFilledFeeData
.Where(x => x.groupType == 76)
.GroupBy(x => x.diId)
.Select(g => new
{
uId = g.Key,
name = g.ToList().FirstOrDefault()?.groupName ?? "-",
msgTips = $"-",
hotelFeeData = g.Select(x1 => new
{
x1.groupType,
x1.groupTypeName
}).ToList(),
Count = g.Count()
})
.ToList();
var groupNotFillEdFeeData1 = new
{
msgTips = $"今天有{hotel_groupNotFilledData.Count()}个团组费用未填写",
Data = hotel_groupNotFilledData,
};
#endregion
return Ok(JsonView(new { groupNotFillEdFeeData = groupNotFillEdFeeData1, dailyPaymentData = dailyPaymentData }));
}
else if (currUserInfo.Role.Equals("签证"))//签证
{
#region 签证
//签证(myself) --> 日付(-:未审核提示)、签证费用(-:未录入提示)
var visa_unAuditDailyFeeData = unAuditDailyFeeData.Where(x => x.CreateUserId == currUserInfo.UserId).ToList();
var dailyPaymentData = new
{
msgTips = $"本年有{visa_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
Data = new
{
uId = currUserInfo.UserId,
name = currUserInfo.UserName,
msgTips = $"本年有{visa_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
visaFeeData = visa_unAuditDailyFeeData,
Count = visa_unAuditDailyFeeData.Count()
}
};
var visa_groupNotFilledData = groupNotFilledFeeData
.Where(x => x.groupType == 80)
.GroupBy(x => x.diId)
.Select(g => new
{
uId = g.Key,
name = g.ToList().FirstOrDefault()?.groupName ?? "-",
msgTips = $"-",
airTicketFeeData = g.Select(x1 => new
{
x1.groupType,
x1.groupTypeName
}).ToList(),
Count = g.Count()
})
.ToList();
var groupNotFillEdFeeData1 = new
{
msgTips = $"今天有{visa_groupNotFilledData.Count()}个团组费用未填写",
Data = visa_groupNotFilledData,
};
#endregion
return Ok(JsonView(new { groupNotFillEdFeeData = groupNotFillEdFeeData1, dailyPaymentData = dailyPaymentData }));
}
else if (currUserInfo.Role.Equals("商邀"))//商邀
{
#region 商邀
//商邀(myself) --> 日付(-:未审核提示)、商邀费用(-:未录入提示)、(公务、翻译人)(-:新增提示)
//日付
var in_unAuditDailyFeeData = unAuditDailyFeeData.Where(x => x.CreateUserId == currUserInfo.UserId).ToList();
var dailyPaymentData = new
{
msgTips = $"本年有{in_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
Data = new
{
uId = currUserInfo.UserId,
name = currUserInfo.UserName,
msgTips = $"本年有{in_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
visaFeeData = in_unAuditDailyFeeData,
Count = in_unAuditDailyFeeData.Count()
}
};
//团组未录入费用
var in_groupNotFilledData = groupNotFilledFeeData
.Where(x => x.groupType == 81)
.GroupBy(x => x.diId)
.Select(g => new
{
uId = g.Key,
name = g.ToList().FirstOrDefault()?.groupName ?? "-",
msgTips = $"-",
airTicketFeeData = g.Select(x1 => new
{
x1.groupType,
x1.groupTypeName
}).ToList(),
Count = g.Count()
})
.ToList();
var groupNotFillEdFeeData1 = new
{
msgTips = $"今天有{in_groupNotFilledData.Count()}个团组费用未填写",
Data = in_groupNotFilledData,
};
//商邀 - 基础数据
var invitationData = await _sqlSugar.Queryable()
.LeftJoin((ioa, u) => ioa.CreateUserId == u.Id)
.Where((ioa, u) => ioa.IsDel == 0 && ioa.CreateTime >= startDateTime && ioa.CreateTime <= endDateTime)
.Select((ioa, u) => new
{
//Area = string.Format("{0}{1}", ioa.Country, !string.IsNullOrEmpty(ioa.City) ? "" : "-" + ioa.City),
Area = string.Format("{0}{1}", ioa.Country, ioa.City),
Client = ioa.UnitName,
ioa.Contact,
ioa.Job,
ioa.Tel,
ioa.CreateUserId,
CreatleUserName = u.CnName,
ioa.CreateTime,
})
.ToListAsync();
var invitationGroups = invitationData.GroupBy(x => x.CreateUserId)
.Select(g => new {
uId = g.Key,
name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
msgTips = $"上月新增商邀资源共{g.Count()}条",
userTourGuideData = g.ToList(),
Count = g.Count()
});
var invitationData1 = new
{
msgTips = $"上月新增商邀资源共{invitationData.Count}条",
Data = invitationGroups,
};
#endregion
return Ok(JsonView(new { groupNotFillEdFeeData = groupNotFillEdFeeData1, dailyPaymentData = dailyPaymentData, invitationData = invitationData }));
}
else if (currUserInfo.Role.Equals("OP"))//OP
{
#region OP
//OP(myself) --> 日付(-:未审核提示)、OP费用(-:未录入提示)、(导游、车)资源信息(-:新增提示)
//日付
var in_unAuditDailyFeeData = unAuditDailyFeeData.Where(x => x.CreateUserId == currUserInfo.UserId).ToList();
var dailyPaymentData = new
{
msgTips = $"本年有{in_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
Data = new
{
uId = currUserInfo.UserId,
name = currUserInfo.UserName,
msgTips = $"本年有{in_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
visaFeeData = in_unAuditDailyFeeData,
Count = in_unAuditDailyFeeData.Count()
}
};
//OP - 团组未录入费用
var in_groupNotFilledData = groupNotFilledFeeData
.Where(x => x.groupType == 79)
.GroupBy(x => x.diId)
.Select(g => new
{
uId = g.Key,
name = g.ToList().FirstOrDefault()?.groupName ?? "-",
msgTips = $"-",
airTicketFeeData = g.Select(x1 => new
{
x1.groupType,
x1.groupTypeName
}).ToList(),
Count = g.Count()
})
.ToList();
var groupNotFillEdFeeData1 = new
{
msgTips = $"今天有{in_groupNotFilledData.Count()}个团组费用未填写",
Data = in_groupNotFilledData,
};
#region op地接导游
//1.2 op地接导游
var opTourGuideData = await _sqlSugar.Queryable()
.LeftJoin((lgd, u) => lgd.CreateUserId == u.Id)
.Where((lgd, u) => lgd.IsDel == 0 && lgd.CreateTime >= startDateTime && lgd.CreateTime <= endDateTime)
.Select((lgd, u) => new
{
Area = lgd.UnitArea,
Client = lgd.UnitName,
lgd.Contact,
Job = "",
Tel = lgd.ContactTel,
lgd.CreateUserId,
CreatleUserName = u.CnName,
lgd.CreateTime,
})
.ToListAsync();
foreach (var item in opTourGuideData) EncryptionProcessor.DecryptProperties(item);
var opTourGuideDataGroups = opTourGuideData.GroupBy(x => x.CreateUserId)
.Select(g => new {
uId = g.Key,
name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
msgTips = $"上月新增OP地接导游资源共{g.Count()}条",
userTourGuideData = g.ToList(),
Count = g.Count()
});
var opTourGuideData1 = new
{
msgTips = $"上月新增OP地接导游资源共{opTourGuideData.Count}条",
Data = opTourGuideDataGroups,
};
#endregion
#region op车数据
//1.3 op车数据
var opCarData = await _sqlSugar.Queryable()
.LeftJoin((cd, u) => cd.CreateUserId == u.Id)
.Where((cd, u) => cd.IsDel == 0 && cd.CreateTime >= startDateTime && cd.CreateTime <= endDateTime)
.Select((cd, u) => new
{
Area = cd.UnitArea,
Client = cd.UnitName,
cd.Contact,
Job = "",
Tel = cd.ContactTel,
cd.CreateUserId,
CreatleUserName = u.CnName,
cd.CreateTime,
})
.ToListAsync();
var opCarDataGroups = opCarData.GroupBy(x => x.CreateUserId)
.Select(g => new {
uId = g.Key,
name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
msgTips = $"上月新增OP地接车资源共{g.Count()}条",
userTourGuideData = g.ToList(),
Count = g.Count()
});
var opCarData1 = new
{
msgTips = $"上月新增OP地接车资源共{opCarData.Count}条",
Data = opCarDataGroups,
};
#endregion
#endregion
return Ok(JsonView(new
{
groupNotFillEdFeeData = groupNotFillEdFeeData1,
dailyPaymentData = dailyPaymentData,
CarData = opCarData1,
TourGuideData = opTourGuideData
}));
}
return Ok(JsonView(false, "国交部消息提示正在开发中......"));
}
else if (department.Equals("财务部"))//总经办
{
#region 团组收款数据
var groupCollectionData = await _sqlSugar.Queryable()
.LeftJoin((fr, u) => fr.CreateUserId == u.Id)
.LeftJoin((fr, u, di) => fr.Diid == di.Id)
.LeftJoin((fr, u, di, sd) => fr.Currency == sd.Id)
.Where((fr, u, di, sd) => fr.IsDel == 0 && fr.CreateTime >= startDateTime && fr.CreateTime <= endDateTime)
.Select((fr, u, di, sd) => new
{
fr.PriceName,
fr.Price,
fr.Count,
fr.Unit,
fr.ItemSumPrice,
Currency = sd.Name,
GroupName = di.TeamName,
fr.CreateUserId,
CreateUserName = u.CnName,
fr.CreateTime,
})
.ToListAsync();
var groupCollectionGroups = groupCollectionData.GroupBy(x => x.CreateUserId)
.Select(g => new
{
uId = g.Key,
name = g.ToList().FirstOrDefault()?.CreateUserName ?? "-",
msgTips = $"上月累计团组收款共{g.Count()}条",
userTourGuideData = g.ToList(),
Count = g.Count()
});
var groupCollectionData1 = new
{
msgTips = $"上月累计团组收款共{groupCollectionData.Count}条",
Data = groupCollectionGroups,
};
#endregion
#region 日付申请未审核数据
var dailyPaymentData = await _sqlSugar.Queryable()
.LeftJoin((dfp, u) => dfp.CreateUserId == u.Id)
.Where(dfp => dfp.IsDel == 0 &&
dfp.MAudit == 0 &&
dfp.CreateTime >= currStartDate &&
dfp.CreateTime <= currEntDate
)
.OrderBy(dfp => dfp.CreateTime, OrderByType.Desc)
//.OrderBy(dfp => dfp.FAudit, OrderByType.Desc)
.Select((dfp, u) => new
{
id = dfp.Id,
amountName = dfp.Instructions,
amount = dfp.SumPrice,
fAuditStatus = dfp.FAudit == 1 ? "审核通过" :
dfp.FAudit == 2 ? "审核未通过" : "未审核",
fAuditDate = dfp.FAuditDate,
dfp.CreateUserId,
CreateUserName = u.CnName,
dfp.CreateTime
})
.ToListAsync();
var dailyPaymentGroups = dailyPaymentData.GroupBy(x => x.CreateUserId)
.Select(g => new
{
uId = g.Key,
name = g.ToList().FirstOrDefault()?.CreateUserName ?? "-",
msgTips = $"本年有{g.Count()}条未审核日常付款申请条",
userTourGuideData = g.ToList(),
Count = g.Count()
});
var dailyPaymentData1 = new
{
msgTips = $"本年有{dailyPaymentData.Count()}条未审核日常付款申请条",
Data = dailyPaymentGroups,
};
#endregion
return Ok(JsonView(new { groupCollectionData = groupCollectionData1, dailyPaymentData = dailyPaymentData1 }));
}
return Ok(JsonView(false,"其余部门消息提示正在开发者中......"));
}
return Ok(JsonView(false));
}
#endregion
}
}