qwj
2023-08-24 6614d9f16c1012b8a9f2ba94b8a15bd1356e8adb
Merge branch 'master' of http://47.108.235.38:8080/r/DocumentService
12个文件已修改
7个文件已添加
874 ■■■■ 已修改文件
.gitignore 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceAPI.Application/DocumentServiceAPI.Application.xml 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceAPI.Application/UserAndLogin/LogInController.cs 236 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceAPI.Application/UserAndLogin/Services/TokenService.cs 66 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceAPI.Application/UserAndLogin/ViewMode/UserInfo.cs 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceAPI.Application/applicationsettings.json 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceAPI.Model/Oder/Oder.cs 50 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceAPI.Model/Permissions/TenantPermissions.cs 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceAPI.Model/UserInfoModel/TenantInfo.cs 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceAPI.Web.Entry/AuthorizeHandler.cs 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceAPI.Web.Entry/appsettings.json 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceAPI.sln 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceApi.InitQMessage/DocumentServiceApi.InitQMessage.csproj 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceApi.InitQMessage/INITQMessageDefine.cs 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceApi.InitQMessage/INITQSetups.cs 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceApi.InitQMessage/MessageReceive.cs 181 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceApi.InitQMessage/TenantOderInfo.cs 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ZcPayCore/Model/OderInfo.cs 55 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ZcPayCore/ZcPayCore.csproj 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.gitignore
@@ -29,3 +29,5 @@
/DocumentFile.Service/obj
/DocumentServiceAPI.Services/bin
/DocumentServiceAPI.Services/obj
ZcPayCore/obj/
DocumentServiceApi.InitQMessage/obj/
DocumentServiceAPI.Application/DocumentServiceAPI.Application.xml
@@ -970,6 +970,7 @@
        <member name="M:DocumentServiceAPI.Application.UserAndLogin.LogInController.LogoIn(DocumentServiceAPI.Application.UserAndLogin.ViewMode.LoginPsWordIN)">
            <summary>
            登录 1 输入员工账户或者租户账户,2 选择租户账户,3 选择公司
            当密码为空时,带入用户中心token即可实现登录
            </summary>
            <returns>登录信息</returns>
        </member>
@@ -999,6 +1000,15 @@
            <summary>
            新建一个TOken 
            </summary>
            <returns></returns>
        </member>
        <member name="M:DocumentServiceAPI.Application.UserAndLogin.Services.TokenService.CheckJwt(System.String,Microsoft.IdentityModel.Tokens.SecurityToken@)">
            <summary>
            校验token 的有效性
            </summary>
            <param name="Token"> Token校验</param>
            <param name="validationParameters"></param>
            <param name="securityToken"></param>
            <returns></returns>
        </member>
        <member name="M:DocumentServiceAPI.Application.UserAndLogin.Services.TokenService.CheckToken">
@@ -1339,8 +1349,8 @@
        </member>
        <member name="P:DocumentServiceAPI.Application.UserAndLogin.ViewMode.EmployeeInfoVM.UserName">
            <summary>
            用户名
            </summary>
            用户名 手机号验证 必填
            </summary>
        </member>
        <member name="P:DocumentServiceAPI.Application.UserAndLogin.ViewMode.EmployeeInfoVM.UserPassWord">
            <summary>
DocumentServiceAPI.Application/UserAndLogin/LogInController.cs
@@ -3,9 +3,14 @@
using DocumentServiceAPI.Utility;
using Furion.DynamicApiController;
using Furion.JsonSerialization;
using Microsoft.AspNetCore.Http;
using Microsoft.IdentityModel.Tokens;
using NetTaste;
using Newtonsoft.Json.Linq;
using Swashbuckle.AspNetCore.Annotations;
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -28,133 +33,172 @@
         }
        /// <summary>
        /// 登录 1 输入员工账户或者租户账户,2 选择租户账户,3 选择公司
        /// 当密码为空时,带入用户中心token即可实现登录
        /// </summary>
        /// <returns>登录信息</returns>
        [HttpPost("LogoIn")]
        public async Task<RetLoginVM> LogoIn (LoginPsWordIN Parma)
        public async Task<RetLoginVM> LogoIn (  LoginPsWordIN Parma)
        {
              bool needtoken=false;
            if (Parma.TenantId==null)
            //zctok校验成功是否标志
            bool IsTokenPass=false;
               if(string.IsNullOrEmpty(Parma.PassWord))
            {
                //如果还没确定租户ID 需要先确定租户ID
                List<TenderVM>Tender = await _userService.GetUserTenderList(Parma.ITCode);
                switch (Tender.Count)
                var Request = App.HttpContext.Request;
                string stoken = Request.Headers["Authorization"];
                if (stoken == null)
                    throw Oops.Oh("没有输入密码");
                stoken = stoken.Replace("Bearer ", "");
                var isvale = _tokenService.CheckJwt(stoken, out SecurityToken securityToken);
                JwtSecurityToken jwtToken = securityToken as JwtSecurityToken;
                string itcode = jwtToken.Claims.FirstOrDefault(claim => claim.Type == "sub")?.Value;
                if (isvale == false)
                    throw Oops.Oh("登录信息出错");
                if(Parma.ITCode!= itcode)
                    throw Oops.Oh("用户名错误");
                IsTokenPass=true;
            }
                bool needtoken = false;
                if (Parma.TenantId == null)
                {
                    case 0:
                        throw Oops.Oh($"账户或者密码错误");
                    case 1:
                         needtoken = await _userService.CheckPsw(Tender[0].TenderId, Tender[0].EmployeeID,Parma.PassWord);
                        if(!needtoken)
                    //如果还没确定租户ID 需要先确定租户ID
                    List<TenderVM> Tender = await _userService.GetUserTenderList(Parma.ITCode);
                    switch (Tender.Count)
                    {
                        case 0:
                            throw Oops.Oh($"账户或者密码错误");
                        Parma.TenantId = Tender[0].TenderId;
                        Parma.employeeID = Tender[0].EmployeeID;
                        if (Parma.UnitID == null)
                        case 1:
                        if (!needtoken)
                        {
                            List<UnitVM> Units = await _userService.GetUserUnitList(Parma.TenantId ?? 0);
                            if (Units.Count == 0)
                            {
                                //没有公司
                                needtoken = true;
                            }
                            else if (Units.Count == 1)
                            {
                                Parma.UnitID = Units[0].UnitID;
                                needtoken = true;
                            }
                            else
                            {
                                //其他需要用户选择租户
                                return new RetLoginVM
                                {
                                    NeedNext = true,
                                    Units = Units,
                            needtoken = await _userService.CheckPsw(Tender[0].TenderId, Tender[0].EmployeeID, Parma.PassWord);
                                };
                            }
                            if (!needtoken)
                                throw Oops.Oh($"账户或者密码错误");
                        }
                        break;
                    default:
                            Parma.TenantId = Tender[0].TenderId;
                            Parma.employeeID = Tender[0].EmployeeID;
                            if (Parma.UnitID == null)
                            {
                                List<UnitVM> Units = await _userService.GetUserUnitList(Parma.TenantId ?? 0);
                                if (Units.Count == 0)
                                {
                                    //没有公司
                                    needtoken = true;
                                }
                                else if (Units.Count == 1)
                                {
                                    Parma.UnitID = Units[0].UnitID;
                                    needtoken = true;
                                }
                                else
                                {
                                    //其他需要用户选择租户
                                    return new RetLoginVM
                                    {
                                        NeedNext = true,
                                        Units = Units,
                                    };
                                }
                            }
                            break;
                        default:
                            //其他需要用户选择租户
                            return new RetLoginVM
                            {
                                NeedNext = true,
                                Tenants = Tender,
                            };
                    }
                }
                else if (Parma.UnitID == null)
                {
                    var Units = await _userService.GetUserUnitList(Parma.TenantId ?? 0);
                    if (Units.Count == 0)
                    {
                        //没有公司
                        needtoken = true;
                    }
                    else if (Units.Count == 1) {
                        Parma.UnitID = Units[0].UnitID;
                        needtoken = true;
                    }
                    else
                    {
                        //其他需要用户选择租户
                        return new RetLoginVM
                        {
                            NeedNext = true,
                            Tenants = Tender,
                            Units = Units,
                        };
                    }
                }
            }
            else if(Parma.UnitID==null)
            {
                var Units = await _userService.GetUserUnitList(Parma.TenantId??0);
                if(Units.Count==0)
                if (needtoken || Parma.UnitID != null)
                {
                    //没有公司
                    needtoken = true;
                }
                else if (Units.Count==1) {
                    Parma.UnitID= Units[0].UnitID;
                    needtoken = true;
                }
                else
                    TenderVM Tender = (await _userService.GetUserTenderList(Parma.ITCode)).Where(x => x.TenderId == Parma.TenantId && x.EmployeeID == Parma.employeeID).SingleOrDefault();
                    if (Tender == null)
                    {
                        throw Oops.Oh($"账户密码或者租户选择错误");
                    }
                if (!IsTokenPass)
                {
                    //其他需要用户选择租户
                    needtoken = await _userService.CheckPsw(Tender.TenderId, Tender.EmployeeID, Parma.PassWord);
                    if (!needtoken)
                        throw Oops.Oh($"账户或者密码错误");
                }
                    var token = _tokenService.CreateToken(new Model.JwtInfo
                    {
                        EID = Tender.EmployeeID,
                        LogInSource = Parma.Form,
                        TEID = Tender.TenderId,
                        UID = Parma.UnitID,
                    });
                    return new RetLoginVM
                    {
                        NeedNext = true,
                       Units = Units,
                        NeedNext = false,
                        Token = token,
                    };
                }
            }
            if(needtoken|| Parma.UnitID!=null)
            {
                TenderVM Tender = (await _userService.GetUserTenderList(Parma.ITCode)).Where(x=>x.TenderId==Parma.TenantId&&x.EmployeeID==Parma.employeeID).SingleOrDefault();
                if(Tender==null)
                {
                    throw Oops.Oh($"账户密码或者租户选择错误");
                }
                needtoken = await _userService.CheckPsw(Tender. TenderId, Tender.EmployeeID, Parma.PassWord);
                if (!needtoken)
                    throw Oops.Oh($"账户或者密码错误");
              var token=  _tokenService.CreateToken(new Model.JwtInfo
                {
                    EID = Tender.EmployeeID,
                    LogInSource = Parma.Form,
                    TEID = Tender.TenderId,
                    UID = Parma.UnitID,
                });
                return new RetLoginVM
                {
                    NeedNext = false,
                   Token = token,
                };
            }
            throw Oops.Oh($"参数错误");
                throw Oops.Oh($"参数错误");
        }
        /// <summary>
        /// 获取公司列表
DocumentServiceAPI.Application/UserAndLogin/Services/TokenService.cs
@@ -3,10 +3,13 @@
using Furion.Authorization;
using Furion.DistributedIDGenerator;
using Furion.JsonSerialization;
using Furion.Logging.Extensions;
using Microsoft.IdentityModel.Tokens;
using NetTaste;
using SqlSugar.Extensions;
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Reflection;
using System.Security.Claims;
@@ -18,7 +21,7 @@
    /// <summary>
    /// token服务类
    /// </summary>
    public  class TokenService: IScoped
    public class TokenService : IScoped
    {
        /// <summary>
        /// Token是啥
@@ -27,7 +30,7 @@
        private ISqlSugarClient _db;
        private UserService _UserService;
        private IRedisCacheService _RedisCase;
        public TokenService(ISqlSugarClient db, UserService  UserInfoService, IRedisCacheService RedisCase ) {
        public TokenService(ISqlSugarClient db, UserService UserInfoService, IRedisCacheService RedisCase) {
            _db = db;
            _UserService = UserInfoService;
            _RedisCase = RedisCase;
@@ -36,9 +39,9 @@
        /// 新建一个TOken 
        /// </summary>
        /// <returns></returns>
        public string  CreateToken(JwtInfo jwt)
        public string CreateToken(JwtInfo jwt)
        {
            string TokenKey=TokenKeys+ getTokenKey(jwt);
            string TokenKey = TokenKeys + getTokenKey(jwt);
            IDictionary<string, object> propertyDictionary = new Dictionary<string, object>();
            PropertyInfo[] properties = jwt.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
@@ -51,14 +54,57 @@
                propertyDictionary.Add(propertyName.ToLower(), propertyValue);
            }
            var ID = IDGen.NextID();
             jwt.JID = ID;
         var token=   JWTEncryption.Encrypt(propertyDictionary, App.GetConfig<JWTSettingsOptions>("JWTSettings").ExpiredTime ?? 3600);
            if(jwt.LogInSource==LogInFrom.PC)
            _RedisCase.Add<string>(TokenKey, ID.ToString(), expireSeconds: (int )(App.GetConfig<JWTSettingsOptions>("JWTSettings").ExpiredTime??3600));
            jwt.JID = ID;
            var token = JWTEncryption.Encrypt(propertyDictionary, App.GetConfig<JWTSettingsOptions>("JWTSettings").ExpiredTime ?? 3600);
            if (jwt.LogInSource == LogInFrom.PC)
                _RedisCase.Add<string>(TokenKey, ID.ToString(), expireSeconds: (int)(App.GetConfig<JWTSettingsOptions>("JWTSettings").ExpiredTime ?? 3600));
            return token;
        }
        /// <summary>
        /// 校验token 的有效性
        /// </summary>
        /// <param name="Token"> Token校验</param>
        /// <param name="validationParameters"></param>
        /// <param name="securityToken"></param>
        /// <returns></returns>
        public bool  CheckJwt(string Token, out SecurityToken?  securityToken)
        {
            var configuration = App.Configuration;
         //   var value = configuration["xxx:xxx"];
            string secretKey = configuration["ZCUserInfoJwtOP:SecurityKey"];
            if (secretKey == null)
            {
                "没有配置用户中心的安全秘钥 ZCUserInfoJwtOP:SecurityKey 找不到".LogInformation<TokenService>();
              throw  Oops.Oh("配置错误,联系管理员");
            }
            JwtSecurityTokenHandler tokenHandler = new JwtSecurityTokenHandler();
            //JwtSecurityToken jwt = tokenHandler.ReadJwtToken(Token);
            // 验证 JWT 签名并检查有效期
            TokenValidationParameters validationParameters = new TokenValidationParameters
            {
                ValidateIssuerSigningKey = true,
                IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(secretKey)),
                ValidateIssuer = false,
                ValidateAudience = false,
                ClockSkew = TimeSpan.Zero // 禁用时间偏移量
            };
            try
            {
                ClaimsPrincipal claimsPrincipal = tokenHandler.ValidateToken(Token, validationParameters, out SecurityToken validatedToken);
                securityToken = validatedToken;
                return true;
            }
            catch (SecurityTokenException)
            {
                securityToken=null;
                return false;
            }
        }
        /// <summary>
@@ -91,6 +137,10 @@
            string TokenKey = TokenKeys + jwt.EID?.ToString() + jwt.UID?.ToString()  + jwt.TEID?.ToString();
            return TokenKey;
        }
    }
   
}
DocumentServiceAPI.Application/UserAndLogin/ViewMode/UserInfo.cs
@@ -130,8 +130,10 @@
        /// </summary>           
        public string LastUpdateName { get; set; }
        /// <summary>
        /// 用户名
        /// </summary>
        /// 用户名 手机号验证 必填
        /// </summary>
        [Required]
        [RegularExpression("/^(?:(?:\\+|00)86)?1\\d{10}$/")]
        public string UserName { get; set; }
        /// <summary>
        /// 用户密码
DocumentServiceAPI.Application/applicationsettings.json
@@ -46,12 +46,25 @@
      "KeepVerb": true,//保持版本号一致
      "LowercaseRoute": false
    },
  "CorsAccessorSettings": {
    "WithExposedHeaders": [
      "access-token",
      "x-access-token",
      "environment"
    ]
  },
  "ZCUserInfoJwtOP": { //zc用户中心jwt配置 用于解析zc的token
      "Issuer": "http://zc",
      "Audience": "http://zc",
      "Expires": 86400,
      "weixinExpires": 1296000, // 86400,
      "SecurityKey": "superSecretKey@345",
      "RefreshTokenExpires": 86400,
      "LoginPath": "/_Framework/Redirect401"
  }
}
DocumentServiceAPI.Model/Oder/Oder.cs
@@ -1,6 +1,8 @@
using DocumentServiceAPI.Enum;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -12,6 +14,54 @@
    /// </summary>
    public class Oder:BaseModel
    {
        /// <summary>
        /// OderID
        /// </summary>
        [SugarColumn( IsPrimaryKey =true,IsIdentity =true)]
        public int Id { get; set; }
        /// <summary>
        /// 月份
        /// </summary>
        [Display(Name = "月份")]
        public int? MonthCount { get; set; }
        /// <summary>
        /// 单位个数
        /// </summary>
        [Display(Name = "单位个数")]
        public int? UnitCount { get; set; }
        /// <summary>
        /// 员工
        /// </summary>
        [Display(Name = "员工个数")]
        public int? EmployeeCount { get; set; }
        /// <summary>
        /// 单价
        /// </summary>
        [Display(Name = "金额")]
        public decimal Amount { get; set; }
       /// <summary>
       /// 支付方式
       /// </summary>
        public string? PayType { get; set; }
        /// <summary>
        /// 支付时间
        /// </summary>
        public DateTime? PayTime { get; set; }
        /// <summary>
        /// 描述
        /// </summary>
        public string? Description { get; set; }
        /// <summary>
        /// 手机号码
        /// </summary>
        public string ITCode { get; set; }
        /// <summary>
        /// 政采用户中心ID
        /// </summary>
        public Guid? ZcUserID { get; set; }
    }
DocumentServiceAPI.Model/Permissions/TenantPermissions.cs
@@ -1,6 +1,8 @@
using DocumentServiceAPI.Enum;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -10,8 +12,50 @@
    /// <summary>
    /// 租户权限
    /// </summary>
    public class TenantPermissions
    public class TenantPermissions: BaseModel
    {
        /// <summary>
        /// id
        /// </summary>
        [Display(Name = "id ")]
        [SugarColumn(ColumnDescription = "id " ,IsPrimaryKey =true,IsIdentity =true)]
        public int Id { get; set; }
        /// <summary>
        /// 租户ID
        /// </summary>
        [Display(Name = "租户ID ")]
        [SugarColumn(ColumnDescription = "租户ID ")]
        public int TenantId { get; set; }
        /// <summary>
        /// 最大企业个数
        /// </summary>
        [Display(Name = "最大企业个数 ")]
        [SugarColumn(ColumnDescription = "最大企业个数 ")]
        public int UnitMaxCount { get; set; }
        /// <summary>
        /// 最大员工数量
        /// </summary>
        [Display(Name = "最大员工数量 ")]
        [SugarColumn(ColumnDescription = "最大员工数量 ")]
        public int EmployeeMaxCount { get; set; }
        /// <summary>
        /// 到期时间
        /// </summary>
        [Display(Name = "到期时间 ")]
        [SugarColumn(ColumnDescription = "到期时间 ")]
        public DateTime OverTime { get; set; }
        /// <summary>
        /// 描述
        /// </summary>
        [Display(Name = "描述 ")]
        [SugarColumn(ColumnDescription = "描述 ")]
        public string? Description { get; set; }
    }
}
DocumentServiceAPI.Model/UserInfoModel/TenantInfo.cs
@@ -68,7 +68,12 @@
        /// 密码
        /// </summary>
        [SugarColumn(Length =30)]
        public string? PsW { get; set; }
        public string? PsW { get; set; }
        /// <summary>
        /// 政采用户中心ID
        /// </summary>
        public Guid? ZcUserID { get; set; }
    }
DocumentServiceAPI.Web.Entry/AuthorizeHandler.cs
@@ -1,4 +1,5 @@
using Furion.Authorization;
using Furion.DataEncryption;
using Microsoft.AspNetCore.Authorization;
namespace DocumentServiceAPI.Web.Entry
@@ -8,6 +9,7 @@
    /// </summary>
    public class AuthorizeHandler:AppAuthorizeHandler
    {
        /// <summary>
        /// 请求管道
        /// </summary>
@@ -17,7 +19,7 @@
        public override Task<bool> PipelineAsync(AuthorizationHandlerContext context, DefaultHttpContext httpContext)
        {
            // 此处已经自动验证 Jwt token的有效性了,无需手动验证
            // 检查权限,如果方法是异步的就不用 Task.FromResult 包裹,直接使用 async/await 即可
            return Task.FromResult(CheckAuthorzie(httpContext));
        }
DocumentServiceAPI.Web.Entry/appsettings.json
@@ -12,7 +12,8 @@
    {
      "ConfigId": "default", //多库配置ID
      "ConnectionString": "Server=.;Database=doc_new;User ID=sa;Password=123456;",
      //"ConnectionString": "Server=.;Database=doc_new;User ID=sa;Password=123456;",
      "ConnectionString": "Server=localhost\\SQLEXPRESS;Database=CY_DocumentSystemOnline;User ID=sa;Password=123456;",
      "DbType": "SqlServer",
      "IsAutoCloseConnection": true
@@ -20,7 +21,7 @@
    }
  ],
  "isCodeFirst": false, //是否执行codefirst 注意这个在迁徙完成后应该设置为false 防止更改数据库
  "isCodeFirst": true, //是否执行codefirst 注意这个在迁徙完成后应该设置为false 防止更改数据库
  //请保持redis为正常可用
  "RedisConfig": {
    // 如果采用容器化部署Service 要写成redis的服务名,否则写地址
@@ -28,7 +29,12 @@
  },
  //消息队列配置 为了独立部署,这里单独配置
  "InitQRedisConfig": {
    // 如果采用容器化部署Service 要写成redis的服务名,否则写地址
    "ConnectionString": "127.0.0.1:6379,password=,connectTimeout=30000,responseTimeout=30000,abortConnect=false,connectRetry=1,syncTimeout=10000,DefaultDatabase=10" //redis数据库连接字符串
  },
  "JWTSettings": {
DocumentServiceAPI.sln
@@ -21,6 +21,10 @@
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DocumentServiceAPI.Services", "DocumentServiceAPI.Services\DocumentServiceAPI.Services.csproj", "{3369F102-ABB2-42A4-B216-58D530AEE8BE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ZcPayCore", "ZcPayCore\ZcPayCore.csproj", "{76BFAB65-B7AC-4534-A595-363551111129}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocumentServiceApi.InitQMessage", "DocumentServiceApi.InitQMessage\DocumentServiceApi.InitQMessage.csproj", "{0A75ECEE-91C9-4A87-8573-4298DF0B6CDE}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
@@ -62,6 +66,14 @@
        {3369F102-ABB2-42A4-B216-58D530AEE8BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {3369F102-ABB2-42A4-B216-58D530AEE8BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {3369F102-ABB2-42A4-B216-58D530AEE8BE}.Release|Any CPU.Build.0 = Release|Any CPU
        {76BFAB65-B7AC-4534-A595-363551111129}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {76BFAB65-B7AC-4534-A595-363551111129}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {76BFAB65-B7AC-4534-A595-363551111129}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {76BFAB65-B7AC-4534-A595-363551111129}.Release|Any CPU.Build.0 = Release|Any CPU
        {0A75ECEE-91C9-4A87-8573-4298DF0B6CDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {0A75ECEE-91C9-4A87-8573-4298DF0B6CDE}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {0A75ECEE-91C9-4A87-8573-4298DF0B6CDE}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {0A75ECEE-91C9-4A87-8573-4298DF0B6CDE}.Release|Any CPU.Build.0 = Release|Any CPU
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
DocumentServiceApi.InitQMessage/DocumentServiceApi.InitQMessage.csproj
New file
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="InitQ" Version="1.0.0.15" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\DocumentServiceAPI.Core\DocumentServiceAPI.Core.csproj" />
    <ProjectReference Include="..\DocumentServiceAPI.Model\DocumentServiceAPI.Model.csproj" />
  </ItemGroup>
</Project>
DocumentServiceApi.InitQMessage/INITQMessageDefine.cs
New file
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DocumentServiceApi.InitQMessage
{
    /// <summary>
    /// 消息结构定义
    /// </summary>
    public static class INITQMessageDefine
    {
        /// <summary>
        /// 购入Oder消息
        /// </summary>
        public const string InitTenantOder = "DocumentServiceAPI_OderINIT";
        /// <summary>
        /// 撤单
        /// </summary>
        public const string DecTenantOder = "DocumentServiceAPI_DecOderINIT";
    }
}
DocumentServiceApi.InitQMessage/INITQSetups.cs
New file
@@ -0,0 +1,48 @@
using CSRedis;
using Furion;
using InitQ;
using Mapster;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace DocumentServiceApi.InitQMessage
{
    /// <summary>
    /// 注册 INITQ
    /// </summary>
    public class DocServiceApiStartup : AppStartup
    {
        public void ConfigureServices(IServiceCollection services)        {
            var readisconnectionstring = App.Configuration["InitQRedisConfig:ConnectionString"];
            if (readisconnectionstring != null)
            //初始化redi配置
            {
                services.AddInitQ((op) =>
                {
                    op.SuspendTime = 500;
                    op.IntervalTime = 500;
                    op.ConnectionString = readisconnectionstring;
                    op.ListSubscribe = new List<Type>() { typeof(MessageReceive) };
                    op.ShowLog = false;
                });
            }
        }
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
        }
    }
}
DocumentServiceApi.InitQMessage/MessageReceive.cs
New file
@@ -0,0 +1,181 @@
using DocumentServiceAPI.Model.Oder;
using DocumentServiceAPI.Model.Permissions;
using DocumentServiceAPI.Model.UserInfoModel;
using Furion;
using Furion.JsonSerialization;
using Furion.Logging.Extensions;
using InitQ.Abstractions;
using InitQ.Attributes;
using Microsoft.Extensions.Options;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DocumentServiceApi.InitQMessage
{
    /// <summary>
    /// 消息接收处理函数
    /// </summary>
    public class MessageReceive: IRedisSubscribe
    {
        /// <summary>
        /// 初始化订单处理
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        [Subscribe(INITQMessageDefine.InitTenantOder)]
        private async Task InitTenantOder(string msg)
        {
            TenantOderInfo? obj = JSON.Deserialize<TenantOderInfo>(msg);
            if(obj==null)
            {
                $"InitTenantOder 初始化 msg 对象错误 ,msg为{msg}".LogInformation<MessageReceive>();
                return;
            }
            var    _db=  App.GetService<ISqlSugarClient>();
            Oder oder = new Oder()
            {
                Amount = obj.Amount,
                CreatBy = "消息队列 InitTenantOder",
                CreatTime = DateTime.Now,
                Description = obj.Description,
                EmployeeCount = obj.EmployeeCount,
                MonthCount = obj.MonthCount,
                UnitCount = obj.UnitCount,
                PayType = obj.PayType,
                PayTime = obj.PayTime,
                ZcUserID = obj.ZcUserID,
                ITCode = obj.ITCode,
            };
            TenantInfo? Tinfo = await _db.Queryable<TenantInfo>().Where(x=>x.ZcUserID==obj.ZcUserID).SingleAsync();
            if(Tinfo==null)
            {
                Tinfo = new TenantInfo
                {
                    ZcUserID = obj.ZcUserID,
                    ItCode = obj.ITCode,
                    CreatBy = "消息队列 InitTenantOder",
                    CreatTime = DateTime.Now,
                    Description = obj.Description,
                    Name = obj.ITCode,
                    PsW = obj.ITCode.Substring(obj.ITCode.Length - 4),
                };
                TenantPermissions permissions = new TenantPermissions()
                {
                    CreatBy = "消息队列 InitTenantOder",
                    CreatTime = DateTime.Now,
                    Description = obj.Description,
                    EmployeeMaxCount = obj.EmployeeCount ?? 0,
                    UnitMaxCount = obj.UnitCount ?? 0,
                    OverTime = DateTime.Now.AddMonths(obj.MonthCount ?? 0),
                };
                try
                {
                    await _db.AsTenant().BeginTranAsync();
                  var id=  await _db.Insertable(Tinfo).ExecuteReturnIdentityAsync();
                    permissions.TenantId = id;
                    await _db.Insertable(permissions).ExecuteCommandAsync ();
                    await _db.Insertable(oder).ExecuteCommandAsync();
                    await _db.AsTenant().CommitTranAsync();
                }
                catch (Exception e)
                {
                    await _db.AsTenant().RollbackTranAsync();
                    $"新建租户处理失败 msg:{msg},e:{e.ToString()} BY:消息队列 InitTenantOder".LogInformation<MessageReceive>();
                    return;
                }
            }
            else
            {
                Tinfo.ItCode = obj.ITCode;
                Tinfo.UpdataBy = "消息队列 InitTenantOder";
                Tinfo.UpdataTime = DateTime.Now;
                Tinfo.IsDel = false;
                Tinfo.IsEn = true;
              var tp= await _db.Queryable<TenantPermissions>().Where(x=>x.TenantId==Tinfo.Id).FirstAsync();
                try
                {
                    await _db.AsTenant().BeginTranAsync();
                    if (Tinfo.ItCode != obj.ITCode)
                    {
                       await _db.Updateable(Tinfo).ExecuteCommandAsync();
                    };
                    if (tp == null)
                    {
                        tp = new TenantPermissions()
                        {
                            CreatBy = "消息队列 InitTenantOder",
                             CreatTime = DateTime.Now,
                              IsDel = false,
                               IsEn = true,
                                EmployeeMaxCount=obj.EmployeeCount??0,
                                 UnitMaxCount=obj.UnitCount??0,
                                  OverTime=DateTime.Now.AddMinutes(obj.MonthCount??0),
                                   TenantId= Tinfo.Id,
                        };
                        await _db.Insertable(tp).ExecuteCommandAsync();
                    }
                    else
                    {
                        tp.IsDel = false;
                        tp.IsEn = true;
                        tp.UnitMaxCount = obj.UnitCount ?? tp.UnitMaxCount;
                        tp.EmployeeMaxCount = obj.EmployeeCount ?? tp.EmployeeMaxCount;
                        tp.OverTime = tp.OverTime.AddMonths(obj.MonthCount??0);
                        tp.UpdataBy = "消息队列 InitTenantOder";
                        tp.UpdataTime = DateTime.Now;
                        await _db.Updateable(tp).ExecuteCommandAsync();
                    }
                    await _db.Insertable(oder).ExecuteCommandAsync();
                    await _db.AsTenant().CommitTranAsync();
                }
                catch (Exception e)
                {
                    await _db.AsTenant().RollbackTranAsync();
                    $"修改租户权限失败 msg:{msg},e:{e.ToString()}  By:消息队列 InitTenantOder".LogInformation<MessageReceive>();
                    return;
                }
            }
        }
    }
}
DocumentServiceApi.InitQMessage/TenantOderInfo.cs
New file
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DocumentServiceApi.InitQMessage
{
    /// <summary>
    /// 订单消息模型详情
    /// </summary>
    internal class TenantOderInfo
    {
        /// <summary>
        /// 手机号码
        /// </summary>
        public string ITCode { get; set; }
        /// <summary>
        /// 政采用户中心ID
        /// </summary>
        public Guid? ZcUserID { get; set; }
        /// <summary>
        /// 月份
        /// </summary>
        [Display(Name = "月份")]
        public int? MonthCount { get; set; }
        /// <summary>
        /// 单位个数
        /// </summary>
        [Display(Name = "单位个数")]
        public int? UnitCount { get; set; }
        /// <summary>
        /// 员工
        /// </summary>
        [Display(Name = "员工个数")]
        public int? EmployeeCount { get; set; }
        /// <summary>
        /// 单价
        /// </summary>
        [Display(Name = "金额")]
        public decimal Amount { get; set; }
        /// <summary>
        /// 支付方式
        /// </summary>
        public string? PayType { get; set; }
        /// <summary>
        /// 支付时间
        /// </summary>
        public DateTime? PayTime { get; set; }
        /// <summary>
        /// 描述
        /// </summary>
        public string? Description { get; set; }
    }
}
ZcPayCore/Model/OderInfo.cs
New file
@@ -0,0 +1,55 @@
using DocumentServiceAPI.Enum;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZcPayCore.Model
{
    /// <summary>
    /// 通用订单类
    /// </summary>
    [Display(Name = "通用订单类 ")]
    [SugarTable(TableName = "Oder", TableDescription = "通用订单类")]
    public class Oder : BaseModel
    {
        /// <summary>
        /// Id
        /// </summary>
        [Display(Name = "Id ")]
        [SugarColumn(ColumnDescription = "Id ",IsIdentity =true,IsPrimaryKey =true)]
        public int Id { get; set; }
        /// <summary>
        /// 用户ID 也可能是租户ID
        /// </summary>
        [Display(Name = "用户ID 也可能是租户ID ")]
        [SugarColumn(ColumnDescription = "用户ID 也可能是租户ID ")]
        public int UserID { get; set; }
        /// <summary>
        /// 订单详情描述
        /// </summary>
        [Display(Name = "订单详情描述 ")]
        [SugarColumn(ColumnDescription = "订单详情描述 ")]
        public string? Description { get; set; }
        /// <summary>
        /// 其他参数
        /// </summary>
        [Display(Name = "其他参数 ")]
        [SugarColumn(ColumnDescription = "其他参数 ")]
        public string? Param { get; set; }
        /// <summary>
        /// PropertyDecName
        /// </summary>
        [Display(Name = "PropertyDecName ")]
        [SugarColumn(ColumnDescription = "PropertyDecName ")]
        public int Property { get; set; }
    }
}
ZcPayCore/ZcPayCore.csproj
New file
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Essensoft.Paylink.Alipay" Version="4.1.2" />
    <PackageReference Include="Essensoft.Paylink.Security" Version="4.1.2" />
    <PackageReference Include="Essensoft.Paylink.WeChatPay" Version="4.1.2" />
    <PackageReference Include="SqlSugarCore" Version="5.1.4.99" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\DocumentServiceAPI.Enum\DocumentServiceAPI.Enum.csproj" />
  </ItemGroup>
</Project>