|
@@ -1,23 +1,46 @@
|
|
|
package com.yaoxiang.planning.service
|
|
|
|
|
|
import com.yaoxiang.planning.domain.PlanningItem
|
|
|
-import com.yaoxiang.planning.model.PlanStatus
|
|
|
+import com.yaoxiang.planning.model.PlanningStatus
|
|
|
+import com.yaoxiang.planning.model.PlanningType
|
|
|
+import com.yaoxiang.planning.repository.AnnualPlanRepo
|
|
|
import com.yaoxiang.planning.repository.PlanningItemRepo
|
|
|
+import com.yaoxiang.planning.repository.QuarterlyPlanRepo
|
|
|
+import mu.KotlinLogging
|
|
|
import org.springframework.beans.factory.annotation.Autowired
|
|
|
import org.springframework.stereotype.Service
|
|
|
import java.util.*
|
|
|
|
|
|
+private val logger = KotlinLogging.logger { }
|
|
|
+
|
|
|
@Service
|
|
|
class PlanningItemService {
|
|
|
|
|
|
@Autowired
|
|
|
private lateinit var planningItemRepo: PlanningItemRepo
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private lateinit var departmentService: DepartmentService
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private lateinit var quarterlyPlanRepo: QuarterlyPlanRepo
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private lateinit var annualPlanRepo: AnnualPlanRepo
|
|
|
+
|
|
|
fun addItem(planningItem: PlanningItem): Boolean {
|
|
|
if (planningItem.type == null || planningItem.planningId == null) {
|
|
|
+ logger.error { "add item fail,type=${planningItem.type},planningId=${planningItem.type}" }
|
|
|
return false
|
|
|
}
|
|
|
- planningItem.status = PlanStatus.READY.ordinal
|
|
|
+ if (!checkAndSetDefault(planningItem)) {
|
|
|
+ logger.error { "check planning fail,planningId=${planningItem.planningId},type=${planningItem.type}" }
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if (planningItem.departmentId != null) {
|
|
|
+ planningItem.departmentName = departmentService.getName(planningItem.departmentId)
|
|
|
+ }
|
|
|
+ planningItem.status = PlanningStatus.READY.ordinal
|
|
|
planningItemRepo.save(planningItem)
|
|
|
return true
|
|
|
}
|
|
@@ -65,20 +88,42 @@ class PlanningItemService {
|
|
|
return planningItemRepo.findById(id)
|
|
|
}
|
|
|
|
|
|
- fun update(id: Long, name: String, content: String, status: Int, remark: String?): Boolean {
|
|
|
+ fun update(id: Long, name: String, content: String, status: Int, remark: String?, departmentId: Long?): Boolean {
|
|
|
val optional = get(id)
|
|
|
if (optional.isPresent) {
|
|
|
val item = optional.get()
|
|
|
item.name = name
|
|
|
item.content = content
|
|
|
item.status = status
|
|
|
+ item.departmentId = departmentId
|
|
|
item.remark = remark
|
|
|
+ if (departmentId != null) {
|
|
|
+ item.departmentName = departmentService.getName(departmentId)
|
|
|
+ }
|
|
|
planningItemRepo.save(item)
|
|
|
return true
|
|
|
}
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
+ private fun checkAndSetDefault(item: PlanningItem): Boolean {
|
|
|
+ when (item.type!!) {
|
|
|
+ PlanningType.ANNUAL.ordinal -> {
|
|
|
+ val optional = annualPlanRepo.findById(item.planningId!!)
|
|
|
+ return optional.isPresent
|
|
|
+ }
|
|
|
+ PlanningType.QUARTERLY.ordinal -> {
|
|
|
+ val optional = quarterlyPlanRepo.findById(item.planningId!!)
|
|
|
+ if (optional.isPresent && item.departmentId == null) {
|
|
|
+ //设置默认的部门Id
|
|
|
+ item.departmentId = optional.get().departmentId
|
|
|
+ }
|
|
|
+ return optional.isPresent
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
fun evaluate(id: Long, evaluation: String): Boolean {
|
|
|
val optional = get(id)
|
|
|
if (optional.isPresent) {
|
|
@@ -90,5 +135,4 @@ class PlanningItemService {
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
-
|
|
|
}
|