|
|
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
import com.huifu.adapay.model.Refund;
|
|
|
import com.izouma.nineth.domain.Asset;
|
|
|
+import com.izouma.nineth.domain.Collection;
|
|
|
import com.izouma.nineth.domain.Order;
|
|
|
import com.izouma.nineth.enums.AssetStatus;
|
|
|
import com.izouma.nineth.enums.CollectionSource;
|
|
|
@@ -29,6 +30,7 @@ import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
public class FixOverSale extends ApplicationTests {
|
|
|
@Autowired
|
|
|
@@ -127,8 +129,34 @@ public class FixOverSale extends ApplicationTests {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void fixOverNumber() {
|
|
|
- List<Asset> assets = assetRepo.findOverNumber();
|
|
|
+ public void fixOverNumber() throws IOException {
|
|
|
+ List<Asset> list = assetRepo.findOverNumber();
|
|
|
+ System.out.println(list.size());
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+ list.stream().collect(Collectors.groupingBy(asset -> asset.getCollectionId()))
|
|
|
+ .forEach((collectionId, assets) -> {
|
|
|
+ Collection collection = collectionRepo.findById(collectionId).orElse(null);
|
|
|
+ if (collection != null) {
|
|
|
+ List<Asset> coldAssets = assetRepo.findColdAsset(collection.getName(), collection.getTotal());
|
|
|
+ System.out.println(collection.getTotal() + " " + collection.getName() + " " + assets.size() + " " + coldAssets.size());
|
|
|
+ for (int i = 0; i < Math.min(assets.size(), coldAssets.size()); i++) {
|
|
|
+ Asset asset = assets.get(i);
|
|
|
+ Asset cold = coldAssets.get(i);
|
|
|
+ String s = asset.getId() + "," + asset.getName() + "," + asset.getNumber() + "->" + cold.getNumber();
|
|
|
+ builder.append(s).append("\n");
|
|
|
+
|
|
|
+ asset.setNumber(cold.getNumber());
|
|
|
+ assetRepo.save(asset);
|
|
|
|
|
|
+ for (Long aLong : collectionRepo.findAllByAssetId(asset.getId())) {
|
|
|
+ collectionRepo.findById(aLong).ifPresent(c -> {
|
|
|
+ c.setNumber(cold.getNumber());
|
|
|
+ collectionRepo.save(c);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ FileUtils.write(new File("/Users/drew/Desktop/改编号.txt"), builder.toString(), StandardCharsets.UTF_8);
|
|
|
}
|
|
|
}
|