|
@@ -35,9 +35,9 @@ namespace Ys.Scada.Backend.Controllers
|
|
|
[HttpPost("delete")]
|
|
[HttpPost("delete")]
|
|
|
public async Task<JsonResult> DeleteVariable(int docId, int id)
|
|
public async Task<JsonResult> DeleteVariable(int docId, int id)
|
|
|
{
|
|
{
|
|
|
- await _fsql.Delete<Variable>()
|
|
|
|
|
- .Where(o => o.Id == id && o.DocId == docId)
|
|
|
|
|
- .ExecuteAffrowsAsync();
|
|
|
|
|
|
|
+ _fsql.Delete<Variable>()
|
|
|
|
|
+ .Where(o => o.Id == id && o.DocId == docId)
|
|
|
|
|
+ .ExecuteAffrows();
|
|
|
return OK();
|
|
return OK();
|
|
|
}
|
|
}
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -67,7 +67,7 @@ namespace Ys.Scada.Backend.Controllers
|
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
|
/// <exception cref="CustomException"></exception>
|
|
/// <exception cref="CustomException"></exception>
|
|
|
[HttpPost("save")]
|
|
[HttpPost("save")]
|
|
|
- public async Task<JsonResult> CreateVariable(int docId, List<VariableModel> variables)
|
|
|
|
|
|
|
+ public async Task<JsonResult> CreateVariable(int docId, int sourceId, List<VariableModel> variables)
|
|
|
{
|
|
{
|
|
|
var document = await _fsql.Select<Document>().Where(o => o.Id == docId).ToOneAsync();
|
|
var document = await _fsql.Select<Document>().Where(o => o.Id == docId).ToOneAsync();
|
|
|
Check.NotNull(document);
|
|
Check.NotNull(document);
|
|
@@ -75,21 +75,22 @@ namespace Ys.Scada.Backend.Controllers
|
|
|
throw new CustomException("项目数据错误");
|
|
throw new CustomException("项目数据错误");
|
|
|
|
|
|
|
|
var newEntitys = _mapper.Map<List<Variable>>(variables);
|
|
var newEntitys = _mapper.Map<List<Variable>>(variables);
|
|
|
- var oldEntitys = await _fsql.Select<Variable>().Where(o => o.DocId == docId).ToListAsync();
|
|
|
|
|
|
|
+ var oldEntitys = await _fsql.Select<Variable>().Where(o => o.DocId == docId && o.SourceId == sourceId).ToListAsync();
|
|
|
var entitys = new List<Variable>();
|
|
var entitys = new List<Variable>();
|
|
|
|
|
+ var removes = new List<Variable>();
|
|
|
foreach (var v in newEntitys)
|
|
foreach (var v in newEntitys)
|
|
|
{
|
|
{
|
|
|
if (string.IsNullOrWhiteSpace(v.Code) || string.IsNullOrWhiteSpace(v.VariableAddress) || string.IsNullOrWhiteSpace(v.ReadWrite))
|
|
if (string.IsNullOrWhiteSpace(v.Code) || string.IsNullOrWhiteSpace(v.VariableAddress) || string.IsNullOrWhiteSpace(v.ReadWrite))
|
|
|
continue;
|
|
continue;
|
|
|
var variable = oldEntitys.Where(o => o.Code == v.Code).FirstOrDefault();
|
|
var variable = oldEntitys.Where(o => o.Code == v.Code).FirstOrDefault();
|
|
|
if (variable != null)
|
|
if (variable != null)
|
|
|
- oldEntitys.Remove(variable);
|
|
|
|
|
|
|
+ removes.Add(variable);
|
|
|
entitys.Add(v);
|
|
entitys.Add(v);
|
|
|
}
|
|
}
|
|
|
- entitys = entitys.Union(oldEntitys).ToList();
|
|
|
|
|
_fsql.Transaction(() =>
|
|
_fsql.Transaction(() =>
|
|
|
{
|
|
{
|
|
|
- _fsql.Delete<Variable>().Where(o => o.DocId == docId).ExecuteAffrows();
|
|
|
|
|
|
|
+ if (removes.Any())
|
|
|
|
|
+ _fsql.Delete<Variable>().Where(removes).ExecuteAffrows();
|
|
|
_fsql.Insert(entitys).ExecuteAffrows();
|
|
_fsql.Insert(entitys).ExecuteAffrows();
|
|
|
});
|
|
});
|
|
|
return OK();
|
|
return OK();
|
|
@@ -102,7 +103,7 @@ namespace Ys.Scada.Backend.Controllers
|
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
|
/// <exception cref="CustomException"></exception>
|
|
/// <exception cref="CustomException"></exception>
|
|
|
[HttpPost("import")]
|
|
[HttpPost("import")]
|
|
|
- public async Task<JsonResult> ImportVarible(int docId, IFormFile formFile)
|
|
|
|
|
|
|
+ public async Task<JsonResult> ImportVarible(int docId, int sourceId, IFormFile formFile)
|
|
|
{
|
|
{
|
|
|
var document = await _fsql.Select<Document>().Where(o => o.Id == docId).ToOneAsync();
|
|
var document = await _fsql.Select<Document>().Where(o => o.Id == docId).ToOneAsync();
|
|
|
Check.NotNull(document);
|
|
Check.NotNull(document);
|
|
@@ -119,10 +120,12 @@ namespace Ys.Scada.Backend.Controllers
|
|
|
var variables = file.OpenReadStream().ExcelToEntity<VariableModel>();
|
|
var variables = file.OpenReadStream().ExcelToEntity<VariableModel>();
|
|
|
var varis = variables.Select(o =>
|
|
var varis = variables.Select(o =>
|
|
|
{
|
|
{
|
|
|
- o.DocId = docId; return o;
|
|
|
|
|
|
|
+ o.DocId = docId;
|
|
|
|
|
+ o.SourceId = sourceId;
|
|
|
|
|
+ return o;
|
|
|
});
|
|
});
|
|
|
var newEntitys = _mapper.Map<List<Variable>>(varis);
|
|
var newEntitys = _mapper.Map<List<Variable>>(varis);
|
|
|
- var oldEntitys = await _fsql.Select<Variable>().Where(o => o.DocId == docId).ToListAsync();
|
|
|
|
|
|
|
+ var oldEntitys = await _fsql.Select<Variable>().Where(o => o.DocId == docId && o.SourceId == sourceId).ToListAsync();
|
|
|
var entitys = new List<Variable>();
|
|
var entitys = new List<Variable>();
|
|
|
foreach (var v in newEntitys)
|
|
foreach (var v in newEntitys)
|
|
|
{
|
|
{
|
|
@@ -136,7 +139,7 @@ namespace Ys.Scada.Backend.Controllers
|
|
|
entitys = newEntitys.Union(oldEntitys).ToList();
|
|
entitys = newEntitys.Union(oldEntitys).ToList();
|
|
|
_fsql.Transaction(() =>
|
|
_fsql.Transaction(() =>
|
|
|
{
|
|
{
|
|
|
- _fsql.Delete<Variable>().Where(o => o.DocId == docId).ExecuteAffrows();
|
|
|
|
|
|
|
+ _fsql.Delete<Variable>().Where(o => o.DocId == docId && o.SourceId == sourceId).ExecuteAffrows();
|
|
|
_fsql.Insert(entitys).ExecuteAffrows();
|
|
_fsql.Insert(entitys).ExecuteAffrows();
|
|
|
});
|
|
});
|
|
|
return OK();
|
|
return OK();
|