Bladeren bron

背包NFT使用特效配置

sunkean 3 jaren geleden
bovenliggende
commit
acb787ed7d

+ 0 - 2
src/main/java/com/izouma/nineth/config/MetaConstants.java

@@ -10,8 +10,6 @@ public interface MetaConstants {
 
     String META_BAG_COLLECTION_NAME = "META_BAG_COLLECTION_NAME";
 
-    String META_CAN_USE_COLLECTION_NAME = "META_CAN_USE_COLLECTION_NAME";
-
     String META_LUCKY_DRAW_ID = "META_LUCKY_DRAW_ID";
 
     String COMMA = ",";

+ 20 - 0
src/main/java/com/izouma/nineth/domain/MetaBagAssetEffectConfig.java

@@ -0,0 +1,20 @@
+package com.izouma.nineth.domain;
+
+import io.swagger.annotations.ApiModel;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.Entity;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Entity
+@ApiModel("元宇宙背包NFT效果配置")
+public class MetaBagAssetEffectConfig extends BaseEntity {
+
+    private String name;
+
+    private int effectId;
+}

+ 3 - 5
src/main/java/com/izouma/nineth/dto/MetaBagAssetDTO.java

@@ -28,17 +28,15 @@ public class MetaBagAssetDTO {
     @Convert(converter = FileObjectListConverter.class)
     private List<FileObject> pic;
 
-    @ApiModelProperty("是否可以直接使用")
-    private boolean canUse;
-
-    private Long collectionId;
+    @ApiModelProperty("效果id")
+    private int effectId;
 
     public static MetaBagAssetDTO create(Asset asset) {
         return MetaBagAssetDTO.builder()
                 .id(asset.getId())
                 .name(asset.getName())
                 .pic(asset.getPic())
-                .collectionId(asset.getCollectionId())
+                .effectId(-1)
                 .build();
     }
 }

+ 21 - 0
src/main/java/com/izouma/nineth/repo/MetaBagAssetEffectConfigRepo.java

@@ -0,0 +1,21 @@
+package com.izouma.nineth.repo;
+
+import com.izouma.nineth.domain.MetaBagAssetEffectConfig;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+
+import javax.transaction.Transactional;
+import java.util.List;
+
+public interface MetaBagAssetEffectConfigRepo extends JpaRepository<MetaBagAssetEffectConfig, Long>, JpaSpecificationExecutor<MetaBagAssetEffectConfig> {
+    @Query("update MetaBagAssetEffectConfig t set t.del = true where t.id = ?1")
+    @Modifying
+    @Transactional
+    void softDelete(Long id);
+
+    List<MetaBagAssetEffectConfig> findAllByDel(boolean del);
+
+    MetaBagAssetEffectConfig findByNameAndDel(String name, boolean del);
+}

+ 20 - 0
src/main/java/com/izouma/nineth/service/MetaBagAssetEffectConfigService.java

@@ -0,0 +1,20 @@
+package com.izouma.nineth.service;
+
+import com.izouma.nineth.domain.MetaBagAssetEffectConfig;
+import com.izouma.nineth.dto.PageQuery;
+import com.izouma.nineth.repo.MetaBagAssetEffectConfigRepo;
+import com.izouma.nineth.utils.JpaUtils;
+import lombok.AllArgsConstructor;
+import org.springframework.data.domain.Page;
+import org.springframework.stereotype.Service;
+
+@Service
+@AllArgsConstructor
+public class MetaBagAssetEffectConfigService {
+
+    private MetaBagAssetEffectConfigRepo metaBagAssetEffectConfigRepo;
+
+    public Page<MetaBagAssetEffectConfig> all(PageQuery pageQuery) {
+        return metaBagAssetEffectConfigRepo.findAll(JpaUtils.toSpecification(pageQuery, MetaBagAssetEffectConfig.class), JpaUtils.toPageRequest(pageQuery));
+    }
+}

+ 65 - 0
src/main/java/com/izouma/nineth/web/MetaBagAssetEffectConfigController.java

@@ -0,0 +1,65 @@
+package com.izouma.nineth.web;
+
+import com.izouma.nineth.domain.MetaBagAssetEffectConfig;
+import com.izouma.nineth.dto.PageQuery;
+import com.izouma.nineth.exception.BusinessException;
+import com.izouma.nineth.repo.MetaBagAssetEffectConfigRepo;
+import com.izouma.nineth.service.MetaBagAssetEffectConfigService;
+import com.izouma.nineth.utils.ObjUtils;
+import com.izouma.nineth.utils.excel.ExcelUtils;
+import lombok.AllArgsConstructor;
+import org.springframework.data.domain.Page;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+import java.util.Objects;
+
+@RestController
+@RequestMapping("/metaBagAssetEffectConfig")
+@AllArgsConstructor
+public class MetaBagAssetEffectConfigController extends BaseController {
+    private MetaBagAssetEffectConfigService metaBagAssetEffectConfigService;
+    private MetaBagAssetEffectConfigRepo metaBagAssetEffectConfigRepo;
+
+    //@PreAuthorize("hasRole('ADMIN')")
+    @PostMapping("/save")
+    public MetaBagAssetEffectConfig save(@RequestBody MetaBagAssetEffectConfig record) {
+        MetaBagAssetEffectConfig config = metaBagAssetEffectConfigRepo.findByNameAndDel(record.getName(), false);
+        if (Objects.nonNull(config) && !Objects.equals(config.getId(), record.getId())) {
+            throw new BusinessException("该名称特效已经配置!");
+        }
+        if (record.getId() != null) {
+            MetaBagAssetEffectConfig orig = metaBagAssetEffectConfigRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
+            ObjUtils.merge(orig, record);
+            return metaBagAssetEffectConfigRepo.save(orig);
+        }
+        return metaBagAssetEffectConfigRepo.save(record);
+    }
+
+
+    //@PreAuthorize("hasRole('ADMIN')")
+    @PostMapping("/all")
+    public Page<MetaBagAssetEffectConfig> all(@RequestBody PageQuery pageQuery) {
+        return metaBagAssetEffectConfigService.all(pageQuery);
+    }
+
+    @GetMapping("/get/{id}")
+    public MetaBagAssetEffectConfig get(@PathVariable Long id) {
+        return metaBagAssetEffectConfigRepo.findById(id).orElseThrow(new BusinessException("无记录"));
+    }
+
+    @PostMapping("/del/{id}")
+    public void del(@PathVariable Long id) {
+        metaBagAssetEffectConfigRepo.softDelete(id);
+    }
+
+    @GetMapping("/excel")
+    @ResponseBody
+    public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
+        List<MetaBagAssetEffectConfig> data = all(pageQuery).getContent();
+        ExcelUtils.export(response, data);
+    }
+}
+

+ 11 - 7
src/main/java/com/izouma/nineth/web/MetaUserBagController.java

@@ -3,15 +3,18 @@ package com.izouma.nineth.web;
 import com.izouma.nineth.config.Constants;
 import com.izouma.nineth.config.MetaConstants;
 import com.izouma.nineth.domain.Asset;
+import com.izouma.nineth.domain.MetaBagAssetEffectConfig;
 import com.izouma.nineth.domain.MetaUserProp;
 import com.izouma.nineth.dto.MetaBagAssetDTO;
 import com.izouma.nineth.dto.MetaRestResult;
 import com.izouma.nineth.dto.MetaUserBagDTO;
 import com.izouma.nineth.repo.AssetRepo;
+import com.izouma.nineth.repo.MetaBagAssetEffectConfigRepo;
 import com.izouma.nineth.repo.MetaUserPropRepo;
 import com.izouma.nineth.service.MetaParamsConfigService;
 import com.izouma.nineth.utils.SecurityUtils;
 import lombok.AllArgsConstructor;
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -37,23 +40,24 @@ public class MetaUserBagController {
 
     private AssetRepo assetRepo;
 
+    private MetaBagAssetEffectConfigRepo metaBagAssetEffectConfigRepo;
+
     @GetMapping("/query")
     public MetaRestResult<MetaUserBagDTO> queryMetaBag() {
         Long userId = SecurityUtils.getAuthenticatedUser().getId();
         List<MetaUserProp> metaUserProps = metaUserPropRepo.findByUserIdAndDel(userId, false);
         String names = metaParamsConfigService.getString(MetaConstants.META_BAG_COLLECTION_NAME);
         List<MetaBagAssetDTO> metaBagAssetDTOS = queryAsset(names, userId);
-        String canUseName = metaParamsConfigService.getString(MetaConstants.META_CAN_USE_COLLECTION_NAME);
-        if (StringUtils.isBlank(canUseName)) {
+        List<MetaBagAssetEffectConfig> configs = metaBagAssetEffectConfigRepo.findAllByDel(false);
+        if (CollectionUtils.isEmpty(configs)) {
             return MetaRestResult.returnSuccess(new MetaUserBagDTO(metaBagAssetDTOS, metaUserProps));
         }
-        String[] canUseNameList = canUseName.split(MetaConstants.COMMA);
         for (MetaBagAssetDTO metaBagAssetDTO :
                 metaBagAssetDTOS) {
-            for (String s :
-                    canUseNameList) {
-                if (metaBagAssetDTO.getName().contains(s)) {
-                    metaBagAssetDTO.setCanUse(Boolean.TRUE);
+            for (MetaBagAssetEffectConfig config :
+                    configs) {
+                if (metaBagAssetDTO.getName().contains(config.getName())) {
+                    metaBagAssetDTO.setEffectId(config.getEffectId());
                     break;
                 }
             }

+ 1 - 0
src/main/resources/genjson/MetaBagAssetEffectConfig.json

@@ -0,0 +1 @@
+{"tableName":"MetaBagAssetEffectConfig","className":"MetaBagAssetEffectConfig","remark":"NFT特效配置","genTable":true,"genClass":true,"genList":true,"genForm":true,"genRouter":true,"javaPath":"/Users/xiaohuoban/IdeaProjects/raex_back/src/main/java/com/izouma/nineth","viewPath":"/Users/xiaohuoban/IdeaProjects/raex_back/src/main/vue/src/views","routerPath":"/Users/xiaohuoban/IdeaProjects/raex_back/src/main/vue/src","resourcesPath":"/Users/xiaohuoban/IdeaProjects/raex_back/src/main/resources","dataBaseType":"Mysql","fields":[{"name":"name","modelName":"name","remark":"NFT名称","showInList":true,"showInForm":true,"formType":"singleLineText","required":true},{"name":"effectId","modelName":"effectId","remark":"特效","showInList":true,"showInForm":true,"formType":"singleLineText","required":true}],"readTable":false,"dataSourceCode":"dataSource","genJson":"","subtables":[],"update":false,"basePackage":"com.izouma.nineth","tablePackage":"com.izouma.nineth.domain.MetaBagAssetEffectConfig"}

+ 16 - 0
src/main/vue/src/router.js

@@ -1829,6 +1829,22 @@ const router = new Router({
                     meta: {
                        title: '频道管理',
                     },
+               },
+                {
+                    path: '/metaBagAssetEffectConfigEdit',
+                    name: 'MetaBagAssetEffectConfigEdit',
+                    component: () => import(/* webpackChunkName: "metaBagAssetEffectConfigEdit" */ '@/views/MetaBagAssetEffectConfigEdit.vue'),
+                    meta: {
+                       title: 'NFT特效配置编辑',
+                    },
+                },
+                {
+                    path: '/metaBagAssetEffectConfigList',
+                    name: 'MetaBagAssetEffectConfigList',
+                    component: () => import(/* webpackChunkName: "metaBagAssetEffectConfigList" */ '@/views/MetaBagAssetEffectConfigList.vue'),
+                    meta: {
+                       title: 'NFT特效配置',
+                    },
                }
                 /**INSERT_LOCATION**/
             ]

+ 132 - 0
src/main/vue/src/views/MetaBagAssetEffectConfigEdit.vue

@@ -0,0 +1,132 @@
+<template>
+    <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>
+        </page-title>
+        <div class="edit-view__content-wrapper">
+            <div class="edit-view__content-section">
+                <el-form :model="formData" :rules="rules" ref="form" label-width="79px" label-position="right" size="small"
+                    style="max-width: 500px;">
+                    <el-form-item prop="name" label="NFT名称">
+                        <el-input v-model="formData.name"></el-input>
+                    </el-form-item>
+                    <el-form-item prop="effectId" label="特效">
+						<el-input-number type="effectId" v-model="formData.effectId" :step="1" :min="1">
+						</el-input-number>
+						<div class="tip">输入规则:正整数,最小为1</div>
+					</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>
+                        <el-button @click="$router.go(-1)" :disabled="saving">取消</el-button>
+                    </el-form-item>
+                </el-form>
+            </div>
+        </div>
+    </div>
+</template>
+<script>
+import { reg } from '../util/regRules';
+export default {
+	name: 'MetaBagAssetEffectConfigEdit',
+	created() {
+		if (this.$route.query.id) {
+			this.$http
+				.get('metaBagAssetEffectConfig/get/' + this.$route.query.id)
+				.then(res => {
+					this.formData = res;
+				})
+				.catch(e => {
+					console.log(e);
+					this.$message.error(e.error);
+				});
+		}
+	},
+	data() {
+		return {
+            reg,
+			saving: false,
+			formData: {},
+			rules: {
+				name: [
+					{
+						required: true,
+						message: '请输入NFT名称',
+						trigger: 'blur'
+					}
+				],
+				effectId: [
+					{
+						required: true,
+						message: '请输入特效',
+						trigger: 'blur'
+					},
+                    {
+						validator: (rule, value, callback) => {
+							if (!this.reg.test(value)) {
+								callback(new Error('特效必须为大于1的整数'));
+								return;
+							} else {
+								callback();
+							}
+						}
+					}
+				]
+			}
+		};
+	},
+	methods: {
+		onSave() {
+			this.$refs.form.validate(valid => {
+				if (valid) {
+					this.submit();
+				} else {
+					return false;
+				}
+			});
+		},
+		submit() {
+			let data = { ...this.formData };
+
+			this.saving = true;
+			this.$http
+				.post('/metaBagAssetEffectConfig/save', 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' })
+				.then(() => {
+					return this.$http.post(`/metaBagAssetEffectConfig/del/${this.formData.id}`);
+				})
+				.then(() => {
+					this.$message.success('删除成功');
+					this.$router.go(-1);
+				})
+				.catch(e => {
+					if (e !== 'cancel') {
+						console.log(e);
+						this.$message.error((e || {}).error || '删除失败');
+					}
+				});
+		}
+	}
+};
+</script>
+<style lang="less" scoped></style>

+ 149 - 0
src/main/vue/src/views/MetaBagAssetEffectConfigList.vue

@@ -0,0 +1,149 @@
+<template>
+    <div class="list-view">
+        <page-title>
+            <el-button @click="addRow" type="primary" icon="el-icon-plus" :disabled="fetchingData || downloading"
+                class="filter-item">
+                新增
+            </el-button>
+            <el-button @click="download" icon="el-icon-upload2" :loading="downloading" :disabled="fetchingData"
+                class="filter-item">
+                导出
+            </el-button>
+        </page-title>
+        <div class="filters-container">
+            <el-input placeholder="搜索..." v-model="search" clearable class="filter-item search"
+                @keyup.enter.native="getData">
+                <el-button @click="getData" slot="append" icon="el-icon-search"> </el-button>
+            </el-input>
+        </div>
+        <el-table :data="tableData" row-key="id" ref="table" header-row-class-name="table-header-row"
+            header-cell-class-name="table-header-cell" row-class-name="table-row" cell-class-name="table-cell"
+            :height="tableHeight" v-loading="fetchingData">
+            <el-table-column v-if="multipleMode" align="center" type="selection" width="50">
+            </el-table-column>
+            <el-table-column prop="name" align="center" label="NFT名称">
+            </el-table-column>
+            <el-table-column prop="effectId" align="center" label="特效">
+            </el-table-column>
+            <el-table-column label="操作" align="center" fixed="right" width="150">
+                <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>
+                </template>
+            </el-table-column>
+        </el-table>
+        <div class="pagination-wrapper">
+            <!-- <div class="multiple-mode-wrapper">
+                <el-button v-if="!multipleMode" @click="toggleMultipleMode(true)">批量编辑</el-button>
+                <el-button-group v-else>
+                    <el-button @click="operation1">批量操作1</el-button>
+                    <el-button @click="operation2">批量操作2</el-button>
+                    <el-button @click="toggleMultipleMode(false)">取消</el-button>
+                </el-button-group>
+            </div> -->
+            <el-pagination background @size-change="onSizeChange" @current-change="onCurrentChange" :current-page="page"
+                :page-sizes="[10, 20, 30, 40, 50]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper"
+                :total="totalElements">
+            </el-pagination>
+        </div>
+
+    </div>
+</template>
+<script>
+import { mapState } from 'vuex';
+import pageableTable from '@/mixins/pageableTable';
+
+export default {
+	name: 'MetaBagAssetEffectConfigList',
+	mixins: [pageableTable],
+	data() {
+		return {
+			multipleMode: false,
+			search: '',
+			url: '/metaBagAssetEffectConfig/all',
+			downloading: false
+		};
+	},
+	computed: {
+		selection() {
+			return this.$refs.table.selection.map(i => i.id);
+		}
+	},
+	methods: {
+		beforeGetData() {
+			return { search: this.search, query: { del: false } };
+		},
+		toggleMultipleMode(multipleMode) {
+			this.multipleMode = multipleMode;
+			if (!multipleMode) {
+				this.$refs.table.clearSelection();
+			}
+		},
+		addRow() {
+			this.$router.push({
+				path: '/metaBagAssetEffectConfigEdit',
+				query: {
+					...this.$route.query
+				}
+			});
+		},
+		editRow(row) {
+			this.$router.push({
+				path: '/metaBagAssetEffectConfigEdit',
+				query: {
+					id: row.id
+				}
+			});
+		},
+		download() {
+			this.downloading = true;
+			this.$axios
+				.get('/metaBagAssetEffectConfig/excel', {
+					responseType: 'blob',
+					params: { size: 10000 }
+				})
+				.then(res => {
+					console.log(res);
+					this.downloading = false;
+					const downloadUrl = window.URL.createObjectURL(new Blob([res.data]));
+					const link = document.createElement('a');
+					link.href = downloadUrl;
+					link.setAttribute('download', res.headers['content-disposition'].split('filename=')[1]);
+					document.body.appendChild(link);
+					link.click();
+					link.remove();
+				})
+				.catch(e => {
+					console.log(e);
+					this.downloading = false;
+					this.$message.error(e.error);
+				});
+		},
+		operation1() {
+			this.$notify({
+				title: '提示',
+				message: this.selection
+			});
+		},
+		operation2() {
+			this.$message('操作2');
+		},
+		deleteRow(row) {
+			this.$alert('删除将无法恢复,确认要删除么?', '警告', { type: 'error' })
+				.then(() => {
+					return this.$http.post(`/metaBagAssetEffectConfig/del/${row.id}`);
+				})
+				.then(() => {
+					this.$message.success('删除成功');
+					this.getData();
+				})
+				.catch(e => {
+					if (e !== 'cancel') {
+						this.$message.error(e.error);
+					}
+				});
+		}
+	}
+};
+</script>
+<style lang="less" scoped></style>