diff --git a/cloud-common-plugin-dictionary/src/main/java/com/cm/common/plugin/controller/wechat/datadictionary/DataDictionaryWechatController.java b/cloud-common-plugin-dictionary/src/main/java/com/cm/common/plugin/controller/wechat/datadictionary/DataDictionaryWechatController.java new file mode 100644 index 0000000..433d8e6 --- /dev/null +++ b/cloud-common-plugin-dictionary/src/main/java/com/cm/common/plugin/controller/wechat/datadictionary/DataDictionaryWechatController.java @@ -0,0 +1,109 @@ +package com.cm.common.plugin.controller.wechat.datadictionary; + +import com.cm.common.base.AbstractController; +import com.cm.common.constants.ISystemConstant; +import com.cm.common.exception.SearchException; +import com.cm.common.plugin.pojo.dtos.datadictionary.DataDictionaryDTO; +import com.cm.common.plugin.service.datadictionary.IDataDictionaryService; +import com.cm.common.pojo.ListPage; +import com.cm.common.pojo.dtos.ZTreeDTO; +import com.cm.common.result.ErrorResult; +import com.cm.common.result.SuccessResultList; +import io.swagger.annotations.*; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; +import java.util.Map; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: DataDictionaryWechatController + * @Description: 微信数据字典 + * @Author: WangGeng + * @Date: 2020/3/8 9:47 上午 + * @Version: 1.0 + **/ +@Api(tags = ISystemConstant.API_TAGS_WECHAT_PREFIX + "字典管理接口") +@RestController +@RequestMapping(ISystemConstant.WECHAT_PREFIX + "/datadictionary") +public class DataDictionaryWechatController extends AbstractController { + + @Autowired + private IDataDictionaryService dataDictionaryService; + + @ApiOperation(value = "字典详情(ID查询)", notes = "字典详情(ID查询)接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "dictionaryId", value = "字典ID", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("getdictionarybyid/{dictionaryId}") + public DataDictionaryDTO getDictionaryById(@PathVariable("dictionaryId") String dictionaryId) { + return dataDictionaryService.getDictionaryById(dictionaryId); + } + + @ApiOperation(value = "字典列表(上级ID查询)", notes = "字典列表(上级ID查询)接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "dictionaryParentId", value = "字典上级ID", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("listdictionarybyparentid/{dictionaryParentId}") + public List listDictionaryByParentId(@PathVariable("dictionaryParentId") String dictionaryParentId) { + return dataDictionaryService.listDictionaryByParentId(dictionaryParentId); + } + + @ApiOperation(value = "字典全部列表(上级ID查询)", notes = "字典全部列表(上级ID查询)接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "dictionaryParentId", value = "字典上级ID", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("listdictionaryallbyparentid/{dictionaryParentId}") + public List listDictionary(@PathVariable("dictionaryParentId") String dictionaryParentId) throws SearchException { + return dataDictionaryService.listDictionaryAllByParentId(dictionaryParentId); + } + + @ApiOperation(value = "分页字典列表", notes = "分页字典列表接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "parentId", value = "上级ID", paramType = "form", dataType = "String"), + @ApiImplicitParam(name = "page", value = "当前页码", paramType = "form", dataType = "Integer", defaultValue = "1"), + @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "form", dataType = "Integer", defaultValue = "20"), + @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "form", dataType = "String"), + @ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "form", dataType = "String"), + @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "form", dataType = "String") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("listpagedictionary") + public SuccessResultList> listPageDictionary(ListPage page) { + Map params = requestParams(); + String dictionaryParentId = "0"; + if (!StringUtils.isBlank(params.get(ISystemConstant.PARAMS_PARENT_ID) == null ? null : params.get(ISystemConstant.PARAMS_PARENT_ID).toString())) { + dictionaryParentId = params.get(ISystemConstant.PARAMS_PARENT_ID).toString(); + } + params.put("dictionaryParentId", dictionaryParentId); + page.setParams(params); + return dataDictionaryService.listPageDictionary(page); + } + + @ApiOperation(value = "zTree列表", notes = "zTree列表接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "父ID", paramType = "form", dataType = "String") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("listztreedictionary") + public List listZTreeDictionary() throws SearchException { + Map params = requestParams(); + String dictionaryParentId = "0"; + if (!StringUtils.isBlank(params.get(ISystemConstant.PARAMS_ID) == null ? null : params.get(ISystemConstant.PARAMS_ID).toString())) { + dictionaryParentId = params.get(ISystemConstant.PARAMS_ID).toString(); + } + params.put("dictionaryParentId", dictionaryParentId); + return dataDictionaryService.listZTreeDictionary(params); + } + +} diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/controller/wechat/file/FileWechatController.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/controller/wechat/file/FileWechatController.java new file mode 100644 index 0000000..60c61f2 --- /dev/null +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/controller/wechat/file/FileWechatController.java @@ -0,0 +1,107 @@ +package com.cm.common.plugin.controller.wechat.file; + +import com.cm.common.base.AbstractController; +import com.cm.common.constants.ISystemConstant; +import com.cm.common.enums.UploadTypeEnum; +import com.cm.common.exception.base.SystemException; +import com.cm.common.plugin.service.file.IFileService; +import com.cm.common.pojo.dtos.FileDTO; +import com.cm.common.result.ErrorResult; +import com.cm.common.result.SuccessResultData; +import io.swagger.annotations.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: FileWechatController + * @Description: 微信文件 + * @Author: WangGeng + * @Date: 2020/3/8 9:39 上午 + * @Version: 1.0 + **/ +@Api(tags = ISystemConstant.API_TAGS_WECHAT_PREFIX + "文件管理接口") +@RestController +@RequestMapping(ISystemConstant.WECHAT_PREFIX + "/file") +public class FileWechatController extends AbstractController { + + @Autowired + private IFileService fileService; + + @ApiOperation(value = "上传文件", notes = "上传文件接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "token", value = "token", paramType = "header"), + @ApiImplicitParam(name = "file", value = "文件name", paramType = "form") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PostMapping("uploadfile") + public SuccessResultData uploadFile(@RequestHeader("token") String token, @RequestParam("file") MultipartFile file) throws SystemException { + Map params = requestParams(); + return uploadSingle(token, file, UploadTypeEnum.FILE, params); + } + + @ApiOperation(value = "上传图片", notes = "上传图片接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "token", value = "token", paramType = "header"), + @ApiImplicitParam(name = "image", value = "文件name", paramType = "form") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PostMapping("uploadimage") + public SuccessResultData uploadImage(@RequestHeader("token") String token, @RequestParam("image") MultipartFile image) throws SystemException { + Map params = requestParams(); + return uploadSingle(token, image, UploadTypeEnum.IMAGE, params); + } + + @ApiOperation(value = "上传视频", notes = "上传视频接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "token", value = "token", paramType = "header"), + @ApiImplicitParam(name = "video", value = "文件video", paramType = "form") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PostMapping("uploadvideo") + public SuccessResultData uploadVideo(@RequestHeader("token") String token, @RequestParam("video") MultipartFile video) throws SystemException { + Map params = requestParams(); + return uploadSingle(token, video, UploadTypeEnum.VIDEO, params); + } + + @ApiOperation(value = "上传音频", notes = "上传音频接口") + @ApiImplicitParams({@ApiImplicitParam(name = "token", value = "token", paramType = "header"), + @ApiImplicitParam(name = "audio", value = "文件audio", paramType = "form") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PostMapping("uploadaudio") + public SuccessResultData uploadAudio(@RequestHeader("token") String token, @RequestParam("audio") MultipartFile audio) throws SystemException { + Map params = requestParams(); + return uploadSingle(token, audio, UploadTypeEnum.AUDIO, params); + } + + @ApiOperation(value = "文件列表", notes = "文件列表接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "ids", value = "id列表,逗号分隔", paramType = "form") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("listfilebyfileid") + public List listFileByFileId(@RequestParam("ids") String ids) { + List idList = Arrays.asList(ids.split(",")); + return fileService.listFileByFileId(idList); + } + + /** + * 上传文件 + * + * @param uploadFile + * @param params + * @return + */ + private SuccessResultData uploadSingle(String token, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map params) throws SystemException { + return fileService.uploadSingle(token, uploadFile, uploadTypeEnum, params); + } + +} diff --git a/cloud-common-wechat/src/main/java/com/cm/common/wechat/controller/WechatOfficialAccountApiController.java b/cloud-common-wechat/src/main/java/com/cm/common/wechat/controller/WechatOfficialAccountApiController.java new file mode 100644 index 0000000..71fd14b --- /dev/null +++ b/cloud-common-wechat/src/main/java/com/cm/common/wechat/controller/WechatOfficialAccountApiController.java @@ -0,0 +1,52 @@ +package com.cm.common.wechat.controller; + +import com.cm.common.constants.ISystemConstant; +import com.cm.common.exception.SearchException; +import com.cm.common.result.SuccessResultData; +import com.cm.common.utils.AesUtil; +import com.cm.common.wechat.manager.officialaccount.WechatOfficialAccountManager; +import com.cm.common.wechat.pojo.WechatOfficialAccountUser; +import io.swagger.annotations.Api; +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.lang3.StringUtils; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: WechatOfficialAccountApiController + * @Description: 微信公众号公共接口 + * @Author: WangGeng + * @Date: 2020/3/8 10:28 上午 + * @Version: 1.0 + **/ +@Api(tags = ISystemConstant.API_TAGS_WECHAT_PREFIX + "公共接口") +@RestController +@RequestMapping(ISystemConstant.WECHAT_PREFIX + "/officialaccount") +public class WechatOfficialAccountApiController { + + @GetMapping("getusertokenbyappidandopenidrelease/{appId}/{openId}") + public SuccessResultData getUserTokenByAppIdAndOpenId(@PathVariable("appId") String appId, + @PathVariable("openId") String openId) throws Exception { + String wechatSignInfo = Base64.encodeBase64String(AesUtil.aesCommonEncoder("WECHAT_SIGN_INFO", new StringBuilder(openId).append("_WenG_").append(appId).toString()).getBytes("UTF-8")); + String token = WechatOfficialAccountManager.getInstance().getAppToken(wechatSignInfo); + return new SuccessResultData<>(token); + } + + @GetMapping("getusertokenrelease") + public SuccessResultData getUserToken(HttpServletRequest request) throws Exception { + Object accessToken = request.getSession().getAttribute(ISystemConstant.SESSION_WECHAT_ACCESS_TOKEN); + if (accessToken == null) { + throw new SearchException("用户未登录,无token"); + } + WechatOfficialAccountUser wechatOfficialAccountUser = (WechatOfficialAccountUser) accessToken; + return new SuccessResultData<>(wechatOfficialAccountUser.getToken()); + } + +} diff --git a/cloud-common-wechat/src/main/java/com/cm/common/wechat/controller/WechatOfficialAccountTestRouteController.java b/cloud-common-wechat/src/main/java/com/cm/common/wechat/controller/WechatOfficialAccountTestRouteController.java index acf2d29..d28e713 100644 --- a/cloud-common-wechat/src/main/java/com/cm/common/wechat/controller/WechatOfficialAccountTestRouteController.java +++ b/cloud-common-wechat/src/main/java/com/cm/common/wechat/controller/WechatOfficialAccountTestRouteController.java @@ -1,10 +1,17 @@ package com.cm.common.wechat.controller; import com.cm.common.constants.ISystemConstant; +import com.cm.common.result.SuccessResult; +import com.cm.common.result.SuccessResultData; +import com.cm.common.utils.AesUtil; +import com.cm.common.wechat.manager.officialaccount.WechatOfficialAccountManager; import io.swagger.annotations.Api; +import org.apache.commons.codec.binary.Base64; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletResponse; import java.io.IOException; diff --git a/cloud-common-wechat/src/main/java/com/cm/common/wechat/filter/WechatFilter.java b/cloud-common-wechat/src/main/java/com/cm/common/wechat/filter/WechatFilter.java index bb01a83..9c9c243 100644 --- a/cloud-common-wechat/src/main/java/com/cm/common/wechat/filter/WechatFilter.java +++ b/cloud-common-wechat/src/main/java/com/cm/common/wechat/filter/WechatFilter.java @@ -1,11 +1,20 @@ package com.cm.common.wechat.filter; +import com.alibaba.fastjson.JSON; import com.cm.common.constants.ISystemConstant; +import com.cm.common.enums.AppTokenTypeEnum; +import com.cm.common.enums.ErrorResultCodeEnum; +import com.cm.common.exception.TokenException; +import com.cm.common.result.ErrorResult; +import com.cm.common.token.app.AppTokenManager; +import com.cm.common.token.app.entity.AppToken; +import com.cm.common.token.app.entity.AppTokenUser; import com.cm.common.wechat.config.pojo.WechatOfficialAccountProperties; import com.cm.common.wechat.manager.officialaccount.WechatOfficialAccountManager; import org.apache.shiro.crypto.hash.SimpleHash; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; import org.springframework.util.AntPathMatcher; import org.springframework.util.StringUtils; @@ -42,11 +51,11 @@ public class WechatFilter implements Filter { /** * 微信放行 */ - private static final String WECHAT_API_RELEASE_URL = "/**/wechat/**release"; + private static final String WECHAT_API_RELEASE_URL = "/**/wechat/**/**release/**"; /** * 微信路由放行 */ - private static final String WECHAT_ROUTE_RELEASE_URL = "/**/wechatroute/**release"; + private static final String WECHAT_ROUTE_RELEASE_URL = "/**/wechatroute/**/**release/**"; @Override public void init(FilterConfig filterConfig) throws ServletException { @@ -67,6 +76,19 @@ public class WechatFilter implements Filter { return; } + // 如果header存在token则校验token,如果没有就校验session + String token = request.getHeader("token"); + if (!StringUtils.isEmpty(token)) { + try { + checkToken(token); + } catch (TokenException e) { + errorResponse(response, e.getMessage()); + return; + } + filterChain.doFilter(request, response); + return; + } + // 判断是不是微信配置校验 String signatureParameter = request.getParameter("signature"); String timestampParameter = request.getParameter("timestamp"); @@ -109,6 +131,25 @@ public class WechatFilter implements Filter { response.sendRedirect(WechatOfficialAccountManager.getInstance().getAuthorizeUrl(request.getRequestURL().toString())); } + /** + * 校验token + * + * @param token + * @return + * @throws TokenException + */ + private void checkToken(String token) throws TokenException { + AppTokenManager appTokenManager = AppTokenManager.getInstance(); + LOG.debug("检查token是否存在"); + AppToken appToken = appTokenManager.getToken(token); + if (appToken != null) { + return; + } + LOG.debug("解析token是否合法"); + AppTokenUser appTokenUser = appTokenManager.parseToAppTokenUser(token); + appTokenManager.addToken(token, AppTokenTypeEnum.WECHAT, appTokenUser); + } + /** * 是来自微信的配置请求 * @@ -138,4 +179,18 @@ public class WechatFilter implements Filter { this.wechatOfficialAccountProperties = wechatOfficialAccountProperties; } + /** + * 错误返回 + * + * @param response + * @param errorInfo + * @throws IOException + */ + private void errorResponse(HttpServletResponse response, String errorInfo) throws IOException { + response.setStatus(HttpStatus.BAD_REQUEST.value()); + response.setHeader("Content-Type", "application/json;charset=UTF-8"); + ErrorResult result = new ErrorResult(ErrorResultCodeEnum.PARAMS_ERROR.getValue(), errorInfo); + response.getWriter().write(JSON.toJSONString(result)); + } + } \ No newline at end of file diff --git a/cloud-common/src/main/java/com/cm/common/base/AbstractService.java b/cloud-common/src/main/java/com/cm/common/base/AbstractService.java index f32bcfb..bb4655b 100644 --- a/cloud-common/src/main/java/com/cm/common/base/AbstractService.java +++ b/cloud-common/src/main/java/com/cm/common/base/AbstractService.java @@ -3,6 +3,7 @@ package com.cm.common.base; import com.alibaba.fastjson.JSONObject; import com.cm.common.component.SecurityComponent; import com.cm.common.constants.ISystemConstant; +import com.cm.common.enums.RoleDataAuthorityEnum; import com.cm.common.exception.AccessTokenException; import com.cm.common.exception.SearchException; import com.cm.common.pojo.bos.UserInfoBO; @@ -17,10 +18,7 @@ import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; import javax.servlet.http.HttpSession; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @ClassName: AbstractService @@ -255,4 +253,33 @@ public abstract class AbstractService { } return listHeaders; } + + /** + * 设置数据权限信息 + * + * @param params + */ + protected void setDataAuthorityInfo(Map params) { + UserInfoBO currentUser = securityComponent.getCurrentUser(); + if (ISystemConstant.ADMIN.equals(securityComponent.getCurrentUser().getUserName())) { + return; + } + String dataAuthority = currentUser.getDataAuthority(); + List dataAuthorityUserIds = currentUser.getDataAuthorityUserIds(); + if (org.apache.commons.lang3.StringUtils.equals(RoleDataAuthorityEnum.SELF.getDataAuthorityType(), dataAuthority)) { + params.put(ISystemConstant.DATA_AUTHORITY, dataAuthority); + params.put(ISystemConstant.DATA_CREATOR, currentUser.getUserId()); + } else if (org.apache.commons.lang3.StringUtils.equals(RoleDataAuthorityEnum.DEPARTMENT.getDataAuthorityType(), dataAuthority) + || org.apache.commons.lang3.StringUtils.equals(RoleDataAuthorityEnum.CUSTOM.getDataAuthorityType(), dataAuthority)) { + if (Objects.isNull(dataAuthorityUserIds) || dataAuthorityUserIds.isEmpty()) { + LOG.debug("权限列表为空,设置查看个人"); + params.put(ISystemConstant.DATA_AUTHORITY, RoleDataAuthorityEnum.SELF.getDataAuthorityType()); + params.put(ISystemConstant.DATA_CREATOR, currentUser.getUserId()); + } else { + params.put(ISystemConstant.DATA_AUTHORITY, dataAuthority); + params.put(ISystemConstant.DATA_CREATORS, dataAuthorityUserIds); + } + } + } + } diff --git a/cloud-common/src/main/java/com/cm/common/constants/ISystemConstant.java b/cloud-common/src/main/java/com/cm/common/constants/ISystemConstant.java index 8f59bb0..8d14580 100644 --- a/cloud-common/src/main/java/com/cm/common/constants/ISystemConstant.java +++ b/cloud-common/src/main/java/com/cm/common/constants/ISystemConstant.java @@ -116,6 +116,10 @@ public interface ISystemConstant { * 创建人 */ String DATA_CREATOR = "data_creator"; + /** + * 创建人列表 + */ + String DATA_CREATORS = "data_creators"; /** * 创建人列 */ diff --git a/cloud-common/src/main/java/com/cm/common/enums/AppTokenTypeEnum.java b/cloud-common/src/main/java/com/cm/common/enums/AppTokenTypeEnum.java new file mode 100644 index 0000000..68529b4 --- /dev/null +++ b/cloud-common/src/main/java/com/cm/common/enums/AppTokenTypeEnum.java @@ -0,0 +1,26 @@ +package com.cm.common.enums; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: AppTokenTypeEnum + * @Description: appToken类别 + * @Author: WangGeng + * @Date: 2020/3/8 10:09 上午 + * @Version: 1.0 + **/ +public enum AppTokenTypeEnum { + + WECHAT("wechat"), + APP("app"); + private String type; + + AppTokenTypeEnum(String type) { + this.type = type; + } + + public String getType() { + return type == null ? "" : type.trim(); + } +} diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/enums/role/RoleDataAuthorityEnum.java b/cloud-common/src/main/java/com/cm/common/enums/RoleDataAuthorityEnum.java similarity index 94% rename from cloud-common-plugin/src/main/java/com/cm/common/plugin/enums/role/RoleDataAuthorityEnum.java rename to cloud-common/src/main/java/com/cm/common/enums/RoleDataAuthorityEnum.java index e5b55ae..93a6ed9 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/enums/role/RoleDataAuthorityEnum.java +++ b/cloud-common/src/main/java/com/cm/common/enums/RoleDataAuthorityEnum.java @@ -1,4 +1,4 @@ -package com.cm.common.plugin.enums.role; +package com.cm.common.enums; /** * When you feel like quitting. Think about why you started diff --git a/cloud-common/src/main/java/com/cm/common/filter/AppFilter.java b/cloud-common/src/main/java/com/cm/common/filter/AppFilter.java index df5c73a..6ccb88f 100644 --- a/cloud-common/src/main/java/com/cm/common/filter/AppFilter.java +++ b/cloud-common/src/main/java/com/cm/common/filter/AppFilter.java @@ -1,6 +1,7 @@ package com.cm.common.filter; import com.alibaba.fastjson.JSON; +import com.cm.common.enums.AppTokenTypeEnum; import com.cm.common.enums.ErrorResultCodeEnum; import com.cm.common.exception.TokenException; import com.cm.common.result.ErrorResult; @@ -99,7 +100,7 @@ public class AppFilter implements Filter { } LOG.debug("解析token是否合法"); AppTokenUser appTokenUser = appTokenManager.parseToAppTokenUser(token); - appTokenManager.addToken(token, appTokenUser); + appTokenManager.addToken(token, AppTokenTypeEnum.APP, appTokenUser); } /** diff --git a/cloud-common/src/main/java/com/cm/common/token/app/AppTokenManager.java b/cloud-common/src/main/java/com/cm/common/token/app/AppTokenManager.java index 01834b6..6c40e21 100644 --- a/cloud-common/src/main/java/com/cm/common/token/app/AppTokenManager.java +++ b/cloud-common/src/main/java/com/cm/common/token/app/AppTokenManager.java @@ -2,6 +2,7 @@ package com.cm.common.token.app; import com.alibaba.fastjson.JSONObject; import com.cm.common.constants.ISystemConstant; +import com.cm.common.enums.AppTokenTypeEnum; import com.cm.common.exception.TokenException; import com.cm.common.token.app.entity.AppToken; import com.cm.common.token.app.entity.AppTokenUser; @@ -59,11 +60,13 @@ public class AppTokenManager { * 添加token * * @param token + * @param type * @param appTokenUser */ - public synchronized void addToken(String token, AppTokenUser appTokenUser) { + public synchronized void addToken(String token, AppTokenTypeEnum appTokenTypeEnum, AppTokenUser appTokenUser) { AppToken appToken = new AppToken(); appToken.setToken(token); + appToken.setAppTokenTypeEnum(appTokenTypeEnum); appToken.setLastTime(System.currentTimeMillis()); appToken.setAppTokenUser(appTokenUser); appToken.setUserId(appTokenUser.getId()); diff --git a/cloud-common/src/main/java/com/cm/common/token/app/entity/AppToken.java b/cloud-common/src/main/java/com/cm/common/token/app/entity/AppToken.java index fdbe603..1676d30 100644 --- a/cloud-common/src/main/java/com/cm/common/token/app/entity/AppToken.java +++ b/cloud-common/src/main/java/com/cm/common/token/app/entity/AppToken.java @@ -1,5 +1,7 @@ package com.cm.common.token.app.entity; +import com.cm.common.enums.AppTokenTypeEnum; + /** * When you feel like quitting. Think about why you started * 当你想要放弃的时候,想想当初你为何开始 @@ -13,6 +15,7 @@ package com.cm.common.token.app.entity; public class AppToken { private String token; + private AppTokenTypeEnum appTokenTypeEnum; private long lastTime; private String userId; private AppTokenUser appTokenUser; @@ -25,6 +28,14 @@ public class AppToken { this.token = token; } + public AppTokenTypeEnum getAppTokenTypeEnum() { + return appTokenTypeEnum; + } + + public void setAppTokenTypeEnum(AppTokenTypeEnum appTokenTypeEnum) { + this.appTokenTypeEnum = appTokenTypeEnum; + } + public long getLastTime() { return lastTime; } @@ -54,6 +65,8 @@ public class AppToken { final StringBuilder sb = new StringBuilder("{"); sb.append("\"token\":") .append("\"").append(token).append("\""); + sb.append(",\"appTokenTypeEnum\":") + .append(appTokenTypeEnum); sb.append(",\"lastTime\":") .append(lastTime); sb.append(",\"userId\":") diff --git a/pom.xml b/pom.xml index 089c486..56802b4 100644 --- a/pom.xml +++ b/pom.xml @@ -414,6 +414,21 @@ + + + org.apache.maven.plugins + maven-source-plugin + 2.1 + + + attach-sources + + jar + + + + + \ No newline at end of file