Browse Source

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

caipin 4 years ago
parent
commit
2b75dc8ab7

+ 1 - 1
dao/project_account_dao.go

@@ -137,6 +137,6 @@ func (d *ProjectAccountDao) Delete(data *models.CmProjectAccount) error {
 // 查找
 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)
+	_, err := d.engine.Sql("select p.`name` as project_name, 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
 }

+ 13 - 4
services/project_service.go

@@ -47,10 +47,19 @@ func NewProjectService() ProjectService {
 // 验证项目项的内容
 func (s *projectService) ValidRule(ctx iris.Context) (viewmodels.Project, error) {
 	projectVaild := viewmodels.Project{}
-	err := ctx.ReadForm(&projectVaild)
-	if err != nil {
-		log.Println("project-ValidRule-ReadForm转换异常, error=", err)
-		return projectVaild, err
+	var err error
+	if ctx.Method() == "POST" {
+		err = ctx.ReadJSON(&projectVaild)
+		if err != nil {
+			log.Println("project-ValidRule-ReadForm转换异常, error=", err)
+			return projectVaild, err
+		}
+	} else {
+		err = ctx.ReadForm(&projectVaild)
+		if err != nil {
+			log.Println("project-ValidRule-ReadForm转换异常, error=", err)
+			return projectVaild, err
+		}
 	}
 
 	if ctx.Path() == s.validSave {

+ 3 - 12
services/rule_service.go

@@ -62,17 +62,17 @@ func (s *ruleService) AutoCode(bid int, pid int, codeType string) (string, error
 	// 获取该标段的规则
 	rule := s.daoRule.FindByPidWithBid(pid, bid)
 	if codeType == "safeRule" {
+		if rule.SafeRule == "" {
+			return "", errors.New("该标段未设置编号规则!")
+		}
 		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))
 				}
@@ -82,15 +82,6 @@ func (s *ruleService) AutoCode(bid int, pid int, codeType string) (string, error
 			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
 		}
 	}

+ 4 - 2
web/api/rule_api.go

@@ -8,6 +8,8 @@
 package api
 
 import (
+	"fmt"
+
 	"github.com/kataras/iris/v12"
 	"go.mod/services"
 	"go.mod/web/utils"
@@ -97,7 +99,7 @@ func (c *RuleApi) Post() {
 	} else {
 		c.Ctx.JSON(iris.Map{
 			"code": -1,
-			"msg":  err,
+			"msg":  fmt.Sprintf("%s", err),
 		})
 	}
 }
@@ -134,7 +136,7 @@ func (c *RuleApi) PostAuto() {
 	if err != nil {
 		c.Ctx.JSON(iris.Map{
 			"code": -1,
-			"msg":  err,
+			"msg":  fmt.Sprintf("%s", err),
 		})
 	} else {
 		c.Ctx.JSON(iris.Map{

+ 7 - 2
web/viewmodels/project.go

@@ -6,7 +6,11 @@
  */
 package viewmodels
 
-import validation "github.com/go-ozzo/ozzo-validation/v3"
+import (
+	"fmt"
+
+	validation "github.com/go-ozzo/ozzo-validation/v3"
+)
 
 type Project struct {
 	Id   string `form:"id" json:"id"`
@@ -14,7 +18,7 @@ type Project struct {
 	Name string `form:"name" json:"name"`
 }
 type ProjectInfo struct {
-	ProjectName string `from:"projectName" json:"projectName"`
+	ProjectName string `from:"project_name" json:"projectName"`
 	Code        string `from:"code" json:"code"`
 	CreateTime  int    `from:"create_time" json:"createTime"`
 	Mobile      string `from:"mobile" json:"mobile"`
@@ -30,6 +34,7 @@ func (l Project) Validate() error {
 }
 
 func (l Project) ValidateName() error {
+	fmt.Println(l)
 	return validation.ValidateStruct(&l,
 		// 字符的4倍
 		validation.Field(&l.Name, validation.Required.Error("项目名称不能为空"), validation.Length(1, 512).Error("最多 128 个字")),