Browse Source

设备基本信息接口

storemanagement
zhaoy 8 months ago
parent
commit
9e9a81f813
13 changed files with 568 additions and 7 deletions
  1. +5
    -4
      BPA.SAAS.Manage.Application/DataBase/Services/GoodsService.cs
  2. +62
    -0
      BPA.SAAS.Manage.Application/Device/DeviceServices.cs
  3. +34
    -0
      BPA.SAAS.Manage.Application/Device/Dtos/Device/DeviceInfoBaseDto.cs
  4. +41
    -0
      BPA.SAAS.Manage.Application/Device/Dtos/Device/DeviceInfoQueryDto.cs
  5. +18
    -0
      BPA.SAAS.Manage.Application/Device/Dtos/Device/DeviceQueryInputDto.cs
  6. +18
    -0
      BPA.SAAS.Manage.Application/Device/Interface/IDeviceService.cs
  7. +142
    -0
      BPA.SAAS.Manage.Application/Device/Services/DeviceService.cs
  8. +1
    -0
      BPA.SAAS.Manage.Comm/BPA.SAAS.Manage.Comm.csproj
  9. +18
    -0
      BPA.SAAS.Manage.Comm/Model/ResultEntity.cs
  10. +219
    -0
      BPA.SAAS.Manage.Comm/Util/Utiily.cs
  11. +0
    -1
      BPA.SAAS.Manage.Core/BPA.SAAS.Manage.Core.csproj
  12. +7
    -1
      BPA.SAAS.Manage.Core/Device/BPA_DeviceInfo.cs
  13. +3
    -1
      BPA.SAAS.Manage.Web.Entry/appsettings.json

+ 5
- 4
BPA.SAAS.Manage.Application/DataBase/Services/GoodsService.cs View File

@@ -50,11 +50,10 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
public async Task<PageUtil> GetGoodsPage(GoodsQueryDto dto)
{
List<IConditionalModel> conModels = new List<IConditionalModel>();
string groupId = App.User.FindFirst(ClaimConst.GroupId)?.Value;
#region 条件查询
if (!string.IsNullOrEmpty(dto.Name))
{
conModels.Add(new ConditionalModel() { FieldName = "a.GoodsName", ConditionalType = ConditionalType.Like, FieldValue = dto.Name });
conModels.Add(new ConditionalModel() { FieldName = "a.Name", ConditionalType = ConditionalType.Like, FieldValue = dto.Name });
}
if (!string.IsNullOrEmpty(dto.GoodsTypeId))
@@ -70,8 +69,6 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
#endregion

RefAsync<int> total = 0;


var res =await _db.Queryable<BPA_GoodsInfo, BPA_GoodsType>((a, b) => new JoinQueryInfos(
JoinType.Left, a.GoodsTypeId == b.Id
))
@@ -111,6 +108,10 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
};
return util;
}
/// <summary>
/// 查询所有商品
/// </summary>
/// <returns></returns>
public async Task<List<BPA_GoodsInfo>> GetGoodsList()
{
var res = await _db.Queryable<BPA_GoodsInfo>().ToListAsync();


+ 62
- 0
BPA.SAAS.Manage.Application/Device/DeviceServices.cs View File

@@ -0,0 +1,62 @@
using BPA.SAAS.Manage.Application.Device.Dtos.Device;
using BPA.SAAS.Manage.Application.Device.Interface;
using BPA.SAAS.Manage.Core.Base;
using Microsoft.AspNetCore.Components.Forms;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.SAAS.Manage.Application.Device
{
[ApiDescriptionSettings("Device", Tag = "设备基础信息管理")]
public class DeviceServices: IDynamicApiController, ITransient
{
IDeviceService _deviceService;
public DeviceServices(IDeviceService deviceService)
{
_deviceService=deviceService;
}
/// <summary>
/// 分页查询
/// </summary>
/// <param name="inputDto"></param>
/// <returns></returns>
[HttpPost("/api/device/page")]
public async Task<PageUtil> GetDeviceInfoPage(DeviceQueryInputDto inputDto)
{
return await _deviceService.GetDeviceInfoPage(inputDto);
}
/// <summary>
/// 添加
/// </summary>
/// <param name="inputDto"></param>
/// <returns></returns>
[HttpPost("/api/device/add")]
public async Task<bool> AddDevice(DeviceInfoBaseDto inputDto)
{
return await _deviceService.AddDevice(inputDto);
}
/// <summary>
/// 修改
/// </summary>
/// <param name="inputDto"></param>
/// <returns></returns>
[HttpPost("/api/device/update")]
public async Task<bool> UpdateDevice(DeviceInfoBaseDto inputDto)
{
return await _deviceService.UpdateDevice(inputDto);
}
/// <summary>
/// 删除
/// </summary>
/// <param name="inputList"></param>
/// <returns></returns>
[HttpPost("/api/device/delete")]
public async Task<bool> DelDeviceInfo(List<string> inputList)
{
return await _deviceService.DelDeviceInfo(inputList);
}
}
}

+ 34
- 0
BPA.SAAS.Manage.Application/Device/Dtos/Device/DeviceInfoBaseDto.cs View File

@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.SAAS.Manage.Application.Device.Dtos.Device
{
public class DeviceInfoBaseDto
{
public string Id { get; set; }
/// <summary>
/// 设备名称
/// </summary>
public string DeviceName { get; set; }

/// <summary>
/// 设备标签
/// </summary>
public string DeviceTypeId { get; set; }
/// <summary>
///归属场景(店铺)
/// </summary>
public string OrgId { get; set; }
/// <summary>
/// 设备类型
/// </summary>
public string DeviceTypeKey { get; set; }
/// <summary>
/// 设备版本
/// </summary>
public string DeviceVersionKey { get; set; }
}
}

+ 41
- 0
BPA.SAAS.Manage.Application/Device/Dtos/Device/DeviceInfoQueryDto.cs View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.SAAS.Manage.Application.Device.Dtos.Device
{
public class DeviceInfoQueryDto
{
public string Id { get; set; }
/// <summary>
/// 设备名称
/// </summary>
public string DeviceName { get; set; }

/// <summary>
/// 设备标签
/// </summary>
public string DeviceTypeId { get; set; }
/// <summary>
///归属场景(店铺)
/// </summary>
public string OrgId { get; set; }
/// <summary>
/// 设备类型
/// </summary>
public string DeviceTypeKey { get; set; }
/// <summary>
/// 设备AutoKey 唯一用于mqtt消息推送标识
/// </summary>
[SugarColumn(IsOnlyIgnoreInsert = true, IsOnlyIgnoreUpdate = true, IsIdentity = true)]
public int AutoKey { get; set; }
/// <summary>
/// 设备版本
/// </summary>
public string DeviceVersionKey { get; set; }
public string OrgKey { get; set; }
public string DeviceVersionName { get; set; }
}
}

+ 18
- 0
BPA.SAAS.Manage.Application/Device/Dtos/Device/DeviceQueryInputDto.cs View File

@@ -0,0 +1,18 @@
using BPA.SAAS.Manage.Core.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.SAAS.Manage.Application.Device.Dtos.Device
{
public class DeviceQueryInputDto : PageInputBase
{
public string DeviceName { get; set; }
public string StoreId { get; set; }
public string DeviceTypeId { get; set; }

public int? Status { get; set; }
}
}

+ 18
- 0
BPA.SAAS.Manage.Application/Device/Interface/IDeviceService.cs View File

@@ -0,0 +1,18 @@
using BPA.SAAS.Manage.Application.Device.Dtos.Device;
using BPA.SAAS.Manage.Core.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.SAAS.Manage.Application.Device.Interface
{
public interface IDeviceService
{
Task<PageUtil> GetDeviceInfoPage(DeviceQueryInputDto inputDto);
Task<bool> AddDevice(DeviceInfoBaseDto inputDto);
Task<bool> UpdateDevice(DeviceInfoBaseDto inputDto);
Task<bool> DelDeviceInfo(List<string> inputList);
}
}

+ 142
- 0
BPA.SAAS.Manage.Application/Device/Services/DeviceService.cs View File

@@ -0,0 +1,142 @@
using BPA.SAAS.Manage.Application.Device.Dtos.Device;
using BPA.SAAS.Manage.Application.Device.Interface;
using BPA.SAAS.Manage.Comm.Const;
using BPA.SAAS.Manage.Comm.Util;
using BPA.SAAS.Manage.Core.Base;
using BPA.SAAS.Manage.Core.Device;
using BPA.SAAS.Manage.Core.Org;
using BPA.SAAS.Manage.Core.system;
using Dm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.SAAS.Manage.Application.Device.Services
{
public class DeviceService: IDeviceService, ITransient
{
ISqlSugarClient _db;
public DeviceService(ISqlSugarClient db)
{
_db=db;
}
/// <summary>
/// 分页查询
/// </summary>
/// <param name="inputDto"></param>
/// <returns></returns>
public async Task<PageUtil> GetDeviceInfoPage(DeviceQueryInputDto inputDto)
{
RefAsync<int> total =0;
var data = await _db.Queryable<BPA_DeviceInfo, BPA_Organize>((a, b) =>
new JoinQueryInfos(JoinType.Inner, a.OrgId == b.Id))
.WhereIF(!string.IsNullOrWhiteSpace(inputDto.StoreId), a => a.OrgId == inputDto.StoreId)
.WhereIF(!string.IsNullOrWhiteSpace(inputDto.DeviceName), a => a.DeviceName.Contains(inputDto.DeviceName))
.WhereIF(!string.IsNullOrWhiteSpace(inputDto.DeviceTypeId), a => a.DeviceTypeId == inputDto.DeviceTypeId)
.OrderBy((a, b) => a.CreateAt, OrderByType.Desc)
.Select((a, b) => new DeviceInfoQueryDto
{
Id = a.Id.SelectAll(),
OrgKey = b.AutoKey,
DeviceVersionName = ""
})
.Mapper(x =>
{
var Vesion = _db.Queryable<BPA_DeviceVesion>().Where(c => c.Id == x.DeviceVersionKey).First();
x.DeviceVersionName = Vesion?.Vesion;
})
.ToPageListAsync(inputDto.Current, inputDto.PageSize, total);
return new PageUtil()
{
Data = data,
Total = total
};
}
/// <summary>
/// 添加
/// </summary>
/// <param name="inputDto"></param>
/// <returns></returns>
public async Task<bool> AddDevice(DeviceInfoBaseDto inputDto)
{
BPA_DeviceInfo bPA_DeviceInfo = inputDto.Adapt<BPA_DeviceInfo>();
var res =await _db.Insertable(bPA_DeviceInfo) .CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync();
mqttsub(res.AutoKey, res.DeviceTypeKey);
return res != null;
}
/// <summary>
/// 更新
/// </summary>
/// <param name="inputDto"></param>
/// <returns></returns>
public async Task<bool> UpdateDevice(DeviceInfoBaseDto inputDto)
{
var data = await _db.Queryable<BPA_DeviceInfo>().Where(x => x.Id == inputDto.Id).FirstAsync();

if (data != null)
{
mqttsub(data.AutoKey, data.DeviceTypeKey);
var inputData = inputDto.Adapt<BPA_DeviceInfo>();
inputData.CreateBy = data.CreateBy;
var res = await _db.Updateable(inputData)
.UpdateColumns(x => new
{
x.DeviceName,
x.DeviceTypeId,
x.OrgId,
x.DeviceTypeKey,
x.Status,
x.DeviceVersionKey
})
.Where(x => x.Id == inputDto.Id).ExecuteCommandAsync();
return res > 0;
}
return false;
}
/// <summary>
/// 删除
/// </summary>
/// <param name="inputList"></param>
/// <returns></returns>
public async Task<bool> DelDeviceInfo(List<string> inputList)
{
var data = await _db.Queryable<BPA_DeviceInfo>().Where(x => inputList.Contains(x.Id)).ToListAsync();
foreach (var item in data)
{
item.IsDeleted = 1;
}
var res = await _db.Updateable(data) .ExecuteCommandAsync();
return res > 0;
}
/// <summary>
/// (调用订单服务)
/// </summary>
/// <param name="AutoKey"></param>
/// <param name="DeviceTypeKey"></param>
/// <returns></returns>
private bool mqttsub(int AutoKey, string DeviceTypeKey)
{

var list = _db.Queryable<BPA_DictData>().Where(x => x.Code == "SubDevice")
.Select(x => x.Value).ToList();
if (!list.Contains(DeviceTypeKey)) return true;
var url = Utiily.OrderUrl + Utiily.newmqttsub + $"/{DeviceTypeKey}/{AutoKey}";

try
{
Utiily.HttpGet(url, "");
}
catch (Exception e)
{
throw Oops.Oh($"调用订单服务:{url}" + e.Message);
// BPALog.WriteLog($"调用订单服务:{url}" + e.Message, LogEnum.Error);
}
Console.WriteLine($"调用订单服务:{url},调用成功");
// BPALog.WriteLog($"调用订单服务:{url},调用成功");
return true;
}
}
}

+ 1
- 0
BPA.SAAS.Manage.Comm/BPA.SAAS.Manage.Comm.csproj View File

@@ -7,6 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Furion.Pure" Version="4.9.1.20" />
<PackageReference Include="Npoi.Mapper" Version="6.2.1" />
</ItemGroup>



+ 18
- 0
BPA.SAAS.Manage.Comm/Model/ResultEntity.cs View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.SAAS.Manage.Comm.Model
{
public class ResultEntity<T>
{

public bool IsSuccess { get; set; }

public string Msg { get; set; }

public T Data { get; set; }
}
}

+ 219
- 0
BPA.SAAS.Manage.Comm/Util/Utiily.cs View File

@@ -0,0 +1,219 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Furion;
using BPA.SAAS.Manage.Comm.Model;
using Newtonsoft.Json;

namespace BPA.SAAS.Manage.Comm.Util
{
public class Utiily
{
public static string OrderUrl = App.Configuration["order_url"];

public static string WechatUrl = App.Configuration["wechat_url"];





//public static string OrderUrl = "http://order.dev1.com";//

//public static string WechatUrl = "http://wechat.dev1.com";//


/// <summary>
/// 设备订阅
/// </summary>
public const string newmqttsub = "/Mqtt/newmqttsub";

/// <summary>
/// 打印小票
/// </summary>
public const string PrintTicket = "/order/print/printtickets";

/// <summary>
/// 新增要货单
/// </summary>
public const string Addrequiregoods = "/api/requiregoodsapplication";

/// <summary>
/// 获取配送信息
/// </summary>
public const string GetDeliveryentry = "/api/deliveryapplication/deliveryentry/";


/// <summary>
/// 新增差异单
/// </summary>
public const string AddCostpriceadjust = "/api/costpriceadjustapplication";

/// <summary>
/// 获取组织
/// </summary>
public const string GetOrg = "/api/baseapplication/orglist/";

/// <summary>
/// 获取供应商
/// </summary>
public const string GetSupplier = "/api/purchaseapplyapplication/supplier/";


/// <summary>
///订单售后
/// </summary>
public const string agreerefundUrl = "/order/agreerefund";


/// <summary>
/// 微信退款
/// </summary>
public const string wechatrefundurl = "/api/wechat/wechatrefund";

/// <summary>
/// 加盟商
/// </summary>
public static string Supplier { get; set; }

/// <summary>
/// 代理服务
/// </summary>
public static string Proxy { get; set; }

public static string HttpPost(string url, string postData, Encoding encoding, string authorize = "")
{
try
{
HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create(url);
myReq.Method = "POST";
myReq.Timeout = 600 * 60;
if (!string.IsNullOrWhiteSpace(authorize))
{
myReq.Headers.Add("Authorize", authorize);
}
byte[] byteArray = encoding.GetBytes(postData);
myReq.ContentType = "application/json-patch+json";
Stream dataStream = myReq.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();

HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse();
dataStream = HttpWResp.GetResponseStream();
string result = "";
using (StreamReader myStreamReader = new StreamReader(dataStream, encoding))
{
result = myStreamReader.ReadToEnd();
myStreamReader.Close();
}
dataStream.Close();
HttpWResp.Close();
// BPALog.WriteLog("post请求:" + $"【url:{url}】【data:{postData}】", LogEnum.Info, null);
return result;
}
catch (System.Exception ex)
{
//BPALog.WriteLog("post请求:" + $"【url:{url}】【data:{postData}】", LogEnum.Error, null, ex);
throw;
}
}


public static string HttpGet(string url, string postDataStr)
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url + postDataStr);
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
string retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();
// BPALog.WriteLog("post请求:" + $"【url:{url}】【data:{postDataStr}】", LogEnum.Info, null);
return retString;
}
catch (Exception ex)
{

//BPALog.WriteLog("post请求:" + $"【url:{url}】【data:{postDataStr}】", LogEnum.Error, null, ex);
throw;
}


}
public static ResultEntity<T> Post<T>(string url, object param, bool UseUnify = true, bool HasResult = true)
{
try
{
HttpClientHandler handler = new HttpClientHandler();
handler.ServerCertificateCustomValidationCallback = (a, b, c, d) => { return true; };
HttpClient client = new HttpClient(handler);
HttpContent content = new StringContent(JsonConvert.SerializeObject(param));
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
if (HasResult)
{
var res = client.PostAsync(Supplier + url, content).Result.Content.ReadAsStringAsync().Result;
if (UseUnify == false)
{
return new ResultEntity<T>
{
Data = default,
IsSuccess = bool.Parse(res),
Msg = string.Empty
};
}
return JsonConvert.DeserializeObject<ResultEntity<T>>(res);// res.FromJSON<ResultEntity<T>>();
}
else
{
client.PostAsync(url, content);
return default;
}
}
catch (Exception ex)
{
return new ResultEntity<T>
{
Data = default,
IsSuccess = false,
Msg = ex.Message
};
}
}

public static ResultEntity<T> Get<T>(string url, string param, bool HasResult = true)
{
try
{
HttpClient client = new HttpClient();
if (HasResult)
{
var res = client.GetAsync(Supplier + url + param).Result.Content.ReadAsStringAsync().Result;
return JsonConvert.DeserializeObject<ResultEntity<T>>(res);// res.FromJSON<ResultEntity<T>>();
}
else
{
client.GetAsync(Proxy + url + param);
return default;
}
}
catch (Exception ex)
{
return new ResultEntity<T>
{
Data = default,
IsSuccess = false,
Msg = ex.Message
};
}

}

}
}

+ 0
- 1
BPA.SAAS.Manage.Core/BPA.SAAS.Manage.Core.csproj View File

@@ -16,7 +16,6 @@
<ItemGroup>
<PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.8.8.5" />
<PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.8.8.5" />
<PackageReference Include="Furion.Pure" Version="4.8.8.5" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.67" />
</ItemGroup>



+ 7
- 1
BPA.SAAS.Manage.Core/Device/BPA_DeviceInfo.cs View File

@@ -1,4 +1,5 @@
using BPA.SAAS.Manage.Core.Base;
using BPA.SAAS.Manage.Comm.Enum;
using BPA.SAAS.Manage.Core.Base;
using SqlSugar;
using System;
using System.Collections.Generic;
@@ -31,6 +32,11 @@ namespace BPA.SAAS.Manage.Core.Device
/// </summary>
public string DeviceTypeKey { get; set; }
/// <summary>
/// 状态 【正常 停用】默认 正常
/// </summary>
[SugarColumn(ColumnDataType = "int", ColumnDescription = "状态", IsNullable = false)]
public CommonStatus Status { get; set; } = CommonStatus.ENABLE;
/// <summary>
/// 设备AutoKey 唯一用于mqtt消息推送标识
/// </summary>
[SugarColumn(IsOnlyIgnoreInsert = true, IsOnlyIgnoreUpdate = true, IsIdentity = true)]


+ 3
- 1
BPA.SAAS.Manage.Web.Entry/appsettings.json View File

@@ -22,5 +22,7 @@
"Bucket": "hbl-test-1305371387",
"SecretId": "AKIDa4KQIvKUP6bw4ye6JI3a8lCPN7cswnV3",
"SecretKey": "ObaLtCH9nCNPFrFQO7ex2sTqyxlLgnfJ"
}
},
"order_url": "http://order",
"wechat_url": "http://wechat"
}

Loading…
Cancel
Save