|
@@ -1,7 +1,10 @@
|
|
|
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;
|
|
|
import com.sky.exception.AccountLockedException;
|
|
@@ -9,10 +12,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 {
|
|
|
|
|
@@ -39,7 +45,8 @@ public class EmployeeServiceImpl implements EmployeeService {
|
|
|
}
|
|
|
|
|
|
//密码比对
|
|
|
- // TODO 后期需要进行md5加密,然后再进行比对
|
|
|
+ // 对前端传来的明文密码进行md5加密处理
|
|
|
+ password = DigestUtils.md5DigestAsHex(password.getBytes());
|
|
|
if (!password.equals(employee.getPassword())) {
|
|
|
//密码错误
|
|
|
throw new PasswordErrorException(MessageConstant.PASSWORD_ERROR);
|
|
@@ -54,4 +61,33 @@ public class EmployeeServiceImpl implements EmployeeService {
|
|
|
return employee;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增员工
|
|
|
+ * @param employeeDTO
|
|
|
+ */
|
|
|
+ public void save(EmployeeDTO employeeDTO) {
|
|
|
+ Employee employee = new Employee();
|
|
|
+
|
|
|
+ //对象属性拷贝
|
|
|
+ BeanUtils.copyProperties(employeeDTO,employee);
|
|
|
+
|
|
|
+ //设置账号的状态,默认正常状态1,0表示锁定
|
|
|
+ employee.setStatus(StatusConstant.ENABLE);
|
|
|
+
|
|
|
+ //设置密码,默认密码123456
|
|
|
+ employee.setPassword(DigestUtils.md5DigestAsHex(PasswordConstant.DEFAULT_PASSWORD.getBytes()));
|
|
|
+
|
|
|
+ //设置当前记录的创建时间和修改时间
|
|
|
+ employee.setCreateTime(LocalDateTime.now());
|
|
|
+ employee.setUpdateTime(LocalDateTime.now());
|
|
|
+
|
|
|
+ //设置当前记录创建人id和修改人id
|
|
|
+ //TODO 后期需要改为当前登陆人id
|
|
|
+ employee.setCreateUser(BaseContext.getCurrentId());
|
|
|
+ employee.setUpdateUser(BaseContext.getCurrentId());
|
|
|
+
|
|
|
+ employeeMapper.insert(employee);
|
|
|
+ }
|
|
|
+
|
|
|
}
|