qinchulong
3 天以前 dc467182bfaeeb0dfd9bc2d6c4ec8fe64b179446
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
using AngleSharp.Dom;
using log4net.Core;
using Mapster;
using Masuit.Tools;
using SqlSugar;
using System.Collections;
using System.Collections.Generic;
using System.Drawing.Printing;
using System.Linq.Expressions;
using System.Threading.Tasks;
using WIDESEA_Common;
using WIDESEA_Core;
using WIDESEA_Model.Models;
 
namespace WIDESEA_StorageBasicService;
 
public class VV_PalletStockInfoService : ServiceBase<VV_PalletStockInfo, IVV_PalletStockInfoRepository>, IVV_PalletStockInfoService
{
    private readonly IDt_PalletStockInfoRepository _PalletStockInfoRepository;
    private readonly IDt_PalletStockInfoDetailRepository _PalletStockInfoDetailRepository;
    private readonly IDt_PalletStockInfo_htyRepository _PalletStockInfo_HtyRepository;
    private readonly ILocationStatusChangeRecordRepository _locationStatusChangeRecordRepository;
    private readonly IUnitOfWorkManage _unitOfWorkManage;
    public VV_PalletStockInfoService(IVV_PalletStockInfoRepository BaseDal, IDt_PalletStockInfoRepository palletStockInfoRepository, IDt_PalletStockInfoDetailRepository palletStockInfoDetailRepository, IUnitOfWorkManage unitOfWorkManage, ILocationStatusChangeRecordRepository locationStatusChangeRecordRepository) : base(BaseDal)
    {
        _PalletStockInfoRepository = palletStockInfoRepository;
        _PalletStockInfoDetailRepository = palletStockInfoDetailRepository;
        _unitOfWorkManage = unitOfWorkManage;
        _locationStatusChangeRecordRepository = locationStatusChangeRecordRepository;
    }
 
    public override WebResponseContent DeleteData(object key)
    {
        try
        {
 
            var stock = _PalletStockInfoRepository.QueryFirstNavAsync(x => x.Id == key.ObjToInt()).Result;
            var stockHty = stock.Adapt<Dt_PalletStockInfo_hty>();
            stockHty.FinishTime = DateTime.Now;
            stockHty.OperateType = (int)OperateTypeEnum.人工删除;
            stockHty.Modifier = App.User.UserName;
 
            var location = SqlSugarHelper.DbWMS.Queryable<DtLocationInfo>().FirstAsync(x => x.LocationCode == stock.LocationCode).Result;
            location.LocationStatus = (int)LocationEnum.Free;
 
            var hty = BaseDal.Db.InsertNav(stockHty)
               .Include(x => x.StockInfoDetails)
               .ExecuteCommand();
 
            var locationd = SqlSugarHelper.DbWMS.Updateable(location).ExecuteCommandHasChange();
 
            _PalletStockInfoRepository.DeleteDataById(stock.Id);
            return base.DeleteData(key);
        }
        catch (Exception ex)
        {
            return WebResponseContent.Instance.Error(ex.Message);
        }
    }
 
    /// <summary>
    /// 批量删除
    /// </summary>
    /// <param name="keys"></param>
    /// <returns></returns>
    public override WebResponseContent DeleteData(object[] keys)
    {
        WebResponseContent content = new WebResponseContent();
        try
        {
            foreach (var item in keys)
            {
                var stock = _PalletStockInfoRepository.QueryFirstNavAsync(x => x.Id == item.ObjToInt()).Result;
                Dt_PalletStockInfo_hty stockHty = stock.Adapt<Dt_PalletStockInfo_hty>();
                stockHty.FinishTime = DateTime.Now;
                stockHty.OperateType = (int)OperateTypeEnum.人工删除;
                stockHty.Modifier = App.User.UserName;
                //_PalletStockInfoRepository.AddData(stockHty);
                _PalletStockInfoRepository.DeleteDataById(stock.Id);
 
                List<Dt_PalletStockInfoDetail> detail = _PalletStockInfoDetailRepository.QueryData(x => x.StockId == stock.Id).ToList();
                if (detail is not null && detail.Count() > 0)
                {
                    List<Dt_PalletStockInfoDetail_hty> details = detail.Adapt<List<Dt_PalletStockInfoDetail_hty>>();
                    var ids = details.Select(x => (object)x.Id).ToArray();
                    var isStockDetailUpdated = _PalletStockInfoDetailRepository.DeleteDataByIds(ids);
                    var isStockAdd = SqlSugarHelper.DbWMS.Insertable(details).ExecuteCommand();
                }
 
                var location = SqlSugarHelper.DbWMS.Queryable<DtLocationInfo>().FirstAsync(x => x.LocationCode == stock.LocationCode).Result;
                int beforeStatue = location.LocationStatus;
                location.LocationStatus = (int)LocationEnum.Lock;
                SqlSugarHelper.DbWMS.Updateable(location).ExecuteCommandHasChange();
 
                _locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(location, beforeStatue, (int)StatusChangeTypeEnum.ManualOperation, 0);
            }
 
            return content.OK("删除成功");
        }
        catch (Exception ex)
        {
            return content.Error(ex.Message);
        }
    }
}