51 lines
2.0 KiB
Java
51 lines
2.0 KiB
Java
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;
|
|
|
|
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;
|
|
}
|
|
|
|
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);
|
|
}
|
|
return planSeq;
|
|
}
|
|
}
|