2021-07-29 19:10:19 +08:00
|
|
|
|
using Furion.DynamicApiController;
|
2021-08-01 15:25:01 +08:00
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
using Microsoft.AspNetCore.Http.Features;
|
2021-07-29 19:10:19 +08:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2021-08-01 15:25:01 +08:00
|
|
|
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
|
|
|
|
|
using Microsoft.AspNetCore.WebUtilities;
|
|
|
|
|
|
using Microsoft.Net.Http.Headers;
|
2021-07-29 19:10:19 +08:00
|
|
|
|
using Nirvana.Common;
|
2021-08-01 15:25:01 +08:00
|
|
|
|
using Nirvana.Common.File;
|
2021-07-29 19:10:19 +08:00
|
|
|
|
using System;
|
2022-08-24 10:19:21 +08:00
|
|
|
|
using System.Collections.Generic;
|
2021-08-01 15:25:01 +08:00
|
|
|
|
using System.IO;
|
2021-07-29 19:10:19 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2021-09-30 09:27:59 +08:00
|
|
|
|
using Waste.Application.SubscribeInfo;
|
2025-03-27 13:34:16 +08:00
|
|
|
|
using Waste.Domain.DataModel;
|
2021-07-29 19:10:19 +08:00
|
|
|
|
|
|
|
|
|
|
namespace Waste.Application.ThirdApiInfo
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 开放数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[ApiDescriptionSettings("DevApi")]
|
2021-07-30 18:15:58 +08:00
|
|
|
|
[NonUnify]
|
2021-07-29 19:10:19 +08:00
|
|
|
|
public class OpenAppService : IDynamicApiController
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly IOpenService _openService;
|
2021-08-01 15:25:01 +08:00
|
|
|
|
private static IWebHostEnvironment _hostingEnvironment;
|
|
|
|
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
|
|
|
|
private static readonly FormOptions _defaultFormOptions = new FormOptions();
|
2022-07-12 17:53:04 +08:00
|
|
|
|
|
2021-08-01 15:25:01 +08:00
|
|
|
|
public OpenAppService(IOpenService openService, IWebHostEnvironment webHostEnvironment, IHttpContextAccessor httpContextAccessor)
|
2021-07-29 19:10:19 +08:00
|
|
|
|
{
|
|
|
|
|
|
_openService = openService;
|
2021-08-01 15:25:01 +08:00
|
|
|
|
_hostingEnvironment = webHostEnvironment;
|
|
|
|
|
|
_httpContextAccessor = httpContextAccessor;
|
2021-07-29 19:10:19 +08:00
|
|
|
|
}
|
2022-07-12 17:53:04 +08:00
|
|
|
|
|
2021-07-29 19:10:19 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取设备上报相关信息
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="data"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
public async Task<ResultInfo> GetDevInfoAsync(GetDevInfoRequestDto data)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await _openService.GetDevInfoAsync(data);
|
|
|
|
|
|
}
|
2021-07-30 18:15:58 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 心跳数据上报
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="data"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
public async Task<ResultInfo> PostHeartAsync(DevHeartRequestDto data)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await _openService.PostHeartAsync(data);
|
|
|
|
|
|
}
|
2022-07-12 17:53:04 +08:00
|
|
|
|
|
2021-07-30 18:15:58 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取设备注册信息,第一次开机使用
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="ecode"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
|
[QueryParameters]
|
|
|
|
|
|
public async Task<ResultInfo> RegInfoAsync(string ecode)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await _openService.RegInfoAsync(ecode);
|
|
|
|
|
|
}
|
2022-07-12 17:53:04 +08:00
|
|
|
|
|
2021-08-13 19:34:39 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 更新上报状态
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="data"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
public async Task<ResultInfo> UpdateStatusAsync(UpdateStatusDto data)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await _openService.UpdateStatusAsync(data);
|
|
|
|
|
|
}
|
2021-08-01 15:25:01 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// BUG上报
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
[Route("api/reportbug/Post")]
|
2021-09-30 09:27:59 +08:00
|
|
|
|
public async Task<object> PostAsync([FromQuery] string ecode = "")
|
2021-08-01 15:25:01 +08:00
|
|
|
|
{
|
|
|
|
|
|
var Request = _httpContextAccessor.HttpContext.Request;
|
|
|
|
|
|
//先保存上传的图片
|
|
|
|
|
|
if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType))
|
|
|
|
|
|
{
|
|
|
|
|
|
return new
|
|
|
|
|
|
{
|
|
|
|
|
|
status = new
|
|
|
|
|
|
{
|
|
|
|
|
|
code = 0,
|
|
|
|
|
|
name = "FAIL",
|
|
|
|
|
|
message = "上传失败"
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
var boundary = MultipartRequestHelper.GetBoundary(MediaTypeHeaderValue.Parse(Request.ContentType), _defaultFormOptions.MultipartBoundaryLengthLimit);
|
|
|
|
|
|
var reader = new MultipartReader(boundary, Request.Body);
|
|
|
|
|
|
var section = await reader.ReadNextSectionAsync();
|
2022-08-24 10:19:21 +08:00
|
|
|
|
while (section != null)
|
2021-08-01 15:25:01 +08:00
|
|
|
|
{
|
|
|
|
|
|
var hasContentDispositionHeader =
|
|
|
|
|
|
ContentDispositionHeaderValue.TryParse(
|
|
|
|
|
|
section.ContentDisposition, out var contentDisposition);
|
|
|
|
|
|
if (hasContentDispositionHeader)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!MultipartRequestHelper.HasFileContentDisposition(contentDisposition))
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2021-09-30 09:27:59 +08:00
|
|
|
|
string[] _permittedExtensions = { };
|
2021-08-01 15:25:01 +08:00
|
|
|
|
long _fileSizeLimit = 1048576 * 10;
|
|
|
|
|
|
string rootname = $"/bugs/{DateTime.Now.ToString("yyyyMMdd")}";
|
|
|
|
|
|
string savefolder = _hostingEnvironment.WebRootPath;
|
|
|
|
|
|
|
|
|
|
|
|
ModelStateDictionary modelState = new ModelStateDictionary();
|
|
|
|
|
|
var streameFileData = await FileHelpers.ApiProcessStreamedFile(
|
|
|
|
|
|
section, contentDisposition, modelState,
|
|
|
|
|
|
_permittedExtensions, _fileSizeLimit);
|
|
|
|
|
|
var streamedFileContent = streameFileData.data;
|
|
|
|
|
|
modelState = streameFileData.modelState;
|
|
|
|
|
|
if (!modelState.IsValid)
|
|
|
|
|
|
{
|
|
|
|
|
|
string msg = "上传失败";
|
|
|
|
|
|
if (modelState.Values.Count() > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
msg = modelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage;
|
|
|
|
|
|
}
|
|
|
|
|
|
return new
|
|
|
|
|
|
{
|
|
|
|
|
|
status = new
|
|
|
|
|
|
{
|
|
|
|
|
|
code = 0,
|
|
|
|
|
|
name = "FAIL",
|
|
|
|
|
|
message = msg
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
var name = $"{Path.GetRandomFileName()}{Path.GetExtension(contentDisposition.FileName.Value)}";
|
|
|
|
|
|
if (!string.IsNullOrEmpty(ecode))
|
|
|
|
|
|
{
|
|
|
|
|
|
name = $"{ecode}_{name}";
|
|
|
|
|
|
}
|
|
|
|
|
|
var thumbnailPath = Path.Combine(savefolder + "/" + rootname, name);
|
|
|
|
|
|
if (!Directory.Exists(Path.GetDirectoryName(thumbnailPath)))
|
|
|
|
|
|
{
|
|
|
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(thumbnailPath));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
//检查文件是否存在
|
|
|
|
|
|
if (System.IO.File.Exists(thumbnailPath))
|
|
|
|
|
|
{
|
|
|
|
|
|
return new
|
|
|
|
|
|
{
|
|
|
|
|
|
status = new
|
|
|
|
|
|
{
|
|
|
|
|
|
code = 0,
|
|
|
|
|
|
name = "FAIL",
|
|
|
|
|
|
message = "此文件已存在"
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
var filepath = Path.Combine("wwwroot" + rootname + "/", name);
|
|
|
|
|
|
var filename = contentDisposition.FileName.Value;
|
|
|
|
|
|
using (var targetStream = File.Create(filepath))
|
|
|
|
|
|
{
|
|
|
|
|
|
await targetStream.WriteAsync(streamedFileContent);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return new
|
|
|
|
|
|
{
|
|
|
|
|
|
status = new
|
|
|
|
|
|
{
|
|
|
|
|
|
code = 1,
|
|
|
|
|
|
name = "SUCCESS",
|
|
|
|
|
|
message = ""
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-02 17:48:22 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// BUG上报
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
[Route("api/reportbug/postbug")]
|
2021-09-30 09:27:59 +08:00
|
|
|
|
public object PostBug(BugModel bug)
|
2021-08-02 17:48:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
var errmsg = $"机器码:{bug.ecode},位置:{bug.ExceptionPos},信息:{bug.ExceptionInfo}";
|
|
|
|
|
|
return new
|
|
|
|
|
|
{
|
|
|
|
|
|
status = new
|
|
|
|
|
|
{
|
|
|
|
|
|
code = 1,
|
|
|
|
|
|
name = "SUCCESS",
|
|
|
|
|
|
message = ""
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2022-07-12 17:53:04 +08:00
|
|
|
|
|
2021-08-01 15:25:01 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 正式升级
|
|
|
|
|
|
/// </summary>
|
2021-08-05 18:34:28 +08:00
|
|
|
|
/// <param name="ecode">机器码</param>
|
|
|
|
|
|
/// <param name="myver">版本号</param>
|
|
|
|
|
|
/// <param name="type">类型</param>
|
2021-08-01 15:25:01 +08:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
|
[QueryParameters]
|
|
|
|
|
|
[Route("api/upgrade/get")]
|
2021-09-30 09:27:59 +08:00
|
|
|
|
public async Task<object> GetAsync(string type, string ecode = "", int myver = 400)
|
2021-08-01 15:25:01 +08:00
|
|
|
|
{
|
2021-09-30 09:27:59 +08:00
|
|
|
|
await _openService.UpdateVersionAsync(new DeviceVerS2SDto
|
|
|
|
|
|
{
|
|
|
|
|
|
ecode = ecode,
|
|
|
|
|
|
ver = myver.ToString()
|
|
|
|
|
|
});
|
2021-08-01 15:25:01 +08:00
|
|
|
|
string rootpath = _hostingEnvironment.WebRootPath;
|
|
|
|
|
|
//读取文件,返回升级信息
|
|
|
|
|
|
var path = $"{rootpath}/apks/upgrade/{type}.txt";
|
2022-08-24 10:19:21 +08:00
|
|
|
|
var ulist = new List<string> { "419b553e92986112", "8f259824aef42c36", "fa324b8fa8da1fc0", "be6d6ef03519d42e", "352050657b2b2608", "d3fc9a38d7f67604" };
|
|
|
|
|
|
if (ulist.Contains(ecode))
|
2022-07-26 10:36:34 +08:00
|
|
|
|
{
|
|
|
|
|
|
path = $"{rootpath}/apks/upgrade/OTHER.txt";
|
|
|
|
|
|
}
|
2021-08-01 15:25:01 +08:00
|
|
|
|
if (!File.Exists(path))
|
|
|
|
|
|
{
|
|
|
|
|
|
return new
|
|
|
|
|
|
{
|
|
|
|
|
|
status = new
|
|
|
|
|
|
{
|
|
|
|
|
|
code = 0,
|
|
|
|
|
|
name = "FAIL",
|
|
|
|
|
|
message = "不存在任何信息"
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
FileStream fileStream = new FileStream(path, FileMode.Open);
|
|
|
|
|
|
string result = string.Empty;
|
|
|
|
|
|
using (StreamReader reader = new StreamReader(fileStream))
|
|
|
|
|
|
{
|
|
|
|
|
|
result = await reader.ReadToEndAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (string.IsNullOrEmpty(result))
|
|
|
|
|
|
{
|
|
|
|
|
|
return new
|
|
|
|
|
|
{
|
|
|
|
|
|
status = new
|
|
|
|
|
|
{
|
|
|
|
|
|
code = 0,
|
|
|
|
|
|
name = "FAIL",
|
|
|
|
|
|
message = "不存在任何信息"
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
return result.ToJson();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取机器到期时间
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="ecode"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
|
[QueryParameters]
|
|
|
|
|
|
[Route("api/machine/getisenable")]
|
|
|
|
|
|
public Object GetIsEnable(string ecode)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(ecode))
|
|
|
|
|
|
{
|
|
|
|
|
|
return new
|
|
|
|
|
|
{
|
|
|
|
|
|
status = new
|
|
|
|
|
|
{
|
|
|
|
|
|
code = 0,
|
|
|
|
|
|
name = "FAIL",
|
|
|
|
|
|
message = "参数错误"
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
return new
|
|
|
|
|
|
{
|
|
|
|
|
|
status = new
|
|
|
|
|
|
{
|
|
|
|
|
|
code = 1,
|
|
|
|
|
|
name = "SUCCESS",
|
|
|
|
|
|
message = ""
|
2021-08-02 17:48:22 +08:00
|
|
|
|
},
|
|
|
|
|
|
data = new
|
|
|
|
|
|
{
|
|
|
|
|
|
isenable = true,
|
|
|
|
|
|
deadline = DateTime.Now.AddYears(2).ToString("yyyy-MM-dd")
|
2021-08-01 15:25:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2022-03-28 17:19:48 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 通过ailink wifi模式发送的数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="data"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task<object> WifiAsync(WifiRequestC2SDto data)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await _openService.WifiPostAsync(data);
|
|
|
|
|
|
}
|
2025-03-27 13:34:16 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 新增电子秤
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="data"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
public async Task<ResultInfo> AddProductAsync(ProductInfoDto data)
|
|
|
|
|
|
{
|
2026-03-31 14:11:44 +08:00
|
|
|
|
// 1. 检查权限(false 直接返回无权限)
|
|
|
|
|
|
if (!data.uploadPermission) // 等效于 data.uploadPermission == false
|
|
|
|
|
|
{
|
|
|
|
|
|
return new ResultInfo(ResultState.FAIL, "没有操作权限");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-27 13:34:16 +08:00
|
|
|
|
return await _openService.AddProductAsync(data);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
public async Task<PageParms<W_Product>> GetProductAsync(QueryParams param)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await _openService.GetProductAsync(param);
|
|
|
|
|
|
}
|
2026-03-31 14:11:44 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 删除产品数据(管理后台专用,无需权限校验)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
[Route("api/open/deleteproduct")]
|
|
|
|
|
|
public async Task<ResultInfo> DeleteProduct(string id)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 1. 检查ID是否为空
|
|
|
|
|
|
if (string.IsNullOrEmpty(id))
|
|
|
|
|
|
{
|
|
|
|
|
|
return new ResultInfo(ResultState.FAIL, "ID不能为空");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 调用删除服务
|
|
|
|
|
|
return await _openService.DeleteProductAsync(id);
|
|
|
|
|
|
}
|
2021-07-29 19:10:19 +08:00
|
|
|
|
}
|
2022-07-12 17:53:04 +08:00
|
|
|
|
}
|