3个文件已添加
3 文件已重命名
10个文件已修改
| | |
| | | web: |
| | | port: 8005 |
| | | port: 8008 |
| | | host: 192.168.20.119 |
| | | apport: 9091 |
| | | alhost: 192.168.20.119 |
| | | alport: 9090 |
| | | nodeId: wangpengfei |
| | | ossType: local |
| | | db: |
| | | dsn: root:c++java123@tcp(192.168.20.119:3306)/aps_server2?charset=utf8&parseTime=True&loc=Local |
| | | dsn: root:c++java123@tcp(192.168.20.119:3306)/silk?charset=utf8&parseTime=True&loc=Local |
| | | logMode: true |
| | | maxIdleCon: 20 |
| | | maxOpenCon: 100 |
| | | connMaxLifeTimeSecond: 120 |
| | | connMaxIdleTimeSecond: 1800 |
| | | registry: |
| | | etcdAddr: 192.168.20.247:2379 |
| | | keyPrefix: /aps/apsServer/node/ |
| | | log: |
| | | path: ./logs/server.log |
| | | encoder: console |
| | |
| | | MaxSize: 200 # 每个日志文件的最大大小(MB) |
| | | MaxBackups: 2 # 保留的旧日志文件个数 |
| | | RotateDays: 5 # 日志文件的最大保留天数 |
| | | nsq: |
| | | nsqdAddr: 121.31.232.83:4150 |
| | | nsqlookupdAddr: |
| | | local: |
| | | storePath: uploads/file |
| | |
| | | package constvar |
| | | |
| | | type DictType int |
| | | |
| | | const ( |
| | | DictTypeMarket DictType = iota //庄口 |
| | | DictTypeWorkshop //车间 |
| | | DictTypeColor //颜色 |
| | | DictTypeSpec //规格 |
| | | ) |
| | |
| | | "fmt" |
| | | "github.com/gin-gonic/gin" |
| | | "gorm.io/gorm" |
| | | "jialian/controllers/request" |
| | | "jialian/extend/code" |
| | | "jialian/extend/util" |
| | | "jialian/models" |
| | | "jialian/pkg/convertx" |
| | | "jialian/pkg/structx" |
| | | "jialian/request" |
| | | ) |
| | | |
| | | type DepartmentController struct{} |
| | |
| | | } |
| | | |
| | | treeMap := make(map[uint][]*models.Department) |
| | | allMenus, err := models.NewDepartmentSearch().FindNotTotal() |
| | | allMenus, err := models.NewDepartmentSearch().FindAll() |
| | | for _, v := range allMenus { |
| | | treeMap[v.ParentId] = append(treeMap[v.ParentId], v) |
| | | } |
New file |
| | |
| | | package controllers |
| | | |
| | | import ( |
| | | "errors" |
| | | "fmt" |
| | | "github.com/gin-gonic/gin" |
| | | "gorm.io/gorm" |
| | | "jialian/controllers/request" |
| | | "jialian/extend/code" |
| | | "jialian/extend/util" |
| | | "jialian/models" |
| | | "jialian/pkg/convertx" |
| | | "jialian/pkg/structx" |
| | | ) |
| | | |
| | | type DictController struct{} |
| | | |
| | | // Add |
| | | // @Tags 系统设置/字典 |
| | | // @Summary 添加字典 |
| | | // @Produce application/json |
| | | // @Param object body request.AddDict true "字典信息" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-jl/v1/system/dict [post] |
| | | func (slf DictController) Add(c *gin.Context) { |
| | | var reqParams request.AddDict |
| | | var params models.Dict |
| | | if err := c.BindJSON(&reqParams); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | if err := structx.AssignTo(reqParams, ¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "数据转换错误") |
| | | return |
| | | } |
| | | |
| | | if err := slf.ParamsCheck(params); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | if err := models.NewDictSearch().Create(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.SaveFail, "插入失败") |
| | | return |
| | | } |
| | | |
| | | util.ResponseFormat(c, code.Success, "添加成功") |
| | | } |
| | | |
| | | // Update |
| | | // @Tags 系统设置/字典 |
| | | // @Summary 编辑字典 |
| | | // @Produce application/json |
| | | // @Param object body request.UpdateDict true "字典信息" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-jl/v1/system/dict [put] |
| | | func (slf DictController) Update(c *gin.Context) { |
| | | var ( |
| | | reqParams request.UpdateDict |
| | | params models.Dict |
| | | ) |
| | | if err := c.BindJSON(&reqParams); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, fmt.Sprintf("参数解析失败: %v"+err.Error())) |
| | | return |
| | | } |
| | | if err := structx.AssignTo(reqParams, ¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, fmt.Sprintf("数据转换错误: %v", err.Error())) |
| | | return |
| | | } |
| | | if err := slf.ParamsCheck(params); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | |
| | | _, err := models.NewDictSearch().SetID(params.ID).First() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "ID不存在") |
| | | return |
| | | } |
| | | |
| | | err = models.NewDictSearch().SetID(params.ID).Save(¶ms) |
| | | |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "修改失败") |
| | | return |
| | | } |
| | | |
| | | util.ResponseFormat(c, code.UpdateSuccess, "更新成功") |
| | | } |
| | | |
| | | func (slf DictController) ParamsCheck(params models.Dict) (err error) { |
| | | dict, err := models.NewDictSearch().SetNumber(params.Number).First() |
| | | if err != gorm.ErrRecordNotFound && dict != nil && dict.ID != params.ID { |
| | | return errors.New("编号重复") |
| | | } |
| | | |
| | | dict, err = models.NewDictSearch().SetName(params.Name).First() |
| | | if err != gorm.ErrRecordNotFound && dict != nil && dict.ID != params.ID { |
| | | return errors.New("名称重复") |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | // List |
| | | // @Tags 系统设置/字典 |
| | | // @Summary 查询字典列表 |
| | | // @Produce application/json |
| | | // @Param object query request.GetDictList true "查询参数" |
| | | // @Success 200 {object} util.ResponseList{data=[]models.Dict} "成功" |
| | | // @Router /api-jl/v1/system/dict [get] |
| | | func (slf DictController) List(c *gin.Context) { |
| | | var params request.GetDictList |
| | | if err := c.ShouldBindQuery(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | |
| | | list, err := models.NewDictSearch().SetDictType(params.DictType).FindAll() |
| | | |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "查找失败") |
| | | return |
| | | } |
| | | |
| | | util.ResponseFormatList(c, code.Success, list, len(list)) |
| | | } |
| | | |
| | | // Delete |
| | | // @Tags 系统设置/字典 |
| | | // @Summary 删除字典 |
| | | // @Produce application/json |
| | | // @Param id path string true "字典信息" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-jl/v1/system/dict/{id} [delete] |
| | | func (slf DictController) Delete(c *gin.Context) { |
| | | idStr := c.Param("id") |
| | | if idStr == "0" || idStr == "" { |
| | | util.ResponseFormat(c, code.RequestParamError, "空的记录id") |
| | | return |
| | | } |
| | | |
| | | id := convertx.StringToUInt(idStr) |
| | | err := models.NewDictSearch().SetID(id).Delete() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "删除失败") |
| | | return |
| | | } |
| | | util.ResponseFormat(c, code.UpdateSuccess, "删除成功") |
| | | } |
New file |
| | |
| | | package request |
| | | |
| | | import "jialian/constvar" |
| | | |
| | | type GetDictList struct { |
| | | PageInfo |
| | | DictType constvar.DictType `json:"dictType"` //字典类型 |
| | | } |
| | | |
| | | type AddDict struct { |
| | | DictType constvar.DictType `json:"dictType"` //字典类型 |
| | | Number string `json:"number"` //编码 |
| | | Name string `json:"name"` //名称 |
| | | Remark string `json:"remark"` //备注 |
| | | } |
| | | |
| | | type UpdateDict struct { |
| | | ID uint `gorm:"comment:主键ID;primaryKey;" json:"id"` |
| | | AddDict |
| | | } |
| | |
| | | "host": "{{.Host}}", |
| | | "basePath": "{{.BasePath}}", |
| | | "paths": { |
| | | "/api-jl/v1/system/dict": { |
| | | "get": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "系统设置/字典" |
| | | ], |
| | | "summary": "查询字典列表", |
| | | "parameters": [ |
| | | { |
| | | "enum": [ |
| | | 0, |
| | | 1, |
| | | 2, |
| | | 3 |
| | | ], |
| | | "type": "integer", |
| | | "x-enum-comments": { |
| | | "DictTypeColor": "颜色", |
| | | "DictTypeMarket": "庄口", |
| | | "DictTypeSpec": "规格", |
| | | "DictTypeWorkshop": "车间" |
| | | }, |
| | | "x-enum-varnames": [ |
| | | "DictTypeMarket", |
| | | "DictTypeWorkshop", |
| | | "DictTypeColor", |
| | | "DictTypeSpec" |
| | | ], |
| | | "description": "字典类型", |
| | | "name": "dictType", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "页码", |
| | | "name": "page", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "每页大小", |
| | | "name": "pageSize", |
| | | "in": "query" |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/util.ResponseList" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/models.Dict" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "put": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "系统设置/字典" |
| | | ], |
| | | "summary": "编辑字典", |
| | | "parameters": [ |
| | | { |
| | | "description": "字典信息", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.UpdateDict" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "系统设置/字典" |
| | | ], |
| | | "summary": "添加字典", |
| | | "parameters": [ |
| | | { |
| | | "description": "字典信息", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.AddDict" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api-jl/v1/system/dict/{id}": { |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "系统设置/字典" |
| | | ], |
| | | "summary": "删除字典", |
| | | "parameters": [ |
| | | { |
| | | "type": "string", |
| | | "description": "字典信息", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api-s/v1/organize/department": { |
| | | "get": { |
| | | "produces": [ |
| | |
| | | } |
| | | }, |
| | | "definitions": { |
| | | "constvar.DictType": { |
| | | "type": "integer", |
| | | "enum": [ |
| | | 0, |
| | | 1, |
| | | 2, |
| | | 3 |
| | | ], |
| | | "x-enum-comments": { |
| | | "DictTypeColor": "颜色", |
| | | "DictTypeMarket": "庄口", |
| | | "DictTypeSpec": "规格", |
| | | "DictTypeWorkshop": "车间" |
| | | }, |
| | | "x-enum-varnames": [ |
| | | "DictTypeMarket", |
| | | "DictTypeWorkshop", |
| | | "DictTypeColor", |
| | | "DictTypeSpec" |
| | | ] |
| | | }, |
| | | "gorm.DeletedAt": { |
| | | "type": "object", |
| | | "properties": { |
| | | "time": { |
| | | "type": "string" |
| | | }, |
| | | "valid": { |
| | | "description": "Valid is true if Time is not NULL", |
| | | "type": "boolean" |
| | | } |
| | | } |
| | | }, |
| | | "models.Department": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "models.Dict": { |
| | | "type": "object", |
| | | "properties": { |
| | | "createdAt": { |
| | | "type": "string" |
| | | }, |
| | | "deletedAt": { |
| | | "$ref": "#/definitions/gorm.DeletedAt" |
| | | }, |
| | | "dictType": { |
| | | "description": "字典类型", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/constvar.DictType" |
| | | } |
| | | ] |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "description": "名称", |
| | | "type": "string" |
| | | }, |
| | | "number": { |
| | | "description": "编号", |
| | | "type": "string" |
| | | }, |
| | | "remark": { |
| | | "description": "备注", |
| | | "type": "string" |
| | | }, |
| | | "updatedAt": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.AddDepartment": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | "parentId": { |
| | | "description": "上级部门ID 一级部门传0", |
| | | "type": "integer" |
| | | }, |
| | | "remark": { |
| | | "description": "备注", |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.AddDict": { |
| | | "type": "object", |
| | | "properties": { |
| | | "dictType": { |
| | | "description": "字典类型", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/constvar.DictType" |
| | | } |
| | | ] |
| | | }, |
| | | "name": { |
| | | "description": "名称", |
| | | "type": "string" |
| | | }, |
| | | "number": { |
| | | "description": "编码", |
| | | "type": "string" |
| | | }, |
| | | "remark": { |
| | | "description": "备注", |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateDict": { |
| | | "type": "object", |
| | | "properties": { |
| | | "dictType": { |
| | | "description": "字典类型", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/constvar.DictType" |
| | | } |
| | | ] |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "description": "名称", |
| | | "type": "string" |
| | | }, |
| | | "number": { |
| | | "description": "编码", |
| | | "type": "string" |
| | | }, |
| | | "remark": { |
| | | "description": "备注", |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "util.Response": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | "contact": {} |
| | | }, |
| | | "paths": { |
| | | "/api-jl/v1/system/dict": { |
| | | "get": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "系统设置/字典" |
| | | ], |
| | | "summary": "查询字典列表", |
| | | "parameters": [ |
| | | { |
| | | "enum": [ |
| | | 0, |
| | | 1, |
| | | 2, |
| | | 3 |
| | | ], |
| | | "type": "integer", |
| | | "x-enum-comments": { |
| | | "DictTypeColor": "颜色", |
| | | "DictTypeMarket": "庄口", |
| | | "DictTypeSpec": "规格", |
| | | "DictTypeWorkshop": "车间" |
| | | }, |
| | | "x-enum-varnames": [ |
| | | "DictTypeMarket", |
| | | "DictTypeWorkshop", |
| | | "DictTypeColor", |
| | | "DictTypeSpec" |
| | | ], |
| | | "description": "字典类型", |
| | | "name": "dictType", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "页码", |
| | | "name": "page", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "每页大小", |
| | | "name": "pageSize", |
| | | "in": "query" |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/util.ResponseList" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/models.Dict" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "put": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "系统设置/字典" |
| | | ], |
| | | "summary": "编辑字典", |
| | | "parameters": [ |
| | | { |
| | | "description": "字典信息", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.UpdateDict" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "系统设置/字典" |
| | | ], |
| | | "summary": "添加字典", |
| | | "parameters": [ |
| | | { |
| | | "description": "字典信息", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.AddDict" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api-jl/v1/system/dict/{id}": { |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "系统设置/字典" |
| | | ], |
| | | "summary": "删除字典", |
| | | "parameters": [ |
| | | { |
| | | "type": "string", |
| | | "description": "字典信息", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api-s/v1/organize/department": { |
| | | "get": { |
| | | "produces": [ |
| | |
| | | } |
| | | }, |
| | | "definitions": { |
| | | "constvar.DictType": { |
| | | "type": "integer", |
| | | "enum": [ |
| | | 0, |
| | | 1, |
| | | 2, |
| | | 3 |
| | | ], |
| | | "x-enum-comments": { |
| | | "DictTypeColor": "颜色", |
| | | "DictTypeMarket": "庄口", |
| | | "DictTypeSpec": "规格", |
| | | "DictTypeWorkshop": "车间" |
| | | }, |
| | | "x-enum-varnames": [ |
| | | "DictTypeMarket", |
| | | "DictTypeWorkshop", |
| | | "DictTypeColor", |
| | | "DictTypeSpec" |
| | | ] |
| | | }, |
| | | "gorm.DeletedAt": { |
| | | "type": "object", |
| | | "properties": { |
| | | "time": { |
| | | "type": "string" |
| | | }, |
| | | "valid": { |
| | | "description": "Valid is true if Time is not NULL", |
| | | "type": "boolean" |
| | | } |
| | | } |
| | | }, |
| | | "models.Department": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "models.Dict": { |
| | | "type": "object", |
| | | "properties": { |
| | | "createdAt": { |
| | | "type": "string" |
| | | }, |
| | | "deletedAt": { |
| | | "$ref": "#/definitions/gorm.DeletedAt" |
| | | }, |
| | | "dictType": { |
| | | "description": "字典类型", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/constvar.DictType" |
| | | } |
| | | ] |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "description": "名称", |
| | | "type": "string" |
| | | }, |
| | | "number": { |
| | | "description": "编号", |
| | | "type": "string" |
| | | }, |
| | | "remark": { |
| | | "description": "备注", |
| | | "type": "string" |
| | | }, |
| | | "updatedAt": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.AddDepartment": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | "parentId": { |
| | | "description": "上级部门ID 一级部门传0", |
| | | "type": "integer" |
| | | }, |
| | | "remark": { |
| | | "description": "备注", |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.AddDict": { |
| | | "type": "object", |
| | | "properties": { |
| | | "dictType": { |
| | | "description": "字典类型", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/constvar.DictType" |
| | | } |
| | | ] |
| | | }, |
| | | "name": { |
| | | "description": "名称", |
| | | "type": "string" |
| | | }, |
| | | "number": { |
| | | "description": "编码", |
| | | "type": "string" |
| | | }, |
| | | "remark": { |
| | | "description": "备注", |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateDict": { |
| | | "type": "object", |
| | | "properties": { |
| | | "dictType": { |
| | | "description": "字典类型", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/constvar.DictType" |
| | | } |
| | | ] |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "description": "名称", |
| | | "type": "string" |
| | | }, |
| | | "number": { |
| | | "description": "编码", |
| | | "type": "string" |
| | | }, |
| | | "remark": { |
| | | "description": "备注", |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "util.Response": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | definitions: |
| | | constvar.DictType: |
| | | enum: |
| | | - 0 |
| | | - 1 |
| | | - 2 |
| | | - 3 |
| | | type: integer |
| | | x-enum-comments: |
| | | DictTypeColor: 颜色 |
| | | DictTypeMarket: 庄口 |
| | | DictTypeSpec: 规格 |
| | | DictTypeWorkshop: 车间 |
| | | x-enum-varnames: |
| | | - DictTypeMarket |
| | | - DictTypeWorkshop |
| | | - DictTypeColor |
| | | - DictTypeSpec |
| | | gorm.DeletedAt: |
| | | properties: |
| | | time: |
| | | type: string |
| | | valid: |
| | | description: Valid is true if Time is not NULL |
| | | type: boolean |
| | | type: object |
| | | models.Department: |
| | | properties: |
| | | children: |
| | |
| | | description: 排序 |
| | | type: integer |
| | | type: object |
| | | models.Dict: |
| | | properties: |
| | | createdAt: |
| | | type: string |
| | | deletedAt: |
| | | $ref: '#/definitions/gorm.DeletedAt' |
| | | dictType: |
| | | allOf: |
| | | - $ref: '#/definitions/constvar.DictType' |
| | | description: 字典类型 |
| | | id: |
| | | type: integer |
| | | name: |
| | | description: 名称 |
| | | type: string |
| | | number: |
| | | description: 编号 |
| | | type: string |
| | | remark: |
| | | description: 备注 |
| | | type: string |
| | | updatedAt: |
| | | type: string |
| | | type: object |
| | | request.AddDepartment: |
| | | properties: |
| | | name: |
| | |
| | | parentId: |
| | | description: 上级部门ID 一级部门传0 |
| | | type: integer |
| | | remark: |
| | | description: 备注 |
| | | type: string |
| | | type: object |
| | | request.AddDict: |
| | | properties: |
| | | dictType: |
| | | allOf: |
| | | - $ref: '#/definitions/constvar.DictType' |
| | | description: 字典类型 |
| | | name: |
| | | description: 名称 |
| | | type: string |
| | | number: |
| | | description: 编码 |
| | | type: string |
| | | remark: |
| | | description: 备注 |
| | | type: string |
| | |
| | | parentId: |
| | | description: 上级部门ID 一级部门传0 |
| | | type: integer |
| | | remark: |
| | | description: 备注 |
| | | type: string |
| | | type: object |
| | | request.UpdateDict: |
| | | properties: |
| | | dictType: |
| | | allOf: |
| | | - $ref: '#/definitions/constvar.DictType' |
| | | description: 字典类型 |
| | | id: |
| | | type: integer |
| | | name: |
| | | description: 名称 |
| | | type: string |
| | | number: |
| | | description: 编码 |
| | | type: string |
| | | remark: |
| | | description: 备注 |
| | | type: string |
| | |
| | | info: |
| | | contact: {} |
| | | paths: |
| | | /api-jl/v1/system/dict: |
| | | get: |
| | | parameters: |
| | | - description: 字典类型 |
| | | enum: |
| | | - 0 |
| | | - 1 |
| | | - 2 |
| | | - 3 |
| | | in: query |
| | | name: dictType |
| | | type: integer |
| | | x-enum-comments: |
| | | DictTypeColor: 颜色 |
| | | DictTypeMarket: 庄口 |
| | | DictTypeSpec: 规格 |
| | | DictTypeWorkshop: 车间 |
| | | x-enum-varnames: |
| | | - DictTypeMarket |
| | | - DictTypeWorkshop |
| | | - DictTypeColor |
| | | - DictTypeSpec |
| | | - description: 页码 |
| | | in: query |
| | | name: page |
| | | type: integer |
| | | - description: 每页大小 |
| | | in: query |
| | | name: pageSize |
| | | type: integer |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: 成功 |
| | | schema: |
| | | allOf: |
| | | - $ref: '#/definitions/util.ResponseList' |
| | | - properties: |
| | | data: |
| | | items: |
| | | $ref: '#/definitions/models.Dict' |
| | | type: array |
| | | type: object |
| | | summary: 查询字典列表 |
| | | tags: |
| | | - 系统设置/字典 |
| | | post: |
| | | parameters: |
| | | - description: 字典信息 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.AddDict' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: 成功 |
| | | schema: |
| | | $ref: '#/definitions/util.Response' |
| | | summary: 添加字典 |
| | | tags: |
| | | - 系统设置/字典 |
| | | put: |
| | | parameters: |
| | | - description: 字典信息 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.UpdateDict' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: 成功 |
| | | schema: |
| | | $ref: '#/definitions/util.Response' |
| | | summary: 编辑字典 |
| | | tags: |
| | | - 系统设置/字典 |
| | | /api-jl/v1/system/dict/{id}: |
| | | delete: |
| | | parameters: |
| | | - description: 字典信息 |
| | | in: path |
| | | name: id |
| | | required: true |
| | | type: string |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: 成功 |
| | | schema: |
| | | $ref: '#/definitions/util.Response' |
| | | summary: 删除字典 |
| | | tags: |
| | | - 系统设置/字典 |
| | | /api-s/v1/organize/department: |
| | | get: |
| | | parameters: |
| | |
| | | package jialian |
| | | package main |
| | | |
| | | import ( |
| | | "jialian/conf" |
| | |
| | | logx.Errorf("db init error! ", err.Error()) |
| | | return |
| | | } |
| | | |
| | | // 启动APS RPC服务 |
| | | //safe.Go(service.StartAPServer) |
| | | |
| | | go shutdown() |
| | | logx.Infof("server start serve...") |
| | |
| | | |
| | | func RegisterTables() error { |
| | | db := mysqlx.GetDB() |
| | | err := db.AutoMigrate() |
| | | err := db.AutoMigrate( |
| | | Dict{}, |
| | | ) |
| | | return err |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | func InsertDefaultData() { |
| | | models := []interface{}{ |
| | | NewDepartmentSearch(), |
| | | } |
| | | models := []interface{}{} |
| | | for _, model := range models { |
| | | if id, ok := model.(InitDefaultData); ok { |
| | | if err := id.InitDefaultData(); err != nil { |
| | |
| | | return records, total, nil |
| | | } |
| | | |
| | | func (slf *DepartmentSearch) FindNotTotal() ([]*Department, error) { |
| | | func (slf *DepartmentSearch) FindAll() ([]*Department, error) { |
| | | var ( |
| | | records = make([]*Department, 0) |
| | | db = slf.build() |
New file |
| | |
| | | package models |
| | | |
| | | import ( |
| | | "fmt" |
| | | "gorm.io/gorm" |
| | | "jialian/constvar" |
| | | "jialian/pkg/mysqlx" |
| | | ) |
| | | |
| | | type ( |
| | | // Dict 词典 |
| | | Dict struct { |
| | | gorm.Model |
| | | DictType constvar.DictType `gorm:"index;type:tinyint(3);not null;comment:字典类型"` //字典类型 |
| | | Number string `gorm:"type:varchar(255);not null;comment:编号" json:"number"` //编号 |
| | | Name string `gorm:"type:varchar(255);not null;comment:名称" json:"name"` //名称 |
| | | Remark string `gorm:"type:varchar(255);not null;comment:备注" json:"remark"` //备注 |
| | | } |
| | | |
| | | DictSearch struct { |
| | | Dict |
| | | Order string |
| | | PageNum int |
| | | PageSize int |
| | | Orm *gorm.DB |
| | | } |
| | | ) |
| | | |
| | | func (slf *Dict) TableName() string { |
| | | return "dict" |
| | | } |
| | | |
| | | func NewDictSearch() *DictSearch { |
| | | return &DictSearch{Orm: mysqlx.GetDB()} |
| | | } |
| | | |
| | | func (slf *DictSearch) SetOrm(tx *gorm.DB) *DictSearch { |
| | | slf.Orm = tx |
| | | return slf |
| | | } |
| | | |
| | | func (slf *DictSearch) SetPage(page, size int) *DictSearch { |
| | | slf.PageNum, slf.PageSize = page, size |
| | | return slf |
| | | } |
| | | |
| | | func (slf *DictSearch) SetOrder(order string) *DictSearch { |
| | | slf.Order = order |
| | | return slf |
| | | } |
| | | |
| | | func (slf *DictSearch) SetID(id uint) *DictSearch { |
| | | slf.ID = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *DictSearch) SetNumber(number string) *DictSearch { |
| | | slf.Number = number |
| | | return slf |
| | | } |
| | | |
| | | func (slf *DictSearch) SetName(name string) *DictSearch { |
| | | slf.Name = name |
| | | return slf |
| | | } |
| | | |
| | | func (slf *DictSearch) SetDictType(dt constvar.DictType) *DictSearch { |
| | | slf.DictType = dt |
| | | return slf |
| | | } |
| | | |
| | | func (slf *DictSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Table(slf.TableName()) |
| | | |
| | | if slf.ID != 0 { |
| | | db = db.Where("id = ?", slf.ID) |
| | | } |
| | | |
| | | if slf.Order != "" { |
| | | db = db.Order(slf.Order) |
| | | } |
| | | |
| | | if slf.Number != "" { |
| | | db = db.Where("number = ?", slf.Number) |
| | | } |
| | | |
| | | if slf.DictType != 0 { |
| | | db = db.Where("dict_type = ?", slf.DictType) |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |
| | | // Create 单条插入 |
| | | func (slf *DictSearch) Create(record *Dict) error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Create(record).Error; err != nil { |
| | | return fmt.Errorf("create err: %v, record: %+v", err, record) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | // CreateBatch 批量插入 |
| | | func (slf *DictSearch) CreateBatch(records []*Dict) error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Create(&records).Error; err != nil { |
| | | return fmt.Errorf("create batch err: %v, records: %+v", err, records) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *DictSearch) Save(record *Dict) error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Omit("CreatedAt").Save(record).Error; err != nil { |
| | | return fmt.Errorf("save err: %v, record: %+v", err, record) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *DictSearch) Update(record *Dict) error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Updates(record).Error; err != nil { |
| | | return fmt.Errorf("save err: %v, record: %+v", err, record) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *DictSearch) UpdateByMap(upMap map[string]interface{}) error { |
| | | var ( |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if err := db.Updates(upMap).Error; err != nil { |
| | | return fmt.Errorf("update by map err: %v, upMap: %+v", err, upMap) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *DictSearch) UpdateByQuery(query string, args []interface{}, upMap map[string]interface{}) error { |
| | | var ( |
| | | db = slf.Orm.Table(slf.TableName()).Where(query, args...) |
| | | ) |
| | | |
| | | if err := db.Updates(upMap).Error; err != nil { |
| | | return fmt.Errorf("update by query err: %v, query: %s, args: %+v, upMap: %+v", err, query, args, upMap) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *DictSearch) Delete() error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Unscoped().Delete(&Dict{}).Error; err != nil { |
| | | return err |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *DictSearch) First() (*Dict, error) { |
| | | var ( |
| | | record = new(Dict) |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if err := db.First(record).Error; err != nil { |
| | | return record, err |
| | | } |
| | | |
| | | return record, nil |
| | | } |
| | | |
| | | func (slf *DictSearch) Find() ([]*Dict, int64, error) { |
| | | var ( |
| | | records = make([]*Dict, 0) |
| | | total int64 |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if err := db.Count(&total).Error; err != nil { |
| | | return records, total, fmt.Errorf("find count err: %v", err) |
| | | } |
| | | if slf.PageNum*slf.PageSize > 0 { |
| | | db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) |
| | | } |
| | | if err := db.Find(&records).Error; err != nil { |
| | | return records, total, fmt.Errorf("find records err: %v", err) |
| | | } |
| | | |
| | | return records, total, nil |
| | | } |
| | | |
| | | func (slf *DictSearch) FindAll() ([]*Dict, error) { |
| | | var ( |
| | | records = make([]*Dict, 0) |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if slf.PageNum*slf.PageSize > 0 { |
| | | db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) |
| | | } |
| | | if err := db.Find(&records).Error; err != nil { |
| | | return records, fmt.Errorf("find records err: %v", err) |
| | | } |
| | | |
| | | return records, nil |
| | | } |
| | | |
| | | // FindByQuery 指定条件查询. |
| | | func (slf *DictSearch) FindByQuery(query string, args []interface{}) ([]*Dict, int64, error) { |
| | | var ( |
| | | records = make([]*Dict, 0) |
| | | total int64 |
| | | db = slf.Orm.Table(slf.TableName()).Where(query, args...) |
| | | ) |
| | | |
| | | if err := db.Count(&total).Error; err != nil { |
| | | return records, total, fmt.Errorf("find by query count err: %v", err) |
| | | } |
| | | if slf.PageNum*slf.PageSize > 0 { |
| | | db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) |
| | | } |
| | | if err := db.Find(&records).Error; err != nil { |
| | | return records, total, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args) |
| | | } |
| | | |
| | | return records, total, nil |
| | | } |
| | | |
| | | // FindByQueryNotTotal 指定条件查询&不查询总条数. |
| | | func (slf *DictSearch) FindByQueryNotTotal(query string, args []interface{}) ([]*Dict, error) { |
| | | var ( |
| | | records = make([]*Dict, 0) |
| | | db = slf.Orm.Table(slf.TableName()).Where(query, args...) |
| | | ) |
| | | |
| | | if slf.PageNum*slf.PageSize > 0 { |
| | | db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) |
| | | } |
| | | if err := db.Find(&records).Error; err != nil { |
| | | return records, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args) |
| | | } |
| | | |
| | | return records, nil |
| | | } |
| | | |
| | | // InitDefaultData 初始化数据 |
| | | func (slf *DictSearch) InitDefaultData() error { |
| | | return nil |
| | | } |
| | |
| | | r.StaticFS(conf.LocalConf.StorePath, http.Dir(conf.LocalConf.StorePath)) // 为用户头像和文件提供静态地址 |
| | | r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) |
| | | |
| | | urlPrefix := "/api-s/v1" |
| | | urlPrefix := "/api-jl/v1" |
| | | |
| | | // 组织管理 |
| | | departmentController := new(controllers.DepartmentController) |
| | |
| | | organizeAPI.DELETE("department/:id", departmentController.Delete) // 删除部门 |
| | | } |
| | | |
| | | // 词典管理 |
| | | DictController := new(controllers.DictController) |
| | | systemApi := r.Group(urlPrefix + "/system") |
| | | { |
| | | systemApi.GET("dict", DictController.List) // 获取词典列表 |
| | | systemApi.POST("dict", DictController.Add) // 新增词典 |
| | | systemApi.PUT("dict", DictController.Update) // 修改词典 |
| | | systemApi.DELETE("dict/:id", DictController.Delete) // 删除词典 |
| | | } |
| | | |
| | | return r |
| | | } |