普通用户申请成为管理员
This commit is contained in:
parent
13f29b03f2
commit
0dec46fc8b
|
@ -0,0 +1,103 @@
|
|||
package com.kening.vordm.entity;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.alibaba.excel.annotation.format.DateTimeFormat;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import org.springblade.common.converter.DateConverter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 用户申请管理员信息
|
||||
*/
|
||||
@Data
|
||||
@TableName(value = "blade_apply_for_admin")
|
||||
public class ApplyForAdmin implements Serializable {
|
||||
/**
|
||||
* 数据自增列
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 申请用户id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户姓
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String realName;
|
||||
/**
|
||||
* 用户账号
|
||||
*/
|
||||
private String account;
|
||||
|
||||
/**
|
||||
* 用户国家
|
||||
*/
|
||||
private String country;
|
||||
|
||||
/**
|
||||
* 组织机构
|
||||
*/
|
||||
private String organization;
|
||||
|
||||
/**
|
||||
* 工作
|
||||
*/
|
||||
private String occupation;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 学历
|
||||
*/
|
||||
private String education;
|
||||
|
||||
/**
|
||||
* 研究领域
|
||||
*/
|
||||
private String researchField;
|
||||
|
||||
/**
|
||||
* 申请简介
|
||||
*/
|
||||
private String introduction;
|
||||
|
||||
/**
|
||||
* 申请状态(0:审核中,1:审核拒绝,2:审核通过)
|
||||
*/
|
||||
private Integer applyForStatus;
|
||||
|
||||
/**
|
||||
* 申请人邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 拒绝原因
|
||||
*/
|
||||
private String reasons;
|
||||
|
||||
/**
|
||||
* 提交时间
|
||||
*/
|
||||
@DateTimeFormat("yyyy-MM-dd HH:mm:ss")
|
||||
private Date submitTime;
|
||||
|
||||
/**
|
||||
* 提交时间
|
||||
*/
|
||||
@DateTimeFormat("yyyy-MM-dd HH:mm:ss")
|
||||
private Date auditTime;
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package com.kening.vordm.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.kening.vordm.entity.ApplyForAdmin;
|
||||
import com.kening.vordm.service.ApplyForAdminServer;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springblade.core.mp.support.Condition;
|
||||
import org.springblade.core.mp.support.Query;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.core.tool.utils.DateUtil;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/ui/applyForAdmin")
|
||||
@RequiredArgsConstructor
|
||||
public class ApplyForAdminController {
|
||||
|
||||
private final ApplyForAdminServer applyForAdminServer;
|
||||
|
||||
/**
|
||||
* 开始审核管理员申请
|
||||
* @param applyForAdmin
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/auditAnApplication")
|
||||
public void auditAnApplication (@RequestBody ApplyForAdmin applyForAdmin){
|
||||
applyForAdminServer.auditAnApplication(applyForAdmin);
|
||||
}
|
||||
|
||||
@PostMapping("/SendAnApplication")
|
||||
public R SendAnApplication (@RequestBody ApplyForAdmin applyForAdmin){
|
||||
applyForAdmin.setSubmitTime(new Date());
|
||||
ApplyForAdmin apply = applyForAdminServer.selectByUserId(applyForAdmin.getUserId());
|
||||
if (apply!=null){
|
||||
if (apply.getApplyForStatus()==0){//审核中
|
||||
return R.data("under review");
|
||||
}
|
||||
if (apply.getApplyForStatus()==1){//审核拒绝,再次申请
|
||||
applyForAdmin.setId(apply.getId());
|
||||
applyForAdminServer.updateApplyForAdminData(applyForAdmin);
|
||||
return R.data("submit successfully,Please wait for review!");
|
||||
}
|
||||
if (apply.getApplyForStatus()==2){//审核通过
|
||||
return R.data("Have passed the review, do not repeat submission");
|
||||
}
|
||||
}
|
||||
applyForAdminServer.SendAnApplication(applyForAdmin);
|
||||
return R.data("submit successfully,Please wait for review!");
|
||||
}
|
||||
|
||||
@GetMapping("selectByUserId")
|
||||
public R<ApplyForAdmin> selectByUserId(Long id){
|
||||
return R.data(applyForAdminServer.selectByUserId(id));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询申请列表
|
||||
*/
|
||||
@GetMapping("/pages")
|
||||
public R<IPage<ApplyForAdmin>> pages(Query query, @RequestParam Map<String,Object> params){
|
||||
return R.data(applyForAdminServer.page(Condition.getPage(query),Condition.getQueryWrapper(params,ApplyForAdmin.class)));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.kening.vordm.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.kening.vordm.entity.ApplyForAdmin;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
public interface ApplyForAdminMapper extends BaseMapper<ApplyForAdmin> {
|
||||
ApplyForAdmin selectByUserId(@Param("userId") Long userId);
|
||||
|
||||
void updateUserRoleID(@Param("userId") Long userId);
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.kening.vordm.mapper.ApplyForAdminMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.kening.vordm.entity.ApplyForAdmin">
|
||||
<id property="id" column="id" jdbcType="BIGINT"/>
|
||||
<result property="userId" column="user_id" jdbcType="BIGINT"/>
|
||||
<result property="introduction" column="introduction" jdbcType="VARCHAR"/>
|
||||
<result property="applyForStatus" column="apply_for_status" jdbcType="INTEGER"/>
|
||||
<result property="email" column="email" jdbcType="VARCHAR"/>
|
||||
<result property="name" column="name" jdbcType="VARCHAR"/>
|
||||
<result property="realName" column="real_name" jdbcType="VARCHAR"/>
|
||||
<result property="account" column="account" jdbcType="VARCHAR"/>
|
||||
<result property="country" column="country" jdbcType="VARCHAR"/>
|
||||
<result property="organization" column="organization" jdbcType="VARCHAR"/>
|
||||
<result property="occupation" column="occupation" jdbcType="VARCHAR"/>
|
||||
<result property="phone" column="phone" jdbcType="VARCHAR"/>
|
||||
<result property="education" column="education" jdbcType="VARCHAR"/>
|
||||
<result property="researchField" column="research_field" jdbcType="VARCHAR"/>
|
||||
<result property="reasons" column="reasons" jdbcType="VARCHAR"/>
|
||||
<result property="submitTime" column="submit_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="auditTime" column="audit_time" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectByUserId" resultType="com.kening.vordm.entity.ApplyForAdmin">
|
||||
select * from blade_apply_for_admin where user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<update id="updateUserRoleID">
|
||||
update blade_user set role_id = '1123598816738675203' where id = #{userId}
|
||||
</update>
|
||||
</mapper>
|
|
@ -50,7 +50,7 @@
|
|||
</sql>
|
||||
|
||||
<insert id="saveUserData">
|
||||
insert into blade_user (tenant_id, password, email, status, is_deleted, role_id, code, name)
|
||||
insert into blade_user (tenant_id, password, email, status, is_deleted, role_id, country, name)
|
||||
values (#{userVo.tenantId}, #{userVo.password}, #{userVo.email}, 1, 0, #{userVo.roleId}, #{userVo.country},
|
||||
#{userVo.name});
|
||||
</insert>
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package com.kening.vordm.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.kening.vordm.entity.ApplyForAdmin;
|
||||
import org.springblade.core.tool.api.R;
|
||||
|
||||
public interface ApplyForAdminServer extends IService<ApplyForAdmin> {
|
||||
void SendAnApplication(ApplyForAdmin applyForAdmin);
|
||||
|
||||
ApplyForAdmin selectByUserId(Long userId);
|
||||
|
||||
void updateApplyForAdminData(ApplyForAdmin applyForAdmin);
|
||||
|
||||
void auditAnApplication(ApplyForAdmin applyForAdmin);
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
package com.kening.vordm.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.kening.vordm.entity.ApplyForAdmin;
|
||||
import com.kening.vordm.entity.Email;
|
||||
import com.kening.vordm.mapper.ApplyForAdminMapper;
|
||||
import com.kening.vordm.service.AdministratorService;
|
||||
import com.kening.vordm.service.ApplyForAdminServer;
|
||||
import com.kening.vordm.service.EmailService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.core.tool.utils.DigestUtil;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ApplyForAdminServerImpl extends ServiceImpl<ApplyForAdminMapper, ApplyForAdmin>
|
||||
implements ApplyForAdminServer {
|
||||
|
||||
@Resource
|
||||
JavaMailSender javaMailSender;
|
||||
|
||||
@Resource
|
||||
EmailService emailService;
|
||||
|
||||
@Resource
|
||||
AdministratorService administratorService;
|
||||
|
||||
@Override
|
||||
public void SendAnApplication(ApplyForAdmin applyForAdmin) {
|
||||
baseMapper.insert(applyForAdmin);
|
||||
/*Email email = new Email();
|
||||
email.setSubject("Your login password has been updated");
|
||||
email.setText("Your login password has been updated to:“admin@#”");
|
||||
email.setHtmlText(false);
|
||||
email.setTos(applyForAdmin.getEmail().split(","));
|
||||
try {
|
||||
emailService.sendMimeMessage(email);
|
||||
} catch (Exception e) {
|
||||
log.error("发送邮件失败:{}", e);
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplyForAdmin selectByUserId(Long userId) {
|
||||
return baseMapper.selectByUserId(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateApplyForAdminData(ApplyForAdmin applyForAdmin) {
|
||||
baseMapper.updateById(applyForAdmin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void auditAnApplication(ApplyForAdmin applyForAdmin) {
|
||||
Email email = new Email();
|
||||
email.setSubject("VORDM:Administrator application result");
|
||||
email.setHtmlText(false);
|
||||
email.setTos(applyForAdmin.getEmail().split(","));
|
||||
applyForAdmin.setAuditTime(new Date());
|
||||
if (applyForAdmin.getApplyForStatus()==1){
|
||||
//审核不通过
|
||||
email.setText("Failed to apply to become administrator. the reason for refusal:"+applyForAdmin.getReasons());
|
||||
}else if (applyForAdmin.getApplyForStatus()==2){
|
||||
//审核通过
|
||||
email.setText("Congratulations on becoming an administrator. Please log in again to load the administrator identity!");
|
||||
baseMapper.updateUserRoleID(applyForAdmin.getUserId());
|
||||
}
|
||||
try {
|
||||
emailService.sendMimeMessage(email);
|
||||
} catch (Exception e) {
|
||||
log.error("发送邮件失败:{}", e);
|
||||
}
|
||||
baseMapper.updateById(applyForAdmin);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue