You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
345 lines
14 KiB
345 lines
14 KiB
using Nancy;
|
|
using Nancy.IO;
|
|
using Newtonsoft.Json;
|
|
using SSWMS.Common;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Markup;
|
|
|
|
namespace SSWMS.Server
|
|
{
|
|
class WebNancyModule : NancyModule
|
|
{
|
|
public WebNancyModule()
|
|
{
|
|
After.AddItemToEndOfPipeline(item => item.Response
|
|
.WithHeader("Access-Control-Allow-Origin", "*")
|
|
.WithHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS")
|
|
.WithHeader("Access-Control-Allow-Headers", "Accept, Origin, Content-type"));
|
|
Get["/"] = _ => "Warehouse Management System";
|
|
// Tablet
|
|
Post["/Tablet/InCell"] = _ =>
|
|
{
|
|
bool success = true;
|
|
string message = string.Empty;
|
|
string sStockBarcode = string.Empty;
|
|
try
|
|
{
|
|
RequestStream stream = this.Request.Body;
|
|
int length = (int)stream.Length;
|
|
byte[] buffer = new byte[length];
|
|
stream.Read(buffer, 0, length);
|
|
string body = Encoding.UTF8.GetString(buffer);
|
|
InCellData data = JsonConvert.DeserializeObject<InCellData>(body);
|
|
MANAGE_MAIN mm = S_BaseService._P_MANAGE_MAIN.GetModelByInSend(data.deviceCode);
|
|
if (mm != null)
|
|
{
|
|
success = S_BaseService._S_ControlService.ManageDelete(mm.MANAGE_ID, 0, out message);
|
|
message = $"入库站台 {data.deviceCode} 存在入库任务并且删除失败 {message}";
|
|
}
|
|
if (success)
|
|
{
|
|
sStockBarcode = data.stockBarcode;
|
|
if (string.IsNullOrWhiteSpace(sStockBarcode))
|
|
{
|
|
success = false;
|
|
message = "扫码异常";
|
|
}
|
|
else if (data.stockBarcode.StartsWith("{"))
|
|
{
|
|
StockBarcodeData stockBarcodeData = JsonConvert.DeserializeObject<StockBarcodeData>(sStockBarcode);
|
|
if (stockBarcodeData != null)
|
|
{
|
|
sStockBarcode = stockBarcodeData.salverNumver;
|
|
}
|
|
}
|
|
else if (sStockBarcode.StartsWith("\"") &&
|
|
sStockBarcode.Length == 22)
|
|
{
|
|
sStockBarcode = sStockBarcode.Substring(1, 20);
|
|
}
|
|
if (!StringUtils.StockBarcodeValidate(sStockBarcode))
|
|
{
|
|
success = false;
|
|
message = $"托盘条码 {sStockBarcode} 格式错误";
|
|
}
|
|
}
|
|
if (success)
|
|
{
|
|
List<STORAGE_LIST> lStorageList = S_BaseService._S_ERPService.ERPGetBarCode(sStockBarcode, out message);
|
|
if (lStorageList == null || lStorageList.Count == 0)
|
|
{
|
|
success = false;
|
|
}
|
|
else
|
|
{
|
|
bool bManual = true;
|
|
if (data.deviceCode == "19015" ||
|
|
data.deviceCode == "19016" ||
|
|
data.deviceCode == "19017" ||
|
|
data.deviceCode == "19018")
|
|
{
|
|
bManual = false;
|
|
}
|
|
success = S_BaseService._S_ManageService.ManageInCell(new STORAGE_MAIN()
|
|
{
|
|
STOCK_BARCODE = sStockBarcode,
|
|
CELL_MODEL = SystemCode.CELL_MODEL.Low,
|
|
CELL_CODE = data.deviceCode,
|
|
}, lStorageList, string.Empty, bManual, "PDA", out message);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
success = false;
|
|
message = $"异常 {ex.Message}";
|
|
}
|
|
return JsonConvert.SerializeObject(new ResponseData()
|
|
{
|
|
success = success,
|
|
message = message,
|
|
data = sStockBarcode
|
|
});
|
|
};
|
|
|
|
// ERP
|
|
Post["/planout"] = _ =>
|
|
{
|
|
bool success = true;
|
|
string message = string.Empty;
|
|
try
|
|
{
|
|
RequestStream stream = this.Request.Body;
|
|
int length = (int)stream.Length;
|
|
byte[] buffer = new byte[length];
|
|
stream.Read(buffer, 0, length);
|
|
string body = Encoding.UTF8.GetString(buffer);
|
|
MainWindow.log.Debug($"planout {body}");
|
|
PlanOutData data = JsonConvert.DeserializeObject<PlanOutData>(body);
|
|
if (S_BaseService._P_PLAN_MAIN.GetModelByPlanCode(data.pickingNo) == null)
|
|
{
|
|
//Task.Factory.StartNew(() =>
|
|
//{
|
|
try
|
|
{
|
|
S_BaseService._P_Base_House.BeginTransaction();
|
|
string sPlanStatus = SystemCode.PLAN_STATUS.Waiting;
|
|
string sCurrentTime = StringUtils.GetCurrentTime();
|
|
string sBeginTime = string.Empty;
|
|
if (!string.IsNullOrWhiteSpace(data.shipmentPort))
|
|
{
|
|
if (S_BaseService._P_MANAGE_MAIN.GetListByPlanOut(data.shipmentPort).Count == 0)
|
|
{
|
|
sPlanStatus = SystemCode.PLAN_STATUS.Auto;
|
|
sBeginTime = sCurrentTime;
|
|
}
|
|
}
|
|
PLAN_MAIN pm = new PLAN_MAIN()
|
|
{
|
|
PLAN_TYPE = SystemCode.PLAN_TYPE.PlanOut,
|
|
PLAN_CODE = data.pickingNo,
|
|
PLAN_CREATE_TIME = sCurrentTime,
|
|
PLAN_BEGIN_TIME = sBeginTime,
|
|
PLAN_STATUS = sPlanStatus,
|
|
PLAN_PROPERTY_01 = data.customerCode,
|
|
PLAN_PROPERTY_02 = data.customerName,
|
|
PLAN_PROPERTY_03 = data.deliveryPlatform,
|
|
PLAN_PROPERTY_04 = data.priority.ToString(),
|
|
PLAN_PROPERTY_05 = data.type.ToString(),
|
|
PLAN_STATION = data.shipmentPort,
|
|
PLAN_REMARK = data.remark,
|
|
PLAN_CREATER = data.createName
|
|
};
|
|
S_BaseService._P_PLAN_MAIN.Add(pm);
|
|
foreach (string sGoodsBarcode in data.salverList)
|
|
{
|
|
S_BaseService._P_PLAN_LIST.Add(new PLAN_LIST()
|
|
{
|
|
PLAN_ID = pm.PLAN_ID,
|
|
GOODS_ID = SystemCode.GOODS_ID.Goods,
|
|
GOODS_BARCODE = sGoodsBarcode,
|
|
PLAN_LIST_QUANTITY = 1,
|
|
PLAN_LIST_FINISHED_QUANTITY = 0,
|
|
});
|
|
}
|
|
S_BaseService._P_Base_House.CommitTransaction();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
S_BaseService._P_Base_House.RollBackTransaction();
|
|
S_BaseService._S_SystemService.AddLog("ERP 异常", $"生成计划 {ex.Message}", "WMS");
|
|
MainWindow.log.Error($"ERP 异常 planout {ex}");
|
|
success = false;
|
|
message = ex.Message;
|
|
}
|
|
//});
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
S_BaseService._S_SystemService.AddLog("ERP 异常", $"解析数据 {ex.Message}", "WMS");
|
|
success = false;
|
|
message = ex.Message;
|
|
}
|
|
return this.Response.AsJson(new ResponseDataERP()
|
|
{
|
|
code = success ? 200 : 0,
|
|
message = message,
|
|
data = null
|
|
});
|
|
};
|
|
Post["/getPositionPlace"] = _ =>
|
|
{
|
|
string sPositionPlace = string.Empty;
|
|
try
|
|
{
|
|
RequestStream stream = this.Request.Body;
|
|
int length = (int)stream.Length;
|
|
byte[] buffer = new byte[length];
|
|
stream.Read(buffer, 0, length);
|
|
string body = Encoding.UTF8.GetString(buffer);
|
|
MainWindow.log.Debug($"getPositionPlace {body}");
|
|
SalverNumberData data = JsonConvert.DeserializeObject<SalverNumberData>(body);
|
|
if (!string.IsNullOrWhiteSpace(data.salverNumber))
|
|
{
|
|
STORAGE_MAIN sm = S_BaseService._P_STORAGE_MAIN.GetModelByStockBarcode(data.salverNumber);
|
|
if (sm != null)
|
|
{
|
|
sPositionPlace = sm.CELL_CODE;
|
|
if (sPositionPlace.Contains("-"))
|
|
{
|
|
WH_CELL wc = S_BaseService._P_WH_CELL.GetModelByCellCode(sm.CELL_CODE);
|
|
if (wc != null)
|
|
{
|
|
sPositionPlace = wc.CELL_NAME;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
S_BaseService._S_SystemService.AddLog("ERP 异常", $"getPositionPlace {ex.Message}", "ERP");
|
|
}
|
|
return this.Response.AsJson(new ResponseDataERP()
|
|
{
|
|
code = 200,
|
|
message = string.Empty,
|
|
data = new PositionPlaceData()
|
|
{
|
|
positionPlace = sPositionPlace
|
|
}
|
|
});
|
|
};
|
|
}
|
|
}
|
|
|
|
public class ResponseDataERP
|
|
{
|
|
public int code { get; set; }
|
|
public string message { get; set; }
|
|
public object data { get; set; }
|
|
public object data1 { get; set; }
|
|
}
|
|
|
|
public class PlanOutData
|
|
{
|
|
public string createName { get; set; }
|
|
public string customerCode { get; set; }
|
|
public string customerName { get; set; }
|
|
public string deliveryPlatform { get; set; }
|
|
public string pickingNo { get; set; }
|
|
public int priority { get; set; }
|
|
public string remark { get; set; }
|
|
public string[] salverList { get; set; }
|
|
public string shipmentPort { get; set; }
|
|
public int type { get; set; }
|
|
}
|
|
|
|
public class SalverNumberData
|
|
{
|
|
public string salverNumber { get; set; }
|
|
}
|
|
|
|
public class PositionPlaceData
|
|
{
|
|
public string positionPlace { get; set; }
|
|
}
|
|
|
|
public class GetBarCodeData
|
|
{
|
|
public string pkcorp { get; set; }
|
|
public string salverNumber { get; set; }
|
|
public string inTime { get; set; }
|
|
public string outTime { get; set; }
|
|
public string warehouseCode { get; set; }
|
|
public string locationCode { get; set; }
|
|
public string positionPlace { get; set; }
|
|
public string status { get; set; }
|
|
public string salverWeight { get; set; }
|
|
public string productWeight { get; set; }
|
|
public string productName { get; set; }
|
|
public string productPk { get; set; }
|
|
public string productCode { get; set; }
|
|
public string productLevel { get; set; }
|
|
public string customerCode { get; set; }
|
|
public string customerName { get; set; }
|
|
public string packKind { get; set; }
|
|
public string packageType { get; set; }
|
|
public string numberRange { get; set; }
|
|
public string isFixedWeight { get; set; }
|
|
public string tradeType { get; set; }
|
|
public string salverBoardType { get; set; }
|
|
public string rollsAmount { get; set; }
|
|
public string salverType { get; set; }
|
|
public string p135Salver { get; set; }
|
|
public string towerType { get; set; }
|
|
public string netWeight { get; set; }
|
|
public string roughWeight { get; set; }
|
|
public string type { get; set; }
|
|
public string transferLine { get; set; }
|
|
}
|
|
|
|
public class StockBarcodeData
|
|
{
|
|
public string netWeight { get; set; }
|
|
public string productName { get; set; }
|
|
public string salverNumver { get; set; }
|
|
}
|
|
|
|
public class ResponseData
|
|
{
|
|
public bool success { get; set; }
|
|
public string message { get; set; }
|
|
public object data { get; set; }
|
|
}
|
|
|
|
public class LoginData
|
|
{
|
|
public string userCode { get; set; }
|
|
public string password { get; set; }
|
|
}
|
|
|
|
public class ManageStationData
|
|
{
|
|
public string stockBarcode { get; set; }
|
|
public StorageListData[] storageList { get; set; }
|
|
public string userName { get; set; }
|
|
}
|
|
|
|
public class StorageListData
|
|
{
|
|
public string goodsBarcode { get; set; }
|
|
public decimal quantity { get; set; }
|
|
}
|
|
|
|
public class InCellData
|
|
{
|
|
public string deviceCode { get; set; }
|
|
public string stockBarcode { get; set; }
|
|
}
|
|
}
|