wangxinhui
2024-11-06 8f392cc88b0768b74efca3b68785cf5aa1c38e70
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
81
82
83
84
85
 
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using System.Linq;
using WIDESEA_Common.LoctionEnum;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Core.Utilities;
using WIDESEA_Entity.DomainModels;
using WIDESEA_Entity.DomainModels.CacheTask;
using WIDESEA_Entity.DomainModels.CacheTask.WIDESEA_Entity.DomainModels;
using WIDESEA_Services.IRepositories;
using WIDESEA_Services.Repositories;
 
namespace WIDESEA_Services.Services
{
    public partial class VV_ContainerInfoService
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly IVV_ContainerInfoRepository _repository;//访问数据库
 
        [ActivatorUtilitiesConstructor]
        public VV_ContainerInfoService(
            IVV_ContainerInfoRepository dbRepository,
            IHttpContextAccessor httpContextAccessor
            )
        : base(dbRepository)
        {
            _httpContextAccessor = httpContextAccessor;
            _repository = dbRepository;
            //多租户会用到这init代码,其他情况可以不用
            //base.Init(dbRepository);
        }
        public override WebResponseContent Del(object[] keys, bool delList = true)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
           VV_ContainerInfo vV_Container=   VV_ContainerInfoRepository.Instance.Find(d => d.container_id.ToString() == keys[0].ToString()).FirstOrDefault();
                VOLContext Context = new VOLContext();
                Ibase_pda_locationRepository Pda_LocationRepository = new base_pda_locationRepository(Context);
                Idt_agvtaskRepository agvtaskRepository=new dt_agvtaskRepository(Context);
                    Idt_containerRepository containerRepository=   new dt_containerRepository(Context);
                if (vV_Container!=null)
                {
                
                     base_pda_location  Pda_Location= Pda_LocationRepository.FindFirst(d=>d.L_Code== vV_Container.L_Code);
                    if (Pda_Location!=null)
                    {
                        dt_agvtask dt_Agvtask = agvtaskRepository.FindFirst(d => d.agv_fromaddress == Pda_Location.L_Code || d.agv_toaddress == Pda_Location.L_Code);
                        if (dt_Agvtask==null)
                        {
                       
 
                            dt_container dt_Container = containerRepository.FindFirst(d => d.container_id == vV_Container.container_id);
 
                            Pda_Location.L_state = LoctionStateEnum.LocationState_Empty.ToString();
                            Pda_Location.L_Task = 2;
                            Pda_LocationRepository.Update(Pda_Location,true);
                            containerRepository.Delete(dt_Container,true);
                            return content.OK("删除成功");
                        }
                        else
                        {
                            return content.Error("AGV任务中存在,无法删除");
 
                        }
 
 
                    }
                    else
                    {
                        return content.Error($"pda货位列表中未找到{Pda_Location.L_Code}");
                    }
                  
                }
            }
            catch (System.Exception)
            {
 
                throw;
            }
            return base.Del(keys, delList); 
        }
    }
}