UpstreamSendCalendar.cs 10.4 KB
using System;
using System.Collections.Generic;
using System.Linq;
using AutoMapper;
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
            {
                var importbachnumber = DateTime.Now.ToString("yyyyMMddhhmmss");

                //重复数据去除
                var dBList = Context.Queryable<base_productionOrder_EP3D>().ToList();
                if (dBList.Count > 0) 
                {
                    list.details = list.details.Where(x=> !dBList.Exists(y=>y.pipelineNo==x.pipelineNo && y.pipeSectionNo==x.pipeSectionNo)).ToList();
                }

                foreach (var model in list.details)
                {
                    model.keys = Guid.NewGuid();
                    model.state = 0;
                    model.createTime = DateTime.Now;
                    model.updateTime = DateTime.Now;
                    model.batchNo = importbachnumber;
                }

                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}");
            }
        }



        public dynamic SendWorkSeverYZJ(base_work_order work_order)
        {
            var response = new POJO.Response.Response();
            string errMsg = "";
            if (string.IsNullOrEmpty(work_order.workOrderCode ))
            {
                errMsg += "生产订单号不能为空;";
            }
            if (string.IsNullOrEmpty(work_order.lineCode))
            {
                errMsg += "生产线不能为空;";
            }
            if (string.IsNullOrEmpty(work_order.workPieceNo))
            {
                errMsg += "工件编码不能为空;";
            }
            if (work_order.bends == null)
            {
                errMsg += "弯管信息不能为空;";
            }
            if (work_order.Cuts == null )
            {
                errMsg += "火焰切割信息不能为空;";
            }
            //if (work_order.flameCut == null)
            //{
            //    errMsg += "火焰切割信息不能为空;";
            //}
            if (work_order.mounting == null)
            {
                errMsg += "装配信息不能为空;";
            }

            if (errMsg.Length>0)
            {
                return response.ResponseError(errMsg);
            }

            Context.Ado.BeginTran();
            try
            {
                Guid keys = Guid.NewGuid();
                base_work_order_head order_head = GetWorkOrderModel(work_order);
                order_head.keys = keys;
                int inI = Context.Insertable(order_head).ExecuteCommand();

                //弯管信息
                List<base_work_order_bends> bends = work_order.bends;
                foreach (var item in bends)
                {
                    item.headKeys = keys;
                    item.createBy = "sys";
                    item.createTime = DateTime.Now;
                }
                Context.Insertable(bends).ExecuteCommand();

                //火焰切割
                List<Work_Order_FlameCut> flameCuts = work_order.Cuts;
                List<base_work_order_flameCut_d> flameCut_d = new List<base_work_order_flameCut_d>();
                foreach (var item in flameCuts)
                {
                    Guid guid = Guid.NewGuid(); 
                    item.headKeys = keys;
                    item.createBy = "sys";
                    item.createTime = DateTime.Now;
                    item.headKeys = keys;
                    item.Keys = guid;
                    if (item.Cut_D.Count > 0)
                    {
                        foreach (var FlameCut_D_Item in item.Cut_D)
                        {
                            base_work_order_flameCut_d flameCut_d1 = FlameCut_D_Item;
                            flameCut_d1.headKeys = guid; 
                            flameCut_d1.createBy = "sys";
                            flameCut_d1.createTime = DateTime.Now;
                            flameCut_d.Add(flameCut_d1);
                        }
                    }
                }
                Mapper.Initialize(x => x.CreateMap<Work_Order_FlameCut, base_work_order_flameCut>());
                List<base_work_order_flameCut> flameCuts2 = new List<base_work_order_flameCut>();
                foreach (Work_Order_FlameCut item in flameCuts)
                {
                    base_work_order_flameCut f = Mapper.Map<base_work_order_flameCut>(item);
                    flameCuts2.Add(f);
                }
                      
                Context.Insertable(flameCuts2).ExecuteCommand();
                Context.Insertable(flameCut_d).ExecuteCommand();

                //装配信息
                List<base_work_order_mounting> mounting = work_order.mounting;
                foreach (var item in mounting)
                {
                    item.headKeys = keys;
                    item.createBy = "sys";
                    item.createTime = DateTime.Now;
                }
                Context.Insertable(mounting).ExecuteCommand();
                Context.Ado.CommitTran();
                return response.ResponseSuccess();
            }
            catch (Exception ex)
            {
                Context.Ado.RollbackTran();
                return response.ResponseError($"{ex.Message}");
            } 
         
        }

        public base_work_order_head GetWorkOrderModel(base_work_order work_order)
        {
            base_work_order_head head = new base_work_order_head();
            head.assemblageInfo = work_order.assemblageInfo;
            head.attachment1 = work_order.attachment1;
            head.attachment2 = work_order.attachment2;
            head.bevels1 = work_order.bevels1;
            head.bevels2 = work_order.bevels2;
            head.cutLength = work_order.cutLength;
            head.diameter = work_order.diameter;
            head.extend1 = work_order.extend1;
            head.extend2 = work_order.extend2;
            head.extend3 = work_order.extend3;
            head.extend4 = work_order.extend4;
            head.flowOrientation1 = work_order.flowOrientation1;
            head.flowOrientation2 = work_order.flowOrientation2;
            head.instructions1 = work_order.instructions1;
            head.instructions2 = work_order.instructions2;
            head.level = work_order.level;
            head.lineCode =work_order.lineCode;
            head.materielCode = work_order.materielCode;
            head.paintCode = work_order.paintCode;
            head.pipePartsCode = work_order.pipePartsCode;
            head.pipePartsNo = work_order.pipePartsNo;
            head.projectNo = work_order.projectNo;
            head.range = work_order.range;
            head.startWorkDate = work_order.startWorkDate;
            head.thickness = work_order.thickness;
            head.turningAngle = work_order.turningAngle;
            head.workOrderCode = work_order.workOrderCode;
            head.workPieceNo = work_order.workPieceNo; 
            if (!string.IsNullOrEmpty(sysUserApi?.Account))
            {
                head.createBy = sysUserApi?.Account;
                head.updateby = sysUserApi?.Account;
            }
            else
            {
                head.createBy = "system";
                head.updateby = "system";
            } 
            head.createTime = DateTime.Now;
            return head;
        } 
    }
}