66 changed files with 4057 additions and 10 deletions
@ -1,12 +1,31 @@ |
|||
# ---> Maven |
|||
HELP.md |
|||
target/ |
|||
pom.xml.tag |
|||
pom.xml.releaseBackup |
|||
pom.xml.versionsBackup |
|||
pom.xml.next |
|||
release.properties |
|||
dependency-reduced-pom.xml |
|||
buildNumber.properties |
|||
.mvn/timing.properties |
|||
.mvn/wrapper/maven-wrapper.jar |
|||
!.mvn/wrapper/maven-wrapper.jar |
|||
!**/src/main/** |
|||
!**/src/test/** |
|||
|
|||
### 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/ |
|||
|
|||
### VS Code ### |
|||
.vscode/ |
|||
|
|||
@ -0,0 +1,141 @@ |
|||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|||
<modelVersion>4.0.0</modelVersion> |
|||
<parent> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-parent</artifactId> |
|||
<version>2.1.3.RELEASE</version> |
|||
<relativePath/> <!-- lookup parent from repository --> |
|||
</parent> |
|||
<groupId>cn.redrock</groupId> |
|||
<artifactId>asset-manage</artifactId> |
|||
<version>0.0.1-SNAPSHOT</version> |
|||
<name>asset-manage</name> |
|||
<description>Demo project for Spring Boot</description> |
|||
|
|||
<properties> |
|||
<java.version>1.8</java.version> |
|||
<spring-boot.version>2.1.3.RELEASE</spring-boot.version> |
|||
<fastjson.version>1.2.55</fastjson.version> |
|||
<pagehelper-starter.version>1.2.5</pagehelper-starter.version> |
|||
<tk.mybatis.starter.version>2.0.2</tk.mybatis.starter.version> |
|||
</properties> |
|||
|
|||
<dependencies> |
|||
<dependency> |
|||
<groupId>org.projectlombok</groupId> |
|||
<artifactId>lombok</artifactId> |
|||
<scope>provided</scope> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-web</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.zaxxer</groupId> |
|||
<artifactId>HikariCP</artifactId> |
|||
<version>3.2.0</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>mysql</groupId> |
|||
<artifactId>mysql-connector-java</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.github.pagehelper</groupId> |
|||
<artifactId>pagehelper-spring-boot-starter</artifactId> |
|||
<version>1.2.5</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>tk.mybatis</groupId> |
|||
<artifactId>mapper-spring-boot-starter</artifactId> |
|||
<version>${tk.mybatis.starter.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>tk.mybatis</groupId> |
|||
<artifactId>mapper-generator</artifactId> |
|||
<version>1.0.0</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.mybatis.generator</groupId> |
|||
<artifactId>mybatis-generator-core</artifactId> |
|||
<version>1.3.6</version> |
|||
<scope>test</scope> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.alibaba</groupId> |
|||
<artifactId>fastjson</artifactId> |
|||
<version>1.2.54</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-test</artifactId> |
|||
<scope>test</scope> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.apache.poi</groupId> |
|||
<artifactId>poi</artifactId> |
|||
<version>3.17</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.apache.poi</groupId> |
|||
<artifactId>poi-ooxml</artifactId> |
|||
<version>3.17</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.apache.commons</groupId> |
|||
<artifactId>commons-lang3</artifactId> |
|||
<version>3.8.1</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>commons-collections</groupId> |
|||
<artifactId>commons-collections</artifactId> |
|||
<version>3.2.2</version> |
|||
</dependency> |
|||
|
|||
</dependencies> |
|||
<dependencyManagement> |
|||
<dependencies> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-web</artifactId> |
|||
<version>${spring-boot.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-autoconfigure</artifactId> |
|||
<version>${spring-boot.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-test</artifactId> |
|||
<version>${spring-boot.version}</version> |
|||
<scope>test</scope> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.projectlombok</groupId> |
|||
<artifactId>lombok</artifactId> |
|||
<version>${lombok.version}</version> |
|||
<scope>provided</scope> |
|||
</dependency> |
|||
</dependencies> |
|||
</dependencyManagement> |
|||
<build> |
|||
<plugins> |
|||
<plugin> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-maven-plugin</artifactId> |
|||
<configuration> |
|||
<finalName>asset-manage</finalName> |
|||
</configuration> |
|||
</plugin> |
|||
</plugins> |
|||
</build> |
|||
|
|||
</project> |
|||
@ -0,0 +1,76 @@ |
|||
create table am_user( |
|||
id int NOT NULL PRIMARY KEY AUTO_INCREMENT, |
|||
name varchar(20) NOT NULL, |
|||
nickname varchar(50), |
|||
password varchar(64) NOT NULL, |
|||
is_admin int NOT NULL, |
|||
phone varchar(11), |
|||
post varchar(30), |
|||
create_time datetime default CURRENT_TIMESTAMP, |
|||
update_time datetime NOT NULL, |
|||
unique key(name) |
|||
); |
|||
|
|||
create table am_token( |
|||
token varchar(32) NOT NULL PRIMARY KEY, |
|||
user_id int NOT NULL , |
|||
expire_time datetime NOT NULL, |
|||
update_time datetime NOT NULL |
|||
); |
|||
|
|||
create table am_public_asset( |
|||
id int NOT NULL PRIMARY KEY AUTO_INCREMENT, |
|||
code varchar(100) NOT NULL, |
|||
name varchar(200) NOT NULL, |
|||
model_num varchar(100) NOT NULL, |
|||
company varchar(200), |
|||
num int NOT NULL default 0, |
|||
position varchar(200), |
|||
user_id int NOT NULL, |
|||
description varchar(200), |
|||
create_time datetime default CURRENT_TIMESTAMP, |
|||
update_time datetime NOT NULL, |
|||
unique key(code) |
|||
); |
|||
|
|||
create table am_staff_asset( |
|||
id int NOT NULL PRIMARY KEY AUTO_INCREMENT, |
|||
name varchar(200) NOT NULL, |
|||
model_num varchar(100) NOT NULL, |
|||
num int NOT NULL default 0, |
|||
position varchar(200), |
|||
user_id int NOT NULL, |
|||
description varchar(200), |
|||
create_time datetime default CURRENT_TIMESTAMP, |
|||
update_time datetime NOT NULL, |
|||
unique key(name,user_id) |
|||
); |
|||
|
|||
create table am_material( |
|||
id int NOT NULL PRIMARY KEY AUTO_INCREMENT, |
|||
code varchar(100) NOT NULL, |
|||
value varchar(200) NOT NULL, |
|||
model_num varchar(100) NOT NULL, |
|||
packages varchar(100), |
|||
company varchar(200), |
|||
num int NOT NULL default 0, |
|||
position varchar(200), |
|||
description varchar(200), |
|||
base_num int default 10, |
|||
create_time datetime default CURRENT_TIMESTAMP, |
|||
update_time datetime NOT NULL, |
|||
unique key(code) |
|||
); |
|||
|
|||
create table am_material_log( |
|||
id int NOT NULL PRIMARY KEY AUTO_INCREMENT, |
|||
code varchar(100) NOT NULL, |
|||
num int NOT NULL, |
|||
status int NOT NULL default 0, -- -1:failed,0:no audit,1:success |
|||
user_id int NOT NULL, |
|||
description varchar(200), |
|||
operate int NOT NULL, -- 0:in,1:out |
|||
create_time datetime default CURRENT_TIMESTAMP |
|||
); |
|||
|
|||
--- 编码是否要变 |
|||
@ -0,0 +1,15 @@ |
|||
package cn.redrock.assetmanage; |
|||
|
|||
import org.springframework.boot.SpringApplication; |
|||
import org.springframework.boot.SpringBootConfiguration; |
|||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
|||
|
|||
@SpringBootConfiguration |
|||
@SpringBootApplication |
|||
public class AssetManageApplication { |
|||
|
|||
public static void main(String[] args) { |
|||
SpringApplication.run(AssetManageApplication.class, args); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
package cn.redrock.assetmanage.auth; |
|||
|
|||
import java.lang.annotation.*; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/7/23 9:17 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
@Target(ElementType.METHOD) |
|||
@Retention(RetentionPolicy.RUNTIME) |
|||
@Documented |
|||
public @interface Admin { |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
package cn.redrock.assetmanage.auth; |
|||
|
|||
import java.lang.annotation.*; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/6/27 13:01 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
@Target(ElementType.METHOD) |
|||
@Retention(RetentionPolicy.RUNTIME) |
|||
@Documented |
|||
public @interface AuthIgnore { |
|||
|
|||
} |
|||
@ -0,0 +1,73 @@ |
|||
package cn.redrock.assetmanage.auth; |
|||
|
|||
|
|||
import cn.redrock.assetmanage.common.ResponseCode; |
|||
import cn.redrock.assetmanage.common.Result; |
|||
import cn.redrock.assetmanage.entity.AmUser; |
|||
import cn.redrock.assetmanage.service.TokenService; |
|||
import cn.redrock.assetmanage.utils.StringUtil; |
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.http.MediaType; |
|||
import org.springframework.stereotype.Component; |
|||
import org.springframework.web.method.HandlerMethod; |
|||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import javax.servlet.http.HttpServletResponse; |
|||
import java.nio.charset.StandardCharsets; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/6/27 13:01 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
@Component |
|||
public class AuthInterceptor extends HandlerInterceptorAdapter { |
|||
@Autowired |
|||
private TokenService tokenService; |
|||
|
|||
@Override |
|||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
|||
AuthIgnore annotation; |
|||
Admin admin; |
|||
if(handler instanceof HandlerMethod) { |
|||
annotation = ((HandlerMethod) handler).getMethodAnnotation(AuthIgnore.class); |
|||
admin = ((HandlerMethod) handler).getMethodAnnotation(Admin.class); |
|||
}else{ |
|||
return true; |
|||
} |
|||
|
|||
if(annotation != null){ |
|||
return true; |
|||
} |
|||
|
|||
String token = TokenUtil.getRequestToken(request); |
|||
|
|||
if(StringUtil.isBlank(token)){ |
|||
responseError(response,ResponseCode.INVALID_USER_TOKEN); |
|||
return false; |
|||
} |
|||
AmUser user = tokenService.getUserByToken(token); |
|||
if(user == null){ |
|||
responseError(response,ResponseCode.EXPIRED_USER_TOKEN); |
|||
return false; |
|||
} |
|||
if(admin != null && user.getIsAdmin() != 1){ |
|||
responseError(response,ResponseCode.USER_NO_AUTHORITY); |
|||
return false; |
|||
} |
|||
request.setAttribute("currentUser", user); |
|||
return true; |
|||
} |
|||
|
|||
private void responseError(HttpServletResponse response,ResponseCode code) throws Exception { |
|||
Result msg = Result.error(code); |
|||
ObjectMapper objectMapper = new ObjectMapper(); |
|||
String content = objectMapper.writeValueAsString(msg); |
|||
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); |
|||
response.getOutputStream().write(content.getBytes(StandardCharsets.UTF_8)); |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
package cn.redrock.assetmanage.auth; |
|||
|
|||
import java.lang.annotation.*; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/6/27 13:26 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
@Target(ElementType.PARAMETER) |
|||
@Retention(RetentionPolicy.RUNTIME) |
|||
@Documented |
|||
public @interface CurrentUser { |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
package cn.redrock.assetmanage.auth; |
|||
|
|||
import cn.redrock.assetmanage.entity.AmUser; |
|||
import org.springframework.core.MethodParameter; |
|||
import org.springframework.web.bind.support.WebDataBinderFactory; |
|||
import org.springframework.web.context.request.NativeWebRequest; |
|||
import org.springframework.web.context.request.RequestAttributes; |
|||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; |
|||
import org.springframework.web.method.support.ModelAndViewContainer; |
|||
import org.springframework.web.multipart.support.MissingServletRequestPartException; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/6/27 13:39 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
public class CurrentUserResolver implements HandlerMethodArgumentResolver { |
|||
@Override |
|||
public boolean supportsParameter(MethodParameter parameter) { |
|||
return parameter.getParameterType().isAssignableFrom(AmUser.class) |
|||
&& parameter.hasParameterAnnotation(CurrentUser.class); |
|||
} |
|||
@Override |
|||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { |
|||
AmUser user = (AmUser) webRequest.getAttribute("currentUser", RequestAttributes.SCOPE_REQUEST); |
|||
if (user != null) { |
|||
return user; |
|||
} |
|||
throw new MissingServletRequestPartException("currentUser"); |
|||
} |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
package cn.redrock.assetmanage.auth; |
|||
|
|||
|
|||
import cn.redrock.assetmanage.utils.StringUtil; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/6/27 14:13 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
public class TokenUtil { |
|||
private static final String TOKEN = "token"; |
|||
public static String getRequestToken(HttpServletRequest request){ |
|||
String token = request.getHeader(TOKEN); |
|||
if(StringUtil.isBlank(token)){ |
|||
token = request.getParameter(TOKEN); |
|||
} |
|||
if(StringUtil.isBlank(token)){ |
|||
Object obj = request.getAttribute(TOKEN); |
|||
if(null!=obj){ |
|||
token=obj.toString(); |
|||
} |
|||
} |
|||
return token; |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
package cn.redrock.assetmanage.common; |
|||
|
|||
import lombok.Getter; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/7/24 10:43 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
public class Constants { |
|||
public static enum Status { |
|||
FAILED(-1), |
|||
NO_AUDIT(0), |
|||
SUCCESS(2); |
|||
|
|||
@Getter |
|||
private Integer status; |
|||
Status(Integer status) { |
|||
this.status = status; |
|||
} |
|||
} |
|||
public static enum Operate { |
|||
IN(0), |
|||
OUT(1); |
|||
|
|||
@Getter |
|||
private Integer operate; |
|||
Operate(Integer operate) { |
|||
this.operate = operate; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
package cn.redrock.assetmanage.common; |
|||
|
|||
public enum ResponseCode { |
|||
OK(0,"OK"), |
|||
USER_NOT_FIND(101,"用户不存在,请先添加"), |
|||
USER_EXISTED(102,"用户已存在"), |
|||
PASSWORD_ERROR(108,"密码错误,请重新输入"), |
|||
USER_OR_PASSWORD_ERROR(110,"用户名或密码错误,请重新输入"), |
|||
|
|||
INVALID_USER_TOKEN(10001,"无效的token"), |
|||
EXPIRED_USER_TOKEN(10002,"token已经过期"), |
|||
USER_NO_AUTHORITY(10003,"该用户没有权限"), |
|||
ASSET_EXISTED(10004,"该资产已存在"), |
|||
ASSET_NO_EXISTED(10005,"该资产不存在"), |
|||
EXCEL_PARSE_ERROR(10006,"Excel解析错误"), |
|||
ASSET_BATCH_ADD_FAIL(10007,"资产批量添加失败"), |
|||
ASSET_SUB_FAIL(10008,"出库失败"), |
|||
UNKNOWN_ERROR(20003, "UNKNOWN_ERROR"); |
|||
|
|||
private Integer code; |
|||
|
|||
private String msg; |
|||
|
|||
ResponseCode(Integer code, String msg) { |
|||
this.code = code; |
|||
this.msg = msg; |
|||
} |
|||
|
|||
public Integer getCode() { |
|||
return code; |
|||
} |
|||
|
|||
public String getMsg() { |
|||
return msg; |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
package cn.redrock.assetmanage.common; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonInclude; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
@JsonInclude(JsonInclude.Include.NON_NULL) |
|||
@Getter |
|||
@Setter |
|||
public class Result<T> implements Serializable { |
|||
private static final long serialVersionUID = 2633283546876721434L; |
|||
private Integer code; |
|||
private String msg; |
|||
private T data; |
|||
|
|||
public static Result ok(Object data){ |
|||
Result result = new Result(); |
|||
result.setCode(ResponseCode.OK.getCode()); |
|||
result.setMsg(ResponseCode.OK.getMsg()); |
|||
result.setData(data); |
|||
return result; |
|||
} |
|||
|
|||
public static Result ok(){ |
|||
return ok(null); |
|||
} |
|||
|
|||
public static Result error(Integer code,String msg){ |
|||
Result result = new Result(); |
|||
result.setCode(code); |
|||
result.setMsg(msg); |
|||
return result; |
|||
} |
|||
|
|||
public static Result error(ResponseCode responseCode){ |
|||
Result result = new Result(); |
|||
result.setCode(responseCode.getCode()); |
|||
result.setMsg(responseCode.getMsg()); |
|||
return result; |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
package cn.redrock.assetmanage.config; |
|||
|
|||
import cn.redrock.assetmanage.auth.AuthInterceptor; |
|||
import cn.redrock.assetmanage.auth.CurrentUserResolver; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; |
|||
import org.springframework.web.servlet.config.annotation.InterceptorRegistration; |
|||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
|||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/6/27 13:41 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
@Configuration |
|||
public class WebMvcConfig extends WebMvcConfigurerAdapter { |
|||
|
|||
@Bean |
|||
public AuthInterceptor myAuthInterceptor() { |
|||
return new AuthInterceptor(); |
|||
} |
|||
|
|||
@Override |
|||
public void addInterceptors(InterceptorRegistry registry) { |
|||
InterceptorRegistration ir = registry.addInterceptor(myAuthInterceptor()); |
|||
ir.addPathPatterns("/**"); |
|||
} |
|||
@Override |
|||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) { |
|||
argumentResolvers.add(currentUserResolver()); |
|||
super.addArgumentResolvers(argumentResolvers); |
|||
} |
|||
@Bean |
|||
public CurrentUserResolver currentUserResolver() { |
|||
return new CurrentUserResolver(); |
|||
} |
|||
} |
|||
@ -0,0 +1,208 @@ |
|||
package cn.redrock.assetmanage.controller; |
|||
|
|||
import cn.redrock.assetmanage.auth.Admin; |
|||
import cn.redrock.assetmanage.auth.CurrentUser; |
|||
import cn.redrock.assetmanage.common.Constants; |
|||
import cn.redrock.assetmanage.common.ResponseCode; |
|||
import cn.redrock.assetmanage.common.Result; |
|||
import cn.redrock.assetmanage.dto.Material; |
|||
import cn.redrock.assetmanage.entity.AmMaterial; |
|||
import cn.redrock.assetmanage.entity.AmMaterialLog; |
|||
import cn.redrock.assetmanage.entity.AmUser; |
|||
import cn.redrock.assetmanage.service.MaterialLogService; |
|||
import cn.redrock.assetmanage.service.MaterialService; |
|||
import cn.redrock.assetmanage.utils.DateUtil; |
|||
import cn.redrock.assetmanage.utils.ExcelUtils; |
|||
import cn.redrock.assetmanage.utils.StringUtil; |
|||
import com.github.pagehelper.PageInfo; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.format.annotation.DateTimeFormat; |
|||
import org.springframework.web.bind.annotation.*; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import javax.servlet.http.HttpServletResponse; |
|||
import javax.validation.Valid; |
|||
import java.util.ArrayList; |
|||
import java.util.Date; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/7/23 16:55 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("/material") |
|||
public class MaterialController { |
|||
@Autowired |
|||
private MaterialService materialService; |
|||
@Autowired |
|||
private MaterialLogService materialLogService; |
|||
|
|||
private AmMaterialLog buildLog(Integer userId, Constants.Operate operate, Constants.Status status, Material material){ |
|||
if(StringUtil.isNotBlank(material.getCode()) && material.getNum() != null){ |
|||
AmMaterialLog materialLog = new AmMaterialLog(); |
|||
materialLog.setCode(material.getCode()); |
|||
materialLog.setOperate(operate.getOperate()); |
|||
materialLog.setCreateTime(new Date()); |
|||
materialLog.setNum(material.getNum()); |
|||
materialLog.setStatus(status.getStatus()); |
|||
materialLog.setDescription(material.getDescription()); |
|||
materialLog.setUserId(userId); |
|||
return materialLog; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
private List<AmMaterialLog> buildBatchLog(Integer userId,Constants.Operate operate, Constants.Status status,List<Material> materials){ |
|||
List<AmMaterialLog> materialLogs = new ArrayList<>(); |
|||
for(Material material : materials){ |
|||
AmMaterialLog log = buildLog(userId,operate,status,material); |
|||
if(log != null){ |
|||
materialLogs.add(log); |
|||
} |
|||
} |
|||
return materialLogs; |
|||
} |
|||
|
|||
@Admin |
|||
@PostMapping("/add") |
|||
public Result addMaterial(@CurrentUser AmUser user,@Valid @RequestBody Material material) { |
|||
if(!materialService.add(material)){ |
|||
materialLogService.writeLog(buildLog(user.getId(), Constants.Operate.IN, Constants.Status.FAILED,material)); |
|||
return Result.error(ResponseCode.ASSET_EXISTED); |
|||
} |
|||
materialLogService.writeLog(buildLog(user.getId(),Constants.Operate.IN,Constants.Status.NO_AUDIT,material)); |
|||
return Result.ok(); |
|||
} |
|||
|
|||
@Admin |
|||
@PostMapping("/batch/add") |
|||
public Result batchAddMaterial(@CurrentUser AmUser user,@RequestParam("file") MultipartFile file,@RequestParam(name = "isOverride",required = false) Boolean isOverride) { |
|||
List<Material> list = ExcelUtils.readExcel(file,Material.class); |
|||
if(list == null || list.isEmpty()){ |
|||
return Result.error(ResponseCode.EXCEL_PARSE_ERROR); |
|||
} |
|||
boolean ret; |
|||
if(isOverride != null && isOverride){ |
|||
ret = materialService.batchAdd(list,true); |
|||
}else{ |
|||
ret = materialService.batchAdd(list,false); |
|||
} |
|||
if(!ret){ |
|||
materialLogService.batchWriteLog(buildBatchLog(user.getId(),Constants.Operate.IN, Constants.Status.FAILED,list)); |
|||
return Result.error(ResponseCode.ASSET_BATCH_ADD_FAIL); |
|||
} |
|||
materialLogService.batchWriteLog(buildBatchLog(user.getId(),Constants.Operate.IN,Constants.Status.NO_AUDIT,list)); |
|||
return Result.ok(); |
|||
} |
|||
|
|||
@PostMapping("/sub") |
|||
public Result subMaterial(@CurrentUser AmUser user,@RequestBody Material material) { |
|||
if(user.getIsAdmin() == 1){ |
|||
if(!materialService.sub(material)){ |
|||
materialLogService.writeLog(buildLog(user.getId(), Constants.Operate.OUT, Constants.Status.FAILED,material)); |
|||
return Result.error(ResponseCode.ASSET_SUB_FAIL); |
|||
}else{ |
|||
materialLogService.writeLog(buildLog(user.getId(), Constants.Operate.OUT, Constants.Status.SUCCESS,material)); |
|||
} |
|||
}else{ |
|||
materialLogService.writeLog(buildLog(user.getId(),Constants.Operate.OUT,Constants.Status.NO_AUDIT,material)); |
|||
} |
|||
return Result.ok(); |
|||
} |
|||
|
|||
@PostMapping("/batch/sub") |
|||
public Result batchSubMaterial(@CurrentUser AmUser user,@RequestParam("file") MultipartFile file) { |
|||
List<Material> list = ExcelUtils.readExcel(file,Material.class); |
|||
if(list == null || list.isEmpty()){ |
|||
return Result.error(ResponseCode.EXCEL_PARSE_ERROR); |
|||
} |
|||
List<Material> successMaterial = new ArrayList<>(); |
|||
List<Material> failMaterial = new ArrayList<>(); |
|||
if(user.getIsAdmin() == 1){ |
|||
materialService.batchSub(list,successMaterial,failMaterial); |
|||
if(!successMaterial.isEmpty() && failMaterial.isEmpty()){ |
|||
materialLogService.batchWriteLog(buildBatchLog(user.getId(),Constants.Operate.OUT, Constants.Status.SUCCESS,list)); |
|||
}else{ |
|||
materialLogService.batchWriteLog(buildBatchLog(user.getId(),Constants.Operate.OUT, Constants.Status.FAILED,failMaterial)); |
|||
materialLogService.batchWriteLog(buildBatchLog(user.getId(),Constants.Operate.OUT, Constants.Status.SUCCESS,successMaterial)); |
|||
return Result.ok(failMaterial); |
|||
} |
|||
}else{ |
|||
materialLogService.batchWriteLog(buildBatchLog(user.getId(),Constants.Operate.OUT, Constants.Status.NO_AUDIT,list)); |
|||
} |
|||
return Result.ok(); |
|||
} |
|||
|
|||
@Admin |
|||
@PostMapping("/audit") |
|||
public Result auditMaterial(@Valid @RequestBody List<Material> list) { |
|||
List<Material> successMaterial = new ArrayList<>(); |
|||
List<Material> failMaterial = new ArrayList<>(); |
|||
materialService.batchSub(list,successMaterial,failMaterial); |
|||
if(failMaterial.isEmpty()){ |
|||
materialLogService.updateLog(list,Constants.Status.SUCCESS.getStatus()); |
|||
}else{ |
|||
materialLogService.updateLog(successMaterial,Constants.Status.SUCCESS.getStatus()); |
|||
materialLogService.updateLog(failMaterial,Constants.Status.FAILED.getStatus()); |
|||
return Result.ok(failMaterial); |
|||
} |
|||
return Result.ok(); |
|||
} |
|||
|
|||
@Admin |
|||
@PostMapping("/edit") |
|||
public Result editMaterial(@Valid @RequestBody Material material) { |
|||
if(!materialService.update(material)){ |
|||
return Result.error(ResponseCode.ASSET_NO_EXISTED); |
|||
} |
|||
return Result.ok(); |
|||
} |
|||
|
|||
@Admin |
|||
@DeleteMapping("/delete/{code}") |
|||
public Result deleteMaterial(@PathVariable("code") String code) { |
|||
if(!materialService.delete(code)){ |
|||
return Result.error(ResponseCode.ASSET_NO_EXISTED); |
|||
} |
|||
return Result.ok(); |
|||
} |
|||
|
|||
@GetMapping("/search") |
|||
public Result searchMaterial(String field,String content,Integer pageNum, Integer pageSize) { |
|||
return Result.ok(PageInfo.of(materialService.search(field,content,pageNum,pageSize))); |
|||
} |
|||
|
|||
@GetMapping("/export") |
|||
public void exportMaterial(String field, String content, HttpServletResponse response) { |
|||
List<AmMaterial> list = materialService.search(field,content,null,null); |
|||
String time = DateUtil.dateToStr(new Date(),"yyyyMMddHHmmss"); |
|||
String fileName = "物料_"+time+".xlsx"; |
|||
ExcelUtils.buildExcelDocument(fileName,ExcelUtils.writeExcel(list,AmMaterial.class),response); |
|||
} |
|||
|
|||
@PostMapping("/export/fail") |
|||
public void exportFailMaterial(@RequestBody List<AmMaterial> list, HttpServletResponse response) { |
|||
String time = DateUtil.dateToStr(new Date(),"yyyyMMddHHmmss"); |
|||
String fileName = "出库失败物料_"+time+".xlsx"; |
|||
ExcelUtils.buildExcelDocument(fileName,ExcelUtils.writeExcel(list,AmMaterial.class),response); |
|||
} |
|||
|
|||
@GetMapping("/log") |
|||
public Result queryMaterialLog(@RequestParam Integer operate,@RequestParam Integer status, |
|||
@RequestParam(required = false) String field, |
|||
@RequestParam(required = false) String content, |
|||
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startTm, |
|||
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTm, |
|||
Integer pageNum, Integer pageSize) { |
|||
return Result.ok(materialLogService.queryLog(operate,status,field,content,startTm,endTm,pageNum,pageSize)); |
|||
} |
|||
|
|||
@GetMapping("/warn") |
|||
public Result queryMaterialWarn(Integer pageNum, Integer pageSize) { |
|||
return Result.ok(materialService.warn(pageNum,pageSize)); |
|||
} |
|||
} |
|||
@ -0,0 +1,68 @@ |
|||
package cn.redrock.assetmanage.controller; |
|||
|
|||
import cn.redrock.assetmanage.common.ResponseCode; |
|||
import cn.redrock.assetmanage.common.Result; |
|||
import cn.redrock.assetmanage.dto.PublicAsset; |
|||
import cn.redrock.assetmanage.entity.AmPublicAsset; |
|||
import cn.redrock.assetmanage.service.PublicAssetService; |
|||
import cn.redrock.assetmanage.utils.DateUtil; |
|||
import cn.redrock.assetmanage.utils.ExcelUtils; |
|||
import com.github.pagehelper.PageInfo; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import javax.servlet.http.HttpServletResponse; |
|||
import javax.validation.Valid; |
|||
import java.util.Date; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/7/23 10:50 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("/asset/public") |
|||
public class PublicAssetController { |
|||
@Autowired |
|||
private PublicAssetService publicAssetService; |
|||
|
|||
@PostMapping("/add") |
|||
public Result addAsset(@Valid @RequestBody PublicAsset asset) { |
|||
if(!publicAssetService.add(asset)){ |
|||
return Result.error(ResponseCode.ASSET_EXISTED); |
|||
} |
|||
return Result.ok(); |
|||
} |
|||
|
|||
@PostMapping("/edit") |
|||
public Result editAsset(@Valid @RequestBody PublicAsset asset) { |
|||
if(!publicAssetService.update(asset)){ |
|||
return Result.error(ResponseCode.ASSET_NO_EXISTED); |
|||
} |
|||
return Result.ok(); |
|||
} |
|||
|
|||
@DeleteMapping("/delete/{code}") |
|||
public Result deleteAsset(@PathVariable("code") String code) { |
|||
if(!publicAssetService.delete(code)){ |
|||
return Result.error(ResponseCode.ASSET_NO_EXISTED); |
|||
} |
|||
return Result.ok(); |
|||
} |
|||
|
|||
@GetMapping("/search") |
|||
public Result searchAsset(String field,String content,Integer pageNum, Integer pageSize) { |
|||
return Result.ok(PageInfo.of(publicAssetService.search(field,content,pageNum,pageSize))); |
|||
} |
|||
|
|||
@GetMapping("/export") |
|||
public void exportAsset(String field, String content, HttpServletResponse response) { |
|||
List<AmPublicAsset> list = publicAssetService.search(field,content,null,null); |
|||
String time = DateUtil.dateToStr(new Date(),"yyyyMMddHHmmss"); |
|||
String fileName = "公共资产_"+time+".xlsx"; |
|||
ExcelUtils.buildExcelDocument(fileName,ExcelUtils.writeExcel(list,AmPublicAsset.class),response); |
|||
} |
|||
} |
|||
@ -0,0 +1,88 @@ |
|||
package cn.redrock.assetmanage.controller; |
|||
|
|||
import cn.redrock.assetmanage.auth.Admin; |
|||
import cn.redrock.assetmanage.auth.CurrentUser; |
|||
import cn.redrock.assetmanage.common.ResponseCode; |
|||
import cn.redrock.assetmanage.common.Result; |
|||
import cn.redrock.assetmanage.dto.Asset; |
|||
import cn.redrock.assetmanage.entity.AmStaffAsset; |
|||
import cn.redrock.assetmanage.entity.AmUser; |
|||
import cn.redrock.assetmanage.service.StaffAssetService; |
|||
import cn.redrock.assetmanage.utils.DateUtil; |
|||
import cn.redrock.assetmanage.utils.ExcelUtils; |
|||
import com.github.pagehelper.PageInfo; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import javax.servlet.http.HttpServletResponse; |
|||
import javax.validation.Valid; |
|||
import java.util.Date; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/7/23 14:15 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("/asset/staff") |
|||
public class StaffAssetController { |
|||
@Autowired |
|||
private StaffAssetService staffAssetService; |
|||
|
|||
@PostMapping("/add") |
|||
public Result addAsset(@CurrentUser AmUser user,@Valid @RequestBody Asset asset) { |
|||
asset.setUserId(user.getId()); |
|||
if(!staffAssetService.add(asset)){ |
|||
return Result.error(ResponseCode.ASSET_EXISTED); |
|||
} |
|||
return Result.ok(); |
|||
} |
|||
|
|||
@PostMapping("/edit") |
|||
public Result editAsset(@CurrentUser AmUser user,@Valid @RequestBody Asset asset) { |
|||
asset.setUserId(user.getId()); |
|||
if(!staffAssetService.update(asset)){ |
|||
return Result.error(ResponseCode.ASSET_NO_EXISTED); |
|||
} |
|||
return Result.ok(); |
|||
} |
|||
|
|||
@DeleteMapping("/delete/{id}") |
|||
public Result deleteAsset(@PathVariable("id") Integer id) { |
|||
if(!staffAssetService.delete(id)){ |
|||
return Result.error(ResponseCode.ASSET_NO_EXISTED); |
|||
} |
|||
return Result.ok(); |
|||
} |
|||
|
|||
@GetMapping("/search") |
|||
public Result searchAsset(@CurrentUser AmUser user,String field, String content, Integer pageNum, Integer pageSize) { |
|||
return Result.ok(PageInfo.of(staffAssetService.search(user.getId(),field,content,pageNum,pageSize))); |
|||
} |
|||
|
|||
@GetMapping("/export") |
|||
public void exportAsset(@CurrentUser AmUser user,String field, String content, HttpServletResponse response) { |
|||
List<AmStaffAsset> list = staffAssetService.search(user.getId(),field,content,null,null); |
|||
String time = DateUtil.dateToStr(new Date(),"yyyyMMddHHmmss"); |
|||
String fileName = user.getNickname()+"_"+time+".xlsx"; |
|||
ExcelUtils.buildExcelDocument(fileName,ExcelUtils.writeExcel(list,AmStaffAsset.class),response); |
|||
} |
|||
|
|||
@Admin |
|||
@GetMapping("/search/all") |
|||
public Result searchAllAsset(String field, String content, Integer pageNum, Integer pageSize) { |
|||
return Result.ok(PageInfo.of(staffAssetService.search(null,field,content,pageNum,pageSize))); |
|||
} |
|||
|
|||
@Admin |
|||
@GetMapping("/export/all") |
|||
public void exportAllAsset(String field, String content, HttpServletResponse response) { |
|||
List<AmStaffAsset> list = staffAssetService.search(null,field,content,null,null); |
|||
String time = DateUtil.dateToStr(new Date(),"yyyyMMddHHmmss"); |
|||
String fileName = "员工资产_"+time+".xlsx"; |
|||
ExcelUtils.buildExcelDocument(fileName,ExcelUtils.writeExcel(list,AmStaffAsset.class),response); |
|||
} |
|||
} |
|||
@ -0,0 +1,125 @@ |
|||
package cn.redrock.assetmanage.controller; |
|||
|
|||
import cn.redrock.assetmanage.auth.Admin; |
|||
import cn.redrock.assetmanage.auth.AuthIgnore; |
|||
import cn.redrock.assetmanage.auth.CurrentUser; |
|||
import cn.redrock.assetmanage.auth.TokenUtil; |
|||
import cn.redrock.assetmanage.common.ResponseCode; |
|||
import cn.redrock.assetmanage.common.Result; |
|||
import cn.redrock.assetmanage.dto.UserBase; |
|||
import cn.redrock.assetmanage.dto.UserInfo; |
|||
import cn.redrock.assetmanage.dto.UserNewPassword; |
|||
import cn.redrock.assetmanage.entity.AmUser; |
|||
import cn.redrock.assetmanage.service.UserService; |
|||
import cn.redrock.assetmanage.utils.UUIDUtil; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import javax.validation.Valid; |
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/7/22 16:12 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("/user") |
|||
public class UserController { |
|||
@Autowired |
|||
private UserService userService; |
|||
|
|||
@AuthIgnore |
|||
@PostMapping("/create") |
|||
public Result create(@Valid @RequestBody UserInfo user) { |
|||
if(!userService.createUser(user)){ |
|||
return Result.error(ResponseCode.USER_EXISTED); |
|||
} |
|||
return Result.ok(); |
|||
} |
|||
|
|||
@Admin |
|||
@PostMapping("/add") |
|||
public Result add(@Valid @RequestBody UserInfo user) { |
|||
if(!userService.createUser(user)){ |
|||
return Result.error(ResponseCode.USER_EXISTED); |
|||
} |
|||
return Result.ok(); |
|||
} |
|||
|
|||
@AuthIgnore |
|||
@PostMapping("/login") |
|||
public Result login(@Valid @RequestBody UserBase user) { |
|||
Map<String,Object> map = userService.authUser(user); |
|||
if(map == null){ |
|||
return Result.error(ResponseCode.USER_OR_PASSWORD_ERROR); |
|||
} |
|||
return Result.ok(map); |
|||
} |
|||
|
|||
@GetMapping("/info") |
|||
public Result getInfo (@CurrentUser AmUser user) { |
|||
return Result.ok(user); |
|||
} |
|||
|
|||
@PostMapping("/logout") |
|||
public Result logout(HttpServletRequest request) { |
|||
String token = TokenUtil.getRequestToken(request); |
|||
userService.logout(token); |
|||
return Result.ok(); |
|||
} |
|||
|
|||
@PostMapping("/modify/password") |
|||
public Result modifyPassword (@CurrentUser AmUser user,@Valid @RequestBody UserNewPassword password) { |
|||
UserInfo userInfo = new UserInfo(); |
|||
userInfo.setPassword(userService.encode(password.getNewPassword())); |
|||
if(!userService.editUser(user.getId(),userInfo)){ |
|||
return Result.error(ResponseCode.USER_NOT_FIND); |
|||
} |
|||
return Result.ok(); |
|||
} |
|||
|
|||
@Admin |
|||
@PostMapping("/reset/password/{id}") |
|||
public Result resetPassword (@PathVariable("id") Integer userId) { |
|||
UserInfo userInfo = new UserInfo(); |
|||
String password = UUIDUtil.generateShortUUID(); |
|||
userInfo.setPassword(userService.encode(password)); |
|||
if(!userService.editUser(userId,userInfo)){ |
|||
return Result.error(ResponseCode.USER_NOT_FIND); |
|||
} |
|||
Map<String,String> map = new HashMap<>(); |
|||
map.put("password",password); |
|||
return Result.ok(map); |
|||
} |
|||
|
|||
@PostMapping("/edit") |
|||
public Result edit(@CurrentUser AmUser user,Integer userId, @RequestBody UserInfo userInfo) { |
|||
if(userId == null){ |
|||
userId = user.getId(); |
|||
} |
|||
if(!userService.editUser(userId,userInfo)){ |
|||
return Result.error(ResponseCode.USER_EXISTED); |
|||
} |
|||
return Result.ok(); |
|||
} |
|||
|
|||
@Admin |
|||
@DeleteMapping("/delete/{id}") |
|||
public Result delete(@PathVariable("id")Integer id) { |
|||
if(!userService.deleteUser(id)){ |
|||
return Result.error(ResponseCode.USER_NOT_FIND); |
|||
} |
|||
return Result.ok(); |
|||
} |
|||
|
|||
@Admin |
|||
@GetMapping("/search") |
|||
public Result search(String field, String content,Integer pageNum,Integer pageSize) { |
|||
return Result.ok(userService.search(field,content,pageNum,pageSize)); |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
package cn.redrock.assetmanage.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import javax.validation.constraints.NotNull; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/7/23 10:07 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
@Data |
|||
public class Asset { |
|||
@NotBlank |
|||
private String name; |
|||
@NotBlank |
|||
private String modelNum; |
|||
@NotNull |
|||
private Integer num; |
|||
|
|||
private String position; |
|||
|
|||
private Integer userId; |
|||
|
|||
private String description; |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
package cn.redrock.assetmanage.dto; |
|||
|
|||
import cn.redrock.assetmanage.utils.ExcelColumn; |
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import javax.validation.constraints.NotNull; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/7/23 15:46 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
@Data |
|||
public class Material { |
|||
private Integer id; |
|||
@ExcelColumn(value = "物料编号", col = 1) |
|||
@NotBlank |
|||
private String code; |
|||
|
|||
@ExcelColumn(value = "物料数值", col = 3) |
|||
@NotBlank |
|||
private String value; |
|||
|
|||
@ExcelColumn(value = "物料型号", col = 4) |
|||
@NotBlank |
|||
private String modelNum; |
|||
|
|||
@ExcelColumn(value = "物料封装", col = 5) |
|||
@NotBlank |
|||
private String packages; |
|||
|
|||
@ExcelColumn(value = "公司名称", col = 6) |
|||
private String company; |
|||
|
|||
@ExcelColumn(value = "物料数量", col = 2) |
|||
@NotNull |
|||
private Integer num; |
|||
|
|||
@ExcelColumn(value = "物料位置", col = 7) |
|||
@NotBlank |
|||
private String position; |
|||
|
|||
@ExcelColumn(value = "备注", col = 8) |
|||
private String description; |
|||
|
|||
private Integer baseNum; |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
package cn.redrock.assetmanage.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/7/23 10:10 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
@Data |
|||
public class PublicAsset extends Asset { |
|||
@NotBlank |
|||
private String code; |
|||
private String company; |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
package cn.redrock.assetmanage.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/6/15 15:16 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
@Data |
|||
public class UserBase { |
|||
@NotBlank |
|||
private String name; |
|||
@NotBlank |
|||
private String password; |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
package cn.redrock.assetmanage.dto; |
|||
|
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import javax.validation.constraints.Pattern; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/7/22 16:10 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
@Getter |
|||
@Setter |
|||
public class UserInfo extends UserBase { |
|||
@Pattern(regexp="^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9])|(16[6]))\\d{8}$",message="phone number pattern error") |
|||
private String phone; |
|||
@NotBlank |
|||
private String nickname; |
|||
private String post; |
|||
private Integer isAdmin = 0; |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
package cn.redrock.assetmanage.dto; |
|||
|
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/6/15 16:17 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
@Getter |
|||
@Setter |
|||
public class UserNewPassword { |
|||
@NotBlank |
|||
private String newPassword; |
|||
} |
|||
@ -0,0 +1,55 @@ |
|||
package cn.redrock.assetmanage.entity; |
|||
|
|||
import cn.redrock.assetmanage.utils.ExcelColumn; |
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.fasterxml.jackson.annotation.JsonInclude; |
|||
import lombok.Data; |
|||
|
|||
import javax.persistence.Column; |
|||
import javax.persistence.Id; |
|||
import javax.persistence.Table; |
|||
import java.util.Date; |
|||
|
|||
@Data |
|||
@JsonInclude(JsonInclude.Include.NON_NULL) |
|||
@Table(name = "am_material") |
|||
public class AmMaterial { |
|||
@Id |
|||
private Integer id; |
|||
|
|||
@ExcelColumn(value = "物料编号", col = 1) |
|||
private String code; |
|||
|
|||
@ExcelColumn(value = "物料数值", col = 3) |
|||
private String value; |
|||
|
|||
@ExcelColumn(value = "物料型号", col = 4) |
|||
@Column(name = "model_num") |
|||
private String modelNum; |
|||
|
|||
@ExcelColumn(value = "物料封装", col = 5) |
|||
private String packages; |
|||
|
|||
@ExcelColumn(value = "公司名称", col = 6) |
|||
private String company; |
|||
|
|||
@ExcelColumn(value = "物料数量", col = 2) |
|||
private Integer num; |
|||
|
|||
@ExcelColumn(value = "物料位置", col = 7) |
|||
private String position; |
|||
|
|||
@ExcelColumn(value = "备注", col = 8) |
|||
private String description; |
|||
|
|||
@Column(name = "base_num") |
|||
private Integer baseNum = 10; |
|||
|
|||
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") |
|||
@Column(name = "create_time",updatable=false) |
|||
private Date createTime; |
|||
|
|||
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") |
|||
@Column(name = "update_time") |
|||
private Date updateTime = new Date(); |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
package cn.redrock.assetmanage.entity; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.fasterxml.jackson.annotation.JsonInclude; |
|||
import lombok.Data; |
|||
|
|||
import javax.persistence.Column; |
|||
import javax.persistence.GeneratedValue; |
|||
import javax.persistence.Id; |
|||
import javax.persistence.Table; |
|||
import java.util.Date; |
|||
|
|||
@Data |
|||
@JsonInclude(JsonInclude.Include.NON_NULL) |
|||
@Table(name = "am_material_log") |
|||
public class AmMaterialLog { |
|||
@Id |
|||
@GeneratedValue(generator = "JDBC") |
|||
private Integer id; |
|||
|
|||
private String code; |
|||
|
|||
private Integer num; |
|||
|
|||
private Integer status; |
|||
|
|||
@Column(name = "user_id") |
|||
private Integer userId; |
|||
|
|||
private String description; |
|||
|
|||
private Integer operate; |
|||
|
|||
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") |
|||
@Column(name = "create_time",updatable=false) |
|||
private Date createTime; |
|||
} |
|||
@ -0,0 +1,56 @@ |
|||
package cn.redrock.assetmanage.entity; |
|||
|
|||
import cn.redrock.assetmanage.utils.ExcelColumn; |
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.fasterxml.jackson.annotation.JsonInclude; |
|||
import lombok.Data; |
|||
|
|||
import javax.persistence.Column; |
|||
import javax.persistence.Id; |
|||
import javax.persistence.Table; |
|||
import java.util.Date; |
|||
|
|||
@Data |
|||
@JsonInclude(JsonInclude.Include.NON_NULL) |
|||
@Table(name = "am_public_asset") |
|||
public class AmPublicAsset { |
|||
@Id |
|||
private Integer id; |
|||
|
|||
@ExcelColumn(value = "资产编号", col = 1) |
|||
private String code; |
|||
|
|||
@ExcelColumn(value = "资产名称", col = 2) |
|||
private String name; |
|||
|
|||
@ExcelColumn(value = "资产型号", col = 3) |
|||
@Column(name = "model_num") |
|||
private String modelNum; |
|||
|
|||
@ExcelColumn(value = "公司名称", col = 4) |
|||
private String company; |
|||
|
|||
@ExcelColumn(value = "资产数量", col = 5) |
|||
private Integer num; |
|||
|
|||
@ExcelColumn(value = "资产位置", col = 6) |
|||
private String position; |
|||
|
|||
@Column(name = "user_id") |
|||
private Integer userId; |
|||
|
|||
@ExcelColumn(value = "负责人", col = 7) |
|||
@Column(name = "user_name") |
|||
private String userName; // for internal
|
|||
|
|||
@ExcelColumn(value = "备注", col = 8) |
|||
private String description; |
|||
|
|||
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") |
|||
@Column(name = "create_time",updatable=false) |
|||
private Date createTime; |
|||
|
|||
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") |
|||
@Column(name = "update_time") |
|||
private Date updateTime = new Date(); |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
package cn.redrock.assetmanage.entity; |
|||
|
|||
import cn.redrock.assetmanage.utils.ExcelColumn; |
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.fasterxml.jackson.annotation.JsonInclude; |
|||
import lombok.Data; |
|||
|
|||
import javax.persistence.Column; |
|||
import javax.persistence.GeneratedValue; |
|||
import javax.persistence.Id; |
|||
import javax.persistence.Table; |
|||
import java.util.Date; |
|||
|
|||
@Data |
|||
@JsonInclude(JsonInclude.Include.NON_NULL) |
|||
@Table(name = "am_staff_asset") |
|||
public class AmStaffAsset { |
|||
@Id |
|||
@GeneratedValue(generator = "JDBC") |
|||
private Integer id; |
|||
|
|||
@ExcelColumn(value = "资产名称", col = 2) |
|||
private String name; |
|||
|
|||
@ExcelColumn(value = "资产型号", col = 3) |
|||
@Column(name = "model_num") |
|||
private String modelNum; |
|||
|
|||
@ExcelColumn(value = "资产数量", col = 4) |
|||
private Integer num; |
|||
|
|||
@ExcelColumn(value = "资产位置", col = 5) |
|||
private String position; |
|||
|
|||
@Column(name = "user_id") |
|||
private Integer userId; |
|||
|
|||
@ExcelColumn(value = "员工姓名", col = 1) |
|||
@Column(name = "user_name") |
|||
private String userName; |
|||
|
|||
@ExcelColumn(value = "备注", col = 6) |
|||
private String description; |
|||
|
|||
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") |
|||
@Column(name = "create_time",updatable=false) |
|||
private Date createTime; |
|||
|
|||
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") |
|||
@Column(name = "update_time") |
|||
private Date updateTime = new Date(); |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
package cn.redrock.assetmanage.entity; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonInclude; |
|||
import lombok.Data; |
|||
|
|||
import javax.persistence.Column; |
|||
import javax.persistence.Id; |
|||
import javax.persistence.Table; |
|||
import java.util.Date; |
|||
|
|||
@Data |
|||
@JsonInclude(JsonInclude.Include.NON_NULL) |
|||
@Table(name = "am_token") |
|||
public class AmToken { |
|||
@Id |
|||
private String token; |
|||
|
|||
@Column(name = "user_id") |
|||
private Integer userId; |
|||
|
|||
@Column(name = "expire_time") |
|||
private Date expireTime; |
|||
|
|||
@Column(name = "update_time") |
|||
private Date updateTime = new Date(); |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
package cn.redrock.assetmanage.entity; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.annotation.JsonInclude; |
|||
import lombok.Data; |
|||
|
|||
import javax.persistence.*; |
|||
import java.util.Date; |
|||
|
|||
@Data |
|||
@JsonInclude(JsonInclude.Include.NON_NULL) |
|||
@Table(name = "am_user") |
|||
public class AmUser { |
|||
@Id |
|||
@GeneratedValue(generator = "JDBC",strategy = GenerationType.IDENTITY) |
|||
private Integer id; |
|||
|
|||
private String name; |
|||
|
|||
private String nickname; |
|||
|
|||
@JsonIgnore |
|||
private String password; |
|||
|
|||
@Column(name = "is_admin") |
|||
private Integer isAdmin; |
|||
|
|||
private String phone; |
|||
|
|||
private String post; |
|||
|
|||
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") |
|||
@Column(name = "create_time",updatable=false) |
|||
private Date createTime; |
|||
|
|||
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") |
|||
@Column(name = "update_time") |
|||
private Date updateTime = new Date(); |
|||
} |
|||
@ -0,0 +1,44 @@ |
|||
package cn.redrock.assetmanage.entity; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import lombok.Data; |
|||
|
|||
import javax.persistence.Column; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/7/23 16:21 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
@Data |
|||
public class MaterialInfo { |
|||
private Integer id; |
|||
@Column(name = "user_name") |
|||
private String userName; |
|||
|
|||
private String code; |
|||
|
|||
private String value; |
|||
|
|||
@Column(name = "model_num") |
|||
private String modelNum; |
|||
|
|||
private String packages; |
|||
|
|||
private String company; |
|||
|
|||
private Integer num; |
|||
|
|||
private String position; |
|||
|
|||
private String description; |
|||
|
|||
private Integer status; |
|||
|
|||
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") |
|||
@Column(name = "create_time",updatable=false) |
|||
private Date createTime; |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
package cn.redrock.assetmanage.mapper; |
|||
|
|||
import cn.redrock.assetmanage.entity.AmMaterialLog; |
|||
import cn.redrock.assetmanage.entity.MaterialInfo; |
|||
import org.apache.ibatis.annotations.Param; |
|||
import tk.mybatis.mapper.common.Mapper; |
|||
|
|||
import java.util.Date; |
|||
import java.util.List; |
|||
|
|||
@org.apache.ibatis.annotations.Mapper |
|||
public interface AmMaterialLogMapper extends Mapper<AmMaterialLog> { |
|||
List<MaterialInfo> queryLog(@Param("operate") Integer operate, |
|||
@Param("status") Integer status, |
|||
@Param("field") String field, |
|||
@Param("content") String content, |
|||
@Param("startTm") Date startTm, |
|||
@Param("endTm") Date endTm); |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
package cn.redrock.assetmanage.mapper; |
|||
|
|||
import cn.redrock.assetmanage.entity.AmMaterial; |
|||
import org.apache.ibatis.annotations.Param; |
|||
import org.apache.ibatis.annotations.Select; |
|||
import tk.mybatis.mapper.common.Mapper; |
|||
|
|||
import java.util.List; |
|||
|
|||
@org.apache.ibatis.annotations.Mapper |
|||
public interface AmMaterialMapper extends Mapper<AmMaterial> { |
|||
@Select(value = "select * from am_material where code=#{code}") |
|||
AmMaterial find(String code); |
|||
List<AmMaterial> search(@Param("field") String field, @Param("content") String content); |
|||
@Select(value = "select * from am_material where num / base_num < #{limit}") |
|||
List<AmMaterial> warn(Float limit); |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
package cn.redrock.assetmanage.mapper; |
|||
|
|||
import cn.redrock.assetmanage.entity.AmPublicAsset; |
|||
import org.apache.ibatis.annotations.Param; |
|||
import org.apache.ibatis.annotations.Select; |
|||
import tk.mybatis.mapper.common.Mapper; |
|||
|
|||
import java.util.List; |
|||
|
|||
@org.apache.ibatis.annotations.Mapper |
|||
public interface AmPublicAssetMapper extends Mapper<AmPublicAsset> { |
|||
@Select(value = "select * from am_public_asset where code=#{code}") |
|||
AmPublicAsset findByKey(String code); |
|||
List<AmPublicAsset> search(@Param("field") String field,@Param("content") String content); |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
package cn.redrock.assetmanage.mapper; |
|||
|
|||
import cn.redrock.assetmanage.entity.AmStaffAsset; |
|||
import org.apache.ibatis.annotations.Param; |
|||
import org.apache.ibatis.annotations.Select; |
|||
import tk.mybatis.mapper.common.Mapper; |
|||
|
|||
import java.util.List; |
|||
|
|||
@org.apache.ibatis.annotations.Mapper |
|||
public interface AmStaffAssetMapper extends Mapper<AmStaffAsset> { |
|||
List<AmStaffAsset> search(@Param("userId") Integer userId,@Param("field") String field, @Param("content") String content); |
|||
|
|||
@Select(value = "select a.*,b.nickname user_name from am_staff_asset a,am_user b where a.user_id=#{userId} and a.user_id=b.id") |
|||
AmStaffAsset find(@Param("userId") Integer userId, @Param("name") String name); |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
package cn.redrock.assetmanage.mapper; |
|||
|
|||
import cn.redrock.assetmanage.entity.AmToken; |
|||
import cn.redrock.assetmanage.entity.AmUser; |
|||
import org.apache.ibatis.annotations.Select; |
|||
import org.apache.ibatis.annotations.Update; |
|||
import tk.mybatis.mapper.common.Mapper; |
|||
|
|||
@org.apache.ibatis.annotations.Mapper |
|||
public interface AmTokenMapper extends Mapper<AmToken> { |
|||
@Select(value = "select * from am_token where user_id=#{userId}") |
|||
AmToken getTokenById(Integer userId); |
|||
|
|||
@Update(value = "update am_token set token=#{token},expire_time=#{expireTime},update_time=#{updateTime} where user_id=#{userId}") |
|||
void updateTokenById(AmToken amToken); |
|||
|
|||
@Select(value = "select a.* from am_user a,am_token b where a.id=b.user_id and b.token=#{token} and b.expire_time > now()") |
|||
AmUser getUserByToken(String token); |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
package cn.redrock.assetmanage.mapper; |
|||
|
|||
import cn.redrock.assetmanage.entity.AmUser; |
|||
import org.apache.ibatis.annotations.Param; |
|||
import org.apache.ibatis.annotations.Select; |
|||
import tk.mybatis.mapper.common.Mapper; |
|||
|
|||
import java.util.List; |
|||
|
|||
@org.apache.ibatis.annotations.Mapper |
|||
public interface AmUserMapper extends Mapper<AmUser> { |
|||
@Select(value = "select * from am_user where name=#{name}") |
|||
AmUser findUserByName(String name); |
|||
List<AmUser> search(@Param("field") String field, @Param("content") String content); |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
package cn.redrock.assetmanage.service; |
|||
|
|||
import cn.redrock.assetmanage.dto.Material; |
|||
import cn.redrock.assetmanage.entity.AmMaterialLog; |
|||
import cn.redrock.assetmanage.entity.MaterialInfo; |
|||
import com.github.pagehelper.PageInfo; |
|||
|
|||
import java.util.Date; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/7/23 16:10 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
public interface MaterialLogService { |
|||
void writeLog(AmMaterialLog materialLog); |
|||
void batchWriteLog(List<AmMaterialLog> materialLogs); |
|||
void updateLog(List<Material> materials,Integer status); |
|||
PageInfo<MaterialInfo> queryLog(Integer operate, Integer status,String field,String content, Date startTm, Date endTm,Integer pageNum, Integer pageSize); |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
package cn.redrock.assetmanage.service; |
|||
|
|||
import cn.redrock.assetmanage.dto.Material; |
|||
import cn.redrock.assetmanage.entity.AmMaterial; |
|||
import com.github.pagehelper.PageInfo; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/7/23 15:00 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
public interface MaterialService { |
|||
boolean add(Material material); |
|||
boolean batchAdd(List<Material> materials,boolean isOverride); |
|||
boolean sub(Material material); |
|||
void batchSub(List<Material> materials,List<Material> successMaterials,List<Material> failMaterials); |
|||
List<AmMaterial> search(String field, String content, Integer pageNum, Integer pageSize); |
|||
boolean update(Material material); |
|||
boolean delete(String code); |
|||
PageInfo<AmMaterial> warn(Integer pageNum, Integer pageSize); |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
package cn.redrock.assetmanage.service; |
|||
|
|||
import cn.redrock.assetmanage.dto.PublicAsset; |
|||
import cn.redrock.assetmanage.entity.AmPublicAsset; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/7/23 9:54 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
public interface PublicAssetService { |
|||
boolean add(PublicAsset publicAsset); |
|||
List<AmPublicAsset> search(String field, String content, Integer pageNum, Integer pageSize); |
|||
boolean update(PublicAsset publicAsset); |
|||
boolean delete(String code); |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
package cn.redrock.assetmanage.service; |
|||
|
|||
import cn.redrock.assetmanage.dto.Asset; |
|||
import cn.redrock.assetmanage.entity.AmStaffAsset; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/7/23 13:52 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
public interface StaffAssetService { |
|||
boolean add(Asset asset); |
|||
List<AmStaffAsset> search(Integer userId,String field, String content, Integer pageNum, Integer pageSize); |
|||
boolean update(Asset asset); |
|||
boolean delete(Integer id); |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
package cn.redrock.assetmanage.service; |
|||
|
|||
import cn.redrock.assetmanage.entity.AmUser; |
|||
|
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/7/22 16:17 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
public interface TokenService { |
|||
Map<String,Object> createToken(Integer userId); |
|||
AmUser getUserByToken(String token); |
|||
void deleteToken(String token); |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
package cn.redrock.assetmanage.service; |
|||
|
|||
import cn.redrock.assetmanage.dto.UserBase; |
|||
import cn.redrock.assetmanage.dto.UserInfo; |
|||
import cn.redrock.assetmanage.entity.AmUser; |
|||
import com.github.pagehelper.PageInfo; |
|||
|
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/7/22 16:08 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
public interface UserService { |
|||
PageInfo<AmUser> search(String field, String content,Integer pageNum, Integer pageSize); |
|||
AmUser findUser(String name); |
|||
boolean createUser(UserInfo user); |
|||
boolean editUser(Integer userId,UserInfo user); |
|||
boolean deleteUser(Integer userId); |
|||
Map<String,Object> authUser(UserBase user); |
|||
void logout(String token); |
|||
String encode(String password); |
|||
} |
|||
@ -0,0 +1,64 @@ |
|||
package cn.redrock.assetmanage.service.impl; |
|||
|
|||
import cn.redrock.assetmanage.dto.Material; |
|||
import cn.redrock.assetmanage.entity.AmMaterialLog; |
|||
import cn.redrock.assetmanage.entity.MaterialInfo; |
|||
import cn.redrock.assetmanage.mapper.AmMaterialLogMapper; |
|||
import cn.redrock.assetmanage.service.MaterialLogService; |
|||
import com.github.pagehelper.PageHelper; |
|||
import com.github.pagehelper.PageInfo; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.util.Date; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/7/24 9:24 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
@Slf4j |
|||
@Service |
|||
@Transactional |
|||
public class MaterialLogServiceImpl implements MaterialLogService { |
|||
@Autowired |
|||
private AmMaterialLogMapper materialLogMapper; |
|||
|
|||
@Override |
|||
public void writeLog(AmMaterialLog materialLog) { |
|||
materialLogMapper.insert(materialLog); |
|||
} |
|||
|
|||
@Override |
|||
public void batchWriteLog(List<AmMaterialLog> materialLogs) { |
|||
for(AmMaterialLog materialLog : materialLogs){ |
|||
materialLogMapper.insert(materialLog); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void updateLog(List<Material> materials,Integer status) { |
|||
for(Material material : materials){ |
|||
if(material.getId() != null){ |
|||
AmMaterialLog log = new AmMaterialLog(); |
|||
log.setId(material.getId()); |
|||
log.setStatus(status); |
|||
log.setNum(material.getNum()); |
|||
materialLogMapper.updateByPrimaryKeySelective(log); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public PageInfo<MaterialInfo> queryLog(Integer operate, Integer status,String field,String content,Date startTm, Date endTm, Integer pageNum, Integer pageSize) { |
|||
if(pageNum != null && pageSize != null){ |
|||
PageHelper.startPage(pageNum, pageSize); |
|||
} |
|||
return PageInfo.of(materialLogMapper.queryLog(operate,status,field,content,startTm,endTm)); |
|||
} |
|||
} |
|||
@ -0,0 +1,201 @@ |
|||
package cn.redrock.assetmanage.service.impl; |
|||
|
|||
import cn.redrock.assetmanage.dto.Material; |
|||
import cn.redrock.assetmanage.entity.AmMaterial; |
|||
import cn.redrock.assetmanage.mapper.AmMaterialMapper; |
|||
import cn.redrock.assetmanage.service.MaterialService; |
|||
import cn.redrock.assetmanage.utils.BeanUtilsExt; |
|||
import cn.redrock.assetmanage.utils.StringUtil; |
|||
import com.alibaba.fastjson.JSON; |
|||
import com.github.pagehelper.PageHelper; |
|||
import com.github.pagehelper.PageInfo; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.BeanUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.util.Date; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/7/23 15:52 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
@Slf4j |
|||
@Service |
|||
@Transactional |
|||
public class MaterialServiceImpl implements MaterialService { |
|||
@Autowired |
|||
private AmMaterialMapper materialMapper; |
|||
|
|||
@Value("${limit}") |
|||
private Float limit; |
|||
|
|||
@Override |
|||
public boolean add(Material material) { |
|||
AmMaterial amMaterial = materialMapper.find(material.getCode()); |
|||
if(amMaterial != null){ |
|||
log.warn("material {} already exists",material.getCode()); |
|||
return false; |
|||
} |
|||
AmMaterial newMaterial = new AmMaterial(); |
|||
BeanUtils.copyProperties(material,newMaterial); |
|||
newMaterial.setCreateTime(new Date()); |
|||
if(materialMapper.insertSelective(newMaterial)> 0){ |
|||
log.info("add material success {}", JSON.toJSONString(newMaterial)); |
|||
return true; |
|||
} |
|||
log.error("add material failed {}", JSON.toJSONString(newMaterial)); |
|||
return false; |
|||
} |
|||
|
|||
@Override |
|||
public boolean batchAdd(List<Material> materials,boolean isOverride) { |
|||
for(Material material : materials){ |
|||
if(material.getNum() != null && StringUtil.isNotBlank(material.getCode())){ |
|||
AmMaterial oldMaterial = materialMapper.find(material.getCode()); |
|||
AmMaterial newMaterial = new AmMaterial(); |
|||
if(oldMaterial != null){ |
|||
Integer num = oldMaterial.getNum(); |
|||
if(isOverride){ |
|||
BeanUtilsExt.copyPropertiesIgnoreNull(material,oldMaterial); |
|||
oldMaterial.setNum(num + material.getNum()); |
|||
newMaterial = oldMaterial; |
|||
}else{ |
|||
newMaterial.setCode(material.getCode()); |
|||
newMaterial.setNum(num + material.getNum()); |
|||
} |
|||
newMaterial.setUpdateTime(new Date()); |
|||
if(materialMapper.updateByPrimaryKeySelective(newMaterial) > 0){ |
|||
log.info("update add material success from {} to {} ", JSON.toJSONString(oldMaterial),JSON.toJSONString(newMaterial)); |
|||
}else{ |
|||
log.error("update add material failed from {} to {} ", JSON.toJSONString(oldMaterial),JSON.toJSONString(newMaterial)); |
|||
} |
|||
}else{ |
|||
BeanUtils.copyProperties(material,newMaterial); |
|||
newMaterial.setCreateTime(new Date()); |
|||
if(materialMapper.insertSelective(newMaterial) > 0){ |
|||
log.info("add material success {}", JSON.toJSONString(newMaterial)); |
|||
}else{ |
|||
log.error("add material failed {}", JSON.toJSONString(newMaterial)); |
|||
} |
|||
} |
|||
}else{ |
|||
return false; |
|||
} |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
@Override |
|||
public boolean sub(Material material) { |
|||
AmMaterial oldMaterial = materialMapper.find(material.getCode()); |
|||
if(oldMaterial != null){ |
|||
AmMaterial newMaterial = new AmMaterial(); |
|||
Integer num = oldMaterial.getNum(); |
|||
if(num >= material.getNum()){ |
|||
newMaterial.setId(oldMaterial.getId()); |
|||
newMaterial.setCode(material.getCode()); |
|||
newMaterial.setNum(num - material.getNum()); |
|||
if(materialMapper.updateByPrimaryKeySelective(newMaterial) > 0){ |
|||
log.info("update sub material success from {} to {} ", JSON.toJSONString(oldMaterial),JSON.toJSONString(newMaterial)); |
|||
return true; |
|||
}else{ |
|||
log.error("update sub material failed from {} to {} ", JSON.toJSONString(oldMaterial),JSON.toJSONString(newMaterial)); |
|||
} |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
@Override |
|||
public void batchSub(List<Material> materials,List<Material> successMaterials,List<Material> failMaterials) { |
|||
for(Material material : materials){ |
|||
if(material.getNum() != null && StringUtil.isNotBlank(material.getCode())) { |
|||
AmMaterial oldMaterial = materialMapper.find(material.getCode()); |
|||
Material errorMaterial = new Material(); |
|||
if(oldMaterial != null){ |
|||
AmMaterial newMaterial = new AmMaterial(); |
|||
Integer num = oldMaterial.getNum(); |
|||
if(num >= material.getNum()){ |
|||
newMaterial.setId(oldMaterial.getId()); |
|||
newMaterial.setCode(material.getCode()); |
|||
newMaterial.setNum(num - material.getNum()); |
|||
successMaterials.add(material); |
|||
if(materialMapper.updateByPrimaryKeySelective(newMaterial) > 0){ |
|||
log.info("update sub material success from {} to {} ", JSON.toJSONString(oldMaterial),JSON.toJSONString(newMaterial)); |
|||
}else{ |
|||
log.error("update sub material failed from {} to {} ", JSON.toJSONString(oldMaterial),JSON.toJSONString(newMaterial)); |
|||
} |
|||
}else{ |
|||
newMaterial.setId(oldMaterial.getId()); |
|||
newMaterial.setCode(material.getCode()); |
|||
newMaterial.setNum(0); |
|||
if(materialMapper.updateByPrimaryKeySelective(newMaterial) > 0){ |
|||
log.info("update add material success from {} to {} for failed ", JSON.toJSONString(oldMaterial),JSON.toJSONString(newMaterial)); |
|||
}else{ |
|||
log.error("update add material failed from {} to {} for failed ", JSON.toJSONString(oldMaterial),JSON.toJSONString(newMaterial)); |
|||
} |
|||
BeanUtils.copyProperties(oldMaterial,errorMaterial); |
|||
errorMaterial.setNum(material.getNum() - num); |
|||
errorMaterial.setId(material.getId()); |
|||
failMaterials.add(errorMaterial); |
|||
} |
|||
}else{ |
|||
errorMaterial.setId(material.getId()); |
|||
errorMaterial.setCode(material.getCode()); |
|||
errorMaterial.setNum(material.getNum()); |
|||
failMaterials.add(errorMaterial); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public List<AmMaterial> search(String field, String content, Integer pageNum, Integer pageSize) { |
|||
if(pageNum != null && pageSize != null){ |
|||
PageHelper.startPage(pageNum, pageSize); |
|||
} |
|||
return materialMapper.search(field,content); |
|||
} |
|||
|
|||
@Override |
|||
public boolean update(Material material) { |
|||
AmMaterial amMaterial = materialMapper.find(material.getCode()); |
|||
if(amMaterial == null){ |
|||
log.warn("material {} not exists",material.getCode()); |
|||
return false; |
|||
} |
|||
BeanUtilsExt.copyPropertiesIgnoreNull(material,amMaterial); |
|||
amMaterial.setUpdateTime(new Date()); |
|||
if(materialMapper.updateByPrimaryKeySelective(amMaterial) > 0){ |
|||
log.info("edit material success from {} to {} ", JSON.toJSONString(material),JSON.toJSONString(amMaterial)); |
|||
return true; |
|||
} |
|||
log.error("edit material failed from {} to {} ", JSON.toJSONString(material),JSON.toJSONString(amMaterial)); |
|||
return false; |
|||
} |
|||
|
|||
@Override |
|||
public boolean delete(String code) { |
|||
if(materialMapper.deleteByPrimaryKey(code) > 0){ |
|||
log.info("delete material success {} ", code); |
|||
return true; |
|||
} |
|||
log.error("delete material failed {} ", code); |
|||
return false; |
|||
} |
|||
|
|||
@Override |
|||
public PageInfo<AmMaterial> warn(Integer pageNum, Integer pageSize) { |
|||
if(pageNum != null && pageSize != null){ |
|||
PageHelper.startPage(pageNum, pageSize); |
|||
} |
|||
return PageInfo.of(materialMapper.warn(limit)); |
|||
} |
|||
} |
|||
@ -0,0 +1,72 @@ |
|||
package cn.redrock.assetmanage.service.impl; |
|||
|
|||
import cn.redrock.assetmanage.dto.PublicAsset; |
|||
import cn.redrock.assetmanage.entity.AmPublicAsset; |
|||
import cn.redrock.assetmanage.mapper.AmPublicAssetMapper; |
|||
import cn.redrock.assetmanage.service.PublicAssetService; |
|||
import cn.redrock.assetmanage.utils.BeanUtilsExt; |
|||
import com.github.pagehelper.PageHelper; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.BeanUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.util.Date; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/7/23 10:03 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
@Slf4j |
|||
@Service |
|||
@Transactional |
|||
public class PublicAssetServiceImpl implements PublicAssetService { |
|||
@Autowired |
|||
private AmPublicAssetMapper publicAssetMapper; |
|||
|
|||
@Override |
|||
public boolean add(PublicAsset publicAsset) { |
|||
AmPublicAsset asset = publicAssetMapper.findByKey(publicAsset.getCode()); |
|||
if(asset != null){ |
|||
log.info("public asset {} already exists",publicAsset.getCode()); |
|||
return false; |
|||
} |
|||
AmPublicAsset amPublicAsset = new AmPublicAsset(); |
|||
BeanUtils.copyProperties(publicAsset,amPublicAsset); |
|||
amPublicAsset.setCreateTime(new Date()); |
|||
if(publicAssetMapper.insertSelective(amPublicAsset)> 0){ |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
@Override |
|||
public List<AmPublicAsset> search(String field, String content, Integer pageNum, Integer pageSize) { |
|||
if(pageNum != null && pageSize != null){ |
|||
PageHelper.startPage(pageNum, pageSize); |
|||
} |
|||
return publicAssetMapper.search(field,content); |
|||
} |
|||
|
|||
@Override |
|||
public boolean update(PublicAsset publicAsset) { |
|||
AmPublicAsset asset = publicAssetMapper.findByKey(publicAsset.getCode()); |
|||
if(asset == null){ |
|||
log.info("public asset {} not exists",publicAsset.getCode()); |
|||
return false; |
|||
} |
|||
BeanUtilsExt.copyPropertiesIgnoreNull(publicAsset,asset); |
|||
asset.setUpdateTime(new Date()); |
|||
return publicAssetMapper.updateByPrimaryKeySelective(asset) > 0; |
|||
} |
|||
|
|||
@Override |
|||
public boolean delete(String code) { |
|||
return publicAssetMapper.deleteByPrimaryKey(code) > 0; |
|||
} |
|||
} |
|||
@ -0,0 +1,74 @@ |
|||
package cn.redrock.assetmanage.service.impl; |
|||
|
|||
import cn.redrock.assetmanage.dto.Asset; |
|||
import cn.redrock.assetmanage.entity.AmStaffAsset; |
|||
import cn.redrock.assetmanage.mapper.AmStaffAssetMapper; |
|||
import cn.redrock.assetmanage.service.StaffAssetService; |
|||
import cn.redrock.assetmanage.utils.BeanUtilsExt; |
|||
import com.github.pagehelper.PageHelper; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.BeanUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.util.Date; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/7/23 13:54 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
@Slf4j |
|||
@Service |
|||
@Transactional |
|||
public class StaffAssetServiceImpl implements StaffAssetService { |
|||
|
|||
@Autowired |
|||
private AmStaffAssetMapper staffAssetMapper; |
|||
|
|||
@Override |
|||
public boolean add(Asset asset) { |
|||
AmStaffAsset staffAsset = staffAssetMapper.find(asset.getUserId(),asset.getName()); |
|||
if(staffAsset != null){ |
|||
log.info("public asset {} already exists",asset.getName()); |
|||
return false; |
|||
} |
|||
AmStaffAsset amStaffAsset = new AmStaffAsset(); |
|||
BeanUtils.copyProperties(asset,amStaffAsset); |
|||
amStaffAsset.setCreateTime(new Date()); |
|||
if(staffAssetMapper.insertSelective(amStaffAsset)> 0){ |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
@Override |
|||
public List<AmStaffAsset> search(Integer userId,String field, String content, Integer pageNum, Integer pageSize) { |
|||
if(pageNum != null && pageSize != null){ |
|||
PageHelper.startPage(pageNum, pageSize); |
|||
} |
|||
return staffAssetMapper.search(userId,field,content); |
|||
} |
|||
|
|||
@Override |
|||
public boolean update(Asset asset) { |
|||
AmStaffAsset staffAsset = staffAssetMapper.find(asset.getUserId(),asset.getName()); |
|||
if(staffAsset == null){ |
|||
log.info("public asset {} not exists",asset.getName()); |
|||
return false; |
|||
} |
|||
BeanUtilsExt.copyPropertiesIgnoreNull(asset,staffAsset); |
|||
staffAsset.setUpdateTime(new Date()); |
|||
staffAsset.setUserName(null); |
|||
return staffAssetMapper.updateByPrimaryKeySelective(staffAsset) > 0; |
|||
} |
|||
|
|||
@Override |
|||
public boolean delete(Integer id) { |
|||
return staffAssetMapper.deleteByPrimaryKey(id) > 0; |
|||
} |
|||
} |
|||
@ -0,0 +1,61 @@ |
|||
package cn.redrock.assetmanage.service.impl; |
|||
|
|||
import cn.redrock.assetmanage.entity.AmToken; |
|||
import cn.redrock.assetmanage.entity.AmUser; |
|||
import cn.redrock.assetmanage.mapper.AmTokenMapper; |
|||
import cn.redrock.assetmanage.service.TokenService; |
|||
import cn.redrock.assetmanage.utils.UUIDUtil; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.util.Date; |
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/7/22 16:18 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
@Service |
|||
@Transactional |
|||
public class TokenServiceImpl implements TokenService { |
|||
private static final long expire = 3600 * 12; |
|||
@Autowired |
|||
private AmTokenMapper tokenMapper; |
|||
|
|||
@Override |
|||
public Map<String,Object> createToken(Integer userId) { |
|||
AmToken amToken = tokenMapper.getTokenById(userId); |
|||
String token = UUIDUtil.generateUUID(); |
|||
Date expireTime = new Date(new Date().getTime() + expire * 1000); |
|||
if(amToken == null){ |
|||
amToken = new AmToken(); |
|||
amToken.setUserId(userId); |
|||
amToken.setExpireTime(expireTime); |
|||
amToken.setToken(token); |
|||
tokenMapper.insert(amToken); |
|||
}else{ |
|||
amToken.setToken(token); |
|||
amToken.setExpireTime(expireTime); |
|||
tokenMapper.updateTokenById(amToken); |
|||
} |
|||
Map<String,Object> map = new HashMap<>(); |
|||
map.put("token", token); |
|||
map.put("expire", expire); |
|||
return map; |
|||
} |
|||
|
|||
@Override |
|||
public AmUser getUserByToken(String token) { |
|||
return tokenMapper.getUserByToken(token); |
|||
} |
|||
|
|||
@Override |
|||
public void deleteToken(String token) { |
|||
tokenMapper.deleteByPrimaryKey(token); |
|||
} |
|||
} |
|||
@ -0,0 +1,134 @@ |
|||
package cn.redrock.assetmanage.service.impl; |
|||
|
|||
import cn.redrock.assetmanage.dto.UserBase; |
|||
import cn.redrock.assetmanage.dto.UserInfo; |
|||
import cn.redrock.assetmanage.entity.AmUser; |
|||
import cn.redrock.assetmanage.mapper.AmUserMapper; |
|||
import cn.redrock.assetmanage.service.TokenService; |
|||
import cn.redrock.assetmanage.service.UserService; |
|||
import cn.redrock.assetmanage.utils.BeanUtilsExt; |
|||
import com.github.pagehelper.PageHelper; |
|||
import com.github.pagehelper.PageInfo; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.BeanUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.nio.charset.StandardCharsets; |
|||
import java.security.MessageDigest; |
|||
import java.security.NoSuchAlgorithmException; |
|||
import java.util.Date; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/7/22 16:16 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
@Slf4j |
|||
@Service |
|||
@Transactional |
|||
public class UserServiceImpl implements UserService { |
|||
@Autowired |
|||
private AmUserMapper userMapper; |
|||
@Autowired |
|||
private TokenService tokenService; |
|||
|
|||
@Override |
|||
public PageInfo<AmUser> search(String field, String content,Integer pageNum, Integer pageSize) { |
|||
if(pageNum != null && pageSize != null){ |
|||
PageHelper.startPage(pageNum, pageSize); |
|||
} |
|||
return PageInfo.of(userMapper.search(field,content)); |
|||
} |
|||
|
|||
@Override |
|||
public AmUser findUser(String name) { |
|||
return userMapper.findUserByName(name); |
|||
} |
|||
|
|||
@Override |
|||
public boolean createUser(UserInfo user) { |
|||
AmUser existing = userMapper.findUserByName(user.getName()); |
|||
if(existing != null){ |
|||
log.info("user {} already exists",user.getName()); |
|||
return false; |
|||
} |
|||
String md5 = encode(user.getPassword()); |
|||
AmUser newUser = new AmUser(); |
|||
BeanUtils.copyProperties(user,newUser); |
|||
newUser.setPassword(md5); |
|||
newUser.setCreateTime(new Date()); |
|||
newUser.setIsAdmin(0); |
|||
userMapper.insert(newUser); |
|||
log.info("new user {} has been created,{}",user.getName(),new Date()); |
|||
return true; |
|||
} |
|||
|
|||
@Override |
|||
public boolean editUser(Integer userId,UserInfo user){ |
|||
AmUser oldUser = userMapper.selectByPrimaryKey(userId); |
|||
if(oldUser == null){ |
|||
log.info("can't find user with id {}",userId); |
|||
return false; |
|||
} |
|||
if(user.getName() != null && !oldUser.getName().equals(user.getName())){ |
|||
if(userMapper.findUserByName(user.getName()) != null){ |
|||
log.info("user {} already exists",user.getName()); |
|||
return false; |
|||
} |
|||
} |
|||
BeanUtilsExt.copyPropertiesIgnoreNull(user,oldUser); |
|||
oldUser.setUpdateTime(new Date()); |
|||
return userMapper.updateByPrimaryKeySelective(oldUser) > 0; |
|||
} |
|||
|
|||
@Override |
|||
public boolean deleteUser(Integer userId) { |
|||
return userMapper.deleteByPrimaryKey(userId) > 0; |
|||
} |
|||
|
|||
@Override |
|||
public Map<String,Object> authUser(UserBase user) { |
|||
AmUser amUser = userMapper.findUserByName(user.getName()); |
|||
if(amUser == null){ |
|||
log.info("can't find user by name {}",user.getName()); |
|||
return null; |
|||
} |
|||
if(!amUser.getPassword().equals(encode(user.getPassword()))){ |
|||
log.info("user {} password error",user.getName(),user.getPassword()); |
|||
return null; |
|||
} |
|||
return tokenService.createToken(amUser.getId()); |
|||
} |
|||
|
|||
@Override |
|||
public void logout(String token) { |
|||
tokenService.deleteToken(token); |
|||
} |
|||
|
|||
@Override |
|||
public String encode(String password) { |
|||
try { |
|||
MessageDigest md = MessageDigest.getInstance("MD5"); |
|||
md.update(password.getBytes(StandardCharsets.UTF_8)); |
|||
return byteToHex(md.digest()); |
|||
}catch (NoSuchAlgorithmException e){ |
|||
log.error("encode error ,{}",e.getMessage()); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
private String byteToHex(byte[] bytes){ |
|||
String strHex = ""; |
|||
StringBuilder sb = new StringBuilder(""); |
|||
for (int n = 0; n < bytes.length; n++) { |
|||
strHex = Integer.toHexString(bytes[n] & 0xFF); |
|||
sb.append((strHex.length() == 1) ? "0" + strHex : strHex); |
|||
} |
|||
return sb.toString().trim(); |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
package cn.redrock.assetmanage.utils; |
|||
|
|||
import org.springframework.beans.BeanUtils; |
|||
import org.springframework.beans.BeanWrapper; |
|||
import org.springframework.beans.BeanWrapperImpl; |
|||
|
|||
import java.util.HashSet; |
|||
import java.util.Set; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2018/11/29 12:55 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
public class BeanUtilsExt { |
|||
public static String[] getNullPropertyNames (Object source) { |
|||
final BeanWrapper src = new BeanWrapperImpl(source); |
|||
java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors(); |
|||
|
|||
Set<String> emptyNames = new HashSet<String>(); |
|||
for(java.beans.PropertyDescriptor pd : pds) { |
|||
Object srcValue = src.getPropertyValue(pd.getName()); |
|||
if (srcValue == null) emptyNames.add(pd.getName()); |
|||
} |
|||
String[] result = new String[emptyNames.size()]; |
|||
return emptyNames.toArray(result); |
|||
} |
|||
|
|||
public static void copyPropertiesIgnoreNull(Object src, Object target){ |
|||
BeanUtils.copyProperties(src, target, getNullPropertyNames(src)); |
|||
} |
|||
} |
|||
@ -0,0 +1,831 @@ |
|||
package cn.redrock.assetmanage.utils; |
|||
|
|||
import java.text.ParseException; |
|||
import java.text.SimpleDateFormat; |
|||
import java.util.Calendar; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* Date Utility Class |
|||
*/ |
|||
public class DateUtil |
|||
{ |
|||
public final static int SECOND = 1000; |
|||
public final static int MINUTE = SECOND * 60; |
|||
public final static int HOUR = MINUTE * 60; |
|||
public final static int DAY = HOUR * 24; |
|||
public final static int DAYOFMIDMONTH = 15; |
|||
public final static String COMMON_TIME_PATTERN = "HH:mm"; |
|||
public final static String COMMON_DATE_PATTERN = "yyyy-MM-dd"; |
|||
public final static String COMMON_DATE1_PATTERN = "yyyyMMdd"; |
|||
public final static String COMMON_DATETIME_PATTERN = COMMON_DATE_PATTERN + " " + COMMON_TIME_PATTERN; |
|||
public final static String COMMON_DATETIME_PATTERN_HHMMSS = COMMON_DATE_PATTERN + " HH:mm:ss"; |
|||
|
|||
private DateUtil() |
|||
{ |
|||
// nothing
|
|||
} |
|||
|
|||
|
|||
/** |
|||
* 将date转换成String |
|||
* |
|||
* @param timestamp |
|||
* @return |
|||
*/ |
|||
public static String dateToStr(Date date) |
|||
{ |
|||
return DateUtil.dateToStr(date, null); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 将date转换成String |
|||
* |
|||
* @param timestamp |
|||
* @return |
|||
*/ |
|||
public static String dateToStr(Date date, String aMask) |
|||
{ |
|||
String ret = null; |
|||
String mask = aMask; |
|||
if (StringUtil.isBlank(mask)) |
|||
mask = "yyyy-MM-dd"; |
|||
SimpleDateFormat sdf = new SimpleDateFormat(mask); |
|||
if(date==null){ |
|||
ret = ""; |
|||
}else{ |
|||
ret = sdf.format(date); |
|||
} |
|||
return ret; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 将String转换成Date |
|||
* |
|||
* @param timestamp |
|||
* @return |
|||
* @throws ParseException |
|||
*/ |
|||
public static Date strToDate(String date) throws ParseException |
|||
{ |
|||
return DateUtil.strToDate(date, null); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 将String转换成Date |
|||
* |
|||
* @param timestamp |
|||
* @return |
|||
* @throws ParseException |
|||
*/ |
|||
public static Date strToDate(String date, String aMask) throws ParseException |
|||
{ |
|||
Date ret = null; |
|||
String mask = aMask; |
|||
if (mask == null || "".equals(mask)) |
|||
mask = "yyyy-MM-dd"; |
|||
SimpleDateFormat sdf = new SimpleDateFormat(mask); |
|||
ret = sdf.parse(date); |
|||
return ret; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 获取当前时间点的日期对象 |
|||
* |
|||
* @return 日期对象 |
|||
*/ |
|||
public static Date getNow() |
|||
{ |
|||
Calendar c = Calendar.getInstance(); |
|||
return c.getTime(); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 得到year年month月day日的秒的日期对象 |
|||
* |
|||
* @param year |
|||
* @param month |
|||
* @param day |
|||
* @return 日期对象 |
|||
*/ |
|||
public static Date getDate(int year, int month, int day) |
|||
{ |
|||
Calendar c = Calendar.getInstance(); |
|||
c.set(Calendar.YEAR, year); |
|||
c.set(Calendar.MONTH, month - 1); |
|||
c.set(Calendar.DAY_OF_MONTH, day); |
|||
c.set(Calendar.HOUR_OF_DAY, 0); |
|||
c.set(Calendar.MINUTE, 0); |
|||
c.set(Calendar.SECOND, 0); |
|||
c.set(Calendar.MILLISECOND, 0); |
|||
return c.getTime(); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 得到当天秒的日期 |
|||
* |
|||
* @return Date 日期对象 |
|||
*/ |
|||
public static Date getTodayZeroClock() |
|||
{ |
|||
Calendar c = Calendar.getInstance(); |
|||
c.setTime(new Date()); |
|||
c.set(Calendar.HOUR_OF_DAY, 0); |
|||
c.set(Calendar.MINUTE, 0); |
|||
c.set(Calendar.SECOND, 0); |
|||
c.set(Calendar.MILLISECOND, 0); |
|||
return c.getTime(); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 比较两个start日期是否在end日期之前 |
|||
* |
|||
* @param start |
|||
* 日期 |
|||
* @param end |
|||
* 日期 |
|||
* @return boolean |
|||
*/ |
|||
public static boolean isBefore(Date start, Date end) |
|||
{ |
|||
return start.getTime() - end.getTime() < 0 ? true : false; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 比较两个start日期是否在end日期之前 |
|||
* |
|||
* @param start |
|||
* 日期 |
|||
* @param end |
|||
* 日期 |
|||
* @return boolean |
|||
*/ |
|||
public static boolean isBeforeOrEqual(Date start, Date end) |
|||
{ |
|||
return start.getTime() - end.getTime() <= 0 ? true : false; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 今天之前的日 |
|||
* |
|||
* @return boolean |
|||
*/ |
|||
public static boolean isBeforeToday(Date date) |
|||
{ |
|||
Date todayZero = getTodayZeroClock(); |
|||
return isBefore(date, todayZero); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 今天或今天之前的日期 |
|||
* |
|||
* @return boolean |
|||
*/ |
|||
public static boolean isBeforeOrEqualToday(Date date) |
|||
{ |
|||
Date todayZero = getTodayZeroClock(); |
|||
return isBeforeOrEqual(date, todayZero); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 该日期是否在上半月之内,15日之 |
|||
* |
|||
* @param date |
|||
* 待判断的日期 |
|||
* @return boolean |
|||
*/ |
|||
public static boolean isBeforeMidMonth(Date date) |
|||
{ |
|||
Calendar c = Calendar.getInstance(); |
|||
c.setTime(date); |
|||
int day = c.get(Calendar.DAY_OF_MONTH); |
|||
return day <= DAYOFMIDMONTH ? true : false; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 取某个时间点前几个月的某个时间点 |
|||
* |
|||
* @param d |
|||
* 原日 |
|||
* @param count |
|||
* 几个月前 |
|||
* @return 目标日期 |
|||
*/ |
|||
public static Date beforeMonths(Date d, int count) |
|||
{ |
|||
Calendar c = Calendar.getInstance(); |
|||
c.setTime(d); |
|||
c.set(Calendar.MONTH, c.get(Calendar.MONTH) - count); |
|||
return c.getTime(); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 取某个时间点前几天的某个时间 |
|||
* |
|||
* @param d |
|||
* 原日 |
|||
* @param count |
|||
* 天数 |
|||
* @return 目标日期 |
|||
*/ |
|||
public static Date beforeDays(Date d, int count) |
|||
{ |
|||
Calendar c = Calendar.getInstance(); |
|||
c.setTime(d); |
|||
c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) - count); |
|||
return c.getTime(); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 取当前日期的前几天的某个时间 |
|||
* |
|||
* @param count |
|||
* 天数 |
|||
* @return 目标日期 |
|||
*/ |
|||
public static Date beforeDays(int count) |
|||
{ |
|||
return beforeDays(getNow(), count); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 取当前时间点前几个小时的日期对象 |
|||
* |
|||
* @param count |
|||
* 小时 |
|||
* @return 目标日期 |
|||
*/ |
|||
public static Date beforeHours(int count) |
|||
{ |
|||
return beforeHours(getNow(), count); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 取某时间点前几个小时的日期对 |
|||
* |
|||
* @param d |
|||
* 原日 |
|||
* @param count |
|||
* 小时 |
|||
* @return 目标日期 |
|||
*/ |
|||
public static Date beforeHours(Date d, int count) |
|||
{ |
|||
Calendar c = Calendar.getInstance(); |
|||
c.setTime(d); |
|||
c.set(Calendar.HOUR, c.get(Calendar.HOUR) - count); |
|||
return c.getTime(); |
|||
} |
|||
/** |
|||
* |
|||
* @Title: beforeYears |
|||
* @Description: 获取count年前的当前时间点 |
|||
* @param d |
|||
* @param count |
|||
* @return |
|||
* @Return: Date |
|||
*/ |
|||
public static Date beforeYears(Date d, int count) |
|||
{ |
|||
Calendar c = Calendar.getInstance(); |
|||
c.setTime(d); |
|||
c.set(Calendar.YEAR, c.get(Calendar.YEAR) - count); |
|||
return c.getTime(); |
|||
} |
|||
|
|||
/** |
|||
* 取某个时间点前几分钟的某个时间点 |
|||
* |
|||
* @param d |
|||
* @param count |
|||
* @return |
|||
*/ |
|||
public static Date beforeMinutes(Date d, int count) |
|||
{ |
|||
Calendar c = Calendar.getInstance(); |
|||
c.setTime(d); |
|||
c.set(Calendar.MINUTE, c.get(Calendar.MINUTE) - count); |
|||
return c.getTime(); |
|||
} |
|||
|
|||
/** |
|||
* 取某个时间点后几个月的某个时间点 |
|||
* |
|||
* @param d |
|||
* 原日 |
|||
* @param count |
|||
* 几个月后 |
|||
* @return 目标日期 |
|||
*/ |
|||
public static Date afterMonths(Date d, int count) |
|||
{ |
|||
Calendar c = Calendar.getInstance(); |
|||
c.setTime(d); |
|||
c.set(Calendar.MONTH, c.get(Calendar.MONTH) + count); |
|||
return c.getTime(); |
|||
} |
|||
|
|||
/** |
|||
* 当前时间点后几个月的某个时间点 |
|||
* |
|||
* @param count |
|||
* 几个月后 |
|||
* @return 目标日期 |
|||
*/ |
|||
public static Date afterMonths(int count) |
|||
{ |
|||
return afterMonths(getNow(), count); |
|||
} |
|||
|
|||
/** |
|||
* 取某个时间点后几天的某个时间 |
|||
* |
|||
* @param d |
|||
* 原日 |
|||
* @param count |
|||
* 天数 |
|||
* @return 目标日期 |
|||
*/ |
|||
public static Date afterDays(Date d, int count) |
|||
{ |
|||
Calendar c = Calendar.getInstance(); |
|||
c.setTime(d); |
|||
c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) + count); |
|||
return c.getTime(); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 取当前日期的前几天的某个时间 |
|||
* |
|||
* @param count |
|||
* 天数 |
|||
* @return 目标日期 |
|||
*/ |
|||
public static Date afterDays(int count) |
|||
{ |
|||
return afterDays(getNow(), count); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 取当前时间点前几个小时的日期对象 |
|||
* |
|||
* @param count |
|||
* 小时 |
|||
* @return 目标日期 |
|||
*/ |
|||
public static Date afterHours(int count) |
|||
{ |
|||
return afterHours(getNow(), count); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 取某时间点前几个小时的日期对 |
|||
* |
|||
* @param d |
|||
* 原日 |
|||
* @param count |
|||
* 小时 |
|||
* @return 目标日期 |
|||
*/ |
|||
public static Date afterHours(Date d, int count) |
|||
{ |
|||
Calendar c = Calendar.getInstance(); |
|||
c.setTime(d); |
|||
c.set(Calendar.HOUR, c.get(Calendar.HOUR) + count); |
|||
return c.getTime(); |
|||
} |
|||
/** |
|||
* |
|||
* @Title: afterYears |
|||
* @Description: 获取count年后的当前时间点 |
|||
* @param count |
|||
* @return |
|||
* @Return: Date |
|||
*/ |
|||
public static Date afterYears(Date d, int count) |
|||
{ |
|||
Calendar c = Calendar.getInstance(); |
|||
c.setTime(d); |
|||
c.set(Calendar.YEAR, c.get(Calendar.YEAR) + count); |
|||
return c.getTime(); |
|||
} |
|||
|
|||
/** |
|||
* |
|||
* @Title: afterYears |
|||
* @Description: 获取count年后的当前时间点 |
|||
* @param count |
|||
* @return |
|||
* @Return: Date |
|||
*/ |
|||
public static Date afterYears(int count) |
|||
{ |
|||
return afterYears(getNow(), count); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 当前时间点后几分钟的某个时间点 |
|||
* |
|||
* 原日 |
|||
* @param count |
|||
* 分钟 |
|||
* @return 目标日期 |
|||
*/ |
|||
public static Date afterMinutes(int count) |
|||
{ |
|||
return afterMinutes(getNow(), count); |
|||
} |
|||
/** |
|||
* 取某个时间点后几分钟的某个时间点 |
|||
* |
|||
* @param d |
|||
* 原日 |
|||
* @param count |
|||
* 分钟 |
|||
* @return 目标日期 |
|||
*/ |
|||
public static Date afterMinutes(Date d, int count) |
|||
{ |
|||
Calendar c = Calendar.getInstance(); |
|||
c.setTime(d); |
|||
c.set(Calendar.MINUTE, c.get(Calendar.MINUTE) + count); |
|||
return c.getTime(); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 返回两个日期之间的毫秒数的差距,负数时取绝对 |
|||
* |
|||
* @param d1 |
|||
* 日期1 |
|||
* @param d2 |
|||
* 日期2 |
|||
* @return 毫秒 |
|||
*/ |
|||
public static long countMilliSecondsBetween(Date d1, Date d2) |
|||
{ |
|||
if (d1 == null || d2 == null) |
|||
{ |
|||
throw new IllegalArgumentException("参数d1或d2不能是null对象!"); |
|||
} |
|||
return Math.abs(d1.getTime() - d2.getTime()); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 获得两个日期之间相差的秒 |
|||
* |
|||
* @param d1 |
|||
* 日期1 |
|||
* @param d2 |
|||
* 日期2 |
|||
* @return 秒数 |
|||
*/ |
|||
public static long countSecondsBetween(Date d1, Date d2) |
|||
{ |
|||
return countMilliSecondsBetween(d1, d2) / SECOND; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 获得两个日期之间相差的分钟数 |
|||
* |
|||
* @param d1 |
|||
* @param d2 |
|||
* @return 分钟 |
|||
*/ |
|||
public static long countMinutesBetween(Date d1, Date d2) |
|||
{ |
|||
return countMilliSecondsBetween(d1, d2) / MINUTE; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 获得两个日期之间相差的小时数 |
|||
* |
|||
* @param d1 |
|||
* @param d2 |
|||
* @return 小时 |
|||
*/ |
|||
public static long countHoursBetween(Date d1, Date d2) |
|||
{ |
|||
return countMilliSecondsBetween(d1, d2) / HOUR; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 获得两个日期之间相差的天 |
|||
* |
|||
* @param d1 |
|||
* @param d2 |
|||
* @return 天数 |
|||
*/ |
|||
public static long countDaysBetween(Date d1, Date d2) |
|||
{ |
|||
return countMilliSecondsBetween(d1, d2) / DAY; |
|||
} |
|||
|
|||
|
|||
public static Date getThisYearBeginning() |
|||
{ |
|||
Calendar c = Calendar.getInstance(); |
|||
c.setTime(new Date()); |
|||
c.set(Calendar.MONTH, 0); |
|||
c.set(Calendar.DAY_OF_MONTH, 0); |
|||
c.set(Calendar.HOUR_OF_DAY, 0); |
|||
c.set(Calendar.MINUTE, 0); |
|||
c.set(Calendar.SECOND, 0); |
|||
c.set(Calendar.MILLISECOND, 0); |
|||
return c.getTime(); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 今年之前的日 |
|||
* |
|||
* @param date |
|||
* @return |
|||
*/ |
|||
public static boolean isBeforeThisYear(Date date) |
|||
{ |
|||
Date yearBeginning = getThisYearBeginning(); |
|||
return isBefore(date, yearBeginning); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 获取当前年份 |
|||
* |
|||
* @return |
|||
*/ |
|||
public static int getCurrentYear() |
|||
{ |
|||
Calendar calendar = Calendar.getInstance(); |
|||
int currentYear = calendar.get(Calendar.YEAR); |
|||
|
|||
return currentYear; |
|||
} |
|||
|
|||
/** |
|||
* 获取当前年份 |
|||
* |
|||
* @return |
|||
*/ |
|||
public static int getCurrentMonth() |
|||
{ |
|||
Calendar calendar = Calendar.getInstance(); |
|||
int currentMonth = calendar.get(Calendar.MONTH); |
|||
|
|||
return currentMonth; |
|||
} |
|||
|
|||
/** |
|||
* 比较两个日期间的天数 |
|||
* |
|||
* @param date1 |
|||
* @param date2 |
|||
* @return |
|||
*/ |
|||
public static int diffDate(Date date1, Date date2) |
|||
{ |
|||
if (date1 == null || date2 == null) |
|||
{ |
|||
return 0; |
|||
} |
|||
// 构建calendar对象
|
|||
Calendar calendar = Calendar.getInstance(); |
|||
int zone_offset = calendar.get(calendar.ZONE_OFFSET); |
|||
int dst_offset = calendar.get(calendar.DST_OFFSET); |
|||
long d1 = date1.getTime() + zone_offset + dst_offset; |
|||
long d2 = date2.getTime() + zone_offset + dst_offset; |
|||
int intDaysFirst = (int) (d1 / (60 * 60 * 1000 * 24)); // 60*60*1000
|
|||
int intDaysSecond = (int) (d2 / (60 * 60 * 1000 * 24)); |
|||
return intDaysFirst > intDaysSecond ? intDaysFirst - intDaysSecond : intDaysSecond - intDaysFirst; |
|||
|
|||
} |
|||
|
|||
|
|||
/** |
|||
* 格式化日期,格式为yyyy-MM-dd |
|||
* |
|||
* @param aDate |
|||
* 日期对象 |
|||
* @return 格式化 |
|||
*/ |
|||
public static String formatDate(Date aDate) |
|||
{ |
|||
return format(aDate, DateUtil.COMMON_DATE_PATTERN); |
|||
} |
|||
|
|||
/** |
|||
* 格式化日期,格式为yyyyMMdd |
|||
* |
|||
* @param aDate |
|||
* 日期对象 |
|||
* @return 格式化 |
|||
*/ |
|||
public static String formatDate1(Date aDate) |
|||
{ |
|||
return format(aDate, DateUtil.COMMON_DATE1_PATTERN); |
|||
} |
|||
|
|||
/** |
|||
* 格式化日期,格式为yyyy-MM-dd HH:mm |
|||
* |
|||
* @param aDate |
|||
* 日期对象 |
|||
* @return 格式化 |
|||
*/ |
|||
public static String formatDateTime(Date aDate) |
|||
{ |
|||
return format(aDate, COMMON_DATETIME_PATTERN); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 格式化日期,格式为yyyy-MM-dd HH:mm:ss |
|||
* |
|||
* @param aDate |
|||
* 日期对象 |
|||
* @return 格式化字 |
|||
*/ |
|||
public static String formatDateTimeByHhmmss(Date aDate) |
|||
{ |
|||
return format(aDate, COMMON_DATETIME_PATTERN_HHMMSS); |
|||
} |
|||
|
|||
/** |
|||
* 转换日期对象为字 |
|||
* |
|||
* @param aDate |
|||
* 日期对象 |
|||
* @param pattern |
|||
* 格式化样式,默认为yyyy-MM-dd |
|||
* @return |
|||
*/ |
|||
public static String format(Date aDate, String pattern) |
|||
{ |
|||
SimpleDateFormat df = new SimpleDateFormat(pattern); |
|||
return df.format(aDate); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 解析字串为日期对象,格式为pattern |
|||
* |
|||
* @param pattern |
|||
* the date pattern the string is in |
|||
* @param strDate |
|||
* a string representation of a date |
|||
* @return a converted Date object |
|||
* @see SimpleDateFormat |
|||
* @throws ParseException |
|||
*/ |
|||
public static final Date parse(String strDate, String pattern) throws ParseException |
|||
{ |
|||
SimpleDateFormat df = null; |
|||
Date date = null; |
|||
df = new SimpleDateFormat(pattern); |
|||
|
|||
try |
|||
{ |
|||
date = df.parse(strDate); |
|||
} |
|||
catch (ParseException pe) |
|||
{ |
|||
throw new ParseException(pe.getMessage(), pe.getErrorOffset()); |
|||
} |
|||
|
|||
return (date); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 解析字串为日期对象,格式为yyyy-MM-dd |
|||
* |
|||
* @param dateStr |
|||
* @return |
|||
* @throws ParseException |
|||
*/ |
|||
public static Date parseDate(String dateStr) throws ParseException |
|||
{ |
|||
return parse(dateStr, COMMON_DATE_PATTERN); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 解析字串为日期对象,格式为yyyy-MM-dd HH:mm |
|||
* |
|||
* @param dateStr |
|||
* @return |
|||
* @throws ParseException |
|||
*/ |
|||
public static Date parseDateTime(String dateStr) throws ParseException |
|||
{ |
|||
return parse(dateStr, COMMON_DATETIME_PATTERN); |
|||
} |
|||
|
|||
/** |
|||
* @Title: getCurrDate |
|||
* @Description: 得到当前时间 格式 yyyyMMddhhmm |
|||
* @return String |
|||
* @throws ParseException |
|||
* @Return: String |
|||
*/ |
|||
public static String getCurrDate() throws ParseException |
|||
{ |
|||
SimpleDateFormat formart = new SimpleDateFormat("yyyyMMddhhmm"); |
|||
return formart.format(new Date()); |
|||
} |
|||
|
|||
public static Date getMondayOfThisWeek(Date d) { |
|||
Calendar c = Calendar.getInstance(); |
|||
c.setTime(d); |
|||
int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1; |
|||
if (day_of_week == 0) |
|||
day_of_week = 7; |
|||
c.add(Calendar.DATE, -day_of_week + 1); |
|||
return c.getTime(); |
|||
} |
|||
|
|||
public static Date getMondayOfThisWeek() { |
|||
Calendar c = Calendar.getInstance(); |
|||
int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1; |
|||
if (day_of_week == 0) |
|||
day_of_week = 7; |
|||
c.add(Calendar.DATE, -day_of_week + 1); |
|||
return c.getTime(); |
|||
} |
|||
|
|||
/** |
|||
* 得到本周周日 |
|||
* |
|||
* @return yyyy-MM-dd |
|||
*/ |
|||
public static Date getSundayOfThisWeek(Date d) { |
|||
Calendar c = Calendar.getInstance(); |
|||
c.setTime(d); |
|||
int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1; |
|||
if (day_of_week == 0) |
|||
day_of_week = 7; |
|||
c.add(Calendar.DATE, -day_of_week + 7); |
|||
return c.getTime(); |
|||
} |
|||
public static Date getSundayOfThisWeek() { |
|||
Calendar c = Calendar.getInstance(); |
|||
int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1; |
|||
if (day_of_week == 0) |
|||
day_of_week = 7; |
|||
c.add(Calendar.DATE, -day_of_week + 7); |
|||
return c.getTime(); |
|||
} |
|||
|
|||
public static Date getFirstOfThisMonth(Date d) { |
|||
Calendar c = Calendar.getInstance(); |
|||
c.setTime(d); |
|||
c.add(Calendar.MONTH, 0); |
|||
c.set(Calendar.DAY_OF_MONTH, 1); |
|||
return c.getTime(); |
|||
} |
|||
public static int getDaysOfMonth(int year, int month) |
|||
{ |
|||
Calendar c = Calendar.getInstance(); |
|||
c.set(Calendar.YEAR, year); |
|||
c.set(Calendar.MONTH, month - 1); |
|||
c.set(Calendar.DATE, 1);//把日期设置为当月第一天
|
|||
c.roll(Calendar.DATE, -1);//日期回滚一天,也就是最后一天
|
|||
int maxDate = c.get(Calendar.DATE); |
|||
return maxDate; |
|||
} |
|||
public static int getDaysOfMonth(Date d) |
|||
{ |
|||
Calendar c = Calendar.getInstance(); |
|||
c.setTime(d); |
|||
c.set(Calendar.YEAR, c.get(Calendar.YEAR)); |
|||
c.set(Calendar.MONTH, c.get(Calendar.MONTH)); |
|||
c.set(Calendar.DATE, 1);//把日期设置为当月第一天
|
|||
c.roll(Calendar.DATE, -1);//日期回滚一天,也就是最后一天
|
|||
int maxDate = c.get(Calendar.DATE); |
|||
return maxDate; |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
package cn.redrock.assetmanage.utils; |
|||
|
|||
import java.lang.annotation.*; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/7/23 11:41 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
@Target({ElementType.FIELD}) |
|||
@Retention(RetentionPolicy.RUNTIME) |
|||
@Documented |
|||
public @interface ExcelColumn { |
|||
|
|||
String value() default ""; |
|||
|
|||
int col() default 0; |
|||
} |
|||
@ -0,0 +1,330 @@ |
|||
package cn.redrock.assetmanage.utils; |
|||
|
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.collections.CollectionUtils; |
|||
import org.apache.commons.lang3.BooleanUtils; |
|||
import org.apache.commons.lang3.CharUtils; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.apache.commons.lang3.math.NumberUtils; |
|||
import org.apache.poi.hssf.usermodel.HSSFDateUtil; |
|||
import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
|||
import org.apache.poi.ss.usermodel.*; |
|||
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|||
import org.springframework.http.MediaType; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import javax.servlet.http.HttpServletResponse; |
|||
import java.io.File; |
|||
import java.io.FileOutputStream; |
|||
import java.io.IOException; |
|||
import java.io.InputStream; |
|||
import java.lang.reflect.Constructor; |
|||
import java.lang.reflect.Field; |
|||
import java.math.BigDecimal; |
|||
import java.net.URLEncoder; |
|||
import java.util.*; |
|||
import java.util.concurrent.atomic.AtomicInteger; |
|||
import java.util.stream.Collectors; |
|||
import java.util.stream.Stream; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/7/23 11:39 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
@Slf4j |
|||
public class ExcelUtils { |
|||
private final static String EXCEL2003 = "xls"; |
|||
private final static String EXCEL2007 = "xlsx"; |
|||
public static <T> List<T> readExcel( MultipartFile file,Class<T> cls){ |
|||
String fileName = file.getOriginalFilename(); |
|||
if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) { |
|||
log.error("上传文件格式不正确"); |
|||
return null; |
|||
} |
|||
List<T> dataList = new ArrayList<>(); |
|||
Workbook workbook = null; |
|||
try { |
|||
InputStream is = file.getInputStream(); |
|||
if (fileName.endsWith(EXCEL2007)) { |
|||
// FileInputStream is = new FileInputStream(new File(path));
|
|||
workbook = new XSSFWorkbook(is); |
|||
} |
|||
if (fileName.endsWith(EXCEL2003)) { |
|||
// FileInputStream is = new FileInputStream(new File(path));
|
|||
workbook = new HSSFWorkbook(is); |
|||
} |
|||
if (workbook != null) { |
|||
//类映射 注解 value-->bean columns
|
|||
Map<String, List<Field>> classMap = new HashMap<>(); |
|||
List<Field> fields = Stream.of(cls.getDeclaredFields()).collect(Collectors.toList()); |
|||
fields.forEach( |
|||
field -> { |
|||
ExcelColumn annotation = field.getAnnotation(ExcelColumn.class); |
|||
if (annotation != null) { |
|||
String value = annotation.value(); |
|||
if (StringUtils.isBlank(value)) { |
|||
return;//return起到的作用和continue是相同的 语法
|
|||
} |
|||
if (!classMap.containsKey(value)) { |
|||
classMap.put(value, new ArrayList<>()); |
|||
} |
|||
field.setAccessible(true); |
|||
classMap.get(value).add(field); |
|||
} |
|||
} |
|||
); |
|||
//索引-->columns
|
|||
Map<Integer, List<Field>> reflectionMap = new HashMap<>(16); |
|||
//默认读取第一个sheet
|
|||
Sheet sheet = workbook.getSheetAt(0); |
|||
|
|||
boolean firstRow = true; |
|||
for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) { |
|||
Row row = sheet.getRow(i); |
|||
//首行 提取注解
|
|||
if (firstRow) { |
|||
for (int j = row.getFirstCellNum(); j <= row.getLastCellNum(); j++) { |
|||
Cell cell = row.getCell(j); |
|||
String cellValue = getCellValue(cell); |
|||
if (classMap.containsKey(cellValue)) { |
|||
reflectionMap.put(j, classMap.get(cellValue)); |
|||
} |
|||
} |
|||
firstRow = false; |
|||
if(reflectionMap.isEmpty()){ |
|||
return null; |
|||
} |
|||
} else { |
|||
//忽略空白行
|
|||
if (row == null) { |
|||
continue; |
|||
} |
|||
try { |
|||
T t = cls.newInstance(); |
|||
//判断是否为空白行
|
|||
boolean allBlank = true; |
|||
for (int j = row.getFirstCellNum(); j <= row.getLastCellNum(); j++) { |
|||
if (reflectionMap.containsKey(j)) { |
|||
Cell cell = row.getCell(j); |
|||
String cellValue = getCellValue(cell); |
|||
if (StringUtils.isNotBlank(cellValue)) { |
|||
allBlank = false; |
|||
} |
|||
List<Field> fieldList = reflectionMap.get(j); |
|||
fieldList.forEach( |
|||
x -> { |
|||
try { |
|||
handleField(t, cellValue, x); |
|||
} catch (Exception e) { |
|||
log.error("reflect field:{} value:{} exception!", x.getName(), cellValue, e); |
|||
} |
|||
} |
|||
); |
|||
} |
|||
} |
|||
if (!allBlank) { |
|||
dataList.add(t); |
|||
} else { |
|||
log.warn("row:{} is blank ignore!", i); |
|||
} |
|||
} catch (Exception e) { |
|||
log.error("parse row:{} exception!", i, e); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} catch (Exception e) { |
|||
log.error("parse excel exception!", e); |
|||
} finally { |
|||
if (workbook != null) { |
|||
try { |
|||
workbook.close(); |
|||
} catch (Exception e) { |
|||
log.error("parse excel exception!", e); |
|||
} |
|||
} |
|||
} |
|||
return dataList; |
|||
} |
|||
|
|||
private static <T> void handleField(T t, String value, Field field) throws Exception { |
|||
Class<?> type = field.getType(); |
|||
if (type == null || type == void.class || StringUtils.isBlank(value)) { |
|||
return; |
|||
} |
|||
if (type == Object.class) { |
|||
field.set(t, value); |
|||
//数字类型
|
|||
} else if (type.getSuperclass() == null || type.getSuperclass() == Number.class) { |
|||
if (type == int.class || type == Integer.class) { |
|||
field.set(t, NumberUtils.toInt(value)); |
|||
} else if (type == long.class || type == Long.class) { |
|||
field.set(t, NumberUtils.toLong(value)); |
|||
} else if (type == byte.class || type == Byte.class) { |
|||
field.set(t, NumberUtils.toByte(value)); |
|||
} else if (type == short.class || type == Short.class) { |
|||
field.set(t, NumberUtils.toShort(value)); |
|||
} else if (type == double.class || type == Double.class) { |
|||
field.set(t, NumberUtils.toDouble(value)); |
|||
} else if (type == float.class || type == Float.class) { |
|||
field.set(t, NumberUtils.toFloat(value)); |
|||
} else if (type == char.class || type == Character.class) { |
|||
field.set(t, CharUtils.toChar(value)); |
|||
} else if (type == boolean.class) { |
|||
field.set(t, BooleanUtils.toBoolean(value)); |
|||
} else if (type == BigDecimal.class) { |
|||
field.set(t, new BigDecimal(value)); |
|||
} |
|||
} else if (type == Boolean.class) { |
|||
field.set(t, BooleanUtils.toBoolean(value)); |
|||
} else if (type == Date.class) { |
|||
//
|
|||
field.set(t, value); |
|||
} else if (type == String.class) { |
|||
field.set(t, value); |
|||
} else { |
|||
Constructor<?> constructor = type.getConstructor(String.class); |
|||
field.set(t, constructor.newInstance(value)); |
|||
} |
|||
} |
|||
|
|||
private static String getCellValue(Cell cell) { |
|||
if (cell == null) { |
|||
return ""; |
|||
} |
|||
if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { |
|||
if (org.apache.poi.ss.usermodel.DateUtil.isCellDateFormatted(cell)) { |
|||
return HSSFDateUtil.getJavaDate(cell.getNumericCellValue()).toString(); |
|||
} else { |
|||
return new BigDecimal(cell.getNumericCellValue()).toString(); |
|||
} |
|||
} else if (cell.getCellType() == Cell.CELL_TYPE_STRING) { |
|||
return StringUtils.trimToEmpty(cell.getStringCellValue()); |
|||
} else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) { |
|||
return StringUtils.trimToEmpty(cell.getCellFormula()); |
|||
} else if (cell.getCellType() == Cell.CELL_TYPE_BLANK) { |
|||
return ""; |
|||
} else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) { |
|||
return String.valueOf(cell.getBooleanCellValue()); |
|||
} else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) { |
|||
return "ERROR"; |
|||
} else { |
|||
return cell.toString().trim(); |
|||
} |
|||
|
|||
} |
|||
|
|||
public static <T> Workbook writeExcel(List<T> dataList, Class<T> cls){ |
|||
Field[] fields = cls.getDeclaredFields(); |
|||
List<Field> fieldList = Arrays.stream(fields) |
|||
.filter(field -> { |
|||
ExcelColumn annotation = field.getAnnotation(ExcelColumn.class); |
|||
if (annotation != null && annotation.col() > 0) { |
|||
field.setAccessible(true); |
|||
return true; |
|||
} |
|||
return false; |
|||
}).sorted(Comparator.comparing(field -> { |
|||
int col = 0; |
|||
ExcelColumn annotation = field.getAnnotation(ExcelColumn.class); |
|||
if (annotation != null) { |
|||
col = annotation.col(); |
|||
} |
|||
return col; |
|||
})).collect(Collectors.toList()); |
|||
|
|||
Workbook wb = new XSSFWorkbook(); |
|||
Sheet sheet = wb.createSheet("sheet1"); |
|||
AtomicInteger ai = new AtomicInteger(); |
|||
{ |
|||
Row row = sheet.createRow(ai.getAndIncrement()); |
|||
AtomicInteger aj = new AtomicInteger(); |
|||
//写入头部
|
|||
fieldList.forEach(field -> { |
|||
ExcelColumn annotation = field.getAnnotation(ExcelColumn.class); |
|||
String columnName = ""; |
|||
if (annotation != null) { |
|||
columnName = annotation.value(); |
|||
} |
|||
Cell cell = row.createCell(aj.getAndIncrement()); |
|||
|
|||
CellStyle cellStyle = wb.createCellStyle(); |
|||
cellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex()); |
|||
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); |
|||
cellStyle.setAlignment(HorizontalAlignment.CENTER); |
|||
|
|||
Font font = wb.createFont(); |
|||
font.setBold(true); |
|||
cellStyle.setFont(font); |
|||
cell.setCellStyle(cellStyle); |
|||
cell.setCellValue(columnName); |
|||
}); |
|||
} |
|||
if (CollectionUtils.isNotEmpty(dataList)) { |
|||
dataList.forEach(t -> { |
|||
Row row1 = sheet.createRow(ai.getAndIncrement()); |
|||
AtomicInteger aj = new AtomicInteger(); |
|||
fieldList.forEach(field -> { |
|||
Class<?> type = field.getType(); |
|||
Object value = ""; |
|||
try { |
|||
value = field.get(t); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
Cell cell = row1.createCell(aj.getAndIncrement()); |
|||
if (value != null) { |
|||
if (type == Date.class) { |
|||
cell.setCellValue(value.toString()); |
|||
} else { |
|||
cell.setCellValue(value.toString()); |
|||
} |
|||
cell.setCellValue(value.toString()); |
|||
} |
|||
}); |
|||
}); |
|||
} |
|||
//冻结窗格
|
|||
wb.getSheet("sheet1").createFreezePane(0, 1, 0, 1); |
|||
return wb; |
|||
} |
|||
|
|||
/** |
|||
* 浏览器下载excel |
|||
* @param fileName |
|||
* @param wb |
|||
* @param response |
|||
*/ |
|||
|
|||
public static void buildExcelDocument(String fileName, Workbook wb,HttpServletResponse response){ |
|||
try { |
|||
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); |
|||
response.setHeader("Content-Disposition", "attachment;filename="+URLEncoder.encode(fileName, "utf-8")); |
|||
response.flushBuffer(); |
|||
wb.write(response.getOutputStream()); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 生成excel文件 |
|||
* @param path 生成excel路径 |
|||
* @param wb |
|||
*/ |
|||
public static void buildExcelFile(String path, Workbook wb){ |
|||
|
|||
File file = new File(path); |
|||
if (file.exists()) { |
|||
file.delete(); |
|||
} |
|||
try { |
|||
wb.write(new FileOutputStream(file)); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,55 @@ |
|||
package cn.redrock.assetmanage.utils; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
|
|||
/** |
|||
* String Utility Class |
|||
*/ |
|||
public class StringUtil |
|||
{ |
|||
|
|||
public static String ENTITY_STR=""; |
|||
|
|||
|
|||
/** |
|||
* check if the string is blank "" and null return true |
|||
* |
|||
*/ |
|||
public static boolean isBlank(String str) |
|||
{ |
|||
boolean flag = false; |
|||
if (str == null || "".equals(str.trim())) |
|||
{ |
|||
flag = true; |
|||
} |
|||
return flag; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* check if the String is not Blank "" and null return false |
|||
* |
|||
* @param str |
|||
* @return |
|||
*/ |
|||
public static boolean isNotBlank(String str) |
|||
{ |
|||
boolean flag = false; |
|||
if (str != null && !"".equals(str)) |
|||
{ |
|||
flag = true; |
|||
} |
|||
return flag; |
|||
} |
|||
|
|||
|
|||
public static String createSerialNum(String model){ |
|||
String serialNum = ""; |
|||
UUID uuid = UUID.randomUUID(); |
|||
serialNum=model+uuid.toString(); |
|||
return serialNum; |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,49 @@ |
|||
package cn.redrock.assetmanage.utils; |
|||
|
|||
import java.util.Random; |
|||
import java.util.UUID; |
|||
|
|||
/** |
|||
* @ Author : lihua |
|||
* @ Date : |
|||
* @ Description : 2019/6/15 15:59 |
|||
* @ Modified by : |
|||
* @ Version : 1.0 |
|||
*/ |
|||
public class UUIDUtil { |
|||
public static String[] chars = new String[] { "a", "b", "c", "d", "e", "f", |
|||
"g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", |
|||
"t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", |
|||
"6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", |
|||
"J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", |
|||
"W", "X", "Y", "Z" }; |
|||
|
|||
public static String generateShortUUID() { |
|||
StringBuffer shortBuffer = new StringBuffer(); |
|||
String uuid = generateUUID(); |
|||
for (int i = 0; i < 8; i++) { |
|||
String str = uuid.substring(i * 4, i * 4 + 4); |
|||
int x = Integer.parseInt(str, 16); |
|||
shortBuffer.append(chars[x % 0x3E]); |
|||
} |
|||
Random r = new Random(); |
|||
return "P" + shortBuffer.toString()+(r.nextInt(89)+10); |
|||
} |
|||
|
|||
public static String generateMiddleUUID() { |
|||
StringBuffer middleBuffer = new StringBuffer(); |
|||
String uuid = generateUUID(); |
|||
for (int i = 0; i < 16; i++) { |
|||
String str = uuid.substring(i * 2, i * 2 + 2); |
|||
int x = Integer.parseInt(str, 16); |
|||
middleBuffer.append(chars[x % 0x3E]); |
|||
} |
|||
Random r = new Random(); |
|||
return "D" + middleBuffer.toString()+(r.nextInt(899)+100); |
|||
} |
|||
|
|||
public static String generateUUID() { |
|||
return UUID.randomUUID().toString().replace("-", ""); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
server: |
|||
port: 8080 |
|||
spring: |
|||
application: |
|||
name: asset-manage |
|||
datasource: |
|||
type: com.zaxxer.hikari.HikariDataSource |
|||
driver-class-name: com.mysql.cj.jdbc.Driver |
|||
url: jdbc:mysql://${MYSQL_HOST:localhost}:${MYSQL_PORT:3306}/${MYSQL_DATABASE:asset-manage}?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false |
|||
username: ${MYSQL_USERNAME:root} |
|||
password: ${MYSQL_PASSWORD:root} |
|||
hikari: |
|||
minimum-idle: 5 |
|||
idle-timeout: 180000 |
|||
maximum-pool-size: 10 |
|||
auto-commit: true |
|||
pool-name: MyHikariCP |
|||
max-lifetime: 1765000 |
|||
connection-timeout: 30000 |
|||
connection-test-query: SELECT 1 |
|||
|
|||
mybatis: |
|||
mapper-locations: classpath:mapper/*.xml |
|||
type-aliases-package: cn.redrock.assetmanage.entity |
|||
configuration: |
|||
map-underscore-to-camel-case: true |
|||
|
|||
pagehelper: |
|||
helperDialect: mysql |
|||
reasonable: true |
|||
supportMethodsArguments: true |
|||
params: count=countSql |
|||
|
|||
limit: 0.1 |
|||
@ -0,0 +1,46 @@ |
|||
<configuration> |
|||
<property name="APP_NAME" value="asset-manage" /> |
|||
<property name="ROOT_DIR" value="logs" /> |
|||
<property name="PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread%X{sourceThread}]%logger{24}[%line] - %msg%n"/> |
|||
|
|||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
|||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> |
|||
<pattern>${PATTERN}</pattern> |
|||
</encoder> |
|||
</appender> |
|||
|
|||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
|||
<file>${ROOT_DIR}/${APP_NAME}/info.log</file> |
|||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
|||
<fileNamePattern>${ROOT_DIR}/${APP_NAME}/%d{yyyy-MM-dd}-info.log.gz</fileNamePattern> |
|||
<maxHistory>7</maxHistory> |
|||
</rollingPolicy> |
|||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> |
|||
<pattern>${PATTERN}</pattern> |
|||
</encoder> |
|||
</appender> |
|||
|
|||
<appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
|||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter"> |
|||
<level>ERROR</level> |
|||
</filter> |
|||
<File>${ROOT_DIR}/${APP_NAME}/error.log</File> |
|||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
|||
<fileNamePattern>${ROOT_DIR}/${APP_NAME}/%d{yyyy-MM-dd}-error.log.%i</fileNamePattern> |
|||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
|||
<maxFileSize>500MB</maxFileSize> |
|||
</timeBasedFileNamingAndTriggeringPolicy> |
|||
<maxHistory>7</maxHistory> |
|||
</rollingPolicy> |
|||
<layout class="ch.qos.logback.classic.PatternLayout"> |
|||
<Pattern>${PATTERN}</Pattern> |
|||
</layout> |
|||
</appender> |
|||
|
|||
<logger name="org.springframework.web.servlet.mvc" level="info"/> |
|||
<root level="info"> |
|||
<appender-ref ref="STDOUT"/> |
|||
<appender-ref ref="FILE"/> |
|||
<appender-ref ref="ERROR_FILE"/> |
|||
</root> |
|||
</configuration> |
|||
@ -0,0 +1,44 @@ |
|||
<?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="cn.redrock.assetmanage.mapper.AmMaterialLogMapper"> |
|||
<resultMap id="BaseResultMap" type="cn.redrock.assetmanage.entity.AmMaterialLog"> |
|||
<id column="id" jdbcType="INTEGER" property="id" /> |
|||
<result column="code" jdbcType="VARCHAR" property="code" /> |
|||
<result column="num" jdbcType="INTEGER" property="num" /> |
|||
<result column="status" jdbcType="INTEGER" property="status" /> |
|||
<result column="user_id" jdbcType="INTEGER" property="userId" /> |
|||
<result column="description" jdbcType="VARCHAR" property="description" /> |
|||
<result column="operate" jdbcType="INTEGER" property="operate" /> |
|||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> |
|||
</resultMap> |
|||
<resultMap id="MaterialInfo" type="cn.redrock.assetmanage.entity.MaterialInfo"> |
|||
<id column="id" jdbcType="INTEGER" property="id" /> |
|||
<result column="user_name" jdbcType="VARCHAR" property="userName" /> |
|||
<result column="code" jdbcType="VARCHAR" property="code" /> |
|||
<result column="value" jdbcType="VARCHAR" property="value" /> |
|||
<result column="packages" jdbcType="VARCHAR" property="packages" /> |
|||
<result column="company" jdbcType="VARCHAR" property="company" /> |
|||
<result column="num" jdbcType="INTEGER" property="num" /> |
|||
<result column="position" jdbcType="VARCHAR" property="position" /> |
|||
<result column="description" jdbcType="VARCHAR" property="description" /> |
|||
<result column="status" jdbcType="INTEGER" property="status" /> |
|||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> |
|||
</resultMap> |
|||
<select id="queryLog" resultMap="MaterialInfo"> |
|||
select * from |
|||
(select a.*,b.nickname user_name,c.value,c.model_num,c.packages,c.company,c.position |
|||
from am_material_log a |
|||
left join am_user b on a.user_id=b.id |
|||
left join am_material c on a.code=c.code |
|||
where a.operate=#{operate} and a.status=#{status} |
|||
<if test="startTm != null and endTm != null "> |
|||
and a.create_time between #{startTm} and #{endTm} |
|||
</if> |
|||
) t |
|||
where 1 = 1 |
|||
<if test="field != null and field != '' and content != null and content != '' "> |
|||
and t.${field} like CONCAT('%',#{content},'%') |
|||
</if> |
|||
order by t.create_time desc |
|||
</select> |
|||
</mapper> |
|||
@ -0,0 +1,24 @@ |
|||
<?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="cn.redrock.assetmanage.mapper.AmMaterialMapper"> |
|||
<resultMap id="BaseResultMap" type="cn.redrock.assetmanage.entity.AmMaterial"> |
|||
<result column="code" jdbcType="VARCHAR" property="code" /> |
|||
<result column="value" jdbcType="VARCHAR" property="value" /> |
|||
<result column="model_num" jdbcType="VARCHAR" property="modelNum" /> |
|||
<result column="packages" jdbcType="VARCHAR" property="packages" /> |
|||
<result column="company" jdbcType="VARCHAR" property="company" /> |
|||
<result column="num" jdbcType="INTEGER" property="num" /> |
|||
<result column="position" jdbcType="VARCHAR" property="position" /> |
|||
<result column="description" jdbcType="VARCHAR" property="description" /> |
|||
<result column="base_num" jdbcType="INTEGER" property="baseNum" /> |
|||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> |
|||
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> |
|||
</resultMap> |
|||
<select id="search" resultMap="BaseResultMap"> |
|||
select * from am_material |
|||
where 1=1 |
|||
<if test="field != null and field != '' and content != null and content != '' "> |
|||
and ${field} like CONCAT('%',#{content},'%') |
|||
</if> |
|||
</select> |
|||
</mapper> |
|||
@ -0,0 +1,25 @@ |
|||
<?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="cn.redrock.assetmanage.mapper.AmPublicAssetMapper"> |
|||
<resultMap id="BaseResultMap" type="cn.redrock.assetmanage.entity.AmPublicAsset"> |
|||
<result column="code" jdbcType="VARCHAR" property="code" /> |
|||
<result column="name" jdbcType="VARCHAR" property="name" /> |
|||
<result column="model_num" jdbcType="VARCHAR" property="modelNum" /> |
|||
<result column="company" jdbcType="VARCHAR" property="company" /> |
|||
<result column="num" jdbcType="INTEGER" property="num" /> |
|||
<result column="position" jdbcType="VARCHAR" property="position" /> |
|||
<result column="user_id" jdbcType="INTEGER" property="userId" /> |
|||
<result column="user_name" jdbcType="INTEGER" property="userName" /> |
|||
<result column="description" jdbcType="VARCHAR" property="description" /> |
|||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> |
|||
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> |
|||
</resultMap> |
|||
<select id="search" resultMap="BaseResultMap"> |
|||
select a.*,b.nickname user_name |
|||
from am_public_asset a left join am_user b on a.user_id=b.id |
|||
where 1=1 |
|||
<if test="field != null and field != '' and content != null and content != '' "> |
|||
and a.${field} like CONCAT('%',#{content},'%') |
|||
</if> |
|||
</select> |
|||
</mapper> |
|||
@ -0,0 +1,28 @@ |
|||
<?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="cn.redrock.assetmanage.mapper.AmStaffAssetMapper"> |
|||
<resultMap id="BaseResultMap" type="cn.redrock.assetmanage.entity.AmStaffAsset"> |
|||
<result column="id" jdbcType="INTEGER" property="id" /> |
|||
<result column="name" jdbcType="VARCHAR" property="name" /> |
|||
<result column="model_num" jdbcType="VARCHAR" property="modelNum" /> |
|||
<result column="num" jdbcType="INTEGER" property="num" /> |
|||
<result column="position" jdbcType="VARCHAR" property="position" /> |
|||
<result column="user_id" jdbcType="INTEGER" property="userId" /> |
|||
<result column="user_name" jdbcType="INTEGER" property="userName" /> |
|||
<result column="description" jdbcType="VARCHAR" property="description" /> |
|||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> |
|||
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> |
|||
</resultMap> |
|||
<select id="search" resultMap="BaseResultMap"> |
|||
select a.*,b.nickname user_name |
|||
from am_staff_asset a left join am_user b on a.user_id=b.id |
|||
where 1=1 |
|||
<if test="userId != null"> |
|||
and a.user_id=#{userId} |
|||
</if> |
|||
<if test="field != null and field != '' and content != null and content != '' "> |
|||
and a.${field} like CONCAT('%',#{content},'%') |
|||
</if> |
|||
</select> |
|||
|
|||
</mapper> |
|||
@ -0,0 +1,10 @@ |
|||
<?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="cn.redrock.assetmanage.mapper.AmTokenMapper"> |
|||
<resultMap id="BaseResultMap" type="cn.redrock.assetmanage.entity.AmToken"> |
|||
<id column="token" jdbcType="VARCHAR" property="token" /> |
|||
<result column="user_id" jdbcType="INTEGER" property="userId" /> |
|||
<result column="expire_time" jdbcType="TIMESTAMP" property="expireTime" /> |
|||
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> |
|||
</resultMap> |
|||
</mapper> |
|||
@ -0,0 +1,22 @@ |
|||
<?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="cn.redrock.assetmanage.mapper.AmUserMapper"> |
|||
<resultMap id="BaseResultMap" type="cn.redrock.assetmanage.entity.AmUser"> |
|||
<id column="id" jdbcType="INTEGER" property="id" /> |
|||
<result column="name" jdbcType="VARCHAR" property="name" /> |
|||
<result column="nickname" jdbcType="VARCHAR" property="nickname" /> |
|||
<result column="password" jdbcType="VARCHAR" property="password" /> |
|||
<result column="is_admin" jdbcType="INTEGER" property="isAdmin" /> |
|||
<result column="phone" jdbcType="VARCHAR" property="phone" /> |
|||
<result column="post" jdbcType="VARCHAR" property="post" /> |
|||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> |
|||
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> |
|||
</resultMap> |
|||
<select id="search" resultMap="BaseResultMap"> |
|||
select * from am_user |
|||
where 1=1 |
|||
<if test="field != null and field != '' and content != null and content != '' "> |
|||
and ${field} like CONCAT('%',#{content},'%') |
|||
</if> |
|||
</select> |
|||
</mapper> |
|||
@ -0,0 +1,16 @@ |
|||
package cn.redrock.assetmanage; |
|||
|
|||
import org.junit.Test; |
|||
import org.junit.runner.RunWith; |
|||
import org.springframework.boot.test.context.SpringBootTest; |
|||
import org.springframework.test.context.junit4.SpringRunner; |
|||
|
|||
@RunWith(SpringRunner.class) |
|||
@SpringBootTest |
|||
public class AssetManageApplicationTests { |
|||
|
|||
@Test |
|||
public void contextLoads() { |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
package cn.redrock.assetmanage; |
|||
|
|||
import org.junit.Test; |
|||
import org.junit.runner.RunWith; |
|||
import org.mybatis.generator.api.MyBatisGenerator; |
|||
import org.mybatis.generator.config.Configuration; |
|||
import org.mybatis.generator.config.xml.ConfigurationParser; |
|||
import org.mybatis.generator.internal.DefaultShellCallback; |
|||
import org.springframework.boot.test.context.SpringBootTest; |
|||
import org.springframework.test.context.junit4.SpringRunner; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
import static org.apache.ibatis.io.Resources.getResourceAsStream; |
|||
|
|||
@RunWith(SpringRunner.class) |
|||
@SpringBootTest |
|||
public class GeneratorTests { |
|||
|
|||
@Test |
|||
public void generate() throws Exception { |
|||
List<String> warnings = new ArrayList<String>(); |
|||
boolean overwrite = true; |
|||
ConfigurationParser cp = new ConfigurationParser(warnings); |
|||
Configuration config = cp.parseConfiguration(getResourceAsStream("generatorConfig.xml")); |
|||
DefaultShellCallback callback = new DefaultShellCallback(overwrite); |
|||
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings); |
|||
myBatisGenerator.generate(null); |
|||
for (String warning : warnings) { |
|||
System.out.println(warning); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,51 @@ |
|||
<!DOCTYPE generatorConfiguration |
|||
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" |
|||
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> |
|||
|
|||
<!--suppress MybatisGenerateCustomPluginInspection --> |
|||
<generatorConfiguration> |
|||
<context id="Mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat"> |
|||
<property name="javaFileEncoding" value="UTF-8"/> |
|||
<!--<property name="useMapperCommentGenerator" value="true"/>--> |
|||
|
|||
<!--通用 Mapper 插件,可以生成带注解的实体类--> |
|||
<plugin type="tk.mybatis.mapper.generator.MapperPlugin"> |
|||
<property name="mappers" value="tk.mybatis.mapper.common.Mapper"/> |
|||
<property name="caseSensitive" value="true"/> |
|||
<!--<property name="forceAnnotation" value="true"/>--> |
|||
<!--<property name="beginningDelimiter" value="`"/>--> |
|||
<!--<property name="endingDelimiter" value="`"/>--> |
|||
</plugin> |
|||
|
|||
<jdbcConnection driverClass="com.mysql.jdbc.Driver" |
|||
connectionURL="jdbc:mysql://localhost:3306/asset-manage" |
|||
userId="root" |
|||
password="root"> |
|||
</jdbcConnection> |
|||
|
|||
<!--MyBatis 生成器只需要生成 Model--> |
|||
<javaModelGenerator targetPackage="cn.redrock.assetmanage.entity" targetProject="src/main/java"/> |
|||
<sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources"/> |
|||
<javaClientGenerator targetPackage="cn.redrock.assetmanage.mapper" targetProject="src/main/java" |
|||
type="XMLMAPPER"/> |
|||
|
|||
<table tableName="am_user"> |
|||
<generatedKey column="id" sqlStatement="JDBC"/> |
|||
</table> |
|||
<table tableName="am_public_asset"> |
|||
<generatedKey column="code" sqlStatement="JDBC"/> |
|||
</table> |
|||
<table tableName="am_staff_asset"> |
|||
<generatedKey column="id" sqlStatement="JDBC"/> |
|||
</table> |
|||
<table tableName="am_material"> |
|||
<generatedKey column="code" sqlStatement="JDBC"/> |
|||
</table> |
|||
<table tableName="am_material_log"> |
|||
|
|||
</table> |
|||
<table tableName="am_token"> |
|||
|
|||
</table> |
|||
</context> |
|||
</generatorConfiguration> |
|||
Loading…
Reference in new issue