shenzekai 2 years ago
parent
commit
1e7ca1adc3
3 changed files with 90 additions and 42 deletions
  1. 3 3
      db/default.go
  2. 2 1
      model/gorm_model/contract_info.go
  3. 85 38
      service/project.go

+ 3 - 3
db/default.go

@@ -253,7 +253,7 @@ func GetTaskTerminatingList(ctx context.Context, projectID string, pageSize, pag
 	var totalTerminating int64
 	var TerminatingInfos []gorm_model.YoungeeContractInfo
 	db = db.Model(gorm_model.YoungeeContractInfo{})
-	err := db.Where("default_status = 3").Find(&TerminatingInfos).Error
+	err := db.Where("default_status = 3 AND project_id=?", projectID).Find(&TerminatingInfos).Error
 	if err != nil {
 		logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
 		return nil, 0, err
@@ -282,7 +282,7 @@ func GetTaskTerminatingList(ctx context.Context, projectID string, pageSize, pag
 		value := conditionValue.FieldByName(field.Name)
 		if tag == "default_status" {
 			if value.Interface() == int64(4) {
-				db = db.Where("cur_default_type = 9")
+				db1 = db1.Where("cur_default_type = 9")
 			}
 			continue
 		} else if !util.IsBlank(value) {
@@ -290,7 +290,7 @@ func GetTaskTerminatingList(ctx context.Context, projectID string, pageSize, pag
 				platform_nickname = fmt.Sprintf("%v", value.Interface())
 				continue
 			} else if tag == "project_id" || tag == "strategy_id" {
-				db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
+				db1 = db1.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
 			}
 		}
 	}

+ 2 - 1
model/gorm_model/contract_info.go

@@ -7,7 +7,8 @@ import (
 
 type YoungeeContractInfo struct {
 	ContractID       int       `gorm:"column:contract_id;primary_key;AUTO_INCREMENT"` // 合约id
-	TaskID           string       `gorm:"column:task_id;NOT NULL"`                       // 任务id
+	TaskID           string    `gorm:"column:task_id;NOT NULL"`                       // 任务id
+	ProjectID        string    `gorm:"column:project_id;NOT NULL"`                    // 任务所属项目id
 	BreakType        int       `gorm:"column:break_type;NOT NULL"`                    // 违约类型(4类严重违约):1(脚本)2(初稿)3(链接)4(数据)
 	SettlementAmount float64   `gorm:"column:settlement_amount;NOT NULL"`             // 应结算金额
 	BreakAt          time.Time `gorm:"column:break_at"`                               // 违约时间

+ 85 - 38
service/project.go

@@ -41,6 +41,7 @@ func (*project) Create(ctx context.Context, newProject http_model.CreateProjectR
 	if err != nil {
 		return nil, err
 	}
+
 	AutoDefaultID, err := db.GetLastAutoDefaultID()
 	if err != nil {
 		return nil, err
@@ -67,7 +68,10 @@ func (*project) Create(ctx context.Context, newProject http_model.CreateProjectR
 	}
 	feeFroms := strings.Join(feeFrom, ",")
 	//fmt.Printf("创建项目new %+v", newProject)
-	RecruitDdl, _ := time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
+	RecruitDdl := time.Time{} //赋零值
+	if newProject.RecruitDdl != "" {
+		RecruitDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
+	}
 	fmt.Println("Create RecruitDdl:", newProject.RecruitDdl, RecruitDdl)
 	projectInfo := gorm_model.ProjectInfo{}
 	rand.Seed(time.Now().UnixNano())
@@ -79,26 +83,50 @@ func (*project) Create(ctx context.Context, newProject http_model.CreateProjectR
 		td = "0" + td
 	}
 	if newProject.ProjectType == int64(1) {
-		projectInfo = gorm_model.ProjectInfo{
-			ProjectID:        conv.MustString(time.Now().Year())[2:] + td + conv.MustString(rand.Intn(100000-10000)+10000),
-			ProjectName:      projectName,
-			ProjectStatus:    1,
-			ProjectType:      newProject.ProjectType,
-			TalentType:       newProject.TalentType,
-			ProjectPlatform:  newProject.ProjectPlatform,
-			ProjectForm:      newProject.ProjectForm,
-			RecruitDdl:       &RecruitDdl,
-			ProjectDetail:    newProject.ProjectDetail,
-			ContentType:      newProject.ContentType,
-			EnterpriseID:     enterpriseID,
-			ProductID:        newProject.ProductID,
-			FeeForm:          feeFroms,
-			AutoTaskID:       conv.MustInt64(AutoTaskID),
-			AutoDefaultID:    conv.MustInt64(AutoDefaultID),
-			EstimatedCost:    ECost,
-			IsRead:           0,
-			ProductSnap:      string(productInfoToJson),
-			ProductPhotoSnap: string(productPhotosToJson),
+		// 没有填写DDL
+		if newProject.RecruitDdl == "" {
+			projectInfo = gorm_model.ProjectInfo{
+				ProjectID:        conv.MustString(time.Now().Year())[2:] + td + conv.MustString(rand.Intn(100000-10000)+10000),
+				ProjectName:      projectName,
+				ProjectStatus:    1,
+				ProjectType:      newProject.ProjectType,
+				TalentType:       newProject.TalentType,
+				ProjectPlatform:  newProject.ProjectPlatform,
+				ProjectForm:      newProject.ProjectForm,
+				ProjectDetail:    newProject.ProjectDetail,
+				ContentType:      newProject.ContentType,
+				EnterpriseID:     enterpriseID,
+				ProductID:        newProject.ProductID,
+				FeeForm:          feeFroms,
+				AutoTaskID:       conv.MustInt64(AutoTaskID),
+				AutoDefaultID:    conv.MustInt64(AutoDefaultID),
+				EstimatedCost:    ECost,
+				IsRead:           0,
+				ProductSnap:      string(productInfoToJson),
+				ProductPhotoSnap: string(productPhotosToJson),
+			}
+		} else {
+			projectInfo = gorm_model.ProjectInfo{
+				ProjectID:        conv.MustString(time.Now().Year())[2:] + td + conv.MustString(rand.Intn(100000-10000)+10000),
+				ProjectName:      projectName,
+				ProjectStatus:    1,
+				ProjectType:      newProject.ProjectType,
+				TalentType:       newProject.TalentType,
+				ProjectPlatform:  newProject.ProjectPlatform,
+				ProjectForm:      newProject.ProjectForm,
+				RecruitDdl:       &RecruitDdl,
+				ProjectDetail:    newProject.ProjectDetail,
+				ContentType:      newProject.ContentType,
+				EnterpriseID:     enterpriseID,
+				ProductID:        newProject.ProductID,
+				FeeForm:          feeFroms,
+				AutoTaskID:       conv.MustInt64(AutoTaskID),
+				AutoDefaultID:    conv.MustInt64(AutoDefaultID),
+				EstimatedCost:    ECost,
+				IsRead:           0,
+				ProductSnap:      string(productInfoToJson),
+				ProductPhotoSnap: string(productPhotosToJson),
+			}
 		}
 	} else {
 		projectInfo = gorm_model.ProjectInfo{
@@ -145,7 +173,7 @@ func (*project) Create(ctx context.Context, newProject http_model.CreateProjectR
 		}
 	}
 	// build
-	if newProject.ProjectType == int64(1) {
+	if newProject.ProjectType == int64(1) && newProject.RecruitStrategys != nil {
 		recruitStrategys := []gorm_model.RecruitStrategy{}
 		for _, strategy := range newProject.RecruitStrategys {
 			// 查询对应定价策略
@@ -182,7 +210,10 @@ func (*project) Create(ctx context.Context, newProject http_model.CreateProjectR
 	return res, nil
 }
 func (*project) Update(ctx context.Context, newProject http_model.UpdateProjectRequest, enterpriseID string) (*http_model.UpdateProjectData, error) {
-	RecruitDdl, _ := time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
+	RecruitDdl := time.Time{} //赋零值
+	if newProject.RecruitDdl != "" {
+		RecruitDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
+	}
 	fmt.Println("Update RecruitDdl:", newProject.RecruitDdl, RecruitDdl)
 	oldProject, err3 := db.GetProjectDetail(ctx, newProject.ProjectID)
 	if err3 != nil {
@@ -195,7 +226,7 @@ func (*project) Update(ctx context.Context, newProject http_model.UpdateProjectR
 		//feeForm += string(strategy.StrategyID)
 	}
 	var ECost float64 = 0
-	if newProject.ProjectType == int64(1) {
+	if newProject.ProjectType == int64(1) && newProject.RecruitStrategys != nil {
 		for _, strategy := range newProject.RecruitStrategys {
 			// 计算预估成本
 			var tmpCost float64 = 0
@@ -209,18 +240,34 @@ func (*project) Update(ctx context.Context, newProject http_model.UpdateProjectR
 	}
 	feeFroms := strings.Join(feeFrom, ",")
 	t := time.Now()
-	project := gorm_model.ProjectInfo{
-		ProjectID:     newProject.ProjectID,
-		RecruitDdl:    &RecruitDdl,
-		TalentType:    newProject.TalentType,
-		ContentType:   conv.MustInt64(newProject.ContentType),
-		ProjectDetail: newProject.ProjectDetail,
-		ProjectForm:   conv.MustInt64(newProject.ProjectForm),
-		EnterpriseID:  enterpriseID,
-		ProjectStatus: conv.MustInt64(newProject.ProjectStatus),
-		FeeForm:       feeFroms,
-		EstimatedCost: ECost,
-		SubmitAt:      &t,
+	project := gorm_model.ProjectInfo{}
+	if newProject.RecruitDdl == "" {
+		project = gorm_model.ProjectInfo{
+			ProjectID:     newProject.ProjectID,
+			TalentType:    newProject.TalentType,
+			ContentType:   conv.MustInt64(newProject.ContentType),
+			ProjectDetail: newProject.ProjectDetail,
+			ProjectForm:   conv.MustInt64(newProject.ProjectForm),
+			EnterpriseID:  enterpriseID,
+			ProjectStatus: conv.MustInt64(newProject.ProjectStatus),
+			FeeForm:       feeFroms,
+			EstimatedCost: ECost,
+			SubmitAt:      &t,
+		}
+	} else {
+		project = gorm_model.ProjectInfo{
+			ProjectID:     newProject.ProjectID,
+			RecruitDdl:    &RecruitDdl,
+			TalentType:    newProject.TalentType,
+			ContentType:   conv.MustInt64(newProject.ContentType),
+			ProjectDetail: newProject.ProjectDetail,
+			ProjectForm:   conv.MustInt64(newProject.ProjectForm),
+			EnterpriseID:  enterpriseID,
+			ProjectStatus: conv.MustInt64(newProject.ProjectStatus),
+			FeeForm:       feeFroms,
+			EstimatedCost: ECost,
+			SubmitAt:      &t,
+		}
 	}
 	projectID, err := db.UpdateProject(ctx, project)
 	if err != nil {
@@ -253,8 +300,8 @@ func (*project) Update(ctx context.Context, newProject http_model.UpdateProjectR
 	if err != nil {
 		return nil, err
 	}
-	fmt.Printf("策略:\t %+v", newProject.RecruitStrategys)
-	if newProject.RecruitStrategys != nil && newProject.ProjectType == int64(1) {
+	fmt.Printf("策略:\t %+v,%+v", newProject.RecruitStrategys, len(newProject.RecruitStrategys) == 0)
+	if len(newProject.RecruitStrategys) != 0 && newProject.ProjectType == int64(1) {
 		// 新增策略
 		RecruitStrategys := []gorm_model.RecruitStrategy{}
 		for _, Strategy := range newProject.RecruitStrategys {