xiongzhu 4 years ago
parent
commit
220ee3d368

+ 12 - 9
src/main/java/com/izouma/nineth/repo/CollectionRepo.java

@@ -1,9 +1,6 @@
 package com.izouma.nineth.repo;
 
 import com.izouma.nineth.domain.Collection;
-import com.izouma.nineth.domain.CollectionProperty;
-import com.izouma.nineth.domain.FileObject;
-import com.izouma.nineth.domain.Privilege;
 import com.izouma.nineth.dto.RecommendCollection;
 import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.cache.annotation.CachePut;
@@ -28,13 +25,19 @@ public interface CollectionRepo extends JpaRepository<Collection, Long>, JpaSpec
 
     @Transactional
     @Modifying
-    @Query("update Collection c set c.onShelf = ?2, c.salable = ?3, c.startTime = ?4, " +
-            "c.scheduleSale = ?5, c.sort = ?6, c.detail = ?7, c.privileges = ?8, " +
-            "c.properties = ?9, c.model3d = ?10 where c.id = ?1")
+    @Query(value = "update collection_info c set c.on_shelf = ?2, c.salable = ?3, c.start_time = ?4, " +
+            "c.schedule_sale = ?5, c.sort = ?6, c.detail = ?7, c.privileges = ?8, " +
+            "c.properties = ?9, c.model3d = ?10 where c.id = ?1",nativeQuery = true)
     @CacheEvict(value = {"collection", "recommend"}, allEntries = true)
     void update(@Nonnull Long id, boolean onShelf, boolean salable, LocalDateTime startTime,
-                boolean schedule, int sort, String detail, List<Privilege> privileges,
-                List<CollectionProperty> properties, FileObject model3d);
+                boolean schedule, int sort, String detail, String privileges,
+                String properties, String model3d);
+
+    @Transactional
+    @Modifying
+    @Query(value = "update collection_info c set c.privileges = ?2 where c.id = ?1",nativeQuery = true)
+    @CacheEvict(value = {"collection", "recommend"}, allEntries = true)
+    void update(@Nonnull Long id, String privileges);
 
     @Cacheable("collection")
     Optional<Collection> findById(@Nonnull Long id);
@@ -93,7 +96,7 @@ public interface CollectionRepo extends JpaRepository<Collection, Long>, JpaSpec
 
     @Transactional
     @Modifying
-    @Query("update Collection c set c.onShelf = true, c.salable = true where c.id = ?1")
+    @Query("update Collection c set c.scheduleSale = false, c.startTime = null, c.onShelf = true, c.salable = true where c.id = ?1")
     @CacheEvict(value = "collection", key = "#id")
     void scheduleOnShelf(Long id);
 

+ 5 - 4
src/main/java/com/izouma/nineth/service/CollectionService.java

@@ -1,5 +1,6 @@
 package com.izouma.nineth.service;
 
+import com.alibaba.fastjson.JSON;
 import com.izouma.nineth.domain.Collection;
 import com.izouma.nineth.domain.*;
 import com.izouma.nineth.dto.CollectionDTO;
@@ -118,8 +119,9 @@ public class CollectionService {
     public Collection update(Collection record) {
         collectionRepo.update(record.getId(), record.isOnShelf(), record.isSalable(),
                 record.getStartTime(), record.isScheduleSale(), record.getSort(),
-                record.getDetail(), record.getPrivileges(), record.getProperties(),
-                record.getModel3d());
+                record.getDetail(), JSON.toJSONString(record.getPrivileges()),
+                JSON.toJSONString(record.getProperties()), JSON.toJSONString(record.getModel3d()));
+        collectionRepo.update(record.getId(), JSON.toJSONString(record.getPrivileges()));
         record = collectionRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
         onShelfTask(record);
         return record;
@@ -194,8 +196,7 @@ public class CollectionService {
     public Collection createBlindBox(CreateBlindBox createBlindBox) {
         Collection blindBox = createBlindBox.getBlindBox();
         if (blindBox.getId() != null) {
-            collectionRepo.save(blindBox);
-            return blindBox;
+            throw new BusinessException("无法完成此操作");
         }
 
         List<Collection> list =

+ 30 - 14
src/main/vue/src/views/BlindBoxEdit.vue

@@ -444,21 +444,37 @@ export default {
             });
         },
         submit() {
-            let data = { blindBox: { ...this.formData }, items: this.blindBoxItems };
+            if (this.formData.id) {
+                this.saving = true;
+                this.$http
+                    .post('/collection/save', this.formData, { body: 'json' })
+                    .then(res => {
+                        this.saving = false;
+                        this.$message.success('成功');
+                        this.$router.go(-1);
+                    })
+                    .catch(e => {
+                        console.log(e);
+                        this.saving = false;
+                        this.$message.error(e.error);
+                    });
+            } else {
+                let data = { blindBox: { ...this.formData }, items: this.blindBoxItems };
 
-            this.saving = true;
-            this.$http
-                .post('/collection/createBlindBox', data, { body: 'json' })
-                .then(res => {
-                    this.saving = false;
-                    this.$message.success('成功');
-                    this.$router.go(-1);
-                })
-                .catch(e => {
-                    console.log(e);
-                    this.saving = false;
-                    this.$message.error(e.error);
-                });
+                this.saving = true;
+                this.$http
+                    .post('/collection/createBlindBox', data, { body: 'json' })
+                    .then(res => {
+                        this.saving = false;
+                        this.$message.success('成功');
+                        this.$router.go(-1);
+                    })
+                    .catch(e => {
+                        console.log(e);
+                        this.saving = false;
+                        this.$message.error(e.error);
+                    });
+            }
         },
         onDelete() {
             this.$confirm('删除将无法恢复,确认要删除么?', '警告', { type: 'error' })

+ 5 - 21
src/main/vue/src/views/CollectionEdit.vue

@@ -59,33 +59,17 @@
                         <el-table :data="formData.properties">
                             <el-table-column prop="name" label="名称">
                                 <template v-slot="{ row }">
-                                    <el-input
-                                        v-model="row.name"
-                                        placeholder="20字以内"
-                                        maxlength="20"
-                                        :disabled="!canEdit"
-                                    ></el-input>
+                                    <el-input v-model="row.name" placeholder="20字以内" maxlength="20"></el-input>
                                 </template>
                             </el-table-column>
                             <el-table-column prop="value" label="内容">
                                 <template v-slot="{ row }">
-                                    <el-input
-                                        v-model="row.value"
-                                        placeholder="20字以内"
-                                        maxlength="20"
-                                        :disabled="!canEdit"
-                                    ></el-input>
+                                    <el-input v-model="row.value" placeholder="20字以内" maxlength="20"></el-input>
                                 </template>
                             </el-table-column>
                             <el-table-column width="80" align="center">
                                 <template v-slot="{ row, $index }">
-                                    <el-button
-                                        type="danger"
-                                        plain
-                                        size="mini"
-                                        @click="delProperty($index)"
-                                        :disabled="!canEdit"
-                                    >
+                                    <el-button type="danger" plain size="mini" @click="delProperty($index)">
                                         删除
                                     </el-button>
                                 </template>
@@ -93,7 +77,7 @@
                         </el-table>
                     </el-form-item>
                     <el-form-item>
-                        <el-button size="mini" @click="addProperty" :disabled="!canEdit"> 添加特性 </el-button>
+                        <el-button size="mini" @click="addProperty"> 添加特性 </el-button>
                     </el-form-item>
                     <el-form-item label="特权" prop="privileges" style="width: calc(100vw - 450px)">
                         <el-table :data="privilegeOptions">
@@ -512,7 +496,7 @@ export default {
             }
         },
         delPrivilege(row, i) {
-            let idx = this.formData.privileges.find(e => e.name === row.name);
+            let idx = this.formData.privileges.findIndex(e => e.name === row.name);
             if (idx > -1) {
                 this.formData.privileges.splice(idx, 1);
             }

+ 8 - 0
src/test/java/com/izouma/nineth/CommonTest.java

@@ -1,9 +1,11 @@
 package com.izouma.nineth;
 
+import com.alibaba.fastjson.JSON;
 import com.github.kevinsawicki.http.HttpRequest;
 import com.izouma.nineth.config.Constants;
 import com.izouma.nineth.domain.BaseEntity;
 import com.izouma.nineth.domain.BlindBoxItem;
+import com.izouma.nineth.domain.Privilege;
 import com.izouma.nineth.domain.User;
 import com.izouma.nineth.web.BaseController;
 import io.ipfs.api.IPFS;
@@ -390,4 +392,10 @@ public class CommonTest {
             }
         }
     }
+
+    @Test
+    public void jj(){
+        System.out.println(JSON.toJSONString(null) == null);
+        System.out.println(JSON.parseObject("null", Privilege.class));
+    }
 }