using Microsoft.Extensions.Logging; using SlnMesnac.Model.domain; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SlnMesnac.Repository.service.Impl { public class LogoConfigImpl : ILogoConfigService { private readonly ILogger _logger; private readonly Repository _rep; public LogoConfigImpl(ILogger logger, Repository rep) { _logger = logger; _rep = rep; } /// /// 从MES查询所有型号 /// /// public List GetMesAllRecord() { List list = null; try { // 查询MES所有型号 list = _rep.Context.SqlQueryable(@"SELECT * FROM ( SELECT a.MATERIAL_CODE, a.MATERIAL_NAME FROM ( SELECT T.MATERIAL_CODE, ( SELECT MAX( B.MATERIAL_NAME ) FROM IMOS_TA_MATERIAL B WHERE B.MATERIAL_CODE = T.MATERIAL_CODE ) AS MATERIAL_NAME FROM IMOS_TA_MATERIAL t WHERE T.DETIAL_TYPE_NAME = '成品' AND T.FACTORY_CODE = '2006' ) a WHERE ( a.MATERIAL_CODE LIKE '%%' OR a.MATERIAL_NAME LIKE '%%' ) ORDER BY a.MATERIAL_CODE, a.MATERIAL_NAME ) T;").ToList(); } catch (Exception ex) { _logger.LogError($"从MES查询数据库所有型号失败:{ex.Message}"); } return list; } /// /// 模糊查询,从本地查询某个型号 /// /// public async Task> GetLikeByCode(string code) { List list = null; list = await _rep.GetListAsync(x=>x.MaterialType.Contains(code) || x.MaterialName.Contains(code)); return list; } /// /// 从本地查询所有型号用来展示 /// /// public async Task> GetLocalAllRecordAsync() { List list = null; list =await _rep.GetListAsync(); return list; } /// ///指定型号查询 /// /// public LogoConfig GetByMaterialType(string materialType) { LogoConfig logoConfig = null; logoConfig = _rep.GetFirst(x => x.MaterialType == materialType); return logoConfig; } /// ///指定型号修改是否校验 /// /// public bool updateByMaterialType(LogoConfig record) { bool result = _rep.Update(record); return result; } /// /// 批量插入型号 /// /// public async Task InsertListAsync(List list) { bool result = await _rep.InsertRangeAsync(list); return result; } } }