天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

505 lines
15 KiB

using System;
using System.Collections.Generic;
using QMAPP.BLL;
using QMAPP.FJC.Entity.EnergyManage;
using QMAPP.FJC.DAL.EnergyManage;
using QMFrameWork.Data;
using QMAPP.Entity;
using System.Data;
using QMAPP.FJC.Entity;
namespace QMAPP.FJC.BLL.EnergyManage
{
/// <summary>
/// 模块名称:能源仪表维护
/// 作 者:周晓东
/// 编写日期:2018年03月03日
/// </summary>
public class MeterBLL : BaseBLL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>信息</returns>
public DataResult<Meter> Get(Meter info)
{
DataResult<Meter> result = new DataResult<Meter>();
try
{
result.Result= new MeterDAL().Get(info);
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
public DataResult<MeterReadings> GetMaxMeterReadings(MeterReadings info)
{
DataResult<MeterReadings> result = new DataResult<MeterReadings>();
try
{
result.Result = new MeterDAL().GetMaxMeterReadings(info);
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
public DataResult<MeterReadings> GetMeterReadings(MeterReadings info)
{
DataResult<MeterReadings> result = new DataResult<MeterReadings>();
try
{
result.Result = new MeterDAL().GetMeterReadings(info);
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataResult<DataPage> GetLists(Meter condition, DataPage page)
{
DataResult<DataPage> result = new DataResult<DataPage>();
try
{
DataPage dataPage = new MeterDAL().GetList(condition, page);
#region 转换报警类别、工序类别显示类型
List<Meter> List = dataPage.Result as List<Meter>;
foreach (Meter m in List)
{
//能源表状态 0 作废 1 自动 2 手动
if (m.STATE=="0")
{
m.STATE_TXT = "作废";
}
else if (m.STATE == "1")
{
m.STATE_TXT = "自动";
}
else if (m.STATE == "2")
{
m.STATE_TXT = "手动";
}
//能源表类型 0 电 1 水
if (m.METER_TYPE == "0")
{
m.METER_TYPE_TXT = "电";
}
else if (m.METER_TYPE == "1")
{
m.METER_TYPE_TXT = "水";
}
else if (m.METER_TYPE == "2")
{
m.METER_TYPE_TXT = "气";
}
}
#endregion
result.Result = dataPage;
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 获取电表读数列表
/// <summary>
/// 获取电表读数列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataResult<DataPage> MeterReadingsConfigList(MeterReadings condition, DataPage page)
{
DataResult<DataPage> result = new DataResult<DataPage>();
try
{
DataPage dataPage = new MeterDAL().MeterReadingsConfigList(condition, page);
#region 转换报警类别、工序类别显示类型
List<MeterReadings> List = dataPage.Result as List<MeterReadings>;
foreach (MeterReadings m in List)
{
//能源表状态 0 失败 1 自动 2 手动
if (m.READ_RESULT == "0")
{
m.READ_RESULT = "失败";
}
else if (m.READ_RESULT == "1")
{
m.READ_RESULT = "自动";
}
else if (m.READ_RESULT == "2")
{
m.READ_RESULT = "手动";
}
//能源表类型 0 电 1 水
if (m.METER_TYPE == "0")
{
m.METER_TYPE_TXT = "电";
}
else if (m.METER_TYPE == "1")
{
m.METER_TYPE_TXT = "水";
}
else if (m.METER_TYPE == "2")
{
m.METER_TYPE_TXT = "气";
}
}
#endregion
result.Result = dataPage;
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 信息是否重复
/// <summary>
/// 判断名称是否存在
/// </summary>
/// <param name="">信息</param>
/// <returns>true:已存在;fasel:不存在。</returns>
public bool Exists(Meter info)
{
try
{
return new MeterDAL().Exists(info);
}
catch (Exception ex)
{
throw ex;
}
}
public bool ExistsEqptCode(Meter info)
{
try
{
return new MeterDAL().ExistsEqptCode(info);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public DataResult<int> InsertMeterReadings(MeterReadings info)
{
DataResult<int> result = new DataResult<int>();
info.READ_RESULT = "2";
var mrd=GetMaxMeterReadings(info);
if (mrd.Result != null )
{
if (info.READ_TIME <= mrd.Result.READ_TIME)
{
result.IsSuccess = false;
result.Msg = "读取时间必须大于:" + mrd.Result.READ_TIME;
return result;
}
if (info.READING < mrd.Result.READING)
{
result.IsSuccess = false;
result.Msg = "电量必须大于等于:" + mrd.Result.READING;
return result;
}
info.DIFF_WITH_LAST = info.READING - mrd.Result.READING;
}
else
{
info.DIFF_WITH_LAST = info.READING;
}
try
{
//基本信息
info.PID = Guid.NewGuid().ToString();
result.Result = new MeterDAL().InsertMeterReadings(info);
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
throw ex;
}
}
public DataResult<int> Insert(Meter info)
{
DataResult<int> result = new DataResult<int>();
try
{
//基本信息
info.PID = Guid.NewGuid().ToString();
result.Result = new MeterDAL().Insert(info);
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name="">信息</param>
/// <returns>更新行数</returns>
public DataResult<int> UpdateMeterReadings(MeterReadings info)
{
DataResult<int> result = new DataResult<int>();
var mrd = GetMaxMeterReadings(info);
if (info.PID != mrd.Result.PID)
{
result.IsSuccess = false;
result.Msg = "只能修改最后一条" ;
return result;
}
try
{
result.Result = new MeterDAL().UpdateMeterReadings(info);
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
throw ex;
}
}
public DataResult<int> Update(Meter info)
{
DataResult<int> result = new DataResult<int>();
try
{
result.Result = new MeterDAL().Update(info);
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 删除
/// <summary>
/// 删除信息
/// </summary>
/// <param name="">主键串</param>
/// <returns>删除个数</returns>
public DataResult<int> DeleteMeterReadings(string str)
{
int count = 0;
var mrd = new MeterReadings {PID = str};
var m1 = GetMeterReadings(mrd);
var m2 = GetMaxMeterReadings(m1.Result);
DataResult<int> result = new DataResult<int>();
if (m2.Result != null)
{
if (m1.Result.PID != m2.Result.PID)
{
result.IsSuccess = false;
result.Msg = "只能删除最后一条";
return result;
}
}
try
{
result.Result = new MeterDAL().DeleteMeterReadings(mrd);
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
throw ex;
}
}
public DataResult<int> DeleteArray(string strs)
{
int count = 0;
DataResult<int> result = new DataResult<int>();
string[] list = strs.Split(":".ToCharArray());
try
{
foreach (string str in list)
{
count += this.Delete(new Meter { PID = str });
}
result.Result = count;
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 删除信息
/// </summary>
/// <param name="">信息</param>
/// <returns>删除个数</returns>
public int Delete(Meter info)
{
try
{
return new MeterDAL().Delete(info);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 导出数据
/// <summary>
/// 获取导出的数据
/// </summary>
/// <param name="">查询条件</param>
/// <returns>数据</returns>
public DataTable GetExportData(Meter info)
{
return null;
}
#endregion
#region 导入数据
/// <summary>
/// 导入数据
/// </summary>
/// <param name="list">数据</param>
/// <returns>导入结果</returns>
public DataResult<ImportMessage> ImportData(List<Meter> list)
{
DataResult<ImportMessage> result = new DataResult<ImportMessage>();
MeterDAL cmDal = new MeterDAL();
List<Meter> List = new List<Meter>();
int index = 0;
try
{
result.Result = new ImportMessage();
result.Result.Errors = new List<RowError>();
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//状态判断
foreach (Meter ma in list)
{
index++;
if (!string.IsNullOrEmpty(ma.InfoError))
{
ma.PID = null;
result.Result.failureNum += 1;
continue;
}
//修改改时根据主键等信息获取详细内容信息
Meter oldInfo = cmDal.Get(ma);
if (oldInfo != null)
{
//更新
ma.PID = oldInfo.PID;
ma.IsNewInfo = false;
result.Result.updateNum += 1;
}
else
{
//新增
oldInfo = new Meter();
ma.PID = Guid.NewGuid().ToString();
ma.IsNewInfo = true;
result.Result.insertNum += 1;
}
List.Add(ma);
}
}
//导入
cmDal.GetImportData(List);
result.Msg = "导入成功";
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Ex = ex;
return result;
}
}
#endregion
public List<Meter> GetList(Meter condition)
{
try
{
return new MeterDAL().GetList(condition);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 抄表(全部电表)
/// </summary>
/// <returns></returns>
public string ReadAllMeter()
{
MeterReader.ReadAllMeter();
return "READED";
}
}
}