2021-02-16 06:05:21 +00:00
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
|
|
|
"background/db"
|
2021-03-05 02:18:59 +00:00
|
|
|
"background/logs"
|
2021-02-16 06:05:21 +00:00
|
|
|
"background/model"
|
2021-02-16 07:44:26 +00:00
|
|
|
"fmt"
|
2021-02-16 06:05:21 +00:00
|
|
|
"log"
|
|
|
|
"strconv"
|
2021-07-17 15:53:21 +00:00
|
|
|
"time"
|
2021-02-16 06:05:21 +00:00
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
type PlanController struct {
|
|
|
|
}
|
|
|
|
|
2021-12-30 16:38:06 +00:00
|
|
|
func (t *PlanController) GetPlan(c *gin.Context) {
|
2021-02-16 06:05:21 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-12-30 16:38:06 +00:00
|
|
|
func (t *PlanController) GetPlanDates(c *gin.Context) {
|
2021-02-16 06:05:21 +00:00
|
|
|
type Req struct {
|
|
|
|
Date string `json:"date"`
|
|
|
|
}
|
|
|
|
var req Req
|
|
|
|
|
|
|
|
resp := RespBase{
|
|
|
|
Msg: "ERROR",
|
|
|
|
Status: 23,
|
|
|
|
}
|
|
|
|
defer c.JSON(200, &resp)
|
|
|
|
e := c.BindJSON(&req)
|
|
|
|
if nil != e {
|
|
|
|
log.Print(e.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
plan := []model.Plan{}
|
|
|
|
e = db.GetOrm().Model(&plan).Where("date = ?", req.Date).Find(&plan).Error
|
|
|
|
if nil != e {
|
|
|
|
log.Print(e.Error())
|
|
|
|
}
|
|
|
|
resp.Status = 0
|
|
|
|
resp.Msg = "OK"
|
|
|
|
resp.Data = plan
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-12-30 16:38:06 +00:00
|
|
|
func (t *PlanController) AddPlan(c *gin.Context) {
|
2021-02-16 06:05:21 +00:00
|
|
|
var req model.Plan
|
|
|
|
resp := RespBase{Msg: "r", Status: 0, Data: nil}
|
|
|
|
defer c.JSON(200, &resp)
|
|
|
|
e := c.BindJSON(&req)
|
|
|
|
if nil != e {
|
|
|
|
log.Print(e.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
e = db.GetOrm().Create(&req).Error
|
|
|
|
if nil != e {
|
|
|
|
log.Print(e.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.Msg = "OK"
|
|
|
|
resp.Status = 0
|
|
|
|
}
|
|
|
|
|
2021-12-30 16:38:06 +00:00
|
|
|
func (t *PlanController) DelPlan(c *gin.Context) {
|
2021-02-16 06:05:21 +00:00
|
|
|
resp := RespBase{Msg: "r", Status: 0, Data: nil}
|
|
|
|
defer c.JSON(200, &resp)
|
|
|
|
var e error
|
|
|
|
iid := 0
|
|
|
|
id := c.Query("id")
|
|
|
|
if "" != id {
|
|
|
|
iid, e = strconv.Atoi(id)
|
|
|
|
if nil != e {
|
|
|
|
log.Print(e.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
plan := model.Plan{}
|
|
|
|
plan.ID = uint32(iid)
|
|
|
|
e = db.GetOrm().Delete(&plan).Error
|
|
|
|
if nil != e {
|
|
|
|
log.Print(e.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
resp.Msg = "OK"
|
|
|
|
resp.Status = 0
|
|
|
|
}
|
2021-02-16 07:44:26 +00:00
|
|
|
|
|
|
|
type ReqDate struct {
|
|
|
|
Date string `gorm:"date" json:"date"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ReqDate) TableName() string {
|
|
|
|
return "plan"
|
|
|
|
}
|
|
|
|
|
2021-12-30 16:38:06 +00:00
|
|
|
func (t *PlanController) PlanDay(c *gin.Context) {
|
2021-02-16 07:44:26 +00:00
|
|
|
var req ReqDate
|
|
|
|
resp := RespBase{
|
|
|
|
Msg: "ERROR",
|
|
|
|
Status: 23,
|
|
|
|
}
|
|
|
|
defer c.JSON(200, &resp)
|
|
|
|
|
|
|
|
e := c.BindJSON(&req)
|
|
|
|
if nil != e {
|
|
|
|
log.Print(e.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ret := make([]ReqDate, 1)
|
|
|
|
sql := fmt.Sprintf(`SELECT distinct plan.date FROM plan where DATE_FORMAT(plan.date,'%%Y-%%m')=DATE_FORMAT('%s','%%Y-%%m')`, req.Date)
|
|
|
|
log.Print(sql)
|
|
|
|
e = db.GetOrm().Raw(sql).Find(&ret).Error
|
|
|
|
if nil != e {
|
|
|
|
log.Print(e.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
resp.Data = ret
|
|
|
|
resp.Msg = "OK"
|
|
|
|
resp.Status = 0
|
|
|
|
}
|
2021-02-21 13:39:37 +00:00
|
|
|
|
2021-12-30 16:38:06 +00:00
|
|
|
func (t *PlanController) Types(c *gin.Context) {
|
2021-02-21 13:39:37 +00:00
|
|
|
resp := RespBase{
|
|
|
|
Msg: "ERROR",
|
|
|
|
Status: 23,
|
|
|
|
}
|
|
|
|
defer c.JSON(200, &resp)
|
|
|
|
rets := []model.PlanType{}
|
|
|
|
e := db.GetOrm().Model(&model.PlanType{}).Find(&rets).Error
|
|
|
|
if nil != e {
|
|
|
|
log.Print(e.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
resp.Data = rets
|
|
|
|
resp.Msg = "OK"
|
|
|
|
resp.Status = 0
|
|
|
|
}
|
2021-03-05 02:18:59 +00:00
|
|
|
|
2021-12-30 16:38:06 +00:00
|
|
|
func (t *PlanController) CreateUndo(c *gin.Context) {
|
2021-03-05 02:18:59 +00:00
|
|
|
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
|
|
|
|
}
|
2021-07-17 15:53:21 +00:00
|
|
|
req.CreateTime = time.Now().Format("2006-01-02 15:04:05")
|
2021-03-05 02:18:59 +00:00
|
|
|
e = db.GetOrm().Model(&model.Undo{}).Create(&req).Error
|
|
|
|
if nil != e {
|
|
|
|
log.Print(e.Error())
|
|
|
|
return
|
|
|
|
}
|
2021-03-09 15:21:12 +00:00
|
|
|
log.Print(req.ID)
|
|
|
|
resp.Data = req.ID
|
2021-03-05 02:18:59 +00:00
|
|
|
resp.Msg = "OK"
|
|
|
|
resp.Status = 0
|
|
|
|
}
|
|
|
|
|
2021-12-30 16:38:06 +00:00
|
|
|
func (t *PlanController) UnFinishUndo(c *gin.Context) {
|
2021-06-11 17:26:37 +00:00
|
|
|
resp := RespBase{}
|
|
|
|
defer func() {
|
|
|
|
c.JSON(200, resp)
|
|
|
|
}()
|
|
|
|
id := c.Param("id")
|
|
|
|
|
|
|
|
e := db.GetOrm().Exec(fmt.Sprintf("update background.`undo` set done = '0' where id = '%s'",id )).Error
|
|
|
|
if nil != e {
|
|
|
|
logs.Error(e.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
resp.Data = nil
|
|
|
|
resp.Msg = "OK"
|
|
|
|
resp.Status = 0
|
|
|
|
}
|
|
|
|
|
2021-12-30 16:38:06 +00:00
|
|
|
func (t *PlanController) FinishUndo(c *gin.Context) {
|
2021-06-11 17:26:37 +00:00
|
|
|
resp := RespBase{}
|
|
|
|
defer func() {
|
|
|
|
c.JSON(200, resp)
|
|
|
|
}()
|
|
|
|
id := c.Param("id")
|
|
|
|
log.Print("finish undo id",id)
|
|
|
|
|
2021-07-20 16:14:05 +00:00
|
|
|
e := db.GetOrm().Exec(fmt.Sprintf("update background.`undo` set done = 1,finish_time='%s' where id = %s",
|
|
|
|
time.Now().Format("2006-01-02 15:04:05"),id)).Error
|
|
|
|
log.Print(fmt.Sprintf("update background.`undo` set done = 1,finish_time='%s' where id = %s",time.Now().Format("2006-01-02 15:04:05"),id))
|
2021-06-11 17:26:37 +00:00
|
|
|
if nil != e {
|
|
|
|
logs.Error(e.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
resp.Data = nil
|
|
|
|
resp.Msg = "OK"
|
|
|
|
resp.Status = 0
|
|
|
|
}
|
|
|
|
|
2021-12-30 16:38:06 +00:00
|
|
|
func (t *PlanController) UpdateUndo(c *gin.Context) {
|
2021-03-05 02:18:59 +00:00
|
|
|
resp := RespBase{}
|
|
|
|
defer func() {
|
|
|
|
c.JSON(200, resp)
|
|
|
|
}()
|
2021-06-11 17:26:37 +00:00
|
|
|
var req model.Undo
|
2021-03-05 02:18:59 +00:00
|
|
|
e := c.BindJSON(&req)
|
|
|
|
if nil != e {
|
|
|
|
resp.Msg = "wrong input"
|
|
|
|
return
|
|
|
|
}
|
2021-06-11 17:26:37 +00:00
|
|
|
e = db.GetOrm().Model(&model.Undo{}).Update(&req).Error
|
2021-03-05 02:18:59 +00:00
|
|
|
if nil != e {
|
|
|
|
logs.Error(e.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
resp.Data = nil
|
|
|
|
resp.Msg = "OK"
|
|
|
|
resp.Status = 0
|
|
|
|
}
|
|
|
|
|
2021-12-30 16:38:06 +00:00
|
|
|
func (t *PlanController) GetDone(c *gin.Context) {
|
2021-06-11 17:26:37 +00:00
|
|
|
resp := RespBase{}
|
|
|
|
defer func() {
|
|
|
|
c.JSON(200, resp)
|
|
|
|
}()
|
|
|
|
undos := []model.Undo{}
|
|
|
|
e := db.GetOrm().Model(&model.Undo{}).Where("done = 1").Find(&undos).Error
|
|
|
|
if nil != e {
|
|
|
|
log.Print(e.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
resp.Data = undos
|
|
|
|
resp.Msg = "OK"
|
|
|
|
resp.Status = 0
|
|
|
|
}
|
|
|
|
|
2021-12-30 16:38:06 +00:00
|
|
|
func (t *PlanController) GetUndo(c *gin.Context) {
|
2021-03-05 02:18:59 +00:00
|
|
|
resp := RespBase{}
|
|
|
|
defer func() {
|
|
|
|
c.JSON(200, resp)
|
|
|
|
}()
|
2021-03-09 15:21:12 +00:00
|
|
|
undos := []model.Undo{}
|
2021-06-12 12:32:42 +00:00
|
|
|
e := db.GetOrm().Model(&model.Undo{}).Find(&undos).Error
|
2021-03-22 04:10:37 +00:00
|
|
|
if nil != e {
|
2021-03-09 15:21:12 +00:00
|
|
|
log.Print(e.Error())
|
2021-03-05 02:18:59 +00:00
|
|
|
return
|
|
|
|
}
|
2021-03-09 15:21:12 +00:00
|
|
|
resp.Data = undos
|
|
|
|
resp.Msg = "OK"
|
|
|
|
resp.Status = 0
|
2021-03-05 02:18:59 +00:00
|
|
|
}
|
|
|
|
|
2021-12-30 16:38:06 +00:00
|
|
|
func (t *PlanController) GetPageUndo(c *gin.Context) {
|
2021-03-05 02:18:59 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-12-30 16:38:06 +00:00
|
|
|
func (t *PlanController) DeleteUndo(c *gin.Context) {
|
2021-03-05 02:18:59 +00:00
|
|
|
resp := RespBase{}
|
|
|
|
defer func() {
|
|
|
|
c.JSON(200, resp)
|
|
|
|
}()
|
2021-03-09 15:21:12 +00:00
|
|
|
sid := c.Param("id")
|
|
|
|
id := db.Atoi(sid)
|
|
|
|
e := db.GetOrm().Model(&model.Undo{}).Delete(&model.Undo{ID: int32(id)}).Error
|
2021-03-22 04:10:37 +00:00
|
|
|
if nil != e {
|
2021-03-09 15:21:12 +00:00
|
|
|
log.Print(e.Error())
|
|
|
|
return
|
2021-03-05 02:18:59 +00:00
|
|
|
}
|
2021-03-09 15:21:12 +00:00
|
|
|
resp.Status = 0
|
|
|
|
resp.Msg = "OK"
|
2021-03-05 02:18:59 +00:00
|
|
|
}
|