瀏覽代碼

厂家管理

sixian 2 年之前
父節點
當前提交
b3826a0547

+ 107 - 0
app/device/controller/utilController.go

@@ -7,6 +7,7 @@ import (
 	"iot_manager_service/app/middleware"
 	"iot_manager_service/util/common"
 	"net/http"
+	"sort"
 	"strconv"
 )
 
@@ -110,3 +111,109 @@ func (c *utilCtl) GetTenantCode(ctx *gin.Context) {
 	code.CityCode = ctx.Query("type") + code.CityCode
 	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, code))
 }
+
+type vendorList struct {
+	Records          []vendorListNew `json:"records"`
+	Total            int             `json:"total"`
+	Size             int             `json:"size"`
+	Current          int             `json:"current"`
+	Orders           []interface{}   `json:"orders"`
+	OptimizeCountSQL bool            `json:"optimizeCountSql"`
+	HitCount         bool            `json:"hitCount"`
+	SearchCount      bool            `json:"searchCount"`
+	Pages            int             `json:"pages"`
+}
+type vendorListNew struct {
+	ID         int    `json:"id"`
+	Vender     string `json:"vender"`
+	Brand      string `json:"brand"`
+	Model      string `json:"model"`
+	Pid        int
+	DeviceType int `json:"deviceType"`
+}
+
+func (c *utilCtl) GetVenderList(ctx *gin.Context) {
+	var result vendorList
+	deviceType := ctx.Query("deviceType")
+	if deviceType == "" {
+		deviceType = "-1"
+	}
+	venderValue := ctx.Query("venderValue")
+	current := ctx.Query("current")
+	size := ctx.Query("size")
+	offset, _ := strconv.Atoi(current)
+	limit, _ := strconv.Atoi(size)
+	if offset == 0 {
+		offset = 1
+		limit = 10
+	}
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+	deviceTypeInt, _ := strconv.Atoi(deviceType)
+	vendors, _, err := service.UtilService.GetDeviceVendorList(claims.TenantId, venderValue, deviceTypeInt, offset, limit)
+	vendorsMap := make(map[int]vendorListNew)
+	vendorListNews1 := make(map[int]vendorListNew)
+	vendorListNews2 := make(map[int]vendorListNew)
+	vendorListNews3 := make(map[int]vendorListNew)
+	for _, vendor := range vendors {
+		vendorsMap[vendor.ID] = vendorListNew{
+			ID:         vendor.ID,
+			Vender:     vendor.VendorValue,
+			DeviceType: vendor.DeviceType,
+			Pid:        vendor.ParentId,
+		}
+		if vendor.VendorType == 3 {
+			vendorListNews3[vendor.ID] = vendorsMap[vendor.ID]
+		}
+		if vendor.VendorType == 2 {
+			vendorListNews2[vendor.ID] = vendorsMap[vendor.ID]
+		}
+		if vendor.VendorType == 1 {
+			vendorListNews1[vendor.ID] = vendorsMap[vendor.ID]
+		}
+	}
+	var vendorListNews []vendorListNew
+	for _, listNew := range vendorListNews3 {
+		vendorListNews = append(vendorListNews, vendorListNew{
+			ID:         listNew.ID,
+			Vender:     vendorListNews1[vendorListNews2[listNew.Pid].Pid].Vender,
+			Brand:      vendorListNews2[listNew.Pid].Vender,
+			Model:      listNew.Vender,
+			DeviceType: listNew.DeviceType,
+			Pid:        listNew.Pid,
+		})
+	}
+	sort.Slice(vendorListNews, func(i, j int) bool {
+		return vendorListNews[i].ID > vendorListNews[j].ID
+	})
+
+	if err != nil {
+		ctx.JSON(http.StatusOK, common.FailResponse(err.Error(), nil))
+		return
+	}
+	result.Records = vendorListNews
+	result.Total = len(vendorListNews)
+	ctx.JSON(http.StatusOK, common.SuccessResponse("", result))
+}
+
+func (c *utilCtl) GetVenderDetail(ctx *gin.Context) {
+	//idStr := ctx.Query("id")
+	//var vendorListNew vendorListNew
+	//id, _ := strconv.Atoi(idStr)
+	ctx.JSON(http.StatusOK, common.SuccessResponse("", nil))
+}
+
+func (c *utilCtl) GetVenderRemove(ctx *gin.Context) {
+	idStr := ctx.Query("id")
+	id, _ := strconv.Atoi(idStr)
+	err := service.UtilService.GetRemoveVendor(id)
+	if err != nil {
+		ctx.JSON(http.StatusOK, common.FailResponse(err.Error(), nil))
+		return
+	}
+	ctx.JSON(http.StatusOK, common.SuccessResponse("", nil))
+}
+
+func (c *utilCtl) GetVenderSubmit(ctx *gin.Context) {
+	ctx.JSON(http.StatusOK, common.SuccessResponse("", nil))
+}

+ 20 - 0
app/device/dao/venderDao.go

@@ -52,3 +52,23 @@ func (c *DeviceVendor) GetModel() ([]DeviceVendor, error) {
 	}
 
 }
+
+func (c DeviceVendor) GetDeviceVendors(offset, limit int) ([]DeviceVendor, int64, error) {
+	var devices []DeviceVendor
+	var count int64
+	db := Db.Debug().Model(&c).Where("is_deleted=0")
+	if c.VendorValue != "" {
+		db.Where("vendor_value like ? ", "%"+c.VendorValue+"%")
+	}
+
+	if c.DeviceType >= 0 {
+		db.Where("device_type=? ", c.DeviceType)
+	}
+	db.Count(&count)
+	err := db.Order("id desc").Find(&devices).Error
+	return devices, count, err
+}
+
+func (c DeviceVendor) Remove() error {
+	return Db.Debug().Model(&c).Where("id=?", c.ID).Update("is_delete", 1).Error
+}

+ 16 - 0
app/device/service/utilService.go

@@ -59,3 +59,19 @@ func (s *utilService) GetTenantCode(tenantId string) (*dao.TenantCode, error) {
 	}
 	return &tenantCode, nil
 }
+
+func (s *utilService) GetDeviceVendorList(tenantId string, venderValue string, deviceType, offset, limit int) ([]dao.DeviceVendor, int64, error) {
+	device := dao.DeviceVendor{
+		TenantId:    tenantId,
+		VendorValue: venderValue,
+		DeviceType:  deviceType,
+	}
+	return device.GetDeviceVendors(offset, limit)
+}
+
+func (s *utilService) GetRemoveVendor(id int) error {
+	device := dao.DeviceVendor{
+		ID: id,
+	}
+	return device.Remove()
+}

+ 1 - 1
app/operation/service/capturePeriodsService.go

@@ -45,7 +45,7 @@ func (s capturePeriodsService) GetPeriodsList(tenantId string, req model.Request
 		if ok {
 			datas[(hour)] += datum.Total
 		} else {
-			datas[(hour)] = 0
+			datas[(hour)] = datum.Total
 		}
 	}
 	var list []model.ResponseCapturePeriods

+ 4 - 0
router/router.go

@@ -40,6 +40,10 @@ func InitRouter(engine *gin.Engine) {
 	{
 		vendor.GET("/getModelList", device.Util.GetModelList)
 		vendor.GET("/getTypeList", device.Util.GetModelList)
+		vendor.GET("/list", device.Util.GetVenderList)
+		vendor.GET("/detail", device.Util.GetVenderDetail)
+		vendor.GET("/remove", device.Util.GetVenderRemove)
+		vendor.GET("/submit", device.Util.GetVenderSubmit)
 	}
 
 	//公共方法