Преглед изворни кода

Merge branch 'dev-meta' of xiongzhu/raex_back into master

sunkean пре 3 година
родитељ
комит
c69f44edf6

+ 1 - 1
src/main/java/com/izouma/nineth/domain/MetaSign.java

@@ -24,7 +24,7 @@ public class MetaSign extends BaseEntity {
     private String date;
 
     @ApiModelProperty("签到规则")
-    @ExcelProperty("签到规则1")
+    @ExcelProperty("签到规则")
     private String signRule;
 
     @ApiModelProperty("奖励类型")

+ 31 - 0
src/main/java/com/izouma/nineth/domain/MetaSwitch.java

@@ -0,0 +1,31 @@
+package com.izouma.nineth.domain;
+
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.Entity;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Entity
+@ApiModel("元宇宙空间码头列表")
+public class MetaSwitch extends BaseEntity {
+
+    @ApiModelProperty("开关名称")
+    @ExcelProperty("开关名称")
+    private String name;
+
+    @ApiModelProperty("描述")
+    @ExcelProperty("描述")
+    private String description;
+
+    @ApiModelProperty("开关状态")
+    @ExcelProperty("开关状态")
+    private boolean status;
+}

+ 23 - 0
src/main/java/com/izouma/nineth/repo/MetaSwitchRepo.java

@@ -0,0 +1,23 @@
+package com.izouma.nineth.repo;
+
+import com.izouma.nineth.domain.MetaSwitch;
+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;
+
+public interface MetaSwitchRepo extends JpaRepository<MetaSwitch, Long>, JpaSpecificationExecutor<MetaSwitch> {
+    @Query("update MetaSwitch t set t.del = true where t.id = ?1")
+    @Modifying
+    @Transactional
+    void softDelete(Long id);
+
+    MetaSwitch findByNameAndDel(String name, boolean del);
+
+    @Query("update MetaSwitch t set t.status = ?2 where t.id = ?1")
+    @Modifying
+    @Transactional
+    void updateStatus(Long id, boolean status);
+}

+ 5 - 1
src/main/java/com/izouma/nineth/service/MetaSignAwardDrawRecordService.java

@@ -64,7 +64,8 @@ public class MetaSignAwardDrawRecordService {
             // 给用户增加金币
             metaUserGoldController.changeNum(userId, metaSignAward.getGoldNum());
             metaSignAwardDrawRecordRepo.save(new MetaSignAwardDrawRecord(userId, metaSignAwardId, metaSignAward.getDate()));
-            return MetaRestResult.returnSuccess("金币领取成功,已自动加入金币余额", metaSignAward);
+            metaSignAward.setDraw(true);
+            return MetaRestResult.returnSuccess("金币奖励领取成功,已自动加入金币余额", metaSignAward);
         }
         if (MetaAwardTypeEnum.ACCESSORIES.equals(metaSignAward.getAwardType())) {
             Long metaAccessoriesId = metaSignAward.getMetaAccessoriesId();
@@ -76,14 +77,17 @@ public class MetaSignAwardDrawRecordService {
             if (Objects.isNull(metaAccessoriesPurchaseRecord)) {
                 metaAccessoriesPurchaseRecordRepo.save(new MetaAccessoriesPurchaseRecord(userId, metaAccessoriesId));
                 metaSignAwardDrawRecordRepo.save(new MetaSignAwardDrawRecord(userId, metaSignAwardId, metaSignAward.getDate()));
+                metaSignAward.setDraw(true);
                 return MetaRestResult.returnSuccess("配饰奖励领取成功", metaSignAward);
             }
             // 配饰已经存在,转化为对应金币
             metaUserGoldController.changeNum(userId, metaAccessories.getPrice());
             metaSignAwardDrawRecordRepo.save(new MetaSignAwardDrawRecord(userId, metaSignAwardId, metaSignAward.getDate()));
+            metaSignAward.setDraw(true);
             return MetaRestResult.returnSuccess("玩家已经拥有该配饰,奖励自动转化为金币", metaSignAward);
         }
         metaSignAwardDrawRecordRepo.save(new MetaSignAwardDrawRecord(userId, metaSignAwardId, metaSignAward.getDate()));
+        metaSignAward.setDraw(true);
         return MetaRestResult.returnSuccess("NFT奖励领取成功,将在指定时间统一发放给用户", metaSignAward);
     }
 

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

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

+ 70 - 0
src/main/java/com/izouma/nineth/web/MetaSwitchController.java

@@ -0,0 +1,70 @@
+package com.izouma.nineth.web;
+
+import com.izouma.nineth.domain.MetaSwitch;
+import com.izouma.nineth.dto.PageQuery;
+import com.izouma.nineth.exception.BusinessException;
+import com.izouma.nineth.repo.MetaSwitchRepo;
+import com.izouma.nineth.service.MetaSwitchService;
+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("/metaSwitch")
+@AllArgsConstructor
+public class MetaSwitchController extends BaseController {
+    private MetaSwitchService metaSwitchService;
+    private MetaSwitchRepo metaSwitchRepo;
+
+    //@PreAuthorize("hasRole('ADMIN')")
+    @PostMapping("/save")
+    public MetaSwitch save(@RequestBody MetaSwitch record) {
+        MetaSwitch metaSwitch = metaSwitchRepo.findByNameAndDel(record.getName(), false);
+        if (Objects.nonNull(metaSwitch) && !Objects.equals(metaSwitch.getId(), record.getId())) {
+            throw new BusinessException("该配置名称已经存在!");
+        }
+        if (record.getId() != null) {
+            MetaSwitch orig = metaSwitchRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
+            ObjUtils.merge(orig, record);
+            return metaSwitchRepo.save(orig);
+        }
+        return metaSwitchRepo.save(record);
+    }
+
+
+    //@PreAuthorize("hasRole('ADMIN')")
+    @PostMapping("/all")
+    public Page<MetaSwitch> all(@RequestBody PageQuery pageQuery) {
+        return metaSwitchService.all(pageQuery);
+    }
+
+    @GetMapping("/get/{id}")
+    public MetaSwitch get(@PathVariable Long id) {
+        return metaSwitchRepo.findById(id).orElseThrow(new BusinessException("无记录"));
+    }
+
+    @PostMapping("/del/{id}")
+    public void del(@PathVariable Long id) {
+        metaSwitchRepo.softDelete(id);
+    }
+
+    @PostMapping("/updateStatus/{id}/{status}")
+    public void updateStatus(@PathVariable Long id, @PathVariable boolean status) {
+        metaSwitchRepo.updateStatus(id, status);
+    }
+
+    @GetMapping("/excel")
+    @ResponseBody
+    public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
+        List<MetaSwitch> data = all(pageQuery).getContent();
+        ExcelUtils.export(response, data);
+    }
+}
+

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

@@ -0,0 +1 @@
+{"tableName":"MetaSwitch","className":"MetaSwitch","remark":"元宇宙开关配置","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":"名称","showInList":true,"showInForm":true,"formType":"singleLineText","required":true},{"name":"description","modelName":"description","remark":"描述","showInList":true,"showInForm":true,"formType":"singleLineText","required":true},{"name":"status","modelName":"status","remark":"状态","showInList":true,"showInForm":true,"formType":"singleLineText"}],"readTable":false,"dataSourceCode":"dataSource","genJson":"","subtables":[],"update":false,"basePackage":"com.izouma.nineth","tablePackage":"com.izouma.nineth.domain.MetaSwitch"}

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

@@ -1612,6 +1612,22 @@ const router = new Router({
                     meta: {
                         title: '走马灯',
                     },
+                },
+                {
+                    path: '/metaSwitchEdit',
+                    name: 'MetaSwitchEdit',
+                    component: () => import(/* webpackChunkName: "metaSwitchEdit" */ '@/views/MetaSwitchEdit.vue'),
+                    meta: {
+                        title: '元宇宙开关配置编辑',
+                    },
+                },
+                {
+                    path: '/metaSwitchList',
+                    name: 'MetaSwitchList',
+                    component: () => import(/* webpackChunkName: "metaSwitchList" */ '@/views/MetaSwitchList.vue'),
+                    meta: {
+                        title: '元宇宙开关配置',
+                    },
                 }
                 /**INSERT_LOCATION**/
             ]

+ 128 - 0
src/main/vue/src/views/MetaSwitchEdit.vue

@@ -0,0 +1,128 @@
+<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="52px"
+					label-position="right"
+					size="small"
+					style="max-width: 500px"
+				>
+					<el-form-item prop="name" label="名称">
+						<el-input v-model="formData.name" :disabled="!canEdit"> </el-input>
+					</el-form-item>
+					<el-form-item prop="description" label="描述">
+						<el-input v-model="formData.description"> </el-input>
+					</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>
+export default {
+	name: 'MetaSwitchEdit',
+	created() {
+		if (this.$route.query.id) {
+			this.$http
+				.get('metaSwitch/get/' + this.$route.query.id)
+				.then(res => {
+					this.formData = res;
+				})
+				.catch(e => {
+					console.log(e);
+					this.$message.error(e.error);
+				});
+		}
+	},
+	computed: {
+		canEdit() {
+			return !!!this.$route.query.id;
+		}
+	},
+	data() {
+		return {
+			saving: false,
+			formData: {},
+			rules: {
+				name: [
+					{
+						required: true,
+						message: '请输入名称',
+						trigger: 'blur'
+					}
+				],
+				description: [
+					{
+						required: true,
+						message: '请输入描述',
+						trigger: 'blur'
+					}
+				]
+			}
+		};
+	},
+	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('/metaSwitch/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(`/metaSwitch/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>

+ 255 - 0
src/main/vue/src/views/MetaSwitchList.vue

@@ -0,0 +1,255 @@
+<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="id" align="center" label="ID" width="100"> </el-table-column>
+            <el-table-column prop="name" align="center" label="名称" width="250"> </el-table-column>
+            <el-table-column prop="description" align="center" label="描述"> </el-table-column>
+            <el-table-column prop="status" align="center" label="状态" width="100">
+                <template v-slot="{ row }">
+                    <template>
+                        {{ row.status ? '开' : '关' }}
+                    </template>
+                </template>
+            </el-table-column>
+            <el-table-column label="操作" align="center" fixed="right" width="300">
+                <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="updateStatus(row, true)"
+                        type="primary"
+                        size="mini"
+                        plain
+                        v-if="row && !row.status"
+                    >
+                        开
+                    </el-button>
+                    <el-button
+                        @click="updateStatus(row, false)"
+                        type="danger"
+                        size="mini"
+                        plain
+                        v-if="row && row.status"
+                    >
+                        关
+                    </el-button>
+                </template>
+            </el-table-column>
+        </el-table>
+        <div class="pagination-wrapper">
+            <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: 'MetaSwitchList',
+    mixins: [pageableTable],
+    data() {
+        return {
+            timer: null,
+            websock: null,
+            multipleMode: false,
+            search: '',
+            url: '/metaSwitch/all',
+            downloading: false
+        };
+    },
+    created() {
+        this.initWebSocket();
+    },
+    destroyed() {
+        window.clearInterval(this.timer);
+        this.websock.close(); //离开路由之后断开websocket连接
+    },
+    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: '/metaSwitchEdit',
+                query: {
+                    ...this.$route.query
+                }
+            });
+        },
+        editRow(row) {
+            this.$router.push({
+                path: '/metaSwitchEdit',
+                query: {
+                    id: row.id
+                }
+            });
+        },
+        download() {
+            this.downloading = true;
+            this.$axios
+                .get('/metaSwitch/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);
+                });
+        },
+        deleteRow(row) {
+            this.$alert('删除将无法恢复,确认要删除么?', '警告', { type: 'error' })
+                .then(() => {
+                    return this.$http.post(`/metaSwitch/del/${row.id}`);
+                })
+                .then(() => {
+                    this.$message.success('删除成功');
+                    this.getData();
+                })
+                .catch(e => {
+                    if (e !== 'cancel') {
+                        this.$message.error(e.error);
+                    }
+                });
+        },
+        updateStatus(row, status) {
+            this.$alert(status ? '确定要打开此开关吗?' : '确定要关闭此开关吗?', status ? '提示' : '警告', {
+                type: status ? 'info' : 'error'
+            })
+                .then(() => {
+                    this.$http.post(`/metaSwitch/updateStatus/${row.id}/${status}`);
+                    this.websocketsend(
+                        status
+                            ? JSON.stringify({ type: row.name + '_OPEN' })
+                            : JSON.stringify({ type: row.name + '_CLOSE' })
+                    );
+                    return;
+                })
+                .then(() => {
+                    this.$message.success('操作成功');
+                    this.getData();
+                })
+                .catch(e => {
+                    if (e !== 'cancel') {
+                        this.$message.error(e.error);
+                    }
+                });
+        },
+        initWebSocket() {
+            const wsuri = 'ws://127.0.0.1:8088/websocket/1';
+            if (location.host === 'raex.vip') {
+                wsuri = 'wss://mmo.raex.vip/websocket/1';
+            }
+            if (location.host === 'test.raex.vip') {
+                wsuri = 'wss://test.mmo.raex.vip/websocket/1';
+            }
+            console.log('初始化websocket' + wsuri);
+            this.websock = new WebSocket(wsuri);
+            this.websock.onmessage = this.websocketonmessage;
+            this.websock.onopen = this.websocketonopen;
+            this.websock.onerror = this.websocketonerror;
+            this.websock.onclose = this.websocketclose;
+        },
+        websocketonopen() {
+            this.websocketsend('META_PING');
+            this.timer = window.setInterval(() => {
+                setTimeout(() => {
+                    this.websocketsend('META_PING');
+                }, 0);
+            }, 10000);
+        },
+        websocketonerror() {
+            console.log('连接建立失败重连');
+            this.initWebSocket();
+        },
+        websocketonmessage(e) {
+            console.log('数据接收' + e.data);
+        },
+        websocketsend(Data) {
+            console.log('数据发送' + Data);
+            this.websock.send(Data);
+        },
+        websocketclose(e) {
+            console.log('断开连接', e);
+        }
+    }
+};
+</script>
+<style lang="less" scoped>
+
+</style>