package cmd_services import ( "cron_admin/app/constants/common" "cron_admin/app/http/entities/backend" "cron_admin/app/models/croncmdmodel" "cron_admin/app/utils/mapstructure" "xorm.io/builder" ) func GetListByWhere(request *backend.CmdListRequest, page int, limit int) (count int64, cmdListInfo []croncmdmodel.CronCmd, err error) { cond := builder.NewCond() if request.CmdName != "" { cond = cond.And(builder.Like{"cmd_name", request.CmdName}) } if request.Status != 0 { cond = cond.And(builder.Eq{"status": request.Status}) } if request.ExecuteType != 0 { cond = cond.And(builder.Eq{"status": request.Status}) } if len(request.CmdIds) > 0 { // 使用IN查询 cond = cond.And(builder.In("cmd_id", request.CmdIds)) } session := croncmdmodel.GetInstance().GetDb().Where(cond) if page != 0 && limit != 0 { session = session.Limit(page, (page-1)*limit) } count, err = session.FindAndCount(&cmdListInfo) if err != nil { return } return } func UserAdd(request *backend.CmdAddRequest) (err error) { var db croncmdmodel.CronCmd _ = mapstructure.Decode(request, &db) db.Status = common.STATUS_ENABLE _, err = croncmdmodel.GetInstance().GetDb().InsertOne(db) return } func UserEdit(request *backend.CmdEditRequest) (err error) { var db croncmdmodel.CronCmd _ = mapstructure.Decode(request, &db) _, err = croncmdmodel.GetInstance().GetDb().ID(request.CmdId).Update(&db) return } func UserDel(request *backend.CmdDeleteRequest) (err error) { _, err = croncmdmodel.GetInstance().GetDb().ID(request.CmdId).Delete(&croncmdmodel.CronCmd{}) return }