UpstreamSendCalendar.cs 3.7 KB
using System;
using System.Collections.Generic;
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.Response;
using NPOI.POIFS.FileSystem;
using Ubiety.Dns.Core;

namespace Hh.Mes.Service.ApiService
{
    public partial class UpstreamService
    {
        public dynamic SendCalendar(CalendarEntity entity)
        {
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                var response = new ResponseUpstream<string>(entity.plmeid);
                var calendar = new base_calendar
                {
                    keys = Guid.NewGuid(),
                    plmeId = entity.plmeid,
                    workShopCode = entity.work_code,
                    currentDate = entity.current_date,
                    shift = entity.shift,
                    startTime = entity.start_time,
                    endTime = entity.end_time,
                    timeFlag = entity.time,

                    isDelete = AddOrUpdateFlag
                };
                int resultCount = 0;
                if (entity.type == EnumAction.I.ToString())
                {
                    if (Context.Queryable<base_calendar>().Any(t => t.plmeId == calendar.plmeId && t.isDelete == AddOrUpdateFlag))
                    {
                        return response.ResponseError($"【MOM】【plmeid】日历信息[{entity.plmeid}]已经存在,请勿重复添加!");
                    }
                    calendar.createTime = DateTime.Now;
                    resultCount = Context.Insertable(calendar).ExecuteCommand();
                }
                else if (entity.type == EnumAction.U.ToString())
                {
                    calendar.updateTime = DateTime.Now;
                    resultCount = Context.Updateable(calendar).IgnoreColumns(it => new { it.keys, it.createBy, it.createTime })
                    .Where(x => x.plmeId == entity.plmeid && x.isDelete == AddOrUpdateFlag)
                    .ExecuteCommand();
                }
                else if (entity.type == EnumAction.D.ToString())
                {
                    calendar.updateTime = DateTime.Now;
                    resultCount = Context.Updateable<base_calendar>()
                                              .SetColumns(t => t.isDelete == DeleteFlag)
                                              .Where(x => x.plmeId.Equals(entity.plmeid) && x.isDelete == AddOrUpdateFlag)
                                              .ExecuteCommand();
                }
                return resultCount > 0 ? response.ResponseSuccess() : response.ResponseError();
            });
        }

        /// <summary>
        /// ep3d订单推送接收
        /// </summary>
        /// <returns></returns>
        public dynamic ep3dDataPush(productionOrderList list)
        {
            var response = new POJO.Response.Response();
            try
            {
                foreach (var model in list.details)
                {
                    model.keys = Guid.NewGuid();
                    model.state = 0;
                    model.createTime = DateTime.Now;
                    model.updateTime = DateTime.Now;

                }

                int inI = Context.Insertable(list.details).ExecuteCommand();
                if (inI > 0)
                {
                    return response;
                }
                else
                {
                    return response.ResponseError($"数据接收失败,新增数据数量为0!");
                }

            }
            catch (Exception ex)
            {
                return response.ResponseError($"{ex.Message}");
            }
        }

    }
}