254 lines
9.7 KiB
C#
254 lines
9.7 KiB
C#
using BLL;
|
|
using Model;
|
|
using Model.Customization._14HJ;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Web.Http;
|
|
|
|
namespace WebAPI.Controllers.Customization._14HJ
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class Api_14HJSyncController : ApiController
|
|
{
|
|
public Model.Customization._14HJ.ResponeData OrganizationSync([FromBody] IOrganizationitem data)
|
|
{
|
|
var responeData = new Model.Customization._14HJ.ResponeData();
|
|
|
|
#region 参数验证
|
|
if (string.IsNullOrEmpty(data.tenantCode))
|
|
{
|
|
responeData.code = "002-000-007";
|
|
responeData.msg = "tenantCode 不能为空";
|
|
responeData.data = "";
|
|
return responeData;
|
|
}
|
|
if (string.IsNullOrEmpty(data.parentCode))
|
|
{
|
|
responeData.code = "002-000-007";
|
|
responeData.msg = "parentCode 不能为空";
|
|
responeData.data = "";
|
|
return responeData;
|
|
}
|
|
if (string.IsNullOrEmpty(data.tenantName))
|
|
{
|
|
responeData.code = "002-000-007";
|
|
responeData.msg = "tenantName 不能为空";
|
|
responeData.data = "";
|
|
return responeData;
|
|
}
|
|
if (string.IsNullOrEmpty(data.nickName))
|
|
{
|
|
responeData.code = "002-000-007";
|
|
responeData.msg = "nickName 不能为空";
|
|
responeData.data = "";
|
|
return responeData;
|
|
}
|
|
if (string.IsNullOrEmpty(data.phone))
|
|
{
|
|
responeData.code = "002-000-007";
|
|
responeData.msg = "phone 不能为空";
|
|
responeData.data = "";
|
|
return responeData;
|
|
}
|
|
if (string.IsNullOrEmpty(data.userCode))
|
|
{
|
|
responeData.code = "002-000-007";
|
|
responeData.msg = "userCode 不能为空";
|
|
responeData.data = "";
|
|
return responeData;
|
|
}
|
|
if (string.IsNullOrEmpty(data.serialNo))
|
|
{
|
|
responeData.code = "002-000-007";
|
|
responeData.msg = "serialNo 不能为空";
|
|
responeData.data = "";
|
|
return responeData;
|
|
}
|
|
|
|
#endregion
|
|
try
|
|
{
|
|
string unitId = "";
|
|
var unit = BLL.UnitService.getUnitByUnitName(data.tenantName);
|
|
if (unit != null)
|
|
{
|
|
unitId = unit.UnitId;
|
|
unit.UnitCode = data.tenantCode;
|
|
unit.LinkName = data.nickName;
|
|
unit.LinkMobile = data.phone;
|
|
UnitService.UpdateUnit(unit);
|
|
|
|
}
|
|
else
|
|
{
|
|
Model.Base_Unit newuUnit = new Model.Base_Unit();
|
|
newuUnit.UnitId = SQLHelper.GetNewID();
|
|
newuUnit.UnitCode = data.tenantCode;
|
|
newuUnit.UnitName = data.tenantName;
|
|
newuUnit.LinkName = data.nickName;
|
|
newuUnit.LinkMobile = data.phone;
|
|
UnitService.AddUnit(newuUnit);
|
|
unitId = newuUnit.UnitId;
|
|
}
|
|
using (var db = new Model.SUBQHSEDB(Funs.ConnString))
|
|
{
|
|
|
|
|
|
var query = (from x in db.Sys_User
|
|
join y in db.Base_Unit on x.UnitId equals y.UnitId into unitJoin
|
|
from y in unitJoin.DefaultIfEmpty()
|
|
where y.UnitCode == data.tenantCode && x.UserName == data.nickName
|
|
select x).ToList();
|
|
int querycount = query.Count;
|
|
if (querycount > 1)
|
|
{
|
|
responeData.code = "002-000-007";
|
|
responeData.msg = " 姓名重复请手动修改";
|
|
responeData.data = "";
|
|
return responeData;
|
|
}
|
|
Sys_User newUser;
|
|
switch (querycount)
|
|
{
|
|
case 0:
|
|
newUser = new Sys_User();
|
|
newUser.UserId = SQLHelper.GetNewID();
|
|
newUser.UserName = data.nickName;
|
|
newUser.UserCode = data.userCode;
|
|
newUser.Account = data.phone;
|
|
newUser.Password = Funs.EncryptionPassword(Const.Password);
|
|
newUser.UnitId = unitId;
|
|
UserService.AddUser(newUser);
|
|
break;
|
|
case 1:
|
|
newUser = query.First();
|
|
newUser.UserCode = data.userCode;
|
|
UserService.UpdateUser(newUser);
|
|
break;
|
|
}
|
|
DetailData detailData = new Model.Customization._14HJ.DetailData
|
|
{
|
|
status = 1
|
|
};
|
|
|
|
responeData.code = "0";
|
|
responeData.msg = "成功";
|
|
responeData.data = detailData;
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
responeData.code = "001-000-001";
|
|
responeData.msg = ex.Message;
|
|
}
|
|
return responeData;
|
|
}
|
|
|
|
public Model.Customization._14HJ.ResponeData UserSync([FromBody] IUserItem data)
|
|
{
|
|
var responeData = new Model.Customization._14HJ.ResponeData();
|
|
#region 参数验证
|
|
if (string.IsNullOrEmpty(data.tenantCode))
|
|
{
|
|
responeData.code = "002-000-007";
|
|
responeData.msg = "tenantCode 不能为空";
|
|
responeData.data = "";
|
|
return responeData;
|
|
}
|
|
if (string.IsNullOrEmpty(data.nickName))
|
|
{
|
|
responeData.code = "002-000-007";
|
|
responeData.msg = "nickName 不能为空";
|
|
responeData.data = "";
|
|
return responeData;
|
|
}
|
|
if (string.IsNullOrEmpty(data.phone))
|
|
{
|
|
responeData.code = "002-000-007";
|
|
responeData.msg = "phone 不能为空";
|
|
responeData.data = "";
|
|
return responeData;
|
|
}
|
|
if (string.IsNullOrEmpty(data.userCode))
|
|
{
|
|
responeData.code = "002-000-007";
|
|
responeData.msg = "userCode 不能为空";
|
|
responeData.data = "";
|
|
return responeData;
|
|
}
|
|
if (string.IsNullOrEmpty(data.serialNo))
|
|
{
|
|
responeData.code = "002-000-007";
|
|
responeData.msg = "serialNo 不能为空";
|
|
responeData.data = "";
|
|
return responeData;
|
|
}
|
|
|
|
#endregion
|
|
try
|
|
{
|
|
using (var db = new Model.SUBQHSEDB(Funs.ConnString))
|
|
{
|
|
var unit = (from x in db.Base_Unit where x.UnitCode == data.tenantCode select x).FirstOrDefault();
|
|
if (unit==null)
|
|
{
|
|
responeData.code = "002-000-007";
|
|
responeData.msg = " 用户组织机构不存在";
|
|
responeData.data = "";
|
|
return responeData;
|
|
}
|
|
var query =( from x in db.Sys_User
|
|
join y in db.Base_Unit on x.UnitId equals y.UnitId into unitJoin
|
|
from y in unitJoin.DefaultIfEmpty()
|
|
where y.UnitCode == data.tenantCode && x.UserName == data.nickName
|
|
select x).ToList();
|
|
int querycount = query.Count;
|
|
if (querycount> 1)
|
|
{
|
|
responeData.code = "002-000-007";
|
|
responeData.msg = " 姓名重复请手动修改";
|
|
responeData.data = "";
|
|
return responeData;
|
|
}
|
|
Sys_User newUser;
|
|
switch (querycount)
|
|
{
|
|
case 0:
|
|
newUser = new Sys_User();
|
|
newUser.UserId = SQLHelper.GetNewID();
|
|
newUser.UserName = data.nickName;
|
|
newUser.UserCode = data.userCode;
|
|
newUser.Account = data.phone;
|
|
newUser.Password = Funs.EncryptionPassword(Const.Password);
|
|
newUser.UnitId = unit.UnitId;
|
|
UserService.AddUser(newUser);
|
|
break;
|
|
case 1:
|
|
newUser = query.First();
|
|
newUser.UserCode = data.userCode;
|
|
UserService.UpdateUser(newUser);
|
|
break;
|
|
}
|
|
DetailData detailData = new Model.Customization._14HJ.DetailData
|
|
{
|
|
status = 1
|
|
};
|
|
responeData.code = "0";
|
|
responeData.msg = "成功";
|
|
responeData.data = detailData;
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
responeData.code = "001-000-001";
|
|
responeData.msg = ex.Message;
|
|
}
|
|
return responeData;
|
|
}
|
|
|
|
}
|
|
} |