zhaojs
2023-09-15 fc13938ff90213060532d99a600dea4a84456885
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
using CommonUtil;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Operater.DAL;
using Operater.DbModel;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
 
namespace ReceiveSmsMq
{
   public class ReceiveSmsHandle
    {
        public static void ReceiveSms(string message)
        {
            Console.WriteLine(message);
            JObject messJob = (JObject)JsonConvert.DeserializeObject(message.Replace(" ", ""));
            if (string.IsNullOrEmpty(messJob["status"].ToString()))
            {
                //短信回复
                string mobile = messJob["mobile"].ToString();
                string smscontent = messJob["content"].ToString();
                string sendid= messJob["msgid"].ToString();
                //根据sendid查询记录
                var history_where_expression = Expressionable.Create<SmsSendhistory>().And(m => m.Sendid == sendid).ToExpression();
                var sendhistory = new SmsSendhistoryDAL().GetFirst(history_where_expression);
                if (sendhistory != null)
                {
                    //添加回复内容
                    SmsSendhistory smsSendhistory = new SmsSendhistory
                    {
                        Id = Guid.NewGuid().ToString(),
                        Mobile = mobile,
                        Succedsmscount = 1,
                        Sendstatus = 0,
                        Sendtime = DateTime.Now,
                        Smscontent = smscontent,
                        Memo = "1",
                        Memberid = sendhistory.Memberid,
                        Isshowsend = 0,
                        Mainid = sendhistory.Mainid,
                        Sendid = sendid,
                        IsRead = 0,
                        ReaLsuccedsmscount = 1
                    };
                    bool issuccess = new SmsSendhistoryDAL().Insert(smsSendhistory);
                    if (issuccess)
                    {
                        //修改短信任务状态
                        SmsSend updateSmssend = new SmsSend
                        {
                            Sendstatus = 8,
                        };
                        int successcount = new SmsSendDAL().Update(updateSmssend, m => new { m.Sendstatus }, s => s.Id == sendhistory.Mainid);
                    }
                }
 
            }
            else
            {
                //短信回执
                string status = messJob["status"].ToString().Equals("1") ? "1" : "2"; //1成功 2失败
                string desc_state = messJob["status"].ToString().Equals("1") ? "DELIVRD" : messJob["desc_state"].ToString();
                string sendid = messJob["msgid"].ToString();
                if (status == "2")
                {
                    //根据sendid查询记录
                    var history_where_expression = Expressionable.Create<SmsSendhistory>().And(m => m.Sendid == sendid).ToExpression();
                    var sendhistory = new SmsSendhistoryDAL().GetSingle(history_where_expression);
                    //修改发送记录为失败
                    SmsSendhistory smsSendhistory = new SmsSendhistory
                    {
                        Sendstatus=1
                    };
                    int his_successcount = new SmsSendhistoryDAL().Update(smsSendhistory, m => new { m.Sendstatus }, s => s.Id == sendhistory.Id);
                    //修改任务为失败
                    SmsSend updateSmssend = new SmsSend
                    {
                        Sendstatus = 9,
                    };
                    int send_successcount = new SmsSendDAL().Update(updateSmssend, m => new { m.Sendstatus }, s => s.Id == sendhistory.Mainid);
                    //补短信
                    int member_successcount = new SmsMemberDAL().ExecuteCommand($"update sms_member set smscount=smscount+{sendhistory.Succedsmscount} where id='{sendhistory.Memberid}'");
                    if (member_successcount == 0)
                    {
                        LogUtil.Error($"补短信失败,任务id:{sendhistory.Mainid},执行sql:update sms_member set smscount=smscount+{sendhistory.Succedsmscount} where id='{sendhistory.Memberid}' ,mq消息:{message}", "补短信失败");
                    }
                }
 
            }
           
        }
    }
}