FAISP/src/main/java/com/dbnt/faisp/fpiMgt/monthPlan/MonthPlanService.java

51 lines
2.0 KiB
Java
Raw Normal View History

2022-09-05 09:02:09 +00:00
package com.dbnt.faisp.fpiMgt.monthPlan;
2022-09-06 09:10:03 +00:00
import com.dbnt.faisp.fpiMgt.monthPlan.model.BoardPlan;
import com.dbnt.faisp.fpiMgt.monthPlan.model.PlanFile;
2022-09-07 09:25:17 +00:00
import com.dbnt.faisp.fpiMgt.monthPlan.model.PlanMainInfo;
2022-09-06 09:10:03 +00:00
import com.dbnt.faisp.fpiMgt.monthPlan.repository.BoardPlanRepository;
import com.dbnt.faisp.fpiMgt.monthPlan.repository.PlanFileRepository;
import com.dbnt.faisp.fpiMgt.monthPlan.repository.PlanMainInfoRepository;
2022-09-05 09:02:09 +00:00
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
2022-09-07 09:25:17 +00:00
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.Transient;
import java.util.List;
2022-09-05 09:02:09 +00:00
@Service
@RequiredArgsConstructor
2022-09-06 09:10:03 +00:00
public class MonthPlanService {
2022-09-07 09:25:17 +00:00
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;
}
@Transactional
public Integer saveBoardPlan(BoardPlan boardPlan, List<String> planInfos, List<String> detailPlanInfos) {
Integer planKey = boardPlanRepository.save(boardPlan).getPlanKey();
Integer infoSeq = savePlanMainInfos(planKey,0, "S", planInfos);//요약 summery
savePlanMainInfos(planKey, infoSeq, "D", detailPlanInfos);//상세 detail
return planKey;
}
2022-09-06 09:10:03 +00:00
2022-09-07 09:25:17 +00:00
private Integer savePlanMainInfos(Integer planKey, Integer planSeq, String infoType, List<String> infoList){
for(String info: infoList){
PlanMainInfo planMainInfo = new PlanMainInfo();
planMainInfo.setPlanKey(planKey);
planMainInfo.setPlanSeq(++planSeq);
planMainInfo.setPlanType(infoType);
planMainInfo.setPlanInfo(info);
planMainInfoRepository.save(planMainInfo);
2022-09-06 09:10:03 +00:00
}
2022-09-07 09:25:17 +00:00
return planSeq;
}
2022-09-05 09:02:09 +00:00
}