123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- package controller
- import (
- "cold-delivery/app/admin/model"
- "cold-delivery/app/admin/service"
- "cold-delivery/app/admin/service/dto"
- "cold-delivery/common/actions"
- "github.com/gin-gonic/gin"
- "github.com/gin-gonic/gin/binding"
- "gogs.baozhida.cn/zoie/OAuth-core/api"
- "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/user"
- _ "gogs.baozhida.cn/zoie/OAuth-core/pkg/response"
- )
- type CompanyController struct {
- api.Api
- }
- // GetPage 获取公司列表
- // @Summary 获取公司列表
- // @Description 获取公司列表(用户公司及子公司)
- // @Tags 公司
- // @Param name query string false "公司名称"
- // @Success 200 {object} response.Response{data=response.Page{list=[]model.SysDept}} "{"code": 200, "data": [...]}"
- // @Router /api/company [get]
- // @Security Bearer
- func (e CompanyController) GetPage(c *gin.Context) {
- s := service.Company{}
- req := dto.CompanyGetPageReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.Query).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- //数据权限检查
- p := actions.GetPermissionFromContext(c)
- //p.DeptId = user.GetDeptId(c)
- list := make([]model.SysDept, 0)
- var count int64
- err = s.GetPage(&req, &list, &count)
- list, err = s.SetDeptPage(&req, p)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(list, "查询成功")
- }
- // GetCurrentCompany 获取当前用户的公司
- // @Summary 获取当前用户的公司
- // @Description 获取当前用户的公司
- // @Tags 公司
- // @Success 200 {object} response.Response{data=response.Page{list=[]model.SysUser}} "{"code": 200, "data": [...]}"
- // @Router /api/company/dept [get]
- // @Security Bearer
- func (e CompanyController) GetCurrentCompany(c *gin.Context) {
- s := service.Company{}
- req := dto.CompanyGetPageReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.Query).
- MakeService(&s.Service).
- Errors
- p := actions.GetPermissionFromContext(c)
- list := make([]model.SysDept, 0)
- var count int64
- err = s.GetCurrentCompany(p, &list, &req, &count)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
- }
- // GetUserPage 获取公司下面的用户列表
- // @Summary 获取公司下面的用户列表
- // @Description 获取公司下面的用户列表
- // @Tags 公司
- // @Param username query string false "用户名"
- // @Param name query string false "姓名"
- // @Param type query int false "类型"
- // @Param companyId query int false "公司id"
- // @Param pageSize query int false "页条数"
- // @Param page query int false "页码"
- // @Success 200 {object} response.Response{data=response.Page{list=[]model.SysUser}} "{"code": 200, "data": [...]}"
- // @Router /api/company/user [get]
- // @Security Bearer
- func (e CompanyController) GetUserPage(c *gin.Context) {
- s := service.SysUser{}
- req := dto.SysUserGetPageByDeptIdReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.Query).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- //数据权限检查
- p := actions.GetPermissionFromContext(c)
- list := make([]model.SysUser, 0)
- var count int64
- err = s.GetPageByDeptId(&req, p, &list, &count)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
- }
- // GetAll 添加用户-获取公司列表
- // @Summary 添加用户-获取公司列表
- // @Description 添加用户-获取公司列表
- // @Tags 公司
- // @Param name query string false "公司名称"
- // @Success 200 {object} response.Response{data=model.SysDept} "{"code": 200, "data": [...]}"
- // @Router /api/company/{id} [get]
- // @Security Bearer
- func (e CompanyController) GetAll(c *gin.Context) {
- s := service.Company{}
- req := dto.CompanyGetAllReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.Query).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- //数据权限检查
- p := actions.GetPermissionFromContext(c)
- p.DeptId = user.GetDeptId(c)
- list := make([]model.SysDept, 0)
- var count int64
- err = s.GetAll(&req, &list, &count, p)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.PageOK(list, int(count), 0, 0, "查询成功")
- }
- // Get 通过id获取公司
- // @Summary 通过id获取公司
- // @Description 通过id获取公司
- // @Tags 公司
- // @Param id path string true "公司id"
- // @Success 200 {object} response.Response{data=model.SysDept} "{"code": 200, "data": [...]}"
- // @Router /api/company/{id} [get]
- // @Security Bearer
- func (e CompanyController) Get(c *gin.Context) {
- s := service.Company{}
- req := dto.CompanyGetReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, nil).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- var object model.SysDept
- //数据权限检查
- err = s.Get(&req, &object)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(object, "查询成功")
- }
- // Insert 添加公司
- // @Summary 添加公司
- // @Description 添加公司
- // @Tags 公司
- // @Accept application/json
- // @Product application/json
- // @Param data body dto.CompanyInsertReq true "data"
- // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
- // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
- // @Router /api/company [post]
- // @Security Bearer
- func (e CompanyController) Insert(c *gin.Context) {
- s := service.Company{}
- req := dto.CompanyInsertReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.JSON).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- // 设置创建人
- req.SetCreateBy(user.GetUserId(c))
- err = s.Insert(&req)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(req.GetId(), "添加成功")
- }
- // Update 修改公司
- // @Summary 修改公司
- // @Description 修改公司
- // @Tags 公司
- // @Accept application/json
- // @Product application/json
- // @Param data body dto.CompanyUpdateReq true "body"
- // @Success 200 {string} string "{"code": 200, "message": "修改成功"}"
- // @Success 200 {string} string "{"code": -1, "message": "修改失败"}"
- // @Router /api/company [put]
- // @Security Bearer
- func (e CompanyController) Update(c *gin.Context) {
- s := service.Company{}
- req := dto.CompanyUpdateReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- req.SetUpdateBy(user.GetUserId(c))
- err = s.Update(&req)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(req.GetId(), "修改成功")
- }
- // Delete 删除公司
- // @Summary 删除公司
- // @Description 删除公司
- // @Tags 公司
- // @Accept application/json
- // @Product application/json
- // @Param data body dto.CompanyDeleteReq true "body"
- // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
- // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
- // @Router /api/company [delete]
- // @Security Bearer
- func (e CompanyController) Delete(c *gin.Context) {
- s := service.Company{}
- req := dto.CompanyDeleteReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.JSON, nil).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- //数据权限检查
- //p := actions.GetPermissionFromContext(c)
- err = s.Remove(&req, nil)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(req.GetId(), "删除成功")
- }
|