陈勇
2 天以前 6b74e1dcf5642c8f56975471e27780d695953989
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using AngleSharp.Dom;
using Mapster;
using Masuit.Tools;
using SqlSugar;
using System.Collections.Generic;
using System.Drawing.Printing;
using System.Linq.Expressions;
using WIDESEA_Common;
using WIDESEA_Core;
using WIDESEA_Core.Enums;
using WIDESEA_DTO;
using WIDESEA_IRecordService;
 
namespace WIDESEA_StorageBasicService;
 
public class VV_StockInfoService : ServiceBase<VV_StockInfo, IVV_StockInfoRepository>, IVV_StockInfoService
{
    private readonly IDt_PalletStockInfoRepository _PalletStockInfoRepository;
    private readonly IStockQuantityChangeRecordService _stockQuantityChangeRecord;
    private readonly IDt_CarBodyInfoRepository _carBodyInfoRepository;
    private readonly ILocationInfoRepository _locationInfoRepository;
    private readonly ILocationStatusChangeRecordRepository _locationStatusChangeRecordRepository;
    private readonly IUnitOfWorkManage _unitOfWorkManage;
 
    public VV_StockInfoService(IVV_StockInfoRepository BaseDal, IDt_PalletStockInfoRepository PalletStockInfoRepository, IStockQuantityChangeRecordService stockQuantityChangeRecord, IDt_CarBodyInfoRepository carBodyInfoRepository, ILocationInfoRepository locationInfoRepository, ILocationStatusChangeRecordRepository locationStatusChangeRecordRepository, IUnitOfWorkManage unitOfWorkManage) : base(BaseDal)
    {
        _PalletStockInfoRepository = PalletStockInfoRepository;
        _stockQuantityChangeRecord = stockQuantityChangeRecord;
        _carBodyInfoRepository = carBodyInfoRepository;
        _locationInfoRepository = locationInfoRepository;
        _locationStatusChangeRecordRepository = locationStatusChangeRecordRepository;
        _unitOfWorkManage = unitOfWorkManage;
    }
 
    public WebResponseContent stockLock(object[] keys)
    {
        WebResponseContent content = new WebResponseContent();
        try
        {
            foreach (var item in keys)
            {
                var stock = _PalletStockInfoRepository.QueryFirst(x => x.Id == Convert.ToInt32(item));
                if (stock.LockOrder != 1)
                {
                    stock.StockStatus = 1;
                    _PalletStockInfoRepository.UpdateData(stock);
                }
            }
            return content.OK("锁定成功!");
        }
        catch (Exception e)
        {
            return content.Error(e.Message);
        }
    }
 
    public WebResponseContent stockUnLock(object[] keys)
    {
        WebResponseContent content = new WebResponseContent();
        try
        {
            foreach (var item in keys)
            {
                var stock = _PalletStockInfoRepository.QueryFirst(x => x.Id == Convert.ToInt32(item));
                stock.StockStatus = 0;
                _PalletStockInfoRepository.UpdateData(stock);
            }
            return content.OK("解锁成功!");
        }
        catch (Exception e)
        {
            return content.Error(e.Message);
        }
    }
 
 
    public override WebResponseContent DeleteData(object[] keys)
    {
        WebResponseContent content = new WebResponseContent();
        try
        {
            var stockInfo = BaseDal.QueryFirst(x => x.Id == keys[0].ObjToInt());
            var stock = _PalletStockInfoRepository.QueryFirst(x => x.Id == keys[0].ObjToInt());
            var location = _locationInfoRepository.QueryFirst(x => x.LocationCode == stock.LocationCode);
            var carInfo = _carBodyInfoRepository.QueryData(x => x.Id == stock.carBodyID);
 
            int beforState = location.LocationStatus;
            stock.StockStatus = 5;
            location.LocationStatus = LocationEnum.Free.ObjToInt();
 
            LocationChangeRecordDto changeRecordDto = new LocationChangeRecordDto()
            {
                AfterStatus = 0,
                BeforeStatus = beforState,
                TaskNum = 0,
                LocationId = location.Id,
                LocationCode = location.LocationCode,
                ChangeType = (int)StatusChangeTypeEnum.ManualOperation
            };
 
            _unitOfWorkManage.BeginTran();
            _PalletStockInfoRepository.DeleteData(stock);
            _locationInfoRepository.UpdateData(location);
            _carBodyInfoRepository.DeleteData(carInfo);
 
            _locationStatusChangeRecordRepository.AddStatusChangeRecord(changeRecordDto);
            _unitOfWorkManage.CommitTran();
 
            return content.OK("删除成功");
        }
        catch (Exception ex)
        {
            _unitOfWorkManage.RollbackTran();
            return content.Error(ex.Message);
        }
    }
}