647556386
2 天以前 bfa52edd6a430978873367426da7b379730da411
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using SqlSugar.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.PLSEnum;
using WIDESEA_Core.BaseServices;
using WIDESEA_DTO;
using WIDESEA_DTO.PLS;
using WIDESEA_IBasicRepository;
using WIDESEA_IBasicService;
using WIDESEA_IInboundRepository;
using WIDESEA_IInboundService;
using WIDESEA_Model.Models;
using WIDESEA_External.PLSService;
using WIDESEA_Core;
 
namespace WIDESEA_InboundService
{
    public class MoInboundOrderService : ServiceBase<Dt_MoInboundOrder, IMoInboundOrderRepository>, IMoInboundOrderService
    {
 
        public IMoInboundOrderRepository Repository => BaseDal;
 
        public MoInboundOrderService(IMoInboundOrderRepository BaseDal) : base(BaseDal)
        {
        }
 
 
        /// <summary>
        /// PLS同步MO票信息
        /// </summary>
        public ApiResponseContent ReceiveMoStatus(MoInboundOrderDTO model)
        {
            // 1. 基础参数校验
            if (model == null || model.Data == null || !model.Data.Any())
            {
                return ApiResponseContent.Instance.Error("MO票传入参数为空");
            }
 
            var dataList = new List<LabelNoData>();
            int successCount = 0;
            int totalCount = model.Data.Count;
 
            try
            {
                foreach (var item in model.Data)
                {
                    var itemResult = new LabelNoData
                    {
                        LabelNo = item.LabelNo
                    };
                    try
                    {
                        // 参数校验
                        if (string.IsNullOrWhiteSpace(item.LabelNo))
                        {
                            throw new Exception("标签号 LabelNo 不能为空");
                        }
 
                        ///签名校验
                        bool IsSign = MD5Util.CheckPLSSign(model);
                        if (!IsSign)
                        {
                            return ApiResponseContent.Instance.Error("签名验证失败,请检查");
                        }
 
                        // 查询唯一键是否已存在(orgId+labelNo)
                        var existMo = BaseDal.QueryFirst(x => x.LabelNo == item.LabelNo && x.OrgId == item.OrgId);
 
                        if (existMo == null)
                        {
                            var addEntity = new Dt_MoInboundOrder()
                            {
                                OrgId = item.OrgId,
                                LabelNo = item.LabelNo,
                                Status = item.Status,
                                BarcodeNumber = item.BarcodeNumber,
                                SupplierCode = item.SupplierCode,
                                ItemCode = item.ItemCode,
                                Qty = item.Qty,
                                WorkOrderName = item.WorkOrderName,
                                DeleteFlag = item.DeleteFlag,
                                ReturnToPlsStatus = ReturnToPlsStatusEnum.未推送.ObjToInt(),
                                CreateDate = item.CreateDate,
                                Creater = item.CreateUser,
                                Modifier = item.UpdateUser,
                                ModifyDate = item.UpdateDate
                            };
                            BaseDal.AddData(addEntity);
                        }
                        else
                        {
                            existMo.OrgId = item.OrgId;
                            existMo.Status = item.Status;
                            existMo.BarcodeNumber = item.BarcodeNumber;
                            existMo.SupplierCode = item.SupplierCode;
                            existMo.ItemCode = item.ItemCode;
                            existMo.Qty = item.Qty;
                            existMo.WorkOrderName = item.WorkOrderName;
                            existMo.DeleteFlag = item.DeleteFlag;
                            existMo.Modifier = item.UpdateUser;
                            existMo.ModifyDate = item.UpdateDate;
 
                            BaseDal.UpdateData(existMo);
                        }
 
                        // 单条处理成功
                        itemResult.Success = 0;
                        successCount++;
                    }
                    catch (Exception ex)
                    {
                        // 单条处理失败
                        itemResult.Success = 1;
                        itemResult.Msg = ex.Message;
                    }
                    finally
                    {
                        // 每条无论成功/失败,都加入返回列表
                        dataList.Add(itemResult);
                    }
                }
 
                // 全部处理完成,返回结果
                return ApiResponseContent.Instance.OK(
                    dataList,
                    $"处理完成:共{totalCount}条,成功{successCount}条,失败{totalCount - successCount}条"
                );
            }
            catch (Exception ex)
            {
                return ApiResponseContent.Instance.Error($"MO票同步整体异常:{ex.Message}");
            }
        }
 
    }
}