Explorar o código

Merge branch 'master' of http://192.168.1.41:3000/caipin/construction_management

# Conflicts:
#	.gitignore
#	web/docs/docs.go
#	web/docs/swagger.json
#	web/docs/swagger.yaml
caipin %!s(int64=4) %!d(string=hai) anos
pai
achega
4e2eac2b14

+ 0 - 4
.gitignore

@@ -2,7 +2,3 @@
 /web/web.exe
 /go.sum
 /go.mod
-docs
-/web/docs/docs.go
-/web/docs/swagger.json
-/web/docs/swagger.yaml

+ 8 - 0
dao/project_account_dao.go

@@ -11,6 +11,7 @@ import (
 
 	"github.com/go-xorm/xorm"
 	"go.mod/models"
+	"go.mod/web/viewmodels"
 )
 
 //数据库操作引擎
@@ -132,3 +133,10 @@ func (d *ProjectAccountDao) Delete(data *models.CmProjectAccount) error {
 	}
 	return err
 }
+
+// 查找
+func (d *ProjectAccountDao) FindById(id int) (viewmodels.ProjectInfo, error) {
+	projectInfo := viewmodels.ProjectInfo{}
+	_, err := d.engine.Sql("select p.`name` as projectName, p.`code`, p.`create_time`, a.`mobile`, a.`name` from `cm_project` as p, `cm_project_account` as a where p.`user_id` = a.`id` and p.`id` = ?", id).Get(&projectInfo)
+	return projectInfo, err
+}

+ 64 - 0
dao/rule_dao.go

@@ -0,0 +1,64 @@
+/*
+ * @description: 编号规则数据库操作相关
+ * @Author: LanJianRong
+ * @Date: 2020-11-27
+ * @FilePath: \construction_management\dao\rule_dao.go
+ */
+
+package dao
+
+import (
+	"fmt"
+
+	"github.com/go-xorm/xorm"
+	"go.mod/models"
+)
+
+//数据库操作引擎
+type RuleDao struct {
+	engine *xorm.Engine
+}
+
+//获得一个DAO对象
+func NewRuleDao(engine *xorm.Engine) *RuleDao {
+	return &RuleDao{
+		engine: engine,
+	}
+}
+
+// 通过项目id和标段id查找
+func (d *RuleDao) FindByPidWithBid(pid int, bid int) *models.CmRule {
+	data := &models.CmRule{BidsectionId: bid, ProjectId: pid}
+	ok, err := d.engine.Get(data)
+	if ok && err == nil {
+		return data
+	} else {
+		data.Id = 0
+		return data
+	}
+}
+
+// 根据pid和bid更新、不存在则创建
+func (d *RuleDao) UpdateOrCreate(pid int, bid int, key string, value string) error {
+	data := &models.CmRule{BidsectionId: bid, ProjectId: pid}
+	has, err := d.engine.Get(data)
+	if key == "safe_rule" {
+		data.SafeRule = value
+	} else if key == "quality_rule" {
+		data.QualityRule = value
+	} else {
+		data.ContractRule = value
+	}
+	// fmt.Println("newData", data, "value", value, "key", key)
+	if has && err == nil {
+		_, err := d.engine.Id(data.Id).Update(data)
+		fmt.Println("err2", err)
+		return err
+	} else if !has && err == nil {
+		_, err := d.engine.Insert(data)
+		fmt.Println("err3", err)
+		return err
+	}
+	fmt.Println(err)
+	return err
+}

+ 18 - 1
dao/safe_dao.go

@@ -39,8 +39,8 @@ func (d *SafeDao) FindById(id int) *models.CmSafe {
 func (d *SafeDao) GetListByBid(id int) []models.CmSafe {
 	dataList := make([]models.CmSafe, 0)
 	err := d.engine.
-		Asc("create_time").
 		Where("bidsection_id=?", id).
+		Asc("id").
 		Find(&dataList)
 	if err != nil {
 		return dataList
@@ -60,3 +60,20 @@ func (d *SafeDao) DeleteRecord(id int) (bool, error) {
 	affected, err := d.engine.Id(id).Delete(safe)
 	return affected > 0, err
 }
+
+// 根据code获取记录
+func (d *SafeDao) FindByCode(code string) bool {
+	data := &models.CmSafe{Code: code}
+	has, _ := d.engine.Get(data)
+	return has
+}
+
+// 筛选出应用了当前规则的条数
+func (d *SafeDao) CountRuleCode(bid int) (int64, error) {
+	data := &models.CmSafe{}
+	total, err := d.engine.Where("`bidsection_id` = ?", bid).Count(data)
+	if err != nil {
+		total = 0
+	}
+	return total, err
+}

+ 7 - 0
services/project_account_service.go

@@ -35,6 +35,7 @@ type ProjectAccountService interface {
 	Save(viewAccount viewmodels.ProjectAccount, id int, projectId int) error
 	Enable(id int, projectId int, enable int) error
 	ChangeAccount(id int, projectId int, viewAccount viewmodels.ProjectAccount) error
+	GetProjectInfo(id int) (viewmodels.ProjectInfo, error)
 	Delete(id int, projectId int) error
 }
 
@@ -253,3 +254,9 @@ func (s *projectAccountService) ChangeAccount(id int, projectId int, viewAccount
 
 	return nil
 }
+
+func (s *projectAccountService) GetProjectInfo(id int) (viewmodels.ProjectInfo, error) {
+	projectInfo, err := s.dao.FindById(id)
+	// return new errors("啊啊啊")
+	return projectInfo, err
+}

+ 127 - 0
services/rule_service.go

@@ -0,0 +1,127 @@
+package services
+
+import (
+	"encoding/json"
+	"errors"
+	"fmt"
+	"log"
+	"reflect"
+	"strconv"
+
+	"go.mod/web/utils"
+
+	"github.com/kataras/iris/v12"
+	"go.mod/dao"
+	"go.mod/datasource"
+	"go.mod/web/viewmodels"
+)
+
+type RuleService interface {
+	Get(pid int, id int) viewmodels.ViewRule
+	Post(pid int, id int, key string, value string) error
+	AutoCode(bid int, pid int, codeType string) (string, error)
+	ValidRule(ctx iris.Context) (viewmodels.ValidField, error)
+}
+
+// //返回service操作类
+type ruleService struct {
+	daoRule       *dao.RuleDao
+	daoSafe       *dao.SafeDao
+	validAutoPath string
+}
+
+//创建项目用户service
+func NewRuleService() RuleService {
+	return &ruleService{
+		validAutoPath: "/api/rule/auto",
+		daoRule:       dao.NewRuleDao(datasource.InstanceDbMaster()),
+		daoSafe:       dao.NewSafeDao(datasource.InstanceDbMaster()),
+	}
+}
+
+func (s *ruleService) Get(pid int, id int) viewmodels.ViewRule {
+	data := s.daoRule.FindByPidWithBid(pid, id)
+	viewData := viewmodels.ViewRule{SafeRule: data.SafeRule, QualityRule: data.QualityRule, ContractRule: data.ContractRule}
+	return viewData
+}
+
+func (s *ruleService) Post(pid int, id int, key string, value string) error {
+	err := s.daoRule.UpdateOrCreate(pid, id, key, value)
+	return err
+}
+
+// type Code struct {
+// 	Date string `from:"date" json:"date"`
+// 	Text string `from:"text" json:"text"`
+// 	Name string `from:"name" json:"name"`
+// 	Code string `from:"code" json:"code"`
+// }
+
+// 生成code
+func (s *ruleService) AutoCode(bid int, pid int, codeType string) (string, error) {
+	// 获取该标段的规则
+	rule := s.daoRule.FindByPidWithBid(pid, bid)
+	if codeType == "safeRule" {
+		var code viewmodels.RuleCode
+		err := json.Unmarshal([]byte(rule.SafeRule), &code)
+		// fmt.Println(code)
+		fmt.Println(err)
+		if err == nil {
+			total, err := s.daoSafe.CountRuleCode(bid)
+			value := reflect.ValueOf(code)
+			for i := 0; i < value.NumField(); i++ {
+				b := fmt.Sprint(value.Field(i))
+				if b == code.Code {
+					// fmt.Println(value.Field(i))
+					k, _ := strconv.Atoi(b)
+					code.Code = utils.CreateRuleCode(int64(k), total, len(code.Code))
+				}
+			}
+
+			e, err := json.Marshal(code)
+			if err != nil {
+				return "", err
+			}
+			// fmt.Println()
+			// var v interface{}
+			// for key, val := range code {
+			// 	fmt.Printf("%v===>%v\n", key, val)
+			// }
+			// c, _ := strconv.Atoi(code.Code)
+			// l := len(code.Code)
+			// fmt.Println(c, l, total)
+			// fmt.Println("total", total)
+			return string(e), err
+		}
+	}
+	return "", errors.New("生成code失败")
+}
+
+func (s *ruleService) ValidRule(ctx iris.Context) (viewmodels.ValidField, error) {
+	safeVaild := viewmodels.ValidField{}
+	if ctx.Method() == "GET" {
+		err := ctx.ReadForm(&safeVaild)
+		if err != nil {
+			log.Println("safe-ValidRule-ReadForm转换异常, error=", err)
+			return safeVaild, err
+		}
+		err = safeVaild.Validate()
+		return safeVaild, err
+	}
+
+	if ctx.Method() == "POST" {
+		err := ctx.ReadJSON(&safeVaild)
+		if err != nil {
+			log.Println("safe-ValidRule-ReadJson转换异常, error=", err)
+			return safeVaild, err
+		}
+		if ctx.Path() == s.validAutoPath {
+			err = safeVaild.ValidateAuto()
+		} else {
+			err = safeVaild.Validate()
+		}
+
+	}
+	return safeVaild, nil
+
+}

+ 10 - 0
services/safe_service.go

@@ -1,6 +1,7 @@
 package services
 
 import (
+	"errors"
 	"fmt"
 	"log"
 	"strconv"
@@ -28,6 +29,7 @@ type safeService struct {
 	daoSafeAudit      *dao.SafeAuditDao
 	daoSafeFile       *dao.SafeFileDao
 	daoProjectAccount *dao.ProjectAccountDao
+	daoRule           *dao.RuleDao
 	validDetail       string
 }
 
@@ -65,6 +67,10 @@ func (s *safeService) Get(id int, pid int) []viewmodels.SafeList {
 
 // post请求,插入单条数据
 func (s *safeService) Post(data models.CmSafe) error {
+	has := s.daoSafe.FindByCode(data.Code)
+	if has {
+		return errors.New("该编号已存在!")
+	}
 	Inserted, err := s.daoSafe.InsertRecord(data)
 	if Inserted == true {
 		return nil
@@ -106,6 +112,7 @@ func (s *safeService) GetDetail(id int, pid int) viewmodels.SafeDetail {
 
 func (s *safeService) ValidRule(ctx iris.Context) (viewmodels.Safe, error) {
 	safeVaild := viewmodels.Safe{}
+	fmt.Println("---------------------------safeVaild", safeVaild)
 	if ctx.Method() == "GET" {
 		err := ctx.ReadForm(&safeVaild)
 		if err != nil {
@@ -118,6 +125,7 @@ func (s *safeService) ValidRule(ctx iris.Context) (viewmodels.Safe, error) {
 		} else {
 			err = safeVaild.ValidateList()
 		}
+		return safeVaild, err
 	}
 
 	if ctx.Method() == "POST" {
@@ -127,6 +135,7 @@ func (s *safeService) ValidRule(ctx iris.Context) (viewmodels.Safe, error) {
 			return safeVaild, err
 		}
 		err = safeVaild.ValidateCreate()
+		return safeVaild, err
 	}
 
 	if ctx.Method() == "PUT" {
@@ -136,6 +145,7 @@ func (s *safeService) ValidRule(ctx iris.Context) (viewmodels.Safe, error) {
 			return safeVaild, err
 		}
 		err = safeVaild.ValidateDelete()
+		return safeVaild, err
 	}
 	return safeVaild, nil
 

+ 23 - 0
web/api/project_setting_api.go

@@ -310,6 +310,29 @@ func (c *ProjectSettingApi) PostAccountChange() {
 	}
 }
 
+// @Summary 获取项目信息
+// @Tags 项目设置-管理员
+// @Description 获取项目信息
+// @Accept  json
+// @Produce  json
+// @Security ApiKeyAuth
+// @Success 200 {string} string "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
+// @Router /api/projectSetting/project [get]
+func (c *ProjectSettingApi) GetProject() {
+	projectId, err := utils.GetProjectId(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+	data, err := c.ServiceProjectAccount.GetProjectInfo(projectId)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	} else {
+		c.Ctx.JSON(iris.Map{"code": 0, "msg": "操作成功", "data": data})
+	}
+}
+
 // @Summary 保存项目信息
 // @Tags 项目设置-管理员
 // @Description 保存项目信息

+ 146 - 0
web/api/rule_api.go

@@ -0,0 +1,146 @@
+/*
+ * @description: 编号规则
+ * @Author: LanJianRong
+ * @Date: 2020-11-27
+ * @FilePath: \construction_management\web\api\rule_api.go
+ */
+
+package api
+
+import (
+	"github.com/kataras/iris/v12"
+	"go.mod/services"
+	"go.mod/web/utils"
+)
+
+type RuleApi struct {
+	//框架-web应用上下文环境
+	Ctx iris.Context
+	// 需要用的service
+	RuleService services.RuleService
+}
+
+// @Summary 获取编号规则
+// @Tags 编号规则
+// @Description 获得制定pid、bid的编号规则
+// @Accept  json
+// @Produce  json
+// @Security ApiKeyAuth
+// @Param   bidsectionId     path    string     true        "标段ID"
+// @Param   projectId     path    string     true        "项目ID"
+// @Success 200 {object} viewmodels.ViewRule "{code:0成功,data:viewmodels.Safe,msg:请求成功}"
+// @Failure 400 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
+// @Router /api/rule [get]
+func (c *RuleApi) Get() {
+	// 1.规则验证
+	safeData, err := c.RuleService.ValidRule(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
+		return
+	}
+	pid, err := utils.GetProjectId(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "项目id不存在, 请重新登录"})
+		return
+	}
+	bidsectionId, err := utils.GetDecryptId(safeData.BidsectionId)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
+		return
+	}
+
+	rule := c.RuleService.Get(pid, bidsectionId)
+
+	c.Ctx.JSON(iris.Map{
+		"code": 0,
+		"msg":  "请求成功",
+		"data": rule,
+	})
+}
+
+// @Summary 提交编号规则
+// @Tags 编号规则
+// @Description 提交规则
+// @Accept  json
+// @Produce  json
+// @Security ApiKeyAuth
+// @Param   bidsectionId     body    string     true        "标段ID"
+// @Param   type 			body     string  true   "规则类型" eg:"safeRule、qualityRule、contractRule"
+// @Param   value 			body     string  true   "编号规则" eg:"'['202011', 'cc3']'"
+// @Success 200 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
+// @Failure 400 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
+// @Router /api/rule [post]
+func (c *RuleApi) Post() {
+	// 1.规则验证
+	safeData, err := c.RuleService.ValidRule(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
+		return
+	}
+	pid, err := utils.GetProjectId(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "项目id不存在, 请重新登录"})
+		return
+	}
+	bidsectionId, err := utils.GetDecryptId(safeData.BidsectionId)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
+		return
+	}
+
+	err = c.RuleService.Post(pid, bidsectionId, safeData.Type, safeData.Rule)
+	if err == nil {
+		c.Ctx.JSON(iris.Map{
+			"code": 0,
+			"msg":  "请求成功",
+		})
+	} else {
+		c.Ctx.JSON(iris.Map{
+			"code": -1,
+			"msg":  err,
+		})
+	}
+}
+
+// @Summary 生成编号
+// @Tags 编号规则
+// @Description 提交规则
+// @Accept  json
+// @Produce  json
+// @Security ApiKeyAuth
+// @Param   bidsectionId     body    string     true        "标段ID"
+// @Param   type 			body     string  true   "规则类型" eg:"safeRule、qualityRule、contractRule"
+// @Success 200 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
+// @Failure 400 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
+// @Router /api/rule/auto [post]
+func (c *RuleApi) PostAuto() {
+	// 1.规则验证
+	safeData, err := c.RuleService.ValidRule(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
+		return
+	}
+	pid, err := utils.GetProjectId(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "项目id不存在, 请重新登录"})
+		return
+	}
+	bidsectionId, err := utils.GetDecryptId(safeData.BidsectionId)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
+		return
+	}
+	code, err := c.RuleService.AutoCode(bidsectionId, pid, safeData.Type)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{
+			"code": -1,
+			"msg":  err,
+		})
+	} else {
+		c.Ctx.JSON(iris.Map{
+			"code": 0,
+			"msg":  "请求成功",
+			"data": code,
+		})
+	}
+}

+ 13 - 12
web/api/safe_api.go

@@ -39,7 +39,7 @@ func (c *SafeApi) Get() {
 	// 1.规则验证
 	safeData, err := c.ServiceSafe.ValidRule(c.Ctx)
 	if err != nil {
-		c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
 		return
 	}
 	pid, err := utils.GetProjectId(c.Ctx)
@@ -62,7 +62,7 @@ func (c *SafeApi) Get() {
 	})
 }
 
-// @Summary 安全巡检列表
+// @Summary 创建新的安全巡检记录
 // @Tags 安全巡检
 // @Description 创建新的安全巡检记录
 // @Accept  json
@@ -79,8 +79,9 @@ func (c *SafeApi) Get() {
 func (c *SafeApi) Post() {
 	// 1.规则验证
 	safeData, err := c.ServiceSafe.ValidRule(c.Ctx)
+	fmt.Println("-------------------------------", err)
 	if err != nil {
-		c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
 		return
 	}
 	bidsectionId, err := utils.GetDecryptId(safeData.BidsectionId)
@@ -103,13 +104,13 @@ func (c *SafeApi) Post() {
 		c.Ctx.JSON(iris.Map{"code": -1, "msg": "日期转换异常,请检查参数"})
 		return
 	}
-	fmt.Println(createTime)
+	// fmt.Println(createTime)
 	data.CreateTime = createTime
-	err1 := c.ServiceSafe.Post(data)
+	err = c.ServiceSafe.Post(data)
 	if err != nil {
 		c.Ctx.JSON(iris.Map{
 			"code": -1,
-			"msg":  err1,
+			"msg":  fmt.Sprintf("%s", err),
 		})
 		return
 	}
@@ -119,7 +120,7 @@ func (c *SafeApi) Post() {
 	})
 }
 
-// @Summary 安全巡检列表
+// @Summary 删除记录
 // @Tags 安全巡检
 // @Description 删除安全巡检记录
 // @Accept  json
@@ -141,11 +142,11 @@ func (c *SafeApi) Delete() {
 		return
 	}
 
-	err1 := c.ServiceSafe.Del(id)
-	if err1 != nil {
+	err = c.ServiceSafe.Del(id)
+	if err != nil {
 		c.Ctx.JSON(iris.Map{
 			"code": -1,
-			"msg":  err1,
+			"msg":  fmt.Sprintf("%s", err),
 		})
 		return
 	}
@@ -155,7 +156,7 @@ func (c *SafeApi) Delete() {
 	})
 }
 
-// @Summary 安全巡检列表
+// @Summary 获取安全巡检详情
 // @Tags 安全巡检
 // @Description 获得安全巡检详情页面数据
 // @Accept  json
@@ -169,7 +170,7 @@ func (c *SafeApi) GetDetail() {
 	// 1.规则验证
 	safeData, err := c.ServiceSafe.ValidRule(c.Ctx)
 	if err != nil {
-		c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
 		return
 	}
 

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 2526 - 0
web/docs/docs.go


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 2462 - 0
web/docs/swagger.json


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 1578 - 0
web/docs/swagger.yaml


+ 13 - 6
web/routes/routes.go

@@ -24,8 +24,9 @@ func Configure(b *bootstrap.Bootstrapper) {
 	BidsectionService := services.NewBidsectionService()
 	BidAccountService := services.NewBidAccountService()
 	ContractService := services.NewContractService()
-	RpcService := services.NewRpcService()
+	// RpcService := services.NewRpcService()
 	SafeService := services.NewSafeService()
+	RuleService := services.NewRuleService()
 	//CSRF相关
 	b.Use(middleware.SetCsrf)
 
@@ -125,11 +126,11 @@ func Configure(b *bootstrap.Bootstrapper) {
 	apiContract.Handle(new(api.ContractApi))
 
 	// rpc相关
-	rpc := mvc.New(b.Party("/api/rpc/test"))
-	rpc.Register(RpcService)
-	rpc.Router.Use(middleware.SessionsAuth)
-	rpc.Router.Use(middleware.AccessAuth)
-	rpc.Handle(new(api.RpcApi))
+	// rpc := mvc.New(b.Party("/api/rpc/test"))
+	// rpc.Register(RpcService)
+	// rpc.Router.Use(middleware.SessionsAuth)
+	// rpc.Router.Use(middleware.AccessAuth)
+	// rpc.Handle(new(api.RpcApi))
 
 	// safe
 	apiSafe := mvc.New(b.Party("/api/safe"))
@@ -138,4 +139,10 @@ func Configure(b *bootstrap.Bootstrapper) {
 	apiSafe.Router.Use(middleware.AccessAuth)
 	apiSafe.Handle(new(api.SafeApi))
 
+	// rule
+	apiRule := mvc.New(b.Party("/api/rule"))
+	apiRule.Register(RuleService)
+	apiRule.Router.Use(middleware.SessionsAuth)
+	apiRule.Router.Use(middleware.AccessAuth)
+	apiRule.Handle(new(api.RuleApi))
 }

+ 27 - 0
web/utils/utils.go

@@ -8,6 +8,7 @@ package utils
 
 import (
 	"errors"
+	"fmt"
 	"strconv"
 	"strings"
 
@@ -72,6 +73,32 @@ func GetDecryptId(id string) (int, error) {
 	return idInt, nil
 }
 
+// 生成code
+func CreateRuleCode(code int64, count int64, len int) string {
+	fmt.Println("code:", code, "count", count, "len", len)
+	// fmt.Println("rule", rule, "counts", count)
+	// egRule := strings.Split(rule.Eg, "-")
+	// for _, value := range egRule {
+	// 	if strings.Contains(value, "_") {
+	// 		// fmt.Println("rule", rule.Code, count)
+	// 		code := fmt.Printf("%0*d", rule.Code, count+1)
+
+	// 		strings.Replace(rule.Eg, )
+
+	// 	}
+	// }
+	// fmt.Println("egRule:", egRule)
+	// return "123"
+	// var newCode string
+	if code == 0 {
+		a := fmt.Sprintf("%0*d", len, count)
+		return a
+	} else {
+		b := fmt.Sprintf("%0*d", len, count+code)
+		return b
+	}
+}
+
 // // 获得项目ID
 // func GetProjectId(ctx iris.Context) (int, error) {
 // 	jwtInfo := ctx.Values().Get("jwt").(*jwt.Token)

+ 7 - 0
web/viewmodels/project.go

@@ -13,6 +13,13 @@ type Project struct {
 	Code string `form:"code" json:"code"`
 	Name string `form:"name" json:"name"`
 }
+type ProjectInfo struct {
+	ProjectName string `from:"projectName" json:"projectName"`
+	Code        string `from:"code" json:"code"`
+	CreateTime  int    `from:"create_time" json:"createTime"`
+	Mobile      string `from:"mobile" json:"mobile"`
+	Name        string `from:"name" json:"name"`
+}
 
 func (l Project) Validate() error {
 	return validation.ValidateStruct(&l,

+ 53 - 0
web/viewmodels/rule.go

@@ -0,0 +1,53 @@
+package viewmodels
+
+import validation "github.com/go-ozzo/ozzo-validation/v3"
+
+/*
+ * @description: 编号规则
+ * @Author: LanJianRong
+ * @Date: 2020-11-27
+ * @FilePath: \construction_management\web\viewmodels\safe.go
+ */
+
+type Rule struct {
+	Id           string `form:"id" json:"id" `
+	ProjectId    string `form:"projectId" json:"projectId" `
+	BidsectionId string `form:"bidsectionId" json:"bidsectionId" `
+	SafeRule     string `form:"safeRule" json:"safeRule" `
+	QualityRule  string `form:"qualityRule" json:"qualityRule" `
+	ContractRule string `form:"contractRule" json:"contractRule" `
+}
+
+// 页面所需字段
+type ViewRule struct {
+	SafeRule     string `form:"safeRule" json:"safeRule" `
+	QualityRule  string `form:"qualityRule" json:"qualityRule" `
+	ContractRule string `form:"contractRule" json:"contractRule" `
+}
+
+type ValidField struct {
+	BidsectionId string `form:"bidsectionId" json:"bidsectionId" `
+	Type         string `form:"type" json:"type"`
+	Rule         string `form:"rule" json:"rule"`
+}
+
+type RuleCode struct {
+	Eg   string `from:"eg" json:"eg"`
+	Date string `from:"date" json:"date"`
+	Text string `from:"text" json:"text"`
+	Name string `from:"name" json:"name"`
+	Code string `from:"code" json:"code"`
+}
+
+func (l ValidField) Validate() error {
+	return validation.ValidateStruct(&l,
+		validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
+	)
+}
+
+func (l ValidField) ValidateAuto() error {
+	return validation.ValidateStruct(&l,
+		validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
+		validation.Field(&l.Type, validation.Required.Error("类型不能为空")),
+	)
+}