136 lines
4.8 KiB
Java
136 lines
4.8 KiB
Java
package com.kri.contact.server.controller;
|
|
|
|
import com.kri.common.webmvc.RequestUserContext;
|
|
import com.kri.contact.server.common.consts.ContactConstant;
|
|
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){
|
|
String searchCmpn = ctx.getUserCmpn();
|
|
if(ctx.getUserRole() < ContactConstant.OUTSOURCE_USER_ROLE){
|
|
return userService.getUserList();
|
|
}
|
|
else{
|
|
return userService.getFieldworkUserListWithCmpn(searchCmpn);
|
|
}
|
|
}
|
|
|
|
@GetMapping("fieldwork")
|
|
public List<UserInfoDto> getFiledoworkUserList(RequestUserContext ctx){
|
|
String searchCmpn = ctx.getUserCmpn();
|
|
if(ctx.getUserRole() < ContactConstant.OUTSOURCE_USER_ROLE){
|
|
searchCmpn = "";
|
|
}
|
|
|
|
return userService.getFieldworkUserListWithCmpn(searchCmpn);
|
|
}
|
|
|
|
@GetMapping("outsource")
|
|
List<UserInfoDto> getOutsourceList(){
|
|
return userService.getOutsourceList();
|
|
}
|
|
|
|
@GetMapping("cmpn")
|
|
public List<String> getUserCmpnList(RequestUserContext ctx){
|
|
if(ctx.getUserRole() < ContactConstant.OUTSOURCE_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() < ContactConstant.OUTSOURCE_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);
|
|
}
|
|
}
|