Ver código fonte

标段生成

caipin 4 anos atrás
pai
commit
9b951d3b8f

+ 91 - 0
dao/bidsection_dao.go

@@ -0,0 +1,91 @@
+/*
+ * @description: 标段-数据库操作
+ * @Author: CP
+ * @Date: 2020-09-28 10:35:56
+ * @FilePath: \construction_management\dao\bidsection_dao.go
+ */
+package dao
+
+import (
+	"errors"
+	"strconv"
+	"time"
+
+	"github.com/go-xorm/xorm"
+	"go.mod/models"
+)
+
+//数据库操作引擎
+type BidsectionDao struct {
+	engine *xorm.Engine
+}
+
+//获得一个DAO对象
+func NewBidsectionDao(engine *xorm.Engine) *BidsectionDao {
+	return &BidsectionDao{
+		engine: engine,
+	}
+}
+
+//id获得数据
+func (d *BidsectionDao) Get(id int) *models.CmBidsection {
+	data := &models.CmBidsection{Id: id}
+	//Get取到值后,会自动赋值到data中
+	ok, err := d.engine.Get(data)
+	if ok && err == nil {
+		return data
+	} else {
+		data.Id = 0
+		return data
+	}
+}
+
+//更新
+func (d *BidsectionDao) Update(data *models.CmBidsection, columns []string) error {
+	_, err := d.engine.Id(data.Id).MustCols(columns...).Update(data)
+	return err
+}
+
+//创建
+func (d *BidsectionDao) Create(data *models.CmTree) error {
+	session := d.engine.NewSession()
+	defer session.Close()
+	err := session.Begin()
+	if err != nil {
+		return errors.New("创建标段出错-db")
+	}
+
+	// 创建标段
+	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)
+	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
+	_, err = session.Insert(data)
+	if err != nil {
+		session.Rollback()
+		return errors.New("创建标段联系出错-db")
+	}
+
+	err = session.Commit()
+	if err != nil {
+		session.Rollback()
+		return errors.New("创建标段出错-db")
+	}
+
+	return err
+}

+ 17 - 2
dao/tree_dao.go

@@ -71,6 +71,21 @@ func (d *TreeDao) GetAllDepth(depth int, projectId int) []models.CmTree {
 	}
 }
 
+// 获得该目录下所有的目录
+func (d *TreeDao) GetChildFolder(id int) []models.CmTree {
+	datalist := make([]models.CmTree, 0)
+	err := d.engine.
+		Asc("serial").
+		Where("parent_id=? and isdelete=0", id).
+		Find(&datalist)
+
+	if err != nil {
+		return datalist
+	} else {
+		return datalist
+	}
+}
+
 // 获得某一深度的某一归属 结构数据(不包含子集) 正序
 func (d *TreeDao) GetALLDepthByAttribution(depth int, projectId int, attribution string) []models.CmTree {
 	datalist := make([]models.CmTree, 0)
@@ -174,7 +189,7 @@ func (d *TreeDao) Move(treeNode *models.CmTree, moveFolder *models.CmTree) error
 	movrAttribution := fmt.Sprintf("%s%d-", moveFolder.Attribution, moveFolder.Serial)
 	// 3-获得移动后最大序列号
 	depth := moveFolder.Depth + 1
-	fmt.Println(depth)
+
 	datalist := d.GetALLDepthByAttribution(depth, moveFolder.ProjectId, movrAttribution)
 	maxIndex := len(datalist)
 	serial := 0
@@ -200,7 +215,7 @@ func (d *TreeDao) Move(treeNode *models.CmTree, moveFolder *models.CmTree) error
 	err = session.Commit()
 	if err != nil {
 		session.Rollback()
-		return errors.New("删除出错-db")
+		return errors.New("移动出错-db")
 	}
 	return nil
 }

+ 31 - 0
models/cm_bidsection.go

@@ -0,0 +1,31 @@
+package models
+
+import (
+	"time"
+)
+
+type CmBidsection struct {
+	Id           int       `xorm:"not null pk autoincr comment('自增ID') INT(11)"`
+	Name         string    `xorm:"comment('名称') VARCHAR(128)"`
+	Status       int       `xorm:"comment('状态') TINYINT(1)"`
+	ProjectId    int       `xorm:"comment('项目id') INT(11)"`
+	UserId       int       `xorm:"comment('用户id') INT(11)"`
+	CreateTime   time.Time `xorm:"comment('创建时间') DATETIME"`
+	Category     string    `xorm:"comment('分类属性') VARCHAR(1024)"`
+	Type         int       `xorm:"comment('标段类型') TINYINT(2)"`
+	LedgerTimes  int       `xorm:"not null default 0 comment('台账审批次数') TINYINT(4)"`
+	LedgerStatus int       `xorm:"not null default 1 comment('台账审批状态') TINYINT(4)"`
+	MRule        string    `xorm:"VARCHAR(1024)"`
+	Times        int       `xorm:"comment('审批次数') TINYINT(4)"`
+	CRule        string    `xorm:"comment('变更令-规则') VARCHAR(1024)"`
+	CConnector   int       `xorm:"comment('变更令-连接符') TINYINT(4)"`
+	CRuleFirst   int       `xorm:"comment('变更令规则第一次出现') TINYINT(1)"`
+	MeasureType  string    `xorm:"VARCHAR(11)"`
+	SImType      string    `xorm:"comment('期,中间计量,模式') VARCHAR(11)"`
+	Cooperation  string    `xorm:"comment('协作人员和功能列表') TEXT"`
+	Valuation    int       `xorm:"comment('计价规范') TINYINT(4)"`
+	TotalPrice   string    `xorm:"comment('0号台账 -- 金额') DECIMAL(12,2)"`
+	DealTp       string    `xorm:"comment('签约 -- 金额') DECIMAL(12,2)"`
+	Uuid         string    `xorm:"comment('更新时间') VARCHAR(64)"`
+	Isdelete     int       `xorm:"default 0 comment('1删除') TINYINT(1)"`
+}

+ 1 - 0
models/cm_tender.go

@@ -27,4 +27,5 @@ type CmTender struct {
 	TotalPrice   string    `xorm:"comment('0号台账 -- 金额') DECIMAL(12,2)"`
 	DealTp       string    `xorm:"comment('签约 -- 金额') DECIMAL(12,2)"`
 	Uuid         string    `xorm:"comment('更新时间') VARCHAR(64)"`
+	Isdelete     int       `xorm:"default 0 comment('1删除') TINYINT(1)"`
 }

+ 12 - 12
models/cm_tree.go

@@ -5,16 +5,16 @@ import (
 )
 
 type CmTree struct {
-	Id          int       `xorm:"not null pk autoincr comment('自增ID') INT(11)"`
-	Name        string    `xorm:"not null comment('名称') VARCHAR(64)"`
-	ProjectId   int       `xorm:"not null default 0 comment('项目ID') INT(11)"`
-	Depth       int       `xorm:"not null default 0 comment('深度') TINYINT(4)"`
-	Serial      int       `xorm:"not null default 0 comment('序号') TINYINT(4)"`
-	Attribution string    `xorm:"comment('归属') VARCHAR(32)"`
-	Isfolder    int       `xorm:"not null default 1 comment('是否文件夹 1文件夹 0其他') TINYINT(1)"`
-	TenderId    int       `xorm:"comment('标段ID') INT(11)"`
-	ParentId    int       `xorm:"not null default 0 comment('父级ID') INT(11)"`
-	Isdelete    int       `xorm:"not null default 0 comment('1删除') TINYINT(1)"`
-	CreateTime  time.Time `xorm:"comment('创建时间') DATETIME"`
-	UpdateTime  time.Time `xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') TIMESTAMP"`
+	Id           int       `xorm:"not null pk autoincr comment('自增ID') INT(11)"`
+	Name         string    `xorm:"not null comment('名称') VARCHAR(64)"`
+	ProjectId    int       `xorm:"not null default 0 comment('项目ID') INT(11)"`
+	Depth        int       `xorm:"not null default 0 comment('深度') TINYINT(4)"`
+	Serial       int       `xorm:"not null default 0 comment('序号') TINYINT(4)"`
+	Attribution  string    `xorm:"comment('归属') VARCHAR(32)"`
+	Isfolder     int       `xorm:"not null default 1 comment('是否文件夹 1文件夹 0其他') TINYINT(1)"`
+	BidsectionId int       `xorm:"comment('标段ID') INT(11)"`
+	ParentId     int       `xorm:"not null default 0 comment('父级ID') INT(11)"`
+	Isdelete     int       `xorm:"not null default 0 comment('1删除') TINYINT(1)"`
+	CreateTime   time.Time `xorm:"comment('创建时间') DATETIME"`
+	UpdateTime   time.Time `xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') TIMESTAMP"`
 }

+ 116 - 0
services/bidsection_service.go

@@ -0,0 +1,116 @@
+/*
+ * @description: 标段相关数据操作相关
+ * @Author: CP
+ * @Date: 2020-09-28 10:31:31
+ * @FilePath: \construction_management\services\bidsection_service.go
+ */
+package services
+
+import (
+	"errors"
+	"fmt"
+	"log"
+	"strconv"
+	"time"
+
+	"github.com/kataras/iris/v12"
+	"go.mod/dao"
+	"go.mod/datasource"
+	"go.mod/models"
+	"go.mod/web/utils"
+	"go.mod/web/viewmodels"
+)
+
+//定义标段Service接口
+type BidsectionService interface {
+	ValidRule(iris.Context) (viewmodels.Bidsection, error)
+	Create(viewmodels.Bidsection) error
+}
+
+//返回service操作类
+type bidsectionService struct {
+	dao     *dao.BidsectionDao
+	treeDao *dao.TreeDao
+}
+
+//创建标段service
+func NewBidsectionService() BidsectionService {
+	return &bidsectionService{
+		dao:     dao.NewBidsectionDao(datasource.InstanceDbMaster()),
+		treeDao: dao.NewTreeDao(datasource.InstanceDbMaster()),
+	}
+}
+
+// 文件夹规则验证
+func (s *bidsectionService) ValidRule(ctx iris.Context) (viewmodels.Bidsection, error) {
+	bidsectionVaild := viewmodels.Bidsection{}
+	err := ctx.ReadJSON(&bidsectionVaild)
+	if err != nil {
+		log.Println("folder-ValidRule-ReadForm转换异常, error=", err)
+		return bidsectionVaild, err
+	}
+
+	err = bidsectionVaild.Validate()
+	if err != nil {
+		log.Println("标段验证, error=", err)
+		return bidsectionVaild, err
+	}
+
+	return bidsectionVaild, nil
+}
+
+// 新增一个标段
+func (s *bidsectionService) Create(data viewmodels.Bidsection) error {
+	// 类型校验
+	folder := models.CmTree{}
+	folder.Name = data.Name
+	ProjectId, err := strconv.Atoi(data.ProjectId)
+	if err != nil {
+		return err
+	}
+
+	// 获得该目录ID
+	Id, err := utils.GetDecryptId(data.FolderId)
+	if err != nil {
+		return err
+	}
+
+	// 该目录中是否有目录 -判断是否是叶子节点--TODO
+	folderList := s.treeDao.GetChildFolder(Id)
+	if len(folderList) > 0 {
+		return errors.New("该目录中存在其他目录,不能新增标段")
+	}
+
+	// 创建在树中的标段
+	// 获得该深度的文件夹最大序号
+	serial := 0
+	treeNode := s.treeDao.Get(Id)
+	if treeNode.Id == 0 {
+		return errors.New("上级目录不正确")
+	}
+	depth := treeNode.Depth + 1
+	attribution := fmt.Sprintf("%s%d-", treeNode.Attribution, treeNode.Serial)
+	fmt.Println(attribution)
+	datalist := s.treeDao.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 = Id
+
+	folder.ProjectId = ProjectId
+	folder.Serial = serial
+	folder.Depth = depth
+	folder.Isfolder = 0
+	folder.CreateTime = time.Now()
+	folder.UpdateTime = time.Now()
+
+	// 创建标段和标段在树中的联系
+	err = s.dao.Create(&folder)
+	if err != nil {
+		return err
+	}
+	return nil
+}

+ 1 - 1
services/login_service.go

@@ -49,7 +49,6 @@ func NewLoginService() LoginService {
 func (s *loginService) ValidRule(ctx iris.Context) (viewmodels.Login, error) {
 	loginVaild := viewmodels.Login{}
 	err := ctx.ReadJSON(&loginVaild)
-	fmt.Println(loginVaild)
 	if err != nil {
 		log.Println("ReadForm转换异常, error=", err)
 		return loginVaild, err
@@ -68,6 +67,7 @@ func (s *loginService) ValidProjectAccount(loginData viewmodels.Login, writer ht
 	projectInfo := models.CmProject{}
 	// 工程项目是否存在
 	projectInfo.Code = loginData.Code
+	fmt.Println(projectInfo.Code)
 	s.projectDao.Get(&projectInfo)
 	if projectInfo.Id == 0 {
 		return errors.New("工程建设管理员还未创建拉取项目,禁止登录")

+ 1 - 0
services/project_account_service.go

@@ -111,5 +111,6 @@ func makeProjectAccountVM(modelsAccount *models.CmProjectAccount) viewmodels.Pro
 	viewAccountData.Role = modelsAccount.Role
 	viewAccountData.Mobile = modelsAccount.Mobile
 	viewAccountData.Telephone = modelsAccount.Telephone
+	viewAccountData.IsAdmin = modelsAccount.IsAdmin
 	return viewAccountData
 }

+ 18 - 0
services/tree_service.go

@@ -254,6 +254,24 @@ func (s *treeService) Move(id int, moveId int) error {
 		return errors.New("目录解析错误")
 	}
 
+	// TODO
+	// 移动的是目录
+	if treeNode.Isfolder == 1 {
+		// 1.目录下不能有标段
+		// 被移动的目录存在标段
+		moveBidList := s.dao.GetBidsection(moveId)
+		if len(moveBidList) > 0 {
+			return errors.New("该目录中存在标段,不能移动")
+		}
+	} else {
+		// 标段
+		// 1.移动的目录是否为叶子节点
+		moveBidList := s.dao.GetChildFolder(moveId)
+		if len(moveBidList) > 0 {
+			return errors.New("该目录中存在其他目录,不能移动")
+		}
+	}
+
 	err := s.dao.Move(treeNode, moveFolder)
 	if err != nil {
 		return err

+ 68 - 0
web/api/bidsection_api.go

@@ -0,0 +1,68 @@
+/*
+ * @description: 标段相关的接口api
+ * @Author: CP
+ * @Date: 2020-09-28 10:26:49
+ * @FilePath: \construction_management\web\api\bidsection_api.go
+ */
+package api
+
+import (
+	"fmt"
+	"strconv"
+
+	"github.com/kataras/iris/v12"
+	"go.mod/services"
+	"go.mod/web/utils"
+)
+
+type BidsectionApi struct {
+	//框架-web应用上下文环境
+	Ctx iris.Context
+	// 需要用的service
+	ServiceBidsection services.BidsectionService
+}
+
+// 获得项目目录结构
+func (c *BidsectionApi) Get() {
+
+}
+
+// 添标段结构
+func (c *BidsectionApi) PostCreate() {
+	ErrMsg := ""
+	// 验证内容
+	BidsectionData, err := c.ServiceBidsection.ValidRule(c.Ctx)
+	if err != nil {
+		ErrMsg = utils.FormValidError(err)
+		c.Ctx.JSON(iris.Map{
+			"code": -1,
+			"msg":  ErrMsg,
+		})
+		return
+	} else {
+
+		// 获得项目ID
+		projectIdInt, err := utils.GetProjectId(c.Ctx)
+		if err != nil {
+			c.Ctx.JSON(iris.Map{
+				"code": -1,
+				"msg":  fmt.Sprintf("%s", err),
+			})
+			return
+		}
+		BidsectionData.ProjectId = strconv.Itoa(projectIdInt)
+		// 新增标段-新增树结构里的标段
+		err = c.ServiceBidsection.Create(BidsectionData)
+		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 - 2
web/api/tree_api.go

@@ -182,6 +182,4 @@ func (c *TreeApi) PostMove() {
 		"code": 0,
 		"msg":  "移动成功",
 	})
-
-	fmt.Println(ProjectAccountVM)
 }

+ 7 - 0
web/routes/routes.go

@@ -21,6 +21,7 @@ func Configure(b *bootstrap.Bootstrapper) {
 	LoginService := services.NewLoginService()
 	ProjectService := services.NewProjectService()
 	TreeService := services.NewTreeService()
+	BidsectionService := services.NewBidsectionService()
 	//CSRF相关
 	b.Use(middleware.SetCsrf)
 
@@ -89,4 +90,10 @@ func Configure(b *bootstrap.Bootstrapper) {
 	apiProjectAccount.Register(ProjectAccountService)
 	apiProjectAccount.Router.Use(middleware.JwtAuth().Serve)
 	apiProjectAccount.Handle(new(api.ProjectAccountApi))
+
+	// 标段相关接口
+	apiBidsection := mvc.New(b.Party("/api/bidsection"))
+	apiBidsection.Register(BidsectionService)
+	apiBidsection.Router.Use(middleware.JwtAuth().Serve)
+	apiBidsection.Handle(new(api.BidsectionApi))
 }

+ 45 - 0
web/viewmodels/bidsection.go

@@ -0,0 +1,45 @@
+/*
+ * @description:
+ * @Author: CP
+ * @Date: 2020-09-28 10:56:55
+ * @FilePath: \construction_management\web\viewmodels\bidsection.go
+ */
+package viewmodels
+
+import (
+	validation "github.com/go-ozzo/ozzo-validation/v3"
+)
+
+type Bidsection struct {
+	Id         string `form:"id"`
+	Name       string `form:"name"`
+	ProjectId  string `form:"name"`
+	CreateTime string `form:"createTime"`
+	FolderId   string `form:"folderId"`
+	// Status   int    `xorm:"comment('状态') TINYINT(1)"`
+	// UserId   int    `xorm:"comment('用户id') INT(11)"`
+	// Category string `xorm:"comment('分类属性') VARCHAR(1024)"`
+
+	// Type         int    `xorm:"comment('标段类型') TINYINT(2)"`
+	// LedgerTimes  int    `xorm:"not null default 0 comment('台账审批次数') TINYINT(4)"`
+	// LedgerStatus int    `xorm:"not null default 1 comment('台账审批状态') TINYINT(4)"`
+	// MRule        string `xorm:"VARCHAR(1024)"`
+	// Times        int    `xorm:"comment('审批次数') TINYINT(4)"`
+	// CRule        string `xorm:"comment('变更令-规则') VARCHAR(1024)"`
+	// CConnector   int    `xorm:"comment('变更令-连接符') TINYINT(4)"`
+	// CRuleFirst   int    `xorm:"comment('变更令规则第一次出现') TINYINT(1)"`
+	// MeasureType  string `xorm:"VARCHAR(11)"`
+	// SImType      string `xorm:"comment('期,中间计量,模式') VARCHAR(11)"`
+	// Cooperation  string `xorm:"comment('协作人员和功能列表') TEXT"`
+	// Valuation    int    `xorm:"comment('计价规范') TINYINT(4)"`
+	// TotalPrice   string `xorm:"comment('0号台账 -- 金额') DECIMAL(12,2)"`
+	// DealTp       string `xorm:"comment('签约 -- 金额') DECIMAL(12,2)"`
+	// Uuid         string `xorm:"comment('更新时间') VARCHAR(64)"`
+}
+
+func (l Bidsection) Validate() error {
+	return validation.ValidateStruct(&l,
+		// Code cannot be empty, and the length must between 5 and 50
+		validation.Field(&l.Name, validation.Required.Error("标段名称不能为空"), validation.Length(2, 128).Error("项目编号最少要输入 2 个字符")),
+	)
+}

+ 1 - 0
web/viewmodels/project_account.go

@@ -17,6 +17,7 @@ type ProjectAccount struct {
 	Role      string `form:"role"`
 	Mobile    string `form:"mobile"`
 	Telephone string `form:"telephone"`
+	IsAdmin   int    `form:"isAdmin"`
 
 	MoveId string `form:"moveId"`
 	// LastLogin    int       `xorm:"comment('最后登录时间') INT(11)"`