Commit a8c391a3 by 袁伟铭

修改启动

parent 05c21c4a
......@@ -22,8 +22,4 @@ public class ApiApplication {
SpringApplication.run(ApiApplication.class, args);
}
@Bean
public SpringContextHolder springContextHolder() {
return new SpringContextHolder();
}
}
package com.zq.api.config;/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.alibaba.fastjson.JSON;
import com.zq.common.config.security.SecurityProperties;
import com.zq.common.vo.ApiTokenVo;
import io.jsonwebtoken.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;
import javax.crypto.spec.SecretKeySpec;
import javax.xml.bind.DatatypeConverter;
import java.security.Key;
import java.util.Date;
/**
* @author /
*/
@Slf4j
@Component
public class ApiTokenUtils implements InitializingBean {
private static SecurityProperties properties;
private static final String APP_TOKEN_KEY = "appToken";
private static Key key;
private static SignatureAlgorithm signatureAlgorithm;
public ApiTokenUtils(SecurityProperties securityProperties) {
ApiTokenUtils.properties = securityProperties;
}
@Override
public void afterPropertiesSet() {
signatureAlgorithm = SignatureAlgorithm.HS512;
byte[] keyBytes = DatatypeConverter.parseBase64Binary(properties.getBase64Secret());
key = new SecretKeySpec(keyBytes, signatureAlgorithm.getJcaName());
}
public static String createToken(ApiTokenVo tokenVo, long minutes) {
long nowMillis = System.currentTimeMillis();
Date now = new Date(nowMillis);
JwtBuilder jwtBuilder = Jwts.builder()
.setSubject(tokenVo.getPhone())
.setIssuedAt(now)
.claim(APP_TOKEN_KEY, tokenVo)
.signWith(signatureAlgorithm, key)
// 加入ID确保生成的 Token 都不一致
.setId(tokenVo.getUserId().toString());
if (minutes >= 0) {
long expMillis = nowMillis + (minutes * 60 * 1000);
Date exp = new Date(expMillis);
jwtBuilder.setExpiration(exp);
}
return jwtBuilder.compact();
}
public static ApiTokenVo getAppTokenVo(String token) {
try {
Claims claims = Jwts.parser()
.setSigningKey(DatatypeConverter.parseBase64Binary(properties.getBase64Secret()))
.parseClaimsJws(token)
.getBody();
// fix bug: 当前用户如果没有任何权限时,在输入用户名后,刷新验证码会抛IllegalArgumentException
return JSON.parseObject(JSON.toJSONString(claims.get(APP_TOKEN_KEY)), ApiTokenVo.class);
} catch (Exception e) {
return null;
}
}
public static boolean isTokenValid(String token) {
try {
//解析JWT字符串中的数据,并进行最基础的验证
Claims claims = Jwts.parser()
.setSigningKey(DatatypeConverter.parseBase64Binary(properties.getBase64Secret()))
.parseClaimsJws(token)
.getBody();
return true;
}
//在解析JWT字符串时,如果密钥不正确,将会解析失败,抛出SignatureException异常,说明该JWT字符串是伪造的
//在解析JWT字符串时,如果‘过期时间字段’已经早于当前时间,将会抛出ExpiredJwtException异常,说明本次请求已经失效
catch (SignatureException | ExpiredJwtException e) {
return false;
}
}
}
......@@ -10,8 +10,8 @@ file.name: FILE-SERVER
api.port: 9100
api.name: API-SERVER
cms.port: 9700
cms.name: CMS-SERVER
portal.port: 9700
portal.name: PORTAL-SERVER
gateway.port: 9888
gateway.name: GATEWAY-SERVER
......
package com.zq.portal.controller;
package com.zq.portal.controller.admin;
import com.zq.common.vo.ResultVo;
import com.zq.portal.service.PeopleService;
......@@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/portal/people/")
@RequestMapping("/portal/admin/people/")
public class PeopleController {
@Autowired
private PeopleService peopleService;
......
package com.zq.portal.controller;
package com.zq.portal.controller.admin;
import com.zq.common.annotation.AnonymousAccess;
import org.springframework.stereotype.Controller;
......@@ -6,7 +6,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/portal")
@RequestMapping("/portal/admin")
public class PortalController {
@AnonymousAccess
......
package com.zq.portal.controller;
package com.zq.portal.controller.admin;
import com.zq.common.vo.ResultVo;
import com.zq.portal.service.SearchService;
......@@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/portal/search/")
@RequestMapping("/portal/admin/search/")
public class SearchController {
@Autowired
......
package com.zq.portal.controller;
package com.zq.portal.controller.admin;
import com.alibaba.fastjson.JSONObject;
import com.zq.common.context.ContextUtils;
......@@ -17,8 +17,8 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/portal/stats/")
public class StatsController {
@RequestMapping("/portal/admin/stats/")
public class StatsAdminController {
@Autowired
private StatsServerFeignClient statsFegin;
@Autowired
......
package com.zq.portal.controller.app;
import com.zq.portal.service.StatsService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Api(tags = "统计相关接口")
@RequiredArgsConstructor
@RestController
@RequestMapping(value = "/portal/app/stats")
public class StatsController {
public final StatsService statsService;
}
package com.zq.portal.controller.app;
public class UserController {
}
package com.zq.portal.dao;
import org.springframework.stereotype.Repository;
@Repository
public interface StatsDao {
}
package com.zq.portal.feign;
import com.zq.common.vo.ResultVo;
import com.zq.common.vo.UploadVo;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
@Component
public class UploadServerFeignClient {
RestTemplate restTemplate = new RestTemplate();
String FileServer = "http://localhost:9500";
String xmlServer = "http://localhost:10230";
/**
* 上传xml 解析
*
* @param vo
* @return
*/
public ResultVo uploadXmlFile(UploadVo vo) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
parts.add("file", vo.getFile().getResource());
parts.add("systemName", vo.getSystemName());
HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(parts, headers);
ResponseEntity<ResultVo> responseEntity = restTemplate.postForEntity(xmlServer + "/xml/doMain", httpEntity, ResultVo.class);
return responseEntity.getBody();
}
// /**
// * 上传图片
// *
// * @param vo
// * @return
// */
// public ResultVo uploadImage(UploadVo vo) {
// return restTemplate.postForObject(FileServer + "/file/uploadImage", vo, ResultVo.class);
// }
//
// /**
// * 上传文件
// *
// * @param vo
// * @return
// */
// public ResultVo uploadFile(UploadVo vo) {
// return restTemplate.postForObject(FileServer + "/file/uploadFile", vo, ResultVo.class);
// }
}
......@@ -19,7 +19,6 @@ public class PortalCacheManager extends RedisUtils {
super(stringRedisTemplate, redisTemplate);
}
/**
* 获取缓存的区域统计数据
*
......@@ -68,7 +67,6 @@ public class PortalCacheManager extends RedisUtils {
setStr("peopleType", JSONObject.toJSONString(param));
}
/**
* 获取残疾人相关类型人口
*
......@@ -79,7 +77,6 @@ public class PortalCacheManager extends RedisUtils {
return getStr("peopleType");
}
/**
* 缓存残疾人相关类型人口
*
......@@ -90,7 +87,6 @@ public class PortalCacheManager extends RedisUtils {
setStr("CountTableData", JSONObject.toJSONString(data));
}
/**
* 获取残疾人相关类型人口
*
......@@ -137,7 +133,6 @@ public class PortalCacheManager extends RedisUtils {
return getStr("CJYLCount");
}
public void cachePeopleBaseDataNum(CountVo data) {
setStr("PeopleBaseDataNum", JSONObject.toJSONString(data));
}
......@@ -174,4 +169,5 @@ public class PortalCacheManager extends RedisUtils {
public void cacheCJYLCount(int count) {
setStr("CJYLCount", JSONObject.toJSONString(count));
}
}
package com.zq.portal.service;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
public class StatsService {
public Object getMapData() {
return null;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zq.portal.dao.StatsDao">
</mapper>
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