xiongzhu %!s(int64=4) %!d(string=hai) anos
pai
achega
10ee0bceba

+ 15 - 10
src/main/java/com/izouma/nineth/service/CollectionService.java

@@ -102,35 +102,40 @@ public class CollectionService {
     public Collection createBlindBox(CreateBlindBox createBlindBox) {
         Collection blindBox = createBlindBox.getBlindBox();
 
-        List<Collection> list = new ArrayList<>();
-        createBlindBox.getItems().stream().parallel().forEach(item -> {
-            Collection collection = collectionRepo.findById(item.getId()).orElseThrow(new BusinessException("所选藏品不存在"));
-            list.add(collection);
+        List<Collection> list =
+                collectionRepo.findAllById(createBlindBox.getItems().stream().map(BlindBoxItem::getCollectionId)
+                        .collect(Collectors.toSet()));
+        for (BlindBoxItem item : createBlindBox.getItems()) {
+            Collection collection = list.stream().filter(i -> i.getId().equals(item.getCollectionId())).findAny()
+                    .orElseThrow(new BusinessException("所选藏品不存在"));
             if (item.getTotal() > collection.getStock()) {
-                throw new BusinessException("所选藏品库存不足");
+                throw new BusinessException("所选藏品库存不足:" + collection.getName());
             }
-        });
+        }
 
         User user = SecurityUtils.getAuthenticatedUser();
         blindBox.setMinter(user.getNickname());
         blindBox.setMinterId(user.getId());
         blindBox.setMinterAvatar(user.getAvatar());
+        blindBox.setStock(blindBox.getTotal());
+        blindBox.setSale(0);
         collectionRepo.save(blindBox);
-        createBlindBox.getItems().stream().parallel().forEach(item -> {
-            Collection collection = list.stream().filter(i -> i.getId().equals(item.getId())).findAny().get();
+        for (BlindBoxItem item : createBlindBox.getItems()) {
+            Collection collection = list.stream().filter(i -> i.getId().equals(item.getCollectionId())).findAny()
+                    .orElseThrow(new BusinessException("所选藏品不存在"));
             collection.setStock(collection.getStock() - item.getTotal());
             collectionRepo.save(collection);
             BlindBoxItem blindBoxItem = new BlindBoxItem();
             BeanUtils.copyProperties(collection, blindBoxItem);
-            blindBoxItem.setCollectionId(collection.getId());
             blindBoxItem.setId(null);
+            blindBoxItem.setCollectionId(item.getCollectionId());
             blindBoxItem.setSale(0);
             blindBoxItem.setTotal(item.getTotal());
             blindBoxItem.setStock(item.getTotal());
             blindBoxItem.setRare(item.isRare());
             blindBoxItem.setBlindBoxId(blindBox.getId());
             blindBoxItemRepo.save(blindBoxItem);
-        });
+        }
 
         return blindBox;
     }

+ 46 - 8
src/main/vue/src/views/BlindBoxEdit.vue

@@ -2,8 +2,8 @@
     <div class="edit-view">
         <page-title>
             <el-button @click="$router.go(-1)" :disabled="saving">取消</el-button>
-            <el-button @click="onDelete" :disabled="saving" type="danger" v-if="formData.id"> 删除 </el-button>
-            <el-button @click="onSave" :loading="saving" type="primary">保存</el-button>
+            <!-- <el-button @click="onDelete" :disabled="saving" type="danger" v-if="formData.id"> 删除 </el-button> -->
+            <el-button @click="onSave" :loading="saving" type="primary" v-if="!formData.id">保存</el-button>
         </page-title>
         <div class="edit-view__content-wrapper">
             <div class="edit-view__content-section">
@@ -83,7 +83,7 @@
                     <el-form-item prop="collectionIds" label="包含作品" style="width: calc(100vw - 450px)">
                         <el-table :data="blindBoxItems">
                             <el-table-column
-                                prop="id"
+                                prop="collectionId"
                                 label="名称"
                                 :formatter="collectionNameFormatter"
                             ></el-table-column>
@@ -115,10 +115,10 @@
                         <el-switch v-model="formData.salable" active-text="可销售" inactive-text="仅展示"></el-switch>
                     </el-form-item>
                     <el-form-item class="form-submit">
-                        <el-button @click="onSave" :loading="saving" type="primary"> 保存 </el-button>
-                        <el-button @click="onDelete" :disabled="saving" type="danger" v-if="formData.id">
+                        <el-button @click="onSave" :loading="saving" type="primary" v-if="!formData.id"> 保存 </el-button>
+                        <!-- <el-button @click="onDelete" :disabled="saving" type="danger" v-if="formData.id">
                             删除
-                        </el-button>
+                        </el-button> -->
                         <el-button @click="$router.go(-1)" :disabled="saving">取消</el-button>
                     </el-form-item>
                 </el-form>
@@ -132,8 +132,8 @@
                 ref="addItemForm"
                 :rules="addItemFormRules"
             >
-                <el-form-item prop="id" label="作品">
-                    <el-select v-model="addItemForm.id">
+                <el-form-item prop="collectionId" label="作品">
+                    <el-select v-model="addItemForm.collectionId">
                         <el-option
                             v-for="item in collections"
                             :label="item.name"
@@ -184,6 +184,44 @@ export default {
         this.$http.post('/collection/all', { query: { del: false }, size: 10000 }, { body: 'json' }).then(res => {
             this.collections = res.content;
         });
+
+        // this.formData = {
+        //     name: 'OASISPUNK绿洲朋克',
+        //     pics: ['https://awesomeadmin.oss-cn-hangzhou.aliyuncs.com/image/2021-10-21-16-44-52kZqxuwhH.gif'],
+        //     minter: '管理员',
+        //     minterId: 1,
+        //     minterAvatar: 'https://awesomeadmin.oss-cn-hangzhou.aliyuncs.com/image/avatar_male.png',
+        //     detail:
+        //         '<div class="content-item" data-v-38285332="">\n<div data-v-38285332="">RAEX绿洲数字藏品中心首次携手星火爱心公益基金及火链Labs,联合发行公益型数字藏品: OASISPUNK绿洲朋克。OASISPUNK绿洲朋克是完全使用算法合成的加密人物头像,仅铸造发行3100枚,每一枚全都不同,更有稀缺度之分。绿洲朋克共分为3种类型:初代目(1500枚),次代目(1500枚),旗帜版(100枚)。每售出一枚绿洲朋克,收益所得将捐赠一定比例给&ldquo;星火爱心公益基金&rdquo;,用于扶贫助困类公益项目,同时买家将收到由星火爱心公益基金颁发的捐款证明,获得投身公益事业的荣誉感。欢迎你来到绿洲元宇宙,共建绿洲生态,共享绿洲文明荣耀。</div>\n</div>',
+        //     type: 'BLIND_BOX',
+        //     source: 'OFFICIAL',
+        //     sale: 0,
+        //     stock: 0,
+        //     total: 23,
+        //     likes: 0,
+        //     onShelf: true,
+        //     salable: true,
+        //     price: 0.01,
+        //     properties: [],
+        //     canResale: false,
+        //     royalties: 0,
+        //     serviceCharge: 0,
+        // };
+        // this.blindBoxItems = [
+        //     {
+        //         collectionId: 212,
+        //         total: 3,
+        //         rare: true
+        //     },
+        //     {
+        //         collectionId: 207,
+        //         total: 6
+        //     },
+        //     {
+        //         collectionId: 201,
+        //         total: 14
+        //     }
+        // ];
     },
     data() {
         return {

+ 2 - 3
src/main/vue/src/views/BlindBoxList.vue

@@ -68,10 +68,9 @@
                 </template>
             </el-table-column>
             <el-table-column prop="price" label="价格"> </el-table-column>
-            <el-table-column label="操作" align="center" fixed="right" width="150">
+            <el-table-column label="操作" align="center" fixed="right" width="100">
                 <template slot-scope="{ row }">
-                    <el-button @click="editRow(row)" type="primary" size="mini" plain>编辑</el-button>
-                    <el-button @click="deleteRow(row)" type="danger" size="mini" plain>删除</el-button>
+                    <el-button @click="editRow(row)" type="primary" size="mini" plain>查看</el-button>
                 </template>
             </el-table-column>
         </el-table>