VHR配置資料庫開發環境
- 2020 年 1 月 22 日
- 筆記
一,vhr項目宏觀分析
目的:實現機關和事業單位的人事管理資訊系統。
軟體使用的對象:面向機關和事業單位內人事資訊管理人員和在職開發人員。
【架構選型】
vhr面向的群體範圍並不大,並非屬於互聯網應用,所以市面上鼓吹的高並發,高性能對於這個項目來說並不適用。
盲目上微服務只會徒增成本。
系統業務流程設計
1.管理員對員工資訊的操作
首先,管理人員登陸進入系統,對員工資訊進行增刪改查,進而對獎罰、工資、考評等資訊進行增刪改查,然後實現對部門員工部分資訊的統計及修改
2.操作員對自己資訊的操作
可對自己的資訊進行操作
系統功能設計
員工資料
員工資料包括基本資料和高級資料。
- 基本資料 員工編號、員工姓名、性別、出生日期、身份證號、婚姻狀況、名族、機關、政治面貌、電子郵箱、聯繫電話、聯繫地址、部門、職位、職稱、基本工資、聘用形式、最高學歷、所屬專業、畢業院校、入職日期、在職狀態、工號、合約期限。
- 高級資料 (1). 獎懲資料:獎懲日期、獎懲分數、獎懲原因。 (2). 培訓資料:培訓日期、培訓內容。 (3). 考評資料:考評日期、考評內容、考評結果。 (4). 調薪資料:調薪日期、調前薪資、調後薪資、調薪原因。 (5). 調動資料:調動日期、調前部門、調前職位、調動原因、調後部門、調後職位、備註。 (6). 工資資訊:賬套名稱、工資月份、應發工資、備註。 (7). 其他資訊:管理員可任意備註其他資訊。
人事管理
主要用於對員工獎懲、培訓、考評、調薪、調動、工資資訊的管理。
1.員工資料
即員工的基本資料,顯示員工資料,並且可對員工進行模糊查詢,即實現員工資料的增刪改查。
2.員工獎懲
對員工獎勵模組的增刪改查的實現。
3.員工培訓
對員工培訓模組的增刪改查的實現。
4.員工好評
對員工好評模組的增刪改查的實現。
5.員工調薪
對員工調薪模組的增刪改查的實現。
6.員工調動
對員工調動模組的增刪改查的實現。
工資管理
實現對員工工資賬套管理、員工賬套設置、工資表管理、月末處理、工資表查詢一系列對員工工資管理的功能。
1 工資賬套管理
對員工獎金、基本工資、提成等各項的增刪改查。
2 員工賬套設置
根據公司賬套(即各部門),查看相應的員工的工資資訊,並實現其增刪功能。
3 工資表管理
集中對同一部門員工工資進行增刪改查的功能。
4 月末處理
對該月該部門員工工資進行增刪改查的功能。
5 工資表查詢
是一種歷史記錄查詢,可查詢某員工在某月的工資情況。
統計管理
對員工資料的統一查詢管理,包括綜合資訊統計、員工積分統計、人事資訊統、人事記錄統計。
1 綜合資訊統計
根據員工出生月份、轉正資訊等統一管理。
2 員工積分統計
根據日期查找員工的積分情況。
3 人事資訊統計
對員工進行的同一查詢管理,可根據性別、工資、職稱等查詢員工的資訊。
4 人事記錄統計
對員工積分的統一管理,可根據部門、月份等查詢其積分資訊。
系統管理
對系統、管理員等一些操作,包括基礎資訊設置、系統管理、操作員管理、備份恢複數據、初始化資料庫。
1 基礎資訊設置
對部門、職位、職稱、獎懲規則和許可權組的設置管理,及其個項目的增刪改查。
2 系統管理
對系統本身的一些設置。
3 操作日誌管理
記錄管理員對數據的操作資訊。
4 操作員管理
管理員基本資訊的管理,及其增刪改功能。
5 備份恢複數據
可對員工資料數據進行備份,並在適當的時候還原。
6 初始化資料庫
對整個資料庫資料初始化的操作。
二,資料庫表設計
vhr系統使用者大致可分為兩類,一種是系統管理員,另外一種是擁有各種許可權的hr員工。
vhr一共有21張表,其中核心的五張表:
hr表
role角色表
用戶角色關聯表【hr_role】
前面三張表定義了vhr使用的對象及所擁有的許可權,
比如hr中第一個id為3的系統管理員對於用戶角色關聯表中rid為6,而6在role表中對應的是系統管理員許可權。
下面兩張菜單表和菜單角色關聯表定義了角色具體擁有的許可權。
menu表
menu_role表
這兩張表需要結合role表來分析,還是以hr表中id為3的用戶舉例,在menu_role中rid為3對應的mid為7,7在menu表中的訪問內容只有基本資料,那麼這個用戶可能是個普通員工。以此類推,作者在文檔里畫了一個圖非常形象生動的詮釋了這五張表的關係:
剩下的表在往下看功能的時候再慢慢了解吧。
三,拆解項目
登錄模組
不知道面對整個項目該如何下手,還好在圖書館借了SpringBoot+Vue的書,實戰介紹完資料庫就到登錄模組了。
在沒有思路的時候,姑且先從這裡開始吧。
在研究登錄模組之前,當然是先把程式跑起來先。
clone,然後用IDEA打開。
第一步就是修改資料庫相關配置
首先建庫,把vhr.sql在MySQL里創建出來。【MySQL版本:8.0】
出於個人習慣,
將properties改為yaml,
SpringBoot版本換到了2.1.8,
Druid版本換到了1.1.20,順帶配置Druid監控。
- 關於application.yaml
spring: datasource: # 數據源基本配置 username: noneplus password: Noneplus564925080! driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://xx.xxx.xxx.xx:3306/vhr?serverTimezone=UTC type: com.alibaba.druid.pool.DruidDataSource # Druid數據源配置 initialSize: 5 minIdle: 5 maxActive: 20 maxWait: 60000 timeBetweenEvictionRunsMillis: 60000 minEvictableIdleTimeMillis: 300000 validationQuery: SELECT 1 FROM DUAL testWhileIdle: true testOnBorrow: false testOnReturn: false poolPreparedStatements: true # 配置監控統計攔截的filters,去掉後監控介面sql無法統計,'wall'用於防火牆 filters: stat,wall,log4j maxPoolPreparedStatementPerConnectionSize: 20 useGlobalDataSourceStat: true connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500 mail: host: smtp.qq.com port: 465 username: 1510161612@qq.com password: fhmvfkwxjwmzhhjd default-encoding: UTF-8 properties: mail: debug: true stmp: socketFactory: class: javax.net.ssl.SSLSocketFactory pagehelper: helperDialect: mysql reasonable: true supportMethodsArguments: true pageSizeZero: false server: port: 8082 ###################################################################################### # 原application.properties ##MySQL配置 # spring.datasource.type=com.alibaba.druid.pool.DruidDataSource # spring.datasource.url=jdbc:mysql://47.103.6.247:3306/vhr?useUnicode=true&characterEncoding=UTF-8 # spring.datasource.username=noneplus # spring.datasource.password=Noneplus564925080! # #MyBatis日誌配置 # mybatis.config-location=classpath:/mybatis-config.xml # #Redis配置 # spring.redis.database=0 # spring.redis.host=192.168.66.130 # spring.redis.port=6379 # spring.redis.password=123@456 # spring.redis.jedis.pool.max-active=8 # spring.redis.jedis.pool.max-idle=8 # spring.redis.jedis.pool.max-wait=-1ms # spring.redis.jedis.pool.min-idle=0 # #快取配置 # spring.cache.cache-names=menus_cache # spring.cache.redis.time-to-live=1800s # #埠配置 # server.port=8082 # # spring.mail.host=smtp.qq.com # spring.mail.port=465 # spring.mail.username=1510161612@qq.com # spring.mail.password=fhmvfkwxjwmzhhjd # spring.mail.default-encoding=UTF-8 # spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory # spring.mail.properties.mail.debug=true
- pom修改的部分
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.8.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.20</version> </dependency>
- 配置DruidConfig監控 在config包下新增一個DruidConfig
package org.sang.config; import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.support.http.StatViewServlet; import com.alibaba.druid.support.http.WebStatFilter; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import javax.sql.DataSource; import java.util.Arrays; import java.util.HashMap; import java.util.Map; @Configuration public class DruidConfig { //載入application.yaml中的Druid配置 @ConfigurationProperties(prefix = "spring.datasource") @Bean public DataSource druid(){ return new DruidDataSource(); } //配置Druid的監控 //1、配置一個管理後台的Servlet @Bean public ServletRegistrationBean statViewServlet(){ ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*"); Map<String,String> initParams = new HashMap<>(); initParams.put("loginUsername","hq"); initParams.put("loginPassword","564925080"); initParams.put("allow","");//默認就是允許所有訪問 initParams.put("deny","192.168.15.21"); bean.setInitParameters(initParams); return bean; } //2、配置一個web監控的filter @Bean public FilterRegistrationBean webStatFilter(){ FilterRegistrationBean bean = new FilterRegistrationBean(); bean.setFilter(new WebStatFilter()); Map<String,String> initParams = new HashMap<>(); initParams.put("exclusions","*.js,*.css,/druid/*"); bean.setInitParameters(initParams); bean.setUrlPatterns(Arrays.asList("/*")); return bean; } }
- 配置Druid監控,還需要配置log4j依賴 <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> log4j.properties【配置在resource路徑下】 # Configure logging for testing: optionally with log file log4j.rootLogger=WARN, stdout # log4j.rootLogger=WARN, stdout, logfile log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] – %m%n log4j.appender.logfile=org.apache.log4j.FileAppender log4j.appender.logfile.File=target/spring.log log4j.appender.logfile.layout=org.apache.log4j.PatternLayout log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] – %m%n
啟動項目測試
訪問:http://localhost:8082/index.html#/
測試Druid監控,訪問:http://localhost:8082/druid/
【註:訪問Druid監控之前需要先登錄獲取許可權,之後再訪問Druid】
程式碼參考
【tips:後續會更新程式碼,為了方便測試,會打下不同的節點】
https://github.com/Noneplus/vhr/releases/tag/v1.0