去除大量无用文件,上传页面优化,代码优化,更新sql文件

This commit is contained in:
郑杰
2018-10-03 10:28:27 +08:00
parent 938e56be62
commit 4ed44c86da
48 changed files with 296 additions and 11451 deletions
@@ -1,4 +1,4 @@
package me.aurora.app.rest.web;
package me.aurora.app.rest.utils;
import lombok.extern.slf4j.Slf4j;
import me.aurora.annotation.Log;
@@ -38,7 +38,7 @@ public class PictureController {
@GetMapping(value = "/index")
public ModelAndView index(){
log.warn("REST request to PicturePage");
return new ModelAndView("/web/picture/index");
return new ModelAndView("/utils/picture/index");
}
/**
@@ -73,7 +73,7 @@ public class PictureController {
@GetMapping(value = "/toAddPage")
public ModelAndView toAddPage(){
log.warn("REST request to addPicturePage");
return new ModelAndView("/web/picture/add");
return new ModelAndView("/utils/picture/add");
}
/**
@@ -20,6 +20,10 @@ import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.Map;
/**
* @author 郑杰
* @date 2018/10/02
*/
@Slf4j
@RestController
@RequestMapping("qiNiu")
@@ -1,36 +0,0 @@
package me.aurora.app.rest.web;
import lombok.extern.slf4j.Slf4j;
import me.aurora.annotation.Log;
import me.aurora.domain.ResponseEntity;
import me.aurora.util.AuroraConstant;
import me.aurora.util.HttpUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
@Slf4j
@RestController
@RequestMapping("weather")
public class WeatherController {
@Log("获取天气信息")
@GetMapping(value = "/index")
public ModelAndView weather() {
return new ModelAndView("/web/weather/weather");
}
@GetMapping(value = "/query")
public ResponseEntity queryWeather(@RequestParam String areaId) {
try {
String data = HttpUtils.sendPost(AuroraConstant.MEIZU_WEATHER_URL, "cityIds=" + areaId);
return ResponseEntity.ok(data);
} catch (Exception e) {
log.error("查询天气失败", e.getMessage());
return ResponseEntity.error("查询天气失败,请联系网站管理员!");
}
}
}
@@ -1,5 +1,6 @@
package me.aurora.config;
import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@@ -30,7 +31,7 @@ public class SwaggerConfig {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.paths(PathSelectors.any())
.paths(Predicates.not(PathSelectors.regex("/error.*")))
.build();
}
@@ -19,12 +19,13 @@ public class PathFormat {
private static final String MINUTE = "ii";
private static final String SECOND = "ss";
private static final String RAND = "rand";
private static final String REGEX = "\\{([^\\}]+)\\}";
private static Date currentDate = null;
public static String parse ( String input ) {
Pattern pattern = Pattern.compile( "\\{([^\\}]+)\\}", Pattern.CASE_INSENSITIVE );
Pattern pattern = Pattern.compile( REGEX, Pattern.CASE_INSENSITIVE );
Matcher matcher = pattern.matcher(input);
PathFormat.currentDate = new Date();
@@ -55,7 +56,7 @@ public class PathFormat {
public static String parse ( String input, String filename ) {
Pattern pattern = Pattern.compile( "\\{([^\\}]+)\\}", Pattern.CASE_INSENSITIVE );
Pattern pattern = Pattern.compile( REGEX, Pattern.CASE_INSENSITIVE );
Matcher matcher = pattern.matcher(input);
String matchStr = null;
@@ -10,7 +10,10 @@ import java.util.Map;
public final class ActionMap {
public static final Map<String, Integer> mapping;
// 获取配置请求
/**
* 获取配置请求
*/
public static final int CONFIG = 0;
public static final int UPLOAD_IMAGE = 1;
public static final int UPLOAD_SCRAWL = 2;
@@ -4,5 +4,8 @@ package me.aurora.config.baidu.ueditor.define;
* @author baidu.com
*/
public enum ActionState {
/**
* 未知的错误
*/
UNKNOW_ERROR
}
@@ -62,7 +62,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity handleMethodArgumentNotValidException(MethodArgumentNotValidException e){
log.error(e.getMessage());
String str[] = e.getBindingResult().getAllErrors().get(0).getCodes()[1].split("\\.");
String[] str = e.getBindingResult().getAllErrors().get(0).getCodes()[1].split("\\.");
StringBuffer msg = new StringBuffer(str[1]+":");
msg.append(e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
return ResponseEntity.error(msg.toString());
@@ -31,7 +31,7 @@ public class EmailVo {
private Boolean isHtml = true;
public ArrayList<String> getTos() {
String str[] = this.tos.split("[,,;;]");
String[] str = this.tos.split("[,,;;]");
ArrayList<String> list = new ArrayList<>();
for (String s : str) {
list.add(s);
@@ -40,8 +40,9 @@ public interface AlipayService {
AlipayConfig findById(long id);
/**
* 配置
* 更新配置
* @param alipayConfig
* @return
*/
@CachePut(key = "#p0.getId()")
AlipayConfig updateConfig(AlipayConfig alipayConfig);
@@ -18,6 +18,8 @@ public interface EmailService {
/**
* 更新邮件配置
* @param emailConfig
* @param old
* @return
*/
@CachePut(key = "#p0.getId()")
EmailConfig updateConfig(EmailConfig emailConfig,EmailConfig old);
@@ -34,6 +36,7 @@ public interface EmailService {
* 发送邮件
* @param emailVo
* @param emailConfig
* @throws Exception
*/
@Async
void send(EmailVo emailVo, EmailConfig emailConfig) throws Exception;
@@ -85,6 +85,7 @@ public interface MenuService {
/**
* 更新菜单
* @param menu
* @param oldMenu
* @param roles
*/
@CacheEvict(allEntries = true)
@@ -32,6 +32,7 @@ public interface QiNiuService {
/**
* 修改配置
* @param qiniuConfig
* @return
*/
@CacheEvict(allEntries = true)
QiniuConfig updateConfig(QiniuConfig qiniuConfig);
@@ -50,7 +50,7 @@ public interface RoleService {
* @return
*/
@CacheEvict(allEntries = true)
void inster(Role role, String permissions) throws AuroraException;
void inster(Role role, String permissions);
/**
* 根据ID查找Role
@@ -8,7 +8,16 @@ import java.util.Map;
*/
public interface SessionService {
/**
* 得到在线的用户
* @return
*/
Map getOnlineInfo();
/**
* 踢出
* @param sessionId
* @return
*/
boolean forceLogout(String sessionId);
}
@@ -37,7 +37,7 @@ public class AlipayServiceImpl implements AlipayService {
AlipayClient alipayClient = new DefaultAlipayClient(alipay.getGatewayUrl(), alipay.getAppID(), alipay.getPrivateKey(), alipay.getFormat(), alipay.getCharset(), alipay.getPublicKey(), alipay.getSignType());
double money = Double.parseDouble(trade.getTotalAmount());
if(money <= 0 || money>=500){
if(money <= 0 || money>=5000){
throw new AuroraException(HttpStatus.HTTP_BAD_REQUEST,"测试金额过大");
}
@@ -13,10 +13,7 @@ import me.aurora.repository.spec.PictureSpec;
import me.aurora.service.PictureService;
import me.aurora.service.dto.PictureDto;
import me.aurora.service.mapper.PictureMapper;
import me.aurora.util.FileUtil;
import me.aurora.util.PageUtil;
import me.aurora.util.SizeUtil;
import me.aurora.util.ValidationUtil;
import me.aurora.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.data.domain.Page;
@@ -40,14 +37,6 @@ import java.util.Optional;
@Service(value = "pictureService")
public class PictureServiceImpl implements PictureService {
private final String uploadUrl = "https://sm.ms/api/upload";
private final String SUCCESS = "success";
private final String CODE = "code";
private final String MSG = "msg";
@Autowired
private PictureRepo pictureRepo;
@@ -74,11 +63,11 @@ public class PictureServiceImpl implements PictureService {
//sm.ms 固定格式
param.add("smfile", resource);
//执行HTTP请求
String str = rest.postForObject(uploadUrl, param, String.class);
String str = rest.postForObject(AuroraConstant.Url.SM_MS_URL, param, String.class);
JSONObject jsonObject = JSONUtil.parseObj(str);
Picture picture = null;
if(!jsonObject.get(CODE).toString().equals(SUCCESS)){
throw new AuroraException(HttpStatus.HTTP_BAD_REQUEST,jsonObject.get(MSG).toString());
if(!jsonObject.get(AuroraConstant.Page.CODE).toString().equals(AuroraConstant.SUCCESS)){
throw new AuroraException(HttpStatus.HTTP_BAD_REQUEST,jsonObject.get(AuroraConstant.Page.MSG).toString());
}
//转成实体类
picture = JSON.parseObject(jsonObject.get("data").toString(), Picture.class);
@@ -28,14 +28,14 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.UnsupportedEncodingException;
import java.sql.Timestamp;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author 郑杰
* @date 2018/10/02
*/
@Service
public class QiNiuServiceImpl implements QiNiuService {
@@ -66,6 +66,9 @@ public class RoleServiceImpl implements RoleService {
if(roleRepo.findByName(role.getName())!=null){
throw new AuroraException(HttpStatus.HTTP_BAD_REQUEST,"角色已存在");
}
if(StrUtil.isEmpty(permissions)){
throw new AuroraException(HttpStatus.HTTP_NOT_FOUND,"请至少为其分配一个权限");
}
role.setPermissions(getPermissions(permissions));
roleRepo.save(role);
}
@@ -80,6 +83,9 @@ public class RoleServiceImpl implements RoleService {
@Override
public void update(Role role, String permissions) {
if(StrUtil.isEmpty(permissions)){
throw new AuroraException(HttpStatus.HTTP_NOT_FOUND,"请至少为其分配一个权限");
}
if(role.getId() == null){
throw new AuroraException(HttpStatus.HTTP_NOT_FOUND,"角色ID不能为空");
}
@@ -117,6 +123,7 @@ public class RoleServiceImpl implements RoleService {
* @return
*/
public Set<Permission> getPermissions(String permissions){
Set<Permission> permissionSet = new HashSet<>();
for(String permissionId:permissions.split(",")){
Permission permission = new Permission();
@@ -13,6 +13,11 @@ import org.mapstruct.ReportingPolicy;
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface PictureMapper extends EntityMapper<PictureDto, Picture>{
/**
* 转DTO
* @param picture
* @return
*/
@Mapping(target = "userName",source = "picture.user.username")
@Override
PictureDto toDto(Picture picture);
@@ -17,8 +17,6 @@ import java.lang.reflect.Method;
*/
public class AddressUtils {
static String region = "内网IP|0|0|内网IP|内网IP";
private AddressUtils() {
}
@@ -57,7 +55,7 @@ public class AddressUtils {
/**
* 太难看了,转换下
*/
return dataBlock.getRegion().equals(region)?"内网IP":dataBlock.getRegion();
return dataBlock.getRegion().equals(AuroraConstant.REGION)?"内网IP":dataBlock.getRegion();
} catch (Exception e) {
log.error("获取地址信息异常:{}", e);
}
@@ -1,14 +1,63 @@
package me.aurora.util;
/**
* 常用接口
* 常用静态常量
* @author 郑杰
* @date 2018/09/29 12:52:06
*/
public class AuroraConstant {
private AuroraConstant() {
public static final String SUCCESS = "success";
/**
* 用于排序
*/
public static class Soft{
public static final String DESC = "desc";
public static final String ASC = "asc";
}
public static final String MEIZU_WEATHER_URL = "http://aider.meizu.com/app/weather/listWeather";
/**
* 用于分页
*/
public static class Page{
public static final String CODE = "code";
public static final String MSG = "msg";
public static final String COUNT = "count";
public static final String DATA = "data";
}
/**
* 用于七牛云zone与机房对应关系
*/
public static class QiNiu{
public static final String HUAD = "华东";
public static final String HUAB = "华北";
public static final String HUAN = "华南";
public static final String BEIM = "北美";
public static final String DNY = "东南亚";
}
/**
* 用于IP定位转换
*/
public static final String REGION = "内网IP|0|0|内网IP|内网IP";
/**
* 常用接口
*/
public static class Url{
public static final String SM_MS_URL = "https://sm.ms/api/upload";
}
}
+1 -1
View File
@@ -116,7 +116,7 @@ public class HttpUtils {
String ret = "";
while (ret != null) {
ret = indata.readLine();
if (ret != null && !ret.trim().equals("")) {
if (ret != null && !"".equals(ret.trim())) {
result.append(ret);
}
}
@@ -33,7 +33,7 @@ public class ListSortUtil<T> {
Method method1 = ((T)obj1).getClass().getMethod(methodStr, new Class[0]);
Method method2 = ((T)obj2).getClass().getMethod(methodStr, new Class[0]);
if (sortMode != null && "desc".equals(sortMode)) {
if (sortMode != null && AuroraConstant.Soft.DESC.equals(sortMode)) {
// 倒序
retVal = method2.invoke(((T) obj2), new Object[0]).toString().compareTo(method1.invoke(((T) obj1), new Object[0]).toString());
} else {
+4 -9
View File
@@ -12,17 +12,12 @@ import java.util.Map;
*/
public class PageUtil {
private static final String CODE = "code";
private static final String MSG = "msg";
private static final String COUNT = "count";
private static final String DATA = "data";
public static Map<String,Object> buildPage(List list,Long total) {
Map<String,Object> map = new HashMap<>(5);
map.put(PageUtil.CODE,0);
map.put(PageUtil.MSG,"");
map.put(PageUtil.COUNT,total);
map.put(PageUtil.DATA,list);
map.put(AuroraConstant.Page.CODE,0);
map.put(AuroraConstant.Page.MSG,"");
map.put(AuroraConstant.Page.COUNT,total);
map.put(AuroraConstant.Page.DATA,list);
return map;
}
}
+4 -4
View File
@@ -19,13 +19,13 @@ public class QiNiuUtil {
*/
public static Configuration getConfiguration(String zone){
if(zone.equals("华东")){
if(AuroraConstant.QiNiu.HUAD.equals(zone)){
return new Configuration(Zone.zone0());
} else if(zone.equals("华北")){
} else if(AuroraConstant.QiNiu.HUAB.equals(zone)){
return new Configuration(Zone.zone1());
} else if(zone.equals("华南")){
} else if(AuroraConstant.QiNiu.HUAN.equals(zone)){
return new Configuration(Zone.zone2());
} else if (zone.equals("北美")){
} else if (AuroraConstant.QiNiu.BEIM.equals(zone)){
return new Configuration(Zone.zoneNa0());
} else {
return new Configuration(Zone.zoneAs0());
+4 -4
View File
@@ -25,19 +25,19 @@ public class SizeUtil {
/**
* 格式化小数
*/
private static final DecimalFormat df = new DecimalFormat("0.00");
private static final DecimalFormat DF = new DecimalFormat("0.00");
public static String getSize(int size){
String resultSize = "";
if (size / GB >= 1) {
//如果当前Byte的值大于等于1GB
resultSize = df.format(size / (float) GB) + "GB ";
resultSize = DF.format(size / (float) GB) + "GB ";
} else if (size / MB >= 1) {
//如果当前Byte的值大于等于1MB
resultSize = df.format(size / (float) MB) + "MB ";
resultSize = DF.format(size / (float) MB) + "MB ";
} else if (size / KB >= 1) {
//如果当前Byte的值大于等于1KB
resultSize = df.format(size / (float) KB) + "KB ";
resultSize = DF.format(size / (float) KB) + "KB ";
} else {
resultSize = size + "B ";
}
@@ -30,7 +30,8 @@ public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper {
*/
@Override
public String getParameter(String name) {
if (("content".equals(name) || name.endsWith("WithHtml")) && !isIncludeRichText) {
boolean b = "content".equals(name) || name.endsWith("WithHtml");
if ( b && !isIncludeRichText) {
return super.getParameter(name);
}
name = JsoupUtil.clean(name);