|
@@ -150,6 +150,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
private ThirdPartyInterfaceMapper thirdPartyInterfaceMapper;
|
|
|
@Resource
|
|
|
SysConfigMapper sysConfigMapper;
|
|
|
+
|
|
|
+ public static String provider_access_token = null;
|
|
|
+ public static long providerTokenExpireTime = 0L;
|
|
|
//登录网页端
|
|
|
@Override
|
|
|
public HttpRespMsg loginAdmin(String username, String password) {
|
|
@@ -431,153 +434,182 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
|
|
|
- //获取员工的列表
|
|
|
- @Override
|
|
|
- public HttpRespMsg getEmployeeList(Integer departmentId, String keyword, Integer status, Integer roleId, Integer onlyDirect, Integer pageIndex, Integer pageSize, HttpServletRequest request) {
|
|
|
- HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
- Integer WXCompanyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
|
|
|
- WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", WXCompanyId));
|
|
|
- if (wxCorpInfo!=null && wxCorpInfo.getSaasSyncContact()==1 && org.apache.commons.lang3.StringUtils.isNotBlank(keyword) && departmentId == -1){
|
|
|
- String AccessUrl = "https://qyapi.weixin.qq.com/cgi-bin/service/get_provider_token";
|
|
|
- String url = "https://qyapi.weixin.qq.com/cgi-bin/service/contact/search?provider_access_token=ACCESS_TOKEN";
|
|
|
+ //获取provider_access_token
|
|
|
+ private String getProviderAccessToken() {
|
|
|
+ if (WeiXinCorpController.SUITE_ACCESS_TOKEN == null || WeiXinCorpController.suiteTokenExpireTime < System.currentTimeMillis()) {
|
|
|
+ //失效了,需要重新获取
|
|
|
+ String url = "https://qyapi.weixin.qq.com/cgi-bin/service/get_provider_token";
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
|
|
|
headers.setContentType(type);
|
|
|
headers.add("Accept", MediaType.APPLICATION_JSON.toString());
|
|
|
- //获取服务商id
|
|
|
- JSONObject AccessRequestMap = new JSONObject();
|
|
|
- AccessRequestMap.put("corpid", corpId);
|
|
|
- AccessRequestMap.put("provider_secret", providerSecret);
|
|
|
- HttpEntity<JSONObject> AccessEntity = new HttpEntity<>(AccessRequestMap, headers);
|
|
|
- ResponseEntity<String> AccessResponseEntity = restTemplate.postForEntity(AccessUrl, AccessEntity, String.class);
|
|
|
- String providerToken ="";
|
|
|
- if (AccessResponseEntity.getStatusCode() == HttpStatus.OK){
|
|
|
- String AccessResp = AccessResponseEntity.getBody();
|
|
|
- JSONObject json = JSONObject.parseObject(AccessResp);
|
|
|
- providerToken = json.getString("provider_access_token");
|
|
|
- //搜索通讯录名单
|
|
|
- url = url.replace("ACCESS_TOKEN", providerToken);
|
|
|
- JSONObject requestMap = new JSONObject();
|
|
|
- requestMap.put("auth_corpid", wxCorpInfo.getCorpid());
|
|
|
- requestMap.put("query_word", keyword);
|
|
|
- requestMap.put("query_type", 1);
|
|
|
- requestMap.put("query_range", 1);
|
|
|
- requestMap.put("limit", 200);
|
|
|
- //requestMap.put("cursor", pageSize);
|
|
|
- HttpEntity<JSONObject> entity = new HttpEntity<>(requestMap, headers);
|
|
|
- ResponseEntity<String> ResponseEntity = restTemplate.postForEntity(url, entity, String.class);
|
|
|
- if (ResponseEntity.getStatusCode() == HttpStatus.OK) {
|
|
|
- String resp = ResponseEntity.getBody();
|
|
|
- JSONObject respJson = JSONObject.parseObject(resp);
|
|
|
+ JSONObject reqParam = new JSONObject();
|
|
|
+ reqParam.put("corpid", corpId);
|
|
|
+ reqParam.put("provider_secret", providerSecret);
|
|
|
+ HttpEntity<JSONObject> Entity = new HttpEntity<>(reqParam, headers);
|
|
|
+ ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, Entity, String.class);
|
|
|
+ if (responseEntity.getStatusCode() == HttpStatus.OK) {
|
|
|
+ String resp = responseEntity.getBody();
|
|
|
+ JSONObject obj = JSONObject.parseObject(resp);
|
|
|
+ if (obj.getIntValue("errcode") == 0) {
|
|
|
+ UserServiceImpl.provider_access_token = obj.getString("provider_access_token");
|
|
|
+ UserServiceImpl.providerTokenExpireTime = System.currentTimeMillis() + obj.getIntValue("expires_in")*1000;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return UserServiceImpl.provider_access_token;
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据关键词查询微信通讯录人员的openid
|
|
|
+ //keyword不可为空格或空字符串,否则请求参数错误
|
|
|
+ private Object[] getOpenId(String corpId,String keyword) {
|
|
|
+ Object[] user = null;
|
|
|
+ String url = "https://qyapi.weixin.qq.com/cgi-bin/service/contact/search?provider_access_token=ACCESS_TOKEN";
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
|
|
|
+ headers.setContentType(type);
|
|
|
+ headers.add("Accept", MediaType.APPLICATION_JSON.toString());
|
|
|
+ String providerToken = getProviderAccessToken();
|
|
|
+ if (providerToken!=null){
|
|
|
+ //搜索通讯录名单
|
|
|
+ url = url.replace("ACCESS_TOKEN", providerToken);
|
|
|
+ JSONObject requestMap = new JSONObject();
|
|
|
+ requestMap.put("auth_corpid", corpId);
|
|
|
+ requestMap.put("query_word", keyword);
|
|
|
+ requestMap.put("query_type", 1);
|
|
|
+ requestMap.put("query_range", 1);
|
|
|
+ requestMap.put("limit", 200);
|
|
|
+ //requestMap.put("cursor", pageSize);
|
|
|
+ HttpEntity<JSONObject> entity = new HttpEntity<>(requestMap, headers);
|
|
|
+ ResponseEntity<String> ResponseEntity = restTemplate.postForEntity(url, entity, String.class);
|
|
|
+ if (ResponseEntity.getStatusCode() == HttpStatus.OK) {
|
|
|
+ String resp = ResponseEntity.getBody();
|
|
|
+ JSONObject respJson = JSONObject.parseObject(resp);
|
|
|
+ if (respJson.getInteger("errcode")==0){
|
|
|
JSONObject queryResult = respJson.getJSONObject("query_result");
|
|
|
if (!queryResult.isEmpty()){
|
|
|
JSONArray jsonArray = queryResult.getJSONObject("user").getJSONArray("open_userid");
|
|
|
- if (jsonArray.size()!=0){
|
|
|
- Object[] user = jsonArray.toArray();
|
|
|
- List<User> users = userMapper.selectList(new QueryWrapper<User>().in("corpwx_userid", user));
|
|
|
- HashMap<String, Object> data = new HashMap<>();
|
|
|
- data.put("records",users);
|
|
|
- data.put("total",0);
|
|
|
- httpRespMsg.data=data;
|
|
|
- return httpRespMsg;
|
|
|
+ if (jsonArray!=null){
|
|
|
+ user = jsonArray.toArray();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- HashMap<String, Object> data = new HashMap<>();
|
|
|
- ArrayList<Object> records = new ArrayList<>();
|
|
|
- data.put("records",records);
|
|
|
- data.put("total",0);
|
|
|
- httpRespMsg.data=data;
|
|
|
- return httpRespMsg;
|
|
|
}
|
|
|
- try {
|
|
|
- Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
|
|
|
- TimeType timeType = timeTypeMapper.selectById(companyId);
|
|
|
- long total;
|
|
|
- List<Map<String, Object>> list;
|
|
|
- Page<User> page = new Page<>(pageIndex, pageSize);
|
|
|
- if (departmentId == -1) {
|
|
|
- //单独查找全部
|
|
|
- list = userMapper.getUserByDepartment(page, companyId, null, keyword, status, roleId);
|
|
|
- total = page.getTotal();
|
|
|
- } else if (departmentId == 0) {
|
|
|
- //单独查找0, 未分配的
|
|
|
- list = userMapper.getUserByDepartment(page, companyId, departmentId, keyword, status, roleId);
|
|
|
- total = page.getTotal();
|
|
|
- } else {
|
|
|
- //范围查找
|
|
|
- List<Integer> ids = new ArrayList<>();
|
|
|
- if (onlyDirect != null && onlyDirect == 1) {
|
|
|
- //只看直属的
|
|
|
- ids.add(departmentId);
|
|
|
- } else {
|
|
|
- //查看当前部门包括子部门的人员
|
|
|
- List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
- ids = departmentService.getDeptIncludeSubDeptIds(departmentId, allDeptList);
|
|
|
- }
|
|
|
+ return user;
|
|
|
+ }
|
|
|
|
|
|
- list = userMapper.getUserByDepartmentList(page, companyId, ids, keyword, status, roleId);
|
|
|
- total = page.getTotal();
|
|
|
- }
|
|
|
- Map<String, Object> resultMap = new HashMap<>();
|
|
|
- if (timeType.getIsSecretSalary() == 1) {
|
|
|
- //秘薪处理
|
|
|
- list.forEach(li->{
|
|
|
- li.put("monthCost", 0.0);
|
|
|
- li.put("cost", 0.0);
|
|
|
- });
|
|
|
+ //获取员工的列表
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg getEmployeeList(Integer departmentId, String keyword, Integer status, Integer roleId, Integer onlyDirect, Integer pageIndex, Integer pageSize, HttpServletRequest request) {
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+ Integer WXCompanyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", WXCompanyId));
|
|
|
+ HashMap<String, Object> data = new HashMap<>();
|
|
|
+ httpRespMsg.data=data;
|
|
|
+ data.put("total",0);
|
|
|
+ //当企业开启了微信通讯录的情况下
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isNotBlank(keyword) && wxCorpInfo!=null && wxCorpInfo.getSaasSyncContact()==1 && departmentId == -1){
|
|
|
+ Object[] users = getOpenId(wxCorpInfo.getCorpid(), keyword);
|
|
|
+ if (users!=null){
|
|
|
+ List<User> realUser = userMapper.selectList(new QueryWrapper<User>().in("corpwx_userid", users));
|
|
|
+ data.put("records",realUser);
|
|
|
+ return httpRespMsg;
|
|
|
+ }else {
|
|
|
+ ArrayList<Object> records = new ArrayList<>();
|
|
|
+ data.put("records",records);
|
|
|
+ return httpRespMsg;
|
|
|
}
|
|
|
- List<UserCustom> userCustomList = userCustomMapper.selectList(new QueryWrapper<UserCustom>().eq("company_id", companyId));
|
|
|
- if(!StringUtils.isEmpty(list)){
|
|
|
- for(Map<String,Object> u:list) {
|
|
|
- HashMap map=new HashMap();
|
|
|
- for (int i = 0; i < userCustomList.size(); i++) {
|
|
|
- switch (i) {
|
|
|
- case 0:
|
|
|
- map.put(userCustomList.get(i).getName(), u.get("plate1"));
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- map.put(userCustomList.get(i).getName(), u.get("plate2"));
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- map.put(userCustomList.get(i).getName(), u.get("plate3"));
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- map.put(userCustomList.get(i).getName(), u.get("plate4"));
|
|
|
- break;
|
|
|
- case 4:
|
|
|
- map.put(userCustomList.get(i).getName(), u.get("plate5"));
|
|
|
- break;
|
|
|
+ }else {
|
|
|
+ try {
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
|
|
|
+ TimeType timeType = timeTypeMapper.selectById(companyId);
|
|
|
+ long total;
|
|
|
+ List<Map<String, Object>> list;
|
|
|
+ Page<User> page = new Page<>(pageIndex, pageSize);
|
|
|
+ if (departmentId == -1) {
|
|
|
+ //单独查找全部
|
|
|
+ list = userMapper.getUserByDepartment(page, companyId, null, keyword, status, roleId);
|
|
|
+ total = page.getTotal();
|
|
|
+ } else if (departmentId == 0) {
|
|
|
+ //单独查找0, 未分配的
|
|
|
+ list = userMapper.getUserByDepartment(page, companyId, departmentId, keyword, status, roleId);
|
|
|
+ total = page.getTotal();
|
|
|
+ } else {
|
|
|
+ //范围查找
|
|
|
+ List<Integer> ids = new ArrayList<>();
|
|
|
+ if (onlyDirect != null && onlyDirect == 1) {
|
|
|
+ //只看直属的
|
|
|
+ ids.add(departmentId);
|
|
|
+ } else {
|
|
|
+ //查看当前部门包括子部门的人员
|
|
|
+ List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
+ ids = departmentService.getDeptIncludeSubDeptIds(departmentId, allDeptList);
|
|
|
+ }
|
|
|
+
|
|
|
+ list = userMapper.getUserByDepartmentList(page, companyId, ids, keyword, status, roleId);
|
|
|
+ total = page.getTotal();
|
|
|
+ }
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
+ if (timeType.getIsSecretSalary() == 1) {
|
|
|
+ //秘薪处理
|
|
|
+ list.forEach(li->{
|
|
|
+ li.put("monthCost", 0.0);
|
|
|
+ li.put("cost", 0.0);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ List<UserCustom> userCustomList = userCustomMapper.selectList(new QueryWrapper<UserCustom>().eq("company_id", companyId));
|
|
|
+ if(!StringUtils.isEmpty(list)){
|
|
|
+ for(Map<String,Object> u:list) {
|
|
|
+ HashMap map=new HashMap();
|
|
|
+ for (int i = 0; i < userCustomList.size(); i++) {
|
|
|
+ switch (i) {
|
|
|
+ case 0:
|
|
|
+ map.put(userCustomList.get(i).getName(), u.get("plate1"));
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ map.put(userCustomList.get(i).getName(), u.get("plate2"));
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ map.put(userCustomList.get(i).getName(), u.get("plate3"));
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ map.put(userCustomList.get(i).getName(), u.get("plate4"));
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ map.put(userCustomList.get(i).getName(), u.get("plate5"));
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
+ u.put("plateMap",map);
|
|
|
}
|
|
|
- u.put("plateMap",map);
|
|
|
}
|
|
|
- }
|
|
|
- if (companyMapper.selectById(companyId).getIsInternational() == 1) {
|
|
|
- //国际化版本
|
|
|
- LocaleInformation locale = localeInformationMapper.selectById(companyId);
|
|
|
- TimeZone curZone = TimeZone.getTimeZone(locale.getTimezone());
|
|
|
- int offsetSeconds = (curZone.getRawOffset() - TimeZone.getTimeZone("GMT+8").getRawOffset())/1000;
|
|
|
- //时区转换,默认数据库存的是GMT+8
|
|
|
- DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm", Locale.CHINA);
|
|
|
- for (Map user : list) {
|
|
|
- String createTime = (String)user.get("createTime");
|
|
|
- LocalDateTime time = LocalDateTime.parse(createTime, dtf);
|
|
|
- time = time.plusSeconds(offsetSeconds);
|
|
|
- user.put("createTime", dtf.format(time));
|
|
|
+ if (companyMapper.selectById(companyId).getIsInternational() == 1) {
|
|
|
+ //国际化版本
|
|
|
+ LocaleInformation locale = localeInformationMapper.selectById(companyId);
|
|
|
+ TimeZone curZone = TimeZone.getTimeZone(locale.getTimezone());
|
|
|
+ int offsetSeconds = (curZone.getRawOffset() - TimeZone.getTimeZone("GMT+8").getRawOffset())/1000;
|
|
|
+ //时区转换,默认数据库存的是GMT+8
|
|
|
+ DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm", Locale.CHINA);
|
|
|
+ for (Map user : list) {
|
|
|
+ String createTime = (String)user.get("createTime");
|
|
|
+ LocalDateTime time = LocalDateTime.parse(createTime, dtf);
|
|
|
+ time = time.plusSeconds(offsetSeconds);
|
|
|
+ user.put("createTime", dtf.format(time));
|
|
|
+ }
|
|
|
}
|
|
|
+ resultMap.put("records", list);
|
|
|
+ resultMap.put("total", total);
|
|
|
+ httpRespMsg.data = resultMap;
|
|
|
+ } catch (NullPointerException e) {
|
|
|
+ //httpRespMsg.setError("验证失败");
|
|
|
+ httpRespMsg.setError(MessageUtils.message("access.verificationError"));
|
|
|
+ return httpRespMsg;
|
|
|
}
|
|
|
- resultMap.put("records", list);
|
|
|
- resultMap.put("total", total);
|
|
|
- httpRespMsg.data = resultMap;
|
|
|
- } catch (NullPointerException e) {
|
|
|
- //httpRespMsg.setError("验证失败");
|
|
|
- httpRespMsg.setError(MessageUtils.message("access.verificationError"));
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
- return httpRespMsg;
|
|
|
}
|
|
|
|
|
|
//删除普通用户
|
|
@@ -2031,7 +2063,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public HttpRespMsg getSimpleActiveUserList(Integer departmentId, HttpServletRequest request) {
|
|
|
+ public HttpRespMsg getSimpleActiveUserList(Integer departmentId, HttpServletRequest request,String keyword) {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
String token = request.getHeader("TOKEN");
|
|
|
User user = userMapper.selectById(token);
|
|
@@ -2043,8 +2075,32 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
wrapper.in("department_id", deptIds);
|
|
|
}
|
|
|
List<User> userList = userMapper.selectList(wrapper);
|
|
|
- msg.data = userList;
|
|
|
- return msg;
|
|
|
+ //企业微信通讯录搜索功能
|
|
|
+ Integer WXCompanyId = user.getCompanyId();
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", WXCompanyId));
|
|
|
+ //当企业开启了微信通讯录的情况下
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isNotBlank(keyword) && wxCorpInfo!=null && wxCorpInfo.getSaasSyncContact()==1){
|
|
|
+ Object[] users = getOpenId(wxCorpInfo.getCorpid(), keyword);
|
|
|
+ List<User> retUser = new ArrayList<>();
|
|
|
+ msg.data = retUser;
|
|
|
+ if (users!=null){
|
|
|
+ List<User> realUser = userMapper.selectList(new QueryWrapper<User>().in("corpwx_userid", users));
|
|
|
+ for (User item : userList) {
|
|
|
+ for (User realItem : realUser) {
|
|
|
+ if (item.getId().equals(realItem.getId())){
|
|
|
+ retUser.add(realItem);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }else {
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ msg.data = userList;
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|