1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
3.6 KiB
C#

using HighWayIot.Log4net;
using HighWayIot.Repository.domain;
using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace HighWayIot.Repository.service
{
public class ZxWeightService
{
private static readonly Lazy<ZxWeightService> lazy = new Lazy<ZxWeightService>(() => new ZxWeightService());
public static ZxWeightService Instance
{
get
{
return lazy.Value;
}
}
private LogHelper log = LogHelper.Instance;
Repository<ZxWeightEntity> _repository => new Repository<ZxWeightEntity>("sqlserver");
/// <summary>
/// 根据配方编号查询称量信息
/// </summary>
/// <param name="recipeCode">配方号</param>
/// <returns></returns>
public List<ZxWeightEntity> GetWeightInfos(string recipeCode)
{
try
{
List<ZxWeightEntity> entity = _repository.GetList(x => x.RecipeCode == recipeCode && x.IsDeleted == false);
return entity;
}
catch (Exception ex)
{
log.Error("称量信息获取异常", ex);
return null;
}
}
/// <summary>
/// 新增称量信息
/// </summary>
/// <param name="entity">称量信息</param>
/// <returns></returns>
public bool InsertWeightInfo(ZxWeightEntity entity)
{
try
{
return _repository.Insert(entity);
}
catch (Exception ex)
{
log.Error("称量信息添加异常", ex);
return false;
}
}
/// <summary>
/// 修改称量信息
/// </summary>
/// <param name="entity">称量信息</param>
/// <returns></returns>
public bool UpdateWeightInfo(ZxWeightEntity entity)
{
try
{
return _repository.Update(entity);
}
catch(Exception ex)
{
log.Error("称量信息修改异常", ex);
return false;
}
}
/// <summary>
/// 根据ID删除称量信息
/// </summary>
/// <param name="id">ID</param>
/// <returns></returns>
public bool DeleteWeightInfoById(int id)
{
try
{
ZxWeightEntity e = _repository.GetById(id);
e.IsDeleted = true;
return _repository.Update(e);
}
catch (Exception ex)
{
log.Error("称量信息删除异常", ex);
return false;
}
}
/// <summary>
/// 根据RecipeCode删除称量信息
/// </summary>
/// <param name="recipeCode">配方号</param>
/// <returns></returns>
public bool DeleteWeightInfoByRecipeCode(string recipeCode)
{
try
{
List<ZxWeightEntity> es = _repository.GetList(x => x.RecipeCode == recipeCode && x.IsDeleted == false);
es.ForEach(x => x.IsDeleted = true);
if (es.Count == 0)
{
return true;
}
return _repository.UpdateRange(es);
}
catch (Exception ex)
{
log.Error("称量信息删除异常", ex);
return false;
}
}
}
}