diff --git a/src/main/java/com/dbnt/faisp/config/BaseBoard.java b/src/main/java/com/dbnt/faisp/config/BaseBoard.java deleted file mode 100644 index 95928459..00000000 --- a/src/main/java/com/dbnt/faisp/config/BaseBoard.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.dbnt.faisp.config; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import org.springframework.format.annotation.DateTimeFormat; - -import javax.persistence.Column; -import javax.persistence.Transient; -import java.time.LocalDateTime; -import java.util.List; - -@Getter -@Setter -@NoArgsConstructor -public class BaseBoard extends BaseModel { - - @Column(name = "wrt_organ") - private String wrtOrgan; - @Column(name = "wrt_nm") - private String wrtNm; - @Column(name = "wrt_dt") - @DateTimeFormat(pattern = "yyyy-MM-dd") - private LocalDateTime wrtDt; - -} diff --git a/src/main/java/com/dbnt/faisp/controller/FpiMgtController.java b/src/main/java/com/dbnt/faisp/controller/FpiMgtController.java index 8f54df4d..34ee3bc4 100644 --- a/src/main/java/com/dbnt/faisp/controller/FpiMgtController.java +++ b/src/main/java/com/dbnt/faisp/controller/FpiMgtController.java @@ -48,6 +48,6 @@ public class FpiMgtController { // 외사경찰견문관리 public Integer savePlan(BoardPlan boardPlan, @RequestParam(value = "planInfos", required = false) List planInfos, @RequestParam(value = "detailPlanInfos", required = false)List detailPlanInfos){ - return 0; + return monthPlanService.saveBoardPlan(boardPlan, planInfos, detailPlanInfos); } } diff --git a/src/main/java/com/dbnt/faisp/fpiMgt/monthPlan/MonthPlanService.java b/src/main/java/com/dbnt/faisp/fpiMgt/monthPlan/MonthPlanService.java index bb4e0ec5..498bf5cc 100644 --- a/src/main/java/com/dbnt/faisp/fpiMgt/monthPlan/MonthPlanService.java +++ b/src/main/java/com/dbnt/faisp/fpiMgt/monthPlan/MonthPlanService.java @@ -3,23 +3,48 @@ package com.dbnt.faisp.fpiMgt.monthPlan; import com.dbnt.faisp.fpiMgt.monthPlan.model.BoardPlan; import com.dbnt.faisp.fpiMgt.monthPlan.model.PlanFile; +import com.dbnt.faisp.fpiMgt.monthPlan.model.PlanMainInfo; import com.dbnt.faisp.fpiMgt.monthPlan.repository.BoardPlanRepository; import com.dbnt.faisp.fpiMgt.monthPlan.repository.PlanFileRepository; import com.dbnt.faisp.fpiMgt.monthPlan.repository.PlanMainInfoRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.persistence.Transient; +import java.util.List; @Service @RequiredArgsConstructor public class MonthPlanService { - private final BoardPlanRepository boardPlanRepository; - private final PlanFileRepository planFileRepository; - private final PlanMainInfoRepository planMainInfoRepository; + private final BoardPlanRepository boardPlanRepository; + private final PlanFileRepository planFileRepository; + private final PlanMainInfoRepository planMainInfoRepository; - public BoardPlan selectBoardPlan(Integer planKey) { - BoardPlan savedPlan = boardPlanRepository.findById(planKey).orElse(null); - savedPlan.setFileList(planFileRepository.findByPlanKey(planKey)); - savedPlan.setMainInfoList(planMainInfoRepository.findByPlanKey(planKey)); - return savedPlan; + public BoardPlan selectBoardPlan(Integer planKey) { + BoardPlan savedPlan = boardPlanRepository.findById(planKey).orElse(null); + savedPlan.setFileList(planFileRepository.findByPlanKey(planKey)); + savedPlan.setMainInfoList(planMainInfoRepository.findByPlanKey(planKey)); + return savedPlan; + } + + @Transactional + public Integer saveBoardPlan(BoardPlan boardPlan, List planInfos, List detailPlanInfos) { + Integer planKey = boardPlanRepository.save(boardPlan).getPlanKey(); + Integer infoSeq = savePlanMainInfos(planKey,0, "S", planInfos);//요약 summery + savePlanMainInfos(planKey, infoSeq, "D", detailPlanInfos);//상세 detail + return planKey; + } + + private Integer savePlanMainInfos(Integer planKey, Integer planSeq, String infoType, List infoList){ + for(String info: infoList){ + PlanMainInfo planMainInfo = new PlanMainInfo(); + planMainInfo.setPlanKey(planKey); + planMainInfo.setPlanSeq(++planSeq); + planMainInfo.setPlanType(infoType); + planMainInfo.setPlanInfo(info); + planMainInfoRepository.save(planMainInfo); } + return planSeq; + } } diff --git a/src/main/java/com/dbnt/faisp/fpiMgt/monthPlan/model/BoardPlan.java b/src/main/java/com/dbnt/faisp/fpiMgt/monthPlan/model/BoardPlan.java index 5eae1529..1a58a5ea 100644 --- a/src/main/java/com/dbnt/faisp/fpiMgt/monthPlan/model/BoardPlan.java +++ b/src/main/java/com/dbnt/faisp/fpiMgt/monthPlan/model/BoardPlan.java @@ -1,7 +1,6 @@ package com.dbnt.faisp.fpiMgt.monthPlan.model; -import com.dbnt.faisp.config.BaseBoard; -import com.fasterxml.jackson.annotation.JsonFormat; +import com.dbnt.faisp.config.BaseModel; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -11,6 +10,7 @@ import org.springframework.format.annotation.DateTimeFormat; import javax.persistence.*; import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.List; @Getter @@ -20,7 +20,7 @@ import java.util.List; @DynamicInsert @DynamicUpdate @Table(name = "board_plan") -public class BoardPlan extends BaseBoard { +public class BoardPlan extends BaseModel { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "plan_key") @@ -44,6 +44,13 @@ public class BoardPlan extends BaseBoard { private String headApprv; @Column(name = "head_etc") private String headEtc; + @Column(name = "wrt_organ") + private String wrtOrgan; + @Column(name = "wrt_nm") + private String wrtNm; + @Column(name = "wrt_dt") + @DateTimeFormat(pattern = "yyyy-MM-dd") + private LocalDateTime wrtDt; @Transient private List mainInfoList; diff --git a/src/main/java/com/dbnt/faisp/fpiMgt/monthPlan/model/PlanMainInfo.java b/src/main/java/com/dbnt/faisp/fpiMgt/monthPlan/model/PlanMainInfo.java index 950b562a..9467dda5 100644 --- a/src/main/java/com/dbnt/faisp/fpiMgt/monthPlan/model/PlanMainInfo.java +++ b/src/main/java/com/dbnt/faisp/fpiMgt/monthPlan/model/PlanMainInfo.java @@ -13,7 +13,7 @@ import java.io.Serializable; @NoArgsConstructor @DynamicInsert @DynamicUpdate -@Table(name = "board_plan") +@Table(name = "plan_main_info") @IdClass(PlanMainInfo.PlanMainInfoId.class) public class PlanMainInfo { @Id