Browse Source

管理端自建信件

master
laishajiang 2 years ago
parent
commit
7b39ee7883
  1. 8
      mailbox-outer-admin/pom.xml
  2. 3
      mailbox-outer-admin/src/main/java/com/biutag/outeradmin/config/LoginConfig.java
  3. 82
      mailbox-outer-admin/src/main/java/com/biutag/outeradmin/controller/FileController.java
  4. 1
      mailbox-outer-admin/src/main/java/com/biutag/outeradmin/controller/LoginController.java
  5. 12
      mailbox-outer-admin/src/main/java/com/biutag/outeradmin/controller/MailController.java
  6. 85
      mailbox-outer-admin/src/main/java/com/biutag/outeradmin/dto/MailBo.java
  7. 19
      mailbox-outer-admin/src/main/java/com/biutag/outeradmin/entity/Mail.java
  8. 5
      mailbox-outer-admin/src/main/java/com/biutag/outeradmin/entity/User.java
  9. 17
      mailbox-outer-admin/src/main/java/com/biutag/outeradmin/enums/MailStateEnum.java
  10. 3
      mailbox-outer-admin/src/main/java/com/biutag/outeradmin/mapper/MailMapper.java
  11. 65
      mailbox-outer-admin/src/main/java/com/biutag/outeradmin/service/MailService.java
  12. 2
      mailbox-outer-admin/src/main/java/com/biutag/outeradmin/service/UserService.java
  13. 9
      mailbox-outer-admin/src/main/resources/application.yml
  14. 4
      mailbox-outer/src/main/java/com/biutag/outer/domain/MailDraft.java

8
mailbox-outer-admin/pom.xml

@ -73,6 +73,14 @@
<artifactId>jjwt</artifactId> <artifactId>jjwt</artifactId>
<version>0.12.3</version> <version>0.12.3</version>
</dependency> </dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
</dependencies> </dependencies>

3
mailbox-outer-admin/src/main/java/com/biutag/outeradmin/config/LoginConfig.java

@ -18,7 +18,8 @@ public class LoginConfig implements WebMvcConfigurer {
interceptorRegistration.excludePathPatterns( interceptorRegistration.excludePathPatterns(
"/login", "/login",
"/captcha", "/captcha",
"/refresh-token" "/refresh-token",
"/file/stream/**"
); );
} }
} }

82
mailbox-outer-admin/src/main/java/com/biutag/outeradmin/controller/FileController.java

@ -0,0 +1,82 @@
package com.biutag.outeradmin.controller;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.biutag.config.Minio;
import com.biutag.core.AjaxResult;
import com.biutag.util.IOUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@Slf4j
@RequestMapping("file")
@Controller
public class FileController {
@Autowired(required = false)
private Minio minio;
@ResponseBody
@PostMapping("upload")
public AjaxResult<JSONObject> upload(@RequestPart("file") MultipartFile file) throws IOException {
String filepath = minio.upload(file.getInputStream(), file.getOriginalFilename());
return AjaxResult.success(JSONObject.of("filepath", filepath));
}
@ResponseBody
@PostMapping("upload/base64")
public AjaxResult<JSONObject> upload(@RequestBody JSONObject file) {
long l = System.currentTimeMillis();
log.info("文件上传开始----------------------------------------");
String base64 = file.getString("base64");
if (base64.startsWith("data:image")) {
base64 = base64.substring(base64.indexOf(",") + 1);
}
String filepath = minio.upload(base64);
log.info("文件上传耗时:{}ms", System.currentTimeMillis() - l);
return AjaxResult.success(JSONObject.of("filepath", filepath));
}
@ResponseBody
@PostMapping("upload/base64/test")
public AjaxResult<JSONObject> uploadTest(@RequestBody JSONObject file) {
long l = System.currentTimeMillis();
String base64 = file.getString("base64");
log.info("test 文件上传 base64: {}", StrUtil.isNotBlank(base64) ? base64.substring(0, Math.min(20, base64.length())) : "");
if (base64.startsWith("data:image")) {
base64 = base64.substring(base64.indexOf(",") + 1);
}
InputStream is = IOUtil.base64ToStream(base64);
try {
FileOutputStream os = new FileOutputStream("/home/jar/files/" + IdUtil.simpleUUID());
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = is.read(buffer, 0, buffer.length)) != -1) {
os.write(buffer, 0, bytesRead);
}
is.close();
os.close();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
log.info("文件上传耗时:{}ms", System.currentTimeMillis() - l);
return AjaxResult.success(JSONObject.of("filepath", "test"));
}
@GetMapping("stream/**")
public void download(HttpServletRequest request, HttpServletResponse response) throws IOException {
String requestURI = request.getRequestURI();
minio.get(requestURI.substring("/file/stream/".length()), response.getOutputStream());
}
}

1
mailbox-outer-admin/src/main/java/com/biutag/outeradmin/controller/LoginController.java

@ -8,7 +8,6 @@ import com.biutag.outeradmin.dto.TokenDTO;
import com.biutag.outeradmin.entity.User; import com.biutag.outeradmin.entity.User;
import com.biutag.outeradmin.service.UserService; import com.biutag.outeradmin.service.UserService;
import com.biutag.outeradmin.util.JwtUtil; import com.biutag.outeradmin.util.JwtUtil;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;

12
mailbox-outer-admin/src/main/java/com/biutag/outeradmin/controller/MailController.java

@ -1,9 +1,12 @@
package com.biutag.outeradmin.controller; package com.biutag.outeradmin.controller;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.biutag.core.AjaxResult;
import com.biutag.exception.BusinessException;
import com.biutag.outeradmin.dto.*; import com.biutag.outeradmin.dto.*;
import com.biutag.outeradmin.entity.*; import com.biutag.outeradmin.entity.*;
import com.biutag.outeradmin.mapper.MailMapper; import com.biutag.outeradmin.mapper.MailMapper;
@ -12,6 +15,7 @@ import com.biutag.outeradmin.util.DesensitizedUtil;
import com.biutag.outeradmin.util.ExcelUtil; import com.biutag.outeradmin.util.ExcelUtil;
import com.biutag.util.StringUtils; import com.biutag.util.StringUtils;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -42,6 +46,14 @@ public class MailController {
return result; return result;
} }
@PostMapping("add")
public AjaxResult<Boolean> add(@RequestBody String form) {
JSONObject jsonObject = JSON.parseObject(form);
JSONObject mailBo = jsonObject.getJSONObject("MailBo");
return AjaxResult.success(mailService.save(mailBo));
}
/** /**
* 根据前端表格数据查询指定信件 * 根据前端表格数据查询指定信件
* *

85
mailbox-outer-admin/src/main/java/com/biutag/outeradmin/dto/MailBo.java

@ -0,0 +1,85 @@
package com.biutag.outeradmin.dto;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson2.JSON;
import com.biutag.outeradmin.entity.Mail;
import com.biutag.validator.annotation.IdCard;
import com.biutag.validator.annotation.Phone;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.validator.constraints.Length;
import java.util.List;
@Setter
@Getter
public class MailBo {
private String id;
/**
* 联系人姓名
*/
@NotBlank(message = "联系人姓名不能为空")
@Length(min = 2, max = 20, message = "联系人姓名不符合规范(2-20字)")
private String contactName;
/**
* 联系人性别
*/
@NotBlank(message = "联系人性别不能为空")
private String contactSex;
/**
* 联系人身份证号码
*/
@IdCard
private String contactIdCard;
/**
*
*/
@Phone
private String contactPhone;
/**
* 案件编号
*/
private String caseNumber;
/**
* 内容
*/
@Length(min= 10, max = 300, message = "信件内容不符合规范(不少于10字,不多于300字)")
@NotBlank(message = "信件内容不能为空")
private String content;
/**
* 附件
*/
@Size(max = 5, message = "附件数量不能超过5")
private List<Attachment> attachments;
/**
* 涉及单位ID
*/
private Integer involvedDeptId;
/**
* 涉及单位名称
*/
private String involvedDeptName;
@Setter
@Getter
public static class Attachment {
private String filepath;
private String type;
private String originFilename;
}
}

19
mailbox-outer-admin/src/main/java/com/biutag/outeradmin/entity/Mail.java

@ -3,6 +3,7 @@ package com.biutag.outeradmin.entity;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data; import lombok.Data;
import java.time.LocalDateTime;
import java.util.Date; import java.util.Date;
@Data @Data
@ -53,7 +54,7 @@ public class Mail {
/** /**
* 创建时间 * 创建时间
*/ */
private Date createTime; private LocalDateTime createTime;
/** /**
* 更新时间 * 更新时间
@ -69,4 +70,20 @@ public class Mail {
* 是否满意 * 是否满意
*/ */
private String satisfaction; private String satisfaction;
/**
* 信件状态
*/
private String mailState;
/**
* 涉及单位ID
*/
private Integer involvedDeptId;
/**
* 涉及单位名称
*/
private String involvedDeptName;
} }

5
mailbox-outer-admin/src/main/java/com/biutag/outeradmin/entity/User.java

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;
import java.time.LocalDateTime;
import java.util.Date; import java.util.Date;
@Data @Data
@ -17,6 +18,6 @@ public class User {
private String idCard; private String idCard;
private String realName; private String realName;
private String phone; private String phone;
private Date updateTime; private LocalDateTime updateTime;
private Date faceAuthTime; private LocalDateTime faceAuthTime;
} }

17
mailbox-outer-admin/src/main/java/com/biutag/outeradmin/enums/MailStateEnum.java

@ -0,0 +1,17 @@
package com.biutag.outeradmin.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum MailStateEnum {
processing("processing", "办理中"),
terminated("terminated", "已终止"),
completion("completion", "已办结");
private String value;
private String name;
}

3
mailbox-outer-admin/src/main/java/com/biutag/outeradmin/mapper/MailMapper.java

@ -3,7 +3,10 @@ package com.biutag.outeradmin.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.biutag.outeradmin.entity.Mail; import com.biutag.outeradmin.entity.Mail;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
@Mapper @Mapper
public interface MailMapper extends BaseMapper<Mail> { public interface MailMapper extends BaseMapper<Mail> {
@Select("SELECT nextval('mail_id_seq') ")
Integer getMailIdSeqVal();
} }

65
mailbox-outer-admin/src/main/java/com/biutag/outeradmin/service/MailService.java

@ -1,10 +1,75 @@
package com.biutag.outeradmin.service; package com.biutag.outeradmin.service;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.biutag.outeradmin.entity.Mail; import com.biutag.outeradmin.entity.Mail;
import com.biutag.outeradmin.entity.User;
import com.biutag.outeradmin.enums.MailStateEnum;
import com.biutag.outeradmin.mapper.MailMapper; import com.biutag.outeradmin.mapper.MailMapper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.Date;
@Service @Service
public class MailService extends ServiceImpl<MailMapper, Mail> { public class MailService extends ServiceImpl<MailMapper, Mail> {
public final UserService userService;
public MailService(UserService userService) {
this.userService = userService;
}
@Transactional(rollbackFor = Exception.class)
public boolean save(JSONObject mailBo) {
// HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
// 获取请求头的值
// String authorization = request.getHeader("Authorization");
// String jwtToken = null;
// if (authorization.startsWith("Bearer ")) {
// // 截取并去掉"Bearer "前缀,得到JWT令牌
// jwtToken = authorization.substring(7); // 7是"Bearer "的长度
// }
// Claims claims = JwtUtil.parsePayload(jwtToken);
// String phone = claims.get("username").toString();
Mail mail = new Mail();
mail.setId(generateMailId());
mail.setCreateTime(LocalDateTime.now());
mail.setContactName(mailBo.getString("contactName"));
mail.setAttachments(mailBo.getString("attachments"));
mail.setCaseNumber(mailBo.getString("caseNumber"));
mail.setContactPhone(mailBo.getString("contactPhone"));
mail.setContactIdCard(mailBo.getString("contactIdCard"));
mail.setContactSex(mailBo.getString("contactSex"));
mail.setContent(mailBo.getString("content"));
mail.setInvolvedDeptId(Integer.parseInt(mailBo.getString("involvedDeptId")));
mail.setInvolvedDeptName(mailBo.getString("involvedDeptName"));
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("phone",mailBo.getString("contactPhone"));
User user = userService.getOne(queryWrapper, false);
if (user == null){
return false;
}
mail.setUserId(user.getId());
mail.setMailState(MailStateEnum.processing.getValue());
boolean save = save(mail);
// boolean save = true;
return save;
}
public String generateMailId() {
Integer seqVal = baseMapper.getMailIdSeqVal();
int length = 6 - seqVal.toString().length();
StringBuilder zeroString = new StringBuilder();
for (int i = 0; i < length; i++) {
zeroString.append('0');
}
// XXWW 信箱外网
return DateUtil.format(new Date(), "yyyyMMddHHMM") + "XXWW" + zeroString + seqVal;
}
} }

2
mailbox-outer-admin/src/main/java/com/biutag/outeradmin/service/UserService.java

@ -1,5 +1,6 @@
package com.biutag.outeradmin.service; package com.biutag.outeradmin.service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.biutag.outeradmin.entity.User; import com.biutag.outeradmin.entity.User;
import com.biutag.outeradmin.mapper.UserMapper; import com.biutag.outeradmin.mapper.UserMapper;
@ -7,4 +8,5 @@ import org.springframework.stereotype.Service;
@Service @Service
public class UserService extends ServiceImpl<UserMapper, User> { public class UserService extends ServiceImpl<UserMapper, User> {
} }

9
mailbox-outer-admin/src/main/resources/application.yml

@ -10,3 +10,12 @@ spring:
url: jdbc:postgresql://172.31.217.20:32378/mailbox?currentSchema=mailbox-outer url: jdbc:postgresql://172.31.217.20:32378/mailbox?currentSchema=mailbox-outer
username: vbadmin username: vbadmin
password: Ip12341234 password: Ip12341234
oss:
minio:
enable: true
endpoint: http://172.31.217.20:31401
accessKey: n8yPVAJk4yw879zi
secretKey: eElQ7gCwuNxaFhKEbtRRq0lsovoOTgI1
bucketName: mailbox

4
mailbox-outer/src/main/java/com/biutag/outer/domain/MailDraft.java

@ -68,12 +68,12 @@ public class MailDraft {
/** /**
* 涉及单位ID * 涉及单位ID
*/ */
private Integer involvedDeptId; // private Integer involvedDeptId;
/** /**
* 涉及单位名称 * 涉及单位名称
*/ */
private String involvedDeptName; // private String involvedDeptName;
@TableLogic(value = Constants.UNDELETED, delval = Constants.DELETED) @TableLogic(value = Constants.UNDELETED, delval = Constants.DELETED)
private String delFlag; private String delFlag;

Loading…
Cancel
Save