Exemple #1
0
        public object PutCapacity([FromBody] IEnumerable <Capacity> details)
        {
            if (details == null || !details.Any())
            {
                return(Result.GenError <Result>(Error.ParamError));
            }
            var markedDateTime = DateTime.Now;

            foreach (var detail in details)
            {
                detail.MarkedDateTime = markedDateTime;
                detail.Remark         = detail.Remark ?? "";
            }
            if (details.Any(x => x.Name.IsNullOrEmpty()))
            {
                var ids = details.Select(x => x.Id);
                var cnt = CapacityHelper.Instance.GetCountByIds(ids);
                if (cnt != details.Count())
                {
                    return(Result.GenError <Result>(Error.CapacityNotExist));
                }
                CapacityHelper.Enable(details);
            }
            else
            {
                if (details.GroupBy(x => x.Name).Any(y => y.Count() > 1))
                {
                    return(Result.GenError <Result>(Error.CapacityDuplicate));
                }
                var wId  = details.FirstOrDefault()?.WorkshopId ?? 0;
                var cIds = details.Select(x => x.TypeId).Distinct();
                if (cIds.Any(x => x == 0))
                {
                    return(Result.GenError <Result>(Error.FlowTypeNotExist));
                }
                var sames = details.Select(x => x.Name);
                var ids   = details.Select(x => x.Id);
                if (CapacityHelper.GetHaveSame(wId, cIds, sames, ids))
                {
                    return(Result.GenError <Result>(Error.CapacityIsExist));
                }
                var cnt = FlowTypeHelper.Instance.GetCountByIds(cIds);
                if (cnt != details.Count())
                {
                    return(Result.GenError <Result>(Error.FlowTypeNotExist));
                }
                if (details.Any(x => x.StepIds.Count != x.StepVs.Count))
                {
                    return(Result.GenError <Result>(Error.CapacityListError));
                }
                cnt = CapacityHelper.Instance.GetCountByIds(ids);
                if (cnt != details.Count())
                {
                    return(Result.GenError <Result>(Error.CapacityNotExist));
                }
                CapacityHelper.Instance.Update(details);
            }
            return(Result.GenError <Result>(Error.Success));
        }
Exemple #2
0
        public object PostCapacity([FromBody] IEnumerable <Capacity> details)
        {
            if (details == null || !details.Any())
            {
                return(Result.GenError <Result>(Error.ParamError));
            }
            if (details.Any(x => x.Name.IsNullOrEmpty()))
            {
                return(Result.GenError <Result>(Error.CapacityNotEmpty));
            }
            if (details.GroupBy(x => x.Name).Any(y => y.Count() > 1))
            {
                return(Result.GenError <Result>(Error.CapacityDuplicate));
            }

            var wId  = details.FirstOrDefault()?.WorkshopId ?? 0;
            var cIds = details.Select(x => x.TypeId).Distinct();

            if (cIds.Any(x => x == 0))
            {
                return(Result.GenError <Result>(Error.FlowTypeNotExist));
            }
            var sames = details.Select(x => x.Name);

            if (CapacityHelper.GetHaveSame(wId, cIds, sames))
            {
                return(Result.GenError <Result>(Error.CapacityIsExist));
            }
            var cnt = FlowTypeHelper.Instance.GetCountByIds(cIds);

            if (cnt != details.Count())
            {
                return(Result.GenError <Result>(Error.FlowTypeNotExist));
            }
            if (details.Any(x => x.StepIds.Count != x.StepVs.Count))
            {
                return(Result.GenError <Result>(Error.CapacityListError));
            }

            var userId         = Request.GetIdentityInformation();
            var markedDateTime = DateTime.Now;

            foreach (var capacity in details)
            {
                capacity.CreateUserId   = userId;
                capacity.MarkedDateTime = markedDateTime;
                capacity.Remark         = capacity.Remark ?? "";
            }
            CapacityHelper.Instance.Add(details);
            return(Result.GenError <Result>(Error.Success));
        }
Exemple #3
0
        public object GetCapacity([FromQuery] int qId, int cId, int wId, bool menu, bool step)
        {
            if (step && qId != 0)
            {
                var data    = CapacityHelper.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.CapacityList.AddRange(d.StepVList.Where(x => steps.ContainsKey(x.StepId)).Select(x => new
                        {
                            steps[x.StepId].Id,
                            steps[x.StepId].Name,
                            steps[x.StepId].Category,
                            V = x.Number,
                        }));
                    }
                }

                return(new
                {
                    errno = 0,
                    errmsg = "成功",
                    datas = data
                });
            }
            var result = new DataResult();

            result.datas.AddRange(menu
                ? CapacityHelper.GetMenu(wId, qId, cId)
                : CapacityHelper.GetDetail(wId, qId, cId));
            if (qId != 0 && !result.datas.Any())
            {
                result.errno = Error.CapacityNotExist;
                return(result);
            }
            return(result);
        }