添加代办事项相关接口

master
zcy 2021-03-05 10:18:59 +08:00
parent 88b9cd5a9d
commit e2ca2baa65
3 changed files with 132 additions and 25 deletions

View File

@ -2,6 +2,7 @@ package controller
import ( import (
"background/db" "background/db"
"background/logs"
"background/model" "background/model"
"fmt" "fmt"
"log" "log"
@ -139,3 +140,100 @@ func (this *PlanController) Types(c *gin.Context) {
resp.Msg = "OK" resp.Msg = "OK"
resp.Status = 0 resp.Status = 0
} }
func (this *PlanController) CreateUndo(c *gin.Context) {
resp := RespBase{}
defer func() {
c.JSON(200, resp)
}()
var req model.Undo
e := c.BindJSON(&req)
if nil != e {
logs.Error(e.Error())
resp.Msg = "wrong input"
return
}
e = db.GetOrm().Model(&model.Undo{}).Create(&req).Error
if nil != e {
log.Print(e.Error())
return
}
resp.Data = nil
resp.Msg = "OK"
resp.Status = 0
}
func (this *PlanController) UpdateUndo(c *gin.Context) {
resp := RespBase{}
defer func() {
c.JSON(200, resp)
}()
var req model.Book
e := c.BindJSON(&req)
if nil != e {
resp.Msg = "wrong input"
return
}
e = db.GetOrm().Model(&model.Book{}).Update(&req).Error
if nil != e {
logs.Error(e.Error())
return
}
resp.Data = nil
resp.Msg = "OK"
resp.Status = 0
}
func (this *PlanController) GetUndo(c *gin.Context) {
type ReqGetUndo struct {
}
var req ReqGetUndo
resp := RespBase{}
defer func() {
c.JSON(200, resp)
}()
e := c.BindJSON(&req)
if nil != e {
logs.Error(e.Error())
return
}
}
func (this *PlanController) GetPageUndo(c *gin.Context) {
type ReqGetPageUndo struct {
}
var req ReqGetPageUndo
resp := RespBase{}
// limit := c.Query("limit")
// offset := c.Query("offset")
// iLmit, e := strconv.Atoi(limit)
// if nil != e {
// return
// }
// iOffset, e := strconv.Atoi(offset)
// if nil != e {
// return
// }
defer func() {
c.JSON(200, resp)
}()
e := c.BindJSON(&req)
if nil != e {
logs.Error(e.Error())
return
}
}
func DeleteUndo(c *gin.Context) {
resp := RespBase{}
defer func() {
c.JSON(200, resp)
}()
type ReqDeleteUndo struct {
}
}

View File

@ -4,21 +4,22 @@ import (
"background/db" "background/db"
"background/logs" "background/logs"
"fmt" "fmt"
"qiniupkg.com/x/log.v7"
"strings" "strings"
"qiniupkg.com/x/log.v7"
) )
type Memo struct { type Memo struct {
ID int64 `sql:"id" json:"id"` ID int64 `sql:"id" json:"id"`
Title string `sql:"title" json:"title"` Title string `sql:"title" json:"title"`
CreateTime string `sql:"create_time" json:"create_time"` CreateTime string `sql:"create_time" json:"create_time"`
Content string `sql:"content" json:"content"` Content string `sql:"content" json:"content"`
} }
func CreateMemo(memo Memo) error{ func CreateMemo(memo Memo) error {
sql := fmt.Sprintf(`insert into memo(title,create_time,content) select '%s','%s','%s' sql := fmt.Sprintf(`insert into memo(title,create_time,content) select '%s','%s','%s'
from dual where not exists (select * from memo where memo.title='%s') `, from dual where not exists (select * from memo where memo.title='%s') `,
memo.Title,memo.CreateTime,strings.Replace(memo.Content, "'", "\\'", -1),memo.Title) memo.Title, memo.CreateTime, strings.Replace(memo.Content, "'", "\\'", -1), memo.Title)
log.Print(sql) log.Print(sql)
_, e := db.GetMysqlClient().Query(sql) _, e := db.GetMysqlClient().Query(sql)
if nil != e { if nil != e {
@ -28,11 +29,11 @@ func CreateMemo(memo Memo) error{
return nil return nil
} }
func UpdateMemo(memo Memo) error{ func UpdateMemo(memo Memo) error {
sql := fmt.Sprintf(`update memo set title = '%s', sql := fmt.Sprintf(`update memo set title = '%s',
create_time = '%s', create_time = '%s',
content = '%s' where memo.id = %d`, content = '%s' where memo.id = %d`,
memo.Title,memo.CreateTime,strings.Replace(memo.Content, "'", "\\'", -1),memo.ID) memo.Title, memo.CreateTime, strings.Replace(memo.Content, "'", "\\'", -1), memo.ID)
_, e := db.GetMysqlClient().Query(sql) _, e := db.GetMysqlClient().Query(sql)
if nil != e { if nil != e {
logs.Error(e.Error()) logs.Error(e.Error())
@ -41,8 +42,8 @@ func UpdateMemo(memo Memo) error{
return nil return nil
} }
func DeleteMemo(id int32) error{ func DeleteMemo(id int32) error {
sql := fmt.Sprintf(`delete from memo where memo.id = '%d'`,id) sql := fmt.Sprintf(`delete from memo where memo.id = '%d'`, id)
log.Print(sql) log.Print(sql)
_, e := db.GetMysqlClient().Query(sql) _, e := db.GetMysqlClient().Query(sql)
if nil != e { if nil != e {
@ -52,27 +53,27 @@ func DeleteMemo(id int32) error{
return nil return nil
} }
func ReadMemo(id int32) ([]Memo,error){ func ReadMemo(id int32) ([]Memo, error) {
memo := []Memo{} memo := []Memo{}
sql := fmt.Sprintf(`select * from memo where memo.id = '%d'`,id) sql := fmt.Sprintf(`select * from memo where memo.id = '%d'`, id)
e := db.GetMysqlClient().Query2(sql,&memo) e := db.GetMysqlClient().Query2(sql, &memo)
if nil != e { if nil != e {
logs.Error(e.Error()) logs.Error(e.Error())
return nil,e return nil, e
} }
return memo,nil return memo, nil
} }
func GetMemos(title string,limit int,offset int) ([]Memo,error) { func GetMemos(title string, limit int, offset int) ([]Memo, error) {
memo := []Memo{} memo := []Memo{}
sql := fmt.Sprintf(`select * from memo where memo.title like '%s%%' limit %d offset %d`, sql := fmt.Sprintf(`select * from memo where memo.title like '%s%%' limit %d offset %d`,
title,limit,offset) title, limit, offset)
log.Print(sql) log.Print(sql)
e := db.GetMysqlClient().Query2(sql,&memo) e := db.GetMysqlClient().Query2(sql, &memo)
if nil != e { if nil != e {
logs.Error(e.Error()) logs.Error(e.Error())
return nil,e return nil, e
} }
return memo,nil return memo, nil
} }

View File

@ -18,10 +18,18 @@ type Plan struct {
Type uint32 `gorm:"column:type" json:"type"` Type uint32 `gorm:"column:type" json:"type"`
} }
type Undo struct {
ID int32 `json:"id" gorm:"column:id" sql:"id"`
Content string `json:"content" gorm:"column:content" sql:"content"`
SpendTime int32 `json:"spend_time" gorm:"column:spend_time" sql:"spend_time"`
Child int32 `json:"child" gorm:"column:child" sql:"child"`
Level int32 `json:"level" gorm:"column:level" sql:"level"`
Type int32 `json:"type" gorm:"column:type" sql:"type"`
}
type PlanType struct { type PlanType struct {
ID uint32 `gorm:"column:id;primary_key" json:"id"` ID uint32 `gorm:"column:id;primary_key" json:"id"`
TypeName string `gorm:"column:type_name;" json:"type_name"` TypeName string `gorm:"column:type_name;" json:"type_name"`
} }
func (m *PlanType) TableName() string { func (m *PlanType) TableName() string {