|
@@ -125,9 +125,58 @@ public class DingDingServiceImpl implements DingDingService {
|
|
private boolean isPrivateDeploy;//企业内部应用,私有化部署的情况
|
|
private boolean isPrivateDeploy;//企业内部应用,私有化部署的情况
|
|
@Value("${dingding.appId}")
|
|
@Value("${dingding.appId}")
|
|
private long appId;//钉钉第三方应用的appId
|
|
private long appId;//钉钉第三方应用的appId
|
|
|
|
+
|
|
@Value("${configEnv.isDev}")
|
|
@Value("${configEnv.isDev}")
|
|
private boolean isDev;//是否是本地开发环境
|
|
private boolean isDev;//是否是本地开发环境
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public synchronized HttpRespMsg initSystem(String corpid) throws ApiException {
|
|
|
|
+ System.out.println("========接收到initSystem请求===corpid="+corpid);
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ if (!isPrivateDeploy) {
|
|
|
|
+ msg.setError("请配置isPrivateDeploy: true");
|
|
|
|
+ } else {
|
|
|
|
+ //查找公司对应的记录是否已经添加
|
|
|
|
+ CompanyDingding dingding = companyDingdingMapper.selectById(corpid);
|
|
|
|
+ if (dingding == null) {
|
|
|
|
+ msg.setError("请在company_dingding表中增加corpid:" + corpid);
|
|
|
|
+ } else if (dingding.getCompanyId() != null) {
|
|
|
|
+ msg.setError("companyId已存在,如需重新初始化请先重置company_dingding中该条数据的companyId为null");
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ Company company = new Company().setCompanyName(dingding.getCorpName())
|
|
|
|
+ .setExpirationDate(LocalDateTime.now().plusDays(15));
|
|
|
|
+ company.setPackageProject(1);
|
|
|
|
+ company.setPackageExpense(1);
|
|
|
|
+ company.setPackageCustomer(1);
|
|
|
|
+ company.setPackageOa(1);
|
|
|
|
+ companyMapper.insert(company);
|
|
|
|
+ dingding.setCompanyId(company.getId());
|
|
|
|
+ companyDingdingMapper.updateById(dingding);
|
|
|
|
+ //生成工作时长
|
|
|
|
+ TimeType timeType = new TimeType();
|
|
|
|
+ timeType.setCompanyId(company.getId());
|
|
|
|
+ timeTypeMapper.insert(timeType);
|
|
|
|
+
|
|
|
|
+ SysRole smanager = sysRoleService.generateDefaultRoles(company.getId());
|
|
|
|
+
|
|
|
|
+ //生成项目的成本基线默认条目
|
|
|
|
+ String[] array = Constant.DEFAULT_BASE_COST_ITEMS;
|
|
|
|
+ for (String baseItem : array) {
|
|
|
|
+ ProjectBasecostSetting setting = new ProjectBasecostSetting();
|
|
|
|
+ setting.setName(baseItem);
|
|
|
|
+ setting.setCompanyId(company.getId());
|
|
|
|
+ projectBasecostSettingMapper.insert(setting);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //获取企业内部应用accessToken
|
|
|
|
+ String innerCorpToken = getInnerCorpToken(dingding);
|
|
|
|
+ getAuthedDeptsAndUsers(dingding, innerCorpToken);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
@Async
|
|
@Async
|
|
public void corpAuth(String corpid, String corpName, String authUserId, Long agentId) throws ApiException {
|
|
public void corpAuth(String corpid, String corpName, String authUserId, Long agentId) throws ApiException {
|
|
@@ -237,40 +286,41 @@ public class DingDingServiceImpl implements DingDingService {
|
|
System.out.println("corpid不存在=="+corpid);
|
|
System.out.println("corpid不存在=="+corpid);
|
|
return "调用失败:corpid不存在==";
|
|
return "调用失败:corpid不存在==";
|
|
}
|
|
}
|
|
- if (dingding.getExpireTime().isBefore(LocalDateTime.now())) {
|
|
|
|
- SysConfig config = sysConfigMapper.selectOne(new QueryWrapper<SysConfig>().eq("param_key", "dingding_suite_ticket"));
|
|
|
|
- OapiServiceGetCorpTokenResponse result = getAuthCorpAccessToken(corpid, config.getParamValue());
|
|
|
|
- if (result != null) {
|
|
|
|
- if (result.getErrcode() == 0L) {
|
|
|
|
- //返回成功
|
|
|
|
- dingding.setAccessToken(result.getAccessToken());
|
|
|
|
- LocalDateTime time = LocalDateTime.now();
|
|
|
|
- time = time.plusSeconds(result.getExpiresIn());//设置token过期时间
|
|
|
|
- dingding.setExpireTime(time);
|
|
|
|
- companyDingdingMapper.updateById(dingding);
|
|
|
|
|
|
+ if (isPrivateDeploy) {
|
|
|
|
+ //私有化部署,取innerToken
|
|
|
|
+ accessToken = getInnerCorpToken(dingding);
|
|
|
|
+ } else {
|
|
|
|
+ if (dingding.getExpireTime().isBefore(LocalDateTime.now())) {
|
|
|
|
+ SysConfig config = sysConfigMapper.selectOne(new QueryWrapper<SysConfig>().eq("param_key", "dingding_suite_ticket"));
|
|
|
|
+ OapiServiceGetCorpTokenResponse result = getAuthCorpAccessToken(corpid, config.getParamValue());
|
|
|
|
+ if (result != null) {
|
|
|
|
+ if (result.getErrcode() == 0L) {
|
|
|
|
+ //返回成功
|
|
|
|
+ dingding.setAccessToken(result.getAccessToken());
|
|
|
|
+ LocalDateTime time = LocalDateTime.now();
|
|
|
|
+ time = time.plusSeconds(result.getExpiresIn());//设置token过期时间
|
|
|
|
+ dingding.setExpireTime(time);
|
|
|
|
+ companyDingdingMapper.updateById(dingding);
|
|
|
|
|
|
- accessToken = dingding.getAccessToken();
|
|
|
|
- } else {
|
|
|
|
- System.out.println(result.getBody());
|
|
|
|
|
|
+ accessToken = dingding.getAccessToken();
|
|
|
|
+ } else {
|
|
|
|
+ System.out.println(result.getBody());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ } else {
|
|
|
|
+ accessToken = dingding.getAccessToken();
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- accessToken = dingding.getAccessToken();
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
if (accessToken == null) {
|
|
if (accessToken == null) {
|
|
System.out.println("获取第三方企业accessToke失败");
|
|
System.out.println("获取第三方企业accessToke失败");
|
|
return "调用失败";
|
|
return "调用失败";
|
|
} else {
|
|
} else {
|
|
System.out.println("syncCorpMembs 开始获取部门, accessToken="+accessToken);
|
|
System.out.println("syncCorpMembs 开始获取部门, accessToken="+accessToken);
|
|
-
|
|
|
|
//获取授权的部门
|
|
//获取授权的部门
|
|
getAuthedDeptsAndUsers(dingding, accessToken);
|
|
getAuthedDeptsAndUsers(dingding, accessToken);
|
|
return "调用成功";
|
|
return "调用成功";
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
-// String rest = getDepartmentList(dingding.getCompanyId(), corpid, accessToken, 1L, null);
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
private void getAuthedDeptsAndUsers(CompanyDingding dingding, String accessToken) {
|
|
private void getAuthedDeptsAndUsers(CompanyDingding dingding, String accessToken) {
|
|
@@ -381,12 +431,14 @@ public class DingDingServiceImpl implements DingDingService {
|
|
*/
|
|
*/
|
|
private String getInnerCorpToken(CompanyDingding dingding) throws ApiException {
|
|
private String getInnerCorpToken(CompanyDingding dingding) throws ApiException {
|
|
if (dingding.getInnerToken() == null || LocalDateTime.now().isAfter(dingding.getInnerExpireTime())) {
|
|
if (dingding.getInnerToken() == null || LocalDateTime.now().isAfter(dingding.getInnerExpireTime())) {
|
|
- DefaultDingTalkClient client= new DefaultDingTalkClient("https://oapi.dingtalk.com/service/get_corp_token");
|
|
|
|
- OapiServiceGetCorpTokenRequest req= new OapiServiceGetCorpTokenRequest();
|
|
|
|
- req.setAuthCorpid(dingding.getCorpid());
|
|
|
|
- OapiServiceGetCorpTokenResponse response= client.execute(req,dingding.getCustomAppkey(),dingding.getCustomAppsecret(),"anything");
|
|
|
|
|
|
+ DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
|
|
|
|
+ OapiGettokenRequest request = new OapiGettokenRequest();
|
|
|
|
+ request.setAppkey(dingding.getInnerAppkey());
|
|
|
|
+ request.setAppsecret(dingding.getInnerAppsecret());
|
|
|
|
+ request.setHttpMethod("GET");
|
|
|
|
+ OapiGettokenResponse response = client.execute(request);
|
|
if (!response.isSuccess()) {
|
|
if (!response.isSuccess()) {
|
|
- System.err.println("获取企业内部token:"+response.getErrorCode()+":"+response.getErrmsg());
|
|
|
|
|
|
+ System.err.println("获取企业内部token失败:"+response.getErrorCode()+":"+response.getErrmsg());
|
|
}
|
|
}
|
|
dingding.setInnerToken(response.getAccessToken());
|
|
dingding.setInnerToken(response.getAccessToken());
|
|
dingding.setInnerExpireTime(LocalDateTime.now().plusSeconds(response.getExpiresIn()));
|
|
dingding.setInnerExpireTime(LocalDateTime.now().plusSeconds(response.getExpiresIn()));
|
|
@@ -430,10 +482,18 @@ public class DingDingServiceImpl implements DingDingService {
|
|
OapiV2UserGetuserinfoRequest req = new OapiV2UserGetuserinfoRequest();
|
|
OapiV2UserGetuserinfoRequest req = new OapiV2UserGetuserinfoRequest();
|
|
req.setCode(code);
|
|
req.setCode(code);
|
|
//获取有效的accessToken
|
|
//获取有效的accessToken
|
|
- String accessToken = getValidCorpAccessToken(corpid);
|
|
|
|
|
|
+
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
OapiV2UserGetuserinfoResponse rsp = null;
|
|
OapiV2UserGetuserinfoResponse rsp = null;
|
|
try {
|
|
try {
|
|
|
|
+ String accessToken = null;
|
|
|
|
+ if (isPrivateDeploy) {
|
|
|
|
+ CompanyDingding companyDingding = companyDingdingMapper.selectById(corpid);
|
|
|
|
+ accessToken = getInnerCorpToken(companyDingding);
|
|
|
|
+ } else {
|
|
|
|
+ accessToken = getValidCorpAccessToken(corpid);
|
|
|
|
+ }
|
|
|
|
+
|
|
rsp = client.execute(req, accessToken);
|
|
rsp = client.execute(req, accessToken);
|
|
System.out.println(rsp.getBody());
|
|
System.out.println(rsp.getBody());
|
|
JSONObject json = JSONObject.parseObject(rsp.getBody());
|
|
JSONObject json = JSONObject.parseObject(rsp.getBody());
|
|
@@ -752,6 +812,54 @@ public class DingDingServiceImpl implements DingDingService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void getAddUserDetail(CompanyDingding dingding, String dingdingUserid, String access_token) throws ApiException {
|
|
|
|
+ DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/get");
|
|
|
|
+ OapiV2UserGetRequest req = new OapiV2UserGetRequest();
|
|
|
|
+ req.setUserid(dingdingUserid);
|
|
|
|
+ req.setLanguage("zh_CN");
|
|
|
|
+ OapiV2UserGetResponse rsp = client.execute(req, access_token);
|
|
|
|
+// System.out.println(rsp.getBody());
|
|
|
|
+ JSONObject resp = JSONObject.parseObject(rsp.getBody());
|
|
|
|
+ if (resp.getInteger("errcode") == 0) {
|
|
|
|
+ JSONObject userJson = resp.getJSONObject("result");
|
|
|
|
+ User user = new User();
|
|
|
|
+ SysRole defaultRole = sysRoleMapper.selectOne(
|
|
|
|
+ new QueryWrapper<SysRole>().eq("company_id", dingding.getCompanyId()).eq("is_default", 1));
|
|
|
|
+
|
|
|
|
+ user.setId(SnowFlake.nextId() + "")
|
|
|
|
+ .setRoleId(defaultRole.getId())
|
|
|
|
+ .setRoleName(defaultRole.getRolename())
|
|
|
|
+ .setCompanyId(dingding.getCompanyId())
|
|
|
|
+ .setName(userJson.getString("name"))
|
|
|
|
+ .setDingdingUserid(dingdingUserid)
|
|
|
|
+ .setDingdingUnionid(userJson.getString("unionid"))
|
|
|
|
+ .setColor(ColorUtil.randomColor());
|
|
|
|
+ JSONArray dingdingDeptIds = userJson.getJSONArray("dept_id_list");
|
|
|
|
+ if (dingdingDeptIds.size() > 0) {
|
|
|
|
+ //取最后一个部门,一般是最末级部门
|
|
|
|
+ Integer dpId = dingdingDeptIds.getInteger(dingdingDeptIds.size()-1);
|
|
|
|
+ DepartmentDingding departmentDingding = departmentDingdingMapper.selectOne(new QueryWrapper<DepartmentDingding>().eq("corpid", dingding.getCorpid())
|
|
|
|
+ .eq("dd_deptid", dpId));
|
|
|
|
+ if (departmentDingding != null) {
|
|
|
|
+ Integer departmentId = departmentDingding.getSysDeptid();
|
|
|
|
+ if (departmentId != null) {
|
|
|
|
+ user.setDepartmentId(departmentDingding.getSysDeptid());
|
|
|
|
+ user.setDepartmentCascade(convertDepartmentIdToCascade(departmentId));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //检查用户是否已经存在
|
|
|
|
+ synchronized (userLock) {
|
|
|
|
+ List<User> oldList = userMapper.selectList(new QueryWrapper<User>().eq("dingding_userid", dingdingUserid).eq("company_id", dingding.getCompanyId()));
|
|
|
|
+ if (oldList.size() == 0) {
|
|
|
|
+ System.out.println("监听变化,主动新增钉钉用户==" + user.getName());
|
|
|
|
+ userMapper.insert(user);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
//获取人员详情
|
|
//获取人员详情
|
|
private void getUserDetail(int roleId, String roleName, Integer companyId, Integer departmentId, String dingdingUserid, String access_token) throws ApiException {
|
|
private void getUserDetail(int roleId, String roleName, Integer companyId, Integer departmentId, String dingdingUserid, String access_token) throws ApiException {
|
|
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/get");
|
|
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/get");
|
|
@@ -1364,51 +1472,6 @@ public class DingDingServiceImpl implements DingDingService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-// public HttpRespMsg getLeaveTypeList(String leaveCode, Integer companyId, Integer departmentId, String userId, Integer pageIndex) {
|
|
|
|
-// CompanyDingding dingding = companyDingdingMapper.selectOne(new QueryWrapper<CompanyDingding>().eq("company_id", companyId));
|
|
|
|
-// HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
-// HashMap resultMap = new HashMap();
|
|
|
|
-// DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/attendance/vacation/type/list");
|
|
|
|
-// OapiAttendanceVacationTypeListRequest req = new OapiAttendanceVacationTypeListRequest();
|
|
|
|
-// List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId).eq("role_name", "超级管理员"));
|
|
|
|
-//// String oaManagerDid = "2221645448842951";
|
|
|
|
-// String oaManagerDid = userList.get(0).getDingdingUserid();
|
|
|
|
-// if (leaveCode == null) {
|
|
|
|
-// req.setOpUserid(oaManagerDid);
|
|
|
|
-// req.setVacationSource("all");
|
|
|
|
-// OapiAttendanceVacationTypeListResponse rsp = null;
|
|
|
|
-// try {
|
|
|
|
-// rsp = client.execute(req, getInnerCorpToken(dingding));
|
|
|
|
-// System.out.println(rsp.getBody());
|
|
|
|
-// JSONObject json = JSONObject.parseObject(rsp.getBody());
|
|
|
|
-// JSONArray result = json.getJSONArray("result");
|
|
|
|
-// List<LeaveTypeVO> typeList = new ArrayList<>();
|
|
|
|
-// LeaveTypeVO defaultType = null;
|
|
|
|
-// for (int i=0;i<result.size(); i++) {
|
|
|
|
-// JSONObject obj = result.getJSONObject(i);
|
|
|
|
-// LeaveTypeVO vo = new LeaveTypeVO();
|
|
|
|
-// vo.leaveCode = obj.getString("leave_code");
|
|
|
|
-// vo.leaveName = obj.getString("leave_name");
|
|
|
|
-// if (vo.leaveName.equals("调休")) {
|
|
|
|
-// defaultType = vo;
|
|
|
|
-// }
|
|
|
|
-// typeList.add(vo);
|
|
|
|
-// }
|
|
|
|
-// resultMap.put("leaveTypeList", typeList);
|
|
|
|
-// if (defaultType == null) defaultType = typeList.get(0);
|
|
|
|
-// leaveCode = defaultType.leaveCode;
|
|
|
|
-// resultMap.put("defaultLeaveType", defaultType);
|
|
|
|
-// System.out.println("本次请求的LeaveCode: "+leaveCode);
|
|
|
|
-// reqQuotaList(companyId, dingding, leaveCode, oaManagerDid, departmentId, userId, pageIndex, resultMap);
|
|
|
|
-// } catch (ApiException e) {
|
|
|
|
-// e.printStackTrace();
|
|
|
|
-// }
|
|
|
|
-// } else {
|
|
|
|
-// reqQuotaList(companyId, dingding, leaveCode, oaManagerDid, departmentId, userId, pageIndex, resultMap);
|
|
|
|
-// }
|
|
|
|
-// msg.data = resultMap;
|
|
|
|
-// return msg;
|
|
|
|
-// }
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public HttpRespMsg syncLeaveQuotaData(Integer companyId) {
|
|
public HttpRespMsg syncLeaveQuotaData(Integer companyId) {
|
|
@@ -1424,6 +1487,8 @@ public class DingDingServiceImpl implements DingDingService {
|
|
OapiAttendanceVacationTypeListResponse rsp = null;
|
|
OapiAttendanceVacationTypeListResponse rsp = null;
|
|
try {
|
|
try {
|
|
rsp = client.execute(req, getInnerCorpToken(dingding));
|
|
rsp = client.execute(req, getInnerCorpToken(dingding));
|
|
|
|
+ System.out.println(rsp.getBody());
|
|
|
|
+ System.out.println(rsp.getErrcode()+":"+rsp.getErrmsg());
|
|
JSONObject json = JSONObject.parseObject(rsp.getBody());
|
|
JSONObject json = JSONObject.parseObject(rsp.getBody());
|
|
JSONArray result = json.getJSONArray("result");
|
|
JSONArray result = json.getJSONArray("result");
|
|
List<LeaveType> typeList = new ArrayList<>();
|
|
List<LeaveType> typeList = new ArrayList<>();
|
|
@@ -1464,6 +1529,78 @@ public class DingDingServiceImpl implements DingDingService {
|
|
return new HttpRespMsg();
|
|
return new HttpRespMsg();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg removeCompInfo(String corpid) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ CompanyDingding dingding = companyDingdingMapper.selectById(corpid);
|
|
|
|
+ Integer companyId = dingding.getCompanyId();
|
|
|
|
+ departmentMapper.delete(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
|
+ departmentDingdingMapper.delete(new QueryWrapper<DepartmentDingding>().eq("corpid", corpid));
|
|
|
|
+ userMapper.delete(new QueryWrapper<User>().eq("company_id", companyId));
|
|
|
|
+ sysRoleMapper.delete(new QueryWrapper<SysRole>().eq("company_id", companyId));
|
|
|
|
+ //sysRoleFunction和sysRoleModule表会级联删除
|
|
|
|
+ projectBasecostSettingMapper.delete(new QueryWrapper<ProjectBasecostSetting>().eq("company_id", companyId));
|
|
|
|
+ companyMapper.deleteById(companyId);
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg initSuperManager(String corpid, String name) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ CompanyDingding dingding = companyDingdingMapper.selectById(corpid);
|
|
|
|
+ Integer companyId = dingding.getCompanyId();
|
|
|
|
+ User user = userMapper.selectOne(new QueryWrapper<User>().eq("name", name).eq("company_id", companyId));
|
|
|
|
+ if (user == null) {
|
|
|
|
+ msg.setError("该用户不存在: " + name);
|
|
|
|
+ } else {
|
|
|
|
+ SysRole role = sysRoleMapper.selectOne(new QueryWrapper<SysRole>().eq("company_id", companyId).eq("rolename", "超级管理员"));
|
|
|
|
+ user.setPhone(user.getName());
|
|
|
|
+ user.setPassword(MD5Util.getPassword("000000"));
|
|
|
|
+ user.setRoleId(role.getId());
|
|
|
|
+ user.setRoleName(role.getRolename());
|
|
|
|
+ userMapper.updateById(user);
|
|
|
|
+ }
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void userLeaveOrg(String corpId, JSONArray userIdArray, LocalDate leaveDate) {
|
|
|
|
+ //员工离职,对其标记为离职状态
|
|
|
|
+ CompanyDingding companyDingding = companyDingdingMapper.selectById(corpId);
|
|
|
|
+ for (int i=0;i<userIdArray.size(); i++) {
|
|
|
|
+ String userdingId = userIdArray.getString(i);
|
|
|
|
+ User user = userMapper.selectOne(new QueryWrapper<User>().eq("company_id", companyDingding.getCompanyId()).eq("dingding_userid", userdingId));
|
|
|
|
+ if (user != null) {
|
|
|
|
+ user.setIsActive(0);
|
|
|
|
+ user.setInactiveDate(leaveDate);
|
|
|
|
+ userMapper.updateById(user);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void userAddOrg(String corpId, JSONArray userIdArray) {
|
|
|
|
+ //添加了员工,检测是否在我们已经授权的范围内
|
|
|
|
+ CompanyDingding companyDingding = companyDingdingMapper.selectById(corpId);
|
|
|
|
+ for (int i=0;i<userIdArray.size(); i++) {
|
|
|
|
+ String userdingId = userIdArray.getString(i);
|
|
|
|
+ User user = userMapper.selectOne(new QueryWrapper<User>().eq("company_id", companyDingding.getCompanyId()).eq("dingding_userid", userdingId));
|
|
|
|
+ if (user == null) {
|
|
|
|
+ //添加人员
|
|
|
|
+ try {
|
|
|
|
+ String corpAccessToken = getInnerCorpToken(companyDingding);
|
|
|
|
+ getAddUserDetail(companyDingding, userdingId, corpAccessToken);
|
|
|
|
+ } catch (ApiException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ //已存在,更新状态
|
|
|
|
+ user.setIsActive(1);
|
|
|
|
+ userMapper.updateById(user);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
//同步公司全部人员的假期余额
|
|
//同步公司全部人员的假期余额
|
|
private void syncQuotaList(String leaveCode,String oaManagerDid, CompanyDingding dingding, List<User> userList, long offset) {
|
|
private void syncQuotaList(String leaveCode,String oaManagerDid, CompanyDingding dingding, List<User> userList, long offset) {
|
|
@@ -1537,112 +1674,6 @@ public class DingDingServiceImpl implements DingDingService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-//
|
|
|
|
-// private void reqQuotaList(Integer companyId, CompanyDingding dingding,
|
|
|
|
-// String leaveCode, String oaManagerDid, Integer departmentId, String userId, Integer pageIndex, HashMap resultMap) {
|
|
|
|
-// //再调用查看假期余额的接口
|
|
|
|
-// long pageSize = 50L;
|
|
|
|
-// DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/attendance/vacation/quota/list");
|
|
|
|
-// OapiAttendanceVacationQuotaListRequest quoataReq = new OapiAttendanceVacationQuotaListRequest();
|
|
|
|
-// quoataReq.setLeaveCode(leaveCode);
|
|
|
|
-// quoataReq.setOpUserid(oaManagerDid);
|
|
|
|
-// List<User> userList = null;
|
|
|
|
-// String userIds = null;
|
|
|
|
-// if (StringUtils.isEmpty(userId)) {
|
|
|
|
-// int total = 0;
|
|
|
|
-// if (departmentId == null) {
|
|
|
|
-// //全部员工,包括离职的
|
|
|
|
-// QueryWrapper<User> queryWrapper = new QueryWrapper<User>();
|
|
|
|
-// queryWrapper.select("distinct dingding_userid, name").eq("company_id", companyId);
|
|
|
|
-// userList = userMapper.selectList(queryWrapper);
|
|
|
|
-// total = userList.size();
|
|
|
|
-// } else {
|
|
|
|
-// //指定部门
|
|
|
|
-// Department dept = departmentMapper.selectById(departmentId);
|
|
|
|
-// List<Department> allDept = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
|
-// List<Department> allSubDepts = getSubDeptList(allDept, dept);
|
|
|
|
-// userList = userMapper.selectList(
|
|
|
|
-// new QueryWrapper<User>().select("distinct dingding_userid, name")
|
|
|
|
-// .in("department_id", allSubDepts.stream().map(Department::getDepartmentId).collect(Collectors.toList())));
|
|
|
|
-// total = userList.size();
|
|
|
|
-// }
|
|
|
|
-// String collect = userList.stream().map(User::getDingdingUserid).collect(Collectors.joining(","));
|
|
|
|
-// userIds = collect;
|
|
|
|
-// resultMap.put("total", total);
|
|
|
|
-// } else {
|
|
|
|
-// userList = new ArrayList<>();
|
|
|
|
-// userList = userMapper.selectList(new QueryWrapper<User>().in("id", ListUtil.convertLongIdsArrayToList(userId)));
|
|
|
|
-// userIds = userList.stream().map(User::getDingdingUserid).collect(Collectors.joining(","));
|
|
|
|
-// resultMap.put("total", userList.size());
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// System.out.println("请求的size="+userList.size());
|
|
|
|
-// System.out.println("长度=="+userIds.length());
|
|
|
|
-// List<LeaveQuotaNum> quotaNumList = new ArrayList<>();
|
|
|
|
-// for (User user : userList) {
|
|
|
|
-// LeaveQuotaNum quotaNum = new LeaveQuotaNum();
|
|
|
|
-// quotaNum.userDingdingId = user.getDingdingUserid();
|
|
|
|
-// quotaNum.name = user.getName();
|
|
|
|
-// quotaNum.leaveCode = leaveCode;
|
|
|
|
-// quotaNumList.add(quotaNum);
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// if (quotaNumList.size() == 0) {
|
|
|
|
-// //无员工数据了
|
|
|
|
-// return;
|
|
|
|
-// }
|
|
|
|
-// quoataReq.setUserids(userIds);
|
|
|
|
-// quoataReq.setOffset(0L);
|
|
|
|
-// quoataReq.setSize(pageSize);
|
|
|
|
-// OapiAttendanceVacationQuotaListResponse quotaListResponse = null;
|
|
|
|
-// try {
|
|
|
|
-// quotaListResponse = client.execute(quoataReq, getInnerCorpToken(dingding));
|
|
|
|
-// } catch (ApiException e) {
|
|
|
|
-// e.printStackTrace();
|
|
|
|
-// }
|
|
|
|
-// System.out.println(quotaListResponse.getBody()+":"+quotaListResponse.getErrmsg());
|
|
|
|
-// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
-// JSONObject json = JSONObject.parseObject(quotaListResponse.getBody());
|
|
|
|
-// DecimalFormat df = new DecimalFormat("#0.0");
|
|
|
|
-// if (json.getInteger("errcode") == 0) {
|
|
|
|
-// JSONObject result = json.getJSONObject("result");
|
|
|
|
-// JSONArray leaveQuotas = result.getJSONArray("leave_quotas");
|
|
|
|
-// if (leaveQuotas != null) {
|
|
|
|
-// for (int i=0;i<leaveQuotas.size(); i++) {
|
|
|
|
-// JSONObject jsonObject = leaveQuotas.getJSONObject(i);
|
|
|
|
-// String userDDid = jsonObject.getString("userid");
|
|
|
|
-// for (LeaveQuotaNum quotaNum : quotaNumList) {
|
|
|
|
-// if (quotaNum.userDingdingId.equals(userDDid)) {
|
|
|
|
-// Date startDate = new Date(jsonObject.getLongValue("start_time"));
|
|
|
|
-// quotaNum.startTime = sdf.format(startDate);
|
|
|
|
-// Date endDate = new Date(jsonObject.getLongValue("end_time"));
|
|
|
|
-// quotaNum.endTime = sdf.format(endDate);
|
|
|
|
-// Integer quota_num_per_hour = jsonObject.getInteger("quota_num_per_hour");
|
|
|
|
-// if (quota_num_per_hour != null) {
|
|
|
|
-// //按小时为单位的情况
|
|
|
|
-// quotaNum.quotaInHours = df.format(quota_num_per_hour*1.0/100);
|
|
|
|
-// Integer used_num_per_hour = jsonObject.getInteger("used_num_per_hour");
|
|
|
|
-// quotaNum.usedInHours = df.format(used_num_per_hour*1.0/100);
|
|
|
|
-// //计算剩余
|
|
|
|
-// quotaNum.leftInHours = df.format((quota_num_per_hour - used_num_per_hour)*1.0/100);
|
|
|
|
-// } else {
|
|
|
|
-// //按天单位的情况
|
|
|
|
-// Integer quota_num_per_day = jsonObject.getInteger("quota_num_per_day");
|
|
|
|
-// quotaNum.quotaInDays = df.format(quota_num_per_day*1.0/100);
|
|
|
|
-// Integer used_num_per_day = jsonObject.getInteger("used_num_per_day");
|
|
|
|
-// quotaNum.usedInDays = df.format(used_num_per_day*1.0/100);
|
|
|
|
-// //计算剩余
|
|
|
|
-// quotaNum.leftInDays = df.format((quota_num_per_day - used_num_per_day)*1.0/100);
|
|
|
|
-// }
|
|
|
|
-// System.out.println(quotaNum.name+" 假期额度="+quotaNum.quotaInDays);
|
|
|
|
-// break;
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// resultMap.put("records", quotaNumList);
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
|
|
|
|
public void activateSuite(String authCorpid, String tmpAuthCode) throws ApiException {
|
|
public void activateSuite(String authCorpid, String tmpAuthCode) throws ApiException {
|
|
DingTalkClient client= new DefaultDingTalkClient("https://oapi.dingtalk.com/service/activate_suite?suite_access_token=" + getDDSuiteAccessToken());
|
|
DingTalkClient client= new DefaultDingTalkClient("https://oapi.dingtalk.com/service/activate_suite?suite_access_token=" + getDDSuiteAccessToken());
|