From a8d0fe2d60c4f8a3fdf60471b3ce00cecb2db7a5 Mon Sep 17 00:00:00 2001 From: yujt Date: Mon, 18 May 2020 14:59:54 +0800 Subject: [PATCH] =?UTF-8?q?git=EF=BC=8Cpoints=E6=A8=A1=E5=9D=97=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 29 +++ epdc-cloud-points/Dockerfile | 20 ++ epdc-cloud-points/pom.xml | 205 +++++++++++++++ .../elink/esua/epdc/PointsApplication.java | 31 +++ .../esua/epdc/config/ModuleConfigImpl.java | 26 ++ .../esua/epdc/modules/async/NewsTask.java | 34 +++ .../epdc/modules/feign/NewsFeignClient.java | 31 +++ .../epdc/modules/feign/UserFeignClient.java | 42 ++++ .../fallback/NewsFeignClientFallback.java | 21 ++ .../fallback/UserFeignClientFallback.java | 28 +++ .../logs/controller/PointsLogsController.java | 112 +++++++++ .../epdc/modules/logs/dao/PointsLogsDao.java | 33 +++ .../modules/logs/entity/PointsLogsEntity.java | 104 ++++++++ .../modules/logs/excel/PointsLogsExcel.java | 86 +++++++ .../modules/logs/redis/PointsLogsRedis.java | 47 ++++ .../logs/service/PointsLogsService.java | 106 ++++++++ .../service/impl/PointsLogsServiceImpl.java | 200 +++++++++++++++ .../rule/controller/PointsRuleController.java | 103 ++++++++ .../epdc/modules/rule/dao/PointsRuleDao.java | 34 +++ .../modules/rule/entity/PointsRuleEntity.java | 91 +++++++ .../modules/rule/excel/PointsRuleExcel.java | 86 +++++++ .../modules/rule/redis/PointsRuleRedis.java | 47 ++++ .../rule/service/PointsRuleService.java | 114 +++++++++ .../service/impl/PointsRuleServiceImpl.java | 235 ++++++++++++++++++ .../epdc/support/annotion/PointsBehavior.java | 42 ++++ .../epdc/support/aop/PointsBehaviorAop.java | 209 ++++++++++++++++ .../initbean/InitPointsRuleRedisCache.java | 31 +++ .../src/main/resources/application.yml | 79 ++++++ .../main/resources/i18n/messages.properties | 0 .../resources/i18n/messages_en_US.properties | 0 .../resources/i18n/messages_zh_CN.properties | 0 .../resources/i18n/messages_zh_TW.properties | 0 .../main/resources/i18n/validation.properties | 0 .../i18n/validation_en_US.properties | 0 .../i18n/validation_zh_CN.properties | 0 .../i18n/validation_zh_TW.properties | 0 .../src/main/resources/logback-spring.xml | 161 ++++++++++++ .../resources/mapper/logs/PointsLogsDao.xml | 29 +++ .../resources/mapper/rule/PointsRuleDao.xml | 27 ++ .../src/main/resources/registry.conf | 21 ++ 40 files changed, 2464 insertions(+) create mode 100644 .gitignore create mode 100644 epdc-cloud-points/Dockerfile create mode 100644 epdc-cloud-points/pom.xml create mode 100644 epdc-cloud-points/src/main/java/com/elink/esua/epdc/PointsApplication.java create mode 100644 epdc-cloud-points/src/main/java/com/elink/esua/epdc/config/ModuleConfigImpl.java create mode 100644 epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/async/NewsTask.java create mode 100644 epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/feign/NewsFeignClient.java create mode 100644 epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/feign/UserFeignClient.java create mode 100644 epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/feign/fallback/NewsFeignClientFallback.java create mode 100644 epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/feign/fallback/UserFeignClientFallback.java create mode 100644 epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/controller/PointsLogsController.java create mode 100644 epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/dao/PointsLogsDao.java create mode 100644 epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/entity/PointsLogsEntity.java create mode 100644 epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/excel/PointsLogsExcel.java create mode 100644 epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/redis/PointsLogsRedis.java create mode 100644 epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/service/PointsLogsService.java create mode 100644 epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/service/impl/PointsLogsServiceImpl.java create mode 100644 epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/controller/PointsRuleController.java create mode 100644 epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/dao/PointsRuleDao.java create mode 100644 epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/entity/PointsRuleEntity.java create mode 100644 epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/excel/PointsRuleExcel.java create mode 100644 epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/redis/PointsRuleRedis.java create mode 100644 epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/service/PointsRuleService.java create mode 100644 epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/service/impl/PointsRuleServiceImpl.java create mode 100644 epdc-cloud-points/src/main/java/com/elink/esua/epdc/support/annotion/PointsBehavior.java create mode 100644 epdc-cloud-points/src/main/java/com/elink/esua/epdc/support/aop/PointsBehaviorAop.java create mode 100644 epdc-cloud-points/src/main/java/com/elink/esua/epdc/support/initbean/InitPointsRuleRedisCache.java create mode 100644 epdc-cloud-points/src/main/resources/application.yml create mode 100644 epdc-cloud-points/src/main/resources/i18n/messages.properties create mode 100644 epdc-cloud-points/src/main/resources/i18n/messages_en_US.properties create mode 100644 epdc-cloud-points/src/main/resources/i18n/messages_zh_CN.properties create mode 100644 epdc-cloud-points/src/main/resources/i18n/messages_zh_TW.properties create mode 100644 epdc-cloud-points/src/main/resources/i18n/validation.properties create mode 100644 epdc-cloud-points/src/main/resources/i18n/validation_en_US.properties create mode 100644 epdc-cloud-points/src/main/resources/i18n/validation_zh_CN.properties create mode 100644 epdc-cloud-points/src/main/resources/i18n/validation_zh_TW.properties create mode 100644 epdc-cloud-points/src/main/resources/logback-spring.xml create mode 100644 epdc-cloud-points/src/main/resources/mapper/logs/PointsLogsDao.xml create mode 100644 epdc-cloud-points/src/main/resources/mapper/rule/PointsRuleDao.xml create mode 100644 epdc-cloud-points/src/main/resources/registry.conf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..281336c --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +# Created by .ignore support plugin (hsz.mobi) +### Java template +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +.idea/ +*.iml +**/target/ + diff --git a/epdc-cloud-points/Dockerfile b/epdc-cloud-points/Dockerfile new file mode 100644 index 0000000..fc459b9 --- /dev/null +++ b/epdc-cloud-points/Dockerfile @@ -0,0 +1,20 @@ +# 基础镜像 +FROM openjdk:8u242-jdk-buster +# 作者 +MAINTAINER rongchao@elink-cn.com +# 对应pom.xml文件中的dockerfile-maven-plugin插件JAR_FILE的值 +ARG JAR_FILE +# 对应pom.xml文件中的dockerfile-maven-plugin插件JAR_NAME的值 +ARG JAR_NAME +# 对应pom.xml文件中的dockerfile-maven-plugin插件SERVER_PORT的值 +ARG SERVER_PORT +# 复制打包完成后的jar文件到/opt目录下 +ENV JAR_PATH /mnt/epdc/${JAR_NAME}.jar +ADD ${JAR_FILE} $JAR_PATH +# /data设为环境变量 +ENV DATAPATH /data +# 挂载/data目录到主机 +VOLUME $DATAPATH +# 启动容器时执行 +ENTRYPOINT java -jar $JAR_CONFIG $JAR_PATH +EXPOSE ${SERVER_PORT} diff --git a/epdc-cloud-points/pom.xml b/epdc-cloud-points/pom.xml new file mode 100644 index 0000000..ca5b05d --- /dev/null +++ b/epdc-cloud-points/pom.xml @@ -0,0 +1,205 @@ + + + + com.esua.epdc.yushan + epdc-cloud-parent-yushan + 1.0.0 + ../epdc-cloud-parent-yushan + + 4.0.0 + + epdc-cloud-points + jar + + + + com.esua.epdc.yushan + epdc-cloud-user-client + ${epdc-cloud-client.version} + + + com.esua.epdc.yushan + epdc-cloud-news-client + ${epdc-cloud-client.version} + + + com.esua.epdc.yushan + epdc-cloud-points-client + ${epdc-cloud-client.version} + + + com.esua.epdc.yushan + epdc-commons-tools + 1.0.0 + + + com.esua.epdc.yushan + epdc-commons-mybatis + ${epdc-cloud-commons.version} + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework + spring-context-support + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + de.codecentric + spring-boot-admin-starter-client + 2.0.3 + + + + org.springframework.cloud + spring-cloud-starter-zipkin + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + com.spotify + dockerfile-maven-plugin + + + + ${project.basedir}/src/main/java + + + true + ${basedir}/src/main/resources + + **/application*.yml + **/*.properties + logback-spring.xml + registry.conf + + + + ${basedir}/src/main/resources + + **/application*.yml + **/*.properties + logback-spring.xml + registry.conf + + + + + + + + + dev + + true + + + dev + dev + + 9070 + + 2 + 47.104.224.45 + 6379 + elink@888 + + + + + epdc + elink833066 + + true + 47.104.224.45:8848 + + http://localhost:9411 + + + + + test + + test + test + + 10017 + + 2 + 114.215.125.123 + 9603 + epdc!redis@master1405 + + + + + epdc + elink833066 + + true + 47.104.224.45:8848 + 47.104.85.99 + 6a3577b4-7b79-43f6-aebb-9c3f31263f6a + + http://localhost:9411 + + + + + prod + + prod + prod + + 9070 + + + 0 + 172.16.1.243 + 6379 + Elink833066 + + + + + epdc + Elink@833066 + + true + 172.16.1.243:8848 + + + + http://localhost:9411 + + + + diff --git a/epdc-cloud-points/src/main/java/com/elink/esua/epdc/PointsApplication.java b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/PointsApplication.java new file mode 100644 index 0000000..8f2b9aa --- /dev/null +++ b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/PointsApplication.java @@ -0,0 +1,31 @@ +/** + * Copyright (c) 2018 人人开源 All rights reserved. + * + * https://www.renren.io + * + * 版权所有,侵权必究! + */ + +package com.elink.esua.epdc; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; + +/** + * 爱心互助模块 + * + * @author Mark sunlightcs@gmail.com + * @since 1.1.0 + */ +@SpringBootApplication +@EnableDiscoveryClient +@EnableFeignClients +public class PointsApplication { + + public static void main(String[] args) { + SpringApplication.run(PointsApplication.class, args); + } + +} diff --git a/epdc-cloud-points/src/main/java/com/elink/esua/epdc/config/ModuleConfigImpl.java b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/config/ModuleConfigImpl.java new file mode 100644 index 0000000..df7c529 --- /dev/null +++ b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/config/ModuleConfigImpl.java @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2018 人人开源 All rights reserved. + *

+ * https://www.renren.io + *

+ * 版权所有,侵权必究! + */ + +package com.elink.esua.epdc.config; + +import com.elink.esua.epdc.commons.tools.config.ModuleConfig; +import org.springframework.stereotype.Service; + +/** + * 模块配置信息-爱心互助模块 + * + * @author Mark sunlightcs@gmail.com + * @since 1.0.0 + */ +@Service +public class ModuleConfigImpl implements ModuleConfig { + @Override + public String getName() { + return "points"; + } +} diff --git a/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/async/NewsTask.java b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/async/NewsTask.java new file mode 100644 index 0000000..d0dddb5 --- /dev/null +++ b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/async/NewsTask.java @@ -0,0 +1,34 @@ +package com.elink.esua.epdc.modules.async; + +import com.elink.esua.epdc.dto.epdc.form.EpdcInformationFormDTO; +import com.elink.esua.epdc.modules.feign.NewsFeignClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +/** + * 新闻通知消息模块 线程任务 + * + * @author yujintao + * @email yujintao@elink-cn.com + * @date 2019/9/10 10:02 + */ +@Component +public class NewsTask { + + @Autowired + private NewsFeignClient newsFeignClient; + + /** + * 给用户发送消息 + * + * @param informationDto + * @return void + * @author yujintao + * @date 2019/9/10 10:33 + */ + @Async + public void insertUserInformation(EpdcInformationFormDTO informationDto) { + newsFeignClient.saveInformation(informationDto); + } +} diff --git a/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/feign/NewsFeignClient.java b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/feign/NewsFeignClient.java new file mode 100644 index 0000000..e780327 --- /dev/null +++ b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/feign/NewsFeignClient.java @@ -0,0 +1,31 @@ +package com.elink.esua.epdc.modules.feign; + +import com.elink.esua.epdc.commons.tools.constant.ServiceConstant; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.dto.epdc.form.EpdcInformationFormDTO; +import com.elink.esua.epdc.modules.feign.fallback.NewsFeignClientFallback; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +/** + * 消息模块 + * + * @author work@yujt.net.cn + * @date 2019/9/18 15:37 + */ +@FeignClient(name = ServiceConstant.EPDC_NEWS_SERVER, fallback = NewsFeignClientFallback.class) +public interface NewsFeignClient { + + /** + * 给用户发消息 + * + * @param formDto + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @author work@yujt.net.cn + * @date 2019/9/18 15:40 + */ + @PostMapping(value = "news/epdc-app/information/save", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) + Result saveInformation(@RequestBody EpdcInformationFormDTO formDto); +} diff --git a/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/feign/UserFeignClient.java b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/feign/UserFeignClient.java new file mode 100644 index 0000000..6a5eb37 --- /dev/null +++ b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/feign/UserFeignClient.java @@ -0,0 +1,42 @@ +package com.elink.esua.epdc.modules.feign; + +import com.elink.esua.epdc.commons.tools.constant.ServiceConstant; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.dto.UserDTO; +import com.elink.esua.epdc.dto.epdc.form.EpdcUserPointsFormDTO; +import com.elink.esua.epdc.modules.feign.fallback.UserFeignClientFallback; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; + +/** + * @Description 用户模块 + * @Author yinzuomei + * @Date 2019/12/13 10:00 + */ +@FeignClient(name = ServiceConstant.EPDC_USER_SERVER, fallback = UserFeignClientFallback.class) +public interface UserFeignClient { + + /** + * @param formDTO + * @return com.elink.esua.epdc.dto.UserDTO + * @Author yinzuomei + * @Description 根据操作类型更新用户积分 + * @Date 2019/12/13 15:12 + **/ + @PostMapping(value = "app-user/user/handleUserPoints", consumes = MediaType.APPLICATION_JSON_VALUE) + Result handleUserPoints(EpdcUserPointsFormDTO formDTO); + + /** + * 查询用户基础信息 + * + * @param userId + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @author work@yujt.net.cn + * @date 2019/10/26 15:16 + */ + @GetMapping("app-user/epdc-app/user/getById/{userId}") + Result getUserInfoById(@PathVariable("userId") String userId); +} diff --git a/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/feign/fallback/NewsFeignClientFallback.java b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/feign/fallback/NewsFeignClientFallback.java new file mode 100644 index 0000000..0a2c9f2 --- /dev/null +++ b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/feign/fallback/NewsFeignClientFallback.java @@ -0,0 +1,21 @@ +package com.elink.esua.epdc.modules.feign.fallback; + +import com.elink.esua.epdc.commons.tools.constant.ServiceConstant; +import com.elink.esua.epdc.commons.tools.utils.ModuleUtils; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.dto.epdc.form.EpdcInformationFormDTO; +import com.elink.esua.epdc.modules.feign.NewsFeignClient; +import org.springframework.stereotype.Component; + +/** + * @author work@yujt.net.cn + * @date 2019/9/18 15:38 + */ +@Component +public class NewsFeignClientFallback implements NewsFeignClient { + + @Override + public Result saveInformation(EpdcInformationFormDTO formDto) { + return ModuleUtils.feignConError(ServiceConstant.EPDC_NEWS_SERVER, "saveInformation", formDto); + } +} diff --git a/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/feign/fallback/UserFeignClientFallback.java b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/feign/fallback/UserFeignClientFallback.java new file mode 100644 index 0000000..2494bf2 --- /dev/null +++ b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/feign/fallback/UserFeignClientFallback.java @@ -0,0 +1,28 @@ +package com.elink.esua.epdc.modules.feign.fallback; + +import com.elink.esua.epdc.commons.tools.constant.ServiceConstant; +import com.elink.esua.epdc.commons.tools.utils.ModuleUtils; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.dto.UserDTO; +import com.elink.esua.epdc.dto.epdc.form.EpdcUserPointsFormDTO; +import com.elink.esua.epdc.modules.feign.UserFeignClient; +import org.springframework.stereotype.Component; + +/** + * @Description + * @Author yinzuomei + * @Date 2019/12/13 10:00 + */ +@Component +public class UserFeignClientFallback implements UserFeignClient { + + @Override + public Result handleUserPoints(EpdcUserPointsFormDTO formDTO) { + return ModuleUtils.feignConError(ServiceConstant.EPDC_USER_SERVER, "handleUserPoints", formDTO); + } + + @Override + public Result getUserInfoById(String userId) { + return ModuleUtils.feignConError(ServiceConstant.EPDC_USER_SERVER, "getUserInfoById", userId); + } +} diff --git a/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/controller/PointsLogsController.java b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/controller/PointsLogsController.java new file mode 100644 index 0000000..a119de4 --- /dev/null +++ b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/controller/PointsLogsController.java @@ -0,0 +1,112 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.modules.logs.controller; + +import com.elink.esua.epdc.commons.tools.page.PageData; +import com.elink.esua.epdc.commons.tools.utils.ExcelUtils; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.commons.tools.validator.AssertUtils; +import com.elink.esua.epdc.commons.tools.validator.ValidatorUtils; +import com.elink.esua.epdc.commons.tools.validator.group.AddGroup; +import com.elink.esua.epdc.commons.tools.validator.group.DefaultGroup; +import com.elink.esua.epdc.commons.tools.validator.group.UpdateGroup; +import com.elink.esua.epdc.dto.epdc.result.EpdcAdjustVolunteerPointsDTO; +import com.elink.esua.epdc.dto.logs.PointsLogsDTO; +import com.elink.esua.epdc.modules.logs.excel.PointsLogsExcel; +import com.elink.esua.epdc.modules.logs.service.PointsLogsService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; +import java.util.List; +import java.util.Map; + + +/** + * 积分日志表 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2019-12-13 + */ +@RestController +@RequestMapping("pointslogs") +public class PointsLogsController { + + @Autowired + private PointsLogsService pointsLogsService; + + @GetMapping("page") + public Result> page(@RequestParam Map params){ + PageData page = pointsLogsService.page(params); + return new Result>().ok(page); + } + + @GetMapping("{id}") + public Result get(@PathVariable("id") String id){ + PointsLogsDTO data = pointsLogsService.get(id); + return new Result().ok(data); + } + + @PostMapping + public Result save(@RequestBody PointsLogsDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); + return pointsLogsService.save(dto); + } + @PostMapping("addPointsLog") + public Result addPointsLog(@RequestBody PointsLogsDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); + return pointsLogsService.save(dto); + } + @PutMapping + public Result update(@RequestBody PointsLogsDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); + pointsLogsService.update(dto); + return new Result(); + } + + @DeleteMapping + public Result delete(@RequestBody String[] ids){ + //效验数据 + AssertUtils.isArrayEmpty(ids, "id"); + pointsLogsService.delete(ids); + return new Result(); + } + + @GetMapping("export") + public void export(@RequestParam Map params, HttpServletResponse response) throws Exception { + List list = pointsLogsService.list(params); + ExcelUtils.exportExcelToTarget(response, null, list, PointsLogsExcel.class); + } + + /** + * @param formDto + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @Author yinzuomei + * @Description 确定调整用户积分 + * @Date 2019/12/16 18:56 + **/ + @PostMapping("confirmAdjustPoint") + public Result confirmAdjustPoint(@RequestBody EpdcAdjustVolunteerPointsDTO formDto){ + ValidatorUtils.validateEntity(formDto); + return pointsLogsService.confirmAdjustPoint(formDto); + } +} diff --git a/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/dao/PointsLogsDao.java b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/dao/PointsLogsDao.java new file mode 100644 index 0000000..5d9945a --- /dev/null +++ b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/dao/PointsLogsDao.java @@ -0,0 +1,33 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.modules.logs.dao; + +import com.elink.esua.epdc.commons.mybatis.dao.BaseDao; +import com.elink.esua.epdc.modules.logs.entity.PointsLogsEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 积分日志表 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2019-12-13 + */ +@Mapper +public interface PointsLogsDao extends BaseDao { + +} diff --git a/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/entity/PointsLogsEntity.java b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/entity/PointsLogsEntity.java new file mode 100644 index 0000000..06a7d22 --- /dev/null +++ b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/entity/PointsLogsEntity.java @@ -0,0 +1,104 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.modules.logs.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.elink.esua.epdc.commons.mybatis.entity.BaseEpdcEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 积分日志表 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2019-12-13 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("epdc_points_logs") +public class PointsLogsEntity extends BaseEpdcEntity { + + private static final long serialVersionUID = 1L; + + /** + * 志愿者ID + */ + private String volunteerId; + + /** + * 用户ID + */ + private String userId; + + /** + * 积分操作类型(0-减积分,1-加积分) + */ + private String operationType; + + /** + * 操作积分值 + */ + private Integer points; + + /** + * 操作描述 + */ + private String operationDesc; + + /** + * 操作时间 + */ + private Date operationTime; + + /** + * 操作方式(user-用户操作,admin-管理员操作,sys-系统操作) + */ + private String operationMode; + + /** + * 积分规则编码 + */ + private String ruleCode; + + /** + * 是否操作成功(0-失败,1-成功) + */ + private String status; + + /** + * 操作失败原因 + */ + private String failureReason; + + /** + * 剩余积分值 + */ + private Integer lavePoints; + + /** + * 积分行为编码 + */ + private String behaviorCode; + + /** + * 关联表ID关联表id + */ + private String referenceId; +} diff --git a/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/excel/PointsLogsExcel.java b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/excel/PointsLogsExcel.java new file mode 100644 index 0000000..4377620 --- /dev/null +++ b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/excel/PointsLogsExcel.java @@ -0,0 +1,86 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.modules.logs.excel; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import lombok.Data; + +import java.util.Date; + +/** + * 积分日志表 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2019-12-13 + */ +@Data +public class PointsLogsExcel { + + @Excel(name = "主键") + private String id; + + @Excel(name = "志愿者ID") + private String volunteerId; + + @Excel(name = "用户ID") + private String userId; + + @Excel(name = "积分操作类型(0-减积分,1-加积分)") + private String operationType; + + @Excel(name = "操作积分值") + private Integer points; + + @Excel(name = "操作描述") + private String operationDesc; + + @Excel(name = "操作时间") + private Date operationTime; + + @Excel(name = "操作方式(user-用户操作,admin-管理员操作,sys-系统操作)") + private String operationMode; + + @Excel(name = "积分规则编码") + private String ruleCode; + + @Excel(name = "是否操作成功(0-失败,1-成功)") + private String status; + + @Excel(name = "操作失败原因") + private String failureReason; + + @Excel(name = "删除标记") + private String delFlag; + + @Excel(name = "乐观锁") + private Integer revision; + + @Excel(name = "创建人") + private String createdBy; + + @Excel(name = "创建时间") + private Date createdTime; + + @Excel(name = "更新人") + private String updatedBy; + + @Excel(name = "更新时间") + private Date updatedTime; + + +} \ No newline at end of file diff --git a/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/redis/PointsLogsRedis.java b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/redis/PointsLogsRedis.java new file mode 100644 index 0000000..81776df --- /dev/null +++ b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/redis/PointsLogsRedis.java @@ -0,0 +1,47 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.modules.logs.redis; + +import com.elink.esua.epdc.commons.tools.redis.RedisUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * 积分日志表 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2019-12-13 + */ +@Component +public class PointsLogsRedis { + @Autowired + private RedisUtils redisUtils; + + public void delete(Object[] ids) { + + } + + public void set(){ + + } + + public String get(String id){ + return null; + } + +} diff --git a/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/service/PointsLogsService.java b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/service/PointsLogsService.java new file mode 100644 index 0000000..6d43ada --- /dev/null +++ b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/service/PointsLogsService.java @@ -0,0 +1,106 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.modules.logs.service; + +import com.elink.esua.epdc.commons.mybatis.service.BaseService; +import com.elink.esua.epdc.commons.tools.page.PageData; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.dto.epdc.result.EpdcAdjustVolunteerPointsDTO; +import com.elink.esua.epdc.dto.logs.PointsLogsDTO; +import com.elink.esua.epdc.modules.logs.entity.PointsLogsEntity; + +import java.util.List; +import java.util.Map; + +/** + * 积分日志表 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2019-12-13 + */ +public interface PointsLogsService extends BaseService { + + /** + * 默认分页 + * + * @param params + * @return PageData + * @author generator + * @date 2019-12-13 + */ + PageData page(Map params); + + /** + * 默认查询 + * + * @param params + * @return java.util.List + * @author generator + * @date 2019-12-13 + */ + List list(Map params); + + /** + * 单条查询 + * + * @param id + * @return PointsLogsDTO + * @author generator + * @date 2019-12-13 + */ + PointsLogsDTO get(String id); + + /** + * 默认保存 + * + * @param dto + * @return void + * @author generator + * @date 2019-12-13 + */ + Result save(PointsLogsDTO dto); + + /** + * 默认更新 + * + * @param dto + * @return void + * @author generator + * @date 2019-12-13 + */ + void update(PointsLogsDTO dto); + + /** + * 批量删除 + * + * @param ids + * @return void + * @author generator + * @date 2019-12-13 + */ + void delete(String[] ids); + + /** + * @param formDto + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @Author yinzuomei + * @Description 确定调整用户积分 + * @Date 2019/12/16 18:56 + **/ + Result confirmAdjustPoint(EpdcAdjustVolunteerPointsDTO formDto); +} diff --git a/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/service/impl/PointsLogsServiceImpl.java b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/service/impl/PointsLogsServiceImpl.java new file mode 100644 index 0000000..fce148a --- /dev/null +++ b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/logs/service/impl/PointsLogsServiceImpl.java @@ -0,0 +1,200 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.modules.logs.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; +import com.elink.esua.epdc.commons.tools.constant.FieldConstant; +import com.elink.esua.epdc.commons.tools.constant.NumConstant; +import com.elink.esua.epdc.commons.tools.constant.PointsConstant; +import com.elink.esua.epdc.commons.tools.enums.YesOrNoEnum; +import com.elink.esua.epdc.commons.tools.enums.pointsenum.PointsOperationEnum; +import com.elink.esua.epdc.commons.tools.enums.pointsenum.PointsOperationModeEnum; +import com.elink.esua.epdc.commons.tools.page.PageData; +import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.constant.PointsNoticeConstant; +import com.elink.esua.epdc.dto.UserDTO; +import com.elink.esua.epdc.dto.epdc.form.EpdcInformationFormDTO; +import com.elink.esua.epdc.dto.epdc.form.EpdcUserPointsFormDTO; +import com.elink.esua.epdc.dto.epdc.result.EpdcAdjustVolunteerPointsDTO; +import com.elink.esua.epdc.dto.logs.PointsLogsDTO; +import com.elink.esua.epdc.modules.async.NewsTask; +import com.elink.esua.epdc.modules.feign.UserFeignClient; +import com.elink.esua.epdc.modules.logs.dao.PointsLogsDao; +import com.elink.esua.epdc.modules.logs.entity.PointsLogsEntity; +import com.elink.esua.epdc.modules.logs.redis.PointsLogsRedis; +import com.elink.esua.epdc.modules.logs.service.PointsLogsService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * 积分日志表 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2019-12-13 + */ +@Service +public class PointsLogsServiceImpl extends BaseServiceImpl implements PointsLogsService { + + @Autowired + private PointsLogsRedis pointsLogsRedis; + + @Autowired + private UserFeignClient userFeignClient; + + @Autowired + private NewsTask newsTask; + + @Override + public PageData page(Map params) { + String volunteerId = (String) params.get("volunteerId"); + String behaviorCode = (String) params.get("behaviorCode"); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq(StringUtils.isNotBlank(volunteerId), "VOLUNTEER_ID", volunteerId) + .eq(StringUtils.isNotBlank(behaviorCode), "BEHAVIOR_CODE", behaviorCode); + + IPage page = baseDao.selectPage( + getPage(params, FieldConstant.CREATED_TIME, false), + wrapper + ); + return getPageData(page, PointsLogsDTO.class); + } + + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); + + return ConvertUtils.sourceToTarget(entityList, PointsLogsDTO.class); + } + + private QueryWrapper getWrapper(Map params){ + String id = (String)params.get(FieldConstant.ID_HUMP); + + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); + + return wrapper; + } + + @Override + public PointsLogsDTO get(String id) { + PointsLogsEntity entity = baseDao.selectById(id); + return ConvertUtils.sourceToTarget(entity, PointsLogsDTO.class); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public Result save(PointsLogsDTO dto) { + PointsLogsEntity entity = ConvertUtils.sourceToTarget(dto, PointsLogsEntity.class); + insert(entity); + return new Result(); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(PointsLogsDTO dto) { + PointsLogsEntity entity = ConvertUtils.sourceToTarget(dto, PointsLogsEntity.class); + updateById(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(String[] ids) { + // 逻辑删除(@TableLogic 注解) + baseDao.deleteBatchIds(Arrays.asList(ids)); + } + + /** + * @param formDto + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @Author yinzuomei + * @Description 确定调整用户积分 + * @Date 2019/12/16 18:56 + **/ + @Override + @Transactional(rollbackFor = Exception.class) + public Result confirmAdjustPoint(EpdcAdjustVolunteerPointsDTO formDto) { + if(formDto.getOperatePoints()== NumConstant.ZERO){ + return new Result().error("操作积分不能为0"); + } + PointsLogsEntity pointsLogsEntity=new PointsLogsEntity(); + pointsLogsEntity.setVolunteerId(formDto.getId()); + pointsLogsEntity.setUserId(formDto.getUserId()); + pointsLogsEntity.setOperationTime(new Date()); + pointsLogsEntity.setOperationMode(PointsOperationModeEnum.OPERATION_MODE_ADMIN.getOperationMode());//操作方式(user-用户操作,admin-管理员操作,sys-系统操作) + pointsLogsEntity.setStatus(YesOrNoEnum.YES.value()); + pointsLogsEntity.setFailureReason(""); + pointsLogsEntity.setRuleCode(PointsConstant.ruleCode); + pointsLogsEntity.setOperationDesc(formDto.getAdjustReason());//操作描述 + pointsLogsEntity.setPoints(formDto.getOperatePoints()); + pointsLogsEntity.setOperationType(formDto.getOperationType());//积分操作类型(0-减积分,1-加积分) + EpdcUserPointsFormDTO userPointsFormDTO = new EpdcUserPointsFormDTO(); + userPointsFormDTO.setUserId(formDto.getUserId()); + userPointsFormDTO.setPoints(formDto.getOperatePoints()); + userPointsFormDTO.setOperationType(formDto.getOperationType()); + Result result = userFeignClient.handleUserPoints(userPointsFormDTO); + if (!result.success()) { + return new Result().error("调整用户积分失败"); + } + //剩余积分 + pointsLogsEntity.setLavePoints(result.getData().getPoints()); + pointsLogsEntity.setBehaviorCode(formDto.getBehaviorCode()); + this.insert(pointsLogsEntity); + //给用户发送消息通知 + this.issueSmsNotification(pointsLogsEntity); + return new Result(); + } + + /** + * @param pointsLogsEntity + * @return void + * @Author yinzuomei + * @Description 调整积分完成后-给用户发送消息通知 + * @Date 2020/2/7 22:12 + **/ + private void issueSmsNotification(PointsLogsEntity pointsLogsEntity) { + EpdcInformationFormDTO informationFormDTO = new EpdcInformationFormDTO(); + informationFormDTO.setUserId(pointsLogsEntity.getUserId()); + String content = ""; + //积分操作类型(0-减积分,1-加积分) + if (PointsOperationEnum.OPERATION_TYPE_ADD.getOperationType().equals(pointsLogsEntity.getOperationType())) { + informationFormDTO.setTitle(PointsNoticeConstant.ADD_POINTS_NOTICE); + content = PointsNoticeConstant.ADD_POINTS + pointsLogsEntity.getPoints() + PointsNoticeConstant.REASON + pointsLogsEntity.getOperationDesc(); + + } else if (PointsOperationEnum.OPERATION_TYPE_SUBSTRACT.getOperationType().equals(pointsLogsEntity.getOperationType())) { + informationFormDTO.setTitle(PointsNoticeConstant.SUBTRACT_POINTS_NOTICE); + content = PointsNoticeConstant.SUBTRACT_POINTS + pointsLogsEntity.getPoints() + PointsNoticeConstant.REASON + pointsLogsEntity.getOperationDesc(); + } + informationFormDTO.setContent(content); + informationFormDTO.setType(PointsNoticeConstant.NOTICE_TYPE_INTERACTIVE_NOTICE); + informationFormDTO.setBusinessType(PointsNoticeConstant.NOTICE__BUSINESS_TYPE_ACTIVITY); + informationFormDTO.setBusinessId(pointsLogsEntity.getId()); + informationFormDTO.setRelBusinessContent(""); + // 发送消息 + newsTask.insertUserInformation(informationFormDTO); + } +} diff --git a/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/controller/PointsRuleController.java b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/controller/PointsRuleController.java new file mode 100644 index 0000000..37ddd36 --- /dev/null +++ b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/controller/PointsRuleController.java @@ -0,0 +1,103 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.modules.rule.controller; + +import com.elink.esua.epdc.commons.tools.page.PageData; +import com.elink.esua.epdc.commons.tools.utils.ExcelUtils; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.commons.tools.validator.AssertUtils; +import com.elink.esua.epdc.commons.tools.validator.ValidatorUtils; +import com.elink.esua.epdc.commons.tools.validator.group.AddGroup; +import com.elink.esua.epdc.commons.tools.validator.group.UpdateGroup; +import com.elink.esua.epdc.commons.tools.validator.group.DefaultGroup; +import com.elink.esua.epdc.dto.rule.PointsRuleDTO; +import com.elink.esua.epdc.modules.rule.excel.PointsRuleExcel; +import com.elink.esua.epdc.modules.rule.service.PointsRuleService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; +import java.util.Map; + + +/** + * 积分规则表 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2019-12-11 + */ +@RestController +@RequestMapping("pointsrule") +public class PointsRuleController { + + @Autowired + private PointsRuleService pointsRuleService; + + @GetMapping("page") + public Result> page(@RequestParam Map params) { + PageData page = pointsRuleService.page(params); + return new Result>().ok(page); + } + + @GetMapping("{id}") + public Result get(@PathVariable("id") String id) { + PointsRuleDTO data = pointsRuleService.get(id); + return new Result().ok(data); + } + + @PostMapping + public Result save(@RequestBody PointsRuleDTO dto) { + //效验数据 + ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); + return pointsRuleService.save(dto); + } + + @PutMapping + public Result update(@RequestBody PointsRuleDTO dto) { + //效验数据 + ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); + return pointsRuleService.update(dto); + } + + @DeleteMapping + public Result delete(@RequestBody String[] ids) { + //效验数据 + AssertUtils.isArrayEmpty(ids, "id"); + pointsRuleService.delete(ids); + return new Result(); + } + + @GetMapping("export") + public void export(@RequestParam Map params, HttpServletResponse response) throws Exception { + List list = pointsRuleService.list(params); + ExcelUtils.exportExcelToTarget(response, null, list, PointsRuleExcel.class); + } + + /** + * @param ruleCode + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @Author yinzuomei + * @Description 根据规则编码查询规则信息 + * @Date 2019/12/12 16:29 + **/ + @GetMapping("getPointRule/{ruleCode}") + public Result getPointRule(@PathVariable("ruleCode") String ruleCode) { + return pointsRuleService.getPointRule(ruleCode); + } +} diff --git a/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/dao/PointsRuleDao.java b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/dao/PointsRuleDao.java new file mode 100644 index 0000000..558b37d --- /dev/null +++ b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/dao/PointsRuleDao.java @@ -0,0 +1,34 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.modules.rule.dao; + +import com.elink.esua.epdc.commons.mybatis.dao.BaseDao; +import com.elink.esua.epdc.modules.rule.entity.PointsRuleEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 积分规则表 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2019-12-11 + */ +@Mapper +public interface PointsRuleDao extends BaseDao { + + +} diff --git a/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/entity/PointsRuleEntity.java b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/entity/PointsRuleEntity.java new file mode 100644 index 0000000..488900d --- /dev/null +++ b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/entity/PointsRuleEntity.java @@ -0,0 +1,91 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.modules.rule.entity; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.elink.esua.epdc.commons.mybatis.entity.BaseEpdcEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 积分规则表 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2019-12-11 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("epdc_points_rule") +public class PointsRuleEntity extends BaseEpdcEntity { + + private static final long serialVersionUID = 1L; + + /** + * 规则编码 + */ + private String ruleCode; + + /** + * 规则描述 + */ + private String ruleDesc; + + /** + * 积分值 + */ + private Integer points; + + /** + * 规则操作类型(0-减积分,1-加积分) + */ + private String operationType; + + /** + * 可用标记(0-不可用,1-可用) + */ + private String available; + + /** + * 积分行为编码 + */ + private String behaviorCode; + + /** + * 积分行为描述 + */ + private String behaviorDesc; + + /** + * 积分是否有上限限制(0-否,1-是) + */ + private String upperLimitFlag; + + /** + * 限制时限(0-分钟,1-小时,2-日,3-月,4-年) + */ + private String limitTimeType; + + /** + * 积分上限值 + */ + private Integer upperLimitVal; + +} diff --git a/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/excel/PointsRuleExcel.java b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/excel/PointsRuleExcel.java new file mode 100644 index 0000000..3342fae --- /dev/null +++ b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/excel/PointsRuleExcel.java @@ -0,0 +1,86 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.modules.rule.excel; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import lombok.Data; + +import java.util.Date; + +/** + * 积分规则表 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2019-12-11 + */ +@Data +public class PointsRuleExcel { + + @Excel(name = "主键") + private String id; + + @Excel(name = "规则编码") + private String ruleCode; + + @Excel(name = "规则描述") + private String ruleDesc; + + @Excel(name = "积分值") + private Integer points; + + @Excel(name = "规则操作类型(0-减积分,1-加积分)") + private String operationType; + + @Excel(name = "可用标记(0-不可用,1-可用)") + private String available; + + @Excel(name = "积分行为编码") + private String behaviorCode; + + @Excel(name = "积分行为描述") + private String behaviorDesc; + + @Excel(name = "积分是否有上限限制(0-否,1-是)") + private String upperLimitFlag; + + @Excel(name = "限制时限(0-分钟,1-小时,2-日,3-月,4-年)") + private String limitTimeType; + + @Excel(name = "积分上限值") + private Integer upperLimitVal; + + @Excel(name = "删除标记") + private String delFlag; + + @Excel(name = "乐观锁") + private Integer revision; + + @Excel(name = "创建人") + private String createdBy; + + @Excel(name = "创建时间") + private Date createdTime; + + @Excel(name = "更新人") + private String updatedBy; + + @Excel(name = "更新时间") + private Date updatedTime; + + +} diff --git a/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/redis/PointsRuleRedis.java b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/redis/PointsRuleRedis.java new file mode 100644 index 0000000..dd7028f --- /dev/null +++ b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/redis/PointsRuleRedis.java @@ -0,0 +1,47 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.modules.rule.redis; + +import com.elink.esua.epdc.commons.tools.redis.RedisUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * 积分规则表 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2019-12-11 + */ +@Component +public class PointsRuleRedis { + @Autowired + private RedisUtils redisUtils; + + public void delete(Object[] ids) { + + } + + public void set(){ + + } + + public String get(String id){ + return null; + } + +} diff --git a/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/service/PointsRuleService.java b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/service/PointsRuleService.java new file mode 100644 index 0000000..35436cc --- /dev/null +++ b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/service/PointsRuleService.java @@ -0,0 +1,114 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.modules.rule.service; + +import com.elink.esua.epdc.commons.mybatis.service.BaseService; +import com.elink.esua.epdc.commons.tools.page.PageData; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.dto.rule.PointsRuleDTO; +import com.elink.esua.epdc.modules.rule.entity.PointsRuleEntity; + +import java.util.List; +import java.util.Map; + +/** + * 积分规则表 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2019-12-11 + */ +public interface PointsRuleService extends BaseService { + + /** + * 默认分页 + * + * @param params + * @return PageData + * @author generator + * @date 2019-12-11 + */ + PageData page(Map params); + + /** + * 默认查询 + * + * @param params + * @return java.util.List + * @author generator + * @date 2019-12-11 + */ + List list(Map params); + + /** + * 单条查询 + * + * @param id + * @return PointsRuleDTO + * @author generator + * @date 2019-12-11 + */ + PointsRuleDTO get(String id); + + /** + * 默认保存 + * + * @param dto + * @return void + * @author generator + * @date 2019-12-11 + */ + Result save(PointsRuleDTO dto); + + /** + * 默认更新 + * + * @param dto + * @return void + * @author generator + * @date 2019-12-11 + */ + Result update(PointsRuleDTO dto); + + /** + * 批量删除 + * + * @param ids + * @return void + * @author generator + * @date 2019-12-11 + */ + void delete(String[] ids); + + /** + * @param + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @Author yinzuomei + * @Description 项目启动初始化积分规则到redis + * @Date 2019/12/12 16:27 + **/ + Result initPointsRuleRedis(); + + /** + * @param ruleCode + * @return com.elink.esua.epdc.dto.rule.PointsRuleDTO + * @Author yinzuomei + * @Description 根据规则编码查询规则信息 + * @Date 2019/12/12 16:30 + **/ + Result getPointRule(String ruleCode); +} diff --git a/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/service/impl/PointsRuleServiceImpl.java b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/service/impl/PointsRuleServiceImpl.java new file mode 100644 index 0000000..c0fbfc1 --- /dev/null +++ b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/modules/rule/service/impl/PointsRuleServiceImpl.java @@ -0,0 +1,235 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.modules.rule.service.impl; + +import cn.hutool.core.collection.CollUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; +import com.elink.esua.epdc.commons.tools.constant.FieldConstant; +import com.elink.esua.epdc.commons.tools.enums.pointsenum.PointsLimitTimeEnum; +import com.elink.esua.epdc.commons.tools.enums.pointsenum.PointsRuleAvailableEnum; +import com.elink.esua.epdc.commons.tools.enums.pointsenum.PointsUpperLimitEnum; +import com.elink.esua.epdc.commons.tools.page.PageData; +import com.elink.esua.epdc.commons.tools.redis.RedisKeys; +import com.elink.esua.epdc.commons.tools.redis.RedisUtils; +import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.dto.rule.PointsRuleDTO; +import com.elink.esua.epdc.modules.rule.dao.PointsRuleDao; +import com.elink.esua.epdc.modules.rule.entity.PointsRuleEntity; +import com.elink.esua.epdc.modules.rule.redis.PointsRuleRedis; +import com.elink.esua.epdc.modules.rule.service.PointsRuleService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * 积分规则表 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2019-12-11 + */ +@Service +public class PointsRuleServiceImpl extends BaseServiceImpl implements PointsRuleService { + + @Autowired + private PointsRuleRedis pointsRuleRedis; + + @Autowired + private RedisUtils redisUtils; + + @Override + public PageData page(Map params) { + String ruleDesc = (String) params.get("ruleDesc"); + String behaviorCode = (String) params.get("behaviorCode"); + String behaviorDesc = (String) params.get("behaviorDesc"); + String ruleCode = (String) params.get("ruleCode"); + String operationType = (String) params.get("operationType"); + String available = (String) params.get("available"); + String upperLimitFlag = (String) params.get("upperLimitFlag"); + String startTime = (String) params.get("startTime"); + String endTime = (String) params.get("endTime"); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.like(StringUtils.isNotBlank(ruleDesc), "RULE_DESC", ruleDesc.trim()) + .like(StringUtils.isNotBlank(behaviorDesc), "BEHAVIOR_DESC", behaviorDesc.trim()) + .like(StringUtils.isNotBlank(ruleCode), "RULE_CODE", ruleCode.trim()) + .eq(StringUtils.isNotBlank(operationType), "OPERATION_TYPE", operationType) + .eq(StringUtils.isNotBlank(available), "AVAILABLE", available) + .eq(StringUtils.isNotBlank(upperLimitFlag), "UPPER_LIMIT_FLAG", upperLimitFlag) + .eq(StringUtils.isNotBlank(behaviorCode), "BEHAVIOR_CODE", behaviorCode) + .between(StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime), + "DATE_FORMAT(CREATED_TIME, '%Y-%m-%d' )", + startTime, + endTime); + IPage page = baseDao.selectPage( + getPage(params, FieldConstant.CREATED_TIME, false), + wrapper + ); + return getPageData(page, PointsRuleDTO.class); + } + + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); + + return ConvertUtils.sourceToTarget(entityList, PointsRuleDTO.class); + } + + private QueryWrapper getWrapper(Map params) { + String id = (String) params.get(FieldConstant.ID_HUMP); + + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); + + return wrapper; + } + + @Override + public PointsRuleDTO get(String id) { + PointsRuleEntity entity = baseDao.selectById(id); + return ConvertUtils.sourceToTarget(entity, PointsRuleDTO.class); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public Result save(PointsRuleDTO dto) { + Result checkResult = checkPointsRuleDTO(dto); + if (!checkResult.success()) { + return checkResult; + } + if(StringUtils.isBlank(dto.getLimitTimeType())){ + dto.setLimitTimeType(PointsLimitTimeEnum.LIMIT_TIME_MINUTE.value()); + } + dto.setAvailable(PointsRuleAvailableEnum.AVAILABLE_TRUE.value());//可用标记(0-不可用,1-可用) 新增时默认可用 + PointsRuleEntity entity = ConvertUtils.sourceToTarget(dto, PointsRuleEntity.class); + insert(entity); + String pointsRuleKey = RedisKeys.getPointsRuleKey(dto.getRuleCode()); + redisUtils.set(pointsRuleKey, entity); + return new Result(); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public Result update(PointsRuleDTO dto) { + Result checkResult = checkPointsRuleDTO(dto); + if (!checkResult.success()) { + return checkResult; + } + if(StringUtils.isBlank(dto.getLimitTimeType())){ + dto.setLimitTimeType(PointsLimitTimeEnum.LIMIT_TIME_MINUTE.value()); + } + PointsRuleEntity entity = ConvertUtils.sourceToTarget(dto, PointsRuleEntity.class); + updateById(entity); + String pointsRuleKey = RedisKeys.getPointsRuleKey(dto.getRuleCode()); + redisUtils.set(pointsRuleKey, entity); + return new Result(); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(String[] ids) { + // 逻辑删除(@TableLogic 注解) + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.in(FieldConstant.ID, ids); + List pointsRuleEntityList = baseDao.selectList(wrapper); + for (PointsRuleEntity pointsRuleEntity : pointsRuleEntityList) { + String pointsRuleKey = RedisKeys.getPointsRuleKey(pointsRuleEntity.getRuleCode()); + redisUtils.delete(pointsRuleKey); + } + baseDao.deleteBatchIds(Arrays.asList(ids)); + } + + /** + * @param + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @Author yinzuomei + * @Description 项目启动初始化积分规则到redis + * @Date 2019/12/12 16:26 + **/ + @Override + public Result initPointsRuleRedis() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("AVAILABLE", PointsRuleAvailableEnum.AVAILABLE_TRUE.value()); + List pointsRuleEntityList = baseDao.selectList(wrapper); + for (PointsRuleEntity pointsRuleEntity : pointsRuleEntityList) { + String pointsRuleKey = RedisKeys.getPointsRuleKey(pointsRuleEntity.getRuleCode()); + redisUtils.set(pointsRuleKey, pointsRuleEntity); + } + return new Result(); + } + + /** + * @param ruleCode + * @return com.elink.esua.epdc.dto.rule.PointsRuleDTO + * @Author yinzuomei + * @Description 根据规则编码查询规则信息 + * @Date 2019/12/12 16:30 + **/ + @Override + public Result getPointRule(String ruleCode) { + if (StringUtils.isBlank(ruleCode)) { + return new Result().error("规则编码不能为空"); + } + String pointsRuleKey = RedisKeys.getPointsRuleKey(ruleCode); + Object obj = redisUtils.get(pointsRuleKey); + if (null == obj) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("RULE_CODE", ruleCode); + List pointsRuleEntityList = baseDao.selectList(wrapper); + if (CollUtil.isEmpty(pointsRuleEntityList)) { + return new Result().error("没有找到有效记录"); + } else if (pointsRuleEntityList.size() > 1) { + return new Result().error("规则编码不唯一"); + } + redisUtils.set(pointsRuleKey, pointsRuleEntityList.get(0)); + obj = redisUtils.get(pointsRuleKey); + } + PointsRuleDTO pointsRuleDTO = ConvertUtils.sourceToTarget(obj, PointsRuleDTO.class); + return new Result().ok(pointsRuleDTO); + } + + /** + * @param dto + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @Author yinzuomei + * @Description 校验界面提交数据 + * @Date 2019/12/11 17:56 + **/ + public Result checkPointsRuleDTO(PointsRuleDTO dto) { + //规则有上限值:积分值不能大于上限值 + if (PointsUpperLimitEnum.YES.value().equals(dto.getUpperLimitFlag()) + && dto.getPoints() > dto.getUpperLimitVal()) { + return new Result().error("积分值不能大于上限值"); + } + //校验规则编码是否唯一 + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("RULE_CODE", dto.getRuleCode()) + .ne(StringUtils.isNotBlank(dto.getId()), FieldConstant.ID, dto.getId()); + List list = baseDao.selectList(wrapper); + if (CollUtil.isNotEmpty(list)) { + return new Result().error("规则编码已存在"); + } + return new Result(); + } +} diff --git a/epdc-cloud-points/src/main/java/com/elink/esua/epdc/support/annotion/PointsBehavior.java b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/support/annotion/PointsBehavior.java new file mode 100644 index 0000000..e223d5e --- /dev/null +++ b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/support/annotion/PointsBehavior.java @@ -0,0 +1,42 @@ +package com.elink.esua.epdc.support.annotion; + +import com.elink.esua.epdc.commons.tools.enums.pointsenum.PointsOperationEnum; +import com.elink.esua.epdc.commons.tools.enums.pointsenum.PointsOperationModeEnum; + +import java.lang.annotation.*; + +/** + * @Auther: yinzuomei + * @Date: 2019/12/13 09:15 + * @Description: 爱心互助积分注解 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +@Inherited +@Documented +public @interface PointsBehavior { + /** + * 积分操作类型(加积分、减积分) + */ + PointsOperationEnum operationType(); + + /** + * 积分操作方式(user-用户操作,admin-管理员操作,sys-系统操作) + */ + PointsOperationModeEnum operationMode(); + + /** + * 志愿者ID + */ + String volunteerId() default ""; + + /** + * 用户ID + */ + String userId() default ""; + + /** + * 规则编码 + */ + String ruleCode() default ""; +} diff --git a/epdc-cloud-points/src/main/java/com/elink/esua/epdc/support/aop/PointsBehaviorAop.java b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/support/aop/PointsBehaviorAop.java new file mode 100644 index 0000000..0ecdad1 --- /dev/null +++ b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/support/aop/PointsBehaviorAop.java @@ -0,0 +1,209 @@ +package com.elink.esua.epdc.support.aop; + +import com.elink.esua.epdc.commons.tools.enums.YesOrNoEnum; +import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.commons.tools.validator.ValidatorUtils; +import com.elink.esua.epdc.dto.epdc.form.EpdcUserPointsFormDTO; +import com.elink.esua.epdc.dto.logs.PointsLogsDTO; +import com.elink.esua.epdc.dto.logs.UserPointsLogDTO; +import com.elink.esua.epdc.dto.rule.PointsRuleDTO; +import com.elink.esua.epdc.modules.feign.UserFeignClient; +import com.elink.esua.epdc.modules.logs.service.PointsLogsService; +import com.elink.esua.epdc.modules.rule.service.PointsRuleService; +import com.elink.esua.epdc.support.annotion.PointsBehavior; +import io.seata.spring.annotation.GlobalTransactional; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.AfterReturning; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.aspectj.lang.reflect.MethodSignature; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +import java.lang.reflect.Method; +import java.util.Date; + +/** + * @Description + * @Author yinzuomei + * @Date 2019/12/13 10:00 + */ +@Aspect +@Component +public class PointsBehaviorAop { + private final Logger logger = LogManager.getLogger(getClass()); + @Autowired + private PointsLogsService pointsLogsService; + + @Autowired + private PointsRuleService pointsRuleService; + + @Autowired + private UserFeignClient userFeignClient; + + @Pointcut("@annotation(com.elink.esua.epdc.support.annotion.PointsBehavior)") + public void recordUserPointsBehavior() { + } + + @AfterReturning("recordUserPointsBehavior()") + public void handleUserPoints(JoinPoint joinPoint) throws Exception { + logger.info("handleUserPoints start"); + MethodSignature signature = (MethodSignature) joinPoint.getSignature(); + Method method = signature.getMethod(); + PointsBehavior pointsBehavior = method.getAnnotation(PointsBehavior.class); + Object[] args = joinPoint.getArgs(); + String[] argNames = ((MethodSignature) joinPoint.getSignature()).getParameterNames(); + //解析入参 + UserPointsLogDTO userPointsLogDTO = this.packageUserPointsLogDTO(pointsBehavior, args, argNames); + //校验入参属性都不能为空 + ValidatorUtils.validateEntity(userPointsLogDTO); + Result result = this.updateUserPoints(userPointsLogDTO); + if (!result.success()) { + throw new Exception("更新用户积分异常" + result.getMsg()); + } + } + + /** + * @param userPointsLogDTO + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @Author yinzuomei + * @Description + * @Date 2019/12/13 15:17 + **/ + private Result updateUserPoints(UserPointsLogDTO userPointsLogDTO) { + //logger.info("解析后的UserPointsLogDTO:" + JSONObject.toJSONString(userPointsLogDTO)); + //插入积分日志 + PointsLogsDTO pointsLogDto = ConvertUtils.sourceToTarget(userPointsLogDTO, PointsLogsDTO.class); + Result pointsRuleDTOResult = pointsRuleService.getPointRule(pointsLogDto.getRuleCode()); + pointsLogDto.setOperationDesc(pointsRuleDTOResult.getData().getBehaviorDesc()); + pointsLogDto.setPoints(pointsRuleDTOResult.getData().getPoints()); + pointsLogDto.setOperationTime(new Date()); + pointsLogDto.setStatus(YesOrNoEnum.YES.value());//是否操作成功(0-失败,1-成功) + Result result = pointsLogsService.save(pointsLogDto); + if (!result.success()) { + return result; + } + //修改用户总积分数 + EpdcUserPointsFormDTO formDTO = new EpdcUserPointsFormDTO(); + formDTO.setOperationType(userPointsLogDTO.getOperationType()); + formDTO.setPoints(pointsRuleDTOResult.getData().getPoints()); + formDTO.setUserId(userPointsLogDTO.getUserId()); + Result res = userFeignClient.handleUserPoints(formDTO); + return res; + } + + /** + * @param pointsBehavior + * @param args + * @param argNames + * @return com.elink.esua.epdc.dto.logs.UserPointsLogDTO + * @Author yinzuomei + * @Description + * @Date 2019/12/13 10:29 + **/ + private UserPointsLogDTO packageUserPointsLogDTO(PointsBehavior pointsBehavior, + Object[] args, + String[] argNames) { + logger.info("packageUserPointsLogDTO start"); + UserPointsLogDTO userPointsLogDTO = new UserPointsLogDTO(); + userPointsLogDTO.setOperationMode(pointsBehavior.operationMode().getOperationMode()); + userPointsLogDTO.setOperationType(pointsBehavior.operationType().getOperationType()); + //志愿者ID + String volunteerIdKey = pointsBehavior.volunteerId(); + //用户ID + String userIdKey = pointsBehavior.userId(); + //规则编码 + String ruleCodeKey = pointsBehavior.ruleCode(); + if (volunteerIdKey.startsWith("#") && userIdKey.startsWith("#") && ruleCodeKey.startsWith("#")) { + String volunteerId = ""; + String userId = ""; + String ruleCode = ""; + + //解析志愿者id + String volunteerIdExpression = volunteerIdKey.substring(2, volunteerIdKey.length() - 1); + String[] volunteerIdStrArr = volunteerIdExpression.split("\\."); + if (volunteerIdStrArr.length > 2 || volunteerIdStrArr.length == 0) { + throw new RuntimeException("记录用户积分注解中volunteerId格式不正确"); + } + if (volunteerIdStrArr.length == 1) { + for (int i = 0; i < argNames.length; i++) { + if (argNames[i].equals(volunteerIdStrArr[0])) { + volunteerId = String.valueOf(args[i]); + } + } + } else if (volunteerIdStrArr.length == 2) { + for (int i = 0; i < argNames.length; i++) { + if (argNames[i].equals(volunteerIdStrArr[0])) { + Object obj = args[i]; + try { + Method method = obj.getClass().getDeclaredMethod(volunteerIdStrArr[1]); + volunteerId = String.valueOf(method.invoke(obj)); + } catch (Exception e) { + throw new RuntimeException("记录用户积分注解中volunteerId反射失败"); + } + } + } + } + //解析ruleCode + String ruleCodeExpression = ruleCodeKey.substring(2, ruleCodeKey.length() - 1); + String[] ruleCodeStrArr = ruleCodeExpression.split("\\."); + if (ruleCodeStrArr.length > 2 || ruleCodeStrArr.length == 0) { + throw new RuntimeException("记录用户积分注解中ruleCode格式不正确"); + } + if (ruleCodeStrArr.length == 1) { + for (int i = 0; i < argNames.length; i++) { + if (argNames[i].equals(ruleCodeStrArr[0])) { + ruleCode = String.valueOf(args[i]); + } + } + } else if (ruleCodeStrArr.length == 2) { + for (int i = 0; i < argNames.length; i++) { + if (argNames[i].equals(ruleCodeStrArr[0])) { + Object obj = args[i]; + try { + Method method = obj.getClass().getDeclaredMethod(ruleCodeStrArr[1]); + ruleCode = String.valueOf(method.invoke(obj)); + } catch (Exception e) { + throw new RuntimeException("记录用户积分注解中ruleCode反射失败"); + } + } + } + } + //解析userId + String userIdExpression = userIdKey.substring(2, userIdKey.length() - 1); + String[] userIdStrArr = userIdExpression.split("\\."); + if (userIdStrArr.length > 2 || userIdStrArr.length == 0) { + throw new RuntimeException("记录用户积分注解中userId格式不正确"); + } + if (userIdStrArr.length == 1) { + for (int i = 0; i < argNames.length; i++) { + if (argNames[i].equals(userIdStrArr[0])) { + userId = String.valueOf(args[i]); + } + } + } else if (userIdStrArr.length == 2) { + for (int i = 0; i < argNames.length; i++) { + if (argNames[i].equals(userIdStrArr[0])) { + Object obj = args[i]; + try { + Method method = obj.getClass().getDeclaredMethod(userIdStrArr[1]); + userId = String.valueOf(method.invoke(obj)); + } catch (Exception e) { + throw new RuntimeException("记录用户积分注解中userId反射失败"); + } + } + } + } + userPointsLogDTO.setVolunteerId(volunteerId); + userPointsLogDTO.setUserId(userId); + userPointsLogDTO.setRuleCode(ruleCode); + } + return userPointsLogDTO; + } + + +} diff --git a/epdc-cloud-points/src/main/java/com/elink/esua/epdc/support/initbean/InitPointsRuleRedisCache.java b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/support/initbean/InitPointsRuleRedisCache.java new file mode 100644 index 0000000..ab5651f --- /dev/null +++ b/epdc-cloud-points/src/main/java/com/elink/esua/epdc/support/initbean/InitPointsRuleRedisCache.java @@ -0,0 +1,31 @@ +package com.elink.esua.epdc.support.initbean; + +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.modules.rule.service.PointsRuleService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * @Description 项目启动初始化积分规则到缓存 + * @Author yinzuomei + * @Date 2019/12/12 16:06 + */ +@Component +public class InitPointsRuleRedisCache implements InitializingBean { + private Logger logger = LoggerFactory.getLogger(getClass()); + @Autowired + private PointsRuleService pointsRuleService; + + @Override + public void afterPropertiesSet() throws Exception { + Result result = pointsRuleService.initPointsRuleRedis(); + if (result.success()) { + logger.info("积分规则初始化成功"); + } else { + logger.info("积分规则初始化失败" + result.getMsg()); + } + } +} diff --git a/epdc-cloud-points/src/main/resources/application.yml b/epdc-cloud-points/src/main/resources/application.yml new file mode 100644 index 0000000..25eddad --- /dev/null +++ b/epdc-cloud-points/src/main/resources/application.yml @@ -0,0 +1,79 @@ +server: + port: @server.port@ + servlet: + context-path: /points + +spring: + main: + allow-bean-definition-overriding: true + application: + name: epdc-points-server + # 环境 dev|test|prod + profiles: + active: @spring.profiles.active@ + messages: + encoding: UTF-8 + basename: i18n/messages,i18n/messages_common + jackson: + time-zone: GMT+8 + date-format: yyyy-MM-dd HH:mm:ss + redis: + database: @spring.redis.index@ + host: @spring.redis.host@ + timeout: 30s + port: @spring.redis.port@ + password: @spring.redis.password@ + cloud: + nacos: + discovery: + server-addr: @nacos.server-addr@ + register-enabled: @nacos.register-enabled@ + ip: @nacos.ip@ + namespace: @nacos.namespace@ + alibaba: + seata: + tx-service-group: epdc-points-server-fescar-service-group + datasource: + druid: + driver-class-name: com.mysql.jdbc.Driver + url: @spring.datasource.druid.url@ + username: @spring.datasource.druid.username@ + password: @spring.datasource.druid.password@ + zipkin: + # 指定了 zipkin 服务器的地址 + base-url: @spring.zipkin.base-url@ + sleuth: + sampler: + # 将采样比例设置为 1.0,也就是全部都需要。默认是 0.1 + probability: 1.0 + + +management: + endpoints: + web: + exposure: + include: "*" + endpoint: + health: + show-details: ALWAYS + +mybatis-plus: + mapper-locations: classpath:/mapper/**/*.xml + #实体扫描,多个package用逗号或者分号分隔 + typeAliasesPackage: io.renren.entity;com.elink.esua.epdc.entity + global-config: + #数据库相关配置 + db-config: + #主键类型 AUTO:"数据库ID自增", INPUT:"用户输入ID", ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID"; + id-type: ID_WORKER + #字段策略 IGNORED:"忽略判断",NOT_NULL:"非 NULL 判断"),NOT_EMPTY:"非空判断" + field-strategy: NOT_NULL + #驼峰下划线转换 + column-underline: true + banner: false + #原生配置 + configuration: + map-underscore-to-camel-case: true + cache-enabled: false + call-setters-on-nulls: true + jdbc-type-for-null: 'null' diff --git a/epdc-cloud-points/src/main/resources/i18n/messages.properties b/epdc-cloud-points/src/main/resources/i18n/messages.properties new file mode 100644 index 0000000..e69de29 diff --git a/epdc-cloud-points/src/main/resources/i18n/messages_en_US.properties b/epdc-cloud-points/src/main/resources/i18n/messages_en_US.properties new file mode 100644 index 0000000..e69de29 diff --git a/epdc-cloud-points/src/main/resources/i18n/messages_zh_CN.properties b/epdc-cloud-points/src/main/resources/i18n/messages_zh_CN.properties new file mode 100644 index 0000000..e69de29 diff --git a/epdc-cloud-points/src/main/resources/i18n/messages_zh_TW.properties b/epdc-cloud-points/src/main/resources/i18n/messages_zh_TW.properties new file mode 100644 index 0000000..e69de29 diff --git a/epdc-cloud-points/src/main/resources/i18n/validation.properties b/epdc-cloud-points/src/main/resources/i18n/validation.properties new file mode 100644 index 0000000..e69de29 diff --git a/epdc-cloud-points/src/main/resources/i18n/validation_en_US.properties b/epdc-cloud-points/src/main/resources/i18n/validation_en_US.properties new file mode 100644 index 0000000..e69de29 diff --git a/epdc-cloud-points/src/main/resources/i18n/validation_zh_CN.properties b/epdc-cloud-points/src/main/resources/i18n/validation_zh_CN.properties new file mode 100644 index 0000000..e69de29 diff --git a/epdc-cloud-points/src/main/resources/i18n/validation_zh_TW.properties b/epdc-cloud-points/src/main/resources/i18n/validation_zh_TW.properties new file mode 100644 index 0000000..e69de29 diff --git a/epdc-cloud-points/src/main/resources/logback-spring.xml b/epdc-cloud-points/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..5de0884 --- /dev/null +++ b/epdc-cloud-points/src/main/resources/logback-spring.xml @@ -0,0 +1,161 @@ + + + + + + + + + + + + + + debug + + + ${CONSOLE_LOG_PATTERN} + + UTF-8 + + + + + + + + ${log.path}/debug.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + + ${log.path}/debug-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + debug + ACCEPT + DENY + + + + + + + ${log.path}/info.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + + ${log.path}/info-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + info + ACCEPT + DENY + + + + + + + ${log.path}/warn.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + ${log.path}/warn-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + warn + ACCEPT + DENY + + + + + + + ${log.path}/error.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + ${log.path}/error-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + ERROR + ACCEPT + DENY + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/epdc-cloud-points/src/main/resources/mapper/logs/PointsLogsDao.xml b/epdc-cloud-points/src/main/resources/mapper/logs/PointsLogsDao.xml new file mode 100644 index 0000000..1412307 --- /dev/null +++ b/epdc-cloud-points/src/main/resources/mapper/logs/PointsLogsDao.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/epdc-cloud-points/src/main/resources/mapper/rule/PointsRuleDao.xml b/epdc-cloud-points/src/main/resources/mapper/rule/PointsRuleDao.xml new file mode 100644 index 0000000..40e8d53 --- /dev/null +++ b/epdc-cloud-points/src/main/resources/mapper/rule/PointsRuleDao.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/epdc-cloud-points/src/main/resources/registry.conf b/epdc-cloud-points/src/main/resources/registry.conf new file mode 100644 index 0000000..fb64abd --- /dev/null +++ b/epdc-cloud-points/src/main/resources/registry.conf @@ -0,0 +1,21 @@ +registry { + # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa + type = "nacos" + + nacos { + serverAddr = "@nacos.server-addr@" + namespace = "public" + cluster = "default" + } +} + +config { + # file、nacos 、apollo、zk、consul、etcd3 + type = "nacos" + + nacos { + serverAddr = "@nacos.server-addr@" + namespace = "public" + cluster = "default" + } +}