ff
2020-12-22 383dd7d14714cbdcf44d86786d7166abe2699141
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using ZY.Mes.DAL.IDAL;
using ZY.Mes.DbHepler;
using ZY.Mes.Model;
using ZY.Mes.Model.DAO;
using ZY.Mes.Model.DTO;
 
namespace ZY.Mes.Service
{
    public class TestService: ITestService
    {
        private readonly ITestDal _testDal;
        private readonly IMapper _mapper;
        public TestService(IMapper mapper, ITestDal testDal)
        {
            _mapper = mapper;
            _testDal = testDal;
        }
        /// <summary>
        /// 测试autoMapper
        /// </summary>
        public void TestAutoMapper()
        {
            M_Test testModel = new M_Test()
            {
                Id = 1,
                UserName = "ouyang"
            };
            TestView testViewModel = _mapper.Map<TestView>(testModel);//测试Model映射
            List<M_Test> testList = new List<M_Test>();
            testList.Add(testModel);
            List<TestView> testViewList = _mapper.Map<List<TestView>>(testList);//测试list映射
        }
        /// <summary>
        /// 测试redis使用
        /// </summary>
        public void TestResdis()
        {
            var serialNum = RedisPools.GetRedisClient("redis").Get<int>(RedisKeyView.LD_TESKNUM.Key, RedisKeyView.LD_TESKNUM.DbIndex);//缓存查询有没有该数据
            if (serialNum == 0)//没有该数据
            {
                serialNum = _testDal.GetSerialNum(15);//从数据库查询
                RedisPools.GetRedisClient("Ld").Set(RedisKeyView.LD_TESKNUM.Key, serialNum, RedisKeyView.LD_TESKNUM.ExpireTime, RedisKeyView.LD_TESKNUM.DbIndex);//存入缓存
            }
        }
        /// <summary>
        /// 测试入列
        /// </summary>
        /// <param name="queStr"></param>
        /// <returns></returns>
        public ApiResult SetTestQue(string queStr)
        {
            RedisPools.GetRedisClient("redis").LPush(RedisKeyView.LD_TESTQUE.Key, RedisKeyView.LD_TESTQUE.DbIndex, queStr);
            return new ApiResult(ApiResultCode.OK, "入列成功");
        }
        /// <summary>
        /// 测试出列
        /// </summary>
        public void PopTestQue()
        {
            while (true)
            {
                var queStr = RedisPools.GetRedisClient("redis").LPop<string>(RedisKeyView.LD_TESTQUE.Key, RedisKeyView.LD_TESTQUE.DbIndex);
                if (!string.IsNullOrEmpty(queStr))
                {
                    Console.WriteLine($"{queStr}数据处理成功");
                }
                else
                {
                    Thread.Sleep(1000);//没有数据休眠1s
                }
            }
        }
    }
}