From 7c3274daba53ee8b65de786d56cd4b946af1e816 Mon Sep 17 00:00:00 2001 From: wyl <wangyulong990316@outlook.com> Date: Tue, 10 Dec 2024 13:46:50 +0000 Subject: [PATCH 1/3] update system construction --- build.gradle | 1 + .../config/WebSecurityConfig.java | 2 +- src/main/resources/application-dev.yml | 4 +- src/main/resources/application.yml | 6 + src/main/resources/data.sql | 73 ++++++++ src/main/resources/schema.sql | 160 ++++++++++++++++++ 6 files changed, 243 insertions(+), 3 deletions(-) create mode 100644 src/main/resources/data.sql create mode 100644 src/main/resources/schema.sql diff --git a/build.gradle b/build.gradle index 06adc59..f23ea5d 100644 --- a/build.gradle +++ b/build.gradle @@ -24,6 +24,7 @@ repositories { } dependencies { + implementation 'org.mariadb.jdbc:mariadb-java-client:3.5.1' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-jdbc' implementation 'org.springframework.boot:spring-boot-starter-web' diff --git a/src/main/java/com/cardiff/client_project/config/WebSecurityConfig.java b/src/main/java/com/cardiff/client_project/config/WebSecurityConfig.java index 52debc2..33028ca 100644 --- a/src/main/java/com/cardiff/client_project/config/WebSecurityConfig.java +++ b/src/main/java/com/cardiff/client_project/config/WebSecurityConfig.java @@ -52,7 +52,7 @@ public class WebSecurityConfig{ http .csrf(csrf-> csrf.disable()) .authorizeHttpRequests(requests -> requests .requestMatchers("/device.html").hasRole("ADMIN") - //.requestMatchers("/superAdminView.html").hasRole("SUPER") + //+.requestMatchers("/superAdminView.html").hasRole("SUPER") .requestMatchers("/commonUser.html").authenticated() .anyRequest().permitAll() diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index ae3309b..016cd27 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -1,6 +1,6 @@ healthcare: datasource: - url: jdbc:mysql://localhost:3306/health_care - port: 3306 + url: jdbc:mariadb://localhost:3307/healthcare + port: 3307 username: root password: root \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index bb26cfa..ccda0b6 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -8,6 +8,12 @@ spring: username: ${healthcare.datasource.username} password: ${healthcare.datasource.password} port: ${healthcare.datasource.port} + sql: + init: + schema-locations: classpath:schema.sql + data-locations: classpath:data.sql + platform: mariadb + mode: always thymeleaf: prefix: classpath:/templates/ suffix: .html diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql new file mode 100644 index 0000000..aab2669 --- /dev/null +++ b/src/main/resources/data.sql @@ -0,0 +1,73 @@ +/* + Navicat Premium Data Transfer + + Source Server : mariaDB + Source Server Type : MariaDB + Source Server Version : 101110 + Source Host : localhost:3307 + Source Schema : healthcare + + Target Server Type : MariaDB + Target Server Version : 101110 + File Encoding : 65001 + + Date: 09/12/2024 17:14:51 +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + + +-- ---------------------------- +-- Records of common_admin +-- ---------------------------- +INSERT INTO `common_admin` VALUES (1, '26497@qq.com', '$2a$10$5UzuKUxgR8H0RzLYrP.BUu8.76yKwMD4XkvJIu/xxB7AAHWfphFQm', 'commonAdmin', 1, '111', 'justnoww', 1); +INSERT INTO `common_admin` VALUES (2, '1234@qq.com', '$2a$10$iW/zeL9TLq55SHFaOfyfr.xFMvB4aD3CL2layeAlGC7CqZ9kcscA.', 'commonAdmin', 1, '123', 'BAa', 1); +INSERT INTO `common_admin` VALUES (3, '123cmy@qq.com', '$2a$10$u2KxNBaHuTVwX7KudUgyNelp8j2lymarXKkkUXfWBMRAgbPNryTuW', 'commonAdmin', 1, '123', 'cmy', 1); + +-- ---------------------------- +-- Records of device +-- ---------------------------- +INSERT INTO `device` VALUES (1, 0, 'bed1', 'bed', '2024-12-02 09:51:12'); +INSERT INTO `device` VALUES (2, 2, 'bed2', 'bed', '2024-12-03 09:30:00'); +INSERT INTO `device` VALUES (3, 2, 'bed3', 'bed', '2025-12-05 10:30:35'); +INSERT INTO `device` VALUES (4, 2, 'instrument1', 'instrument', '2024-12-05 07:15:59'); +INSERT INTO `device` VALUES (5, 2, 'instrument5', 'instrument', '2024-12-05 10:30:00'); + +-- ---------------------------- +-- Records of hospital +-- ---------------------------- +INSERT INTO `hospital` VALUES (1, 'hospital1', 5, 200, 'hospital', 'beijing', '6371', 1, 3, 'hospital1@qq.com', '$2a$10$wvAZoj4V51MH/MLhVIrnG.NrY07/.Gn9Ar6JsyzRAubWtqbWzgKie', 0, 0); +INSERT INTO `hospital` VALUES (2, 'hospital2', 10, 50, 'hospital', 'cardiff', '123', 1, 3, 'hospital2@qq.com', '$2a$10$wvAZoj4V51MH/MLhVIrnG.NrY07/.Gn9Ar6JsyzRAubWtqbWzgKie', 0, 0); + + +-- ---------------------------- +-- Records of nurse +-- ---------------------------- +INSERT INTO `nurse` VALUES (1, 'nn', 0, 2, 'nurse', 23, '111', '23453', 'Cardiff'); +INSERT INTO `nurse` VALUES (2, 'Li Xiaoming', 1, 2, 'nurse', 25, '222', '4399', 'Cardiff'); +INSERT INTO `nurse` VALUES (3, 'Sun Hao', 1, 2, 'nurse', 24, '123', '23576', 'Bute'); +INSERT INTO `nurse` VALUES (4, 'Wang Xiaoming', 0, 2, 'nurse', 26, '333', '34578', 'Cardiff'); +INSERT INTO `nurse` VALUES (5, 'Tian Hao', 0, 2, 'nurse', 30, '321', '24353', 'Cardiff'); + +-- ---------------------------- +-- Records of patient +-- ---------------------------- +INSERT INTO `patient` VALUES (1, 'Li Ming', '$2a$10$obgmyiqAuhIkBjuw3bROr.LkCh.Nb70e4dL8lwKjSsPxS8gSpQxSC', 2, 1, 0, 'patient', 20, '135', 'wwgwg@outlook.com'); +INSERT INTO `patient` VALUES (2, 'Li Hua', '$2a$10$obgmyiqAuhIkBjuw3bROr.LkCh.Nb70e4dL8lwKjSsPxS8gSpQxSC', 2, 0, 0, 'patient', 21, '166', 'ss@qq.com'); +INSERT INTO `patient` VALUES (3, 'Huang Li', '$2a$10$obgmyiqAuhIkBjuw3bROr.LkCh.Nb70e4dL8lwKjSsPxS8gSpQxSC', 2, 0, 0, 'patient', 13, '111', '22@qq.com'); +INSERT INTO `patient` VALUES (4, 'Xia Ming', '$2a$10$obgmyiqAuhIkBjuw3bROr.LkCh.Nb70e4dL8lwKjSsPxS8gSpQxSC', 2, 1, 2, 'patient', 61, '15', '131@qq.com'); +INSERT INTO `patient` VALUES (5, 'Xia Yu', '$2a$10$obgmyiqAuhIkBjuw3bROr.LkCh.Nb70e4dL8lwKjSsPxS8gSpQxSC', 2, 1, 2, 'patient', 33, '14315', 'xx@qq.com'); + +-- ---------------------------- +-- Records of role +-- ---------------------------- +INSERT INTO `role` VALUES (0, 'SUPER'); +INSERT INTO `role` VALUES (1, 'ADMIN'); +INSERT INTO `role` VALUES (2, 'PATIENT'); +INSERT INTO `role` VALUES (3, 'HOSPITAL'); + +-- ---------------------------- +-- Records of super_admin +-- ---------------------------- +INSERT INTO `super_admin` VALUES (1, '2649783657@qq.com', '$2a$10$5UzuKUxgR8H0RzLYrP.BUu8.76yKwMD4XkvJIu/xxB7AAHWfphFQm', 0); diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql new file mode 100644 index 0000000..cecb3c0 --- /dev/null +++ b/src/main/resources/schema.sql @@ -0,0 +1,160 @@ +/* + Navicat Premium Data Transfer + + Source Server : mariaDB + Source Server Type : MariaDB + Source Server Version : 101110 + Source Host : localhost:3307 + Source Schema : healthcare + + Target Server Type : MariaDB + Target Server Version : 101110 + File Encoding : 65001 + + Date: 09/12/2024 17:20:20 +*/ + +CREATE DATABASE IF NOT EXISTS healthcare; + +USE healthcare; + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for care_homes +-- ---------------------------- +DROP TABLE IF EXISTS `care_homes`; +CREATE TABLE `care_homes` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `address` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `status` enum('approved','rejected','pending') CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT 'pending', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Table structure for common_admin +-- ---------------------------- +DROP TABLE IF EXISTS `common_admin`; +CREATE TABLE `common_admin` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `email` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `password` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `type` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `roleId` int(11) NULL DEFAULT NULL, + `phone` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `status` int(11) NULL DEFAULT NULL, + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Table structure for device +-- ---------------------------- +DROP TABLE IF EXISTS `device`; +CREATE TABLE `device` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `hospitalId` int(11) NULL DEFAULT NULL, + `name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `type` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `freeTime` datetime NULL DEFAULT NULL, + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Table structure for hospital +-- ---------------------------- +DROP TABLE IF EXISTS `hospital`; +CREATE TABLE `hospital` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `amountPatient` int(11) NULL DEFAULT NULL, + `maxAmount` int(11) NULL DEFAULT NULL, + `type` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `address` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `phone` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `status` int(11) NULL DEFAULT NULL, + `roleId` int(11) NULL DEFAULT NULL, + `email` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `password` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `patientId` int(11) NULL DEFAULT NULL, + `deviceId` int(11) NULL DEFAULT NULL, + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Table structure for hospital_device +-- ---------------------------- +DROP TABLE IF EXISTS `hospital_device`; +CREATE TABLE `hospital_device` ( + `hospitalId` int(11) NULL DEFAULT NULL, + `deviceId` int(11) NULL DEFAULT NULL +) ENGINE = InnoDB CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Table structure for nurse +-- ---------------------------- +DROP TABLE IF EXISTS `nurse`; +CREATE TABLE `nurse` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `status` int(11) NULL DEFAULT NULL, + `hospitalId` int(11) NULL DEFAULT NULL, + `type` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `age` int(11) NULL DEFAULT NULL, + `phone` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `email` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `address` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Table structure for patient +-- ---------------------------- +DROP TABLE IF EXISTS `patient`; +CREATE TABLE `patient` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `password` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `roleId` int(11) NULL DEFAULT NULL, + `status` int(11) NULL DEFAULT NULL, + `hospitalId` int(11) NULL DEFAULT NULL, + `type` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `age` int(11) NULL DEFAULT NULL, + `phone` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `email` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Table structure for patient_hospital +-- ---------------------------- +DROP TABLE IF EXISTS `patient_hospital`; +CREATE TABLE `patient_hospital` ( + `hosptialId` int(11) NULL DEFAULT NULL, + `patientId` int(11) NULL DEFAULT NULL +) ENGINE = InnoDB CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Table structure for role +-- ---------------------------- +DROP TABLE IF EXISTS `role`; +CREATE TABLE `role` ( + `roleId` int(11) NULL DEFAULT NULL, + `type` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL +) ENGINE = InnoDB CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Table structure for super_admin +-- ---------------------------- +DROP TABLE IF EXISTS `super_admin`; +CREATE TABLE `super_admin` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, + `password` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, + `roleId` int(11) NULL DEFAULT NULL, + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic; + +SET FOREIGN_KEY_CHECKS = 1; -- GitLab From 9b4fc537104d8eee8fdc5f58cf55686dcf3cbb18 Mon Sep 17 00:00:00 2001 From: Burhan Akbar <akbarb@cardiff.ac.uk> Date: Wed, 11 Dec 2024 01:52:24 +0000 Subject: [PATCH 2/3] Resolve "As a user I would like to be able to view information about the nursing home, so that I can get details of the facilities available." --- healthcare.sql | 237 +++++++++++++++++ .../client_project/pojo/dto/HospitalDTO.java | 4 +- .../client_project/service/NursingHome.java | 24 -- .../service/NursingHomeService.java | 14 + .../client_project/service/UserLogin.java | 2 +- src/main/resources/application-dev.yml | 2 +- src/main/resources/static/js/beds.js | 241 +++++++++++++----- 7 files changed, 431 insertions(+), 93 deletions(-) create mode 100644 healthcare.sql delete mode 100644 src/main/java/com/cardiff/client_project/service/NursingHome.java create mode 100644 src/main/java/com/cardiff/client_project/service/NursingHomeService.java diff --git a/healthcare.sql b/healthcare.sql new file mode 100644 index 0000000..2b14790 --- /dev/null +++ b/healthcare.sql @@ -0,0 +1,237 @@ +/* + Navicat Premium Data Transfer + + Source Server : wyl + Source Server Type : MySQL + Source Server Version : 80031 + Source Host : localhost:3306 + Source Schema : health_care + + Target Server Type : MySQL + Target Server Version : 80031 + File Encoding : 65001 + + Date: 09/12/2024 10:09:27 +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for common_admin +-- ---------------------------- +DROP TABLE IF EXISTS `common_admin`; +CREATE TABLE `common_admin` ( + `id` int NOT NULL AUTO_INCREMENT, + `email` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `password` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `type` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `roleId` int NULL DEFAULT NULL, + `phone` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `status` int NULL DEFAULT NULL, + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of common_admin +-- ---------------------------- +INSERT INTO `common_admin` VALUES (1, '26497@qq.com', '$2a$10$5UzuKUxgR8H0RzLYrP.BUu8.76yKwMD4XkvJIu/xxB7AAHWfphFQm', 'commonAdmin', 1, '111', 'justnoww', 1); +INSERT INTO `common_admin` VALUES (2, '1234@qq.com', '$2a$10$iW/zeL9TLq55SHFaOfyfr.xFMvB4aD3CL2layeAlGC7CqZ9kcscA.', 'commonAdmin', 1, '123', 'BAa', 1); +INSERT INTO `common_admin` VALUES (3, '123cmy@qq.com', '$2a$10$u2KxNBaHuTVwX7KudUgyNelp8j2lymarXKkkUXfWBMRAgbPNryTuW', 'commonAdmin', 1, '123', 'cmy', 1); + +-- ---------------------------- +-- Table structure for device +-- ---------------------------- +DROP TABLE IF EXISTS `device`; +CREATE TABLE `device` ( + `id` int NOT NULL AUTO_INCREMENT, + `hospitalId` int NULL DEFAULT NULL, + `name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `type` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `freeTime` datetime NULL DEFAULT NULL, + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = DYNAMIC; + +-- ---------------------------- +-- Records of device +-- ---------------------------- +INSERT INTO `device` VALUES (1, 0, 'bed1', 'bed', '2024-12-02 09:51:12'); +INSERT INTO `device` VALUES (2, 2, 'bed2', 'bed', '2024-12-03 09:30:00'); +INSERT INTO `device` VALUES (3, 2, 'bed3', 'bed', '2025-12-05 10:30:35'); +INSERT INTO `device` VALUES (4, 2, 'instrument1', 'instrument', '2024-12-05 07:15:59'); +INSERT INTO `device` VALUES (5, 2, 'instrument5', 'instrument', '2024-12-05 10:30:00'); + +-- ---------------------------- +-- Table structure for hospital +-- ---------------------------- +DROP TABLE IF EXISTS `hospital`; +CREATE TABLE `hospital` ( + `id` int NOT NULL AUTO_INCREMENT, + `name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `amountPatient` int NULL DEFAULT NULL, + `maxAmount` int NULL DEFAULT NULL, + `type` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `address` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `phone` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `status` int NULL DEFAULT NULL, + `roleId` int NULL DEFAULT NULL, + `email` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `password` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `patientId` int NULL DEFAULT NULL, + `deviceId` int NULL DEFAULT NULL, + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of hospital +-- ---------------------------- +INSERT INTO `hospital` VALUES (1, 'hospital0', 3, 100, 'hospital', 'road', '145267', 1, 3, 'agag', '$2a$10$wvAZoj4V51MH/MLhVIrnG.NrY07/.Gn9Ar6JsyzRAubWtqbWzgKie', 0, 0); +INSERT INTO `hospital` VALUES (2, 'hospital1', 5, 200, 'hospital', 'beijing', '6371', 1, 3, 'soga', '$2a$10$wvAZoj4V51MH/MLhVIrnG.NrY07/.Gn9Ar6JsyzRAubWtqbWzgKie', 0, 0); +INSERT INTO `hospital` VALUES (3, 'hospital2', 10, 50, 'hospital', 'cardiff', '123', 1, 3, 'hospital2@qq.com', '$2a$10$wvAZoj4V51MH/MLhVIrnG.NrY07/.Gn9Ar6JsyzRAubWtqbWzgKie', 0, 0); + +-- ---------------------------- +-- Table structure for hospital_device +-- ---------------------------- +DROP TABLE IF EXISTS `hospital_device`; +CREATE TABLE `hospital_device` ( + `hospitalId` int NULL DEFAULT NULL, + `deviceId` int NULL DEFAULT NULL +) ENGINE = InnoDB CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of hospital_device +-- ---------------------------- + +-- ---------------------------- +-- Table structure for nurse +-- ---------------------------- +DROP TABLE IF EXISTS `nurse`; +CREATE TABLE `nurse` ( + `id` int NOT NULL AUTO_INCREMENT, + `name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `status` int NULL DEFAULT NULL, + `hospitalId` int NULL DEFAULT NULL, + `type` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `age` int NULL DEFAULT NULL, + `phone` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `email` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `address` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = DYNAMIC; + +-- ---------------------------- +-- Records of nurse +-- ---------------------------- +INSERT INTO `nurse` VALUES (1, 'nn', 0, 2, 'nurse', 23, '111', '23453', 'Cardiff'); +INSERT INTO `nurse` VALUES (2, 'Li Xiaoming', 1, 2, 'nurse', 25, '222', '4399', 'Cardiff'); +INSERT INTO `nurse` VALUES (3, 'Sun Hao', 1, 0, 'nurse', 24, '123', '23576', 'Bute'); +INSERT INTO `nurse` VALUES (4, 'Wang Xiaoming', 0, 2, 'nurse', 26, '333', '34578', 'Cardiff'); +INSERT INTO `nurse` VALUES (5, 'Tian Hao', 0, 2, 'nurse', 30, '321', '24353', 'Cardiff'); + +-- ---------------------------- +-- Table structure for patient +-- ---------------------------- +DROP TABLE IF EXISTS `patient`; +CREATE TABLE `patient` ( + `id` int NOT NULL AUTO_INCREMENT, + `name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `password` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `roleId` int NULL DEFAULT NULL, + `status` int NULL DEFAULT NULL, + `hospitalId` int NULL DEFAULT NULL, + `type` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `age` int NULL DEFAULT NULL, + `phone` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + `email` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL, + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = DYNAMIC; + +-- ---------------------------- +-- Records of patient +-- ---------------------------- +INSERT INTO `patient` VALUES (1, 'Li Ming', '$2a$10$obgmyiqAuhIkBjuw3bROr.LkCh.Nb70e4dL8lwKjSsPxS8gSpQxSC', 2, 1, 0, 'patient', 20, '135', 'wwgwg@outlook.com'); +INSERT INTO `patient` VALUES (2, 'Li Hua', '$2a$10$obgmyiqAuhIkBjuw3bROr.LkCh.Nb70e4dL8lwKjSsPxS8gSpQxSC', 2, 0, 0, 'patient', 21, '166', 'ss@qq.com'); +INSERT INTO `patient` VALUES (3, 'Huang Li', '$2a$10$obgmyiqAuhIkBjuw3bROr.LkCh.Nb70e4dL8lwKjSsPxS8gSpQxSC', 2, 0, 0, 'patient', 13, '111', '22@qq.com'); +INSERT INTO `patient` VALUES (4, 'Xia Ming', '$2a$10$obgmyiqAuhIkBjuw3bROr.LkCh.Nb70e4dL8lwKjSsPxS8gSpQxSC', 2, 1, 2, 'patient', 61, '15', '131@qq.com'); +INSERT INTO `patient` VALUES (5, 'Xia Yu', '$2a$10$obgmyiqAuhIkBjuw3bROr.LkCh.Nb70e4dL8lwKjSsPxS8gSpQxSC', 2, 1, 2, 'patient', 33, '14315', 'xx@qq.com'); + +-- ---------------------------- +-- Table structure for patient_hospital +-- ---------------------------- +DROP TABLE IF EXISTS `patient_hospital`; +CREATE TABLE `patient_hospital` ( + `hosptialId` int NULL DEFAULT NULL, + `patientId` int NULL DEFAULT NULL +) ENGINE = InnoDB CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of patient_hospital +-- ---------------------------- + +-- ---------------------------- +-- Table structure for role +-- ---------------------------- +DROP TABLE IF EXISTS `role`; +CREATE TABLE `role` ( + `roleId` int NULL DEFAULT NULL, + `type` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL +) ENGINE = InnoDB CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of role +-- ---------------------------- +INSERT INTO `role` VALUES (0, 'SUPER'); +INSERT INTO `role` VALUES (1, 'ADMIN'); +INSERT INTO `role` VALUES (2, 'PATIENT'); +INSERT INTO `role` VALUES (3, 'HOSPITAL'); + +-- ---------------------------- +-- Table structure for super_admin +-- ---------------------------- +DROP TABLE IF EXISTS `super_admin`; +CREATE TABLE `super_admin` ( + `id` int NOT NULL AUTO_INCREMENT, + `name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, + `password` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, + `roleId` int NULL DEFAULT NULL, + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of super_admin +-- ---------------------------- +INSERT INTO `super_admin` VALUES (1, '2649783657@qq.com', '$2a$10$5UzuKUxgR8H0RzLYrP.BUu8.76yKwMD4XkvJIu/xxB7AAHWfphFQm', 0); + +-- ---------------------------- +-- Procedure structure for reset_primary_keys +-- ---------------------------- +DROP PROCEDURE IF EXISTS `reset_primary_keys`; +delimiter ;; +CREATE PROCEDURE `reset_primary_keys`() +BEGIN + DECLARE done INT DEFAULT 0; + DECLARE current_id INT DEFAULT 0; + DECLARE cur CURSOR FOR + SELECT id FROM common_admin ORDER BY id; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; + + OPEN cur; + + -- 釿–°æ›´æ–°æ¯ä¸€æ¡è®°å½•çš„ ID + read_loop: LOOP + FETCH cur INTO current_id; + IF done THEN + LEAVE read_loop; + END IF; + + -- æ ¹æ®æ–°çš„æŽ’åºä¿®æ”¹ ID + UPDATE common_admin SET id = current_id - 1 WHERE id = current_id; + END LOOP; + + CLOSE cur; +END +;; +delimiter ; + +SET FOREIGN_KEY_CHECKS = 1; diff --git a/src/main/java/com/cardiff/client_project/pojo/dto/HospitalDTO.java b/src/main/java/com/cardiff/client_project/pojo/dto/HospitalDTO.java index 214ecc0..0bc6896 100644 --- a/src/main/java/com/cardiff/client_project/pojo/dto/HospitalDTO.java +++ b/src/main/java/com/cardiff/client_project/pojo/dto/HospitalDTO.java @@ -6,10 +6,10 @@ import lombok.Data; public class HospitalDTO { private int id; private String name; - private String address; private String location; + private String address; private String phone; private int totalBeds; private int availableBeds; private double occupancyRate; -} +} \ No newline at end of file diff --git a/src/main/java/com/cardiff/client_project/service/NursingHome.java b/src/main/java/com/cardiff/client_project/service/NursingHome.java deleted file mode 100644 index cf9d047..0000000 --- a/src/main/java/com/cardiff/client_project/service/NursingHome.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.cardiff.client_project.pojo.entity; - - -import lombok.Data; -import lombok.ToString; - -@Data -@ToString -public class NursingHome { - private int id; - private String name; - private String password; - private int maxAmount; - private int amountPatient; - private int patientId; - private int deviceId; - private String type; - private String address; - private String phone; - private String email; - private int roleId; - private int status; - -} diff --git a/src/main/java/com/cardiff/client_project/service/NursingHomeService.java b/src/main/java/com/cardiff/client_project/service/NursingHomeService.java new file mode 100644 index 0000000..c0e0026 --- /dev/null +++ b/src/main/java/com/cardiff/client_project/service/NursingHomeService.java @@ -0,0 +1,14 @@ +package com.cardiff.client_project.service; + +import com.cardiff.client_project.pojo.dto.HospitalDTO; +import com.cardiff.client_project.utils.Result; +import java.util.List; + +public interface NursingHomeService { + Result<List<HospitalDTO>> getAvailableBeds(); + Result<HospitalDTO> insertPatientInfo(HospitalDTO hospitalDTO); + Result<String> updatePatient(HospitalDTO hospitalDTO); + Result<String> deletePatientById(List<Integer> ids); + Result<List<HospitalDTO>> getAllPatients(); + Result<String> updateBedCount(int hospitalId, int currentPatients); +} \ No newline at end of file diff --git a/src/main/java/com/cardiff/client_project/service/UserLogin.java b/src/main/java/com/cardiff/client_project/service/UserLogin.java index 78a634e..d8d10e8 100644 --- a/src/main/java/com/cardiff/client_project/service/UserLogin.java +++ b/src/main/java/com/cardiff/client_project/service/UserLogin.java @@ -76,4 +76,4 @@ public class UserLogin implements UserDetailsService { } -} \ No newline at end of file +} \ No newline at end of file diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index ae3309b..cfed10b 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -1,6 +1,6 @@ healthcare: datasource: - url: jdbc:mysql://localhost:3306/health_care + url: jdbc:mysql://localhost:3306/healthcare port: 3306 username: root password: root \ No newline at end of file diff --git a/src/main/resources/static/js/beds.js b/src/main/resources/static/js/beds.js index 2484d0c..7f59480 100644 --- a/src/main/resources/static/js/beds.js +++ b/src/main/resources/static/js/beds.js @@ -1,31 +1,51 @@ $(document).ready(function () { + // Constants const API_BASE_URL = '/api/hospitals'; + const DEFAULT_ERROR = 'Operation failed. Please try again.'; + // Initialize page + setupNavBar(); loadHospitals(); initializeEventHandlers(); + function setupNavBar() { + const nav = ` + <nav class="top-nav"> + <div class="nav-brand">Digital Insight for Health</div> + <div class="nav-items"> + <a href="/dashboard" class="nav-link"> + <i class="fas fa-home"></i> Home + </a> + <a href="/beds" class="nav-link active"> + <i class="fas fa-bed"></i> Beds + </a> + <button class="nav-link sign-out" onclick="handleSignOut()"> + <i class="fas fa-sign-out-alt"></i> Sign Out + </button> + </div> + <div class="user-info"> + <span class="user-name">${localStorage.getItem('name') || 'User'}</span> + <span class="user-role">${localStorage.getItem('type') || 'Guest'}</span> + </div> + </nav> + `; + $('.main-container').prepend(nav); + } + function loadHospitals() { showLoading(); - $.ajax({ url: `${API_BASE_URL}/available`, method: 'GET', contentType: 'application/json', success: function(response) { if(response && response.code === 1) { - if (response.data && response.data.length > 0) { - updateTable(response.data); - } else { - showNoDataMessage(); - } + updateTable(response.data || []); } else { - showError('Error loading hospitals'); + showError(response.msg || DEFAULT_ERROR); } }, - error: function(xhr) { - showError('Failed to load hospitals'); - console.error('API Error:', xhr); - } + error: handleAjaxError }); } @@ -59,26 +79,7 @@ $(document).ready(function () { function initializeEventHandlers() { // Search Handler - $("#searchButton").click(function() { - const searchName = $("#searchName").val(); - - $.ajax({ - url: `${API_BASE_URL}/available`, - method: 'GET', - data: { name: searchName }, - success: function(response) { - if(response && response.code === 200) { - updateTable(response.data); - } else { - showError('Search failed'); - } - }, - error: function(xhr) { - showError('Search failed'); - console.error('Search Error:', xhr); - } - }); - }); + $("#searchButton").click(handleSearch); // Add Hospital Handler $("#addHospitalBtn").click(function() { @@ -94,40 +95,7 @@ $(document).ready(function () { }); // Form Submit Handler - $("#hospitalForm").submit(function(e) { - e.preventDefault(); - - const hospitalData = { - name: $("#hospitalName").val(), - location: $("#hospitalLocation").val(), - phone: $("#hospitalPhone").val(), - totalBeds: parseInt($("#totalBeds").val()), - availableBeds: parseInt($("#availableBeds").val()) - }; - - const id = $("#hospitalId").val(); - const method = id ? 'PUT' : 'POST'; - const url = id ? `${API_BASE_URL}/${id}` : API_BASE_URL; - - $.ajax({ - url: url, - method: method, - contentType: 'application/json', - data: JSON.stringify(hospitalData), - success: function(response) { - if(response.code === 200) { - $("#hospitalModal").fadeOut(); - loadHospitals(); - } else { - alert(response.msg || 'Operation failed'); - } - }, - error: function(xhr) { - alert('Error processing request'); - console.error('API Error:', xhr); - } - }); - }); + $("#hospitalForm").submit(handleFormSubmit); // Delete Handler $(document).on('click', '.delete-btn', function() { @@ -152,6 +120,65 @@ $(document).ready(function () { }); } + function handleSearch(event) { + event.preventDefault(); + const searchTerm = $("#searchName").val().trim(); + + $.ajax({ + url: `${API_BASE_URL}/search`, + method: 'POST', + contentType: 'application/json', + data: JSON.stringify({ name: searchTerm }), + success: function(response) { + if(response && response.code === 1) { + updateTable(response.data || []); + } else { + showError('No hospitals found'); + } + }, + error: handleAjaxError + }); + } + + function handleFormSubmit(event) { + event.preventDefault(); + const formData = { + name: $("#hospitalName").val(), + address: $("#hospitalLocation").val(), + phone: $("#hospitalPhone").val(), + maxAmount: parseInt($("#totalBeds").val()), + amountPatient: parseInt($("#totalBeds").val() - $("#availableBeds").val()), + type: 'hospital', + status: 1 + }; + + const id = $("#hospitalId").val(); + const method = id ? 'PUT' : 'POST'; + const url = id ? `${API_BASE_URL}/${id}` : API_BASE_URL; + + $.ajax({ + url: url, + method: method, + contentType: 'application/json', + data: JSON.stringify(formData), + success: function(response) { + if(response && response.code === 1) { + $("#hospitalModal").fadeOut(); + showSuccess('Operation successful'); + loadHospitals(); + } else { + showError(response.msg || DEFAULT_ERROR); + } + }, + error: handleAjaxError + }); + } + + function handleAjaxError(xhr, status, error) { + console.error('API Error:', {xhr, status, error}); + showError(DEFAULT_ERROR); + } + function showLoading() { $('#hospitalTable tbody').html('<tr><td colspan="8" class="text-center">Loading...</td></tr>'); } @@ -163,4 +190,88 @@ $(document).ready(function () { function showError(message) { $('#hospitalTable tbody').html(`<tr><td colspan="8" class="text-center text-danger">${message}</td></tr>`); } + + // Add CSS for new components + const styles = ` + .top-nav { + background: var(--primary-color); + padding: 1rem 2rem; + display: flex; + justify-content: space-between; + align-items: center; + margin-bottom: 2rem; + border-radius: 10px; + box-shadow: 0 2px 4px rgba(0,0,0,0.1); + } + + .nav-brand { + color: white; + font-size: 1.5rem; + font-weight: 600; + } + + .nav-items { + display: flex; + gap: 1rem; + align-items: center; + } + + .nav-link { + color: white; + text-decoration: none; + padding: 0.5rem 1rem; + border-radius: 6px; + transition: all 0.3s ease; + } + + .nav-link:hover, .nav-link.active { + background: rgba(255,255,255,0.1); + } + + .sign-out { + background: var(--danger-color); + border: none; + cursor: pointer; + } + + .user-info { + display: flex; + flex-direction: column; + align-items: flex-end; + color: white; + } + + .user-name { + font-weight: 500; + } + + .user-role { + font-size: 0.875rem; + opacity: 0.8; + } + + .success-message { + background: var(--success-color); + color: white; + padding: 1rem; + border-radius: 6px; + margin-bottom: 1rem; + display: flex; + align-items: center; + justify-content: space-between; + } + `; + + $('<style>').text(styles).appendTo('head'); + + // Initialize tooltips and other UI enhancements + $('[data-toggle="tooltip"]').tooltip(); + + // Add fade effects for smoother transitions + $('.table-container').hide().fadeIn(); }); + +function handleSignOut() { + localStorage.clear(); + window.location.href = '/login'; +} -- GitLab From 8f27ec0d2d7b56ce67a0c71b9fc3ac3aa32b1e0b Mon Sep 17 00:00:00 2001 From: wyl <wangyulong990316@outlook.com> Date: Wed, 11 Dec 2024 12:49:17 +0000 Subject: [PATCH 3/3] update system construction --- .../client_project/config/WebSecurityConfig.java | 6 +++--- src/main/resources/application-dev.yml | 6 +++--- src/main/resources/application.yml | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/cardiff/client_project/config/WebSecurityConfig.java b/src/main/java/com/cardiff/client_project/config/WebSecurityConfig.java index 33028ca..fe2fac1 100644 --- a/src/main/java/com/cardiff/client_project/config/WebSecurityConfig.java +++ b/src/main/java/com/cardiff/client_project/config/WebSecurityConfig.java @@ -51,9 +51,9 @@ public class WebSecurityConfig{ // Turn off the csrf mechanism, you can use get login, otherwise you can only use post http .csrf(csrf-> csrf.disable()) .authorizeHttpRequests(requests -> requests - .requestMatchers("/device.html").hasRole("ADMIN") - //+.requestMatchers("/superAdminView.html").hasRole("SUPER") - .requestMatchers("/commonUser.html").authenticated() + .requestMatchers("/superAdminView.html").hasRole("SUPER") + .requestMatchers("/hospitalView.html").hasRole("HOSPITAL") + .requestMatchers("/admin.html").hasRole("ADMIN") .anyRequest().permitAll() ) diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 016cd27..0b86801 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -1,6 +1,6 @@ healthcare: datasource: - url: jdbc:mariadb://localhost:3307/healthcare - port: 3307 + url: jdbc:mariadb://localhost:3306/healthcare?createDatabaseIfNotExist=true + port: 3306 username: root - password: root \ No newline at end of file + password: comsc \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index ccda0b6..6263e3e 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -8,12 +8,12 @@ spring: username: ${healthcare.datasource.username} password: ${healthcare.datasource.password} port: ${healthcare.datasource.port} - sql: - init: - schema-locations: classpath:schema.sql - data-locations: classpath:data.sql - platform: mariadb - mode: always + sql: + init: + schema-locations: classpath:schema.sql + data-locations: classpath:data.sql + platform: mariadb + mode: always thymeleaf: prefix: classpath:/templates/ suffix: .html -- GitLab