Example #1
0
        /// <summary>
        /// [验证] 考核模板
        /// </summary>
        /// <param name="modelDto"></param>
        /// <returns></returns>
        private Result CheckTemplat(KpiEvaluationTemplatSubmitDto modelDto)
        {
            if (modelDto.TemplateRecord.Count == 0)
            {
                return Result.Fail("请选择考核对象");
            }
            foreach (var item in modelDto.TemplateRecord)
            {
                var lsContent = JsonConvert.DeserializeObject<List<KpiTemplateContentsDto>>(item.Contents).ToList();
                if (lsContent.Count() == 0)
                {
                    return Result.Fail("请设置考核内容");
                }
                var lsAudits = JsonConvert.DeserializeObject<List<KpiTemplateAuditsDto>>(item.Audits).ToList();
                if (lsAudits.Count() == 0)
                {
                    return Result.Fail("请设置审核人");
                }
            }

            return Result.Success();
        }
Example #2
0
 public Result EditTemplat([FromForm] KpiEvaluationTemplatSubmitDto modelDto)
 {
     return(_wrappers.AddOrEditTemplat(modelDto));
 }
Example #3
0
        /// <summary>
        /// [添加/编辑] 考核模板
        /// </summary>
        /// <param name="modelDto"></param>
        /// <returns></returns>
        public Result AddOrEditTemplat(KpiEvaluationTemplatSubmitDto modelDto)
        {
            try
            {
                var dtNow = DateTime.Now;
                var result = CheckTemplat(modelDto);
                if (!result.Succeed)
                {
                    return result;
                }

                using (TransactionScope ts = new TransactionScope())
                {
                    //保存 考核模板记录
                    var dbTplRecord = new List<KpiTemplateRecord>();
                    //保存 考核模板
                    var dbTpl = new List<KpiTemplate>();

                    var whereTplRecord = new Condition<KpiTemplateRecord>();
                    whereTplRecord.And(p => p.KpiType == modelDto.KpiType);
                    whereTplRecord.And(p => p.KpiId == modelDto.KpiId);

                    if (modelDto.KpiType == KpiType.Dept) //部门
                    {
                        var dptIds = modelDto.TemplateRecord.Select(p => p.DptId);
                        whereTplRecord.And(p => dptIds.Contains(p.DptId));
                        dbTplRecord = _tplRecordBusiness.Query(whereTplRecord.Combine()).ToList();
                        dbTpl = _tplBusiness.Query(p => p.KpiType == modelDto.KpiType && dptIds.Contains(p.DptId)).ToList();
                    }
                    else //人员
                    {
                        var employeeIds = modelDto.TemplateRecord.Select(p => p.EmployeeId);
                        whereTplRecord.And(p => employeeIds.Contains(p.EmployeeId));
                        dbTplRecord = _tplRecordBusiness.Query(whereTplRecord.Combine()).ToList();
                        dbTpl = _tplBusiness.Query(p => p.KpiType == modelDto.KpiType && employeeIds.Contains(p.EmployeeId)).ToList();
                    }

                    var lsExistTplRecord = new List<KpiTemplateRecord>();
                    var lsNotExistTplRecord = new List<KpiTemplateRecord>();

                    var lsNotExistMagTotal = new List<KpiManageTotal>();

                    var distinct = dbTplRecord.ToDictionary(p => $"{p.CompanyId}_{p.DptId}_{p.EmployeeId}_{(int)p.KpiId}_{(int)p.KpiType}");
                    foreach (var item in modelDto.TemplateRecord)
                    {
                        var key = $"{item.CompanyId}_{item.DptId}_{item.EmployeeId}_{(int)item.KpiId}_{(int)item.KpiType}";
                        if (distinct.ContainsKey(key)) //已经存在
                        {
                            var modelTemp = distinct[key];
                            modelTemp.Contents = item.Contents;
                            modelTemp.Audits = item.Audits;
                            lsExistTplRecord.Add(modelTemp);
                        }
                        else
                        {
                            lsNotExistTplRecord.Add(item);
                        }
                    }

                    if (lsNotExistTplRecord.Count > 0)
                    {
                        _tplRecordBusiness.AddRange(lsNotExistTplRecord);
                    }

                    //填充 不存在和存在的数据
                    var lsTplRecord = new List<KpiTemplateRecord>();
                    lsTplRecord.AddRange(lsNotExistTplRecord);
                    lsTplRecord.AddRange(lsExistTplRecord);

                    //考核模板
                    var lsExistTpl = new List<KpiTemplate>();
                    var lsNotExistTpl = new List<KpiTemplate>();

                    foreach (var tplRecord in lsTplRecord)
                    {
                        //考核模板
                        KpiTemplate modelTpl = null;
                        if (dbTpl.Count > 0)
                        {
                            if (modelDto.KpiType == KpiType.Dept) //部门
                            {
                                modelTpl = dbTpl.FirstOrDefault(p => p.CompanyId == tplRecord.CompanyId && p.DptId == tplRecord.DptId);
                            }
                            else //人员
                            {
                                modelTpl = dbTpl.FirstOrDefault(p => p.CompanyId == tplRecord.CompanyId && p.DptId == tplRecord.DptId && p.EmployeeId == tplRecord.EmployeeId);
                            }
                        }
                        if (modelTpl == null)
                        {
                            lsNotExistTpl.Add(new KpiTemplate()
                            {
                                Id = 0,
                                KpiType = tplRecord.KpiType,
                                CompanyId = tplRecord.CompanyId,
                                CompanyName = tplRecord.CompanyName,
                                DptId = tplRecord.DptId,
                                DptName = tplRecord.DptName,
                                EmployeeId = tplRecord.EmployeeId,
                                UserName = tplRecord.UserName,
                                Monthly = modelDto.KpiId == KpiPlan.Monthly ? tplRecord.Id : 0,
                                Quarter = modelDto.KpiId == KpiPlan.Quarter ? tplRecord.Id : 0,
                                HalfYear = modelDto.KpiId == KpiPlan.HalfYear ? tplRecord.Id : 0,
                                Annual = modelDto.KpiId == KpiPlan.Annual ? tplRecord.Id : 0,
                            });
                        }
                        else
                        {
                            modelTpl.Monthly = modelDto.KpiId == KpiPlan.Monthly ? tplRecord.Id : modelTpl.Monthly;
                            modelTpl.Quarter = modelDto.KpiId == KpiPlan.Quarter ? tplRecord.Id : modelTpl.Quarter;
                            modelTpl.HalfYear = modelDto.KpiId == KpiPlan.HalfYear ? tplRecord.Id : modelTpl.HalfYear;
                            modelTpl.Annual = modelDto.KpiId == KpiPlan.Annual ? tplRecord.Id : modelTpl.Annual;
                            lsExistTpl.Add(modelTpl);
                        }
                    }

                    if (lsNotExistTplRecord.Count > 0)
                    {
                        _tplRecordBusiness.UpdateRange(lsExistTplRecord);
                    }
                    if (lsNotExistMagTotal.Count > 0)
                    {
                        _magTotalBusiness.AddRange(lsNotExistMagTotal);
                    }
                    if (lsNotExistTpl.Count > 0)
                    {
                        _tplBusiness.AddRange(lsNotExistTpl);
                    }
                    if (lsExistTpl.Count > 0)
                    {
                        _tplBusiness.UpdateRange(lsExistTpl);
                    }

                    ts.Complete();
                    return Result.Success();
                }
            }
            catch (Exception ex)
            {
                return Result.Fail("操作失败:" + ex.Message);
            }
        }