caipin 4 jaren geleden
bovenliggende
commit
dcaecf5e4a

+ 2 - 2
bootstrap/bootstrap.go

@@ -35,13 +35,13 @@ type Bootstrapper struct {
 var RpcConnect *grpc.ClientConn
 
 func init() {
-	log.Println("rpcClient初始化中...")
+	log.Println("RpcConnect 初始化中...")
 	conn, err := grpc.Dial(conf.NodeRpcHost, grpc.WithInsecure())
 	if err != nil {
 		log.Fatalf("did not connect: %v", err)
 	}
 	RpcConnect = conn
-	log.Println("rpcClient初始化成功")
+	log.Println("RpcConnect 初始化成功")
 }
 
 //新建和返回一个Bootstrapper

+ 6 - 2
dao/contract_dao.go

@@ -40,7 +40,10 @@ func (d *ContractDao) Get(id int) *models.CmContracts {
 }
 
 // 新增合同
-func (d *ContractDao) Add(contractData *models.CmContracts) error {
+// contractData *models.CmContracts
+// contractTotal 合同总数
+// priceTotal 收入总金额
+func (d *ContractDao) Add(contractData *models.CmContracts, contractTotal int, priceTotal float64) error {
 	session := d.engine.NewSession()
 	defer session.Close()
 	err := session.Begin()
@@ -63,12 +66,13 @@ func (d *ContractDao) Add(contractData *models.CmContracts) error {
 		session.Rollback()
 		return errors.New("新增合同出错-项目节更新失败")
 	}
+
 	// 3.更新标段目录金额合计
 	// 3-1 获得项目-标段下合同总数
 	// 3-2 获得项目标段下合同收入中金额
 	_, err = session.Exec("UPDATE  cm_tree SET `contracts` = ?,`contracts_income` = ? "+
 		"where project_id = ? and bidsection_id = ? ",
-		contractData.Id, contractData.Name, contractData.Code, contractData.Price,
+		contractTotal, priceTotal,
 		contractData.ProjectId, contractData.BidsectionId)
 	if err != nil {
 		session.Rollback()

+ 14 - 0
dao/tree_contract_dao.go

@@ -56,6 +56,20 @@ func (d *TreeContractDao) GetAll(bidsectionId int, projectId int) []models.CmTre
 	}
 }
 
+// 获得标段 项目节中已有的合同
+func (d *TreeContractDao) GetContract(bidsectionId int, projectId int) []models.CmTreeContracts {
+	datalist := make([]models.CmTreeContracts, 0)
+	err := d.engine.
+		Asc("id").
+		Where("bidsection_id =? and project_id=? and contract_id!=0", bidsectionId, projectId).
+		Find(&datalist)
+	if err != nil {
+		return datalist
+	} else {
+		return datalist
+	}
+}
+
 // 获得节点的孩子
 func (d *TreeContractDao) GetChildren(parentId int, bidsectionId int, projectId int) []models.CmTreeContracts {
 	datalist := make([]models.CmTreeContracts, 0)

+ 9 - 2
models/cm_contracts.go

@@ -10,12 +10,19 @@ type CmContracts struct {
 	ContractsType int       `xorm:"not null comment('合同类型(1收入合同2支出合同)') TINYINT(1)"`
 	ProjectId     int       `xorm:"not null default 0 comment('项目ID') INT(11)"`
 	BidsectionId  int       `xorm:"comment('标段ID') INT(11)"`
-	Name          string    `xorm:"not null comment('名称') VARCHAR(64)"`
+	Name          string    `xorm:"not null comment('合同名称') VARCHAR(64)"`
+	Content       string    `xorm:"comment('合同内容') VARCHAR(1024)"`
 	Code          string    `xorm:"comment('合同编号') VARCHAR(32)"`
+	PartyA        string    `xorm:"comment('甲方') VARCHAR(32)"`
+	PartyASigner  string    `xorm:"comment('甲方签约人') VARCHAR(32)"`
+	PartyB        string    `xorm:"comment('乙方') VARCHAR(32)"`
+	PartyBSigner  string    `xorm:"comment('乙方签约人') VARCHAR(32)"`
+	SignerTime    time.Time `xorm:"comment('签约日期') DATETIME"`
+	Remarks       string    `xorm:"comment('备注') VARCHAR(1024)"`
 	Price         string    `xorm:"not null comment('合同金额 0') DECIMAL(12,2)"`
 	Returned      string    `xorm:"not null comment('回款总金额 0') DECIMAL(12,2)"`
 	Paid          string    `xorm:"not null default 0.00 comment('合同已支付金额 0') DECIMAL(12,2)"`
-	Status        int       `xorm:"not null comment('合同状态 0') TINYINT(1)"`
+	Status        int       `xorm:"not null comment('合同状态(0履行中1待关闭2已关闭)') TINYINT(1)"`
 	CreateTime    time.Time `xorm:"comment('创建时间') DATETIME"`
 	UpdateTime    time.Time `xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') TIMESTAMP"`
 }

+ 17 - 1
services/contract_service.go

@@ -8,7 +8,9 @@ package services
 
 import (
 	"errors"
+	"fmt"
 	"log"
+	"strconv"
 	"time"
 
 	"github.com/kataras/iris/v12"
@@ -233,7 +235,21 @@ func (s *contractService) Add(contractData *viewmodels.Contracts, projectId int,
 	contractsCm.CreateTime = time.Now()
 	contractsCm.UpdateTime = time.Now()
 
-	err := s.contractDao.Add(contractsCm)
+	// 获得该标段下合同总数 - 总收入金额
+	contractList := s.treeContractDao.GetContract(bidsectionId, projectId)
+	priceTotal := 0.00
+	for _, item := range contractList {
+		contractPrice, _ := strconv.ParseFloat(item.ContractPrice, 64)
+		priceTotal = priceTotal + contractPrice
+	}
+	// 合同总数
+	contractTotal := len(contractList) + 1
+	// 合同收入总金额
+	price, _ := strconv.ParseFloat(contractsCm.Price, 64)
+	priceTotal = priceTotal + price
+	// 保留2位小数
+	priceTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", priceTotal), 64)
+	err := s.contractDao.Add(contractsCm, contractTotal, priceTotal)
 	if err != nil {
 		return err
 	}

+ 50 - 1
web/api/contract_api.go

@@ -179,8 +179,57 @@ func (c *ContractApi) GetIncome() {
 	})
 }
 
-// 新增合同
+// @Summary 新增合同
+// @Tags 合同管理
+// @Description 新增合同
+// @Accept  json
+// @Produce  json
+// @Security ApiKeyAuth
+// @Param   treeId     path    string     true        "项目节ID"
+// @Param   bidsectionId     path    string     true        "标段ID"
+// @Param   code     path    string     true        "合同编号"
+// @Param   name     path    string     true        "合同名称"
+// @Param   contractsType     path    int     true        "合同类型(1)"
+// @Param   price     path    string     true        "合同金额"
+// @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
+// @Router /api/contract/income/create [post]
 func (c *ContractApi) PostIncomeCreate() {
+	// 获得模板号
+	contractData, err := c.ServiceContract.ValidRuleContractAdd(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+
+	// 项目ID
+	projectIdInt, err := utils.GetProjectId(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+	// 标段ID
+	bidsectionId, err := utils.GetDecryptId(contractData.BidsectionId)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+	// 项目节ID
+	treeId, err := utils.GetDecryptId(contractData.TreeId)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+
+	err = c.ServiceContract.Add(contractData, projectIdInt, bidsectionId, treeId)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+	c.Ctx.JSON(iris.Map{"code": 0, "msg": "新增成功"})
+}
+
+// 编辑合同
+func (c *ContractApi) PostIncomeUpdate() {
 
 	// 获得模板号
 	contractData, err := c.ServiceContract.ValidRuleContractAdd(c.Ctx)

+ 8 - 0
web/viewmodels/contract.go

@@ -26,6 +26,14 @@ type Contracts struct {
 	Status        int       `form:"status" json:"status" `
 	CreateTime    time.Time `form:"createTime" json:"createTime" `
 	UpdateTime    time.Time `form:"updateTime" json:"updateTime" `
+
+	Content      string    `xorm:"comment('合同内容') VARCHAR(1024)"`
+	PartyA       string    `xorm:"comment('甲方') VARCHAR(32)"`
+	PartyASigner string    `xorm:"comment('甲方签约人') VARCHAR(32)"`
+	PartyB       string    `xorm:"comment('乙方') VARCHAR(32)"`
+	PartyBSigner string    `xorm:"comment('乙方签约人') VARCHAR(32)"`
+	SignerTime   time.Time `xorm:"comment('签约日期') DATETIME"`
+	Remarks      string    `xorm:"comment('备注') VARCHAR(1024)"`
 }
 
 // 验证方法