ImportMethod_Equipment.cs 3.79 KB
using Hh.Mes.Common;
using Hh.Mes.Common.config;
using Hh.Mes.Common.DataTableTo;
using Hh.Mes.Common.log;
using Hh.Mes.Pojo.System;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.EnumEntitys;
using Hh.Mes.POJO.Response;
using Hh.Mes.POJO.WebEntity;
using Hh.Mes.POJO.WebEntity.bus;
using Hh.Mes.Service.Repository;
using MySqlX.XDevAPI.Common;
using MySqlX.XDevAPI.Relational;
using NPOI.OpenXmlFormats.Dml.Diagram;
using NPOI.POIFS.FileSystem;
using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using static Hh.Mes.Common.Exel.NpoiExcelImportHelper;

namespace Hh.Mes.Service.WebService.Planned
{
    /// <summary>
    /// 定义导入方法加上特性
    /// dicDtSource 添加需要保存到数据源的数据源 
    /// 注意:只改对应业务的dt 数据【公共方法里面的读取的数据源不要修改、其他地方可能需要用到】
    /// </summary>
    public partial class ImportMethod 
    {
        #region 设备管理 Action里面的 equipment  是数据库表名 ,方法名没有特殊要求 ,注意不要删除sysDicDtSource里面的key
        [Action("equipment")]
        public Response EquipmentMethod(Dictionary<string, SysDtAllCls> sysDicDtSource, dynamic user, DateTime nowTime)
        {
            #region init
            var response = new Response();
            //【修改项1】
            var excelFileNameKeys = ExcelName.equipment.ToString();
            response = ImportOhter.ImportMethodBefore(sysDicDtSource, response, excelFileNameKeys);
            if (response.Code != 200)
            {
                response.Message = $"【{TableName.excelFileNameEquipment}】" + response.Message;
                return response;
            }
            //公共方法数据源,需要判断的数据源单独建一个
            DataTable excelDtSourceDt = response.Result.data;

            DataTable titleVerifySourceDt = response.Result.title;
            #endregion

            #region 创建dt、添加保存到数据库的dicDtSource 【修改项2
            var tableName = TableName.tableNameEquipment;
            var eqSaveDt = GetTableStructure(tableName);
            var temp = new SysDtAllCls()
            {
                dtData = eqSaveDt
            };
            var dtSourceNameKey = tableName + TableName.tableSuffix;
            sysDicDtSource.Add(dtSourceNameKey, temp);
            #endregion

            #region 去重 【修改项3 根据实际业务】
            var tempExcelDtSourceDt = excelDtSourceDt.Distinct("Code");
            #endregion

            #region 赋值  理论上是通用的,修改excel文件名 【修改项4
            var columns = tempExcelDtSourceDt.Columns;
            for (int i = 0; i < tempExcelDtSourceDt.Rows.Count; i++)
            {
                var dr = eqSaveDt.NewRow();
                for (int c = 0; c < columns.Count; c++)
                {
                    var colName = columns[c].ColumnName;
                    dynamic colNameVal = tempExcelDtSourceDt.Rows[i][colName].ToString();
                    response = ImportOhter.SetDataTableDataBefore(response, i, colName, colNameVal, titleVerifySourceDt, TableName.excelFileNameEquipment);
                    if (response.Code != 200) return response;

                    colNameVal = ImportOhter.SetDataTableData(colNameVal, eqSaveDt.Columns[colName].DataType.Name);
                    dr[colName] = colNameVal;
                }

                dr["CreatedBy"] = user.Account;
                dr["Created"] = nowTime;
                eqSaveDt.Rows.Add(dr);
            }
            #endregion

            #region 逻辑判断


            #endregion

            return response;
        }
        #endregion

    }
}