forked from wenjy/HighWayIot
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.
120 lines
3.5 KiB
C#
120 lines
3.5 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 ZxMaterialService
|
|
{
|
|
private static readonly Lazy<ZxMaterialService> lazy = new Lazy<ZxMaterialService>(() => new ZxMaterialService());
|
|
|
|
public static ZxMaterialService Instance
|
|
{
|
|
get
|
|
{
|
|
return lazy.Value;
|
|
}
|
|
}
|
|
|
|
private LogHelper log = LogHelper.Instance;
|
|
Repository<ZxMaterialEntity> _repository => new Repository<ZxMaterialEntity>("sqlserver");
|
|
|
|
/// <summary>
|
|
/// 查询所有物料信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<ZxMaterialEntity> GetMaterialInfos(string materialName = null, string materialType = null, string childType = null)
|
|
{
|
|
try
|
|
{
|
|
List<ZxMaterialEntity> entity = _repository.GetList(x => x.IsDeleted == false);
|
|
if(!string.IsNullOrEmpty(materialName))
|
|
{
|
|
entity = entity.Where(x => x.MaterialName.Contains(materialName)).ToList();
|
|
}
|
|
|
|
if(!string.IsNullOrEmpty(materialType))
|
|
{
|
|
if(!string.IsNullOrEmpty(childType))
|
|
{
|
|
entity.Where(x => x.MaterialType == materialType && x.ChildType == childType).ToList();
|
|
}
|
|
else
|
|
{
|
|
entity.Where(x => x.MaterialType == materialType).ToList();
|
|
}
|
|
}
|
|
|
|
return entity;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error("物料信息获取异常", ex);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改物料信息
|
|
/// </summary>
|
|
/// <param name="entity"></param>
|
|
/// <returns></returns>
|
|
public bool UpdateMaterialInfo(ZxMaterialEntity entity)
|
|
{
|
|
try
|
|
{
|
|
return _repository.Update(entity);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error("物料信息修改异常", ex);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增物料信息
|
|
/// </summary>
|
|
/// <param name="entity"></param>
|
|
/// <returns></returns>
|
|
public bool InsertMaterialInfo(ZxMaterialEntity entity)
|
|
{
|
|
try
|
|
{
|
|
return _repository.Insert(entity);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error("物料信息添加异常", ex);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除物料信息
|
|
/// </summary>
|
|
/// <param name="materialCode"></param>
|
|
/// <returns></returns>
|
|
public bool DeleteMaterialInfoByMaterialCode(string materialCode)
|
|
{
|
|
try
|
|
{
|
|
ZxMaterialEntity e = _repository.GetById(materialCode);
|
|
e.IsDeleted = true;
|
|
return _repository.Update(e);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error("物料信息删除异常", ex);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|