caipin 4 年之前
父節點
當前提交
815a4df325
共有 5 個文件被更改,包括 49 次插入20 次删除
  1. 12 8
      lib/cld.go
  2. 12 4
      services/backstage_service.go
  3. 3 4
      web/backstage/project_bs.go
  4. 19 4
      web/middleware/accessAuth.go
  5. 3 0
      web/utils/utils.go

+ 12 - 8
lib/cld.go

@@ -78,21 +78,19 @@ func (c *Cld) LoginValid(loginData viewmodels.StaffCld) (*Result, error) {
 }
 
 // 获得cld办事处和员工 列表
-func (c *Cld) GetList(categoryId int) {
+func (c *Cld) GetList(categoryId int) (map[string]interface{}, error) {
 
 	data := url.Values{}
 	parameter := strings.NewReader(data.Encode())
 
 	url := fmt.Sprintf("%s?categoryId=%d", c.CategoryUrl, categoryId)
-	fmt.Println(url)
-	c.cldRequest("GET", url, parameter)
+
+	return c.cldRequest("GET", url, parameter)
 }
 
-func (c *Cld) cldRequest(Method string, url string, parameter *strings.Reader) (*Result, error) {
+func (c *Cld) cldRequest(Method string, url string, parameter *strings.Reader) (map[string]interface{}, error) {
 
 	client := &http.Client{}
-	fmt.Println("====================")
-
 	reqest, err := http.NewRequest(Method, url, parameter)
 	if err != nil {
 		return nil, errors.New("CLD网络出现问题")
@@ -107,6 +105,12 @@ func (c *Cld) cldRequest(Method string, url string, parameter *strings.Reader) (
 		return nil, errors.New("请求CLD发送错误")
 	}
 	body, _ := ioutil.ReadAll(response.Body)
-	fmt.Println(string(body))
-	return nil, nil
+
+	result := make(map[string]interface{})
+	err = json.Unmarshal(body, &result)
+	if err != nil {
+		return nil, errors.New("解析数据错误")
+	}
+
+	return result, nil
 }

+ 12 - 4
services/backstage_service.go

@@ -25,7 +25,7 @@ type BackstageService interface {
 	ValidCldStaff(loginData viewmodels.StaffCld, writer http.ResponseWriter) (*viewmodels.ResultCld, error)
 	ValidRuleProject(ctx iris.Context) (viewmodels.Project, error)
 	ValidRuleProjectAdd(ctx iris.Context) (viewmodels.Project, error)
-	GetCldByCategoryId(categoryId int)
+	GetCldByCategoryId(categoryId int) (map[string]interface{}, error)
 	Out(ctx iris.Context) error
 }
 
@@ -151,8 +151,16 @@ func (s *backstageService) Out(ctx iris.Context) error {
 }
 
 // 获得cld办事处和员工 列表
-func (s *backstageService) GetCldByCategoryId(categoryId int) {
+func (s *backstageService) GetCldByCategoryId(categoryId int) (map[string]interface{}, error) {
 	cld := lib.NewCld()
-	cld.GetList(categoryId)
-	// result, err := cld.GetList(categoryId)
+
+	result, err := cld.GetList(categoryId)
+	if err != nil {
+		return nil, err
+	}
+
+	if result["code"].(float64) != 0 {
+		return nil, errors.New(result["code"].(string))
+	}
+	return result, nil
 }

+ 3 - 4
web/backstage/project_bs.go

@@ -137,16 +137,15 @@ func (c *ProjectBs) GetCld() {
 	}
 
 	// 获得项目信息
-	ProjectData := ""
-	c.ServiceBackstage.GetCldByCategoryId(categoryId)
-	// ProjectData, err := c.ServiceBackstage.GetCld(categoryId)
+	// c.ServiceBackstage.GetCldByCategoryId(categoryId)
+	data, err := c.ServiceBackstage.GetCldByCategoryId(categoryId)
 	if err != nil {
 		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
 		return
 	}
 	c.Ctx.JSON(iris.Map{
 		"code": 0,
-		"data": ProjectData,
+		"data": data,
 		"msg":  "",
 	})
 }

+ 19 - 4
web/middleware/accessAuth.go

@@ -16,8 +16,8 @@ import (
 	"github.com/kataras/iris/v12"
 	"go.mod/dao"
 	"go.mod/datasource"
-	"go.mod/lib"
 	"go.mod/models"
+	"go.mod/web/utils"
 )
 
 // 员工表权限解析
@@ -60,9 +60,24 @@ func AccessAuth(ctx iris.Context) {
 		return
 	}
 
-	// 1-1获得标段ID
-	key := fmt.Sprintf("pm_%d_%d", account.ProjectId, account.Id)
-	bidsectionId := lib.NewRedis().GetBidsectionIdByCache(key)
+	// 1-1获得标段ID --没有标段ID 默认为0
+	bidsectionIdHeader := ctx.GetHeader("bidsectionId")
+	bidsectionId, _ := utils.GetDecryptId(bidsectionIdHeader)
+
+	// if bidsectionIdHeader == "" {
+	// 	ctx.JSON(iris.Map{"code": 2, "msg": "标段解析出错"})
+	// 	return
+	// } else {
+	// 	bidsectionId, err := utils.GetDecryptId(bidsectionIdHeader)
+	// 	if err != nil {
+	// 		ctx.JSON(iris.Map{"code": 2, "msg": "标段解析出错"})
+	// 		return
+	// 	}
+
+	// }
+
+	// key := fmt.Sprintf("pm_%d_%d", account.ProjectId, account.Id)
+	// bidsectionId := lib.NewRedis().GetBidsectionIdByCache(key)
 
 	// 1-2 获得账号权限
 	permissionAccountDao := dao.NewPermissionAccountDao(datasource.InstanceDbMaster())

+ 3 - 0
web/utils/utils.go

@@ -62,6 +62,9 @@ func GetProjectAccountId(ctx iris.Context) (int, error) {
 
 // 获得解密后的ID
 func GetDecryptId(id string) (int, error) {
+	if id == "" {
+		return 0, errors.New("ID 解析错误")
+	}
 	id, err := comm.AesDecrypt(id, conf.SignSecret)
 	if err != nil {
 		return 0, errors.New("ID 解析错误")