|
@@ -4,15 +4,20 @@ using Microsoft.Extensions.Logging;
|
|
|
using MiniExcelLibs;
|
|
|
using Model.Dto;
|
|
|
using Model.Entities;
|
|
|
+using PLCTool.Pdf;
|
|
|
using Prism.Commands;
|
|
|
using Prism.Mvvm;
|
|
|
using Prism.Services.Dialogs;
|
|
|
+using QuestPDF.Infrastructure;
|
|
|
+using QuestPDF;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Collections.ObjectModel;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
+using Newtonsoft.Json;
|
|
|
+using QuestPDF.Fluent;
|
|
|
|
|
|
namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
|
{
|
|
@@ -26,12 +31,13 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
|
private readonly IBasicPlcTestSchemeService _basicPlcTestSchemeService;
|
|
|
private readonly IBizTestRecordDtlService _iBizTestRecordDtlService;
|
|
|
private readonly IBizTestRecordService _iBizTestRecordService;
|
|
|
+ private readonly IBasicPlcTestSchemeDtlService _iBasicPlcTestSchemeDtlService;
|
|
|
private readonly IMapper _mapper;
|
|
|
private readonly IDialogService _dialog;
|
|
|
private readonly ILogger _logger;
|
|
|
private List<DeviceDtlWithResultModel> allDeviceList = new List<DeviceDtlWithResultModel>();//所有方案
|
|
|
private List<DeviceDtlWithResultModel> conditionDevices = new List<DeviceDtlWithResultModel>();//符合条件的方案
|
|
|
- public ResultQueryViewModel(IBasicDeviceService iBasicDeviceService, IBasicDeviceKindService iBasicDeviceKindService, IBasicProjectService iBasicProjectService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBizTestRecordDtlService iBizTestRecordDtlService, IBizTestRecordService iBizTestRecordService, IMapper mapper, IDialogService dialog, ILogger logger)
|
|
|
+ public ResultQueryViewModel(IBasicDeviceService iBasicDeviceService, IBasicDeviceKindService iBasicDeviceKindService, IBasicProjectService iBasicProjectService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBizTestRecordDtlService iBizTestRecordDtlService, IBizTestRecordService iBizTestRecordService, IBasicPlcTestSchemeDtlService iBasicPlcTestSchemeDtlService, IMapper mapper, IDialogService dialog, ILogger logger)
|
|
|
{
|
|
|
_iBasicDeviceService = iBasicDeviceService;
|
|
|
_iBasicDeviceKindService = iBasicDeviceKindService;
|
|
@@ -39,6 +45,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
|
_basicPlcTestSchemeService = basicPlcTestSchemeService;
|
|
|
_iBizTestRecordService= iBizTestRecordService;
|
|
|
_iBizTestRecordDtlService= iBizTestRecordDtlService;
|
|
|
+ _iBasicPlcTestSchemeDtlService = iBasicPlcTestSchemeDtlService;
|
|
|
_mapper = mapper;
|
|
|
_dialog = dialog;
|
|
|
_logger = logger;
|
|
@@ -48,17 +55,11 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
|
CheckDetailCommand = new DelegateCommand<object>(CheckDetail);
|
|
|
ResetCommand = new DelegateCommand<object>(Reset);
|
|
|
OnLoadCommand = new DelegateCommand(OnLoad);
|
|
|
-
|
|
|
+ PdfReportCommand = new DelegateCommand<object>(CreatePdf);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
#region 私有方法
|
|
|
/// <summary>
|
|
|
/// 加载页面
|
|
@@ -223,7 +224,6 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
|
TotalCount = conditionDevices.Count;
|
|
|
CurrentPageChanged();
|
|
|
|
|
|
-
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 页面变化
|
|
@@ -238,7 +238,211 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
|
DeviceResultItemList.Add(i);
|
|
|
}
|
|
|
}
|
|
|
+ /// <summary>
|
|
|
+ /// 生成pdf
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="obj"></param>
|
|
|
+ public void CreatePdf(object obj)
|
|
|
+ {
|
|
|
+ object[] multiObj = obj as object[];
|
|
|
+
|
|
|
+ //测试方案名称和设备id
|
|
|
+ string schemeName = (string)multiObj[0];
|
|
|
+ long deviceId = (long)multiObj[1];
|
|
|
+ //查找recordid
|
|
|
+ long recordId=(long)_iBizTestRecordService.FindRecorddByDeviceIdAndSchname((int)deviceId, schemeName)?.record_id;
|
|
|
+ //查找详细记录
|
|
|
+ var recordDtls = _iBizTestRecordDtlService.FindRecordDetailByRecordID(recordId);
|
|
|
+ string deviceName = _iBasicDeviceService.Find((int)deviceId).device_name;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ Settings.License = LicenseType.Community;
|
|
|
+ var model = GetReportPLCInfo(schemeName,deviceName, recordDtls);
|
|
|
+ var document = new InvoiceDocument(model);
|
|
|
+ //pdf名称为轴编号+时间
|
|
|
+
|
|
|
+ //输出文件
|
|
|
+ using (System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog()
|
|
|
+ {
|
|
|
+ //设置文件类型
|
|
|
+ //书写规则例如:txt files(*.txt)|*.txt
|
|
|
+ Filter = "pdf文件|*.pdf",
|
|
|
+ //设置默认文件名(可以不设置)
|
|
|
+ FileName = "报表" + string.Format("{0:yyyyMMddHHmm}", DateTime.Now),
|
|
|
+
|
|
|
+ //获取或设置一个值,该值指示如果用户省略扩展名,文件对话框是否自动在文件名中添加扩展名。(可以不设置)
|
|
|
+ AddExtension = true,
|
|
|
+
|
|
|
+ //保存对话框是否记忆上次打开的目录
|
|
|
+ RestoreDirectory = true
|
|
|
+ })
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ //点了保存按钮进入
|
|
|
+ if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
|
+ {
|
|
|
+ //获得文件路径
|
|
|
+ string localFilePath = saveFileDialog.FileName.ToString();
|
|
|
+ document.GeneratePdf(localFilePath);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ _logger.LogError(ex.ToString());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// pdf报告相关信息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="schDtlId"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private InvoiceModel GetReportPLCInfo(string schName,string deviceName,List<biz_test_record_dtl> recordDtls)
|
|
|
+ {
|
|
|
+ //测试方案明细主键ID
|
|
|
+
|
|
|
+ InvoiceModel invoiceModel = new InvoiceModel();
|
|
|
+
|
|
|
+ invoiceModel.ReportPLCModels = new List<ReportPLCModel>();
|
|
|
+ invoiceModel.SchemeName = schName;
|
|
|
+ invoiceModel.DeviceName = deviceName;
|
|
|
+
|
|
|
+ foreach (var each in recordDtls)
|
|
|
+ {
|
|
|
+ long recordId = each.record_id.Value;
|
|
|
+ long schDtlid = each.scheme_dtl_id;
|
|
|
+
|
|
|
+ string schItemName = _iBasicPlcTestSchemeDtlService.Find((int)schDtlid)?.item_name;
|
|
|
+ string schItemType = string.Empty;
|
|
|
+ int typeNo=(int) _iBasicPlcTestSchemeDtlService.Find((int)schDtlid)?.item_type;
|
|
|
+ switch (typeNo)
|
|
|
+ {
|
|
|
+ case 0:
|
|
|
+ schItemType = "前置项";
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ schItemType = "PLC点位测试项";
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ schItemType = "Robot动作测试";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ //根据测试结果明细
|
|
|
+ if (each != null)
|
|
|
+ { //前置项结果解析
|
|
|
+ string preconStr = each.precondition_final?.ToString();
|
|
|
+ if (!string.IsNullOrEmpty(preconStr))
|
|
|
+ {
|
|
|
+ JsonModel preconditionModel = JsonConvert.DeserializeObject<JsonModel>(preconStr);
|
|
|
+
|
|
|
+ foreach (var detail in preconditionModel.DetailInfo)
|
|
|
+ {
|
|
|
+
|
|
|
+ invoiceModel.ReportPLCModels.Add(new ReportPLCModel()
|
|
|
+ {
|
|
|
+ ItemName =schItemName,
|
|
|
+ ItemType = schItemType,
|
|
|
+ Type = "前置项",
|
|
|
+ JudgeType = preconditionModel.ItemType,
|
|
|
+ SelectLogic = preconditionModel.ItemLogical,
|
|
|
+ Detail = preconditionModel.Description,
|
|
|
+ Id = detail.Id,
|
|
|
+ PlcAddress = detail.PlcAddress,
|
|
|
+ PlcItem = detail.PlcItem,
|
|
|
+ PlcValue = detail.PlcValue,
|
|
|
+ Remark = detail.Remark,
|
|
|
+ TestTime = detail.TestTime,
|
|
|
+ RealValue = detail.RealValue,
|
|
|
+ TestResult = detail.TestResult,
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //输入项解析
|
|
|
+ string inStr = each.action_final?.ToString();
|
|
|
+ if (!string.IsNullOrEmpty(inStr))
|
|
|
+ {
|
|
|
+ JsonModel inModel = JsonConvert.DeserializeObject<JsonModel>(inStr);
|
|
|
+
|
|
|
+ foreach (var detail in inModel.DetailInfo)
|
|
|
+ {
|
|
|
+ invoiceModel.ReportPLCModels.Add(new ReportPLCModel()
|
|
|
+ {
|
|
|
+ ItemName = schItemName,
|
|
|
+ ItemType = schItemType,
|
|
|
+ Type = "输入项",
|
|
|
+ JudgeType = inModel.ItemType,
|
|
|
+ SelectLogic = inModel.ItemLogical,
|
|
|
+ Detail = inModel.Description,
|
|
|
+ Id = detail.Id,
|
|
|
+ PlcAddress = detail.PlcAddress,
|
|
|
+ PlcItem = detail.PlcItem,
|
|
|
+ PlcValue = detail.PlcValue,
|
|
|
+ Remark = detail.Remark,
|
|
|
+ TestTime = detail.TestTime,
|
|
|
+ RealValue = detail.RealValue,
|
|
|
+ TestResult = detail.TestResult,
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ //输出项解析
|
|
|
+ string outStr = each.judgement_result_final?.ToString();
|
|
|
+ if (!string.IsNullOrEmpty(outStr))
|
|
|
+ {
|
|
|
+ JsonModel outModel = JsonConvert.DeserializeObject<JsonModel>(outStr);
|
|
|
+
|
|
|
+ foreach (var detail in outModel.DetailInfo)
|
|
|
+ {
|
|
|
+ invoiceModel.ReportPLCModels.Add(new ReportPLCModel()
|
|
|
+ {
|
|
|
+ ItemName = schItemName,
|
|
|
+ ItemType = schItemType,
|
|
|
+ Type = "结果项",
|
|
|
+ JudgeType = outModel.ItemType,
|
|
|
+ SelectLogic = outModel.ItemLogical,
|
|
|
+ Detail = outModel.Description,
|
|
|
+ Id = detail.Id,
|
|
|
+ PlcAddress = detail.PlcAddress,
|
|
|
+ PlcItem = detail.PlcItem,
|
|
|
+ PlcValue = detail.PlcValue,
|
|
|
+ Remark = detail.Remark,
|
|
|
+ TestTime = detail.TestTime,
|
|
|
+ RealValue = detail.RealValue,
|
|
|
+ TestResult = detail.TestResult,
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断方案结果是否通过
|
|
|
+ //var testCount = allDeviceList.FindAll(X => X.SchemeName == findSch.scheme_name && X.TestResult == "通过")?.Count;
|
|
|
+ //if (testCount == allResult.Count)
|
|
|
+ //{
|
|
|
+ // invoiceModel.FinalReuslt = "通过";
|
|
|
+ //}
|
|
|
+ //else
|
|
|
+ //{
|
|
|
+ // invoiceModel.FinalReuslt = "不通过";
|
|
|
+ //}
|
|
|
+
|
|
|
+
|
|
|
+ return invoiceModel;
|
|
|
+ }
|
|
|
#endregion
|
|
|
#region 命令绑定
|
|
|
|
|
@@ -251,7 +455,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
|
|
|
|
public DelegateCommand OnLoadCommand { set; get; }
|
|
|
public DelegateCommand<object> CheckDetailCommand { set; get; }
|
|
|
-
|
|
|
+ public DelegateCommand<object> PdfReportCommand { set; get; }
|
|
|
#endregion
|
|
|
|
|
|
#region 数据绑定
|