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