Bladeren bron

元宇宙空间信息

sunkean 3 jaren geleden
bovenliggende
commit
db411bb1a4

+ 36 - 0
src/main/java/com/izouma/nineth/domain/MetaSpatialInfo.java

@@ -0,0 +1,36 @@
+package com.izouma.nineth.domain;
+
+import com.izouma.nineth.enums.MetaRegionEnum;
+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 MetaSpatialInfo extends BaseEntity {
+
+    @ApiModelProperty("所属区域")
+    private MetaRegionEnum region;
+
+    @ApiModelProperty("目前状态:true在售/false未售")
+    private boolean sale;
+
+    @ApiModelProperty("所属用户id")
+    private Long userId;
+
+    @ApiModelProperty("空间大小")
+    private int size;
+
+    @ApiModelProperty("区域内坐标x轴")
+    private String axisX;
+
+    @ApiModelProperty("区域内坐标y轴")
+    private String axisY;
+}

+ 25 - 0
src/main/java/com/izouma/nineth/enums/MetaRegionEnum.java

@@ -0,0 +1,25 @@
+package com.izouma.nineth.enums;
+
+
+public enum MetaRegionEnum {
+
+    ONE("1区"),
+    TWO("2区"),
+    THREE("3区"),
+    FOUR("4区"),
+    FIVE("5区"),
+    SIX("6区"),
+    SEVEN("7区"),
+    EIGHT("8区"),
+    NINE("9区");
+
+    private final String description;
+
+    MetaRegionEnum(String description) {
+        this.description = description;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+}

+ 25 - 0
src/main/java/com/izouma/nineth/repo/MetaSpatialInfoRepo.java

@@ -0,0 +1,25 @@
+package com.izouma.nineth.repo;
+
+import com.izouma.nineth.domain.MetaSpatialInfo;
+import com.izouma.nineth.enums.MetaRegionEnum;
+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 MetaSpatialInfoRepo extends JpaRepository<MetaSpatialInfo, Long>, JpaSpecificationExecutor<MetaSpatialInfo> {
+
+    @Query("update MetaSpatialInfo t set t.del = true where t.id = ?1")
+    @Modifying
+    @Transactional
+    void softDelete(Long id);
+
+    MetaSpatialInfo findByRegionAndAxisXAndAxisYAndDel(MetaRegionEnum region, String axisX, String axisY, boolean del);
+
+    List<MetaSpatialInfo> findAllByUserIdAndDel(Long userId, boolean del);
+
+    int countBySaleAndDel(boolean sale, boolean del);
+}

+ 1 - 0
src/main/java/com/izouma/nineth/security/WebSecurityConfig.java

@@ -142,6 +142,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
                 .antMatchers("/collection/count/*").permitAll()
                 .antMatchers("/asset/whetherMetaCanUse/*").permitAll()
                 .antMatchers("/metaPlayerInfo/**").permitAll()
+                .antMatchers("/metaSpatialInfo/**").permitAll()
                 // all other requests need to be authenticated
                 .anyRequest().authenticated().and()
                 // make sure we use stateless session; session won't be used to

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

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

+ 87 - 0
src/main/java/com/izouma/nineth/web/MetaSpatialInfoController.java

@@ -0,0 +1,87 @@
+package com.izouma.nineth.web;
+
+import com.izouma.nineth.domain.MetaSpatialInfo;
+import com.izouma.nineth.dto.MetaRestResult;
+import com.izouma.nineth.dto.PageQuery;
+import com.izouma.nineth.exception.BusinessException;
+import com.izouma.nineth.repo.MetaSpatialInfoRepo;
+import com.izouma.nineth.service.MetaSpatialInfoService;
+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("/metaSpatialInfo")
+@AllArgsConstructor
+public class MetaSpatialInfoController extends BaseController {
+    private MetaSpatialInfoService metaSpatialInfoService;
+    private MetaSpatialInfoRepo metaSpatialInfoRepo;
+
+    //@PreAuthorize("hasRole('ADMIN')")
+    @PostMapping("/save")
+    public MetaSpatialInfo save(@RequestBody MetaSpatialInfo record) {
+        MetaSpatialInfo metaSpatialInfo = metaSpatialInfoRepo.findByRegionAndAxisXAndAxisYAndDel(record.getRegion(), record.getAxisX(), record.getAxisY(), false);
+        if (Objects.nonNull(metaSpatialInfo) && !Objects.equals(metaSpatialInfo.getId(), record.getId())) {
+            throw new BusinessException("当前区域内已经存在该坐标的空间");
+        }
+        if (record.getId() != null) {
+            MetaSpatialInfo orig = metaSpatialInfoRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
+            ObjUtils.merge(orig, record);
+            return metaSpatialInfoRepo.save(orig);
+        }
+        return metaSpatialInfoRepo.save(record);
+    }
+
+
+    //@PreAuthorize("hasRole('ADMIN')")
+    @PostMapping("/all")
+    public Page<MetaSpatialInfo> all(@RequestBody PageQuery pageQuery) {
+        return metaSpatialInfoService.all(pageQuery);
+    }
+
+    @GetMapping("/get/{id}")
+    public MetaSpatialInfo get(@PathVariable Long id) {
+        return metaSpatialInfoRepo.findById(id).orElseThrow(new BusinessException("无记录"));
+    }
+
+    @PostMapping("/del/{id}")
+    public void del(@PathVariable Long id) {
+        metaSpatialInfoRepo.softDelete(id);
+    }
+
+    @GetMapping("/excel")
+    @ResponseBody
+    public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
+        List<MetaSpatialInfo> data = all(pageQuery).getContent();
+        ExcelUtils.export(response, data);
+    }
+
+    @GetMapping("/{userId}/find")
+    public MetaRestResult<List<MetaSpatialInfo>> findByUserId(@PathVariable Long userId) {
+        List<MetaSpatialInfo> metaSpatialInfos = metaSpatialInfoRepo.findAllByUserIdAndDel(userId, false);
+        return MetaRestResult.returnSuccess(metaSpatialInfos);
+    }
+
+    @GetMapping("/onSale")
+    public MetaRestResult<Integer> findOnSale() {
+        int onSale = metaSpatialInfoRepo.countBySaleAndDel(true, false);
+        return MetaRestResult.returnSuccess(onSale);
+    }
+
+    @GetMapping("/{id}/detail")
+    public MetaRestResult<MetaSpatialInfo> detail(@PathVariable Long id) {
+        MetaSpatialInfo metaSpatialInfo = metaSpatialInfoRepo.findById(id).orElse(null);
+        if (Objects.isNull(metaSpatialInfo)) {
+            return MetaRestResult.returnError(String.format("没有id为:%S的空间信息", id));
+        }
+        return MetaRestResult.returnSuccess(metaSpatialInfo);
+    }
+}
+

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

@@ -0,0 +1 @@
+{"tableName":"MetaSpatialInfo","className":"MetaSpatialInfo","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":"region","modelName":"region","remark":"所属区域","showInList":true,"showInForm":true,"formType":"select","required":true,"apiFlag":"1","optionsValue":"[{\"label\":\"1区\",\"value\":\"ONE\"},{\"label\":\"2区\",\"value\":\"TWO\"},{\"label\":\"3区\",\"value\":\"THREE\"},{\"label\":\"4区\",\"value\":\"FOUR\"},{\"label\":\"5区\",\"value\":\"FIVE\"},{\"label\":\"6区\",\"value\":\"SIX\"},{\"label\":\"7区\",\"value\":\"SEVEN\"},{\"label\":\"8区\",\"value\":\"EIGHT\"},{\"label\":\"9区\",\"value\":\"NINE\"}]"},{"name":"xCoordinate","modelName":"xCoordinate","remark":"区域内坐标x轴","showInList":true,"showInForm":true,"formType":"singleLineText","required":true},{"name":"yCoordinate","modelName":"yCoordinate","remark":"区域内坐标y轴","showInList":true,"showInForm":true,"formType":"singleLineText","required":true},{"name":"sale","modelName":"sale","remark":"状态","showInList":true,"showInForm":true,"formType":"switch","required":true},{"name":"userId","modelName":"userId","remark":"所属用户id","showInList":true,"showInForm":true,"formType":"number","required":true},{"name":"size","modelName":"size","remark":"空间大小","showInList":true,"showInForm":true,"formType":"number","required":true}],"readTable":false,"dataSourceCode":"dataSource","genJson":"","subtables":[],"update":false,"basePackage":"com.izouma.nineth","tablePackage":"com.izouma.nineth.domain.MetaSpatialInfo"}

+ 17 - 1
src/main/vue/src/router.js

@@ -979,6 +979,22 @@ const router = new Router({
                     meta: {
                        title: '开关',
                     },
+               },
+                {
+                    path: '/metaSpatialInfoEdit',
+                    name: 'MetaSpatialInfoEdit',
+                    component: () => import(/* webpackChunkName: "metaSpatialInfoEdit" */ '@/views/MetaSpatialInfoEdit.vue'),
+                    meta: {
+                       title: '元宇宙空间信息编辑',
+                    },
+                },
+                {
+                    path: '/metaSpatialInfoList',
+                    name: 'MetaSpatialInfoList',
+                    component: () => import(/* webpackChunkName: "metaSpatialInfoList" */ '@/views/MetaSpatialInfoList.vue'),
+                    meta: {
+                       title: '元宇宙空间信息',
+                    },
                }
                 /**INSERT_LOCATION**/
             ]
@@ -1039,4 +1055,4 @@ router.beforeEach((to, from, next) => {
     }
 });
 
-export default router;
+export default router;

+ 181 - 0
src/main/vue/src/views/MetaSpatialInfoEdit.vue

@@ -0,0 +1,181 @@
+<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="116px"
+					label-position="right"
+					size="small"
+					style="max-width: 500px"
+				>
+					<el-form-item prop="region" label="所属区域">
+						<el-select v-model="formData.region" clearable filterable placeholder="请选择">
+							<el-option
+								v-for="item in regionOptions"
+								:key="item.value"
+								:label="item.label"
+								:value="item.value"
+							>
+							</el-option>
+						</el-select>
+					</el-form-item>
+					<el-form-item prop="axisX" label="区域内坐标x轴">
+						<el-input v-model="formData.axisX"> </el-input>
+					</el-form-item>
+					<el-form-item prop="axisY" label="区域内坐标y轴">
+						<el-input v-model="formData.axisY"> </el-input>
+					</el-form-item>
+					<el-form-item prop="sale" label="挂售">
+						<el-switch v-model="formData.sale"> </el-switch>
+					</el-form-item>
+					<el-form-item prop="userId" label="所属用户id">
+						<el-input-number type="number" v-model="formData.userId"> </el-input-number>
+					</el-form-item>
+					<el-form-item prop="size" label="空间大小(m)²">
+						<el-input-number type="number" v-model="formData.size"> </el-input-number>
+					</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: 'MetaSpatialInfoEdit',
+	created() {
+		if (this.$route.query.id) {
+			this.$http
+				.get('metaSpatialInfo/get/' + this.$route.query.id)
+				.then(res => {
+					this.formData = res;
+				})
+				.catch(e => {
+					console.log(e);
+					this.$message.error(e.error);
+				});
+		}
+	},
+	data() {
+		return {
+			saving: false,
+			formData: {},
+			rules: {
+				region: [
+					{
+						required: true,
+						message: '请输入所属区域',
+						trigger: 'blur'
+					}
+				],
+				axisX: [
+					{
+						required: true,
+						message: '请输入区域内坐标x轴',
+						trigger: 'blur'
+					}
+				],
+				axisY: [
+					{
+						required: true,
+						message: '请输入区域内坐标y轴',
+						trigger: 'blur'
+					}
+				],
+				sale: [
+					{
+						required: true,
+						message: '请输入状态',
+						trigger: 'blur'
+					}
+				],
+				userId: [
+					{
+						required: true,
+						message: '请输入所属用户id',
+						trigger: 'blur'
+					}
+				],
+				size: [
+					{
+						required: true,
+						message: '请输入空间大小',
+						trigger: 'blur'
+					}
+				]
+			},
+			regionOptions: [
+				{ label: '1区', value: 'ONE' },
+				{ label: '2区', value: 'TWO' },
+				{ label: '3区', value: 'THREE' },
+				{ label: '4区', value: 'FOUR' },
+				{ label: '5区', value: 'FIVE' },
+				{ label: '6区', value: 'SIX' },
+				{ label: '7区', value: 'SEVEN' },
+				{ label: '8区', value: 'EIGHT' },
+				{ label: '9区', value: 'NINE' }
+			]
+		};
+	},
+	methods: {
+		onSave() {
+			this.$refs.form.validate(valid => {
+				if (valid) {
+					this.submit();
+				} else {
+					return false;
+				}
+			});
+		},
+		submit() {
+			let data = { ...this.formData };
+            console.log(data)
+			this.saving = true;
+			this.$http
+				.post('/metaSpatialInfo/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(`/metaSpatialInfo/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>

+ 203 - 0
src/main/vue/src/views/MetaSpatialInfoList.vue

@@ -0,0 +1,203 @@
+<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" label="ID" width="100"> </el-table-column>
+			<el-table-column prop="region" label="所属区域" :formatter="regionFormatter"> </el-table-column>
+			<el-table-column prop="axisX" label="区域内坐标x轴"> </el-table-column>
+			<el-table-column prop="axisY" label="区域内坐标y轴"> </el-table-column>
+			<el-table-column prop="sale" label="状态">
+				<template slot-scope="{ row }">
+					{{ row.sale ? '可售' : '未售' }} 
+				</template>
+			</el-table-column>
+			<el-table-column prop="userId" label="所属用户id"> </el-table-column>
+			<el-table-column prop="size" 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: 'MetaSpatialInfoList',
+	mixins: [pageableTable],
+	data() {
+		return {
+			multipleMode: false,
+			search: '',
+			url: '/metaSpatialInfo/all',
+			downloading: false,
+			regionOptions: [
+				{ label: '1区', value: 'ONE' },
+				{ label: '2区', value: 'TWO' },
+				{ label: '3区', value: 'THREE' },
+				{ label: '4区', value: 'FOUR' },
+				{ label: '5区', value: 'FIVE' },
+				{ label: '6区', value: 'SIX' },
+				{ label: '7区', value: 'SEVEN' },
+				{ label: '8区', value: 'EIGHT' },
+				{ label: '9区', value: 'NINE' }
+			]
+		};
+	},
+	computed: {
+		selection() {
+			return this.$refs.table.selection.map(i => i.id);
+		}
+	},
+	methods: {
+		regionFormatter(row, column, cellValue, index) {
+			let selectedOption = this.regionOptions.find(i => i.value === cellValue);
+			if (selectedOption) {
+				return selectedOption.label;
+			}
+			return '';
+		},
+		beforeGetData() {
+			return { search: this.search, query: { del: false } };
+		},
+		toggleMultipleMode(multipleMode) {
+			this.multipleMode = multipleMode;
+			if (!multipleMode) {
+				this.$refs.table.clearSelection();
+			}
+		},
+		addRow() {
+			this.$router.push({
+				path: '/metaSpatialInfoEdit',
+				query: {
+					...this.$route.query
+				}
+			});
+		},
+		editRow(row) {
+			this.$router.push({
+				path: '/metaSpatialInfoEdit',
+				query: {
+					id: row.id
+				}
+			});
+		},
+		download() {
+			this.downloading = true;
+			this.$axios
+				.get('/metaSpatialInfo/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(`/metaSpatialInfo/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>