|
|
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.uas.account.entity.PartnershipRecord;
|
|
|
import com.uas.account.util.AccountUtils;
|
|
|
+import com.uas.message.mail.service.MailService;
|
|
|
import com.uas.message.sms.service.SmsService;
|
|
|
import com.uas.platform.b2b.core.util.ThreadUtils;
|
|
|
import com.uas.platform.b2b.dao.CommonDao;
|
|
|
@@ -17,6 +18,7 @@ import com.uas.platform.b2b.service.EnterpriseService;
|
|
|
import com.uas.platform.b2b.service.InvitationRecordService;
|
|
|
import com.uas.platform.b2b.service.UserService;
|
|
|
import com.uas.platform.b2b.support.MessageConf;
|
|
|
+import com.uas.platform.b2b.support.SystemSession;
|
|
|
import com.uas.platform.b2b.temporary.model.SmsMessage;
|
|
|
import com.uas.platform.b2b.v2.model.Invitation;
|
|
|
import com.uas.platform.b2b.v2.service.InviteRecordService;
|
|
|
@@ -32,9 +34,7 @@ import org.springframework.ui.ModelMap;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* Created by hejq on 2018-03-22.
|
|
|
@@ -63,6 +63,9 @@ public class InviteRecordServiceImpl implements InviteRecordService {
|
|
|
@Autowired
|
|
|
private SmsService smsService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private MailService mailService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private UserDao userDao;
|
|
|
|
|
|
@@ -316,17 +319,16 @@ public class InviteRecordServiceImpl implements InviteRecordService {
|
|
|
}
|
|
|
User custUser = userService.findUserByUserUU(record.getUseruu());
|
|
|
if (StringUtils.isEmpty(custUser)) {
|
|
|
- throw new IllegalOperatorException("不存在邀请人信息");
|
|
|
+ throw new IllegalOperatorException(record.getUseruu() + ",不存在邀请人信息");
|
|
|
}
|
|
|
Enterprise custEn = enterpriseService.findByEnUU(record.getEnuu());
|
|
|
if (StringUtils.isEmpty(custEn)) {
|
|
|
- throw new IllegalOperatorException("不存在邀请企业信息");
|
|
|
+ throw new IllegalOperatorException(record.getEnuu() + ",不存在邀请企业信息");
|
|
|
}
|
|
|
ModelMap map = new ModelMap();
|
|
|
List<Enterprise> enterprises = enterpriseService.findByEnName(record.getVendname());
|
|
|
if (!CollectionUtils.isEmpty(enterprises)) {
|
|
|
- map.put("error", "该企业已注册!");
|
|
|
- return map;
|
|
|
+ throw new IllegalOperatorException(record.getVendname() + "已注册!");
|
|
|
}
|
|
|
// 先判断记录
|
|
|
InvitationRecord oldrecord = invitationRecordDao.findByUseruuAndVendname(record.getUseruu(), record.getVendname());
|
|
|
@@ -407,4 +409,72 @@ public class InviteRecordServiceImpl implements InviteRecordService {
|
|
|
}
|
|
|
}).run();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量邀请注册
|
|
|
+ *
|
|
|
+ * @param enUU 企业UU
|
|
|
+ * @param userUU 用户UU
|
|
|
+ * @param records 邀请记录
|
|
|
+ * @param source 数据来源
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ModelMap inviteByBatch(Long enUU, Long userUU, List<InvitationRecord> records, String source) {
|
|
|
+ Enterprise ve = enterpriseService.findByEnUU(enUU);
|
|
|
+ if (null == ve) {
|
|
|
+ throw new IllegalOperatorException(enUU + "对应的企业不存在!");
|
|
|
+ }
|
|
|
+ User vu = userDao.findOne(userUU);
|
|
|
+ if (null == vu) {
|
|
|
+ throw new IllegalOperatorException(userUU + "对应的用户不存在!");
|
|
|
+ }
|
|
|
+ for (InvitationRecord record : records) {
|
|
|
+ List<Enterprise> enterprises = enterpriseService.findByEnName(record.getVendname());
|
|
|
+ if (!CollectionUtils.isEmpty(enterprises)) {
|
|
|
+ throw new IllegalOperatorException(record.getVendname() + "已注册!");
|
|
|
+ }
|
|
|
+ record.setDate(new Date(System.currentTimeMillis()));
|
|
|
+ record.setBussinesscode(ve.getEnBussinessCode());
|
|
|
+ record.setUseruu(userUU);
|
|
|
+ record.setActive(Constant.NO);
|
|
|
+ record.setSource(source);
|
|
|
+ invite(record);
|
|
|
+ // 发送邮件
|
|
|
+ if (null != record.getVenduseremail() && record.getVenduseremail().contains("@")) {
|
|
|
+ sendEmail(record);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new ModelMap("success", "邀请已发送,共" + records.size() + "条");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送邮件通知
|
|
|
+ *
|
|
|
+ * @param record
|
|
|
+ */
|
|
|
+ private void sendEmail(final InvitationRecord record) {
|
|
|
+ Map<String, Object> model = new HashMap<String, Object>();
|
|
|
+ // 邮件信息
|
|
|
+ if (null != record.getVendusername()) {
|
|
|
+ model.put("vendorusername", record.getVendusername().trim());
|
|
|
+ }
|
|
|
+ model.put("vendorname", record.getVendname().trim());
|
|
|
+ model.put("custname", SystemSession.getUser().getUserName() + "("
|
|
|
+ + SystemSession.getUser().getEnterprise().getEnName() + ")");
|
|
|
+ model.put("inviteuid", SystemSession.getUser().getEnterprise().getEnBussinessCode());
|
|
|
+ model.put("inviteUserCode", SystemSession.getUser().getUserUU());
|
|
|
+
|
|
|
+ final Map<String, Object> modMap = model;
|
|
|
+ ThreadUtils.task(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ mailService.send(messageConf.getTplInvitationForB2B(), record.getVenduseremail(), modMap);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }).run();
|
|
|
+ }
|
|
|
}
|