CompetitionAPI_dotnet/CompetitionAPI/Controllers/back/system/EditUserController.cs

110 lines
4.3 KiB
C#

using Competition.Common.Util;
using CompetitionAPI.api.back;
using CompetitionAPI.Util;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace CompetitionAPI.Controllers.back.system
{
[Route("api/[controller]")]
[ApiController]
public class EditUserController : Controller
{
Competition.Mysql.BLL.admin_user user_bll = new Competition.Mysql.BLL.admin_user();
private static Object Lockobj = new object();
public EditUserController()
{
}
/// <summary>
/// 编辑用户接口
/// </summary>
/// <param name="req">请求参数</param>
/// <returns></returns>
[Authorize]
[HttpPost]
[APIFilter]
public JsonResult Index([FromBody] EditUserRequest req)
{
try
{
lock (Lockobj)
{
if (req != null)
{
if (string.IsNullOrWhiteSpace(req.RealName))
{
return Json(Tool.GetJsonWithCode(APICode.Fail, "姓名不能为空"));
}
if (string.IsNullOrWhiteSpace(req.PlayerCode))
{
return Json(Tool.GetJsonWithCode(APICode.Fail, "员工编码不能为空"));
}
if (req.PlayerCode.Length > 10)
{
return Json(Tool.GetJsonWithCode(APICode.Fail, "员工编码长度不能超过10个字符"));
}
if (string.IsNullOrWhiteSpace(req.Sex))
{
return Json(Tool.GetJsonWithCode(APICode.Fail, "性别不能为空"));
}
if (user_bll.GetRecordCount(string.Format(" login_name = '{0}' and user_id!='{1}' ", req.PlayerCode, req.UserId)) > 0)
{
return Json(Tool.GetJsonWithCode(APICode.Fail, "员工编码禁止重复"));
}
var model = user_bll.GetModel(req.UserId);
//所属市 姓名 ERP编码 性别 员工编码
model.OwnCity = req.OwnCity;
model.real_name = req.RealName;
model.ErpCode = req.ErpCode;
model.sex = req.Sex;
//工作单位 所在部门 工作岗位 身份证号 参加工作时间 文化程度 现有专业资格等级 现有职业技能等级 联系电话 备注
model.unit_name = req.UnitName;
model.dep_name = req.DepName;
model.GZGW = req.GZGW;
model.id_card = req.IdCard;
if (!string.IsNullOrEmpty(req.WorkDate))
{
model.WorkDate = DateTime.Parse(req.WorkDate);
}
model.Education = req.Education;
model.NowMajorGrade = req.NowMajorGrade;
model.NowJobGrade = req.NowJobGrade;
//联系电话 备注
model.mobile = req.Mobile;
model.r1 = req.Remark;
model.role_id = "2";
//账号
//model.create_time = DateTime.Now;
if (user_bll.Update(model))
{
return Json(Tool.GetJsonWithCode(APICode.Success, "编辑成功"));
}
else
{
return Json(Tool.GetJsonWithCode(APICode.Fail, "编辑失败"));
}
}
else
{
return Json(Tool.GetJsonWithCode(APICode.Fail, "请求参数不能为空"));
}
}
}
catch (Exception ex)
{
LogHelper.WriteLog(ex.Message + ",行号:" + ex.StackTrace);
return Json(Tool.GetJsonWithCode(APICode.Fail, "发生错误,请联系管理员。"));
}
}
}
}