liupeng 4 years ago
parent
commit
d56b1de705

+ 6 - 1
code/sapparent/sapservice/src/main/java/org/fouram/core/plugin/weixin/cp/util/WXCpMessageUtil.java

@@ -29,6 +29,11 @@ public class WXCpMessageUtil {
 	}
 
 	public static void main(String[] args) throws WxErrorException {
-		send("test\njjjjjj\n<a href=\"http://www.baidu.com\">百度一下</a>", "1000001");
+		StringBuffer sb = new StringBuffer();
+		sb.append("有一个新员工入职,待同步企业微信").append("\n").append("员工姓名:").append("张三")
+		.append("\n").append("手机号:").append("138XXXXXXXX")
+		.append("\n").append("邮箱:").append("138XXXXXXXX@")
+		.append("\n").append("<a href=\"http://www.baidu.com\"><a href=\"http://www.baidu.com\">立即同步</a></a>");
+		send(sb.toString(), "1000001");
 	}
 }

+ 3 - 0
code/sapparent/sapservice/src/main/java/org/fouram/entity/SapUser.java

@@ -86,6 +86,9 @@ public class SapUser implements Serializable {
 	
 	@ApiModelProperty(value = "敏感数据微信部门")
 	private String wxFullDepart;
+	
+	@ApiModelProperty(value = "是否发送入职提示消息")
+	private Boolean sendEntryMessageFlag;
 
 	private List<List<SapOrg>> departList;
 	

+ 27 - 3
code/sapparent/sapservice/src/main/java/org/fouram/job/MessageJob.java

@@ -1,13 +1,37 @@
 package org.fouram.job;
 
+import java.util.List;
+
+import org.fouram.core.util.LoggerUtil;
+import org.fouram.entity.SapUser;
+import org.fouram.service.SapUserService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
 
 @Service
-@Transactional
 public class MessageJob {
 
+	@Autowired
+	private SapUserService sapUserService;
+
 	public void taskBiz() {
-		System.out.println(111);
+		try {
+			List<SapUser> sapUsers = sapUserService.selectNotSendEntryMessageList();
+			StringBuffer messageContent = null;
+			for (SapUser sapUser : sapUsers) {
+				messageContent = new StringBuffer();
+				messageContent.append("有一个新员工入职,待同步企业微信").append("\n").append("员工姓名:").append(sapUser.getName())
+						.append("\n").append("手机号:").append(sapUser.getFormatMobile()).append("\n").append("邮箱:")
+						.append(sapUser.getRealEmail()).append("\n").append(getSyncUrl());
+				sapUserService.sendEntryMessage(messageContent.toString(), sapUser);
+			}
+		} catch (Exception e) {
+			LoggerUtil.error(e);
+		}
+	}
+
+	private static String getSyncUrl() {
+		String syncUrl = "https://studybom.suggest.vip/#/userSync/list";
+		return String.format("<a href=\"%s\"><a href=\"%s\">立即同步</a></a>", syncUrl, syncUrl);
 	}
 }

+ 11 - 0
code/sapparent/sapservice/src/main/java/org/fouram/mapper/SapUserMapper.xml

@@ -153,4 +153,15 @@
 		</if>
 		order by sortNumber ASC
 	</select>
+	
+	<select id="selectNotSendEntryMessageList" resultType="SapUser">
+		select * from sap_user 
+		where isPrimary = 1 and delFlag = 0 and sendEntryMessageFlag = 0 and result = 'ENTRY'
+	</select>
+
+	<update id="updateSendEntryMessageFlag">
+		update sap_user 
+		set sendEntryMessageFlag=#{sendEntryMessageFlag} 
+		where userId=#{userId}
+	</update>
 </mapper>

+ 27 - 10
code/sapparent/sapservice/src/main/java/org/fouram/service/SapUserService.java

@@ -10,6 +10,7 @@ import org.fouram.constants.WebConstants;
 import org.fouram.core.base.model.PageData;
 import org.fouram.core.base.service.BaseService;
 import org.fouram.core.base.service.RequestService;
+import org.fouram.core.plugin.weixin.cp.util.WXCpMessageUtil;
 import org.fouram.core.plugin.weixin.cp.util.WXCpUserUtil;
 import org.fouram.core.util.Base64Util;
 import org.fouram.core.util.ConfConfig;
@@ -99,7 +100,7 @@ public class SapUserService extends BaseService {
 		// 获取用户对应职务
 		sapEmpJobService.setPosition(sapUsers);
 		LoggerUtil.info("saveWxDeparts->setPosition:" + DateUtil.getTime());
-		// EmpEmployment->startDate 
+		// EmpEmployment->startDate
 		sapEmpEmploymentService.setStartDate(sapUsers);
 		LoggerUtil.info("saveWxDeparts->setStartDate:" + DateUtil.getTime());
 		// EmpEmploymentTermination->endDate
@@ -116,7 +117,7 @@ public class SapUserService extends BaseService {
 				this.saveSapUser(sapUser);
 			} else {
 				// 如果是忽略INGORE,保留INGORE状态
-				if(SapUserResultEnum.INGORE.getCode().equals(sapUserDb.getResult())) {
+				if (SapUserResultEnum.INGORE.getCode().equals(sapUserDb.getResult())) {
 					sapUser.setResult(SapUserResultEnum.INGORE.getCode());
 				} else {
 					sapUser.setResult(SapUserResultEnum.NORMAL.getCode());
@@ -204,7 +205,7 @@ public class SapUserService extends BaseService {
 				sb.append(user.getFullOrgName()).append(";");
 			}
 		}
-		if(sb.length() > 0) {
+		if (sb.length() > 0) {
 			return sb.substring(0, sb.length() - 1);
 		}
 		return "";
@@ -224,7 +225,7 @@ public class SapUserService extends BaseService {
 				sb.append(user.getFormatPosition()).append("、");
 			}
 		}
-		if(sb.length() > 0) {
+		if (sb.length() > 0) {
 			return sb.substring(0, sb.length() - 1);
 		}
 		return "";
@@ -245,7 +246,7 @@ public class SapUserService extends BaseService {
 	@Transactional
 	public void updateSync(List<String> userIds) throws Exception {
 		SapUser sapUser = null;
-		for(String userId : userIds) {
+		for (String userId : userIds) {
 			sapUser = this.selectByUserId(userId);
 			if (SapUserResultEnum.LEAVE.getCode().equals(sapUser.getResult())) {
 				this.deleteQuitUserByUserId(userId, null);
@@ -254,7 +255,7 @@ public class SapUserService extends BaseService {
 			}
 		}
 	}
-	
+
 	public void updateSyncWxResult(String personId) throws Exception {
 		String result = createOrUpdateWXUser(personId);
 		updateResultByUserId(result, personId);
@@ -408,7 +409,7 @@ public class SapUserService extends BaseService {
 
 	public void updateResultByUserId(String result, String userId) throws Exception {
 		SapUser sapUser = SapUser.builder().userId(userId).result(result).build();
-		if(SapUserResultEnum.INGORE.getCode().equals(result)) {
+		if (SapUserResultEnum.INGORE.getCode().equals(result)) {
 			sapUser.setIngoreDate(new Date());
 		}
 		update("SapUserMapper.updateResultByUserId", sapUser);
@@ -441,15 +442,15 @@ public class SapUserService extends BaseService {
 
 	@Transactional
 	public void updateIngore(List<String> personIds) throws Exception {
-		for(String personId : personIds) {
+		for (String personId : personIds) {
 			updateResultByUserId(SapUserResultEnum.INGORE.getCode(), personId);
 		}
 	}
-	
+
 	public void updateCancelIngore(String personId) throws Exception {
 		SapUser sapUser = selectByUserId(personId);
 		String result = getCheckResultByWx(sapUser);
-		if(StringUtils.isBlank(result)) {
+		if (StringUtils.isBlank(result)) {
 			result = SapUserResultEnum.NORMAL.getCode();
 		}
 		updateResultByUserId(result, personId);
@@ -480,4 +481,20 @@ public class SapUserService extends BaseService {
 		Long total = (Long) findObject("SapUserMapper.selectIngorePrimaryTotal", pd);
 		return GetIngoreListOutput.builder().data(toInfoDetails(data)).total(total).build();
 	}
+
+	@SuppressWarnings("unchecked")
+	public List<SapUser> selectNotSendEntryMessageList() throws Exception {
+		return (List<SapUser>) findList("SapUserMapper.selectNotSendEntryMessageList", null);
+	}
+
+	@Transactional
+	public void sendEntryMessage(String messageContent, SapUser sapUser) throws Exception {
+		WXCpMessageUtil.send(messageContent, "1000001");
+		updateSendEntryMessageFlag(sapUser.getUserId(), true);
+	}
+
+	private void updateSendEntryMessageFlag(String userId, boolean sendEntryMessageFlag) throws Exception {
+		SapUser sapUser = SapUser.builder().userId(userId).sendEntryMessageFlag(sendEntryMessageFlag).build();
+		update("SapUserMapper.updateSendEntryMessageFlag", sapUser);
+	}
 }