xinyb
2024-09-04 4284431e6755e854a7de7afb2ef09e461d3e72eb
src/com/yc/crm/mail/action/MailController.java
@@ -2,6 +2,7 @@
import com.yc.crm.mail.entity.T482102Entity;
import com.yc.crm.mail.entity.t482101HEntity;
import com.yc.crm.mail.entity.t482101HList;
import com.yc.crm.mail.service.MailAccountIfc;
import com.yc.crm.mail.service.MailIfc;
import com.yc.crm.mail.util.AllBackMsg;
@@ -59,7 +60,7 @@
            }
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
            List<t482101HEntity> t482101HEntityList = emailIfc.getReceivingMailList(mail, mailType, isNoRead);
            List<t482101HList> t482101HEntityList = emailIfc.getReceivingMailList(mail, mailType, isNoRead);
            if (t482101HEntityList.size() > 0) {
                msg.setSuccess("执行完成", t482101HEntityList);
            }
@@ -77,22 +78,16 @@
     * @return
     */
    @GetMapping("/getMailInfo.do")
    public AllBackMsg getMailInfo(String mail, String docCode, HttpServletRequest request, HttpServletResponse response) throws Exception {
    public AllBackMsg getMailInfo(String docCode, HttpServletRequest request, HttpServletResponse response) throws Exception {
        AllBackMsg msg = new AllBackMsg();
        try {
            if (StringUtils.isBlank(docCode)) {//获取不到当前用户直接结束
                msg.setFail("缺少邮箱唯一码docCode,请检查");
                return msg;
            }
            if (StringUtils.isNotBlank(mail)) {
                if (!EMAIL_PATTERN.matcher(mail).matches()) {
                    msg.setFail("邮箱的格式不正确");
                    return msg;
                }
            }
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
            t482101HEntity t482101HEntity = emailIfc.getReceivingMailInfo(mail, docCode);
            t482101HEntity t482101HEntity = emailIfc.getReceivingMailInfo(docCode);
            if (t482101HEntity != null) {
                msg.setSuccess("执行完成", t482101HEntity);
            }
@@ -105,18 +100,19 @@
    }
    /**
     * 获取邮件详情
     * 删除邮件
     *
     * @return
     */
    @GetMapping("/deleteReceivingMail.do")
    public AllBackMsg deleteReceivingMail(String docCode, HttpServletRequest request, HttpServletResponse response) throws Exception {
    @PostMapping("/deleteReceivingMail.do")
    public AllBackMsg deleteReceivingMail(@RequestBody List<String> docCode, HttpServletRequest request, HttpServletResponse response) throws Exception {
        AllBackMsg msg = new AllBackMsg();
        try {
            if (StringUtils.isBlank(docCode)) {//获取不到当前用户直接结束
                msg.setFail("缺少邮箱唯一码docCode,请检查");
            if (docCode == null && docCode.size() == 0) {//获取不到当前用户直接结束
                msg.setFail("请选中删除的邮件");
                return msg;
            }
            String arrayCode = StringUtils.join(docCode, ",");
            HttpSession session = request.getSession();
            String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
            if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
@@ -125,7 +121,7 @@
            }
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
            Integer cont = emailIfc.deleteReceivingMail(userCode, docCode);
            Integer cont = emailIfc.deleteReceivingMail(userCode, arrayCode);
            if (cont > 0) {
                msg.setOk("邮件已删除");
            }
@@ -158,11 +154,14 @@
                    return msg;
                }
            }
            if (StringUtils.isNotBlank(t482101H.getReceiver())) {
                if (!EMAIL_PATTERN.matcher(t482101H.getReceiver()).matches()) {
                    msg.setFail("收件人邮箱:" + t482101H.getReceiver() + "的格式不正确");
                    return msg;
            if (t482101H.getReceiver()!=null && t482101H.getReceiver().size()>0) {
                for (String mail : t482101H.getReceiver()) {
                    if (!EMAIL_PATTERN.matcher(mail).matches()) {
                        msg.setFail("收件人邮箱:" + mail + "的格式不正确");
                        return msg;
                    }
                }
            }
            String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID);
            String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME);
@@ -178,7 +177,6 @@
            Map<String, Object> map = new HashMap<>();
            map.put("docCode", t482101H.getDocCode());
            msg.setSuccess("执行成功", map);
//            msg.setOk("执行成功");
        } catch (Exception e) {
            msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
@@ -192,17 +190,24 @@
     *
     * @return
     */
    @GetMapping("/deleteMailDrafts.do")
    public AllBackMsg deleteMailDrafts(String docCode, HttpServletRequest request, HttpServletResponse response) throws Exception {
    @PostMapping("/deleteMailDrafts.do")
    public AllBackMsg deleteMailDrafts(@RequestBody List<String> docCode, HttpServletRequest request, HttpServletResponse response) throws Exception {
        AllBackMsg msg = new AllBackMsg();
        try {
            if (StringUtils.isBlank(docCode)) {//获取不到当前用户直接结束
                msg.setFail("缺少邮箱唯一码docCode,请检查");
            if (docCode == null && docCode.size() == 0) {//获取不到当前用户直接结束
                msg.setFail("请选中删除的邮件");
                return msg;
            }
            String arrayCode=StringUtils.join(docCode,",");
            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());//切换数据源
            int cont = emailIfc.deleteMailDrafts(docCode);
            int cont = emailIfc.deleteMailDrafts(userCode,arrayCode);
            if (cont > 0) {
                msg.setOk("删除成功");
            }
@@ -237,11 +242,14 @@
                    return msg;
                }
            }
            if (StringUtils.isNotBlank(t482101H.getReceiver())) {
                if (!EMAIL_PATTERN.matcher(t482101H.getReceiver()).matches()) {
                    msg.setFail("收件人邮箱:" + t482101H.getReceiver() + "的格式不正确");
                    return msg;
            if (t482101H.getReceiver()!=null && t482101H.getReceiver().size()>0) {
                for (String mail : t482101H.getReceiver()) {
                    if (!EMAIL_PATTERN.matcher(mail).matches()) {
                        msg.setFail("收件人邮箱:" + mail + "的格式不正确");
                        return msg;
                    }
                }
            }
            String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID);
            String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME);
@@ -322,4 +330,39 @@
        }
        return msg;
    }
    /**
     * 标记已读
     *
     * @param request
     * @param response
     * @return
     */
    @PostMapping("/updateRead.do")
    public AllBackMsg updateRead(@RequestBody List<String> docCode, HttpServletRequest request, HttpServletResponse response) throws Exception {
        AllBackMsg msg = new AllBackMsg();
        try {
            HttpSession session = request.getSession();
            String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
            if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
                msg.setFail("获取不到用户信息");
                return msg;
            }
            if (docCode == null && docCode.size() == 0) {
                msg.setFail("请选择标记邮件");
                return msg;
            }
            String arrayCode = StringUtils.join(docCode, ",");
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
            emailIfc.updateRead(arrayCode);
            msg.setOk("标记成功");
        } catch (Exception e) {
            msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
}