From 4115c46ea22c90198d46eecbe33be1703fd0cf6f Mon Sep 17 00:00:00 2001
From: liaoxujun@qq.com <liaoxujun@qq.com>
Date: 星期五, 25 八月 2023 15:57:21 +0800
Subject: [PATCH] 修改支付授权建立租户
---
DocumentServiceApi.InitQMessage/MessageReceive.cs | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 154 insertions(+), 4 deletions(-)
diff --git a/DocumentServiceApi.InitQMessage/MessageReceive.cs b/DocumentServiceApi.InitQMessage/MessageReceive.cs
index 1451c2d..39221e6 100644
--- a/DocumentServiceApi.InitQMessage/MessageReceive.cs
+++ b/DocumentServiceApi.InitQMessage/MessageReceive.cs
@@ -1,5 +1,13 @@
-锘縰sing InitQ.Abstractions;
+锘縰sing 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;
@@ -13,15 +21,157 @@
/// </summary>
public class MessageReceive: IRedisSubscribe
{
+
+
/// <summary>
/// 鍒濆鍖栬鍗曞鐞�
/// </summary>
/// <param name="msg"></param>
- /// <returns></returns>
-
- [Subscribe(INITQMessageDefine.InitTentOder)]
+ /// <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;
+ }
+
+ }
+
+
+
+
+
+
+
--
Gitblit v1.9.1