-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_ReqAddDelTeamTaskOverseer.cpp
More file actions
179 lines (159 loc) · 5.46 KB
/
cmd_ReqAddDelTeamTaskOverseer.cpp
File metadata and controls
179 lines (159 loc) · 5.46 KB
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
167
168
169
170
171
172
173
174
175
176
177
178
#include "cmd_ReqAddDelTeamTaskOverseer.h"
void ReqAddDelTeamTaskOverseerCmd::handle(Context* ct)throw (CmdException)
{
SProxy* proxy = ct->process->getSproxy();
m_pLog = proxy->getRollLog();
Connection* pConn = ct->connection;
m_pLog->debug("ReqAddDelTeamTaskOverseerCmd::handle begining........");
c2sCmd::C2SAddDelTeamTaskOverseerBody c2s;
s2cCmd::S2CAddDelTeamTaskOverseerBody s2c;
s2c.res = ERROR_CODE::EC_Succeed;
int seqno = -1;
bool isNoExcept = false;
try
{
ProtocolMgr& pack = *(ct->pack);
seqno = pack.m_header.seqno;
m_zip = pack.m_header.zip ;
msgpack::object obj = pack.m_pUnpackBody->get();
obj.convert(&c2s);
int teamId = c2s.tid;
int userId = c2s.uid;
int type = c2s.type;
s2c.uid = userId;
s2c.tid = teamId;
s2c.type = type;
m_pLog->debug("ReqAddDelTeamTaskOverseerCmd::handle begining........oseers.size()[%d]", c2s.oseers.size());
if(ct->userid != userId || c2s.oseers.size() <= 0 || teamId <= 0 || userId <= 0 || type < COMMON_DEF::TASKREQTYPE_ADD || type > COMMON_DEF::TASKREQTYPE_DEL)
{
s2c.res = ERROR_CODE::EC_INVALID_INPUT;
s2c.err = ERROR_CODE::EC_INVALID_INPUT_DES;
m_pLog->error("ReqAddDelTeamTaskOverseerCmd: EC_INVALID_INPUT! oseers.size:%d", c2s.oseers.size());
sendResp(pConn, s2c, ct->puid, seqno);
return;
}
string checkBit = "11000000001" ;
ERROR_CODE::Errorcode ret = proxy->m_commonMsg.checkByBit(checkBit, teamId, 0, userId);
if( ret.res != ERROR_CODE::EC_Succeed )
{
m_pLog->error("ReqAddDelTeamTaskOverseerCmd::handle:call checkByBit error,checkBit[%s]teamId[%d]", checkBit.c_str(), teamId);
s2c.res = ret.res;
s2c.err = ret.err;
sendResp(pConn, s2c, ct->puid, seqno);
return;
}
int curTime = (int)time(NULL);
int changeStatus = 0;
for(int i = 0; i < c2s.oseers.size(); i++)
{
int overseerId = c2s.oseers[i];
ret = proxy->m_commonMsg.checkByBit(checkBit, teamId, 0, overseerId);
if( ret.res != ERROR_CODE::EC_Succeed )
{
m_pLog->error("ReqAddDelTeamTaskOverseerCmd::handle:call checkByBit error,checkBit[%s]teamId[%d]overseerId[%d]", checkBit.c_str(), teamId, overseerId);
continue;
}
int status = proxy->m_commonMsg.getTeamTaskParticipantStatus(teamId, userId, overseerId);
if(type == COMMON_DEF::TASKREQTYPE_ADD)
{
changeStatus = COMMON_DEF::TBLTASK_NORMAL;
if(status == COMMON_DEF::TBLTASK_NORMAL)
{
continue;
}
else if(status == COMMON_DEF::TBLTASK_DELETE)
{
proxy->m_commonMsg.updateTeamTaskParticipantStatus(teamId, userId, overseerId, curTime, changeStatus);
}
else if(status == COMMON_DEF::TBLTASK_NOTFOUND)
{
proxy->m_commonMsg.insertTeamTaskParticipant(teamId, userId, overseerId, curTime, changeStatus);
}
}
else if(type == COMMON_DEF::TASKREQTYPE_DEL)
{
changeStatus = COMMON_DEF::TBLTASK_DELETE;
if(status == COMMON_DEF::TBLTASK_DELETE)
{
continue;
}
else if(status == COMMON_DEF::TBLTASK_NORMAL)
{
proxy->m_commonMsg.updateTeamTaskParticipantStatus(teamId, userId, overseerId, curTime, changeStatus);
}
else if(status == COMMON_DEF::TBLTASK_NOTFOUND)
{
proxy->m_commonMsg.insertTeamTaskParticipant(teamId, userId, overseerId, curTime, changeStatus);
}
}
s2c.oseers.push_back(overseerId);
}
sendResp(pConn, s2c, ct->puid, seqno);
isNoExcept = true;
}
catch (std::string& e)
{
m_pLog->error("ReqAddDelTeamTaskOverseerCmd:string error ,%s",e.c_str());
}
catch (msgpack::type_error& e)
{
m_pLog->error("ReqAddDelTeamTaskOverseerCmd:type_error ,%s",e.what());
}
catch (socket_error& e)
{
m_pLog->error("ReqAddDelTeamTaskOverseerCmd:socket_error ,%s",e.what());
}
catch (...)
{
m_pLog->error("ReqAddDelTeamTaskOverseerCmd:unknowed excp");
}
//有异常也要给客户端回应
if(!isNoExcept)
{
s2c.res = ERROR_CODE::EC_UNKNOWED_ERROR;
s2c.err = ERROR_CODE::EC_UNKNOW_ERR_DES;
sendResp(pConn , s2c , ct->puid , seqno ) ;
}
m_pLog->debug("ReqAddDelTeamTaskOverseerCmd::handle ending........");
}
void ReqAddDelTeamTaskOverseerCmd::sendResp(Connection* pConn, s2cCmd::S2CAddDelTeamTaskOverseerBody& s2c, int puid, int seqno)
{
try
{
ProtocolMgr packSent;
packSent.m_header.stx = 0x09;
packSent.m_header.cmd = Cmd::RspAddDelTeamTaskOverseer;
packSent.m_header.seqno = seqno ;
packSent.m_header.ext = puid;
packSent.m_header.zip = m_zip ;
packSent.m_pEncoder->pack(s2c);
char buf[1024*20]={'\0'};
int nLen = 1024*20;
packSent.setWebSocketSupport(pConn->isWebSocket());
packSent.encode(buf,nLen);
pConn->sendMessage(buf,nLen);
//--
ProtocolMgr proMgr;
proMgr.decode(buf,nLen,(ProtocolMgr::PackType)1);
msgpack::object objSnd = proMgr.m_pUnpackBody->get();
std::ostringstream osSnd("");
osSnd << objSnd;
m_pLog->debug("ReqAddDelTeamTaskOverseerCmd::sendResp cmd:%d,body:%s, fd:%d, puid:%d",proMgr.m_header.cmd, osSnd.str().c_str(),pConn->fd(), puid);
}
catch (std::string& e)
{
m_pLog->error("ReqAddDelTeamTaskOverseerCmd::sendResp:string error ,%s",e.c_str());
}
catch (msgpack::type_error& e)
{
m_pLog->error("ReqAddDelTeamTaskOverseerCmd::sendResp:type_error ,%s",e.what());
}
catch (socket_error& e)
{
m_pLog->error("ReqAddDelTeamTaskOverseerCmd::sendResp:socket_error ,%s",e.what());
}
catch (...)
{
m_pLog->error("ReqAddDelTeamTaskOverseerCmd::sendResp:unknowed excp");
}
}