当前位置:   article > 正文

数据库大作业实训项目-民宿管理_高级数据库应用实验(oracle)项目有什么

高级数据库应用实验(oracle)项目有什么

        Oracle数据库实训项目-民宿管理,纯sql数据库操作相关,没有前端后端。触发器等相关功能实现纯粹为了使用触发器而使用的触发器,实际上无需触发器也能实现。


  •  Mysql数据库实验及练习题相关

        MySQL 数据库和表的管理-数据库实验一

        MySQL连接查询、索引、视图-数据库实验二、实验三

        MySQL约束、触发器-数据库实验四

        MYSQL存储过程和存储函数-数据库实验五

                MySQL批量随机生成name、TEL、idNumber

        MYSQL数据库的安全管理-数据库实验六

                MYSQL数据库安全性练习题

        MYSQL数据库的备份与恢复-数据库实验七

        MYSQL数据库设计题-窗帘店


目录

 Mysql数据库实验及练习题相关

①建表空间、建表、插入数据相关sql如下:

②各触发器实现的相关功能及测试sql如下:

一、项目概述

(一)项目简介与背景

(二)项目功能

        2.1房间管理        

2.2入住管理

2.3餐饮

2.4活动管理

2.5评价模块

2.6留言板块

二、需求分析

(一)业务流程图

(二)数据流程

2.1数据流图

(1)顶层数据流图

(2)二级数据流图

三、数据库概念模型

四、数据库物理模型

(一)物理模型

(二)数据库表

(三)表空间创建

3.1 永久表空间 HomeStay1_data

3.2 临时表空间 HomeStay_temp

(四)用户创建

4.1 创建管理员用户

4.2 创建前台用户 

(五)关键应用编程实现

5.1 预定功能

5.2 入住办理功能

5.3 活动报名功能

5.4 新建房间类型

5.5 费用结算功能

5.6 退房办理

5.7 序列与触发器

(六)测试

6.1 权限管理

        6.1.2 授予前台用户proscenium  resource和connect权限,允许登录和创建实体及对住客表、菜品表、订单表、入住表、用餐表、费用表的insert、update、select、delete权限;对房间表、房间类型表的select权限。

        6.1.3 增         

        6.1.4 删

        6.1.5 改

        6.1.6 查

6.2 数据完整性

6.3 存储过程结构测试

        6.3.1 录入房间信息测试

6.3.2 查询房间信息测试

6.3.3 住客注册功能测试

6.3.4 餐饮信息录入测试

6.3.5 住客预定功能测试

6.3.6入住办理功能测试

6.3.7 用餐信息录入测试

6.3.8 费用结算测试

6.3.9 活动报名测试

6.3.10 留言测试

6.3.11 评价测试

6.3.12 退房办理

五、总结


①建表空间、建表、插入数据相关sql如下:

  1. --永久表空间 HomeStay_data
  2. CREATE TABLESPACE HomeStay1_data DATAFILE 'D:\Data\local\sql\HomeStay1\HomeStay1_data.dbf'
  3. SIZE 500M AUTOEXTEND ON NEXT 100M MAXSIZE UNLIMITED ONLINE;
  4. --drop tablespace HomeStay1_data;
  5. --alter tablespace HomeStay1_data datafile 'D:\Data\local\sql\HomeStay1\HomeStay1_data.dbf' online;
  6. --临时表空间 HomeStay_temp
  7. CREATE TEMPORARY TABLESPACE HomeStay1_temp TEMPFILE
  8. 'D:\Data\local\sql\HomeStay1\HomeStay1_temp.dbf' SIZE 500M AUTOEXTEND ON NEXT 100M MAXSIZE 500M;
  9. --索引表空间 HomeStay_idx
  10. CREATE TABLESPACE HomeStay1_idx DATAFILE 'D:\Data\local\sql\HomeStay1\HomeStay1_idx.dbf' SIZE 500M AUTOEXTEND OFF;
  11. --用户创建
  12. --CREATE USER customer IDENTIFIED BY customer123 TEMPORARY TABLESPACE HomeStay_temp1;
  13. --GRANT CONNECT TO customer;
  14. -- 管理员user创建
  15. CREATE USER manager1 IDENTIFIED BY 123 DEFAULT TABLESPACE HomeStay1_data QUOTA UNLIMITED ON HomeStay1_data QUOTA UNLIMITED ON HomeStay1_idx TEMPORARY TABLESPACE HomeStay1_temp;
  16. GRANT dba TO manager1;
  17. --create user proscenium identified by proscenium123 TEMPORARY TABLESPACE HomeStay_temp;
  18. --GRANT CONNECT TO proscenium;
  19. --创建表
  20. /*==============================================================*/
  21. /* DBMS name: ORACLE Version 11g */
  22. /* Created on: 2022/9/6 10:55:37 */
  23. /*==============================================================*/
  24. /*==============================================================*/
  25. /* Table: activity */
  26. /*==============================================================*/
  27. create table activity
  28. (
  29. activity_code VARCHAR2(16) not null,
  30. activity_name VARCHAR2(32),
  31. activity_type VARCHAR2(32),
  32. activity_start_time DATE,
  33. activity_end_time DATE,
  34. activity_position VARCHAR2(64),
  35. activity_content VARCHAR2(240),
  36. activity_price FLOAT(16),
  37. constraint PK_ACTIVITY primary key (activity_code)
  38. );
  39. comment on table activity is
  40. '民宿中各种活动的相关信息。';
  41. /*==============================================================*/
  42. /* Table: activity_registration */
  43. /*==============================================================*/
  44. create table activity_registration
  45. (
  46. customer_code VARCHAR2(16) not null,
  47. activity_code VARCHAR2(16) not null,
  48. activity_recode VARCHAR2(16) not null,
  49. constraint PK_ACTIVITY_REGISTRATION primary key (customer_code, activity_code)
  50. );
  51. comment on table activity_registration is
  52. '住户报名参加活动。';
  53. /*==============================================================*/
  54. /* Index: activity_registration_FK */
  55. /*==============================================================*/
  56. create index activity_registration_FK on activity_registration (
  57. customer_code ASC
  58. );
  59. /*==============================================================*/
  60. /* Index: activity_registration2_FK */
  61. /*==============================================================*/
  62. create index activity_registration2_FK on activity_registration (
  63. activity_code ASC
  64. );
  65. /*==============================================================*/
  66. /* Table: book */
  67. alter table book drop column order_code;
  68. alter table book add order_code varchar2(16) not null after room_type_code;
  69. select * from book;
  70. /*==============================================================*/
  71. create table book
  72. (
  73. reservation_code VARCHAR2(16) not null,
  74. customer_code VARCHAR2(16) not null,
  75. room_type_code VARCHAR2(16) not null,
  76. order_code VARCHAR2(16) not null,
  77. lease_way VARCHAR2(1),
  78. reservation_check_in_time DATE,
  79. reservation_check_out_time DATE,
  80. constraint PK_BOOK primary key (reservation_code)
  81. );
  82. comment on table book is
  83. '客户进行民宿预定。';
  84. /*==============================================================*/
  85. /* Index: 住客预定_FK */
  86. /*==============================================================*/
  87. create index 住客预定_FK on book (
  88. customer_code ASC
  89. );
  90. /*==============================================================*/
  91. /* Index: 房间预定_FK */
  92. /*==============================================================*/
  93. create index 房间预定_FK on book (
  94. room_type_code ASC
  95. );
  96. /*==============================================================*/
  97. /* Table: check_in */
  98. /*==============================================================*/
  99. create table check_in
  100. (
  101. check_in_code VARCHAR2(16) not null,
  102. room_code VARCHAR2(16) not null,
  103. order_code VARCHAR2(16) not null,
  104. cost_code VARCHAR2(16),
  105. check_in_person_name VARCHAR2(32),
  106. check_in_person_id_card varchar2(18),
  107. check_in_person_tel NUMBER(15),
  108. check_in_time DATE,
  109. check_out_tim DATE,
  110. check_in_lease_way VARCHAR2(1),
  111. constraint PK_CHECK_IN primary key (check_in_code)
  112. );
  113. comment on table check_in is
  114. '住户租房基本信息。';
  115. /*==============================================================*/
  116. /* Index: 订单入住_FK */
  117. /*==============================================================*/
  118. create index 订单入住_FK on check_in (
  119. order_code ASC
  120. );
  121. /*==============================================================*/
  122. /* Index: 入住费用_FK */
  123. /*==============================================================*/
  124. create index 入住费用_FK on check_in (
  125. cost_code ASC
  126. );
  127. /*==============================================================*/
  128. /* Index: 入住房间_FK */
  129. /*==============================================================*/
  130. create index 入住房间_FK on check_in (
  131. room_code ASC
  132. );
  133. /*==============================================================*/
  134. /* Table: cost */
  135. /*==============================================================*/
  136. create table cost
  137. (
  138. cost_code VARCHAR2(16) not null,
  139. check_in_code VARCHAR2(16),
  140. dinning_cost FLOAT(16),
  141. room_cost FLOAT(16),
  142. total_cost FLOAT(16),
  143. constraint PK_COST primary key (cost_code)
  144. );
  145. comment on table cost is
  146. '客户入住对应订单相关费用。';
  147. /*==============================================================*/
  148. /* Index: 入住费用2_FK */
  149. /*==============================================================*/
  150. create index 入住费用2_FK on cost (
  151. check_in_code ASC
  152. );
  153. /*==============================================================*/
  154. /* Table: customer */
  155. /*==============================================================*/
  156. create table customer
  157. (
  158. customer_code VARCHAR2(16) not null,
  159. customer_name VARCHAR2(32),
  160. gender VARCHAR2(1),
  161. id varchar2(18),
  162. tel VARCHAR2(15),
  163. constraint PK_CUSTOMER primary key (customer_code)
  164. );
  165. comment on table customer is
  166. '进入民宿的租户。';
  167. /*==============================================================*/
  168. /* Table: customer_comment */
  169. /*==============================================================*/
  170. create table customer_comment
  171. (
  172. comment_code VARCHAR2(16) not null,
  173. customer_code VARCHAR2(16) not null,
  174. comment_score NUMBER(1),
  175. comment_content VARCHAR2(240),
  176. constraint PK_CUSTOMER_COMMENT primary key (comment_code)
  177. );
  178. comment on table customer_comment is
  179. '住户对与民宿的相关评价,可以给出自己的评分与评价内容。';
  180. /*==============================================================*/
  181. /* Index: 客户评价_FK */
  182. /*==============================================================*/
  183. create index 客户评价_FK on customer_comment (
  184. customer_code ASC
  185. );
  186. /*==============================================================*/
  187. /* Table: customer_order */
  188. /*==============================================================*/
  189. create table customer_order
  190. (
  191. order_code VARCHAR2(16) not null,
  192. customer_code VARCHAR2(16) not null,
  193. reservation_code VARCHAR2(16) not null,
  194. order_time DATE,
  195. constraint PK_CUSTOMER_ORDER primary key (order_code)
  196. );
  197. comment on table customer_order is
  198. '客户入住相关订单。';
  199. /*==============================================================*/
  200. /* Index: 订单预定_FK */
  201. /*==============================================================*/
  202. create index 订单预定_FK on customer_order (
  203. reservation_code ASC
  204. );
  205. /*==============================================================*/
  206. /* Index: 客户订单_FK */
  207. /*==============================================================*/
  208. create index 客户订单_FK on customer_order (
  209. customer_code ASC
  210. );
  211. /*==============================================================*/
  212. /* Table: dinning */
  213. /*==============================================================*/
  214. create table dinning
  215. (
  216. dinning_code VARCHAR2(16) not null,
  217. check_in_code VARCHAR2(16),
  218. food_code VARCHAR2(16) not null,
  219. dinning_time DATE,
  220. constraint PK_DINNING primary key (dinning_code)
  221. );
  222. comment on table dinning is
  223. '入住的客户在民宿中进行用餐的信息。';
  224. /*==============================================================*/
  225. /* Index: 用餐_FK */
  226. /*==============================================================*/
  227. create index 用餐_FK on dinning (
  228. check_in_code ASC
  229. );
  230. /*==============================================================*/
  231. /* Index: 用餐合计_FK */
  232. /*==============================================================*/
  233. create index 用餐合计_FK on dinning (
  234. food_code ASC
  235. );
  236. /*==============================================================*/
  237. /* Table: dishes */
  238. /*==============================================================*/
  239. create table dishes
  240. (
  241. food_code VARCHAR2(16) not null,
  242. food_name VARCHAR2(32),
  243. food_price FLOAT(32),
  244. food_content VARCHAR2(240),
  245. constraint PK_DISHES primary key (food_code)
  246. );
  247. comment on table dishes is
  248. '入住的客户在民宿中可以消费的具体餐品。';
  249. /*==============================================================*/
  250. /* Table: leave_message */
  251. /*==============================================================*/
  252. create table leave_message
  253. (
  254. message_code VARCHAR2(16) not null,
  255. customer_code VARCHAR2(16) not null,
  256. message_tinfo VARCHAR2(240),
  257. message_time DATE,
  258. constraint PK_LEAVE_MESSAGE primary key (message_code)
  259. );
  260. comment on table leave_message is
  261. '客户可以对民宿进行留言。';
  262. /*==============================================================*/
  263. /* Index: 客户留言_FK */
  264. /*==============================================================*/
  265. create index 客户留言_FK on leave_message (
  266. customer_code ASC
  267. );
  268. /*==============================================================*/
  269. /* Table: room */
  270. /*==============================================================*/
  271. create table room
  272. (
  273. room_code VARCHAR2(16) not null,
  274. room_type_code VARCHAR2(16) not null,
  275. room_number VARCHAR2(32),
  276. check_out_confirm VARCHAR2(1),
  277. room_name VARCHAR2(10),
  278. constraint PK_ROOM primary key (room_code)
  279. );
  280. comment on table room is
  281. '住户已经入住的房间信息。';
  282. /*==============================================================*/
  283. /* Index: 房间属别_FK */
  284. /*==============================================================*/
  285. create index 房间属别_FK on room (
  286. room_type_code ASC
  287. );
  288. /*==============================================================*/
  289. /* Table: room_type */
  290. /*==============================================================*/
  291. create table room_type
  292. (
  293. room_type_code VARCHAR2(16) not null,
  294. room_type_name VARCHAR2(32),
  295. room_day_price FLOAT(32),
  296. room_short_price FLOAT(32),
  297. room_long_price FLOAT(32),
  298. room_type_info VARCHAR2(240),
  299. room_type_sums NUMBER(5),
  300. constraint PK_ROOM_TYPE primary key (room_type_code)
  301. );
  302. comment on table room_type is
  303. '民宿的各种房间信息。';
  304. alter table activity_registration
  305. add constraint FK_ACTIVITY_ACTIVITY__CUSTOMER foreign key (customer_code)
  306. references customer (customer_code);
  307. alter table activity_registration
  308. add constraint FK_ACTIVITY_ACTIVITY__ACTIVITY foreign key (activity_code)
  309. references activity (activity_code);
  310. alter table book
  311. add constraint FK_BOOK_住客预定_CUSTOMER foreign key (customer_code)
  312. references customer (customer_code);
  313. alter table book
  314. add constraint FK_BOOK_房间预定_ROOM_TYP foreign key (room_type_code)
  315. references room_type (room_type_code);
  316. alter table check_in
  317. add constraint FK_CHECK_IN_入住房间_ROOM foreign key (room_code)
  318. references room (room_code);
  319. alter table check_in
  320. add constraint FK_CHECK_IN_入住费用_COST foreign key (cost_code)
  321. references cost (cost_code);
  322. alter table check_in
  323. add constraint FK_CHECK_IN_订单入住_CUSTOMER foreign key (order_code)
  324. references customer_order (order_code);
  325. alter table cost
  326. add constraint FK_COST_入住费用2_CHECK_IN foreign key (check_in_code)
  327. references check_in (check_in_code);
  328. alter table customer_comment
  329. add constraint FK_CUSTOMER_客户评价_CUSTOMER foreign key (customer_code)
  330. references customer (customer_code);
  331. alter table customer_order
  332. add constraint FK_CUSTOMER_客户订单_CUSTOMER foreign key (customer_code)
  333. references customer (customer_code);
  334. alter table customer_order
  335. add constraint FK_CUSTOMER_订单预定_BOOK foreign key (reservation_code)
  336. references book (reservation_code);
  337. alter table dinning
  338. add constraint FK_DINNING_用餐_CHECK_IN foreign key (check_in_code)
  339. references check_in (check_in_code);
  340. alter table dinning
  341. add constraint FK_DINNING_用餐合计_DISHES foreign key (food_code)
  342. references dishes (food_code);
  343. alter table leave_message
  344. add constraint FK_LEAVE_ME_客户留言_CUSTOMER foreign key (customer_code)
  345. references customer (customer_code);
  346. alter table room
  347. add constraint FK_ROOM_房间属别_ROOM_TYP foreign key (room_type_code)
  348. references room_type (room_type_code);
  349. alter table activity_registration
  350. drop constraint FK_ACTIVITY_ACTIVITY__CUSTOMER;
  351. alter table activity_registration
  352. drop constraint FK_ACTIVITY_ACTIVITY__ACTIVITY;
  353. alter table book
  354. drop constraint FK_BOOK_住客预定_CUSTOMER;
  355. alter table book
  356. drop constraint FK_BOOK_房间预定_ROOM_TYP;
  357. alter table check_in
  358. drop constraint FK_CHECK_IN_入住房间_ROOM;
  359. alter table check_in
  360. drop constraint FK_CHECK_IN_入住费用_COST;
  361. alter table check_in
  362. drop constraint FK_CHECK_IN_订单入住_CUSTOMER;
  363. alter table cost
  364. drop constraint FK_COST_入住费用2_CHECK_IN;
  365. alter table customer_comment
  366. drop constraint FK_CUSTOMER_客户评价_CUSTOMER;
  367. alter table customer_order
  368. drop constraint FK_CUSTOMER_客户订单_CUSTOMER;
  369. alter table customer_order
  370. drop constraint FK_CUSTOMER_订单预定_BOOK;
  371. alter table dinning
  372. drop constraint FK_DINNING_用餐_CHECK_IN;
  373. alter table dinning
  374. drop constraint FK_DINNING_用餐合计_DISHES;
  375. alter table leave_message
  376. drop constraint FK_LEAVE_ME_客户留言_CUSTOMER;
  377. alter table room
  378. drop constraint FK_ROOM_房间属别_ROOM_TYP;
  379. --为顾客电话创建索引
  380. create index index_tel on customer('tel') TABLESPACE HomeStay_idx;
  381. -- drop table activity cascade constraints;
  382. --
  383. -- drop index activity_registration2_FK;
  384. --
  385. -- drop index activity_registration_FK;
  386. --
  387. -- drop table activity_registration cascade constraints;
  388. --
  389. -- drop index 房间预定_FK;
  390. --
  391. -- drop index 住客预定_FK;
  392. --
  393. -- drop table book cascade constraints;
  394. --
  395. -- drop index 入住房间_FK;
  396. --
  397. -- drop index 入住费用_FK;
  398. --
  399. -- drop index 订单入住_FK;
  400. --
  401. -- drop table check_in cascade constraints;
  402. --
  403. -- drop index 入住费用2_FK;
  404. --
  405. -- drop table cost cascade constraints;
  406. --
  407. -- drop table customer cascade constraints;
  408. --
  409. -- drop index 客户评价_FK;
  410. --
  411. -- drop table customer_comment cascade constraints;
  412. --
  413. -- drop index 客户订单_FK;
  414. --
  415. -- drop index 订单预定_FK;
  416. --
  417. -- drop table customer_order cascade constraints;
  418. --
  419. -- drop index 用餐合计_FK;
  420. --
  421. -- drop index 用餐_FK;
  422. --
  423. -- drop table dinning cascade constraints;
  424. --
  425. -- drop table dishes cascade constraints;
  426. --
  427. -- drop index 客户留言_FK;
  428. --
  429. -- drop table leave_message cascade constraints;
  430. --
  431. -- drop index 房间属别_FK;
  432. --
  433. -- drop table room cascade constraints;
  434. --
  435. -- drop table room_type cascade constraints;
  436. --序列与触发器
  437. create sequence AUTOID1
  438. increment by 1
  439. start with 100001
  440. nomaxvalue
  441. nocycle
  442. cache 10;
  443. /*触发器用户编号生成*/
  444. CREATE or replace TRIGGER MS_AutoID
  445. BEFORE INSERT ON customer
  446. FOR EACH ROW begin
  447. SELECT ('ms'||trim(to_char(AUTOID1.NEXTVAL,'000000')))
  448. INTO :NEW.CUSTOMER_CODE
  449. FROM DUAL;
  450. dbms_output.put_line('客户编号为'||:NEW.CUSTOMER_CODE);
  451. End;
  452. /
  453. create sequence AUTOID2
  454. increment by 1
  455. start with 10001
  456. nomaxvalue
  457. nocycle
  458. cache 10;
  459. /*住客预定编号生成*/
  460. CREATE or replace TRIGGER YD_AutoID
  461. BEFORE INSERT ON book
  462. FOR EACH ROW begin
  463. SELECT ('yd'||trim(to_char(AUTOID2.NEXTVAL,'000000')))
  464. INTO :NEW.RESERVATION_CODE
  465. FROM DUAL;
  466. dbms_output.put_line('预订编号为'||:NEW.RESERVATION_CODE);
  467. End;
  468. /
  469. create sequence AUTOID3
  470. increment by 1
  471. start with 10001
  472. nomaxvalue
  473. nocycle
  474. cache 10;
  475. /*订单编号生成*/
  476. CREATE or replace TRIGGER DD_AutoID
  477. BEFORE INSERT ON customer_order
  478. FOR EACH ROW begin
  479. SELECT ('dd'||trim(to_char(AUTOID3.NEXTVAL,'000000')))
  480. INTO :NEW.ORDER_CODE
  481. FROM DUAL;
  482. dbms_output.put_line('订单编号为'||:NEW.ORDER_CODE);
  483. End;
  484. /
  485. create sequence AUTOID4
  486. increment by 1
  487. start with 10001
  488. nomaxvalue
  489. nocycle
  490. cache 10;
  491. /*入住编号生成*/
  492. CREATE or replace TRIGGER RZ_AutoID
  493. BEFORE INSERT ON CHECK_IN
  494. FOR EACH ROW begin
  495. SELECT ('rz'||trim(to_char(AUTOID4.NEXTVAL,'000000')))
  496. INTO :NEW.CHECK_IN_CODE
  497. FROM DUAL;
  498. dbms_output.put_line('入住编号为'||:NEW.CHECK_IN_CODE);
  499. End;
  500. /
  501. create sequence AUTOID5
  502. increment by 1
  503. start with 10001
  504. nomaxvalue
  505. nocycle
  506. cache 10;
  507. /*用餐编号生成*/
  508. CREATE or replace TRIGGER DIN_AutoID
  509. BEFORE INSERT ON dinning
  510. FOR EACH ROW begin
  511. SELECT ('yc'||trim(to_char(AUTOID5.NEXTVAL,'000000')))
  512. INTO :NEW.DINNING_CODE
  513. FROM DUAL;
  514. dbms_output.put_line('订单编号为'||:NEW.DINNING_CODE);
  515. End;
  516. /
  517. create sequence AUTOID6
  518. increment by 1
  519. start with 10001
  520. nomaxvalue
  521. nocycle
  522. cache 10;
  523. /*活动报名编号生成*/
  524. CREATE or replace TRIGGER BM_AutoID
  525. BEFORE INSERT ON activity_registration
  526. FOR EACH ROW begin
  527. SELECT ('bm'||trim(to_char(AUTOID6.NEXTVAL,'00000')))
  528. INTO :NEW.ACTIVITY_RECODE
  529. FROM DUAL;
  530. End;
  531. /
  532. create sequence AUTOID7
  533. increment by 1
  534. start with 10001
  535. nomaxvalue
  536. nocycle
  537. cache 10;
  538. /*留言编号生成*/
  539. CREATE or replace TRIGGER LY_AutoID
  540. BEFORE INSERT ON leave_message
  541. FOR EACH ROW begin
  542. SELECT ('ly'||trim(to_char(AUTOID7.NEXTVAL,'000000')))
  543. INTO :NEW.MESSAGE_CODE
  544. FROM DUAL;
  545. End;
  546. /
  547. create sequence AUTOID8
  548. increment by 1
  549. start with 10001
  550. nomaxvalue
  551. nocycle
  552. cache 10;
  553. /*评价编号生成*/
  554. CREATE or replace TRIGGER PJ_AutoID
  555. BEFORE INSERT ON customer_comment
  556. FOR EACH ROW begin
  557. SELECT ('pj'||trim(to_char(AUTOID8.NEXTVAL,'000000')))
  558. INTO :NEW.COMMENT_CODE
  559. FROM DUAL;
  560. End;
  561. /
  562. create sequence AUTOID9
  563. increment by 1
  564. start with 10001
  565. nomaxvalue
  566. nocycle
  567. cache 10;
  568. /*房间类型编号生成*/
  569. CREATE or replace TRIGGER LX_AutoID
  570. BEFORE INSERT ON room_type
  571. FOR EACH ROW begin
  572. SELECT ('lx'||trim(to_char(AUTOID9.NEXTVAL,'000000')))
  573. INTO :NEW.ROOM_TYPE_CODE
  574. FROM DUAL;
  575. End;
  576. /
  577. create sequence AUTOID10
  578. increment by 1
  579. start with 10001
  580. nomaxvalue
  581. nocycle
  582. cache 10;
  583. /*活动编号生成*/
  584. CREATE or replace TRIGGER HD_AutoID
  585. BEFORE INSERT ON activity
  586. FOR EACH ROW begin
  587. SELECT ('hd'||trim(to_char(AUTOID10.NEXTVAL,'000000')))
  588. INTO :NEW.ACTIVITY_CODE
  589. FROM DUAL;
  590. End;
  591. /
  592. select * from customer;
  593. delete from customer;
  594. INSERT INTO customer(customer_name, gender, id, tel) VALUES ('翁乾岚', 'M', '321001199512012472', '13554532227');
  595. INSERT INTO customer(customer_name, gender, id, tel) VALUES ('胡雪擎', 'F', '320112199512033375', '13644089109');
  596. INSERT INTO customer(customer_name, gender, id, tel) VALUES ('殷苑', 'F', '320112199911119251', '13509455854');
  597. INSERT INTO customer(customer_name, gender, id, tel) VALUES ('贝海', 'F', '321001199511110342', '13718678110');
  598. INSERT INTO customer(customer_name, gender, id, tel) VALUES ('楮瑜冷', 'M', '321102199511119990', '13505506023');
  599. INSERT INTO customer(customer_name, gender, id, tel) VALUES ('经经磊', 'F', '321001199912011919', '13602902300');
  600. INSERT INTO customer(customer_name, gender, id, tel) VALUES ('章柏', 'F', '320112199312018246', '13759350230');
  601. INSERT INTO customer(customer_name, gender, id, tel) VALUES ('冯彤祥', 'M', '320021199509036207', '13663741513');
  602. INSERT INTO customer(customer_name, gender, id, tel) VALUES ('何沛', 'F', '321102199911117494', '13660206154');
  603. INSERT INTO customer(customer_name, gender, id, tel) VALUES ('危熠', 'M', '321102199311112316', '13637685244');
  604. -- 餐品
  605. select * from dishes;
  606. insert into dishes values (1, '中式精选套餐A', 119, '山药排骨汤,江山鱼,萝卜炖牛腩,红烧豆腐,上汤菠菜,香煎野菜包,热带水果盘');
  607. insert into dishes values (2, '中式精选套餐B', 129, '槟榔花猪肚汤,话梅小排,芹菜炒鱿鱼,外婆豆腐,蒜蓉炒鸡叶菜,香煎葱油饼,热带水果盘');
  608. insert into dishes values (3, '经济套餐',99, '鱼子酱,牛尾汤,红烧鱼片,羔羊腿,蔬菜,布丁,咖啡');
  609. insert into dishes values (4, '情侣套餐', 199, '熏鲑鱼,奶油茄子汤,牛肉蔬菜汤,酒酿鱼,烤牛肉,冷肉拼香肠,酿青椒,酸黄瓜,冰淇淋,咖啡');
  610. -- 房间类型
  611. delete from room_type;
  612. insert into room_type(room_type_name, room_day_price, room_short_price, room_long_price, room_type_info, room_type_sums)
  613. values( '单人间', 59, 49, 45, '单人床,一个卫生间,无阳台,有电视电脑,24h热水', 5); -- lx001
  614. insert into room_type(room_type_name, room_day_price, room_short_price, room_long_price, room_type_info, room_type_sums)
  615. values( '标准间', 99, 89, 79, '单人床两张, 一个卫生间,有阳台,有电视电脑,24h热水', 3);
  616. insert into room_type(room_type_name, room_day_price, room_short_price, room_long_price, room_type_info, room_type_sums)
  617. values( '豪华情侣房', 119, 109, 99, '大床房,一个卫生间,有阳台,有电视电脑,24h热水', 2);
  618. insert into room_type(room_type_name, room_day_price, room_short_price, room_long_price, room_type_info, room_type_sums)
  619. values( '家庭复式', 349, 319, 299, '两室两床,最多可住4人,有客厅,有沙发,有电视电脑,有阳台,24h热水', 1);
  620. select * from room_type;
  621. -- 入住房间
  622. delete from room;
  623. insert into room values('1001', 'lx001', '101', 'N', '凌霄斋');
  624. insert into room values('1002', 'lx001', '102', 'N', '云梦阁');
  625. insert into room values('1003', 'lx001', '103', 'N', '碧水间');
  626. insert into room values('1004', 'lx001', '201', 'N', '晴天阁');
  627. insert into room values('1005', 'lx001', '202', 'N', '凌霄斋');
  628. insert into room values('1006', 'lx002', '105', 'N', '月亮湾');
  629. insert into room values('1007', 'lx002', '106', 'N', '天涯间');
  630. insert into room values('1008', 'lx002', '203', 'N', '别云间');
  631. insert into room values('1009', 'lx003', '301', 'N', '郁宁间');
  632. insert into room values('1010', 'lx003', '302', 'N', '赏心阁');
  633. insert into room values('1011', 'lx004', '108', 'N', '披星斋');
  634. select * from room;
  635. -- 活动
  636. delete from activity;
  637. insert into activity values('hd1', '山里一日游','出游',date'2022-10-1',date'2022-10-6','庐山','欣赏风景','36.5');
  638. insert into activity(activity_name, activity_type, activity_start_time, activity_end_time, activity_position, activity_content, activity_price)
  639. values('山里一日游','出游',date'2022-10-1',date'2022-10-6','庐山','欣赏风景','36.5');
  640. insert into activity(activity_name, activity_type, activity_start_time, activity_end_time, activity_position, activity_content, activity_price)
  641. values('丛林探险','出游',date'2022-11-1',date'2022-11-7','国家森林公园','游玩','66.7');
  642. select * from activity;

②各触发器实现的相关功能及测试sql如下:

  1. -- 用户注册
  2. CREATE OR REPLACE PROCEDURE customers_reg(
  3. customer_name customer.customer_name%type,
  4. gender customer.gender%type,
  5. id1 customer.id%type,
  6. tel1 customer.tel%type)
  7. as
  8. cnm number;
  9. BEGIN
  10. select count(*) into cnm from customer where id1=customer.id;
  11. if cnm>0 then
  12. dbms_output.put_line('该用户已注册,请勿重复注册!');
  13. return;
  14. end if;
  15. INSERT INTO customer(customer_name, gender, id, tel) VALUES (customer_name,gender,id1,tel1);
  16. dbms_output.put_line('注册成功');
  17. END customers_reg;
  18. -- 测试
  19. call customers_reg('丽江好', 'M', '123456', '110');
  20. select * from customer;
  21. -- 预定
  22. CREATE OR REPLACE PROCEDURE Customer_book(
  23. c_code varchar2, rt_code varchar2, --顾客编号 房间类型编号 订单编号
  24. l_way varchar2,re_citime DATE, re_cotime DATE) -- 租聘方式 预定入住时间 预定退房时间
  25. is
  26. count1 number; --
  27. r_code varchar(16);
  28. r_name varchar(32);
  29. begin
  30. select count(*) into count1 from customer where customer_code = c_code;
  31. if count1=0 then
  32. dbms_output.put_line('该住客不存在!');
  33. else
  34. select count(*) into count1 from room where room_type_code = rt_code and check_out_confirm = 'n';
  35. if count1=0 then
  36. dbms_output.put_line('该房型预定已满不存在!');
  37. else
  38. INSERT INTO book(customer_code,room_type_code,lease_way,reservation_check_in_time,reservation_check_out_time)
  39. values(c_code, rt_code,l_way,re_citime,re_cotime);
  40. select room_code into r_code from (
  41. select *from room where room_type_code = rt_code and check_out_confirm = 'n'
  42. ) where rownum <= 1;
  43. update room set check_out_confirm = 'y' where room_code = r_code;
  44. select room_name into r_name from room where room_code = r_code;
  45. dbms_output.put_line('预定成功!,房间编号code为;'||r_code || '房间名:' || r_name);
  46. end if;
  47. end if;
  48. end;
  49. -- 测试
  50. select * from customer_order;
  51. alter table book drop column order_code;
  52. call customer_book('ms100011', 'lx001', 's', date'2022-9-7', date'2022-9-10');
  53. select * from book;
  54. select * from room;
  55. update room set check_out_confirm = 'n';
  56. select reservation_code into sel_reservation_code from book
  57. where customer_code = c_code;
  58. sel_reservation_code book.reservation_code%type;
  59. -- 订单加入
  60. insert into customer_order values('dd001', 'ms100011', 'yd010001', sysdate);
  61. select * from customer_order;
  62. -- 入住办理
  63. CREATE OR REPLACE PROCEDURE do_checkin(
  64. room_code varchar2, o_code varchar2, lease_way varchar, check_itime date, check_otime date,
  65. check_name varchar2, check_id varchar2, check_tel number)
  66. is
  67. begin
  68. INSERT INTO check_in(room_code,order_code,check_in_lease_way,check_in_time,
  69. check_out_time,check_in_person_name,check_in_person_id_card,check_in_person_tel)
  70. values(room_code, o_code, lease_way, check_itime,check_otime, check_name, check_id, check_tel);
  71. end;
  72. -- 测试
  73. call do_checkin('1001', 'dd001', 's', date'2022-9-7', date'2022-9-10', '丽江好', '123456', '110');
  74. select * from check_in;
  75. -- 就餐
  76. select * from dishes;
  77. select * from dinning;
  78. insert into dinning(check_in_code, food_code, dinning_time) values('rz010001', '1', sysdate);
  79. select * from dinning;
  80. --参加活动
  81. select * from activity;
  82. call activity_registration_proc('ms100011', 'hd010001');
  83. select * from activity_registration;
  84. -- 费用结算
  85. CREATE OR REPLACE PROCEDURE get_cost(
  86. o_code customer_order.order_code%type,c_code customer.customer_code%type)
  87. is
  88. day_begin check_in.check_in_time%type;
  89. day_end date;
  90. roomcode varchar2(16);
  91. roomtype varchar2(16);
  92. checkway varchar2(1);
  93. checkcode varchar2(16);
  94. day_diff number;
  95. dishestime number;
  96. onedayroom_cost float;
  97. onedishescost float;
  98. roomcost float;
  99. foodtype varchar2(16);
  100. dishescost float;
  101. actcode varchar2(16);
  102. actprice float;
  103. actcost float;
  104. res float;
  105. begin
  106. select check_in_time into day_begin from check_in where order_code = o_code;
  107. select check_out_time into day_end from check_in where order_code = o_code;
  108. select check_in_lease_way into checkway from check_in where order_code = o_code;
  109. day_diff := day_end - day_begin;
  110. select room_code into roomcode from check_in where order_code = o_code;
  111. select room_type_code into roomtype from room where room_code = roomcode;
  112. if checkway = 'd' then
  113. select room_day_price into onedayroom_cost from room_type where room_type_code = roomtype;
  114. roomcost := onedayroom_cost * day_diff;
  115. end if;
  116. if checkway = 's' then
  117. select room_short_price into onedayroom_cost from room_type where room_type_code = roomtype;
  118. roomcost := onedayroom_cost * day_diff;
  119. end if;
  120. if checkway = 'l' then
  121. select room_long_price into onedayroom_cost from room_type where room_type_code = roomtype;
  122. roomcost := onedayroom_cost * day_diff;
  123. end if;
  124. dbms_output.put_line('房间费用为:'||roomcost||'元');
  125. select check_in_code into checkcode from check_in where order_code = o_code;
  126. select food_code into foodtype from (select * from dinning where check_in_code = checkcode)
  127. where rownum <= 1;
  128. select food_price into onedishescost from dishes where food_code = foodtype;
  129. select count(*) into dishestime from dinning where check_in_code = checkcode;
  130. dishescost := onedishescost * dishestime;
  131. dbms_output.put_line('用餐费用为:'||dishescost||'元');
  132. select activity_code into actcode from activity_registration
  133. where customer_code = c_code;
  134. select activity_price into actprice from activity
  135. where activity_code = actcode;
  136. actcost := actprice;
  137. dbms_output.put_line('活动费用为:'||actcost||'元');
  138. res :=roomcost + dishescost + actcost;
  139. dbms_output.put_line('最终费用为:'||res||'元');
  140. end;
  141. -- 测试
  142. select * from customer;
  143. select * from customer_order;
  144. call get_cost('dd001', 'ms100011');
  145. -- 退房
  146. CREATE OR REPLACE PROCEDURE do_checkout(
  147. room_code1 varchar2)
  148. is
  149. count1 number;
  150. count2 number;
  151. begin
  152. select count(*) into count1 from room where room_code = room_code1;
  153. if count1 = 0 then
  154. dbms_output.put_line('该房间不存在');
  155. else
  156. select count(*) into count2 from room where room_code = room_code1 and check_out_confirm = 'y';
  157. if count2 = 0 then
  158. dbms_output.put_line('该房间暂无住客');
  159. else
  160. update room set check_out_confirm = 'n' where room_code = room_code1 and check_out_confirm = 'y';
  161. dbms_output.put_line('退房成功');
  162. end if;
  163. end if;
  164. end;
  165. -- 测试
  166. select * from room;
  167. call do_checkout('1002');
  168. select * from room;
  169. -- 新建房间类型
  170. CREATE OR REPLACE PROCEDURE insert_roomtype(
  171. lxcode varchar2,
  172. lxname varchar2,
  173. dcost float,
  174. scost float,
  175. lcost float,
  176. rinfo varchar2
  177. )
  178. is
  179. count1 number;
  180. begin
  181. select count(*) into count1 from room_type where room_type_code=lxcode;
  182. if count1 = 1 then
  183. dbms_output.put_line('该房间类型号已存在');
  184. else
  185. insert into room_type(ROOM_TYPE_CODE,ROOM_TYPE_NAME,ROOM_DAY_PRICE,ROOM_SHORT_PRICE,ROOM_LONG_PRICE,ROOM_TYPE_INFO)
  186. values (lxcode,lxname,dcost,scost,lcost,rinfo);
  187. end if;
  188. end;
  189. --查询入住房间及情况
  190. CREATE OR REPLACE PROCEDURE select_rm(rm_code room.room_code%type) AS
  191. --声明异常的变量
  192. no_result EXCEPTION;
  193. rm_number room.room_number%type;
  194. check_out room.check_out_confirm%type ;
  195. BEGIN
  196. --根据传入的id删除用户
  197. select room_number,check_out_confirm into rm_number,check_out from room
  198. where room_code=rm_code;
  199. --使用游标判断是否删除成功
  200. IF rm_number is null THEN
  201. --没有删除成功抛出异常
  202. RAISE no_result;
  203. END IF;
  204. dbms_output.put_line('房间编号:'||rm_code||',房间名:'||rm_number||',入住情况:'||check_out);
  205. EXCEPTION
  206. WHEN no_result THEN
  207. dbms_output.put_line('房间编号不存在!');
  208. WHEN OTHERS THEN
  209. dbms_output.put_line('房间编号不存在!');
  210. END select_rm;
  211. -- 活动创建
  212. CREATE OR REPLACE PROCEDURE activity_add(
  213. code activity.activity_code%type,
  214. name activity.activity_name%type,
  215. act_type activity.activity_type%type,
  216. start_time activity.activity_start_time%type,
  217. end_time activity.activity_end_time%type,
  218. position activity.activity_position%type,
  219. content activity.activity_content%type,
  220. price activity.activity_price%type)
  221. is
  222. BEGIN
  223. INSERT INTO activity VALUES (code,name,act_type,start_time,
  224. end_time,position,content,price);
  225. dbms_output.put_line('活动创建成功!');
  226. END activity_add;
  227. --留言
  228. create or replace procedure do_leave_message(
  229. customer_code1 customer.customer_code%type,
  230. l_message_tinfo leave_message.message_tinfo%type)
  231. is
  232. begin
  233. insert into leave_message(customer_code, message_tinfo,message_time)
  234. values(customer_code1, l_message_tinfo, sysdate);
  235. dbms_output.put_line('留言成功!');
  236. dbms_output.put_line('调用完成!');
  237. end;
  238. -- 留言调用测试
  239. call do_leave_message('ms100001', '民宿不错!');
  240. select * from leave_message;
  241. --评价
  242. create or replace procedure do_customer_comment(
  243. p_customer_code customer.customer_code%type,
  244. p_comment_score customer_comment.comment_score%type,
  245. p_comment_content customer_comment.comment_content%type
  246. )
  247. is
  248. begin
  249. insert into customer_comment(customer_code,comment_score,comment_content)
  250. values(p_customer_code,p_comment_score,p_comment_content );
  251. dbms_output.put_line('评价成功!');
  252. dbms_output.put_line('调用完成!');
  253. end;
  254. --评价调用测试
  255. call do_customer_comment('ms100013', 3, '还不错');
  256. select * from customer_comment;

一、项目概述

(一)项目简介与背景

        民宿通常指的是自用住宅空闲房间,结合当地人文、自然景观、生态、环境资源等方面资源,以家庭副业方式经营,提供旅客居住生活的方式。近年来,民宿凭借其接地气、特色化、具有家庭氛围等优势,逐步发展成为一种住店潮流,深受国内外旅行者的喜爱。而民宿的管理水平的高低将直接影响到民宿的形象和声誉。伴随社会信息化脚步的发展,民宿服务只有走上网络化、智能化的发展之路,才能更好的满足人们对高标准、高质量和个性化服务的追求,因此,民宿管理系统的开发拥有着广泛的应用前景。

        本项目旨在借助数据库相关知识打造符合实际需求,结构完整的民宿管理系统,采用Oracle数据库实现各项需求。分为房间管理、入住、餐饮、活动、评价、留言六大功能模块。

(二)项目功能
        2.1房间管理        

①房间信息录入:管理员可以向系统中录入房间的编号、房间号、房间类型、  房间价格(日租、短租、长租)、是否已入住的信息。

②房间信息查询:工作人员可以通过房间信息表查询房间的信息,需要精确,  模糊查询,如房间号查询,已入住房间查询,未入住房间查询,已入住客户信息查询等方式。

③房间信息管理:管理员可以根据需要,对房间的编号,房间号、房间类型、房间价格等信息进行添加,修改和删除等功能。

2.2入住管理

①预定功能:客户可以通过网络查询到各类的房间信息,包括基本图片、类型、价格、是否已经被预定、餐饮等信息。住客需要录入预定信息,预定信息包括住客的姓名、性别、身份证、联系方式基本信息和租赁方式、预定入住时间、预定退房时间。根据房间信息和人员信息判断能否预定成功。当系统接收到该房间被预定后,需将房间信息中是否预定的信息更变为已预定。

②入住办理:当客户办理入住手续时,如已预定,在登记住客身份证后将该用户预定信息一并记录。如未预定,在客户查询客房各类信息之后,登记其姓名、性别、身份证号、联系方式、入住房间、入住开始结束时间、租赁方式,房间已有入住人员则不允许办理入住。

③住客信息查询:工作人员可以通过住客登记的姓名、身份证,入住时间,房间号等查询到住客的住房信息以及其住房的历史记录等信息。

④退房办理: 在客户需要办理退房手续且上交房卡后,工作人员进行退房,先计算顾客总共消费,付钱后完成退房流程,在房间信息表中将该房间标记为未入住,同时更新入住记录和预定信息住客状态。

2.3餐饮

①餐饮信息录入:工作人员需向系统录入餐饮时间、价格、内容等信息。

②餐饮信息查询。

③餐饮信息修改。

④用餐人员信息录入:在接收到网上预定或入住办理时用户用餐的信息,工作人员需要将用餐人员的时间录入系统。

⑤用餐信息查询:工作人员,管理员可以通过日期,客户姓名,房间号、身份证号查询其用餐信息。

⑥用餐信息修改和删除。

2.4活动管理

①活动创建:工作人员可以定期组织租客举办交友,游戏等活动。此时工作人员需要将活动时间,内容,地点,收费等信息录入系统中。

②活动信息修改:工作人员可以修改活动信息。

③活动信息查询:管理员可以通过时间、名称查询活动信息,查询今后一周的活动信息。

④活动信息展示:客户可以通过民宿大屏幕查看活动信息。

⑤活动报名:在客户查询到未来的活动后,可以通过工作人员报名此活动,将自己的姓名、房间号或身份证等基本信息录入系统。

2.5评价模块

①评价:客户在办理退房手续后,可以对入住期间的环境,服务进行综合评价,打分。工作人员将评价信息录入系统。

②评价查询:客户、工作人员、管理员可以查询历史评价信息,包括好评,差评、综合查询方式。

2.6留言板块

①留言信息录入:租客可以通过工作人员留下自己在该地旅行居住的各类感受或者写简单的游记。

②留言信息展示:租客可以通过大屏幕赏阅历史的留言,游记等。

图1 功能模块图

二、需求分析

        系统开发之前,先要充分了解和熟悉有关民宿相关的信息,并区分其与一般旅馆的区别和其存在的特点,充分了解民宿管理系统中的所需功能项,从而使开发设计的系统可以全面便捷的概括所需的操作,以达到满足使用者的需求。

(一)业务流程图

一个简化的业务流程如图2所示:

  

图2 业务流程图

(二)数据流程
2.1数据流图
(1)顶层数据流图

        一级数据流图包括主要的外部实体、数据存储对象以及流程,首先确定住客、前台人员、管理人员三个主要的外部实体,随后根据需求分析列出了入住预定与退房、餐饮信息管理、房间信息管理等六个流程。对于入住预定与退房以及活动管理还扩展了二级数据流图。最后的是存储表单的确定,根据系统信息需要我们共写出了客户信息、入住信息等十二个存储表。

  

(2)二级数据流图

        二级数据流图是对一级部分流程的细化。入住预定与退房流程包含预定办理、入住办理以及退房办理三个业务流程;活动信息管理流程包括活动信息管理以及活动报名两个流程。

三、数据库概念模型

        本民宿管理数据库设计主要实体对象包括客户、房间、活动、餐饮、评价、留言等,共12个实体模型。

图3 概念模型

四、数据库物理模型

(一)物理模型

        物理模型是由概念模型通过PowerDesigner自动生成得到的,将概念模型中的联系转为外键引入到实体中,更能体现实体间的联系。

图4 物理模型

(二)数据库表

        数据库的主要表格包括:

客户表
customer (customer_code,  customer_name, gender, id, tel)
餐品表
dishes (food_code, food_name, food_price, food_content)
房间类型
room_type (room_type_code, room_type_name, room_day_price, 
room_short_price, room_long_price, room_type_info, room_type_sums)
入住房间
room (room_code, room_name, check_out_confirm, room_type_code)
活动表 activity 
(activity_code, activity_name, activity_type, activity_start_time, activity_end_time, activity_position, activity_content, activity_price) 
报名表
activity_registration (customer_code, activity_code, activity_recode) 
留言表 leave_message (message_code, customer_code, message_time, message_info)
评价表 customer_comment (comment_code, customer_code, comment_score, 
comment_content)
订单表
customer_order (order_code, customer_code, order_time)
预定表
book (reservation_code, customer_code, room_type_code, order_code, lease_way, reservation_check_in_time, reservation_check_out_time, room_code_res)
入住表
check_in (check_in_code, room_code, order_code, check_in_lease_way, check_in_time, check_out_time, check_in_person_name, check_in_person_id_card, check_in_person_tel)
用餐表
dinning (dinning_code, food_code, check_in_code, dinning_time)
费用表 cost (cost_code, check_in_code, dinning_cost, room_cost, total_cost)
 

(三)表空间创建

        表空间是Oracle数据库最大的逻辑单位,Oracle数据库通过表空间来组织数据库中的数据。一个数据库逻辑上由一个或多个表空间组成,一个表空间物理上是由一个或多个数据文件组成。在任何一个时刻,一个数据文件只能属于一个表空间,一个表空间只能属于一个数据库,反之则不成立。

        永久表空间:专门针对用户的具体应用而创建的数据表空间,用户方案对象(如表、索引等)中的数据 就存放在此。

        临时表空间:保存SQL语句在执行过程中所产生的临时数据(如查询操作中的记录排序、分组汇总等)。此类表空间通常不能存放用户数据,由系统自动管理,其中的数据不需要永久保存,属于“临时”性质。

        本项目创建表空间如下:

3.1 永久表空间 HomeStay1_data
  1. CREATE TABLESPACE HomeStay1_data DATAFILE 'D: \Data\local\sql\HomeStay1\HomeStay1_data. dbf'
  2. SIZE 500M AUTOEXTEND ON NEXT 100M MAXSIZE UNLIMITED ONLINE;
3.2 临时表空间 HomeStay_temp
  1. CREATE TEMPORARY TABLESPACE HomeStay1_temp TEMPFILE
  2. 'D:\Data\local\sql\HomeStay1\HomeStay1_temp.dbf' SIZE 500M AUTOEXTEND ON NEXT 100M MAXSIZE 500M;

(四)用户创建

        Oracle数据库对安全性的管理,使用用户以及授权权限来达到安全性。下面是对住客、老板、前台分别创建的用户,并为其授予权限。创建授权如下:

4.1 创建管理员用户
  1. CREATE USER manager1 IDENTIFIED BY 123 DEFAULT TABLESPACE HomeStay1_data QUOTA UNLIMITED ON HomeStay1_data TEMPORARY TABLESPACE HomeStay1_temp;
  2. GRANT dba TO manager1;
4.2 创建前台用户 
  1. create user proscenium identified by proscenium123 TEMPORARY TABLESPACE HomeStay_temp;
  2. GRANT CONNECT TO proscenium;

(五)关键应用编程实现

        顾客注册账号、预定房间、顾客入住、顾客入住办理、顾客退房办理、费用结算、用餐、活动报名、在表中插入相关的新信息、留言和评价。下面展示用存储过程实现的一些主要功能。

5.1 预定功能

        通过传入顾客编号、预定房间的类型编号、租聘方式、预计入住时间、预计退房时间,先进性判断各信息是否正确,房间是否有空缺,最后预定成功插入相关表中.

  1. CREATE OR REPLACE PROCEDURE Customer_book(
  2. c_code varchar2, rt_code varchar2, --顾客编号 房间类型编号
  3. l_way varchar2,re_citime DATE, re_cotime DATE) -- 租聘方式 预定入住时间 预定退房时间
  4. is
  5. count1 number; --
  6. r_code varchar(16);
  7. r_name varchar(32);
  8. begin
  9. select count(*) into count1 from customer where customer_code = c_code;
  10. if count1=0 then
  11. dbms_output.put_line('该住客不存在!');
  12. else
  13. select count(*) into count1 from room where room_type_code = rt_code and check_out_confirm = 'n';
  14. if count1=0 then
  15. dbms_output.put_line('该房型预定已满不存在!');
  16. else
  17. INSERT INTO book(customer_code,room_type_code,lease_way,reservation_check_in_time,reservation_check_out_time)
  18. values(c_code, rt_code,l_way,re_citime,re_cotime);
  19. select room_code into r_code from (
  20. select *from room where room_type_code = rt_code and check_out_confirm = 'n'
  21. ) where rownum <= 1;
  22. update room set check_out_confirm = 'y' where room_code = r_code;
  23. select room_name into r_name from room where room_code = r_code;
  24. dbms_output.put_line('预定成功!,房间编号code为;'||r_code || '房间名:' || r_name);
  25. end if;
  26. end if;
  27. end;
5.2 入住办理功能

        通过传入房间编号、订单编号、租聘方式、入住时间、预计退房时间,进行入住办理。

  1. CREATE OR REPLACE PROCEDURE do_checkin(
  2. room_code varchar2, o_code varchar2, lease_way varchar, check_itime date, check_otime date,
  3. check_name varchar2, check_id varchar2, check_tel number)
  4. is
  5. begin
  6. INSERT INTO check_in(room_code,order_code,check_in_lease_way,check_in_time,
  7. check_out_time,check_in_person_name,check_in_person_id_card,check_in_person_tel)
  8. values(room_code, o_code, lease_way, check_itime,check_otime, check_name, check_id, check_tel);
  9. end;
5.3 活动报名功能

        通过传入顾客编号和活动编号先进性边界判断,最后报名成功,在相关表中添加报名信息。

  1. create or replace procedure activity_registration_proc(
  2. in_cus_code in customer.customer_code%type,
  3. in_act_code in activity.activity_code%type) is
  4. begin
  5. declare
  6. cus_name customer.customer_name%type;
  7. act_name activity.activity_name%type;
  8. cursor cur_cusName is select customer_name from customer where customer_code = in_cus_code;
  9. cursor cur_actName is select activity_name from activity where activity_code = in_act_code;
  10. begin
  11. open cur_cusName;
  12. open cur_actName;
  13. fetch cur_cusName into cus_name;
  14. fetch cur_actName into act_name;
  15. if cur_cusName%found then
  16. if cur_actName%found then
  17. insert into activity_registration(customer_code, activity_code)
  18. values(in_cus_code, in_act_code);
  19. commit;
  20. dbms_output.put_line(in_cus_code||'顾客:'||cus_name||'报名 '||in_act_code||' 活动 '||act_name||'成功!');
  21. else dbms_output.put_line('未查到编号'||in_act_code||'活动!');
  22. end if;
  23. else dbms_output.put_line('未查到编号'||in_cus_code||'顾客!');
  24. end if;
  25. close cur_cusName;
  26. close cur_actName;
  27. end;
5.4 新建房间类型
  1. CREATE OR REPLACE PROCEDURE insert_roomtype(
  2. lxcode varchar2,
  3. lxname varchar2,
  4. dcost float,
  5. scost float,
  6. lcost float,
  7. rinfo varchar2
  8. )
  9. is
  10. count1 number;
  11. begin
  12. select count(*) into count1 from room_type where room_type_code=lxcode;
  13. if count1 = 1 then
  14. dbms_output.put_line('该房间类型号已存在');
  15. else
  16. insert into room_type(ROOM_TYPE_CODE,ROOM_TYPE_NAME,ROOM_DAY_PRICE,ROOM_SHORT_PRICE,ROOM_LONG_PRICE,ROOM_TYPE_INFO)
  17. values (lxcode,lxname,dcost,scost,lcost,rinfo);
  18. end if;
  19. end;
5.5 费用结算功能

        通过传入的顾客编号和订单编号,计算出相关的消费:房费、用餐费用和活动费用,并插入到消费表中。

       

  1. CREATE OR REPLACE PROCEDURE get_cost(
  2. o_code customer_order.order_code%type,c_code customer.customer_code%type)
  3. is-- 订单编号 顾客编号
  4. day_begin date; -- 需查询入住时间
  5. day_end date; -- 需查询退房房间
  6. roomcode varchar2(16);-- 房间编号
  7. roomtype varchar2(16);-- 房间类型
  8. checkway varchar2(1);-- 租聘方式
  9. checkcode varchar2(16);--入住编号
  10. day_diff number; -- 天数
  11. dishestime number;-- 餐品次数
  12. onedayroom_cost float;--房间单价
  13. onedishescost float;-- 餐品单价
  14. roomcost float; -- 房间总费用
  15. foodtype varchar2(16); -- 餐品类型
  16. dishescost float; -- 餐品总费用
  17. actcode varchar2(16); -- 活动编号
  18. actprice float; -- 活动价格
  19. actcost float; --活动总费用
  20. res float; -- 总费用
  21. begin
  22. select check_in_time into day_begin from check_in where order_code = o_code;
  23. select check_out_time into day_end from check_in where order_code = o_code;
  24. select check_in_lease_way into checkway from check_in where order_code = o_code;
  25. day_diff := day_end - day_begin;
  26. select room_code into roomcode from check_in where order_code = o_code;
  27. select room_type_code into roomtype from room where room_code = roomcode;
  28. if checkway = 'd' then
  29. select room_day_price into onedayroom_cost from room_type where room_type_code = roomtype;
  30. roomcost := onedayroom_cost * day_diff;
  31. end if;
  32. if checkway = 's' then
  33. select room_short_price into onedayroom_cost from room_type where room_type_code = roomtype;
  34. roomcost := onedayroom_cost * day_diff;
  35. end if;
  36. if checkway = 'l' then
  37. select room_long_price into onedayroom_cost from room_type where room_type_code = roomtype;
  38. roomcost := onedayroom_cost * day_diff;
  39. end if;
  40. dbms_output.put_line('房间费用为:'||roomcost||'元');
  41. select check_in_code into checkcode from check_in where order_code = o_code;
  42. select food_code into foodtype from (select * from dinning where check_in_code = checkcode)
  43. where rownum <= 1;
  44. select food_price into onedishescost from dishes where food_code = foodtype;
  45. select count(*) into dishestime from dinning where check_in_code = checkcode;
  46. dishescost := onedishescost * dishestime;
  47. dbms_output.put_line('用餐费用为:'||dishescost||'元');
  48. select activity_code into actcode from activity_registration
  49. where customer_code = c_code;
  50. select activity_price into actprice from activity
  51. where activity_code = actcode;
  52. actcost := actprice;
  53. dbms_output.put_line('活动费用为:'||actcost||'元');
  54. res :=roomcost + dishescost + actcost;
  55. dbms_output.put_line('最终费用为:'||res||'元');
  56. insert into cost(check_in_code, dinning_cost, room_cost, total_cost)
  57. values(checkcode, dishescost, roomcost, res);
  58. update customer_order set payed = 'y' where o_code = order_code;
  59. commit;
  60. end;
5.6 退房办理

        通过传入的房间编号进行边界判断,判断房间编号是否正确以及是否有顾客入住,完成退房修改相关表的信息。

  1. CREATE OR REPLACE PROCEDURE do_checkout(
  2. room_code1 varchar2)
  3. is
  4. count1 number;
  5. count2 number;
  6. begin
  7. select count(*) into count1 from room where room_code = room_code1;
  8. if count1 = 0 then
  9. dbms_output.put_line('该房间不存在');
  10. else
  11. select count(*) into count2 from room where room_code = room_code1 and check_out_confirm = 'y';
  12. if count2 = 0 then
  13. dbms_output.put_line('该房间暂无住客');
  14. else
  15. update room set check_out_confirm = 'n' where room_code = room_code1 and check_out_confirm = 'y';
  16. dbms_output.put_line('退房成功');
  17. end if;
  18. end if;
  19. end;
5.7 序列与触发器

        触发器利用序列生成相关表的编号自增。下面是其中一个,其余10个触发器功能和这个类似,都是给表进行编号自增。

--序列与触发器
create sequence AUTOID1
increment by 1
start with 100001
nomaxvalue
nocycle
cache 10;

/*触发器用户编号生成*/
CREATE or replace TRIGGER MS_AutoID
BEFORE INSERT ON customer
FOR EACH ROW begin
SELECT ('ms'||trim(to_char(AUTOID1.NEXTVAL,'000000')))
INTO :NEW.CUSTOMER_CODE
FROM DUAL;
dbms_output.put_line('客户编号为'||:NEW.CUSTOMER_CODE);
End;

(六)测试

6.1 权限管理

        6.1.1 授予管理员boss resource和connect权限,允许登录和创建实体及对活动表、活动报名表、房间表、房间类型表的insert、update、select、delete权限

        6.1.2 授予前台用户proscenium  resource和connect权限,允许登录和创建实体及对住客表、菜品表、订单表、入住表、用餐表、费用表的insert、update、select、delete权限;对房间表、房间类型表的select权限。

        6.1.3 增         

INSERT INTO  room_type  VALUES ('lx004','豪华单人间',250,238,218,'独立房间,1室1床,可住1人,生活设备一应俱全');

        6.1.4 删

DELETE from room_type where room_type_code = 'lx004';

        6.1.5 改

update room_type set room_day_price=room_day_price*0.9 where room_type_name='商务标准双人房';

        6.1.6 查

select room_long_price from room_type where room_type_name='商务标准双人房';

6.2 数据完整性

        实体完整性、参照完整性、用户完整性

6.3 存储过程结构测试
        6.3.1 录入房间信息测试

call insert_room_type('lx004','豪华单人间',250,238,218,'独立房间,1室1床,可住1人,生活设备一应俱全');

接口名称

测试用例

预期结果

实际结果

是否通过

insert_room_type

同上

插入成功

插入成功

insert_room_type

同上

弹出重复提示

已存在该房间类型编号,插入失败

6.3.2 查询房间信息测试

接口名称

测试用例

预期结果

实际结果

是否通过

select_rm

'fj100010'

输出房间信息

如下图

select_rm

'fj100015'

弹出错误提示

房间编号不存在

call select_rm('fj100010');

call select_rm('fj100015');

6.3.3 住客注册功能测试

Callcustomers_reg('ms100013','李健豪','m',123456','110');

接口名称

测试用例

预期结果

实际结果

是否通过

customers_reg

同上

注册成功

注册成功

customers_reg

同上

弹出重复提示

该用户已注册,请勿重复注册

customers_reg

如下

请输入18位身份证号

注册成功

customers_reg

如下

请输入11位手机号

注册成功

6.3.4 餐饮信息录入测试

call dishes_add('cp100004','豪华会议餐','150','京都排条套餐,猪排饭,奥尔良鸡排套餐');

接口名称

测试用例

预期结果

实际结果

是否通过

dishes_add

同上

添加成功

套餐添加成功

dishes_add

同上

弹出重复提示

该套餐已存在,请勿重复添加

6.3.5 住客预定功能测试

call Customer_book('yd100003', 'ms100013', 'lx002', 'dd100003','l',sysdate, sysdate+7);

接口名称

测试用例

预期结果

实际结果

是否通过

Customer_book

同上

预定成功

如下图

Customer_book

同上

弹出重复提示

该预订已注册,请勿重复预订

Customer_book

如下

无空房

该房型预订已满

call Customer_book('yd100004', 'ms100013', 'lx002', 'dd100003','l',sysdate, sysdate+7);

6.3.6入住办理功能测试

call do_checkin('1001', 'dd002', 's', date'2022-9-7', date'2022-9-10', '丽江好', '123456', '110');

6.3.7 用餐信息录入测试

insert into dinning(check_in_code, food_code, dinning_time) values('rz010002', '1', sysdate);

6.3.8 费用结算测试

call get_cost('dd002', 'ms100013');

6.3.9 活动报名测试

接口名称

测试用例

预期结果

实际结果

是否通过

activity_registration_proc

('ms100001','hd010001')

报名成功,反馈信息

如图

activity_registration_proc

('ms1','hd10001')

报名失败,提示信息

没有这个编号的租户

activity_registration_proc

('ms100001','hd1')

报名失败,提示信息

没有这个编号的活动

call activity_registration_proc('ms100001','hd010001');

查询activity_registration活动报名表,信息正确。

call activity_registration_proc('ms100001','hd1');

call activity_registration_proc('ms1','hd010001');

6.3.10 留言测试

call do_leave_message('ly100001','ms100013',sysdate,'我觉得这家民宿真不错啊,真不错!!!');

6.3.11 评价测试

call do_comment('pl100002','ms100013', 3, '还不错');

6.3.12 退房办理

call do_checkout('fj100008');

五、总结

        本项目中,我的任务主要数据库模型的建立,概念模型图以及物理模型图,表结构和字段的具体设计,用触发器和存储过程实现活动报名功能和费用结算功能。在小组讨论好我们的所有表和联系后,我用PowerDesigner绘制了概念模型图,然后优化一下各个表的具体哪些字段、类型已经各表的主键、外键设计。概念模型需要确定系统中有哪些实体以及实体之间的联系,同时还要写上实体所有的属性名、主键等。联系不仅要写出联系名还要写出联系的类型,包括一对一、一对多等等。物理模型可以在概念模型的基础上自动生成,其会自动地将概念模型中的外键引入到实体属性中,同时箭头指向引入外键的实体。在设计费用结算时卡了很久,也不断进行优化数据和逻辑流程,因为涉及表比较多,也debug了很久,让我对于存储过程和多表之间的关联查询有了更加深刻的理解。


 这个项目的背景是学校数据库实训课的大作业,给了五天的时间,要完成相关项目的数据库开发,因为时间问题所以并没有要求前后端,只需要有相关sql操作就行,触发器实现相关功能,纯粹是因为体现触发器的教学而使用的,实际上并不完全需要。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/秋刀鱼在做梦/article/detail/791503
推荐阅读
相关标签
  

闽ICP备14008679号