Commit 2c0e009e by guanzhenshan

1:完善获取入库单列表服务

2、完成导入sku服务
3、完成获取仓库列表服务
4、完成保存入库单服务
parent b50d3f5f
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.OMSApi.Common
{
public class GlobalConfig
{
/// <summary>
/// wms api docker独立版服务
/// </summary>
public static string wmsapiurl2 { get; set; }
/// <summary>
/// skums url
/// </summary>
public static string skumsurl { get; set; }
/// <summary>
/// wms url (旧)
/// </summary>
public static string wmsapiurl { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.OMSApi.Models.Common
{
/// <summary>
/// 仓库model
/// </summary>
public class mWarehouse
{
public int Id { get; set; }
public string Code { get; set; }
public string Name { get; set; }
public string ExtendName { get; set; }
public int? TenantId { get; set; }
}
public class requestWarehouse
{
public int code { get; set; }
public string message { get; set; }
public List<mWarehouse> data { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.OMSApi.Models.PutIn
{
public class mCheckSku
{
/// <summary>
/// sku编码
/// </summary>
public string sku { get; set; }
/// <summary>
/// 是否存在
/// </summary>
public bool exists { get; set; }
}
public class request_Sku
{
public request_Sku_result result { get; set; }
public int statusCode { get; set; }
public string message { get; set; }
}
public class request_Sku_result
{
public bool isSucceeded { get; set; }
public string message { get; set; }
public int code { get; set; }
public List<mCheckSku> data { get; set; }
}
}
......@@ -36,7 +36,7 @@ namespace Bailun.OMSApi.Models.PutIn
/// <summary>
/// 仓库信息
/// </summary>
public mWarehouse warehouse { get; set; }
public mPutInWarehouse warehouse { get; set; }
/// <summary>
/// 状态
......@@ -91,7 +91,7 @@ namespace Bailun.OMSApi.Models.PutIn
}
public class mWarehouse
public class mPutInWarehouse
{
public string code { get; set; }
......@@ -107,4 +107,19 @@ namespace Bailun.OMSApi.Models.PutIn
public int confirmQuantity { get; set; }
}
public class mPutIn_Input
{
public string warehousecode { get; set; }
public List<mPutIn_Sku> listsku { get; set; }
}
public class mPutIn_Sku
{
public string sku { get; set; }
public int count { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.OMSApi.Models.PutIn
{
public class mStockInForecastInput
{
/// <summary>
/// 第三方单号 string [Required][StringLength(50)]
/// </summary>
public string ExternalCode { get; set; }
/// <summary>
/// 采购单号
/// </summary>
public string Flag { get; set; }
/// <summary>
/// 仓库编码 string [Required][StringLength(50)]
/// </summary>
public string WarehouseCode { get; set; }
/// <summary>
/// 备注 string
/// </summary>
public string Remark { get; set; }
/// <summary>
/// 创建人 int [Required]
/// </summary>
public int CreatorUserId { get; set; }
/// <summary>
/// Sku 详情
/// </summary>
public List<mStockInForecastOutput_Details> Details { get; set; }
/// <summary>
/// 公司id
/// </summary>
public int TenantId { get; set; }
}
public class mStockInForecastOutput_Details
{
/// <summary>
/// Sku string [Required][StringLength(50)]
/// </summary>
public string Sku { get; set; }
/// <summary>
/// 预报数量 int [Required]
/// </summary>
public int ForecastQuantity { get; set; }
}
public class mStockInForecastOutput
{
/// <summary>
/// 是否成功
/// </summary>
public bool isSuccess { get; set; }
/// <summary>
/// 入库单号
/// </summary>
public string data { get; set; }
public string message { get; set; }
}
/// <summary>
/// 推送产品信息
/// </summary>
public class mPushProductInfoToWmsInput
{
/// <summary>
/// 仓库编码
/// </summary>
public string WarehouseCode { get; set; }
/// <summary>
/// sku编码
/// </summary>
public List<string> Skus { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.OMSApi.Models.PutIn
{
public class search_PutIn
{
public string warehousecode { get; set; }
/// <summary>
/// 当前页
/// </summary>
public int pageindex { get; set; }
/// <summary>
/// 每页记录数
/// </summary>
public int pagesize { get; set; }
/// <summary>
/// 符合条件的记录数
/// </summary>
public int total { get; set; }
}
}
......@@ -6,6 +6,7 @@ using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Linq;
namespace Bailun.OMSApi.Services.PutIn
{
......@@ -19,9 +20,9 @@ namespace Bailun.OMSApi.Services.PutIn
/// <param name="companyid">公司id</param>
/// <param name="total">符合条件的记录数</param>
/// <returns></returns>
public async Task<List<mPutIn>> ListPutin(string warehouse, Page page, int companyid)
public List<mPutIn> ListPutin(search_PutIn m, int companyid)
{
var url = "http://api.wms.bailuntec.com/api/services/app/StorageOrderService/SearchStorageOrderByPage";
var url = Common.GlobalConfig.wmsapiurl+"api/services/app/StorageOrderService/SearchStorageOrderByPage";
var param = new
{
......@@ -29,12 +30,13 @@ namespace Bailun.OMSApi.Services.PutIn
{
Search = new
{
WarehouseCode = warehouse,
WarehouseCode = m.warehousecode,
TenantId = companyid,
},
Page = new
{
page = page.pageindex,
rows = page.pagesize,
page = m.pageindex,
rows = m.pagesize,
}
}
};
......@@ -45,7 +47,7 @@ namespace Bailun.OMSApi.Services.PutIn
{
var obj = JsonConvert.DeserializeObject<CommonRequestPage<mPutIn>>(result);
page.total = obj.data.pageItem.total;
m.total = obj.data.pageItem.total;
return obj.data.items;
}
......@@ -53,11 +55,110 @@ namespace Bailun.OMSApi.Services.PutIn
return null;
}
/// <summary>
/// 新增入库单
/// </summary>
/// <param name="m"></param>
/// <param name="userid">当前用户id</param>
/// <param name="companyid">公司id</param>
/// <returns></returns>
public string AddPutIn(mPutIn_Input m,int userid,int companyid)
{
var listNoCount = m.listsku.Where(a => a.count <= 0).ToList();
if (listNoCount.Count>0)
{
return "Sku:"+string.Join(",",listNoCount.Select(a=>a.sku))+" 的入库数量必须大于0!";
}
var countNoSku = m.listsku.Where(a => string.IsNullOrWhiteSpace(a.sku)).Count();
if (countNoSku > 0)
{
return "Sku编码不能为空!";
}
//检测sku是否可用
try
{
var skuurl = Common.GlobalConfig.skumsurl+"api/sku/productsku/checkskubycompanyasync";
var obj = m.listsku.Select(a => new {
Sku=a.sku,
CompanyId = companyid
});
var checkSku = HttpHelper.NetHelper.HttpPostJson(skuurl, JsonConvert.SerializeObject(obj));
if (!string.IsNullOrEmpty(checkSku))
{
var result_CheckSku = JsonConvert.DeserializeObject<request_Sku>(checkSku);
if (!result_CheckSku.result.isSucceeded)
{
return result_CheckSku.result.message;
}
else if (result_CheckSku.result.data.Where(a => !a.exists).Count() > 0)
{
return "Sku【" + string.Join(",", result_CheckSku.result.data.Where(a => !a.exists).Select(p => p.sku)) + "】不存在。";
}
else if(result_CheckSku.statusCode!=200)
{
return result_CheckSku.message;
}
}
}
catch (Exception ex)
{
return "检测Sku是否存在时出现异常,错误信息:"+ex.Message;
}
try
{
var url = Common.GlobalConfig.wmsapiurl+"api/services/app/StorageOrderService/Forecast";
//入库单号
var no = "P" + (int)((DateTime.Now-TimeZoneInfo.ConvertTimeToUtc(new System.DateTime(1970,1,1))).TotalSeconds);
var obj = new mStockInForecastInput()
{
CreatorUserId = userid,
ExternalCode = no,
Flag = no,
Remark = "OMS入库单",
WarehouseCode = m.warehousecode,
TenantId = companyid,
Details = m.listsku.Select(a => new mStockInForecastOutput_Details
{
ForecastQuantity = a.count,
Sku = a.sku
}).ToList()
};
var param = "{ data:" + JsonConvert.SerializeObject(obj) + " }";
var result = HttpHelper.NetHelper.HttpPostJson(url, param);
if (!string.IsNullOrEmpty(result))
{
mStockInForecastOutput o = JsonConvert.DeserializeObject<mStockInForecastOutput>(result);
if (!o.isSuccess)
{
return o.message;
}
else
{
return "";
}
}
return "上传WMS出现异常,请重试!";
}
catch (Exception ex)
{
return "出现系统错误,错误信息:" + ex.Message;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Bailun.OMSApi.Models.PutIn;
using Bailun.ServiceFabric.Authorize;
using Bailun.ServiceFabric.Core.Extension;
using Bailun.ServiceFabric.Core.Extension.HttpContext;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace Bailun.OMSApi.Areas.Common.Controllers
{
[BailunAuthentication(LoginMode.Enforce)]
[Area("Common")]
public class HomeController : Controller
{
public HomeController()
{
}
public IActionResult Index()
{
return View();
}
/// <summary>
/// 仓库列表
/// </summary>
/// <returns></returns>
[HttpPost]
public JsonResult ListWarehouse()
{
var companyid = HttpContextHelper.Current.User.GetCompanyId();
var param = new {
TenantId = companyid
};
var result = Bailun.OMSApi.Common.HttpHelper.NetHelper.HttpPostJson(OMSApi.Common.GlobalConfig.wmsapiurl2 + "api/WareHouse/GetWareHouse",JsonConvert.SerializeObject(param));
if (string.IsNullOrEmpty(result))
{
return Json(new {
success = false,
msg = "获取仓库列表接口出现异常"
});
}
try
{
var list = new List<Models.Common.mWarehouse>();
var obj = JsonConvert.DeserializeObject<Models.Common.requestWarehouse>(result);
if (obj.data != null && obj.data.Count>0)
{
list = obj.data;
return Json(new
{
success = true,
list = list.Select(a => new { a.Code, a.Name }).Distinct(),
msg = "",
});
}
return Json(new
{
success = false,
msg = "没有获取到仓库列表数据",
});
}
catch (Exception ex)
{
return Json(new {
success = false,
msg = "获取仓库列表出现异常,异常信息:" + ex.Message
});
}
}
}
}
\ No newline at end of file
......@@ -8,9 +8,12 @@ using Bailun.ServiceFabric.Authorize;
using Bailun.ServiceFabric.Core.Extension.HttpContext;
using Bailun.ServiceFabric.Core.Extension;
using Bailun.ServiceFabric.Extension;
using Bailun.OMSApi.Models.PutIn;
using System.Data;
namespace Bailun.OMSApi.Areas.PutIn.Controllers
{
[BailunAuthentication(LoginMode.Enforce)]
[Area("PutIn")]
public class HomeController : Controller
{
......@@ -20,26 +23,114 @@ namespace Bailun.OMSApi.Areas.PutIn.Controllers
/// <param name="warehousecode">仓库编码</param>
/// <param name="page">分页信息</param>
/// <returns></returns>
[BailunAuthentication(LoginMode.Enforce)]
[HttpPost]
public async Task<JsonResult> ListPutIn(string warehousecode,Page page)
public JsonResult ListPutIn([FromBody] search_PutIn m)
{
var companyid = HttpContextHelper.Current?.User?.GetCompanyId();
var result = await new Services.PutIn.PutInServices().ListPutin(warehousecode,page,int.Parse(companyid));
var result = new Services.PutIn.PutInServices().ListPutin(m, int.Parse(companyid));
return Json(new {
list = result,
total = page.total,
page = page.pageindex,
pagesize = page.pagesize
total = m.total,
page = m.pageindex,
pagesize = m.pagesize,
pagecount = (m.total/m.pagesize)+(m.total%m.pagesize==0?0:1),
});
}
/// <summary>
/// 新增入库单
/// </summary>
/// <param name="m"></param>
/// <returns></returns>
[HttpPost]
public JsonResult AddPutin([FromBody]mPutIn_Input m)
{
var companyid = HttpContextHelper.Current.User.GetCompanyId();
var userid = HttpContextHelper.Current.User.GetUid();
var result = new Services.PutIn.PutInServices().AddPutIn(m,userid,int.Parse(companyid));
return Json(new {
success = string.IsNullOrEmpty(result),
msg = result,
});
}
/// <summary>
/// 批量导入sku
/// </summary>
/// <returns></returns>
public JsonResult UploadSku(Microsoft.AspNetCore.Http.IFormFile file)
{
if (file == null)
{
return Json(new
{
success = false,
msg = "请上传文件!"
});
}
//var file = files[0];
Dictionary<string, DataTable> dic = Code.NpolHelper.ExcelToDataTable(file.OpenReadStream(), file.FileName, true);
if (dic.Count > 0)
{
var tb = dic.FirstOrDefault();
var list = new List<Tuple<string,int>>();
for (var i = 0; i < tb.Value.Rows.Count; i++)
{
var row = tb.Value.Rows[i];
try
{
var sku = row["sku"].ToString();
var count = int.Parse(row["数量"].ToString());
list.Add(new Tuple<string, int>(sku, count));
}
catch (Exception ex)
{
return Json(new
{
success = false,
msg = "导入失败,异常信息:" + ex.Message
});
}
}
if (list.Count == 0)
{
return Json(new
{
success = false,
msg = "表格没有数据。",
});
}
return Json(new
{
success = true,
msg = "",
list = list.Select(a=>new {
sku = a.Item1,
count = a.Item2
}),
});
}
else
{
return Json(new
{
success = false,
msg = "请上传文件"
});
}
}
}
}
\ No newline at end of file
......@@ -11,9 +11,13 @@
<PackageReference Include="Bailun.ServiceFabric.Core" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" />
<PackageReference Include="NPOI" Version="2.4.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="Areas\Common\Data\" />
<Folder Include="Areas\Common\Models\" />
<Folder Include="Areas\Common\Views\" />
<Folder Include="Areas\PutIn\Data\" />
<Folder Include="Areas\PutIn\Models\" />
<Folder Include="Areas\PutIn\Views\" />
......
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace Bailun.OMSApi.Code
{
public class NpolHelper
{
#region ExcelToDataTable excel导入到datatable
/// <summary>
/// 将excel导入到datatable
/// </summary>
/// <param name="fs">excel数据流</param>
/// <param name="fileName">excel名称,主要是取后面的后缀判断EXCEL03或者07版本</param>
/// <param name="isColumnName">第一行是否是列名</param>
/// <param name="SheetName">获取某一个工作簿的内容,如果为空的话,则获取所有;如果有多个的话,那么用,分隔</param>
/// <param name="emptySheet">是否要获取为空的工作簿的内容</param>
/// <returns>返回dicDataTable</returns>
public static Dictionary<string, DataTable> ExcelToDataTable(Stream fs, string fileName, bool isColumnName, List<string> SheetName = null, bool emptySheet = true)
{
Dictionary<string, DataTable> dicDataTable = new Dictionary<string, DataTable>();
DataColumn column = null;
DataRow dataRow = null;
IWorkbook workbook = null;
ISheet sheet = null;
IRow row = null;
ICell cell = null;
int startRow = 0;
using (fs)
{
ExcelToDataTable(fs, fileName, isColumnName, ref dicDataTable, ref column, ref dataRow, ref workbook, ref sheet, ref row, ref cell, ref startRow, SheetName, emptySheet);
}
return dicDataTable;
}
/// <summary>
/// 将excel导入到datatable
/// </summary>
/// <param name="filePath">excel路径</param>
/// <param name="isColumnName">第一行是否是列名</param>
/// <param name="SheetName">获取某一个工作簿的内容,如果为空的话,则获取所有;如果有多个的话,那么用,分隔</param>
/// <param name="emptySheet">是否要获取为空的工作簿的内容</param>
/// <returns>返回datatables</returns>
public static Dictionary<string, DataTable> ExcelToDataTable(string filePath, bool isColumnName, List<string> SheetName = null, bool emptySheet = true)
{
Dictionary<string, DataTable> dicDataTable = new Dictionary<string, DataTable>();
FileStream fs = null;
DataColumn column = null;
DataRow dataRow = null;
IWorkbook workbook = null;
ISheet sheet = null;
IRow row = null;
ICell cell = null;
int startRow = 0;
using (fs = File.OpenRead(filePath))
{
ExcelToDataTable(fs, filePath, isColumnName, ref dicDataTable, ref column, ref dataRow, ref workbook, ref sheet, ref row, ref cell, ref startRow, SheetName, emptySheet);
}
return dicDataTable;
}
#endregion
#region privateExcelToDataTable
private static void ExcelToDataTable(Stream fs, string fileName, bool isColumnName, ref Dictionary<string, DataTable> dicDataTable, ref DataColumn column, ref DataRow dataRow, ref IWorkbook workbook, ref ISheet sheet, ref IRow row, ref ICell cell, ref int startRow, List<string> SheetName, bool emptySheet)
{
try
{
// 2007版本
if (fileName.ToLower().IndexOf(".xlsx") > 0) workbook = new XSSFWorkbook(fs);
// 2003版本
else if (fileName.ToLower().IndexOf(".xls") > 0) workbook = new HSSFWorkbook(fs);
DataTable dataTable = null;
if (workbook != null)
{
for (int k = 0; k < workbook.NumberOfSheets; k++)
{
sheet = workbook.GetSheetAt(k);
dataTable = new DataTable();
if (sheet != null)
{
string sName = sheet.SheetName;
if (SheetName != null && SheetName.Count > 0 && !SheetName.Contains(sName)) { continue; }
int rowCount = sheet.LastRowNum;//总行数
if (rowCount > 0)
{
IRow firstRow = sheet.GetRow(0);//第一行
int cellCount = firstRow.LastCellNum;//列数
//构建datatable的列
if (isColumnName)
{
startRow = 1;//如果第一行是列名,则从第二行开始读取
for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
{
cell = firstRow.GetCell(i);
if (cell != null)
{
if (cell.StringCellValue != null)
{
column = new DataColumn(cell.StringCellValue);
dataTable.Columns.Add(column);
}
}
else
{
cellCount = i;
break;
}
}
}
else
{
for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
{
column = new DataColumn("column" + (i + 1));
dataTable.Columns.Add(column);
}
}
//填充行
for (int i = startRow; i <= rowCount; ++i)
{
row = sheet.GetRow(i);
if (row == null) continue;
try
{
dataRow = dataTable.NewRow();
for (int j = row.FirstCellNum; j < cellCount; ++j)
{
cell = row.GetCell(j);
if (cell == null) { dataRow[j] = ""; }
else
{
switch (cell.CellType)
{
case CellType.Blank: dataRow[j] = ""; break;
case CellType.Numeric:
short format = cell.CellStyle.DataFormat;
if (format == 14 || format == 31 || format == 57 || format == 58 || HSSFDateUtil.IsCellDateFormatted(cell)) dataRow[j] = cell.DateCellValue.ToString("yyyy-MM-dd HH:mm:ss");
else dataRow[j] = cell.NumericCellValue;
break;
case CellType.String: dataRow[j] = cell.StringCellValue; break;
}
}
}
dataTable.Rows.Add(dataRow);
}
catch (Exception ex)
{
throw ex;
}
}
}
if (!emptySheet && !SheetName.Contains(sName) && dataTable.Rows.Count == 0) { continue; }
dicDataTable.Add(sName, dataTable);
}
}
}
}
catch (Exception ex)
{
if (fs != null)
{
fs.Close();
}
}
}
#endregion
}
}
......@@ -17,13 +17,13 @@ namespace Bailun.OMSApi
{
public class Startup
{
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
......@@ -38,6 +38,7 @@ namespace Bailun.OMSApi
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
......@@ -69,6 +70,11 @@ namespace Bailun.OMSApi
ConfigManagerConf.SetConfiguration(Configuration);
app.UseStaticHttpContext();
Common.GlobalConfig.wmsapiurl2 = Configuration["wmsapiurl2"].ToString();
Common.GlobalConfig.skumsurl = Configuration["skumsurl"].ToString();
Common.GlobalConfig.wmsapiurl = Configuration["wmsapiurl"].ToString();
}
}
}
......@@ -8,6 +8,9 @@
"AppSetting": {
"SsoUrl": "http://sso.bailuntec.com", //֤url
"AuthType": "debug" //Ƿdebugģʽ
}
},
"wmsapiurl": "http://api.wms.bailuntec.com/",
"skumsurl": "http://api.skums.bailuntec.com/",
"wmsapiurl2": "http://134.175.215.43:8001/"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment