苍穹外卖--新增员工功能完善二-通过ThreadLocal动态设置登录者ID
This commit is contained in:
@@ -3,6 +3,7 @@ package com.sky.service.impl;
|
||||
import com.sky.constant.MessageConstant;
|
||||
import com.sky.constant.PasswordConstant;
|
||||
import com.sky.constant.StatusConstant;
|
||||
import com.sky.context.BaseContext;
|
||||
import com.sky.dto.EmployeeDTO;
|
||||
import com.sky.dto.EmployeeLoginDTO;
|
||||
import com.sky.entity.Employee;
|
||||
@@ -11,6 +12,7 @@ import com.sky.exception.AccountNotFoundException;
|
||||
import com.sky.exception.PasswordErrorException;
|
||||
import com.sky.mapper.EmployeeMapper;
|
||||
import com.sky.service.EmployeeService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -19,6 +21,7 @@ import org.springframework.util.DigestUtils;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class EmployeeServiceImpl implements EmployeeService {
|
||||
|
||||
@Autowired
|
||||
@@ -65,6 +68,7 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
*/
|
||||
@Override
|
||||
public void save(EmployeeDTO employeeDTO) {
|
||||
log.info("新增员工Service层所处的线程id:{}",Thread.currentThread().getId());
|
||||
//1.对象属性拷贝:EmployeeDTO--->Employee
|
||||
Employee employee = new Employee();
|
||||
BeanUtils.copyProperties(employeeDTO,employee);
|
||||
@@ -75,8 +79,10 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
employee.setUpdateTime(LocalDateTime.now());
|
||||
//4.设置当前记录创建人和修改人的id
|
||||
//todo 后期要修改为当前登录用户的id
|
||||
employee.setCreateUser(1L);
|
||||
employee.setUpdateUser(1L);
|
||||
//取出拦截器中保存的登录员工ID,作为创建者和更新者ID数据
|
||||
Long empId = BaseContext.getCurrentId();
|
||||
employee.setCreateUser(empId);
|
||||
employee.setUpdateUser(empId);
|
||||
|
||||
//添加默认密码
|
||||
employee.setPassword(DigestUtils.md5DigestAsHex(PasswordConstant.DEFAULT_PASSWORD.getBytes()));
|
||||
|
||||
Reference in New Issue
Block a user