‘linchangsheng’ 7 months ago
parent
commit
9fa4556c4f

+ 4 - 0
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/bean/user/UserApplyBean.java

@@ -32,6 +32,10 @@ public class UserApplyBean {
     @ApiModelProperty("其他图片")
     private List<WorkerImg> workerImgs;
 
+    @ApiModelProperty("是否购买")
+    private String isBuy;
+
+
     @ApiModelProperty("银行卡")
     private String bankAccount;
 

+ 1 - 0
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/logic/user/UserLogic.java

@@ -1185,6 +1185,7 @@ public class UserLogic {
         user.setApplyType(type);
         user.setApplyWebsitId(websitId);
         user.setApplyTime(new Date());
+        user.setIsBuy(userApplyBean.getIsBuy());
         user.updateById();
 
         if (CollectionUtils.isNotEmpty(workerImgs)) {

+ 2 - 1
mall-server-api/src/main/java/com/gree/mall/manager/bean/policy/PolicyOrderVO.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.gree.mall.manager.annotation.ZfireField;
 import com.gree.mall.manager.enums.IsYesNoEnum;
+import com.gree.mall.manager.enums.PolicyOrderStatusEnum;
 import com.gree.mall.manager.plus.entity.PolicyOrder;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
@@ -23,7 +24,7 @@ public class PolicyOrderVO  {
     private String id;
 
     @ApiModelProperty(value = "保单状态")
-    private String policyOrderStatus;
+    private PolicyOrderStatusEnum policyOrderStatus;
 
     @ApiModelProperty(value = "保单名称")
     private String policyName;

+ 20 - 0
mall-server-api/src/main/java/com/gree/mall/manager/enums/PolicyOrderStatusEnum.java

@@ -0,0 +1,20 @@
+package com.gree.mall.manager.enums;
+
+import com.gree.mall.manager.enums.base.BaseEnum;
+import lombok.AccessLevel;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+@Getter
+@AllArgsConstructor(access = AccessLevel.PRIVATE)
+public enum  PolicyOrderStatusEnum implements BaseEnum {
+
+    DSX("DSX", "待生效"),
+    BZZ("BZZ", "保障中"),
+    YSX("YSX", "已失效"),
+
+    ;
+
+    private final String key;
+    private final String remark;
+}

+ 21 - 0
mall-server-api/src/main/java/com/gree/mall/manager/enums/PolicyTypeEnum.java

@@ -0,0 +1,21 @@
+package com.gree.mall.manager.enums;
+
+import com.gree.mall.manager.enums.base.BaseEnum;
+import lombok.AccessLevel;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+@Getter
+@AllArgsConstructor(access = AccessLevel.PRIVATE)
+public enum  PolicyTypeEnum implements BaseEnum {
+    AC("AC","意外险"),
+    EM("EM","雇主险"),
+    IN("IN","工伤险"),
+
+
+            ;
+
+    private final String key;
+    private final String remark;
+
+}

+ 282 - 0
mall-server-api/src/main/java/com/gree/mall/manager/logic/policy/AgreementLogic.java

@@ -3,11 +3,13 @@ package com.gree.mall.manager.logic.policy;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.gree.mall.manager.bean.ExcelData;
 import com.gree.mall.manager.bean.admin.AdminUserCom;
 import com.gree.mall.manager.bean.policy.*;
 import com.gree.mall.manager.commonmapper.PolicyCMapper;
+import com.gree.mall.manager.enums.*;
 import com.gree.mall.manager.logic.common.CommonLogic;
 import com.gree.mall.manager.plus.entity.*;
 import com.gree.mall.manager.plus.service.*;
@@ -16,11 +18,15 @@ import com.gree.mall.manager.utils.email.EmailUtilsNew;
 import com.gree.mall.manager.utils.excel.ExcelUtils;
 import com.gree.mall.manager.zfire.bean.ZfireParamBean;
 import com.gree.mall.manager.zfire.util.FieldUtils;
+import lombok.SneakyThrows;
+import org.apache.http.client.utils.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
 
+import javax.mail.MessagingException;
 import java.io.File;
 import java.io.IOException;
 import java.util.*;
@@ -60,6 +66,12 @@ public class AgreementLogic {
     @Autowired
     MailboxSendRecordPolicyService mailboxSendRecordPolicyService;
 
+    @Autowired
+    PolicyOrderService policyOrderService;
+
+    @Autowired
+    WorkerPolicyService workerPolicyService;
+
 
 
     public IPage<AgreementVo> list(Page page, ZfireParamBean zfireParam) {
@@ -410,4 +422,274 @@ public class AgreementLogic {
     public void del(String id) {
         agreementService.removeById(id);
     }
+
+    public void sendEmailSche() {
+
+
+        Mailbox mailbox = mailboxService.getById("1");
+
+        //今天要发送的保单
+        //Date startTime = DateUtil.beginOfDay(new Date());
+        Date endTime = DateUtil.parseDateTime(DateUtils.formatDate(new Date(),"yyyy-MM-dd") +" "+ mailbox.getSendTime()+":00");
+        if(new Date().getTime() < endTime.getTime()){
+            //还没到可发邮件的时间
+            return;
+        }
+
+        if (mailboxSendRecordService.lambdaQuery().gt(MailboxSendRecord::getSendTime, DateUtil.beginOfDay(new Date())).count() > 0) {
+            return;
+        }
+
+
+        List<MailboxReceive> mailboxReceives = mailboxReceiveService.lambdaQuery().eq(MailboxReceive::getMailboxId, mailbox.getId()).list();
+
+
+
+
+        //意外保险发送邮件
+        List<PolicyOrder> policyOrders = policyOrderService.lambdaQuery().eq(PolicyOrder::getType, PolicyTypeEnum.AC.getKey())
+                .eq(PolicyOrder::getIsPay, IsYesNoEnum.YES.getKey())
+                .eq(PolicyOrder::getIsSend, IsYesNoEnum.NO.getKey()).list();
+
+
+        if (!CollectionUtils.isEmpty(policyOrders)){
+            MailboxSendRecord mailboxSendRecord = new MailboxSendRecord();
+            mailboxSendRecord.setId(IdWorker.getIdStr());
+            mailboxSendRecord.setPolicyType(PolicyTypeEnum.AC.getKey());
+            mailboxSendRecord.setSendBatch(mailboxSendRecord.getId());
+            mailboxSendRecord.setSendMailbox(mailbox.getSendMailbox());
+            mailboxSendRecord.setReceiveMailbox(mailbox.getAccidentMailbox());
+            mailboxSendRecord.setReceiptStatus(IsYesNoEnum.NO.getKey());
+            mailboxSendRecord.setCompanyWechatId(mailbox.getCompanyWechatId());
+            mailboxSendRecord.setCompanyWechatName(mailbox.getCompanyWechatName());
+
+            List<MailboxSendRecordPolicy> mailboxSendRecordPolicies = new ArrayList<>();
+
+            for (PolicyOrder policyOrder : policyOrders) {
+                MailboxSendRecordPolicy mailboxSendRecordPolicy = new MailboxSendRecordPolicy();
+
+                mailboxSendRecordPolicy.setCompanyWechatId(mailboxSendRecord.getCompanyWechatId());
+                mailboxSendRecordPolicy.setCompanyWechatId(mailboxSendRecord.getCompanyWechatName());
+                mailboxSendRecordPolicy.setPolicyNumber(policyOrder.getPolicyId());
+                mailboxSendRecordPolicy.setWebsitName(policyOrder.getWebsitName());
+                mailboxSendRecordPolicy.setWebsitId(policyOrder.getWebsitId());
+                mailboxSendRecordPolicy.setPolicyMobile(policyOrder.getWorkerMobile());
+                mailboxSendRecordPolicy.setPolicyNumber(policyOrder.getWorkerNumber());
+                mailboxSendRecordPolicy.setPolicyIdcard(policyOrder.getWorkerIdcard());
+                mailboxSendRecordPolicy.setType("IN");
+                mailboxSendRecordPolicy.setSendBatch(mailboxSendRecord.getSendBatch());
+                mailboxSendRecordPolicy.setPolicyOrderId(policyOrder.getId());
+                mailboxSendRecordPolicy.setPolicyType(PolicyTypeEnum.AC.getKey());
+
+                mailboxSendRecordPolicies.add(mailboxSendRecordPolicy);
+            }
+
+            mailboxSendRecord.insert();
+            mailboxSendRecordPolicyService.saveBatch(mailboxSendRecordPolicies);
+
+            //发邮件
+            try {
+                this.sendEmailFile(mailboxSendRecordPolicies, mailboxSendRecord, mailbox);
+                mailboxSendRecord.setSendStatus("OK");
+                mailboxSendRecord.setSendTime(new Date());
+                mailboxSendRecord.updateById();
+            } catch (Exception e) {
+                mailboxSendRecord.setSendStatus("NO");
+                mailboxSendRecord.setSendTime(new Date());
+                mailboxSendRecord.updateById();
+            }
+        }
+
+
+        //雇主保险发送邮件
+        List<PolicyOrder> policyOrdersEm = policyOrderService.lambdaQuery()
+                .eq(PolicyOrder::getType, PolicyTypeEnum.EM.getKey())
+                .eq(PolicyOrder::getIsSend, IsYesNoEnum.NO.getKey()).list();
+
+        if (!CollectionUtils.isEmpty(policyOrders)){
+            MailboxSendRecord mailboxSendRecord = new MailboxSendRecord();
+            mailboxSendRecord.setId(IdWorker.getIdStr());
+            mailboxSendRecord.setPolicyType(PolicyTypeEnum.EM.getKey());
+            mailboxSendRecord.setSendBatch(mailboxSendRecord.getId());
+            mailboxSendRecord.setSendMailbox(mailbox.getSendMailbox());
+            mailboxSendRecord.setReceiveMailbox(mailbox.getEmployerMailbox());
+            mailboxSendRecord.setReceiptStatus(IsYesNoEnum.NO.getKey());
+            mailboxSendRecord.setCompanyWechatId(mailbox.getCompanyWechatId());
+            mailboxSendRecord.setCompanyWechatName(mailbox.getCompanyWechatName());
+
+            List<MailboxSendRecordPolicy> mailboxSendRecordPolicies = new ArrayList<>();
+
+            for (PolicyOrder policyOrder : policyOrdersEm) {
+                MailboxSendRecordPolicy mailboxSendRecordPolicy = new MailboxSendRecordPolicy();
+
+                mailboxSendRecordPolicy.setCompanyWechatId(mailboxSendRecord.getCompanyWechatId());
+                mailboxSendRecordPolicy.setCompanyWechatId(mailboxSendRecord.getCompanyWechatName());
+                mailboxSendRecordPolicy.setPolicyNumber(policyOrder.getPolicyId());
+                mailboxSendRecordPolicy.setPolicyOrderId(policyOrder.getId());
+                mailboxSendRecordPolicy.setWebsitName(policyOrder.getWebsitName());
+                mailboxSendRecordPolicy.setWebsitId(policyOrder.getWebsitId());
+                mailboxSendRecordPolicy.setPolicyMobile(policyOrder.getWorkerMobile());
+                mailboxSendRecordPolicy.setPolicyNumber(policyOrder.getWorkerNumber());
+                mailboxSendRecordPolicy.setPolicyIdcard(policyOrder.getWorkerIdcard());
+                mailboxSendRecordPolicy.setType("IN");
+                mailboxSendRecordPolicy.setSendBatch(mailboxSendRecord.getSendBatch());
+                mailboxSendRecordPolicy.setPolicyType(PolicyTypeEnum.EM.getKey());
+
+                if (!StringUtil.isEmpty(policyOrder.getReplaceName())) {
+                    mailboxSendRecordPolicy.setType("RE");
+                    mailboxSendRecordPolicy.setReplaceName(policyOrder.getReplaceName());
+                    mailboxSendRecordPolicy.setReplaceIdcard(policyOrder.getReplaceIdcard());
+                }
+
+
+                mailboxSendRecordPolicies.add(mailboxSendRecordPolicy);
+            }
+
+            mailboxSendRecord.insert();
+            mailboxSendRecordPolicyService.saveBatch(mailboxSendRecordPolicies);
+
+            //发邮件
+            try {
+                this.sendEmailFileEm(mailboxSendRecordPolicies, mailboxSendRecord, mailbox);
+                mailboxSendRecord.setSendStatus("OK");
+                mailboxSendRecord.setSendTime(new Date());
+                mailboxSendRecord.updateById();
+            } catch (Exception e) {
+                mailboxSendRecord.setSendStatus("NO");
+                mailboxSendRecord.setSendTime(new Date());
+                mailboxSendRecord.updateById();
+            }
+        }
+        //工伤保险发送邮件
+        for (MailboxReceive mailboxReceive : mailboxReceives) {
+            List<PolicyOrder> policyOrdersIn = policyOrderService.lambdaQuery()
+                    .eq(PolicyOrder::getType, PolicyTypeEnum.IN.getKey())
+                    .eq(PolicyOrder::getBuyUnitId, mailboxReceive.getDictId())
+                    .eq(PolicyOrder::getIsSend, IsYesNoEnum.NO.getKey()).list();
+
+            if (!CollectionUtils.isEmpty(policyOrdersIn)){
+
+
+                MailboxSendRecord mailboxSendRecord = new MailboxSendRecord();
+                mailboxSendRecord.setId(IdWorker.getIdStr());
+                mailboxSendRecord.setPolicyType(PolicyTypeEnum.IN.getKey());
+                mailboxSendRecord.setSendBatch(mailboxSendRecord.getId());
+                mailboxSendRecord.setSendMailbox(mailbox.getSendMailbox());
+                mailboxSendRecord.setReceiveMailbox(mailboxReceive.getReceiveMailbox());
+                mailboxSendRecord.setReceiptStatus(IsYesNoEnum.NO.getKey());
+                mailboxSendRecord.setCompanyWechatId(mailbox.getCompanyWechatId());
+                mailboxSendRecord.setCompanyWechatName(mailbox.getCompanyWechatName());
+
+                List<MailboxSendRecordPolicy> mailboxSendRecordPolicies = new ArrayList<>();
+
+                for (PolicyOrder policyOrder : policyOrdersIn) {
+                    MailboxSendRecordPolicy mailboxSendRecordPolicy = new MailboxSendRecordPolicy();
+
+                    mailboxSendRecordPolicy.setCompanyWechatId(mailboxSendRecord.getCompanyWechatId());
+                    mailboxSendRecordPolicy.setCompanyWechatId(mailboxSendRecord.getCompanyWechatName());
+                    mailboxSendRecordPolicy.setPolicyNumber(policyOrder.getPolicyId());
+                    mailboxSendRecordPolicy.setPolicyOrderId(policyOrder.getId());
+                    mailboxSendRecordPolicy.setWebsitName(policyOrder.getWebsitName());
+                    mailboxSendRecordPolicy.setWebsitId(policyOrder.getWebsitId());
+                    mailboxSendRecordPolicy.setPolicyMobile(policyOrder.getWorkerMobile());
+                    mailboxSendRecordPolicy.setPolicyNumber(policyOrder.getWorkerNumber());
+                    mailboxSendRecordPolicy.setPolicyIdcard(policyOrder.getWorkerIdcard());
+                    mailboxSendRecordPolicy.setType("IN");
+                    mailboxSendRecordPolicy.setSendBatch(mailboxSendRecord.getSendBatch());
+                    mailboxSendRecordPolicy.setPolicyType(PolicyTypeEnum.IN.getKey());
+
+
+                    mailboxSendRecordPolicies.add(mailboxSendRecordPolicy);
+                }
+
+                mailboxSendRecord.insert();
+                mailboxSendRecordPolicyService.saveBatch(mailboxSendRecordPolicies);
+
+                //发邮件
+                try {
+                    this.sendEmailFileIn(mailboxSendRecordPolicies, mailboxSendRecord, mailbox);
+                    mailboxSendRecord.setSendStatus("OK");
+                    mailboxSendRecord.setSendTime(new Date());
+                    mailboxSendRecord.updateById();
+                } catch (Exception e) {
+                    mailboxSendRecord.setSendStatus("NO");
+                    mailboxSendRecord.setSendTime(new Date());
+                    mailboxSendRecord.updateById();
+                }
+            }
+        }
+
+
+    }
+
+    public void receEmail() throws IOException, MessagingException {
+
+        Mailbox mailbox = mailboxService.getById("1");
+
+        List<MailboxReceive> mailboxReceives = mailboxReceiveService.lambdaQuery().eq(MailboxReceive::getMailboxId, mailbox.getId()).list();
+
+        Boolean rece = new EmailUtilsNew(mailbox.getSendMailbox(), mailbox.getSendPassword()).receEmail(mailbox.getAccidentMailbox());
+        if(rece){
+            //将今天的意外险都收到回执
+            mailboxSendRecordService.lambdaUpdate()
+                    .between(MailboxSendRecord::getSendTime,DateUtil.beginOfDay(new Date()), DateUtil.endOfDay(new Date()))
+                    .eq(MailboxSendRecord::getPolicyType,PolicyTypeEnum.AC.getKey())
+                    .set(MailboxSendRecord::getReceiptStatus,IsYesNoEnum.YES.getKey())
+                    .set(MailboxSendRecord::getReceiptTime,new Date()).update();
+
+            //将保险都生效或待生效
+            List<MailboxSendRecord> mailboxSendRecords = mailboxSendRecordService.lambdaQuery()
+                    .between(MailboxSendRecord::getSendTime, DateUtil.beginOfDay(new Date()), DateUtil.endOfDay(new Date()))
+                    .eq(MailboxSendRecord::getPolicyType, PolicyTypeEnum.AC.getKey()).list();
+
+            if (!CollectionUtils.isEmpty(mailboxSendRecords)) {
+
+                List<String> sendBatch = mailboxSendRecords.stream().map(MailboxSendRecord::getSendBatch).collect(Collectors.toList());
+
+                List<MailboxSendRecordPolicy> mailboxSendRecordPolicies = mailboxSendRecordPolicyService.lambdaQuery().in(MailboxSendRecordPolicy::getSendBatch, sendBatch).list();
+
+                List<String> policyOrderId = mailboxSendRecordPolicies.stream().map(MailboxSendRecordPolicy::getPolicyOrderId).collect(Collectors.toList());
+
+                policyOrderService.lambdaUpdate()
+                        .in(PolicyOrder::getId,policyOrderId)
+                        .le(PolicyOrder::getStartTime,new Date())
+                        .ge(PolicyOrder::getEndTime,new Date())
+                        .set(PolicyOrder::getPolicyOrderStatus, PolicyOrderEmStutasEnum.BZZ.getKey()).update();
+                workerPolicyService.lambdaUpdate()
+                        .in(WorkerPolicy::getOrderId,policyOrderId)
+                        .le(WorkerPolicy::getStartTime,new Date())
+                        .ge(WorkerPolicy::getEndTime,new Date())
+                        .set(WorkerPolicy::getStatus, "ON").update();
+
+            }
+        }
+        Boolean receEm = new EmailUtilsNew(mailbox.getSendMailbox(), mailbox.getSendPassword()).receEmail(mailbox.getEmployerMailbox());
+
+        if(receEm){
+            //将今天的雇主险都收到回执
+            mailboxSendRecordService.lambdaUpdate()
+                    .between(MailboxSendRecord::getSendTime,DateUtil.beginOfDay(new Date()), DateUtil.endOfDay(new Date()))
+                    .eq(MailboxSendRecord::getPolicyType,PolicyTypeEnum.EM.getKey())
+                    .set(MailboxSendRecord::getReceiptStatus,IsYesNoEnum.YES.getKey())
+                    .set(MailboxSendRecord::getReceiptTime,new Date()).update();
+
+
+        }
+
+
+        for (MailboxReceive mailboxReceive : mailboxReceives) {
+            Boolean receIn = new EmailUtilsNew(mailbox.getSendMailbox(), mailbox.getSendPassword()).receEmail(mailboxReceive.getReceiveMailbox());
+
+            if(receIn){
+                //将今天的工伤险都收到回执
+                mailboxSendRecordService.lambdaUpdate()
+                        .between(MailboxSendRecord::getSendTime,DateUtil.beginOfDay(new Date()), DateUtil.endOfDay(new Date()))
+                        .eq(MailboxSendRecord::getPolicyType,PolicyTypeEnum.IN.getKey())
+                        .eq(MailboxSendRecord::getReceiveMailbox,mailboxReceive.getReceiveMailbox())
+                        .set(MailboxSendRecord::getReceiptStatus,IsYesNoEnum.YES.getKey())
+                        .set(MailboxSendRecord::getReceiptTime,new Date()).update();
+            }
+        }
+
+    }
 }

+ 47 - 0
mall-server-api/src/main/java/com/gree/mall/manager/schedule/InsureEmailSchedule.java

@@ -0,0 +1,47 @@
+package com.gree.mall.manager.schedule;
+
+
+
+import com.gree.mall.manager.logic.policy.AgreementLogic;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import javax.mail.MessagingException;
+import java.io.IOException;
+
+/**
+ * 定时购买保险
+ */
+@ConditionalOnProperty(name = "schedule.enable", havingValue = "true", matchIfMissing = true)
+@Component
+public class InsureEmailSchedule {
+
+
+    @Autowired
+    AgreementLogic agreementLogic;
+
+
+
+    //每小时执行1次
+    @Scheduled(fixedDelay = 60*60* 1000)
+    public void task() throws IOException {
+        agreementLogic.sendEmailSche();
+    }
+
+
+    //监测今天是否有回执邮件,如果有则表示今天买保险的回执成功
+    @Scheduled(fixedDelay = 60* 1000)
+    public void task2() throws IOException, MessagingException {
+        agreementLogic.receEmail();
+    }
+
+
+/*    //保险过期
+    @Scheduled(fixedDelay = 60*60* 1000)
+    public void task3(){
+        agreementLogic.offInsure();
+    }*/
+
+}

+ 2 - 0
mall-server-api/src/main/java/com/gree/mall/manager/utils/email/EmailUtilsNew.java

@@ -179,6 +179,8 @@ public class EmailUtilsNew {
             //今天接收的邮件
             if(receivedDate.getTime() > DateUtil.beginOfDay(new Date()).getTime() && from.indexOf(receEmail) > -1){
                 messages[i].setFlag(Flags.Flag.SEEN, true);
+                folder.close(false);
+                store.close();
                 return true;
             }