mirror of
https://git.hmsn.ink/kospo/svcm/api.git
synced 2026-03-20 05:53:27 +09:00
sap 직원검색 기능 추가
계약관리 pageable 설정
This commit is contained in:
@@ -62,4 +62,23 @@ public class UserController {
|
||||
return ResponseEntity.ok(userService.findByNameContaining(name));
|
||||
}
|
||||
|
||||
@Operation(summary = "(sap 결재용) 직원검색", description = "이름 또는 사번으로 직원검색")
|
||||
@ApiResponses({
|
||||
@ApiResponse(description = "Success", responseCode = "200",
|
||||
content = @io.swagger.v3.oas.annotations.media.Content(mediaType = "application/json", schema = @Schema(oneOf =
|
||||
{User.class}))),
|
||||
@ApiResponse(description = "Not found", responseCode = "404",
|
||||
content = @io.swagger.v3.oas.annotations.media.Content(mediaType = "text/plain", schema = @Schema(oneOf =
|
||||
{String.class}))),
|
||||
@ApiResponse(description = "Internal Error", responseCode = "500",
|
||||
content = @io.swagger.v3.oas.annotations.media.Content(mediaType = "application/json", schema = @Schema(oneOf =
|
||||
{CustomErrorResponse.class })))
|
||||
})
|
||||
@GetMapping("/sap/user")
|
||||
public ResponseEntity findSapByName(
|
||||
@Parameter(description = "이름") @RequestParam String name,
|
||||
Principal principal) {
|
||||
return ResponseEntity.ok(userService.findSapUserByNameContaining(name));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class UserSelectListResponse {
|
||||
.sabun(user.getSabun())
|
||||
.name(user.getName())
|
||||
.deptCd(user.getDeptCd())
|
||||
.deptNm(user.getDept().getDeptNm())
|
||||
.deptNm("")
|
||||
.ptsnNm(user.getPtsnNm())
|
||||
.gradeCd(user.getGradeCd())
|
||||
.gradeNm(user.getGradeNm())
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.kospo.svcm.model;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.*;
|
||||
import org.hibernate.type.YesNoConverter;
|
||||
@@ -24,6 +25,12 @@ public class Code {
|
||||
@Column(name = "\"desc\"", length = 200)
|
||||
private String desc;
|
||||
|
||||
@Column(name = "ri_id", nullable = false)
|
||||
private int riId;
|
||||
|
||||
@Size(max = 10)
|
||||
@Column(name = "ri_cd", nullable = false, length = 10)
|
||||
private String riCd;
|
||||
|
||||
@Column(name = "use_yn", columnDefinition = "CHAR(1)")
|
||||
@Convert(converter = YesNoConverter.class)
|
||||
|
||||
@@ -18,6 +18,22 @@ import java.util.List;
|
||||
@Entity
|
||||
@Table(name = "users")
|
||||
public class User implements UserDetails {
|
||||
public User(String sabun, String name, String deptCd, String gradeCd, String gradeNm, String ptsnNm, String ofcePhn, String mblPhn, String state, String attendCd, String attendNm, String attendStaYmd, String attendEndYmd) {
|
||||
this.sabun = sabun;
|
||||
this.name = name;
|
||||
this.deptCd = deptCd;
|
||||
this.gradeCd = gradeCd;
|
||||
this.gradeNm = gradeNm;
|
||||
this.ptsnNm = ptsnNm;
|
||||
this.ofcePhn = ofcePhn;
|
||||
this.mblPhn = mblPhn;
|
||||
this.state = state;
|
||||
this.attendCd = attendCd;
|
||||
this.attendNm = attendNm;
|
||||
this.attendStaYmd = attendStaYmd;
|
||||
this.attendEndYmd = attendEndYmd;
|
||||
}
|
||||
|
||||
@Id
|
||||
@Size(max = 10)
|
||||
@Column(name = "sabun", nullable = false, length = 10)
|
||||
|
||||
@@ -2,10 +2,50 @@ package com.kospo.svcm.repository;
|
||||
|
||||
import com.kospo.svcm.model.User;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserRepository extends JpaRepository<User, String> {
|
||||
User findBySabun(String sabun);
|
||||
List<User> findByNameContaining(String name);
|
||||
|
||||
@Query(value = "select \n" +
|
||||
"new User(u.sabun," +
|
||||
"u.name," +
|
||||
"u.deptCd," +
|
||||
"u.ptsnNm," +
|
||||
"u.gradeCd," +
|
||||
"u.gradeNm," +
|
||||
"u.ofcePhn," +
|
||||
"u.mblPhn," +
|
||||
"u.state," +
|
||||
"u.attendCd," +
|
||||
"u.attendNm," +
|
||||
"u.attendStaYmd," +
|
||||
"u.attendEndYmd) " +
|
||||
"from User u \n" +
|
||||
"where u.state = 'C' \n" +
|
||||
"and ((:name is null or :name = '' or u.name like concat('%', :name, '%'))" +
|
||||
"or (:name is null or :name = '' or u.sabun like concat('%', :name, '%')))")
|
||||
List<User> findByNameContainingOrSabunContaining(String name);
|
||||
|
||||
@Query(value = "select \n" +
|
||||
"new User(u.sabun," +
|
||||
"u.name," +
|
||||
"u.deptCd," +
|
||||
"u.ptsnNm," +
|
||||
"u.gradeCd," +
|
||||
"u.gradeNm," +
|
||||
"u.ofcePhn," +
|
||||
"u.mblPhn," +
|
||||
"u.state," +
|
||||
"(select c.id.cd from Code c where c.id.id = 10 and c.riCd = u.attendCd) as attendCd," +
|
||||
"u.attendNm," +
|
||||
"u.attendStaYmd," +
|
||||
"u.attendEndYmd) " +
|
||||
"from User u \n" +
|
||||
"where u.state = 'C' \n" +
|
||||
"and ((:name is null or :name = '' or u.name like concat('%', :name, '%'))" +
|
||||
"or (:name is null or :name = '' or u.sabun like concat('%', :name, '%')))")
|
||||
List<User> findSapByNameContainingOrSabunContaining(String name);
|
||||
}
|
||||
@@ -5,13 +5,14 @@ import com.kospo.svcm.dto.req.ContUpdateRequest;
|
||||
import com.kospo.svcm.dto.res.ContDetailResponse;
|
||||
import com.kospo.svcm.dto.res.ContListResponse;
|
||||
import com.kospo.svcm.dto.res.ContSaveResponse;
|
||||
import com.kospo.svcm.dto.res.PageResponse;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ContService {
|
||||
List<ContListResponse> findPage(String sabun, String contStatCd, String signSdt, String signEdt, Pageable pageable);
|
||||
PageResponse findPage(String sabun, String contStatCd, String signSdt, String signEdt, Pageable pageable);
|
||||
|
||||
@Transactional
|
||||
ContDetailResponse findDetail(String contNo);
|
||||
|
||||
@@ -13,4 +13,6 @@ public interface UserService {
|
||||
UserDetails loadUserByUsername(String sabun) throws UsernameNotFoundException;
|
||||
|
||||
List<UserSelectListResponse> findByNameContaining(String name);
|
||||
|
||||
List<UserSelectListResponse> findSapUserByNameContaining(String name);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.kospo.svcm.dto.req.ContUpdateRequest;
|
||||
import com.kospo.svcm.dto.res.ContDetailResponse;
|
||||
import com.kospo.svcm.dto.res.ContListResponse;
|
||||
import com.kospo.svcm.dto.res.ContSaveResponse;
|
||||
import com.kospo.svcm.dto.res.PageResponse;
|
||||
import com.kospo.svcm.exception.CustomException;
|
||||
import com.kospo.svcm.exception.CustomMessageException;
|
||||
import com.kospo.svcm.model.*;
|
||||
@@ -17,6 +18,7 @@ import com.kospo.svcm.service.ContService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.poi.util.StringUtil;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -47,8 +49,14 @@ public class ContServiceImpl implements ContService {
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public List<ContListResponse> findPage(String sabun, String contStatCd, String signSdt, String signEdt, Pageable pageable) {
|
||||
return contRepository.findBySearch(sabun, contStatCd, signSdt, signEdt, pageable).stream().map(ContListResponse::iFrom).toList();
|
||||
public PageResponse findPage(String sabun, String contStatCd, String signSdt, String signEdt, Pageable pageable) {
|
||||
Page<ContRepository.IContResponse> page = contRepository.findBySearch(sabun, contStatCd, signSdt, signEdt, pageable);
|
||||
return PageResponse.builder()
|
||||
.pageable(page.getPageable())
|
||||
.content(page.getContent().stream().map(ContListResponse::iFrom).toList())
|
||||
.totalElements(page.getTotalElements())
|
||||
.totalPages(page.getTotalPages())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.kospo.svcm.service.impl;
|
||||
|
||||
import com.kospo.svcm.dto.res.UserSelectListResponse;
|
||||
import com.kospo.svcm.model.Dept;
|
||||
import com.kospo.svcm.model.User;
|
||||
import com.kospo.svcm.repository.DeptRepository;
|
||||
import com.kospo.svcm.repository.UserRepository;
|
||||
import com.kospo.svcm.service.UserService;
|
||||
import jakarta.transaction.Transactional;
|
||||
@@ -17,6 +19,7 @@ import java.util.List;
|
||||
@RequiredArgsConstructor
|
||||
public class UserServiceImpl implements UserService {
|
||||
private final UserRepository userRepository;
|
||||
private final DeptRepository deptRepository;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@@ -34,10 +37,34 @@ public class UserServiceImpl implements UserService {
|
||||
if(name.equals("") || name == null) {
|
||||
return new ArrayList<UserSelectListResponse>();
|
||||
} else {
|
||||
return userRepository.findByNameContaining(name).stream().map(u -> UserSelectListResponse.builder()
|
||||
.label(u.getDept().getDeptNm() + " - " + u.getName() + " (" + u.getSabun() + ")")
|
||||
.value(UserSelectListResponse.UserSelect.from(u))
|
||||
.build()).toList();
|
||||
List<Dept> deptList = deptRepository.findAll();
|
||||
return userRepository.findByNameContainingOrSabunContaining(name).stream().map(u -> {
|
||||
Dept dept = deptList.stream().filter(d -> d.getDeptCd().equals(u.getDeptCd())).findFirst().orElse(null);
|
||||
UserSelectListResponse.UserSelect userSelect = UserSelectListResponse.UserSelect.from(u);
|
||||
userSelect.setDeptNm(dept.getDeptNm());
|
||||
return UserSelectListResponse.builder()
|
||||
.label(dept.getDeptNm() + " - " + u.getName() + " (" + u.getSabun() + ")")
|
||||
.value(userSelect)
|
||||
.build();
|
||||
}).toList();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserSelectListResponse> findSapUserByNameContaining(String name) {
|
||||
if(name.equals("") || name == null) {
|
||||
return new ArrayList<UserSelectListResponse>();
|
||||
} else {
|
||||
List<Dept> deptList = deptRepository.findAll();
|
||||
return userRepository.findSapByNameContainingOrSabunContaining(name).stream().map(u -> {
|
||||
Dept dept = deptList.stream().filter(d -> d.getDeptCd().equals(u.getDeptCd())).findFirst().orElse(null);
|
||||
UserSelectListResponse.UserSelect userSelect = UserSelectListResponse.UserSelect.from(u);
|
||||
userSelect.setDeptNm(dept.getDeptNm());
|
||||
return UserSelectListResponse.builder()
|
||||
.label(dept.getDeptNm() + " - " + u.getName() + " (" + u.getSabun() + ")")
|
||||
.value(userSelect)
|
||||
.build();
|
||||
}).toList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user