|
|
@@ -0,0 +1,161 @@
|
|
|
+package com.storlead.mail.controller;
|
|
|
+
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.storlead.framework.common.result.Result;
|
|
|
+import com.storlead.framework.util.LoginUserUtil;
|
|
|
+import com.storlead.mail.pojo.dto.EmailSignatureDTO;
|
|
|
+import com.storlead.mail.pojo.entity.EmailSignatureEntity;
|
|
|
+import com.storlead.mail.service.EmailSignatureService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.log4j.Log4j2;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 邮件签名增删改查
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/email/signature")
|
|
|
+@Api(tags = "邮件: 邮件签名")
|
|
|
+@Log4j2
|
|
|
+public class MailSignatureApiController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private EmailSignatureService emailSignatureService;
|
|
|
+
|
|
|
+ @PostMapping("/pageLlist")
|
|
|
+ @ApiOperation("分页查询邮件签名")
|
|
|
+ public Result<?> pageList(EmailSignatureDTO dto) {
|
|
|
+ Long currentUserId = LoginUserUtil.getCurrentUserId();
|
|
|
+ Page<EmailSignatureEntity> page = new Page<>(dto.getPageIndex(), dto.getPageSize());
|
|
|
+ LambdaQueryWrapper<EmailSignatureEntity> queryWrapper = buildQuery(dto, currentUserId);
|
|
|
+ IPage<EmailSignatureEntity> pageList = emailSignatureService.page(page, queryWrapper);
|
|
|
+ return Result.result(pageList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/list")
|
|
|
+ @ApiOperation("列表查询(精简字段)")
|
|
|
+ public Result<?> list(EmailSignatureDTO dto) {
|
|
|
+ Long currentUserId = LoginUserUtil.getCurrentUserId();
|
|
|
+ Page<EmailSignatureEntity> page = new Page<>(dto.getPageIndex(), dto.getPageSize());
|
|
|
+ LambdaQueryWrapper<EmailSignatureEntity> queryWrapper = buildQuery(dto, currentUserId);
|
|
|
+ queryWrapper.select(
|
|
|
+ EmailSignatureEntity::getId,
|
|
|
+ EmailSignatureEntity::getSignatureTitle,
|
|
|
+ EmailSignatureEntity::getIsDefault,
|
|
|
+ EmailSignatureEntity::getSmtpPopId,
|
|
|
+ EmailSignatureEntity::getEnabled,
|
|
|
+ EmailSignatureEntity::getSort,
|
|
|
+ EmailSignatureEntity::getCreateTime,
|
|
|
+ EmailSignatureEntity::getUpdateTime
|
|
|
+ );
|
|
|
+ IPage<EmailSignatureEntity> pageList = emailSignatureService.page(page, queryWrapper);
|
|
|
+ return Result.result(pageList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/getById")
|
|
|
+ @ApiOperation("签名详情")
|
|
|
+ public Result<?> getById(Long id) {
|
|
|
+ EmailSignatureEntity entity = emailSignatureService.getById(id);
|
|
|
+ return Result.result(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/getDefault")
|
|
|
+ @ApiOperation("获取当前用户默认签名(可选 smtpPopId)")
|
|
|
+ public Result<?> getDefault(Long smtpPopId) {
|
|
|
+ Long currentUserId = LoginUserUtil.getCurrentUserId();
|
|
|
+ LambdaQueryWrapper<EmailSignatureEntity> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(EmailSignatureEntity::getOwnerBy, currentUserId);
|
|
|
+ queryWrapper.eq(EmailSignatureEntity::getIsDelete, 0);
|
|
|
+ queryWrapper.eq(EmailSignatureEntity::getEnabled, true);
|
|
|
+ queryWrapper.eq(EmailSignatureEntity::getIsDefault, 1);
|
|
|
+ if (Objects.nonNull(smtpPopId)) {
|
|
|
+ queryWrapper.eq(EmailSignatureEntity::getSmtpPopId, smtpPopId);
|
|
|
+ } else {
|
|
|
+ queryWrapper.isNull(EmailSignatureEntity::getSmtpPopId);
|
|
|
+ }
|
|
|
+ queryWrapper.last("limit 1");
|
|
|
+ EmailSignatureEntity entity = emailSignatureService.getOne(queryWrapper);
|
|
|
+ return Result.result(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/save")
|
|
|
+ @ApiOperation("新增或更新签名")
|
|
|
+ public Result<?> save(@RequestBody EmailSignatureEntity entity) {
|
|
|
+ if (StrUtil.isBlank(entity.getSignatureTitle())) {
|
|
|
+ return Result.error("签名名称不能为空");
|
|
|
+ }
|
|
|
+ emailSignatureService.saveSignature(entity);
|
|
|
+ return Result.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/deleteIds")
|
|
|
+ @ApiOperation("逻辑删除")
|
|
|
+ public Result<?> delete(Long[] ids) {
|
|
|
+ if (Objects.isNull(ids) || ids.length == 0) {
|
|
|
+ return Result.error("参数错误");
|
|
|
+ }
|
|
|
+ emailSignatureService.lgDelete(Arrays.asList(ids));
|
|
|
+ return Result.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/enabled")
|
|
|
+ @ApiOperation("启用或禁用")
|
|
|
+ public Result<?> enabled(Long id, Boolean enable) {
|
|
|
+ if (Objects.isNull(id)) {
|
|
|
+ return Result.error("参数错误");
|
|
|
+ }
|
|
|
+ LambdaUpdateWrapper<EmailSignatureEntity> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.set(EmailSignatureEntity::getEnabled, enable);
|
|
|
+ updateWrapper.eq(EmailSignatureEntity::getId, id);
|
|
|
+ emailSignatureService.update(updateWrapper);
|
|
|
+ return Result.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/setDefault")
|
|
|
+ @ApiOperation("设为默认签名")
|
|
|
+ public Result<?> setDefault(Long id) {
|
|
|
+ if (Objects.isNull(id)) {
|
|
|
+ return Result.error("参数错误");
|
|
|
+ }
|
|
|
+ EmailSignatureEntity entity = emailSignatureService.getById(id);
|
|
|
+ if (entity == null || Objects.equals(entity.getIsDelete(), 1)) {
|
|
|
+ return Result.error("签名不存在");
|
|
|
+ }
|
|
|
+ entity.setIsDefault(1);
|
|
|
+ emailSignatureService.saveSignature(entity);
|
|
|
+ return Result.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ private LambdaQueryWrapper<EmailSignatureEntity> buildQuery(EmailSignatureDTO dto, Long currentUserId) {
|
|
|
+ LambdaQueryWrapper<EmailSignatureEntity> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(EmailSignatureEntity::getOwnerBy, currentUserId);
|
|
|
+ queryWrapper.eq(EmailSignatureEntity::getIsDelete, 0);
|
|
|
+ if (StrUtil.isNotBlank(dto.getSignatureTitle())) {
|
|
|
+ queryWrapper.like(EmailSignatureEntity::getSignatureTitle, dto.getSignatureTitle());
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(dto.getIsDefault())) {
|
|
|
+ queryWrapper.eq(EmailSignatureEntity::getIsDefault, dto.getIsDefault());
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(dto.getSmtpPopId())) {
|
|
|
+ queryWrapper.eq(EmailSignatureEntity::getSmtpPopId, dto.getSmtpPopId());
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(dto.getEnabled())) {
|
|
|
+ queryWrapper.eq(EmailSignatureEntity::getEnabled, dto.getEnabled());
|
|
|
+ }
|
|
|
+ queryWrapper.orderByAsc(EmailSignatureEntity::getSort);
|
|
|
+ queryWrapper.orderByDesc(EmailSignatureEntity::getId);
|
|
|
+ return queryWrapper;
|
|
|
+ }
|
|
|
+}
|