xinyb
2024-09-19 1956855b43808d81f246d9570d477ac1cbc404b7
src/com/yc/crm/mail/action/MailController.java
@@ -2,11 +2,13 @@
import com.yc.crm.mail.entity.*;
import com.yc.crm.mail.service.MailAccountIfc;
import com.yc.crm.mail.service.MailFileIfc;
import com.yc.crm.mail.service.MailIfc;
import com.yc.crm.mail.service.MailServiceIfc;
import com.yc.crm.mail.util.AllBackMsg;
import com.yc.entity.AttachmentConfig;
import com.yc.entity.DataSourceEntity;
import com.yc.entity.attachment.AttachmentEntity;
import com.yc.factory.FactoryBean;
import com.yc.multiData.MultiDataSource;
import com.yc.multiData.SpObserver;
@@ -46,6 +48,8 @@
    MailIfc emailIfc;
    @Autowired
    MailServiceIfc mailServiceIfc;
    @Autowired
    MailFileIfc mailFileIfc;
    private static final Pattern EMAIL_PATTERN =
            Pattern.compile("^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$");
@@ -84,7 +88,8 @@
     * @return
     */
    @GetMapping("/getMailList.do")
    public AllBackMsg getMailList(String mail, @RequestParam(defaultValue = "1") Integer mailType, boolean isNoRead, HttpServletRequest request, HttpServletResponse response) throws Exception {
    public AllBackMsg getMailList(String mail, @RequestParam(defaultValue = "1") Integer mailType,
                                  @RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "20") Integer limit, boolean isNoRead, HttpServletRequest request, HttpServletResponse response) throws Exception {
        AllBackMsg msg = new AllBackMsg();
        try {
            if (StringUtils.isNotBlank(mail)) {
@@ -101,7 +106,43 @@
            }
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
            List<t482101HList> t482101HEntityList = emailIfc.getReceivingMailList(mail, mailType, isNoRead, userCode);
            List<t482101HList> t482101HEntityList = emailIfc.getReceivingMailList(mail, mailType, isNoRead, userCode,page,limit);
            if (t482101HEntityList.size() > 0) {
                msg.setSuccess("执行完成", t482101HEntityList);
            }
        } catch (Exception e) {
            msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
    /**
     * 获取待处理邮件列表
     *
     * @return
     */
    @GetMapping("/getHandleMailList.do")
    public AllBackMsg getHandleMailList(String mail,@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "20") Integer limit,
                                        HttpServletRequest request, HttpServletResponse response) throws Exception {
        AllBackMsg msg = new AllBackMsg();
        try {
            if (StringUtils.isNotBlank(mail)) {
                if (!EMAIL_PATTERN.matcher(mail).matches()) {
                    msg.setFail("邮箱的各式不争取");
                    return msg;
                }
            }
            HttpSession session = request.getSession();
            String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
            if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
                msg.setFail("获取不到用户信息");
                return msg;
            }
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
            List<t482101HList> t482101HEntityList = emailIfc.getHandleMailList(mail, userCode,page,limit);
            if (t482101HEntityList.size() > 0) {
                msg.setSuccess("执行完成", t482101HEntityList);
            }
@@ -131,12 +172,12 @@
            t482101HEntity t482101HEntity = emailIfc.getReceivingMailInfo(docCode);
            if (t482101HEntity != null) {
                if (StringUtils.isNotBlank(t482101HEntity.getAttachmentList())) {//附件的处理
                    //获取到附件内容
                    List<AttachmentEntity> attachmentEntities = mailFileIfc.getAttachmentEntityList(t482101HEntity.getAttachmentList());
                    List<String> list = new ArrayList<>();
                    String[] path = t482101HEntity.getAttachmentList().split(";");
                    if (path.length > 1) {
                        String unId = path[0];//第一个必定是unid;
                        for (int p = 1; p < path.length; p++) {
                            list.add(shoppingImageServer + "/uploads/attachment/82/482101/" + unId + "@p@" + path[p]);
                    if (attachmentEntities.size() > 0) {
                        for (AttachmentEntity a : attachmentEntities) {
                            list.add(shoppingImageServer + "/uploads/email/" + dataSourceEntity.getDbId() + "/482101/" + a.getUnid() + "@p@" + a.getPhysicalFile());
                        }
                        t482101HEntity.setAttachmentPath(list);
                    }
@@ -186,6 +227,52 @@
    }
    /**
     * 快速回复
     *
     * @return
     */
    @PostMapping("/setQuickReply.do")
    public AllBackMsg setQuickReply(@RequestBody Map<String, Object> reply, HttpServletRequest request, HttpServletResponse response) throws Exception {
        AllBackMsg msg = new AllBackMsg();
        try {
            if (reply.get("docCode") == null) {
                msg.setFail("获取不到回复邮件的唯一docCode值");
                return msg;
            }
            if (reply.get("content") == null) {
                msg.setFail("请输入回复内容");
                return msg;
            }
            HttpSession session = request.getSession();
            String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
            if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
                msg.setFail("获取不到用户信息");
                return msg;
            }
            String docCode = (String) reply.get("docCode");//编号
            String content = (String) reply.get("content");//内容
            Integer count = mailServiceIfc.setQuickReply(docCode, content);
            Map<String, Object> map = new HashMap<>();
            if (count.equals(1)) {
                map.put("code", 0);
                map.put("docCode", docCode);
                map.put("msg", "邮件已回复");
                msg.setSuccess("执行成功", map);
            } else {
                map.put("code", -1);
                map.put("docCode", docCode);
                map.put("msg", "邮件回复失败");
                msg.setSuccess("执行成功", map);
            }
        } catch (Exception e) {
            msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
    /**
     * 保存草稿箱(保存或修改)
     *
     * @return