Java OA系统薪资管理模块

### 基于Spring Boot的OA系统薪资管理模块实现

本文介绍了如何使用Spring Boot和MySQL开发一个简单的OA系统薪资管理模块,包括基础设置、考勤数据导入、绩效考核、工资单查询,并扩展到使用Spring Security进行安全认证和权限控制,以及使用Spring Scheduler进行定时任务管理。

#### 项目结构
1. **Spring Boot**: 主要框架,负责处理业务逻辑和REST API。
2. **MySQL**: 数据存储。
3. **Thymeleaf**: 前端模板渲染。
4. **Spring Data JPA**: 数据库操作。
5. **Spring Security**: 安全认证和权限控制。
6. **Spring Scheduler**: 定时任务管理。

### 数据库设计

#### 数据库表
```sql
CREATE TABLE employee (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    base_salary DECIMAL(10, 2),
    allowance DECIMAL(10, 2),
    subsidy DECIMAL(10, 2),
    bonus DECIMAL(10, 2)
);

CREATE TABLE attendance (
    id INT AUTO_INCREMENT PRIMARY KEY,
    employee_id INT,
    date DATE,
    hours_worked DECIMAL(5, 2),
    leave_hours DECIMAL(5, 2),
    FOREIGN KEY (employee_id) REFERENCES employee(id)
);

CREATE TABLE performance (
    id INT AUTO_INCREMENT PRIMARY KEY,
    employee_id INT,
    score DECIMAL(5, 2),
    FOREIGN KEY (employee_id) REFERENCES employee(id)
);

CREATE TABLE payroll (
    id INT AUTO_INCREMENT PRIMARY KEY,
    employee_id INT,
    month DATE,
    total_salary DECIMAL(10, 2),
    FOREIGN KEY (employee_id) REFERENCES employee(id)
);
```

### Spring Boot 代码实现

#### 1. 薪资基础设置

**Controller**
```java
@RestController
@RequestMapping("/api/salary")
public class SalaryController {

    @Autowired
    private EmployeeRepository employeeRepository;

    @PostMapping("/set")
    public ResponseEntity<Employee> setSalary(@RequestBody Employee employee) {
        Employee savedEmployee = employeeRepository.save(employee);
        return ResponseEntity.ok(savedEmployee);
    }
}
```

**Repository**
```java
public interface EmployeeRepository extends JpaRepository<Employee, Integer> {}
```

**Entity**
```java
@Entity
public class Employee {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    private String name;
    private BigDecimal baseSalary;
    private BigDecimal allowance;
    private BigDecimal subsidy;
    private BigDecimal bonus;

    // Getters and setters
}
```

#### 2. 考勤数据导入

**Controller**
```java
@RestController
@RequestMapping("/api/attendance")
public class AttendanceController {

    @Autowired
    private AttendanceRepository attendanceRepository;

    @PostMapping("/import")
    public ResponseEntity<Attendance> importAttendance(@RequestBody Attendance attendance) {
        Attendance savedAttendance = attendanceRepository.save(attendance);
        return ResponseEntity.ok(savedAttendance);
    }
}
```

**Repository**
```java
public interface AttendanceRepository extends JpaRepository<Attendance, Integer> {}
```

**Entity**
```java
@Entity
public class Attendance {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    private Integer employeeId;
    private Date date;
    private BigDecimal hoursWorked;
    private BigDecimal leaveHours;

    // Getters and setters
}
```

#### 3. 绩效考核

**Controller**
```java
@RestController
@RequestMapping("/api/performance")
public class PerformanceController {

    @Autowired
    private PerformanceRepository performanceRepository;

    @PostMapping("/evaluate")
    public ResponseEntity<Performance> evaluatePerformance(@RequestBody Performance performance) {
        Performance savedPerformance = performanceRepository.save(performance);
        return ResponseEntity.ok(savedPerformance);
    }
}
```

**Repository**
```java
public interface PerformanceRepository extends JpaRepository<Performance, Integer> {}
```

**Entity**
```java
@Entity
public class Performance {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    private Integer employeeId;
    private BigDecimal score;

    // Getters and setters
}
```

#### 4. 工资单查询

**Controller**
```java
@RestController
@RequestMapping("/api/payroll")
public class PayrollController {

    @Autowired
    private PayrollRepository payrollRepository;

    @GetMapping("/list")
    public ResponseEntity<List<Payroll>> listPayrolls() {
        List<Payroll> payrolls = payrollRepository.findAll();
        return ResponseEntity.ok(payrolls);
    }

    @GetMapping("/export/{id}")
    public ResponseEntity<Payroll> exportPayroll(@PathVariable Integer id) {
        Optional<Payroll> payroll = payrollRepository.findById(id);
        return payroll.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
    }
}
```

**Repository**
```java
public interface PayrollRepository extends JpaRepository<Payroll, Integer> {}
```

**Entity**
```java
@Entity
public class Payroll {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    private Integer employeeId;
    private Date month;
    private BigDecimal totalSalary;

    // Getters and setters
}
```

### 安全认证和权限控制

#### 添加Spring Security依赖
在`pom.xml`中添加Spring Security依赖:
```xml
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>
```

#### 配置Spring Security
创建一个Security配置类来配置基本的安全设置:
```java
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .antMatchers("/api/salary/**", "/api/attendance/**", "/api/performance/**", "/api/payroll/**").authenticated()
                .and()
            .httpBasic()
                .and()
            .csrf().disable(); // Disable CSRF for simplicity
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
            .withUser("admin")
            .password(passwordEncoder().encode("admin123"))
            .roles("ADMIN");
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }
}
```

### 定时任务管理

#### 添加Spring Scheduler依赖
在`pom.xml`中添加Spring Scheduler依赖:
```xml
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
</dependency>
```

#### 配置Spring Scheduler
在应用程序主类或配置类上启用定时任务功能:
```java
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
public class PayrollApplication {

    public static void main(String[] args) {
        SpringApplication.run(PayrollApplication.class, args);
    }
}
```

#### 实现定时任务
创建一个定时任务类,按月自动计算工资:
```java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Component
public class PayrollScheduler {

    @Autowired
    private PayrollRepository payrollRepository;

    @Autowired
    private EmployeeRepository employeeRepository;

    @Autowired
    private AttendanceRepository attendanceRepository;

    @Autowired
    private PerformanceRepository performanceRepository;

    @Scheduled(cron = "0 0 0 1 * ?") // 每月1号凌晨0点触发
    public void calculateMonthlyPayroll() {
        List<Employee> employees = employeeRepository.findAll();
        for (Employee employee : employees) {
            BigDecimal totalSalary = calculateSalary(employee);
            Payroll payroll = new Payroll();
            payroll.setEmployeeId(employee.getId());
            payroll.setMonth(new Date());
            payroll.setTotalSalary(totalSalary);
            payrollRepository.save(payroll);
        }
    }

    private BigDecimal calculateSalary(Employee employee) {
        BigDecimal baseSalary = employee.getBaseSalary();
        BigDecimal allowance = employee.getAllowance();
        BigDecimal subsidy = employee.getSubsidy();
        BigDecimal bonus = employee.getBonus();
        BigDecimal performanceSalary = performanceRepository.findByEmployeeId(employee.getId())
                                  .map(Performance::getScore)
                                  .orElse(BigDecimal.ZERO);
        BigDecimal attendanceDeduction = attendanceRepository.findByEmployeeId(employee.getId())
                                  .stream()
                                  .map(attendance -> attendance.getHoursWorked().subtract(attendance.getLeaveHours()))
                                  .reduce(BigDecimal.ZERO, BigDecimal::add);

        return baseSalary.add(allowance).add(subsidy).add(bonus).add(performanceSalary).subtract(attendanceDeduction);
    }
}
```

### 总结

本文展示了如何使用Spring Boot、MySQL、Spring Security和Spring Scheduler开发一个简单的OA系统薪资管理模块。通过这些技术的结合,实现了薪资基础设置、考勤数据导入、绩效考核、工资单查询等功能,并确保系统的安全性和定时任务管理。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/754888.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

css 流动边框

一、背景流动边框 实现原理&#xff1a; 用背景进行旋转&#xff0c;超出我们想显示的范围则hidden&#xff0c;就有以上的效果&#xff0c;可以用after或者before元素来实现也可以。 <!DOCTYPE html> <html lang"en"><head><meta charset&qu…

【开发环境】MacBook M2安装git并拉取gitlab项目,解决gitlab出现Access Token使用无效的方法

文章目录 安装Homebrew安装git打开IDEA配置git打开IDEA拉取项目 安装Homebrew /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"在iTerm等命令行工具打开后&#xff0c;输入上面的命令 之后根据中文提示完成Homebrew的下载…

web项目打包成可以离线跑的exe软件

目录 引言打开PyCharm安装依赖创建 Web 应用运行应用程序打包成可执行文件结语注意事项 引言 在开发桌面应用程序时&#xff0c;我们经常需要将网页集成到应用程序中。Python 提供了多种方法来实现这一目标&#xff0c;其中 pywebview 是一个轻量级的库&#xff0c;它允许我们…

PyScript:在浏览器中释放Python的强大

PyScript&#xff1a;Python代码&#xff0c;直接在网页上运行。- 精选真开源&#xff0c;释放新价值。 概览 PyScript是一个创新的框架&#xff0c;它打破了传统编程环境的界限&#xff0c;允许开发者直接在浏览器中使用Python语言来创建丰富的网络应用。结合了HTML界面、Pyo…

把飞书云文档变成HTML邮件:问题挑战与解决历程

一、背景 云文档转HTML邮件 基于公司内部的飞书办公套件&#xff0c;早在去年6月&#xff0c;我们就建设了将飞书云文档转译成HTML邮件的能力&#xff0c;方便同学们在编写邮件文档和发送邮件时&#xff0c;都能有较好的体验和较高的效率。 当下问题 要被邮件客户端识别&am…

【蓝桥杯省赛真题46】python数字币统计 中小学青少年组蓝桥杯比赛 算法思维python编程省赛真题解析

目录 python数字币统计 一、题目要求 1、编程实现 2、输入输出 二、算法分析 三、程序编写 四、程序说明 五、运行结果 六、考点分析 七、 推荐资料 1、蓝桥杯比赛 2、考级资料 3、其它资料 python数字币统计 第十四届蓝桥杯青少年组python比赛省赛真题 一、题目…

Spring Boot结合FFmpeg实现视频会议系统视频流处理与优化

在构建高效稳定的视频会议系统时,实时视频流的处理和优化是开发者面临的核心挑战之一。这不仅仅是简单的视频数据传输,更涉及到一系列复杂的技术问题,需要我们深入分析和有效解决。 高并发与实时性要求: 视频会议系统通常需要支持多人同时进行视频通话,这就意味着系统需要…

ONLYOFFICE8.1版本桌面编辑器——功能测评

一、编辑DOCX 相信大家都有写word文档的经历&#xff0c;不知道大家是不是跟我一样&#xff0c;感觉做一个word不难&#xff0c;但想做好一个word却很麻烦&#xff0c;功能太多&#xff0c;看的人眼花缭乱&#xff0c;有时候一个功能要找很久&#xff0c;甚至有的功能用一辈子都…

Matlab/simulink三段式距离/低阻抗保护

距离1段仿真波形如下所示 距离2段仿真波形如下所示 距离3段仿真波形如下所示

独立开发者系列(12)——下单与支付

做业务有个绕不开的业务逻辑&#xff0c;就是支付。这里总结一个基础的支付电商逻辑闭环流程&#xff0c;完成支付基础体系的实现。这里假定我们要实现的是一个独立的电商平台上允许用户在平台充值&#xff0c;其他的类似多多购物或者淘宝购物的流程逻辑。 数据表结构的逻辑设…

搭建Renesas R7FA8D1BHECBD-BTB的开发调试环境(DAP-LINK: N32G45XVL-STB)

目录 概述 1 软硬件 1.1 软硬件环境信息 1.2 开发板信息 1.3 调试器信息 2 FSP和KEIL产生测试项目 2.1 FSP生成项目 2.2 Keil中配置 3 硬件连接框图 4 一个测试案例 4.1 功能介绍 4.2 定时器函数 5 测试 搭建Renesas R7FA8D1BHECBD-BTB的开发调试环境&#xff08…

【漏洞复现】I doc view——任意文件读取

声明&#xff1a;本文档或演示材料仅供教育和教学目的使用&#xff0c;任何个人或组织使用本文档中的信息进行非法活动&#xff0c;均与本文档的作者或发布者无关。 文章目录 漏洞描述漏洞复现测试工具 漏洞描述 I doc view 在线文档预览是一个用于查看、编辑、管理文档的工具…

LabVIEW材料样本结构缺陷检测

本文介绍了一种基于LabVIEW的实验室振动特性分析测试装置&#xff0c;通过分析振动特性来检测结构缺陷。文章详细描述了具体案例、硬件型号、工作原理、软件功能以及注意事项。 硬件型号 振动传感器&#xff1a;PCB Piezotronics 352C33加速度计 数据采集卡&#xff1a;NI PXI…

天气网站爬虫及可视化

摘要&#xff1a;随着互联网的快速发展&#xff0c;人们对天气信息的需求也越来越高。本论文基于Python语言&#xff0c;设计并实现了一个天气网站爬虫及可视化系统。该系统通过网络爬虫技术从多个天气网站上获取实时的天气数据&#xff0c;并将数据进行清洗和存储。同时&#…

Windows下activemq集群配置(broker-network)

1.activemq版本信息 activemq&#xff1a;apache-activemq-5.18.4 2.activemq架构 3.activemq集群配置 activemq集群配置基于Networks of Brokers 这种HA方案的优点&#xff1a;是占用的节点数更少(只需要2个节点),而且2个broker都可以响应消息的接收与发送。不足&#xff…

下载旧版本vscode及扩展,离线下载远程linux服务器插件

背景 工作的内网没有网络&#xff0c;无法使用网络来下载插件和vscode软件&#xff0c;且有远程linux服务器需求&#xff0c;linux服务器中lib相关库比较旧且无法更新&#xff0c;所以需要选择一个旧版本的vscode&#xff0c;相应插件也需要选择旧版本的 旧版本vscode下载 没…

JavaWeb——MySQL:事务的简单学习

前面学习完了数据库增删查改的SQL语言&#xff0c;约束&#xff0c;数据库设计&#xff0c;以及多表查询&#xff0c;再学完事务就达到初级工程师的水平了。 6. 事务 6.1 概念 事务类似于编程语言的方法&#xff0c;包含一组SQL指令。 事务是不可分割的&#xff1b; 该指令步…

高中数学:复数-三角表示式

一、定义 辐角主值 二、复数乘除运算的三角表示及其几何意义 乘法 复数乘法的几何意义 除法 练习 解

机器学习 笔记

什么是机器学习 Machine Learning 约等于 Look for a function. 学习路线 监督学习&#xff1a; 回归Regression&#xff1a;指模型预估的输出是数值Classification&#xff1a;指模型预估的输出是类别&#xff0c;二分类的输出是或否会告诉机器正确的答案是什么 半监督学习…

xlsx插件简介

1. xlsx插件 1.1. 常用属性和方法 1.1.1. 创建新的工作簿1.1.2. 从数组生成工作表1.1.3. 添加工作表到工作簿1.1.4. 从HTML表格创建工作表1.1.5. 读取Excel文件1.1.6. 导出Excel文件1.1.7. 设置单元格样式 2. vue中如何使用xlsx 2.1. vue-xlsx的特点2.2. 常用属性和方法 2.2.1…