|
|
@@ -0,0 +1,188 @@
|
|
|
+package com.uas.platform.b2b.erp.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.dubbo.common.utils.CollectionUtils;
|
|
|
+import com.uas.account.util.AccountUtils;
|
|
|
+import com.uas.message.mail.service.MailService;
|
|
|
+import com.uas.platform.b2b.dao.CommonDao;
|
|
|
+import com.uas.platform.b2b.dao.InvitationRecordDao;
|
|
|
+import com.uas.platform.b2b.dao.VendorDao;
|
|
|
+import com.uas.platform.b2b.erp.model.ErpInviteRecord;
|
|
|
+import com.uas.platform.b2b.erp.model.InquiryVendorInfo;
|
|
|
+import com.uas.platform.b2b.erp.service.VendorService;
|
|
|
+import com.uas.platform.b2b.model.InvitationRecord;
|
|
|
+import com.uas.platform.b2b.model.Vendor;
|
|
|
+import com.uas.platform.b2b.support.MessageConf;
|
|
|
+import com.uas.platform.b2b.support.SysConf;
|
|
|
+import com.uas.platform.b2b.support.SystemSession;
|
|
|
+import com.uas.platform.b2b.temporary.model.SmsMessage;
|
|
|
+import com.uas.platform.core.model.Status;
|
|
|
+import com.uas.platform.core.util.HttpUtil;
|
|
|
+import com.uas.platform.core.util.serializer.FlexJsonUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by hejq on 2017-09-29.
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class VendorServiceImpl implements VendorService{
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InvitationRecordDao invitationRecordDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MailService mailService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MessageConf messageConf;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private VendorDao vendorDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysConf sysConf;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CommonDao commonDao;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 短信接口
|
|
|
+ */
|
|
|
+ final String messageUrl = "http://message.ubtob.com/sms/send";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 日期格式
|
|
|
+ */
|
|
|
+ final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void saveInvitation(List<InquiryVendorInfo> infos) {
|
|
|
+ if(!CollectionUtils.isEmpty(infos)) {
|
|
|
+ for(InquiryVendorInfo info :infos) {
|
|
|
+ boolean tplstatus = false;
|
|
|
+ boolean msgstatus = false;
|
|
|
+ InvitationRecord record = invitationRecordDao.findByEnuuAndVendname(SystemSession.getUser().getEnterprise().getUu(), info.getVe_name());
|
|
|
+ if(null == record || Status.NOT_UPLOAD.value() == record.getStatus()) {
|
|
|
+ record = info.covert();
|
|
|
+ //发送邮件前先进行判断,每天每个供应商只发送一封邮件
|
|
|
+ List<ErpInviteRecord> inviteRecords = getRecord(record.getVendname());
|
|
|
+ if(inviteRecords.size() == 0) {
|
|
|
+ // 发送邮件或短信成功才进行保存
|
|
|
+ if(record.getVenduseremail() != null) {
|
|
|
+ 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", info.getEn_adminname() + "(" + info.getEn_name() + ")");
|
|
|
+ // 注册地址链接,为了测试正式分开,从系统配置中取
|
|
|
+ String url = sysConf.getRegisterUrl() + "?inviteuid=" + record.getBussinesscode()
|
|
|
+ + "&inviteUserCode=" + SystemSession.getUser().getUserUU() + "&method=addVendor";
|
|
|
+ model.put("registerUrl", url);
|
|
|
+ try {
|
|
|
+ mailService.send(messageConf.getTplInvitationForERP(), record.getVenduseremail(), model);
|
|
|
+ record.setStatus(Status.DOWNLOADED.value());
|
|
|
+ tplstatus = true;
|
|
|
+ } catch (Exception e) {
|
|
|
+ record.setStatus(Status.NOT_UPLOAD.value());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(record.getVendusertel() != null) {
|
|
|
+ try {
|
|
|
+ SmsMessage sms = new SmsMessage();
|
|
|
+ List<Object> obj = new ArrayList<Object>();
|
|
|
+ obj.add(record.getVendusername());
|
|
|
+ obj.add(record.getVendname());
|
|
|
+ obj.add(info.getEn_adminname() + "(" + info.getEn_name() + ")");
|
|
|
+ sms.setParams(obj);
|
|
|
+ sms.setReceiver(record.getVendusertel());
|
|
|
+ sms.setTemplateId(messageConf.getMsgInvitationForERP());
|
|
|
+ HttpUtil.sendPost(messageUrl, FlexJsonUtils.toJsonDeep(sms));
|
|
|
+ record.setStatus(Status.DOWNLOADED.value());
|
|
|
+ msgstatus = true;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(tplstatus || msgstatus) {
|
|
|
+ invitationRecordDao.save(record);
|
|
|
+ //记录状态
|
|
|
+ addNewRecord(record.getVendusertel(), record.getVenduseremail(), sdf.format(new Date()), record.getVendname());
|
|
|
+ }
|
|
|
+ // 同步一个数据到账户中心(不是必须,不判断状态)
|
|
|
+ if(record.getId() == null) {// 新增时候才进行同步
|
|
|
+ try {
|
|
|
+ record.setUser(null);
|
|
|
+ record.setId(null);
|
|
|
+ record.setSamecount(null);
|
|
|
+ record.setVenduu(null);
|
|
|
+ record.setBussinesscode(SystemSession.getUser().getEnterprise().getEnBussinessCode());
|
|
|
+ AccountUtils.synchroInvitation(FlexJsonUtils.toJsonDeep(record));
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询邀请是否已经发送
|
|
|
+ *
|
|
|
+ * @param venduseremail
|
|
|
+ * @param vendusertel
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<ErpInviteRecord> getRecord(String name) {
|
|
|
+ String sql = "select * from invitation_tplrecord where ve_name = '" + name +"'";
|
|
|
+ List<ErpInviteRecord> records = commonDao.query(sql, ErpInviteRecord.class);
|
|
|
+ return records;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 记录一个邮件发送状况,防止重复发送
|
|
|
+ *
|
|
|
+ * @param vendusertel
|
|
|
+ * @param venduseremail
|
|
|
+ * @param format
|
|
|
+ */
|
|
|
+ private void addNewRecord(String vendusertel, String venduseremail, String date, String name) {
|
|
|
+ String sql = "insert into invitation_tplrecord values('" + venduseremail + "','" + vendusertel + "','success','" + date + "','" + name +"')";
|
|
|
+ commonDao.getJdbcTemplate().update(sql);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<InquiryVendorInfo> getInfo() {
|
|
|
+ List<Vendor> vendors = vendorDao.findByMyEnUUAndErpstatus(SystemSession.getUser().getEnterprise().getUu(), Status.NOT_UPLOAD.value());
|
|
|
+ List<InquiryVendorInfo> infos = new ArrayList<InquiryVendorInfo>();
|
|
|
+ if(!CollectionUtils.isEmpty(vendors)) {
|
|
|
+ for(Vendor vendor : vendors) {
|
|
|
+ InquiryVendorInfo info = vendor.covert();
|
|
|
+ infos.add(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return infos;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateStatus(String ids) {
|
|
|
+ updateDownStatus(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新平台供应商UU的下载状态
|
|
|
+ *
|
|
|
+ * @param ids
|
|
|
+ */
|
|
|
+ private void updateDownStatus(String ids) {
|
|
|
+ String sql = "update purc$vendors set ve_erpstatus = 203 where ve_id in (" + ids +")";
|
|
|
+ commonDao.getJdbcTemplate().update(sql);
|
|
|
+ }
|
|
|
+}
|