226 lines
8.2 KiB
C#
226 lines
8.2 KiB
C#
using Infrastructure.Attribute;
|
||
using Infrastructure.Extensions;
|
||
using Infrastructure.Model;
|
||
using Microsoft.AspNetCore.Http;
|
||
using MiniExcelLibs;
|
||
using RIZO.Model.System;
|
||
using RIZO.Repository;
|
||
using static MiniExcelLib.Core.MiniExcel;
|
||
using System.Collections.Generic;
|
||
using System.IO;
|
||
using Microsoft.AspNetCore.Http;
|
||
using RIZO.Model.Mes.Process;
|
||
using RIZO.Model.Mes.Dto.Process;
|
||
using RIZO.Service.Mes.IMesService.Process;
|
||
|
||
namespace RIZO.Service.Mes.Process
|
||
{
|
||
/// <summary>
|
||
/// 工艺表Service业务层处理
|
||
/// </summary>
|
||
[AppService(ServiceType = typeof(IProcessInfoService), ServiceLifetime = LifeTime.Transient)]
|
||
public class ProcessInfoService : BaseService<ProcessInfo>, IProcessInfoService
|
||
{
|
||
private OperationInfoService operationInfoService = new OperationInfoService();
|
||
/// <summary>
|
||
/// 查询工艺表列表
|
||
/// </summary>
|
||
/// <param name="parm"></param>
|
||
/// <returns></returns>
|
||
public PagedInfo<ProcessInfoDto> GetList(ProcessInfoQueryDto parm)
|
||
{
|
||
var predicate = QueryExp(parm);
|
||
|
||
var response = Queryable()
|
||
.Where(predicate.ToExpression())
|
||
.ToPage<ProcessInfo, ProcessInfoDto>(parm);
|
||
|
||
return response;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 获取详情
|
||
/// </summary>
|
||
/// <param name="Id"></param>
|
||
/// <returns></returns>
|
||
public ProcessInfo GetInfo(long Id)
|
||
{
|
||
var response = Queryable()
|
||
.Where(x => x.Id == Id)
|
||
.First();
|
||
|
||
return response;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加工艺表
|
||
/// </summary>
|
||
/// <param name="model"></param>
|
||
/// <returns></returns>
|
||
public ProcessInfo AddProcessInfo(ProcessInfo model)
|
||
{
|
||
return Insertable(model).ExecuteReturnEntity();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 修改工艺表
|
||
/// </summary>
|
||
/// <param name="model"></param>
|
||
/// <returns></returns>
|
||
public int UpdateProcessInfo(ProcessInfo model)
|
||
{
|
||
return Update(model, true);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询导出表达式
|
||
/// </summary>
|
||
/// <param name="parm"></param>
|
||
/// <returns></returns>
|
||
private static Expressionable<ProcessInfo> QueryExp(ProcessInfoQueryDto parm)
|
||
{
|
||
var predicate = Expressionable.Create<ProcessInfo>();
|
||
if (!string.IsNullOrWhiteSpace(parm.ProcessCode))
|
||
{
|
||
predicate.And(it => it.ProcessCode.Contains(parm.ProcessCode));
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(parm.ProcessName))
|
||
{
|
||
predicate.And(it => it.ProcessName.Contains(parm.ProcessName));
|
||
}
|
||
return predicate;
|
||
}
|
||
|
||
/// <summary>
|
||
/// excel表格导入工艺路线
|
||
/// </summary>
|
||
/// <param name="stream"></param>
|
||
/// <param name="userId"></param>
|
||
/// <returns></returns>
|
||
public ApiResult ImportProcessInfo(Stream stream, string userId,string userName)
|
||
{
|
||
int code = 200;
|
||
string strMessage = "";
|
||
try
|
||
{
|
||
if (string.IsNullOrWhiteSpace(userId))
|
||
{
|
||
code = 400;
|
||
strMessage = "创建人不可为空!";
|
||
return new ApiResult(code, strMessage);
|
||
}
|
||
if (stream == null || stream.Length == 0)
|
||
{
|
||
code = 400;
|
||
strMessage = "导入的Excel流不能为空!";
|
||
return new ApiResult(code, strMessage);
|
||
}
|
||
if (stream.CanSeek)
|
||
{
|
||
stream.Position = 0;
|
||
}
|
||
|
||
List<ProcessInfo> processInfos = new List<ProcessInfo>();
|
||
List<OperationInfo> operationInfos = new List<OperationInfo>();
|
||
//工艺路线导入模板
|
||
List<ProcessInfoImport> processInfoImports = new List<ProcessInfoImport>();
|
||
List<ProcessInfoImport> resultList = stream.Query<ProcessInfoImport>().ToList();
|
||
List<string> porocessCodeList = new List<string>();
|
||
//从1开始循环,排除掉0行的标题行
|
||
for(int i = 1;i<resultList.Count; i++)
|
||
{
|
||
ProcessInfoImport processInfoImport = resultList[i];
|
||
if (!processInfos.Any(p => p.ProcessCode == processInfoImport.ProcessCode))
|
||
{
|
||
ProcessInfo processInfo = new ProcessInfo();
|
||
processInfo.ProcessCode = processInfoImport.ProcessCode;
|
||
processInfo.ProcessName = processInfoImport.ProcessName;
|
||
processInfo.Delflag = 0;
|
||
processInfo.CreateBy = userId;
|
||
processInfo.CreateTime = DateTime.Now;
|
||
processInfo.UpdateBy = userId;
|
||
processInfo.UpdateTime = DateTime.Now;
|
||
processInfo.CreateName = userName;
|
||
processInfo.UpdateName = userName;
|
||
processInfos.Add(processInfo);
|
||
porocessCodeList.Add(processInfoImport.ProcessCode);
|
||
}
|
||
OperationInfo operationInfo = new OperationInfo();
|
||
operationInfo.OperationCode = processInfoImport.OperationCode;
|
||
operationInfo.OperationName = processInfoImport.OperationName;
|
||
operationInfo.ProcessCode = processInfoImport.ProcessCode;
|
||
operationInfo.Delflag = 0;
|
||
operationInfo.CreateBy = userId;
|
||
operationInfo.CreateTime = DateTime.Now;
|
||
operationInfo.UpdateBy = userId;
|
||
operationInfo.UpdateTime = DateTime.Now;
|
||
operationInfo.CreateName = userName;
|
||
operationInfo.UpdateName = userName;
|
||
operationInfos.Add(operationInfo);
|
||
}
|
||
if (porocessCodeList.Any())
|
||
{
|
||
var delCountP = Deleteable().Where(it => porocessCodeList.Contains(it.ProcessCode))
|
||
.ExecuteCommand();
|
||
var delCountO = operationInfoService.Deleteable().Where(it => porocessCodeList.Contains(it.ProcessCode))
|
||
.ExecuteCommand();
|
||
}
|
||
int iResult = Insert(processInfos);
|
||
if (iResult > 0)
|
||
{
|
||
code = 200;
|
||
strMessage = "导入成功!";
|
||
int iResult2 = operationInfoService.Insert(operationInfos);
|
||
}
|
||
else
|
||
{
|
||
code = 400;
|
||
strMessage = "导入失败!";
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
code = 500;
|
||
strMessage = "发生错误!"+ex.ToString();
|
||
}
|
||
return new ApiResult(code, strMessage);
|
||
}
|
||
|
||
public int DeleteByProcessCode(string[] processCodeArr)
|
||
{
|
||
int iResult = 0;
|
||
try
|
||
{
|
||
if(processCodeArr != null && processCodeArr.Any())
|
||
{
|
||
int delCountP = Deleteable().Where(it => processCodeArr.Contains(it.ProcessCode))
|
||
.ExecuteCommand();
|
||
int delCountO = operationInfoService.Deleteable().Where(it => processCodeArr.Contains(it.ProcessCode))
|
||
.ExecuteCommand();
|
||
if (delCountP > 0)
|
||
{
|
||
iResult = delCountP;
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
iResult = 0;
|
||
}
|
||
return iResult;
|
||
}
|
||
|
||
public PagedInfo<ProcessInfoDto> GetProcessInfoCondition(ProcessInfoQueryDto parm)
|
||
{
|
||
var predicate = QueryExp(parm);
|
||
var response = Queryable()
|
||
.Where(predicate.ToExpression())
|
||
.ToPage<ProcessInfo, ProcessInfoDto>(parm);
|
||
|
||
return response;
|
||
}
|
||
|
||
}
|
||
} |