dengjunjie
3 天以前 b784d019c3848718eb95eb0d34dde34c6a262b06
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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
    {
        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);
            }
        }
 
    }
}