数据批量操作
parent
29c56a7193
commit
28cff3e298
|
|
@ -435,7 +435,7 @@ namespace OpenAuth.App.ServiceApp.DataMaintenance
|
|||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 导出shp文件
|
||||
/// </summary>
|
||||
|
|
@ -454,7 +454,7 @@ namespace OpenAuth.App.ServiceApp.DataMaintenance
|
|||
List<IFeature> features = new List<IFeature>();
|
||||
|
||||
foreach (var row in data)
|
||||
{
|
||||
{
|
||||
var geometry = ParseGeometry(row.geom.ToString());
|
||||
if (geometry == null)
|
||||
{
|
||||
|
|
@ -536,5 +536,43 @@ namespace OpenAuth.App.ServiceApp.DataMaintenance
|
|||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
//批量修改
|
||||
public async Task<Response<bool>> UpdateBatch(UpdateBatchDataReq updateBatchDataReq)
|
||||
{
|
||||
var result = new Response<bool>();
|
||||
using (var db = UnitWork.CreateContext())
|
||||
{
|
||||
if (updateBatchDataReq.OldValue == "")
|
||||
{
|
||||
var flag = await db.Db.Updateable<object>()
|
||||
.AS(updateBatchDataReq.TableName)
|
||||
.SetColumns(updateBatchDataReq.SingleField, updateBatchDataReq.NewValue)
|
||||
.Where($"\"{updateBatchDataReq.SingleField}\" = @OldValue OR \"{updateBatchDataReq.SingleField}\" IS NULL", new { OldValue = updateBatchDataReq.OldValue })
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
var flag = await db.Db.Updateable<object>()
|
||||
.AS(updateBatchDataReq.TableName)
|
||||
.SetColumns(updateBatchDataReq.SingleField, updateBatchDataReq.NewValue)
|
||||
.Where($"\"{updateBatchDataReq.SingleField}\" = @OldValue", new { OldValue = updateBatchDataReq.OldValue })
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
if (db.Commit())
|
||||
{
|
||||
result.Result = true;
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Result = false;
|
||||
result.Message = "修改失败";
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OpenAuth.App.ServiceApp.DataMaintenance.Request
|
||||
{
|
||||
public class UpdateBatchDataReq : TableDataReq
|
||||
{
|
||||
//
|
||||
public string SingleField { get; set; }
|
||||
//
|
||||
public string OldValue { get; set; }
|
||||
//
|
||||
public string NewValue { get; set; }
|
||||
//
|
||||
public List<string> Ids { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -155,7 +155,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers.DataMaintenance
|
|||
return Ok();
|
||||
}
|
||||
/// <summary>
|
||||
/// 导出案件shp文件
|
||||
/// 导出shp文件
|
||||
/// </summary>
|
||||
/// <param name="req"></param>
|
||||
/// <returns></returns>
|
||||
|
|
@ -184,6 +184,14 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers.DataMaintenance
|
|||
return StatusCode(500, $"Internal server error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
//批量修改
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public async Task<Response<bool>> UpdateBatch(UpdateBatchDataReq req)
|
||||
{
|
||||
return await _app.UpdateBatch(req);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue