add
department 部门模块
add, Delete, update, list
New file |
| | |
| | | package v1 |
| | | |
| | | import ( |
| | | "aps_crm/model" |
| | | "aps_crm/model/request" |
| | | "aps_crm/model/response" |
| | | "aps_crm/pkg/contextx" |
| | | "aps_crm/pkg/ecode" |
| | | "github.com/gin-gonic/gin" |
| | | "strconv" |
| | | ) |
| | | |
| | | type DepartmentApi struct{} |
| | | |
| | | // Add |
| | | // |
| | | // @Tags Department |
| | | // @Summary 添加部门 |
| | | // @Produce application/json |
| | | // @Param object body request.AddDepartment true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/department/add [post] |
| | | func (dep *DepartmentApi) Add(c *gin.Context) { |
| | | var params request.AddDepartment |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | department := new(model.Department) |
| | | department.Name = params.Name |
| | | |
| | | errCode := departmentService.AddDepartment(department) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // Delete |
| | | // |
| | | // @Tags Department |
| | | // @Summary 删除部门 |
| | | // @Produce application/json |
| | | // @Param id path int true "部门ID" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/department/delete/{id} [delete] |
| | | func (dep *DepartmentApi) Delete(c *gin.Context) { |
| | | ctx, ok := contextx.NewContext(c, nil) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | id, _ := strconv.Atoi(c.Param("id")) |
| | | errCode := departmentService.DeleteDepartment(id) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // Update |
| | | // |
| | | // @Tags Department |
| | | // @Summary 更新部门 |
| | | // @Produce application/json |
| | | // @Param object body request.UpdateDepartmentList true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/department/update/{id} [put] |
| | | func (dep *DepartmentApi) Update(c *gin.Context) { |
| | | var params request.UpdateDepartmentList |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | errCode := departmentService.UpdateDepartment(params.Departments) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // List |
| | | // |
| | | // @Tags Department |
| | | // @Summary 部门列表 |
| | | // @Produce application/json |
| | | // @Success 200 {object} contextx.Response{data=response.DepartmentResponse} |
| | | // @Router /api/department/list [get] |
| | | func (dep *DepartmentApi) List(c *gin.Context) { |
| | | ctx, ok := contextx.NewContext(c, nil) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | list, errCode := departmentService.GetDepartmentList() |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.OkWithDetailed(response.DepartmentResponse{ |
| | | List: list, |
| | | }) |
| | | } |
| | |
| | | AuthorityApi |
| | | MenuApi |
| | | GetAllDataApi |
| | | DepartmentApi |
| | | } |
| | | |
| | | var ApiGroup = new(Group) |
| | |
| | | authorityService = service.ServiceGroup.AuthorityService |
| | | menuService = service.ServiceGroup.MenuService |
| | | allDataServer = service.ServiceGroup.DataServer |
| | | departmentService = service.ServiceGroup.DepartmentService |
| | | ) |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api/department/add": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Department" |
| | | ], |
| | | "summary": "添加部门", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.AddDepartment" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/department/delete/{id}": { |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Department" |
| | | ], |
| | | "summary": "删除部门", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "description": "部门ID", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/department/list": { |
| | | "get": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Department" |
| | | ], |
| | | "summary": "部门列表", |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "$ref": "#/definitions/response.DepartmentResponse" |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/department/update/{id}": { |
| | | "put": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Department" |
| | | ], |
| | | "summary": "更新部门", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.UpdateDepartmentList" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/enterpriseNature/add": { |
| | | "post": { |
| | | "produces": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "model.Department": { |
| | | "type": "object", |
| | | "properties": { |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "model.EnterpriseNature": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | }, |
| | | "serviceMode": { |
| | | "type": "integer" |
| | | } |
| | | } |
| | | }, |
| | | "request.AddDepartment": { |
| | | "type": "object", |
| | | "required": [ |
| | | "name" |
| | | ], |
| | | "properties": { |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateDepartment": { |
| | | "type": "object", |
| | | "required": [ |
| | | "id", |
| | | "name" |
| | | ], |
| | | "properties": { |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateDepartmentList": { |
| | | "type": "object", |
| | | "required": [ |
| | | "departments" |
| | | ], |
| | | "properties": { |
| | | "departments": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/request.UpdateDepartment" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateEnterpriseNature": { |
| | | "type": "object", |
| | | "required": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "response.DepartmentResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | | "list": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/model.Department" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "response.EnterpriseNatureResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api/department/add": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Department" |
| | | ], |
| | | "summary": "添加部门", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.AddDepartment" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/department/delete/{id}": { |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Department" |
| | | ], |
| | | "summary": "删除部门", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "description": "部门ID", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/department/list": { |
| | | "get": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Department" |
| | | ], |
| | | "summary": "部门列表", |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "$ref": "#/definitions/response.DepartmentResponse" |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/department/update/{id}": { |
| | | "put": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Department" |
| | | ], |
| | | "summary": "更新部门", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.UpdateDepartmentList" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/enterpriseNature/add": { |
| | | "post": { |
| | | "produces": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "model.Department": { |
| | | "type": "object", |
| | | "properties": { |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "model.EnterpriseNature": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | }, |
| | | "serviceMode": { |
| | | "type": "integer" |
| | | } |
| | | } |
| | | }, |
| | | "request.AddDepartment": { |
| | | "type": "object", |
| | | "required": [ |
| | | "name" |
| | | ], |
| | | "properties": { |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateDepartment": { |
| | | "type": "object", |
| | | "required": [ |
| | | "id", |
| | | "name" |
| | | ], |
| | | "properties": { |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateDepartmentList": { |
| | | "type": "object", |
| | | "required": [ |
| | | "departments" |
| | | ], |
| | | "properties": { |
| | | "departments": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/request.UpdateDepartment" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateEnterpriseNature": { |
| | | "type": "object", |
| | | "required": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "response.DepartmentResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | | "list": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/model.Department" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "response.EnterpriseNatureResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | serviceMode: |
| | | type: integer |
| | | type: object |
| | | model.Department: |
| | | properties: |
| | | id: |
| | | type: integer |
| | | name: |
| | | type: string |
| | | type: object |
| | | model.EnterpriseNature: |
| | | properties: |
| | | id: |
| | |
| | | type: integer |
| | | serviceMode: |
| | | type: integer |
| | | type: object |
| | | request.AddDepartment: |
| | | properties: |
| | | name: |
| | | type: string |
| | | required: |
| | | - name |
| | | type: object |
| | | request.AddEnterpriseNature: |
| | | properties: |
| | |
| | | serviceMode: |
| | | type: integer |
| | | type: object |
| | | request.UpdateDepartment: |
| | | properties: |
| | | id: |
| | | type: integer |
| | | name: |
| | | type: string |
| | | required: |
| | | - id |
| | | - name |
| | | type: object |
| | | request.UpdateDepartmentList: |
| | | properties: |
| | | departments: |
| | | items: |
| | | $ref: '#/definitions/request.UpdateDepartment' |
| | | type: array |
| | | required: |
| | | - departments |
| | | type: object |
| | | request.UpdateEnterpriseNature: |
| | | properties: |
| | | id: |
| | |
| | | description: 商机来源 |
| | | items: |
| | | $ref: '#/definitions/model.SalesSources' |
| | | type: array |
| | | type: object |
| | | response.DepartmentResponse: |
| | | properties: |
| | | list: |
| | | items: |
| | | $ref: '#/definitions/model.Department' |
| | | type: array |
| | | type: object |
| | | response.EnterpriseNatureResponse: |
| | |
| | | summary: 获取所有数据 |
| | | tags: |
| | | - Data |
| | | /api/department/add: |
| | | post: |
| | | parameters: |
| | | - description: 查询参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.AddDepartment' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: OK |
| | | schema: |
| | | $ref: '#/definitions/contextx.Response' |
| | | summary: 添加部门 |
| | | tags: |
| | | - Department |
| | | /api/department/delete/{id}: |
| | | delete: |
| | | parameters: |
| | | - description: 部门ID |
| | | in: path |
| | | name: id |
| | | required: true |
| | | type: integer |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: OK |
| | | schema: |
| | | $ref: '#/definitions/contextx.Response' |
| | | summary: 删除部门 |
| | | tags: |
| | | - Department |
| | | /api/department/list: |
| | | get: |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: OK |
| | | schema: |
| | | allOf: |
| | | - $ref: '#/definitions/contextx.Response' |
| | | - properties: |
| | | data: |
| | | $ref: '#/definitions/response.DepartmentResponse' |
| | | type: object |
| | | summary: 部门列表 |
| | | tags: |
| | | - Department |
| | | /api/department/update/{id}: |
| | | put: |
| | | parameters: |
| | | - description: 查询参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.UpdateDepartmentList' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: OK |
| | | schema: |
| | | $ref: '#/definitions/contextx.Response' |
| | | summary: 更新部门 |
| | | tags: |
| | | - Department |
| | | /api/enterpriseNature/add: |
| | | post: |
| | | parameters: |
New file |
| | |
| | | package model |
| | | |
| | | import ( |
| | | "aps_crm/pkg/mysqlx" |
| | | "gorm.io/gorm" |
| | | ) |
| | | |
| | | type ( |
| | | Department struct { |
| | | Id int `json:"id" gorm:"column:id;primaryKey;autoIncrement;not null"` |
| | | Name string `json:"name" gorm:"column:name;type:varchar(255);comment:部门名称"` |
| | | ParentId int `json:"-" gorm:"column:parent_id;type:int(11);comment:上级部门ID"` |
| | | } |
| | | |
| | | DepartmentSearch struct { |
| | | Department |
| | | Orm *gorm.DB |
| | | } |
| | | ) |
| | | |
| | | func (Department) TableName() string { |
| | | return "department" |
| | | } |
| | | |
| | | func NewDepartmentSearch() *DepartmentSearch { |
| | | return &DepartmentSearch{ |
| | | Orm: mysqlx.GetDB(), |
| | | } |
| | | } |
| | | |
| | | func (slf *DepartmentSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&Department{}) |
| | | if slf.Id != 0 { |
| | | db = db.Where("id = ?", slf.Id) |
| | | } |
| | | if slf.Name != "" { |
| | | db = db.Where("name = ?", slf.Name) |
| | | } |
| | | if slf.ParentId != 0 { |
| | | db = db.Where("parent_id = ?", slf.ParentId) |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |
| | | func (slf *DepartmentSearch) Create(record *Department) error { |
| | | var db = slf.build() |
| | | return db.Create(record).Error |
| | | } |
| | | |
| | | func (slf *DepartmentSearch) Delete() error { |
| | | var db = slf.build() |
| | | return db.Delete(&Department{}).Error |
| | | } |
| | | |
| | | func (slf *DepartmentSearch) Update(record *Department) error { |
| | | var db = slf.build() |
| | | return db.Updates(record).Error |
| | | } |
| | | |
| | | func (slf *DepartmentSearch) Find() ([]*Department, error) { |
| | | var db = slf.build() |
| | | var result []*Department |
| | | err := db.Find(&result).Error |
| | | return result, err |
| | | } |
| | | |
| | | func (slf *DepartmentSearch) SetId(id int) *DepartmentSearch { |
| | | slf.Id = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *DepartmentSearch) Updates(data map[string]interface{}) error { |
| | | var db = slf.build() |
| | | return db.Updates(data).Error |
| | | } |
| | |
| | | ServiceFeeManage{}, |
| | | Authority{}, |
| | | Api{}, |
| | | Department{}, |
| | | ) |
| | | return err |
| | | } |
New file |
| | |
| | | package request |
| | | |
| | | type AddDepartment struct { |
| | | Name string `json:"name" binding:"required"` |
| | | } |
| | | |
| | | type UpdateDepartment struct { |
| | | Id int `json:"id" binding:"required"` |
| | | Name string `json:"name" binding:"required"` |
| | | } |
| | | |
| | | type UpdateDepartmentList struct { |
| | | Departments []*UpdateDepartment `json:"departments" binding:"required"` |
| | | } |
| | |
| | | // 老客户营销 |
| | | RegularCustomers []*model.RegularCustomers `json:"regular_customers"` |
| | | } |
| | | |
| | | DepartmentResponse struct { |
| | | List []*model.Department `json:"list"` |
| | | } |
| | | ) |
| | |
| | | MenuListErr = 3900001 // 获取菜单列表失败 |
| | | SetMenuAuthorityErr = 3900002 // 设置菜单权限失败 |
| | | |
| | | DepartmentExist = 4000001 // 部门已存在 |
| | | DepartmentNotExist = 4000002 // 部门不存在 |
| | | DepartmentListErr = 4000003 // 获取部门列表失败 |
| | | DepartmentSetErr = 4000004 // 设置部门失败 |
| | | DepartmentUpdateErr = 4000005 // 更新部门失败 |
| | | DepartmentDeleteErr = 4000006 // 删除部门失败 |
| | | DepartmentDeleteErr1 = 4000007 // 该部门下存在用户,无法删除 |
| | | ) |
New file |
| | |
| | | package router |
| | | |
| | | import ( |
| | | v1 "aps_crm/api/v1" |
| | | "github.com/gin-gonic/gin" |
| | | ) |
| | | |
| | | type DepartmentRouter struct{} |
| | | |
| | | func (s *DepartmentRouter) InitDepartmentRouter(router *gin.RouterGroup) { |
| | | departmentRouter := router.Group("department") |
| | | //departmentRouterWithoutRecord := router.Group("department") |
| | | departmentApi := v1.ApiGroup.DepartmentApi |
| | | { |
| | | departmentRouter.POST("add", departmentApi.Add) // 添加部门 |
| | | departmentRouter.DELETE("delete/:id", departmentApi.Delete) // 删除部门 |
| | | departmentRouter.PUT("update", departmentApi.Update) // 更新部门 |
| | | departmentRouter.GET("list", departmentApi.List) // 获取部门列表 |
| | | } |
| | | } |
| | |
| | | AuthorityRouter |
| | | MenuRouter |
| | | DataRouter |
| | | DepartmentRouter |
| | | } |
| | | |
| | | func InitRouter() *gin.Engine { |
| | |
| | | routerGroup.InitAuthorityRouter(PrivateGroup) // 注册authority路由 |
| | | routerGroup.InitMenuRouter(PrivateGroup) // 注册menu路由 |
| | | routerGroup.InitDataRouter(PrivateGroup) // 注册data路由 |
| | | routerGroup.InitDepartmentRouter(PrivateGroup) // 注册department路由 |
| | | } |
| | | return Router |
| | | } |
New file |
| | |
| | | package service |
| | | |
| | | import ( |
| | | "aps_crm/model" |
| | | "aps_crm/model/request" |
| | | "aps_crm/pkg/ecode" |
| | | ) |
| | | |
| | | type DepartmentService struct{} |
| | | |
| | | func (DepartmentService) AddDepartment(department *model.Department) int { |
| | | err := model.NewDepartmentSearch().Create(department) |
| | | if err != nil { |
| | | return ecode.DepartmentExist |
| | | } |
| | | |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (DepartmentService) DeleteDepartment(id int) int { |
| | | _, err := model.NewDepartmentSearch().SetId(id).Find() |
| | | if err != nil { |
| | | return ecode.DepartmentNotExist |
| | | } |
| | | |
| | | err = model.NewDepartmentSearch().SetId(id).Delete() |
| | | if err != nil { |
| | | return ecode.DepartmentNotExist |
| | | } |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (DepartmentService) GetDepartmentList() ([]*model.Department, int) { |
| | | list, err := model.NewDepartmentSearch().Find() |
| | | if err != nil { |
| | | return nil, ecode.DepartmentListErr |
| | | } |
| | | |
| | | return list, ecode.OK |
| | | } |
| | | |
| | | func (DepartmentService) UpdateDepartment(departments []*request.UpdateDepartment) int { |
| | | for _, v := range departments { |
| | | // check department exist |
| | | _, err := model.NewDepartmentSearch().SetId(v.Id).Find() |
| | | if err != nil { |
| | | return ecode.DepartmentNotExist |
| | | } |
| | | |
| | | err = model.NewDepartmentSearch().SetId(v.Id).Updates(map[string]interface{}{ |
| | | "name": v.Name, |
| | | }) |
| | | if err != nil { |
| | | return ecode.DepartmentSetErr |
| | | } |
| | | } |
| | | |
| | | return ecode.OK |
| | | } |
| | |
| | | AuthorityService |
| | | MenuService |
| | | DataServer |
| | | DepartmentService |
| | | } |
| | | |
| | | var ServiceGroup = new(Group) |