From 17c4508aada288c304032771e180ddf9f4c84d53 Mon Sep 17 00:00:00 2001 From: sxu <602087911@qq.com> Date: Fri, 14 Mar 2025 17:45:25 +0800 Subject: [PATCH] get token --- .../auth/oauth/controller/AuthController.java | 163 ++++++++------- .../core/auth/oauth/vo/OpenApiLoginVo.java | 49 +++++ .../canteen/core/config/SecureManager.java | 154 +++++++++++++++ .../modules/auth/constants/CheckEnum.java | 45 +++++ .../modules/auth/mapper/OpenAppMapper.java | 9 + .../core/open/modules/auth/model/OpenApp.java | 187 ++++++++++++++++++ .../modules/auth/service/OpenAppService.java | 22 +++ .../auth/service/impl/OpenAppServiceImpl.java | 54 +++++ 8 files changed, 599 insertions(+), 84 deletions(-) create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/vo/OpenApiLoginVo.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/config/SecureManager.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/open/modules/auth/constants/CheckEnum.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/open/modules/auth/mapper/OpenAppMapper.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/open/modules/auth/model/OpenApp.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/open/modules/auth/service/OpenAppService.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/open/modules/auth/service/impl/OpenAppServiceImpl.java diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/controller/AuthController.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/controller/AuthController.java index bfa05e43..1ece9be1 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/controller/AuthController.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/controller/AuthController.java @@ -9,14 +9,19 @@ import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.bonus.canteen.core.auth.oauth.util.OAuthUtil; +import com.bonus.canteen.core.auth.oauth.vo.OpenApiLoginVo; import com.bonus.canteen.core.auth.user.dto.UserLoginDTO; -import com.bonus.canteen.core.config.AccessToken; -import com.bonus.canteen.core.config.SecureProperties; -import com.bonus.canteen.core.config.SmUtils; -import com.bonus.canteen.core.config.WebContext; +import com.bonus.canteen.core.common.utils.TenantContextHolder; +import com.bonus.canteen.core.config.*; import com.bonus.canteen.core.customer.model.PigxUser; import com.bonus.canteen.core.device.mq.MacMessageService; +import com.bonus.canteen.core.merchant.entity.MercMerchant; +import com.bonus.canteen.core.open.modules.auth.constants.CheckEnum; +import com.bonus.canteen.core.open.modules.auth.model.OpenApp; +import com.bonus.canteen.core.open.modules.auth.service.OpenAppService; +import com.bonus.common.core.exception.ServiceException; import com.bonus.common.core.web.domain.AjaxResult; +import com.bonus.common.houqin.constant.LeConstants; import com.google.common.base.Joiner; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -66,35 +71,33 @@ public class AuthController { // @Autowired // @Lazy // BackDeviceApi backDeviceApi; -// @Autowired -// private OpenAppService openAppService; + @Autowired + private OpenAppService openAppService; -// @RequireVerifyCode -// @PostMapping({"/web/token"}) -// @RequiresGuest -// @ApiOperation("web登陆") -// public LeResponse webLogin(@RequestParam String content) { -// MgrUserLoginDTO loginDTO = (MgrUserLoginDTO)JSON.parseObject(content, MgrUserLoginDTO.class); -// -// JSONObject object; -// try { -// PigxUser user = this.mgrUserService.login(loginDTO); -// object = JSON.parseObject(JSON.toJSONString(user)); -// if (ObjectUtil.isNotNull(user.getMerchantId())) { -// TenantContextHolder.setTenantId(user.getMerchantId()); -// MercMerchant mercMerchant = this.mercMerchantApi.getMerchant(); -// object.put("merchantName", mercMerchant.getMerchantName()); -// } -// -// if (WebContext.get().getAccessToken().isPresent()) { -// object.put("securityTokenSign", OAuthUtil.responseSetSecurityTokenSign(user.getMerchantId(), ((AccessToken)WebContext.get().getAccessToken().get()).getId())); -// } -// } catch (LeCheckedException var6) { -// return LeResponse.fail(var6.getMessage()); -// } -// -// return LeResponse.succ(object); -// } + @PostMapping({"/web/token"}) + @ApiOperation("web登陆") + public AjaxResult webLogin(@RequestParam String content) { + UserLoginDTO loginDTO = (UserLoginDTO)JSON.parseObject(content, UserLoginDTO.class); + + JSONObject object; + try { + PigxUser user = new PigxUser(); //this.mgrUserService.login(loginDTO); + object = JSON.parseObject(JSON.toJSONString(user)); + if (ObjectUtil.isNotNull(user.getMerchantId())) { + TenantContextHolder.setTenantId(user.getMerchantId()); + MercMerchant mercMerchant = this.mercMerchantApi.getMerchant(); + object.put("merchantName", mercMerchant.getMerchantName()); + } + + if (WebContext.get().getAccessToken().isPresent()) { + object.put("securityTokenSign", OAuthUtil.responseSetSecurityTokenSign(user.getMerchantId(), ((AccessToken)WebContext.get().getAccessToken().get()).getId())); + } + } catch (Exception var6) { + return AjaxResult.error(var6.getMessage()); + } + + return AjaxResult.success(object); + } @PostMapping({"/token"}) @ApiOperation("设备登陆接口登陆") @@ -117,18 +120,13 @@ public class AuthController { return AjaxResult.success(object); } -// @DeleteMapping({"/logOut"}) -// @RequiresAuthentication -// @ApiOperation("退出登陆") -// @AnLogRecord( -// value = "退出登录", -// type = LogRecordOperTypeEnum.SIGN_OUT -// ) -// public LeResponse logOut() { -// SecureManager.logout(); -// return LeResponse.succ("操作成功"); -// } -// + @DeleteMapping({"/logOut"}) + @ApiOperation("退出登陆") + public AjaxResult logOut() { + SecureManager.logout(); + return AjaxResult.success("操作成功"); + } + // @PostMapping({"/public/login"}) // @RequiresGuest // @ApiOperation("采购库存公众号登陆接口") @@ -158,7 +156,6 @@ public class AuthController { // // @ApiOperation("web-单点登陆") // @PostMapping({"/web/single-sign-on"}) -// @RequiresGuest // public PigxUser webSingleSignOn(@RequestParam("tenantId") Long tenantId, @RequestBody LeRequest request) { // return this.mgrUserService.webSingleSignOn(tenantId, (MgrUserSsoDTO)request.getContent()); // } @@ -232,44 +229,42 @@ public class AuthController { return SmUtils.signAuthTokenBySm3(paramMap, clientKey); } -// @ApiOperation("openapi认证") -// @PostMapping({"/openapi/login"}) -// @RequiresGuest -// @ResponseWrapperByPass -// public OpenApiLoginVo openApiLogin(@RequestHeader Map header, @RequestBody Map content) { -// String appIdEncrypt = (String)content.get("content"); -// if (ObjectUtil.isNull(appIdEncrypt)) { -// throw new LeException(CheckEnum.VALID_APPID_MISS.getCode(), CheckEnum.VALID_APPID_MISS.getErrorMsg()); -// } else { -// String appIdStr = SmUtils.decryptBySm2(appIdEncrypt); -// if (!NumberUtil.isLong(appIdStr)) { -// throw new LeException(CheckEnum.VALID_APPID_FORMAT_ERROR.getCode(), CheckEnum.VALID_APPID_FORMAT_ERROR.getErrorMsg()); -// } else { -// Long appid = Long.parseLong(appIdStr); -// OpenApp app = this.openAppService.getAppInfoByAppId(appid); -// if (ObjectUtil.isNull(app)) { -// throw new LeException(CheckEnum.VALID_APPID_ERROR.getCode(), CheckEnum.VALID_APPID_ERROR.getErrorMsg()); -// } else if (ObjectUtil.equals(app.getDisable(), LeConstants.COMMON_YES)) { -// throw new LeException(CheckEnum.VALID_APPID_DISABLE.getCode(), CheckEnum.VALID_APPID_DISABLE.getErrorMsg()); -// } else { -// LocalDateTime startTime = app.getStartTime(); -// LocalDateTime endTime = app.getEndTime(); -// LocalDateTime now = LocalDateTime.now(); -// if (ObjectUtil.isNotNull(startTime) && now.isBefore(startTime)) { -// throw new LeException(CheckEnum.VALID_APPID_BEFORE.getCode(), CheckEnum.VALID_APPID_BEFORE.getErrorMsg()); -// } else if (ObjectUtil.isNotNull(endTime) && now.isAfter(endTime)) { -// throw new LeException(CheckEnum.VALID_APPID_EXPIRED.getCode(), CheckEnum.VALID_APPID_EXPIRED.getErrorMsg()); -// } else { -// String encryptKey = HeaderFetchUtil.getValueFromHeadersIgnoreCase(header, this.secureProperties.getSecurity().getServerEncryptedClientKeyHeaderName()); -// String clientKey = SmUtils.decryptBySm4WithServerKey(encryptKey); -// String token = this.generatorToken(String.valueOf(appid), clientKey, app.getTenantId()); -// OpenApiLoginVo loginVo = new OpenApiLoginVo(); -// loginVo.setToken(token).setTenantId(app.getTenantId()).setSecurityTokenSign(OAuthUtil.responseSetSecurityTokenSign(app.getTenantId(), token)).setAppName(app.getAppName()); -// return loginVo; -// } -// } -// } -// } -// } + @ApiOperation("openapi认证") + @PostMapping({"/openapi/login"}) + public OpenApiLoginVo openApiLogin(@RequestHeader Map header, @RequestBody Map content) { + String appIdEncrypt = (String)content.get("content"); + if (ObjectUtil.isNull(appIdEncrypt)) { + throw new ServiceException(CheckEnum.VALID_APPID_MISS.getCode() + CheckEnum.VALID_APPID_MISS.getErrorMsg()); + } else { + String appIdStr = SmUtils.decryptBySm2(appIdEncrypt); + if (!NumberUtil.isLong(appIdStr)) { + throw new ServiceException(CheckEnum.VALID_APPID_FORMAT_ERROR.getCode() + CheckEnum.VALID_APPID_FORMAT_ERROR.getErrorMsg()); + } else { + Long appid = Long.parseLong(appIdStr); + OpenApp app = this.openAppService.getAppInfoByAppId(appid); + if (ObjectUtil.isNull(app)) { + throw new ServiceException(CheckEnum.VALID_APPID_ERROR.getCode() + CheckEnum.VALID_APPID_ERROR.getErrorMsg()); + } else if (ObjectUtil.equals(app.getDisable(), LeConstants.COMMON_YES)) { + throw new ServiceException(CheckEnum.VALID_APPID_DISABLE.getCode() + CheckEnum.VALID_APPID_DISABLE.getErrorMsg()); + } else { + LocalDateTime startTime = app.getStartTime(); + LocalDateTime endTime = app.getEndTime(); + LocalDateTime now = LocalDateTime.now(); + if (ObjectUtil.isNotNull(startTime) && now.isBefore(startTime)) { + throw new ServiceException(CheckEnum.VALID_APPID_BEFORE.getCode() + CheckEnum.VALID_APPID_BEFORE.getErrorMsg()); + } else if (ObjectUtil.isNotNull(endTime) && now.isAfter(endTime)) { + throw new ServiceException(CheckEnum.VALID_APPID_EXPIRED.getCode() + CheckEnum.VALID_APPID_EXPIRED.getErrorMsg()); + } else { + String encryptKey = HeaderFetchUtil.getValueFromHeadersIgnoreCase(header, this.secureProperties.getSecurity().getServerEncryptedClientKeyHeaderName()); + String clientKey = SmUtils.decryptBySm4WithServerKey(encryptKey); + String token = this.generatorToken(String.valueOf(appid), clientKey, app.getTenantId()); + OpenApiLoginVo loginVo = new OpenApiLoginVo(); + loginVo.setToken(token).setTenantId(app.getTenantId()).setSecurityTokenSign(OAuthUtil.responseSetSecurityTokenSign(app.getTenantId(), token)).setAppName(app.getAppName()); + return loginVo; + } + } + } + } + } } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/vo/OpenApiLoginVo.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/vo/OpenApiLoginVo.java new file mode 100644 index 00000000..d6694531 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/vo/OpenApiLoginVo.java @@ -0,0 +1,49 @@ +package com.bonus.canteen.core.auth.oauth.vo; + +public class OpenApiLoginVo { + private Long tenantId; + private String securityTokenSign; + private String token; + private String appName; + + public Long getTenantId() { + return this.tenantId; + } + + public String getSecurityTokenSign() { + return this.securityTokenSign; + } + + public String getToken() { + return this.token; + } + + public String getAppName() { + return this.appName; + } + + public OpenApiLoginVo setTenantId(final Long tenantId) { + this.tenantId = tenantId; + return this; + } + + public OpenApiLoginVo setSecurityTokenSign(final String securityTokenSign) { + this.securityTokenSign = securityTokenSign; + return this; + } + + public OpenApiLoginVo setToken(final String token) { + this.token = token; + return this; + } + + public OpenApiLoginVo setAppName(final String appName) { + this.appName = appName; + return this; + } + + public String toString() { + Long var10000 = this.getTenantId(); + return "OpenApiLoginVo(tenantId=" + var10000 + ", securityTokenSign=" + this.getSecurityTokenSign() + ", token=" + this.getToken() + ", appName=" + this.getAppName() + ")"; + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/config/SecureManager.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/config/SecureManager.java new file mode 100644 index 00000000..92cdcf34 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/config/SecureManager.java @@ -0,0 +1,154 @@ +package com.bonus.canteen.core.config; + +import cn.hutool.core.map.MapUtil; +import com.bonus.canteen.core.customer.service.AuthorizingService; +import com.bonus.canteen.core.secure.PmsCache; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.ListUtils; +import org.apache.commons.lang3.BooleanUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.data.redis.core.BoundHashOperations; +import org.springframework.data.redis.core.StringRedisTemplate; +import java.time.Instant; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class SecureManager { + private static final Logger log = LoggerFactory.getLogger(SecureManager.class); + private static SecureProperties secureProperties; + private static StringRedisTemplate redisTemplate; + private static AuthorizingService authorizingService; + private static ObjectMapper objectMapper; + + private SecureManager() { + } + + public static void setSecureProperties(SecureProperties secureProperties) { + if (SecureManager.secureProperties == null) { + SecureManager.secureProperties = secureProperties; + } + } + + public static void setRedisTemplate(StringRedisTemplate redisTemplate) { + if (SecureManager.redisTemplate == null) { + SecureManager.redisTemplate = redisTemplate; + } + } + + public static void setAuthorizingService(AuthorizingService authorizingService) { + if (SecureManager.authorizingService == null) { + SecureManager.authorizingService = authorizingService; + } + } + + public static void setObjectMapper(ObjectMapper objectMapper) { + if (SecureManager.objectMapper == null) { + SecureManager.objectMapper = objectMapper; + } + } + + private static String getPmsKey(long subjectId) { + return "permissions:subject_id:" + subjectId; + } + + private static String getRoleKey(long subjectId) { + return "roles:subject_id:" + subjectId; + } + + public static void clearAllRoleAndPermission() { + redisTemplate.delete(secureProperties.getPermissionKey()); + } + + public static void clearRoleAndPermission(long subjectId) { + redisTemplate.boundHashOps(secureProperties.getPermissionKey()).delete(new Object[]{getRoleKey(subjectId), getPmsKey(subjectId)}); + } + + public static void clearRole(long subjectId) { + redisTemplate.boundHashOps(secureProperties.getPermissionKey()).delete(new Object[]{getRoleKey(subjectId)}); + } + + public static void clearPermission(long subjectId) { + redisTemplate.boundHashOps(secureProperties.getPermissionKey()).delete(new Object[]{getPmsKey(subjectId)}); + } + + public static boolean isLogin() { + return (Boolean)WebContext.get().getAccessToken().map(AccessToken::isAuthenticated).orElse(false); + } + + public static Optional getSubjectId() { + return WebContext.get().getAccessToken().map(AccessToken::getSubjectId); + } + + public static Optional getSubjectName() { + return WebContext.get().getAccessToken().map(AccessToken::getSubjectName); + } + + public static Map getSubjectData() { + return (Map)WebContext.get().getAccessToken().map(AccessToken::getSubjectData).orElse(Maps.newHashMap()); + } + + public static Map attachData(Map data) { + try { + if (MapUtil.isEmpty(data)) { + return Maps.newHashMapWithExpectedSize(0); + } else { + AccessToken accessToken = (AccessToken)WebContext.get().getAccessToken().orElse(AccessToken.create()); + Objects.requireNonNull(accessToken); + data.forEach(accessToken::setData); + accessToken.bind().store(); + return accessToken.getSubjectData(); + } + } catch (Throwable var2) { + throw var2; + } + } + + public static Map attachData(String key, String value) { + try { + return attachData(Collections.singletonMap(key, value)); + } catch (Throwable var3) { + throw var3; + } + } + + public static void logout() { + WebContext.get().getAccessToken().ifPresent(AccessToken::clear); + } + + public static void revokeAuthenticate() { + WebContext.get().getAccessToken().ifPresent((accessToken) -> { + accessToken.revokeAuthenticate().store(); + }); + } + + public static void revokeAuthenticate(long subjectId, int reservedRecentNum) { + StringRedisTemplate var10000 = redisTemplate; + String var10001 = secureProperties.getServer().getSubjectRefTokenKey(); + Set keys = var10000.keys(var10001 + ":" + subjectId + ":*"); + if (CollectionUtils.size(keys) > reservedRecentNum) { + assert keys != null; + + Map> createTimeAsc_keys = (Map)keys.stream().collect(Collectors.groupingBy((key) -> { + return Long.parseLong(key.split(":")[4]); + }, TreeMap::new, Collectors.toList())); + List keysAsc = createTimeAsc_keys.values().stream().flatMap(Collection::stream).collect(Collectors.toList()); + List beDeleteRefKeys = keysAsc.subList(0, keysAsc.size() - reservedRecentNum); + List beDeleteTokenKeys = beDeleteRefKeys.stream().map((dk) -> { + String var100001 = secureProperties.getServer().getStoreKey(); + return var100001 + ":" + dk.split(":")[3]; + }).collect(Collectors.toList()); + redisTemplate.delete(ListUtils.sum(beDeleteRefKeys, beDeleteTokenKeys)); + } + } + + public String toString() { + return "SecureManager()"; + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/open/modules/auth/constants/CheckEnum.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/open/modules/auth/constants/CheckEnum.java new file mode 100644 index 00000000..44cc1cd0 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/open/modules/auth/constants/CheckEnum.java @@ -0,0 +1,45 @@ +package com.bonus.canteen.core.open.modules.auth.constants; + +public enum CheckEnum { + VALID_ERROR_PARAMS(100010, "参数不正确"), + VALID_TIMESTAMP_MISS(100011, "未提供请求时间戳"), + VALID_TIMESTAMP_ERROR(100012, "时间戳格式错误"), + VALID_TIMESTAMP_TIMEOUT(100013, "请求超出有效时间"), + VALID_APPID_MISS(100021, "未提供应用ID"), + VALID_APPID_EXPIRED(100022, "应用授权过期或未生效"), + VALID_APPID_BEFORE(100023, "应用授权还未生效"), + VALID_APPID_ERROR(100024, "应用ID错误"), + VALID_APPID_URL_MISS(100025, "URL不存在或未授权"), + VALID_APPID_DISABLE(100026, "应用未启用"), + VALID_APPID_FORMAT_ERROR(100027, "应用ID格式不正确"), + VALID_NONCE_MISS(100031, "未提供请求随机数"), + VALID_NONCE_REPEAT(100032, "不允许重复请求"), + VALID_NONCE_LENGTH(100033, "随机数长度有误"), + VALID_SIGN_MISS(100041, "未提供签名"), + VALID_SIGN_ERROR(100042, "签名错误"), + VALID_SIGNTYPE_ERROR(100043, "签名方法错误"), + VALID_URL_ERROR(100051, "URL不存在"), + VALID_URL_BUSY(100052, "资源繁忙"), + VALID_MERCHANTID_ERROR(100061, "商户号不存在"), + VALID_TOKEN_ERROR(100062, "token无效"), + VALID_TOKEN(100063, "token 过期"), + VALID_TIMESTAMP_FORMAT_ERROR(100014, "APP-ID格式不正确"), + VALID_TIMESTAMP_MERCHANTID_FORMAT_ERROR(100015, "商户号格式不正确"), + VALID_TIMESTAMP_MERCHANTID_ERROR(100016, "商户号不正确"); + + private final Integer code; + private final String errorMsg; + + public Integer getCode() { + return this.code; + } + + public String getErrorMsg() { + return this.errorMsg; + } + + private CheckEnum(final Integer code, final String errorMsg) { + this.code = code; + this.errorMsg = errorMsg; + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/open/modules/auth/mapper/OpenAppMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/open/modules/auth/mapper/OpenAppMapper.java new file mode 100644 index 00000000..457017dc --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/open/modules/auth/mapper/OpenAppMapper.java @@ -0,0 +1,9 @@ +package com.bonus.canteen.core.open.modules.auth.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.bonus.canteen.core.open.modules.auth.model.OpenApp; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface OpenAppMapper extends BaseMapper { +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/open/modules/auth/model/OpenApp.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/open/modules/auth/model/OpenApp.java new file mode 100644 index 00000000..d0f5b2bd --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/open/modules/auth/model/OpenApp.java @@ -0,0 +1,187 @@ +package com.bonus.canteen.core.open.modules.auth.model; + +import com.baomidou.mybatisplus.annotation.*; +import com.baomidou.mybatisplus.extension.activerecord.Model; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import java.time.LocalDateTime; + +@TableName("open_app") +@ApiModel("接入应用") +public class OpenApp extends Model { + private static final long serialVersionUID = 1L; + @TableId + @ApiModelProperty("主键") + private Long appId; + @ApiModelProperty("应用秘钥") + private String appSecret; + @ApiModelProperty("应用名称") + private String appName; + @ApiModelProperty("商户id") + private Long tenantId; + @TableField( + updateStrategy = FieldStrategy.IGNORED + ) + @ApiModelProperty("有效起始时间") + private LocalDateTime startTime; + @TableField( + updateStrategy = FieldStrategy.IGNORED + ) + @ApiModelProperty("有效结束时间") + private LocalDateTime endTime; + @TableField( + updateStrategy = FieldStrategy.IGNORED + ) + @ApiModelProperty("备注") + private String remark; + @ApiModelProperty("是否禁用") + private Integer disable; + @ApiModelProperty("删除标志") + private Integer delFlag; + @TableField( + value = "crby", + fill = FieldFill.INSERT + ) + @ApiModelProperty("创建人") + private String crby; + @TableField( + value = "crtime", + fill = FieldFill.INSERT + ) + @ApiModelProperty("创建时间") + private LocalDateTime crtime; + @TableField( + value = "upby", + fill = FieldFill.UPDATE + ) + @ApiModelProperty("更新人") + private String upby; + @TableField( + value = "uptime", + fill = FieldFill.UPDATE + ) + @ApiModelProperty("更新时间") + private LocalDateTime uptime; + + public Long getAppId() { + return this.appId; + } + + public String getAppSecret() { + return this.appSecret; + } + + public String getAppName() { + return this.appName; + } + + public Long getTenantId() { + return this.tenantId; + } + + public LocalDateTime getStartTime() { + return this.startTime; + } + + public LocalDateTime getEndTime() { + return this.endTime; + } + + public String getRemark() { + return this.remark; + } + + public Integer getDisable() { + return this.disable; + } + + public Integer getDelFlag() { + return this.delFlag; + } + + public String getCrby() { + return this.crby; + } + + public LocalDateTime getCrtime() { + return this.crtime; + } + + public String getUpby() { + return this.upby; + } + + public LocalDateTime getUptime() { + return this.uptime; + } + + public OpenApp setAppId(final Long appId) { + this.appId = appId; + return this; + } + + public OpenApp setAppSecret(final String appSecret) { + this.appSecret = appSecret; + return this; + } + + public OpenApp setAppName(final String appName) { + this.appName = appName; + return this; + } + + public OpenApp setTenantId(final Long tenantId) { + this.tenantId = tenantId; + return this; + } + + public OpenApp setStartTime(final LocalDateTime startTime) { + this.startTime = startTime; + return this; + } + + public OpenApp setEndTime(final LocalDateTime endTime) { + this.endTime = endTime; + return this; + } + + public OpenApp setRemark(final String remark) { + this.remark = remark; + return this; + } + + public OpenApp setDisable(final Integer disable) { + this.disable = disable; + return this; + } + + public OpenApp setDelFlag(final Integer delFlag) { + this.delFlag = delFlag; + return this; + } + + public OpenApp setCrby(final String crby) { + this.crby = crby; + return this; + } + + public OpenApp setCrtime(final LocalDateTime crtime) { + this.crtime = crtime; + return this; + } + + public OpenApp setUpby(final String upby) { + this.upby = upby; + return this; + } + + public OpenApp setUptime(final LocalDateTime uptime) { + this.uptime = uptime; + return this; + } + + public String toString() { + Long var10000 = this.getAppId(); + return "OpenApp(appId=" + var10000 + ", appSecret=" + this.getAppSecret() + ", appName=" + this.getAppName() + ", tenantId=" + this.getTenantId() + ", startTime=" + String.valueOf(this.getStartTime()) + ", endTime=" + String.valueOf(this.getEndTime()) + ", remark=" + this.getRemark() + ", disable=" + this.getDisable() + ", delFlag=" + this.getDelFlag() + ", crby=" + this.getCrby() + ", crtime=" + String.valueOf(this.getCrtime()) + ", upby=" + this.getUpby() + ", uptime=" + String.valueOf(this.getUptime()) + ")"; + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/open/modules/auth/service/OpenAppService.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/open/modules/auth/service/OpenAppService.java new file mode 100644 index 00000000..7f694031 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/open/modules/auth/service/OpenAppService.java @@ -0,0 +1,22 @@ +package com.bonus.canteen.core.open.modules.auth.service; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; +import com.bonus.canteen.core.open.modules.auth.model.OpenApp; + + +public interface OpenAppService extends IService { +// Page page(OpenAppSearchVO searchVO); +// +// void add(OpenAppEditVO openAppEditVO); +// +// void update(OpenAppEditVO openAppEditVO); + +// void remove(Long appId); +// +// void disable(Long appId); +// +// void enable(Long appId); + + OpenApp getAppInfoByAppId(Long appId); +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/open/modules/auth/service/impl/OpenAppServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/open/modules/auth/service/impl/OpenAppServiceImpl.java new file mode 100644 index 00000000..a79650b9 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/open/modules/auth/service/impl/OpenAppServiceImpl.java @@ -0,0 +1,54 @@ +package com.bonus.canteen.core.open.modules.auth.service.impl; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.IdUtil; +import com.baomidou.mybatisplus.core.conditions.Wrapper; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.bonus.canteen.core.open.modules.auth.mapper.OpenAppMapper; +import com.bonus.canteen.core.open.modules.auth.model.OpenApp; +import com.bonus.canteen.core.open.modules.auth.service.OpenAppService; +import org.springframework.stereotype.Service; + +import java.lang.invoke.SerializedLambda; +import java.util.Objects; + +@Service +public class OpenAppServiceImpl extends ServiceImpl implements OpenAppService { +// public Page page(OpenAppSearchVO searchVO) { +// return (Page)this.page(searchVO.getPage(), (Wrapper)((LambdaQueryWrapper)((LambdaQueryWrapper)((LambdaQueryWrapper)((LambdaQueryWrapper)Wrappers.lambdaQuery().and(Objects.nonNull(searchVO.getKeyword()), (e) -> { +// ((LambdaQueryWrapper)((LambdaQueryWrapper)e.like(OpenApp::getAppName, searchVO.getKeyword())).or()).like(OpenApp::getRemark, searchVO.getKeyword()); +// })).eq(Objects.nonNull(searchVO.getTenantId()), OpenApp::getTenantId, searchVO.getTenantId())).eq(Objects.nonNull(searchVO.getDisable()), OpenApp::getDisable, searchVO.getDisable())).eq(OpenApp::getDelFlag, LeConstants.COMMON_NO)).orderByDesc(OpenApp::getCrtime)); +// } +// +// public void add(OpenAppEditVO openAppEditVO) { +// OpenApp openApp = (OpenApp)BeanUtil.copyProperties(openAppEditVO, OpenApp.class, new String[0]); +// openApp.setAppId(Id.next()).setAppSecret(IdUtil.fastSimpleUUID()); +// this.save(openApp); +// } +// +// public void update(OpenAppEditVO openAppEditVO) { +// OpenApp openApp = (OpenApp)BeanUtil.copyProperties(openAppEditVO, OpenApp.class, new String[0]); +// this.updateById(openApp); +// } + +// public void remove(Long appId) { +// this.update((Wrapper)((LambdaUpdateWrapper)Wrappers.lambdaUpdate().eq(OpenApp::getAppId, appId)).set(OpenApp::getDelFlag, LeConstants.COMMON_YES)); +// } +// +// public void disable(Long appId) { +// this.update((Wrapper)((LambdaUpdateWrapper)Wrappers.lambdaUpdate().eq(OpenApp::getAppId, appId)).set(OpenApp::getDisable, LeConstants.COMMON_YES)); +// } +// +// public void enable(Long appId) { +// this.update((Wrapper)((LambdaUpdateWrapper)Wrappers.lambdaUpdate().eq(OpenApp::getAppId, appId)).set(OpenApp::getDisable, LeConstants.COMMON_NO)); +// } + + public OpenApp getAppInfoByAppId(Long appId) { + return (OpenApp)this.getById(appId); + } + +}