dengjunjie
3 天以前 8efaf9f620920921bbaa6440ea34063c89f53d7a
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
using HslCommunication;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Helper;
using WIDESEA_ISquareCabinServices;
using WIDESEA_Model.Models;
using static WIDESEA_DTO.SquareCabin.OrderDto;
 
 
namespace WIDESEA_SquareCabinServices
{
    public class SupplierServices : ServiceBase<Dt_Supplier, IRepository<Dt_Supplier>>, ISupplierServices
    {
        public SupplierServices(IRepository<Dt_Supplier> BaseDal) : base(BaseDal)
        {
        }
 
        static string SearchDate = "";
        /// <summary>
        /// 获取上游供应商信息 0成功1失败
        /// </summary>
        /// <param name="searchDate"></param>
        /// <returns></returns>
        public WebResponseContent SyncSupplier()
        {
            var responseContent = new WebResponseContent();
            try
            {
                var url = "http://121.37.118.63:80/GYZ2/95fck/supplierInfo";
                // 请求参数
                if (string.IsNullOrEmpty(SearchDate)) SearchDate = DateTime.Now.ToString("yyyy-MM-dd:mm:ss");
                //请求参数
                var requestData = new
                {
                    searchDate = SearchDate
                };
                SearchDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
                var result = HttpHelper.Post(url, responseContent.ToJsonString());
                var response = JsonConvert.DeserializeObject<UpstreamResponse<SupplierInfo>>(result);
                if (response.resultCode!="0")
                {
                    //调用异常接口
                    //SendErrorToUpstream(6, "", response.resultMsg ?? "上游接口返回失败", "");
                    return responseContent.Error(response.resultMsg ?? "上游接口返回失败");
                }
                if (response.data == null || !response.data.Any())
                {
                    return responseContent.OK("上游供应商信息为空");
                }
                foreach (var supplier in response.data)
                {
                    var supplierInfo = new Dt_Supplier {
                       Supplier_no=supplier.supplier_no,
                       Supplier_name = supplier.supplier_name,
                       Telephone=supplier.phone,
                       Address = supplier.address,
                       Email=supplier.email,
                       Remark=supplier.remark,
                       ModifyDate=supplier.modify_date,
                    };
                    AddData(supplierInfo);
 
                }
                return responseContent.OK("同步成功");
            }
            catch (Exception ex)
            {
 
                //SendErrorToUpstream(6, "", ex.Message, "");
                return responseContent.Error("同步失败: " + ex.Message);
            }
        }
 
        /// <summary>
        /// 推送异常信息给上游系统1.入库单接口;2.入库单报完成接口;3.出库单接口;4.出库报完成接口;5.药品基础信息同步接口;6.供应商信息接口;7.客户信息接口;8.库存
        /// </summary>
        public void SendErrorToUpstream(int type, string code, string message, string remark)
        {
            try
            {
                var url = "http://121.37.118.63:80/GYZ2/95fck/exceptionLog";
 
                var requestData = new
                {
                    type = type.ToString(),
                    code = code,
                    message = message,
                    remark = remark
                };
 
                var result = HttpHelper.Post(url, requestData.ToJsonString());
                // 可以反序列化检查 resultCode 是否为0
            }
            catch (Exception e)
            {
                // 这里不要再抛异常了,避免死循环
                Console.WriteLine("异常接口推送失败:" + e.Message);
            }
        }
    }
}