diff --git a/.gitignore b/.gitignore
index 63eb717..a2a3040 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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/
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..7a70690
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,141 @@
+
+
+ 4.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.1.3.RELEASE
+
+
+ cn.redrock
+ asset-manage
+ 0.0.1-SNAPSHOT
+ asset-manage
+ Demo project for Spring Boot
+
+
+ 1.8
+ 2.1.3.RELEASE
+ 1.2.55
+ 1.2.5
+ 2.0.2
+
+
+
+
+ org.projectlombok
+ lombok
+ provided
+
+
+ org.springframework.boot
+ spring-boot-starter
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ com.zaxxer
+ HikariCP
+ 3.2.0
+
+
+ mysql
+ mysql-connector-java
+
+
+ com.github.pagehelper
+ pagehelper-spring-boot-starter
+ 1.2.5
+
+
+ tk.mybatis
+ mapper-spring-boot-starter
+ ${tk.mybatis.starter.version}
+
+
+ tk.mybatis
+ mapper-generator
+ 1.0.0
+
+
+ org.mybatis.generator
+ mybatis-generator-core
+ 1.3.6
+ test
+
+
+ com.alibaba
+ fastjson
+ 1.2.54
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.apache.poi
+ poi
+ 3.17
+
+
+ org.apache.poi
+ poi-ooxml
+ 3.17
+
+
+
+ org.apache.commons
+ commons-lang3
+ 3.8.1
+
+
+
+ commons-collections
+ commons-collections
+ 3.2.2
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+ ${spring-boot.version}
+
+
+ org.springframework.boot
+ spring-boot-autoconfigure
+ ${spring-boot.version}
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ ${spring-boot.version}
+ test
+
+
+ org.projectlombok
+ lombok
+ ${lombok.version}
+ provided
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+ asset-manage
+
+
+
+
+
+
diff --git a/sql/asset_manage.sql b/sql/asset_manage.sql
new file mode 100644
index 0000000..03d83a7
--- /dev/null
+++ b/sql/asset_manage.sql
@@ -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
+);
+
+--- 编码是否要变
diff --git a/src/main/java/cn/redrock/assetmanage/AssetManageApplication.java b/src/main/java/cn/redrock/assetmanage/AssetManageApplication.java
new file mode 100644
index 0000000..7b3edb9
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/AssetManageApplication.java
@@ -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);
+ }
+
+}
diff --git a/src/main/java/cn/redrock/assetmanage/auth/Admin.java b/src/main/java/cn/redrock/assetmanage/auth/Admin.java
new file mode 100644
index 0000000..e414280
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/auth/Admin.java
@@ -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 {
+}
diff --git a/src/main/java/cn/redrock/assetmanage/auth/AuthIgnore.java b/src/main/java/cn/redrock/assetmanage/auth/AuthIgnore.java
new file mode 100644
index 0000000..f13d63c
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/auth/AuthIgnore.java
@@ -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 {
+
+}
\ No newline at end of file
diff --git a/src/main/java/cn/redrock/assetmanage/auth/AuthInterceptor.java b/src/main/java/cn/redrock/assetmanage/auth/AuthInterceptor.java
new file mode 100644
index 0000000..82fbba2
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/auth/AuthInterceptor.java
@@ -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));
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/cn/redrock/assetmanage/auth/CurrentUser.java b/src/main/java/cn/redrock/assetmanage/auth/CurrentUser.java
new file mode 100644
index 0000000..e93f24a
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/auth/CurrentUser.java
@@ -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 {
+}
diff --git a/src/main/java/cn/redrock/assetmanage/auth/CurrentUserResolver.java b/src/main/java/cn/redrock/assetmanage/auth/CurrentUserResolver.java
new file mode 100644
index 0000000..c02898e
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/auth/CurrentUserResolver.java
@@ -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");
+ }
+}
diff --git a/src/main/java/cn/redrock/assetmanage/auth/TokenUtil.java b/src/main/java/cn/redrock/assetmanage/auth/TokenUtil.java
new file mode 100644
index 0000000..821dfcf
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/auth/TokenUtil.java
@@ -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;
+ }
+}
diff --git a/src/main/java/cn/redrock/assetmanage/common/Constants.java b/src/main/java/cn/redrock/assetmanage/common/Constants.java
new file mode 100644
index 0000000..1363f77
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/common/Constants.java
@@ -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;
+ }
+ }
+}
diff --git a/src/main/java/cn/redrock/assetmanage/common/ResponseCode.java b/src/main/java/cn/redrock/assetmanage/common/ResponseCode.java
new file mode 100644
index 0000000..a0b2819
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/common/ResponseCode.java
@@ -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;
+ }
+}
diff --git a/src/main/java/cn/redrock/assetmanage/common/Result.java b/src/main/java/cn/redrock/assetmanage/common/Result.java
new file mode 100644
index 0000000..00a51e3
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/common/Result.java
@@ -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 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;
+ }
+}
diff --git a/src/main/java/cn/redrock/assetmanage/config/WebMvcConfig.java b/src/main/java/cn/redrock/assetmanage/config/WebMvcConfig.java
new file mode 100644
index 0000000..47a777b
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/config/WebMvcConfig.java
@@ -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 argumentResolvers) {
+ argumentResolvers.add(currentUserResolver());
+ super.addArgumentResolvers(argumentResolvers);
+ }
+ @Bean
+ public CurrentUserResolver currentUserResolver() {
+ return new CurrentUserResolver();
+ }
+}
diff --git a/src/main/java/cn/redrock/assetmanage/controller/MaterialController.java b/src/main/java/cn/redrock/assetmanage/controller/MaterialController.java
new file mode 100644
index 0000000..916b37c
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/controller/MaterialController.java
@@ -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 buildBatchLog(Integer userId,Constants.Operate operate, Constants.Status status,List materials){
+ List 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 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 list = ExcelUtils.readExcel(file,Material.class);
+ if(list == null || list.isEmpty()){
+ return Result.error(ResponseCode.EXCEL_PARSE_ERROR);
+ }
+ List successMaterial = new ArrayList<>();
+ List 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 list) {
+ List successMaterial = new ArrayList<>();
+ List 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 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 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));
+ }
+}
diff --git a/src/main/java/cn/redrock/assetmanage/controller/PublicAssetController.java b/src/main/java/cn/redrock/assetmanage/controller/PublicAssetController.java
new file mode 100644
index 0000000..5a4b795
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/controller/PublicAssetController.java
@@ -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 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);
+ }
+}
diff --git a/src/main/java/cn/redrock/assetmanage/controller/StaffAssetController.java b/src/main/java/cn/redrock/assetmanage/controller/StaffAssetController.java
new file mode 100644
index 0000000..758fcf9
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/controller/StaffAssetController.java
@@ -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 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 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);
+ }
+}
diff --git a/src/main/java/cn/redrock/assetmanage/controller/UserController.java b/src/main/java/cn/redrock/assetmanage/controller/UserController.java
new file mode 100644
index 0000000..e837eb1
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/controller/UserController.java
@@ -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 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 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));
+ }
+}
diff --git a/src/main/java/cn/redrock/assetmanage/dto/Asset.java b/src/main/java/cn/redrock/assetmanage/dto/Asset.java
new file mode 100644
index 0000000..90ce1fc
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/dto/Asset.java
@@ -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;
+}
diff --git a/src/main/java/cn/redrock/assetmanage/dto/Material.java b/src/main/java/cn/redrock/assetmanage/dto/Material.java
new file mode 100644
index 0000000..d0004ff
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/dto/Material.java
@@ -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;
+}
diff --git a/src/main/java/cn/redrock/assetmanage/dto/PublicAsset.java b/src/main/java/cn/redrock/assetmanage/dto/PublicAsset.java
new file mode 100644
index 0000000..968cf55
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/dto/PublicAsset.java
@@ -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;
+}
diff --git a/src/main/java/cn/redrock/assetmanage/dto/UserBase.java b/src/main/java/cn/redrock/assetmanage/dto/UserBase.java
new file mode 100644
index 0000000..c6e8e2a
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/dto/UserBase.java
@@ -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;
+}
diff --git a/src/main/java/cn/redrock/assetmanage/dto/UserInfo.java b/src/main/java/cn/redrock/assetmanage/dto/UserInfo.java
new file mode 100644
index 0000000..121930d
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/dto/UserInfo.java
@@ -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;
+}
diff --git a/src/main/java/cn/redrock/assetmanage/dto/UserNewPassword.java b/src/main/java/cn/redrock/assetmanage/dto/UserNewPassword.java
new file mode 100644
index 0000000..4ffeb62
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/dto/UserNewPassword.java
@@ -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;
+}
diff --git a/src/main/java/cn/redrock/assetmanage/entity/AmMaterial.java b/src/main/java/cn/redrock/assetmanage/entity/AmMaterial.java
new file mode 100644
index 0000000..f052485
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/entity/AmMaterial.java
@@ -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();
+}
\ No newline at end of file
diff --git a/src/main/java/cn/redrock/assetmanage/entity/AmMaterialLog.java b/src/main/java/cn/redrock/assetmanage/entity/AmMaterialLog.java
new file mode 100644
index 0000000..04d7d58
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/entity/AmMaterialLog.java
@@ -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;
+}
\ No newline at end of file
diff --git a/src/main/java/cn/redrock/assetmanage/entity/AmPublicAsset.java b/src/main/java/cn/redrock/assetmanage/entity/AmPublicAsset.java
new file mode 100644
index 0000000..3434f30
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/entity/AmPublicAsset.java
@@ -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();
+}
\ No newline at end of file
diff --git a/src/main/java/cn/redrock/assetmanage/entity/AmStaffAsset.java b/src/main/java/cn/redrock/assetmanage/entity/AmStaffAsset.java
new file mode 100644
index 0000000..ba9765d
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/entity/AmStaffAsset.java
@@ -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();
+}
\ No newline at end of file
diff --git a/src/main/java/cn/redrock/assetmanage/entity/AmToken.java b/src/main/java/cn/redrock/assetmanage/entity/AmToken.java
new file mode 100644
index 0000000..3bbc0e7
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/entity/AmToken.java
@@ -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();
+}
\ No newline at end of file
diff --git a/src/main/java/cn/redrock/assetmanage/entity/AmUser.java b/src/main/java/cn/redrock/assetmanage/entity/AmUser.java
new file mode 100644
index 0000000..faf3fc0
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/entity/AmUser.java
@@ -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();
+}
\ No newline at end of file
diff --git a/src/main/java/cn/redrock/assetmanage/entity/MaterialInfo.java b/src/main/java/cn/redrock/assetmanage/entity/MaterialInfo.java
new file mode 100644
index 0000000..baccac0
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/entity/MaterialInfo.java
@@ -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;
+}
diff --git a/src/main/java/cn/redrock/assetmanage/mapper/AmMaterialLogMapper.java b/src/main/java/cn/redrock/assetmanage/mapper/AmMaterialLogMapper.java
new file mode 100644
index 0000000..aa210df
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/mapper/AmMaterialLogMapper.java
@@ -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 {
+ List 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);
+}
\ No newline at end of file
diff --git a/src/main/java/cn/redrock/assetmanage/mapper/AmMaterialMapper.java b/src/main/java/cn/redrock/assetmanage/mapper/AmMaterialMapper.java
new file mode 100644
index 0000000..f37aeac
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/mapper/AmMaterialMapper.java
@@ -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 {
+ @Select(value = "select * from am_material where code=#{code}")
+ AmMaterial find(String code);
+ List search(@Param("field") String field, @Param("content") String content);
+ @Select(value = "select * from am_material where num / base_num < #{limit}")
+ List warn(Float limit);
+}
\ No newline at end of file
diff --git a/src/main/java/cn/redrock/assetmanage/mapper/AmPublicAssetMapper.java b/src/main/java/cn/redrock/assetmanage/mapper/AmPublicAssetMapper.java
new file mode 100644
index 0000000..0fa1b94
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/mapper/AmPublicAssetMapper.java
@@ -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 {
+ @Select(value = "select * from am_public_asset where code=#{code}")
+ AmPublicAsset findByKey(String code);
+ List search(@Param("field") String field,@Param("content") String content);
+}
\ No newline at end of file
diff --git a/src/main/java/cn/redrock/assetmanage/mapper/AmStaffAssetMapper.java b/src/main/java/cn/redrock/assetmanage/mapper/AmStaffAssetMapper.java
new file mode 100644
index 0000000..2f70ee2
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/mapper/AmStaffAssetMapper.java
@@ -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 {
+ List 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);
+}
\ No newline at end of file
diff --git a/src/main/java/cn/redrock/assetmanage/mapper/AmTokenMapper.java b/src/main/java/cn/redrock/assetmanage/mapper/AmTokenMapper.java
new file mode 100644
index 0000000..50a9666
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/mapper/AmTokenMapper.java
@@ -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 {
+ @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);
+}
\ No newline at end of file
diff --git a/src/main/java/cn/redrock/assetmanage/mapper/AmUserMapper.java b/src/main/java/cn/redrock/assetmanage/mapper/AmUserMapper.java
new file mode 100644
index 0000000..0c266a0
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/mapper/AmUserMapper.java
@@ -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 {
+ @Select(value = "select * from am_user where name=#{name}")
+ AmUser findUserByName(String name);
+ List search(@Param("field") String field, @Param("content") String content);
+}
\ No newline at end of file
diff --git a/src/main/java/cn/redrock/assetmanage/service/MaterialLogService.java b/src/main/java/cn/redrock/assetmanage/service/MaterialLogService.java
new file mode 100644
index 0000000..5a969f4
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/service/MaterialLogService.java
@@ -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 materialLogs);
+ void updateLog(List materials,Integer status);
+ PageInfo queryLog(Integer operate, Integer status,String field,String content, Date startTm, Date endTm,Integer pageNum, Integer pageSize);
+}
diff --git a/src/main/java/cn/redrock/assetmanage/service/MaterialService.java b/src/main/java/cn/redrock/assetmanage/service/MaterialService.java
new file mode 100644
index 0000000..8fcda01
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/service/MaterialService.java
@@ -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 materials,boolean isOverride);
+ boolean sub(Material material);
+ void batchSub(List materials,List successMaterials,List failMaterials);
+ List search(String field, String content, Integer pageNum, Integer pageSize);
+ boolean update(Material material);
+ boolean delete(String code);
+ PageInfo warn(Integer pageNum, Integer pageSize);
+}
diff --git a/src/main/java/cn/redrock/assetmanage/service/PublicAssetService.java b/src/main/java/cn/redrock/assetmanage/service/PublicAssetService.java
new file mode 100644
index 0000000..48c6875
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/service/PublicAssetService.java
@@ -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 search(String field, String content, Integer pageNum, Integer pageSize);
+ boolean update(PublicAsset publicAsset);
+ boolean delete(String code);
+}
diff --git a/src/main/java/cn/redrock/assetmanage/service/StaffAssetService.java b/src/main/java/cn/redrock/assetmanage/service/StaffAssetService.java
new file mode 100644
index 0000000..fbbd5a4
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/service/StaffAssetService.java
@@ -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 search(Integer userId,String field, String content, Integer pageNum, Integer pageSize);
+ boolean update(Asset asset);
+ boolean delete(Integer id);
+}
diff --git a/src/main/java/cn/redrock/assetmanage/service/TokenService.java b/src/main/java/cn/redrock/assetmanage/service/TokenService.java
new file mode 100644
index 0000000..70f431f
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/service/TokenService.java
@@ -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 createToken(Integer userId);
+ AmUser getUserByToken(String token);
+ void deleteToken(String token);
+}
diff --git a/src/main/java/cn/redrock/assetmanage/service/UserService.java b/src/main/java/cn/redrock/assetmanage/service/UserService.java
new file mode 100644
index 0000000..d75ef7a
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/service/UserService.java
@@ -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 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 authUser(UserBase user);
+ void logout(String token);
+ String encode(String password);
+}
diff --git a/src/main/java/cn/redrock/assetmanage/service/impl/MaterialLogServiceImpl.java b/src/main/java/cn/redrock/assetmanage/service/impl/MaterialLogServiceImpl.java
new file mode 100644
index 0000000..b2b6fc8
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/service/impl/MaterialLogServiceImpl.java
@@ -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 materialLogs) {
+ for(AmMaterialLog materialLog : materialLogs){
+ materialLogMapper.insert(materialLog);
+ }
+ }
+
+ @Override
+ public void updateLog(List 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 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));
+ }
+}
diff --git a/src/main/java/cn/redrock/assetmanage/service/impl/MaterialServiceImpl.java b/src/main/java/cn/redrock/assetmanage/service/impl/MaterialServiceImpl.java
new file mode 100644
index 0000000..14db800
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/service/impl/MaterialServiceImpl.java
@@ -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 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 materials,List successMaterials,List 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 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 warn(Integer pageNum, Integer pageSize) {
+ if(pageNum != null && pageSize != null){
+ PageHelper.startPage(pageNum, pageSize);
+ }
+ return PageInfo.of(materialMapper.warn(limit));
+ }
+}
diff --git a/src/main/java/cn/redrock/assetmanage/service/impl/PublicAssetServiceImpl.java b/src/main/java/cn/redrock/assetmanage/service/impl/PublicAssetServiceImpl.java
new file mode 100644
index 0000000..d9eefe0
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/service/impl/PublicAssetServiceImpl.java
@@ -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 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;
+ }
+}
diff --git a/src/main/java/cn/redrock/assetmanage/service/impl/StaffAssetServiceImpl.java b/src/main/java/cn/redrock/assetmanage/service/impl/StaffAssetServiceImpl.java
new file mode 100644
index 0000000..07bc010
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/service/impl/StaffAssetServiceImpl.java
@@ -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 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;
+ }
+}
diff --git a/src/main/java/cn/redrock/assetmanage/service/impl/TokenServiceImpl.java b/src/main/java/cn/redrock/assetmanage/service/impl/TokenServiceImpl.java
new file mode 100644
index 0000000..bf770e2
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/service/impl/TokenServiceImpl.java
@@ -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 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 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);
+ }
+}
diff --git a/src/main/java/cn/redrock/assetmanage/service/impl/UserServiceImpl.java b/src/main/java/cn/redrock/assetmanage/service/impl/UserServiceImpl.java
new file mode 100644
index 0000000..87556f6
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/service/impl/UserServiceImpl.java
@@ -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 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 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();
+ }
+}
diff --git a/src/main/java/cn/redrock/assetmanage/utils/BeanUtilsExt.java b/src/main/java/cn/redrock/assetmanage/utils/BeanUtilsExt.java
new file mode 100644
index 0000000..da31364
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/utils/BeanUtilsExt.java
@@ -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 emptyNames = new HashSet();
+ 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));
+ }
+}
diff --git a/src/main/java/cn/redrock/assetmanage/utils/DateUtil.java b/src/main/java/cn/redrock/assetmanage/utils/DateUtil.java
new file mode 100644
index 0000000..62585b4
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/utils/DateUtil.java
@@ -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;
+ }
+}
diff --git a/src/main/java/cn/redrock/assetmanage/utils/ExcelColumn.java b/src/main/java/cn/redrock/assetmanage/utils/ExcelColumn.java
new file mode 100644
index 0000000..dd62b2c
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/utils/ExcelColumn.java
@@ -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;
+}
\ No newline at end of file
diff --git a/src/main/java/cn/redrock/assetmanage/utils/ExcelUtils.java b/src/main/java/cn/redrock/assetmanage/utils/ExcelUtils.java
new file mode 100644
index 0000000..b893f09
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/utils/ExcelUtils.java
@@ -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 List readExcel( MultipartFile file,Class cls){
+ String fileName = file.getOriginalFilename();
+ if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
+ log.error("上传文件格式不正确");
+ return null;
+ }
+ List 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> classMap = new HashMap<>();
+ List 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> 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 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 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 Workbook writeExcel(List dataList, Class cls){
+ Field[] fields = cls.getDeclaredFields();
+ List 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();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/cn/redrock/assetmanage/utils/StringUtil.java b/src/main/java/cn/redrock/assetmanage/utils/StringUtil.java
new file mode 100644
index 0000000..fd090d2
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/utils/StringUtil.java
@@ -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;
+ }
+
+
+}
diff --git a/src/main/java/cn/redrock/assetmanage/utils/UUIDUtil.java b/src/main/java/cn/redrock/assetmanage/utils/UUIDUtil.java
new file mode 100644
index 0000000..9a1eb2e
--- /dev/null
+++ b/src/main/java/cn/redrock/assetmanage/utils/UUIDUtil.java
@@ -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("-", "");
+ }
+
+}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
new file mode 100644
index 0000000..5059512
--- /dev/null
+++ b/src/main/resources/application.yml
@@ -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
diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml
new file mode 100644
index 0000000..c6ab5e4
--- /dev/null
+++ b/src/main/resources/logback-spring.xml
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+ ${PATTERN}
+
+
+
+
+ ${ROOT_DIR}/${APP_NAME}/info.log
+
+ ${ROOT_DIR}/${APP_NAME}/%d{yyyy-MM-dd}-info.log.gz
+ 7
+
+
+ ${PATTERN}
+
+
+
+
+
+ ERROR
+
+ ${ROOT_DIR}/${APP_NAME}/error.log
+
+ ${ROOT_DIR}/${APP_NAME}/%d{yyyy-MM-dd}-error.log.%i
+
+ 500MB
+
+ 7
+
+
+ ${PATTERN}
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/mapper/AmMaterialLogMapper.xml b/src/main/resources/mapper/AmMaterialLogMapper.xml
new file mode 100644
index 0000000..d746d66
--- /dev/null
+++ b/src/main/resources/mapper/AmMaterialLogMapper.xml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/mapper/AmMaterialMapper.xml b/src/main/resources/mapper/AmMaterialMapper.xml
new file mode 100644
index 0000000..f4f22b2
--- /dev/null
+++ b/src/main/resources/mapper/AmMaterialMapper.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/mapper/AmPublicAssetMapper.xml b/src/main/resources/mapper/AmPublicAssetMapper.xml
new file mode 100644
index 0000000..2047831
--- /dev/null
+++ b/src/main/resources/mapper/AmPublicAssetMapper.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/mapper/AmStaffAssetMapper.xml b/src/main/resources/mapper/AmStaffAssetMapper.xml
new file mode 100644
index 0000000..8c92f48
--- /dev/null
+++ b/src/main/resources/mapper/AmStaffAssetMapper.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/mapper/AmTokenMapper.xml b/src/main/resources/mapper/AmTokenMapper.xml
new file mode 100644
index 0000000..8314e96
--- /dev/null
+++ b/src/main/resources/mapper/AmTokenMapper.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/mapper/AmUserMapper.xml b/src/main/resources/mapper/AmUserMapper.xml
new file mode 100644
index 0000000..0640477
--- /dev/null
+++ b/src/main/resources/mapper/AmUserMapper.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/test/java/cn/redrock/assetmanage/AssetManageApplicationTests.java b/src/test/java/cn/redrock/assetmanage/AssetManageApplicationTests.java
new file mode 100644
index 0000000..f87ea69
--- /dev/null
+++ b/src/test/java/cn/redrock/assetmanage/AssetManageApplicationTests.java
@@ -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() {
+ }
+
+}
diff --git a/src/test/java/cn/redrock/assetmanage/GeneratorTests.java b/src/test/java/cn/redrock/assetmanage/GeneratorTests.java
new file mode 100644
index 0000000..b90244c
--- /dev/null
+++ b/src/test/java/cn/redrock/assetmanage/GeneratorTests.java
@@ -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 warnings = new ArrayList();
+ 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);
+ }
+ }
+}
+
diff --git a/src/test/resources/generatorConfig.xml b/src/test/resources/generatorConfig.xml
new file mode 100644
index 0000000..111af79
--- /dev/null
+++ b/src/test/resources/generatorConfig.xml
@@ -0,0 +1,51 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file