Skip to content

Commit

Permalink
Merge pull request #53 from KBDS-Dreamverse/feat/#31
Browse files Browse the repository at this point in the history
Feat/#31
  • Loading branch information
oU-Ua authored Feb 11, 2024
2 parents 84846fa + 6e6fb6a commit 89cb3cb
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public static AssetRes assetInfo (Asset asset){
return AssetRes.builder()
.astId(asset.getAstId())
.astName(asset.getAstName())
.astTag(asset.getAstTag()) //자산태그
.astDpd(asset.getAstDpd()) //상세설명
.astSpd(asset.getAstSpd()) //간략설명
.astTag(asset.getAstTag())
.astDpd(asset.getAstDpd())
.astSpd(asset.getAstSpd())
.astVer(asset.getAstVer())
.astPrice(asset.getAstPrice())
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.kbds.itamserveradmin.domain.contract.controller;

import com.kbds.itamserveradmin.domain.contract.dto.CalKeyRes;
import com.kbds.itamserveradmin.domain.contract.dto.ContExpireRes;
import com.kbds.itamserveradmin.domain.contract.dto.DashBoardRes;
import com.kbds.itamserveradmin.domain.contract.dto.PasswordReq;
import com.kbds.itamserveradmin.domain.contract.service.ContractService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import static com.kbds.itamserveradmin.global.exception.ErrorCode.CONTRACT_IS_NOT_CAL_LIC;
import static com.kbds.itamserveradmin.global.exception.ErrorCode.PASSWORD_INCORRECT;
import static org.springframework.http.ResponseEntity.ok;

Expand All @@ -26,63 +25,23 @@ public ResponseEntity<DashBoardRes> getDashboard(
@PathVariable String dept,
@PathVariable String contId,
@RequestHeader String userId) {
try {
DashBoardRes dashBoardRes = contractService.createDashBoard(contId, userId);
return ok(dashBoardRes);
} catch (IllegalArgumentException e) {
// CONTRACT_NOT_FOUND 예외 처리
return ResponseEntity.notFound().build();
}
DashBoardRes dashBoardRes = contractService.createDashBoard(contId, userId);
return ok(dashBoardRes);
}


@PostMapping("/kbitam/{dept}/{contId}/cal")
public ResponseEntity<?> findCalKey(
@PathVariable(name = "contId") String contId,
@RequestBody PasswordReq pwReq,
@RequestHeader String userId) {

final String correctPw = "1234";

if (!correctPw.equals(pwReq.getPw())) {
if (correctPw.equals(pwReq.getPw())) {
CalKeyRes calKey = contractService.getCalKey(userId, contId);
return ResponseEntity.ok(calKey);
} else {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(PASSWORD_INCORRECT);
}

CalKeyRes calKey = contractService.getCalKey(userId, contId);
if (calKey == null) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(CONTRACT_IS_NOT_CAL_LIC);
}
return ResponseEntity.ok(calKey);
}

@GetMapping("/kbitam/{dept}/{contId}/expire")
public ResponseEntity<ContExpireRes> expire(
@PathVariable String dept,
@PathVariable String contId) {

return ResponseEntity.ok(contractService.getExpire(contId));
}

// @PatchMapping("/kbitam/{dept}/{contId}/renewal")
// public ResponseEntity<?> renewal(
// @PathVariable String dept,
// @PathVariable String contId) {
//
// }
@PatchMapping("/kbitam/{dept}/{contId}/stop")
public ResponseEntity<?> stop(
@PathVariable String dept,
@PathVariable String contId) {
try {
contractService.stopContract(contId);
return ResponseEntity.ok("Successfully stop the contract!");
} catch (IllegalArgumentException e) {
return ResponseEntity.notFound().build();
} catch (IllegalStateException e) {
// CONTRACT_IS_ALREADY_IN_DISPOSAL 예외 처리
return ResponseEntity.status(HttpStatus.CONFLICT).body(e.getMessage());
}
}


}

This file was deleted.

This file was deleted.

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

public interface ContractRepository extends JpaRepository<Contract, String> {
// Contract findByContId (String contId);
Contract findByContId (String contId);
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
package com.kbds.itamserveradmin.domain.contract.service;

import com.kbds.itamserveradmin.domain.asset.entity.Asset;
import com.kbds.itamserveradmin.domain.assetRequest.entity.AssetRequest;
import com.kbds.itamserveradmin.domain.assetRequest.entity.UserAssetRequestInfo;
import com.kbds.itamserveradmin.domain.assetRequest.repository.AssetRequestRepository;
import com.kbds.itamserveradmin.domain.assetRequest.repository.UserAssetRequestInfoRepository;
import com.kbds.itamserveradmin.domain.assetRequest.service.AssetRequestService;
import com.kbds.itamserveradmin.domain.contract.dto.CalKeyRes;
import com.kbds.itamserveradmin.domain.contract.dto.ContExpireRes;
import com.kbds.itamserveradmin.domain.contract.dto.DashBoardRes;
import com.kbds.itamserveradmin.domain.contract.entity.*;
import com.kbds.itamserveradmin.domain.contract.repository.ContractRepository;
import com.kbds.itamserveradmin.domain.contract.repository.NumOfUsersTypeRepository;
import com.kbds.itamserveradmin.domain.contract.repository.PeriodTypeRepository;
import com.kbds.itamserveradmin.domain.contract.repository.SupplyTypeRepository;
import com.kbds.itamserveradmin.domain.purchaseRequest.entity.NewAssetRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;

import static com.kbds.itamserveradmin.domain.contract.entity.OpStatus.IN_DISPOSAL;
import static com.kbds.itamserveradmin.domain.contract.entity.OpStatus.IN_OPERATION;
import static com.kbds.itamserveradmin.global.exception.ErrorCode.CONTRACT_IS_ALREADY_IN_DISPOSAL;
import static com.kbds.itamserveradmin.global.exception.ErrorCode.CONTRACT_NOT_FOUND;

@Slf4j
Expand All @@ -38,6 +35,7 @@ public class ContractService {
private final SupplyTypeRepository supplyTypeRepository;
private final PeriodTypeRepository periodTypeRepository;
private final NumOfUsersTypeRepository numOfUsersTypeRepository;
private final AssetRequestRepository assetRequestRepository;
private final UserAssetRequestInfoRepository userAssetRequestInfoRepository;

private final AssetRequestService assetRequestService;
Expand Down Expand Up @@ -82,8 +80,7 @@ public static List<String> parseContLicTag(String contLicTag) {
}
//Ast id 찾는 메서드
public Asset getAstIdByContId(String contId){
Contract contract = contractRepository.findById(contId)
.orElseThrow(() -> new IllegalArgumentException(String.valueOf(CONTRACT_NOT_FOUND)));
Contract contract = contractRepository.findByContId(contId);
if (contract == null){
return null;
}
Expand Down Expand Up @@ -122,10 +119,12 @@ public DashBoardRes createDashBoard(String contId, String userId) {

// 3.2 기간 (1. yml에서 write-dates-as-timestamps: false 로 설정해도 날짜 리스트로 출력)
// (2. PeriodType에서 @JsonFormat으로 설정해도 수정 안된다)
List<LocalDateTime> dateTimeList = getPeriod(contId);
List<String> formattedDate = getFormattedDate(dateTimeList);
licValues.put("contStartDate", formattedDate.get(0));
licValues.put("contEndDate", formattedDate.get(1));
PeriodType periodType = periodTypeRepository.findByCont_ContId(contId);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedStartDate = periodType.getContStartDate().format(formatter);
String formattedEndDate = periodType.getContEndDate().format(formatter);
licValues.put("contStartDate", formattedStartDate);
licValues.put("contEndDate", formattedEndDate);


// 3.3 사용자
Expand Down Expand Up @@ -175,13 +174,6 @@ public DashBoardRes createDashBoard(String contId, String userId) {
}

public CalKeyRes getCalKey(String userId, String contId) {
Contract findContract = contractRepository.findById(contId)
.orElseThrow(() -> new IllegalArgumentException(String.valueOf(CONTRACT_NOT_FOUND)));

// 해당 계약의 라이선스 조합이 서버접속이 아닌 경우 -> Exception 던지기
if (findContract.getContLicTag().charAt(2) != '5') {
return null;
}
String astReqId = assetRequestService.getAstReqIdByUserIdAndContId(userId, contId);
UserAssetRequestInfo userAstReqInfo = userAssetRequestInfoRepository.findByAssetRequest_AstReqId(astReqId);

Expand All @@ -198,47 +190,4 @@ public CalKeyRes getCalKey(String userId, String contId) {
.build();
}

public List<LocalDateTime> getPeriod(String contId) {
List<LocalDateTime> period = new ArrayList<>(2);
PeriodType periodType = periodTypeRepository.findByCont_ContId(contId);
period.add(periodType.getContStartDate());
period.add(periodType.getContEndDate());
return period;
}

public List<String> getFormattedDate(List<LocalDateTime> dateTimeList) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedStartDate = dateTimeList.get(0).format(formatter);
String formattedEndDate = dateTimeList.get(1).format(formatter);

List<String> formatted = new ArrayList<>();
formatted.add(formattedStartDate);
formatted.add(formattedEndDate);
return formatted;
}

public ContExpireRes getExpire(String contId) {
List<LocalDateTime> period = getPeriod(contId);
List<String> formattedDate = getFormattedDate(period);

Long between = ChronoUnit.DAYS.between(LocalDateTime.now(), period.get(1));

return ContExpireRes.builder()
.contStartDate(formattedDate.get(0))
.contEndDate(formattedDate.get(1))
.remainingDays(between)
.build();
}

public void stopContract(String contId) {
Contract contract = contractRepository.findById(contId)
.orElseThrow(() -> new IllegalArgumentException(String.valueOf(CONTRACT_NOT_FOUND)));

if (contract.getContOpStatus() == IN_OPERATION) {
contract.setContOpStatus(IN_DISPOSAL);
} else {
throw new IllegalStateException(String.valueOf(CONTRACT_IS_ALREADY_IN_DISPOSAL));
}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.kbds.itamserveradmin.domain.user.controller;

import com.kbds.itamserveradmin.domain.user.dto.MainRes;
import com.kbds.itamserveradmin.domain.user.dto.UserInfoRes;
import com.kbds.itamserveradmin.domain.user.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -12,11 +12,11 @@
@RequiredArgsConstructor
@RequestMapping("/kbitam")
public class UserController {
private final UserService userService;

@PostMapping("/")
public ResponseEntity<MainRes>GetUserInfo(@RequestBody String userId){
private final UserService userService;

return ResponseEntity.ok(null);
@GetMapping("/userInfo")
public ResponseEntity<UserInfoRes> getUserInfo(@RequestParam String userId) {
return ResponseEntity.ok(userService.GetUserInfo(userId));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.kbds.itamserveradmin.domain.user.dto;


import com.kbds.itamserveradmin.domain.user.entity.UserRole;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class UserInfoRes {
private String userId;
private String userName;
private String userPhoto;
private UserRole userRole;
private String DeptName;
private String CorpName;

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.kbds.itamserveradmin.domain.user.entity;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.kbds.itamserveradmin.domain.asset.entity.AssetNotice;
import com.kbds.itamserveradmin.domain.assetRequest.entity.AssetRequest;
import com.kbds.itamserveradmin.domain.contract.entity.ContractRecord;
Expand All @@ -23,7 +24,6 @@
@Builder
public class User extends BaseEntity {
@Id
@Column(name = "user_id")
private String userId;

@Column(name = "user_name")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package com.kbds.itamserveradmin.domain.user.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum UserRole {
L0("L0","주임"),
L1("L1","대리"),
L2_1("L2","과장"),L2_2("L2","차장"),
L3_1("L3","수석 차장"),L3_2("L3","팀장"),
L4_1("L4","부장"),L4_2("L4","본부장");

private final String code;
private final String value;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
package com.kbds.itamserveradmin.domain.user.repository;

import com.kbds.itamserveradmin.domain.user.dto.UserInfoRes;
import com.kbds.itamserveradmin.domain.user.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

public interface UserRepository extends JpaRepository<User,String> {

// @Query("SELECT u FROM User u WHERE u.userId =:user_id")
// User findByUserId(@Param("user_id") String userId);


@Query("SELECT NEW com.kbds.itamserveradmin.domain.user.dto.UserInfoRes(u.userId, u.userName, u.userPhoto, u.userRole, d.deptName, c.corpName) " +
"FROM User u JOIN u.department d JOIN u.corporation c " +
"WHERE u.userId = :userId")
UserInfoRes findUserInfoWithCooperationAndDepartmentByUserId(@Param("userId") String userId);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package com.kbds.itamserveradmin.domain.user.service;

import com.kbds.itamserveradmin.domain.user.dto.UserInfoRes;

public interface UserService {
public UserInfoRes GetUserInfo(String userId);
}
Loading

0 comments on commit 89cb3cb

Please sign in to comment.