🎨 规范化部分代码格式

This commit is contained in:
Binary Wang 2019-08-11 11:26:36 +08:00
parent c6a4f4548f
commit 6e1d7fcef0
8 changed files with 64 additions and 51 deletions

View File

@ -27,7 +27,6 @@
<property name="max" value="120"/> <property name="max" value="120"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/> <property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
</module> </module>
<module name="AvoidStarImport"/>
<module name="OneTopLevelClass"/> <module name="OneTopLevelClass"/>
<module name="NoLineWrap"/> <module name="NoLineWrap"/>
<module name="EmptyBlock"> <module name="EmptyBlock">

View File

@ -36,34 +36,36 @@ import java.util.Map;
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.*; import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.*;
/** /**
* .
*
* @author chanjarster * @author chanjarster
*/ */
@Slf4j @Slf4j
public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestHttp<H, P> { public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestHttp<H, P> {
private WxCpUserService userService = new WxCpUserServiceImpl(this); private WxCpUserService userService = new WxCpUserServiceImpl(this);
private WxCpChatService chatService = new WxCpChatServiceImpl(this); private WxCpChatService chatService = new WxCpChatServiceImpl(this);
private WxCpDepartmentService departmentService = new WxCpDepartmentServiceImpl(this); private WxCpDepartmentService departmentService = new WxCpDepartmentServiceImpl(this);
private WxCpMediaService mediaService = new WxCpMediaServiceImpl(this); private WxCpMediaService mediaService = new WxCpMediaServiceImpl(this);
private WxCpMenuService menuService = new WxCpMenuServiceImpl(this); private WxCpMenuService menuService = new WxCpMenuServiceImpl(this);
private WxCpOAuth2Service oauth2Service = new WxCpOAuth2ServiceImpl(this); private WxCpOAuth2Service oauth2Service = new WxCpOAuth2ServiceImpl(this);
private WxCpTagService tagService = new WxCpTagServiceImpl(this); private WxCpTagService tagService = new WxCpTagServiceImpl(this);
private WxCpAgentService agentService = new WxCpAgentServiceImpl(this); private WxCpAgentService agentService = new WxCpAgentServiceImpl(this);
private WxCpOaService oaService = new WxCpOaServiceImpl(this); private WxCpOaService oaService = new WxCpOaServiceImpl(this);
private WxCpTaskCardService taskCardService = new WxCpTaskCardServiceImpl(this); private WxCpTaskCardService taskCardService = new WxCpTaskCardServiceImpl(this);
private WxCpExternalContactService externalContactService = new WxCpExternalContactServiceImpl(this); private WxCpExternalContactService externalContactService = new WxCpExternalContactServiceImpl(this);
/** /**
* 全局的是否正在刷新access token的锁 * 全局的是否正在刷新access token的锁.
*/ */
protected final Object globalAccessTokenRefreshLock = new Object(); protected final Object globalAccessTokenRefreshLock = new Object();
/** /**
* 全局的是否正在刷新jsapi_ticket的锁 * 全局的是否正在刷新jsapi_ticket的锁.
*/ */
protected final Object globalJsapiTicketRefreshLock = new Object(); protected final Object globalJsapiTicketRefreshLock = new Object();
/** /**
* 全局的是否正在刷新agent的jsapi_ticket的锁 * 全局的是否正在刷新agent的jsapi_ticket的锁.
*/ */
protected final Object globalAgentJsapiTicketRefreshLock = new Object(); protected final Object globalAgentJsapiTicketRefreshLock = new Object();
@ -72,7 +74,7 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
private WxSessionManager sessionManager = new StandardSessionManager(); private WxSessionManager sessionManager = new StandardSessionManager();
/** /**
* 临时文件目录 * 临时文件目录.
*/ */
private File tmpDirFile; private File tmpDirFile;
private int retrySleepMillis = 1000; private int retrySleepMillis = 1000;
@ -183,8 +185,8 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
params.put("js_code", jsCode); params.put("js_code", jsCode);
params.put("grant_type", "authorization_code"); params.put("grant_type", "authorization_code");
String result = this.get(this.configStorage.getApiUrl(JSCODE_TO_SESSION), Joiner.on("&").withKeyValueSeparator("=").join(params)); final String url = this.configStorage.getApiUrl(JSCODE_TO_SESSION);
return WxCpMaJsCode2SessionResult.fromJson(result); return WxCpMaJsCode2SessionResult.fromJson(this.get(url, Joiner.on("&").withKeyValueSeparator("=").join(params)));
} }
@Override @Override

View File

@ -26,6 +26,8 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* .
*
* @author zhenjun cai * @author zhenjun cai
*/ */
@Slf4j @Slf4j
@ -73,7 +75,7 @@ public abstract class BaseWxCpTpServiceImpl<H, P> implements WxCpTpService, Requ
@Override @Override
public String getSuiteTicket(boolean forceRefresh) throws WxErrorException { public String getSuiteTicket(boolean forceRefresh) throws WxErrorException {
// suite ticket由微信服务器推送不能强制刷新 // suite ticket由微信服务器推送不能强制刷新
// if (forceRefresh) { // if (forceRefresh) {
// this.configStorage.expireSuiteTicket(); // this.configStorage.expireSuiteTicket();
// } // }
@ -93,8 +95,8 @@ public abstract class BaseWxCpTpServiceImpl<H, P> implements WxCpTpService, Requ
params.put("js_code", jsCode); params.put("js_code", jsCode);
params.put("grant_type", "authorization_code"); params.put("grant_type", "authorization_code");
String result = this.get(configStorage.getApiUrl(WxCpApiPathConsts.Tp.JSCODE_TO_SESSION), Joiner.on("&").withKeyValueSeparator("=").join(params)); final String url = configStorage.getApiUrl(WxCpApiPathConsts.Tp.JSCODE_TO_SESSION);
return WxCpMaJsCode2SessionResult.fromJson(result); return WxCpMaJsCode2SessionResult.fromJson(this.get(url, Joiner.on("&").withKeyValueSeparator("=").join(params)));
} }

View File

@ -36,8 +36,8 @@ public class WxCpAgentServiceImpl implements WxCpAgentService {
throw new IllegalArgumentException("缺少agentid参数"); throw new IllegalArgumentException("缺少agentid参数");
} }
String responseContent = this.mainService.get(String.format(this.mainService.getWxCpConfigStorage().getApiUrl(AGENT_GET), agentId), null); final String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(AGENT_GET), agentId);
return WxCpAgent.fromJson(responseContent); return WxCpAgent.fromJson(this.mainService.get(url, null));
} }
@Override @Override

View File

@ -43,13 +43,14 @@ public class WxCpChatServiceImpl implements WxCpChatService {
if (StringUtils.isNotBlank(chatId)) { if (StringUtils.isNotBlank(chatId)) {
data.put("chatid", chatId); data.put("chatid", chatId);
} }
String result = this.cpService.post(this.cpService.getWxCpConfigStorage().getApiUrl(APPCHAT_CREATE), WxGsonBuilder.create().toJson(data)); final String url = this.cpService.getWxCpConfigStorage().getApiUrl(APPCHAT_CREATE);
String result = this.cpService.post(url, WxGsonBuilder.create().toJson(data));
return new JsonParser().parse(result).getAsJsonObject().get("chatid").getAsString(); return new JsonParser().parse(result).getAsJsonObject().get("chatid").getAsString();
} }
@Override @Override
public String create(String name, String owner, List<String> users, String chatId) throws WxErrorException { public String create(String name, String owner, List<String> users, String chatId) throws WxErrorException {
return chatCreate(name, owner, users, chatId); return this.chatCreate(name, owner, users, chatId);
} }
@Override @Override
@ -72,24 +73,27 @@ public class WxCpChatServiceImpl implements WxCpChatService {
data.put("del_user_list", usersToDelete); data.put("del_user_list", usersToDelete);
} }
this.cpService.post(this.cpService.getWxCpConfigStorage().getApiUrl(APPCHAT_UPDATE), WxGsonBuilder.create().toJson(data)); final String url = this.cpService.getWxCpConfigStorage().getApiUrl(APPCHAT_UPDATE);
this.cpService.post(url, WxGsonBuilder.create().toJson(data));
} }
@Override @Override
public void update(String chatId, String name, String owner, List<String> usersToAdd, List<String> usersToDelete) throws WxErrorException { public void update(String chatId, String name, String owner, List<String> usersToAdd, List<String> usersToDelete)
throws WxErrorException {
chatUpdate(chatId, name, owner, usersToAdd, usersToDelete); chatUpdate(chatId, name, owner, usersToAdd, usersToDelete);
} }
@Override @Override
public WxCpChat chatGet(String chatId) throws WxErrorException { public WxCpChat chatGet(String chatId) throws WxErrorException {
String result = this.cpService.get(this.cpService.getWxCpConfigStorage().getApiUrl(APPCHAT_GET_CHATID + chatId), null); final String url = this.cpService.getWxCpConfigStorage().getApiUrl(APPCHAT_GET_CHATID + chatId);
return WxCpGsonBuilder.create() String result = this.cpService.get(url, null);
.fromJson(JSON_PARSER.parse(result).getAsJsonObject().getAsJsonObject("chat_info").toString(), WxCpChat.class); final String chatInfo = JSON_PARSER.parse(result).getAsJsonObject().getAsJsonObject("chat_info").toString();
return WxCpGsonBuilder.create().fromJson(chatInfo, WxCpChat.class);
} }
@Override @Override
public WxCpChat get(String chatId) throws WxErrorException { public WxCpChat get(String chatId) throws WxErrorException {
return chatGet(chatId); return this.chatGet(chatId);
} }
@Override @Override

View File

@ -20,22 +20,22 @@ public class WxCpExternalContactServiceImpl implements WxCpExternalContactServic
@Override @Override
public WxCpUserExternalContactInfo getExternalContact(String userId) throws WxErrorException { public WxCpUserExternalContactInfo getExternalContact(String userId) throws WxErrorException {
String responseContent = this.mainService.get(this.mainService.getWxCpConfigStorage().getApiUrl(GET_EXTERNAL_CONTACT + userId), null); final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_EXTERNAL_CONTACT + userId);
String responseContent = this.mainService.get(url, null);
return WxCpUserExternalContactInfo.fromJson(responseContent); return WxCpUserExternalContactInfo.fromJson(responseContent);
} }
@Override @Override
public List<String> listExternalContacts(String userId) throws WxErrorException { public List<String> listExternalContacts(String userId) throws WxErrorException {
String responseContent = this.mainService.get(this.mainService.getWxCpConfigStorage().getApiUrl(LIST_EXTERNAL_CONTACT + userId), null); final String url = this.mainService.getWxCpConfigStorage().getApiUrl(LIST_EXTERNAL_CONTACT + userId);
WxCpUserExternalContactList list = WxCpUserExternalContactList.fromJson(responseContent); String responseContent = this.mainService.get(url, null);
return list.getExternalUserId(); return WxCpUserExternalContactList.fromJson(responseContent).getExternalUserId();
} }
@Override @Override
public List<String> listFollowUser() throws WxErrorException { public List<String> listFollowUser() throws WxErrorException {
String responseContent = this.mainService.get(this.mainService.getWxCpConfigStorage().getApiUrl(GET_FOLLOW_USER_LIST), null); final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_FOLLOW_USER_LIST);
WxCpUserWithExternalPermission list = WxCpUserWithExternalPermission.fromJson(responseContent); String responseContent = this.mainService.get(url, null);
return list.getFollowUser(); return WxCpUserWithExternalPermission.fromJson(responseContent).getFollowUser();
} }
} }

View File

@ -6,6 +6,7 @@ import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils; import me.chanjar.weixin.common.util.fs.FileUtils;
import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor; import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor;
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.cp.api.WxCpMediaService; import me.chanjar.weixin.cp.api.WxCpMediaService;
import me.chanjar.weixin.cp.api.WxCpService; import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts; import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
@ -59,8 +60,8 @@ public class WxCpMediaServiceImpl implements WxCpMediaService {
@Override @Override
public String uploadImg(File file) throws WxErrorException { public String uploadImg(File file) throws WxErrorException {
final WxMediaUploadResult result = this.mainService final String url = this.mainService.getWxCpConfigStorage().getApiUrl(IMG_UPLOAD);
.execute(MediaUploadRequestExecutor.create(this.mainService.getRequestHttp()), this.mainService.getWxCpConfigStorage().getApiUrl(IMG_UPLOAD), file); return this.mainService.execute(MediaUploadRequestExecutor.create(this.mainService.getRequestHttp()), url, file)
return result.getUrl(); .getUrl();
} }
} }

View File

@ -22,6 +22,8 @@ import java.util.List;
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Oa.*; import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Oa.*;
/** /**
* .
*
* @author Element * @author Element
* @date 2019-04-06 11:20 * @date 2019-04-06 11:20
*/ */
@ -60,7 +62,8 @@ public class WxCpOaServiceImpl implements WxCpOaService {
jsonObject.add("useridlist", jsonArray); jsonObject.add("useridlist", jsonArray);
String responseContent = this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(GET_CHECKIN_DATA), jsonObject.toString()); final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_CHECKIN_DATA);
String responseContent = this.mainService.post(url, jsonObject.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent); JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.create() return WxCpGsonBuilder.create()
.fromJson( .fromJson(
@ -89,7 +92,8 @@ public class WxCpOaServiceImpl implements WxCpOaService {
jsonObject.addProperty("datetime", datetime.getTime() / 1000L); jsonObject.addProperty("datetime", datetime.getTime() / 1000L);
jsonObject.add("useridlist", jsonArray); jsonObject.add("useridlist", jsonArray);
String responseContent = this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(GET_CHECKIN_OPTION), jsonObject.toString()); final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_CHECKIN_OPTION);
String responseContent = this.mainService.post(url, jsonObject.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent); JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.create() return WxCpGsonBuilder.create()
@ -109,12 +113,14 @@ public class WxCpOaServiceImpl implements WxCpOaService {
jsonObject.addProperty("next_spnum", nextSpnum); jsonObject.addProperty("next_spnum", nextSpnum);
} }
String responseContent = this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(GET_APPROVAL_DATA), jsonObject.toString()); final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_APPROVAL_DATA);
String responseContent = this.mainService.post(url, jsonObject.toString());
return WxCpGsonBuilder.create().fromJson(responseContent, WxCpApprovalDataResult.class); return WxCpGsonBuilder.create().fromJson(responseContent, WxCpApprovalDataResult.class);
} }
@Override @Override
public List<WxCpDialRecord> getDialRecord(Date startTime, Date endTime, Integer offset, Integer limit) throws WxErrorException { public List<WxCpDialRecord> getDialRecord(Date startTime, Date endTime, Integer offset, Integer limit)
throws WxErrorException {
JsonObject jsonObject = new JsonObject(); JsonObject jsonObject = new JsonObject();
if (offset == null) { if (offset == null) {
@ -141,14 +147,13 @@ public class WxCpOaServiceImpl implements WxCpOaService {
jsonObject.addProperty("end_time", endtimestamp); jsonObject.addProperty("end_time", endtimestamp);
} }
String responseContent = this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(GET_DIAL_RECORD), jsonObject.toString()); final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_DIAL_RECORD);
String responseContent = this.mainService.post(url, jsonObject.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent); JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.create() return WxCpGsonBuilder.create().fromJson(tmpJsonElement.getAsJsonObject().get("record"),
.fromJson( new TypeToken<List<WxCpDialRecord>>() {
tmpJsonElement.getAsJsonObject().get("record"), }.getType()
new TypeToken<List<WxCpDialRecord>>() { );
}.getType()
);
} }
} }