Commit 14c7e74d by guanzhenshan

增加物流账单流水模块和解析数据

parent 73276365
......@@ -65,6 +65,13 @@ namespace Bailun.DC.Models.DataWareHouse
/// </summary>
public DateTime createtime { get; set; }
public string website { get; set; }
public string col_orderno { get; set; }
public string month { get; set; }
public string createuser { get; set; }
}
}
......@@ -18,6 +18,7 @@ namespace Bailun.DC.Models.DataWareHouse
/// </summary>
public string platform { get; set; }
public string website { get; set; }
/// <summary>
///
......
......@@ -29,7 +29,10 @@ namespace Bailun.DC.Models.DataWareHouse
/// </summary>
public string cols { get; set; }
/// <summary>
/// 数据类型,1:销售平台的,2:物流费用
/// </summary>
public int datatype { get; set; }
}
}
......@@ -85,5 +85,10 @@ namespace Bailun.DC.Models.DataWareHouse
/// </summary>
public string versionno { get; set; }
/// <summary>
/// 数据类型,1:销售平台的,2:物流费用
/// </summary>
public int datatype { get; set; }
}
}
......@@ -38,7 +38,7 @@ namespace Bailun.DC.Services.DataWareHouse
/// <param name="end"></param>
/// <param name="total"></param>
/// <returns></returns>
public List<flowing_logistic> ListFlowingLogistic(int page,int pagesize,string platform,DateTime? start,DateTime? end,string orderno,ref int total)
public List<flowing_logistic> ListFlowingLogistic(int page,int pagesize,string platform, string website, DateTime? start,DateTime? end,string orderno,ref int total)
{
var sql = "select * from flowing_logistic where 1=1";
var sqlparam = new DynamicParameters();
......@@ -49,7 +49,13 @@ namespace Bailun.DC.Services.DataWareHouse
sqlparam.Add("platform", platform);
}
if(start.HasValue)
if (!string.IsNullOrEmpty(website))
{
sql += " and website=@website";
sqlparam.Add("website", website);
}
if (start.HasValue)
{
sql += $" and datatime>='{start.Value.ToString("yyyy-MM-dd")}'";
}
......@@ -88,5 +94,52 @@ namespace Bailun.DC.Services.DataWareHouse
}
/// <summary>
/// 保存流水信息
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
public string InsertOrderBilling(List<Models.DataWareHouse.flowing_logistic> list)
{
try
{
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString_DW))
{
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
}
foreach (var item in list)
{
SaveOrderBill(cn, item);
}
}
return "";
}
catch (Exception ex)
{
return ex.Message;
}
}
public void SaveOrderBill(MySqlConnection cn, flowing_logistic m)
{
try
{
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
}
cn.Insert(m);
}
catch (Exception ex)
{
SaveOrderBill(cn, m);
}
}
}
}
......@@ -86,6 +86,25 @@ namespace Bailun.DC.Services.DataWareHouse
return "";
}
/// <summary>
/// 获取费用解析财务流水配置
/// </summary>
/// <param name="datatype"></param>
/// <returns></returns>
public List<order_fee_config> ListOrderFeeConfig(int datatype)
{
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString_DW))
{
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
}
return cn.Query<order_fee_config>("select * from order_fee_config where datatype="+datatype).ToList();
}
}
#endregion
public List<order_fee_col> ListOrderFeeCol()
......
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
namespace Bailun.DC.Web.Areas.DataWareHouse.Controllers
{
[Area("DataWareHouse")]
public class LogisticsController : Controller
public class LogisticsController : Base.BaseController
{
public IActionResult List(string platform)
{
var listconfig = new Services.DataWareHouse.LogisticServices().ListLogisticConfig();
var listconfig = new Services.DataWareHouse.PlatformOrderFeeServices().ListOrderFeeConfig(2);
ViewBag.listconfig = listconfig;
ViewBag.listconfig = listconfig.Select(a=>a.platform).Distinct().ToList();
ViewBag.platform = platform;
ViewBag.sites = listconfig.Where(a=>a.platform==platform).Select(b=>b.website).Distinct().Where(c=>!string.IsNullOrEmpty(c)).ToList();
return View();
}
......@@ -30,7 +32,7 @@ namespace Bailun.DC.Web.Areas.DataWareHouse.Controllers
/// <param name="pagesize"></param>
/// <returns></returns>
[HttpPost]
public JsonResult ListFlowingJson(int page, string platform, DateTime? start, DateTime? end, string orderno, int pagesize = 25)
public JsonResult ListFlowingJson(int page, string platform,string website, DateTime? start, DateTime? end, string orderno, int pagesize = 25)
{
var total = 0;
if (page <= 0)
......@@ -38,7 +40,7 @@ namespace Bailun.DC.Web.Areas.DataWareHouse.Controllers
page = 1;
}
var obj = new Services.DataWareHouse.LogisticServices().ListFlowingLogistic(page, pagesize, platform, start, end,orderno, ref total);
var obj = new Services.DataWareHouse.LogisticServices().ListFlowingLogistic(page, pagesize, platform,website, start, end,orderno, ref total);
;
var list = obj.Select(a => new {
a.createtime,
......@@ -58,7 +60,87 @@ namespace Bailun.DC.Web.Areas.DataWareHouse.Controllers
}
/// <summary>
/// 上传物流流水数据
/// </summary>
/// <param name="platform"></param>
/// <returns></returns>
[RequestSizeLimit(100_000_000)]
public JsonResult UploadFlowing(string platform,string website, string month)
{
if (string.IsNullOrEmpty(platform))
{
return Json(new
{
success = false,
msg = "请选择平台"
});
}
if (string.IsNullOrEmpty(month))
{
return Json(new
{
success = false,
msg = "请选择月份后再导入"
});
}
if (Request.Form.Files.Count == 0)
{
return Json(new
{
success = false,
msg = "请上传文件!"
});
}
//var user = HttpContextHelper.Current?.User;
var file = Request.Form.Files[0];
Dictionary<string, DataTable> dic = Base.NpolHelper.ExcelToDataTable(file.OpenReadStream(), file.FileName, true);
if (dic.Count > 0)
{
var tb = dic.FirstOrDefault();
var list = Dtb2Json(tb.Value);
var listOrders = new List<Models.DataWareHouse.flowing_logistic>();
foreach (var item in list)
{
//保存数据
var m = new Models.DataWareHouse.flowing_logistic
{
createtime = DateTime.Now,
jsondata = Newtonsoft.Json.JsonConvert.SerializeObject(item),
month = month,
platformtype = platform,
website = website,
createuser = "页面上传",
datatype = 1,
datatypename = "物流账单",
account = "",
};
listOrders.Add(m);
}
var result = new Services.DataWareHouse.LogisticServices().InsertOrderBilling(listOrders);
return Json(new
{
success = string.IsNullOrEmpty(result),
msg = result
});
}
return Json(new
{
success = false,
msg = "无法识别表格的数据,请下载模版重新导入,或者检查下表格数据是否正确。",
});
}
}
}
......@@ -559,37 +559,5 @@ namespace Bailun.DC.Web.Areas.DataWareHouse.Controllers
#endregion
#region 私有方法
private System.Collections.ArrayList Dtb2Json(DataTable dtb)
{
System.Collections.ArrayList dic = new System.Collections.ArrayList();
foreach (DataRow dr in dtb.Rows)
{
System.Collections.Generic.Dictionary<string, object> drow = new System.Collections.Generic.Dictionary<string, object>();
foreach (DataColumn dc in dtb.Columns)
{
drow.Add(dc.ColumnName, dr[dc.ColumnName]);
}
//判断是否空行,如果null值
if (drow.ToList().Where(a => a.Value == null).Count() == drow.Count || drow.FirstOrDefault().Value == null)
{
continue;
}
else
{
dic.Add(drow);
}
}
return dic;
}
#endregion
}
}
......@@ -16,16 +16,29 @@
<div id="sel_platform_contain" class="form-group" style="display:none;">
<label>平台:</label>
<select id="platform" name="platform" class="form-control" style="width:120px">
@if (ViewBag.listconfig.Count > 0)
{
foreach (var item in ViewBag.listconfig)
{
@if (ViewBag.listconfig.Count > 0)
{
foreach (var item in ViewBag.listconfig)
{
<option value="@item">@item</option>
}
}
}
}
</select>
</div>
<div class="form-group">
站点:
<div data-toggle="buttons-checkbox" class="btn-group">
@foreach (var item in ViewBag.sites)
{
//<option value="@item">@item</option>
<button class="btn btn-info wsites" type="button" aria-pressed="false" onclick="selWebsite('@item',this)">@item</button>
}
</div>
</div>
<div class="form-group" style="margin-left:10px">
<label>账单月份</label>
<input id="month" name="month" class="form-control" style="width:135px" placeholder="账单归属月份" />
</div>
<div class="form-group" style="margin-left:10px">
<label>时间</label>
@*<input id="month" name="month" class="form-control" style="width:100px" value="@(DateTime.Now.AddMonths(-1).ToString("yyyy-MM"))" />*@
......@@ -194,8 +207,14 @@
var tb;
var current_page = 1;
var platform = '@(ViewBag.platform)';
var website = '';
var websitecount = '@(ViewBag.sites.Count)';
var BASE_URL = '@(Url.Content("~/js/webuploader-0.1.5/"))';
var month = '';
var uploader;
$(document).ready(function () {
......@@ -207,6 +226,9 @@
$('#platform').change(function () {
platform = $('#platform').val();
initUpload();
//获取平台站点
getWebsite();
})
}
......@@ -215,6 +237,17 @@
laydate.render({ elem: '#start' });
laydate.render({ elem: '#end' });
laydate.render({
elem: '#month', type: 'month', done: function (value, date, endDate) {
console.log(value); //得到日期生成的值,如:2017-08-18
console.log(date); //得到日期时间对象:{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
console.log(endDate); //得结束的日期时间对象,开启范围选择(range: true)才会返回。对象成员同上。
month = value;
initUpload();
}
});
initUpload();
......@@ -232,7 +265,6 @@
}
});*@
})
function list() {
......@@ -263,7 +295,7 @@
$.submit({
url: '@Url.Content("~/DataWareHouse/Logistics/ListFlowingJson")',
type:'POST',
paramData: 'page=' + current_page + '&platform=' + platform + '&start=' + start + '&end=' + end + '&orderno=' + orderno ,
paramData: 'page=' + current_page + '&platform=' + platform + '&start=' + start + '&end=' + end + '&orderno=' + orderno + '&website=' + website ,
func: function (result) {
layer.close(load_index)
$('#tb_head').html('');
......@@ -336,7 +368,7 @@
//}
uploadfile('btn_Upload',
'@Url.Content("~/DataWareHouse/PlatformOrder/UploadOrderBilling")' + '?platform=' + platform,
'@Url.Content("~/DataWareHouse/Logistics/UploadFlowing")' + '?platform=' + platform + '&month=' + month + '&website=' + website,
function(result){
if(result.success)
{
......@@ -380,11 +412,27 @@
}
function isJson (obj) {
var isjson = typeof (obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() == "[object object]" && !obj.length;
return isjson;
}
function selWebsite(site, data) {
website = site;
$('.wsites').each(function () {
$(this).attr('aria-pressed', 'false');
$(this).removeClass('active');
})
$(data).prop('aria-pressed', 'true');
list();
initUpload();
}
function ExportCSV() {
//var website = $('#website').val();
//var month = $('#month').val();
......@@ -402,7 +450,7 @@
return false;
}
window.open('@Url.Content("~/DataWareHouse/PlatformOrder/ExportOrderBillings")' + '?platform=' + platform + '&start=' + start + '&end=' + end + '&orderno=' + orderno);
//window.open('@Url.Content("~/DataWareHouse/PlatformOrder/ExportOrderBillings")' + '?platform=' + platform + '&start=' + start + '&end=' + end + '&orderno=' + orderno);
}
function downloadTemplate() {
......@@ -415,13 +463,13 @@
var end = $('#end').val();
var orderno = $('#orderno').val();
window.open('@Url.Content("~/DataWareHouse/PlatformOrder/DownLoadOrderBillingTemplate?platform=")' + platform + '&start=' + start + '&end=' + end ,'_blank');
//window.open('@Url.Content("~/DataWareHouse/PlatformOrder/DownLoadOrderBillingTemplate?platform=")' + platform + '&start=' + start + '&end=' + end ,'_blank');
}
function uploadfile(id,url,callback)
{
var uploader = new WebUploader.Uploader({
uploader = new WebUploader.Uploader({
// swf文件路径
swf: BASE_URL + 'Uploader.swf',
// 文件接收服务端。
......@@ -449,6 +497,74 @@
uploader.on('uploadError', function (file) {
layer.msg("上传出错");
});
uploader.register({
"before-send-file": "beforeSendFile",
"before-send": "beforeSend",
"after-send-file": "afterSendFile",
}, {
//时间点1:所有分块进行上传之前调用此函数
beforeSendFile: function (file) {
var deferred = WebUploader.Deferred();
//1、计算文件的唯一标记,用于断点续传
(new WebUploader.Uploader()).md5File(file, 0, 2 * 1024 * 1024)
.progress(function (percentage) {
})
.then(function (val) {
fileMd5 = val;
//获取文件信息后进入下一步
deferred.resolve();
});
return deferred.promise();
},
//时间点2:如果有分块上传,则每个分块上传之前调用此函数
beforeSend: function (block) {
var deferred = WebUploader.Deferred();
if (videoAdd[block.file.id] > block.start) {
// 分块存在,跳过
deferred.reject();
} else {
// 分块不存在或不完整,重新发送该分块内容
this.owner.options.formData = {
start: block.start,//设置视频上传的start点
fileMd5: videoMd5[block.file.id]//设置视频上传的唯一标识MD5
}
deferred.resolve();
}
return deferred.promise();
},
//时间点3:所有分块上传成功后调用此函数
afterSendFile: function (file, response) {
//分块上传成功,执行成功回调
successHandler(file, response, fileArr);
}
});
}
function getWebsite() {
$.submit({
url: '@Url.Content("~/DataWareHouse/PlatformOrder/ListWebsite?platform=")' + $('#platform').val(),
paramData: '',
type:'POST',
func: function (result) {
$('#website').html('<option value="">请选择站点</option>');
if (result.success) {
if (result.data.length > 0) {
for (var i in result.data) {
$('#website').append('<option value="' + result.data[i] + '">' + result.data[i] + '</option>');
}
}
}
else {
alert(result.msg);
}
}
})
}
......
......@@ -158,5 +158,33 @@ namespace Bailun.DC.Web.Base
#endregion
public System.Collections.ArrayList Dtb2Json(DataTable dtb)
{
System.Collections.ArrayList dic = new System.Collections.ArrayList();
foreach (DataRow dr in dtb.Rows)
{
System.Collections.Generic.Dictionary<string, object> drow = new System.Collections.Generic.Dictionary<string, object>();
foreach (DataColumn dc in dtb.Columns)
{
drow.Add(dc.ColumnName, dr[dc.ColumnName]);
}
//判断是否空行,如果null值
if (drow.ToList().Where(a => a.Value == null).Count() == drow.Count || drow.FirstOrDefault().Value == null)
{
continue;
}
else
{
dic.Add(drow);
}
}
return dic;
}
}
}
......@@ -387,7 +387,8 @@ namespace Bailun.DC.Web.Controllers
platform = platform,
website = website,
currency = currency,
delstatus = 0
delstatus = 0,
datatype=1,
};
list.Add(m);
......@@ -400,6 +401,7 @@ namespace Bailun.DC.Web.Controllers
cols = string.Join("||",cols.Distinct().ToList()),
platform = platform,
website = website,
datatype=1,
}});
if (!string.IsNullOrEmpty(result))
......@@ -419,6 +421,141 @@ namespace Bailun.DC.Web.Controllers
return Content("OK");
}
/// <summary>
/// 保存物流商费用取数配置
/// </summary>
/// <returns></returns>
public ActionResult UploadLogisticFeeConfig()
{
if (Request.Form.Files.Count == 0)
{
return Json(new
{
success = false,
msg = "请上传文件!"
});
}
//var user = HttpContextHelper.Current?.User;
var file = Request.Form.Files[0];
Dictionary<string, DataTable> dic = Base.NpolHelper.ExcelToDataTable(file.OpenReadStream(), file.FileName, true);
if (dic.Count > 0)
{
var tb = dic.FirstOrDefault();
var list = new List<Bailun.DC.Models.DataWareHouse.order_fee_config>();
var columns = tb.Value.Columns;
var _service = new Services.DataWareHouse.PlatformOrderFeeServices();
//cols.Add(columns[3].ColumnName.Split('-')[1]);
for (var i = 0; i < tb.Value.Rows.Count; i++)
{
//解析行
var row = tb.Value.Rows[i];
if (row == null || string.IsNullOrEmpty(row[0].ToString()))
{
continue;
}
var cols = new List<string>();
cols.Add(row["判断字段1"].ToString().Trim());
cols.Add(row["判断字段2"].ToString().Trim());
var type = row["具体字段1"].ToString();
var description = row["具体字段2"].ToString();
var fulfillment = "";
var valcol = row["取数列"].ToString();
var feetype = "";
var category = row["科目名称"].ToString();
var subjectcode = row["科目编码"].ToString();
var projectcode = "";
var datacentercol = row["数据中心字段归集"].ToString();
var note = "";
var currency = row["币别"].ToString();
var platform = row["物流商"].ToString();
var website = row["分表"].ToString();
//格式化组合条件
var _condition = "{";
if (!string.IsNullOrEmpty(type) && type!="/")
{
_condition += "\"" + row["判断字段1"].ToString() + "\":\"" + type.Trim() + "\",";
}
if (!string.IsNullOrEmpty(description) && description != "/")
{
_condition += "\"" + row["判断字段2"].ToString() + "\":\"" + description.Trim() + "\",";
}
if (!string.IsNullOrEmpty(fulfillment))
{
_condition += "\"" + columns[3].ColumnName.Split('-')[1] + "\":\"" + fulfillment.Trim() + "\",";
}
if (_condition.Length > 1)
{
_condition = _condition.Substring(0, _condition.Length - 1);
}
_condition += "}";
//需要解析的字段
cols.Add(valcol);
//保存需要解析的字段
var _col_result = _service.SaveOrderFeeCol(new List<Models.DataWareHouse.order_fee_col> { new Models.DataWareHouse.order_fee_col {
cols = string.Join("||",cols.Distinct().Where(b=>b!="/" && !string.IsNullOrEmpty(b)).ToList()),
platform = platform,
website = website,
datatype=2,
}});
if (!string.IsNullOrEmpty(_col_result))
{
return Content("保存字段解析配置异常,请确认字段格式是否正确。");
}
var m = new Models.DataWareHouse.order_fee_config
{
subjectcode = subjectcode,
colname_fee = valcol,
condition_forfee = _condition,
datacenter_col = datacentercol,
feetype = feetype,
financecategory = category,
note = note,
projectcode = projectcode,
platform = platform,
website = website,
currency = currency,
delstatus = 0,
datatype=2
};
list.Add(m);
}
//保存取数逻辑条件
var result = _service.SaveOrderFeeConfig(list);
if (!string.IsNullOrEmpty(result))
{
return Content("保存平台费用取数逻辑配置异常:" + result);
}
}
return Content("OK");
}
}
}
\ No newline at end of file
......@@ -4,8 +4,9 @@
ViewBag.Nav = new string[] { "销售平台流水", (ViewBag.platform == "" ? "其他" : ViewBag.platform) + "账单流水" };
}
<button id="btn_Upload" type="button" style="" class="btn btn-warning">导入配置文件</button>
<button id="btn_Upload" type="button" style="" class="btn btn-warning">导入销售订单费用配置</button>
<button id="btn_LogisticFee" type="button" style="" class="btn btn-success">导入物流费配置</button>
@section css{
<link href="~/js/webuploader-0.1.5/webuploader.css" rel="stylesheet" />
......@@ -47,6 +48,16 @@
function (result) {
alert('上传成功!');
});
//物流商配置 UploadLogisticFeeConfig
uploadfile('btn_LogisticFee',
'@Url.Content("~/Home/UploadLogisticFeeConfig")',
function (result) {
alert('上传成功!');
});
})
function uploadfile(id,url,callback)
......
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