301 lines
11 KiB
C#
301 lines
11 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Net;
|
||
using System.Net.Http;
|
||
using System.Web.Http;
|
||
using BLL;
|
||
using Model;
|
||
|
||
namespace WebAPI.Controllers.DataPenetrate
|
||
{
|
||
/// <summary>
|
||
/// 项目用户控制器
|
||
/// </summary>
|
||
public class ProjectUserPenetrateController : ApiController
|
||
{
|
||
#region 查询
|
||
/// <summary>
|
||
/// 查询项目人员personId
|
||
/// </summary>
|
||
/// <param name="projectIds"></param>
|
||
/// <param name="unitId"></param>
|
||
/// <returns></returns>
|
||
[HttpGet]
|
||
public Model.ResponeData getInfo(string projectIds = "", string unitId = "")
|
||
{
|
||
string projectId = projectIds;
|
||
var responeData = new Model.ResponeData();
|
||
try
|
||
{
|
||
if (string.IsNullOrEmpty(projectId))
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "项目id不能为空";
|
||
return responeData;
|
||
}
|
||
var getDataList = new List<SitePerson_Person_new>();
|
||
if (!string.IsNullOrEmpty(unitId))
|
||
{
|
||
getDataList = Funs.DB.SitePerson_Person.Where(x => x.ProjectId == projectId && x.UnitId == unitId)
|
||
.Select(s => new SitePerson_Person_new()
|
||
{
|
||
PersonId = s.PersonId,
|
||
PersonName = s.PersonName
|
||
})
|
||
.ToList();
|
||
}
|
||
else
|
||
{
|
||
getDataList = Funs.DB.SitePerson_Person.Where(x => x.ProjectId == projectId)
|
||
.Select(s => new SitePerson_Person_new()
|
||
{
|
||
PersonId = s.PersonId,
|
||
PersonName = s.PersonName
|
||
})
|
||
.ToList();
|
||
}
|
||
if (getDataList.Count == 0)
|
||
{
|
||
responeData.code = 1;
|
||
responeData.message = "根据条件未查询到数据。";
|
||
return responeData;
|
||
}
|
||
responeData.data = new { getDataList };
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = ex.Message;
|
||
}
|
||
|
||
return responeData;
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据用户登录名查询系统用户
|
||
/// </summary>
|
||
/// <param name="account"></param>
|
||
/// <returns></returns>
|
||
[HttpGet]
|
||
public Model.ResponeData getSysUserInfo(string account="") {
|
||
var responeData = new Model.ResponeData();
|
||
try
|
||
{
|
||
if (string.IsNullOrEmpty(account))
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "用户登录名不能为空";
|
||
return responeData;
|
||
}
|
||
|
||
var getDataList = Funs.DB.Sys_User.Where(x => x.Account == account)
|
||
.Select(s => new Sys_User_New()
|
||
{
|
||
UserId = s.UserId,
|
||
Account = s.Account
|
||
})
|
||
.ToList();
|
||
|
||
responeData.data = new { getDataList };
|
||
if (getDataList.Count == 0)
|
||
{
|
||
responeData.code = 1;
|
||
responeData.message = "根据条件未查询到数据。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "查询成功。";
|
||
return responeData;
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
responeData.code = 0;
|
||
responeData.message = ex.Message;
|
||
}
|
||
|
||
return responeData;
|
||
}
|
||
|
||
private class SitePerson_Person_new {
|
||
public string PersonId { get; set; }
|
||
public string PersonName { get; set; }
|
||
}
|
||
|
||
private class Sys_User_New
|
||
{
|
||
public string UserId { get; set; }
|
||
|
||
public string Account { get; set; }
|
||
}
|
||
#endregion
|
||
|
||
#region 保存用户
|
||
/// <summary>
|
||
/// 保存用户
|
||
/// </summary>
|
||
/// <param name="model"></param>
|
||
/// <returns></returns>
|
||
public ResponeData saveUser(Sys_User model)
|
||
{
|
||
var responeData = new Model.ResponeData();
|
||
try
|
||
{
|
||
#region 判断
|
||
if (string.IsNullOrEmpty(model.UnitId))
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "单位id不能为空。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
var umodel = Funs.DB.Base_Unit.FirstOrDefault(x => x.UnitId == model.UnitId);
|
||
if (umodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "单位id未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
}
|
||
|
||
var q = Funs.DB.Sys_User.FirstOrDefault(x => x.Account == model.Account && (x.UserId != model.UserId || (model.UserId == null && x.UserId != null)));
|
||
if (q != null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "输入的账号已存在。";
|
||
return responeData;
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(model.UserCode))
|
||
{
|
||
var q2 = Funs.DB.Sys_User.FirstOrDefault(x => x.UserCode == model.UserCode && (x.UserId != model.UserId || (model.UserId == null && x.UserId != null)));
|
||
if (q2 != null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "输入的编号已存在。";
|
||
return responeData;
|
||
}
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(model.IdentityCard) && BLL.UserService.IsExistUserIdentityCard(model.UserId, model.IdentityCard) == true)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "输入的身份证号码已存在。";
|
||
return responeData;
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(model.DataSources))
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "项目id不能为空";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
//判断projectid是否有数据
|
||
var pmodel = Funs.DB.Base_Project.FirstOrDefault(x => x.ProjectId == model.DataSources);
|
||
if (pmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "该项目id未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
if (string.IsNullOrEmpty(model.UserId))
|
||
{
|
||
model.RawPassword = UserService.getInitialPassword(model.UnitId, model.IdentityCard); ;
|
||
model.Password = Funs.EncryptionPassword(model.RawPassword);
|
||
model.UserId = SQLHelper.GetNewID(typeof(Model.Sys_User));
|
||
UserService.AddUser(model);
|
||
|
||
Model.Project_ProjectUser newProjectUser = new Model.Project_ProjectUser
|
||
{
|
||
ProjectUserId = SQLHelper.GetNewID(typeof(Model.Project_ProjectUser)),
|
||
ProjectId = model.DataSources,
|
||
UserId = model.UserId,
|
||
UnitId = model.UnitId,
|
||
IsPost = true,
|
||
MainCNProfessionalId = model.MainCNProfessionalId,
|
||
ViceCNProfessionalId = model.ViceCNProfessionalId
|
||
};
|
||
|
||
newProjectUser.RoleId = "";
|
||
BLL.ProjectUserService.AddProjectUser(newProjectUser);
|
||
this.SetWorkPost(newProjectUser);
|
||
}
|
||
else {
|
||
//判断userid是否有数据
|
||
var umodel = Funs.DB.Sys_User.FirstOrDefault(x => x.UserId == model.UserId);
|
||
if (umodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "用户id(UserId)未查询到数据,无法修改,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
umodel.UserName = model.UserName;
|
||
umodel.UserCode = model.UserCode;
|
||
umodel.Account = model.Account;
|
||
umodel.UnitId = model.UnitId;
|
||
umodel.IdentityCard = model.IdentityCard;
|
||
umodel.Telephone = model.Telephone;
|
||
umodel.DataSources = model.DataSources;
|
||
UserService.UpdateUser(umodel);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
responeData.code = 0;
|
||
responeData.message = ex.Message;
|
||
}
|
||
return responeData;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新用户的项目岗位
|
||
/// </summary>
|
||
/// <param name="projectUser"></param>
|
||
private void SetWorkPost(Model.Project_ProjectUser projectUser)
|
||
{
|
||
var user = BLL.UserService.GetUserByUserId(projectUser.UserId);
|
||
if (user != null && !string.IsNullOrEmpty(user.IdentityCard))
|
||
{
|
||
var sitePerson = BLL.PersonService.GetPersonByIdentityCard(projectUser.ProjectId, user.IdentityCard);
|
||
if (sitePerson != null)
|
||
{
|
||
sitePerson.WorkPostId = null;
|
||
sitePerson.MainCNProfessionalId = projectUser.MainCNProfessionalId;
|
||
sitePerson.ViceCNProfessionalId = projectUser.ViceCNProfessionalId;
|
||
BLL.PersonService.UpdatePerson(sitePerson);
|
||
}
|
||
else
|
||
{
|
||
Model.SitePerson_Person newPerson = new Model.SitePerson_Person
|
||
{
|
||
PersonId = SQLHelper.GetNewID(typeof(Model.SitePerson_Person)),
|
||
PersonName = user.UserName,
|
||
Sex = user.Sex,
|
||
IdentityCard = user.IdentityCard,
|
||
ProjectId = projectUser.ProjectId,
|
||
UnitId = user.UnitId,
|
||
IsUsed = true,
|
||
MainCNProfessionalId = projectUser.MainCNProfessionalId,
|
||
ViceCNProfessionalId = projectUser.ViceCNProfessionalId,
|
||
};
|
||
newPerson.WorkPostId = null;
|
||
BLL.PersonService.AddPerson(newPerson);
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
} |