From 9443a6b751ad1cbb9efce8c116b6fb8dae7a56b3 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期四, 05 十月 2023 14:26:47 +0800 Subject: [PATCH] 添加对象序列化 --- src/main/java/com/smartearth/poiexcel/service/EntService.java | 23 ++++- src/main/resources/application.properties | 2 src/main/java/com/smartearth/poiexcel/controller/EntController.java | 3 src/main/java/com/smartearth/poiexcel/entity/Result.java | 52 +++++++++++++ src/main/java/com/smartearth/poiexcel/config/InitConfig.java | 15 +++ src/main/java/com/smartearth/poiexcel/entity/TokenResult.java | 139 ++++++++++++++++++++++++++++++++++ 6 files changed, 229 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/smartearth/poiexcel/config/InitConfig.java b/src/main/java/com/smartearth/poiexcel/config/InitConfig.java index 6917ff4..1dc8ce4 100644 --- a/src/main/java/com/smartearth/poiexcel/config/InitConfig.java +++ b/src/main/java/com/smartearth/poiexcel/config/InitConfig.java @@ -1,5 +1,9 @@ package com.smartearth.poiexcel.config; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.smartearth.poiexcel.entity.Result; +import com.smartearth.poiexcel.entity.TokenResult; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.boot.ApplicationArguments; @@ -18,9 +22,20 @@ public void run(ApplicationArguments args) { // noinspection AlibabaRemoveCommentedCode try { + test(); + log.info("***************** 绯荤粺鍚姩瀹屾瘯 *****************" + "\n"); } catch (Exception ex) { log.error(ex.getMessage(), ex); } } + + private void test() { + String json = "{\"success\":true,\"code\":200,\"message\":\"鎴愬姛\",\"data\":{\"ctoken\":\"ZmYxZTgyN2QxZTYyNDMxMDhjZjgzNDNiNDZiN2RjMDVAYTc3ZmFlOGE5ZGM0OGQ1Y2ZmODY4ZTFmNWYwZTEzM2E=\",\"userInfo\":{\"loginLogId\":\"1ab1675c3632428a84dc0ebe579cd66f\",\"phoneNumber\":\"\",\"displayName\":\"鏃剁┖涓�寮犲浘\",\"userMail\":\"\",\"departLevel\":\"5-1\",\"id\":\"ff1e827d1e6243108cf8343b46b7dc05\",\"userID\":\"shikong001\",\"uniqueID\":\"\",\"departName\":\"姹借溅鍜屾櫤鑳藉埗閫犱骇涓氫笓鐝璡"},\"expires\":3600,\"roles\":[]}}"; + Result rs = JSON.parseObject(json, Result.class); + // TokenResult tr = JSON.parseObject(rs.getData().toJSONString(), TokenResult.class) + TokenResult tr = JSONObject.parseObject(rs.getData(), TokenResult.class); + + int len = json.length(); + } } diff --git a/src/main/java/com/smartearth/poiexcel/controller/EntController.java b/src/main/java/com/smartearth/poiexcel/controller/EntController.java index 6057bab..908ae80 100644 --- a/src/main/java/com/smartearth/poiexcel/controller/EntController.java +++ b/src/main/java/com/smartearth/poiexcel/controller/EntController.java @@ -1,6 +1,8 @@ package com.smartearth.poiexcel.controller; import com.smartearth.poiexcel.entity.ResponseMsg; +import com.smartearth.poiexcel.entity.Result; +import com.smartearth.poiexcel.entity.TokenResult; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -25,6 +27,7 @@ @GetMapping({"/selectCount"}) public ResponseMsg<Integer> selectCount(String name) { try { + //Result<TokenResult> rs = new Result<>(); return success(0); diff --git a/src/main/java/com/smartearth/poiexcel/entity/Result.java b/src/main/java/com/smartearth/poiexcel/entity/Result.java new file mode 100644 index 0000000..1ddd128 --- /dev/null +++ b/src/main/java/com/smartearth/poiexcel/entity/Result.java @@ -0,0 +1,52 @@ +package com.smartearth.poiexcel.entity; + +import com.alibaba.fastjson.JSONObject; + +/** + * 缁撴灉绫� + * @author WWW + */ +public class Result { + public Result() { + } + + private Boolean success; + + private Integer code; + + private String message; + + private String data; + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } +} diff --git a/src/main/java/com/smartearth/poiexcel/entity/TokenResult.java b/src/main/java/com/smartearth/poiexcel/entity/TokenResult.java new file mode 100644 index 0000000..1d6f9a8 --- /dev/null +++ b/src/main/java/com/smartearth/poiexcel/entity/TokenResult.java @@ -0,0 +1,139 @@ +package com.smartearth.poiexcel.entity; + +import java.io.Serializable; + +/** + * 浠ょ墝缁撴灉绫� + * @author WWW + */ +public class TokenResult implements Serializable { + private static final long serialVersionUID = -8624235184539814992L; + + private String ctoken; + + private UserInfo userInfo; + + private Integer expires; + + public static class UserInfo { + public UserInfo() { + } + + private String loginLogId; + + private String phoneNumber; + + private String displayName; + + private String userMail; + + private String departLevel; + + private String id; + + private String userID; + + private String uniqueID; + + private String departName; + + public String getLoginLogId() { + return loginLogId; + } + + public void setLoginLogId(String loginLogId) { + this.loginLogId = loginLogId; + } + + public String getPhoneNumber() { + return phoneNumber; + } + + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + public String getDisplayName() { + return displayName; + } + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + public String getUserMail() { + return userMail; + } + + public void setUserMail(String userMail) { + this.userMail = userMail; + } + + public String getDepartLevel() { + return departLevel; + } + + public void setDepartLevel(String departLevel) { + this.departLevel = departLevel; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getUserID() { + return userID; + } + + public void setUserID(String userID) { + this.userID = userID; + } + + public String getUniqueID() { + return uniqueID; + } + + public void setUniqueID(String uniqueID) { + this.uniqueID = uniqueID; + } + + public String getDepartName() { + return departName; + } + + public void setDepartName(String departName) { + this.departName = departName; + } + } + + public TokenResult() { + } + + public String getCtoken() { + return ctoken; + } + + public void setCtoken(String ctoken) { + this.ctoken = ctoken; + } + + public UserInfo getUserInfo() { + return userInfo; + } + + public void setUserInfo(UserInfo userInfo) { + this.userInfo = userInfo; + } + + public Integer getExpires() { + return expires; + } + + public void setExpires(Integer expires) { + this.expires = expires; + } +} diff --git a/src/main/java/com/smartearth/poiexcel/service/EntService.java b/src/main/java/com/smartearth/poiexcel/service/EntService.java index 1cbc6e0..2e66ae3 100644 --- a/src/main/java/com/smartearth/poiexcel/service/EntService.java +++ b/src/main/java/com/smartearth/poiexcel/service/EntService.java @@ -24,8 +24,8 @@ @Resource EntMapper entMapper; - @Value("${qylweb.url}") - String url; + @Value("${qylweb.host}") + String host; @Value("${qylweb.user}") String user; @@ -39,6 +39,21 @@ private final static String getEntBaseInfo = "%s/yqfwg/api/project/getEntBaseInfoForOtherSysListPage?ctoken=%s&buildDate_startdate=%s&buildDate_enddate=%s&qylabel=%s&showCount=%d¤tPage=%d"; + public String getToken() { + try { + String url = String.format(generateToken, host); + + Map<String, String> map = new HashMap<>(2); + map.put("userName", user); + map.put("passWord", pwd); + + return null; + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + return null; + } + } + /** * post璇锋眰锛圧est锛� */ @@ -51,14 +66,14 @@ /** * delete璇锋眰锛圧est锛� */ - public Object deleteForRest(String url, Map<String, Object> map) { + public <T> T deleteForRest(String url, Map<String, T> map, Class<T> clazz) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<?> entity = new HttpEntity<>(map, headers); RestTemplate rest = RestHelper.getRestTemplate(); - ResponseEntity<Object> rs = rest.exchange(url, HttpMethod.DELETE, entity, Object.class); + ResponseEntity<T> rs = rest.exchange(url, HttpMethod.DELETE, entity, clazz); return rs.getBody(); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 9f34537..bb5afb2 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -18,6 +18,6 @@ mybatis-plus.config-location=classpath:mybatis.xml mybatis-plus.mapper-locations=classpath:mapper/**/*.xml -qylweb.url=https://qylweb.bda.gov.cn +qylweb.host=https://qylweb.bda.gov.cn qylweb.user=shikong001 qylweb.pwd=123!@#qwe -- Gitblit v1.9.3