123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- package controllers
- import (
- "Cold_Api/controllers/lib"
- "Cold_Api/models/Account"
- "Cold_Api/models/Device"
- "Cold_Api/models/RawSql"
- "fmt"
- beego "github.com/beego/beego/v2/server/web"
- "strings"
- )
- // Handle
- type RawSqlController struct {
- beego.Controller
- Admin_r Account.Admin // 登陆的用户
- }
- func (c *RawSqlController) Prepare() {
- GetCookie := c.Ctx.GetCookie("User_tokey")
- GetString := c.GetString("User_tokey")
- User_tokey := GetCookie
- if len(User_tokey) == 0 {
- User_tokey = GetString
- }
- c.Admin_r = *Account.Admin_r
- }
- func (c *RawSqlController) List_Post() {
- var id int64
- var err error
- id, _ = c.GetInt64("id")
- T_name := c.GetString("T_name")
- T_text := c.GetString("T_text")
- var_ := RawSql.RawSql{
- T_name: T_name,
- T_text: T_text,
- }
- T_SQL_ := strings.ToLower(T_text)
- if strings.Contains(T_SQL_, "show") ||
- strings.Contains(T_SQL_, "create") ||
- strings.Contains(T_SQL_, "drop") ||
- strings.Contains(T_SQL_, "desc") ||
- strings.Contains(T_SQL_, "alter") ||
- strings.Contains(T_SQL_, "insert") ||
- strings.Contains(T_SQL_, "update") ||
- strings.Contains(T_SQL_, "delete") {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败,有违禁 语法!"}
- c.ServeJSON()
- return
- }
- if id > 0 {
- var_.Id = int(id)
- is := RawSql.Update_TRawSql(var_, "T_name", "T_text")
- if !is {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- } else {
- _, err = RawSql.Add_RawSql(var_)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
- c.ServeJSON()
- return
- }
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *RawSqlController) List_Del() {
- Id, _ := c.GetInt("Id")
- if Id > 0 {
- RawSql_r := RawSql.Read_RawSql_ById(Id)
- RawSql.Delete_RawSql(RawSql_r)
- } else {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "e!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 执行 SQL
- func (c *RawSqlController) Raw() {
- T_id := c.GetString("T_id")
- if len(T_id) != 5 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
- c.ServeJSON()
- return
- }
- RawSql_r := RawSql.Read_RawSql_ByT_id(T_id)
- if RawSql_r.Id == 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
- c.ServeJSON()
- return
- }
- T_data := c.GetString("T_data")
- fmt.Println(" 执行SQL:", T_id, " => [", T_data, "] ", c.Admin_r.T_uuid, c.Admin_r.T_name)
- var T_dataL []string
- for _, v := range strings.Split(T_data, "|") {
- if len(v) > 0 {
- T_dataL = append(T_dataL, v)
- }
- }
- str_, Params := Device.Read_SqlRawL(RawSql_r.T_text, T_dataL)
- if len(str_) > 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "ok!", Data: str_}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Params}
- c.ServeJSON()
- return
- }
|