Commit e4765c6a by Seniorious

1

parent cda74cdc
...@@ -3,6 +3,7 @@ using APIs.Dto; ...@@ -3,6 +3,7 @@ using APIs.Dto;
using APIs.Req; using APIs.Req;
using Autofac.Core; using Autofac.Core;
using AutoMapper; using AutoMapper;
using Common;
using Common.Utility.Model; using Common.Utility.Model;
using Common.Utility.RabbitMQ; using Common.Utility.RabbitMQ;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
...@@ -18,8 +19,10 @@ using Services.Interface; ...@@ -18,8 +19,10 @@ using Services.Interface;
using SqlSugar; using SqlSugar;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Security.Cryptography.Xml; using System.Security.Cryptography.Xml;
using static Microsoft.AspNetCore.Razor.Language.TagHelperMetadata; using static Microsoft.AspNetCore.Razor.Language.TagHelperMetadata;
...@@ -42,11 +45,17 @@ namespace APIs.Controllers ...@@ -42,11 +45,17 @@ namespace APIs.Controllers
private readonly ILogService _logService; private readonly ILogService _logService;
private readonly IDevHistoryService _devHistoryService; private readonly IDevHistoryService _devHistoryService;
private readonly IDevService _devService; private readonly IDevService _devService;
private readonly IWarehouseService _warehouseService;
private readonly IOrderService _orderService;
private readonly ISupplierService _supplierService;
private readonly IThisInfoService _thisInfoService;
private readonly IPrintService _printService;
public BaseInfoController(IMapper mapper,IPoliceService policeService, IEquipmentTypeService equipmentTypeService, public BaseInfoController(IMapper mapper,IPoliceService policeService, IEquipmentTypeService equipmentTypeService,
IEquipmentSizeService equipmentSizeService,ICarService carService, IInventoryService inventoryService, IEquipmentSizeService equipmentSizeService,ICarService carService, IInventoryService inventoryService,
IInvService invService, IUsersService usersService, ILogService logService, IDevHistoryService devHistoryService, IInvService invService, IUsersService usersService, ILogService logService, IDevHistoryService devHistoryService,
IDevService devService) IDevService devService, IWarehouseService warehouseService, IOrderService orderService, ISupplierService supplierService,
IThisInfoService thisInfoService, IPrintService printService)
{ {
_carService = carService; _carService = carService;
_equipmentSizeService = equipmentSizeService; _equipmentSizeService = equipmentSizeService;
...@@ -58,38 +67,379 @@ namespace APIs.Controllers ...@@ -58,38 +67,379 @@ namespace APIs.Controllers
_logService = logService; _logService = logService;
_devHistoryService = devHistoryService; _devHistoryService = devHistoryService;
_devService = devService; _devService = devService;
_warehouseService = warehouseService;
_orderService = orderService;
_supplierService = supplierService;
_thisInfoService = thisInfoService;
_printService = printService;
Mapper = mapper; Mapper = mapper;
} }
/// <summary>
/// 通道上传出入库信息
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult> UploadRFID([FromBody] ChannelLogReq req)
{
try
{
#region 合法判断
if (req.Epc == null || req.Epc.Count() == 0)
{
return new ApiResult
{
code = ResultCode.OPERATE_FAILED.Code,
msg = "EPC为空",
};
}
if (req.state != 0 || req.Epc.Count() != 1)
{
return new ApiResult
{
code = ResultCode.OPERATE_FAILED.Code,
msg = "出入库状态错误",
};
}
if(req.warehouseId == null)
{
return new ApiResult
{
code = ResultCode.OPERATE_FAILED.Code,
msg = "仓库为空",
};
}
#endregion
var myOrder = await _orderService.QueryOne(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> epcList = new List<string>();//经过过滤后的EPC
//初步过滤
if (myOrder == null || !(newEquOrderType.Contains(myOrder.bussinessType) && myOrder.orderType.Equals("in")))//日常和无新装备单据的出入库过滤非本仓库物资
{
if (warehouseInvtory == null || warehouseInvtory.Count() == 0)
{
return new ApiResult
{
code = ResultCode.OPERATE_FAILED.Code,
msg = "仓库无装备"
};
}
var removeEpcs = req.Epc.Except(warehouseInvtory.Select(s => s.epc).ToList()).ToList();
epcList = req.Epc.Where(s => !removeEpcs.Contains(s)).ToList();
}
else//有新装备单据过滤本仓库物资
{
if (warehouseInvtory == null || warehouseInvtory.Count() == 0)
{
epcList = req.Epc;
}
else
{
var keepEpcs = req.Epc.Except(warehouseInvtory.Select(s => s.epc).ToList()).ToList();
epcList = req.Epc.Where(s => keepEpcs.Contains(s)).ToList();
}
}
var deatilDic = myOrder?.DetailList.Where(s => s.warehouseId.Equals(req.warehouseId))
.Select(s =>s.equipmentSize)
.ToList();//通道所在仓库子单
//创建出入库记录
List<Inventory> newEquList = new List<Inventory>();
List<LogDetail> logDetailList = new List<LogDetail>();
var orgInfo = await _thisInfoService.QueryOne(s => true);
foreach (var epc in epcList)
{
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();
var mytype = await _equipmentTypeService.QueryOne(s => s.id.Equals(typecode));
var mysize = await _equipmentSizeService.QueryOne(s => s.typeId.Equals(typecode) && s.code.Equals(sizecode));
var mysupplier = await _supplierService.QueryOne(s => s.code.Equals(suppliercode)); ;
if (mytype != null && mysize != null)
{
if(myOrder != null && deatilDic != null)//单据出入库则过滤非单据装备
{
if(!deatilDic.Contains(mysize.id))
{
continue;
}
else if(newEquOrderType.Contains(myOrder.bussinessType) && myOrder.orderType.Equals("in"))//有新装备单据生成库存记录
{
var periodInfo = (await _printService.QueryOne(s => s.id.Equals(myOrder.id)))?.DetailList.FirstOrDefault(s => s.sizeId.Equals(mysize.id));
newEquList.Add(new Inventory
{
id = Guid.NewGuid().ToString(),
state = "2",
epc = epc,
typeId = mytype.id ?? "",
sizeId = mysize.id ?? "",
typeName = mytype.name ?? "",
sizeName = mysize.name ?? "",
bussinessState = "normal",
equState = "normal",
locationId = req.warehouseId,
locationName = warehouse?.name,
maintenancePeriod = Convert.ToString(periodInfo?.maintenancePeriod),
warrantyPeriod = Convert.ToString(periodInfo?.warrantyPeriod),
supplierId = mysupplier?.id ?? "",
orgId = Convert.ToInt64(orgInfo.orgId),
lostFlag = "0",
equipmentType = "0",
locationType = "0",
supplierName = mysupplier?.name ?? "",
productionDate = periodInfo?.productionDate,
createTime = DateTime.Now,
updateTime = DateTime.Now,
price = myOrder.DetailList?.FirstOrDefault(s => s.equipmentSize.Equals(mysize.id))?.price ?? 0,
});
}
}
//出入库子单
var inv = await _inventoryService.QueryOne(s => s.epc.Equals(epc));
logDetailList.Add(new LogDetail()
{
inventoryId = inv?.id,
epc = epc,
equipmentName = mytype?.name ?? "",
equipmentSize = mysize.name ?? "",
equipmentTypeId = mytype?.id ?? "",
equipmentSizeId = mysize.id ?? "",
errorState = 0,
state = req.state == 1 ? 0 : 1,
equipmentType = 0,
supplierId = mysupplier?.id ?? "",
supplierName = mysupplier?.name ?? "",
price = inv?.price ?? 0,
createTime = DateTime.Now,
updateTime = DateTime.Now,
});
}
else
{
continue;
}
}
//生成主单
LogSummary summary = new LogSummary();
if (logDetailList.Count() > 0)
{
var names = logDetailList.GroupBy(s => s.equipmentName).Select(s => s.Key).ToList();
string equipments = "";
for (int i = 0; i < names.Count; i++)
{
equipments = (i == names.Count - 1) ? equipments + $"{names[i]}" : equipments + $"{names[i]},";
}
summary = new LogSummary()
{
locationId = req.warehouseId,
locationName = warehouse.name,
userName = "",
useTime = DateTime.Now,
createTime = DateTime.Now,
updateTime = DateTime.Now,
bussinessType = myOrder?.bussinessType ?? "normal",
deviceType = 2,
number = logDetailList.Count(),
outInState = req.state == 0 ? "out" : "in",
equipments = equipments,
orderId = myOrder?.id,
orderCode = myOrder?.orderCode,
isUpload = 0,
price = logDetailList.Sum(s => s.price),
DetailList = logDetailList,
};
}
var rs = await _logService.AddChannelLog(myOrder, summary, newEquList);
return rs ? new ApiResult
{
code = ResultCode.OPERATE_SUCCESS.Code,
msg = ResultCode.OPERATE_SUCCESS.Msg
}: new ApiResult
{
code = ResultCode.OPERATE_FAILED.Code,
msg = ResultCode.OPERATE_FAILED.Msg
};
}
catch (Exception ex)
{
var error = new ApiResult
{
code = ResultCode.OPERATE_FAILED.Code,
msg = ex.Message,
};
return error;
}
}
/// <summary> /// <summary>
/// 3.0平台获取图片 /// 获取装备类别
/// </summary> /// </summary>
/// <param name="id"></param>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
public IActionResult DownloadLogPicture(string id) public async Task<ApiResult> GetEquipmentType()
{ {
try try
{ {
// 读取文件内容 var types = (await _equipmentTypeService.Query())?.Select(s => new
byte[] fileBytes = System.IO.File.ReadAllBytes($"LogPictures\\{id}.jpg"); {
id = s.id,
name = s.name,
code = s.id,
}).ToList();
// 获取文件的MIME类型
string contentType = "application/octet-stream"; // 默认使用二进制流的MIME类型,如果需要根据具体文件类型动态获取,请进行适当的处理。
// 返回文件结果 var src = new ApiResult
return File(fileBytes, contentType, $"{id}.jpg"); {
code = ResultCode.OPERATE_SUCCESS.Code,
msg = ResultCode.OPERATE_SUCCESS.Msg,
data = types
};
return src;
}
catch (Exception ex)
{
var error = new ApiResult
{
code = ResultCode.OPERATE_FAILED.Code,
msg = ex.Message,
};
return error;
}
}
/// <summary>
/// 获取本组织机构所有仓库
/// </summary>
/// <param name=""></param>
/// <returns></returns>
[HttpGet]
public async Task<ApiResult> GetWarehouse()
{
try
{
var warehouses = (await _warehouseService.Query())?.Select(s => new
{
id = s.id,
name = s.name,
}).ToList();
var src = new ApiResult
{
code = ResultCode.OPERATE_SUCCESS.Code,
msg = ResultCode.OPERATE_SUCCESS.Msg,
data = warehouses
};
return src;
} }
catch (Exception ex) catch (Exception ex)
{ {
return new ContentResult var error = new ApiResult
{ {
Content = "ERROR:" + ex, code = ResultCode.OPERATE_FAILED.Code,
ContentType = "text/plain", msg = ex.Message,
StatusCode = 400
}; };
return error;
} }
}
/// <summary>
/// 通道出入库照片上传
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult> UploadLogPicture([FromForm] LogPictureReq req)
{
try
{
if(req.picture == null)
{
return new ApiResult
{
code = ResultCode.OPERATE_FAILED.Code,
msg = "无图片",
};
}
if (string.IsNullOrEmpty(req.fileName))
{
return new ApiResult
{
code = ResultCode.OPERATE_FAILED.Code,
msg = "无图片名称",
};
}
if (string.IsNullOrEmpty(req.directoy))
{
return new ApiResult
{
code = ResultCode.OPERATE_FAILED.Code,
msg = "无文件夹名称",
};
}
using (MemoryStream ms = new MemoryStream())
{
//拷贝文件到内存流
req.picture.CopyTo(ms);
var tmp = ms.GetBuffer();
var fileType = tmp[0].ToString() + tmp[1].ToString();
var path = Path.Combine("LogPictures", req.directoy);
Directory.CreateDirectory(path);
var filePath = Path.Combine(path, req.fileName);
System.Drawing.Image.FromStream(ms).Save(filePath);
var src = new ApiResult
{
code = ResultCode.OPERATE_SUCCESS.Code,
msg = ResultCode.OPERATE_SUCCESS.Msg,
};
return src;
}
}
catch (Exception ex)
{
var error = new ApiResult
{
code = ResultCode.OPERATE_FAILED.Code,
msg = ex.Message,
};
return error;
}
} }
/// <summary> /// <summary>
...@@ -104,7 +454,7 @@ namespace APIs.Controllers ...@@ -104,7 +454,7 @@ namespace APIs.Controllers
//读取图片 //读取图片
string imageBytes = ""; string imageBytes = "";
string url = $"LogPictures\\{req.logId}.jpg"; string url = $"LogPictures/{req.pid}.jpg";
using (FileStream fileStream = new FileStream(url, FileMode.Open)) using (FileStream fileStream = new FileStream(url, FileMode.Open))
{ {
using (BinaryReader reader = new BinaryReader(fileStream)) using (BinaryReader reader = new BinaryReader(fileStream))
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
public string id { get; set; } public string id { get; set; }
} }
public class PictureReq public class PictureReq
{ {
public string policeId { get; set; } public string policeId { get; set; }
...@@ -23,7 +22,13 @@ ...@@ -23,7 +22,13 @@
public class GetLogPictureReq public class GetLogPictureReq
{ {
public string logId { get; set;} public string pid { get; set;}
} }
public class LogPictureReq
{
public IFormFile picture { get; set; }
public string fileName { get; set; }//文件名
public string directoy { get; set; }//文件夹
}
} }
...@@ -71,6 +71,8 @@ namespace APIs ...@@ -71,6 +71,8 @@ namespace APIs
services.AddScoped<IThisInfoService, ThisInfoService>(); services.AddScoped<IThisInfoService, ThisInfoService>();
services.AddScoped<IDevService, DevService>(); services.AddScoped<IDevService, DevService>();
services.AddScoped<IDevHistoryService, DevHistoryService>(); services.AddScoped<IDevHistoryService, DevHistoryService>();
services.AddScoped<IWarehouseService, WarehouseService>();
services.AddScoped<ISupplierService, SupplierService>();
#endregion #endregion
#region Repository #region Repository
...@@ -91,6 +93,8 @@ namespace APIs ...@@ -91,6 +93,8 @@ namespace APIs
services.AddScoped<IThisInfoRepository, ThisInfoRepository>(); services.AddScoped<IThisInfoRepository, ThisInfoRepository>();
services.AddScoped<IDevRepository, DevRepository>(); services.AddScoped<IDevRepository, DevRepository>();
services.AddScoped<IDevHistoryRepository, DevHistoryRepository>(); services.AddScoped<IDevHistoryRepository, DevHistoryRepository>();
services.AddScoped<IWarehouseRepository, WarehouseRepository>();
services.AddScoped<ISupplierRepository, SupplierRepository>();
#endregion #endregion
#region 注册RabbitMQ消费者 #region 注册RabbitMQ消费者
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Common
{
public class Analyzingepc
{
public byte Header; // 标头(8bits): JY物资专用标头 0x11(00010001b)
public byte IssuerId; // 发行机构标识符(6bits):GA组织机构: 0x01(000001b) 国家组织机构:0x02(000010b)
public string OrganizationCode; // 组织机构代码(54bits):JY物资生产厂商使用GA或国家组织机构代码, 英文字母及数字的每一个字符转换为六位二进制
public byte WzdmLen; // 物资代码长度(4bits): 指定物资代码的长度(N*8bits), 此处为0x7
public UInt64 Wzdm; // 物资代码(56bits): 使用警用物资编目数据的物资代码,按十进制转换成十六进制存储
public UInt64 Hxdm;
public byte SerialLen; // 序列号长度(4bits): 指定序列号长度(N*8bits), 此处为0xD
public byte Ver; // 版本号(8bits): 0x01
public byte TagType; // 标签类型(8bits): 0x00 件标 0x01 箱标
public byte PackingType; // 包装类型(4bits): 0x1 单品, 0x2 外包装, 0x3 内包装, 0xF 零头配箱
public UInt32 ProductionDate; // 生产日期(24bits): 0x161201
public byte ExpiryDate; // 有效期值(6bits): 0-63
public byte ExpiryDateUnit; // 有效期时间单位(2bits): 1:01b-日, 2:10b-月, 3:11b-年
public byte SubPackageNum; // 下级包装内数量(8bits):最大255
public UInt16 WzCount; // 包装数量(12bits): MAX:4095, 每箱内产品总数
public UInt32 BoxNo; // 包装箱序列号(20bits): MAX:65535
public UInt16 NoInBox; // 箱内序列号(12bits): 每箱内产品序号, MAX4095
/*---------以下为2.0版本新增参数,以下参数用于替换生产日期之后的字段,确保真唯一-----------*/
public ulong TimeSpan { get; set; } //当前日期时间戳,精确到毫秒
public byte MachineNum { get; set; } //服务器识别码(4bits),用于区分测试服务器与正式服务器生成的数据,实际1b就够了,其他3b做保留
}
public static class EpcConvert
{
private readonly static string strKeyWords = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // 无源标签6位字段对应表
/// <summary>
/// 此方法用于将普通字符串转换成16进制的字符串。
/// </summary>
/// <param name="_str">要转换的字符串。</param>
/// <returns></returns>
public static string StringToHex16String(string _str)
{
//将字符串转换成字节数组。
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(_str);
//定义一个string类型的变量,用于存储转换后的值。
string result = string.Empty;
for (int i = 0; i < buffer.Length; i++)
{
//将每一个字节数组转换成16进制的字符串,以空格相隔开。
result += Convert.ToString(buffer[i], 16) + " ";
}
return result;
}
/// <summary>
/// 此方法用于将16进制的字节数组转换成16进制的字符串。
/// </summary>
/// <param name="_hex16Byte">要转换的16进制的字节数组。</param>
/// <returns></returns>
public static string Hex16ByteToHex16String(byte[] _hex16Byte)
{
string result = string.Empty;
//如果字节数组不为空。
if (_hex16Byte != null)
{
for (int i = 0; i < _hex16Byte.Length; i++)
{
//将每一个字节数组转换成16进制string类型的字符串,用空格分隔开。
result += _hex16Byte[i].ToString("X2") + " ";
}
}
return result;
}
public static byte[] ToHexByte(string hexString)
{
hexString = hexString.Replace(" ", "");
if ((hexString.Length % 2) != 0)
{
hexString = hexString + " ";
}
byte[] buffer = new byte[hexString.Length / 2];
for (int i = 0; i < buffer.Length; i++)
{
buffer[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 0x10);
}
return buffer;
}
/// <summary>
/// 生成2.0EPC
/// </summary>
/// <param name="epc"></param>
/// <returns></returns>
public static byte[] Epc2Gen(Analyzingepc epc)
{
byte[] buf = new byte[40];
int pos = 0;
SetData(ref buf, pos, 8, epc.Header);
pos += 8;
SetData(ref buf, pos, 6, epc.IssuerId);
pos += 6;
SetData(ref buf, pos, 54, OrganizationCodeTo6Bin(epc.OrganizationCode.ToUpper()));
pos += 54;
SetData(ref buf, pos, 4, epc.WzdmLen);
pos += 4;
var wzlen = ((epc.WzdmLen - 1) % 8) * 8;
SetData(ref buf, pos, wzlen, epc.Wzdm); // 物资代码暂时定义最长为64bits
pos += wzlen;
SetData(ref buf, pos, 8, epc.Hxdm); // 物资代码暂时定义最长为64bits
pos += 8;
SetData(ref buf, pos, 4, epc.SerialLen);
pos += 4;
/*----------------2.0版本字段-------------*/
SetData(ref buf, pos, 8, epc.Ver);
pos += 8;
SetData(ref buf, pos, 24, epc.ProductionDate);
pos += 24;
SetData(ref buf, pos, 6, epc.ExpiryDate);
pos += 6;
SetData(ref buf, pos, 2, epc.ExpiryDateUnit);
pos += 2;
SetData(ref buf, pos, 48, epc.TimeSpan);
pos += 48;
SetData(ref buf, pos, 12, epc.NoInBox);
pos += 12;
SetData(ref buf, pos, 4, epc.MachineNum);
// 双字节对齐, 剩余保留区
if (pos % 16 != 0)
{
pos += 16 - pos % 16;
}
// 数据体长度
var len = pos / 8;
var crc = Crc16(buf, len);
SetData(ref buf, pos, 16, crc);
byte[] rtn = new byte[len + 2];
Array.Copy(buf, rtn, len + 2);
return rtn;
}
/// <summary>
/// 生成EPC
/// </summary>
/// <param name="epc"></param>
/// <returns></returns>
public static byte[] EpcGen(Analyzingepc epc)
{
byte[] buf = new byte[40];
int pos = 0;
SetData(ref buf, pos, 8, epc.Header);
pos += 8;
SetData(ref buf, pos, 6, epc.IssuerId);
pos += 6;
SetData(ref buf, pos, 54, OrganizationCodeTo6Bin(epc.OrganizationCode.ToUpper()));
pos += 54;
SetData(ref buf, pos, 4, epc.WzdmLen);
pos += 4;
var wzlen = ((epc.WzdmLen - 1) % 8) * 8;
SetData(ref buf, pos, wzlen, epc.Wzdm); // 物资代码暂时定义最长为64bits
pos += wzlen;
SetData(ref buf, pos, 8, epc.Hxdm); // 物资代码暂时定义最长为64bits
pos += 8;
SetData(ref buf, pos, 4, epc.SerialLen);
pos += 4;
SetData(ref buf, pos, 8, epc.Ver);
pos += 8;
SetData(ref buf, pos, 8, epc.TagType);
pos += 8;
SetData(ref buf, pos, 4, epc.PackingType);
pos += 4;
SetData(ref buf, pos, 24, epc.ProductionDate);
pos += 24;
SetData(ref buf, pos, 6, epc.ExpiryDate);
pos += 6;
SetData(ref buf, pos, 2, epc.ExpiryDateUnit);
pos += 2;
SetData(ref buf, pos, 8, epc.SubPackageNum);
pos += 8;
SetData(ref buf, pos, 12, epc.WzCount);
pos += 12;
SetData(ref buf, pos, 20, epc.BoxNo);
pos += 20;
SetData(ref buf, pos, 12, epc.NoInBox);
pos += 12;
// 双字节对齐, 剩余保留区
if (pos % 16 != 0)
{
pos += 16 - pos % 16;
}
// 数据体长度
var len = pos / 8;
var crc = Crc16(buf, len);
SetData(ref buf, pos, 16, crc);
byte[] rtn = new byte[len + 2];
Array.Copy(buf, rtn, len + 2);
return rtn;
}
/// <summary>
/// 解析EPC
/// </summary>
/// <param name="epc"></param>
/// <returns></returns>
public static Analyzingepc EpcAnlysing(byte[] epc)
{
// CRC 校验
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;
//2.0版本解析
if (rtn.Ver == 0x02)
{
rtn.ProductionDate = (byte)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 = (byte)GetData(epc, pos, 48);
pos += 48;
rtn.NoInBox = (byte)GetData(epc, pos, 12);
pos += 12;
rtn.MachineNum = (byte)GetData(epc, pos, 4);
pos += 4;
}
else
{
rtn.TagType = (byte)GetData(epc, pos, 8);
pos += 8;
rtn.PackingType = (byte)GetData(epc, pos, 4);
pos += 4;
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.SubPackageNum = (byte)GetData(epc, pos, 8);
pos += 8;
rtn.WzCount = (UInt16)GetData(epc, pos, 12);
pos += 12;
rtn.BoxNo = (UInt32)GetData(epc, pos, 20);
pos += 20;
rtn.NoInBox = (UInt16)GetData(epc, pos, 12);
pos += 12;
}
return rtn;
}
/// <summary>
/// 向目标数组指定位置插入数据
/// </summary>
/// <param name="data">待操作数组</param>
/// <param name="pos">起始位置</param>
/// <param name="len">写入长度bits</param>
/// <param name="value">写入的值</param>
private static void SetData(ref byte[] data, int pos, int len, UInt64 value)
{
int p = pos;
while (--len >= 0)
{
var bitPos = 7 - p % 8;
data[p++ / 8] |= (byte)(((value >> len) & 1) << bitPos);
}
}
/// <summary>
/// 从目标数组获取成员变量
/// </summary>
/// <param name="data"></param>
/// <param name="pos"></param>
/// <param name="len"></param>
/// <returns></returns>
private static UInt64 GetData(byte[] data, int pos, int len)
{
UInt64 rtn = 0;
int p = pos;
while (len-- > 0)
{
var bitPos = 7 - p % 8;
rtn <<= 1;
rtn |= (byte)((data[p++ / 8] >> bitPos) & 1);
}
return rtn;
}
/// <summary>
/// 转换成字符串
/// </summary>
/// <param name="icode"></param>
/// <returns></returns>
private static string OrganizationCodeToStr(UInt64 icode)
{
string code = "";
for (int i = 0; i < 9; i++)
{
var v = (byte)((icode >> (i * 6)) & 0x3f);
code = strKeyWords[v] + code;
}
return code;
}
/// <summary>
/// 生成十六进制组织代码, 6Bin
/// </summary>
/// <param name="code"></param>
/// <returns>0 失败, 其它:正常的组织代码编号</returns>
private static UInt64 OrganizationCodeTo6Bin(string code)
{
UInt64 iCode = 0;
if (code.Length == 9)
{
for (int i = 0; i < code.Length; i++)
{
var index = strKeyWords.IndexOf(code[i]);
if (index == -1)
{
throw new Exception("输入字符非法!");
}
iCode <<= 6;
iCode |= (byte)index;
}
}
else
{
throw new Exception("输入长度非法!");
}
return iCode;
}
/// <summary>
/// CRC运算
/// </summary>
/// <param name="data"></param>
/// <param name="len">必须是偶数</param>
/// <returns></returns>
public static UInt16 Crc16(byte[] data, int lenth)
{
ushort crc = 0x8791;
for (int i = 0; i < lenth; ++i)
{
ushort temp = 0;
ushort a = (ushort)(((crc >> 8) ^ (0xff & data[i])) << 8);
for (int j = 0; j < 8; ++j)
{
if (((temp ^ a) & 0x8000) != 0)
{
temp = (ushort)((temp << 1) ^ 0x1021);
}
else
{
temp <<= 1;
}
a <<= 1;
}
crc = (ushort)((crc << 8) ^ temp);
}
return crc;
}
}
}
...@@ -55,6 +55,13 @@ namespace Common.Utility.Model ...@@ -55,6 +55,13 @@ namespace Common.Utility.Model
public String equipments { get; set; } public String equipments { get; set; }
[AllowNull] [AllowNull]
public List<EquipmentList>? equipmentList { get; set; } public List<EquipmentList>? equipmentList { get; set; }
// }
public class ChannelLogReq
{
public List<string> Epc { get; set; }
public int? state { get; set; }
public string warehouseId { get; set; }
public string picture { get; set; }
} }
} }
...@@ -15,20 +15,20 @@ namespace Models.Table ...@@ -15,20 +15,20 @@ namespace Models.Table
{ {
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)] [SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
public String id { get; set; } public string id { get; set; }
public String code { get; set; } public string code { get; set; }
[SugarColumn(ColumnName = "type_id")] [SugarColumn(ColumnName = "type_id")]
public String? typeId { get; set; } public string typeId { get; set; }
[SugarColumn(ColumnName = "name")] [SugarColumn(ColumnName = "name")]
public String? name { get; set; } public string name { get; set; }
public String? note { get; set; } public string note { get; set; }
public String? price { get; set; } public string price { get; set; }
public String? state { get; set; } public string state { get; set; }
} }
......
using SqlSugar; using Models.SqlModel;
using SqlSugar;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Principal; using System.Security.Principal;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using static Dm.net.buffer.ByteArrayBuffer;
namespace Models.Table namespace Models.Table
{ {
...@@ -12,54 +14,73 @@ namespace Models.Table ...@@ -12,54 +14,73 @@ namespace Models.Table
public class Inventory : BaseTable public class Inventory : BaseTable
{ {
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)] [SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
public String id { get; set; } public string id { get; set; }
[SugarColumn(ColumnName = "type_id")] [SugarColumn(ColumnName = "type_id")]
public String typeId { get; set; } public string typeId { get; set; }
[SugarColumn(ColumnName = "size_id")] [SugarColumn(ColumnName = "size_id")]
public String sizeId { get; set; } public string sizeId { get; set; }
[SugarColumn(ColumnName = "supplier_id")] [SugarColumn(ColumnName = "supplier_id")]
public String supplierId { get; set; } public string supplierId { get; set; }
public String epc { get; set; } public string epc { get; set; }
[SugarColumn(ColumnName = "org_id")] [SugarColumn(ColumnName = "org_id")]
public String orgId { get; set; } public long? orgId { get; set; }
public String state { get; set; } public string state { get; set; }
[SugarColumn(ColumnName = "bussiness_state")] [SugarColumn(ColumnName = "bussiness_state")]
public String bussinessState { get; set; } public string bussinessState { get; set; }
[SugarColumn(ColumnName = "equ_state")]
public string equState { get; set; }
[SugarColumn(ColumnName = "production_date")] [SugarColumn(ColumnName = "production_date")]
public DateTime? productionDate { get; set; } public DateTime? productionDate { get; set; }
[SugarColumn(ColumnName = "warranty_period")] [SugarColumn(ColumnName = "warranty_period")]
public String warrantyPeriod { get; set; } public string warrantyPeriod { get; set; }
[SugarColumn(ColumnName = "maintenance_period")] [SugarColumn(ColumnName = "maintenance_period")]
public String maintenancePeriod { get; set; } public string maintenancePeriod { get; set; }
[SugarColumn(ColumnName = "fix_count")] [SugarColumn(ColumnName = "fix_count")]
public String fixCount { get; set; } public string fixCount { get; set; }
[SugarColumn(ColumnName = "location_id")] [SugarColumn(ColumnName = "location_id")]
public String locationId { get; set; } public string locationId { get; set; }
[SugarColumn(ColumnName = "location_name")]
public string locationName { get; set; }
[SugarColumn(ColumnName = "location_type")] [SugarColumn(ColumnName = "location_type")]
public String locationType { get; set; } public string locationType { get; set; }
[SugarColumn(ColumnName = "lost_flag")] [SugarColumn(ColumnName = "lost_flag")]
public String lostFlag { get; set; } public string lostFlag { get; set; }
[SugarColumn(ColumnName = "note")]
public string note { get; set; }
[SugarColumn(ColumnName = "equipment_type")]
public string equipmentType { get; set; }
public String price { get; set; } public decimal? price { get; set; }
[SugarColumn(ColumnName = "type_name")] [SugarColumn(ColumnName = "type_name")]
public String typeName { get; set; } public string typeName { get; set; }
[SugarColumn(ColumnName = "size_name")] [SugarColumn(ColumnName = "size_name")]
public String sizeName { get; set; } public string sizeName { get; set; }
[SugarColumn(ColumnName = "supplier_name")]
public string supplierName { get; set; }
[SugarColumn(ColumnName = "package_id")]
public string packageId { get; set; }
} }
} }
...@@ -15,24 +15,24 @@ namespace Models.Table ...@@ -15,24 +15,24 @@ namespace Models.Table
public int id { get; set; } public int id { get; set; }
[SugarColumn(ColumnName = "inventory_id")] [SugarColumn(ColumnName = "inventory_id")]
public int inventoryId { get; set; } public string inventoryId { get; set; }
[SugarColumn(ColumnName = "summary_id")] [SugarColumn(ColumnName = "summary_id")]
public int summaryId { get; set; } public int summaryId { get; set; }
public String epc { get; set; } public string epc { get; set; }
[SugarColumn(ColumnName = "equipment_name")] [SugarColumn(ColumnName = "equipment_name")]
public String? equipmentName { get; set; } public string equipmentName { get; set; }
[SugarColumn(ColumnName = "equipment_size")] [SugarColumn(ColumnName = "equipment_size")]
public String? equipmentSize { get; set; } public string equipmentSize { get; set; }
[SugarColumn(ColumnName = "equipment_type_id")] [SugarColumn(ColumnName = "equipment_type_id")]
public String? equipmentTypeId { get; set; } public string equipmentTypeId { get; set; }
[SugarColumn(ColumnName = "equipment_size_id")] [SugarColumn(ColumnName = "equipment_size_id")]
public String? equipmentSizeId { get; set; } public string equipmentSizeId { get; set; }
[SugarColumn(ColumnName = "error_state")] [SugarColumn(ColumnName = "error_state")]
public int? errorState { get; set; } public int? errorState { get; set; }
...@@ -43,16 +43,16 @@ namespace Models.Table ...@@ -43,16 +43,16 @@ namespace Models.Table
public int? carid { get; set; } public int? carid { get; set; }
[SugarColumn(ColumnName = "order_id")] [SugarColumn(ColumnName = "order_id")]
public String? orderId { get; set; } public string orderId { get; set; }
[SugarColumn(ColumnName = "order_code")] [SugarColumn(ColumnName = "order_code")]
public String? orderCode { get; set; } public string orderCode { get; set; }
[SugarColumn(ColumnName = "supplier_id")] [SugarColumn(ColumnName = "supplier_id")]
public String? supplierId { get; set; } public string supplierId { get; set; }
[SugarColumn(ColumnName = "supplier_name")] [SugarColumn(ColumnName = "supplier_name")]
public String? supplierName { get; set; } public string supplierName { get; set; }
[SugarColumn(ColumnName = "equipment_type")] [SugarColumn(ColumnName = "equipment_type")]
public int? equipmentType { get; set; } public int? equipmentType { get; set; }
......
...@@ -41,7 +41,7 @@ namespace Models.Table ...@@ -41,7 +41,7 @@ namespace Models.Table
public String? device { get; set; } public String? device { get; set; }
[SugarColumn(ColumnName = "device_type")] [SugarColumn(ColumnName = "device_type")]
public int? device_type { get; set; } public int? deviceType { get; set; }
[SugarColumn(ColumnName = "location_id")] [SugarColumn(ColumnName = "location_id")]
public String? locationId { get; set; } public String? locationId { get; set; }
...@@ -63,5 +63,6 @@ namespace Models.Table ...@@ -63,5 +63,6 @@ namespace Models.Table
[Navigate(NavigateType.OneToMany, nameof(LogDetail.summaryId))] [Navigate(NavigateType.OneToMany, nameof(LogDetail.summaryId))]
public List<LogDetail> DetailList { get; set; } = new List<LogDetail>(); public List<LogDetail> DetailList { get; set; } = new List<LogDetail>();
} }
} }
...@@ -41,5 +41,11 @@ namespace Models.Table ...@@ -41,5 +41,11 @@ namespace Models.Table
public int? actualNum { get; set; } public int? actualNum { get; set; }
public decimal? price { get; set; } public decimal? price { get; set; }
[SugarColumn(ColumnName = "warehouse_id")]
public string warehouseId { get; set; }
[SugarColumn(ColumnName = "warehouse_name")]
public string warehouseName { get; set; }
} }
} }
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using static Dm.net.buffer.ByteArrayBuffer;
namespace Models.Table
{
[SugarTable("base_supplier")]
public class Supplier : BaseTable
{
[SugarColumn(IsPrimaryKey = true)]
public string id { get; set; }
public string name { get; set; }
public string code { get; set; }
[SugarColumn(ColumnName = "short_name")]
public string shortName { get; set; }
public string contacts { get; set; }
public string phone { get; set; }
[SugarColumn(ColumnName = "create_user")]
public string createUser { get; set; }
[SugarColumn(ColumnName = "update_user")]
public string updateUser { get; set; }
public string state { get; set; }
}
}
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Models.Table
{
[SugarTable("base_warehouse")]
public class Warehouse : BaseTable
{
[SugarColumn(IsPrimaryKey = true)]
public string id { get; set; }
public string name { get; set; }
public string location { get; set; }
public string phone { get; set; }
[SugarColumn(ColumnName = "is_locked")]
public int? isLocked { get; set; }
[SugarColumn(ColumnName = "org_id")]
public string orgId { get; set; }
public int? sum { get; set; }
[SugarColumn(ColumnName = "out_sum")]
public int? outSum { get; set; }
[SugarColumn(ColumnName = "in_sum")]
public int? inSum { get; set; }
[SugarColumn(ColumnName = "price_total")]
public decimal? priceTotal { get; set; }
public int? state { get; set; }
}
}
...@@ -15,5 +15,7 @@ namespace Repositories.IRepository.IBussiness ...@@ -15,5 +15,7 @@ namespace Repositories.IRepository.IBussiness
Task<bool> AddHandLogs(LogSummary model, List<Inventory> invs); Task<bool> AddHandLogs(LogSummary model, List<Inventory> invs);
Task<bool> AddChannelLog(OrderMain? myOrder, LogSummary summary, List<Inventory> newInvs, Tuple<string, string> inv_states);
} }
} }
using Models.Table;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Repositories.IRepository.IBussiness
{
public interface ISupplierRepository : IBaseRepository<Supplier>
{
}
}
using Models.Table;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Repositories.IRepository.IBussiness
{
public interface IWarehouseRepository : IBaseRepository<Warehouse>
{
}
}
...@@ -21,6 +21,92 @@ namespace Repositories.Repository.Bussiness ...@@ -21,6 +21,92 @@ namespace Repositories.Repository.Bussiness
_suger = sugarUnitOfWork; _suger = sugarUnitOfWork;
} }
public async Task<bool> AddChannelLog(OrderMain? myOrder, LogSummary summary, List<Inventory> newInvs, Tuple<string,string> inv_states)
{
using (var context = _suger.GetDbClient())
{
try
{
context.BeginTran();
if(newInvs != null && newInvs.Count() > 0)
{
var inv_rs = context.Insertable(newInvs).ExecuteCommand();
summary.DetailList.ForEach(s =>
{
s.inventoryId = context.Queryable<Inventory>().First(n => n.epc.Equals(s.epc))?.id;
});
}
var logrs = context.InsertNav(summary).Include(z1 => z1.DetailList).ExecuteCommand();
//更新库存状态
var invIds = summary.DetailList.Select(a => a.inventoryId).ToList();
context.Updateable<Inventory>().Where(s => invIds.Contains(s.id))
.SetColumns(i => new Inventory()
{
state = newInvs != null && newInvs.Count() > 0 ? "2" : summary.outInState.Equals("out") ? "1" : "0",
bussinessState = inv_states.Item1,
equState = inv_states.Item2,
updateTime = DateTime.Now
}).ExecuteCommand();
//更新单据
if (myOrder != null)
{
//子表
List<LogDetail> details = new List<LogDetail>();
context.Queryable<LogSummary>()
.Where(s => s.orderId.Equals(myOrder.id))
.Select(s => s.DetailList)
.ForEach(s =>
{
details.AddRange(s);
});
var detailSumDic = details
.GroupBy(s => new { s.equipmentSizeId, s.epc })
.Select(s => new { size = s.Key.equipmentSizeId, epc = s.Key.epc })
.GroupBy(s => s.size)
.Select(s => new { size = s.Key, count = s.Count() })
.ToDictionary(s => s.size, s => s.count);
foreach (var item in myOrder.DetailList)
{
if (detailSumDic.ContainsKey(item.equipmentSize))
{
item.actualNum = detailSumDic[item.equipmentSize];
}
}
//主表
decimal sumPrice = Convert.ToDecimal(myOrder.DetailList.Select(s => s.actualNum * s.price).Sum());
myOrder.actualQuantity = summary.number;
myOrder.price = sumPrice;
myOrder.isUpload = 1;
myOrder.orderState = 0;
myOrder.updateTime = DateTime.Now;
var orderrs = context.UpdateNav(myOrder).Include(z1 => z1.DetailList).ExecuteCommand();
//调拨出库删除装备
if (inv_states.Item1.Equals("transfer"))
{
context.Deleteable<Inventory>().Where(s => invIds.Contains(s.id)).ExecuteCommand();
}
}
context.CommitTran();
}
catch (Exception e)
{
return false;
}
}
return true;
}
public async Task<bool> AddHandLogs(LogSummary model, List<Inventory> inv) public async Task<bool> AddHandLogs(LogSummary model, List<Inventory> inv)
{ {
using (var context = _suger.GetDbClient()) using (var context = _suger.GetDbClient())
......
using Models.Table;
using Repositories.IRepository.IBussiness;
using Repositories.IRepository.IUnitOfWork;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Repositories.Repository.Bussiness
{
public class SupplierRepository : BaseRepository<Supplier>, ISupplierRepository
{
public SupplierRepository(ILocalSugarUnitOfWork sugarUnitOfWork) : base(sugarUnitOfWork)
{
}
}
}
using Models.Table;
using Repositories.IRepository.IBussiness;
using Repositories.IRepository.IUnitOfWork;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Repositories.Repository.Bussiness
{
public class WarehouseRepository : BaseRepository<Warehouse>, IWarehouseRepository
{
public WarehouseRepository(ILocalSugarUnitOfWork sugarUnitOfWork) : base(sugarUnitOfWork)
{
}
}
}
...@@ -18,5 +18,7 @@ namespace Services.Interface ...@@ -18,5 +18,7 @@ namespace Services.Interface
/// <returns></returns> /// <returns></returns>
Task<bool> AddLogs(RecordsReq model); Task<bool> AddLogs(RecordsReq model);
Task<bool> AddHandLogs(HandRecordsReq model); Task<bool> AddHandLogs(HandRecordsReq model);
Task<bool> AddChannelLog(OrderMain? myOrder, LogSummary summary, List<Inventory> newInvs);
} }
} }
using Models.Table;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Services.Interface
{
public interface ISupplierService : IBaseServices<Supplier>
{
}
}
using Models.Table;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Services.Interface
{
public interface IWarehouseService : IBaseServices<Warehouse>
{
}
}
...@@ -28,6 +28,44 @@ namespace Services ...@@ -28,6 +28,44 @@ namespace Services
mapper = _mapper; mapper = _mapper;
} }
public Task<bool> AddChannelLog(OrderMain? myOrder, LogSummary summary, List<Inventory> newInvs)
{
var rs1 = "normal";//bussiness_state
var rs2 = "normal";//equ_state
if (myOrder != null)
{
if (myOrder.orderType.Equals("out"))//获取装备应设为的状态
{
switch (myOrder.bussinessType)
{
case "allocate":
rs1 = "transfer";
break;
case "use":
rs1 = "take";
break;
case "remove":
rs1 = "remove";
break;
case "destruction":
rs1 = "destruction";
rs2 = "destory";
break;
case "repair":
rs1 = "repair";
rs2 = "fix";
break;
default:
break;
}
}
}
var inv_states = new Tuple<string, string>(rs1,rs2);
return _logSummaryRepository.AddChannelLog(myOrder, summary, newInvs, inv_states);
}
public Task<bool> AddHandLogs(HandRecordsReq model) public Task<bool> AddHandLogs(HandRecordsReq model)
{ {
LogSummary log = mapper.Map<LogSummary>(model); LogSummary log = mapper.Map<LogSummary>(model);
......
using Models.Table;
using Repositories.IRepository.IBussiness;
using Services.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Services
{
public class SupplierService : BaseService<Supplier>, ISupplierService
{
private readonly ISupplierRepository _supplierRepository;
public SupplierService(ISupplierRepository supplierRepository)
{
base.BaseDal = supplierRepository;
_supplierRepository = supplierRepository;
}
}
}
using Models.Table;
using Repositories.IRepository.IBussiness;
using Services.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Services
{
public class WarehouseService : BaseService<Warehouse>, IWarehouseService
{
private readonly IWarehouseRepository _WarehouseRepository;
public WarehouseService(IWarehouseRepository WarehouseRepository)
{
base.BaseDal = WarehouseRepository;
_WarehouseRepository = WarehouseRepository;
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论