using IStation.CalcModel;
|
using IStation.Common;
|
using IStation.Dto;
|
using System;
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Linq;
|
using System.Net;
|
using System.Net.Http;
|
using System.Security.Permissions;
|
using System.Text;
|
using System.Threading.Tasks;
|
using System.Web;
|
using System.Web.Http;
|
using System.Web.UI.WebControls;
|
using System.Web.UI.WebControls.WebParts;
|
|
namespace IStation.WebApi.Controllers
|
{
|
/// <summary>
|
/// 计算配置
|
/// </summary>
|
[RoutePrefix("AnaPrj")]
|
public class AnaPrjController : ApiController
|
{
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="day"></param>
|
/// <returns></returns>
|
[Route("Debug")]
|
[HttpGet]
|
public IStation.Dto.ApiResult Debug(string info)
|
{
|
|
IStation.LogHelper.Info("debug:"+ info);
|
|
|
return new IStation.Dto.ApiResult<string >("ok");
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="day"></param>
|
/// <returns></returns>
|
[Route("GetPrj")]
|
[HttpGet]
|
public IStation.Dto.ApiResult GetPrj(string day)
|
{
|
if (day == null)
|
{
|
return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day null" };
|
}
|
DateTime d;
|
if (!DateTime.TryParse(day, out d))
|
{
|
return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 格式不正确" };
|
}
|
|
var prj = Common.HistoryAnaPrjFileHelper.GetPrj(d);
|
|
return new IStation.Dto.ApiResult<IStation.CalcModel.AnaPrj>(prj);
|
}
|
|
|
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="day"></param>
|
/// <returns></returns>
|
[Route("GetExistStatus")]
|
[HttpGet]
|
public IStation.Dto.ApiResult GetExistStatus(int year, int month)
|
{
|
var list = HistoryAnaPrjFileHelper.GetExistStatus(year, month);
|
if (list == null)
|
{
|
list = new List<string >();
|
}
|
|
return new IStation.Dto.ApiResult<List<string>>(list);
|
}
|
|
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="day"></param>
|
/// <returns></returns>
|
[Route("GetLastTimeOpenPumpCount")]
|
[HttpGet]
|
public IStation.Dto.ApiResult GetLastTimeOpenPumpCount(DateTime day)
|
{
|
int dict = HistoryAnaPrjFileHelper.GetLastTime_OpenPumpCount(day);
|
|
return new IStation.Dto.ApiResult<int>(dict);
|
}
|
|
|
|
public class SavePrjRequest
|
{
|
public IStation.CalcModel.AnaSetting settting { get; set; }
|
public IStation.CalcModel.AnaRequestBase requestBase { get; set; }
|
public IStation.CalcModel.AnaPrj prj { get; set; }
|
public bool isSubmit { get; set; }
|
}
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="request"></param>
|
/// <returns></returns>
|
[Route("SavePrj")]
|
[HttpPost]
|
public async Task<IStation.Dto.ApiResult> SavePrj([FromBody] SavePrjRequest request)
|
{
|
if (request == null )
|
{
|
return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day null" };
|
}
|
if (request.prj == null)
|
{
|
return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "prj null" };
|
}
|
|
var ret = Common.HistoryAnaPrjFileHelper.SavePrj( request.settting, request.requestBase, request.prj);
|
|
if (request.isSubmit)
|
{
|
string error = await ZyConnectHelper.SubmitPrj(request.prj);//, (id) => { IStation.LogHelper.Info("SavePrj success id=" + id); }, (info) => { IStation.LogHelper.Info("SavePrj failse info:" + info); });//.Result;
|
|
|
|
|
if(!string.IsNullOrEmpty(error))
|
{
|
IStation.LogHelper.Info("Submit prj finish (fail) day:" + request.requestBase.StartTime + ",error:" + error);
|
return new IStation.Dto.ApiResult<string>(error) { Code = ApiResultCode.Error};
|
}
|
else
|
{
|
IStation.LogHelper.Info("Submit prj finish (success) day:" + request.requestBase.StartTime);
|
}
|
}
|
|
|
return new IStation.Dto.ApiResult<bool>(ret) { Code = ApiResultCode.Success };
|
}
|
|
|
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="request"></param>
|
/// <returns></returns>
|
[Route("CalcPrj")]
|
[HttpPost]
|
public async Task<IStation.Dto.ApiResult> CalcPrj([FromBody] SavePrjRequest request)
|
{
|
if (request == null )
|
{
|
return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day null" };
|
}
|
if (request.prj == null)
|
{
|
return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "prj null" };
|
}
|
|
var ret = Common.HistoryAnaPrjFileHelper.SavePrj( request.settting, request.requestBase, request.prj);
|
|
if (request.isSubmit)
|
{
|
string error = await ZyConnectHelper.SubmitPrj(request.prj);//, (id) => { IStation.LogHelper.Info("SavePrj success id=" + id); }, (info) => { IStation.LogHelper.Info("SavePrj failse info:" + info); });//.Result;
|
|
|
|
|
if (!string.IsNullOrEmpty(error))
|
{
|
IStation.LogHelper.Info("Submit prj finish (fail) day:" + request.requestBase.StartTime + ",error:" + error);
|
return new IStation.Dto.ApiResult<string>(error) { Code = ApiResultCode.Error };
|
}
|
else
|
{
|
IStation.LogHelper.Info("Submit prj finish (success) day:" + request.requestBase.StartTime);
|
}
|
}
|
|
|
return new IStation.Dto.ApiResult<bool>(ret) { Code = ApiResultCode.Success };
|
}
|
|
|
|
}
|
}
|