178 lines
6.7 KiB
Go
178 lines
6.7 KiB
Go
![]() |
package api_conn
|
|||
|
|
|||
|
import (
|
|||
|
"all_platform/dbpool"
|
|||
|
"database/sql"
|
|||
|
"encoding/json"
|
|||
|
"log"
|
|||
|
"net/http"
|
|||
|
|
|||
|
"github.com/gin-gonic/gin"
|
|||
|
)
|
|||
|
|
|||
|
// 输出参数
|
|||
|
type Constellation_list struct {
|
|||
|
Date string `json:"date"` //时间
|
|||
|
Signname string `json:"signname"` //星座名
|
|||
|
Data_type string `json:"data_type"` //天,周,月,明天,all
|
|||
|
}
|
|||
|
|
|||
|
// 数据库字段
|
|||
|
type Constellation_list_out struct {
|
|||
|
Date sql.NullString //时间
|
|||
|
Signname sql.NullString //星座名
|
|||
|
Week sql.NullString //周几
|
|||
|
Month sql.NullString //月Month
|
|||
|
Today sql.NullString //今天
|
|||
|
Tomorrow sql.NullString //明天
|
|||
|
}
|
|||
|
|
|||
|
// 星座
|
|||
|
func constellation(c *gin.Context) {
|
|||
|
var constellation_list Constellation_list
|
|||
|
err := json.NewDecoder(c.Request.Body).Decode(&constellation_list)
|
|||
|
if err != nil {
|
|||
|
c.JSON(http.StatusOK, gin.H{"error": err.Error()})
|
|||
|
return
|
|||
|
}
|
|||
|
log.Println(constellation_list)
|
|||
|
if constellation_list.Date != "" && constellation_list.Signname != "" && constellation_list.Data_type != "" {
|
|||
|
if constellation_list.Data_type == "all" {
|
|||
|
//查询所有数据
|
|||
|
//查询sql 获取用户信息
|
|||
|
rows, err := dbpool.Query("SELECT * FROM `all_platform`.`dt_constellation_info` WHERE DT_SIGNNAME=? AND DT_DATE=?;", constellation_list.Signname, constellation_list.Date)
|
|||
|
if err != nil {
|
|||
|
log.Println(err)
|
|||
|
}
|
|||
|
var constellation_list_out Constellation_list_out
|
|||
|
for rows.Next() {
|
|||
|
if err := rows.Scan(&constellation_list_out.Date, &constellation_list_out.Signname, &constellation_list_out.Week, &constellation_list_out.Month, &constellation_list_out.Today, &constellation_list_out.Tomorrow); err != nil {
|
|||
|
log.Println(err)
|
|||
|
}
|
|||
|
log.Println(constellation_list_out)
|
|||
|
}
|
|||
|
// typecho_userss = append(typecho_userss, itemIDStr.String)
|
|||
|
if err := rows.Err(); err != nil {
|
|||
|
log.Fatal(err)
|
|||
|
}
|
|||
|
log.Println("查询到的结果:", constellation_list_out)
|
|||
|
Str := map[string]string{
|
|||
|
"date": constellation_list_out.Date.String,
|
|||
|
"signname": constellation_list_out.Signname.String,
|
|||
|
"week": constellation_list_out.Week.String,
|
|||
|
"month": constellation_list_out.Month.String,
|
|||
|
"today": constellation_list_out.Today.String,
|
|||
|
"tomorrow": constellation_list_out.Tomorrow.String,
|
|||
|
}
|
|||
|
c.JSON(http.StatusOK, gin.H{"msg": Str})
|
|||
|
} else if constellation_list.Data_type == "week" {
|
|||
|
//查询所有数据
|
|||
|
//查询sql 获取用户信息
|
|||
|
rows, err := dbpool.Query("SELECT DT_DATE,DT_SIGNNAME,DT_WEEK FROM `all_platform`.`dt_constellation_info` WHERE DT_SIGNNAME=? AND DT_DATE=?;", constellation_list.Signname, constellation_list.Date)
|
|||
|
if err != nil {
|
|||
|
log.Println(err)
|
|||
|
}
|
|||
|
var constellation_list_out Constellation_list_out
|
|||
|
for rows.Next() {
|
|||
|
if err := rows.Scan(&constellation_list_out.Date, &constellation_list_out.Signname, &constellation_list_out.Week); err != nil {
|
|||
|
log.Println(err)
|
|||
|
}
|
|||
|
log.Println(constellation_list_out)
|
|||
|
}
|
|||
|
if err := rows.Err(); err != nil {
|
|||
|
log.Fatal(err)
|
|||
|
}
|
|||
|
log.Println("查询到的结果:", constellation_list_out)
|
|||
|
Str := map[string]string{
|
|||
|
"date": constellation_list_out.Date.String,
|
|||
|
"signname": constellation_list_out.Signname.String,
|
|||
|
"week": constellation_list_out.Week.String,
|
|||
|
}
|
|||
|
c.JSON(http.StatusOK, gin.H{"msg": Str})
|
|||
|
} else if constellation_list.Data_type == "month" {
|
|||
|
//查询所有数据
|
|||
|
//查询sql 获取用户信息
|
|||
|
rows, err := dbpool.Query("SELECT DT_DATE,DT_SIGNNAME,DT_MONTH FROM `all_platform`.`dt_constellation_info` WHERE DT_SIGNNAME=? AND DT_DATE=?;", constellation_list.Signname, constellation_list.Date)
|
|||
|
if err != nil {
|
|||
|
log.Println(err)
|
|||
|
}
|
|||
|
var constellation_list_out Constellation_list_out
|
|||
|
for rows.Next() {
|
|||
|
if err := rows.Scan(&constellation_list_out.Date, &constellation_list_out.Signname, &constellation_list_out.Month); err != nil {
|
|||
|
log.Println(err)
|
|||
|
}
|
|||
|
log.Println(constellation_list_out)
|
|||
|
}
|
|||
|
if err := rows.Err(); err != nil {
|
|||
|
log.Fatal(err)
|
|||
|
}
|
|||
|
log.Println("查询到的结果:", constellation_list_out)
|
|||
|
Str := map[string]string{
|
|||
|
"date": constellation_list_out.Date.String,
|
|||
|
"signname": constellation_list_out.Signname.String,
|
|||
|
"month": constellation_list_out.Month.String,
|
|||
|
}
|
|||
|
c.JSON(http.StatusOK, gin.H{"msg": Str})
|
|||
|
} else if constellation_list.Data_type == "today" {
|
|||
|
//查询所有数据
|
|||
|
//查询sql 获取用户信息
|
|||
|
rows, err := dbpool.Query("SELECT DT_DATE,DT_SIGNNAME,DT_TODAY FROM `all_platform`.`dt_constellation_info` WHERE DT_SIGNNAME=? AND DT_DATE=?;", constellation_list.Signname, constellation_list.Date)
|
|||
|
if err != nil {
|
|||
|
log.Println(err)
|
|||
|
}
|
|||
|
var constellation_list_out Constellation_list_out
|
|||
|
for rows.Next() {
|
|||
|
if err := rows.Scan(&constellation_list_out.Date, &constellation_list_out.Signname, &constellation_list_out.Today); err != nil {
|
|||
|
log.Println(err)
|
|||
|
}
|
|||
|
log.Println(constellation_list_out)
|
|||
|
}
|
|||
|
if err := rows.Err(); err != nil {
|
|||
|
log.Fatal(err)
|
|||
|
}
|
|||
|
log.Println("查询到的结果:", constellation_list_out)
|
|||
|
Str := map[string]string{
|
|||
|
"date": constellation_list_out.Date.String,
|
|||
|
"signname": constellation_list_out.Signname.String,
|
|||
|
"week": constellation_list_out.Week.String,
|
|||
|
"month": constellation_list_out.Month.String,
|
|||
|
"today": constellation_list_out.Today.String,
|
|||
|
"tomorrow": constellation_list_out.Tomorrow.String,
|
|||
|
}
|
|||
|
c.JSON(http.StatusOK, gin.H{"msg": Str})
|
|||
|
} else if constellation_list.Data_type == "tomorrow" {
|
|||
|
//查询所有数据
|
|||
|
//查询sql 获取用户信息
|
|||
|
rows, err := dbpool.Query("SELECT DT_DATE,DT_SIGNNAME,DT_TOMORROW FROM `all_platform`.`dt_constellation_info` WHERE DT_SIGNNAME=? AND DT_DATE=?;", constellation_list.Signname, constellation_list.Date)
|
|||
|
if err != nil {
|
|||
|
log.Println(err)
|
|||
|
}
|
|||
|
var constellation_list_out Constellation_list_out
|
|||
|
for rows.Next() {
|
|||
|
if err := rows.Scan(&constellation_list_out.Date, &constellation_list_out.Signname, &constellation_list_out.Tomorrow); err != nil {
|
|||
|
log.Println(err)
|
|||
|
}
|
|||
|
log.Println(constellation_list_out)
|
|||
|
}
|
|||
|
if err := rows.Err(); err != nil {
|
|||
|
log.Fatal(err)
|
|||
|
}
|
|||
|
log.Println("查询到的结果:", constellation_list_out)
|
|||
|
Str := map[string]string{
|
|||
|
"date": constellation_list_out.Date.String,
|
|||
|
"signname": constellation_list_out.Signname.String,
|
|||
|
"week": constellation_list_out.Week.String,
|
|||
|
"month": constellation_list_out.Month.String,
|
|||
|
"today": constellation_list_out.Today.String,
|
|||
|
"tomorrow": constellation_list_out.Tomorrow.String,
|
|||
|
}
|
|||
|
c.JSON(http.StatusOK, gin.H{"msg": Str})
|
|||
|
} else {
|
|||
|
c.JSON(http.StatusOK, gin.H{"msg": "类型匹配不成立[week,month,today,tomorrow]"})
|
|||
|
log.Println("匹配不成立")
|
|||
|
}
|
|||
|
} else {
|
|||
|
c.JSON(http.StatusOK, gin.H{"error": "参数为空"})
|
|||
|
}
|
|||
|
}
|