diff --git a/src/components/floor-plan/modal/circuitTrestle/CircuitTrestleSetting.jsx b/src/components/floor-plan/modal/circuitTrestle/CircuitTrestleSetting.jsx index a0d2b34f..8c9d31af 100644 --- a/src/components/floor-plan/modal/circuitTrestle/CircuitTrestleSetting.jsx +++ b/src/components/floor-plan/modal/circuitTrestle/CircuitTrestleSetting.jsx @@ -43,7 +43,7 @@ export default function CircuitTrestleSetting({ id }) { const [circuitAllocationType, setCircuitAllocationType] = useState(1) const { managementState, setManagementState, managementStateLoaded } = useContext(GlobalDataContext) const selectedModules = useRecoilValue(selectedModuleState) - const { getPcsAutoRecommendList } = useMasterController() + const { getPcsAutoRecommendList, getPcsVoltageChk } = useMasterController() useEffect(() => { if (!managementState) { @@ -75,32 +75,48 @@ export default function CircuitTrestleSetting({ id }) { pcsItemList: getPcsItemList(), } - getPcsAutoRecommendList(params).then((res) => { - if (res.data?.pcsItemList) { - setModels( - res.data.pcsItemList.map((model) => { + if (selectedModels.length === 0) { + getPcsAutoRecommendList(params).then((res) => { + if (res.data?.pcsItemList) { + const itemList = models.filter((model) => { + return res.data?.pcsItemList.map((item) => item.itemId).includes(model.itemId) + }) + const selectedModels = itemList.map((model) => { return { ...model, id: uuidv4(), } - }), - ) - setTabNum(2) - } else { - // 데이터가 없는 경우 오류 메시지 확인 필요 - if (res.result.resultCode === 'E') { - swalFire({ - title: res.result.resultMsg, - type: 'alert', + }) + const pcsVoltageChkParams = { + ...getOptYn(), + useModuleItemList: getUseModuleItemList(), + roofSurfaceList: getRoofSurfaceList(), + pcsItemList: getPcsItemList(), + } + setSelectedModels(selectedModels) + getPcsVoltageChk(pcsVoltageChkParams).then((res) => { + setTabNum(2) }) } else { - swalFire({ - title: '파워컨디셔너를 추가해 주세요.', - type: 'alert', - }) + // 데이터가 없는 경우 오류 메시지 확인 필요 + if (res.result.resultCode === 'E') { + swalFire({ + title: res.result.resultMsg, + type: 'alert', + }) + } else { + swalFire({ + title: '파워컨디셔너를 추가해 주세요.', + type: 'alert', + }) + } } - } - }) + }) + } else { + getPcsVoltageChk(params).then((res) => { + setTabNum(2) + }) + } } const getOptYn = () => { @@ -135,6 +151,7 @@ export default function CircuitTrestleSetting({ id }) { .getObjects() .filter((obj) => obj.name === POLYGON_TYPE.MODULE_SETUP_SURFACE) .map((obj) => { + getModuleList(obj) return { roofSurfaceId: obj.id, roofSurface: canvas @@ -142,7 +159,7 @@ export default function CircuitTrestleSetting({ id }) { .filter((o) => o.id === obj.parentId)[0] .directionText.replace(/[0-9]/g, ''), roofSurfaceIncl: canvas.getObjects().filter((o) => o.id === obj.parentId)[0].roofMaterial.pitch, - moduleList: obj.modules.map((module) => { + moduleList: getModuleList(obj).map((module) => { return { itemId: module.moduleInfo.itemId, circuit: module.circuitNumber ? module.circuitNumber : null, @@ -153,6 +170,79 @@ export default function CircuitTrestleSetting({ id }) { }) } + const getModuleList = (surface) => { + let moduleList = [] + let [xObj, yObj] = [{}, {}] + let [xPoints, yPoints] = [[], []] + surface.modules.forEach((module) => { + if (!xObj[module.left]) { + xObj[module.left] = module.left + xPoints.push(module.left) + } + if (!yObj[module.top]) { + yObj[module.top] = module.top + yPoints.push(module.top) + } + }) + switch (surface.direction) { + case 'south': + xPoints.sort((a, b) => a - b) + yPoints.sort((a, b) => b - a) + yPoints.forEach((y, index) => { + let temp = surface.modules.filter((m) => m.top === y) + if (index % 2 === 0) { + temp.sort((a, b) => a.left - b.left) + } else { + temp.sort((a, b) => b.left - a.left) + } + moduleList = [...moduleList, ...temp] + }) + break + case 'north': + xPoints.sort((a, b) => b - a) + yPoints.sort((a, b) => a - b) + yPoints.forEach((y, index) => { + let temp = surface.modules.filter((m) => m.top === y) + if (index % 2 === 0) { + temp.sort((a, b) => b.left - a.left) + } else { + temp.sort((a, b) => a.left - b.left) + } + moduleList = [...moduleList, ...temp] + }) + break + case 'west': + xPoints.sort((a, b) => a - b) + yPoints.sort((a, b) => a - b) + xPoints.forEach((x, index) => { + let temp = surface.modules.filter((m) => m.left === x) + if (index % 2 === 0) { + temp.sort((a, b) => a.top - b.top) + } else { + temp.sort((a, b) => b.top - a.top) + } + moduleList = [...moduleList, ...temp] + }) + break + case 'east': + xPoints.sort((a, b) => b - a) + yPoints.sort((a, b) => b - a) + xPoints.forEach((x, index) => { + let temp = surface.modules.filter((m) => m.left === x) + if (index % 2 === 0) { + temp.sort((a, b) => b.top - a.top) + } else { + temp.sort((a, b) => a.top - b.top) + } + moduleList = [...moduleList, ...temp] + }) + break + default: + return [] + } + return moduleList + } + const onAutoAllocation = () => { let moduleStdQty = 0 let moduleMaxQty = 0 @@ -168,19 +258,19 @@ export default function CircuitTrestleSetting({ id }) { return acc + parseInt(model.moduleMaxQty) }, 0) } - const target = pcsCheck.max ? moduleMaxQty : moduleStdQty - const placementModules = canvas.getObjects().filter((obj) => obj.name === POLYGON_TYPE.MODULE) + // const target = pcsCheck.max ? moduleMaxQty : moduleStdQty + // const placementModules = canvas.getObjects().filter((obj) => obj.name === POLYGON_TYPE.MODULE) - if (placementModules.length > target) { - swalFire({ - title: '배치가능 매수를 초과합니다. 파워컨디셔너를 다시 선택해 주세요.', - type: 'alert', - }) - return - } + // if (placementModules.length > target) { + // swalFire({ + // title: '배치가능 매수를 초과합니다. 파워컨디셔너를 다시 선택해 주세요.', + // type: 'alert', + // }) + // return + // } // setAllocationType(ALLOCATION_TYPE.AUTO) - setTabNum(2) + // setTabNum(2) } const onPassivityAllocation = () => { @@ -197,14 +287,20 @@ export default function CircuitTrestleSetting({ id }) { const itemList = models.filter((model) => { return res.data?.pcsItemList.map((item) => item.itemId).includes(model.itemId) }) - setSelectedModels( - itemList.map((model) => { - return { - ...model, - id: uuidv4(), - } - }), - ) + const selectedModels = itemList.map((model) => { + return { + ...model, + id: uuidv4(), + } + }) + const PcsVoltageChkParams = { + ...getOptYn(), + useModuleItemList: getUseModuleItemList(), + roofSurfaceList: getRoofSurfaceList(), + pcsItemList: getPcsItemList(), + } + setSelectedModels(selectedModels) + getPcsVoltageChk(PcsVoltageChkParams).then((res) => {}) } else { swalFire({ title: '파워컨디셔너를 추가해 주세요.', diff --git a/src/hooks/common/useMasterController.js b/src/hooks/common/useMasterController.js index 554b6a4a..ef31962f 100644 --- a/src/hooks/common/useMasterController.js +++ b/src/hooks/common/useMasterController.js @@ -173,6 +173,22 @@ export function useMasterController() { }) } + /** + * PCS로 회로 구성 가능 여부 체크 + * @param {Max접속(과적)여부} maxConnYn + * @param {동일회로도여부} smpCirYn + * @param {한랭지여부} coldZoneYn + * @param {사용된 모듈 아이템 List} useModuleItemList + * @param {지붕면별 목록} roofSurfaceList + * @param {PCS 제품 목록} pcsItemList + * @returns + */ + const getPcsVoltageChk = async (params = null) => { + return await post({ url: '/api/v1/master/getPcsVoltageChk', data: params }).then((res) => { + return res + }) + } + /** * PCS 승압설정 정보 조회 * @param {Max접속(과적)여부} maxConnYn @@ -195,10 +211,7 @@ export function useMasterController() { pcsItemList: params2.pcsItemList, } - console.log('🚀 ~ getPcsVoltageStepUpList ~ params >>>>> :', params) - return await post({ url: '/api/v1/master/getPcsVoltageStepUpList', data: params }).then((res) => { - console.log('🚀🚀 ~ getPcsVoltageStepUpList ~ res:', res) return res }) } @@ -212,6 +225,7 @@ export function useMasterController() { getPcsMakerList, getPcsModelList, getPcsAutoRecommendList, + getPcsVoltageChk, getPcsManualConfChk, getPcsVoltageStepUpList, }