|
@@ -0,0 +1,105 @@
|
|
|
+package com.citu.module.menduner.system.task;
|
|
|
+
|
|
|
+import cn.hutool.core.map.MapUtil;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
+import com.citu.framework.common.util.validation.ValidationUtils;
|
|
|
+import com.citu.module.menduner.system.controller.base.enterprise.vip.EnterpriseEntitlementRespVO;
|
|
|
+import com.citu.module.menduner.system.dal.dataobject.enterprise.EnterpriseDO;
|
|
|
+import com.citu.module.menduner.system.dal.dataobject.enterprise.EnterpriseEntitlementDO;
|
|
|
+import com.citu.module.menduner.system.dal.dataobject.enterprise.EnterpriseUserBindDO;
|
|
|
+import com.citu.module.menduner.system.dal.mysql.enterprise.EnterpriseMapper;
|
|
|
+import com.citu.module.menduner.system.enums.CommonConstants;
|
|
|
+import com.citu.module.menduner.system.service.enterprise.bind.EnterpriseUserBindService;
|
|
|
+import com.citu.module.menduner.system.service.enterprise.vip.EnterpriseEntitlementService;
|
|
|
+import com.citu.module.system.api.mail.MailSendApi;
|
|
|
+import com.citu.module.system.api.mail.dto.MailSendSingleToUserReqDTO;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 企业邮箱通知任务
|
|
|
+ * 该业务用于春节前,免费赠送3个
|
|
|
+ **/
|
|
|
+@Component
|
|
|
+public class EnterpriseEmailNoticeTask {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private EnterpriseMapper enterpriseMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private EnterpriseUserBindService enterpriseUserBindService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private EnterpriseEntitlementService enterpriseEntitlementService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private MailSendApi mailSendApi;
|
|
|
+
|
|
|
+ @DSTransactional
|
|
|
+ public void sendEmailNotice() {
|
|
|
+ // 获取企业邮箱通知开关状态
|
|
|
+ List<EnterpriseDO> enterpriseList = enterpriseMapper.getNoVipEnterpriseList();
|
|
|
+ List<Long> entId = enterpriseList.stream().map(EnterpriseDO::getId).collect(Collectors.toList());
|
|
|
+ // 企业用户绑定列表
|
|
|
+ List<EnterpriseUserBindDO> userBindList = enterpriseUserBindService.getByEnterpriseIdList(entId);
|
|
|
+// EnterpriseUserBindReqVO EnterpriseUserBindReqVO = new EnterpriseUserBindReqVO();
|
|
|
+// EnterpriseUserBindReqVO.setEnterpriseId(1L);
|
|
|
+// EnterpriseUserBindReqVO.setUserId(1L);
|
|
|
+// List<EnterpriseUserBindDO> userBindList = enterpriseUserBindService.list(EnterpriseUserBindReqVO);
|
|
|
+ Map<Long, List<EnterpriseUserBindDO>> userBindMap = userBindList.stream()
|
|
|
+ .collect(Collectors.groupingBy(EnterpriseUserBindDO::getId));
|
|
|
+
|
|
|
+ for (EnterpriseDO enterprise : enterpriseList) {
|
|
|
+ List<EnterpriseUserBindDO> mapList = userBindMap.getOrDefault(enterprise.getId(), null);
|
|
|
+ if (null == mapList) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (null == enterprise.getBizFlag() || !enterprise.getBizFlag()) {
|
|
|
+ // 没有发送过就发送邮件
|
|
|
+ sendEmail(mapList);
|
|
|
+ enterprise.setBizFlag(true);
|
|
|
+ enterpriseMapper.updateById(enterprise);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void sendEmail(List<EnterpriseUserBindDO> mapList) {
|
|
|
+ for (EnterpriseUserBindDO userBindDO : mapList) {
|
|
|
+ // 发送邮件
|
|
|
+ if (null == userBindDO.getEmail()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!ValidationUtils.isEmail(userBindDO.getEmail())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ MailSendSingleToUserReqDTO reqDTO = new MailSendSingleToUserReqDTO();
|
|
|
+ reqDTO.setMail(userBindDO.getEmail());
|
|
|
+ reqDTO.setTemplateCode(CommonConstants.EMAIL_ENTERPRISE_INIT_PASSWORD);
|
|
|
+ reqDTO.setTemplateParams(MapUtil.builder("password", (Object) userBindDO.getEmail()).build());
|
|
|
+ mailSendApi.sendSingleMailToMember(reqDTO).getCheckedData();
|
|
|
+
|
|
|
+ // 增加额度
|
|
|
+ EnterpriseEntitlementRespVO entitlement =
|
|
|
+ enterpriseEntitlementService.getByEnterpriseIdAndUserId(userBindDO.getEnterpriseId(), userBindDO.getUserId());
|
|
|
+
|
|
|
+ if (entitlement.getPublishJobCount() <= 3) {
|
|
|
+ // 小于等于3不做处理,同时规避已经加过发布数量的情况
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 设置为三个发布职位额度
|
|
|
+ enterpriseEntitlementService.update(EnterpriseEntitlementDO.builder()
|
|
|
+ .id(entitlement.getId())
|
|
|
+ .publishJobCount(3)
|
|
|
+ .build());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|