static void Main(string[] args) { var str = "5Lul5ZCO5ZGo5LiJ5YGa55qE"; var res2 = DecodeBase64("UTF-8", str); string cloudServer = @"http://111.231.200.224:8842/HanBinScoreService.svc"; string localServer = @"http://192.168.0.105:8842/HanBinSystemService.svc"; RestClient client = new RestClient(localServer); AddOfficerParameter param = new AddOfficerParameter(); param.Name = "剪刀手爱德华29"; param.Gender = 1; param.IdentifyNumber = "111"; param.Birthday = DateTime.Now.ToString(); param.OrganizationID = 62; //UpFile upfile = new UpFile(); //upfile.FileName = "testFile"; //upfile.FileSize = 100; //upfile.FileStream = File.Create(filePath); string json = param.ToClientString(); var res = client.Post(json, "AddOfficerRecord"); Console.WriteLine(res); Console.ReadKey(); }
public BaseResponse <bool> AddOfficerRecord(AddOfficerParameter parameter) { if (Validate(parameter)) { return(officerManager.AddOfficerRecord(parameter)); } else { BaseResponse <bool> response = new BaseResponse <bool>(); response.IsSuccessful = false; response.Reason = "JWT_ERR"; return(response); } }
public BaseResponse <bool> AddOfficerRecord(AddOfficerParameter parameter) { return(officerManager.AddOfficerRecord(parameter)); }
public BaseResponse <bool> AddOfficerRecord(AddOfficerParameter parameter) { //1. 添加干部基础信息 //2. 添加此干部的积分申请(并设置为审批通过) //3. 修改当前积分 //4. 添加积分变更记录 BaseResponse <bool> response = new BaseResponse <bool>(); //iCMSDbContext dbContext = new iCMSDbContext(); OperationResult operResult = null; try { ExecuteDB.ExecuteTrans((dbContext) => { ValidateAddOfficer(dbContext, parameter); Officer officer = new Officer(); officer.Name = parameter.Name; officer.Gender = parameter.Gender; officer.IdentifyCardNumber = parameter.IdentifyNumber; var birth = DateTime.MinValue; var birthdayStr = Utilitys.GetBrithdayFromIdCard(parameter.IdentifyNumber); if (DateTime.TryParse(birthdayStr, out birth)) { officer.Birthday = birth; } officer.OrganizationID = parameter.OrganizationID; officer.PositionStr = parameter.PositionStr; officer.LevelID = parameter.LevelID; DateTime onOfficerDate = DateTime.MinValue; if (DateTime.TryParse(parameter.OnOfficeDate, out onOfficerDate)) { officer.OnOfficeDate = onOfficerDate; } officer.InitialScore = parameter.InitialScore; officer.CurrentScore = officer.InitialScore; officer.LastUpdateDate = DateTime.Now; officer.LastUpdateUserID = parameter.AddUserID; officer.AddUserID = parameter.AddUserID; operResult = dbContext.Officers.AddNew <Officer>(dbContext, officer); if (operResult.ResultType != EnumOperationResultType.Success) { throw new Exception("数据库操作异常"); } #region 操作日志 new LogManager().AddOperationLog(parameter.AddUserID, "添加干部", parameter.RequestIP); #endregion var scoreItemArray = scoreItemRepository.GetDatas <ScoreItem>(t => !t.IsDeleted, true).ToList(); int extraScore = 0; if (parameter.ApplyItemList.Any()) { parameter.ApplyItemList.ForEach(t => { ScoreApply scApply = new ScoreApply(); scApply.OfficerID = officer.OfficerID; scApply.ItemID = t.ItemID; var tempscoreItem = scoreItemArray.Where(s => s.ItemID == t.ItemID).FirstOrDefault(); if (tempscoreItem == null) { throw new Exception("积分条目已被删除"); } scApply.ItemScore = tempscoreItem.ItemScore; scApply.ApplyStatus = 1;//自动设置为审批通过 scApply.ProposeID = officer.AddUserID; scApply.AddUserID = officer.AddUserID; scApply.LastUpdateDate = DateTime.Now; scApply.LastUpdateUserID = officer.AddUserID; scApply.ApplySummary = t.ApplySummary; scApply.IsDeleted = false; operResult = dbContext.ScoreApplies.AddNew <ScoreApply>(dbContext, scApply); if (operResult.ResultType != EnumOperationResultType.Success) { throw new Exception("数据库操作异常"); } //保存变化的分值,最后更新CurrentScore extraScore += scApply.ItemScore; //保存积分更新历史记录表 ScoreChangeHistory his = new ScoreChangeHistory(); his.ApplyID = scApply.ApplyID; his.OfficerID = scApply.OfficerID; his.ItemID = scApply.ItemID; his.ItemScore = scApply.ItemScore; his.ProcessUserID = null; his.ProposeID = scApply.ProposeID; his.AddUserID = scApply.AddUserID; var scoreItem = dbContext.ScoreItems.Where(x => x.ItemID == his.ItemID).FirstOrDefault(); if (scoreItem != null) { var off = dbContext.Officers.Where(o => !o.IsDeleted && o.OfficerID == his.OfficerID).FirstOrDefault(); if (off != null) { var organ = dbContext.Organizations.Where(or => !or.IsDeleted && or.OrganID == off.OrganizationID).FirstOrDefault(); if (organ != null) { his.Content = string.Format("{0} {1} {2}", organ.OrganFullName, off.Name, scoreItem.ItemDescription); operResult = dbContext.ScoreChangeHistories.AddNew <ScoreChangeHistory>(dbContext, his); if (operResult.ResultType != EnumOperationResultType.Success) { throw new Exception("数据库操作异常"); } } } } }); } var officeIndb = dbContext.Officers.Where(t => t.OfficerID == officer.OfficerID && !t.IsDeleted).FirstOrDefault(); if (officeIndb != null) { officeIndb.CurrentScore += extraScore; dbContext.Officers.Update <Officer>(dbContext, officeIndb); } }); } catch (Exception e) { LogHelper.WriteLog(e); response.IsSuccessful = false; response.Reason = e.Message; } return(response); }
private void ValidateAddOfficer(iCMSDbContext dbContext, AddOfficerParameter parameter) { #region 输入验证 if (string.IsNullOrEmpty(parameter.Name)) { throw new Exception("请输入用户名"); } if (string.IsNullOrEmpty(parameter.IdentifyNumber)) { throw new Exception("请输入身份证号码"); } if (string.IsNullOrEmpty(parameter.OnOfficeDate)) { throw new Exception("请输入任职时间"); } if (parameter.OrganizationID < 1) { throw new Exception("请选择单位"); } //var isExisted = dbContext.Officers.Where(t => !t.IsDeleted && !string.IsNullOrEmpty(t.Name) && t.Name.Equals(parameter.Name)).Any(); //if (isExisted) //{ // throw new Exception("干部名称已重复"); //} if (!Utilitys.CheckIDCard(parameter.IdentifyNumber)) { throw new Exception("请输入合法的身份证号码"); } var isExisted = dbContext.Officers.Where(t => !t.IsDeleted && !string.IsNullOrEmpty(t.IdentifyCardNumber) && t.IdentifyCardNumber.Equals(parameter.IdentifyNumber)).Any(); if (isExisted) { throw new Exception("身份证号码重复"); } var addUser = dbContext.HBUsers.Where(t => !t.IsDeleted && t.UserID == parameter.AddUserID).FirstOrDefault(); if (addUser == null) { throw new Exception("数据异常"); } int roleID = addUser.RoleID; switch (roleID) { case (int)EnumRoleType.SuperAdmin: //超级管理员可以任意单位的干部 break; case (int)EnumRoleType.FirstLevelAdmin: //一级管理员不能够添加干部 throw new Exception("请使用二级管理员登陆,然后添加干部"); break; case (int)EnumRoleType.SecondLevelAdmin: var organ = dbContext.Organizations.Where(t => !t.IsDeleted && t.OrganID == addUser.OrganizationID).FirstOrDefault(); if (organ == null) { throw new Exception("请选择干部所在单位"); } //二级管理员只能够添加本单位的干部 if (addUser.OrganizationID != parameter.OrganizationID) { string msg = string.Format("只能添加本单位({0})的干部", organ.OrganFullName); throw new Exception(msg); } break; } #endregion }
public BaseResponse <bool> AddOfficerRecord(AddOfficerParameter parameter) { //1. 添加干部基础信息 //2. 添加此干部的积分申请(并设置为审批通过) //3. 修改当前积分 //4. 添加积分变更记录 BaseResponse <bool> response = new BaseResponse <bool>(); //iCMSDbContext dbContext = new iCMSDbContext(); try { ExecuteDB.ExecuteTrans((dbContext) => { Officer officer = new Officer(); officer.Name = parameter.Name; officer.Gender = parameter.Gender; officer.IdentifyCardNumber = parameter.IdentifyNumber; officer.Birthday = parameter.Birthday; officer.OrganizationID = parameter.OrganizationID; officer.PositionID = parameter.PositionID; officer.LevelID = parameter.LevelID; officer.OnOfficeDate = parameter.OnOfficeDate; officer.InitialScore = parameter.InitialScore; officer.CurrentScore = officer.InitialScore; officer.LastUpdateDate = DateTime.Now; officer.LastUpdateUserID = parameter.AddUserID; dbContext.Officers.AddNew <Officer>(dbContext, officer); int extraScore = 0; if (parameter.ApplyItemList.Any()) { parameter.ApplyItemList.ForEach(t => { ScoreApply scApply = new ScoreApply(); scApply.OfficerID = officer.OfficerID; scApply.ItemID = t.ItemID; scApply.ItemScore = t.ItemScore; scApply.ApplyStatus = 1;//自动设置为审批通过 scApply.ProposeID = officer.AddUserID; scApply.AddUserID = officer.AddUserID; scApply.ApplySummary = t.ApplySummary; scApply.IsDeleted = false; dbContext.ScoreApplies.AddNew <ScoreApply>(dbContext, scApply); //保存变化的分值,最后更新CurrentScore extraScore += scApply.ItemScore; //保存积分更新历史记录表 ScoreChangeHistory his = new ScoreChangeHistory(); his.ApplyID = scApply.ApplyID; his.OfficerID = scApply.OfficerID; his.ItemID = scApply.ItemID; his.ItemScore = scApply.ItemScore; his.ProcessUserID = null; his.ProposeID = scApply.ProposeID; his.AddUserID = scApply.AddUserID; var scoreItem = dbContext.ScoreItems.Where(x => x.ItemID == his.ItemID).First(); his.Content = string.Format("{0} {1} {2}", his.ItemScore, his.AddDate, scoreItem.ItemDescription); dbContext.ScoreChangeHistories.AddNew <ScoreChangeHistory>(dbContext, his); }); } var officeIndb = dbContext.Officers.Where(t => t.OfficerID == officer.OfficerID && !t.IsDeleted).FirstOrDefault(); if (officeIndb != null) { officeIndb.CurrentScore += extraScore; dbContext.Officers.Update <Officer>(dbContext, officeIndb); } }); } catch (Exception e) { response.IsSuccessful = false; response.Reason = "添加干部发生异常!"; } return(response); }