260410_01_ENH: 리스트 업로드, 조회, 삭제 수정 및 Controller 연결
This commit is contained in:
@@ -31,7 +31,7 @@ public enum SystemEventType implements CodeEnum<Short> {
|
|||||||
UPSERT_LIST_HEADER((short) 1011), //리스트 헤더 수정
|
UPSERT_LIST_HEADER((short) 1011), //리스트 헤더 수정
|
||||||
UPLOAD_LIST((short) 1021), //리스트 업로드
|
UPLOAD_LIST((short) 1021), //리스트 업로드
|
||||||
UPDATE_LIST((short) 1022), //리스트 수정
|
UPDATE_LIST((short) 1022), //리스트 수정
|
||||||
DELETE_LIST((short) 1023), //리스트 삭제
|
RESET_LIST((short) 1023), //리스트 삭제
|
||||||
|
|
||||||
DUMMY((short) 9999);
|
DUMMY((short) 9999);
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,18 @@ package com.kri.contact.server.controller;
|
|||||||
import com.kri.common.feature.datetime.DateTimeUtil;
|
import com.kri.common.feature.datetime.DateTimeUtil;
|
||||||
import com.kri.common.feature.web.BusinessException;
|
import com.kri.common.feature.web.BusinessException;
|
||||||
import com.kri.common.feature.web.RequestUserContext;
|
import com.kri.common.feature.web.RequestUserContext;
|
||||||
|
import com.kri.common.feature.web.page.PageResponseDto;
|
||||||
import com.kri.contact.server.dto.excel.ExcelUploadResultDto;
|
import com.kri.contact.server.dto.excel.ExcelUploadResultDto;
|
||||||
|
import com.kri.contact.server.dto.list.ListResetRequestDto;
|
||||||
|
import com.kri.contact.server.dto.list.ListSearchRequestDto;
|
||||||
|
import com.kri.contact.server.dto.list.ListSearchResponseDto;
|
||||||
|
import com.kri.contact.server.dto.list.ListSearchWithResultDto;
|
||||||
|
import com.kri.contact.server.dto.list.ListUpdateRequestDto;
|
||||||
import com.kri.contact.server.dto.list.ListUploadRequestDto;
|
import com.kri.contact.server.dto.list.ListUploadRequestDto;
|
||||||
import com.kri.contact.server.dto.project.ProjectInfoDto;
|
import com.kri.contact.server.dto.project.ProjectInfoDto;
|
||||||
|
import com.kri.contact.server.service.ListResetService;
|
||||||
|
import com.kri.contact.server.service.ListSearchService;
|
||||||
|
import com.kri.contact.server.service.ListUpdateService;
|
||||||
import com.kri.contact.server.service.ListUploadService;
|
import com.kri.contact.server.service.ListUploadService;
|
||||||
import com.kri.contact.server.service.ProjectService;
|
import com.kri.contact.server.service.ProjectService;
|
||||||
import com.kri.contact.server.service.SystemEventLogService;
|
import com.kri.contact.server.service.SystemEventLogService;
|
||||||
@@ -19,8 +28,11 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RequestPart;
|
import org.springframework.web.bind.annotation.RequestPart;
|
||||||
@@ -34,11 +46,32 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
public class ListController {
|
public class ListController {
|
||||||
|
|
||||||
private final ProjectService projectService;
|
private final ProjectService projectService;
|
||||||
|
private final ListSearchService listSearchService;
|
||||||
private final ListUploadService listUploadService;
|
private final ListUploadService listUploadService;
|
||||||
|
private final ListUpdateService listUpdateService;
|
||||||
|
private final ListResetService listResetService;
|
||||||
private final SystemEventLogService systemEventLogService;
|
private final SystemEventLogService systemEventLogService;
|
||||||
|
|
||||||
|
@Operation(summary = "리스트 정보 조회 With Sid")
|
||||||
|
@GetMapping("/search/{prjctIdx}/{sid}")
|
||||||
|
public ListSearchWithResultDto getListSearchWithResult(
|
||||||
|
@PathVariable Long prjctIdx,
|
||||||
|
@PathVariable Integer sid
|
||||||
|
){
|
||||||
|
return listSearchService.getListSearchOne(prjctIdx, sid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "리스트 정보 조회 With Filter")
|
||||||
|
@PostMapping("/search/{prjctIdx}")
|
||||||
|
public PageResponseDto<ListSearchWithResultDto> searchListWithFilter(
|
||||||
|
@PathVariable Long prjctIdx,
|
||||||
|
@Valid @RequestBody ListSearchRequestDto request
|
||||||
|
){
|
||||||
|
return listSearchService.getListSearchWithResultList(prjctIdx, request);
|
||||||
|
}
|
||||||
|
|
||||||
@Operation(summary = "리스트 파일 업로드 양식 다운로드")
|
@Operation(summary = "리스트 파일 업로드 양식 다운로드")
|
||||||
@PostMapping("excel/template/{prjctIdx}")
|
@PostMapping("/excel/template/{prjctIdx}")
|
||||||
public ResponseEntity<byte[]> downloadExcelTemplate(
|
public ResponseEntity<byte[]> downloadExcelTemplate(
|
||||||
@PathVariable Long prjctIdx,
|
@PathVariable Long prjctIdx,
|
||||||
RequestUserContext ctx
|
RequestUserContext ctx
|
||||||
@@ -59,7 +92,7 @@ public class ListController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "리스트 파일 업로드")
|
@Operation(summary = "리스트 파일 업로드")
|
||||||
@PostMapping(value = "excel/upload/{prjctIdx}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
@PostMapping(value = "/excel/upload/{prjctIdx}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
public ExcelUploadResultDto uploadExcel(
|
public ExcelUploadResultDto uploadExcel(
|
||||||
@PathVariable Long prjctIdx,
|
@PathVariable Long prjctIdx,
|
||||||
@RequestParam("file") MultipartFile file,
|
@RequestParam("file") MultipartFile file,
|
||||||
@@ -76,4 +109,33 @@ public class ListController {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "리스트 수정")
|
||||||
|
@PostMapping("/update/{prjctIdx}")
|
||||||
|
public int updateList(
|
||||||
|
@PathVariable Long prjctIdx,
|
||||||
|
@Valid @RequestBody ListUpdateRequestDto request,
|
||||||
|
RequestUserContext ctx) {
|
||||||
|
final LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||||
|
|
||||||
|
int updateCount = listUpdateService.updateList(prjctIdx, request, ctx.getUserRole(), ctx.getUserId(), now);
|
||||||
|
systemEventLogService.writeUpdateList(ctx.getUserId(), now, ctx.getClientIp(), prjctIdx, request);
|
||||||
|
|
||||||
|
return updateCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "리스트 삭제")
|
||||||
|
@DeleteMapping("/{prjctIdx}")
|
||||||
|
public int resetList(
|
||||||
|
@PathVariable Long prjctIdx,
|
||||||
|
@Valid @RequestBody ListResetRequestDto request,
|
||||||
|
RequestUserContext ctx
|
||||||
|
){
|
||||||
|
final LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||||
|
|
||||||
|
int resetCount = listResetService.resetByFilter(prjctIdx, request.getListFilter(), request.getResetMode(), ctx.getUserId(), now);
|
||||||
|
systemEventLogService.writeResetList(ctx.getUserId(), now, ctx.getClientIp(), prjctIdx, request);
|
||||||
|
|
||||||
|
return resetCount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,17 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
@Schema(description = "리스트 필터 Dto")
|
@Schema(description = "리스트 필터 Dto")
|
||||||
public class ListFilterDto {
|
public class ListFilterDto {
|
||||||
|
|
||||||
@@ -27,4 +33,13 @@ public class ListFilterDto {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Schema(description = "그 외 필터 정보")
|
@Schema(description = "그 외 필터 정보")
|
||||||
private Map<Integer, Set<String>> otherItems;
|
private Map<Integer, Set<String>> otherItems;
|
||||||
|
|
||||||
|
public static ListFilterDto onlyOneSid(Integer sid) {
|
||||||
|
return ListFilterDto.builder()
|
||||||
|
.sidSet(Set.of(sid))
|
||||||
|
.listUseSet(Set.of())
|
||||||
|
.memo("")
|
||||||
|
.otherItems(Map.of())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.kri.contact.server.dto.list;
|
||||||
|
|
||||||
|
import com.kri.contact.server.common.enums.ListResetMode;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Schema(description = "리스트 초기화 요청 DTO")
|
||||||
|
public class ListResetRequestDto {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Schema(description = "초기화 범위")
|
||||||
|
private ListResetMode resetMode;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Schema(description = "리스트 필터")
|
||||||
|
private ListFilterDto listFilter;
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.kri.contact.server.dto.list;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import java.util.Map;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Schema(description = "리스트 정보 수정 요청 DTO")
|
||||||
|
public class ListUpdateRequestDto {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Schema(description = "리스트 정보 수정내용 sid를 제외한 모든 내용, listHderId by listItemValue")
|
||||||
|
private Map<Integer, String> updateContents;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Schema(description = "리스트 필터")
|
||||||
|
private ListFilterDto listFilter;
|
||||||
|
}
|
||||||
@@ -0,0 +1,198 @@
|
|||||||
|
package com.kri.contact.server.persistence.jdbc;
|
||||||
|
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
|
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ListUpdateJdbcSupport {
|
||||||
|
|
||||||
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
public void batchInsertUpdateHist(List<UpdateHistRow> rows, int batchSize) {
|
||||||
|
if (rows == null || rows.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String sql = """
|
||||||
|
insert into t_list_update_hist (
|
||||||
|
prjct_idx,
|
||||||
|
sid,
|
||||||
|
list_hder_id,
|
||||||
|
before_val,
|
||||||
|
after_val,
|
||||||
|
reg_user,
|
||||||
|
reg_dt
|
||||||
|
) values (?, ?, ?, ?, ?, ?, ?)
|
||||||
|
""";
|
||||||
|
|
||||||
|
for (int i = 0; i < rows.size(); i += batchSize) {
|
||||||
|
List<UpdateHistRow> sub = rows.subList(i, Math.min(rows.size(), i + batchSize));
|
||||||
|
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
|
||||||
|
@Override
|
||||||
|
public void setValues(@NonNull PreparedStatement ps, int index) throws SQLException {
|
||||||
|
UpdateHistRow row = sub.get(index);
|
||||||
|
ps.setLong(1, row.prjctIdx());
|
||||||
|
ps.setInt(2, row.sid());
|
||||||
|
ps.setInt(3, row.listHderId());
|
||||||
|
ps.setString(4, row.beforeVal());
|
||||||
|
ps.setString(5, row.afterVal());
|
||||||
|
ps.setString(6, row.regUser());
|
||||||
|
ps.setTimestamp(7, Timestamp.valueOf(row.regDt()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBatchSize() {
|
||||||
|
return sub.size();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void batchUpdateList(List<ListUpdateRow> rows, int batchSize) {
|
||||||
|
if (rows == null || rows.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String sql = """
|
||||||
|
update t_list
|
||||||
|
set is_use = ?,
|
||||||
|
memo = ?,
|
||||||
|
mod_user = ?,
|
||||||
|
mod_dt = ?
|
||||||
|
where prjct_idx = ?
|
||||||
|
and sid = ?
|
||||||
|
""";
|
||||||
|
|
||||||
|
batchUpdate(rows, batchSize, sql, (ps, row) -> {
|
||||||
|
ps.setShort(1, row.isUse());
|
||||||
|
ps.setString(2, row.memo());
|
||||||
|
ps.setString(3, row.modUser());
|
||||||
|
ps.setTimestamp(4, Timestamp.valueOf(row.modDt()));
|
||||||
|
ps.setLong(5, row.prjctIdx());
|
||||||
|
ps.setInt(6, row.sid());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void batchUpdateListItem(List<ListItemUpdateRow> rows, int batchSize) {
|
||||||
|
if (rows == null || rows.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String sql = """
|
||||||
|
update t_list_item
|
||||||
|
set list_item_val = ?,
|
||||||
|
mod_user = ?,
|
||||||
|
mod_dt = ?
|
||||||
|
where prjct_idx = ?
|
||||||
|
and sid = ?
|
||||||
|
and list_hder_id = ?
|
||||||
|
""";
|
||||||
|
|
||||||
|
batchUpdate(rows, batchSize, sql, (ps, row) -> {
|
||||||
|
ps.setString(1, row.listItemVal());
|
||||||
|
ps.setString(2, row.modUser());
|
||||||
|
ps.setTimestamp(3, Timestamp.valueOf(row.modDt()));
|
||||||
|
ps.setLong(4, row.prjctIdx());
|
||||||
|
ps.setInt(5, row.sid());
|
||||||
|
ps.setInt(6, row.listHderId());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void batchInsertListItem(List<ListItemInsertRow> rows, int batchSize) {
|
||||||
|
if (rows == null || rows.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String sql = """
|
||||||
|
insert into t_list_item (
|
||||||
|
prjct_idx,
|
||||||
|
sid,
|
||||||
|
list_hder_id,
|
||||||
|
list_item_val,
|
||||||
|
reg_user,
|
||||||
|
reg_dt
|
||||||
|
) values (?, ?, ?, ?, ?, ?)
|
||||||
|
""";
|
||||||
|
|
||||||
|
batchUpdate(rows, batchSize, sql, (ps, row) -> {
|
||||||
|
ps.setLong(1, row.prjctIdx());
|
||||||
|
ps.setInt(2, row.sid());
|
||||||
|
ps.setInt(3, row.listHderId());
|
||||||
|
ps.setString(4, row.listItemVal());
|
||||||
|
ps.setString(5, row.regUser());
|
||||||
|
ps.setTimestamp(6, Timestamp.valueOf(row.regDt()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> void batchUpdate(
|
||||||
|
List<T> rows,
|
||||||
|
int batchSize,
|
||||||
|
String sql,
|
||||||
|
PreparedStatementWriter<T> writer
|
||||||
|
) {
|
||||||
|
for (int i = 0; i < rows.size(); i += batchSize) {
|
||||||
|
List<T> sub = rows.subList(i, Math.min(rows.size(), i + batchSize));
|
||||||
|
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
|
||||||
|
@Override
|
||||||
|
public void setValues(@NonNull PreparedStatement ps, int index) throws SQLException {
|
||||||
|
writer.write(ps, sub.get(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBatchSize() {
|
||||||
|
return sub.size();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record UpdateHistRow(
|
||||||
|
Long prjctIdx,
|
||||||
|
Integer sid,
|
||||||
|
Integer listHderId,
|
||||||
|
String beforeVal,
|
||||||
|
String afterVal,
|
||||||
|
String regUser,
|
||||||
|
LocalDateTime regDt
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public record ListUpdateRow(
|
||||||
|
Long prjctIdx,
|
||||||
|
Integer sid,
|
||||||
|
Short isUse,
|
||||||
|
String memo,
|
||||||
|
String modUser,
|
||||||
|
LocalDateTime modDt
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public record ListItemUpdateRow(
|
||||||
|
Long prjctIdx,
|
||||||
|
Integer sid,
|
||||||
|
Integer listHderId,
|
||||||
|
String listItemVal,
|
||||||
|
String modUser,
|
||||||
|
LocalDateTime modDt
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public record ListItemInsertRow(
|
||||||
|
Long prjctIdx,
|
||||||
|
Integer sid,
|
||||||
|
Integer listHderId,
|
||||||
|
String listItemVal,
|
||||||
|
String regUser,
|
||||||
|
LocalDateTime regDt
|
||||||
|
) {}
|
||||||
|
|
||||||
|
private interface PreparedStatementWriter<T> {
|
||||||
|
void write(PreparedStatement ps, T row) throws SQLException;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -55,4 +55,10 @@ public interface ListItemRepository extends JpaRepository<TListItemEntity, TList
|
|||||||
Long prjctIdx,
|
Long prjctIdx,
|
||||||
Set<Integer> sids
|
Set<Integer> sids
|
||||||
);
|
);
|
||||||
|
|
||||||
|
List<TListItemEntity> findByIdPrjctIdxAndIdSidInAndIdListHderIdIn(
|
||||||
|
Long prjctIdx,
|
||||||
|
Set<Integer> sids,
|
||||||
|
Collection<Integer> listHderIds
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.kri.contact.server.persistence.repository;
|
|||||||
import com.kri.contact.server.persistence.entity.TListEntity;
|
import com.kri.contact.server.persistence.entity.TListEntity;
|
||||||
import com.kri.contact.server.persistence.entity.id.TListEntityId;
|
import com.kri.contact.server.persistence.entity.id.TListEntityId;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
@@ -12,6 +13,8 @@ import org.springframework.data.jpa.repository.Query;
|
|||||||
public interface ListRepository extends JpaRepository<TListEntity, TListEntityId>,
|
public interface ListRepository extends JpaRepository<TListEntity, TListEntityId>,
|
||||||
JpaSpecificationExecutor<TListEntity>, ListQueryRepository {
|
JpaSpecificationExecutor<TListEntity>, ListQueryRepository {
|
||||||
|
|
||||||
|
List<TListEntity> findByIdPrjctIdxAndIdSidIn(Long prjctIdx, Collection<Integer> sids);
|
||||||
|
|
||||||
@Query("""
|
@Query("""
|
||||||
select l.id.sid
|
select l.id.sid
|
||||||
from TListEntity l
|
from TListEntity l
|
||||||
|
|||||||
@@ -6,11 +6,8 @@ import com.kri.contact.server.common.enums.ListResetMode;
|
|||||||
import com.kri.contact.server.dto.list.ListFilterDto;
|
import com.kri.contact.server.dto.list.ListFilterDto;
|
||||||
import com.kri.contact.server.persistence.entity.TListResetLogEntity;
|
import com.kri.contact.server.persistence.entity.TListResetLogEntity;
|
||||||
import com.kri.contact.server.persistence.jdbc.ListResetJdbcSupport;
|
import com.kri.contact.server.persistence.jdbc.ListResetJdbcSupport;
|
||||||
import com.kri.contact.server.persistence.repository.ListRepository;
|
|
||||||
import com.kri.contact.server.persistence.repository.ListResetLogRepository;
|
import com.kri.contact.server.persistence.repository.ListResetLogRepository;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -21,27 +18,23 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
public class ListResetService {
|
public class ListResetService {
|
||||||
|
|
||||||
private final ListResetLogRepository listResetLogRepository;
|
private final ListResetLogRepository listResetLogRepository;
|
||||||
private final ListRepository listRepository;
|
private final ListSearchService listSearchService;
|
||||||
private final ListHeaderService listHeaderService;
|
|
||||||
private final ListResetJdbcSupport listResetJdbcSupport;
|
private final ListResetJdbcSupport listResetJdbcSupport;
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public long resetByFilter(
|
public int resetByFilter(
|
||||||
Long prjctIdx,
|
Long prjctIdx,
|
||||||
ListFilterDto filter,
|
ListFilterDto filter,
|
||||||
ListResetMode mode,
|
ListResetMode mode,
|
||||||
String regUser,
|
String regUser,
|
||||||
LocalDateTime regDt
|
LocalDateTime regDt
|
||||||
) {
|
) {
|
||||||
List<Integer> emailTelnumHeaderIds = listHeaderService.getEmailTelnumHeaderId(prjctIdx);
|
Set<Integer> sids = listSearchService.findTargetSids(prjctIdx, filter);
|
||||||
Set<Integer> sids = new LinkedHashSet<>(
|
|
||||||
listRepository.findAllSids(prjctIdx, emailTelnumHeaderIds, filter)
|
|
||||||
);
|
|
||||||
return resetBySids(prjctIdx, sids, mode, regUser, regDt);
|
return resetBySids(prjctIdx, sids, mode, regUser, regDt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public long resetBySids(
|
public int resetBySids(
|
||||||
Long prjctIdx,
|
Long prjctIdx,
|
||||||
Set<Integer> sids,
|
Set<Integer> sids,
|
||||||
ListResetMode mode,
|
ListResetMode mode,
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package com.kri.contact.server.service;
|
package com.kri.contact.server.service;
|
||||||
|
|
||||||
|
import com.kri.common.feature.web.BusinessException;
|
||||||
|
import com.kri.common.feature.web.page.PageRequestDto;
|
||||||
|
import com.kri.common.feature.web.page.PageResponseDto;
|
||||||
import com.kri.contact.server.common.enums.ResultCodeType;
|
import com.kri.contact.server.common.enums.ResultCodeType;
|
||||||
import com.kri.contact.server.dto.list.ListContactResultDto;
|
import com.kri.contact.server.dto.list.ListContactResultDto;
|
||||||
import com.kri.contact.server.dto.list.ListFilterDto;
|
import com.kri.contact.server.dto.list.ListFilterDto;
|
||||||
@@ -13,14 +16,19 @@ import com.kri.contact.server.persistence.entity.TListItemEntity;
|
|||||||
import com.kri.contact.server.persistence.repository.ListEventHistRepository;
|
import com.kri.contact.server.persistence.repository.ListEventHistRepository;
|
||||||
import com.kri.contact.server.persistence.repository.ListItemRepository;
|
import com.kri.contact.server.persistence.repository.ListItemRepository;
|
||||||
import com.kri.contact.server.persistence.repository.ListRepository;
|
import com.kri.contact.server.persistence.repository.ListRepository;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.data.domain.PageImpl;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@@ -34,25 +42,69 @@ public class ListSearchService {
|
|||||||
private final ListHeaderService listHeaderService;
|
private final ListHeaderService listHeaderService;
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public List<ListSearchBaseDto> getListSearchBaseList(Long prjctIdx, ListSearchRequestDto request) {
|
public ListSearchWithResultDto getListSearchOne(Long prjctIdx, Integer sid) {
|
||||||
return createListSearchBase(prjctIdx, findPagedListEntities(prjctIdx, request));
|
ListFilterDto filterDto = ListFilterDto.onlyOneSid(sid);
|
||||||
|
List<ListSearchWithResultDto> result = createListSearchWithResult(prjctIdx, findAllListEntities(prjctIdx, filterDto));
|
||||||
|
|
||||||
|
if (result.isEmpty()) {
|
||||||
|
throw BusinessException.notFound("Not found list", "해당하는 List가 없습니다.")
|
||||||
|
.with("sid", sid);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public List<ListSearchWithResultDto> getListSearchWithResultList(Long prjctIdx, ListSearchRequestDto request) {
|
public PageResponseDto<ListSearchWithResultDto> getListSearchWithResultList(
|
||||||
return createListSearchWithResult(prjctIdx, findPagedListEntities(prjctIdx, request));
|
Long prjctIdx,
|
||||||
|
ListSearchRequestDto request
|
||||||
|
) {
|
||||||
|
List<TListEntity> listEntities = findPagedListEntities(prjctIdx, request);
|
||||||
|
List<ListSearchWithResultDto> content = createListSearchWithResult(prjctIdx, listEntities);
|
||||||
|
long totalCount = findAllSids(prjctIdx, request == null ? null : request.getListFilter()).size();
|
||||||
|
|
||||||
|
PageRequestDto pageRequest = request == null ? null : request.getPageRequest();
|
||||||
|
int pageIndex = pageRequest == null ? 0 : Math.max(pageRequest.getPageIndex(), 0);
|
||||||
|
int pageSize = pageRequest == null ? Math.max(content.size(), 1) : Math.max(pageRequest.getPageSize(), 1);
|
||||||
|
|
||||||
|
return PageResponseDto.from(new PageImpl<>(
|
||||||
|
content,
|
||||||
|
PageRequest.of(pageIndex, pageSize),
|
||||||
|
totalCount
|
||||||
|
));
|
||||||
|
}
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public Set<Integer> findTargetSids(Long prjctIdx, ListFilterDto listFilter) {
|
||||||
|
return new LinkedHashSet<>(findAllSids(prjctIdx, listFilter));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public List<ListSearchBaseDto> getAllListSearchBaseList(Long prjctIdx, ListFilterDto listFilter) {
|
public List<ListUpdateTargetRow> findUpdateTargetRows(
|
||||||
List<Integer> emailTelnumHeaderIds = listHeaderService.getEmailTelnumHeaderId(prjctIdx);
|
Long prjctIdx,
|
||||||
List<TListEntity> listEntities = listRepository.findAllListEntities(
|
Collection<Integer> sids,
|
||||||
prjctIdx,
|
Collection<Integer> headerIds
|
||||||
emailTelnumHeaderIds,
|
) {
|
||||||
listFilter
|
if (sids == null || sids.isEmpty()) {
|
||||||
);
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
return createListSearchBase(prjctIdx, listEntities);
|
Set<Integer> sidSet = new LinkedHashSet<>(sids);
|
||||||
|
List<TListEntity> listEntities = listRepository.findByIdPrjctIdxAndIdSidIn(prjctIdx, sidSet);
|
||||||
|
if (listEntities.isEmpty()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Integer, Map<Integer, String>> itemMapBySid = createItemMapBySid(prjctIdx, sidSet, headerIds);
|
||||||
|
List<ListUpdateTargetRow> rows = new ArrayList<>(listEntities.size());
|
||||||
|
for (TListEntity entity : listEntities) {
|
||||||
|
rows.add(new ListUpdateTargetRow(
|
||||||
|
entity.getSid(),
|
||||||
|
entity.getUse(),
|
||||||
|
entity.getMemo(),
|
||||||
|
itemMapBySid.getOrDefault(entity.getSid(), Collections.emptyMap())
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<TListEntity> findPagedListEntities(Long prjctIdx, ListSearchRequestDto request) {
|
private List<TListEntity> findPagedListEntities(Long prjctIdx, ListSearchRequestDto request) {
|
||||||
@@ -67,6 +119,16 @@ public class ListSearchService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<TListEntity> findAllListEntities(Long prjctIdx, ListFilterDto listFilter) {
|
||||||
|
List<Integer> emailTelnumHeaderIds = listHeaderService.getEmailTelnumHeaderId(prjctIdx);
|
||||||
|
return listRepository.findAllListEntities(prjctIdx, emailTelnumHeaderIds, listFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Integer> findAllSids(Long prjctIdx, ListFilterDto listFilter) {
|
||||||
|
List<Integer> emailTelnumHeaderIds = listHeaderService.getEmailTelnumHeaderId(prjctIdx);
|
||||||
|
return listRepository.findAllSids(prjctIdx, emailTelnumHeaderIds, listFilter);
|
||||||
|
}
|
||||||
|
|
||||||
private List<ListSearchBaseDto> createListSearchBase(Long prjctIdx, List<TListEntity> listEntities) {
|
private List<ListSearchBaseDto> createListSearchBase(Long prjctIdx, List<TListEntity> listEntities) {
|
||||||
return createListSearchRows(prjctIdx, listEntities).stream()
|
return createListSearchRows(prjctIdx, listEntities).stream()
|
||||||
.map(row -> ListSearchBaseDto.from(row.listEntity(), row.itemList()))
|
.map(row -> ListSearchBaseDto.from(row.listEntity(), row.itemList()))
|
||||||
@@ -114,10 +176,26 @@ public class ListSearchService {
|
|||||||
Set<Integer> sidSet = listEntities.stream()
|
Set<Integer> sidSet = listEntities.stream()
|
||||||
.map(TListEntity::getSid)
|
.map(TListEntity::getSid)
|
||||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||||
|
Map<Integer, Map<Integer, String>> itemMapBySid = createItemMapBySid(prjctIdx, sidSet, null);
|
||||||
|
|
||||||
Map<Integer, Map<Integer, String>> itemMapBySid = listItemRepository
|
return listEntities.stream()
|
||||||
.findByIdPrjctIdxAndIdSidIn(prjctIdx, sidSet)
|
.map(entity -> new ListSearchRow(
|
||||||
.stream()
|
entity,
|
||||||
|
itemMapBySid.getOrDefault(entity.getSid(), Collections.emptyMap())
|
||||||
|
))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<Integer, Map<Integer, String>> createItemMapBySid(
|
||||||
|
Long prjctIdx,
|
||||||
|
Set<Integer> sidSet,
|
||||||
|
Collection<Integer> headerIds
|
||||||
|
) {
|
||||||
|
List<TListItemEntity> itemEntities = headerIds == null || headerIds.isEmpty()
|
||||||
|
? listItemRepository.findByIdPrjctIdxAndIdSidIn(prjctIdx, sidSet)
|
||||||
|
: listItemRepository.findByIdPrjctIdxAndIdSidInAndIdListHderIdIn(prjctIdx, sidSet, headerIds);
|
||||||
|
|
||||||
|
return itemEntities.stream()
|
||||||
.collect(Collectors.groupingBy(
|
.collect(Collectors.groupingBy(
|
||||||
TListItemEntity::getSid,
|
TListItemEntity::getSid,
|
||||||
LinkedHashMap::new,
|
LinkedHashMap::new,
|
||||||
@@ -128,13 +206,6 @@ public class ListSearchService {
|
|||||||
LinkedHashMap::new
|
LinkedHashMap::new
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
|
||||||
return listEntities.stream()
|
|
||||||
.map(entity -> new ListSearchRow(
|
|
||||||
entity,
|
|
||||||
itemMapBySid.getOrDefault(entity.getSid(), Collections.emptyMap())
|
|
||||||
))
|
|
||||||
.toList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private record ListSearchRow(
|
private record ListSearchRow(
|
||||||
@@ -146,4 +217,11 @@ public class ListSearchService {
|
|||||||
Integer sid,
|
Integer sid,
|
||||||
Short eventTy
|
Short eventTy
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
public record ListUpdateTargetRow(
|
||||||
|
Integer sid,
|
||||||
|
Short isUse,
|
||||||
|
String memo,
|
||||||
|
Map<Integer, String> itemMap
|
||||||
|
) {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,257 @@
|
|||||||
|
package com.kri.contact.server.service;
|
||||||
|
|
||||||
|
import static com.kri.common.feature.util.StringUtil.normalizeBlank;
|
||||||
|
|
||||||
|
import com.kri.common.feature.web.BusinessException;
|
||||||
|
import com.kri.contact.server.common.consts.ContactConstant;
|
||||||
|
import com.kri.contact.server.common.enums.ListHeaderGrade;
|
||||||
|
import com.kri.contact.server.common.enums.ListHeaderType;
|
||||||
|
import com.kri.contact.server.common.enums.ListIsUse;
|
||||||
|
import com.kri.contact.server.dto.list.ListFilterDto;
|
||||||
|
import com.kri.contact.server.dto.list.ListUpdateRequestDto;
|
||||||
|
import com.kri.contact.server.persistence.entity.TListHeaderEntity;
|
||||||
|
import com.kri.contact.server.persistence.jdbc.ListUpdateJdbcSupport;
|
||||||
|
import com.kri.contact.server.persistence.jdbc.ListUpdateJdbcSupport.ListItemInsertRow;
|
||||||
|
import com.kri.contact.server.persistence.jdbc.ListUpdateJdbcSupport.ListItemUpdateRow;
|
||||||
|
import com.kri.contact.server.persistence.jdbc.ListUpdateJdbcSupport.ListUpdateRow;
|
||||||
|
import com.kri.contact.server.persistence.jdbc.ListUpdateJdbcSupport.UpdateHistRow;
|
||||||
|
import com.kri.contact.server.persistence.repository.ListHeaderRepository;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ListUpdateService {
|
||||||
|
|
||||||
|
private final ListHeaderRepository listHeaderRepository;
|
||||||
|
private final ListSearchService listSearchService;
|
||||||
|
private final ListUpdateJdbcSupport listUpdateJdbcSupport;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public int updateList(
|
||||||
|
Long prjctIdx,
|
||||||
|
ListUpdateRequestDto request,
|
||||||
|
Integer userRole,
|
||||||
|
String regUser,
|
||||||
|
LocalDateTime regDt
|
||||||
|
) {
|
||||||
|
Map<Integer, String> updateContents = request.getUpdateContents();
|
||||||
|
if (updateContents == null || updateContents.isEmpty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<Integer> sids = resolveTargetSids(prjctIdx, request.getListFilter());
|
||||||
|
if (sids.isEmpty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Integer, TListHeaderEntity> headerMap = validateHeaders(prjctIdx, updateContents.keySet(), userRole);
|
||||||
|
List<Integer> itemHeaderIds = updateContents.keySet().stream()
|
||||||
|
.filter(headerId -> !isListColumnHeader(headerId))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
int chunkSize = ContactConstant.INSERT_CHUNK_SIZE;
|
||||||
|
int totalUpdatedCount = 0;
|
||||||
|
List<Integer> sidList = new ArrayList<>(sids);
|
||||||
|
for (int i = 0; i < sidList.size(); i += chunkSize) {
|
||||||
|
List<Integer> sidChunk = sidList.subList(i, Math.min(sidList.size(), i + chunkSize));
|
||||||
|
List<ListSearchService.ListUpdateTargetRow> targetRows = listSearchService.findUpdateTargetRows(
|
||||||
|
prjctIdx,
|
||||||
|
sidChunk,
|
||||||
|
itemHeaderIds
|
||||||
|
);
|
||||||
|
|
||||||
|
if (targetRows.size() != sidChunk.size()) {
|
||||||
|
throw BusinessException.badRequest("LIST_NOT_FOUND", "?섏젙 ???由ъ뒪?몃? 李얠쓣 ???놁뒿?덈떎.");
|
||||||
|
}
|
||||||
|
|
||||||
|
totalUpdatedCount += updateChunk(
|
||||||
|
prjctIdx,
|
||||||
|
targetRows,
|
||||||
|
updateContents,
|
||||||
|
headerMap,
|
||||||
|
regUser,
|
||||||
|
regDt
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return totalUpdatedCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int updateChunk(
|
||||||
|
Long prjctIdx,
|
||||||
|
List<ListSearchService.ListUpdateTargetRow> targetRows,
|
||||||
|
Map<Integer, String> updateContents,
|
||||||
|
Map<Integer, TListHeaderEntity> headerMap,
|
||||||
|
String regUser,
|
||||||
|
LocalDateTime regDt
|
||||||
|
) {
|
||||||
|
List<UpdateHistRow> updateHistRows = new ArrayList<>();
|
||||||
|
Map<Integer, ListUpdateRow> listUpdates = new LinkedHashMap<>();
|
||||||
|
Map<ListItemKey, ListItemUpdateRow> itemUpdates = new LinkedHashMap<>();
|
||||||
|
Map<ListItemKey, ListItemInsertRow> itemInserts = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
for (ListSearchService.ListUpdateTargetRow targetRow : targetRows) {
|
||||||
|
Short currentIsUse = targetRow.isUse();
|
||||||
|
String currentMemo = targetRow.memo();
|
||||||
|
Map<Integer, String> itemMap = new LinkedHashMap<>(targetRow.itemMap());
|
||||||
|
|
||||||
|
for (Map.Entry<Integer, String> entry : updateContents.entrySet()) {
|
||||||
|
Integer headerId = entry.getKey();
|
||||||
|
Integer sid = targetRow.sid();
|
||||||
|
String newValue = normalizeUpdateValue(headerMap.get(headerId), entry.getValue());
|
||||||
|
|
||||||
|
if (ListHeaderType.IS_USE.getCode().intValue() == headerId.intValue()) {
|
||||||
|
String beforeVal = String.valueOf(currentIsUse);
|
||||||
|
if (!Objects.equals(beforeVal, newValue)) {
|
||||||
|
currentIsUse = Short.valueOf(newValue);
|
||||||
|
listUpdates.put(sid, new ListUpdateRow(
|
||||||
|
prjctIdx,
|
||||||
|
sid,
|
||||||
|
currentIsUse,
|
||||||
|
defaultString(currentMemo),
|
||||||
|
regUser,
|
||||||
|
regDt
|
||||||
|
));
|
||||||
|
updateHistRows.add(new UpdateHistRow(prjctIdx, sid, headerId, beforeVal, newValue, regUser, regDt));
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ListHeaderType.MEMO.getCode().intValue() == headerId.intValue()) {
|
||||||
|
String beforeVal = defaultString(currentMemo);
|
||||||
|
if (!Objects.equals(beforeVal, newValue)) {
|
||||||
|
currentMemo = newValue;
|
||||||
|
listUpdates.put(sid, new ListUpdateRow(
|
||||||
|
prjctIdx,
|
||||||
|
sid,
|
||||||
|
currentIsUse,
|
||||||
|
newValue,
|
||||||
|
regUser,
|
||||||
|
regDt
|
||||||
|
));
|
||||||
|
updateHistRows.add(new UpdateHistRow(prjctIdx, sid, headerId, beforeVal, newValue, regUser, regDt));
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String currentValue = itemMap.get(headerId);
|
||||||
|
String beforeVal = currentValue == null ? "" : defaultString(currentValue);
|
||||||
|
if (Objects.equals(beforeVal, newValue)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ListItemKey itemKey = new ListItemKey(sid, headerId);
|
||||||
|
if (currentValue == null) {
|
||||||
|
itemInserts.put(itemKey, new ListItemInsertRow(
|
||||||
|
prjctIdx,
|
||||||
|
sid,
|
||||||
|
headerId,
|
||||||
|
newValue,
|
||||||
|
regUser,
|
||||||
|
regDt
|
||||||
|
));
|
||||||
|
itemUpdates.remove(itemKey);
|
||||||
|
} else {
|
||||||
|
itemUpdates.put(itemKey, new ListItemUpdateRow(
|
||||||
|
prjctIdx,
|
||||||
|
sid,
|
||||||
|
headerId,
|
||||||
|
newValue,
|
||||||
|
regUser,
|
||||||
|
regDt
|
||||||
|
));
|
||||||
|
}
|
||||||
|
itemMap.put(headerId, newValue);
|
||||||
|
updateHistRows.add(new UpdateHistRow(prjctIdx, sid, headerId, beforeVal, newValue, regUser, regDt));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updateHistRows.isEmpty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
listUpdateJdbcSupport.batchInsertUpdateHist(updateHistRows, ContactConstant.INSERT_CHUNK_SIZE);
|
||||||
|
listUpdateJdbcSupport.batchUpdateList(new ArrayList<>(listUpdates.values()), ContactConstant.INSERT_CHUNK_SIZE);
|
||||||
|
listUpdateJdbcSupport.batchUpdateListItem(new ArrayList<>(itemUpdates.values()), ContactConstant.INSERT_CHUNK_SIZE);
|
||||||
|
listUpdateJdbcSupport.batchInsertListItem(new ArrayList<>(itemInserts.values()), ContactConstant.INSERT_CHUNK_SIZE);
|
||||||
|
|
||||||
|
return updateHistRows.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Set<Integer> resolveTargetSids(Long prjctIdx, ListFilterDto listFilter) {
|
||||||
|
return new LinkedHashSet<>(listSearchService.findTargetSids(prjctIdx, listFilter));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<Integer, TListHeaderEntity> validateHeaders(
|
||||||
|
Long prjctIdx,
|
||||||
|
Collection<Integer> headerIds,
|
||||||
|
Integer userRole
|
||||||
|
) {
|
||||||
|
Map<Integer, TListHeaderEntity> headerMap = listHeaderRepository.findByIdPrjctIdx(prjctIdx).stream()
|
||||||
|
.filter(header -> headerIds.contains(header.getListHderId()))
|
||||||
|
.collect(LinkedHashMap::new, (map, entity) -> map.put(entity.getListHderId(), entity), Map::putAll);
|
||||||
|
|
||||||
|
if (headerMap.size() != headerIds.size()) {
|
||||||
|
throw BusinessException.badRequest("HEADER_NOT_FOUND", "?섏젙 ????ㅻ뜑瑜?李얠쓣 ???놁뒿?덈떎.");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Integer headerId : headerIds) {
|
||||||
|
TListHeaderEntity header = headerMap.get(headerId);
|
||||||
|
if (ListHeaderType.SID.getCode().intValue() == headerId.intValue()) {
|
||||||
|
throw BusinessException.badRequest("SID_UPDATE_NOT_ALLOWED", "SID???섏젙?????놁뒿?덈떎.");
|
||||||
|
}
|
||||||
|
if (header.getListHderGrad() < ListHeaderGrade.RESERVED.getCode()) {
|
||||||
|
throw BusinessException.badRequest("HEADER_UPDATE_NOT_ALLOWED", "?섏젙?????녿뒗 ?ㅻ뜑媛 ?ы븿?섏뼱 ?덉뒿?덈떎.");
|
||||||
|
}
|
||||||
|
if (userRole != null
|
||||||
|
&& userRole >= ContactConstant.FIELDWORK_USER_ROLE
|
||||||
|
&& !Boolean.TRUE.equals(header.getUseIntrvwerEdit())) {
|
||||||
|
throw BusinessException.badRequest("INTERVIEWER_EDIT_NOT_ALLOWED", "硫댁젒???섏젙 沅뚰븳???녿뒗 ?ㅻ뜑媛 ?ы븿?섏뼱 ?덉뒿?덈떎.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return headerMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeUpdateValue(TListHeaderEntity header, String value) {
|
||||||
|
if (header.getListHderTy().equals(ListHeaderType.IS_USE.getCode())) {
|
||||||
|
return String.valueOf(parseIsUseCode(value));
|
||||||
|
}
|
||||||
|
return defaultString(normalizeBlank(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
private short parseIsUseCode(String value) {
|
||||||
|
String normalized = defaultString(normalizeBlank(value)).toUpperCase();
|
||||||
|
return switch (normalized) {
|
||||||
|
case "0", "X" -> ListIsUse.UNUSABLE.getCode();
|
||||||
|
case "1", "O" -> ListIsUse.USABLE.getCode();
|
||||||
|
case "9", "TEST" -> ListIsUse.TEST.getCode();
|
||||||
|
default -> throw BusinessException.badRequest("INVALID_IS_USE", "?ъ슜 ?щ???0, 1, 9 ?먮뒗 O, X, TEST留??덉슜?⑸땲??");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isListColumnHeader(Integer headerId) {
|
||||||
|
return ListHeaderType.IS_USE.getCode().intValue() == headerId.intValue()
|
||||||
|
|| ListHeaderType.MEMO.getCode().intValue() == headerId.intValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String defaultString(String value) {
|
||||||
|
return value == null ? "" : value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private record ListItemKey(
|
||||||
|
Integer sid,
|
||||||
|
Integer listHderId
|
||||||
|
) {}
|
||||||
|
}
|
||||||
@@ -5,6 +5,8 @@ import static com.kri.common.feature.json.JsonUtil.toMap;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.kri.contact.server.common.enums.SystemEventType;
|
import com.kri.contact.server.common.enums.SystemEventType;
|
||||||
import com.kri.contact.server.dto.list.ListHeaderDto;
|
import com.kri.contact.server.dto.list.ListHeaderDto;
|
||||||
|
import com.kri.contact.server.dto.list.ListResetRequestDto;
|
||||||
|
import com.kri.contact.server.dto.list.ListUpdateRequestDto;
|
||||||
import com.kri.contact.server.dto.project.ProjectCreateRequestDto;
|
import com.kri.contact.server.dto.project.ProjectCreateRequestDto;
|
||||||
import com.kri.contact.server.dto.project.ProjectMainTemplateUpdateRequestDto;
|
import com.kri.contact.server.dto.project.ProjectMainTemplateUpdateRequestDto;
|
||||||
import com.kri.contact.server.dto.project.ProjectUpdateRequestDto;
|
import com.kri.contact.server.dto.project.ProjectUpdateRequestDto;
|
||||||
@@ -157,6 +159,18 @@ public class SystemEventLogService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void writeUpdateList(String regId, LocalDateTime regDt, String clientIp,
|
||||||
|
Long prjctIdx, ListUpdateRequestDto req){
|
||||||
|
writeSystemLog(SystemEventType.UPDATE_LIST,
|
||||||
|
"Update List Info", prjctIdx, regId, regDt, clientIp, req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeResetList(String regId, LocalDateTime regDt, String clientIp,
|
||||||
|
Long prjctIdx, ListResetRequestDto req){
|
||||||
|
writeSystemLog(SystemEventType.RESET_LIST,
|
||||||
|
"Reset List", prjctIdx, regId, regDt, clientIp, req);
|
||||||
|
}
|
||||||
|
|
||||||
protected <T> void writeSystemLog(
|
protected <T> void writeSystemLog(
|
||||||
SystemEventType eventType,
|
SystemEventType eventType,
|
||||||
String title,
|
String title,
|
||||||
|
|||||||
Reference in New Issue
Block a user