|
1 | 1 | package system |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "strconv" |
| 5 | + |
4 | 6 | "github.com/flipped-aurora/gin-vue-admin/server/global" |
5 | 7 | "github.com/flipped-aurora/gin-vue-admin/server/model/common/response" |
6 | 8 | "github.com/flipped-aurora/gin-vue-admin/server/model/system" |
@@ -146,3 +148,120 @@ func (s *DictionaryDetailApi) GetSysDictionaryDetailList(c *gin.Context) { |
146 | 148 | PageSize: pageInfo.PageSize, |
147 | 149 | }, "获取成功", c) |
148 | 150 | } |
| 151 | + |
| 152 | +// GetDictionaryTreeList |
| 153 | +// @Tags SysDictionaryDetail |
| 154 | +// @Summary 获取字典详情树形结构 |
| 155 | +// @Security ApiKeyAuth |
| 156 | +// @accept application/json |
| 157 | +// @Produce application/json |
| 158 | +// @Param sysDictionaryID query int true "字典ID" |
| 159 | +// @Success 200 {object} response.Response{data=[]system.SysDictionaryDetail,msg=string} "获取字典详情树形结构" |
| 160 | +// @Router /sysDictionaryDetail/getDictionaryTreeList [get] |
| 161 | +func (s *DictionaryDetailApi) GetDictionaryTreeList(c *gin.Context) { |
| 162 | + sysDictionaryID := c.Query("sysDictionaryID") |
| 163 | + if sysDictionaryID == "" { |
| 164 | + response.FailWithMessage("字典ID不能为空", c) |
| 165 | + return |
| 166 | + } |
| 167 | + |
| 168 | + var id uint |
| 169 | + if idUint64, err := strconv.ParseUint(sysDictionaryID, 10, 32); err != nil { |
| 170 | + response.FailWithMessage("字典ID格式错误", c) |
| 171 | + return |
| 172 | + } else { |
| 173 | + id = uint(idUint64) |
| 174 | + } |
| 175 | + |
| 176 | + list, err := dictionaryDetailService.GetDictionaryTreeList(id) |
| 177 | + if err != nil { |
| 178 | + global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| 179 | + response.FailWithMessage("获取失败", c) |
| 180 | + return |
| 181 | + } |
| 182 | + response.OkWithDetailed(gin.H{"list": list}, "获取成功", c) |
| 183 | +} |
| 184 | + |
| 185 | +// GetDictionaryTreeListByType |
| 186 | +// @Tags SysDictionaryDetail |
| 187 | +// @Summary 根据字典类型获取字典详情树形结构 |
| 188 | +// @Security ApiKeyAuth |
| 189 | +// @accept application/json |
| 190 | +// @Produce application/json |
| 191 | +// @Param type query string true "字典类型" |
| 192 | +// @Success 200 {object} response.Response{data=[]system.SysDictionaryDetail,msg=string} "获取字典详情树形结构" |
| 193 | +// @Router /sysDictionaryDetail/getDictionaryTreeListByType [get] |
| 194 | +func (s *DictionaryDetailApi) GetDictionaryTreeListByType(c *gin.Context) { |
| 195 | + dictType := c.Query("type") |
| 196 | + if dictType == "" { |
| 197 | + response.FailWithMessage("字典类型不能为空", c) |
| 198 | + return |
| 199 | + } |
| 200 | + |
| 201 | + list, err := dictionaryDetailService.GetDictionaryTreeListByType(dictType) |
| 202 | + if err != nil { |
| 203 | + global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| 204 | + response.FailWithMessage("获取失败", c) |
| 205 | + return |
| 206 | + } |
| 207 | + response.OkWithDetailed(gin.H{"list": list}, "获取成功", c) |
| 208 | +} |
| 209 | + |
| 210 | +// GetDictionaryDetailsByParent |
| 211 | +// @Tags SysDictionaryDetail |
| 212 | +// @Summary 根据父级ID获取字典详情 |
| 213 | +// @Security ApiKeyAuth |
| 214 | +// @accept application/json |
| 215 | +// @Produce application/json |
| 216 | +// @Param data query request.GetDictionaryDetailsByParentRequest true "查询参数" |
| 217 | +// @Success 200 {object} response.Response{data=[]system.SysDictionaryDetail,msg=string} "获取字典详情列表" |
| 218 | +// @Router /sysDictionaryDetail/getDictionaryDetailsByParent [get] |
| 219 | +func (s *DictionaryDetailApi) GetDictionaryDetailsByParent(c *gin.Context) { |
| 220 | + var req request.GetDictionaryDetailsByParentRequest |
| 221 | + err := c.ShouldBindQuery(&req) |
| 222 | + if err != nil { |
| 223 | + response.FailWithMessage(err.Error(), c) |
| 224 | + return |
| 225 | + } |
| 226 | + |
| 227 | + list, err := dictionaryDetailService.GetDictionaryDetailsByParent(req) |
| 228 | + if err != nil { |
| 229 | + global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| 230 | + response.FailWithMessage("获取失败", c) |
| 231 | + return |
| 232 | + } |
| 233 | + response.OkWithDetailed(gin.H{"list": list}, "获取成功", c) |
| 234 | +} |
| 235 | + |
| 236 | +// GetDictionaryPath |
| 237 | +// @Tags SysDictionaryDetail |
| 238 | +// @Summary 获取字典详情的完整路径 |
| 239 | +// @Security ApiKeyAuth |
| 240 | +// @accept application/json |
| 241 | +// @Produce application/json |
| 242 | +// @Param id query uint true "字典详情ID" |
| 243 | +// @Success 200 {object} response.Response{data=[]system.SysDictionaryDetail,msg=string} "获取字典详情路径" |
| 244 | +// @Router /sysDictionaryDetail/getDictionaryPath [get] |
| 245 | +func (s *DictionaryDetailApi) GetDictionaryPath(c *gin.Context) { |
| 246 | + idStr := c.Query("id") |
| 247 | + if idStr == "" { |
| 248 | + response.FailWithMessage("字典详情ID不能为空", c) |
| 249 | + return |
| 250 | + } |
| 251 | + |
| 252 | + var id uint |
| 253 | + if idUint64, err := strconv.ParseUint(idStr, 10, 32); err != nil { |
| 254 | + response.FailWithMessage("字典详情ID格式错误", c) |
| 255 | + return |
| 256 | + } else { |
| 257 | + id = uint(idUint64) |
| 258 | + } |
| 259 | + |
| 260 | + path, err := dictionaryDetailService.GetDictionaryPath(id) |
| 261 | + if err != nil { |
| 262 | + global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| 263 | + response.FailWithMessage("获取失败", c) |
| 264 | + return |
| 265 | + } |
| 266 | + response.OkWithDetailed(gin.H{"path": path}, "获取成功", c) |
| 267 | +} |
0 commit comments