xiongzhu 4 سال پیش
والد
کامیت
98cf275169

+ 6 - 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,13 @@ 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);
 
     @Cacheable("collection")
     Optional<Collection> findById(Long id);
@@ -62,7 +59,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);
 

+ 6 - 2
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;
@@ -117,8 +118,8 @@ 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()));
         record = collectionRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
         onShelfTask(record);
         return record;
@@ -192,6 +193,9 @@ public class CollectionService {
     @Transactional
     public Collection createBlindBox(CreateBlindBox createBlindBox) {
         Collection blindBox = createBlindBox.getBlindBox();
+        if (blindBox.getId() != null) {
+            throw new BusinessException("无法完成此操作");
+        }
 
         List<Collection> list =
                 collectionRepo.findAllById(createBlindBox.getItems().stream().map(BlindBoxItem::getCollectionId)

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

@@ -438,21 +438,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

@@ -17,7 +17,7 @@
                     style="max-width: 500px"
                 >
                     <el-form-item prop="name" label="名称">
-                        <el-input v-model="formData.name" :disabled="!canEdit" :maxlength="16"></el-input>
+                        <el-input v-model="formData.name" :disabled="!canEdit"></el-input>
                     </el-form-item>
                     <el-form-item prop="pic" label="图片">
                         <object-upload
@@ -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>
@@ -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);
             }