Skip to content

Commit

Permalink
sync from oschina and isuue version v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoymin committed Jun 19, 2018
1 parent b9dede9 commit 4d5b35d
Show file tree
Hide file tree
Showing 118 changed files with 22,601 additions and 164 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# oss-server
![](https://static.oschina.net/uploads/img/201806/18222124_VR9L.png)

**项目文档地址:http://oss-server.mydoc.io**

**oss-server项目交流群:608374991**

## 项目介绍

Expand Down
32 changes: 30 additions & 2 deletions oss-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.xiaominfo.oss</groupId>
<artifactId>oss-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>1.0</version>
<packaging>jar</packaging>
<name>oss-server</name>
<description>oss-server上传组件,该组件为项目服务,可单独部署迁移</description>
Expand Down Expand Up @@ -43,7 +43,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down Expand Up @@ -134,6 +137,31 @@
<artifactId>hutool-all</artifactId>
<version>4.0.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc -->
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.21.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.baomidou/mybatisplus-spring-boot-starter -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatisplus-spring-boot-starter</artifactId>
<version>1.0.5</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>2.1.9</version>
</dependency>
</dependencies>

<build>
Expand Down
112 changes: 112 additions & 0 deletions oss-server/src/main/java/com/xiaominfo/oss/api/AppInfoApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright (C) 2018 Zhejiang xiaominfo Technology CO.,LTD.
* All rights reserved.
* Official Web Site: http://www.xiaominfo.com.
* Developer Web Site: http://open.xiaominfo.com.
*/

package com.xiaominfo.oss.api;

import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Lists;
import com.xiaominfo.oss.common.pojo.Pagination;
import com.xiaominfo.oss.common.pojo.RestfulMessage;
import com.xiaominfo.oss.exception.AssemblerException;
import com.xiaominfo.oss.exception.ErrorCable;
import com.xiaominfo.oss.exception.ErrorConstant;
import com.xiaominfo.oss.module.model.OSSAppInfo;
import com.xiaominfo.oss.service.OSSAppInfoService;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/***
*
* @since:oss-server 1.0
* @author <a href="mailto:[email protected]">[email protected]</a>
* 2018/06/17 19:53
*/
@RestController
@RequestMapping("/oss/app")
public class AppInfoApplication extends RootApis{

@Autowired
OSSAppInfoService ossAppInfoService;

@GetMapping("/queryByPage")
public Pagination<OSSAppInfo> queryByPage(OSSAppInfo ossAppInfo,
@RequestParam(value = "page",defaultValue = "1") Integer current_page,
@RequestParam(value = "rows",defaultValue = "10") Integer page_size){
return ossAppInfoService.queryByPage(ossAppInfo,current_page,page_size);

}

@PostMapping("/queryById")
public RestfulMessage queryById(String id){
RestfulMessage restfulMessage=new RestfulMessage();
try{
assertArgumentNotEmpty(id,"项目id不能为空");
restfulMessage.setData(ossAppInfoService.selectById(id));
successResultCode(restfulMessage);
}catch (Exception e){
restfulMessage=wrapperException(e);
}
return restfulMessage;
}

@PostMapping("/delete")
public RestfulMessage delete(String id){
RestfulMessage restfulMessage=new RestfulMessage();
try{
//验证邮箱
assertArgumentNotEmpty(id,"项目id不能为空");
String[] ids= StrUtil.split(id,",");
ossAppInfoService.deleteBatchIds(Lists.newArrayList(ids));
successResultCode(restfulMessage);
}catch (Exception e){
restfulMessage=wrapperException(e);
}
return restfulMessage;
}


@PostMapping("/merge")
public RestfulMessage merge(OSSAppInfo ossAppInfo){
RestfulMessage restfulMessage=new RestfulMessage();
try{
//验证邮箱
assertArgumentNotEmpty(ossAppInfo.getName(),"项目名称不能为空");
assertArgumentNotEmpty(ossAppInfo.getCode(),"项目code不能为空");
assertArgumentNotEmpty(ossAppInfo.getDevId(),"开发者不能为空");
String regex="^.*?(\\\\|\\/|\\:|\\*|\\?|\\?|\\\"|\\“|\\”|\\>|\\<|\\|).*";
if (ReUtil.isMatch(regex,ossAppInfo.getCode())){
throw new AssemblerException(new ErrorCable(ErrorConstant.REQUEST_PARAMS_NOT_VALID,"项目code不能包含以下字符: / /: *?<>|"));
}
//不能包含\s字符
//不能包含中文
regex=".*?[\\u4e00-\\u9fa5\\s].*";
if (ReUtil.isMatch(regex,ossAppInfo.getCode())){
throw new AssemblerException(new ErrorCable(ErrorConstant.REQUEST_PARAMS_NOT_VALID,"项目code不能包含中文"));
}
//判断是否存在
if (ossAppInfoService.queryByCode(ossAppInfo.getCode())>0){
throw new AssemblerException(new ErrorCable(ErrorConstant.REQUEST_PARAMS_NOT_VALID,"项目code已经存在"));
}
if (StrUtil.isEmpty(ossAppInfo.getId())){
//insert
ossAppInfo.setCreateTime(DateTime.now().toString("yyyy-MM-dd HH:mm:ss"));
ossAppInfo.setUseSpace(0L);
ossAppInfo.setUseSpaceStr("0kb");
ossAppInfoService.insert(ossAppInfo);
}else{
ossAppInfoService.updateById(ossAppInfo);
}
successResultCode(restfulMessage);
}catch (Exception e){
restfulMessage=wrapperException(e);
}
return restfulMessage;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright (C) 2018 Zhejiang xiaominfo Technology CO.,LTD.
* All rights reserved.
* Official Web Site: http://www.xiaominfo.com.
* Developer Web Site: http://open.xiaominfo.com.
*/

package com.xiaominfo.oss.api;

import cn.hutool.core.lang.PatternPool;
import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Lists;
import com.xiaominfo.oss.common.pojo.Pagination;
import com.xiaominfo.oss.common.pojo.RestfulMessage;
import com.xiaominfo.oss.module.model.OSSDeveloper;
import com.xiaominfo.oss.service.OSSDeveloperService;
import com.xiaominfo.oss.utils.RandomUtils;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/***
*
* @since:oss-server 1.0
* @author <a href="mailto:[email protected]">[email protected]</a>
* 2018/06/17 12:01
*/
@RestController
@RequestMapping("/oss/developer")
public class DeveloperApplication extends RootApis{

@Autowired
OSSDeveloperService ossDeveloperService;


@GetMapping("/queryByPage")
public Pagination<OSSDeveloper> queryByPage(OSSDeveloper ossDeveloper,
@RequestParam(value = "page",defaultValue = "1") Integer current_page,
@RequestParam(value = "rows",defaultValue = "10") Integer page_size){
return ossDeveloperService.queryByPage(ossDeveloper,current_page,page_size);

}

@PostMapping("/queryById")
public RestfulMessage queryById(String id){
RestfulMessage restfulMessage=new RestfulMessage();
try{
//验证邮箱
assertArgumentNotEmpty(id,"id不能为空");
restfulMessage.setData(ossDeveloperService.selectById(id));
successResultCode(restfulMessage);
}catch (Exception e){
restfulMessage=wrapperException(e);
}
return restfulMessage;
}

@PostMapping("/delete")
public RestfulMessage delete(String id){
RestfulMessage restfulMessage=new RestfulMessage();
try{
//验证邮箱
assertArgumentNotEmpty(id,"id不能为空");
String[] ids=StrUtil.split(id,",");
ossDeveloperService.deleteBatchIds(Lists.newArrayList(ids));
successResultCode(restfulMessage);
}catch (Exception e){
restfulMessage=wrapperException(e);
}
return restfulMessage;
}


@PostMapping("/merge")
public RestfulMessage merge(OSSDeveloper ossDeveloper){
RestfulMessage restfulMessage=new RestfulMessage();
try{
//验证邮箱
assertArgumentNotEmpty(ossDeveloper.getName(),"开发者名称不能为空");
assertArgumentNotEmpty(ossDeveloper.getTel(),"手机号不能为空");
assertArgumentNotEmpty(ossDeveloper.getEmail(),"邮箱不能为空");
isTrue(ReUtil.isMatch(PatternPool.EMAIL,ossDeveloper.getEmail()),"邮箱格式非法");
if (StrUtil.isEmpty(ossDeveloper.getId())){
//insert
ossDeveloper.setAppid("oss"+ RandomUtils.random(6));
ossDeveloper.setAppsecret(RandomUtils.random(8));
ossDeveloper.setStatus("0");
ossDeveloper.setCreateTime(DateTime.now().toString("yyyy-MM-dd HH:mm:ss"));
ossDeveloper.setUseSpace(0L);
ossDeveloper.setUseSpaceStr("0kb");
ossDeveloperService.insert(ossDeveloper);
}else{
ossDeveloperService.updateById(ossDeveloper);
}
successResultCode(restfulMessage);
}catch (Exception e){
restfulMessage=wrapperException(e);
}
return restfulMessage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@

import cn.hutool.core.util.StrUtil;
import com.google.common.collect.ImmutableMap;
import com.xiaominfo.oss.common.annotation.NotLogin;
import com.xiaominfo.oss.common.conf.Consts;
import com.xiaominfo.oss.common.pojo.RestfulMessage;
import com.xiaominfo.oss.exception.ErrorConstant;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

Expand All @@ -24,7 +29,7 @@
* 2018/06/11 14:25
*/
@Controller
public class IndexApplication {
public class IndexApplication extends RootApis{

@Value(value = "${oss.security.userName}")
private String userN;
Expand All @@ -35,22 +40,34 @@ public class IndexApplication {

@GetMapping(value = {"/","/index"})
public String index(){
return "redirect:/oss/list/";
return "index";
}


@NotLogin
@GetMapping("/login")
public String login(){
return "login";
}

@GetMapping("/exit")
public String exit(HttpServletRequest request){
request.getSession().removeAttribute(Consts.Admin_User_Session);
return "login";
}

@NotLogin
@PostMapping("/login")
public String loginValidate(String username, String password, Model model, HttpServletRequest request){
@ResponseBody
public RestfulMessage loginValidate(String username, String password, Model model, HttpServletRequest request){
RestfulMessage r=new RestfulMessage();
if (StrUtil.equalsIgnoreCase(username,userN)&&StrUtil.equalsIgnoreCase(password,passwd)){
request.getSession().setAttribute("USER", ImmutableMap.of("userName",username));
return "redirect:/oss/list/";
request.getSession().setAttribute(Consts.Admin_User_Session, ImmutableMap.of("userName",username));
successResultCode(r);
}else{
r.setCode(ErrorConstant.REQUEST_PARAMS_NOT_VALID);
r.setMessage("用户名或密码错误");
}
model.addAttribute("message","用户名或密码错误");
return "login";
return r;
}
}
Loading

0 comments on commit 4d5b35d

Please sign in to comment.