设备数采项目刷选 工艺标准模板导出

This commit is contained in:
2023-06-05 17:23:19 +08:00
parent 7ec192f711
commit 0d7e49695c
12 changed files with 471 additions and 1 deletions

View File

@@ -0,0 +1,67 @@
using JNPF.Common.Contracts;
using JNPF.Common.Security;
using SqlSugar;
namespace Tnb.PerMgr.Entities;
/// <summary>
/// 工艺参数类型
/// </summary>
[SugarTable("per_process_param_type")]
public partial class PerProcessParamType : BaseEntity<string>
{
public PerProcessParamType()
{
id = SnowflakeIdHelper.NextId();
}
/// <summary>
/// 名称
/// </summary>
public string name { get; set; } = string.Empty;
/// <summary>
/// 设备类型id
/// </summary>
public string equip_type_id { get; set; } = string.Empty;
/// <summary>
/// 排序
/// </summary>
public long ordinal { get; set; }
/// <summary>
/// 创建用户
/// </summary>
public string? create_id { get; set; }
/// <summary>
/// 修改用户
/// </summary>
public string? modify_id { get; set; }
/// <summary>
/// 所属组织
/// </summary>
public string? org_id { get; set; }
/// <summary>
/// 修改时间
/// </summary>
public DateTime? modify_time { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime? create_time { get; set; }
/// <summary>
/// 流程任务Id
/// </summary>
public string? f_flowtaskid { get; set; }
/// <summary>
/// 流程引擎Id
/// </summary>
public string? f_flowid { get; set; }
}

View File

@@ -0,0 +1,107 @@
using JNPF.Common.Contracts;
using JNPF.Common.Security;
using SqlSugar;
namespace Tnb.PerMgr.Entities;
/// <summary>
/// 工艺标准
/// </summary>
[SugarTable("per_process_standards_h")]
public partial class PerProcessStandardsH : BaseEntity<string>
{
public PerProcessStandardsH()
{
id = SnowflakeIdHelper.NextId();
}
/// <summary>
/// 工艺类型
/// </summary>
public string process_type { get; set; } = string.Empty;
/// <summary>
/// 编号
/// </summary>
public string code { get; set; } = string.Empty;
/// <summary>
/// 工艺文件名
/// </summary>
public string? file_name { get; set; }
/// <summary>
/// 是否启用
/// </summary>
public int? enabled { get; set; }
/// <summary>
/// 产出物料id
/// </summary>
public string? output_material_id { get; set; }
/// <summary>
/// 设备id
/// </summary>
public string equip_id { get; set; } = string.Empty;
/// <summary>
/// 模具id
/// </summary>
public string? molds_id { get; set; }
/// <summary>
/// 工序id
/// </summary>
public string? process_id { get; set; }
/// <summary>
/// 投入物料id
/// </summary>
public string? input_material_id { get; set; }
/// <summary>
/// 版本号
/// </summary>
public string version { get; set; } = string.Empty;
/// <summary>
/// 创建用户
/// </summary>
public string? create_id { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime? create_time { get; set; }
/// <summary>
/// 修改用户
/// </summary>
public string? modify_id { get; set; }
/// <summary>
/// 修改时间
/// </summary>
public DateTime? modify_time { get; set; }
/// <summary>
/// 所属组织
/// </summary>
public string? org_id { get; set; }
/// <summary>
/// 备注
/// </summary>
public string? remark { get; set; }
/// <summary>
/// 流程任务Id
/// </summary>
public string? f_flowtaskid { get; set; }
/// <summary>
/// 流程引擎Id
/// </summary>
public string? f_flowid { get; set; }
}

View File

@@ -1,3 +1,4 @@
using Microsoft.AspNetCore.Mvc;
using Tnb.PerMgr.Entities.Dto;
namespace Tnb.PerMgr.Interfaces
@@ -10,5 +11,6 @@ namespace Tnb.PerMgr.Interfaces
/// <param name="dic"></param>
/// <returns></returns>
public Task<ProcessParamOutput> GetProcessParamInfo(Dictionary<string,string> dic);
}
}

View File

@@ -0,0 +1,13 @@
using Microsoft.AspNetCore.Mvc;
namespace Tnb.PerMgr.Interfaces
{
public interface IPerProcessStandardsService
{
/// <summary>
/// 导出模板
/// </summary>
/// <returns></returns>
public Task<IActionResult> ExportTemplate();
}
}

View File

@@ -1,7 +1,12 @@
using JNPF.Common.Core.Manager;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.FriendlyException;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using NPOI.XSSF.UserModel;
using SqlSugar;
using Tnb.PerMgr.Entities;
using Tnb.PerMgr.Entities.Dto;
@@ -41,5 +46,6 @@ namespace Tnb.PerMgr
}).SingleAsync();
return result;
}
}
}

View File

@@ -0,0 +1,94 @@
using JNPF;
using JNPF.Common.Core.Manager;
using JNPF.Common.Enums;
using JNPF.Common.Helper;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.FriendlyException;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using NPOI.XSSF.UserModel;
using SqlSugar;
using Tnb.PerMgr.Entities;
using Tnb.PerMgr.Entities.Dto;
using Tnb.PerMgr.Interfaces;
namespace Tnb.PerMgr
{
/// <summary>
/// 工艺标准
/// </summary>
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
[Route("api/[area]/[controller]/[action]")]
public class PerProcessStandardsService : IPerProcessStandardsService, IDynamicApiController, ITransient
{
private readonly ISqlSugarRepository<PerProcessStandardsH> _repository;
private readonly IUserManager _userManager;
public PerProcessStandardsService(ISqlSugarRepository<PerProcessStandardsH> repository, IUserManager userManager)
{
_userManager = userManager;
_repository = repository;
}
[AllowAnonymous]
[HttpGet]
public async Task<IActionResult> ExportTemplate()
{
try
{
var db = _repository.AsSugarClient();
string[] perProcessParamTypes = await db.Queryable<PerProcessParamType>().OrderBy(x => x.ordinal).Select(x=>x.name).ToArrayAsync();
string[] perProcessParams = await db.Queryable<PerProcessParam>().OrderBy(x => x.ordinal).Select(x=>x.name).ToArrayAsync();
XSSFWorkbook workbook = new XSSFWorkbook();
NPOI.SS.UserModel.ISheet sheet = workbook.CreateSheet("BOM详情");
IRow row1 = sheet.CreateRow(0);
string[] titles = new[] { "工艺参数类型", "工艺参数", "设定值" };
for (int i = 0; i < titles.Length; i++)
{
ICell cell1 = row1.CreateCell(i);
cell1.SetCellValue(titles[i]);
sheet.SetColumnWidth(i,15 * 256);
}
int rowIndex = 1;
// var column = sheet.GetColumn(0);
// 设置下拉项
var validationHelper = sheet.GetDataValidationHelper();
var constraint = validationHelper.CreateExplicitListConstraint(perProcessParamTypes);
var region = new CellRangeAddressList(1, 1000, 0, 0);
var validation = validationHelper.CreateValidation(constraint, region);
sheet.AddValidationData(validation);
var constraint2 = validationHelper.CreateExplicitListConstraint(perProcessParams);
var region2 = new CellRangeAddressList(1, 1000, 1, 1);
var validation2 = validationHelper.CreateValidation(constraint2, region2);
sheet.AddValidationData(validation2);
MemoryStream ms = new MemoryStream();
workbook.Write(ms);
MemoryStream ms2 = new MemoryStream(ms.ToArray());
ms2.Position = 0;
FileStreamResult fileStreamResult = new FileStreamResult(ms2, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { FileDownloadName = "template.xlsx" };
return fileStreamResult;
}
catch (Exception e)
{
Console.WriteLine(e);
throw Oops.Bah("导出失败");
}
}
}
}