| | |
| | | package com.yuanchu.mom.util; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.http.HttpRequest; |
| | | import cn.hutool.http.HttpResponse; |
| | | import cn.hutool.log.Log; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.fasterxml.jackson.databind.JsonNode; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.Optional; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | }catch (Exception e){ |
| | | throw new ErrorException(e.getMessage()); |
| | | } |
| | | /*return companies.stream().filter(ob->{ |
| | | if(ob.getStatus().equals("enabled")) return true; |
| | | return companies.stream().filter(ob->{ |
| | | if(Objects.equals(ob.getStatus(), "enabled")) return true; |
| | | return false; |
| | | }).collect(Collectors.toList());*/ |
| | | return companies; |
| | | }).collect(Collectors.toList()); |
| | | // return companies; |
| | | } |
| | | |
| | | public List<Person> userUrl(String companyId) { |
| | |
| | | }catch (Exception e){ |
| | | throw new ErrorException(e.getMessage()); |
| | | } |
| | | List<JSONObject> department = getDepartment(companyId); |
| | | return person.stream().filter(ob->{ |
| | | ob.setIsLive(userMapper.selectCount(Wrappers.<User>lambdaQuery().eq(User::getAccount, ob.getEmployeeID()))); |
| | | return true; |
| | | if(Objects.equals(ob.getStatus(), "enabled")) { |
| | | ob.setIsLive(userMapper.selectCount(Wrappers.<User>lambdaQuery().eq(User::getAccount, ob.getEmployeeID()))); |
| | | ob.setDepartment(getDepartmentStr(department, ob.getDepartmentCode()).replaceFirst("/", "")); |
| | | return true; |
| | | } |
| | | return false; |
| | | }).collect(Collectors.toList()); |
| | | } |
| | | |
| | | public String getDepartmentStr(List<JSONObject> department, String code){ |
| | | String str = ""; |
| | | Optional<JSONObject> depart = department.stream().filter(a -> code.equals(a.get("departmentCode"))).findFirst(); |
| | | str = "/" + depart.get().get("departmentName") + str; |
| | | if(depart.get().get("parentDepartmentCode") != null){ |
| | | str = getDepartmentStr(department, depart.get().get("parentDepartmentCode").toString()) + str; |
| | | } |
| | | return str; |
| | | } |
| | | |
| | | public String getPassword(String employeeId) { |
| | |
| | | System.out.println(request.execute().body()); |
| | | return JSON.parseObject(request.execute().body()).get("originalPwd").toString(); |
| | | } |
| | | |
| | | public List<JSONObject> getDepartment(String companyId){ |
| | | String accessToken = getAccessToken(); |
| | | HttpRequest request = HttpRequest.get(AuthApi.department.replace("companyId", companyId)) |
| | | .header("Authorization", "Bearer " + accessToken) |
| | | .header("Content-Type", "application/form-data"); |
| | | List<JSONObject> list; |
| | | try { |
| | | list = JSON.parseArray(request.execute().body()); |
| | | }catch (Exception e){ |
| | | throw new ErrorException(e.getMessage()); |
| | | } |
| | | return list.stream().filter(ob->{ |
| | | if(Objects.equals(ob.get("status"), "enabled")) return true; |
| | | return false; |
| | | }).collect(Collectors.toList()); |
| | | } |
| | | |
| | | public Person selectPersonUser(String code){ |
| | | String accessToken = getAccessToken(); |
| | | HttpRequest request = HttpRequest.get(AuthApi.person + code) |
| | | .header("Authorization", "Bearer " + accessToken) |
| | | .header("Content-Type", "application/form-data"); |
| | | Person person; |
| | | try { |
| | | person = JSON.parseObject(request.execute().body(), Person.class); |
| | | if(BeanUtil.isEmpty(person))return null; |
| | | }catch (Exception e){ |
| | | throw new ErrorException(e.getMessage()); |
| | | } |
| | | List<JSONObject> department = getDepartment(person.getCompanyId()); |
| | | person.setDepartment(getDepartmentStr(department, person.getDepartmentCode()).replaceFirst("/", "")); |
| | | person.setIsLive(userMapper.selectCount(Wrappers.<User>lambdaQuery().eq(User::getAccount, person.getEmployeeID()))); |
| | | return person; |
| | | } |
| | | |
| | | } |