caipin 4 years ago
parent
commit
9ed3279aed

+ 33 - 3
comm/functions.go

@@ -44,7 +44,8 @@ func MakeProjectAccountVM(modelsAccount *models.CmProjectAccount) viewmodels.Pro
 	return viewAccountData
 }
 
-func MakeTreeContract(Data []*viewmodels.TreeContract, node *viewmodels.TreeContract) { //参数为父节点,添加父节点的子节点指针切片
+// 创建合同目录树
+func MakeFolderContract(Data []*viewmodels.FolderContract, node *viewmodels.FolderContract) { //参数为父节点,添加父节点的子节点指针切片
 	childs, _ := HaveChildContract(Data, node) //判断节点是否有子节点并返回
 	if childs != nil {
 		// 子节点总数
@@ -59,7 +60,7 @@ func MakeTreeContract(Data []*viewmodels.TreeContract, node *viewmodels.TreeCont
 			_, has := HaveChildContract(Data, v)
 			if has {
 				// 递归添加节点
-				MakeTreeContract(Data, v)
+				MakeFolderContract(Data, v)
 			}
 			// 目录下是否包含标段
 			if v.Isfolder == 0 {
@@ -72,7 +73,36 @@ func MakeTreeContract(Data []*viewmodels.TreeContract, node *viewmodels.TreeCont
 }
 
 // 是否有子树
-func HaveChildContract(Data []*viewmodels.TreeContract, node *viewmodels.TreeContract) (child []*viewmodels.TreeContract, yes bool) {
+func HaveChildContract(Data []*viewmodels.FolderContract, node *viewmodels.FolderContract) (child []*viewmodels.FolderContract, yes bool) {
+	for _, v := range Data {
+		if v.ParentId == node.Id {
+			child = append(child, v)
+		}
+	}
+	if child != nil {
+		yes = true
+	}
+	return
+}
+
+// 创建合同项目节树
+func MakeSectionContract(Data []*viewmodels.TreeSectionContract, node *viewmodels.TreeSectionContract) { //参数为父节点,添加父节点的子节点指针切片
+	childs, _ := HaveChildSectionContract(Data, node) //判断节点是否有子节点并返回
+	if childs != nil {
+		// 往父节点添加子节点
+		node.Children = append(node.Children, childs[0:]...) //添加子节点
+		for _, v := range childs {                           //查询子节点的子节点,并添加到子节点
+			_, has := HaveChildSectionContract(Data, v)
+			if has {
+				// 递归添加节点
+				MakeSectionContract(Data, v)
+			}
+		}
+	}
+}
+
+// 是否有子树
+func HaveChildSectionContract(Data []*viewmodels.TreeSectionContract, node *viewmodels.TreeSectionContract) (child []*viewmodels.TreeSectionContract, yes bool) {
 	for _, v := range Data {
 		if v.ParentId == node.Id {
 			child = append(child, v)

+ 7 - 10
dao/bidsection_dao.go

@@ -8,7 +8,6 @@ package dao
 
 import (
 	"errors"
-	"strconv"
 	"time"
 
 	"github.com/go-xorm/xorm"
@@ -56,25 +55,23 @@ func (d *BidsectionDao) Create(data *models.CmTree) error {
 	}
 
 	// 创建标段
-	bidsection := models.CmBidsection{}
+	bidsection := &models.CmBidsection{}
 	bidsection.ProjectId = data.ProjectId
 	bidsection.Name = data.Name
 	bidsection.CreateTime = time.Now()
 	bidsection.DealTp = "0"
 	bidsection.TotalPrice = "0"
-	id, err := session.Insert(bidsection)
+	_, err = session.Insert(bidsection)
 	if err != nil {
 		session.Rollback()
 		return errors.New("标段创建不正确")
 	}
 	// 创建标段在树结构中的联系
-	idStr := strconv.FormatInt(id, 10)
-	idInt, err := strconv.Atoi(idStr)
-	if err != nil {
-		session.Rollback()
-		return errors.New("创建标段联系出错-db")
-	}
-	data.BidsectionId = idInt
+	data.BidsectionId = bidsection.Id
+	data.ContractsIncome = "0"
+	data.ContractsPaid = "0"
+	data.ContractsPay = "0"
+	data.ContractsReturned = "0"
 	_, err = session.Insert(data)
 	if err != nil {
 		session.Rollback()

+ 58 - 0
dao/tree_contract_dao.go

@@ -0,0 +1,58 @@
+/*
+ * @description: 合同项目节相关数据库操作
+ * @Author: CP
+ * @Date: 2020-11-02 11:37:32
+ * @FilePath: \construction_management\dao\tree_contract_dao.go
+ */
+package dao
+
+import (
+	"github.com/go-xorm/xorm"
+	"go.mod/models"
+)
+
+//数据库操作引擎
+type TreeContractDao struct {
+	engine *xorm.Engine
+}
+
+//获得一个DAO对象
+func NewTreeContractDao(engine *xorm.Engine) *TreeContractDao {
+	return &TreeContractDao{
+		engine: engine,
+	}
+}
+
+// 获得项目下的项目节
+func (d *TreeContractDao) GetAll(projectId int) []models.CmTreeContracts {
+	datalist := make([]models.CmTreeContracts, 0)
+	err := d.engine.
+		Asc("id").
+		Where("project_id=?", projectId).
+		Find(&datalist)
+	if err != nil {
+		return datalist
+	} else {
+		return datalist
+	}
+}
+
+// 获得最后一条项目节
+func (d *TreeContractDao) GetLast(projectId int) *models.CmTreeContracts {
+	data := &models.CmTreeContracts{}
+	_, err := d.engine.
+		Desc("id").
+		Where("project_id=?", projectId).
+		Get(data)
+	if err != nil {
+		data.Id = 0
+		return data
+	}
+	return data
+}
+
+// 插入多条数据
+func (d *TreeContractDao) CreateAll(data []*models.CmTreeContracts) error {
+	_, err := d.engine.Insert(data)
+	return err
+}

+ 124 - 3
services/contract_service.go

@@ -6,35 +6,156 @@
  */
 package services
 
+import (
+	"errors"
+	"log"
+	"strconv"
+	"time"
+
+	"github.com/kataras/iris/v12"
+	"go.mod/comm"
+	"go.mod/conf"
+	"go.mod/dao"
+	"go.mod/datasource"
+	"go.mod/lib"
+	"go.mod/models"
+	"go.mod/web/viewmodels"
+)
+
 //定义项目用户Service接口
 type ContractService interface {
-	// ValidRule(ctx iris.Context) (viewmodels.BidAccount, error)
+	ValidRule(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
 	// Create(viewBidAccount viewmodels.BidAccount, projectId int) error
 	// Delete(viewBidAccount viewmodels.BidAccount, projectId int) error
 	GetAll()
+	GetSeciontTree(projectId int) *viewmodels.TreeSectionContract
+	SetSection(templateNumber int, projectIdInt int) error
 }
 
 //返回service操作类
 type contractService struct {
+	treeContractDao *dao.TreeContractDao
 	// dao *dao.ProjectAccountDao
 	// projectDao        *dao.ProjectDao
 	// bidsectionDao     *dao.BidsectionDao
-	// treeDao           *dao.TreeDao
+
 	// bidAccountDao     *dao.BidAccountDao
 }
 
 //创建项目用户service
 func NewContractService() ContractService {
 	return &contractService{
+		treeContractDao: dao.NewTreeContractDao(datasource.InstanceDbMaster()),
 		// projectAccountDao: dao.NewProjectAccountDao(datasource.InstanceDbMaster()),
 		// projectDao:        dao.NewProjectDao(datasource.InstanceDbMaster()),
 		// bidsectionDao:     dao.NewBidsectionDao(datasource.InstanceDbMaster()),
-		// treeDao:           dao.NewTreeDao(datasource.InstanceDbMaster()),
+
 		// bidAccountDao:     dao.NewBidAccountDao(datasource.InstanceDbMaster()),
 	}
 }
 
+// 文件夹规则验证
+func (s *contractService) ValidRule(ctx iris.Context) (*viewmodels.TreeSectionContract, error) {
+	treeSectionVaild := &viewmodels.TreeSectionContract{}
+	err := ctx.ReadJSON(treeSectionVaild)
+	if err != nil {
+		log.Println("folder-ValidRule-ReadForm转换异常, error=", err)
+		return treeSectionVaild, err
+	}
+
+	err = treeSectionVaild.Validate()
+	if err != nil {
+		log.Println("文件夹验证, error=", err)
+		return treeSectionVaild, err
+	}
+
+	return treeSectionVaild, nil
+}
+
 // 获得合同标段内容
 func (s *contractService) GetAll() {
 
 }
+
+// 获得合同项目节
+func (s *contractService) GetSeciontTree(projectId int) *viewmodels.TreeSectionContract {
+	sectionList := make([]*viewmodels.TreeSectionContract, 0)
+	dataList := s.treeContractDao.GetAll(projectId)
+	// 生成根
+	sectionRoot := &viewmodels.TreeSectionContract{}
+	id, _ := comm.AesEncrypt(strconv.Itoa(0), conf.SignSecret)
+	parentId, _ := comm.AesEncrypt(strconv.Itoa(-1), conf.SignSecret)
+	sectionRoot.Id = id
+	sectionRoot.Name = "root"
+	sectionRoot.ParentId = parentId
+	sectionList = append(sectionList, sectionRoot)
+	for _, data := range dataList {
+		section := &viewmodels.TreeSectionContract{}
+		id, _ := comm.AesEncrypt(strconv.Itoa(data.TreeId), conf.SignSecret)
+		parentId, _ := comm.AesEncrypt(strconv.Itoa(data.ParentId), conf.SignSecret)
+		projectId, _ := comm.AesEncrypt(strconv.Itoa(data.ProjectId), conf.SignSecret)
+		contractId, _ := comm.AesEncrypt(strconv.Itoa(data.ContractId), conf.SignSecret)
+		section.Id = id
+		section.Name = data.Name
+		section.ParentId = parentId
+		section.Depth = data.Depth + 1
+		section.Serial = data.Serial
+		section.ProjectId = projectId
+		section.ContractId = contractId
+
+		section.Name = data.Name
+		section.ContractCode = data.ContractCode
+		section.ContractPrice = data.ContractPrice
+		section.ContractReturned = data.ContractReturned
+		section.ContractsPaid = data.ContractsPaid
+		section.ContractStatus = data.ContractStatus
+
+		section.CreateTime = data.CreateTime.Format(conf.SysTimeform)
+		sectionList = append(sectionList, section)
+	}
+
+	Node := sectionRoot //父节点
+	comm.MakeSectionContract(sectionList, Node)
+	return Node
+}
+
+// 设置合同项目节初始数据-根据模板导入
+func (s *contractService) SetSection(templateNumber int, projectIdInt int) error {
+	// 获得模板数据
+	templateTree := make([]*lib.ItemSectionTemplateTree, 0)
+	if templateNumber == 1 {
+		templateTree = lib.NewItemSectionData().TemplateList1
+	} else if templateNumber == 2 {
+		templateTree = lib.NewItemSectionData().TemplateList2
+	} else {
+		return errors.New("找不到合同项目节模板")
+	}
+
+	// 1.组合数据-写入库中
+	sectionTreeList := make([]*models.CmTreeContracts, 0)
+	for _, item := range templateTree {
+		section := &models.CmTreeContracts{}
+		section.TreeId = item.Id
+		section.ParentId = item.ParentId
+		section.ProjectId = projectIdInt
+		section.Name = item.Name
+		section.Depth = item.Depth
+		section.Serial = item.Serial
+		section.Attribution = item.Attribution
+
+		section.CreateTime = time.Now()
+
+		section.ContractPrice = "0"
+		section.ContractReturned = "0"
+		section.ContractsPaid = "0"
+
+		sectionTreeList = append(sectionTreeList, section)
+	}
+
+	err := s.treeContractDao.CreateAll(sectionTreeList)
+	if err != nil {
+		log.Println("设置合同项目节模板错误 err=", err)
+		return errors.New("设置合同项目节模板错误")
+	}
+	return nil
+}

+ 34 - 22
services/tree_service.go

@@ -29,7 +29,7 @@ type TreeService interface {
 	ValidRule(ctx iris.Context) (viewmodels.Tree, error)
 	Create(data viewmodels.Tree) error
 	GetAllProject(projectId int) *viewmodels.Tree
-	GetAllContract(projectId int) *viewmodels.TreeContract
+	GetAllContract(projectId int) *viewmodels.FolderContract
 	Rename(treevm viewmodels.Tree, projectId int) error
 	GetFolderAndBid(id int, projectId int) ([]models.CmTree, error)
 	DeleteFolderAndBid(id int, projectId int) error
@@ -69,27 +69,30 @@ func (s *treeService) ValidRule(ctx iris.Context) (viewmodels.Tree, error) {
 // 获得项目下 相关文件夹-整个树结构
 func (s *treeService) GetAllProject(projectId int) *viewmodels.Tree {
 	datalist := s.dao.GetAllTree(projectId)
-	folderlist := make([]viewmodels.Tree, 0)
+	folderlist := make([]*viewmodels.Tree, 0)
 	// 生成根
-	folder := viewmodels.Tree{}
+	folder := &viewmodels.Tree{}
 	id, _ := comm.AesEncrypt(strconv.Itoa(0), conf.SignSecret)
 	parentId, _ := comm.AesEncrypt(strconv.Itoa(-1), conf.SignSecret)
 	folder.Id = id
 	folder.Name = "root"
+	folder.Isfolder = 1
 	folder.ParentId = parentId
 	folderlist = append(folderlist, folder)
 	// 加入数据
 	for _, data := range datalist {
-		folder := viewmodels.Tree{}
+		folder := &viewmodels.Tree{}
 		//folder.Id = comm.Encrypt([]byte(conf.SignSecret), []byte(strconv.Itoa(data.Id)))
 		id, _ := comm.AesEncrypt(strconv.Itoa(data.Id), conf.SignSecret)
 		parentId, _ := comm.AesEncrypt(strconv.Itoa(data.ParentId), conf.SignSecret)
 		projectId, _ := comm.AesEncrypt(strconv.Itoa(data.ProjectId), conf.SignSecret)
 		serial, _ := comm.AesEncrypt(strconv.Itoa(data.Serial), conf.SignSecret)
+		bidsectionId, _ := comm.AesEncrypt(strconv.Itoa(data.BidsectionId), conf.SignSecret)
 		folder.Id = id
 		folder.Name = data.Name
 		folder.ParentId = parentId
 		folder.ProjectId = projectId
+		folder.BidsectionId = bidsectionId
 		folder.Depth = data.Depth + 1
 		folder.Serial = serial
 		folder.Ancounts = data.Ancounts
@@ -104,42 +107,45 @@ func (s *treeService) GetAllProject(projectId int) *viewmodels.Tree {
 
 	//fmt.Println(folderlist)
 
-	var data []*viewmodels.Tree
-	data = make([]*viewmodels.Tree, 0)
-	for i, _ := range folderlist {
-		var a *viewmodels.Tree
-		a = &folderlist[i]
-		data = append(data, a)
-	}
+	//var data []*viewmodels.Tree
+	// data := make([]*viewmodels.Tree, 0)
+	// for i, _ := range folderlist {
+	// 	var a *viewmodels.Tree
+	// 	a = &folderlist[i]
+	// 	data = append(data, a)
+	// }
 
-	node := &folderlist[0] //父节点
-	maketree(data, node)   //调用生成tree
+	node := folderlist[0]      //父节点
+	maketree(folderlist, node) //调用生成tree
 	//transformjson(node)    //转化为json
 	return node
 }
 
 // 获得合同管理的目录
-func (s *treeService) GetAllContract(projectId int) *viewmodels.TreeContract {
+func (s *treeService) GetAllContract(projectId int) *viewmodels.FolderContract {
 	datalist := s.dao.GetAllTree(projectId)
-	folderlist := make([]viewmodels.TreeContract, 0)
+	folderlist := make([]viewmodels.FolderContract, 0)
 	// 生成根
-	folder := viewmodels.TreeContract{}
+	folder := viewmodels.FolderContract{}
 	id, _ := comm.AesEncrypt(strconv.Itoa(0), conf.SignSecret)
 	parentId, _ := comm.AesEncrypt(strconv.Itoa(-1), conf.SignSecret)
 	folder.Id = id
 	folder.Name = "root"
 	folder.ParentId = parentId
+	folder.Isfolder = 1
 	folderlist = append(folderlist, folder)
 	// 加入数据
 	for _, data := range datalist {
-		folder := viewmodels.TreeContract{}
+		folder := viewmodels.FolderContract{}
 		id, _ := comm.AesEncrypt(strconv.Itoa(data.Id), conf.SignSecret)
 		parentId, _ := comm.AesEncrypt(strconv.Itoa(data.ParentId), conf.SignSecret)
 		projectId, _ := comm.AesEncrypt(strconv.Itoa(data.ProjectId), conf.SignSecret)
+		bidsectionId, _ := comm.AesEncrypt(strconv.Itoa(data.BidsectionId), conf.SignSecret)
 		folder.Id = id
 		folder.Name = data.Name
 		folder.ParentId = parentId
 		folder.ProjectId = projectId
+		folder.BidsectionId = bidsectionId
 		// 合同数据
 		folder.Contracts = data.Contracts
 		folder.ContractsIncome = data.ContractsIncome
@@ -182,16 +188,16 @@ func (s *treeService) GetAllContract(projectId int) *viewmodels.TreeContract {
 
 	//fmt.Println(folderlist)
 
-	var data []*viewmodels.TreeContract
-	data = make([]*viewmodels.TreeContract, 0)
+	var data []*viewmodels.FolderContract
+	data = make([]*viewmodels.FolderContract, 0)
 	for i, _ := range folderlist {
-		var a *viewmodels.TreeContract
+		var a *viewmodels.FolderContract
 		a = &folderlist[i]
 		data = append(data, a)
 	}
 
 	node := &folderlist[0] //父节点
-	comm.MakeTreeContract(data, node)
+	comm.MakeFolderContract(data, node)
 	return node
 }
 
@@ -241,11 +247,12 @@ func (s *treeService) Create(data viewmodels.Tree) error {
 			return errors.New("上级目录不正确")
 		}
 		attribution := fmt.Sprintf("%s%d-", treeNode.Attribution, treeNode.Serial)
-		datalist := s.dao.GetALLDepthByAttribution(data.Depth, ProjectId, attribution)
+		datalist := s.dao.GetALLDepthByAttribution(depth, ProjectId, attribution)
 		maxIndex := len(datalist)
 		if maxIndex != 0 {
 			serial = datalist[maxIndex-1].Serial + 1
 		}
+
 		// 设置归属
 		folder.Attribution = attribution //treeNode.Attribution + strconv.Itoa(treeNode.Serial) + "-"
 		folder.ParentId = IdInt
@@ -257,8 +264,13 @@ func (s *treeService) Create(data viewmodels.Tree) error {
 	folder.Isfolder = 1
 	folder.CreateTime = time.Now()
 	folder.UpdateTime = time.Now()
+	folder.ContractsIncome = "0"
+	folder.ContractsPaid = "0"
+	folder.ContractsPay = "0"
+	folder.ContractsReturned = "0"
 	err = s.dao.Create(&folder)
 	if err != nil {
+		log.Println("添加目录出错, error=", err)
 		return errors.New("添加目录出错")
 	}
 	return nil

+ 108 - 9
web/api/contract_api.go

@@ -7,16 +7,21 @@
 package api
 
 import (
+	"fmt"
+
 	"github.com/kataras/iris/v12"
+	"go.mod/lib"
 	"go.mod/services"
 	"go.mod/web/utils"
+	"go.mod/web/viewmodels"
 )
 
 type ContractApi struct {
 	//框架-web应用上下文环境
 	Ctx iris.Context
 	// // 需要用的service
-	ServiceTree services.TreeService
+	ServiceTree     services.TreeService
+	ServiceContract services.ContractService
 	// ServiceLogin          services.LoginService
 	// ServiceProject        services.ProjectService
 }
@@ -27,16 +32,13 @@ type ContractApi struct {
 // @Accept  json
 // @Produce  json
 // @Security ApiKeyAuth
-// @Success 200 {object} viewmodels.TreeContract "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
+// @Success 200 {object} viewmodels.FolderContract "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
 // @Router /api/contract [get]
 func (c *ContractApi) Get() {
 	// 获得项目ID
 	projectIdInt, err := utils.GetProjectId(c.Ctx)
 	if err != nil {
-		c.Ctx.JSON(iris.Map{
-			"code": -1,
-			"msg":  err,
-		})
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
 		return
 	}
 
@@ -50,10 +52,107 @@ func (c *ContractApi) Get() {
 	})
 }
 
+// @Summary 获得合同信息
+// @Tags 合同管理
+// @Description 未设置合同项目节 返回项目节模板信息
+// @Accept  json
+// @Produce  json
+// @Security ApiKeyAuth
+// @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,data:viewmodels.TreeSectionContract,msg:错误信息}"
+// @Router /api/contract/income [get]
 func (c *ContractApi) GetIncome() {
+
+	// 项目ID
+	projectIdInt, err := utils.GetProjectId(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
+		return
+	}
+
+	//获得合同项目节
+	sectionTree := c.ServiceContract.GetSeciontTree(projectIdInt)
+
 	// 1.未设置了项目节
-	// 返回项目节2个基础模板
+	if len(sectionTree.Children) == 0 {
+		// 返回项目节2个基础模板
+		templateTree1 := lib.NewItemSection().TemplateTree1
+		templateTree2 := lib.NewItemSection().TemplateTree2
 
-	// 2.已设置项目节
-	// 返回项目相关所有信息
+		c.Ctx.JSON(iris.Map{
+			"code":             0,
+			"msg":              "",
+			"isTemplate":       1,
+			"sectionTemplate1": templateTree1,
+			"sectionTemplate2": templateTree2,
+		})
+		return
+		//2.项目节已设置
+	} else {
+		// 2.已设置项目节
+		c.Ctx.JSON(iris.Map{
+			"code":        0,
+			"msg":         "",
+			"isTemplate":  0,
+			"sectionTree": sectionTree,
+		})
+		return
+		// 返回项目相关所有信息
+	}
+}
+
+// 升级降级合同项目节
+func (c *ContractApi) PostSectionDepth() {
+
+	// 验证字段
+
+	// 项目ID
+	projectIdInt, err := utils.GetProjectId(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
+		return
+	}
+
+}
+
+// 修改合同好
+func (c *ContractApi) PostSectionSave() {
+
+}
+
+// @Summary 设置合同项目节模板
+// @Tags 合同管理
+// @Description 设置合同项目节模板
+// @Accept  json
+// @Produce  json
+// @Security ApiKeyAuth
+// @Param   templateNumber     body    int     true        "模板号" default(1)
+// @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,data:viewmodels.TreeSectionContract,msg:错误信息}"
+// @Router /api/contract/section/template [post]
+func (c *ContractApi) PostSectionTemplate() {
+
+	// 获得模板号
+	sectionTemplate := &viewmodels.TreeSectionContract{}
+	err := c.Ctx.ReadJSON(sectionTemplate)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
+		return
+	}
+	// 检查模板号
+	if !(sectionTemplate.TemplateNumber == 1 || sectionTemplate.TemplateNumber == 2) {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "模板号出错"})
+		return
+	}
+	// 项目ID
+	projectIdInt, err := utils.GetProjectId(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+
+	err = c.ServiceContract.SetSection(sectionTemplate.TemplateNumber, projectIdInt)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+	c.Ctx.JSON(iris.Map{"code": 0, "msg": "设置成功"})
 }

+ 0 - 1
web/api/login_api.go

@@ -30,7 +30,6 @@ type LoginApi struct {
 // @Param   code     	body    string     true        "项目编号" 	default(234)
 // @Param   account     body    string     true        "项目账号" 	default(caipin)
 // @Param   password     body    string    true        "密码"		default(123456)
-// @Param   X-CSRF-Token      header    string     true        "csrf"
 // @Success 200 {object} viewmodels.ProjectAccount "{code:0成功,data:viewmodels.ProjectAccount,msg:}"
 // @Failure 400 {string} string	"{code:-1参数类错误,msg:错误信息}"
 // @Router /api/login [post]

+ 1 - 1
web/main.go

@@ -39,7 +39,7 @@ func newApp() *bootstrap.Bootstrapper {
 
 // @securityDefinitions.apikey ApiKeyAuth
 // @in header
-// @name Authorization
+// @name X-CSRF-Token
 
 func main() {
 	// 服务器集群的时候才需要区分这项设置

+ 2 - 0
web/routes/routes.go

@@ -23,6 +23,7 @@ func Configure(b *bootstrap.Bootstrapper) {
 	TreeService := services.NewTreeService()
 	BidsectionService := services.NewBidsectionService()
 	BidAccountService := services.NewBidAccountService()
+	ContractService := services.NewContractService()
 	//CSRF相关
 	b.Use(middleware.SetCsrf)
 
@@ -115,6 +116,7 @@ func Configure(b *bootstrap.Bootstrapper) {
 	// 合同管理
 	apiContract := mvc.New(b.Party("/api/contract"))
 	apiContract.Register(TreeService)
+	apiContract.Register(ContractService)
 	// 中间件
 	apiContract.Router.Use(middleware.SessionsAuth)
 	apiContract.Router.Use(middleware.AccessAuth)

+ 8 - 8
web/viewmodels/tree_contract.go

@@ -2,13 +2,13 @@
  * @description:合同目录视图模型
  * @Author: CP
  * @Date: 2020-10-27 17:07:50
- * @FilePath: \construction_management\web\viewmodels\tree_contract.go
+ * @FilePath: \construction_management\web\viewmodels\folder_contract.go
  */
 package viewmodels
 
 import validation "github.com/go-ozzo/ozzo-validation/v3"
 
-type TreeContract struct {
+type FolderContract struct {
 	Id           string `form:"id" json:"id" `
 	Name         string `form:"name" json:"name"`
 	ProjectId    string `form:"projectId" json:"projectId"`
@@ -26,14 +26,14 @@ type TreeContract struct {
 
 	Csrf string `form:"csrf" json:"csrf"`
 	// Leaf        bool    `json:"leaf" `
-	HasFolder   bool            `json:"hasFolder" `
-	IsBid       bool            `json:"isBid" `
-	IsEnd       bool            `json:"isEnd"`
-	ChildsTotal int             `json:"childsTotal"`
-	Children    []*TreeContract `json:"children"`
+	HasFolder   bool              `json:"hasFolder" `
+	IsBid       bool              `json:"isBid" `
+	IsEnd       bool              `json:"isEnd"`
+	ChildsTotal int               `json:"childsTotal"`
+	Children    []*FolderContract `json:"children"`
 }
 
-func (l TreeContract) Validate() error {
+func (l FolderContract) Validate() error {
 	return validation.ValidateStruct(&l,
 		validation.Field(&l.Id, validation.Required.Error("文件夹ID不能为空")),
 		validation.Field(&l.Name, validation.Required.Error("文件夹名称不能为空"), validation.Length(1, 60).Error("最多 15 个字符")),

+ 45 - 0
web/viewmodels/tree_section_contract.go

@@ -0,0 +1,45 @@
+/*
+ * @description:合同项目节-视图层
+ * @Author: CP
+ * @Date: 2020-11-02 15:18:59
+ * @FilePath: \construction_management\web\viewmodels\tree_section_contract.go
+ */
+package viewmodels
+
+type TreeSectionContract struct {
+	Id          string `form:"id" json:"id" `
+	ParentId    string `form:"parentId" json:"parentId"`
+	Name        string `form:"name" json:"name"`
+	Depth       int    `form:"depth" json:"depth"`
+	Serial      string `form:"serial" json:"serial"`
+	Attribution string `form:"attribution" json:"attribution"`
+	Sort        int    `form:"sort" json:"attribsortution"`
+	ProjectId   string `form:"projectId" json:"projectId"`
+	ContractId  string `form:"contractId" json:"contractId"`
+
+	ContractName     string `form:"contractName" json:"contractName"`
+	ContractCode     string `form:"contractCode" json:"contractCode"`
+	ContractPrice    string `form:"contractPrice" json:"contractPrice"`
+	ContractReturned string `form:"contractReturned" json:"contractReturned"`
+	ContractsPaid    string `form:"contractsPaid" json:"contractsPaid"`
+	ContractStatus   int    `form:"contractStatus" json:"contractStatus"`
+
+	CreateTime string `form:"createTime" json:"createTime"`
+
+	Children []*TreeSectionContract `json:"children"`
+
+	TemplateNumber int `form:"templateNumber" json:"templateNumber"`
+}
+
+// Isfolder int `form:"isfolder" json:"isfolder"`
+
+// 	UpdateTime     string `form:"updateTime" json:"updateTime"`
+// 	TargetFolderId string `form:"targetFolderId" json:"targetFolderId"`
+// 	Ancounts       int    `form:"ancounts" json:"ancounts"`
+
+// 	Csrf string `form:"csrf" json:"csrf"`
+// 	// Leaf        bool    `json:"leaf" `
+// 	HasFolder   bool    `json:"hasFolder" `
+// 	IsBid       bool    `json:"isBid" `
+// 	IsEnd       bool    `json:"isEnd"`
+// 	ChildsTotal int     `json:"childsTotal"`