添加对外开放接口

main
吴顺杰 2 months ago
parent 318c22df86
commit 8ed9410603

@ -8,22 +8,44 @@ import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.tc.entity.*;
import com.ruoyi.tc.entity.AssetBasicNetwork;
import com.ruoyi.tc.entity.AssetCurrent;
import com.ruoyi.tc.entity.AssetExport;
import com.ruoyi.tc.entity.AssetSupplyChain;
import com.ruoyi.tc.entity.AssetTask;
import com.ruoyi.tc.entity.UnitOtherConcat;
import com.ruoyi.tc.entity.po.AssetBasicNetworkCpPo;
import com.ruoyi.tc.entity.po.AssetCurrentCpPo;
import com.ruoyi.tc.entity.po.AssetSupplyChainCpPo;
import com.ruoyi.tc.entity.po.UnitOtherConcatCpPo;
import com.ruoyi.tc.entity.request.AssetCurrentPageRequest;
import com.ruoyi.tc.service.*;
import com.ruoyi.tc.service.AssetBasicNetworkCpService;
import com.ruoyi.tc.service.AssetBasicNetworkService;
import com.ruoyi.tc.service.AssetBusinessFormCpService;
import com.ruoyi.tc.service.AssetBusinessFormService;
import com.ruoyi.tc.service.AssetCurrentCpService;
import com.ruoyi.tc.service.AssetCurrentService;
import com.ruoyi.tc.service.AssetSupplyChainCpService;
import com.ruoyi.tc.service.AssetSupplyChainService;
import com.ruoyi.tc.service.AssetTaskService;
import com.ruoyi.tc.service.UnitOtherConcatCpService;
import com.ruoyi.tc.service.UnitOtherConcatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.Serializable;
@ -100,26 +122,6 @@ public class AssetCurrentController extends BaseController {
return success(assetCurrentService.page(page, as));
}
/**
* ()
*
* @param as
* @return
*/
@ApiOperation(value = "查询所有数据(带子表)", response = AssetCurrent.class)
@PostMapping("/selectAllAsset")
public AjaxResult selectAllAsset(@RequestBody AssetCurrentPageRequest as, HttpServletRequest request) {
if (!"U2FsdGVkX199X+bZRylJnFMCCCrHgQw7OJ0DIV7jDQHnrX//trM2UNQx00jKvg4Oi16bAi2VWcg=".equals(request.getHeader("token"))) {
throw new ServiceException("token验证失败");
}
if (!"OB4J7ZcpC8aLDuH0InPRhYjxNx0TGaRK".equals(request.getHeader("signature"))) {
throw new ServiceException("签名验证失败");
}
return success(assetCurrentService.selectAllAsset(as));
}
/**
*
*

@ -0,0 +1,138 @@
package com.ruoyi.tc.controller;
import cn.hutool.core.collection.CollectionUtil;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.tc.entity.AssetCurrent;
import com.ruoyi.tc.entity.Unit;
import com.ruoyi.tc.entity.request.AssetCurrentPageRequest;
import com.ruoyi.tc.entity.request.GeneralQueryRequest;
import com.ruoyi.tc.service.AssetCurrentService;
import com.ruoyi.tc.service.UnitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
*
*
* @author wu
* @since 2024/11/28 16:41
*/
@Api(tags = "提供外部接口")
@RestController
@RequestMapping("/tc/without")
public class WithoutController extends BaseController {
@Resource
private AssetCurrentService assetCurrentService;
@Resource
private UnitService unitService;
@Resource
private RedisCache redisCache;
/**
* ()
*
* @param as
* @return
*/
@ApiOperation(value = "查询所有数据(带子表)", response = AssetCurrent.class)
@PostMapping("/selectAllAsset")
public AjaxResult selectAllAsset(@RequestBody AssetCurrentPageRequest as, HttpServletRequest request) {
if (!"U2FsdGVkX199X+bZRylJnFMCCCrHgQw7OJ0DIV7jDQHnrX//trM2UNQx00jKvg4Oi16bAi2VWcg=".equals(request.getHeader("token"))) {
throw new ServiceException("签名验证失败");
}
if (!"OB4J7ZcpC8aLDuH0InPRhYjxNx0TGaRK".equals(request.getHeader("signature"))) {
throw new ServiceException("签名验证失败");
}
return success(assetCurrentService.selectAllAsset(as));
}
/**
*
*
* @param req
* @return
*/
@ApiOperation(value = "获取所有单位列表", response = Unit.class)
@PostMapping("/selectAllUnit")
public AjaxResult selectAllUnit(@RequestBody GeneralQueryRequest req, HttpServletRequest request) {
if (!"U2FsdGVkX199X+bZRylJnFMCCCrHgQw7OJ0DIV7jDQHnrX//trM2UNQx00jKvg4Oi16bAi2VWcg=".equals(request.getHeader("token"))) {
throw new ServiceException("签名验证失败");
}
if (!"OB4J7ZcpC8aLDuH0InPRhYjxNx0TGaRK".equals(request.getHeader("signature"))) {
throw new ServiceException("签名验证失败");
}
return AjaxResult.success(unitService.selectAllUnit(req));
}
/**
*
*
* @return
*/
@ApiOperation(value = "获取所有单位列表213", response = Unit.class)
@GetMapping("/test")
public void test() {
sendSms("123", "17638176947", "120ErrorMes");
}
/**
*
*
* @param content
* @param tel 使,
* @param errorMes rediskey
*/
public void sendSms(String content, String tel, String errorMes) {
if (errorMes != null) {
Integer minutes = redisCache.getCacheObject(errorMes);
if (minutes == null) {
redisCache.setCacheObject(errorMes, 1, 10, TimeUnit.MINUTES);
return;
}
if (minutes < 10) {
long expireTime = redisCache.getExpire(errorMes);
if (expireTime == -1 || expireTime == -2) {
redisCache.setCacheObject(errorMes, 1, 10, TimeUnit.MINUTES);
} else {
redisCache.setCacheObject(errorMes, minutes + 1, (int) expireTime, TimeUnit.SECONDS);
}
return;
}
}
// 限制每种tel每天只能发一次短信
Map<String, Object> dataKey = redisCache.getCacheMap("dataKey");
if (CollectionUtil.isNotEmpty(dataKey)) {
String sendDateStr = (String) dataKey.get(content);
LocalDate sendDate = LocalDate.parse(sendDateStr);
if (LocalDate.now().equals(sendDate)) {
return;
} else {
dataKey.put(content, LocalDate.now());
redisCache.setCacheMap("dataKey", dataKey);
}
} else {
Map<String, Object> map = new HashMap<>();
map.put(content, LocalDate.now());
redisCache.setCacheMap("dataKey", map);
}
System.err.println("已经发送短信");
}
}

@ -0,0 +1,37 @@
package com.ruoyi.tc.entity.request;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
/**
*
*
* @author wu
* @since 2024/11/28 17:11
*/
@Data
public class GeneralQueryRequest implements Serializable {
private static final long serialVersionUID = 7986278462703735074L;
/**
*
*/
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty("开始时间")
private Date startTime;
/**
*
*/
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty("结束时间")
private Date endTime;
}

@ -2,8 +2,8 @@ package com.ruoyi.tc.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.tc.entity.Unit;
import com.ruoyi.tc.entity.request.GeneralQueryRequest;
import com.ruoyi.tc.entity.request.UnitRequest;
import org.apache.ibatis.annotations.Param;
@ -59,4 +59,12 @@ public interface UnitMapper extends BaseMapper<Unit> {
* @return
*/
Page<Unit> dwList(Page<Unit> page, @Param("req") UnitRequest unit);
/**
*
*
* @param req
* @return
*/
List<Unit> selectAllUnit(@Param("req") GeneralQueryRequest req);
}

@ -5,6 +5,7 @@ package com.ruoyi.tc.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.tc.entity.Unit;
import com.ruoyi.tc.entity.request.GeneralQueryRequest;
import com.ruoyi.tc.entity.request.UnitRequest;
import java.util.List;
@ -56,8 +57,6 @@ public interface UnitService extends IService<Unit> {
*/
void deleteUnits(Long ids);
/**
*
*
@ -65,4 +64,12 @@ public interface UnitService extends IService<Unit> {
* @return
*/
Page<Unit> dwList(Page<Unit> page, UnitRequest unit);
/**
*
*
* @param req
* @return
*/
List<Unit> selectAllUnit(GeneralQueryRequest req);
}

@ -9,6 +9,7 @@ import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.tc.entity.Unit;
import com.ruoyi.tc.entity.request.GeneralQueryRequest;
import com.ruoyi.tc.entity.request.UnitRequest;
import com.ruoyi.tc.mapper.UnitMapper;
import com.ruoyi.tc.service.UnitService;
@ -118,4 +119,15 @@ public class UnitServiceImpl extends ServiceImpl<UnitMapper, Unit> implements Un
return baseMapper.dwList(page, unit);
}
/**
*
*
* @param req
* @return
*/
@Override
public List<Unit> selectAllUnit(GeneralQueryRequest req) {
return baseMapper.selectAllUnit(req);
}
}

@ -1,125 +1,89 @@
//package com.ruoyi.web.core.config;
//
//import java.util.ArrayList;
//import java.util.List;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import com.ruoyi.common.config.RuoYiConfig;
//import io.swagger.annotations.ApiOperation;
//import io.swagger.models.auth.In;
//import springfox.documentation.builders.ApiInfoBuilder;
//import springfox.documentation.builders.PathSelectors;
//import springfox.documentation.builders.RequestHandlerSelectors;
//import springfox.documentation.service.ApiInfo;
//import springfox.documentation.service.ApiKey;
//import springfox.documentation.service.AuthorizationScope;
//import springfox.documentation.service.Contact;
//import springfox.documentation.service.SecurityReference;
//import springfox.documentation.service.SecurityScheme;
//import springfox.documentation.spi.DocumentationType;
//import springfox.documentation.spi.service.contexts.SecurityContext;
//import springfox.documentation.spring.web.plugins.Docket;
//
///**
// * Swagger2的接口配置
// *
// * @author ruoyi
// */
//@Configuration
//public class SwaggerConfig
//{
// /** 系统基础配置 */
// @Autowired
// private RuoYiConfig ruoyiConfig;
//
// /** 是否开启swagger */
// @Value("${swagger.enabled}")
// private boolean enabled;
//
// /** 设置请求的统一前缀 */
// @Value("${swagger.pathMapping}")
// private String pathMapping;
//
// /**
// * 创建API
// */
// @Bean
// public Docket createRestApi()
// {
// return new Docket(DocumentationType.OAS_30)
// // 是否启用Swagger
// .enable(enabled)
// // 用来创建该API的基本信息展示在文档的页面中自定义展示的信息
// .apiInfo(apiInfo())
// // 设置哪些接口暴露给Swagger展示
// .select()
// // 扫描所有有注解的api用这种方式更灵活
// .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
// // 扫描指定包中的swagger注解
// // .apis(RequestHandlerSelectors.basePackage("com.ruoyi.project.tool.swagger"))
// // 扫描所有 .apis(RequestHandlerSelectors.any())
// .paths(PathSelectors.any())
// .build()
// /* 设置安全模式swagger可以设置访问token */
// .securitySchemes(securitySchemes())
// .securityContexts(securityContexts())
// .pathMapping(pathMapping);
// }
//
// /**
// * 安全模式这里指定token通过Authorization头请求头传递
// */
// private List<SecurityScheme> securitySchemes()
// {
// List<SecurityScheme> apiKeyList = new ArrayList<SecurityScheme>();
// apiKeyList.add(new ApiKey("Authorization", "Authorization", In.HEADER.toValue()));
// return apiKeyList;
// }
//
// /**
// * 安全上下文
// */
// private List<SecurityContext> securityContexts()
// {
// List<SecurityContext> securityContexts = new ArrayList<>();
// securityContexts.add(
// SecurityContext.builder()
// .securityReferences(defaultAuth())
// .operationSelector(o -> o.requestMappingPattern().matches("/.*"))
// .build());
// return securityContexts;
// }
//
// /**
// * 默认的安全上引用
// */
// private List<SecurityReference> defaultAuth()
// {
// AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
// AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
// authorizationScopes[0] = authorizationScope;
// List<SecurityReference> securityReferences = new ArrayList<>();
// securityReferences.add(new SecurityReference("Authorization", authorizationScopes));
// return securityReferences;
// }
//
// /**
// * 添加摘要信息
// */
// private ApiInfo apiInfo()
// {
// // 用ApiInfoBuilder进行定制
// return new ApiInfoBuilder()
// // 设置标题
// .title("标题若依管理系统_接口文档")
// // 描述
// .description("描述:用于管理集团旗下公司的人员信息,具体包括XXX,XXX模块...")
// // 作者信息
// .contact(new Contact(ruoyiConfig.getName(), null, null))
// // 版本
// .version("版本号:" + ruoyiConfig.getVersion())
// .build();
// }
//}
package com.ruoyi.web.core.config;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.config.RuoYiConfig;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
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.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
/**
* Swagger2
*
* @author ruoyi
*/
@Configuration
@EnableSwagger2WebMvc
public class SwaggerConfig {
/**
*
*/
@Autowired
private RuoYiConfig ruoyiConfig;
/**
* swagger
*/
@Value("${swagger.enabled}")
private boolean enabled;
/**
*
*/
@Value("${swagger.pathMapping}")
private String pathMapping;
/**
* API
*/
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
// 是否启用Swagger
.enable(enabled)
//分组名称
.groupName("太仓资产核查")
// 用来创建该API的基本信息展示在文档的页面中自定义展示的信息
.apiInfo(apiInfo())
// 设置哪些接口暴露给Swagger展示
.select()
// 扫描所有有注解的api用这种方式更灵活
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
// 扫描指定包中的swagger注解
// .apis(RequestHandlerSelectors.basePackage("com.ruoyi.project.tool.swagger"))
// 扫描所有 .apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.pathMapping(pathMapping)
// 排除mybatis-plus的分页参数
.ignoredParameterTypes(Page.class, IPage.class);
}
/**
*
*/
private ApiInfo apiInfo() {
// 用ApiInfoBuilder进行定制
return new ApiInfoBuilder()
// 设置标题
.title("太仓资产核查系统_接口文档")
// 描述
.description("描述:用于太仓资产核查")
// 作者信息
.contact(new Contact(ruoyiConfig.getName(), null, null))
// 版本
.version("版本号:" + ruoyiConfig.getVersion())
.build();
}
}

@ -94,6 +94,13 @@ knife4j:
production: true
enable: false
# Swagger配置
swagger:
# 是否开启swagger
enabled: false
# 请求前缀
pathMapping: /
# 开发环境配置
server:
# 服务器的HTTP端口默认为8080

@ -119,6 +119,13 @@ knife4j:
# production: true
enable: true
# Swagger配置
swagger:
# 是否开启swagger
enabled: true
# 请求前缀
pathMapping: /
# 防止XSS攻击
xss:
# 过滤开关

@ -450,12 +450,12 @@
and a.xtzt = #{req.xtzt}
</if>
<if test="req.startTime != null ">
and a.create_time &gt;= #{req.startTime}
and a.update_time &gt;= #{req.startTime}
</if>
<if test="req.endTime != null">
and a.create_time &lt;= #{req.endTime}
and a.update_time &lt;= #{req.endTime}
</if>
</where>
order by a.create_time desc
order by a.create_time
</select>
</mapper>

@ -139,6 +139,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
</select>
<select id="selectAllUnit" resultType="com.ruoyi.tc.entity.Unit">
select a.*,d.dept_name as deptName from unit_info a
left join sys_dept d on a.dept_id = d.dept_id
<where>
a.del_flag = '0' and d.del_flag = '0'
<if test="req.startTime != null ">
and a.update_time &gt;= #{req.startTime}
</if>
<if test="req.endTime != null">
and a.update_time &lt;= #{req.endTime}
</if>
</where>
order by create_time
</select>
<update id="deleteUnits">
update unit_info set del_flag = '2' where id = #{id}
</update>

@ -1,5 +1,9 @@
package com.ruoyi.framework.config;
import com.ruoyi.framework.config.properties.PermitAllUrlProperties;
import com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter;
import com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl;
import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -16,10 +20,6 @@ import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.authentication.logout.LogoutFilter;
import org.springframework.web.filter.CorsFilter;
import com.ruoyi.framework.config.properties.PermitAllUrlProperties;
import com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter;
import com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl;
import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl;
/**
* spring security
@ -117,7 +117,7 @@ public class SecurityConfig
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
// .antMatchers("/unit/assetTask/**","/tc/**","/unit/assetLc/**","/tc/unit/**").permitAll()
// 除上面外的所有请求全部需要鉴权认证
.antMatchers("/tc/assetCurrent/selectAllAsset").permitAll()
.antMatchers("/tc/without/**").permitAll()
.anyRequest().authenticated();
})
// 添加Logout filter

Loading…
Cancel
Save