lijin
2025-11-20 2a75aa6b6e23a2f86046a2da21eb9e97ec58bdc3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using ApiTools.Core;
using Furion.DatabaseAccessor;
using Mapster;
using MediatR;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ApiTools.CommonServer.Application
{
    public class SaveWxSettingCommandHandler(IRepository<WxSetting> rep) :IRequestHandler<SaveWxSettingCommand, Guid>
    {
        private readonly IRepository<WxSetting> rep = rep;
 
        /// <summary>
        /// 保存微信配置
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Guid> Handle(SaveWxSettingCommand request, CancellationToken cancellationToken)
        {
            var logier = JwtUtils.GetCurrentLogier();
            var entity = await rep.AsQueryable()
                .Where(it => it.Code == request.Code)
                .FirstOrDefaultAsync();
            var add = false;
            if (entity == null)
            {
                entity = new WxSetting();
                entity.Code = request.Code;
                entity.AppId = request.AppId;
                entity.AppSecret = request.AppSecret;
                entity.EnvVersion = request.EnvVersion;
                add = true;
            }
            request.Adapt(entity);
            if (add)
            {
                await rep.InsertAsync(entity);
            }
            else
            {
                await rep.UpdateAsync(entity);
            }
            return entity.Id;
            //return Guid.NewGuid();
        }
    }
}