|
@@ -1,8 +1,11 @@
|
|
|
package com.ruoyi.clock.service.impl;
|
|
package com.ruoyi.clock.service.impl;
|
|
|
|
|
|
|
|
|
|
+import cn.dev33.satoken.secure.BCrypt;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
+import com.ruoyi.clock.domain.Shop;
|
|
|
import com.ruoyi.clock.exception.EmployeeExceptionEnum;
|
|
import com.ruoyi.clock.exception.EmployeeExceptionEnum;
|
|
|
|
|
+import com.ruoyi.clock.exception.ShopExceptionEnum;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.BeanCopyUtils;
|
|
import com.ruoyi.common.utils.BeanCopyUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
@@ -34,6 +37,7 @@ import java.util.Collection;
|
|
|
public class EmployeeServiceImpl implements IEmployeeService {
|
|
public class EmployeeServiceImpl implements IEmployeeService {
|
|
|
|
|
|
|
|
private final EmployeeMapper baseMapper;
|
|
private final EmployeeMapper baseMapper;
|
|
|
|
|
+ public static final String password = "123456";
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 查询店员信息分页
|
|
* 查询店员信息分页
|
|
@@ -92,7 +96,7 @@ public class EmployeeServiceImpl implements IEmployeeService {
|
|
|
public Employee loadById(Long employeeId, Boolean tw){
|
|
public Employee loadById(Long employeeId, Boolean tw){
|
|
|
Employee info = this.baseMapper.selectById(employeeId);
|
|
Employee info = this.baseMapper.selectById(employeeId);
|
|
|
if(ObjectUtil.isEmpty(info) && tw){
|
|
if(ObjectUtil.isEmpty(info) && tw){
|
|
|
- throw new ServiceException(EmployeeExceptionEnum.Employee_IS_NOT_EXISTS);
|
|
|
|
|
|
|
+ throw new ServiceException(EmployeeExceptionEnum.EMPLOYEE_IS_NOT_EXISTS);
|
|
|
}
|
|
}
|
|
|
return info;
|
|
return info;
|
|
|
}
|
|
}
|
|
@@ -105,8 +109,9 @@ public class EmployeeServiceImpl implements IEmployeeService {
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public Boolean insertByBo(EmployeeBo bo) {
|
|
public Boolean insertByBo(EmployeeBo bo) {
|
|
|
|
|
+ validEntityBeforeSave(bo);
|
|
|
Employee add = BeanUtil.toBean(bo, Employee.class);
|
|
Employee add = BeanUtil.toBean(bo, Employee.class);
|
|
|
- validEntityBeforeSave(add);
|
|
|
|
|
|
|
+ add.setPassword(BCrypt.hashpw(password));
|
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
|
if (flag) {
|
|
if (flag) {
|
|
|
bo.setEmployeeId(add.getEmployeeId());
|
|
bo.setEmployeeId(add.getEmployeeId());
|
|
@@ -122,21 +127,31 @@ public class EmployeeServiceImpl implements IEmployeeService {
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public Boolean updateByBo(EmployeeBo bo) {
|
|
public Boolean updateByBo(EmployeeBo bo) {
|
|
|
|
|
+ validEntityBeforeSave(bo);
|
|
|
Employee employee = baseMapper.selectById(bo.getEmployeeId());
|
|
Employee employee = baseMapper.selectById(bo.getEmployeeId());
|
|
|
Employee update = BeanCopyUtils.copy(bo, employee);
|
|
Employee update = BeanCopyUtils.copy(bo, employee);
|
|
|
- validEntityBeforeSave(update);
|
|
|
|
|
return baseMapper.updateById(update) > 0;
|
|
return baseMapper.updateById(update) > 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 保存前的数据校验
|
|
* 保存前的数据校验
|
|
|
*
|
|
*
|
|
|
- * @param entity 实体类数据
|
|
|
|
|
|
|
+ * @param bo 实体类数据
|
|
|
*/
|
|
*/
|
|
|
- private void validEntityBeforeSave(Employee entity){
|
|
|
|
|
|
|
+ private void validEntityBeforeSave(EmployeeBo bo){
|
|
|
//TODO 做一些数据校验,如唯一约束
|
|
//TODO 做一些数据校验,如唯一约束
|
|
|
|
|
+ Employee employee = getEmployeeByPhone(bo.getPhonenumber());
|
|
|
|
|
+ if(ObjectUtil.isNotNull(employee)&& !employee.getEmployeeId().equals(bo.getEmployeeId())){
|
|
|
|
|
+ throw new ServiceException(EmployeeExceptionEnum.EMPLOYEE_PHONENUMBER_REPEAT);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public Employee getEmployeeByPhone(String phonenumber) {
|
|
|
|
|
+ return baseMapper.selectOne(new LambdaQueryWrapper<Employee>().eq(Employee::getPhonenumber,phonenumber)
|
|
|
|
|
+ .last("limit 1"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 批量删除店员信息
|
|
* 批量删除店员信息
|
|
|
*
|
|
*
|