Commit 8bb40134 authored by 梁光意's avatar 梁光意

优化配置类

parent eebd96b3
package com.syc.slm.slmbi.config;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
/**
* @author: guangyi-liang
* @date: 2021/5/7
*/
public final class DataCenterConfig {
@Configuration
@Data
public class DataCenterConfig {
@Value("${dc_client.host}")
public static String dcClientHost;
private String dcClientHost;
@Value("${dc_client.interfaces.permissionCodeUrl}")
public static String permissionCodeUrl;
private String permissionCodeUrl;
@Value("${dc_client.interfaces.companyAppId}")
public static String companyAppId;
private String companyAppId;
@Value("${dc_client.interfaces.positionListUrl}")
public static String positionListUrl;
private String positionListUrl;
@Value("${dc_client.interfaces.deptListUrl}")
public static String deptListUrl;
private String deptListUrl;
@Value("${dc_client.interfaces.userTree}")
public static String userTree;
private String userTree;
@Value("${dc_client.interfaces.variableList}")
public static String variableList;
private String variableList;
@Value("${dc_client.interfaces.deviceList}")
public static String deviceList;
private String deviceList;
@Value("${dc_client.interfaces.deptsRoles}")
public static String deptsRoles;
private String deptsRoles;
@Value("${dc_client.interfaces.businessFiledData}")
public static String businessFiledData;
private String businessFiledData;
@Value("${dc_client.interfaces.businessDataFieldStatistics}")
public static String businessDataFieldStatistics;
private String businessDataFieldStatistics;
@Value("${dc_client.interfaces.variableCodeHistoryList}")
public static String variableHistoryDataList;
private String variableHistoryDataList;
@Value("${dc_client.interfaces.variableAllDataList}")
public static String variableRealTimeDataList;
private String variableRealTimeDataList;
@Value("${dc_client.interfaces.filedValue}")
public static String filedValue;
private String filedValue;
@Value("${dc_client.interfaces.send}")
public static String send;
private String send;
@Value("${dc_client.interfaces.variableStatus}")
public static String variableStatus;
private String variableStatus;
@Value("${dc_client.interfaces.variableHistoryStatus}")
public static String variableHistoryStatus;
private String variableHistoryStatus;
@Value("${dc_client.interfaces.realTimeVariableDataList}")
public static String realTimeVariableDataList;
private String realTimeVariableDataList;
@Value("${dc_client.interfaces.variableStatusRealTimeDataList}")
public static String variableStatusRealTimeDataList;
private String variableStatusRealTimeDataList;
}
......@@ -12,6 +12,7 @@ import com.syc.slm.slmbi.exception.SysException;
import com.syc.slm.slmbi.function.Action0;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.context.request.RequestAttributes;
......@@ -33,6 +34,9 @@ import java.util.function.Supplier;
@Slf4j
public class BaseRestController {
@Autowired
private DataCenterConfig dataCenterConfig;
@ModelAttribute
public void onInit(HttpServletRequest request) {
String uri = request.getRequestURI();
......@@ -59,7 +63,7 @@ public class BaseRestController {
Map<String, String> map = (Map<String, String>) webRequest.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
Map<String,String> uriVariables =Maps.newHashMap();
uriVariables.put("appId",map.get("appId")+"");
String getUrl = DataCenterConfig.dcClientHost + "/{appId}/users/user-info";
String getUrl = dataCenterConfig.getDcClientHost() + "/{appId}/users/user-info";
R<CurrentUser> result = RestTemplateUtils.get(getUrl, new TypeToken<R<CurrentUser>>() {
}.getType(), uriVariables);
request.setAttribute(token,SlmConstants.gson.toJson(result.detach()));
......
......@@ -34,6 +34,9 @@ public class DeptController extends BaseRestController{
@Autowired
private DeptService deptService;
@Autowired
private DataCenterConfig dataCenterConfig;
@GetMapping
@ApiOperation("部门查询")
@ApiImplicitParams({@ApiImplicitParam(name = "deptName", value = "部门名称",dataTypeClass = String.class),
......@@ -45,16 +48,4 @@ public class DeptController extends BaseRestController{
return deptService.selectPositionList( currentUser.getToken(), appId, deptName);
});
}
@GetMapping("/base")
@ApiOperation("部门查询")
public R<List<DeptVo>> base(HttpServletRequest request, @PathVariable String appId) {
return call(() -> {
Map<String,String> uriVariables = Maps.newHashMap();
uriVariables.put("appId",appId);
String uri = DataCenterConfig.dcClientHost + "/{appId}/base";
RestTemplateUtils.get(uri, new TypeToken<R<List<DeptVo>>>() {}.getType(),uriVariables );
return null;
});
}
}
......@@ -10,6 +10,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -27,6 +28,9 @@ import java.util.Map;
@RequestMapping("/tokens")
@Api(value ="获取token",tags = "获取token")
public class TokenController extends BaseRestController{
@Autowired
private DataCenterConfig dataCenterConfig;
@PostMapping
@ApiOperation("获取token")
@ApiImplicitParams({
......@@ -37,7 +41,7 @@ public class TokenController extends BaseRestController{
public R<Map<String,Object>> token(String account,String password,Integer origin){
return call(()->{
Map<String ,Object> maps = Maps.newHashMap();
String uri = DataCenterConfig.dcClientHost + "/user/token?account=" + account + "&password=" + password + "&origin=" + origin;
String uri = dataCenterConfig.getDcClientHost() + "/user/token?account=" + account + "&password=" + password + "&origin=" + origin;
ResponseEntity<Map> post = RestTemplateUtils.post(uri, Map.class);
if(ObjectUtils.isNotEmpty(post)){
Integer code = (int)post.getBody().get("code");
......
......@@ -25,6 +25,7 @@ import com.syc.slm.slmbi.enums.Condition;
import com.syc.slm.slmbi.exception.SysException;
import com.syc.slm.slmbi.service.BusinessConfigService;
import com.syc.slm.slmbi.vo.BusinessConfigVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -43,6 +44,10 @@ import java.util.stream.Collectors;
**/
@Service
public class BusinessConfigServiceImpl extends ServiceImpl<BusinessConfigMapper, BusinessConfig> implements BusinessConfigService {
@Autowired
private DataCenterConfig dataCenterConfig;
@Override
@Transactional(readOnly = true)
public List<BusinessConfigVo> selectConfigList() {
......@@ -125,7 +130,7 @@ public class BusinessConfigServiceImpl extends ServiceImpl<BusinessConfigMapper,
dto.setWhere(this.filterWhereNoLimit(dto.getWhere()));
Map<String, String> uriVariables = Maps.newHashMap();
uriVariables.put("appId", user.getAppId());
String uri= DataCenterConfig.dcClientHost + DataCenterConfig. businessFiledData;
String uri= dataCenterConfig.getDcClientHost() + dataCenterConfig.getBusinessFiledData();
R<Map<String,List<Object>>> result = RestTemplateUtils.post(uri, null,dto, new TypeToken<R<Map<String,List<Object>>>>() {}.getType(), uriVariables);
return result.detach();
}
......@@ -166,7 +171,7 @@ public class BusinessConfigServiceImpl extends ServiceImpl<BusinessConfigMapper,
dto.setWhere(this.filterWhereNoLimit(dto.getWhere()));
Map<String, String> uriVariables = Maps.newHashMap();
uriVariables.put("appId", user.getAppId());
String uri =DataCenterConfig.dcClientHost+DataCenterConfig.businessDataFieldStatistics;
String uri =dataCenterConfig.getDcClientHost()+dataCenterConfig.getBusinessDataFieldStatistics();
R<Map<String,Object>> result = RestTemplateUtils.post(uri, null,dto, new TypeToken<R<Map<String,Object>>>() {}.getType(), uriVariables);
return result.detach();
}
......@@ -188,7 +193,7 @@ public class BusinessConfigServiceImpl extends ServiceImpl<BusinessConfigMapper,
uriVariables.put("size", size);
uriVariables.put("name", name);
IPage<String> page = new Page<>(current,size);
String uri =DataCenterConfig.dcClientHost+DataCenterConfig.filedValue;
String uri = dataCenterConfig.getDcClientHost()+dataCenterConfig.getFiledValue();
R<Map<String,Object>> result = RestTemplateUtils.get(uri, new TypeToken<R<Map<String,Object>>>() {}.getType(), uriVariables);
Map<String, Object> resultMaps = result.detach();
if(CollectionUtils.isNotEmpty(resultMaps)){
......
......@@ -35,6 +35,9 @@ public class CompanyServiceImpl implements CompanyService {
@Autowired
private InstrumentPanelTreeInitMapper treeInitMapper;
@Autowired
private DataCenterConfig dataCenterConfig;
@Override
public Set<String> findAll(String appId) {
return this.findAllAppId(appId);
......@@ -62,7 +65,7 @@ public class CompanyServiceImpl implements CompanyService {
private Set<String> findAllAppId(String appId){
Map<String,String> map = Maps.newHashMap();
map.put("appId",appId);
R<Set<String>> result = RestTemplateUtils.get(DataCenterConfig.dcClientHost+DataCenterConfig.companyAppId, new TypeToken<R<Set<String>>>() {}.getType(),map);
R<Set<String>> result = RestTemplateUtils.get(dataCenterConfig.getDcClientHost()+dataCenterConfig.getCompanyAppId(), new TypeToken<R<Set<String>>>() {}.getType(),map);
return result.detach();
}
......
......@@ -8,6 +8,7 @@ import com.syc.slm.slmbi.config.DataCenterConfig;
import com.syc.slm.slmbi.service.DeptService;
import com.syc.slm.slmbi.vo.DeptVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
......@@ -24,6 +25,8 @@ import java.util.Map;
@Slf4j
public class DeptServiceImpl implements DeptService {
@Autowired
private DataCenterConfig dataCenterConfig;
@Override
public List<DeptVo> selectPositionList(String token, String appId, String deptName) {
......@@ -32,7 +35,7 @@ public class DeptServiceImpl implements DeptService {
uriVariables.put("deptName",deptName);
uriVariables.put("appId",appId);
String uri = DataCenterConfig.dcClientHost + DataCenterConfig.deptListUrl;
String uri = dataCenterConfig.getDcClientHost() + dataCenterConfig.getDeptListUrl();
R<List<DeptVo>> result = RestTemplateUtils.get(uri, new TypeToken<R<List<DeptVo>>>() {}.getType(), uriVariables);
return result.detach();
}
......
......@@ -52,6 +52,10 @@ public class InstrumentPanelTreeServiceImpl extends ServiceImpl<InstrumentPanelT
@Autowired
private InstrumentPanelService panelService;
@Autowired
private DataCenterConfig dataCenterConfig;
@Override
public void batchUpdateTreeByIds(Set<String> treeIds, Integer recordStatus) {
if (CollectionUtils.isNotEmpty(treeIds)) {
......@@ -424,7 +428,7 @@ public class InstrumentPanelTreeServiceImpl extends ServiceImpl<InstrumentPanelT
private R<Map<String,String>> setDeptAndRole(CurrentUser user){
Map<String,String> uriVariables =Maps.newHashMap();
uriVariables.put("appId",user.getAppId());
String uri = DataCenterConfig.dcClientHost + DataCenterConfig.deptsRoles;
String uri = dataCenterConfig.getDcClientHost() + dataCenterConfig.getDeptsRoles();
return RestTemplateUtils.get(uri, new TypeToken<R<Map<String,String>>>() {}.getType(), uriVariables);
}
......
......@@ -7,6 +7,7 @@ import com.syc.slm.common.core.util.RestTemplateUtils;
import com.syc.slm.slmbi.config.DataCenterConfig;
import com.syc.slm.slmbi.service.PermissionService;
import com.syc.slm.slmbi.vo.PermissionCodeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
......@@ -19,12 +20,14 @@ import java.util.Map;
@Service
public class PermissionServiceImpl implements PermissionService {
@Autowired
private DataCenterConfig dataCenterConfig;
@Override
public List<PermissionCodeVo> findAllPermissionCode(String appId, String token) {
Map<String, String> uriVariables = Maps.newHashMap();
uriVariables.put("appId",appId);
R<List<PermissionCodeVo>> result = RestTemplateUtils.get(DataCenterConfig.dcClientHost+DataCenterConfig.permissionCodeUrl, new TypeToken<R<List<PermissionCodeVo>>>() {}.getType(), uriVariables);
R<List<PermissionCodeVo>> result = RestTemplateUtils.get(dataCenterConfig.getDcClientHost()+dataCenterConfig.getPermissionCodeUrl(), new TypeToken<R<List<PermissionCodeVo>>>() {}.getType(), uriVariables);
return result.detach();
}
}
......@@ -7,6 +7,7 @@ import com.syc.slm.common.core.util.RestTemplateUtils;
import com.syc.slm.slmbi.config.DataCenterConfig;
import com.syc.slm.slmbi.service.PositionService;
import com.syc.slm.slmbi.vo.PositionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
......@@ -22,13 +23,16 @@ import java.util.Map;
@Service
public class PositionServiceImpl implements PositionService {
@Autowired
private DataCenterConfig dataCenterConfig;
@Override
public List<PositionVo> selectPositionList(String token,String appId,String name) {
Map<String,String> uriVariables =Maps.newHashMap();
uriVariables.put("positionName",name);
uriVariables.put("appId",appId);
String uri = DataCenterConfig.dcClientHost + DataCenterConfig.positionListUrl;
String uri = dataCenterConfig.getDcClientHost() + dataCenterConfig.getPositionListUrl();
R<List<PositionVo>> result = RestTemplateUtils.get(uri, new TypeToken<R<List<PositionVo>>>() {}.getType(), uriVariables);
return result.detach();
}
......
......@@ -7,6 +7,7 @@ import com.syc.slm.common.core.util.RestTemplateUtils;
import com.syc.slm.slmbi.config.DataCenterConfig;
import com.syc.slm.slmbi.service.UserService;
import com.syc.slm.slmbi.vo.UserTreeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
......@@ -21,12 +22,15 @@ import java.util.Map;
**/
@Service
public class UserServiceImpl implements UserService {
@Autowired
private DataCenterConfig dataCenterConfig;
@Override
public List<UserTreeVo> selectUserList(String appId,String token,String userName) {
Map<String,String> uriVariables =Maps.newHashMap();
uriVariables.put("userName",userName);
uriVariables.put("appId",appId);
String uri = DataCenterConfig.dcClientHost + DataCenterConfig.userTree;
String uri = dataCenterConfig.getDcClientHost() + dataCenterConfig.getUserTree();
R<List<UserTreeVo>> result = RestTemplateUtils.get(uri,new TypeToken<R<List<UserTreeVo>>>() {}.getType(), uriVariables);
return result.detach();
}
......
......@@ -21,6 +21,7 @@ import com.syc.slm.slmbi.service.VariableService;
import com.syc.slm.slmbi.vo.VariableDeviceVo;
import com.syc.slm.slmbi.vo.VariableSourceVo;
import com.syc.slm.slmbi.vo.VariableVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -38,6 +39,10 @@ import java.util.stream.Collectors;
**/
@Service
public class VariableServiceImpl implements VariableService {
@Autowired
private DataCenterConfig dataCenterConfig;
@Override
public IPage<VariableVo> getVariableList(VariableDTO variableDTO,String appId,String token) {
IPage<VariableVo> page = new Page<>(variableDTO.getCurrent(),variableDTO.getSize());
......@@ -57,7 +62,7 @@ public class VariableServiceImpl implements VariableService {
p.put("current",variableDTO.getCurrent()+"");
p.put("size",variableDTO.getSize()+"");
String uri = DataCenterConfig.dcClientHost + DataCenterConfig.variableList;
String uri = dataCenterConfig.getDcClientHost() + dataCenterConfig.getVariableList();
R<Map<String, Object>> result = RestTemplateUtils.get(uri, new TypeToken<R<Map<String, Object>>>() {
}.getType(), p);
Map<String, Object> detach = result.detach();
......@@ -106,7 +111,7 @@ public class VariableServiceImpl implements VariableService {
p.put("warranty_status", null);
p.put("page_num", queryPageDTO.getCurrent() + "");
p.put("page_size", queryPageDTO.getSize() + "");
String uri =DataCenterConfig.dcClientHost+DataCenterConfig.deviceList;
String uri =dataCenterConfig.getDcClientHost()+dataCenterConfig.getDeviceList();
R<Map<String, Object>> result = RestTemplateUtils.get(uri, new TypeToken<R<Map<String, Object>>>() {
}.getType(), p);
Map<String, Object> detach = result.detach();
......@@ -147,7 +152,7 @@ public class VariableServiceImpl implements VariableService {
// Map<String, String> uriVariables =SlmConstants.gson.fromJson(SlmConstants.gson.toJson(variableDTO),new TypeToken<Map<String,String>>(){}.getType());
Map<String, String> uriVariables = Maps.newHashMap();
uriVariables.put("appId",user.getAppId());
String uri =DataCenterConfig.dcClientHost + DataCenterConfig.variableRealTimeDataList;
String uri =dataCenterConfig.getDcClientHost() + dataCenterConfig.getVariableRealTimeDataList();
R<Map<String,List<Object>>> result = RestTemplateUtils.post(uri,variableDTO,new TypeToken<R<Map<String,List<Object>>>>() {}.getType(), uriVariables);
return result.detach();
}
......@@ -194,7 +199,7 @@ public class VariableServiceImpl implements VariableService {
Map<String, String> uriVariables = Maps.newHashMap();
uriVariables.put("appId",user.getAppId());
String uri =DataCenterConfig.dcClientHost + DataCenterConfig.variableHistoryDataList;
String uri =dataCenterConfig.getDcClientHost() + dataCenterConfig.getVariableHistoryDataList();
R<Map<String,Object>> result = RestTemplateUtils.post(uri,variableDTO,new TypeToken<R<Map<String,Object>>>() {}.getType(), uriVariables);
return result.detach();
}
......@@ -231,7 +236,7 @@ public class VariableServiceImpl implements VariableService {
}
if (CollectionUtils.isNotEmpty(departments) || CollectionUtils.isNotEmpty(positions)) {
R<Map<String, String>> result = setDeptAndRole(currentUser, DataCenterConfig.dcClientHost+DataCenterConfig.deptsRoles);
R<Map<String, String>> result = setDeptAndRole(currentUser, dataCenterConfig.getDcClientHost()+dataCenterConfig.getDeptsRoles());
Map<String, String> detach = result.detach();
String officeIds = detach.get("deptIds");
String roleIds = detach.get("roleIds");
......@@ -274,7 +279,7 @@ public class VariableServiceImpl implements VariableService {
dto.setAppId(currentUser.getAppId());
Map<String, String> uriVariables = Maps.newHashMap();
uriVariables.put("appId", currentUser.getAppId());
String uri = DataCenterConfig.dcClientHost + DataCenterConfig.send;
String uri = dataCenterConfig.getDcClientHost() + dataCenterConfig.getSend();
R<Object> result = RestTemplateUtils.post(uri, null, dto, new TypeToken<R<Object>>() {}.getType(), uriVariables);
result.detach();
......@@ -294,7 +299,7 @@ public class VariableServiceImpl implements VariableService {
uriVariables.put("deviceId",deviceId);
uriVariables.put("variableId",variableId);
uriVariables.put("variableCode",variableCode);
String uri =DataCenterConfig.dcClientHost + DataCenterConfig.variableStatus;
String uri =dataCenterConfig.getDcClientHost() + dataCenterConfig.getVariableStatus();
R<Map<String,Object>> result = RestTemplateUtils.get(uri,new TypeToken<R<Map<String,Object>>>() {}.getType(), uriVariables);
return result.detach();
}
......@@ -328,7 +333,7 @@ public class VariableServiceImpl implements VariableService {
uriVariables.put("variableCode",variableCode);
uriVariables.put("startTime",startTime);
uriVariables.put("endTime",endTime);
String uri =DataCenterConfig.dcClientHost+DataCenterConfig.variableHistoryStatus;
String uri =dataCenterConfig.getDcClientHost()+dataCenterConfig.getVariableHistoryStatus();
R<Map<String,Object>> result = RestTemplateUtils.get(uri,new TypeToken<R<Map<String,Object>>>() {}.getType(), uriVariables);
return result.detach();
}
......@@ -338,7 +343,7 @@ public class VariableServiceImpl implements VariableService {
this.judgeSearchList(variableDTO.getVariableSearchList());
Map<String, String> uriVariables = Maps.newHashMap();
uriVariables.put("appId",user.getAppId());
String uri =DataCenterConfig.dcClientHost+DataCenterConfig.realTimeVariableDataList;
String uri =dataCenterConfig.getDcClientHost()+dataCenterConfig.getRealTimeVariableDataList();
R<Map<String,List<Object>>> result = RestTemplateUtils.post(uri,variableDTO,new TypeToken<R<Map<String,List<Object>>>>() {}.getType(), uriVariables);
return result.detach();
}
......@@ -360,7 +365,7 @@ public class VariableServiceImpl implements VariableService {
}
Map<String, String> uriVariables = Maps.newHashMap();
uriVariables.put("appId",user.getAppId());
String uri =DataCenterConfig.dcClientHost+DataCenterConfig.variableStatusRealTimeDataList;
String uri =dataCenterConfig.getDcClientHost()+dataCenterConfig.getVariableStatusRealTimeDataList();
R<Map<String, Map<String, Object>>> result = RestTemplateUtils.post(uri,statusRealTimeDataList,new TypeToken<R<Map<String, Map<String, Object>>>>() {}.getType(), uriVariables);
return result.detach();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment