cnf
2025-03-20 4d7047f93580a2a7dd36b915ef05a2ea292e8108
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
using Castle.Core.Resource;
using MES.Service.DB;
using MES.Service.Dto.webApi;
using MES.Service.Modes;
using SqlSugar;
 
namespace MES.Service.service.BasicData;
 
public class MesLineManager : Repository<MesLine>
{
 
    public bool SaveList(List<ErpSb> devices)
    {
        var result = devices.Select(Save).ToList();
        return result.All(b => b);
    }
 
    public bool Save(ErpSb device)
    {
        var entity = GetErpDevice(device);
 
        return UseTransaction(db =>
        {
            switch (device.Type)
            {
                case "3":
                    return DeleteData(db, entity) ? 1 : 0;
                case "0":
                case "1":
                case "2":
                    return SaveOrUpdateData(db, entity) ? 1 : 0;
                default:
                    throw new NotImplementedException(
                        $"type没有{device.Type}这个类型");
            }
        }) > 0;
    }
 
    private bool SaveOrUpdateData(SqlSugarScope db, MesLine device)
    {
        if (device.Id != null) base.DeleteById(device.Id);
 
        var orUpdate = base.Insert(device);
        if (orUpdate) return true;
        throw new NotImplementedException("插入或更新失败");
    }
 
    private bool DeleteData(SqlSugarScope db, MesLine device)
    {
        var update = base.DeleteById(device.Id);
 
        if (update) return true;
        throw new NotImplementedException("更新失败");
    }
 
    private MesLine GetErpDevice(ErpSb device)
    {
        var entity = new MesLine
        {
            FNUMBER = device.FNUMBER,
            FFORBIDSTATUS = device.FFORBIDSTATUS,
            LineName = device.FNAME,
            Memo = device.FDESCRIPTION,
            FCREATEORGID = device.FCREATEORGID,
            FUSEORGID = device.FUSEORGID,
            Departmentcode = device.F_WWC_BASE,
            WorkType=0,
            Factory="1000",
            Company="1000",
            CreateDate=DateTime.Now,
            LineNo=device.FNUMBER,
            FBILLHEAD=device.Id
        };
 
        var single = base.GetSingle(it => it.FNUMBER == entity.FNUMBER);
        if (single != null) entity.Id = single.Id;
 
        return entity;
    }
 
}