工艺标准接口修改
This commit is contained in:
@@ -79,7 +79,7 @@ namespace Tnb.EquipMgr
|
||||
{
|
||||
await _repository.AsSugarClient().Updateable<EqpMaintainRecordD>()
|
||||
.SetColumns(x=>x.result==item["result"])
|
||||
.SetColumns(x=>x.maintain_descrip==item["maintain_descrip"])
|
||||
.SetColumnsIF(item.ContainsKey("maintain_descrip"),x=>x.maintain_descrip==item["maintain_descrip"])
|
||||
.Where(x=>x.id==item["id"])
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
@@ -3,11 +3,17 @@ namespace Tnb.PerMgr.Entities.Dto
|
||||
public class ProcessChildDataInput
|
||||
{
|
||||
|
||||
public string id { get; set; }
|
||||
public string process_standards_id { get; set; }
|
||||
/// <summary>
|
||||
/// 工艺参数id
|
||||
/// </summary>
|
||||
public string process_param_id { get; set; }
|
||||
/// <summary>
|
||||
/// 工艺参数类型id
|
||||
/// </summary>
|
||||
public string process_param_type_id { get; set; }
|
||||
public decimal value { get; set; }
|
||||
public string daq_id { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -14,5 +14,7 @@ namespace Tnb.PerMgr.Entities.Dto
|
||||
public decimal? value { get; set; }
|
||||
public decimal upper_value { get; set; }
|
||||
public decimal lower_value { get; set; }
|
||||
|
||||
public string daq_id { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Tnb.PerMgr.Entities.Dto
|
||||
{
|
||||
public class ProcessParamTypeDaqListOutput
|
||||
{
|
||||
public string id { get; set; }
|
||||
public string label_name { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using JNPF.Common.Contracts;
|
||||
using JNPF.Common.Security;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Tnb.PerMgr.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// 工艺参数设定值修改记录
|
||||
/// </summary>
|
||||
[SugarTable("per_process_param_edit_record")]
|
||||
public partial class PerProcessParamEditRecord : BaseEntity<string>
|
||||
{
|
||||
public PerProcessParamEditRecord()
|
||||
{
|
||||
id = SnowflakeIdHelper.NextId();
|
||||
}
|
||||
/// <summary>
|
||||
/// 工艺参数id
|
||||
/// </summary>
|
||||
public string process_param_id { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 修改前值
|
||||
/// </summary>
|
||||
public decimal old_value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改后值
|
||||
/// </summary>
|
||||
public decimal new_value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户
|
||||
/// </summary>
|
||||
public string modify_id { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 修改时间
|
||||
/// </summary>
|
||||
public DateTime modify_time { get; set; } = DateTime.Now;
|
||||
|
||||
/// <summary>
|
||||
/// 所属组织
|
||||
/// </summary>
|
||||
public string? org_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 工艺参数名
|
||||
/// </summary>
|
||||
public string? process_param_name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备id
|
||||
/// </summary>
|
||||
public string equip_id { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 流程任务Id
|
||||
/// </summary>
|
||||
public string? f_flowtaskid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 流程引擎Id
|
||||
/// </summary>
|
||||
public string? f_flowid { get; set; }
|
||||
|
||||
}
|
||||
@@ -18,6 +18,11 @@ public partial class PerProcessStandardsD : BaseEntity<string>
|
||||
/// 工艺标准主表id
|
||||
/// </summary>
|
||||
public string process_standards_id { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 工艺参数类型id
|
||||
/// </summary>
|
||||
public string process_param_type_id { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 工艺参数id
|
||||
@@ -38,5 +43,10 @@ public partial class PerProcessStandardsD : BaseEntity<string>
|
||||
/// 下限
|
||||
/// </summary>
|
||||
public decimal? lower_value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据采集id
|
||||
/// </summary>
|
||||
public string? daq_id { get; set; }
|
||||
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using JNPF.Common.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Tnb.PerMgr.Interfaces
|
||||
@@ -9,5 +10,12 @@ namespace Tnb.PerMgr.Interfaces
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<IActionResult> ExportTemplate();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 导入
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<IActionResult> Import(string id,ChunkModel input);
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,11 @@ namespace Tnb.PerMgr
|
||||
{
|
||||
tab_id = x.id,
|
||||
tab_name = x.name,
|
||||
daq_list = SqlFunc.Subqueryable<EqpDaq>().Where(a=>a.equip_id==equipId).ToList<ProcessParamTypeDaqListOutput>(a=>new ProcessParamTypeDaqListOutput
|
||||
{
|
||||
id = a.id,
|
||||
label_name = a.label_name,
|
||||
}),
|
||||
children = SqlFunc.Subqueryable<PerProcessParam>()
|
||||
.LeftJoin<PerToleranceCategory>((y,z)=>y.tolerance_category_id==z.id)
|
||||
.Where(y=>y.process_param_type_id==x.id)
|
||||
@@ -71,19 +76,67 @@ namespace Tnb.PerMgr
|
||||
{
|
||||
|
||||
List<PerProcessStandardsD> list = new List<PerProcessStandardsD>();
|
||||
List<string> insertIds = new List<string>();
|
||||
if (input != null && input.Count > 0)
|
||||
{
|
||||
foreach (var item in input)
|
||||
{
|
||||
list.Add(new PerProcessStandardsD()
|
||||
PerProcessStandardsD processStandardsD = await db.Queryable<PerProcessStandardsD>().Where(x =>
|
||||
x.process_param_id == item.process_param_id && x.process_standards_id == item.process_standards_id &&
|
||||
item.process_param_type_id == x.process_param_type_id).FirstAsync();
|
||||
|
||||
if (processStandardsD != null)
|
||||
{
|
||||
process_standards_id = item.process_standards_id,
|
||||
process_param_id = item.process_param_id,
|
||||
value = item.value
|
||||
});
|
||||
PerProcessStandardsH perProcessStandardsH = await db.Queryable<PerProcessStandardsH>().SingleAsync(x => x.id == processStandardsD.process_standards_id);
|
||||
PerProcessParam processParam = await db.Queryable<PerProcessParam>().SingleAsync(x => x.id == processStandardsD.process_param_id);
|
||||
|
||||
if (processStandardsD.value != item.value)
|
||||
{
|
||||
PerProcessParamEditRecord record = new PerProcessParamEditRecord
|
||||
{
|
||||
process_param_id = item.process_param_id,
|
||||
old_value = processStandardsD.value,
|
||||
new_value = item.value,
|
||||
modify_id = _userManager.UserId,
|
||||
modify_time = DateTime.Now,
|
||||
org_id = _userManager.GetUserInfo().Result.organizeId,
|
||||
equip_id = perProcessStandardsH.equip_id,
|
||||
process_param_name = processParam.name
|
||||
};
|
||||
db.Insertable<PerProcessParamEditRecord>(record).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(item.id))
|
||||
{
|
||||
PerProcessStandardsD insertObj = new PerProcessStandardsD()
|
||||
{
|
||||
value = item.value,
|
||||
process_param_id = item.process_param_id,
|
||||
process_standards_id = item.process_standards_id,
|
||||
process_param_type_id = item.process_param_type_id,
|
||||
daq_id = item.daq_id,
|
||||
};
|
||||
|
||||
insertIds.Add(insertObj.id);
|
||||
await db.Insertable<PerProcessStandardsD>(insertObj).ExecuteCommandAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
await db.Updateable<PerProcessStandardsD>()
|
||||
.SetColumns(x=>x.value==item.value)
|
||||
.SetColumns(x=>x.daq_id==item.daq_id)
|
||||
.Where(x=>x.id==item.id).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
await db.Insertable<PerProcessStandardsD>(list).ExecuteCommandAsync();
|
||||
List<string> notDeleteIds = input.Select(x => x.id).ToList();
|
||||
notDeleteIds.AddRange(insertIds);
|
||||
await db.Deleteable<PerProcessStandardsD>().Where(x => !notDeleteIds.Contains(x.id)).ExecuteCommandAsync();
|
||||
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
@@ -108,6 +161,11 @@ namespace Tnb.PerMgr
|
||||
{
|
||||
tab_id = a.id,
|
||||
tab_name = a.name,
|
||||
daq_list = SqlFunc.Subqueryable<EqpDaq>().Where(e=>e.equip_id==perProcessStandardsH.equip_id).ToList<ProcessParamTypeDaqListOutput>(e=>new ProcessParamTypeDaqListOutput
|
||||
{
|
||||
id = e.id,
|
||||
label_name = e.label_name,
|
||||
}),
|
||||
children = SqlFunc.Subqueryable<PerProcessStandardsD>()
|
||||
.LeftJoin<PerProcessParam>((b,c)=>b.process_param_id==c.id)
|
||||
.LeftJoin<PerToleranceCategory>((b,c,d)=>c.tolerance_category_id==d.id)
|
||||
@@ -120,7 +178,8 @@ namespace Tnb.PerMgr
|
||||
name = c.name,
|
||||
value = b.value,
|
||||
upper_value = d.upper_value,
|
||||
lower_value = d.lower_value
|
||||
lower_value = d.lower_value,
|
||||
daq_id = b.daq_id
|
||||
}),
|
||||
}).ToListAsync();
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using System.Data;
|
||||
using JNPF;
|
||||
using JNPF.Common.Core.Manager;
|
||||
using JNPF.Common.Enums;
|
||||
using JNPF.Common.Helper;
|
||||
using JNPF.Common.Models;
|
||||
using JNPF.Common.Security;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.DynamicApiController;
|
||||
@@ -9,6 +11,7 @@ using JNPF.FriendlyException;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NPOI.HSSF.UserModel;
|
||||
using NPOI.SS.UserModel;
|
||||
using NPOI.SS.Util;
|
||||
using NPOI.XSSF.UserModel;
|
||||
@@ -90,5 +93,161 @@ namespace Tnb.PerMgr
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Import([FromForm]string id, [FromForm]ChunkModel input)
|
||||
{
|
||||
int rowIndex = 1;
|
||||
bool flag = false;
|
||||
try
|
||||
{
|
||||
using (Stream stream = input.file.OpenReadStream())
|
||||
{
|
||||
IWorkbook workbook = null;
|
||||
// 2007版本
|
||||
if (input.fileName.IndexOf(".xlsx") > 0)
|
||||
workbook = new XSSFWorkbook(stream);
|
||||
else if (input.fileName.IndexOf(".xls") > 0)
|
||||
workbook = new HSSFWorkbook(stream);
|
||||
|
||||
ISheet sheet = workbook.GetSheetAt(0);
|
||||
|
||||
if (sheet.LastRowNum <= 1)
|
||||
throw Oops.Bah("无导入数据");
|
||||
|
||||
var db = _repository.AsSugarClient();
|
||||
List<PerProcessParamType> perProcessParamTypes = await db.Queryable<PerProcessParamType>().ToListAsync();
|
||||
List<PerProcessParam> perProcessParams = await db.Queryable<PerProcessParam>().ToListAsync();
|
||||
int errorColumnIndex = 5;
|
||||
|
||||
ICellStyle style = workbook.CreateCellStyle();
|
||||
IFont font = workbook.CreateFont();
|
||||
font.Color = IndexedColors.Red.Index; // 将字体颜色设置为红色
|
||||
style.SetFont(font);
|
||||
|
||||
List<PerProcessStandardsD> list = new List<PerProcessStandardsD>() { };
|
||||
for (rowIndex = 1; rowIndex < sheet.LastRowNum; rowIndex++)
|
||||
{
|
||||
IRow row = sheet.GetRow(rowIndex);
|
||||
ICell cell0 = row.GetCell(0);
|
||||
ICell cell1 = row.GetCell(1);
|
||||
ICell cell2 = row.GetCell(2);
|
||||
|
||||
PerProcessStandardsD item = new PerProcessStandardsD();
|
||||
PerProcessParamType perProcessParamType = perProcessParamTypes.FirstOrDefault(x => x.name == cell0.StringCellValue);
|
||||
if (perProcessParamType != null)
|
||||
{
|
||||
item.process_param_type_id = perProcessParamType.id;
|
||||
}
|
||||
else
|
||||
{
|
||||
ICell errorCell = row.GetCell(errorColumnIndex) ?? row.CreateCell(errorColumnIndex);
|
||||
errorCell.SetCellValue("无该工艺参数类型");
|
||||
errorCell.CellStyle = style;
|
||||
flag = true;
|
||||
}
|
||||
|
||||
PerProcessParam perProcessParam = perProcessParams.FirstOrDefault(x => x.name == cell1.StringCellValue);
|
||||
if (perProcessParam != null)
|
||||
{
|
||||
item.process_param_id = perProcessParam.id;
|
||||
}
|
||||
else
|
||||
{
|
||||
ICell errorCell = row.GetCell(errorColumnIndex) ?? row.CreateCell(errorColumnIndex);
|
||||
errorCell.SetCellValue(errorCell.StringCellValue+",无该工艺参数");
|
||||
errorCell.CellStyle = style;
|
||||
flag = true;
|
||||
}
|
||||
if (!TrySetNumberCellValue(cell2, ref item))
|
||||
{
|
||||
ICell errorCell = row.GetCell(errorColumnIndex) ?? row.CreateCell(errorColumnIndex);
|
||||
errorCell.SetCellValue(errorCell.StringCellValue+",设定值不是数字");
|
||||
errorCell.CellStyle = style;
|
||||
flag = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
list.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in list)
|
||||
{
|
||||
PerProcessStandardsD oldData = await _repository.AsSugarClient().Queryable<PerProcessStandardsD>()
|
||||
.FirstAsync(x =>
|
||||
x.process_param_id == item.process_param_id &&
|
||||
x.process_param_type_id == item.process_param_type_id && x.process_standards_id == id);
|
||||
if (oldData!=null)
|
||||
{
|
||||
if (oldData.value != item.value)
|
||||
{
|
||||
await _repository.AsSugarClient().Updateable<PerProcessStandardsD>()
|
||||
.SetColumns(x => x.value == item.value).ExecuteCommandAsync();
|
||||
|
||||
PerProcessStandardsH perProcessStandardsH = await _repository.AsSugarClient().Queryable<PerProcessStandardsH>().SingleAsync(x => x.id == oldData.process_standards_id);
|
||||
PerProcessParam processParam = await _repository.AsSugarClient().Queryable<PerProcessParam>().SingleAsync(x => x.id == oldData.process_param_id);
|
||||
|
||||
await _repository.AsSugarClient().Updateable<PerProcessStandardsD>()
|
||||
.SetColumns(x=>x.value==item.value)
|
||||
.Where(x=>x.id==oldData.id).ExecuteCommandAsync();
|
||||
|
||||
PerProcessParamEditRecord record = new PerProcessParamEditRecord
|
||||
{
|
||||
process_param_id = item.process_param_id,
|
||||
old_value = oldData.value,
|
||||
new_value = item.value,
|
||||
modify_id = _userManager.UserId,
|
||||
modify_time = DateTime.Now,
|
||||
org_id = _userManager.GetUserInfo().Result.organizeId,
|
||||
equip_id = perProcessStandardsH.equip_id,
|
||||
process_param_name = processParam.name
|
||||
};
|
||||
await _repository.AsSugarClient().Insertable<PerProcessParamEditRecord>(record).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await _repository.AsSugarClient().Insertable<PerProcessStandardsD>(item).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (flag)
|
||||
{
|
||||
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 = "导入报错说明.xlsx" };
|
||||
return fileStreamResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new JsonResult("导入成功");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw Oops.Bah("导入失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private bool TrySetNumberCellValue(ICell cell,ref PerProcessStandardsD item)
|
||||
{
|
||||
try
|
||||
{
|
||||
item.value = cell.CellType == CellType.Numeric ? (decimal)cell.NumericCellValue : cell.CellType == CellType.String ? Convert.ToDecimal(cell.StringCellValue) : 0;
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user