From 81cea34144adcec06c3a6bae9c74f50b045b7b87 Mon Sep 17 00:00:00 2001 From: oU-Ua Date: Wed, 14 Feb 2024 01:08:25 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20=EB=B6=80=EC=84=9C=EB=B3=84=20asset?= =?UTF-8?q?=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/asset/entity/Asset.java | 1 + .../repository/AssetNoticeRepository.java | 1 + .../asset/repository/AssetRepository.java | 2 + .../controller/AssetRequestController.java | 11 +-- .../assetRequest/entity/RequestStatus.java | 2 +- .../repository/AssetRequestRepository.java | 3 + .../domain/contract/dto/ContExpireRes.java | 17 ++++ .../domain/contract/dto/StopContRes.java | 11 +++ .../repository/CorporationRepository.java | 1 + .../controller/DepartmentController.java | 28 +++++- .../domain/department/dto/DeptAssetRes.java | 23 +++++ .../domain/department/dto/DeptInfoRes.java | 15 +++ .../repository/DepartmentAssetRepository.java | 6 ++ .../repository/DepartmentRepository.java | 9 ++ .../department/service/DepartmentService.java | 10 +- .../service/DepartmentServiceImpl.java | 99 +++++++++++++++++++ .../user/controller/UserController.java | 3 +- .../user/repository/UserRepository.java | 2 + 18 files changed, 233 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/kbds/itamserveradmin/domain/contract/dto/ContExpireRes.java create mode 100644 src/main/java/com/kbds/itamserveradmin/domain/contract/dto/StopContRes.java create mode 100644 src/main/java/com/kbds/itamserveradmin/domain/department/dto/DeptAssetRes.java create mode 100644 src/main/java/com/kbds/itamserveradmin/domain/department/dto/DeptInfoRes.java create mode 100644 src/main/java/com/kbds/itamserveradmin/domain/department/service/DepartmentServiceImpl.java diff --git a/src/main/java/com/kbds/itamserveradmin/domain/asset/entity/Asset.java b/src/main/java/com/kbds/itamserveradmin/domain/asset/entity/Asset.java index d7daa3e..408993c 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/asset/entity/Asset.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/asset/entity/Asset.java @@ -37,5 +37,6 @@ public class Asset { private Boolean isAstInstallFile; private String astSpd; private String astDpd; + private String astImgUrl; } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/asset/repository/AssetNoticeRepository.java b/src/main/java/com/kbds/itamserveradmin/domain/asset/repository/AssetNoticeRepository.java index c086076..40fdb0f 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/asset/repository/AssetNoticeRepository.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/asset/repository/AssetNoticeRepository.java @@ -4,4 +4,5 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface AssetNoticeRepository extends JpaRepository { + } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/asset/repository/AssetRepository.java b/src/main/java/com/kbds/itamserveradmin/domain/asset/repository/AssetRepository.java index f2cf2e2..9591387 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/asset/repository/AssetRepository.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/asset/repository/AssetRepository.java @@ -4,4 +4,6 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface AssetRepository extends JpaRepository { + Asset findAssetByAstId(String astId); + } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/controller/AssetRequestController.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/controller/AssetRequestController.java index b7bd476..14b7867 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/controller/AssetRequestController.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/controller/AssetRequestController.java @@ -6,20 +6,19 @@ import com.kbds.itamserveradmin.domain.assetRequest.service.AssetRequestService; import com.kbds.itamserveradmin.global.exception.BaseException; import com.kbds.itamserveradmin.global.exception.ErrorCode; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @RestController +@Slf4j +@RequiredArgsConstructor public class AssetRequestController { -// private final AssetRequestService assetRequestService; -// -// @Autowired -// public AssetRequestController(AssetRequestService assetRequestService) { -// this.assetRequestService = assetRequestService; -// } + private final AssetRequestService assetRequestService; // // // @PostMapping("/test") diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/entity/RequestStatus.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/entity/RequestStatus.java index e5fcbf9..8e7c1ce 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/entity/RequestStatus.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/entity/RequestStatus.java @@ -7,7 +7,7 @@ @AllArgsConstructor @Getter public enum RequestStatus { - APPROVAL_WAIT("승인대기"),APPROVAL("승인"),IN_USE("사용중"),APPROVAL_REJECTED("승인거절"),EXPIRED("폐기"); + APPROVAL_WAIT("승인대기"),APPROVAL("승인"),IN_USE("사용중"),APPROVAL_REJECTED("승인거절"),EXPIRED("폐기"),NOT_IN_USE("미사용중"); @JsonValue private String value; diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestRepository.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestRepository.java index f37d30e..fdb05bb 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestRepository.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestRepository.java @@ -1,10 +1,13 @@ package com.kbds.itamserveradmin.domain.assetRequest.repository; import com.kbds.itamserveradmin.domain.assetRequest.entity.AssetRequest; +import com.kbds.itamserveradmin.domain.contract.entity.Contract; +import com.kbds.itamserveradmin.domain.user.entity.User; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; public interface AssetRequestRepository extends JpaRepository { List findByAstRequestUserUserId(String userId); + AssetRequest findAssetRequestByContractAndAstRequestUser(Contract contract, User user); } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/contract/dto/ContExpireRes.java b/src/main/java/com/kbds/itamserveradmin/domain/contract/dto/ContExpireRes.java new file mode 100644 index 0000000..a28fa41 --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/contract/dto/ContExpireRes.java @@ -0,0 +1,17 @@ +package com.kbds.itamserveradmin.domain.contract.dto; + +import lombok.Builder; +import lombok.Data; + +import java.time.LocalDateTime; + +@Data +@Builder +public class ContExpireRes { + + private String contStartDate; + + private String contEndDate; + + private Long remainingDays; +} diff --git a/src/main/java/com/kbds/itamserveradmin/domain/contract/dto/StopContRes.java b/src/main/java/com/kbds/itamserveradmin/domain/contract/dto/StopContRes.java new file mode 100644 index 0000000..3fb4322 --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/contract/dto/StopContRes.java @@ -0,0 +1,11 @@ +package com.kbds.itamserveradmin.domain.contract.dto; + +import com.kbds.itamserveradmin.domain.contract.entity.OpStatus; +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class StopContRes { + private OpStatus opStatus; +} diff --git a/src/main/java/com/kbds/itamserveradmin/domain/corporation/repository/CorporationRepository.java b/src/main/java/com/kbds/itamserveradmin/domain/corporation/repository/CorporationRepository.java index f3dde0d..a0b6253 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/corporation/repository/CorporationRepository.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/corporation/repository/CorporationRepository.java @@ -4,5 +4,6 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface CorporationRepository extends JpaRepository { + Corporation findCorporationByCorpName(String CorpName); } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/department/controller/DepartmentController.java b/src/main/java/com/kbds/itamserveradmin/domain/department/controller/DepartmentController.java index 6103941..8cc223b 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/department/controller/DepartmentController.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/department/controller/DepartmentController.java @@ -1,8 +1,34 @@ package com.kbds.itamserveradmin.domain.department.controller; +import com.kbds.itamserveradmin.domain.department.dto.DeptAssetRes; +import com.kbds.itamserveradmin.domain.department.dto.DeptInfoRes; +import com.kbds.itamserveradmin.domain.department.service.DepartmentService; +import com.kbds.itamserveradmin.domain.user.dto.UserInfoRes; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.repository.query.Param; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; -@Controller +import java.util.List; + +@RestController +@Slf4j +@RequiredArgsConstructor +@RequestMapping("/kbitam") +@CrossOrigin(origins ="*", allowedHeaders = "*") public class DepartmentController { + private final DepartmentService departmentService; + + @GetMapping("/dept") + public ResponseEntity> getDeptInfo(@RequestParam("corpName") String corpName) { + return ResponseEntity.ok(departmentService.DeptInfo(corpName)); + } + @GetMapping("/dept/asset") + public ResponseEntity> getDeptAsset(@Param("deptId") String deptId, @Param("userId") String userId){ + return ResponseEntity.ok(departmentService.getDeptAsset(deptId,userId)); + } + } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/department/dto/DeptAssetRes.java b/src/main/java/com/kbds/itamserveradmin/domain/department/dto/DeptAssetRes.java new file mode 100644 index 0000000..cf41b0b --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/department/dto/DeptAssetRes.java @@ -0,0 +1,23 @@ +package com.kbds.itamserveradmin.domain.department.dto; + +import com.kbds.itamserveradmin.domain.assetRequest.entity.RequestStatus; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.coyote.Request; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class DeptAssetRes { + private String AssetName; + private String ContNumOfType; + private String ContPeriodType; + private String ContSupplyType; + private String AssetSpd; + private RequestStatus AssetReqStatus; + private String AssetImgUrl; + private String ContId; +} diff --git a/src/main/java/com/kbds/itamserveradmin/domain/department/dto/DeptInfoRes.java b/src/main/java/com/kbds/itamserveradmin/domain/department/dto/DeptInfoRes.java new file mode 100644 index 0000000..b8c9ecc --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/department/dto/DeptInfoRes.java @@ -0,0 +1,15 @@ +package com.kbds.itamserveradmin.domain.department.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class DeptInfoRes { + private String DeptId; + private String DeptName; +} diff --git a/src/main/java/com/kbds/itamserveradmin/domain/department/repository/DepartmentAssetRepository.java b/src/main/java/com/kbds/itamserveradmin/domain/department/repository/DepartmentAssetRepository.java index feb1f6b..a131631 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/department/repository/DepartmentAssetRepository.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/department/repository/DepartmentAssetRepository.java @@ -1,10 +1,16 @@ package com.kbds.itamserveradmin.domain.department.repository; +import com.kbds.itamserveradmin.domain.contract.entity.Contract; +import com.kbds.itamserveradmin.domain.department.entity.Department; import com.kbds.itamserveradmin.domain.department.entity.DepartmentAsset; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import java.util.List; public interface DepartmentAssetRepository extends JpaRepository { // List findBy (Iterable strings); + @Query("select da.contract from DepartmentAsset da where da.department =:department") + List findContractByDept(@Param("department") Department department); } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/department/repository/DepartmentRepository.java b/src/main/java/com/kbds/itamserveradmin/domain/department/repository/DepartmentRepository.java index bfada86..9966803 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/department/repository/DepartmentRepository.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/department/repository/DepartmentRepository.java @@ -1,9 +1,18 @@ package com.kbds.itamserveradmin.domain.department.repository; +import com.kbds.itamserveradmin.domain.corporation.entity.Corporation; +import com.kbds.itamserveradmin.domain.department.dto.DeptInfoRes; import com.kbds.itamserveradmin.domain.department.entity.Department; import com.kbds.itamserveradmin.domain.department.entity.DepartmentAsset; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.List; public interface DepartmentRepository extends JpaRepository { + @Query("select NEW com.kbds.itamserveradmin.domain.department.dto.DeptInfoRes(d.deptId, d.deptName) from Department d where d.corporation =:corporation") + List findNameByCorp(@Param("corporation") Corporation corporation); + Department findDepartmentByDeptId(String deptId); } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/department/service/DepartmentService.java b/src/main/java/com/kbds/itamserveradmin/domain/department/service/DepartmentService.java index 430c57e..308ba35 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/department/service/DepartmentService.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/department/service/DepartmentService.java @@ -1,8 +1,14 @@ package com.kbds.itamserveradmin.domain.department.service; +import com.kbds.itamserveradmin.domain.department.dto.DeptAssetRes; +import com.kbds.itamserveradmin.domain.department.dto.DeptInfoRes; import org.springframework.stereotype.Service; -@Service -public class DepartmentService { +import java.util.List; + + +public interface DepartmentService { + public List DeptInfo(String corpName); + public List getDeptAsset(String deptId,String userId); } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/department/service/DepartmentServiceImpl.java b/src/main/java/com/kbds/itamserveradmin/domain/department/service/DepartmentServiceImpl.java new file mode 100644 index 0000000..1c07c62 --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/department/service/DepartmentServiceImpl.java @@ -0,0 +1,99 @@ +package com.kbds.itamserveradmin.domain.department.service; + +import com.kbds.itamserveradmin.domain.asset.entity.Asset; +import com.kbds.itamserveradmin.domain.asset.repository.AssetRepository; +import com.kbds.itamserveradmin.domain.assetRequest.entity.AssetRequest; +import com.kbds.itamserveradmin.domain.assetRequest.entity.RequestStatus; +import com.kbds.itamserveradmin.domain.assetRequest.repository.AssetRequestRepository; +import com.kbds.itamserveradmin.domain.contract.entity.Contract; +import com.kbds.itamserveradmin.domain.contract.repository.ContractRepository; +import com.kbds.itamserveradmin.domain.corporation.entity.Corporation; +import com.kbds.itamserveradmin.domain.corporation.repository.CorporationRepository; +import com.kbds.itamserveradmin.domain.department.dto.DeptAssetRes; +import com.kbds.itamserveradmin.domain.department.dto.DeptInfoRes; +import com.kbds.itamserveradmin.domain.department.entity.Department; +import com.kbds.itamserveradmin.domain.department.repository.DepartmentAssetRepository; +import com.kbds.itamserveradmin.domain.department.repository.DepartmentRepository; +import com.kbds.itamserveradmin.domain.user.entity.User; +import com.kbds.itamserveradmin.domain.user.repository.UserRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +@Service +@Slf4j +@RequiredArgsConstructor +public class DepartmentServiceImpl implements DepartmentService{ + + private final DepartmentRepository departmentRepository; + private final CorporationRepository corporationRepository; + private final UserRepository userRepository; + private final DepartmentAssetRepository departmentAssetRepository; + private final AssetRepository assetRepository; + private final AssetRequestRepository assetRequestRepository; + + @Override + public List DeptInfo(String corpName) { + Corporation corporation = corporationRepository.findCorporationByCorpName(corpName); + List departList = departmentRepository.findNameByCorp(corporation); + return departList; + } + + @Override + public List getDeptAsset(String deptId, String userId) { + Department department = departmentRepository.findDepartmentByDeptId(deptId); + List ContractList = departmentAssetRepository.findContractByDept(department); + User user = userRepository.findUserByUserId(userId); + + Map supplyTypes = Map.of( + '1', "패키지", + '2', "Low Volume", + '3', "High Volume", + '4', "SaaS" + ); + + Map periodTypes = Map.of( + '1', "구독", + '2', "영구" + ); + + Map userTypes = Map.of( + '1', "동시 사용자수", + '2', "사이트", + '3', "코어", + '4', "1pc1copy", + '5', "서버접속" + ); + + + List deptAssetResList = new ArrayList<>(); + for(Contract cont : ContractList){ + Asset asset = assetRepository.findAssetByAstId(cont.getAst().getAstId()); + AssetRequest assetRequest = assetRequestRepository.findAssetRequestByContractAndAstRequestUser(cont,user); + + String contLicTag= cont.getContLicTag(); + char supplyChar = contLicTag.charAt(0); + char periodChar = contLicTag.charAt(1); + char userChar = contLicTag.charAt(2); + + if (assetRequest==null){ + DeptAssetRes deptAssetRes = DeptAssetRes.builder(). + AssetName(asset.getAstName()).AssetReqStatus(RequestStatus.NOT_IN_USE).AssetSpd(asset.getAstSpd()).AssetImgUrl(asset.getAstImgUrl()).ContId(cont.getContId()). + ContNumOfType(supplyTypes.get(supplyChar)).ContPeriodType(periodTypes.get(periodChar)).ContSupplyType(userTypes.get(userChar)).build(); + deptAssetResList.add(deptAssetRes); + } + else { + DeptAssetRes deptAssetRes = DeptAssetRes.builder(). + AssetName(asset.getAstName()).AssetReqStatus(assetRequest.getAstReqStatus()).AssetSpd(asset.getAstSpd()).AssetImgUrl(asset.getAstImgUrl()).ContId(cont.getContId()). + ContNumOfType(supplyTypes.get(supplyChar)).ContPeriodType(periodTypes.get(periodChar)).ContSupplyType(userTypes.get(userChar)).build(); + deptAssetResList.add(deptAssetRes); + } + + } + return deptAssetResList; + } +} diff --git a/src/main/java/com/kbds/itamserveradmin/domain/user/controller/UserController.java b/src/main/java/com/kbds/itamserveradmin/domain/user/controller/UserController.java index 5197189..1fa1100 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/user/controller/UserController.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/user/controller/UserController.java @@ -11,12 +11,13 @@ @Slf4j @RequiredArgsConstructor @RequestMapping("/kbitam") +@CrossOrigin(origins ="*", allowedHeaders = "*") public class UserController { private final UserService userService; @GetMapping("/userInfo") - public ResponseEntity getUserInfo(@RequestParam String userId) { + public ResponseEntity getUserInfo(@RequestParam("userId") String userId) { return ResponseEntity.ok(userService.GetUserInfo(userId)); } } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/user/repository/UserRepository.java b/src/main/java/com/kbds/itamserveradmin/domain/user/repository/UserRepository.java index 68b25a5..63154b3 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/user/repository/UserRepository.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/user/repository/UserRepository.java @@ -18,4 +18,6 @@ public interface UserRepository extends JpaRepository { "FROM User u JOIN u.department d JOIN u.corporation c " + "WHERE u.userId = :userId") UserInfoRes findUserInfoWithCooperationAndDepartmentByUserId(@Param("userId") String userId); + + User findUserByUserId(String userId); }