/// <summary> /// 验证月固化信息 /// </summary> /// <param name="month"></param> /// <returns></returns> private string ValidateMonth(string month, ref MonthBonusModel bonus) { string result = ""; if (string.IsNullOrEmpty(month)) { result = "待固化月份值不能为空!"; } else { bonus = _MonthBonusService.GetMonthBonus(month); if (bonus != null) { var bill = _MonthBillCase.FirstOrDefault(p => p.Month == month && p.IsUse); if (bill != null) { result = "月度【" + month + "】已产生固化单,编号为【" + bill.Id.ToString() + "】。"; } } else { result = "请先设定月度【" + month + "】总奖金!"; } } return(result); }
/// <summary> /// 更新和新增月度总奖金 /// </summary> /// <param name="input"></param> /// <returns></returns> public MonthBonusModel InsertOrUpdateMonthBonus(MonthBonusModel input) { if (_MonthBonusCase.GetAll().Any(p => p.Id != input.Id && p.Month == input.Month)) { throw new UserFriendlyException("月份【" + input.Month + "】的对象已存在!"); } // var entObj =input.MapTo<MonthBonus>(); var entObj = _MonthBonusCase.GetAll().FirstOrDefault(x => x.Id == input.Id) ?? new MonthBonus(); //var entObj= AutoMapper.Mapper.Map<MonthBonus>(input); entObj = Fun.ClassToCopy(input, entObj, (new string[] { "Id" }).ToList()); var resObj = _MonthBonusCase.InsertOrUpdate(entObj); if (resObj == null) { throw new UserFriendlyException("新增或更新失败!"); } else { return(resObj.MapTo <MonthBonusModel>()); } }
public void CuringMonthTarget(CurTarget obj) { //string month = GetPropertyValue(obj,"month").ToString(); //string curWay = GetPropertyValue(obj, "curWay").ToString(); string month = obj.Month; string curWay = obj.CurWay; MonthBonusModel bonus = new MonthBonusModel(); var result = ValidateMonth(month, ref bonus); if (result == "") { var user = GetCurrentUserAsync().Result; //1.生成固化单 #region bill MonthBill bill = new MonthBill { Id = 0, BonusValue = bonus.BonusValue, CurTime = DateTime.Now, CurUserId = user.Id,//外部调用可能会报错 IsUse = true, Month = month, Status = MonthBillConst.generate, CurWay = curWay }; #endregion long billId = _MonthBillCase.InsertAndGetIdAsync(bill).Result;//获得固化单ID //写日志 MonthLog(billId, "开始启动生成月份【" + month + "】固化单【" + billId.ToString() + "】:启动人【" + user.Name + "】"); //2.生成月度指标内容 var targetList = _TargetCase.GetAllList(); if (targetList != null && targetList.Count > 0) { try { var managerList = _ManagerCase.GetAllList(); //获取客户经理信息装入内存中 var districtList = _DistrictCase.GetAllList(p => p.CurLevel == 2); //获取所有二级组织(区县) for (int i = 0; i < targetList.Count; i++) { var target = targetList[i]; MonthLog(billId, "===Start======固化指标【" + target.Name + "】编号【" + target.Id.ToString() + "】======"); MonthLog(billId, "->本次固化共有【" + targetList.Count.ToString() + "】个指标"); MonthLog(billId, "->第【" + i.ToString() + "】个指标:建立MonthTarget实例单开始"); #region mTarg MonthTarget mTarg = new MonthTarget { Id = 0, ChooseType = target.ChooseType, EndTable = target.EndTable, MainField = target.MainField, Month = month, MonthBillId = billId, Weight = target.Weight, Remark = target.Remark, TargetId = target.Id, TargetName = target.Name, TargetTagId = target.TargetTagId, TargetTypeId = target.TargetTypeId, CrisisValue = target.CrisisValue//计分门槛值 }; #endregion long monthTargetId = _MonthTargetCase.InsertAndGetIdAsync(mTarg).Result;//得到当前固化指标ID MonthLog(billId, "->第【" + i.ToString() + "】个指标:建立MonthTarget实例单【" + monthTargetId.ToString() + "】完成"); //3.生成月度指标明细(当未获取到目标值时,默认为0) InitMonthTargetDetail(month, monthTargetId, billId, target, managerList, districtList); MonthLog(billId, "===End======固化指标【" + target.Name + "】编号【" + target.Id.ToString() + "】======"); } } catch (Exception ex) { bill.Status = MonthBillConst.error; bill.IsUse = false; _MonthBillCase.UpdateAsync(bill); string errStr = "月份【" + month + "】固化单生成失败.错误:" + ex.InnerException.Message; MonthLog(billId, "失败:" + errStr); bill.Status = MonthBillConst.error; bill.IsUse = false; bill.Remark = errStr; _MonthBillCase.UpdateAsync(bill); throw new Exception(errStr); } } bill.Status = MonthBillConst.success; _MonthBillCase.UpdateAsync(bill); //_MonthBillCase.InsertAsync(bill); MonthLog(billId, "结束:月份【" + month + "】固化单生成全部完成。成功"); } else { throw new Exception(result); } }