Commit 69099885 by jianshuqin

优化:组件功能

parent c0b58793
......@@ -420,27 +420,141 @@ namespace Bailun.DC.Services.DataWareHouse
}
using (var trans = db.BeginTransaction())
{
int? resultCount = default(int?);
flowing_sales_fee oldEntity = default(flowing_sales_fee);
try
{
int? resultCount = entity.id > 0 ? db.Update(entity) : db.Insert(entity);
//更新
if (entity.id > 0)
{
oldEntity = db.Get<flowing_sales_fee>(entity.id);
if (oldEntity != null)
{
entity.create_time = oldEntity.create_time;
entity.update_time = DateTime.Now;
resultCount = db.Update(entity);
}
}
//新增
else
{
entity.create_time = DateTime.Now;
entity.update_time = entity.create_time;
entity.id = (resultCount = db.Insert(entity)) ?? 0;
}
if (resultCount > 0)
{
if (entity.id == 0)
if (oldEntity == null || (oldEntity.amount != entity.amount || oldEntity.currency != entity.currency || oldEntity.month != entity.month || oldEntity.platform != entity.platform || oldEntity.fee_type != entity.fee_type))
{
string sql = "select max(id) from flowing_sales_fee";
entity.id = db.QueryFirstOrDefault<int>(sql);
result = this.ImportFlowingSalesFeeDetail(new[] { entity.id }, new List<flowing_sales_fee> { entity }, db);
}
result = this.ImportFlowingSalesFeeDetail(new[] { entity.id }, entity.month);
if (result.Result)
{
trans.Commit();
}
else
{
trans.Rollback();
}
}
else
{
result.Result = false;
result.Message = "数据异常";
}
}
catch (Exception ex)
{
trans.Rollback();
trans.Dispose();
result.Result = false;
result.Message = ex.Message;
}
}
}
}
return result;
}
public ResultDTO SaveFlowingSalesFeeDetail(flowing_sales_fee_detail entity)
{
ResultDTO result = result = this.BeforeSaveFlowingSalesFeeDetail(entity);
if (result.Result)
{
using (var db = new MySqlConnection(GlobalConfig.ConnectionString_DW))
{
if (db.State == ConnectionState.Closed)
{
db.Open();
}
using (var trans = db.BeginTransaction())
{
int resultCount = 0;
try
{
string sql = "select * from exchange_rate_finance where month = @month and code in @code";
IList<exchange_rate_finance> listRate = db.Query<exchange_rate_finance>(sql, new { month = entity.date.ToString("yyyy-MM"), code = new string[] { "CNY", "USD" } }).ToList();
if (listRate?.Count > 0)
{
if (entity.currency.Equals("CNY", StringComparison.OrdinalIgnoreCase))
{
entity.amount_cny = entity.amount;
}
else
{
exchange_rate_finance rate_cny = listRate.FirstOrDefault(l => l.code.Equals(entity.currency, StringComparison.OrdinalIgnoreCase));
if (rate_cny != null)
{
entity.amount_cny = Math.Round(entity.amount / rate_cny.exchange_rate, 2);
}
}
if (entity.currency.Equals("USD", StringComparison.OrdinalIgnoreCase))
{
entity.amount_usd = entity.amount;
}
else
{
exchange_rate_finance rate_usd = listRate.FirstOrDefault(l => l.code.Equals("USD", StringComparison.OrdinalIgnoreCase));
if (rate_usd != null)
{
entity.amount_usd = Math.Round(entity.amount_cny * rate_usd.exchange_rate, 2);
}
}
//更新
if (entity.id > 0)
{
entity.update_time = DateTime.Now;
resultCount = db.Update(entity);
}
//新增
else
{
entity.create_time = DateTime.Now;
entity.update_time = entity.create_time;
resultCount = db.Insert(entity) ?? 0;
}
if (resultCount > 0)
{
trans.Commit();
}
else
{
result.Result = false;
result.Message = "数据异常";
}
}
else
{
result.Result = false;
result.Message = "没有汇率信息";
}
}
catch (Exception ex)
{
trans.Rollback();
result.Result = false;
result.Message = ex.Message;
}
}
......@@ -468,14 +582,14 @@ namespace Bailun.DC.Services.DataWareHouse
{
try
{
foreach (DataRow row in dt.Rows)
IList<flowing_sales_fee> list = new List<flowing_sales_fee>();
for (int i = 0; i < dt.Rows.Count; i++)
{
flowing_sales_fee entity = new flowing_sales_fee();
entity.platform = row["平台"]?.ToString();
if (string.IsNullOrWhiteSpace(entity.platform))
DataRow row = dt.Rows[i];
if (!string.IsNullOrWhiteSpace(row["平台"]?.ToString()))
{
continue;
}
flowing_sales_fee entity = new flowing_sales_fee();
entity.platform = row["平台"].ToString();
entity.account_name = row["账号"]?.ToString();
entity.fee_type = row["费用类型"]?.ToString();
entity.month = row["结算时间"]?.ToString()?.Replace("年", "-")?.Replace("月", string.Empty);
......@@ -488,15 +602,30 @@ namespace Bailun.DC.Services.DataWareHouse
entity.remark = row["备注"]?.ToString();
entity.create_time = now;
entity.update_time = now;
int? resultCount = db.Insert(entity);
if (!string.IsNullOrWhiteSpace(entity.fee_type) && !string.IsNullOrWhiteSpace(entity.month) && entity.amount != 0m && !string.IsNullOrWhiteSpace(entity.currency))
{
entity.id = db.Insert(entity) ?? 0;
list.Add(entity);
}
else
{
result.Message = $"第{(i + 1)}行的{(!string.IsNullOrWhiteSpace(entity.fee_type) ? (!string.IsNullOrWhiteSpace(entity.month) ? (entity.amount != 0m ? "币种" : "金额") : "结算时间") : "费用类型")}不能为空{(entity.amount == 0m ? "或者为0" : string.Empty)}";
return result;
}
}
}
if (list.Count > 0)
{
result = this.ImportFlowingSalesFeeDetail(null, list, db);
if (result.Result)
{
trans.Commit();
result.Result = true;
}
}
}
catch (Exception ex)
{
trans.Rollback();
trans.Dispose();
result.Message = ex.Message;
}
}
......@@ -510,36 +639,32 @@ namespace Bailun.DC.Services.DataWareHouse
return result;
}
public ResultDTO ImportFlowingSalesFeeDetail(int[] feeId, string month = null)
public ResultDTO ImportFlowingSalesFeeDetail(int[] feeId, IList<flowing_sales_fee> list = null, MySqlConnection db = null)
{
ResultDTO result = new ResultDTO();
if (feeId?.Length > 0)
{
DateTime now = DateTime.Now;
string sql = "select * from flowing_sales_fee where id in @fee_id";
using (var db = new MySqlConnection(GlobalConfig.ConnectionString_DW))
MySqlConnection dbDetail = db == null ? new MySqlConnection(GlobalConfig.ConnectionString_DW) : db;
if (dbDetail.State == ConnectionState.Closed)
{
if (db.State == ConnectionState.Closed)
dbDetail.Open();
}
if (list == null)
{
db.Open();
list = dbDetail.Query<flowing_sales_fee>(sql, new { fee_id = feeId }).ToList();
}
IList<flowing_sales_fee> list = db.Query<flowing_sales_fee>(sql, new { fee_id = feeId }).ToList();
List<flowing_sales_fee_detail> listDetail = new List<flowing_sales_fee_detail>();
if (list?.Count > 0)
{
IList<flowing_sales_fee_detail> listDetail = new List<flowing_sales_fee_detail>();
sql = "select * from exchange_rate_finance where month in @month";
IList<exchange_rate_finance> listRate = db.Query<exchange_rate_finance>(sql, new { month = !string.IsNullOrWhiteSpace(month) ? new string[] { month } : list.Select(l => l.month).Distinct() }).ToList();
IList<exchange_rate_finance> listRate = dbDetail.Query<exchange_rate_finance>(sql, new { month = list.Select(l => l.month).Distinct() }).ToList();
if (listRate?.Count > 0)
{
DateTime now = DateTime.Now;
DateTime date = DateTime.MinValue;
foreach (flowing_sales_fee entity in list)
{
if (!string.IsNullOrWhiteSpace(month))
{
entity.month = month;
}
if (DateTime.TryParse(entity.month, out date))
{
DateTime monthTime = date;
......@@ -561,34 +686,66 @@ namespace Bailun.DC.Services.DataWareHouse
{
detailEntity.amount = Math.Round(entity.amount - (Math.Round(entity.amount / days, 2) * (days - 1)), 2);
}
if (entity.currency.Equals("CNY", StringComparison.OrdinalIgnoreCase))
{
detailEntity.amount_cny = detailEntity.amount;
}
else
{
exchange_rate_finance rate_cny = listRate.FirstOrDefault(l => l.month == entity.month && l.code.Equals(entity.currency, StringComparison.OrdinalIgnoreCase));
exchange_rate_finance rate_usd = listRate.FirstOrDefault(l => l.month == entity.month && l.code.Equals(entity.currency, StringComparison.OrdinalIgnoreCase));
if (rate_cny != null && rate_usd != null)
if (rate_cny != null)
{
detailEntity.amount_cny = Math.Round(detailEntity.amount / rate_cny.exchange_rate, 2);
}
}
if (entity.currency.Equals("USD", StringComparison.OrdinalIgnoreCase))
{
detailEntity.amount_usd = detailEntity.amount;
}
else
{
exchange_rate_finance rate_usd = listRate.FirstOrDefault(l => l.month == entity.month && l.code.Equals("USD", StringComparison.OrdinalIgnoreCase));
if (rate_usd != null)
{
detailEntity.amount_usd = Math.Round(detailEntity.amount_cny * rate_usd.exchange_rate, 2);
}
}
listDetail.Add(detailEntity);
}
}
}
using (var trans = db.BeginTransaction())
{
var trans = db == null ? dbDetail.BeginTransaction() : null;
try
{
sql = "delete from flowing_sales_fee_detail where fee_id in @fee_id";
int resultCount = db.Execute(sql, new { fee_id = feeId });
int resultCount = dbDetail.Execute(sql, new { fee_id = feeId });
sql = "insert into flowing_sales_fee_detail(fee_id,platform,fee_type,date,amount,currency,amount_cny,amount_usd,delstatus,create_time,update_time)values(@fee_id,@platform,@fee_type,@date,@amount,@currency,@amount_cny,@amount_usd,@delstatus,@create_time,@update_time)";
resultCount = db.Execute(sql, listDetail.ToArray());
resultCount = dbDetail.Execute(sql, listDetail.ToArray());
if (db == null)
{
trans.Commit();
}
result.Result = true;
}
catch (Exception ex)
{
if (db == null)
{
trans.Rollback();
trans.Dispose();
}
result.Message = ex.Message;
}
finally
{
if (trans != null)
{
trans.Dispose();
}
if (db == null)
{
dbDetail.Close();
dbDetail.Dispose();
}
}
}
else
......@@ -597,7 +754,6 @@ namespace Bailun.DC.Services.DataWareHouse
}
}
}
}
else
{
result.Message = "数据不能为空";
......@@ -608,7 +764,7 @@ namespace Bailun.DC.Services.DataWareHouse
public ResultDTO DeleteFlowingSalesFee(int[] id)
{
ResultDTO result = this.BeforeDeleteFlowingSalesFee(id);
ResultDTO result = this.BeforeDelete(id);
if (result.Result)
{
......@@ -627,11 +783,10 @@ namespace Bailun.DC.Services.DataWareHouse
int resultCount = db.Execute(sql, new { id = id, delstatus = 1, update_time = DateTime.Now });
if (resultCount > 0)
{
sql = "update flowing_sales_fee_detail set delstatus = @delstatus, update_time = @update_time where fee_id in @fee_id";
resultCount = db.Execute(sql, new { fee_id = id, delstatus = 1, update_time = DateTime.Now });
sql = "delete from flowing_sales_fee_detail where fee_id in @fee_id";
resultCount = db.Execute(sql, new { fee_id = id });
//提交事务
transaction.Commit();
result.Message = "保存成功";
}
}
catch (Exception ex)
......@@ -648,6 +803,41 @@ namespace Bailun.DC.Services.DataWareHouse
return result;
}
public ResultDTO DeleteFlowingSalesFeeDetail(int[] id)
{
ResultDTO result = this.BeforeDelete(id);
if (result.Result)
{
string sql = "delete from flowing_sales_fee_detail where id in @id";
using (var db = new MySqlConnection(GlobalConfig.ConnectionString_DW))
{
if (db.State == ConnectionState.Closed)
{
db.Open();
}
//开启事务
using (MySqlTransaction transaction = db.BeginTransaction())
{
try
{
int resultCount = db.Execute(sql, new { id = id, delstatus = 1, update_time = DateTime.Now });
transaction.Commit();
}
catch (Exception ex)
{
//回滚事务
transaction.Rollback();
result.Message = ex.Message;
result.Result = false;
}
}
}
}
return result;
}
public ResultDTO BeforeSaveFlowingSalesFee(flowing_sales_fee entity)
{
ResultDTO result = new ResultDTO();
......@@ -669,7 +859,41 @@ namespace Bailun.DC.Services.DataWareHouse
}
else if (entity.amount == 0m)
{
result.Message = "金额不能为空";
result.Message = "金额不能为空或为0";
}
else if (string.IsNullOrWhiteSpace(entity.currency))
{
result.Message = "币种不能为空";
}
else
{
result.Result = true;
}
return result;
}
public ResultDTO BeforeSaveFlowingSalesFeeDetail(flowing_sales_fee_detail entity)
{
ResultDTO result = new ResultDTO();
if (entity == null)
{
result.Message = "数据不能为空";
}
else if (string.IsNullOrWhiteSpace(entity.platform))
{
result.Message = "平台不能为空";
}
else if (string.IsNullOrWhiteSpace(entity.fee_type))
{
result.Message = "费用类型不能为空";
}
else if (entity.date <= DateTime.Parse("1991-01-01"))
{
result.Message = "分摊日期不能为空";
}
else if (entity.amount == 0m)
{
result.Message = "金额不能为空或为0";
}
else if (string.IsNullOrWhiteSpace(entity.currency))
{
......@@ -682,7 +906,7 @@ namespace Bailun.DC.Services.DataWareHouse
return result;
}
public ResultDTO BeforeDeleteFlowingSalesFee(int[] id)
public ResultDTO BeforeDelete(int[] id)
{
ResultDTO result = new ResultDTO();
if (id == null || id.Length == 0 || id.Contains(0))
......
......@@ -4,7 +4,6 @@
class="el-dialog-form"
el-dialog
append-to-body
destroy-on-close
v-dialogDrag
v-bind:title="dialog.name"
v-bind:visible.sync="show"
......
......@@ -45,7 +45,7 @@
},
//查询数据
onSearch: function (firstPage) {
this.$refs.tableQuery.onSearch(null, firstPage);
this.$refs.tableQuery.onSearch(false, firstPage);
}
}
})
......
......@@ -1476,6 +1476,22 @@ namespace Bailun.DC.Web.Areas.DataWareHouse.Controllers
}
[HttpPost]
public JsonResult SaveFlowingSalesFeeDetail([FromBody] flowing_sales_fee_detail entity)
{
ResultDTO result = default(ResultDTO);
try
{
result = new Services.DataWareHouse.PlatformOrderFeeServices().SaveFlowingSalesFeeDetail(entity);
}
catch (Exception ex)
{
result = new ResultDTO() { Message = ex.Message };
}
return Json(result);
}
[HttpPost]
public JsonResult ImportFlowingSalesFee(IFormFile file)
{
ResultDTO result = new ResultDTO();
......@@ -1532,6 +1548,22 @@ namespace Bailun.DC.Web.Areas.DataWareHouse.Controllers
return Json(result);
}
[HttpPost]
public JsonResult DeleteFlowingSalesFeeDetail(int[] id)
{
ResultDTO result = default(ResultDTO);
try
{
result = new Services.DataWareHouse.PlatformOrderFeeServices().DeleteFlowingSalesFeeDetail(id);
}
catch (Exception ex)
{
result = new ResultDTO() { Message = ex.Message };
}
return Json(result);
}
#endregion
......
......@@ -40,16 +40,19 @@
var result = response.data;
if (response.status === 200 && result.result && result.data) {
Vue.set(that, "dialog", result.data)
that.show = true;
that.$set(that, "show", true);
if (title) {
Vue.set(that.dialog, "name", title);
}
if (that.dialog.listFormItem && that.dialog.listFormItem.constructor === String) {
Vue.set(that.dialog, "listFormItem", JSON.parse(that.dialog.listFormItem));
}
if (form && that.dialog.listFormItem && that.dialog.listFormItem.length) {
that.dialog.listFormItem.forEach(function (item) {
if (item.type == "select" && (!item.listOption || item.listOption.length) && form[item.prop] && form[item.propname]) {
if (that.dialog.listFormItem) {
that.dialog.listFormItem.forEach(function (item, i) {
if (that.$refs.dialog && that.$refs.dialog.rendered && item.defaultValue) {
that.$refs.control[i].setDefaultValue();
}
if (form && item.type == "select" && (!item.listOption || item.listOption.length) && form[item.prop] && form[item.propname]) {
var listOption = [];
var listPropValue = Array.isArray(form[item.prop]) ? form[item.prop] : [form[item.prop]]
listPropValue.forEach(function (l, i) {
......@@ -80,11 +83,11 @@
var resetFieldsIndex = that.dialog.listFormItem && that.dialog.listFormItem.findIndex(function (l, i) {
return (l.type == "input" || l.type == "number" || l.type == "select" || l.type == "daterange" || l.type == "date" || l.type == "month" || l.type == "year" || l.type == "switch");
});
if (resetFieldsIndex > 0) {
if (resetFieldsIndex >= 0) {
that.$refs.form && that.$refs.form.resetFields && that.$refs.form.resetFields();
};
}
that.show = false
that.$set(that, "show", false);
},
//提交表单
submitForm: function () {
......@@ -101,28 +104,6 @@
that.javaScript.call(that, that.dialog.saveScript, that.form)
}
},
//
visibleChange: function (visible, item) {
var that = this
if (visible && item.api && (!item.listOption || item.listOption.length <= 1 || (that.form && item.prop && that.form[item.prop] && Array.isArray(that.form[item.prop]) && that.form[item.prop].length == item.listOption.length))) {
//that.$set(item, "loading", true)
//if (item.apiType == "post") {
// request.post(item.api, { limit: 2147483647 }).then(response => {
// if (response.code == 200 && response.data) {
// that.$set(item, "listOption", response.data.list)
// }
// that.$set(item, "loading", false)
// })
//} else {
// request.get(item.api, { limit: 2147483647 }).then(response => {
// if (response.code == 200 && response.data) {
// that.$set(item, "listOption", response.data.list)
// }
// that.$set(item, "loading", false)
// })
//}
}
}
},
template: '#elDialogForm'
});
\ No newline at end of file
......@@ -202,6 +202,10 @@
}
that.$set(that, "item_value", date);
break;
case 'input':
case 'textarea':
that.$set(that, "item_value", that.item.defaultValue);
break;
}
}
},
......@@ -242,7 +246,7 @@
//文件上传成功
onSuccess(response, file, listFile) {
var that = this;
if (response.code = 200) {
if (response.result) {
listFile.splice(listFile.length - 1, 1)
that.$emit("import", true, file)
that.$nextTick(function () {
......
......@@ -47,7 +47,7 @@
var listFilter = [];
//筛选区域过虑条件
if (!filter) {
listFilter = that.$refs.formFilter.getFilter(true);
listFilter = that.$refs.formFilter.getFilter(filter != false);
} else {
listFilter = filter.length > 0 ? filter : [];
}
......
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