From 595d0e53b9391b08083232002be46c71b61cd17f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?niohe=C2=B7erbao?= Date: Tue, 14 Mar 2023 15:59:00 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=8F=91=E9=80=81=E7=9F=AD=E4=BF=A1?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pmapi/pom.xml | 5 + .../sms/controller/VerificationCodeController.java | 2 +- .../com/ningdatech/pmapi/sms/manage/SmsManage.java | 121 +++++++++++---------- pmapi/src/main/resources/security/auth-dev.yml | 2 + 4 files changed, 70 insertions(+), 60 deletions(-) diff --git a/pmapi/pom.xml b/pmapi/pom.xml index 1314c06..4aea8f4 100644 --- a/pmapi/pom.xml +++ b/pmapi/pom.xml @@ -191,6 +191,11 @@ nd-basic + com.ningdatech + nd-yxt-starter + 1.0.0 + + com.alibaba easyexcel-core diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sms/controller/VerificationCodeController.java b/pmapi/src/main/java/com/ningdatech/pmapi/sms/controller/VerificationCodeController.java index b766142..1b6733e 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sms/controller/VerificationCodeController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sms/controller/VerificationCodeController.java @@ -35,7 +35,7 @@ public class VerificationCodeController { @ApiOperation(value = "发送验证码", notes = "发送验证码") @PostMapping(value = "/send") public void send(@Validated @RequestBody ReqVerificationCodePO request) { -// smsManage.sendVerificationCode(request); + smsManage.sendVerificationCode(request); } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sms/manage/SmsManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/sms/manage/SmsManage.java index 3465c5b..5c6fb2e 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sms/manage/SmsManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sms/manage/SmsManage.java @@ -11,6 +11,9 @@ import com.ningdatech.pmapi.sms.model.dto.VerifyCodeCacheDTO; import com.ningdatech.pmapi.sms.model.po.ReqVerificationCodePO; import com.ningdatech.pmapi.sms.utils.DateUtil; import com.ningdatech.pmapi.sms.utils.SmsRedisKeyUtils; +import com.ningdatech.yxt.client.YxtClient; +import com.ningdatech.yxt.constants.YxtSmsSignEnum; +import com.ningdatech.yxt.model.cmd.SendSmsCmd; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -29,65 +32,65 @@ import java.util.Collections; @Component @RequiredArgsConstructor public class SmsManage { -// -// private final YxtClient yxtClient; -// private final CachePlusOps cachePlusOps; -// -// public void sendVerificationCode(ReqVerificationCodePO request) { -// Assert.isTrue(PhoneUtil.isMobile(request.getMobile()), "手机号码格式不正确"); -// String verificationType = request.getVerificationType(); -// VerificationCodeType verificationCodeTypeEnum = VerificationCodeType.of(verificationType); -// -// // 验证是否被锁定 -// String lockKey = SmsRedisKeyUtils.smsSendLockKey(verificationCodeTypeEnum, request.getMobile()); -// if (StringUtils.isNotBlank(cachePlusOps.get(lockKey))) { -// throw BizException.wrap("今日" + verificationCodeTypeEnum.getDesc() + "的验证码发送次数过多,已被锁定"); -// } -// // 验证发送间隔 -// String cacheKey = SmsRedisKeyUtils.smsCodeVerifyKey(verificationCodeTypeEnum, request.getMobile()); -// VerifyCodeCacheDTO preCache = (VerifyCodeCacheDTO) cachePlusOps.get(cacheKey); -// if (preCache != null) { -// if (LocalDateTime.now().minusMinutes(verificationCodeTypeEnum.getSendInterval()) -// .isBefore(preCache.getSendTime())) { -// throw BizException.wrap(verificationCodeTypeEnum.getSendInterval() + "分钟之内已发送过验证码,请稍后重试"); -// } -// } -// String code = RandomUtil.randomNumbers(6); -// VerifyCodeCacheDTO cache = VerifyCodeCacheDTO.builder() -// .code(code) -// .sendTime(LocalDateTime.now()) -// .mobile(request.getMobile()) -// .build(); -// -// // 创建短信内容 -// SendSmsCmd sendSmsCmd = new SendSmsCmd(); -// switch (verificationCodeTypeEnum) { -// case LOGIN: -// SendSmsCmd.SendSmsContext sendSmsContext = new SendSmsCmd.SendSmsContext(); -// sendSmsContext.setReceiveNumber(request.getMobile()); -// sendSmsContext.setContent(String.format(YxtSmsTemplateConst.SMS_LOGIN_TEMPLATE, code, verificationCodeTypeEnum.getExpireTime())); -// sendSmsCmd.setContextList(Collections.singletonList(sendSmsContext)); -// sendSmsCmd.setSmsSignEnum(YxtSmsSignEnum.ZJS_ELECTRONIC_EXPERT_LIB); -// break; -// default: -// throw new IllegalArgumentException("非法的短信发送类型"); -// } -// // 发送 短信 -// yxtClient.submitSmsTask(sendSmsCmd); -// log.info("send verificationCode mobile = {},code = {}", request.getMobile(), code); -// -// cachePlusOps.set(new CacheKey(cacheKey, Duration.ofMinutes(verificationCodeTypeEnum.getExpireTime())), cache); -// String limitKey = SmsRedisKeyUtils.smsSendLimitKey(verificationCodeTypeEnum, request.getMobile()); -// if (StringUtils.isNotBlank(cachePlusOps.get(limitKey))) { -// long limitCount = cachePlusOps.incr(new CacheKey(limitKey, Duration.ofSeconds(DateUtil.restSecondsFromNowToNoon()))); -// // 超出单日发送次数之后直接锁定 -// if (limitCount >= verificationCodeTypeEnum.getSendTimesByDay().longValue()) { -// cachePlusOps.set(new CacheKey(lockKey, Duration.ofSeconds(DateUtil.restSecondsFromNowToNoon())), request.getMobile()); -// } -// } else { -// cachePlusOps.set(new CacheKey(limitKey, Duration.ofSeconds(DateUtil.restSecondsFromNowToNoon())), 1); -// } -// } + + private final YxtClient yxtClient; + private final CachePlusOps cachePlusOps; + + public void sendVerificationCode(ReqVerificationCodePO request) { + Assert.isTrue(PhoneUtil.isMobile(request.getMobile()), "手机号码格式不正确"); + String verificationType = request.getVerificationType(); + VerificationCodeType verificationCodeTypeEnum = VerificationCodeType.of(verificationType); + + // 验证是否被锁定 + String lockKey = SmsRedisKeyUtils.smsSendLockKey(verificationCodeTypeEnum, request.getMobile()); + if (StringUtils.isNotBlank(cachePlusOps.get(lockKey))) { + throw BizException.wrap("今日" + verificationCodeTypeEnum.getDesc() + "的验证码发送次数过多,已被锁定"); + } + // 验证发送间隔 + String cacheKey = SmsRedisKeyUtils.smsCodeVerifyKey(verificationCodeTypeEnum, request.getMobile()); + VerifyCodeCacheDTO preCache = (VerifyCodeCacheDTO) cachePlusOps.get(cacheKey); + if (preCache != null) { + if (LocalDateTime.now().minusMinutes(verificationCodeTypeEnum.getSendInterval()) + .isBefore(preCache.getSendTime())) { + throw BizException.wrap(verificationCodeTypeEnum.getSendInterval() + "分钟之内已发送过验证码,请稍后重试"); + } + } + String code = RandomUtil.randomNumbers(6); + VerifyCodeCacheDTO cache = VerifyCodeCacheDTO.builder() + .code(code) + .sendTime(LocalDateTime.now()) + .mobile(request.getMobile()) + .build(); + + // 创建短信内容 + SendSmsCmd sendSmsCmd = new SendSmsCmd(); + switch (verificationCodeTypeEnum) { + case LOGIN: + SendSmsCmd.SendSmsContext sendSmsContext = new SendSmsCmd.SendSmsContext(); + sendSmsContext.setReceiveNumber(request.getMobile()); + sendSmsContext.setContent(String.format(YxtSmsTemplateConst.SMS_LOGIN_TEMPLATE, code, verificationCodeTypeEnum.getExpireTime())); + sendSmsCmd.setContextList(Collections.singletonList(sendSmsContext)); + sendSmsCmd.setSmsSignEnum(YxtSmsSignEnum.ZJS_ELECTRONIC_EXPERT_LIB); + break; + default: + throw new IllegalArgumentException("非法的短信发送类型"); + } + // 发送 短信 + yxtClient.submitSmsTask(sendSmsCmd); + log.info("send verificationCode mobile = {},code = {}", request.getMobile(), code); + + cachePlusOps.set(new CacheKey(cacheKey, Duration.ofMinutes(verificationCodeTypeEnum.getExpireTime())), cache); + String limitKey = SmsRedisKeyUtils.smsSendLimitKey(verificationCodeTypeEnum, request.getMobile()); + if (StringUtils.isNotBlank(cachePlusOps.get(limitKey))) { + long limitCount = cachePlusOps.incr(new CacheKey(limitKey, Duration.ofSeconds(DateUtil.restSecondsFromNowToNoon()))); + // 超出单日发送次数之后直接锁定 + if (limitCount >= verificationCodeTypeEnum.getSendTimesByDay().longValue()) { + cachePlusOps.set(new CacheKey(lockKey, Duration.ofSeconds(DateUtil.restSecondsFromNowToNoon())), request.getMobile()); + } + } else { + cachePlusOps.set(new CacheKey(limitKey, Duration.ofSeconds(DateUtil.restSecondsFromNowToNoon())), 1); + } + } } diff --git a/pmapi/src/main/resources/security/auth-dev.yml b/pmapi/src/main/resources/security/auth-dev.yml index 19fcc71..86f67a6 100644 --- a/pmapi/src/main/resources/security/auth-dev.yml +++ b/pmapi/src/main/resources/security/auth-dev.yml @@ -21,6 +21,7 @@ security: - /oa/** - /wflow/** - /sys/** + - /api/v1/verification/** ignore-csrf-urls: - /api/v1/user/auth/** - /v2/api-docs @@ -37,6 +38,7 @@ security: - /oa/** - /wflow/** - /sys/** + - /api/v1/verification/** role-map: "engineer": "project_manager": From 53fb15cdf8f104cd58cbdc38b3ea4fa1c6723921 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?niohe=C2=B7erbao?= Date: Tue, 14 Mar 2023 17:18:20 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9D=A1=E7=BA=BF=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/GovBusinessStripController.java | 30 ++++++++++++++-- .../organization/entity/GovBusinessStrip.java | 19 +++++----- .../manage/GovBusinessStripManage.java | 42 ++++++++++++++++++++++ .../model/vo/GovBusinessStripTreeVO.java | 28 +++++++++++++++ 4 files changed, 107 insertions(+), 12 deletions(-) create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/organization/manage/GovBusinessStripManage.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/organization/model/vo/GovBusinessStripTreeVO.java diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/organization/controller/GovBusinessStripController.java b/pmapi/src/main/java/com/ningdatech/pmapi/organization/controller/GovBusinessStripController.java index 78981ed..2e3d4fe 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/organization/controller/GovBusinessStripController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/organization/controller/GovBusinessStripController.java @@ -1,20 +1,44 @@ package com.ningdatech.pmapi.organization.controller; +import com.ningdatech.pmapi.organization.manage.GovBusinessStripManage; +import com.ningdatech.pmapi.organization.model.vo.GovBusinessStripTreeVO; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Controller; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; -import org.springframework.stereotype.Controller; +import java.util.List; /** *

- * 前端控制器 + * 前端控制器 *

* * @author Liuxinxin * @since 2023-03-08 */ @Controller -@RequestMapping("/pmapi.organization/gov-business-strip") +@Slf4j +@Validated +@RestController +@RequiredArgsConstructor +@Api(value = "GovBusinessStripController", tags = "条线管理") +@RequestMapping("/api/v1/gov-business-strip") public class GovBusinessStripController { + private final GovBusinessStripManage govBusinessStripManage; + + @GetMapping("/get-child-list") + @ApiOperation("获取条线标签的的树状结构") + public List getChildOrganizationList(@RequestParam(value = "parentCode", required = false) String parentCode) { + return govBusinessStripManage.getChildOrganizationList(parentCode); + } + } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/organization/entity/GovBusinessStrip.java b/pmapi/src/main/java/com/ningdatech/pmapi/organization/entity/GovBusinessStrip.java index 4309dff..60ff77d 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/organization/entity/GovBusinessStrip.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/organization/entity/GovBusinessStrip.java @@ -5,7 +5,6 @@ import io.swagger.annotations.ApiModel; import lombok.Data; import java.io.Serializable; -import java.time.LocalDateTime; /** *

@@ -24,14 +23,6 @@ public class GovBusinessStrip implements Serializable { private Long id; - private LocalDateTime createOn; - - private LocalDateTime updateOn; - - private Long createBy; - - private Long updateBy; - /** * 条线code */ @@ -41,4 +32,14 @@ public class GovBusinessStrip implements Serializable { * 条线名称 */ private String businessStripName; + + /** + * 父级条线code + */ + private String parentCode; + + /** + * 父级条线名称 + */ + private String parentName; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/organization/manage/GovBusinessStripManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/organization/manage/GovBusinessStripManage.java new file mode 100644 index 0000000..078b653 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/organization/manage/GovBusinessStripManage.java @@ -0,0 +1,42 @@ +package com.ningdatech.pmapi.organization.manage; + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.ningdatech.pmapi.organization.entity.GovBusinessStrip; +import com.ningdatech.pmapi.organization.model.vo.GovBusinessStripTreeVO; +import com.ningdatech.pmapi.organization.service.IGovBusinessStripService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * @author liuxinxin + * @date 2023/3/14 下午4:48 + */ + +@Component +@RequiredArgsConstructor +public class GovBusinessStripManage { + + private final IGovBusinessStripService iGovBusinessStripService; + + + public List getChildOrganizationList(String parentCode) { + if (Objects.isNull(parentCode)) { + parentCode = "-1"; + } + List govBusinessStripList = iGovBusinessStripService.list(Wrappers.lambdaQuery(GovBusinessStrip.class) + .eq(GovBusinessStrip::getParentCode, parentCode)); + + return govBusinessStripList.stream().map(r -> { + GovBusinessStripTreeVO govBusinessStripTreeVO = new GovBusinessStripTreeVO(); + govBusinessStripTreeVO.setBusinessStripCode(r.getBusinessStripCode()); + govBusinessStripTreeVO.setBusinessStripName(r.getBusinessStripName()); + govBusinessStripTreeVO.setParentCode(r.getParentCode()); + govBusinessStripTreeVO.setParentName(r.getParentName()); + return govBusinessStripTreeVO; + }).collect(Collectors.toList()); + } +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/organization/model/vo/GovBusinessStripTreeVO.java b/pmapi/src/main/java/com/ningdatech/pmapi/organization/model/vo/GovBusinessStripTreeVO.java new file mode 100644 index 0000000..c3e50bb --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/organization/model/vo/GovBusinessStripTreeVO.java @@ -0,0 +1,28 @@ +package com.ningdatech.pmapi.organization.model.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author Liuxinxin + * @since 2023-03-08 + */ +@Data +@ApiModel(value = "条线树形 responseVO", description = "") +public class GovBusinessStripTreeVO { + + private Long id; + + @ApiModelProperty("条线code") + private String businessStripCode; + + @ApiModelProperty("条线名称") + private String businessStripName; + + @ApiModelProperty("父级条线code") + private String parentCode; + + @ApiModelProperty("父级条线名称") + private String parentName; +}