|
|
|
@ -3,35 +3,57 @@ package com.glxp.udi.admin.controller.info;
|
|
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
|
|
import com.glxp.udi.admin.annotation.AuthRuleAnnotation;
|
|
|
|
|
import com.glxp.udi.admin.entity.info.PlatformEntity;
|
|
|
|
|
import com.glxp.udi.admin.entity.inout.UnitMaintainEntity;
|
|
|
|
|
import com.glxp.udi.admin.exception.JsonException;
|
|
|
|
|
import com.glxp.udi.admin.res.PageSimpleResponse;
|
|
|
|
|
import com.glxp.udi.admin.service.info.PlatformService;
|
|
|
|
|
import com.glxp.udi.admin.service.inout.UnitMaintainService;
|
|
|
|
|
import com.glxp.udi.admin.util.UuidUtils;
|
|
|
|
|
import com.glxp.udi.common.enums.ResultEnum;
|
|
|
|
|
import com.glxp.udi.common.res.BaseResponse;
|
|
|
|
|
import com.glxp.udi.common.util.ResultVOUtils;
|
|
|
|
|
|
|
|
|
|
import org.springframework.http.converter.StringHttpMessageConverter;
|
|
|
|
|
import org.springframework.util.MultiValueMap;
|
|
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
import org.springframework.validation.BindingResult;
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
|
import org.springframework.http.HttpEntity;
|
|
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
|
|
import org.springframework.http.HttpMethod;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import okhttp3.OkHttpClient;
|
|
|
|
|
import okhttp3.Request;
|
|
|
|
|
import okhttp3.Response;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.validation.Valid;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.nio.charset.Charset;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import com.glxp.udi.admin.util.HttpClient;
|
|
|
|
|
@RestController
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class PlatformController {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private PlatformService platformService;
|
|
|
|
|
@Resource
|
|
|
|
|
private UnitMaintainService unitMaintainService;
|
|
|
|
|
|
|
|
|
|
@AuthRuleAnnotation("")
|
|
|
|
|
@PostMapping("/udims/platform/remove")
|
|
|
|
@ -66,5 +88,48 @@ public class PlatformController {
|
|
|
|
|
return ResultVOUtils.success(pageSimpleResponse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@AuthRuleAnnotation("")
|
|
|
|
|
@PostMapping("/udims/platform/link")
|
|
|
|
|
public BaseResponse update(@RequestBody UnitMaintainEntity unitMaintainEntity) {
|
|
|
|
|
PlatformEntity platformEntity = platformService.get(unitMaintainEntity.getPlatformId());
|
|
|
|
|
if(platformEntity!=null) {
|
|
|
|
|
String url = platformEntity.getHost()+"/verify";
|
|
|
|
|
|
|
|
|
|
Map<String, Object> map = new HashMap<String,Object>();
|
|
|
|
|
map.put("username",unitMaintainEntity.getPlatformUsername());
|
|
|
|
|
map.put("password",unitMaintainEntity.getPlatformPassword());
|
|
|
|
|
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
|
|
|
|
|
|
|
|
|
|
HttpEntity<String> request = new HttpEntity<String>(JSON.toJSONString(map),headers);
|
|
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
log.error(url);
|
|
|
|
|
|
|
|
|
|
String result = restTemplate.postForObject(url, request, String.class, map);
|
|
|
|
|
log.error(result);
|
|
|
|
|
Map<String,Object> object = JSON.parseObject(result,Map.class);
|
|
|
|
|
|
|
|
|
|
if(object!=null&&object.get("data")!=null&&data.get("appid")!=null) {
|
|
|
|
|
Map<String,Object> data = JSON.parseObject(JSON.toJSONString(object.get("data")),Map.class);
|
|
|
|
|
log.error(JSON.toJSONString(object.get("data")));
|
|
|
|
|
if(data.get("appid")!=null)
|
|
|
|
|
unitMaintainEntity.setAppid(data.get("appid").toString());
|
|
|
|
|
if(data.get("apiKey")!=null)
|
|
|
|
|
unitMaintainEntity.setAppid(data.get("apiKey").toString());
|
|
|
|
|
if(data.get("secretKey")!=null)
|
|
|
|
|
unitMaintainEntity.setSecretKey(data.get("secretKey").toString());
|
|
|
|
|
} else if(object!=null&&object.get("message")!=null){
|
|
|
|
|
return ResultVOUtils.error(500, object.get("message").toString());
|
|
|
|
|
} else {
|
|
|
|
|
return ResultVOUtils.error(500, "关联失败,请联系管理人员");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
return ResultVOUtils.error(500, "未查询到平台信息");
|
|
|
|
|
}
|
|
|
|
|
unitMaintainService.updateUnit(unitMaintainEntity);
|
|
|
|
|
return ResultVOUtils.success("关联成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|