qinchulong
2025-03-29 039a4a5433e7f80adc88b491b549e5d9486e4f9a
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
/*
 *所有关于Bill_group_stock类的业务代码应在此处编写
*可使用repository.调用常用方法,获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*Bill_group_stockService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using WIDESEA_Services.IRepositories;
using WIDESEA_Core.Utilities;
using WIDESEA_Services.Repositories;
using WIDESEA_Entity.DomainModels;
using System;
 
namespace WIDESEA_Services.Services
{
    public partial class VV_StockLocationService
    {
        public WebResponseContent DelStock(DeleteStockRequest request)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                content = bill_group_stockRepository.Instance.DbContextBeginTransaction(() =>
                {
                    bill_group_stock stock = bill_group_stockRepository.Instance.FindFirst(x => x.stock_id == request.stock_id);
                    var location = base_ware_locationRepository.Instance.FindFirst(f => f.id == stock.location_id);
                    var task = new dt_agvtask();
                    if (location == null) { task = dt_agvtaskRepository.Instance.FindFirst(f => f.agv_materbarcode == stock.BarCode); }
                    else
                    {
                        task = dt_agvtaskRepository.Instance.FindFirst(f => f.agv_materbarcode == stock.BarCode && (f.agv_fromaddress == location.upper_code || f.agv_fromaddress == location.down_code || f.agv_toaddress == location.upper_code || f.agv_toaddress == location.down_code));
                    }
                    if (task != null) { return WebResponseContent.Instance.Error($"该条码已经有任务,任务号是:{task.agv_tasknum}"); }
                    if (stock == null)
                    {
                        return WebResponseContent.Instance.Error($"未找到该数据,stock_id:{request.stock_id}");
                    }
                    else
                    {
                        WebResponseContent responseContent = new WebResponseContent();
                        try
                        {
                            bill_group_stockRepository.Instance.Delete(stock, true);
                        }
                        catch (Exception ex)
                        {
                            throw new Exception($"{ex.Message}");
                        }
                    }
                    content.Code = "0";
                    return WebResponseContent.Instance.OK("删除成功");
                });
            }
            catch (Exception ex)
            {
                content = WebResponseContent.Instance.Error($"库存删除失败,错误消息:{ex.Message}");
            }
            return content;
        }
    }
}