123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050 |
- using Mapster;
- using SqlSugar;
- using wms.sqlsugar.model.fj;
- using WMS.BZModels;
- using WMS.BZModels.Dto.FJ.BillBom;
- using WMS.BZModels.Models.FJ;
- using WMS.BZSqlSugar;
- using WMS.Info;
- namespace WMS.BZServices.FJ
- {
- public class BillBomSetService
- {
- private readonly Repository<BillBomsetgrp> _billBomsetgrpRepository;
- private readonly Repository<BillBomsetinfo> _billBomsetinfoRepository;
- private readonly Repository<BillBominfo> _billBominfoRepository;
- private readonly Repository<BaseMatinfo> _matinforepository;
- private readonly Repository<BillPaiKu> _billPaiKurepository;
- private readonly Repository<BaseWarehouse> _billBaseWarehouse;
- public BillBomSetService(Repository<BillBomsetgrp> billBomsetgrpRepository,
- Repository<BillBomsetinfo> billBomsetinfoRepository,
- Repository<BillBominfo> billBominfoRepository,
- Repository<BaseMatinfo> matinforepository,
- Repository<BillPaiKu> billPaiKurepository,
- Repository<BaseWarehouse> billBaseWarehouse)
- {
- _billBomsetgrpRepository = billBomsetgrpRepository;
- _billBomsetinfoRepository = billBomsetinfoRepository;
- _billBominfoRepository = billBominfoRepository;
- _matinforepository = matinforepository;
- _billPaiKurepository = billPaiKurepository;
- _billBaseWarehouse = billBaseWarehouse;
- }
- public PagedInfo<BillBomsetgrpDto> GetPageList(Pagination pagination, BillBomsetgrpQueryDto billBomsetgrpQueryDto)
- {
- var list = GetQueryable(billBomsetgrpQueryDto)
- .ToPage<BillBomsetgrp, BillBomsetgrpDto>(pagination);
- return list;
- }
- public IEnumerable<dynamic> PaiKuGetList()
- {
- var list = _billBomsetgrpRepository.AsQueryable().With(SqlWith.NoLock).Where(x => x.IsStop == 0).ToList().Select(x => new { id = x.Id.ToString(), text = x.Name });
- return list;
- }
- public PagedInfo<BillPaiKuDto> GetPaiKuList(Pagination pagination, BillPaiKuQueryDto billPaiKuQueryDto)
- {
- var predicate = Expressionable.Create<BillPaiKu, BillBomsetgrp, BaseWarehouse>();
- predicate = predicate.AndIF(!string.IsNullOrEmpty(billPaiKuQueryDto?.KeyWord), (paiku, bomsetgrp, wareHouse) =>
- paiku.Id.ToString() == billPaiKuQueryDto.KeyWord ||
- paiku.WarehousId.ToString() == billPaiKuQueryDto.KeyWord ||
- paiku.WarehouseCode.Contains(billPaiKuQueryDto.KeyWord) ||
- paiku.BomsetgrpId.ToString() == billPaiKuQueryDto.KeyWord ||
- paiku.BomsetgrpName.Contains(billPaiKuQueryDto.KeyWord) ||
- paiku.Percent.ToString() == billPaiKuQueryDto.KeyWord);
- predicate = predicate.AndIF(!string.IsNullOrEmpty(billPaiKuQueryDto.WarehouseId), (paiku, bomsetgrp, wareHouse) => paiku.WarehousId.ToString() == billPaiKuQueryDto.WarehouseId);
- predicate = predicate.AndIF(!string.IsNullOrEmpty(billPaiKuQueryDto.BomsetgrpId), (paiku, bomsetgrp, wareHouse) => paiku.BomsetgrpId.ToString() == billPaiKuQueryDto.BomsetgrpId);
- predicate = predicate.AndIF(!string.IsNullOrEmpty(billPaiKuQueryDto.Percent), (paiku, bomsetgrp, wareHouse) => paiku.Percent.ToString() == billPaiKuQueryDto.Percent);
- var list = _billPaiKurepository.Context.Queryable<BillPaiKu, BillBomsetgrp, BaseWarehouse>((paiku, bomsetgrp, wareHouse) => new object[]
- {
- JoinType.Left, paiku.BomsetgrpId == bomsetgrp.Id,
- JoinType.Left, paiku.WarehousId==wareHouse.Id,
- }).Where(predicate.ToExpression())
- .Select((paiku, bomsetgrp, wareHouse) => new BillPaiKuDto
- {
- Id = paiku.Id.ToString(),
- Memo = paiku.Memo,
- AddWho = paiku.AddWho,
- EditWho = paiku.EditWho,
- AddTime = paiku.AddTime,
- EditTime = paiku.EditTime,
- BomsetgrpId = paiku.BomsetgrpId.ToString(),
- BomsetgrpName = paiku.BomsetgrpName,
- WarehousId = paiku.WarehousId.ToString(),
- WarehouseCode = paiku.WarehouseCode,
- Percent = paiku.Percent
- })
- .MergeTable()
- .OrderByIF(!pagination.sidx.IsEmpty(), $"{pagination.sidx.ToSqlFilter()} {(!string.IsNullOrWhiteSpace(pagination.sord) && pagination.sord.ToLower().Contains("desc") ? "desc" : "asc")}").ToList().Adapt<List<BillPaiKuDto>>();
- var page = new PagedInfo<BillPaiKuDto>
- {
- PageSize = pagination.rows,
- PageIndex = pagination.page,
- TotalNum = list.Count,
- Result = list
- };
- return page;
- }
- private ISugarQueryable<BillBomsetgrp> GetQueryable(BillBomsetgrpQueryDto billBomsetgrpQueryDto)
- {
- var predicate = Expressionable.Create<BillBomsetgrp>();
- predicate = predicate.AndIF(!string.IsNullOrEmpty(billBomsetgrpQueryDto?.KeyWord), m => m.Code.Contains(billBomsetgrpQueryDto.KeyWord)
- || m.ProCode.Contains(billBomsetgrpQueryDto.KeyWord) || m.ProMaterCode.Contains(billBomsetgrpQueryDto.KeyWord) || m.ShortCode.ToString().Contains(billBomsetgrpQueryDto.KeyWord));
- predicate = predicate.AndIF(!string.IsNullOrEmpty(billBomsetgrpQueryDto?.Code), m => m.Code.Contains(billBomsetgrpQueryDto.Code));
- predicate = predicate.AndIF(!string.IsNullOrEmpty(billBomsetgrpQueryDto?.Name), m => m.Name.Contains(billBomsetgrpQueryDto.Name));
- predicate = predicate.AndIF(!string.IsNullOrEmpty(billBomsetgrpQueryDto?.ShortCode), m => m.ShortCode.ToString().Contains(billBomsetgrpQueryDto.ShortCode));
- predicate = predicate.AndIF(!string.IsNullOrEmpty(billBomsetgrpQueryDto?.ProMaterCode), m => m.ProMaterCode.Contains(billBomsetgrpQueryDto.ProMaterCode));
- predicate = predicate.AndIF(!string.IsNullOrEmpty(billBomsetgrpQueryDto?.BomName), m => m.BomName.Contains(billBomsetgrpQueryDto.BomName));
- predicate = predicate.AndIF(!string.IsNullOrEmpty(billBomsetgrpQueryDto?.ProCode), m => m.ProCode.Contains(billBomsetgrpQueryDto.ProCode));
- predicate = predicate.AndIF(!string.IsNullOrEmpty(billBomsetgrpQueryDto?.StampType), m => m.StampType.Equals(billBomsetgrpQueryDto.StampType));
- predicate = predicate.AndIF(!string.IsNullOrEmpty(billBomsetgrpQueryDto?.IsStop), m => m.IsStop.Equals(billBomsetgrpQueryDto.IsStop));
- predicate = predicate.AndIF(!string.IsNullOrEmpty(billBomsetgrpQueryDto?.IsDelete), m => m.IsDelete.Equals(billBomsetgrpQueryDto.IsDelete));
- var sugarQueryable = _billBomsetgrpRepository.Queryable().Where(predicate.ToExpression());
- return sugarQueryable;
- }
- public IList<BillBomsetgrpDto> GetList(BillBomsetgrpQueryDto billBomsetgrpQueryDto)
- {
- var list = GetQueryable(billBomsetgrpQueryDto).ToList().Adapt<List<BillBomsetgrpDto>>();
- return list;
- }
- public IList<BillBomsetinfoDto> GetBillBomsetinfoItem(long bomSetHdrId)
- {
- var predicate = Expressionable.Create<BillBomsetinfo>();
- predicate = predicate.AndIF(bomSetHdrId > 0, m => m.BomSetHdrId.Equals(bomSetHdrId));
- var list = _billBomsetinfoRepository.Queryable().Where(predicate.ToExpression()).ToList().OrderBy(o => Convert.ToInt32(o.XYNo)).Adapt<List<BillBomsetinfoDto>>();
- return list;
- }
- public BillBomsetDto GetBillBomsetinfo(long BomsetId)
- {
- var bomset = _billBomsetgrpRepository.Queryable().Single(o => o.Id == BomsetId);
- if (bomset == null)
- {
- throw BZSysExCore.ThrowFailException("不存在的跺型!");
- }
- var bomsetinfos = _billBomsetinfoRepository.Queryable().Where(o => o.BomSetHdrId == bomset.Id && o.IsEmpty == 0).ToList();
- var dto = bomset.Adapt<BillBomsetDto>();
- dto.Bomsetinfos = bomsetinfos.Adapt<List<BillBomsetinfoDto>>();
- return dto;
- }
- public void Save09(LoginUserInfo loginUser, string keyValue, BillBomsetgrp billBomsetgrpEntity, IList<BillBomsetinfo> billBomsetinfos)
- {
- if (string.IsNullOrWhiteSpace(billBomsetgrpEntity.Code))
- {
- throw BZSysExCore.ThrowFailException("跺型编码不能为空!");
- }
- if (string.IsNullOrWhiteSpace(billBomsetgrpEntity.ProCode))
- {
- throw BZSysExCore.ThrowFailException("投料信息不能为空!");
- }
- if (billBomsetinfos == null || !billBomsetinfos.Any())
- {
- throw BZSysExCore.ThrowFailException("请选择跺型工字轮编号!");
- }
- if (billBomsetgrpEntity.ShortCode <= 0)
- {
- throw BZSysExCore.ThrowFailException("跺型短编码不正确!");
- }
- var infoMatCodes = billBomsetinfos.Select(o => o.MatCode).Distinct().ToList();
- // var duplicates = infoMatCodes.GroupBy(x => x).Where(g => g.Count() > 1).ToDictionary(x => x.Key, x => x.Count());
- //var hasDuplicates = infoMatCodes.GroupBy(x => x).Any(g => g.Count() > 1);
- var duplicates = infoMatCodes.GroupBy(x => x).Where(g => g.Count() > 1).Select(x => x.Key).ToList();
- if (duplicates != null && duplicates.Any())
- {
- throw BZSysExCore.ThrowFailException(string.Join(",", duplicates) + ",湿拉物料有重复!");
- }
- // todo 判断数量
- // 主数据的数量和子的数量要一致。
- //var groups = billBomsetinfos.GroupBy(o => o.MatCode).Select(g => (new { key = g, max = g.Max(n => n.QtyMaxCount), count = g.Count() }));
- //if (billBomsetinfos.Count() != billBomsetgrpEntity.HWCountQty)
- //{
- // throw BZSysExCore.ThrowFailException("填写的跺型数量不一致!");
- //}
- //if (groups.Any(o => o.max != o.count))
- //{
- // throw BZSysExCore.ThrowFailException("子跺型选择的工字轮和填写的数量不一致!");
- //}
- var first = billBomsetinfos.FirstOrDefault();
- for (int i = 1; i <= billBomsetgrpEntity.TotalQty; i++)
- {
- var item = billBomsetinfos.FirstOrDefault(o => o.XYNo == i.ToString());
- if (item == null)
- {
- billBomsetinfos.Add(new BillBomsetinfo
- {
- BomSetHdrId = first.BomSetHdrId,
- CategoryId = 99,
- XYNo = i.ToString(),
- IsEmpty = 1,
- IsStop = 1,
- });
- }
- }
- billBomsetinfos.ToList().ForEach(o =>
- {
- o.Row = Convert.ToInt32(Math.Ceiling(Convert.ToInt32(o.XYNo) / 5.0d));
- });
- var mixRows = billBomsetinfos.GroupBy(o => new { o.Row, o.MatCode }).Where(o => o.Count() != 5).ToList().GroupBy(o => o.Key.Row).Where(o => o.Count() > 1);
- foreach (var row in mixRows)
- {
- billBomsetinfos.Where(o => o.Row == row.Key).ToList().ForEach(o =>
- {
- if (row.Key.HasValue)
- {
- o.IsMixRow = 1;
- o.MixRowCode = row.Key.Value.ToString();
- }
- });
- }
- var procodelists = _billBominfoRepository.Queryable().Where(o => billBomsetgrpEntity.ProCode == o.ProCode && o.IsDelete == 0 && o.IsStop == 0).ToList();
- if (!procodelists.Any())
- {
- throw BZSysExCore.ThrowFailException("投料信息不存在!");
- }
- //if (!_matinforepository.Queryable().Any(o => o.Code == billBomsetgrpEntity.ProMaterCode))
- //{
- // throw BZSysExCore.ThrowFailException("产出物料编码不存在!");
- //}
- var baseMatinfos = _billBominfoRepository.Queryable().Where(o => o.IsDelete == 0 && o.IsStop == 0 && infoMatCodes.Contains(o.MatCode)).ToList();
- //foreach (var item in infoMatCodes)
- //{
- // if (baseMatinfos.Where(o => o.MatCode == item).Select(o => o.ProCode).Distinct().Count() > 1)
- // {
- // throw BZSysExCore.ThrowFailException("湿拉物料存在于多个投料大类中!");
- // }
- //}
- //var bomProMatCodelists = _billBominfoRepository.Queryable().Where(o => o.ProCode == billBomsetgrpEntity.BomCode).Select(o => o.ProMatCode).Distinct().ToList();
- //billBomsetgrpEntity.ProMaterCode = string.Join(',', bomProMatCodelists);
- if (keyValue.IsEmpty() || keyValue == "undefined")
- {
- var mat = _billBomsetgrpRepository.GetSingle(p => p.Code == billBomsetgrpEntity.Code);
- if (mat != null)
- {
- throw BZSysExCore.ThrowFailException("跺型编码已存在!");
- }
- //if (_billBomsetgrpRepository.Queryable().Any(o => o.ShortCode == billBomsetgrpEntity.ShortCode))
- //{
- // throw BZSysExCore.ThrowFailException("跺型内部编码已存在,请重新修改短编号!");
- //}
- //if (_billBomsetgrpRepository.Queryable().Any(o => o.IsDelete == 0 && o.IsStop == 0 && o.BomCode == billBomsetgrpEntity.BomCode))
- //{
- // throw BZSysExCore.ThrowFailException("投料信息已存在于其他跺型!");
- //}
- //billBomsetgrpEntity.ShortCode = GetShoreCodes();
- //if (billBomsetgrpEntity.ShortCode <= 0)
- //{
- // throw BZSysExCore.ThrowFailException("跺型短编码不正确!");
- //}
- //if ( billBomsetgrpEntity.ShortCode > 255)
- //{
- // throw BZSysExCore.ThrowFailException("跺型已满,请删除不用的跺型!");
- //}
- //if (_billBomsetgrpRepository.Queryable().Any(o => o.ShortCode == billBomsetgrpEntity.ShortCode))
- //{
- // //billBomsetgrpEntity.ShortCode = GetShoreCodes();
- // //if (_billBomsetgrpRepository.Queryable().Any(o => o.ShortCode == billBomsetgrpEntity.ShortCode))
- // //{
- // throw BZSysExCore.ThrowFailException("跺型内部编码已存在,请重新修改短编号!");
- // //}
- //}
- //var list = _billBomsetinfoRepository.Queryable().Where(o => infoMatCodes.Contains(o.MatCode)).ToList();
- //if (list.Any())
- //{
- // throw BZSysExCore.ThrowFailException(string.Join(",", list.Select(o => o.MatCode).ToArray()) + ",湿拉物料已经存在其他跺型中!");
- //}
- _billBomsetgrpRepository.UseTranAction(() =>
- {
- var id = IdFactory.NewId();
- billBomsetgrpEntity.Id = id;
- billBomsetgrpEntity.HWCountQty = billBomsetinfos.Count(o => o.IsEmpty == 0);
- billBomsetgrpEntity.AddWho = loginUser.UserNo;
- billBomsetgrpEntity.EditWho = loginUser.UserNo;
- billBomsetgrpEntity.AddTime = DateTime.Now;
- billBomsetgrpEntity.EditTime = DateTime.Now;
- billBomsetgrpEntity.BomCode = String.Join("|", billBomsetinfos.Where(o => !string.IsNullOrEmpty(o.MatCode)).Select(o => o.MatCode).Distinct().ToArray());
- billBomsetgrpEntity.IsStop = 1;
- _billBomsetgrpRepository.Insert(billBomsetgrpEntity);
- billBomsetinfos.ToList().ForEach(o =>
- {
- o.Id = IdFactory.NewId();
- var xyno = Convert.ToInt32(o.XYNo);
- o.Row = Convert.ToInt32(Math.Ceiling(xyno / 5.0d));
- o.BomSetHdrId = id;
- if (o.IsEmpty == 0 || o.CategoryId < 99)
- {
- o.SpoolType = SpoolType.WS09.ToString();
- var matinfo = baseMatinfos.FirstOrDefault(c => c.MatCode == o.MatCode);
- if (matinfo != null)
- {
- o.MatId = matinfo.MatId;
- }
- }
- o.AddTime = DateTime.Now;
- o.EditTime = DateTime.Now;
- o.AddWho = loginUser.UserNo;
- o.EditWho = loginUser.UserNo;
- o.IsStop = 1;
- });
- _billBomsetinfoRepository.Insert(billBomsetinfos.ToList());
- });
- }
- else
- {
- var bomsetgrpId = Convert.ToInt64(keyValue);
- var entitys = _billBomsetgrpRepository.Queryable().Where(x => (x.Id == bomsetgrpId || x.Code == billBomsetgrpEntity.Code)).ToList();
- if (!entitys.Any())
- {
- throw BZSysExCore.ThrowFailException("跺型不存在!");
- }
- if (entitys.Any(o => o.Id != bomsetgrpId))
- {
- throw BZSysExCore.ThrowFailException("跺型编码已存在!");
- }
- //if (_billBomsetgrpRepository.Queryable().Any(o => o.Id != bomsetgrpId && o.ShortCode == billBomsetgrpEntity.ShortCode))
- //{
- // throw BZSysExCore.ThrowFailException("跺型内部编码已存在,请重新修改短编号!");
- //}
- //if (_billBomsetgrpRepository.Queryable().Any(o => o.Id != bomsetgrpId && o.IsDelete == 0 && o.IsStop == 0 && o.BomCode == billBomsetgrpEntity.BomCode))
- //{
- // throw BZSysExCore.ThrowFailException("投料信息已存在于其他跺型!");
- //}
- // var list = _billBomsetinfoRepository.Context.Queryable<BillBomsetinfo, BillBomsetgrp>((billBomsetinfo, billBomsetgrp) => new object[] {
- //JoinType.Left,billBomsetinfo.BomSetHdrId == billBomsetgrp.Id }).Where((billBomsetinfo, billBomsetgrp) => billBomsetgrp.IsDelete == 0
- //&& billBomsetgrp.IsStop == 0 && billBomsetinfo.BomSetHdrId != bomsetgrpId && infoMatCodes.Contains(billBomsetinfo.MatCode)).ToList();
- // if (list.Any())
- // {
- // throw BZSysExCore.ThrowFailException(string.Join(",", list.Select(o => o.MatCode).ToArray()) + ",湿拉物料已经存在其他跺型中!");
- // }
- _billBomsetgrpRepository.UseTranAction(() =>
- {
- billBomsetgrpEntity.Id = bomsetgrpId;
- //if (_billBomsetgrpRepository.Queryable().Any(x => x.Id != bomsetgrpId && (x.Code == billBomsetgrpEntity.Code || x.Name == billBomsetgrpEntity.Name) && x.IsStop == 0))
- //{
- // throw BZSysExCore.ThrowFailException("跺型已存在!");
- //}
- //billBomsetgrpEntity.Id = bomsetgrpId;
- billBomsetgrpEntity.HWCountQty = billBomsetinfos.Count(o => o.IsEmpty == 0);
- billBomsetgrpEntity.BomCode = String.Join("|", billBomsetinfos.Where(o => !string.IsNullOrEmpty(o.MatCode)).Select(o => o.MatCode).Distinct().ToArray());
- billBomsetgrpEntity.EditWho = loginUser.UserNo;
- billBomsetgrpEntity.EditTime = DateTime.Now;
- billBomsetgrpEntity.IsStop = 1;
- _billBomsetgrpRepository.UpdateEntity(billBomsetgrpEntity);
- _billBomsetinfoRepository.Deleteable().Where(it => it.BomSetHdrId == billBomsetgrpEntity.Id).ExecuteCommand();
- billBomsetinfos.ToList().ForEach(o =>
- {
- o.Id = IdFactory.NewId();
- var xyno = Convert.ToInt32(o.XYNo);
- o.Row = Convert.ToInt32(Math.Ceiling(xyno / 5.0d));
- o.BomSetHdrId = billBomsetgrpEntity.Id;
- if (o.IsEmpty == 0 || o.CategoryId < 99)
- {
- o.SpoolType = SpoolType.WS09.ToString();
- var matinfo = baseMatinfos.FirstOrDefault(c => c.MatCode == o.MatCode);
- if (matinfo != null)
- {
- o.MatId = matinfo.MatId;
- }
- }
- o.AddTime = DateTime.Now;
- o.EditTime = DateTime.Now;
- o.AddWho = loginUser.UserNo;
- o.EditWho = loginUser.UserNo;
- o.IsStop = 1;
- });
- _billBomsetinfoRepository.Insert(billBomsetinfos.ToList());
- });
- }
- }
- /// <summary>
- /// 保存排库信息
- /// </summary>
- /// <param name="loginUser"></param>
- /// <param name="keyValue"></param>
- /// <param name="billPaiKuEntity"></param>
- public void SavePK(LoginUserInfo loginUser, string keyValue, BillPaiKu billPaiKuEntity)
- {
- try
- {
- if (billPaiKuEntity.Percent != Math.Truncate(billPaiKuEntity.Percent) || billPaiKuEntity.Percent > 100)
- {
- throw BZSysExCore.ThrowFailException("占比只能传入整数,且必须小于100!");
- }
- if (billPaiKuEntity.BomsetgrpId <= 0)
- {
- throw BZSysExCore.ThrowFailException("垛型编码有误!");
- }
- if (billPaiKuEntity.WarehousId <= 0)
- {
- throw BZSysExCore.ThrowFailException("仓库id有误!");
- }
- var bomsetgrp = _billBomsetgrpRepository.AsQueryable().With(SqlWith.NoLock).First(x => x.Id == billPaiKuEntity.BomsetgrpId);
- if (bomsetgrp == null)
- {
- throw BZSysExCore.ThrowFailException($"未找到对应垛型{billPaiKuEntity.BomsetgrpId}!");
- }
- var warehouse = _billBaseWarehouse.AsQueryable().With(SqlWith.NoLock).First(x => x.Id == billPaiKuEntity.WarehousId);
- if (warehouse == null)
- {
- throw BZSysExCore.ThrowFailException($"未找到对应仓库{billPaiKuEntity.WarehousId}!");
- }
- if (keyValue == "undefined") keyValue = "0";
- var paiKuId = Convert.ToInt64(keyValue);
- var paiKu = _billPaiKurepository.GetFirst(x => x.Id == paiKuId);
- if (paiKu != null) //更新
- {
- //判断此垛型排库占比总数是否超过100
- var percent = _billPaiKurepository.GetList(x => x.BomsetgrpId == bomsetgrp.Id && x.Id != paiKu.Id).Sum(x => x.Percent);
- if ((percent + billPaiKuEntity.Percent) > 100)
- {
- throw BZSysExCore.ThrowFailException($"{bomsetgrp.Name}超过最大占比,除当前编辑信息外总比重为{percent},请重新调整!");
- }
- paiKu.BomsetgrpId = bomsetgrp.Id;
- paiKu.BomsetgrpName = bomsetgrp.Name;
- paiKu.WarehousId = warehouse.Id;
- paiKu.WarehouseCode = warehouse.Code;
- paiKu.Percent = billPaiKuEntity.Percent;
- _billPaiKurepository.Update(paiKu);
- }
- else //新增
- {
- //判断此垛型排库占比总数是否超过100
- var percent = _billPaiKurepository.GetList(x => x.BomsetgrpId == bomsetgrp.Id).Sum(x => x.Percent);
- if ((percent + billPaiKuEntity.Percent) > 100)
- {
- throw BZSysExCore.ThrowFailException($"{bomsetgrp.Name}超过最大占比,请重新调整!");
- }
- BillPaiKu item = new BillPaiKu()
- {
- BomsetgrpId = bomsetgrp.Id,
- BomsetgrpName = bomsetgrp.Name,
- WarehousId = warehouse.Id,
- WarehouseCode = warehouse.Code,
- Percent = billPaiKuEntity.Percent
- };
- _billPaiKurepository.Insert(item);
- }
- }
- catch (Exception ex)
- {
- throw BZSysExCore.ThrowFailException(ex.Message);
- }
- }
- public void Save(LoginUserInfo loginUser, string keyValue, BillBomsetgrp billBomsetgrpEntity, IList<BillBomsetinfo> billBomsetinfos)
- {
- if (string.IsNullOrWhiteSpace(billBomsetgrpEntity.Code))
- {
- throw BZSysExCore.ThrowFailException("跺型编码不能为空!");
- }
- if (string.IsNullOrWhiteSpace(billBomsetgrpEntity.ProCode))
- {
- throw BZSysExCore.ThrowFailException("投料信息不能为空!");
- }
- if (billBomsetinfos == null || !billBomsetinfos.Any())
- {
- throw BZSysExCore.ThrowFailException("请选择跺型工字轮编号!");
- }
- if (billBomsetgrpEntity.ShortCode <= 0)
- {
- throw BZSysExCore.ThrowFailException("跺型短编码不正确!");
- }
- var infoMatCodes = billBomsetinfos.Select(o => o.MatCode).Distinct().ToList();
- // var duplicates = infoMatCodes.GroupBy(x => x).Where(g => g.Count() > 1).ToDictionary(x => x.Key, x => x.Count());
- //var hasDuplicates = infoMatCodes.GroupBy(x => x).Any(g => g.Count() > 1);
- var duplicates = infoMatCodes.GroupBy(x => x).Where(g => g.Count() > 1).Select(x => x.Key).ToList();
- if (duplicates != null && duplicates.Any())
- {
- throw BZSysExCore.ThrowFailException(string.Join(",", duplicates) + ",湿拉物料有重复!");
- }
- var procodelists = _billBominfoRepository.Queryable().Where(o => o.IsDelete == 0 && o.IsStop == 0 && billBomsetgrpEntity.ProCode == o.ProCode).ToList();
- if (!procodelists.Any())
- {
- throw BZSysExCore.ThrowFailException("投料信息不存在!");
- }
- //在Bill_BomInfo 中MatCode不存在2个ProCode中
- var baseMatinfos = _billBominfoRepository.Queryable().Where(o => o.IsDelete == 0 && o.IsStop == 0 && infoMatCodes.Contains(o.MatCode)).ToList();
- //foreach (var item in infoMatCodes)
- //{
- // if (baseMatinfos.Where(o => o.MatCode == item).Select(o => o.ProCode).Distinct().Count() > 1)
- // {
- // throw BZSysExCore.ThrowFailException("湿拉物料存在于多个投料大类中!");
- // }
- //}
- //if (!_matinforepository.Queryable().Any(o => o.Code == billBomsetgrpEntity.ProMaterCode))
- //{
- // throw BZSysExCore.ThrowFailException("产出物料编码不存在!");
- //}
- //billBomsetgrpEntity.BomCode = baseMatinfos.First().ProCode;
- //var bomProMatCodelists = _billBominfoRepository.Queryable().Where(o => o.ProCode == billBomsetgrpEntity.BomCode).Select(o => o.ProMatCode).Distinct().ToList();
- //billBomsetgrpEntity.ProMaterCode = string.Join(',', bomProMatCodelists);
- var first = billBomsetinfos.FirstOrDefault();
- for (int i = 1; i <= billBomsetgrpEntity.TotalQty; i++)
- {
- var item = billBomsetinfos.FirstOrDefault(o => o.XYNo == i.ToString());
- if (item == null)
- {
- billBomsetinfos.Add(new BillBomsetinfo
- {
- BomSetHdrId = first.BomSetHdrId,
- CategoryId = 99,
- XYNo = i.ToString(),
- IsEmpty = 1,
- IsStop = 1,
- });
- }
- }
- if (keyValue.IsEmpty() || keyValue == "undefined")
- {
- var mat = _billBomsetgrpRepository.GetSingle(p => p.Code == billBomsetgrpEntity.Code);
- if (mat != null)
- {
- throw BZSysExCore.ThrowFailException("跺型编码已存在!");
- }
- //if (_billBomsetgrpRepository.Queryable().Any(o => o.ShortCode == billBomsetgrpEntity.ShortCode))
- //{
- // throw BZSysExCore.ThrowFailException("跺型内部编码已存在,请重新修改短编号!");
- //}
- //if (_billBomsetgrpRepository.Queryable().Any(o => o.IsDelete == 0 && o.IsStop == 0 && o.BomCode == billBomsetgrpEntity.BomCode))
- //{
- // throw BZSysExCore.ThrowFailException("投料信息已存在于其他跺型!");
- //}
- //billBomsetgrpEntity.ShortCode = GetShoreCodes();
- //if (billBomsetgrpEntity.ShortCode > 255)
- //{
- // throw BZSysExCore.ThrowFailException("跺型已满,请删除不用的跺型!");
- //}
- //if (_billBomsetgrpRepository.Queryable().Any(o => o.ShortCode == billBomsetgrpEntity.ShortCode))
- //{
- // billBomsetgrpEntity.ShortCode = GetShoreCodes();
- // if (_billBomsetgrpRepository.Queryable().Any(o => o.ShortCode == billBomsetgrpEntity.ShortCode))
- // {
- // throw BZSysExCore.ThrowFailException("跺型内部编码已存在,请重新提交跺型!");
- // }
- //}
- //var list = _billBomsetinfoRepository.Context.Queryable<BillBomsetinfo, BillBomsetgrp>((billBomsetinfo, billBomsetgrp) => new object[] {
- //JoinType.Left,billBomsetinfo.BomSetHdrId == billBomsetgrp.Id }).Where((billBomsetinfo, billBomsetgrp) => billBomsetgrp.IsDelete == 0 && billBomsetgrp.IsStop == 0 && infoMatCodes.Contains(billBomsetinfo.MatCode)).ToList();
- //if (list.Any())
- //{
- // throw BZSysExCore.ThrowFailException(string.Join(",", list.Select(o => o.MatCode).Distinct().ToArray()) + ",湿拉物料已经存在其他跺型中!");
- //}
- _billBomsetgrpRepository.UseTranAction(() =>
- {
- var id = IdFactory.NewId();
- billBomsetgrpEntity.HWCountQty = billBomsetinfos.Count(o => o.CategoryId < 99);
- billBomsetgrpEntity.Id = id;
- billBomsetgrpEntity.AddWho = loginUser.UserNo;
- billBomsetgrpEntity.EditWho = loginUser.UserNo;
- billBomsetgrpEntity.AddTime = DateTime.Now;
- billBomsetgrpEntity.EditTime = DateTime.Now;
- billBomsetgrpEntity.IsStop = 1;
- billBomsetgrpEntity.BomCode = String.Join("|", billBomsetinfos.Where(o => !string.IsNullOrEmpty(o.MatCode)).Select(o => o.MatCode).Distinct().ToArray());
- _billBomsetgrpRepository.Insert(billBomsetgrpEntity);
- //_billBomsetinfoRepository.Deleteable().Where(it => it.BomSetHdrId == billBomsetgrpEntity.Id).ExecuteCommand();
- billBomsetinfos.ToList().ForEach(o =>
- {
- o.Id = IdFactory.NewId();
- var xyno = Convert.ToInt32(o.XYNo);
- o.Row = Convert.ToInt32(Math.Ceiling(xyno / 5.0d));
- o.BomSetHdrId = id;
- if (o.CategoryId < 99)
- {
- var matinfo = baseMatinfos.FirstOrDefault(c => c.MatCode == o.MatCode);
- if (matinfo != null)
- {
- o.MatId = matinfo.MatId;
- }
- }
- o.AddTime = DateTime.Now;
- o.EditTime = DateTime.Now;
- o.AddWho = loginUser.UserNo;
- o.EditWho = loginUser.UserNo;
- //o.Row = 0;
- o.IsStop = 1;
- });
- _billBomsetinfoRepository.Insert(billBomsetinfos.ToList());
- });
- }
- else
- {
- var bomsetgrpId = Convert.ToInt64(keyValue);
- var entitys = _billBomsetgrpRepository.Queryable().Where(x => x.Id == bomsetgrpId || x.Code == billBomsetgrpEntity.Code).ToList();
- if (!entitys.Any())
- {
- throw BZSysExCore.ThrowFailException("跺型不存在!");
- }
- if (entitys.Any(o => o.Id != bomsetgrpId))
- {
- throw BZSysExCore.ThrowFailException("跺型编码已存在!");
- }
- //if (_billBomsetgrpRepository.Queryable().Any(o => o.Id != bomsetgrpId && o.ShortCode == billBomsetgrpEntity.ShortCode))
- //{
- // throw BZSysExCore.ThrowFailException("跺型内部编码已存在,请重新修改短编号!");
- //}
- //if (_billBomsetgrpRepository.Queryable().Any(o => o.Id != bomsetgrpId && o.IsDelete == 0 && o.IsStop == 0 && o.BomCode == billBomsetgrpEntity.BomCode))
- //{
- // throw BZSysExCore.ThrowFailException("投料信息已存在于其他跺型!");
- //}
- //var list = _billBomsetinfoRepository.Context.Queryable<BillBomsetinfo, BillBomsetgrp>((billBomsetinfo, billBomsetgrp) => new object[] {
- //JoinType.Left,billBomsetinfo.BomSetHdrId == billBomsetgrp.Id }).Where((billBomsetinfo, billBomsetgrp) => billBomsetgrp.IsDelete == 0
- //&& billBomsetgrp.IsStop == 0 && billBomsetinfo.BomSetHdrId != bomsetgrpId && infoMatCodes.Contains(billBomsetinfo.MatCode)).ToList();
- //if (list.Any())
- //{
- // throw BZSysExCore.ThrowFailException(string.Join(",", list.Select(o => o.MatCode).Distinct().ToArray()) + ",湿拉物料已经存在其他跺型中!");
- //}
- _billBomsetgrpRepository.UseTranAction(() =>
- {
- billBomsetgrpEntity.Id = bomsetgrpId;
- //billBomsetgrpEntity.ShortCode = entitys.First().ShortCode;
- billBomsetgrpEntity.HWCountQty = billBomsetinfos.Count(o => o.CategoryId < 99);
- billBomsetgrpEntity.EditWho = loginUser.UserNo;
- billBomsetgrpEntity.EditTime = DateTime.Now;
- billBomsetgrpEntity.IsStop = 1;
- billBomsetgrpEntity.BomCode = String.Join("|", billBomsetinfos.Where(o => !string.IsNullOrEmpty(o.MatCode)).Select(o => o.MatCode).Distinct().ToArray());
- _billBomsetgrpRepository.UpdateEntity(billBomsetgrpEntity);
- _billBomsetinfoRepository.Deleteable().Where(it => it.BomSetHdrId == billBomsetgrpEntity.Id).ExecuteCommand();
- billBomsetinfos.ToList().ForEach(o =>
- {
- o.Id = IdFactory.NewId();
- var xyno = Convert.ToInt32(o.XYNo);
- o.Row = Convert.ToInt32(Math.Ceiling(xyno / 5.0d));
- o.BomSetHdrId = billBomsetgrpEntity.Id;
- if (o.CategoryId < 99)
- {
- var matinfo = baseMatinfos.FirstOrDefault(c => c.MatCode == o.MatCode);
- if (matinfo != null)
- {
- o.MatId = matinfo.MatId;
- }
- }
- o.AddTime = DateTime.Now;
- o.EditTime = DateTime.Now;
- o.AddWho = loginUser.UserNo;
- o.EditWho = loginUser.UserNo;
- //o.Row = 0;
- o.IsStop = 1;
- });
- _billBomsetinfoRepository.Insert(billBomsetinfos.ToList());
- });
- }
- }
- public void SaveException(LoginUserInfo loginUser, string keyValue, BillBomsetgrp billBomsetgrpEntity, IList<BillBomsetinfo> billBomsetinfos)
- {
- if (string.IsNullOrWhiteSpace(billBomsetgrpEntity.Code))
- {
- throw BZSysExCore.ThrowFailException("跺型编码不能为空!");
- }
- if (!billBomsetinfos.Any())
- {
- throw BZSysExCore.ThrowFailException("请选择工字轮!");
- }
- if (billBomsetinfos == null || !billBomsetinfos.Any())
- {
- throw BZSysExCore.ThrowFailException("请选择跺型工字轮编号!");
- }
- var first = billBomsetinfos.FirstOrDefault();
- for (int i = 1; i <= billBomsetgrpEntity.TotalQty; i++)
- {
- var item = billBomsetinfos.FirstOrDefault(o => o.XYNo == i.ToString());
- if (item == null)
- {
- billBomsetinfos.Add(new BillBomsetinfo
- {
- BomSetHdrId = first.BomSetHdrId,
- CategoryId = 99,
- XYNo = i.ToString(),
- IsEmpty = 1,
- IsStop = 1,
- });
- }
- }
- if (keyValue.IsEmpty() || keyValue == "undefined")
- {
- var mat = _billBomsetgrpRepository.GetSingle(p => p.Code == billBomsetgrpEntity.Code);
- if (mat != null)
- {
- throw BZSysExCore.ThrowFailException("跺型编码已存在!");
- }
- //billBomsetgrpEntity.ShortCode = GetShoreCodes();
- //if (billBomsetgrpEntity.ShortCode > 255)
- //{
- // throw BZSysExCore.ThrowFailException("跺型已满,请删除不用的跺型!");
- //}
- //if (_billBomsetgrpRepository.Queryable().Any(o => o.ShortCode == billBomsetgrpEntity.ShortCode))
- //{
- // billBomsetgrpEntity.ShortCode = GetShoreCodes();
- // if (_billBomsetgrpRepository.Queryable().Any(o => o.ShortCode == billBomsetgrpEntity.ShortCode))
- // {
- // throw BZSysExCore.ThrowFailException("跺型内部编码已存在,请重新提交跺型!");
- // }
- //}
- _billBomsetgrpRepository.UseTranAction(() =>
- {
- var id = IdFactory.NewId();
- billBomsetgrpEntity.HWCountQty = billBomsetinfos.Count(o => o.CategoryId < 99);
- billBomsetgrpEntity.Id = id;
- billBomsetgrpEntity.AddWho = loginUser.UserNo;
- billBomsetgrpEntity.EditWho = loginUser.UserNo;
- billBomsetgrpEntity.AddTime = DateTime.Now;
- billBomsetgrpEntity.EditTime = DateTime.Now;
- billBomsetgrpEntity.IsStop = 1;
- _billBomsetgrpRepository.Insert(billBomsetgrpEntity);
- //_billBomsetinfoRepository.Deleteable().Where(it => it.BomSetHdrId == billBomsetgrpEntity.Id).ExecuteCommand();
- billBomsetinfos.ToList().ForEach(o =>
- {
- o.Id = IdFactory.NewId();
- var xyno = Convert.ToInt32(o.XYNo);
- //if (billBomsetgrpEntity.StampChildType == 4)
- //{
- o.Row = Convert.ToInt32(Math.Ceiling(xyno / 5.0d));
- //}
- o.BomSetHdrId = id;
- o.AddTime = DateTime.Now;
- o.EditTime = DateTime.Now;
- o.AddWho = loginUser.UserNo;
- o.EditWho = loginUser.UserNo;
- o.IsStop = 1;
- });
- _billBomsetinfoRepository.Insert(billBomsetinfos.ToList());
- });
- }
- else
- {
- var bomsetgrpId = Convert.ToInt64(keyValue);
- var entitys = _billBomsetgrpRepository.Queryable().Where(x => x.Id == bomsetgrpId || x.Code == billBomsetgrpEntity.Code).ToList();
- if (!entitys.Any())
- {
- throw BZSysExCore.ThrowFailException("跺型编码不存在!");
- }
- if (entitys.Any(o => o.Id != bomsetgrpId))
- {
- throw BZSysExCore.ThrowFailException("跺型编码已存在!");
- }
- _billBomsetgrpRepository.UseTranAction(() =>
- {
- billBomsetgrpEntity.Id = bomsetgrpId;
- billBomsetgrpEntity.ShortCode = entitys.First().ShortCode;
- billBomsetgrpEntity.HWCountQty = billBomsetinfos.Count(o => o.CategoryId < 99);
- billBomsetgrpEntity.EditWho = loginUser.UserNo;
- billBomsetgrpEntity.EditTime = DateTime.Now;
- billBomsetgrpEntity.IsStop = 1;
- _billBomsetgrpRepository.UpdateEntity(billBomsetgrpEntity);
- _billBomsetinfoRepository.Deleteable().Where(it => it.BomSetHdrId == billBomsetgrpEntity.Id).ExecuteCommand();
- billBomsetinfos.ToList().ForEach(o =>
- {
- o.Id = IdFactory.NewId();
- var xyno = Convert.ToInt32(o.XYNo);
- //if (billBomsetgrpEntity.StampChildType == 4)
- //{
- o.Row = Convert.ToInt32(Math.Ceiling(xyno / 5.0d));
- //}
- o.BomSetHdrId = billBomsetgrpEntity.Id;
- o.AddTime = DateTime.Now;
- o.EditTime = DateTime.Now;
- o.AddWho = loginUser.UserNo;
- o.EditWho = loginUser.UserNo;
- o.IsStop = 1;
- });
- _billBomsetinfoRepository.Insert(billBomsetinfos.ToList());
- });
- }
- }
- public int GetShoreCodes()
- {
- var lists = _billBomsetgrpRepository.Queryable().OrderBy(o => o.ShortCode).Select(o => o.ShortCode).ToArray();
- if (!lists.Any())
- {
- //没有数据的时候返回1.
- return 1;
- }
- else
- {
- var numberArrs = lists.Adapt<List<int>>();
- var numbers = FindDisappearedNumbers(numberArrs);
- if (numbers.Any())
- {
- //找到缺失的数字
- return numbers[0];
- }
- else
- {
- //没有缺失的数字,则返回最大值加1.
- var maxShortCode = _billBomsetgrpRepository.Queryable().Select(o => SqlFunc.AggregateMax(o.ShortCode)).Single();
- return ++maxShortCode;
- }
- }
- }
- public IList<int> FindDisappearedNumbers(List<int> nums)
- {
- var res = new List<int>();
- if (nums[nums.Count - 1] != nums.Count)
- {
- var len = nums[nums.Count - 1] - nums.Count;
- for (int i = 0; i < len; i++)
- {
- nums.Insert(i, 1);
- }
- }
- var numsarr = nums.ToArray();
- for (int i = 0; i < numsarr.Length; i++)
- {
- //记录索引,位置为i处的值的绝对值减1
- //(因为数值范围从1..n所以要减1)作为临时索引位
- int index = Math.Abs(numsarr[i]) - 1;
- if (index < 0)
- {
- index = 0;
- }
- //如果此处的值大于0,那么将其变为负数,
- //没有变为负数的值即为不存在于数组中的数字,
- //直接变为负数不至于使其值丢失,只需要取绝对值即可恢复原值
- if (index < numsarr.Length && numsarr[index] > 0)
- {
- numsarr[index] = -numsarr[index];
- }
- }
- //所有值大于0的即为“迷失的数字”
- for (int i = 0; i < numsarr.Length; i++)
- {
- if (numsarr[i] > 0)
- {
- res.Add(i + 1);
- }
- }
- return res;
- }
- // Function to return the missing element
- public static int findMissing(int[] arr, int n)
- {
- int l = 0, h = n - 1;
- int mid;
- while (h > l)
- {
- mid = l + (h - l) / 2;
- // Check if middle element is consistent
- if (arr[mid] - mid == arr[0])
- {
- // No inconsistency till middle elements
- // When missing element is just after
- // the middle element
- if (arr[mid + 1] - arr[mid] > 1)
- return arr[mid] + 1;
- else
- {
- // Move right
- l = mid + 1;
- }
- }
- else
- {
- // Inconsistency found
- // When missing element is just before
- // the middle element
- if (arr[mid] - arr[mid - 1] > 1)
- return arr[mid] - 1;
- else
- {
- // Move left
- h = mid - 1;
- }
- }
- }
- // No missing element found
- return -1;
- }
- public void DeletePK(long id)
- {
- try
- {
- _billPaiKurepository.Deleteable().Where(o => o.Id == id).ExecuteCommand();
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- public void Delete(long id)
- {
- var entity = _billBomsetgrpRepository.GetSingle(o => o.Id == id);
- if (entity == null)
- {
- throw BZSysExCore.ThrowFailException("跺型不存在!");
- }
- _billBomsetgrpRepository.Deleteable().Where(it => it.Id == entity.Id).ExecuteCommand();
- _billBomsetinfoRepository.Deleteable().Where(it => it.BomSetHdrId == entity.Id).ExecuteCommand();
- }
- public void Deletes(string[] ids, string userId)
- {
- if (ids == null || ids.Length == 0)
- {
- throw BZSysExCore.ThrowFailException("跺型Id不能为空!");
- }
- var list = _billBomsetgrpRepository.Queryable().Where(o => ids.Contains(o.Id.ToString())).ToList();
- if (!list.Any())
- {
- throw new ArgumentException("没有选择跺型数据!");
- }
- _billBomsetgrpRepository.UseTranAction(() =>
- {
- foreach (var item in list)
- {
- _billBomsetgrpRepository.Deleteable().Where(it => it.Id == item.Id).ExecuteCommand();
- _billBomsetinfoRepository.Deleteable().Where(it => it.BomSetHdrId == item.Id).ExecuteCommand();
- }
- });
- //list.ForEach(o =>
- //{
- // o.IsDelete = 1;
- // o.EditWho = userId;
- // o.EditTime = DateTime.Now;
- //});
- //var result = _billBomsetgrpRepository.UpdateRange(list.ToArray());
- }
- public void DeleteByCode(string code)
- {
- var entity = _billBomsetgrpRepository.GetSingle(o => o.Code == code);
- if (entity == null)
- {
- throw BZSysExCore.ThrowFailException("跺型不存在!");
- }
- _billBomsetgrpRepository.Deleteable().Where(it => it.Id == entity.Id).ExecuteCommand();
- _billBomsetinfoRepository.Deleteable().Where(it => it.BomSetHdrId == entity.Id).ExecuteCommand();
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="Ids">跺型编号</param>
- /// <param name="locationStop">是否</param>
- /// <param name="userId">操作人</param>
- /// <returns></returns>
- /// <exception cref="ArgumentException"></exception>
- public void ChangeEnableds(List<string> Ids, LocationStop locationStop, string userId)
- {
- if (Ids == null || !Ids.Any())
- {
- throw new ArgumentException("没有选择跺型数据!");
- }
- var billBomsetgrplist = _billBomsetgrpRepository.Queryable().Where(o => Ids.Contains(o.Id.ToString())).ToList();
- if (!billBomsetgrplist.Any())
- {
- throw new ArgumentException("没有选择跺型数据!");
- }
- var now = DateTime.Now;
- billBomsetgrplist.ForEach(o =>
- {
- o.IsStop = (int)locationStop;
- o.EditWho = userId;
- o.EditTime = now;
- });
- var infos = _billBomsetinfoRepository.Queryable().Where(it => Ids.Contains(it.BomSetHdrId.ToString())).ToList();
- if (!infos.Any())
- {
- throw new ArgumentException("没有选择跺型数据!");
- }
- //启用
- if (locationStop == LocationStop.LocationInvoke)
- {
- var infoMatCodes = infos.Select(o => o.MatCode).Distinct().ToList();
- foreach (var item in billBomsetgrplist)
- {
- if (_billBomsetgrpRepository.Queryable().Any(o => o.Id != item.Id && o.IsDelete == 0 && o.IsStop == 0 && o.BomCode == item.BomCode))
- {
- throw BZSysExCore.ThrowFailException("投料信息已存在于其他跺型!");
- }
- var list = _billBomsetinfoRepository.Context.Queryable<BillBomsetinfo, BillBomsetgrp>((billBomsetinfo, billBomsetgrp) => new object[] {
- JoinType.Left,billBomsetinfo.BomSetHdrId == billBomsetgrp.Id }).Where((billBomsetinfo, billBomsetgrp) => billBomsetgrp.IsDelete == 0
- && billBomsetgrp.IsStop == 0 && billBomsetinfo.BomSetHdrId != item.Id && infoMatCodes.Contains(billBomsetinfo.MatCode)).ToList();
- if (list.Any())
- {
- throw BZSysExCore.ThrowFailException(string.Join(",", list.Select(o => o.MatCode).ToArray()) + ",湿拉物料已经存在其他跺型中!");
- }
- }
- }
- infos.ForEach(o =>
- {
- o.IsStop = (int)locationStop;
- o.EditWho = userId;
- o.EditTime = now;
- });
- // var result = _billBomsetgrpRepository.UpdateRange(list.ToArray());
- _billBomsetgrpRepository.UseTranAction(() =>
- {
- _billBomsetgrpRepository.UpdateRange(billBomsetgrplist.ToArray());
- _billBomsetinfoRepository.UpdateRange(infos.ToArray());
- });
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="typenum">1为09的跺型。</param>
- /// <returns></returns>
- public IEnumerable<dynamic> GetSelectCodeListByType(string typenum)
- {
- return typenum == "1"
- ? _billBomsetgrpRepository.Queryable().Where(o => o.IsStop == 0 && o.StampType == 1).ToList().Select(o => new { id = o.Code.ToString(), text = o.Name })
- : _billBomsetgrpRepository.Queryable().Where(o => o.IsStop == 0 && o.StampType != 1).ToList().Select(o => new { id = o.Code.ToString(), text = o.Name });
- }
- }
- }
|