Kaynağa Gözat

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

lidongze 2 yıl önce
ebeveyn
işleme
570569f90a

+ 34 - 0
src/main/java/com/izouma/nineth/domain/MetaProblem.java

@@ -0,0 +1,34 @@
+package com.izouma.nineth.domain;
+
+
+import com.izouma.nineth.annotations.Searchable;
+import com.izouma.nineth.enums.MetaProblemType;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+
+@AllArgsConstructor
+@NoArgsConstructor
+@Data
+@Entity
+@ApiModel("元宇宙问答")
+public class MetaProblem extends BaseEntity {
+
+    @ApiModelProperty("标题")
+    @Searchable
+    private String title;
+
+    @ApiModelProperty("答案类型")
+    @Enumerated(EnumType.STRING)
+    private MetaProblemType type;
+
+    @ApiModelProperty("答案")
+    private String answer;
+
+}

+ 17 - 0
src/main/java/com/izouma/nineth/enums/MetaProblemType.java

@@ -0,0 +1,17 @@
+package com.izouma.nineth.enums;
+
+public enum MetaProblemType {
+
+    TEXT("文本"),
+    FILE("文件");
+
+    private final String description;
+
+    MetaProblemType(String description) {
+        this.description = description;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+}

+ 18 - 0
src/main/java/com/izouma/nineth/repo/MetaProblemRepo.java

@@ -0,0 +1,18 @@
+package com.izouma.nineth.repo;
+
+import com.izouma.nineth.domain.MetaProblem;
+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 MetaProblemRepo extends JpaRepository<MetaProblem, Long>, JpaSpecificationExecutor<MetaProblem> {
+    @Query("update MetaProblem t set t.del = true where t.id = ?1")
+    @Modifying
+    @Transactional
+    void softDelete(Long id);
+
+
+}

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

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

+ 64 - 0
src/main/java/com/izouma/nineth/web/MetaProblemController.java

@@ -0,0 +1,64 @@
+package com.izouma.nineth.web;
+import com.izouma.nineth.domain.MetaProblem;
+import com.izouma.nineth.dto.PageQuery;
+import com.izouma.nineth.exception.BusinessException;
+import com.izouma.nineth.repo.MetaProblemRepo;
+import com.izouma.nineth.service.MetaProblemService;
+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;
+
+@RestController
+@RequestMapping("/metaProblem")
+@AllArgsConstructor
+public class MetaProblemController extends BaseController {
+    private MetaProblemService metaProblemService;
+    private MetaProblemRepo metaProblemRepo;
+
+    //@PreAuthorize("hasRole('ADMIN')")
+    @PostMapping("/save")
+    public MetaProblem save(@RequestBody MetaProblem record) {
+        if (record.getId() != null) {
+            MetaProblem orig = metaProblemRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
+            ObjUtils.merge(orig, record);
+            return metaProblemRepo.save(orig);
+        }
+        return metaProblemRepo.save(record);
+    }
+
+
+    //@PreAuthorize("hasRole('ADMIN')")
+    @PostMapping("/all")
+    public Page<MetaProblem> all(@RequestBody PageQuery pageQuery) {
+        return metaProblemService.all(pageQuery);
+    }
+
+    @GetMapping("/get/{id}")
+    public MetaProblem get(@PathVariable Long id) {
+        return metaProblemRepo.findById(id).orElseThrow(new BusinessException("无记录"));
+    }
+
+    @PostMapping("/del/{id}")
+    public void del(@PathVariable Long id) {
+        metaProblemRepo.softDelete(id);
+    }
+
+    @GetMapping("/excel")
+    @ResponseBody
+    public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
+        List<MetaProblem> data = all(pageQuery).getContent();
+        ExcelUtils.export(response, data);
+    }
+
+//    @GetMapping("/findAll")
+//    public List<MetaProblem> findAll(){
+//        return
+//    }
+}
+

+ 1 - 10
src/main/java/com/izouma/nineth/web/UserBalanceController.java

@@ -1,6 +1,5 @@
 package com.izouma.nineth.web;
 
-import cn.hutool.core.math.Money;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.github.kevinsawicki.http.HttpRequest;
@@ -15,29 +14,21 @@ import com.izouma.nineth.enums.PayMethod;
 import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.repo.*;
 import com.izouma.nineth.service.UserBalanceService;
-import com.izouma.nineth.utils.DateTimeUtils;
 import com.izouma.nineth.utils.JpaUtils;
 import com.izouma.nineth.utils.SecurityUtils;
 import com.izouma.nineth.utils.SnowflakeIdWorker;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.io.IOUtils;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
-import org.springframework.core.io.InputStreamResource;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.math.BigDecimal;
-import java.time.Duration;
 import java.time.LocalDate;
 import java.util.concurrent.ExecutionException;
 
@@ -57,7 +48,7 @@ public class UserBalanceController extends BaseController {
     private final SnowflakeIdWorker             snowflakeIdWorker;
 
     @PostMapping("/all")
-    @PreAuthorize("hasRole('ADMIN')")
+    @PreAuthorize("hasAnyRole('ADMIN','ORDERINFO')")
     public Page<UserBalance> all(@RequestBody PageQuery pageQuery) {
         return userBalanceRepo
                 .findAll(JpaUtils.toSpecification(pageQuery, UserBalance.class), JpaUtils.toPageRequest(pageQuery));

+ 1 - 1
src/main/java/com/izouma/nineth/web/WithdrawApplyController.java

@@ -27,7 +27,7 @@ public class WithdrawApplyController extends BaseController {
     private WithdrawApplyService withdrawApplyService;
     private WithdrawApplyRepo    withdrawApplyRepo;
 
-    @PreAuthorize("hasRole('ADMIN')")
+    @PreAuthorize("hasAnyRole('ADMIN','ORDERINFO')")
     @PostMapping("/all")
     public Page<WithdrawApply> all(@RequestBody PageQuery pageQuery) {
         return withdrawApplyService.all(pageQuery);

+ 18 - 2
src/main/vue/src/router.js

@@ -1845,7 +1845,23 @@ const router = new Router({
                     meta: {
                        title: 'NFT特效配置',
                     },
-               }
+               },
+                {
+                    path: '/metaProblemEdit',
+                    name: 'MetaProblemEdit',
+                    component: () => import(/* webpackChunkName: "metaChannelEdit" */ '@/views/MetaProblemEdit.vue'),
+                    meta: {
+                        title: '元宇宙问答编辑',
+                    },
+                },
+                {
+                    path: '/metaProblemList',
+                    name: 'MetaProblemList',
+                    component: () => import(/* webpackChunkName: "metaChannelList" */ '@/views/MetaProblemList.vue'),
+                    meta: {
+                        title: '元宇宙问答管理',
+                    },
+                }
                 /**INSERT_LOCATION**/
             ]
         },
@@ -1905,4 +1921,4 @@ router.beforeEach((to, from, next) => {
     }
 });
 
-export default router;
+export default router;

+ 137 - 0
src/main/vue/src/views/MetaProblemEdit.vue

@@ -0,0 +1,137 @@
+<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="80px" label-position="right"
+                         size="small"
+                         style="max-width: 500px;">
+                        <el-form-item prop="title" label="标题">
+                                    <el-input v-model="formData.title"></el-input>
+                        </el-form-item>
+                        <el-form-item prop="type" label="答案类型">
+                                    <el-select v-model="formData.type" clearable filterable placeholder="请选择">
+                                        <el-option
+                                                v-for="item in typeOptions"
+                                                :key="item.value"
+                                                :label="item.label"
+                                                :value="item.value">
+                                        </el-option>
+                                    </el-select>
+                        </el-form-item>
+                        <el-form-item prop="answer" label="答案">
+                        <file-upload v-model="formData.answer" v-if="formData.type === 'FILE'" :limit="1"></file-upload>
+                        <el-input v-model="formData.answer" v-if="formData.type === 'TEXT'"></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: 'MetaProblemEdit',
+        created() {
+            if (this.$route.query.id) {
+                this.$http
+                    .get('metaProblem/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: {
+                    value: ''
+                },
+                rules: {
+                    title: [
+                    {
+                        required: true,
+                        message: '请输入标题',
+                        trigger: 'blur'
+                    }
+                ],
+                type: [
+                    {
+                        required: true,
+                        message: '请选择类型',
+                        trigger: 'blur'
+                    }
+                ],
+                answer: [
+                    {
+                        required: true,
+                        message: '请输入答案或上传答案',
+                        trigger: 'blur'
+                    }
+                ]
+                },
+                typeOptions: [{"label":"文本","value":"TEXT"},{"label":"文件","value":"FILE"}],
+            }
+        },
+        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('/metaProblem/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(`/metaProblem/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>

+ 178 - 0
src/main/vue/src/views/MetaProblemList.vue

@@ -0,0 +1,178 @@
+<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="title" label="标题"
+>
+                    </el-table-column>
+                    <el-table-column prop="type" label="答案类型"
+                            :formatter="typeFormatter"
+                        >
+                    </el-table-column>
+                    <el-table-column prop="answer" 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: 'MetaProblemList',
+        mixins: [pageableTable],
+        data() {
+            return {
+                multipleMode: false,
+                search: "",
+                url: "/metaProblem/all",
+                downloading: false,
+                        typeOptions:[{"label":"文本","value":"TEXT"},{"label":"文件","value":"FILE"}],
+            }
+        },
+        computed: {
+            selection() {
+                return this.$refs.table.selection.map(i => i.id);
+            }
+        },
+        methods: {
+                    typeFormatter(row, column, cellValue, index) {
+                        let selectedOption = this.typeOptions.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: "/metaProblemEdit",
+                    query: {
+                        ...this.$route.query
+                    }
+                });
+            },
+            editRow(row) {
+                this.$router.push({
+                    path: "/metaProblemEdit",
+                    query: {
+                    id: row.id
+                    }
+                });
+            },
+            download() {
+                this.downloading = true;
+                this.$axios
+                    .get("/metaProblem/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(`/metaProblem/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>