|
@@ -1,13 +1,17 @@
|
|
|
using Aspose.Cells;
|
|
|
using AutoMapper;
|
|
|
+using EyeSoft.Collections.Generic;
|
|
|
using EyeSoft.Runtime.InteropServices;
|
|
|
using Newtonsoft.Json;
|
|
|
using OASystem.Domain;
|
|
|
using OASystem.Domain.Dtos.PersonnelModule;
|
|
|
+using OASystem.Domain.Dtos.System;
|
|
|
using OASystem.Domain.Entities.Groups;
|
|
|
using OASystem.Domain.Entities.PersonnelModule;
|
|
|
using OASystem.Domain.ViewModels.PersonnelModule;
|
|
|
+using OASystem.Infrastructure.Repositories.System;
|
|
|
using OASystem.Infrastructure.Tools;
|
|
|
+using System.Text.RegularExpressions;
|
|
|
|
|
|
namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
{
|
|
@@ -22,7 +26,8 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
private string _url;
|
|
|
private string _excelPath;
|
|
|
private List<int> _goodsTypeIds; //多部门审核物品类型Id
|
|
|
- public GoodsRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
|
|
|
+ private readonly ApprovalProcessRepository _approvalProcessRep;
|
|
|
+ public GoodsRepository(SqlSugarClient sqlSugar, IMapper mapper, ApprovalProcessRepository approvalProcessRep) : base(sqlSugar)
|
|
|
{
|
|
|
_mapper = mapper;
|
|
|
_jv = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败!" };
|
|
@@ -35,6 +40,7 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
_goodsTypeIds = new List<int>() {
|
|
|
1423, //1423 贵重物品
|
|
|
};
|
|
|
+ _approvalProcessRep = approvalProcessRep;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -43,7 +49,6 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
/// <returns></returns>
|
|
|
public async Task<JsonView> InitDataSource()
|
|
|
{
|
|
|
-
|
|
|
var typeData = await _sqlSugar.Queryable<GoodsTypeView>()
|
|
|
.Includes(x => x.SubTypeItems.Where(z => z.IsDel == 0)
|
|
|
//.Select(z => new {
|
|
@@ -1182,6 +1187,17 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
hrAuditPer = true;
|
|
|
}
|
|
|
|
|
|
+ if (currUserId == 343) //陈湘OAId登录 只显示贵重物品审核信息
|
|
|
+ {
|
|
|
+ if (_goodsTypeIds.Any())
|
|
|
+ {
|
|
|
+ var newArray = typeLabel.ToList();
|
|
|
+ newArray.AddRange(_goodsTypeIds);
|
|
|
+ typeLabel = newArray.ToArray();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
var beginBool = DateTime.TryParse(!string.IsNullOrEmpty(dto.BeginDt) ? $"{dto.BeginDt} 00:00:00" : string.Empty, out var begin);
|
|
|
var endBool = DateTime.TryParse(!string.IsNullOrEmpty(dto.EndDt) ? $"{dto.EndDt} 00:00:00" : string.Empty, out var end);
|
|
|
|
|
@@ -1201,7 +1217,7 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
.WhereIF(isAllGroups, (gr, gi, sd, u1, u2, di) => gr.GroupId > 0)
|
|
|
.WhereIF(!isAllGroups && groupLabel.Length > 0, (gr, gi, sd, u1, u2, di) => groupLabel.Contains(gr.GroupId))
|
|
|
.WhereIF(beginBool && endBool, (gr, gi, sd, u1, u2, di) => gr.CreateTime >= begin && gr.CreateTime <= end)
|
|
|
- .WhereIF(hrAuditPer, (gr, gi, sd, u1, u2, di) => _goodsTypeIds.Contains(gi.Type))
|
|
|
+ //.WhereIF((string.IsNullOrEmpty(dto.GoodsName) || !isAllGroups) && hrAuditPer, (gr, gi, sd, u1, u2, di) => _goodsTypeIds.Contains(gi.Type))
|
|
|
.Select((gr, gi, sd, u1, u2, di) => new GoodsReceiveListMobileView
|
|
|
{
|
|
|
Id = gr.Id,
|
|
@@ -1425,8 +1441,8 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
|
|
|
if (isAuditPer)
|
|
|
{
|
|
|
- goodsAuditInfos.Add(goodsAuditInfo2);
|
|
|
- stringBuilder.Append($"人事部:状态:待确认 审核人:- 审核时间:-;<br/>");
|
|
|
+ goodsAuditInfos.Add(goodsAuditInfo2);
|
|
|
+ stringBuilder.Append($"人事部:状态:待确认 审核人:- 审核时间:-;<br/>");
|
|
|
}
|
|
|
|
|
|
info.StatusDesc = stringBuilder.ToString();
|
|
@@ -2790,5 +2806,293 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
|
|
|
|
return _jv;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ #region New 物品领用、审核
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 物品领用 可批量 OP(Add Or Edit)
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <param name="currUserId"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<JsonView> GoodsReceiveBatchOp(GoodsReceiveBatchOpDto dto)
|
|
|
+ {
|
|
|
+ var goodsReceiveId = dto.Id;
|
|
|
+ var currUserId = dto.CurrUserId;
|
|
|
+ //请求参数处理
|
|
|
+ var receiveInfo = new Pm_GoodsReceive()
|
|
|
+ {
|
|
|
+ Id = goodsReceiveId,
|
|
|
+ GroupId = dto.GroupId,
|
|
|
+ Reason = dto.Reason,
|
|
|
+ AuditStatus = GoodsAuditEnum.Pending,
|
|
|
+ CreateUserId = currUserId,
|
|
|
+ };
|
|
|
+ var receiveDetails = _mapper.Map<Pm_GoodsReceiveDetails[]>(dto.ReceiveDetails);
|
|
|
+ //receiveDetails.ForEach(x => { x.CreateUserId = dto.CurrUserId; });
|
|
|
+
|
|
|
+ _sqlSugar.BeginTran();
|
|
|
+
|
|
|
+
|
|
|
+ //审核状态验证 false:其他物品 true:贵重物品
|
|
|
+ var isBatchVail = false;
|
|
|
+
|
|
|
+ //物品库存验证
|
|
|
+ int goodsIndex = 1;
|
|
|
+ foreach (var item in receiveDetails)
|
|
|
+ {
|
|
|
+ item.CreateUserId = currUserId;
|
|
|
+ int goodsId = item.GoodsId;
|
|
|
+ //物品验证
|
|
|
+ var goodsInfo = _sqlSugar.Queryable<Pm_GoodsInfo>().First(x => x.IsDel == 0 && x.Id == goodsId);
|
|
|
+ if (goodsInfo == null)
|
|
|
+ {
|
|
|
+ _jv.Msg = $"第{goodsIndex}项物品不存在!";
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+
|
|
|
+ //物品库存验证
|
|
|
+ var stockQuantity = goodsInfo.StockQuantity;
|
|
|
+ var awaitAuditQuantity = await GoodsAwaitQuantity(goodsId);
|
|
|
+ stockQuantity -= awaitAuditQuantity;
|
|
|
+ if (item.Quantity > stockQuantity)
|
|
|
+ {
|
|
|
+ _jv.Msg = $"“{goodsInfo.Name}”物品库存不足!剩余库存:{stockQuantity} {goodsInfo.Unit}(含待审数量:{awaitAuditQuantity});";
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+
|
|
|
+ //物品类型验证
|
|
|
+ if (_goodsTypeIds.Contains(goodsInfo.Type)) isBatchVail = true;
|
|
|
+
|
|
|
+ goodsIndex++;
|
|
|
+ }
|
|
|
+
|
|
|
+ //验证领用 添加OR编辑
|
|
|
+ var goodsReceiveInfo = await _sqlSugar.Queryable<Pm_GoodsReceive>().FirstAsync(x => x.IsDel == 0 && x.Id == goodsReceiveId);
|
|
|
+ if (goodsReceiveInfo == null) //添加
|
|
|
+ {
|
|
|
+ goodsReceiveId = await _sqlSugar.Insertable(receiveInfo).ExecuteReturnIdentityAsync();
|
|
|
+ if (goodsReceiveId < 1)
|
|
|
+ {
|
|
|
+ _jv.Msg = $"领用添加失败!";
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+
|
|
|
+ receiveDetails.ForEach(x => { x.GoodsReceiveId = goodsReceiveId; });
|
|
|
+
|
|
|
+ var receiveDetailsStatus = await _sqlSugar.Insertable(receiveDetails).ExecuteCommandAsync();
|
|
|
+ if (receiveDetailsStatus < 1)
|
|
|
+ {
|
|
|
+ _jv.Msg = $"领用明细添加失败!";
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else //修改
|
|
|
+ {
|
|
|
+ //更改前状态验证
|
|
|
+ if (goodsReceiveInfo.AuditStatus != GoodsAuditEnum.Pending)
|
|
|
+ {
|
|
|
+ _jv.Msg = $"领用状态在“领用待确认”,即可修改!";
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+
|
|
|
+ var receiveStatus = await _sqlSugar.Updateable(receiveInfo).ExecuteCommandAsync();
|
|
|
+
|
|
|
+ if (receiveStatus < 1)
|
|
|
+ {
|
|
|
+ _jv.Msg = $"领用更新失败!";
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除旧数据
|
|
|
+ var delStatus = await _sqlSugar.Updateable<Pm_GoodsReceiveDetails>()
|
|
|
+ .SetColumns(x => new Pm_GoodsReceiveDetails()
|
|
|
+ {
|
|
|
+ IsDel = 1,
|
|
|
+ DeleteUserId = currUserId,
|
|
|
+ DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
|
|
|
+ })
|
|
|
+ .Where(x => x.GoodsReceiveId == goodsReceiveId)
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+
|
|
|
+ if (delStatus < 1)
|
|
|
+ {
|
|
|
+ _jv.Msg = $"领用明细旧数据删除失败!";
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加新明细数据
|
|
|
+ if (receiveDetails.Any())
|
|
|
+ {
|
|
|
+ var addStatus = await _sqlSugar.Insertable(receiveDetails).ExecuteCommandAsync();
|
|
|
+ if (addStatus < 1)
|
|
|
+ {
|
|
|
+ _jv.Msg = $"领用明细更新失败!";
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //审核验证 物品含有贵重物品 使用贵重物品审批流程
|
|
|
+ var auditTempInfo = new ApprovalProcessView();
|
|
|
+ if (isBatchVail) //贵重物品审核模板
|
|
|
+ {
|
|
|
+ auditTempInfo = await _approvalProcessRep.GetTemplateByBusinessTypeAsync(3);
|
|
|
+ }
|
|
|
+ else //其他物品审核模板
|
|
|
+ {
|
|
|
+ auditTempInfo = await _approvalProcessRep.GetTemplateByBusinessTypeAsync(2);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (auditTempInfo == null)
|
|
|
+ {
|
|
|
+ _jv.Msg = $"未配置审核模板!";
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (auditTempInfo == null && !auditTempInfo.TempNodes.Any())
|
|
|
+ {
|
|
|
+ _jv.Msg = $"审核模板未配置节点!";
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+
|
|
|
+ //创建审核流程
|
|
|
+ var firstNode = auditTempInfo.TempNodes.OrderBy(x => x.NodeOrder).First();
|
|
|
+
|
|
|
+ var flow = await _approvalProcessRep.GetFlowByBusinessAsync(goodsReceiveId,1);
|
|
|
+
|
|
|
+ int flowId;
|
|
|
+ if (flow == null)
|
|
|
+ {
|
|
|
+ flow = new Sys_AuditFlow()
|
|
|
+ {
|
|
|
+ BusinessId = goodsReceiveId,
|
|
|
+ BusinessType = 1,
|
|
|
+ TemplateId = auditTempInfo.Id,
|
|
|
+ CurrentNodeId = firstNode.Id,
|
|
|
+ Status = 1,
|
|
|
+ };
|
|
|
+
|
|
|
+ flowId = await _sqlSugar.Insertable(flow).ExecuteReturnIdentityAsync();
|
|
|
+ if (flowId < 1)
|
|
|
+ {
|
|
|
+ _jv.Msg = $"审核流程添加失败!";
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else flowId = flow.Id;
|
|
|
+
|
|
|
+ //获取第一个节点的审核人员
|
|
|
+ var nodeUsers = firstNode.NodeUsers;
|
|
|
+
|
|
|
+ //创建审核记录
|
|
|
+ var records = nodeUsers.Select(user => new Sys_AuditRecord
|
|
|
+ {
|
|
|
+ FlowId = flowId,
|
|
|
+ NodeId = firstNode.Id,
|
|
|
+ NodeName = firstNode.NodeName,
|
|
|
+ AuditorId = user.UserId,
|
|
|
+ AuditorName = user.UserName,
|
|
|
+ AuditResult = 0, // 审核中
|
|
|
+ }).ToList();
|
|
|
+
|
|
|
+ var recordStatus = await _sqlSugar.Insertable(records).ExecuteCommandAsync();
|
|
|
+ if (recordStatus < 1)
|
|
|
+ {
|
|
|
+ _jv.Msg = $"审核记录创建失败!";
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+ _sqlSugar.CommitTran();
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 物品领用 审核
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <param name="currUserId"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<JsonView> GoodsReceiveAudit(GoodsReceiveAuditDto dto)
|
|
|
+ {
|
|
|
+ var appId = dto.Id;
|
|
|
+ var currUserId = dto.CurrUserId;
|
|
|
+
|
|
|
+ //验证审核流程
|
|
|
+ var flowInfo = await _approvalProcessRep.GetFlowByBusinessAsync(appId,1);
|
|
|
+ if (flowInfo == null)
|
|
|
+ {
|
|
|
+ _jv.Msg = $"审核流程不存在";
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return _jv;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 物品待审核数量
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="goodsId"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<decimal> GoodsAwaitQuantity(int goodsId)
|
|
|
+ {
|
|
|
+ decimal quantity = 0.00M;
|
|
|
+ //单条领用 待审核、确认中 物品数量
|
|
|
+ var waitAuditQuantity = await _sqlSugar.Queryable<Pm_GoodsReceive>().Where(x => x.IsDel == 0 &&
|
|
|
+ x.GoodsId == goodsId &&
|
|
|
+ (x.AuditStatus == GoodsAuditEnum.Pending || x.AuditStatus == GoodsAuditEnum.OutConfirming)
|
|
|
+ ).SumAsync(x => x.Quantity);
|
|
|
+
|
|
|
+ //批量领用 待审核、确认中 物品数量
|
|
|
+ var waitAuditBatchQuantity = await _sqlSugar.Queryable<Pm_GoodsReceive>()
|
|
|
+ .InnerJoin<Pm_GoodsReceiveDetails>((gr, grd) => gr.Id == grd.GoodsReceiveId)
|
|
|
+ .Where((gr, grd) => gr.IsDel == 0 &&
|
|
|
+ (gr.AuditStatus == GoodsAuditEnum.Pending || gr.AuditStatus == GoodsAuditEnum.OutConfirming) &&
|
|
|
+ grd.GoodsId == goodsId
|
|
|
+ )
|
|
|
+ .Select((gr, grd) => new
|
|
|
+ {
|
|
|
+ grd.GoodsReceiveId,
|
|
|
+ gr.AuditStatus,
|
|
|
+ grd.Quantity
|
|
|
+ })
|
|
|
+ .SumAsync(x => x.Quantity);
|
|
|
+
|
|
|
+ quantity = waitAuditQuantity + waitAuditBatchQuantity;
|
|
|
+
|
|
|
+ return quantity;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 更改领用状态
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id"></param>
|
|
|
+ /// <param name="status"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<bool> UpdateStatusAsync(int id, GoodsAuditEnum status)
|
|
|
+ {
|
|
|
+ return await _sqlSugar.Updateable<Pm_GoodsReceive>()
|
|
|
+ .SetColumns(x => x.AuditStatus == status)
|
|
|
+ .Where(x => x.Id == id)
|
|
|
+ .ExecuteCommandHasChangeAsync();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ #endregion
|
|
|
}
|
|
|
}
|