Ai trái ngành muốn chuyển sang IT hãy nhìn những hình này

Văn mẫu lên nào
20216c7a2309-87df-4c84-82b2-d2aecf242343.png
 
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.

:rolleyes:.

đấ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 :after_boom:

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,
                });
            }
        }
    }

Chắc dự án nhỏ vài role mới làm vậy được, nhìn cái isShowMenu bần không thể tả.
 
đọc vẫn còn dễ hiểu chán so với đọc code thằng đồng nghiệp tôi viết. đọc chỉ muốn chửi thề :choler:
 
tính ra tôi làm java code còn dễ đọc chán :sexy_girl:

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;
  }
 
tôi nghe nói thằng dev cùi, điểm đại học trung bình yếu năm nhất tạch gần hết môn, ra trường muộn 3 4 năm mà lương vẫn 10tr mà nhỉ
 
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.

:rolleyes:.

đấ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 :after_boom:

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,
                });
            }
        }
    }
có biến tip thuế thanh tra nữa hả thím
 
tính ra tôi làm java code còn dễ đọc chán :sexy_girl:

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;
  }
Fen code dài quá. Tách phần db ra. Throw exception cụ thể nữa
 
Back
Top