外卖项目day01-新增员工_代码开发
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.sky.controller.admin;
|
||||
|
||||
import com.sky.constant.JwtClaimsConstant;
|
||||
import com.sky.dto.EmployeeDTO;
|
||||
import com.sky.dto.EmployeeLoginDTO;
|
||||
import com.sky.entity.Employee;
|
||||
import com.sky.properties.JwtProperties;
|
||||
@@ -76,4 +77,12 @@ public class EmployeeController {
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@ApiOperation("新增员工")
|
||||
@PostMapping()
|
||||
public Result<String> save(@RequestBody EmployeeDTO employeeDTO) {
|
||||
log.info("新增员工:{}",employeeDTO);
|
||||
//调用业务层新增员工的功能
|
||||
employeeService.save(employeeDTO);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.sky.entity.Employee;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
@@ -15,4 +16,11 @@ public interface EmployeeMapper {
|
||||
@Select("select * from employee where username = #{username}")
|
||||
Employee getByUsername(String username);
|
||||
|
||||
/**
|
||||
* 新增员工
|
||||
* @param employee
|
||||
*/
|
||||
@Insert("insert into employee (name, username, password, phone, sex, id_number, create_time, update_time, create_user, update_user) " +
|
||||
"values (#{name},#{username},#{password},#{phone},#{sex},#{idNumber},#{createTime},#{updateTime},#{createUser},#{updateUser})")
|
||||
void insert(Employee employee);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.sky.service;
|
||||
|
||||
import com.sky.dto.EmployeeDTO;
|
||||
import com.sky.dto.EmployeeLoginDTO;
|
||||
import com.sky.entity.Employee;
|
||||
|
||||
@@ -12,4 +13,9 @@ public interface EmployeeService {
|
||||
*/
|
||||
Employee login(EmployeeLoginDTO employeeLoginDTO);
|
||||
|
||||
/**
|
||||
* 新增员工
|
||||
* @param employeeDTO
|
||||
*/
|
||||
void save(EmployeeDTO employeeDTO);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.sky.service.impl;
|
||||
|
||||
import com.sky.constant.MessageConstant;
|
||||
import com.sky.constant.PasswordConstant;
|
||||
import com.sky.constant.StatusConstant;
|
||||
import com.sky.dto.EmployeeDTO;
|
||||
import com.sky.dto.EmployeeLoginDTO;
|
||||
import com.sky.entity.Employee;
|
||||
import com.sky.exception.AccountLockedException;
|
||||
@@ -9,10 +11,13 @@ import com.sky.exception.AccountNotFoundException;
|
||||
import com.sky.exception.PasswordErrorException;
|
||||
import com.sky.mapper.EmployeeMapper;
|
||||
import com.sky.service.EmployeeService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Service
|
||||
public class EmployeeServiceImpl implements EmployeeService {
|
||||
|
||||
@@ -55,4 +60,27 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
return employee;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增员工
|
||||
* @param employeeDTO
|
||||
*/
|
||||
@Override
|
||||
public void save(EmployeeDTO employeeDTO) {
|
||||
//dto->Employee 相同属性值的复制
|
||||
Employee employee = new Employee();
|
||||
//对象属性拷贝
|
||||
BeanUtils.copyProperties(employeeDTO,employee);
|
||||
//设置账号的状态,默认正常状态 1:正常 0 表示锁定
|
||||
employee.setStatus(StatusConstant.ENABLE);
|
||||
//设置密码(暗文)
|
||||
employee.setPassword(DigestUtils.md5DigestAsHex(PasswordConstant.DEFAULT_PASSWORD.getBytes()));
|
||||
//补充剩下字段的值
|
||||
employee.setCreateTime(LocalDateTime.now());
|
||||
employee.setUpdateTime(LocalDateTime.now());
|
||||
//todo 先写死操作者,后面再处理
|
||||
employee.setCreateUser(1L);
|
||||
employee.setUpdateUser(1L);
|
||||
employeeMapper.insert(employee);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user