云e办(后端)——工资账套实现

云e办(后端)——工资账套实现

一、工资套账管理

1、修改实体类 pojo/ Salary.java

添加返回日期格式
在这里插入图片描述

2、controller层,由于单表,而mybatis-plus写完controller层即可。
package com.xxxx.server.controller;


import com.xxxx.server.pojo.RespBean;
import com.xxxx.server.pojo.Salary;
import com.xxxx.server.service.ISalaryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author huyelin
 * @since 2022-01-12
 */
@RestController
@RequestMapping("/salary/sob")
public class SalaryController工资 {

    @Autowired
    private ISalaryService iSalaryService;

    @ApiOperation(value = "获取所有工资账套")
    @GetMapping("/")
    public List<Salary> getAllSalary(){
        return iSalaryService.list();
    }

    @ApiOperation(value = "添加工资账套")
    @PostMapping( "/")
    public RespBean addSalary(@RequestBody Salary salary){
        salary.setCreateDate(LocalDateTime.now());
        if (iSalaryService.save(salary)){
            return RespBean.success("添加成功");
        }
        return RespBean.error("添加失败");
    }
 
     @ApiOperation(value = "删除工资账套")
     @DeleteMapping("/{id}")
     public RespBean deleteSalary(@PathVariable Integer id) {
         if (iSalaryService.removeById(id)){
             return RespBean.success("删除成功!");
         }
         return RespBean.error("删除失败!");
     }
     
    @ApiOperation(value = "更改工资账套")
    @PutMapping(value = "/")
    public RespBean updateSalary(@RequestBody Salary salary){
        if (iSalaryService.updateById(salary)){
            return RespBean.success("更改成功");
        }
        return RespBean.error("更新失败");
    }
}

二、员工账套管理

虽然是说员工账套,但是查询的是员工表,员工表是需要关联外键id(salaryId),其中有对应的工资情况。

需要的接口:

  • 查询所有员工账套,分页显示。那么需要查询员工信息,关联员工账套。
  • 查询所有的工资账套, 因为得需要修改工资账套功能
  • 更新员工账套。
1.修改员工类Employee.java

给员工类添加工资属性
在这里插入图片描述

2.controller
/**
* 员工账套
*
* @author zhoubin
* @since 1.0.0
*/
@RestController
@RequestMapping("/salary/sobcfg")
public class SalarySobCfgController {
    @Autowired
    private ISalaryService salaryService;
    @Autowired
    private IEmployeeService employeeService;
    
    @ApiOperation(value = "获取所有员工账套")
    @GetMapping("/")
    public RespPageBean getEmployeeWithSalary(@RequestParam(defaultValue = "1") Integer currentPage,
                                             @RequestParam(defaultValue = "10") Integer size) {
       return employeeService.getEmployeeWithSalary(currentPage, size);
    }
    
    @ApiOperation(value = "获取所有工资账套")
    @GetMapping("/salaries")
    public List<Salary> getAllSalaries() {
       return salaryService.list();
    }
    
    @ApiOperation(value = "更新员工账套")
    @PutMapping("/")
    public RespBean updateEmployeeSalary(Integer eid, Integer sid) {
       if (employeeService.update(new UpdateWrapper<Employee>().set("salaryId", sid).eq("id", eid))) {
          return RespBean.success("更新成功!");
       }
       return RespBean.error("更新失败!");
    }
}

3.EmployeeService
IEmployeeService.java
/**
* 获取所有员工账套
*
* @param currentPage
* @param size
* @return
*/
RespPageBean getEmployeeWithSalary(Integer currentPage, Integer size);
/**
* 获取所有员工账套
*
* @param currentPage
* @param size
* @return
*/
@Override
public RespPageBean getEmployeeWithSalary(Integer currentPage, Integer size) {
   //开启分页
   Page<Employee> page = new Page<>(currentPage, size);
   IPage<Employee> employeePage = employeeMapper.getEmployeeWithSalary(page);
   RespPageBean respPageBean = new RespPageBean(employeePage.getTotal(), employeePage.getRecords());
   return respPageBean;
}


4.EmployeeMapper
 <resultMap id="EmployeeWithSalary" type="com.xxxx.server.pojo.Employee"
extends="BaseResultMap">
 <association property="salary" javaType="com.xxxx.server.pojo.Salary">
 <id column="sid" property="id"/>
 <result column="sbasicSalary" property="basicSalary"/>
 <result column="sbonus" property="bonus"/>
 <result column="slunchSalary" property="lunchSalary"/>
 <result column="strafficSalary" property="trafficSalary"/>
 <result column="sallSalary" property="allSalary"/>
 <result column="spensionBase" property="pensionBase"/>
 <result column="spensionPer" property="pensionPer"/>
 <result column="smedicalBase" property="medicalBase"/>
 <result column="smedicalPer" property="medicalPer"/>
 <result column="saccumulationFundBase"
property="accumulationFundBase"/>
 <result column="saccumulationFundPer"
property="accumulationFundPer"/>
 <result column="sname" property="name"/>
 </association>
 <association property="department"
javaType="com.xxxx.server.pojo.Department">
 <result column="dname" property="name"/>
 </association>
 </resultMap>
 <!--获取所有员工账套-->
 <select id="getEmployeeWithSalary" resultMap="EmployeeWithSalary">
    SELECT
     e.*,
     d.`name` AS dname,
     s.id AS sid,
     s.`name` AS sname,
     s.basicSalary AS sbasicSalary,
     s.trafficSalary AS strafficSalary,
     s.lunchSalary AS slunchSalary,
     s.bonus AS sbonus,
     s.allSalary AS sallSalary,
     s.pensionPer AS spensionPer,
     s.pensionBase AS spensionBase,
     s.medicalPer AS smedicalPer,
     s.medicalBase AS smedicalBase,
     s.accumulationFundPer AS saccumulationFundPer,
     s.accumulationFundBase AS saccumulationFundBase
     FROM
     t_employee AS e
     LEFT JOIN t_salary AS s ON e.salaryId = s.id
     LEFT JOIN t_department AS d ON e.departmentId = d.id
     ORDER BY
     e.id
 </select>
</mapper>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

真真最可爱

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值