Angular mà cũng tận 45tr NET áLý do nên chuyển
View attachment 443610
bạn là nữ 27 tuổi hôm qua à, nữ mà biết code cũng ghê đóTôi lên stackoverfollow tìm thằng nào nhiều vote nhất tôi copy về chứ việc gì viết code cho mỏi tay vậy bạn
Hình 1 đoán là đang làm navbar dropdown,
Hình 2 setup môi trường.
Hình 3 gọi API để làm gì đấy.
Hình 4 funtion có chức năng lấy tọa độ và vẽ lên màn hình.
.
đấy là bình thường chứ nhìn code cũ của cty tôi đây, 1 đoạn thần chú mà đéo ai biết nó làm cái gì luôn. Tự tin public vì éo sợ ai đọc và hiểu đc
JavaScript:async getUser() { const { dispatch } = this.props; const user = await dispatch(getCookie("user")); //console.log(user.user); if (typeof user !== "undefined") { this.setState({ user: JSON.parse(user) }); //console.log(this.state.user.user.email) //console.log(this.state.user.token); let token = "Bearer " + this.state.user.token; let params = { email: this.state.user.user.email, }; await callApi("POST", GETAVATARUSER, params, token).then((res) => { this.setState({ avatar: res.data.data ? URLSERVERIMAGE + res.data.data : "", }); }); // console.log(this.state.user.user.userType === Constant.FACTORY); if ( this.state.user.user.userType === Constant.SUPERADMIN || this.state.user.user.userType === Constant.GOVERMENT ) { this.setState({ isShowMenu: [ true, true, true, true, true, true, true, true, true, true, true, false, true, true, true, true, ], isShowDriver: true, isShowGoogleMap: true, isShowThanhtra: true, isShowCalender: true, isShowUpdateOrder: true, isShowShippingManager: true, isShowRentalPartner: true, isShowDistributionAgency: true, isShowIndustry: true, isShowRestaurant: true, isShowCar: true, isOrder: true, isShowKinhDoanh: true, }); } else if ( this.state.user.user.userType === Constant.FACTORY && this.state.user.user.userRole !== "Deliver" && this.state.user.user.userRole !== "Inspector" ) { if (this.state.user.user.userRole === "SuperAdmin") { this.setState({ isShowMenu: [ true, false, false, true, true, false, true, true, false, true, false, false, true, true, ], isShowDriver: true, isShowGoogleMap: true, isShowThanhtra: true, isShowCalender: true, isShowCreateOrder: true, isShowRentalPartner: true, isShowDistributionAgency: true, isShowIndustry: true, isShowRestaurant: true, isShowCar: true, isOrder: true, isShowKinhDoanh: true, isShowTurnBack: true, }); } else { this.setState({ isShowMenu: [ true, false, false, true, true, false, true, true, false, false, false, false, false, false, ], // isShowMenu: [true, false, false, true, true, true, true, true, false, true, false, false, true, false], isShowDriver: true, isShowGoogleMap: true, isShowThanhtra: false, isShowCalender: false, isShowCreateOrder: false, isShowUpdateOrder: true, isShowShippingManager: true, isShowRentalPartner: false, isShowCar: true, isOrder: false, isShowKinhDoanh: false, }); } } else if ( this.state.user.user.userType === Constant.STATION && this.state.user.user.userRole !== "Deliver" && this.state.user.user.userRole !== "Inspector" ) { this.setState({ isShowMenu: [ true, false, false, false, false, false, true, false, false, false, ], isShowDriver: true, isShowGoogleMap: true, isShowThanhtra: false, isShowCalender: true, isShowCreateOrder: false, isShowUpdateOrder: true, isShowShippingManager: true, isShowRentalPartner: false, isShowDistributionAgency: false, isShowIndustry: false, isShowRestaurant: false, isShowCar: false, isOrder: false, isShowKinhDoanh: true, }); } else if ( this.state.user.user.userType === Constant.GENERAL && this.state.user.user.userRole !== "Deliver" && this.state.user.user.userRole !== "Inspector" ) { this.setState({ isShowMenu: [ true, false, false, false, false, true, true, false, false, false, ], isShowDriver: true, isShowGoogleMap: false, isShowThanhtra: false, isShowCalender: false, isShowCreateOrder: false, isShowUpdateOrder: true, isShowShippingManager: true, isShowRentalPartner: false, isShowDistributionAgency: false, isShowIndustry: false, isShowRestaurant: false, isShowCar: false, isOrder: false, isShowKinhDoanh: true, }); } else if ( this.state.user.user.userType === Constant.FIXER && this.state.user.user.userRole !== "Deliver" && this.state.user.user.userRole !== "Inspector" ) { this.setState({ isShowMenu: [ false, false, false, false, false, false, true, false, false, false, ], isShowDriver: true, isShowGoogleMap: false, isShowThanhtra: false, isShowCalender: false, isShowCreateOrder: false, isShowUpdateOrder: true, isShowShippingManager: true, isShowRentalPartner: false, isShowDistributionAgency: false, isShowIndustry: false, isShowRestaurant: false, isShowCar: false, isOrder: false, isShowKinhDoanh: false, }); } else if ( this.state.user.user.userType === Constant.AGENCY && this.state.user.user.userRole !== "Deliver" && this.state.user.user.userRole !== "Inspector" ) { if (this.state.user.user.parentRoot === "") this.setState({ isShowMenu: [ true, false, false, false, false, false, true, false, true, true, true, ], isShowDriver: true, isShowGoogleMap: false, isShowThanhtra: false, isShowCalender: false, isShowCreateOrder: false, isShowUpdateOrder: false, isShowShippingManager: false, isShowRentalPartner: false, isShowDistributionAgency: false, isShowIndustry: false, isShowRestaurant: false, isShowCar: false, isOrder: false, isShowKinhDoanh: true, }); else this.setState({ isShowMenu: [ true, false, false, false, false, false, true, false, false, false, false, ], isShowDriver: true, isShowGoogleMap: false, isShowThanhtra: false, isShowCalender: false, isShowCreateOrder: false, isShowUpdateOrder: false, isShowShippingManager: true, isShowRentalPartner: false, isShowDistributionAgency: false, isShowIndustry: false, isShowRestaurant: false, isShowCar: false, isOrder: false, isShowKinhDoanh: false, }); } else if ( this.state.user.user.userType === Constant.NORMAL && this.state.user.user.userRole !== "Deliver" && this.state.user.user.userRole !== "Inspector" ) { this.setState({ isShowMenu: [ true, true, true, true, true, true, true, true, true, false, ], isShowDriver: true, isShowGoogleMap: true, isShowThanhtra: false, isShowCalender: false, isShowCreateOrder: false, isShowUpdateOrder: true, isShowShippingManager: true, isShowRentalPartner: false, isShowDistributionAgency: false, isShowIndustry: false, isShowRestaurant: false, isShowCar: false, isOrder: false, }); } else if ( this.state.user.user.userRole === "Deliver" || this.state.user.user.userRole === "Inspector" ) { this.setState({ isShowMenu: [ false, false, false, false, false, false, false, false, false, false, false, false, false, false, ], isShowDriver: false, isShowGoogleMap: false, isShowThanhtra: false, isShowCalender: false, isShowCreateOrder: false, isShowUpdateOrder: false, isShowShippingManager: false, isShowRentalPartner: false, isShowDistributionAgency: false, isShowIndustry: false, isShowRestaurant: false, isShowCar: false, isOrder: false, }); } } }
Spaghetti code. Không hiểu sao mà lọt được qua review mà merge vào master nữa.Còn muốn chuyển sang IT nữa ko
View attachment 443600
View attachment 443576
View attachment 443578
View attachment 443606
/**
* ScvIdから素材とするデータセット一覧を取得.
*
* @param contractCompanyId 契約企業ID
* @param scvId scvId
* @return ScvDataSetListDto
* @throws Exception
*/
public ScvDataSetListDto findDataSetListByScvId(@NonNull Long contractCompanyId, @NonNull String scvId)
throws Exception {
MBiConnectSetting mBiConnectSetting = mBiConnectSettingDao.findByContractCompanyId(contractCompanyId);
// 親ScvIdを取得.
String parentScvId;
try {
parentScvId = scvDataDao.findParentScvIdByScvId(mBiConnectSetting, scvId);
} catch (Exception e) {
LOGGER.error("Failed to get parentScvId.");
throw e;
}
List<String> scvIdList = new ArrayList<>();
// 親ScvIdを基にScvIdリストを取得
if (StringUtils.isNotBlank(parentScvId)) {
scvIdList = scvDataDao.findScvIdListByParentScvId(mBiConnectSetting, parentScvId);
}
scvIdList.add(scvId);
// 対象のデータセット行IDリストを取得
List<SqlRow> rowScvSourceList = scvSourceDao.findListByScvIdList(mBiConnectSetting, scvIdList);
// データセット行IDのテーブル名とPKリストを紐付けるためマッピング
Map<String, List<Long>> dataSetRowList = new HashMap<>();
scvSourceDao.findDataSetRowIdColumnNameList(mBiConnectSetting).stream().forEach(columnName -> {
List<Long> dataSetRowIdList = new ArrayList<>();
rowScvSourceList.stream().forEach(rowScvSource -> {
Long dataSetRowId = rowScvSource.getLong(columnName);
if (Objects.nonNull(dataSetRowId)) {
dataSetRowIdList.add(dataSetRowId);
}
});
String dataSetRowTableName = columnName.replace("id_", "");
dataSetRowList.put(dataSetRowTableName, dataSetRowIdList);
});
List<ScvDataSetListDto.ScvDataSetDto> customerFragmentList = new ArrayList<>();
// データセット行情報からデータセットを取得
dataSetRowList.forEach((tableName, idList) -> {
// TODO 同一のデータセット行テーブルに異なるデータセット行情報ID は存在しないので List じゃなくてよい
List<Long> dataSetRowInfoIdList = new ArrayList<>();
// 行IDリストから行情報IDリストを取得
try {
dataSetRowInfoIdList =
dataSetRowDao.findDataSetRowInfoIdListByDataSetRowIdList(mBiConnectSetting, tableName, idList);
} catch (Exception e) {
LOGGER.warn(e.getMessage());
return;
}
if (CollectionUtils.isEmpty(dataSetRowInfoIdList)) {
return;
}
// 行情報IDリストからデータセットを取得
mDataSetDao.findDataSetWithDataSourceByDataSetRowIdList(contractCompanyId, dataSetRowInfoIdList).stream()
.forEach(sqlRow -> {
Optional<List<Long>> optionalDataSetRowIdList = dataSetRowList.entrySet().stream().filter(
dataSetRowMap -> Long.valueOf(dataSetRowMap.getKey().replace("data_set_row_", "")) == sqlRow
.getLong("data_set_id"))
.map(dataSetRowMap -> dataSetRowMap.getValue())
.findFirst();
if (customerFragmentList.isEmpty()
|| !customerFragmentList.get(customerFragmentList.size() - 1).getDataSetId()
// リストに未登録のデータセットの場合はデータセットとデータソースを登録
.equals(sqlRow.getLong("data_set_id"))) {
ScvDataSetListDto.ScvDataSetDto scvDataSetDto = new ScvDataSetListDto.ScvDataSetDto();
scvDataSetDto.setDataSetId(sqlRow.getLong("data_set_id"));
scvDataSetDto.setDataSetName(sqlRow.getString("data_set_name"));
List<ScvDataSetListDto.ScvDataSourceDto> dataSourceList = new ArrayList<>();
scvDataSetDto.setDataSourceList(dataSourceList);
customerFragmentList.add(scvDataSetDto);
}
ScvDataSetListDto.ScvDataSourceDto scvDataSourceDto = new ScvDataSetListDto.ScvDataSourceDto();
scvDataSourceDto.setDataSourceId(sqlRow.getLong("data_source_id"));
scvDataSourceDto.setDataSourceName(sqlRow.getString("data_source_name"));
// データ部の取得
// TODO n+1 な処理なのでチューニング対象
optionalDataSetRowIdList.ifPresent(dataSetRowIdList -> {
if (CollectionUtils.isEmpty(dataSetRowIdList)) {
// data_set_row_id が取れない場合は SCV がそのデータセットを使ってないのでスキップ
return;
}
if (DATA_SOURCE_CONNECTOR_TYPE.CSV.getValue().equals(sqlRow.getInteger("connector_type"))
|| DATA_SOURCE_CONNECTOR_TYPE.API.getValue().equals(sqlRow.getInteger("connector_type"))) {
// CSV/API は master_data の値を入れる
scvDataSourceDto.setDataMetaJsonList(
masterDataDao.findDataMetaJsonByMasterHeaderId(mBiConnectSetting, sqlRow.getLong("master_header_id"),
sqlRow.getString("master_hash"), sqlRow.getLong("data_set_id"),
sqlRow.getLong("data_source_id"), dataSetRowIdList));
} else if (DATA_SOURCE_CONNECTOR_TYPE.WEB.getValue().equals(sqlRow.getInteger("connector_type"))
|| DATA_SOURCE_CONNECTOR_TYPE.ANDROID.getValue().equals(sqlRow.getInteger("connector_type"))
|| DATA_SOURCE_CONNECTOR_TYPE.IOS.getValue().equals(sqlRow.getInteger("connector_type"))) {
// Web計測系は user_unknown を入れる
// データセット行構築ルールから顧客識別用情報に連結設定されているデータソースIDとカラムインデックスを取得
Long targetDataSourceID = sqlRow.getLong("target_data_source_id");
String targetColumnReference = sqlRow.getString("target_column_reference");
String targetHeaderMetaJson = sqlRow.getString("target_header_meta_json");
// 顧客識別用情報に連結設定されているカラム物理名を取得
List<String> dataSetRowColumnNameList = new ArrayList<>();
try {
List<DataSetRowInfoListDto.DataSetRowInfoDto.ColumnDto> columnDtoList;
Map<String, List<DataSetRowInfoListDto.DataSetRowInfoDto.ColumnDto>> headerMetaMap =
Jackson.getObjectMapper().readValue(targetHeaderMetaJson,
new TypeReference<Map<String, List<DataSetRowInfoListDto.DataSetRowInfoDto.ColumnDto>>>() {
});
columnDtoList = headerMetaMap.get("columns");
Map<String, List<Long>> indexListWrapper =
Jackson.getObjectMapper().readValue(targetColumnReference,
new TypeReference<Map<String, List<Long>>>() {
});
List<Long> indexList = indexListWrapper.get("indexList");
dataSetRowColumnNameList =
columnDtoList.stream().filter(columnDto -> indexList.contains(columnDto.getIndex()))
.map(columnDto -> targetDataSourceID + "_" + columnDto.getPhysicalName())
.collect(Collectors.toList());
} catch (JsonProcessingException e) {
LOGGER.warn(e.getMessage());
return;
}
// カラム物理名で特定した対象SCVの顧客識別用情報とデータソースIDで JSON 形式に変換した匿名客を取得
if (CollectionUtils.isNotEmpty(dataSetRowColumnNameList)) {
scvDataSourceDto.setDataMetaJsonList(
userUnknownDao.findDataMetaJsonByMasterHeaderId(mBiConnectSetting, sqlRow.getLong("data_set_id"),
sqlRow.getLong("data_source_id"),
dataSetRowIdList,
dataSetRowColumnNameList));
}
}
});
// リストの末尾にデータソースを登録
customerFragmentList.get(customerFragmentList.size() - 1).getDataSourceList().add(scvDataSourceDto);
});
});
ScvDataSetListDto scvDataSetListDto = new ScvDataSetListDto();
scvDataSetListDto.setCustomerFragmentList(customerFragmentList);
return scvDataSetListDto;
}
Chuẫn ....nghe có vẻ nguy hiểm vkl.Mấy dòng code con nít
có biến tip thuế thanh tra nữa hả thímHình 1 đoán là đang làm navbar dropdown,
Hình 2 setup môi trường.
Hình 3 gọi API để làm gì đấy.
Hình 4 funtion có chức năng lấy tọa độ và vẽ lên màn hình.
.
đấy là bình thường chứ nhìn code cũ của cty tôi đây, 1 đoạn thần chú mà đéo ai biết nó làm cái gì luôn. Tự tin public vì éo sợ ai đọc và hiểu đc
JavaScript:async getUser() { const { dispatch } = this.props; const user = await dispatch(getCookie("user")); //console.log(user.user); if (typeof user !== "undefined") { this.setState({ user: JSON.parse(user) }); //console.log(this.state.user.user.email) //console.log(this.state.user.token); let token = "Bearer " + this.state.user.token; let params = { email: this.state.user.user.email, }; await callApi("POST", GETAVATARUSER, params, token).then((res) => { this.setState({ avatar: res.data.data ? URLSERVERIMAGE + res.data.data : "", }); }); // console.log(this.state.user.user.userType === Constant.FACTORY); if ( this.state.user.user.userType === Constant.SUPERADMIN || this.state.user.user.userType === Constant.GOVERMENT ) { this.setState({ isShowMenu: [ true, true, true, true, true, true, true, true, true, true, true, false, true, true, true, true, ], isShowDriver: true, isShowGoogleMap: true, isShowThanhtra: true, isShowCalender: true, isShowUpdateOrder: true, isShowShippingManager: true, isShowRentalPartner: true, isShowDistributionAgency: true, isShowIndustry: true, isShowRestaurant: true, isShowCar: true, isOrder: true, isShowKinhDoanh: true, }); } else if ( this.state.user.user.userType === Constant.FACTORY && this.state.user.user.userRole !== "Deliver" && this.state.user.user.userRole !== "Inspector" ) { if (this.state.user.user.userRole === "SuperAdmin") { this.setState({ isShowMenu: [ true, false, false, true, true, false, true, true, false, true, false, false, true, true, ], isShowDriver: true, isShowGoogleMap: true, isShowThanhtra: true, isShowCalender: true, isShowCreateOrder: true, isShowRentalPartner: true, isShowDistributionAgency: true, isShowIndustry: true, isShowRestaurant: true, isShowCar: true, isOrder: true, isShowKinhDoanh: true, isShowTurnBack: true, }); } else { this.setState({ isShowMenu: [ true, false, false, true, true, false, true, true, false, false, false, false, false, false, ], // isShowMenu: [true, false, false, true, true, true, true, true, false, true, false, false, true, false], isShowDriver: true, isShowGoogleMap: true, isShowThanhtra: false, isShowCalender: false, isShowCreateOrder: false, isShowUpdateOrder: true, isShowShippingManager: true, isShowRentalPartner: false, isShowCar: true, isOrder: false, isShowKinhDoanh: false, }); } } else if ( this.state.user.user.userType === Constant.STATION && this.state.user.user.userRole !== "Deliver" && this.state.user.user.userRole !== "Inspector" ) { this.setState({ isShowMenu: [ true, false, false, false, false, false, true, false, false, false, ], isShowDriver: true, isShowGoogleMap: true, isShowThanhtra: false, isShowCalender: true, isShowCreateOrder: false, isShowUpdateOrder: true, isShowShippingManager: true, isShowRentalPartner: false, isShowDistributionAgency: false, isShowIndustry: false, isShowRestaurant: false, isShowCar: false, isOrder: false, isShowKinhDoanh: true, }); } else if ( this.state.user.user.userType === Constant.GENERAL && this.state.user.user.userRole !== "Deliver" && this.state.user.user.userRole !== "Inspector" ) { this.setState({ isShowMenu: [ true, false, false, false, false, true, true, false, false, false, ], isShowDriver: true, isShowGoogleMap: false, isShowThanhtra: false, isShowCalender: false, isShowCreateOrder: false, isShowUpdateOrder: true, isShowShippingManager: true, isShowRentalPartner: false, isShowDistributionAgency: false, isShowIndustry: false, isShowRestaurant: false, isShowCar: false, isOrder: false, isShowKinhDoanh: true, }); } else if ( this.state.user.user.userType === Constant.FIXER && this.state.user.user.userRole !== "Deliver" && this.state.user.user.userRole !== "Inspector" ) { this.setState({ isShowMenu: [ false, false, false, false, false, false, true, false, false, false, ], isShowDriver: true, isShowGoogleMap: false, isShowThanhtra: false, isShowCalender: false, isShowCreateOrder: false, isShowUpdateOrder: true, isShowShippingManager: true, isShowRentalPartner: false, isShowDistributionAgency: false, isShowIndustry: false, isShowRestaurant: false, isShowCar: false, isOrder: false, isShowKinhDoanh: false, }); } else if ( this.state.user.user.userType === Constant.AGENCY && this.state.user.user.userRole !== "Deliver" && this.state.user.user.userRole !== "Inspector" ) { if (this.state.user.user.parentRoot === "") this.setState({ isShowMenu: [ true, false, false, false, false, false, true, false, true, true, true, ], isShowDriver: true, isShowGoogleMap: false, isShowThanhtra: false, isShowCalender: false, isShowCreateOrder: false, isShowUpdateOrder: false, isShowShippingManager: false, isShowRentalPartner: false, isShowDistributionAgency: false, isShowIndustry: false, isShowRestaurant: false, isShowCar: false, isOrder: false, isShowKinhDoanh: true, }); else this.setState({ isShowMenu: [ true, false, false, false, false, false, true, false, false, false, false, ], isShowDriver: true, isShowGoogleMap: false, isShowThanhtra: false, isShowCalender: false, isShowCreateOrder: false, isShowUpdateOrder: false, isShowShippingManager: true, isShowRentalPartner: false, isShowDistributionAgency: false, isShowIndustry: false, isShowRestaurant: false, isShowCar: false, isOrder: false, isShowKinhDoanh: false, }); } else if ( this.state.user.user.userType === Constant.NORMAL && this.state.user.user.userRole !== "Deliver" && this.state.user.user.userRole !== "Inspector" ) { this.setState({ isShowMenu: [ true, true, true, true, true, true, true, true, true, false, ], isShowDriver: true, isShowGoogleMap: true, isShowThanhtra: false, isShowCalender: false, isShowCreateOrder: false, isShowUpdateOrder: true, isShowShippingManager: true, isShowRentalPartner: false, isShowDistributionAgency: false, isShowIndustry: false, isShowRestaurant: false, isShowCar: false, isOrder: false, }); } else if ( this.state.user.user.userRole === "Deliver" || this.state.user.user.userRole === "Inspector" ) { this.setState({ isShowMenu: [ false, false, false, false, false, false, false, false, false, false, false, false, false, false, ], isShowDriver: false, isShowGoogleMap: false, isShowThanhtra: false, isShowCalender: false, isShowCreateOrder: false, isShowUpdateOrder: false, isShowShippingManager: false, isShowRentalPartner: false, isShowDistributionAgency: false, isShowIndustry: false, isShowRestaurant: false, isShowCar: false, isOrder: false, }); } } }
Nhiều như lợn conAngular mà cũng tận 45tr NET á
Fen code dài quá. Tách phần db ra. Throw exception cụ thể nữatính ra tôi làm java code còn dễ đọc chán
demo 1 cái method cơ bản trong project đang làm
Java:/** * ScvIdから素材とするデータセット一覧を取得. * * @param contractCompanyId 契約企業ID * @param scvId scvId * @return ScvDataSetListDto * @throws Exception */ public ScvDataSetListDto findDataSetListByScvId(@NonNull Long contractCompanyId, @NonNull String scvId) throws Exception { MBiConnectSetting mBiConnectSetting = mBiConnectSettingDao.findByContractCompanyId(contractCompanyId); // 親ScvIdを取得. String parentScvId; try { parentScvId = scvDataDao.findParentScvIdByScvId(mBiConnectSetting, scvId); } catch (Exception e) { LOGGER.error("Failed to get parentScvId."); throw e; } List<String> scvIdList = new ArrayList<>(); // 親ScvIdを基にScvIdリストを取得 if (StringUtils.isNotBlank(parentScvId)) { scvIdList = scvDataDao.findScvIdListByParentScvId(mBiConnectSetting, parentScvId); } scvIdList.add(scvId); // 対象のデータセット行IDリストを取得 List<SqlRow> rowScvSourceList = scvSourceDao.findListByScvIdList(mBiConnectSetting, scvIdList); // データセット行IDのテーブル名とPKリストを紐付けるためマッピング Map<String, List<Long>> dataSetRowList = new HashMap<>(); scvSourceDao.findDataSetRowIdColumnNameList(mBiConnectSetting).stream().forEach(columnName -> { List<Long> dataSetRowIdList = new ArrayList<>(); rowScvSourceList.stream().forEach(rowScvSource -> { Long dataSetRowId = rowScvSource.getLong(columnName); if (Objects.nonNull(dataSetRowId)) { dataSetRowIdList.add(dataSetRowId); } }); String dataSetRowTableName = columnName.replace("id_", ""); dataSetRowList.put(dataSetRowTableName, dataSetRowIdList); }); List<ScvDataSetListDto.ScvDataSetDto> customerFragmentList = new ArrayList<>(); // データセット行情報からデータセットを取得 dataSetRowList.forEach((tableName, idList) -> { // TODO 同一のデータセット行テーブルに異なるデータセット行情報ID は存在しないので List じゃなくてよい List<Long> dataSetRowInfoIdList = new ArrayList<>(); // 行IDリストから行情報IDリストを取得 try { dataSetRowInfoIdList = dataSetRowDao.findDataSetRowInfoIdListByDataSetRowIdList(mBiConnectSetting, tableName, idList); } catch (Exception e) { LOGGER.warn(e.getMessage()); return; } if (CollectionUtils.isEmpty(dataSetRowInfoIdList)) { return; } // 行情報IDリストからデータセットを取得 mDataSetDao.findDataSetWithDataSourceByDataSetRowIdList(contractCompanyId, dataSetRowInfoIdList).stream() .forEach(sqlRow -> { Optional<List<Long>> optionalDataSetRowIdList = dataSetRowList.entrySet().stream().filter( dataSetRowMap -> Long.valueOf(dataSetRowMap.getKey().replace("data_set_row_", "")) == sqlRow .getLong("data_set_id")) .map(dataSetRowMap -> dataSetRowMap.getValue()) .findFirst(); if (customerFragmentList.isEmpty() || !customerFragmentList.get(customerFragmentList.size() - 1).getDataSetId() // リストに未登録のデータセットの場合はデータセットとデータソースを登録 .equals(sqlRow.getLong("data_set_id"))) { ScvDataSetListDto.ScvDataSetDto scvDataSetDto = new ScvDataSetListDto.ScvDataSetDto(); scvDataSetDto.setDataSetId(sqlRow.getLong("data_set_id")); scvDataSetDto.setDataSetName(sqlRow.getString("data_set_name")); List<ScvDataSetListDto.ScvDataSourceDto> dataSourceList = new ArrayList<>(); scvDataSetDto.setDataSourceList(dataSourceList); customerFragmentList.add(scvDataSetDto); } ScvDataSetListDto.ScvDataSourceDto scvDataSourceDto = new ScvDataSetListDto.ScvDataSourceDto(); scvDataSourceDto.setDataSourceId(sqlRow.getLong("data_source_id")); scvDataSourceDto.setDataSourceName(sqlRow.getString("data_source_name")); // データ部の取得 // TODO n+1 な処理なのでチューニング対象 optionalDataSetRowIdList.ifPresent(dataSetRowIdList -> { if (CollectionUtils.isEmpty(dataSetRowIdList)) { // data_set_row_id が取れない場合は SCV がそのデータセットを使ってないのでスキップ return; } if (DATA_SOURCE_CONNECTOR_TYPE.CSV.getValue().equals(sqlRow.getInteger("connector_type")) || DATA_SOURCE_CONNECTOR_TYPE.API.getValue().equals(sqlRow.getInteger("connector_type"))) { // CSV/API は master_data の値を入れる scvDataSourceDto.setDataMetaJsonList( masterDataDao.findDataMetaJsonByMasterHeaderId(mBiConnectSetting, sqlRow.getLong("master_header_id"), sqlRow.getString("master_hash"), sqlRow.getLong("data_set_id"), sqlRow.getLong("data_source_id"), dataSetRowIdList)); } else if (DATA_SOURCE_CONNECTOR_TYPE.WEB.getValue().equals(sqlRow.getInteger("connector_type")) || DATA_SOURCE_CONNECTOR_TYPE.ANDROID.getValue().equals(sqlRow.getInteger("connector_type")) || DATA_SOURCE_CONNECTOR_TYPE.IOS.getValue().equals(sqlRow.getInteger("connector_type"))) { // Web計測系は user_unknown を入れる // データセット行構築ルールから顧客識別用情報に連結設定されているデータソースIDとカラムインデックスを取得 Long targetDataSourceID = sqlRow.getLong("target_data_source_id"); String targetColumnReference = sqlRow.getString("target_column_reference"); String targetHeaderMetaJson = sqlRow.getString("target_header_meta_json"); // 顧客識別用情報に連結設定されているカラム物理名を取得 List<String> dataSetRowColumnNameList = new ArrayList<>(); try { List<DataSetRowInfoListDto.DataSetRowInfoDto.ColumnDto> columnDtoList; Map<String, List<DataSetRowInfoListDto.DataSetRowInfoDto.ColumnDto>> headerMetaMap = Jackson.getObjectMapper().readValue(targetHeaderMetaJson, new TypeReference<Map<String, List<DataSetRowInfoListDto.DataSetRowInfoDto.ColumnDto>>>() { }); columnDtoList = headerMetaMap.get("columns"); Map<String, List<Long>> indexListWrapper = Jackson.getObjectMapper().readValue(targetColumnReference, new TypeReference<Map<String, List<Long>>>() { }); List<Long> indexList = indexListWrapper.get("indexList"); dataSetRowColumnNameList = columnDtoList.stream().filter(columnDto -> indexList.contains(columnDto.getIndex())) .map(columnDto -> targetDataSourceID + "_" + columnDto.getPhysicalName()) .collect(Collectors.toList()); } catch (JsonProcessingException e) { LOGGER.warn(e.getMessage()); return; } // カラム物理名で特定した対象SCVの顧客識別用情報とデータソースIDで JSON 形式に変換した匿名客を取得 if (CollectionUtils.isNotEmpty(dataSetRowColumnNameList)) { scvDataSourceDto.setDataMetaJsonList( userUnknownDao.findDataMetaJsonByMasterHeaderId(mBiConnectSetting, sqlRow.getLong("data_set_id"), sqlRow.getLong("data_source_id"), dataSetRowIdList, dataSetRowColumnNameList)); } } }); // リストの末尾にデータソースを登録 customerFragmentList.get(customerFragmentList.size() - 1).getDataSourceList().add(scvDataSourceDto); }); }); ScvDataSetListDto scvDataSetListDto = new ScvDataSetListDto(); scvDataSetListDto.setCustomerFragmentList(customerFragmentList); return scvDataSetListDto; }