| | |
| | | package com.vincent.rsf.server.manager.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.beans.factory.ObjectProvider; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.sql.DataSource; |
| | | import java.util.Collection; |
| | |
| | | |
| | | /** |
| | | * cus_barcode_sync_view:barcode 即为物料号(含 # 等字符亦原样),对应 man_matnr.code。与 {@link CusItemSyncViewQueryService} 独立。 |
| | | * 查询不启事务;{@code NOT_SUPPORTED} 挂起外层事务,避免主库连接占用导致副库路由失效。 |
| | | */ |
| | | @UseDataSource(DataSourceNames.DJ_CLOUD_WMS) |
| | | @Service |
| | |
| | | return viewItems.stream().anyMatch(r -> rowMatchesOrderMatnr(oc, Objects.toString(r.get("barcode"), null))); |
| | | } |
| | | |
| | | /** 挂起外层事务,查询本身不包事务 */ |
| | | @Transactional(propagation = Propagation.NOT_SUPPORTED) |
| | | public List<Map<String, Object>> probeSample(int limit) { |
| | | if (cusItemSyncDataSourceProvider.getIfAvailable() == null) { |
| | | return Collections.emptyList(); |
| | |
| | | return toViewMaps(page.getRecords()); |
| | | } |
| | | |
| | | @Transactional(propagation = Propagation.NOT_SUPPORTED) |
| | | public List<Map<String, Object>> listByItemNos(Collection<String> itemNos) { |
| | | if (itemNos == null || itemNos.isEmpty()) { |
| | | return Collections.emptyList(); |
| | |
| | | return Collections.emptyList(); |
| | | } |
| | | List<CusBarcodeSyncView> rows = cusBarcodeSyncViewMapper.selectList( |
| | | Wrappers.<CusBarcodeSyncView>lambdaQuery() |
| | | .in(CusBarcodeSyncView::getBarcode, codes) |
| | | buildBarcodeOrQuery(codes) |
| | | .select( |
| | | CusBarcodeSyncView::getBarcode, |
| | | CusBarcodeSyncView::getItemName, |
| | |
| | | return toViewMaps(rows); |
| | | } |
| | | |
| | | private LambdaQueryWrapper<CusBarcodeSyncView> buildBarcodeOrQuery(List<String> codes) { |
| | | LambdaQueryWrapper<CusBarcodeSyncView> wrapper = Wrappers.lambdaQuery(); |
| | | wrapper.and(q -> { |
| | | for (int i = 0; i < codes.size(); i++) { |
| | | String code = codes.get(i); |
| | | if (i == 0) { |
| | | q.eq(CusBarcodeSyncView::getBarcode, code); |
| | | } else { |
| | | q.or().eq(CusBarcodeSyncView::getBarcode, code); |
| | | } |
| | | } |
| | | }); |
| | | return wrapper; |
| | | } |
| | | |
| | | private List<Map<String, Object>> toViewMaps(List<CusBarcodeSyncView> rows) { |
| | | if (rows == null || rows.isEmpty()) { |
| | | return Collections.emptyList(); |