1.帮忙设计一个表格生成sql 包含职级 自动计算 提成扣减 扣减比例 扣减后金额 运营姓名 实际流水 业绩流水 有效流水 实际毛利 业绩毛利 提成字段 每一个字段加上备注 2.帮忙转成java实体

1.帮忙设计一个表格生成sql 包含职级 自动计算 提成扣减 扣减比例 扣减后金额
运营姓名 实际流水 业绩流水 有效流水 实际毛利 业绩毛利 提成字段 每一个字段加上备注

2.帮忙转成java实体并且实体加上备注

3.帮忙根据前面的实体生成xml

4.帮忙根据前面的实体生成mybatis 框架对应的xml 需要包含mapper resultMap映射的 resultMap包含jdbcType

5.还需要对应的Mapper service serviceImpl controller

1. 设计表格并生成 SQL

让我们先定义一个表结构,然后编写 SQL 语句来创建这个表。

表格结构
  • id: 主键,自增长
  • job_level: 职级 (VARCHAR)
  • is_auto_calculate: 是否自动计算 (BOOLEAN)
  • commission_deduction: 提成扣减 (DECIMAL)
  • deduction_rate: 扣减比例 (DECIMAL)
  • after_deduction_amount: 扣减后金额 (DECIMAL)
  • operator_name: 运营姓名 (VARCHAR)
  • actual_turnover: 实际流水 (DECIMAL)
  • performance_turnover: 业绩流水 (DECIMAL)
  • valid_turnover: 有效流水 (DECIMAL)
  • actual_profit: 实际毛利 (DECIMAL)
  • performance_profit: 业绩毛利 (DECIMAL)
  • commission: 提成字段 (DECIMAL)
SQL 语句
CREATE TABLE `employee_commission` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `job_level` VARCHAR(255) COMMENT '职级',
  `is_auto_calculate` BOOLEAN DEFAULT FALSE COMMENT '是否自动计算',
  `commission_deduction` DECIMAL(10, 2) COMMENT '提成扣减',
  `deduction_rate` DECIMAL(5, 2) COMMENT '扣减比例',
  `after_deduction_amount` DECIMAL(10, 2) COMMENT '扣减后金额',
  `operator_name` VARCHAR(255) COMMENT '运营姓名',
  `actual_turnover` DECIMAL(10, 2) COMMENT '实际流水',
  `performance_turnover` DECIMAL(10, 2) COMMENT '业绩流水',
  `valid_turnover` DECIMAL(10, 2) COMMENT '有效流水',
  `actual_profit` DECIMAL(10, 2) COMMENT '实际毛利',
  `performance_profit` DECIMAL(10, 2) COMMENT '业绩毛利',
  `commission` DECIMAL(10, 2) COMMENT '提成字段'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='员工提成表';

2. Java 实体类

接下来,我们创建一个 Java 实体类来表示上述表中的数据。

package com.example.model;

import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

@Table(name = "employee_commission")
public class EmployeeCommission {

    @Id
    private Integer id; // 主键

    private String jobLevel; // 职级

    private Boolean isAutoCalculate; // 是否自动计算

    private Double commissionDeduction; // 提成扣减

    private Double deductionRate; // 扣减比例

    private Double afterDeductionAmount; // 扣减后金额

    private String operatorName; // 运营姓名

    private Double actualTurnover; // 实际流水

    private Double performanceTurnover; // 业绩流水

    private Double validTurnover; // 有效流水

    private Double actualProfit; // 实际毛利

    private Double performanceProfit; // 业绩毛利

    private Double commission; // 提成字段

    // Getters and Setters
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getJobLevel() {
        return jobLevel;
    }

    public void setJobLevel(String jobLevel) {
        this.jobLevel = jobLevel;
    }

    public Boolean getIsAutoCalculate() {
        return isAutoCalculate;
    }

    public void setIsAutoCalculate(Boolean isAutoCalculate) {
        this.isAutoCalculate = isAutoCalculate;
    }

    public Double getCommissionDeduction() {
        return commissionDeduction;
    }

    public void setCommissionDeduction(Double commissionDeduction) {
        this.commissionDeduction = commissionDeduction;
    }

    public Double getDeductionRate() {
        return deductionRate;
    }

    public void setDeductionRate(Double deductionRate) {
        this.deductionRate = deductionRate;
    }

    public Double getAfterDeductionAmount() {
        return afterDeductionAmount;
    }

    public void setAfterDeductionAmount(Double afterDeductionAmount) {
        this.afterDeductionAmount = afterDeductionAmount;
    }

    public String getOperatorName() {
        return operatorName;
    }

    public void setOperatorName(String operatorName) {
        this.operatorName = operatorName;
    }

    public Double getActualTurnover() {
        return actualTurnover;
    }

    public void setActualTurnover(Double actualTurnover) {
        this.actualTurnover = actualTurnover;
    }

    public Double getPerformanceTurnover() {
        return performanceTurnover;
    }

    public void setPerformanceTurnover(Double performanceTurnover) {
        this.performanceTurnover = performanceTurnover;
    }

    public Double getValidTurnover() {
        return validTurnover;
    }

    public void setValidTurnover(Double validTurnover) {
        this.validTurnover = validTurnover;
    }

    public Double getActualProfit() {
        return actualProfit;
    }

    public void setActualProfit(Double actualProfit) {
        this.actualProfit = actualProfit;
    }

    public Double getPerformanceProfit() {
        return performanceProfit;
    }

    public void setPerformanceProfit(Double performanceProfit) {
        this.performanceProfit = performanceProfit;
    }

    public Double getCommission() {
        return commission;
    }

    public void setCommission(Double commission) {
        this.commission = commission;
    }
}

3. & 4. MyBatis 映射文件

MyBatis 的映射文件需要定义 SQL 查询和结果映射。

<?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.example.mapper.EmployeeCommissionMapper">

    <resultMap id="EmployeeCommissionResultMap" type="com.example.model.EmployeeCommission">
        <id property="id" column="id" jdbcType="INTEGER"/>
        <result property="jobLevel" column="job_level" jdbcType="VARCHAR"/>
        <result property="isAutoCalculate" column="is_auto_calculate" jdbcType="BOOLEAN"/>
        <result property="commissionDeduction" column="commission_deduction" jdbcType="DECIMAL"/>
        <result property="deductionRate" column="deduction_rate" jdbcType="DECIMAL"/>
        <result property="afterDeductionAmount" column="after_deduction_amount" jdbcType="DECIMAL"/>
        <result property="operatorName" column="operator_name" jdbcType="VARCHAR"/>
        <result property="actualTurnover" column="actual_turnover" jdbcType="DECIMAL"/>
        <result property="performanceTurnover" column="performance_turnover" jdbcType="DECIMAL"/>
        <result property="validTurnover" column="valid_turnover" jdbcType="DECIMAL"/>
        <result property="actualProfit" column="actual_profit" jdbcType="DECIMAL"/>
        <result property="performanceProfit" column="performance_profit" jdbcType="DECIMAL"/>
        <result property="commission" column="commission" jdbcType="DECIMAL"/>
    </resultMap>

    <insert id="insert" parameterType="com.example.model.EmployeeCommission">
        INSERT INTO employee_commission
        (job_level, is_auto_calculate, commission_deduction, deduction_rate, after_deduction_amount, operator_name, actual_turnover, performance_turnover, valid_turnover, actual_profit, performance_profit, commission)
        VALUES
        (#{jobLevel}, #{isAutoCalculate}, #{commissionDeduction}, #{deductionRate}, #{afterDeductionAmount}, #{operatorName}, #{actualTurnover}, #{performanceTurnover}, #{validTurnover}, #{actualProfit}, #{performanceProfit}, #{commission})
    </insert>

    <update id="update" parameterType="com.example.model.EmployeeCommission">
        UPDATE employee_commission SET
        job_level = #{jobLevel},
        is_auto_calculate = #{isAutoCalculate},
        commission_deduction = #{commissionDeduction},
        deduction_rate = #{deductionRate},
        after_deduction_amount = #{afterDeductionAmount},
        operator_name = #{operatorName},
        actual_turnover = #{actualTurnover},
        performance_turnover = #{performanceTurnover},
        valid_turnover = #{validTurnover},
        actual_profit = #{actualProfit},
        performance_profit = #{performanceProfit},
        commission = #{commission}
        WHERE id = #{id}
    </update>

    <select id="selectById" resultMap="EmployeeCommissionResultMap" parameterType="int">
        SELECT * FROM employee_commission WHERE id = #{id}
    </select>

    <delete id="deleteById" parameterType="int">
        DELETE FROM employee_commission WHERE id = #{id}
    </delete>

    <select id="selectAll" resultMap="EmployeeCommissionResultMap">
        SELECT * FROM employee_commission
    </select>
</mapper>

5. Mapper, Service, ServiceImpl, Controller

Mapper Interface
package com.example.mapper;

import com.example.model.EmployeeCommission;
import java.util.List;

public interface EmployeeCommissionMapper {

    void insert(EmployeeCommission record);

    void update(EmployeeCommission record);

    EmployeeCommission selectById(Integer id);

    void deleteById(Integer id);

    List<EmployeeCommission> selectAll();
}
Service Interface
package com.example.service;

import com.example.model.EmployeeCommission;
import java.util.List;

public interface EmployeeCommissionService {

    void insert(EmployeeCommission record);

    void update(EmployeeCommission record);

    EmployeeCommission selectById(Integer id);

    void deleteById(Integer id);

    List<EmployeeCommission> selectAll();
}
Service Implementation
package com.example.service.impl;

import com.example.mapper.EmployeeCommissionMapper;
import com.example.model.EmployeeCommission;
import com.example.service.EmployeeCommissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeCommissionServiceImpl implements EmployeeCommissionService {

    @Autowired
    private EmployeeCommissionMapper employeeCommissionMapper;

    @Override
    public void insert(EmployeeCommission record) {
        employeeCommissionMapper.insert(record);
    }

    @Override
    public void update(EmployeeCommission record) {
        employeeCommissionMapper.update(record);
    }

    @Override
    public EmployeeCommission selectById(Integer id) {
        return employeeCommissionMapper.selectById(id);
    }

    @Override
    public void deleteById(Integer id) {
        employeeCommissionMapper.deleteById(id);
    }

    @Override
    public List<EmployeeCommission> selectAll() {
        return employeeCommissionMapper.selectAll();
    }
}
Controller
package com.example.controller;

import com.example.model.EmployeeCommission;
import com.example.service.EmployeeCommissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/employee-commissions")
public class EmployeeCommissionController {

    @Autowired
    private EmployeeCommissionService employeeCommissionService;

    @PostMapping
    public void create(@RequestBody EmployeeCommission employeeCommission) {
        employeeCommissionService.insert(employeeCommission);
    }

    @PutMapping("/{id}")
    public void update(@PathVariable Integer id, @RequestBody EmployeeCommission employeeCommission) {
        employeeCommission.setId(id); // Ensure the ID matches the path variable
        employeeCommissionService.update(employeeCommission);
    }

    @GetMapping("/{id}")
    public EmployeeCommission getById(@PathVariable Integer id) {
        return employeeCommissionService.selectById(id);
    }

    @DeleteMapping("/{id}")
    public void deleteById(@PathVariable Integer id) {
        employeeCommissionService.deleteById(id);
    }

    @GetMapping
    public List<EmployeeCommission> getAll() {
        return employeeCommissionService.selectAll();
    }
}

以上就是完整的代码实现。如果你有任何疑问或者需要进一步的帮助,请随时告知。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值