193 lines
6.7 KiB
C#
193 lines
6.7 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 AcceptPowerPlanController : BaseHandlerController
|
||
{
|
||
Competition.Mysql.BLL.app_accept_power_plan bll = new Competition.Mysql.BLL.app_accept_power_plan();
|
||
|
||
Competition.Mysql.BLL.app_client_collect bll_client_collect = new Competition.Mysql.BLL.app_client_collect();
|
||
|
||
private readonly IWebHostEnvironment _env;
|
||
public AcceptPowerPlanController(IHttpContextAccessor IHttpContextAccessor, IWebHostEnvironment env, IConfiguration iconfiguration)
|
||
{
|
||
Configuration = iconfiguration;
|
||
_env = env;
|
||
context = IHttpContextAccessor.HttpContext!;
|
||
CrossDomain();
|
||
}
|
||
|
||
//[Authorize]
|
||
/// <summary>
|
||
/// 查询所有信息
|
||
/// </summary>
|
||
[Route("All")]
|
||
public JsonResult QueryALL()
|
||
{
|
||
/*
|
||
accept_type '受电点类型',
|
||
accept_name '受电点名称',
|
||
power_count '电源数目',
|
||
high_power_factor '高峰负荷时功率因数',
|
||
have_self_power '有无自备电源',
|
||
power_remark '受电点备注',
|
||
power_plan_note '供电方案说明',
|
||
price_type '定价策略类型',
|
||
power_factor_checktype '功率因数考核方式',
|
||
fee_compute_type '基本电费计算方式',
|
||
protocol_stand '协议额定值',
|
||
*/
|
||
var check = new Competition.Mysql.Model.app_accept_power_plan();
|
||
check.accept_type = "受电点类型";
|
||
check.accept_name = "受电点名称";
|
||
check.power_count = "电源数目";
|
||
check.high_power_factor = (decimal)1.00;
|
||
check.have_self_power = "有无自备电源";
|
||
check.power_remark = "受电点备注";
|
||
check.power_plan_note = "供电方案说明";
|
||
|
||
check.price_type = "定价策略类型";
|
||
check.power_factor_checktype = "功率因数考核方式";
|
||
check.fee_compute_type = "基本电费计算方式";
|
||
check.protocol_stand = "协议额定值";
|
||
|
||
var obj = new
|
||
{
|
||
accept_type = "受电点类型",
|
||
accept_name = "受电点名称",
|
||
power_count = "电源数目",
|
||
high_power_factor = (decimal)1.00,
|
||
have_self_power = "有无自备电源",
|
||
power_remark = "受电点备注",
|
||
power_plan_note = "供电方案说明",
|
||
|
||
price_type = "定价策略类型",
|
||
power_factor_checktype = "功率因数考核方式",
|
||
fee_compute_type = "基本电费计算方式",
|
||
protocol_stand = "协议额定值",
|
||
};
|
||
|
||
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_accept_power_plan();
|
||
try
|
||
{
|
||
model = JsonConvert.DeserializeObject<Competition.Mysql.Model.app_accept_power_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
|
||
}
|
||
}
|