|
|
@@ -20,8 +20,12 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.echepei.dto.mail.MailDto;
|
|
|
+import com.echepei.enums.MailTypeEnum;
|
|
|
+import com.echepei.utils.mail.SendMailUtil;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springblade.common.enums.CommonEnum;
|
|
|
+import org.springblade.core.secure.BladeUser;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.core.tool.utils.BeanUtil;
|
|
|
@@ -47,6 +51,7 @@ import org.springblade.los.business.customsDeclaration.service.ICustomsDeclarati
|
|
|
import org.springblade.los.business.sea.dto.ContainersReports;
|
|
|
import org.springblade.los.business.sea.entity.*;
|
|
|
import org.springblade.los.business.sea.service.*;
|
|
|
+import org.springblade.los.business.sea.vo.GenerateMailVo;
|
|
|
import org.springblade.los.enums.AmendType;
|
|
|
import org.springblade.los.finance.agreement.entity.AgreementPrice;
|
|
|
import org.springblade.los.finance.agreement.entity.AgreementPriceItems;
|
|
|
@@ -78,11 +83,19 @@ import org.springblade.system.user.feign.IUserClient;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.BigInteger;
|
|
|
import java.math.MathContext;
|
|
|
import java.math.RoundingMode;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Paths;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.function.Function;
|
|
|
@@ -6690,6 +6703,71 @@ public class ReportsServiceImpl extends ServiceImpl<ReportsMapper, Reports> impl
|
|
|
return baseMapper.getReports(reports);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public R<String> generateMailFileAndSend(GenerateMailVo generateMailVo) {
|
|
|
+ String baseFilePath = sysClient.getParamService("stimulsoft.send.mail.path");
|
|
|
+ if (!StringUtils.hasText(baseFilePath)) {
|
|
|
+ return R.fail("请配置发送邮件文件路径");
|
|
|
+ }
|
|
|
+ BladeUser bladeUser = AuthUtil.getUser();
|
|
|
+ R<User> userInfoResult = userClient.userInfoById(bladeUser.getUserId());
|
|
|
+ if (!userInfoResult.isSuccess()) {
|
|
|
+ return R.fail(userInfoResult.getMsg());
|
|
|
+ }
|
|
|
+ User userInfo = userInfoResult.getData();
|
|
|
+ if (org.springframework.util.ObjectUtils.isEmpty(userInfo)) {
|
|
|
+ return R.fail("用户不存在,请重新登录");
|
|
|
+ }
|
|
|
+ String userMail = userInfo.getEmail();
|
|
|
+ String userMailAuthorization = userInfo.getEmailAuthorization();
|
|
|
+ if (!StringUtils.hasText(userMail) || !StringUtils.hasText(userMailAuthorization)) {
|
|
|
+ R<List<DictBiz>> bizResult = dictBizClient.getList("mail_send");
|
|
|
+ if (!bizResult.isSuccess()) {
|
|
|
+ return R.fail("请完善邮箱信息");
|
|
|
+ }
|
|
|
+ List<DictBiz> dictBizList = bizResult.getData();
|
|
|
+ if (CollectionUtils.isEmpty(dictBizList)) {
|
|
|
+ return R.fail("请完善邮箱信息");
|
|
|
+ }
|
|
|
+ DictBiz dictBiz = dictBizList.stream().filter(db -> db.getTenantId().equals(bladeUser.getTenantId())
|
|
|
+ && db.getIsDeleted() == 0 && db.getIsSealed() == 0).sorted(Comparator.comparingInt(DictBiz::getSort)).findFirst().orElse(null);
|
|
|
+ if (dictBiz == null) {
|
|
|
+ return R.fail("请完善有效的邮箱信息");
|
|
|
+ }
|
|
|
+ userMail = dictBiz.getDictKey();
|
|
|
+ userMailAuthorization = dictBiz.getDictValue();
|
|
|
+ if (!StringUtils.hasText(userMail) || !StringUtils.hasText(userMailAuthorization)) {
|
|
|
+ return R.fail("请维护邮箱信息");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LocalDate nowDate = LocalDate.now();
|
|
|
+ baseFilePath = baseFilePath + "/" + nowDate.getYear() + "/" + nowDate.getMonthValue() + "/" + nowDate.getDayOfMonth();
|
|
|
+ if (!Files.exists(Paths.get(baseFilePath))) {
|
|
|
+ new File(baseFilePath).mkdirs();
|
|
|
+ }
|
|
|
+ String realFileName = generateMailVo.getFileName() + "." + generateMailVo.getFileType().toLowerCase();
|
|
|
+ String filePath = baseFilePath + "/" + realFileName;
|
|
|
+ try {
|
|
|
+ Files.write(Paths.get(filePath), generateMailVo.getFileContent());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.toString());
|
|
|
+ return R.fail("文件写入失败");
|
|
|
+ }
|
|
|
+ MailDto mailDto = new MailDto();
|
|
|
+ mailDto.setMailFrom(userMail);
|
|
|
+ mailDto.setMailUserName(userMail);
|
|
|
+ mailDto.setMailPassword(userMailAuthorization);
|
|
|
+ mailDto.setMailType(MailTypeEnum.QQ.mailType);
|
|
|
+ mailDto.setMailTo(generateMailVo.getSendTo());
|
|
|
+ mailDto.setMailCc(generateMailVo.getSendCc());
|
|
|
+ mailDto.setMailBcc(generateMailVo.getSendBcc());
|
|
|
+ mailDto.setMailTitle(generateMailVo.getMailTitle());
|
|
|
+ mailDto.setMailContent(generateMailVo.getMailContent());
|
|
|
+ mailDto.setMailFilePath(Arrays.asList(filePath));
|
|
|
+ SendMailUtil.sendHtmlFileMail(mailDto);
|
|
|
+ return R.data("发送成功");
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
|
|
|
Set<Object> seen = ConcurrentHashMap.newKeySet();
|