266 lines
10 KiB
C#
266 lines
10 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Hosting;
|
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
|
|
using Quartz.Impl.AdoJobStore.Common;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using VolPro.Core.DBManager;
|
|
using VolPro.Core.DbSqlSugar;
|
|
using VolPro.Core.EFDbContext;
|
|
using VolPro.Core.Extensions;
|
|
using VolPro.Entity.DomainModels;
|
|
|
|
namespace VolPro.Core.Print
|
|
{
|
|
public class PrintCustom : PrintFilter
|
|
{
|
|
public PrintCustom() { }
|
|
/// <summary>
|
|
/// 主表查询
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="query"></param>
|
|
/// <param name="parms"></param>
|
|
/// <returns></returns>
|
|
public override ISugarQueryable<T> Query<T>(ISugarQueryable<T> query, PrintQuery parms) where T : class
|
|
{
|
|
//判断是哪张主表自定义过滤条件
|
|
if (typeof(T).Name == typeof(Demo_Order).Name)
|
|
{
|
|
var orderQuery = ((ISugarQueryable<Demo_Order>)query);
|
|
return orderQuery
|
|
//这里where可以写自定义条件
|
|
.Where(x => true) as ISugarQueryable<T>;
|
|
|
|
}
|
|
return query;
|
|
}
|
|
/// <summary>
|
|
/// 明细表查询
|
|
/// </summary>
|
|
/// <typeparam name="Detail"></typeparam>
|
|
/// <param name="query"></param>
|
|
/// <param name="parms"></param>
|
|
/// <returns></returns>
|
|
|
|
public override ISugarQueryable<Detail> QueryDetail<Detail>(ISugarQueryable<Detail> query, PrintQuery parms) where Detail : class
|
|
{
|
|
//判断是哪张明细表自定义过滤条件
|
|
if (typeof(Detail).Name == typeof(Demo_OrderList).Name)
|
|
{
|
|
var orderQuery = ((ISugarQueryable<Demo_OrderList>)query);
|
|
return orderQuery
|
|
//这里where可以写自定义条件
|
|
.Where(x => true) as ISugarQueryable<Detail>;
|
|
|
|
}
|
|
return query;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 对返回的结果自定义处理
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <typeparam name="Detail"></typeparam>
|
|
/// <param name="result"></param>
|
|
/// <param name="parms"></param>
|
|
/// <returns></returns>
|
|
public override List<Dictionary<string, object>> QueryResult<T>(
|
|
List<Dictionary<string, object>> result,
|
|
PrintQuery parms,
|
|
BaseDbContext dbContext)
|
|
{
|
|
if (result.Count == 0) return result;
|
|
|
|
//判断表,自定义返回数据
|
|
if (typeof(T).Name == typeof(Demo_Order).Name)
|
|
{
|
|
//判断是哪个打印模板,然后自定义返回数据
|
|
if (parms.TemplateName == "订单管理主从明细表打印")
|
|
{
|
|
//返回DemoOrder表自定义配置
|
|
SetDemoOrderValue(result, parms, dbContext);
|
|
}
|
|
}
|
|
//告警统计数据
|
|
if (typeof(T).Name == typeof(Warehouse_Alert).Name)
|
|
{
|
|
//日报打印模板处理
|
|
if (parms.TemplateName == "统计日报")
|
|
{
|
|
//返回Alert表自定义配置
|
|
SetAlertValue(result, parms, dbContext);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 返回Alert表自定义配置
|
|
/// </summary>
|
|
/// <param name="result"></param>
|
|
/// <param name="parms"></param>
|
|
/// <param name="dbContext"></param>
|
|
private void SetAlertValue(
|
|
List<Dictionary<string, object>> result,
|
|
PrintQuery parms,
|
|
BaseDbContext dbContext)
|
|
{
|
|
//给明细表设置合计
|
|
//var data = dbContext.Set<Warehouse_Alert>()
|
|
|
|
//设置自定义返回的字段(模板设计页面需要定义:单价合计、数量合计两个字段)
|
|
//result[0]["单价合计"] = data?.单价合计 ?? 0;
|
|
//result[0]["数量合计"] = data?.数量合计 ?? 0;
|
|
|
|
//result[0]这里还可以自定义其他字段设置值与模板设计页面定义的字段一致即可
|
|
var dic = new Dictionary<string, object>();
|
|
dic.Add("单位名称", "1#仓库");
|
|
dic.Add("上报日期", DateTime.Now.ToString("D"));
|
|
dic.Add("截止时间", DateTime.Now.ToString("T"));
|
|
|
|
//parms.Ids是勾选的主表主键id
|
|
var options = parms.Options.DeserializeObject<Dictionary<string, string[]>>();
|
|
List<Guid?> ids = parms.Ids.Select(s => s.GetGuid()).ToList();
|
|
if (options["month"] == null)
|
|
{
|
|
//自定义查询返回表格数据
|
|
var data = dbContext.Set<Warehouse_Alert>().Where(x => ids.Contains(x.AlertId))
|
|
.Select(s => new
|
|
{
|
|
时间 = s.CreateDate,
|
|
告警区域 = s.Area,
|
|
事件描述 = s.Message,
|
|
处理结果 = s.Result,
|
|
负责人 = s.ChargePerson,
|
|
结果确认 = s.CheckResult,
|
|
确认人 = s.CheckPerson,
|
|
确认时间 = s.CheckTime
|
|
}).ToList();
|
|
dic.Add("告警记录", data);
|
|
}
|
|
else
|
|
{
|
|
//按月份查询返回表格数据
|
|
var dateStart = DateTime.Parse(options["month"][0], null, DateTimeStyles.RoundtripKind).ToLocalTime();
|
|
var dateEnd = DateTime.Parse(options["month"][1], null, DateTimeStyles.RoundtripKind).ToLocalTime();
|
|
var data = dbContext.Set<Warehouse_Alert>()
|
|
.Where(x => x.CreateDate>=dateStart && x.CreateDate<=dateEnd)
|
|
.Select(s => new
|
|
{
|
|
时间 = s.CreateDate,
|
|
告警区域 = s.Area,
|
|
事件描述 = s.Message,
|
|
处理结果 = s.Result,
|
|
负责人 = s.ChargePerson,
|
|
结果确认 = s.CheckResult,
|
|
确认人 = s.CheckPerson,
|
|
确认时间 = s.CheckTime
|
|
}).ToList();
|
|
dic.Add("告警记录", data);
|
|
}
|
|
|
|
//返回库房管理系统的数据
|
|
var warehouseManageTable = dbContext.Set<Warehouse_SubSystemReport>()
|
|
.Where(x => x.Type == "库房管理系统")//这里写条件
|
|
.Select(s => new
|
|
{
|
|
状态 = s.Status,//[名称]与[编号]是打印板自定义表格的里面输入的字段名
|
|
项目 = s.Title,
|
|
当日情况 = s.Situation,
|
|
正常值 = s.ReferenceValue,
|
|
结论 = s.Result
|
|
}).ToList();
|
|
var dicTable1 = new Dictionary<string, object>();
|
|
dic.Add("库房管理系统", warehouseManageTable);
|
|
//返回钥匙管控系统的数据
|
|
var keyManageTable = dbContext.Set<Warehouse_SubSystemReport>()
|
|
.Where(x => x.Type == "钥匙管控系统")//这里写条件
|
|
.Select(s => new
|
|
{
|
|
状态 = s.Status,//[名称]与[编号]是打印板自定义表格的里面输入的字段名
|
|
项目 = s.Title,
|
|
当日情况 = s.Situation,
|
|
正常值 = s.ReferenceValue,
|
|
结论 = s.Result
|
|
}).ToList();
|
|
var dicTable2 = new Dictionary<string, object>();
|
|
dic.Add("钥匙管控系统", keyManageTable);
|
|
//返回门禁系统的数据
|
|
var doorManageTable = dbContext.Set<Warehouse_SubSystemReport>()
|
|
.Where(x => x.Type == "门禁系统")//这里写条件
|
|
.Select(s => new
|
|
{
|
|
状态 = s.Status,//[名称]与[编号]是打印板自定义表格的里面输入的字段名
|
|
项目 = s.Title,
|
|
当日情况 = s.Situation,
|
|
正常值 = s.ReferenceValue,
|
|
结论 = s.Result
|
|
}).ToList();
|
|
var dicTable3 = new Dictionary<string, object>();
|
|
dic.Add("门禁系统", doorManageTable);
|
|
//返回视频监控系统的数据
|
|
var cameraManageTable = dbContext.Set<Warehouse_SubSystemReport>()
|
|
.Where(x => x.Type == "视频监控系统")//这里写条件
|
|
.Select(s => new
|
|
{
|
|
状态 = s.Status,//[名称]与[编号]是打印板自定义表格的里面输入的字段名
|
|
项目 = s.Title,
|
|
当日情况 = s.Situation,
|
|
正常值 = s.ReferenceValue,
|
|
结论 = s.Result
|
|
}).ToList();
|
|
var dicTable4 = new Dictionary<string, object>();
|
|
dic.Add("视频监控系统", cameraManageTable);
|
|
|
|
result.Clear();
|
|
result.Add(dic);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 返回DemoOrder表自定义配置
|
|
/// </summary>
|
|
/// <param name="result"></param>
|
|
/// <param name="parms"></param>
|
|
/// <param name="dbContext"></param>
|
|
private void SetDemoOrderValue(
|
|
List<Dictionary<string, object>> result,
|
|
PrintQuery parms,
|
|
BaseDbContext dbContext)
|
|
{
|
|
//给明细表设置合计
|
|
var data = dbContext.Set<Demo_OrderList>()
|
|
//根据主表id查询返回明细表合计
|
|
.Where(x => x.Order_Id == parms.Ids[0].GetGuid())
|
|
.Select(s => new
|
|
{
|
|
单价合计 = SqlFunc.AggregateSum(s.Price),
|
|
数量合计 = SqlFunc.AggregateSum(s.Qty),
|
|
}).FirstOrDefault();
|
|
|
|
//设置自定义返回的字段(模板设计页面需要定义:单价合计、数量合计两个字段)
|
|
result[0]["单价合计"] = data?.单价合计 ?? 0;
|
|
result[0]["数量合计"] = data?.数量合计 ?? 0;
|
|
|
|
//result[0]这里还可以自定义其他字段设置值与模板设计页面定义的字段一致即可
|
|
|
|
////例如:再返回一些自定义的表格数据
|
|
//var otherTable = dbContext.Set<Demo_Product>()
|
|
// .Where(x => true)//这里写条件
|
|
// .Select(s => new
|
|
// {
|
|
// 名称 = s.ProductName,//[名称]与[编号]是打印板自定义表格的里面输入的字段名
|
|
// 编号 = s.ProductCode
|
|
// }).ToList();
|
|
|
|
//result[0]["字段名"] = otherTable;
|
|
}
|
|
}
|
|
}
|