Explorar o código

自动添加考察单位

zk %!s(int64=2) %!d(string=hai) anos
pai
achega
6ec6654309
Modificáronse 2 ficheiros con 37 adicións e 6 borrados
  1. 35 6
      server/api/v1/autocode/problem_info.go
  2. 2 0
      server/model/autocode/unit.go

+ 35 - 6
server/api/v1/autocode/problem_info.go

@@ -46,8 +46,9 @@ func (problemInfoApi *ProblemInfoApi) CreateProblemInfo(c *gin.Context) {
 		problemInfo.Region = place.Region
 	}
 
-	if problemInfo.UnitId != nil && *problemInfo.UnitId != 0 {
+	if problemInfo.Department != "" {
 		probleTypeIds := strings.Split(problemInfo.Matter, "|")
+		//计算分值
 		if len(probleTypeIds) > 0 {
 			_, proTypes := problemTypeService.GetProblemTypeIds(probleTypeIds)
 			var integral int
@@ -58,12 +59,40 @@ func (problemInfoApi *ProblemInfoApi) CreateProblemInfo(c *gin.Context) {
 			problemInfo.Integral = &integral
 		}
 		// 发送问题到负责人
-		if err, unituser := unitUserService.GetUnitUsers(problemInfo.UnitId); err != nil {
-			source := make([]string, 0)
-			for _, item := range unituser {
-				source = append(source, item.UUID)
+		departmentIds := strings.Split(problemInfo.Department, "|")
+		for _, unitId := range departmentIds {
+			id, _ := strconv.Atoi(unitId)
+			if err, unitPlaces := unitPlaceService.GetUnitPlaces(&id); err != nil {
+				unitPlaceService.CreateUnitPlace(autocode.UnitPlace{UnitId: &id, PlaceId: strconv.Itoa(int(problemInfo.SiteId))})
+				ids := []string{unitId}
+				sum := placeService.FindPlaceSum(ids)
+				unitService.UpdateUnitMaxIntegral(&id, sum)
+			} else {
+				isA := true
+				for _, unitPlace := range unitPlaces {
+					if unitPlace.PlaceId == strconv.Itoa(int(problemInfo.SiteId)) {
+						isA = false
+					}
+				}
+				if isA {
+					placeIds := make([]string, 0)
+					for _, places := range unitPlaces {
+						placeIds = append(placeIds, places.PlaceId)
+					}
+					placeIds = append(placeIds, strconv.Itoa(int(problemInfo.SiteId)))
+					sum := placeService.FindPlaceSum(placeIds)
+					unitService.UpdateUnitMaxIntegral(&id, sum)
+					unitPlaceService.CreateUnitPlace(autocode.UnitPlace{UnitId: &id, PlaceId: strconv.Itoa(int(problemInfo.SiteId))})
+				}
+			}
+
+			if err, unituser := unitUserService.GetUnitUsers(&id); err != nil {
+				source := make([]string, 0)
+				for _, item := range unituser {
+					source = append(source, item.UUID)
+				}
+				SendMsg(autocodeReq.SendUser{ProblemID: problemInfo.ID, ID: source}, true)
 			}
-			SendMsg(autocodeReq.SendUser{ProblemID: problemInfo.ID, ID: source}, true)
 		}
 
 	}

+ 2 - 0
server/model/autocode/unit.go

@@ -14,6 +14,8 @@ type Unit struct {
 	UnitIntegral    *int   `json:"unitIntegral" form:"unitIntegral" gorm:"column:unit_integral;comment:现有积分;type:int"`
 	UnitMaxIntegral *int   `json:"unitMaxIntegral" form:"unitMaxIntegral" gorm:"column:unit_max_integral;comment:满分;type:int"`
 	Remark          string `json:"remark" form:"remark" gorm:"column:remark;comment:单位类型;type:varchar(600);"`
+	//Place           Place   `json:"place" gorm:"foreignKey:PlaceId;references:PlaceId;comment:点位id"`
+	//Places          []Place `json:"places" gorm:"many2many:place;"`
 }
 
 // TableName Unit 表名