插入员工数据
This commit is contained in:
parent
7b0bd0e175
commit
cc6d1b8e5b
|
@ -1,9 +1,6 @@
|
|||
package com.sky.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
@ -41,5 +38,4 @@ public class Employee implements Serializable {
|
|||
private Long createUser;
|
||||
|
||||
private Long updateUser;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package com.sky.controller.admin;
|
||||
|
||||
import com.sky.constant.JwtClaimsConstant;
|
||||
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.properties.JwtProperties;
|
||||
|
@ -12,13 +15,16 @@ import io.swagger.annotations.Api;
|
|||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.DigestUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -78,4 +84,17 @@ public class EmployeeController {
|
|||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求新增员工
|
||||
*
|
||||
* @param employeeDTO 请求新增员工参数
|
||||
* @return Result
|
||||
*/
|
||||
@Operation(summary = "新增员工")
|
||||
@PostMapping
|
||||
public Result save(@RequestBody EmployeeDTO employeeDTO) {
|
||||
log.info("新增员工:{}", employeeDTO);
|
||||
employeeService.insert(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,9 @@ public interface EmployeeMapper {
|
|||
@Select("select * from employee where username = #{username}")
|
||||
Employee getByUsername(String username);
|
||||
|
||||
/**
|
||||
* 插入员工数据
|
||||
* @param employee 员工
|
||||
*/
|
||||
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;
|
||||
|
||||
|
@ -7,9 +8,14 @@ public interface EmployeeService {
|
|||
|
||||
/**
|
||||
* 员工登录
|
||||
* @param employeeLoginDTO
|
||||
* @return
|
||||
* @param employeeLoginDTO 员工请求
|
||||
* @return Employee
|
||||
*/
|
||||
Employee login(EmployeeLoginDTO employeeLoginDTO);
|
||||
|
||||
/**
|
||||
* 新增员工
|
||||
* @param employeeDTO 请求新增员工参数
|
||||
*/
|
||||
void insert(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,6 +11,7 @@ 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;
|
||||
|
@ -16,6 +19,7 @@ import org.springframework.util.DigestUtils;
|
|||
import javax.annotation.Resource;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Service
|
||||
public class EmployeeServiceImpl implements EmployeeService {
|
||||
|
@ -58,4 +62,31 @@ public class EmployeeServiceImpl implements EmployeeService {
|
|||
return employee;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 插入员工数据
|
||||
* @param employeeDTO EmployeeDTO
|
||||
*/
|
||||
@Override
|
||||
public void insert(EmployeeDTO employeeDTO) {
|
||||
Employee employee = new Employee();
|
||||
// 对象属性拷贝
|
||||
BeanUtils.copyProperties(employeeDTO, employee);
|
||||
|
||||
// 设置状态默认1正常,0表示锁定
|
||||
employee.setStatus(StatusConstant.ENABLE);
|
||||
employee.setPassword(DigestUtils.md5DigestAsHex(PasswordConstant.DEFAULT_PASSWORD.getBytes()));
|
||||
employee.setIdNumber(employeeDTO.getIdNumber());
|
||||
|
||||
// 设置当前时间
|
||||
employee.setCreateTime(LocalDateTime.now());
|
||||
employee.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
// 设置当前记录创建人id
|
||||
// TODO 当前是写死的,后期改为当前登录用户id
|
||||
employee.setCreateUser(10L);
|
||||
employee.setUpdateUser(10L);
|
||||
|
||||
employeeMapper.insert(employee);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,4 +2,12 @@
|
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.sky.mapper.EmployeeMapper">
|
||||
|
||||
|
||||
<insert id="insert">
|
||||
insert into employee (name, username, password, phone, sex, id, id_number, status, create_time, update_time,
|
||||
create_user, update_user)
|
||||
values (#{name}, #{username}, #{password}, #{phone}, #{sex}, #{id}, #{idNumber}, #{status}, #{createTime},
|
||||
#{updateTime}, #{createUser}, #{updateUser});
|
||||
</insert>
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue