UpstreamSendEquipmentAlarm.cs 4.21 KB
using Hh.Mes.Common;
using Hh.Mes.Common.config;
using Hh.Mes.Common.Json;
using Hh.Mes.Common.log;
using Hh.Mes.Pojo.System;
using Hh.Mes.POJO.ApiEntity;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.EnumEntitys;
using Hh.Mes.POJO.Request;
using Hh.Mes.POJO.Response;
using System;
using System.Collections.Generic;

namespace Hh.Mes.Service.ApiService
{
    public partial class UpstreamService
    {
        public dynamic SendEquipment(List<EquipmentAlarmEntity> list)
        {
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                //var reqData = DynamicJson.Parse(requestData); reqData.data
                EquipmentAlarmEntity entity = new EquipmentAlarmEntity();
                var response = new ResponseUpstream<string>("");
                int resultCount = 0;
                foreach (EquipmentAlarmEntity e in list)
                {
                    entity = e;
                    response = new ResponseUpstream<string>(entity.plmeid);
                    if (!typeValidation(entity.type, response).Status) return response;
                    //var equipment = new Equipment()
                    //{
                    //    //factoryCode = entity.factory_code,
                    //    //equipmentCode = entity.equipment_code,
                    //    //equipmentName = entity.equipment_name,
                    //    //equipmentTypeCode = entity.equipmentType_code,
                    //    //equipmentTypeName = entity.equipmentType_Name,
                    //    //ip = entity.ip,
                    //    //destinationArea = entity.destination_area,
                    //    //remark = entity.remark,
                    //    //isDelete = entity.isDelete,
                    //};
                    //bool isExist = Context.Queryable<base_equipment>().Any(t => t.factoryCode == equipment.factoryCode && t.equipmentCode == equipment.equipmentCode);
                    //if (entity.type == EnumAction.I.ToString())
                    //{
                    //    if (isExist)
                    //    {
                    //        return response.ResponseError($"【上位系统】【唯一标识plmeId:{entity.plmeid}】【厂房factory_Code,设备编码equipment_code】设备基础信息[{entity.factory_code},{entity.equipment_name}]已经存在,请勿重复添加!");
                    //    }
                    //    equipment.createTime = DateTime.Now;
                    //    Context.Insertable(equipment).AddQueue();
                    //}
                    //else if (entity.type == EnumAction.U.ToString())
                    //{
                    //    if (!isExist) return response.ResponseError($"【上位系统】【唯一标识plmeId:{entity.plmeid}】【厂房factory_Code,设备编码equipment_code】设备基础信息[{entity.factory_code},{entity.equipment_name}]不存在,无法修改!");
                    //    equipment.updateTime = DateTime.Now;
                    //    Context.Updateable(equipment)
                    //    .IgnoreColumns(it => new { it.createTime, it.createBy })
                    //    .Where(x => x.factoryCode == entity.factory_code && x.equipmentCode == entity.equipment_code)
                    //    .AddQueue();
                    //}
                    //else if (entity.type == EnumAction.D.ToString())
                    //{
                    //    if (!isExist) return response.ResponseError($"【上位系统】【唯一标识plmeId:{entity.plmeid}】【厂房factory_Code,设备编码equipment_code】设备基础信息[{entity.factory_code},{entity.equipment_name}]不存在,无法删除!");
                    //    equipment.isDelete = 0;
                    //    equipment.updateTime = DateTime.Now;
                    //    Context.Updateable(equipment)
                    //    .IgnoreColumns(it => new { it.createTime, it.createBy })
                    //    .Where(x => x.factoryCode == entity.factory_code && x.equipmentCode == entity.equipment_code)
                    //    .AddQueue();
                    //}
                }
                resultCount = ExecuteQueues(Context);
                return resultCount > 0 ? response.ResponseSuccess() : response.ResponseError();
            });
        }
    }
}