苍穹外卖--新增员工工程实现
This commit is contained in:
@@ -1,16 +1,22 @@
|
|||||||
package com.sky.dto;
|
package com.sky.dto;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@ApiModel("新增员工DTO")
|
||||||
public class EmployeeDTO implements Serializable {
|
public class EmployeeDTO implements Serializable {
|
||||||
|
|
||||||
|
@ApiModelProperty("员工id")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
@ApiModelProperty("用户名")
|
||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
|
@ApiModelProperty("姓名")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private String phone;
|
private String phone;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.sky.controller.admin;
|
package com.sky.controller.admin;
|
||||||
|
|
||||||
import com.sky.constant.JwtClaimsConstant;
|
import com.sky.constant.JwtClaimsConstant;
|
||||||
|
import com.sky.dto.EmployeeDTO;
|
||||||
import com.sky.dto.EmployeeLoginDTO;
|
import com.sky.dto.EmployeeLoginDTO;
|
||||||
import com.sky.entity.Employee;
|
import com.sky.entity.Employee;
|
||||||
import com.sky.properties.JwtProperties;
|
import com.sky.properties.JwtProperties;
|
||||||
@@ -76,4 +77,18 @@ public class EmployeeController {
|
|||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增员工
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ApiOperation("新增员工")
|
||||||
|
@PostMapping
|
||||||
|
public Result save(@RequestBody EmployeeDTO employeeDTO) {
|
||||||
|
log.info("新增员工:{}",employeeDTO);
|
||||||
|
//调用业务层新增员工
|
||||||
|
employeeService.save(employeeDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.sky.mapper;
|
package com.sky.mapper;
|
||||||
|
|
||||||
import com.sky.entity.Employee;
|
import com.sky.entity.Employee;
|
||||||
|
import org.apache.ibatis.annotations.Insert;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
@@ -15,4 +16,11 @@ public interface EmployeeMapper {
|
|||||||
@Select("select * from employee where username = #{username}")
|
@Select("select * from employee where username = #{username}")
|
||||||
Employee getByUsername(String 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;
|
package com.sky.service;
|
||||||
|
|
||||||
|
import com.sky.dto.EmployeeDTO;
|
||||||
import com.sky.dto.EmployeeLoginDTO;
|
import com.sky.dto.EmployeeLoginDTO;
|
||||||
import com.sky.entity.Employee;
|
import com.sky.entity.Employee;
|
||||||
|
|
||||||
@@ -12,4 +13,8 @@ import com.sky.entity.Employee;
|
|||||||
*/
|
*/
|
||||||
Employee login(EmployeeLoginDTO employeeLoginDTO);
|
Employee login(EmployeeLoginDTO employeeLoginDTO);
|
||||||
|
|
||||||
|
/*
|
||||||
|
新增员工
|
||||||
|
*/
|
||||||
|
void save(EmployeeDTO employeeDTO);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package com.sky.service.impl;
|
package com.sky.service.impl;
|
||||||
|
|
||||||
import com.sky.constant.MessageConstant;
|
import com.sky.constant.MessageConstant;
|
||||||
|
import com.sky.constant.PasswordConstant;
|
||||||
import com.sky.constant.StatusConstant;
|
import com.sky.constant.StatusConstant;
|
||||||
|
import com.sky.dto.EmployeeDTO;
|
||||||
import com.sky.dto.EmployeeLoginDTO;
|
import com.sky.dto.EmployeeLoginDTO;
|
||||||
import com.sky.entity.Employee;
|
import com.sky.entity.Employee;
|
||||||
import com.sky.exception.AccountLockedException;
|
import com.sky.exception.AccountLockedException;
|
||||||
@@ -9,10 +11,13 @@ import com.sky.exception.AccountNotFoundException;
|
|||||||
import com.sky.exception.PasswordErrorException;
|
import com.sky.exception.PasswordErrorException;
|
||||||
import com.sky.mapper.EmployeeMapper;
|
import com.sky.mapper.EmployeeMapper;
|
||||||
import com.sky.service.EmployeeService;
|
import com.sky.service.EmployeeService;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.DigestUtils;
|
import org.springframework.util.DigestUtils;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class EmployeeServiceImpl implements EmployeeService {
|
public class EmployeeServiceImpl implements EmployeeService {
|
||||||
|
|
||||||
@@ -55,4 +60,29 @@ public class EmployeeServiceImpl implements EmployeeService {
|
|||||||
return employee;
|
return employee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
新增员工
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void save(EmployeeDTO employeeDTO) {
|
||||||
|
//1.对象属性拷贝:EmployeeDTO--->Employee
|
||||||
|
Employee employee = new Employee();
|
||||||
|
BeanUtils.copyProperties(employeeDTO,employee);
|
||||||
|
//2.设置账号的状态,默认正常状态:1,0表示禁用
|
||||||
|
employee.setStatus(StatusConstant.ENABLE);
|
||||||
|
//3.设置创建时间和更新时间
|
||||||
|
employee.setCreateTime(LocalDateTime.now());
|
||||||
|
employee.setUpdateTime(LocalDateTime.now());
|
||||||
|
//4.设置当前记录创建人和修改人的id
|
||||||
|
//todo 后期要修改为当前登录用户的id
|
||||||
|
employee.setCreateUser(1L);
|
||||||
|
employee.setUpdateUser(1L);
|
||||||
|
|
||||||
|
//添加默认密码
|
||||||
|
employee.setPassword(DigestUtils.md5DigestAsHex(PasswordConstant.DEFAULT_PASSWORD.getBytes()));
|
||||||
|
|
||||||
|
//5.将数据保存到数据库,调用Mapper操作数据库
|
||||||
|
employeeMapper.insert(employee);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user