public object PutFlowCode([FromBody] IEnumerable <FlowCode> details) { if (details == null || !details.Any()) { return(Result.GenError <Result>(Error.ParamError)); } if (details.Any(x => x.Id == 0)) { return(Result.GenError <Result>(Error.FlowCodeNotExist)); } var markedDateTime = DateTime.Now; foreach (var detail in details) { detail.MarkedDateTime = markedDateTime; detail.Remark = detail.Remark ?? ""; } if (details.Any(x => x.Code.IsNullOrEmpty())) { var ids = details.Select(x => x.Id); var cnt = FlowCodeHelper.Instance.GetCountByIds(ids); if (cnt != details.Count()) { return(Result.GenError <Result>(Error.FlowCodeNotExist)); } FlowCodeHelper.Enable(details); } else { if (details.GroupBy(x => x.Code).Any(y => y.Count() > 1)) { return(Result.GenError <Result>(Error.FlowCodeDuplicate)); } var sIds = details.SelectMany(x => x.StepIds).Distinct(); var cnt = FlowStepHelper.Instance.GetCountByIds(sIds); if (cnt != sIds.Count()) { return(Result.GenError <Result>(Error.FlowStepNotExist)); } var wId = details.FirstOrDefault()?.WorkshopId ?? 0; var sames = details.Select(x => x.Code); var ids = details.Select(x => x.Id); if (FlowCodeHelper.GetHaveSame(wId, sames, ids)) { return(Result.GenError <Result>(Error.FlowCodeIsExist)); } var olds = FlowCodeHelper.Instance.GetByIds <FlowCode>(ids); if (olds.Count() != details.Count()) { return(Result.GenError <Result>(Error.FlowCodeNotExist)); } FlowCodeHelper.Instance.Update(details); } return(Result.GenError <Result>(Error.Success)); }
public object GetFlowCode([FromQuery] int wId, bool menu, int qId, int cId, bool step) { if (step && qId != 0) { var data = FlowCodeHelper.GetDetail(wId, qId); var stepIds = data.SelectMany(x => x.StepIds).Distinct(); if (stepIds.Any()) { var steps = FlowStepHelper.GetDetails(stepIds).ToDictionary(x => x.Id); foreach (var d in data) { d.StepList.AddRange(d.StepIds.Where(stepId => steps.ContainsKey(stepId)).Select(stepId => new { steps[stepId].Id, steps[stepId].Name, steps[stepId].Category, steps[stepId].FormatId, })); } } return(new { errno = 0, errmsg = "成功", datas = data }); } var result = new DataResult(); if (menu) { result.datas.AddRange(FlowCodeHelper.GetMenu(wId, qId, cId)); } else { var data = FlowCodeHelper.GetDetail(wId, qId, cId); var stepIds = data.SelectMany(x => x.StepIds); if (stepIds.Any()) { var steps = FlowStepHelper.Instance.GetByIds <FlowStep>(stepIds).ToDictionary(x => x.Id); foreach (var d in data) { d.Steps = d.StepIds.Where(stepId => steps.ContainsKey(stepId)).Select(stepId => steps[stepId].Name).Join(); } } result.datas.AddRange(data); } if (qId != 0 && !result.datas.Any()) { result.errno = Error.FlowCodeNotExist; return(result); } return(result); }
public object PostFlowCode([FromBody] IEnumerable <FlowCode> details) { if (details == null || !details.Any()) { return(Result.GenError <Result>(Error.ParamError)); } if (details.Any(x => x.Code.IsNullOrEmpty())) { return(Result.GenError <Result>(Error.FlowCodeNotEmpty)); } if (details.GroupBy(x => x.Code).Any(y => y.Count() > 1)) { return(Result.GenError <Result>(Error.FlowCodeDuplicate)); } var sIds = details.SelectMany(x => x.StepIds).Distinct(); var cnt = FlowStepHelper.Instance.GetCountByIds(sIds); if (cnt != sIds.Count()) { return(Result.GenError <Result>(Error.FlowStepNotExist)); } var wId = details.FirstOrDefault()?.WorkshopId ?? 0; var sames = details.Select(x => x.Code); if (FlowCodeHelper.GetHaveSame(wId, sames)) { return(Result.GenError <Result>(Error.FlowCodeIsExist)); } var userId = Request.GetIdentityInformation(); var markedDateTime = DateTime.Now; foreach (var detail in details) { detail.CreateUserId = userId; detail.MarkedDateTime = markedDateTime; detail.Remark = detail.Remark ?? ""; } FlowCodeHelper.Instance.Add(details); return(Result.GenError <Result>(Error.Success)); }
public object PutProduction([FromBody] IEnumerable <ProductionDetail> details) { if (details == null || !details.Any()) { return(Result.GenError <Result>(Error.ParamError)); } if (details.Any(x => x.Id == 0)) { return(Result.GenError <Result>(Error.ProductionNotExist)); } if (details.Any(x => x.Name.IsNullOrEmpty())) { var ids = details.Select(x => x.Id); var cnt = ProductionHelper.Instance.GetCountByIds(ids); if (cnt != details.Count()) { return(Result.GenError <Result>(Error.ProductionNotExist)); } var markedDateTime = DateTime.Now; foreach (var detail in details) { detail.MarkedDateTime = markedDateTime; } ProductionHelper.Enable(details); } else { if (details.GroupBy(x => x.Name).Any(y => y.Count() > 1)) { return(Result.GenError <Result>(Error.ProductionDuplicate)); } if (details.Any(x => x.StepIds.Count != x.Rates.Count || x.StepIds.Count != x.Costs.Count)) { return(Result.GenError <Result>(Error.ProductionCapacityListError)); } var ids = details.Select(x => x.Id); var data = ProductionHelper.Instance.GetByIds <Production>(ids); if (data.Count() != details.Count()) { return(Result.GenError <Result>(Error.ProductionNotExist)); } var wId = details.FirstOrDefault()?.WorkshopId ?? 0; var userId = Request.GetIdentityInformation(); var markedDateTime = DateTime.Now; foreach (var detail in details) { detail.CreateUserId = userId; detail.MarkedDateTime = markedDateTime; detail.Remark = detail.Remark ?? ""; detail.FlowList = detail.Args?.Select(x => x.FlowId).Distinct().Join() ?? ""; foreach (var arg in detail.Args) { arg.WorkshopId = wId; arg.CreateUserId = userId; arg.MarkedDateTime = markedDateTime; arg.ProductionId = detail.Id; arg.Para = arg.Para ?? ""; arg.Other = arg.Other ?? ""; } } var newDetails = details.Where(x => ClassExtension.HaveChange(x, data.First(y => y.Id == x.Id))); if (newDetails.Any()) { var tIds = newDetails.Select(x => x.TypeId).Distinct(); var flowTypes = FlowTypeHelper.Instance.GetByIds <FlowType>(tIds).ToDictionary(x => x.Id); if (tIds.Count() != flowTypes.Count) { return(Result.GenError <Result>(Error.FlowTypeNotExist)); } var cIds = newDetails.Select(x => x.CapacityId).Distinct(); var cnt = CapacityHelper.Instance.GetCountByIds(cIds); if (cIds.Count() != cnt) { return(Result.GenError <Result>(Error.CapacityNotExist)); } var aTypeFlows = FlowCodeHelper.GetDetails(wId, null, tIds); var flowIds = newDetails.SelectMany(x => x.FlowIds).Distinct(); if (flowIds.Any(x => aTypeFlows.All(y => y.Id != x))) { return(Result.GenError <Result>(Error.FlowCodeNotExist)); } var typeFlows = aTypeFlows.Where(x => flowIds.Contains(x.Id)); var flowCodes = typeFlows.ToDictionary(x => x.Id); if (flowIds.Count() != flowCodes.Count) { return(Result.GenError <Result>(Error.FlowCodeNotExist)); } if (newDetails.Count(detail => { var fIds = detail.Args.Select(arg => arg.FlowId).Distinct(); return(fIds.Any(fId => { var mFcDic = detail.Args.Where(x => x.FlowId == fId).GroupBy(x => x.StepId).ToDictionary(y => y.Key, y => y.Count()); var fcDic = flowCodes[fId].StepIds.GroupBy(y => y).ToDictionary(y => y.Key, y => y.Count()); return detail.Args.Count(x => x.FlowId == fId) != flowCodes[fId].StepIds.Count || mFcDic.Any(x => x.Value != fcDic[x.Key]); })); }) > 0) { return(Result.GenError <Result>(Error.ProductionFlowCodeStepCountError)); } var sames = newDetails.Select(x => x.Name); if (ProductionHelper.GetHaveSame(wId, sames, ids)) { return(Result.GenError <Result>(Error.ProductionIsExist)); } var stepIds = newDetails.SelectMany(x => x.StepIds).Distinct(); if (stepIds.Any()) { var steps = FlowStepHelper.Instance.GetByIds <FlowStep>(stepIds).ToDictionary(x => x.Id); var formatIds = steps.Values.Select(x => x.FormatId).Distinct(); if (formatIds.Any()) { var formats = ArgsFormatHelper.Instance.GetByIds <ArgsFormat>(formatIds).ToDictionary(x => x.Id); if (newDetails.Any(x => x.Args.Any(arg => { if (steps.ContainsKey(arg.StepId) && steps[arg.StepId].FormatId != 0 && formats.ContainsKey(steps[arg.StepId].FormatId)) { var format = formats[steps[arg.StepId].FormatId]; return(ArgsFormatHelper.CheckPara(format, arg.Para)); } return(false); }))) { return(Result.GenError <Result>(Error.ProductionFlowCodeStepFormatError)); } } } ProductionHelper.Instance.Update(newDetails); } var args = ProductionArgHelper.GetMenus(ids, null); var argTmps = details.SelectMany(x => x.Args); var add = new List <ProductionArg>(); var up = new List <ProductionArg>(); var del = new List <int>(); add.AddRange(argTmps.Where(x => x.Id == 0)); up.AddRange(argTmps.Where(x => x.Id != 0).Where(x => argTmps.Any(y => ClassExtension.HaveChange(y, x)))); del.AddRange(args.Where(x => !argTmps.Any(y => y.Id == x.Id)).Select(x => x.Id)); if (add.Any()) { ProductionArgHelper.Instance.Add(add); } if (up.Any()) { ProductionArgHelper.Instance.Update <ProductionArg>(up); } if (del.Any()) { ProductionArgHelper.Instance.Delete(del); } } return(Result.GenError <Result>(Error.Success)); }