Browse Source

feat: 1111

lanjianrong 4 years ago
parent
commit
b105b7c6d5
4 changed files with 48 additions and 24 deletions
  1. 2 2
      dao/contract_dao.go
  2. 3 1
      dao/rule_dao.go
  3. 32 12
      services/rule_service.go
  4. 11 9
      web/viewmodels/rule.go

+ 2 - 2
dao/contract_dao.go

@@ -370,9 +370,9 @@ func (d *ContractDao) Unlock(projectId int, bidsectionId int, treeId int, id int
 }
 
 // 筛选出应用了当前规则的条数
-func (d *ContractDao) CountRuleCode(bid int) (int64, error) {
+func (d *ContractDao) CountRuleCode(bid int, contractType int) (int64, error) {
 	data := &models.CmContracts{}
-	total, err := d.engine.Where("`bidsection_id` = ?", bid).Count(data)
+	total, err := d.engine.Where("`bidsection_id` = ? and `contracts_type` = ?", bid, contractType).Count(data)
 	if err != nil {
 		total = 0
 	}

+ 3 - 1
dao/rule_dao.go

@@ -46,8 +46,10 @@ func (d *RuleDao) UpdateOrCreate(pid int, bid int, key string, value string) err
 		data.SafeRule = value
 	} else if key == "quality_rule" {
 		data.QualityRule = value
+	} else if key == "contract_return_rule" {
+		data.ContractReturnRule = value
 	} else {
-		data.ContractRule = value
+		data.ContractPaidRule = value
 	}
 	// fmt.Println("newData", data, "value", value, "key", key)
 	if has && err == nil {

+ 32 - 12
services/rule_service.go

@@ -45,7 +45,7 @@ func NewRuleService() RuleService {
 
 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}
+	viewData := viewmodels.ViewRule{SafeRule: data.SafeRule, QualityRule: data.QualityRule, ContractPaidRule: data.ContractPaidRule, ContractReturnRule: data.ContractReturnRule}
 	return viewData
 }
 
@@ -54,15 +54,9 @@ func (s *ruleService) Post(pid int, id int, key string, value string) error {
 	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) {
+	fmt.Println("codeType---------------------------------------", codeType)
 	// 获取该标段的规则
 	rule := s.daoRule.FindByPidWithBid(pid, bid)
 	if codeType == "safeRule" {
@@ -88,14 +82,40 @@ func (s *ruleService) AutoCode(bid int, pid int, codeType string) (string, error
 			}
 			return string(e), err
 		}
-	} else if codeType == "contractRule" {
-		if rule.ContractRule == "" {
+	} else if codeType == "contractReturnRule" {
+		if rule.ContractReturnRule == "" {
+			return "", errors.New("该标段未设置编号规则!")
+		}
+		var code viewmodels.RuleCode
+		err := json.Unmarshal([]byte(rule.ContractReturnRule), &code)
+		if err == nil {
+			total, err := s.daoContract.CountRuleCode(bid, 0)
+			if err != nil {
+				return "", err
+			}
+			value := reflect.ValueOf(code)
+			for i := 0; i < value.NumField(); i++ {
+				b := fmt.Sprint(value.Field(i))
+				if b == code.Code {
+					k, _ := strconv.Atoi(b)
+					code.Code = utils.CreateRuleCode(int64(k), total, len(code.Code))
+				}
+			}
+
+			e, err := json.Marshal(code)
+			if err != nil {
+				return "", err
+			}
+			return string(e), err
+		}
+	} else if codeType == "contractPaidRule" {
+		if rule.ContractReturnRule == "" {
 			return "", errors.New("该标段未设置编号规则!")
 		}
 		var code viewmodels.RuleCode
-		err := json.Unmarshal([]byte(rule.ContractRule), &code)
+		err := json.Unmarshal([]byte(rule.ContractPaidRule), &code)
 		if err == nil {
-			total, err := s.daoContract.CountRuleCode(bid)
+			total, err := s.daoContract.CountRuleCode(bid, 1)
 			if err != nil {
 				return "", err
 			}

+ 11 - 9
web/viewmodels/rule.go

@@ -9,19 +9,21 @@ package viewmodels
 import validation "github.com/go-ozzo/ozzo-validation/v3"
 
 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" `
+	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" `
+	ContractReturnRule string `form:"contractReturnRule" json:"contractReturnRule" `
+	ContractPaidRule   string `form:"contractPaidRule" json:"contractPaidRule" `
 }
 
 // 页面所需字段
 type ViewRule struct {
-	SafeRule     string `form:"safeRule" json:"safeRule" `
-	QualityRule  string `form:"qualityRule" json:"qualityRule" `
-	ContractRule string `form:"contractRule" json:"contractRule" `
+	SafeRule           string `form:"safeRule" json:"safeRule" `
+	QualityRule        string `form:"qualityRule" json:"qualityRule" `
+	ContractReturnRule string `form:"contractReturnRule" json:"contractReturnRule" `
+	ContractPaidRule   string `form:"contractPaidRule" json:"contractPaidRule" `
 }
 
 type ValidField struct {