14 changed files with 309 additions and 8 deletions
@ -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()); |
||||
} |
||||
|
||||
} |
||||
@ -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; |
||||
} |
||||
|
||||
} |
||||
@ -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; |
||||
|
||||
} |
||||
@ -1,10 +1,75 @@
|
||||
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.biutag.outeradmin.entity.Mail; |
||||
import com.biutag.outeradmin.entity.User; |
||||
import com.biutag.outeradmin.enums.MailStateEnum; |
||||
import com.biutag.outeradmin.mapper.MailMapper; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
import java.time.LocalDateTime; |
||||
import java.util.Date; |
||||
|
||||
@Service |
||||
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; |
||||
} |
||||
|
||||
|
||||
} |
||||
|
||||
Loading…
Reference in new issue