模板导出成功
This commit is contained in:
@@ -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<ProWorklplan_v2> proWorkplanList = Context.Queryable<ProWorklplan_v2>().Where(predicate).ToPageList(pageNum, pageSize, ref totalCount);
|
||||
List<ProWorklplan_v2> proWorkplanList = Context.Queryable<ProWorklplan_v2>().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<ProWorkplan>().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();
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取生产计划id
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private int Getworkplanid_max()
|
||||
{
|
||||
|
||||
ProWorklplan_v2 max_workplan = Context.Queryable<ProWorklplan_v2>().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<ProWorklplan_v2>()
|
||||
.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<ProWorklplan_v2>().In(id).ExecuteCommand();
|
||||
}
|
||||
|
||||
|
||||
public string ImportExceldata(List<ProWorklplan_v2> 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; //插入可插入部分
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 下载
|
||||
/// </summary>
|
||||
/// <param name="year"></param>
|
||||
/// <param name="week"></param>
|
||||
/// <returns></returns>
|
||||
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<ProWorkorder> GetWorkorderListByPlanId(string id)
|
||||
{
|
||||
return Context.Queryable<ProWorkorder>().Where(it => it.FkProPlanId == id).OrderBy("priority desc ").ToList();
|
||||
@@ -93,5 +211,42 @@ namespace ZR.Service.mes.pro
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 周计划汇总
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public WorkplanSummaryDto GetWeekSummary(int year, int week)
|
||||
{
|
||||
return Context.Queryable<ProWorklplan_v2>().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();
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除周计划全部
|
||||
/// </summary>
|
||||
/// <param name="week"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public int DeleteAllWorkPlan(int year,int week)
|
||||
{
|
||||
return Context.Deleteable<ProWorklplan_v2>().Where(it => it.Year == year && it.Week == week).ExecuteCommand();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user