苍穹外卖实现员工账号启用禁用

178 阅读1分钟

员工账号启用禁用功能开发

1. 需求分析

为POST请求,提供路径参数status和id

image-20250728000511787

2. 代码开发

  1. controller层:
@PostMapping("/status/{status}")
    @ApiOperation(value = "启用禁用员工")
    public Result startOrStop(@PathVariable Integer status,Long id){
        log.info("启用禁用员工账号:{},{}",status,id);
        employeeService.startOrStop(status,id);
        return Result.success();
    }
  1. service层
public void startOrStop(Integer status, Long id) {
        Employee employee = Employee.builder().id(id).status(status).build();

        employeeMapper.update(employee);
    }
  1. mapper层(直接实现更新功能,对所有可能更新的数据进行更新)
void update(Employee employee);
  1. 动态SQL(这里直接把所有可能更新的数据写上)
<update id="update">
        update employee
        <set>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="username != null">username = #{username},</if>
            <if test="password != null">password = #{password},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="sex != null">sex = #{sex},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
            <if test="idNumber != null">idNumber = #{idNumber},</if>
            <if test="updateUser != null">updateUser = #{updateUser},</if>
            <if test="status != null">status = #{status}</if>
        </set>
        where id = #{id}
    </update>

3. 功能测试

Swagger测试:

image-20250728003456068

前后端联调测试:

image-20250728003549107

经过测试功能可以正常使用

4. 代码提交

点击Git,提交并推送

image-20250728004116904