using Competition.Common.Util;
using CompetitionAPI.Util;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System.Security.Cryptography.X509Certificates;
namespace CompetitionAPI.Controllers
{
///
/// 供电方案-现场勘探(供电方案)
///
[Route("api/[controller]")]
[ApiController]
public class PlaceCheckController : BaseHandlerController
{
Competition.Mysql.BLL.app_place_check bll = new Competition.Mysql.BLL.app_place_check();
Competition.Mysql.BLL.app_client_collect bll_client_collect = new Competition.Mysql.BLL.app_client_collect();
private readonly IWebHostEnvironment _env;
public PlaceCheckController(IHttpContextAccessor IHttpContextAccessor, IWebHostEnvironment env, IConfiguration iconfiguration)
{
Configuration = iconfiguration;
_env = env;
context = IHttpContextAccessor.HttpContext!;
CrossDomain();
}
//[Authorize]
///
/// 查询所有联系人信息
///
[Route("All")]
public JsonResult QueryALL()
{
var check = new Competition.Mysql.Model.app_place_check();
check.verify_capacity = "核定容量";
check.power_voltage = "供电电压";
check.power_type = "负荷性质一类";
check.if_has_project_flag = "无工程";
check.if_jiakong = "是否架空";
check.if_yulinbiao = "是否预领表";
check.if_new_point = "是";
check.power_plan_note = "供电方案说明";
check.accept_power_time = DateTime.Now;
check.zhuangong_flag = "转供标志";
var obj = new
{
verify_capacity = "核定容量",
power_voltage = "供电电压",
power_type = "负荷性质一类",
if_has_project_flag = "无工程",
if_jiakong = "是否架空",
if_yulinbiao = "是否预领表",
if_new_point = "是",
power_plan_note = "供电方案说明",
accept_power_time = DateTime.Now,
zhuangong_flag = "转供标志"
};
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 + "'").OrderByDescending(s => s.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_place_check();
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
}
}