298 lines
		
	
	
		
			16 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			298 lines
		
	
	
		
			16 KiB
		
	
	
	
		
			C#
		
	
	
	
|  | using System; | |||
|  | using System.Collections.Generic; | |||
|  | using System.Configuration; | |||
|  | using System.IO; | |||
|  | using System.Linq; | |||
|  | using System.Net; | |||
|  | using System.Net.Http; | |||
|  | using System.Web.Http; | |||
|  | using BLL; | |||
|  | using WebAPI.Filter; | |||
|  | 
 | |||
|  | namespace WebAPI.Controllers | |||
|  | { | |||
|  |     public class uploadController : ApiController | |||
|  |     { | |||
|  |         #region 项目出入记录接口 | |||
|  |         /// <summary> | |||
|  |         /// 保存出入记录信息 | |||
|  |         /// </summary> | |||
|  |         /// <param name="records">出入记录信息</param> | |||
|  |         /// <returns></returns> | |||
|  |         [HttpPost] | |||
|  |         public Model.ResponeData attendance([FromBody] Model.attendanceItems records) | |||
|  |         { | |||
|  |             var responeData = new Model.ResponeData(); | |||
|  |             try | |||
|  |             { | |||
|  |                 if (records != null && records.records.Count() > 0) | |||
|  |                 { | |||
|  |                     List<Model.attendanceItem> attendanceItems = records.records; | |||
|  |                     var getprojectCode = attendanceItems.FirstOrDefault(x => x.ProjectCode != null || x.ProjectId != null); | |||
|  |                     if (getprojectCode != null) | |||
|  |                     { | |||
|  |                         string projectId = getprojectCode.ProjectId; | |||
|  |                         if (string.IsNullOrEmpty(projectId)) | |||
|  |                         { | |||
|  |                             var getProject = ProjectService.GetProjectByProjectCode(getprojectCode.ProjectCode); | |||
|  |                             if (getProject != null) | |||
|  |                             { | |||
|  |                                 projectId = getProject.ProjectId; | |||
|  |                             } | |||
|  |                         } | |||
|  |                         if (!string.IsNullOrEmpty(projectId)) | |||
|  |                         { | |||
|  |                             using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) | |||
|  |                             { | |||
|  |                                 int maxId = 0; | |||
|  |                                 var getmax = db.T_d_facerecord.Where(x => x.ProjectId == projectId && x.RoleID == "白名单").Select(x => x.ID); | |||
|  |                                 if (getmax.Count() > 0) | |||
|  |                                 { | |||
|  |                                     maxId = getmax.Max(); | |||
|  |                                 } | |||
|  |                                 foreach (var item in attendanceItems) | |||
|  |                                 { | |||
|  |                                     maxId = maxId + 1; | |||
|  |                                     string name = string.Empty; | |||
|  |                                     string cardNo = string.Empty; | |||
|  |                                     var getPerson = db.SitePerson_Person.FirstOrDefault(x => x.IdentityCard == item.idCardNumber); | |||
|  |                                     if (getPerson != null) | |||
|  |                                     { | |||
|  |                                         name = getPerson.PersonName; | |||
|  |                                         cardNo = getPerson.CardNo; | |||
|  |                                     } | |||
|  | 
 | |||
|  |                                     Model.T_d_facerecord newFacerecord = new Model.T_d_facerecord() | |||
|  |                                     { | |||
|  |                                         NewID = SQLHelper.GetNewID(), | |||
|  |                                         ProjectId = projectId, | |||
|  |                                         ID = maxId, | |||
|  |                                         EmployName = name, | |||
|  |                                         EmployNO = item.idCardNumber, | |||
|  |                                         RoleID = "白名单", | |||
|  |                                         DateTimeRecord = Funs.GetNewDateTime(item.attendanceTime), | |||
|  |                                         RecordDes = "白名单:允许通行", | |||
|  |                                         InOrOut = (item.attendanceType == 1 ? "进门" : "出门"), | |||
|  |                                     }; | |||
|  | 
 | |||
|  |                                     db.T_d_facerecord.InsertOnSubmit(newFacerecord); | |||
|  |                                     db.SubmitChanges(); | |||
|  |                                     ///// 根据出入记录 写入考勤记录 | |||
|  |                                     Model.t_d_facerecordItem facerecord = new Model.t_d_facerecordItem | |||
|  |                                     { | |||
|  |                                         ID = maxId, | |||
|  |                                         EmployName = name, | |||
|  |                                         IDCardNo = item.idCardNumber, | |||
|  |                                         EmployNO = item.idCardNumber, | |||
|  |                                         ProjectId = projectId, | |||
|  |                                         RoleID = "白名单", | |||
|  |                                         DateTimeRecord = Funs.GetNewDateTime(item.attendanceTime), | |||
|  |                                         RecordDes = "白名单:允许通行", | |||
|  |                                         InOrOut = (item.attendanceType == 1 ? "进门" : "出门"), | |||
|  |                                     }; | |||
|  |                                     DoorServerService.InsertEmployInOutRecord(facerecord, getPerson); | |||
|  |                                     if (facerecord.DateTimeRecord.HasValue) | |||
|  |                                     { | |||
|  |                                         int isIn = 0; | |||
|  |                                         if (facerecord.InOrOut == "进门") | |||
|  |                                         { | |||
|  |                                             isIn = 1; | |||
|  |                                         } | |||
|  |                                         APIPersonService.getPersonInOut(getPerson, isIn, facerecord.DateTimeRecord.Value); | |||
|  |                                     } | |||
|  |                                 } | |||
|  |                                 responeData.message = "插入成功!"; | |||
|  |                             } | |||
|  |                         } | |||
|  |                         else | |||
|  |                         { | |||
|  |                             responeData.code = 0; | |||
|  |                             responeData.message = "项目号异常!"; | |||
|  |                         } | |||
|  |                     } | |||
|  |                     else | |||
|  |                     { | |||
|  |                         responeData.code = 0; | |||
|  |                         responeData.message = "项目号为空!"; | |||
|  |                     } | |||
|  |                 } | |||
|  |                 else | |||
|  |                 { | |||
|  |                     responeData.code = 0; | |||
|  |                     responeData.message = "数据为空!"; | |||
|  |                 } | |||
|  |             } | |||
|  |             catch (Exception ex) | |||
|  |             { | |||
|  |                 responeData.code = 0; | |||
|  |                 responeData.message = ex.Message; | |||
|  |             } | |||
|  | 
 | |||
|  |             return responeData; | |||
|  |         } | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         #region 项目出入人员信息 | |||
|  |         /// <summary> | |||
|  |         /// 保存人员信息 | |||
|  |         /// </summary> | |||
|  |         /// <param name="person">人员信息</param> | |||
|  |         /// <returns></returns> | |||
|  |         [HttpPost] | |||
|  |         public Model.ResponeData person([FromBody] Model.PersonItem person) | |||
|  |         { | |||
|  |             var responeData = new Model.ResponeData(); | |||
|  |             try | |||
|  |             { | |||
|  |                 if (person != null) | |||
|  |                 { | |||
|  |                     using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) | |||
|  |                     { | |||
|  |                         var getProject = ProjectService.GetProjectByProjectCode(person.ProjectCode); | |||
|  |                         if (getProject != null) | |||
|  |                         { | |||
|  |                             var getUnit = UnitService.getUnitByCollCropCodeUnitName(person.CollCropCode, person.UnitName); | |||
|  |                             if (getUnit != null) | |||
|  |                             { | |||
|  |                                 var getPerson = PersonService.GetPersonByIdentityCard(getProject.ProjectId, person.IdentityCard); | |||
|  |                                 if (getPerson == null) | |||
|  |                                 { | |||
|  |                                     Model.SitePerson_Person newPerson = new Model.SitePerson_Person | |||
|  |                                     { | |||
|  |                                         PersonId = SQLHelper.GetNewID(), | |||
|  |                                         ProjectId = getProject.ProjectId, | |||
|  |                                         UnitId = getUnit.UnitId, | |||
|  |                                         PersonName = person.PersonName, | |||
|  |                                         IdentityCard = person.IdentityCard, | |||
|  |                                         IdcardType = "SHENFEN_ZHENGJIAN", | |||
|  |                                         IdcardAddress = person.IdcardAddress, | |||
|  |                                         IdcardForever = "N", | |||
|  |                                         IdcardStartDate = Funs.GetNewDateTime(person.IdcardStartDate), | |||
|  |                                         IdcardEndDate = Funs.GetNewDateTime(person.IdcardEndDate), | |||
|  |                                         Sex = (person.Sex == "女" || person.Sex == "2") ? "2" : "1", | |||
|  |                                         Address = person.Address, | |||
|  |                                         OutResult = person.OutResult, | |||
|  |                                         Birthday = person.Birthday, | |||
|  |                                         Telephone = person.Telephone, | |||
|  |                                         IsUsed = person.IsUsed == false ? false : true, | |||
|  |                                         InTime = Funs.GetNewDateTimeOrNow(person.InTime), | |||
|  |                                         Password = BLL.PersonService.GetPersonPassWord(person.IdentityCard), | |||
|  |                                         Isprint = "0", | |||
|  |                                         //PositionId = person.PositionId, | |||
|  |                                         //PostTitleId = person.PostTitleId,                               | |||
|  |                                         //IsForeign = person.IsForeign, | |||
|  |                                         //IsOutside = person.IsOutside, | |||
|  |                                         //EduLevel = person.EduLevel, | |||
|  |                                         //MaritalStatus = person.MaritalStatus, | |||
|  |                                         //PoliticsStatus = person.PoliticsStatus, | |||
|  |                                         //Nation = person.Nation, | |||
|  |                                         //CountryCode = person.CountryCode, | |||
|  |                                         //ProvinceCode = person.ProvinceCode, | |||
|  |                                     }; | |||
|  | 
 | |||
|  |                                     if (!string.IsNullOrEmpty(person.TeamGroupName) && !string.IsNullOrEmpty(newPerson.UnitId)) | |||
|  |                                     { | |||
|  |                                         var getTeamGroup = TeamGroupService.getTeamGroupByTeamGroupName(getProject.ProjectId, newPerson.UnitId, person.TeamGroupName); | |||
|  |                                         if (getTeamGroup != null) | |||
|  |                                         { | |||
|  |                                             newPerson.TeamGroupId = getTeamGroup.TeamGroupId; | |||
|  |                                         } | |||
|  |                                         else | |||
|  |                                         { | |||
|  |                                             Model.ProjectData_TeamGroup newTeamGroup = new Model.ProjectData_TeamGroup | |||
|  |                                             { | |||
|  |                                                 TeamGroupId = SQLHelper.GetNewID(), | |||
|  |                                                 ProjectId = getProject.ProjectId, | |||
|  |                                                 UnitId = newPerson.UnitId, | |||
|  |                                                 TeamGroupName = person.TeamGroupName, | |||
|  |                                                 Remark = "来源:考勤对接数据", | |||
|  |                                                 TeamTypeId = "CANJIAN_TEAM", | |||
|  |                                                 EntryTime = System.DateTime.Now, | |||
|  |                                                 RealNamePushTime = null, | |||
|  |                                             }; | |||
|  |                                             db.ProjectData_TeamGroup.InsertOnSubmit(newTeamGroup); | |||
|  |                                             db.SubmitChanges(); | |||
|  |                                             newPerson.TeamGroupId = newTeamGroup.TeamGroupId; | |||
|  |                                         } | |||
|  |                                     } | |||
|  |                                     var getWorkArea = UnitWorkService.GetUnitWorkByUnitWorkName(getProject.ProjectId, person.WorkAreaName); | |||
|  |                                     if (getWorkArea != null) | |||
|  |                                     { | |||
|  |                                         newPerson.WorkAreaId = getWorkArea.UnitWorkId; | |||
|  |                                     } | |||
|  |                                     var getWorkPost = WorkPostService.GetWorkPostByName(person.WorkPostName); | |||
|  |                                     if (getWorkPost != null) | |||
|  |                                     { | |||
|  |                                         newPerson.WorkPostId = getWorkPost.WorkPostId; | |||
|  |                                     } | |||
|  |                                     var getHsseMan = ProjectService.getHSSEManager(getProject.ProjectId); | |||
|  |                                     if (getHsseMan != null) | |||
|  |                                     { | |||
|  |                                         newPerson.AuditorId = getHsseMan.UserId; | |||
|  |                                         newPerson.AuditorDate = DateTime.Now; | |||
|  |                                     } | |||
|  |                                     newPerson.OutTime = Funs.GetNewDateTime(person.OutTime); | |||
|  |                                     if (person.headImage != null) | |||
|  |                                     { | |||
|  |                                         var image = Convert.FromBase64String(person.headImage); | |||
|  |                                         newPerson.HeadImage = image; | |||
|  |                                         string rootPath = ConfigurationManager.AppSettings["localRoot"]; | |||
|  |                                         string path = "FileUpLoad/PersonBaseInfo/" + DateTime.Now.ToString("yyyy-MM") + "/"; | |||
|  |                                         string fileUrl = (rootPath + path).Replace('/', '\\'); | |||
|  |                                         string flieName = Funs.GetNewFileName() + "~" + person.IdentityCard + ".jpg"; | |||
|  |                                         if (!Directory.Exists(fileUrl)) | |||
|  |                                         { | |||
|  |                                             Directory.CreateDirectory(fileUrl); | |||
|  |                                         } | |||
|  |                                         newPerson.PhotoUrl = path + flieName; | |||
|  |                                         System.IO.File.WriteAllBytes((fileUrl + flieName), image); | |||
|  |                                         //AttachFileService.Base64ToImage(person.headImage, path, person.PersonName); | |||
|  |                                     } | |||
|  | 
 | |||
|  |                                     PersonService.AddPerson(newPerson); | |||
|  |                                     responeData.message = "新增人员成功!"; | |||
|  |                                 } | |||
|  |                                 else | |||
|  |                                 { | |||
|  |                                     if (!string.IsNullOrEmpty(person.OutTime)) | |||
|  |                                     { | |||
|  |                                         var outTime = Funs.GetNewDateTimeOrNow(person.OutTime); | |||
|  |                                         PersonService.PersonOut(getPerson.PersonId, outTime); | |||
|  |                                         responeData.message = "更新出场时间"; | |||
|  |                                     } | |||
|  |                                     else | |||
|  |                                     { | |||
|  |                                         responeData.message = "该身份证号码人员已存在!"; | |||
|  |                                     } | |||
|  |                                 } | |||
|  |                             } | |||
|  |                             else | |||
|  |                             { | |||
|  |                                 responeData.code = 0; | |||
|  |                                 responeData.message = "单位:" + person.UnitName + "施工平台不存在!"; | |||
|  |                             } | |||
|  |                         } | |||
|  |                         else | |||
|  |                         { | |||
|  |                             responeData.code = 0; | |||
|  |                             responeData.message = "项目号:" + person.ProjectCode + "施工平台不存在!"; | |||
|  |                         } | |||
|  |                     } | |||
|  |                 } | |||
|  |                 else | |||
|  |                 { | |||
|  |                     responeData.code = 0; | |||
|  |                     responeData.message = "数据为空!"; | |||
|  |                 } | |||
|  |             } | |||
|  |             catch (Exception ex) | |||
|  |             { | |||
|  |                 responeData.code = 0; | |||
|  |                 responeData.message = ex.Message; | |||
|  |             } | |||
|  | 
 | |||
|  |             return responeData; | |||
|  |         } | |||
|  |         #endregion | |||
|  |     } | |||
|  | } |