Commit 182d6cbf by zxw

大屏调用接口转发主平台

调整定时任务调用的数据库模式
parent 5c9dc64a
......@@ -2085,6 +2085,157 @@ namespace JunmpPoliceStation.Controllers
}
/// <summary>
/// 通过箱标/件标epc获取件标epc(混装 智能货架使用)
/// </summary>
/// <remarks>
///
/// ## 例子
///
/// {
/// "epcList":[
/// {"epc":"箱标/件标epc"},
/// {"epc":"箱标/件标epc"},
/// ]
///
/// }
///
/// </remarks>
/// <param name="jdata"></param>
/// <returns></returns>
[HttpPost("GetEpcListByEpc")]
public async Task<HttpResponseMessage> GetEpcListByEpc([FromBody] JObject jdata)
{
return await Task.Run(() =>
{
try
{
if (jdata != null)
{
var entity = JsonManager.GetJsonEntity(jdata);
Expression<Func<CommonJpEquipmentBoxMark, bool>> xbExpression = t => t.ReloadBoxingState != 1;
Expression<Func<CommonJpEquipmentInventory, bool>> jbExpression = t => t.InventoryState != "loss" && t.CurrentState == 0;
var xbEpcList = new List<string>();
var jbEpcList = new List<string>();
foreach (var epc in entity.epcList)
{
if (!string.IsNullOrEmpty(epc.epc))
{
if (epc.epc.Length == 24)
{
//旧版箱标
xbEpcList.Add(epc.epc);
continue;
}
var buffer = EpcConvert.ToHexByte(epc.epc);
var epc_info = EpcConvert.EpcAnlysing(buffer);
if (epc_info.TagType == 0x00)
{
//件标
jbEpcList.Add(epc.epc);
}
else
{
xbEpcList.Add(epc.epc);
}
}
}
if (xbEpcList.Count == 0 && jbEpcList.Count == 0)
{
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
}
xbExpression = xbExpression.AndAlso(x => xbEpcList.Contains(x.Epc) || xbEpcList.Contains(x.OldEpc));
jbExpression = jbExpression.AndAlso(x => jbEpcList.Contains(x.Epc));
var param = new string[] {
"Warehouse",
"EquipmentDetail",
"Size",
"Supplier",
"CommonJpEquipmentInventories"
};
var param2 = new string[] {
"WarehouseCodeNavigation",
"EquipmentCodeNavigation",
"EquipmentSizecodeNavigation",
"SupplierCodeNavigation",
};
var data = _unitOfWork.EquipmentBoxMarkRepository.GetList(xbExpression, includes: param).ToList();
var data2 = _unitOfWork.EquipmentInventoryRepository.GetList(jbExpression, includes: param2).ToList();
var res = new List<object>();
res.AddRange(data.Select(x =>
new
{
id = x.Id,
createTime = x.CreateTime,
epc = x.Epc,
oneBoxNum = x.OneBoxNum,
warehouseId = x.WarehouseId,
warehouseName = x.Warehouse.Name,
orgizationId = x.Warehouse.OrgizationId,
equipmentInfoId = x.EquipmentDetail.EquipmentId,
equipmentDetailId = x.EquipmentDetailId,
equipmentDetailName = x.EquipmentDetail.Name,
equipmentDetailCode = x.EquipmentDetail.Code,
sizeId = x.SizeId,
sizeName = x.Size.SizeName,
sizeCode = x.Size.SizeCode,
sizeEpcType = x.Size.EpcType,
supplierId = x.SupplierId,
supplierCode = x.Supplier.SupplierCode,
supplierName = x.Supplier.Name,
oldEpc = x.OldEpc,
epcList = x.CommonJpEquipmentInventories.Select(y => y.Epc)
}).ToList());
res.AddRange(data2.Select(x =>
new
{
id = x.Id,
createTime = x.CreateTime,
epc = x.Epc,
oneBoxNum = 1,
warehouseId = x.WarehouseCode,
warehouseName = x.WarehouseCodeNavigation.Name,
orgizationId = x.WarehouseCodeNavigation.OrgizationId,
equipmentInfoId = x.EquipmentCodeNavigation.EquipmentId,
equipmentDetailId = x.EquipmentCode,
equipmentDetailName = x.EquipmentCodeNavigation.Name,
equipmentDetailCode = x.EquipmentCodeNavigation.Code,
sizeId = x.EquipmentSizecode,
sizeName = x.EquipmentSizecodeNavigation.SizeName,
sizeCode = x.EquipmentSizecodeNavigation.SizeCode,
sizeEpcType = x.EquipmentSizecodeNavigation.EpcType,
supplierId = x.SupplierCode,
supplierCode = x.SupplierCodeNavigation.SupplierCode,
supplierName = x.SupplierCodeNavigation.Name,
oldEpc = (string)null,
epcList = new List<string>() { x.Epc }
}).ToList());
return JsonManager.ReturnSuccessResponse(res);
}
else
{
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
}
}
catch (Exception ex)
{
//_logger.LogError("Login/SignIn 错误:" + ex.ToString());
return JsonManager.SimpleStatusResponse(ResultCode.OPERATE_FAILED);
}
});
}
/// <summary>
/// 根据装备包实例id获取物资出入流水记录
/// </summary>
/// <remarks>
......
......@@ -3,6 +3,7 @@ using JmpCommon.Tools;
using JmpModel.Model;
using JmpModel.Model.Repository;
using JunmpPoliceStation.App_Start;
using JunmpPoliceStation.Extensions;
using JunmpPoliceStation.Models.Repository;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
......@@ -15,8 +16,10 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Net;
using System.Net.Http;
using System.Net.WebSockets;
using System.Text;
using System.Threading.Tasks;
namespace JunmpPoliceStation.Controllers
......@@ -29,12 +32,14 @@ namespace JunmpPoliceStation.Controllers
//private ICabinetRepository _CabinetRepository;
private ILogger<ViewController> _logger;
UnitOfWork _unitOfWork;
private HttpHelper _httpHelper;
public ViewController(ILogger<ViewController> logger, UnitOfWork unitOfWork)
public ViewController(ILogger<ViewController> logger, UnitOfWork unitOfWork, HttpHelper httpHelper)
{
_logger = logger;
//_CabinetRepository = CabinetRepository;
_unitOfWork = unitOfWork;
_httpHelper = httpHelper;
}
/// <summary>
......@@ -59,93 +64,26 @@ namespace JunmpPoliceStation.Controllers
{
try
{
if (jdata != null)
//转发主平台
var httpResult = _httpHelper.GetHtml(new HttpItem()
{
var entity = JsonManager.GetJsonEntity(jdata);
//在库总量、领用总量、维修数量、报废总量、单警柜数、仓库数
int zkTopCount = 0;
int zkCount = 0;
int lyCount = 0;
int wxCount = 0;
int bfCount = 0;
int houseCount = 0;
var jjbfCount = 0;
string FindCode = entity.findCode;
Expression<Func<ViewEquipment, bool>> ViewEquipmentExpression = t => !t.OrgId.Equals(null);
string level = entity.level;
if (string.IsNullOrEmpty(level))
{
level = "本级及下级";
}
if (level == "本级")
{
ViewEquipmentExpression = t => t.OrgCode == FindCode.PadRight(12, '0') && t.ParentName != null;
}
else if (level == "本级及下级")
{
ViewEquipmentExpression = t => t.OrgCode.IndexOf(FindCode) == 0 && t.ParentName != null;
}
else
{
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
}
IQueryable<ViewEquipment> ViewEquipmentList = _unitOfWork.ViewEquipmentRepository.GetArray(ViewEquipmentExpression, t => t.FindCode, false);
//在库总量
zkTopCount = ViewEquipmentList.Count();
if (!String.IsNullOrEmpty(entity.name))
{
string parentName = entity.name;
zkCount = ViewEquipmentList.Where(c => c.ParentName.Equals(parentName) && (c.CurrentState.Equals(0) || c.CurrentState.Equals(3))).Count();
//调拨数量
houseCount = ViewEquipmentList.Where(c => c.ParentName.Equals(parentName) && c.CurrentState.Equals(1)).Count();
//领用总量
lyCount = ViewEquipmentList.Where(c => c.ParentName.Equals(parentName) && !(c.CurrentState.Equals(0) || c.CurrentState.Equals(3) || c.CurrentState.Equals(1) || c.CurrentState.Equals(4) || c.CurrentState.Equals(6))).Count();
//维修数量
wxCount = ViewEquipmentList.Where(c => c.ParentName.Equals(parentName) && c.CurrentState.Equals(4)).Count();
//报废总量
bfCount = ViewEquipmentList.Where(c => c.ParentName.Equals(parentName) && c.CurrentState.Equals(6)).Count();
//即将报废
jjbfCount = ViewEquipmentList.Where(c => c.ParentName.Equals(parentName) && c.SafeLevel.Equals(1) && !c.CurrentState.Equals(6)).Count();
}
else
{
zkCount = ViewEquipmentList.Where(c => (c.CurrentState.Equals(0) || c.CurrentState.Equals(3))).Count();
//调拨数量
houseCount = ViewEquipmentList.Where(c => c.CurrentState.Equals(1)).Count();
//领用总量
lyCount = ViewEquipmentList.Where(c => !(c.CurrentState.Equals(0) || c.CurrentState.Equals(3) || c.CurrentState.Equals(1) || c.CurrentState.Equals(4) || c.CurrentState.Equals(6))).Count();
//维修数量
wxCount = ViewEquipmentList.Where(c => c.CurrentState.Equals(4)).Count();
//报废总量
bfCount = ViewEquipmentList.Where(c => c.CurrentState.Equals(6)).Count();
//即将报废
jjbfCount = ViewEquipmentList.Where(c => c.SafeLevel.Equals(1) && !c.CurrentState.Equals(6)).Count();
}
var reData = new { zkCount = zkCount, lyCount = lyCount, wxCount = wxCount, bfCount = bfCount, houseCount = houseCount, zkTopCount = zkTopCount, jjbfCount = jjbfCount };
return JsonManager.ReturnSuccessResponse(reData);
URL = _httpHelper._centerServerAddress + "/api/View/GetCount",
Encoding = Encoding.UTF8,
Method = "POST",
ContentType = "application/json",
Timeout = 5000,
Postdata = jdata.ToString()
});
if (httpResult.StatusCode != HttpStatusCode.OK || string.IsNullOrEmpty(httpResult.Html))
{
return JsonManager.SimpleCustResponse("远端上报数据失败");
}
else
var obj = JsonConvert.DeserializeObject<JmpBaseResponse<object>>(httpResult.Html);
if (obj.code != "10000")
{
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
return JsonManager.SimpleCustResponse(obj.msg);
}
return JsonManager.ReturnSuccessResponse(obj.data);
}
catch (Exception ex)
{
......@@ -318,45 +256,26 @@ namespace JunmpPoliceStation.Controllers
{
try
{
if (jdata != null)
//转发主平台
var httpResult = _httpHelper.GetHtml(new HttpItem()
{
var entity = JsonManager.GetJsonEntity(jdata);
Expression<Func<ViewEquipment, bool>> ViewEquipmentExpression = t => !t.OrgId.Equals(null);
string FindCode = entity.findCode;
string level = entity.level;
if (string.IsNullOrEmpty(level))
{
level = "本级及下级";
}
if (level == "本级")
{
ViewEquipmentExpression = t => t.OrgCode == FindCode.PadRight(12, '0') && t.ParentName != null && (t.CurrentState.Equals(0) || t.CurrentState.Equals(3));
}
else if (level == "本级及下级")
{
ViewEquipmentExpression = t => t.OrgCode.IndexOf(FindCode) == 0 && t.ParentName != null && (t.CurrentState.Equals(0) || t.CurrentState.Equals(3));
}
else
{
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
}
IQueryable<ViewEquipment> ViewEquipmentList = _unitOfWork.ViewEquipmentRepository.GetArray(ViewEquipmentExpression, t => t.FindCode, false);
var groupList = ViewEquipmentList.GroupBy(c => c.ParentName).Select(g => new { name = g.Key, value = g.Count() }).ToList();
return JsonManager.ReturnSuccessResponse(groupList);
URL = _httpHelper._centerServerAddress + "/api/View/GetGroupByCount",
Encoding = Encoding.UTF8,
Method = "POST",
ContentType = "application/json",
Timeout = 5000,
Postdata = jdata.ToString()
});
if (httpResult.StatusCode != HttpStatusCode.OK || string.IsNullOrEmpty(httpResult.Html))
{
return JsonManager.SimpleCustResponse("远端上报数据失败");
}
else
var obj = JsonConvert.DeserializeObject<JmpBaseResponse<object>>(httpResult.Html);
if (obj.code != "10000")
{
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
return JsonManager.SimpleCustResponse(obj.msg);
}
return JsonManager.ReturnSuccessResponse(obj.data);
}
catch (Exception ex)
{
......@@ -540,27 +459,26 @@ namespace JunmpPoliceStation.Controllers
{
try
{
if (jdata != null)
//转发主平台
var httpResult = _httpHelper.GetHtml(new HttpItem()
{
var entity = JsonManager.GetJsonEntity(jdata);
string FindCode = entity.findCode;
List<CSyP> data = _unitOfWork.ViewEquipmentRepository.Exec_ProP(" EXEC c_top5_sy_ps @p_findCode ='" + FindCode + "'").ToList();
List<Object> itemList = new List<object>();
for (var i = 0; i < data.Count; i++)
{
var item = new { id = i + 1, itemNum = data[i].MonthP, workUnit = data[i].ParentName };
itemList.Add(item);
}
return JsonManager.ReturnSuccessResponse(itemList);
URL = _httpHelper._centerServerAddress + "/api/View/GetTop5",
Encoding = Encoding.UTF8,
Method = "POST",
ContentType = "application/json",
Timeout = 5000,
Postdata = jdata.ToString()
});
if (httpResult.StatusCode != HttpStatusCode.OK || string.IsNullOrEmpty(httpResult.Html))
{
return JsonManager.SimpleCustResponse("远端上报数据失败");
}
else
var obj = JsonConvert.DeserializeObject<JmpBaseResponse<object>>(httpResult.Html);
if (obj.code != "10000")
{
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
return JsonManager.SimpleCustResponse(obj.msg);
}
return JsonManager.ReturnSuccessResponse(obj.data);
}
catch (Exception ex)
{
......@@ -596,120 +514,26 @@ namespace JunmpPoliceStation.Controllers
{
try
{
if (jdata != null)
//转发主平台
var httpResult = _httpHelper.GetHtml(new HttpItem()
{
var entity = JsonManager.GetJsonEntity(jdata);
string FindCode = entity.findCode;
List<CSyP> sydata = _unitOfWork.ViewEquipmentRepository.Exec_ProP("EXEC c_sy_ps @p_findCode ='" + FindCode + "'").ToList();
List<CSyP> wxdata = _unitOfWork.ViewEquipmentRepository.Exec_ProP("EXEC c_wx_p @p_findCode ='" + FindCode + "'").ToList();
List<CSyP> bfdata = _unitOfWork.ViewEquipmentRepository.Exec_ProP("EXEC c_bf_p @p_findCode ='" + FindCode + "'").ToList();
sydata = sydata.OrderBy(c => c.ParentName).ToList();
wxdata = wxdata.OrderBy(c => c.ParentName).ToList();
bfdata = bfdata.OrderBy(c => c.ParentName).ToList();
List<String> pList = new List<String>();
List<List<int>> dataType = new List<List<int>>();
for (var i = 0; i < sydata.Count; i++)
{
if (!pList.Contains(sydata[i].ParentName))
{
pList.Add(sydata[i].ParentName);
}
}
for (var i = 0; i < wxdata.Count; i++)
{
if (!pList.Contains(wxdata[i].ParentName))
{
pList.Add(wxdata[i].ParentName);
}
}
for (var i = 0; i < bfdata.Count; i++)
{
if (!pList.Contains(bfdata[i].ParentName))
{
pList.Add(bfdata[i].ParentName);
}
}
List<int> syList = new List<int>();
for (var i = 0; i < pList.Count; i++)
{
var flg = true;
for (var j = 0; j < sydata.Count; j++)
{
if (pList[i].Equals(sydata[j].ParentName))
{
syList.Add(int.Parse(sydata[i].MonthP.ToString()));
flg = false;
break;
}
}
if (flg)
{
syList.Add(0);
}
}
dataType.Add(syList);
List<int> wxList = new List<int>();
for (var i = 0; i < pList.Count; i++)
{
var flg = true;
for (var j = 0; j < wxdata.Count; j++)
{
if (pList[i].Equals(wxdata[j].ParentName))
{
wxList.Add(int.Parse(wxdata[i].WeekP.ToString()));
flg = false;
break;
}
}
if (flg)
{
wxList.Add(0);
}
}
dataType.Add(wxList);
List<int> bfList = new List<int>();
for (var i = 0; i < pList.Count; i++)
{
var flg = true;
for (var j = 0; j < bfdata.Count; j++)
{
if (pList[i].Equals(bfdata[j].ParentName))
{
bfList.Add(int.Parse(bfdata[i].WeekP.ToString()));
flg = false;
break;
}
}
if (flg)
{
bfList.Add(0);
}
}
dataType.Add(bfList);
var reData = new { pList = pList, dataType = dataType };
return JsonManager.ReturnSuccessResponse(reData);
URL = _httpHelper._centerServerAddress + "/api/View/GetSyWxBf",
Encoding = Encoding.UTF8,
Method = "POST",
ContentType = "application/json",
Timeout = 5000,
Postdata = jdata.ToString()
});
if (httpResult.StatusCode != HttpStatusCode.OK || string.IsNullOrEmpty(httpResult.Html))
{
return JsonManager.SimpleCustResponse("远端上报数据失败");
}
else
var obj = JsonConvert.DeserializeObject<JmpBaseResponse<object>>(httpResult.Html);
if (obj.code != "10000")
{
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
return JsonManager.SimpleCustResponse(obj.msg);
}
return JsonManager.ReturnSuccessResponse(obj.data);
}
catch (Exception ex)
{
......@@ -1057,95 +881,26 @@ namespace JunmpPoliceStation.Controllers
{
try
{
if (jdata != null)
//转发主平台
var httpResult = _httpHelper.GetHtml(new HttpItem()
{
var entity = JsonManager.GetJsonEntity(jdata);
string findcode = entity.findCode;
if (string.IsNullOrEmpty(findcode))
{
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
}
Expression<Func<ViewEquipment, bool>> expressionPoliceman = null;
expressionPoliceman = t => t.FindCode.Contains(findcode);
List<ViewEquipment> equipmentList = _unitOfWork.ViewEquipmentRepository.GetList(expressionPoliceman).OrderBy(c => c.FindCode.Length).ToList();
if (findcode.Length == 6)
{
var data = equipmentList.GroupBy(t => t.OrgName).Select(c => new
{
c.FirstOrDefault().OrgName,
c.FirstOrDefault().OrgCode,
c.FirstOrDefault().FindCode,
c.FirstOrDefault().IsMap,
children = c.GroupBy(a => a.ParentName).Select(c => new
{
id = c.FirstOrDefault().TypeOneId,
name = c.FirstOrDefault().ParentName,
zsCount = c.Count(f => f.CurrentState != null)
}).Where(f => f.id != null && f.zsCount != 0).OrderBy(c => c.id).ToList()
}).ToList();
List<String> pList = new List<String>();
for (var i = 0; i < data.Count; i++)
{
for (var j = 0; j < data[i].children.Count; j++)
{
if (!pList.Contains(data[i].children[j].name))
{
pList.Add(data[i].children[j].name);
}
}
}
var redata = new { data = data.OrderBy(x => x.OrgCode).ToList(), pList = pList };
return JsonManager.ReturnSuccessResponse(redata);
}
else
{
var codeLen = findcode.Length + 2;
var data = equipmentList.GroupBy(t => t.FindCode.PadLeft(codeLen, '0').Substring(0, codeLen)).Select(c => new
{
OrgName = c.FirstOrDefault().AreaName,
c.FirstOrDefault(x => x.OrgCode == c.FirstOrDefault().FindCode.PadRight(12, '0'))?.OrgCode,
c.FirstOrDefault().FindCode,
isMap = c.FirstOrDefault(x => x.OrgCode == c.FirstOrDefault().FindCode.PadRight(12, '0'))?.IsMap ?? 0,
zsCount = c.Count(f => f.CurrentState != null),
children = c.GroupBy(a => a.ParentName).Select(c => new
{
id = c.FirstOrDefault().TypeOneId,
name = c.FirstOrDefault().ParentName,
zsCount = c.Count(f => f.CurrentState != null)
}).Where(f => f.id != null).OrderBy(c => c.id).ToList()
}).ToList();
List<String> pList = new List<String>();
for (var i = 0; i < data.Count; i++)
{
for (var j = 0; j < data[i].children.Count; j++)
{
if (!pList.Contains(data[i].children[j].name))
{
pList.Add(data[i].children[j].name);
}
}
}
var redata = new { data = data.OrderBy(x => x.OrgCode).ToList(), pList = pList };
return JsonManager.ReturnSuccessResponse(redata);
}
URL = _httpHelper._centerServerAddress + "/api/View/GetAreaType",
Encoding = Encoding.UTF8,
Method = "POST",
ContentType = "application/json",
Timeout = 5000,
Postdata = jdata.ToString()
});
if (httpResult.StatusCode != HttpStatusCode.OK || string.IsNullOrEmpty(httpResult.Html))
{
return JsonManager.SimpleCustResponse("远端上报数据失败");
}
else
var obj = JsonConvert.DeserializeObject<JmpBaseResponse<object>>(httpResult.Html);
if (obj.code != "10000")
{
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
return JsonManager.SimpleCustResponse(obj.msg);
}
return JsonManager.ReturnSuccessResponse(obj.data);
}
catch (Exception ex)
{
......
......@@ -28,12 +28,15 @@ namespace JunmpPoliceStation.Extensions
HttpHelper _httpHelper;
private IConfiguration Configuration;
private ILogger<CronJob> _logger;
public CronJob(JunmppolicesqlContext dbContext, IConfiguration configuration, ILogger<CronJob> logger, HttpHelper httpHelper)
public CronJob(IConfiguration configuration, ILogger<CronJob> logger, HttpHelper httpHelper)
{
_dbContext = dbContext;
_httpHelper = httpHelper;
Configuration = configuration;
_logger = logger;
var options = new DbContextOptionsBuilder<JunmppolicesqlContext>();
options.UseMySQL(Configuration.GetConnectionString("MySqlConnection"));
_dbContext = new JunmppolicesqlContext(options.Options);
}
public void SyncEquipmentState()
......@@ -169,9 +172,9 @@ namespace JunmpPoliceStation.Extensions
Postdata = reqData,
IsNoTIP = true
});
if (res.StatusCode!=HttpStatusCode.Created)
if (res.StatusCode != HttpStatusCode.Created)
{
_logger.LogError("获取ACCESS_TOKEN失败 code:" + res.StatusCode +JsonConvert.SerializeObject(res));
_logger.LogError("获取ACCESS_TOKEN失败 code:" + res.StatusCode + JsonConvert.SerializeObject(res));
return false;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论