From 00d097382901cf8ecab22422d57a51d3ace65932 Mon Sep 17 00:00:00 2001 From: wxz Date: Thu, 20 Aug 2020 18:15:50 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=A4=96=E9=83=A8?= =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=BB=B4=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tools/exception/EpmetErrorCode.java | 2 + .../epmet/dto/form/ExternalAppFormDTO.java | 22 +++++++++ .../dto/form/ExternalCustomerFormDTO.java | 23 ++++++++-- .../dto/result/ExternalAppResultDTO.java | 19 ++++++++ .../common-service-server/pom.xml | 2 +- .../controller/ExternalAppController.java | 26 +++++++++++ .../ExternalCustomerController.java | 45 ++++++++++++++----- .../java/com/epmet/dao/ExternalAppDao.java | 4 +- .../com/epmet/dao/ExternalCustomerDao.java | 15 +++++++ .../epmet/service/ExternalAppAuthService.java | 1 + .../com/epmet/service/ExternalAppService.java | 3 ++ .../service/ExternalCustomerService.java | 9 ++-- .../impl/ExternalAppAuthServiceImpl.java | 8 ++++ .../service/impl/ExternalAppServiceImpl.java | 37 +++++++++++++++ .../impl/ExternalCustomerServiceImpl.java | 36 +++++++++++++-- .../main/resources/mapper/ExternalAppDao.xml | 11 +++++ .../resources/mapper/ExternalCustomerDao.xml | 16 +++++++ 17 files changed, 257 insertions(+), 22 deletions(-) create mode 100644 epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ExternalAppFormDTO.java create mode 100644 epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/result/ExternalAppResultDTO.java diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java index e86296856e..24e795fd1a 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java @@ -100,6 +100,8 @@ public enum EpmetErrorCode { OPER_UPLOAD_FILE_OVER_SIZE(8707, "文件体积过大"), OPER_UPLOAD_FILE_TYPE_ERROR(8708, "文件类型错误"), OPER_EXTERNAL_APP_AUTH_ERROR(8709, "外部应用认证失败"), + OPER_EXTERNAL_CUSTOMER_NOT_EXISTS(8710, "该客户不存在"), + OPER_EXTERNAL_APP_EXISTS(8711, "应用已存在"), // 党建声音 前端提示 88段 DRAFT_CONTENT_IS_NULL(8801, "至少需要添加一个段落"), diff --git a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ExternalAppFormDTO.java b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ExternalAppFormDTO.java new file mode 100644 index 0000000000..9d416731d6 --- /dev/null +++ b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ExternalAppFormDTO.java @@ -0,0 +1,22 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +@Data +public class ExternalAppFormDTO { + + public interface AddExternalApp {} + public interface UpdateExternalApp {} + + @NotBlank(message = "缺少应用ID", groups = { UpdateExternalApp.class }) + private String appId; + + @NotBlank(message = "缺少应用名称", groups = { AddExternalApp.class, UpdateExternalApp.class }) + private String appName; + + @NotBlank(message = "缺少所属客户ID", groups = { AddExternalApp.class, UpdateExternalApp.class }) + private String customerId; + +} diff --git a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ExternalCustomerFormDTO.java b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ExternalCustomerFormDTO.java index da8c394aea..3ec9ccecac 100644 --- a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ExternalCustomerFormDTO.java +++ b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ExternalCustomerFormDTO.java @@ -3,13 +3,28 @@ package com.epmet.dto.form; import lombok.Data; import javax.validation.constraints.Min; +import javax.validation.constraints.NotBlank; @Data public class ExternalCustomerFormDTO { - @Min(0) - private Integer pageNo; + public interface ListExternalCustomerGroup {} + public interface AddExternalCustomerGroup {} + public interface UpdateExternalCustomerGroup {} - @Min(0) - private Integer pageSize; + + @NotBlank(message = "缺少客户ID参数", groups = { UpdateExternalCustomerGroup.class }) + private String customerId; + + /** + * 客户名称 + */ + @NotBlank(message = "请填写客户名称", groups = { AddExternalCustomerGroup.class, UpdateExternalCustomerGroup.class }) + private String customerName; + + @Min(value = 0, groups = { ListExternalCustomerGroup.class }) + private Integer pageNo = 1; + + @Min(value = 0, groups = { ListExternalCustomerGroup.class }) + private Integer pageSize = 10; } diff --git a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/result/ExternalAppResultDTO.java b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/result/ExternalAppResultDTO.java new file mode 100644 index 0000000000..7de7015a69 --- /dev/null +++ b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/result/ExternalAppResultDTO.java @@ -0,0 +1,19 @@ +package com.epmet.dto.result; + +import lombok.Data; + +@Data +public class ExternalAppResultDTO { + + public String id; + /** + * APP名字 + */ + private String appName; + + /** + * 客户ID + */ + private String customerId; + +} diff --git a/epmet-module/epmet-common-service/common-service-server/pom.xml b/epmet-module/epmet-common-service/common-service-server/pom.xml index 597eb77772..4c2122a905 100644 --- a/epmet-module/epmet-common-service/common-service-server/pom.xml +++ b/epmet-module/epmet-common-service/common-service-server/pom.xml @@ -113,7 +113,7 @@ 6379 123456 - true + false 122.152.200.70:8848 fcd6fc8f-ca3a-4b01-8026-2b05cdc5976b diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ExternalAppController.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ExternalAppController.java index 1e627e5de8..47027649eb 100644 --- a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ExternalAppController.java +++ b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ExternalAppController.java @@ -2,9 +2,13 @@ package com.epmet.controller; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.dto.form.ExternalAppAuthFormDTO; +import com.epmet.dto.form.ExternalAppFormDTO; import com.epmet.dto.result.ExternalAppAuthResultDTO; +import com.epmet.dto.result.ExternalAppResultDTO; import com.epmet.service.ExternalAppAuthService; +import com.epmet.service.ExternalAppService; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -14,6 +18,8 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.validation.constraints.NotBlank; + @RestController @RequestMapping("/externalapp") public class ExternalAppController { @@ -23,6 +29,9 @@ public class ExternalAppController { @Autowired private ExternalAppAuthService externalAppAuthService; + @Autowired + private ExternalAppService externalAppService; + /** * 外部请求认证 * @param formDTO @@ -41,4 +50,21 @@ public class ExternalAppController { return new Result().ok(auth); } + /** + * 添加应用 + * @param formDTO + * @return + */ + @PostMapping("/add") + public Result add(@RequestBody ExternalAppFormDTO formDTO) { + + ValidatorUtils.validateEntity(formDTO, ExternalAppFormDTO.AddExternalApp.class); + + String appName = formDTO.getAppName(); + String customerId = formDTO.getCustomerId(); + + ExternalAppResultDTO dto = externalAppService.add(appName, customerId); + return new Result().ok(dto); + } + } diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ExternalCustomerController.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ExternalCustomerController.java index e5ae0ae464..2817a2fae5 100644 --- a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ExternalCustomerController.java +++ b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ExternalCustomerController.java @@ -1,13 +1,12 @@ package com.epmet.controller; -import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; -import com.epmet.dto.form.ExternalAppAuthFormDTO; import com.epmet.dto.form.ExternalCustomerFormDTO; -import com.epmet.dto.result.ExternalAppAuthResultDTO; -import com.epmet.service.ExternalAppAuthService; -import org.apache.commons.lang3.StringUtils; +import com.epmet.dto.result.ExternalCustomerResultDTO; +import com.epmet.entity.ExternalCustomerEntity; +import com.epmet.service.ExternalCustomerService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -16,7 +15,7 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import javax.validation.constraints.Min; +import javax.validation.constraints.NotBlank; /** * 外部客户管理 @@ -28,20 +27,46 @@ public class ExternalCustomerController { private static Logger logger = LoggerFactory.getLogger(ExternalCustomerController.class); @Autowired - private ExternalAppAuthService externalAppAuthService; + private ExternalCustomerService externalCustomerService; /** * 外部客户管理 * @return */ @PostMapping("/list") - public Result list(@RequestBody ExternalCustomerFormDTO form) { - ValidatorUtils.validateEntity(form); + public Result> list(@RequestBody ExternalCustomerFormDTO form) { + ValidatorUtils.validateEntity(form, ExternalCustomerFormDTO.ListExternalCustomerGroup.class); Integer pageNo = form.getPageNo(); Integer pageSize = form.getPageSize(); + PageData page = externalCustomerService.listPage(pageNo, pageSize); + return new Result>().ok(page); + } + /** + * 添加外部客户 + * @param formDTO + * @return + */ + @PostMapping("add") + public Result add(@RequestBody ExternalCustomerFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO, ExternalCustomerFormDTO.AddExternalCustomerGroup.class); + String customerName = formDTO.getCustomerName(); + ExternalCustomerEntity result = externalCustomerService.add(customerName); + return new Result().ok(result); + } - return null; + /** + * 更新客户信息 + * @param formDTO + * @return + */ + @PostMapping("update") + public Result update(@RequestBody ExternalCustomerFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO, ExternalCustomerFormDTO.UpdateExternalCustomerGroup.class); + String customerId = formDTO.getCustomerId(); + String customerName = formDTO.getCustomerName(); + ExternalCustomerEntity result = externalCustomerService.update(customerId, customerName); + return new Result().ok(result); } } diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/ExternalAppDao.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/ExternalAppDao.java index f07f428cfd..f07ab43f75 100644 --- a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/ExternalAppDao.java +++ b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/ExternalAppDao.java @@ -20,6 +20,7 @@ package com.epmet.dao; import com.epmet.commons.mybatis.dao.BaseDao; import com.epmet.entity.ExternalAppEntity; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; /** * 外部应用列表 @@ -29,5 +30,6 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface ExternalAppDao extends BaseDao { - + + Integer countByAppNameAndCustomerId(@Param("appName") String appName, @Param("customerId") String customerId); } \ No newline at end of file diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/ExternalCustomerDao.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/ExternalCustomerDao.java index b22be4caf9..e8d67410ac 100644 --- a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/ExternalCustomerDao.java +++ b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/ExternalCustomerDao.java @@ -21,6 +21,7 @@ import com.epmet.commons.mybatis.dao.BaseDao; import com.epmet.dto.result.ExternalCustomerResultDTO; import com.epmet.entity.ExternalCustomerEntity; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -38,4 +39,18 @@ public interface ExternalCustomerDao extends BaseDao { * @return */ List listBaseInfo(); + + /** + * 根据名称查询客户 + * @param customerName + * @return + */ + ExternalCustomerResultDTO getByCustomerName(@Param("customerName") String customerName); + + /** + * 根据客户名称计数 + * @param customerName + * @return + */ + Integer countByCustomerName(@Param("customerName") String customerName); } \ No newline at end of file diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalAppAuthService.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalAppAuthService.java index aff79d5f72..e1158c592c 100644 --- a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalAppAuthService.java +++ b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalAppAuthService.java @@ -1,6 +1,7 @@ package com.epmet.service; import com.epmet.dto.result.ExternalAppAuthResultDTO; +import com.epmet.dto.result.ExternalAppResultDTO; public interface ExternalAppAuthService { diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalAppService.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalAppService.java index 5799ea0abb..0dfc3cc2d9 100644 --- a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalAppService.java +++ b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalAppService.java @@ -17,6 +17,8 @@ package com.epmet.service; +import com.epmet.dto.result.ExternalAppResultDTO; + /** * 外部应用列表 * @@ -24,4 +26,5 @@ package com.epmet.service; * @since v1.0.0 2020-08-18 */ public interface ExternalAppService { + ExternalAppResultDTO add(String appName, String customerId); } \ No newline at end of file diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalCustomerService.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalCustomerService.java index bcc8d10cc6..6af116be98 100644 --- a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalCustomerService.java +++ b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalCustomerService.java @@ -1,11 +1,14 @@ package com.epmet.service; +import com.epmet.commons.tools.page.PageData; import com.epmet.dto.result.ExternalCustomerResultDTO; - -import java.util.List; +import com.epmet.entity.ExternalCustomerEntity; public interface ExternalCustomerService { - public List list(Integer pageNo, Integer pageSize); + PageData listPage(Integer pageNo, Integer pageSize); + + ExternalCustomerEntity add(String customerName); + ExternalCustomerEntity update(String customerId, String customerName); } diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppAuthServiceImpl.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppAuthServiceImpl.java index 822e654cbb..e87a4c6f46 100644 --- a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppAuthServiceImpl.java +++ b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppAuthServiceImpl.java @@ -1,10 +1,15 @@ package com.epmet.service.impl; +import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.ExceptionUtils; +import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.redis.RedisKeys; import com.epmet.commons.tools.redis.RedisUtils; +import com.epmet.dao.ExternalAppDao; import com.epmet.dao.ExternalAppSecretDao; import com.epmet.dto.result.ExternalAppAuthResultDTO; +import com.epmet.dto.result.ExternalAppResultDTO; +import com.epmet.entity.ExternalAppEntity; import com.epmet.entity.ExternalAppSecretEntity; import com.epmet.service.ExternalAppAuthService; import com.epmet.utils.externalapp.ExtAppJwtTokenUtils; @@ -29,6 +34,9 @@ public class ExternalAppAuthServiceImpl implements ExternalAppAuthService { @Autowired private ExternalAppSecretDao externalAppSecretDao; + @Autowired + private ExternalAppDao externalAppDao; + private int diffMillins = 1000 * 60 * 5; @Override diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppServiceImpl.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppServiceImpl.java index 1621e74e2d..bef41b455e 100644 --- a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppServiceImpl.java +++ b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppServiceImpl.java @@ -17,7 +17,14 @@ package com.epmet.service.impl; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.RenException; +import com.epmet.dao.ExternalAppDao; +import com.epmet.dao.ExternalCustomerDao; +import com.epmet.dto.result.ExternalAppResultDTO; +import com.epmet.entity.ExternalAppEntity; import com.epmet.service.ExternalAppService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** @@ -29,5 +36,35 @@ import org.springframework.stereotype.Service; @Service public class ExternalAppServiceImpl implements ExternalAppService { + @Autowired + private ExternalAppDao externalAppDao; + + @Autowired + private ExternalCustomerDao externalCustomerDao; + + @Override + public ExternalAppResultDTO add(String appName, String customerId) { + Integer count = externalAppDao.countByAppNameAndCustomerId(appName, customerId); + if (count > 0) { + throw new RenException(EpmetErrorCode.OPER_EXTERNAL_APP_EXISTS.getCode(), + EpmetErrorCode.OPER_EXTERNAL_APP_EXISTS.getMsg()); + } + + if (externalCustomerDao.selectById(customerId) == null) { + throw new RenException(EpmetErrorCode.OPER_EXTERNAL_CUSTOMER_NOT_EXISTS.getCode(), + EpmetErrorCode.OPER_EXTERNAL_CUSTOMER_NOT_EXISTS.getMsg()); + } + + ExternalAppEntity entity = new ExternalAppEntity(); + entity.setAppName(appName); + entity.setCustomerId(customerId); + externalAppDao.insert(entity); + + ExternalAppResultDTO dto = new ExternalAppResultDTO(); + dto.setAppName(appName); + dto.setCustomerId(customerId); + dto.setId(entity.getId()); + return dto; + } } \ No newline at end of file diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalCustomerServiceImpl.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalCustomerServiceImpl.java index 9925841b0f..8cfe32cf96 100644 --- a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalCustomerServiceImpl.java +++ b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalCustomerServiceImpl.java @@ -1,7 +1,11 @@ package com.epmet.service.impl; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.page.PageData; import com.epmet.dao.ExternalCustomerDao; import com.epmet.dto.result.ExternalCustomerResultDTO; +import com.epmet.entity.ExternalCustomerEntity; import com.epmet.service.ExternalCustomerService; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; @@ -17,10 +21,36 @@ public class ExternalCustomerServiceImpl implements ExternalCustomerService { private ExternalCustomerDao externalCustomerDao; @Override - public List list(Integer pageNo, Integer pageSize) { + public PageData listPage(Integer pageNo, Integer pageSize) { PageHelper.startPage(pageNo, pageSize); List customers = externalCustomerDao.listBaseInfo(); - PageInfo pageInfo = new PageInfo<>(customers); - return null; + long total = new PageInfo<>(customers).getTotal(); + + PageData pageData = new PageData<>(customers, (int) total); + return pageData; + } + + @Override + public ExternalCustomerEntity add(String customerName) { + Integer exitsCustomerCount = externalCustomerDao.countByCustomerName(customerName); + if (exitsCustomerCount > 0) { + throw new RenException(EpmetErrorCode.OPER_CUSTOMER_EXISTS.getCode(), "客户已存在"); + } + ExternalCustomerEntity entity = new ExternalCustomerEntity(); + entity.setCustomerName(customerName); + externalCustomerDao.insert(entity); + return entity; + } + + @Override + public ExternalCustomerEntity update(String customerId, String customerName) { + ExternalCustomerEntity existsCustomer = externalCustomerDao.selectById(customerId); + if (existsCustomer == null) { + throw new RenException(EpmetErrorCode.OPER_EXTERNAL_CUSTOMER_NOT_EXISTS.getCode(), + EpmetErrorCode.OPER_EXTERNAL_CUSTOMER_NOT_EXISTS.getMsg()); + } + existsCustomer.setCustomerName(customerName); + externalCustomerDao.updateById(existsCustomer); + return existsCustomer; } } diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalAppDao.xml b/epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalAppDao.xml index 8662bc5f97..6c4b308eb0 100644 --- a/epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalAppDao.xml +++ b/epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalAppDao.xml @@ -15,5 +15,16 @@ + + + \ No newline at end of file diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalCustomerDao.xml b/epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalCustomerDao.xml index 9d59a01224..0e4d03d0cc 100644 --- a/epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalCustomerDao.xml +++ b/epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalCustomerDao.xml @@ -25,5 +25,21 @@ DEL_FLAG = 0 + + + + \ No newline at end of file From 320a9dbc4cdbd58c292d554168d302b6344d2d8b Mon Sep 17 00:00:00 2001 From: wxz Date: Thu, 20 Aug 2020 23:28:41 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E7=BB=B4=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/dto/form/ExternalAppFormDTO.java | 3 + .../dto/result/ExternalAppResultDTO.java | 12 ++- .../controller/ExternalAppController.java | 32 +++++++- .../java/com/epmet/dao/ExternalAppDao.java | 7 ++ .../com/epmet/service/ExternalAppService.java | 5 ++ .../service/impl/ExternalAppServiceImpl.java | 73 +++++++++++++++++-- .../main/resources/mapper/ExternalAppDao.xml | 34 +++++++++ 7 files changed, 158 insertions(+), 8 deletions(-) diff --git a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ExternalAppFormDTO.java b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ExternalAppFormDTO.java index 9d416731d6..36a504a135 100644 --- a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ExternalAppFormDTO.java +++ b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ExternalAppFormDTO.java @@ -19,4 +19,7 @@ public class ExternalAppFormDTO { @NotBlank(message = "缺少所属客户ID", groups = { AddExternalApp.class, UpdateExternalApp.class }) private String customerId; + private Integer pageNo = 1; + private Integer pageSize = 10; + } diff --git a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/result/ExternalAppResultDTO.java b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/result/ExternalAppResultDTO.java index 7de7015a69..e4cf3fedb6 100644 --- a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/result/ExternalAppResultDTO.java +++ b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/result/ExternalAppResultDTO.java @@ -5,7 +5,7 @@ import lombok.Data; @Data public class ExternalAppResultDTO { - public String id; + public String appId; /** * APP名字 */ @@ -16,4 +16,14 @@ public class ExternalAppResultDTO { */ private String customerId; + /** + * 客户名称 + */ + private String customerName; + + /** + * 秘钥 + */ + private String secret; + } diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ExternalAppController.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ExternalAppController.java index 47027649eb..976c4e4ef0 100644 --- a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ExternalAppController.java +++ b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ExternalAppController.java @@ -1,6 +1,7 @@ package com.epmet.controller; import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.dto.form.ExternalAppAuthFormDTO; @@ -18,8 +19,6 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import javax.validation.constraints.NotBlank; - @RestController @RequestMapping("/externalapp") public class ExternalAppController { @@ -67,4 +66,33 @@ public class ExternalAppController { return new Result().ok(dto); } + /** + * 修改应用 + * @param formDTO + * @return + */ + @PostMapping("/update") + public Result update(@RequestBody ExternalAppFormDTO formDTO) { + + ValidatorUtils.validateEntity(formDTO, ExternalAppFormDTO.UpdateExternalApp.class); + + String appId = formDTO.getAppId(); + String appName = formDTO.getAppName(); + String customerId = formDTO.getCustomerId(); + + ExternalAppResultDTO dto = externalAppService.updateById(appId, appName, customerId); + return new Result().ok(dto); + } + + /** + * 查询列表 + * @param formDTO + * @return + */ + @PostMapping("/list") + public Result> list(@RequestBody ExternalAppFormDTO formDTO) { + PageData page = externalAppService.listPage(formDTO.getPageNo(), formDTO.getPageSize(), formDTO.getCustomerId()); + return new Result>().ok(page); + } + } diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/ExternalAppDao.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/ExternalAppDao.java index f07ab43f75..73f6bd3407 100644 --- a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/ExternalAppDao.java +++ b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/ExternalAppDao.java @@ -18,10 +18,13 @@ package com.epmet.dao; import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.dto.result.ExternalAppResultDTO; import com.epmet.entity.ExternalAppEntity; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import java.util.List; + /** * 外部应用列表 * @@ -32,4 +35,8 @@ import org.apache.ibatis.annotations.Param; public interface ExternalAppDao extends BaseDao { Integer countByAppNameAndCustomerId(@Param("appName") String appName, @Param("customerId") String customerId); + + ExternalAppResultDTO getByNameAndCustomerId(@Param("appName") String appName, @Param("customerId") String customerId); + + List list(@Param("customerId") String customerId); } \ No newline at end of file diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalAppService.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalAppService.java index 0dfc3cc2d9..dff718695f 100644 --- a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalAppService.java +++ b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ExternalAppService.java @@ -17,6 +17,7 @@ package com.epmet.service; +import com.epmet.commons.tools.page.PageData; import com.epmet.dto.result.ExternalAppResultDTO; /** @@ -27,4 +28,8 @@ import com.epmet.dto.result.ExternalAppResultDTO; */ public interface ExternalAppService { ExternalAppResultDTO add(String appName, String customerId); + + ExternalAppResultDTO updateById(String appId, String appName, String customerId); + + PageData listPage(Integer pageNo, Integer pageSize, String customerId); } \ No newline at end of file diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppServiceImpl.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppServiceImpl.java index bef41b455e..5f92de268e 100644 --- a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppServiceImpl.java +++ b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ExternalAppServiceImpl.java @@ -19,13 +19,22 @@ package com.epmet.service.impl; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.page.PageData; import com.epmet.dao.ExternalAppDao; +import com.epmet.dao.ExternalAppSecretDao; import com.epmet.dao.ExternalCustomerDao; import com.epmet.dto.result.ExternalAppResultDTO; import com.epmet.entity.ExternalAppEntity; +import com.epmet.entity.ExternalAppSecretEntity; import com.epmet.service.ExternalAppService; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.UUID; /** * 外部应用列表 @@ -39,9 +48,13 @@ public class ExternalAppServiceImpl implements ExternalAppService { @Autowired private ExternalAppDao externalAppDao; + @Autowired + private ExternalAppSecretDao externalAppSecretDao; + @Autowired private ExternalCustomerDao externalCustomerDao; + @Transactional @Override public ExternalAppResultDTO add(String appName, String customerId) { Integer count = externalAppDao.countByAppNameAndCustomerId(appName, customerId); @@ -55,16 +68,66 @@ public class ExternalAppServiceImpl implements ExternalAppService { EpmetErrorCode.OPER_EXTERNAL_CUSTOMER_NOT_EXISTS.getMsg()); } - ExternalAppEntity entity = new ExternalAppEntity(); - entity.setAppName(appName); - entity.setCustomerId(customerId); - externalAppDao.insert(entity); + // 应用表插入 + ExternalAppEntity appEntity = new ExternalAppEntity(); + appEntity.setAppName(appName); + appEntity.setCustomerId(customerId); + externalAppDao.insert(appEntity); + + // 秘钥表插入 + ExternalAppSecretEntity secretEntity = new ExternalAppSecretEntity(); + secretEntity.setAppId(appEntity.getId()); + secretEntity.setSecret(genSecret()); + externalAppSecretDao.insert(secretEntity); ExternalAppResultDTO dto = new ExternalAppResultDTO(); dto.setAppName(appName); dto.setCustomerId(customerId); - dto.setId(entity.getId()); + dto.setAppId(appEntity.getId()); return dto; } + /** + * 生成秘钥 + * @return + */ + private String genSecret() { + String part1 = UUID.randomUUID().toString(); + String part2 = UUID.randomUUID().toString(); + return part1.concat(part2).replace("-", ""); + } + + @Override + public ExternalAppResultDTO updateById(String appId, String appName, String customerId) { + ExternalAppEntity exists = externalAppDao.selectById(appId); + if (exists == null) { + throw new RenException(EpmetErrorCode.OPER_EXTERNAL_CUSTOMER_NOT_EXISTS.getCode(), + EpmetErrorCode.OPER_EXTERNAL_CUSTOMER_NOT_EXISTS.getMsg()); + } + + ExternalAppResultDTO byName = externalAppDao.getByNameAndCustomerId(appName, customerId); + if (byName != null && !byName.getAppId().equals(appId)) { + // 说明改了之后的名字跟当前客户内的其他应用重复 + throw new RenException(EpmetErrorCode.OPER_EXTERNAL_APP_EXISTS.getCode(), "应用名称重复"); + } + + exists.setAppName(appName); + exists.setCustomerId(customerId); + externalAppDao.updateById(exists); + + ExternalAppResultDTO resultDTO = new ExternalAppResultDTO(); + resultDTO.setAppId(appId); + resultDTO.setCustomerId(customerId); + resultDTO.setAppName(appName); + return resultDTO; + } + + @Override + public PageData listPage(Integer pageNo, Integer pageSize, String customerId) { + PageHelper.startPage(pageNo, pageSize); + List list = externalAppDao.list(customerId); + PageInfo pageInfo = new PageInfo<>(list); + return new PageData<>(list, pageInfo.getTotal()); + } + } \ No newline at end of file diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalAppDao.xml b/epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalAppDao.xml index 6c4b308eb0..588f735da7 100644 --- a/epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalAppDao.xml +++ b/epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ExternalAppDao.xml @@ -24,6 +24,40 @@ WHERE APP_NAME = #{appName} AND CUSTOMER_ID = #{customerId} + AND DEL_FLAG = 0 + + + + + From a013f2bfbd1acf2f1300ac4d6259c426fe3265d7 Mon Sep 17 00:00:00 2001 From: wxz Date: Fri, 21 Aug 2020 09:19:41 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=89=93=E5=BC=80dev=E7=9A=84nacos?= =?UTF-8?q?=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- epmet-module/epmet-common-service/common-service-server/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/epmet-module/epmet-common-service/common-service-server/pom.xml b/epmet-module/epmet-common-service/common-service-server/pom.xml index 4c2122a905..597eb77772 100644 --- a/epmet-module/epmet-common-service/common-service-server/pom.xml +++ b/epmet-module/epmet-common-service/common-service-server/pom.xml @@ -113,7 +113,7 @@ 6379 123456 - false + true 122.152.200.70:8848 fcd6fc8f-ca3a-4b01-8026-2b05cdc5976b From 183932f995c80d376085d4f1b6e5a560db725ff5 Mon Sep 17 00:00:00 2001 From: wxz Date: Fri, 21 Aug 2020 14:05:00 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=8A=A8=E6=80=81=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=BA=90-=E6=94=AF=E6=8C=81=E6=96=B9=E6=B3=95=E5=85=A5?= =?UTF-8?q?=E5=8F=82=E7=BA=A7=E5=88=AB=E7=9A=84=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datasource/annotation/DataSource.java | 10 +++++ .../datasource/aspect/DataSourceAspect.java | 42 ++++++++++++++++++- .../datasource/bean/DataSourceParam.java | 12 ++++++ 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 epmet-commons/epmet-commons-dynamic-datasource/src/main/java/com/epmet/commons/dynamic/datasource/bean/DataSourceParam.java diff --git a/epmet-commons/epmet-commons-dynamic-datasource/src/main/java/com/epmet/commons/dynamic/datasource/annotation/DataSource.java b/epmet-commons/epmet-commons-dynamic-datasource/src/main/java/com/epmet/commons/dynamic/datasource/annotation/DataSource.java index 3a8ac1ae8f..e0675092c8 100644 --- a/epmet-commons/epmet-commons-dynamic-datasource/src/main/java/com/epmet/commons/dynamic/datasource/annotation/DataSource.java +++ b/epmet-commons/epmet-commons-dynamic-datasource/src/main/java/com/epmet/commons/dynamic/datasource/annotation/DataSource.java @@ -21,5 +21,15 @@ import java.lang.annotation.*; @Documented @Inherited public @interface DataSource { + /** + * 直接指定数据源名称 + * @return + */ String value() default ""; + + /** + * 是否从参数中获取数据源名称,优先级高于value + * @return + */ + boolean datasourceNameFromArg() default false; } diff --git a/epmet-commons/epmet-commons-dynamic-datasource/src/main/java/com/epmet/commons/dynamic/datasource/aspect/DataSourceAspect.java b/epmet-commons/epmet-commons-dynamic-datasource/src/main/java/com/epmet/commons/dynamic/datasource/aspect/DataSourceAspect.java index d636568425..45113847c6 100644 --- a/epmet-commons/epmet-commons-dynamic-datasource/src/main/java/com/epmet/commons/dynamic/datasource/aspect/DataSourceAspect.java +++ b/epmet-commons/epmet-commons-dynamic-datasource/src/main/java/com/epmet/commons/dynamic/datasource/aspect/DataSourceAspect.java @@ -9,7 +9,9 @@ package com.epmet.commons.dynamic.datasource.aspect; import com.epmet.commons.dynamic.datasource.annotation.DataSource; +import com.epmet.commons.dynamic.datasource.bean.DataSourceParam; import com.epmet.commons.dynamic.datasource.config.DynamicContextHolder; +import org.apache.commons.lang3.StringUtils; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; @@ -22,6 +24,7 @@ import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; import java.lang.reflect.Method; +import java.lang.reflect.Parameter; /** * 多数据源,切面处理类 @@ -52,9 +55,9 @@ public class DataSourceAspect { if(targetDataSource != null || methodDataSource != null){ String value; if(methodDataSource != null){ - value = methodDataSource.value(); + value = getDatasourceName(methodDataSource, signature.getMethod().getParameters(), point.getArgs()); }else { - value = targetDataSource.value(); + value = getDatasourceName(targetDataSource, signature.getMethod().getParameters(), point.getArgs()); } DynamicContextHolder.push(value); @@ -68,4 +71,39 @@ public class DataSourceAspect { logger.debug("clean datasource"); } } + + /** + * 获取要用到的数据源名称 + * @param dataSource + * @return + */ + public String getDatasourceName(DataSource dataSource, Parameter[] methodParameters, Object[] methodArgValues) { + if (dataSource.datasourceNameFromArg()) { + // 1.从参数中动态获取数据源名称 + String datasourceNameFromParam = getDatasourceNameFromArg(methodParameters, methodArgValues); + if (StringUtils.isNotBlank(datasourceNameFromParam)) { + // 如果有DatasourceParam类型的参数并且设置了datasourceName值,那么返回这个值,否则使用硬编码的 + return datasourceNameFromParam; + } + } + // 2.硬编码指定数据源名称 + return dataSource.value(); + } + + /** + * 从参数中取数据源名称 + * @param parameters + * @param argsObject + * @return + */ + public String getDatasourceNameFromArg(Parameter[] parameters, Object[] argsObject) { + for (int i = 0; i < parameters.length; i++) { + if (parameters[i].getType() == DataSourceParam.class) { + DataSourceParam param = (DataSourceParam) argsObject[i]; + return param.getDatasourceName(); + } + } + + return null; + } } diff --git a/epmet-commons/epmet-commons-dynamic-datasource/src/main/java/com/epmet/commons/dynamic/datasource/bean/DataSourceParam.java b/epmet-commons/epmet-commons-dynamic-datasource/src/main/java/com/epmet/commons/dynamic/datasource/bean/DataSourceParam.java new file mode 100644 index 0000000000..19b5905588 --- /dev/null +++ b/epmet-commons/epmet-commons-dynamic-datasource/src/main/java/com/epmet/commons/dynamic/datasource/bean/DataSourceParam.java @@ -0,0 +1,12 @@ +package com.epmet.commons.dynamic.datasource.bean; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class DataSourceParam { + + private String datasourceName; + +}