하석형 하석형 2023-02-24
230224 하석형 장비 매칭 대상자의 최신 idx 목록 조회
@b72bfaba12097f07231acf5ecf7c782b343c8bda
client/views/pages/equipment/EquipmentManagementSelect.jsx
--- client/views/pages/equipment/EquipmentManagementSelect.jsx
+++ client/views/pages/equipment/EquipmentManagementSelect.jsx
@@ -9,6 +9,11 @@
 
 export default function EquipmentManagementSelect() {
 
+	// 시스템 코드 - 장비 상태
+	const [equipmentStates, setEquipmentStates] = React.useState({});
+	// 시스템 코드 - 장비 대여 상태
+	const [equipmentRentalStates, setEquipmentRentalStates] = React.useState({});
+
 	const [modalOpen, setModalOpen] = React.useState(false);
 	const openModal = () => {
 		setModalOpen(true);
@@ -37,78 +42,97 @@
 	const navigate = useNavigate();
 
 	// 시스템 코드 - 장비 대여 상태 조회
-	const equipmentRentalStatesSelect = () => {
-		// console.log('equipmentRentalStatesSelect Function Run');
-		// axios.get('/common/systemCode/equipmentRentalStatesSelect.json')
-		// .then(function (response) {
-		// 	console.log('equipmentRentalStatesSelect : ', response.data);
-		// }).catch(function (error) {
-		// 	console.log("equipmentRentalStatesSelect - error : ", error);
-		// });
+	const equipmentStatesSelect = () => {
+		console.log('equipmentStatesSelect Function Run');
 
-		// fetch('/common/systemCode/equipmentRentalStatesSelect.json', {
-		// 	method: "GET",
-		// })
-		// .then((response) => response.json())
-		// .then((data) => {
-		// 	console.log('equipmentRentalStatesSelect response : ', data);
-		// }).catch((error) => {
-		// 	console.log('equipmentRentalStatesSelect error : ', error);
-		// });
-
-		// fetch('/common/systemCode/equipmentRentalStatesSelect.json', {
-		// 	// headers: {
-		// 	//   Accept: "application / json",
-		// 	// },
-		// 	method: "GET",
-		//   })
-		// .then((response) => response.json())
-		// .then((data) => console.log(data));
-
-		// fetch('https://dummyjson.com/products/1')
-		// .then(res => res.json())
-		// .then(json => console.log(json))
+		//fetch post
+		fetch("/common/systemCode/equipmentStatesSelect.json", {
+			method: "POST",
+			headers: {
+				'Content-Type': 'application/json; charset=UTF-8'
+			},
+			body: JSON.stringify({})
+		}).then((response) => response.json()).then((data) => {
+			console.log('equipmentStatesSelect response : ', data);
+			setEquipmentStates(data);
+		}).catch((error) => {
+			console.log('equipmentStatesSelect error : ', error);
+		});
 	}
 
-	// fetch("https://jsonplaceholder.typicode.com/posts/1")
-	// .then((response) => response.json())
-	// .then((data) => console.log(data))
+	// 시스템 코드 - 장비 대여 상태 조회
+	const equipmentRentalStatesSelect = () => {
+		console.log('equipmentRentalStatesSelect Function Run');
 
-	// fetch("https://jsonplaceholder.typicode.com/posts/1", {
-	// 	method : "POST",
-	// 	headers : {"Content-Type": "application/json",},
-	// 	body: JSON.stringify({
-	// 		title: "Test",
-	// 		body: "I am testing!",
-	// 		userId: 1,
-	// 	}),
-	// })
-	// .then((response) => response.json())
-	// .then((json) => console.log(json))
+		//fetch post
+		fetch("/common/systemCode/equipmentRentalStatesSelect.json", {
+			method: "POST",
+			headers: {
+				'Content-Type': 'application/json; charset=UTF-8'
+			},
+			body: JSON.stringify({})
+		}).then((response) => response.json()).then((data) => {
+			console.log('equipmentRentalStatesSelect response : ', data);
+			setEquipmentRentalStates(data);
+		}).catch((error) => {
+			console.log('equipmentRentalStatesSelect error : ', error);
+		});
 
-	// 대상자 목록 조회
-	const seniorSelectList = () => {
+		//fetch get
+		/* fetch('/common/systemCode/equipmentRentalStatesSelect.json')
+		.then((response) => response.json()).then((data) => {
+			console.log('equipmentRentalStatesSelect response : ', data);
+		}).catch((error) => {
+			console.log('equipmentRentalStatesSelect error : ', error);
+		}); */
+
+		//axios get
+		/* axios.get('/common/systemCode/equipmentRentalStatesSelect.json')
+		.then(function (response) {
+			console.log('equipmentRentalStatesSelect : ', response.data);
+		}).catch(function (error) {
+			console.log("equipmentRentalStatesSelect - error : ", error);
+		}); */
+
+		//axios post
+		/* axios({
+			url: '/common/systemCode/equipmentRentalStatesSelect.json',
+			method: 'post',
+			headers: {
+				'Content-Type': "application/json; charset=UTF-8",
+			},
+			data: {}
+		}).then(function (response) {
+			console.log("equipmentRentalStatesSelect - response : ", response.data);
+		}).catch(function (error) {
+			console.log("equipmentRentalStatesSelect - error : ", error);
+		}); */
+	}
+
+	// 장비 비매칭 대상자 목록 조회
+	const equipmentNotMatchSeniorSelectList = () => {
 		console.log('seniorSelectList Function Run');
-		fetch("/user/userSeleteList.json", {
+		fetch("/user/equipmentMatchStateSelectListBySenior.json", {
 			method: "POST",
 			headers: {
 				'Content-Type': 'application/json; charset=UTF-8'
 			},
 			body: JSON.stringify({
-				user_code: 'SENIOR01'
+				agency_id: 'AGENCY01',
+				matchState: false
 			})
 		}).then((response) => response.json()).then((data) => {
-			console.log('seniorSelectList response : ', data);
-			setSeniorList(data);
+			console.log('equipmentNotMatchSeniorSelectList response : ', data);
+			setEquipmentNotMatchSeniorList(data);
 		}).catch((error) => {
-			console.log('seniorSelectList error : ', error);
+			console.log('equipmentNotMatchSeniorSelectList error : ', error);
 		});
 	}
 
 	// 담당자 목록 조회
 	const workerSelectList = () => {
 		console.log('workerSelectList Function Run');
-		fetch("/user/userSeleteList.json", {
+		fetch("/user/selectUserList.json", {
 			method: "POST",
 			headers: {
 				'Content-Type': 'application/json; charset=UTF-8'
@@ -257,7 +281,7 @@
 	/********************************** 시행기관 장비 (시작) **********************************/
 	//로그 확인
 	const logCheck = () => {
-		console.log('seniorList - change: ', seniorList);
+		console.log('equipmentNotMatchSeniorList - change: ', equipmentNotMatchSeniorList);
 	};
 
 	// 시행기관 전체 장비 목록
@@ -273,8 +297,8 @@
 	// 대상자 장비 반납 모달창
 	const [seniorMatchReturnModal, setSeniorMatchReturnModal] = React.useState(false);
 
-	// 대상자 목록
-	const [seniorList, setSeniorList] = React.useState([]);
+	// 장비 비매칭 대상자 목록
+	const [equipmentNotMatchSeniorList, setEquipmentNotMatchSeniorList] = React.useState([]);
 	// 담당자 목록
 	const [workerList, setWorkerList] = React.useState([]);
 
@@ -436,14 +460,14 @@
 
 		// 대상자 아이디 유효성 검사
 		let check = 0;
-		for (let i = 0; i < seniorList.length; i++) {
-			// 입력한 데이터가 대상자 목록에 있을 경우
-			if (seniorList[i]['user_id'] == seniorEquipment['senior_id']) {
-				console.log('success: ', seniorList[i]['user_id']);
+		for (let i = 0; i < equipmentNotMatchSeniorList.length; i++) {
+			// 입력한 대상자 아이디가 대상자 목록에 있을 경우
+			if (equipmentNotMatchSeniorList[i]['senior_id'] == seniorEquipment['senior_id']) {
+				console.log('success: ', equipmentNotMatchSeniorList[i]['senior_id']);
 				// 원본 데이터 복사 및 수정
 				let data = {
 					...seniorEquipment,
-					user_name: seniorList[i]['user_name']
+					user_name: equipmentNotMatchSeniorList[i]['user_name'],
 				}
 				// 복사 데이터를 원본 데이터에 덮어쓰기
 				setSeniorEquipment(data);
@@ -451,12 +475,24 @@
 				check = 1;
 			}
 		}
-		// 입력한 데이터가 대상자 목록에 없을 경우
+		// 입력한 대상자 아이디가 대상자 목록에 없을 경우
 		if (check != 1) {
-			console.log('fail: ', seniorList, seniorEquipment['senior_id']);
+			console.log('fail: ', equipmentNotMatchSeniorList, seniorEquipment['senior_id']);
 			alert('존재하지 않는 대상자입니다.');
 			return;
 		}
+
+		// 대여일 유효성 검사
+		/* if(seniorEquipment['equipment_rental_start_date'] == null) {
+			alert('대여일을 입력해 주세요');
+			return;
+		} */
+
+		// 반납 예정일 유효성 검사
+		/* if(seniorEquipment['equipment_rental_end_date'] == null) {
+			alert('반납 예정일 입력해 주세요');
+			return;
+		} */
 
 		fetch("/equipment/seniorEquipmentInsert.json", {
 			method: "POST",
@@ -468,11 +504,14 @@
 			console.log('seniorEquipmentInsert response : ', data);
 			// 대상자 장비 데이터 초기화
 			setSeniorEquipment({});
-
+			//장비 비매칭 대상자 목록 조회
+			equipmentNotMatchSeniorSelectList();
 			// 장비 목록 조회
 			agencyEquipmentSelectList();
 			agencySeniorEquipmentSelectList();
 			agencyStockEquipmentSelectList();
+			// 모달창 닫기
+			setSeniorMatchInsertModal(false);
 
 			alert('등록이 완료됐습니다.');
 		}).catch((error) => {
@@ -488,18 +527,24 @@
 		// 담당자 아이디 유효성 검사
 		let check = 0;
 		for (let i = 0; i < workerList.length; i++) {
-			// 입력한 데이터가 담당자 목록에 있을 경우
+			// 입력한 담당자 아이디가 담당자 목록에 있을 경우
 			if (workerList[i]['user_id'] == seniorEquipment['return_user_id']) {
 				console.log('success: ', workerList[i]['user_id']);
 				check = 1;
 			}
 		}
-		// 입력한 데이터가 담당자 목록에 없을 경우
+		// 입력한 담당자 아이디가 담당자 목록에 없을 경우
 		if (check != 1) {
 			console.log('fail: ', workerList, seniorEquipment['return_user_id']);
 			alert('존재하지 않는 담당자입니다.');
 			return;
 		}
+
+		// 반납 예정일 유효성 검사
+		/* if(seniorEquipment['equipment_rental_return_date'] == null) {
+			alert('반납일 입력해 주세요');
+			return;
+		} */
 
 		fetch("/equipment/seniorEquipmentReturn.json", {
 			method: "POST",
@@ -511,11 +556,14 @@
 			console.log('seniorEquipmentReturn response : ', data);
 			// 대상자 장비 데이터 초기화
 			setSeniorEquipment({});
-
+			//장비 비매칭 대상자 목록 조회
+			equipmentNotMatchSeniorSelectList();
 			// 장비 목록 조회
 			agencyEquipmentSelectList();
 			agencySeniorEquipmentSelectList();
 			agencyStockEquipmentSelectList();
+			// 모달창 닫기
+			setSeniorMatchReturnModal(false);
 
 			alert('반납이 완료됐습니다.');
 		}).catch((error) => {
@@ -532,6 +580,7 @@
 		"시리얼 넘버",
 		"기기 상태",
 		"대여 상태",
+		"동일 기기 매칭 순번",
 		"대상자 관리",
 	];
 	const key11 = [
@@ -550,6 +599,7 @@
 		"대상자",
 		"대여일",
 		"반납예정일",
+		"동일 기기 매칭 순번",
 		"대상자 관리",
 	];
 	const key22 = [
@@ -559,6 +609,7 @@
 		"senior_name",
 		"equipment_rental_start_date",
 		"equipment_rental_end_date",
+		"equipment_match_idx",
 	];
 
 	// 시행기관 재고 장비 thead, key
@@ -592,8 +643,9 @@
 
 	// 마운트 시 실행 함수
 	React.useEffect(() => {
+		equipmentStatesSelect();
 		equipmentRentalStatesSelect();
-		seniorSelectList();
+		equipmentNotMatchSeniorSelectList();
 		workerSelectList();
 
 		//관리자
@@ -756,12 +808,30 @@
 								return (
 									<tr key={index}>
 										<td>{agencyEquipmentList.length - index}</td>
-										{key11.map((kes) => {
+										{/* {key11.map((kes) => {
+											if(kes == "equipment_rental_state") {
+												for(let i = 0; i < Object.keys(equipmentRentalStates).length; i++) {
+													if(item[kes].toString().toUpperCase() == Object.keys(equipmentRentalStates)[i]) {
+														item[kes] = Object.values(equipmentRentalStates)[i];
+													}
+												}
+											}
 											return <td>{item[kes]}</td>
+										})} */}
+										<td>{item['equipment_name']}</td>
+										<td>{item['equipment_serial_number']}</td>
+										{Object.keys(equipmentStates).map((key, idx) => {
+											if(item['equipment_state'] == key)
+											return <td>{Object.values(equipmentStates)[idx]}</td>
 										})}
+										{Object.keys(equipmentRentalStates).map((key, idx) => {
+											if(item['equipment_rental_state'] == key)
+											return <td>{Object.values(equipmentRentalStates)[idx]}</td>
+										})}
+										<td>{item['equipment_match_idx']}</td>
 										<td>
 											{
-												item['equipment_rental_state'] == false
+												item['equipment_rental_state'] == 'RENTABLE'
 													? <Button
 														className={"btn-small green-btn"}
 														btnName={"등록"}
@@ -943,9 +1013,9 @@
 									<td>
 										<input type="text" list="senior_list" placeholder="대상자를 입력해 주세요" onChange={seniorEquipmentSeniorInsert} />
 										<datalist id="senior_list">
-											{seniorList.map((item) => {
-												// return <option value={item['user_name'] + " (" + item['user_id'] + ")"}></option>
-												return <option value={item['user_id']}>{item['user_name']}</option>
+											{equipmentNotMatchSeniorList.map((item) => {
+												// return <option value={item['user_name'] + " (" + item['senior_id'] + ")"}></option>
+												return <option value={item['senior_id']}>{item['user_name']}</option>
 
 											})}
 										</datalist>
Add a comment
List