|
@@ -1,11 +1,21 @@
|
|
-using AutoMapper;
|
|
|
|
|
|
+using Aspose.Cells;
|
|
|
|
+using Aspose.Cells.Drawing;
|
|
|
|
+using Aspose.Words.Drawing;
|
|
|
|
+using AutoMapper;
|
|
|
|
+using EyeSoft.IO;
|
|
using EyeSoft.Reflection;
|
|
using EyeSoft.Reflection;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json;
|
|
|
|
+using NPOI.OpenXmlFormats.Vml;
|
|
|
|
+using NPOI.SS.UserModel;
|
|
|
|
+using NPOI.Util;
|
|
using OASystem.Domain.Dtos.PersonnelModule;
|
|
using OASystem.Domain.Dtos.PersonnelModule;
|
|
using OASystem.Domain.Entities.Groups;
|
|
using OASystem.Domain.Entities.Groups;
|
|
using OASystem.Domain.Entities.PersonnelModule;
|
|
using OASystem.Domain.Entities.PersonnelModule;
|
|
using OASystem.Domain.ViewModels.PersonnelModule;
|
|
using OASystem.Domain.ViewModels.PersonnelModule;
|
|
|
|
+using OASystem.Infrastructure.Tools;
|
|
using System.Drawing;
|
|
using System.Drawing;
|
|
|
|
+using System.IO;
|
|
|
|
+using System.Security.Policy;
|
|
|
|
|
|
namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
{
|
|
{
|
|
@@ -17,10 +27,18 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
{
|
|
{
|
|
private readonly IMapper _mapper;
|
|
private readonly IMapper _mapper;
|
|
private JsonView _jv;
|
|
private JsonView _jv;
|
|
|
|
+ private string _url;
|
|
|
|
+ private string _excelPath;
|
|
public GoodsRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
|
|
public GoodsRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
|
|
{
|
|
{
|
|
_mapper = mapper;
|
|
_mapper = mapper;
|
|
_jv = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败!" };
|
|
_jv = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败!" };
|
|
|
|
+ _url = AppSettingsHelper.Get("ExcelBaseUrl");
|
|
|
|
+ _excelPath = $"{AppSettingsHelper.Get("ExcelBasePath")}";
|
|
|
|
+ if (!Directory.Exists(_excelPath))
|
|
|
|
+ {
|
|
|
|
+ Directory.CreateDirectory(_excelPath);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -523,6 +541,136 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
return _jv;
|
|
return _jv;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 物品入库
|
|
|
|
+ /// excelDownload
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="dto"></param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ public async Task<JsonView> GoodsStorageExcelDownload()
|
|
|
|
+ {
|
|
|
|
+ var fileName = $"物资入库{Guid.NewGuid()}.xlsx";
|
|
|
|
+
|
|
|
|
+ var excelTempPath = $"{_excelPath}Template/物资入库Temp.xlsx";
|
|
|
|
+ if (!File.Exists(excelTempPath))
|
|
|
|
+ {
|
|
|
|
+ _jv.Code = StatusCodes.Status204NoContent;
|
|
|
|
+ _jv.Msg = $"该模板文件不存在!";
|
|
|
|
+ return _jv;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ _url = $"{_url}Office/Excel/GoodsFiles/";
|
|
|
|
+ _excelPath = $"{_excelPath}GoodsFiles";
|
|
|
|
+ if (!Directory.Exists(_excelPath))
|
|
|
|
+ {
|
|
|
|
+ Directory.CreateDirectory(_excelPath);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //入库记录
|
|
|
|
+ var storageData = await _sqlSugar.Queryable<Pm_GoodsStorage>()
|
|
|
|
+ .LeftJoin<Sys_Users>((gs, su) => gs.StorageUserId == su.Id)
|
|
|
|
+ .Where((gs, su) => gs.IsDel == 0)
|
|
|
|
+ .Select((gs, su) => new
|
|
|
|
+ {
|
|
|
|
+ gs.GoodsId,
|
|
|
|
+ gs.Quantity,
|
|
|
|
+ su.CnName,
|
|
|
|
+ gs.StorageTime
|
|
|
|
+ })
|
|
|
|
+ .ToListAsync();
|
|
|
|
+
|
|
|
|
+ //出库记录
|
|
|
|
+ var receiveData = await _sqlSugar.Queryable<Pm_GoodsReceive>()
|
|
|
|
+ .LeftJoin<Sys_Users>((gr, su) => gr.CreateUserId == su.Id)
|
|
|
|
+ .Where((gr, su) => gr.IsDel == 0)
|
|
|
|
+ .Select((gr, su) => new
|
|
|
|
+ {
|
|
|
|
+ gr.GoodsId,
|
|
|
|
+ gr.Quantity,
|
|
|
|
+ su.CnName,
|
|
|
|
+ gr.CreateTime,
|
|
|
|
+ gr.Reason
|
|
|
|
+ })
|
|
|
|
+ .ToListAsync();
|
|
|
|
+
|
|
|
|
+ var data = await _sqlSugar.Queryable<Pm_GoodsInfo>()
|
|
|
|
+ .Where(gi => gi.IsDel == 0)
|
|
|
|
+ .Select(gi => new GoodsStorageExcelDownloadView
|
|
|
|
+ {
|
|
|
|
+ Id = gi.Id,
|
|
|
|
+ Name = gi.Name,
|
|
|
|
+ SQ_Total = gi.SQ_Total,
|
|
|
|
+ OQ_Total = gi.OQ_Total,
|
|
|
|
+ StockQuantity = gi.StockQuantity,
|
|
|
|
+ Unit = gi.Unit
|
|
|
|
+ })
|
|
|
|
+ .ToListAsync();
|
|
|
|
+
|
|
|
|
+ foreach (var item in data)
|
|
|
|
+ {
|
|
|
|
+ var storageData1 = storageData.Where(x => x.GoodsId == item.Id).ToList();
|
|
|
|
+ if (storageData1.Any())
|
|
|
|
+ {
|
|
|
|
+ item.SQ_Total1 = storageData1.Sum(x => x.Quantity);
|
|
|
|
+ item.SQ_Total -= item.SQ_Total1;
|
|
|
|
+ item.StorageLabel = string.Join("\r\n", storageData1.Select(x => "数量:【" + x.Quantity.ToString("#0.00") + "】 入库人:【" + x.CnName + "】 入库时间:【" + x.StorageTime + "】").ToList());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var receiveData1 = receiveData.Where(x => x.GoodsId == item.Id).ToList();
|
|
|
|
+ if (receiveData1.Any())
|
|
|
|
+ {
|
|
|
|
+ item.ReceiveLabel = string.Join("\r\n", receiveData1.Select(x => "数量:【" + x.Quantity.ToString("#0.00") + "】 申请人:【" + x.CnName + "】 申请时间:【" + x.CreateTime.ToString("yyyy-MM-dd HH:mm:ss") + "】 原因:【" + x.Reason + "】").ToList());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //载入模板
|
|
|
|
+ WorkbookDesigner designer = new WorkbookDesigner();
|
|
|
|
+ designer.Workbook = new Workbook(excelTempPath);
|
|
|
|
+
|
|
|
|
+ designer.SetDataSource("Export", data);
|
|
|
|
+
|
|
|
|
+ designer.Process();
|
|
|
|
+
|
|
|
|
+ #region 渲染Cell批注
|
|
|
|
+ var sheet = designer.Workbook.Worksheets[0];
|
|
|
|
+ for (int i = 0; i < data.Count; i++)
|
|
|
|
+ {
|
|
|
|
+ string storageComment = $"C{i + 2}",
|
|
|
|
+ receiveComment = $"D{i + 2}",
|
|
|
|
+ storageCommentText = data[i].StorageLabel,
|
|
|
|
+ receiveCommentText = data[i].ReceiveLabel;
|
|
|
|
+ if (!string.IsNullOrEmpty(storageCommentText))
|
|
|
|
+ {
|
|
|
|
+ int storageIndex = sheet.Comments.Add(storageComment);
|
|
|
|
+ Aspose.Cells.Comment comment = sheet.Comments[storageIndex];
|
|
|
|
+ comment.Note = storageCommentText;
|
|
|
|
+ comment.Width = 500;
|
|
|
|
+ comment.Height = 200;
|
|
|
|
+ //comment.Font.Color = Color.Red;
|
|
|
|
+ }
|
|
|
|
+ if (!string.IsNullOrEmpty(receiveCommentText))
|
|
|
|
+ {
|
|
|
|
+ int receiveIndex = sheet.Comments.Add(receiveComment);
|
|
|
|
+ Aspose.Cells.Comment comment = sheet.Comments[receiveIndex];
|
|
|
|
+ comment.Note = receiveCommentText;
|
|
|
|
+ comment.Width = 800;
|
|
|
|
+ comment.Height = 200;
|
|
|
|
+ //comment.Font.Color = Color.Red;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ #endregion
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ string serverPath = $"{_url}{fileName}";
|
|
|
|
+ designer.Workbook.Save($"{_excelPath}/{fileName}");
|
|
|
|
+
|
|
|
|
+ _jv.Code = StatusCodes.Status200OK;
|
|
|
|
+ _jv.Data = new { url = serverPath };
|
|
|
|
+ _jv.Msg = $"操作成功";
|
|
|
|
+ return _jv;
|
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 物品领用列表
|
|
/// 物品领用列表
|
|
@@ -589,53 +737,90 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
|
|
var endBool = DateTime.TryParse(!string.IsNullOrEmpty(dto.EndDt) ? $"{dto.EndDt} 00:00:00" : string.Empty, out var end);
|
|
var endBool = DateTime.TryParse(!string.IsNullOrEmpty(dto.EndDt) ? $"{dto.EndDt} 00:00:00" : string.Empty, out var end);
|
|
|
|
|
|
RefAsync<int> total = 0;
|
|
RefAsync<int> total = 0;
|
|
- var data = await _sqlSugar.Queryable<Pm_GoodsReceive>()
|
|
|
|
- .LeftJoin<Pm_GoodsInfo>((gr, gi) => gr.GoodsId == gi.Id)
|
|
|
|
- .LeftJoin<Sys_SetData>((gr, gi, sd) => gi.Type == sd.Id)
|
|
|
|
- .LeftJoin<Sys_Users>((gr, gi, sd, u1) => gr.AuditUserId == u1.Id)
|
|
|
|
- .LeftJoin<Sys_Users>((gr, gi, sd, u1, u2) => gr.CreateUserId == u2.Id)
|
|
|
|
- .LeftJoin<Grp_DelegationInfo>((gr, gi, sd, u1, u2, di) => gr.GroupId == di.Id)
|
|
|
|
- .Where((gr, gi, sd, u1, u2, di) => gr.IsDel == 0)
|
|
|
|
- .WhereIF(dto.GoodsId > 0, (gr, gi, sd, u1, u2, di) => gr.GoodsId == dto.GoodsId)
|
|
|
|
- .WhereIF(!string.IsNullOrEmpty(dto.GoodsName), (gr, gi, sd, u1, u2, di) => gi.Name.Contains(dto.GoodsName))
|
|
|
|
- .WhereIF(auditLabel.Length > 0, (gr, gi, sd, u1, u2, di) => auditLabel.Contains((int)gr.AuditStatus))
|
|
|
|
- .WhereIF(typeLabel.Length > 0, (gr, gi, sd, u1, u2, di) => typeLabel.Contains(gi.Type))
|
|
|
|
- .WhereIF(userLabel.Length > 0, (gr, gi, sd, u1, u2, di) => userLabel.Contains(gr.CreateUserId))
|
|
|
|
- .WhereIF(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)
|
|
|
|
- .Select((gr, gi, sd, u1, u2, di) => new GoodsReceiveListMobileView
|
|
|
|
- {
|
|
|
|
- Id = gr.Id,
|
|
|
|
- GroupId = gr.GroupId,
|
|
|
|
- GroupName = di.TeamName,
|
|
|
|
- GoodsId = gr.GoodsId,
|
|
|
|
- GoodsName = gi.Name,
|
|
|
|
- GoodsType = sd.Name,
|
|
|
|
- Quantity = gr.Quantity,
|
|
|
|
- Unit = gi.Unit,
|
|
|
|
- Reason = gr.Reason,
|
|
|
|
- Remark = gr.Remark,
|
|
|
|
- AuditStatus = gr.AuditStatus,
|
|
|
|
- //AuditStatusText = gr.AuditStatus.GetEnumDescription(),
|
|
|
|
- AuditUserId = gr.AuditUserId,
|
|
|
|
- AuditUserName = u1.CnName,
|
|
|
|
- AuditTime = gr.AuditTime,
|
|
|
|
- CreateUserName = u2.CnName,
|
|
|
|
- CreateTime = gr.CreateTime
|
|
|
|
- })
|
|
|
|
- .OrderByDescending(gr => gr.CreateTime)
|
|
|
|
- .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
|
|
|
|
|
|
+ var data = _sqlSugar.Queryable<Pm_GoodsReceive>()
|
|
|
|
+ .LeftJoin<Pm_GoodsInfo>((gr, gi) => gr.GoodsId == gi.Id)
|
|
|
|
+ .LeftJoin<Sys_SetData>((gr, gi, sd) => gi.Type == sd.Id)
|
|
|
|
+ .LeftJoin<Sys_Users>((gr, gi, sd, u1) => gr.AuditUserId == u1.Id)
|
|
|
|
+ .LeftJoin<Sys_Users>((gr, gi, sd, u1, u2) => gr.CreateUserId == u2.Id)
|
|
|
|
+ .LeftJoin<Grp_DelegationInfo>((gr, gi, sd, u1, u2, di) => gr.GroupId == di.Id)
|
|
|
|
+ .Where((gr, gi, sd, u1, u2, di) => gr.IsDel == 0)
|
|
|
|
+ .WhereIF(dto.GoodsId > 0, (gr, gi, sd, u1, u2, di) => gr.GoodsId == dto.GoodsId)
|
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.GoodsName), (gr, gi, sd, u1, u2, di) => gi.Name.Contains(dto.GoodsName))
|
|
|
|
+ .WhereIF(auditLabel.Length > 0, (gr, gi, sd, u1, u2, di) => auditLabel.Contains((int)gr.AuditStatus))
|
|
|
|
+ .WhereIF(typeLabel.Length > 0, (gr, gi, sd, u1, u2, di) => typeLabel.Contains(gi.Type))
|
|
|
|
+ .WhereIF(userLabel.Length > 0, (gr, gi, sd, u1, u2, di) => userLabel.Contains(gr.CreateUserId))
|
|
|
|
+ .WhereIF(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)
|
|
|
|
+ .Select((gr, gi, sd, u1, u2, di) => new GoodsReceiveListMobileView
|
|
|
|
+ {
|
|
|
|
+ Id = gr.Id,
|
|
|
|
+ GroupId = gr.GroupId,
|
|
|
|
+ GroupName = di.TeamName,
|
|
|
|
+ GoodsId = gr.GoodsId,
|
|
|
|
+ GoodsName = gi.Name,
|
|
|
|
+ GoodsType = sd.Name,
|
|
|
|
+ Quantity = gr.Quantity,
|
|
|
|
+ Unit = gi.Unit,
|
|
|
|
+ Reason = gr.Reason,
|
|
|
|
+ Remark = gr.Remark,
|
|
|
|
+ AuditStatus = gr.AuditStatus,
|
|
|
|
+ //AuditStatusText = gr.AuditStatus.GetEnumDescription(),
|
|
|
|
+ AuditUserId = gr.AuditUserId,
|
|
|
|
+ AuditUserName = u1.CnName,
|
|
|
|
+ AuditTime = gr.AuditTime,
|
|
|
|
+ CreateUserName = u2.CnName,
|
|
|
|
+ CreateTime = gr.CreateTime
|
|
|
|
+ })
|
|
|
|
+ .OrderByDescending(gr => gr.CreateTime);
|
|
|
|
+
|
|
|
|
|
|
|
|
+ //excel导出
|
|
|
|
+ if (dto.IsExcelDownload)
|
|
|
|
+ {
|
|
|
|
+ var fileName = $"物资领用{Guid.NewGuid()}.xlsx";
|
|
|
|
|
|
-
|
|
|
|
|
|
+ var excelTempPath = $"{_excelPath}Template/物资领用Temp.xlsx";
|
|
|
|
+ if (!File.Exists(excelTempPath))
|
|
|
|
+ {
|
|
|
|
+ _jv.Code = StatusCodes.Status204NoContent;
|
|
|
|
+ _jv.Msg = $"该模板文件不存在!";
|
|
|
|
+ return _jv;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ _url = $"{_url}Office/Excel/GoodsFiles/";
|
|
|
|
+ _excelPath = $"{_excelPath}GoodsFiles";
|
|
|
|
+ if (!Directory.Exists(_excelPath))
|
|
|
|
+ {
|
|
|
|
+ Directory.CreateDirectory(_excelPath);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //载入模板
|
|
|
|
+ WorkbookDesigner designer = new WorkbookDesigner();
|
|
|
|
+ designer.Workbook = new Workbook(excelTempPath);
|
|
|
|
+
|
|
|
|
+ var tableData = await data.ToListAsync();
|
|
|
|
+ designer.SetDataSource("Export", tableData);
|
|
|
|
+
|
|
|
|
+ designer.Process();
|
|
|
|
+
|
|
|
|
+ string serverPath = $"{_url}{fileName}";
|
|
|
|
+ designer.Workbook.Save($"{_excelPath}/{fileName}");
|
|
|
|
|
|
|
|
+ _jv.Code = StatusCodes.Status200OK;
|
|
|
|
+ _jv.Data = new { url = serverPath };
|
|
|
|
+ _jv.Msg = $"操作成功";
|
|
|
|
+ return _jv;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //返回分页数据
|
|
|
|
+ var view = await data.ToPageListAsync(dto.PageIndex, dto.PageSize, total);
|
|
if (dto.PortType == 2 || dto.PortType == 3)
|
|
if (dto.PortType == 2 || dto.PortType == 3)
|
|
{
|
|
{
|
|
- _jv.Data = data;
|
|
|
|
|
|
+ _jv.Data = view;
|
|
}
|
|
}
|
|
else if (dto.PortType == 1)
|
|
else if (dto.PortType == 1)
|
|
{
|
|
{
|
|
- _jv.Data = _mapper.Map<List<GoodsReceiveListView>>(data);
|
|
|
|
|
|
+ _jv.Data = _mapper.Map<List<GoodsReceiveListView>>(view);
|
|
}
|
|
}
|
|
|
|
|
|
_jv.Code = StatusCodes.Status200OK;
|
|
_jv.Code = StatusCodes.Status200OK;
|