diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/.gitignore b/src/arm-equipment-system-parent/arm-equipment-system-parent/.gitignore new file mode 100644 index 0000000..918bde7 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/.gitignore @@ -0,0 +1,31 @@ +HELP.md +**/target/ +!.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/src/arm-equipment-system-parent/arm-equipment-system-parent/README.md b/src/arm-equipment-system-parent/arm-equipment-system-parent/README.md new file mode 100644 index 0000000..7249966 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/README.md @@ -0,0 +1,5 @@ +# + + + +### diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/pom.xml b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/pom.xml new file mode 100644 index 0000000..77f377f --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/pom.xml @@ -0,0 +1,99 @@ + + + 4.0.0 + + com.arm.equipment.system + arm-equipment-system-parent + 0.0.1-SNAPSHOT + + jar + admin + 0.0.1-SNAPSHOT + admin + Demo project for Spring Boot + + + 1.8 + + + + + com.arm.equipment.system + data + 0.0.1-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.springframework.session + spring-session-data-redis + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + javax.servlet + javax.servlet-api + + + + mysql + mysql-connector-java + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-web + + + + org.apache.commons + commons-lang3 + + + + com.alibaba + fastjson + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.springframework.retry + spring-retry + + + + + + arm-equipment-system-parent-${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/app/AdminApplication.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/app/AdminApplication.java new file mode 100644 index 0000000..32dc9a8 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/app/AdminApplication.java @@ -0,0 +1,39 @@ +package com.arm.equipment.system.admin.app; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.ServletListenerRegistrationBean; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; +import org.springframework.transaction.annotation.EnableTransactionManagement; +import org.springframework.web.util.IntrospectorCleanupListener; + +/** + * 工程启动配置 + * + * @author admin + */ +@SpringBootApplication +@ComponentScan("com.arm.equipment.system") +@EnableTransactionManagement +@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 86400) +@EnableAsync +@EnableCaching +@EnableScheduling +public class AdminApplication { + + public static void main(String[] args) { + SpringApplication.run(AdminApplication.class, args); + } + + @Bean + public ServletListenerRegistrationBean introspectorCleanupListener() { + ServletListenerRegistrationBean listenerRegistration = new ServletListenerRegistrationBean(); + listenerRegistration.setListener(new IntrospectorCleanupListener()); + return listenerRegistration; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/app/AdminCorsConfiguration.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/app/AdminCorsConfiguration.java new file mode 100644 index 0000000..54f5f01 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/app/AdminCorsConfiguration.java @@ -0,0 +1,38 @@ +package com.arm.equipment.system.admin.app; + + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * CORS配置 + */ +@Configuration +public class AdminCorsConfiguration { + + @Bean + public CorsFilter corsFilter() { + // 添加CORS配置信息 + CorsConfiguration config = new CorsConfiguration(); + // 放行哪些原始域 + config.addAllowedOriginPattern("*"); + // 是否发送Cookie信息 + config.setAllowCredentials(true); + // 放行哪些原始域(请求方式) + config.addAllowedMethod("*"); + // 放行哪些原始域(头部信息) + config.addAllowedHeader("*"); + // 暴露哪些头部信息(因为跨域访问默认不能获取全部头部信息) + // config.addExposedHeader("*"); + + //2.添加映射路径 + UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource(); + configSource.registerCorsConfiguration("/**", config); + + //3.返回新的CorsFilter. + return new CorsFilter(configSource); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/app/InterceptorConfiguration.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/app/InterceptorConfiguration.java new file mode 100644 index 0000000..80a1a46 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/app/InterceptorConfiguration.java @@ -0,0 +1,80 @@ +package com.arm.equipment.system.admin.app; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import com.arm.equipment.system.admin.filter.LoginPermissionsFilter; +import com.arm.equipment.system.admin.filter.SysLogFilter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; + +import java.math.BigInteger; +import java.util.List; + +/** + * @author: admin + * @time: 2022/9/16 11:20 + */ +@Configuration +public class InterceptorConfiguration extends WebMvcConfigurationSupport { + @Autowired + private LoginPermissionsFilter loginPermissionsFilter; + @Autowired + private SysLogFilter sysLogFilter; + + @Override + protected void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(sysLogFilter).addPathPatterns("/**/*"); + registry.addInterceptor(loginPermissionsFilter).addPathPatterns("/**/*") + .excludePathPatterns("/file/**");; + super.addInterceptors(registry); + } + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + /** + * @Description: 对文件的路径进行配置, 创建一个虚拟路径/Path/** ,即只要在便可以直接引用图片 + *这是图片的物理路径 "file:/+本地图片的地址" + */ + String os = System.getProperty("os.name"); + //Windows操作系统 + String resourcePath = System.getProperty("user.dir"); + if (os != null && os.toLowerCase().startsWith("windows")) { + resourcePath = resourcePath + "\\"; + } else { + resourcePath = resourcePath + "/"; + } + registry.addResourceHandler("/file/**").addResourceLocations("file:" + resourcePath); + super.addResourceHandlers(registry); + } + + @Override + protected void extendMessageConverters(List> converters) { + MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter(); + ObjectMapper objectMapper = new ObjectMapper(); + /** + * 序列换成json时,将所有的long变成string + * 因为js中得数字类型不能包含所有的java long值 + */ + SimpleModule simpleModule = new SimpleModule(); + simpleModule.addSerializer(Long.class, ToStringSerializer.instance); + simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); + simpleModule.addSerializer(BigInteger.class, ToStringSerializer.instance); + + // 反序列化时忽略多余字段 + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + + // 注册 + objectMapper.registerModule(simpleModule); + jackson2HttpMessageConverter.setObjectMapper(objectMapper); + converters.add(0, jackson2HttpMessageConverter); + super.extendMessageConverters(converters); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/app/RedisListenerConfiguration.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/app/RedisListenerConfiguration.java new file mode 100644 index 0000000..c7ae4eb --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/app/RedisListenerConfiguration.java @@ -0,0 +1,17 @@ +package com.arm.equipment.system.admin.app; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.listener.RedisMessageListenerContainer; + +@Configuration +public class RedisListenerConfiguration { + + @Bean + RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory lettuceConnectionFactory) { + RedisMessageListenerContainer container = new RedisMessageListenerContainer(); + container.setConnectionFactory(lettuceConnectionFactory); + return container; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/app/SchedulerConfiguration.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/app/SchedulerConfiguration.java new file mode 100644 index 0000000..ad829b1 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/app/SchedulerConfiguration.java @@ -0,0 +1,29 @@ +package com.arm.equipment.system.admin.app; + + +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.SchedulingConfigurer; +import org.springframework.scheduling.config.ScheduledTaskRegistrar; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; + +/** + * 定时任务配置 + * @author admin + */ +@Configuration +public class SchedulerConfiguration implements SchedulingConfigurer { + @Override + public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { + taskRegistrar.setScheduler(taskExecutor()); + } + + /** + * 创建线程池 + * @return + */ + public ScheduledExecutorService taskExecutor() { + return Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors() + 1); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/BaseController.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/BaseController.java new file mode 100644 index 0000000..1f6529a --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/BaseController.java @@ -0,0 +1,12 @@ +package com.arm.equipment.system.admin.controller; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * 接口的基础类 + * @author admin + */ +public abstract class BaseController{ + protected Logger logger = LoggerFactory.getLogger(this.getClass()); +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/ExceptionController.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/ExceptionController.java new file mode 100644 index 0000000..3f5ad5a --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/ExceptionController.java @@ -0,0 +1,131 @@ +package com.arm.equipment.system.admin.controller; + + +import com.alibaba.fastjson.JSON; +import com.arm.equipment.system.data.exception.AuthException; +import com.arm.equipment.system.data.exception.BusinessException; +import com.arm.equipment.system.data.vo.RespJSON; +import com.arm.equipment.system.data.vo.ReturnCode; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.QueryTimeoutException; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.validation.BindException; +import org.springframework.validation.FieldError; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; + +import javax.servlet.http.HttpServletRequest; +import java.text.ParseException; + +/** + * 统一异常处理 + * + * @author admin + */ +@ControllerAdvice +public class ExceptionController { + private final static Logger LOGGER = LoggerFactory.getLogger(ExceptionController.class); + @Autowired + private RedisTemplate redisTemplate; + + @ExceptionHandler(value = IllegalArgumentException.class) + @ResponseBody + public RespJSON illegalArgumentException(HttpServletRequest req, Exception e) { + logErrDetail(req); + return RespJSON.returnCodeWithMessage(ReturnCode.CUSTOM_MESSAGE, "参数错误: " + e.getMessage()); + } + + @ExceptionHandler(value = MethodArgumentTypeMismatchException.class) + @ResponseBody + public RespJSON methodArgumentTypeMismatchException(HttpServletRequest req, Exception e) { + logErrDetail(req); + String field = ((MethodArgumentTypeMismatchException) e).getName(); + String rejectedValue = ((MethodArgumentTypeMismatchException) e).getValue().toString(); + String message = "参数:" + field + "注入的值不合法:" + rejectedValue; + LOGGER.error("入参错误", e); + return RespJSON.returnCodeWithMessage(ReturnCode.CUSTOM_MESSAGE, message); + } + + @ExceptionHandler(value = BusinessException.class) + @ResponseBody + public RespJSON customException(HttpServletRequest req, BusinessException e) { + //投票成功返自定义message + if (e.getErrorCode() != null && StringUtils.isNotBlank(e.getMessage())) { + return RespJSON.returnCustomCodeWithMessage(e.getErrorCode(), e.getMessage()); + } + LOGGER.info("自定义异常: {}", e.getMessage()); + LOGGER.info("异常请求: {}", req.getRequestURI()); + LOGGER.info("异常参数: {}", JSON.toJSONString(req.getParameterMap())); + return RespJSON.returnCodeWithMessage(ReturnCode.CUSTOM_MESSAGE, e.getMessage()); + } + + @ExceptionHandler(value = AuthException.class) + @ResponseBody + public RespJSON authException(HttpServletRequest req, AuthException e) { + logErrDetail(req); + if (e.getReturnCode() != null) { + return RespJSON.returnCode(e.getReturnCode()); + } else { + return RespJSON.returnCode(ReturnCode.CODE_OK, e.getMessage()); + } + } + + @ExceptionHandler(value = BindException.class) + @ResponseBody + public RespJSON bindException(HttpServletRequest req, Exception e) { + logErrDetail(req); + FieldError fieldError = ((BindException) e).getBindingResult().getFieldError(); + String field = fieldError.getField(); + Object rejectedValue = fieldError.getRejectedValue(); + String message = "参数:" + field + "注入的值不合法:" + rejectedValue; + LOGGER.error("入参错误", e); + return RespJSON.returnCodeWithMessage(ReturnCode.CUSTOM_MESSAGE, message); + } + + @ExceptionHandler(value = ParseException.class) + @ResponseBody + public RespJSON parseException(HttpServletRequest req, Exception e) { + logErrDetail(req); + return RespJSON.returnCode(ReturnCode.PARSE_ERROR); + } + + @ExceptionHandler(value = QueryTimeoutException.class) + @ResponseBody + public RespJSON queryTimeoutException(HttpServletRequest req, Exception e) { + logErrDetail(req); + LOGGER.error(e.getMessage(), e); + ((LettuceConnectionFactory) redisTemplate.getConnectionFactory()).resetConnection(); + ((LettuceConnectionFactory) redisTemplate.getConnectionFactory()).afterPropertiesSet(); + LOGGER.info("reset redis connection"); + return RespJSON.returnCode(ReturnCode.SYS_ERROR); + } + +// @ExceptionHandler(value = MethodNotSupportedException.class) +// @ResponseBody +// public RespJSON httpRequestMethodNotSupportedException(HttpServletRequest req, Exception e) { +// logErrDetail(req); +// return RespJSON.genJsonResultWithMsgData(ReturnCode.CUSTOM_MESSAGE, "请求方式不支持!"); +// } + + @ExceptionHandler(value = Exception.class) + @ResponseBody + public RespJSON defaultErrorHandler(HttpServletRequest req, Exception e) { + logErrDetail(req); + LOGGER.error(e.getMessage(), e); + return RespJSON.returnCode(ReturnCode.SYS_ERROR); + } + + + private void logErrDetail(HttpServletRequest req) { + LOGGER.error("异常请求: " + req.getRequestURI()); + LOGGER.error("异常参数: " + JSON.toJSONString(req.getParameterMap())); + LOGGER.error("异常UA: {}", req.getHeader("user-agent")); + LOGGER.error("异常referer: {}", req.getHeader("referer")); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/common/DictController.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/common/DictController.java new file mode 100644 index 0000000..f2f64c8 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/common/DictController.java @@ -0,0 +1,33 @@ +package com.arm.equipment.system.admin.controller.common; + +import com.arm.equipment.system.data.service.common.IDictService; +import com.arm.equipment.system.data.vo.RespJSON; +import com.arm.equipment.system.data.vo.dict.DictVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * 字典接口 + */ +@RestController +@RequestMapping("/common/dict") +public class DictController { + @Autowired + private IDictService dictService; + + /** + * 统计枚举名称获得枚举的数据 + * + * @param name 枚举名称, 枚举文件必须在com.arm.equipment.system.data.enums.dict包下 + * @return + */ + @RequestMapping("/getDictDataByName/{name}") + public RespJSON getDictDataByName(@PathVariable String name) { + List dictData = dictService.getDictData(name); + return RespJSON.success(dictData); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/file/UploadController.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/file/UploadController.java new file mode 100644 index 0000000..24afa35 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/file/UploadController.java @@ -0,0 +1,53 @@ +package com.arm.equipment.system.admin.controller.file; + +import com.arm.equipment.system.admin.controller.BaseController; +import com.arm.equipment.system.data.enums.file.EnumUpload; +import com.arm.equipment.system.data.exception.BusinessException; +import com.arm.equipment.system.data.service.file.IFileService; +import com.arm.equipment.system.data.util.StringUtils; +import com.arm.equipment.system.data.vo.RespJSON; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +/** + * 公共文件上传接口 + * + * @author: xly + * @time: 2023/3/10 10:56 + */ +@RestController +@RequestMapping("/file/upload") +public class UploadController extends BaseController { + @Autowired + private IFileService fileService; + + /** + * 文件上传接口 + * + * @param file + * @return + */ + @PostMapping("/upload") + public RespJSON upload(String uploadItem, @RequestParam("file") MultipartFile file) { + if (null == file) { + throw new BusinessException("文件不合法"); + } + EnumUpload enumUploadItem = EnumUpload.RES_PHOTO_LIB; + if (StringUtils.isNotBlank(uploadItem)) { + enumUploadItem = EnumUpload.getEnum(uploadItem); + } + if (enumUploadItem == null) { + throw new BusinessException("上传文件类目不正确"); + } + try { + return RespJSON.success(fileService.upload(file, enumUploadItem)); + } catch (Exception e) { + logger.error("文件上传错误", e); + throw new BusinessException("文件上传错误"); + } + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/system/SysBaseParamController.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/system/SysBaseParamController.java new file mode 100644 index 0000000..0fb302c --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/system/SysBaseParamController.java @@ -0,0 +1,132 @@ +package com.arm.equipment.system.admin.controller.system; + +import com.arm.equipment.system.admin.controller.BaseController; +import com.arm.equipment.system.admin.util.CurrentUserUtils; +import com.arm.equipment.system.data.domain.PageResult; +import com.arm.equipment.system.data.domain.system.SysBaseParam; +import com.arm.equipment.system.data.domain.system.SysUser; +import com.arm.equipment.system.data.service.system.ISysBaseParamService; +import com.arm.equipment.system.data.util.WJAssert; +import com.arm.equipment.system.data.vo.RespJSON; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.List; + +/** + * 系统--基础参数 + * + * @author Administrator + * @date 2021年10月26日 16:36:52 + */ +@RestController +@RequestMapping("/system/sysBaseParam") +public class SysBaseParamController extends BaseController { + + @Autowired + private ISysBaseParamService sysBaseParamService; + + /** + * 保存或更新 + * + * @param sysBaseParamReq sysBaseParamReq + * @return RespJSON + */ + @PostMapping("/save") + public RespJSON save(@RequestBody SysBaseParam sysBaseParamReq, @SessionAttribute(CurrentUserUtils.SYSTEM_USER) SysUser loginSysUser) { + sysBaseParamService.save(sysBaseParamReq, loginSysUser.getUsername()); + return RespJSON.success(); + } + + /** + * 分页查询 + * + * @param sysBaseParamReq sysBaseParamReq + * @return RespJSON + */ + @PostMapping("/getPageList") + public RespJSON getPageList(@RequestBody SysBaseParam sysBaseParamReq) { + int count = sysBaseParamService.getCount(sysBaseParamReq); + List list = new ArrayList<>(); + if (count > 0) { + list = sysBaseParamService.getPageList(sysBaseParamReq); + } + PageResult result = new PageResult(sysBaseParamReq.getPageNo(), sysBaseParamReq.getPageSize(), count, list); + return RespJSON.success(result); + } + + /** + * 主键查询 + * + * @param id id + * @return RespJSON + */ + @RequestMapping("/getOneById") + public RespJSON getOneById(Long id) { + return RespJSON.success(sysBaseParamService.getOneById(id)); + } + + /** + * 审核 + * + * @param id id + * @return RespJSON + */ + @PostMapping("/audit") + @ResponseBody + public RespJSON audit(Long id, @SessionAttribute(CurrentUserUtils.SYSTEM_USER) SysUser loginSysUser) { + WJAssert.notNull(id, "ID 不合法"); + sysBaseParamService.audit(id, loginSysUser.getUsername()); + return RespJSON.success(); + } + + @PostMapping("/delete") + public RespJSON delete(Long id, @SessionAttribute(CurrentUserUtils.SYSTEM_USER) SysUser loginSysUser) { + WJAssert.notNull(id, "ID 不合法"); + sysBaseParamService.delete(id, loginSysUser.getUsername()); + return RespJSON.success(); + } + + /** + * 取消审核 + * + * @param id id + * @return RespJSON + */ + @PostMapping("/unaudit") + @ResponseBody + public RespJSON unaudit(Long id, @SessionAttribute(CurrentUserUtils.SYSTEM_USER) SysUser loginSysUser) { + WJAssert.notNull(id, "ID 不合法"); + sysBaseParamService.unaudit(id, loginSysUser.getUsername()); + return RespJSON.success(); + } + + /** + * 通过code查value + * + * @param unicode + * @return + */ + @PostMapping("/selectValueByUnicode") + public RespJSON selectValueByUnicode(String unicode) { + WJAssert.isMaxLength(unicode, 33, "参数非法"); + String value = sysBaseParamService.getOneByUniCode(unicode).getValue(); + return RespJSON.success(value); + } + + /** + * 通过code设置value + * + * @param sysBaseParamReq + * @return + */ + @PostMapping("/setValueByUnicode") + public RespJSON setValueByUnicode(@RequestBody SysBaseParam sysBaseParamReq) { + WJAssert.notNull(sysBaseParamReq.getUniCode(), "参数非法"); + WJAssert.notNull(sysBaseParamReq.getValue(), "参数值非法"); + SysBaseParam sysBaseParamDB = sysBaseParamService.getOneByUniCode(sysBaseParamReq.getUniCode()); + sysBaseParamDB.setValue(sysBaseParamReq.getValue()); + return RespJSON.success(sysBaseParamService.updateSelectiveById(sysBaseParamDB)); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/system/SysLogController.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/system/SysLogController.java new file mode 100644 index 0000000..0617693 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/system/SysLogController.java @@ -0,0 +1,98 @@ +package com.arm.equipment.system.admin.controller.system; + +import com.arm.equipment.system.admin.controller.BaseController; +import com.arm.equipment.system.admin.util.CurrentUserUtils; +import com.arm.equipment.system.data.domain.PageResult; +import com.arm.equipment.system.data.domain.system.SysLog; +import com.arm.equipment.system.data.domain.system.SysUser; +import com.arm.equipment.system.data.service.system.ISysLogService; +import com.arm.equipment.system.data.util.WJAssert; +import com.arm.equipment.system.data.vo.RespJSON; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.List; + +/** + * 日志表 + * + * @author admin + * @date 2022年09月16日 12:41:35 + */ +@RestController +@RequestMapping("/system/sysLog") +public class SysLogController extends BaseController { + + @Autowired + private ISysLogService sysLogService; + + /** + * 保存或更新 + * + * @param sysLogReq sysLogReq + * @return RespJSON + */ + @PostMapping("/save") + public RespJSON save(@RequestBody SysLog sysLogReq, @SessionAttribute(CurrentUserUtils.SYSTEM_USER) SysUser loginSysUser) { + sysLogService.save(sysLogReq, loginSysUser.getUsername()); + return RespJSON.success(); + } + + /** + * 分页查询 + * + * @param sysLogReq sysLogReq + * @return RespJSON + */ + @PostMapping("/getPageList") + public RespJSON getPageList(@RequestBody SysLog sysLogReq) { + int count = sysLogService.getCount(sysLogReq); + List list = new ArrayList<>(); + if (count > 0) { + list = sysLogService.getPageList(sysLogReq); + } + PageResult result = new PageResult(sysLogReq.getPageNo(), sysLogReq.getPageSize(), count, list); + return RespJSON.success(result); + } + + /** + * 主键查询 + * + * @param id id + * @return RespJSON + */ + @RequestMapping("/getOneById") + public RespJSON getOneById(Long id) { + return RespJSON.success(sysLogService.getOneById(id)); + } + + /** + * 审核 + * + * @param id id + * @return RespJSON + */ + @PostMapping("/audit") + @ResponseBody + public RespJSON audit(Long id, @SessionAttribute(CurrentUserUtils.SYSTEM_USER) SysUser loginSysUser) { + WJAssert.notNull(id, "ID 不合法"); + sysLogService.audit(id, loginSysUser.getUsername()); + return RespJSON.success(); + } + + /** + * 取消审核 + * + * @param id id + * @return RespJSON + */ + @PostMapping("/unaudit") + @ResponseBody + public RespJSON unaudit(Long id, @SessionAttribute(CurrentUserUtils.SYSTEM_USER) SysUser loginSysUser) { + WJAssert.notNull(id, "ID 不合法"); + sysLogService.unaudit(id, loginSysUser.getUsername()); + return RespJSON.success(); + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/system/SysResourceController.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/system/SysResourceController.java new file mode 100644 index 0000000..e58d02c --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/system/SysResourceController.java @@ -0,0 +1,97 @@ +package com.arm.equipment.system.admin.controller.system; + +import com.arm.equipment.system.admin.util.CurrentUserUtils; +import com.arm.equipment.system.admin.controller.BaseController; +import com.arm.equipment.system.data.domain.PageResult; +import com.arm.equipment.system.data.vo.RespJSON; +import com.arm.equipment.system.data.domain.system.SysUser; +import com.arm.equipment.system.data.domain.system.SysResource; +import com.arm.equipment.system.data.service.system.ISysResourceService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.ArrayList; + +/** + * 系统--权限表 + * + * @author admin + * @date 2021年10月19日 15:06:30 + */ +@RestController +@RequestMapping("/system/sysResource") +public class SysResourceController extends BaseController { + + @Autowired + private ISysResourceService sysResourceService; + + /** + * 保存或更新 + * + * @param sysResourceReq sysResourceReq + * @return RespJSON + */ + @PostMapping("/save") + public RespJSON save(@RequestBody SysResource sysResourceReq, @SessionAttribute(CurrentUserUtils.SYSTEM_USER)SysUser loginSysUser) { + sysResourceService.save(sysResourceReq, loginSysUser.getUsername()); + return RespJSON.success(); + } + + /** + * 分页查询 + * + * @param sysResourceReq sysResourceReq + * @return RespJSON + */ + @PostMapping("/getPageList") + public RespJSON getPageList(@RequestBody SysResource sysResourceReq) { + int count = sysResourceService.getCount(sysResourceReq); + List list = new ArrayList<>(); + if (count > 0) { + list = sysResourceService.getPageList(sysResourceReq); + } + PageResult result = new PageResult(sysResourceReq.getPageNo(), sysResourceReq.getPageSize(), count, list); + return RespJSON.success(result); + } + + /** + * 目录树分页查询 + * + * @param sysResourceReq sysResourceReq + * @return RespJSON + */ + @PostMapping("/getPageTreeList") + public RespJSON getPageTreeList(@RequestBody SysResource sysResourceReq) { + int count = sysResourceService.getCount(sysResourceReq); + List list = new ArrayList<>(); + if (count > 0) { + list = sysResourceService.getPageTreeList(sysResourceReq); + } + PageResult result = new PageResult(sysResourceReq.getPageNo(), sysResourceReq.getPageSize(), count, list); + return RespJSON.success(result); + } + + + /** + * 主键查询 + * + * @param id id + * @return RespJSON + */ + @RequestMapping("/getOneById") + public RespJSON getOneById(Long id) { + return RespJSON.success(sysResourceService.getOneById(id)); + } + + + /** + *获取资源树 + * + * @return RespJSON + */ + @RequestMapping("/getResourceTree") + public RespJSON getResourceTree() { + return RespJSON.success(sysResourceService.getResourceTree()); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/system/SysRoleController.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/system/SysRoleController.java new file mode 100644 index 0000000..7ddbd95 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/system/SysRoleController.java @@ -0,0 +1,99 @@ +package com.arm.equipment.system.admin.controller.system; + +import com.arm.equipment.system.admin.util.CurrentUserUtils; +import com.arm.equipment.system.admin.controller.BaseController; +import com.arm.equipment.system.data.domain.PageResult; +import com.arm.equipment.system.data.domain.system.SysRole; +import com.arm.equipment.system.data.domain.system.SysUser; +import com.arm.equipment.system.data.enums.dict.EnumStatus; +import com.arm.equipment.system.data.service.system.ISysRoleService; +import com.arm.equipment.system.data.vo.RespJSON; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.List; + +/** + * 系统--角色表 + * + * @author admin + * @date 2021年10月19日 15:06:47 + */ +@RestController +@RequestMapping("/system/sysRole") +public class SysRoleController extends BaseController { + + @Autowired + private ISysRoleService sysRoleService; + + /** + * 保存或更新 + * + * @param sysRoleReq sysRoleReq + * @return RespJSON + */ + @PostMapping("/save") + public RespJSON save(@RequestBody SysRole sysRoleReq, @SessionAttribute(CurrentUserUtils.SYSTEM_USER) SysUser loginSysUser) { + sysRoleService.save(sysRoleReq, loginSysUser.getUsername()); + return RespJSON.success(); + } + + /** + * 分页查询 + * + * @param sysRoleReq sysRoleReq + * @return RespJSON + */ + @PostMapping("/getPageList") + public RespJSON getPageList(@RequestBody SysRole sysRoleReq) { + sysRoleReq.setStatus(EnumStatus.NEW.getCode()); + int count = sysRoleService.getCount(sysRoleReq); + List list = new ArrayList<>(); + if (count > 0) { + list = sysRoleService.getPageList(sysRoleReq); + } + PageResult result = new PageResult(sysRoleReq.getPageNo(), sysRoleReq.getPageSize(), count, list); + return RespJSON.success(result); + } + + + /** + * 删除角色 + * + * @param id + * @param loginSysUser + * @return + */ + @PostMapping("/delete") + public RespJSON delete(Long id, @SessionAttribute(CurrentUserUtils.SYSTEM_USER) SysUser loginSysUser) { + sysRoleService.delete(id, loginSysUser.getName()); + return RespJSON.success(); + } + + /** + * 主键查询 + * + * @param id id + * @return RespJSON + */ + @RequestMapping("/getOneById") + public RespJSON getOneById(Long id) { + + return RespJSON.success(sysRoleService.getOneById(id)); + } + + /** + * 获取用户角色 + * + * @param loginSysUser + * @return + */ + @PostMapping("/getCurrentUserRole") + public RespJSON getCurrentUserRole(@SessionAttribute(CurrentUserUtils.SYSTEM_USER) SysUser loginSysUser) { + List sysRoleList = sysRoleService.getCurrentUserRole(loginSysUser.getId()); + return RespJSON.success(sysRoleList); + } + + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/system/SysRoleResourceController.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/system/SysRoleResourceController.java new file mode 100644 index 0000000..3843b48 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/system/SysRoleResourceController.java @@ -0,0 +1,48 @@ +package com.arm.equipment.system.admin.controller.system; + +import com.arm.equipment.system.admin.util.CurrentUserUtils; +import com.arm.equipment.system.admin.controller.BaseController; +import com.arm.equipment.system.data.domain.system.SysUser; +import com.arm.equipment.system.data.service.system.ISysRoleResourceService; +import com.arm.equipment.system.data.vo.RespJSON; +import com.arm.equipment.system.data.vo.system.SysRoleResourceVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +/** + * 系统-角色权限关联表 + * + * @author admin + * @date 2021年10月19日 15:06:41 + */ +@RestController +@RequestMapping("/system/sysRoleResource") +public class SysRoleResourceController extends BaseController { + + @Autowired + private ISysRoleResourceService sysRoleResourceService; + + /** + * 添加角色按此单 + * @param roleResourceVO + * @param loginSysUser + * @return + */ + @PostMapping("/addResource") + public RespJSON addResource(@RequestBody SysRoleResourceVO roleResourceVO, @SessionAttribute(CurrentUserUtils.SYSTEM_USER) SysUser loginSysUser) { + sysRoleResourceService.addResource(roleResourceVO, loginSysUser.getName()); + return RespJSON.success(); + } + + /** + * 根据角色ID查询所拥有菜单权限 + * + * @param roleResourceVO + * @return RespJSON + */ + @PostMapping("/getResourcesIdListByRoleId") + public RespJSON getResourcesIdListByRoleId(@RequestBody SysRoleResourceVO roleResourceVO) { + return RespJSON.success(sysRoleResourceService.getResourcesIdListByRoleId(roleResourceVO.getRoleId())); + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/system/SysUserController.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/system/SysUserController.java new file mode 100644 index 0000000..bd04108 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/system/SysUserController.java @@ -0,0 +1,157 @@ +package com.arm.equipment.system.admin.controller.system; + +import com.arm.equipment.system.admin.controller.BaseController; +import com.arm.equipment.system.admin.util.CurrentUserUtils; +import com.arm.equipment.system.data.domain.PageResult; +import com.arm.equipment.system.data.domain.system.*; +import com.arm.equipment.system.data.service.system.*; +import com.arm.equipment.system.data.util.WJAssert; +import com.arm.equipment.system.data.vo.RespJSON; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.CollectionUtils; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpSession; +import java.util.ArrayList; +import java.util.List; + +/** + * 系统--用户表 + * + * @author admin + * @date 2021年10月19日 15:07:06 + */ +@RestController +@RequestMapping("/system/sysUser") +public class SysUserController extends BaseController { + + @Autowired + private ISysUserService sysUserService; + @Autowired + private ISysRoleService sysRoleService; + @Autowired + private ISysRoleResourceService roleResourceService; + + /** + * 保存或更新 + * + * @param sysUserReq sysUserReq + * @return RespJSON + */ + @PostMapping("/save") + public RespJSON save(@RequestBody SysUser sysUserReq, @SessionAttribute(CurrentUserUtils.SYSTEM_USER) SysUser loginSysUser) { + sysUserService.save(sysUserReq, loginSysUser.getUsername()); + return RespJSON.success(); + } + + /** + * 分页查询 + * + * @param sysUserReq sysUserReq + * @return RespJSON + */ + @PostMapping("/getPageList") + public RespJSON getPageList(@RequestBody SysUser sysUserReq) { + int count = sysUserService.getCount(sysUserReq); + List list = new ArrayList<>(); + if (count > 0) { + list = sysUserService.getPageList(sysUserReq); + } + PageResult result = new PageResult(sysUserReq.getPageNo(), sysUserReq.getPageSize(), count, list); + return RespJSON.success(result); + } + + /** + * 主键查询 + * + * @param id id + * @return RespJSON + */ + @RequestMapping("/getOneById") + public RespJSON getOneById(Long id) { + return RespJSON.success(sysUserService.getOneById(id)); + } + + /** + * 主键查询 + * + * @param id id + * @return RespJSON + */ + @PostMapping("/delete") + public RespJSON delete(Long id, @SessionAttribute(CurrentUserUtils.SYSTEM_USER) SysUser loginSysUser) { + sysUserService.delete(id, loginSysUser.getUsername()); + return RespJSON.success(); + } + + + /** + * 登陆 + *

+ * param username 用户名 + * param password 密码 + * + * @return + */ + @PostMapping("/login") + public RespJSON login(@RequestBody SysUser sysUser, HttpSession webSession) { + SysUser sysUserDB = sysUserService.login(sysUser, webSession); + webSession.setAttribute(CurrentUserUtils.SYSTEM_USER, sysUserDB); + return RespJSON.success(webSession.getId()); + } + + /** + * 注销 + * + * @param webSession + * @return + */ + @PostMapping("/logout") + public RespJSON logout(HttpSession webSession) { + webSession.removeAttribute(CurrentUserUtils.SYSTEM_USER); + return RespJSON.success(); + } + + /** + * 获取当前用户信息 + * + * @param loginSysUser + * @return + */ + @GetMapping("/getCurrentUser") + public RespJSON getCurrentUserAndRole(@SessionAttribute(CurrentUserUtils.SYSTEM_USER) SysUser loginSysUser) { + List currentUserRole = sysRoleService.getCurrentUserRole(loginSysUser.getId()); + + loginSysUser.setSysRoleList(currentUserRole); + List sysResourceIdentityList = new ArrayList<>(); + List sysResourceList = new ArrayList<>(); + + roleResourceService.buildUserResourceListAndIdentityList(currentUserRole, sysResourceList, sysResourceIdentityList); + if (CollectionUtils.isEmpty(currentUserRole)) { + currentUserRole = new ArrayList<>(); + SysRole sysRole = new SysRole(); + sysRole.setName("首页"); + currentUserRole.add(sysRole); + loginSysUser.setSysRoleList(currentUserRole); + } + loginSysUser.setSysResourceList(sysResourceList); + loginSysUser.setSysResourceIdentityList(sysResourceIdentityList); + return RespJSON.success(loginSysUser); + } + + /** + * 修改密码 + * + * @param oldPassword + * @param newPassword + * @param loginSysUser + * @return + */ + @PostMapping("/updatePassword") + public RespJSON login(String oldPassword, String newPassword, @SessionAttribute(CurrentUserUtils.SYSTEM_USER) SysUser loginSysUser) { + WJAssert.isMaxLength(oldPassword, 32, "旧密码错误"); + WJAssert.isMaxLength(newPassword, 32, "新密码错误"); + sysUserService.updatePassword(oldPassword, newPassword, loginSysUser.getId()); + return RespJSON.success(); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/system/SysUserRoleController.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/system/SysUserRoleController.java new file mode 100644 index 0000000..19ba719 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/system/SysUserRoleController.java @@ -0,0 +1,105 @@ +package com.arm.equipment.system.admin.controller.system; + +import com.arm.equipment.system.admin.util.CurrentUserUtils; +import com.arm.equipment.system.admin.controller.BaseController; +import com.arm.equipment.system.data.domain.PageResult; +import com.arm.equipment.system.data.domain.system.SysUser; +import com.arm.equipment.system.data.domain.system.SysUserRole; +import com.arm.equipment.system.data.service.system.ISysUserRoleService; +import com.arm.equipment.system.data.service.system.ISysUserService; +import com.arm.equipment.system.data.vo.RespJSON; +import com.arm.equipment.system.data.vo.system.AddRoleVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 系统--用户角色关联表 + * + * @author admin + * @date 2021年10月19日 15:06:59 + */ +@RestController +@RequestMapping("/system/sysUserRole") +public class SysUserRoleController extends BaseController { + + @Autowired + private ISysUserRoleService sysUserRoleService; + @Autowired + private ISysUserService sysUserService; + + + /** + * 保存或更新 + * + * @param sysUserRoleReq sysUserRoleReq + * @return RespJSON + */ + @PostMapping("/save") + public RespJSON save(@RequestBody SysUserRole sysUserRoleReq, @SessionAttribute(CurrentUserUtils.SYSTEM_USER) SysUser loginSysUser) { + sysUserRoleService.save(sysUserRoleReq, loginSysUser.getOperator()); + return RespJSON.success(); + } + + /** + * 分页查询 + * + * @param sysUserRoleReq sysUserRoleReq + * @return RespJSON + */ + @PostMapping("/getPageList") + public RespJSON getPageList(@RequestBody SysUserRole sysUserRoleReq) { + int count = sysUserRoleService.getCount(sysUserRoleReq); + List list = new ArrayList<>(); + if (count > 0) { + list = sysUserRoleService.getPageList(sysUserRoleReq); + } + PageResult result = new PageResult(sysUserRoleReq.getPageNo(), sysUserRoleReq.getPageSize(), count, list); + return RespJSON.success(result); + } + + /** + * 主键查询 + * + * @param id id + * @return RespJSON + */ + @RequestMapping("/getOneById") + public RespJSON getOneById(Long id) { + return RespJSON.success(sysUserRoleService.getOneById(id)); + } + + /** + * 为用户分配角色 + * + * @param addRoleVO + * @param loginSysUser + * @return + */ + @PostMapping("/addRole") + public RespJSON addRole(@RequestBody AddRoleVO addRoleVO, @SessionAttribute(CurrentUserUtils.SYSTEM_USER) SysUser loginSysUser) { + sysUserRoleService.addRole(addRoleVO, loginSysUser); + return RespJSON.success(); + } + + /** + * 列表查询 + * + * @param sysUserRoleReq + * @param loginSysUser + * @return + */ + @PostMapping("/getList") + public RespJSON addRole(@RequestBody SysUserRole sysUserRoleReq, @SessionAttribute(CurrentUserUtils.SYSTEM_USER) SysUser loginSysUser) { + List sysUserList = sysUserRoleService.getList(sysUserRoleReq).stream().map(item -> { + return sysUserService.getExitOneById(item.getSysUserId()); + }).collect(Collectors.toList()); + sysUserList.removeAll(Collections.singleton(null)); + return RespJSON.success(sysUserList); + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/user/AppUserController.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/user/AppUserController.java new file mode 100644 index 0000000..320b8cd --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/user/AppUserController.java @@ -0,0 +1,98 @@ +package com.arm.equipment.system.admin.controller.user; + +import com.arm.equipment.system.admin.controller.BaseController; +import com.arm.equipment.system.admin.util.CurrentUserUtils; +import com.arm.equipment.system.data.domain.PageResult; +import com.arm.equipment.system.data.vo.RespJSON; +import com.arm.equipment.system.data.domain.system.SysUser; +import com.arm.equipment.system.data.util.WJAssert; +import com.arm.equipment.system.data.domain.user.AppUser; +import com.arm.equipment.system.data.service.user.IAppUserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.ArrayList; + +/** + * APP用户 + * + * @author admin + * @date 2023年03月13日 22:34:47 + */ +@RestController +@RequestMapping("/user/appUser") +public class AppUserController extends BaseController { + + @Autowired + private IAppUserService appUserService; + + /** + * 保存或更新 + * + * @param appUserReq appUserReq + * @return RespJSON + */ + @PostMapping("/save") + public RespJSON save(@RequestBody AppUser appUserReq, @SessionAttribute(CurrentUserUtils.SYSTEM_USER)SysUser loginSysUser) { + appUserService.save(appUserReq, loginSysUser.getUsername()); + return RespJSON.success(); + } + + /** + * 分页查询 + * + * @param appUserReq appUserReq + * @return RespJSON + */ + @PostMapping("/getPageList") + public RespJSON getPageList(@RequestBody AppUser appUserReq) { + int count = appUserService.getCount(appUserReq); + List list = new ArrayList<>(); + if (count > 0) { + list = appUserService.getPageList(appUserReq); + } + PageResult result = new PageResult(appUserReq.getPageNo(), appUserReq.getPageSize(), count, list); + return RespJSON.success(result); + } + + /** + * 主键查询 + * + * @param id id + * @return RespJSON + */ + @RequestMapping("/getOneById") + public RespJSON getOneById(Long id) { + return RespJSON.success(appUserService.getOneById(id)); + } + + /** + * 审核 + * + * @param id id + * @return RespJSON + */ + @PostMapping("/audit") + @ResponseBody + public RespJSON audit(Long id, @SessionAttribute(CurrentUserUtils.SYSTEM_USER)SysUser loginSysUser) { + WJAssert.notNull(id, "ID 不合法"); + appUserService.audit(id, loginSysUser.getUsername()); + return RespJSON.success(); + } + + /** + * 取消审核 + * + * @param id id + * @return RespJSON + */ + @PostMapping("/unaudit") + @ResponseBody + public RespJSON unaudit(Long id, @SessionAttribute(CurrentUserUtils.SYSTEM_USER)SysUser loginSysUser) { + WJAssert.notNull(id, "ID 不合法"); + appUserService.unaudit(id, loginSysUser.getUsername()); + return RespJSON.success(); + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/verifycode/VerifyCodeController.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/verifycode/VerifyCodeController.java new file mode 100644 index 0000000..b4e83e4 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/verifycode/VerifyCodeController.java @@ -0,0 +1,65 @@ +package com.arm.equipment.system.admin.controller.verifycode; + + +import com.arm.equipment.system.data.service.common.IVerifyCodeService; +import com.arm.equipment.system.data.util.ValidCodeUtil; +import com.arm.equipment.system.data.vo.system.VerifyCodeVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import javax.imageio.ImageIO; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.awt.image.BufferedImage; +import java.io.IOException; + +/** + * @author: admin + * @time: 2022/9/16 14:35 + */ +@RestController +@RequestMapping("/verifycode") +public class VerifyCodeController { + @Autowired + private IVerifyCodeService verifyCodeService; + /** + * 验证码key开头 + */ + public final static String KEY_TOP = "verifyCode_"; + + /** + * 生成验证码图片与存入SESSION + * + * @param response + * @param webSession + * @return + * @throws IOException + */ + @ResponseBody + @GetMapping("/getVerifyCode") + public void getVerifyCode(HttpServletResponse response, HttpSession webSession) throws IOException { + VerifyCodeVO verifyCode = verifyCodeService.generate(80, 28); + String code = verifyCode.getCode(); + webSession.setAttribute(KEY_TOP + code, verifyCode); + response.setContentType(MediaType.IMAGE_JPEG_VALUE); + ServletOutputStream outputStream; + try { + outputStream = response.getOutputStream(); + } catch (IOException e) { + throw new RuntimeException("获得响应流失败"); + } + try { + BufferedImage image = ValidCodeUtil.generateImg(code); + ImageIO.write(image, "png", outputStream); + outputStream.flush(); + outputStream.close(); + } catch (IOException e) { + throw new RuntimeException("验证码输出到流失败"); + } + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/weaponry/WeaponryController.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/weaponry/WeaponryController.java new file mode 100644 index 0000000..aac9a5c --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/weaponry/WeaponryController.java @@ -0,0 +1,98 @@ +package com.arm.equipment.system.admin.controller.weaponry; + +import com.arm.equipment.system.admin.controller.BaseController; +import com.arm.equipment.system.admin.util.CurrentUserUtils; +import com.arm.equipment.system.data.domain.PageResult; +import com.arm.equipment.system.data.domain.system.SysUser; +import com.arm.equipment.system.data.util.WJAssert; +import com.arm.equipment.system.data.vo.RespJSON; +import com.arm.equipment.system.data.domain.weaponry.Weaponry; +import com.arm.equipment.system.data.service.weaponry.IWeaponryService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.ArrayList; + +/** + * 装备武器 + * + * @author admin + * @date 2023年03月23日 10:29:48 + */ +@RestController +@RequestMapping("/weaponry/weaponry") +public class WeaponryController extends BaseController { + + @Autowired + private IWeaponryService weaponryService; + + /** + * 保存或更新 + * + * @param weaponryReq weaponryReq + * @return RespJSON + */ + @PostMapping("/save") + public RespJSON save(@RequestBody Weaponry weaponryReq, @SessionAttribute(CurrentUserUtils.SYSTEM_USER)SysUser loginSysUser) { + weaponryService.save(weaponryReq, loginSysUser.getUsername()); + return RespJSON.success(); + } + + /** + * 分页查询 + * + * @param weaponryReq weaponryReq + * @return RespJSON + */ + @PostMapping("/getPageList") + public RespJSON getPageList(@RequestBody Weaponry weaponryReq) { + int count = weaponryService.getCount(weaponryReq); + List list = new ArrayList<>(); + if (count > 0) { + list = weaponryService.getPageList(weaponryReq); + } + PageResult result = new PageResult(weaponryReq.getPageNo(), weaponryReq.getPageSize(), count, list); + return RespJSON.success(result); + } + + /** + * 主键查询 + * + * @param id id + * @return RespJSON + */ + @RequestMapping("/getOneById") + public RespJSON getOneById(Long id) { + return RespJSON.success(weaponryService.getOneById(id)); + } + + /** + * 审核 + * + * @param id id + * @return RespJSON + */ + @PostMapping("/audit") + @ResponseBody + public RespJSON audit(Long id, @SessionAttribute(CurrentUserUtils.SYSTEM_USER)SysUser loginSysUser) { + WJAssert.notNull(id, "ID 不合法"); + weaponryService.audit(id, loginSysUser.getUsername()); + return RespJSON.success(); + } + + /** + * 取消审核 + * + * @param id id + * @return RespJSON + */ + @PostMapping("/unaudit") + @ResponseBody + public RespJSON unaudit(Long id, @SessionAttribute(CurrentUserUtils.SYSTEM_USER)SysUser loginSysUser) { + WJAssert.notNull(id, "ID 不合法"); + weaponryService.unaudit(id, loginSysUser.getUsername()); + return RespJSON.success(); + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/weaponry/WeaponryLendRecordController.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/weaponry/WeaponryLendRecordController.java new file mode 100644 index 0000000..c643cd3 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/weaponry/WeaponryLendRecordController.java @@ -0,0 +1,98 @@ +package com.arm.equipment.system.admin.controller.weaponry; + +import com.arm.equipment.system.admin.controller.BaseController; +import com.arm.equipment.system.admin.util.CurrentUserUtils; +import com.arm.equipment.system.data.domain.PageResult; +import com.arm.equipment.system.data.domain.system.SysUser; +import com.arm.equipment.system.data.domain.weaponry.WeaponryLendRecord; +import com.arm.equipment.system.data.service.weaponry.IWeaponryLendRecordService; +import com.arm.equipment.system.data.util.WJAssert; +import com.arm.equipment.system.data.vo.RespJSON; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.List; + +/** + * 装备武器借出记录 + * + * @author admin + * @date 2023年03月23日 09:20:19 + */ +@RestController +@RequestMapping("/weaponry/weaponryLendRecord") +public class WeaponryLendRecordController extends BaseController { + + @Autowired + private IWeaponryLendRecordService weaponryLendRecordService; + + /** + * 保存或更新 + * + * @param weaponryLendRecordReq weaponryLendRecordReq + * @return RespJSON + */ + @PostMapping("/save") + public RespJSON save(@RequestBody WeaponryLendRecord weaponryLendRecordReq, @SessionAttribute(CurrentUserUtils.SYSTEM_USER) SysUser loginSysUser) { + weaponryLendRecordService.save(weaponryLendRecordReq, loginSysUser.getUsername()); + return RespJSON.success(); + } + + /** + * 分页查询 + * + * @param weaponryLendRecordReq weaponryLendRecordReq + * @return RespJSON + */ + @PostMapping("/getPageList") + public RespJSON getPageList(@RequestBody WeaponryLendRecord weaponryLendRecordReq) { + int count = weaponryLendRecordService.getCount(weaponryLendRecordReq); + List list = new ArrayList<>(); + if (count > 0) { + list = weaponryLendRecordService.getPageList(weaponryLendRecordReq); + } + PageResult result = new PageResult(weaponryLendRecordReq.getPageNo(), weaponryLendRecordReq.getPageSize(), count, list); + return RespJSON.success(result); + } + + /** + * 主键查询 + * + * @param id id + * @return RespJSON + */ + @RequestMapping("/getOneById") + public RespJSON getOneById(Long id) { + return RespJSON.success(weaponryLendRecordService.getOneById(id)); + } + + /** + * 拒绝 + * + * @param id id + * @return RespJSON + */ + @PostMapping("/refuse") + @ResponseBody + public RespJSON refuse(Long id, @SessionAttribute(CurrentUserUtils.SYSTEM_USER) SysUser loginSysUser) { + WJAssert.notNull(id, "ID 不合法"); + weaponryLendRecordService.refuse(id, loginSysUser.getUsername()); + return RespJSON.success(); + } + + /** + * 通过 + * + * @param id id + * @return RespJSON + */ + @PostMapping("/adopt") + @ResponseBody + public RespJSON adopt(Long id, @SessionAttribute(CurrentUserUtils.SYSTEM_USER) SysUser loginSysUser) { + WJAssert.notNull(id, "ID 不合法"); + weaponryLendRecordService.adopt(id, loginSysUser.getUsername()); + return RespJSON.success(); + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/weaponry/WeaponryReturnRecordController.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/weaponry/WeaponryReturnRecordController.java new file mode 100644 index 0000000..5751797 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/controller/weaponry/WeaponryReturnRecordController.java @@ -0,0 +1,98 @@ +package com.arm.equipment.system.admin.controller.weaponry; + +import com.arm.equipment.system.admin.controller.BaseController; +import com.arm.equipment.system.admin.util.CurrentUserUtils; +import com.arm.equipment.system.data.domain.PageResult; +import com.arm.equipment.system.data.domain.system.SysUser; +import com.arm.equipment.system.data.util.WJAssert; +import com.arm.equipment.system.data.vo.RespJSON; +import com.arm.equipment.system.data.domain.weaponry.WeaponryReturnRecord; +import com.arm.equipment.system.data.service.weaponry.IWeaponryReturnRecordService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.ArrayList; + +/** + * 装备武器归还记录 + * + * @author admin + * @date 2023年03月23日 09:20:25 + */ +@RestController +@RequestMapping("/weaponry/weaponryReturnRecord") +public class WeaponryReturnRecordController extends BaseController { + + @Autowired + private IWeaponryReturnRecordService weaponryReturnRecordService; + + /** + * 保存或更新 + * + * @param weaponryReturnRecordReq weaponryReturnRecordReq + * @return RespJSON + */ + @PostMapping("/save") + public RespJSON save(@RequestBody WeaponryReturnRecord weaponryReturnRecordReq, @SessionAttribute(CurrentUserUtils.SYSTEM_USER)SysUser loginSysUser) { + weaponryReturnRecordService.save(weaponryReturnRecordReq, loginSysUser.getUsername()); + return RespJSON.success(); + } + + /** + * 分页查询 + * + * @param weaponryReturnRecordReq weaponryReturnRecordReq + * @return RespJSON + */ + @PostMapping("/getPageList") + public RespJSON getPageList(@RequestBody WeaponryReturnRecord weaponryReturnRecordReq) { + int count = weaponryReturnRecordService.getCount(weaponryReturnRecordReq); + List list = new ArrayList<>(); + if (count > 0) { + list = weaponryReturnRecordService.getPageList(weaponryReturnRecordReq); + } + PageResult result = new PageResult(weaponryReturnRecordReq.getPageNo(), weaponryReturnRecordReq.getPageSize(), count, list); + return RespJSON.success(result); + } + + /** + * 主键查询 + * + * @param id id + * @return RespJSON + */ + @RequestMapping("/getOneById") + public RespJSON getOneById(Long id) { + return RespJSON.success(weaponryReturnRecordService.getOneById(id)); + } + + /** + * 审核 + * + * @param id id + * @return RespJSON + */ + @PostMapping("/audit") + @ResponseBody + public RespJSON audit(Long id, @SessionAttribute(CurrentUserUtils.SYSTEM_USER)SysUser loginSysUser) { + WJAssert.notNull(id, "ID 不合法"); + weaponryReturnRecordService.audit(id, loginSysUser.getUsername()); + return RespJSON.success(); + } + + /** + * 取消审核 + * + * @param id id + * @return RespJSON + */ + @PostMapping("/unaudit") + @ResponseBody + public RespJSON unaudit(Long id, @SessionAttribute(CurrentUserUtils.SYSTEM_USER)SysUser loginSysUser) { + WJAssert.notNull(id, "ID 不合法"); + weaponryReturnRecordService.unaudit(id, loginSysUser.getUsername()); + return RespJSON.success(); + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/filter/BodyReaderHttpServletRequestWrapper.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/filter/BodyReaderHttpServletRequestWrapper.java new file mode 100644 index 0000000..433fba0 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/filter/BodyReaderHttpServletRequestWrapper.java @@ -0,0 +1,91 @@ +package com.arm.equipment.system.admin.filter; + +import javax.servlet.ReadListener; +import javax.servlet.ServletInputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; +import java.io.*; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + +/** + * request封装 + */ +public class BodyReaderHttpServletRequestWrapper extends HttpServletRequestWrapper { + + private final byte[] body; + private String bodyStr; + + public BodyReaderHttpServletRequestWrapper(HttpServletRequest request) throws IOException { + super(request); + String bodyString = getBodyString(request); + body = bodyString.getBytes(StandardCharsets.UTF_8); + bodyStr = bodyString; + } + + public String getBodyStr() { + return bodyStr; + } + + @Override + public ServletInputStream getInputStream() throws IOException { + final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body); + + return new ServletInputStream() { + @Override + public int read() throws IOException { + return byteArrayInputStream.read(); + } + + @Override + public boolean isFinished() { + return false; + } + + @Override + public boolean isReady() { + return false; + } + + @Override + public void setReadListener(ReadListener readListener) { + } + }; + } + + + public String getBodyString(HttpServletRequest request) throws IOException { + StringBuilder sb = new StringBuilder(); + InputStream inputStream = null; + BufferedReader reader = null; + try { + inputStream = request.getInputStream(); + reader = new BufferedReader( + new InputStreamReader(inputStream, Charset.forName("UTF-8"))); + + char[] bodyCharBuffer = new char[1024]; + int len = 0; + while ((len = reader.read(bodyCharBuffer)) != -1) { + sb.append(new String(bodyCharBuffer, 0, len)); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return sb.toString(); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/filter/LoginPermissionsFilter.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/filter/LoginPermissionsFilter.java new file mode 100644 index 0000000..860e332 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/filter/LoginPermissionsFilter.java @@ -0,0 +1,81 @@ +package com.arm.equipment.system.admin.filter; + +import com.alibaba.fastjson.JSON; +import com.google.common.base.Throwables; +import com.arm.equipment.system.admin.util.CurrentUserUtils; +import com.arm.equipment.system.data.domain.system.SysUser; +import com.arm.equipment.system.data.vo.RespJSON; +import com.arm.equipment.system.data.vo.ReturnCode; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.Order; +import org.springframework.web.servlet.HandlerInterceptor; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.List; + +/** + * @author: admin + * @time: 2022/9/16 11:20 + */ +@Order(1001) +@Configuration +public class LoginPermissionsFilter implements HandlerInterceptor { + private final static Logger logger = LoggerFactory.getLogger(LoginPermissionsFilter.class); + @Value("${domain.admin}") + private String adminDomain; + + private static final List IGNORE_URL_LIST = Arrays.asList("/login", "/file/upload", "/common/dict", "/verifycode/getVerifyCode"); + + private final String RETURN_INFO = JSON.toJSONString(RespJSON.returnCode(ReturnCode.NOT_LOGIN_ERROR)); + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + // 将 options 请求放过 + String method = request.getMethod(); + if ("options".equalsIgnoreCase(method)) { + return true; + } + String uri = request.getRequestURI(); + for (String ignoreUrl : IGNORE_URL_LIST) { + if (StringUtils.contains(uri, ignoreUrl)) { + return true; + } + } + SysUser sysUser = (SysUser) request.getSession().getAttribute(CurrentUserUtils.SYSTEM_USER); + if (null != sysUser) { + return true; + } + returnNoLogin(response, request); + return false; + + } + + private void returnNoLogin(HttpServletResponse response, HttpServletRequest request) { + String origin = adminDomain; + String originHeader = request.getHeader("Origin"); + if (StringUtils.isNotEmpty(originHeader)) { + origin = originHeader; + } + response.setCharacterEncoding("UTF-8"); + response.setHeader("Content-Type", "application/json; charset=utf-8"); + response.setHeader("Access-Control-Allow-Credentials", "true"); + response.setHeader("Access-Control-Allow-Origin", origin); + PrintWriter writer = null; + try { + writer = response.getWriter(); + writer.write(RETURN_INFO); + } catch (IOException e) { + logger.error(Throwables.getStackTraceAsString(e)); + } finally { + writer.close(); + } + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/filter/RequestBodyFilter.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/filter/RequestBodyFilter.java new file mode 100644 index 0000000..de3a12d --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/filter/RequestBodyFilter.java @@ -0,0 +1,37 @@ +package com.arm.equipment.system.admin.filter; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import javax.servlet.*; +import javax.servlet.annotation.WebFilter; +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; + +/** + * 记录用户请求参数 + */ +@Component +@WebFilter(filterName = "httpServletRequestWrapperFilter", urlPatterns = {"/"}) +public class RequestBodyFilter implements Filter { + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { + ServletRequest requestWrapper = null; + if (request instanceof HttpServletRequest) { + HttpServletRequest httpRequest = (HttpServletRequest) request; + //遇到post方法才对request进行包装 + String methodType = httpRequest.getMethod(); + String contentType = ((HttpServletRequest) request).getHeader("Content-Type"); + if (StringUtils.isNotEmpty(contentType) && contentType.contains("application/json") && "POST".equals(methodType)) { + requestWrapper = new BodyReaderHttpServletRequestWrapper((HttpServletRequest) request); + } + } + if (null == requestWrapper) { + chain.doFilter(request, response); + } else { + chain.doFilter(requestWrapper, response); + + } + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/filter/SysLogFilter.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/filter/SysLogFilter.java new file mode 100644 index 0000000..20ceb08 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/filter/SysLogFilter.java @@ -0,0 +1,101 @@ +package com.arm.equipment.system.admin.filter; + +import com.alibaba.fastjson.JSONObject; +import com.arm.equipment.system.admin.util.CurrentUserUtils; +import com.arm.equipment.system.data.domain.system.SysLog; +import com.arm.equipment.system.data.domain.system.SysUser; +import com.arm.equipment.system.data.enums.dict.EnumSysLogType; +import com.arm.equipment.system.data.service.system.ISysLogService; +import com.arm.equipment.system.data.util.IPUtil; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.Order; +import org.springframework.web.servlet.HandlerInterceptor; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +/** + * 系统日志filter, 记录所有请求 + */ +@Order(1002) +@Configuration +public class SysLogFilter implements HandlerInterceptor { + private final static Logger logger = LoggerFactory.getLogger(SysLogFilter.class); + @Autowired + private ISysLogService sysLogService; + /** + * 50个线程, 无界队列, 超过异常 + */ + private final static ThreadPoolExecutor THREAD_POOL_EXECUTOR = new ThreadPoolExecutor(50, 50, 120, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new ThreadPoolExecutor.AbortPolicy()); + /** + * 登录路径 + */ + private final static String LOGIN_PATH = "/system/sysUser/login"; + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + THREAD_POOL_EXECUTOR.submit(() -> { + String userAgent = request.getHeader("User-Agent"); + SysLog sysLog = new SysLog(); + sysLog.setType(EnumSysLogType.LOG.getCode()); + // todo 尽量设置访问链接的菜单 + sysLog.setTitle(" "); + sysLog.setRemoteAddr(IPUtil.getRemoteAddress(request)); + + sysLog.setUserAgent(userAgent); + sysLog.setRequestUri(buildUri(request)); + sysLog.setMethod(request.getMethod()); + String requestBody = getRequestBody(((BodyReaderHttpServletRequestWrapper) request).getBodyStr()); + sysLog.setParams(requestBody); + //登录接口日志特殊处理 不显示密码 + if (sysLog.getRequestUri().contains(LOGIN_PATH)) { + JSONObject loginInfoJson = JSONObject.parseObject(requestBody); + loginInfoJson.put("password", ""); + sysLog.setParams(loginInfoJson.toJSONString()); + } + SysUser sysUser = (SysUser) request.getSession().getAttribute(CurrentUserUtils.SYSTEM_USER); + if (null != sysUser) { + sysLogService.save(sysLog, sysUser.getUsername()); + } else { + sysLogService.save(sysLog, "SYSTEM"); + } + }); + return true; + } + + private Map getAllHeader(HttpServletRequest request) { + Enumeration headerNames = request.getHeaderNames(); + Map map = new HashMap<>(); + while (headerNames.hasMoreElements()) { + String key = headerNames.nextElement(); + map.put(key, request.getHeader(key)); + } + return map; + } + + private String getRequestBody(String requestBody) { + if (StringUtils.isEmpty(requestBody)) { + return null; + } + return requestBody; + } + + private String buildUri(HttpServletRequest request) { + String path = request.getRequestURL().toString(); + String query = request.getQueryString(); + if (StringUtils.isEmpty(query)) { + return path; + } + return path + "?" + query; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/util/CurrentUserUtils.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/util/CurrentUserUtils.java new file mode 100644 index 0000000..07fd4f9 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/java/com/arm/equipment/system/admin/util/CurrentUserUtils.java @@ -0,0 +1,13 @@ +package com.arm.equipment.system.admin.util; + +/** + * + * + * @author: admin + * @time: 2022/9/16 11:20 + */ +public class CurrentUserUtils { + + public static final String SYSTEM_USER = "system_user"; + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/resources/application-dev.yml b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/resources/application-dev.yml new file mode 100644 index 0000000..e45c91a --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/resources/application-dev.yml @@ -0,0 +1,34 @@ +env: dev +spring: + datasource: + url: jdbc:mysql://127.0.0.1:3306/arm-equipment-system?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: + type: com.zaxxer.hikari.HikariDataSource + hikari: + auto-commit: true + connection-timeout: 30000 + idle-timeout: 600000 + max-lifetime: 1800000 + minimum-idle: 1 + maximum-pool-size: 10 + pool-name: hikaricp + validation-timeout: 5000 + redis: + host: 127.0.0.1 + port: 6379 + password: + database: 0 + timeout: 5000ms + lettuce: + pool: + max-idle: 100 + min-idle: 1 + max-active: 1000 + web: + resources: + static-locations: file:admin/src/main/resources/static +# 域名配置 +domain: + admin: http://localhost:9527 diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/resources/application.yml b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/resources/application.yml new file mode 100644 index 0000000..818c7ac --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/resources/application.yml @@ -0,0 +1,25 @@ +git: + version: "@git.commit.id.abbrev@" + commitTime: "@git.commit.time@" +server: + port: 18081 + compression: + enabled: true + mime-types: application/javascript,text/css,application/json,application/xml,text/html,text/xml,text/plain +spring: + jackson: + serialization: + write-dates-as-timestamps: true + output: + ansi: + enabled: always + webflux: + static-path-pattern: /** + session: + store-type: redis + timeout: 86400 + profiles: + active: dev + servlet: + multipart: + max-file-size: 1024MB diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/resources/logback-spring.xml b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..eb56ff8 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/main/resources/logback-spring.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + ${log.base}.log + + true + 30 + + ${log.base}.%d{yyyy-MM-dd}.log + + + + + %date [%thread] %-5level %logger{80} - %msg%n + + + + + + + + + + + + + + diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/test/java/com/arm/equipment/system/admin/AdminApplicationTests.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/test/java/com/arm/equipment/system/admin/AdminApplicationTests.java new file mode 100644 index 0000000..182e469 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/test/java/com/arm/equipment/system/admin/AdminApplicationTests.java @@ -0,0 +1,38 @@ +package com.arm.equipment.system.admin; + +import com.arm.equipment.system.admin.app.AdminApplication; +import com.arm.equipment.system.data.service.common.IIdWorkerService; +import com.arm.equipment.system.data.util.passwordEncoder.BCryptPasswordEncoderUtils; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit.jupiter.SpringExtension; + + +@ExtendWith(SpringExtension.class) +@SpringBootTest(classes = AdminApplication.class) +@ActiveProfiles(profiles = "dev") +public class AdminApplicationTests { + + @Autowired + private BCryptPasswordEncoderUtils bCryptPasswordEncoder; + + @Test + public void test() { + System.out.println(bCryptPasswordEncoder.encode("123123")); + } + + + + @Autowired + IIdWorkerService idWorkerService; + + @Test + public void aa(){ + for (int i = 0; i < 30; i++) { + System.out.println(idWorkerService.getNextId()); + } + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/test/java/com/arm/equipment/system/admin/SysResourceTests.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/test/java/com/arm/equipment/system/admin/SysResourceTests.java new file mode 100644 index 0000000..6dbaedc --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/admin/src/test/java/com/arm/equipment/system/admin/SysResourceTests.java @@ -0,0 +1,141 @@ +package com.arm.equipment.system.admin; + +import com.google.common.collect.ImmutableMap; +import com.arm.equipment.system.admin.app.AdminApplication; +import com.arm.equipment.system.data.domain.system.SysResource; +import com.arm.equipment.system.data.service.system.ISysResourceService; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +@ExtendWith(SpringExtension.class) +@SpringBootTest(classes = AdminApplication.class) +@ActiveProfiles(profiles = "dev") +public class SysResourceTests { + @Autowired + private ISysResourceService sysResourceService; + + /** + * 公共按钮map + */ + private final static Map MAP = ImmutableMap.builder() + .put("list", "查询") + .put("add", "添加") + .put("edit", "编辑") + .put("delete", "删除") + .put("audit", "审核") + .put("unAudit", "取消审核") + .put("publish", "发布") + .put("unPublish", "取消发布") + .put("archives", "归档") + .put("unArchives", "取消归档") + .put("setPosition", "调整位置") + .put("exportToExcel", "导出Excel") + .put("recommend", "推荐") + .put("unRecommend", "取消推荐") + .put("used", "标记使用") + .put("clueFee", "线索费") + .put("show", "显示") + .put("unShow", "取消显示") + .put("send", "发放红包") + .put("refuse", "拒绝") + .put("top", "置顶") + .put("unTop", "取消置顶") + .put("handle", "处理") + .put("onShelves", "上架") + .put("offShell", "下架") + .put("push", "推送") + .put("recruit", "招聘管理") + .put("download", "下载简历模板") + .put("recruitmentDeliverInfoList", "查看职位投递信息") + .put("updateStatus", "操作提醒状态") + .put("option", "直播间设置") + .put("startLuckyBag", "直播间开启福袋") + .put("closeLuckyBag", "直播间关闭福袋") + .put("modifyLuckyBag", "直播间修改福袋") + .put("startRedPacket", "直播间开启红包") + .put("modifyRedPacket", "直播间修改红包") + .put("interaction", "直播间互动") + .put("data", "直播间数据") + .put("split", "直播间拆条") + .put("startLive", "直播间开始直播") + .put("stopLive", "直播间结束直播") + .put("modifyLive", "直播间修改直播") + .put("addLine", "直播间新增线路") + .put("breakLine", "直播间断开线路") + .put("restoreLine", "直播间恢复线路") + .put("modifyLine", "直播间修改线路") + .put("deleteLine", "直播间删除线路") + .put("addVote", "直播间添加投票") + .put("modifyVote", "直播间修改投票") + .put("deleteVote", "直播间删除投票") + .put("deleteComment", "直播间删除评论") + .put("cancelTopComment", "直播间取消置顶评论") + .put("topComment", "直播间置顶评论") + .put("addDraw", "直播间创建抽奖") + .put("addCoupon", "直播间创建优惠券") + .put("startCoupon", "直播间开启优惠券") + .put("closeCoupon", "直播间关闭优惠券") + .put("modifyCoupon", "直播间修改优惠券") + .put("updateBrowseMultiple", "浏览倍率") + .put("sliderManage", "轮播管理") + .put("navManage", "导航栏管理") + .put("start", "导播台开启") + .put("stop", "导播台关闭") + .put("detail", "导播台详情") + .put("canPublish", "可发布文章") + .put("sign", "标记") + .build(); + /**父级菜单查询条件 这里是根据路径找到对象 根据需求更换*/ + private final static String URL_WHERE = "/live/liveStudioGiftsList"; + /**按钮标识前缀 根据需求更换*/ + private final static String SUFFIX_IDENTITY = "live_studio_gifts"+"_"; + /**按钮名称前缀 根据需求更换*/ + private final static String SUFFIX_NAME = "直播间礼物"; + /**需要生成的按钮权限 已公共map中的为准 有其他公共权限可以自行添加到map 一般如果存在多个按钮 list按钮权限最好生成 根据需求更换*/ + private final static List COMMON_ROLE = Arrays.asList("list", "add","edit","delete","audit","unAudit"); +// "startRedPacket", "modifyRedPacket", "interaction", "data", "split", "startLive", "stopLive", "modifyLive", +// "addLine", "breakLine", "restoreLine", "modifyLine", "deleteLine", "addVote", "modifyVote", "deleteVote", +// "deleteComment", "cancelTopComment", "topComment", "addDraw", "addCoupon", "startCoupon", "closeCoupon"); + /** + * 公共添加 + */ + @Test + public void commonSave() { + SysResource where = new SysResource(); + where.setUrl(URL_WHERE); + List sysResourcesListDB = sysResourceService.getList(where); + COMMON_ROLE.forEach(item -> { + buildSave(sysResourcesListDB.get(0).getId().toString(), SUFFIX_IDENTITY + item, SUFFIX_NAME + MAP.get(item)); + }); + } + + /** + * 单个添加 + */ +// @Test +// public void save() { +// SysResource where = new SysResource(); +// where.setUrl(URL_WHERE); +// List sysResourcesListDB = sysResourceService.getList(where); +// buildSave(sysResourcesListDB.get(0).getId(), SUFFIX_IDENTITY + "generalize", SUFFIX_NAME + "微兔眼爆料跟踪信息"); +// } + + private void buildSave(String parentId, String identity, String name) { + SysResource req = new SysResource(); + req.setIdentity(identity); + req.setName(name); + req.setParentId(parentId); + req.setType(2); + req.setSort(1); + req.setIsShow(1); + sysResourceService.save(req, "admin"); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/pom.xml b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/pom.xml new file mode 100644 index 0000000..bd7bf59 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/pom.xml @@ -0,0 +1,93 @@ + + + 4.0.0 + + com.arm.equipment.system + arm-equipment-system-parent + 0.0.1-SNAPSHOT + + api + 0.0.1-SNAPSHOT + api + 接口工程 + + + 1.8 + + + + + com.arm.equipment.system + data + 0.0.1-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.springframework.session + spring-session-data-redis + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + javax.servlet + javax.servlet-api + + + + mysql + mysql-connector-java + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-web + + + + org.apache.commons + commons-lang3 + + + + com.alibaba + fastjson + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + arm-equipment-system-parent-${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/annotation/LoginCheck.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/annotation/LoginCheck.java new file mode 100644 index 0000000..39ca155 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/annotation/LoginCheck.java @@ -0,0 +1,13 @@ +package com.arm.equipment.system.api.annotation; + + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * 判断接口是否必须要登录才能使用 + * @author admin + */ +@Retention(RetentionPolicy.RUNTIME) +public @interface LoginCheck { +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/app/ApiApplication.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/app/ApiApplication.java new file mode 100644 index 0000000..b8affdf --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/app/ApiApplication.java @@ -0,0 +1,35 @@ +package com.arm.equipment.system.api.app; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.ServletListenerRegistrationBean; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; +import org.springframework.transaction.annotation.EnableTransactionManagement; +import org.springframework.web.util.IntrospectorCleanupListener; + +/** + * 工程启动配置 + * + * @author admin + */ +@SpringBootApplication +@ComponentScan("com.arm.equipment.system") +@EnableTransactionManagement +@EnableRedisHttpSession +@EnableCaching +public class ApiApplication { + + public static void main(String[] args) { + SpringApplication.run(ApiApplication.class, args); + } + + @Bean + public ServletListenerRegistrationBean introspectorCleanupListener() { + ServletListenerRegistrationBean listenerRegistration = new ServletListenerRegistrationBean(); + listenerRegistration.setListener(new IntrospectorCleanupListener()); + return listenerRegistration; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/app/ApiCorsConfiguration.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/app/ApiCorsConfiguration.java new file mode 100644 index 0000000..5e68d0c --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/app/ApiCorsConfiguration.java @@ -0,0 +1,38 @@ +package com.arm.equipment.system.api.app; + + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * CORS配置 + */ +@Configuration +public class ApiCorsConfiguration { + + @Bean + public CorsFilter corsFilter() { + // 添加CORS配置信息 + CorsConfiguration config = new CorsConfiguration(); + // 放行哪些原始域 + config.addAllowedOriginPattern("*"); + // 是否发送Cookie信息 + config.setAllowCredentials(true); + // 放行哪些原始域(请求方式) + config.addAllowedMethod("*"); + // 放行哪些原始域(头部信息) + config.addAllowedHeader("*"); + // 暴露哪些头部信息(因为跨域访问默认不能获取全部头部信息) + // config.addExposedHeader("*"); + + //2.添加映射路径 + UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource(); + configSource.registerCorsConfiguration("/**", config); + + //3.返回新的CorsFilter. + return new CorsFilter(configSource); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/app/InterceptorConfiguration.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/app/InterceptorConfiguration.java new file mode 100644 index 0000000..777741b --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/app/InterceptorConfiguration.java @@ -0,0 +1,77 @@ +package com.arm.equipment.system.api.app; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import com.arm.equipment.system.api.filter.LoginFilter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; + +import java.math.BigInteger; +import java.util.List; + + +/** + * @author: admin + * @time: 2022/9/16 11:20 + */ +@Configuration +public class InterceptorConfiguration extends WebMvcConfigurationSupport { + @Autowired + private LoginFilter loginFilter; + + @Override + protected void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(loginFilter) + .excludePathPatterns("/file/**"); + super.addInterceptors(registry); + } + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + /** + * @Description: 对文件的路径进行配置, 创建一个虚拟路径/Path/** ,即只要在便可以直接引用图片 + *这是图片的物理路径 "file:/+本地图片的地址" + */ + String os = System.getProperty("os.name"); + //Windows操作系统 + String resourcePath = System.getProperty("user.dir"); + if (os != null && os.toLowerCase().startsWith("windows")) { + resourcePath = resourcePath + "\\"; + } else { + resourcePath = resourcePath + "/"; + } + registry.addResourceHandler("/file/**").addResourceLocations("file:" + resourcePath); + super.addResourceHandlers(registry); + } + + @Override + protected void extendMessageConverters(List> converters) { + MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter(); + ObjectMapper objectMapper = new ObjectMapper(); + /** + * 序列换成json时,将所有的long变成string + * 因为js中得数字类型不能包含所有的java long值 + */ + SimpleModule simpleModule = new SimpleModule(); + simpleModule.addSerializer(Long.class, ToStringSerializer.instance); + simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); + simpleModule.addSerializer(BigInteger.class, ToStringSerializer.instance); + + // 反序列化时忽略多余字段 + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + + // 注册 + objectMapper.registerModule(simpleModule); + jackson2HttpMessageConverter.setObjectMapper(objectMapper); + converters.add(0, jackson2HttpMessageConverter); + super.extendMessageConverters(converters); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/BaseController.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/BaseController.java new file mode 100644 index 0000000..b2aa1f5 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/BaseController.java @@ -0,0 +1,16 @@ +package com.arm.equipment.system.api.controller; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; + +/** + * 接口的基础类 + * @author admin + */ +public abstract class BaseController{ + @Autowired + protected RedisTemplate redisTemplate; + protected Logger logger = LoggerFactory.getLogger(this.getClass()); +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/ExceptionController.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/ExceptionController.java new file mode 100644 index 0000000..a0fc1e3 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/ExceptionController.java @@ -0,0 +1,155 @@ +package com.arm.equipment.system.api.controller; + + +import com.alibaba.fastjson.JSON; +import com.arm.equipment.system.data.constant.ConstantValues; +import com.arm.equipment.system.data.exception.AuthException; +import com.arm.equipment.system.data.exception.BusinessException; +import com.arm.equipment.system.data.util.EnvUtil; +import com.arm.equipment.system.data.vo.RespJSON; +import com.arm.equipment.system.data.vo.ReturnCode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.QueryTimeoutException; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.validation.BindException; +import org.springframework.validation.FieldError; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; +import org.springframework.web.server.ServerWebInputException; +import org.springframework.web.server.UnsupportedMediaTypeStatusException; + +import javax.servlet.http.HttpServletRequest; +import java.text.ParseException; + +/** + * 统一异常处理 + * + * @author admin + */ +@ControllerAdvice +public class ExceptionController { + private final static Logger LOGGER = LoggerFactory.getLogger(ExceptionController.class); + @Autowired + private RedisTemplate redisTemplate; + + @ExceptionHandler(value = IllegalArgumentException.class) + @ResponseBody + public RespJSON illegalArgumentException(HttpServletRequest req, Exception e) { + if (EnvUtil.isDev()) { + LOGGER.error("异常", e); + } else { + LOGGER.info("异常: {}", e.getMessage()); + } + logErrDetail(req); + return RespJSON.returnCodeWithMessage(ReturnCode.CUSTOM_MESSAGE, "参数错误: " + e.getMessage()); + } + + @ExceptionHandler(value = MethodArgumentTypeMismatchException.class) + @ResponseBody + public RespJSON methodArgumentTypeMismatchException(HttpServletRequest req, Exception e) { + logErrDetail(req); + String field = ((MethodArgumentTypeMismatchException) e).getName(); + String rejectedValue = ((MethodArgumentTypeMismatchException) e).getValue().toString(); + String message = "参数:" + field + "注入的值不合法:" + rejectedValue; + LOGGER.error("入参错误", e); + return RespJSON.returnCodeWithMessage(ReturnCode.CUSTOM_MESSAGE, message); + } + + @ExceptionHandler(value = BusinessException.class) + @ResponseBody + public RespJSON customException(HttpServletRequest req, BusinessException e) { + if (EnvUtil.isDev()) { + LOGGER.error("自定义异常", e); + } else { + LOGGER.info("自定义异常: {}", e.getMessage()); + } + logErrDetail(req); + return RespJSON.returnCodeWithMessage(ReturnCode.CUSTOM_MESSAGE, e.getMessage()); + } + + @ExceptionHandler(value = AuthException.class) + @ResponseBody + public RespJSON authException(HttpServletRequest req, AuthException e) { + logErrDetail(req); + if (e.getReturnCode() != null) { + return RespJSON.returnCode(e.getReturnCode()); + } else { + return RespJSON.returnCode(ReturnCode.CODE_OK, e.getMessage()); + } + } + + @ExceptionHandler(value = BindException.class) + @ResponseBody + public RespJSON bindException(HttpServletRequest req, Exception e) { + logErrDetail(req); + FieldError fieldError = ((BindException) e).getBindingResult().getFieldError(); + String field = fieldError.getField(); + Object rejectedValue = fieldError.getRejectedValue(); + String message = "参数:" + field + "注入的值不合法:" + rejectedValue; + LOGGER.error("入参错误", e); + return RespJSON.returnCodeWithMessage(ReturnCode.CUSTOM_MESSAGE, message); + } + + @ExceptionHandler(value = ParseException.class) + @ResponseBody + public RespJSON parseException(HttpServletRequest req, Exception e) { + logErrDetail(req); + return RespJSON.returnCode(ReturnCode.PARSE_ERROR); + } + + @ExceptionHandler(value = UnsupportedMediaTypeStatusException.class) + @ResponseBody + public RespJSON unsupportedMediaTypeStatusException(HttpServletRequest req, Exception e) { + logErrDetail(req); + return RespJSON.returnCustomCodeWithMessage(ReturnCode.SYS_ERROR.getCode(), "错误的请求格式"); + } + + @ExceptionHandler(value = ServerWebInputException.class) + @ResponseBody + public RespJSON serverWebInputException(HttpServletRequest req, Exception e) { + logErrDetail(req); + LOGGER.error(e.getMessage(), e); + return RespJSON.returnCodeWithMessage(ReturnCode.CUSTOM_MESSAGE, "请在body中传参"); + } + + @ExceptionHandler(value = QueryTimeoutException.class) + @ResponseBody + public RespJSON queryTimeoutException(HttpServletRequest req, Exception e) { + logErrDetail(req); + LOGGER.error(e.getMessage(), e); + ((LettuceConnectionFactory)redisTemplate.getConnectionFactory()).initConnection(); + LOGGER.info("reset redis connection"); + return RespJSON.returnCode(ReturnCode.SYS_ERROR); + } + + @ExceptionHandler(value = Exception.class) + @ResponseBody + public RespJSON defaultErrorHandler(HttpServletRequest req, Exception e) { + logErrDetail(req); + LOGGER.error(e.getMessage(), e); + return RespJSON.returnCode(ReturnCode.SYS_ERROR); + } + + + /** + * 打印异常参数等信息 + * @param req + */ + private void logErrDetail(HttpServletRequest req) { + LOGGER.error("异常请求: {}", req.getRequestURI()); + LOGGER.error("异常参数: {}", JSON.toJSONString(req.getParameterMap())); + Object requestBody = req.getAttribute(ConstantValues.REQUEST_BODY); + if (null == requestBody) { + requestBody = ""; + } + LOGGER.error("异常参数: {}", requestBody.toString()); + LOGGER.error("异常UA: {}", req.getHeader("user-agent")); + LOGGER.error("异常referer: {}", req.getHeader("referer")); + LOGGER.error("异常Content-Type: {}", req.getHeader("Content-Type")); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/app/SysBaseParamAction.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/app/SysBaseParamAction.java new file mode 100644 index 0000000..670867b --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/app/SysBaseParamAction.java @@ -0,0 +1,41 @@ +package com.arm.equipment.system.api.controller.app; + +import com.arm.equipment.system.api.controller.BaseController; +import com.arm.equipment.system.data.domain.system.SysBaseParam; +import com.arm.equipment.system.data.service.system.ISysBaseParamService; +import com.arm.equipment.system.data.vo.RespJSON; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * 系统--基础参数 + * + * @author: admin + * @time: 2022/9/22 22:03 + */ +@RestController +@RequestMapping("/system/sysBaseParam") +public class SysBaseParamAction extends BaseController { + + @Autowired + private ISysBaseParamService sysBaseParamService; + + /** + * 主键查询 + * + * @param uniCode uniCode + * @return RespJSON + */ + @RequestMapping("/getOneUniCode/{uniCode}") + public RespJSON getOneUniCode(@PathVariable String uniCode) { + SysBaseParam baseParamDB = sysBaseParamService.getOneByUniCode(uniCode); + if (baseParamDB != null) { + //不返回备注 + baseParamDB.setDescription(null); + } + return RespJSON.success(baseParamDB); + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/common/UploadAction.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/common/UploadAction.java new file mode 100644 index 0000000..d7d69a9 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/common/UploadAction.java @@ -0,0 +1,54 @@ +package com.arm.equipment.system.api.controller.common; + + +import com.arm.equipment.system.api.controller.BaseController; +import com.arm.equipment.system.data.enums.file.EnumUpload; +import com.arm.equipment.system.data.exception.BusinessException; +import com.arm.equipment.system.data.service.file.IFileService; +import com.arm.equipment.system.data.util.StringUtils; +import com.arm.equipment.system.data.vo.RespJSON; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +/** + * 公共文件上传接口 + * + * @author: xly + * @time: 2023/3/10 10:55 + */ +@RestController +@RequestMapping("/common/file") +public class UploadAction extends BaseController { + @Autowired + private IFileService fileService; + + /** + * 文件上传接口 + * + * @param file + * @return + */ + @PostMapping("/upload") + public RespJSON upload(String uploadItem, @RequestParam("file") MultipartFile file) { + if (null == file) { + throw new BusinessException("文件不合法"); + } + EnumUpload enumUploadItem = EnumUpload.RES_PHOTO_LIB; + if (StringUtils.isNotBlank(uploadItem)) { + enumUploadItem = EnumUpload.getEnum(uploadItem); + } + if (enumUploadItem == null) { + throw new BusinessException("上传文件类目不正确"); + } + try { + return RespJSON.success(fileService.upload(file, enumUploadItem)); + } catch (Exception e) { + logger.error("文件上传错误", e); + throw new BusinessException("文件上传错误"); + } + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/dict/DictAction.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/dict/DictAction.java new file mode 100644 index 0000000..e8fe92f --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/dict/DictAction.java @@ -0,0 +1,30 @@ +package com.arm.equipment.system.api.controller.dict; + + +import com.arm.equipment.system.data.service.common.IDictService; +import com.arm.equipment.system.data.vo.RespJSON; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * 字典接口 + */ +@RestController +@RequestMapping("/common/dict") +public class DictAction { + @Autowired + private IDictService dictService; + + /** + * 统计枚举名称获得枚举的数据 + * + * @param name + * @return + */ + @RequestMapping("/getDictData/{name}") + public RespJSON getDictData(@PathVariable("name") String name) { + return RespJSON.success(dictService.getDictData(name)); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/user/AppUserAction.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/user/AppUserAction.java new file mode 100644 index 0000000..d6a121e --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/user/AppUserAction.java @@ -0,0 +1,75 @@ +package com.arm.equipment.system.api.controller.user; + +import com.arm.equipment.system.api.annotation.LoginCheck; +import com.arm.equipment.system.api.controller.BaseController; +import com.arm.equipment.system.api.util.LoginUtil; +import com.arm.equipment.system.data.constant.RedisKeys; +import com.arm.equipment.system.data.domain.user.AppUser; +import com.arm.equipment.system.data.exception.BusinessException; +import com.arm.equipment.system.data.service.user.IAppUserService; +import com.arm.equipment.system.data.vo.RespJSON; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import java.util.Optional; + +/** + * 用户 + * + * @author ousei + * @date 2020年11月4日15:13:16 + */ +@RestController +@RequestMapping("/user/appUser") +public class AppUserAction extends BaseController { + @Autowired + private IAppUserService appUserService; + + @LoginCheck + @PostMapping("/getUserInfo") + public RespJSON getBaseUserInfo(@SessionAttribute(value = LoginUtil.LOGIN_USER_SESSION_KEY, required = false) AppUser loginUser, HttpServletRequest request) { + AppUser appUserDB = Optional.ofNullable(appUserService.getOneById(loginUser.getId())).orElseThrow(() -> new BusinessException("用户不存在")); + LoginUtil.saveInCache(appUserDB, request); + return RespJSON.success(appUserDB); + } + + /** + * 登录 + * * @return + */ + @PostMapping("/login") + public RespJSON login(@RequestBody AppUser appUser, HttpServletRequest request) { + AppUser appUserDB = appUserService.login(appUser); + LoginUtil.saveInCache(appUserDB, request); + return RespJSON.success(appUserDB); + } + + /** + * 注册 + * + * @param req + * @return + */ + @PostMapping("/save") + public RespJSON save(@RequestBody AppUser req) { + appUserService.saveUser(req); + return RespJSON.success(); + } + + /** + * 退出登陆 + * + * @param loginUser + * @return + */ + @LoginCheck + @PostMapping("/logout") + public RespJSON logout(@SessionAttribute(LoginUtil.LOGIN_USER_SESSION_KEY) AppUser loginUser) { + // 删除登陆缓存 + redisTemplate.delete(RedisKeys.getAppUserSessionKey(loginUser.getToken())); + return RespJSON.success(); + } + + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/weaponry/WeaponryAction.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/weaponry/WeaponryAction.java new file mode 100644 index 0000000..5055113 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/weaponry/WeaponryAction.java @@ -0,0 +1,76 @@ +package com.arm.equipment.system.api.controller.weaponry; + +import com.arm.equipment.system.api.controller.BaseController; +import com.arm.equipment.system.data.domain.weaponry.Weaponry; +import com.arm.equipment.system.data.enums.dict.EnumStatus; +import com.arm.equipment.system.data.enums.dict.EnumYesNo; +import com.arm.equipment.system.data.service.weaponry.IWeaponryLendRecordService; +import com.arm.equipment.system.data.service.weaponry.IWeaponryService; +import com.arm.equipment.system.data.util.WJAssert; +import com.arm.equipment.system.data.vo.RespJSON; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * 装备武器 + * + * @author admin + * @date 2023年03月22日 10:39:04 + */ +@RestController +@RequestMapping("/weaponry/weaponry") +public class WeaponryAction extends BaseController { + + @Autowired + private IWeaponryService weaponryService; + @Autowired + private IWeaponryLendRecordService weaponryLendRecordService; + + /** + * 分页查询 + * + * @param weaponryReq weaponryReq + * @return RespJSON + */ + @PostMapping("/getPageList") + public RespJSON getPageList(@RequestBody Weaponry weaponryReq) { + WJAssert.notNull(weaponryReq.getPageNo(), "参数非法"); + WJAssert.notNull(weaponryReq.getPageSize(), "参数非法"); + weaponryReq.setStatus(EnumStatus.AUDIT.getCode()); + List list = weaponryService.getPageList(weaponryReq) + .parallelStream() + .peek(item -> { + item.setIsLend(EnumYesNo.NO.getCode()); + //判断是否已借出 + int count = weaponryLendRecordService.getCountByWeaponryId(item.getId()); + if (count > 0) { + item.setIsLend(EnumYesNo.YES.getCode()); + } + }).collect(Collectors.toList()); + + return RespJSON.success(list); + } + + /** + * 武器预警定位列表(查询借出数量大于1的武器列表) + * + * @param weaponryReq weaponryReq + * @return RespJSON + */ + @PostMapping("/getLocationWarningPageList") + public RespJSON getLocationWarningPageList(@RequestBody Weaponry weaponryReq) { + WJAssert.notNull(weaponryReq.getPageNo(), "参数非法"); + WJAssert.notNull(weaponryReq.getPageSize(), "参数非法"); + weaponryReq.setStatus(EnumStatus.AUDIT.getCode()); + weaponryReq.setLockInventoryStart(1); + List list = weaponryService.getPageList(weaponryReq); + return RespJSON.success(list); + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/weaponry/WeaponryLendRecordAction.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/weaponry/WeaponryLendRecordAction.java new file mode 100644 index 0000000..96bb4f6 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/weaponry/WeaponryLendRecordAction.java @@ -0,0 +1,58 @@ +package com.arm.equipment.system.api.controller.weaponry; + + +import com.arm.equipment.system.api.controller.BaseController; +import com.arm.equipment.system.data.domain.weaponry.WeaponryLendRecord; +import com.arm.equipment.system.data.enums.dict.EnumWeaponryLendRecordStatus; +import com.arm.equipment.system.data.service.weaponry.IWeaponryLendRecordService; +import com.arm.equipment.system.data.util.WJAssert; +import com.arm.equipment.system.data.vo.RespJSON; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * 装备武器借出表 + * + * @author admin + * @date 2023年03月22日 10:57:51 + */ +@RestController +@RequestMapping("/weaponry/weaponryLend") +public class WeaponryLendRecordAction extends BaseController { + + @Autowired + private IWeaponryLendRecordService weaponryLendRecordService; + + /** + * 保存或更新 + * + * @param weaponryLendRecord weaponryLendRecord + * @return RespJSON + */ + @PostMapping("/save") + public RespJSON save(@RequestBody WeaponryLendRecord weaponryLendRecord) { + weaponryLendRecordService.saveLend(weaponryLendRecord); + return RespJSON.success(); + } + + /** + * 分页查询 + * + * @param weaponryLendReq weaponryLendReq + * @return RespJSON + */ + @PostMapping("/getPageList") + public RespJSON getPageList(@RequestBody WeaponryLendRecord weaponryLendReq) { + WJAssert.notNull(weaponryLendReq.getPageNo(), "参数非法"); + WJAssert.notNull(weaponryLendReq.getPageSize(), "参数非法"); + weaponryLendReq.setStatus(EnumWeaponryLendRecordStatus.ADOPT.getCode()); + List pageList = weaponryLendRecordService.getPageList(weaponryLendReq); + return RespJSON.success(pageList); + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/weaponry/WeaponryReturnRecordAction.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/weaponry/WeaponryReturnRecordAction.java new file mode 100644 index 0000000..ad402c6 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/controller/weaponry/WeaponryReturnRecordAction.java @@ -0,0 +1,34 @@ +package com.arm.equipment.system.api.controller.weaponry; + +import com.arm.equipment.system.api.controller.BaseController; +import com.arm.equipment.system.data.service.weaponry.IWeaponryReturnRecordService; +import com.arm.equipment.system.data.vo.RespJSON; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +/** + * 装备武器归还日志 + * + * @author admin + * @date 2023年03月22日 10:42:24 + */ +@RestController +@RequestMapping("/weaponry/weaponryReturnRecord") +public class WeaponryReturnRecordAction extends BaseController { + + @Autowired + private IWeaponryReturnRecordService weaponryReturnRecordService; + + /** + * 保存归还 + * + * @param lendRecordId + * @return + */ + @GetMapping("/save") + public RespJSON save( Long lendRecordId) { + weaponryReturnRecordService.saveReturn(lendRecordId); + return RespJSON.success(); + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/filter/BodyReaderHttpServletRequestWrapper.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/filter/BodyReaderHttpServletRequestWrapper.java new file mode 100644 index 0000000..fa32531 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/filter/BodyReaderHttpServletRequestWrapper.java @@ -0,0 +1,91 @@ +package com.arm.equipment.system.api.filter; + +import javax.servlet.ReadListener; +import javax.servlet.ServletInputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; +import java.io.*; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + +/** + * request封装 + */ +public class BodyReaderHttpServletRequestWrapper extends HttpServletRequestWrapper { + + private final byte[] body; + private String bodyStr; + + public BodyReaderHttpServletRequestWrapper(HttpServletRequest request) throws IOException { + super(request); + String bodyString = getBodyString(request); + body = bodyString.getBytes(StandardCharsets.UTF_8); + bodyStr = bodyString; + } + + public String getBodyStr() { + return bodyStr; + } + + @Override + public ServletInputStream getInputStream() throws IOException { + final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body); + + return new ServletInputStream() { + @Override + public int read() throws IOException { + return byteArrayInputStream.read(); + } + + @Override + public boolean isFinished() { + return false; + } + + @Override + public boolean isReady() { + return false; + } + + @Override + public void setReadListener(ReadListener readListener) { + } + }; + } + + + public String getBodyString(HttpServletRequest request) throws IOException { + StringBuilder sb = new StringBuilder(); + InputStream inputStream = null; + BufferedReader reader = null; + try { + inputStream = request.getInputStream(); + reader = new BufferedReader( + new InputStreamReader(inputStream, Charset.forName("UTF-8"))); + + char[] bodyCharBuffer = new char[1024]; + int len = 0; + while ((len = reader.read(bodyCharBuffer)) != -1) { + sb.append(new String(bodyCharBuffer, 0, len)); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return sb.toString(); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/filter/LoginFilter.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/filter/LoginFilter.java new file mode 100644 index 0000000..1238d50 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/filter/LoginFilter.java @@ -0,0 +1,93 @@ +package com.arm.equipment.system.api.filter; + +import com.alibaba.fastjson.JSON; +import com.arm.equipment.system.api.annotation.LoginCheck; +import com.arm.equipment.system.api.util.LoginUtil; +import com.google.common.base.Throwables; +import com.arm.equipment.system.data.domain.user.AppUser; +import com.arm.equipment.system.data.util.StringUtils; +import com.arm.equipment.system.data.vo.RespJSON; +import com.arm.equipment.system.data.vo.ReturnCode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.Order; +import org.springframework.web.method.HandlerMethod; +import org.springframework.web.servlet.HandlerInterceptor; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.io.IOException; +import java.io.PrintWriter; + +/** + * 登录过滤器 + * 用于将登录信息放到session中 + **/ +@Order(1004) +@Configuration +public class LoginFilter implements HandlerInterceptor { + private final static Logger logger = LoggerFactory.getLogger(LoginFilter.class); + private final String NO_LOGIN_RETURN_INFO = JSON.toJSONString(RespJSON.returnCode(ReturnCode.NOT_LOGIN_ERROR)); + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + // 将 options 请求放过 + String method = request.getMethod(); + if ("options".equalsIgnoreCase(method)) { + return true; + } + HandlerMethod handlerMethod = (HandlerMethod) handler; + LoginCheck loginCheckAnnotation = handlerMethod.getMethodAnnotation(LoginCheck.class); + String userTokenHeader = request.getHeader("User-Token"); + AppUser loginUser; + // 不需要登录的接口直接放过 + if (null == loginCheckAnnotation) { + if (StringUtils.isEmpty(userTokenHeader)) { + return true; + } + // 没有获取到用户信息 直接报错 + loginUser = LoginUtil.getLoginUser(userTokenHeader); + + } else { + // 请求头没有token 直接报错 + if (StringUtils.isEmpty(userTokenHeader)) { + returnNoLogin(response); + return false; + } + // 没有获取到用户信息 直接报错 + loginUser = LoginUtil.getLoginUser(userTokenHeader); + if (null == loginUser) { + returnNoLogin(response); + return false; + } + } + + // 用户信息保存到session + AppUser finalLoginUser = loginUser; + HttpSession session = request.getSession(); + session.setAttribute(LoginUtil.LOGIN_USER_SESSION_KEY, finalLoginUser); + return true; + } + + /** + * 未登录时的返回内容 + * + * @param response + * @return + */ + private void returnNoLogin(HttpServletResponse response) { + response.setCharacterEncoding("UTF-8"); + response.setHeader("Content-Type", "application/json; charset=utf-8"); + PrintWriter writer = null; + try { + writer = response.getWriter(); + writer.write(NO_LOGIN_RETURN_INFO); + } catch (IOException e) { + logger.error(Throwables.getStackTraceAsString(e)); + } finally { + writer.close(); + } + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/filter/RequestBodyFilter.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/filter/RequestBodyFilter.java new file mode 100644 index 0000000..4469a39 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/filter/RequestBodyFilter.java @@ -0,0 +1,37 @@ +package com.arm.equipment.system.api.filter; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import javax.servlet.*; +import javax.servlet.annotation.WebFilter; +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; + +/** + * 记录用户请求参数 + */ +@Component +@WebFilter(filterName = "httpServletRequestWrapperFilter", urlPatterns = {"/"}) +public class RequestBodyFilter implements Filter { + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { + ServletRequest requestWrapper = null; + if (request instanceof HttpServletRequest) { + HttpServletRequest httpRequest = (HttpServletRequest) request; + //遇到post方法才对request进行包装 + String methodType = httpRequest.getMethod(); + String contentType = ((HttpServletRequest) request).getHeader("Content-Type"); + if (StringUtils.isNotEmpty(contentType) && contentType.contains("application/json") && "POST".equals(methodType)) { + requestWrapper = new BodyReaderHttpServletRequestWrapper((HttpServletRequest) request); + } + } + if (null == requestWrapper) { + chain.doFilter(request, response); + } else { + chain.doFilter(requestWrapper, response); + + } + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/util/LoginUtil.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/util/LoginUtil.java new file mode 100644 index 0000000..9e735cf --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/util/LoginUtil.java @@ -0,0 +1,121 @@ +package com.arm.equipment.system.api.util; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.arm.equipment.system.data.constant.RedisKeys; +import com.arm.equipment.system.data.domain.user.AppUser; +import com.arm.equipment.system.data.util.UuidUtils; +import com.arm.equipment.system.data.util.WJAssert; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.SetOperations; +import org.springframework.data.redis.core.ValueOperations; +import org.springframework.stereotype.Component; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; +import java.util.Set; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +/** + * 登录用户的工具类 + */ +@Component +public class LoginUtil { + private final static Logger logger = LoggerFactory.getLogger(LoginUtil.class); + private static RedisTemplate redisTemplate; + private static ValueOperations valueOps; + /** + * 登录用户在session中的key + */ + public static final String LOGIN_USER_SESSION_KEY = "appUserSessionKey"; + /** + * 50个线程, 无界队列, 超过异常 + */ + private final static ThreadPoolExecutor THREAD_POOL_EXECUTOR = new ThreadPoolExecutor(50, 50, 120, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new ThreadPoolExecutor.AbortPolicy()); + + public static AppUser getLoginUser(String token) { + WJAssert.isMaxLength(token, 500, "token非法"); + String key = RedisKeys.getAppUserSessionKey(token); + String s = valueOps.get(key); + if (StringUtils.isEmpty(s)) { + return null; + } + return JSONObject.parseObject(s, AppUser.class); + } + + /** + * 用户登录状态保存到redis + * 不会重新设置token + * + * @param appUser + * @param request + * @return + */ + public static AppUser refreshCache(AppUser appUser, HttpServletRequest request) { + String key = RedisKeys.getAppUserSessionKey(appUser.getToken()); + valueOps.set(key, JSON.toJSONString(appUser), 1, TimeUnit.DAYS); + HttpSession session = request.getSession(); + if (null == session) { + logger.info("session 是空的"); + return null; + } + session.setAttribute(LoginUtil.LOGIN_USER_SESSION_KEY, appUser); + return appUser; + } + + /** + * 用户登录状态保存到redis + * 会重新设置token + * + * @param appUser + * @param request + * @return + */ + public static AppUser saveInCache(AppUser appUser, HttpServletRequest request) { + appUser.setToken(UuidUtils.uuid()); + refreshCache(appUser, request); + // 保存token和用户的关系, 是个 set + String appUsernameByTokenSetKey = RedisKeys.getAppUsernameByTokenSetKey(appUser.getUsername()); + SetOperations setOps = redisTemplate.opsForSet(); + setOps.add(appUsernameByTokenSetKey, appUser.getToken()); + // 清除set中的过期token, 避免set过大 + clearUserTokenSet(appUsernameByTokenSetKey); + return appUser; + } + + /** + * 清除用户的登录token set避免过大 + * + * @param appUsernameByTokenSetKey + */ + private static void clearUserTokenSet(String appUsernameByTokenSetKey) { + THREAD_POOL_EXECUTOR.submit(() -> { + SetOperations setOps = redisTemplate.opsForSet(); + Set tokenSet = setOps.members(appUsernameByTokenSetKey); + if (CollectionUtils.isEmpty(tokenSet)) { + return; + } + tokenSet.forEach(token -> { + String appUserSessionKey = RedisKeys.getAppUserSessionKey(token); + Long expire = redisTemplate.getExpire(appUserSessionKey); + if (null == expire || expire < 0) { + logger.info("删除过期key {}", token); + setOps.remove(appUsernameByTokenSetKey, token); + } + }); + }); + } + + @Autowired + public void setRedisTemplate(RedisTemplate redisTemplate) { + LoginUtil.redisTemplate = redisTemplate; + LoginUtil.valueOps = redisTemplate.opsForValue(); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/vo/user/RefreshTokenVO.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/vo/user/RefreshTokenVO.java new file mode 100644 index 0000000..6927787 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/vo/user/RefreshTokenVO.java @@ -0,0 +1,24 @@ +package com.arm.equipment.system.api.vo.user; + +public class RefreshTokenVO { + /** 手机号 */ + private String data; + /** 平台 */ + private Integer platform; + + public Integer getPlatform() { + return platform; + } + + public void setPlatform(Integer platform) { + this.platform = platform; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/vo/user/UpdateUserVO.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/vo/user/UpdateUserVO.java new file mode 100644 index 0000000..a08d651 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/vo/user/UpdateUserVO.java @@ -0,0 +1,72 @@ +package com.arm.equipment.system.api.vo.user; + +import java.util.Date; + +/** + * + * 编辑用户信息VO + * @author: xly + * @time: 2022/9/19 12:00 + */ +public class UpdateUserVO { + /** 生日 */ + private Date birthday; + /** 昵称 */ + private String nickname; + /** 性别 1 男 2 女 */ + private Integer genderCode; + /** 所在地址 */ + private String address; + /** 学历 */ + private String education; + /**头像 */ + private String avatarPath; + + public String getAvatarPath() { + return avatarPath; + } + + public void setAvatarPath(String avatarPath) { + this.avatarPath = avatarPath; + } + + public Date getBirthday() { + return birthday; + } + + public void setBirthday(Date birthday) { + this.birthday = birthday; + } + + public String getNickname() { + return nickname; + } + + public void setNickname(String nickname) { + this.nickname = nickname; + } + + public Integer getGenderCode() { + return genderCode; + } + + public void setGenderCode(Integer genderCode) { + this.genderCode = genderCode; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getEducation() { + return education; + } + + public void setEducation(String education) { + this.education = education; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/vo/user/UserCenterVO.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/vo/user/UserCenterVO.java new file mode 100644 index 0000000..cada3fb --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/vo/user/UserCenterVO.java @@ -0,0 +1,34 @@ +package com.arm.equipment.system.api.vo.user; + +/** + * 用户中心VO + * @author: xly + * @time: 2021/11/19 17:41 + */ +public class UserCenterVO { + /** + * 用户ID + */ + private String userId; + /** + * 由于微兔眼小程序只统计爆料评论的总数 所以这里由此类型 + * 请求类型 type (0 智能农机云 1 微兔眼小程序) + */ + private Integer type; + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/vo/user/UserLoginVO.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/vo/user/UserLoginVO.java new file mode 100644 index 0000000..3226038 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/java/com/arm/equipment/system/api/vo/user/UserLoginVO.java @@ -0,0 +1,110 @@ +package com.arm.equipment.system.api.vo.user; + +/** + * 用户登录信息VO + * + * @author ousei + * @date 2020年11月4日15:17:48 + */ +public class UserLoginVO { + /** 手机号 */ + private String username; + /** 验证码 */ + private String verifyCode; + /** 设备TOKEN */ + private String deviceToken; + /** unionid */ + private String unionid; + /** 登录的类型 */ + private Integer loginType; + /**用户密码*/ + private String password; + /**平台*/ + private Integer platform; + /**邀请码*/ + private String invcode; + /**微信code**/ + private String code; + /**一键登录手机号token*/ + private String usernameToken; + + public String getUsernameToken() { + return usernameToken; + } + + public void setUsernameToken(String usernameToken) { + this.usernameToken = usernameToken; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public Integer getPlatform() { + return platform; + } + + public void setPlatform(Integer platform) { + this.platform = platform; + } + + public String getInvcode() { + return invcode; + } + + public void setInvcode(String invcode) { + this.invcode = invcode; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public Integer getLoginType() { + return loginType; + } + + public void setLoginType(Integer loginType) { + this.loginType = loginType; + } + + public String getUnionid() { + return unionid; + } + + public void setUnionid(String unionid) { + this.unionid = unionid; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getVerifyCode() { + return verifyCode; + } + + public void setVerifyCode(String verifyCode) { + this.verifyCode = verifyCode; + } + + public String getDeviceToken() { + return deviceToken; + } + + public void setDeviceToken(String deviceToken) { + this.deviceToken = deviceToken; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/resources/application-dev.yml b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/resources/application-dev.yml new file mode 100644 index 0000000..30a52df --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/resources/application-dev.yml @@ -0,0 +1,31 @@ +env: dev +spring: + datasource: + url: jdbc:mysql://127.0.0.1:3306/arm-equipment-system?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: + type: com.zaxxer.hikari.HikariDataSource + hikari: + auto-commit: true + connection-timeout: 30000 + idle-timeout: 600000 + max-lifetime: 1800000 + minimum-idle: 1 + maximum-pool-size: 10 + pool-name: hikaricp + validation-timeout: 5000 + redis: + host: 127.0.0.1 + port: 6379 + password: + database: 0 + timeout: 5000ms + lettuce: + pool: + max-idle: 100 + min-idle: 1 + max-active: 1000 + web: + resources: + static-locations: file:admin/src/main/resources/static diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/resources/application.yml b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/resources/application.yml new file mode 100644 index 0000000..d80075d --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/resources/application.yml @@ -0,0 +1,21 @@ +git: + version: "@git.commit.id.abbrev@" + commitTime: "@git.commit.time@" +server: + port: 8088 + compression: + enabled: true + mime-types: application/javascript,text/css,application/json,application/xml,text/html,text/xml,text/plain +spring: + jackson: + serialization: + write-dates-as-timestamps: true + output: + ansi: + enabled: always + webflux: + static-path-pattern: /** + session: + store-type: redis + profiles: + active: dev diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/resources/logback-spring.xml b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..c0898d6 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/main/resources/logback-spring.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + ${log.base}.log + + true + 30 + + ${log.base}.%d{yyyy-MM-dd}.log + + + + + %date [%thread] %-5level %logger{80} - %msg%n + + + + + + + + + + + + + + diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/test/java/com/arm/equipment/system/api/ApiApplicationTests.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/test/java/com/arm/equipment/system/api/ApiApplicationTests.java new file mode 100644 index 0000000..83c2b60 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/api/src/test/java/com/arm/equipment/system/api/ApiApplicationTests.java @@ -0,0 +1,22 @@ +package com.arm.equipment.system.api; + +import com.arm.equipment.system.api.app.ApiApplication; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +@SpringBootTest(classes = ApiApplication.class) +@ActiveProfiles(profiles = "dev") +public class ApiApplicationTests { + private final static Logger LOGGER = LoggerFactory.getLogger(ApiApplicationTests.class); + + @Test + public void test() { + + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/pom.xml b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/pom.xml new file mode 100644 index 0000000..ac9ec02 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/pom.xml @@ -0,0 +1,141 @@ + + + 4.0.0 + + com.arm.equipment.system + arm-equipment-system-parent + 0.0.1-SNAPSHOT + + data + 0.0.1-SNAPSHOT + data + 业务公共项目 + + + + org.springframework.boot + spring-boot-starter-web + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-aop + + + + mysql + mysql-connector-java + + + + org.apache.commons + commons-lang3 + + + + com.alibaba + fastjson + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + org.springframework.boot + spring-boot-starter + + + + org.apache.commons + commons-pool2 + + + + org.bouncycastle + bcprov-jdk16 + 1.46 + + + + + org.apache.velocity + velocity + 1.7 + test + + + + org.springframework.boot + spring-boot-starter-test + test + + + com.alibaba + easyexcel + + + commons-logging + commons-logging + + + 1.1.1 + + + org.apache.httpcomponents + httpmime + 4.5.2 + + + + javax.validation + validation-api + 2.0.1.Final + + + org.hibernate + hibernate-validator + 5.2.0.Final + + + commons-lang + commons-lang + 2.6 + + + + org.jsoup + jsoup + 1.13.1 + + + + com.belerweb + pinyin4j + 2.5.0 + + + javax.servlet + javax.servlet-api + 4.0.1 + + + + com.google.zxing + javase + 3.0.0 + + + com.google.guava + guava + 16.0.1 + + + + diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/app/AsyncConfiguration.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/app/AsyncConfiguration.java new file mode 100644 index 0000000..d2c62c0 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/app/AsyncConfiguration.java @@ -0,0 +1,36 @@ +package com.arm.equipment.system.data.app; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; + +import java.util.concurrent.Executor; +import java.util.concurrent.ThreadPoolExecutor; + +/** + * spring异步配置 + * @author admin + */ +@Configuration +@EnableAsync +public class AsyncConfiguration { + + @Bean + public Executor threadPoolTaskExecutor() { + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + executor.setCorePoolSize(1); + executor.setMaxPoolSize(100); + executor.setQueueCapacity(1000); + executor.setThreadNamePrefix("thread-pool-"); + executor.setKeepAliveSeconds(120); + executor.setDaemon(true); + executor.setWaitForTasksToCompleteOnShutdown(true); + executor.setAwaitTerminationSeconds(90); + // CALLER_RUNS:当抛出RejectedExecutionException异常时,会调rejectedExecution方法 调用者运行策略实现了一种调节机制, + // 该策略既不会抛弃任务也不会爆出异常,而是将任务退回给调用者,从而降低新任务的流量 + executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); + executor.initialize(); + return executor; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/app/BCryptConfiguration.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/app/BCryptConfiguration.java new file mode 100644 index 0000000..ffec75c --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/app/BCryptConfiguration.java @@ -0,0 +1,25 @@ +package com.arm.equipment.system.data.app; + +import com.arm.equipment.system.data.util.passwordEncoder.BCryptPasswordEncoderUtils; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * + * + * @author: admin + * @time: 2022/9/16 11:20 + */ +@Configuration +public class BCryptConfiguration { + + /** + * BCrypt密码校验 + * + * @return + */ + @Bean + public BCryptPasswordEncoderUtils bCryptPasswordEncoder() { + return new BCryptPasswordEncoderUtils(5, null); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/app/DataApplication.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/app/DataApplication.java new file mode 100644 index 0000000..d0db0e7 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/app/DataApplication.java @@ -0,0 +1,17 @@ +package com.arm.equipment.system.data.app; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@SpringBootApplication +@EnableTransactionManagement +@ComponentScan("com.arm.equipment.system") +public class DataApplication { + + public static void main(String[] args) { + SpringApplication.run(DataApplication.class, args); + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/app/MyBatisConfiguration.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/app/MyBatisConfiguration.java new file mode 100644 index 0000000..07f11c2 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/app/MyBatisConfiguration.java @@ -0,0 +1,52 @@ +package com.arm.equipment.system.data.app; + +import com.arm.equipment.system.data.exception.BusinessException; +import com.zaxxer.hikari.HikariDataSource; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.ibatis.mapping.VendorDatabaseIdProvider; +import org.apache.ibatis.session.SqlSessionFactory; +import org.mybatis.spring.SqlSessionFactoryBean; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.core.io.support.ResourcePatternResolver; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; + +/** + * mybatis配置 + * @author admin + */ +@MapperScan("com.arm.equipment.system.data.mapper") +@Configuration +public class MyBatisConfiguration { + + @Bean(name = "sessionFactory") + public SqlSessionFactory sessionFactory(HikariDataSource dataSource) { + SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); + bean.setDataSource(dataSource); + bean.setDatabaseIdProvider(new VendorDatabaseIdProvider()); + bean.setTypeHandlersPackage("com.arm.equipment.system.data.mybatis.type"); + + //添加XML目录 + ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); + try { + //设置xml扫描路径 + Resource[] baseMapperResource = resolver.getResources("classpath*:/mybatis/base-mapper.xml"); + Resource[] resources = resolver.getResources("classpath*:/mybatis/**/*.xml"); + bean.setMapperLocations(ArrayUtils.addAll(resources, resources)); + return bean.getObject(); + } catch (Exception e) { + throw new BusinessException("sessionFactory init fail",e); + } + } + + /** + * 配置事务管理器 + */ + @Bean(name = "transactionManager") + public DataSourceTransactionManager transactionManager(HikariDataSource dataSource) { + return new DataSourceTransactionManager(dataSource); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/app/RedisConfiguration.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/app/RedisConfiguration.java new file mode 100644 index 0000000..418e6a7 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/app/RedisConfiguration.java @@ -0,0 +1,174 @@ +package com.arm.equipment.system.data.app; + +import com.arm.equipment.system.data.constant.RedisKeys; +import org.apache.commons.pool2.impl.GenericObjectPoolConfig; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.autoconfigure.data.redis.RedisProperties; +import org.springframework.boot.context.event.ApplicationStartedEvent; +import org.springframework.context.ApplicationEvent; +import org.springframework.context.ApplicationListener; +import org.springframework.context.Lifecycle; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.context.event.ContextClosedEvent; +import org.springframework.data.redis.cache.RedisCacheConfiguration; +import org.springframework.data.redis.cache.RedisCacheManager; +import org.springframework.data.redis.cache.RedisCacheWriter; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.RedisStandaloneConfiguration; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; +import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration; +import org.springframework.data.redis.connection.stream.MapRecord; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.RedisSerializationContext; +import org.springframework.data.redis.serializer.RedisSerializer; +import org.springframework.data.redis.serializer.StringRedisSerializer; +import org.springframework.data.redis.stream.StreamMessageListenerContainer; + +import java.time.Duration; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +/** + * redis 配置 + * + * @author admin + */ +@Configuration +public class RedisConfiguration implements ApplicationListener { + @Autowired + private RedisProperties redisProperties; + /** + * 100个线程, 无界队列, 超过异常 + */ + private final static ThreadPoolExecutor THREAD_POOL_EXECUTOR = new ThreadPoolExecutor(100, 100, 120, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new ThreadPoolExecutor.AbortPolicy()); + + /** + * lettuce对象连接池 + * + * @return + */ + @Bean + public LettuceConnectionFactory lettuceConnectionFactory() { + RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration(); + configuration.setHostName(redisProperties.getHost()); + configuration.setDatabase(redisProperties.getDatabase()); + configuration.setPort(redisProperties.getPort()); + configuration.setPassword(redisProperties.getPassword()); + //连接池配置 + GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); + RedisProperties.Pool pool = redisProperties.getLettuce().getPool(); + poolConfig.setMaxIdle(20); + poolConfig.setMinIdle(1); + poolConfig.setMaxTotal(100); + poolConfig.setMaxWaitMillis(3000); + poolConfig.setTimeBetweenEvictionRunsMillis(20000); + poolConfig.setTestWhileIdle(true); + LettucePoolingClientConfiguration clientConfiguration = LettucePoolingClientConfiguration.builder() + .commandTimeout(Duration.ofSeconds(10)) + .poolConfig(poolConfig).build(); + return new LettuceConnectionFactory(configuration, clientConfiguration); + } + + @Bean + public RedisTemplate getTemplate(@Qualifier(value = "redisTemplate") RedisTemplate template) { + template.setConnectionFactory(lettuceConnectionFactory()); + template.setDefaultSerializer(new StringRedisSerializer()); + template.setKeySerializer(new StringRedisSerializer()); + template.setValueSerializer(new StringRedisSerializer()); + template.setHashKeySerializer(new GenericJackson2JsonRedisSerializer()); + template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer()); + return template; + } + + /** + * 缓存管理器 + * 1.默认缓存为1天 + * + * @return + */ + @Bean + @Primary + public RedisCacheManager cacheManager() { + RedisCacheWriter redisCacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(lettuceConnectionFactory()); + GenericJackson2JsonRedisSerializer genericJackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializer(); + RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig() + .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(RedisSerializer.string())) + .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(genericJackson2JsonRedisSerializer)) + .entryTtl(Duration.ofDays(1)); + RedisCacheManager redisCacheManager = RedisCacheManager.builder(redisCacheWriter) + .cacheDefaults(redisCacheConfiguration) + .withInitialCacheConfigurations(getRedisCacheConfigurationMap()).build(); + return redisCacheManager; + } + + /** + * 为指定 key 设置过期时间 + * + * @return + */ + private Map getRedisCacheConfigurationMap() { + Map redisCacheConfigurationMap = new HashMap<>(); + redisCacheConfigurationMap.put(RedisKeys.WECHAT_ACCESS_TOKEN, getRedisCacheConfigurationWithTtl(600)); + // 直播间统计ID集合 默认保存七天 + return redisCacheConfigurationMap; + } + + private RedisCacheConfiguration getRedisCacheConfigurationWithTtl(Integer seconds) { + GenericJackson2JsonRedisSerializer genericJackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializer(); + return RedisCacheConfiguration.defaultCacheConfig() + .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(RedisSerializer.string())) + .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(genericJackson2JsonRedisSerializer)) + .computePrefixWith(name -> name + ":").entryTtl(Duration.ofSeconds(seconds)); + } + + + /** + * 流监听容器, 这里只是创建, 需要在下面启动 + * + * @param redisConnectionFactory + * @return + */ + @Bean + public StreamMessageListenerContainer> streamMessageListenerContainer(RedisConnectionFactory redisConnectionFactory) { + // 创建配置对象 + StreamMessageListenerContainer.StreamMessageListenerContainerOptions> listenerContainerOptions = StreamMessageListenerContainer.StreamMessageListenerContainerOptions + .builder() + // 一次性最多拉取多少条消息 + .batchSize(100) + .executor(THREAD_POOL_EXECUTOR) + .build(); + // 根据配置对象创建监听容器 + + StreamMessageListenerContainer> listenerContainer = StreamMessageListenerContainer.create(redisConnectionFactory, listenerContainerOptions); + return listenerContainer; + } + + /** + * 1.spring启动后启动redis监听容器 + * 2.spring结束后关闭redis监听容器 + * + * @param applicationEvent + */ + @Override + public void onApplicationEvent(ApplicationEvent applicationEvent) { + if (applicationEvent instanceof ApplicationStartedEvent) { + // 启动redis stream 监听 + ((ApplicationStartedEvent) applicationEvent).getApplicationContext() + .getBeanProvider(StreamMessageListenerContainer.class) + .ifAvailable(Lifecycle::start); + } + if (applicationEvent instanceof ContextClosedEvent) { + // 启动redis stream 监听 + ((ContextClosedEvent) applicationEvent).getApplicationContext() + .getBeanProvider(StreamMessageListenerContainer.class) + .ifAvailable(Lifecycle::stop); + } + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/app/RestTemplateConfiguration.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/app/RestTemplateConfiguration.java new file mode 100644 index 0000000..3a1d53a --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/app/RestTemplateConfiguration.java @@ -0,0 +1,47 @@ +package com.arm.equipment.system.data.app; + +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.alibaba.fastjson.support.config.FastJsonConfig; +import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.client.SimpleClientHttpRequestFactory; +import org.springframework.http.converter.FormHttpMessageConverter; +import org.springframework.http.converter.StringHttpMessageConverter; +import org.springframework.web.client.RestTemplate; + +import java.util.ArrayList; +import java.util.List; + +@Configuration +public class RestTemplateConfiguration { + @Bean(name = "restTemplate") + public RestTemplate getRestTemplate() { + List messageConverters = new ArrayList<>(); + messageConverters.add(new FormHttpMessageConverter()); + messageConverters.add(getFastJsonHttpMessageConverter()); + messageConverters.add(new StringHttpMessageConverter()); + RestTemplate restTemplate = new RestTemplate(getHttpRequestFactory()); + restTemplate.setMessageConverters(messageConverters); + return restTemplate; + } + + private FastJsonHttpMessageConverter getFastJsonHttpMessageConverter() { + FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter(); + fastJsonHttpMessageConverter.setFastJsonConfig(getFastJsonConfig()); + return fastJsonHttpMessageConverter; + } + + private FastJsonConfig getFastJsonConfig() { + FastJsonConfig fastJsonConfig = new FastJsonConfig(); + fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteDateUseDateFormat); + return fastJsonConfig; + } + + private SimpleClientHttpRequestFactory getHttpRequestFactory() { + SimpleClientHttpRequestFactory simpleClientHttpRequestFactory = new SimpleClientHttpRequestFactory(); + simpleClientHttpRequestFactory.setConnectTimeout(120000); + simpleClientHttpRequestFactory.setReadTimeout(120000); + return simpleClientHttpRequestFactory; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/constant/ConstantValues.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/constant/ConstantValues.java new file mode 100644 index 0000000..c822b04 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/constant/ConstantValues.java @@ -0,0 +1,13 @@ +package com.arm.equipment.system.data.constant; + +import java.util.Arrays; +import java.util.List; + +/** + * 全局变量存放处 + * @author wyd + */ +public class ConstantValues { + /** request请求中的参数 */ + public final static String REQUEST_BODY = "WJ-Request-Body"; +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/constant/RedisKeys.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/constant/RedisKeys.java new file mode 100644 index 0000000..09d6080 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/constant/RedisKeys.java @@ -0,0 +1,29 @@ +package com.arm.equipment.system.data.constant; + +/** + * redisKey集合 + */ +public class RedisKeys { + public final static String SYS_BASE_PARAM_KEY = "sysBaseParamKey"; + /** * 微信accesstoken*/ + public final static String WECHAT_ACCESS_TOKEN = "wechatAccessToken"; + /*** id worker service中的worker id*/ + public static final String SNOW_FLAKE_WORKER_ID = "snow:flake_worker:id"; + /**系统用户登陆错误次数*/ + public static final String SYS_USER_LOGIN_ERROR_NUM = "sys:user:login:error:num:%s"; + /** + * token和用户的对应关系 + *

+ * 数据结构: SET + * + * @param token + * @return + */ + public static String getAppUsernameByTokenSetKey(String token) { + return String.format("app:user:token:%s", token); + } + + public static String getAppUserSessionKey(String token) { + return String.format("app:user:session:%s", token); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/BaseDomain.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/BaseDomain.java new file mode 100644 index 0000000..f6d2bb7 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/BaseDomain.java @@ -0,0 +1,65 @@ +package com.arm.equipment.system.data.domain; + +import java.util.Date; + +/** + * 数据库实体基类 + * @author admin + */ +public class BaseDomain extends BasePage { + /** 主键 */ + private Long id; + /** 创建时间 */ + private Date createTime; + /** 更新时间 */ + private Date updateTime; + /** 更新时间结束 */ + private Date updateTimeEnd; + /** 操作人*/ + private String operator; + /** 备注 */ + private String remark; + + public String getOperator() { + return operator; + } + + public void setOperator(String operator) { + this.operator = operator; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Date getCreateTime() { return createTime; } + + public void setCreateTime(Date createTime) { this.createTime = createTime; } + + public Date getUpdateTime() { return updateTime; } + + public void setUpdateTime(Date updateTime) { this.updateTime = updateTime; } + + public Date getUpdateTimeEnd() { return updateTimeEnd; } + + public void setUpdateTimeEnd(Date updateTimeEnd) { this.updateTimeEnd = updateTimeEnd; } + + public String getRemark() { return remark; } + + public void setRemark(String remark) { this.remark = remark; } + + @Override + public String toString() { + return "BaseDomain{" + + "id=" + id + + ", createTime=" + createTime + + ", updateTime=" + updateTime + + ", updateTimeEnd=" + updateTimeEnd + + ", remark='" + remark + '\'' + + '}'; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/BasePage.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/BasePage.java new file mode 100644 index 0000000..8b4ff6c --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/BasePage.java @@ -0,0 +1,49 @@ +package com.arm.equipment.system.data.domain; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.Serializable; + +/** + * 每个对象都需要继承的类, 用于分页 + * @author admin + */ +public class BasePage implements Serializable { + private static final Logger LOGGER = LoggerFactory.getLogger(BasePage.class); + private static final long serialVersionUID = -320995871886379593L; + /** 页码 */ + private Integer pageNo; + /** 每页大小 */ + private Integer pageSize; + + public Integer getPageNo() { + return pageNo; + } + + public void setPageNo(Integer pageNo) { + this.pageNo = pageNo; + } + + public Integer getPageSize() { + //最大限制为5000 + if (null != pageSize && pageSize > 5000) { + LOGGER.warn(" pageSize 过大!!!pageSize={}", pageSize); + return 5000; + } + return pageSize; + } + + public void setPageSize(Integer pageSize) { + this.pageSize = pageSize; + } + + @JsonIgnore + public Integer getStartIndex() { + if (pageNo == null || pageSize == null) { + return null; + } + return (this.pageNo - 1) * this.pageSize; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/PageResult.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/PageResult.java new file mode 100644 index 0000000..f3f5281 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/PageResult.java @@ -0,0 +1,94 @@ +package com.arm.equipment.system.data.domain; + +import java.util.Collection; + +/** + * @author admin + */ +public class PageResult { + /** 页数 */ + private int pageNo; + /** 总页数 */ + private int pageCount; + /** 总条数 */ + private int total; + /** 数据 */ + private Collection rows; + /** 页大小 */ + private int pageSize; + + public PageResult() { + } + + public PageResult(int pageNo, int pageSize, int total, Collection rows) { + this.pageNo = pageNo; + this.total = total; + this.rows = rows; + this.pageSize = pageSize; + this.pageCount = calcPageCount(total); + + } + + private int calcPageCount(int count) { + if (pageSize == 0) { + return 0; + } + if (count % pageSize == 0) { + return count / pageSize; + } else { + return count / pageSize + 1; + + } + } + + public static int getPageCount(int count, int pageSize) { + if (pageSize == 0) { + return 0; + } + if (count % pageSize == 0) { + return count / pageSize; + } else { + return count / pageSize + 1; + } + } + + public int getPageSize() { + return pageSize; + } + + public void setPageSize(int pageSize) { + this.pageSize = pageSize; + } + + public int getPageNo() { + return pageNo; + } + + public void setPageNo(int pageNo) { + this.pageNo = pageNo; + } + + public int getPageCount() { + return pageCount; + } + + public void setPageCount(int pageCount) { + this.pageCount = pageCount; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public Collection getRows() { + return rows; + } + + public void setRows(Collection rows) { + this.rows = rows; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/system/SysBaseParam.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/system/SysBaseParam.java new file mode 100644 index 0000000..ecbe306 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/system/SysBaseParam.java @@ -0,0 +1,67 @@ +package com.arm.equipment.system.data.domain.system; + +import com.arm.equipment.system.data.domain.BaseDomain; + +/** + * 系统--基础参数 + * + * @author Administrator + * @date 2021年10月26日 16:36:52 + */ +public class SysBaseParam extends BaseDomain { + /** 唯一编码 */ + private String uniCode; + /** 值 */ + private String value; + /** 描述 */ + private String description; + /** 操作人 */ + private String operator; + /** 数据状态 */ + private Integer status; + + public String getUniCode() { + return uniCode; + } + + public void setUniCode(String uniCode) { + this.uniCode = uniCode; + } + + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + + public String getOperator() { + return operator; + } + + public void setOperator(String operator) { + this.operator = operator; + } + + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/system/SysLog.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/system/SysLog.java new file mode 100644 index 0000000..0b34c59 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/system/SysLog.java @@ -0,0 +1,111 @@ +package com.arm.equipment.system.data.domain.system; + +import com.arm.equipment.system.data.domain.BaseDomain; + +/** + * 日志表 + * + * @author admin + * @date 2022年09月16日 12:41:35 + */ +public class SysLog extends BaseDomain { + /** 日志类型(1:接入日志;2:错误日志) */ + private Integer type; + /** 日志标题 */ + private String title; + /** 操作IP地址 */ + private String remoteAddr; + /** 用户代理 */ + private String userAgent; + /** 请求URI */ + private String requestUri; + /** 操作方式 */ + private String method; + /** 操作提交的数据 */ + private String params; + /** 异常信息 */ + private String exception; + /** 状态 */ + private Integer status; + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + + public String getRemoteAddr() { + return remoteAddr; + } + + public void setRemoteAddr(String remoteAddr) { + this.remoteAddr = remoteAddr; + } + + + public String getUserAgent() { + return userAgent; + } + + public void setUserAgent(String userAgent) { + this.userAgent = userAgent; + } + + + public String getRequestUri() { + return requestUri; + } + + public void setRequestUri(String requestUri) { + this.requestUri = requestUri; + } + + + public String getMethod() { + return method; + } + + public void setMethod(String method) { + this.method = method; + } + + + public String getParams() { + return params; + } + + public void setParams(String params) { + this.params = params; + } + + + public String getException() { + return exception; + } + + public void setException(String exception) { + this.exception = exception; + } + + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/system/SysResource.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/system/SysResource.java new file mode 100644 index 0000000..3bcb845 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/system/SysResource.java @@ -0,0 +1,166 @@ +package com.arm.equipment.system.data.domain.system; + +import com.arm.equipment.system.data.domain.BaseDomain; + +import java.util.List; + +/** + * 系统--权限表 + * + * @author admin + * @date 2021年10月20日 08:59:10 + */ +public class SysResource extends BaseDomain { + /** 菜单名称 */ + private String name; + /** 链接地址 */ + private String url; + /** 父菜单ID */ + private String parentId; + /** 图标 */ + private String icon; + /** 排序 */ + private Integer sort; + /** 菜单类型 */ + private Integer type; + /** 权限标识 */ + private String identity; + /** 是否显示 */ + private Integer isShow; + /** 状态 */ + private Integer status; + /** 操作人 */ + private String operator; + /** 根路径,用.分隔 */ + private String rootPath; + + /********VO******/ + /**子集集合*/ + private List children; + /**标签*/ + private String label; + /**ID集合*/ + private List idsList; + + public List getIdsList() { + return idsList; + } + + public void setIdsList(List idsList) { + this.idsList = idsList; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + + public String getParentId() { + return parentId; + } + + public void setParentId(String parentId) { + this.parentId = parentId; + } + + + public String getIcon() { + return icon; + } + + public void setIcon(String icon) { + this.icon = icon; + } + + + public Integer getSort() { + return sort; + } + + public void setSort(Integer sort) { + this.sort = sort; + } + + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + + public String getIdentity() { + return identity; + } + + public void setIdentity(String identity) { + this.identity = identity; + } + + + public Integer getIsShow() { + return isShow; + } + + public void setIsShow(Integer isShow) { + this.isShow = isShow; + } + + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + + public String getOperator() { + return operator; + } + + public void setOperator(String operator) { + this.operator = operator; + } + + + public String getRootPath() { + return rootPath; + } + + public void setRootPath(String rootPath) { + this.rootPath = rootPath; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/system/SysRole.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/system/SysRole.java new file mode 100644 index 0000000..19a89f1 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/system/SysRole.java @@ -0,0 +1,69 @@ +package com.arm.equipment.system.data.domain.system; + +import com.arm.equipment.system.data.domain.BaseDomain; + +import java.util.List; + +/** + * 系统--角色表 + * + * @author admin + * @date 2021年10月19日 15:06:47 + */ +public class SysRole extends BaseDomain { + /** 角色名称 */ + private String name; + /** 描述 */ + private String description; + /** 状态 */ + private Integer status; + /** 操作人 */ + private String operator; + + /****** VO ***/ + /**角色ID集合*/ + private List sysRoleIdList; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + + public String getOperator() { + return operator; + } + + public void setOperator(String operator) { + this.operator = operator; + } + + public List getSysRoleIdList() { + return sysRoleIdList; + } + + public void setSysRoleIdList(List sysRoleIdList) { + this.sysRoleIdList = sysRoleIdList; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/system/SysRoleResource.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/system/SysRoleResource.java new file mode 100644 index 0000000..8648703 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/system/SysRoleResource.java @@ -0,0 +1,70 @@ +package com.arm.equipment.system.data.domain.system; + +import com.arm.equipment.system.data.domain.BaseDomain; + +import java.util.List; + +/** + * 系统-角色权限关联表 + * + * @author admin + * @date 2021年10月19日 15:06:41 + */ +public class SysRoleResource extends BaseDomain { + /** 角色ID */ + private Long sysRoleId; + /** 权限ID */ + private Long sysResourceId; + /** 状态 */ + private Integer status; + /** 操作人 */ + private String operator; + + /****** VO ***/ + /**添加新权限(修改权限)*/ + private List newResources; + + public List getNewResources() { + return newResources; + } + + public void setNewResources(List newResources) { + this.newResources = newResources; + } + + public Long getSysRoleId() { + return sysRoleId; + } + + public void setSysRoleId(Long sysRoleId) { + this.sysRoleId = sysRoleId; + } + + + public Long getSysResourceId() { + return sysResourceId; + } + + public void setSysResourceId(Long sysResourceId) { + this.sysResourceId = sysResourceId; + } + + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + + public String getOperator() { + return operator; + } + + public void setOperator(String operator) { + this.operator = operator; + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/system/SysUser.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/system/SysUser.java new file mode 100644 index 0000000..7bcc362 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/system/SysUser.java @@ -0,0 +1,172 @@ +package com.arm.equipment.system.data.domain.system; + +import com.arm.equipment.system.data.domain.BaseDomain; + +import java.util.List; + +/** + * 系统--用户表 + * + * @author admin + * @date 2021年10月19日 15:07:06 + */ +public class SysUser extends BaseDomain { + /** 用户名 */ + private String username; + /** 密码 */ + private String password; + /** 手机 */ + private String phone; + /** 姓名 */ + private String name; + /** 邮箱 */ + private String email; + /** + * 用户标签 + * @see + * */ + private String tag; + /** 状态 */ + private Integer status; + /**是否需要二次登陆*/ + private Integer isSecondLanding; + + /******VO****/ + /** + * 验证码 + */ + private String verifyCode; + /** + * 角色信息 + */ + private List sysRoleList; + /** + * 用户菜单标识信息 + */ + private List sysResourceIdentityList; + /** + * 用户菜单列表 + */ + private List sysResourceList; + /**标签集合*/ + private List tagList; + /**二次登陆验证码*/ + private String twoVerifyCode; + + public String getTwoVerifyCode() { + return twoVerifyCode; + } + + public void setTwoVerifyCode(String twoVerifyCode) { + this.twoVerifyCode = twoVerifyCode; + } + + public Integer getIsSecondLanding() { + return isSecondLanding; + } + + public void setIsSecondLanding(Integer isSecondLanding) { + this.isSecondLanding = isSecondLanding; + } + + public List getTagList() { + return tagList; + } + + public void setTagList(List tagList) { + this.tagList = tagList; + } + + public String getVerifyCode() { + return verifyCode; + } + + public void setVerifyCode(String verifyCode) { + this.verifyCode = verifyCode; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + public List getSysRoleList() { + return sysRoleList; + } + + public void setSysRoleList(List sysRoleList) { + this.sysRoleList = sysRoleList; + } + + public List getSysResourceIdentityList() { + return sysResourceIdentityList; + } + + public void setSysResourceIdentityList(List sysResourceIdentityList) { + this.sysResourceIdentityList = sysResourceIdentityList; + } + + public List getSysResourceList() { + return sysResourceList; + } + + public void setSysResourceList(List sysResourceList) { + this.sysResourceList = sysResourceList; + } + + public String getTag() { + return tag; + } + + public void setTag(String tag) { + this.tag = tag; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/system/SysUserRole.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/system/SysUserRole.java new file mode 100644 index 0000000..55de1e3 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/system/SysUserRole.java @@ -0,0 +1,56 @@ +package com.arm.equipment.system.data.domain.system; + +import com.arm.equipment.system.data.domain.BaseDomain; + +/** + * 系统--用户角色关联表 + * + * @author admin + * @date 2021年10月19日 15:06:59 + */ +public class SysUserRole extends BaseDomain { + /** 角色ID */ + private Long sysRoleId; + /** 用户ID */ + private Long sysUserId; + /** 状态 */ + private Integer status; + /** 执行者 */ + private String operator; + + public Long getSysRoleId() { + return sysRoleId; + } + + public void setSysRoleId(Long sysRoleId) { + this.sysRoleId = sysRoleId; + } + + + public Long getSysUserId() { + return sysUserId; + } + + public void setSysUserId(Long sysUserId) { + this.sysUserId = sysUserId; + } + + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + + public String getOperator() { + return operator; + } + + public void setOperator(String operator) { + this.operator = operator; + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/user/AppUser.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/user/AppUser.java new file mode 100644 index 0000000..796f65d --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/user/AppUser.java @@ -0,0 +1,89 @@ +package com.arm.equipment.system.data.domain.user; + +import com.arm.equipment.system.data.domain.BaseDomain; + +import java.util.Date; + +/** + * APP用户 + * + * @author admin + * @date 2023年03月13日 22:34:47 + */ +public class AppUser extends BaseDomain { + /** 用户昵称 */ + private String nickname; + /** 登录账号 */ + private String username; + /** 密码 */ + private String password; + /** 手机号 */ + private String phone; + /** 数据状态 */ + private Integer status; + /** 登录时间 */ + private Date loginTime; + + private String token; + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + public String getNickname() { + return nickname; + } + + public void setNickname(String nickname) { + this.nickname = nickname; + } + + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + + public Date getLoginTime() { + return loginTime; + } + + public void setLoginTime(Date loginTime) { + this.loginTime = loginTime; + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/weaponry/Weaponry.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/weaponry/Weaponry.java new file mode 100644 index 0000000..c763cf8 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/weaponry/Weaponry.java @@ -0,0 +1,124 @@ +package com.arm.equipment.system.data.domain.weaponry; + +import com.arm.equipment.system.data.domain.BaseDomain; + +import java.util.Date; + +/** + * 装备武器 + * + * @author admin + * @date 2023年03月23日 10:29:48 + */ +public class Weaponry extends BaseDomain { + /** 武器名称 */ + private String name; + /** 武器封面 */ + private String imgPath; + /** 弹夹容量(发) */ + private Integer cartridgeCapacity; + /** 子弹口径(mm) */ + private Double bulletCaliber; + /** 有效射程 */ + private Integer effectiveRange; + /** 总库存 */ + private Integer totalInventory; + /** 锁定库存 */ + private Integer lockInventory; + /** 数据状态 */ + private Integer status; + + /**VO*/ + /**是否已借出*/ + private Integer isLend; + /**锁定数起始值*/ + private Integer lockInventoryStart; + + public Integer getLockInventoryStart() { + return lockInventoryStart; + } + + public void setLockInventoryStart(Integer lockInventoryStart) { + this.lockInventoryStart = lockInventoryStart; + } + + public Integer getIsLend() { + return isLend; + } + + public void setIsLend(Integer isLend) { + this.isLend = isLend; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + + public String getImgPath() { + return imgPath; + } + + public void setImgPath(String imgPath) { + this.imgPath = imgPath; + } + + + public Integer getCartridgeCapacity() { + return cartridgeCapacity; + } + + public void setCartridgeCapacity(Integer cartridgeCapacity) { + this.cartridgeCapacity = cartridgeCapacity; + } + + + public Double getBulletCaliber() { + return bulletCaliber; + } + + public void setBulletCaliber(Double bulletCaliber) { + this.bulletCaliber = bulletCaliber; + } + + + public Integer getEffectiveRange() { + return effectiveRange; + } + + public void setEffectiveRange(Integer effectiveRange) { + this.effectiveRange = effectiveRange; + } + + + public Integer getTotalInventory() { + return totalInventory; + } + + public void setTotalInventory(Integer totalInventory) { + this.totalInventory = totalInventory; + } + + + public Integer getLockInventory() { + return lockInventory; + } + + public void setLockInventory(Integer lockInventory) { + this.lockInventory = lockInventory; + } + + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/weaponry/WeaponryLendRecord.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/weaponry/WeaponryLendRecord.java new file mode 100644 index 0000000..e6f3686 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/weaponry/WeaponryLendRecord.java @@ -0,0 +1,92 @@ +package com.arm.equipment.system.data.domain.weaponry; + +import com.arm.equipment.system.data.domain.BaseDomain; + +import java.util.Date; + +/** + * 装备武器借出记录 + * + * @author admin + * @date 2023年03月23日 11:02:17 + */ +public class WeaponryLendRecord extends BaseDomain { + /** 武器ID */ + private Long weaponryId; + /** 武器名称 */ + private String weaponryName; + /** 借出数量 */ + private Integer num; + /** 归还时间 */ + private Date returnTime; + /** 归还状态(0未归还 1已归还) */ + private Integer returnStatus; + /** 数据状态 */ + private Integer status; + + /****************VO**************/ + private Weaponry weaponry; + + public Weaponry getWeaponry() { + return weaponry; + } + + public void setWeaponry(Weaponry weaponry) { + this.weaponry = weaponry; + } + + + public Long getWeaponryId() { + return weaponryId; + } + + public void setWeaponryId(Long weaponryId) { + this.weaponryId = weaponryId; + } + + + public String getWeaponryName() { + return weaponryName; + } + + public void setWeaponryName(String weaponryName) { + this.weaponryName = weaponryName; + } + + + public Integer getNum() { + return num; + } + + public void setNum(Integer num) { + this.num = num; + } + + + public Date getReturnTime() { + return returnTime; + } + + public void setReturnTime(Date returnTime) { + this.returnTime = returnTime; + } + + + public Integer getReturnStatus() { + return returnStatus; + } + + public void setReturnStatus(Integer returnStatus) { + this.returnStatus = returnStatus; + } + + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/weaponry/WeaponryReturnRecord.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/weaponry/WeaponryReturnRecord.java new file mode 100644 index 0000000..836ee51 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/domain/weaponry/WeaponryReturnRecord.java @@ -0,0 +1,91 @@ +package com.arm.equipment.system.data.domain.weaponry; + +import com.arm.equipment.system.data.domain.BaseDomain; + +import java.util.Date; + +/** + * 装备武器归还记录 + * + * @author admin + * @date 2023年03月23日 11:03:25 + */ +public class WeaponryReturnRecord extends BaseDomain { + /** 武器ID */ + private Long weaponryId; + /** 武器名称 */ + private String weaponryName; + /** 记录ID */ + private Long lendRecordId; + /** 借出数量 */ + private Integer num; + /** 归还时间 */ + private Date returnTime; + /** 数据状态 */ + private Integer status; + + /****************VO**************/ + private Weaponry weaponry; + + public Weaponry getWeaponry() { + return weaponry; + } + + public void setWeaponry(Weaponry weaponry) { + this.weaponry = weaponry; + } + + public Long getWeaponryId() { + return weaponryId; + } + + public void setWeaponryId(Long weaponryId) { + this.weaponryId = weaponryId; + } + + + public String getWeaponryName() { + return weaponryName; + } + + public void setWeaponryName(String weaponryName) { + this.weaponryName = weaponryName; + } + + + public Long getLendRecordId() { + return lendRecordId; + } + + public void setLendRecordId(Long lendRecordId) { + this.lendRecordId = lendRecordId; + } + + + public Integer getNum() { + return num; + } + + public void setNum(Integer num) { + this.num = num; + } + + + public Date getReturnTime() { + return returnTime; + } + + public void setReturnTime(Date returnTime) { + this.returnTime = returnTime; + } + + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumFileResourceType.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumFileResourceType.java new file mode 100644 index 0000000..275323a --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumFileResourceType.java @@ -0,0 +1,37 @@ +package com.arm.equipment.system.data.enums.dict; + +/*** + * + * 资源文件类型 + * @author: admin + * @time: 2021/11/17 17:35 + */ +public enum EnumFileResourceType { + /** */ + IMG(1, "图片"), + VIDEO(2, "视频"), + ; + + private Integer code; + private String text; + + EnumFileResourceType(Integer code, String text) { + this.code = code; + this.text = text; + } + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + }} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumGender.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumGender.java new file mode 100644 index 0000000..0e7570b --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumGender.java @@ -0,0 +1,51 @@ +package com.arm.equipment.system.data.enums.dict; + +import com.arm.equipment.system.data.exception.BusinessException; + +/** + * 数据状态枚举 + * @author admin + */ +public enum EnumGender { + /** 审核 */ + MALE(1, "男"), + + /** The release. */ + FEMALE(2, "女"), + ; + + private Integer code; + private String text; + + EnumGender(Integer code, String text) { + this.code = code; + this.text = text; + } + + public static EnumGender getByCode(Integer code) { + if (null == code) { + return null; + } + for (EnumGender type : EnumGender.values()) { + if (type.getCode().equals(code)) { + return type; + } + } + throw new BusinessException("内容类型非法"); + } + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + }} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumSortType.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumSortType.java new file mode 100644 index 0000000..9be4db9 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumSortType.java @@ -0,0 +1,51 @@ +package com.arm.equipment.system.data.enums.dict; + +/** + * 排序类型 + * + * @author: xly + * @time: 2022/9/16 18:30 + */ +public enum EnumSortType { + ASC(1, "升序"), + DESC(2, "降序"), + ; + + private Integer code; + private String text; + + EnumSortType(Integer code, String text) { + this.code = code; + this.text = text; + } + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + + public static EnumSortType getByCode(Integer code) { + if (code == null) { + return null; + } + EnumSortType[] values = EnumSortType.values(); + for (EnumSortType v : values) { + if (v.getCode().equals(code)) { + return v; + } + } + return null; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumStatus.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumStatus.java new file mode 100644 index 0000000..908b4fe --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumStatus.java @@ -0,0 +1,56 @@ +package com.arm.equipment.system.data.enums.dict; + +/** + * 数据状态枚举 + * + * @author admin + */ +public enum EnumStatus { + /** + * The new. + */ + NEW(0, "新增"), + + AUDIT(1, "已审核"), + + DEL(-9, "已删除"); + + private Integer code; + private String text; + EnumStatus(Integer code, String text) { + this.code = code; + this.text = text; + } + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + /** + * 通过code获得该枚举类型 + * + * @param code + * @return + */ + public static EnumStatus getByCode(Integer code) { + EnumStatus[] values = EnumStatus.values(); + for (EnumStatus type : values) { + if (type.code.equals(code)) { + return type; + } + } + return NEW; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumSysLogType.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumSysLogType.java new file mode 100644 index 0000000..b0d5028 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumSysLogType.java @@ -0,0 +1,56 @@ +package com.arm.equipment.system.data.enums.dict; + +/** + * 数据状态枚举 + * + * @author admin + */ +public enum EnumSysLogType { + /** + * The new. + */ + LOG(1, "普通日志"), + + EXCEPTION_LOG(2, "异常日志"), + ; + + private Integer code; + private String text; + + EnumSysLogType(Integer code, String text) { + this.code = code; + this.text = text; + } + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + /** + * 通过code获得该枚举类型 + * + * @param code + * @return + */ + public static EnumSysLogType getByCode(Integer code) { + EnumSysLogType[] values = EnumSysLogType.values(); + for (EnumSysLogType type : values) { + if (type.code.equals(code)) { + return type; + } + } + return null; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumSysResourceType.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumSysResourceType.java new file mode 100644 index 0000000..34163d6 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumSysResourceType.java @@ -0,0 +1,41 @@ +package com.arm.equipment.system.data.enums.dict; + +/** + * 系统资源菜单类型 + * + * @author: admin + * @time: 2021/10/19 18:02 + */ +public enum EnumSysResourceType { + /** + * + */ + CATALOGUE(0, "目录"), + MENU(1, "菜单"), + BUTTON(2, "按钮"), + ; + + private Integer code; + private String text; + + EnumSysResourceType(Integer code, String text) { + this.code = code; + this.text = text; + } + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumWeaponryLendRecordReturnStatus.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumWeaponryLendRecordReturnStatus.java new file mode 100644 index 0000000..27b650b --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumWeaponryLendRecordReturnStatus.java @@ -0,0 +1,50 @@ +package com.arm.equipment.system.data.enums.dict; + +/** + * @author: xly + * @time: 2023/3/23 9:02 + */ +public enum EnumWeaponryLendRecordReturnStatus { + NOT_RETURN(0, "未归还"), + RETURN(1, "已经归还"), + ; + private Integer code; + private String text; + + EnumWeaponryLendRecordReturnStatus(Integer code, String text) { + this.code = code; + this.text = text; + } + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + /** + * 通过code获得该枚举类型 + * + * @param code + * @return + */ + public static EnumSysLogType getByCode(Integer code) { + EnumSysLogType[] values = EnumSysLogType.values(); + for (EnumSysLogType type : values) { + if (type.getCode().equals(code)) { + return type; + } + } + return null; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumWeaponryLendRecordStatus.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumWeaponryLendRecordStatus.java new file mode 100644 index 0000000..1155c62 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumWeaponryLendRecordStatus.java @@ -0,0 +1,51 @@ +package com.arm.equipment.system.data.enums.dict; + +/** + * @author: xly + * @time: 2023/3/23 9:02 + */ +public enum EnumWeaponryLendRecordStatus { + NEW(0, "新增"), + ADOPT(1, "通过"), + REFUSE(2, "拒绝"), + ; + private Integer code; + private String text; + + EnumWeaponryLendRecordStatus(Integer code, String text) { + this.code = code; + this.text = text; + } + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + /** + * 通过code获得该枚举类型 + * + * @param code + * @return + */ + public static EnumSysLogType getByCode(Integer code) { + EnumSysLogType[] values = EnumSysLogType.values(); + for (EnumSysLogType type : values) { + if (type.getCode().equals(code)) { + return type; + } + } + return null; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumYesNo.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumYesNo.java new file mode 100644 index 0000000..aed2617 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/dict/EnumYesNo.java @@ -0,0 +1,36 @@ +package com.arm.equipment.system.data.enums.dict; + +/** + * yes no枚举 + * @author admin + */ +public enum EnumYesNo { + /** */ + NO(0, "否"), + + YES(1, "是") + ; + + private Integer code; + private String text; + + EnumYesNo(Integer code, String text) { + this.code = code; + this.text = text; + } + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + }} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/file/EnumUpload.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/file/EnumUpload.java new file mode 100644 index 0000000..adf03f4 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/enums/file/EnumUpload.java @@ -0,0 +1,73 @@ +package com.arm.equipment.system.data.enums.file; + +import org.apache.commons.lang3.StringUtils; + +/** + * 上传枚举,写名每个上传的作用 + * 1.规定文件夹 + * 2.规定后缀,避免任意文件上传 + * + * @author admin + */ +public enum EnumUpload { + RES_PHOTO_LIB("resPhotoLib", "jpg", "上传图片"), + RES_VIDEO_LIB("resVideoLib", "mp4", "上传视频"), + QR_CODE("qrCode", "jpg", "二维码"), + ; + + EnumUpload(String baseDir, String suffix, String desc) { + this.baseDir = baseDir; + this.suffix = suffix; + this.desc = desc; + } + + /** + * 上传具体业务目录,只允许为英文数字,不允许重复 + * 业务名称,请参考业务表名称也定义 + */ + String baseDir; + /** + * 文件类型,比如jpg,png,txt,apk等等 + */ + String suffix; + /** + * 功能描述说明 + */ + String desc; + + public static EnumUpload getEnum(String baseDir) { + if (StringUtils.isEmpty(baseDir)) { + return null; + } + for (EnumUpload type : EnumUpload.values()) { + if (type.getBaseDir().equals(baseDir)) { + return type; + } + } + return null; + } + + public String getBaseDir() { + return baseDir; + } + + public void setBaseDir(String baseDir) { + this.baseDir = baseDir; + } + + public String getSuffix() { + return suffix; + } + + public void setSuffix(String suffix) { + this.suffix = suffix; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/exception/AuthException.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/exception/AuthException.java new file mode 100644 index 0000000..fd5141f --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/exception/AuthException.java @@ -0,0 +1,62 @@ +package com.arm.equipment.system.data.exception; + +import com.arm.equipment.system.data.vo.ReturnCode; + +/** + * @author 向帅 用户登录异常 + * @Date 2019/7/27 17:11 + **/ +public class AuthException extends RuntimeException { + + private static final long serialVersionUID = -7429924842303522242L; + + String message; + + ReturnCode returnCode; + + public AuthException() { + super(); + } + + public AuthException(String message) { + this.message = message; + } + + public AuthException(ReturnCode returnCode) { + this.returnCode = returnCode; + } + + public AuthException(String message, ReturnCode returnCode) { + this.message = message; + this.returnCode = returnCode; + } + + public AuthException(String message, Throwable cause) { + super(message, cause); + } + + public AuthException(Throwable cause) { + super(cause); + } + + protected AuthException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } + + @Override + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public ReturnCode getReturnCode() { + return returnCode; + } + + public void setReturnCode(ReturnCode returnCode) { + this.returnCode = returnCode; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/exception/BusinessException.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/exception/BusinessException.java new file mode 100644 index 0000000..9943531 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/exception/BusinessException.java @@ -0,0 +1,48 @@ +package com.arm.equipment.system.data.exception; + +/** + * 自定义异常,service中业务异常使用这个 + */ +public class BusinessException extends RuntimeException { + + + private static final long serialVersionUID = -6053475656376646723L; + + Integer errorCode; + + String message; + + public BusinessException(String message) { + this.message = message; + } + + public BusinessException(Integer errorCode, String message) { + this.errorCode = errorCode; + this.message = message; + } + + public BusinessException(Throwable cause) { + super(cause); + } + + public BusinessException(String message, Throwable cause) { + super(message, cause); + } + + public Integer getErrorCode() { + return errorCode; + } + + public void setErrorCode(Integer errorCode) { + this.errorCode = errorCode; + } + + @Override + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/system/ISysBaseParamMapper.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/system/ISysBaseParamMapper.java new file mode 100644 index 0000000..749c3ce --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/system/ISysBaseParamMapper.java @@ -0,0 +1,71 @@ +package com.arm.equipment.system.data.mapper.system; + +import com.arm.equipment.system.data.domain.system.SysBaseParam; + +import java.util.List; + +/** + * 系统--基础参数 + * + * @author Administrator + * @date 2021年10月26日 16:36:52 + */ +public interface ISysBaseParamMapper { + + /** + * 插入 + * + * @param sysBaseParam sysBaseParam + * @return int + */ + int insertSelective(SysBaseParam sysBaseParam); + + /** + * 更新 + * + * @param setParam setParam + * @param whereParam whereParam + * @return int + */ + int updateSelective(SysBaseParam setParam, SysBaseParam whereParam); + + /** + * 数量 + * + * @param sysBaseParam sysBaseParam + * @return int + */ + int getCount(SysBaseParam sysBaseParam); + + /** + * 单条 + * + * @param sysBaseParam sysBaseParam + * @return SysBaseParam + */ + SysBaseParam getOne(SysBaseParam sysBaseParam); + + /** + * 多条 + * + * @param sysBaseParam sysBaseParam + * @return List + */ + List getList(SysBaseParam sysBaseParam); + + /** + * 分页 + * + * @param sysBaseParam sysBaseParam + * @return List + */ + List getPageList(SysBaseParam sysBaseParam); + + /** + * 根据ID删除 + * + * @param id + * @return + */ + int delete(String id); +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/system/ISysLogMapper.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/system/ISysLogMapper.java new file mode 100644 index 0000000..21f3b48 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/system/ISysLogMapper.java @@ -0,0 +1,64 @@ +package com.arm.equipment.system.data.mapper.system; + +import com.arm.equipment.system.data.domain.system.SysLog; + +import java.util.List; + +/** + * 日志表 + * + * @author admin + * @date 2022年09月16日 12:41:35 + */ +public interface ISysLogMapper { + + /** + * 插入 + * + * @param sysLog sysLog + * @return int + */ + int insertSelective(SysLog sysLog); + + /** + * 更新 + * + * @param setParam setParam + * @param whereParam whereParam + * @return int + */ + int updateSelective(SysLog setParam, SysLog whereParam); + + /** + * 数量 + * + * @param sysLog sysLog + * @return int + */ + int getCount(SysLog sysLog); + + /** + * 单条 + * + * @param sysLog sysLog + * @return SysLog + */ + SysLog getOne(SysLog sysLog); + + /** + * 多条 + * + * @param sysLog sysLog + * @return List + */ + List getList(SysLog sysLog); + + /** + * 分页 + * + * @param sysLog sysLog + * @return List + */ + List getPageList(SysLog sysLog); + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/system/ISysResourceMapper.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/system/ISysResourceMapper.java new file mode 100644 index 0000000..e7d9cee --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/system/ISysResourceMapper.java @@ -0,0 +1,63 @@ +package com.arm.equipment.system.data.mapper.system; + +import com.arm.equipment.system.data.domain.system.SysResource; + +import java.util.List; + +/** + * 系统--权限表 + * + * @author admin + * @date 2021年10月19日 15:06:30 + */ +public interface ISysResourceMapper { + + /** + * 插入 + * + * @param sysResource sysResource + * @return int + */ + int insertSelective(SysResource sysResource); + + /** + * 更新 + * + * @param setParam setParam + * @param whereParam whereParam + * @return int + */ + int updateSelective(SysResource setParam, SysResource whereParam); + + /** + * 数量 + * + * @param sysResource sysResource + * @return int + */ + int getCount(SysResource sysResource); + + /** + * 单条 + * + * @param sysResource sysResource + * @return SysResource + */ + SysResource getOne(SysResource sysResource); + + /** + * 多条 + * + * @param sysResource sysResource + * @return List + */ + List getList(SysResource sysResource); + + /** + * 分页 + * + * @param sysResource sysResource + * @return List + */ + List getPageList(SysResource sysResource); +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/system/ISysRoleMapper.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/system/ISysRoleMapper.java new file mode 100644 index 0000000..b369299 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/system/ISysRoleMapper.java @@ -0,0 +1,64 @@ +package com.arm.equipment.system.data.mapper.system; + +import com.arm.equipment.system.data.domain.system.SysRole; + +import java.util.List; + +/** + * 系统--角色表 + * + * @author admin + * @date 2021年10月19日 15:06:47 + */ +public interface ISysRoleMapper { + + /** + * 插入 + * + * @param sysRole sysRole + * @return int + */ + int insertSelective(SysRole sysRole); + + /** + * 更新 + * + * @param setParam setParam + * @param whereParam whereParam + * @return int + */ + int updateSelective(SysRole setParam, SysRole whereParam); + + /** + * 数量 + * + * @param sysRole sysRole + * @return int + */ + int getCount(SysRole sysRole); + + /** + * 单条 + * + * @param sysRole sysRole + * @return SysRole + */ + SysRole getOne(SysRole sysRole); + + /** + * 多条 + * + * @param sysRole sysRole + * @return List + */ + List getList(SysRole sysRole); + + /** + * 分页 + * + * @param sysRole sysRole + * @return List + */ + List getPageList(SysRole sysRole); + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/system/ISysRoleResourceMapper.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/system/ISysRoleResourceMapper.java new file mode 100644 index 0000000..815cc67 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/system/ISysRoleResourceMapper.java @@ -0,0 +1,82 @@ +package com.arm.equipment.system.data.mapper.system; + +import com.arm.equipment.system.data.domain.system.SysRoleResource; + +import java.util.List; + +/** + * 系统-角色权限关联表 + * + * @author admin + * @date 2021年10月19日 15:06:41 + */ +public interface ISysRoleResourceMapper { + + /** + * 插入 + * + * @param sysRoleResource sysRoleResource + * @return int + */ + int insertSelective(SysRoleResource sysRoleResource); + + /** + * 更新 + * + * @param setParam setParam + * @param whereParam whereParam + * @return int + */ + int updateSelective(SysRoleResource setParam, SysRoleResource whereParam); + + /** + * 数量 + * + * @param sysRoleResource sysRoleResource + * @return int + */ + int getCount(SysRoleResource sysRoleResource); + + /** + * 单条 + * + * @param sysRoleResource sysRoleResource + * @return SysRoleResource + */ + SysRoleResource getOne(SysRoleResource sysRoleResource); + + /** + * 多条 + * + * @param sysRoleResource sysRoleResource + * @return List + */ + List getList(SysRoleResource sysRoleResource); + + /** + * 分页 + * + * @param sysRoleResource sysRoleResource + * @return List + */ + List getPageList(SysRoleResource sysRoleResource); + + /** + * 获取权限ID in数据 + * @param sysUserRoleIdList + * @return + */ + List getListBySysRoleIdIn(List sysUserRoleIdList); + + /** + * 根据权限ID删除 + * @param roleId + */ + void deleteByRoleId(Long roleId); + + /** + * 批量添加 + * @param list + */ + void batchInsert(List list); +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/system/ISysUserMapper.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/system/ISysUserMapper.java new file mode 100644 index 0000000..60e9db1 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/system/ISysUserMapper.java @@ -0,0 +1,64 @@ +package com.arm.equipment.system.data.mapper.system; + +import com.arm.equipment.system.data.domain.system.SysUser; + +import java.util.List; + +/** + * 系统--用户表 + * + * @author admin + * @date 2021年10月19日 15:07:06 + */ +public interface ISysUserMapper { + + /** + * 插入 + * + * @param sysUser sysUser + * @return int + */ + int insertSelective(SysUser sysUser); + + /** + * 更新 + * + * @param setParam setParam + * @param whereParam whereParam + * @return int + */ + int updateSelective(SysUser setParam, SysUser whereParam); + + /** + * 数量 + * + * @param sysUser sysUser + * @return int + */ + int getCount(SysUser sysUser); + + /** + * 单条 + * + * @param sysUser sysUser + * @return SysUser + */ + SysUser getOne(SysUser sysUser); + + /** + * 多条 + * + * @param sysUser sysUser + * @return List + */ + List getList(SysUser sysUser); + + /** + * 分页 + * + * @param sysUser sysUser + * @return List + */ + List getPageList(SysUser sysUser); + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/system/ISysUserRoleMapper.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/system/ISysUserRoleMapper.java new file mode 100644 index 0000000..03165f1 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/system/ISysUserRoleMapper.java @@ -0,0 +1,80 @@ +package com.arm.equipment.system.data.mapper.system; + +import com.arm.equipment.system.data.domain.system.SysUserRole; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 系统--用户角色关联表 + * + * @author admin + * @date 2021年10月19日 15:06:59 + */ +public interface ISysUserRoleMapper { + + /** + * 插入 + * + * @param sysUserRole sysUserRole + * @return int + */ + int insertSelective(SysUserRole sysUserRole); + + /** + * 更新 + * + * @param setParam setParam + * @param whereParam whereParam + * @return int + */ + int updateSelective(SysUserRole setParam, SysUserRole whereParam); + + /** + * 数量 + * + * @param sysUserRole sysUserRole + * @return int + */ + int getCount(SysUserRole sysUserRole); + + /** + * 单条 + * + * @param sysUserRole sysUserRole + * @return SysUserRole + */ + SysUserRole getOne(SysUserRole sysUserRole); + + /** + * 多条 + * + * @param sysUserRole sysUserRole + * @return List + */ + List getList(SysUserRole sysUserRole); + + /** + * 分页 + * + * @param sysUserRole sysUserRole + * @return List + */ + List getPageList(SysUserRole sysUserRole); + + /** + * 根据用户ID删除用户角色 + * + * @param userId + */ + void deleteByUserId(Long userId); + + /** + * 为用户批量添加角色 + * + * @param newRole + * @param userId + * @param operator + */ + void insertByRoleIdIn(@Param("newRole") List newRole, @Param("userId") Long userId, @Param("operator") String operator); +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/user/IAppUserMapper.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/user/IAppUserMapper.java new file mode 100644 index 0000000..908b1d3 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/user/IAppUserMapper.java @@ -0,0 +1,64 @@ +package com.arm.equipment.system.data.mapper.user; + +import com.arm.equipment.system.data.domain.user.AppUser; + +import java.util.List; + +/** + * APP用户 + * + * @author admin + * @date 2023年03月13日 22:34:47 + */ +public interface IAppUserMapper { + + /** + * 插入 + * + * @param appUser appUser + * @return int + */ + int insertSelective(AppUser appUser); + + /** + * 更新 + * + * @param setParam setParam + * @param whereParam whereParam + * @return int + */ + int updateSelective(AppUser setParam, AppUser whereParam); + + /** + * 数量 + * + * @param appUser appUser + * @return int + */ + int getCount(AppUser appUser); + + /** + * 单条 + * + * @param appUser appUser + * @return AppUser + */ + AppUser getOne(AppUser appUser); + + /** + * 多条 + * + * @param appUser appUser + * @return List + */ + List getList(AppUser appUser); + + /** + * 分页 + * + * @param appUser appUser + * @return List + */ + List getPageList(AppUser appUser); + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/weaponry/IWeaponryLendRecordMapper.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/weaponry/IWeaponryLendRecordMapper.java new file mode 100644 index 0000000..9ff8c04 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/weaponry/IWeaponryLendRecordMapper.java @@ -0,0 +1,64 @@ +package com.arm.equipment.system.data.mapper.weaponry; + +import com.arm.equipment.system.data.domain.weaponry.WeaponryLendRecord; + +import java.util.List; + +/** + * 装备武器借出记录 + * + * @author admin + * @date 2023年03月23日 11:02:17 + */ +public interface IWeaponryLendRecordMapper { + + /** + * 插入 + * + * @param weaponryLendRecord weaponryLendRecord + * @return int + */ + int insertSelective(WeaponryLendRecord weaponryLendRecord); + + /** + * 更新 + * + * @param setParam setParam + * @param whereParam whereParam + * @return int + */ + int updateSelective(WeaponryLendRecord setParam, WeaponryLendRecord whereParam); + + /** + * 数量 + * + * @param weaponryLendRecord weaponryLendRecord + * @return int + */ + int getCount(WeaponryLendRecord weaponryLendRecord); + + /** + * 单条 + * + * @param weaponryLendRecord weaponryLendRecord + * @return WeaponryLendRecord + */ + WeaponryLendRecord getOne(WeaponryLendRecord weaponryLendRecord); + + /** + * 多条 + * + * @param weaponryLendRecord weaponryLendRecord + * @return List + */ + List getList(WeaponryLendRecord weaponryLendRecord); + + /** + * 分页 + * + * @param weaponryLendRecord weaponryLendRecord + * @return List + */ + List getPageList(WeaponryLendRecord weaponryLendRecord); + +} \ No newline at end of file diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/weaponry/IWeaponryMapper.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/weaponry/IWeaponryMapper.java new file mode 100644 index 0000000..d38b48d --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/weaponry/IWeaponryMapper.java @@ -0,0 +1,64 @@ +package com.arm.equipment.system.data.mapper.weaponry; + +import com.arm.equipment.system.data.domain.weaponry.Weaponry; + +import java.util.List; + +/** + * 装备武器 + * + * @author admin + * @date 2023年03月23日 10:29:48 + */ +public interface IWeaponryMapper { + + /** + * 插入 + * + * @param weaponry weaponry + * @return int + */ + int insertSelective(Weaponry weaponry); + + /** + * 更新 + * + * @param setParam setParam + * @param whereParam whereParam + * @return int + */ + int updateSelective(Weaponry setParam, Weaponry whereParam); + + /** + * 数量 + * + * @param weaponry weaponry + * @return int + */ + int getCount(Weaponry weaponry); + + /** + * 单条 + * + * @param weaponry weaponry + * @return Weaponry + */ + Weaponry getOne(Weaponry weaponry); + + /** + * 多条 + * + * @param weaponry weaponry + * @return List + */ + List getList(Weaponry weaponry); + + /** + * 分页 + * + * @param weaponry weaponry + * @return List + */ + List getPageList(Weaponry weaponry); + +} \ No newline at end of file diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/weaponry/IWeaponryReturnRecordMapper.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/weaponry/IWeaponryReturnRecordMapper.java new file mode 100644 index 0000000..be80762 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mapper/weaponry/IWeaponryReturnRecordMapper.java @@ -0,0 +1,64 @@ +package com.arm.equipment.system.data.mapper.weaponry; + +import com.arm.equipment.system.data.domain.weaponry.WeaponryReturnRecord; + +import java.util.List; + +/** + * 装备武器归还记录 + * + * @author admin + * @date 2023年03月23日 11:03:25 + */ +public interface IWeaponryReturnRecordMapper { + + /** + * 插入 + * + * @param weaponryReturnRecord weaponryReturnRecord + * @return int + */ + int insertSelective(WeaponryReturnRecord weaponryReturnRecord); + + /** + * 更新 + * + * @param setParam setParam + * @param whereParam whereParam + * @return int + */ + int updateSelective(WeaponryReturnRecord setParam, WeaponryReturnRecord whereParam); + + /** + * 数量 + * + * @param weaponryReturnRecord weaponryReturnRecord + * @return int + */ + int getCount(WeaponryReturnRecord weaponryReturnRecord); + + /** + * 单条 + * + * @param weaponryReturnRecord weaponryReturnRecord + * @return WeaponryReturnRecord + */ + WeaponryReturnRecord getOne(WeaponryReturnRecord weaponryReturnRecord); + + /** + * 多条 + * + * @param weaponryReturnRecord weaponryReturnRecord + * @return List + */ + List getList(WeaponryReturnRecord weaponryReturnRecord); + + /** + * 分页 + * + * @param weaponryReturnRecord weaponryReturnRecord + * @return List + */ + List getPageList(WeaponryReturnRecord weaponryReturnRecord); + +} \ No newline at end of file diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mybatis/type/CustomLocalTimeTypeHandler.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mybatis/type/CustomLocalTimeTypeHandler.java new file mode 100644 index 0000000..1146d89 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/mybatis/type/CustomLocalTimeTypeHandler.java @@ -0,0 +1,62 @@ +package com.arm.equipment.system.data.mybatis.type; + +import org.apache.commons.lang3.StringUtils; +import org.apache.ibatis.lang.UsesJava8; +import org.apache.ibatis.type.JdbcType; +import org.apache.ibatis.type.LocalTimeTypeHandler; + +import java.sql.*; +import java.time.LocalTime; + +/** + * 继承了LocalTimeTypeHandler这个类, 重写了对localtime的处理 + * 主要是针对0点返回null的问题 + * @author + */ +@UsesJava8 +public class CustomLocalTimeTypeHandler extends LocalTimeTypeHandler { + + @Override + public void setNonNullParameter(PreparedStatement ps, int i, LocalTime parameter, JdbcType jdbcType) + throws SQLException { + ps.setTime(i, Time.valueOf(parameter)); + } + + @Override + public LocalTime getNullableResult(ResultSet rs, String columnName) throws SQLException { + String stringTime = rs.getString(columnName); + return getLocalTime(stringTime); + } + + @Override + public LocalTime getNullableResult(ResultSet rs, int columnIndex) throws SQLException { + String stringTime = rs.getString(columnIndex); + return getLocalTime(stringTime); + } + + @Override + public LocalTime getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { + String stringTime = cs.getString(columnIndex); + return getLocalTime(stringTime); + } + + /** + * 从字符串中解析时间 + * 取出每一位设置为localtime的时,分,秒,毫秒 + * @param stringTime 时间字符串 + * @return + */ + private LocalTime getLocalTime(String stringTime) { + if (StringUtils.isEmpty(stringTime)) { + return null; + } + String[] timeSplit = stringTime.split(":"); + if (stringTime.contains(".")) { + String[] secondSplit = timeSplit[2].split("\\."); + String nano = secondSplit[1].replaceAll("[0]+$", ""); + return LocalTime.of(Integer.parseInt(timeSplit[0]), Integer.parseInt(timeSplit[1]), Integer.parseInt(secondSplit[0]), Integer.parseInt(nano)); + } else { + return LocalTime.of(Integer.parseInt(timeSplit[0]), Integer.parseInt(timeSplit[1]), Integer.parseInt(timeSplit[2])); + } + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/common/IDictService.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/common/IDictService.java new file mode 100644 index 0000000..9f70eab --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/common/IDictService.java @@ -0,0 +1,20 @@ +package com.arm.equipment.system.data.service.common; + +import com.arm.equipment.system.data.vo.dict.DictVO; + +import java.util.List; + +/** + * 字典业务类 + * + * @author admin + */ +public interface IDictService { + /** + * 获取字典数据 + * + * @param name 字典名称 + * @return 字典数据 + */ + List getDictData(String name); +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/common/IIdWorkerService.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/common/IIdWorkerService.java new file mode 100644 index 0000000..2c2589d --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/common/IIdWorkerService.java @@ -0,0 +1,15 @@ +package com.arm.equipment.system.data.service.common; + +/** + * id生成器 + */ +public interface IIdWorkerService { + + /** + * 获取id(趋势为自增) + * long最大值9223372036854775807 + * + * @return + */ + long getNextId(); +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/common/IVerifyCodeService.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/common/IVerifyCodeService.java new file mode 100644 index 0000000..2e255d3 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/common/IVerifyCodeService.java @@ -0,0 +1,36 @@ +package com.arm.equipment.system.data.service.common; + +import com.arm.equipment.system.data.vo.system.VerifyCodeVO; + +import java.io.IOException; +import java.io.OutputStream; + +/** + * 后台管理验证码生成 + * + * @author Ousei + * @date 2020年7月17日15:27:07 + */ +public interface IVerifyCodeService { + /** + * 生成验证码并返回code,将图片写到os中 + * + * @param width + * @param height + * @param os + * @return + * @throws IOException + */ + String generate(int width, int height, OutputStream os) throws IOException; + + /** + * 生成验证码对象 + * + * @param width + * @param height + * @return + * @throws IOException + */ + VerifyCodeVO generate(int width, int height) throws IOException; +} + diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/common/impl/DictServiceImpl.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/common/impl/DictServiceImpl.java new file mode 100644 index 0000000..417e231 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/common/impl/DictServiceImpl.java @@ -0,0 +1,65 @@ +package com.arm.equipment.system.data.service.common.impl; + + +import com.arm.equipment.system.data.exception.BusinessException; +import com.arm.equipment.system.data.service.common.IDictService; +import com.arm.equipment.system.data.vo.dict.DictVO; +import org.springframework.stereotype.Service; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +/** + * 字典业务类 + * + * @author admin + */ +@Service +public class DictServiceImpl implements IDictService { + /** + * 所有的新枚举都在这个包下 + */ + String DICT_BASE_PACKAGE = "com.arm.equipment.system.data.enums.dict"; + + + @Override + public List getDictData(String name) { + return getEnumDict(name); + } + + /** + * 通过枚举名称获得枚举数据 + * + * @param name 枚举名称, 注意枚举必须放在DICT_BASE_PACKAGE下面 + * @return + */ + private List getEnumDict(String name) { + String className = DICT_BASE_PACKAGE + "." + name; + Method method; + try { + method = Class.forName(className).getMethod("values"); + } catch (NoSuchMethodException e) { + throw new BusinessException("枚举类反射异常:不存在的方法!method=values"); + } catch (ClassNotFoundException e) { + throw new BusinessException(String.format("枚举类反射异常:不存在的枚举类!className=%s", className)); + } + try { + Object invoke = method.invoke(null); + Object[] list = (Object[]) invoke; + List voList = new ArrayList<>(); + for (Object o : list) { + Object enumCode = o.getClass().getMethod("getCode").invoke(o); + String enumText = o.getClass().getMethod("getText").invoke(o).toString(); + DictVO vo = new DictVO(enumCode.toString(), enumText); + voList.add(vo); + } + return voList; + } catch (IllegalAccessException | InvocationTargetException e) { + throw new BusinessException(String.format("枚举类反射异常:方法[%s]执行失败!", method.getName())); + } catch (NoSuchMethodException e) { + throw new BusinessException(String.format("枚举类反射异常:方法[%s]不存在!", method.getName())); + } + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/common/impl/IdWorkerServiceImpl.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/common/impl/IdWorkerServiceImpl.java new file mode 100644 index 0000000..b43d216 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/common/impl/IdWorkerServiceImpl.java @@ -0,0 +1,159 @@ +package com.arm.equipment.system.data.service.common.impl; + +import com.arm.equipment.system.data.service.common.IIdWorkerService; +import com.arm.equipment.system.data.constant.RedisKeys; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; + + +/** + * Twitter_Snowflake
+ * SnowFlake的结构如下(每部分用-分开):
+ * 0 - 0000000000 0000000000 0000000000 0000000000 0 - 00000 - 00000 - 000000000000
+ * 1位标识,由于long基本类型在Java中是带符号的,最高位是符号位,正数是0,负数是1,所以id一般是正数,最高位是0
+ * 41位时间截(毫秒级),注意,41位时间截不是存储当前时间的时间截,而是存储时间截的差值(当前时间截 - 开始时间截) + * 得到的值),这里的的开始时间截,一般是我们的id生成器开始使用的时间,由我们程序来指定的(如下下面程序IdWorker类的startTime属性)。41位的时间截,可以使用69年,年T = (1L << 41) / (1000L * 60 * 60 * 24 * 365) = 69
+ * 10位的数据机器位,可以部署在1024个节点,包括5位datacenterId和5位workerId
+ * 12位序列,毫秒内的计数,12位的计数顺序号支持每个节点每毫秒(同一机器,同一时间截)产生4096个ID序号
+ * 加起来刚好64位,为一个Long型。
+ * SnowFlake的优点是,整体上按照时间自增排序,并且整个分布式系统内不会产生ID碰撞(由数据中心ID和机器ID作区分),并且效率较高,经测试,SnowFlake每秒能够产生26万ID左右。 + */ +@Service +public class IdWorkerServiceImpl implements IIdWorkerService { + private final static Logger logger = LoggerFactory.getLogger(IdWorkerServiceImpl.class); + @Autowired + private RedisTemplate redisTemplate; + + /** + * 开始时间截 (Thu Mar 05 2020 11:57:29 GMT+0800) + */ + private final long twepoch = 1583380649557L; + /** + * 机器id所占的位数 + */ + private final static long WORKER_ID_BITS = 5L; + /** + * 数据标识id所占的位数 + */ + private final long datacenterIdBits = 5L; + /** + * 支持的最大机器id,结果是31 (这个移位算法可以很快的计算出几位二进制数所能表示的最大十进制数) + */ + private final static long MAX_WORKER_ID = -1L ^ (-1L << WORKER_ID_BITS); + /** + * 支持的最大数据标识id,结果是31 + */ + private final long maxDatacenterId = -1L ^ (-1L << datacenterIdBits); + /** + * 序列在id中占的位数 + */ + private final long sequenceBits = 12L; + /** + * 机器ID向左移12位 + */ + private final long workerIdShift = sequenceBits; + /** + * 数据标识id向左移17位(12+5) + */ + private final long datacenterIdShift = sequenceBits + WORKER_ID_BITS; + /** + * 时间截向左移22位(5+5+12) + */ + private final long timestampLeftShift = sequenceBits + WORKER_ID_BITS + datacenterIdBits; + /** + * 生成序列的掩码,这里为4095 (0b111111111111=0xfff=4095) + */ + private final long sequenceMask = -1L ^ (-1L << sequenceBits); + /** + * 工作机器ID(0~31) + */ + private Long workerId = (long) (Math.random() * 32); + /** + * 数据中心ID(0~31) + */ + private static long datacenterId = 0; + /** + * 毫秒内序列(0~4095) + */ + private long sequence = 0L; + /** + * 上次生成ID的时间截 + */ + private long lastTimestamp = -1L; + + /** + * 初始化worker id + * 1.从redis中自增 + * 2.自增值对32求余(拿到0~31) + */ + @PostConstruct + public void init() { + Long increment = redisTemplate.opsForValue().increment(RedisKeys.SNOW_FLAKE_WORKER_ID); + workerId = increment % 32; + logger.info("当前机器 workerId: {}", workerId); + } + + /** + * 获得下一个ID (该方法是线程安全的) + * + * @return SnowflakeId + */ + @Override + public synchronized long getNextId() { + long timestamp = timeGen(); + //如果当前时间小于上一次ID生成的时间戳,说明系统时钟回退过这个时候应当抛出异常 + if (timestamp < lastTimestamp) { + throw new RuntimeException(String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp)); + } + //如果是同一时间生成的,则进行毫秒内序列 + if (lastTimestamp == timestamp) { + sequence = (sequence + 1) & sequenceMask; + //毫秒内序列溢出 + if (sequence == 0) { + //阻塞到下一个毫秒,获得新的时间戳 + timestamp = tilNextMillis(lastTimestamp); + } + } + //时间戳改变,毫秒内序列重置 + else { + sequence = 0L; + } + //上次生成ID的时间截 + lastTimestamp = timestamp; + //移位并通过或运算拼到一起组成64位的ID + long id = ((timestamp - twepoch) << timestampLeftShift) + | (datacenterId << datacenterIdShift) + | (workerId << workerIdShift) + | sequence; + return id; + } + + + /** + * 阻塞到下一个毫秒,直到获得新的时间戳 + * + * @param lastTimestamp 上次生成ID的时间截 + * @return 当前时间戳 + */ + private long tilNextMillis(long lastTimestamp) { + long timestamp = timeGen(); + while (timestamp <= lastTimestamp) { + timestamp = timeGen(); + } + return timestamp; + } + + /** + * 返回以毫秒为单位的当前时间 + * + * @return 当前时间(毫秒) + */ + private static long timeGen() { + return System.currentTimeMillis(); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/common/impl/VerifyCodeServiceImpl.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/common/impl/VerifyCodeServiceImpl.java new file mode 100644 index 0000000..3c69db6 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/common/impl/VerifyCodeServiceImpl.java @@ -0,0 +1,110 @@ +package com.arm.equipment.system.data.service.common.impl; + +import com.arm.equipment.system.data.service.common.IVerifyCodeService; +import com.arm.equipment.system.data.util.RandomUtils; +import com.arm.equipment.system.data.vo.system.VerifyCodeVO; +import org.springframework.stereotype.Service; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Random; + +@Service +public class VerifyCodeServiceImpl implements IVerifyCodeService { + + private static final String[] FONT_TYPES = {"\u5b8b\u4f53", "\u65b0\u5b8b\u4f53", "\u9ed1\u4f53", "\u6977\u4f53", "\u96b6\u4e66"}; + + private static final int VALICATE_CODE_LENGTH = 4; + + /** + * 设置背景颜色及大小,干扰线 + * + * @param graphics + * @param width + * @param height + */ + private static void fillBackground(Graphics graphics, int width, int height) { + // 填充背景 + graphics.setColor(Color.WHITE); + //设置矩形坐标x y 为0 + graphics.fillRect(0, 0, width, height); + // 加入干扰线条 + for (int i = 0; i < 8; i++) { + //设置随机颜色算法参数 + graphics.setColor(RandomUtils.randomColor(40, 150)); + Random random = new Random(); + int x = random.nextInt(width); + int y = random.nextInt(height); + int x1 = random.nextInt(width); + int y1 = random.nextInt(height); + graphics.drawLine(x, y, x1, y1); + } + } + + /** + * 生成随机字符 + * + * @param width + * @param height + * @param os + * @return + * @throws IOException + */ + @Override + public String generate(int width, int height, OutputStream os) throws IOException { + BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + Graphics graphics = image.getGraphics(); + fillBackground(graphics, width, height); + String randomStr = RandomUtils.randomString(VALICATE_CODE_LENGTH); + createCharacter(graphics, randomStr); + graphics.dispose(); + //设置JPEG格式 + ImageIO.write(image, "JPEG", os); + return randomStr; + } + + /** + * 验证码生成 + * + * @param width + * @param height + * @return + */ + @Override + public VerifyCodeVO generate(int width, int height) { + VerifyCodeVO verifyCode = null; + //将流的初始化放到这里就不需要手动关闭流 + try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { + String code = generate(width, height, baos); + verifyCode = new VerifyCodeVO(); + verifyCode.setCode(code); + verifyCode.setImgBytes(baos.toByteArray()); + } catch (IOException e) { + verifyCode = null; + } + return verifyCode; + } + + /** + * 设置字符颜色大小 + * + * @param g + * @param randomStr + */ + private void createCharacter(Graphics g, String randomStr) { + char[] charArray = randomStr.toCharArray(); + for (int i = 0; i < charArray.length; i++) { + //设置RGB颜色算法参数 + g.setColor(new Color(50 + RandomUtils.nextInt(100), + 50 + RandomUtils.nextInt(100), 50 + RandomUtils.nextInt(100))); + //设置字体大小,类型 + g.setFont(new Font(FONT_TYPES[RandomUtils.nextInt(FONT_TYPES.length)], Font.BOLD, 26)); + //设置x y 坐标 + g.drawString(String.valueOf(charArray[i]), 15 * i + 5, 19 + RandomUtils.nextInt(8)); + } + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/file/IFileService.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/file/IFileService.java new file mode 100644 index 0000000..46cb86b --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/file/IFileService.java @@ -0,0 +1,22 @@ +package com.arm.equipment.system.data.service.file; + + +import com.arm.equipment.system.data.enums.file.EnumUpload; +import org.springframework.web.multipart.MultipartFile; + +/** + * 文件业务类 + * + * @author admin + */ +public interface IFileService { + /** + * 上传文件 + * + * @param file + * @param enumUploadItem + * @return + * @throws Exception + */ + String upload(MultipartFile file, EnumUpload enumUploadItem); +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/file/impl/FileServiceImpl.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/file/impl/FileServiceImpl.java new file mode 100644 index 0000000..795c247 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/file/impl/FileServiceImpl.java @@ -0,0 +1,53 @@ +package com.arm.equipment.system.data.service.file.impl; + + +import com.arm.equipment.system.data.enums.file.EnumUpload; +import com.arm.equipment.system.data.service.file.IFileService; +import com.arm.equipment.system.data.util.DateUtils; +import com.arm.equipment.system.data.util.UuidUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.io.IOException; +import java.util.Date; + +/** + * 上传文件 + * + * @author: xly + * @time: 2023/3/10 10:54 + */ +@Component +public class FileServiceImpl implements IFileService { + private final static Logger LOGGER = LoggerFactory.getLogger(FileServiceImpl.class); + @Override + public String upload(MultipartFile file, EnumUpload enumUploadItem) { + try { + String os = System.getProperty("os.name"); + //Windows操作系统 + String resourcePath = System.getProperty("user.dir"); + if (os != null && os.toLowerCase().startsWith("windows")) { + resourcePath = resourcePath + "\\"; + } else { + resourcePath = resourcePath + "/"; + } + File pathFile = new File(resourcePath); + //判断文件夹是否存在 + if (!pathFile.exists() && !pathFile.isDirectory()) { + pathFile.mkdirs(); + } + String fileName = UuidUtils.uuid() + "." + enumUploadItem.getSuffix(); + String filePath = resourcePath + fileName; + file.transferTo(new File(filePath)); + return fileName; + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/ISysBaseParamService.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/ISysBaseParamService.java new file mode 100644 index 0000000..bee886d --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/ISysBaseParamService.java @@ -0,0 +1,96 @@ +package com.arm.equipment.system.data.service.system; + +import com.arm.equipment.system.data.domain.system.SysBaseParam; + +import java.util.List; + +/** + * 系统--基础参数 + * + * @author Administrator + * @date 2021年10月26日 16:36:52 + */ +public interface ISysBaseParamService { + /** + * 保存或更新 + * @param req + */ + void save(SysBaseParam req, String operator); + + /** + * 插入 + * + * @param sysBaseParam sysBaseParam + * @return int + */ + int insertSelective(SysBaseParam sysBaseParam); + + /** + * 主键更新 + * + * @param sysBaseParam sysBaseParam + * @return int + */ + int updateSelectiveById(SysBaseParam sysBaseParam); + + /** + * 数量 + * + * @param sysBaseParam sysBaseParam + * @return int + */ + int getCount(SysBaseParam sysBaseParam); + + /** + * unicode查询 + * @param uniCode + * @return + */ + SysBaseParam getOneByUniCode(String uniCode); + + /** + * 主键查询 + * + * @param id id + * @return SysBaseParam + */ + SysBaseParam getOneById(Long id); + + /** + * 多条 + * + * @param sysBaseParam sysBaseParam + * @return List + */ + List getList(SysBaseParam sysBaseParam); + + /** + * 分页 + * + * @param sysBaseParam sysBaseParam + * @return List + */ + List getPageList(SysBaseParam sysBaseParam); + + /** + * 审核 + * @param id + * @param operator + */ + void audit(Long id, String operator); + + /** + * 取消审核 + * @param id + * @param operator + */ + void unaudit(Long id, String operator); + + /** + * 删除 + * @param id + * @param operator + */ + void delete(Long id, String operator); + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/ISysLogService.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/ISysLogService.java new file mode 100644 index 0000000..c83be9d --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/ISysLogService.java @@ -0,0 +1,88 @@ +package com.arm.equipment.system.data.service.system; + +import com.arm.equipment.system.data.domain.system.SysLog; + +import java.util.List; + +/** + * 日志表 + * + * @author admin + * @date 2022年09月16日 12:41:35 + */ +public interface ISysLogService { + /** + * 保存或更新 + * @param req + */ + void save(SysLog req, String operator); + + /** + * 插入 + * + * @param sysLog sysLog + * @return int + */ + int insertSelective(SysLog sysLog); + + /** + * 主键更新 + * + * @param sysLog sysLog + * @return int + */ + int updateSelectiveById(SysLog sysLog); + + /** + * 数量 + * + * @param sysLog sysLog + * @return int + */ + int getCount(SysLog sysLog); + + /** + * 主键查询 + * + * @param id id + * @return SysLog + */ + SysLog getOneById(Long id); + + /** + * 多条 + * + * @param sysLog sysLog + * @return List + */ + List getList(SysLog sysLog); + + /** + * 分页 + * + * @param sysLog sysLog + * @return List + */ + List getPageList(SysLog sysLog); + + /** + * 审核 + * @param id + * @param operator + */ + void audit(Long id, String operator); + + /** + * 取消审核 + * @param id + * @param operator + */ + void unaudit(Long id, String operator); + + /** + * 删除 + * @param id + * @param operator + */ + void delete(Long id, String operator); +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/ISysResourceService.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/ISysResourceService.java new file mode 100644 index 0000000..185cdc6 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/ISysResourceService.java @@ -0,0 +1,107 @@ +package com.arm.equipment.system.data.service.system; + +import com.arm.equipment.system.data.domain.system.SysResource; + +import java.util.List; + +/** + * 系统--权限表 + * + * @author admin + * @date 2021年10月19日 15:06:30 + */ +public interface ISysResourceService { + /** + * 保存或更新 + * + * @param req + */ + void save(SysResource req, String operator); + + /** + * 插入 + * + * @param sysResource sysResource + * @return int + */ + int insertSelective(SysResource sysResource); + + /** + * 主键更新 + * + * @param sysResource sysResource + * @return int + */ + int updateSelectiveById(SysResource sysResource); + + /** + * 数量 + * + * @param sysResource sysResource + * @return int + */ + int getCount(SysResource sysResource); + + /** + * 主键查询 + * + * @param id id + * @return SysResource + */ + SysResource getOneById(Long id); + + /** + * 多条 + * + * @param sysResource sysResource + * @return List + */ + List getList(SysResource sysResource); + + /** + * 分页 + * + * @param sysResource sysResource + * @return List + */ + List getPageList(SysResource sysResource); + + /** + * 审核 + * + * @param id + * @param operator + */ + void audit(Long id, String operator); + + /** + * 取消审核 + * + * @param id + * @param operator + */ + void unaudit(Long id, String operator); + + /** + * 删除 + * + * @param id + * @param operator + */ + void delete(Long id, String operator); + + /** + * 获取目录分页数据 + * + * @param sysResource + * @return + */ + List getPageTreeList(SysResource sysResource); + + /** + * 获取资源树 + * + * @return + */ + List getResourceTree(); +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/ISysRoleResourceService.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/ISysRoleResourceService.java new file mode 100644 index 0000000..0be329c --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/ISysRoleResourceService.java @@ -0,0 +1,120 @@ +package com.arm.equipment.system.data.service.system; + +import com.arm.equipment.system.data.domain.system.SysResource; +import com.arm.equipment.system.data.domain.system.SysRole; +import com.arm.equipment.system.data.domain.system.SysRoleResource; +import com.arm.equipment.system.data.vo.system.SysRoleResourceVO; + +import java.util.List; +import java.util.Map; + +/** + * 系统-角色权限关联表 + * + * @author admin + * @date 2021年10月19日 15:06:41 + */ +public interface ISysRoleResourceService { + /** + * 保存或更新 + * + * @param req + */ + void save(SysRoleResource req, String operator); + + /** + * 插入 + * + * @param sysRoleResource sysRoleResource + * @return int + */ + int insertSelective(SysRoleResource sysRoleResource); + + /** + * 主键更新 + * + * @param sysRoleResource sysRoleResource + * @return int + */ + int updateSelectiveById(SysRoleResource sysRoleResource); + + /** + * 数量 + * + * @param sysRoleResource sysRoleResource + * @return int + */ + int getCount(SysRoleResource sysRoleResource); + + /** + * 主键查询 + * + * @param id id + * @return SysRoleResource + */ + SysRoleResource getOneById(Long id); + + /** + * 多条 + * + * @param sysRoleResource sysRoleResource + * @return List + */ + List getList(SysRoleResource sysRoleResource); + + /** + * 分页 + * + * @param sysRoleResource sysRoleResource + * @return List + */ + List getPageList(SysRoleResource sysRoleResource); + + /** + * 审核 + * + * @param id + * @param operator + */ + void audit(Long id, String operator); + + /** + * 取消审核 + * + * @param id + * @param operator + */ + void unaudit(Long id, String operator); + + /** + * 删除 + * + * @param id + * @param operator + */ + void delete(Long id, String operator); + + /** + * 构建用户资源菜单及资源标识 + * + * @param sysUserRoleIdList + * @param sysUserResourceList + * @param sysResourceIdentityList + */ + void buildUserResourceListAndIdentityList(List sysUserRoleIdList, List sysUserResourceList, + List sysResourceIdentityList); + + /** + * 添加角色资源 + * @param roleResourceVO + * @param operator + */ + void addResource(SysRoleResourceVO roleResourceVO, String operator); + + /** + * 获取角色资源 + * @param roleId + * @return + */ + Map getResourcesIdListByRoleId(Long roleId); +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/ISysRoleService.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/ISysRoleService.java new file mode 100644 index 0000000..e8d884d --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/ISysRoleService.java @@ -0,0 +1,100 @@ +package com.arm.equipment.system.data.service.system; + +import com.arm.equipment.system.data.domain.system.SysRole; + +import java.util.List; + +/** + * 系统--角色表 + * + * @author admin + * @date 2021年10月19日 15:06:47 + */ +public interface ISysRoleService { + /** + * 保存或更新 + * + * @param req + */ + void save(SysRole req, String operator); + + /** + * 插入 + * + * @param sysRole sysRole + * @return int + */ + int insertSelective(SysRole sysRole); + + /** + * 主键更新 + * + * @param sysRole sysRole + * @return int + */ + int updateSelectiveById(SysRole sysRole); + + /** + * 数量 + * + * @param sysRole sysRole + * @return int + */ + int getCount(SysRole sysRole); + + /** + * 主键查询 + * + * @param id id + * @return SysRole + */ + SysRole getOneById(Long id); + + /** + * 多条 + * + * @param sysRole sysRole + * @return List + */ + List getList(SysRole sysRole); + + /** + * 分页 + * + * @param sysRole sysRole + * @return List + */ + List getPageList(SysRole sysRole); + + /** + * 审核 + * + * @param id + * @param operator + */ + void audit(Long id, String operator); + + /** + * 取消审核 + * + * @param id + * @param operator + */ + void unaudit(Long id, String operator); + + /** + * 删除 + * + * @param id + * @param operator + */ + void delete(Long id, String operator); + + /** + * 获取当前登陆用户拥有绝角色 + * + * @param userId + * @return + */ + List getCurrentUserRole(Long userId); +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/ISysUserRoleService.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/ISysUserRoleService.java new file mode 100644 index 0000000..429796a --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/ISysUserRoleService.java @@ -0,0 +1,86 @@ +package com.arm.equipment.system.data.service.system; + +import com.arm.equipment.system.data.domain.system.SysUser; +import com.arm.equipment.system.data.domain.system.SysUserRole; +import com.arm.equipment.system.data.vo.system.AddRoleVO; + +import java.util.List; + +/** + * 系统--用户角色关联表 + * + * @author admin + * @date 2021年10月19日 15:06:59 + */ +public interface ISysUserRoleService { + /** + * 保存或更新 + * + * @param req + */ + void save(SysUserRole req, String operator); + + /** + * 插入 + * + * @param sysUserRole sysUserRole + * @return int + */ + int insertSelective(SysUserRole sysUserRole); + + /** + * 主键更新 + * + * @param sysUserRole sysUserRole + * @return int + */ + int updateSelectiveById(SysUserRole sysUserRole); + + /** + * 数量 + * + * @param sysUserRole sysUserRole + * @return int + */ + int getCount(SysUserRole sysUserRole); + + /** + * 主键查询 + * + * @param id id + * @return SysUserRole + */ + SysUserRole getOneById(Long id); + + /** + * 多条 + * + * @param sysUserRole sysUserRole + * @return List + */ + List getList(SysUserRole sysUserRole); + + /** + * 分页 + * + * @param sysUserRole sysUserRole + * @return List + */ + List getPageList(SysUserRole sysUserRole); + + /** + * 删除 + * + * @param id + * @param operator + */ + void delete(Long id, String operator); + + /** + * 为用户分配角色 + * + * @param addRoleVO + * @param currentUser + */ + void addRole(AddRoleVO addRoleVO, SysUser currentUser); +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/ISysUserService.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/ISysUserService.java new file mode 100644 index 0000000..5367c2f --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/ISysUserService.java @@ -0,0 +1,115 @@ +package com.arm.equipment.system.data.service.system; + +import com.arm.equipment.system.data.domain.system.SysUser; + +import javax.servlet.http.HttpSession; +import java.util.List; + +/** + * 系统--用户表 + * + * @author admin + * @date 2021年10月19日 15:07:06 + */ +public interface ISysUserService { + /** + * 保存或更新 + * + * @param req + */ + void save(SysUser req, String operator); + + /** + * 插入 + * + * @param sysUser sysUser + * @return int + */ + int insertSelective(SysUser sysUser); + + /** + * 主键更新 + * + * @param sysUser sysUser + * @return int + */ + int updateSelectiveById(SysUser sysUser); + + /** + * 数量 + * + * @param sysUser sysUser + * @return int + */ + int getCount(SysUser sysUser); + + /** + * 主键查询 + * + * @param id id + * @return SysUser + */ + SysUser getOneById(Long id); + + /** + * 多条 + * + * @param sysUser sysUser + * @return List + */ + List getList(SysUser sysUser); + + /** + * 分页 + * + * @param sysUser sysUser + * @return List + */ + List getPageList(SysUser sysUser); + + /** + * @param id + * @return + */ + SysUser getExitOneById(Long id); + + /** + * 删除 + * + * @param id + * @param operator + */ + void delete(Long id, String operator); + + /** + * 登陆 + * + * @param sysUserReq + * @return + */ + SysUser login(SysUser sysUserReq, HttpSession webSession); + + /** + * 接口登陆 + * + * @param username + * @param password + * @return + */ + SysUser thirdLogin(String username, String password); + + /** + * 修改密码 + * + * @param oldPassword + * @param newPassword + * @param sysUserId + */ + void updatePassword(String oldPassword, String newPassword, Long sysUserId); + + /** + * 验证用户登陆错误次数 + * @param username + */ + void checkLoginErrorNumByUsername(String username); +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/impl/SysBaseParamServiceImpl.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/impl/SysBaseParamServiceImpl.java new file mode 100644 index 0000000..0a57c0e --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/impl/SysBaseParamServiceImpl.java @@ -0,0 +1,147 @@ +package com.arm.equipment.system.data.service.system.impl; + +import com.arm.equipment.system.data.domain.system.SysBaseParam; +import com.arm.equipment.system.data.enums.dict.EnumStatus; +import com.arm.equipment.system.data.exception.BusinessException; +import com.arm.equipment.system.data.mapper.system.ISysBaseParamMapper; +import com.arm.equipment.system.data.service.common.IIdWorkerService; +import com.arm.equipment.system.data.service.system.ISysBaseParamService; +import com.arm.equipment.system.data.constant.RedisKeys; +import com.arm.equipment.system.data.util.WJAssert; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 系统--基础参数 + * + * @author Administrator + * @date 2021年10月26日 16:36:52 + */ +@Service +public class SysBaseParamServiceImpl implements ISysBaseParamService { + @Autowired + private ISysBaseParamMapper sysBaseParamMapper; + @Autowired + private IIdWorkerService idWorkerService; + @Autowired + @Lazy + private ISysBaseParamService sysBaseParamService; + + @Override + public void save(SysBaseParam req, String operator) { + req.setOperator(operator); + if (null == req.getId()) { + insertSelective(req); + } else { + updateSelectiveById(req); + } + } + + @Override + public int insertSelective(SysBaseParam req) { + req.setId(idWorkerService.getNextId()); + req.setStatus(EnumStatus.NEW.getCode()); + if (null != getOneByUniCode(req.getUniCode())) { + throw new BusinessException("已存在同名参数值"); + } + checkStringLength(req, false); + return sysBaseParamMapper.insertSelective(req); + } + + @Override + @CacheEvict(value = RedisKeys.SYS_BASE_PARAM_KEY, key = "#sysBaseParam.uniCode") + public int updateSelectiveById(SysBaseParam sysBaseParam) { + WJAssert.notNull(sysBaseParam, "入参对象不能为空"); + WJAssert.notNull(sysBaseParam.getId(), "id参数错误"); + SysBaseParam where = new SysBaseParam(); + where.setId(sysBaseParam.getId()); + return sysBaseParamMapper.updateSelective(sysBaseParam, where); + } + + @Override + public int getCount(SysBaseParam sysBaseParam) { + checkStringLength(sysBaseParam, true); + return sysBaseParamMapper.getCount(sysBaseParam); + } + + @Override + public SysBaseParam getOneById(Long id) { + WJAssert.notNull(id, "id参数错误"); + SysBaseParam where = new SysBaseParam(); + where.setId(id); + return sysBaseParamMapper.getOne(where); + } + + @Override + public List getList(SysBaseParam sysBaseParam) { + checkStringLength(sysBaseParam, true); + return sysBaseParamMapper.getList(sysBaseParam); + } + + @Override + public List getPageList(SysBaseParam sysBaseParam) { + checkStringLength(sysBaseParam, true); + return sysBaseParamMapper.getPageList(sysBaseParam); + } + + @Override + public void audit(Long id, String operator) { + SysBaseParam req = new SysBaseParam(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.AUDIT.getCode()); + + SysBaseParam baseParamDB = getOneById(id); + req.setUniCode(baseParamDB.getUniCode()); + sysBaseParamService.updateSelectiveById(req); + } + + @Override + public void unaudit(Long id, String operator) { + SysBaseParam req = new SysBaseParam(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.NEW.getCode()); + + SysBaseParam baseParamDB = getOneById(id); + req.setUniCode(baseParamDB.getUniCode()); + sysBaseParamService.updateSelectiveById(req); + } + + @Override + public void delete(Long id, String operator) { + SysBaseParam req = new SysBaseParam(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.DEL.getCode()); + updateSelectiveById(req); + } + + @Cacheable(value = RedisKeys.SYS_BASE_PARAM_KEY, key = "#uniCode") + @Override + public SysBaseParam getOneByUniCode(String uniCode) { + WJAssert.isMaxLength(uniCode, 50, "UNICODE非法"); + SysBaseParam where = new SysBaseParam(); + where.setUniCode(uniCode); + where.setStatus(EnumStatus.AUDIT.getCode()); + return sysBaseParamMapper.getOne(where); + } + + + /** + * 参数校验注解默认使用的方法 + */ + private void checkStringLength(SysBaseParam sysBaseParam, boolean nullAble) { + WJAssert.notNull(sysBaseParam, "入参对象不能为空"); + WJAssert.limitMaxLength(sysBaseParam.getUniCode(), nullAble, 50, "唯一编码不合法!"); + WJAssert.limitMaxLength(sysBaseParam.getValue(), nullAble, 2000, "值不合法!"); + WJAssert.limitMaxLength(sysBaseParam.getDescription(), nullAble, 300, "描述不合法!"); + WJAssert.limitMaxLength(sysBaseParam.getOperator(), nullAble, 100, "操作人不合法!"); + WJAssert.limitMaxLength(sysBaseParam.getRemark(), true, 255, "备注不合法!"); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/impl/SysLogServiceImpl.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/impl/SysLogServiceImpl.java new file mode 100644 index 0000000..c0f7130 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/impl/SysLogServiceImpl.java @@ -0,0 +1,122 @@ +package com.arm.equipment.system.data.service.system.impl; + +import com.arm.equipment.system.data.enums.dict.EnumStatus; +import com.arm.equipment.system.data.util.WJAssert; +import com.arm.equipment.system.data.service.common.IIdWorkerService; +import com.arm.equipment.system.data.mapper.system.ISysLogMapper; +import com.arm.equipment.system.data.domain.system.SysLog; +import com.arm.equipment.system.data.service.system.ISysLogService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 日志表 + * + * @author admin + * @date 2022年09月16日 12:41:35 + */ +@Service +public class SysLogServiceImpl implements ISysLogService { + @Autowired + private ISysLogMapper sysLogMapper; + @Autowired + private IIdWorkerService idWorkerService; + + @Override + public void save(SysLog req, String operator) { + req.setOperator(operator); + if (null == req.getId()) { + insertSelective(req); + } else { + updateSelectiveById(req); + } + } + + @Override + public int insertSelective(SysLog req) { + req.setId(idWorkerService.getNextId()); + req.setStatus(EnumStatus.NEW.getCode()); + checkStringLength(req, false); + return sysLogMapper.insertSelective(req); + } + + @Override + public int updateSelectiveById(SysLog sysLog) { + WJAssert.notNull(sysLog, "入参对象不能为空"); + WJAssert.notNull(sysLog.getId(), "id参数错误"); + SysLog where = new SysLog(); + where.setId(sysLog.getId()); + return sysLogMapper.updateSelective(sysLog, where); + } + + @Override + public int getCount(SysLog sysLog) { + checkStringLength(sysLog, true); + return sysLogMapper.getCount(sysLog); + } + + @Override + public SysLog getOneById(Long id) { + WJAssert.notNull(id, "id参数错误"); + SysLog where = new SysLog(); + where.setId(id); + return sysLogMapper.getOne(where); + } + + @Override + public List getList(SysLog sysLog) { + checkStringLength(sysLog, true); + return sysLogMapper.getList(sysLog); + } + + @Override + public List getPageList(SysLog sysLog) { + checkStringLength(sysLog, true); + return sysLogMapper.getPageList(sysLog); + } + + @Override + public void audit(Long id, String operator) { + SysLog req = new SysLog(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.AUDIT.getCode()); + updateSelectiveById(req); + } + + @Override + public void unaudit(Long id, String operator) { + SysLog req = new SysLog(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.NEW.getCode()); + updateSelectiveById(req); + } + + @Override + public void delete(Long id, String operator) { + SysLog req = new SysLog(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.DEL.getCode()); + updateSelectiveById(req); + } + + /** + * 参数校验注解默认使用的方法 + */ + private void checkStringLength(SysLog sysLog, boolean nullAble) { + WJAssert.notNull(sysLog, "入参对象不能为空"); + WJAssert.limitMaxLength(sysLog.getTitle(), true, 500, "日志标题不合法!"); + WJAssert.limitMaxLength(sysLog.getRemoteAddr(), true, 255, "操作IP地址不合法!"); + WJAssert.limitMaxLength(sysLog.getUserAgent(), true, 255, "用户代理不合法!"); + WJAssert.limitMaxLength(sysLog.getRequestUri(), true, 255, "请求URI不合法!"); + WJAssert.limitMaxLength(sysLog.getMethod(), true, 10, "操作方式不合法!"); + WJAssert.limitMaxLength(sysLog.getParams(), true, 1000, "操作提交的数据不合法!"); + WJAssert.limitMaxLength(sysLog.getException(), true, 1000, "异常信息不合法!"); + WJAssert.limitMaxLength(sysLog.getOperator(), nullAble, 50, "操作人不合法!"); + WJAssert.limitMaxLength(sysLog.getRemark(), true, 255, "备注不合法!"); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/impl/SysResourceServiceImpl.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/impl/SysResourceServiceImpl.java new file mode 100644 index 0000000..a79362e --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/impl/SysResourceServiceImpl.java @@ -0,0 +1,201 @@ +package com.arm.equipment.system.data.service.system.impl; + +import com.arm.equipment.system.data.domain.system.SysResource; +import com.arm.equipment.system.data.enums.dict.EnumStatus; +import com.arm.equipment.system.data.enums.dict.EnumSysResourceType; +import com.arm.equipment.system.data.exception.BusinessException; +import com.arm.equipment.system.data.mapper.system.ISysResourceMapper; +import com.arm.equipment.system.data.service.common.IIdWorkerService; +import com.arm.equipment.system.data.service.system.ISysResourceService; +import com.arm.equipment.system.data.util.WJAssert; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 系统--权限表 + * + * @author admin + * @date 2021年10月20日 08:59:10 + */ +@Service +public class SysResourceServiceImpl implements ISysResourceService { + @Autowired + private ISysResourceMapper sysResourceMapper; + @Autowired + private IIdWorkerService idWorkerService; + + @Override + public void save(SysResource req, String operator) { + req.setOperator(operator); + if (StringUtils.isNotBlank(req.getIdentity())) { + SysResource where = new SysResource(); + where.setIdentity(req.getIdentity()); + SysResource resourceDB = sysResourceMapper.getOne(where); + if (resourceDB != null && !resourceDB.getId().equals(req.getId())) { + throw new BusinessException("标识已存在!"); + } + } + if (null == req.getId()) { + insertSelective(req); + } else { + updateSelectiveById(req); + } + } + + @Override + public int insertSelective(SysResource req) { + req.setId(idWorkerService.getNextId()); + req.setStatus(EnumStatus.NEW.getCode()); + checkStringLength(req, false); + return sysResourceMapper.insertSelective(req); + } + + @Override + public int updateSelectiveById(SysResource sysResource) { + WJAssert.notNull(sysResource, "入参对象不能为空"); + WJAssert.notNull(sysResource.getId(), "id参数错误"); + SysResource where = new SysResource(); + where.setId(sysResource.getId()); + return sysResourceMapper.updateSelective(sysResource, where); + } + + @Override + public int getCount(SysResource sysResource) { + checkStringLength(sysResource, true); + return sysResourceMapper.getCount(sysResource); + } + + @Override + public SysResource getOneById(Long id) { + WJAssert.notNull(id, "id参数错误"); + SysResource where = new SysResource(); + where.setId(id); + return sysResourceMapper.getOne(where); + } + + @Override + public List getList(SysResource sysResource) { + checkStringLength(sysResource, true); + return sysResourceMapper.getList(sysResource); + } + + @Override + public List getPageList(SysResource sysResource) { + checkStringLength(sysResource, true); + return sysResourceMapper.getPageList(sysResource); + } + + @Override + public void audit(Long id, String operator) { + SysResource req = new SysResource(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.AUDIT.getCode()); + updateSelectiveById(req); + } + + @Override + public void unaudit(Long id, String operator) { + SysResource req = new SysResource(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.NEW.getCode()); + updateSelectiveById(req); + } + + @Override + public void delete(Long id, String operator) { + SysResource req = new SysResource(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.DEL.getCode()); + updateSelectiveById(req); + } + + /** + * 获取目录分页数据 + * + * @param sysResource + * @return + */ + @Override + public List getPageTreeList(SysResource sysResource) { + SysResource where = new SysResource(); + sysResource.setStatus(EnumStatus.NEW.getCode()); + List listDB = sysResourceMapper.getList(where); + + return sysResourceMapper.getPageList(sysResource) + .stream().peek(item -> { + item.setLabel(item.getName()); + item.setChildren(getChildrenTree(listDB, item.getId().toString())); + }).collect(Collectors.toList()); + } + + /** + * 获取资源树 + * 获取全部数据进行楼中楼 + * + * @return + */ + @Override + public List getResourceTree() { + SysResource sysResource = new SysResource(); + sysResource.setStatus(EnumStatus.NEW.getCode()); + List listDB = sysResourceMapper.getList(sysResource); + + List catalogueList = listDB.stream().filter(item -> { + return item.getType().equals(EnumSysResourceType.CATALOGUE.getCode()); + }).sorted(Comparator.comparing(SysResource::getSort)).collect(Collectors.toList()); + + return catalogueList.stream() + .peek(item -> { + item.setLabel(item.getName()); + item.setIcon("el-icon-folder-opened"); + item.setChildren(getChildrenTree(listDB, item.getId().toString())); + }).collect(Collectors.toList()); + } + + /** + * 根据目录盖楼 格式(目录->菜单->按钮) + * + * @param listDB + * @param parentId + * @return + */ + private List getChildrenTree(List listDB, String parentId) { + return listDB.stream() + .filter(item -> { + return parentId.equals(item.getParentId()) && EnumSysResourceType.MENU.getCode().equals(item.getType()); + }).peek(item -> { + item.setLabel(item.getName()); + item.setIcon("el-icon-document"); + List btnList = listDB.stream() + .filter(btnItem -> { + return btnItem.getParentId().equals(item.getId().toString()) && EnumSysResourceType.BUTTON.getCode().equals(btnItem.getType()); + }).peek(btnItem -> { + btnItem.setLabel(btnItem.getName()); + }).sorted(Comparator.comparing(SysResource::getSort)).collect(Collectors.toList()); + item.setChildren(btnList); + }).sorted(Comparator.comparing(SysResource::getSort)).collect(Collectors.toList()); + } + + /** + * 参数校验注解默认使用的方法 + */ + private void checkStringLength(SysResource sysResource, boolean nullAble) { + WJAssert.notNull(sysResource, "入参对象不能为空"); + WJAssert.limitMaxLength(sysResource.getName(), nullAble, 100, "菜单名称不合法!"); + WJAssert.limitMaxLength(sysResource.getUrl(), true, 200, "链接地址不合法!"); + WJAssert.limitMaxLength(sysResource.getParentId(), true, 32, "父菜单ID不合法!"); + WJAssert.limitMaxLength(sysResource.getIcon(), true, 200, "图标不合法!"); + WJAssert.limitMaxLength(sysResource.getIdentity(), nullAble, 255, "权限标识不合法!"); + WJAssert.limitMaxLength(sysResource.getOperator(), true, 50, "操作人不合法!"); + WJAssert.limitMaxLength(sysResource.getRemark(), true, 255, "备注不合法!"); + WJAssert.limitMaxLength(sysResource.getRootPath(), true, 255, "根路径,用.分隔不合法!"); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/impl/SysRoleResourceServiceImpl.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/impl/SysRoleResourceServiceImpl.java new file mode 100644 index 0000000..c12a856 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/impl/SysRoleResourceServiceImpl.java @@ -0,0 +1,311 @@ +package com.arm.equipment.system.data.service.system.impl; + +import com.arm.equipment.system.data.domain.system.SysResource; +import com.arm.equipment.system.data.domain.system.SysRole; +import com.arm.equipment.system.data.domain.system.SysRoleResource; +import com.arm.equipment.system.data.enums.dict.EnumStatus; +import com.arm.equipment.system.data.enums.dict.EnumSysResourceType; +import com.arm.equipment.system.data.exception.BusinessException; +import com.arm.equipment.system.data.mapper.system.ISysRoleResourceMapper; +import com.arm.equipment.system.data.service.common.IIdWorkerService; +import com.arm.equipment.system.data.service.system.ISysResourceService; +import com.arm.equipment.system.data.service.system.ISysRoleResourceService; +import com.arm.equipment.system.data.service.system.ISysRoleService; +import com.arm.equipment.system.data.util.WJAssert; +import com.arm.equipment.system.data.vo.system.SysRoleResourceVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * 系统-角色权限关联表 + * + * @author admin + * @date 2021年10月19日 15:06:41 + */ +@Service +public class SysRoleResourceServiceImpl implements ISysRoleResourceService { + @Autowired + private ISysRoleResourceMapper sysRoleResourceMapper; + @Autowired + private IIdWorkerService idWorkerService; + @Autowired + private ISysResourceService sysResourceService; + @Autowired + private ISysRoleService sysRoleService; + + @Override + public void save(SysRoleResource req, String operator) { + req.setOperator(operator); + if (null == req.getId()) { + insertSelective(req); + } else { + updateSelectiveById(req); + } + } + + @Override + public int insertSelective(SysRoleResource req) { + req.setId(idWorkerService.getNextId()); + req.setStatus(EnumStatus.NEW.getCode()); + checkStringLength(req, false); + return sysRoleResourceMapper.insertSelective(req); + } + + @Override + public int updateSelectiveById(SysRoleResource sysRoleResource) { + WJAssert.notNull(sysRoleResource, "入参对象不能为空"); + WJAssert.notNull(sysRoleResource.getId(), "id参数错误"); + SysRoleResource where = new SysRoleResource(); + where.setId(sysRoleResource.getId()); + return sysRoleResourceMapper.updateSelective(sysRoleResource, where); + } + + @Override + public int getCount(SysRoleResource sysRoleResource) { + checkStringLength(sysRoleResource, true); + return sysRoleResourceMapper.getCount(sysRoleResource); + } + + @Override + public SysRoleResource getOneById(Long id) { + WJAssert.notNull(id, "id参数错误"); + SysRoleResource where = new SysRoleResource(); + where.setId(id); + return sysRoleResourceMapper.getOne(where); + } + + @Override + public List getList(SysRoleResource sysRoleResource) { + checkStringLength(sysRoleResource, true); + return sysRoleResourceMapper.getList(sysRoleResource); + } + + @Override + public List getPageList(SysRoleResource sysRoleResource) { + checkStringLength(sysRoleResource, true); + return sysRoleResourceMapper.getPageList(sysRoleResource); + } + + @Override + public void audit(Long id, String operator) { + SysRoleResource req = new SysRoleResource(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.AUDIT.getCode()); + updateSelectiveById(req); + } + + @Override + public void unaudit(Long id, String operator) { + SysRoleResource req = new SysRoleResource(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.NEW.getCode()); + updateSelectiveById(req); + } + + @Override + public void delete(Long id, String operator) { + SysRoleResource req = new SysRoleResource(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.DEL.getCode()); + updateSelectiveById(req); + } + + /** + * 构建用户资源菜单及资源标识 + * + * @param sysUserRoleIdList + * @param sysUserResourceList + * @param sysResourceIdentityList + */ + @Override + public void buildUserResourceListAndIdentityList(List sysUserRoleIdList, List sysUserResourceList, + List sysResourceIdentityList) { + if (CollectionUtils.isEmpty(sysUserRoleIdList)) { + return; + } + List roleIds = sysUserRoleIdList.stream().map(SysRole::getId).collect(Collectors.toList()); + List list = sysRoleResourceMapper.getListBySysRoleIdIn(roleIds); + if (CollectionUtils.isEmpty(list)) { + return; + } + List resourceIdList = list.stream().map(SysRoleResource::getSysResourceId).distinct().collect(Collectors.toList()); + + SysResource sysResourceWhere = new SysResource(); + sysResourceWhere.setStatus(EnumStatus.NEW.getCode()); + sysResourceWhere.setIdsList(resourceIdList); + List sysResourcesList = sysResourceService.getList(sysResourceWhere); + if (CollectionUtils.isEmpty(sysResourcesList)) { + return; + } + //用户所拥有资源标识 + List resourceIdentityList = sysResourcesList.stream().map(SysResource::getIdentity).collect(Collectors.toList()); + //目录资源集合 + List allCatalogueResourceList = sysResourcesList.stream().filter(item -> { + return EnumSysResourceType.CATALOGUE.getCode().equals(item.getType()); + }).sorted(Comparator.comparing(SysResource::getSort)).collect(Collectors.toList()); + //菜单资源集合 + List allMenuResourceList = sysResourcesList.stream().filter(item -> { + return EnumSysResourceType.MENU.getCode().equals(item.getType()); + }).collect(Collectors.toList()); + //用户所拥有目录菜单资源盖楼 + List userResourceList = allCatalogueResourceList.stream() + .peek(item -> { + List childrenList = allMenuResourceList.stream().filter(childrenItem -> { + return item.getId().toString().equals(childrenItem.getParentId()); + }).sorted(Comparator.comparing(SysResource::getSort)).collect(Collectors.toList()); + item.setChildren(childrenList); + }).collect(Collectors.toList()); + sysUserResourceList.addAll(userResourceList); + sysResourceIdentityList.addAll(resourceIdentityList); + } + + /** + * 添加角色资源 + * + * @param roleResourceVO + * @param operator + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void addResource(SysRoleResourceVO roleResourceVO, String operator) { + List newResourcesList = roleResourceVO.getResourcesIds(); + if (null == roleResourceVO.getRoleId()) { + return; + } + SysRole sysRoleDB = sysRoleService.getOneById(roleResourceVO.getRoleId()); + if (sysRoleDB == null) { + throw new BusinessException("不存的角色!"); + } + sysRoleResourceMapper.deleteByRoleId(roleResourceVO.getRoleId()); + if (CollectionUtils.isEmpty(newResourcesList)) { + return; + } + List list = newResourcesList.parallelStream().map(item -> { + SysRoleResource req = new SysRoleResource(); + req.setOperator(operator); + req.setSysResourceId(item); + req.setSysRoleId(roleResourceVO.getRoleId()); + req.setId(idWorkerService.getNextId()); + req.setStatus(EnumStatus.NEW.getCode()); + return req; + }).collect(Collectors.toList()); + sysRoleResourceMapper.batchInsert(list); + } + + /** + * 获取角色所拥有权限 el-tree树默认勾选 + * 1.获取当前角色所拥有所有权限菜单 + * 2.分别获取当前角色所拥有所有权限菜单中的目录、菜单、按钮集合 + * 3.过滤当前角色菜单中是否所有按钮权限都拥有,是返回当前菜单ID 否 不返回(决定当前菜单树下面的所有子节点是否全勾选) + * 4.过滤当前角色目录中是否所有菜单权限都拥有,(使用步骤三过滤出来的菜单集合进行判断)是返回当前目录ID 否 不返回(决定当前菜单树下面的所有子节点是否全勾选) + * 5.返回过滤后的目录、菜单、按钮集合(用与默认勾选)与无过滤的集合(防止不更改直接提交) + * + * @param roleId + * @return + */ + @Override + public Map getResourcesIdListByRoleId(Long roleId) { + Map resultMap = new HashMap<>(2); + resultMap.put("checkedTreeList", new ArrayList<>()); + resultMap.put("treeList", new ArrayList<>()); + + List resultList = new ArrayList<>(); + SysRoleResource req = new SysRoleResource(); + req.setSysRoleId(roleId); + List resourceIdList = getList(req).stream().map(SysRoleResource::getSysResourceId).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(resourceIdList)) { + return resultMap; + } + + SysResource sysResourceWhere = new SysResource(); + sysResourceWhere.setStatus(EnumStatus.NEW.getCode()); + sysResourceWhere.setIdsList(resourceIdList); + List sysResourcesList = sysResourceService.getList(sysResourceWhere); + if (CollectionUtils.isEmpty(sysResourcesList)) { + return resultMap; + } + //用户所拥有目录资源集合 + List allCatalogueResourceIdList = sysResourcesList.stream().filter(item -> { + return EnumSysResourceType.CATALOGUE.getCode().equals(item.getType()); + }).map(SysResource::getId).collect(Collectors.toList()); + + //用户所拥有菜单资源集合 + List allMenuResourceIdList = sysResourcesList.stream().filter(item -> { + return EnumSysResourceType.MENU.getCode().equals(item.getType()); + }).collect(Collectors.toList()); + + //用户所拥有按钮资源集合 + List allButtonResourceIdList = sysResourcesList.stream().filter(item -> { + return EnumSysResourceType.BUTTON.getCode().equals(item.getType()); + }).collect(Collectors.toList()); + + + SysResource srWhere = new SysResource(); + srWhere.setStatus(EnumStatus.NEW.getCode()); + List resourceAllListDB = sysResourceService.getList(srWhere); + + + //过滤后的结果菜单 + List menuResourceIdListResult = allMenuResourceIdList.stream() + .filter(item -> { + return isHasAllChildren(allButtonResourceIdList, resourceAllListDB, EnumSysResourceType.BUTTON.getCode(), item.getId()); + }).collect(Collectors.toList()); + + //过滤后的结果目录 + List catalogueResourceIdListResult = allCatalogueResourceIdList.stream() + .filter(item -> { + return isHasAllChildren(menuResourceIdListResult, resourceAllListDB, EnumSysResourceType.MENU.getCode(), item); + }).collect(Collectors.toList()); + List buttonIdList = allButtonResourceIdList.stream().map(SysResource::getId).collect(Collectors.toList()); + List menuIdList = menuResourceIdListResult.stream().map(SysResource::getId).collect(Collectors.toList()); + resultList.addAll(catalogueResourceIdListResult); + resultList.addAll(menuIdList); + resultList.addAll(buttonIdList); + + resultMap.put("checkedTreeList", resultList); + resultMap.put("treeList", resourceIdList); + + return resultMap; + } + + /** + * 菜单是否包含所有子类 + * + * @param resourceIdList + * @param type + * @param resourceId + * @return + */ + private boolean isHasAllChildren(List resourceIdList, List resourceAllListDB, Integer type, Long resourceId) { + //得到当前类型的所有对应子节点 + List idList = resourceIdList + .stream() + .filter(item -> item.getParentId().equals(resourceId.toString())) + .map(SysResource::getId).collect(Collectors.toList()); + List idListDB = resourceAllListDB + .stream() + .filter(item -> item.getParentId().equals(resourceId.toString()) && item.getType().equals(type)) + .map(SysResource::getId).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(idListDB)) { + return true; + } + return idList.size() == idListDB.size(); + } + + /** + * 参数校验注解默认使用的方法 + */ + private void checkStringLength(SysRoleResource sysRoleResource, boolean nullAble) { + WJAssert.notNull(sysRoleResource, "入参对象不能为空"); + WJAssert.limitMaxLength(sysRoleResource.getOperator(), true, 255, "操作人不合法!"); + WJAssert.limitMaxLength(sysRoleResource.getRemark(), true, 255, "备注不合法!"); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/impl/SysRoleServiceImpl.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/impl/SysRoleServiceImpl.java new file mode 100644 index 0000000..b501198 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/impl/SysRoleServiceImpl.java @@ -0,0 +1,146 @@ +package com.arm.equipment.system.data.service.system.impl; + +import com.arm.equipment.system.data.domain.system.SysRole; +import com.arm.equipment.system.data.domain.system.SysUserRole; +import com.arm.equipment.system.data.enums.dict.EnumStatus; +import com.arm.equipment.system.data.mapper.system.ISysRoleMapper; +import com.arm.equipment.system.data.service.common.IIdWorkerService; +import com.arm.equipment.system.data.service.system.ISysRoleService; +import com.arm.equipment.system.data.service.system.ISysUserRoleService; +import com.arm.equipment.system.data.util.WJAssert; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * 系统--角色表 + * + * @author admin + * @date 2021年10月19日 15:06:47 + */ +@Service +public class SysRoleServiceImpl implements ISysRoleService { + @Autowired + private ISysRoleMapper sysRoleMapper; + @Autowired + private IIdWorkerService idWorkerService; + @Autowired + private ISysUserRoleService sysUserRoleService; + + @Override + public void save(SysRole req, String operator) { + req.setOperator(operator); + if (null == req.getId()) { + insertSelective(req); + } else { + updateSelectiveById(req); + } + } + + @Override + public int insertSelective(SysRole req) { + req.setId(idWorkerService.getNextId()); + req.setStatus(EnumStatus.NEW.getCode()); + checkStringLength(req, false); + return sysRoleMapper.insertSelective(req); + } + + @Override + public int updateSelectiveById(SysRole sysRole) { + WJAssert.notNull(sysRole, "入参对象不能为空"); + WJAssert.notNull(sysRole.getId(), "id参数错误"); + SysRole where = new SysRole(); + where.setId(sysRole.getId()); + return sysRoleMapper.updateSelective(sysRole, where); + } + + @Override + public int getCount(SysRole sysRole) { + checkStringLength(sysRole, true); + return sysRoleMapper.getCount(sysRole); + } + + @Override + public SysRole getOneById(Long id) { + WJAssert.notNull(id, "id参数错误"); + SysRole where = new SysRole(); + where.setId(id); + where.setStatus(EnumStatus.NEW.getCode()); + return sysRoleMapper.getOne(where); + } + + @Override + public List getList(SysRole sysRole) { + checkStringLength(sysRole, true); + return sysRoleMapper.getList(sysRole); + } + + @Override + public List getPageList(SysRole sysRole) { + checkStringLength(sysRole, true); + return sysRoleMapper.getPageList(sysRole); + } + + @Override + public void audit(Long id, String operator) { + SysRole req = new SysRole(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.AUDIT.getCode()); + updateSelectiveById(req); + } + + @Override + public void unaudit(Long id, String operator) { + SysRole req = new SysRole(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.NEW.getCode()); + updateSelectiveById(req); + } + + @Override + public void delete(Long id, String operator) { + SysRole req = new SysRole(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.DEL.getCode()); + updateSelectiveById(req); + } + + /** + * 获取当前登陆用户拥有绝角色 + * + * @param userId + * @return + */ + @Override + public List getCurrentUserRole(Long userId) { + SysUserRole sysUserRole = new SysUserRole(); + sysUserRole.setStatus(EnumStatus.NEW.getCode()); + sysUserRole.setSysUserId(userId); + List sysUserRoleList = sysUserRoleService.getList(sysUserRole); + if (CollectionUtils.isEmpty(sysUserRoleList)) { + return null; + } + List sysRoleIdList = sysUserRoleList.stream().map(SysUserRole::getSysRoleId).collect(Collectors.toList()); + SysRole sysRole = new SysRole(); + sysRole.setSysRoleIdList(sysRoleIdList); + List sysRoleList = sysRoleMapper.getList(sysRole); + return sysRoleList; + } + + /** + * 参数校验注解默认使用的方法 + */ + private void checkStringLength(SysRole sysRole, boolean nullAble) { + WJAssert.notNull(sysRole, "入参对象不能为空"); + WJAssert.limitMaxLength(sysRole.getName(), nullAble, 100, "角色名称不合法!"); + WJAssert.limitMaxLength(sysRole.getDescription(), nullAble, 200, "描述不合法!"); + WJAssert.limitMaxLength(sysRole.getOperator(), true, 255, "操作人不合法!"); + WJAssert.limitMaxLength(sysRole.getRemark(), true, 255, "备注不合法!"); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/impl/SysUserRoleServiceImpl.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/impl/SysUserRoleServiceImpl.java new file mode 100644 index 0000000..2eca55b --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/impl/SysUserRoleServiceImpl.java @@ -0,0 +1,123 @@ +package com.arm.equipment.system.data.service.system.impl; + +import com.arm.equipment.system.data.domain.system.SysUser; +import com.arm.equipment.system.data.domain.system.SysUserRole; +import com.arm.equipment.system.data.enums.dict.EnumStatus; +import com.arm.equipment.system.data.exception.BusinessException; +import com.arm.equipment.system.data.mapper.system.ISysUserRoleMapper; +import com.arm.equipment.system.data.service.common.IIdWorkerService; +import com.arm.equipment.system.data.service.system.ISysUserRoleService; +import com.arm.equipment.system.data.util.WJAssert; +import com.arm.equipment.system.data.vo.system.AddRoleVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +/** + * 系统--用户角色关联表 + * + * @author admin + * @date 2021年10月19日 15:06:59 + */ +@Service +public class SysUserRoleServiceImpl implements ISysUserRoleService { + @Autowired + private ISysUserRoleMapper sysUserRoleMapper; + @Autowired + private IIdWorkerService idWorkerService; + + @Override + public void save(SysUserRole req, String operator) { + req.setOperator(operator); + if (null == req.getId()) { + insertSelective(req); + } else { + updateSelectiveById(req); + } + } + + @Override + public int insertSelective(SysUserRole req) { + req.setId(idWorkerService.getNextId()); + req.setStatus(EnumStatus.NEW.getCode()); + checkStringLength(req, false); + return sysUserRoleMapper.insertSelective(req); + } + + @Override + public int updateSelectiveById(SysUserRole sysUserRole) { + WJAssert.notNull(sysUserRole, "入参对象不能为空"); + WJAssert.notNull(sysUserRole.getId(), "id参数错误"); + SysUserRole where = new SysUserRole(); + where.setId(sysUserRole.getId()); + return sysUserRoleMapper.updateSelective(sysUserRole, where); + } + + @Override + public int getCount(SysUserRole sysUserRole) { + checkStringLength(sysUserRole, true); + return sysUserRoleMapper.getCount(sysUserRole); + } + + @Override + public SysUserRole getOneById(Long id) { + WJAssert.notNull(id, "id参数错误"); + SysUserRole where = new SysUserRole(); + where.setId(id); + return sysUserRoleMapper.getOne(where); + } + + @Override + public List getList(SysUserRole sysUserRole) { + checkStringLength(sysUserRole, true); + return sysUserRoleMapper.getList(sysUserRole); + } + + @Override + public List getPageList(SysUserRole sysUserRole) { + checkStringLength(sysUserRole, true); + return sysUserRoleMapper.getPageList(sysUserRole); + } + + @Override + public void delete(Long id, String operator) { + SysUserRole req = new SysUserRole(); + req.setId(id); + req.setOperator(operator); + updateSelectiveById(req); + } + + /** + * 为用户分配角色 + * + * @param addRoleVO + * @param currentUser + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void addRole(AddRoleVO addRoleVO, SysUser currentUser) { + List newRoleList = addRoleVO.getNewRole(); + if (null == addRoleVO.getUserId()) { + throw new BusinessException("新增角色ID或用户ID不能为空"); + } + sysUserRoleMapper.deleteByUserId(addRoleVO.getUserId()); + newRoleList.stream().forEach(item -> { + SysUserRole req = new SysUserRole(); + req.setSysRoleId(item); + req.setOperator(currentUser.getName()); + req.setSysUserId(addRoleVO.getUserId()); + insertSelective(req); + }); + } + + /** + * 参数校验注解默认使用的方法 + */ + private void checkStringLength(SysUserRole sysUserRole, boolean nullAble) { + WJAssert.notNull(sysUserRole, "入参对象不能为空"); + WJAssert.limitMaxLength(sysUserRole.getOperator(), nullAble, 50, "执行者不合法!"); + WJAssert.limitMaxLength(sysUserRole.getRemark(), true, 255, "备注不合法!"); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/impl/SysUserServiceImpl.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/impl/SysUserServiceImpl.java new file mode 100644 index 0000000..26f4c03 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/system/impl/SysUserServiceImpl.java @@ -0,0 +1,254 @@ +package com.arm.equipment.system.data.service.system.impl; + +import com.arm.equipment.system.data.constant.RedisKeys; +import com.arm.equipment.system.data.domain.system.SysUser; +import com.arm.equipment.system.data.enums.dict.EnumStatus; +import com.arm.equipment.system.data.exception.BusinessException; +import com.arm.equipment.system.data.mapper.system.ISysUserMapper; +import com.arm.equipment.system.data.service.common.IIdWorkerService; +import com.arm.equipment.system.data.service.system.ISysUserService; +import com.arm.equipment.system.data.util.WJAssert; +import com.arm.equipment.system.data.util.passwordEncoder.BCryptPasswordEncoderUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.ValueOperations; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.servlet.http.HttpSession; +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +/** + * 系统--用户表 + * + * @author admin + * @date 2021年10月19日 15:07:06 + */ +@Service +public class SysUserServiceImpl implements ISysUserService { + @Autowired + private ISysUserMapper sysUserMapper; + @Autowired + private IIdWorkerService idWorkerService; + @Autowired + private BCryptPasswordEncoderUtils bCryptPasswordEncoder; + @Autowired + private RedisTemplate redisTemplate; + + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(SysUser req, String operator) { + req.setOperator(operator); + String password = req.getPassword(); + if (StringUtils.isNotBlank(password)) { + req.setPassword(bCryptPasswordEncoder.encode(password)); + } + // 检查用户名 + if (isUsernameExist(req)) { + throw new BusinessException("用户名已存在"); + } + // 检查用户名 + if (isEmailExist(req)) { + throw new BusinessException("邮箱已存在"); + } + // 检查邮箱 + if (null == req.getId()) { + insertSelective(req); + } else { + updateSelectiveById(req); + } + } + + @Override + public int insertSelective(SysUser req) { + req.setId(idWorkerService.getNextId()); + req.setStatus(EnumStatus.NEW.getCode()); + checkStringLength(req, false); + return sysUserMapper.insertSelective(req); + } + + @Override + public int updateSelectiveById(SysUser sysUser) { + WJAssert.notNull(sysUser, "入参对象不能为空"); + WJAssert.notNull(sysUser.getId(), "id参数错误"); + SysUser where = new SysUser(); + where.setId(sysUser.getId()); + return sysUserMapper.updateSelective(sysUser, where); + } + + @Override + public int getCount(SysUser sysUser) { + checkStringLength(sysUser, true); + return sysUserMapper.getCount(sysUser); + } + + @Override + public SysUser getOneById(Long id) { + WJAssert.notNull(id, "id参数错误"); + SysUser where = new SysUser(); + where.setId(id); + return sysUserMapper.getOne(where); + } + + @Override + public List getList(SysUser sysUser) { + checkStringLength(sysUser, true); + return sysUserMapper.getList(sysUser); + } + + @Override + public List getPageList(SysUser sysUser) { + checkStringLength(sysUser, true); + return sysUserMapper.getPageList(sysUser) + .parallelStream() + .peek(item -> { + if (StringUtils.isNotBlank(item.getTag())) { + item.setTagList(Arrays.asList(item.getTag().split(","))); + } + }).collect(Collectors.toList()); + } + + + @Override + public SysUser getExitOneById(Long id) { + WJAssert.notNull(id, "id参数错误"); + SysUser where = new SysUser(); + where.setStatus(EnumStatus.NEW.getCode()); + where.setId(id); + return sysUserMapper.getOne(where); + } + + @Override + public void delete(Long id, String operator) { + SysUser req = new SysUser(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.DEL.getCode()); + updateSelectiveById(req); + } + + @Override + public SysUser login(SysUser sysUserReq, HttpSession webSession) { + WJAssert.limitMaxLength(sysUserReq.getUsername(), false, 100, "用户名不合法!"); + WJAssert.limitMaxLength(sysUserReq.getPassword(), false, 100, "密码不合法!"); + Object code = webSession.getAttribute("verifyCode_" + sysUserReq.getVerifyCode().toUpperCase()); + //验证码判断 + if (code == null) { + throw new BusinessException("验证码错误"); + } + checkLoginErrorNum(sysUserReq.getUsername()); + + SysUser sysUser = new SysUser(); + sysUser.setUsername(sysUserReq.getUsername()); + SysUser sysUserDB = sysUserMapper.getOne(sysUser); + if (Objects.isNull(sysUserDB) || !bCryptPasswordEncoder.matches(sysUserReq.getPassword(), sysUserDB.getPassword())) { + checkLoginErrorNumByUsername(sysUserReq.getUsername()); + throw new BusinessException("账户不存在或密码错误"); + } + if (Objects.equals(sysUserDB.getStatus(), EnumStatus.DEL.getCode())) { + throw new BusinessException("账户已删除"); + } + return sysUserDB; + } + + @Override + public SysUser thirdLogin(String username, String password) { + checkLoginErrorNum(username); + + SysUser sysUser = new SysUser(); + sysUser.setUsername(username); + SysUser sysUserDB = sysUserMapper.getOne(sysUser); + if (Objects.isNull(sysUserDB) || !bCryptPasswordEncoder.matches(password, sysUserDB.getPassword())) { + checkLoginErrorNumByUsername(username); + throw new BusinessException("用户名或密码错误"); + } + if (Objects.equals(sysUserDB.getStatus(), EnumStatus.DEL.getCode())) { + throw new BusinessException("账户已删除"); + } + return sysUserDB; + } + + /** + * 检查错误次数 + * + * @param username + */ + private void checkLoginErrorNum(String username) { + ValueOperations valueOperations = redisTemplate.opsForValue(); + String key = String.format(RedisKeys.SYS_USER_LOGIN_ERROR_NUM, username); + Object errorNumObj = valueOperations.get(key); + if (errorNumObj != null && Integer.parseInt(errorNumObj.toString()) > 4) { + throw new BusinessException("错误次数过多,请过半小时后再试!"); + } + } + + @Override + public void updatePassword(String oldPassword, String newPassword, Long sysUserId) { + SysUser sysUser = new SysUser(); + sysUser.setId(sysUserId); + SysUser sysUserDB = sysUserMapper.getOne(sysUser); + if (Objects.isNull(sysUserDB) || !bCryptPasswordEncoder.matches(oldPassword, sysUserDB.getPassword())) { + throw new BusinessException("旧密码输入有误!"); + } + sysUserDB.setPassword(bCryptPasswordEncoder.encode(newPassword)); + updateSelectiveById(sysUserDB); + } + + /** + * 验证用户登陆错误次数 + * + * @param username + */ + @Override + public void checkLoginErrorNumByUsername(String username) { + String key = String.format(RedisKeys.SYS_USER_LOGIN_ERROR_NUM, username); + ValueOperations valueOperations = redisTemplate.opsForValue(); + Object errorNumObj = valueOperations.get(key); + int errorNum = 1; + if (errorNumObj != null) { + errorNum += Integer.parseInt(errorNumObj.toString()); + } + valueOperations.set(key, String.valueOf(errorNum), 30, TimeUnit.MINUTES); + if (errorNum > 4) { + throw new BusinessException("错误次数过多,请过半小时后再试!"); + } + } + + private boolean isEmailExist(SysUser sysUserReq) { + return getOneByEmail(sysUserReq.getEmail()).map(item -> !item.getId().equals(sysUserReq.getId())).orElse(false); + } + + private Boolean isUsernameExist(SysUser sysUserReq) { + return getOneByUsername(sysUserReq.getUsername()).map(item -> !item.getId().equals(sysUserReq.getId())).orElse(false); + } + + private Optional getOneByUsername(String username) { + SysUser req = new SysUser(); + req.setUsername(username); + return Optional.ofNullable(sysUserMapper.getOne(req)); + } + + private Optional getOneByEmail(String email) { + SysUser req = new SysUser(); + req.setEmail(email); + return Optional.ofNullable(sysUserMapper.getOne(req)); + } + + /** + * 参数校验注解默认使用的方法 + */ + private void checkStringLength(SysUser sysUser, boolean nullAble) { + WJAssert.notNull(sysUser, "入参对象不能为空"); + WJAssert.limitMaxLength(sysUser.getUsername(), nullAble, 100, "用户名不合法!"); + WJAssert.limitMaxLength(sysUser.getPassword(), nullAble, 100, "密码不合法!"); + WJAssert.limitMaxLength(sysUser.getPhone(), true, 20, "手机不合法!"); + WJAssert.limitMaxLength(sysUser.getName(), true, 50, "姓名不合法!"); + WJAssert.limitMaxLength(sysUser.getEmail(), true, 100, "邮箱不合法!"); + WJAssert.limitMaxLength(sysUser.getOperator(), nullAble, 50, "操作人不合法!"); + WJAssert.limitMaxLength(sysUser.getRemark(), true, 255, "备注不合法!"); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/user/IAppUserService.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/user/IAppUserService.java new file mode 100644 index 0000000..e777073 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/user/IAppUserService.java @@ -0,0 +1,101 @@ +package com.arm.equipment.system.data.service.user; + +import com.arm.equipment.system.data.domain.user.AppUser; + +import java.util.List; + +/** + * APP用户 + * + * @author admin + * @date 2023年03月13日 22:34:47 + */ +public interface IAppUserService { + /** + * 保存或更新 + * @param req + */ + void save(AppUser req, String operator); + + /** + * 插入 + * + * @param appUser appUser + * @return int + */ + int insertSelective(AppUser appUser); + + /** + * 主键更新 + * + * @param appUser appUser + * @return int + */ + int updateSelectiveById(AppUser appUser); + + /** + * 数量 + * + * @param appUser appUser + * @return int + */ + int getCount(AppUser appUser); + + /** + * 主键查询 + * + * @param id id + * @return AppUser + */ + AppUser getOneById(Long id); + + /** + * 多条 + * + * @param appUser appUser + * @return List + */ + List getList(AppUser appUser); + + /** + * 分页 + * + * @param appUser appUser + * @return List + */ + List getPageList(AppUser appUser); + + /** + * 审核 + * @param id + * @param operator + */ + void audit(Long id, String operator); + + /** + * 取消审核 + * @param id + * @param operator + */ + void unaudit(Long id, String operator); + + /** + * 删除 + * @param id + * @param operator + */ + void delete(Long id, String operator); + + /** + * 登录 + * @param req + * @return + */ + AppUser login(AppUser req); + + /** + * 注册 + * @param req + */ + void saveUser(AppUser req); +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/user/impl/AppUserServiceImpl.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/user/impl/AppUserServiceImpl.java new file mode 100644 index 0000000..2ef4f1d --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/user/impl/AppUserServiceImpl.java @@ -0,0 +1,172 @@ +package com.arm.equipment.system.data.service.user.impl; + +import com.arm.equipment.system.data.exception.BusinessException; +import com.arm.equipment.system.data.util.WJAssert; +import com.arm.equipment.system.data.enums.dict.EnumStatus; +import com.arm.equipment.system.data.service.common.IIdWorkerService; +import com.arm.equipment.system.data.mapper.user.IAppUserMapper; +import com.arm.equipment.system.data.domain.user.AppUser; +import com.arm.equipment.system.data.service.user.IAppUserService; +import com.arm.equipment.system.data.util.passwordEncoder.BCryptPasswordEncoderUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; +import java.util.Objects; + +/** + * APP用户 + * + * @author admin + * @date 2023年03月13日 22:34:47 + */ +@Service +public class AppUserServiceImpl implements IAppUserService { + @Autowired + private IAppUserMapper appUserMapper; + @Autowired + private IIdWorkerService idWorkerService; + @Autowired + private BCryptPasswordEncoderUtils bCryptPasswordEncoder; + + @Override + public void save(AppUser req, String operator) { + req.setOperator(operator); + if (null == req.getId()) { + insertSelective(req); + } else { + updateSelectiveById(req); + } + } + + @Override + public int insertSelective(AppUser req) { + req.setId(idWorkerService.getNextId()); + req.setStatus(EnumStatus.NEW.getCode()); + checkStringLength(req, false); + return appUserMapper.insertSelective(req); + } + + @Override + public int updateSelectiveById(AppUser appUser) { + WJAssert.notNull(appUser, "入参对象不能为空"); + WJAssert.notNull(appUser.getId(), "id参数错误"); + AppUser where = new AppUser(); + where.setId(appUser.getId()); + return appUserMapper.updateSelective(appUser, where); + } + + @Override + public int getCount(AppUser appUser) { + checkStringLength(appUser, true); + return appUserMapper.getCount(appUser); + } + + + private boolean getCountByPhone(String phone) { + WJAssert.notBlank(phone, "手机号非法"); + AppUser appUser = new AppUser(); + appUser.setPhone(phone); + return appUserMapper.getCount(appUser) > 0; + } + + private boolean getCountByUsername(String username) { + WJAssert.notBlank(username, "用户名非法"); + AppUser appUser = new AppUser(); + appUser.setUsername(username); + return appUserMapper.getCount(appUser) > 0; + } + + @Override + public AppUser getOneById(Long id) { + WJAssert.notNull(id, "id参数错误"); + AppUser where = new AppUser(); + where.setId(id); + return appUserMapper.getOne(where); + } + + @Override + public List getList(AppUser appUser) { + checkStringLength(appUser, true); + return appUserMapper.getList(appUser); + } + + @Override + public List getPageList(AppUser appUser) { + checkStringLength(appUser, true); + return appUserMapper.getPageList(appUser); + } + + @Override + public void audit(Long id, String operator) { + AppUser req = new AppUser(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.AUDIT.getCode()); + updateSelectiveById(req); + } + + @Override + public void unaudit(Long id, String operator) { + AppUser req = new AppUser(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.NEW.getCode()); + updateSelectiveById(req); + } + + @Override + public void delete(Long id, String operator) { + AppUser req = new AppUser(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.DEL.getCode()); + updateSelectiveById(req); + } + + @Override + public AppUser login(AppUser req) { + WJAssert.notBlank(req.getUsername(), "账号非法"); + WJAssert.notBlank(req.getPassword(), "密码非法吗"); + AppUser where = new AppUser(); + where.setUsername(req.getUsername()); + AppUser appUserDB = appUserMapper.getOne(where); + if (Objects.isNull(appUserDB) || !bCryptPasswordEncoder.matches(req.getPassword(), appUserDB.getPassword())) { + throw new BusinessException("账户不存在或密码错误"); + } + appUserDB.setPassword(null); + appUserDB.setLoginTime(new Date()); + updateSelectiveById(appUserDB); + return appUserDB; + } + + @Override + public void saveUser(AppUser req) { + checkStringLength(req, false); + req.setPassword(bCryptPasswordEncoder.encode(req.getPassword())); + // 检查用户名 + if (getCountByPhone(req.getPhone())) { + throw new BusinessException("用户名已存在"); + } + // 检查用户名 + if (getCountByUsername(req.getUsername())) { + throw new BusinessException("登录账号已存在"); + } + req.setId(null); + req.setLoginTime(new Date()); + insertSelective(req); + } + + /** + * 参数校验注解默认使用的方法 + */ + private void checkStringLength(AppUser appUser, boolean nullAble) { + WJAssert.notNull(appUser, "入参对象不能为空"); + WJAssert.limitMaxLength(appUser.getNickname(), nullAble, 50, "用户昵称不合法!"); + WJAssert.limitMaxLength(appUser.getUsername(), nullAble, 20, "登录账号不合法!"); + WJAssert.limitMaxLength(appUser.getPassword(), nullAble, 100, "密码不合法!"); + WJAssert.limitMaxLength(appUser.getPhone(), nullAble, 11, "手机号不合法!"); + WJAssert.limitMaxLength(appUser.getRemark(), true, 255, "备注不合法!"); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/weaponry/IWeaponryLendRecordService.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/weaponry/IWeaponryLendRecordService.java new file mode 100644 index 0000000..fa4d74f --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/weaponry/IWeaponryLendRecordService.java @@ -0,0 +1,107 @@ +package com.arm.equipment.system.data.service.weaponry; + +import com.arm.equipment.system.data.domain.weaponry.WeaponryLendRecord; + +import java.util.List; + +/** + * 装备武器借出记录 + * + * @author admin + * @date 2023年03月23日 09:20:19 + */ +public interface IWeaponryLendRecordService { + /** + * 保存或更新 + * + * @param req + */ + void save(WeaponryLendRecord req, String operator); + + /** + * 插入 + * + * @param weaponryLendRecord weaponryLendRecord + * @return int + */ + int insertSelective(WeaponryLendRecord weaponryLendRecord); + + /** + * 主键更新 + * + * @param weaponryLendRecord weaponryLendRecord + * @return int + */ + int updateSelectiveById(WeaponryLendRecord weaponryLendRecord); + + /** + * 数量 + * + * @param weaponryLendRecord weaponryLendRecord + * @return int + */ + int getCount(WeaponryLendRecord weaponryLendRecord); + + /** + * 主键查询 + * + * @param id id + * @return WeaponryLendRecord + */ + WeaponryLendRecord getOneById(Long id); + + /** + * 多条 + * + * @param weaponryLendRecord weaponryLendRecord + * @return List + */ + List getList(WeaponryLendRecord weaponryLendRecord); + + /** + * 分页 + * + * @param weaponryLendRecord weaponryLendRecord + * @return List + */ + List getPageList(WeaponryLendRecord weaponryLendRecord); + + /** + * 审核拒绝 + * + * @param id + * @param operator + */ + void refuse(Long id, String operator); + + /** + * 审核通过 + * + * @param id + * @param operator + */ + void adopt(Long id, String operator); + + /** + * 删除 + * + * @param id + * @param operator + */ + void delete(Long id, String operator); + + /** + * 借出 + * + * @param req + */ + void saveLend(WeaponryLendRecord req); + + /** + * 获取未归还得总数 + * + * @param weaponryId + * @return + */ + int getCountByWeaponryId(Long weaponryId); +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/weaponry/IWeaponryReturnRecordService.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/weaponry/IWeaponryReturnRecordService.java new file mode 100644 index 0000000..5094597 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/weaponry/IWeaponryReturnRecordService.java @@ -0,0 +1,99 @@ +package com.arm.equipment.system.data.service.weaponry; + +import com.arm.equipment.system.data.domain.weaponry.WeaponryReturnRecord; + +import java.util.List; + +/** + * 装备武器归还记录 + * + * @author admin + * @date 2023年03月23日 09:20:25 + */ +public interface IWeaponryReturnRecordService { + /** + * 保存或更新 + * + * @param req + */ + void save(WeaponryReturnRecord req, String operator); + + /** + * 插入 + * + * @param weaponryReturnRecord weaponryReturnRecord + * @return int + */ + int insertSelective(WeaponryReturnRecord weaponryReturnRecord); + + /** + * 主键更新 + * + * @param weaponryReturnRecord weaponryReturnRecord + * @return int + */ + int updateSelectiveById(WeaponryReturnRecord weaponryReturnRecord); + + /** + * 数量 + * + * @param weaponryReturnRecord weaponryReturnRecord + * @return int + */ + int getCount(WeaponryReturnRecord weaponryReturnRecord); + + /** + * 主键查询 + * + * @param id id + * @return WeaponryReturnRecord + */ + WeaponryReturnRecord getOneById(Long id); + + /** + * 多条 + * + * @param weaponryReturnRecord weaponryReturnRecord + * @return List + */ + List getList(WeaponryReturnRecord weaponryReturnRecord); + + /** + * 分页 + * + * @param weaponryReturnRecord weaponryReturnRecord + * @return List + */ + List getPageList(WeaponryReturnRecord weaponryReturnRecord); + + /** + * 审核 + * + * @param id + * @param operator + */ + void audit(Long id, String operator); + + /** + * 取消审核 + * + * @param id + * @param operator + */ + void unaudit(Long id, String operator); + + /** + * 删除 + * + * @param id + * @param operator + */ + void delete(Long id, String operator); + + /** + * 保存退还记录 + * + * @param lendRecordId + */ + void saveReturn(Long lendRecordId); +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/weaponry/IWeaponryService.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/weaponry/IWeaponryService.java new file mode 100644 index 0000000..fc31ffb --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/weaponry/IWeaponryService.java @@ -0,0 +1,88 @@ +package com.arm.equipment.system.data.service.weaponry; + +import com.arm.equipment.system.data.domain.weaponry.Weaponry; + +import java.util.List; + +/** + * 装备武器 + * + * @author admin + * @date 2023年03月23日 10:29:48 + */ +public interface IWeaponryService { + /** + * 保存或更新 + * @param req + */ + void save(Weaponry req, String operator); + + /** + * 插入 + * + * @param weaponry weaponry + * @return int + */ + int insertSelective(Weaponry weaponry); + + /** + * 主键更新 + * + * @param weaponry weaponry + * @return int + */ + int updateSelectiveById(Weaponry weaponry); + + /** + * 数量 + * + * @param weaponry weaponry + * @return int + */ + int getCount(Weaponry weaponry); + + /** + * 主键查询 + * + * @param id id + * @return Weaponry + */ + Weaponry getOneById(Long id); + + /** + * 多条 + * + * @param weaponry weaponry + * @return List + */ + List getList(Weaponry weaponry); + + /** + * 分页 + * + * @param weaponry weaponry + * @return List + */ + List getPageList(Weaponry weaponry); + + /** + * 审核 + * @param id + * @param operator + */ + void audit(Long id, String operator); + + /** + * 取消审核 + * @param id + * @param operator + */ + void unaudit(Long id, String operator); + + /** + * 删除 + * @param id + * @param operator + */ + void delete(Long id, String operator); +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/weaponry/impl/WeaponryLendRecordServiceImpl.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/weaponry/impl/WeaponryLendRecordServiceImpl.java new file mode 100644 index 0000000..51bffa0 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/weaponry/impl/WeaponryLendRecordServiceImpl.java @@ -0,0 +1,181 @@ +package com.arm.equipment.system.data.service.weaponry.impl; + +import com.arm.equipment.system.data.domain.weaponry.Weaponry; +import com.arm.equipment.system.data.domain.weaponry.WeaponryLendRecord; +import com.arm.equipment.system.data.enums.dict.EnumStatus; +import com.arm.equipment.system.data.enums.dict.EnumWeaponryLendRecordReturnStatus; +import com.arm.equipment.system.data.enums.dict.EnumWeaponryLendRecordStatus; +import com.arm.equipment.system.data.exception.BusinessException; +import com.arm.equipment.system.data.mapper.weaponry.IWeaponryLendRecordMapper; +import com.arm.equipment.system.data.service.common.IIdWorkerService; +import com.arm.equipment.system.data.service.weaponry.IWeaponryLendRecordService; +import com.arm.equipment.system.data.service.weaponry.IWeaponryService; +import com.arm.equipment.system.data.util.WJAssert; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * 装备武器借出记录 + * + * @author admin + * @date 2023年03月23日 09:20:19 + */ +@Service +public class WeaponryLendRecordServiceImpl implements IWeaponryLendRecordService { + @Autowired + private IWeaponryLendRecordMapper weaponryLendRecordMapper; + @Autowired + private IIdWorkerService idWorkerService; + @Autowired + private IWeaponryService weaponryService; + + @Override + public void save(WeaponryLendRecord req, String operator) { + req.setOperator(operator); + if (null == req.getId()) { + insertSelective(req); + } else { + updateSelectiveById(req); + } + } + + @Override + public int insertSelective(WeaponryLendRecord req) { + req.setId(idWorkerService.getNextId()); + req.setStatus(EnumStatus.NEW.getCode()); + checkStringLength(req, false); + return weaponryLendRecordMapper.insertSelective(req); + } + + @Override + public int updateSelectiveById(WeaponryLendRecord weaponryLendRecord) { + WJAssert.notNull(weaponryLendRecord, "入参对象不能为空"); + WJAssert.notNull(weaponryLendRecord.getId(), "id参数错误"); + WeaponryLendRecord where = new WeaponryLendRecord(); + where.setId(weaponryLendRecord.getId()); + return weaponryLendRecordMapper.updateSelective(weaponryLendRecord, where); + } + + @Override + public int getCount(WeaponryLendRecord weaponryLendRecord) { + checkStringLength(weaponryLendRecord, true); + return weaponryLendRecordMapper.getCount(weaponryLendRecord); + } + + @Override + public WeaponryLendRecord getOneById(Long id) { + WJAssert.notNull(id, "id参数错误"); + WeaponryLendRecord where = new WeaponryLendRecord(); + where.setId(id); + return weaponryLendRecordMapper.getOne(where); + } + + @Override + public List getList(WeaponryLendRecord weaponryLendRecord) { + checkStringLength(weaponryLendRecord, true); + return weaponryLendRecordMapper.getList(weaponryLendRecord); + } + + @Override + public List getPageList(WeaponryLendRecord weaponryLendRecord) { + checkStringLength(weaponryLendRecord, true); + return weaponryLendRecordMapper.getPageList(weaponryLendRecord) + .parallelStream() + .peek(item -> { + Weaponry weaponryDB = weaponryService.getOneById(item.getWeaponryId()); + item.setWeaponry(weaponryDB); + }).collect(Collectors.toList()); + } + + /** + * 拒绝 + * + * @param id + * @param operator + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void refuse(Long id, String operator) { + WeaponryLendRecord req = new WeaponryLendRecord(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumWeaponryLendRecordStatus.REFUSE.getCode()); + updateSelectiveById(req); + + //拒绝通过 归还锁定库存 + WeaponryLendRecord weaponryLendRecordDB = getOneById(id); + Weaponry weaponryDB = weaponryService.getOneById(weaponryLendRecordDB.getWeaponryId()); + weaponryDB.setLockInventory(weaponryDB.getLockInventory() - weaponryLendRecordDB.getNum()); + weaponryService.updateSelectiveById(weaponryDB); + + } + + /** + * 通过 + * + * @param id + * @param operator + */ + @Override + public void adopt(Long id, String operator) { + WeaponryLendRecord req = new WeaponryLendRecord(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumWeaponryLendRecordStatus.ADOPT.getCode()); + updateSelectiveById(req); + } + + @Override + public void delete(Long id, String operator) { + WeaponryLendRecord req = new WeaponryLendRecord(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.DEL.getCode()); + updateSelectiveById(req); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void saveLend(WeaponryLendRecord req) { + WJAssert.notNull(req.getNum(), "数量非法"); + WJAssert.notNull(req.getReturnTime(), "归还时间非法"); + WJAssert.notNull(req.getWeaponryId(), "装备非法"); + if (req.getNum() < 0) { + throw new BusinessException("数量非法"); + } + Weaponry weaponryDB = Optional.ofNullable(weaponryService.getOneById(req.getWeaponryId())) + .orElseThrow(() -> new BusinessException("装备不存在")); + //剩余库存 = 总库存 - 锁定库存 + if ((weaponryDB.getTotalInventory() - weaponryDB.getLockInventory()) < req.getNum()) { + throw new BusinessException("库存不足"); + } + req.setWeaponryName(weaponryDB.getName()); + insertSelective(req); + + //增加锁定库存 + weaponryDB.setLockInventory(weaponryDB.getLockInventory() + req.getNum()); + weaponryService.updateSelectiveById(weaponryDB); + } + + @Override + public int getCountByWeaponryId(Long weaponryId) { + WeaponryLendRecord where = new WeaponryLendRecord(); + where.setWeaponryId(weaponryId); + where.setReturnStatus(EnumWeaponryLendRecordReturnStatus.NOT_RETURN.getCode()); + where.setStatus(EnumWeaponryLendRecordStatus.ADOPT.getCode()); + return getCount(where); + } + + /** + * 参数校验注解默认使用的方法 + */ + private void checkStringLength(WeaponryLendRecord weaponryLendRecord, boolean nullAble) { + WJAssert.notNull(weaponryLendRecord, "入参对象不能为空"); + WJAssert.limitMaxLength(weaponryLendRecord.getRemark(), true, 255, "备注不合法!"); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/weaponry/impl/WeaponryReturnRecordServiceImpl.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/weaponry/impl/WeaponryReturnRecordServiceImpl.java new file mode 100644 index 0000000..e9a90c3 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/weaponry/impl/WeaponryReturnRecordServiceImpl.java @@ -0,0 +1,162 @@ +package com.arm.equipment.system.data.service.weaponry.impl; + +import com.arm.equipment.system.data.domain.weaponry.Weaponry; +import com.arm.equipment.system.data.domain.weaponry.WeaponryLendRecord; +import com.arm.equipment.system.data.domain.weaponry.WeaponryReturnRecord; +import com.arm.equipment.system.data.enums.dict.EnumStatus; +import com.arm.equipment.system.data.enums.dict.EnumWeaponryLendRecordReturnStatus; +import com.arm.equipment.system.data.enums.dict.EnumWeaponryLendRecordStatus; +import com.arm.equipment.system.data.exception.BusinessException; +import com.arm.equipment.system.data.mapper.weaponry.IWeaponryReturnRecordMapper; +import com.arm.equipment.system.data.service.common.IIdWorkerService; +import com.arm.equipment.system.data.service.weaponry.IWeaponryLendRecordService; +import com.arm.equipment.system.data.service.weaponry.IWeaponryReturnRecordService; +import com.arm.equipment.system.data.service.weaponry.IWeaponryService; +import com.arm.equipment.system.data.util.WJAssert; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * 装备武器归还记录 + * + * @author admin + * @date 2023年03月23日 09:20:25 + */ +@Service +public class WeaponryReturnRecordServiceImpl implements IWeaponryReturnRecordService { + @Autowired + private IWeaponryReturnRecordMapper weaponryReturnRecordMapper; + @Autowired + private IIdWorkerService idWorkerService; + @Autowired + private IWeaponryLendRecordService weaponryLendRecordService; + @Autowired + private IWeaponryService weaponryService; + + @Override + public void save(WeaponryReturnRecord req, String operator) { + req.setOperator(operator); + if (null == req.getId()) { + insertSelective(req); + } else { + updateSelectiveById(req); + } + } + + @Override + public int insertSelective(WeaponryReturnRecord req) { + req.setId(idWorkerService.getNextId()); + req.setStatus(EnumStatus.NEW.getCode()); + checkStringLength(req, false); + return weaponryReturnRecordMapper.insertSelective(req); + } + + @Override + public int updateSelectiveById(WeaponryReturnRecord weaponryReturnRecord) { + WJAssert.notNull(weaponryReturnRecord, "入参对象不能为空"); + WJAssert.notNull(weaponryReturnRecord.getId(), "id参数错误"); + WeaponryReturnRecord where = new WeaponryReturnRecord(); + where.setId(weaponryReturnRecord.getId()); + return weaponryReturnRecordMapper.updateSelective(weaponryReturnRecord, where); + } + + @Override + public int getCount(WeaponryReturnRecord weaponryReturnRecord) { + checkStringLength(weaponryReturnRecord, true); + return weaponryReturnRecordMapper.getCount(weaponryReturnRecord); + } + + @Override + public WeaponryReturnRecord getOneById(Long id) { + WJAssert.notNull(id, "id参数错误"); + WeaponryReturnRecord where = new WeaponryReturnRecord(); + where.setId(id); + return weaponryReturnRecordMapper.getOne(where); + } + + @Override + public List getList(WeaponryReturnRecord weaponryReturnRecord) { + checkStringLength(weaponryReturnRecord, true); + return weaponryReturnRecordMapper.getList(weaponryReturnRecord); + } + + @Override + public List getPageList(WeaponryReturnRecord weaponryReturnRecord) { + checkStringLength(weaponryReturnRecord, true); + return weaponryReturnRecordMapper.getPageList(weaponryReturnRecord) + .parallelStream() + .peek(item -> { + Weaponry weaponryDB = weaponryService.getOneById(item.getWeaponryId()); + item.setWeaponry(weaponryDB); + }).collect(Collectors.toList()); + } + + @Override + public void audit(Long id, String operator) { + WeaponryReturnRecord req = new WeaponryReturnRecord(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.AUDIT.getCode()); + updateSelectiveById(req); + } + + @Override + public void unaudit(Long id, String operator) { + WeaponryReturnRecord req = new WeaponryReturnRecord(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.NEW.getCode()); + updateSelectiveById(req); + } + + @Override + public void delete(Long id, String operator) { + WeaponryReturnRecord req = new WeaponryReturnRecord(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.DEL.getCode()); + updateSelectiveById(req); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void saveReturn(Long lendRecordId) { + WJAssert.notNull(lendRecordId, "ID非法"); + WeaponryLendRecord weaponryLendRecordDB = Optional.ofNullable(weaponryLendRecordService.getOneById(lendRecordId)) + .orElseThrow(() -> new BusinessException("借出记录不存在")); + if (!EnumWeaponryLendRecordStatus.ADOPT.getCode().equals(weaponryLendRecordDB.getStatus()) + || !EnumWeaponryLendRecordReturnStatus.NOT_RETURN.getCode().equals(weaponryLendRecordDB.getReturnStatus())) { + throw new BusinessException("数据非法"); + } + WeaponryReturnRecord req = new WeaponryReturnRecord(); + req.setWeaponryId(weaponryLendRecordDB.getWeaponryId()); + req.setLendRecordId(weaponryLendRecordDB.getId()); + req.setNum(weaponryLendRecordDB.getNum()); + req.setReturnTime(weaponryLendRecordDB.getReturnTime()); + req.setWeaponryName(weaponryLendRecordDB.getWeaponryName()); + insertSelective(req); + + //修改借出归还状态 + weaponryLendRecordDB.setReturnStatus(EnumWeaponryLendRecordReturnStatus.RETURN.getCode()); + weaponryLendRecordService.updateSelectiveById(weaponryLendRecordDB); + + //扣除锁定库存 + Weaponry weaponryDB = Optional.ofNullable(weaponryService.getOneById(weaponryLendRecordDB.getWeaponryId())) + .orElseThrow(() -> new BusinessException("武器不存在")); + weaponryDB.setLockInventory(weaponryDB.getLockInventory() - weaponryLendRecordDB.getNum()); + weaponryService.updateSelectiveById(weaponryDB); + } + + /** + * 参数校验注解默认使用的方法 + */ + private void checkStringLength(WeaponryReturnRecord weaponryReturnRecord, boolean nullAble) { + WJAssert.notNull(weaponryReturnRecord, "入参对象不能为空"); + WJAssert.limitMaxLength(weaponryReturnRecord.getRemark(), true, 255, "备注不合法!"); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/weaponry/impl/WeaponryServiceImpl.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/weaponry/impl/WeaponryServiceImpl.java new file mode 100644 index 0000000..2ae92ee --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/service/weaponry/impl/WeaponryServiceImpl.java @@ -0,0 +1,117 @@ +package com.arm.equipment.system.data.service.weaponry.impl; + +import com.arm.equipment.system.data.enums.dict.EnumStatus; +import com.arm.equipment.system.data.util.WJAssert; +import com.arm.equipment.system.data.service.common.IIdWorkerService; +import com.arm.equipment.system.data.mapper.weaponry.IWeaponryMapper; +import com.arm.equipment.system.data.domain.weaponry.Weaponry; +import com.arm.equipment.system.data.service.weaponry.IWeaponryService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 装备武器 + * + * @author admin + * @date 2023年03月23日 10:29:48 + */ +@Service +public class WeaponryServiceImpl implements IWeaponryService { + @Autowired + private IWeaponryMapper weaponryMapper; + @Autowired + private IIdWorkerService idWorkerService; + + @Override + public void save(Weaponry req, String operator) { + req.setOperator(operator); + if (null == req.getId()) { + insertSelective(req); + } else { + updateSelectiveById(req); + } + } + + @Override + public int insertSelective(Weaponry req) { + req.setId(idWorkerService.getNextId()); + req.setStatus(EnumStatus.NEW.getCode()); + checkStringLength(req, false); + return weaponryMapper.insertSelective(req); + } + + @Override + public int updateSelectiveById(Weaponry weaponry) { + WJAssert.notNull(weaponry, "入参对象不能为空"); + WJAssert.notNull(weaponry.getId(), "id参数错误"); + Weaponry where = new Weaponry(); + where.setId(weaponry.getId()); + return weaponryMapper.updateSelective(weaponry, where); + } + + @Override + public int getCount(Weaponry weaponry) { + checkStringLength(weaponry, true); + return weaponryMapper.getCount(weaponry); + } + + @Override + public Weaponry getOneById(Long id) { + WJAssert.notNull(id, "id参数错误"); + Weaponry where = new Weaponry(); + where.setId(id); + return weaponryMapper.getOne(where); + } + + @Override + public List getList(Weaponry weaponry) { + checkStringLength(weaponry, true); + return weaponryMapper.getList(weaponry); + } + + @Override + public List getPageList(Weaponry weaponry) { + checkStringLength(weaponry, true); + return weaponryMapper.getPageList(weaponry); + } + + @Override + public void audit(Long id, String operator) { + Weaponry req = new Weaponry(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.AUDIT.getCode()); + updateSelectiveById(req); + } + + @Override + public void unaudit(Long id, String operator) { + Weaponry req = new Weaponry(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.NEW.getCode()); + updateSelectiveById(req); + } + + @Override + public void delete(Long id, String operator) { + Weaponry req = new Weaponry(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.DEL.getCode()); + updateSelectiveById(req); + } + + /** + * 参数校验注解默认使用的方法 + */ + private void checkStringLength(Weaponry weaponry, boolean nullAble) { + WJAssert.notNull(weaponry, "入参对象不能为空"); + WJAssert.limitMaxLength(weaponry.getName(), nullAble, 50, "武器名称不合法!"); + WJAssert.limitMaxLength(weaponry.getImgPath(), nullAble, 200, "武器封面不合法!"); + WJAssert.limitMaxLength(weaponry.getRemark(), true, 255, "备注不合法!"); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/AesUtil.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/AesUtil.java new file mode 100644 index 0000000..d67e9e7 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/AesUtil.java @@ -0,0 +1,80 @@ +package com.arm.equipment.system.data.util; + +import org.bouncycastle.util.encoders.Hex; +import sun.misc.BASE64Decoder; + +import javax.crypto.Cipher; +import javax.crypto.spec.SecretKeySpec; + +/** + * Aes 加密/解密工具类 + */ +public class AesUtil { + + private static final String ALGORITHM = "AES"; + private static final String TRANSFORMATION = "AES/ECB/PKCS5Padding"; + + + public String encrypt(String input, String key) { + byte[] decodeKey = Hex.decode(key); + byte[] crypted = null; + try { + SecretKeySpec skey = new SecretKeySpec(decodeKey, ALGORITHM); + Cipher cipher = Cipher.getInstance(TRANSFORMATION); + cipher.init(Cipher.ENCRYPT_MODE, skey); + crypted = cipher.doFinal(input.getBytes()); + } catch (Exception e) { + System.out.println(e.toString()); + } + return parseByte2HexStr(crypted); + + } + + /** + * 解密 + * + * @param content 原文 + * @param key 安全key + * @param platform 平台 @see EnumPlatform + * @return + * @throws Exception + */ + public static String decrypt(String content, String key, Integer platform) throws Exception { + content = new String(new BASE64Decoder().decodeBuffer(content)); + Cipher cipher = Cipher.getInstance(TRANSFORMATION); + byte[] keyBytes = key.getBytes(); + SecretKeySpec sk = new SecretKeySpec(keyBytes, "AES"); + //7.初始化密码器,第一个参数为加密(Encrypt_mode)或者解密(Decrypt_mode)操作,第二个参数为使用的KEY + cipher.init(Cipher.DECRYPT_MODE, sk); + byte[] bytes = parseHexStr2Byte(content); + byte[] decode = cipher.doFinal(bytes); + return new String(decode, "utf-8"); + } + + private static byte[] parseHexStr2Byte(String hexStr) { + if (hexStr.length() < 1) { + return null; + } + byte[] result = new byte[hexStr.length() / 2]; + for (int i = 0; i < hexStr.length() / 2; i++) { + int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16); + int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16); + result[i] = (byte) (high * 16 + low); + } + return result; + + } + + private static String parseByte2HexStr(byte buf[]) { + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < buf.length; i++) { + String hex = Integer.toHexString(buf[i] & 0xFF); + if (hex.length() == 1) { + hex = '0' + hex; + } + sb.append(hex.toUpperCase()); + } + return sb.toString(); + + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/BeanUtil.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/BeanUtil.java new file mode 100644 index 0000000..97d2dd4 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/BeanUtil.java @@ -0,0 +1,33 @@ +package com.arm.equipment.system.data.util; + +import org.springframework.beans.BeanWrapper; +import org.springframework.beans.BeanWrapperImpl; + +import java.util.HashSet; +import java.util.Set; + +/** + * @author admin + */ +public class BeanUtil { + + /** + * 获得对象里是null的属性 + * @param source + * @return + */ + 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); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/DATAUtil.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/DATAUtil.java new file mode 100644 index 0000000..556579d --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/DATAUtil.java @@ -0,0 +1,67 @@ +package com.arm.equipment.system.data.util; + +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.JdbcTemplate; + +import java.util.UUID; + +/** + * 基础数据单元 + * + * Update by xy on 2017/4/27. + */ +public class DATAUtil { + + /** + * 获得查询分页总页数 + * + * @param sql + * @param jdbcTemplate + * @param pageSize + * @return + */ + public static final int getPageCount(String sql, JdbcTemplate jdbcTemplate, int pageSize, Object... objects) { + try { + Integer totalCount = jdbcTemplate.queryForObject(sql, objects, Integer.class); + int pageCount = (totalCount - 1) / pageSize; + return pageCount + 1; + } catch (DataAccessException e) { + return 0; + } + } + + /** + * 获取页总数 + * @param totalCount + * @param pageSize + * @return + */ + public static int getPageCount(int totalCount, int pageSize) { + int pageCount = (totalCount - 1) / pageSize; + return pageCount + 1; + } + + /** + * 获取UUID + * + * @return + */ + public static String uuid() { + return UUID.randomUUID().toString().replace("-", ""); + } + + /** + * 生成六位随机数 + * + * @return + */ + public static String getCode() { + String code = Math.round(Math.random() * 1000000) + ""; + if (code.length() < 6) { + code = ((1+ Math.round(Math.random())) * 100000) +""; + //生成一个以1开头的6位数 + } + code = code.substring(0,6);//防止第一次生成code时,round方法对六个9四舍五入导致可能超过6位的情况 + return code; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/DateUtils.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/DateUtils.java new file mode 100644 index 0000000..571f585 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/DateUtils.java @@ -0,0 +1,343 @@ +package com.arm.equipment.system.data.util; + +import org.apache.commons.lang.time.DateFormatUtils; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +/** + * 日期工具类, 继承org.apache.commons.lang.time.DateUtils类 + */ +public class DateUtils extends org.apache.commons.lang.time.DateUtils { + /** + * 中文月份数组 + */ + public static final String[] NUM_ARRAY = {"一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"}; + + private static String[] parsePatterns = { + "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM", + "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM", + "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM", + "yyyy-MM-dd HH"}; + + /** + * 得到当前日期字符串 格式(yyyy-MM-dd) + */ + public static String getDate() { + return getDate("yyyy-MM-dd"); + } + + /** + * 得到当前日期字符串 格式(yyyy-MM-dd) pattern可以为:"yyyy-MM-dd" "HH:mm:ss" "E" + */ + public static String getDate(String pattern) { + return DateFormatUtils.format(new Date(), pattern); + } + + /** + * 得到日期字符串 默认格式(yyyy-MM-dd) pattern可以为:"yyyy-MM-dd" "HH:mm:ss" "E" + */ + public static String formatDate(Date date, Object... pattern) { + String formatDate = null; + if (pattern != null && pattern.length > 0) { + formatDate = DateFormatUtils.format(date, pattern[0].toString()); + } else { + formatDate = DateFormatUtils.format(date, "yyyy-MM-dd"); + } + return formatDate; + } + + /** + * 得到日期时间字符串,转换格式(yyyy-MM-dd HH:mm:ss) + */ + public static String formatDateTime(Date date) { + return formatDate(date, "yyyy-MM-dd HH:mm:ss"); + } + + /** + * 得到当前时间字符串 格式(HH:mm:ss) + */ + public static String getTime() { + return formatDate(new Date(), "HH:mm:ss"); + } + + /** + * 得到当前日期和时间字符串 格式(yyyy-MM-dd HH:mm:ss) + */ + public static String getDateTime() { + return formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"); + } + + /** + * 得到当前年份字符串 格式(yyyy) + */ + public static String getYear() { + return formatDate(new Date(), "yyyy"); + } + + /** + * 得到当前月份字符串 格式(MM) + */ + public static String getMonth() { + return formatDate(new Date(), "MM"); + } + + /** + * 得到当天字符串 格式(dd) + */ + public static String getDay() { + return formatDate(new Date(), "dd"); + } + + /** + * 得到当前星期字符串 格式(E)星期几 + */ + public static String getWeek() { + return formatDate(new Date(), "E"); + } + + /** + * 日期型字符串转化为日期 格式 + * { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", + * "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", + * "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm" } + */ + public static Date parseDate(Object str) { + if (str == null) { + return null; + } + try { + return parseDate(str.toString(), parsePatterns); + } catch (ParseException e) { + return null; + } + } + + /** + * 获取过去的天数 + * + * @param date + * @return + */ + public static long pastDays(Date date) { + long t = new Date().getTime() - date.getTime(); + return t / (24 * 60 * 60 * 1000); + } + + /** + * 获取过去的小时 + * + * @param date + * @return + */ + public static long pastHour(Date date) { + long t = new Date().getTime() - date.getTime(); + return t / (60 * 60 * 1000); + } + + /** + * 获取过去的分钟 + * + * @param date + * @return + */ + public static long pastMinutes(Date date) { + long t = new Date().getTime() - date.getTime(); + return t / (60 * 1000); + } + + /** + * 转换为时间(天,时:分:秒.毫秒) + * + * @param timeMillis + * @return + */ + public static String formatDateTime(long timeMillis) { + long day = timeMillis / (24 * 60 * 60 * 1000); + long hour = (timeMillis / (60 * 60 * 1000) - day * 24); + long min = ((timeMillis / (60 * 1000)) - day * 24 * 60 - hour * 60); + long s = (timeMillis / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60); + long sss = (timeMillis - day * 24 * 60 * 60 * 1000 - hour * 60 * 60 * 1000 - min * 60 * 1000 - s * 1000); + return (day > 0 ? day + "," : "") + hour + ":" + min + ":" + s + "." + sss; + } + + /** + * 获取两个日期之间的天数 + * + * @param before + * @param after + * @return + */ + public static double getDistanceOfTwoDate(Date before, Date after) { + long beforeTime = before.getTime(); + long afterTime = after.getTime(); + return (afterTime - beforeTime) / (1000 * 60 * 60 * 24); + } + + /** + * 获取在当前时间往后增加指定天数的Date + * + * @param appendDay + * @return + */ + public static Date addAppendDay(int appendDay) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + Date dt = new Date(); + Calendar rightNow = Calendar.getInstance(); + rightNow.setTime(dt); + rightNow.add(Calendar.DAY_OF_YEAR, appendDay); + return rightNow.getTime(); + } + + /** + * 获取日期的零点时间 + * + * @param date + * @return + */ + public static Date getStartTimeOfDate(Date date) { + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + cal.set(Calendar.HOUR_OF_DAY, 0); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); + cal.set(Calendar.MILLISECOND, 0); + return cal.getTime(); + } + + /** + * 获取日期的23:59:59:999 + * + * @param date + * @return + */ + public static Date getEndTimeOfDate(Date date) { + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + cal.set(Calendar.HOUR_OF_DAY, 23); + cal.set(Calendar.MINUTE, 59); + cal.set(Calendar.SECOND, 59); + cal.set(Calendar.MILLISECOND, 999); + return cal.getTime(); + } + + /** + * 获取昨天日期时间 + * + * @return + */ + public static Date getYesterdayDateTime() { + Calendar cal = Calendar.getInstance(); + cal.add(5, -1); + return cal.getTime(); + } + + /** + * 根据开始时间和结束时间返回时间段内的时间集合 + * + * @param beginDate + * @param endDate + * @return List + */ + public static List getDatesBetweenTwoDate(Date beginDate, Date endDate) { + if (beginDate.getTime() >= endDate.getTime()) { + throw new RuntimeException("endDate must after beginDate ..."); + } + List lDate = new ArrayList(); + lDate.add(beginDate);// 把开始时间加入集合 + Calendar cal = Calendar.getInstance(); + // 使用给定的 Date 设置此 Calendar 的时间 + cal.setTime(beginDate); + boolean bContinue = true; + while (bContinue) { + // 根据日历的规则,为给定的日历字段添加或减去指定的时间量 + cal.add(Calendar.DAY_OF_MONTH, 1); + // 测试此日期是否在指定日期之后 + if (endDate.after(cal.getTime())) { + lDate.add(cal.getTime()); + } else { + break; + } + } + lDate.add(endDate);// 把结束时间加入集合 + return lDate; + } + + /** + * 取得昨天0点整时间 + * + * @return + */ + public static Date getYesterDayZEROTIME() { + return getSpecifiedDay(-1, 0, 0, 0); + } + + + /** + * 获得指定 + * + * @param day 整数,指定一月中的某天,正数为未来某天时间,负数为过去某天时间 + * @param hour 正整数,一天当中的指定小时数 + * @param minute 正整数,指定分钟数 + * @param second 正整数,指定秒数 + * @return + */ + public static Date getSpecifiedDay(int day, int hour, int minute, int second) { + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + day); + calendar.set(Calendar.HOUR_OF_DAY, hour); + calendar.set(Calendar.MINUTE, minute); + calendar.set(Calendar.SECOND, second); + calendar.set(Calendar.MILLISECOND, 0); + return calendar.getTime(); + } + + /** + * 取得今天0点整时间 + * + * @return + */ + public static Date getZEROTIME() { + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + calendar.set(Calendar.MILLISECOND, 0); + return calendar.getTime(); + } + + /** + * /** + * 获取当前时间前n个小时德开始与结束后时间 + * + * @param type 0 开始 1结束 + * @param n n个小时 + * @return + */ + public static Date getDateBeforeOneHour(Date date, int type, int n) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - n); + String dateStr = formatDate(calendar.getTime(), "yyyy-MM-dd HH"); + if (type == 1) { + return parseDate(dateStr + ":59:59"); + } + return parseDate(dateStr + ":00:00"); + } + + /** + * 获取指定时间的当前小时 + * + * @param date + * @return + */ + public static int getHourByDate(Date date) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + return calendar.get(Calendar.HOUR_OF_DAY); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/EasyExcelListener.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/EasyExcelListener.java new file mode 100644 index 0000000..85acd99 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/EasyExcelListener.java @@ -0,0 +1,32 @@ +package com.arm.equipment.system.data.util; + +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; +import com.alibaba.excel.metadata.BaseRowModel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; + +public class EasyExcelListener extends AnalysisEventListener { + + private final static Logger logger = LoggerFactory.getLogger(EasyExcelListener.class); + + private final List rows = new ArrayList<>(); + + @Override + public void invoke(T object, AnalysisContext context) { + rows.add(object); + } + + @Override + public void doAfterAllAnalysed(AnalysisContext context) { + logger.info("read {} rows %n", rows.size()); + } + + public List getRows() { + logger.info("read {} rows %n", rows); + return rows; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/EnvUtil.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/EnvUtil.java new file mode 100644 index 0000000..3b90625 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/EnvUtil.java @@ -0,0 +1,60 @@ +package com.arm.equipment.system.data.util; + +import org.springframework.context.EnvironmentAware; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; + +/** + * 判断当前系统运行环境 + */ +@Component +public class EnvUtil implements EnvironmentAware { + /** 系统环境 */ + private static Environment environment; + + /** + * 判断是否开发环境 + * @return + */ + public static boolean isDev() { + return isEnv("dev"); + } + + /** + * 判断是否测试环境 + * @return + */ + public static boolean isTest() { + return isEnv("test"); + } + + /** + * 判断是否生产环境 + * @return + */ + public static boolean isProd() { + return isEnv("prod"); + } + + /** + * 判断是否激活某个profile + * @param env + * @return + */ + private static boolean isEnv(String env) { + return environment.getProperty("env").equalsIgnoreCase(env); + } + + public static String getEnv() { + return environment.getProperty("env"); + } + + @Override + public void setEnvironment(Environment environment) { + EnvUtil.environment = environment; + } + + public static boolean isESEnable() { + return true; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/FileUtils.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/FileUtils.java new file mode 100644 index 0000000..234126a --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/FileUtils.java @@ -0,0 +1,115 @@ +package com.arm.equipment.system.data.util; + +import com.arm.equipment.system.data.exception.BusinessException; +import org.apache.commons.lang3.StringUtils; +import org.springframework.util.CollectionUtils; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.net.URLConnection; +import java.nio.ByteBuffer; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.nio.channels.WritableByteChannel; +import java.util.Map; + +/** + * 文件工具类 + * @author admin + */ +public class FileUtils { + + /** + * 获得文件的扩展名 + * @param fileName + * @return + */ + public static String getSuffix(String fileName) { + if (StringUtils.isEmpty(fileName)) { + return ""; + } + return fileName.substring(fileName.lastIndexOf(".")); + } + + /** + * 获得路径中包含后缀的文件名 + * @param path 文件路径 + * @return + */ + public static String getFileName(String path) { + return path.substring(path.lastIndexOf("/")); + } + + public static String getFileNameWithoutSuffix(String path) { + if (StringUtils.isEmpty(path)) { + throw new BusinessException("文件路径非法"); + } + // 有些人上传文件没有后缀 + if (!path.contains(".")) { + return path; + } + return path.substring(0, path.lastIndexOf(".")); + } + + /** + * 获得远程路径文件的字节码 + * @param url + * @return + * @throws IOException + */ + public static byte[] getUrlBytes(String url) throws IOException { + WJAssert.hasLength(url, "URL不合法"); + WJAssert.isTrue(url.contains("http"), "URL没有协议"); + URL requestUrl = new URL(url); + InputStream inputStream = requestUrl.openStream(); + ReadableByteChannel src = Channels.newChannel(inputStream); + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + WritableByteChannel dest = Channels.newChannel(byteArrayOutputStream); + ByteBuffer buffer = ByteBuffer.allocate(10240); + while (src.read(buffer) != -1) { + buffer.flip(); + while (buffer.hasRemaining()) { + dest.write(buffer); + } + buffer.clear(); + } + inputStream.close(); + src.close(); + dest.close(); + byteArrayOutputStream.close(); + return byteArrayOutputStream.toByteArray(); + } + + /** + * 获得远程路径的字节码 + * @param url + * @param header + * @return + * @throws IOException + */ + public static byte[] getUrlBytes(String url, Map header) throws IOException { + URLConnection requestUrl = new URL(url).openConnection(); + if(!CollectionUtils.isEmpty(header)) { + header.forEach((k, v) -> requestUrl.setRequestProperty(k, v)); + } + InputStream inputStream = requestUrl.getInputStream(); + ReadableByteChannel src = Channels.newChannel(inputStream); + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + WritableByteChannel dest = Channels.newChannel(byteArrayOutputStream); + ByteBuffer buffer = ByteBuffer.allocate(10240); + while (src.read(buffer) != -1) { + buffer.flip(); + while (buffer.hasRemaining()) { + dest.write(buffer); + } + buffer.clear(); + } + inputStream.close(); + src.close(); + dest.close(); + byteArrayOutputStream.close(); + return byteArrayOutputStream.toByteArray(); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/IPUtil.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/IPUtil.java new file mode 100644 index 0000000..3fbdc8b --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/IPUtil.java @@ -0,0 +1,121 @@ +package com.arm.equipment.system.data.util; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.http.HttpHeaders; +import org.springframework.util.CollectionUtils; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; +import java.util.Map; + +/** + * ip工具类 + */ +public class IPUtil { + + private static final String IP_UTILS_FLAG = ","; + + /** + * 获得用户远程地址 + */ + public static String getRemoteAddress(HttpHeaders headers) { + List remoteAddrList = headers.get("X-Real-IP"); + if (CollectionUtils.isEmpty(remoteAddrList)) { + remoteAddrList = headers.get("X-Forwarded-For"); + } else if (CollectionUtils.isEmpty(remoteAddrList)) { + remoteAddrList = headers.get("Proxy-Client-IP"); + } else if (CollectionUtils.isEmpty(remoteAddrList)) { + remoteAddrList = headers.get("WL-Proxy-Client-IP"); + } + if (CollectionUtils.isEmpty(remoteAddrList)) { + return ""; + } + String remoteAddr = remoteAddrList.get(0); + //使用代理,则获取第一个IP地址 + if (StringUtils.isNotBlank(remoteAddr) && remoteAddr.indexOf(IP_UTILS_FLAG) > 0) { + remoteAddr = remoteAddr.substring(0, remoteAddr.indexOf(IP_UTILS_FLAG)); + } + return remoteAddr; + } + + public static String getRemoteAddress(Map map) { + String remoteAddr = map.get("X-Real-IP"); + if (StringUtils.isEmpty(remoteAddr)) { + remoteAddr = map.get("X-Forwarded-For"); + } else if (StringUtils.isEmpty(remoteAddr)) { + remoteAddr = map.get("Proxy-Client-IP"); + } else if (StringUtils.isEmpty(remoteAddr)) { + remoteAddr = map.get("WL-Proxy-Client-IP"); + } + if (StringUtils.isEmpty(remoteAddr)) { + return ""; + } + //使用代理,则获取第一个IP地址 + if (StringUtils.isNotBlank(remoteAddr) && remoteAddr.indexOf(IP_UTILS_FLAG) > 0) { + remoteAddr = remoteAddr.substring(0, remoteAddr.indexOf(IP_UTILS_FLAG)); + } + return remoteAddr; + } + + public static String getRemoteAddress(HttpServletRequest request) { + String ip = request.getHeader("x-forwarded-for"); + if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) { + // 多次反向代理后会有多个ip值,第一个ip才是真实ip + if (ip.indexOf(IP_UTILS_FLAG) != -1) { + ip = ip.split(",")[0]; + } + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("Proxy-Client-IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("x-forwarded-for"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("remoteip"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("WL-Proxy-Client-IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_CLIENT_IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_X_FORWARDED_FOR"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("X-Real-IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getRemoteHost(); + } + + return ip.replaceAll(":", "."); + } + + + /** + * aj captcha使用的 + * + * @param request + * @return + */ + public static final String getRemoteId(HttpServletRequest request) { + String xfwd = IPUtil.getRemoteAddress(request); + String ip = getRemoteIpFromXfwd(xfwd); + String ua = request.getHeader("user-agent"); + if (StringUtils.isNotBlank(ip)) { + return ip + ua; + } + return request.getRemoteAddr() + ua; + } + + private static String getRemoteIpFromXfwd(String xfwd) { + if (StringUtils.isNotBlank(xfwd)) { + String[] ipList = xfwd.split(","); + return StringUtils.trim(ipList[0]); + } + return null; + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/LocalDateUtils.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/LocalDateUtils.java new file mode 100644 index 0000000..eddd23c --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/LocalDateUtils.java @@ -0,0 +1,267 @@ +package com.arm.equipment.system.data.util; + +import java.time.*; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * 基于java8 的日期工具类 + * Created by liuyu on 2017/8/18. + */ +public class LocalDateUtils { + + /** + * 收集起始日期到结束日期之间所有的日期并以集合方式返回 + * + * @param start LocalDate 开始日期 + * @param end LocalDate 结束日期 + * @return 返回 String类型 日期 集合 + */ + public static List collectLocalDatesStrByTwoDate(LocalDate start, LocalDate end) { + // 用起始时间作为流的源头,按照每次加一天的方式创建一个无限流 + return Stream.iterate(start, localDate -> localDate.plusDays(1)) + // 截断无限流,长度为起始时间和结束时间的差+1个 + .limit(ChronoUnit.DAYS.between(start, end) + 1) + // 由于最后要的是字符串,所以map转换一下 + .map(LocalDate::toString) + // 把流收集为List + .collect(Collectors.toList()); + } + + + /** + * 收集起始日期到结束日期之间所有的日期并以集合方式返回 + * + * @param start String 开始日期 + * @param end String 结束日期 + * @return 返回 String类型 日期 集合 + */ + public static List collectLocalDatesStrByTwoDateStr(String start, String end) { + return collectLocalDatesStrByTwoDate(LocalDate.parse(start), LocalDate.parse(end)); + } + + /** + * 收集起始日期到结束日期之间所有的日期并以集合方式返回 + * + * @param start LocalDate 开始日期 + * @param end LocalDate 结束日期 + * @return 返回 LocalDate类型 日期 集合 + */ + public static List collectLocalDatesByTwoDate(LocalDate start, LocalDate end) { + return Stream.iterate(start, localDate -> localDate.plusDays(1)) + .limit(ChronoUnit.DAYS.between(start, end) + 1) + .collect(Collectors.toList()); + } + + /** + * 收集起始日期到结束日期之间所有的日期并以集合方式返回 + * + * @param start String 开始日期 + * @param end String 结束日期 + * @return 返回 LocalDate类型 日期 集合 + */ + public static List collectLocalDatesByTwoDateStr(String start, String end) { + return collectLocalDatesByTwoDate(LocalDate.parse(start), LocalDate.parse(end)); + } + + /** + * 按周收集起始日期到结束日期之间所有的日期并以集合方式返回 + * + * @param start LocalDate 开始日期 + * @param end LocalDate 结束日期 + * @return 返回 LocalDate类型 日期 集合 + */ + public static List collectOfWeekByTwoDate(LocalDate start, LocalDate end) { + return Stream.iterate(start, localDate -> localDate.plusWeeks(1)) + .limit(ChronoUnit.WEEKS.between(start, end) + 1) + .collect(Collectors.toList()); + } + + /** + * 按周收集起始日期到结束日期之间所有的日期并以集合方式返回 + * + * @param start String 开始日期 + * @param end String 结束日期 + * @return 返回 LocalDate类型 日期 集合 + */ + public static List collectOfWeekByTwoDate(String start, String end) { + return collectOfWeekByTwoDate(LocalDate.parse(start), LocalDate.parse(end)); + } + + /** + * 按周收集起始日期到结束日期之间所有的日期并以集合方式返回 + * + * @param start LocalDate 开始日期 + * @param end LocalDate 结束日期 + * @return 返回 String类型 日期 集合 + */ + public static List collectOfWeekStrByTwoDate(LocalDate start, LocalDate end) { + return Stream.iterate(start, localDate -> localDate.plusWeeks(1)) + .limit(ChronoUnit.WEEKS.between(start, end) + 1) + .map(LocalDate::toString) + .collect(Collectors.toList()); + } + + /** + * 按周收集起始日期到结束日期之间所有的日期并以集合方式返回 + * + * @param start String 开始日期 + * @param end String 结束日期 + * @return 返回 String类型 日期 集合 + */ + public static List collectOfWeekStrByTwoDateStr(String start, String end) { + return collectOfWeekStrByTwoDate(LocalDate.parse(start), LocalDate.parse(end)); + } + + /** + * 获取当前时间戳秒数 + */ + public static long getCurrentSecond() { + return LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")); + } + + /** + * 获取当前时间戳毫秒数 + */ + public static long getCurrentSecondMill() { + return LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli(); + } + + /** + * 获取LocaDate得 毫秒数 + */ + public static long getCurrentSecondMillByLocalDate(LocalDate localDate) { + return localDate.atStartOfDay().toInstant(ZoneOffset.of("+8")).toEpochMilli(); + } + + /** + * 获取毫秒数 + */ + public static long getCurrentSecondMill(LocalDateTime localDateTime) { + return localDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli(); + } + + /** + * 获取当前时间的小时与分钟 + */ + public static String getNowHourAndMinute() { + DateTimeFormatter pattern = DateTimeFormatter.ofPattern("HH:mm"); + return pattern.format(LocalDateTime.now()); + } + + /** + * Date 转 LocalDateTime + * + * @param date + * @return + */ + public static LocalDateTime dateToLocalDateTime(Date date) { + Instant instant = date.toInstant(); + ZoneId zoneId = ZoneId.systemDefault(); + return instant.atZone(zoneId).toLocalDateTime(); + } + + /** + * Date 转 LocalDateTime + * + * @param localDateTime + * @return + */ + public static Date localDateTimeToDate(LocalDateTime localDateTime) { + ZoneId zoneId = ZoneId.systemDefault(); + ZonedDateTime zdt = localDateTime.atZone(zoneId); + return Date.from(zdt.toInstant()); + } + + /** + * LocalDate转Date + * + * @param localDate + * @return + */ + public static Date localDateToDate(LocalDate localDate) { + ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault()); + return Date.from(zonedDateTime.toInstant()); + } + + /** + * Date转LocalDate + * + * @param date + */ + public static LocalDate dateToLocalDate(Date date) { + return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + } + + public static void main(String[] args) { + System.out.println(new Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDate()); + } + + /** + * 根据年月获取当前月开始时间 + * + * @param year + * @param month + * @return + */ + public static Date getBeginTimeByYearAndMonth(int year, int month) { + YearMonth yearMonth = YearMonth.of(year, month); + LocalDate localDate = yearMonth.atDay(1); + LocalDateTime startOfDay = localDate.atStartOfDay(); + ZonedDateTime zonedDateTime = startOfDay.atZone(ZoneId.of("Asia/Shanghai")); + + return Date.from(zonedDateTime.toInstant()); + } + + /** + * 根据年月获取当前月结束时间 + * + * @param year + * @param month + * @return + */ + public static Date getEndTimeByYearAndMonth(int year, int month) { + YearMonth yearMonth = YearMonth.of(year, month); + LocalDate endOfMonth = yearMonth.atEndOfMonth(); + LocalDateTime localDateTime = endOfMonth.atTime(23, 59, 59, 999); + ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.of("Asia/Shanghai")); + return Date.from(zonedDateTime.toInstant()); + } + + /** + * 时间戳转localDate + * + * @param timestamp + * @return + */ + public static LocalDate timestampToLocalDate(long timestamp) { + return Instant.ofEpochMilli(timestamp).atZone(ZoneOffset.ofHours(8)).toLocalDate(); + } + + /** + * 获取指定日期所在月份的开始或结束日期 + * + * @param today + * @param isFirst true 开始 false 结束 + * @return + */ + public static LocalDate getStartOrEndDayOfMonth(LocalDate today, Boolean isFirst) { + LocalDate resDate = LocalDate.now(); + if (today == null) { + today = resDate; + } + Month month = today.getMonth(); + int length = month.length(today.isLeapYear()); + if (isFirst) { + resDate = LocalDate.of(today.getYear(), month, 1); + } else { + resDate = LocalDate.of(today.getYear(), month, length); + } + return resDate; + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/Md5Utils.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/Md5Utils.java new file mode 100644 index 0000000..62fa2ae --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/Md5Utils.java @@ -0,0 +1,36 @@ +package com.arm.equipment.system.data.util; + +import java.security.MessageDigest; + +public class Md5Utils { + + private static byte[] md5(String s) throws Exception{ + MessageDigest algorithm = MessageDigest.getInstance("MD5"); + algorithm.reset(); + algorithm.update(s.getBytes("UTF-8")); + byte[] messageDigest = algorithm.digest(); + return messageDigest; + } + + private static final String toHex(byte hash[]) { + if (hash == null) { + return null; + } + StringBuffer buf = new StringBuffer(hash.length * 2); + int i; + + for (i = 0; i < hash.length; i++) { + if ((hash[i] & 0xff) < 0x10) { + buf.append("0"); + } + buf.append(Long.toString(hash[i] & 0xff, 16)); + } + return buf.toString(); + } + + public static String hash(String s) throws Exception{ + return new String(toHex(md5(s)).getBytes("UTF-8"), "UTF-8"); + } + + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/PinYinUtil.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/PinYinUtil.java new file mode 100644 index 0000000..216d8c2 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/PinYinUtil.java @@ -0,0 +1,75 @@ +package com.arm.equipment.system.data.util; + +import net.sourceforge.pinyin4j.PinyinHelper; +import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType; +import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; +import net.sourceforge.pinyin4j.format.HanyuPinyinToneType; +import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination; + +/** + * @author: admin + * @time: 2021/5/20 17:59 + */ +public class PinYinUtil { + /** + * 测试main方法 + * + * @param args + */ + public static void main(String[] args) { + System.out.println(toFirstChar("汉字转换为拼音").toUpperCase()); //转为首字母大写 + System.out.println(toPinyin("234234")); + } + + /** + * 获取字符串拼音的第一个字母 + * + * @param chinese + * @return + */ + public static String toFirstChar(String chinese) { + String pinyinStr = ""; + char[] newChar = chinese.toCharArray(); //转为单个字符 + HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat(); + defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE); + defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE); + for (int i = 0; i < newChar.length; i++) { + if (newChar[i] > 128) { + try { + pinyinStr += PinyinHelper.toHanyuPinyinStringArray(newChar[i], defaultFormat)[0].charAt(0); + } catch (BadHanyuPinyinOutputFormatCombination e) { + e.printStackTrace(); + } + } else { + pinyinStr += newChar[i]; + } + } + return pinyinStr; + } + + /** + * 汉字转为拼音 + * + * @param chinese + * @return + */ + public static String toPinyin(String chinese) { + String pinyinStr = ""; + char[] newChar = chinese.toCharArray(); + HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat(); + defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE); + defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE); + for (int i = 0; i < newChar.length; i++) { + if (newChar[i] > 128) { + try { + pinyinStr += PinyinHelper.toHanyuPinyinStringArray(newChar[i], defaultFormat)[0]; + } catch (BadHanyuPinyinOutputFormatCombination e) { + e.printStackTrace(); + } + } else { + pinyinStr += newChar[i]; + } + } + return pinyinStr; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/RandomUtils.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/RandomUtils.java new file mode 100644 index 0000000..414e0fa --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/RandomUtils.java @@ -0,0 +1,49 @@ +package com.arm.equipment.system.data.util; + + +import java.awt.*; +import java.util.Random; + +public class RandomUtils extends org.apache.commons.lang3.RandomUtils { + + private static final char[] CODE_SEQ = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', + 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', + 'X', 'Y', 'Z', '2', '3', '4', '5', '6', '7', '8', '9' }; + + private static final char[] NUMBER_ARRAY = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; + + private static Random random = new Random(); + + public static String randomString(int length) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < length; i++) { + sb.append(CODE_SEQ[random.nextInt(CODE_SEQ.length)]); + } + return sb.toString(); + } + + public static String randomNumberString(int length) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < length; i++) { + sb.append(NUMBER_ARRAY[random.nextInt(NUMBER_ARRAY.length)]); + } + return sb.toString(); + } + + public static Color randomColor(int fc, int bc) { + int f = fc; + int b = bc; + Random random = new Random(); + if (f > 255) { + f = 255; + } + if (b > 255) { + b = 255; + } + return new Color(f + random.nextInt(b - f), f + random.nextInt(b - f), f + random.nextInt(b - f)); + } + + public static int nextInt(int bound) { + return random.nextInt(bound); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/RequestUtil.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/RequestUtil.java new file mode 100644 index 0000000..546e862 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/RequestUtil.java @@ -0,0 +1,49 @@ +package com.arm.equipment.system.data.util; + +import com.alibaba.fastjson.JSONObject; +import com.arm.equipment.system.data.exception.BusinessException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.RestTemplate; + +/** + * 请求工具类 + */ +@Component +public class RequestUtil { + private final static Logger logger = LoggerFactory.getLogger(RequestUtil.class); + private static RestTemplate restTemplate; + + /** + * 发起请求 + * + * @param requestUrl 请求地址 + * @param params 参数 + * @return + */ + public static String post(String requestUrl, MultiValueMap params) { + logger.info("请求: {}, 参数: {}", requestUrl, JSONObject.toJSON(params)); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + HttpEntity request = new HttpEntity<>(params, headers); + try { + String result = restTemplate.postForObject(requestUrl, request, String.class); + logger.info("返回结: {}", result); + return result; + } catch (Exception e) { + logger.info("接口请求异常: {}", e); + throw new BusinessException("接口请求异常"); + } + } + + @Autowired + public void setRestTemplate(RestTemplate restTemplate) { + RequestUtil.restTemplate = restTemplate; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/StreamUtil.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/StreamUtil.java new file mode 100644 index 0000000..d20115a --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/StreamUtil.java @@ -0,0 +1,14 @@ +package com.arm.equipment.system.data.util; + +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; +import java.util.function.Predicate; + +public class StreamUtil { + + public static Predicate distinctByKey(Function keyExtractor) { + Set seen = ConcurrentHashMap.newKeySet(); + return t -> seen.add(keyExtractor.apply(t)); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/StringUtils.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/StringUtils.java new file mode 100644 index 0000000..2688e8f --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/StringUtils.java @@ -0,0 +1,93 @@ +package com.arm.equipment.system.data.util; + +import org.apache.commons.lang3.StringEscapeUtils; + +import javax.servlet.http.HttpServletRequest; +import java.io.UnsupportedEncodingException; +import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * 字符串工具类 + */ +public class StringUtils extends org.apache.commons.lang3.StringUtils { + + private static final String DASH = "-"; + + /** + * 缩略字符串(不区分中英文字符) + * + * @param str 目标字符串 + * @param length 截取长度 + * @return + */ + public static String abbr(String str, int length) { + if (str == null) { + return ""; + } + try { + StringBuilder sb = new StringBuilder(); + int currentLength = 0; + for (char c : replaceHtml(StringEscapeUtils.unescapeHtml4(str)).toCharArray()) { + currentLength += String.valueOf(c).getBytes("GBK").length; + if (currentLength <= length - 3) { + sb.append(c); + } else { + sb.append("..."); + break; + } + } + return sb.toString(); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return ""; + } + + /** + * 替换掉HTML标签方法 + */ + public static String replaceHtml(String html) { + if (isBlank(html)) { + return ""; + } + String regEx = "<.+?>"; + Pattern p = Pattern.compile(regEx); + Matcher m = p.matcher(html); + String s = m.replaceAll(""); + return s; + } + + /** + * 获取UUID + * + * @return uuid + */ + public static String uuid() { + return UUID.randomUUID().toString().replace(DASH, EMPTY); + } + + /** + * 批量发货时调用 + * + * @return + */ + public static synchronized String threadUUID() { + return UUID.randomUUID().toString().replace(DASH, EMPTY); + } + + /** + * 获取N位随机数 + * + * @param num + * @return + */ + public static String getRandomNumber(int num) { + if (num <= 0) { + throw new IllegalArgumentException(); + } + double d = (Math.random() * 9 + 1) * (Math.pow(10, num - 1)); + return String.valueOf((int) d); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/UuidUtils.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/UuidUtils.java new file mode 100644 index 0000000..1d44c47 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/UuidUtils.java @@ -0,0 +1,10 @@ +package com.arm.equipment.system.data.util; + +import java.util.UUID; + +public class UuidUtils { + + public static String uuid() { + return UUID.randomUUID().toString().replaceAll("-",""); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/ValidCodeUtil.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/ValidCodeUtil.java new file mode 100644 index 0000000..bb09571 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/ValidCodeUtil.java @@ -0,0 +1,101 @@ +package com.arm.equipment.system.data.util; + +import java.awt.*; +import java.awt.image.BufferedImage; +import java.util.Random; + +/** + * 验证码工具类 + * @author wyd + */ +public class ValidCodeUtil { + private final static char[] CODE_SEQUENCE = { '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' }; + private final static int CODE_COUNT = 4; + + /** + * 生成验证码图片 + * @param validCode + * @return + */ + public static BufferedImage generateImg(String validCode) { + //图片的宽和高 + int imgWidth = CODE_COUNT * 20; + int imgHeight = 30; + + BufferedImage image = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_BGR); + drawImg(image, validCode, imgWidth , imgHeight); + return image; + } + + /** + * 生成验证码 + * @return + */ + public static String generateRandomCode() { + Random rand = new Random(); + //记录验证码 + StringBuilder chapter = new StringBuilder(); + for (int i = 0; i < CODE_COUNT; i++) { + //记录字符 + chapter.append(CODE_SEQUENCE[rand.nextInt(CODE_SEQUENCE.length)]); + } + return chapter.toString(); + } + + /** + * 根据宽度、高度、和验证码的个数绘制验证码图片,并返回验证码的值 + * @param buffImg BufferedImage对象 + * @param validCode 验证码 + * @param imgWidth 图片宽度 + * @param imgHeight 图片高度 + * @return 验证码的值 + */ + private static void drawImg(BufferedImage buffImg, String validCode, int imgWidth, int imgHeight) { + Random rand = new Random(); + Graphics2D gd = buffImg.createGraphics(); + + //填充矩形 + gd.setColor(Color.WHITE); + gd.fillRect(0, 0, imgWidth, imgHeight); + + //设置字体 + Font font = new Font("微软雅黑", Font.PLAIN, imgHeight - 5); + gd.setFont(font); + + //绘制边框 + gd.setColor(Color.BLACK); + gd.drawRect(0, 0, imgWidth - 1, imgHeight - 1); + + //绘制灰色干扰线 + gd.setColor(Color.GRAY); + for (int i = 0, x, y, x1, y1; i < 30; i++) { + x = rand.nextInt(imgWidth); + y = rand.nextInt(imgHeight); + x1 = rand.nextInt(12); + y1 = rand.nextInt(12); + gd.drawLine(x, y, x + x1, y + y1); + } + + //int codeCount = 4, + int codeX = 15, codeY = 25; + + //临时变量 + String item; + + for (int i = 0, red, green, blue; i < validCode.length(); i++) { + item = String.valueOf(validCode.charAt(i)); + //随机选择字符颜色 + red = rand.nextInt(255); + green = rand.nextInt(255); + blue = rand.nextInt(255); + gd.setColor(new Color(red, green, blue)); + + //绘制字符 + gd.drawString(item, (i + 1) * codeX, codeY); + } + } + + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/ValidateCode.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/ValidateCode.java new file mode 100644 index 0000000..baae01f --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/ValidateCode.java @@ -0,0 +1,276 @@ +package com.arm.equipment.system.data.util; + +import java.awt.*; +import java.awt.image.BufferedImage; +import java.util.Random; + +/** + * Desc: 验证码生成器类,可生成数字、大写、小写字母及三者混合类型的验证码。 + * 支持自定义验证码字符数量; 支持自定义验证码图片的大小; 支持自定义需排除的特殊字符; + * 支持自定义干扰线的数量; 支持自定义验证码图文颜色 + */ +public class ValidateCode { + + /** + * 验证码类型为仅数字 0~9 + */ + public static final int TYPE_NUM_ONLY = 0; + + /** + * 验证码类型为仅字母,即大写、小写字母混合 + */ + public static final int TYPE_LETTER_ONLY = 1; + + /** + * 验证码类型为数字、大写字母、小写字母混合 + */ + public static final int TYPE_ALL_MIXED = 2; + + /** + * 验证码类型为数字、大写字母混合 + */ + public static final int TYPE_NUM_UPPER = 3; + + /** + * 验证码类型为数字、小写字母混合 + */ + public static final int TYPE_NUM_LOWER = 4; + + /** + * 验证码类型为仅大写字母 + */ + public static final int TYPE_UPPER_ONLY = 5; + + /** + * 验证码类型为仅小写字母 + */ + public static final int TYPE_LOWER_ONLY = 6; + + private ValidateCode() { + + } + + /** + * 生成验证码字符串 + * + * @param type + * 验证码类型,参见本类的静态属性 + * @param length + * 验证码长度,大于0的整数 + * @param exChars + * 需排除的特殊字符(仅对数字、字母混合型验证码有效,无需排除则为null) + * @return 验证码字符串 + */ + public static String generateTextCode(int type, int length, String exChars) { + + if (length <= 0) + return ""; + + StringBuffer code = new StringBuffer(); + int i = 0; + Random r = new Random(); + + switch (type) { + + // 仅数字 + case TYPE_NUM_ONLY: + while (i < length) { + int t = r.nextInt(10); + if (exChars == null || exChars.indexOf(t + "") < 0) {// 排除特殊字符 + code.append(t); + i++; + } + } + break; + + // 仅字母(即大写字母、小写字母混合) + case TYPE_LETTER_ONLY: + while (i < length) { + int t = r.nextInt(123); + if ((t >= 97 || (t >= 65 && t <= 90)) && (exChars == null || exChars.indexOf((char) t) < 0)) { + code.append((char) t); + i++; + } + } + break; + + // 数字、大写字母、小写字母混合 + case TYPE_ALL_MIXED: + while (i < length) { + int t = r.nextInt(123); + if ((t >= 97 || (t >= 65 && t <= 90) || (t >= 48 && t <= 57)) + && (exChars == null || exChars.indexOf((char) t) < 0)) { + code.append((char) t); + i++; + } + } + break; + + // 数字、大写字母混合 + case TYPE_NUM_UPPER: + while (i < length) { + int t = r.nextInt(91); + if ((t >= 65 || (t >= 48 && t <= 57)) && (exChars == null || exChars.indexOf((char) t) < 0)) { + code.append((char) t); + i++; + } + } + break; + + // 数字、小写字母混合 + case TYPE_NUM_LOWER: + while (i < length) { + int t = r.nextInt(123); + if ((t >= 97 || (t >= 48 && t <= 57)) && (exChars == null || exChars.indexOf((char) t) < 0)) { + code.append((char) t); + i++; + } + } + break; + + // 仅大写字母 + case TYPE_UPPER_ONLY: + while (i < length) { + int t = r.nextInt(91); + if ((t >= 65) && (exChars == null || exChars.indexOf((char) t) < 0)) { + code.append((char) t); + i++; + } + } + break; + + // 仅小写字母 + case TYPE_LOWER_ONLY: + while (i < length) { + int t = r.nextInt(123); + if ((t >= 97) && (exChars == null || exChars.indexOf((char) t) < 0)) { + code.append((char) t); + i++; + } + } + break; + + } + + return code.toString(); + } + + /** + * 已有验证码,生成验证码图片 + * + * @param textCode + * 文本验证码 + * @param width + * 图片宽度 + * @param height + * 图片高度 + * @param interLine + * 图片中干扰线的条数 + * @param randomLocation + * 每个字符的高低位置是否随机 + * @param backColor + * 图片颜色,若为null,则采用随机颜色 + * @param foreColor + * 字体颜色,若为null,则采用随机颜色 + * @param lineColor + * 干扰线颜色,若为null,则采用随机颜色 + * @return 图片缓存对象 + */ + public static BufferedImage generateImageCode(String textCode, int width, int height, int interLine, + boolean randomLocation, Color backColor, Color foreColor, Color lineColor) { + + BufferedImage bim = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + Graphics g = bim.getGraphics(); + + // 画背景图 + g.setColor(backColor == null ? getRandomColor() : backColor); + g.fillRect(0, 0, width, height); + + // 画干扰线 + Random r = new Random(); + if (interLine > 0) { + + int x = 0, y = 0, x1 = width, y1 = 0; + for (int i = 0; i < interLine; i++) { + g.setColor(lineColor == null ? getRandomColor() : lineColor); + y = r.nextInt(height); + y1 = r.nextInt(height); + + g.drawLine(x, y, x1, y1); + } + } + + // 写验证码 + + // g.setColor(getRandomColor()); + // g.setColor(isSimpleColor?Color.BLACK:Color.WHITE); + + // 字体大小为图片高度的80% + int fsize = (int) (height * 0.8); + int fx = height - fsize; + int fy = fsize; + + g.setFont(new Font("Default", Font.PLAIN, fsize)); + + // 写验证码字符 + for (int i = 0; i < textCode.length(); i++) { + fy = randomLocation ? (int) ((Math.random() * 0.3 + 0.6) * height) : fy;// 每个字符高低是否随机 + g.setColor(foreColor == null ? getRandomColor() : foreColor); + g.drawString(textCode.charAt(i) + "", fx, fy); + fx += fsize * 0.9; + } + + g.dispose(); + + return bim; + } + + /** + * 生成图片验证码 + * + * @param type + * 验证码类型,参见本类的静态属性 + * @param length + * 验证码字符长度,大于0的整数 + * @param exChars + * 需排除的特殊字符 + * @param width + * 图片宽度 + * @param height + * 图片高度 + * @param interLine + * 图片中干扰线的条数 + * @param randomLocation + * 每个字符的高低位置是否随机 + * @param backColor + * 图片颜色,若为null,则采用随机颜色 + * @param foreColor + * 字体颜色,若为null,则采用随机颜色 + * @param lineColor + * 干扰线颜色,若为null,则采用随机颜色 + * @return 图片缓存对象 + */ + public static BufferedImage generateImageCode(int type, int length, String exChars, int width, int height, + int interLine, boolean randomLocation, Color backColor, Color foreColor, Color lineColor) { + + String textCode = generateTextCode(type, length, exChars); + BufferedImage bim = generateImageCode(textCode, width, height, interLine, randomLocation, backColor, foreColor, + lineColor); + + return bim; + } + + /** + * 产生随机颜色 + * + * @return + */ + private static Color getRandomColor() { + Random r = new Random(); + Color c = new Color(r.nextInt(255), r.nextInt(255), r.nextInt(255)); + return c; + } + + + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/WJAssert.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/WJAssert.java new file mode 100644 index 0000000..fce9ccf --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/WJAssert.java @@ -0,0 +1,86 @@ +package com.arm.equipment.system.data.util; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.util.Assert; + +/** + * 参数校验 + * @author admin + */ +public class WJAssert extends Assert { + + /** + * 判断是否在规定的长度内 + * + * @param str + * @param minLength + * @param maxLength + * @param message + */ + public static void isRange(String str, int minLength, int maxLength, String message) { + if (StringUtils.isEmpty(str)) { + throw new IllegalArgumentException(message); + } + if (str.length() < minLength || str.length() > maxLength) { + throw new IllegalArgumentException(message); + } + } + + /** + * 判断是否超过最大限制 + *

判定目标不可以为空

+ * + * @param str + * @param maxLength + * @param message + */ + public static void isMaxLength(String str, int maxLength, String message) { + limitMaxLength(str, false, maxLength, message); + } + + /** + * 判断字符串是否为null或空字符串 + *

判定目标不可以为空

+ * + * @param str + * @param message + */ + public static void notBlank(String str, String message) { + if (StringUtils.isBlank(str)) { + throw new IllegalArgumentException(message); + } + } + + /** + * 判断是否超过最大限制 + * + * @param str 判定目标 + * @param nullAble 是否可空 + * @param maxLength 最大长度 + * @param message 提示信息 + */ + public static void limitMaxLength(String str, boolean nullAble, int maxLength, String message) { + if (!nullAble) { + if (StringUtils.isEmpty(str) || str.length() > maxLength) { + throw new IllegalArgumentException(message); + } + } else { + if (str != null && str.length() > maxLength) { + throw new IllegalArgumentException(message); + } + } + } + + /** + * 判断地址 + * @param str + * @param message + */ + public static void isMatchesLiveUrl(String str, String message) { + String regex = "^(https?|ftp|file|http?|rtmp?)://\\S+"; + if(!str.matches(regex)) { + throw new IllegalArgumentException(message); + } + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/excel/EasyExcelListener.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/excel/EasyExcelListener.java new file mode 100644 index 0000000..92dea84 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/excel/EasyExcelListener.java @@ -0,0 +1,32 @@ +package com.arm.equipment.system.data.util.excel; + +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; +import com.alibaba.excel.metadata.BaseRowModel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; + +public class EasyExcelListener extends AnalysisEventListener { + + private final static Logger logger = LoggerFactory.getLogger(EasyExcelListener.class); + + private final List rows = new ArrayList<>(); + + @Override + public void invoke(T object, AnalysisContext context) { + rows.add(object); + } + + @Override + public void doAfterAllAnalysed(AnalysisContext context) { + logger.info("read {} rows %n", rows.size()); + } + + public List getRows() { + logger.info("read {} rows %n", rows); + return rows; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/excel/EasyExcelUtils.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/excel/EasyExcelUtils.java new file mode 100644 index 0000000..bd16f22 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/excel/EasyExcelUtils.java @@ -0,0 +1,144 @@ +package com.arm.equipment.system.data.util.excel; + +import com.alibaba.excel.ExcelReader; +import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.metadata.BaseRowModel; +import com.alibaba.excel.metadata.Sheet; +import com.alibaba.excel.support.ExcelTypeEnum; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.poi.poifs.filesystem.FileMagic; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * + * + * @author: admin + * @time: 2022/9/16 11:20 + */ +public final class EasyExcelUtils { + + private final static Logger logger = LoggerFactory.getLogger(EasyExcelUtils.class); + + + /** + * sheet编号 + */ + private static final int sheetNo = 1; + /** + * 从第几行开始读 + */ + private static final int headLineMun = 0; + + public static final List> headList = new ArrayList<>(); + + static { + headList.add(Stream.of("列1").collect(Collectors.toList())); + } + + /** + * 根据模型关系构建excel文件 + */ + public static void accordingModelRelationBuilder( + Class clazz, List tList, String url, ExcelTypeEnum typeEnum) + throws FileNotFoundException { + OutputStream outputStream = new FileOutputStream(url); + try { + ExcelWriter writer = new ExcelWriter(outputStream, typeEnum); + Sheet sheet1 = new Sheet(sheetNo, headLineMun, clazz); + sheet1.setAutoWidth(Boolean.TRUE); + writer.write(tList, sheet1); + writer.finish(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + outputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + /** + * 自定义excel文件 + */ + public static void customBuilder( + Class clazz, List> tList, String url, ExcelTypeEnum typeEnum, + String sheetName, List> headList) + throws FileNotFoundException { + OutputStream outputStream = new FileOutputStream(url); + try { + ExcelWriter writer = new ExcelWriter(outputStream, typeEnum); + Sheet sheet1 = new Sheet(sheetNo, headLineMun, clazz, sheetName, headList); + sheet1.setAutoWidth(Boolean.TRUE); + writer.write1(tList, sheet1); + writer.finish(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + outputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + public static List readExcel(final InputStream inputStream, final Class clazz) { + if (null == inputStream) { + throw new NullPointerException("the inputStream is null!"); + } + EasyExcelListener listener = new EasyExcelListener<>(); + // 这里因为EasyExcel-1.1.1版本的bug,所以需要选用下面这个标记已经过期的版本 + ExcelReader reader = new ExcelReader(inputStream, valueOf(inputStream), null, listener); + reader.read(new Sheet(1, 1, clazz)); + return listener.getRows(); + } + + public static void writeExcel(final File file, List list) { + try (OutputStream out = new FileOutputStream(file)) { + ExcelWriter writer = new ExcelWriter(out, ExcelTypeEnum.XLSX); + //写第一个sheet, 有模型映射关系 + Class t = null; + if (CollectionUtils.isNotEmpty(list)) { + t = list.get(0).getClass(); + } else { + t = BaseRowModel.class; + } + Sheet sheet = new Sheet(1, 0, t); + writer.write(list, sheet); + writer.finish(); + } catch (IOException e) { + logger.warn("fail to write to excel file: file[{}]", file.getName(), e); + } + } + + + /** + * 根据输入流,判断为xls还是xlsx,该方法原本存在于easyexcel 1.1.0 的ExcelTypeEnum中。 + */ + public static ExcelTypeEnum valueOf(InputStream inputStream) { + try { + FileMagic fileMagic = FileMagic.valueOf(inputStream); + if (FileMagic.OLE2.equals(fileMagic)) { + return ExcelTypeEnum.XLS; + } + if (FileMagic.OOXML.equals(fileMagic)) { + return ExcelTypeEnum.XLSX; + } + throw new IllegalArgumentException("excelTypeEnum can not null"); + + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/passwordEncoder/BCrypt.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/passwordEncoder/BCrypt.java new file mode 100644 index 0000000..2e95b38 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/passwordEncoder/BCrypt.java @@ -0,0 +1,628 @@ +package com.arm.equipment.system.data.util.passwordEncoder; + +import java.io.ByteArrayOutputStream; +import java.io.UnsupportedEncodingException; +import java.security.SecureRandom; + +/** + * + * + * @author: admin + * @time: 2022/9/16 11:20 + */ +public class BCrypt {// BCrypt parameters + + private static final int GENSALT_DEFAULT_LOG2_ROUNDS = 10; + private static final int BCRYPT_SALT_LEN = 16; + // Blowfish parameters + private static final int BLOWFISH_NUM_ROUNDS = 16; + // Initial contents of key schedule + private static final int P_orig[] = { 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, + 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, + 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, + 0x9216d5d9, 0x8979fb1b }; + private static final int S_orig[] = { 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, + 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, 0x24a19947, 0xb3916cf7, + 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, + 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, + 0x9c30d539, 0x2af26013, 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, + 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, 0xd71577c1, 0xbd314b27, + 0x78af2fda, 0x55605c60, 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, + 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, 0xa15486af, 0x7c72e993, + 0xb3ee1411, 0x636fbc2a, 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, + 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, 0x3b8f4898, 0x6b4bb9af, + 0xc4bfe81b, 0x66282193, 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, + 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, + 0x0f6d6ff3, 0x83f44239, 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, + 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0, 0x6a51a0d2, 0xd8542f68, + 0x960fa728, 0xab5133a3, 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, + 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, + 0x7d84a5c3, 0x3b8b5ebe, 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, + 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d, 0x37d0d724, 0xd00a1248, + 0xdb0fead3, 0x49f1c09b, 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, + 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, 0xc1a94fb6, 0x409f60c4, + 0x5e5c9ec2, 0x196a2463, 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, + 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09, 0xbee3d004, 0xde334afd, + 0x660f2807, 0x192e4bb3, 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, + 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, 0x679f25fe, 0xfb1fa3cc, + 0x8ea5e9f8, 0xdb3222f8, 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, + 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82, 0x9e5c57bb, 0xca6f8ca0, + 0x1a87562e, 0xdf1769db, 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, + 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, 0xfd2183b8, + 0x4afcb56c, 0x2dd1d35b, 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, + 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8, 0xef20cada, 0x36774c01, + 0xd07e9efe, 0x2bf11fb4, 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, + 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, + 0x8888b812, 0x900df01c, 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, + 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1, 0xe5a0cc0f, 0xb56f74e8, + 0x18acf3d6, 0xce89e299, 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, + 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, + 0xc75442f5, 0xfb9d35cf, 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, + 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af, 0x2464369b, 0xf009b91e, + 0x5563911d, 0x59dfa6aa, 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, + 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, + 0x1b510052, 0x9a532915, 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, + 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, 0xb6636521, 0xe7b9f9b6, + 0xff34052e, 0xc5855664, 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a, + 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, + 0x9cee60b8, 0x8fedb266, 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, + 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, 0x3f54989a, 0x5b429d65, + 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, + 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, 0x09686b3f, 0x3ebaefc9, + 0x3c971814, 0x6b6a70a1, 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, + 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, 0xb03ada37, 0xf0500c0d, + 0xf01c1f04, 0x0200b3ff, 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, + 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, 0x3ae5e581, 0x37c2dadc, + 0xc8b57634, 0x9af3dda7, 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, + 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, 0x4e548b38, 0x4f6db908, + 0x6f420d03, 0xf60a04bf, 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af, + 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, 0x5512721f, 0x2e6b7124, + 0x501adde6, 0x9f84cd87, 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, + 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, 0xef1c1847, 0x3215d908, + 0xdd433b37, 0x24c2ba16, 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd, + 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, 0x043556f1, 0xd7a3c76b, + 0x3c11183b, 0x5924a509, 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, + 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, 0x771fe71c, 0x4e3d06fa, + 0x2965dcb9, 0x99e71d0f, 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a, + 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, 0xf2f74ea7, 0x361d2b3d, + 0x1939260f, 0x19c27960, 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, + 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, 0xc332ddef, 0xbe6c5aa5, + 0x65582185, 0x68ab9802, 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, + 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, 0x13cca830, 0xeb61bd96, + 0x0334fe1e, 0xaa0363cf, 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, + 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, 0x648b1eaf, 0x19bdf0ca, + 0xa02369b9, 0x655abb50, 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, + 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, 0xf837889a, 0x97e32d77, + 0x11ed935f, 0x16681281, 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, + 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, 0xcdb30aeb, 0x532e3054, + 0x8fd948e4, 0x6dbc3128, 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, + 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, 0x45eee2b6, 0xa3aaabea, + 0xdb6c4f15, 0xfacb4fd0, 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, + 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, 0xcf62a1f2, 0x5b8d2646, + 0xfc8883a0, 0xc1c7b6a3, 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285, + 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, 0x58428d2a, 0x0c55f5ea, + 0x1dadf43e, 0x233f7061, 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, + 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, 0xa6078084, 0x19f8509e, + 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, + 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd, + 0x675fda79, 0xe3674340, 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, + 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7, 0xe93d5a68, 0x948140f7, + 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, + 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 0x1e39f62e, 0x97244546, + 0x14214f74, 0xbf8b8840, 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, + 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, 0x96eb27b3, 0x55fd3941, + 0xda2547e6, 0xabca0a9a, 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb, + 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, 0x4f3ffea2, 0xe887ad8c, + 0xb58ce006, 0x7af4d6b6, 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, + 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b, 0x1dc9faf7, 0x4b6d1856, + 0x26a36631, 0xeae397b2, 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb, + 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, 0x55533a3a, 0x20838d87, + 0xfe6ba9b7, 0xd096954b, 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, + 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c, 0xfdf8e802, 0x04272f70, + 0x80bb155c, 0x05282ce3, 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc, + 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, 0x325f51eb, 0xd59bc0d1, + 0xf2bcc18f, 0x41113564, 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, + 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115, 0x6b2395e0, 0x333e92e1, + 0x3b240b62, 0xeebeb922, 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728, + 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, 0x5449a36f, 0x877d48fa, + 0xc39dfd27, 0xf33e8d1e, 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, + 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d, 0xc67b5510, 0x6d672c37, + 0x2765d43b, 0xdcd0e804, 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b, + 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, 0xbb132f88, 0x515bad24, + 0x7b9479bf, 0x763bd6eb, 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, + 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c, 0x6a124237, 0xb79251e7, + 0x06a1bbe6, 0x4bfb6350, 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9, + 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, 0x64af674e, 0xda86a85f, + 0xbebfe988, 0x64e4c3fe, 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, + 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc, 0x83426b33, 0xf01eab71, + 0xb0804187, 0x3c005e5f, 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61, + 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, 0x5366f9c3, 0xc8b38e74, + 0xb475f255, 0x46fcd9b9, 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, + 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c, 0xb90bace1, 0xbb8205d0, + 0x11a86248, 0x7574a99e, 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633, + 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, 0x1ab93d1d, 0x0ba5a4df, + 0xa186f20f, 0x2868f169, 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, + 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027, 0x9af88c27, 0x773f8641, + 0xc3604c06, 0x61a806b5, 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62, + 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, 0xbbcbee56, 0x90bcb6de, + 0xebfc7da1, 0xce591d76, 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, + 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc, 0xed545578, 0x08fca5b5, + 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, + 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, 0xd79a3234, 0x92638212, + 0x670efa8e, 0x406000e0, 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, + 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, 0xd5118e9d, 0xbf0f7315, + 0xd62d1c7e, 0xc700c47b, 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, + 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, + 0xd5730a1d, 0x4cd04dc6, 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, + 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22, 0xc089c2b8, 0x43242ef6, + 0xa51e03aa, 0x9cf2d0a4, 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, + 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, 0xc72fefd3, 0xf752f7da, + 0x3f046f69, 0x77fa0a59, 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, + 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51, 0x96d5ac3a, 0x017da67d, + 0xd1cf3ed6, 0x7c7d2d28, 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, + 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, 0xe8d3c48d, 0x283b57cc, + 0xf8d56629, 0x79132e28, 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, + 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd, 0xc3eb9e15, 0x3c9057a2, + 0x97271aec, 0xa93a072a, 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, + 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, 0x28517711, 0xc20ad9f8, + 0xabcc5167, 0xccad925f, 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, + 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32, 0xa8b6e37e, 0xc3293d46, + 0x48de5369, 0x6413e680, 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, + 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, 0x5bbef7dd, 0x1b588d40, + 0xccd2017f, 0x6bb4e3bb, 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, + 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47, 0xd29be463, 0x542f5d9e, + 0xaec2771b, 0xf64e6370, 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, + 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, 0xe1b00428, 0x95983a1d, + 0x06b89fb4, 0xce6ea048, 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, + 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd, 0xa08839e1, 0x51ce794b, + 0x2f32c9b7, 0xa01fbac9, 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, + 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, 0x0339c32a, 0xc6913667, + 0x8df9317c, 0xe0b12b4f, 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, + 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525, 0xfae59361, 0xceb69ceb, + 0xc2a86459, 0x12baa8d1, 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, + 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, 0x9f1f9532, 0xe0d392df, + 0xd3a0342b, 0x8971f21e, 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, + 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d, 0xe54cda54, 0x1edad891, + 0xce6279cf, 0xcd3e7e6f, 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, + 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, + 0x6e163697, 0x88d273cc, 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, + 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a, 0xc9aa53fd, 0x62a80f00, + 0xbb25bfe2, 0x35bdd2f6, 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, + 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, + 0x77afa1c5, 0x20756060, 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, + 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, 0x90d4f869, 0xa65cdea0, + 0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6 }; + // bcrypt IV: "OrpheanBeholderScryDoubt" + static private final int bf_crypt_ciphertext[] = { 0x4f727068, 0x65616e42, + 0x65686f6c, 0x64657253, 0x63727944, 0x6f756274 }; + // Table for Base64 encoding + static private final char base64_code[] = { '.', '/', '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', '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' }; + // Table for Base64 decoding + static private final byte index_64[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 54, 55, + 56, 57, 58, 59, 60, 61, 62, 63, -1, -1, -1, -1, -1, -1, -1, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, + -1, -1, -1, -1, -1, -1, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, -1, -1, -1, -1, -1 }; + static final int MIN_LOG_ROUNDS = 4; + static final int MAX_LOG_ROUNDS = 31; + // Expanded Blowfish key + private int P[]; + private int S[]; + + /** + * Encode a byte array using bcrypt's slightly-modified base64 encoding scheme. Note + * that this is not compatible with the standard MIME-base64 + * encoding. + * + * @param d the byte array to encode + * @param len the number of bytes to encode + * @param rs the destination buffer for the base64-encoded string + * @exception IllegalArgumentException if the length is invalid + */ + static void encode_base64(byte d[], int len, StringBuilder rs) + throws IllegalArgumentException { + int off = 0; + int c1, c2; + + if (len <= 0 || len > d.length) { + throw new IllegalArgumentException("Invalid len"); + } + + while (off < len) { + c1 = d[off++] & 0xff; + rs.append(base64_code[(c1 >> 2) & 0x3f]); + c1 = (c1 & 0x03) << 4; + if (off >= len) { + rs.append(base64_code[c1 & 0x3f]); + break; + } + c2 = d[off++] & 0xff; + c1 |= (c2 >> 4) & 0x0f; + rs.append(base64_code[c1 & 0x3f]); + c1 = (c2 & 0x0f) << 2; + if (off >= len) { + rs.append(base64_code[c1 & 0x3f]); + break; + } + c2 = d[off++] & 0xff; + c1 |= (c2 >> 6) & 0x03; + rs.append(base64_code[c1 & 0x3f]); + rs.append(base64_code[c2 & 0x3f]); + } + } + + /** + * Look up the 3 bits base64-encoded by the specified character, range-checking + * against conversion table + * @param x the base64-encoded value + * @return the decoded value of x + */ + private static byte char64(char x) { + if (x > index_64.length) { + return -1; + } + return index_64[x]; + } + + /** + * Decode a string encoded using bcrypt's base64 scheme to a byte array. Note that + * this is *not* compatible with the standard MIME-base64 encoding. + * @param s the string to decode + * @param maxolen the maximum number of bytes to decode + * @return an array containing the decoded bytes + * @throws IllegalArgumentException if maxolen is invalid + */ + static byte[] decode_base64(String s, int maxolen) throws IllegalArgumentException { + ByteArrayOutputStream out = new ByteArrayOutputStream(maxolen); + int off = 0, slen = s.length(), olen = 0; + byte c1, c2, c3, c4, o; + + if (maxolen <= 0) { + throw new IllegalArgumentException("Invalid maxolen"); + } + + while (off < slen - 1 && olen < maxolen) { + c1 = char64(s.charAt(off++)); + c2 = char64(s.charAt(off++)); + if (c1 == -1 || c2 == -1) { + break; + } + o = (byte) (c1 << 2); + o |= (c2 & 0x30) >> 4; + out.write(o); + if (++olen >= maxolen || off >= slen) { + break; + } + c3 = char64(s.charAt(off++)); + if (c3 == -1) { + break; + } + o = (byte) ((c2 & 0x0f) << 4); + o |= (c3 & 0x3c) >> 2; + out.write(o); + if (++olen >= maxolen || off >= slen) { + break; + } + c4 = char64(s.charAt(off++)); + o = (byte) ((c3 & 0x03) << 6); + o |= c4; + out.write(o); + ++olen; + } + + return out.toByteArray(); + } + + /** + * Blowfish encipher a single 64-bit block encoded as two 32-bit halves + * @param lr an array containing the two 32-bit half blocks + * @param off the position in the array of the blocks + */ + private final void encipher(int lr[], int off) { + int i, n, l = lr[off], r = lr[off + 1]; + + l ^= P[0]; + for (i = 0; i <= BLOWFISH_NUM_ROUNDS - 2;) { + // Feistel substitution on left word + n = S[(l >> 24) & 0xff]; + n += S[0x100 | ((l >> 16) & 0xff)]; + n ^= S[0x200 | ((l >> 8) & 0xff)]; + n += S[0x300 | (l & 0xff)]; + r ^= n ^ P[++i]; + + // Feistel substitution on right word + n = S[(r >> 24) & 0xff]; + n += S[0x100 | ((r >> 16) & 0xff)]; + n ^= S[0x200 | ((r >> 8) & 0xff)]; + n += S[0x300 | (r & 0xff)]; + l ^= n ^ P[++i]; + } + lr[off] = r ^ P[BLOWFISH_NUM_ROUNDS + 1]; + lr[off + 1] = l; + } + + /** + * Cycically extract a word of key material + * @param data the string to extract the data from + * @param offp a "pointer" (as a one-entry array) to the current offset into data + * @return the next word of material from data + */ + private static int streamtoword(byte data[], int offp[]) { + int i; + int word = 0; + int off = offp[0]; + + for (i = 0; i < 4; i++) { + word = (word << 8) | (data[off] & 0xff); + off = (off + 1) % data.length; + } + + offp[0] = off; + return word; + } + + /** + * Initialise the Blowfish key schedule + */ + private void init_key() { + P = (int[]) P_orig.clone(); + S = (int[]) S_orig.clone(); + } + + /** + * Key the Blowfish cipher + * @param key an array containing the key + */ + private void key(byte key[]) { + int i; + int koffp[] = { 0 }; + int lr[] = { 0, 0 }; + int plen = P.length, slen = S.length; + + for (i = 0; i < plen; i++) { + P[i] = P[i] ^ streamtoword(key, koffp); + } + + for (i = 0; i < plen; i += 2) { + encipher(lr, 0); + P[i] = lr[0]; + P[i + 1] = lr[1]; + } + + for (i = 0; i < slen; i += 2) { + encipher(lr, 0); + S[i] = lr[0]; + S[i + 1] = lr[1]; + } + } + + /** + * Perform the "enhanced key schedule" step described by Provos and Mazieres in + * "A Future-Adaptable Password Scheme" https://www.openbsd.org/papers/bcrypt-paper.ps + * @param data salt information + * @param key password information + */ + private void ekskey(byte data[], byte key[]) { + int i; + int koffp[] = { 0 }, doffp[] = { 0 }; + int lr[] = { 0, 0 }; + int plen = P.length, slen = S.length; + + for (i = 0; i < plen; i++) { + P[i] = P[i] ^ streamtoword(key, koffp); + } + + for (i = 0; i < plen; i += 2) { + lr[0] ^= streamtoword(data, doffp); + lr[1] ^= streamtoword(data, doffp); + encipher(lr, 0); + P[i] = lr[0]; + P[i + 1] = lr[1]; + } + + for (i = 0; i < slen; i += 2) { + lr[0] ^= streamtoword(data, doffp); + lr[1] ^= streamtoword(data, doffp); + encipher(lr, 0); + S[i] = lr[0]; + S[i + 1] = lr[1]; + } + } + + static long roundsForLogRounds(int log_rounds) { + if (log_rounds < 4 || log_rounds > 31) { + throw new IllegalArgumentException("Bad number of rounds"); + } + return 1L << log_rounds; + } + + /** + * Perform the central password hashing step in the bcrypt scheme + * @param password the password to hash + * @param salt the binary salt to hash with the password + * @param log_rounds the binary logarithm of the number of rounds of hashing to apply + * @return an array containing the binary hashed password + */ + private byte[] crypt_raw(byte password[], byte salt[], int log_rounds) { + int cdata[] = (int[]) bf_crypt_ciphertext.clone(); + int clen = cdata.length; + byte ret[]; + + long rounds = roundsForLogRounds(log_rounds); + + init_key(); + ekskey(salt, password); + for (long i = 0; i < rounds; i++) { + key(password); + key(salt); + } + + for (int i = 0; i < 64; i++) { + for (int j = 0; j < (clen >> 1); j++) { + encipher(cdata, j << 1); + } + } + + ret = new byte[clen * 4]; + for (int i = 0, j = 0; i < clen; i++) { + ret[j++] = (byte) ((cdata[i] >> 24) & 0xff); + ret[j++] = (byte) ((cdata[i] >> 16) & 0xff); + ret[j++] = (byte) ((cdata[i] >> 8) & 0xff); + ret[j++] = (byte) (cdata[i] & 0xff); + } + return ret; + } + + /** + * Hash a password using the OpenBSD bcrypt scheme + * @param password the password to hash + * @param salt the salt to hash with (perhaps generated using BCrypt.gensalt) + * @return the hashed password + * @throws IllegalArgumentException if invalid salt is passed + */ + public static String hashpw(String password, String salt) throws IllegalArgumentException { + BCrypt B; + String real_salt; + byte passwordb[], saltb[], hashed[]; + char minor = (char) 0; + int rounds, off = 0; + StringBuilder rs = new StringBuilder(); + + if (salt == null) { + throw new IllegalArgumentException("salt cannot be null"); + } + + int saltLength = salt.length(); + + if (saltLength < 28) { + throw new IllegalArgumentException("Invalid salt"); + } + + if (salt.charAt(0) != '$' || salt.charAt(1) != '2') { + throw new IllegalArgumentException("Invalid salt version"); + } + if (salt.charAt(2) == '$') { + off = 3; + } + else { + minor = salt.charAt(2); + if (minor != 'a' || salt.charAt(3) != '$') { + throw new IllegalArgumentException("Invalid salt revision"); + } + off = 4; + } + + if (saltLength - off < 25) { + throw new IllegalArgumentException("Invalid salt"); + } + + // Extract number of rounds + if (salt.charAt(off + 2) > '$') { + throw new IllegalArgumentException("Missing salt rounds"); + } + rounds = Integer.parseInt(salt.substring(off, off + 2)); + + real_salt = salt.substring(off + 3, off + 25); + try { + passwordb = (password + (minor >= 'a' ? "\000" : "")).getBytes("UTF-8"); + } + catch (UnsupportedEncodingException uee) { + throw new AssertionError("UTF-8 is not supported"); + } + + saltb = decode_base64(real_salt, BCRYPT_SALT_LEN); + + B = new BCrypt(); + hashed = B.crypt_raw(passwordb, saltb, rounds); + + rs.append("$2"); + if (minor >= 'a') { + rs.append(minor); + } + rs.append("$"); + if (rounds < 10) { + rs.append("0"); + } + rs.append(rounds); + rs.append("$"); + encode_base64(saltb, saltb.length, rs); + encode_base64(hashed, bf_crypt_ciphertext.length * 4 - 1, rs); + return rs.toString(); + } + + /** + * Generate a salt for use with the BCrypt.hashpw() method + * @param log_rounds the log2 of the number of rounds of hashing to apply - the work + * factor therefore increases as 2**log_rounds. Minimum 4, maximum 31. + * @param random an instance of SecureRandom to use + * @return an encoded salt value + */ + public static String gensalt(int log_rounds, SecureRandom random) { + if (log_rounds < MIN_LOG_ROUNDS || log_rounds > MAX_LOG_ROUNDS) { + throw new IllegalArgumentException("Bad number of rounds"); + } + StringBuilder rs = new StringBuilder(); + byte rnd[] = new byte[BCRYPT_SALT_LEN]; + + random.nextBytes(rnd); + + rs.append("$2a$"); + if (log_rounds < 10) { + rs.append("0"); + } + rs.append(log_rounds); + rs.append("$"); + encode_base64(rnd, rnd.length, rs); + return rs.toString(); + } + + /** + * Generate a salt for use with the BCrypt.hashpw() method + * @param log_rounds the log2 of the number of rounds of hashing to apply - the work + * factor therefore increases as 2**log_rounds. Minimum 4, maximum 31. + * @return an encoded salt value + */ + public static String gensalt(int log_rounds) { + return gensalt(log_rounds, new SecureRandom()); + } + + /** + * Generate a salt for use with the BCrypt.hashpw() method, selecting a reasonable + * default for the number of hashing rounds to apply + * @return an encoded salt value + */ + public static String gensalt() { + return gensalt(GENSALT_DEFAULT_LOG2_ROUNDS); + } + + /** + * Check that a plaintext password matches a previously hashed one + * @param plaintext the plaintext password to verify + * @param hashed the previously-hashed password + * @return true if the passwords match, false otherwise + */ + public static boolean checkpw(String plaintext, String hashed) { + return equalsNoEarlyReturn(hashed, hashpw(plaintext, hashed)); + } + + static boolean equalsNoEarlyReturn(String a, String b) { + char[] caa = a.toCharArray(); + char[] cab = b.toCharArray(); + + if (caa.length != cab.length) { + return false; + } + + byte ret = 0; + for (int i = 0; i < caa.length; i++) { + ret |= caa[i] ^ cab[i]; + } + return ret == 0; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/passwordEncoder/BCryptPasswordEncoderUtils.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/passwordEncoder/BCryptPasswordEncoderUtils.java new file mode 100644 index 0000000..0be3f5b --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/util/passwordEncoder/BCryptPasswordEncoderUtils.java @@ -0,0 +1,79 @@ +package com.arm.equipment.system.data.util.passwordEncoder; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.security.SecureRandom; +import java.util.regex.Pattern; +/** + * + * + * @author: admin + * @time: 2022/9/16 11:20 + */ +public class BCryptPasswordEncoderUtils { + + private Pattern BCRYPT_PATTERN = Pattern + .compile("\\A\\$2a?\\$\\d\\d\\$[./0-9A-Za-z]{53}"); + private final Log logger = LogFactory.getLog(getClass()); + + private final int strength; + + private final SecureRandom random; + + public BCryptPasswordEncoderUtils() { + this(-1); + } + + /** + * @param strength the log rounds to use, between 4 and 31 + */ + public BCryptPasswordEncoderUtils(int strength) { + this(strength, null); + } + + /** + * @param strength the log rounds to use, between 4 and 31 + * @param random the secure random instance to use + */ + public BCryptPasswordEncoderUtils(int strength, SecureRandom random) { + if (strength != -1 && (strength < BCrypt.MIN_LOG_ROUNDS || strength > BCrypt.MAX_LOG_ROUNDS)) { + throw new IllegalArgumentException("Bad strength"); + } + this.strength = strength; + this.random = random; + } + + public static void main(String[] args) { + BCryptPasswordEncoderUtils da=new BCryptPasswordEncoderUtils(); + System.out.println(da.encode("123123")); + } + + public String encode(CharSequence rawPassword) { + String salt; + if (strength > 0) { + if (random != null) { + salt = BCrypt.gensalt(strength, random); + } else { + salt = BCrypt.gensalt(strength); + } + } else { + salt = BCrypt.gensalt(); + } + return BCrypt.hashpw(rawPassword.toString(), salt); + } + + public boolean matches(CharSequence rawPassword, String encodedPassword) { + if (encodedPassword == null || encodedPassword.length() == 0) { + logger.warn("Empty encoded password"); + return false; + } + + if (!BCRYPT_PATTERN.matcher(encodedPassword).matches()) { + logger.warn("Encoded password does not look like BCrypt"); + return false; + } + + return BCrypt.checkpw(rawPassword.toString(), encodedPassword); + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/RespJSON.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/RespJSON.java new file mode 100644 index 0000000..b8eb20c --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/RespJSON.java @@ -0,0 +1,153 @@ +package com.arm.equipment.system.data.vo; + + +import java.io.Serializable; + +/** + * action ajax封装json数据的对象 + * + * @author admin + */ +public class RespJSON implements Serializable { + + private static final long serialVersionUID = -1793734311569686636L; + + /** + * 结果代码 + */ + private Integer code; + + /** + * 结果描述 + */ + private String message; + + /** + * 数据 + */ + private Object data; + + /** + * 不允许外部new对象 + */ + private RespJSON() { + } + + /** + * 取得返回JsonResult对象 + * + * @param returnCode + * @return + */ + public static RespJSON returnCode(ReturnCode returnCode) { + RespJSON respJSON = new RespJSON(); + respJSON.setCode(returnCode.getCode()); + respJSON.setMessage(returnCode.getMsg()); + return respJSON; + } + + /** + * 返回成功的数据 + * + * @return + */ + public static RespJSON success() { + ReturnCode returnCode = ReturnCode.CODE_OK; + RespJSON respJSON = new RespJSON(); + respJSON.setCode(returnCode.getCode()); + respJSON.setMessage(returnCode.getMsg()); + return respJSON; + } + + /** + * 返回成功的数据 + * + * @param data + * @return + */ + public static RespJSON success(Object data) { + ReturnCode returnCode = ReturnCode.CODE_OK; + RespJSON respJSON = new RespJSON(); + respJSON.setCode(returnCode.getCode()); + respJSON.setMessage(returnCode.getMsg()); + respJSON.setData(data); + return respJSON; + } + + /** + * 返回自定义code以及message + */ + public static RespJSON returnCustomCodeWithMessage(Integer code, String message) { + RespJSON respJSON = new RespJSON(); + respJSON.setCode(code); + respJSON.setMessage(message); + return respJSON; + } + + /** + * 取得返回JsonResult对象 + * + * @param + * @param data + * @return + */ + public static RespJSON returnCode(ReturnCode returnCode, Object data) { + RespJSON respJSON = new RespJSON(); + respJSON.setCode(returnCode.getCode()); + respJSON.setMessage(returnCode.getMsg()); + respJSON.setData(data); + return respJSON; + } + + /** + * 取得返回JsonResult对象 + * + * @param returnCode + * @param msgData + * @return 返回信息的动态数据 + */ + public static RespJSON returnCodeWithMessage(ReturnCode returnCode, Object... msgData) { + RespJSON respJSON = new RespJSON(); + respJSON.setCode(returnCode.getCode()); + if (msgData != null && msgData.length > 0 && returnCode.getMsg() != null) { + respJSON.setMessage(String.format(returnCode.getMsg(), msgData)); + } else { + respJSON.setMessage(returnCode.getMsg()); + } + return respJSON; + } + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + /** + * 获取 数据 + * + * @return + */ + public Object getData() { + return data; + } + + /** + * 设置 数据 + * + * @param data + */ + public void setData(Object data) { + this.data = data; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/ReturnCode.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/ReturnCode.java new file mode 100644 index 0000000..ee33809 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/ReturnCode.java @@ -0,0 +1,69 @@ +package com.arm.equipment.system.data.vo; + +/** + * 返回错误码,对外接口一定要设置错误码 错误码按照顺序递增,不要重复 + */ +public enum ReturnCode { + + CODE_OK(200, "成功"), + + OPEN_API_CODE_OK(0, "成功"), + + SYS_ERROR(1, "系统繁忙,请联系管理员。"), + + LOGIN_TIMEOUT_ERROR(2, "登录已超时,请重新登录。"), + + PERMISSION_DENY(3, "当前用户,没有权限。"), + + PARAM_ERROR(4, "参数错误"), + + CUSTOM_EXCEPTION(5, "自定义异常"), + + SYS_PARAM_IS_NULL_ERROR(6, "入参%s不能为空"), + + PARSE_ERROR(7, "数据解析错误"), + + CUSTOM_MESSAGE(8, "%s"), + + NOT_LOGIN_ERROR(9, "用户未登录"), + + TOKEN_EXPIRATION_ERROR(9, "token过期"), + + INVALID_USER_ERROR(9, "无效用户"), + + VERSION_NEED_UPGRADE(10, "APP版本需要升级"), + + LOGON_USER(11, "该账户已注销"), + + /** + * The success. + */ + SUCCESS(0, "成功"), + + /** + * The fail. + */ + FAIL(-1, "系统繁忙,请稍后再试"), + ; + + private Integer code; + private String msg; + + ReturnCode(Integer code, String msg) { + this.code = code; + this.msg = msg; + } + + public Integer getCode() { + return this.code; + } + + public String getMsg() { + return this.msg; + } + + @Override + public String toString() { + return "code:" + code + ", msg:" + msg; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/dict/DictVO.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/dict/DictVO.java new file mode 100644 index 0000000..302c39e --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/dict/DictVO.java @@ -0,0 +1,46 @@ +package com.arm.equipment.system.data.vo.dict; + +import java.io.Serializable; + +/** + * 字典、枚举数据封装对象 + * @author admin + */ +public class DictVO implements Serializable { + + private String code; + private String text; + private Integer index; + + public DictVO() { + } + + public DictVO(String code, String text) { + this.code = code; + this.text = text; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public Integer getIndex() { + return index; + } + + public void setIndex(Integer index) { + this.index = index; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/file/FileResLibVO.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/file/FileResLibVO.java new file mode 100644 index 0000000..037638b --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/file/FileResLibVO.java @@ -0,0 +1,70 @@ +package com.arm.equipment.system.data.vo.file; + +/** + * 资源文件信息VO + * + * @author: admin + * @time: 2021/11/17 17:25 + */ +public class FileResLibVO { + /**文件路径*/ + private String path; + /**文件类型 1 图片 2 视频*/ + private Integer type; + /**文件大小*/ + private Long fileSize; + /** 时长(秒) */ + private Double duration; + /**图片高*/ + private Integer imgHeight; + /**图片宽*/ + private Integer imgWidth; + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public Long getFileSize() { + return fileSize; + } + + public void setFileSize(Long fileSize) { + this.fileSize = fileSize; + } + + public Double getDuration() { + return duration; + } + + public void setDuration(Double duration) { + this.duration = duration; + } + + public Integer getImgHeight() { + return imgHeight; + } + + public void setImgHeight(Integer imgHeight) { + this.imgHeight = imgHeight; + } + + public Integer getImgWidth() { + return imgWidth; + } + + public void setImgWidth(Integer imgWidth) { + this.imgWidth = imgWidth; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/file/UploadFileVO.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/file/UploadFileVO.java new file mode 100644 index 0000000..c546284 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/file/UploadFileVO.java @@ -0,0 +1,78 @@ +package com.arm.equipment.system.data.vo.file; + +/** + * 文件上传VO + */ +public class UploadFileVO { + private String fileName; + private Long fileSize; + private String key; + private String suffix; + private String hash; + private Float width; + private Float height; + + public UploadFileVO() { + } + + public UploadFileVO(String fileName, String key) { + this.fileName = fileName; + this.key = key; + } + + public String getSuffix() { + return suffix; + } + + public void setSuffix(String suffix) { + this.suffix = suffix; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public Long getFileSize() { + return fileSize; + } + + public void setFileSize(Long fileSize) { + this.fileSize = fileSize; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getHash() { + return hash; + } + + public void setHash(String hash) { + this.hash = hash; + } + + public Float getWidth() { + return width; + } + + public void setWidth(Float width) { + this.width = width; + } + + public Float getHeight() { + return height; + } + + public void setHeight(Float height) { + this.height = height; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/res/VideoVO.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/res/VideoVO.java new file mode 100644 index 0000000..3ae6d45 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/res/VideoVO.java @@ -0,0 +1,75 @@ +package com.arm.equipment.system.data.vo.res; + +/** + * + * + * @author: admin + * @time: 2022/9/16 15:00 + */ +public class VideoVO { + + private static final long serialVersionUID = 1231130572193539013L; + /** 视频地址 */ + private String path; + /** 时长(单位:秒) */ + private double duration; + /** 文章大小(单位:byte) */ + private long size; + + public VideoVO() { + } + + /** + * Gets path. + * + * @return the path + */ + public String getPath() { + return path; + } + + /** + * Sets path. + * + * @param path the path + */ + public void setPath(String path) { + this.path = path; + } + + /** + * Gets duration. + * + * @return the duration + */ + public double getDuration() { + return duration; + } + + /** + * Sets duration. + * + * @param duration the duration + */ + public void setDuration(double duration) { + this.duration = duration; + } + + /** + * Gets size. + * + * @return the size + */ + public long getSize() { + return size; + } + + /** + * Sets size. + * + * @param size the size + */ + public void setSize(long size) { + this.size = size; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/system/AddRoleVO.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/system/AddRoleVO.java new file mode 100644 index 0000000..83544ff --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/system/AddRoleVO.java @@ -0,0 +1,31 @@ +package com.arm.equipment.system.data.vo.system; + +import java.util.List; +/** + * + * + * @author: admin + * @time: 2022/9/16 11:20 + */ +public class AddRoleVO { + + private List newRole; + + private Long userId; + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public List getNewRole() { + return newRole; + } + + public void setNewRole(List newRole) { + this.newRole = newRole; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/system/SysDeptUserVO.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/system/SysDeptUserVO.java new file mode 100644 index 0000000..a4be16f --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/system/SysDeptUserVO.java @@ -0,0 +1,36 @@ +package com.arm.equipment.system.data.vo.system; + +import java.util.List; + +/** + * + * + * @author: admin + * @time: 2021/10/20 15:49 + */ +public class SysDeptUserVO { + + private Long id; + private String name; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public SysDeptUserVO(Long id, String name) { + this.id = id; + this.name = name; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/system/SysRoleResourceVO.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/system/SysRoleResourceVO.java new file mode 100644 index 0000000..bedb4c3 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/system/SysRoleResourceVO.java @@ -0,0 +1,35 @@ +package com.arm.equipment.system.data.vo.system; + +import java.util.List; + +/** + * + * + * @author: admin + * @time: 2021/10/20 15:49 + */ +public class SysRoleResourceVO { + + private List resourcesIds; + + private Long roleId; + + public SysRoleResourceVO() { + } + + public Long getRoleId() { + return roleId; + } + + public void setRoleId(Long roleId) { + this.roleId = roleId; + } + + public List getResourcesIds() { + return resourcesIds; + } + + public void setResourcesIds(List resourcesIds) { + this.resourcesIds = resourcesIds; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/system/VerifyCodeVO.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/system/VerifyCodeVO.java new file mode 100644 index 0000000..ec13d9f --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/java/com/arm/equipment/system/data/vo/system/VerifyCodeVO.java @@ -0,0 +1,43 @@ +package com.arm.equipment.system.data.vo.system; + + +import com.arm.equipment.system.data.domain.BaseDomain; + +/** + * 验证码VO + * + * @author ousei + * @date 2020年8月6日14:33:42 + */ +public class VerifyCodeVO extends BaseDomain { + /** 二维码 */ + private String code; + /** 图片数组 */ + private byte[] imgBytes; + /** 过期时间 */ + private long expireTime; + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public byte[] getImgBytes() { + return imgBytes; + } + + public void setImgBytes(byte[] imgBytes) { + this.imgBytes = imgBytes; + } + + public long getExpireTime() { + return expireTime; + } + + public void setExpireTime(long expireTime) { + this.expireTime = expireTime; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/application.yml b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/application.yml new file mode 100644 index 0000000..e69de29 diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/appUserMapper.xml b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/appUserMapper.xml new file mode 100644 index 0000000..d2f3d09 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/appUserMapper.xml @@ -0,0 +1,213 @@ + + + + + + + + + + + + + + + + + + + id,nickname,username,password,phone,status,login_time,create_time,update_time,remark + + + + + + AND id = #{id,jdbcType=BIGINT} + + + AND nickname = #{nickname,jdbcType=VARCHAR} + + + AND username = #{username,jdbcType=VARCHAR} + + + AND password = #{password,jdbcType=VARCHAR} + + + AND phone = #{phone,jdbcType=VARCHAR} + + + + AND status = #{status,jdbcType=INTEGER} + + + AND status != -9 + + + + AND login_time = #{loginTime,jdbcType=TIMESTAMP} + + + AND create_time = #{createTime,jdbcType=TIMESTAMP} + + + AND update_time = #{updateTime,jdbcType=TIMESTAMP} + + + AND remark = #{remark,jdbcType=VARCHAR} + + + + + + + + SELECT + + FROM app_user + + + + + INSERT INTO app_user + + + id, + + + nickname, + + + username, + + + password, + + + phone, + + + status, + + + login_time, + + create_time, + update_time, + + remark, + + + + + #{id,jdbcType=BIGINT}, + + + #{nickname,jdbcType=VARCHAR}, + + + #{username,jdbcType=VARCHAR}, + + + #{password,jdbcType=VARCHAR}, + + + #{phone,jdbcType=VARCHAR}, + + + #{status,jdbcType=INTEGER}, + + + #{loginTime,jdbcType=TIMESTAMP}, + + now(3), + now(3), + + #{remark,jdbcType=VARCHAR}, + + + + + + UPDATE app_user + + + nickname = #{param1.nickname,jdbcType=VARCHAR}, + + + username = #{param1.username,jdbcType=VARCHAR}, + + + password = #{param1.password,jdbcType=VARCHAR}, + + + phone = #{param1.phone,jdbcType=VARCHAR}, + + + status = #{param1.status,jdbcType=INTEGER}, + + + login_time = #{param1.loginTime,jdbcType=TIMESTAMP}, + + update_time = now(3), + + remark = #{param1.remark,jdbcType=VARCHAR}, + + + + + AND id = #{param2.id,jdbcType=BIGINT} + + + AND nickname = #{param2.nickname,jdbcType=VARCHAR} + + + AND username = #{param2.username,jdbcType=VARCHAR} + + + AND password = #{param2.password,jdbcType=VARCHAR} + + + AND phone = #{param2.phone,jdbcType=VARCHAR} + + + AND status = #{param2.status,jdbcType=INTEGER} + + + AND login_time = #{param2.loginTime,jdbcType=TIMESTAMP} + + + AND create_time = #{param2.createTime,jdbcType=TIMESTAMP} + + + AND update_time = #{param2.updateTime,jdbcType=TIMESTAMP} + + + AND remark = #{param2.remark,jdbcType=VARCHAR} + + + + + + + + + + + + + + diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/system/sysBaseParamMapper.xml b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/system/sysBaseParamMapper.xml new file mode 100644 index 0000000..fd0e6bf --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/system/sysBaseParamMapper.xml @@ -0,0 +1,192 @@ + + + + + + + + + + + + + + + + + + id,uni_code,value,description,operator,status,create_time,update_time,remark + + + + + + AND id = #{id,jdbcType=BIGINT} + + + AND uni_code = #{uniCode,jdbcType=VARCHAR} + + + AND value = #{value,jdbcType=VARCHAR} + + + AND description = #{description,jdbcType=VARCHAR} + + + AND operator = #{operator,jdbcType=VARCHAR} + + + AND status = #{status,jdbcType=INTEGER} + + + AND create_time = #{createTime,jdbcType=TIMESTAMP} + + + AND update_time = #{updateTime,jdbcType=TIMESTAMP} + + + AND remark = #{remark,jdbcType=VARCHAR} + + + + + + SELECT + + FROM sys_base_param + + + + + INSERT INTO sys_base_param + + + id, + + + uni_code, + + + value, + + + description, + + + operator, + + + status, + + create_time, + update_time, + + remark, + + + + + #{id,jdbcType=BIGINT}, + + + #{uniCode,jdbcType=VARCHAR}, + + + #{value,jdbcType=VARCHAR}, + + + #{description,jdbcType=VARCHAR}, + + + #{operator,jdbcType=VARCHAR}, + + + #{status,jdbcType=INTEGER}, + + now(3), + now(3), + + #{remark,jdbcType=VARCHAR}, + + + + + + UPDATE sys_base_param + + + uni_code = #{param1.uniCode,jdbcType=VARCHAR}, + + + value = #{param1.value,jdbcType=VARCHAR}, + + + description = #{param1.description,jdbcType=VARCHAR}, + + + operator = #{param1.operator,jdbcType=VARCHAR}, + + + status = #{param1.status,jdbcType=INTEGER}, + + update_time = now(3), + + remark = #{param1.remark,jdbcType=VARCHAR}, + + + + + AND id = #{param2.id,jdbcType=BIGINT} + + + AND uni_code = #{param2.uniCode,jdbcType=VARCHAR} + + + AND value = #{param2.value,jdbcType=VARCHAR} + + + AND description = #{param2.description,jdbcType=VARCHAR} + + + AND operator = #{param2.operator,jdbcType=VARCHAR} + + + AND status = #{param2.status,jdbcType=INTEGER} + + + AND create_time = #{param2.createTime,jdbcType=TIMESTAMP} + + + AND update_time = #{param2.updateTime,jdbcType=TIMESTAMP} + + + AND remark = #{param2.remark,jdbcType=VARCHAR} + + + + + + + + + + + + + + DELETE FROM sys_base_param WHERE id = #{id, jdbcType=VARCHAR} + + diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/system/sysLogMapper.xml b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/system/sysLogMapper.xml new file mode 100644 index 0000000..d28a120 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/system/sysLogMapper.xml @@ -0,0 +1,277 @@ + + + + + + + + + + + + + + + + + + + + + + + id,type,title,remote_addr,user_agent,request_uri,method,params,exception,status,operator,create_time,update_time,remark + + + + + + AND id = #{id,jdbcType=BIGINT} + + + AND type = #{type,jdbcType=INTEGER} + + + AND title = #{title,jdbcType=VARCHAR} + + + AND remote_addr = #{remoteAddr,jdbcType=VARCHAR} + + + AND user_agent = #{userAgent,jdbcType=VARCHAR} + + + AND request_uri = #{requestUri,jdbcType=VARCHAR} + + + AND method = #{method,jdbcType=VARCHAR} + + + AND params = #{params,jdbcType=VARCHAR} + + + AND exception = #{exception,jdbcType=VARCHAR} + + + + AND status = #{status,jdbcType=INTEGER} + + + AND status != -9 + + + + AND operator = #{operator,jdbcType=VARCHAR} + + + AND create_time = #{createTime,jdbcType=TIMESTAMP} + + + AND update_time = #{updateTime,jdbcType=TIMESTAMP} + + + AND remark = #{remark,jdbcType=VARCHAR} + + + + + + + + SELECT + + FROM sys_log + + + + + INSERT INTO sys_log + + + id, + + + type, + + + title, + + + remote_addr, + + + user_agent, + + + request_uri, + + + method, + + + params, + + + exception, + + + status, + + + operator, + + create_time, + update_time, + + remark, + + + + + #{id,jdbcType=BIGINT}, + + + #{type,jdbcType=INTEGER}, + + + #{title,jdbcType=VARCHAR}, + + + #{remoteAddr,jdbcType=VARCHAR}, + + + #{userAgent,jdbcType=VARCHAR}, + + + #{requestUri,jdbcType=VARCHAR}, + + + #{method,jdbcType=VARCHAR}, + + + #{params,jdbcType=VARCHAR}, + + + #{exception,jdbcType=VARCHAR}, + + + #{status,jdbcType=INTEGER}, + + + #{operator,jdbcType=VARCHAR}, + + now(3), + now(3), + + #{remark,jdbcType=VARCHAR}, + + + + + + UPDATE sys_log + + + type = #{param1.type,jdbcType=INTEGER}, + + + title = #{param1.title,jdbcType=VARCHAR}, + + + remote_addr = #{param1.remoteAddr,jdbcType=VARCHAR}, + + + user_agent = #{param1.userAgent,jdbcType=VARCHAR}, + + + request_uri = #{param1.requestUri,jdbcType=VARCHAR}, + + + method = #{param1.method,jdbcType=VARCHAR}, + + + params = #{param1.params,jdbcType=VARCHAR}, + + + exception = #{param1.exception,jdbcType=VARCHAR}, + + + status = #{param1.status,jdbcType=INTEGER}, + + + operator = #{param1.operator,jdbcType=VARCHAR}, + + update_time = now(3), + + remark = #{param1.remark,jdbcType=VARCHAR}, + + + + + AND id = #{param2.id,jdbcType=BIGINT} + + + AND type = #{param2.type,jdbcType=INTEGER} + + + AND title = #{param2.title,jdbcType=VARCHAR} + + + AND remote_addr = #{param2.remoteAddr,jdbcType=VARCHAR} + + + AND user_agent = #{param2.userAgent,jdbcType=VARCHAR} + + + AND request_uri = #{param2.requestUri,jdbcType=VARCHAR} + + + AND method = #{param2.method,jdbcType=VARCHAR} + + + AND params = #{param2.params,jdbcType=VARCHAR} + + + AND exception = #{param2.exception,jdbcType=VARCHAR} + + + AND status = #{param2.status,jdbcType=INTEGER} + + + AND operator = #{param2.operator,jdbcType=VARCHAR} + + + AND create_time = #{param2.createTime,jdbcType=TIMESTAMP} + + + AND update_time = #{param2.updateTime,jdbcType=TIMESTAMP} + + + AND remark = #{param2.remark,jdbcType=VARCHAR} + + + + + + + + + + + + + + diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/system/sysResourceMapper.xml b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/system/sysResourceMapper.xml new file mode 100644 index 0000000..7ba75f1 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/system/sysResourceMapper.xml @@ -0,0 +1,290 @@ + + + + + + + + + + + + + + + + + + + + + + + + id,name,url,parent_id,icon,sort,type,identity,is_show,status,operator,create_time,update_time,remark,root_path + + + + + + AND id = #{id,jdbcType=BIGINT} + + + AND name = #{name,jdbcType=VARCHAR} + + + AND url = #{url,jdbcType=VARCHAR} + + + AND parent_id = #{parentId,jdbcType=VARCHAR} + + + AND icon = #{icon,jdbcType=VARCHAR} + + + AND sort = #{sort,jdbcType=INTEGER} + + + AND type = #{type,jdbcType=INTEGER} + + + AND identity = #{identity,jdbcType=VARCHAR} + + + AND is_show = #{isShow,jdbcType=INTEGER} + + + AND status = #{status,jdbcType=INTEGER} + + + AND operator = #{operator,jdbcType=VARCHAR} + + + AND create_time = #{createTime,jdbcType=TIMESTAMP} + + + AND update_time = #{updateTime,jdbcType=TIMESTAMP} + + + AND remark = #{remark,jdbcType=VARCHAR} + + + AND root_path = #{rootPath,jdbcType=VARCHAR} + + + AND id IN + + #{id,jdbcType=VARCHAR} + + + + + + + SELECT + + FROM sys_resource + + + + + INSERT INTO sys_resource + + + id, + + + name, + + + url, + + + parent_id, + + + icon, + + + sort, + + + type, + + + identity, + + + is_show, + + + status, + + + operator, + + create_time, + update_time, + + remark, + + + root_path, + + + + + #{id,jdbcType=BIGINT}, + + + #{name,jdbcType=VARCHAR}, + + + #{url,jdbcType=VARCHAR}, + + + #{parentId,jdbcType=VARCHAR}, + + + #{icon,jdbcType=VARCHAR}, + + + #{sort,jdbcType=INTEGER}, + + + #{type,jdbcType=INTEGER}, + + + #{identity,jdbcType=VARCHAR}, + + + #{isShow,jdbcType=INTEGER}, + + + #{status,jdbcType=INTEGER}, + + + #{operator,jdbcType=VARCHAR}, + + now(3), + now(3), + + #{remark,jdbcType=VARCHAR}, + + + #{rootPath,jdbcType=VARCHAR}, + + + + + + UPDATE sys_resource + + + name = #{param1.name,jdbcType=VARCHAR}, + + + url = #{param1.url,jdbcType=VARCHAR}, + + + parent_id = #{param1.parentId,jdbcType=VARCHAR}, + + + icon = #{param1.icon,jdbcType=VARCHAR}, + + + sort = #{param1.sort,jdbcType=INTEGER}, + + + type = #{param1.type,jdbcType=INTEGER}, + + + identity = #{param1.identity,jdbcType=VARCHAR}, + + + is_show = #{param1.isShow,jdbcType=INTEGER}, + + + status = #{param1.status,jdbcType=INTEGER}, + + + operator = #{param1.operator,jdbcType=VARCHAR}, + + update_time = now(3), + + remark = #{param1.remark,jdbcType=VARCHAR}, + + + root_path = #{param1.rootPath,jdbcType=VARCHAR}, + + + + + AND id = #{param2.id,jdbcType=BIGINT} + + + AND name = #{param2.name,jdbcType=VARCHAR} + + + AND url = #{param2.url,jdbcType=VARCHAR} + + + AND parent_id = #{param2.parentId,jdbcType=VARCHAR} + + + AND icon = #{param2.icon,jdbcType=VARCHAR} + + + AND sort = #{param2.sort,jdbcType=INTEGER} + + + AND type = #{param2.type,jdbcType=INTEGER} + + + AND identity = #{param2.identity,jdbcType=VARCHAR} + + + AND is_show = #{param2.isShow,jdbcType=INTEGER} + + + AND status = #{param2.status,jdbcType=INTEGER} + + + AND operator = #{param2.operator,jdbcType=VARCHAR} + + + AND create_time = #{param2.createTime,jdbcType=TIMESTAMP} + + + AND update_time = #{param2.updateTime,jdbcType=TIMESTAMP} + + + AND remark = #{param2.remark,jdbcType=VARCHAR} + + + AND root_path = #{param2.rootPath,jdbcType=VARCHAR} + + + + + + + + + + + + diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/system/sysRoleMapper.xml b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/system/sysRoleMapper.xml new file mode 100644 index 0000000..65da52c --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/system/sysRoleMapper.xml @@ -0,0 +1,180 @@ + + + + + + + + + + + + + + + + + id,name,description,status,operator,create_time,update_time,remark + + + + + + AND id = #{id,jdbcType=BIGINT} + + + AND name = #{name,jdbcType=VARCHAR} + + + AND description = #{description,jdbcType=VARCHAR} + + + AND status = #{status,jdbcType=INTEGER} + + + AND operator = #{operator,jdbcType=VARCHAR} + + + AND create_time = #{createTime,jdbcType=TIMESTAMP} + + + AND update_time = #{updateTime,jdbcType=TIMESTAMP} + + + AND remark = #{remark,jdbcType=VARCHAR} + + + AND id IN + + #{id, jdbcType=VARCHAR} + + + + + + + SELECT + + FROM sys_role + + + + + INSERT INTO sys_role + + + id, + + + name, + + + description, + + + status, + + + operator, + + create_time, + update_time, + + remark, + + + + + #{id,jdbcType=BIGINT}, + + + #{name,jdbcType=VARCHAR}, + + + #{description,jdbcType=VARCHAR}, + + + #{status,jdbcType=INTEGER}, + + + #{operator,jdbcType=VARCHAR}, + + now(3), + now(3), + + #{remark,jdbcType=VARCHAR}, + + + + + + UPDATE sys_role + + + name = #{param1.name,jdbcType=VARCHAR}, + + + description = #{param1.description,jdbcType=VARCHAR}, + + + status = #{param1.status,jdbcType=INTEGER}, + + + operator = #{param1.operator,jdbcType=VARCHAR}, + + update_time = now(3), + + remark = #{param1.remark,jdbcType=VARCHAR}, + + + + + AND id = #{param2.id,jdbcType=BIGINT} + + + AND name = #{param2.name,jdbcType=VARCHAR} + + + AND description = #{param2.description,jdbcType=VARCHAR} + + + AND status = #{param2.status,jdbcType=INTEGER} + + + AND operator = #{param2.operator,jdbcType=VARCHAR} + + + AND create_time = #{param2.createTime,jdbcType=TIMESTAMP} + + + AND update_time = #{param2.updateTime,jdbcType=TIMESTAMP} + + + AND remark = #{param2.remark,jdbcType=VARCHAR} + + + + + + + + + + + + + + diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/system/sysRoleResourceMapper.xml b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/system/sysRoleResourceMapper.xml new file mode 100644 index 0000000..861076e --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/system/sysRoleResourceMapper.xml @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + id,sys_role_id,sys_resource_id,status,operator,create_time,update_time,remark + + + + + + AND id = #{id,jdbcType=BIGINT} + + + AND sys_role_id = #{sysRoleId,jdbcType=BIGINT} + + + AND sys_resource_id = #{sysResourceId,jdbcType=BIGINT} + + + AND status = #{status,jdbcType=INTEGER} + + + AND operator = #{operator,jdbcType=VARCHAR} + + + AND create_time = #{createTime,jdbcType=TIMESTAMP} + + + AND update_time = #{updateTime,jdbcType=TIMESTAMP} + + + AND remark = #{remark,jdbcType=VARCHAR} + + + + + + SELECT + + FROM sys_role_resource + + + + + INSERT INTO sys_role_resource + + + id, + + + sys_role_id, + + + sys_resource_id, + + + status, + + + operator, + + create_time, + update_time, + + remark, + + + + + #{id,jdbcType=BIGINT}, + + + #{sysRoleId,jdbcType=VARCHAR}, + + + #{sysResourceId,jdbcType=BIGINT}, + + + #{status,jdbcType=INTEGER}, + + + #{operator,jdbcType=VARCHAR}, + + now(3), + now(3), + + #{remark,jdbcType=VARCHAR}, + + + + + + UPDATE sys_role_resource + + + sys_role_id = #{param1.sysRoleId,jdbcType=BIGINT}, + + + sys_resource_id = #{param1.sysResourceId,jdbcType=BIGINT}, + + + status = #{param1.status,jdbcType=INTEGER}, + + + operator = #{param1.operator,jdbcType=VARCHAR}, + + update_time = now(3), + + remark = #{param1.remark,jdbcType=VARCHAR}, + + + + + AND id = #{param2.id,jdbcType=BIGINT} + + + AND sys_role_id = #{param2.sysRoleId,jdbcType=BIGINT} + + + AND sys_resource_id = #{param2.sysResourceId,jdbcType=BIGINT} + + + AND status = #{param2.status,jdbcType=INTEGER} + + + AND operator = #{param2.operator,jdbcType=VARCHAR} + + + AND create_time = #{param2.createTime,jdbcType=TIMESTAMP} + + + AND update_time = #{param2.updateTime,jdbcType=TIMESTAMP} + + + AND remark = #{param2.remark,jdbcType=VARCHAR} + + + + + + + + + + + + + + + delete from sys_role_resource + where sys_role_id = #{roleId,jdbcType=BIGINT} + + + + insert into sys_role_resource (id,sys_role_id,sys_resource_id,status,operator,create_time,update_time) + values + + ( + #{item.id,jdbcType=BIGINT}, #{item.sysRoleId,jdbcType=BIGINT}, #{item.sysResourceId,jdbcType=BIGINT}, + #{item.status,jdbcType=INTEGER}, #{item.operator,jdbcType=VARCHAR},now(3),now(3) + ) + + + + + diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/system/sysUserMapper.xml b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/system/sysUserMapper.xml new file mode 100644 index 0000000..78d0268 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/system/sysUserMapper.xml @@ -0,0 +1,257 @@ + + + + + + + + + + + + + + + + + + + + + + + id,username,password,phone,name,email,tag,status,operator,create_time,update_time,remark,is_second_landing + + + + + + AND id = #{id,jdbcType=BIGINT} + + + AND username = #{username,jdbcType=VARCHAR} + + + AND password = #{password,jdbcType=VARCHAR} + + + AND phone = #{phone,jdbcType=VARCHAR} + + + AND name = #{name,jdbcType=VARCHAR} + + + AND email = #{email,jdbcType=VARCHAR} + + + AND tag = #{tag,jdbcType=VARCHAR} + + + AND status = #{status,jdbcType=INTEGER} + + + AND operator = #{operator,jdbcType=VARCHAR} + + + AND create_time = #{createTime,jdbcType=TIMESTAMP} + + + AND update_time = #{updateTime,jdbcType=TIMESTAMP} + + + AND remark = #{remark,jdbcType=VARCHAR} + + + AND is_second_landing = #{isSecondLanding,jdbcType=INTEGER} + + + + + + + SELECT + + FROM sys_user + + + + + INSERT INTO sys_user + + + id, + + + username, + + + password, + + + phone, + + + name, + + + email, + + + tag, + + + status, + + + operator, + + create_time, + update_time, + + remark, + + + is_second_landing, + + + + + #{id,jdbcType=BIGINT}, + + + #{username,jdbcType=VARCHAR}, + + + #{password,jdbcType=VARCHAR}, + + + #{phone,jdbcType=VARCHAR}, + + + #{name,jdbcType=VARCHAR}, + + + #{email,jdbcType=VARCHAR}, + + + #{tag,jdbcType=VARCHAR}, + + + #{status,jdbcType=INTEGER}, + + + #{operator,jdbcType=VARCHAR}, + + now(3), + now(3), + + #{remark,jdbcType=VARCHAR}, + + + #{isSecondLanding,jdbcType=INTEGER}, + + + + + + UPDATE sys_user + + + username = #{param1.username,jdbcType=VARCHAR}, + + + password = #{param1.password,jdbcType=VARCHAR}, + + + phone = #{param1.phone,jdbcType=VARCHAR}, + + + name = #{param1.name,jdbcType=VARCHAR}, + + + email = #{param1.email,jdbcType=VARCHAR}, + + + tag = #{param1.tag,jdbcType=VARCHAR}, + + + status = #{param1.status,jdbcType=INTEGER}, + + + operator = #{param1.operator,jdbcType=VARCHAR}, + + update_time = now(3), + + remark = #{param1.remark,jdbcType=VARCHAR}, + + + is_second_landing = #{param1.isSecondLanding,jdbcType=INTEGER}, + + + + + AND id = #{param2.id,jdbcType=BIGINT} + + + AND username = #{param2.username,jdbcType=VARCHAR} + + + AND password = #{param2.password,jdbcType=VARCHAR} + + + AND phone = #{param2.phone,jdbcType=VARCHAR} + + + AND name = #{param2.name,jdbcType=VARCHAR} + + + AND email = #{param2.email,jdbcType=VARCHAR} + + + AND tag = #{param2.tag,jdbcType=VARCHAR} + + + AND status = #{param2.status,jdbcType=INTEGER} + + + AND operator = #{param2.operator,jdbcType=VARCHAR} + + + AND create_time = #{param2.createTime,jdbcType=TIMESTAMP} + + + AND update_time = #{param2.updateTime,jdbcType=TIMESTAMP} + + + AND remark = #{param2.remark,jdbcType=VARCHAR} + + + AND is_second_landing = #{param2.isSecondLanding,jdbcType=INTEGER} + + + + + + + + + + + + + + + diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/system/sysUserRoleMapper.xml b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/system/sysUserRoleMapper.xml new file mode 100644 index 0000000..4769cb7 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/system/sysUserRoleMapper.xml @@ -0,0 +1,193 @@ + + + + + + + + + + + + + + + + + id,sys_role_id,sys_user_id,status,operator,create_time,update_time,remark + + + + + + AND id = #{id,jdbcType=BIGINT} + + + AND sys_role_id = #{sysRoleId,jdbcType=BIGINT} + + + AND sys_user_id = #{sysUserId,jdbcType=BIGINT} + + + AND status = #{status,jdbcType=INTEGER} + + + AND operator = #{operator,jdbcType=VARCHAR} + + + AND create_time = #{createTime,jdbcType=TIMESTAMP} + + + AND update_time = #{updateTime,jdbcType=TIMESTAMP} + + + AND remark = #{remark,jdbcType=VARCHAR} + + + + + + SELECT + + FROM sys_user_role + + + + + INSERT INTO sys_user_role + + + id, + + + sys_role_id, + + + sys_user_id, + + + status, + + + operator, + + create_time, + update_time, + + remark, + + + + + #{id,jdbcType=BIGINT}, + + + #{sysRoleId,jdbcType=BIGINT}, + + + #{sysUserId,jdbcType=BIGINT}, + + + #{status,jdbcType=INTEGER}, + + + #{operator,jdbcType=VARCHAR}, + + now(3), + now(3), + + #{remark,jdbcType=VARCHAR}, + + + + + + UPDATE sys_user_role + + + sys_role_id = #{param1.sysRoleId,jdbcType=BIGINT}, + + + sys_user_id = #{param1.sysUserId,jdbcType=BIGINT}, + + + status = #{param1.status,jdbcType=INTEGER}, + + + operator = #{param1.operator,jdbcType=VARCHAR}, + + update_time = now(3), + + remark = #{param1.remark,jdbcType=VARCHAR}, + + + + + AND id = #{param2.id,jdbcType=BIGINT} + + + AND sys_role_id = #{param2.sysRoleId,jdbcType=BIGINT} + + + AND sys_user_id = #{param2.sysUserId,jdbcType=BIGINT} + + + AND status = #{param2.status,jdbcType=INTEGER} + + + AND operator = #{param2.operator,jdbcType=VARCHAR} + + + AND create_time = #{param2.createTime,jdbcType=TIMESTAMP} + + + AND update_time = #{param2.updateTime,jdbcType=TIMESTAMP} + + + AND remark = #{param2.remark,jdbcType=VARCHAR} + + + + + + + + + + + + + + DELETE FROM sys_user_role WHERE sys_user_id = #{userId,jdbcType=BIGINT} + + + + INSERT INTO sys_user_role + (sys_role_id,sys_user_id,status,operator,create_time,update_time) + VALUES + + ( + #{newRole,jdbcType=BIGINT}, + #{userId,jdbcType=BIGINT}, + 0, + #{operator,jdbcType=VARCHAR}, + now(3), + now(3) + ) + + + + diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/weaponryLendRecordMapper.xml b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/weaponryLendRecordMapper.xml new file mode 100644 index 0000000..aee499f --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/weaponryLendRecordMapper.xml @@ -0,0 +1,213 @@ + + + + + + + + + + + + + + + + + + + id,weaponry_id,weaponry_name,num,return_time,return_status,status,create_time,update_time,remark + + + + + + AND id = #{id,jdbcType=BIGINT} + + + AND weaponry_id = #{weaponryId,jdbcType=BIGINT} + + + AND weaponry_name = #{weaponryName,jdbcType=VARCHAR} + + + AND num = #{num,jdbcType=INTEGER} + + + AND return_time = #{returnTime,jdbcType=TIMESTAMP} + + + AND return_status = #{returnStatus,jdbcType=INTEGER} + + + + AND status = #{status,jdbcType=INTEGER} + + + AND status != -9 + + + + AND create_time = #{createTime,jdbcType=TIMESTAMP} + + + AND update_time = #{updateTime,jdbcType=TIMESTAMP} + + + AND remark = #{remark,jdbcType=VARCHAR} + + + + + + + + SELECT + + FROM weaponry_lend_record + + + + + INSERT INTO weaponry_lend_record + + + id, + + + weaponry_id, + + + weaponry_name, + + + num, + + + return_time, + + + return_status, + + + status, + + create_time, + update_time, + + remark, + + + + + #{id,jdbcType=BIGINT}, + + + #{weaponryId,jdbcType=BIGINT}, + + + #{weaponryName,jdbcType=VARCHAR}, + + + #{num,jdbcType=INTEGER}, + + + #{returnTime,jdbcType=TIMESTAMP}, + + + #{returnStatus,jdbcType=INTEGER}, + + + #{status,jdbcType=INTEGER}, + + now(3), + now(3), + + #{remark,jdbcType=VARCHAR}, + + + + + + UPDATE weaponry_lend_record + + + weaponry_id = #{param1.weaponryId,jdbcType=BIGINT}, + + + weaponry_name = #{param1.weaponryName,jdbcType=VARCHAR}, + + + num = #{param1.num,jdbcType=INTEGER}, + + + return_time = #{param1.returnTime,jdbcType=TIMESTAMP}, + + + return_status = #{param1.returnStatus,jdbcType=INTEGER}, + + + status = #{param1.status,jdbcType=INTEGER}, + + update_time = now(3), + + remark = #{param1.remark,jdbcType=VARCHAR}, + + + + + AND id = #{param2.id,jdbcType=BIGINT} + + + AND weaponry_id = #{param2.weaponryId,jdbcType=BIGINT} + + + AND weaponry_name = #{param2.weaponryName,jdbcType=VARCHAR} + + + AND num = #{param2.num,jdbcType=INTEGER} + + + AND return_time = #{param2.returnTime,jdbcType=TIMESTAMP} + + + AND return_status = #{param2.returnStatus,jdbcType=INTEGER} + + + AND status = #{param2.status,jdbcType=INTEGER} + + + AND create_time = #{param2.createTime,jdbcType=TIMESTAMP} + + + AND update_time = #{param2.updateTime,jdbcType=TIMESTAMP} + + + AND remark = #{param2.remark,jdbcType=VARCHAR} + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/weaponryMapper.xml b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/weaponryMapper.xml new file mode 100644 index 0000000..2a62ae4 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/weaponryMapper.xml @@ -0,0 +1,247 @@ + + + + + + + + + + + + + + + + + + + + + id,name,img_path,cartridge_capacity,bullet_caliber,effective_range,total_inventory,lock_inventory,status,create_time,update_time,remark + + + + + + AND id = #{id,jdbcType=BIGINT} + + + AND name = #{name,jdbcType=VARCHAR} + + + AND img_path = #{imgPath,jdbcType=VARCHAR} + + + AND cartridge_capacity = #{cartridgeCapacity,jdbcType=INTEGER} + + + AND bullet_caliber = #{bulletCaliber,jdbcType=DOUBLE} + + + AND effective_range = #{effectiveRange,jdbcType=INTEGER} + + + AND total_inventory = #{totalInventory,jdbcType=INTEGER} + + + AND lock_inventory = #{lockInventory,jdbcType=INTEGER} + + + + AND status = #{status,jdbcType=INTEGER} + + + AND status != -9 + + + + AND create_time = #{createTime,jdbcType=TIMESTAMP} + + + AND update_time = #{updateTime,jdbcType=TIMESTAMP} + + + AND remark = #{remark,jdbcType=VARCHAR} + + + AND lock_inventory >= #{lockInventoryStart,jdbcType=INTEGER} + + + + + + + SELECT + + FROM weaponry + + + + + INSERT INTO weaponry + + + id, + + + name, + + + img_path, + + + cartridge_capacity, + + + bullet_caliber, + + + effective_range, + + + total_inventory, + + + lock_inventory, + + + status, + + create_time, + update_time, + + remark, + + + + + #{id,jdbcType=BIGINT}, + + + #{name,jdbcType=VARCHAR}, + + + #{imgPath,jdbcType=VARCHAR}, + + + #{cartridgeCapacity,jdbcType=INTEGER}, + + + #{bulletCaliber,jdbcType=DOUBLE}, + + + #{effectiveRange,jdbcType=INTEGER}, + + + #{totalInventory,jdbcType=INTEGER}, + + + #{lockInventory,jdbcType=INTEGER}, + + + #{status,jdbcType=INTEGER}, + + now(3), + now(3), + + #{remark,jdbcType=VARCHAR}, + + + + + + UPDATE weaponry + + + name = #{param1.name,jdbcType=VARCHAR}, + + + img_path = #{param1.imgPath,jdbcType=VARCHAR}, + + + cartridge_capacity = #{param1.cartridgeCapacity,jdbcType=INTEGER}, + + + bullet_caliber = #{param1.bulletCaliber,jdbcType=DOUBLE}, + + + effective_range = #{param1.effectiveRange,jdbcType=INTEGER}, + + + total_inventory = #{param1.totalInventory,jdbcType=INTEGER}, + + + lock_inventory = #{param1.lockInventory,jdbcType=INTEGER}, + + + status = #{param1.status,jdbcType=INTEGER}, + + update_time = now(3), + + remark = #{param1.remark,jdbcType=VARCHAR}, + + + + + AND id = #{param2.id,jdbcType=BIGINT} + + + AND name = #{param2.name,jdbcType=VARCHAR} + + + AND img_path = #{param2.imgPath,jdbcType=VARCHAR} + + + AND cartridge_capacity = #{param2.cartridgeCapacity,jdbcType=INTEGER} + + + AND bullet_caliber = #{param2.bulletCaliber,jdbcType=DOUBLE} + + + AND effective_range = #{param2.effectiveRange,jdbcType=INTEGER} + + + AND total_inventory = #{param2.totalInventory,jdbcType=INTEGER} + + + AND lock_inventory = #{param2.lockInventory,jdbcType=INTEGER} + + + AND status = #{param2.status,jdbcType=INTEGER} + + + AND create_time = #{param2.createTime,jdbcType=TIMESTAMP} + + + AND update_time = #{param2.updateTime,jdbcType=TIMESTAMP} + + + AND remark = #{param2.remark,jdbcType=VARCHAR} + + + + + + + + + + + + + + diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/weaponryReturnRecordMapper.xml b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/weaponryReturnRecordMapper.xml new file mode 100644 index 0000000..748e395 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/main/resources/mybatis/weaponryReturnRecordMapper.xml @@ -0,0 +1,213 @@ + + + + + + + + + + + + + + + + + + + id,weaponry_id,weaponry_name,lend_record_id,num,return_time,status,create_time,update_time,remark + + + + + + AND id = #{id,jdbcType=BIGINT} + + + AND weaponry_id = #{weaponryId,jdbcType=BIGINT} + + + AND weaponry_name = #{weaponryName,jdbcType=VARCHAR} + + + AND lend_record_id = #{lendRecordId,jdbcType=BIGINT} + + + AND num = #{num,jdbcType=INTEGER} + + + AND return_time = #{returnTime,jdbcType=TIMESTAMP} + + + + AND status = #{status,jdbcType=INTEGER} + + + AND status != -9 + + + + AND create_time = #{createTime,jdbcType=TIMESTAMP} + + + AND update_time = #{updateTime,jdbcType=TIMESTAMP} + + + AND remark = #{remark,jdbcType=VARCHAR} + + + + + + + + SELECT + + FROM weaponry_return_record + + + + + INSERT INTO weaponry_return_record + + + id, + + + weaponry_id, + + + weaponry_name, + + + lend_record_id, + + + num, + + + return_time, + + + status, + + create_time, + update_time, + + remark, + + + + + #{id,jdbcType=BIGINT}, + + + #{weaponryId,jdbcType=BIGINT}, + + + #{weaponryName,jdbcType=VARCHAR}, + + + #{lendRecordId,jdbcType=BIGINT}, + + + #{num,jdbcType=INTEGER}, + + + #{returnTime,jdbcType=TIMESTAMP}, + + + #{status,jdbcType=INTEGER}, + + now(3), + now(3), + + #{remark,jdbcType=VARCHAR}, + + + + + + UPDATE weaponry_return_record + + + weaponry_id = #{param1.weaponryId,jdbcType=BIGINT}, + + + weaponry_name = #{param1.weaponryName,jdbcType=VARCHAR}, + + + lend_record_id = #{param1.lendRecordId,jdbcType=BIGINT}, + + + num = #{param1.num,jdbcType=INTEGER}, + + + return_time = #{param1.returnTime,jdbcType=TIMESTAMP}, + + + status = #{param1.status,jdbcType=INTEGER}, + + update_time = now(3), + + remark = #{param1.remark,jdbcType=VARCHAR}, + + + + + AND id = #{param2.id,jdbcType=BIGINT} + + + AND weaponry_id = #{param2.weaponryId,jdbcType=BIGINT} + + + AND weaponry_name = #{param2.weaponryName,jdbcType=VARCHAR} + + + AND lend_record_id = #{param2.lendRecordId,jdbcType=BIGINT} + + + AND num = #{param2.num,jdbcType=INTEGER} + + + AND return_time = #{param2.returnTime,jdbcType=TIMESTAMP} + + + AND status = #{param2.status,jdbcType=INTEGER} + + + AND create_time = #{param2.createTime,jdbcType=TIMESTAMP} + + + AND update_time = #{param2.updateTime,jdbcType=TIMESTAMP} + + + AND remark = #{param2.remark,jdbcType=VARCHAR} + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/java/com/arm/equipment/system/data/generator/Generator.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/java/com/arm/equipment/system/data/generator/Generator.java new file mode 100644 index 0000000..63f5dcc --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/java/com/arm/equipment/system/data/generator/Generator.java @@ -0,0 +1,250 @@ +package com.arm.equipment.system.data.generator; + + +import com.arm.equipment.system.data.generator.domain.ConnectInfo; +import com.arm.equipment.system.data.generator.domain.DoMain; +import com.arm.equipment.system.data.generator.domain.DoMainProperty; +import com.arm.equipment.system.data.generator.domain.FileInfo; +import com.arm.equipment.system.data.generator.util.JDBCUtil; +import com.arm.equipment.system.data.generator.util.StringUtil; +import org.apache.commons.lang3.StringUtils; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.util.*; + +/** + * 自动在com.xxx.entity.后追加。 + *

如:设置为equip,则会在com.xxx.domain.equip包下生成实体类 + *

其他文件类似,具体可以参考genConnectInfo方法中的设置 + *

多级目录用.分割,如: a.b.c. 则会在com.xxx.domain.a.b.c包下生成实体类 + *

实体类的类名根据表名生成。如:generator_test,则实体类名:GeneratorTest + */ +public class Generator { + /////////////////////////////////////一般只需修改下面两个参数///////////////////////////////////////////// + /** + * todo 修改包名 todo 修改包名 todo 修改包名 + */ + private static final String PACKAGE = "weaponry"; + + /** + * todo 修改表名 todo 修改表名 todo 修改表名 + */ + private static final String TABLE_NAME = "weaponry_return_record"; + /** + * 生成器类型 mysql es + * TODO 注意在这里放开下面注释 + */ + private static final String GENERATOR_TYPE = "mysql"; + //////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + + //sql1获取表信息: 第一列:表名,第二列:表注释 + private static String sql_table; + //sql2获取字段信息: 第一列:字段名称,第二列:字段注释,第三列:字段类型,第四列:varchar长度,第五列:是否可空 + private static String sql_fields; + //本地工程目录,如果不设置,则根据默认的target目录,来生成 + private static String projectPath; + //允许的数据库类型及映射关系 + private static Map dataTypeMap; + + static { + //有序 + dataTypeMap = new LinkedHashMap<>(); + //mysql + dataTypeMap.put("varchar", new String[]{"String", "VARCHAR"}); + dataTypeMap.put("text", new String[]{"String", "VARCHAR"}); + dataTypeMap.put("datetime", new String[]{"Date", "TIMESTAMP"}); + dataTypeMap.put("double", new String[]{"Double", "DOUBLE"}); + dataTypeMap.put("int", new String[]{"Integer", "INTEGER"}); + dataTypeMap.put("bigint", new String[]{"Long", "BIGINT"}); + dataTypeMap.put("time", new String[]{"LocalTime", "TIMESTAMP"}); + dataTypeMap.put("decimal", new String[]{"BigDecimal", "DECIMAL"}); + dataTypeMap.put("date", new String[]{"Date", "TIMESTAMP"}); + dataTypeMap.put("tinyint", new String[]{"Boolean", "TINYINT"}); + dataTypeMap.put("bit", new String[]{"Integer", "INTEGER"}); + } + + @Test + public void test() throws Exception { + + DoMain doMain = new DoMain(); + doMain.setGeneratorType(GENERATOR_TYPE); + JDBCUtil jdbcUtil = new JDBCUtil(genConnectInfo(doMain)); + List> executeSQL; + //第一次查询表信息 + executeSQL = jdbcUtil.executeSQL(sql_table); + + for (List list : executeSQL) { + //0 名称 + doMain.setClassName(StringUtil.getClassName(list.get(0))); + doMain.setNickName(StringUtil.makeFirstCharLow(doMain.getClassName())); + //1 注释 + String tableNote = list.get(1); + if (StringUtils.isEmpty(tableNote)) { + throw new Exception("表注释不能为空"); + } + doMain.setClassNote(tableNote); + doMain.setTableName(TABLE_NAME); + } + //第二次查询字段信息 + executeSQL = jdbcUtil.executeSQL(sql_fields); + jdbcUtil.closeConnection(); + + //检查主键 + StringUtil.checkPrimaryKey(executeSQL.get(0), doMain.getOracle()); + //获取主键类型 + doMain.setIdJavaType(StringUtil.getPrimaryKeyType(executeSQL.get(0), doMain.getOracle())); + + List doMainProperties = new ArrayList<>(); + for (List list : executeSQL) { + DoMainProperty doMainProperty = new DoMainProperty(); + //0 名称 + String colName = list.get(0); + doMainProperty.setColumnName(colName); + doMainProperty.setPropertyName(StringUtil.initCap(colName)); + //1 注释 + String columnNote = list.get(1); + if (StringUtils.isEmpty(columnNote)) { + throw new Exception(colName + "的字段注释不能为空"); + } + doMainProperty.setColumnNote(columnNote); + doMainProperty.setTerProperty(StringUtil.makeFirstCharUp(doMainProperty.getPropertyName())); + //2 类型 + String columnType = list.get(2); + for (String key : dataTypeMap.keySet()) { + if (columnType.startsWith(key)) { + doMainProperty.setJavaType(dataTypeMap.get(key)[0]); + doMainProperty.setJdbcType(dataTypeMap.get(key)[1]); + } + } + if (StringUtils.isEmpty(doMainProperty.getJavaType()) + && StringUtils.isEmpty(doMainProperty.getJdbcType())) { + throw new Exception(colName + "的数据库类型错误,请参照《开发规范》"); + } + //3字符串长度 + String stringMaxLength = list.get(3); + if (StringUtils.isNotEmpty(stringMaxLength)) { + doMainProperty.setStringMaxLength(Integer.valueOf(stringMaxLength)); + } + //4是否可空 + doMainProperty.setNullAble(true); + if (list.get(4).startsWith("N")) { + doMainProperty.setNullAble(false); + } + + + doMainProperties.add(doMainProperty); + } + doMain.setDoMainProperties(doMainProperties); + + if (StringUtils.isEmpty(projectPath)) { + projectPath = new File(Generator.class.getResource("/").toURI()).getParentFile().getParentFile().getPath(); + } + genFiles(doMain, projectPath); + + System.exit(0); + } + + /** + * 生成连接信息 + * + * @param doMain doMain + * @return ConnectInfo + * @throws Exception Exception + */ + private static ConnectInfo genConnectInfo(DoMain doMain) throws Exception { + if (StringUtil.isMysql(TABLE_NAME)) { + doMain.setOracle(false); + } else { + doMain.setOracle(true); + } + //各种包名 + StringBuilder daoPackage = new StringBuilder("com.arm.equipment.system.data.mapper"); + StringBuilder esPackage = new StringBuilder("com.arm.equipment.system.data.es"); + StringBuilder mapperPackage = new StringBuilder("mybatis"); + StringBuilder domainPackage = new StringBuilder("com.arm.equipment.system.data.domain"); + StringBuilder servicePackage = new StringBuilder("com.arm.equipment.system.data.service"); + StringBuilder controllerPackage = new StringBuilder("com.arm.equipment.system.admin.controller"); + if (StringUtils.isEmpty(PACKAGE)) { + throw new Exception("包名不能为空"); + } + ConnectInfo connectInfo = new ConnectInfo(); + //数据库名称 + String DBName = "arm-equipment-system"; + String url = "jdbc:mysql://127.0.0.1:3306/arm-equipment-system?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull"; + //查询准备 + connectInfo.setClassPath("/mysql-connector-java-6.0.6.jar"); + connectInfo.setDriverClass("com.mysql.jdbc.Driver"); + connectInfo.setUrl(url); + connectInfo.setUserName("root"); + connectInfo.setPassword(""); + + sql_table = "select table_name,table_comment from information_schema.TABLES " + + "where table_schema = '" + DBName + "' and table_name='" + TABLE_NAME + "'"; + sql_fields = "select column_name,column_comment,column_type,character_maximum_length,is_nullable " + + "from information_schema.COLUMNS where table_schema = '" + DBName + "' and table_name='" + + TABLE_NAME + "' ORDER BY ordinal_position ASC"; + //设置对应包名 + daoPackage.append(".").append(PACKAGE); + mapperPackage.append(".").append(PACKAGE); + esPackage.append(".").append(PACKAGE); + domainPackage.append(".").append(PACKAGE); + servicePackage.append(".").append(PACKAGE); + controllerPackage.append(".").append(PACKAGE); + + doMain.setPackageName(domainPackage.toString()); + doMain.setSimplePackageName(PACKAGE); + doMain.setDaoPackageName(daoPackage.toString()); + doMain.setEsPackageName(esPackage.toString()); + doMain.setMapperPackageName(mapperPackage.toString()); + doMain.setServicePackageName(servicePackage.toString()); + doMain.setControllerPackageName(controllerPackage.toString()); + return connectInfo; + } + + /** + * 生成对应的文件 + * + * @param doMain vm参数信息 + * @param projectPath 工程目录 + * @throws Exception Exception + */ + private static void genFiles(DoMain doMain, String projectPath) throws Exception { + Map paramMap = new HashMap<>(); + paramMap.put("doMain", doMain); + + //实体类 + FileInfo fileInfo = new FileInfo(); + fileInfo.setTargetProject(projectPath + "/src/main/java"); + fileInfo.setTargetPackage(doMain.getPackageName().toLowerCase()); + StringUtil.genTemplateFile("DoMain.vm", paramMap, fileInfo.toString() + "/" + doMain.getClassName() + ".java", true); + //DAO接口 + fileInfo.setTargetProject(projectPath + "/src/main/java"); + fileInfo.setTargetPackage(doMain.getDaoPackageName().toLowerCase()); + StringUtil.genTemplateFile("IDao.vm", paramMap, fileInfo.toString() + "/I" + doMain.getClassName() + "Mapper.java"); + + if ("mysql".equalsIgnoreCase(GENERATOR_TYPE)) { + //mapper + fileInfo.setTargetProject(projectPath + "/src/main/resources"); + fileInfo.setTargetPackage("/mybatis/"); + StringUtil.genTemplateFile("Mapper.vm", paramMap, fileInfo.toString() + "/" + doMain.getNickName() + "Mapper.xml", true); + } + +// Service + fileInfo.setTargetProject(projectPath + "/src/main/java"); + fileInfo.setTargetPackage(doMain.getServicePackageName().toLowerCase()); +// StringUtil.genTemplateFile("IService.vm", paramMap, fileInfo.toString() + "/I" + doMain.getClassName() + "Service.java"); + //Service impl +// StringUtil.genTemplateFile("IServiceImpl.vm", paramMap, fileInfo.toString() + "/impl/" + doMain.getClassName() + "ServiceImpl.java"); + + + // Controller + fileInfo.setTargetProject(new File(projectPath).getParentFile() + "/admin/src/main/java"); + fileInfo.setTargetPackage(doMain.getControllerPackageName().toLowerCase()); +// StringUtil.genTemplateFile("Controller.vm", paramMap, fileInfo.toString() + "/" + doMain.getClassName() + "Controller.java"); +//// // List vue +// StringUtil.genTemplateFile("List.vm", paramMap, fileInfo.toString() + "/" + doMain.getNickName() + "List.vue"); + + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/java/com/arm/equipment/system/data/generator/domain/ConnectInfo.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/java/com/arm/equipment/system/data/generator/domain/ConnectInfo.java new file mode 100644 index 0000000..1ac090e --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/java/com/arm/equipment/system/data/generator/domain/ConnectInfo.java @@ -0,0 +1,50 @@ +package com.arm.equipment.system.data.generator.domain; + +public class ConnectInfo { + private String classPath; + private String driverClass; + private String url; + private String userName; + private String password; + + public String getClassPath() { + return classPath; + } + + public void setClassPath(String classPath) { + this.classPath = classPath; + } + + public String getDriverClass() { + return driverClass; + } + + public void setDriverClass(String driverClass) { + this.driverClass = driverClass; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/java/com/arm/equipment/system/data/generator/domain/DoMain.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/java/com/arm/equipment/system/data/generator/domain/DoMain.java new file mode 100644 index 0000000..0b89a9d --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/java/com/arm/equipment/system/data/generator/domain/DoMain.java @@ -0,0 +1,171 @@ +package com.arm.equipment.system.data.generator.domain; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; + +public class DoMain { + private Boolean oracle; + private String tableName;//表名 + private String packageName; + private String simplePackageName; + private String daoPackageName; + private String esPackageName; + private String mapperPackageName; + private String servicePackageName; + private String controllerPackageName; + private String className;//实体类 类名 + private String nickName;//className 首字母小写 + private String classNote;//表注释 + private String idJavaType;//主键类型 + private String author = System.getProperty("user.name");//作者 + private String date = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss").format(new Date());//创建日期 + private List doMainProperties; + private String limitStatement = "LIMIT #{startIndex, jdbcType=INTEGER}, #{pageSize, jdbcType=INTEGER}"; + // 代码生成器类型 mysql es + private String generatorType; + + public String getGeneratorType() { + return generatorType; + } + + public void setGeneratorType(String generatorType) { + this.generatorType = generatorType; + } + + public String getEsPackageName() { + return esPackageName; + } + + public void setEsPackageName(String esPackageName) { + this.esPackageName = esPackageName; + } + + public String getLimitStatement() { + return limitStatement; + } + + public void setLimitStatement(String limitStatement) { + this.limitStatement = limitStatement; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + public String getDate() { + return date; + } + + public void setDate(String date) { + this.date = date; + } + + public String getIdJavaType() { + return idJavaType; + } + + public void setIdJavaType(String idJavaType) { + this.idJavaType = idJavaType; + } + + public String getSimplePackageName() { + return simplePackageName; + } + + public void setSimplePackageName(String simplePackageName) { + this.simplePackageName = simplePackageName; + } + + public String getControllerPackageName() { + return controllerPackageName; + } + + public void setControllerPackageName(String controllerPackageName) { + this.controllerPackageName = controllerPackageName; + } + + public Boolean getOracle() { + return oracle; + } + + public void setOracle(Boolean oracle) { + this.oracle = oracle; + } + + public String getTableName() { + return tableName; + } + + public void setTableName(String tableName) { + this.tableName = tableName; + } + + public String getPackageName() { + return packageName; + } + + public void setPackageName(String packageName) { + this.packageName = packageName; + } + + public String getDaoPackageName() { + return daoPackageName; + } + + public void setDaoPackageName(String daoPackageName) { + this.daoPackageName = daoPackageName; + } + + public String getMapperPackageName() { + return mapperPackageName; + } + + public void setMapperPackageName(String mapperPackageName) { + this.mapperPackageName = mapperPackageName; + } + + public String getServicePackageName() { + return servicePackageName; + } + + public void setServicePackageName(String servicePackageName) { + this.servicePackageName = servicePackageName; + } + + public String getClassName() { + return className; + } + + public void setClassName(String className) { + this.className = className; + } + + public String getNickName() { + return nickName; + } + + public void setNickName(String nickName) { + this.nickName = nickName; + } + + public String getClassNote() { + return classNote; + } + + public void setClassNote(String classNote) { + this.classNote = classNote; + } + + public List getDoMainProperties() { + return doMainProperties; + } + + public void setDoMainProperties(List doMainProperties) { + this.doMainProperties = doMainProperties; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/java/com/arm/equipment/system/data/generator/domain/DoMainProperty.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/java/com/arm/equipment/system/data/generator/domain/DoMainProperty.java new file mode 100644 index 0000000..dee493e --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/java/com/arm/equipment/system/data/generator/domain/DoMainProperty.java @@ -0,0 +1,78 @@ +package com.arm.equipment.system.data.generator.domain; + +public class DoMainProperty { + + private String columnName;//列名称 + private String columnNote;//列注释 + private String jdbcType; + private String propertyName;//实体类成员变量名称 + private String javaType; + private String terProperty;//实体类成员变量名称,首字母大写 + private Integer stringMaxLength;//字符串的最大长度(数据库中的字符串最好设置成字符,不要设置成字节) + private Boolean nullAble;//字段是否可空 + + public Integer getStringMaxLength() { + return stringMaxLength; + } + + public void setStringMaxLength(Integer stringMaxLength) { + this.stringMaxLength = stringMaxLength; + } + + public Boolean getNullAble() { + return nullAble; + } + + public void setNullAble(Boolean nullAble) { + this.nullAble = nullAble; + } + + public String getColumnName() { + return columnName; + } + + public void setColumnName(String columnName) { + this.columnName = columnName; + } + + public String getColumnNote() { + return columnNote; + } + + public void setColumnNote(String columnNote) { + this.columnNote = columnNote; + } + + public String getJdbcType() { + return jdbcType; + } + + public void setJdbcType(String jdbcType) { + this.jdbcType = jdbcType; + } + + public String getPropertyName() { + return propertyName; + } + + public void setPropertyName(String propertyName) { + this.propertyName = propertyName; + } + + public String getJavaType() { + return javaType; + } + + public void setJavaType(String javaType) { + this.javaType = javaType; + } + + public String getTerProperty() { + return terProperty; + } + + public void setTerProperty(String terProperty) { + this.terProperty = terProperty; + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/java/com/arm/equipment/system/data/generator/domain/FileInfo.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/java/com/arm/equipment/system/data/generator/domain/FileInfo.java new file mode 100644 index 0000000..394d509 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/java/com/arm/equipment/system/data/generator/domain/FileInfo.java @@ -0,0 +1,29 @@ +package com.arm.equipment.system.data.generator.domain; + +public class FileInfo { + private String targetProject; + + private String targetPackage; + + public String getTargetProject() { + return targetProject; + } + + public void setTargetProject(String targetProject) { + this.targetProject = targetProject; + } + + public String getTargetPackage() { + return targetPackage; + } + + public void setTargetPackage(String targetPackage) { + this.targetPackage = targetPackage; + } + + @Override + public String toString() { + return targetProject + "/" + targetPackage.replaceAll("\\.", "/"); + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/java/com/arm/equipment/system/data/generator/util/JDBCUtil.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/java/com/arm/equipment/system/data/generator/util/JDBCUtil.java new file mode 100644 index 0000000..2b8d828 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/java/com/arm/equipment/system/data/generator/util/JDBCUtil.java @@ -0,0 +1,68 @@ +package com.arm.equipment.system.data.generator.util; + + +import com.arm.equipment.system.data.generator.domain.ConnectInfo; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.sql.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + + +public class JDBCUtil { + + private Connection connection; + + public JDBCUtil(ConnectInfo connectInfo) throws Exception { + connection = getConnection(connectInfo); + } + + private Connection getConnection(ConnectInfo connectInfo) throws Exception { + ClassLoader loader = new URLClassLoader(new URL[]{new File(connectInfo.getClassPath()).toURI().toURL()}); + Class loadClass = loader.loadClass(connectInfo.getDriverClass()); + Properties info = new Properties(); + info.put("user", connectInfo.getUserName()); + info.put("password", connectInfo.getPassword()); + Driver driver = (Driver) loadClass.newInstance(); + Method connectMethod = null; + // 本类中没有找到方法,去父类中找 + while (loadClass != null) { + try { + connectMethod = loadClass.getDeclaredMethod("connect", String.class, Properties.class); + connectMethod.setAccessible(true); + break; + } catch (NoSuchMethodException e) { + loadClass = loadClass.getSuperclass(); + } + } + assert connectMethod != null; + return (Connection) connectMethod.invoke(driver, connectInfo.getUrl(), info); + } + + public List> executeSQL(String sql) throws Exception { + PreparedStatement prepareStatement = connection.prepareStatement(sql); + ResultSet resultSet = prepareStatement.executeQuery(); + List> listList = new ArrayList<>(); + while (resultSet.next()) { + List list = new ArrayList<>(); + // 特殊: 从1 开始 + for (int i = 1; i <= resultSet.getMetaData().getColumnCount(); i++) { + list.add(resultSet.getString(i)); + } + listList.add(list); + } + if (listList.size() < 1) { + throw new Exception("查询结果为空,请检查表是否存在"); + } + return listList; + } + + public void closeConnection() throws SQLException { + connection.close(); + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/java/com/arm/equipment/system/data/generator/util/StringUtil.java b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/java/com/arm/equipment/system/data/generator/util/StringUtil.java new file mode 100644 index 0000000..8614adc --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/java/com/arm/equipment/system/data/generator/util/StringUtil.java @@ -0,0 +1,210 @@ +package com.arm.equipment.system.data.generator.util; + +import org.apache.commons.lang.StringUtils; +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.Velocity; +import org.apache.velocity.app.VelocityEngine; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.FileWriter; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +public class StringUtil { + private final static Logger LOGGER = LoggerFactory.getLogger(StringUtil.class); + + private static VelocityEngine engine; + + static { + engine = new VelocityEngine(); + Properties properties = new Properties(); + properties.setProperty(Velocity.RESOURCE_LOADER, "class"); + properties.setProperty("class.resource.loader.class", + "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); + + properties.setProperty(Velocity.OUTPUT_ENCODING, "UTF-8"); + properties.setProperty(Velocity.INPUT_ENCODING, "UTF-8"); + //不生成日志文件 + properties.setProperty(Velocity.RUNTIME_LOG, ""); + try { + engine.init(properties); + } catch (Exception e) { + LOGGER.error(e.getMessage(), e); + } + } + + private StringUtil() { + } + + /** + * 通过模版生成文件,不覆盖之前的文件 + * + * @param vmFileName 模版文件名字 + * @param map 参数 + * @param outFileName 输出文件名字 + * @throws Exception 异常 + */ + public static void genTemplateFile(String vmFileName, Map map, String outFileName) throws Exception { + genTemplateFile(vmFileName, map, outFileName, true); + } + + /** + * 通过模版生成文件 + * + * @param vmFileName 模版文件名字 + * @param map 参数 + * @param outFileName 输出文件名字 + * @param override 是否覆盖 + * @throws Exception 异常 + */ + public static void genTemplateFile(String vmFileName, Map map, String outFileName, boolean override) throws Exception { + File file = new File(outFileName); + // 如果文件父路径不存在 + if (!file.getParentFile().exists()) { + if (!file.getParentFile().mkdirs()) { + throw new Exception("创建文件父路径失败,请检查"); + } + } + if (file.createNewFile()) { + System.out.println("创建文件成功" + file); + } else { + if (!override) { + System.out.println(file + "文件已存在,不更改任何内容"); + return; + } + System.out.println("覆盖!覆盖!覆盖!原文件成功" + file); + } + + Template template = engine.getTemplate("generator/" + vmFileName, "utf-8"); +// Template template = engine.getTemplate("file:C:/howjoy/IdeaWorkSpaces/flash-card-parent/data/src/test/resource/generator/DoMain.vm", "utf-8"); + VelocityContext ctx = new VelocityContext(); + for (String key : map.keySet()) { + ctx.put(key, map.get(key)); + } + try (FileWriter fileWriter = new FileWriter(file)) { + template.merge(ctx, fileWriter); + } + } + + /** + * 将带有 _ 的字符串 驼峰规范化 + * + * @param string 字符串 + * @return 规范化后的字符串 + */ + public static String initCap(String string) { + String[] split = string.toLowerCase().split("_"); + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < split.length; i++) { + if (i == 0) { + builder.append(split[i]); + } else { + builder.append(makeFirstCharUp(split[i])); + } + } + return builder.toString(); + } + + /** + * 获取实体类的className + * + * @param string 表名 + * @return className + * @throws Exception 表命名不规范 + */ + public static String getClassName(String string) throws Exception { + String[] split = string.toLowerCase().split("_"); + StringBuilder builder = new StringBuilder(); + for (String aSplit : split) { + if ("hj".equalsIgnoreCase(aSplit)) { + continue; + } + builder.append(makeFirstCharUp(aSplit)); + } + return builder.toString(); + + } + + public static String makeFirstCharUp(String string) { + char[] ch = string.toCharArray(); + if (ch[0] >= 'a' && ch[0] <= 'z') { + ch[0] = (char) (ch[0] - 32); + } + return new String(ch); + } + + public static String makeFirstCharLow(String string) { + char[] ch = string.toCharArray(); + if (ch[0] >= 'A' && ch[0] <= 'Z') { + ch[0] = (char) (ch[0] + 32); + } + return new String(ch); + } + + /** + * 根据表名判断数据库 + * + * @param tableName 表名 + */ + public static boolean isMysql(String tableName) throws Exception { + if (StringUtils.isEmpty(tableName)) { + throw new Exception("表名不能为空"); + } + char[] chars = tableName.replaceAll("_", "").toCharArray(); + boolean flag = false; + if (Character.isUpperCase(chars[0])) { + //判断后面的字符是否和首字母大写一致 + for (char aChar : chars) { + if (Character.isLowerCase(aChar)) { + throw new Exception("表名不符合规范"); + } + } + } else if (Character.isLowerCase(chars[0])) { + //判断后面的字符是否和首字母小写一致 + for (char aChar : chars) { + if (Character.isUpperCase(aChar)) { + throw new Exception("表名不符合规范"); + } + } + flag = true; + } else { + throw new Exception("表名不符合规范"); + } + return flag; + } + + /** + * 检查主键 + * + * @param firstColumn 查询出的第一列 + * @param oracle 数据库类型 + */ + public static void checkPrimaryKey(List firstColumn, boolean oracle) throws Exception { + if (!oracle) { + if (!firstColumn.get(0).equals("id")) { + throw new Exception("MYSQL表的第一列列名必须是:id"); + } + if (!(firstColumn.get(2).startsWith("bigint") || firstColumn.get(2).startsWith("varchar"))) { + throw new Exception("MYSQL表的第一列id类型必须是:bigint或者varchar"); + } + }else { + if (!(firstColumn.get(2).startsWith("NUMBER") || firstColumn.get(2).startsWith("VARCHAR2"))) { + throw new Exception("MYSQL表的第一列id类型必须是:NUMBER或者VARCHAR2"); + } + } + } + + /** + * 获取主键类型 + * + * @param firstColumn 查询出的第一列 + * @param oracle 数据库类型 + */ + public static String getPrimaryKeyType(List firstColumn, boolean oracle) { + return "String"; + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/BaseEsDao.vm b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/BaseEsDao.vm new file mode 100644 index 0000000..90568f0 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/BaseEsDao.vm @@ -0,0 +1,14 @@ +package ${doMain.esPackageName}; + + +import ${doMain.packageName}.${doMain.className}; +import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; + +/** +* $!{doMain.classNote} +* @author $!{doMain.author} +* @date $!{doMain.date} +*/ +public interface Base$!{doMain.className}EsDao extends ElasticsearchRepository<${doMain.className}, String> { + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/Controller.vm b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/Controller.vm new file mode 100644 index 0000000..9d91600 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/Controller.vm @@ -0,0 +1,98 @@ +package ${doMain.controllerPackageName}; + +import com.arm.equipment.system.admin.controller.BaseController; +import com.arm.equipment.system.admin.util.CurrentUserUtils; +import com.arm.equipment.system.data.domain.PageResult; +import com.arm.equipment.system.data.domain.system.SysUser; +import com.arm.equipment.system.data.util.WJAssert; +import com.arm.equipment.system.data.vo.RespJSON; +import ${doMain.packageName}.${doMain.className}; +import ${doMain.servicePackageName}.I${doMain.className}Service; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.ArrayList; + +/** + * ${doMain.classNote} + * + * @author ${doMain.author} + * @date ${doMain.date} + */ +@RestController +@RequestMapping("/${doMain.simplePackageName}/${doMain.nickName}") +public class ${doMain.className}Controller extends BaseController { + + @Autowired + private I${doMain.className}Service ${doMain.nickName}Service; + + /** + * 保存或更新 + * + * @param ${doMain.nickName}Req ${doMain.nickName}Req + * @return RespJSON + */ + @PostMapping("/save") + public RespJSON save(@RequestBody ${doMain.className} ${doMain.nickName}Req, @SessionAttribute(CurrentUserUtils.SYSTEM_USER)SysUser loginSysUser) { + ${doMain.nickName}Service.save(${doMain.nickName}Req, loginSysUser.getUsername()); + return RespJSON.success(); + } + + /** + * 分页查询 + * + * @param ${doMain.nickName}Req ${doMain.nickName}Req + * @return RespJSON + */ + @PostMapping("/getPageList") + public RespJSON getPageList(@RequestBody ${doMain.className} ${doMain.nickName}Req) { + int count = ${doMain.nickName}Service.getCount(${doMain.nickName}Req); + List<${doMain.className}> list = new ArrayList<>(); + if (count > 0) { + list = ${doMain.nickName}Service.getPageList(${doMain.nickName}Req); + } + PageResult result = new PageResult(${doMain.nickName}Req.getPageNo(), ${doMain.nickName}Req.getPageSize(), count, list); + return RespJSON.success(result); + } + + /** + * 主键查询 + * + * @param id id + * @return RespJSON + */ + @RequestMapping("/getOneById") + public RespJSON getOneById(Long id) { + return RespJSON.success(${doMain.nickName}Service.getOneById(id)); + } + + /** + * 审核 + * + * @param id id + * @return RespJSON + */ + @PostMapping("/audit") + @ResponseBody + public RespJSON audit(Long id, @SessionAttribute(CurrentUserUtils.SYSTEM_USER)SysUser loginSysUser) { + WJAssert.notNull(id, "ID 不合法"); + ${doMain.nickName}Service.audit(id, loginSysUser.getUsername()); + return RespJSON.success(); + } + + /** + * 取消审核 + * + * @param id id + * @return RespJSON + */ + @PostMapping("/unaudit") + @ResponseBody + public RespJSON unaudit(Long id, @SessionAttribute(CurrentUserUtils.SYSTEM_USER)SysUser loginSysUser) { + WJAssert.notNull(id, "ID 不合法"); + ${doMain.nickName}Service.unaudit(id, loginSysUser.getUsername()); + return RespJSON.success(); + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/DoMain.vm b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/DoMain.vm new file mode 100644 index 0000000..d1cdab4 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/DoMain.vm @@ -0,0 +1,36 @@ +package $!{doMain.packageName}; + +import com.arm.equipment.system.data.domain.BaseDomain; + +import java.util.Date; + +/** + * $!{doMain.classNote} + * + * @author $!{doMain.author} + * @date $!{doMain.date} + */ +#if($!{doMain.generatorType} == "es" || $!{doMain.generatorType} == "ES" ) +@Document(indexName = "$!{doMain.tableName}") +#end +public class $!{doMain.className} extends BaseDomain { +#foreach( $elem in $doMain.doMainProperties) +#if($!{elem.propertyName}!="id" && $!{elem.propertyName}!="createTime" && $!{elem.propertyName}!="updateTime" && $!{elem.propertyName}!="remark" && $!{elem.propertyName}!="operator" ) + /** $!{elem.columnNote} */ + private $elem.javaType $elem.propertyName; +#end +#end +#foreach( $elem in $doMain.doMainProperties) +#if($!{elem.propertyName}!="id" && $!{elem.propertyName}!="createTime" && $!{elem.propertyName}!="updateTime" && $!{elem.propertyName}!="remark" && $!{elem.propertyName}!="operator" ) + + public $elem.javaType get${elem.terProperty}() { + return $elem.propertyName; + } + + public void set${elem.terProperty}(${elem.javaType} ${elem.propertyName}) { + this.${elem.propertyName} = ${elem.propertyName}; + } + +#end +#end +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/EsDao.vm b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/EsDao.vm new file mode 100644 index 0000000..bad3e3e --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/EsDao.vm @@ -0,0 +1,157 @@ +package ${doMain.esPackageName}; + + +import com.arm.equipment.system.data.enums.dict.EnumEsSortType; +import BusinessException; +import $!{doMain.packageName}.$!{doMain.className}; +import $!{doMain.daoPackageName}.I$!{doMain.className}Mapper; +import org.apache.commons.lang3.StringUtils; +import org.elasticsearch.index.query.BoolQueryBuilder; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.search.sort.SortBuilder; +import org.elasticsearch.search.sort.SortBuilders; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; +import org.springframework.data.elasticsearch.core.SearchHit; +import org.springframework.data.elasticsearch.core.SearchHits; +import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; +import org.springframework.data.elasticsearch.core.query.Query; +import org.springframework.stereotype.Component; + +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +/** +* $!{doMain.classNote} +* @author $!{doMain.author} +* @date $!{doMain.date} +*/ +@Component +public class $!{doMain.className}EsDao implements I$!{doMain.className}Mapper { + + @Autowired + private Base$!{doMain.className}EsDao $!{doMain.nickName}EsDao; + + @Autowired + private ElasticsearchRestTemplate elasticsearchRestTemplate; + + @Override + public int insertSelective($!{doMain.className} req) { + req.setCreateTime(new Date()); + req.setUpdateTime(req.getCreateTime()); + $!{doMain.nickName}EsDao.save(req); + return 1; + } + + @Override + public int updateSelective($!{doMain.className} setParam, $!{doMain.className} whereParam) { + $!{doMain.className} updateReq = buildUpdateCondition(setParam); + updateReq.setId(whereParam.getId()); + $!{doMain.nickName}EsDao.save(updateReq); + return 1; + } + + @Override + public int getCount($!{doMain.className} req) { + BoolQueryBuilder queryBuilder = buildQueryBuilder(req); + //组合构建语句 + Query searchQuery = new NativeSearchQueryBuilder().withQuery(queryBuilder).build(); + long count = elasticsearchRestTemplate.count(searchQuery, $!{doMain.className}.class); + return Math.toIntExact(count); + } + + @Override + public $!{doMain.className} getOne($!{doMain.className} req) { + BoolQueryBuilder queryBuilder = buildQueryBuilder(req); + //组合构建语句 + Query searchQuery = new NativeSearchQueryBuilder().withQuery(queryBuilder).build(); + SearchHits<$!{doMain.className}> hits = elasticsearchRestTemplate.search(searchQuery, $!{doMain.className}.class); + $!{doMain.className} $!{doMain.nickName} = null; + if (hits.getTotalHits() > 0) { + $!{doMain.nickName} = hits.stream().map(SearchHit::getContent).findFirst().orElse(null); + } + return $!{doMain.nickName}; + } + + @Override + public List<$!{doMain.className}> getList($!{doMain.className} req) { + //构建排序条件 + SortBuilder sortBuilder = buildSortBuilder(req); + BoolQueryBuilder queryBuilder = buildQueryBuilder(req); + //组合构建语句 + Query searchQuery = new NativeSearchQueryBuilder().withQuery(queryBuilder).withSort(sortBuilder).build(); + SearchHits<$!{doMain.className}> hits = elasticsearchRestTemplate.search(searchQuery, $!{doMain.className}.class); + return hits.stream().map(SearchHit::getContent).collect(Collectors.toList()); + } + + @Override + public List<$!{doMain.className}> getPageList($!{doMain.className} req) { + //构建排序条件 + SortBuilder sortBuilder = buildSortBuilder(req); + BoolQueryBuilder queryBuilder = buildQueryBuilder(req); + //分页 + Pageable pageable = PageRequest.of(req.getPageNo() - 1, req.getPageSize()); + //组合构建语句 + Query searchQuery = new NativeSearchQueryBuilder().withQuery(queryBuilder).withSort(sortBuilder).withPageable(pageable).build(); + SearchHits<$!{doMain.className}> hits = elasticsearchRestTemplate.search(searchQuery, $!{doMain.className}.class); + return hits.stream().map(SearchHit::getContent).collect(Collectors.toList()); + } + + /** + * 构建查询条件 + * 注意: 生成代码字符串都为模糊查询,如果需要精确查询需要换为(QueryBuilders.termQuery("字段名.keyword")) + * @param req + * @return + */ + private BoolQueryBuilder buildQueryBuilder($!{doMain.className} req) { + BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery(); + +#foreach( $elem in $doMain.doMainProperties) +#if(${elem.javaType}=='String') + if (StringUtils.isNotBlank(req.get${elem.terProperty}())) { + queryBuilder.must(QueryBuilders.matchQuery("${elem.propertyName}", req.get${elem.terProperty}())); + } +#else + if (req.get${elem.terProperty}() != null) { + queryBuilder.must(QueryBuilders.termQuery("${elem.propertyName}", req.get${elem.terProperty}())); + } +#end +#end + return queryBuilder; + } + + /** + * 构建排序字段 + */ + private SortBuilder buildSortBuilder($!{doMain.className} req) { + //构建默认排序条件 + SortBuilder sortBuilder = SortBuilders.fieldSort(EnumEsSortType.UPDATE_TIME_DESC.getField()).order(EnumEsSortType.UPDATE_TIME_DESC.getSort()); + return sortBuilder; + } + + /** + * 构建更新字段 + * (理论上这里可以用BeanUtils.copyProperties(), 暂时先不用)) + * @param condition + */ + private $!{doMain.className} buildUpdateCondition($!{doMain.className} condition) { + $!{doMain.className} update = $!{doMain.nickName}EsDao.findById(condition.getId()).orElseThrow(() -> new BusinessException("数据不存在")); + update.setUpdateTime(new Date()); +#foreach( $elem in $doMain.doMainProperties) +#if(${elem.javaType}=='String') + if (StringUtils.isNotBlank(condition.get${elem.terProperty}())) { + update.set${elem.terProperty}(condition.get${elem.terProperty}()); + } +#else + if (condition.get${elem.terProperty}() != null) { + update.set${elem.terProperty}(condition.get${elem.terProperty}()); + } +#end +#end + return update; + } + +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/IDao.vm b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/IDao.vm new file mode 100644 index 0000000..aa1e79f --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/IDao.vm @@ -0,0 +1,64 @@ +package $!{doMain.daoPackageName}; + +import $!{doMain.packageName}.$!{doMain.className}; + +import java.util.List; + +/** + * $!{doMain.classNote} + * + * @author $!{doMain.author} + * @date $!{doMain.date} + */ +public interface I$!{doMain.className}Mapper { + + /** + * 插入 + * + * @param $!{doMain.nickName} $!{doMain.nickName} + * @return int + */ + int insertSelective($!{doMain.className} $!{doMain.nickName}); + + /** + * 更新 + * + * @param setParam setParam + * @param whereParam whereParam + * @return int + */ + int updateSelective($!{doMain.className} setParam, $!{doMain.className} whereParam); + + /** + * 数量 + * + * @param $!{doMain.nickName} $!{doMain.nickName} + * @return int + */ + int getCount($!{doMain.className} $!{doMain.nickName}); + + /** + * 单条 + * + * @param $!{doMain.nickName} $!{doMain.nickName} + * @return $!{doMain.className} + */ + $!{doMain.className} getOne($!{doMain.className} $!{doMain.nickName}); + + /** + * 多条 + * + * @param $!{doMain.nickName} $!{doMain.nickName} + * @return List<$!{doMain.className}> + */ + List<$!{doMain.className}> getList($!{doMain.className} $!{doMain.nickName}); + + /** + * 分页 + * + * @param $!{doMain.nickName} $!{doMain.nickName} + * @return List<$!{doMain.className}> + */ + List<$!{doMain.className}> getPageList($!{doMain.className} $!{doMain.nickName}); + +} \ No newline at end of file diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/IService.vm b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/IService.vm new file mode 100644 index 0000000..4b00b1b --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/IService.vm @@ -0,0 +1,88 @@ +package $!{doMain.servicePackageName}; + +import $!{doMain.packageName}.$!{doMain.className}; + +import java.util.List; + +/** + * $!{doMain.classNote} + * + * @author $!{doMain.author} + * @date $!{doMain.date} + */ +public interface I$!{doMain.className}Service { + /** + * 保存或更新 + * @param req + */ + void save($!{doMain.className} req, String operator); + + /** + * 插入 + * + * @param $!{doMain.nickName} $!{doMain.nickName} + * @return int + */ + int insertSelective($!{doMain.className} $!{doMain.nickName}); + + /** + * 主键更新 + * + * @param $!{doMain.nickName} $!{doMain.nickName} + * @return int + */ + int updateSelectiveById($!{doMain.className} $!{doMain.nickName}); + + /** + * 数量 + * + * @param $!{doMain.nickName} $!{doMain.nickName} + * @return int + */ + int getCount($!{doMain.className} $!{doMain.nickName}); + + /** + * 主键查询 + * + * @param id id + * @return $!{doMain.className} + */ + $!{doMain.className} getOneById(Long id); + + /** + * 多条 + * + * @param $!{doMain.nickName} $!{doMain.nickName} + * @return List<$!{doMain.className}> + */ + List<$!{doMain.className}> getList($!{doMain.className} $!{doMain.nickName}); + + /** + * 分页 + * + * @param $!{doMain.nickName} $!{doMain.nickName} + * @return List<$!{doMain.className}> + */ + List<$!{doMain.className}> getPageList($!{doMain.className} $!{doMain.nickName}); + + /** + * 审核 + * @param id + * @param operator + */ + void audit(Long id, String operator); + + /** + * 取消审核 + * @param id + * @param operator + */ + void unaudit(Long id, String operator); + + /** + * 删除 + * @param id + * @param operator + */ + void delete(Long id, String operator); +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/IServiceImpl.vm b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/IServiceImpl.vm new file mode 100644 index 0000000..a51d44e --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/IServiceImpl.vm @@ -0,0 +1,130 @@ +package $!{doMain.servicePackageName}.impl; + +import com.arm.equipment.system.data.enums.dict.EnumStatus; +import com.arm.equipment.system.data.util.WJAssert; +import com.arm.equipment.system.data.service.common.IIdWorkerService; +import $!{doMain.daoPackageName}.I$!{doMain.className}Mapper; +import $!{doMain.packageName}.$!{doMain.className}; +import $!{doMain.servicePackageName}.I$!{doMain.className}Service; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * $!{doMain.classNote} + * + * @author $!{doMain.author} + * @date $!{doMain.date} + */ +@Service +public class $!{doMain.className}ServiceImpl implements I$!{doMain.className}Service { + @Autowired +#if($!{doMain.generatorType} == "es" || $!{doMain.generatorType} == "ES" ) + @Qualifier("$!{doMain.nickName}EsDao") +#end + private I$!{doMain.className}Mapper $!{doMain.nickName}Mapper; + @Autowired + private IIdWorkerService idWorkerService; + + @Override + public void save($!{doMain.className} req, String operator) { + req.setOperator(operator); + if (null == req.getId()) { + insertSelective(req); + } else { + updateSelectiveById(req); + } + } + + @Override + public int insertSelective($!{doMain.className} req) { + req.setId(idWorkerService.getNextId()); + req.setStatus(EnumStatus.NEW.getCode()); + checkStringLength(req, false); + return $!{doMain.nickName}Mapper.insertSelective(req); + } + + @Override + public int updateSelectiveById($!{doMain.className} $!{doMain.nickName}) { + WJAssert.notNull($!{doMain.nickName}, "入参对象不能为空"); + WJAssert.notNull($!{doMain.nickName}.getId(), "id参数错误"); + $!{doMain.className} where = new $!{doMain.className}(); + where.setId($!{doMain.nickName}.getId()); + return $!{doMain.nickName}Mapper.updateSelective($!{doMain.nickName}, where); + } + + @Override + public int getCount($!{doMain.className} $!{doMain.nickName}) { + checkStringLength($!{doMain.nickName}, true); + return $!{doMain.nickName}Mapper.getCount($!{doMain.nickName}); + } + + @Override + public $!{doMain.className} getOneById(Long id) { + WJAssert.notNull(id, "id参数错误"); + $!{doMain.className} where = new $!{doMain.className}(); + where.setId(id); + return $!{doMain.nickName}Mapper.getOne(where); + } + + @Override + public List<$!{doMain.className}> getList($!{doMain.className} $!{doMain.nickName}) { + checkStringLength($!{doMain.nickName}, true); + return $!{doMain.nickName}Mapper.getList($!{doMain.nickName}); + } + + @Override + public List<$!{doMain.className}> getPageList($!{doMain.className} $!{doMain.nickName}) { + checkStringLength($!{doMain.nickName}, true); + return $!{doMain.nickName}Mapper.getPageList($!{doMain.nickName}); + } + + @Override + public void audit(Long id, String operator) { + $!{doMain.className} req = new $!{doMain.className}(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.AUDIT.getCode()); + updateSelectiveById(req); + } + + @Override + public void unaudit(Long id, String operator) { + $!{doMain.className} req = new $!{doMain.className}(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.NEW.getCode()); + updateSelectiveById(req); + } + + @Override + public void delete(Long id, String operator) { + $!{doMain.className} req = new $!{doMain.className}(); + req.setId(id); + req.setOperator(operator); + req.setStatus(EnumStatus.DEL.getCode()); + updateSelectiveById(req); + } + + /** + * 参数校验注解默认使用的方法 + */ + private void checkStringLength($!{doMain.className} $!{doMain.nickName}, boolean nullAble) { + WJAssert.notNull($!{doMain.nickName}, "入参对象不能为空"); +#foreach( $elem in $doMain.doMainProperties) +#if(${elem.propertyName}=='id'|| ${elem.propertyName}=='createTime' +|| ${elem.propertyName}=='updateTime') +#else +#if(${elem.javaType}=='String') + #if(${elem.nullAble}) + WJAssert.limitMaxLength($!{doMain.nickName}.get$!{elem.terProperty}(), true, $!{elem.stringMaxLength}, "$!{elem.columnNote}不合法!"); +#else + WJAssert.limitMaxLength($!{doMain.nickName}.get$!{elem.terProperty}(), nullAble, $!{elem.stringMaxLength}, "$!{elem.columnNote}不合法!"); +#end +#end +#end +#end + } +} diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/List.vm b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/List.vm new file mode 100644 index 0000000..c9c000e --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/List.vm @@ -0,0 +1,208 @@ + + + + + diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/Mapper.vm b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/Mapper.vm new file mode 100644 index 0000000..b3aae53 --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/data/src/test/resources/generator/Mapper.vm @@ -0,0 +1,137 @@ + + + + + + #foreach( $elem in $doMain.doMainProperties) + + #end + + + + #foreach( $elem in $doMain.doMainProperties)#if($velocityCount != $!{doMain.doMainProperties.size()})#if(($velocityCount - 1)%5!=0)${elem.columnName},#else${elem.columnName},#end#else$elem.columnName#end#end + + + + + + #foreach( $elem in $doMain.doMainProperties) + #if(${elem.propertyName}=='status') + + + AND status = #{status,jdbcType=INTEGER} + + + AND status != -9 + + + #else + #if(${elem.javaType}=='String') + + #else + + #end + AND ${elem.columnName} = #{${elem.propertyName},jdbcType=${elem.jdbcType}} + + #end + #end + + + + + + + SELECT + + FROM $!{doMain.tableName} + + + + + INSERT INTO $!{doMain.tableName} + + #foreach( $elem in $doMain.doMainProperties) + #if(${elem.propertyName}=='createTime'|| ${elem.propertyName}=='updateTime') + ${elem.columnName}, + #else#if(${elem.javaType}=='String') + + #else + + #end ${elem.columnName}, + + #end + #end + + + #foreach( $elem in $doMain.doMainProperties) + #if(${elem.propertyName}=='createTime'|| ${elem.propertyName}=='updateTime')now(3), + #else#if(${elem.javaType}=='String') + #else + + #end + #{${elem.propertyName},jdbcType=${elem.jdbcType}}, + + #end + #end + + + + + UPDATE $!{doMain.tableName} + +#foreach( $elem in $doMain.doMainProperties) +#if(!(${elem.propertyName}=='id'||${elem.propertyName}=='createTime')) +#if(${elem.propertyName}=='updateTime') + ${elem.columnName} = now(3), +#else +#if(${elem.javaType}=='String') +#if(${elem.nullAble}) + +#else + +#end +#else + +#end + ${elem.columnName} = #{param1.${elem.propertyName},jdbcType=${elem.jdbcType}}, + +#end +#end +#end + + + #foreach( $elem in $doMain.doMainProperties) + #if(${elem.javaType}=='String') + + #else + + #end + AND ${elem.columnName} = #{param2.${elem.propertyName},jdbcType=${elem.jdbcType}} + + #end + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/arm-equipment-system-parent/arm-equipment-system-parent/pom.xml b/src/arm-equipment-system-parent/arm-equipment-system-parent/pom.xml new file mode 100644 index 0000000..25664ca --- /dev/null +++ b/src/arm-equipment-system-parent/arm-equipment-system-parent/pom.xml @@ -0,0 +1,96 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.7.5 + + pom + com.arm.equipment.system + arm-equipment-system-parent + 0.0.1-SNAPSHOT + arm-equipment-system-parent + + + UTF-8 + UTF-8 + 1.8 + + + + + + + com.alibaba + fastjson + 1.2.83 + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 1.3.1 + + + mysql + mysql-connector-java + 8.0.18 + + + org.apache.commons + commons-lang3 + 3.7 + + + + javax.servlet + javax.servlet-api + 4.0.1 + + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + + + data + admin + api + +