Commit 9fd46a7f by Seniorious

1

parent 6c3db362
using APIs.Common;
using APIs.Dto;
using APIs.Req;
using APIs.TimedTasks;
using Autofac.Core;
using AutoMapper;
using Common;
......@@ -39,6 +38,8 @@ using static Microsoft.AspNetCore.Razor.Language.TagHelperMetadata;
using static System.Net.Mime.MediaTypeNames;
using static JmpDehumidifierLib.Dehumidifier;
using JmpDehumidifierLib;
using NLog.Fluent;
using System.Security.Policy;
namespace APIs.Controllers
{
......@@ -232,7 +233,7 @@ namespace APIs.Controllers
}
var httpRes = JsonConvert.DeserializeObject<res<string>>(json);
if (httpRes == null || httpRes.code != "9920")
if (httpRes == null || httpRes.code != "99200")
{
await _bussinessInventoryService.OrderRollBack(rs);
return new ApiResult
......@@ -399,7 +400,7 @@ namespace APIs.Controllers
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult> UpdateHKPicture([FromBody] UpdateHKPictureReq req)
public async Task<ApiResult> UpdateHKPicture([FromForm] UpdateHKPictureReq req)
{
try
{
......@@ -423,18 +424,43 @@ namespace APIs.Controllers
if (policeinfo != null)
{
policeinfo.photo = req.photo;
var rs = await _policeInfoService.Update(policeinfo);
return rs ? new ApiResult
{
code = ResultCode.OPERATE_SUCCESS.Code,
msg = ResultCode.OPERATE_SUCCESS.Msg,
} : new ApiResult
using (HttpClient client = new HttpClient())
{
code = ResultCode.OPERATE_FAILED.Code,
msg = "更新地址失败",
}; ;
var postContent = new MultipartFormDataContent();
string boundary = string.Format("--{0}", DateTime.Now.Ticks.ToString("x"));
postContent.Headers.Add("ContentType", $"multipart/form-data, boundary={boundary}");
postContent.Add(new ByteArrayContent(req.picture), "picture");
postContent.Add(new StringContent(req.policeId), "policeId");
using (HttpResponseMessage response = client.PostAsync(AdminGlobalContext.jyzbConfig + "/api/uploadPolicePhoto", postContent).Result)
{
var str = response.Content.ReadAsStringAsync().Result;
var res = JsonConvert.DeserializeObject<HttpHelper.res<dynamic>>(str);
if (res != null && res.code.Equals("99200"))
{
policeinfo.photo = res.data.photo;
var rs = await _policeInfoService.Update(policeinfo);
return rs ? new ApiResult
{
code = ResultCode.OPERATE_SUCCESS.Code,
msg = ResultCode.OPERATE_SUCCESS.Msg,
} : new ApiResult
{
code = ResultCode.OPERATE_FAILED.Code,
msg = "更新地址失败",
};
}
else
{
return new ApiResult
{
code = ResultCode.OPERATE_FAILED.Code,
msg = "上传平台失败",
};
}
}
}
}
else
{
......@@ -466,7 +492,7 @@ namespace APIs.Controllers
{
try
{
if (req == null || string.IsNullOrEmpty(req.deviceId))
if (req == null || (string.IsNullOrEmpty(req.deviceId) && string.IsNullOrEmpty(req.warehouseId)))
{
return new ApiResult
{
......@@ -475,7 +501,15 @@ namespace APIs.Controllers
};
}
var config = await _channelService.QueryOne(s => s.id.Equals(req.deviceId));
Channel? config = null;
if (!string.IsNullOrEmpty(req.deviceId))
{
config = await _channelService.QueryOne(s => s.id.Equals(req.deviceId));
}
else
{
config = await _channelService.QueryOne(s => s.warehouseId.Equals(req.warehouseId));
}
if (config != null)
{
......@@ -615,6 +649,13 @@ namespace APIs.Controllers
{
try
{
var error = new ApiResult
{
code = ResultCode.OPERATE_FAILED.Code,
msg = "",
};
return error;
#region 合法判断
if (req.Epc == null || req.Epc.Count() == 0)
{
......@@ -653,13 +694,28 @@ namespace APIs.Controllers
};
}
var myOrder = await _orderService.QueryOne(s => s.orderState == 2);//单据
//还原非单标签EPC
List<string> PendingEpc = new List<string>();
foreach (var item in req.Epc)
{
var info = EpcConvert.EpcAnlysing(EpcConvert.ToHexByte(item));
if (info.EType != 0 && info.EType != 1)//如果不是单标签则还原
{
PendingEpc.Add(EpcConvert.RestoreEpc(item));
}
else
{
PendingEpc.Add(item);
}
}
var myOrder = await _orderService.QueryOrder(s => s.orderState == 2);//单据
var warehouse = await _warehouseService.QueryOne(s => s.id.Equals(req.warehouseId));
var warehouseInvtory = await _inventoryService.Query(s => !s.bussinessState.Equals("destruction") && !s.state.Equals("2") && s.locationId.Equals(req.warehouseId));//仓库装备
myOrder = (myOrder != null && !myOrder.orderType.Equals(req.state == 0 ? "in" : "out")) ? null : myOrder;//如果出入状态与单据不匹配则作为无单据处理
List<string> newEquOrderType = new List<string>() { "purchase", "allocate", "gift" };//入库单据为这些种类则会有新装备
List<string> newEquOrderType = new List<string>() { "purchase", "allocate", "gift", "return" };//入库单据为这些种类则会有新装备
List<string> epcList = new List<string>();//经过过滤后的EPC
......@@ -675,22 +731,23 @@ namespace APIs.Controllers
};
}
var removeEpcs = req.Epc.Except(warehouseInvtory.Select(s => s.epc).ToList()).ToList();
epcList = req.Epc.Where(s => !removeEpcs.Contains(s)).ToList();
var removeEpcs = PendingEpc.Except(warehouseInvtory.Select(s => s.epc).ToList()).ToList();
epcList = PendingEpc.Where(s => !removeEpcs.Contains(s)).ToList();
}
else//有新装备单据过滤本仓库物资
{
if (warehouseInvtory == null || warehouseInvtory.Count() == 0)
{
epcList = req.Epc;
epcList = PendingEpc;
}
else
{
var keepEpcs = req.Epc.Except(warehouseInvtory.Select(s => s.epc).ToList()).ToList();
epcList = req.Epc.Where(s => keepEpcs.Contains(s)).ToList();
var keepEpcs = PendingEpc.Except(warehouseInvtory.Select(s => s.epc).ToList()).ToList();
epcList = PendingEpc.Where(s => keepEpcs.Contains(s)).ToList();
}
}
var deatilDic = myOrder?.DetailList.Where(s => s.warehouseId.Equals(req.warehouseId))
.Select(s =>s.equipmentSize)
.ToList();//通道所在仓库子单
......@@ -707,7 +764,7 @@ namespace APIs.Controllers
var epc_info = EpcConvert.EpcAnlysing(EpcConvert.ToHexByte(epc));
string typecode = epc_info.Wzdm.ToString("X");
string sizecode = epc_info.Hxdm.ToString("X");
string suppliercode = epc_info.OrganizationCode.ToString();
string suppliercode = epc_info.OrganizationCode.ToString().ToLower();
var mytype = await _equipmentTypeService.QueryOne(s => s.id.Equals(typecode));
var mysize = await _equipmentSizeService.QueryOne(s => s.typeId.Equals(typecode) && s.code.Equals(sizecode));
......@@ -737,8 +794,8 @@ namespace APIs.Controllers
equState = "normal",
locationId = req.warehouseId,
locationName = warehouse?.name,
maintenancePeriod = Convert.ToString(periodInfo?.maintenancePeriod),
warrantyPeriod = Convert.ToString(periodInfo?.warrantyPeriod),
maintenancePeriod = Convert.ToString(Convert.ToInt32(periodInfo?.maintenancePeriod)),
warrantyPeriod = Convert.ToString(Convert.ToInt32(periodInfo?.warrantyPeriod)),
supplierId = mysupplier?.id ?? "",
orgId = Convert.ToInt64(orgInfo.orgId),
lostFlag = "0",
......@@ -879,10 +936,15 @@ namespace APIs.Controllers
};
}else
{
var json = HttpHelper.HttpPost(AdminGlobalContext.jyzbConfig.Url + "/PolicemanFinger/insertOrUpdateFingerInfo", JsonConvert.SerializeObject(req));
var send = new
{
policeId = req.policeId,
fingerList = req.fingerList.Select(s => new { fingerInfo = s.fingerInfo, fingerNum = s.fingerNum })
};
var json = HttpHelper.HttpPost(/*AdminGlobalContext.jyzbConfig.Url*/"http://192.168.2.14:10030" + "/PolicemanFinger/insertOrUpdateFingerInfo", JsonConvert.SerializeObject(send));
var httprs = JsonConvert.DeserializeObject<HttpHelper.res<string>>(json);
if(httprs != null && httprs.code == "9920")
if(httprs != null && httprs.code == "99200")
{
var rs = await _policeFingerService.UpdateFinger(req.policeId, req.fingerList);
......
......@@ -19,8 +19,8 @@ namespace APIs.Req
public class UpdateHKPictureReq
{
public byte[] picture { get; set; }
public string policeId { get; set; }
public string photo { get; set; }
}
public class GetInventoryOrderReq
......@@ -31,6 +31,7 @@ namespace APIs.Req
public class GetWarehouseConfigReq
{
public string deviceId { get; set; }
public string warehouseId { get; set; }
}
public class UpdateFingerReq
......
......@@ -30,6 +30,8 @@ namespace Common
/*---------以下为2.0版本新增参数,以下参数用于替换生产日期之后的字段,确保真唯一-----------*/
public ulong TimeSpan { get; set; } //当前日期时间戳,精确到毫秒
public byte MachineNum { get; set; } //服务器识别码(4bits),用于区分测试服务器与正式服务器生成的数据,实际1b就够了,其他3b做保留
/*---------以下为警用装备3.0添加参数-----------*/
public byte EType { get; set; } //1单标签 2双标签 3三标签(兼容2.0标签 2.0解析输出0)
}
public static class EpcConvert
......@@ -128,6 +130,11 @@ namespace Common
SetData(ref buf, pos, 12, epc.NoInBox);
pos += 12;
SetData(ref buf, pos, 4, epc.MachineNum);
pos += 4;
/*----------------警用装备3.0字段-------------*/
SetData(ref buf, pos, 4, epc.EType);
pos += 4;
// 双字节对齐, 剩余保留区
if (pos % 16 != 0)
......@@ -260,6 +267,8 @@ namespace Common
pos += 12;
rtn.MachineNum = (byte)GetData(epc, pos, 4);
pos += 4;
rtn.EType = (byte)GetData(epc, pos, 4);
pos += 4;
}
else
{
......@@ -286,6 +295,122 @@ namespace Common
return rtn;
}
//非单标签还原(jyzb3.0)
public static string RestoreEpc(string info)
{
var epc = ToHexByte(info);
var crc_chk = Crc16(epc, epc.Length - 2);
var crc_src = epc[epc.Length - 2] << 8 | epc[epc.Length - 1];
if (crc_src != crc_chk)
{
throw new Exception("CRC校验失败");
}
// 数据解析
Analyzingepc rtn = new Analyzingepc();
int pos = 0;
rtn.Header = (byte)GetData(epc, pos, 8);
pos += 8;
rtn.IssuerId = (byte)GetData(epc, pos, 6);
pos += 6;
var oc = GetData(epc, pos, 54);
rtn.OrganizationCode = OrganizationCodeToStr(oc);
pos += 54;
rtn.WzdmLen = (byte)(GetData(epc, pos, 4));
pos += 4;
var wzlen = ((rtn.WzdmLen - 1) % 8) * 8;
rtn.Wzdm = GetData(epc, pos, wzlen);
pos += wzlen;
rtn.Hxdm = GetData(epc, pos, 8);
pos += 8;
rtn.SerialLen = (byte)GetData(epc, pos, 4);
pos += 4;
rtn.Ver = (byte)GetData(epc, pos, 8);
pos += 8;
rtn.ProductionDate = (UInt32)GetData(epc, pos, 24);
pos += 24;
rtn.ExpiryDate = (byte)GetData(epc, pos, 6);
pos += 6;
rtn.ExpiryDateUnit = (byte)GetData(epc, pos, 2);
pos += 2;
rtn.TimeSpan = (ulong)GetData(epc, pos, 48);
pos += 48;
rtn.NoInBox = (UInt16)GetData(epc, pos, 12);
pos += 12;
rtn.MachineNum = (byte)GetData(epc, pos, 4);
pos += 4;
rtn.EType = (byte)GetData(epc, pos, 4);
pos += 4;
rtn.EType = 1;
string baseEpc = Hex16ByteToHex16String(EpcConvert.Epc2Gen(rtn)).Replace(" ", "");
return baseEpc;
}
//补充生成多标签(jyzb3.0)
public static List<string> SupplementEpc(string info, int etype)
{
var epc = ToHexByte(info);
var crc_chk = Crc16(epc, epc.Length - 2);
var crc_src = epc[epc.Length - 2] << 8 | epc[epc.Length - 1];
if (crc_src != crc_chk)
{
throw new Exception("CRC校验失败");
}
// 数据解析
Analyzingepc rtn = new Analyzingepc();
int pos = 0;
rtn.Header = (byte)GetData(epc, pos, 8);
pos += 8;
rtn.IssuerId = (byte)GetData(epc, pos, 6);
pos += 6;
var oc = GetData(epc, pos, 54);
rtn.OrganizationCode = OrganizationCodeToStr(oc);
pos += 54;
rtn.WzdmLen = (byte)(GetData(epc, pos, 4));
pos += 4;
var wzlen = ((rtn.WzdmLen - 1) % 8) * 8;
rtn.Wzdm = GetData(epc, pos, wzlen);
pos += wzlen;
rtn.Hxdm = GetData(epc, pos, 8);
pos += 8;
rtn.SerialLen = (byte)GetData(epc, pos, 4);
pos += 4;
rtn.Ver = (byte)GetData(epc, pos, 8);
pos += 8;
rtn.ProductionDate = (UInt32)GetData(epc, pos, 24);
pos += 24;
rtn.ExpiryDate = (byte)GetData(epc, pos, 6);
pos += 6;
rtn.ExpiryDateUnit = (byte)GetData(epc, pos, 2);
pos += 2;
rtn.TimeSpan = (ulong)GetData(epc, pos, 48);
pos += 48;
rtn.NoInBox = (UInt16)GetData(epc, pos, 12);
pos += 12;
rtn.MachineNum = (byte)GetData(epc, pos, 4);
pos += 4;
rtn.EType = (byte)GetData(epc, pos, 4);
pos += 4;
List<string> epcList = new List<string>();
for (int i = 2; i <= etype; i++)
{
rtn.EType = Convert.ToByte(i);
epcList.Add(Hex16ByteToHex16String(EpcConvert.Epc2Gen(rtn)).Replace(" ", ""));
}
return epcList;
}
/// <summary>
/// 向目标数组指定位置插入数据
/// </summary>
......
......@@ -13,7 +13,7 @@ namespace Models.Table
[SugarTable("base_equipment_size")]
public class EquipmentSize: BaseTable
{
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
[SugarColumn(IsPrimaryKey = true)]
public string id { get; set; }
......
......@@ -12,7 +12,7 @@ namespace Models.SqlModel
[SugarTable("base_equipment_type")]
public class EquipmentType : BaseTable
{
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
[SugarColumn(IsPrimaryKey = true)]
public string id { get; set; }
public string name { get; set; }
......
......@@ -13,7 +13,7 @@ namespace Models.Table
[SugarTable("base_inventory")]
public class Inventory : BaseTable
{
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
[SugarColumn(IsPrimaryKey = true)]
public string id { get; set; }
[SugarColumn(ColumnName = "type_id")]
......
......@@ -13,7 +13,7 @@ namespace Models.Table
/// <summary>
/// 指纹id
///</summary>
[SugarColumn(ColumnName="id" ,IsPrimaryKey = true ,IsIdentity = true )]
[SugarColumn(IsPrimaryKey = true ,IsIdentity = true)]
public int id { get; set; }
/// <summary>
/// 警员id
......
......@@ -33,12 +33,35 @@ namespace Repositories.Repository.Bussiness
});
//新增或更新
var x = context.Storageable(fingers).ToStorage();
x.AsInsertable.ExecuteCommand();
x.AsUpdateable.WhereColumns(s => new { s.id, s.fingerNum })//查询字段
.UpdateColumns(s => new { s.fingerInfo, s.updateTime })//更新字段
.IgnoreColumns(s => new { s.policeId, s.fingerNum, s.createTime })//不更新字段
.ExecuteCommand();
//var x = context.Storageable(fingers).WhereColumns(s => new { s.policeId, s.fingerNum }).ToStorage();
//x.AsInsertable.IgnoreColumns(s => s.id).ExecuteCommand();
//x.AsUpdateable.WhereColumns(s => new { s.policeId, s.fingerNum })//查询字段
// .UpdateColumns(s => new { s.fingerInfo, s.updateTime })//更新字段
// //.IgnoreColumns(s => new { s.policeId, s.fingerNum, s.createTime })//不更新字段
// .ExecuteCommand();
var fingerinfo = context.Queryable<PoliceFinger>().Where(s => s.policeId.Equals(policeId)).ToList();
var updateDic = fingerinfo.Select(s => s.fingerNum).ToList();
var updateList = new List<PoliceFinger>();
var insertList = new List<PoliceFinger>();
fingers.ForEach(s =>
{
if (updateDic.Contains(s.fingerNum))
{
updateList.Add(s);
}
else
{
insertList.Add(s);
}
});
if (insertList.Any()) context.Insertable(insertList).ExecuteCommand();
if (updateList.Any()) context.Updateable(updateList)
.WhereColumns(it => new { it.policeId, it.fingerNum })
.UpdateColumns(it => new { it.fingerInfo, it.updateTime })
.ExecuteCommand();
return true;
}
......
......@@ -3,6 +3,7 @@ using Models.Table;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
......@@ -11,5 +12,6 @@ namespace Services.Interface
public interface IOrderService : IBaseServices<OrderMain>
{
Task<object> QueryHandOrder(string warehouseId);
Task<OrderMain?> QueryOrder(Expression<Func<OrderMain, bool>> exp);
}
}
......@@ -6,6 +6,7 @@ using Services.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
......@@ -29,5 +30,12 @@ namespace Services
{
return _orderMainRepository.QueryHandOrder(warehouseId);
}
public async Task<OrderMain?> QueryOrder(Expression<Func<OrderMain, bool>> exp)
{
var main = await _orderMainRepository.QueryOne(exp);
if (main != null) main.DetailList = await _orderDetailRepository.Query(s => s.orderId.Equals(main.id));
return main;
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论