256 lines
9.7 KiB
C#
256 lines
9.7 KiB
C#
|
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
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 交建定制接口
|
|||
|
/// </summary>
|
|||
|
public class CNCCGController : ApiController
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 获取人员
|
|||
|
/// </summary>
|
|||
|
[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<Model.Customization.IPersonItem>(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<Model.UserItem>();
|
|||
|
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获取在岗用户
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 返回类
|
|||
|
/// </summary>
|
|||
|
public class onDutyUser {
|
|||
|
/// <summary>
|
|||
|
/// 用户名
|
|||
|
/// </summary>
|
|||
|
public string username { get; set; }
|
|||
|
/// <summary>
|
|||
|
/// 用户id
|
|||
|
/// </summary>
|
|||
|
public string userid { get; set; }
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 根据项目id获取在岗用户
|
|||
|
/// </summary>
|
|||
|
/// <param name="userProjectid"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public Model.ResponeData getUserByProjectId(string userProjectid)
|
|||
|
{
|
|||
|
var responeData = new Model.ResponeData();
|
|||
|
try
|
|||
|
{
|
|||
|
var list = UserService.GetProjectUserListByProjectId(userProjectid);
|
|||
|
List<onDutyUser> userlist = new List<onDutyUser>();
|
|||
|
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
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 获取列表接口
|
|||
|
/// </summary>
|
|||
|
/// <param name="state"></param>
|
|||
|
/// <param name="pageIndex"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[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;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 获取详情
|
|||
|
/// </summary>
|
|||
|
/// <param name="SafetyOfficerCheckId">主键ID</param>
|
|||
|
/// <returns></returns>
|
|||
|
[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;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 新增群安员巡检(state0是保存 1是提交)
|
|||
|
/// </summary>
|
|||
|
/// <param name="model"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[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;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 生成安全巡检
|
|||
|
/// </summary>
|
|||
|
/// <param name="SafetyOfficerCheckId"></param>
|
|||
|
/// <param name="LoginProjectId"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[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
|
|||
|
}
|
|||
|
}
|