雷神教育集团
2026-03-06 75c4ed0d3c640e66bc95dc170de52b753629e3ed
ÏîÄ¿´úÂë/WCS/WCSServices/WIDESEAWCS_PackInfoService/PackaxisService.cs
@@ -15,13 +15,27 @@
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_IPackInfoService;
<<<<<<< HEAD
=======
using WIDESEAWCS_IBasicInfoRepository;
>>>>>>> main
namespace WIDESEAWCS_PackInfoService
{
    public class PackaxisService : ServiceBase<Dt_Packaxis, IPackaxisRepository>, IPackaxisService
    {
<<<<<<< HEAD
        public PackaxisService(IPackaxisRepository BaseDal) : base(BaseDal)
        {
=======
        private readonly IPackTypeRepository _packTypeRepository;
        private readonly IStationMangerRepository _stationMangerRepository;
        public PackaxisService(IPackaxisRepository BaseDal, IPackTypeRepository packTypeRepository, IStationMangerRepository stationMangerRepository) : base(BaseDal)
        {
            _packTypeRepository = packTypeRepository;
            _stationMangerRepository = stationMangerRepository;
>>>>>>> main
        }
        public override WebResponseContent Import(List<IFormFile> files)
        {
@@ -56,7 +70,11 @@
                using (ImportExcelHelper excelHelper = new ImportExcelHelper(fullPath))
                {
                    dtExcel = excelHelper.ExcelToDataTable();
<<<<<<< HEAD
                    
=======
>>>>>>> main
                }
                List<Dt_Packaxis> addAxis = new List<Dt_Packaxis>();
                List<Dt_Packaxis> updateAxis = new List<Dt_Packaxis>();
@@ -82,7 +100,11 @@
                    string AxisZCount = row["AxisZCount"]?.ToString() ?? string.Empty;
                    string AxisZSpacing = row["AxisZSpacing"]?.ToString() ?? string.Empty;
                    var axis = BaseDal.QueryFirst(x => x.DeviceCode == DeviceCode && x.StationCode == StationCode && x.PackType == PackType);
<<<<<<< HEAD
                    if(axis == null)
=======
                    if (axis == null)
>>>>>>> main
                    {
                        Dt_Packaxis packaxis = new Dt_Packaxis()
                        {
@@ -136,5 +158,112 @@
            return content;
        }
<<<<<<< HEAD
=======
        /// <summary>
        /// æ·»åŠ åæ ‡æ•°æ®
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public override WebResponseContent AddData(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                string json = JsonConvert.SerializeObject(saveModel.MainData);
                Dt_Packaxis dt_Pack = JsonConvert.DeserializeObject<Dt_Packaxis>(json);
                Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == dt_Pack.StationCode  && x.StackerCraneCode == dt_Pack.DeviceCode);
                Dt_PackType packTyp = _packTypeRepository.QueryFirst(x => x.Id == dt_Pack.PackType);
                int w = 1200;//这个是码垛托盘宽1.2ç±³
                int h = 1500;//托盘的高度限高1.5ç±³
                int AxisXCountMax = w / packTyp.PackLength;//X坐标最多放码垛数量
                int AxisYCountMax = w / packTyp.PackWidth;//Y坐标最多放码垛数量
                int AxisZCountMax = h / packTyp.PackHeight;//Z坐标最多放码垛数量
                if (dt_Pack.AxisXCount <= 0 || dt_Pack.AxisXCount > AxisXCountMax || dt_Pack.AxisYCount <= 0 || dt_Pack.AxisYCount > AxisYCountMax || dt_Pack.AxisZCount <= 0 || dt_Pack.AxisZCount > AxisZCountMax)
                {
                    return WebResponseContent.Instance.Error($"添加失败,请输入X坐标码垛数大于0且小于{AxisXCountMax + 1}且Y坐标码垛数大于0且小于{AxisYCountMax + 1}且Z坐标码垛数大于0且小于{AxisZCountMax + 1}");
                }
                if (stationManger.IsNullOrEmpty())
                {
                    return WebResponseContent.Instance.Error($"添加失败,该码垛机器输送线工位选错!");
                }
                Dt_Packaxis packaxis = BaseDal.QueryFirst(x => x.DeviceCode == dt_Pack.DeviceCode && x.StationCode == dt_Pack.StationCode && x.PackType == dt_Pack.PackType);
                if (packaxis.IsNullOrEmpty())
                {
                    saveModel.MainData["PackNum"] = dt_Pack.AxisXCount * dt_Pack.AxisYCount * dt_Pack.AxisZCount;
                    return base.AddData(saveModel);
                }
                return WebResponseContent.Instance.Error($"添加失败,该码垛坐标数据已存在!");
            }
            catch (Exception ex)
            {
                content = WebResponseContent.Instance.Error(ex.Message);
            }
            return content;
        }
        /// <summary>
        /// ä¿®æ”¹åæ ‡æ•°æ®
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public override WebResponseContent UpdateData(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                string json = JsonConvert.SerializeObject(saveModel.MainData);
                Dt_Packaxis dt_Pack = JsonConvert.DeserializeObject<Dt_Packaxis>(json);
                Dt_PackType packTyp = _packTypeRepository.QueryFirst(x => x.Id == dt_Pack.PackType);
                int w = 1200;//这个是码垛托盘宽1.2ç±³
                int h = 1500;//托盘的高度限高1.5ç±³
                int AxisXCountMax = w / packTyp.PackLength;//X坐标最多放码垛数量
                int AxisYCountMax = w / packTyp.PackWidth;//Y坐标最多放码垛数量
                int AxisZCountMax = h / packTyp.PackHeight;//Z坐标最多放码垛数量
                if (dt_Pack.AxisXCount <= 0 || dt_Pack.AxisXCount > AxisXCountMax || dt_Pack.AxisYCount <= 0 || dt_Pack.AxisYCount > AxisYCountMax || dt_Pack.AxisZCount <= 0 || dt_Pack.AxisZCount > AxisZCountMax)
                {
                    return WebResponseContent.Instance.Error($"修改失败,请输入X坐标码垛数大于0且小于{AxisXCountMax + 1}且Y坐标码垛数大于0且小于{AxisYCountMax + 1}且Z坐标码垛数大于0且小于{AxisZCountMax + 1}");
                }
                Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == dt_Pack.StationCode && x.StackerCraneCode == dt_Pack.DeviceCode);
                if (stationManger.IsNullOrEmpty())
                {
                    return WebResponseContent.Instance.Error($"修改失败,该码垛机器输送线工位选错!");
                }
                Dt_Packaxis packaxis = BaseDal.QueryFirst(x => x.Id != dt_Pack.Id && x.DeviceCode == dt_Pack.DeviceCode && x.StationCode == dt_Pack.StationCode && x.PackType == dt_Pack.PackType);
                if (packaxis.IsNullOrEmpty())
                {
                    saveModel.MainData["PackNum"] = dt_Pack.AxisXCount * dt_Pack.AxisYCount * dt_Pack.AxisZCount;
                    return base.UpdateData(saveModel);
                }
                return WebResponseContent.Instance.Error($"修改失败,该码垛坐标数据已存在!");
            }
            catch (Exception ex)
            {
                content = WebResponseContent.Instance.Error(ex.Message);
            }
            return content;
        }
>>>>>>> main
    }
}