package com.newfiber.api.pc.service.impl; import com.newfiber.api.config.UrlConfig; import com.newfiber.api.pc.model.UserManager.Data_User_Info; import com.newfiber.api.pc.model.UserManager.SysOrganization; import com.newfiber.api.pc.model.UserManager.Sys_Roles; import com.newfiber.api.pc.model.UserManager.UserInfo; import com.newfiber.api.pc.model.Users; import com.newfiber.api.pc.service.RestTemplateService; import java.util.Arrays; import java.util.List; import javax.annotation.Resource; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.stereotype.Service; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; @Service public class RestTemplateServiceImpl implements RestTemplateService { @Resource private UrlConfig urlConfig; @Resource private RestTemplate restTemplate; @Override public Data_User_Info getUserInfo(String userNo) { MultiValueMap<String, Object> postParameters = new LinkedMultiValueMap<>(); postParameters.add("userNo", userNo); HttpHeaders headers = new HttpHeaders(); headers.add("Content-Type", "application/x-www-form-urlencoded"); HttpEntity<MultiValueMap<String, Object>> r = new HttpEntity<>(postParameters, headers); return restTemplate.postForEntity(getUrl(GET_USER_INFO), r, Data_User_Info.class).getBody(); } @Override public List<Users> getSystemManager() { return Users.getSystemManagerUser(); } @Override public List<Users> getSystemManagerByUserNo(String userNo) { return Users.getSystemManagerUser(); } @Override public SysOrganization getOrgByUserNo(String userNo) { MultiValueMap<String, Object> postParameters = new LinkedMultiValueMap<>(); postParameters.add("userNo", userNo); HttpHeaders headers = new HttpHeaders(); headers.add("Content-Type", "application/x-www-form-urlencoded"); HttpEntity<MultiValueMap<String, Object>> r = new HttpEntity<>(postParameters, headers); return restTemplate.postForEntity(getUrl(GET_USER_ORG), r, SysOrganization.class).getBody(); } @Override public List<Sys_Roles> selectRoleList() { Sys_Roles[] rolesList = restTemplate.postForEntity(getUrl(GET_ALL_ROLE), null, Sys_Roles[].class).getBody(); return Arrays.asList(rolesList); } @Override public Sys_Roles selectRoleByOrgNo(String orgNo) { MultiValueMap<String, Object> postParameters = new LinkedMultiValueMap<>(); postParameters.add("orgNo", orgNo); HttpHeaders headers = new HttpHeaders(); headers.add("Content-Type", "application/x-www-form-urlencoded"); HttpEntity<MultiValueMap<String, Object>> r = new HttpEntity<>(postParameters, headers); return restTemplate.postForEntity(getUrl(GET_ROLE_BY_ORG), r, Sys_Roles.class).getBody(); } @Override public List<Data_User_Info> getUsetList() { Data_User_Info[] userInfos = restTemplate.postForEntity(getUrl(GET_USER_LIST), null, Data_User_Info[].class).getBody(); return Arrays.asList(userInfos); } @Override public List<UserInfo> listByOrgNo(String orgNo) { UserInfo[] users = restTemplate.postForEntity(getUrl(LIST_BY_ORG_NO).concat("/").concat(orgNo), null, UserInfo[].class).getBody(); return Arrays.asList(users); } private String getUrl(String path){ return urlConfig.getHuludaoMainUrl().concat(path); } }