-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_ReqAddModDelTeamTask.cpp
More file actions
496 lines (442 loc) · 16.3 KB
/
cmd_ReqAddModDelTeamTask.cpp
File metadata and controls
496 lines (442 loc) · 16.3 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
#include "cmd_ReqAddModDelTeamTask.h"
void ReqAddModDelTeamTaskCmd::handle(Context* ct)throw (CmdException)
{
SProxy* proxy = ct->process->getSproxy();
m_pLog = proxy->getRollLog();
Connection* pConn = ct->connection;
m_pLog->debug("ReqAddModDelTeamTaskCmd::handle begining........");
c2sCmd::C2SAddModDelTeamTaskBody c2s;
s2cCmd::S2CAddModDelTeamTaskBody 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();
std::ostringstream osSnd("");
osSnd << obj;
m_pLog->debug("ReqAddModDelTeamTaskCmd::handle cmd:%d,body:%s, fd:%d",pack.m_header.cmd, osSnd.str().c_str(),pConn->fd());
obj.convert(&c2s);
int LEN = 920;
int LEN1 = 512;
int LEN2 = 32;
int teamId = c2s.tid;
int userId = c2s.uid;
int type = c2s.type;
s2c.uid = userId;
s2c.tid = teamId;
s2c.type = type;
m_pLog->debug("ReqAddModDelTeamTaskCmd::tkinfo.size()[%d]",c2s.tkinfo.size());
if(ct->userid != userId || type < COMMON_DEF::TASKREQTYPE_ADD || type > COMMON_DEF::TASKREQTYPE_MOD || teamId <= 0 || userId <= 0)
{
s2c.res = ERROR_CODE::EC_INVALID_INPUT;
s2c.err = ERROR_CODE::EC_INVALID_INPUT_DES;
m_pLog->error("ReqAddModDelTeamTaskCmd: EC_INVALID_INPUT1! type:%d teamId:%d userId:%d",type,teamId,userId);
sendResp(pConn, s2c, ct->puid, seqno);
return;
}
if(c2s.tkinfo.size() != 1)
{
s2c.res = ERROR_CODE::EC_INVALID_INPUT;
s2c.err = ERROR_CODE::EC_INVALID_INPUT_DES;
m_pLog->error("ReqAddModDelTeamTaskCmd: EC_INVALID_INPUT2! tkinfo.size:%d",c2s.tkinfo.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("ReqAddModDelTeamTaskCmd::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);
string strTmUsrTk = TBL_TEAMUSERTASK + "_" + base::i2s(teamId % 10);
QueryParam paraTmUsrTk;
paraTmUsrTk.tableName = strTmUsrTk;
if(type == COMMON_DEF::TASKREQTYPE_DEL)
{
int tkid = c2s.tkinfo[0].tkid;
if(tkid <= 0)
{
s2c.res = ERROR_CODE::EC_INVALID_INPUT;
s2c.err = ERROR_CODE::EC_INVALID_INPUT_DES;
m_pLog->error("ReqAddModDelTeamTaskCmd: EC_INVALID_INPUT3! del tkid:%d", tkid);
sendResp(pConn, s2c, ct->puid, seqno);
return;
}
//查询是否存在该任务id
int rowNum = proxy->m_commonMsg.chkTeamUserTaskInTaskid(teamId, userId, tkid);
if(rowNum <= 0)
{
s2c.res = ERROR_CODE::EC_TEAMTASKID_NOTFOUNT;
s2c.err = ERROR_CODE::EC_TEAMTASKID_NOTFOUNT_DES;
m_pLog->error("ReqAddModDelTeamTaskCmd: EC_INVALID_INPUT4! no this tkid:%d or already del", tkid);
sendResp(pConn, s2c, ct->puid, seqno);
return;
}
string strSql = "update " + strTmUsrTk + " set status = '" + base::i2s(COMMON_DEF::TBLTASK_DELETE) + "',updated = '" + base::i2s(curTime) \
+ "' where userId = '" + base::i2s(userId) + "' and teamId = '" + base::i2s(teamId) + "' and taskId = '" + base::i2s(tkid) + "' ;";
proxy->m_ar_dbMgr.oper_db_shm(paraTmUsrTk, strSql);
//m_pLog->debug("ReqAddModDelTeamTaskCmd::TASKREQTYPE_DEL strSql[%s]",strSql.c_str());
s2cCmd::S2CTeamTaskListInfo tkInfo;
tkInfo.tkid = tkid;
s2c.tkinfo.push_back(tkInfo);
}
else
{
int tkid = c2s.tkinfo[0].tkid;
string tktitle = c2s.tkinfo[0].tktitle;
int frsppsn = c2s.tkinfo[0].frsppsn;
vector<int> excut = c2s.tkinfo[0].excut;
string tkdes = c2s.tkinfo[0].tkdes;
int tkstat = c2s.tkinfo[0].tkstat;
int level = c2s.tkinfo[0].level;
string bgntm = c2s.tkinfo[0].bgntm;
string endtm = c2s.tkinfo[0].endtm;
string plntm = c2s.tkinfo[0].plntm;
string acttm = c2s.tkinfo[0].acttm;
//string ftinwk = c2s.tkinfo[0].ftinwk;
string remark = c2s.tkinfo[0].remark;
int wkpro = c2s.tkinfo[0].wkpro;
if((tkid != 0 && type == COMMON_DEF::TASKREQTYPE_ADD) || \
(tkid <= 0 && type == COMMON_DEF::TASKREQTYPE_MOD) || \
tktitle.empty() || \
tkstat < COMMON_DEF::TASK_NOTSTART || \
tkstat > COMMON_DEF::TASK_FINISH || \
level < COMMON_DEF::TASKLEVEL_FIRST || \
level > COMMON_DEF::TASKLEVEL_THIRD || \
plntm.length() > LEN2 || \
acttm.length() > LEN2 || \
wkpro < 0 || \
wkpro > 100)
{
s2c.res = ERROR_CODE::EC_INVALID_INPUT;
s2c.err = ERROR_CODE::EC_INVALID_INPUT_DES;
m_pLog->error("ReqAddModDelTeamTaskCmd: EC_INVALID_INPUT5!");
sendResp(pConn, s2c, ct->puid, seqno);
return;
}
if(tktitle.length() > LEN1)
{
s2c.res = ERROR_CODE::EC_TEAMTASK_TITLE_TOOLONG;
s2c.err = ERROR_CODE::EC_TEAMTASK_TITLE_TOOLONG_DES;
m_pLog->error("ReqAddModDelTeamTaskCmd: EC_TEAMTASK_TITLE_TOOLONG! tktitle.length():%d", tktitle.length());
sendResp(pConn, s2c, ct->puid, seqno);
return;
}
if(tkdes.length() > LEN*4)
{
s2c.res = ERROR_CODE::EC_TEAMTASK_TKDES_TOOLONG;
s2c.err = ERROR_CODE::EC_TEAMTASK_TKDES_TOOLONG_DES;
m_pLog->error("ReqAddModDelTeamTaskCmd: EC_TEAMTASK_TKDES_TOOLONG! tkdes.length():%d", tkdes.length());
sendResp(pConn, s2c, ct->puid, seqno);
return;
}
if(remark.length() > LEN*4)
{
s2c.res = ERROR_CODE::EC_TEAMTASK_REMARK_TOOLONG;
s2c.err = ERROR_CODE::EC_TEAMTASK_REMARK_TOOLONG_DES;
m_pLog->error("ReqAddModDelTeamTaskCmd: EC_TEAMTASK_REMARK_TOOLONG! remark.length():%d", remark.length());
sendResp(pConn, s2c, ct->puid, seqno);
return;
}
if(level == COMMON_DEF::TASKLEVEL_FIRST && type == COMMON_DEF::TASKREQTYPE_ADD)
{
//查询是否已有等级为一的任务(需求只有一条等级为一级任务)
int rowNum = proxy->m_commonMsg.chkTeamUserTaskCntInLevel(teamId, userId, level);
//已有则不能新增一级任务
if(rowNum > 0)
{
s2c.res = ERROR_CODE::EC_TEAMTASKLV_BEONE;
s2c.err = ERROR_CODE::EC_TEAMTASKLV_BEONE_DES;
m_pLog->error("ReqAddModDelTeamTaskCmd: EC_INVALID_INPUT6! level 1 task rowNum:%d", rowNum);
sendResp(pConn, s2c, ct->puid, seqno);
return;
}
}
if(type == COMMON_DEF::TASKREQTYPE_MOD)
{
//查询是否存在该任务id
int rowNum = proxy->m_commonMsg.chkTeamUserTaskInTaskid(teamId, userId, tkid);
if(rowNum <= 0)
{
s2c.res = ERROR_CODE::EC_TEAMTASKID_NOTFOUNT;
s2c.err = ERROR_CODE::EC_TEAMTASKID_NOTFOUNT_DES;
m_pLog->error("ReqAddModDelTeamTaskCmd: EC_INVALID_INPUT7! no this tkid:%d or already del", tkid);
sendResp(pConn, s2c, ct->puid, seqno);
return;
}
if(level == COMMON_DEF::TASKLEVEL_FIRST)
{
int rowNum = proxy->m_commonMsg.chkTeamUserOtherTaskLevel(teamId, userId, tkid, level);
//已有则不能新增一级任务
if(rowNum > 0)
{
s2c.res = ERROR_CODE::EC_TEAMTASKLV_BEONE;
s2c.err = ERROR_CODE::EC_TEAMTASKLV_BEONE_DES;
m_pLog->error("ReqAddModDelTeamTaskCmd: EC_INVALID_INPUT8! other level 1 task rowNum:%d", rowNum);
sendResp(pConn, s2c, ct->puid, seqno);
return;
}
}
}
string strfrsppsn = base::i2s(frsppsn);
string strexcut = "";
for(int i = 0; i < excut.size(); i++)
{
if(excut[i] > 0)
{
if(i >0)
{
strexcut += ",";
}
strexcut += base::i2s(excut[i]);
}
}
m_pLog->debug("ReqAddModDelTeamTaskCmd::strfrsppsn[%s] strexcut[%s]",strfrsppsn.c_str(),strexcut.c_str());
int taskId = 0;
if(type == COMMON_DEF::TASKREQTYPE_ADD)
{
taskId = proxy->m_idMgr.dispatchTaskTblMaxId(strTmUsrTk);
m_pLog->debug("ReqAddModDelTeamTaskCmd::taskId[%d]",taskId);
bson::bo boGm = BSON("taskId" << taskId \
<< "teamId" << teamId \
<< "userId" << userId \
<< "taskTitle" << tktitle \
<< "firstResponsiblePerson" << strfrsppsn \
<< "executant" << strexcut \
<< "taskDescription" << tkdes \
<< "taskStatus" << tkstat \
<< "level" << level \
<< "beginTime" << bgntm \
<< "endTime" << endtm \
<< "plannedTime" << plntm \
<< "actualTime" << acttm \
<< "remarks" << remark \
<< "workProgress" << wkpro \
<< "status" << COMMON_DEF::TBLTASK_NORMAL \
<< "created" << curTime \
<< "updated" << curTime );
proxy->m_ar_dbMgr.save_db_shm(boGm, paraTmUsrTk, DBOPER_ADD);
string strSql1 = "update " + strTmUsrTk + " set " + \
"taskDescription = '" + tkdes + "'" + \
" where userId = '" + base::i2s(userId) + "' and teamId = '" + base::i2s(teamId) + "' and taskId = '" + base::i2s(taskId) + "' ;";
proxy->m_ar_dbMgr.oper_db_shm(paraTmUsrTk, strSql1);
string strSql2 = "update " + strTmUsrTk + " set " + \
"remarks = '" + remark + "'" + \
" where userId = '" + base::i2s(userId) + "' and teamId = '" + base::i2s(teamId) + "' and taskId = '" + base::i2s(taskId) + "' ;";
proxy->m_ar_dbMgr.oper_db_shm(paraTmUsrTk, strSql2);
}
else if(type == COMMON_DEF::TASKREQTYPE_MOD)
{
string strSql = "update " + strTmUsrTk + " set " + \
"taskTitle = '" + tktitle + "'," + \
"firstResponsiblePerson = '" + strfrsppsn + "'," + \
"executant = '" + strexcut + "'," + \
"taskStatus = '" + base::i2s(tkstat) + "'," + \
"level = '" + base::i2s(level) + "'," + \
"beginTime = '" + bgntm + "'," + \
"endTime = '" + endtm + "'," + \
"plannedTime = '" + plntm + "'," + \
"actualTime = '" + acttm + "'," + \
"workProgress = '" + base::i2s(wkpro) + "'," + \
"updated = '" + base::i2s(curTime) + "'" + \
" where userId = '" + base::i2s(userId) + "' and teamId = '" + base::i2s(teamId) + "' and taskId = '" + base::i2s(tkid) + "' ;";
proxy->m_ar_dbMgr.oper_db_shm(paraTmUsrTk, strSql);
string strSql1 = "update " + strTmUsrTk + " set " + \
"taskDescription = '" + tkdes + "'" + \
" where userId = '" + base::i2s(userId) + "' and teamId = '" + base::i2s(teamId) + "' and taskId = '" + base::i2s(tkid) + "' ;";
proxy->m_ar_dbMgr.oper_db_shm(paraTmUsrTk, strSql1);
string strSql2 = "update " + strTmUsrTk + " set " + \
"remarks = '" + remark + "'" + \
" where userId = '" + base::i2s(userId) + "' and teamId = '" + base::i2s(teamId) + "' and taskId = '" + base::i2s(tkid) + "' ;";
proxy->m_ar_dbMgr.oper_db_shm(paraTmUsrTk, strSql2);
//m_pLog->debug("ReqAddModDelTeamTaskCmd::TASKREQTYPE_MOD strSql[%s]", strSql.c_str());
taskId = tkid;
}
s2cCmd::S2CTeamTaskListInfo tkInfo;
tkInfo.tkid = taskId;
tkInfo.tktitle = tktitle;
tkInfo.frsppsn = frsppsn;
tkInfo.excut = excut;
tkInfo.tkdes = tkdes;
tkInfo.tkstat = tkstat;
tkInfo.level = level;
tkInfo.bgntm = bgntm;
tkInfo.endtm = endtm;
tkInfo.plntm = plntm;
tkInfo.acttm = acttm;
//tkInfo.ftinwk = ftinwk;
tkInfo.remark = remark;
tkInfo.wkpro = wkpro;
tkInfo.updtm = curTime;
if(type == COMMON_DEF::TASKREQTYPE_ADD)
{
tkInfo.crttm = curTime;
}
else
{
tkInfo.crttm = c2s.tkinfo[0].crttm;
}
s2c.tkinfo.push_back(tkInfo);
}
sendResp(pConn, s2c, ct->puid, seqno);
//更新审批状态为未审批,清空remark
int workerId = userId;
int overseerId = 0;
int apstat = COMMON_DEF::TASKAPPROVALSTATUS_UNAPPROVAL;
string apRemark = "";
vector<int> oseers;
proxy->m_commonMsg.updateTeamTaskApprovalStatus(teamId, workerId, overseerId, curTime, apstat, apRemark);
int aps = 0;
string apr = "";
proxy->m_commonMsg.getTeamTaskOverseer(teamId, workerId, oseers, aps, apr);
if(oseers.size() > 0)
{
//推送到其他的参与者
s2cCmd::SendApprovalTeamTask sdApTmTkBody;
sdApTmTkBody.tid = teamId;
sdApTmTkBody.oseer = 0;
sdApTmTkBody.tkuid = workerId;
sdApTmTkBody.apstat = apstat;
sdApTmTkBody.remark = apRemark;
for(int i = COMMON_DEF::TERMINAL_PC; i <= COMMON_DEF::TERMINAL_IOS; ++i)
{
for(int j = 0; j < oseers.size(); ++j)
{
int puid = common_utils::getPuid(oseers[j], i);
GameUserInfo* pGameUserInfo = proxy->m_userMgr.getUserInfoByPuid(puid);
if(pGameUserInfo == NULL)
{
//离线
}
else
{
if(puid != ct->puid)
{
//推送给其他端
SendApprovalTeamTask(pConn, sdApTmTkBody, puid, seqno);
}
}
}
}
}
isNoExcept = true;
}
catch (std::string& e)
{
m_pLog->error("ReqAddModDelTeamTaskCmd:string error ,%s",e.c_str());
}
catch (msgpack::type_error& e)
{
m_pLog->error("ReqAddModDelTeamTaskCmd:type_error ,%s",e.what());
}
catch (socket_error& e)
{
m_pLog->error("ReqAddModDelTeamTaskCmd:socket_error ,%s",e.what());
}
catch (...)
{
m_pLog->error("ReqAddModDelTeamTaskCmd: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("ReqAddModDelTeamTaskCmd::handle ending........");
}
void ReqAddModDelTeamTaskCmd::sendResp(Connection* pConn, s2cCmd::S2CAddModDelTeamTaskBody& s2c, int puid, int seqno)
{
try
{
ProtocolMgr packSent;
packSent.m_header.stx = 0x09;
packSent.m_header.cmd = Cmd::RspAddModDelTeamTask;
packSent.m_header.seqno = seqno ;
packSent.m_header.ext = puid;
packSent.m_header.zip = m_zip ;
packSent.m_pEncoder->pack(s2c);
char buf[1024*10]={'\0'};
int nLen = 1024*10;
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("ReqAddModDelTeamTaskCmd::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("ReqAddModDelTeamTaskCmd::sendResp:string error ,%s",e.c_str());
}
catch (msgpack::type_error& e)
{
m_pLog->error("ReqAddModDelTeamTaskCmd::sendResp:type_error ,%s",e.what());
}
catch (socket_error& e)
{
m_pLog->error("ReqAddModDelTeamTaskCmd::sendResp:socket_error ,%s",e.what());
}
catch (...)
{
m_pLog->error("ReqAddModDelTeamTaskCmd::sendResp:unknowed excp");
}
}
void ReqAddModDelTeamTaskCmd::SendApprovalTeamTask(Connection* pConn, s2cCmd::SendApprovalTeamTask& s2c, int puid, int seqno)
{
try
{
ProtocolMgr packSent;
packSent.m_header.stx = 0x09;
packSent.m_header.cmd = Cmd::SendApprovalTeamTask;
packSent.m_header.seqno = seqno;
packSent.m_header.ext = puid;
packSent.m_header.zip = m_zip;
packSent.m_pEncoder->pack(s2c);
char buf[1024*10]={'\0'};
int nLen = 1024*10;
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("ReqGetTeamTaskListCmd::sendSessionMsg cmd:%d,zip:%d,puid:%d,body:%s",proMgr.m_header.cmd,proMgr.m_header.zip, puid ,osSnd.str().c_str());
*/
m_pLog->debug("ReqAddModDelTeamTaskCmd::SendApprovalTeamTask cmd:%d,zip:%d,puid:%d,seqno[%d]" ,packSent.m_header.cmd, m_zip , puid , seqno) ;
}
catch (std::string& e)
{
m_pLog->error("ReqAddModDelTeamTaskCmd:SendApprovalTeamTask string error ,%s",e.c_str());
}
catch (msgpack::type_error& e)
{
m_pLog->error("ReqAddModDelTeamTaskCmd:SendApprovalTeamTask type_error ,%s",e.what());
}
catch (socket_error& e)
{
m_pLog->error("ReqAddModDelTeamTaskCmd:SendApprovalTeamTask socket_error ,%s",e.what());
}
catch (...)
{
m_pLog->error("ReqAddModDelTeamTaskCmd:SendApprovalTeamTask unknowed excp");
}
}