diff --git a/.DS_Store b/.DS_Store index e7b2389..e5d2312 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/build.gradle b/build.gradle index 93e67b4..5694845 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,18 @@ +buildscript { + ext { + queryDslVersion = "5.0.0" + } +} + + + plugins { id 'java' id 'org.springframework.boot' version '2.6.2' id 'io.spring.dependency-management' version '1.1.4' + + //querydsl 추가 + id "com.ewerk.gradle.plugins.querydsl" version "1.0.10" } group = 'com.kbds' @@ -28,12 +39,14 @@ dependencies { annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' + //querydsl 추가 + implementation "com.querydsl:querydsl-jpa:${queryDslVersion}" + implementation "com.querydsl:querydsl-apt:${queryDslVersion}" //h2 DB runtimeOnly 'com.h2database:h2' - runtimeOnly ('mysql:mysql-connector-java') //mysql8 implementation 'org.springframework.boot:spring-boot-starter-jdbc' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' @@ -41,8 +54,6 @@ dependencies { //jasypt 설정파일 암호화 라이브러리 implementation 'com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.5' - - // Security, Authentication // 시큐리티 추가 implementation 'org.springframework.boot:spring-boot-starter-security' @@ -52,10 +63,13 @@ dependencies { implementation 'io.springfox:springfox-boot-starter:3.0.0' implementation 'io.springfox:springfox-swagger-ui:3.0.0' - - - // 이미지 S3 업로드 - //implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE' + //pdf view + implementation 'com.itextpdf:itext7-core:7.2.6' +// // 이미지 S3 업로드 +// implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE' +// implementation 'com.amazonaws:aws-java-sdk-s3:1.12.476' +// implementation 'org.apache.tika:tika-core:2.5.0' +// annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" @@ -65,3 +79,24 @@ dependencies { tasks.named('test') { useJUnitPlatform() } + + + + +//querydsl 추가 시작 +def querydslDir = "$buildDir/generated/querydsl" + +querydsl { + jpa = true + querydslSourcesDir = querydslDir +} +sourceSets { + main.java.srcDir querydslDir +} +configurations { + querydsl.extendsFrom compileClasspath +} +compileQuerydsl { + options.annotationProcessorPath = configurations.querydsl +} +//querydsl 추가 끝 \ No newline at end of file diff --git a/src/.DS_Store b/src/.DS_Store index 445c29a..660bdd1 100644 Binary files a/src/.DS_Store and b/src/.DS_Store differ diff --git a/src/main/.DS_Store b/src/main/.DS_Store new file mode 100644 index 0000000..d4552b3 Binary files /dev/null and b/src/main/.DS_Store differ diff --git a/src/main/java/.DS_Store b/src/main/java/.DS_Store new file mode 100644 index 0000000..891785a Binary files /dev/null and b/src/main/java/.DS_Store differ diff --git a/src/main/java/com/.DS_Store b/src/main/java/com/.DS_Store new file mode 100644 index 0000000..4f7ca53 Binary files /dev/null and b/src/main/java/com/.DS_Store differ diff --git a/src/main/java/com/kbds/.DS_Store b/src/main/java/com/kbds/.DS_Store new file mode 100644 index 0000000..c14f4f9 Binary files /dev/null and b/src/main/java/com/kbds/.DS_Store differ diff --git a/src/main/java/com/kbds/itamserveradmin/.DS_Store b/src/main/java/com/kbds/itamserveradmin/.DS_Store new file mode 100644 index 0000000..cb96ba5 Binary files /dev/null and b/src/main/java/com/kbds/itamserveradmin/.DS_Store differ diff --git a/src/main/java/com/kbds/itamserveradmin/KbdsItamServerAdminApplication.java b/src/main/java/com/kbds/itamserveradmin/KbdsItamServerAdminApplication.java index 7b4ff5d..2aecc9c 100644 --- a/src/main/java/com/kbds/itamserveradmin/KbdsItamServerAdminApplication.java +++ b/src/main/java/com/kbds/itamserveradmin/KbdsItamServerAdminApplication.java @@ -1,8 +1,12 @@ package com.kbds.itamserveradmin; +import com.querydsl.jpa.impl.JPAQueryFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; +import org.springframework.context.annotation.Bean; + +import javax.persistence.EntityManager; @SpringBootApplication(exclude = SecurityAutoConfiguration.class) @@ -18,4 +22,9 @@ public static void main(String[] args) { } + @Bean + public JPAQueryFactory queryFactory(EntityManager em){ + return new JPAQueryFactory(em); + } + } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/Test.java b/src/main/java/com/kbds/itamserveradmin/domain/Test.java new file mode 100644 index 0000000..e69de29 diff --git a/src/main/java/com/kbds/itamserveradmin/domain/asset/controller/AssetController.java b/src/main/java/com/kbds/itamserveradmin/domain/asset/controller/AssetController.java index b68c8e4..cea48fb 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/asset/controller/AssetController.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/asset/controller/AssetController.java @@ -1,17 +1,38 @@ package com.kbds.itamserveradmin.domain.asset.controller; import com.kbds.itamserveradmin.domain.asset.dto.AssetRes; +import com.kbds.itamserveradmin.domain.asset.dto.ManualLogRes; +import com.kbds.itamserveradmin.domain.asset.entity.Asset; +import com.kbds.itamserveradmin.domain.asset.entity.ManualLog; import com.kbds.itamserveradmin.domain.asset.service.AssetService; +import com.kbds.itamserveradmin.domain.asset.service.ManualLogService; +import com.kbds.itamserveradmin.domain.contract.service.ContractService; import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import com.itextpdf.kernel.pdf.PdfDocument; +import com.itextpdf.kernel.pdf.PdfReader; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.List; +import java.util.stream.Collectors; + +import com.kbds.itamserveradmin.domain.asset.service.AssetService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @RequiredArgsConstructor @RequestMapping("/kbitam") public class AssetController { - public final AssetService assetService; + private final AssetService assetService; + private final ManualLogService manualLogService; + private final ContractService contractService; @GetMapping("/{dept}/{cont-id}/info") public ResponseEntity info(@PathVariable("cont-id") String contId, @PathVariable String dept){ @@ -21,4 +42,70 @@ public ResponseEntity info(@PathVariable("cont-id") String contId, @Pa } return ResponseEntity.ok(assetRes); } -} + + + @GetMapping("/d/{corpId}") + public ResponseEntity PKtest(@PathVariable("corpId")String corpId){ + + System.out.println(corpId+"!!!"); + + + return ResponseEntity.ok( assetService.testSaveForcreatePk(corpId)); + + } + + + @GetMapping("/{dept}/{cont-id}/allver") + public ResponseEntity> allVer(@PathVariable("cont-id") String contId, @PathVariable String dept){ + Asset asset = contractService.findAstIdByContId(contId); + + List manualLogs = manualLogService.findByAstId(asset); + List mnLogVersList = manualLogs.stream() + .map(ManualLogRes::allvers) + .collect(Collectors.toList()); + + return ResponseEntity.ok(mnLogVersList); + } + + @GetMapping("/{dept}/{cont-id}/installguide") + public ResponseEntity installGuide(@PathVariable("cont-id") String contId, @PathVariable String dept) throws IOException { + ManualLogRes installGuideRes = assetService.getInstallGuide(contId); + if (installGuideRes == null) { + return ResponseEntity.notFound().build(); + } + + String pdfFilePath = installGuideRes.getMnLogInstallGuide(); + + // PDF 파일을 HTML로 변환 + ByteArrayOutputStream htmlStream = new ByteArrayOutputStream(); + PdfReader reader = new PdfReader(pdfFilePath); + PdfDocument pdfDoc = new PdfDocument(reader); + pdfDoc.copyPagesTo(1, pdfDoc.getNumberOfPages(), new PdfDocument(new com.itextpdf.kernel.pdf.PdfWriter(htmlStream))); + pdfDoc.close(); + reader.close(); + String htmlContent = new String(htmlStream.toByteArray()); + + // HTML을 바이트 배열로 변환하여 클라이언트에게 전송 + byte[] htmlBytes = htmlContent.getBytes(); + + // HTTP 응답으로 HTML 파일 반환 + return ResponseEntity.ok() + .contentType(MediaType.TEXT_HTML) + .body(htmlBytes); + + } + } +// @GetMapping("/{dept}/{cont-id}/pdfView") +// public ModelAndView getPdfView(@PathVariable("cont-id") String contId, @PathVariable String dept) { +// findBycontId +// ManualLog manualLog = manualLogService.findByMnLogId(mnLogId); +// if (manualLog == null) { +// return null; +// } +// +// ModelAndView mav = new ModelAndView(); +// mav.setView(new CustomPdfView()); +// mav.addObject("manualLog", manualLog); +// return mav; +// } + diff --git a/src/main/java/com/kbds/itamserveradmin/domain/asset/dto/AssetRes.java b/src/main/java/com/kbds/itamserveradmin/domain/asset/dto/AssetRes.java index 063d6a2..905e7dc 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/asset/dto/AssetRes.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/asset/dto/AssetRes.java @@ -34,5 +34,4 @@ public static AssetRes assetInfo (Asset asset){ .astPrice(asset.getAstPrice()) .build(); } - } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/asset/dto/ManualLogReq.java b/src/main/java/com/kbds/itamserveradmin/domain/asset/dto/ManualLogReq.java new file mode 100644 index 0000000..691990b --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/asset/dto/ManualLogReq.java @@ -0,0 +1,10 @@ +package com.kbds.itamserveradmin.domain.asset.dto; + +import lombok.Data; +import org.springframework.web.multipart.MultipartFile; + +@Data +public class ManualLogReq { + private MultipartFile file; + +} diff --git a/src/main/java/com/kbds/itamserveradmin/domain/asset/dto/ManualLogRes.java b/src/main/java/com/kbds/itamserveradmin/domain/asset/dto/ManualLogRes.java new file mode 100644 index 0000000..6c29c19 --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/asset/dto/ManualLogRes.java @@ -0,0 +1,34 @@ +package com.kbds.itamserveradmin.domain.asset.dto; + +import com.kbds.itamserveradmin.domain.asset.entity.ManualLog; +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class ManualLogRes { + + private String mnLogId; + private String mnLogVer; + private String mnLogUserGuide; + private String mnLogInstallFile; + private String mnLogInstallGuide; + private String assetId; + + public static ManualLogRes installGuideRes(ManualLog manualLog){ + return ManualLogRes.builder() + .assetId(manualLog.getAsset().getAstId()) + .mnLogId(manualLog.getMnLogId()) + .mnLogVer(manualLog.getMnLogVer()) + .mnLogInstallFile(manualLog.getMnLogInstallFile()) + .mnLogInstallGuide(manualLog.getMnLogInstallGuide()) + .build(); + } + + public static ManualLogRes allvers(ManualLog manualLog){ + return ManualLogRes.builder() + .assetId(manualLog.getAsset().getAstId()) + .mnLogVer(manualLog.getMnLogVer()) + .build(); + } +} 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 408993c..76be24b 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 @@ -39,4 +39,8 @@ public class Asset { private String astDpd; private String astImgUrl; + + + + } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/asset/entity/ManualLog.java b/src/main/java/com/kbds/itamserveradmin/domain/asset/entity/ManualLog.java index 7c34c04..f0da5f1 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/asset/entity/ManualLog.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/asset/entity/ManualLog.java @@ -27,4 +27,8 @@ public class ManualLog { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "ast_id") private Asset asset; + + public void updateInstallFilePath(String InsFilePath){ + this.mnLogInstallFile = InsFilePath; + } } 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 9591387..c19e723 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 @@ -1,9 +1,36 @@ package com.kbds.itamserveradmin.domain.asset.repository; import com.kbds.itamserveradmin.domain.asset.entity.Asset; +import com.kbds.itamserveradmin.domain.corporation.entity.CorpPK; 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; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + + +@Repository public interface AssetRepository extends JpaRepository { + Asset findAssetByAstId(String astId); + + + + +// @Query("SELECT a " + +// "FROM Asset a " + +// "Where a.corp.corpId = :corp_id " + +// "order by astId desc") +// Asset findCorpCntById(@Param("corp_id") String corp_id); + + @Query(value = "SELECT max(a.astId) " + + "FROM Asset a " + // 여기서 공백을 추가해야 함 + "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); + } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/asset/repository/ManualLogRepository.java b/src/main/java/com/kbds/itamserveradmin/domain/asset/repository/ManualLogRepository.java index f8900cf..f5554cc 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/asset/repository/ManualLogRepository.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/asset/repository/ManualLogRepository.java @@ -1,7 +1,13 @@ package com.kbds.itamserveradmin.domain.asset.repository; +import com.kbds.itamserveradmin.domain.asset.entity.Asset; import com.kbds.itamserveradmin.domain.asset.entity.ManualLog; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface ManualLogRepository extends JpaRepository { + ManualLog findByAsset_AstId(String astId); + List findByAsset (Asset asset); + ManualLog findByMnLogId (String mnLogId); } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/asset/service/AssetService.java b/src/main/java/com/kbds/itamserveradmin/domain/asset/service/AssetService.java index 09365aa..da250c4 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/asset/service/AssetService.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/asset/service/AssetService.java @@ -1,25 +1,121 @@ package com.kbds.itamserveradmin.domain.asset.service; +import com.kbds.itamserveradmin.domain.asset.entity.Asset; +import com.kbds.itamserveradmin.domain.asset.entity.AstTag; +import com.kbds.itamserveradmin.domain.asset.repository.AssetRepository; +import com.kbds.itamserveradmin.domain.corporation.entity.CorpPK; +import com.kbds.itamserveradmin.domain.corporation.entity.Corporation; +import com.kbds.itamserveradmin.domain.corporation.repository.CorporationRepository; +import com.kbds.itamserveradmin.domain.user.entity.User; +import com.kbds.itamserveradmin.domain.user.service.UserService; +import com.kbds.itamserveradmin.global.exception.BaseException; +import com.kbds.itamserveradmin.global.exception.ErrorCode; +import org.springframework.beans.factory.annotation.Autowired; import com.kbds.itamserveradmin.domain.asset.dto.AssetRes; +import com.kbds.itamserveradmin.domain.asset.dto.ManualLogRes; import com.kbds.itamserveradmin.domain.asset.entity.Asset; +import com.kbds.itamserveradmin.domain.asset.entity.ManualLog; import com.kbds.itamserveradmin.domain.contract.service.ContractService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; +import java.util.Locale; +import java.util.Optional; + @Service @RequiredArgsConstructor public class AssetService { + private final AssetRepository assetRepository; + private final CorporationRepository corporationRepository; + private final UserService userService; + + + public String createPK(String corp){ + + + //List t = assetRepository.findCorpCntById(corp); + String t = assetRepository.findCorpCntById(corp); + System.out.println("<<<"+t); + + + //int temp = 0; + if(t == null || t.toString() == "0"){ //회사만 있고(회사가 없을 수 없음) 자산이 등록되어 있지 않는 경우. + System.out.println("nullllllll"); + } + + System.out.println(">>>> " + t.toString()); + + + int temp = Integer.parseInt(t.toString().substring(6,9)) + 1; + + String PK_NUM =t.toString().substring(0,6)+ String.format("%03d", temp); + + System.out.println(">>>>22"+PK_NUM); + + return PK_NUM; + + } + + public String testSaveForcreatePk(String corp){ + + Corporation c = corporationRepository.findById(corp).orElseThrow( + () -> new BaseException(ErrorCode.INTERNAL_SERVER_ERROR) + ); + + User user = userService.getUser("L00"); + + System.out.println("들어가기전"); + Asset ast = Asset.builder() + .astId(createPK(c.getCorpId())) + .astName("zzzz") + .astTag(AstTag.BANK) + .corp(c) + .user(user) + .build(); + + System.out.println("저장준비"); + Asset saved = assetRepository.save(ast); + + System.out.println("저장완료"); + + //System.out.println(saved); + + String ttemp =saved.getAstId(); + System.out.println(ttemp); + return ttemp; + + } + + + + private final ContractService contractService; + private final ManualLogService manualLogService; @Transactional public AssetRes getInfo(String contId) { - Asset asset = contractService.getAstIdByContId(contId); + Asset asset = contractService.findAstIdByContId(contId); if (asset == null) { return null; } return AssetRes.assetInfo(asset); } + + @Transactional + public ManualLogRes getInstallGuide(String contId) { + Asset asset = contractService.findAstIdByContId(contId); + if (asset == null) { + return null; + } + ManualLog manualLog = manualLogService.findByAsset_AstId(asset.getAstId()); + if (manualLog == null){ + return null; + } + return ManualLogRes.installGuideRes(manualLog); + } + } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/asset/service/ManualLogService.java b/src/main/java/com/kbds/itamserveradmin/domain/asset/service/ManualLogService.java new file mode 100644 index 0000000..9951cf3 --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/asset/service/ManualLogService.java @@ -0,0 +1,42 @@ +package com.kbds.itamserveradmin.domain.asset.service; + +import com.kbds.itamserveradmin.domain.asset.dto.ManualLogReq; +import com.kbds.itamserveradmin.domain.asset.entity.Asset; +import com.kbds.itamserveradmin.domain.asset.entity.ManualLog; +import com.kbds.itamserveradmin.domain.asset.repository.ManualLogRepository; +import com.kbds.itamserveradmin.global.file.FileUploadService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.io.IOException; +import java.util.List; + + +@Service +@RequiredArgsConstructor +public class ManualLogService { + private final ManualLogRepository manualLogRepository; + private final FileUploadService fileUploadService; + + public ManualLog findByAsset_AstId(String astId) { + return manualLogRepository.findByAsset_AstId(astId); + } + + public List findByAstId(Asset asset) { + return manualLogRepository.findByAsset(asset); + } + //일단 로컬에 파일 업로드 로직을 작성했습니다.(asset에 연결 아직못함) + @Transactional + public void saveInstallFile(ManualLogReq manualLogReq)throws IOException{ + ManualLog manualLog = new ManualLog(); + String filePath = fileUploadService.saveFile(manualLogReq.getFile()); + manualLog.updateInstallFilePath(filePath); + + manualLogRepository.save(manualLog); + } + + public ManualLog findByMnLogId(String mnLogId){ + return manualLogRepository.findByMnLogId(mnLogId); + } +} 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 14b7867..63dc8e1 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 @@ -1,17 +1,27 @@ package com.kbds.itamserveradmin.domain.assetRequest.controller; -import com.kbds.itamserveradmin.domain.assetRequest.dto.AssetRequestReq; +import com.kbds.itamserveradmin.domain.assetRequest.dto.*; import com.kbds.itamserveradmin.domain.assetRequest.entity.AssetRequest; +import com.kbds.itamserveradmin.domain.assetRequest.entity.RequestStatus; import com.kbds.itamserveradmin.domain.assetRequest.service.AssetRequestService; +import com.kbds.itamserveradmin.domain.user.dto.AssetAdminList; +import com.kbds.itamserveradmin.domain.user.dto.AssetAdminListRes; 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; +import org.springframework.data.web.PageableDefault; +import org.springframework.format.annotation.DateTimeFormat; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.time.LocalDateTime; +import java.util.List; + @RestController @Slf4j @RequiredArgsConstructor @@ -19,41 +29,145 @@ public class AssetRequestController { private final AssetRequestService assetRequestService; -// -// -// @PostMapping("/test") -// @ResponseBody -// public ResponseEntity test(){ -// boolean test = true; -// System.out.println("시작"); -// -// if(test) { -// throw new BaseException(ErrorCode.INTERNAL_SERVER_ERROR); -// } -// -// return ResponseEntity.ok("성공"); -// -// } -// -// -// @PostMapping("/kbitam/{dept}/{contId}/request") + + @Autowired + public AssetRequestController(AssetRequestService assetRequestService) { + this.assetRequestService = assetRequestService; + } + + + @PostMapping("/test") + @ResponseBody + public ResponseEntity test(){ + boolean test = true; + System.out.println("시작"); + + if(test) { + throw new BaseException(ErrorCode.INTERNAL_SERVER_ERROR); + } + + return ResponseEntity.ok("성공"); + + } + + + @PostMapping("/kbitam/{dept}/{contId}/request") + @ResponseBody + public ResponseEntity requestAsset(@PathVariable String dept, + @PathVariable String contId, + @RequestBody AssetRequestReq req){ + + + AssetRequestRes as = assetRequestService.RequestAsset(dept,contId,req); + + return ResponseEntity.ok(as); + + + } + + @GetMapping("/kbitam/getassetadminList/{conId}") + @ResponseBody + public ResponseEntity getAssetAdminList(@PathVariable String conId){ +// AssetAdminListRes result = assetRequestService.getAssetAdminList(conId); +// System.out.println("hello1"); +// System.out.println(result.getCount() + result.getData().toString()); +// System.out.println("hello2"); + return ResponseEntity.ok(assetRequestService.getAssetAdminList(conId)); + } + + + @GetMapping("/kbitam/mypage/{userId}/requestList/search") + @ResponseBody + public ResponseEntity> userRequestSearch(@PathVariable String userId, + @RequestParam(name = "start", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime start, + @RequestParam(name = "end", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime end, + @PageableDefault(size=5) Pageable pageable){ + + System.out.println("시작 : "+userId); + AstReqSearchReq req = new AstReqSearchReq(userId,start,end); + + Page t = assetRequestService.userRequestSearch(req, pageable); + System.out.println("빠이"); + return ResponseEntity.ok(t); + + } + + + + @GetMapping("/kbitam/mypage/{userId}/receptionList/search") + @ResponseBody + public ResponseEntity> adminRequestSearch(@PathVariable String userId, + @RequestParam(name = "start", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime start, + @RequestParam(name = "end", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime end, + @RequestParam(name= "userName", required = false) String userName, + @RequestParam(name= "astReqDept", required = false) String astReqDept, + @RequestParam(name="astReqMgStatus",required = false) String astReqMgStatus, + @PageableDefault(size=5) Pageable pageable){ + + System.out.println("시작 : "+userId); + AstReqSearchForAdminReq req = new AstReqSearchForAdminReq(userId,start,end,userName,astReqDept,astReqMgStatus); + + Page t = assetRequestService.searchForAdmin(req, pageable); + System.out.println("빠이"); + return ResponseEntity.ok(t); + + } + +// @GetMapping("/kk/{userId}") // @ResponseBody -// public ResponseEntity requestAsset(@PathVariable String dept, -// @PathVariable String contId, -// @RequestBody AssetRequestReq req){ -// -//// System.out.println("dept :"+dept+" conId:"+contId); -//// System.out.println(req.getContId()); -//// System.out.println(req.getAstReqStartDate()); -//// System.out.println(req.getAstReqEndDate()); -//// System.out.println(req.getAstReqEndDate()); -//// System.out.println(req.getAstReqMgDate()); -//// System.out.println(req.getAstReqReason()); -//// System.out.println(req.getUserId()); -// -// -// return ResponseEntity.ok("성공"); +// public ResponseEntity test(@PathVariable String userId){ // +// System.out.println("시작 : "+userId); +// String t = assetRequestService.test(userId); +// System.out.println("빠이"); +// return ResponseEntity.ok(t); // // } + + + @GetMapping("/kbitam/mypage/{userId}/requestList/{astReqId}") + public ResponseEntity getUserRequestDetails(@PathVariable String userId, @PathVariable String astReqId){ + + AstReqDetailRes res = assetRequestService.getAstReqDetatils(astReqId,userId); + System.out.println("왔어?ㅠㅠ"); + //System.out.println(res.getAstReqName()); + System.out.println("-----dsadhsja----"); + + return ResponseEntity.ok(res); + + + } + + + @GetMapping("/kbitam/mypage/{userId}/receptionList/{contId}") + public ResponseEntity getAdminRequestDetails(@PathVariable String userId, @PathVariable String astReqId){ + + AstReqDetailRes res = assetRequestService.getAstReqDetatils(astReqId,userId); + System.out.println("왔어?ㅠㅠ"); + //System.out.println(res.getAstReqName()); + System.out.println("-----dsadhsja----"); + + return ResponseEntity.ok(res); + + + } + + @PatchMapping("/kbitam/mypage/{userId}/requestList/{contId}/update") + public ResponseEntity updateUserRequestStatus(@PathVariable String userId, @PathVariable String contId, @RequestBody AstReqStatusUpdateReq req){ + + assetRequestService.updateUserRequestStatus(req.getAstReqId()); + System.out.println("변경완료"); + + AstReqStatusUpdateRes t = assetRequestService.saveLogUpdateUserRequestStatus(req.getAstReqId(), RequestStatus.CANCEL); + + return ResponseEntity.ok(t); + + } + + + + + + + } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AssetRequestReq.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AssetRequestReq.java index 7736fda..5d9018a 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AssetRequestReq.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AssetRequestReq.java @@ -10,6 +10,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.List; @Getter @Builder @@ -18,8 +19,8 @@ public class AssetRequestReq { - @ApiModelProperty(notes = "계약서 ID",example = "") - private String contId; +// @ApiModelProperty(notes = "계약서 ID",example = "") +// private String contId; @ApiModelProperty(notes = "사용시작일",example = "2022-08-04") @JsonFormat(pattern = "yyyy-MM-dd") @@ -39,10 +40,34 @@ public class AssetRequestReq { private String astReqReason; - @ApiModelProperty(notes = "사용자ID",example = "") + @ApiModelProperty(notes = "요청자의 ID (사용자ID), 요청자가 누군지 식별",example = "") private String userId; + private List assetAdminList; + + + private String astName; //요청 자산 이름 + + private String astVer; //요청버전 + + + + + + + + + + + + + + + + + + } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AssetRequestRes.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AssetRequestRes.java new file mode 100644 index 0000000..192f5b3 --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AssetRequestRes.java @@ -0,0 +1,32 @@ +package com.kbds.itamserveradmin.domain.assetRequest.dto; + + +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; + +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Getter +//@JsonPropertyOrder({"astReqId", "astReqMgIdList"}) +public class AssetRequestRes { + + + private String astReqId; + + private List astReqMgIdList; + + public static AssetRequestRes of(String astReqId, List astReqMgIdList){ + return AssetRequestRes.builder().astReqId(astReqId).astReqMgIdList(astReqMgIdList).build(); + + } +} + + diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqAdminList.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqAdminList.java new file mode 100644 index 0000000..9d72deb --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqAdminList.java @@ -0,0 +1,38 @@ +package com.kbds.itamserveradmin.domain.assetRequest.dto; + + +import com.kbds.itamserveradmin.domain.assetRequest.entity.AssetRequestManage; +import com.kbds.itamserveradmin.domain.corporation.entity.Corporation; +import com.kbds.itamserveradmin.domain.department.entity.Department; +import com.kbds.itamserveradmin.domain.user.entity.User; +import com.kbds.itamserveradmin.domain.user.entity.UserRole; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.Getter; +import lombok.NoArgsConstructor; + + + +@Data +public class AstReqAdminList { + + private String userName; + private String userRole; + private String corporation; + private String department; + private String status; + + public AstReqAdminList(AssetRequestManage assetRequestManage) { + System.out.println("====adminList==="); + + User user = assetRequestManage.getAssetAdmin().getManager(); + this.userName = user.getUserName(); + this.userRole = user.getUserRole().getValue(); + this.corporation = user.getCorporation().getCorpName(); + this.department = user.getDepartment().getDeptName(); + this.status = assetRequestManage.getAstReqMgStatus().getValue(); + + System.out.println("====adminList22222==="); + + } +} diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqDetailForAdminRes.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqDetailForAdminRes.java new file mode 100644 index 0000000..edb36c3 --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqDetailForAdminRes.java @@ -0,0 +1,49 @@ +package com.kbds.itamserveradmin.domain.assetRequest.dto; + + +import com.kbds.itamserveradmin.domain.assetRequest.entity.AssetRequestManage; +import com.kbds.itamserveradmin.domain.user.entity.User; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + + +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Getter +public class AstReqDetailForAdminRes { + + private String astReqName; + private String astReqMgStatus; + + private UserInfoDto user; + + private LocalDateTime astReqStartDate; + private LocalDateTime astReqEndDate; + + private String astReqReason; + + private String contId; //나중에 에셋정보보기로 이어지기 위함. + + public final AstReqDetailForAdminRes of(User u , AssetRequestManage a, String contId){ + return AstReqDetailForAdminRes.builder() + .astReqName(a.getAstReqName()) + .astReqMgStatus(a.getAstReqMgStatus().getValue()) + .user(UserInfoDto.from(u)) + .astReqStartDate(a.getAssetRequest().getAstReqStartDate()) + .astReqEndDate(a.getAssetRequest().getAstReqEndDate()) + .astReqReason(a.getAssetRequest().getAstReqReason()) + .contId(contId) + .build(); + + } + + + + + +} diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqDetailRes.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqDetailRes.java new file mode 100644 index 0000000..1a75a94 --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqDetailRes.java @@ -0,0 +1,54 @@ +package com.kbds.itamserveradmin.domain.assetRequest.dto; + + +import com.kbds.itamserveradmin.domain.assetRequest.entity.AssetRequest; +import com.kbds.itamserveradmin.domain.assetRequest.entity.AssetRequestManage; +import com.kbds.itamserveradmin.domain.user.entity.User; +import lombok.*; + +import java.time.LocalDateTime; +import java.util.List; + + +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Getter +public class AstReqDetailRes { + + private String astReqName; + private String requestStatus; + + private UserInfoDto user; + + private LocalDateTime astReqStartDate; + private LocalDateTime astReqEndDate; + + private String astReqReason; + + private List astAdminList; + + + + public static AstReqDetailRes of(String astReqName,String requestStatus, LocalDateTime astReqStartDate, LocalDateTime astReqEndDate,String astReqReason, User u, List astAdminList){ + System.out.println("와?"); + return AstReqDetailRes.builder() + .astReqName(astReqName) + .requestStatus(requestStatus) + .user(UserInfoDto.from(u)) + .astReqStartDate(astReqStartDate) + .astReqEndDate(astReqEndDate) + .astReqReason(astReqReason) + .astAdminList(astAdminList) + .build(); + + + + } + + + + + + +} diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqSearchForAdminReq.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqSearchForAdminReq.java new file mode 100644 index 0000000..36a12e7 --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqSearchForAdminReq.java @@ -0,0 +1,25 @@ +package com.kbds.itamserveradmin.domain.assetRequest.dto; + +import com.kbds.itamserveradmin.domain.assetRequest.entity.RequestMangeStatus; +import com.kbds.itamserveradmin.domain.assetRequest.entity.RequestStatus; +import lombok.*; + +import java.time.LocalDateTime; + +@AllArgsConstructor +@NoArgsConstructor +@Builder +@Data +public class AstReqSearchForAdminReq { + + + private String userId; + private LocalDateTime start; + private LocalDateTime end; + + private String userName; + private String astReqDept; + + private String astReqMgStatus; + +} diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqSearchForAdminRes.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqSearchForAdminRes.java new file mode 100644 index 0000000..eb7654c --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqSearchForAdminRes.java @@ -0,0 +1,38 @@ +package com.kbds.itamserveradmin.domain.assetRequest.dto; + + +import com.kbds.itamserveradmin.domain.assetRequest.entity.RequestMangeStatus; +import com.kbds.itamserveradmin.domain.assetRequest.entity.RequestStatus; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Builder +public class AstReqSearchForAdminRes { + + + private String astReqName; //자산 이름 + private String astReqMgId; //요청관리id + + private String astReqId; //요청id + private LocalDateTime astReqMgDate; //요청날짜 + private RequestMangeStatus astReqMgStatus; //요청태관리상태 + + private String userName; //이름 + private String userId; //사번 + private String astReqDept; // 요청부서 + private String contId;//계약id + + + + + + +} diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqSearchReq.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqSearchReq.java new file mode 100644 index 0000000..2f12b7f --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqSearchReq.java @@ -0,0 +1,23 @@ +package com.kbds.itamserveradmin.domain.assetRequest.dto; + + +import lombok.*; + +import java.io.Serializable; +import java.time.LocalDate; +import java.time.LocalDateTime; + +@AllArgsConstructor +@NoArgsConstructor +@Getter +@Builder +@Data +public class AstReqSearchReq implements Serializable { + + + private String userId; + private LocalDateTime start; + private LocalDateTime end; + + +} diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqSearchRes.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqSearchRes.java new file mode 100644 index 0000000..fc44586 --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqSearchRes.java @@ -0,0 +1,29 @@ +package com.kbds.itamserveradmin.domain.assetRequest.dto; + + +import com.kbds.itamserveradmin.domain.assetRequest.entity.RequestStatus; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Getter +public class AstReqSearchRes { + + + private String astName; //자산 이름 + + private String astReqId; //id + private LocalDateTime astReqMgDate; //요청날짜 + private RequestStatus astReqStatus; //요청상태 + + + + + +} diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqStatusUpdateReq.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqStatusUpdateReq.java new file mode 100644 index 0000000..08f90c4 --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqStatusUpdateReq.java @@ -0,0 +1,14 @@ +package com.kbds.itamserveradmin.domain.assetRequest.dto; + + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +public class AstReqStatusUpdateReq { + + private String astReqId; +} diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqStatusUpdateRes.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqStatusUpdateRes.java new file mode 100644 index 0000000..8460f5d --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/AstReqStatusUpdateRes.java @@ -0,0 +1,25 @@ +package com.kbds.itamserveradmin.domain.assetRequest.dto; + + +import com.kbds.itamserveradmin.domain.assetRequest.entity.RequestStatus; +import lombok.*; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Builder +public class AstReqStatusUpdateRes { + + private String astReqLogId; + private String astReqId; + private String status; + + public static AstReqStatusUpdateRes of(String astReqLogId, String astReqId, RequestStatus status){ + return AstReqStatusUpdateRes.builder() + .astReqId(astReqId) + .astReqLogId(astReqLogId) + .status(status.getValue()) + .build(); + + } +} diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/UserInfoDto.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/UserInfoDto.java new file mode 100644 index 0000000..2572f2d --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/dto/UserInfoDto.java @@ -0,0 +1,29 @@ +package com.kbds.itamserveradmin.domain.assetRequest.dto; + + +import com.kbds.itamserveradmin.domain.user.entity.User; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class UserInfoDto { + + private String userName; + private String userRole; + private String department; + private String corporation; + + public static UserInfoDto from(User u){ + return UserInfoDto.builder() + .userName(u.getUserName()) + .userRole(u.getUserRole().getValue()) + .department(u.getDepartment().getDeptName()) + .corporation(u.getCorporation().getCorpName()) + .build(); + } +} diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/entity/AssetRequest.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/entity/AssetRequest.java index ffbd248..2f31c10 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/entity/AssetRequest.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/entity/AssetRequest.java @@ -49,6 +49,32 @@ public class AssetRequest { @JoinColumn(name = "cont_id") private Contract contract; + + + + private LocalDateTime astReqMgDate; + private LocalDateTime astReqMgSud; + + @PrePersist + public void prePersist() { + LocalDateTime now = LocalDateTime.now(); + astReqMgDate = now; + astReqMgSud = now; + } + + @PreUpdate + public void preUpdate() { + astReqMgSud = LocalDateTime.now(); + } + //==연관관계==// +// public static AssetRequest from() + + + + + + + } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/entity/AssetRequestManage.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/entity/AssetRequestManage.java index 034e398..6a8e858 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/entity/AssetRequestManage.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/entity/AssetRequestManage.java @@ -53,4 +53,8 @@ public void preUpdate() { astReqMgSud = LocalDateTime.now(); } + + + + } 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 8e7c1ce..e4e15ab 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,14 @@ @AllArgsConstructor @Getter public enum RequestStatus { - APPROVAL_WAIT("승인대기"),APPROVAL("승인"),IN_USE("사용중"),APPROVAL_REJECTED("승인거절"),EXPIRED("폐기"),NOT_IN_USE("미사용중"); + + APPROVAL_WAIT("승인대기"), + APPROVAL("승인"), + IN_USE("사용중"), + APPROVAL_REJECTED("승인거절"), + EXPIRED("폐기"), + CANCEL("요청취소"), + NOT_IN_USE("미사용중"); @JsonValue private String value; diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestLogRepository.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestLogRepository.java index d55ea76..3841f96 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestLogRepository.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestLogRepository.java @@ -2,6 +2,14 @@ import com.kbds.itamserveradmin.domain.assetRequest.entity.AssetRequestLog; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; +import org.springframework.web.bind.annotation.ResponseBody; + + +@Repository +public interface AssetRequestLogRepository extends JpaRepository ,AssetRequestLogRepositoryCustom{ + + + -public interface AssetRequestLogRepository extends JpaRepository { } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestLogRepositoryCustom.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestLogRepositoryCustom.java new file mode 100644 index 0000000..9f9534e --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestLogRepositoryCustom.java @@ -0,0 +1,11 @@ +package com.kbds.itamserveradmin.domain.assetRequest.repository; + + +import com.kbds.itamserveradmin.domain.assetRequest.entity.AssetRequestLog; + +public interface AssetRequestLogRepositoryCustom { + + AssetRequestLog getRecentLog(String astReqId); + + +} diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestLogRepositoryImpl.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestLogRepositoryImpl.java new file mode 100644 index 0000000..2d93ce3 --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestLogRepositoryImpl.java @@ -0,0 +1,28 @@ +package com.kbds.itamserveradmin.domain.assetRequest.repository; + + +import com.kbds.itamserveradmin.domain.assetRequest.entity.AssetRequestLog; +import com.kbds.itamserveradmin.domain.assetRequest.entity.QAssetRequest; +import com.kbds.itamserveradmin.domain.assetRequest.entity.QAssetRequestLog; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; + +@Repository +@RequiredArgsConstructor +public class AssetRequestLogRepositoryImpl implements AssetRequestLogRepositoryCustom { + private final JPAQueryFactory queryFactory; + + + @Override + public AssetRequestLog getRecentLog(String astReqId) { + AssetRequestLog result = queryFactory + .selectFrom(QAssetRequestLog.assetRequestLog) + .where(QAssetRequest.assetRequest.astReqId.eq(astReqId)) + .orderBy(QAssetRequest.assetRequest.astReqId.desc()) + .limit(1) + .fetchOne(); + + return result; + } +} diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestManageLogRepository.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestManageLogRepository.java index 90c1045..9eb35ba 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestManageLogRepository.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestManageLogRepository.java @@ -2,6 +2,9 @@ import com.kbds.itamserveradmin.domain.assetRequest.entity.AssetRequestManageLog; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository public interface AssetRequestManageLogRepository extends JpaRepository { } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestManageRepository.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestManageRepository.java index 4d6d938..35dcc7c 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestManageRepository.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestManageRepository.java @@ -2,6 +2,40 @@ import com.kbds.itamserveradmin.domain.assetRequest.entity.AssetRequestManage; 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; +import java.util.List; + +@Repository public interface AssetRequestManageRepository extends JpaRepository { + + +// @Query("select am " + +// "from AssetRequestManage am " + +// "join fetch am.assetRequest ar " + +// "join fetch am.assetAdmin u " + +// "where am.ast_req_id = :astReqId and am.assetRequest.astReqId = ar.astReqId and am.assetAdmin.astAdminId = u.astAdminId ") +// List findAssetRequestManageById(@Param("astReqId")String astReqId); + + @Query("SELECT ar FROM AssetRequestManage ar" + + " JOIN FETCH ar.assetRequest" + + " JOIN FETCH ar.assetAdmin " + + " WHERE ar.assetRequest.astReqId = :astReqId") + public List findByAstReqIdWithAssetRequest(@Param("astReqId") String astReqId); + + + + @Query("SELECT ar FROM AssetRequestManage ar " + + "WHERE ar.assetRequest.astReqId = :astReqId ") + public List findByAstReqId(@Param("astReqId") String astReqId); + + + @Query("SELECT ar FROM AssetRequestManage ar " + + "WHERE ar.astReqMgId = :astReqMgId ") + AssetRequestManage findByAstReqMgId(@Param("astReqMgId") String astReqMgId); + + + } 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 fdb05bb..3bde172 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 @@ -4,10 +4,13 @@ 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; import java.util.List; -public interface AssetRequestRepository extends JpaRepository { +@Repository +public interface AssetRequestRepository extends JpaRepository,AssetRequestRepositoryCustom { List findByAstRequestUserUserId(String userId); AssetRequest findAssetRequestByContractAndAstRequestUser(Contract contract, User user); + } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestRepositoryCustom.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestRepositoryCustom.java new file mode 100644 index 0000000..7f9469d --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestRepositoryCustom.java @@ -0,0 +1,21 @@ +package com.kbds.itamserveradmin.domain.assetRequest.repository; + +import com.kbds.itamserveradmin.domain.assetRequest.dto.AstReqSearchForAdminReq; +import com.kbds.itamserveradmin.domain.assetRequest.dto.AstReqSearchForAdminRes; +import com.kbds.itamserveradmin.domain.assetRequest.dto.AstReqSearchReq; +import com.kbds.itamserveradmin.domain.assetRequest.dto.AstReqSearchRes; +import com.kbds.itamserveradmin.domain.assetRequest.entity.AssetRequest; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +import java.util.List; + +public interface AssetRequestRepositoryCustom { + + + Page search(AstReqSearchReq req, Pageable pageable); + Page searchForAdmin(AstReqSearchForAdminReq req, Pageable pageable); + + List test(String userId); + +} diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestRepositoryImpl.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestRepositoryImpl.java new file mode 100644 index 0000000..fe8e204 --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/AssetRequestRepositoryImpl.java @@ -0,0 +1,195 @@ +package com.kbds.itamserveradmin.domain.assetRequest.repository; + + +import com.kbds.itamserveradmin.domain.asset.entity.QAsset; +import com.kbds.itamserveradmin.domain.assetRequest.dto.AstReqSearchForAdminReq; +import com.kbds.itamserveradmin.domain.assetRequest.dto.AstReqSearchForAdminRes; +import com.kbds.itamserveradmin.domain.assetRequest.dto.AstReqSearchReq; +import com.kbds.itamserveradmin.domain.assetRequest.dto.AstReqSearchRes; +import com.kbds.itamserveradmin.domain.assetRequest.entity.*; +import com.kbds.itamserveradmin.domain.contract.entity.QContract; +import com.kbds.itamserveradmin.domain.user.entity.QUser; +import com.querydsl.core.types.Projections; +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Repository; + +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.List; + + +@Repository +@RequiredArgsConstructor +public class AssetRequestRepositoryImpl implements AssetRequestRepositoryCustom { + + private final JPAQueryFactory queryFactory; + + QAssetRequest astRequest = new QAssetRequest("AssetRequest"); + + + @Override + public Page search(AstReqSearchReq req, Pageable pageable){ + + + List contents = queryFactory + .select(Projections.fields(AstReqSearchRes.class, + QAsset.asset.astName, + QAssetRequest.assetRequest.astReqId, + QAssetRequest.assetRequest.astReqMgDate, + QAssetRequest.assetRequest.astReqStatus)) + .from(QAssetRequest.assetRequest) + .join(QAssetRequest.assetRequest.contract,QContract.contract) + .join(QContract.contract.ast,QAsset.asset) + .where(astRequestUser(req.getUserId()) , UserRequestCond(req.getStart(),req.getEnd())) + .orderBy(QAssetRequest.assetRequest.astReqMgDate.desc()) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .fetch(); + + + Long total = queryFactory + .select(QAssetRequest.assetRequest.count()) + .from(QAssetRequest.assetRequest) + .where(astRequestUser(req.getUserId()) , UserRequestCond(req.getStart(),req.getEnd())) + .fetchOne(); + + System.out.println("total>>"+total); + + + + + return new PageImpl<>(contents,pageable,total); + + //return PageableExecutionUtils.getPage(contents,pageable,countQuery::fetchCount); + } + + @Override + public Page searchForAdmin(AstReqSearchForAdminReq req, Pageable pageable) { + + List contents = queryFactory + .select(Projections.fields(AstReqSearchForAdminRes.class, + QAssetRequestManage.assetRequestManage.astReqName, //자산이름 + QAssetRequestManage.assetRequestManage.astReqMgId, + QAssetRequestManage.assetRequestManage.assetRequest.astReqId, //요청PK + QAssetRequestManage.assetRequestManage.astReqMgDate, //요청날짜 + QAssetRequestManage.assetRequestManage.astReqMgStatus, //요청관리 상리 + QUser.user.userName, //요청자 이름 + QUser.user.userId, //요청자 PK + QAssetRequestManage.assetRequestManage.astReqDept, //요청부서 + QAssetRequest.assetRequest.contract.contId + )) + .from(QAssetRequestManage.assetRequestManage) + .join(QAssetRequestManage.assetRequestManage.assetRequest, QAssetRequest.assetRequest) + .join(QAssetRequest.assetRequest.astRequestUser, QUser.user) + .join(QAssetRequest.assetRequest.contract,QContract.contract) + .where(eqAstRequestMangerUser(req.getUserId()) , + findByReqUser(req.getUserName()), + findByReqDept(req.getAstReqDept()), + findByReqMgStatus(req.getAstReqMgStatus()), + UserRequestCond(req.getStart(),req.getEnd())) + .orderBy(QAssetRequest.assetRequest.astReqMgDate.desc()) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .fetch(); + + + Long total = queryFactory + .select(QAssetRequestManage.assetRequestManage.count()) + .from(QAssetRequestManage.assetRequestManage) + .where(eqAstRequestMangerUser(req.getUserId()) , + findByReqUser(req.getUserName()), + findByReqDept(req.getAstReqDept()), + findByReqMgStatus(req.getAstReqMgStatus()), + UserRequestCond(req.getStart(),req.getEnd())) + .fetchOne(); + + System.out.println("total>>"+total); + + + + + return new PageImpl<>(contents,pageable,total); + } + + private BooleanExpression eqAstRequestMangerUser(String userId){ // 요청관리 본인(메니저인사람)으로 검색 + + return QAssetRequestManage.assetRequestManage.assetAdmin.astAdminId.eq(userId); + + } + + private BooleanExpression astRequestUser(String userId){ //요청자가 요청한거 검색 + + return QAssetRequest.assetRequest.astRequestUser.userId.eq(userId); + } + + + private BooleanExpression UserRequestCond(LocalDateTime start, LocalDateTime end){ + + if(start != null){ + if(end == null){ + end = LocalDateTime.now(); + } + start = start.with(LocalTime.of(0, 0, 0)); // 시분초를 0시로 설정 + end = end.with(LocalTime.MAX); // 자정으로 설정 + System.out.println("시간 SET : "+"start : "+start+" end: " + end); + return QAssetRequest.assetRequest.astReqMgDate.between(start,end); + } + + return null; + } + private BooleanExpression findByReqUser(String userName){ + if(userName != null){ + return QAssetRequestManage.assetRequestManage.assetRequest.astRequestUser.userName.eq(userName); //이름 같은사람 + } + + return null; + + } + + private BooleanExpression findByReqDept(String dept){ + if(dept != null){ + return QAssetRequestManage.assetRequestManage.astReqDept.eq(dept); + + } + + return null; + + } + + private BooleanExpression findByReqMgStatus(String status){ + if(status != null){ + return QAssetRequestManage.assetRequestManage.astReqMgStatus.eq(RequestMangeStatus.valueOf(status)); + } + + return null; + + } + + + + + + + @Override + public List test(String userId) { + QAssetRequest assetRequest = QAssetRequest.assetRequest; + return queryFactory.selectFrom(assetRequest) + .where(assetRequest.astRequestUser.userId.eq(userId)) + .fetch(); + +// AssetRequest c = queryFactory +// .selectFrom() +// .where(QAssetRequest.assetRequest.astRequestUser.userId.eq(userId)) +// .limit(1L) +// .fetchOne(); + + + +// return c; + } +} diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/UserAssetRequestInfoRepository.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/UserAssetRequestInfoRepository.java index 62cc135..3c67688 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/UserAssetRequestInfoRepository.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/repository/UserAssetRequestInfoRepository.java @@ -2,12 +2,13 @@ import com.kbds.itamserveradmin.domain.assetRequest.entity.UserAssetRequestInfo; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import java.util.List; - +@Repository public interface UserAssetRequestInfoRepository extends JpaRepository { UserAssetRequestInfo findByAssetRequest_AstReqId(String astReqId); diff --git a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/service/AssetRequestService.java b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/service/AssetRequestService.java index fb2e7a0..e839d81 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/service/AssetRequestService.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/assetRequest/service/AssetRequestService.java @@ -1,6 +1,26 @@ package com.kbds.itamserveradmin.domain.assetRequest.service; +import com.kbds.itamserveradmin.domain.assetRequest.dto.*; +import com.kbds.itamserveradmin.domain.assetRequest.entity.*; +import com.kbds.itamserveradmin.domain.assetRequest.repository.AssetRequestLogRepository; +import com.kbds.itamserveradmin.domain.assetRequest.repository.AssetRequestManageLogRepository; +import com.kbds.itamserveradmin.domain.assetRequest.repository.AssetRequestManageRepository; +import com.kbds.itamserveradmin.domain.assetRequest.repository.AssetRequestRepository; +import com.kbds.itamserveradmin.domain.contract.entity.Contract; +import com.kbds.itamserveradmin.domain.contract.entity.OpStatus; +import com.kbds.itamserveradmin.domain.contract.repository.ContractRepository; +import com.kbds.itamserveradmin.domain.contract.service.ContractService; +import com.kbds.itamserveradmin.domain.user.dto.AssetAdminList; +import com.kbds.itamserveradmin.domain.user.dto.AssetAdminListRes; +import com.kbds.itamserveradmin.domain.user.entity.User; +import com.kbds.itamserveradmin.domain.user.repository.AssetAdminRepository; +import com.kbds.itamserveradmin.domain.user.service.UserService; +import com.kbds.itamserveradmin.global.exception.BaseException; +import com.kbds.itamserveradmin.global.exception.ErrorCode; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import com.kbds.itamserveradmin.domain.assetRequest.entity.AssetRequest; import com.kbds.itamserveradmin.domain.assetRequest.repository.AssetRequestRepository; import lombok.RequiredArgsConstructor; @@ -8,7 +28,14 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; @Slf4j @Service @@ -16,10 +43,30 @@ @RequiredArgsConstructor public class AssetRequestService { - private final AssetRequestRepository astReqRepository; + private final AssetRequestManageRepository assetRequestManageRepository; + private final AssetRequestRepository assetRequestRepository; + private final ContractRepository contractRepository; +// private final ContractService contractService; + private final UserService userService; + private final AssetAdminRepository assetAdminRepository; + private final AssetRequestLogRepository assetRequestLogRepository; + private final AssetRequestManageLogRepository assetRequestManageLogRepository; + + +// @Autowired +// public AssetRequestService(AssetRequestManageRepository assetRequestManageRepository, AssetRequestRepository assetRequestRepository, ContractRepository contractRepository, ContractService contractService, UserService userService, AssetAdminRepository assetAdminRepository, AssetRequestLogRepository assetRequestLogRepository, AssetRequestManageLogRepository assetRequestManageLogRepository) { +// this.assetRequestManageRepository = assetRequestManageRepository; +// this.assetRequestRepository = assetRequestRepository; +// this.contractRepository = contractRepository; +// this.contractService = contractService; +// this.userService = userService; +// this.assetAdminRepository = assetAdminRepository; +// this.assetRequestLogRepository = assetRequestLogRepository; +// this.assetRequestManageLogRepository = assetRequestManageLogRepository; +// } public String getAstReqIdByUserIdAndContId(String userId, String contId) { - List astReqs = astReqRepository.findByAstRequestUserUserId(userId); + List astReqs = assetRequestRepository.findByAstRequestUserUserId(userId); // astReqs에서 contId 값과 같은 astReq 객체의 astReqId 값을 리턴 (결과는 한 개만 나온다고 가정함. 그래서 List이 아님) return astReqs.stream() .filter(astReq -> astReq.getContract() != null && contId.equals(astReq.getContract().getContId())) @@ -29,4 +76,334 @@ public String getAstReqIdByUserIdAndContId(String userId, String contId) { } + public AssetRequest findAssetRequestByUserIdAndContId(String userId, String contId) { + List astReqs = assetRequestRepository.findByAstRequestUserUserId(userId); + Optional matchedAstReq = astReqs.stream() + .filter(astReq -> astReq.getContract() != null && contId.equals(astReq.getContract().getContId())) + .findFirst(); + + return matchedAstReq.orElse(null); + } + + + + /** + * @note : asset(contId로 식별)을 관리하는 관리자 LIST 호출. + * @param conId + * @return count( 몇 명 ), data ( 관리자 정보 List ) + */ + public AssetAdminListRes getAssetAdminList(String conId){ + + List astadminList = (List) assetAdminRepository.getAssetAdminList(conId); +// for(AssetAdminList aa : astadminList){ +// System.out.println(aa.getDept_name()); +// } + return AssetAdminListRes.of(astadminList.size(),astadminList); + } + + + /** + * * + * @param contId + * @param req + * @return + */ + public AssetRequestRes RequestAsset(String dept, String contId, + AssetRequestReq req){ + + + //사용자 있음? + User user = userService.getUser(req.getUserId()); + + //계약존재? + //Contract contract = contractService.getContract(contId); + Contract contract = contractRepository.findById(contId).orElseThrow( + () -> new BaseException(ErrorCode.NOT_FIND_CONTRACT) ); + + + //운영중인 계약? + if(contract.getContOpStatus() != OpStatus.IN_OPERATION ){ + throw new BaseException(ErrorCode.CONTRACT_IS_NOT_IN_OPERATION); + } + + + //운영중인 계약임. 신청 가능함. + //신청 진행 + AssetRequest astReq = AssetRequest.builder() + .astReqId(UUID.randomUUID().toString()) + .astReqReason(req.getAstReqReason()) + .astReqStartDate(req.getAstReqStartDate().atStartOfDay()) + .astReqEndDate(req.getAstReqEndDate().atStartOfDay()) + .astReqStatus(RequestStatus.APPROVAL_WAIT) + .astRequestUser(user) + .contract(contract) + .build(); + + AssetRequest astSaved = assetRequestRepository.save(astReq); + + //자산 요청 로그 저장 + saveAssetRequestLog(req.getAstName(),req.getAstVer(),astSaved,user); + + + List astReqMgIdList = new ArrayList<>(); + //신청 완료되면 자산 요청관리에 넣어줌. + for(String astAdmin : req.getAssetAdminList()){ + + AssetRequestManage astReqMg = AssetRequestManage.builder() + .astReqMgId(UUID.randomUUID().toString()) + .astReqMgStatus(RequestMangeStatus.APPROVAL_WAIT) + .astReqDept(dept) + .astReqName(req.getAstName()) + .assetAdmin(assetAdminRepository.getById(astAdmin)) + .assetRequest(astSaved) + .build(); + + AssetRequestManage savedAstMg = assetRequestManageRepository.save(astReqMg); + astReqMgIdList.add(savedAstMg.getAstReqMgId()); + //자산 요청 관리 로그 저장 + saveAssetRequestMangeLog(savedAstMg); + + } + + + + + + return AssetRequestRes.of(astReq.getAstReqId(), astReqMgIdList); + + } + + + + public void saveAssetRequestLog(String astName, String reqver, AssetRequest req, User user){ + AssetRequestLog astLog = AssetRequestLog.builder() + .astReqLogId(UUID.randomUUID().toString()) + .astReqLogStatus(req.getAstReqStatus()) + .astReqVer(reqver) + .astReqName(astName) + .astReqCnt(0L) + .assetRequest(req) + .assetRequestUser(user).build(); + + + try{ + assetRequestLogRepository.save(astLog); + }catch (Exception e){ + throw new BaseException(ErrorCode.FAIL_SAVED_ASSETREQUESTLOG); + } + + + + } + + + public void saveAssetRequestMangeLog(AssetRequestManage savedAstMg){ + + AssetRequestManageLog astReqMgLog= AssetRequestManageLog.builder() + .astReqMgLogId(UUID.randomUUID().toString()) + .astReqMgLogStatus(savedAstMg.getAstReqMgStatus()) + .astReqName(savedAstMg.getAstReqName()) + .assetRequestManage(savedAstMg) + .build(); + + try{ + assetRequestManageLogRepository.save(astReqMgLog); + }catch (Exception e){ + throw new BaseException(ErrorCode.FAIL_SAVED_ASSETREQUESTMGLOG); + } + + + } + + public Page userRequestSearch(AstReqSearchReq req, Pageable pageable){ + System.out.println("====서비스 ====="); + Page t= assetRequestRepository.search(req,pageable); + return t; + + } + + public Page searchForAdmin(AstReqSearchForAdminReq req, Pageable pageable){ + System.out.println("====서비스 ====="); + + + Page t= assetRequestRepository.searchForAdmin(req,pageable); + + return t; + + } + + + +// +// public AstReqDetailRes getAstReqDetatils(String astReqId, String userId){ +// System.out.println("zzzzz"); +// List e = assetRequestManageRepository.findByAstReqIdWithAssetRequest(astReqId); +// System.out.println(e.size()); +// System.out.println(e.toString()); +// System.out.println("====1==="); +// List admins = e.stream() +// .map(o -> new AstReqAdminList(o)) +// .collect(Collectors.toList()); +// System.out.println(admins.size()); +// +// System.out.println("====2==="); +// +// +// +// +// +// AssetRequest astreq = e.get(0).getAssetRequest(); +// String astReqName = e.get(0).getAstReqName(); +// String requestStatus = astreq.getAstReqStatus().getValue(); +// LocalDateTime astReqStartDate = astreq.getAstReqStartDate(); +// LocalDateTime astReqEndDate =astreq.getAstReqEndDate(); +// String astReqReason = astreq.getAstReqReason(); +// +// System.out.println("====3==="); +// +// User user = userService.getUser(userId); +// +// System.out.println("====4==="); +// +// +// +// +// +// AstReqDetailRes res = AstReqDetailRes.of(astReqName,requestStatus,astReqStartDate,astReqEndDate,astReqReason,user,admins); +// +// System.out.println("====5==="); +// +// +// return res; +// +// +// } + + + public AstReqDetailRes getAstReqDetatils(String astReqId, String userId){ + System.out.println("===1==="); + + List e = assetRequestManageRepository.findByAstReqId(astReqId); + System.out.println(e.size()); + System.out.println("===2==="); + + List admins = e.stream() + .map(o -> new AstReqAdminList(o)) + .collect(Collectors.toList()); + + System.out.println(admins.size()); + System.out.println("===3==="); + + + + + AssetRequest astreq = e.get(0).getAssetRequest(); + System.out.println(astreq.getAstReqId()); + System.out.println("===4==="); + + String astReqName = e.get(0).getAstReqName(); + + System.out.println(astReqName); + System.out.println("===4==="); + + + String requestStatus = astreq.getAstReqStatus().getValue(); + + System.out.println(requestStatus); + System.out.println("===5==="); + LocalDateTime astReqStartDate = astreq.getAstReqStartDate(); + LocalDateTime astReqEndDate =astreq.getAstReqEndDate(); + + System.out.println(astReqStartDate); + System.out.println("===6==="); + String astReqReason = astreq.getAstReqReason(); + + System.out.println(astReqReason); + System.out.println("===7==="); + User user = userService.getUser(userId); + + System.out.println(user.getUserName()); + System.out.println("===8-=="); + + + + + AstReqDetailRes res = AstReqDetailRes.of(astReqName,requestStatus,astReqStartDate,astReqEndDate,astReqReason,user,admins); + + + + return res; + + + } + + public AstReqDetailForAdminRes getAstReqDetatilsForAdmin(String astReqMgId, String userId){ + + AssetRequestManage e = assetRequestManageRepository.findByAstReqMgId(astReqMgId); + + + AstReqDetailForAdminRes t = null; + + + + + + return t; + } + + + public void updateUserRequestStatus(String astReqId){ + //변경 가능한지에 대한 유효성 검사 + + //변경 가능하다면 변경 시작 + AssetRequest assetRequest = assetRequestRepository.findById(astReqId).orElseThrow( + ()-> new BaseException(ErrorCode.INTERNAL_SERVER_ERROR) + ); + + if(assetRequest.getAstReqStatus() != RequestStatus.APPROVAL_WAIT){ + new BaseException(ErrorCode.INTERNAL_SERVER_ERROR); //변경불가 + } + + assetRequest.setAstReqStatus(RequestStatus.CANCEL); + + + } + + public AstReqStatusUpdateRes saveLogUpdateUserRequestStatus(String astReqID, RequestStatus status){ + + //로그 가져와서~ + AssetRequestLog recent = assetRequestLogRepository.getRecentLog(astReqID); + +// String PK = recent.getAstReqLogId().charAt(recent.getAstReqLogId().length() - 1) + + //002 하드 코딩 하면 안됨..PK 바꾸는 로직 추가하면 바뀔 예정.. + AssetRequestLog astLog = AssetRequestLog.builder() + .astReqLogId(recent.getAstReqLogId()+"002") + .astReqLogStatus(status) + .astReqVer(recent.getAstReqVer()) + .astReqName(recent.getAstReqName()) + .astReqCnt(0L) + .assetRequest(recent.getAssetRequest()) + .assetRequestUser(recent.getAssetRequestUser()).build(); + + AssetRequestLog saved = null; + + try{ + saved = assetRequestLogRepository.save(astLog); + }catch (Exception e){ + throw new BaseException(ErrorCode.FAIL_SAVED_ASSETREQUESTLOG); + } + + + return AstReqStatusUpdateRes.of(saved.getAstReqLogId(),astReqID, saved.getAstReqLogStatus()); + + + } + + + + + + + } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/contract/controller/ContractController.java b/src/main/java/com/kbds/itamserveradmin/domain/contract/controller/ContractController.java index 891a27e..04ad403 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/contract/controller/ContractController.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/contract/controller/ContractController.java @@ -1,6 +1,7 @@ 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; @@ -8,40 +9,88 @@ 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.PASSWORD_INCORRECT; +import static com.kbds.itamserveradmin.global.exception.ErrorCode.*; import static org.springframework.http.ResponseEntity.ok; @Slf4j @RestController @RequiredArgsConstructor +@CrossOrigin(origins ="*", allowedHeaders = "*") public class ContractController { private final ContractService contractService; @GetMapping("/kbitam/{dept}/{contId}/dashboard") - public ResponseEntity getDashboard( + public ResponseEntity getDashboard( @PathVariable String dept, @PathVariable String contId, @RequestHeader String userId) { - DashBoardRes dashBoardRes = contractService.createDashBoard(contId, userId); - return ok(dashBoardRes); + try { + DashBoardRes dashBoardRes = contractService.createDashBoard(contId, userId); + return ok(dashBoardRes); + } catch (IllegalArgumentException e) { + // CONTRACT_NOT_FOUND 예외 처리 + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage()); + } } + @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())) { - CalKeyRes calKey = contractService.getCalKey(userId, contId); - return ResponseEntity.ok(calKey); - } else { - return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(PASSWORD_INCORRECT); + if (!correctPw.equals(pwReq.getPw())) { + return ResponseEntity.ok(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 expire( + @PathVariable String dept, + @PathVariable String contId, + @RequestHeader String userId) { + try { + ContExpireRes contExpireRes = contractService.getExpireInfo(contId, userId); + return ResponseEntity.ok(contExpireRes); + } catch (IllegalStateException e) { + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage()); } + } + // @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, + @RequestHeader String userId) { + try { + contractService.stopContract(contId, userId); + 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(ASSET_IS_NOT_INUSE); + } } + + } + diff --git a/src/main/java/com/kbds/itamserveradmin/domain/contract/dto/DashBoardRes.java b/src/main/java/com/kbds/itamserveradmin/domain/contract/dto/DashBoardRes.java index a144d2b..f5db1b4 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/contract/dto/DashBoardRes.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/contract/dto/DashBoardRes.java @@ -12,7 +12,7 @@ @Builder public class DashBoardRes { - private String contName; + private String astName; /** * 라이선스 이름 리스트 @@ -27,4 +27,4 @@ public class DashBoardRes { -} +} \ No newline at end of file diff --git a/src/main/java/com/kbds/itamserveradmin/domain/contract/service/ContractService.java b/src/main/java/com/kbds/itamserveradmin/domain/contract/service/ContractService.java index 3dc2c14..13af44a 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/contract/service/ContractService.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/contract/service/ContractService.java @@ -1,46 +1,58 @@ package com.kbds.itamserveradmin.domain.contract.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.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 com.kbds.itamserveradmin.global.exception.BaseException; +import com.kbds.itamserveradmin.global.exception.ErrorCode; 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.global.exception.ErrorCode.CONTRACT_NOT_FOUND; +import static com.kbds.itamserveradmin.global.exception.ErrorCode.*; @Slf4j @Service @Transactional @RequiredArgsConstructor + public class ContractService { private final ContractRepository contractRepository; + private final AssetRepository assetRepository; private final SupplyTypeRepository supplyTypeRepository; private final PeriodTypeRepository periodTypeRepository; private final NumOfUsersTypeRepository numOfUsersTypeRepository; - private final AssetRequestRepository assetRequestRepository; private final UserAssetRequestInfoRepository userAssetRequestInfoRepository; private final AssetRequestService assetRequestService; + public Contract getContract(String contId){ + return contractRepository.findById(contId).orElseThrow( + () -> new BaseException(ErrorCode.NOT_FIND_CONTRACT) ); + } + + + public static List parseContLicTag(String contLicTag) { // 분류별 의미를 저장하는 맵 정의 Map supplyTypes = Map.of( @@ -79,13 +91,28 @@ public static List parseContLicTag(String contLicTag) { return licenseTypes; } //Ast id 찾는 메서드 - public Asset getAstIdByContId(String contId){ - Contract contract = contractRepository.findByContId(contId); + + +// public Asset getAstIdByContId(String contId){ +// Contract contract = contractRepository.findById(contId) +// .orElseThrow(() -> new IllegalArgumentException(String.valueOf(CONTRACT_NOT_FOUND))); +// if (contract == null){ +// return null; +// } +// return contract.getAst(); +// } + + //Ast id 찾는 메서드 + + public Asset findAstIdByContId(String contId){ + Contract contract = contractRepository.findById(contId) + .orElseThrow(() -> new IllegalArgumentException(String.valueOf(CONTRACT_NOT_FOUND))); if (contract == null){ return null; } return contract.getAst(); } + /** * DashBoard에 보여줄 데이터 가져오는 메서드 * @param contId @@ -97,6 +124,9 @@ public DashBoardRes createDashBoard(String contId, String userId) { Contract findContract = contractRepository.findById(contId) .orElseThrow(() -> new IllegalArgumentException(String.valueOf(CONTRACT_NOT_FOUND))); + String astName = findContract.getAst().getAstName(); + log.info("astName" + astName); + System.out.println("[asset name] " + astName); // 2. Contract.contLicTag 값 파싱 List licNames = parseContLicTag(findContract.getContLicTag()); @@ -119,12 +149,10 @@ public DashBoardRes createDashBoard(String contId, String userId) { // 3.2 기간 (1. yml에서 write-dates-as-timestamps: false 로 설정해도 날짜 리스트로 출력) // (2. PeriodType에서 @JsonFormat으로 설정해도 수정 안된다) - 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); + List dateTimeList = getPeriod(contId); + List formattedDate = getFormattedDate(dateTimeList); + licValues.put("contStartDate", formattedDate.get(0)); + licValues.put("contEndDate", formattedDate.get(1)); // 3.3 사용자 @@ -139,7 +167,7 @@ public DashBoardRes createDashBoard(String contId, String userId) { } String astReqId = assetRequestService.getAstReqIdByUserIdAndContId(userId, contId); - System.out.println("[asset_request_id]" + astReqId); +// System.out.println("[asset_request_id]" + astReqId); UserAssetRequestInfo userAstReqInfo = userAssetRequestInfoRepository.findByAssetRequest_AstReqId(astReqId); if (licTag.charAt(2) == '2') { // 사이트 licValues.put("ipRange", numOfUsersType.getIpRange()); @@ -166,7 +194,7 @@ public DashBoardRes createDashBoard(String contId, String userId) { // 4. 찾은 값들을 DashBoardRes에 담아 전달하기 return DashBoardRes.builder() - .contName(findContract.getContName()) + .astName(astName) .licNames(licNames) .licValues(licValues) .build(); @@ -174,6 +202,13 @@ 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); @@ -190,4 +225,64 @@ public CalKeyRes getCalKey(String userId, String contId) { .build(); } -} + public List getPeriod(String contId) { + List period = new ArrayList<>(2); + PeriodType periodType = periodTypeRepository.findByCont_ContId(contId); + period.add(periodType.getContStartDate()); + period.add(periodType.getContEndDate()); + return period; + } + + public List getAstReqPeriod(String contId, String userId) { + List period = new ArrayList<>(2); + AssetRequest assetRequest = assetRequestService.findAssetRequestByUserIdAndContId(userId, contId); + period.add(assetRequest.getAstReqStartDate()); + period.add(assetRequest.getAstReqEndDate()); + return period; + } + + public List getFormattedDate(List 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 formatted = new ArrayList<>(); + formatted.add(formattedStartDate); + formatted.add(formattedEndDate); + return formatted; + } + + public ContExpireRes getExpireInfo(String contId, String userId) { + AssetRequest assetRequest = assetRequestService.findAssetRequestByUserIdAndContId(userId, contId); + if (assetRequest.getAstReqStatus() != RequestStatus.IN_USE) { + if (assetRequest.getAstReqStatus() == RequestStatus.EXPIRED) { + throw new IllegalStateException(String.valueOf(ASSET_IS_EXPIRE)); + } + throw new IllegalStateException(String.valueOf(ASSET_IS_NOT_INUSE)); + } + + + + List period = getAstReqPeriod(contId, userId); + List 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, String userId) { + AssetRequest assetRequest = assetRequestService.findAssetRequestByUserIdAndContId(userId, contId); + + if (assetRequest.getAstReqStatus() == RequestStatus.IN_USE) { + assetRequest.setAstReqStatus(RequestStatus.EXPIRED); + } else { + throw new IllegalStateException(String.valueOf(ASSET_IS_NOT_INUSE)); + } + } + +} \ No newline at end of file diff --git a/src/main/java/com/kbds/itamserveradmin/domain/corporation/entity/CorpPK.java b/src/main/java/com/kbds/itamserveradmin/domain/corporation/entity/CorpPK.java new file mode 100644 index 0000000..0cebe68 --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/corporation/entity/CorpPK.java @@ -0,0 +1,27 @@ +package com.kbds.itamserveradmin.domain.corporation.entity; + +import com.fasterxml.jackson.annotation.JsonValue; +import lombok.AllArgsConstructor; +import lombok.Getter; + + +@AllArgsConstructor +@Getter +public enum CorpPK { + + BNK("국민은행"), + CRD("국민카드"), + ISR("손해보험"), + STK("증권"), + LIF("라이프"), + ASM("자산운용"), + CAP("캐피탈"), + RET("부동산신탁"), + SAV("저축은행"), + INV("인베스트먼트"), + DAS("데이타시스템"); + + + @JsonValue + private final String name; +} 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 a0b6253..180a467 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 @@ -2,7 +2,10 @@ import com.kbds.itamserveradmin.domain.corporation.entity.Corporation; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository public interface CorporationRepository extends JpaRepository { Corporation findCorporationByCorpName(String CorpName); diff --git a/src/main/java/com/kbds/itamserveradmin/domain/department/entity/Department.java b/src/main/java/com/kbds/itamserveradmin/domain/department/entity/Department.java index 8b65b28..71feed9 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/department/entity/Department.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/department/entity/Department.java @@ -18,6 +18,8 @@ @AllArgsConstructor @Builder public class Department { + + @Id @Column(name = "dept_id") private String deptId; @@ -31,5 +33,24 @@ public class Department { @JoinColumn(name = "corp_id") private Corporation corporation; +// +// +// @Id +// @Column(name = "dept_id") +// @Enumerated(EnumType.STRING) +// private DeptPK deptId; +// +// @Column(name = "dept_name") +// private String deptName; +// +// +// //==연관관계==// +// +// @ManyToOne(fetch = FetchType.LAZY) +// @JoinColumn(name = "corp_id") +// private Corporation corporation; + //==연관관계==// + + } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/department/entity/DeptPK.java b/src/main/java/com/kbds/itamserveradmin/domain/department/entity/DeptPK.java new file mode 100644 index 0000000..5a4a6c8 --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/department/entity/DeptPK.java @@ -0,0 +1,22 @@ +package com.kbds.itamserveradmin.domain.department.entity; + + +import com.fasterxml.jackson.annotation.JsonValue; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +@Getter +public enum DeptPK { + + DNB("디지털신사업부"), + RCP("수신상품부"), + GBP("글로벌플랫폼부"), + CSD("고객만족부"), + ESD("직원만족부"); + + + @JsonValue + private final String name; + +} 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 1fa1100..f648d50 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 @@ -10,6 +10,7 @@ @RestController @Slf4j @RequiredArgsConstructor +@CrossOrigin(origins ="*", allowedHeaders = "*") @RequestMapping("/kbitam") @CrossOrigin(origins ="*", allowedHeaders = "*") public class UserController { diff --git a/src/main/java/com/kbds/itamserveradmin/domain/user/dto/AssetAdminList.java b/src/main/java/com/kbds/itamserveradmin/domain/user/dto/AssetAdminList.java new file mode 100644 index 0000000..44c08e2 --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/user/dto/AssetAdminList.java @@ -0,0 +1,48 @@ +package com.kbds.itamserveradmin.domain.user.dto; + + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.ColumnResult; +import javax.persistence.ConstructorResult; +import javax.persistence.SqlResultSetMapping; + + +//@NoArgsConstructor +//@AllArgsConstructor + +public interface AssetAdminList { + +// private String ast_admin_id; //관리자id +// private String user_name; //유저이름 +// private String user_id; //유저 사번 +// private String dept_name; //부서 이름 +// private String user_role; //유저 직급 + + String getAst_admin_id(); + String getUser_name(); + String getUser_id(); + String getDept_name(); + String getUser_role(); +// public String getAst_admin_id() { +// return ast_admin_id; +// } +// +// public String getUser_name() { +// return user_name; +// } +// +// public String getUser_id() { +// return user_id; +// } +// +// public String getDept_name() { +// return dept_name; +// } +// +// public String getUser_role() { +// return user_role; +// } +} diff --git a/src/main/java/com/kbds/itamserveradmin/domain/user/dto/AssetAdminListRes.java b/src/main/java/com/kbds/itamserveradmin/domain/user/dto/AssetAdminListRes.java new file mode 100644 index 0000000..88795a6 --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/user/dto/AssetAdminListRes.java @@ -0,0 +1,33 @@ +package com.kbds.itamserveradmin.domain.user.dto; + + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + + +@Builder +@Getter +@AllArgsConstructor +@JsonPropertyOrder({"count", "data"}) +public class AssetAdminListRes { + private int count; + @JsonInclude(JsonInclude.Include.NON_NULL) + private T data; // 리스트의 값 + + // 정적 팩토리 메서드 + public static AssetAdminListRes of(int count, T data) { + return AssetAdminListRes.builder() + .count(count) + .data(data) + .build(); + } + +} + diff --git a/src/main/java/com/kbds/itamserveradmin/domain/user/entity/User.java b/src/main/java/com/kbds/itamserveradmin/domain/user/entity/User.java index 36ab604..dca035c 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/user/entity/User.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/user/entity/User.java @@ -8,15 +8,13 @@ import com.kbds.itamserveradmin.domain.corporation.entity.Corporation; import com.kbds.itamserveradmin.domain.department.entity.Department; import com.kbds.itamserveradmin.global.entity.BaseEntity; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; import javax.persistence.*; import java.util.ArrayList; import java.util.List; +@EqualsAndHashCode(callSuper = true) @Entity @Data @NoArgsConstructor @@ -52,4 +50,7 @@ public class User extends BaseEntity { @JoinColumn(name = "corp_id") private Corporation corporation; + + + } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/user/repository/AssetAdminRepository.java b/src/main/java/com/kbds/itamserveradmin/domain/user/repository/AssetAdminRepository.java index f88190c..7b711d1 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/user/repository/AssetAdminRepository.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/user/repository/AssetAdminRepository.java @@ -1,7 +1,25 @@ package com.kbds.itamserveradmin.domain.user.repository; +import com.kbds.itamserveradmin.domain.user.dto.AssetAdminList; import com.kbds.itamserveradmin.domain.user.entity.AssetAdmin; 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 AssetAdminRepository extends JpaRepository { + + + + @Query( + value = "SELECT ast_admin_id, user_name, user_id, dept_name, user_role \n" + + "FROM asset_admin\n" + + "LEFT JOIN user u on asset_admin.manager_id = u.user_id\n" + + "LEFT JOIN department d on u.dept_id = d.dept_id\n" + + "where cont_id = :cont_id", nativeQuery = true) + public List getAssetAdminList(@Param("cont_id")String cont_id); + + + } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/user/service/UserService.java b/src/main/java/com/kbds/itamserveradmin/domain/user/service/UserService.java index 37ddaf6..5981dd8 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/user/service/UserService.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/user/service/UserService.java @@ -1,7 +1,43 @@ package com.kbds.itamserveradmin.domain.user.service; +import com.kbds.itamserveradmin.domain.department.entity.Department; +import com.kbds.itamserveradmin.domain.department.repository.DepartmentRepository; import com.kbds.itamserveradmin.domain.user.dto.UserInfoRes; +import com.kbds.itamserveradmin.domain.user.entity.User; +import com.kbds.itamserveradmin.domain.user.entity.UserRole; +import com.kbds.itamserveradmin.domain.user.repository.UserRepository; +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.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; -public interface UserService { - public UserInfoRes GetUserInfo(String userId); +@Service +@Transactional +@RequiredArgsConstructor +@Slf4j +public class UserService { + + + private final UserRepository userRepository; + + + public UserInfoRes GetUserInfo(String userId) { + log.info("userId : {}", userId); + UserInfoRes userInfoRes = userRepository.findUserInfoWithCooperationAndDepartmentByUserId(userId); + log.info(userInfoRes.toString()); + return userInfoRes; + } + + + + public User getUser(String userId){ + return userRepository.findById(userId).orElseThrow( + () -> new BaseException(ErrorCode.NOT_FIND_USER) ); + } } + + + diff --git a/src/main/java/com/kbds/itamserveradmin/domain/user/service/UserServiceImpl.java b/src/main/java/com/kbds/itamserveradmin/domain/user/service/UserServiceImpl.java index d1bfa14..e69de29 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/user/service/UserServiceImpl.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/user/service/UserServiceImpl.java @@ -1,28 +0,0 @@ -package com.kbds.itamserveradmin.domain.user.service; - -import com.kbds.itamserveradmin.domain.department.entity.Department; -import com.kbds.itamserveradmin.domain.department.repository.DepartmentRepository; -import com.kbds.itamserveradmin.domain.user.dto.UserInfoRes; -import com.kbds.itamserveradmin.domain.user.entity.User; -import com.kbds.itamserveradmin.domain.user.entity.UserRole; -import com.kbds.itamserveradmin.domain.user.repository.UserRepository; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -@Service -@Slf4j -@RequiredArgsConstructor -public class UserServiceImpl implements UserService { - - private final UserRepository userRepository; - - @Override - public UserInfoRes GetUserInfo(String userId) { - log.info("userId : {}", userId); - UserInfoRes userInfoRes = userRepository.findUserInfoWithCooperationAndDepartmentByUserId(userId); - log.info(userInfoRes.toString()); - return userInfoRes; - } -} \ No newline at end of file diff --git a/src/main/java/com/kbds/itamserveradmin/global/exception/ErrorCode.java b/src/main/java/com/kbds/itamserveradmin/global/exception/ErrorCode.java index 630776d..c0dabea 100644 --- a/src/main/java/com/kbds/itamserveradmin/global/exception/ErrorCode.java +++ b/src/main/java/com/kbds/itamserveradmin/global/exception/ErrorCode.java @@ -10,15 +10,31 @@ @Getter public enum ErrorCode { + //user + NOT_FIND_USER(HttpStatus.BAD_REQUEST,"U-001","사용자를 찾을 수 없습니다."), + // contract CONTRACT_RECORD_TYPE_NOT_FOUND(HttpStatus.NOT_FOUND, "C-001", "활동 기록 타입을 찾을 수 없습니다."), CONTRACT_NOT_FOUND(HttpStatus.NOT_FOUND, "C-002", "해당 계약을 찾을 수 없습니다."), - + CONTRACT_IS_NOT_CAL_LIC(HttpStatus.FORBIDDEN, "C-003", "해당 계약은 cal 라이선스가 아닙니다."), + NOT_FIND_CONTRACT(HttpStatus.BAD_REQUEST,"C-004","계약을 찾을 수 없습니다."), + CONTRACT_IS_NOT_IN_OPERATION(HttpStatus.BAD_REQUEST,"C-005","운영중인 자산이 아닙니다."), + + //Log + FAIL_SAVED_ASSETREQUESTLOG(HttpStatus.INTERNAL_SERVER_ERROR,"L-001","자산 요청 로그 저장 실패"), + FAIL_SAVED_ASSETREQUESTMGLOG(HttpStatus.INTERNAL_SERVER_ERROR,"L-002","자산 요청 관리 로그 저장 실패"), + + //기타 INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "I-001", "내부 에러가 발생했습니다."), // cal key 조회를 위한 pw - PASSWORD_INCORRECT(HttpStatus.UNAUTHORIZED, "P-001", "비밀번호가 틀립니다."); + PASSWORD_INCORRECT(HttpStatus.UNAUTHORIZED, "P-001", "비밀번호가 틀립니다."), + + // asset + ASSET_IS_NOT_INUSE(HttpStatus.CONFLICT, "A-001", "사용중인 상태가 아닙니다."), + ASSET_IS_EXPIRE(HttpStatus.FORBIDDEN, "A-002", "사용이 만료되었습니다."); + diff --git a/src/main/java/com/kbds/itamserveradmin/global/file/CustomPdfView.java b/src/main/java/com/kbds/itamserveradmin/global/file/CustomPdfView.java new file mode 100644 index 0000000..0a5b02a --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/global/file/CustomPdfView.java @@ -0,0 +1,31 @@ +package com.kbds.itamserveradmin.global.file; + +import org.springframework.web.servlet.view.document.AbstractPdfView; + +import java.util.Map; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +//import com.lowagie.text.Chapter; +//import com.lowagie.text.Document; +//import com.lowagie.text.Paragraph; +//import com.lowagie.text.pdf.PdfWriter; +// +////pdf 파일을 보여주는 view로 만들기위해 extends +//public class CustomPdfView extends AbstractPdfView { +// +// @Override +// protected void buildPdfDocument(Map model, +// Document document, PdfWriter writer, +// HttpServletRequest request, +// HttpServletResponse response) throws Exception { +// +// +// Chapter chapter = new Chapter(new Paragraph("Spring Message"),1); +// chapter.add(new Paragraph((String)model.get("message"))); // +// +// document.add(chapter); +// +// } +// +//} \ No newline at end of file diff --git a/src/main/java/com/kbds/itamserveradmin/global/file/FileController.java b/src/main/java/com/kbds/itamserveradmin/global/file/FileController.java new file mode 100644 index 0000000..21a0f70 --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/global/file/FileController.java @@ -0,0 +1,54 @@ +package com.kbds.itamserveradmin.global.file; + +import lombok.AllArgsConstructor; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + + +@RestController +@Log4j2 +public class FileController { + @Autowired + private FileUploadService fileUploadService; + + @Value("${file.dir}") // application 의 properties 의 변수 + private String uploadPath; + + + @PostMapping("/upload") + public ResponseEntity> upload (@RequestParam("files") MultipartFile[] files) { + List resultDTOList = new ArrayList<>(); + if (files == null || files.length == 0) { + return ResponseEntity.badRequest().build(); + } + + for (MultipartFile file : files) { + if (file.isEmpty()) { + continue; + } + + try { + String filePath = fileUploadService.saveFile(file); // 파일 업로드 후 경로 반환 + resultDTOList.add(new UploadResultDTO(file.getOriginalFilename(), filePath)); // 파일 이름과 경로 추가 + } catch (IOException e) { + log.error("Failed to upload file", e); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); // 업로드 실패 시 500 에러 반환 + } + } + + return ResponseEntity.ok(resultDTOList); + } +} diff --git a/src/main/java/com/kbds/itamserveradmin/global/file/FileService.java b/src/main/java/com/kbds/itamserveradmin/global/file/FileService.java new file mode 100644 index 0000000..1911f49 --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/global/file/FileService.java @@ -0,0 +1,36 @@ +package com.kbds.itamserveradmin.global.file; + +import com.kbds.itamserveradmin.domain.asset.repository.ManualLogRepository; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +@Service +public class FileService { +// +// private ManualLogRepository manualLogRepository; +// private MultipartFile multipartFile; +// +// String originalFilename = multipartFile.getOriginalFilename(); +// String saveFileName = createSaveFileName(originalFilename); +// +// @Value("${file.dir}") +// private String uploadPath; +//// 2-1.서버에 파일 저장 +//multipartFile.transferTo(new File(getFullPath(saveFileName))); +// +// // 2-2. DB에 정보 저장 +// String contentType = multipartFile.getContentType(); +// +// FileInfoRegister fileInfoRegister = FileInfoRegister.builder() +// .fileName(originalFilename) +// .saveFileName(saveFileName) +// .contentType(contentType) +// .deleteFlag(notDeleted).build(); +// +// int fileInfoId = fileInfoDao.insert(fileInfoRegister); +// public store(){ +// +// } + +} diff --git a/src/main/java/com/kbds/itamserveradmin/global/file/FileUploadService.java b/src/main/java/com/kbds/itamserveradmin/global/file/FileUploadService.java new file mode 100644 index 0000000..1a5949c --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/global/file/FileUploadService.java @@ -0,0 +1,9 @@ +package com.kbds.itamserveradmin.global.file; + +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; + +public interface FileUploadService { + String saveFile(MultipartFile file) throws IOException; +} diff --git a/src/main/java/com/kbds/itamserveradmin/global/file/FileUploadServiceImpl.java b/src/main/java/com/kbds/itamserveradmin/global/file/FileUploadServiceImpl.java new file mode 100644 index 0000000..53607af --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/global/file/FileUploadServiceImpl.java @@ -0,0 +1,42 @@ +package com.kbds.itamserveradmin.global.file; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.UUID; + +@Service +public class FileUploadServiceImpl implements FileUploadService{ + @Value("${file.dir}") // application의 properties 변수 + private String uploadPath; + + @Override + public String saveFile(MultipartFile file) throws IOException { + if (file == null || file.isEmpty()) { + throw new IllegalArgumentException("File is null or empty"); + } + + String originalName = file.getOriginalFilename(); + assert originalName != null; + String fileName = originalName.substring(originalName.lastIndexOf("\\") + 1); + + String uuid = UUID.randomUUID().toString(); + + String saveName = uploadPath + File.separator + uuid + "_" + fileName; + + Path savePath = Paths.get(saveName); + + try { + file.transferTo(savePath); + } catch (IOException e) { + throw new IOException("Failed to save file", e); + } + + return saveName; + } +} diff --git a/src/main/java/com/kbds/itamserveradmin/global/file/UploadResultDTO.java b/src/main/java/com/kbds/itamserveradmin/global/file/UploadResultDTO.java new file mode 100644 index 0000000..acd69de --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/global/file/UploadResultDTO.java @@ -0,0 +1,21 @@ +package com.kbds.itamserveradmin.global.file; + +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.io.Serializable; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; + +@Data +@AllArgsConstructor +public class UploadResultDTO implements Serializable { + + private String fileName; + private String uuid; + + public String getFileURL() { + return URLEncoder.encode(uuid+"_"+fileName, StandardCharsets.UTF_8); + } + +} \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index a6546b9..0909e3f 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 8080 + port: 9000 servlet: context-path: / encoding: @@ -18,7 +18,7 @@ spring: platform: mysql url: jdbc:mysql://localhost:3306/kbds?serverTimezone=Asia/Seoul&characterEncoding=UTF-8 username: root - password: 1234 + password: smilechs5542 driver-class-name: com.mysql.cj.jdbc.Driver # mysql 8버전 @@ -40,15 +40,19 @@ spring: # turn OSIV off open-in-view: false database: mysql - - + servlet: + multipart: + max-request-size: 500MB + max-file-size: 500MB security: user: name: test password: 1234 +file: + dir: /Users/minizi015/Desktop/images #다들 파일업로드 경로 설정해주세요,,! -#logging: -# level: -# org.hibernate.SQL: debug # 하이버네이트가 생성하는 SQL이 다보인다. -## org.hibernate.type: #binding parameter의 값이 무엇인지를 알려줌. +logging: + level: + org.hibernate.SQL: debug # 하이버네이트가 생성하는 SQL이 다보인다. +# org.hibernate.type: #binding parameter의 값이 무엇인지를 알려줌.