using Masuit.Tools;
|
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.BaseServices;
|
using WIDESEA_Core.Helper;
|
using WIDESEA_ISquareCabinRepository;
|
using WIDESEA_ISquareCabinServices;
|
using WIDESEA_Model.Models;
|
using WIDESEA_SquareCabinRepository;
|
using static WIDESEA_DTO.SquareCabin.OrderDto;
|
|
namespace WIDESEA_SquareCabinServices
|
{
|
public class CustomerServices : ServiceBase<Dt_Customer, ICustomerRepository>, ICustomerServices
|
{
|
public CustomerServices(ICustomerRepository BaseDal) : base(BaseDal)
|
{
|
}
|
|
public WebResponseContent GetCustomerList(DateTime searchDate)
|
{
|
var responseContent = new WebResponseContent();
|
try
|
{
|
//请求地址
|
var url = "http:/127.0.0.1:9000/GYZ2/95fck/clientInfo";
|
//请求参数
|
var requestDate = new
|
{
|
searchDate = searchDate.ToString("yyyy-MM-dd:mm:ss")
|
};
|
//调用上游接口
|
var reslu = HttpHelper.Post(url, requestDate.ToJsonString());
|
var response = JsonConvert.DeserializeObject<UpstreamResponse<CustomerInfo>>(reslu);
|
if (response.resultCode!="0")
|
{
|
// 调用异常接口
|
SendErrorToUpstream(7, "", response.resultMsg ?? "上游接口返回失败", "");
|
return responseContent.Error(response.resultMsg ?? "上游接口返回失败");
|
}
|
if (response.data == null || !response.data.Any())
|
{
|
return responseContent.OK("返回用户列表为空");
|
}
|
foreach (var custom in response.data)
|
{
|
var customdata = new Dt_Customer
|
{
|
Client_no=custom.client_no,
|
Client_name=custom.client_name,
|
Telephone=custom.telephone,
|
Address = custom.address,
|
Email =custom.email,
|
Remark=custom.remark,
|
ModifyDate = custom.modify_date
|
};
|
AddData(customdata);
|
}
|
return responseContent.OK("信息同步成功");
|
}
|
catch (Exception ex)
|
{
|
SendErrorToUpstream(7, "", 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://127.0.0.1:9090/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);
|
}
|
}
|
|
}
|
}
|