刘磊
2025-04-19 823752496e2a4cdb6a1fb36227cd15b8b7135336
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
using Mapster;
using Masuit.Tools;
using System.CodeDom;
using System.ComponentModel.DataAnnotations;
using System.Reflection.Emit;
using WIDESEA_Common;
 
namespace WIDESEA_StorageBasicService;
 
public class Dt_CacheInfoService : ServiceBase<Dt_CacheInfo, IDt_CacheInfoRepository>, IDt_CacheInfoService
{
    private readonly IDt_CacheInfo_htyRepository _cacheInfo_htyRepository;
    public Dt_CacheInfoService(IDt_CacheInfoRepository BaseDal, IDt_CacheInfo_htyRepository cacheInfo_htyRepository) : base(BaseDal)
    {
        _cacheInfo_htyRepository = cacheInfo_htyRepository;
    }
 
    public WebResponseContent AddCacheInfoByAPP(SaveModel input)
    {
        WebResponseContent content = new WebResponseContent();
        try
        {
            string operateType = input.MainData["operateType"].ToString();
 
            string cztm = input.MainData["cztm"].ToString();
            if (string.IsNullOrEmpty(cztm)) throw new Exception("车轴条码不能为空");
 
            string machine = input.MainData["machine"].ToString();
 
            if (operateType.Equals("1"))
            {
                if (BaseDal.QueryFirst(x => x.cacheNo == machine) != null) throw new Exception($"{machine}缓存架存在车轴数据,请核实后重试");
 
                Dt_CacheInfo cacheInfo = new Dt_CacheInfo
                {
                    cacheNo = machine,
                    cacheName = machine == "1000" ? "1号压装位" : "2号压装位",
                    targetAddress = machine == "1000" ? "2032" : "2042",
                    CreateDate = DateTime.Now,
                    Creater = "admin",
                    createType = 2,   //1-自动创建  2-手动创建
                    czh = cztm,
                };
 
                if (BaseDal.AddData(cacheInfo) > 0)
                {
                    content.OK("保存成功");
                }
                else
                {
                    content.Error("保存失败");
                }
            }
            else
            {
                var cacheInfo = BaseDal.QueryFirst(x => x.cacheNo == machine && x.czh == cztm);
                if (cacheInfo == null) throw new Exception($"未找到{machine}缓存架车轴{cztm}数据,请核实后重试");
 
                Dt_CacheInfo_hty cacheInfo_hty = new Dt_CacheInfo_hty();
 
                cacheInfo.Adapt(cacheInfo_hty);
                cacheInfo_hty.FinishDate = DateTime.Now;
                cacheInfo_hty.OperateType = 4;
 
                if (_cacheInfo_htyRepository.AddData(cacheInfo_hty) > 0 && BaseDal.DeleteData(cacheInfo))
                {
                    
                    content.OK("保存成功");
                }
                else
                {
                    content.Error("保存失败");
                }
            }
        }
        catch (Exception ex)
        {
            content.Error($"添加异常:{ex.Message}");
        }
        return content;
    }
}