195 lines
6.5 KiB
C#
195 lines
6.5 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 EnergyMeterController : BaseHandlerController
|
||
{
|
||
Competition.Mysql.BLL.app_energy_meter bll = new Competition.Mysql.BLL.app_energy_meter();
|
||
|
||
Competition.Mysql.BLL.app_client_collect bll_client_collect = new Competition.Mysql.BLL.app_client_collect();
|
||
|
||
private readonly IWebHostEnvironment _env;
|
||
public EnergyMeterController(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',
|
||
meter_category '类别',
|
||
meter_type '类型',
|
||
inline_type '接线方式',
|
||
power_voltage '电压',
|
||
power_current '电流',
|
||
|
||
active_power_level '有功准确度等级',
|
||
is_precast_meter '是否预领表',
|
||
is_whole_meter '是否配置一体表',
|
||
refer_flag '参考表标志',
|
||
indicator_type '电能表示数类型',
|
||
*/
|
||
var check = new Competition.Mysql.Model.app_energy_meter();
|
||
|
||
check.measure_id = "计量点id";
|
||
check.meter_category = "类别";
|
||
check.meter_type = "类型";
|
||
check.inline_type = "接线方式";
|
||
check.power_voltage = "电压";
|
||
check.power_current = "电流";
|
||
|
||
check.active_power_level = "有功准确度等级";
|
||
check.is_precast_meter = "是否预领表";
|
||
check.is_whole_meter = "是否配置一体表";
|
||
check.refer_flag = "参考表标志";
|
||
check.indicator_type = "电能表示数类型";
|
||
|
||
var obj = new
|
||
{
|
||
measure_id = "计量点id",
|
||
meter_category = "类别",
|
||
meter_type = "类型",
|
||
inline_type = "接线方式",
|
||
power_voltage = "电压",
|
||
power_current = "电流",
|
||
|
||
active_power_level = "有功准确度等级",
|
||
is_precast_meter = "是否预领表",
|
||
is_whole_meter = "是否配置一体表",
|
||
refer_flag = "参考表标志",
|
||
indicator_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_energy_meter();
|
||
try
|
||
{
|
||
model = JsonConvert.DeserializeObject<Competition.Mysql.Model.app_energy_meter>(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
|
||
}
|
||
} |