MailBoxServiceImpl.java 3.31 KB
package com.huaheng.pc.config.sendMail.service;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.documentWarning.service.IDocumentWarningService;
import com.huaheng.pc.config.receiptType.domain.ReceiptType;
import com.huaheng.pc.config.sendMail.domain.MailBox;
import com.huaheng.pc.config.sendMail.domain.SendMail;
import com.huaheng.pc.config.sendMail.mapper.MailBoxMapper;
import com.huaheng.pc.config.sendMail.mapper.SendMailMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class MailBoxServiceImpl extends ServiceImpl<MailBoxMapper, MailBox> implements MailBoxService {

    @Resource
    private MailBoxMapper mailBoxMapper;
    @Resource
    private IDocumentWarningService documentWarningService;
    @Resource
    private SendMailService sendMailService;
    @Resource
    private MailService mailService;




    /**
     *  根据邮件类型发送邮件
     *
     * @param type
     * @return
     */
    @Override
    @Transactional
    public AjaxResult sendMail(Integer type) {

        MailBox
            mailBox = new MailBox();
        mailBox.setType(type);
        LambdaQueryWrapper<MailBox> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(MailBox::getType,type);
        List<MailBox> mailBoxs = this.list(lambdaQueryWrapper);
        List<String> persons = new ArrayList<>();
        for (MailBox box : mailBoxs) {
            persons.add(box.getEmail());
        }

        String subject = "昆山仓部报表";
        String content = "<html><body><a href=\"http://172.16.2.10:9008/jmreport/view/1370215917140709376\" >七天物料交易图</a>" +
            "&nbsp;&nbsp;&nbsp;<a href=\"http://172.16.2.10:9008/jmreport/view/1369889034708586496\" >七天物料交易数据</a>" +
            "&nbsp;&nbsp;&nbsp;<a href=\"http://172.16.2.10:9008/jmreport/view/1370570301456388096\" >物料交易频次数据</a>" +
            "<br/><a href=\"http://172.16.2.10:9008/jmreport/view/1368849556351094784\" >库龄分布图</a>" +
            "&nbsp;&nbsp;&nbsp;<a href=\"http://172.16.2.10:9008/jmreport/view/1369887964003438592\" >库龄0-3个月数据</a>" +
            "&nbsp;&nbsp;&nbsp;<a href=\"http://172.16.2.10:9008/jmreport/view/1369888140189372416\" >库龄3-6个月数据</a>" +
            "&nbsp;&nbsp;&nbsp;<a href=\"http://172.16.2.10:9008/jmreport/view/1369888410508070912\" >库龄6-9个月数据</a>" +
            "&nbsp;&nbsp;&nbsp;<a href=\"http://172.16.2.10:9008/jmreport/view/1369888507509739520\" >库龄9-12个月数据</a>" +
            "&nbsp;&nbsp;&nbsp;<a href=\"http://172.16.2.10:9008/jmreport/view/1369888675143487488\" >库龄大于1年数据</a>" +
            "<br/><br/><br/>昆山wms推送</body></html>";
        String[] cc = null;
        mailService.sendHtmlMail(persons.toArray(new String[persons.size()]),subject,content,cc);
        return AjaxResult.success("成功");
    }
}