|
@@ -9,6 +9,7 @@ import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|
|
import com.fjhx.file.entity.FileInfo;
|
|
|
import com.fjhx.file.service.FileInfoService;
|
|
|
import com.obs.services.ObsClient;
|
|
@@ -17,6 +18,7 @@ import com.ruoyi.common.core.domain.BaseIdPo;
|
|
|
import com.ruoyi.framework.mybatis.holder.LogicHolder;
|
|
|
import com.sd.SdApplication;
|
|
|
import com.sd.business.entity.bom.po.Bom;
|
|
|
+import com.sd.business.entity.bom.po.BomSpec;
|
|
|
import com.sd.business.service.bom.BomService;
|
|
|
import com.sd.business.service.bom.BomSpecService;
|
|
|
import org.junit.Test;
|
|
@@ -56,14 +58,6 @@ public class SyncBomBootTest {
|
|
|
classifyIdMap.put("1636175375388172289", 1682221804409675778L);
|
|
|
}
|
|
|
|
|
|
- @Autowired
|
|
|
- private BomService bomService;
|
|
|
- @Autowired
|
|
|
- private BomSpecService bomSpecService;
|
|
|
- @Autowired
|
|
|
- private DataSource dataSource;
|
|
|
- @Autowired
|
|
|
- private FileInfoService fileInfoService;
|
|
|
@Value("${obs.ak}")
|
|
|
private String ak;
|
|
|
@Value("${obs.sk}")
|
|
@@ -79,16 +73,70 @@ public class SyncBomBootTest {
|
|
|
@Value("${ruoyi.name}")
|
|
|
private String name;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private BomService bomService;
|
|
|
+ @Autowired
|
|
|
+ private BomSpecService bomSpecService;
|
|
|
+ @Autowired
|
|
|
+ private DataSource dataSource;
|
|
|
+ @Autowired
|
|
|
+ private FileInfoService fileInfoService;
|
|
|
+
|
|
|
@DSTransactional
|
|
|
@Test
|
|
|
public void test() {
|
|
|
DynamicRoutingDataSource dynamicRoutingDataSource = (DynamicRoutingDataSource) dataSource;
|
|
|
DataSource sdDataSource = dynamicRoutingDataSource.getDataSource("business");
|
|
|
+
|
|
|
List<Bom> bomList = saveBom(sdDataSource);
|
|
|
+ saveBomSpec(sdDataSource, bomList);
|
|
|
|
|
|
System.out.println();
|
|
|
}
|
|
|
|
|
|
+ private void saveBomSpec(DataSource sdDataSource, List<Bom> bomList) {
|
|
|
+ LogicHolder.setLogicHolder(new LogicHolder());
|
|
|
+ List<BomSpec> list = bomSpecService.list(q -> q.isNotNull(BomSpec::getOldId));
|
|
|
+ List<Long> bomSpecIdList = list.stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
+ bomSpecService.removeBatchByIds(bomSpecIdList);
|
|
|
+ removeFile(bomSpecIdList);
|
|
|
+ LogicHolder.clear();
|
|
|
+
|
|
|
+ String sql = "SELECT\n" +
|
|
|
+ "\tid oldId,\n" +
|
|
|
+ "\tbom_id oldBomId,\n" +
|
|
|
+ "\tmag_path mainImgUrl,\n" +
|
|
|
+ "\tname_chinese name,\n" +
|
|
|
+ "\tspec_code code,\n" +
|
|
|
+ "\tcolor colour,\n" +
|
|
|
+ "\tcost_price costPrice,\n" +
|
|
|
+ "\tprice internalSellingPrice,\n" +
|
|
|
+ "\tforeign_price externalSellingPrice,\n" +
|
|
|
+ "\tsafety_stock safetyStock,\n" +
|
|
|
+ "\tproduct_long length,\n" +
|
|
|
+ "\tproduct_wide width,\n" +
|
|
|
+ "\tproduct_high height,\n" +
|
|
|
+ "\tnet_weight netWeight \n" +
|
|
|
+ "FROM\n" +
|
|
|
+ "\tt_sd_bom_color";
|
|
|
+
|
|
|
+ List<Map<String, Object>> bomSpecMapList = new JdbcTemplate(sdDataSource).queryForList(sql);
|
|
|
+ List<BomSpec> bomSpecList = BeanUtil.copyToList(bomSpecMapList, BomSpec.class);
|
|
|
+
|
|
|
+ Map<String, Long> bomMap = bomList.stream().collect(Collectors.toMap(Bom::getOldId, BaseIdPo::getId));
|
|
|
+
|
|
|
+ for (BomSpec bomSpec : bomSpecList) {
|
|
|
+ long id = IdWorker.getId();
|
|
|
+ bomSpec.setId(id);
|
|
|
+ bomSpec.setBomId(bomMap.get(bomSpec.getOldBomId()));
|
|
|
+
|
|
|
+ String fileUrl = uploadFile(bomSpec.getMainImgUrl(), id);
|
|
|
+ bomSpec.setMainImgUrl(fileUrl);
|
|
|
+ }
|
|
|
+
|
|
|
+ bomSpecService.saveBatch(bomSpecList);
|
|
|
+ }
|
|
|
+
|
|
|
private List<Bom> saveBom(DataSource sdDataSource) {
|
|
|
LogicHolder.setLogicHolder(new LogicHolder());
|
|
|
List<Bom> list = bomService.list(q -> q.isNotNull(Bom::getOldId));
|
|
@@ -148,15 +196,19 @@ public class SyncBomBootTest {
|
|
|
return bomList;
|
|
|
}
|
|
|
|
|
|
- private String uploadFile(String url, Long businessId) {
|
|
|
- String objectKey = getFileName(url);
|
|
|
- byte[] bytes = HttpUtil.downloadBytes(oldUrlPrefix + url);
|
|
|
+ private String uploadFile(String fileUrl, Long businessId) {
|
|
|
+ if (StrUtil.isBlank(fileUrl)) {
|
|
|
+ return StringPool.EMPTY;
|
|
|
+ }
|
|
|
+
|
|
|
+ String objectKey = getFileName(fileUrl);
|
|
|
+ byte[] bytes = HttpUtil.downloadBytes(oldUrlPrefix + fileUrl);
|
|
|
InputStream inputStream = new ByteArrayInputStream(bytes);
|
|
|
getObsClient().putObject(bucketName, objectKey, inputStream);
|
|
|
|
|
|
FileInfo fileInfo = new FileInfo();
|
|
|
fileInfo.setFileUrl(objectKey);
|
|
|
- fileInfo.setFileName(FileUtil.getName(url));
|
|
|
+ fileInfo.setFileName(FileUtil.getName(fileUrl));
|
|
|
fileInfo.setBusinessId(businessId);
|
|
|
fileInfo.setBusinessType(0);
|
|
|
fileInfoService.save(fileInfo);
|