wzp
2021-07-28 864986e4cad03f6b9bba9a7e65379db496b62a6a
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
namespace AsiaINFO.SMS.APPCMPP2.MyThread.DataThread
{
    using AsiaINFO.SMS.APPCMPP2;
    using AsiaINFO.SMS.APPCMPP2.MyThread;
    using AsiaINFO.SMS.BusinessFactory;
    using AsiaINFO.SMS.CMPP2;
    using AsiaINFO.SMS.Entity;
    using System;
    using System.Collections;
    using System.Collections.Generic;
 
    public class GetMTWaitThread : ThreadBase
    {
        private string _out_gateway_id;
        private SyncEvents _submitEvents;
        private Queue<SubmitInfo> _submitQueue;
        private readonly int _waitlong;
        private readonly int _waitshort;
 
        public GetMTWaitThread(SyncEvents syncEvents, Queue<SubmitInfo> submitQueue, SyncEvents submitEvents, string out_gateway_id) : base(syncEvents)
        {
            //this._waitlong = 5;
            this._waitlong = 10;
            if ((submitQueue == null) || (submitEvents == null))
            {
                throw new Exception("GetMTWaitThread参数不能为空!");
            }
            this._submitQueue = submitQueue;
            this._submitEvents = submitEvents;
            this._out_gateway_id = out_gateway_id;
        }
 
        protected void CheckFull()
        {
            do
            {
                if (this._submitCount < 0x1388)
                {
                    return;
                }
            }
            while (!base._syncEvents.ExitThreadEvent.WaitOne((int)(0x3e8 * this._waitlong), false));
        }
 
        private List<MTWaitInfo> GetMTWaitList()
        {
            List<MTWaitInfo> list = new List<MTWaitInfo>();
            try
            {
                list = MTBusiness.GetMTWaitList(100, ShareData.CurrentISMG, this._out_gateway_id);
            }
            catch (Exception exception)
            {
                base.OnMsg("[GetMTWaitList] " + exception.Message, MsgLevel.Err);
            }
            return list;
        }
 
        private bool checkFull()
        {
            return this._submitCount >= 100;
        }
 
        protected override void Run()
        {
            List<MTWaitInfo> mTWaitList = null;
            int num = this._waitlong;
            do
            {
                lock (base._syncSuspendLogLockObject)
                {
                    //this.CheckFull();
 
                    if (this.checkFull())
                    {
                        base.OnMsg("【待发送】队列已满...等待数:" + this._submitCount,MsgLevel.Msg);
                        //this._submitEvents.NewItemEvent.Set();
                        //base.OnMsg($"【待发送】开始,唤醒...",MsgLevel.Debug);
                        
 
                        System.Threading.Thread.Sleep(500);
                        continue;
                    }
 
                    base.OnMsg("【待发送】执行检查...", MsgLevel.Msg);
                    MTBusiness.UpdateUnSendMsg();
 
                    mTWaitList = this.GetMTWaitList();
                    base.OnMsg($"【待发送】已经获取待发送数据,结果:"+mTWaitList.Count,MsgLevel.Msg);
                    if ((mTWaitList != null) && (mTWaitList.Count > 0))
                    {
                        num = this._waitshort;
                        foreach (MTWaitInfo info in mTWaitList)
                        {
                            //检查是否重复
                            if (!DetectionBusiness.Instance.checkMessageId(info.Guid))
                            {
                                DBFactory.log4netService.Debug("[待发送]添加 guid=" + info.Guid + ",手机号码:" + info.MOBILE_NO);
                                DetectionBusiness.Instance.addSubmitMessageToCache(info.Guid);
                            }
                            else
                            {
                                try
                                {
                                    DBFactory.log4netService.Debug("[待发送][已存在不处理]-guid=" + info.Guid + ",手机号码:" + info.MOBILE_NO);
                                    //SubmitInfo info3 = new SubmitInfo(info, ShareData.SeqID, 1);
                                    //MTBusiness.UpdateMTInfo(info3);
 
                                    MTBusiness.DeleteMTWait(info, ShareData.CurrentISMG);
                                }
                                catch (Exception ex)
                                {
                                    base.OnMsg("[检测重复的异常]- " + ex.Message, MsgLevel.Err);
                                }
                                continue;
                            }
 
                            SubmitInfo info2 = new SubmitInfo(info, ShareData.SeqID, 1);
                            this._submitData = info2;
                        }
                        this._submitEvents.NewItemEvent.Set();
                    }
                    else
                    {
                        num = this._waitlong;
                    }
                }
            }
            while (!base._syncEvents.ExitThreadEvent.WaitOne((int) (0x3e8 * num), false));
            base.Stop();
        }
 
        private int _submitCount
        {
            get
            {
                lock (((ICollection) this._submitQueue).SyncRoot)
                {
                    return this._submitQueue.Count;
                }
            }
        }
 
        private SubmitInfo _submitData
        {
            get
            {
                lock (((ICollection) this._submitQueue).SyncRoot)
                {
                    if (this._submitQueue.Count > 0)
                    {
                        return this._submitQueue.Dequeue();
                    }
                }
                return null;
            }
            set
            {
                lock (((ICollection) this._submitQueue).SyncRoot)
                {
                    this._submitQueue.Enqueue(value);
                }
            }
        }
    }
}