13 changed files with 806 additions and 3 deletions
@ -0,0 +1,541 @@ |
|||
package dict |
|||
|
|||
import ( |
|||
"appPlatform/models/modelAppPlatform" |
|||
"appPlatform/overall" |
|||
"appPlatform/overall/publicmethod" |
|||
"strconv" |
|||
"time" |
|||
|
|||
"github.com/gin-gonic/gin" |
|||
) |
|||
|
|||
/* |
|||
* |
|||
@ 作者: 秦东 |
|||
@ 时间: 2023-05-25 10:33:18 |
|||
@ 功能: 字典类型列表 |
|||
@ 参数 |
|||
|
|||
# |
|||
|
|||
@ 返回值 |
|||
|
|||
# |
|||
|
|||
@ 方法原型 |
|||
|
|||
# |
|||
*/ |
|||
func (a *ApiMethod) DictTypeList(c *gin.Context) { |
|||
var requestData DictType |
|||
c.ShouldBindJSON(&requestData) |
|||
if requestData.Page == 0 { |
|||
requestData.Page = 1 |
|||
} |
|||
if requestData.PageSize == 0 { |
|||
requestData.PageSize = 15 |
|||
} |
|||
var dictListCont []modelAppPlatform.DictType |
|||
gormDb := overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.DictType{}).Where("`status` BETWEEN ? AND ?", 1, 2) |
|||
if requestData.KeyWords != "" { |
|||
gormDb.Where("`name` like ?", "%"+requestData.KeyWords+"%") |
|||
} |
|||
var total int64 |
|||
totalErr := gormDb.Count(&total).Error |
|||
if totalErr != nil { |
|||
total = 0 |
|||
} |
|||
gormDb = publicmethod.PageTurningSettings(gormDb, requestData.Page, requestData.PageSize) |
|||
err := gormDb.Find(&dictListCont).Error |
|||
if err != nil && len(dictListCont) < 1 { |
|||
publicmethod.Result(105, err, c) |
|||
return |
|||
} |
|||
var sendData []SendDictTypeList |
|||
for _, v := range dictListCont { |
|||
var sendCont SendDictTypeList |
|||
sendCont.Id = v.Id //
|
|||
sendCont.Name = v.Name //字典类型名称"`
|
|||
sendCont.Code = v.Code //字典类型编码"`
|
|||
sendCont.Status = v.Status //显示状态(1:显示;2:隐藏,3:删除)"`
|
|||
sendCont.Remark = v.Remark //字典类型描述"`
|
|||
sendCont.Time = v.Time //创建时间"`
|
|||
sendCont.CodeKey = strconv.FormatInt(v.Code, 10) |
|||
sendData = append(sendData, sendCont) |
|||
} |
|||
|
|||
publicmethod.ResultList(0, requestData.Page, requestData.PageSize, total, int64(len(sendData)), sendData, c) |
|||
} |
|||
|
|||
/* |
|||
* |
|||
@ 作者: 秦东 |
|||
@ 时间: 2023-05-25 11:06:39 |
|||
@ 功能: 新增字典类别 |
|||
@ 参数 |
|||
|
|||
# |
|||
|
|||
@ 返回值 |
|||
|
|||
# |
|||
|
|||
@ 方法原型 |
|||
|
|||
# |
|||
*/ |
|||
func (a *ApiMethod) AddDictType(c *gin.Context) { |
|||
var requestData AddNewDictType |
|||
err := c.ShouldBindJSON(&requestData) |
|||
if err != nil { |
|||
publicmethod.Result(100, err, c) |
|||
return |
|||
} |
|||
if requestData.Name == "" { |
|||
publicmethod.Result(1, err, c, "请输入字典类型名称!") |
|||
return |
|||
} |
|||
if requestData.Status == 0 { |
|||
requestData.Status = 1 |
|||
} |
|||
var dictCont modelAppPlatform.DictType |
|||
err = dictCont.GetCont(map[string]interface{}{"`name`": requestData.Name}, "`id`") |
|||
if err == nil || dictCont.Id != 0 { |
|||
publicmethod.Result(103, err, c) |
|||
return |
|||
} |
|||
dictCont.Name = requestData.Name //字典类型名称"`
|
|||
dictCont.Code = publicmethod.GetUUid(4) //字典类型编码"`
|
|||
dictCont.Status = requestData.Status //显示状态(1:显示;2:隐藏,3:删除)"`
|
|||
dictCont.Remark = requestData.Remark //字典类型描述"`
|
|||
dictCont.Time = time.Now().Unix() //创建时间"`
|
|||
err = overall.CONSTANT_DB_AppPlatform.Create(&dictCont).Error |
|||
if err != nil { |
|||
publicmethod.Result(104, err, c) |
|||
return |
|||
} |
|||
publicmethod.Result(0, err, c) |
|||
} |
|||
|
|||
/* |
|||
* |
|||
@ 作者: 秦东 |
|||
@ 时间: 2023-05-25 13:07:48 |
|||
@ 功能: 查看字典类型内容 |
|||
@ 参数 |
|||
|
|||
# |
|||
|
|||
@ 返回值 |
|||
|
|||
# |
|||
|
|||
@ 方法原型 |
|||
|
|||
# |
|||
*/ |
|||
func (a *ApiMethod) GetDictTypeCont(c *gin.Context) { |
|||
id := c.Query("id") |
|||
if id == "" { |
|||
publicmethod.Result(1, id, c, "未知字典类型!") |
|||
return |
|||
} |
|||
var dictCont modelAppPlatform.DictType |
|||
err := dictCont.GetCont(map[string]interface{}{"`id`": id}) |
|||
if err != nil { |
|||
publicmethod.Result(105, err, c) |
|||
return |
|||
} |
|||
publicmethod.Result(0, dictCont, c) |
|||
} |
|||
|
|||
/* |
|||
* |
|||
@ 作者: 秦东 |
|||
@ 时间: 2023-05-25 13:21:21 |
|||
@ 功能: 编辑字典类型内容 |
|||
@ 参数 |
|||
|
|||
# |
|||
|
|||
@ 返回值 |
|||
|
|||
# |
|||
|
|||
@ 方法原型 |
|||
|
|||
# |
|||
*/ |
|||
func (a *ApiMethod) EditDictCont(c *gin.Context) { |
|||
var requestData EditDictTypeInfo |
|||
c.ShouldBindJSON(&requestData) |
|||
if requestData.Id == "" { |
|||
publicmethod.Result(1, requestData, c, "未知字典类型!") |
|||
return |
|||
} |
|||
if requestData.Name == "" { |
|||
publicmethod.Result(1, requestData, c, "请输入字典类型名称!") |
|||
return |
|||
} |
|||
if requestData.Status == 0 { |
|||
requestData.Status = 1 |
|||
} |
|||
whery := publicmethod.MapOut[string]() |
|||
whery["`id`"] = requestData.Id |
|||
var dictTypeOldCont modelAppPlatform.DictType |
|||
err := dictTypeOldCont.GetCont(whery) |
|||
if err != nil { |
|||
publicmethod.Result(107, err, c) |
|||
return |
|||
} |
|||
editCont := publicmethod.MapOut[string]() |
|||
if requestData.Name != dictTypeOldCont.Name { |
|||
var dictTypeCont modelAppPlatform.DictType |
|||
err = dictTypeCont.GetCont(map[string]interface{}{"`name`": requestData.Name}, "`id`") |
|||
if err == nil || dictTypeCont.Id != 0 { |
|||
publicmethod.Result(103, err, c) |
|||
return |
|||
} |
|||
editCont["`name`"] = requestData.Name |
|||
} |
|||
if requestData.Status != dictTypeOldCont.Status { |
|||
editCont["`status`"] = requestData.Status |
|||
} |
|||
if requestData.Remark != dictTypeOldCont.Remark { |
|||
editCont["`remark`"] = requestData.Remark |
|||
} |
|||
if len(editCont) > 0 { |
|||
editCont["`time`"] = time.Now().Unix() |
|||
var editDictTypeCont modelAppPlatform.DictType |
|||
err := editDictTypeCont.EiteCont(whery, editCont) |
|||
if err != nil { |
|||
publicmethod.Result(106, err, c) |
|||
return |
|||
} |
|||
syncSeting.Add(1) |
|||
go EditDictContStatus(dictTypeOldCont.Id, requestData.Status) |
|||
} |
|||
syncSeting.Wait() |
|||
publicmethod.Result(0, err, c) |
|||
} |
|||
|
|||
// 操作字典类型下属内容
|
|||
func EditDictContStatus(typeId, status int) { |
|||
defer syncSeting.Done() |
|||
var dictCont modelAppPlatform.Dictionary |
|||
dictCont.EiteCont(map[string]interface{}{"`typeCode`": typeId}, map[string]interface{}{"`status`": status, "`time`": time.Now().Unix()}) |
|||
} |
|||
|
|||
/* |
|||
* |
|||
@ 作者: 秦东 |
|||
@ 时间: 2023-05-25 13:54:09 |
|||
@ 功能: 删除字典类别 |
|||
@ 参数 |
|||
|
|||
# |
|||
|
|||
@ 返回值 |
|||
|
|||
# |
|||
|
|||
@ 方法原型 |
|||
|
|||
# |
|||
*/ |
|||
func (a *ApiMethod) DelDictTypeCont(c *gin.Context) { |
|||
var requestData DelDictTypeInfo |
|||
err := c.ShouldBindJSON(&requestData) |
|||
if err != nil { |
|||
publicmethod.Result(100, err, c) |
|||
return |
|||
} |
|||
if len(requestData.Id) < 1 { |
|||
publicmethod.Result(101, err, c) |
|||
return |
|||
} |
|||
editDictTypeInfo := publicmethod.MapOut[string]() |
|||
editDictTypeInfo["`status`"] = 3 |
|||
err = overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.DictType{}).Where("`id` IN ?", requestData.Id).Updates(editDictTypeInfo).Error |
|||
if err != nil { |
|||
publicmethod.Result(108, err, c) |
|||
return |
|||
} |
|||
for i := 0; i < len(requestData.Id); i++ { |
|||
dictTypeId, dictErr := strconv.Atoi(requestData.Id[i]) |
|||
if dictErr == nil { |
|||
syncSeting.Add(1) |
|||
go EditDictContStatus(dictTypeId, 3) |
|||
} |
|||
} |
|||
syncSeting.Wait() |
|||
publicmethod.Result(0, err, c) |
|||
} |
|||
|
|||
/* |
|||
* |
|||
@ 作者: 秦东 |
|||
@ 时间: 2023-05-25 14:45:16 |
|||
@ 功能: 获取字典内容列表 |
|||
@ 参数 |
|||
|
|||
# |
|||
|
|||
@ 返回值 |
|||
|
|||
# |
|||
|
|||
@ 方法原型 |
|||
|
|||
# |
|||
*/ |
|||
func (a *ApiMethod) GetDictionary(c *gin.Context) { |
|||
var requestData DictionaryList |
|||
c.ShouldBindJSON(&requestData) |
|||
if requestData.CodeType == "" { |
|||
publicmethod.Result(1, requestData, c, "未知字典类型") |
|||
return |
|||
} |
|||
if requestData.Page == 0 { |
|||
requestData.Page = 1 |
|||
} |
|||
if requestData.PageSize == 0 { |
|||
requestData.PageSize = 10 |
|||
} |
|||
var dictionaryContList []modelAppPlatform.Dictionary |
|||
gormDb := overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.Dictionary{}).Where("`status` BETWEEN ? AND ?", 1, 2) |
|||
if requestData.KeyWords != "" { |
|||
gormDb.Where("`name` like ?", "%"+requestData.KeyWords+"%") |
|||
} |
|||
var total int64 |
|||
totalErr := gormDb.Count(&total).Error |
|||
if totalErr != nil { |
|||
total = 0 |
|||
} |
|||
gormDb = publicmethod.PageTurningSettings(gormDb, requestData.Page, requestData.PageSize) |
|||
err := gormDb.Order("`sort` ASC").Find(&dictionaryContList).Error |
|||
if err != nil && len(dictionaryContList) < 1 { |
|||
publicmethod.Result(105, err, c) |
|||
return |
|||
} |
|||
var sendDataList []SendDictionaryList |
|||
for _, v := range dictionaryContList { |
|||
var sendCont SendDictionaryList |
|||
sendCont.Id = v.Id |
|||
sendCont.Name = v.Name //字典内容名称"`
|
|||
sendCont.TypeCode = v.TypeCode //字典类型编码"`
|
|||
sendCont.Code = v.Code //字典内编码"`
|
|||
sendCont.Sort = v.Sort //排序(数字越小排名越靠前))"`
|
|||
sendCont.Status = v.Status //显示状态(1:显示;2:隐藏,3:删除)"`
|
|||
sendCont.Remark = v.Remark //字典内描述"`
|
|||
sendCont.Time = v.Time //创建时间"`
|
|||
sendCont.CodeString = strconv.FormatInt(v.Code, 10) |
|||
sendDataList = append(sendDataList, sendCont) |
|||
} |
|||
publicmethod.ResultList(0, requestData.Page, requestData.PageSize, total, int64(len(sendDataList)), sendDataList, c) |
|||
} |
|||
|
|||
/* |
|||
* |
|||
@ 作者: 秦东 |
|||
@ 时间: 2023-05-25 15:26:59 |
|||
@ 功能: 新增字典内容 |
|||
@ 参数 |
|||
|
|||
# |
|||
|
|||
@ 返回值 |
|||
|
|||
# |
|||
|
|||
@ 方法原型 |
|||
|
|||
# |
|||
*/ |
|||
func (a *ApiMethod) AddDictionaryCont(c *gin.Context) { |
|||
var requestData AddNewDictionaryCont |
|||
c.ShouldBindJSON(&requestData) |
|||
if requestData.TypeCode == "" { |
|||
publicmethod.Result(1, requestData, c, "未知字典类型") |
|||
return |
|||
} |
|||
typeCode, err := strconv.ParseInt(requestData.TypeCode, 10, 64) |
|||
if err != nil { |
|||
publicmethod.Result(1, err, c, "未知字典类型") |
|||
return |
|||
} |
|||
if requestData.Name == "" { |
|||
publicmethod.Result(1, requestData, c, "请输入字典内容名称") |
|||
return |
|||
} |
|||
var dictContJudge modelAppPlatform.Dictionary |
|||
err = dictContJudge.GetCont(map[string]interface{}{"`name`": requestData.Name}, "`id`") |
|||
if err == nil || dictContJudge.Id != 0 { |
|||
publicmethod.Result(103, err, c) |
|||
return |
|||
} |
|||
if requestData.Sort == 0 { |
|||
requestData.Sort = 50 |
|||
} |
|||
if requestData.Status == 0 { |
|||
requestData.Status = 1 |
|||
} |
|||
var dictCont modelAppPlatform.Dictionary |
|||
dictCont.Name = requestData.Name //字典内容名称"`
|
|||
dictCont.TypeCode = typeCode //字典类型编码"`
|
|||
dictCont.Code = publicmethod.GetUUid(6) //字典内编码"`
|
|||
dictCont.Sort = requestData.Sort //排序(数字越小排名越靠前))"`
|
|||
dictCont.Status = requestData.Status //显示状态(1:显示;2:隐藏,3:删除)"`
|
|||
dictCont.Remark = requestData.Remark //字典内描述"`
|
|||
dictCont.Time = time.Now().Unix() //创建时间"`
|
|||
err = overall.CONSTANT_DB_AppPlatform.Create(&dictCont).Error |
|||
if err != nil { |
|||
publicmethod.Result(104, err, c) |
|||
return |
|||
} |
|||
publicmethod.Result(0, err, c) |
|||
} |
|||
|
|||
/* |
|||
* |
|||
@ 作者: 秦东 |
|||
@ 时间: 2023-05-25 15:49:36 |
|||
@ 功能: 查看字典内容详情 |
|||
@ 参数 |
|||
|
|||
# |
|||
|
|||
@ 返回值 |
|||
|
|||
# |
|||
|
|||
@ 方法原型 |
|||
|
|||
# |
|||
*/ |
|||
func (a *ApiMethod) GetDictionaryCont(c *gin.Context) { |
|||
id := c.Query("id") |
|||
if id == "" { |
|||
publicmethod.Result(1, id, c, "未知字典内容!") |
|||
return |
|||
} |
|||
var dictCont modelAppPlatform.Dictionary |
|||
err := dictCont.GetCont(map[string]interface{}{"`id`": id}) |
|||
if err != nil { |
|||
publicmethod.Result(105, err, c) |
|||
return |
|||
} |
|||
publicmethod.Result(0, dictCont, c) |
|||
} |
|||
|
|||
/* |
|||
* |
|||
@ 作者: 秦东 |
|||
@ 时间: 2023-05-25 16:19:53 |
|||
@ 功能: |
|||
@ 参数 |
|||
|
|||
# |
|||
|
|||
@ 返回值 |
|||
|
|||
# |
|||
|
|||
@ 方法原型 |
|||
|
|||
# |
|||
*/ |
|||
func (a *ApiMethod) EditDictionaryCont(c *gin.Context) { |
|||
var requestData EditNewDictionaryCont |
|||
c.ShouldBindJSON(&requestData) |
|||
if requestData.Id == 0 { |
|||
publicmethod.Result(1, requestData.Id, c, "未知字典内容!") |
|||
return |
|||
} |
|||
if requestData.Name == "" { |
|||
publicmethod.Result(1, requestData.Name, c, "请输入字典名称!") |
|||
return |
|||
} |
|||
if requestData.Sort == 0 { |
|||
requestData.Sort = 50 |
|||
} |
|||
if requestData.Status == 0 { |
|||
requestData.Status = 1 |
|||
} |
|||
whery := publicmethod.MapOut[string]() |
|||
whery["`id`"] = requestData.Id |
|||
var oldDictCont modelAppPlatform.Dictionary |
|||
err := oldDictCont.GetCont(whery) |
|||
if err != nil { |
|||
publicmethod.Result(107, err, c) |
|||
return |
|||
} |
|||
editCont := publicmethod.MapOut[string]() |
|||
if requestData.Name != oldDictCont.Name { |
|||
var dictCont modelAppPlatform.Dictionary |
|||
err = dictCont.GetCont(map[string]interface{}{"`name`": requestData.Name, "`typeCode`": oldDictCont.TypeCode}, "`id`") |
|||
if err == nil || dictCont.Id != 0 { |
|||
publicmethod.Result(103, err, c) |
|||
return |
|||
} |
|||
editCont["`name`"] = requestData.Name |
|||
} |
|||
if requestData.Status != oldDictCont.Status { |
|||
editCont["`status`"] = requestData.Status |
|||
} |
|||
if requestData.Remark != oldDictCont.Remark { |
|||
editCont["`remark`"] = requestData.Remark |
|||
} |
|||
if requestData.Sort != oldDictCont.Sort { |
|||
editCont["`sort`"] = requestData.Sort |
|||
} |
|||
if len(editCont) > 0 { |
|||
editCont["`time`"] = time.Now().Unix() |
|||
var editDictCont modelAppPlatform.Dictionary |
|||
err := editDictCont.EiteCont(whery, editCont) |
|||
if err != nil { |
|||
publicmethod.Result(106, err, c) |
|||
return |
|||
} |
|||
} |
|||
publicmethod.Result(0, err, c) |
|||
} |
|||
|
|||
/* |
|||
* |
|||
@ 作者: 秦东 |
|||
@ 时间: 2023-05-25 16:35:04 |
|||
@ 功能: 删除字典内容 |
|||
@ 参数 |
|||
|
|||
# |
|||
|
|||
@ 返回值 |
|||
|
|||
# |
|||
|
|||
@ 方法原型 |
|||
|
|||
# |
|||
*/ |
|||
func (a *ApiMethod) DelDictionaryCont(c *gin.Context) { |
|||
var requestData DelDictTypeInfo |
|||
err := c.ShouldBindJSON(&requestData) |
|||
if err != nil { |
|||
publicmethod.Result(100, err, c) |
|||
return |
|||
} |
|||
if len(requestData.Id) < 1 { |
|||
publicmethod.Result(101, err, c) |
|||
return |
|||
} |
|||
editDictTypeInfo := publicmethod.MapOut[string]() |
|||
editDictTypeInfo["`status`"] = 3 |
|||
err = overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.Dictionary{}).Where("`id` IN ?", requestData.Id).Updates(editDictTypeInfo).Error |
|||
if err != nil { |
|||
publicmethod.Result(108, err, c) |
|||
return |
|||
} |
|||
publicmethod.Result(0, err, c) |
|||
} |
|||
@ -0,0 +1,94 @@ |
|||
package dict |
|||
|
|||
import ( |
|||
"appPlatform/models/modelAppPlatform" |
|||
"appPlatform/overall/publicmethod" |
|||
"sync" |
|||
|
|||
"github.com/gin-gonic/gin" |
|||
) |
|||
|
|||
// 协程设置
|
|||
var syncSeting = sync.WaitGroup{} |
|||
|
|||
type ApiMethod struct{} |
|||
|
|||
/* |
|||
* |
|||
@ 作者: 秦东 |
|||
@ 时间: 2023-05-25 10:20:11 |
|||
@ 功能:字典入口 |
|||
@ 参数 |
|||
|
|||
# |
|||
|
|||
@ 返回值 |
|||
|
|||
# |
|||
|
|||
@ 方法原型 |
|||
|
|||
# |
|||
*/ |
|||
func (a *ApiMethod) Index(c *gin.Context) { |
|||
outputCont := publicmethod.MapOut[string]() |
|||
outputCont["index"] = "字典入口" |
|||
publicmethod.Result(0, outputCont, c) |
|||
} |
|||
|
|||
// 获取字典类型列表
|
|||
type DictType struct { |
|||
publicmethod.PagesTurn |
|||
KeyWords string `json:"keywords"` //搜索关键字
|
|||
} |
|||
|
|||
// 输出字典类型列表
|
|||
type SendDictTypeList struct { |
|||
modelAppPlatform.DictType |
|||
CodeKey string `json:"codekey"` //编码
|
|||
} |
|||
|
|||
// 新增字典类别
|
|||
type AddNewDictType struct { |
|||
publicmethod.PublicName |
|||
Remark string `json:"remark"` //备注
|
|||
publicmethod.PublicStatus //1:正常;2:停用
|
|||
} |
|||
|
|||
// 编辑字典类型内容
|
|||
type EditDictTypeInfo struct { |
|||
publicmethod.PublicId |
|||
AddNewDictType |
|||
} |
|||
|
|||
// 删除
|
|||
type DelDictTypeInfo struct { |
|||
Id []string `json:"id"` |
|||
} |
|||
|
|||
// 获取字典内容列表
|
|||
type DictionaryList struct { |
|||
DictType |
|||
CodeType string `json:"codetype"` |
|||
} |
|||
|
|||
// 输出字典内容列表
|
|||
type SendDictionaryList struct { |
|||
modelAppPlatform.Dictionary |
|||
CodeString string `json:"codestring"` |
|||
} |
|||
|
|||
// 新增字典内容数据
|
|||
type AddNewDictionaryCont struct { |
|||
publicmethod.PublicName |
|||
Remark string `json:"remark"` //备注
|
|||
Sort int `json:"sort"` //排序
|
|||
publicmethod.PublicStatus //1:正常;2:停用
|
|||
TypeCode string `json:"typeCode"` //字典类型
|
|||
} |
|||
|
|||
// 编辑字典内容
|
|||
type EditNewDictionaryCont struct { |
|||
Id int `json:"id"` //
|
|||
AddNewDictionaryCont |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
package dict_routers |
|||
|
|||
import ( |
|||
"appPlatform/api/version1" |
|||
|
|||
"github.com/gin-gonic/gin" |
|||
) |
|||
|
|||
// 字典PC端
|
|||
func (a *ApiRouter) RouterGroupPc(router *gin.RouterGroup) { |
|||
apiRouter := router.Group("dict") |
|||
|
|||
var methodBinding = version1.AppApiEntry.DictApi |
|||
{ |
|||
apiRouter.GET("", methodBinding.Index) //入口
|
|||
apiRouter.POST("", methodBinding.Index) //入口
|
|||
apiRouter.POST("dict_type_list", methodBinding.DictTypeList) //字典类型列表
|
|||
apiRouter.POST("add_dict_type", methodBinding.AddDictType) //新增字典类别
|
|||
apiRouter.GET("get_dict_type_cont", methodBinding.GetDictTypeCont) //查看字典类型内容
|
|||
apiRouter.POST("edit_dict_type_cont", methodBinding.EditDictCont) //编辑字典类型内容
|
|||
apiRouter.POST("del_dict_type_cont", methodBinding.DelDictTypeCont) //删除字典类别
|
|||
|
|||
apiRouter.POST("get_dictionary", methodBinding.GetDictionary) //获取字典内容列表
|
|||
apiRouter.POST("add_dictionary_cont", methodBinding.AddDictionaryCont) //新增字典内容
|
|||
apiRouter.GET("get_dictionary_cont", methodBinding.GetDictionaryCont) //查看字典内容
|
|||
apiRouter.POST("edit_dictionary_cont", methodBinding.EditDictionaryCont) //编辑字典内容
|
|||
apiRouter.POST("del_dictionary_cont", methodBinding.DelDictionaryCont) //删除字典内容
|
|||
} |
|||
} |
|||
@ -0,0 +1,4 @@ |
|||
package dict_routers |
|||
|
|||
//菜单路由
|
|||
type ApiRouter struct{} |
|||
@ -0,0 +1,61 @@ |
|||
package modelAppPlatform |
|||
|
|||
import ( |
|||
"appPlatform/overall" |
|||
"strings" |
|||
) |
|||
|
|||
// 字典类型
|
|||
type DictType struct { |
|||
Id int `json:"id" gorm:"primaryKey;column:id;type:int(5) unsigned;not null;comment:Id;index"` |
|||
Name string `json:"name" gorm:"column:name;type:varchar(255) unsigned;default:'';not null;comment:字典类型名称"` |
|||
Code int64 `json:"code" gorm:"column:code;type:bigint(20) unsigned;default:0;not null;comment:字典类型编码"` |
|||
Status int `json:"status" gorm:"column:status;type:int(1) unsigned;default:1;not null;comment:显示状态(1:显示;2:隐藏,3:删除)"` |
|||
Remark string `json:"remark" gorm:"column:remark;type:mediumtext;default:'';comment:字典类型描述"` |
|||
Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` |
|||
} |
|||
|
|||
func (DictType *DictType) TableName() string { |
|||
return "dict_type" |
|||
} |
|||
|
|||
// 编辑内容
|
|||
func (cont *DictType) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Updates(saveData).Error |
|||
return |
|||
} |
|||
|
|||
// 获取内容
|
|||
func (cont *DictType) GetCont(whereMap interface{}, field ...string) (err error) { |
|||
gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
gormDb = gormDb.Where(whereMap) |
|||
err = gormDb.First(&cont).Error |
|||
return |
|||
} |
|||
|
|||
// 根据条件获取总数
|
|||
func (cont *DictType) CountCont(whereMap interface{}) (countId int64) { |
|||
overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Count(&countId) |
|||
return |
|||
} |
|||
|
|||
// 读取全部信息
|
|||
func (cont *DictType) ContMap(whereMap interface{}, field ...string) (countAry []DictType, err error) { |
|||
gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
err = gormDb.Where(whereMap).Find(&countAry).Error |
|||
return |
|||
} |
|||
|
|||
// 删除内容
|
|||
func (cont *DictType) DelCont(whereMap interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_AppPlatform.Where(whereMap).Delete(&cont).Error |
|||
return |
|||
} |
|||
@ -0,0 +1,63 @@ |
|||
package modelAppPlatform |
|||
|
|||
import ( |
|||
"appPlatform/overall" |
|||
"strings" |
|||
) |
|||
|
|||
// 字典内容
|
|||
type Dictionary struct { |
|||
Id int `json:"id" gorm:"primaryKey;column:id;type:int(5) unsigned;not null;comment:Id;index"` |
|||
Name string `json:"name" gorm:"column:name;type:varchar(255) unsigned;default:'';not null;comment:字典内容名称"` |
|||
TypeCode int64 `json:"typeCode" gorm:"column:typeCode;type:bigint(20) unsigned;default:0;not null;comment:字典类型编码"` |
|||
Code int64 `json:"code" gorm:"column:code;type:bigint(20) unsigned;default:0;not null;comment:字典内编码"` |
|||
Sort int `json:"sort" gorm:"column:sort;type:int(1) unsigned;default:50;not null;comment:排序(数字越小排名越靠前))"` |
|||
Status int `json:"status" gorm:"column:status;type:int(1) unsigned;default:1;not null;comment:显示状态(1:显示;2:隐藏,3:删除)"` |
|||
Remark string `json:"remark" gorm:"column:remark;type:mediumtext;default:'';comment:字典内描述"` |
|||
Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` |
|||
} |
|||
|
|||
func (Dictionary *Dictionary) TableName() string { |
|||
return "dictionary" |
|||
} |
|||
|
|||
// 编辑内容
|
|||
func (cont *Dictionary) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Updates(saveData).Error |
|||
return |
|||
} |
|||
|
|||
// 获取内容
|
|||
func (cont *Dictionary) GetCont(whereMap interface{}, field ...string) (err error) { |
|||
gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
gormDb = gormDb.Where(whereMap) |
|||
err = gormDb.First(&cont).Error |
|||
return |
|||
} |
|||
|
|||
// 根据条件获取总数
|
|||
func (cont *Dictionary) CountCont(whereMap interface{}) (countId int64) { |
|||
overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Count(&countId) |
|||
return |
|||
} |
|||
|
|||
// 读取全部信息
|
|||
func (cont *Dictionary) ContMap(whereMap interface{}, field ...string) (countAry []Dictionary, err error) { |
|||
gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
err = gormDb.Where(whereMap).Find(&countAry).Error |
|||
return |
|||
} |
|||
|
|||
// 删除内容
|
|||
func (cont *Dictionary) DelCont(whereMap interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_AppPlatform.Where(whereMap).Delete(&cont).Error |
|||
return |
|||
} |
|||
Loading…
Reference in new issue