فهرست منبع

add annual api

Feick 4 سال پیش
والد
کامیت
b6e304560a

+ 1 - 1
src/main/kotlin/com/yaoxiang/planning/PlaningApplication.kt

@@ -7,5 +7,5 @@ import org.springframework.boot.runApplication
 class PlaningApplication
 
 fun main(args: Array<String>) {
-	runApplication<PlaningApplication>(*args)
+    runApplication<PlaningApplication>(*args)
 }

+ 49 - 1
src/main/kotlin/com/yaoxiang/planning/action/AnnualAction.kt

@@ -1,16 +1,64 @@
 package com.yaoxiang.planning.action
 
+import com.yaoxiang.planning.domain.AnnualPlan
+import com.yaoxiang.planning.model.Reply
 import com.yaoxiang.planning.service.AnnualPlanService
 import io.swagger.annotations.Api
+import io.swagger.annotations.ApiImplicitParam
+import io.swagger.annotations.ApiImplicitParams
+import io.swagger.annotations.ApiOperation
 import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.web.bind.annotation.GetMapping
+import org.springframework.web.bind.annotation.PostMapping
 import org.springframework.web.bind.annotation.RequestMapping
+import org.thymeleaf.util.DateUtils
+import java.util.*
 
 @Api(tags = ["年度计划"])
 @RequestMapping("annual")
-class AnnualAction{
+class AnnualAction {
 
     @Autowired
     private lateinit var annualPlanService: AnnualPlanService
 
+    @ApiOperation("添加年度计划")
+    @ApiImplicitParams(ApiImplicitParam(name = "name", value = "名称", paramType = "query"),
+            ApiImplicitParam(name = "content", value = "计划内容", paramType = "query"),
+            ApiImplicitParam(name = "year", value = "年份", paramType = "query"))
+    @PostMapping("add")
+    fun add(name: String, content: String, year: Int): Reply<Any> {
+        val result = annualPlanService.add(name, content, year)
+        return Reply(result)
+    }
+
+    @ApiOperation("更新年度计划")
+    @ApiImplicitParams(ApiImplicitParam(name = "id", value = "年度计划id", paramType = "query"),
+            ApiImplicitParam(name = "name", value = "名称", paramType = "query"),
+            ApiImplicitParam(name = "content", value = "计划内容", paramType = "query"),
+            ApiImplicitParam(name = "year", value = "年份", paramType = "query"))
+    @PostMapping("update")
+    fun update(id: Long, name: String, content: String, status: Int): Reply<Any> {
+        val result = annualPlanService.update(id, name, content, status)
+        return Reply(result)
+    }
+
+    @PostMapping("delete")
+    fun delete(id: Long): Reply<Any> {
+        val result = annualPlanService.delete(id)
+        return Reply(result)
+    }
+
+    @GetMapping("current")
+    fun get(year: Int? = null): Reply<AnnualPlan?> {
+        val y: Int = year ?: DateUtils.year(Date())
+        val optional = annualPlanService.findByYear(y)
+        return Reply(optional.isPresent, "", optional.orElse(null))
+    }
+
+    @GetMapping("list")
+    fun list(): Reply<List<AnnualPlan>> {
+        val list = annualPlanService.list()
+        return Reply.ok(list)
+    }
 
 }

+ 1 - 1
src/main/kotlin/com/yaoxiang/planning/action/DepartmentAction.kt

@@ -5,7 +5,7 @@ import io.swagger.annotations.Api
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.web.bind.annotation.RequestMapping
 
-@Api(tags=["部门"])
+@Api(tags = ["部门"])
 @RequestMapping("department")
 class DepartmentAction {
 

+ 16 - 0
src/main/kotlin/com/yaoxiang/planning/action/PlanningItemAction.kt

@@ -1,8 +1,12 @@
 package com.yaoxiang.planning.action
 
+import com.yaoxiang.planning.domain.PlanningItem
+import com.yaoxiang.planning.model.Reply
 import com.yaoxiang.planning.service.PlanningItemService
 import io.swagger.annotations.Api
 import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.web.bind.annotation.PostMapping
+import org.springframework.web.bind.annotation.RequestBody
 import org.springframework.web.bind.annotation.RequestMapping
 
 @Api(tags = ["分计划"])
@@ -12,4 +16,16 @@ class PlanningItemAction {
     @Autowired
     private lateinit var planningItemService: PlanningItemService
 
+    @PostMapping("addItem")
+    fun addItem(@RequestBody item: PlanningItem): Reply<Any> {
+        val result = planningItemService.addItem(item)
+        return Reply(result)
+    }
+
+    @PostMapping("addItems")
+    fun addItems(@RequestBody items: List<PlanningItem>): Reply<Any> {
+        val result = planningItemService.addItems(items)
+        return Reply(result)
+    }
+
 }

+ 0 - 2
src/main/kotlin/com/yaoxiang/planning/config/LoginSuccessHandler.kt

@@ -8,13 +8,11 @@ import java.io.IOException
 import javax.servlet.ServletException
 import javax.servlet.http.HttpServletRequest
 import javax.servlet.http.HttpServletResponse
-import kotlin.jvm.Throws
 
 private val logger = KotlinLogging.logger {}
 
 class LoginSuccessHandler : SavedRequestAwareAuthenticationSuccessHandler() {
 
-    @Throws(IOException::class, ServletException::class)
     override fun onAuthenticationSuccess(request: HttpServletRequest, response: HttpServletResponse, authentication: Authentication) {
         val loginFrom = request.getParameter("loginFrom")
         val user: AuthUser = authentication.principal as AuthUser

+ 3 - 2
src/main/kotlin/com/yaoxiang/planning/config/PlanningConfig.kt

@@ -7,9 +7,10 @@ import org.springframework.context.annotation.Configuration
 import javax.sql.DataSource
 
 @Configuration
-class PlanningConfig{
+class PlanningConfig {
 
-    @Bean //    @Profile("dev")
+    @Bean
+    //    @Profile("dev")
     @ConfigurationProperties("spring.datasource")
     fun dataSource(): DataSource {
         return DruidDataSource()

+ 0 - 1
src/main/kotlin/com/yaoxiang/planning/config/WebMvcConfig.kt

@@ -2,7 +2,6 @@ package com.yaoxiang.planning.config
 
 import org.springframework.context.annotation.Bean
 import org.springframework.context.annotation.Configuration
-import org.springframework.web.servlet.config.annotation.EnableWebMvc
 import org.springframework.web.servlet.config.annotation.ViewControllerRegistry
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
 

+ 5 - 5
src/main/kotlin/com/yaoxiang/planning/domain/BaseLongEntity.kt

@@ -1,19 +1,19 @@
 package com.yaoxiang.planning.domain
 
+import io.swagger.annotations.ApiModelProperty
 import org.hibernate.annotations.CreationTimestamp
 import org.hibernate.annotations.UpdateTimestamp
 import java.io.Serializable
 import java.util.*
-import javax.persistence.GeneratedValue
-import javax.persistence.GenerationType
-import javax.persistence.Id
-import javax.persistence.MappedSuperclass
+import javax.persistence.*
 
 @MappedSuperclass
-open class BaseLongEntity :Serializable{
+open class BaseLongEntity : Serializable {
 
     @Id
     @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @ApiModelProperty("主键")
+    @Column(columnDefinition = "int(11) COMMENT '主键'")
     open var id: Long? = null
 
     @CreationTimestamp

+ 14 - 13
src/main/kotlin/com/yaoxiang/planning/domain/Planning.kt

@@ -6,35 +6,36 @@ import javax.persistence.*
 
 
 //@Entity
-@ApiModel("计划")
-@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+//@ApiModel("计划")
+//@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+@MappedSuperclass
 open class Planning() : BaseLongEntity() {
 
     @ApiModelProperty("计划名称")
     @Column(columnDefinition = "varchar(255) COMMENT '计划名称'")
-    var name: String? = null
+    open var name: String? = null
 
     @ApiModelProperty("计划内容")
     @Column(columnDefinition = "mediumtext COMMENT '计划内容'")
-    var content: String? = null
+    open var content: String? = null
 
-    @ApiModelProperty("计划状态 0未开始 1 进行中 2暂搁 3已完成 4中止")
-    @Column(columnDefinition = "int(11) COMMENT '计划状态 0未开始 1 进行中 2暂搁 3已完成 4中止'")
-    var status: Int? = null
+    @ApiModelProperty("计划状态 0准备 1执行 2暂搁 3完成 4中止")
+    @Column(columnDefinition = "int(11) COMMENT '计划状态 0准备 1执行 2暂搁 3完成 4中止'")
+    open var status: Int? = null
 
     @ApiModelProperty("评价")
     @Column(columnDefinition = "mediumtext COMMENT '评价'")
-    var evaluation: String? = null
+    open var evaluation: String? = null
 
     @ApiModelProperty("计划年份")
     @Column(columnDefinition = "int(11) COMMENT '计划年份'")
-    var year: Int? = null
+    open var year: Int? = null
 
-    @ApiModelProperty("计划类型 1 年度计划 2 季度计划 3 周计划")
-    @Column(columnDefinition = "int(11) COMMENT '计划类型 1 年度计划 2 季度计划 3 周计划'")
-    var type: Int? = null
+    @ApiModelProperty("计划类型 0年度计划 1季度计划 2周计划")
+    @Column(columnDefinition = "int(11) COMMENT '计划类型 0年度计划 1季度计划 2周计划'")
+    open var type: Int? = null
 
     @Transient
     @ApiModelProperty("计划项列表")
-    var items: List<PlanningItem>? = null
+    open var items: List<PlanningItem>? = null
 }

+ 7 - 3
src/main/kotlin/com/yaoxiang/planning/domain/PlanningItem.kt

@@ -33,9 +33,13 @@ class PlanningItem() : BaseLongEntity() {
     @Column(columnDefinition = "int(20) COMMENT '分计划所属部门Id'")
     var departmentId: Long? = null
 
-    @ApiModelProperty("分计划序号")
-    @Column(columnDefinition = "int(11) COMMENT '分计序号'")
-    var indexes: Int? = null
+//    @ApiModelProperty("分计划序号")
+//    @Column(columnDefinition = "int(11) COMMENT '分计序号'")
+//    var indexes: Int? = null
+
+    @ApiModelProperty("分计划类型")
+    @Column(columnDefinition = "int(20) COMMENT '分计划类型'")
+    var type: Int? = null
 
     @ApiModelProperty("计划Id")
     @Column(columnDefinition = "int(20) COMMENT '计划Id'")

+ 1 - 1
src/main/kotlin/com/yaoxiang/planning/domain/UserInfo.kt

@@ -43,7 +43,7 @@ class UserInfo() : BaseLongEntity() {
 
     @ApiModelProperty("是否启用")
     @Column(columnDefinition = "bit(1) COMMENT '是否启用'")
-    var enabled:Boolean=true
+    var enabled: Boolean = true
 
     @ApiModelProperty("部门Id")
     @Column(columnDefinition = "int(20) COMMENT '部门Id'")

+ 19 - 0
src/main/kotlin/com/yaoxiang/planning/model/Constants.kt

@@ -0,0 +1,19 @@
+package com.yaoxiang.planning.model
+
+class Constants {
+
+}
+
+enum class PlanStatus(val status: String) {
+    READY("准备"),
+    EXECUTE("执行"),
+    PAUSE("暂搁"),
+    FINISHED("完成"),
+    CANCEL("中止")
+}
+
+enum class PlanType(val type: String) {
+    ANNUAL("年度计划"),
+    QUARTERLY("季度计划"),
+    WEEKLY("周计划")
+}

+ 5 - 1
src/main/kotlin/com/yaoxiang/planning/repository/AnnualPlanRepo.kt

@@ -3,6 +3,10 @@ package com.yaoxiang.planning.repository
 import com.yaoxiang.planning.domain.AnnualPlan
 import org.springframework.data.jpa.repository.JpaRepository
 import org.springframework.stereotype.Repository
+import java.util.*
 
 @Repository
-interface AnnualPlanRepo :JpaRepository<AnnualPlan,Long>
+interface AnnualPlanRepo : JpaRepository<AnnualPlan, Long> {
+
+    fun findFirstByYear(year: Int): Optional<AnnualPlan>
+}

+ 1 - 1
src/main/kotlin/com/yaoxiang/planning/repository/DepartmentRepo.kt

@@ -5,4 +5,4 @@ import org.springframework.data.jpa.repository.JpaRepository
 import org.springframework.stereotype.Repository
 
 @Repository
-interface DepartmentRepo :JpaRepository<Department,Long>
+interface DepartmentRepo : JpaRepository<Department, Long>

+ 3 - 1
src/main/kotlin/com/yaoxiang/planning/repository/PlanningItemRepo.kt

@@ -5,4 +5,6 @@ import org.springframework.data.jpa.repository.JpaRepository
 import org.springframework.stereotype.Repository
 
 @Repository
-interface PlanningItemRepo :JpaRepository<PlanningItem,Long>
+interface PlanningItemRepo : JpaRepository<PlanningItem, Long> {
+    fun findByPlanningIdAndType(planningId: Long, type: Int): List<PlanningItem>
+}

+ 68 - 0
src/main/kotlin/com/yaoxiang/planning/service/AnnualPlanService.kt

@@ -1,8 +1,11 @@
 package com.yaoxiang.planning.service
 
+import com.yaoxiang.planning.domain.AnnualPlan
+import com.yaoxiang.planning.model.PlanType
 import com.yaoxiang.planning.repository.AnnualPlanRepo
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.stereotype.Service
+import java.util.*
 
 @Service
 class AnnualPlanService {
@@ -10,5 +13,70 @@ class AnnualPlanService {
     @Autowired
     private lateinit var annualPlanRepo: AnnualPlanRepo
 
+    @Autowired
+    private lateinit var planningService: PlanningService
+
+    @Autowired
+    private lateinit var planningItemService: PlanningItemService
+
+    fun add(name: String, content: String, year: Int): Boolean {
+        if (exists(year)) {
+            return false
+        }
+        val planning = AnnualPlan()
+        planning.type = PlanType.ANNUAL.ordinal
+        planningService.add(name, content, year, planning)
+        return true
+    }
+
+    fun exists(year: Int): Boolean {
+        val optional = annualPlanRepo.findFirstByYear(year)
+        return optional.isPresent
+    }
+
+    fun getByYear(year: Int): Optional<AnnualPlan> {
+        val optional = findByYear(year)
+        if (optional.isPresent) {
+            val plan = optional.get()
+            val list = planningItemService.findByPlanningIdAndType(plan.id!!, plan.type!!)
+            plan.items = list
+        }
+        return optional
+    }
+
+    fun findByYear(year: Int): Optional<AnnualPlan> {
+        return annualPlanRepo.findFirstByYear(year)
+    }
+
+    fun get(id: Long): Optional<AnnualPlan> {
+        return annualPlanRepo.findById(id)
+    }
+
+    fun update(id: Long, name: String, content: String, status: Int): Boolean {
+        val optional = get(id)
+        if (!optional.isPresent) {
+            return false
+        }
+        val plan = optional.get()
+        plan.name = name
+        plan.content = content
+        plan.status = status
+        annualPlanRepo.save(plan)
+        return true
+    }
+
+    fun delete(id: Long): Boolean {
+        val optional = get(id)
+        if (!optional.isPresent) {
+            return false
+        }
+        annualPlanRepo.delete(optional.get())
+        return true
+    }
+
+    fun list(): List<AnnualPlan> {
+        return annualPlanRepo.findAll()
+    }
+
 
 }

+ 19 - 0
src/main/kotlin/com/yaoxiang/planning/service/PlanningItemService.kt

@@ -1,5 +1,7 @@
 package com.yaoxiang.planning.service
 
+import com.yaoxiang.planning.domain.PlanningItem
+import com.yaoxiang.planning.model.PlanStatus
 import com.yaoxiang.planning.repository.PlanningItemRepo
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.stereotype.Service
@@ -10,4 +12,21 @@ class PlanningItemService {
     @Autowired
     private lateinit var planningItemRepo: PlanningItemRepo
 
+    fun addItem(planningItem: PlanningItem): Boolean {
+        if (planningItem.type == null || planningItem.planningId == null) {
+            return false
+        }
+        planningItem.status = PlanStatus.READY.ordinal
+        planningItemRepo.save(planningItem)
+        return true
+    }
+
+    fun addItems(items: List<PlanningItem>): Boolean {
+        items.forEach { addItem(it) }
+        return true
+    }
+
+    fun findByPlanningIdAndType(planningId: Long, type: Int): List<PlanningItem> {
+        return planningItemRepo.findByPlanningIdAndType(planningId, type)
+    }
 }

+ 45 - 0
src/main/kotlin/com/yaoxiang/planning/service/PlanningService.kt

@@ -0,0 +1,45 @@
+package com.yaoxiang.planning.service
+
+import com.yaoxiang.planning.domain.AnnualPlan
+import com.yaoxiang.planning.domain.Planning
+import com.yaoxiang.planning.domain.QuarterlyPlan
+import com.yaoxiang.planning.domain.WeeklyPlan
+import com.yaoxiang.planning.model.PlanStatus
+import com.yaoxiang.planning.model.PlanType
+import com.yaoxiang.planning.repository.AnnualPlanRepo
+import com.yaoxiang.planning.repository.QuarterlyPlanRepo
+import com.yaoxiang.planning.repository.WeeklyPlanRepo
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.stereotype.Service
+
+@Service
+class PlanningService {
+
+    @Autowired
+    private lateinit var annualPlanRepo: AnnualPlanRepo
+
+    @Autowired
+    private lateinit var quarterlyPlanRepo: QuarterlyPlanRepo
+
+    @Autowired
+    private lateinit var weeklyPlanRepo: WeeklyPlanRepo
+
+    fun add(name: String, content: String, year: Int, planning: Planning): Boolean {
+        planning.name = name
+        planning.content = content
+        planning.year = year
+        planning.status = PlanStatus.READY.ordinal
+        when (planning.type) {
+            PlanType.ANNUAL.ordinal -> {
+                annualPlanRepo.save(planning as AnnualPlan)
+            }
+            PlanType.QUARTERLY.ordinal -> {
+                quarterlyPlanRepo.save(planning as QuarterlyPlan)
+            }
+            PlanType.WEEKLY.ordinal -> {
+                weeklyPlanRepo.save(planning as WeeklyPlan)
+            }
+        }
+        return true
+    }
+}