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.
72 lines
1.4 KiB
72 lines
1.4 KiB
4 years ago
|
package models
|
||
|
|
||
|
import (
|
||
|
"github.com/beego/beego/v2/client/orm"
|
||
|
"strconv"
|
||
|
"yixiang.co/yshop/dto"
|
||
|
"yixiang.co/yshop/untils"
|
||
|
)
|
||
|
|
||
4 years ago
|
type SysJob struct {
|
||
4 years ago
|
Id int64 `json:"id"`
|
||
|
Name string `json:"name" valid:"Required;"`
|
||
|
Enabled int8 `json:"enabled"`
|
||
|
Sort int8 `json:"sort"`
|
||
|
//DeptId int64 `json:"deptId"`
|
||
4 years ago
|
Dept *SysDept `json:"dept" orm:"column(dept_id);bigint;rel(one)""`
|
||
4 years ago
|
BaseModel
|
||
|
}
|
||
|
|
||
|
func init() {
|
||
4 years ago
|
orm.RegisterModel(new(SysJob))
|
||
4 years ago
|
}
|
||
|
|
||
|
|
||
|
// get all
|
||
4 years ago
|
func GetAllJob(base dto.BasePage,query ...interface{}) (int,[]SysJob) {
|
||
4 years ago
|
var (
|
||
4 years ago
|
tableName = "sys_job"
|
||
|
lists []SysJob
|
||
4 years ago
|
condition = ""
|
||
|
)
|
||
|
if base.Blurry != "" {
|
||
|
condition = " and name= '" + base.Blurry + "'"
|
||
|
}
|
||
|
if len(query) > 0 {
|
||
|
enabled := query[0].(int64)
|
||
|
if enabled >= 0 {
|
||
|
condition += " and enabled=" + strconv.FormatInt(enabled,10)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
total, _, rs := GetPagesInfo(tableName, base.Page, base.Size, condition)
|
||
|
rs.QueryRows(&lists)
|
||
|
|
||
|
o := orm.NewOrm()
|
||
|
for k, _ := range lists {
|
||
|
_, _ = o.LoadRelated(&lists[k], "Dept")
|
||
|
}
|
||
|
|
||
|
|
||
|
return total,lists
|
||
|
}
|
||
|
|
||
4 years ago
|
func AddJob(m *SysJob) (id int64, err error) {
|
||
4 years ago
|
o := orm.NewOrm()
|
||
|
id, err = o.Insert(m)
|
||
|
return
|
||
|
}
|
||
|
|
||
4 years ago
|
func UpdateByJob(m *SysJob) (err error) {
|
||
4 years ago
|
o := orm.NewOrm()
|
||
|
_, err = o.Update(m)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func DelByJob(ids []int64) (err error) {
|
||
|
str := untils.ReturnQ(len(ids))
|
||
|
o := orm.NewOrm()
|
||
4 years ago
|
_, err = o.Raw("UPDATE sys_job SET is_del = ? WHERE id in("+str+")", 1, ids).Exec()
|
||
4 years ago
|
return
|
||
|
}
|