1 CREATE OR REPLACE PROCEDURE "ESI_QIANDAO5MAIXIANG" (qdQRcode in varchar2, -- 签到二维码 2 out_Course out varchar2, -- 课程期次 3 out_Student out varchar2, -- 学员姓名 4 out_Group out varchar2, -- 所属小组 5 out_Tutor out varchar2, -- 助教老师 6 out_Flag out int, -- 是否成功flag 7 out_sqlcode out int, 8 out_sqlerrm out varchar2, 9 in_UserID in int, -- 用户id 10 in_Status in int, 11 out_SGroup out varchar2, -- 大组 12 out_Customer out varchar2, 13 in_AppID in varchar2) AS 14 -- 客户名称 15 16 qdID varchar2(22); --签到ID 17 xxjhID varchar2(22); --学习计划ID 18 jxjhID varchar2(22); --教学计划ID 19 ddID varchar2(22); --订单ID 20 xxjhPlanNumber int; -- 学习计划表中计划人数 21 xxjhAlreadyCourse int; -- 学习计划中已签到人数 22 qdAccountid int; -- 客户ID 23 qdAccountBaohuYigou int; -- 客户池:保护池/已购池 24 ddIDCreateTime varchar2(22); -- 签到表对应订单的创建时间 25 khStatePrew int; -- 客户原来的状态(更新前的状态) 26 27 out_unpayed_amount int; -- 订单中未收款金额 28 29 out_org_id varchar2(22); 30 out_yckb_id int; 31 32 in_the_AppID varchar2(22); --签到的AppID 33 34 out_the_Flag int; --先查询二维码是否过期,即以签到表对应的教学计划中课程的开始和结束日期作为条件 35 36 begin 37 begin 38 39 /* 40 ---------------------------------------------------------------------- 41 先进行7项检查 42 1 非法的二维码 43 2 签到二维码已过期 44 3 未到签到时间 45 4 签到状态为是,即已签到 46 5 签到表类型为正式课 47 6 签到表的参课判定不是参加 48 7 未收款金额是否>0, >0则需要先收款,才可以签到 49 ---------------------------------------------------------------------- 50 */ 51 52 -- 1 非法的二维码 53 select count(yckb_id) 54 into out_the_Flag 55 from tcu_yckb 56 where qrcode = qdQRcode; 57 58 if out_the_Flag = 0 then 59 out_the_Flag := null; 60 goto InvalidQrCode; 61 end if; 62 63 -- 2 签到表类型为正式课 64 SELECT count(t.yckb_id) 65 into out_the_Flag 66 FROM tcu_yckb t 67 inner join tc_contact tc 68 on t.yckb_refid01 = tc.contact_id 69 and tc.org_id = t.org_id 70 inner join tcu_jiaoxplan jp 71 on t.yckb_refid02 = jp.jiaoxplan_id 72 and t.org_id = jp.org_id 73 inner join tc_account khb 74 on tc.account_id = khb.account_id 75 and khb.org_id = tc.org_id 76 where t.yckb_type = 2132 -- 迈向课 77 and t.qrcode = qdQRcode; 78 79 if out_the_Flag = 0 then 80 out_the_Flag := null; 81 goto TheQrCodeTypeIsZhengShi; 82 end if; 83 84 -- 3 签到二维码已过期 85 SELECT count(t.yckb_id) 86 into out_the_Flag 87 FROM tcu_yckb t 88 inner join tc_contact tc 89 on t.yckb_refid01 = tc.contact_id 90 and tc.org_id = t.org_id 91 inner join tcu_jiaoxplan jp 92 on t.yckb_refid02 = jp.jiaoxplan_id 93 and t.org_id = jp.org_id 94 inner join tc_account khb 95 on tc.account_id = khb.account_id 96 and khb.org_id = tc.org_id 97 where (trunc(jp.jiaoxplan_date02 + 1) - 1 / 24 / 60 / 60) < sysdate -- 当前时间>结课日期的23:59:59 98 and t.qrcode = qdQRcode; 99 100 if out_the_Flag = 1 then 101 out_the_Flag := null; 102 goto TheCourceIsOver; 103 end if; 104 105 -- 4 未到签到时间 106 SELECT count(t.yckb_id) 107 into out_the_Flag 108 FROM tcu_yckb t 109 inner join tc_contact tc 110 on t.yckb_refid01 = tc.contact_id 111 and t.org_id = tc.org_id 112 inner join tcu_jiaoxplan jp 113 on t.yckb_refid02 = jp.jiaoxplan_id 114 and t.org_id = jp.org_id 115 inner join tc_account khb 116 on tc.account_id = khb.account_id 117 and tc.org_id = khb.org_id 118 where jp.jiaoxplan_date01 - 1 > trunc(sysdate) -- 当前时间<报到日(开课日期前一天)0点,即未到可签到时间 119 and t.qrcode = qdQRcode; 120 121 if out_the_Flag = 1 then 122 out_the_Flag := null; 123 goto CantQianDao; 124 end if; 125 126 -- 5 签到状态为是,即已签到 127 SELECT count(t.yckb_id) 128 into out_the_Flag 129 FROM tcu_yckb t 130 inner join tc_contact tc 131 on t.yckb_refid01 = tc.contact_id 132 and tc.org_id = t.org_id 133 inner join tcu_jiaoxplan jp 134 on t.yckb_refid02 = jp.jiaoxplan_id 135 and t.org_id = jp.org_id 136 inner join tc_account khb 137 on tc.account_id = khb.account_id 138 and khb.org_id = tc.org_id 139 where t.yckb_int03 = 1001 -- 签到状态:否 140 and t.qrcode = qdQRcode; 141 142 if out_the_Flag = 0 then 143 out_the_Flag := null; 144 goto TheQrCodeAlreadySigned; 145 end if; 146 147 -- 6 签到表的参课判定不是参加 148 SELECT count(t.yckb_id) 149 into out_the_Flag 150 FROM tcu_yckb t 151 inner join tc_contact tc 152 on t.yckb_refid01 = tc.contact_id 153 and tc.org_id = t.org_id 154 inner join tcu_jiaoxplan jp 155 on t.yckb_refid02 = jp.jiaoxplan_id 156 and t.org_id = jp.org_id 157 inner join tc_account khb 158 on tc.account_id = khb.account_id 159 and khb.org_id = tc.org_id 160 where t.yckb_int05 = 1001 -- 参课判定:参加 161 and t.qrcode = qdQRcode; 162 163 if out_the_Flag = 0 then 164 out_the_Flag := null; 165 goto TheQrCodeTypeIsnotCanjia; 166 end if; 167 168 -- 7 查询未收款金额 169 select contract_unpayed_amount 170 into out_unpayed_amount 171 from tc_contract 172 where contract_id = 173 (select ref_3 from tcu_yckb where qrcode = qdQRcode); 174 175 -- 未收款金额>0 ,需要先缴费 176 if out_unpayed_amount > 0 then 177 out_the_Flag := null; 178 goto PayFirst; 179 end if; 180 181 /* 182 183 改造选“没查到符合条件的签到表”中的逻辑,继续细化成几种情况 184 没查到符合条件的签到表, 185 可能情况: 186 1 签到表的参课判定为 不参加; 187 2 签到表的类型为:迈向课签到表; 188 3 签到表的签到状态为:是 189 190 SELECT count(t.yckb_id) 191 into out_the_Flag 192 FROM tcu_yckb t 193 inner join tc_contact tc 194 on t.yckb_refid01 = tc.contact_id 195 and tc.org_id = t.org_id 196 inner join tcu_jiaoxplan jp 197 on t.yckb_refid02 = jp.jiaoxplan_id 198 and t.org_id = jp.org_id 199 inner join tc_account khb 200 on tc.account_id = khb.account_id 201 and khb.org_id = tc.org_id 202 where 203 -- jp.jiaoxplan_date01 >= trunc(sysdate) 204 -- and (trunc(jp.jiaoxplan_date02 + 1) - 1 / 24 / 60 / 60) > sysdate 205 206 -- 当前日期>=报到日(开课日期前一天)0点,其当前日期<=结课日期的23:59:59 207 jp.jiaoxplan_date01 - 1 <= trunc(sysdate) 208 and trunc(jp.jiaoxplan_date02 + 1) - 1 / 24 / 60 / 60 >= sysdate 209 and t.yckb_int03 = 1001 -- 签到状态:否 210 -- and t.yckb_type = 2136 -- 正式课 211 and t.yckb_int05 = 1001 -- 参课判定:参加 212 and t.qrcode = qdQRcode; 213 214 -- 没查到符合条件的签到表 215 if out_the_Flag = 0 then 216 out_the_Flag := null; 217 goto NoRecordddd; 218 end if; 219 220 */ 221 222 -- 1 签到动作本身 223 -- 获取签到表相关信息 224 -- 获取签到表ID 225 select tb.yckb_id, 226 tb.ref_3, 227 tb.yckb_refid02, 228 tb.account_id, 229 tc.create_time -- 签到表对应订单的创建时间 230 into qdID, ddID, jxjhID, qdAccountid,ddIDCreateTime 231 from tcu_yckb tb 232 inner join tc_contract tc 233 on tb.ref_3 = tc.contract_id 234 where tb.qrcode = qdQRcode; 235 236 -- 获取学习计划ID 237 -- 先查询 238 SELECT count(t.ref_1) 239 into out_the_Flag 240 from tcu_yckb_1_1 t 241 where yckb_id = qdID; 242 243 if out_the_Flag = 0 then 244 goto NoXueXiPlan; 245 end if; 246 247 -- 再获取 248 select ref_1 into xxjhID from tcu_yckb_1_1 where yckb_id = qdID; 249 250 -- 更新签到表 更新字段:是否签到,有效到场/合格总裁,签到时间,是否电子签到 251 update tcu_yckb 252 set yckb_int03 = '1001', 253 -- set yckb_int03 = '1002', -- lgy eidt @2015-5-12 for 可以多次签到 254 yckb_int06 = '1002', -- 先默认是否,签到更新的时候再更新此字段 255 yckb_date01 = sysdate - 1 / 3, 256 IsESI = 1 257 where yckb_id = qdID; 258 259 -- 更新签到表扩展表 更新字段:yckb_refid06 签到人 260 update tcu_yckb_xattr 261 set yckb_refid06 = in_UserID 262 where yckb_id = qdID; 263 264 -- 更新学习计划表 265 update tcu_learnplan 266 set learnplan_dec04 = learnplan_dec04 + 1, 267 learnplan_dec05 = learnplan_dec05 - 1 268 where learnplan_id = xxjhID; 269 -- 获取学习计划中的计划人数,已签到人数 270 select learnplan_dec04, learnplan_dec01 271 into xxjhPlanNumber, xxjhAlreadyCourse 272 from tcu_learnplan 273 where learnplan_id = xxjhID; 274 -- 如果学习计划中的计划人数=已签到人数,则此学习计划的状态设置为完成 275 if (xxjhPlanNumber = xxjhAlreadyCourse) then 276 update tcu_learnplan 277 set learnplan_int03 = 1003 278 where learnplan_id = xxjhID; 279 end if; 280 281 -- 更新订单表 282 update tc_contract tct 283 set cntrt_dec03 = cntrt_dec03 + 1, cntrt_dec09 = cntrt_dec09 - 1 284 where tct.contract_id = ddID; 285 286 -- 更新客户状态 :如果客户所在客户池,不是已购池,则 1 把客户状态改为:迈向签到状态 2 记录客户状态变更表 287 select acct_int02, acct_int03 288 into qdAccountBaohuYigou, khStatePrew 289 from tc_account 290 where account_id = qdAccountid; 291 292 if (qdAccountBaohuYigou <> 1004) then 293 -- 1 更改客户状态 294 update tc_account 295 set acct_int03 = 1010 296 where account_id = qdAccountid; 297 -- 2 写更改客户状态日志表及相关 298 -- 2.1 写更改客户状态日志表 299 insert into tcu_cuschange 300 (ORG_ID, 301 cuschange_id, 302 account_id, 303 owner_user_id, 304 create_user_id, 305 create_time, 306 modify_user_id, 307 modify_time, 308 dept_id, 309 cuschange_int03, 310 cuschange_int04) 311 values 312 (1, 313 (select max(cuschange_id) + 1 from tcu_cuschange), 314 qdAccountid, 315 in_UserID, 316 in_UserID, 317 ddIDCreateTime, -- 签到表对应订单的创建时间 318 in_UserID, 319 sysdate, 320 (select dept_id from tc_user where user_id = in_UserID), -- 用户所在的部门ID 321 khStatePrew, 322 1010); 323 324 -- 2.2 写更改客户状态日志表 tcu_cuschange_attr 表 325 insert into tcu_cuschange_attr 326 (org_id, cuschange_ID, cuschange_refid03, cuschange_refid04) 327 values 328 (1, (select max(cuschange_id) from tcu_cuschange), in_UserID, 0); 329 330 -- 2.3 写更改客户状态日志表 tcu_cuschange_xattr 表 331 insert into tcu_cuschange_xattr 332 (org_id, 333 cuschange_ID, 334 cuschange_refid05, 335 cuschange_refid06, 336 cuschange_refid07, 337 cuschange_refid08) 338 values 339 (1, (select max(cuschange_id) from tcu_cuschange), 0, 0, 0, 0); 340 341 end if; 342 343 -- 获取要返回的信息 344 SELECT tat.account_name, 345 t.yckb_int01, -- 大组 346 tc.contact_name, 347 ub.user_name, 348 -- substr(to_char(t.yckb_int09), 3, 2), 349 t.yckb_int09, -- 小组 350 jp.jiaoxplan_name, 351 t.org_id, 352 t.yckb_id 353 into out_Customer, 354 out_SGroup, 355 out_Student, 356 out_Tutor, 357 out_Group, 358 out_Course, 359 out_org_id, 360 out_yckb_id 361 FROM tcu_yckb t 362 left join tc_account tat 363 on tat.account_id = t.account_id 364 left join tcu_yckb_attr b 365 on t.yckb_id = b.yckb_id 366 and b.org_id = t.org_id 367 left join tcu_yckb_1_1 c 368 on t.yckb_id = c.yckb_id 369 and c.org_id = t.org_id 370 left join tc_user ub 371 on b.yckb_refid04 = ub.user_id 372 and ub.org_id = b.org_id 373 left join tc_contact tc 374 on t.yckb_refid01 = tc.contact_id 375 and tc.org_id = t.org_id 376 left join tcu_jiaoxplan jp 377 on t.yckb_refid02 = jp.jiaoxplan_id 378 and jp.org_id = t.org_id 379 WHERE QRCODE = qdQRcode 380 and t.yckb_id = qdID 381 and rownum = 1; 382 383 -- 得到大组信息 384 if out_SGroup <> '0' then 385 select distinct enum_value 386 into out_SGroup 387 from tc_enum_str 388 where attr_name = 'yckb.newdazu' 389 and enum_key = out_SGroup 390 order by enum_key desc; 391 end if; 392 393 -- 得到小组信息 394 if out_Group <> '0' then 395 out_Group := substr(out_Group, 3, 2); 396 end if; 397 398 -- 获取到实际的appID 399 select appid into in_the_AppID from ESI_Client where authno = in_AppID; 400 -- 2 写签到日志表 401 402 insert into esi_signinlog 403 (org_id, 404 yckb_id, 405 appid, 406 userid, 407 qrcode, 408 course, 409 student, 410 tutor, 411 learninggroup, 412 signintime, 413 status) 414 values 415 (out_org_id, 416 out_yckb_id, 417 in_the_AppID, 418 in_UserID, 419 qdQRcode, 420 out_Course, 421 out_Student, 422 out_Tutor, 423 out_Group, 424 sysdate() - 1 / 3, 425 in_Status); 426 427 commit; 428 out_Flag := 100; 429 exception 430 when others then 431 432 out_sqlcode := sqlcode; 433 out_sqlerrm := sqlerrm; 434 435 rollback; 436 out_Flag := 999; 437 438 end; 439 440 <<NoXueXiPlan>> 441 if (out_Flag is null) then 442 out_Flag := 101; -- 没找到对应的学习计划 443 out_sqlerrm := '没找到对应的学习计划。'; 444 end if; 445 446 <<TheCourceIsOver>> 447 if (out_Flag is null) then 448 out_Flag := 103; -- 当前课程已结束 449 out_sqlerrm := '该课程已结束,请确认。'; 450 end if; 451 452 <<CantQianDao>> 453 if (out_Flag is null) then 454 out_Flag := 104; -- 未到签到时间 455 out_sqlerrm := '该课程尚未开始签到,请确认。'; 456 end if; 457 458 <<PayFirst>> 459 if (out_Flag is null) then 460 out_Flag := 105; -- 有未收款金额 461 out_sqlerrm := '未收款金额:¥' || to_char(out_unpayed_amount) || '元'; 462 end if; 463 464 <<TheQrCodeAlreadySigned>> 465 if (out_Flag is null) then 466 out_Flag := 106; -- 此二维码已经签到过 467 out_sqlerrm := '此二维码已经签到过,请确认。'; 468 end if; 469 470 <<TheQrCodeTypeIsnotCanjia>> 471 if (out_Flag is null) then 472 out_Flag := 108; -- 此签到表的参课判定不是参加 473 out_sqlerrm := '此签到表的参课判定不是参加,请确认。'; 474 end if; 475 476 <<TheQrCodeTypeIsZhengShi>> 477 if (out_Flag is null) then 478 out_Flag := 107; -- 此签到表的类型为正式课 479 out_sqlerrm := '此签到表的类型为正式课,请确认。'; 480 end if; 481 482 <<InvalidQrCode>> 483 if (out_Flag is null) then 484 out_Flag := 102; -- 非法的签到二维码 485 out_sqlerrm := '不可识别的签到二维码,请确认。'; 486 end if; 487 488 end;
1 create or replace procedure ESI_GetLearnPlan( 2 in_phone_number in varchar2, 3 in_company_name in varchar2, 4 in_status in int, 5 out_learnPlanId out int, --学习计划ID 6 out_course_name out varchar2, --课程名称 7 out_status out int, --0:未开课、1:已开课、2:全部 8 out_start_date out varchar2, --课程开始日期 9 out_end_date out varchar2, --课程结束日期 10 out_students out varchar2, --已签到学员姓名数组 11 out_plan_count out int, --签到人数 12 out_is_confirm out int , --是否确认 (true或false) 13 out_is_manager out boolean --是否为确认人 14 ) as 15 tc_account_id varchar2(22); --客户Id 16 begin 17 18 19 20 --获取客户Id 21 22 select a.account_id into tc_account_id from tc_account a left join tc_account_attr b on a.account_id=b.account_id 23 where a.org_id=1 and a.org_id=b.org_id and a.account_id=b.account_id 24 and a.account_name= in_company_name 25 and ( 26 a.account_mobile_phone = in_phone_number 27 or a.account_phone=in_phone_number 28 or b.acct_char14= in_phone_number 29 30 or exists( 31 select 1 from tc_contact c where c.org_id=1 and (c.mobile= in_phone_number or c.cnct_char03= in_phone_number) and c.account_id=a.account_id 32 ) 33 ); 34 35 /*if tc_account_id = null then 36 tc_account_id := 0; 37 end if; 38 */ 39 --根据客户取学习计划 40 select l.learnplan_id , --学习计划ID 41 l.learnplan_int01 , --是否确认 (true或false) 42 l.learnplan_dec04 , --签到人数 43 l.learnplan_start_date, --开始时间 44 l.learnplan_end_date, --结束日期 45 l.learnplan_name, --课程名称 46 47 CASE WHEN in_status=0 then 1 else l.learnplan_stage --状态0:未开课、1:已开课、2:全部 48 into out_learnPlanId ,out_is_confirm , out_plan_count ,out_start_date, out_end_date ,out_course_name,out_status 49 from tcu_learnplan l 50 where l.org_id=1 51 and l.account_id=tc_account_id 52 and l.learnplan_type='2151'; --正式学习计划 53 54 55 56 57 58 if in_status=0 then --未开课 加下面条件 59 60 61 and if then 62 exists( 63 select 1 from tcu_jiaoxplan j where j.org_id=1 and j.jiaoxplan_date01 > sysdate and j.jiaoxplan_id=a.learnplan_refid02 64 ) 65 end if 66 67 68 69 end if 70 71 --去签到表里获取 72 73 74 75 76 77 78 79 80 81 82 83 end ESI_GetLearnPlan;
ESI_MARKSTATE
1 CREATE OR REPLACE PROCEDURE "ESI_MARKSTATE" (in_QRCode in varchar2, 2 in_State in int, 3 out_Flag out number, 4 out_sqlcode out int, 5 out_sqlerrm out varchar2) as 6 /* 7 范 围:和微众对接 8 作 用:更新迈向签到课程的“有效到场/合格总裁 "1001:是;1002:否;1003:无名片"” 9 发生时间:微众调用我们更新签到接口后 10 最后更新:2015-05-08 pm 11 */ 12 the_State int; 13 out_the_Flag int; 14 begin 15 16 if in_State = 0 then 17 the_State := 1001; 18 elsif in_State = 1 then 19 the_State := 1002; 20 elsif in_State = 2 then 21 the_State := 1003; 22 end if; 23 24 begin 25 26 select count(yckb_id) 27 into out_the_Flag 28 from tcu_yckb 29 where yckb_int03 = 1001 -- 已签到 30 and qrcode = in_QRCode; 31 32 if out_the_Flag = 0 then 33 out_the_Flag := null; 34 goto InvalidQrCode; 35 end if; 36 37 update tcu_yckb set yckb_int06 = the_State where qrcode = in_QRCode; 38 39 out_Flag := 100; 40 commit; 41 exception 42 when others then 43 out_sqlcode := sqlcode; 44 45 out_sqlerrm := sqlerrm; 46 47 rollback; 48 out_Flag := 999; 49 50 end; 51 52 <<InvalidQrCode>> 53 if (out_Flag is null) then 54 out_Flag := 105; -- 非法的签到二维码 55 out_sqlerrm := '不可识别的签到二维码,请确认。'; 56 end if; 57 58 end;