7575import apijson .Log ;
7676import apijson .RequestMethod ;
7777import apijson .StringUtil ;
78+ import apijson .demo .CompareUtil ;
7879import apijson .demo .DemoFunctionParser ;
7980import apijson .demo .DemoParser ;
8081import apijson .demo .DemoSQLConfig ;
8990import apijson .orm .exception .ConflictException ;
9091import apijson .orm .exception .NotExistException ;
9192import apijson .orm .exception .OutOfRangeException ;
93+ import apijson .orm .model .TestRecord ;
9294import apijson .router .APIJSONRouterController ;
9395
9496import static apijson .RequestMethod .DELETE ;
104106import static apijson .framework .APIJSONConstant .FUNCTION_ ;
105107import static apijson .framework .APIJSONConstant .ID ;
106108import static apijson .framework .APIJSONConstant .REQUEST_ ;
109+ import static apijson .framework .APIJSONConstant .TEST_RECORD_ ;
107110import static apijson .framework .APIJSONConstant .USER_ID ;
108111import static apijson .framework .APIJSONConstant .VERSION ;
109112import static org .springframework .http .HttpHeaders .COOKIE ;
@@ -643,6 +646,7 @@ private apijson.JSONRequest newVerifyRequest(int type, String phone, String veri
643646
644647
645648 public static final String LOGIN = "login" ;
649+ public static final String AS_DB_ACCOUNT = "asDBAccount" ;
646650 public static final String REMEMBER = "remember" ;
647651 public static final String DEFAULTS = "defaults" ;
648652
@@ -653,12 +657,12 @@ private apijson.JSONRequest newVerifyRequest(int type, String phone, String veri
653657 * @return
654658 * @see
655659 * <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+ }
662666 * </pre>
663667 */
664668 @ PostMapping (LOGIN ) //TODO 改 SQLConfig 里的 dbAccount, dbPassword,直接用数据库鉴权
@@ -670,6 +674,7 @@ public JSONObject login(@RequestBody String request, HttpSession session) {
670674 int version ;
671675 Boolean format ;
672676 boolean remember ;
677+ Boolean asDBAccount ;
673678 JSONObject defaults ;
674679 try {
675680 requestObject = DemoParser .parseRequest (request );
@@ -695,6 +700,7 @@ public JSONObject login(@RequestBody String request, HttpSession session) {
695700 version = requestObject .getIntValue (VERSION );
696701 format = requestObject .getBoolean (FORMAT );
697702 remember = requestObject .getBooleanValue (REMEMBER );
703+ asDBAccount = requestObject .getBoolean (AS_DB_ACCOUNT );
698704 defaults = requestObject .getJSONObject (DEFAULTS ); //默认加到每个请求最外层的字段
699705 requestObject .remove (VERSION );
700706 requestObject .remove (FORMAT );
@@ -705,7 +711,6 @@ public JSONObject login(@RequestBody String request, HttpSession session) {
705711 }
706712
707713
708-
709714 //手机号是否已注册
710715 JSONObject phoneResponse = new DemoParser (HEADS , false ).parseResponse (
711716 new JSONRequest (
@@ -735,7 +740,7 @@ public JSONObject login(@RequestBody String request, HttpSession session) {
735740 }
736741
737742 //校验凭证
738- if (isPassword ) {//password密码登录
743+ if (isPassword ) { //password 密码登录
739744 response = new JSONResponse (
740745 new DemoParser (HEADS , false ).parseResponse (
741746 new JSONRequest (new Privacy (userId ).setPassword (password ))
@@ -774,6 +779,7 @@ public JSONObject login(@RequestBody String request, HttpSession session) {
774779 session .setAttribute (USER_ , user ); //用户
775780 session .setAttribute (PRIVACY_ , privacy ); //用户隐私信息
776781 session .setAttribute (REMEMBER , remember ); //是否记住登录
782+ session .setAttribute (AS_DB_ACCOUNT , asDBAccount ); //是否作为数据库账号密码
777783 session .setMaxInactiveInterval (60 *60 *24 *(remember ? 7 : 1 )); //设置session过期时间
778784
779785 response .put (REMEMBER , remember );
@@ -790,7 +796,7 @@ public JSONObject login(@RequestBody String request, HttpSession session) {
790796 public JSONObject logout (HttpSession session ) {
791797 SESSION_MAP .remove (session .getId ());
792798
793- long userId ;
799+ Long userId ;
794800 try {
795801 userId = DemoVerifier .getVisitorId (session );//必须在session.invalidate();前!
796802 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) {
13661372 JSONObject req = JSON .parseObject (request );
13671373 String database = req .getString ("database" );
13681374 String uri = req .getString ("uri" );
1375+ String account = req .getString ("account" );
1376+ String password = req .getString ("password" );
13691377 String sql = StringUtil .getTrimedString (req .getString ("sql" ));
13701378 JSONArray arg = req .getJSONArray ("arg" );
13711379 List <Object > valueList = arg ;
13721380
13731381 DemoSQLExecutor executor = new DemoSQLExecutor ();
13741382 DemoSQLConfig config = new DemoSQLConfig ();
13751383
1376- if (StringUtil .isNotEmpty (uri )) {
1377- config .setDBUri (uri );
1378- }
13791384 config .setDatabase (database ); // "NEBULA"); //
1385+ config .setDBUri (uri );
1386+ config .setDBAccount (account );
1387+ config .setDBPassword (password );
13801388 config .setPrepared (true );
13811389 config .setPreparedValueList (valueList );
13821390
@@ -1417,16 +1425,16 @@ public String execute(@RequestBody String request, HttpSession session) {
14171425 long executeDuration = System .currentTimeMillis () - executeStartTime ;
14181426
14191427 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 ();
14221430
14231431 JSONArray arr = new JSONArray ();
14241432
14251433 long cursorDuration = 0 ;
14261434 long rsDuration = 0 ;
14271435
14281436 long cursorStartTime = System .currentTimeMillis ();
1429- while (rs .next ()) {
1437+ while (rs != null && rs .next ()) {
14301438 cursorDuration += System .currentTimeMillis () - cursorStartTime ;
14311439
14321440 JSONObject obj = new JSONObject (true );
0 commit comments