xiongzhu 4 år sedan
förälder
incheckning
7951cfda58

+ 35 - 0
src/main/java/com/izouma/nineth/domain/IdentityAuth.java

@@ -0,0 +1,35 @@
+package com.izouma.nineth.domain;
+
+import com.izouma.nineth.enums.AuthStatus;
+import io.swagger.annotations.ApiModel;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.Entity;
+
+@Data
+@Entity
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+@ApiModel("身份认证")
+public class IdentityAuth extends BaseEntity {
+    private Long userId;
+
+    private String realName;
+
+    private String phone;
+
+    private String email;
+
+    private String idNo;
+
+    private String idFront;
+
+    private String idBack;
+
+    private AuthStatus status;
+
+}

+ 6 - 0
src/main/java/com/izouma/nineth/domain/User.java

@@ -4,6 +4,7 @@ import com.alibaba.excel.annotation.ExcelIgnore;
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.izouma.nineth.annotations.Searchable;
 import com.izouma.nineth.config.Constants;
+import com.izouma.nineth.enums.AuthStatus;
 import com.izouma.nineth.security.Authority;
 import io.swagger.annotations.ApiModel;
 import lombok.AllArgsConstructor;
@@ -77,4 +78,9 @@ public class User extends BaseEntity implements Serializable {
 
     private String bg;
 
+    private String realName;
+
+    private AuthStatus authStatus;
+
+
 }

+ 18 - 0
src/main/java/com/izouma/nineth/enums/AuthStatus.java

@@ -0,0 +1,18 @@
+package com.izouma.nineth.enums;
+
+public enum AuthStatus {
+    NOT_AUTH("未认证"),
+    PENDING("认证中"),
+    SUCCESS("已认证"),
+    FAIL("失败");
+
+    private final String description;
+
+    AuthStatus(String description) {
+        this.description = description;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+}

+ 22 - 0
src/main/java/com/izouma/nineth/repo/IdentityAuthRepo.java

@@ -0,0 +1,22 @@
+package com.izouma.nineth.repo;
+
+import com.izouma.nineth.domain.IdentityAuth;
+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;
+import java.util.Optional;
+
+public interface IdentityAuthRepo extends JpaRepository<IdentityAuth, Long>, JpaSpecificationExecutor<IdentityAuth> {
+    @Query("update IdentityAuth t set t.del = true where t.id = ?1")
+    @Modifying
+    @Transactional
+    void softDelete(Long id);
+
+    List<IdentityAuth> findByUserIdAndDelFalse(Long userId);
+
+    Optional<IdentityAuth> findByIdAndDelFalse(Long id);
+}

+ 56 - 0
src/main/java/com/izouma/nineth/service/IdentityAuthService.java

@@ -0,0 +1,56 @@
+package com.izouma.nineth.service;
+
+import com.izouma.nineth.domain.IdentityAuth;
+import com.izouma.nineth.domain.User;
+import com.izouma.nineth.dto.PageQuery;
+import com.izouma.nineth.enums.AuthStatus;
+import com.izouma.nineth.exception.BusinessException;
+import com.izouma.nineth.repo.IdentityAuthRepo;
+import com.izouma.nineth.repo.UserRepo;
+import com.izouma.nineth.utils.JpaUtils;
+import lombok.AllArgsConstructor;
+import org.springframework.data.domain.Page;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+@AllArgsConstructor
+public class IdentityAuthService {
+
+    private IdentityAuthRepo identityAuthRepo;
+    private UserRepo         userRepo;
+
+    public Page<IdentityAuth> all(PageQuery pageQuery) {
+        return identityAuthRepo.findAll(JpaUtils.toSpecification(pageQuery, IdentityAuth.class), JpaUtils.toPageRequest(pageQuery));
+    }
+
+    public void apply(IdentityAuth identityAuth) {
+        if (identityAuth.getUserId() == null) {
+            throw new BusinessException("用户不存在");
+        }
+        User user = userRepo.findByIdAndDelFalse(identityAuth.getUserId()).orElseThrow(new BusinessException("用户不存在"));
+        List<IdentityAuth> auths = identityAuthRepo.findByUserIdAndDelFalse(identityAuth.getUserId());
+        auths.stream().filter(auth -> auth.getStatus() == AuthStatus.PENDING).findAny().ifPresent(a -> {
+            throw new BusinessException("正在审核中,请勿重复提交");
+        });
+        auths.stream().filter(auth -> auth.getStatus() == AuthStatus.SUCCESS).findAny().ifPresent(a -> {
+            throw new BusinessException("已认证,请勿重复提交");
+        });
+        identityAuthRepo.save(identityAuth);
+        user.setAuthStatus(AuthStatus.PENDING);
+        userRepo.save(user);
+    }
+
+    public void audit(Long id, AuthStatus status) {
+        IdentityAuth auth = identityAuthRepo.findByIdAndDelFalse(id).orElseThrow(new BusinessException("申请不存在"));
+        if (auth.getStatus() != AuthStatus.PENDING) {
+            throw new BusinessException("已经审核过");
+        }
+        User user = userRepo.findByIdAndDelFalse(auth.getUserId()).orElseThrow(new BusinessException("用户不存在"));
+        auth.setStatus(status);
+        identityAuthRepo.save(auth);
+        user.setAuthStatus(status);
+        userRepo.save(user);
+    }
+}

+ 72 - 0
src/main/java/com/izouma/nineth/web/IdentityAuthController.java

@@ -0,0 +1,72 @@
+package com.izouma.nineth.web;
+
+import com.izouma.nineth.domain.IdentityAuth;
+import com.izouma.nineth.enums.AuthStatus;
+import com.izouma.nineth.service.IdentityAuthService;
+import com.izouma.nineth.dto.PageQuery;
+import com.izouma.nineth.exception.BusinessException;
+import com.izouma.nineth.repo.IdentityAuthRepo;
+import com.izouma.nineth.utils.ObjUtils;
+import com.izouma.nineth.utils.SecurityUtils;
+import com.izouma.nineth.utils.excel.ExcelUtils;
+import lombok.AllArgsConstructor;
+import org.springframework.data.domain.Page;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+
+@RestController
+@RequestMapping("/identityAuth")
+@AllArgsConstructor
+public class IdentityAuthController extends BaseController {
+    private IdentityAuthService identityAuthService;
+    private IdentityAuthRepo    identityAuthRepo;
+
+    @PreAuthorize("hasRole('ADMIN')")
+    @PostMapping("/all")
+    public Page<IdentityAuth> all(@RequestBody PageQuery pageQuery) {
+        return identityAuthService.all(pageQuery);
+    }
+
+    @PreAuthorize("hasRole('ADMIN')")
+    @GetMapping("/get/{id}")
+    public IdentityAuth get(@PathVariable Long id) {
+        return identityAuthRepo.findById(id).orElseThrow(new BusinessException("无记录"));
+    }
+
+    @PreAuthorize("hasRole('ADMIN')")
+    @PostMapping("/del/{id}")
+    public void del(@PathVariable Long id) {
+        identityAuthRepo.softDelete(id);
+    }
+
+    @PreAuthorize("hasRole('ADMIN')")
+    @GetMapping("/excel")
+    @ResponseBody
+    public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
+        List<IdentityAuth> data = all(pageQuery).getContent();
+        ExcelUtils.export(response, data);
+    }
+
+    @PostMapping("/apply")
+    public void apply(@RequestBody IdentityAuth identityAuth) {
+        identityAuth.setUserId(SecurityUtils.getAuthenticatedUser().getId());
+        identityAuthService.apply(identityAuth);
+    }
+
+    @PreAuthorize("hasRole('ADMIN')")
+    @PostMapping("/pass")
+    public void audit(@RequestParam Long id) {
+        identityAuthService.audit(id, AuthStatus.SUCCESS);
+    }
+
+    @PreAuthorize("hasRole('ADMIN')")
+    @PostMapping("/deny")
+    public void deny(@RequestParam Long id) {
+        identityAuthService.audit(id, AuthStatus.FAIL);
+    }
+}
+

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

@@ -0,0 +1 @@
+{"tableName":"IdentityAuth","className":"IdentityAuth","remark":"身份认证","genTable":true,"genClass":true,"genList":true,"genForm":true,"genRouter":true,"javaPath":"/Users/drew/Projects/Java/9th/src/main/java/com/izouma/nineth","viewPath":"/Users/drew/Projects/Java/9th/src/main/vue/src/views","routerPath":"/Users/drew/Projects/Java/9th/src/main/vue/src","resourcesPath":"/Users/drew/Projects/Java/9th/src/main/resources","dataBaseType":"Mysql","fields":[{"name":"userId","modelName":"userId","remark":"userId","showInList":true,"showInForm":true,"formType":"number"},{"name":"realName","modelName":"realName","remark":"realName","showInList":true,"showInForm":true,"formType":"singleLineText"},{"name":"phone","modelName":"phone","remark":"phone","showInList":true,"showInForm":true,"formType":"singleLineText"},{"name":"email","modelName":"email","remark":"email","showInList":true,"showInForm":true,"formType":"singleLineText"},{"name":"idNo","modelName":"idNo","remark":"idNo","showInList":true,"showInForm":true,"formType":"singleLineText"},{"name":"idFront","modelName":"idFront","remark":"idFront","showInList":true,"showInForm":true,"formType":"singleLineText"},{"name":"idBack","modelName":"idBack","remark":"idBack","showInList":true,"showInForm":true,"formType":"singleLineText"},{"name":"status","modelName":"status","remark":"status","showInList":true,"showInForm":true,"formType":"select","apiFlag":"1","optionsValue":"[{\"label\":\"未认证\",\"value\":\"NOT_AUTH\"},{\"label\":\"认证中\",\"value\":\"PENDING\"},{\"label\":\"已认证\",\"value\":\"AUTHED\"}]"}],"readTable":false,"dataSourceCode":"dataSource","genJson":"","subtables":[],"update":false,"basePackage":"com.izouma.nineth","tablePackage":"com.izouma.nineth.domain.IdentityAuth"}

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

@@ -230,7 +230,23 @@ const router = new Router({
                     meta: {
                         title: '铸造者列表'
                     }
-                }
+                },
+                {
+                    path: '/identityAuthEdit',
+                    name: 'IdentityAuthEdit',
+                    component: () => import(/* webpackChunkName: "identityAuthEdit" */ '@/views/IdentityAuthEdit.vue'),
+                    meta: {
+                       title: '身份认证编辑',
+                    },
+                },
+                {
+                    path: '/identityAuthList',
+                    name: 'IdentityAuthList',
+                    component: () => import(/* webpackChunkName: "identityAuthList" */ '@/views/IdentityAuthList.vue'),
+                    meta: {
+                       title: '身份认证',
+                    },
+               }
                 /**INSERT_LOCATION**/
             ]
         },
@@ -282,4 +298,4 @@ router.beforeEach((to, from, next) => {
     }
 });
 
-export default router;
+export default router;

+ 129 - 0
src/main/vue/src/views/IdentityAuthEdit.vue

@@ -0,0 +1,129 @@
+<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="88px" label-position="right"
+                         size="small"
+                         style="max-width: 500px;">
+                        <el-form-item prop="userId" label="userId">
+                                    <el-input-number type="number" v-model="formData.userId"></el-input-number>
+                        </el-form-item>
+                        <el-form-item prop="realName" label="realName">
+                                    <el-input v-model="formData.realName"></el-input>
+                        </el-form-item>
+                        <el-form-item prop="phone" label="phone">
+                                    <el-input v-model="formData.phone"></el-input>
+                        </el-form-item>
+                        <el-form-item prop="email" label="email">
+                                    <el-input v-model="formData.email"></el-input>
+                        </el-form-item>
+                        <el-form-item prop="idNo" label="idNo">
+                                    <el-input v-model="formData.idNo"></el-input>
+                        </el-form-item>
+                        <el-form-item prop="idFront" label="idFront">
+                                    <el-input v-model="formData.idFront"></el-input>
+                        </el-form-item>
+                        <el-form-item prop="idBack" label="idBack">
+                                    <el-input v-model="formData.idBack"></el-input>
+                        </el-form-item>
+                        <el-form-item prop="status" label="status">
+                                    <el-select v-model="formData.status" clearable filterable placeholder="请选择">
+                                        <el-option
+                                                v-for="item in statusOptions"
+                                                :key="item.value"
+                                                :label="item.label"
+                                                :value="item.value">
+                                        </el-option>
+                                    </el-select>
+                        </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: 'IdentityAuthEdit',
+        created() {
+            if (this.$route.query.id) {
+                this.$http
+                    .get('identityAuth/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: {
+                },
+                statusOptions: [{"label":"未认证","value":"NOT_AUTH"},{"label":"认证中","value":"PENDING"},{"label":"已认证","value":"AUTHED"}],
+            }
+        },
+        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('/identityAuth/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(`/identityAuth/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>

+ 193 - 0
src/main/vue/src/views/IdentityAuthList.vue

@@ -0,0 +1,193 @@
+<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="userId" label="userId"
+>
+                    </el-table-column>
+                    <el-table-column prop="realName" label="realName"
+>
+                    </el-table-column>
+                    <el-table-column prop="phone" label="phone"
+>
+                    </el-table-column>
+                    <el-table-column prop="email" label="email"
+>
+                    </el-table-column>
+                    <el-table-column prop="idNo" label="idNo"
+>
+                    </el-table-column>
+                    <el-table-column prop="idFront" label="idFront"
+>
+                    </el-table-column>
+                    <el-table-column prop="idBack" label="idBack"
+>
+                    </el-table-column>
+                    <el-table-column prop="status" label="status"
+                            :formatter="statusFormatter"
+                        >
+                    </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: 'IdentityAuthList',
+        mixins: [pageableTable],
+        data() {
+            return {
+                multipleMode: false,
+                search: "",
+                url: "/identityAuth/all",
+                downloading: false,
+                        statusOptions:[{"label":"未认证","value":"NOT_AUTH"},{"label":"认证中","value":"PENDING"},{"label":"已认证","value":"AUTHED"}],
+            }
+        },
+        computed: {
+            selection() {
+                return this.$refs.table.selection.map(i => i.id);
+            }
+        },
+        methods: {
+                    statusFormatter(row, column, cellValue, index) {
+                        let selectedOption = this.statusOptions.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: "/identityAuthEdit",
+                    query: {
+                        ...this.$route.query
+                    }
+                });
+            },
+            editRow(row) {
+                this.$router.push({
+                    path: "/identityAuthEdit",
+                    query: {
+                    id: row.id
+                    }
+                });
+            },
+            download() {
+                this.downloading = true;
+                this.$axios
+                    .get("/identityAuth/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(`/identityAuth/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>