251202_01_ENH: User 관련 기능 구현

This commit is contained in:
2025-12-02 13:46:44 +09:00
parent bff9747d52
commit d13595f315
52 changed files with 1279 additions and 159 deletions

View File

@@ -0,0 +1,119 @@
package com.kri.contact.server.controller;
import com.kri.common.webmvc.RequestUserContext;
import com.kri.contact.server.common.consts.AppConstant;
import com.kri.contact.server.dto.DataVerificationDto;
import com.kri.contact.server.dto.ExcelUploadResponseDto;
import com.kri.contact.server.dto.UserInfoDto;
import com.kri.contact.server.dto.systemlog.UploadUserContentDto;
import com.kri.contact.server.service.SystemEventLogService;
import com.kri.contact.server.service.UserService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.Collections;
import java.util.List;
@RestController
@RequestMapping("/api/v1/user")
@RequiredArgsConstructor
@Tag(name = "User", description = "사용자 관리 API")
public class UserController {
private final UserService userService;
private final SystemEventLogService systemEventLogService;
@GetMapping("/check-user-id")
public DataVerificationDto checkUserId(@RequestParam String userId){
return userService.checkUserId(userId);
}
@GetMapping("/{userId}")
public UserInfoDto getUser(@PathVariable String userId){
return userService.getUser(userId);
}
@GetMapping()
public List<UserInfoDto> getUserList(RequestUserContext ctx){
//내부 직원
if(ctx.getUserRole() < AppConstant.EXTERNAL_USER_ROLE){
return userService.getUserListWithCmpn("");
}
//외주사 이상
return userService.getUserListWithCmpn(ctx.getUserCmpn());
}
@GetMapping("cmpn")
public List<String> getUserCmpnList(RequestUserContext ctx){
if(ctx.getUserRole() < AppConstant.EXTERNAL_USER_ROLE){
return userService.getUserCmpnList();
}
return Collections.emptyList();
}
@PutMapping
public void createUser(@RequestBody UserInfoDto userInfo, RequestUserContext ctx){
String regId = ctx.getUserId();
String clientIp = ctx.getClientIp();
userService.createUser(userInfo, regId);
systemEventLogService.writeCreatUserLog(regId, clientIp, userInfo);
}
@PostMapping("/excel")
public ExcelUploadResponseDto createUserFromExcel(
@RequestPart("file") MultipartFile file,
RequestUserContext ctx
) {
String regId = ctx.getUserId();
String clientIp = ctx.getClientIp();
//외주사급이 업로드로 계정을 생성하는 경우 자신의 회사명으로 고정
String forceCmpn = ctx.getUserRole() < AppConstant.EXTERNAL_USER_ROLE? "" : ctx.getUserCmpn();
ExcelUploadResponseDto result = userService.createUsersFromExcel(file, regId, forceCmpn);
UploadUserContentDto content = new UploadUserContentDto(
file.getOriginalFilename(),
file.getContentType(),
file.getSize()
);
systemEventLogService.writeUploadUserLog(regId, clientIp, content);
return result;
}
@PostMapping("/excel/template")
public ResponseEntity<byte[]> exportUserTemplate(){
byte[] bytes = userService.exportUserTemplate();
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION,
"attachment; filename=\"user_upload_template.xlsx\"")
.contentType(MediaType.parseMediaType(
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))
.body(bytes);
}
@PatchMapping()
public void updateUser(@RequestBody UserInfoDto dto, RequestUserContext ctx){
String modId = ctx.getUserId();
String clientIp = ctx.getClientIp();
userService.updateUser(dto, modId);
systemEventLogService.writeUpdateUserLog(modId, clientIp, dto);
}
@DeleteMapping("/{userId}")
public void deleteUser(@PathVariable String userId, RequestUserContext ctx){
String regId = ctx.getUserId();
String clientIp = ctx.getClientIp();
userService.deleteUser(userId, regId);
systemEventLogService.writeDeleteUserLog(regId, clientIp, userId);
}
}