Commit 4d4c89ef authored by yaobaizheng's avatar yaobaizheng

合伙招商后台

parents
Pipeline #71 failed with stages
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
# cfld-know-partner
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin http://10.90.102.101/cfld-group/cfld-know-partner.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](http://10.90.102.101/cfld-group/cfld-know-partner/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!--parent指明继承关系-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.15</version>
</parent>
<groupId>com.partner</groupId>
<artifactId>cfld-know-partner</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>partner-admin</name>
<description>partner-admin</description>
<packaging>jar</packaging>
<properties>
<java.version>1.8</java.version>
<pagehelper.boot.version>1.4.6</pagehelper.boot.version>
<mybatis.plus.version>3.5.2</mybatis.plus.version>
<druid.version>1.2.16</druid.version>
<hutool.version>5.8.20</hutool.version>
<lombook.version>1.18.28</lombook.version>
<swagger.version>3.0.0</swagger.version>
<swagger-models.version>1.6.2</swagger-models.version>
<knife4j.version>3.0.3</knife4j.version>
<commons.io.version>2.11.0</commons.io.version>
</properties>
<dependencies>
<!--mysql连接驱动-->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<!-- 阿里数据库连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${druid.version}</version>
</dependency>
<!-- pagehelper分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>${pagehelper.boot.version}</version>
</dependency>
<!-- mybatis增强器依赖 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis.plus.version}</version>
</dependency>
<!-- mybatis-plus代码生成器依赖 -->
<!-- <dependency>-->
<!-- <groupId>com.baomidou</groupId>-->
<!-- <artifactId>mybatis-plus-generator</artifactId>-->
<!-- <version>${mybatis.plus.version}</version>-->
<!-- </dependency>-->
<!-- hutool工具包 -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>${hutool.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombook.version}</version>
</dependency>
<!-- Swagger3依赖 -->
<!-- <dependency>-->
<!-- <groupId>io.springfox</groupId>-->
<!-- <artifactId>springfox-boot-starter</artifactId>-->
<!-- <version>${swagger.version}</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>${knife4j.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<!-- SpringBoot 拦截器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!--热部署-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<!--常用工具类 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!-- io常用工具类 -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons.io.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- #解决swagger报错 Failed to start bean ‘documentationPluginsBootstrapper’-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-webmvc</artifactId>
<version>3.0.0</version>
</dependency>
<!--华为obs依赖 -->
<dependency>
<groupId>com.huaweicloud</groupId>
<artifactId>esdk-obs-java</artifactId>
<version>3.21.8</version>
</dependency>
<dependency>
<groupId>org.web3j</groupId>
<artifactId>core</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.3.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork> <!-- 如果没有该配置,devtools不会生效 -->
</configuration>
</plugin>
</plugins>
</build>
</project>
package com.partner.admin;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DfldKnowPartnerApplication {
public static void main(String[] args) {
SpringApplication.run(DfldKnowPartnerApplication.class, args);
}
}
package com.partner.admin;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(DfldKnowPartnerApplication.class);
}
}
package com.partner.admin.VO;
import com.partner.admin.domain.PartnerImageSource;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
/**
*
*/
@Data
@ApiModel(value = "返回登陆时首页轮播图,统计数信息")
public class HomePageLoginInfoVO implements Serializable {
@ApiModelProperty(value = "轮播图")
private List<PartnerImageSource> partnerImageSourceList = new ArrayList<>();
@ApiModelProperty(value = "总项目量")
private Long projectAllCount = 0L;
@ApiModelProperty(value = "总投资额")
private BigDecimal projectInvestmentTotal = new BigDecimal(0.0);
@ApiModelProperty(value = "审核中的项目")
private Long projectExamineCount = 0L;
@ApiModelProperty(value = "推进中的项目")
private Long projectPushCount = 0L;
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
package com.partner.admin.VO;
import com.partner.admin.domain.PartnerImageSource;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
/**
*
*/
@Data
@ApiModel(value = "返回未登陆时首页轮播图,统计数信息")
public class HomePageLogoutInfoVO implements Serializable {
@ApiModelProperty(value = "轮播图")
private List<PartnerImageSource> partnerImageSourceList = new ArrayList<>();
@ApiModelProperty(value = "总项目量")
private Long projectAllCount = 0L;
@ApiModelProperty(value = "项目总投资额")
private BigDecimal projectInvestmentTotal = new BigDecimal(0.0);
@ApiModelProperty(value = "项目总固定资产投资额")
private BigDecimal projectInvestmentRegular = new BigDecimal(0.0);
@ApiModelProperty(value = "平台合伙人")
private Long partnerCount = 0L;
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
package com.partner.admin.VO;
import com.partner.admin.domain.PartnerBaseInfo;
import com.partner.admin.domain.PartnerCoporateAccountInfo;
import com.partner.admin.domain.PartnerImageSource;
import lombok.Data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@Data
public class PartnerBaseInfoVO implements Serializable {
// /**
// * 合伙人id
// */
// @TableId
// private Integer id;
//
// /**
// * 昵称
// */
// private String nickName;
//
// /**
// * 头像
// */
// private String headerUrl;
//
// /**
// * 0-未认知 1-已认证 未认证不能做佣金提取 -真实姓名和身份证都有才认为认证通过
// */
// private Integer hasAuthentication;
//
// /**
// * 手机号
// */
// private String mobilePhone;
//
// /**
// * 资料完成度
// */
// private String infoPrecentage;
//
// /**
// * 真实姓名
// */
// private String realName;
//
// /**
// * 身份证号
// */
// private String idcardNumber;
//
// /**
// * 开户行
// */
// private String bank;
//
// /**
// * 银行账户
// */
// private String bankCard;
//
// /**
// * 在职公司
// */
// private String company;
//
// /**
// * 在职行业
// */
// private String industry;
//
// /**
// * 所在职位
// */
// private String position;
//
// /**
// * 负责内容
// */
// private String responsbility;
//
// /**
// * 邮箱地址
// */
// private String email;
//
// /**
// * 毕业院校
// */
// private String college;
//
// /**
// *
// */
// private String region;
//
// /**
// * 租户id
// */
// private Integer tenantId;
//
// /**
// *
// */
// private String openId;
private PartnerBaseInfo partnerBaseInfo = new PartnerBaseInfo();
private List<PartnerCoporateAccountInfoVO> partnerCoporateAccountInfoVO = new ArrayList<>();
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
package com.partner.admin.VO;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.partner.admin.domain.PartnerCoporateAccountInfo;
import com.partner.admin.domain.PartnerImageSource;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
*
* @TableName partner_coporate_account_info
*/
@TableName(value ="partner_coporate_account_info")
@Data
public class PartnerCoporateAccountInfoVO implements Serializable {
private PartnerCoporateAccountInfo partnerCoporateAccountInfo = new PartnerCoporateAccountInfo();
private List<PartnerImageSource> partnerImageSourceList = new ArrayList<>();
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
package com.partner.admin.VO;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
*
* @TableName partner_project_info
*/
@Data
@ApiModel(value="项目信息")
public class PartnerExamineProjectInfoVO implements Serializable {
/**
*
*/
@ApiModelProperty(hidden = true)
private Integer id;
/**
* 投资主体
*/
@ApiModelProperty(value = "投资主体")
private String investmentSubject;
/**
* 投资总额
*/
@ApiModelProperty(value = "投资总额")
private BigDecimal projectInvestmentTotal;
/**
* 固定资产投资总额
*/
@ApiModelProperty(value = "固定资产投资总额")
private BigDecimal projectInvestmentRegular;
/**
* 0-暂存 1-信息提报 2-项目查重通过 3-项目查重拒绝 4-招商公司匹配 5-企业对接 6-投资意向确认 7-确认项目信息 8-完成审核 9-项目信息 10-项目沟通 11-区域匹配 12-政企互访 13-项目谈判 14-项目签约 15-分配中 20-作废
*/
@ApiModelProperty(hidden = true)
private Integer status;
/**
* 0-暂存 1-信息提报 2-项目查重通过 3-项目查重拒绝 4-招商公司匹配 5-企业对接 6-投资意向确认 7-确认项目信息 8-完成审核 9-项目信息 10-项目沟通 11-区域匹配 12-政企互访 13-项目谈判 14-项目签约 15-分配中 20-作废
*/
@ApiModelProperty(hidden = true)
private String statusDescription;
/**
* 匹配招商公司
*/
@ApiModelProperty(value = "匹配招商公司")
private String investmentPromotionCompany;
/**
* 0-项目查重确认 1-确认项目所属 2-确认佣金比例
*/
@ApiModelProperty(hidden = true)
private Integer todoStatus;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
package com.partner.admin.VO;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 用户信息表
* @TableName sys_user
*/
@Data
@ApiModel(value = "个人基本信息")
public class SysUserVO implements Serializable {
/**
* 用户ID
*/
@ApiModelProperty(value = "用户ID")
private Integer userId;
/**
* 登录账号
*/
@ApiModelProperty(value = "登录账号")
private String loginName;
/**
* 用户昵称
*/
@ApiModelProperty(value = "用户昵称")
private String userName;
/**
* 用户邮箱
*/
@ApiModelProperty(value = "用户邮箱")
private String email;
/**
* 手机号码
*/
@ApiModelProperty(value = "手机号码")
private String phonenumber;
/**
* 头像路径
*/
@ApiModelProperty(value = "头像路径")
private String avatar;
@ApiModelProperty(value = "token")
private String token;
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
package com.partner.admin.common.config;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
/**
* @author yaobaizheng
*/
@Configuration
// 表示通过aop框架暴露该代理对象,AopContext能够访问
@EnableAspectJAutoProxy(exposeProxy = true)
// 指定要扫描的Mapper类的包的路径
@MapperScan("com.partner.**.mapper")
public class ApplicationConfig
{
}
package com.partner.admin.common.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* 全局配置类
* @author yaobaizheng
*/
@Data
@Component
@ConfigurationProperties(prefix = "partner")
public class PartnerConfig
{
private String profile;
private String obsPath;
private Integer tokenExpireTimeDays;
private Boolean enableUrlFilter;
}
package com.partner.admin.common.config;
import com.partner.admin.common.interceptor.LoginInterceptor;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* @author yaobaizheng
* @desc 解决跨域问题
*/
@Configuration
public class ResourceConfig implements WebMvcConfigurer {
@Autowired
LoginInterceptor loginInterceptor;
@Autowired
PartnerConfig parterConfig;
/**
* 自定义拦截规则
*/
@Override
public void addInterceptors(InterceptorRegistry registry)
{
if(parterConfig.getEnableUrlFilter()){
String[] excludeSwagger = new String[]{"/swagger-resources/**",
"/webjars/**", "/v2/**","/v3/**", "/swagger-ui.html/**",
"/api", "/api-docs", "/api-docs/**", "/doc.html/**"};
String[] excludeUrl = new String[]{"/weixin/**",
"/sysFile/**","/common/**"};
String[] excludePatterns = (String[]) ArrayUtils.addAll(excludeSwagger, excludeUrl);
System.out.println("自定义拦截器#############################################");
registry.addInterceptor(loginInterceptor)
.addPathPatterns("/**")
.excludePathPatterns(excludePatterns);
}
}
/**
* 跨域配置
*/
@Bean
public CorsFilter corsFilter()
{
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
// 设置访问源地址
config.addAllowedOriginPattern("*");
// 设置访问源请求头
config.addAllowedHeader("*");
// 设置访问源请求方法
config.addAllowedMethod("*");
// 有效期 3600秒
config.setMaxAge(3600L);
// 添加映射路径,拦截一切请求
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", config);
// 返回新的CorsFilter
return new CorsFilter(source);
}
}
package com.partner.admin.common.config;
import com.partner.admin.common.exception.APIExceptionEnum;
import com.partner.admin.common.utils.AjaxResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.builders.ResponseBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Response;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.springframework.http.HttpMethod.*;
/**
* Swagger3的接口配置,使用的是knife4j,Swagger3的增强
* @author 姚百政
*/
@Configuration
public class SwaggerConfig
{
/** 是否开启swagger */
@Value("${swagger.enabled}")
private boolean enabled;
/**
* 创建API
*/
@Bean
public Docket createRestApi()
{
/** 更改默认返回码 */
List<Response> responseList = new ArrayList<>();
Arrays.stream(AjaxResult.Type.values()).forEach(resultCode -> {
responseList.add(
new ResponseBuilder().code(String.valueOf( resultCode.value())).description(resultCode.message()).build()
);
});
return new Docket(DocumentationType.OAS_30)
.globalResponses(GET, responseList)
.globalResponses(POST, responseList)
.globalResponses(PUT, responseList)
.globalResponses(DELETE, responseList)
// .globalResponses(HEAD, responseList)
// .globalResponses(PATCH, responseList)
// .globalResponses(OPTIONS, responseList)
// .globalResponses(TRACE, responseList)
// 是否启用Swagger
.enable(enabled)
//分组设置
.groupName("合伙人平台基本接口")
// 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息)
.apiInfo(apiInfo())
// 设置哪些接口暴露给Swagger展示
.select()
// 扫描所有有注解的api,用这种方式更灵活
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
// 扫描指定包中的swagger注解
// .apis(RequestHandlerSelectors.basePackage("com.lyy.admin.controller"))
// 扫描所有
// .apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
/**
* 添加摘要信息
*/
private ApiInfo apiInfo()
{
// 用ApiInfoBuilder进行定制
return new ApiInfoBuilder()
// 设置标题
.title("标题:合伙人招商平台_接口文档")
// 描述
.description("描述:合伙人招商平台后端接口")
// 作者信息
.contact(new Contact("PARTNER", null, null))
// 版本
.version("版本号:0.0.1" )
.build();
}
}
package com.partner.admin.common.constant;
/**
* 通用常量信息
* @author yaobaizheng
*/
public class Constants {
/**
* UTF-8 字符集
*/
public static final String UTF8 = "UTF-8";
/**
* GBK 字符集
*/
public static final String GBK = "GBK";
/**
* http请求
*/
public static final String HTTP = "http://";
/**
* https请求
*/
public static final String HTTPS = "https://";
/**
* 通用成功标识
*/
public static final String SUCCESS = "0";
/**
* 通用失败标识
*/
public static final String FAIL = "1";
/**
* 登录成功
*/
public static final String LOGIN_SUCCESS = "Success";
/**
* 注销
*/
public static final String LOGOUT = "Logout";
/**
* 注册
*/
public static final String REGISTER = "Register";
/**
* 登录失败
*/
public static final String LOGIN_FAIL = "Error";
/**
* 系统用户授权缓存
*/
public static final String SYS_AUTH_CACHE = "sys-authCache";
/**
* 参数管理 cache name
*/
public static final String SYS_CONFIG_CACHE = "sys-config";
/**
* 参数管理 cache key
*/
public static final String SYS_CONFIG_KEY = "sys_config:";
/**
* 字典管理 cache name
*/
public static final String SYS_DICT_CACHE = "sys-dict";
/**
* 字典管理 cache key
*/
public static final String SYS_DICT_KEY = "sys_dict:";
/**
* 资源映射路径 前缀
*/
public static final String RESOURCE_PREFIX = "/profile";
/**
* RMI 远程方法调用
*/
public static final String LOOKUP_RMI = "rmi:";
/**
* LDAP 远程方法调用
*/
public static final String LOOKUP_LDAP = "ldap:";
/**
* LDAPS 远程方法调用
*/
public static final String LOOKUP_LDAPS = "ldaps:";
/**
* 定时任务白名单配置(仅允许访问的包名,如其他需要可以自行添加)
*/
public static final String[] JOB_WHITELIST_STR = { "com.ruoyi" };
/**
* 定时任务违规的字符
*/
public static final String[] JOB_ERROR_STR = { "java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml",
"org.springframework", "org.apache", "com.ruoyi.common.utils.file", "com.ruoyi.common.config" };
}
\ No newline at end of file
package com.partner.admin.common.exception;
import lombok.Data;
@Data
public class APIException extends RuntimeException {
private int code;
private String message;
public int getCode() {
return code;
}
public String getMessage() {
return message;
}
public APIException(int code, String message) {
this.code = code;
this.message = message;
}
public APIException(APIExceptionEnum apiExceptionEnum) {
this.code = apiExceptionEnum.getCode();
this.message = apiExceptionEnum.getMessage();
}
}
package com.partner.admin.common.exception;
import lombok.Getter;
@Getter
public enum APIExceptionEnum {
//用户
USER_NOTEXISTS(4001, "当前用户不存在"),
USER_PASSWORD_ERROR(4002, "当前用户密码输入错误"),
USER_TOKEN_EXPIRE(4003, "当前会话失效,请重新登录"),
NOTEXISTS_EXCEPTION(4500, "数据不存在,请确认!"),
//
WX_GETPHONENUMBER_ERROR(40029, "微信获取手机号code码无效,或着微信异常,请重试!");
private int code;
private String message;
APIExceptionEnum(int code, String message) {
this.code = code;
this.message = message;
}
public int getCode() {
return code;
}
public String getMsg() {
return message;
}
}
package com.partner.admin.common.exception;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.partner.admin.common.utils.AjaxResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.validation.BindException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MissingPathVariableException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
import javax.servlet.http.HttpServletRequest;
/**
* 全局异常处理器
* @author yaobaizheng
*/
@RestControllerAdvice(basePackages = "com.partner.admin.controller")
public class GlobalExceptionHandler implements ResponseBodyAdvice {
private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
@Override
public boolean supports(MethodParameter returnType, Class converterType) {
boolean assignableFrom = returnType.getParameterType().isAssignableFrom(AjaxResult.class);
return !assignableFrom;
}
@Override
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
AjaxResult value = AjaxResult.success(body);
boolean isStringResult = returnType.getParameterType().equals(String.class);
if (isStringResult) {
ObjectMapper objectMapper = new ObjectMapper();
try {
String s = objectMapper.writeValueAsString(value);
return s;
} catch (JsonProcessingException e) {
e.printStackTrace();
try {
throw new Exception(e.getMessage());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
return value;
}
@ExceptionHandler(APIException.class)
public AjaxResult APIExceptionHandler(APIException apiException) {
int code = apiException.getCode();
String message = apiException.getMessage();
AjaxResult fail = AjaxResult.warn( message);
if(code == APIExceptionEnum.USER_TOKEN_EXPIRE.getCode()){
fail = AjaxResult.userTokenExpier(message);
}
return fail;
}
/**
* 请求方式不支持
*/
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public AjaxResult handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e,
HttpServletRequest request)
{
String requestURI = request.getRequestURI();
log.error("请求地址'{}',不支持'{}'请求", requestURI, e.getMethod());
return AjaxResult.error(e.getMessage());
}
/**
* 拦截未知的运行时异常
*/
@ExceptionHandler(RuntimeException.class)
public AjaxResult handleRuntimeException(RuntimeException e, HttpServletRequest request)
{
String requestURI = request.getRequestURI();
log.error("请求地址'{}',发生未知异常.", requestURI, e);
return AjaxResult.error(e.getMessage());
}
/**
* 系统异常
*/
@ExceptionHandler(Exception.class)
public AjaxResult handleException(Exception e, HttpServletRequest request)
{
String requestURI = request.getRequestURI();
log.error("请求地址'{}',发生系统异常.", requestURI, e);
return AjaxResult.error(e.getMessage());
}
/**
* 请求路径中缺少必需的路径变量
*/
@ExceptionHandler(MissingPathVariableException.class)
public AjaxResult handleMissingPathVariableException(MissingPathVariableException e, HttpServletRequest request)
{
String requestURI = request.getRequestURI();
log.error("请求路径中缺少必需的路径变量'{}',发生系统异常.", requestURI, e);
return AjaxResult.error(String.format("请求路径中缺少必需的路径变量[%s]", e.getVariableName()));
}
/**
* 请求参数类型不匹配
*/
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
public AjaxResult handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e,
HttpServletRequest request)
{
String requestURI = request.getRequestURI();
log.error("请求参数类型不匹配'{}',发生系统异常.", requestURI, e);
return AjaxResult.error(String.format("请求参数类型不匹配,参数[%s]要求类型为:'%s',但输入值为:'%s'", e.getName(), e.getRequiredType().getName(), e.getValue()));
}
/**
* 自定义验证异常
*/
@ExceptionHandler(BindException.class)
public AjaxResult handleBindException(BindException e)
{
log.error(e.getMessage(), e);
String message = e.getAllErrors().get(0).getDefaultMessage();
return AjaxResult.error(message);
}
}
package com.partner.admin.common.exception;
/**
* 工具类异常
* @author yaobaizheng
*/
public class UtilException extends RuntimeException
{
private static final long serialVersionUID = 8247610319171014183L;
public UtilException(Throwable e)
{
super(e.getMessage(), e);
}
public UtilException(String message)
{
super(message);
}
public UtilException(String message, Throwable throwable)
{
super(message, throwable);
}
}
package com.partner.admin.common.exception.base;
import com.partner.admin.common.utils.MessageUtils;
import com.partner.admin.common.utils.StringUtils;
/**
* 基础异常
*
* @author ruoyi
*/
public class BaseException extends RuntimeException
{
private static final long serialVersionUID = 1L;
/**
* 所属模块
*/
private String module;
/**
* 错误码
*/
private String code;
/**
* 错误码对应的参数
*/
private Object[] args;
/**
* 错误消息
*/
private String defaultMessage;
public BaseException(String module, String code, Object[] args, String defaultMessage)
{
this.module = module;
this.code = code;
this.args = args;
this.defaultMessage = defaultMessage;
}
public BaseException(String module, String code, Object[] args)
{
this(module, code, args, null);
}
public BaseException(String module, String defaultMessage)
{
this(module, null, null, defaultMessage);
}
public BaseException(String code, Object[] args)
{
this(null, code, args, null);
}
public BaseException(String defaultMessage)
{
this(null, null, null, defaultMessage);
}
@Override
public String getMessage()
{
String message = null;
if (!StringUtils.isEmpty(code))
{
message = MessageUtils.message(code, args);
}
if (message == null)
{
message = defaultMessage;
}
return message;
}
public String getModule()
{
return module;
}
public String getCode()
{
return code;
}
public Object[] getArgs()
{
return args;
}
public String getDefaultMessage()
{
return defaultMessage;
}
}
package com.partner.admin.common.exception.file;
import com.partner.admin.common.exception.base.BaseException;
/**
* 文件信息异常类
*
* @author ruoyi
*/
public class FileException extends BaseException
{
private static final long serialVersionUID = 1L;
public FileException(String code, Object[] args)
{
super("file", code, args, null);
}
}
package com.partner.admin.common.exception.file;
/**
* 文件名称超长限制异常类
*
* @author ruoyi
*/
public class FileNameLengthLimitExceededException extends FileException
{
private static final long serialVersionUID = 1L;
public FileNameLengthLimitExceededException(int defaultFileNameLength)
{
super("upload.filename.exceed.length", new Object[] { defaultFileNameLength });
}
}
package com.partner.admin.common.exception.file;
/**
* 文件名大小限制异常类
*
* @author ruoyi
*/
public class FileSizeLimitExceededException extends FileException
{
private static final long serialVersionUID = 1L;
public FileSizeLimitExceededException(long defaultMaxSize)
{
super("upload.exceed.maxSize", new Object[] { defaultMaxSize });
}
}
package com.partner.admin.common.exception.file;
import java.io.PrintStream;
import java.io.PrintWriter;
/**
* 文件上传异常类
*
* @author ruoyi
*/
public class FileUploadException extends Exception
{
private static final long serialVersionUID = 1L;
private final Throwable cause;
public FileUploadException()
{
this(null, null);
}
public FileUploadException(final String msg)
{
this(msg, null);
}
public FileUploadException(String msg, Throwable cause)
{
super(msg);
this.cause = cause;
}
@Override
public void printStackTrace(PrintStream stream)
{
super.printStackTrace(stream);
if (cause != null)
{
stream.println("Caused by:");
cause.printStackTrace(stream);
}
}
@Override
public void printStackTrace(PrintWriter writer)
{
super.printStackTrace(writer);
if (cause != null)
{
writer.println("Caused by:");
cause.printStackTrace(writer);
}
}
@Override
public Throwable getCause()
{
return cause;
}
}
package com.partner.admin.common.exception.file;
import java.util.Arrays;
/**
* 文件上传 误异常类
*
* @author ruoyi
*/
public class InvalidExtensionException extends FileUploadException
{
private static final long serialVersionUID = 1L;
private String[] allowedExtension;
private String extension;
private String filename;
public InvalidExtensionException(String[] allowedExtension, String extension, String filename)
{
super("文件[" + filename + "]后缀[" + extension + "]不正确,请上传" + Arrays.toString(allowedExtension) + "格式");
this.allowedExtension = allowedExtension;
this.extension = extension;
this.filename = filename;
}
public String[] getAllowedExtension()
{
return allowedExtension;
}
public String getExtension()
{
return extension;
}
public String getFilename()
{
return filename;
}
public static class InvalidImageExtensionException extends InvalidExtensionException
{
private static final long serialVersionUID = 1L;
public InvalidImageExtensionException(String[] allowedExtension, String extension, String filename)
{
super(allowedExtension, extension, filename);
}
}
public static class InvalidFlashExtensionException extends InvalidExtensionException
{
private static final long serialVersionUID = 1L;
public InvalidFlashExtensionException(String[] allowedExtension, String extension, String filename)
{
super(allowedExtension, extension, filename);
}
}
public static class InvalidMediaExtensionException extends InvalidExtensionException
{
private static final long serialVersionUID = 1L;
public InvalidMediaExtensionException(String[] allowedExtension, String extension, String filename)
{
super(allowedExtension, extension, filename);
}
}
public static class InvalidVideoExtensionException extends InvalidExtensionException
{
private static final long serialVersionUID = 1L;
public InvalidVideoExtensionException(String[] allowedExtension, String extension, String filename)
{
super(allowedExtension, extension, filename);
}
}
}
package com.partner.admin.common.interceptor;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.partner.admin.common.exception.APIException;
import com.partner.admin.common.exception.APIExceptionEnum;
import com.partner.admin.domain.Token;
import com.partner.admin.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
@Component
public class LoginInterceptor implements HandlerInterceptor {
@Autowired
TokenService sysUserTokenService;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//判断是不是swagger是就放行
// HandlerMethod handlerMethod=(HandlerMethod)handler;
// if("springfox.documentation.swagger.web.ApiResourceController".equals(handlerMethod.getBean().getClass().getName())){
// return true;
// }
String token = request.getHeader("token");// 从 http 请求头中取出 token
if(token == null || "".equals(token) ){
throw new APIException(APIExceptionEnum.USER_TOKEN_EXPIRE);
}
//判断token是否在有效期内
QueryWrapper<Token> sysUserTokenQW = new QueryWrapper<>();
sysUserTokenQW.eq("token",token);
Token sysUserToken = sysUserTokenService.getOne(sysUserTokenQW);
if(sysUserToken == null){
throw new APIException(APIExceptionEnum.USER_TOKEN_EXPIRE);
}
Date expireTime = sysUserToken.getExpireTime();
DateTime expireTimeNew = DateUtil.dateNew(expireTime);
DateTime currentTime = DateUtil.date();
if(!expireTimeNew.isAfter(currentTime)){
throw new APIException(APIExceptionEnum.USER_TOKEN_EXPIRE);
}
return true;
}
}
package com.partner.admin.common.menu;
public enum PartnerProjectStatusEnum {
// 0-暂存 1-信息提报 2-项目查重通过 3-项目查重拒绝 4-招商公司匹配 5-企业对接
// 6-投资意向确认 7-确认项目信息 8-完成审核
PROJECTSTATUS0(0,"暂存"),
PROJECTSTATUS1(1,"信息提报"),
PROJECTSTATUS2(2,"项目查重通过"),
PROJECTSTATUS3(3,"项目查重拒绝"),
PROJECTSTATUS4(4,"招商公司匹配"),
PROJECTSTATUS5(5,"企业对接"),
PROJECTSTATUS6(6,"投资意向确认"),
PROJECTSTATUS7(7,"确认项目信息"),
PROJECTSTATUS8(8,"完成审核"),
// 9-项目信息 10-项目沟通 11-区域匹配 12-政企互访 13-项目谈判 14-项目签约
// 15-分配中 20-作废
PROJECTSTATUS9(9,"项目信息"),
PROJECTSTATUS10(10,"项目沟通"),
PROJECTSTATUS11(11,"区域匹配"),
PROJECTSTATUS12(12,"政企互访"),
PROJECTSTATUS13(13,"项目谈判"),
PROJECTSTATUS14(14,"项目签约"),
PROJECTSTATUS15(15,"分配中"),
PROJECTSTATUS20(20,"作废");
private int code;
private String message;
PartnerProjectStatusEnum(int code,String message)
{
this.code = code;
this.message = message;
}
public int code()
{
return this.code;
}
public String message()
{
return this.message;
}
}
package com.partner.admin.common.page;
import com.partner.admin.common.utils.StringUtils;
/**
* 分页数据
* @author yaobaizheng
*/
public class PageDomain {
/** 当前记录起始索引 */
private Integer pageNum;
/** 每页显示记录数 */
private Integer pageSize;
/** 排序列 */
private String orderByColumn;
/** 排序的方向desc或者asc */
private String isAsc = "asc";
/** 分页参数合理化 */
private Boolean reasonable = true;
public String getOrderBy()
{
if (StringUtils.isEmpty(orderByColumn))
{
return "";
}
return StringUtils.toUnderScoreCase(orderByColumn) + " " + isAsc;
}
public Integer getPageNum()
{
return pageNum;
}
public void setPageNum(Integer pageNum)
{
this.pageNum = pageNum;
}
public Integer getPageSize()
{
return pageSize;
}
public void setPageSize(Integer pageSize)
{
this.pageSize = pageSize;
}
public String getOrderByColumn()
{
return orderByColumn;
}
public void setOrderByColumn(String orderByColumn)
{
this.orderByColumn = orderByColumn;
}
public String getIsAsc()
{
return isAsc;
}
public void setIsAsc(String isAsc)
{
this.isAsc = isAsc;
}
public Boolean getReasonable()
{
if (StringUtils.isNull(reasonable))
{
return Boolean.TRUE;
}
return reasonable;
}
public void setReasonable(Boolean reasonable)
{
this.reasonable = reasonable;
}
}
package com.partner.admin.common.page;
import java.io.Serializable;
import java.util.List;
/**
* 表格分页数据对象
* @author yaobaizheng
*/
public class TableDataInfo implements Serializable
{
private static final long serialVersionUID = 1L;
/** 总记录数 */
private long total;
/** 列表数据 */
private List<?> rows;
/**
* 表格数据对象
*/
public TableDataInfo()
{
}
/**
* 分页
*
* @param list 列表数据
* @param total 总记录数
*/
public TableDataInfo(List<?> list, int total)
{
this.rows = list;
this.total = total;
}
public long getTotal()
{
return total;
}
public void setTotal(long total)
{
this.total = total;
}
public List<?> getRows()
{
return rows;
}
public void setRows(List<?> rows)
{
this.rows = rows;
}
}
\ No newline at end of file
package com.partner.admin.common.page;
import com.partner.admin.common.text.Convert;
import com.partner.admin.common.utils.ServletUtils;
/**
* 表格数据处理
* @author yaobaizheng
*/
public class TableSupport
{
/**
* 当前记录起始索引
*/
public static final String PAGE_NUM = "pageNum";
/**
* 每页显示记录数
*/
public static final String PAGE_SIZE = "pageSize";
/**
* 排序列
*/
public static final String ORDER_BY_COLUMN = "orderByColumn";
/**
* 排序的方向 "desc" 或者 "asc".
*/
public static final String IS_ASC = "isAsc";
/**
* 分页参数合理化
*/
public static final String REASONABLE = "reasonable";
/**
* 封装分页对象
*/
public static PageDomain getPageDomain()
{
PageDomain pageDomain = new PageDomain();
pageDomain.setPageNum(Convert.toInt(ServletUtils.getParameter(PAGE_NUM), 1));
pageDomain.setPageSize(Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 10));
pageDomain.setOrderByColumn(ServletUtils.getParameter(ORDER_BY_COLUMN));
pageDomain.setIsAsc(ServletUtils.getParameter(IS_ASC));
pageDomain.setReasonable(ServletUtils.getParameterToBool(REASONABLE));
return pageDomain;
}
public static PageDomain buildPageRequest()
{
return getPageDomain();
}
}
package com.partner.admin.common.text;
import com.partner.admin.common.utils.StringUtils;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
/**
* 字符集工具类
* @author yaobaizheng
*/
public class CharsetKit
{
/** ISO-8859-1 */
public static final String ISO_8859_1 = "ISO-8859-1";
/** UTF-8 */
public static final String UTF_8 = "UTF-8";
/** GBK */
public static final String GBK = "GBK";
/** ISO-8859-1 */
public static final Charset CHARSET_ISO_8859_1 = Charset.forName(ISO_8859_1);
/** UTF-8 */
public static final Charset CHARSET_UTF_8 = Charset.forName(UTF_8);
/** GBK */
public static final Charset CHARSET_GBK = Charset.forName(GBK);
/**
* 转换为Charset对象
*
* @param charset 字符集,为空则返回默认字符集
* @return Charset
*/
public static Charset charset(String charset)
{
return StringUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset);
}
/**
* 转换字符串的字符集编码
*
* @param source 字符串
* @param srcCharset 源字符集,默认ISO-8859-1
* @param destCharset 目标字符集,默认UTF-8
* @return 转换后的字符集
*/
public static String convert(String source, String srcCharset, String destCharset)
{
return convert(source, Charset.forName(srcCharset), Charset.forName(destCharset));
}
/**
* 转换字符串的字符集编码
*
* @param source 字符串
* @param srcCharset 源字符集,默认ISO-8859-1
* @param destCharset 目标字符集,默认UTF-8
* @return 转换后的字符集
*/
public static String convert(String source, Charset srcCharset, Charset destCharset)
{
if (null == srcCharset)
{
srcCharset = StandardCharsets.ISO_8859_1;
}
if (null == destCharset)
{
destCharset = StandardCharsets.UTF_8;
}
if (StringUtils.isEmpty(source) || srcCharset.equals(destCharset))
{
return source;
}
return new String(source.getBytes(srcCharset), destCharset);
}
/**
* @return 系统字符集编码
*/
public static String systemCharset()
{
return Charset.defaultCharset().name();
}
}
This diff is collapsed.
package com.partner.admin.common.text;
import com.partner.admin.common.utils.StringUtils;
/**
* 字符串格式化
* @author yaobaizehng
*/
public class StrFormatter {
public static final String EMPTY_JSON = "{}";
public static final char C_BACKSLASH = '\\';
public static final char C_DELIM_START = '{';
public static final char C_DELIM_END = '}';
/**
* 格式化字符串<br>
* 此方法只是简单将占位符 {} 按照顺序替换为参数<br>
* 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可<br>
* 例:<br>
* 通常使用:format("this is {} for {}", "a", "b") -> this is a for b<br>
* 转义{}: format("this is \\{} for {}", "a", "b") -> this is \{} for a<br>
* 转义\: format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br>
*
* @param strPattern 字符串模板
* @param argArray 参数列表
* @return 结果
*/
public static String format(final String strPattern, final Object... argArray)
{
if (StringUtils.isEmpty(strPattern) || StringUtils.isEmpty(argArray))
{
return strPattern;
}
final int strPatternLength = strPattern.length();
// 初始化定义好的长度以获得更好的性能
StringBuilder sbuf = new StringBuilder(strPatternLength + 50);
int handledPosition = 0;
int delimIndex;// 占位符所在位置
for (int argIndex = 0; argIndex < argArray.length; argIndex++)
{
delimIndex = strPattern.indexOf(EMPTY_JSON, handledPosition);
if (delimIndex == -1)
{
if (handledPosition == 0)
{
return strPattern;
}
else
{ // 字符串模板剩余部分不再包含占位符,加入剩余部分后返回结果
sbuf.append(strPattern, handledPosition, strPatternLength);
return sbuf.toString();
}
}
else
{
if (delimIndex > 0 && strPattern.charAt(delimIndex - 1) == C_BACKSLASH)
{
if (delimIndex > 1 && strPattern.charAt(delimIndex - 2) == C_BACKSLASH)
{
// 转义符之前还有一个转义符,占位符依旧有效
sbuf.append(strPattern, handledPosition, delimIndex - 1);
sbuf.append(Convert.utf8Str(argArray[argIndex]));
handledPosition = delimIndex + 2;
}
else
{
// 占位符被转义
argIndex--;
sbuf.append(strPattern, handledPosition, delimIndex - 1);
sbuf.append(C_DELIM_START);
handledPosition = delimIndex + 1;
}
}
else
{
// 正常占位符
sbuf.append(strPattern, handledPosition, delimIndex);
sbuf.append(Convert.utf8Str(argArray[argIndex]));
handledPosition = delimIndex + 2;
}
}
}
// 加入最后一个占位符后所有的字符
sbuf.append(strPattern, handledPosition, strPattern.length());
return sbuf.toString();
}
}
package com.partner.admin.common.utils;
import java.util.HashMap;
import java.util.Objects;
/**
* 操作消息提醒
* @author yaobaizheng
*/
public class AjaxResult extends HashMap<String, Object>
{
private static final long serialVersionUID = 1L;
/** 状态码 */
public static final String CODE_TAG = "code";
/** 返回内容 */
public static final String MSG_TAG = "msg";
/** 数据对象 */
public static final String DATA_TAG = "data";
/**
* 状态类型
*/
public enum Type
{
/** 成功 */
SUCCESS(200,"成功"),
/** 警告 */
WARN(300,"警告"),
USER_TOKEN_EXPIRE(4003, "当前会话失效,请重新登录"),
/** 错误 */
ERROR(500,"错误");
private final int value;
private String message;
Type(int value,String message)
{
this.value = value;
this.message = message;
}
public int value()
{
return this.value;
}
public String message()
{
return this.message;
}
}
/**
* 初始化一个新创建的 AjaxResult 对象,使其表示一个空消息。
*/
public AjaxResult()
{
}
/**
* 初始化一个新创建的 AjaxResult 对象
*
* @param type 状态类型
* @param msg 返回内容
*/
public AjaxResult(Type type, String msg)
{
super.put(CODE_TAG, type.value);
super.put(MSG_TAG, msg);
}
/**
* 初始化一个新创建的 AjaxResult 对象
*
* @param type 状态类型
* @param msg 返回内容
* @param data 数据对象
*/
public AjaxResult(Type type, String msg, Object data)
{
super.put(CODE_TAG, type.value);
super.put(MSG_TAG, msg);
if (StringUtils.isNotNull(data))
{
super.put(DATA_TAG, data);
}
}
/**
* 返回成功消息
*
* @return 成功消息
*/
public static AjaxResult success()
{
return AjaxResult.success("操作成功");
}
/**
* 返回成功数据
*
* @return 成功消息
*/
public static AjaxResult success(Object data)
{
return AjaxResult.success("操作成功", data);
}
/**
* 返回成功消息
*
* @param msg 返回内容
* @return 成功消息
*/
public static AjaxResult success(String msg)
{
return AjaxResult.success(msg, null);
}
/**
* 返回成功消息
*
* @param msg 返回内容
* @param data 数据对象
* @return 成功消息
*/
public static AjaxResult success(String msg, Object data)
{
return new AjaxResult(Type.SUCCESS, msg, data);
}
/**
* 返回警告消息
*
* @param msg 返回内容
* @return 警告消息
*/
public static AjaxResult warn(String msg)
{
return AjaxResult.warn(msg, null);
}
/**
* 返回警告消息
*
* @param msg 返回内容
* @param data 数据对象
* @return 警告消息
*/
public static AjaxResult warn(String msg, Object data)
{
return new AjaxResult(Type.WARN, msg, data);
}
/**
* 返回错误消息
*
* @return
*/
public static AjaxResult error()
{
return AjaxResult.error("操作失败");
}
/**
* 返回错误消息
*
* @param msg 返回内容
* @return 警告消息
*/
public static AjaxResult error(String msg)
{
return AjaxResult.error(msg, null);
}
/**
* 返回错误消息
*
* @param msg 返回内容
* @param data 数据对象
* @return 警告消息
*/
public static AjaxResult error(String msg, Object data)
{
return new AjaxResult(Type.ERROR, msg, data);
}
public static AjaxResult userTokenExpier(String msg)
{
return new AjaxResult(Type.USER_TOKEN_EXPIRE, msg);
}
/**
* 是否为成功消息
*
* @return 结果
*/
public boolean isSuccess()
{
return Objects.equals(Type.SUCCESS.value, this.get(CODE_TAG));
}
/**
* 是否为警告消息
*
* @return 结果
*/
public boolean isWarn()
{
return Objects.equals(Type.WARN.value, this.get(CODE_TAG));
}
/**
* 是否为错误消息
*
* @return 结果
*/
public boolean isError()
{
return Objects.equals(Type.ERROR.value, this.get(CODE_TAG));
}
/**
* 方便链式调用
*
* @param key 键
* @param value 值
* @return 数据对象
*/
@Override
public AjaxResult put(String key, Object value)
{
super.put(key, value);
return this;
}
}
package com.partner.admin.common.utils;
import org.apache.commons.lang3.time.DateFormatUtils;
import java.lang.management.ManagementFactory;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.util.Date;
/**
* 时间工具类
*
* @author ruoyi
*/
public class DateUtils extends org.apache.commons.lang3.time.DateUtils
{
public static String YYYY = "yyyy";
public static String YYYY_MM = "yyyy-MM";
public static String YYYY_MM_DD = "yyyy-MM-dd";
public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
private static String[] parsePatterns = {
"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
"yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};
/**
* 获取当前Date型日期
*
* @return Date() 当前日期
*/
public static Date getNowDate()
{
return new Date();
}
/**
* 获取当前日期, 默认格式为yyyy-MM-dd
*
* @return String
*/
public static String getDate()
{
return dateTimeNow(YYYY_MM_DD);
}
public static final String getTime()
{
return dateTimeNow(YYYY_MM_DD_HH_MM_SS);
}
public static final String dateTimeNow()
{
return dateTimeNow(YYYYMMDDHHMMSS);
}
public static final String dateTimeNow(final String format)
{
return parseDateToStr(format, new Date());
}
public static final String dateTime(final Date date)
{
return parseDateToStr(YYYY_MM_DD, date);
}
public static final String parseDateToStr(final String format, final Date date)
{
return new SimpleDateFormat(format).format(date);
}
public static final Date dateTime(final String format, final String ts)
{
try
{
return new SimpleDateFormat(format).parse(ts);
}
catch (ParseException e)
{
throw new RuntimeException(e);
}
}
/**
* 日期路径 即年/月/日 如2018/08/08
*/
public static final String datePath()
{
Date now = new Date();
return DateFormatUtils.format(now, "yyyy/MM/dd");
}
/**
* 日期路径 即年/月/日 如20180808
*/
public static final String dateTime()
{
Date now = new Date();
return DateFormatUtils.format(now, "yyyyMMdd");
}
/**
* 日期型字符串转化为日期 格式
*/
public static Date parseDate(Object str)
{
if (str == null)
{
return null;
}
try
{
return parseDate(str.toString(), parsePatterns);
}
catch (ParseException e)
{
return null;
}
}
/**
* 获取服务器启动时间
*/
public static Date getServerStartDate()
{
long time = ManagementFactory.getRuntimeMXBean().getStartTime();
return new Date(time);
}
/**
* 计算相差天数
*/
public static int differentDaysByMillisecond(Date date1, Date date2)
{
return Math.abs((int) ((date2.getTime() - date1.getTime()) / (1000 * 3600 * 24)));
}
/**
* 计算时间差
*
* @param endDate 最后时间
* @param startTime 开始时间
* @return 时间差(天/小时/分钟)
*/
public static String timeDistance(Date endDate, Date startTime)
{
long nd = 1000 * 24 * 60 * 60;
long nh = 1000 * 60 * 60;
long nm = 1000 * 60;
// long ns = 1000;
// 获得两个时间的毫秒时间差异
long diff = endDate.getTime() - startTime.getTime();
// 计算差多少天
long day = diff / nd;
// 计算差多少小时
long hour = diff % nd / nh;
// 计算差多少分钟
long min = diff % nd % nh / nm;
// 计算差多少秒//输出结果
// long sec = diff % nd % nh % nm / ns;
return day + "天" + hour + "小时" + min + "分钟";
}
/**
* 增加 LocalDateTime ==> Date
*/
public static Date toDate(LocalDateTime temporalAccessor)
{
ZonedDateTime zdt = temporalAccessor.atZone(ZoneId.systemDefault());
return Date.from(zdt.toInstant());
}
/**
* 增加 LocalDate ==> Date
*/
public static Date toDate(LocalDate temporalAccessor)
{
LocalDateTime localDateTime = LocalDateTime.of(temporalAccessor, LocalTime.of(0, 0, 0));
ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault());
return Date.from(zdt.toInstant());
}
}
package com.partner.admin.common.utils;
import com.partner.admin.common.utils.spring.SpringUtils;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
/**
* 获取i18n资源文件
*
* @author ruoyi
*/
public class MessageUtils
{
/**
* 根据消息键和参数 获取消息 委托给spring messageSource
*
* @param code 消息键
* @param args 参数
* @return 获取国际化翻译值
*/
public static String message(String code, Object... args)
{
MessageSource messageSource = SpringUtils.getBean(MessageSource.class);
return messageSource.getMessage(code, args, LocaleContextHolder.getLocale());
}
}
package com.partner.admin.common.utils;
import com.github.pagehelper.PageHelper;
import com.partner.admin.common.page.PageDomain;
import com.partner.admin.common.page.TableSupport;
/**
* 分页工具类
* @author yaobaizheng
*/
public class PageUtils extends PageHelper {
/**
* 设置请求分页数据
*/
public static void startPage(){
PageDomain pageDomain = TableSupport.buildPageRequest();
Integer pageNum = pageDomain.getPageNum();
Integer pageSize = pageDomain.getPageSize();
String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
Boolean reasonable = pageDomain.getReasonable();
PageHelper.startPage(pageNum, pageSize, orderBy).setReasonable(reasonable);
}
}
package com.partner.admin.common.utils;
import com.partner.admin.common.constant.Constants;
import com.partner.admin.common.text.Convert;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
/**
* 客户端工具类
* @author yaobaizheng
*/
public class ServletUtils
{
/**
* 定义移动端请求的所有可能类型
*/
private final static String[] agent = { "Android", "iPhone", "iPod", "iPad", "Windows Phone", "MQQBrowser" };
/**
* 获取String参数
*/
public static String getParameter(String name)
{
return getRequest().getParameter(name);
}
/**
* 获取String参数
*/
public static String getParameter(String name, String defaultValue)
{
return Convert.toStr(getRequest().getParameter(name), defaultValue);
}
/**
* 获取Integer参数
*/
public static Integer getParameterToInt(String name)
{
return Convert.toInt(getRequest().getParameter(name));
}
/**
* 获取Integer参数
*/
public static Integer getParameterToInt(String name, Integer defaultValue)
{
return Convert.toInt(getRequest().getParameter(name), defaultValue);
}
/**
* 获取Boolean参数
*/
public static Boolean getParameterToBool(String name)
{
return Convert.toBool(getRequest().getParameter(name));
}
/**
* 获取Boolean参数
*/
public static Boolean getParameterToBool(String name, Boolean defaultValue)
{
return Convert.toBool(getRequest().getParameter(name), defaultValue);
}
/**
* 获取request
*/
public static HttpServletRequest getRequest()
{
return getRequestAttributes().getRequest();
}
/**
* 获取response
*/
public static HttpServletResponse getResponse()
{
return getRequestAttributes().getResponse();
}
/**
* 获取session
*/
public static HttpSession getSession()
{
return getRequest().getSession();
}
public static ServletRequestAttributes getRequestAttributes()
{
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
return (ServletRequestAttributes) attributes;
}
/**
* 将字符串渲染到客户端
*
* @param response 渲染对象
* @param string 待渲染的字符串
* @return null
*/
public static String renderString(HttpServletResponse response, String string)
{
try
{
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
response.getWriter().print(string);
}
catch (IOException e)
{
e.printStackTrace();
}
return null;
}
/**
* 是否是Ajax异步请求
*
* @param request
*/
public static boolean isAjaxRequest(HttpServletRequest request)
{
String accept = request.getHeader("accept");
if (accept != null && accept.contains("application/json"))
{
return true;
}
String xRequestedWith = request.getHeader("X-Requested-With");
if (xRequestedWith != null && xRequestedWith.contains("XMLHttpRequest"))
{
return true;
}
String uri = request.getRequestURI();
if (StringUtils.inStringIgnoreCase(uri, ".json", ".xml"))
{
return true;
}
String ajax = request.getParameter("__ajax");
return StringUtils.inStringIgnoreCase(ajax, "json", "xml");
}
/**
* 判断User-Agent 是不是来自于手机
*/
public static boolean checkAgentIsMobile(String ua)
{
boolean flag = false;
if (!ua.contains("Windows NT") || (ua.contains("Windows NT") && ua.contains("compatible; MSIE 9.0;")))
{
// 排除 苹果桌面系统
if (!ua.contains("Windows NT") && !ua.contains("Macintosh"))
{
for (String item : agent)
{
if (ua.contains(item))
{
flag = true;
break;
}
}
}
}
return flag;
}
/**
* 内容编码
*
* @param str 内容
* @return 编码后的内容
*/
public static String urlEncode(String str)
{
try
{
return URLEncoder.encode(str, Constants.UTF8);
}
catch (UnsupportedEncodingException e)
{
return StringUtils.EMPTY;
}
}
/**
* 内容解码
*
* @param str 内容
* @return 解码后的内容
*/
public static String urlDecode(String str)
{
try
{
return URLDecoder.decode(str, Constants.UTF8);
}
catch (UnsupportedEncodingException e)
{
return StringUtils.EMPTY;
}
}
}
package com.partner.admin.common.utils;
import com.partner.admin.common.exception.UtilException;
/**
* sql操作工具类
* @author yaobaizheng
*/
public class SqlUtil
{
/**
* 定义常用的 sql关键字
*/
public static String SQL_REGEX = "and |extractvalue|updatexml|exec |insert |select |delete |update |drop |count |chr |mid |master |truncate |char |declare |or |+|user()";
/**
* 仅支持字母、数字、下划线、空格、逗号、小数点(支持多个字段排序)
*/
public static String SQL_PATTERN = "[a-zA-Z0-9_\\ \\,\\.]+";
/**
* 限制orderBy最大长度
*/
private static final int ORDER_BY_MAX_LENGTH = 500;
/**
* 检查字符,防止注入绕过
*/
public static String escapeOrderBySql(String value)
{
if (StringUtils.isNotEmpty(value) && !isValidOrderBySql(value))
{
throw new UtilException("参数不符合规范,不能进行查询");
}
if (StringUtils.length(value) > ORDER_BY_MAX_LENGTH)
{
throw new UtilException("参数已超过最大限制,不能进行查询");
}
return value;
}
/**
* 验证 order by 语法是否符合规范
*/
public static boolean isValidOrderBySql(String value)
{
return value.matches(SQL_PATTERN);
}
/**
* SQL关键字检查
*/
public static void filterKeyword(String value)
{
if (StringUtils.isEmpty(value))
{
return;
}
String[] sqlKeywords = StringUtils.split(SQL_REGEX, "\\|");
for (String sqlKeyword : sqlKeywords)
{
if (StringUtils.indexOfIgnoreCase(value, sqlKeyword) > -1)
{
throw new UtilException("参数存在SQL注入风险");
}
}
}
}
This diff is collapsed.
package com.partner.admin.common.utils;
import cn.hutool.http.*;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import javax.net.ssl.HttpsURLConnection;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ConnectException;
import java.net.URL;
import java.util.HashMap;
public class WeixinUtil {
public final static String appId = "wx4f764e291fbbbc1f";//"wx35350b50c51466bf";
public final static String appSecret = "5b89040e2105bf601133962be0532439";//"50f32ffb4d4a98350ceddae254d1e236";
/**
* 获取微信Access Token
* @return
*/
// public static String getAccessToken() {
// String accessToken = "";
//// String ACCESS_TOKEN_URL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid="+appId+"&secret="+appSecret+"&code="+code+"&grant_type=authorization_code";
// String ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appId + "&secret=" + appSecret;
// JSONObject jsonObject = httpRequest(ACCESS_TOKEN_URL, "GET", null);
// // 如果请求成功
// if (jsonObject != null) {
// accessToken = (String) jsonObject.get("access_token");
// }
// return String.valueOf(accessToken);
// }
/**
* 请求微信接口服务,获取小程序全局唯一后台接口调用凭据(access_token)
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/access-token/auth.getAccessToken.html
*
* @param appid
* @param secretKey
* @return
*/
public static String getAccessToken(String appid, String secretKey) {
String result = null;
String accessToken = null ;
try {
String baseUrl = "https://api.weixin.qq.com/cgi-bin/token";
HashMap<String, Object> requestParam = new HashMap<>();
// 小程序 appId
requestParam.put("grant_type", "client_credential");
// 小程序唯一凭证id appid:(换成自己的)
requestParam.put("appid", appid);
// 小程序 appSecret(小程序的唯一凭证密钥,换成自己的)
requestParam.put("secret", secretKey);
// 发送GET请求读取调用微信接口获取openid用户唯一标识
result = HttpUtil.get(baseUrl, requestParam);
accessToken = JSONUtil.parseObj(result).getStr("access_token");
} catch (Exception e) {
e.printStackTrace();
}
return accessToken;
}
/**
* 请求微信接口服务,用code换取用户手机号(每个code只能使用一次,code的有效期为5min)
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/phonenumber/phonenumber.getPhoneNumber.html
*
* @param code
* @param accessToken
* @return
*/
public static JSONObject getPhoneNumber(String code, String accessToken) {
String result = null;
try {
// 接口调用凭证:accessToken
String baseUrl = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + accessToken;
HashMap<String, Object> requestParam = new HashMap<>();
// 手机号调用凭证
requestParam.put("code", code);
// 发送post请求读取调用微信接口获取openid用户唯一标识
String jsonStr = JSONUtil.toJsonStr(requestParam);
HttpResponse response = HttpRequest.post(baseUrl)
.header(Header.CONTENT_ENCODING, "UTF-8")
// 发送json数据需要设置contentType
.header(Header.CONTENT_TYPE, "application/x-www-form-urlencoded")
.body(jsonStr)
.execute();
if (response.getStatus() == HttpStatus.HTTP_OK) {
result = response.body();
}
} catch (Exception e) {
e.printStackTrace();
}
return JSONUtil.parseObj(result);
}
/**
* 请求微信接口服务,获取用户信息
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/phonenumber/phonenumber.getPhoneNumber.html
*
* @param accessToken
* @param openid
* @param signature
* @param sig_method
* @return
*/
public static JSONObject getUserInfo(String accessToken,String openid,String signature,String sig_method) {
String result = null;
try {
// 接口调用凭证:accessToken
String baseUrl = "https://api.weixin.qq.com/wxa/business/getuserencryptkey?access_token=" + accessToken;
HashMap<String, Object> requestParam = new HashMap<>();
// 手机号调用凭证
requestParam.put("openid", openid);
requestParam.put("signature", signature);
requestParam.put("sig_method", sig_method);
// 发送post请求读取调用微信接口获取openid用户唯一标识
String jsonStr = JSONUtil.toJsonStr(requestParam);
HttpResponse response = HttpRequest.post(baseUrl)
.header(Header.CONTENT_ENCODING, "UTF-8")
// 发送json数据需要设置contentType
.header(Header.CONTENT_TYPE, "application/x-www-form-urlencoded")
.body(jsonStr)
.execute();
if (response.getStatus() == HttpStatus.HTTP_OK) {
result = response.body();
}
} catch (Exception e) {
e.printStackTrace();
}
return JSONUtil.parseObj(result);
}
/**
* 请求微信接口服务,获取用户信息
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/phonenumber/phonenumber.getPhoneNumber.html
*
* @param accessToken
* @param code
* @return
*/
public static JSONObject getLogin(String accessToken,String code) {
String result = null;
try {
// 接口调用凭证:accessToken
String baseUrl = "https://api.weixin.qq.com/wxa/getpluginopenpid?access_token=" + accessToken;
HashMap<String, Object> requestParam = new HashMap<>();
// 手机号调用凭证
requestParam.put("code", code);
// 发送post请求读取调用微信接口获取openid用户唯一标识
String jsonStr = JSONUtil.toJsonStr(requestParam);
HttpResponse response = HttpRequest.post(baseUrl)
.header(Header.CONTENT_ENCODING, "UTF-8")
// 发送json数据需要设置contentType
.header(Header.CONTENT_TYPE, "application/x-www-form-urlencoded")
.body(jsonStr)
.execute();
if (response.getStatus() == HttpStatus.HTTP_OK) {
result = response.body();
}
} catch (Exception e) {
e.printStackTrace();
}
return JSONUtil.parseObj(result);
}
public static JSONObject httpRequest(String requestUrl, String requestMethod, String outputStr) {
JSONObject jsonObject = null;
StringBuffer buffer = new StringBuffer();
try {
URL url = new URL(requestUrl);
HttpsURLConnection httpUrlConn = (HttpsURLConnection) url.openConnection();
httpUrlConn.setDoOutput(true);
httpUrlConn.setDoInput(true);
httpUrlConn.setUseCaches(false);
// 设置请求方式(GET/POST)
httpUrlConn.setRequestMethod(requestMethod);
if ("GET".equalsIgnoreCase(requestMethod)) {
httpUrlConn.connect();
}
// 当有数据需要提交时
if (null != outputStr) {
OutputStream outputStream = httpUrlConn.getOutputStream();
// 注意编码格式,防止中文乱码
outputStream.write(outputStr.getBytes("UTF-8"));
outputStream.close();
}
InputStream inputStream = httpUrlConn.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");
BufferedReader streamReader = new BufferedReader(inputStreamReader);
StringBuilder responseStrBuilder = new StringBuilder();
String inputStr;
while ((inputStr = streamReader.readLine()) != null) responseStrBuilder.append(inputStr);
jsonObject = new JSONObject(responseStrBuilder.toString());
inputStreamReader.close();
// 释放资源
inputStream.close();
inputStream = null;
httpUrlConn.disconnect();
} catch (ConnectException ce) {
//log.error("Weixin server connection timed out.");
} catch (Exception e) {
//log.error("https request error:{}", e);
}
return jsonObject;
}
}
package com.partner.admin.common.utils.hwobs;
import org.apache.tomcat.util.codec.binary.Base64;
public final class Base64Utils {
public Base64Utils() {
}
public static byte[] decode(String base64) throws Exception {
return Base64.decodeBase64(base64);
}
public static String encode(byte[] bytes) throws Exception {
return new String(Base64.encodeBase64(bytes));
}
}
package com.partner.admin.common.utils.hwobs;
import com.obs.services.ObsClient;
import com.obs.services.model.ObsObject;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
@Component
public class ObsUtils {
@Value("${huaweiObs.endPoint}")
private String endPoint;
@Value("${huaweiObs.ak}")
private String ak;
@Value("${huaweiObs.sk}")
private String sk;
@Value("${huaweiObs.bucketName}")
private String bucketName;
//文件上传
public void ObsUpload(String bucketName, String key, InputStream inputStream) throws IOException {
// 创建ObsClient实例
ObsClient obsClient = new ObsClient(ak, sk, endPoint);
obsClient.putObject(bucketName, key, inputStream);
obsClient.close();
}
//文件下载
public void downloadFile(HttpServletResponse response, String fileName) {
ObsClient obsClient = new ObsClient(ak, sk, endPoint);
ObsObject obsObject = obsClient.getObject(bucketName, fileName);
InputStream content = obsObject.getObjectContent();
response.setHeader("content-type", "application/octet-stream");
response.setContentType("application/octet-stream");
try {
response.setHeader("Content-Disposition", "attachment;filename=" + java.net.URLEncoder.encode(fileName, "UTF-8"));
} catch (Exception e) {
e.printStackTrace();
}
byte[] items = new byte[1024 * 10];
int i = 0;
try {
BufferedInputStream bufferedInputStream = new BufferedInputStream(content);
OutputStream outputStream = response.getOutputStream();
BufferedOutputStream outputStream1 = new BufferedOutputStream(outputStream);
while ((i = bufferedInputStream.read(items)) != -1) {
outputStream1.write(items, 0, i);
outputStream1.flush();
}
outputStream1.close();
outputStream.close();
bufferedInputStream.close();
content.close();
} catch (Exception e1) {
e1.printStackTrace();
}
}
/**
* @Description: 删除对象
*/
public void deleteFile(String bucketName, String fileName) {
ObsClient obsClient = new ObsClient(ak, sk, endPoint);
obsClient.deleteObject(bucketName, fileName);
}
/**
* @Description: 文件转base64
*/
public String fileToBase64(String fileName){
ObsClient obsClient = new ObsClient(ak, sk, endPoint);
ObsObject obsObject = obsClient.getObject(bucketName, fileName);
InputStream content = obsObject.getObjectContent();
try {
byte[] bytes = IOUtils.toByteArray(content);
content.close();
return Base64Utils.encode(bytes);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
package com.partner.admin.common.utils.spring;
import com.partner.admin.common.utils.StringUtils;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
/**
* spring工具类 方便在非spring管理环境中获取bean
*
* @author ruoyi
*/
@Component
public final class SpringUtils implements BeanFactoryPostProcessor, ApplicationContextAware
{
/** Spring应用上下文环境 */
private static ConfigurableListableBeanFactory beanFactory;
private static ApplicationContext applicationContext;
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException
{
SpringUtils.beanFactory = beanFactory;
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
{
SpringUtils.applicationContext = applicationContext;
}
/**
* 获取对象
*
* @param name
* @return Object 一个以所给名字注册的bean的实例
* @throws BeansException
*
*/
@SuppressWarnings("unchecked")
public static <T> T getBean(String name) throws BeansException
{
return (T) beanFactory.getBean(name);
}
/**
* 获取类型为requiredType的对象
*
* @param clz
* @return
* @throws BeansException
*
*/
public static <T> T getBean(Class<T> clz) throws BeansException
{
T result = (T) beanFactory.getBean(clz);
return result;
}
/**
* 如果BeanFactory包含一个与所给名称匹配的bean定义,则返回true
*
* @param name
* @return boolean
*/
public static boolean containsBean(String name)
{
return beanFactory.containsBean(name);
}
/**
* 判断以给定名字注册的bean定义是一个singleton还是一个prototype。 如果与给定名字相应的bean定义没有被找到,将会抛出一个异常(NoSuchBeanDefinitionException)
*
* @param name
* @return boolean
* @throws NoSuchBeanDefinitionException
*
*/
public static boolean isSingleton(String name) throws NoSuchBeanDefinitionException
{
return beanFactory.isSingleton(name);
}
/**
* @param name
* @return Class 注册对象的类型
* @throws NoSuchBeanDefinitionException
*
*/
public static Class<?> getType(String name) throws NoSuchBeanDefinitionException
{
return beanFactory.getType(name);
}
/**
* 如果给定的bean名字在bean定义中有别名,则返回这些别名
*
* @param name
* @return
* @throws NoSuchBeanDefinitionException
*
*/
public static String[] getAliases(String name) throws NoSuchBeanDefinitionException
{
return beanFactory.getAliases(name);
}
/**
* 获取aop代理对象
*
* @param invoker
* @return
*/
@SuppressWarnings("unchecked")
public static <T> T getAopProxy(T invoker)
{
return (T) AopContext.currentProxy();
}
/**
* 获取当前的环境配置,无配置返回null
*
* @return 当前的环境配置
*/
public static String[] getActiveProfiles()
{
return applicationContext.getEnvironment().getActiveProfiles();
}
/**
* 获取当前的环境配置,当有多个环境配置时,只获取第一个
*
* @return 当前的环境配置
*/
public static String getActiveProfile()
{
final String[] activeProfiles = getActiveProfiles();
return StringUtils.isNotEmpty(activeProfiles) ? activeProfiles[0] : null;
}
/**
* 获取配置文件中的值
*
* @param key 配置文件的key
* @return 当前的配置文件的值
*
*/
public static String getRequiredProperty(String key)
{
return applicationContext.getEnvironment().getRequiredProperty(key);
}
}
package com.partner.admin.common.utils.uuid;
/**
* ID生成器工具类
*
* @author ruoyi
*/
public class IdUtils
{
/**
* 获取随机UUID
*
* @return 随机UUID
*/
public static String randomUUID()
{
return UUID.randomUUID().toString();
}
/**
* 简化的UUID,去掉了横线
*
* @return 简化的UUID,去掉了横线
*/
public static String simpleUUID()
{
return UUID.randomUUID().toString(true);
}
/**
* 获取随机UUID,使用性能更好的ThreadLocalRandom生成UUID
*
* @return 随机UUID
*/
public static String fastUUID()
{
return UUID.fastUUID().toString();
}
/**
* 简化的UUID,去掉了横线,使用性能更好的ThreadLocalRandom生成UUID
*
* @return 简化的UUID,去掉了横线
*/
public static String fastSimpleUUID()
{
return UUID.fastUUID().toString(true);
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
package com.partner.admin.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.partner.admin.VO.HomePageLoginInfoVO;
import com.partner.admin.VO.HomePageLogoutInfoVO;
import com.partner.admin.domain.PartnerImageSource;
import com.partner.admin.domain.PartnerProjectInfo;
import com.partner.admin.service.PartnerImageSourceService;
import com.partner.admin.service.PartnerProjectInfoService;
import com.partner.admin.service.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
/**
* 首页信息
* @author yaobaizheng
*/
@Controller
@RequestMapping("/common")
@Api(tags = "首页信息返回")
public class CommonController extends BaseController{
@Autowired
PartnerImageSourceService partnerImageSourceService;
@Autowired
PartnerProjectInfoService partnerProjectInfoService;
@PostMapping("/getLogOutHomePageInfo")
@ResponseBody
@ApiOperation(value = "返回未登陆时首页轮播图,统计数信息",notes = "直接调用")
public HomePageLogoutInfoVO getLogOutHomePageInfo() {
//首页轮播图
QueryWrapper<PartnerImageSource> pisQW = new QueryWrapper<PartnerImageSource>();
pisQW.eq("object_type", 4);
List<PartnerImageSource> pisList = partnerImageSourceService.list(pisQW);
//本意只使用合伙人平台的数据,但是鉴于数据为空,暂时不好看,暂时借用产业知道的数据,下面的以后会删除
// 统计数-总项目量+项目总投资额+项目总固定资产投资额+平台合伙人
HomePageLogoutInfoVO homePageLogoutInfoVO = partnerProjectInfoService.getLogoutStatistics();
homePageLogoutInfoVO.setPartnerImageSourceList(pisList);
return homePageLogoutInfoVO;
}
@PostMapping("/getLoginHomePageInfo")
@ResponseBody
@ApiOperation(value = "返回登陆时首页轮播图,统计数信息",notes = "直接调用")
public HomePageLoginInfoVO getLoginHomePageInfo() {
//首页轮播图
QueryWrapper<PartnerImageSource> pisQW = new QueryWrapper<>();
pisQW.eq("object_type", 5);
List<PartnerImageSource> pisList = partnerImageSourceService.list(pisQW);
//统计数-总项目量+总投资额+审核中的项目+推进中的项目
HomePageLoginInfoVO homePageLoginInfoVO = partnerProjectInfoService.getLoginStatistics(getUserInfo().getUserId());
homePageLoginInfoVO.setPartnerImageSourceList(pisList);
return homePageLoginInfoVO;
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment