初始化

master
tangwenkang 2023-11-06 19:30:41 +08:00
commit 9fd87605d7
22 changed files with 1473 additions and 0 deletions

39
.gitignore vendored 100644
View File

@ -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

19
Dockerfile 100644
View File

@ -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"]

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.health</groupId>
<artifactId>health-information</artifactId>
<version>3.6.3</version>
</parent>
<version>3.6.3</version>
<artifactId>health-information-common</artifactId>
<dependencies>
<dependency>
<groupId>com.health</groupId>
<artifactId>health-common-core</artifactId>
</dependency>
<dependency>
<groupId>com.health</groupId>
<artifactId>health-common-security</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
<repositories>
<repository>
<id>dragon-public</id>
<name>dragon-maven</name>
<url>http://10.100.1.7:8081/repository/maven-public/</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>dragon-release</id>
<name>dragon-releases</name>
<url>http://10.100.1.7:8081/repository/maven-releases/</url>
</repository>
</distributionManagement>
</project>

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.health</groupId>
<artifactId>health-information</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>health-information-remote</artifactId>
<version>3.6.3</version>
<repositories>
<repository>
<id>dragon-public</id>
<name>dragon-maven</name>
<url>http://10.100.1.7:8081/repository/maven-public/</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>dragon-release</id>
<name>dragon-releases</name>
<url>http://10.100.1.7:8081/repository/maven-releases/</url>
</repository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>com.health</groupId>
<artifactId>health-information-common</artifactId>
<version>3.6.3</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,177 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.health</groupId>
<artifactId>health-information</artifactId>
<version>3.6.3</version>
</parent>
<version>3.6.3</version>
<artifactId>health-information-server</artifactId>
<dependencies>
<dependency>
<groupId>com.health</groupId>
<artifactId>health-wallet-common</artifactId>
<version>3.6.5</version>
</dependency>
<dependency>
<groupId>com.health</groupId>
<artifactId>health-wallet-remote</artifactId>
<version>3.6.5</version>
</dependency>
<dependency>
<groupId>com.health</groupId>
<artifactId>health-information-common</artifactId>
<version>3.6.3</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>4.5.16</version>
</dependency>
<dependency>
<groupId>com.health</groupId>
<artifactId>base-file-remote</artifactId>
</dependency>
<dependency>
<groupId>com.health</groupId>
<artifactId>base-system-common</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos Config -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- SpringCloud Alibaba Sentinel -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- SpringBoot Actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Swagger UI -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.fox.version}</version>
</dependency>
<!-- Mysql Connector -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<!-- RuoYi Common DataSource -->
<dependency>
<groupId>com.health</groupId>
<artifactId>health-common-datasource</artifactId>
</dependency>
<!-- RuoYi Common DataScope -->
<dependency>
<groupId>com.health</groupId>
<artifactId>health-common-datascope</artifactId>
</dependency>
<dependency>
<groupId>com.health</groupId>
<artifactId>health-common-security</artifactId>
<version>3.6.8</version>
</dependency>
<dependency>
<groupId>com.health</groupId>
<artifactId>health-common-redis</artifactId>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>2.18.30</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.813</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3-transfer-manager</artifactId>
<version>2.18.30-PREVIEW</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.15</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.5</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>dragon-public</id>
<name>dragon-maven</name>
<url>http://10.100.1.7:8081/repository/maven-public/</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>dragon-release</id>
<name>dragon-releases</name>
<url>http://10.100.1.7:8081/repository/maven-releases/</url>
</repository>
</distributionManagement>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!--当deploy时候忽略此model-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -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);
}
}

View File

@ -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<List<ResponseInformation>> listInformation(@PathVariable Integer informationTypeId) {
List<ResponseInformation> information = informationService.listInformation(informationTypeId);
return Result.success(information, "操作成功!");
}
/**
*
*
* @return
*/
@GetMapping("/listInformationType")
public Result<List<InformationType>> listInformationType() {
List<InformationType> 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<List<ResponseInformation>> listInformationCollection(@PathVariable Integer userId) {
List<ResponseInformation> 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);
}
}

View File

@ -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<ResponseInformation> listInformation(@Param("informationTypeId") Integer informationTypeId);
/**
*
*
* @return
*/
List<InformationType> listInformationType();
/**
*
*
* @param requestInsertInformation
*/
void insertInformation(RequestInsertInformation requestInsertInformation);
/**
*
*
* @param informationCollection
*/
void insertCollectionByUserIdAndInformationId(InformationCollection informationCollection);
/**
*
*
* @param userId
* @return
*/
List<ResponseInformation> 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);
}

View File

@ -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<ResponseInformation> listInformation(Integer informationTypeId);
/**
*
*
* @return
*/
List<InformationType> listInformationType();
/**
*
*
* @param requestInsertInformation
*/
void insertInformation(RequestInsertInformation requestInsertInformation);
/**
*
*
* @param informationId
*/
void insertCollectionByUserIdAndInformationId(Integer informationId);
/**
*
*
* @param userId
* @return
*/
List<ResponseInformation> listInformationCollection(Integer userId);
/**
*
*
* @param informationCollectionId
*/
void deleteInformationCollection(Integer informationCollectionId);
/**
*
*
* @param file
*/
Result uploadPicture(MultipartFile file) throws IOException;
/**
* H
*
* @param informationId
*/
void browseRewards(Integer informationId);
}

View File

@ -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<String, String> 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<ResponseInformation> listInformation(Integer informationTypeId) {
//根据资讯类型ID查询资讯类型对象
InformationType informationType = informationMapper.getInformationTypeKey(informationTypeId);
//判断当前查询的资讯是否存在redis
if (redisService.hasKey(informationType.getInformationTypeName())) {
//缓存
return redisService.getCacheList(informationType.getInformationTypeName());
}
List<ResponseInformation> responseInformationList = informationMapper.listInformation(informationType.getInformationTypeId());
redisService.setCacheList(informationType.getInformationTypeName(), responseInformationList);
//数据库
return responseInformationList;
}
/**
*
*
* @return
*/
@Override
public List<InformationType> 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<ResponseInformation> 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);
}
}
}

View File

@ -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<String, String> params) {
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, String> 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;
}
}

View File

@ -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}

View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<!-- 日志存放路径 -->
<property name="log.path" value="./logs/health-information" />
<!-- 日志输出格式 -->
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
<!-- 控制台输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
</appender>
<!-- 系统日志输出 -->
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/info.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>INFO</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/error.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>ERROR</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 系统模块日志级别控制 -->
<logger name="com.health" level="info" />
<!-- Spring日志级别控制 -->
<logger name="org.springframework" level="warn" />
<root level="info">
<appender-ref ref="console" />
</root>
<!--系统操作日志-->
<root level="info">
<appender-ref ref="file_info" />
<appender-ref ref="file_error" />
</root>
</configuration>

View File

@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.health.information.server.mapper.InformationMapper">
<!-- 发布资讯 -->
<insert id="insertInformation">
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>
<!-- 收藏资讯 -->
<insert id="insertCollectionByUserIdAndInformationId">
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>
<!-- 添加奖励记录 -->
<insert id="insertRewards">
INSERT INTO `health-information`.`t_rewards` (`rewards_id`, `is_rewards`, `rewards_time`, `rewards_user_id`,
`information_id`)
VALUES (0, #{isRewards}, now(), #{rewardsUserId}, #{informationId});
</insert>
<!-- 删除我收藏的资讯 -->
<update id="deleteInformationCollection">
update t_information_collection
set is_delete = 1
where information_collection_id = #{informationCollectionId}
</update>
<!-- 资讯列表 -->
<select id="listInformation" resultType="com.health.information.common.domain.response.ResponseInformation">
select
i.*,
it.information_type_name,
ic.information_collection_id,
ic.user_id,
ic.collection_time,
ic.is_delete,
ic.is_collection,
tr.rewards_id,
tr.is_rewards,
tr.rewards_time,
tr.rewards_user_id
from t_information i
left join t_information_type it on i.information_type_id = it.information_type_id
left join t_information_collection ic on ic.information_id = i.information_id
left join t_rewards tr on tr.information_id = i.information_id
<where>
<if test="null != informationTypeId">
and i.information_type_id = #{informationTypeId}
</if>
</where>
order by create_time desc
</select>
<!-- 查询资讯类型表 -->
<select id="listInformationType" resultType="com.health.information.common.domain.InformationType">
select *
from t_information_type
</select>
<!-- 查询资讯收藏表 -->
<select id="getInformationCollection" resultType="com.health.information.common.domain.InformationCollection">
select *
from t_information_collection
where information_id = #{informationId}
and user_id = #{userId}
</select>
<!-- 我收藏的资讯 -->
<select id="listInformationCollection" resultType="com.health.information.common.domain.response.ResponseInformation">
select ic.*,
i.information_title,
i.picture,
i.create_name,
i.create_time,
i.information_details,
i.information_type_id,
it.information_type_name
from t_information_collection ic
left join t_information i on i.information_id = ic.information_id
left join t_information_type it on it.information_type_id = i.information_type_id
where ic.user_id = #{userId}
and ic.is_delete = 2
and is_collection = 1
</select>
<!-- 根据资讯类型主键查询资讯类型对象 -->
<select id="getInformationTypeKey" resultType="com.health.information.common.domain.InformationType">
select *
from t_information_type
where information_type_id = #{informationTypeId}
</select>
<!-- 查询奖励表 -->
<select id="getInformation" resultType="com.health.information.common.domain.Rewards">
select is_rewards
from t_rewards
where information_id = #{informationId}
</select>
</mapper>

33
pom.xml 100644
View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.health</groupId>
<artifactId>health-modules</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>health-information</artifactId>
<packaging>pom</packaging>
<modules>
<module>health-information-common</module>
<module>health-information-remote</module>
<module>health-information-server</module>
</modules>
<version>3.6.3</version>
<repositories>
<repository>
<id>dragon-public</id>
<name>dragon-maven</name>
<url>http://10.100.1.7:8081/repository/maven-public/</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>dragon-release</id>
<name>dragon-releases</name>
<url>http://10.100.1.7:8081/repository/maven-releases/</url>
</repository>
</distributionManagement>
</project>