[2311] 견적 저장 후 CONN_VOL_W(접속용량) 백필 — circuitItemList 빈 {} 제거, PCS 실대수 기준 매핑
This commit is contained in:
parent
8817e72ddb
commit
cf0ff417fc
@ -10,6 +10,8 @@ import { useRouter, useSearchParams } from 'next/navigation'
|
|||||||
import { FloorPlanContext } from '@/app/floor-plan/FloorPlanProvider'
|
import { FloorPlanContext } from '@/app/floor-plan/FloorPlanProvider'
|
||||||
import { QcastContext } from '@/app/QcastProvider'
|
import { QcastContext } from '@/app/QcastProvider'
|
||||||
import { useSwal } from '@/hooks/useSwal'
|
import { useSwal } from '@/hooks/useSwal'
|
||||||
|
import { POLYGON_TYPE } from '@/common/common'
|
||||||
|
import { logger } from '@/util/logger'
|
||||||
// Constants
|
// Constants
|
||||||
const ESTIMATE_API_ENDPOINT = '/api/estimate' // API 엔드포인트 정의
|
const ESTIMATE_API_ENDPOINT = '/api/estimate' // API 엔드포인트 정의
|
||||||
|
|
||||||
@ -33,7 +35,7 @@ export const useEstimateController = (planNo, flag) => {
|
|||||||
|
|
||||||
const { getMessage } = useMessage()
|
const { getMessage } = useMessage()
|
||||||
|
|
||||||
const { promiseGet, post, promisePost } = useAxios(globalLocaleState)
|
const { promiseGet, post, promisePost, get } = useAxios(globalLocaleState)
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
const { estimateContextState, setEstimateContextState } = useContext(FloorPlanContext)
|
const { estimateContextState, setEstimateContextState } = useContext(FloorPlanContext)
|
||||||
@ -386,6 +388,44 @@ export const useEstimateController = (planNo, flag) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 견적 저장 직후 CONN_VOL_W(접속용량) 백필 → 인증용량 = Σ min(CONN_VOL_W_unit, PCS정격_unit) 계산용.
|
||||||
|
// 견적서 상세 화면엔 라이브 캔버스가 없으므로, 서버에 저장된 plan JSON(by-object)을 받아 파싱한다.
|
||||||
|
const backfillConnVol = async (objectNo, planNo) => {
|
||||||
|
try {
|
||||||
|
const list = await get({ url: `/api/canvas-management/canvas-statuses/by-object/${objectNo}` })
|
||||||
|
const target = (list || []).find((it) => String(it.planNo) === String(planNo)) || (list || [])[0]
|
||||||
|
const raw = target?.canvasStatus?.replace(/##/g, '"').replace(/∠/g, '∠').replace(/°/g, '°')
|
||||||
|
const objects = raw ? JSON.parse(raw).objects || [] : []
|
||||||
|
|
||||||
|
const moduleObjs = objects.filter((o) => o.name === POLYGON_TYPE.MODULE)
|
||||||
|
const moduleList = moduleObjs.map((m) => ({ circuit: m.circuitNumber, specification: m.moduleInfo?.wpOut }))
|
||||||
|
|
||||||
|
// PCS 데이터는 surfaces[0] 에만 실려 있다.
|
||||||
|
// circuitItemList 개수 = 실제 PCS 대수(빈 {} 금지). 라벨 첫 숫자로 유닛 수를 세면
|
||||||
|
// 단일 PCS+회로 여러 개일 때 pcsList[unit-1] 이 undefined → 빈 {} 가 생겨 서버가 정격을 못 찾아 회로가 탈락한다.
|
||||||
|
const surface0 = objects.find((o) => o.name === POLYGON_TYPE.MODULE_SETUP_SURFACE)
|
||||||
|
const pcsList = (surface0?.pcses || []).filter((pcs) => pcs?.pcsItemId)
|
||||||
|
const circuitItemList = pcsList.map((pcs) => ({ itemId: pcs.pcsItemId }))
|
||||||
|
|
||||||
|
logger.log('[UPDATE-CONN-VOL] enter', {
|
||||||
|
planCount: (list || []).length,
|
||||||
|
moduleCount: moduleObjs.length,
|
||||||
|
pcsCount: pcsList.length,
|
||||||
|
objectNo,
|
||||||
|
planNo,
|
||||||
|
})
|
||||||
|
if (moduleList.length === 0) {
|
||||||
|
logger.log('[UPDATE-CONN-VOL] skip — plan JSON 에 모듈 없음')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const connVolData = { objectNo, planNo, circuitItemList, roofSurfaceList: [{ moduleList }] }
|
||||||
|
logger.log('[UPDATE-CONN-VOL] payload', JSON.stringify(connVolData))
|
||||||
|
await promisePost({ url: `${ESTIMATE_API_ENDPOINT}/update-conn-vol`, data: connVolData })
|
||||||
|
} catch (e) {
|
||||||
|
logger.log('[UPDATE-CONN-VOL] 백필 호출 실패', e?.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const realSave = async (fileList) => {
|
const realSave = async (fileList) => {
|
||||||
|
|
||||||
setEstimateContextState({pricingFlag: false})
|
setEstimateContextState({pricingFlag: false})
|
||||||
@ -451,9 +491,12 @@ export const useEstimateController = (planNo, flag) => {
|
|||||||
//2. 상세데이터 저장
|
//2. 상세데이터 저장
|
||||||
try {
|
try {
|
||||||
setIsGlobalLoading(true)
|
setIsGlobalLoading(true)
|
||||||
await promisePost({ url: `${ESTIMATE_API_ENDPOINT}/save-estimate`, data: estimateData }).then((res) => {
|
await promisePost({ url: `${ESTIMATE_API_ENDPOINT}/save-estimate`, data: estimateData }).then(async (res) => {
|
||||||
|
logger.log('[UPDATE-CONN-VOL] save-estimate 응답', res.status)
|
||||||
if (res.status === 201) {
|
if (res.status === 201) {
|
||||||
estimateData.newFileList = []
|
estimateData.newFileList = []
|
||||||
|
// 인증용량이 CONN_VOL_W 로 계산되므로 /detail 재조회(fetchSetting) 전에 백필을 끝낸다.
|
||||||
|
await backfillConnVol(estimateData.objectNo, estimateData.planNo)
|
||||||
swalFire({ text: getMessage('estimate.detail.save.alertMsg'), type: 'alert' })
|
swalFire({ text: getMessage('estimate.detail.save.alertMsg'), type: 'alert' })
|
||||||
fetchSetting(estimateData.objectNo, estimateData.planNo)
|
fetchSetting(estimateData.objectNo, estimateData.planNo)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user