UpstreamSendUser.cs 3.31 KB
using Hh.Mes.Common;
using Hh.Mes.Common.config;
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.Response;
using System;
using static Microsoft.AspNetCore.Hosting.Internal.HostingApplication;

namespace Hh.Mes.Service.ApiService
{
    public partial class UpstreamService
    {
        public dynamic SendUser(SysUserEntity entity)
        {
            var response = new ResponseUpstream<string>(entity.plmeid);
            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 = 1,
            };
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                int resultCount = 0;
                if (entity.type == EnumAction.I.ToString())
                {
                    if (Context.Queryable<sys_user>().Any(t => t.plmeid == user.plmeid && t.status == 1))
                    {
                        return response.ResponseError($"【上位系统】【name,plmeid】用户信息[{entity.name},{entity.plmeid}]已经存在,请勿重复添加!");
                    }
                    user.createTime = DateTime.Now;
                    Context.Insertable(user).AddQueue();

                    //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 == 1).id;
                    var relevance = new sys_relevance
                    {
                        relKey = "UserOrg",
                        firstId = userId,
                        secondId = Convert.ToInt32(deptId),
                        createTime = DateTime.Now,
                        createBy = entity.code,
                    };
                    Context.Insertable(relevance).AddQueue();
                    resultCount = ExecuteQueues(Context);
                }
                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 == 1).ExecuteCommand();
                }
                else if (entity.type == EnumAction.D.ToString())
                {
                    user.updateTime = DateTime.Now;
                    resultCount = Context.Updateable<sys_user>()
                                             .SetColumns(t => t.status == 0)
                                             .Where(x => x.plmeid == entity.plmeid && x.status == 1)
                                             .ExecuteCommand();
                }
                return resultCount > 0 ? response.ResponseSuccess() : response.ResponseError();
            });
        }
    }
}