diff --git a/ZR.Admin.WebApi/Controllers/BaseController.cs b/ZR.Admin.WebApi/Controllers/BaseController.cs index fb72640c..e202e809 100644 --- a/ZR.Admin.WebApi/Controllers/BaseController.cs +++ b/ZR.Admin.WebApi/Controllers/BaseController.cs @@ -64,7 +64,8 @@ namespace ZR.Admin.WebApi.Controllers var stream = Io.File.OpenRead(path); //创建文件流 Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition"); - return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", HttpUtility.UrlEncode(fileName)); + return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", HttpUtility.UrlEncode(fileName)); + // return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileName); } #region 方法 diff --git a/ZR.Admin.WebApi/Controllers/mes/pro/ProWorkorderV2Controller.cs b/ZR.Admin.WebApi/Controllers/mes/pro/ProWorkorderV2Controller.cs new file mode 100644 index 00000000..55095723 --- /dev/null +++ b/ZR.Admin.WebApi/Controllers/mes/pro/ProWorkorderV2Controller.cs @@ -0,0 +1,162 @@ +using Infrastructure.Extensions; +using JinianNet.JNTemplate; +using Microsoft.AspNetCore.Mvc; +using Microsoft.IdentityModel.Tokens; +using MiniExcelLibs; +using Model.DBModel; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using SqlSugar; +using System.Text.Json; +using ZR.Admin.WebApi.Extensions; +using ZR.Admin.WebApi.Filters; +using ZR.Model.mes.pro; +using ZR.Model.MES.pro; +using ZR.Service.mes.pro; +using ZR.Service.mes.pro.IService; + +namespace ZR.Admin.WebApi.Controllers.mes.pro +{ + [Route("mes/pro/workorder_v2")] + public class ProWorkorderV2Controller : BaseController + { + + + private readonly IProWorkorderServiceV2 proWorkorderService; + + + + public ProWorkorderV2Controller(IProWorkorderServiceV2 proWorkorderService) + { + this.proWorkorderService = proWorkorderService; + } + + + + + [HttpGet("getWorkoderList")] + public IActionResult GetWorkorderList(int pageNum, int pageSize, int year = -1, int week = -1, int date = -1) + { + (List, int) data = proWorkorderService.GetWorkorderList(pageNum, pageSize, year, week, date, 0); + + return ToResponse(new ApiResult(200, "success", data)); + } + + /// + /// 生产工单模板下载 + /// + /// + [HttpGet("importTemplate")] + [Log(Title = "生产工单模板模板", BusinessType = BusinessType.EXPORT, IsSaveRequestData = true, IsSaveResponseData = false)] + [AllowAnonymous] //不需要授权 就可以访问 + public IActionResult ImportTemplateExcel() + { + (string, string) result = DownloadImportTemplate("日生产计划模板");//返回文件名和路径 + return ExportExcel(result.Item2, result.Item1); + } + + /// + /// 导入 + /// + /// 使用IFromFile必须使用name属性否则获取不到文件 + /// + [HttpPost("importData")] + [Log(Title = "生产计划导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = true)] + public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile, bool updateSupport) + { + //1.0 读取excel 文件 保存在指定位置 + IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment)); + string sFileName = DateTime.Now.ToString("yyyyMMddHHmmss") + formFile.FileName; + string target = Path.Combine(webHostEnvironment.WebRootPath, "workorder", sFileName); + int year = 0; + int week = 0; + int date = 0; + using (var stream = formFile.OpenReadStream()) + { + FileStream targetFileStream = new FileStream(target, FileMode.Create, FileAccess.Write); + + byte[] buffer = new byte[1024]; + int bytesRead; + while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0) + { + targetFileStream.Write(buffer, 0, bytesRead); + } + + //2.0 解析excel + //读取第一行 解析 年和月 + var row = stream.Query().Skip(1).First(); + year = Convert.ToInt32(row.A); + week = Convert.ToInt32(row.B); + date = Convert.ToInt32(row.C); + + + //读取列表数据 + try + { + var list = stream.Query(sheetName: "Sheet1", startCell: "A3") + .Where(it => it.FinishedPartNumber != null) + .Where(it =>it.BlankNumber!=null&&!it.BlankNumber.Contains("圈数")) + .ToList(); + list.ForEach(it => + { + it.ToCreate(HttpContext); + it.Year = year; + it.Week = week; + it.Date = date; + + }); + string result = proWorkorderService.ImportExceldata(list); + return SUCCESS(result); + } + catch (Exception ex) + { + return ToResponse(ResultCode.GLOBAL_ERROR, "模板内容错误,请仔细检测格式,并联系管理员" + ex.Message); + } + + } + return SUCCESS(null); + } + + /// + /// 浏览器下载 生产工单 + /// + /// + /// + [HttpGet("downloadWorkorder")] + [Log(Title = "下载生产工单", BusinessType = BusinessType.EXPORT)] + public IActionResult UserExport(int? year, int? week,int? date) + { + if (year == null || week == null || date==null) + { + return SUCCESS(0); + } + var result = proWorkorderService.ExportExceldata((int)year, (int)week,(int)date); + + + return ExportExcel(result.Item2, result.Item1); + } + /// + /// 删除本周所有计划 + /// + /// + /// + [HttpGet("deleteAll")] + public IActionResult DeleteAllItem(int? year, int? week, int? date) + { + int data = 0; + if (week != null && week > 0) + { + if (year != null && year > 0) + data = proWorkorderService.DeleteAllWorkorder((int)year, (int)week,(int)date); + } + + return ToResponse(new ApiResult(200, "success", data)); + } + + + + + + + } +} diff --git a/ZR.Admin.WebApi/Controllers/mes/pro/ProWorkplanV2Controller.cs b/ZR.Admin.WebApi/Controllers/mes/pro/ProWorkplanV2Controller.cs index 229897c7..1173ba2e 100644 --- a/ZR.Admin.WebApi/Controllers/mes/pro/ProWorkplanV2Controller.cs +++ b/ZR.Admin.WebApi/Controllers/mes/pro/ProWorkplanV2Controller.cs @@ -1,7 +1,21 @@ -using Microsoft.AspNetCore.Mvc; +using Aliyun.OSS; +using AutoMapper.Configuration.Conventions; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Hosting.Internal; +using MimeKit; +using MiniExcelLibs; +using MiniExcelLibs.OpenXml; using Model.DBModel; +using Org.BouncyCastle.Crypto.IO; +using System.IO; using ZR.Admin.WebApi.Extensions; +using ZR.Admin.WebApi.Filters; +using ZR.Model; using ZR.Model.mes.pro; +using ZR.Model.MES.pro.DTO; +using ZR.Model.System; +using ZR.Model.System.Dto; +using ZR.Service.mes.pro; using ZR.Service.mes.pro.IService; namespace ZR.Admin.WebApi.Controllers.mes.pro @@ -71,7 +85,23 @@ namespace ZR.Admin.WebApi.Controllers.mes.pro return ToResponse(new ApiResult(200, "success", data)); } + /// + /// 删除本周所有计划 + /// + /// + /// + [HttpGet("deleteAll")] + public IActionResult DeleteAllItem(int? year,int? week) + { + int data = 0; + if (week!=null&&week>0) + { + if (year != null && year > 0) + data = proWorkplanService.DeleteAllWorkPlan((int)year,(int)week); + } + return ToResponse(new ApiResult(200, "success", data)); + } /// @@ -93,5 +123,131 @@ namespace ZR.Admin.WebApi.Controllers.mes.pro return ToResponse(new ApiResult(200, "success", data)); } + + /// + /// 生产计划模板下载 + /// + /// + [HttpGet("importTemplate")] + [Log(Title = "生产计划模板模板", BusinessType = BusinessType.EXPORT, IsSaveRequestData = true, IsSaveResponseData = false)] + [AllowAnonymous] //不需要授权 就可以访问 + public IActionResult ImportTemplateExcel() + { + (string, string) result = DownloadImportTemplate("周生产计划模板");//返回文件名和路径 + return ExportExcel(result.Item2, result.Item1); + } + + /// + /// 获取周汇总 + /// + /// + /// + /// + [HttpGet("getWeekSummary")] + public IActionResult GetWeekSummary(int? year, int? week) + { + if (year == null && week == null) + { + return SUCCESS(0); + } + WorkplanSummaryDto workplanSummaryDto = proWorkplanService.GetWeekSummary((int)year, (int)week); + return SUCCESS(workplanSummaryDto); + + } + + + /// + /// 导入 + /// + /// 使用IFromFile必须使用name属性否则获取不到文件 + /// + [HttpPost("importData")] + [Log(Title = "生产计划导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = true)] + public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile, bool updateSupport) + { + //1.0 读取excel 文件 保存在指定位置 + IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment)); + string sFileName = DateTime.Now.ToString("yyyyMMddHHmmss") + formFile.FileName; + string target = Path.Combine(webHostEnvironment.WebRootPath, "workplan", sFileName); + int year = 0; + int week = 0; + using (var stream = formFile.OpenReadStream()) + { + FileStream targetFileStream = new FileStream(target, FileMode.Create, FileAccess.Write); + + byte[] buffer = new byte[1024]; + int bytesRead; + while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0) + { + targetFileStream.Write(buffer, 0, bytesRead); + } + + //2.0 解析excel + //读取第一行 解析 年和月 + var row = stream.Query().Take(1).First(); + year = Convert.ToInt32(row.A); + + week = Convert.ToInt32(row.B); + + + //读取列表数据 + try + { + var list = stream.Query(sheetName: "Sheet1", startCell: "B3") + .Where(it => it.Partnumber != null) + .Where(it => !it.Partnumber.Contains("合计")) + .Where(it => it.RequireNum > 0) + .ToList(); + list.ForEach(it => + { + it.ToCreate(HttpContext); + it.Year = year; + it.Week = week; + + }); + string result = proWorkplanService.ImportExceldata(list); + return SUCCESS(result); + } + catch (Exception ex) + { + return ToResponse(ResultCode.GLOBAL_ERROR,"模板内容错误,请仔细检测格式,并联系管理员"+ex.Message); + } + + + + + + + + + + } + + + + return SUCCESS(null); + } + + /// + /// 浏览器下载 生产计划 + /// + /// + /// + [HttpGet("downloadWorkplan")] + [Log(Title = "下载生产计划", BusinessType = BusinessType.EXPORT)] + public IActionResult UserExport(int? year, int? week) + { + if (year == null || week == null) + { + return SUCCESS(0); + } + var result = proWorkplanService.ExportExceldata((int)year, (int)week); + + + return ExportExcel(result.Item2, result.Item1); + } + + + } } diff --git a/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj b/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj index 0a3f610e..7c1dc8c0 100644 --- a/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj +++ b/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj @@ -16,6 +16,9 @@ True False + + + @@ -40,6 +43,9 @@ + + + diff --git a/ZR.Admin.WebApi/wwwroot/ImportTemplate/周计划标准模板.xlsx b/ZR.Admin.WebApi/wwwroot/ImportTemplate/周计划标准模板.xlsx new file mode 100644 index 00000000..df89cb78 Binary files /dev/null and b/ZR.Admin.WebApi/wwwroot/ImportTemplate/周计划标准模板.xlsx differ diff --git a/ZR.Admin.WebApi/wwwroot/ImportTemplate/周计划标准模板1.xlsx b/ZR.Admin.WebApi/wwwroot/ImportTemplate/周计划标准模板1.xlsx new file mode 100644 index 00000000..0b184866 Binary files /dev/null and b/ZR.Admin.WebApi/wwwroot/ImportTemplate/周计划标准模板1.xlsx differ diff --git a/ZR.Admin.WebApi/wwwroot/ImportTemplate/日生产计划模板.xlsx b/ZR.Admin.WebApi/wwwroot/ImportTemplate/日生产计划模板.xlsx new file mode 100644 index 00000000..6f35b14c Binary files /dev/null and b/ZR.Admin.WebApi/wwwroot/ImportTemplate/日生产计划模板.xlsx differ diff --git a/ZR.Admin.WebApi/wwwroot/ImportTemplate/日生产计划模板1.xlsx b/ZR.Admin.WebApi/wwwroot/ImportTemplate/日生产计划模板1.xlsx new file mode 100644 index 00000000..3dc3c964 Binary files /dev/null and b/ZR.Admin.WebApi/wwwroot/ImportTemplate/日生产计划模板1.xlsx differ diff --git a/ZR.Model/MES/pro/DTO/WorkplanSummaryDto.cs b/ZR.Model/MES/pro/DTO/WorkplanSummaryDto.cs new file mode 100644 index 00000000..632830b3 --- /dev/null +++ b/ZR.Model/MES/pro/DTO/WorkplanSummaryDto.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ZR.Model.MES.pro.DTO +{ + public class WorkplanSummaryDto + { + + + public float requireNum { set; get; } + public float requireHanger { set; get; } + public float turnnum { set; get; } + public float productiontime { set; get; } + + + + + + } +} diff --git a/ZR.Model/MES/pro/ProWorklplan_v2.cs b/ZR.Model/MES/pro/ProWorklplan_v2.cs index f9e60538..d440cc91 100644 --- a/ZR.Model/MES/pro/ProWorklplan_v2.cs +++ b/ZR.Model/MES/pro/ProWorklplan_v2.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using MiniExcelLibs.Attributes; using SqlSugar; /* @@ -21,18 +22,22 @@ namespace Model.DBModel /// WP2024030001 /// [SugarColumn(ColumnName = "id",IsPrimaryKey = true)] + [ExcelIgnore] public string Id { get; set; } /// /// 零件号 /// [SugarColumn(ColumnName = "partnumber")] + [ExcelColumn(Name = "零件号", IndexName = "C")] public string Partnumber { get; set; } /// /// 产品描述 /// [SugarColumn(ColumnName = "product_name")] + + [ExcelColumn(Name = "产品描述", IndexName = "D")] public string ProductName { get; set; } @@ -40,6 +45,7 @@ namespace Model.DBModel /// 规格 /// [SugarColumn(ColumnName = "specification")] + [ExcelColumn(Name = "规格", IndexName = "E")] public string Specification { get; set; } @@ -49,39 +55,52 @@ namespace Model.DBModel /// 颜色代码 /// [SugarColumn(ColumnName = "color_code")] + [ExcelColumn(Name = "颜色代码", IndexName = "F")] public string ColorCode { get; set; } /// /// 本周要货数量 /// - + [SugarColumn(ColumnName = "require_num")] - public float RequireNum { get; set; } + [ExcelColumn(Name = "本周要货数量", IndexName = "G")] + public int RequireNum { get; set; } /// /// 产品合格率 /// [SugarColumn(ColumnName = "qualification_rate")] - public float QualificationRate { get; set; } + [ExcelColumnIndex("H")] + [ExcelColumnName("产品合格率")] + + public double QualificationRate { get; set; } /// /// 每挂数量 /// [SugarColumn(ColumnName = "every_hanger_num")] + + [ExcelColumnIndex("I")] + [ExcelColumnName("每挂数量")] + public float EveryHangerNum { get; set; } /// /// 生产节拍(分钟) /// [SugarColumn(ColumnName = "production_beat")] + [ExcelColumnIndex("J")] + [ExcelColumnName("生产节拍(分钟)")] public decimal ProductionBeat { get; set; } /// /// 总挂具数 /// [SugarColumn(ColumnName = "all_hanger_num")] + [ExcelColumnIndex("K")] + [ExcelColumnName("总挂具数")] public float AllHangerNum { get; set; } /// @@ -89,6 +108,8 @@ namespace Model.DBModel /// /// [SugarColumn(ColumnName = "require_hanger")] + [ExcelColumnIndex("L")] + [ExcelColumnName("订单需生产挂具数量")] public float RequireHanger { get; set; } /// @@ -96,6 +117,8 @@ namespace Model.DBModel /// /// [SugarColumn(ColumnName = "turn_number")] + [ExcelColumnIndex("M")] + [ExcelColumnName("圈数")] public float TurnNumber { get; set; } /// @@ -103,6 +126,8 @@ namespace Model.DBModel /// [SugarColumn(ColumnName = "product_time")] + [ExcelColumnIndex("N")] + [ExcelColumnName("订单生产时间(分钟)")] public float ProductTime { get; set; } @@ -111,15 +136,26 @@ namespace Model.DBModel /// [SugarColumn(ColumnName = "no_schedule")] + [ExcelIgnore] public int NoSchedule { get; set; } /// /// 毛坯号 /// - [SugarColumn(ColumnName = "blank_num")] + [ExcelColumnIndex("B")] + [ExcelColumnName("毛坯号")] public string BlankNum { get; set; } + /// + /// 来源:手动插入,excel导入 + /// + [SugarColumn(ColumnName = "remark")] + [ExcelIgnore] + public string Remark { get; set; } + + + /// @@ -127,15 +163,15 @@ namespace Model.DBModel /// /// [SugarColumn(ColumnName = "year")] + [ExcelIgnore] public float Year { get; set; } /// /// 周 /// /// - - [SugarColumn(ColumnName = "week")] + [ExcelIgnore] public float Week { get; set; } @@ -143,9 +179,8 @@ namespace Model.DBModel /// 创建人 /// /// - - [SugarColumn(ColumnName = "CREATED_BY")] + [ExcelIgnore] public string CreatedBy { get; set; } /// @@ -153,6 +188,7 @@ namespace Model.DBModel /// /// [SugarColumn(ColumnName = "CREATED_TIME")] + [ExcelIgnore] public DateTime CreatedTime { get; set; } /// @@ -160,6 +196,7 @@ namespace Model.DBModel /// /// [SugarColumn(ColumnName = "UPDATED_BY")] + [ExcelIgnore] public string UpdatedBy { get; set; } /// @@ -167,6 +204,7 @@ namespace Model.DBModel /// /// [SugarColumn(ColumnName = "UPDATED_TIME")] + [ExcelIgnore] public DateTime UpdatedTime { get; set; } } diff --git a/ZR.Model/MES/pro/ProWorkorder_v2.cs b/ZR.Model/MES/pro/ProWorkorder_v2.cs new file mode 100644 index 00000000..09e64d4e --- /dev/null +++ b/ZR.Model/MES/pro/ProWorkorder_v2.cs @@ -0,0 +1,165 @@ +using MiniExcelLibs.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ZR.Model.MES.pro +{ + /// + /// 生产工单 + /// + [SugarTable("pro_workorder2", TableDescription = "生产工单")] + public class ProWorkorder_v2 + { + /// + /// 工单号WO20240301001 + /// + [SugarColumn(IsPrimaryKey = true,ColumnName ="id")] + [ExcelIgnore] + public string Id { get; set; } + + /// + /// 毛坯号 + /// + [SugarColumn(ColumnName = "blank_number")] + [ExcelColumn(Name = "毛坯号", IndexName = "A")] + public string BlankNumber { get; set; } + + /// + /// 成品零件号 + /// + [SugarColumn(ColumnName = "finished_part_number")] + [ExcelColumn(Name = "成品零件号", IndexName = "B")] + public string FinishedPartNumber { get; set; } + + /// + /// 产品描述 + /// + [SugarColumn(ColumnName = "product_description")] + [ExcelColumn(Name = "产品描述", IndexName = "C")] + public string ProductDescription { get; set; } + + /// + /// 颜色 + /// + [SugarColumn(ColumnName = "colour")] + [ExcelColumn(Name = "颜色", IndexName = "D")] + public string Colour { get; set; } + + /// + /// 规格 + /// + [SugarColumn(ColumnName = "specifications")] + [ExcelColumn(Name = "规格", IndexName = "E")] + public string Specifications { get; set; } + + /// + /// 编码号 + /// + [SugarColumn(ColumnName = "code_number")] + [ExcelColumn(Name = "编码号", IndexName = "F")] + public int CodeNumber { get; set; } + + /// + /// 车数 + /// + [SugarColumn(ColumnName = "vehicle_number")] + [ExcelColumn(Name = "车数", IndexName = "G")] + public int VehicleNumber { get; set; } + + /// + /// 挂具摆放 + /// + [SugarColumn(ColumnName = "hang_number")] + [ExcelColumn(Name = "挂具摆放", IndexName = "H")] + public int hangNumber { get; set; } + + /// + /// 上件数 + /// + [SugarColumn(ColumnName = "previous_number")] + [ExcelColumn(Name = "上件数", IndexName = "I")] + public int PreviousNumber { get; set; } + + /// + /// 双组号缸号 + /// + [SugarColumn(ColumnName = "cylinder_number")] + [ExcelColumn(Name = "双组号缸号", IndexName = "J")] + public string CylinderNumber { get; set; } + + /// + /// 备注1 + /// + [SugarColumn(ColumnName = "remark1")] + [ExcelColumn(Name = "备注1", IndexName = "K")] + public string Remark1 { get; set; } + + /// + /// 备注2 + /// + [SugarColumn(ColumnName = "remark2")] + [ExcelColumn(Name = "备注2", IndexName = "L")] + public string Remark2 { get; set; } + /// + /// 备注3 + /// + [SugarColumn(ColumnName = "remark3")] + [ExcelIgnore] + public string Remark3 { get; set; } + + /// + /// 年 + /// + [SugarColumn(ColumnName = "year")] + [ExcelIgnore] + public int Year { get; set; } + + /// + /// 周 + /// + [SugarColumn(ColumnName = "week")] + [ExcelIgnore] + public int Week { get; set; } + + /// + /// 日 + /// + [SugarColumn(ColumnName = "date")] + [ExcelIgnore] + public int Date { get; set; } + + /// + /// 创建人 + /// + [SugarColumn(ColumnName = "CREATED_BY")] + [ExcelIgnore] + public string CreatedBy { get; set; } + + /// + /// 创建时间 + /// + [SugarColumn(ColumnName = "CREATED_TIME")] + [ExcelIgnore] + public DateTime CreatedTime { get; set; } + + /// + /// 更新人 + /// + [SugarColumn(ColumnName = "UPDATED_BY")] + [ExcelIgnore] + public string UpdatedBy { get; set; } + + /// + /// 更新时间 + /// + [SugarColumn(ColumnName = "UPDATED_TIME")] + [ExcelIgnore] + public DateTime UpdatedTime { get; set; } + + + + } +} diff --git a/ZR.Model/ZR.Model.csproj b/ZR.Model/ZR.Model.csproj index d8ec2149..c313740a 100644 --- a/ZR.Model/ZR.Model.csproj +++ b/ZR.Model/ZR.Model.csproj @@ -7,7 +7,7 @@ - + diff --git a/ZR.Service/mes/pro/IService/IProWorkorderServiceV2.cs b/ZR.Service/mes/pro/IService/IProWorkorderServiceV2.cs new file mode 100644 index 00000000..665ec5ac --- /dev/null +++ b/ZR.Service/mes/pro/IService/IProWorkorderServiceV2.cs @@ -0,0 +1,31 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.VisualBasic; +using Model.DBModel; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ZR.Model.mes.pro; +using ZR.Model.MES.op.DTO; +using ZR.Model.MES.pro; +using ZR.Model.MES.pro.DTO; + +namespace ZR.Service.mes.pro.IService +{ + public interface IProWorkorderServiceV2 + { + + + public (List, int) GetWorkorderList(int pageNum, int pageSize, int year, int week, int date, int isSchedule); + + public string ImportExceldata(List proWorklplans); + + public (string, string) ExportExceldata(int year, int week, int date); + + + public int DeleteAllWorkorder(int year, int week, int date); + + } +} diff --git a/ZR.Service/mes/pro/IService/IProWorkplanServiceV2.cs b/ZR.Service/mes/pro/IService/IProWorkplanServiceV2.cs index 1b4019da..d26d9d57 100644 --- a/ZR.Service/mes/pro/IService/IProWorkplanServiceV2.cs +++ b/ZR.Service/mes/pro/IService/IProWorkplanServiceV2.cs @@ -2,11 +2,13 @@ using System; using System.Collections.Generic; using System.Drawing; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using ZR.Model.mes.pro; using ZR.Model.MES.op.DTO; +using ZR.Model.MES.pro.DTO; namespace ZR.Service.mes.pro.IService { @@ -27,6 +29,14 @@ namespace ZR.Service.mes.pro.IService public int UpdateWorkPlan(ProWorklplan_v2 proWorkplan); public int DeleteWorkPlan(string id); + public int DeleteAllWorkPlan(int year,int week); + + public string ImportExceldata(List proWorklplans); + + public (string,string) ExportExceldata(int year, int week); + + + public WorkplanSummaryDto GetWeekSummary(int year ,int week); /// /// 根据生产计划ID,获取工单列表 diff --git a/ZR.Service/mes/pro/ProWorkorderServiceV2.cs b/ZR.Service/mes/pro/ProWorkorderServiceV2.cs new file mode 100644 index 00000000..c1dffb8f --- /dev/null +++ b/ZR.Service/mes/pro/ProWorkorderServiceV2.cs @@ -0,0 +1,199 @@ +using Infrastructure.Attribute; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; +using ZR.Common; +using ZR.Model.mes.md; +using ZR.Model.mes.pro; +using ZR.Model.MES.wm; +using ZR.Service.mes.pro.IService; +using ZR.Service.MES.md.IService; +using static System.Net.WebRequestMethods; + +using JinianNet.JNTemplate; +using static Aliyun.OSS.Model.LiveChannelStat; +using ZR.Model.MES.pro.DTO; +using ZR.Model.MES.qu; +using ZR.Model.MES.pro; +using Model.DBModel; +using Infrastructure; +using Microsoft.AspNetCore.Hosting; +using MiniExcelLibs; +using System.IO; +using SqlSugar.Extensions; + +namespace ZR.Service.mes.pro +{ + [AppService(ServiceType = typeof(IProWorkorderServiceV2), ServiceLifetime = LifeTime.Transient)] + public class ProWorkorderServiceV2 : BaseService, IProWorkorderServiceV2 + { + + public (List, int) GetWorkorderList(int pageNum, int pageSize, int year, int week, int date, int isSchedule) + { + + var predicate = Expressionable.Create() + .AndIF(year > 0, it => it.Year == year) + .AndIF(week > 0, it => it.Week == week) + .AndIF(date > 0, it => it.Date == date) + .ToExpression(); + + int totalCount = 0; + List proWorkorderList = Context.Queryable().Where(predicate).OrderBy(it => it.Id).ToPageList(pageNum, pageSize, ref totalCount); + + return (proWorkorderList, totalCount); + } + /// + /// 获取生产计划id + /// + /// + private int Getworkplanid_max() + { + + ProWorkorder_v2 max_workoder = Context.Queryable().OrderBy(it => it.Id, OrderByType.Desc).First(); + if (max_workoder != null && !string.IsNullOrEmpty(max_workoder.Id) && max_workoder.Id.Substring(2, 8) == DateTime.Now.ToString("yyyyMMdd")) + { + int num = Convert.ToInt32(max_workoder.Id.Substring(10)) + 1; + return num; + } + else + { + return 0; + } + + + } + + + public string ImportExceldata(List workorderList) + { + int max_id = Getworkplanid_max(); + + + // 更新生产计划 + if (workorderList != null && workorderList.Count > 0) + { + workorderList.ForEach(it => + { + it.Id = "WO" + DateTime.Now.ToString("yyyyMMdd") + max_id.ToString("000"); + it.Remark3 = "Excel导入"; + max_id++; + }); + foreach (ProWorkorder_v2 item in workorderList) + { + ProWorklplan_v2 planItem = Context.Queryable().Where(it => it.Id == item.FinishedPartNumber).First(); + if (planItem != null) + { + Context.Updateable().Where(it => it.Id == planItem.Id) + .SetColumns(it => + + it.NoSchedule == planItem.RequireNum - item.hangNumber + ).ExecuteCommandAsync(); + + } + + } + + + UseTran(() => + { + // 删除之前的工单 + Context.Deleteable().Where(it => it.Year == workorderList[0].Year) + .Where(it => it.Week == workorderList[0].Week) + .Where(it => it.Date == workorderList[0].Date).ExecuteCommand(); + //插入 + Context.Insertable(workorderList).ExecuteCommand(); + + }); + + return "success"; + } + + //var x = Context.Storageable(workorderList) + // .SplitUpdate(it => it.Any())//存在更新 + // .SplitInsert(it => true)//否则插入(更新优先级大于插入) + // .WhereColumns(it => new { it.Year, it.Week, it.Date, it.FinishedPartNumber })//如果不是主键可以这样实现(多字段it=>new{it.x1,it.x2}) + // .ToStorage(); + + //x.AsInsertable.ExecuteCommand();//插入可插入部分; + //x.AsUpdateable.IgnoreColumns(it => it.Id).ExecuteCommand();//存在更新 + + //string msg = string.Format(" 插入{0} 更新{1} 错误数据{2} 不计算数据{3} 删除数据{4} 总共{5}", + // x.InsertList.Count, + // x.UpdateList.Count, + // x.ErrorList.Count, + // x.IgnoreList.Count, + // x.DeleteList.Count, + // x.TotalList.Count); + + + return ""; //插入可插入部分 + + } + + /// + /// 下载 + /// + /// + /// + /// + /// + public (string, string) ExportExceldata(int year, int week, int date) + { + //1.0 读取表数据 + var list = Queryable().Where(it => it.Year == year && it.Week == week && it.Date == date).ToList(); + + //2.0 保存为excel + IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment)); + string sFileName = $"{year}年{week}周{date}日计划-{DateTime.Now:MM-dd-HHmmss}.xlsx"; + + + string fullPath = Path.Combine(webHostEnvironment.WebRootPath, "export", sFileName); + + + Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); + + + + var Sheet1 = new + { + year = year, + week = week, + date=date, + title = $"{year}年车镜实业涂装事业{week}周{date}生产滚动表", + + workorder = list + }; + string templatePath = Path.Combine(webHostEnvironment.WebRootPath, "ImportTemplate", "日生产计划模板1.xlsx"); + MiniExcel.SaveAsByTemplate(fullPath, templatePath, Sheet1); + // MiniExcel.SaveAs(fullPath, list); + + + //3.0 返回路径和文件名 + return (sFileName, fullPath); + + + + + } + + /// + /// 删除周计划全部 + /// + /// + /// + /// + public int DeleteAllWorkorder(int year, int week, int date) + { + return Context.Deleteable().Where(it => it.Year == year && it.Week == week && it.Date == date).ExecuteCommand(); + } + + + } +} diff --git a/ZR.Service/mes/pro/ProWorkplanServiceV2.cs b/ZR.Service/mes/pro/ProWorkplanServiceV2.cs index f6fd237f..1d6ce36c 100644 --- a/ZR.Service/mes/pro/ProWorkplanServiceV2.cs +++ b/ZR.Service/mes/pro/ProWorkplanServiceV2.cs @@ -1,16 +1,22 @@ -using Infrastructure.Attribute; +using Infrastructure; +using Infrastructure.Attribute; using Mapster.Utils; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Routing.Template; using Microsoft.Extensions.DependencyInjection; +using MiniExcelLibs; using Model.DBModel; using SqlSugar; using System; using System.Collections.Generic; using System.Drawing; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using ZR.Model.mes.md; using ZR.Model.mes.pro; +using ZR.Model.MES.pro.DTO; using ZR.Service.mes.pro.IService; using ZR.Service.MES.md.IService; @@ -30,7 +36,7 @@ namespace ZR.Service.mes.pro .AndIF(!string.IsNullOrEmpty(color), it => it.ColorCode.Contains(color)) .ToExpression(); int totalCount = 0; - List proWorkplanList = Context.Queryable().Where(predicate).ToPageList(pageNum, pageSize, ref totalCount); + List proWorkplanList = Context.Queryable().Where(predicate).OrderBy(it => it.Id).ToPageList(pageNum, pageSize, ref totalCount); return (proWorkplanList, totalCount); } @@ -40,25 +46,59 @@ namespace ZR.Service.mes.pro return Context.Queryable().Where(it => it.Id == id).ToList(); } + + public int AddWorkPlan(ProWorklplan_v2 proWorkplan) { + proWorkplan.Id = "MP" + DateTime.Now.ToString("yyyyMMdd") + Getworkplanid_max().ToString("000"); + proWorkplan.Remark = "手动插入"; + return Context.Insertable(proWorkplan).ExecuteCommand(); + } + /// + /// 获取生产计划id + /// + /// + private int Getworkplanid_max() + { + ProWorklplan_v2 max_workplan = Context.Queryable().OrderBy(it => it.Id, OrderByType.Desc).First(); if (max_workplan != null && !string.IsNullOrEmpty(max_workplan.Id) && max_workplan.Id.Substring(2, 8) == DateTime.Now.ToString("yyyyMMdd")) { int num = Convert.ToInt32(max_workplan.Id.Substring(10)) + 1; - proWorkplan.Id = "MP" + DateTime.Now.ToString("yyyyMMdd") + num.ToString("000"); + return num; } else { - proWorkplan.Id = "MP" + DateTime.Now.ToString("yyyyMMdd") + "001"; + return 0; } - return Context.Insertable(proWorkplan).ExecuteCommand(); + } + // 修改 public int UpdateWorkPlan(ProWorklplan_v2 proWorkplan) { - return Context.Updateable(proWorkplan).ExecuteCommand(); + + + + return Context.Updateable() + .SetColumns(it => new ProWorklplan_v2() + { + BlankNum = proWorkplan.BlankNum, + Partnumber = proWorkplan.Partnumber, + ProductName = proWorkplan.ProductName, + Specification = proWorkplan.Specification, + ColorCode = proWorkplan.ColorCode, + RequireNum = proWorkplan.RequireNum, + EveryHangerNum = proWorkplan.EveryHangerNum, + ProductionBeat = proWorkplan.ProductionBeat, + AllHangerNum = proWorkplan.AllHangerNum, + TurnNumber = proWorkplan.TurnNumber, + ProductTime = proWorkplan.ProductTime, + RequireHanger = proWorkplan.RequireHanger, + }) + .Where(it => it.Id == proWorkplan.Id) + .ExecuteCommand(); } public int DeleteWorkPlan(string id) @@ -66,6 +106,84 @@ namespace ZR.Service.mes.pro return Context.Deleteable().In(id).ExecuteCommand(); } + + public string ImportExceldata(List worklplanList) + { + int max_id = Getworkplanid_max(); + worklplanList.ForEach(it => + { + it.Id = "MP" + DateTime.Now.ToString("yyyyMMdd") + max_id.ToString("000"); + it.Remark = "Excel导入"; + max_id++; + }); + + var x = Context.Storageable(worklplanList) + .SplitUpdate(it => it.Any())//存在更新 + .SplitInsert(it => true)//否则插入(更新优先级大于插入) + .WhereColumns(it => new { it.Year, it.Week, it.Partnumber })//如果不是主键可以这样实现(多字段it=>new{it.x1,it.x2}) + .ToStorage(); + + x.AsInsertable.ExecuteCommand();//插入可插入部分; + x.AsUpdateable.IgnoreColumns(it => it.Id).ExecuteCommand();//存在更新 + + string msg = string.Format(" 插入{0} 更新{1} 错误数据{2} 不计算数据{3} 删除数据{4} 总共{5}", + x.InsertList.Count, + x.UpdateList.Count, + x.ErrorList.Count, + x.IgnoreList.Count, + x.DeleteList.Count, + x.TotalList.Count); + + + return msg; //插入可插入部分 + + } + + + /// + /// 下载 + /// + /// + /// + /// + public (string, string) ExportExceldata(int year, int week) + { + //1.0 读取表数据 + var list = Queryable().Where(it => it.Year == year && it.Week == week).ToList(); + + //2.0 保存为excel + IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment)); + string sFileName = $"{year}年{week}周计划-{DateTime.Now:MM-dd-HHmmss}.xlsx"; + + + string fullPath = Path.Combine(webHostEnvironment.WebRootPath, "export", sFileName); + + + Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); + + + + var Sheet1 = new + { + year = year, + week = week, + title = $"{year}年车镜实业涂装事业{week}周生产滚动表", + + workplan = list + }; + string templatePath = Path.Combine(webHostEnvironment.WebRootPath, "ImportTemplate", "周计划标准模板1.xlsx"); + MiniExcel.SaveAsByTemplate(fullPath, templatePath, Sheet1); + // MiniExcel.SaveAs(fullPath, list); + + + //3.0 返回路径和文件名 + return (sFileName, fullPath); + + + + + } + public List GetWorkorderListByPlanId(string id) { return Context.Queryable().Where(it => it.FkProPlanId == id).OrderBy("priority desc ").ToList(); @@ -93,5 +211,42 @@ namespace ZR.Service.mes.pro } + + /// + /// 周计划汇总 + /// + /// + /// + public WorkplanSummaryDto GetWeekSummary(int year, int week) + { + return Context.Queryable().Where(it => it.Year == year && it.Week == week) + .GroupBy(it => new { it.Week }) + .Select(it => new WorkplanSummaryDto + { + requireNum = SqlFunc.AggregateSum(it.RequireNum), + requireHanger = SqlFunc.AggregateSum(it.RequireHanger), + turnnum = SqlFunc.AggregateSum(it.TurnNumber), + productiontime = SqlFunc.AggregateSum(it.ProductTime), + + }) + .First(); + + + + } + /// + /// 删除周计划全部 + /// + /// + /// + /// + public int DeleteAllWorkPlan(int year,int week) + { + return Context.Deleteable().Where(it => it.Year == year && it.Week == week).ExecuteCommand(); + } + + + + } }