1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| package com.atguigu.demo.component.dao;
import com.atguigu.demo.entity.Department; import com.atguigu.demo.entity.Employee; import org.springframework.stereotype.Repository;
import java.util.*;
@Repository public class EmpDao {
private static Map<String, Employee> dataMap;
static { dataMap = new HashMap<>();
String empId = UUID.randomUUID().toString(); dataMap.put(empId, new Employee(empId, "乔峰", "SSN001", DeptDao.getDeptByName("市场部")));
empId = UUID.randomUUID().toString(); dataMap.put(empId, new Employee(empId, "虚竹", "SSN002", DeptDao.getDeptByName("市场部")));
empId = UUID.randomUUID().toString(); dataMap.put(empId, new Employee(empId, "段誉", "SSN003", DeptDao.getDeptByName("市场部")));
empId = UUID.randomUUID().toString(); dataMap.put(empId, new Employee(empId, "鸠摩智", "SSN004", DeptDao.getDeptByName("技术部")));
empId = UUID.randomUUID().toString(); dataMap.put(empId, new Employee(empId, "萧远山", "SSN005", DeptDao.getDeptByName("技术部")));
empId = UUID.randomUUID().toString(); dataMap.put(empId, new Employee(empId, "慕容复", "SSN006", DeptDao.getDeptByName("技术部")));
empId = UUID.randomUUID().toString(); dataMap.put(empId, new Employee(empId, "段正淳", "SSN007", DeptDao.getDeptByName("公关部")));
empId = UUID.randomUUID().toString(); dataMap.put(empId, new Employee(empId, "段延庆", "SSN008", DeptDao.getDeptByName("公关部")));
empId = UUID.randomUUID().toString(); dataMap.put(empId, new Employee(empId, "丁春秋", "SSN009", DeptDao.getDeptByName("销售部")));
empId = UUID.randomUUID().toString(); dataMap.put(empId, new Employee(empId, "无崖子", "SSN010", DeptDao.getDeptByName("人事部")));
empId = UUID.randomUUID().toString(); dataMap.put(empId, new Employee(empId, "慕容博", "SSN011", DeptDao.getDeptByName("人事部"))); }
public void saveEmp(Employee employee) {
String empId = UUID.randomUUID().toString(); employee.setEmpId(empId);
String deptId = employee.getDepartment().getDeptId(); Department department = DeptDao.getDeptById(deptId); employee.setDepartment(department);
dataMap.put(empId, employee); }
public void removeEmp(String empId) { dataMap.remove(empId); }
public void updateEmp(Employee employee) {
String deptId = employee.getDepartment().getDeptId(); Department department = DeptDao.getDeptById(deptId); employee.setDepartment(department);
dataMap.put(employee.getEmpId(), employee); }
public Employee getEmpById(String empId) { return dataMap.get(empId); }
public List<Employee> getEmpList() { return new ArrayList<>(dataMap.values()); } }
|