Skip to content

Commit

Permalink
Merge pull request #66 from KBDS-Dreamverse/feat/#31
Browse files Browse the repository at this point in the history
feat : 부서별 asset 리스트 구현
  • Loading branch information
oU-Ua authored Feb 14, 2024
2 parents d9781b4 + bb727fb commit 8fd79e3
Show file tree
Hide file tree
Showing 16 changed files with 208 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class Asset {
private Boolean isAstInstallFile;
private String astSpd;
private String astDpd;
private String astImgUrl;



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
import org.springframework.data.jpa.repository.JpaRepository;

public interface AssetNoticeRepository extends JpaRepository<AssetNotice, String> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
@Repository
public interface AssetRepository extends JpaRepository<Asset, String> {

Asset findAssetByAstId(String astId);





// @Query("SELECT a " +
Expand All @@ -28,4 +32,5 @@ public interface AssetRepository extends JpaRepository<Asset, String> {
"WHERE a.corp.corpId = :corp_id " + // WHERE 절에 공백을 추가하고 corp_id의 앞에 콜론(:)을 빼먹지 않아야 함
"ORDER BY a.astId DESC") // ORDER BY 구문을 추가하고 astId 앞에 a.를 빼먹지 않아야 함
String findCorpCntById(@Param("corp_id") String corp_id);

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -22,6 +23,8 @@
import java.util.List;

@RestController
@Slf4j
@RequiredArgsConstructor
public class AssetRequestController {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
@AllArgsConstructor
@Getter
public enum RequestStatus {

APPROVAL_WAIT("승인대기"),
APPROVAL("승인"),
IN_USE("사용중"),
APPROVAL_REJECTED("승인거절"),
EXPIRED("폐기"),
CANCEL("요청취소");
CANCEL("요청취소"),
NOT_IN_USE("미사용중");

@JsonValue
private String value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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 org.springframework.stereotype.Repository;

Expand All @@ -9,5 +11,6 @@
@Repository
public interface AssetRequestRepository extends JpaRepository<AssetRequest, String>,AssetRequestRepositoryCustom {
List<AssetRequest> findByAstRequestUserUserId(String userId);
AssetRequest findAssetRequestByContractAndAstRequestUser(Contract contract, User user);

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@

@Repository
public interface CorporationRepository extends JpaRepository<Corporation,String> {
Corporation findCorporationByCorpName(String CorpName);

}
Original file line number Diff line number Diff line change
@@ -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<List<DeptInfoRes>> getDeptInfo(@RequestParam("corpName") String corpName) {
return ResponseEntity.ok(departmentService.DeptInfo(corpName));
}
@GetMapping("/dept/asset")
public ResponseEntity<List<DeptAssetRes>> getDeptAsset(@Param("deptId") String deptId, @Param("userId") String userId){
return ResponseEntity.ok(departmentService.getDeptAsset(deptId,userId));
}


}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<DepartmentAsset,String> {
// List<DepartmentAsset> findBy (Iterable<String> strings);
@Query("select da.contract from DepartmentAsset da where da.department =:department")
List<Contract> findContractByDept(@Param("department") Department department);
}
Original file line number Diff line number Diff line change
@@ -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<Department,String> {
@Query("select NEW com.kbds.itamserveradmin.domain.department.dto.DeptInfoRes(d.deptId, d.deptName) from Department d where d.corporation =:corporation")
List<DeptInfoRes> findNameByCorp(@Param("corporation") Corporation corporation);

Department findDepartmentByDeptId(String deptId);
}
Original file line number Diff line number Diff line change
@@ -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<DeptInfoRes> DeptInfo(String corpName);
public List<DeptAssetRes> getDeptAsset(String deptId,String userId);

}
Original file line number Diff line number Diff line change
@@ -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<DeptInfoRes> DeptInfo(String corpName) {
Corporation corporation = corporationRepository.findCorporationByCorpName(corpName);
List<DeptInfoRes> departList = departmentRepository.findNameByCorp(corporation);
return departList;
}

@Override
public List<DeptAssetRes> getDeptAsset(String deptId, String userId) {
Department department = departmentRepository.findDepartmentByDeptId(deptId);
List<Contract> ContractList = departmentAssetRepository.findContractByDept(department);
User user = userRepository.findUserByUserId(userId);

Map<Character, String> supplyTypes = Map.of(
'1', "패키지",
'2', "Low Volume",
'3', "High Volume",
'4', "SaaS"
);

Map<Character, String> periodTypes = Map.of(
'1', "구독",
'2', "영구"
);

Map<Character, String> userTypes = Map.of(
'1', "동시 사용자수",
'2', "사이트",
'3', "코어",
'4', "1pc1copy",
'5', "서버접속"
);


List<DeptAssetRes> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
@RequiredArgsConstructor
@CrossOrigin(origins ="*", allowedHeaders = "*")
@RequestMapping("/kbitam")
@CrossOrigin(origins ="*", allowedHeaders = "*")
public class UserController {

private final UserService userService;

@GetMapping("/userInfo")
public ResponseEntity<UserInfoRes> getUserInfo(@RequestParam String userId) {
public ResponseEntity<UserInfoRes> getUserInfo(@RequestParam("userId") String userId) {
return ResponseEntity.ok(userService.GetUserInfo(userId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ public interface UserRepository extends JpaRepository<User,String> {
"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);
}

0 comments on commit 8fd79e3

Please sign in to comment.