|
@@ -4,6 +4,7 @@ import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin"
|
|
"iot_manager_service/app/device/model"
|
|
"iot_manager_service/app/device/model"
|
|
"iot_manager_service/app/device/service"
|
|
"iot_manager_service/app/device/service"
|
|
|
|
+ "iot_manager_service/app/middleware"
|
|
"iot_manager_service/util"
|
|
"iot_manager_service/util"
|
|
"net/http"
|
|
"net/http"
|
|
"strconv"
|
|
"strconv"
|
|
@@ -33,47 +34,70 @@ type utilCtl struct{}
|
|
func (c *utilCtl) GetModelList(ctx *gin.Context) {
|
|
func (c *utilCtl) GetModelList(ctx *gin.Context) {
|
|
t := ctx.Query("type")
|
|
t := ctx.Query("type")
|
|
d := ctx.Query("deviceType")
|
|
d := ctx.Query("deviceType")
|
|
|
|
+ id := ctx.Query("id")
|
|
|
|
+ pid := ctx.Query("pid")
|
|
modeType, err := strconv.Atoi(t)
|
|
modeType, err := strconv.Atoi(t)
|
|
if err != nil || modeType < 1 || modeType > 3 {
|
|
if err != nil || modeType < 1 || modeType > 3 {
|
|
ctx.JSON(http.StatusOK, util.ParamsInvalidResponse("type invalid", nil))
|
|
ctx.JSON(http.StatusOK, util.ParamsInvalidResponse("type invalid", nil))
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+ modeType++ //前端传入的1和2,实际是2和3
|
|
|
|
+
|
|
deviceType, err := strconv.Atoi(d)
|
|
deviceType, err := strconv.Atoi(d)
|
|
if err != nil {
|
|
if err != nil {
|
|
ctx.JSON(http.StatusOK, util.ParamsInvalidResponse("deviceType invalid", nil))
|
|
ctx.JSON(http.StatusOK, util.ParamsInvalidResponse("deviceType invalid", nil))
|
|
return
|
|
return
|
|
}
|
|
}
|
|
-
|
|
|
|
- vendor, err := service.UtilService.GetDeviceVendor(modeType, deviceType)
|
|
|
|
- if err != nil {
|
|
|
|
- ctx.JSON(http.StatusOK, util.FailResponse(err.Error(), nil))
|
|
|
|
- return
|
|
|
|
|
|
+ parentId := -1
|
|
|
|
+ if id != "" {
|
|
|
|
+ parentId, _ = strconv.Atoi(id)
|
|
|
|
+ } else if pid != "" {
|
|
|
|
+ parentId, _ = strconv.Atoi(pid)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ value, _ := ctx.Get(middleware.Authorization)
|
|
|
|
+ claims := value.(*middleware.Claims)
|
|
|
|
+
|
|
var result []model.VendorDetail
|
|
var result []model.VendorDetail
|
|
if modeType == model.TypeVendor {
|
|
if modeType == model.TypeVendor {
|
|
- result = append(result, model.VendorDetail{
|
|
|
|
- Id: vendor.ID,
|
|
|
|
- ParentId: vendor.ParentId,
|
|
|
|
- Vendor: vendor.VendorValue,
|
|
|
|
- Brand: "",
|
|
|
|
- Model: "",
|
|
|
|
- })
|
|
|
|
|
|
+ vendors, err := service.UtilService.GetDeviceVendor(claims.TenantId, deviceType)
|
|
|
|
+ if err != nil {
|
|
|
|
+ ctx.JSON(http.StatusOK, util.FailResponse(err.Error(), nil))
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ for _, vendor := range vendors {
|
|
|
|
+ result = append(result, model.VendorDetail{
|
|
|
|
+ Id: vendor.ID,
|
|
|
|
+ ParentId: vendor.ParentId,
|
|
|
|
+ Vendor: vendor.VendorValue,
|
|
|
|
+ })
|
|
|
|
+ }
|
|
} else if modeType == model.TypeBrand {
|
|
} else if modeType == model.TypeBrand {
|
|
- result = append(result, model.VendorDetail{
|
|
|
|
- Id: vendor.ID,
|
|
|
|
- ParentId: vendor.ParentId,
|
|
|
|
- Vendor: "",
|
|
|
|
- Brand: vendor.VendorValue,
|
|
|
|
- Model: "",
|
|
|
|
- })
|
|
|
|
|
|
+ vendors, err := service.UtilService.GetDeviceBrand(claims.TenantId, deviceType)
|
|
|
|
+ if err != nil {
|
|
|
|
+ ctx.JSON(http.StatusOK, util.FailResponse(err.Error(), nil))
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ for _, vendor := range vendors {
|
|
|
|
+ result = append(result, model.VendorDetail{
|
|
|
|
+ Id: vendor.ID,
|
|
|
|
+ ParentId: vendor.ParentId,
|
|
|
|
+ Brand: vendor.VendorValue,
|
|
|
|
+ })
|
|
|
|
+ }
|
|
} else if modeType == model.TypeModel {
|
|
} else if modeType == model.TypeModel {
|
|
- result = append(result, model.VendorDetail{
|
|
|
|
- Id: vendor.ID,
|
|
|
|
- ParentId: vendor.ParentId,
|
|
|
|
- Vendor: "",
|
|
|
|
- Brand: "",
|
|
|
|
- Model: vendor.VendorValue,
|
|
|
|
- })
|
|
|
|
|
|
+ vendors, err := service.UtilService.GetDeviceModel(claims.TenantId, deviceType, parentId)
|
|
|
|
+ if err != nil {
|
|
|
|
+ ctx.JSON(http.StatusOK, util.FailResponse(err.Error(), nil))
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ for _, vendor := range vendors {
|
|
|
|
+ result = append(result, model.VendorDetail{
|
|
|
|
+ Id: vendor.ID,
|
|
|
|
+ ParentId: vendor.ParentId,
|
|
|
|
+ Model: vendor.VendorValue,
|
|
|
|
+ })
|
|
|
|
+ }
|
|
}
|
|
}
|
|
ctx.JSON(http.StatusOK, util.SuccessResponse("", result))
|
|
ctx.JSON(http.StatusOK, util.SuccessResponse("", result))
|
|
}
|
|
}
|