def countUserDB(self, server_id): logger.info("enter") sql = "select count(*) from %s where server_id = '%s' " % ( self.table_name, server_id) sqlOper = SQLOper() count = sqlOper.executeSql(sql) return count[0][0]
def insertUser2DB(self, user): logger.info("enter") # print("AAA"+user.data.get("wechat_no","")+user.data.get("qq_no","")) if (user.data.get("wechat_no", "") + user.data.get("qq_no", "")).strip().__len__() == 0: # print("qq号, 微信号 不同时为空") msg = "qq号, 微信号 不同时为空" logger.error(msg) return FAILURE.setMsg(msg) checkRes = self.check.uniqueUserCheck( user.data, "user_id").uniqueUserCheck(user.data, "qq_no").uniqueUserCheck( user.data, "wechat_no").unique_check if (checkRes == False): msg = "{0}={1}含有重复数据,请确认后输入".format( self.check.un_unique_key, user.data[self.check.un_unique_key]) logger.error(msg) return FAILURE.setMsg(msg) sqlOper = SQLOper() sqlRes = sqlOper.executeInsertSql(self.table_name, user.pattern, user.value_str) if (sqlRes): msg = "insert{:^25}SUCCESS".format(user.data["user_id"]) logger.info(msg) return SUCCESS.setMsg(msg) else: msg = "insert FAIL" logger.info(msg) return SUCCESS.setMsg(msg)
def countUserDB(self, user_id): return 0 #TODO dangban sql = "select count(*) from %s where user_id = '%s' " % ( self.table_name, user_id) sqlOper = SQLOper() count = sqlOper.executeSql(sql) return count[0][0]
def selectServer(self, which, data): logger.info("enter") cond = "" for k, v in data.items(): cond = " %s and %s='%s' " % (cond, k, v) sql = "select %s from %s where 1=1 %s" % (which, self.table_name, cond) sqlOper = SQLOper() res = sqlOper.executeSql(sql) return res
def updateUserAttr(self, key, value, user_id): logger.info("enter") # 根据user_id 修改数据 sqlOper = SQLOper() res = sqlOper.executeUpdateSql(self.table_name, key, value, "user_id", user_id) if res: logger.info("updateUserAttr SUCCESS") else: logger.info("updateUserAttr FAIL") return res
def selectUserFromDBCon1(self, which, key, value): logger.info("enter") sqlOper = SQLOper() res = sqlOper.executeSelectCondition1(which, self.table_name, key, value) if (res != ""): logger.info("select SUCCESS") return res else: logger.info("select FAIL")
def selectUserFromDBCon2(self, which, key, value, key2, value2): logger.info("select oper") sqlOper = SQLOper() res = sqlOper.executeSelectCondition2(which, self.table_name, key, value, key2, value2) if res != "": print("select SUCCESS") return res else: print("select FAIL")
def updateServer(self, server_id, data): logger.info("enter") if self.countUserDB(server_id) == 1: sqlOper = SQLOper() str_update = self.getUpdateStr(data) res = sqlOper.executeSomeUpdateSql(self.table_name, str_update, "server_id", server_id) logger.info("update server_id={} success".format(server_id)) return SUCCESS.setRet( msg="update server_id={} success".format(server_id), data={"res": res}) else: logger.error("user_id 不存在") return FAILURE.setRet(msg="user_id 不存在")
def uniqueCheck(self, key, value): logger.info("enter") sql = "select count(*) from %s where %s=%s" % (self.table_name, key, value) # print(sql) sqlOper = SQLOper() count = sqlOper.executeSql(sql)[0][0] if count > 0: logger.info("%s=%s is not only" % (key, value)) self.unique_check = False else: logger.info("%s=%s is only" % (key, value)) self.unique_check = True return self
def insertRequset(self, request): sqlOper = SQLOper() sqlRes = sqlOper.executeInsertSql(self.table_name, request.pattern, request.value_str) if (sqlRes): logger.info("insert{:^25}SUCCESS".format(request.data['req_no'])) ret = SUCCESS else: logger.error(" insert FAIL {}={} ".format("req_no", request.data['req_no'])) ret = FAILURE.setRet(msg=" insert FAIL {}={} ".format( "req_no", request.data['req_no']))
def updateBalance(self, user_id, data): logger.info("enter") if self.countUserDB(user_id) != 1: logger.error("user_id 不存在") return FAILURE.setMsg("user_id 不存在") sqlOper = SQLOper() str_update = self.getUpdateStr(data) res = sqlOper.executeSomeUpdateSql(self.table_name, str_update, "user_id", user_id) if res is False: logger.error("update balance failed") return FAILURE.setMsg("update balance failed") logger.info("update user_id={} success".format(user_id)) return SUCCESS.setMsg( "update user_id={} success".format(user_id)).setData({"res": res})
def insertTrans(self, trans): logger.info("enter") user_id = trans.data["user_id"] trans_cd = trans.data["trans_cd"] sqlOper = SQLOper() sqlRes = sqlOper.executeInsertSql(self.table_name, trans.pattern, trans.value_str) if (sqlRes): logger.info("insert user_id={},trans_cd={} SUCCESS".format( user_id, trans_cd)) return SUCCESS.setRet( msg="insert user_id={},trans_cd={} SUCCESS".format( user_id, trans_cd)) else: logger.error(" insert FAILURE {}={} ".format("user_id", user_id)) return FAILURE.setRet( msg=" insert FAIL {}={} ".format("user_id", user_id))
def getServer(self, server_id): logger.info("enter") data = {} if self.countUserDB(server_id) == 1: sqlOper = SQLOper() keys = self.select_all_which.replace(" ", "").split(",") res = sqlOper.executeSelectCondition1(self.select_all_which, self.table_name, "server_id", server_id) # balance = Balance(user_id) print(res) for i in range(keys.__len__()): data.setdefault(keys[i], res[0][i]) print(data) return SUCCESS.setData(data) else: logger.error("user_id 不存在") return FAILURE.setRet(msg="user_id 不存在")
def insertBalance2DB(self, balance): logger.info("enter") user_id = balance.data["user_id"] if self.countUserDB(user_id) == 0: sqlOper = SQLOper() sqlRes = sqlOper.executeInsertSql(self.table_name, balance.pattern, balance.value_str) if (sqlRes): logger.info("insert{:^25}SUCCESS".format(user_id)) ret = SUCCESS else: logger.error(" insert FAIL {}={} ".format("user_id", user_id)) ret = FAILURE.setMsg(" insert FAIL {}={} ".format( "user_id", user_id)) else: logger.error("{}={} 已存在".format("user_id", user_id)) ret = FAILURE.setMsg("{}={} 已存在".format("user_id", user_id)) return ret
def insertServer2DB(self, server): logger.info("enter") server_id = server.data["server_id"] if self.countUserDB(server_id) == 0: sqlOper = SQLOper() sqlRes = sqlOper.executeInsertSql(self.table_name, server.pattern, server.value_str) if (sqlRes): logger.info("insert{:^25}SUCCESS".format(server_id)) ret = SUCCESS else: logger.error(" insert FAIL {}={} ".format( "server_id", server_id)) ret = FAILURE.setRet( msg=" insert FAIL {}={} ".format("server_id", server_id)) else: logger.error("{}={} 已存在".format("server_id", server_id)) ret = FAILURE.setRet( msg="{}={} 已存在".format("server_id", server_id)) return ret
def fromUserIdGetCurr(self, userId): sql = "select current_day,total_balance from tbl_balance" sqlOper = SQLOper() res = sqlOper.executeSql(sql) return res