189 lines
6.2 KiB
C#
189 lines
6.2 KiB
C#
using Competition.Common.Util;
|
||
using CompetitionAPI.Util;
|
||
using Microsoft.AspNetCore.Authorization;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using Newtonsoft.Json;
|
||
|
||
namespace CompetitionAPI.Controllers
|
||
{
|
||
/// <summary>
|
||
/// 互感器方案
|
||
/// </summary>
|
||
[Route("api/[controller]")]
|
||
[ApiController]
|
||
public class TransformPlanController : BaseHandlerController
|
||
{
|
||
Competition.Mysql.BLL.app_transform_plan bll = new Competition.Mysql.BLL.app_transform_plan();
|
||
|
||
Competition.Mysql.BLL.app_client_collect bll_client_collect = new Competition.Mysql.BLL.app_client_collect();
|
||
|
||
private readonly IWebHostEnvironment _env;
|
||
public TransformPlanController(IHttpContextAccessor IHttpContextAccessor, IWebHostEnvironment env, IConfiguration iconfiguration)
|
||
{
|
||
Configuration = iconfiguration;
|
||
_env = env;
|
||
context = IHttpContextAccessor.HttpContext!;
|
||
CrossDomain();
|
||
}
|
||
|
||
//[Authorize]
|
||
/// <summary>
|
||
/// 查询所有信息
|
||
/// </summary>
|
||
[Route("All")]
|
||
public JsonResult QueryALL()
|
||
{
|
||
/*
|
||
measure_id '计量点id',
|
||
transform_category '类别',
|
||
transform_type '类型',
|
||
ta_level 'TA有功准确度等级',
|
||
current_rate '电流变比',
|
||
|
||
is_prepare '是否预领',
|
||
tv_level 'TV有功准确度等级',
|
||
asset_number '资产编号',
|
||
phase_type '相别',
|
||
*/
|
||
var check = new Competition.Mysql.Model.app_transform_plan();
|
||
|
||
check.measure_id = "计量点id";
|
||
check.transform_category = "类别";
|
||
check.transform_type = "类型";
|
||
check.ta_level = "TA有功准确度等级";
|
||
check.current_rate = "电流变比";
|
||
|
||
check.is_prepare = "是否预领";
|
||
check.tv_level = "TV有功准确度等级";
|
||
check.asset_number = "资产编号";
|
||
check.phase_type = "相别";
|
||
|
||
|
||
var obj = new
|
||
{
|
||
measure_id = "计量点id",
|
||
transform_category = "类别",
|
||
transform_type = "类型",
|
||
ta_level = "TA有功准确度等级",
|
||
current_rate = "电流变比",
|
||
|
||
is_prepare = "是否预领",
|
||
tv_level = "TV有功准确度等级",
|
||
asset_number = "资产编号",
|
||
phase_type = "相别",
|
||
};
|
||
|
||
var json = JsonConvert.SerializeObject(obj);
|
||
var list = bll.GetModelList("");
|
||
var result = GetResult(true, list);
|
||
return result;
|
||
}
|
||
|
||
//[Authorize]
|
||
/// <summary>
|
||
/// 查询互感器方案
|
||
/// </summary>
|
||
[Route("Query")]
|
||
public JsonResult QueryByClient()
|
||
{
|
||
JsonResult ret;
|
||
var client_id = GetValue("client_id");
|
||
if (string.IsNullOrEmpty(client_id))
|
||
{
|
||
ret = GetResult(false, "client_id不能为空");
|
||
return ret;
|
||
}
|
||
var model = bll.GetModelList("client_id='" + client_id + "'").FirstOrDefault();
|
||
if (null == model)
|
||
{
|
||
var result = GetResult(false, "记录不存在");
|
||
return result;
|
||
}
|
||
else
|
||
{
|
||
var result = GetResult(true, model, "");
|
||
return result;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
#region 添加或修改互感器方案
|
||
//[Authorize]
|
||
[HttpPost]
|
||
[Route("AddUpdate")]
|
||
public JsonResult AddUpdate()
|
||
{
|
||
try
|
||
{
|
||
JsonResult ret;
|
||
var client_id = GetValue("client_id");
|
||
if (string.IsNullOrEmpty(client_id))
|
||
{
|
||
ret = GetResult(false, "client_id不能为空");
|
||
return ret;
|
||
}
|
||
|
||
var client = bll_client_collect.GetModel(client_id);
|
||
if (null == client)
|
||
{
|
||
ret = GetResult(false, "客户收资材料不能为空:client_id:" + client_id);
|
||
return ret;
|
||
}
|
||
|
||
var data = GetValue("data");
|
||
if (string.IsNullOrEmpty(data))
|
||
{
|
||
ret = GetResult(false, "data不能为空");
|
||
return ret;
|
||
}
|
||
var model = new Competition.Mysql.Model.app_transform_plan();
|
||
try
|
||
{
|
||
model = JsonConvert.DeserializeObject<Competition.Mysql.Model.app_transform_plan>(data)!;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ret = GetResult(false, "data转换错误:" + ex.Message);
|
||
return ret;
|
||
}
|
||
|
||
var exist_model = bll.GetModelList("client_id='" + client_id + "'").OrderByDescending(s => s.id).FirstOrDefault();
|
||
if (null == exist_model)
|
||
{
|
||
model.id = Tool.GetId();
|
||
model.client_id = client_id;
|
||
model.create_time = DateTime.Now;
|
||
if (bll.Add(model))
|
||
{
|
||
return GetResult(true, model, "");
|
||
}
|
||
else
|
||
{
|
||
return GetResult(false, "添加失败");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
model.id = exist_model.id;
|
||
model.client_id = client_id;
|
||
model.create_time = DateTime.Now;
|
||
if (bll.Update(model))
|
||
{
|
||
return GetResult(true, model, "");
|
||
}
|
||
else
|
||
{
|
||
return GetResult(false, "修改失败");
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.WriteLog(ex.Message + ",行号:" + ex.StackTrace);
|
||
return GetResult(false, "发生错误,请联系管理员");
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
} |