|
@@ -40,7 +40,7 @@ public class WeiXinCorpController {
|
|
|
//获取成员详情
|
|
|
public static final String GET_USER_INFO_URL = "https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&userid=USERID";
|
|
|
//获取部门列表
|
|
|
-// public static final String GET_DEPARTMENT_URL = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=ACCESS_TOKEN";
|
|
|
+ public static final String GET_ALL_DEPARTMENT_URL = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=ACCESS_TOKEN";
|
|
|
public static final String GET_DEPARTMENT_URL = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=ACCESS_TOKEN&id=1";//获取某个部门下的子部门
|
|
|
//获取部门成员详情
|
|
|
public static final String GET_DEPARTMENT_USER_DETAIL_URL = "https://qyapi.weixin.qq.com/cgi-bin/user/list?access_token=ACCESS_TOKEN&department_id=DEPARTMENT_ID&fetch_child=0";
|
|
@@ -105,9 +105,6 @@ public class WeiXinCorpController {
|
|
|
@Resource
|
|
|
UserService userService;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
//"获取企业微信jssdk初始化配置参数"
|
|
|
@RequestMapping("/getCorpWXConfig")
|
|
|
public HttpRespMsg getCorpWXConfig(String url, String token) {
|
|
@@ -349,6 +346,8 @@ public class WeiXinCorpController {
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
private void handleCorpAuth(String authCode) {
|
|
|
String suitAccessToken = getSuiteAccessToken();
|
|
|
String url = GET_CORP_PERMANENT_CODE_URL.replace("SUITE_ACCESS_TOKEN", suitAccessToken);
|
|
@@ -444,8 +443,7 @@ public class WeiXinCorpController {
|
|
|
User user = new User()
|
|
|
.setId(id.toString())
|
|
|
.setRole(1)
|
|
|
- .setName(data.getAuthUsername())
|
|
|
- .setName(userId)//使用wx userid作为姓名
|
|
|
+ .setName(data.getAuthUsername()==null?userId:data.getAuthUsername())
|
|
|
.setPassword(MD5Util.getPassword("000000"))
|
|
|
.setCorpwxUserid(userId)
|
|
|
.setColor(ColorUtil.randomColor())
|
|
@@ -587,7 +585,7 @@ public class WeiXinCorpController {
|
|
|
User user = new User()
|
|
|
.setId(id.toString())
|
|
|
.setRole(1)
|
|
|
- .setName(data.getAuthUsername())
|
|
|
+ .setName(data.getAuthUsername()==null?userId:data.getAuthUsername())
|
|
|
.setCorpwxUserid(userId)
|
|
|
.setColor(ColorUtil.randomColor())
|
|
|
.setCompanyId(companyId);
|
|
@@ -601,7 +599,7 @@ public class WeiXinCorpController {
|
|
|
private JSONArray getDeptUserSimple(String accessToken, int deptId) {
|
|
|
String url = GET_DEPARTMENT_USER_SIMPLE_URL.replace("ACCESS_TOKEN", accessToken).replace("DEPARTMENT_ID", ""+deptId);
|
|
|
String result = restTemplate.getForObject(url, String.class);
|
|
|
- log.info("部门人员详情:"+result);
|
|
|
+ System.out.println("部门人员详情:"+result);
|
|
|
JSONObject obj = JSONObject.parseObject(result);
|
|
|
JSONArray userlist = obj.getJSONArray("userlist");
|
|
|
|
|
@@ -616,6 +614,16 @@ public class WeiXinCorpController {
|
|
|
|
|
|
return obj;
|
|
|
}
|
|
|
+
|
|
|
+ private JSONObject getAllDepartments(String accessToken) {
|
|
|
+ String url = GET_ALL_DEPARTMENT_URL.replace("ACCESS_TOKEN", accessToken);
|
|
|
+ String result = restTemplate.getForObject(url, String.class);
|
|
|
+ System.out.println("部门列表:"+result);
|
|
|
+ JSONObject obj = JSONObject.parseObject(result);
|
|
|
+
|
|
|
+ return obj;
|
|
|
+ }
|
|
|
+
|
|
|
private JSONObject getUserInfo(String accessToken, String userId) {
|
|
|
String url = GET_USER_INFO_URL.replace("ACCESS_TOKEN", accessToken).replace("USERID", userId);
|
|
|
String result = restTemplate.getForObject(url, String.class);
|
|
@@ -755,9 +763,10 @@ public class WeiXinCorpController {
|
|
|
|
|
|
//获取企业微信考勤打卡统计数据
|
|
|
@RequestMapping("/getUserCheckInDayData")
|
|
|
- public HttpRespMsg getUserCheckInDayData(int companyId, String date) {
|
|
|
- LocalDateTime localDate = LocalDateTime.parse(date+" 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
- return wxCorpInfoService.getUserCheckInDayData(companyId, localDate);
|
|
|
+ public HttpRespMsg getUserCheckInDayData(int companyId, String startDate, String endDate) {
|
|
|
+ LocalDateTime start = LocalDateTime.parse(startDate+" 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
+ LocalDateTime end = LocalDateTime.parse(endDate+" 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
+ return wxCorpInfoService.getUserCheckInDayData(companyId, start, end);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -862,4 +871,73 @@ public class WeiXinCorpController {
|
|
|
|
|
|
return msg;
|
|
|
}
|
|
|
+
|
|
|
+ @RequestMapping("/getCorpMembs")
|
|
|
+ public HttpRespMsg getCorpMembs(String corpId) {
|
|
|
+
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectById(corpId);
|
|
|
+
|
|
|
+ Company company = companyMapper.selectById(wxCorpInfo.getCompanyId());
|
|
|
+ String curCorpAccessToken = null;
|
|
|
+ try {
|
|
|
+ curCorpAccessToken = getCorpAccessToken(wxCorpInfo);
|
|
|
+ } catch (Exception exception) {
|
|
|
+ exception.printStackTrace();
|
|
|
+ }
|
|
|
+ int companyId = company.getId();
|
|
|
+ //获取公司根部门人员,也就是没有分配部门的人员
|
|
|
+ int companyRootDeptId = 1;
|
|
|
+ JSONArray unAssignedUserList = getDeptUserSimple(curCorpAccessToken, companyRootDeptId);
|
|
|
+ for (int m=0;m<unAssignedUserList.size(); m++) {
|
|
|
+ JSONObject userJson = unAssignedUserList.getJSONObject(m);
|
|
|
+ String curUserid = userJson.getString("userid");
|
|
|
+ System.out.println("userid="+curUserid+", name=" + userJson.getString("name")+", mobile="+userJson.getString("mobile"));
|
|
|
+ //不存在的人员, 进行插入
|
|
|
+ User user = new User();
|
|
|
+
|
|
|
+ user.setId(SnowFlake.nextId()+"")
|
|
|
+ .setRole(0)//默认普通员工
|
|
|
+ .setCompanyId(companyId)
|
|
|
+ .setName(userJson.getString("name"))
|
|
|
+ .setCorpwxUserid(curUserid)
|
|
|
+ .setColor(ColorUtil.randomColor());
|
|
|
+
|
|
|
+ //检查用户是否已经存在
|
|
|
+ if (userMapper.selectCount(new QueryWrapper<User>().eq("corpwx_userid", curUserid)) == 0) {
|
|
|
+ userMapper.insert(user);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+//获取部门
|
|
|
+ JSONObject deptObj = getAllDepartments(curCorpAccessToken);
|
|
|
+ JSONArray deptObjJSONArray = deptObj.getJSONArray("department");
|
|
|
+
|
|
|
+ for (int i=0;i<deptObjJSONArray.size(); i++) {
|
|
|
+ int deptId = deptObjJSONArray.getJSONObject(i).getIntValue("id");
|
|
|
+
|
|
|
+ JSONArray userList = getDeptUserSimple(curCorpAccessToken, deptId);
|
|
|
+ for (int m=0;m<userList.size(); m++) {
|
|
|
+ JSONObject userJson = userList.getJSONObject(m);
|
|
|
+ String curUserid = userJson.getString("userid");
|
|
|
+ System.out.println("userid="+curUserid+", name=" + userJson.getString("name")+", mobile="+userJson.getString("mobile"));
|
|
|
+ //不存在的人员, 进行插入
|
|
|
+ User user = new User();
|
|
|
+
|
|
|
+ user.setId(SnowFlake.nextId()+"")
|
|
|
+ .setRole(0)//默认普通员工
|
|
|
+ .setCompanyId(companyId)
|
|
|
+ .setDepartmentId(0)
|
|
|
+ .setName(userJson.getString("name"))
|
|
|
+ .setCorpwxUserid(curUserid)
|
|
|
+ .setColor(ColorUtil.randomColor());
|
|
|
+
|
|
|
+ //检查用户是否已经存在
|
|
|
+ if (userMapper.selectCount(new QueryWrapper<User>().eq("corpwx_userid", curUserid)) == 0) {
|
|
|
+ userMapper.insert(user);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return new HttpRespMsg();
|
|
|
+ }
|
|
|
}
|