75
75
import apijson .Log ;
76
76
import apijson .RequestMethod ;
77
77
import apijson .StringUtil ;
78
+ import apijson .demo .CompareUtil ;
78
79
import apijson .demo .DemoFunctionParser ;
79
80
import apijson .demo .DemoParser ;
80
81
import apijson .demo .DemoSQLConfig ;
89
90
import apijson .orm .exception .ConflictException ;
90
91
import apijson .orm .exception .NotExistException ;
91
92
import apijson .orm .exception .OutOfRangeException ;
93
+ import apijson .orm .model .TestRecord ;
92
94
import apijson .router .APIJSONRouterController ;
93
95
94
96
import static apijson .RequestMethod .DELETE ;
104
106
import static apijson .framework .APIJSONConstant .FUNCTION_ ;
105
107
import static apijson .framework .APIJSONConstant .ID ;
106
108
import static apijson .framework .APIJSONConstant .REQUEST_ ;
109
+ import static apijson .framework .APIJSONConstant .TEST_RECORD_ ;
107
110
import static apijson .framework .APIJSONConstant .USER_ID ;
108
111
import static apijson .framework .APIJSONConstant .VERSION ;
109
112
import static org .springframework .http .HttpHeaders .COOKIE ;
@@ -643,6 +646,7 @@ private apijson.JSONRequest newVerifyRequest(int type, String phone, String veri
643
646
644
647
645
648
public static final String LOGIN = "login" ;
649
+ public static final String AS_DB_ACCOUNT = "asDBAccount" ;
646
650
public static final String REMEMBER = "remember" ;
647
651
public static final String DEFAULTS = "defaults" ;
648
652
@@ -653,12 +657,12 @@ private apijson.JSONRequest newVerifyRequest(int type, String phone, String veri
653
657
* @return
654
658
* @see
655
659
* <pre>
656
- {
657
- "type": 0, //登录方式,非必须 0-密码 1-验证码
658
- "phone": "13000082001",
659
- "password": "1234567",
660
- "version": 1 //全局版本号,非必须
661
- }
660
+ {
661
+ "type": 0, //登录方式,非必须 0-密码 1-验证码
662
+ "phone": "13000082001",
663
+ "password": "1234567",
664
+ "version": 1 //全局版本号,非必须
665
+ }
662
666
* </pre>
663
667
*/
664
668
@ PostMapping (LOGIN ) //TODO 改 SQLConfig 里的 dbAccount, dbPassword,直接用数据库鉴权
@@ -670,6 +674,7 @@ public JSONObject login(@RequestBody String request, HttpSession session) {
670
674
int version ;
671
675
Boolean format ;
672
676
boolean remember ;
677
+ Boolean asDBAccount ;
673
678
JSONObject defaults ;
674
679
try {
675
680
requestObject = DemoParser .parseRequest (request );
@@ -695,6 +700,7 @@ public JSONObject login(@RequestBody String request, HttpSession session) {
695
700
version = requestObject .getIntValue (VERSION );
696
701
format = requestObject .getBoolean (FORMAT );
697
702
remember = requestObject .getBooleanValue (REMEMBER );
703
+ asDBAccount = requestObject .getBoolean (AS_DB_ACCOUNT );
698
704
defaults = requestObject .getJSONObject (DEFAULTS ); //默认加到每个请求最外层的字段
699
705
requestObject .remove (VERSION );
700
706
requestObject .remove (FORMAT );
@@ -705,7 +711,6 @@ public JSONObject login(@RequestBody String request, HttpSession session) {
705
711
}
706
712
707
713
708
-
709
714
//手机号是否已注册
710
715
JSONObject phoneResponse = new DemoParser (HEADS , false ).parseResponse (
711
716
new JSONRequest (
@@ -735,7 +740,7 @@ public JSONObject login(@RequestBody String request, HttpSession session) {
735
740
}
736
741
737
742
//校验凭证
738
- if (isPassword ) {//password密码登录
743
+ if (isPassword ) { //password 密码登录
739
744
response = new JSONResponse (
740
745
new DemoParser (HEADS , false ).parseResponse (
741
746
new JSONRequest (new Privacy (userId ).setPassword (password ))
@@ -774,6 +779,7 @@ public JSONObject login(@RequestBody String request, HttpSession session) {
774
779
session .setAttribute (USER_ , user ); //用户
775
780
session .setAttribute (PRIVACY_ , privacy ); //用户隐私信息
776
781
session .setAttribute (REMEMBER , remember ); //是否记住登录
782
+ session .setAttribute (AS_DB_ACCOUNT , asDBAccount ); //是否作为数据库账号密码
777
783
session .setMaxInactiveInterval (60 *60 *24 *(remember ? 7 : 1 )); //设置session过期时间
778
784
779
785
response .put (REMEMBER , remember );
@@ -790,7 +796,7 @@ public JSONObject login(@RequestBody String request, HttpSession session) {
790
796
public JSONObject logout (HttpSession session ) {
791
797
SESSION_MAP .remove (session .getId ());
792
798
793
- long userId ;
799
+ Long userId ;
794
800
try {
795
801
userId = DemoVerifier .getVisitorId (session );//必须在session.invalidate();前!
796
802
Log .d (TAG , "logout userId = " + userId + "; session.getId() = " + (session == null ? null : session .getId ()));
@@ -1366,17 +1372,19 @@ public String execute(@RequestBody String request, HttpSession session) {
1366
1372
JSONObject req = JSON .parseObject (request );
1367
1373
String database = req .getString ("database" );
1368
1374
String uri = req .getString ("uri" );
1375
+ String account = req .getString ("account" );
1376
+ String password = req .getString ("password" );
1369
1377
String sql = StringUtil .getTrimedString (req .getString ("sql" ));
1370
1378
JSONArray arg = req .getJSONArray ("arg" );
1371
1379
List <Object > valueList = arg ;
1372
1380
1373
1381
DemoSQLExecutor executor = new DemoSQLExecutor ();
1374
1382
DemoSQLConfig config = new DemoSQLConfig ();
1375
1383
1376
- if (StringUtil .isNotEmpty (uri )) {
1377
- config .setDBUri (uri );
1378
- }
1379
1384
config .setDatabase (database ); // "NEBULA"); //
1385
+ config .setDBUri (uri );
1386
+ config .setDBAccount (account );
1387
+ config .setDBPassword (password );
1380
1388
config .setPrepared (true );
1381
1389
config .setPreparedValueList (valueList );
1382
1390
@@ -1417,16 +1425,16 @@ public String execute(@RequestBody String request, HttpSession session) {
1417
1425
long executeDuration = System .currentTimeMillis () - executeStartTime ;
1418
1426
1419
1427
ResultSet rs = statement .getResultSet ();
1420
- ResultSetMetaData rsmd = rs .getMetaData ();
1421
- int length = rsmd .getColumnCount ();
1428
+ ResultSetMetaData rsmd = rs == null ? null : rs .getMetaData ();
1429
+ int length = rsmd == null ? 0 : rsmd .getColumnCount ();
1422
1430
1423
1431
JSONArray arr = new JSONArray ();
1424
1432
1425
1433
long cursorDuration = 0 ;
1426
1434
long rsDuration = 0 ;
1427
1435
1428
1436
long cursorStartTime = System .currentTimeMillis ();
1429
- while (rs .next ()) {
1437
+ while (rs != null && rs .next ()) {
1430
1438
cursorDuration += System .currentTimeMillis () - cursorStartTime ;
1431
1439
1432
1440
JSONObject obj = new JSONObject (true );
0 commit comments