lanjianrong 4 년 전
부모
커밋
d610b56a47

+ 8 - 0
dao/tree_contract_dao.go

@@ -14,6 +14,7 @@ import (
 
 	"github.com/go-xorm/xorm"
 	"go.mod/models"
+	"go.mod/web/viewmodels"
 )
 
 //数据库操作引擎
@@ -28,6 +29,13 @@ func NewTreeContractDao(engine *xorm.Engine) *TreeContractDao {
 	}
 }
 
+func (d *TreeContractDao) GetDetail(id int) *viewmodels.TreeSectionDetail {
+	data := &viewmodels.TreeSectionDetail{}
+	_, _ = d.engine.Sql("select t.name, s.content from cm_tree_contracts as t left join cm_contracts as s on t.contract_id = s.id where t.id = ?", id).Get(data)
+
+	return data
+}
+
 // 获得本项目的合同项目节
 func (d *TreeContractDao) Get(treeId int) *models.CmTreeContracts {
 

+ 5 - 0
services/contract_section_tree_service.go

@@ -26,6 +26,11 @@ func (s *contractService) GetSecionTree() *viewmodels.TreeSectionContract {
 	return Node
 }
 
+func (s *contractService) GetSection(id int) *viewmodels.TreeSectionDetail {
+	data := s.treeContractDao.GetDetail(id)
+	return data
+}
+
 // 获得合同项目节-不包含合同
 func (s *contractService) GetSecionTreeNotContract(bidsectionId int, projectId int, treeType int) *viewmodels.TreeSectionContract {
 	dataList := s.treeContractDao.GetAllNotContract(bidsectionId, projectId, treeType)

+ 1 - 0
services/contract_service.go

@@ -32,6 +32,7 @@ type ContractService interface {
 	// 项目节
 	GetSecionTree() *viewmodels.TreeSectionContract
 	SetSection() error
+	GetSection(id int) *viewmodels.TreeSectionDetail
 	SectionAdd(sectionData *viewmodels.TreeSectionContract) (*models.CmTreeContracts, error)
 	SectionSave(sectionData *viewmodels.TreeSectionContract) error
 	UpdateSerial(sectionData *viewmodels.TreeSectionContract) error

+ 29 - 0
web/api/contract_api.go

@@ -9,6 +9,7 @@ package api
 import (
 	"github.com/kataras/iris/v12"
 	"go.mod/services"
+	"go.mod/web/utils"
 	"go.mod/web/viewmodels"
 )
 
@@ -62,3 +63,31 @@ func (c *ContractApi) GetSectionAll() {
 		"result": sectionTree,
 	})
 }
+
+// @Summary 获得单个项目节详情
+// @Tags 合同管理-项目节
+// @Description 未设置合同项目节 返回项目节模板信息
+// @Accept  json
+// @Produce  json
+// @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,data:viewmodels.TreeSectionContract,msg:错误信息}"
+// @Router /api/section [get]
+func (c *ContractApi) GetSection() {
+
+	sectionData := viewmodels.TreeSectionContract{}
+	err := c.Ctx.ReadForm(&sectionData)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
+		return
+	}
+
+	id, _ := utils.GetDecryptId(sectionData.Id)
+
+	//获得合同项目节
+	sectionTree := c.ServiceContract.GetSection(id)
+
+	c.Ctx.JSON(iris.Map{
+		"code":   0,
+		"msg":    "",
+		"result": sectionTree,
+	})
+}

+ 4 - 1
web/api/login_api.go

@@ -47,10 +47,13 @@ func (c *LoginApi) Post() {
 		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
 		return
 	}
+	result := map[string]interface{}{
+		"token": token,
+	}
 	c.Ctx.JSON(iris.Map{
 		"code":   0,
 		"msg":    "",
-		"result": token,
+		"result": result,
 	})
 }
 

+ 7 - 2
web/utils/utils.go

@@ -12,6 +12,7 @@ import (
 	"strconv"
 	"strings"
 
+	"github.com/iris-contrib/middleware/jwt"
 	"github.com/kataras/iris/v12"
 	"go.mod/comm"
 	"go.mod/conf"
@@ -64,11 +65,15 @@ func GetProjectId(ctx iris.Context) (int, error) {
 // 获得项目账号ID
 func GetProjectAccountId(ctx iris.Context) (int, error) {
 
-	identityIdInt, err := ctx.Values().GetInt("accountId")
+	userInfo := ctx.Values().Get("jwt").(*jwt.Token).Claims.(jwt.MapClaims)
+	accountId := userInfo["identity"].(string)
+
+	uid, err := GetDecryptId(accountId)
+	// identityIdInt, err := ctx.Values().GetInt("accountId")
 	if err != nil {
 		return 0, errors.New("项目账号不存在")
 	}
-	return identityIdInt, nil
+	return uid, nil
 }
 
 // 获得解密后的ID

+ 5 - 0
web/viewmodels/tree_section_contract.go

@@ -43,6 +43,11 @@ type TreeSectionContract struct {
 	IsEnd        bool   `form:"isEnd" json:"isEnd"`
 }
 
+type TreeSectionDetail struct {
+	Name    string `from:"name" json:"name"`
+	Content string `from:"content" json:"content"`
+}
+
 func (l TreeSectionContract) ValidateDepth() error {
 	return validation.ValidateStruct(&l,
 		validation.Field(&l.Id, validation.Required.Error("项目节ID不能为空")),