liupeng 5 éve
szülő
commit
bf8286b5c6

+ 31 - 0
code/sapparent/sapservice/src/main/java/org/fouram/core/plugin/weixin/cp/core/WXCpOaBase.java

@@ -0,0 +1,31 @@
+package org.fouram.core.plugin.weixin.cp.core;
+
+import org.fouram.core.util.ConfConfig;
+
+import me.chanjar.weixin.cp.api.WxCpOaService;
+import me.chanjar.weixin.cp.api.WxCpService;
+import me.chanjar.weixin.cp.api.impl.WxCpOaServiceImpl;
+import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
+import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
+
+/**
+ * 企业微信工具类
+ *
+ * @author Liup
+ */
+public class WXCpOaBase {
+
+
+	public static final WxCpService service = new WxCpServiceImpl();
+	public static final WxCpOaService oaService;
+	static {
+		WxCpDefaultConfigImpl configStorage = new WxCpDefaultConfigImpl();
+		configStorage.setCorpId(ConfConfig.getConfigString("wxCp.corpId"));
+		configStorage.setCorpSecret(ConfConfig.getConfigString("wxCp.oa.secret"));
+		configStorage.setAgentId(ConfConfig.getConfigInteger("wxCp.oa.agentId"));
+		// 初始化基础service
+		service.setWxCpConfigStorage(configStorage);
+		// 初始化用户service
+		oaService = new WxCpOaServiceImpl(service);
+	}
+}

+ 32 - 0
code/sapparent/sapservice/src/main/java/org/fouram/core/plugin/weixin/cp/util/WXCpOaUtil.java

@@ -0,0 +1,32 @@
+package org.fouram.core.plugin.weixin.cp.util;
+
+import static org.fouram.core.plugin.weixin.cp.core.WXCpOaBase.oaService;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+
+import com.google.common.collect.Lists;
+
+import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.cp.bean.WxCpCheckinData;
+
+/**
+ * 企业微信用户工具类
+ * 
+ * @author Liup
+ */
+public class WXCpOaUtil {
+
+	public static List<WxCpCheckinData> getCheckinData(Date startTime, Date endTime, List<String> userIdList)
+			throws WxErrorException {
+		// 打卡类型。1:上下班打卡;2:外出打卡;3:全部打卡
+		return oaService.getCheckinData(3, startTime, endTime, userIdList);
+	}
+
+	public static void main(String[] args) throws WxErrorException, ParseException {
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+		System.out.println(getCheckinData(sdf.parse("2020-04-01"), sdf.parse("2020-04-30"), Lists.newArrayList("1017")));
+	}
+}

+ 96 - 0
code/sapparent/sapservice/src/main/java/org/fouram/core/util/BeanUtils.java

@@ -0,0 +1,96 @@
+package org.fouram.core.util;
+
+import org.springframework.beans.BeansException;
+import org.springframework.beans.FatalBeanException;
+import org.springframework.util.Assert;
+
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.*;
+
+/**
+ * 扩展spring的BeanUtils,增加拷贝属性排除null值的功能(注:String为null不考虑)
+ *
+ * @author 孙宇
+ */
+public class BeanUtils extends org.springframework.beans.BeanUtils {
+
+    public static void copyNotNullProperties(Object source, Object target, String[] ignoreProperties) throws BeansException {
+        copyNotNullProperties(source, target, null, ignoreProperties);
+    }
+
+    public static void copyNotNullProperties(Object source, Object target, Class<?> editable) throws BeansException {
+        copyNotNullProperties(source, target, editable, null);
+    }
+
+    public static void copyNotNullProperties(Object source, Object target) throws BeansException {
+        copyNotNullProperties(source, target, null, null);
+    }
+
+    @SuppressWarnings("rawtypes")
+    private static void copyNotNullProperties(Object source, Object target, Class<?> editable, String[] ignoreProperties) throws BeansException {
+
+        Assert.notNull(source, "Source must not be null");
+        Assert.notNull(target, "Target must not be null");
+
+        Class<?> actualEditable = target.getClass();
+        if (editable != null) {
+            if (!editable.isInstance(target)) {
+                throw new IllegalArgumentException("Target class [" + target.getClass().getName() + "] not assignable to Editable class [" + editable.getName() + "]");
+            }
+            actualEditable = editable;
+        }
+        PropertyDescriptor[] targetPds = getPropertyDescriptors(actualEditable);
+        List<String> ignoreList = (ignoreProperties != null) ? Arrays.asList(ignoreProperties) : null;
+
+        for (PropertyDescriptor targetPd : targetPds) {
+            if (targetPd.getWriteMethod() != null && (ignoreProperties == null || (!ignoreList.contains(targetPd.getName())))) {
+                PropertyDescriptor sourcePd = getPropertyDescriptor(source.getClass(), targetPd.getName());
+                if (sourcePd != null && sourcePd.getReadMethod() != null) {
+                    try {
+                        Method readMethod = sourcePd.getReadMethod();
+                        if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) {
+                            readMethod.setAccessible(true);
+                        }
+                        Object value = readMethod.invoke(source);
+                        if (value != null || "java.lang.String".equals(readMethod.getReturnType().getName())) {// 这里判断以下value是否为空,当然这里也能进行一些特殊要求的处理 例如绑定时格式转换等等,如果是String类型,则不需要验证是否为空
+                            boolean isEmpty = false;
+                            if (value instanceof Set) {
+                                Set s = (Set) value;
+                                if (s == null || s.isEmpty()) {
+                                    isEmpty = true;
+                                }
+                            } else if (value instanceof Map) {
+                                Map m = (Map) value;
+                                if (m == null || m.isEmpty()) {
+                                    isEmpty = true;
+                                }
+                            } else if (value instanceof List) {
+                                List l = (List) value;
+                                if (l == null || l.size() < 1) {
+                                    isEmpty = true;
+                                }
+                            } else if (value instanceof Collection) {
+                                Collection c = (Collection) value;
+                                if (c == null || c.size() < 1) {
+                                    isEmpty = true;
+                                }
+                            }
+                            if (!isEmpty) {
+                                Method writeMethod = targetPd.getWriteMethod();
+                                if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) {
+                                    writeMethod.setAccessible(true);
+                                }
+                                writeMethod.invoke(target, value);
+                            }
+                        }
+                    } catch (Throwable ex) {
+                        throw new FatalBeanException("Could not copy properties from source to target", ex);
+                    }
+                }
+            }
+        }
+    }
+
+}

+ 31 - 0
code/sapparent/sapservice/src/main/java/org/fouram/entity/SapCheck.java

@@ -0,0 +1,31 @@
+package org.fouram.entity;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import org.apache.ibatis.type.Alias;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+@Alias(value = "SapCheck")
+public class SapCheck implements Serializable {
+	private static final long serialVersionUID = 1L;
+
+	private String userId;
+	private String groupName;
+	private String checkinType;
+	private Date checkinDate;
+	private String exceptionType;
+	private Long checkinTime;
+	private String locationTitle;
+	private String locationDetail;
+	private String wifiName;
+	private String wifiMac;
+}

+ 24 - 0
code/sapparent/sapservice/src/main/java/org/fouram/mapper/SapCheckMapper.xml

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="SapCheckMapper">
+	<insert id="saveCheckin">
+		insert into sap_checkin(userId,groupName,checkinType,checkinDate,exceptionType,
+			checkinTime,locationTitle,locationDetail,wifiName,wifiMac) 
+		values (#{userId},#{groupName},#{checkinType},#{checkinDate},#{exceptionType},
+			#{checkinTime},#{locationTitle},#{locationDetail},#{wifiName},#{wifiMac})
+	</insert>
+	
+	<insert id="saveCheckoff">
+		insert into sap_checkoff(userId,groupName,checkinType,checkinDate,exceptionType,
+			checkinTime,locationTitle,locationDetail,wifiName,wifiMac) 
+		values (#{userId},#{groupName},#{checkinType},#{checkinDate},#{exceptionType},
+			#{checkinTime},#{locationTitle},#{locationDetail},#{wifiName},#{wifiMac})
+	</insert>
+	
+	<insert id="saveCheckout">
+		insert into sap_checkout(userId,groupName,checkinType,checkinDate,exceptionType,
+			checkinTime,locationTitle,locationDetail,wifiName,wifiMac) 
+		values (#{userId},#{groupName},#{checkinType},#{checkinDate},#{exceptionType},
+			#{checkinTime},#{locationTitle},#{locationDetail},#{wifiName},#{wifiMac})
+	</insert>
+</mapper>

+ 61 - 0
code/sapparent/sapservice/src/main/java/org/fouram/service/SapCheckService.java

@@ -0,0 +1,61 @@
+package org.fouram.service;
+
+import java.util.List;
+
+import org.fouram.core.base.service.BaseService;
+import org.fouram.core.plugin.weixin.cp.util.WXCpOaUtil;
+import org.fouram.core.util.BeanUtils;
+import org.fouram.core.util.DateUtil;
+import org.fouram.entity.SapCheck;
+import org.fouram.entity.SapUser;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.google.common.collect.Lists;
+
+import me.chanjar.weixin.cp.bean.WxCpCheckinData;
+
+@Service
+public class SapCheckService extends BaseService {
+
+	@Autowired
+	private SapUserService userService;
+
+	public void saveAllUserCheckData() throws Exception {
+		List<SapUser> users = userService.selectSuccessList();
+		for (SapUser user : users) {
+			List<WxCpCheckinData> checkinDatas = WXCpOaUtil.getCheckinData(
+					DateUtil.sdfTime.parse("2020-04-01 00:00:00"), DateUtil.sdfTime.parse("2020-05-01 00:00:00"),
+					Lists.newArrayList(user.getUserId()));
+			for (WxCpCheckinData data : checkinDatas) {
+				if (data.getCheckinType().equals("上班打卡")) {
+					saveCheckin(data);
+				} else if (data.getCheckinType().equals("下班打卡")) {
+					saveCheckoff(data);
+				} else if (data.getCheckinType().equals("外出打卡")) {
+					saveCheckout(data);
+				} else {
+					System.out.println(data);
+				}
+			}
+		}
+	}
+
+	public void saveCheckin(WxCpCheckinData data) throws Exception {
+		SapCheck check = new SapCheck();
+		BeanUtils.copyProperties(data, check);
+		save("SapCheckMapper.saveCheckin", check);
+	}
+
+	public void saveCheckoff(WxCpCheckinData data) throws Exception {
+		SapCheck check = new SapCheck();
+		BeanUtils.copyProperties(data, check);
+		save("SapCheckMapper.saveCheckoff", check);
+	}
+
+	public void saveCheckout(WxCpCheckinData data) throws Exception {
+		SapCheck check = new SapCheck();
+		BeanUtils.copyProperties(data, check);
+		save("SapCheckMapper.saveCheckout", check);
+	}
+}

+ 4 - 0
code/sapparent/sapservice/src/main/resources/env/develop/config.properties

@@ -7,6 +7,8 @@ wxCp.massage.agentId = 1000003
 wxCp.massage.secret = Sf9mHYuIeAFyqvyoDnTXAH2hlly7kWq6LoIYGCuTZUM
 wxCp.massage.toUser = 1000001
 wxCp.massage.quitUserUrl = https://www.baidu.com
+wxCp.oa.agentId = 3010011
+wxCp.oa.secret = wSzjASahMpA7FoLEpQr_aRvoOY3DwES4Mnh57xGD0OY
 #prod
 #wxCp.corpId = ww911e29458d3a46fd
 #wxCp.corpSecret = amUNgH2lo-szEYkLmClZN2jMYcDu0NnXIAtWfW729P4
@@ -14,6 +16,8 @@ wxCp.massage.quitUserUrl = https://www.baidu.com
 #wxCp.massage.secret = a0HDbErBYZxL43yLIzTZ_9Q5q4eFf2EHSi67TWP1RbE
 #wxCp.massage.toUser = dd4d61108fecaa34918a555fd1d8cce1
 #wxCp.massage.quitUserUrl = https://www.baidu.com
+#wxCp.oa.agentId = 3010011
+#wxCp.oa.secret = iD6-Kv41i4S50bEZcwa9v-S7SYpD1Q7LbR3dQx5oM7s
 
 wxCp.mailList.corpSecret = aI66cnVoFAd381rgd3NpyZaEP2qnuZJ2ogpZKWmz9qg
 wxCp.redirectUri = http://cmcadressbook.suggest.vip/sapcms