dengjunjie
3 天以前 b784d019c3848718eb95eb0d34dde34c6a262b06
´úÂë¹ÜÀí/WIDESEAWCS_Server/WIDESEAWCS_Server/WIDESEAWCS_BasicInfoService/BoxingService.cs
@@ -1,20 +1,80 @@
using System;
using Autofac.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Common;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_IBasicInfoService;
using WIDESEAWCS_Model.Models;
namespace WIDESEAWCS_BasicInfoService
{
    public class BoxingService : ServiceBase<Dt_Boxing, IRepository<Dt_Boxing>>, IBoxingService
    {
        public BoxingService(IRepository<Dt_Boxing> BaseDal) : base(BaseDal)
        private readonly IProcessInfoService _processInfoService;
        // ç›´æŽ¥æ³¨å…¥ BoxingDetail çš„仓储,替代注入 BoxingDetailService
        private readonly IRepository<Dt_BoxingDetail> _boxingDetailRepo;
        public BoxingService(
            IRepository<Dt_Boxing> BaseDal,
            IProcessInfoService processInfoService,
            // æ–°å¢žæ³¨å…¥ BoxingDetail ä»“储
            IRepository<Dt_BoxingDetail> boxingDetailRepo
            ) : base(BaseDal)
        {
            _processInfoService = processInfoService;
            _boxingDetailRepo = boxingDetailRepo; // èµ‹å€¼
        }
        public IRepository<Dt_Boxing> Repository => BaseDal;
        //删除当前托盘
        public WebResponseContent DeleteCurrentTray()
        {
            try
            {
                var PalletCode = TcpClientExample.Start("192.168.2.120", 2001);
                if (!PalletCode.IsNotEmptyOrNull() || PalletCode == "NoRead")
                {
                    return WebResponseContent.Instance.Error("托盘码未扫到,请重试");
                }
                Db.Ado.BeginTran();
                // 1. åˆ é™¤ Boxing ä¸»è¡¨æ•°æ®
                Dt_Boxing dt_Boxing = BaseDal.QueryFirst(x => x.PalletCode == PalletCode);
                if (dt_Boxing != null)
                {
                    BaseDal.DeleteData(dt_Boxing);
                    // 2. ç›´æŽ¥é€šè¿‡ä»“储删除 BoxingDetail æ•°æ®ï¼ˆæ ¸å¿ƒä¿®æ”¹ï¼‰
                    Dt_BoxingDetail dt_BoxingDetail = _boxingDetailRepo.QueryFirst(x => x.BoxingId == dt_Boxing.Id);
                    if (dt_BoxingDetail != null)
                    {
                        _boxingDetailRepo.DeleteData(dt_BoxingDetail);
                    }
                }
                // 3. åˆ é™¤ ProcessInfo æ•°æ®
                Dt_ProcessInfo dt_ProcessInfo = _processInfoService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
                if (dt_ProcessInfo != null)
                {
                    _processInfoService.Repository.DeleteData(dt_ProcessInfo);
                }
                Db.Ado.CommitTran();
                return WebResponseContent.Instance.OK("删除成功");
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                throw new Exception(ex.Message);
            }
        }
    }
}