CompetitionAPI_dotnet/CompetitionAPI/Controllers/PowerPlanController.cs

201 lines
6.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 PowerPlanController : BaseHandlerController
{
Competition.Mysql.BLL.app_power_plan bll = new Competition.Mysql.BLL.app_power_plan();
Competition.Mysql.BLL.app_client_collect bll_client_collect = new Competition.Mysql.BLL.app_client_collect();
private readonly IWebHostEnvironment _env;
public PowerPlanController(IHttpContextAccessor IHttpContextAccessor, IWebHostEnvironment env, IConfiguration iconfiguration)
{
Configuration = iconfiguration;
_env = env;
context = IHttpContextAccessor.HttpContext!;
CrossDomain();
}
//[Authorize]
/// <summary>
/// 查询所有信息
/// </summary>
[Route("All")]
public JsonResult QueryALL()
{
/*
power_nature '电源性质',
power_type '电源类型',
power_capacity '供电容量',
power_voltage '供电电压',
in_line_type '进线方式',
power_phase '电源相数',
protect_type '保护方式',
relay_protect_type '继电保护类型',
property_split '产权分界点',
in_line_no '进线杆号/电缆分支箱',
power_remark '电源备注',
station_info '站线台信息',
*/
var check = new Competition.Mysql.Model.app_power_plan();
check.power_nature = "电源性质";
check.power_type = "电源类型";
check.power_capacity = "供电容量";
check.power_voltage = "供电电压";
check.in_line_type = "进线方式";
check.power_phase = "电源相数";
check.protect_type = "保护方式";
check.relay_protect_type = "继电保护类型";
check.property_split = "产权分界点";
check.in_line_no = "进线杆号/电缆分支箱";
check.power_remark = "电源备注";
check.station_info = "站线台信息";
var obj = new
{
power_nature = "电源性质",
power_type = "电源类型",
power_capacity = "供电容量",
power_voltage = "供电电压",
in_line_type = "进线方式",
power_phase = "电源相数",
protect_type = "保护方式",
relay_protect_type = "继电保护类型",
property_split = "产权分界点",
in_line_no = "进线杆号/电缆分支箱",
power_remark = "电源备注",
station_info = "站线台信息",
};
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_power_plan();
try
{
model = JsonConvert.DeserializeObject<Competition.Mysql.Model.app_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
}
}