using Competition.Common.Util;
using CompetitionAPI.Util;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace CompetitionAPI.Controllers
{
///
/// 计量点
///
[Route("api/[controller]")]
[ApiController]
public class MeasurePointController : BaseHandlerController
{
Competition.Mysql.BLL.app_measure_point bll = new Competition.Mysql.BLL.app_measure_point();
Competition.Mysql.BLL.app_client_collect bll_client_collect = new Competition.Mysql.BLL.app_client_collect();
private readonly IWebHostEnvironment _env;
public MeasurePointController(IHttpContextAccessor IHttpContextAccessor, IWebHostEnvironment env, IConfiguration iconfiguration)
{
Configuration = iconfiguration;
_env = env;
context = IHttpContextAccessor.HttpContext!;
CrossDomain();
}
//[Authorize]
///
/// 查询所有信息
///
[Route("All")]
public JsonResult QueryALL()
{
/*
measure_name '计量点名称',
measure_capacity '计量点容量',
measure_way '计量方式',
is_fill_meter '是否装表',
measure_info '计量点信息',
power_factor_type '参与功率因数计算方式',
voltage_level '电压等级',
inline_type '接线方式',
is_stop_power '是否可停电',
main_use '主用途类型',
measure_type '计量点分类',
measure_nature '计量点性质',
device_type '计量装置分类',
own_side '计量点所属侧',
shop_attrtype '市场化属性类型',
agent_price '代理购电特别电价(高耗能)',
station_info '站线台信息',
price_calc_way '电量计算方式',
power_factor_stand '功率因数标准',
rate_reduce_flag '定比扣减标志',
rate_value '定比定量值',
exec_order '执行顺序',
is_peak_flag '是否执行峰谷标志',
fee_hangye_type '电价行业类别',
exec_price '执行电价',
*/
var check = new Competition.Mysql.Model.app_measure_point();
//====1============
check.measure_name = "计量点名称";
check.measure_capacity = "计量点容量";
check.measure_way = "计量方式";
check.is_fill_meter = "是否装表";
check.measure_info = "计量点信息";
//====2=======
check.power_factor_type = "参与功率因数计算方式";
check.voltage_level = "电压等级";
check.inline_type = "接线方式";
check.is_stop_power = "是否可停电";
check.main_use = "主用途类型";
//====3=======
check.measure_type = "计量点分类";
check.measure_nature = "计量点性质";
check.device_type = "计量装置分类";
check.own_side = "计量点所属侧";
check.shop_attrtype = "市场化属性类型";
//====4=======
check.agent_price = "代理购电特别电价(高耗能)";
check.station_info = "站线台信息";
check.price_calc_way = "电量计算方式";
check.power_factor_stand = "功率因数标准";
check.rate_reduce_flag = "定比扣减标志";
//====5=======
check.rate_value = "定比定量值";
check.exec_order = "执行顺序";
check.is_peak_flag = "是否执行峰谷标志";
check.fee_hangye_type = "电价行业类别";
check.exec_price = "执行电价";
var obj = new
{
//======1=========
measure_name = "计量点名称",
measure_capacity = "计量点容量",
measure_way = "计量方式",
is_fill_meter = "是否装表",
measure_info = "计量点信息",
//=====2================
power_factor_type = "参与功率因数计算方式",
voltage_level = "电压等级",
inline_type = "接线方式",
is_stop_power = "是否可停电",
main_use = "主用途类型",
//=====3=========
measure_type = "计量点分类",
measure_nature = "计量点性质",
device_type = "计量装置分类",
own_side = "计量点所属侧",
shop_attrtype = "市场化属性类型",
//====4=======
agent_price = "代理购电特别电价(高耗能)",
station_info = "站线台信息",
price_calc_way = "电量计算方式",
power_factor_stand = "功率因数标准",
rate_reduce_flag = "定比扣减标志",
//====5=======
rate_value = "定比定量值",
exec_order = "执行顺序",
is_peak_flag = "是否执行峰谷标志",
fee_hangye_type = "电价行业类别",
exec_price = "执行电价",
};
var json = JsonConvert.SerializeObject(obj);
var list = bll.GetModelList("");
var result = GetResult(true, list);
return result;
}
//[Authorize]
///
/// 查询计量点
///
[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_measure_point();
try
{
model = JsonConvert.DeserializeObject(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
}
}