添加报工人

This commit is contained in:
qianhao.xu 2024-12-16 13:46:46 +08:00
parent 73b6acd375
commit ac20efae2f
12 changed files with 188 additions and 52 deletions

View File

@ -92,17 +92,16 @@ namespace DOAN.Admin.WebApi.Controllers
/// 存储文件
/// </summary>
/// <param name="uploadDto">自定义文件名</param>
/// <param name="file"></param>
/// <param name="storeType">上传类型1、保存到本地 2、保存到阿里云</param>
/// <returns></returns>
[HttpPost()]
[Verify]
[ActionPermissionFilter(Permission = "common")]
public async Task<IActionResult> UploadFile([FromForm] UploadDto uploadDto, IFormFile file, StoreType storeType = StoreType.LOCAL)
public async Task<IActionResult> UploadFile([FromForm] UploadDto2 uploadDto, StoreType storeType = StoreType.LOCAL)
{
if (file == null) throw new CustomException(ResultCode.PARAM_ERROR, "上传文件不能为空");
SysFile sysfile = new();
IFormFile formFile = file;
IFormFile formFile = uploadDto.File;
if (formFile == null) throw new CustomException(ResultCode.PARAM_ERROR, "上传文件不能为空");
SysFile file = new();
string fileExt = Path.GetExtension(formFile.FileName);//文件后缀
double fileSize = Math.Round(formFile.Length / 1024.0, 2);//文件大小KB
@ -121,12 +120,27 @@ namespace DOAN.Admin.WebApi.Controllers
switch (storeType)
{
case StoreType.LOCAL:
string savePath = Path.Combine(WebHostEnvironment.WebRootPath);
string savePath = null;
if (string.IsNullOrEmpty(OptionsSetting.Upload.rootDirectory))
{
savePath = Path.Combine(WebHostEnvironment.WebRootPath);
}
else
{
savePath = Path.Combine(OptionsSetting.Upload.rootDirectory);
if (!Directory.Exists(savePath))
{
Directory.CreateDirectory(savePath);
}
}
if (uploadDto.FileDir.IsEmpty())
{
uploadDto.FileDir = OptionsSetting.Upload.LocalSavePath;
}
sysfile = await SysFileService.SaveFileToLocal(savePath, uploadDto.FileName, uploadDto.FileDir, HttpContext.GetName(), formFile);
//savePath 根目录 uploadDto.FileName uploadDto.FileName
file = await SysFileService.SaveFileToLocal(savePath, uploadDto.FileName, uploadDto.FileName, HttpContext.GetName(), formFile, uploadDto.filePath);
break;
case StoreType.REMOTE:
break;
@ -140,14 +154,14 @@ namespace DOAN.Admin.WebApi.Controllers
{
return ToResponse(ResultCode.CUSTOM_ERROR, "上传文件过大,不能超过 " + AlimaxContentLength + " MB");
}
sysfile = new(formFile.FileName, uploadDto.FileName, fileExt, fileSize + "kb", uploadDto.FileDir, HttpContext.GetName())
file = new(formFile.FileName, uploadDto.FileName, fileExt, fileSize + "kb", uploadDto.FileDir, HttpContext.GetName())
{
StoreType = (int)StoreType.ALIYUN,
FileType = formFile.ContentType
};
sysfile = await SysFileService.SaveFileToAliyun(sysfile, formFile);
file = await SysFileService.SaveFileToAliyun(file, formFile);
if (sysfile.Id <= 0) { return ToResponse(ApiResult.Error("阿里云连接失败")); }
if (file.Id <= 0) { return ToResponse(ApiResult.Error("阿里云连接失败")); }
break;
case StoreType.TENCENT:
break;
@ -158,12 +172,31 @@ namespace DOAN.Admin.WebApi.Controllers
}
return SUCCESS(new
{
url = sysfile.AccessUrl,
fileName = sysfile.FileName,
fileId = sysfile.Id.ToString()
url = file.AccessUrl,
fileName = file.FileName,
fileId = file.Id.ToString()
});
}
public class UploadDto2
{
/// <summary>
/// 自定文件名
/// </summary>
public string? FileName { get; set; }
/// <summary>
/// 存储目录
/// </summary>
public string? FileDir { get; set; }
/// <summary>
/// 文件名生成类型 1 原文件名 2 自定义 3 自动生成
/// </summary>
public int FileNameType { get; set; }
/// <summary>
/// 存储目录 比FileDir 优先
/// </summary>
public string filePath { get; set; }
public IFormFile? File { get; set; }
}
#endregion
/// <summary>

View File

@ -56,14 +56,14 @@ public class ReportFlowController : BaseController
}
//TODO 领料工序
[HttpGet("feed_process_reportwork")]
public IActionResult FeedProcessReportwork(string workorder, int processId, int finish_num,string stove_code,string feed_order)
public IActionResult FeedProcessReportwork(string workorder, int processId, int finish_num,string stove_code,string feed_order,string process_operator)
{
if (string.IsNullOrEmpty(workorder))
{
throw new CustomException("workorder or process is null");
}
return SUCCESS(_reportFlowService.FeedProcessReportwork(workorder, processId, finish_num, stove_code, feed_order, HttpContext.GetNickName()));
return SUCCESS(_reportFlowService.FeedProcessReportwork(workorder, processId, finish_num, stove_code, feed_order, process_operator));
}
//TODO 工序报工
@ -77,26 +77,26 @@ public class ReportFlowController : BaseController
/// <returns></returns>
/// <exception cref="CustomException"></exception>
[HttpGet("process_reportwork")]
public IActionResult ProcessReportWork(string workorder, int processId, int finish_num,int bad_num)
public IActionResult ProcessReportWork(string workorder, int processId, int finish_num,int bad_num,string process_operator)
{
if (string.IsNullOrEmpty(workorder))
{
throw new CustomException("workorder or process is null");
}
return SUCCESS(_reportFlowService.ProcessReportWork(workorder, processId, finish_num,bad_num,HttpContext.GetNickName()));
return SUCCESS(_reportFlowService.ProcessReportWork(workorder, processId, finish_num,bad_num, process_operator));
}
//TODO 出货工序
[HttpGet("shipment_process_reportwork")]
public IActionResult ShipmentProcessReportwork(string workorder, int processId, int finish_num, int bad_num, string customer_order)
public IActionResult ShipmentProcessReportwork(string workorder, int processId, int finish_num, int bad_num, string customer_order, string process_operator)
{
if (string.IsNullOrEmpty(workorder))
{
throw new CustomException("workorder or process is null");
}
return SUCCESS(_reportFlowService.ShipmentProcessReportwork(workorder, processId, finish_num, bad_num, customer_order, HttpContext.GetNickName()));
return SUCCESS(_reportFlowService.ShipmentProcessReportwork(workorder, processId, finish_num, bad_num, customer_order, process_operator));
}
//TODO 获取工单下的报工列表

View File

@ -0,0 +1,7 @@
### GET request to example server
GET https://examples.http-client.intellij.net/get
?generated-in=JetBrains Rider
### 工单打印接口
GET http://localhost:8888/mes/productManagement/ProWorkorder/print?workorderArray=20241210_3A_1_001
##

View File

@ -2,7 +2,8 @@
"dbConfigs": [
{
//
"Conn": "Data Source=192.168.0.58;User ID=root;Password=123456;Initial Catalog=bzfm_mes;Port=3306",
"Conn": "Data Source=139.224.232.211;User ID=root;Password=doantech123;Initial Catalog=bzfm_mes;Port=3308",
// "Conn": "Data Source=192.168.0.58;User ID=root;Password=123456;Initial Catalog=bzfm_mes;Port=3306",
"DbType": 0, // MySql = 0, SqlServer = 1, Oracle = 3PgSql = 4
"ConfigId": "0", //
"IsAutoCloseConnection": true

View File

@ -19,5 +19,13 @@
},
"ShowDbLog": false, //db
"urls": "http://0.0.0.0:8888", //urldevServer
"corsUrls": [ "http://localhost:8887", "http://localhost:8886", "http://localhost:9090", "http://localhost:8080" ] //","
"corsUrls": [ "http://localhost:8887", "http://localhost:8886", "http://localhost:9090", "http://localhost:8080" ], //","
"Upload": {
"rootDirectory": "D:/MES/file",
"uploadUrl": "http://127.0.0.1:7000", //访
"localSavePath": "", // wwwroot+localSavePath
"maxSize": 15, // 15M
"notAllowedExt": [ ".bat", ".exe", ".jar", ".js" ]
}
}

View File

@ -1,4 +1,5 @@
namespace DOAN.Model.Dto

namespace DOAN.Model.Dto
{
public class UploadDto
{
@ -14,5 +15,10 @@
/// 文件名生成类型 1 原文件名 2 自定义 3 自动生成
/// </summary>
public int FileNameType { get; set; }
/// <summary>
/// 存储目录 比FileDir 优先
/// </summary>
public string filePath { get; set; }
}
}

View File

@ -30,6 +30,7 @@ using DOAN.Model.MES.base_.Dto;
using Infrastructure.Converter;
using QuestPDF;
using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;
@ -679,8 +680,8 @@ namespace DOAN.Service.MES.product
int index = (row - 3);
string nickCode = ProductCodeList.Where(it => it.DictLabel == workorder.productionCode)
.Select(it => it.DictValue).FirstOrDefault();
workorder.Workorder = dateValue.ToString("yyyyMMdd") + "_" + workorder.RouteCode +
workorder.GroupCode + "_" + nickCode + "_" + index.ToString("000");
workorder.Workorder = dateValue.ToString("yyyyMMdd") + "_" +workorder.GroupCode+ workorder.RouteCode +
"_" + nickCode + "_" + index.ToString("000");
workorder.Sort = index * 10;
@ -997,8 +998,8 @@ namespace DOAN.Service.MES.product
string nickCode = ProductCodeList.Where(it => it.DictLabel == workorder.productionCode)
.Select(it => it.DictValue).FirstOrDefault();
workorder.Workorder = dateValue.ToString("yyyyMMdd") + "_" + workorder.RouteCode +
workorder.GroupCode + "_" + nickCode + "_" + index.ToString("000");
workorder.Workorder = dateValue.ToString("yyyyMMdd") + "_" + workorder.GroupCode+ workorder.RouteCode +
"_" + nickCode + "_" + index.ToString("000");
workorder.Sort = index * 10 + Convert.ToInt16(MaxWorkorder.Sort);
@ -1299,7 +1300,12 @@ namespace DOAN.Service.MES.product
}
/// <summary>
/// https://www.questpdf.com/
/// </summary>
/// <param name="workorderArray"></param>
/// <returns></returns>
public async Task<(string, Stream)> ExportPDFByQuestPDFDemo(string[] workorderArray)
{
@ -1315,38 +1321,51 @@ namespace DOAN.Service.MES.product
Settings.CheckIfAllTextGlyphsAreAvailable = false;
var document = QuestPDF.Fluent.Document.Create(container =>
{
int PageWidth = 40 * 10;
int PageHeight = 30 * 10;
for (int i = 0; i < dataList.Count(); i++)
{
byte[] imageBytes= PrintHelper.CreateBarCode(dataList[i].Workorder, 30, 30);
container.Page(page =>
byte[] imageBytes = PrintHelper.CreateBarCode(dataList[i].Workorder, PageWidth * 3, PageHeight);
container.Page(page =>
{
page.Margin(20);
// 设置页面大小为A4默认有页边距
//page.Size(new PageSize(40*10,30*10)); // 移除默认页边距或设置自定义边距
page.Size(PageWidth, PageHeight);
page.DefaultTextStyle(TextStyle.Default.FontSize(16*2-5));
//page.DefaultTextStyle(TextStyle.Default.FontSize(1));
page.Content().Column(column =>
{
column.Item().Table(table =>
{
// Define columns
// 动态计算列宽,减去必要的边距
float columnWidth = (PageWidth) / 8;
table.ColumnsDefinition(columns =>
{
columns.RelativeColumn(); // Column 1
columns.RelativeColumn(); // Column 2
columns.RelativeColumn();
columns.RelativeColumn();
columns.RelativeColumn();
columns.RelativeColumn();
columns.RelativeColumn();
columns.RelativeColumn();
for (int j = 0; j < 8; j++)
columns.ConstantColumn(columnWidth);
});
table.Cell().Row(1).ColumnSpan(8).Image(imageBytes);
table.Cell().Row(2).Column(2).Text("编号");
table.Cell().Row(2).Column(6).Text(dataList[i].Workorder);
table.Cell().Row(3).Column(2).Text("炉号");
table.Cell().Row(3).Column(6).Text(dataList[i].StoveCode);
table.Cell().Row(4).Column(2).Text("数量");
table.Cell().Row(4).Column(6).Text(dataList[i].PlanNum);
// 创建一个单元格跨越所有列,用于放置图片
table.Cell().ColumnSpan(8).Image(imageBytes);
table.Cell().ColumnSpan(8).MinHeight(PageHeight / 7/4);
// 剩余内容...
// 注意:确保剩余内容的高度不超过剩余的页面空间
// 这里只是一个简单的例子,实际应用中你可能需要更复杂的逻辑来计算剩余可用空间
table.Cell().ColumnSpan(2).Border(1).MinHeight(PageHeight/7).AlignLeft().Padding(1).Text("编号");
table.Cell().ColumnSpan(6).Border(1).MinHeight(PageHeight/7).AlignLeft().Padding(1).Text(dataList[i].Workorder);
table.Cell().ColumnSpan(2).Border(1).MinHeight(PageHeight/7).AlignLeft().Padding(1).Text("炉号");
table.Cell().ColumnSpan(6).Border(1).MinHeight(PageHeight/7).AlignLeft().Padding(1).Text(dataList[i].StoveCode);
table.Cell().ColumnSpan(2).Border(1).MinHeight(PageHeight/7).AlignLeft().Padding(1).Text("数量");
table.Cell().ColumnSpan(6).Border(1).MinHeight(PageHeight/7).AlignLeft().Padding(1).Text(dataList[i].PlanNum);
for (int j = 0; j< 8; j++)
{
table.Cell().Border(1).MinHeight(PageHeight/7).AlignCenter().Text($"[{j+1}]");
}
});
});
});

View File

@ -2,6 +2,7 @@ using DOAN.Model.MES.base_;
using DOAN.Model.MES.product;
using DOAN.Model.Mobile.ReportFlow.Dto;
using DOAN.Model.Public;
using DOAN.Model.System;
using DOAN.Service.Mobile.IService;
using DOAN.Service.Public.IPublicService;
using Infrastructure.Attribute;
@ -41,6 +42,9 @@ public class ReportFlowService : BaseService<ProReportwork01>, IReportFlowServic
{
int result = 0;
bool Exist = Context.Queryable<ProReportwork01>().Where(it => it.Workorder == workorder && it.ProcessId == processId).Any();
string NickName= Context.Queryable<SysUser>().Where(it=>it.UserName==Worker).Select(it=>it.NickName).First();
Worker = string.IsNullOrEmpty(NickName) ? Worker : NickName;
if (Exist)
{
result = Context.Updateable<ProReportwork01>().Where(it => it.Workorder == workorder && it.ProcessId == processId)
@ -81,6 +85,8 @@ public class ReportFlowService : BaseService<ProReportwork01>, IReportFlowServic
{
int result = 0;
bool Exist = Context.Queryable<ProReportwork01>().Where(it => it.Workorder == workorder && it.ProcessId == process).Any();
string NickName = Context.Queryable<SysUser>().Where(it => it.UserName == Worker).Select(it => it.NickName).First();
Worker = string.IsNullOrEmpty(NickName) ? Worker : NickName;
if (Exist)
{
result = Context.Updateable<ProReportwork01>().Where(it => it.Workorder == workorder && it.ProcessId == process)
@ -125,6 +131,8 @@ public class ReportFlowService : BaseService<ProReportwork01>, IReportFlowServic
{
int result = 0;
bool Exist = Context.Queryable<ProReportwork01>().Where(it => it.Workorder == workorder && it.ProcessId == processId).Any();
string NickName = Context.Queryable<SysUser>().Where(it => it.UserName == Worker).Select(it => it.NickName).First();
Worker = string.IsNullOrEmpty(NickName) ? Worker : NickName;
if (Exist)
{
result = Context.Updateable<ProReportwork01>()

View File

@ -17,7 +17,16 @@ namespace DOAN.ServiceCore.Services
/// <param name="userName"></param>
/// <returns>文件对象</returns>
Task<SysFile> SaveFileToLocal(string rootPath, string fileName, string fileDir, string userName, IFormFile formFile);
/// <summary>
/// 上传文件
/// </summary>
/// <param name="fileDir"></param>
/// <param name="fileName"></param>
/// <param name="formFile"></param>
/// <param name="rootPath"></param>
/// <param name="userName"></param>
/// <returns>文件对象</returns>
Task<SysFile> SaveFileToLocal(string rootPath, string fileName, string fileDir, string userName, IFormFile formFile, string filePath);
Task<SysFile> SaveFileToAliyun(SysFile file, IFormFile formFile);
/// <summary>
/// 按时间来创建文件夹

View File

@ -69,6 +69,50 @@ namespace DOAN.ServiceCore.Services
return file;
}
/// <summary>
/// 存储本地
/// </summary>
/// <param name="fileDir">存储文件夹</param>
/// <param name="rootPath">存储根目录</param>
/// <param name="fileName">自定文件名</param>
/// <param name="formFile">上传的文件流</param>
/// <param name="userName"></param>
/// <param name="filePath">文件路径</param>
/// <returns></returns>
public async Task<SysFile> SaveFileToLocal(string rootPath, string fileName, string fileDir, string userName, IFormFile formFile, string filePath)
{
string fileExt = Path.GetExtension(formFile.FileName);
fileName = (fileName.IsEmpty() ? HashFileName() : fileName) + fileExt;
if (string.IsNullOrEmpty(filePath))
{
filePath = GetdirPath(fileDir);
}
string finalFilePath = Path.Combine(rootPath, filePath, fileName);
double fileSize = Math.Round(formFile.Length / 1024.0, 2);
if (!Directory.Exists(Path.GetDirectoryName(finalFilePath)))
{
Directory.CreateDirectory(Path.GetDirectoryName(finalFilePath));
}
using (var stream = new FileStream(finalFilePath, FileMode.Create))
{
await formFile.CopyToAsync(stream);
}
string uploadUrl = OptionsSetting.Upload.UploadUrl;
string accessPath = string.Concat(uploadUrl, "/", filePath.Replace("\\", "/"), "/", fileName);
SysFile file = new(formFile.FileName, fileName, fileExt, fileSize + "kb", filePath, userName)
{
StoreType = (int)StoreType.LOCAL,
FileType = formFile.ContentType,
FileUrl = finalFilePath.Replace("\\", "/"),
AccessUrl = accessPath
};
file.Id = await InsertFile(file);
return file;
}
/// <summary>
/// 上传文件到阿里云
/// </summary>

View File

@ -30,7 +30,7 @@ public class PrintHelper
var zzb = new ZXing.ZKWeb.BarcodeWriter();
zzb.Options = new EncodingOptions()
{
Margin = 3,
Margin = 0,
PureBarcode = false
};

View File

@ -68,6 +68,7 @@ namespace Infrastructure.Model
/// </summary>
public class Upload
{
public string rootDirectory { get; set; }
public string UploadUrl { get; set; }
public string LocalSavePath { get; set; }
public int MaxSize { get; set; }