package admin import ( "ulink-admin/frame" "ulink-admin/modules/car/models/model" "ulink-admin/modules/car/models/req" "ulink-admin/modules/car/models/response" "ulink-admin/modules/car/service" "ulink-admin/pkg/excels" "ulink-admin/pkg/file" "ulink-admin/pkg/page" "ulink-admin/utils" ) type CarApi struct { CarService *service.CarService `inject:""` } // List 查询车辆管理分页数据 // @Summary 分页查询车辆管理数据接口 // @Description 分页查询车辆管理数据接口 // @Tags 车辆管理相关接口 // @Accept application/json // @Produce application/json // @Param Authorization header string false "Bearer 令牌" // @Param object query req.CarQuery false "查询参数" // @Security ApiKeyAuth // @Success 200 {object} resp.Response{data=page.Page{list=model.Car},msg=string} "分页获取车辆管理列表,返回包括列表,总数,页码,每页数量" // @Router /car/page [get] func (this CarApi) Page(c *frame.Context) { query := &req.CarQuery{} c.ValidteError(c.ShouldBind(query), query) list := make([]response.CarResponse, 0) i := this.CarService.Page(query, &list) c.Ok(page.Page{List: list, Total: i, Size: query.PageSize}) } // List 查询车辆管理所有数据 // @Summary 查询全部数据车辆管理数据接口 // @Description 查询全部数据车辆管理数据接口 // @Tags 车辆管理相关接口 // @Accept application/json // @Produce application/json // @Param Authorization header string false "Bearer 令牌" // @Param object query req.CarQuery false "查询参数" // @Security ApiKeyAuth // @Success 200 {object} resp.Response{data=model.Car,msg=string} "分页获取车辆管理列表,返回包括列表,总数,页码,每页数量" // @Router /car/list [get] func (this CarApi) List(c *frame.Context) { query := &req.CarQuery{} list := make([]response.CarResponse, 0) c.ValidteError(c.ShouldBind(query), query) this.CarService.List(query, &list) c.Ok(list) } // Get 根据车辆管理Id获取详细信息 // @Summary 车辆管理详情查询接口 // @Description 车辆管理详情查询接口 // @Tags 车辆管理相关接口 // @Accept application/json // @Produce application/json // @Param Authorization header string false "Bearer 令牌" // @Param id query int true "id" id // @Security ApiKeyAuth // @Success 200 {object} resp.Response{data=model.Car,msg=string} "返回车辆管理详情查询" // @Router /car [get] func (this CarApi) Get(c *frame.Context) { var req struct { Id int64 `form:"id" binding:"required" msg:"id不存在" ` //id } c.ValidteError(c.ShouldBind(&req), &req) c.Ok(this.CarService.Get(req.Id)) } // Add 新增车辆管理 // @Summary 新增车辆管理接口 // @Description 新增车辆管理接口 // @Tags 车辆管理相关接口 // @Accept application/json // @Produce application/json // @Param Authorization header string false "Bearer 令牌" // @Param data body model.Car true "车辆管理实体对象" // @Success 200 {object} resp.Response{msg=string} "操作状态" // @Router /car/add [post] func (this CarApi) Add(c *frame.Context) { params, car := &req.CarAdd{}, &model.Car{} c.ValidteError(c.ShouldBind(params), params) utils.CopyFields(car, params) this.CarService.Insert(car) } // Edit 修改车辆管理数据接口 // @Summary 修改车辆管理接口 // @Description 新增车辆管理接口 // @Tags 车辆管理相关接口 // @Accept application/json // @Produce application/json // @Param Authorization header string false "Bearer 令牌" // @Param data body model.Car true "车辆管理实体对象" // @Success 200 {object} resp.Response{msg=string} "操作状态" // @Router /car/edit [put] func (this CarApi) Edit(c *frame.Context) { params, car := &req.CarEdit{}, &model.Car{} c.ValidteError(c.ShouldBind(params), params) utils.CopyFields(car, params) this.CarService.Edit(car, c.Cols()) } // Delete 删除车辆管理数据 // @Summary 删除车辆管理接口 // @Description 删除车辆管理接口 // @Tags 车辆管理相关接口 // @Accept application/json // @Produce application/json // @Param Authorization header string false "Bearer 令牌" // @Param id path int true "id" id // @Success 200 {object} resp.Response{msg=string} "操作状态" // @Router /car [delete] func (a CarApi) Delete(c *frame.Context) { var req struct { Ids []int64 `form:"ids" binding:"required" msg:"ids不存在"` //ids } c.ValidteError(c.ShouldBind(&req), &req) a.CarService.Delete(req.Ids) } // Export 导出excel func (this CarApi) Export(c *frame.Context) { query := &req.CarQuery{} list := make([]model.Car, 0) c.ValidteError(c.ShouldBind(query), query) this.CarService.List(query, list) excelList := make([]interface{}, 0) for _, car := range list { excelList = append(excelList, car) } _, files := excels.ExportExcel(excelList, "车辆管理数据表") file.DownloadExcel(c, files) }