36.工资账套
服务端接口设计
salary/SalaryController
@RestController
@RequestMapping("/salary/sob")
public class SalaryController {
@Autowired
SalaryService salaryService;
@GetMapping("/")
public List<Salary> getAllSalary(){
return salaryService.getAllSalary();
}
@PostMapping("/")
public RespBean addSalary(@RequestBody Salary salary) {
if (salaryService.addSalary(salary) == 1) {
return RespBean.ok("添加成功");
}
return RespBean.error("添加失败");
}
@DeleteMapping("/{id}")
public RespBean deleteSalary(@PathVariable Integer id) {
if (salaryService.deleteSalary(id)==1) {
return RespBean.ok("删除成功");
}
return RespBean.error("删除失败");
}
@PutMapping("/")
public RespBean updateSalary(@RequestBody Salary salary) {
if (salaryService.updateSalary(salary) == 1) {
return RespBean.ok("更改成功");
}
return RespBean.error("更改失败");
}
}
salarySerice
@Service
public class SalaryService {
@Autowired
SalaryMapper salaryMapper;
public List<Salary> getAllSalary() {
return salaryMapper.getAllSalary();
}
public Integer addSalary(Salary salary) {
return salaryMapper.insertSelective(salary);
}
public Integer deleteSalary(Integer id) {
return salaryMapper.deleteByPrimaryKey(id);
}
public Integer updateSalary(Salary salary) {
return salaryMapper.updateByPrimaryKeySelective(salary);
}
}
mapper
public interface SalaryMapper {
int deleteByPrimaryKey(Integer id);
int insert(Salary record);
int insertSelective(Salary record);
Salary selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(Salary record);
int updateByPrimaryKey(Salary record);
List<Salary> getAllSalary();
}
xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.qwl.vhr.mapper.SalaryMapper" >
<resultMap id="BaseResultMap" type="com.qwl.vhr.model.Salary" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="basicSalary" property="basicsalary" jdbcType="INTEGER" />
<result column="bonus" property="bonus" jdbcType="INTEGER" />
<result column="lunchSalary" property="lunchsalary" jdbcType="INTEGER" />
<result column="trafficSalary" property="trafficsalary" jdbcType="INTEGER" />
<result column="allSalary" property="allsalary" jdbcType="INTEGER" />
<result column="pensionBase" property="pensionbase" jdbcType="INTEGER" />
<result column="pensionPer" property="pensionper" jdbcType="REAL" />
<result column="createDate" property="createdate" jdbcType="TIMESTAMP" />
<result column="medicalBase" property="medicalbase" jdbcType="INTEGER" />
<result column="medicalPer" property="medicalper" jdbcType="REAL" />
<result column="accumulationFundBase" property="accumulationfundbase" jdbcType="INTEGER" />
<result column="accumulationFundPer" property="accumulationfundper" jdbcType="REAL" />
<result column="name" property="name" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, basicSalary, bonus, lunchSalary, trafficSalary, allSalary, pensionBase, pensionPer,
createDate, medicalBase, medicalPer, accumulationFundBase, accumulationFundPer, name
</sql>
<select id="getAllSalary" resultType="com.qwl.vhr.model.Salary">
select
<include refid="Base_Column_List"></include>
from salary
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from salary
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from salary
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.qwl.vhr.model.Salary" >
insert into salary (id, basicSalary, bonus,
lunchSalary, trafficSalary, allSalary,
pensionBase, pensionPer, createDate,
medicalBase, medicalPer, accumulationFundBase,
accumulationFundPer, name)
values (#{id,jdbcType=INTEGER}, #{basicsalary,jdbcType=INTEGER}, #{bonus,jdbcType=INTEGER},
#{lunchsalary,jdbcType=INTEGER}, #{trafficsalary,jdbcType=INTEGER}, #{allsalary,jdbcType=INTEGER},
#{pensionbase,jdbcType=INTEGER}, #{pensionper,jdbcType=REAL}, #{createdate,jdbcType=TIMESTAMP},
#{medicalbase,jdbcType=INTEGER}, #{medicalper,jdbcType=REAL}, #{accumulationfundbase,jdbcType=INTEGER},
#{accumulationfundper,jdbcType=REAL}, #{name,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.qwl.vhr.model.Salary" >
insert into salary
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="basicsalary != null" >
basicSalary,
</if>
<if test="bonus != null" >
bonus,
</if>
<if test="lunchsalary != null" >
lunchSalary,
</if>
<if test="trafficsalary != null" >
trafficSalary,
</if>
<if test="allsalary != null" >
allSalary,
</if>
<if test="pensionbase != null" >
pensionBase,
</if>
<if test="pensionper != null" >
pensionPer,
</if>
<if test="createdate != null" >
createDate,
</if>
<if test="medicalbase != null" >
medicalBase,
</if>
<if test="medicalper != null" >
medicalPer,
</if>
<if test="accumulationfundbase != null" >
accumulationFundBase,
</if>
<if test="accumulationfundper != null" >
accumulationFundPer,
</if>
<if test="name != null" >
name,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="basicsalary != null" >
#{basicsalary,jdbcType=INTEGER},
</if>
<if test="bonus != null" >
#{bonus,jdbcType=INTEGER},
</if>
<if test="lunchsalary != null" >
#{lunchsalary,jdbcType=INTEGER},
</if>
<if test="trafficsalary != null" >
#{trafficsalary,jdbcType=INTEGER},
</if>
<if test="allsalary != null" >
#{allsalary,jdbcType=INTEGER},
</if>
<if test="pensionbase != null" >
#{pensionbase,jdbcType=INTEGER},
</if>
<if test="pensionper != null" >
#{pensionper,jdbcType=REAL},
</if>
<if test="createdate != null" >
#{createdate,jdbcType=TIMESTAMP},
</if>
<if test="medicalbase != null" >
#{medicalbase,jdbcType=INTEGER},
</if>
<if test="medicalper != null" >
#{medicalper,jdbcType=REAL},
</if>
<if test="accumulationfundbase != null" >
#{accumulationfundbase,jdbcType=INTEGER},
</if>
<if test="accumulationfundper != null" >
#{accumulationfundper,jdbcType=REAL},
</if>
<if test="name != null" >
#{name,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.qwl.vhr.model.Salary" >
update salary
<set >
<if test="basicsalary != null" >
basicSalary = #{basicsalary,jdbcType=INTEGER},
</if>
<if test="bonus != null" >
bonus = #{bonus,jdbcType=INTEGER},
</if>
<if test="lunchsalary != null" >
lunchSalary = #{lunchsalary,jdbcType=INTEGER},
</if>
<if test="trafficsalary != null" >
trafficSalary = #{trafficsalary,jdbcType=INTEGER},
</if>
<if test="allsalary != null" >
allSalary = #{allsalary,jdbcType=INTEGER},
</if>
<if test="pensionbase != null" >
pensionBase = #{pensionbase,jdbcType=INTEGER},
</if>
<if test="pensionper != null" >
pensionPer = #{pensionper,jdbcType=REAL},
</if>
<if test="createdate != null" >
createDate = #{createdate,jdbcType=TIMESTAMP},
</if>
<if test="medicalbase != null" >
medicalBase = #{medicalbase,jdbcType=INTEGER},
</if>
<if test="medicalper != null" >
medicalPer = #{medicalper,jdbcType=REAL},
</if>
<if test="accumulationfundbase != null" >
accumulationFundBase = #{accumulationfundbase,jdbcType=INTEGER},
</if>
<if test="accumulationfundper != null" >
accumulationFundPer = #{accumulationfundper,jdbcType=REAL},
</if>
<if test="name != null" >
name = #{name,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.qwl.vhr.model.Salary" >
update salary
set basicSalary = #{basicsalary,jdbcType=INTEGER},
bonus = #{bonus,jdbcType=INTEGER},
lunchSalary = #{lunchsalary,jdbcType=INTEGER},
trafficSalary = #{trafficsalary,jdbcType=INTEGER},
allSalary = #{allsalary,jdbcType=INTEGER},
pensionBase = #{pensionbase,jdbcType=INTEGER},
pensionPer = #{pensionper,jdbcType=REAL},
createDate = #{createdate,jdbcType=TIMESTAMP},
medicalBase = #{medicalbase,jdbcType=INTEGER},
medicalPer = #{medicalper,jdbcType=REAL},
accumulationFundBase = #{accumulationfundbase,jdbcType=INTEGER},
accumulationFundPer = #{accumulationfundper,jdbcType=REAL},
name = #{name,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
页面设计
<template>
<div>
<div style="display: flex;justify-content: space-between">
<el-button icon="el-icon-plus" type="primary" @click="showAddSalaryView">添加工资账套</el-button>
<el-button icon="el-icon-refresh" type="success" @click="initSalaries"></el-button>
</div>
<div style="margin-top: 10px">
<el-table :data="salaries" border stripe>
<el-table-column type="selection" width="55"></el-table-column>
<el-table-column width="120" prop="name" label="账套名称"></el-table-column>
<el-table-column width="70" prop="basicsalary" label="基本工资"></el-table-column>
<el-table-column width="70" prop="trafficsalary" label="交通补助"></el-table-column>
<el-table-column width="70" prop="lunchsalary" label="午餐补助"></el-table-column>
<el-table-column width="70" prop="bonus" label="奖金"></el-table-column>
<el-table-column width="100" prop="createdate" label="启用时间"></el-table-column>
<el-table-column label="养老金" align="center">
<el-table-column width="70" prop="pensionper" label="比率"></el-table-column>
<el-table-column width="70" prop="pensionbase" label="基数"></el-table-column>
</el-table-column>
<el-table-column label="医疗保险" align="center">
<el-table-column width="70" prop="medicalper" label="比率"></el-table-column>
<el-table-column width="70" prop="medicalbase" label="基数"></el-table-column>
</el-table-column>
<el-table-column label="公积金" align="center">
<el-table-column width="70" prop="accumulationfundper" label="比率"></el-table-column>
<el-table-column width="70" prop="accumulationfundbase" label="基数"></el-table-column>
</el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button @click="showEditSalaryView(scope.row)">编辑</el-button>
<el-button type="danger" @click="deleteSalary(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
</div>
<el-dialog
:title="dialogTitle"
:visible.sync="dialogVisible"
width="50%">
<div style="display: flex;justify-content: space-around;align-items: center">
<el-steps direction="vertical" :active="activeItemIndex">
<el-step :title="itemName" v-for="(itemName,index) in salaryItemName" :key="index"></el-step>
</el-steps>
<el-input v-model="salary[title]" :placeholder="'请输入'+salaryItemName[index]+'...'"
v-for="(value,title,index) in salary"
:key="index" v-show="activeItemIndex==index" style="width: 200px"></el-input>
</div>
<span slot="footer" class="dialog-footer">
<el-button @click="preStep">{{activeItemIndex==10?'取消':'上一步'}}</el-button>
<el-button type="primary" @click="nextStep">{{activeItemIndex==10?'完成':'下一步'}}</el-button>
</span>
</el-dialog>
</div>
</template>
<script>
export default {
name: "SalSob",
data() {
return {
dialogVisible: false,
dialogTitle: '添加工资账套',
salaries: [],
activeItemIndex: 0,
salaryItemName: [
'基本工资',
'交通补助',
'午餐补助',
'奖金',
'养老金比率',
'养老金基数',
'医疗保险比率',
'医疗保险基数',
'公积金比率',
'公积金基数',
'账套名称'
],
salary: {
basicsalary: 0,
trafficsalary: 0,
lunchsalary: 0,
bonus: 0,
pensionper: 0,
pensionbase: 0,
medicalper: 0,
medicalbase: 0,
accumulationfundper: 0,
accumulationfundbase: 0,
name: ''
}
}
},
mounted() {
this.initSalaries();
},
methods: {
showEditSalaryView(data) {
this.dialogTitle = '修改工资账套';
this.dialogVisible = true;
this.salary.basicsalary = data.basicsalary;
this.salary.trafficsalary = data.trafficsalary;
this.salary.lunchsalary = data.lunchsalary;
this.salary.bonus = data.bonus;
this.salary.pensionper = data.pensionper;
this.salary.pensionbase = data.pensionbase;
this.salary.medicalper = data.medicalper;
this.salary.medicalbase = data.medicalbase;
this.salary.accumulationfundper = data.accumulationfundper;
this.salary.accumulationfundbase = data.accumulationfundbase;
this.salary.name = data.name;
this.salary.id = data.id;
},
deleteSalary(data) {
this.$confirm('此操作将删除【' + data.name + '】账套,是否继续?', '提示', {
cancelButtonText: '取消',
confirmButtonText: '确定'
}).then(() => {
this.deleteRequest("/salary/sob/" + data.id).then(resp => {
if (resp) {
this.initSalaries();
}
})
}).catch(() => {
this.$message.info("取消删除!");
})
},
preStep() {
if (this.activeItemIndex == 0) {
return;
} else if (this.activeItemIndex == 10) {
//关闭对话框
this.dialogVisible = false;
return;
}
this.activeItemIndex--;
},
nextStep() {
if (this.activeItemIndex == 10) {
if (this.salary.id) {
this.putRequest("/salary/sob/", this.salary).then(resp=>{
if (resp) {
this.initSalaries();
this.dialogVisible = false;
}
})
} else {
this.postRequest("/salary/sob/", this.salary).then(resp => {
if (resp) {
this.initSalaries();
this.dialogVisible = false;
}
});
}
return;
}
this.activeItemIndex++;
},
showAddSalaryView() {
//数据初始化
this.salary = {
basicsalary: 0,
trafficsalary: 0,
lunchsalary: 0,
bonus: 0,
pensionper: 0,
pensionbase: 0,
medicalper: 0,
medicalbase: 0,
accumulationfundper: 0,
accumulationfundbase: 0,
name: '默认名称'
}
this.dialogTitle = '添加工资账套';
this.activeItemIndex = 0;
this.dialogVisible = true;
},
initSalaries() {
this.getRequest("/salary/sob/").then(resp => {
if (resp) {
this.salaries = resp;
}
})
}
}
}
</script>
<style scoped>
</style>