using BLL; using Model; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using RestSharp; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Net.Http; using System.Text; using System.Text.RegularExpressions; using System.Web.Http; namespace WebAPI.Controllers { /// /// 交建定制接口 /// public class CNCCGController : ApiController { /// /// 获取人员 /// [HttpGet] public string GetPerson(string path) { // string path="https://cncccg.hcmcloud.cn"; string baseurl = path + "/api/private.GetAllPerson?private_token=hcm7958d257318f2399e12bf44052a75fc17d22c461"; var client = new RestClient(baseurl); client.Timeout = -1; var request = new RestRequest(Method.POST); //request.AddParameter("private_token", "hcm7958d257318f2399e12bf44052a75fc17d22c461"); var body = @"{ ""page_index"":0, ""page_size"":4000, ""date"":""2001-04-03"" }"; // request.AddParameter("text/plain", body, ParameterType.RequestBody); // request.AddJsonBody("{\r\n \"page_index\":0,\r\n \"page_size\":4000,\r\n \"date\":\"2001-04-03\"\r\n}"); request.AddJsonBody(body); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); var value = new Regex(@"\\u([0-9A-F]{4})", RegexOptions.IgnoreCase | RegexOptions.Compiled).Replace( response.Content.ToString(), x => string.Empty + Convert.ToChar(Convert.ToUInt16(x.Result("$1"), 16))); var responeData = JsonConvert.DeserializeObject(value); var list = responeData.result.data.list; // list = list.Where(x => x.pos_sta_name != "离职"&& x.pos_sta_name != "退休").ToList(); Model.UserListItem userListItem = new Model.UserListItem(); userListItem.list = new List(); foreach (var item in list) { Model.UserItem userItem = new Model.UserItem { Account = item.number, Telephone = item.mobile, UserName = item.name, UserCode = item.number, Sex = item.gender, IdentityCard = item.identity_card, UnitName = item.unit.name == "总部" ? "中化学交通建设集团有限公司" : item.unit.name, UnitCode = item.unit.number, IsPost = (item.pos_sta_name == "离职" || item.pos_sta_name == "退休") ? false : true, Remark = item.position.name }; userListItem.list.Add(userItem); } var result= APIUserService.SaveCNCCGUserInfo(userListItem); return result; } #region 群安员巡检接口 #region 根据项目id获取在岗用户 /// /// 返回类 /// public class onDutyUser { /// /// 用户名 /// public string username { get; set; } /// /// 用户id /// public string userid { get; set; } } /// /// 根据项目id获取在岗用户 /// /// /// public Model.ResponeData getUserByProjectId(string userProjectid) { var responeData = new Model.ResponeData(); try { var list = UserService.GetProjectUserListByProjectId(userProjectid); List userlist = new List(); list.ForEach(x => { onDutyUser m = new onDutyUser(); m.username = x.UserName; m.userid = x.UserId; userlist.Add(m); }); responeData.data = userlist; } catch (Exception ex) { responeData.code = 0; responeData.message = ex.Message; } return responeData; } #endregion /// /// 获取列表接口 /// /// /// /// [HttpGet] public Model.ResponeData getSafetyOfficerCheckList(string state,string userid, int pageIndex=0) { var responeData = new Model.ResponeData(); try { var getDataList = SafetyOfficerCheckService.getSafetyOfficerList(state,userid); int pageCount = getDataList.Count; if (pageCount > 0 && pageIndex > 0) { getDataList = getDataList.Skip(Funs.PageSize * (pageIndex - 1)).Take(Funs.PageSize).ToList(); } responeData.data = new { pageCount, getDataList }; } catch (Exception ex) { responeData.code = 0; responeData.message = ex.Message; } return responeData; } /// /// 获取详情 /// /// 主键ID /// [HttpGet] public Model.ResponeData getSafetyOfficerCheckItem(string SafetyOfficerCheckId) { var responeData = new Model.ResponeData(); try { responeData.data = SafetyOfficerCheckService.getSafetyOfficerItem(SafetyOfficerCheckId); } catch (Exception ex) { responeData.code = 0; responeData.message = ex.Message; } return responeData; } /// /// 新增群安员巡检(state0是保存 1是提交) /// /// /// [HttpPost] public Model.ResponeData saveSafetyOfficerCheck([FromBody] Model.Check_SafetyOfficerCheck model) { var responeData = new Model.ResponeData(); try { if (!string.IsNullOrEmpty(model.SafetyOfficerCheckId)) { model.SafetyOfficerCheckId = model.SafetyOfficerCheckId; BLL.SafetyOfficerCheckService.Update(model); } else { model.SafetyOfficerCheckId = SQLHelper.GetNewID(typeof(Model.Check_SafetyOfficerCheck)); BLL.SafetyOfficerCheckService.Add(model); } } catch (Exception ex) { responeData.code = 0; responeData.message = ex.Message; } return responeData; } /// /// 生成安全巡检 /// /// /// /// [HttpGet] public Model.ResponeData submitSafetyOfficerCheck(string SafetyOfficerCheckId,string LoginProjectId) { var responeData = new Model.ResponeData(); try { Model.Check_SafetyOfficerCheck model = Funs.DB.Check_SafetyOfficerCheck.FirstOrDefault(x => x.SafetyOfficerCheckId == SafetyOfficerCheckId); if (model.State=="2") { responeData.code = 0; responeData.message = "当前状态不是待生成,不可生成安全巡检"; return responeData; } model.State = "2"; BLL.SafetyOfficerCheckService.Update(model); #region 插入安全巡检 Model.HSSE_Hazard_HazardRegister register = new Model.HSSE_Hazard_HazardRegister(); register.RegisterDef = model.HandleIdea;//问题描述 register.ProblemTypes = "1"; //安全隐患问题 register.ImageUrl = model.ImageUrl;//整改前照片 register.States = "1"; //待整改 register.CheckManId = model.ReceiveMan;//群安员安检接收人为检查人 register.ProjectId = LoginProjectId;//项目id register.HazardRegisterId = SQLHelper.GetNewID(typeof(Model.HSSE_Hazard_HazardRegister)); #region 保存附件 //保存附件 Model.AttachFile file = BLL.AttachFileService.GetAttachFile(SafetyOfficerCheckId, Const.Check_SafetyOfficerCheckMenuId); Model.AttachFile newFile = new Model.AttachFile(); newFile.ToKeyId = register.HazardRegisterId; newFile.AttachSource = file.AttachSource; newFile.AttachUrl = file.AttachUrl; newFile.MenuId = BLL.Const.HiddenRectificationMenuId; BLL.AttachFileService.AddAttachFile(newFile); #endregion BLL.HSSE_Hazard_HazardRegisterService.AddHazardRegister(register); #endregion responeData.message = "生成安全巡检成功。"; } catch (Exception ex) { responeData.code = 0; responeData.message = ex.Message; } return responeData; } #endregion } }