1811872455@163.com 2 долоо хоног өмнө
parent
commit
cc2465092d

+ 1 - 1
storlead-centre-api/src/main/java/com/storlead/centre/dispatch/AttendanceSignDispatchTask.java

@@ -31,6 +31,6 @@ public class AttendanceSignDispatchTask {
     public void syncSignData() throws ParseException {
         log.error("开始时间--"+new Date());
         log.info("oa company dept job user sync task starting ----");
-        attendanceSignRecordService.getSaveSignRecord();
+        // attendanceSignRecordService.getSaveSignRecord();
     }
 }

+ 1 - 1
storlead-centre-api/src/main/java/com/storlead/centre/dispatch/SyncAttendanceSignToOaTask.java

@@ -38,7 +38,7 @@ public class SyncAttendanceSignToOaTask {
     @Resource
     private HrmschedulesignService hrmschedulesignService;
 
-    @Scheduled(cron ="0 */5 6-23 * * ? ")
+//    @Scheduled(cron ="0 */5 6-23 * * ? ")
     public void syncSignData() throws ParseException {
         // 获取未同步的数据到
         LambdaQueryWrapper<AttendanceSignRecordEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();

+ 33 - 0
storlead-centre-api/src/main/java/com/storlead/centre/dispatch/SyncOaBaseDataTask.java

@@ -0,0 +1,33 @@
+package com.storlead.centre.dispatch;
+
+import com.storlead.user.service.IUserService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.text.ParseException;
+
+/**
+ * @program: storlead-centre-platform
+ * @description:
+ * @author: chenkq
+ * @create: 2026-01-14 11:04
+ */
+
+@Slf4j
+@Component
+public class SyncOaBaseDataTask {
+
+    @Resource
+    private IUserService userService;
+
+    @Scheduled(cron ="0 0 7 * * ? ")
+    public void syncOaData() throws ParseException {
+        /**
+         * 同步OA数据
+         */
+        userService.syncOa();
+
+    }
+}

+ 3 - 0
storlead-user/src/main/java/com/storlead/user/pojo/entity/UserEntity.java

@@ -128,6 +128,9 @@ public class UserEntity extends SysBaseField {
     @ApiModelProperty(value = "最近的活动时间")
     private Date lastActivityTime;
 
+    @ApiModelProperty(value = "备注")
+    private String remark;
+
     public UserEntity(Long id, String userName, String password) {
         this.id = id;
         this.userName = userName;

+ 49 - 37
storlead-user/src/main/java/com/storlead/user/service/impl/UserServiceImpl.java

@@ -1,6 +1,8 @@
 package com.storlead.user.service.impl;
 
 import cn.hutool.core.date.DateTime;
+import cn.hutool.core.lang.Validator;
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -140,6 +142,8 @@ public class UserServiceImpl extends MyBaseServiceImpl<UserMapper, UserEntity> i
 					boolean sj = syncJob();
 					if (c && sc && sj) {
 						syncUser();
+						// 同步企业微信id,根据手机号
+						syncWxId();
 					}
 					log.error("syncCompany--------------end = "+(System.currentTimeMillis() - d));
 				}
@@ -155,29 +159,37 @@ public class UserServiceImpl extends MyBaseServiceImpl<UserMapper, UserEntity> i
 	@Override
 	public Boolean syncWxId() {
 		LambdaQueryWrapper<UserEntity> wp = new LambdaQueryWrapper<>();
-		wp.isNull(UserEntity::getXworkUserId);
 		wp.eq(UserEntity::getIsDelete, CommonConstant.DEL_FLAG_0);
 		wp.isNotNull(UserEntity::getMobile).ne(UserEntity::getMobile,"");
 		wp.ne(UserEntity::getStatus,Integer.valueOf(5));
-		wp.isNotNull(UserEntity::getPermanentDate);
+		wp.isNull(UserEntity::getXworkUserId);
+
 		List<UserEntity> list = list(wp);
+		if (CollectionUtils.isEmpty(list)) {
+			return true;
+		}
+		String token = corpWeChatService.getAddressAccessTokenFromTencent().getToken();
 
-		List<com.storlead.framework.common.vo.UserVo> us = new ArrayList<>();
-		List<com.storlead.framework.common.vo.UserVo> finalUs = us;
-		list.forEach(a -> {
-			com.storlead.framework.common.vo.UserVo v = new com.storlead.framework.common.vo.UserVo();
-			BeanUtils.copyProperties(a,v);
-			finalUs.add(v);
-		});
-		corpWeChatService.syncWxUserIdByMobile(finalUs);
-		for (com.storlead.framework.common.vo.UserVo user : us) {
-			if (Objects.nonNull(user.getXworkUserId())) {
+		for (UserEntity user : list) {
+			String mobile = user.getMobile();
+			boolean isValid = Validator.isMobile(mobile);
+			if (!isValid) {
 				LambdaUpdateWrapper<UserEntity> updateWrapper = new LambdaUpdateWrapper<>();
-				updateWrapper.eq(UserEntity::getMobile,user.getMobile());
-				updateWrapper.set(UserEntity::getXworkUserId,user.getXworkUserId());
+				updateWrapper.eq(UserEntity::getId,user.getId());
+				updateWrapper.set(UserEntity::getXworkUserId,"");
 				update(updateWrapper);
+				continue;
 			}
+			String xworkUserId =  corpWeChatService.syncWxUserIdByMobile(token,mobile);
+			LambdaUpdateWrapper<UserEntity> updateWrapper = new LambdaUpdateWrapper<>();
+			if (StrUtil.isBlank(xworkUserId)) {
+				updateWrapper.eq(UserEntity::getRemark,"账号异常,未获取到微信Id");
+			}
+			updateWrapper.eq(UserEntity::getId,user.getId());
+			updateWrapper.set(UserEntity::getXworkUserId,xworkUserId);
+			update(updateWrapper);
 		}
+
 		return Boolean.TRUE;
 	}
 	/**
@@ -383,20 +395,17 @@ public class UserServiceImpl extends MyBaseServiceImpl<UserMapper, UserEntity> i
 			currentUser = new LoginUser().setId(0L);
 		}
 		List<UserEntity> userList = hrmresourceService.getUserList();
-		log.error("syncUser--------------end3 = "+(System.currentTimeMillis()-d));
 		List<UserEntity> dbUserList = list();
 		List<UserEntity> addList = new ArrayList<>();
 		List<UserEntity> updateList = new ArrayList<>();
 
 		List<DeptEntity> depts = departService.list();
-		log.error("syncUser--------------end4 = "+(System.currentTimeMillis()-d));
 		Map deptMap = new HashMap();
 		depts.forEach(c -> {
 			deptMap.put(c.getId(),c.getRouteCode());
 		});
 		// 默认密码
 		String defaultPassWord = "storlead123456";
-		log.error("syncUser--------------end5 = "+(System.currentTimeMillis()-d));
 		for (UserEntity user : userList) {
 			UserEntity userDb = dbUserList.stream().filter(u -> u.getId().equals(user.getId())).findFirst().orElse(null);
 			String routeCode =  Objects.isNull(deptMap.get(user.getDeptId())) ? "" : deptMap.get(user.getDeptId()).toString();
@@ -406,8 +415,10 @@ public class UserServiceImpl extends MyBaseServiceImpl<UserMapper, UserEntity> i
 						.setUserName(user.getMobile()).setOrgRouteCode(routeCode)
 						.setPassword(passwordEncoder.encode(defaultPassWord))
 						.setDataSource(0)
-						.setCreateBy(currentUser.getId())
-						.setEnabled(false);
+						.setCreateBy(currentUser.getId());
+				if (user.getStatus()!=null && Integer.parseInt(user.getStatus()) == 5) {
+					user.setEnabled(false);
+				}
 				addList.add(user);
 			} else {
 				//禁用离职状态的用户
@@ -417,31 +428,29 @@ public class UserServiceImpl extends MyBaseServiceImpl<UserMapper, UserEntity> i
 
 				user
 						.setOrgRouteCode(routeCode)
+						.setXworkUserId(user.getXworkUserId())
 						.setUserName(user.getMobile());
+
 				updateList.add(user);
 			}
 		}
-		log.error("syncUser--------------end6 = "+(System.currentTimeMillis()-d));
 		if (!CollectionUtils.isEmpty(addList)) {
 			this.saveBatch(addList);
 		}
-		if (CollectionUtils.isEmpty(updateList)) {
-			syncUserOpenIdFormTencent();
-		}
-		log.error("syncUser--------------end7 = "+(System.currentTimeMillis()-d));
-		if (!CollectionUtils.isEmpty(updateList)) {
-			ThreadPoolUtil.execute(new Runnable() {
-				@Override
-				public void run() {
-					saveOrUpdateBatch(updateList);
-					syncUserOpenIdFormTencent();
-
-				}
-			});
-		}
-		log.error("syncUser--------------end8 = "+(System.currentTimeMillis()-d));
-
-
+//		if (CollectionUtils.isEmpty(updateList)) {
+//			syncUserOpenIdFormTencent();
+//		}
+//		log.error("syncUser--------------end7 = "+(System.currentTimeMillis()-d));
+//		if (!CollectionUtils.isEmpty(updateList)) {
+//			ThreadPoolUtil.execute(new Runnable() {
+//				@Override
+//				public void run() {
+//					saveOrUpdateBatch(updateList);
+//					syncUserOpenIdFormTencent();
+//
+//				}
+//			});
+//		}
 		return true;
 	}
 
@@ -452,6 +461,9 @@ public class UserServiceImpl extends MyBaseServiceImpl<UserMapper, UserEntity> i
 	 * @date 2021-6-15 上午 11:58
 	 */
 	public boolean syncUserOpenIdFormTencent() {
+
+//		LambdaQueryWrapper<UserEntity> us = new LambdaQueryWrapper();
+//		us.eq(UserEntity::getIsDelete,CommonConstant.DEL_FLAG_0);
 		List<UserEntity> list = this.list();
 
 		List<com.storlead.framework.common.vo.UserVo> us = new ArrayList<>();

+ 2 - 1
storlead-user/src/main/resources/mapper/UserMapper.xml

@@ -35,6 +35,7 @@
 		<result column="education" property="education" />
 		<result column="job_des" property="jobDes" />
 		<result column="is_freeze" property="isFreeze" />
+		<result column="remark" property="remark" />
 		<result column="last_activity_time" property="lastActivityTime" />
 		<result column="external_user_type" property="externalUserType" />
 	</resultMap>
@@ -43,7 +44,7 @@
 	<sql id="Base_Column_List">
 		id, user_name, `password`, data_source,xwork_user_id, avatar, sex, nick_name, real_name, mobile, email, job_id, dept_id, sub_company_id, company_id, id_num
 , address, birthday, entry_date,external_user_type, permanent_date, resign_date, bank_name, bank_card_num, status, probation_pay, formal_pay, is_shenzhen_census, census, ethnic, marriage
-, education,job_des,is_freeze,last_activity_time, <include refid="com.storlead.framework.mybatis.mapper.SysBaseFieldMapper.Base_Column_List"></include>
+, education,job_des,is_freeze,last_activity_time,remark, <include refid="com.storlead.framework.mybatis.mapper.SysBaseFieldMapper.Base_Column_List"></include>
 	</sql>
 
 	<update id="addUserAvatar">

+ 2 - 1
storlead-wx/src/main/java/com/storlead/wx/service/CorpWeChatService.java

@@ -39,6 +39,7 @@ public interface CorpWeChatService {
      */
     WechatToken getJSApiTicket();
 
+    WechatToken getAddressAccessTokenFromTencent();
     /**
      * 返回用于企业微信登陆所需要的参数
      *
@@ -98,7 +99,7 @@ public interface CorpWeChatService {
     // boolean sendTextCardMsg(@NotNull String title, @NotNull String description, @NotNull String redirectionUrl, Set<String> userSet, Set<Long> deptSet);
 
 
-    void syncWxUserIdByMobile(List<UserVo> userList);
+    String syncWxUserIdByMobile(String token,String mobile);
     /**
      * 发送卡片消息
      *

+ 9 - 10
storlead-wx/src/main/java/com/storlead/wx/service/impl/CorpWeChatServiceImpl.java

@@ -77,7 +77,8 @@ public class CorpWeChatServiceImpl implements CorpWeChatService {
      * @author blank
      * @date 2021-3-8 下午 2:59
      */
-    private WechatToken getAddressAccessTokenFromTencent() {
+    @Override
+    public WechatToken getAddressAccessTokenFromTencent() {
         return CorpWechatUtil.getAccessToken(CorpWeChatConstants.GET_ACCESS_TOKEN_URL, CorpWeChatProperties.getCorpId(), CorpWeChatProperties.getCorpAgentSecret());
     }
 
@@ -168,15 +169,13 @@ public class CorpWeChatServiceImpl implements CorpWeChatService {
 
 
     @Override
-    public void syncWxUserIdByMobile(List<UserVo> userList) {
-        String token = getAddressAccessTokenFromTencent().getToken();
-        for(UserVo user : userList) {
-            try{
-                String workUserId = CorpWechatUtil.getWxUserIdByMobile(CorpWeChatConstants.GET_USER_ID_BY_MOBILE_URL, token, user.getMobile());
-                user.setXworkUserId(workUserId);
-            }catch (Exception e) {
-                log.error("syncUserOpenIdFormTencent ------------error = ",e);
-            }
+    public String syncWxUserIdByMobile(String token,String mobile) {
+        try{
+            String workUserId = CorpWechatUtil.getWxUserIdByMobile(CorpWeChatConstants.GET_USER_ID_BY_MOBILE_URL, token, mobile);
+            return workUserId;
+        }catch (Exception e) {
+            log.error("syncUserOpenIdFormTencent ------------error = ",e);
+            return "";
         }
     }
 

+ 1 - 1
storlead-wx/src/main/java/com/storlead/wx/util/CorpWechatUtil.java

@@ -158,7 +158,7 @@ public class CorpWechatUtil {
                 return userid;
             }
         }
-        return null;
+        return "";
     }
 
     /**