GenTools.cs 8.51 KB
using HHECS.Application.Enums;
using HHECS.Infrastructure.Enums;
using HHECS.Model.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HHECS.Test
{
    /// <summary>
    /// 设备生成帮助类
    /// </summary>
    public class GenTools
    {
        /// <summary>
        /// 生成站台请求到达地址,按需修改
        /// </summary>
        /// <param name="stationGenModels"></param>
        /// <param name="delete"></param>
        static void GenStation(List<StationGenModel> stationGenModels, bool delete)
        {
            //EquipmentService equipmentService = new EquipmentService();
            //if (delete)
            //{
            //    var temp = stationGenModels.Select(t => t.EquipmentTypeConst.ToString()).ToList();
            //    equipmentService.DeleteEuipmentByIds(equipmentService.GetEquipments(t => temp.Contains(t.EquipmentType.Code)).Data.Select(t => t.Id).ToList());
            //}
            //foreach (var station in stationGenModels)
            //{
            //    var w = station.MapTo<StationGenModel, Equipment>();
            //    w.Code = $"{station.EquipmentTypeConst}{station.Code}";
            //    w.Name = $"{station.EquipmentTypeConst.ToDescriptionOrString()}{station.Code}";
            //    w.EquipmentTypeId = equipmentService.GetEquipmentTypes(t => t.Code == station.EquipmentTypeConst.ToString()).Data.First().Id;
            //    w.Created = DateTime.Now;
            //    var temp = equipmentService.InsertEquipment(w).Data;

            //    equipmentService.SyncEquipmentProp(temp.Id, "", "");
            //    temp.EquipmentProps = equipmentService.GetEquipmentProps(t => t.EquipmentId == temp.Id).Data;
            //    //删除控制指令和PLC的ACK,现在还用不上
            //    equipmentService.DeleteEquipmentPropByIds(temp.EquipmentProps.Where(t => t.EquipmentTypePropTemplateCode.Contains("Control")).Select(t => t.Id).ToList());
            //    equipmentService.DeleteEquipmentPropByIds(temp.EquipmentProps.Where(t => t.EquipmentTypePropTemplateCode.StartsWith("ACK")).Select(t => t.Id).ToList());
            //    if (station.RequestDB == 0)
            //    {
            //        equipmentService.DeleteEquipmentPropByIds(temp.EquipmentProps.Where(t => t.EquipmentTypePropTemplateCode.StartsWith("Request")).Select(t => t.Id).ToList());
            //    }
            //    else
            //    {
            //        temp[StationProps.RequestMessage.ToString()].Address = $"DB{station.RequestDB}W{station.RequestStart + 0}";
            //        temp[StationProps.RequestLoadStatus.ToString()].Address = $"DB{station.RequestDB}W{station.RequestStart + 2}";
            //        temp[StationProps.RequestNumber.ToString()].Address = $"DB{station.RequestDB}W{station.RequestStart + 4}";
            //        temp[StationProps.RequestBarcode.ToString()].Address = $"DB{station.RequestDB}CHAR{station.RequestStart + 6},20";
            //        temp[StationProps.RequestWeight.ToString()].Address = $"DB{station.RequestDB}W{station.RequestStart + 26}";
            //        temp[StationProps.RequestLength.ToString()].Address = $"DB{station.RequestDB}W{station.RequestStart + 28}";
            //        temp[StationProps.RequestWidth.ToString()].Address = $"DB{station.RequestDB}W{station.RequestStart + 30}";
            //        temp[StationProps.RequestHeight.ToString()].Address = $"DB{station.RequestDB}W{station.RequestStart + 32}";
            //        temp[StationProps.RequestRetCode.ToString()].Address = $"DB{station.RequestDB}W{station.RequestStart + 34}";
            //        temp[StationProps.RequestBackup.ToString()].Address = $"DB{station.RequestDB}W{station.RequestStart + 36}";
            //        equipmentService.UpdateEquipmentProp(temp.EquipmentProps.FindAll(t => t.EquipmentTypePropTemplateCode.StartsWith("Request")));
            //    }

            //    if (station.WCSRequestDB == 0)
            //    {
            //        equipmentService.DeleteEquipmentPropByIds(temp.EquipmentProps.Where(t => t.EquipmentTypePropTemplateCode.StartsWith("WCSReply")).Select(t => t.Id).ToList());
            //    }
            //    else
            //    {
            //        temp[StationProps.WCSReplyMessage.ToString()].Address = $"DB{station.WCSRequestDB}W{station.WCSRequestStart + 0}";
            //        temp[StationProps.WCSReplyLoadStatus.ToString()].Address = $"DB{station.WCSRequestDB}W{station.WCSRequestStart + 2}";
            //        temp[StationProps.WCSReplyNumber.ToString()].Address = $"DB{station.WCSRequestDB}W{station.WCSRequestStart + 4}";
            //        temp[StationProps.WCSReplyBarcode.ToString()].Address = $"DB{station.WCSRequestDB}CHAR{station.WCSRequestStart + 6},20";
            //        temp[StationProps.WCSReplyWeight.ToString()].Address = $"DB{station.WCSRequestDB}W{station.WCSRequestStart + 26}";
            //        temp[StationProps.WCSReplyLength.ToString()].Address = $"DB{station.WCSRequestDB}W{station.WCSRequestStart + 28}";
            //        temp[StationProps.WCSReplyWidth.ToString()].Address = $"DB{station.WCSRequestDB}W{station.WCSRequestStart + 30}";
            //        temp[StationProps.WCSReplyHeight.ToString()].Address = $"DB{station.WCSRequestDB}W{station.WCSRequestStart + 32}";
            //        temp[StationProps.WCSReplyAddress.ToString()].Address = $"DB{station.WCSRequestDB}W{station.WCSRequestStart + 34}";
            //        temp[StationProps.WCSReplyBackUp.ToString()].Address = $"DB{station.WCSRequestDB}W{station.WCSRequestStart + 36}";
            //        equipmentService.UpdateEquipmentProp(temp.EquipmentProps.FindAll(t => t.EquipmentTypePropTemplateCode.StartsWith("WCSReply")));
            //    }

            //    if (station.ArrivaDB == 0)
            //    {
            //        equipmentService.DeleteEquipmentPropByIds(temp.EquipmentProps.Where(t => t.EquipmentTypePropTemplateCode.StartsWith("Arrive")).Select(t => t.Id).ToList());
            //    }
            //    else
            //    {
            //        temp[StationProps.ArriveMessage.ToString()].Address = $"DB{station.ArrivaDB}W{station.ArrivaStart + 0}";
            //        temp[StationProps.ArriveResult.ToString()].Address = $"DB{station.ArrivaDB}W{station.ArrivaStart + 2}";
            //        temp[StationProps.ArriveRealAddress.ToString()].Address = $"DB{station.ArrivaDB}W{station.ArrivaStart + 4}";
            //        temp[StationProps.ArriveAllocationAddress.ToString()].Address = $"DB{station.ArrivaDB}W{station.ArrivaStart + 6}";
            //        temp[StationProps.ArriveBarcode.ToString()].Address = $"DB{station.ArrivaDB}CHAR{station.ArrivaStart + 8},20";
            //        temp[StationProps.ArrivePaddingBit.ToString()].Address = $"DB{station.ArrivaDB}W{station.ArrivaStart + 28}";
            //        equipmentService.UpdateEquipmentProp(temp.EquipmentProps.FindAll(t => t.EquipmentTypePropTemplateCode.StartsWith("Arrive")));
            //    }

            //    if (station.WCSArrivaDB == 0)
            //    {
            //        equipmentService.DeleteEquipmentPropByIds(temp.EquipmentProps.Where(t => t.EquipmentTypePropTemplateCode.StartsWith("WCSACK")).Select(t => t.Id).ToList());
            //    }
            //    else
            //    {
            //        temp[StationProps.WCSACKMessage.ToString()].Address = $"DB{station.WCSArrivaDB}W{station.WCSArrivaStart + 0}";
            //        temp[StationProps.WCSACKLoadStatus.ToString()].Address = $"DB{station.WCSArrivaDB}W{station.WCSArrivaStart + 2}";
            //        temp[StationProps.WCSACKNumber.ToString()].Address = $"DB{station.WCSArrivaDB}W{station.WCSArrivaStart + 4}";
            //        temp[StationProps.WCSACKBackup.ToString()].Address = $"DB{station.WCSArrivaDB}W{station.WCSArrivaStart + 6}";
            //        equipmentService.UpdateEquipmentProp(temp.EquipmentProps.FindAll(t => t.EquipmentTypePropTemplateCode.StartsWith("WCSACK")));

            //    }

            //}
        }
    }

    /// <summary>
    /// 站台地址生成model
    /// </summary>
    public class StationGenModel : Equipment
    {
        public EquipmentTypeConst EquipmentTypeConst { get; set; }

        public int RequestDB { get; set; }

        public int RequestStart { get; set; }

        public int WCSRequestDB { get; set; }

        public int WCSRequestStart { get; set; }

        public int ArrivaDB { get; set; }

        public int ArrivaStart { get; set; }

        public int WCSArrivaDB { get; set; }

        public int WCSArrivaStart { get; set; }


    }
}