commit 9fd87605d70e83911759f491ea0f4c860e6438cd
Author: tangwenkang <2720983602@qq.com>
Date: Mon Nov 6 19:30:41 2023 +0800
初始化
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9369b72
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,39 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+logs
+.idea
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..055be55
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,19 @@
+#起始镜像
+FROM anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/openjdk:17-8.6
+#暴露端口号
+EXPOSE 10008
+
+#挂载目录的位置
+VOLUME /home/logs/health-information
+#构建复制外部文件到docker
+COPY health-information-server/target/health-information-server.jar /home/app.jar
+#工作目录 exec -it 进入容器内部后的默认的起始目录
+WORKDIR /home
+ENV TIME_ZONE Asia/Shanghai
+#指定东八区
+RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
+
+#启动java 程序
+ENTRYPOINT ["java","-Dfile.encoding=UTF-8","-jar","/home/app.jar"]
+
+
diff --git a/health-information-common/pom.xml b/health-information-common/pom.xml
new file mode 100644
index 0000000..71d7154
--- /dev/null
+++ b/health-information-common/pom.xml
@@ -0,0 +1,42 @@
+
+
+ 4.0.0
+
+ com.health
+ health-information
+ 3.6.3
+
+ 3.6.3
+ health-information-common
+
+
+ com.health
+ health-common-core
+
+
+ com.health
+ health-common-security
+
+
+ org.projectlombok
+ lombok
+
+
+
+
+ dragon-public
+ dragon-maven
+ http://10.100.1.7:8081/repository/maven-public/
+
+
+
+
+ dragon-release
+ dragon-releases
+ http://10.100.1.7:8081/repository/maven-releases/
+
+
+
+
diff --git a/health-information-common/src/main/java/com/health/information/common/domain/Information.java b/health-information-common/src/main/java/com/health/information/common/domain/Information.java
new file mode 100644
index 0000000..4980297
--- /dev/null
+++ b/health-information-common/src/main/java/com/health/information/common/domain/Information.java
@@ -0,0 +1,46 @@
+package com.health.information.common.domain;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.util.Date;
+
+/**
+ * @author Wenkang Tang
+ * @date 2023/10/19 15:21
+ * 资讯表
+ */
+@Data
+public class Information {
+ /**
+ * 资讯列表主键
+ */
+ private Integer informationId;
+ /**
+ * 资讯标题
+ */
+ private String informationTitle;
+ /**
+ * 图片
+ */
+ private String picture;
+ /**
+ * 发布人
+ */
+ private String createName;
+ /**
+ * 发布资讯时间
+ */
+ @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+ private Date createTime;
+ /**
+ * 资讯详情
+ */
+ private String informationDetails;
+ /**
+ * 资讯类型主键
+ */
+ private Integer informationTypeId;
+}
diff --git a/health-information-common/src/main/java/com/health/information/common/domain/InformationCollection.java b/health-information-common/src/main/java/com/health/information/common/domain/InformationCollection.java
new file mode 100644
index 0000000..6467e71
--- /dev/null
+++ b/health-information-common/src/main/java/com/health/information/common/domain/InformationCollection.java
@@ -0,0 +1,42 @@
+package com.health.information.common.domain;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.util.Date;
+
+/**
+ * @author Wenkang Tang
+ * @date 2023/10/22 20:16
+ * 资讯收藏表
+ */
+@Data
+public class InformationCollection {
+ /**
+ * 用户收藏资讯表主键
+ */
+ private Integer informationCollectionId;
+ /**
+ * 用户表主键
+ */
+ private Integer userId;
+ /**
+ * 资讯表主键
+ */
+ private Integer informationId;
+ /**
+ * 收藏时间
+ */
+ @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+ private Date collectionTime;
+ /**
+ * 是否删除收藏 1-是 2-否
+ */
+ private Integer isDelete;
+ /**
+ * 是否收藏 1-是
+ */
+ private Integer isCollection;
+}
diff --git a/health-information-common/src/main/java/com/health/information/common/domain/InformationType.java b/health-information-common/src/main/java/com/health/information/common/domain/InformationType.java
new file mode 100644
index 0000000..6f563f0
--- /dev/null
+++ b/health-information-common/src/main/java/com/health/information/common/domain/InformationType.java
@@ -0,0 +1,20 @@
+package com.health.information.common.domain;
+
+import lombok.Data;
+
+/**
+ * @author Wenkang Tang
+ * @date 2023/10/19 15:49
+ * 资讯类型表
+ */
+@Data
+public class InformationType {
+ /**
+ * 资讯类型主键
+ */
+ private Integer informationTypeId;
+ /**
+ * 资讯类型名称
+ */
+ private String informationTypeName;
+}
diff --git a/health-information-common/src/main/java/com/health/information/common/domain/Rewards.java b/health-information-common/src/main/java/com/health/information/common/domain/Rewards.java
new file mode 100644
index 0000000..01d0b68
--- /dev/null
+++ b/health-information-common/src/main/java/com/health/information/common/domain/Rewards.java
@@ -0,0 +1,33 @@
+package com.health.information.common.domain;
+
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * @author Wenkang Tang
+ * @date 2023/11/1 9:24
+ */
+@Data
+public class Rewards {
+ /**
+ * 奖励表主键
+ */
+ private Integer rewardsId;
+ /**
+ * 是否已经获取奖励 1-是
+ */
+ private Integer isRewards;
+ /**
+ * 被奖励时间
+ */
+ private Date rewardsTime;
+ /**
+ * 被奖励用户ID
+ */
+ private Integer rewardsUserId;
+ /**
+ * 视频表主键
+ */
+ private Integer informationId;
+}
diff --git a/health-information-common/src/main/java/com/health/information/common/domain/request/RequestInsertInformation.java b/health-information-common/src/main/java/com/health/information/common/domain/request/RequestInsertInformation.java
new file mode 100644
index 0000000..47ab709
--- /dev/null
+++ b/health-information-common/src/main/java/com/health/information/common/domain/request/RequestInsertInformation.java
@@ -0,0 +1,38 @@
+package com.health.information.common.domain.request;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @author Wenkang Tang
+ * @date 2023/10/20 16:18
+ * 发布咨询参数
+ */
+@Data
+public class RequestInsertInformation implements Serializable {
+ /**
+ * 资讯标题
+ */
+ private String informationTitle;
+ /**
+ * 图片
+ */
+ private String picture;
+ /**
+ * 传入的图片
+ */
+ private String[] receivePicture;
+ /**
+ * 发布资讯人
+ */
+ private String createName;
+ /**
+ * 资讯详情
+ */
+ private String informationDetails;
+ /**
+ * 资讯类型主键
+ */
+ private Integer informationTypeId;
+}
diff --git a/health-information-common/src/main/java/com/health/information/common/domain/request/RequestList.java b/health-information-common/src/main/java/com/health/information/common/domain/request/RequestList.java
new file mode 100644
index 0000000..e5d654c
--- /dev/null
+++ b/health-information-common/src/main/java/com/health/information/common/domain/request/RequestList.java
@@ -0,0 +1,14 @@
+package com.health.information.common.domain.request;
+
+import lombok.Data;
+
+/**
+ * @author Wenkang Tang
+ * @date 2023/11/3 20:46
+ */
+@Data
+public class RequestList {
+ private Integer informationTypeId;
+ private Integer pageNum = 1;
+ private Integer pageSize = 5;
+}
diff --git a/health-information-common/src/main/java/com/health/information/common/domain/response/ResponseInformation.java b/health-information-common/src/main/java/com/health/information/common/domain/response/ResponseInformation.java
new file mode 100644
index 0000000..d05233b
--- /dev/null
+++ b/health-information-common/src/main/java/com/health/information/common/domain/response/ResponseInformation.java
@@ -0,0 +1,80 @@
+package com.health.information.common.domain.response;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.util.Date;
+
+/**
+ * @author Wenkang Tang
+ * @date 2023/10/19 16:06
+ * 资讯列表响应参数
+ */
+@Data
+public class ResponseInformation {
+ /**
+ * 资讯列表主键
+ */
+ private Integer informationId;
+ /**
+ * 资讯标题
+ */
+ private String informationTitle;
+ /**
+ * 图片
+ */
+ private String picture;
+ /**
+ * 响应到前台的图片
+ */
+ private String[] receivePicture;
+ /**
+ * 发布人
+ */
+ private String createName;
+ /**
+ * 发布资讯时间
+ */
+ @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+ private Date createTime;
+ /**
+ * 资讯详情
+ */
+ private String informationDetails;
+ /**
+ * 资讯类型主键
+ */
+ private Integer informationTypeId;
+ /**
+ * 资讯类型名称
+ */
+ private String informationTypeName;
+ /**
+ * 用户收藏资讯表主键
+ */
+ private Integer informationCollectionId;
+ /**
+ * 用户表主键
+ */
+ private Integer userId;
+ /**
+ * 收藏时间
+ */
+ @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+ private Date collectionTime;
+ /**
+ * 是否删除收藏 1-是 2-否
+ */
+ private Integer isDelete;
+ /**
+ * 是否已经领取H币奖励 1-是 2-否
+ */
+ private Integer isRewards;
+ /**
+ * 是否收藏 1-是
+ */
+ private Integer isCollection;
+}
diff --git a/health-information-remote/pom.xml b/health-information-remote/pom.xml
new file mode 100644
index 0000000..957e5e6
--- /dev/null
+++ b/health-information-remote/pom.xml
@@ -0,0 +1,37 @@
+
+
+ 4.0.0
+
+ com.health
+ health-information
+ 3.6.3
+
+
+ health-information-remote
+
+ 3.6.3
+
+
+ dragon-public
+ dragon-maven
+ http://10.100.1.7:8081/repository/maven-public/
+
+
+
+
+ dragon-release
+ dragon-releases
+ http://10.100.1.7:8081/repository/maven-releases/
+
+
+
+
+ com.health
+ health-information-common
+ 3.6.3
+
+
+
+
diff --git a/health-information-server/pom.xml b/health-information-server/pom.xml
new file mode 100644
index 0000000..7ec783c
--- /dev/null
+++ b/health-information-server/pom.xml
@@ -0,0 +1,177 @@
+
+
+ 4.0.0
+
+ com.health
+ health-information
+ 3.6.3
+
+ 3.6.3
+ health-information-server
+
+
+ com.health
+ health-wallet-common
+ 3.6.5
+
+
+ com.health
+ health-wallet-remote
+ 3.6.5
+
+
+
+ com.health
+ health-information-common
+ 3.6.3
+
+
+ cn.hutool
+ hutool-all
+ 4.5.16
+
+
+
+ com.health
+ base-file-remote
+
+
+ com.health
+ base-system-common
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-discovery
+
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-config
+
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-sentinel
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+
+
+ io.springfox
+ springfox-swagger-ui
+ ${swagger.fox.version}
+
+
+
+
+ com.mysql
+ mysql-connector-j
+
+
+
+
+ com.health
+ health-common-datasource
+
+
+
+
+ com.health
+ health-common-datascope
+
+
+ com.health
+ health-common-security
+ 3.6.8
+
+
+ com.health
+ health-common-redis
+
+
+ software.amazon.awssdk
+ s3
+ 2.18.30
+
+
+ com.amazonaws
+ aws-java-sdk-s3
+ 1.11.813
+
+
+
+ org.slf4j
+ slf4j-simple
+ 2.0.5
+
+
+ software.amazon.awssdk
+ s3-transfer-manager
+ 2.18.30-PREVIEW
+
+
+ commons-codec
+ commons-codec
+ 1.15
+
+
+ org.slf4j
+ slf4j-simple
+ 2.0.5
+
+
+
+
+
+ dragon-public
+ dragon-maven
+ http://10.100.1.7:8081/repository/maven-public/
+
+
+
+
+ dragon-release
+ dragon-releases
+ http://10.100.1.7:8081/repository/maven-releases/
+
+
+
+ ${project.artifactId}
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ repackage
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-deploy-plugin
+
+ true
+
+
+
+
+
diff --git a/health-information-server/src/main/java/com/health/information/server/HealthInformationApp.java b/health-information-server/src/main/java/com/health/information/server/HealthInformationApp.java
new file mode 100644
index 0000000..4efcb20
--- /dev/null
+++ b/health-information-server/src/main/java/com/health/information/server/HealthInformationApp.java
@@ -0,0 +1,19 @@
+package com.health.information.server;
+
+import com.health.common.security.annotation.EnableRyFeignClients;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+/**
+ * @author 冯凯
+ * @version 1.0
+ * @description:
+ * @date 2023/10/18 22:20
+ */
+@SpringBootApplication
+@EnableRyFeignClients
+public class HealthInformationApp {
+ public static void main(String[] args) {
+ SpringApplication.run(HealthInformationApp.class);
+ }
+}
diff --git a/health-information-server/src/main/java/com/health/information/server/controller/InformationController.java b/health-information-server/src/main/java/com/health/information/server/controller/InformationController.java
new file mode 100644
index 0000000..b7907bf
--- /dev/null
+++ b/health-information-server/src/main/java/com/health/information/server/controller/InformationController.java
@@ -0,0 +1,116 @@
+package com.health.information.server.controller;
+
+import com.health.common.core.domain.Result;
+import com.health.information.common.domain.InformationType;
+import com.health.information.common.domain.request.RequestInsertInformation;
+import com.health.information.common.domain.response.ResponseInformation;
+import com.health.information.server.service.InformationService;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * @author Wenkang Tang
+ * @date 2023/10/19 11:11
+ */
+@RestController
+@RequestMapping("/information")
+@Log4j2
+public class InformationController {
+ @Autowired
+ private InformationService informationService;
+
+ /**
+ * 资讯列表
+ *
+ * @param informationTypeId
+ * @return
+ */
+ @PostMapping("/listInformation/{informationTypeId}")
+ public Result> listInformation(@PathVariable Integer informationTypeId) {
+ List information = informationService.listInformation(informationTypeId);
+ return Result.success(information, "操作成功!");
+ }
+
+ /**
+ * 查询资讯类型表
+ *
+ * @return
+ */
+ @GetMapping("/listInformationType")
+ public Result> listInformationType() {
+ List informationTypes = informationService.listInformationType();
+ return Result.success(informationTypes, "操作成功!");
+ }
+
+ /**
+ * 发布资讯
+ *
+ * @param requestInsertInformation
+ */
+ @PostMapping("/insertInformation")
+ public Result insertInformation(@RequestBody RequestInsertInformation requestInsertInformation) {
+ informationService.insertInformation(requestInsertInformation);
+ return Result.success(null, "操作成功!");
+ }
+
+ /**
+ * 收藏资讯
+ *
+ * @param informationId
+ */
+ @PostMapping("/insertInformationCollection/{informationId}")
+ public Result insertCollectionByUserIdAndInformationId(@PathVariable Integer informationId) {
+ informationService.insertCollectionByUserIdAndInformationId(informationId);
+ return Result.success(null, "操作成功!");
+ }
+
+ /**
+ * 我收藏的资讯
+ *
+ * @param userId
+ * @return
+ */
+ @PostMapping("/listInformationCollection/{userId}")
+ public Result> listInformationCollection(@PathVariable Integer userId) {
+ List responseInformationList = informationService.listInformationCollection(userId);
+ return Result.success(responseInformationList, "操作成功!");
+ }
+
+ /**
+ * 删除我收藏的资讯
+ *
+ * @param informationCollectionId
+ */
+ @PostMapping("/deleteInformationCollection/{informationCollectionId}")
+ public Result deleteInformationCollection(@PathVariable Integer informationCollectionId) {
+ informationService.deleteInformationCollection(informationCollectionId);
+ return Result.success(null, "操作成功!");
+ }
+
+ /**
+ * 上传图片
+ *
+ * @param file
+ */
+ @PostMapping("/uploadPicture")
+ public Result uploadPicture(@RequestParam MultipartFile file) throws IOException {
+ Result result = informationService.uploadPicture(file);
+ return result;
+ }
+
+ /**
+ * 浏览奖励H币
+ *
+ * @param informationId
+ */
+ @PostMapping("/browseRewards/{informationId}")
+ public void browseRewards(@PathVariable Integer informationId) {
+ informationService.browseRewards(informationId);
+ }
+
+}
diff --git a/health-information-server/src/main/java/com/health/information/server/mapper/InformationMapper.java b/health-information-server/src/main/java/com/health/information/server/mapper/InformationMapper.java
new file mode 100644
index 0000000..a95933d
--- /dev/null
+++ b/health-information-server/src/main/java/com/health/information/server/mapper/InformationMapper.java
@@ -0,0 +1,86 @@
+package com.health.information.server.mapper;
+
+import com.health.information.common.domain.InformationCollection;
+import com.health.information.common.domain.InformationType;
+import com.health.information.common.domain.Rewards;
+import com.health.information.common.domain.request.RequestInsertInformation;
+import com.health.information.common.domain.response.ResponseInformation;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * @author Wenkang Tang
+ * @date 2023/10/19 11:12
+ */
+@Mapper
+public interface InformationMapper {
+
+ /**
+ * 资讯列表
+ *
+ * @param informationTypeId
+ * @return
+ */
+ List listInformation(@Param("informationTypeId") Integer informationTypeId);
+
+ /**
+ * 查询资讯类型表
+ *
+ * @return
+ */
+ List listInformationType();
+
+ /**
+ * 发布咨询
+ *
+ * @param requestInsertInformation
+ */
+ void insertInformation(RequestInsertInformation requestInsertInformation);
+
+ /**
+ * 收藏资讯
+ *
+ * @param informationCollection
+ */
+ void insertCollectionByUserIdAndInformationId(InformationCollection informationCollection);
+
+ /**
+ * 我收藏的资讯
+ *
+ * @param userId
+ * @return
+ */
+ List listInformationCollection(@Param("userId") Integer userId);
+
+ /**
+ * 删除我收藏的资讯
+ *
+ * @param informationCollectionId
+ */
+ void deleteInformationCollection(@Param("informationCollectionId") Integer informationCollectionId);
+
+ /**
+ * 根据资讯类型主键查询资讯类型对象
+ *
+ * @param informationTypeId
+ * @return
+ */
+ InformationType getInformationTypeKey(@Param("informationTypeId") Integer informationTypeId);
+
+ /**
+ * 查询奖励表
+ *
+ * @param informationId
+ * @return
+ */
+ Rewards getInformation(@Param("informationId") Integer informationId);
+
+ /**
+ * 添加奖励记录
+ *
+ * @param rws
+ */
+ void insertRewards(Rewards rws);
+}
diff --git a/health-information-server/src/main/java/com/health/information/server/service/InformationService.java b/health-information-server/src/main/java/com/health/information/server/service/InformationService.java
new file mode 100644
index 0000000..7fe2520
--- /dev/null
+++ b/health-information-server/src/main/java/com/health/information/server/service/InformationService.java
@@ -0,0 +1,74 @@
+package com.health.information.server.service;
+
+import com.health.common.core.domain.Result;
+import com.health.information.common.domain.InformationType;
+import com.health.information.common.domain.request.RequestInsertInformation;
+import com.health.information.common.domain.response.ResponseInformation;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * @author Wenkang Tang
+ * @date 2023/10/19 11:12
+ */
+public interface InformationService {
+ /**
+ * 资讯列表
+ *
+ * @param informationTypeId
+ * @return
+ */
+ List listInformation(Integer informationTypeId);
+
+ /**
+ * 查询资讯类型表
+ *
+ * @return
+ */
+ List listInformationType();
+
+ /**
+ * 发布咨询
+ *
+ * @param requestInsertInformation
+ */
+ void insertInformation(RequestInsertInformation requestInsertInformation);
+
+ /**
+ * 收藏资讯
+ *
+ * @param informationId
+ */
+ void insertCollectionByUserIdAndInformationId(Integer informationId);
+
+ /**
+ * 我收藏的资讯
+ *
+ * @param userId
+ * @return
+ */
+ List listInformationCollection(Integer userId);
+
+ /**
+ * 删除我收藏的资讯
+ *
+ * @param informationCollectionId
+ */
+ void deleteInformationCollection(Integer informationCollectionId);
+
+ /**
+ * 上传图片
+ *
+ * @param file
+ */
+ Result uploadPicture(MultipartFile file) throws IOException;
+
+ /**
+ * 浏览奖励H币
+ *
+ * @param informationId
+ */
+ void browseRewards(Integer informationId);
+}
diff --git a/health-information-server/src/main/java/com/health/information/server/service/impl/InformationServiceImpl.java b/health-information-server/src/main/java/com/health/information/server/service/impl/InformationServiceImpl.java
new file mode 100644
index 0000000..2227bf3
--- /dev/null
+++ b/health-information-server/src/main/java/com/health/information/server/service/impl/InformationServiceImpl.java
@@ -0,0 +1,228 @@
+package com.health.information.server.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.health.common.core.constant.SecurityConstants;
+import com.health.common.core.domain.Result;
+import com.health.common.redis.service.RedisService;
+import com.health.common.security.utils.SecurityUtils;
+import com.health.information.common.domain.InformationType;
+import com.health.information.common.domain.InformationCollection;
+import com.health.information.common.domain.Rewards;
+import com.health.information.common.domain.request.RequestInsertInformation;
+import com.health.information.common.domain.response.ResponseInformation;
+import com.health.information.server.mapper.InformationMapper;
+import com.health.information.server.service.InformationService;
+import com.health.information.server.utils.DogeUtil;
+import com.health.wallet.common.domain.req.MoneyChangeRecordReq;
+import com.health.wallet.remote.RemoteWalletService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
+import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
+import software.amazon.awssdk.core.sync.RequestBody;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.s3.S3Client;
+import software.amazon.awssdk.services.s3.model.PutObjectRequest;
+import software.amazon.awssdk.services.s3.model.PutObjectResponse;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * @author Wenkang Tang
+ * @date 2023/10/19 11:12
+ */
+@Service
+@SuppressWarnings("ALL")
+public class InformationServiceImpl implements InformationService {
+ @Autowired
+ private InformationMapper informationMapper;
+ @Autowired
+ private RedisService redisService;
+ @Autowired
+ private RedisTemplate redisTemplate;
+ @Autowired
+ private DogeUtil dogeUtil;
+ @Autowired
+ private RemoteWalletService remoteWalletService;
+
+ public static S3Client init(JSONObject credentials) {
+ AwsSessionCredentials awsCreds = AwsSessionCredentials.create(
+ credentials.getString("accessKeyId"),
+ credentials.getString("secretAccessKey"),
+ credentials.getString("sessionToken"));
+
+ return S3Client.builder()
+ .credentialsProvider(StaticCredentialsProvider.create(awsCreds))
+ .region(Region.of("automatic"))
+ .endpointOverride(URI.create("https://cos.ap-shanghai.myqcloud.com")) // 修改为多吉云控制台存储空间 SDK 参数中的 s3Endpoint
+ .build();
+ }
+
+ /**
+ * 资讯列表
+ *
+ * @param informationTypeId
+ * @return
+ */
+ @Override
+ public List listInformation(Integer informationTypeId) {
+ //根据资讯类型ID查询资讯类型对象
+ InformationType informationType = informationMapper.getInformationTypeKey(informationTypeId);
+ //判断当前查询的资讯是否存在redis
+ if (redisService.hasKey(informationType.getInformationTypeName())) {
+ //缓存
+ return redisService.getCacheList(informationType.getInformationTypeName());
+ }
+ List responseInformationList = informationMapper.listInformation(informationType.getInformationTypeId());
+
+ redisService.setCacheList(informationType.getInformationTypeName(), responseInformationList);
+ //数据库
+ return responseInformationList;
+ }
+
+ /**
+ * 查询资讯类型表
+ *
+ * @return
+ */
+ @Override
+ public List listInformationType() {
+ return informationMapper.listInformationType();
+ }
+
+ /**
+ * 发布资讯
+ *
+ * @param requestInsertInformation
+ */
+ @Override
+ public void insertInformation(RequestInsertInformation requestInsertInformation) {
+ //根据资讯类型主键查询资讯类型对象
+ InformationType informationTypeKey = informationMapper.getInformationTypeKey(requestInsertInformation.getInformationTypeId());
+ //根据资讯类型名称删除键
+ redisTemplate.delete(informationTypeKey.getInformationTypeName());
+ //获取前台传入的照片数组
+ String[] receivePicture = requestInsertInformation.getReceivePicture();
+ StringBuilder pics = new StringBuilder();
+ for (String picture : receivePicture) {
+ //循环拼接
+ pics.append(picture).append(",");
+ }
+ //获取当前发布咨询人名称给参数createName赋值
+ requestInsertInformation.setCreateName(SecurityUtils.getUsername());
+ //字符串图片截取
+ requestInsertInformation.setPicture(pics.substring(0, pics.length() - 1));
+ informationMapper.insertInformation(requestInsertInformation);
+ }
+
+ /**
+ * 收藏资讯
+ *
+ * @param informationId
+ */
+ @Override
+ public void insertCollectionByUserIdAndInformationId(Integer informationId) {
+ //创建收藏资讯对象
+ InformationCollection collection = new InformationCollection();
+ collection.setUserId(Math.toIntExact(SecurityUtils.getUserId()));
+ collection.setInformationId(informationId);
+ collection.setIsDelete(2);
+ collection.setIsCollection(1);
+ informationMapper.insertCollectionByUserIdAndInformationId(collection);//收藏资讯
+ }
+
+ /**
+ * 查询我收藏的资讯
+ *
+ * @param userId
+ * @return
+ */
+ @Override
+ public List listInformationCollection(Integer userId) {
+ return informationMapper.listInformationCollection(userId);
+ }
+
+ /**
+ * 删除我收藏的资讯
+ *
+ * @param informationCollectionId
+ */
+ @Override
+ public void deleteInformationCollection(Integer informationCollectionId) {
+ informationMapper.deleteInformationCollection(informationCollectionId);
+ }
+
+ /**
+ * 上传图片
+ *
+ * @param file
+ */
+ @Override
+ public Result uploadPicture(MultipartFile file) throws IOException {
+ String _bucket = "yanmou"; // 替换为你要上传到的存储空间名称
+ //获取文件后缀,因此此后端代码可接收一切文件,上传格式前端限定
+ String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1)
+ .toLowerCase();
+ // 重构文件名称
+ String pikId = UUID.randomUUID().toString().replaceAll("-", "");
+ String newVideoName = pikId + "." + fileExt;
+ String _key = "information/" + newVideoName; // 本次允许客户端上传的文件名,请根据当前网站用户登录状态、权限进行合理的最小化授权
+ // String _key = "abc/*"; // 也可以这样设置为 abc/* ,表示允许客户端上传到 abc 文件夹下的任意文件名
+ // String _key = "*"; // 或者设为 * 表示允许客户端上传到该存储空间内的任意文件(有安全风险,不推荐这样做)
+
+ JSONObject body = new JSONObject(); // 这里 JSONObject 来自 org.json.JSONObject
+ // 存储请求的信息
+ body.put("channel", "OSS_UPLOAD");
+ body.put("scopes", _bucket + ":" + _key);
+
+ JSONObject data = dogeUtil.dogeAPIGet("/auth/tmp_token.json", body);
+ JSONObject credentials = data.getJSONObject("Credentials");
+ System.out.println(data);
+ // 调用 init 方法初始化 s3Client,并将 credentials 作为参数
+ S3Client s3Client = init(credentials);
+ PutObjectRequest putOb = PutObjectRequest.builder()
+ .bucket("s-sh-7758-yanmou-1258813047") // 存储空间的名称
+ .key(_key)
+ .build();
+
+ InputStream inputStream = file.getInputStream();//获取文件的输入流
+ int available = inputStream.available();
+ PutObjectResponse putObjectResponse = s3Client.putObject(putOb, RequestBody.fromInputStream(inputStream, available));
+
+ return Result.success("http://s-sh-7758-yanmou.oss.dogecdn.com/" + putOb.key(), "上传成功!");
+ // RequestBody 也支持 fromFile、fromBytes、fromBytesBuffer、fromInputStream 等多种来源
+ }
+
+ /**
+ * 浏览奖励H币
+ *
+ * @param informationId
+ */
+ @Override
+ public void browseRewards(Integer informationId) {
+ //查询奖励表
+ Rewards rewards = informationMapper.getInformation(informationId);
+ if (null == rewards.getIsRewards()) {
+ Rewards rws = new Rewards();
+ rws.setRewardsUserId(Math.toIntExact(SecurityUtils.getUserId()));
+ rws.setIsRewards(1);
+ rws.setInformationId(informationId);
+ //添加奖励记录
+ informationMapper.insertRewards(rws);
+
+ //修改用户余额
+ MoneyChangeRecordReq moneyChangeRecordReq = new MoneyChangeRecordReq();
+ moneyChangeRecordReq.setChangeAmount(10);
+ moneyChangeRecordReq.setChangeOrigin("浏览资讯超过10s奖励H币");
+ moneyChangeRecordReq.setChangeType(1);
+ moneyChangeRecordReq.setCreateUser(SecurityUtils.getUserId());
+ remoteWalletService.moneyChangeByOtherOperate(moneyChangeRecordReq, SecurityConstants.INNER);
+ }
+ }
+}
diff --git a/health-information-server/src/main/java/com/health/information/server/utils/DogeUtil.java b/health-information-server/src/main/java/com/health/information/server/utils/DogeUtil.java
new file mode 100644
index 0000000..46e66af
--- /dev/null
+++ b/health-information-server/src/main/java/com/health/information/server/utils/DogeUtil.java
@@ -0,0 +1,119 @@
+package com.health.information.server.utils;
+
+import com.alibaba.fastjson.JSONObject;
+import org.apache.commons.codec.binary.Hex;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.stereotype.Component;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.util.Map;
+
+/**
+ * @author Wenkang Tang
+ * @date 2023/10/27 20:33
+ */
+@Configuration
+@Component
+public class DogeUtil {
+ // 普通 API 请使用这个方法
+ public JSONObject dogeAPIGet(String apiPath, Map params) {
+ StringBuilder sb = new StringBuilder();
+ for (Map.Entry hm : params.entrySet()) {
+ try {
+ sb.append(URLEncoder.encode(hm.getKey(), String.valueOf(StandardCharsets.UTF_8))).append('=').append(URLEncoder.encode(hm.getValue(), String.valueOf(StandardCharsets.UTF_8))).append("&");
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ String bodyText = sb.toString().replace("&$", "");
+ try {
+ return dogeAPIGet(apiPath, bodyText, false);
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new RuntimeException(e.getMessage());
+ }
+ }
+
+ // 要求请求内容 Body 是一个 JSON 的 API,请使用这个方法
+ public JSONObject dogeAPIGet(String apiPath, JSONObject params) {
+ String bodyText = params.toString();
+ try {
+ return dogeAPIGet(apiPath, bodyText, true);
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new RuntimeException(e.getMessage());
+ }
+ }
+
+ // 无参数 API
+ public JSONObject dogeAPIGet(String apiPath) {
+ try {
+ return dogeAPIGet(apiPath, "", true);
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new RuntimeException(e.getMessage());
+ }
+ }
+
+ public JSONObject dogeAPIGet(String apiPath, String paramsText, Boolean jsonMode) throws IOException {
+ // 这里返回值类型是 JSONObject,你也可以根据你的具体情况使用不同的 JSON 库并修改最下方 JSON 处理代码
+
+ // 这里替换为你的多吉云永久 AccessKey 和 SecretKey,可在用户中心 - 密钥管理中查看
+ // 请勿在客户端暴露 AccessKey 和 SecretKey,那样恶意用户将获得账号完全控制权
+ String accessKey = "02a4810cb73129c4";
+ String secretKey = "4d9a1342fcee91d96698ce9425d5a23a";
+
+ String signStr = apiPath + "\n" + paramsText;
+ String sign = "";
+ try {
+ Mac mac = Mac.getInstance("HmacSHA1");
+ mac.init(new SecretKeySpec(secretKey.getBytes(), "HmacSHA1"));
+ sign = new String(new Hex().encode(mac.doFinal(signStr.getBytes())), StandardCharsets.UTF_8); // 这里 Hex 来自 org.apache.commons.codec.binary.Hex
+ } catch (NoSuchAlgorithmException | InvalidKeyException e) {
+ e.printStackTrace();
+ throw new RuntimeException(e.getMessage());
+ }
+ String authorization = "TOKEN " + accessKey + ':' + sign;
+
+ URL u = new URL("https://api.dogecloud.com" + apiPath);
+ HttpURLConnection conn = (HttpURLConnection) u.openConnection();
+ conn.setDoOutput(true);
+ conn.setRequestMethod("POST");
+ conn.setRequestProperty("Content-Type", jsonMode ? "application/json" : "application/x-www-form-urlencoded");
+ conn.setRequestProperty("Authorization", authorization);
+ conn.setRequestProperty("Content-Length", String.valueOf(paramsText.length()));
+ OutputStream os = conn.getOutputStream();
+ os.write(paramsText.getBytes());
+ os.flush();
+ os.close();
+ StringBuilder retJSON = new StringBuilder();
+ if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
+ String readLine = "";
+ try (BufferedReader responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) {
+ while ((readLine = responseReader.readLine()) != null) {
+ retJSON.append(readLine).append("\n");
+ }
+ responseReader.close();
+ }
+ JSONObject ret = JSONObject.parseObject(retJSON.toString());
+ if (ret.getInteger("code") != 200) {
+ System.err.println("{\"error\":\"API 返回错误:" + ret.getString("msg") + "\"}");
+ } else {
+ JSONObject output = new JSONObject();
+ JSONObject data = ret.getJSONObject("data");
+ return data;
+ }
+ } else {
+ System.err.println("{\"error\":\"网络错误:" + conn.getResponseCode() + "\"}");
+ }
+ return null;
+ }
+}
diff --git a/health-information-server/src/main/resources/bootstrap.yml b/health-information-server/src/main/resources/bootstrap.yml
new file mode 100644
index 0000000..b07a134
--- /dev/null
+++ b/health-information-server/src/main/resources/bootstrap.yml
@@ -0,0 +1,28 @@
+# Tomcat
+server:
+ port: 10008
+
+# Spring
+spring:
+ jackson:
+ date-format: yyyy-MM-dd HH:mm:ss
+ time-zone: GMT+8
+ application:
+ # 应用名称
+ name: health-information
+ profiles:
+ # 环境配置
+ active: dev
+ cloud:
+ nacos:
+ discovery:
+ # 服务注册地址
+ server-addr: 10.100.1.5:8848
+ config:
+ # 配置中心地址
+ server-addr: 10.100.1.5:8848
+ # 配置文件格式
+ file-extension: yml
+ # 共享配置
+ shared-configs:
+ - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
diff --git a/health-information-server/src/main/resources/logback.xml b/health-information-server/src/main/resources/logback.xml
new file mode 100644
index 0000000..c02e4e7
--- /dev/null
+++ b/health-information-server/src/main/resources/logback.xml
@@ -0,0 +1,74 @@
+
+
+
+
+
+
+
+
+
+
+ ${log.pattern}
+
+
+
+
+
+ ${log.path}/info.log
+
+
+
+ ${log.path}/info.%d{yyyy-MM-dd}.log
+
+ 60
+
+
+ ${log.pattern}
+
+
+
+ INFO
+
+ ACCEPT
+
+ DENY
+
+
+
+
+ ${log.path}/error.log
+
+
+
+ ${log.path}/error.%d{yyyy-MM-dd}.log
+
+ 60
+
+
+ ${log.pattern}
+
+
+
+ ERROR
+
+ ACCEPT
+
+ DENY
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/health-information-server/src/main/resources/mapper/InformationMapper.xml b/health-information-server/src/main/resources/mapper/InformationMapper.xml
new file mode 100644
index 0000000..d1bcb54
--- /dev/null
+++ b/health-information-server/src/main/resources/mapper/InformationMapper.xml
@@ -0,0 +1,109 @@
+
+
+
+
+
+
+ INSERT INTO `health-information`.`t_information` (`information_id`, `information_title`, `picture`,
+ `create_name`, `create_time`, `information_details`,
+ `information_type_id`)
+ VALUES (0, #{informationTitle}, #{picture}, #{createName}, now(), #{informationDetails}, #{informationTypeId});
+
+
+
+
+ INSERT INTO `health-information`.`t_information_collection` (`information_collection_id`, `user_id`,
+ `information_id`, `collection_time`, `is_delete`,
+ `is_collection`)
+ VALUES (0, #{userId}, #{informationId}, now(), #{isDelete}, #{isCollection});
+
+
+
+
+ INSERT INTO `health-information`.`t_rewards` (`rewards_id`, `is_rewards`, `rewards_time`, `rewards_user_id`,
+ `information_id`)
+ VALUES (0, #{isRewards}, now(), #{rewardsUserId}, #{informationId});
+
+
+
+
+
+ update t_information_collection
+ set is_delete = 1
+ where information_collection_id = #{informationCollectionId}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..5109615
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,33 @@
+
+
+ 4.0.0
+
+ com.health
+ health-modules
+ 3.6.3
+
+ health-information
+ pom
+
+ health-information-common
+ health-information-remote
+ health-information-server
+
+ 3.6.3
+
+
+ dragon-public
+ dragon-maven
+ http://10.100.1.7:8081/repository/maven-public/
+
+
+
+
+ dragon-release
+ dragon-releases
+ http://10.100.1.7:8081/repository/maven-releases/
+
+
+