123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- package client
- import (
- "ulink-admin/frame"
- "ulink-admin/modules/system/models/model"
- "ulink-admin/modules/system/models/req"
- "ulink-admin/modules/system/models/response"
- "ulink-admin/modules/system/service"
- "ulink-admin/pkg/excels"
- "ulink-admin/pkg/file"
- "ulink-admin/pkg/page"
- "ulink-admin/utils"
- )
- type CityApi struct {
- CityService *service.CityService `inject:""`
- }
- // List 查询城市管理分页数据
- // @Summary 分页查询城市管理数据接口
- // @Description 分页查询城市管理数据接口
- // @Tags 城市管理相关接口
- // @Accept application/json
- // @Produce application/json
- // @Param Authorization header string false "Bearer 令牌"
- // @Param object query req.CityQuery false "查询参数"
- // @Security ApiKeyAuth
- // @Success 200 {object} resp.Response{data=page.Page{list=model.City},msg=string} "分页获取城市管理列表,返回包括列表,总数,页码,每页数量"
- // @Router /city/page [get]
- func (this CityApi) Page(c *frame.Context) {
- query := &req.CityQuery{}
- c.ValidteError(c.ShouldBind(query), query)
- list := make([]response.CityResponse, 0)
- i := this.CityService.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.CityQuery false "查询参数"
- // @Security ApiKeyAuth
- // @Success 200 {object} resp.Response{data=model.City,msg=string} "分页获取城市管理列表,返回包括列表,总数,页码,每页数量"
- // @Router /city/list [get]
- func (this CityApi) List(c *frame.Context) {
- query := &req.CityQuery{}
- list := make([]response.CityResponse, 0)
- c.ValidteError(c.ShouldBind(query), query)
- this.CityService.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.City,msg=string} "返回城市管理详情查询"
- // @Router /city [get]
- func (this CityApi) 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.CityService.Get(req.Id))
- }
- // Add 新增城市管理
- // @Summary 新增城市管理接口
- // @Description 新增城市管理接口
- // @Tags 城市管理相关接口
- // @Accept application/json
- // @Produce application/json
- // @Param Authorization header string false "Bearer 令牌"
- // @Param data body model.City true "城市管理实体对象"
- // @Success 200 {object} resp.Response{msg=string} "操作状态"
- // @Router /city/add [post]
- func (this CityApi) Add(c *frame.Context) {
- params, city := &req.CityAdd{}, &model.City{}
- c.ValidteError(c.ShouldBind(params), params)
- utils.CopyFields(city, params)
- this.CityService.Insert(city)
- }
- // Edit 修改城市管理数据接口
- // @Summary 修改城市管理接口
- // @Description 新增城市管理接口
- // @Tags 城市管理相关接口
- // @Accept application/json
- // @Produce application/json
- // @Param Authorization header string false "Bearer 令牌"
- // @Param data body model.City true "城市管理实体对象"
- // @Success 200 {object} resp.Response{msg=string} "操作状态"
- // @Router /city/edit [put]
- func (this CityApi) Edit(c *frame.Context) {
- params, city := &req.CityEdit{}, &model.City{}
- c.ValidteError(c.ShouldBind(params), params)
- utils.CopyFields(city, params)
- this.CityService.Edit(city, 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 /city [delete]
- func (a CityApi) Delete(c *frame.Context) {
- var req struct {
- Ids []int64 `form:"ids" binding:"required" msg:"ids不存在"` //ids
- }
- c.ValidteError(c.ShouldBind(&req), &req)
- a.CityService.Delete(req.Ids)
- }
- // Export 导出excel
- func (this CityApi) Export(c *frame.Context) {
- query := &req.CityQuery{}
- list := make([]model.City, 0)
- c.ValidteError(c.ShouldBind(query), query)
- this.CityService.List(query, list)
- excelList := make([]interface{}, 0)
- for _, city := range list {
- excelList = append(excelList, city)
- }
- _, files := excels.ExportExcel(excelList, "城市管理数据表")
- file.DownloadExcel(c, files)
- }
|