12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031 |
- using SqlSugar;
- using wms.sqlsugar.model.fj;
- using WMS.BZModels.Dto.FJ.BillBom;
- using WMS.BZModels;
- using WMS.Info;
- using WMS.BZSqlSugar;
- using Mapster;
- using FreeRedis;
- using Org.BouncyCastle.Crypto;
- using System.Collections.Generic;
- using WMS.BZModels.Models.FJ;
- using NPOI.SS.Formula.Functions;
- 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;
- public BillBomSetService(Repository<BillBomsetgrp> billBomsetgrpRepository,
- Repository<BillBomsetinfo> billBomsetinfoRepository,
- Repository<BillBominfo> billBominfoRepository,
- Repository<BaseMatinfo> matinforepository,
- Repository<BillPaiKu> billPaiKurepository)
- {
- _billBomsetgrpRepository = billBomsetgrpRepository;
- _billBomsetinfoRepository = billBomsetinfoRepository;
- _billBominfoRepository = billBominfoRepository;
- _matinforepository = matinforepository;
- _billPaiKurepository = billPaiKurepository;
- }
- public PagedInfo<BillBomsetgrpDto> GetPageList(Pagination pagination, BillBomsetgrpQueryDto billBomsetgrpQueryDto)
- {
- var list = GetQueryable(billBomsetgrpQueryDto)
- .ToPage<BillBomsetgrp, BillBomsetgrpDto>(pagination);
- return list;
- }
- public PagedInfo<BillPaiKuDto> GetPaiKuList(Pagination pagination, BillPaiKuQueryDto billPaiKuQueryDto)
- {
- //var list = GetQueryablePK(billPaiKuQueryDto)
- // .ToPage<BillPaiKu, BillPaiKuDto>(pagination);
- //return list;
- var predicate = Expressionable.Create<BillPaiKu, BillBomsetgrp>();
- predicate = predicate.AndIF(!string.IsNullOrEmpty(billPaiKuQueryDto?.KeyWord), (paiku, bomsetgrp) => paiku.WarehouseCode.Contains(billPaiKuQueryDto.KeyWord));
- //|| m.ProCode.Contains(billPaiKuQueryDto.KeyWord) || m.ProMaterCode.Contains(billPaiKuQueryDto.KeyWord) || m.ShortCode.ToString().Contains(billPaiKuQueryDto.KeyWord));
- predicate = predicate.AndIF(!string.IsNullOrEmpty(billPaiKuQueryDto?.WarehouseId.ToString()), (paiku, bomsetgrp) => paiku.WarehousId.ToString().Contains(billPaiKuQueryDto.WarehouseId.ToString()));
- predicate = predicate.AndIF(!string.IsNullOrEmpty(billPaiKuQueryDto?.BomsetgrpId.ToString()), (paiku, bomsetgrp) => paiku.BomsetgrpId.ToString().Contains(billPaiKuQueryDto.BomsetgrpId.ToString()));
- predicate = predicate.AndIF(!string.IsNullOrEmpty(billPaiKuQueryDto?.BomsetgrpName), (paiku, bomsetgrp) =>bomsetgrp.Code.Contains(billPaiKuQueryDto.BomsetgrpName));
- //predicate = predicate.AndIF(!string.IsNullOrEmpty(billPaiKuQueryDto?.ProMaterCode), m => m.ProMaterCode.Contains(billPaiKuQueryDto.ProMaterCode));
- //predicate = predicate.AndIF(!string.IsNullOrEmpty(billPaiKuQueryDto?.BomName), m => m.BomName.Contains(billPaiKuQueryDto.BomName));
- //predicate = predicate.AndIF(!string.IsNullOrEmpty(billPaiKuQueryDto?.ProCode), m => m.ProCode.Contains(billPaiKuQueryDto.ProCode));
- //predicate = predicate.AndIF(!string.IsNullOrEmpty(billPaiKuQueryDto?.StampType), m => m.StampType.Equals(billPaiKuQueryDto.StampType));
- //predicate = predicate.AndIF(!string.IsNullOrEmpty(billPaiKuQueryDto?.IsStop), m => m.IsStop.Equals(billPaiKuQueryDto.IsStop));
- //predicate = predicate.AndIF(!string.IsNullOrEmpty(billPaiKuQueryDto?.IsDelete), m => m.IsDelete.Equals(billPaiKuQueryDto.IsDelete));
- var list = _billPaiKurepository.Context.Queryable<BillPaiKu, BillBomsetgrp>((paiku, bomsetgrp) => new object[] { JoinType.Left, paiku.BomsetgrpId == bomsetgrp.Id,
- }).Where(predicate.ToExpression())
- .Select((paiku, bomsetgrp) => new BillPaiKuDto
- {
- BomsetgrpId = paiku.BomsetgrpId,
- BomsetgrpName = bomsetgrp.Code,
- WarehouseId = paiku.WarehousId,
- WarehouseCode = paiku.WarehouseCode,
- Percent = paiku.Percent
- }).MergeTable()
- .ToPage(pagination);
- return list;
- }
- //private ISugarQueryable<BillPaiKu> GetQueryablePK(BillPaiKuQueryDto billPaiKuQueryDto)
- //{
- // var predicate = Expressionable.Create<BillPaiKu,BillBomsetgrp,BaseWarehouse>();
- // predicate = predicate.AndIF(!string.IsNullOrEmpty(billPaiKuQueryDto?.KeyWord), (paiku, bomsetgrp, warehouse) => paiku.WarehouseCode.Contains(billPaiKuQueryDto.KeyWord));
- // //|| m.ProCode.Contains(billPaiKuQueryDto.KeyWord) || m.ProMaterCode.Contains(billPaiKuQueryDto.KeyWord) || m.ShortCode.ToString().Contains(billPaiKuQueryDto.KeyWord));
- //predicate = predicate.AndIF(!string.IsNullOrEmpty(billPaiKuQueryDto?.Code), m => m.Code.Contains(billPaiKuQueryDto.Code));
- //predicate = predicate.AndIF(!string.IsNullOrEmpty(billPaiKuQueryDto?.Name), m => m.Name.Contains(billPaiKuQueryDto.Name));
- // //predicate = predicate.AndIF(!string.IsNullOrEmpty(billPaiKuQueryDto?.ShortCode), m => m.ShortCode.ToString().Contains(billPaiKuQueryDto.ShortCode));
- // //predicate = predicate.AndIF(!string.IsNullOrEmpty(billPaiKuQueryDto?.ProMaterCode), m => m.ProMaterCode.Contains(billPaiKuQueryDto.ProMaterCode));
- // //predicate = predicate.AndIF(!string.IsNullOrEmpty(billPaiKuQueryDto?.BomName), m => m.BomName.Contains(billPaiKuQueryDto.BomName));
- // //predicate = predicate.AndIF(!string.IsNullOrEmpty(billPaiKuQueryDto?.ProCode), m => m.ProCode.Contains(billPaiKuQueryDto.ProCode));
- // //predicate = predicate.AndIF(!string.IsNullOrEmpty(billPaiKuQueryDto?.StampType), m => m.StampType.Equals(billPaiKuQueryDto.StampType));
- // //predicate = predicate.AndIF(!string.IsNullOrEmpty(billPaiKuQueryDto?.IsStop), m => m.IsStop.Equals(billPaiKuQueryDto.IsStop));
- // //predicate = predicate.AndIF(!string.IsNullOrEmpty(billPaiKuQueryDto?.IsDelete), m => m.IsDelete.Equals(billPaiKuQueryDto.IsDelete));
- // var sugarQueryable = _billPaiKurepository.Context.Queryable<BillPaiKu, BillBomsetgrp, BaseWarehouse>((paiku, bomsetgrp, warehouse) => new object[] { JoinType.Left, paiku.BomsetgrpId == bomsetgrp.Id, paiku.WarehousId == warehouse.Id }).Where(predicate.ToExpression())
- // .Select((paiku, bomsetgrp, warehous) => new BillPaiKuQueryDto
- // {
- // BomsetgrpId = paiku.BomsetgrpId,
- // BomsetgrpName = bomsetgrp.Code,
- // WarehouseId = paiku.WarehousId,
- // WarehouseCode = paiku.WarehouseCode
- // }).MergeTable()
- // .ToList();
- // //_billPaiKurepository.Queryable().Where(predicate.ToExpression());
- // return sugarQueryable;
- //}
- 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());
- });
- }
- }
- public void SavePK(LoginUserInfo loginUser, string keyValue, BillPaiKu billPaiKuEntity)
- {
- try
- {
- if (billPaiKuEntity.BomsetgrpId <= 0)
- {
- throw BZSysExCore.ThrowFailException("垛型编码有误!");
- }
- if (billPaiKuEntity.WarehousId <= 0)
- {
- throw BZSysExCore.ThrowFailException("仓库id有误!");
- }
- var code = _billPaiKurepository.Context.Queryable<BaseWarehouse>().Where(x => x.Id == billPaiKuEntity.WarehousId);
- if (code == null)
- {
- throw BZSysExCore.ThrowFailException($"未找到对应仓库{billPaiKuEntity.WarehousId}!");
- }
- var percent = _billPaiKurepository.Context.Queryable<BillPaiKu>().Where(x => x.BomsetgrpId == billPaiKuEntity.BomsetgrpId && x.WarehouseCode == billPaiKuEntity.WarehouseCode).Sum(x => x.Percent);
- if (Math.Ceiling(percent) >= 100)
- {
- throw BZSysExCore.ThrowFailException($"{billPaiKuEntity.WarehouseCode}超过最大占比,请重新调整!");
- }
- BillPaiKu item = new BillPaiKu()
- {
- BomsetgrpId = billPaiKuEntity.BomsetgrpId,
- WarehousId = billPaiKuEntity.WarehousId,
- WarehouseCode = billPaiKuEntity.WarehouseCode,
- 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 });
- }
- }
- }
|