7caeaebc1ee299c440adaa51073c21fdc88a2b7f..7cf738d43c5d38e9a6246c7d6212d2d5bd055886
2024-09-13 xinyb
CRM邮箱配置和客户功能
7cf738 对比 | 目录
2024-09-13 xinyb
调整审计功能加密功能
3118f7 对比 | 目录
2个文件已删除
3个文件已添加
13个文件已修改
979 ■■■■ 已修改文件
WebRoot/js/panel.js 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/custom/action/Custom.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/custom/action/CustomController.java 167 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/custom/entity/CustomEntity.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/custom/entity/CustomModule.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/custom/entity/T480601HEntity.java 166 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/custom/service/CustomIfc.java 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/custom/service/CustomImpl.java 84 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/mail/action/MailAccount.java 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/mail/action/MailController.java 67 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/mail/entity/MailFileEntity.java 33 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/mail/entity/t482101HEntity.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/mail/entity/t482101HList.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/mail/service/MailAccountIfc.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/mail/service/MailAccountImpl.java 21 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/mail/service/MailIfc.java 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/mail/service/MailImpl.java 56 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/crm/mail/service/MailServiceImpl.java 233 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
WebRoot/js/panel.js
@@ -3390,10 +3390,25 @@
                            array.push((plane[auditField[a][0]] != null ? plane[auditField[a][0]] : ''));
                        }
                    }
                    auditJson.auditIndex = news + ',' + old + ',' + array.join(',');
                    let auditType="update";
                    if (isNew == 1 && doc == "") {
                        auditType = 'add';
                    }
                    if (typeof (type) != 'undefined' && type == '2add') {
                        auditType = "add";
                    }
                    auditJson.auditType = auditType;
                    auditJson.usercode = '';
                    auditJson.username = '';
                    auditJson.fieldId = name;
                    auditJson.fieldname = auditField[i][2];
                    auditJson.oldvalue = old;
                    auditJson.newvalue = news;
                    auditJson.formid = auditFormId;
                    auditJson.doccode = doc;
                    auditJson.mainFormId = formId;//主功能号,在三表或多表时MainFormId取主功能号,其他情况取值和formid相同取当前功能号
                    auditJson.headFlag = 0;//主表为0 从表为1
                    if ($doc(name + "_expr").val() != null && $doc(name + "_expr").val() == 0) {
                        var encrypt = new JSEncrypt();
                        encrypt.setPublicKey(rsakey.pubkey);
@@ -3402,16 +3417,8 @@
                        auditJson.newvalue_expr = 0;
                        auditJson.oldvalue = $doc(name + "_expr_val").val();
                        auditJson.newvalue = news;
                        auditJson.auditIndex_expr = news;//处理加密
                    }
                    auditJson.usercode = '';
                    auditJson.username = '';
                    auditJson.auditType = (typeof (type) == 'undefined' ? ((isNew == 1 && doc == "") ? "add" : "update") : (type == "2add" ? "add" : "update"));
                    auditJson.formid = auditFormId;
                    auditJson.doccode = doc;
                    auditJson.auditIndex = ',' + news + ',' + old + ',' + array.join(',')+',';
                    auditJson.auditIndex_expr = '';//处理加密
                    auditJson.mainFormId = formId;//主功能号,在三表或多表时MainFormId取主功能号,其他情况取值和formid相同取当前功能号
                    auditJson.headFlag = 0;//主表为0 从表为1
                    newValue.push(auditJson);
                }
            }
src/com/yc/crm/custom/action/Custom.java
File was deleted
src/com/yc/crm/custom/action/CustomController.java
New file
@@ -0,0 +1,167 @@
package com.yc.crm.custom.action;
import com.yc.crm.custom.entity.T480601HEntity;
import com.yc.crm.custom.service.CustomIfc;
import com.yc.crm.mail.entity.MailModuleEntity;
import com.yc.crm.mail.util.AllBackMsg;
import com.yc.entity.DataSourceEntity;
import com.yc.multiData.MultiDataSource;
import com.yc.multiData.SpObserver;
import com.yc.utils.SessionKey;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @BelongsProject: eCoWorksV3
 * @BelongsPackage: com.yc.crm.custom.action
 * @author: xinyb
 * @CreateTime: 2024-08-24  14:15
 * @Description:
 */
@CrossOrigin
@RestController
@RequestMapping("/crm/custom/")
public class CustomController {
    @Autowired
    CustomIfc customIfc;
    /**
     * 获取客户左边模块
     *
     * @return
     */
    @GetMapping("/getCustomModule.do")
    public AllBackMsg getCustomModule(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;
            }
            String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID);
            String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME);
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
            List<MailModuleEntity> list = null;
            msg.setSuccess("执行成功", list);
        } catch (Exception e) {
            msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
    /**
     * 保存客户
     *
     * @return
     */
    @PostMapping("/saveCustom.do")
    public AllBackMsg saveCustom(@RequestBody T480601HEntity custom, 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;
            }
            String userName = (String) session.getAttribute(SessionKey.USERNAME);
            String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID);
            String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME);
            custom.setCompanyid(companyId);
            custom.setCompanyname(companyName);
            custom.setEnterCode(userCode);
            custom.setEnterName(userName);
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
            String docCode = customIfc.saveCustom(custom);
            Map<String, Object> map = new HashMap<>();
            if (StringUtils.isNotBlank(docCode)) {
                map.put("docCode", docCode);
            }
            msg.setSuccess("执行成功", map);
        } catch (Exception e) {
            msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
    /**
     * 修改客户
     *
     * @return
     */
    @PostMapping("/updateCustom.do")
    public AllBackMsg updateCustom(@RequestBody T480601HEntity custom, 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 (StringUtils.isBlank(custom.getDocCode())) {
                msg.setFail("请输入修改的客户编号");
                return msg;
            }
            String userName = (String) session.getAttribute(SessionKey.USERNAME);
            String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID);
            String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME);
            custom.setCompanyid(companyId);
            custom.setCompanyname(companyName);
            custom.setEnterCode(userCode);
            custom.setEnterName(userName);
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
            customIfc.updateCustom(custom);
            msg.setSuccess("执行成功", "已保存");
        } catch (Exception e) {
            msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
    /**
     * 删除客户
     *
     * @return
     */
    @PostMapping("/deleteCustom.do")
    public AllBackMsg deleteCustom(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;
            }
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
            customIfc.deleteCustom(docCode, userCode);
            msg.setSuccess("执行成功", "已保存");
        } catch (Exception e) {
            msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
}
src/com/yc/crm/custom/entity/CustomEntity.java
File was deleted
src/com/yc/crm/custom/entity/CustomModule.java
New file
@@ -0,0 +1,27 @@
package com.yc.crm.custom.entity;
import lombok.Data;
import java.util.List;
/**
 * @BelongsProject: eCoWorksV3
 * @BelongsPackage: com.yc.crm.custom.entity
 * @author: xinyb
 * @CreateTime: 2024-09-07  10:21
 * @Description:客户模块
 */
@Data
public class CustomModule {
    private String key;
    private String id;
    private String name;
    private String title;
    private boolean isCommon;//常用
    public static List<CustomModule> setCustomModuleInitial() {
        return null;
    }
}
src/com/yc/crm/custom/entity/T480601HEntity.java
New file
@@ -0,0 +1,166 @@
package com.yc.crm.custom.entity;
import com.yc.crm.base.entity.AuditEntity;
import com.yc.crm.base.entity.FileEntity;
import com.yc.crm.clues.entity.T482103Entity;
import lombok.Data;
import java.util.List;
/**
 * @BelongsProject: eCoWorksV3
 * @BelongsPackage: com.yc.crm.custom.entity
 * @author: xinyb
 * @CreateTime: 2024-09-07  10:57
 * @Description:客户
 */
@Data
public class T480601HEntity {
//    private String docCode;//单号
//    private Integer formId;//功能号
////    private String userCode;//用户
////    private String userName;//用户名称
//    private String docDate;//时间
//    private Integer docStatus;//状态
//    private String docStatusName;//状态名称
//    private String companyId;//公司ID
//    private String companyName;//公司名称
//    private String enterCode;//创建人code
//    private String enterName;//创建人名称
//    private String enterDate;//创建时间
//    private String cltCode;//客户编号
//    private String cltName;//客户名称
//    private List<String> leadSourceCode;//客户来源
//    private List<String> leadSourceName;//客户来源名
//    private String country;//国家/地区
//    private String province;//州/省
//    private String city;//城市
//    private String district;//区县
//    private String street;//街道
//    private List<T482103Entity> contactsList;//联系人
    private String docCode;
    private Integer formId;
    private String refcode;
    private String doctype;
    private String docDate;
    private String periodid;
    private Integer docStatus;
    private String docStatusName;
    private String companyid;
    private String companyname;
    private String enterCode;
    private String enterName;
    private String enterDate;
    private String modifyName;
    private String modifyDate;
    private String modifylog;
    private String postName;
    private String postDate;
    private String createUsercode;
    private String createUserName;
    private Integer lastprintnum;
    private Integer lastprintformid;
    private Integer lastprintdocstatus;
    private String cccode;
    private String cltCode;
    private String cltName;
    private String honorific;
    private String title;
    private Integer isRead;
    private String email;
    private String website;
    private String fax;
    private Integer hasOptedOutOfFax;
    private String phone;
    private Integer doNotCall;
    private String mobilePhone;
    private String qq;
    private String weiXin;
    private String weiBo;
    private String yiXin;
    private String faceBook;
    private String cltStatus;
    private String country;//国家
    private String province;
    private String city;
    private String district;
    private String street;
    private String address;
    private String postCode;
    private Integer hasOptedOutOfEmail;
    private String cleanupStatus;
    private String cltCompanyName;
    private String industryCode;
    private String industryName;
    private Integer numberOfEmployees;
    private String leadSourceCode;
    private String leadSourceName;
    private String marketActDocCode;
    private Integer marketActFormId;
    private Integer marketActFormType;
    private String marketActName;
    private String hdMemo;//线索备注
    private Integer registeredYear;
    private String registeredCapital;
    private String marketShare;
    private String salesTotalMoney;
    private String annualProfit;
    private Integer docVersion;
    private String modifyCode;
    private String cluesName;//线索名称
    private String archiveTime;//存档时间
    private String orderTime;
    private Integer lostDayCount;
    private Integer transferCount;
    private Integer releaseCount;
    private Boolean isArchive;
    private Integer archiveType;
    private Integer statusId;//状态id
    private String status;//状态内容
    private String followUpTime;//跟进时间
    private Integer failType;//无效类型
    private Integer failStatus;//无效状态id
    private String failStatusName;//无效状态内容
    private String failReason;//无效原因
    private Boolean readFlag;
    private String lastEditUser;
    private String editTime;
    private String privateTime;//进入私海时间
    private String publicTime;//进入公海时间
    private Boolean isPublic;//是否为公海线索
    private Integer storeId;
    private Integer star;//评分分数
    private Boolean transformTaskStatus;
    private String nextFollowUpTime;//下次跟进时间
    private Boolean duplicateFlag;//是否有重复内容
    private String tagList;//标签列表
    //private List<CrmTagEntity> tagList;//标签列表
    private String homepage;//公司网址
    private String originList;//线索来源,以分号分隔多个来源id
    // private List<T480107Entity> originList;//线索来源
    private String shortName;//简称
    private String corporateName;//公司名称
    private String bizType;//公司类型
    private String telAreaCode;//地区号
    private String tel;//座机
    private String intentionLevel;//采购意向
    private Double annualProcurement;//年采购额
    private String timezone;//时区
    private String adKeyword;//搜索关键字
    private String imageList;//图片列表
    private String scaleId;//规模
    private String seller;//业务员
    private String inquiryOrigin;//访问来源
    private String categoryIds;//主营产品
    private String inquiryCountry;//访客IP所在地
    private Integer pinFlag=0;//关注
    private List<T482103Entity> contactsList;//联系人
    private Integer totalRowCount;
    private Integer pageCount;
    private String ccCode;
    private String ccName;
    private  List<FileEntity> files;
    private List<AuditEntity> auditRecords;
    private Integer systemFlag;//系统标签
    private Integer cluesStatusFlag;//线索状态
}
src/com/yc/crm/custom/service/CustomIfc.java
@@ -1,4 +1,44 @@
package com.yc.crm.custom.service;
import com.yc.crm.custom.entity.T480601HEntity;
import java.util.List;
public interface CustomIfc {
    /**
     * 保存客户
     *
     * @param custom
     */
    abstract String saveCustom(T480601HEntity custom);
    /**
     * 修改客户
     * @param custom
     * @return
     */
    abstract Integer updateCustom(T480601HEntity custom);
    /**
     * 删除客户
     * @param docCode
     * @param userCode
     * @return
     */
    abstract Integer deleteCustom(String docCode, String userCode);
    /**
     * 查询客户列
     * @param userCode
     * @return
     */
    abstract List<T480601HEntity> getCustomList(String userCode);
    /**
     * 查询客户详情
     * @param docCode
     * @param userCode
     * @return
     */
    abstract T480601HEntity getCustomInfo(String docCode,String userCode);
}
src/com/yc/crm/custom/service/CustomImpl.java
@@ -1,6 +1,12 @@
package com.yc.crm.custom.service;
import com.yc.action.grid.GridUtils;
import com.yc.crm.clues.entity.T482103Entity;
import com.yc.crm.custom.entity.T480601HEntity;
import com.yc.service.BaseService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
 * @BelongsProject: eCoWorksV3
@@ -10,6 +16,82 @@
 * @Description:
 */
@Service
public class CustomImpl {
public class CustomImpl extends BaseService implements CustomIfc {
    @Override
    public String saveCustom(T480601HEntity custom) {
        String sql = "set nocount on\n";
        try {
            sql += "declare @docCode varchar(50) \n";
            sql += "exec sp_newdoccode 482101," + GridUtils.prossSqlParm(custom.getEnterCode()) + ",@docCode output \n";
            sql += "insert into t480601H(formId,docDate,periodId,docStatus,companyId,companyName,enterCode,enterName,enterDate," +
                    "postCode,postName,postDate,cltCode,cltName,country,province,city,district,street) " +
                    "values (" + custom.getFormId() + ",convert(varchar(10),getdate(),120),convert(varchar(7),getdate(),120),0," +
                    GridUtils.prossSqlParm(custom.getCompanyid()) + "," + GridUtils.prossSqlParm(custom.getCompanyname()) + "," +
                    GridUtils.prossSqlParm(custom.getEnterCode()) + "," + GridUtils.prossSqlParm(custom.getEnterName()) + ",getdate()," +
                    GridUtils.prossSqlParm(custom.getEnterCode()) + "," + GridUtils.prossSqlParm(custom.getEnterName()) + ",getdate()," +
                    "'',''," + GridUtils.prossSqlParm(custom.getCountry()) + "," + GridUtils.prossSqlParm(custom.getProvince()) + "," +
                    GridUtils.prossSqlParm(custom.getCity()) + "," + GridUtils.prossSqlParm(custom.getDistrict()) + "," +
                    GridUtils.prossSqlParm(custom.getStreet()) + ") \n";
            if (custom.getContactsList() != null && custom.getContactsList().size() > 0) {//插入联系人
                for (T482103Entity c : custom.getContactsList()) {
                    sql += "insert into t482103(main_customer_flag,refCode,name,email,gender,post,remark,image_list,birth,post_grade,growth_level,create_time,update_time) " +
                            "values(" + c.getMainCustomerFlag() + ",@docCode," + GridUtils.prossSqlParm(c.getName()) + "," + GridUtils.prossSqlParm(c.getEmail()) + "," +
                            GridUtils.prossSqlParm(c.getGender()) + "," + GridUtils.prossSqlParm(c.getPost()) + "," + GridUtils.prossSqlParm(c.getRemark()) + "," +
                            GridUtils.prossSqlParm(c.getImageList()) + "," + GridUtils.prossSqlParm(c.getBirth()) + "," + GridUtils.prossSqlParm(c.getPostGrade()) + "," +
                            c.getGrowthLevel() + ",getdate(),getdate()) \n";
                }
            }
            sql += "select @docCode as docCode";
            String docCode = jdbcTemplate.queryForObject(sql, String.class);
            return docCode;
        } catch (Exception e) {
            throw e;
        }
    }
    @Override
    public Integer updateCustom(T480601HEntity custom) {
        String sql = "set nocunt on \n";
        try {
            sql += "update t480601H set modifyCode=" + GridUtils.prossSqlParm(custom.getEnterCode()) + ",modifyName=" + GridUtils.prossSqlParm(custom.getEnterName()) + "," +
                    "modifyDate=getdate(),country=" + GridUtils.prossSqlParm(custom.getCountry()) + ",province=" + GridUtils.prossSqlParm(custom.getProvince()) + "," +
                    "city=" + GridUtils.prossSqlParm(custom.getCity()) + ",district=" + GridUtils.prossSqlParm(custom.getDistrict()) + ",street=" + GridUtils.prossSqlParm(custom.getStreet()) +
                    " where docCode=" + GridUtils.prossSqlParm(custom.getDocCode());
            sql += "select @@ROWCOUNT \n";
            return jdbcTemplate.queryForObject(sql, Integer.class);
        } catch (Exception e) {
            throw e;
        }
    }
    @Override
    public Integer deleteCustom(String docCode, String userCode) {
        String sql = "set nocunt on \n";
        try {
            sql += "delete t480601H where docCode=" + GridUtils.prossSqlParm(docCode);
            sql += "select @@ROWCOUNT \n";
            return jdbcTemplate.queryForObject(sql, Integer.class);
        } catch (Exception e) {
            throw e;
        }
    }
    @Override
    public List<T480601HEntity> getCustomList(String userCode) {
        try {
            return null;
        } catch (Exception e) {
            throw e;
        }
    }
    @Override
    public T480601HEntity getCustomInfo(String docCode, String userCode) {
        try {
            return null;
        } catch (Exception e) {
            throw e;
        }
    }
}
src/com/yc/crm/mail/action/MailAccount.java
@@ -455,7 +455,7 @@
                map.put("smtpPort", emailEntity.getSmtpPort());
                map.put("proxyFlag", emailEntity.isProxyFlag());
                map.put("biSyncFlag", emailEntity.isBiSyncFlag());
                map.put("mailStatus", emailEntity.getMailStatus());
                map.put("mailStatus", "正常");
                msg.setSuccess("执行成功", map);
            } else {
                //异常处理
@@ -525,17 +525,10 @@
            folder.close(false);
            store.close();
//            Session mailSession = Session.getInstance(props, new Authenticator() {
//                @Override
//                protected PasswordAuthentication getPasswordAuthentication() {
//                    return new PasswordAuthentication(emailEntity.getEmail(), emailEntity.getPassword());
//                }
//            });
            Transport transport = session.getTransport();
            transport.connect();
            transport.close();
            mailAccountIfc.updateMailStatus("正常", emailEntity.getAccountId());
        } catch (MessagingException e) {
            errorMsg = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();
        } catch (Exception e) {
src/com/yc/crm/mail/action/MailController.java
@@ -5,6 +5,7 @@
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.factory.FactoryBean;
import com.yc.multiData.MultiDataSource;
@@ -36,6 +37,8 @@
@RequestMapping("/crm/mail")
public class MailController {
    ThreadPoolTaskExecutor threadPoolExecutor = (ThreadPoolTaskExecutor) FactoryBean.getBean("threadPoolExecutor");//线程池
    final static String shoppingImageServer = AttachmentConfig.get("attachment.server");
    @Autowired
    MailAccountIfc emailAccountIfc;
    @Autowired
@@ -126,6 +129,17 @@
            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
            t482101HEntity t482101HEntity = emailIfc.getReceivingMailInfo(docCode);
            if (t482101HEntity != null) {
                if (StringUtils.isNotBlank(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]);
                        }
                        t482101HEntity.setAttachmentPath(list);
                    }
                }
                msg.setSuccess("执行完成", t482101HEntity);
            }
        } catch (Exception e) {
@@ -255,7 +269,10 @@
            if (StringUtils.isBlank(mail)) {
                emailEntities = emailAccountIfc.getAccount(userCode);//返回邮箱的账号信息
            } else {
                emailEntities.add(emailAccountIfc.getAccountInfo(userCode, mail));
                T482102Entity T482102 = emailAccountIfc.getAccountInfo(userCode, mail);
                if (T482102 != null) {
                    emailEntities.add(T482102);
                }
            }
            if (emailEntities.size() > 0) {
                List<t482101HEntity> mails = new ArrayList<>();
@@ -264,8 +281,8 @@
                    //多线程收邮件
                    threadPoolExecutor.execute(new ReceivingEmailsSave(mailServiceIfc, e, new FoundationEntity(request)));
                }
                map.put("code",0);
                map.put("msg", "邮件正在执行系统保存");
                map.put("code", 0);
                map.put("msg", "请销等,邮件正在系统保存");
                msg.setSuccess("执行成功", map);
            } else {
                msg.setFail("没有找到绑定的邮箱信息");
@@ -349,7 +366,7 @@
     * @return
     */
    @PostMapping("/updateRead.do")
    public AllBackMsg updateRead(@RequestBody List<String> docCode, HttpServletRequest request, HttpServletResponse response) throws Exception {
    public AllBackMsg updateRead(@RequestBody Map<String, Object> map, HttpServletRequest request, HttpServletResponse response) throws Exception {
        AllBackMsg msg = new AllBackMsg();
        try {
            HttpSession session = request.getSession();
@@ -358,14 +375,20 @@
                msg.setFail("获取不到用户信息");
                return msg;
            }
            List<String> docCode = (List<String>) map.get("list");
            if (docCode == null && docCode.size() == 0) {
                msg.setFail("请选择标记邮件");
                return msg;
            }
            if (map.get("status") == null) {
                msg.setFail("请传入状态值");
                return msg;
            }
            boolean read = (Boolean) map.get("status");
            String arrayCode = StringUtils.join(docCode, ",");
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
            emailIfc.updateRead(arrayCode);
            emailIfc.updateRead(arrayCode, read);
            msg.setOk("标记成功");
        } catch (Exception e) {
            msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
@@ -375,6 +398,40 @@
        return msg;
    }
    /**
     * 待处理邮件
     *
     * @param request
     * @param response
     * @return
     */
    @GetMapping("/updateHandle.do")
    public AllBackMsg updateHandle(String handleTime, 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 (StringUtils.isBlank(docCode)) {
                msg.setFail("邮件唯一标识docCode不能空");
                return msg;
            }
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
            emailIfc.updateMailHandle(handleTime, docCode);
            msg.setOk("成功标记为待处理邮件");
        } catch (Exception e) {
            msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
    private class ReceivingEmailsSave implements Runnable {
        final MailServiceIfc mailServiceIfc;
        final T482102Entity t482102;
src/com/yc/crm/mail/entity/MailFileEntity.java
@@ -1,7 +1,6 @@
package com.yc.crm.mail.entity;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import java.io.InputStream;
import java.util.List;
@@ -21,38 +20,16 @@
    @Data
    public static class MailBodyPart {
        private String cid;
        private String fieldId;//自定义字段
        private String physicalFile;//系统自定义一个随机(针对邮件附件)
        private String fileName;
        private String fileType;
        private long fileSize;
        private byte[] byteFile;
        private InputStream InputStream;//不能在已关闭对象里获取值,请保持连接状态才可以获取(针对javaMail邮件)
        public String getCid() {
            if (StringUtils.isBlank(cid)) {
                return fileName;
            }
            return cid;
        }
        /**
         * 返回附件后缀
         *
         * @return
         */
        public String getFileType() {
            if (StringUtils.isNotBlank(fileName)) {
                int index = fileName.lastIndexOf(".");
                if (index != -1) {
                    return fileName.substring(index + 1);
                } else {
                    if (StringUtils.isNotBlank(cid)) {
                        index = cid.lastIndexOf(".");
                        return (index != -1 ? cid.substring(index + 1) : "");
                    }
                    return "";
                }
            }
            return "";
        public String getPhysicalFile() {
            return fieldId+"."+fileType;
        }
    }
}
src/com/yc/crm/mail/entity/t482101HEntity.java
@@ -61,6 +61,7 @@
    private String content;
    private String plainText;
    private String attachmentList;
    private List<String> attachmentPath;
    private String inlineImageList;
    private String summary;
    private String tagList;
src/com/yc/crm/mail/entity/t482101HList.java
@@ -32,4 +32,6 @@
    private String receiveTime;// [note:'回复时间']
    private String plainText;
    private String eMail;
    private Integer handle;//是否待处理 1是 0不是
    private String handleTime;//待处理时间
}
src/com/yc/crm/mail/service/MailAccountIfc.java
@@ -22,6 +22,13 @@
    abstract Integer updateEmailAccount(T482102Entity account);
    /**
     * 更新时间
     * @param accountId
     * @return
     */
    abstract Integer updateEmailTime(Integer accountId);
    /**
     * 修改邮箱状态
     *
     * @param status
src/com/yc/crm/mail/service/MailAccountImpl.java
@@ -59,9 +59,22 @@
            }
            sql += " smtpSSL='" + account.isSmtpSSL() + "'," + " smtpPort=" + account.getSmtpPort() + ",smtpHost=" + GridUtils.prossSqlParm(account.getSmtpHost()) + "," +
                    " invalid='" + account.isInvalid() + "',bisync_flag='" + account.isBiSyncFlag() + "',proxyFlag='" + account.isProxyFlag() + "'," +
                    " mailType=" + account.getMailType() + ",mailStatus=" + GridUtils.prossSqlParm(account.getMailStatus()) + "," +
                    " update_time=convert(varchar(19),getdate(),120) " +
                    " mailType=" + account.getMailType() + ",mailStatus=" + GridUtils.prossSqlParm(account.getMailStatus()) +
//                    " ,update_time=convert(varchar(19),getdate(),120) " +
                    " where userCode=" + GridUtils.prossSqlParm(account.getUserCode()) + " and accountId=" + account.getAccountId();
            sql += "select @@ROWCOUNT";
            return jdbcTemplate.queryForObject(sql, Integer.class);
        } catch (Exception e) {
            throw e;
        }
    }
    @Override
    public Integer updateEmailTime(Integer accountId) {
        String sql = "set nocount on\n";
        try {
            sql += "update t482102 set update_time=convert(varchar(19),getdate(),120) " +
                    " where accountId=" + accountId;
            sql += "select @@ROWCOUNT";
            return jdbcTemplate.queryForObject(sql, Integer.class);
        } catch (Exception e) {
@@ -73,7 +86,7 @@
    public Integer updateMailStatus(String status, Integer accountId) {
        String sql = "set nocount on\n";
        try {
            sql += "update t482102 set mailStatus=" + GridUtils.prossSqlParm(status) + ",update_time=convert(varchar(19),getdate(),120) " +
            sql += "update t482102 set mailStatus=" + GridUtils.prossSqlParm(status) + //",update_time=convert(varchar(19),getdate(),120) " +
                    " where accountId=" + accountId;
            sql += "select @@ROWCOUNT";
            return jdbcTemplate.queryForObject(sql, Integer.class);
@@ -86,7 +99,7 @@
    public Integer updateAliasEmail(String aliasEmail, Integer accountId) {
        String sql = "set nocount on\n";
        try {
            sql += "update t482102 set alias_email=" + GridUtils.prossSqlParm(aliasEmail) + ",update_time=convert(varchar(19),getdate(),120) " +
            sql += "update t482102 set alias_email=" + GridUtils.prossSqlParm(aliasEmail) + //",update_time=convert(varchar(19),getdate(),120) " +
                    " where accountId=" + accountId;
            sql += "select @@ROWCOUNT";
            return jdbcTemplate.queryForObject(sql, Integer.class);
src/com/yc/crm/mail/service/MailIfc.java
@@ -142,7 +142,7 @@
     *
     * @param docCode
     */
    abstract void updateRead(String docCode);
    abstract void updateRead(String docCode,boolean status);
    /**
     * 绑定账号的邮箱模块
@@ -151,4 +151,11 @@
     * @return
     */
    abstract List<MailModuleEntity> getMailModuleList(String userCode);
    /**
     * 待处理邮件
     * @param handleTime
     * @param docCode
     */
    abstract void updateMailHandle(String handleTime,String docCode);
}
src/com/yc/crm/mail/service/MailImpl.java
@@ -39,7 +39,8 @@
        String sql = "set nocount on\n";
        try {
            if (StringUtils.isBlank(m.getDocCode())) {
                sql += "declare @docCode varchar(50) \n";
                sql += "declare @docCode varchar(50) ,@unid varchar(50),@fieldId varchar(100),@originalFileName varchar(100)," +
                        "@physicalFile varchar(50),@OriginalPicture varbinary(max) \n";
                sql += "exec sp_newdoccode 482101," + GridUtils.prossSqlParm(m.getUserCode()) + ",@docCode output \n";
                sql += "insert into t482101H(companyId,companyName,formId,docCode,docdate,PeriodID,postCode,postname,mailType,sender,receiver," +
                        "cc,bcc,subject,userCode,userName,content,plain_text,messageId,read_flag,delete_flag,create_time,update_time,receive_time," +
@@ -74,7 +75,7 @@
        String sql = "set nocount on\n";
        try {
            sql += "declare @docCode varchar(50) ,@unid varchar(50),@fieldId varchar(100),@originalFileName varchar(100)," +
                    "@SmallPicture varbinary(max),@OriginalPicture varbinary(max) \n";
                    "@physicalFile varchar(50),@OriginalPicture varbinary(max) \n";
            for (t482101HEntity m : mail) {//遍历内容
                sql += "exec sp_newdoccode 482101," + GridUtils.prossSqlParm(m.getUserCode()) + ",@docCode output \n";
                sql += "insert into t482101H(companyId,companyName,formId,docCode,docdate,PeriodID,postCode,postname,mailType,sender,receiver," +
@@ -92,7 +93,6 @@
                        m.getAttachFlag() + "," + GridUtils.prossSqlParm(m.getAttachmentList()) + ") \n" +
                        mailFileSql(m.getMailFile());
            }
            System.out.println("已执行:1");
            jdbcTemplate.update(sql);
        } catch (Exception e) {
            throw e;
@@ -117,12 +117,12 @@
                originalFileName = file.getFileName();
                fileType = file.getFileType();
                sql += "select @unid=" + GridUtils.prossSqlParm(mailFile.getUnId()) + "\n" +
                        ",@fieldId=" + GridUtils.prossSqlParm(file.getCid()) + "\n" +
                        ",@fieldId=" + GridUtils.prossSqlParm(file.getFieldId()) + "\n" +
                        ",@originalFileName=" + GridUtils.prossSqlParm(originalFileName) + "\n" +
//                        ",@SmallPicture=" + UploadFiles.byteToHexString(file.getByteFile()) + "\n" +
                        ",@physicalFile=" + GridUtils.prossSqlParm(file.getPhysicalFile()) + "\n" +
                        ",@OriginalPicture=" + UploadFiles.byteToHexString(file.getByteFile()) + "\n";
                sql += "insert into _sys_Attachment(unId,formId,docCode,fieldId,physicalFile,originalFileName,FileSize,fileType,UploadTime,LastUpdateTime,OriginalPicture) values ";
                sql += " (@unid,482101,@docCode,@fieldId,@originalFileName,@originalFileName," + file.getFileSize() + "," + GridUtils.prossSqlParm(fileType) + ",getdate(),getdate(),OriginalPicture) \n";
                sql += " (@unid,482101,@docCode,@fieldId,@physicalFile,@originalFileName," + file.getFileSize() + "," + GridUtils.prossSqlParm(fileType) + ",getdate(),getdate(),@OriginalPicture) \n";
            }
            return sql;
        } catch (Exception e) {
@@ -207,9 +207,9 @@
        try {
            sql += "select companyId,companyName,mailType,DocCode,sender,receiver,subject,plain_text," +
                    "receive_time,update_time,create_time,sender,userCode,userName,folder_id,delete_Flag, " +
                    "read_Flag from t482101H ";
                    "read_Flag,(case when (isnull(handle_time,'') <> '' and isnull(handle_time,'') < getdate()) then 1 else 0 end) as handle," +
                    "handle_time from t482101H ";
            sql += " where userCode=" + GridUtils.prossSqlParm(userCode);
            sql += " and isnull(read_flag,0) = " + (isNoRead ? 0 : 1);//0表示未读,1表示已读
            sql += " and mailType=" + mailType;//0:草稿箱 1:收件箱 2:发件箱
            if (StringUtils.isNotBlank(email)) {
                if (mailType == 1) {
@@ -217,6 +217,9 @@
                } else if (mailType == 2) {
                    sql += " and sender =" + GridUtils.prossSqlParm(email);
                }
            }
            if (isNoRead) {//0表示未读,1表示已读
                sql += " and isnull(read_flag,0) = 0";
            }
            return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(t482101HList.class));
        } catch (Exception e) {
@@ -228,8 +231,9 @@
    public List<t482101HList> getUserMailList(String userCode) {
        String sql = " set nocount on \n";
        try {
            sql = "select a.DocCode,isnull(a.mailType,0) as mailType,isnull(a.read_flag,0) as read_flag,a.sender,a.receiver " +
                    "from t482101H a where  a.userCode=" + GridUtils.prossSqlParm(userCode) + " order by a.mailType";
            sql = "select a.DocCode,isnull(a.mailType,0) as mailType,isnull(a.read_flag,0) as read_flag,a.sender,a.receiver, " +
                    "(case when (isnull(handle_time,'') <> '' and isnull(handle_time,'') < getdate()) then 1 else 0 end) as handle " +
                    " from t482101H a where  a.userCode=" + GridUtils.prossSqlParm(userCode) + " order by a.mailType";
            return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(t482101HList.class));
        } catch (Exception e) {
            throw e;
@@ -329,11 +333,11 @@
    }
    @Override
    public void updateRead(String docCode) {
    public void updateRead(String docCode, boolean status) {
        String sql = " set nocount on \n";
        try {
            sql += "declare @docCode varchar(200) ='" + docCode + "' \n";
            sql += "update t482101H set read_flag=1 where docCode in (select list from GetInStr(@docCode))\n";
            sql += "update t482101H set read_flag=" + (status ? 1 : 0) + " where docCode in (select list from GetInStr(@docCode))\n";
            sql += "select @@ROWCOUNT";
            jdbcTemplate.queryForObject(sql, Integer.class);
        } catch (Exception e) {
@@ -378,9 +382,13 @@
                                nextCode.setKey(mailType == 1 ? "receiver" : "sender");
                                nextCode.setMailName(eMail);
                                nextCode.setMailType(m.getMailType());
                                if (userMail.size() > 0) {
                                    count = (mailType == 1 ? (int) userMail.stream().filter(s -> s.getMailType().equals(mailType) && s.getReceiver().contains(eMail)).count() :
                                            (int) userMail.stream().filter(s -> s.getMailType().equals(mailType) && s.getSender().contains(eMail)).count());
//                                if (userMail.size() > 0) {
//                                    count = (mailType == 1 ? (int) userMail.stream().filter(s -> s.getMailType().equals(mailType) && s.getReceiver().contains(eMail)).count() :
//                                            (int) userMail.stream().filter(s -> s.getMailType().equals(mailType) && s.getSender().contains(eMail)).count());
//                                    nextCode.setTotal(count);
//                                }
                                if (mailType == 1) {//是收件箱,统计未读数量
                                    count = (int) userMail.stream().filter(s -> s.getMailType().equals(mailType) && s.getReceiver().contains(eMail) && s.getReadFlag().equals(0)).count();
                                    nextCode.setTotal(count);
                                }
                                codeList.add(nextCode);
@@ -394,13 +402,13 @@
                    case 3://待处理邮件
                        m.setChildren(new ArrayList<>());
                        if (userMail.size() > 0) {
                            m.setTotal((int) userMail.stream().filter(s -> s.getReadFlag().equals("1")).count());
                            m.setTotal((int) userMail.stream().filter(s -> s.getHandle().equals(1)).count());
                        }
                        break;
                    case 4://未读邮件
                        m.setChildren(new ArrayList<>());
                        if (userMail.size() > 0) {
                            m.setTotal((int) userMail.stream().filter(s -> s.getReadFlag().equals("0")).count());
                            m.setTotal((int) userMail.stream().filter(s -> s.getReadFlag().equals(0)).count());
                        }
                        break;
                    case 5://群邮箱
@@ -415,4 +423,18 @@
            throw e;
        }
    }
    @Override
    public void updateMailHandle(String handleTime, String docCode) {
        String sql = " set nocount on \n";
        try {
            sql += "declare @docCode varchar(200) ='" + docCode + "' \n";
            sql += "update t482101H set handle_time=" + (StringUtils.isBlank(handleTime) ? "null" : GridUtils.prossSqlParm(handleTime)) +
                    " where docCode = @docCode\n";
            sql += "select @@ROWCOUNT";
            jdbcTemplate.queryForObject(sql, Integer.class);
        } catch (Exception e) {
            throw e;
        }
    }
}
src/com/yc/crm/mail/service/MailServiceImpl.java
@@ -18,6 +18,8 @@
import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;
import static com.yc.crm.mail.service.MailImpl.shoppingImageServer;
@@ -73,14 +75,22 @@
            folder = store.getFolder("INBOX");
            // 以读写模式打开收件箱
            folder.open(Folder.READ_WRITE);
            //false 表示未读
            //false 表示未读 ,true已读,获得收件箱的邮件列表
//            FlagTerm flagTerm = new FlagTerm(new Flags(Flags.Flag.SEEN), true);
            //获得收件箱的邮件列表(已读的,根据上面的flagTerm获取已读或未读)
//            Message[] messages = folder.search(flagTerm);
            //获取收件箱邮件(全部)
            Message[] messages = folder.getMessages();
            //根据时间
//            SimpleDateFormat format=new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");//
//            SearchTerm sinceTerm=new FromStringTerm(emailEntity.getCreateTime());//开始时间
//            SearchTerm beforeTerm=new FromStringTerm(format.format(new Date()));//结束时间
//            Message[] messages = folder.search(new AndTerm(sinceTerm,beforeTerm));
            //邮箱封装保存
            setMailContent(messages, user, foundation);
            setMailContent(messages, emailEntity, foundation);
        } catch (NoSuchProviderException e) {
            throw e;
        } catch (MessagingException e) {
@@ -202,105 +212,112 @@
     * @throws MessagingException
     * @throws IOException
     */
    public void setMailContent(Message[] messages, String receiver, FoundationEntity foundation) throws Exception {
    public void setMailContent(Message[] messages, T482102Entity email, FoundationEntity foundation) throws Exception {
        try {
            List<t482101HEntity> t482101HEntityList = new ArrayList<>();
            List<String> messageIdList = mailIfc.getMessageIdList(receiver);//存在系统表里的邮件
//            List<String> deleteMsgId = new ArrayList<>();
            List<String> messageIdList = mailIfc.getMessageIdList(email.getReceiveEmail());//存在系统表里的邮件
            Message m = null;
            LocalDate startTime = LocalDate.parse(email.getCreateTime().split(" ")[0]);//创建时间
            LocalDate endTime = LocalDate.parse(email.getUpdateTime().split(" ")[0]);//更新时间
            if (startTime.equals(endTime)) {
                startTime = endTime.minusDays(30);
            } else {
                startTime = endTime;
                endTime = LocalDate.now();
            }
            Date nowTime = new Date();
            for (int i = 0; i < messages.length; i++) {
                m = messages[i];
                t482101HEntity mail = new t482101HEntity();
                String messageId = m.getHeader("Message-ID")[0];
                if (messageIdList != null && messageIdList.contains(messageId)) {//存在就不组装
//                    if (m.isSet(Flags.Flag.DELETED)) {//邮件是否需要删除
//                        deleteMsgId.add(messageId);//删除的
//                    }
                    continue;
                }
                mail.setMessageId(messageId);//获取邮件唯一ID
                mail.setMailType(1);//收件
                if (m.isSet(Flags.Flag.SEEN)) {//邮件已标记为已读
                    mail.setReadFlag(1);//已读
                }
                if (m.isExpunged()) {//检查一个消息是否已被删除。‌
                    mail.setDeleteFlag(1);//已删除
                }
                if (m.isSet(Flags.Flag.ANSWERED)) {//邮件是否已回复
                }
                if (m.isSet(Flags.Flag.DRAFT)) {//是否是草稿箱
                    mail.setMailType(0);//是草稿箱
                }
                mail.setUserCode(foundation.getUserCode());
                mail.setUserName(foundation.getUserName());
                mail.setCompanyId(foundation.getCompanyId());
                mail.setCompanyName(foundation.getCompanyName());
                mail.setClassType(1);
                mail.setSubject(m.getSubject());//标题
                Date date = m.getReceivedDate();//时间
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                mail.setReceiveTime(formatter.format(date));
                String result = "";
                StringBuilder plainText = new StringBuilder();//纯文本
                if (m.isMimeType("text/plain")) {
                    plainText.append(m.getContent());
                } else if (m.isMimeType("text/html")) {//html格式
                    result = m.getContent().toString();
                } else if (m.isMimeType("multipart/*")) {
                    MailFileEntity mailFile = new MailFileEntity();//附件
                    List<MailFileEntity.MailBodyPart> part = new ArrayList<>();
                    String unId = UUID.randomUUID().toString().toUpperCase();
                    StringBuilder attachment = new StringBuilder();
                    result = getTextFromMimeMultipart((MimeMultipart) m.getContent(), plainText, part, unId, attachment);
                    mailFile.setPart(part);
                    mailFile.setUnId(unId);//生成uuid
                    mail.setMailFile(mailFile);//附件添加到里面
                    if (StringUtils.isNotBlank(attachment)) {//附件游标保存
                        mail.setAttachFlag(1);
                        mail.setAttachmentList(unId + attachment.toString());
                LocalDate sendDate = m.getSentDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                if ((sendDate.isAfter(startTime) || sendDate.isEqual(startTime)) &&
                        (sendDate.isBefore(endTime) || sendDate.isEqual(endTime))) {//时间段获取邮件
                    t482101HEntity mail = new t482101HEntity();
                    String messageId = m.getHeader("Message-ID")[0];
                    if (messageIdList != null && messageIdList.contains(messageId)) {//存在就不组装
                        continue;
                    }
                } else {
                    result = m.getContent().toString();
                }
                mail.setContent(result);//保存内容
                mail.setPlainText(plainText.toString().trim());//明文
                String from = MimeUtility.decodeText(m.getFrom()[0].toString());
                InternetAddress internetAddress = new InternetAddress(from);
                mail.setSender(internetAddress.getAddress());//发件人
                from = MimeUtility.decodeText(m.getRecipients(Message.RecipientType.TO)[0].toString());
                internetAddress = new InternetAddress(from);
                    mail.setMessageId(messageId);//获取邮件唯一ID
                    mail.setMailType(1);//收件
                    if (m.isSet(Flags.Flag.SEEN)) {//邮件已标记为已读
                        mail.setReadFlag(1);//已读
                    }
                    if (m.isExpunged()) {//检查一个消息是否已被删除。‌
                        mail.setDeleteFlag(1);//已删除
                    }
                    if (m.isSet(Flags.Flag.ANSWERED)) {//邮件是否已回复
                    }
                    if (m.isSet(Flags.Flag.DRAFT)) {//是否是草稿箱
                        mail.setMailType(0);//是草稿箱
                    }
                    mail.setUserCode(foundation.getUserCode());
                    mail.setUserName(foundation.getUserName());
                    mail.setCompanyId(foundation.getCompanyId());
                    mail.setCompanyName(foundation.getCompanyName());
                    mail.setClassType(1);
                    mail.setSubject(m.getSubject());//标题
                    Date date = m.getReceivedDate();//时间
                    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    mail.setReceiveTime(formatter.format(date));
                    String result = "";
                    StringBuilder plainText = new StringBuilder();//纯文本
                    if (m.isMimeType("text/plain")) {
                        plainText.append(m.getContent());
                    } else if (m.isMimeType("text/html")) {//html格式
                        result = m.getContent().toString();
                    } else if (m.isMimeType("multipart/*")) {
                        MailFileEntity mailFile = new MailFileEntity();//附件
                        List<MailFileEntity.MailBodyPart> part = new ArrayList<>();
                        String unId = UUID.randomUUID().toString().toUpperCase();
                        StringBuilder attachment = new StringBuilder();
                        result = getTextFromMimeMultipart((MimeMultipart) m.getContent(), plainText, part, unId, attachment);
                        mailFile.setPart(part);
                        mailFile.setUnId(unId);//生成uuid
                        mail.setMailFile(mailFile);//附件添加到里面
                        if (StringUtils.isNotBlank(attachment)) {//附件游标保存
                            mail.setAttachFlag(1);
                            mail.setAttachmentList(unId + attachment.toString());
                        }
                    } else {
                        result = m.getContent().toString();
                    }
                    mail.setContent(result);//保存内容
                    mail.setPlainText(plainText.toString().trim());//明文
                    String from = MimeUtility.decodeText(m.getFrom()[0].toString());
                    InternetAddress internetAddress = new InternetAddress(from);
                    mail.setSender(internetAddress.getAddress());//发件人
                    from = MimeUtility.decodeText(m.getRecipients(Message.RecipientType.TO)[0].toString());
                    internetAddress = new InternetAddress(from);
//                mail.setReceiver(internetAddress.getAddress());//收件人
                List<String> receivers = new ArrayList<>();//抄送人
                receivers.add(receiver);
                mail.setReceiver(receivers);//统一成一个收件人
                    List<String> receivers = new ArrayList<>();//抄送人
                    receivers.add(email.getReceiveEmail());
                    mail.setReceiver(receivers);//统一成一个收件人
                Address[] ccAddress = m.getRecipients(Message.RecipientType.CC);
                if (ccAddress != null && ccAddress.length > 0) {
                    List<String> cc = new ArrayList<>();//抄送人
                    for (Address c : ccAddress) {
                        from = MimeUtility.decodeText(c.toString());
                        internetAddress = new InternetAddress(from);
                        cc.add(internetAddress.getAddress());
                    Address[] ccAddress = m.getRecipients(Message.RecipientType.CC);
                    if (ccAddress != null && ccAddress.length > 0) {
                        List<String> cc = new ArrayList<>();//抄送人
                        for (Address c : ccAddress) {
                            from = MimeUtility.decodeText(c.toString());
                            internetAddress = new InternetAddress(from);
                            cc.add(internetAddress.getAddress());
                        }
                        mail.setCc(cc);
                    }
                    mail.setCc(cc);
                }
                Address[] bccAddress = m.getRecipients(Message.RecipientType.BCC);
                if (bccAddress != null && bccAddress.length > 0) {
                    List<String> bcc = new ArrayList<>();//密送
                    for (Address c : bccAddress) {
                        from = MimeUtility.decodeText(c.toString());
                        internetAddress = new InternetAddress(from);
                        bcc.add(internetAddress.getAddress());
                    Address[] bccAddress = m.getRecipients(Message.RecipientType.BCC);
                    if (bccAddress != null && bccAddress.length > 0) {
                        List<String> bcc = new ArrayList<>();//密送
                        for (Address c : bccAddress) {
                            from = MimeUtility.decodeText(c.toString());
                            internetAddress = new InternetAddress(from);
                            bcc.add(internetAddress.getAddress());
                        }
                        mail.setBcc(bcc);//密送人
                    }
                    mail.setBcc(bcc);//密送人
                    t482101HEntityList.add(mail);
                }
                t482101HEntityList.add(mail);
            }
//            if (deleteMsgId.size() > 0) { //进行推送删除
//                deleteEmail(StringUtils.join(deleteMsgId, ","));
//            }
            if (t482101HEntityList.size() > 0) {
                mailAccountIfc.updateEmailTime(email.getAccountId());//更新一次配置
                mailIfc.saveReceivingMailList(t482101HEntityList);//保存
            }
        } catch (Exception e) {
@@ -338,28 +355,44 @@
                BodyPart bodyPart = mimeMultipart.getBodyPart(i);
                if (bodyPart.isMimeType("image/*")) {//图片
                    MailFileEntity.MailBodyPart p = new MailFileEntity.MailBodyPart();
                    String fileName = MimeUtility.decodeText(bodyPart.getFileName());
                    p.setFileName(fileName);//有些邮件没有扩展名
                    String cId = ((IMAPBodyPart) bodyPart).getContentID();//获取cId
                    p.setFileName(MimeUtility.decodeText(bodyPart.getFileName()));
                    if (StringUtils.isNotBlank(cId)) {//在有扩展名时候
                        if (cId.lastIndexOf(".") != -1) {
                            p.setFileType(cId.substring(cId.lastIndexOf(".") + 1));
                            p.setFileName(cId);//有些邮件没有扩展名
                        }
                    }
                    if (StringUtils.isBlank(p.getFileType()) && StringUtils.isNotBlank(fileName)) {
                        if (fileName.lastIndexOf(".") != -1) {
                            p.setFileType(fileName.substring(fileName.lastIndexOf(".") + 1));
                        }
                    }
                    p.setFileSize(bodyPart.getSize());
//                    p.setInputStream(bodyPart.getInputStream());
//                    p.setByteFile(convertInputStreamToByteArray(bodyPart.getInputStream()));
                    p.setCid(cId);//获取cId
                    part.add(p);
                    p.setByteFile(convertInputStreamToByteArray(bodyPart.getInputStream()));
                    String fieldId = UUID.randomUUID().toString();//系统自定义一个随机字段
                    p.setFieldId(fieldId);
                    String nextResult = result.toString();
                    if (nextResult.contains(cId)) {//有嵌套内容
                        //替换
                        nextResult = nextResult.replace("cid:" + cId + "", shoppingImageServer + "/uploads/attachment/82/482101/" + unId + "@p@" + cId);
                        nextResult = nextResult.replace("cid:" + cId + "", shoppingImageServer + "/uploads/attachment/82/482101/" + unId + "@p@" + p.getPhysicalFile());
                        result.setLength(0);//清空先
                        result.append(nextResult);
                    }
                    part.add(p);
                } else if (Part.ATTACHMENT.equalsIgnoreCase(bodyPart.getDisposition())) {//附件
                    MailFileEntity.MailBodyPart p = new MailFileEntity.MailBodyPart();
                    p.setFileName(MimeUtility.decodeText(bodyPart.getFileName()));
                    String fileName = MimeUtility.decodeText(bodyPart.getFileName());
                    p.setFileName(fileName);
                    if (StringUtils.isNotBlank(fileName)) {
                        p.setFileType(fileName.substring(fileName.lastIndexOf(".") + 1));
                    }
                    p.setFileSize(bodyPart.getSize());
//                    p.setInputStream(bodyPart.getInputStream());
//                    p.setByteFile(convertInputStreamToByteArray(bodyPart.getInputStream()));
                    p.setCid(((IMAPBodyPart) bodyPart).getContentID());//获取cId
                    attachment.append(";" + p.getCid());
                    p.setByteFile(convertInputStreamToByteArray(bodyPart.getInputStream()));
                    String fieldId = UUID.randomUUID().toString();//系统自定义一个随机字段
                    p.setFieldId(fieldId);
                    attachment.append(";" + fieldId);
                    part.add(p);
                } else if (bodyPart.isMimeType("multipart/*")) {
                    result.append(getTextFromMimeMultipart((MimeMultipart) bodyPart.getContent(), plainText, part, unId, attachment));