UpstreamSendUser.cs 3.27 KB
using Hh.Mes.Common;
using Hh.Mes.Common.config;
using Hh.Mes.Common.Json;
using Hh.Mes.Common.log;
using Hh.Mes.Pojo.System;
using Hh.Mes.POJO.ApiEntity;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.EnumEntitys;
using Hh.Mes.POJO.Request;
using Hh.Mes.POJO.Response;
using System;

namespace Hh.Mes.Service.ApiService
{
    public partial class UpstreamService
    {
        public dynamic SendUser(SysUserEntity requestData)
        {
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                //var reqData = DynamicJson.Parse(requestData); reqData.data
                SysUserEntity entity = requestData ;

                var response = new ResponseUpstream<string>(entity.plmeid);
                if (!typeValidation(entity.type, response).Status) return response;
                var user = new sys_user
                {
                    plmeid = entity.plmeid,
                    account = entity.code,
                    name = entity.name,
                    sex = entity.gender == "男" ? 1 : 0,
                    password = Encryption.Encrypt(ConfigRead.GetInstance.GetAppsetConnection().ResetPwd),

                    otherCode = entity.code,
                    phoneNumber = entity.tel,
                    remarks = entity.remarks,
                    status = AddOrUpdateFlag,
                };
                int resultCount = 0;
                if (entity.type == EnumAction.I.ToString())
                {
                    if (Context.Queryable<sys_user>().Any(t => t.plmeid == user.plmeid && t.status == 1&&t.account==user.account))
                    {
                        return response.ResponseError($"【上位系统】【name,plmeid】用户信息[{entity.name},{entity.plmeid}]已经存在,请勿重复添加!");
                    }
                    user.createTime = DateTime.Now;
                    resultCount=Context.Insertable(user).ExecuteCommand();
                    if (resultCount > 0)
                    {
                        //var deptId = Context.Queryable<sys_dept>().Select(x => x.id).First();
                        var deptId = ConfigRead.GetInstance.GetAppsetConnection().Extend1;
                        var userId = Context.Queryable<sys_user>().First(x => x.plmeid == user.plmeid && x.status == AddOrUpdateFlag).id;
                        var relevance = new sys_relevance
                        {
                            relKey = "UserOrg",
                            firstId = userId,
                            secondId = Convert.ToInt32(deptId),
                            createTime = DateTime.Now,
                            createBy = entity.code,
                        };
                        Context.Insertable(relevance).ExecuteCommand();
                    }
                }
                else if (entity.type == EnumAction.U.ToString())
                {
                    user.updateTime = DateTime.Now;
                    resultCount = Context.Updateable(user)
                    .IgnoreColumns(it => new { it.createBy, it.createTime })
                    .Where(x => x.plmeid == entity.plmeid && x.status == AddOrUpdateFlag).ExecuteCommand();
                }
                return resultCount > 0 ? response.ResponseSuccess() : response.ResponseError();
            });
        }
    }
}