release/2025-02-20-10-37
This commit is contained in:
parent
e3d9694b01
commit
899ce38b87
@ -1,5 +1,7 @@
|
||||
package com.example.nto.controller;
|
||||
|
||||
import com.example.nto.dto.EmployeeDataDto;
|
||||
import com.example.nto.dto.EntryDto;
|
||||
import com.example.nto.entity.EmployeeData;
|
||||
import com.example.nto.entity.Entry;
|
||||
import com.example.nto.service.AdminService;
|
||||
@ -23,7 +25,7 @@ public class AdminController {
|
||||
private void amIAdmin() {}
|
||||
|
||||
@PostMapping("/panel/get-employee-info")
|
||||
private EmployeeData getEmployeeInfo(@RequestParam("employee-login") String employeeLogin) {
|
||||
private EmployeeDataDto getEmployeeInfo(@RequestParam("employee-login") String employeeLogin) {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
String login = authentication.getName();
|
||||
return adminService.getEmployeeInfo(employeeLogin, login);
|
||||
@ -38,7 +40,7 @@ public class AdminController {
|
||||
}
|
||||
|
||||
@PostMapping("/panel/get-employee-entry-list")
|
||||
private List<Entry> getEmployeeEntryList(@RequestParam("employee-login") String employeeLogin) {
|
||||
private List<EntryDto> getEmployeeEntryList(@RequestParam("employee-login") String employeeLogin) {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
String login = authentication.getName();
|
||||
return adminService.getEmployeeEntryList(employeeLogin, login);
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.example.nto.controller;
|
||||
|
||||
import com.example.nto.dto.EmployeeDataDto;
|
||||
import com.example.nto.dto.EntryDto;
|
||||
import com.example.nto.entity.Code;
|
||||
import com.example.nto.entity.Employee;
|
||||
import com.example.nto.entity.EmployeeData;
|
||||
@ -25,7 +27,7 @@ public class EmployeeController {
|
||||
private void auth() {}
|
||||
|
||||
@PostMapping("/info")
|
||||
private EmployeeData info() {
|
||||
private EmployeeDataDto info() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
String login = authentication.getName();
|
||||
return employeeService.info(login);
|
||||
@ -39,7 +41,7 @@ public class EmployeeController {
|
||||
}
|
||||
|
||||
@PostMapping("/get-entry-list")
|
||||
private List<Entry> getEntryList() {
|
||||
private List<EntryDto> getEntryList() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
String login = authentication.getName();
|
||||
return employeeService.getEntryList(login);
|
||||
|
19
src/main/java/com/example/nto/dto/EmployeeDataDto.java
Normal file
19
src/main/java/com/example/nto/dto/EmployeeDataDto.java
Normal file
@ -0,0 +1,19 @@
|
||||
package com.example.nto.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class EmployeeDataDto {
|
||||
private String name;
|
||||
private String photo;
|
||||
private String employeePosition;
|
||||
private LocalDateTime lastVisit;
|
||||
}
|
18
src/main/java/com/example/nto/dto/EntryDto.java
Normal file
18
src/main/java/com/example/nto/dto/EntryDto.java
Normal file
@ -0,0 +1,18 @@
|
||||
package com.example.nto.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class EntryDto {
|
||||
private long codeId;
|
||||
private LocalDateTime entryTime;
|
||||
private boolean isCard;
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.example.nto.dto.mapper;
|
||||
|
||||
import com.example.nto.dto.EmployeeDataDto;
|
||||
import com.example.nto.entity.EmployeeData;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
@UtilityClass
|
||||
public class EmployeeDataMapper {
|
||||
public static EmployeeDataDto toEmployeeDataDto(EmployeeData employeeData) {
|
||||
return EmployeeDataDto.builder()
|
||||
.name(employeeData.getName())
|
||||
.photo(employeeData.getPhoto())
|
||||
.employeePosition(employeeData.getEmployeePosition())
|
||||
.lastVisit(employeeData.getLastVisit())
|
||||
.build();
|
||||
}
|
||||
}
|
16
src/main/java/com/example/nto/dto/mapper/EntryMapper.java
Normal file
16
src/main/java/com/example/nto/dto/mapper/EntryMapper.java
Normal file
@ -0,0 +1,16 @@
|
||||
package com.example.nto.dto.mapper;
|
||||
|
||||
import com.example.nto.dto.EntryDto;
|
||||
import com.example.nto.entity.Entry;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
@UtilityClass
|
||||
public class EntryMapper {
|
||||
public static EntryDto toEntryDto(Entry entry) {
|
||||
return EntryDto.builder()
|
||||
.codeId(entry.getId())
|
||||
.entryTime(entry.getEntryTime())
|
||||
.isCard(entry.isCard())
|
||||
.build();
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ import java.util.Optional;
|
||||
@Repository
|
||||
public interface EmployeeDataRepository extends JpaRepository<EmployeeData, Long> {
|
||||
Optional<EmployeeData> findByOwnerId(long ownerId);
|
||||
@Query(value = "select e.id from employee_data e where owner_id = :owner_id", nativeQuery = true)
|
||||
@Query("select e.id from EmployeeData e where e.ownerId = :owner_id")
|
||||
Optional<Long> findIdByOwnerId(@Param("owner_id") long ownerId);
|
||||
|
||||
@Modifying
|
||||
|
@ -13,12 +13,12 @@ import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface EmployeeRepository extends JpaRepository<Employee, Long> {
|
||||
@Query(value = "select e.id from Employee e where e.login = :login")
|
||||
@Query("select e.id from Employee e where e.login = :login")
|
||||
Optional<Long> findIdByLogin(@Param("login") String login);
|
||||
|
||||
Optional<Employee> findByLogin(String login);
|
||||
|
||||
@Modifying
|
||||
@Query(value = "update Employee e set e.is_block = :value where e.id = :id", nativeQuery = true)
|
||||
@Query("update Employee set isBlock = :value where id = :id")
|
||||
void updateBlockCondition(@Param("id") long id, @Param("value") boolean value);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import java.util.List;
|
||||
|
||||
public interface EntryRepository extends JpaRepository<Entry, Long> {
|
||||
@Modifying
|
||||
@Query(value = "insert into Entry(employee_id, code_id, entry_time, is_card) values (:employeeId, :codeId, :entryTime, false)", nativeQuery = true)
|
||||
@Query(value = "insert into entry(employee_id, code_id, entry_time, is_card) values (:employeeId, :codeId, :entryTime, false)", nativeQuery = true)
|
||||
void insert(@Param("employeeId") long employeeId, @Param("codeId") long codeId, @Param("entryTime") LocalDateTime entryTime);
|
||||
|
||||
List<Entry> findAllByEmployeeId(Long employeeId);
|
||||
|
@ -1,12 +1,14 @@
|
||||
package com.example.nto.service;
|
||||
|
||||
import com.example.nto.dto.EmployeeDataDto;
|
||||
import com.example.nto.dto.EntryDto;
|
||||
import com.example.nto.entity.EmployeeData;
|
||||
import com.example.nto.entity.Entry;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface AdminService {
|
||||
EmployeeData getEmployeeInfo(String employeeLogin, String selfLogin);
|
||||
EmployeeDataDto getEmployeeInfo(String employeeLogin, String selfLogin);
|
||||
void setBlockCondition(String employeeLogin, boolean blockCondition, String selfLogin);
|
||||
List<Entry> getEmployeeEntryList(String employeeLogin, String selfLogin);
|
||||
List<EntryDto> getEmployeeEntryList(String employeeLogin, String selfLogin);
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.example.nto.service;
|
||||
|
||||
import com.example.nto.dto.EmployeeDataDto;
|
||||
import com.example.nto.dto.EntryDto;
|
||||
import com.example.nto.entity.Code;
|
||||
import com.example.nto.entity.Employee;
|
||||
import com.example.nto.entity.EmployeeData;
|
||||
@ -11,11 +13,11 @@ import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
public interface EmployeeService {
|
||||
EmployeeData info(String login);
|
||||
EmployeeDataDto info(String login);
|
||||
|
||||
void open(String login, long value);
|
||||
|
||||
List<Entry> getEntryList(String login);
|
||||
List<EntryDto> getEntryList(String login);
|
||||
|
||||
boolean amIBlocked(String login);
|
||||
}
|
||||
|
@ -1,7 +1,10 @@
|
||||
package com.example.nto.service.impl;
|
||||
|
||||
import com.example.nto.dto.EmployeeDataDto;
|
||||
import com.example.nto.dto.EntryDto;
|
||||
import com.example.nto.dto.mapper.EmployeeDataMapper;
|
||||
import com.example.nto.dto.mapper.EntryMapper;
|
||||
import com.example.nto.entity.EmployeeData;
|
||||
import com.example.nto.entity.Entry;
|
||||
import com.example.nto.exception.EmployeeDataNotFoundException;
|
||||
import com.example.nto.exception.EmployeeNotFoundException;
|
||||
import com.example.nto.exception.SelfChangeException;
|
||||
@ -15,6 +18,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@ -24,7 +28,7 @@ public class AdminServiceImpl implements AdminService {
|
||||
private final EntryRepository entryRepository;
|
||||
|
||||
@Override
|
||||
public EmployeeData getEmployeeInfo(String employeeLogin, String selfLogin) {
|
||||
public EmployeeDataDto getEmployeeInfo(String employeeLogin, String selfLogin) {
|
||||
if (employeeLogin.equals(selfLogin)) {
|
||||
throw new SelfChangeException("Self View");
|
||||
}
|
||||
@ -39,7 +43,7 @@ public class AdminServiceImpl implements AdminService {
|
||||
throw new EmployeeDataNotFoundException("Employee Data Not Found");
|
||||
}
|
||||
|
||||
return employeeData.get();
|
||||
return EmployeeDataMapper.toEmployeeDataDto(employeeData.get());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@ -58,7 +62,7 @@ public class AdminServiceImpl implements AdminService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Entry> getEmployeeEntryList(String employeeLogin, String selfLogin) {
|
||||
public List<EntryDto> getEmployeeEntryList(String employeeLogin, String selfLogin) {
|
||||
if (employeeLogin.equals(selfLogin)) {
|
||||
throw new SelfChangeException("Self View");
|
||||
}
|
||||
@ -68,6 +72,8 @@ public class AdminServiceImpl implements AdminService {
|
||||
throw new EmployeeNotFoundException("Employee Not Found");
|
||||
}
|
||||
|
||||
return entryRepository.findAllByEmployeeId(employee.get());
|
||||
return entryRepository.findAllByEmployeeId(employee.get()).stream()
|
||||
.map(EntryMapper::toEntryDto)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,9 @@
|
||||
package com.example.nto.service.impl;
|
||||
|
||||
import com.example.nto.dto.EmployeeDataDto;
|
||||
import com.example.nto.dto.EntryDto;
|
||||
import com.example.nto.dto.mapper.EmployeeDataMapper;
|
||||
import com.example.nto.dto.mapper.EntryMapper;
|
||||
import com.example.nto.entity.Code;
|
||||
import com.example.nto.entity.Employee;
|
||||
import com.example.nto.entity.EmployeeData;
|
||||
@ -20,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@ -30,7 +35,7 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
private final EntryRepository entryRepository;
|
||||
|
||||
@Override
|
||||
public EmployeeData info(String login) {
|
||||
public EmployeeDataDto info(String login) {
|
||||
Optional<Long> employee = employeeRepository.findIdByLogin(login);
|
||||
if (employee.isEmpty()) {
|
||||
throw new EmployeeNotFoundException("Employee Not Found");
|
||||
@ -41,7 +46,7 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
throw new EmployeeDataNotFoundException("Employee Data Not Found");
|
||||
}
|
||||
|
||||
return employeeData.get();
|
||||
return EmployeeDataMapper.toEmployeeDataDto(employeeData.get());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@ -72,13 +77,15 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Entry> getEntryList(String login) {
|
||||
public List<EntryDto> getEntryList(String login) {
|
||||
Optional<Long> employee = employeeRepository.findIdByLogin(login);
|
||||
if (employee.isEmpty()) {
|
||||
throw new EmployeeNotFoundException("Employee Not Found");
|
||||
}
|
||||
|
||||
return entryRepository.findAllByEmployeeId(employee.get());
|
||||
return entryRepository.findAllByEmployeeId(employee.get()).stream()
|
||||
.map(EntryMapper::toEntryDto)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user