Procházet zdrojové kódy

修正更新邀请注册记录方法

hejq před 7 roky
rodič
revize
1b8143ba98

+ 26 - 0
src/main/java/com/uas/platform/b2bManage/dao/InvitationRecordDao.java

@@ -0,0 +1,26 @@
+package com.uas.platform.b2bManage.dao;
+
+import com.uas.platform.b2bManage.model.InvitationRecord;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+/**
+ * 邀请注册记录
+ *
+ * @author hejq
+ * @date 2018-07-27 18:21
+ */
+@Repository
+public interface InvitationRecordDao extends JpaSpecificationExecutor<InvitationRecord>, JpaRepository<InvitationRecord, Long> {
+
+    /**
+     * 通过被邀请企业名称查询邀请记录
+     *
+     * @param vendName 被邀请企业名称
+     * @return
+     */
+    List<InvitationRecord> findByVendname(String vendName);
+}

+ 5 - 0
src/main/java/com/uas/platform/b2bManage/model/Constant.java

@@ -37,4 +37,9 @@ public class Constant {
      * 重置密码地址
      */
     public static final String RESETPWD_URL = "/resetPassword";
+
+    /**
+     * 默认YES
+     */
+    public static final Short YES = 1;
 }

+ 14 - 0
src/main/java/com/uas/platform/b2bManage/model/EnterpriseBaseInfo.java

@@ -54,6 +54,12 @@ public class EnterpriseBaseInfo implements Serializable {
     @Column(name = "en_time")
     private Date enDate;
 
+    /**
+     * 管理员UU号
+     */
+    @Column(name = "en_adminuu")
+    private Long adminUU;
+
     public Long getUu() {
         return uu;
     }
@@ -94,6 +100,14 @@ public class EnterpriseBaseInfo implements Serializable {
         this.enDate = enDate;
     }
 
+    public Long getAdminUU() {
+        return adminUU;
+    }
+
+    public void setAdminUU(Long adminUU) {
+        this.adminUU = adminUU;
+    }
+
     @Override
     public String toString() {
         return "EnterpriseBaseInfo{" +

+ 216 - 0
src/main/java/com/uas/platform/b2bManage/model/InvitationRecord.java

@@ -0,0 +1,216 @@
+package com.uas.platform.b2bManage.model;
+
+import javax.persistence.*;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 邀请合作伙伴注册
+ * 
+ * @author hejq
+ * @time 创建时间:2017年4月19日
+ */
+@Table(name = "invitationrecords")
+@Entity
+public class InvitationRecord implements Serializable {
+
+	/**
+	 * default serialVersionUID
+	 */
+	private static final long serialVersionUID = 1L;
+
+	@Id
+	@GeneratedValue(strategy = GenerationType.AUTO)
+	@Column(name = "in_id")
+	private Long id;
+	
+	/**
+	 * 邀请企业uu
+	 */
+	@Column(name = "in_enuu")
+	private Long enuu;
+	
+	/**
+	 * 邀请企业营业执照
+	 */
+	@Column(name = "in_bussinesscode")
+	private String bussinesscode;
+
+	/**
+	 * 用户uu
+	 */
+	@Column(name = "in_useruu")
+	private Long useruu;
+
+	/**
+	 * 邀请人联系方式
+	 */
+	@Column(name = "in_usertel")
+	private String userTel;
+	
+	/**
+	 * 最后一次邀请时间
+	 */
+	@Column(name = "in_date")
+	private Date date;
+
+	/**
+	 * 被邀请的客户名称
+	 */
+	@Column(name = "in_vendname")
+	private String vendname;
+
+	/**
+	 * 被邀请的用户名称
+	 */
+	@Column(name = "in_vendusername")
+	private String vendusername;
+
+	/**
+	 * 被邀请的用户的电话
+	 */
+	@Column(name = "in_vendusertel")
+	private String vendusertel;
+
+	/**
+	 * 被邀请的用户的邮箱
+	 */
+	@Column(name = "in_venduseremail")
+	private String venduseremail;
+
+	/**
+	 * 是否已激活
+	 */
+	@Column(name = "in_active")
+	private Short active;
+
+	/**
+	 * 企业uu(如果有相同名称的设置方便查询)
+	 */
+	@Column(name = "in_venduu")
+	private Long venduu;
+
+	/**
+	 * 邀请来源
+	 */
+	@Column(name = "in_source")
+	private String source;
+
+	/**
+	 * 邀请状态
+	 */
+	@Column(name = "in_status")
+	private Integer status;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public Long getEnuu() {
+		return enuu;
+	}
+
+	public void setEnuu(Long enuu) {
+		this.enuu = enuu;
+	}
+
+	public String getBussinesscode() {
+		return bussinesscode;
+	}
+
+	public void setBussinesscode(String bussinesscode) {
+		this.bussinesscode = bussinesscode;
+	}
+
+	public Long getUseruu() {
+		return useruu;
+	}
+
+	public void setUseruu(Long useruu) {
+		this.useruu = useruu;
+	}
+
+	public String getUserTel() {
+		return userTel;
+	}
+
+	public void setUserTel(String userTel) {
+		this.userTel = userTel;
+	}
+
+	public Date getDate() {
+		return date;
+	}
+
+	public void setDate(Date date) {
+		this.date = date;
+	}
+
+	public String getVendname() {
+		return vendname;
+	}
+
+	public void setVendname(String vendname) {
+		this.vendname = vendname;
+	}
+
+	public String getVendusername() {
+		return vendusername;
+	}
+
+	public void setVendusername(String vendusername) {
+		this.vendusername = vendusername;
+	}
+
+	public String getVendusertel() {
+		return vendusertel;
+	}
+
+	public void setVendusertel(String vendusertel) {
+		this.vendusertel = vendusertel;
+	}
+
+	public String getVenduseremail() {
+		return venduseremail;
+	}
+
+	public void setVenduseremail(String venduseremail) {
+		this.venduseremail = venduseremail;
+	}
+
+	public Short getActive() {
+		return active;
+	}
+
+	public void setActive(Short active) {
+		this.active = active;
+	}
+
+	public Long getVenduu() {
+		return venduu;
+	}
+
+	public void setVenduu(Long venduu) {
+		this.venduu = venduu;
+	}
+
+	public String getSource() {
+		return source;
+	}
+
+	public void setSource(String source) {
+		this.source = source;
+	}
+
+	public Integer getStatus() {
+		return status;
+	}
+
+	public void setStatus(Integer status) {
+		this.status = status;
+	}
+}

+ 92 - 6
src/main/java/com/uas/platform/b2bManage/service/impl/InviteServiceImpl.java

@@ -2,24 +2,28 @@ package com.uas.platform.b2bManage.service.impl;
 
 import com.uas.platform.b2bManage.core.util.StringUtils;
 import com.uas.platform.b2bManage.dao.EnterpriseBaseInfoDao;
+import com.uas.platform.b2bManage.dao.InvitationRecordDao;
 import com.uas.platform.b2bManage.dao.InviteDao;
 import com.uas.platform.b2bManage.dao.UserBaseInfoDao;
-import com.uas.platform.b2bManage.model.EnterpriseBaseInfo;
-import com.uas.platform.b2bManage.model.Invite;
-import com.uas.platform.b2bManage.model.UserBaseInfo;
+import com.uas.platform.b2bManage.model.*;
 import com.uas.platform.b2bManage.page.exception.IllegalOperatorException;
 import com.uas.platform.b2bManage.service.InviteService;
 import com.uas.platform.b2bManage.support.MyException;
+import com.uas.platform.b2bManage.support.MyThread;
+import com.uas.platform.b2bManage.support.MyThreadPoolExecutor;
 import com.uas.platform.core.model.PageInfo;
+import com.uas.platform.core.model.Status;
 import com.uas.platform.core.persistence.criteria.CriterionExpression;
 import com.uas.platform.core.persistence.criteria.LogicalExpression;
 import com.uas.platform.core.persistence.criteria.PredicateUtils;
 import com.uas.platform.core.persistence.criteria.SimpleExpression;
+import org.apache.curator.utils.ThreadUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
 import org.springframework.ui.ModelMap;
+import org.springframework.util.CollectionUtils;
 
 import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.CriteriaQuery;
@@ -29,6 +33,7 @@ import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.concurrent.*;
 
 
 /**
@@ -49,6 +54,9 @@ public class InviteServiceImpl extends BaseService implements InviteService {
     @Autowired
     private UserBaseInfoDao userBaseInfoDao;
 
+    @Autowired
+    private InvitationRecordDao recordDao;
+
     /**
      * 通过分页信息获取邀请注册记录
      *
@@ -119,19 +127,79 @@ public class InviteServiceImpl extends BaseService implements InviteService {
      * @throws MyException 抛出异常
      */
     @Override
-    public ModelMap editInvite(Long enUU, String userMessage, String enterMessage) throws MyException {
+    public ModelMap editInvite(final Long enUU, String userMessage, String enterMessage) throws MyException {
         if (StringUtils.isEmpty(userMessage) || StringUtils.isEmpty(enterMessage)) {
             throw new MyException("邀请人或邀请企业信息不能为空");
         }
         // 校验用户信息
-        Long userUU = invalidUserInfo(userMessage);
-        Long inviteUU = invalidEnterpriseInfo(enterMessage);
+        final Long userUU = invalidUserInfo(userMessage);
+        final Long inviteUU = invalidEnterpriseInfo(enterMessage);
         String sql = "update sec$enterprises set en_inviteuu = " + inviteUU +
                 ", en_inviteuseruu = " + userUU + " where en_uu = " + enUU;
         jdbcTemplate.execute(sql);
+        MyThreadPoolExecutor.executor.execute(new Runnable() {
+            @Override
+            public void run() {
+                // 更新邀请记录
+                updateInvitation(userUU, enUU, inviteUU);
+            }
+        });
         return new ModelMap("content", inviteDao.findOne(enUU));
     }
 
+    /**
+     * 更新邀请记录
+     *
+     * @param userUU 邀请用户UU
+     * @param enUU 被邀请企业UU
+     * @param inviteUU 邀请企业UU
+     */
+    private void updateInvitation(Long userUU, Long enUU, Long inviteUU) {
+        EnterpriseBaseInfo enterpriseBaseInfo = enterpriseBaseInfoDao.findOne(enUU);
+        EnterpriseBaseInfo inviteEnterprise = enterpriseBaseInfoDao.findOne(inviteUU);
+        UserBaseInfo userBaseInfo = userBaseInfoDao.findOne(userUU);
+        UserBaseInfo admin = userBaseInfoDao.findOne(enterpriseBaseInfo.getAdminUU());
+        List<InvitationRecord> records = recordDao.findByVendname(enterpriseBaseInfo.getEnName());
+        if (CollectionUtils.isEmpty(records)) {
+            InvitationRecord record = initRecord(enterpriseBaseInfo, inviteEnterprise, userBaseInfo, admin);
+            recordDao.save(record);
+        } else {
+            for (InvitationRecord record : records) {
+                Long id = record.getId();
+                record = initRecord(enterpriseBaseInfo, inviteEnterprise, userBaseInfo, admin);
+                record.setId(id);
+            }
+            recordDao.save(records);
+        }
+    }
+
+    /**
+     * 初始化邀请注册信息
+     *
+     * @param enterpriseBaseInfo 被邀请企业信息
+     * @param inviteEnterprise 邀请企业信息
+     * @param userBaseInfo 邀请用户信息
+     * @param admin 注册企业管理员信息
+     * @return
+     */
+    private InvitationRecord initRecord(EnterpriseBaseInfo enterpriseBaseInfo, EnterpriseBaseInfo inviteEnterprise, UserBaseInfo userBaseInfo, UserBaseInfo admin) {
+        InvitationRecord record = new InvitationRecord();
+        record.setActive(Constant.YES);
+        record.setBussinesscode(inviteEnterprise.getEnBussinessCode());
+        record.setSource("Manage");
+        record.setDate(new Date(System.currentTimeMillis()));
+        record.setStatus(Status.DOWNLOADED.value());
+        record.setEnuu(inviteEnterprise.getUu());
+        record.setUserTel(userBaseInfo.getTel());
+        record.setUseruu(userBaseInfo.getUu());
+        record.setVendname(enterpriseBaseInfo.getEnName());
+        record.setVenduseremail(admin.getEmail());
+        record.setVendusername(admin.getName());
+        record.setVendusertel(admin.getTel());
+        record.setVenduu(enterpriseBaseInfo.getUu());
+        return record;
+    }
+
     /**
      * 校验用户信息
      *
@@ -223,4 +291,22 @@ public class InviteServiceImpl extends BaseService implements InviteService {
         String sql = "update sec$enterprises set en_inviteuu = null, en_inviteuseruu = null where en_uu = " + enUU;
         jdbcTemplate.execute(sql);
     }
+
+    public static void main(String[] args) {
+        ThreadPoolExecutor executor = new ThreadPoolExecutor(
+                5,
+                10,
+                60,
+                TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(),
+                new MyThread(),
+                new ThreadPoolExecutor.AbortPolicy());
+        executor.execute(new Runnable() {
+            @Override
+            public void run() {
+                System.out.println("Tread start");
+            }
+        });
+    }
+
+
 }

+ 27 - 0
src/main/java/com/uas/platform/b2bManage/support/MyThread.java

@@ -0,0 +1,27 @@
+package com.uas.platform.b2bManage.support;
+
+import javax.validation.constraints.NotNull;
+import java.util.concurrent.ThreadFactory;
+
+/**
+ * 手动创建线程池
+ *
+ * @author hejq
+ * @date 2018-07-27 17:54
+ */
+public class MyThread implements ThreadFactory {
+    /**
+     * Constructs a new {@code Thread}.  Implementations may also initialize
+     * priority, name, daemon status, {@code ThreadGroup}, etc.
+     *
+     * @param r a runnable to be executed by new thread instance
+     * @return constructed thread, or {@code null} if the request to
+     * create a thread is rejected
+     */
+    @Override
+    public Thread newThread(@NotNull Runnable r) {
+        Thread thread = new Thread(r);
+        thread.setName("myThread");
+        return thread;
+    }
+}

+ 38 - 0
src/main/java/com/uas/platform/b2bManage/support/MyThreadPoolExecutor.java

@@ -0,0 +1,38 @@
+package com.uas.platform.b2bManage.support;
+
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author hejq
+ * @date 2018-07-27 17:56
+ */
+public class MyThreadPoolExecutor {
+
+    /**
+     * 核心线程数
+     */
+    static final int corePoolSize = 5;
+
+    /**
+     * 最大线程
+     */
+    static final int maxmunPoolSize = 10;
+
+    /**
+     * 回收空闲线程时间间隔
+     */
+    static final int keepAliveTime = 60;
+
+    /**
+     * 自定义线程
+     */
+    public static ThreadPoolExecutor executor = new ThreadPoolExecutor(
+            corePoolSize,
+            maxmunPoolSize,
+            keepAliveTime,
+            TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(),
+            new MyThread(),
+            new ThreadPoolExecutor.AbortPolicy());
+}