Compare commits
15 Commits
1.0.18
...
1.0.24-tes
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1d2cabb048 | ||
|
|
b4334f4a5b | ||
|
|
ce44e4a05a | ||
|
|
a7024f7a8d | ||
|
|
c2fe494ed9 | ||
|
|
07de3f6ba7 | ||
|
|
1c521e5378 | ||
|
|
e98e98d659 | ||
|
|
75d052bd0c | ||
|
|
3758826987 | ||
|
|
8a4cf8e439 | ||
|
|
09203ac78d | ||
|
|
ef5861327c | ||
|
|
23faaa8f67 | ||
|
|
341c82e0bc |
20
pom.xml
20
pom.xml
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>1.0.18</version>
|
||||
<version>1.0.24-test3</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>springboot-parent</name>
|
||||
<description>杭州铁晟科技有限公司基础依赖</description>
|
||||
@@ -57,55 +57,55 @@
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-database</artifactId>
|
||||
<version>1.0.18</version>
|
||||
<version>1.0.24-test3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-login</artifactId>
|
||||
<version>1.0.18</version>
|
||||
<version>1.0.24-test3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-web</artifactId>
|
||||
<version>1.0.18</version>
|
||||
<version>1.0.24-test3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-util</artifactId>
|
||||
<version>1.0.18</version>
|
||||
<version>1.0.24-test3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-platform</artifactId>
|
||||
<version>1.0.18</version>
|
||||
<version>1.0.24-test3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-message</artifactId>
|
||||
<version>1.0.18</version>
|
||||
<version>1.0.24-test3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-encrypt</artifactId>
|
||||
<version>1.0.18</version>
|
||||
<version>1.0.24-test3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-annotation</artifactId>
|
||||
<version>1.0.18</version>
|
||||
<version>1.0.24-test3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-poi</artifactId>
|
||||
<version>1.0.18</version>
|
||||
<version>1.0.24-test3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>1.0.18</version>
|
||||
<version>1.0.24-test3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-ademo</artifactId>
|
||||
<version>1.0.18</version>
|
||||
<version>1.0.24-test3</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>1.0.18</version>
|
||||
<version>1.0.24-test3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-annotation</artifactId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>1.0.18</version>
|
||||
<version>1.0.24-test3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-database</artifactId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>1.0.18</version>
|
||||
<version>1.0.24-test3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-encrypt</artifactId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>1.0.18</version>
|
||||
<version>1.0.24-test3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-login</artifactId>
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.tiesheng.login.service.TieshengLoginConfigurer;
|
||||
import com.tiesheng.platform.config.ding.PlatformDingConfig;
|
||||
import com.tiesheng.platform.config.ding.bean.DingJsapiSignature;
|
||||
import com.tiesheng.platform.config.ding.bean.DingUserInfo;
|
||||
import com.tiesheng.platform.config.ding.bean.DingUserSimple;
|
||||
import com.tiesheng.platform.config.wxmini.PlatformWxminiConfig;
|
||||
import com.tiesheng.platform.config.wxmp.PlatformWxmpConfig;
|
||||
import com.tiesheng.platform.config.wxmp.bean.WxConfigBean;
|
||||
@@ -85,7 +86,7 @@ public class LoginController {
|
||||
public ApiResp<String> uniqueIndex(@RequestBody UniqueIndexDTO dto) {
|
||||
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo("web_unique_index",
|
||||
dto.getNo(), dto.getPlatform(), dto.getInfo()));
|
||||
if (tokenBean == null) {
|
||||
if (tokenBean == null || StrUtil.isEmpty(tokenBean.getId())) {
|
||||
throw new ApiException("登录失败");
|
||||
}
|
||||
return ApiResp.respOK(tokenBean.toToken());
|
||||
@@ -131,8 +132,8 @@ public class LoginController {
|
||||
@RequestMapping("/ding/oauth2/{service}")
|
||||
@OperationIgnore
|
||||
public void dingOauth2(@PathVariable String service, CodeExtraDTO dto, HttpServletResponse response) {
|
||||
String ddUserId = platformDingConfig.getUserIdByCode(service, dto.getCode());
|
||||
DingUserInfo dingUserInfo = platformDingConfig.topapiV2UserGet(service, ddUserId);
|
||||
DingUserSimple userSimple = platformDingConfig.getUserIdByCode(service, dto.getCode());
|
||||
DingUserInfo dingUserInfo = platformDingConfig.topapiV2UserGet(service, userSimple.getUserid());
|
||||
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo(dingUserInfo.getAppId(),
|
||||
dingUserInfo.getUserid(), "ding", JSON.toJSONString(dingUserInfo)));
|
||||
tieshengLoginConfigurer.onLoginRedirect(tokenBean, dto.getTo(), dto.getExtra(), response);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>1.0.18</version>
|
||||
<version>1.0.24-test3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-message</artifactId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>1.0.18</version>
|
||||
<version>1.0.24-test3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-platform</artifactId>
|
||||
|
||||
@@ -56,7 +56,7 @@ public class PlatformDingConfig {
|
||||
* @param service
|
||||
* @return
|
||||
*/
|
||||
public String doRequest(String service, String url, JSONObject body) {
|
||||
public <T> DingResponse<T> doRequest(String service, String url, JSONObject body, TypeReference<DingResponse<T>> typeReference) {
|
||||
if (StrUtil.contains(url, "?")) {
|
||||
url = url + "&access_token=" + getAccessToken(service);
|
||||
} else {
|
||||
@@ -70,12 +70,15 @@ public class PlatformDingConfig {
|
||||
execute = HttpUtil.createPost(url).body(body.toString()).execute();
|
||||
}
|
||||
|
||||
String resp = execute.body();
|
||||
if (execute.isOk()) {
|
||||
return resp;
|
||||
DingResponse<T> bean = JSONUtil.toBean(execute.body(), typeReference, true);
|
||||
if (!bean.isOk()) {
|
||||
LogFactory.get().info(bean.getErrmsg());
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
LogFactory.get().info("{}: {}", url, resp);
|
||||
return "";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -119,13 +122,15 @@ public class PlatformDingConfig {
|
||||
DingConfigBean dingConfigBean = getConfigBean(service);
|
||||
String jsapiTicket = TimedCacheHelper.getTimedCache().get(CACHE_JSAPI_TICKET + dingConfigBean.getAppKey(), false);
|
||||
if (StrUtil.isEmpty(jsapiTicket)) {
|
||||
String response = doRequest(service, "https://oapi.dingtalk.com/get_jsapi_ticket", null);
|
||||
JSONObject respJson = JSONUtil.parseObj(response);
|
||||
if (!Objects.equals(respJson.getStr("errcode"), "0")) {
|
||||
throw new ApiException(respJson.getStr("errmsg"));
|
||||
DingResponse<String> respJson = doRequest(service, "https://oapi.dingtalk.com/get_jsapi_ticket", null,
|
||||
new TypeReference<DingResponse<String>>() {
|
||||
});
|
||||
if (!respJson.isOk()) {
|
||||
throw new ApiException(respJson.getErrmsg());
|
||||
}
|
||||
jsapiTicket = respJson.getStr("ticket");
|
||||
TimedCacheHelper.getTimedCache().put(CACHE_JSAPI_TICKET + dingConfigBean.getAppKey(), jsapiTicket, respJson.getLong("expires_in"));
|
||||
jsapiTicket = respJson.getTicket();
|
||||
TimedCacheHelper.getTimedCache().put(CACHE_JSAPI_TICKET + dingConfigBean.getAppKey(),
|
||||
jsapiTicket, respJson.getExpiresIn());
|
||||
}
|
||||
return jsapiTicket;
|
||||
}
|
||||
@@ -154,10 +159,11 @@ public class PlatformDingConfig {
|
||||
* @return
|
||||
* @see <a href="https://open.dingtalk.com/document/isvapp-server/obtain-the-userid-of-a-user-by-using-the-log-free"></a>
|
||||
*/
|
||||
public String getUserIdByCode(String service, String code) {
|
||||
String resp = doRequest(service, "https://oapi.dingtalk.com/topapi/v2/user/getuserinfo",
|
||||
JSONUtil.createObj().putOpt("code", code));
|
||||
return JSONUtil.parseObj(resp).getJSONObject("result").getStr("userid");
|
||||
public DingUserSimple getUserIdByCode(String service, String code) {
|
||||
DingResponse<DingUserSimple> resp = doRequest(service, "https://oapi.dingtalk.com/topapi/v2/user/getuserinfo",
|
||||
JSONUtil.createObj().putOpt("code", code), new TypeReference<DingResponse<DingUserSimple>>() {
|
||||
});
|
||||
return resp.getResult();
|
||||
}
|
||||
|
||||
|
||||
@@ -172,12 +178,11 @@ public class PlatformDingConfig {
|
||||
public DingUserInfo topapiV2UserGet(String service, String ddUserId) {
|
||||
DingConfigBean dingConfigBean = getConfigBean(service);
|
||||
|
||||
String response = doRequest(service, "https://oapi.dingtalk.com/topapi/v2/user/get",
|
||||
JSONUtil.createObj().putOpt("userid", ddUserId));
|
||||
JSONObject resultJson = JSONUtil.parseObj(response).getJSONObject("result");
|
||||
DingUserInfo userInfo = JSONUtil.toBean(resultJson, DingUserInfo.class);
|
||||
DingUserInfo userInfo = doRequest(service, "https://oapi.dingtalk.com/topapi/v2/user/get",
|
||||
JSONUtil.createObj().putOpt("userid", ddUserId), new TypeReference<DingResponse<DingUserInfo>>() {
|
||||
}).getResult();
|
||||
// 设置一下job_number
|
||||
userInfo.setJobNumber(resultJson.getStr("job_number"));
|
||||
userInfo.setJobNumber(userInfo.getJobNumber());
|
||||
userInfo.setAppId(dingConfigBean.getAppKey());
|
||||
return userInfo;
|
||||
}
|
||||
@@ -195,16 +200,9 @@ public class PlatformDingConfig {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
String resp = doRequest(service, "https://oapi.dingtalk.com/topapi/v2/department/listsub",
|
||||
JSONUtil.createObj().putOpt("dept_id", deptId));
|
||||
|
||||
DingResponse<List<DingDeptVo>> result = JSONUtil.toBean(resp, new TypeReference<DingResponse<List<DingDeptVo>>>() {
|
||||
}.getType(), true);
|
||||
|
||||
if (!result.isOk()) {
|
||||
result.setResult(new ArrayList<>());
|
||||
}
|
||||
return result.getResult();
|
||||
return doRequest(service, "https://oapi.dingtalk.com/topapi/v2/department/listsub",
|
||||
JSONUtil.createObj().putOpt("dept_id", deptId), new TypeReference<DingResponse<List<DingDeptVo>>>() {
|
||||
}).getResult();
|
||||
}
|
||||
|
||||
|
||||
@@ -220,19 +218,16 @@ public class PlatformDingConfig {
|
||||
return DingUserListVo.fail();
|
||||
}
|
||||
|
||||
String resp = doRequest(service, "https://oapi.dingtalk.com/topapi/v2/user/list",
|
||||
JSONUtil.createObj().putOpt("dept_id", deptId).putOpt("cursor", cursor).putOpt("size", 100));
|
||||
|
||||
DingResponse<DingUserListVo> result = JSONUtil.toBean(resp, new TypeReference<DingResponse<DingUserListVo>>() {
|
||||
}.getType(), true);
|
||||
if (!result.isOk()) {
|
||||
result.setResult(DingUserListVo.fail());
|
||||
}
|
||||
return result.getResult();
|
||||
return doRequest(service, "https://oapi.dingtalk.com/topapi/v2/user/list",
|
||||
JSONUtil.createObj().putOpt("dept_id", deptId).putOpt("cursor", cursor).putOpt("size", 100),
|
||||
new TypeReference<DingResponse<DingUserListVo>>() {
|
||||
}).getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步钉钉的通讯录
|
||||
* <br />
|
||||
* PS:如果需要钉钉用户手机号,需要开通权限:企业员工手机号信息
|
||||
*
|
||||
* @param deptVo 为null时从第一级获取
|
||||
* @param consumer 回调
|
||||
@@ -271,18 +266,19 @@ public class PlatformDingConfig {
|
||||
* @param content
|
||||
* @param actionUrl
|
||||
* @param userIds
|
||||
* @return
|
||||
*/
|
||||
public void messageNotification(String service, String title, String content, String actionUrl, List<String> userIds) {
|
||||
public DingResponse<String> messageNotification(String service, String title, String markdown, String actionUrl, List<String> userIds) {
|
||||
|
||||
if (CollUtil.isEmpty(userIds)) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
DingConfigBean configBean = getConfigBean(service);
|
||||
|
||||
JSONObject actionCard = new JSONObject();
|
||||
actionCard.set("title", title);
|
||||
actionCard.set("markdown", "### " + title + "\n" + content);
|
||||
actionCard.set("markdown", markdown);
|
||||
actionCard.set("single_title", "点击查看");
|
||||
actionCard.set("single_url", actionUrl);
|
||||
|
||||
@@ -294,12 +290,14 @@ public class PlatformDingConfig {
|
||||
body.putOpt("agent_id", configBean.getAgentId());
|
||||
body.putOpt("userid_list", CollUtil.join(userIds, ","));
|
||||
body.putOpt("msg", msg);
|
||||
doRequest(service, "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2", body);
|
||||
return doRequest(service, "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2", body,
|
||||
new TypeReference<DingResponse<String>>() {
|
||||
});
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// setter\getter
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// setter\getter
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public Map<String, DingConfigBean> getConfigs() {
|
||||
return configs;
|
||||
|
||||
@@ -6,6 +6,8 @@ public class DingResponse<T> {
|
||||
|
||||
private String errcode;
|
||||
private String errmsg;
|
||||
private String ticket;
|
||||
private Long expiresIn;
|
||||
private T result;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
@@ -43,4 +45,20 @@ public class DingResponse<T> {
|
||||
public void setResult(T result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public String getTicket() {
|
||||
return ticket;
|
||||
}
|
||||
|
||||
public void setTicket(String ticket) {
|
||||
this.ticket = ticket;
|
||||
}
|
||||
|
||||
public Long getExpiresIn() {
|
||||
return expiresIn;
|
||||
}
|
||||
|
||||
public void setExpiresIn(Long expiresIn) {
|
||||
this.expiresIn = expiresIn;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,8 @@ import java.util.List;
|
||||
/**
|
||||
* @author hao
|
||||
*/
|
||||
public class DingUserInfo {
|
||||
public class DingUserInfo extends DingUserSimple {
|
||||
|
||||
private String name;
|
||||
private String userid;
|
||||
private String avatar;
|
||||
private String mobile;
|
||||
private String email;
|
||||
@@ -17,7 +15,6 @@ public class DingUserInfo {
|
||||
private String nickname;
|
||||
private String title;
|
||||
private String remark;
|
||||
private String unionid;
|
||||
private String appId;
|
||||
private List<String> deptIdList;
|
||||
private boolean leader;
|
||||
@@ -34,30 +31,6 @@ public class DingUserInfo {
|
||||
// setter\getter
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUnionid() {
|
||||
return unionid;
|
||||
}
|
||||
|
||||
public void setUnionid(String unionid) {
|
||||
this.unionid = unionid;
|
||||
}
|
||||
|
||||
public String getUserid() {
|
||||
return userid;
|
||||
}
|
||||
|
||||
public void setUserid(String userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public String getAvatar() {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.tiesheng.platform.config.ding.bean;
|
||||
|
||||
public class DingUserSimple {
|
||||
|
||||
private String unionid;
|
||||
private String name;
|
||||
private String userid;
|
||||
|
||||
public String getUnionid() {
|
||||
return unionid;
|
||||
}
|
||||
|
||||
public void setUnionid(String unionid) {
|
||||
this.unionid = unionid;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUserid() {
|
||||
return userid;
|
||||
}
|
||||
|
||||
public void setUserid(String userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>1.0.18</version>
|
||||
<version>1.0.24-test3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-poi</artifactId>
|
||||
|
||||
BIN
springboot-util/.DS_Store
vendored
Normal file
BIN
springboot-util/.DS_Store
vendored
Normal file
Binary file not shown.
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>1.0.18</version>
|
||||
<version>1.0.24-test3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-util</artifactId>
|
||||
|
||||
BIN
springboot-util/src/main/.DS_Store
vendored
Normal file
BIN
springboot-util/src/main/.DS_Store
vendored
Normal file
Binary file not shown.
@@ -7,6 +7,7 @@ import com.tiesheng.util.config.DesensitizeValueFilter;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class CommonUtil {
|
||||
|
||||
@@ -18,6 +19,7 @@ public class CommonUtil {
|
||||
*/
|
||||
public static FastJsonConfig fastJsonConfig() {
|
||||
FastJsonConfig config = new FastJsonConfig();
|
||||
config.setCharset(StandardCharsets.UTF_8);
|
||||
config.setSerializerFeatures(SerializerFeature.WriteMapNullValue,
|
||||
SerializerFeature.WriteNullStringAsEmpty,
|
||||
SerializerFeature.WriteEnumUsingName,
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>1.0.18</version>
|
||||
<version>1.0.24-test3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-web</artifactId>
|
||||
|
||||
@@ -0,0 +1,453 @@
|
||||
package com.tiesheng.core.config.json;
|
||||
|
||||
import cn.hutool.core.util.ClassUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.hutool.log.LogFactory;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONException;
|
||||
import com.alibaba.fastjson.JSONPObject;
|
||||
import com.alibaba.fastjson.serializer.SerializeFilter;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.alibaba.fastjson.support.config.FastJsonConfig;
|
||||
import com.alibaba.fastjson.support.spring.FastJsonContainer;
|
||||
import com.alibaba.fastjson.support.spring.MappingFastJsonValue;
|
||||
import com.alibaba.fastjson.support.spring.PropertyPreFilters;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpInputMessage;
|
||||
import org.springframework.http.HttpOutputMessage;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.AbstractHttpMessageConverter;
|
||||
import org.springframework.http.converter.GenericHttpMessageConverter;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.http.converter.HttpMessageNotWritableException;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Fastjson for Spring MVC Converter.
|
||||
* <p>
|
||||
* Compatible Spring MVC version 3.2+
|
||||
*
|
||||
* @author VictorZeng
|
||||
* @see AbstractHttpMessageConverter
|
||||
* @see GenericHttpMessageConverter
|
||||
* @since 1.2.10
|
||||
* <p>
|
||||
* <p>
|
||||
* <p>
|
||||
* Supported return type:
|
||||
* </p>
|
||||
* Simple object: Object
|
||||
* <p>
|
||||
* <p>
|
||||
* With property filter :FastJsonContainer[Object]
|
||||
* </p>
|
||||
* <p>
|
||||
* Jsonp :MappingFastJsonValue[Object]
|
||||
* </p>
|
||||
* Jsonp with property filter: MappingFastJsonValue[FastJsonContainer[Object]]
|
||||
*/
|
||||
|
||||
public class FastJsonHttpMessageConverter extends AbstractHttpMessageConverter<Object>//
|
||||
implements GenericHttpMessageConverter<Object> {
|
||||
|
||||
public static final MediaType APPLICATION_JAVASCRIPT = new MediaType("application", "javascript");
|
||||
|
||||
@Deprecated
|
||||
protected SerializerFeature[] features = new SerializerFeature[0];
|
||||
|
||||
@Deprecated
|
||||
protected SerializeFilter[] filters = new SerializeFilter[0];
|
||||
|
||||
@Deprecated
|
||||
protected String dateFormat;
|
||||
|
||||
private boolean setLengthError = false;
|
||||
|
||||
/**
|
||||
* with fastJson config
|
||||
*/
|
||||
private FastJsonConfig fastJsonConfig = new FastJsonConfig();
|
||||
|
||||
/**
|
||||
* @return the fastJsonConfig.
|
||||
* @since 1.2.11
|
||||
*/
|
||||
public FastJsonConfig getFastJsonConfig() {
|
||||
return fastJsonConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fastJsonConfig the fastJsonConfig to set.
|
||||
* @since 1.2.11
|
||||
*/
|
||||
public void setFastJsonConfig(FastJsonConfig fastJsonConfig) {
|
||||
this.fastJsonConfig = fastJsonConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can serialize/deserialize all types.
|
||||
*/
|
||||
public FastJsonHttpMessageConverter() {
|
||||
|
||||
super(MediaType.ALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets charset.
|
||||
*
|
||||
* @return the charset
|
||||
* @see FastJsonConfig#getCharset()
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public Charset getCharset() {
|
||||
return this.fastJsonConfig.getCharset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets charset.
|
||||
*
|
||||
* @param charset the charset
|
||||
* @see FastJsonConfig#setCharset(Charset)
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public void setCharset(Charset charset) {
|
||||
this.fastJsonConfig.setCharset(charset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets date format.
|
||||
*
|
||||
* @return the date format
|
||||
* @see FastJsonConfig#getDateFormat()
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public String getDateFormat() {
|
||||
return this.fastJsonConfig.getDateFormat();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets date format.
|
||||
*
|
||||
* @param dateFormat the date format
|
||||
* @see FastJsonConfig#setDateFormat(String)
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public void setDateFormat(String dateFormat) {
|
||||
this.fastJsonConfig.setDateFormat(dateFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get features serializer feature [].
|
||||
*
|
||||
* @return the serializer feature []
|
||||
* @see FastJsonConfig#getSerializerFeatures()
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public SerializerFeature[] getFeatures() {
|
||||
return this.fastJsonConfig.getSerializerFeatures();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets features.
|
||||
*
|
||||
* @param features the features
|
||||
* @see FastJsonConfig#setSerializerFeatures(SerializerFeature...)
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public void setFeatures(SerializerFeature... features) {
|
||||
this.fastJsonConfig.setSerializerFeatures(features);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get filters serialize filter [].
|
||||
*
|
||||
* @return the serialize filter []
|
||||
* @see FastJsonConfig#getSerializeFilters()
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public SerializeFilter[] getFilters() {
|
||||
return this.fastJsonConfig.getSerializeFilters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets filters.
|
||||
*
|
||||
* @param filters the filters
|
||||
* @see FastJsonConfig#setSerializeFilters(SerializeFilter...)
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public void setFilters(SerializeFilter... filters) {
|
||||
this.fastJsonConfig.setSerializeFilters(filters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add serialize filter.
|
||||
*
|
||||
* @param filter the filter
|
||||
* @see FastJsonConfig#setSerializeFilters(SerializeFilter...)
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public void addSerializeFilter(SerializeFilter filter) {
|
||||
if (filter == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int length = this.fastJsonConfig.getSerializeFilters().length;
|
||||
SerializeFilter[] filters = new SerializeFilter[length + 1];
|
||||
System.arraycopy(this.fastJsonConfig.getSerializeFilters(), 0, filters, 0, length);
|
||||
filters[filters.length - 1] = filter;
|
||||
this.fastJsonConfig.setSerializeFilters(filters);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supports(Class<?> clazz) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean canRead(Type type, Class<?> contextClass, MediaType mediaType) {
|
||||
return super.canRead(contextClass, mediaType);
|
||||
}
|
||||
|
||||
|
||||
public boolean canWrite(Type type, Class<?> clazz, MediaType mediaType) {
|
||||
return super.canWrite(clazz, mediaType);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.http.converter.GenericHttpMessageConverter#read(java.lang.reflect.Type, java.lang.Class, org.springframework.http.HttpInputMessage)
|
||||
*/
|
||||
public Object read(Type type, //
|
||||
Class<?> contextClass, //
|
||||
HttpInputMessage inputMessage //
|
||||
) throws IOException, HttpMessageNotReadableException {
|
||||
return readType(getType(type, contextClass), inputMessage);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.http.converter.GenericHttpMessageConverter.write
|
||||
*/
|
||||
public void write(Object o, Type type, MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
|
||||
super.write(o, contentType, outputMessage);// support StreamingHttpOutputMessage in spring4.0+
|
||||
//writeInternal(o, outputMessage);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @see org.springframework.http.converter.AbstractHttpMessageConverter#readInternal(java.lang.Class, org.springframework.http.HttpInputMessage)
|
||||
*/
|
||||
@Override
|
||||
protected Object readInternal(Class<?> clazz, //
|
||||
HttpInputMessage inputMessage //
|
||||
) throws IOException, HttpMessageNotReadableException {
|
||||
return readType(getType(clazz, null), inputMessage);
|
||||
}
|
||||
|
||||
private Object readType(Type type, HttpInputMessage inputMessage) {
|
||||
|
||||
try {
|
||||
InputStream in = inputMessage.getBody();
|
||||
return JSON.parseObject(in,
|
||||
fastJsonConfig.getCharset(),
|
||||
type,
|
||||
fastJsonConfig.getParserConfig(),
|
||||
fastJsonConfig.getParseProcess(),
|
||||
JSON.DEFAULT_PARSER_FEATURE,
|
||||
fastJsonConfig.getFeatures());
|
||||
} catch (JSONException ex) {
|
||||
throw new HttpMessageNotReadableException("JSON parse error: " + ex.getMessage(), ex);
|
||||
} catch (IOException ex) {
|
||||
throw new HttpMessageNotReadableException("I/O error while reading input message", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeInternal(Object object, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
|
||||
|
||||
|
||||
LogFactory.get().info(ClassUtil.getClassName(object, false));
|
||||
LogFactory.get().info(JSONUtil.toJsonStr(object));
|
||||
|
||||
ByteArrayOutputStream outnew = new ByteArrayOutputStream();
|
||||
try {
|
||||
HttpHeaders headers = outputMessage.getHeaders();
|
||||
|
||||
//获取全局配置的filter
|
||||
SerializeFilter[] globalFilters = fastJsonConfig.getSerializeFilters();
|
||||
List<SerializeFilter> allFilters = new ArrayList<SerializeFilter>(Arrays.asList(globalFilters));
|
||||
|
||||
boolean isJsonp = false;
|
||||
|
||||
//不知道为什么会有这行代码, 但是为了保持和原来的行为一致,还是保留下来
|
||||
Object value = strangeCodeForJackson(object);
|
||||
|
||||
if (value instanceof FastJsonContainer) {
|
||||
FastJsonContainer fastJsonContainer = (FastJsonContainer) value;
|
||||
PropertyPreFilters filters = fastJsonContainer.getFilters();
|
||||
allFilters.addAll(filters.getFilters());
|
||||
value = fastJsonContainer.getValue();
|
||||
}
|
||||
|
||||
//revise 2017-10-23 ,
|
||||
// 保持原有的MappingFastJsonValue对象的contentType不做修改 保持旧版兼容。
|
||||
// 但是新的JSONPObject将返回标准的contentType:application/javascript ,不对是否有function进行判断
|
||||
if (value instanceof MappingFastJsonValue) {
|
||||
if (!StringUtils.isEmpty(((MappingFastJsonValue) value).getJsonpFunction())) {
|
||||
isJsonp = true;
|
||||
}
|
||||
} else if (value instanceof JSONPObject) {
|
||||
isJsonp = true;
|
||||
}
|
||||
|
||||
|
||||
int len = JSON.writeJSONStringWithFastJsonConfig(outnew, //
|
||||
fastJsonConfig.getCharset(), //
|
||||
value, //
|
||||
fastJsonConfig.getSerializeConfig(), //
|
||||
//fastJsonConfig.getSerializeFilters(), //
|
||||
allFilters.toArray(new SerializeFilter[allFilters.size()]),
|
||||
fastJsonConfig.getDateFormat(), //
|
||||
JSON.DEFAULT_GENERATE_FEATURE, //
|
||||
fastJsonConfig.getSerializerFeatures());
|
||||
|
||||
if (isJsonp) {
|
||||
headers.setContentType(APPLICATION_JAVASCRIPT);
|
||||
}
|
||||
|
||||
if (fastJsonConfig.isWriteContentLength() && !setLengthError) {
|
||||
try {
|
||||
headers.setContentLength(len);
|
||||
} catch (UnsupportedOperationException ex) {
|
||||
// skip
|
||||
setLengthError = true;
|
||||
}
|
||||
}
|
||||
|
||||
outnew.writeTo(outputMessage.getBody());
|
||||
|
||||
} catch (JSONException ex) {
|
||||
throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
|
||||
} finally {
|
||||
outnew.close();
|
||||
}
|
||||
}
|
||||
|
||||
private Object strangeCodeForJackson(Object obj) {
|
||||
if (obj != null) {
|
||||
String className = obj.getClass().getName();
|
||||
if ("com.fasterxml.jackson.databind.node.ObjectNode".equals(className)) {
|
||||
return obj.toString();
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
protected Type getType(Type type, Class<?> contextClass) {
|
||||
if (Spring4TypeResolvableHelper.isSupport()) {
|
||||
return Spring4TypeResolvableHelper.getType(type, contextClass);
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
private static class Spring4TypeResolvableHelper {
|
||||
private static boolean hasClazzResolvableType;
|
||||
|
||||
static {
|
||||
try {
|
||||
Class.forName("org.springframework.core.ResolvableType");
|
||||
hasClazzResolvableType = true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
hasClazzResolvableType = false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isSupport() {
|
||||
return hasClazzResolvableType;
|
||||
}
|
||||
|
||||
|
||||
private static Type getType(Type type, Class<?> contextClass) {
|
||||
if (contextClass != null) {
|
||||
ResolvableType resolvedType = ResolvableType.forType(type);
|
||||
if (type instanceof TypeVariable) {
|
||||
ResolvableType resolvedTypeVariable = resolveVariable((TypeVariable) type, ResolvableType.forClass(contextClass));
|
||||
if (resolvedTypeVariable != ResolvableType.NONE) {
|
||||
return resolvedTypeVariable.resolve();
|
||||
}
|
||||
} else if (type instanceof ParameterizedType && resolvedType.hasUnresolvableGenerics()) {
|
||||
ParameterizedType parameterizedType = (ParameterizedType) type;
|
||||
Class<?>[] generics = new Class[parameterizedType.getActualTypeArguments().length];
|
||||
Type[] typeArguments = parameterizedType.getActualTypeArguments();
|
||||
|
||||
for (int i = 0; i < typeArguments.length; ++i) {
|
||||
Type typeArgument = typeArguments[i];
|
||||
if (typeArgument instanceof TypeVariable) {
|
||||
ResolvableType resolvedTypeArgument = resolveVariable((TypeVariable) typeArgument, ResolvableType.forClass(contextClass));
|
||||
if (resolvedTypeArgument != ResolvableType.NONE) {
|
||||
generics[i] = resolvedTypeArgument.resolve();
|
||||
} else {
|
||||
generics[i] = ResolvableType.forType(typeArgument).resolve();
|
||||
}
|
||||
} else {
|
||||
generics[i] = ResolvableType.forType(typeArgument).resolve();
|
||||
}
|
||||
}
|
||||
|
||||
return ResolvableType.forClassWithGenerics(resolvedType.getRawClass(), generics).getType();
|
||||
}
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
private static ResolvableType resolveVariable(TypeVariable<?> typeVariable, ResolvableType contextType) {
|
||||
ResolvableType resolvedType;
|
||||
if (contextType.hasGenerics()) {
|
||||
resolvedType = ResolvableType.forType(typeVariable, contextType);
|
||||
if (resolvedType.resolve() != null) {
|
||||
return resolvedType;
|
||||
}
|
||||
}
|
||||
|
||||
ResolvableType superType = contextType.getSuperType();
|
||||
if (superType != ResolvableType.NONE) {
|
||||
resolvedType = resolveVariable(typeVariable, superType);
|
||||
if (resolvedType.resolve() != null) {
|
||||
return resolvedType;
|
||||
}
|
||||
}
|
||||
for (ResolvableType ifc : contextType.getInterfaces()) {
|
||||
resolvedType = resolveVariable(typeVariable, ifc);
|
||||
if (resolvedType.resolve() != null) {
|
||||
return resolvedType;
|
||||
}
|
||||
}
|
||||
return ResolvableType.NONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.tiesheng.core.config.json;
|
||||
|
||||
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
||||
import com.tiesheng.util.CommonUtil;
|
||||
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@@ -19,7 +19,11 @@ public class MybatisTimeMetaHandler implements MetaObjectHandler {
|
||||
@Override
|
||||
public void insertFill(MetaObject metaObject) {
|
||||
// 其中方法参数中第一个是前面自动填充所对应的字段,第二个是要自动填充的值。第三个是指定实体类的对象
|
||||
this.setFieldValByName("createTime", DateUtil.date(), metaObject);
|
||||
Object createTime = getFieldValByName("createTime", metaObject);
|
||||
if (createTime == null) {
|
||||
createTime = DateUtil.date();
|
||||
}
|
||||
this.setFieldValByName("createTime", createTime, metaObject);
|
||||
this.setFieldValByName("updateTime", DateUtil.date(), metaObject);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,28 @@ public class CoreConfigService extends TsServiceBase<CoreConfigSystemMapper, Cor
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取(或创建)一个文本类型的配置
|
||||
*
|
||||
* @param configKey
|
||||
* @param defaultValue
|
||||
* @return
|
||||
*/
|
||||
public CoreConfigSystem getTextOrCreate(String configKey, String defaultValue) {
|
||||
CoreConfigSystem oneByColumn = getOneByColumn("config_key", configKey);
|
||||
if (oneByColumn == null) {
|
||||
oneByColumn = new CoreConfigSystem();
|
||||
oneByColumn.setId(configKey);
|
||||
oneByColumn.setConfigKey(configKey);
|
||||
oneByColumn.setConfigVal(defaultValue);
|
||||
oneByColumn.setRemark(defaultValue);
|
||||
oneByColumn.setConfigType(0);
|
||||
save(oneByColumn);
|
||||
}
|
||||
return oneByColumn;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 刷新功能点
|
||||
*
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.tiesheng.core.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.tiesheng.core.mapper.CorePlatformUniqueMapper;
|
||||
import com.tiesheng.core.pojos.dao.CorePlatformUnique;
|
||||
import com.tiesheng.login.config.token.bean.TokenBean;
|
||||
@@ -11,6 +11,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author hao
|
||||
@@ -37,11 +38,22 @@ public class CorePlatformUniqueService extends TsServiceBase<CorePlatformUniqueM
|
||||
platformUnique.setInfo(loginInfo.getInfo());
|
||||
saveOrUpdate(platformUnique);
|
||||
|
||||
String oldUserId = platformUnique.getUserId();
|
||||
TokenBean tokenBean = tieshengWebConfigurer.login(platformUnique);
|
||||
if (tokenBean != null) {
|
||||
|
||||
// 添加登录日志
|
||||
coreLogService.addLoginLog(platformUnique, tokenBean);
|
||||
|
||||
// 更新唯一值
|
||||
if (!StrUtil.isEmpty(tokenBean.getId()) &&
|
||||
!Objects.equals(oldUserId, tokenBean.getId())) {
|
||||
platformUnique.setUserId(tokenBean.getId());
|
||||
saveOrUpdate(platformUnique);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return tokenBean;
|
||||
}
|
||||
|
||||
@@ -55,19 +67,5 @@ public class CorePlatformUniqueService extends TsServiceBase<CorePlatformUniqueM
|
||||
tieshengWebConfigurer.onSignError(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户id
|
||||
*
|
||||
* @param uniqueId
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
public boolean updateUserId(String uniqueId, String userId) {
|
||||
return update(new UpdateWrapper<CorePlatformUnique>().eq("unique_id", uniqueId)
|
||||
.set("user_id", userId)
|
||||
.set("is_deleted", 0)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user