From 0dec46fc8b43c7004411832b7c7220c4fbcca7a1 Mon Sep 17 00:00:00 2001 From: nihaotian Date: Thu, 10 Oct 2024 17:21:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=99=AE=E9=80=9A=E7=94=A8=E6=88=B7=E7=94=B3?= =?UTF-8?q?=E8=AF=B7=E6=88=90=E4=B8=BA=E7=AE=A1=E7=90=86=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kening/vordm/entity/ApplyForAdmin.java | 103 ++++++++++++++++++ .../controller/ApplyForAdminController.java | 67 ++++++++++++ .../vordm/mapper/ApplyForAdminMapper.java | 11 ++ .../vordm/mapper/ApplyForAdminMapper.xml | 34 ++++++ .../vordm/mapper/DisasterInfoMapper.xml | 2 +- .../vordm/service/ApplyForAdminServer.java | 15 +++ .../service/impl/ApplyForAdminServerImpl.java | 82 ++++++++++++++ 7 files changed, 313 insertions(+), 1 deletion(-) create mode 100644 kn-service-api/biz-vordm-api/src/main/java/com/kening/vordm/entity/ApplyForAdmin.java create mode 100644 kn-service/biz-vordm/src/main/java/com/kening/vordm/controller/ApplyForAdminController.java create mode 100644 kn-service/biz-vordm/src/main/java/com/kening/vordm/mapper/ApplyForAdminMapper.java create mode 100644 kn-service/biz-vordm/src/main/java/com/kening/vordm/mapper/ApplyForAdminMapper.xml create mode 100644 kn-service/biz-vordm/src/main/java/com/kening/vordm/service/ApplyForAdminServer.java create mode 100644 kn-service/biz-vordm/src/main/java/com/kening/vordm/service/impl/ApplyForAdminServerImpl.java diff --git a/kn-service-api/biz-vordm-api/src/main/java/com/kening/vordm/entity/ApplyForAdmin.java b/kn-service-api/biz-vordm-api/src/main/java/com/kening/vordm/entity/ApplyForAdmin.java new file mode 100644 index 0000000..d8b2f40 --- /dev/null +++ b/kn-service-api/biz-vordm-api/src/main/java/com/kening/vordm/entity/ApplyForAdmin.java @@ -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; +} diff --git a/kn-service/biz-vordm/src/main/java/com/kening/vordm/controller/ApplyForAdminController.java b/kn-service/biz-vordm/src/main/java/com/kening/vordm/controller/ApplyForAdminController.java new file mode 100644 index 0000000..a8ee7e3 --- /dev/null +++ b/kn-service/biz-vordm/src/main/java/com/kening/vordm/controller/ApplyForAdminController.java @@ -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 selectByUserId(Long id){ + return R.data(applyForAdminServer.selectByUserId(id)); + } + + + /** + * 查询申请列表 + */ + @GetMapping("/pages") + public R> pages(Query query, @RequestParam Map params){ + return R.data(applyForAdminServer.page(Condition.getPage(query),Condition.getQueryWrapper(params,ApplyForAdmin.class))); + } +} diff --git a/kn-service/biz-vordm/src/main/java/com/kening/vordm/mapper/ApplyForAdminMapper.java b/kn-service/biz-vordm/src/main/java/com/kening/vordm/mapper/ApplyForAdminMapper.java new file mode 100644 index 0000000..1a89b16 --- /dev/null +++ b/kn-service/biz-vordm/src/main/java/com/kening/vordm/mapper/ApplyForAdminMapper.java @@ -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 selectByUserId(@Param("userId") Long userId); + + void updateUserRoleID(@Param("userId") Long userId); +} diff --git a/kn-service/biz-vordm/src/main/java/com/kening/vordm/mapper/ApplyForAdminMapper.xml b/kn-service/biz-vordm/src/main/java/com/kening/vordm/mapper/ApplyForAdminMapper.xml new file mode 100644 index 0000000..54ed5db --- /dev/null +++ b/kn-service/biz-vordm/src/main/java/com/kening/vordm/mapper/ApplyForAdminMapper.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + update blade_user set role_id = '1123598816738675203' where id = #{userId} + + diff --git a/kn-service/biz-vordm/src/main/java/com/kening/vordm/mapper/DisasterInfoMapper.xml b/kn-service/biz-vordm/src/main/java/com/kening/vordm/mapper/DisasterInfoMapper.xml index c90a26e..fb5f731 100644 --- a/kn-service/biz-vordm/src/main/java/com/kening/vordm/mapper/DisasterInfoMapper.xml +++ b/kn-service/biz-vordm/src/main/java/com/kening/vordm/mapper/DisasterInfoMapper.xml @@ -50,7 +50,7 @@ - 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}); diff --git a/kn-service/biz-vordm/src/main/java/com/kening/vordm/service/ApplyForAdminServer.java b/kn-service/biz-vordm/src/main/java/com/kening/vordm/service/ApplyForAdminServer.java new file mode 100644 index 0000000..abc2ffe --- /dev/null +++ b/kn-service/biz-vordm/src/main/java/com/kening/vordm/service/ApplyForAdminServer.java @@ -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 { + void SendAnApplication(ApplyForAdmin applyForAdmin); + + ApplyForAdmin selectByUserId(Long userId); + + void updateApplyForAdminData(ApplyForAdmin applyForAdmin); + + void auditAnApplication(ApplyForAdmin applyForAdmin); +} diff --git a/kn-service/biz-vordm/src/main/java/com/kening/vordm/service/impl/ApplyForAdminServerImpl.java b/kn-service/biz-vordm/src/main/java/com/kening/vordm/service/impl/ApplyForAdminServerImpl.java new file mode 100644 index 0000000..56c8d87 --- /dev/null +++ b/kn-service/biz-vordm/src/main/java/com/kening/vordm/service/impl/ApplyForAdminServerImpl.java @@ -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 + 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); + } +}