|
|
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.uas.account.entity.PartnershipRecord;
|
|
|
import com.uas.account.util.AccountUtils;
|
|
|
import com.uas.platform.b2b.dao.CommonDao;
|
|
|
+import com.uas.platform.b2b.dao.InvitationRecordDao;
|
|
|
import com.uas.platform.b2b.model.Enterprise;
|
|
|
import com.uas.platform.b2b.model.EnterpriseBaseInfo;
|
|
|
import com.uas.platform.b2b.model.InvitationRecord;
|
|
|
@@ -12,9 +13,14 @@ import com.uas.platform.b2b.model.User;
|
|
|
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.temporary.model.SmsMessage;
|
|
|
import com.uas.platform.b2b.v2.model.Invitation;
|
|
|
import com.uas.platform.b2b.v2.service.InviteRecordService;
|
|
|
import com.uas.platform.core.exception.IllegalOperatorException;
|
|
|
+import com.uas.platform.core.model.Constant;
|
|
|
+import com.uas.platform.core.util.HttpUtil;
|
|
|
+import com.uas.platform.core.util.serializer.FlexJsonUtils;
|
|
|
import com.uas.search.b2b.model.PageParams;
|
|
|
import com.uas.search.b2b.model.SPage;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -23,8 +29,7 @@ import org.springframework.ui.ModelMap;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* Created by hejq on 2018-03-22.
|
|
|
@@ -44,6 +49,12 @@ public class InviteRecordServiceImpl implements InviteRecordService {
|
|
|
@Autowired
|
|
|
private UserService userService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private InvitationRecordDao invitationRecordDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MessageConf messageConf;
|
|
|
+
|
|
|
/**
|
|
|
* 通过填写的名称检验企业是否已注册
|
|
|
*
|
|
|
@@ -185,4 +196,110 @@ public class InviteRecordServiceImpl implements InviteRecordService {
|
|
|
map.put("success", object.getString("success"));
|
|
|
return map;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 短信接口
|
|
|
+ */
|
|
|
+ final String messageUrl = "http://message.ubtob.com/sms/send";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 增加注册记录
|
|
|
+ *
|
|
|
+ * @param record 注册记录
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ModelMap invite(InvitationRecord record) {
|
|
|
+ if (StringUtils.isEmpty(record.getUseruu()) || StringUtils.isEmpty(record.getEnuu())) {
|
|
|
+ throw new IllegalOperatorException("邀请人或企业不能为空");
|
|
|
+ }
|
|
|
+ User custUser = userService.findUserByUserUU(record.getUseruu());
|
|
|
+ if (StringUtils.isEmpty(custUser)) {
|
|
|
+ throw new IllegalOperatorException("不存在邀请人信息");
|
|
|
+ }
|
|
|
+ Enterprise custEn = enterpriseService.findByEnUU(record.getEnuu());
|
|
|
+ if (StringUtils.isEmpty(custEn)) {
|
|
|
+ throw new IllegalOperatorException("不存在邀请企业信息");
|
|
|
+ }
|
|
|
+ ModelMap map = new ModelMap();
|
|
|
+ List<Enterprise> enterprises = enterpriseService.findByEnName(record.getVendname());
|
|
|
+ if (!CollectionUtils.isEmpty(enterprises)) {
|
|
|
+ map.put("error", "该企业已注册!");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ Map<String, Object> model = new HashMap<String, Object>();
|
|
|
+ // 先判断记录
|
|
|
+ InvitationRecord oldrecord = invitationRecordDao.findByUseruuAndVendname(record.getUseruu(), record.getVendname());
|
|
|
+ if (record.getId() != null) { // 如果是已存在的,直接替换
|
|
|
+ oldrecord = invitationRecordDao.findOne(record.getId());
|
|
|
+ }
|
|
|
+ if (oldrecord != null) {
|
|
|
+ oldrecord.setCount(oldrecord.getCount() + 1);
|
|
|
+ oldrecord.setDate(new Date());
|
|
|
+ if (record.getVendname() != null) {
|
|
|
+ oldrecord.setVendname(record.getVendname());
|
|
|
+ }
|
|
|
+ if (record.getVendusername() != null) {
|
|
|
+ oldrecord.setVendusername(record.getVendusername());
|
|
|
+ }
|
|
|
+ if (record.getVendusertel() != null) {
|
|
|
+ oldrecord.setVendusertel(record.getVendusertel().trim());
|
|
|
+ }
|
|
|
+ if (record.getVenduseremail() != null) {
|
|
|
+ oldrecord.setVenduseremail(record.getVenduseremail().trim());
|
|
|
+ }
|
|
|
+ record = invitationRecordDao.save(oldrecord);
|
|
|
+ if (oldrecord.getVendusertel() != null) {
|
|
|
+ sendMsg(record, custUser, custEn);
|
|
|
+ }
|
|
|
+ map.put("success", "邀请已发送");
|
|
|
+ } else {
|
|
|
+ record.setCount(1);
|
|
|
+ record.setDate(new Date(System.currentTimeMillis()));
|
|
|
+ record.setActive(Constant.NO);
|
|
|
+ record = invitationRecordDao.save(record);
|
|
|
+ if (record.getVendusertel() != null) {
|
|
|
+ sendMsg(record, custUser, custEn);
|
|
|
+ }
|
|
|
+ if (record.getId() != null) {
|
|
|
+ map.put("success", "邀请已发送");
|
|
|
+ } else {
|
|
|
+ map.put("error", "邀请发送失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 同步一个数据到账户中心(不是必须,不判断状态)
|
|
|
+ try {
|
|
|
+ record.setUser(null);
|
|
|
+ record.setId(null);
|
|
|
+ record.setSamecount(null);
|
|
|
+ record.setVenduu(null);
|
|
|
+ record.setBussinesscode(custEn.getEnBussinessCode());
|
|
|
+ AccountUtils.synchroInvitation(FlexJsonUtils.toJsonDeep(record));
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送短信
|
|
|
+ * @param record 邀请记录
|
|
|
+ * @param custUser 当前用户
|
|
|
+ * @param custEn 当前企业
|
|
|
+ */
|
|
|
+ private void sendMsg(InvitationRecord record, User custUser, Enterprise custEn) {
|
|
|
+ try {
|
|
|
+ SmsMessage sms = new SmsMessage();
|
|
|
+ List<Object> obj = new ArrayList<Object>();
|
|
|
+ obj.add(record.getVendusername());
|
|
|
+ obj.add(record.getVendname());
|
|
|
+ obj.add(custUser.getUserName() + "(" + custEn.getEnName() + ")");
|
|
|
+ sms.setParams(obj);
|
|
|
+ sms.setReceiver(record.getVendusertel());
|
|
|
+ sms.setTemplateId(messageConf.getMsgInvitationForB2B());
|
|
|
+ HttpUtil.sendPost(messageUrl, FlexJsonUtils.toJsonDeep(sms));
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|