You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
307 lines
6.4 KiB
307 lines
6.4 KiB
<?php
|
|
|
|
require_once __ROOT__ . "/entity/ApiToken.php";
|
|
require_once __ROOT__ . "/entity/Garbage.php";
|
|
require_once __ROOT__ . "/entity/Question.php";
|
|
require_once __ROOT__ . "/entity/Answer.php";
|
|
require_once __ROOT__ . "/entity/Manager.php";
|
|
require_once __ROOT__ . "/database/DbUtil.php";
|
|
//Token查询
|
|
abstract class AbstractTokenQuery implements DoExcute
|
|
{
|
|
// token查询结果
|
|
private $token_array = array();
|
|
|
|
/**
|
|
* TokenQuery constructor.
|
|
*/
|
|
public function __construct()
|
|
{
|
|
}
|
|
|
|
|
|
// 绑定toekn信息
|
|
public function doResult(mysqli_stmt $stmt)
|
|
{
|
|
/**
|
|
*
|
|
* $col1 $id
|
|
* $col2 $refresh_token
|
|
* $col3 $expires_in
|
|
* $col4 $end_time
|
|
* $col5 $scope
|
|
* $col6 $session_key
|
|
* $col7 $access_token
|
|
* $col8 $session_secret
|
|
*/
|
|
$stmt->bind_result($col1, $col2, $col3, $col4, $col5, $col6, $col7, $col8);
|
|
while ($stmt->fetch()) {
|
|
array_push($this->token_array, new ApiToken($col1, $col2, $col3, $col4, $col5, $col6, $col7, $col8));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function getTokenArray(): array
|
|
{
|
|
return $this->token_array;
|
|
}
|
|
|
|
function getToken(): ApiToken
|
|
{
|
|
return $this->token_array[0];
|
|
}
|
|
|
|
|
|
}
|
|
|
|
//垃圾分类查询
|
|
abstract class AbstractGarbageQuery implements DoExcute
|
|
{
|
|
// 垃圾分类查询结果
|
|
private $garbage_obj_array = array();
|
|
|
|
|
|
public function doResult(mysqli_stmt $stmt)
|
|
{
|
|
|
|
$stmt->bind_result($col1, $col2, $col3, $col4);
|
|
while ($stmt->fetch()) {
|
|
array_push($this->garbage_obj_array, new Garbage($col1, $col2, $col3, $col4));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function getGarbageObjArray(): array
|
|
{
|
|
return $this->garbage_obj_array;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
//根据垃圾名模糊匹配垃圾分类信息
|
|
function QueryGarbageWithName($sql, $keyword): AbstractGarbageQuery
|
|
{
|
|
$garbage_result = new class() extends AbstractGarbageQuery
|
|
{
|
|
public function bind_param(mysqli_stmt $stmt, array $param = null)
|
|
{
|
|
if (count($param) > 1) {
|
|
$stmt->bind_param(str_repeat("s", count($param)), $param[0], ...array_slice($param, 1));
|
|
} else {
|
|
$stmt->bind_param(str_repeat("s", count($param)), $param[0]);
|
|
}
|
|
|
|
}
|
|
};
|
|
|
|
DbUtil::query($sql, $garbage_result, $keyword);
|
|
|
|
return $garbage_result;
|
|
}
|
|
|
|
//查询问题
|
|
class QuestionQuery implements DoExcute
|
|
{
|
|
|
|
private $question_array = array();
|
|
|
|
public function bind_param(mysqli_stmt $stmt, array $param = null)
|
|
{
|
|
|
|
}
|
|
|
|
public function doResult(mysqli_stmt $stmt)
|
|
{
|
|
$stmt->bind_result($col1, $col2);
|
|
while ($stmt->fetch()) {
|
|
array_push($this->question_array, new Question($col1, $col2));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function getQuestionArray(): array
|
|
{
|
|
return $this->question_array;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
//查询问题答案
|
|
class AnswerQuery implements DoExcute
|
|
{
|
|
|
|
private $answer_array = array();
|
|
|
|
public function bind_param(mysqli_stmt $stmt, array $param = null)
|
|
{
|
|
if (!empty($param)) {
|
|
$stmt->bind_param("i", $param[0]);
|
|
}
|
|
}
|
|
|
|
public function doResult(mysqli_stmt $stmt)
|
|
{
|
|
$stmt->bind_result($col1, $col2, $col3, $col4);
|
|
while ($stmt->fetch()) {
|
|
array_push($this->answer_array, new Answer($col1, $col2, $col3, $col4));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function getAnswerArray(): array
|
|
{
|
|
return $this->answer_array;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
function get_category($category)
|
|
{
|
|
switch ($category) {
|
|
case 1:
|
|
return "可回收垃圾";
|
|
case 2:
|
|
return "有害垃圾";
|
|
case 4:
|
|
return "湿垃圾";
|
|
case 8:
|
|
return "干垃圾";
|
|
case 16:
|
|
return "大件垃圾";
|
|
}
|
|
}
|
|
|
|
//统计垃圾分类数据量
|
|
class CountGrabage implements DoExcute
|
|
{
|
|
private $result = array();
|
|
|
|
public function bind_param(mysqli_stmt $stmt, array $param = null)
|
|
{
|
|
|
|
}
|
|
|
|
public function doResult(mysqli_stmt $stmt)
|
|
{
|
|
$stmt->bind_result($col1, $col2);
|
|
while ($stmt->fetch()) {
|
|
array_push($this->result, array("category" => $col1, "category_name" => get_category($col1), "count" => $col2));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function getResult(): array
|
|
{
|
|
return $this->result;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//查询某个垃圾分类下的垃圾数据
|
|
class QueryGarbageWithCategory implements DoExcute
|
|
{
|
|
private $result_list = array();
|
|
|
|
public function bind_param(mysqli_stmt $stmt, array $param = null)
|
|
{
|
|
if (!empty($param)) {
|
|
$stmt->bind_param("iii", $param[0], ...array_slice($param, 1));
|
|
}
|
|
}
|
|
|
|
public function doResult(mysqli_stmt $stmt)
|
|
{
|
|
$stmt->bind_result($col1, $col2, $col3, $col4);
|
|
while ($stmt->fetch()) {
|
|
array_push($this->result_list, new Garbage($col1, $col2, $col3, $col4));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function getResultList(): array
|
|
{
|
|
return $this->result_list;
|
|
}
|
|
}
|
|
|
|
//查询某个垃圾分类数据量
|
|
class QueryGarbageCount implements DoExcute
|
|
{
|
|
|
|
private $count;
|
|
|
|
public function bind_param(mysqli_stmt $stmt, array $param = null)
|
|
{
|
|
if (!empty($param)) {
|
|
$stmt->bind_param("i", $param[0]);
|
|
}
|
|
}
|
|
|
|
public function doResult(mysqli_stmt $stmt)
|
|
{
|
|
$stmt->bind_result($col1);
|
|
while ($stmt->fetch()) {
|
|
$this->count = $col1;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return mixed
|
|
*/
|
|
public function getCount()
|
|
{
|
|
return $this->count;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
//查询管理
|
|
class QueryManager implements DoExcute
|
|
{
|
|
|
|
private $manager_result;
|
|
|
|
public function bind_param(mysqli_stmt $stmt, array $param = null)
|
|
{
|
|
if (!empty($param)) {
|
|
$stmt->bind_param(str_repeat("s", count($param)), $param[0], ...array_slice($param, 1));
|
|
}
|
|
}
|
|
|
|
public function doResult(mysqli_stmt $stmt)
|
|
{
|
|
$stmt->bind_result($col1, $col2, $col3, $col4);
|
|
while ($stmt->fetch()) {
|
|
$this->manager_result = new Manager($col1, $col2, $col3, $col4);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return mixed
|
|
*/
|
|
public function getManagerResult()
|
|
{
|
|
return $this->manager_result;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|