commit 3294cc04bb6e913ef9bd48fb3bd39ea4080b2cb1 Author: chenxudong Date: Fri Dec 13 15:27:59 2024 +0800 第一次提交。 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f464f36 --- /dev/null +++ b/.gitignore @@ -0,0 +1,40 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store +.idea/ +logs/ diff --git a/electrmangnetic/pom.xml b/electrmangnetic/pom.xml new file mode 100644 index 0000000..4fe8767 --- /dev/null +++ b/electrmangnetic/pom.xml @@ -0,0 +1,169 @@ + + + 4.0.0 + + com.electromagnetic.data + electromagnetic-data-new + 1.0-SNAPSHOT + + + electrmangnetic + + + 8 + 8 + UTF-8 + 1.4.1.Final + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter + + + ch.qos.logback + logback-classic + + + org.slf4j + slf4j-log4j12 + + + org.apache.logging.log4j + log4j-to-slf4j + + + + + + cn.hutool + hutool-all + 5.8.22 + + + com.baomidou + mybatis-plus-boot-starter + 3.5.3.1 + + + mysql + mysql-connector-java + + + org.projectlombok + lombok + 1.18.34 + + + io.springfox + springfox-swagger2 + 2.7.0 + + + io.springfox + springfox-swagger-ui + 2.7.0 + + + com.electromagnetic.data + electromagnetic-common + 1.0-SNAPSHOT + compile + + + com.github.pagehelper + pagehelper + 5.1.2 + + + org.apache.commons + commons-lang3 + 3.8.1 + + + com.alibaba + druid + 1.1.10 + + + + org.apache.logging.log4j + log4j-api + 2.11.2 + + + org.apache.logging.log4j + log4j-core + 2.11.2 + + + org.apache.logging.log4j + log4j-jcl + 2.11.2 + + + + com.lmax + disruptor + 3.4.2 + + + + + org.apache.logging.log4j + log4j-slf4j-impl + 2.11.2 + + + org.springframework.boot + spring-boot-starter-test + + + org.mapstruct + mapstruct-processor + ${mapstruct.version} + + + org.mapstruct + mapstruct + ${mapstruct.version} + + + org.aspectj + aspectjweaver + 1.9.7 + + + + + + electromagnetic + + + org.springframework.boot + spring-boot-maven-plugin + 2.6.12 + + + + com.electromagnetic.industry.software.manage.Application + + + repackage + + + + + + + + + \ No newline at end of file diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/Application.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/Application.java new file mode 100644 index 0000000..facd78e --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/Application.java @@ -0,0 +1,11 @@ +package com.electromagnetic.industry.software.manage; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} \ No newline at end of file diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/aop/ServiceAspect.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/aop/ServiceAspect.java new file mode 100644 index 0000000..6a18aa9 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/aop/ServiceAspect.java @@ -0,0 +1,72 @@ +package com.electromagnetic.industry.software.manage.aop; + +import cn.hutool.json.JSONUtil; +import lombok.extern.slf4j.Slf4j; +import org.apache.catalina.connector.ResponseFacade; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import org.springframework.util.StopWatch; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import java.util.ArrayList; +import java.util.List; + +@Aspect +@Component +@Slf4j +public class ServiceAspect { + + /** + * 日志切面 + */ + @Around("execution(* com.electromagnetic.industry.software.manage.controller..*.*(..)))") + public Object process(ProceedingJoinPoint jp) throws Throwable { + String methodInfo = jp.getTarget().getClass().getSimpleName() + "." + + jp.getSignature().getName(); + Object[] args = jp.getArgs(); + String paramInfo = ""; + if (args != null && args.length > 0) { + if (args[0] != null && args[0].getClass() != ResponseFacade.class) { + try { + List list = new ArrayList<>(); + for (Object obj : jp.getArgs()) { + + if (obj instanceof ServletResponse) { + log.info("参数中有response"); + } else if (obj instanceof ServletRequest) { + log.info("参数中有request"); + } else if (obj instanceof MultipartFile) { + //文件不输出 + MultipartFile obj1 = (MultipartFile) obj; + log.info("参数中文件;文件名:{},文件大小:{}", obj1.getName(), obj1.getSize()); + break; + } else { + list.add(obj); + } + } + paramInfo = JSONUtil.toJsonStr(list); + } catch (Exception e) { + log.warn("切面异常", e.getMessage()); + } + } + } + log.info("请求接口开始:{},参数:{}", methodInfo, paramInfo); + long startTime = System.currentTimeMillis(); + StopWatch stopwatch = new StopWatch(); + stopwatch.start("接口:" + methodInfo); + Object rvt = jp.proceed(); + if (rvt instanceof ResponseEntity) { + return rvt; + } + String returnInfo = JSONUtil.toJsonStr(rvt); + log.info("请求接口结束:{},返回参数:{},接口耗时:{}", methodInfo, returnInfo, (System.currentTimeMillis() - startTime) + "毫秒"); + stopwatch.stop(); + log.debug(stopwatch.prettyPrint()); + return rvt; + } +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/config/LoginInterceptor.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/config/LoginInterceptor.java new file mode 100644 index 0000000..5fa6631 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/config/LoginInterceptor.java @@ -0,0 +1,76 @@ +package com.electromagnetic.industry.software.manage.config; + +import cn.hutool.core.date.SystemClock; +import com.electromagnetic.industry.software.common.cons.UserConstants; +import com.electromagnetic.industry.software.common.pojo.UserLoginInfo; +import com.electromagnetic.industry.software.common.util.TokenUtil; +import com.electromagnetic.industry.software.common.util.UserThreadLocal; +import com.electromagnetic.industry.software.manage.mapper.TokenMapper; +import com.electromagnetic.industry.software.manage.pojo.models.Token; +import io.jsonwebtoken.Claims; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.HandlerInterceptor; +import org.springframework.web.servlet.ModelAndView; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.Date; + +@Component +@Slf4j +public class LoginInterceptor implements HandlerInterceptor { + + @Resource + private TokenMapper tokenMapper; + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + + String token = request.getHeader("Authorization"); + if (token==null) { + log.error("Authorization header is null"); + response.setStatus(401); + return false; + } else { + token = token.substring(7); + } + boolean result = isTokenValid(token); + if (!result) { + log.error("Invalid token"); + response.setStatus(401); + return false; + } else { + Claims claims = TokenUtil.getLoginInfo(token); + if (claims==null) { + log.error("User info is missing"); + response.setStatus(401); + return false; + } else { + UserLoginInfo userLoginInfo = new UserLoginInfo(); + userLoginInfo.setUserId(claims.get(UserConstants.LOGIN_USER_ID, String.class)); + userLoginInfo.setUsername(claims.get(UserConstants.LOGIN_USER_NAME, String.class)); + userLoginInfo.setWorkNumber(claims.get(UserConstants.LOGIN_WORK_NUMBER, String.class)); + UserThreadLocal.set(userLoginInfo); + } + return true; + } + } + + @Override + public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { + + } + + @Override + public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { + UserThreadLocal.remove(); + } + + public Boolean isTokenValid(String tokenStr){ + Token token = tokenMapper.selectToken(tokenStr); + Date now = new Date(SystemClock.now()); + return token != null && now.before(token.getExpireAt()); + } +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/config/WebMvcConfig.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/config/WebMvcConfig.java new file mode 100644 index 0000000..10fd9c6 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/config/WebMvcConfig.java @@ -0,0 +1,40 @@ +package com.electromagnetic.industry.software.manage.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +import javax.annotation.Resource; + +/** + * @author + * @version $Id: d.java, v 0.1 2021-01-05 19:33 Exp $$ + */ +@Configuration +public class WebMvcConfig implements WebMvcConfigurer { + + @Resource + private LoginInterceptor loginInterceptor; + + /** + * + * @param registry registry + */ + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("swagger-ui.html") + .addResourceLocations("classpath:/META-INF/resources/"); + + registry.addResourceHandler("/webjars/**") + .addResourceLocations("classpath:/META-INF/resources/webjars/"); + } + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(loginInterceptor) + .addPathPatterns("/**") + .excludePathPatterns("/data/ed/user/login"); + } + +} \ No newline at end of file diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/controller/CategoryController.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/controller/CategoryController.java new file mode 100644 index 0000000..1177ab6 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/controller/CategoryController.java @@ -0,0 +1,27 @@ +package com.electromagnetic.industry.software.manage.controller; + +import com.electromagnetic.industry.software.common.resp.ElectromagneticResult; +import com.electromagnetic.industry.software.manage.service.CategoryService; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +@RequestMapping("/data/ed/category") +@RestController +public class CategoryController { + + @Resource + private CategoryService categoryService; + + /** + * 目录树查询 + */ + @ApiOperation(value = "目录树查询", notes = "") + @RequestMapping(value = "/tree", method = RequestMethod.GET) + public ElectromagneticResult categoryTree() { + return categoryService.getAllCategories(); + } +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/controller/EDDataController.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/controller/EDDataController.java new file mode 100644 index 0000000..4defbe6 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/controller/EDDataController.java @@ -0,0 +1,106 @@ +package com.electromagnetic.industry.software.manage.controller; + +import com.electromagnetic.industry.software.common.resp.*; +import com.electromagnetic.industry.software.manage.pojo.req.EDDataRequest; +import com.electromagnetic.industry.software.manage.pojo.req.FileChunkDTO; +import com.electromagnetic.industry.software.manage.service.EDDataService; +import io.swagger.annotations.ApiOperation; +import org.springframework.core.io.InputStreamResource; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.Date; + +@RequestMapping("/data/ed/file") +@RestController +public class EDDataController { + + + @Resource + private EDDataService edDataService; + + @ApiOperation(value = "新建文件夹",notes = "") + @RequestMapping(value = "/createFolder",method = RequestMethod.POST) + public ElectromagneticResult createFolder(@RequestBody EDDataRequest request){ + return edDataService.createFolder(request); + } + + + @ApiOperation(value = "获取文件信息列表",notes = "") + @RequestMapping(value = "/getFileInfoList",method = RequestMethod.POST) + public ElectromagneticResult getFileInfoList(@RequestBody EDDataRequest request){ + return edDataService.getDataInfoList(request); + } + + + @ApiOperation(value = "更新文件信息",notes = "") + @RequestMapping(value = "/updateFileInfo",method = RequestMethod.POST) + public ElectromagneticResult updateFileInfo(@RequestBody EDDataRequest request){ + return edDataService.updateFileInfo(request); + } + + + @ApiOperation(value = "获取子文件数量",notes = "") + @RequestMapping(value = "/getChildFileCount",method = RequestMethod.POST) + public ElectromagneticResult getChildFileCount(@RequestBody EDDataRequest request){ + return edDataService.getChildFileCount(request); + } + + + @ApiOperation(value = "上传",notes = "") + @RequestMapping(value = "/upload", consumes = "multipart/form-data",method = RequestMethod.POST) + public ElectromagneticResult upload(@RequestParam("parentId") String parentId, + @RequestParam("file") MultipartFile file, + @RequestParam("gmtBatchUpload") Long gmtBatchUpload){ + EDDataRequest request = new EDDataRequest(); + request.setParentId(parentId); + request.setFileData(file); + request.setGmtBatchUpload(new Date(gmtBatchUpload)); + return edDataService.uploadFile(request); + } + + + @ApiOperation(value = "下载",notes = "") + @RequestMapping(value = "/download",method = RequestMethod.GET) + public ResponseEntity download(@RequestParam String dataId, HttpServletResponse response) throws IOException { + return edDataService.download(dataId, response); + } + + + @ApiOperation(value = "数据导出",notes = "") + @RequestMapping(value = "/batchExport",method = RequestMethod.GET) + public ResponseEntity batchExport(@RequestParam String dataIdArr, HttpServletResponse response) throws IOException { + return edDataService.batchExport(dataIdArr, response); + } + + @ApiOperation(value = "获取已经上传的分片",notes = "") + @RequestMapping(value = "/getUploadedChunkNums",method = RequestMethod.GET) + public ElectromagneticResult getUploadedChunkNums(@RequestParam String identifier) { + return edDataService.getUploadedChunkNums(identifier); + } + + @ApiOperation(value = "合并分片",notes = "") + @RequestMapping(value = "/mergeChunks",method = RequestMethod.GET) + public ElectromagneticResult mergeChunks(@RequestParam String identifier, + @RequestParam String fileName, + @RequestParam Integer totalChunks) { + return edDataService.mergeChunks(identifier, fileName, totalChunks); + } + + @ApiOperation(value = "分片上传",notes = "") + @RequestMapping(value = "/batchImport",method = RequestMethod.POST) + public ElectromagneticResult batchImport(FileChunkDTO fileChunkDTO) { + return edDataService.batchImport(fileChunkDTO); + } + + @ApiOperation(value = "检查分片是否存在",notes = "") + @RequestMapping(value = "/batchImport",method = RequestMethod.GET) + public ElectromagneticResult checkChunkExist(FileChunkDTO fileChunkDTO) { + return edDataService.checkChunkExist(fileChunkDTO); + } + +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/controller/UserController.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/controller/UserController.java new file mode 100644 index 0000000..c9f1600 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/controller/UserController.java @@ -0,0 +1,71 @@ +package com.electromagnetic.industry.software.manage.controller; + +import com.electromagnetic.industry.software.common.resp.ElectromagneticResult; +import com.electromagnetic.industry.software.manage.pojo.req.*; +import com.electromagnetic.industry.software.manage.service.UserService; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; + +@RequestMapping("/data/ed/user") +@RestController +public class UserController { + + @Resource + private UserService userService; + + @ApiOperation(value = "登录", notes = "") + @PostMapping("/login") + public ElectromagneticResult login(@RequestBody UserLoginRequest loginRequest) { + return userService.login(loginRequest); + } + + @ApiOperation(value = "新增用户信息", notes = "") + @PostMapping("/createUser") + public ElectromagneticResult createUser(@RequestBody UserRequest userRequest) { + return userService.createUser(userRequest); + } + + @ApiOperation(value="编辑用户信息",notes = "") + @PutMapping("/updateUser") + public ElectromagneticResult updateUser(@RequestBody UserModiRequest userModiRequest){ + return userService.modifyUser(userModiRequest); + } + + @ApiOperation(value = "发布用户信息", notes = "") + @RequestMapping(value = "/publish", method = RequestMethod.POST) + public ElectromagneticResult publishUser(@RequestBody UserPublishRequest userPublishRequest) { + return userService.publishUser(userPublishRequest); + } + + @ApiOperation(value = "获取单条用户信息", notes = "") + @RequestMapping(value = "/getInfo", method = RequestMethod.GET) + public ElectromagneticResult getSingleUser(GetSingleUserRequest getSingleUserRequest) { + return userService.getSingleUser(getSingleUserRequest); + } + + @ApiOperation(value = "查询用户信息", notes = "") + @RequestMapping(value = "/list", method = RequestMethod.POST) + public ElectromagneticResult searchUser(@RequestBody SearchUserRequest searchUserRequest) { + return userService.searchUser(searchUserRequest); + } + + @ApiOperation(value = "校验工号唯一性", notes = "") + @RequestMapping(value = "/validateWorkNumber", method = RequestMethod.POST) + public ElectromagneticResult validateWorkNum(@RequestBody UserWorkNumRequest userWorkNumRequest) { + return userService.validateWorkNum(userWorkNumRequest); + } + + @ApiOperation(value="删除用户信息",notes="") + @PostMapping(value = "/deleteUser") + public ElectromagneticResult deleteUser(@RequestBody UserDeleteRequest userDeleteRequest) { + return userService.deleteUser(userDeleteRequest); + } + + @ApiOperation(value="登出", notes = "") + @RequestMapping(value = "/logout", method = RequestMethod.POST) + public ElectromagneticResult logout(@RequestHeader("Authorization") String token) { + return userService.logout(token); + } +} \ No newline at end of file diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/mapper/CategoryMapper.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/mapper/CategoryMapper.java new file mode 100644 index 0000000..3dcf249 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/mapper/CategoryMapper.java @@ -0,0 +1,43 @@ +package com.electromagnetic.industry.software.manage.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.electromagnetic.industry.software.manage.pojo.models.Category; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface CategoryMapper extends BaseMapper { + + /** + * 获取顶级节点 + * @return + */ + List selectTopCategories(); + + /** + * 获取所有节点 + * @return + */ + List selectAllCategories(); + + /** + * 获取节点通过编码ID + * @return + */ + List selectCategories(Category category); + + /** + * 获取子节点通过父ID + * @return + */ + List selectChildCategories(Category category); + + /** + * 创建目录树节点数据 + * @return + */ + Boolean createCategory(Category category); + + +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/mapper/EDDataMapper.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/mapper/EDDataMapper.java new file mode 100644 index 0000000..f864d85 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/mapper/EDDataMapper.java @@ -0,0 +1,33 @@ +package com.electromagnetic.industry.software.manage.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.electromagnetic.industry.software.manage.pojo.models.EDDataInfo; +import com.electromagnetic.industry.software.manage.pojo.other.EDDataParams; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + + +@Mapper +public interface EDDataMapper extends BaseMapper { + /** + * 创建文件/文件夹数据信息 + * @param edDataInfo + * @return + */ + Boolean createDataInfo(EDDataInfo edDataInfo); + + /** + * 获取文件信息列表 + * @param parames + * @return + */ + List getDataInfoList(EDDataParams parames); + + /** + * 更新文件信息 + * @param parames + * @return + */ + Boolean updateFileInfo(EDDataParams parames); +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/mapper/EDDataMappers.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/mapper/EDDataMappers.java new file mode 100644 index 0000000..df57f8c --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/mapper/EDDataMappers.java @@ -0,0 +1,35 @@ +package com.electromagnetic.industry.software.manage.mapper; + +import com.electromagnetic.industry.software.manage.pojo.models.EDDataInfo; +import com.electromagnetic.industry.software.manage.pojo.other.EDDataPage; +import com.electromagnetic.industry.software.manage.pojo.other.EDDataParams; +import com.electromagnetic.industry.software.manage.pojo.req.EDDataRequest; +import com.electromagnetic.industry.software.manage.pojo.resp.EDDataPageResponse; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface EDDataMappers { + + EDDataMappers INSTANCE= Mappers.getMapper(EDDataMappers.class); + + /** + * 文件数据扩展模型入参转换 + * @param request + * @return + */ + EDDataParams getEDDataParames(EDDataRequest request); + /** + * 文件数据扩展模型入参转换 + * @param request + * @return + */ + EDDataInfo getEDDataInfo(EDDataRequest request); + /** + * 指标卡扩展模型返回 + * @param edDataPage + * @return + */ + EDDataPageResponse getEDDataInfoToModel(EDDataPage edDataPage); + +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/mapper/TokenMapper.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/mapper/TokenMapper.java new file mode 100644 index 0000000..b61cb96 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/mapper/TokenMapper.java @@ -0,0 +1,31 @@ +package com.electromagnetic.industry.software.manage.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.electromagnetic.industry.software.manage.pojo.models.Token; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface TokenMapper extends BaseMapper { + + /** + * 插入 + * @param token + * @return + */ + int insert(Token token); + + /** + * 查询 + * @param token + * @return Token + */ + Token selectToken(String token); + + /** + * 删除token + * @param token + * @return + */ + int deleteToken(String token); + +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/mapper/UserMapper.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/mapper/UserMapper.java new file mode 100644 index 0000000..5940696 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/mapper/UserMapper.java @@ -0,0 +1,70 @@ +package com.electromagnetic.industry.software.manage.mapper; + +import com.electromagnetic.industry.software.manage.pojo.models.User; +import com.electromagnetic.industry.software.manage.pojo.other.PublishParam; +import com.electromagnetic.industry.software.manage.pojo.other.SearchKeyWords; +import com.electromagnetic.industry.software.manage.pojo.other.UserDeleteKeyWords; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface UserMapper { + + /** + * 插入 + * @param user + * @return + */ + int insert(User user); + + /** + * 编辑 + * @param user + * @return + */ + int modify(User user); + + /** + * 发布 + * @param publishParam + * @return + */ + int publish(PublishParam publishParam); + + /** + * 通过工号查询用户 + * @param workNumber + * @return + */ + User selectUserByWorkNumber(String workNumber); + + /** + * 通过用户编码查询用户 + * @param userId + * @return + */ + User getSingleUser(String userId); + + /** + * 通过用户编码查询用户 + * @param searchKeywords + * @return + */ + List search(SearchKeyWords searchKeywords); + + /** + * 查询数据总条目数 + * @param searchKeywords + * @return + */ + int getTotalCount (SearchKeyWords searchKeywords); + + /** + * 通过用户ID删除用户 + * @param userId + * @return + */ + int deleteUser(UserDeleteKeyWords userDeleteKeyWords); + +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/mapper/UserMappers.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/mapper/UserMappers.java new file mode 100644 index 0000000..c15c345 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/mapper/UserMappers.java @@ -0,0 +1,82 @@ +package com.electromagnetic.industry.software.manage.mapper; + +import com.electromagnetic.industry.software.common.pojo.UserLoginInfo; +import com.electromagnetic.industry.software.manage.pojo.models.User; +import com.electromagnetic.industry.software.manage.pojo.other.PublishParam; +import com.electromagnetic.industry.software.manage.pojo.other.SearchKeyWords; +import com.electromagnetic.industry.software.manage.pojo.other.SingleUserResponse; +import com.electromagnetic.industry.software.manage.pojo.other.UserDeleteKeyWords; +import com.electromagnetic.industry.software.manage.pojo.req.*; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +@Mapper +public interface UserMappers { + UserMappers INSTANCE= Mappers.getMapper(UserMappers.class); + + /** + * 用户Request转用户模型 + * @param userRequest + * @return + */ + User getUserRequestToModel(UserRequest userRequest); + + /** + * 用户登录Request转用户登录模型 + * @param loginRequest + * @return + */ + UserLoginInfo getUserLoginRequestToModel(UserLoginRequest loginRequest); + + /** + * 获取单条用户信息Request转用户模型 + * @param user + * @return + */ + SingleUserResponse getSingleUserToResponse(User user); + + + /** + * 用户发布request转用户发布参数模型 + * @param userPublishRequest + * @return + */ + PublishParam getUserPublishRequestToModel(UserPublishRequest userPublishRequest); + + /** + * 获取单条用户信息Request转用户模型 + * @param searchUserRequest + * @return + */ + SearchKeyWords getSearchKeywordsRequestToModel(SearchUserRequest searchUserRequest); + + /** + * 获取用户列表转response列表 + * @param users + * @return + */ + List userListToResponseList(List users); + + /** + * 编辑用户Request转用户模型 + * @param userModiRequest + * @return + */ + User getUserModiRequestToModel(UserModiRequest userModiRequest); + + /** + * 校验工号唯一性Request转用户模型 + * @param userWorkNumRequest + * @return + */ + User getUserWorkNumRequestToModel(UserWorkNumRequest userWorkNumRequest); + + /** + * 删除单条用户信息Request转用户模型 + * @param userDeleteRequest + * @return + */ + UserDeleteKeyWords getUserDeleteRequestToModel(UserDeleteRequest userDeleteRequest); +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/models/Category.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/models/Category.java new file mode 100644 index 0000000..2fc142a --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/models/Category.java @@ -0,0 +1,84 @@ +package com.electromagnetic.industry.software.manage.pojo.models; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@Data +@TableName("ed_category") +public class Category { + /** + * 主键ID + */ + private Long id; + + /** + * 目录类型ID + */ + private String categoryTypeId; + + /** + * 上级编码,为空则为一级 + */ + private String parentId; + + /** + * 目录编码 + */ + private String categoryId; + + /** + * 目录名称 + */ + private String categoryName; + + /** + * 目录状态 + */ + private String categoryStatus; + + /** + * 创建人 + */ + private String creator; + + /** + * 创建人姓名 + */ + private String creatorName; + + /** + * 创建时间 + */ + private Date gmtCreate; + + /** + * 编辑人 + */ + private String modifier; + + /** + * 编辑人姓名 + */ + private String modifierName; + + /** + * 编辑时间 + */ + private Date gmtModified; + + /** + * 是否有效:0-无效 1-有效 + */ + private int effectFlag; + + /** + * 子目录 + */ + @TableField(exist = false) + private List children = new ArrayList<>(); +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/models/EDDataInfo.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/models/EDDataInfo.java new file mode 100644 index 0000000..7aed008 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/models/EDDataInfo.java @@ -0,0 +1,99 @@ +package com.electromagnetic.industry.software.manage.pojo.models; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@TableName("ed_data_info") +@Data +public class EDDataInfo { + /** + * 主键ID + */ + private Long id; + /** + * 目录编码 + */ + private String categoryId; + /** + * 数据编码 + */ + private String dataId; + /** + * 数据可视化码 + */ + private String dataNo; + /** + * 数据名称 + */ + private String dataName; + /** + * 数据类型:folder文件夹;file文件 + */ + private String dataType; + /** + * 文件类型 + */ + private String fileType; + /** + * 当前版本 + */ + private String version; + /** + * 富文本内容 + */ + private String content; + /** + * 文件地址JSON + */ + private String implantJson; + /** + * 状态:publish:发布,occupy:占用 + */ + private String dataStatus; + /** + * 备注 + */ + private String note; + /** + * 编辑人 + */ + private String editor; + /** + * 批量上传时间 + */ + private Date gmtBatchUpload; + /** + * 保存状态 + */ + private String saveStatus; + /** + * 创建人 + */ + private String creator; + /** + * 创建人姓名 + */ + private String creatorName; + /** + * 创建时间 + */ + private Date gmtCreate; + /** + * 更新人 + */ + private String modifier; + /** + * 更新人姓名 + */ + private String modifierName; + /** + * 更新时间 + */ + private Date gmtModified; + /** + * 是否有效:0-无效 1-有效 + */ + private Integer effectFlag; +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/models/Token.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/models/Token.java new file mode 100644 index 0000000..ac2ceca --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/models/Token.java @@ -0,0 +1,41 @@ +package com.electromagnetic.industry.software.manage.pojo.models; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("tokens") +public class Token { + + /** + * 主键ID + */ + private Long id; + + /** + * 用户编码 + */ + private String userId; + + /** + * 令牌 + */ + private String token; + + /** + * 是否是长期令牌 + */ + private int isLongTerm; + + /** + * 创建时间 + */ + private Date createdAt; + + /** + * 过期时间 + */ + private Date expireAt; +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/models/User.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/models/User.java new file mode 100644 index 0000000..84ef804 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/models/User.java @@ -0,0 +1,107 @@ +package com.electromagnetic.industry.software.manage.pojo.models; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@TableName("ed_users") +@Data +public class User { + + /** + * 主键ID + */ + private Long id; + + /** + * 用户编码 + */ + private String userId; + + /** + * 用户姓名 + */ + private String userName; + + /** + * 工号 + */ + private String workNumber; + + /** + * 手机号 + */ + private String mobile; + + /** + * 所属部门 + */ + private String userDept; + + /** + * 职称 + */ + private String userTitle; + + /** + * 登录密码 + */ + private String userPwd; + + /** + * 入职日期 + */ + private Date joinTime; + + /** + * 工作状态 + */ + private String userStatus; + + /** + * 实习截止日期 + */ + private Date internshipEndDate; + + /** + * 是否已发布 + */ + private Integer isPublished; + + /** + * 盐 + */ + private String salt; + + /** + * 创建人 + */ + private String creator; + + /** + * 创建人姓名 + */ + private String creatorName; + /** + * 创建时间 + */ + private Date gmtCreate; + /** + * 更新人 + */ + private String modifier; + /** + * 更新人姓名 + */ + private String modifierName; + /** + * 更新时间 + */ + private Date gmtModified; + + /** + * 是否有效:0-无效 1-有效 + */ + private Integer effectFlag; +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/other/EDDataPage.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/other/EDDataPage.java new file mode 100644 index 0000000..f44d170 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/other/EDDataPage.java @@ -0,0 +1,23 @@ +package com.electromagnetic.industry.software.manage.pojo.other; + +import com.electromagnetic.industry.software.manage.pojo.models.EDDataInfo; +import com.github.pagehelper.PageInfo; +import lombok.Data; + +import java.io.Serializable; + +/** + * 分页综合返回 + * @author + * @version $Id: IndicatorCardPage.java, v 0.1 2024-08-14 17:30 + */ +@Data +public class EDDataPage implements Serializable { + + private static final long serialVersionUID = -6207631048120337133L; + /** + * 电磁数据-文件数据列表 + */ + private PageInfo edDataInfo; + +} \ No newline at end of file diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/other/EDDataParams.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/other/EDDataParams.java new file mode 100644 index 0000000..bbbfe8f --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/other/EDDataParams.java @@ -0,0 +1,80 @@ +package com.electromagnetic.industry.software.manage.pojo.other; + +import lombok.Data; +import org.springframework.web.multipart.MultipartFile; + +import java.io.Serializable; +import java.util.Date; + +@Data +public class EDDataParams implements Serializable { + private static final long serialVersionUID = -4835122199589863011L; + /** + * 当前页 + */ + private Integer pageIndex = 1; + /** + * 每页数据 + */ + private Integer pageSize = 10; + /** + * 操作用户id + */ + private String userId; + /** + * 用户名 + */ + private String userName; + /** + * 上级文件夹数据码,为空是顶级 + */ + private String parentId; + /** + * 文件数据编码 + */ + private String dataId; + /** + * 文件夹名称 + */ + private String name; + /** + * 文件类型 + */ + private String dataType; + /** + * 创建日期排序 + */ + private String gmtCreate; + /** + * 文件数据状态 + */ + private String dataStatus; + /** + * 备注 + */ + private String note; + /** + * 是否有效 + */ + private String effectFlag; + /** + * 关键词 + */ + private String keyWord; + /** + * 批量上传时间 + */ + private Date gmtBatchUpload; + /** + * 保存状态 + */ + private String saveStatus; + /** + * 文件数据编码数组 + */ + private String[] dataIdArr; + /** + * 文件数据 + */ + private MultipartFile fileData; +} \ No newline at end of file diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/other/PublishParam.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/other/PublishParam.java new file mode 100644 index 0000000..c9488e3 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/other/PublishParam.java @@ -0,0 +1,25 @@ +package com.electromagnetic.industry.software.manage.pojo.other; + +import lombok.Data; + +import java.util.List; + +@Data +public class PublishParam { + private static final long serialVersionUID = 1L; + + /** + * 用户编码 + */ + private List userIds; + + /** + * 编辑者 + */ + private String modifier; + + /** + * 编辑者姓名 + */ + private String modifierName; +} \ No newline at end of file diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/other/SearchKeyWords.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/other/SearchKeyWords.java new file mode 100644 index 0000000..3ec3e9d --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/other/SearchKeyWords.java @@ -0,0 +1,46 @@ +package com.electromagnetic.industry.software.manage.pojo.other; + +import lombok.Data; + +@Data +public class SearchKeyWords { + /** + * 搜索关键词 + */ + private String keyWord; + + /** + * 用户状态 + */ + private String userStatus; + + /** + * 用户发布状态 + */ + private String isPublished; + + /** + * 排序方式: "asc" 或 "desc" 或 “” + */ + private String gmtCreate; + + /** + * 排序方式: "asc" 或 "desc" 或 “” + */ + private String joinTime; + + /** + * 排序方式: "asc" 或 "desc" 或 “” + */ + private String internEndDate; + + /** + * 页码 + */ + private int pageIndex; + + /** + * 单页条目数量 + */ + private int pageSize; +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/other/SingleUserResponse.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/other/SingleUserResponse.java new file mode 100644 index 0000000..27d8652 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/other/SingleUserResponse.java @@ -0,0 +1,110 @@ +package com.electromagnetic.industry.software.manage.pojo.other; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.util.Date; + +@Data +public class SingleUserResponse { + + private static final long serialVersionUID = -7475233976453471059L; + + /** + * 主键ID + */ + private Long id; + + /** + * 用户编码 + */ + private String userId; + + /** + * 用户姓名 + */ + private String userName; + + /** + * 工号 + */ + private String workNumber; + + /** + * 手机号 + */ + private String mobile; + + /** + * 所属部门 + */ + private String userDept; + + /** + * 职称 + */ + private String userTitle; + + /** + * 登录密码 + */ + private String userPwd; + + /** + * 入职日期 + */ + @JsonFormat(pattern = "yyyy-MM-dd") + private Date joinTime; + + /** + * 工作状态 + */ + private String userStatus; + + /** + * 实习截止日期 + */ + @JsonFormat(pattern = "yyyy-MM-dd") + private Date internshipEndDate; + + /** + * 是否已发布 + */ + private Integer isPublished; + + /** + * 盐 + */ + private String salt; + + /** + * 创建人 + */ + private String creator; + + /** + * 创建人姓名 + */ + private String creatorName; + /** + * 创建时间 + */ + private Date gmtCreate; + /** + * 更新人 + */ + private String modifier; + /** + * 更新人姓名 + */ + private String modifierName; + /** + * 更新时间 + */ + private Date gmtModified; + + /** + * 是否有效:0-无效 1-有效 + */ + private Integer effectFlag; +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/other/UserDeleteKeyWords.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/other/UserDeleteKeyWords.java new file mode 100644 index 0000000..f68e060 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/other/UserDeleteKeyWords.java @@ -0,0 +1,27 @@ +package com.electromagnetic.industry.software.manage.pojo.other; + +import lombok.Data; + +@Data +public class UserDeleteKeyWords { + + /** + * 主键ID + */ + private Long id; + + /** + * 用户编码 + */ + private String userId; + + /** + * 更新人 + */ + private String modifier; + /** + * 更新人姓名 + */ + private String modifierName; + +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/BaseRequest.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/BaseRequest.java new file mode 100644 index 0000000..aa72004 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/BaseRequest.java @@ -0,0 +1,49 @@ +package com.electromagnetic.industry.software.manage.pojo.req; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class BaseRequest implements Serializable { + + private static final long serialVersionUID = -9017146892952264211L; + + /** + * 操作用户id + */ + private String userId; + + /** + * 用户部门 + */ + private String department; + + /** + * 用户名 + */ + private String userName; + + /** + * 调用服务ip + */ + private String ip; + + /** + * 调用服务app name + */ + private String appName; + /** + *人员编码 + */ + private String personNo; + /** + *人员姓名 + */ + private String personName; + /** + * 权限码 + */ + private String permissionCode; + +} \ No newline at end of file diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/EDDataRequest.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/EDDataRequest.java new file mode 100644 index 0000000..ec00f38 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/EDDataRequest.java @@ -0,0 +1,72 @@ +package com.electromagnetic.industry.software.manage.pojo.req; + +import lombok.Data; +import org.springframework.web.multipart.MultipartFile; + +import java.io.Serializable; +import java.util.Date; + +@Data +public class EDDataRequest extends BaseRequest implements Serializable { + + /** + * 当前页 + */ + private Integer pageIndex = 1; + /** + * 每页数据 + */ + private Integer pageSize = 10; + /** + * 上级文件夹数据码,为空是顶级 + */ + private String parentId; + /** + * 文件数据编码 + */ + private String dataId; + /** + * 文件夹名称 + */ + private String name; + /** + * 文件类型 + */ + private String dataType; + /** + * 创建日期排序 + */ + private String gmtCreate; + /** + * 文件数据状态 + */ + private String dataStatus; + /** + * 备注 + */ + private String note; + /** + * 是否有效 + */ + private String effectFlag; + /** + * 关键词 + */ + private String keyWord; + /** + * 批量上传时间 + */ + private Date gmtBatchUpload; + /** + * 保存状态 + */ + private String saveStatus; + /** + * 文件数据编码数组 + */ + private String[] dataIdArr; + /** + * 文件数据 + */ + private MultipartFile fileData; +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/EDDataResponse.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/EDDataResponse.java new file mode 100644 index 0000000..4770d9a --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/EDDataResponse.java @@ -0,0 +1,100 @@ +package com.electromagnetic.industry.software.manage.pojo.req; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +@Data +public class EDDataResponse implements Serializable { + + private static final long serialVersionUID = -4835122199589863011L; + /** + * 主键ID + */ + private Long id; + /** + * 目录编码 + */ + private String categoryId; + /** + * 数据编码 + */ + private String dataId; + /** + * 数据可视化码 + */ + private String dataNo; + /** + * 数据名称 + */ + private String dataName; + /** + * 数据类型:folder文件夹;file文件 + */ + private String dataType; + /** + * 文件类型 + */ + private String fileType; + /** + * 当前版本 + */ + private String version; + /** + * 富文本内容 + */ + private String content; + /** + * 文件地址JSON + */ + private String implantJson; + /** + * 状态:publish:发布,occupy:占用 + */ + private String dataStatus; + /** + * 备注 + */ + private String note; + /** + * 编辑人 + */ + private String editor; + /** + * 批量上传时间 + */ + private Date gmtBatchUpload; + /** + * 保存状态 + */ + private String saveStatus; + /** + * 创建人 + */ + private String creator; + /** + * 创建人姓名 + */ + private String creatorName; + /** + * 创建时间 + */ + private Date gmtCreate; + /** + * 更新人 + */ + private String modifier; + /** + * 更新人姓名 + */ + private String modifierName; + /** + * 更新时间 + */ + private Date gmtModified; + /** + * 是否有效:0-无效 1-有效 + */ + private Integer effectFlag; +} \ No newline at end of file diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/FileChunkDTO.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/FileChunkDTO.java new file mode 100644 index 0000000..17895c6 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/FileChunkDTO.java @@ -0,0 +1,18 @@ +package com.electromagnetic.industry.software.manage.pojo.req; + +import lombok.Data; +import org.springframework.web.multipart.MultipartFile; + +@Data +public class FileChunkDTO { + + private String identifier; + private long totalSize; + private MultipartFile file; + private String fileName; + private Integer chunkNumber; + private Long chunkSize; + private Long currentChunkSize; + private Integer totalChunks; + +} \ No newline at end of file diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/FileChunkResultDTO.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/FileChunkResultDTO.java new file mode 100644 index 0000000..043d119 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/FileChunkResultDTO.java @@ -0,0 +1,15 @@ +package com.electromagnetic.industry.software.manage.pojo.req; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Set; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class FileChunkResultDTO { + private Boolean skipUpload; + private Set uploaded; +} \ No newline at end of file diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/GetSingleUserRequest.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/GetSingleUserRequest.java new file mode 100644 index 0000000..0c5480b --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/GetSingleUserRequest.java @@ -0,0 +1,17 @@ +package com.electromagnetic.industry.software.manage.pojo.req; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class GetSingleUserRequest extends BaseRequest implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 用户编码 + */ + private String userId; + +} + diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/SearchUserRequest.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/SearchUserRequest.java new file mode 100644 index 0000000..74e7404 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/SearchUserRequest.java @@ -0,0 +1,51 @@ +package com.electromagnetic.industry.software.manage.pojo.req; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class SearchUserRequest extends BaseRequest implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 搜索关键词 + */ + private String keyWord; + + /** + * 用户状态 + */ + private String userStatus; + + /** + * 用户发布状态,1已发布,0未发布 + */ + private String isPublished; + + /** + * 排序方式: "asc" 或 "desc" 或 “” + */ + private String gmtCreate; + + /** + * 排序方式: "asc" 或 "desc" 或 “” + */ + private String joinTime; + + /** + * 排序方式: "asc" 或 "desc" 或 “” + */ + private String internEndDate; + + /** + * 页码 + */ + private int pageIndex; + + /** + * 单页条目数量 + */ + private int pageSize; +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/UserDeleteRequest.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/UserDeleteRequest.java new file mode 100644 index 0000000..53df248 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/UserDeleteRequest.java @@ -0,0 +1,17 @@ +package com.electromagnetic.industry.software.manage.pojo.req; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class UserDeleteRequest extends BaseRequest implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 用户编码 + */ + private String userId; + +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/UserLoginRequest.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/UserLoginRequest.java new file mode 100644 index 0000000..1f388b2 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/UserLoginRequest.java @@ -0,0 +1,19 @@ +package com.electromagnetic.industry.software.manage.pojo.req; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class UserLoginRequest extends BaseRequest implements Serializable { + + /** + * 工号 + */ + private String workNumber; + + /** + * 用户密码 + */ + private String userPwd; +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/UserModiRequest.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/UserModiRequest.java new file mode 100644 index 0000000..9c7458a --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/UserModiRequest.java @@ -0,0 +1,60 @@ +package com.electromagnetic.industry.software.manage.pojo.req; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +@Data +public class UserModiRequest extends BaseRequest implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 用户Id + */ + private String userId; + + /** + * 用户姓名 + */ + private String userName; + + /** + * 工号 + */ + private String workNumber; + + /** + * 手机号 + */ + private String mobile; + + /** + * 所属部门 + */ + private String userDept; + + /** + * 职称 + */ + private String userTitle; + + /** + * 入职日期 + */ + @JsonFormat(pattern = "yyyy-MM-dd") + private Date joinTime; + + /** + * 工作状态 + */ + private String userStatus; + + /** + * 实习截止日期 + */ + @JsonFormat(pattern = "yyyy-MM-dd") + private Date internshipEndDate; +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/UserPublishRequest.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/UserPublishRequest.java new file mode 100644 index 0000000..a04cb7d --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/UserPublishRequest.java @@ -0,0 +1,19 @@ +package com.electromagnetic.industry.software.manage.pojo.req; + + +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +@Data +public class UserPublishRequest extends BaseRequest implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 用户编码 + */ + private List userIds; + +} \ No newline at end of file diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/UserRequest.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/UserRequest.java new file mode 100644 index 0000000..dd4272e --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/UserRequest.java @@ -0,0 +1,56 @@ +package com.electromagnetic.industry.software.manage.pojo.req; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +@Data +public class UserRequest extends BaseRequest implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 用户姓名 + */ + private String userName; + + /** + * 工号 + */ + private String workNumber; + + /** + * 手机号 + */ + private String mobile; + + /** + * 所属部门 + */ + private String userDept; + + /** + * 职称 + */ + private String userTitle; + + /** + * 入职日期 + */ + @JsonFormat(pattern="yyyy-MM-dd") + private Date joinTime; + + /** + * 工作状态 + */ + private String userStatus; + + /** + * 实习截止日期 + */ + @JsonFormat(pattern="yyyy-MM-dd") + private Date internshipEndDate; + +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/UserWorkNumRequest.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/UserWorkNumRequest.java new file mode 100644 index 0000000..f1ebb67 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/req/UserWorkNumRequest.java @@ -0,0 +1,23 @@ +package com.electromagnetic.industry.software.manage.pojo.req; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class UserWorkNumRequest extends BaseRequest implements Serializable { + + private static final long serialVersionUID = 1L; + + + /** + * 工号 + */ + private String workNumber; + + /** + * 用户编号 + */ + private String userID; + +} \ No newline at end of file diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/resp/EDDataPageResponse.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/resp/EDDataPageResponse.java new file mode 100644 index 0000000..661f37d --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/resp/EDDataPageResponse.java @@ -0,0 +1,16 @@ +package com.electromagnetic.industry.software.manage.pojo.resp; + +import com.electromagnetic.industry.software.manage.pojo.req.EDDataResponse; +import com.github.pagehelper.PageInfo; +import lombok.Data; + +import java.io.Serializable; + +@Data +public class EDDataPageResponse implements Serializable { + private static final long serialVersionUID = 3464355768912308150L; + /** + * 指电磁数据-文件信息数据 + */ + private PageInfo edDataInfo; +} \ No newline at end of file diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/resp/UserLoginResponse.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/resp/UserLoginResponse.java new file mode 100644 index 0000000..0ac4e47 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/resp/UserLoginResponse.java @@ -0,0 +1,13 @@ +package com.electromagnetic.industry.software.manage.pojo.resp; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class UserLoginResponse implements Serializable { + + private String token; + + private String userId; +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/resp/UserSearchResponse.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/resp/UserSearchResponse.java new file mode 100644 index 0000000..afb98ca --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/resp/UserSearchResponse.java @@ -0,0 +1,23 @@ +package com.electromagnetic.industry.software.manage.pojo.resp; + +import com.electromagnetic.industry.software.manage.pojo.other.SingleUserResponse; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +@Data +public class UserSearchResponse implements Serializable { + private static final long serialVersionUID = -7475233976453471059L; + + /** + * 用户列表 + */ + private List userList; + + + /** + * 总数据数 + */ + private long totalCount; +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/CategoryService.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/CategoryService.java new file mode 100644 index 0000000..6c4ffa0 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/CategoryService.java @@ -0,0 +1,9 @@ +package com.electromagnetic.industry.software.manage.service; + +import com.electromagnetic.industry.software.common.resp.ElectromagneticResult; + +public interface CategoryService { + + ElectromagneticResult getAllCategories(); + +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/EDDataService.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/EDDataService.java new file mode 100644 index 0000000..f7c9c2a --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/EDDataService.java @@ -0,0 +1,99 @@ +package com.electromagnetic.industry.software.manage.service; + +import com.electromagnetic.industry.software.common.resp.ElectromagneticResult; +import com.electromagnetic.industry.software.manage.pojo.req.EDDataRequest; +import com.electromagnetic.industry.software.manage.pojo.req.FileChunkDTO; +import com.electromagnetic.industry.software.manage.pojo.req.FileChunkResultDTO; +import com.electromagnetic.industry.software.manage.pojo.resp.EDDataPageResponse; +import org.springframework.core.io.InputStreamResource; +import org.springframework.http.ResponseEntity; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.List; +import java.util.Map; + +public interface EDDataService { + /** + * 创建文件夹 + * @param request + * @return + */ + ElectromagneticResult createFolder(EDDataRequest request); + + + /** + * 获取文件信息列表 + * @param request + * @return + */ + ElectromagneticResult getDataInfoList(EDDataRequest request); + + /** + * 更新文件信息 + * @param request + * @return + */ + ElectromagneticResult updateFileInfo(EDDataRequest request); + + /** + * 获取子文件数量 + * @param request + * @return + */ + ElectromagneticResult> getChildFileCount(EDDataRequest request); + + /** + * 上传 + * @param request + * @return + */ + ElectromagneticResult uploadFile(EDDataRequest request); + + /** + * 下载 + * + * @param dataId + * @return + */ + ResponseEntity download(String dataId, HttpServletResponse response) throws IOException; + + /** + * 导出数据 + * @param dataIdArr + * @return + */ + ResponseEntity batchExport(String dataIdArr, HttpServletResponse response) throws IOException; + + /** + * 导入数据 + * @param fileChunkDTO + * @return + */ + ElectromagneticResult batchImport(FileChunkDTO fileChunkDTO); + + /** + * 获取已经上传的分片 + * @param identifier + * @return + */ + ElectromagneticResult> getUploadedChunkNums(String identifier); + + + /** + * 合并分片 + * @param identifier + * @param fileName + * @param totalChunks + * @return + */ + ElectromagneticResult mergeChunks(String identifier, String fileName, Integer totalChunks); + + + /** + * 检查分片是否存在 + * @param fileChunkDTO + * @return + */ + ElectromagneticResult checkChunkExist(FileChunkDTO fileChunkDTO); +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/TokenService.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/TokenService.java new file mode 100644 index 0000000..3c4c1a1 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/TokenService.java @@ -0,0 +1,33 @@ +package com.electromagnetic.industry.software.manage.service; + + +import com.electromagnetic.industry.software.common.pojo.UserLoginInfo; +import com.electromagnetic.industry.software.manage.pojo.models.User; + +public interface TokenService { + + /** + * 创建令牌 + * @param loginInfo + * @return 令牌 + */ + String createToken(UserLoginInfo loginInfo); + + /** + * 创建用户令牌 + * @param user + * @param tokenStr + * @return + */ + Boolean createUserToken(User user, String tokenStr); + + /** + * 查看token是否有效 + */ + Boolean isTokenValid(String tokenStr); + + /** + * 删除token + */ + int deleteToken(String tokenStr); +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/UserService.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/UserService.java new file mode 100644 index 0000000..ce1ef24 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/UserService.java @@ -0,0 +1,72 @@ +package com.electromagnetic.industry.software.manage.service; + +import com.electromagnetic.industry.software.common.resp.ElectromagneticResult; +import com.electromagnetic.industry.software.manage.pojo.req.*; + +public interface UserService { + + /** + * 用户登录 + * @param loginRequest + * @return + */ + ElectromagneticResult login(UserLoginRequest loginRequest); + + /** + * 新增用户信息 + * @param userRequest + * @return + */ + ElectromagneticResult createUser(UserRequest userRequest); + + /** + * 编辑用户信息 + * @param userModiRequest + * @return + */ + ElectromagneticResult modifyUser(UserModiRequest userModiRequest); + + + /** + * 发布用户 + * @param userPublishRequest + * @return + */ + ElectromagneticResult publishUser(UserPublishRequest userPublishRequest); + + /** + * 校验工号唯一性 + * @param workNumberRequest + * @return + */ + ElectromagneticResult validateWorkNum(UserWorkNumRequest workNumberRequest); + + /** + * 通过用户编码获取单条用户信息 + * @param getSingleUserRequest + * @return + */ + ElectromagneticResult getSingleUser(GetSingleUserRequest getSingleUserRequest); + + /** + * 查询用户信息 + * @param searchUserRequest + * @return + */ + ElectromagneticResult searchUser(SearchUserRequest searchUserRequest); + + /** + * 刪除用戶(逻辑删除) + * @param userDeleteRequest + * @return + */ + ElectromagneticResult deleteUser(UserDeleteRequest userDeleteRequest); + + /** + * 用户登出 + * @param token + * @return + */ + ElectromagneticResult logout(String token); + +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/CategoryServiceImpl.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/CategoryServiceImpl.java new file mode 100644 index 0000000..c274bc4 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/CategoryServiceImpl.java @@ -0,0 +1,82 @@ +package com.electromagnetic.industry.software.manage.service.serviceimpl; + +import com.electromagnetic.industry.software.common.resp.ElectromagneticResult; +import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil; +import com.electromagnetic.industry.software.manage.mapper.CategoryMapper; +import com.electromagnetic.industry.software.manage.pojo.models.Category; +import com.electromagnetic.industry.software.manage.service.CategoryService; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.stream.Collectors; + +@Service +public class CategoryServiceImpl implements CategoryService { + + @Resource + private CategoryMapper categoryMapper; + + @Override + public ElectromagneticResult getAllCategories() { + List categories = categoryMapper.selectAllCategories(); + List returnList = new ArrayList<>(); + List tempList = categories.stream().map(Category::getCategoryId).collect(Collectors.toList()); + for (Category category : categories) { + if (!tempList.contains(category.getParentId())) { + recursionFn(categories, category); + returnList.add(category); + } + } + if (returnList.isEmpty()) { + returnList = categories; + } + return ElectromagneticResultUtil.success(returnList); + } + + /** + * 递归列表 + * @param list + * @param category + */ + private void recursionFn (List list, Category category) { + List childList = getChildList(list, category); + category.setChildren(childList); + for (Category child : childList) { + if (hasChild(list, child)) { + recursionFn(list, child); + } + } + } + + /** + * 得到子节点列表 + * @param list + * @param category + * @return + */ + private List getChildList(List list, Category category) { + List childList = new ArrayList<>(); + Iterator it = list.iterator(); + while (it.hasNext()) { + Category child = it.next(); + if (!StringUtils.isEmpty(child.getParentId()) && child.getParentId().equals(category.getCategoryId())) { + childList.add(child); + } + } + return childList; + } + + /** + * 判断是否有子节点 + * @param list + * @param category + * @return + */ + private boolean hasChild(List list, Category category) { + return !getChildList(list, category).isEmpty(); + } +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EDDataServiceImpl.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EDDataServiceImpl.java new file mode 100644 index 0000000..f739a2c --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EDDataServiceImpl.java @@ -0,0 +1,923 @@ +package com.electromagnetic.industry.software.manage.service.serviceimpl; + +import cn.hutool.core.codec.Base64; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.io.IoUtil; +import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.StrUtil; +import cn.hutool.core.util.ZipUtil; +import cn.hutool.crypto.SecureUtil; +import cn.hutool.crypto.symmetric.AES; +import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONUtil; +import com.electromagnetic.industry.software.common.cons.ElectromagneticConstants; +import com.electromagnetic.industry.software.common.resp.ElectromagneticResult; +import com.electromagnetic.industry.software.common.util.EleCommonUtil; +import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil; +import com.electromagnetic.industry.software.common.util.IdWorker; +import com.electromagnetic.industry.software.common.util.UserThreadLocal; +import com.electromagnetic.industry.software.manage.mapper.CategoryMapper; +import com.electromagnetic.industry.software.manage.mapper.EDDataMapper; +import com.electromagnetic.industry.software.manage.mapper.EDDataMappers; +import com.electromagnetic.industry.software.manage.pojo.models.Category; +import com.electromagnetic.industry.software.manage.pojo.models.EDDataInfo; +import com.electromagnetic.industry.software.manage.pojo.other.EDDataPage; +import com.electromagnetic.industry.software.manage.pojo.other.EDDataParams; +import com.electromagnetic.industry.software.manage.pojo.req.EDDataRequest; +import com.electromagnetic.industry.software.manage.pojo.req.FileChunkDTO; +import com.electromagnetic.industry.software.manage.pojo.req.FileChunkResultDTO; +import com.electromagnetic.industry.software.manage.pojo.resp.EDDataPageResponse; +import com.electromagnetic.industry.software.manage.service.EDDataService; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.io.FileSystemResource; +import org.springframework.core.io.InputStreamResource; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; + +@Service +@Slf4j +public class EDDataServiceImpl implements EDDataService { + + @Resource + private EDDataMapper edDataMapper; + @Resource + private CategoryMapper categoryMapper; + + + @Value("${data.windows.path}") + private String uploadFilePath; + + @Value("${data.file.storage.dir}") + private String fileStorageDir; + + @Value("${data.import.cache.dir}") + private String importCacheDir; + + @Value("${file.encode.passwd}") + private String encodePasswd; + + @Value("${data.type.folder}") + private String dataTypeFolder; + + @Value("${data.windows.path}") + private String windowsDir; + @Value("${data.file.cache.dir}") + private String fileCacheDir; + @Value("${data.upload.cache.dir}") + private String uploadCacheDir; + @Value("${data.export.cache.dir}") + private String exportCacheDir; + @Value("${data.type.file}") + private String dataTypeFile; + + private static final String UPLOAD_FILE_CHUNK_SUFFIX = ".part"; + // 文件夹名称分隔符 + private static final String FOLDER_NAME_SEPARATOR = "_"; + + + @Override + public ElectromagneticResult createFolder(EDDataRequest request) { + + EDDataInfo edDataInfo = EDDataMappers.INSTANCE.getEDDataInfo(request); + + edDataInfo.setCreator(UserThreadLocal.getUserId()); + edDataInfo.setCreatorName(UserThreadLocal.getUsername()); + edDataInfo.setModifier(UserThreadLocal.getUserId()); + edDataInfo.setModifierName(UserThreadLocal.getUsername()); + edDataInfo.setCategoryId(request.getParentId()); + edDataInfo.setDataName(request.getName()); + edDataInfo.setNote(request.getNote()); + edDataInfo.setGmtBatchUpload(new Date()); + + edDataInfo.setDataId(IdWorker.getSnowFlakeIdString()); + edDataInfo.setDataNo(edDataInfo.getDataId()); + edDataInfo.setDataType(dataTypeFolder); + edDataInfo.setVersion("1.0.0"); + edDataInfo.setDataStatus("publish"); + edDataInfo.setSaveStatus("success"); + + try { + return ElectromagneticResultUtil.success(createDataInfo(edDataInfo)); + } catch (Exception e) { + log.error("创建文件夹失败。。。", e); + return ElectromagneticResultUtil.fail("500", e.getMessage()); + } + + } + + public Boolean createDataInfo(EDDataInfo edDataInfo) throws Exception + { + // 获取上级目录的名称 + String fileName = edDataInfo.getDataName(); + Assert.isTrue(EleCommonUtil.isFileNameValid(fileName), "文件名不符合规范,只能包含中文字符、下划线、连字符、加号、数字和英文字符且长度小于32。"); + + Category categoryParent = new Category(); + categoryParent.setCategoryId(edDataInfo.getCategoryId()); + List categoryParentList = categoryMapper.selectCategories(categoryParent); + + if(categoryParentList.size() < 1) { + throw new Exception("上级文件夹不存在"); + } + else + { + // 获取新文件夹路径信息 + categoryParent = categoryParentList.get(0); + + String dataStoragePath = getDataStoragePath(); + String folderParent = categoryParent.getCategoryId() + FOLDER_NAME_SEPARATOR + categoryParent.getCategoryName() ; + String folderNew = dataStoragePath + File.separator + folderParent + File.separator + edDataInfo.getDataName(); + + // 判断文件夹名称是否存在 + EDDataParams folderParames = new EDDataParams(); + folderParames.setParentId(edDataInfo.getCategoryId()); + List childFileInfoList = edDataMapper.getDataInfoList(folderParames); + for(EDDataInfo fileInfo : childFileInfoList) + { + if(fileInfo.getDataName().equals(edDataInfo.getDataName())){ + throw new Exception("文件夹已存在"); + } + } + + // 将文件夹数据写到数据库中 + if(edDataMapper.createDataInfo(edDataInfo)) { + if (!FileUtil.exist(folderNew)){ + FileUtil.mkdir(folderNew); + } + } + } + + return Boolean.TRUE; + } + + /** + * 获取数据存储目录 + * @return + */ + public String getDataStoragePath() { + String osName = System.getProperty("os.name").toLowerCase(); + return osName.startsWith("win") ? windowsDir + fileStorageDir : fileStorageDir; + } + + @Override + public ElectromagneticResult getDataInfoList(EDDataRequest request) { + EDDataParams parames= EDDataMappers.INSTANCE.getEDDataParames(request); + //获取中支指标配置列表 + PageHelper.startPage(parames.getPageIndex(), parames.getPageSize()); + List edDataInfoList = edDataMapper.getDataInfoList(parames); + PageInfo pageInfo = new PageInfo<>(edDataInfoList); + EDDataPage edDataPage = new EDDataPage(); + edDataPage.setEdDataInfo(pageInfo); + //模型转换 + EDDataPageResponse edDataPageResponse = EDDataMappers.INSTANCE.getEDDataInfoToModel(edDataPage); + return ElectromagneticResultUtil.success(edDataPageResponse); + } + + @Override + public ElectromagneticResult updateFileInfo(EDDataRequest request) { + + try { + EDDataParams parames = EDDataMappers.INSTANCE.getEDDataParames(request); + parames.setUserId(UserThreadLocal.getUserId()); + parames.setUserName(UserThreadLocal.getUsername()); + return ElectromagneticResultUtil.success(updateFileInfo(parames)); + } catch (Exception e) { + log.error("文件信息更新失败。。。", e); + return ElectromagneticResultUtil.fail("500", e.getMessage()); + } + } + + public Boolean updateFileInfo(EDDataParams parames) throws Exception { + + String dataStoragePath = getDataStoragePath(); + if (!FileUtil.exist(dataStoragePath)){ + throw new Exception("数据存储文件夹不存在"); + } + + EDDataParams paramesFind = new EDDataParams(); + paramesFind.setDataId(parames.getDataId()); + List edDataInfoList = edDataMapper.getDataInfoList(paramesFind); + if(edDataInfoList.size() < 1) { + throw new Exception("文件信息不存在"); + } + + EDDataInfo edDataInfo = edDataInfoList.get(0); + String filePathOfFolder = getFilePathOfFolder(edDataInfo.getCategoryId()); + String fileType = StrUtil.isEmpty(edDataInfo.getFileType()) ? "" : "." + edDataInfo.getFileType(); + String fileStorageFullPath = dataStoragePath + filePathOfFolder + File.separator + edDataInfo.getDataName() + fileType; + + if (!FileUtil.exist(fileStorageFullPath)){ + throw new Exception("文件不存在"); + } + + String fileNameNew = parames.getName() + fileType; + if(fileNameNew != null && fileNameNew != "" && !fileNameNew.equals(edDataInfo.getDataName())) { + FileUtil.rename(Paths.get(fileStorageFullPath) ,fileNameNew,true); + } + + // 修改文件夹 + edDataMapper.updateFileInfo(parames); + // 修改文件夹中的文件 + if(edDataInfo.getDataType().equals(dataTypeFolder) && parames.getEffectFlag() != null) { + EDDataParams paramesChild = new EDDataParams(); + paramesChild.setParentId(edDataInfo.getDataId()); + paramesChild.setEffectFlag(parames.getEffectFlag()); + edDataMapper.updateFileInfo(paramesChild); + } + + return Boolean.TRUE; + } + + public String getFilePathOfFolder(String categoryId) { + String filePathOfFolder = ""; //文件存放在文件夹的路径 + + String categoryIdHighest = categoryId; //最高级的目录编码 + EDDataParams folderParames = new EDDataParams(); + folderParames.setDataId(categoryId); + List edDataInfoList = edDataMapper.getDataInfoList(folderParames); + EDDataInfo edDataInfoParent = null; + if(CollUtil.isNotEmpty(edDataInfoList)) { + categoryIdHighest = edDataInfoList.get(0).getCategoryId(); + edDataInfoParent = edDataInfoList.get(0); + } + Category categoryParent = new Category(); + categoryParent.setCategoryId(categoryIdHighest); + List categoryParentList = categoryMapper.selectCategories(categoryParent); + if(categoryParentList.size() > 0){ + categoryParent = categoryParentList.get(0); + filePathOfFolder = categoryParent.getCategoryId() + FOLDER_NAME_SEPARATOR + categoryParent.getCategoryName(); + if(edDataInfoParent != null) { + String fileType = StrUtil.isEmpty(edDataInfoParent.getFileType()) ? "" : "." + edDataInfoParent.getFileType(); + filePathOfFolder = filePathOfFolder + File.separator + edDataInfoParent.getDataName() + fileType; + } + } + + return filePathOfFolder; + } + + @Override + public ElectromagneticResult> getChildFileCount(EDDataRequest request) { + EDDataParams parames= EDDataMappers.INSTANCE.getEDDataParames(request); + Integer fileCount = getChildFileCount(parames); + Map result = new HashMap<>(); + result.put("fileCount", fileCount); + return ElectromagneticResultUtil.success(result); + } + + public Integer getChildFileCount(EDDataParams parames) { + Integer childFileCount = 0; + + List edDataInfoList = edDataMapper.getDataInfoList(parames); + parames.setDataId(null); + for (EDDataInfo edDataInfo : edDataInfoList) { + if(edDataInfo.getDataType().equals(dataTypeFolder)) + { + parames.setParentId(edDataInfo.getDataId()); + childFileCount += getChildFileCount(parames); + } + else if(edDataInfo.getDataType().equals(dataTypeFile) && edDataInfo.getEffectFlag().equals(1)) + { + ++childFileCount; + } + } + + return childFileCount; + } + + @Override + public ElectromagneticResult uploadFile(EDDataRequest request) { + try { + EDDataParams parames= EDDataMappers.INSTANCE.getEDDataParames(request); + parames.setUserId(UserThreadLocal.getUserId()); + parames.setUserName(UserThreadLocal.getUsername()); + return ElectromagneticResultUtil.success(upload(parames)); + } catch (Exception e) { + log.error("上传文件失败。。。", e); + return ElectromagneticResultUtil.fail("500", e.getMessage()); + } + } + + private Boolean upload(EDDataParams parames) throws Exception { + // 获取目录编码ID + String categoryId = parames.getParentId(); + + // 获取要上传的文件 + MultipartFile fileInput = parames.getFileData(); + + // 检查文件是否为空 + if (fileInput == null || fileInput.isEmpty()) { + throw new Exception("上传的文件为空"); + } + + // 获取文件名 + String fileFullName = fileInput.getOriginalFilename(); + // 获取文件类型 + String fileType = EleCommonUtil.getFileType(fileFullName); + // 获取文件名称 + String fileName = EleCommonUtil.getFileName(fileFullName); + Assert.isTrue(EleCommonUtil.isFileNameValid(fileName), "文件名不符合规范,只能包含中文字符、下划线、连字符、加号、数字和英文字符且长度小于32。"); + // 判断文件名称是否存在 + EDDataParams folderParames = new EDDataParams(); + folderParames.setParentId(categoryId); + List childFileInfoList = edDataMapper.getDataInfoList(folderParames); + for(EDDataInfo fileInfo : childFileInfoList) + { + if(fileInfo.getDataName().equals(fileFullName)){ + throw new Exception("上传的文件已存在"); + } + } + + String dataStoragePath = getDataStoragePath(); + if (!FileUtil.exist(dataStoragePath)){ + FileUtil.mkdir(dataStoragePath); + } + + //获取文件存放在文件夹的路径 + String filePathOfFolder = getFilePathOfFolder(categoryId); + + // 将文件数据信息写到数据库 + EDDataInfo edDataInfo = new EDDataInfo(); + + + // 创建新文件数据 + edDataInfo.setCreator(parames.getUserId()); + edDataInfo.setCreatorName(parames.getUserName()); + edDataInfo.setModifier(parames.getUserId()); + edDataInfo.setModifierName(parames.getUserName()); + edDataInfo.setCategoryId(parames.getParentId()); + edDataInfo.setDataName(fileName); + edDataInfo.setNote(parames.getNote()); + edDataInfo.setFileType(fileType); + edDataInfo.setGmtBatchUpload(parames.getGmtBatchUpload()); + + edDataInfo.setDataId(IdWorker.getSnowFlakeIdString()); + edDataInfo.setDataNo(edDataInfo.getDataId()); + edDataInfo.setDataType(dataTypeFile); + edDataInfo.setVersion("1.0.0"); + edDataInfo.setDataStatus("publish"); + edDataInfo.setSaveStatus("saving"); + + boolean isSuccess = edDataMapper.createDataInfo(edDataInfo); + log.info("文件开始保存."); + + // 保存文件数据 到 文件存储目录 + + + // 文件保存目录路径 + String fileSavePath = dataStoragePath + File.separator + filePathOfFolder; + String newFileName = edDataInfo.getDataId() + FOLDER_NAME_SEPARATOR + fileFullName; + if (!FileUtil.exist(fileSavePath)){ + FileUtil.mkdir(fileSavePath); + } + + String dataCachePath = getDataCachePath(); + String uploadFileCachePath = dataCachePath + uploadCacheDir + FOLDER_NAME_SEPARATOR + getTimeStampString(); + if (!FileUtil.exist(uploadFileCachePath)){ + FileUtil.mkdir(uploadFileCachePath); + } + + String fileCacheFullPath = uploadFileCachePath + File.separator + newFileName; + String fileSaveFullPath = fileSavePath + File.separator + fileFullName; + log.info("文件缓存路径为: " + fileCacheFullPath); + + + // 这里可以添加将文件保存到本地磁盘或其他存储介质的逻辑 + File saveFile = new File(fileCacheFullPath); + + // 将文件保存到硬盘 + EDDataParams fileParames = new EDDataParams(); + try { + fileInput.transferTo(saveFile); + + + fileParames.setDataId(edDataInfo.getDataId()); + if(fileInput.getSize() == saveFile.length()) + { + Path source = Paths.get(fileCacheFullPath); + Path target = Paths.get(fileSaveFullPath); + Files.move(source, target); + fileParames.setSaveStatus("success"); + } + else + { + saveFile.delete(); + fileParames.setSaveStatus("failure"); + } + + isSuccess = edDataMapper.updateFileInfo(fileParames); + + FileUtil.del(uploadFileCachePath);//删除临时目录 + + log.info("文件保存成功: " + fileSaveFullPath); + + return Boolean.TRUE; + + } catch (IOException e) { + fileParames.setSaveStatus("failure"); + edDataMapper.updateFileInfo(fileParames); + log.info("文件保存失败: " + fileSaveFullPath); + throw new Exception(e.getMessage()); + } + } + + /** + * 获取时间戳字符串 + * @return + */ + public String getTimeStampString() { + long timestamp = System.currentTimeMillis(); + return String.valueOf(timestamp); + } + + /** + * 获取数据缓存目录 + * @return + */ + public String getDataCachePath() { + String osName = System.getProperty("os.name").toLowerCase(); + return osName.startsWith("win") ? windowsDir + fileCacheDir : fileCacheDir; + } + + @Override + public ResponseEntity download(String dataId, HttpServletResponse response) throws IOException { + // 获取文件存储的文件夹路径 + String osName = System.getProperty("os.name").toLowerCase(); + String storageFilePath = osName.startsWith("win") ? uploadFilePath + fileStorageDir : fileStorageDir; + EDDataParams parames = new EDDataParams(); + parames.setDataId(dataId); + List edDataInfos = edDataMapper.getDataInfoList(parames); + Assert.isTrue(CollUtil.isNotEmpty(edDataInfos), "没有找到该下载文件"); + EDDataInfo edDataInfo = edDataInfos.get(0); + String filePathOfFolder = getFilePathOfFolder1(edDataInfo.getCategoryId()); + String fileType = StrUtil.isEmpty(edDataInfo.getFileType()) ? "" : "." + edDataInfo.getFileType(); + String filePath = storageFilePath + "/" + filePathOfFolder + "/" + edDataInfo.getDataName() + fileType; + + Assert.isTrue(FileUtil.exist(filePath), "下载文件不存在。"); + FileSystemResource fileSystemResource = new FileSystemResource(filePath); + HttpHeaders headers = new HttpHeaders(); + headers.add("Cache-Control", "no-cache, no-store, must-revalidate"); + headers.add("Pragma", "no-cache"); + headers.add("Expires", "0"); + String fileName = Base64.encode(fileSystemResource.getFilename()); + response.setHeader("content-disposition","attachment;filename=" + fileName); + // 构建响应实体(可以返回 edDataInfoList = edDataMapper.getDataInfoList(folderParames); + EDDataInfo edDataInfoParent = null; + if(CollUtil.isNotEmpty(edDataInfoList)) { + categoryIdHighest = edDataInfoList.get(0).getCategoryId(); + edDataInfoParent = edDataInfoList.get(0); + } + Category categoryParent = new Category(); + categoryParent.setCategoryId(categoryIdHighest); + List categoryParentList = categoryMapper.selectCategories(categoryParent); + if(categoryParentList.size() > 0){ + categoryParent = categoryParentList.get(0); + filePathOfFolder = categoryParent.getCategoryId() + FOLDER_NAME_SEPARATOR + categoryParent.getCategoryName(); + if(edDataInfoParent != null) { + String fileType = StrUtil.isEmpty(edDataInfoParent.getFileType()) ? "" : "." + edDataInfoParent.getFileType(); + filePathOfFolder = filePathOfFolder + File.separator + edDataInfoParent.getDataName() + fileType; + } + } + return filePathOfFolder; + } + + @Override + public ResponseEntity batchExport(String dataIdArr, HttpServletResponse response) throws IOException { + //1、根据用户选择层级树编码查出所有文件和文件夹list + //2、循环list将每个文件复制到新建目录并进行重命名,命名规则:目录树编码+,+文件夹编码(有则填写无则为空)+,+文件编码 + //3、打包新建为zip,并根据生产下载地址(域名+文件路径+文件) + //4、返回前端下载的地址 + + // **********在导出的过程中可能会出现有用户上传文件的情况 + + Map result = new HashMap<>(); + List dataIdList = Arrays.asList(dataIdArr.split(",")); + if(!dataIdList.isEmpty()) { + String filePath = exportData(dataIdList); + + Assert.isTrue(FileUtil.exist(filePath), "下载文件不存在。"); + File file = new File(filePath); + FileSystemResource fileSystemResource = new FileSystemResource(file); + + HttpHeaders headers = new HttpHeaders(); + headers.add("Cache-Control", "no-cache, no-store, must-revalidate"); + String fileName = Base64.encode(fileSystemResource.getFilename()); + headers.add("Pragma", "no-cache"); + headers.add("Expires", "0"); + response.setHeader("content-disposition","attachment;filename=" + fileName); + + // 构建响应实体(可以返回 dataIdList) { + String zipPathFileName = ""; + String exportDataCachePath = ""; + String enCodeZipPathFileName = ""; + + try { + // 获取文件夹编码ID数组 + List categoryIdInputList = dataIdList; + + String dataCachePath = getDataCachePath(); + + // 导出数据时的临时存放目录 + exportDataCachePath = dataCachePath + exportCacheDir + FOLDER_NAME_SEPARATOR + getTimeStampString(); + if (!FileUtil.exist(exportDataCachePath)) { + FileUtil.mkdir(exportDataCachePath); + } + + List categoryAllList = categoryMapper.selectAllCategories(); + Map categoryAllMap = new HashMap(); //所有目录数组map + for (Category category : categoryAllList) { + categoryAllMap.put(category.getCategoryId(), category); + } + + EDDataParams folderParames = new EDDataParams(); + List fileAllList = edDataMapper.getDataInfoList(folderParames); //获取所有文件信息数据 + Map fileAllMap = new HashMap(); //所有文件数组map + for (EDDataInfo fileFinfo : fileAllList) { + fileAllMap.put(fileFinfo.getDataId(), fileFinfo); + } + + List categoryInputList = new ArrayList(); //客户端输入的目录数组 + Map categoryInputMap = new HashMap(); //客户端输入的目录数组map + for (String categoryId : categoryIdInputList) { + Category category = categoryAllMap.get(categoryId); + if (category != null) { + categoryInputList.add(category); + categoryInputMap.put(categoryId, category); + } + } + + + // 将List转换为JSON字符串 + String jsonStringCategory = JSONUtil.toJsonStr(categoryInputList); + String categoryListFileFullPath = exportDataCachePath + "/categoryList.json"; + FileUtil.writeString(jsonStringCategory, categoryListFileFullPath, "utf-8"); + log.info("目录树数据已成功导出为JSON文件。" + categoryListFileFullPath); + + + // 导出文件信息数据和文件数据 + + List fileExportList = new ArrayList(); //需要导出的文件信息数据数组 + Map fileExportMap = new HashMap(); //需要导出的文件信息数据数组map + for (EDDataInfo fileFinfo : fileAllList) { + if (categoryInputMap.get(fileFinfo.getCategoryId()) != null) { + fileExportList.add(fileFinfo); + fileExportMap.put(fileFinfo.getDataId(), fileFinfo); + } + } + // 找出子文件夹下的文件 + for (EDDataInfo fileFinfo : fileAllList) { + if (fileExportMap.get(fileFinfo.getCategoryId()) != null) { + fileExportList.add(fileFinfo); + } + } + + // 将文件信息数据导出为json文件 + String jsonStringFile = JSONUtil.toJsonStr(fileExportList); + String fileListFileFullPath = exportDataCachePath + "/fileInfoList.json"; + FileUtil.writeString(jsonStringFile, fileListFileFullPath, "utf-8"); + log.info("文件数据已成功导出为JSON文件。" + fileListFileFullPath); + + + // 将文件 复制到 数据导出的缓存目录中 + String dataStoragePath = getDataStoragePath(); + String needExportfolder = ""; + for (Category category : categoryInputList) { + needExportfolder = dataStoragePath + category.getCategoryId() + FOLDER_NAME_SEPARATOR + category.getCategoryName(); + if (FileUtil.exist(needExportfolder)) { + Path source = Paths.get(needExportfolder); + Path target = Paths.get(exportDataCachePath); + FileUtil.copy(source, target); // StandardCopyOption.REPLACE_EXISTING + } + } + + log.info("文件数据已成功复制到目标目录。"); + + // 将目录树数据 和 文件夹及文件夹内数据 进行压缩打包 + Date date = new Date(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss"); + String dateString = sdf.format(date); + + zipPathFileName = dataCachePath + "/exportData_" + dateString; + enCodeZipPathFileName = dataCachePath + "/exportData_" + dateString + ElectromagneticConstants.EXPORT_FILE_SUFFIX; + + ZipUtil.zip(exportDataCachePath, zipPathFileName); + + AES aes = SecureUtil.aes(encodePasswd.getBytes()); // aesKey是加密密钥 + try ( + InputStream inputStream = new FileInputStream(zipPathFileName); + OutputStream outputStream = new FileOutputStream(enCodeZipPathFileName); + ) { + aes.encrypt(inputStream, outputStream, true); + } catch (Exception e) { + log.error("文件加密错误..", e); + } + + log.info("目录树数据+文件数据已成功复制到目标目录。" + enCodeZipPathFileName); + } + catch (Exception e) { + log.error("导出数据异常..", e); + } + finally { + // 删除 导出数据的 缓存目录 + FileUtil.del(exportDataCachePath); + } + + return enCodeZipPathFileName; + } + + + @Override + public ElectromagneticResult batchImport(FileChunkDTO fileChunkDTO) { + String identifier = fileChunkDTO.getIdentifier(); + String fileName = fileChunkDTO.getFileName(); + + String dataCachePath = getDataCachePath(); + String importDataCachePath = dataCachePath + importCacheDir; + + // 首先检查文件是否存在,如果存在则不允许重复上传。 + String destZipPath = importDataCachePath + identifier + File.separator + fileName; + boolean existFile = FileUtil.exist(new File(destZipPath)); + if (existFile) { + return ElectromagneticResultUtil.fail("-1", "文件已经存在,请勿重复上传。"); + } + + // 检查该分片有没被上传过 + String destChunkPath = importDataCachePath + identifier + File.separator + fileChunkDTO.getChunkNumber() + UPLOAD_FILE_CHUNK_SUFFIX; + boolean existChunk = FileUtil.exist(new File(destChunkPath)); + if (existChunk) { + return ElectromagneticResultUtil.success(true); + } + + File dir = new File(importDataCachePath + identifier + File.separator); + if (!dir.exists()) { + dir.mkdir(); + } + + try ( + InputStream inputStream = fileChunkDTO.getFile().getInputStream(); + FileOutputStream fileOutputStream = new FileOutputStream(destChunkPath); + ) { + IoUtil.copy(inputStream, fileOutputStream); + } catch (IOException ioException) { + log.error("上传文件错误...", ioException); + } + return ElectromagneticResultUtil.success(fileChunkDTO.getIdentifier()); + } + + @Override + public ElectromagneticResult> getUploadedChunkNums(String identifier) { + return ElectromagneticResultUtil.success(getUploadedChunks(identifier)); + } + + private List getUploadedChunks(String identifier) { + String dataCachePath = getDataCachePath(); + String importDataCachePath = dataCachePath + importCacheDir; + String destPath = importDataCachePath + identifier; + if (!FileUtil.exist(new File(destPath))) { + return new ArrayList<>(); + } + + return FileUtil.listFileNames(destPath) + .stream() + .filter(e -> !e.endsWith(ElectromagneticConstants.EXPORT_FILE_SUFFIX)) + .map(e -> e.replace(UPLOAD_FILE_CHUNK_SUFFIX, "")) + .map(Integer::parseInt) + .collect(Collectors.toList()); + } + + @Override + public ElectromagneticResult mergeChunks(String identifier, String fileName, Integer totalChunks) { + String dataCachePath = getDataCachePath(); + String importDataCachePath = dataCachePath + importCacheDir; + + // 检查所有分片是否已经上传完成,分片编号从1开始 + for (int i = 1; i <= totalChunks; i++) { + String tmpPath = importDataCachePath + identifier + File.separator + i + UPLOAD_FILE_CHUNK_SUFFIX; + if (!FileUtil.exist(new File(tmpPath))) { + log.error("第{}个分片没有上传完成,请上传完成后再合并。", i); + ElectromagneticResultUtil.fail("-1", "文件尚未上传完成。"); + } + } + + // 合并分片 + String destZipPath = importDataCachePath + identifier + File.separator + fileName; + File mergedFile = new File(destZipPath); + try { + RandomAccessFile targetFile = new RandomAccessFile(mergedFile, "rw"); + byte[] buffer = new byte[1024]; + for (int i = 1; i <= totalChunks; i++) { + String tmpPath = importDataCachePath + identifier + File.separator + i + UPLOAD_FILE_CHUNK_SUFFIX; + RandomAccessFile tmp = new RandomAccessFile(new File(tmpPath), "r"); + int len; + while ((len = tmp.read(buffer)) != -1) { + targetFile.write(buffer, 0, len); + } + tmp.close(); + } + targetFile.close(); + } catch (IOException ioException) { + ElectromagneticResultUtil.fail("-1", "文件合并失败"); + } + + // 删除分片 + for (int i = 1; i <= totalChunks; i++) { + String tmpPath = importDataCachePath + identifier + File.separator + i + UPLOAD_FILE_CHUNK_SUFFIX; + FileUtil.del(tmpPath); + } + + // 检验文件的MD5值 + + // 解密文件 + String decryptFilePath = destZipPath + "_decrypted"; + AES aes = SecureUtil.aes(encodePasswd.getBytes()); // aesKey是加密密钥 + try( + InputStream inputStream = new FileInputStream(destZipPath); + OutputStream outputStream = new FileOutputStream(decryptFilePath); + ) { + aes.decrypt(inputStream, outputStream, true); + } catch (Exception e) { + log.error("文件加密错误..", e); + } + + // 解压文件 + String unzipFileOutputPath = importDataCachePath + identifier + File.separator; + ZipUtil.unzip(decryptFilePath, unzipFileOutputPath); + + // 文件信息存入数据库 + Map> result = importData(importDataCachePath + identifier); + + // 删除 解压数据的 缓存目录 + FileUtil.del(unzipFileOutputPath); + + return ElectromagneticResultUtil.success(result); + } + + public Map> importData(String folderPath) { + // 获取所有目录树节点数据 + List categoryAllList = categoryMapper.selectAllCategories(); + Map categoryAllMap = new HashMap(); //所有目录数组map + for (Category category : categoryAllList) { + categoryAllMap.put(category.getCategoryId(), category); + } + + // 获取所有文件信息数据 + EDDataParams parames = new EDDataParams(); + List fileInfoAllList = edDataMapper.getDataInfoList(parames); + Map fileInfoAllMap = new HashMap(); //所有文件数组map + for (EDDataInfo fileInfo : fileInfoAllList) { + fileInfoAllMap.put(fileInfo.getDataId(), fileInfo); + } + + + // 读取并反序列化目录树的JSON文件数据为List;然后写入到数据库中。 + String jsonStringCategory = FileUtil.readString(folderPath + "/categoryList.json", StandardCharsets.UTF_8); + JSONArray jsonArrayCategory = JSONUtil.parseArray(jsonStringCategory); + List categoryImportList = JSONUtil.toList(jsonArrayCategory, Category.class); + if (categoryImportList == null) { + log.error("读取并反序列化JSON文件数据为List失败!"); + return null; + } + // 将目录树数据写入到数据库中 + for (Category category : categoryImportList) { + if (categoryAllMap.get(category.getCategoryId()) == null) { + categoryMapper.createCategory(category); + } + } + + // 读取并反序列化文件信息的JSON文件数据为List;然后写入到数据库中。 + String jsonStringFile = FileUtil.readString(folderPath + "/fileInfoList.json", StandardCharsets.UTF_8); + JSONArray jsonArrayFile = JSONUtil.parseArray(jsonStringFile); + List fileInfoImportList = JSONUtil.toList(jsonArrayFile, EDDataInfo.class); + if (fileInfoImportList == null) { + log.error("读取并反序列化JSON文件数据为List失败!"); + return null; + } + // 将文件信息数据写入到数据库中 + for (EDDataInfo fileInfo : fileInfoImportList) { + if (fileInfoAllMap.get(fileInfo.getDataId()) == null) { + edDataMapper.createDataInfo(fileInfo); + } + } + + // 将解压后的文件夹和文件 移动到 上传文件的存储目录中 + List importFileSuccess = new ArrayList(); + List importFileFail = new ArrayList(); + + String dataStoragePath = getDataStoragePath(); + if (!FileUtil.exist(dataStoragePath)){ + FileUtil.mkdir(dataStoragePath); + } + + String importDataCachePath = folderPath; //导入数据时 数据文件解压后的目录 + String importFileCachePath = ""; //需要导入的文件的缓存路径 + String importFileCacheFullPath = ""; //需要导入的文件的全路径 + String fileStorageFolder = ""; //文件存储的文件夹 + String fileStoragePath = ""; //文件存储的文件夹路径 + String fileStorageFullPath = ""; //文件存储的文件全路径 + + for (EDDataInfo fileInfo : fileInfoImportList) { + fileStorageFolder = getFilePathOfFolder(fileInfo.getCategoryId()); + importFileCachePath = importDataCachePath + File.separator + fileStorageFolder; + importFileCacheFullPath = importFileCachePath + File.separator + fileInfo.getDataName(); + fileStoragePath = dataStoragePath + File.separator + fileStorageFolder; + fileStorageFullPath = fileStoragePath + File.separator + fileInfo.getDataName(); + + if (fileInfoAllMap.get(fileInfo.getDataId()) == null + && !fileStorageFolder.isEmpty() + && FileUtil.exist(importFileCachePath) + && FileUtil.exist(importFileCacheFullPath) + && !FileUtil.exist(fileStorageFullPath) + ) + { + if(fileInfo.getDataType().equals(dataTypeFolder)) { + if (!FileUtil.exist(fileStorageFullPath)) { + FileUtil.mkdir(fileStorageFullPath); + } + } else if(fileInfo.getDataType().equals(dataTypeFile)) { + Path source = Paths.get(importFileCacheFullPath); + Path target = Paths.get(fileStorageFullPath); + FileUtil.move(source,target,true); + } + + importFileSuccess.add(fileInfo.getDataId() + FOLDER_NAME_SEPARATOR + fileInfo.getDataName()); + } + else + { + importFileFail.add(fileInfo.getDataId() + FOLDER_NAME_SEPARATOR + fileInfo.getDataName()); + } + } + + + Map> result = new HashMap<>(); + result.put("success", importFileSuccess); + result.put("fail", importFileFail); + + return result; + } + + + @Override + public ElectromagneticResult checkChunkExist(FileChunkDTO fileChunkDTO) { + String dataCachePath = getDataCachePath(); + String importDataCachePath = dataCachePath + importCacheDir; + // 首先判断zip文件是否存在,如果不存在则表示还没有上传完成。 + String identifier = fileChunkDTO.getIdentifier(); + String fileName = fileChunkDTO.getFileName(); + String destZipPath = importDataCachePath + identifier + File.separator + fileName; + boolean existFile = FileUtil.exist(new File(destZipPath)); + + if (existFile) { + return ElectromagneticResultUtil.success(new FileChunkResultDTO(true, new HashSet<>())); + } + + List uploadedChunks = getUploadedChunks(identifier); + return ElectromagneticResultUtil.success(new FileChunkResultDTO(false, new HashSet<>(uploadedChunks))); + } +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/TokenServiceImpl.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/TokenServiceImpl.java new file mode 100644 index 0000000..89df594 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/TokenServiceImpl.java @@ -0,0 +1,27 @@ +package com.electromagnetic.industry.software.manage.service.serviceimpl; + +import com.electromagnetic.industry.software.common.pojo.UserLoginInfo; +import com.electromagnetic.industry.software.manage.pojo.models.User; +import com.electromagnetic.industry.software.manage.service.TokenService; + +public class TokenServiceImpl implements TokenService { + @Override + public String createToken(UserLoginInfo loginInfo) { + return ""; + } + + @Override + public Boolean createUserToken(User user, String tokenStr) { + return null; + } + + @Override + public Boolean isTokenValid(String tokenStr) { + return null; + } + + @Override + public int deleteToken(String tokenStr) { + return 0; + } +} diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/UserServiceImpl.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/UserServiceImpl.java new file mode 100644 index 0000000..01478d5 --- /dev/null +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/UserServiceImpl.java @@ -0,0 +1,236 @@ +package com.electromagnetic.industry.software.manage.service.serviceimpl; + +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.SystemClock; +import com.electromagnetic.industry.software.common.cons.UserConstants; +import com.electromagnetic.industry.software.common.enums.EffectFlagEnum; +import com.electromagnetic.industry.software.common.enums.ElectromagneticErrorEnum; +import com.electromagnetic.industry.software.common.enums.PublishEnum; +import com.electromagnetic.industry.software.common.pojo.UserLoginInfo; +import com.electromagnetic.industry.software.common.resp.ElectromagneticResult; +import com.electromagnetic.industry.software.common.util.*; +import com.electromagnetic.industry.software.manage.mapper.TokenMapper; +import com.electromagnetic.industry.software.manage.mapper.UserMapper; +import com.electromagnetic.industry.software.manage.mapper.UserMappers; +import com.electromagnetic.industry.software.manage.pojo.models.Token; +import com.electromagnetic.industry.software.manage.pojo.models.User; +import com.electromagnetic.industry.software.manage.pojo.other.PublishParam; +import com.electromagnetic.industry.software.manage.pojo.other.SearchKeyWords; +import com.electromagnetic.industry.software.manage.pojo.other.SingleUserResponse; +import com.electromagnetic.industry.software.manage.pojo.other.UserDeleteKeyWords; +import com.electromagnetic.industry.software.manage.pojo.req.*; +import com.electromagnetic.industry.software.manage.pojo.resp.UserLoginResponse; +import com.electromagnetic.industry.software.manage.pojo.resp.UserSearchResponse; +import com.electromagnetic.industry.software.manage.service.UserService; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; +import org.apache.commons.lang3.RandomStringUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static cn.hutool.core.date.DateTime.now; + +@Service +public class UserServiceImpl implements UserService { + + @Resource + private UserMapper userMapper; + @Resource + private TokenMapper tokenMapper; + + /** + * 用户登录 + * @param loginRequest + * @return + */ + @Override + public ElectromagneticResult login(UserLoginRequest loginRequest) { + UserLoginInfo info = UserMappers.INSTANCE.getUserLoginRequestToModel(loginRequest); + String decodePwd = AESUtils.decrypt(info.getUserPwd(), UserConstants.SECRET_KEY); + User user = userMapper.selectUserByWorkNumber(info.getWorkNumber()); + info.setUserId(user.getUserId()); + info.setUsername(user.getUserName()); + if ( checkUserValid(user) && matchPassword(user, decodePwd)) { + String tokenStr = createToken(info); + createUserToken(user, tokenStr); + UserLoginResponse userLoginResponse = new UserLoginResponse(); + userLoginResponse.setToken(tokenStr); + userLoginResponse.setUserId(user.getUserId()); + return ElectromagneticResultUtil.success(userLoginResponse); + } + return ElectromagneticResultUtil.fail("500","用户不存在/密码错误"); + } + + public Boolean createUserToken (User user, String tokenStr){ + Token token = new Token(); + token.setUserId(user.getUserId()); + token.setToken(tokenStr); + token.setExpireAt(new DateTime(SystemClock.now()+ UserConstants.DEFAULT_EXPIRE_TIME)); + return tokenMapper.insert(token)>0; + } + + public Boolean checkUserValid(User user){ + if ( user == null + || user.getIsPublished() == PublishEnum.UNPUBLISHED.getCode() + || user.getEffectFlag() == EffectFlagEnum.EFFECT_FLAG_0.getCode() + ) { + return false; + } else if( user.getInternshipEndDate()!=null && user.getInternshipEndDate().before(now())) { + return false; + } + return true; + } + + public String createToken(UserLoginInfo loginInfo){ + Map claims = new HashMap<>(); + claims.put(UserConstants.LOGIN_USER_ID, loginInfo.getUserId()); + claims.put(UserConstants.LOGIN_USER_NAME, loginInfo.getUsername()); + claims.put(UserConstants.LOGIN_WORK_NUMBER, loginInfo.getWorkNumber()); + return Jwts.builder() + .addClaims(claims) + .setIssuedAt(DateTime.now()) + .signWith(SignatureAlgorithm.HS512, UserConstants.SECRET_KEY) + .compact(); + } + + public Boolean matchPassword(User user, String password){ + String salt = user.getSalt(); + String encodePwd = SignUtils.MD5(password+salt); + return user.getUserPwd().equals(encodePwd); + } + + /** + * 新增用户信息 + * @param userRequest + * @return + */ + @Override + public ElectromagneticResult createUser(UserRequest userRequest) { + + User user = UserMappers.INSTANCE.getUserRequestToModel(userRequest); + user.setSalt(RandomStringUtils.randomAlphanumeric(16)); + user.setUserId(IdWorker.getSnowFlakeIdString()); + user.setUserPwd(SignUtils.MD5(UserConstants.DEFAULT_PASSWORD+user.getSalt())); + user.setIsPublished(UserConstants.DEFAULT_PUBLISH_STATUS); + user.setCreator(UserThreadLocal.getUserId()); + user.setCreatorName(UserThreadLocal.getUsername()); + return ElectromagneticResultUtil.success(userMapper.insert(user) > 0); + } + + /** + * 修改用户信息 + * @param userModiRequest + * @return + */ + @Override + public ElectromagneticResult modifyUser(UserModiRequest userModiRequest) { + User user = UserMappers.INSTANCE.getUserModiRequestToModel(userModiRequest); + user.setModifier(UserThreadLocal.getUserId()); + user.setModifierName(UserThreadLocal.getUsername()); + return ElectromagneticResultUtil.success(userMapper.modify(user) > 0); + } + + /** + * 发布用户信息 + * @param userPublishRequest + * @return + */ + @Override + public ElectromagneticResult publishUser(UserPublishRequest userPublishRequest) { + PublishParam model = UserMappers.INSTANCE.getUserPublishRequestToModel(userPublishRequest); + model.setModifier(UserThreadLocal.getUserId()); + model.setModifierName(UserThreadLocal.getUsername()); + return ElectromagneticResultUtil.success(userMapper.publish(model) > 0 ); + } + + @Override + public ElectromagneticResult validateWorkNum(UserWorkNumRequest workNumberRequest) { + // 将前端请求对象转换为模型对象,包含userId和userWorkNum + User user = UserMappers.INSTANCE.getUserWorkNumRequestToModel(workNumberRequest); + + //根据请求对象的userId判断当前处于什么状态 + if(user.getUserId()==null){ + //userId为空,表示是新增用户阶段 + //判断数据库中有无该工号对应的用户 + User existingUser = userMapper.selectUserByWorkNumber(user.getWorkNumber()); + //如果有该用户就返回false,如果没有(==null)就返回true + boolean isWorkNumberUnique = (existingUser == null); + return ElectromagneticResultUtil.success(isWorkNumberUnique); + }else{ + //userId不为空,表示是编辑用户阶段 + //请求对象的userWordNum在数据库中对应的user + User existingUser = userMapper.selectUserByWorkNumber(user.getWorkNumber()); + //判断,请求对象的userId对应的user和请求对象的userWordNum在数据库中对应的user是否为用一个 + if(existingUser!=null){ + //请求对象的userWordNum在数据库中对应的user与请求对象的userId对应的user是否为同一个 + if(user.getUserId().equals(existingUser.getUserId())){ + // 如果获取到的用户ID与当前编辑的用户ID相同,说明工号未改变,直接返回true + return ElectromagneticResultUtil.success(true); + }else{ + // 如果获取到的用户ID与当前编辑的用户ID不同,说明工号已改变,需要判断新工号是否唯一 + // 如果根据新工号获取不到用户,说明新工号唯一 + boolean isWorkNumberUnique = (userMapper.selectUserByWorkNumber(user.getWorkNumber()) == null); + return ElectromagneticResultUtil.success(isWorkNumberUnique); + } + }else{ + //请求对象的userWordNum在数据库中不存在对应的user + return ElectromagneticResultUtil.success(true); + } + + } + } + + @Override + public ElectromagneticResult getSingleUser(GetSingleUserRequest getSingleUserRequest) { + User user = userMapper.getSingleUser(getSingleUserRequest.getUserId()); + SingleUserResponse singleUserResponse = UserMappers.INSTANCE.getSingleUserToResponse(user); + return ElectromagneticResultUtil.success(singleUserResponse); + } + + @Override + public ElectromagneticResult searchUser(SearchUserRequest searchUserRequest) { + searchUserRequest.setPageIndex((searchUserRequest.getPageIndex()-1)*searchUserRequest.getPageSize()); + SearchKeyWords model = UserMappers.INSTANCE.getSearchKeywordsRequestToModel(searchUserRequest); + List userList = userMapper.search(model); + int totalCount = userMapper.getTotalCount(model); + List singleUserResponseList = UserMappers.INSTANCE.userListToResponseList(userList); + UserSearchResponse userSearchResponse = new UserSearchResponse(); + userSearchResponse.setUserList(singleUserResponseList); + userSearchResponse.setTotalCount(totalCount); + return ElectromagneticResultUtil.success(userSearchResponse); + } + + @Override + public ElectromagneticResult deleteUser(UserDeleteRequest userDeleteRequest) { + // 将请求对象转换为模型对象 + UserDeleteKeyWords userDeleteKeyWords = UserMappers.INSTANCE.getUserDeleteRequestToModel(userDeleteRequest); + userDeleteKeyWords.setModifier(UserThreadLocal.getUserId()); + userDeleteKeyWords.setModifierName(UserThreadLocal.getUsername()); + + // 检查用户是否已经被逻辑删除 + User existingUser = userMapper.getSingleUser(userDeleteKeyWords.getUserId()); + + if(existingUser != null && existingUser.getEffectFlag()==0){ + // 如果用户已经被逻辑删除(在这个假设中,0 表示已删除),则不进行任何操作或返回错误 + return ElectromagneticResultUtil.fail(ElectromagneticErrorEnum. FINE_DELETE_USER_ERROR); + } + if(existingUser!=null && existingUser.getEffectFlag()==1){// 在这个假设中,1 表示未删除 + return ElectromagneticResultUtil.success(userMapper.deleteUser(userDeleteKeyWords)); + }else{ + // 如果用户不存在(理论上不应该发生,除非数据库状态不一致),则返回错误 + return ElectromagneticResultUtil.fail(ElectromagneticErrorEnum. FINE_DELETE_USER_ERROR); + + } + } + + @Override + public ElectromagneticResult logout(String token) { + token = token.substring(7); + return ElectromagneticResultUtil.success(tokenMapper.deleteToken(token)); + } +} diff --git a/electrmangnetic/src/main/resources/application.properties b/electrmangnetic/src/main/resources/application.properties new file mode 100644 index 0000000..2a11b3e --- /dev/null +++ b/electrmangnetic/src/main/resources/application.properties @@ -0,0 +1,45 @@ +#required +spring.application.name=electromagnetic-data +# security +run.mode=NORMAL +com.alipay.env=shared +#log +logging.file.path=./logs +loggerPath=electromagnetic-data +logging.level.com.aliyun.fsi.insurance=${LOG_LEVEL:INFO} +#日志配置 +logging.config=classpath:${LOG_CONFIG:log4j2-spring.xml} + + +spring.datasource.typd=com.alibaba.druid.pool.DruidDataSource +spring.datasource.url=jdbc:mysql://139.224.43.89:3306/em_data?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=true&rewriteBatchedStatements=true +spring.datasource.username=comac +spring.datasource.password=2024*Comac +spring.servlet.multipart.max-file-size=500MB +spring.servlet.multipart.max-request-size=10MB + +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver +spring.datasource.type=com.alibaba.druid.pool.DruidDataSource +mybatis-plus.mapper-locations=classpath:sqlmapper/*.xml +mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl +pagehelper.helperDialect=mysql +pagehelper.reasonable=false +server.port=12365 + +#windows文件存储目录 +data.windows.path=E:/comacFileStorage/ +#文件缓存路径 +data.file.cache.dir=/szsd/cache/ +#文件存储路径 +data.file.storage.dir=/szsd/fileStorage/ +#上传文件时文件的缓存文件夹名称 +data.upload.cache.dir=upload +#导出数据时文件的缓存文件夹名称 +data.export.cache.dir=export +#导入数据时文件的缓存文件夹名称 +data.import.cache.dir=import +file.encode.passwd=adknfhkj87654knd +#数据类型中的文件类型为file +data.type.file=file +#数据类型中的文件夹类型为folder +data.type.folder=folder diff --git a/electrmangnetic/src/main/resources/log4j.properties b/electrmangnetic/src/main/resources/log4j.properties new file mode 100644 index 0000000..f15f1e7 --- /dev/null +++ b/electrmangnetic/src/main/resources/log4j.properties @@ -0,0 +1,5 @@ +log4j.rootLogger=DEBUG, stdout +# Console output... +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n \ No newline at end of file diff --git a/electrmangnetic/src/main/resources/log4j2-spring-prod.xml b/electrmangnetic/src/main/resources/log4j2-spring-prod.xml new file mode 100644 index 0000000..199e1fc --- /dev/null +++ b/electrmangnetic/src/main/resources/log4j2-spring-prod.xml @@ -0,0 +1,205 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/electrmangnetic/src/main/resources/log4j2-spring.xml b/electrmangnetic/src/main/resources/log4j2-spring.xml new file mode 100644 index 0000000..4a41574 --- /dev/null +++ b/electrmangnetic/src/main/resources/log4j2-spring.xml @@ -0,0 +1,217 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/electrmangnetic/src/main/resources/sqlmapper/CategoryMapper.xml b/electrmangnetic/src/main/resources/sqlmapper/CategoryMapper.xml new file mode 100644 index 0000000..d5f91a2 --- /dev/null +++ b/electrmangnetic/src/main/resources/sqlmapper/CategoryMapper.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + select category_type_id, parent_id, category_id, category_name, category_status, + creator, creator_name, gmt_create, modifier, modifier_name, gmt_modified, effect_flag + from ed_category + + + + + + + + + + + + + SELECT LAST_INSERT_ID() + + replace into ed_data_info (id, + category_type_id, parent_id, category_id, + category_name, category_status, + creator, creator_name, gmt_create, + modifier, modifier_name, gmt_modified, + effect_flag + ) + values (#{id,jdbcType=VARCHAR}, #{categoryTypeId,jdbcType=VARCHAR}, + #{parentId,jdbcType=VARCHAR}, #{categoryId,jdbcType=VARCHAR}, + #{categoryName,jdbcType=VARCHAR}, #{categoryStatus,jdbcType=VARCHAR}, + #{creator,jdbcType=VARCHAR}, #{creatorName,jdbcType=VARCHAR}, now(), #{modifier,jdbcType=VARCHAR}, + #{modifierName,jdbcType=VARCHAR},now(),1 + ) + + + \ No newline at end of file diff --git a/electrmangnetic/src/main/resources/sqlmapper/EdDataInfoMapper.xml b/electrmangnetic/src/main/resources/sqlmapper/EdDataInfoMapper.xml new file mode 100644 index 0000000..da9db2e --- /dev/null +++ b/electrmangnetic/src/main/resources/sqlmapper/EdDataInfoMapper.xml @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id,category_id,data_id,data_no,data_name,data_type,file_type,version,content, + implant_json,data_status,note,editor,gmt_batch_upload,save_status,creator,creator_name,gmt_create,modifier,modifier_name, + gmt_modified,effect_flag + + + + + + SELECT LAST_INSERT_ID() + + replace into ed_data_info (category_id, + data_id, data_no, data_name, + data_type, file_type, version, + content, implant_json, data_status, + note, editor, gmt_batch_upload, save_status, + creator, creator_name, gmt_create, + modifier, modifier_name, gmt_modified, + effect_flag + ) + values (#{categoryId,jdbcType=VARCHAR}, + #{dataId,jdbcType=VARCHAR}, #{dataNo,jdbcType=VARCHAR}, #{dataName,jdbcType=VARCHAR}, + #{dataType,jdbcType=VARCHAR}, #{fileType,jdbcType=VARCHAR},#{version,jdbcType=VARCHAR}, + #{content,jdbcType=VARCHAR}, #{implantJson,jdbcType=VARCHAR}, #{dataStatus,jdbcType=VARCHAR}, + #{note,jdbcType=VARCHAR}, #{editor,jdbcType=VARCHAR}, #{gmtBatchUpload,jdbcType=TIMESTAMP}, #{saveStatus,jdbcType=VARCHAR}, + #{creator,jdbcType=VARCHAR}, #{creatorName,jdbcType=VARCHAR}, now(), #{modifier,jdbcType=VARCHAR}, + #{modifierName,jdbcType=VARCHAR},now(),1 + ) + + + + + + update ed_data_info + + + data_name = #{name,jdbcType=VARCHAR}, + + + data_status = #{dataStatus,jdbcType=VARCHAR}, + + + note = #{note,jdbcType=VARCHAR}, + + + save_status = #{saveStatus,jdbcType=VARCHAR}, + + + effect_flag = #{effectFlag,jdbcType=VARCHAR}, + + + modifier = #{userId,jdbcType=VARCHAR}, + + + modifier_name = #{userName,jdbcType=VARCHAR}, + + gmt_modified = now() + + + + + data_id = #{dataId,jdbcType=VARCHAR} + + + + category_id = #{parentId,jdbcType=VARCHAR} + + + + + + + diff --git a/electrmangnetic/src/main/resources/sqlmapper/TokenMapper.xml b/electrmangnetic/src/main/resources/sqlmapper/TokenMapper.xml new file mode 100644 index 0000000..a986bdd --- /dev/null +++ b/electrmangnetic/src/main/resources/sqlmapper/TokenMapper.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + select id, user_id, token, is_long_term, created_at, expire_at from tokens + + + + insert into tokens( + user_id, + token, + is_long_term, + created_at, + expire_at + ) + values ( + #{userId}, + #{token}, + 0, + now(), + #{expireAt} + ) + + + + + + delete from tokens where token=#{token} + + + \ No newline at end of file diff --git a/electrmangnetic/src/main/resources/sqlmapper/UserMapper.xml b/electrmangnetic/src/main/resources/sqlmapper/UserMapper.xml new file mode 100644 index 0000000..af1e27d --- /dev/null +++ b/electrmangnetic/src/main/resources/sqlmapper/UserMapper.xml @@ -0,0 +1,212 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + select user_id, user_name, work_number, mobile, user_dept, user_title, user_pwd, + join_time, is_published, salt, user_status, internship_end_date, + creator, creator_name, gmt_create, modifier, modifier_name, gmt_modified, effect_flag + from ed_users + + + + insert into ed_users( + user_id, + user_name, + work_number, + mobile, + user_dept, + user_title, + user_pwd, + join_time, + is_published, + salt, + user_status, + internship_end_date, + creator, + creator_name, + gmt_create, + effect_flag) + values ( + #{userId}, + #{userName}, + #{workNumber}, + #{mobile}, + #{userDept}, + #{userTitle}, + #{userPwd}, + #{joinTime}, + #{isPublished}, + #{salt}, + #{userStatus}, + #{internshipEndDate}, + #{creator}, + #{creatorName}, + now(), + 1 + ) + + + update ed_users + + user_id = #{userId}, + user_name = #{userName}, + work_number = #{workNumber}, + mobile = #{mobile}, + user_dept = #{userDept}, + user_title = #{userTitle}, + join_time = #{joinTime}, + user_status = #{userStatus}, + internship_end_date = #{internshipEndDate}, + modifier = #{modifier}, + modifier_name = #{modifierName}, + gmt_modified=now() + + where user_id= #{userId} + + + + + update ed_users + + is_published = 1, + modifier = #{modifier}, + modifier_name = #{modifierName}, + gmt_modified = now() + + where user_id IN + + #{userId} + + + + + + + + + + + + + update ed_users + + effect_flag=0, + modifier=#{modifier}, + modifier_name=#{modifierName}, + gmt_modified = now() + + where user_id = #{userId} + + \ No newline at end of file diff --git a/electrmangnetic/src/test/java/Test1.java b/electrmangnetic/src/test/java/Test1.java new file mode 100644 index 0000000..e5ff10a --- /dev/null +++ b/electrmangnetic/src/test/java/Test1.java @@ -0,0 +1,22 @@ +//import com.electromagnetic.industry.software.manage.Application; +//import com.electromagnetic.industry.software.manage.mapper.CategoryMapper; +//import com.electromagnetic.industry.software.manage.pojo.models.Category; +//import org.junit.jupiter.api.Test; +//import org.springframework.boot.test.context.SpringBootTest; +// +//import javax.annotation.Resource; +//import java.util.List; +// +//@SpringBootTest(classes = Application.class) +//public class Test1 { +// +// @Resource +// private CategoryMapper categoryMapper; +// +// @Test +// public void test() { +// List categories = categoryMapper.selectAllCategories(); +// System.out.println("categories = " + categories); +// } +// +//} diff --git a/electromagnetic-common/pom.xml b/electromagnetic-common/pom.xml new file mode 100644 index 0000000..89395fd --- /dev/null +++ b/electromagnetic-common/pom.xml @@ -0,0 +1,44 @@ + + + 4.0.0 + + com.electromagnetic.data + electromagnetic-data-new + 1.0-SNAPSHOT + + + electromagnetic-common + + + 8 + 8 + UTF-8 + 0.9.0 + + + + + org.projectlombok + lombok + 1.18.34 + + + io.jsonwebtoken + jjwt + ${jwt.version} + + + org.bouncycastle + bcprov-jdk16 + 1.46 + + + cn.hutool + hutool-all + 5.8.22 + + + + \ No newline at end of file diff --git a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/cons/ElectromagneticConstants.java b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/cons/ElectromagneticConstants.java new file mode 100644 index 0000000..2c560ae --- /dev/null +++ b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/cons/ElectromagneticConstants.java @@ -0,0 +1,7 @@ +package com.electromagnetic.industry.software.common.cons; + +public interface ElectromagneticConstants { + + String EXPORT_FILE_SUFFIX = ".colib"; + +} diff --git a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/cons/UserConstants.java b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/cons/UserConstants.java new file mode 100644 index 0000000..4693c1c --- /dev/null +++ b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/cons/UserConstants.java @@ -0,0 +1,36 @@ +package com.electromagnetic.industry.software.common.cons; + +public interface UserConstants { + + /** + * 默认初始密码 + */ + String DEFAULT_PASSWORD = "123456"; + + /** + * 默认发布状态(未发布) + */ + int DEFAULT_PUBLISH_STATUS = 0; + + /** + * 默认令牌过期时间(7天) + */ + long DEFAULT_EXPIRE_TIME = 7*24*60*60*1000; + + /** + * 令牌密钥 + */ + String SECRET_KEY = "5JKRGV0QO4WK1WCWVK55YEU0A1NPOXOP"; + + /** + * 令牌前缀 + */ + String LOGIN_USER_NAME = "userName"; + String LOGIN_WORK_NUMBER = "workNumber"; + String LOGIN_USER_ID = "userId"; + + /** + * 管理员账号 + */ + String ADMIN_WORK_NUMBER = "100000"; +} diff --git a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/enums/EffectFlagEnum.java b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/enums/EffectFlagEnum.java new file mode 100644 index 0000000..8203d55 --- /dev/null +++ b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/enums/EffectFlagEnum.java @@ -0,0 +1,27 @@ +package com.electromagnetic.industry.software.common.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 是否删除枚举 + * + * @author zhangxiong.pt + * @version $Id: EffectFlagEnum.java, v 0.1 2024-08-01 18:18 + */ +@AllArgsConstructor +@Getter +public enum EffectFlagEnum { + /** + * 有效 + */ + EFFECT_FLAG_1(1,"有效"), + /** + * 无效 + */ + EFFECT_FLAG_0(0,"无效"), + ; + private Integer code; + private String desc; + +} \ No newline at end of file diff --git a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/enums/ElectromagneticErrorEnum.java b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/enums/ElectromagneticErrorEnum.java new file mode 100644 index 0000000..9a00cf4 --- /dev/null +++ b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/enums/ElectromagneticErrorEnum.java @@ -0,0 +1,201 @@ +package com.electromagnetic.industry.software.common.enums; + +import lombok.Getter; + +@Getter +public enum ElectromagneticErrorEnum implements ErrorEnum { + /** + * 系统 + */ + SYSTEM_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "000", "SYSTEM_ERROR", "系统异常"), + PARAMS_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "001", "PARAMS_ERROR", "参数异常"), + /*****************业务级*****************/ + + + //111 + INPUT_PARAMETER_IS_EMPTY(ErrorLevels.ERROR, ErrorTypes.BIZ, "53001", "INPUT_PARAMETER_IS_EMPTY", "入参为空"), + NAME_IS_EMPTY(ErrorLevels.ERROR, ErrorTypes.BIZ, "53002", "NAME_IS_EMPTY", "名字为空"), + CREATOR_IS_EMPTY(ErrorLevels.ERROR, ErrorTypes.BIZ, "53003", "CREATOR_IS_EMPTY", "创建人不能为空"), + NAME_IS_REPEAT(ErrorLevels.ERROR, ErrorTypes.BIZ, "53004", "NAME_IS_REPEAT", "名字重复"), + NAME_FORM_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53005", "NAME_FORM_ERROR", "名字格式不正确"), + PARENT_CATEGORY_NOT_EXIST(ErrorLevels.ERROR, ErrorTypes.BIZ, "53006", "PARENT_CATEGORY_NOT_EXIST", "父类目不存在"), + DEPT_NOT_EXIST(ErrorLevels.ERROR, ErrorTypes.BIZ, "53007", "DEPT_NOT_EXIST", "属主部门不存在"), + + CATEGORY_BUILD_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53008", "CATEGORY_BUILD_ERROR", "类目代码生成失败"), + CATEGORY_INSERT_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53009", "CATEGORY_INSERT_ERROR", "类目新增异常"), + CATEGORY_NOT_EXIST_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53010", "CATEGORY_NOT_EXIST_ERROR", "类目不存在"), + CATEGORY_DELETE_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53011", "CATEGORY_DELETE_ERROR", "类目删除异常"), + REPORT_STATUS_CREATE(ErrorLevels.ERROR, ErrorTypes.BIZ, "53012", "REPORT_STATUS_CREATE", "新建状态可以编辑"), + REPORT_STATUS_DELETE(ErrorLevels.ERROR, ErrorTypes.BIZ, "53013", "REPORT_STATUS_CREATE", "新建状态可以删除"), + REPORT_DELETE(ErrorLevels.ERROR, ErrorTypes.BIZ, "53014", "REPORT_DELETE", "删除失败"), + REPORT_UPDATE(ErrorLevels.ERROR, ErrorTypes.BIZ, "53015", "REPORT_UPDATE", "更新失败"), + REPORT_CREATE(ErrorLevels.ERROR, ErrorTypes.BIZ, "53016", "REPORT_CREATE", "创建失败"), + REPORT_STATUS(ErrorLevels.ERROR, ErrorTypes.BIZ, "53017", "REPORT_STATUS", + "传入对应更新状态:●状态为“新增”,可操作“上架:3”;●状态为“使用中”,可传入“下架:4”;●状态为“将下架”,可操作“取消下架:6”"), + REPORT_GINSENG_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53018", "REPORT_GINSENG_NULL", "入参为空"), + REPORT_CHECK_NAME(ErrorLevels.ERROR, ErrorTypes.BIZ, "53019", "REPORT_GINSENG_NULL", "名称重复,请重新输入"), + GETSEQUENCEID_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53020", "GETSEQUENCEID_ERROR", "序列化ID生成错误"), + GET_DEPT_CODE_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53020", "GET_DEPT_CODE_ERROR", "部门编码获取异常"), + REPORT_NO_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53021", "REPORT_NO_ERROR", "ID生成不能为空"), + DEPT_INSERT_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53022", "DEPT_INSERT_ERROR", "新增异常"), + DEPT_EXIST(ErrorLevels.ERROR, ErrorTypes.BIZ, "53023", "DEPT_EXIST", "属主部门已存在"), + DEPT_ENUM_NOT_EXIST(ErrorLevels.ERROR, ErrorTypes.BIZ, "53024", "DEPT_ENUM_NOT_EXIST", "属主部门枚举映射不存在"), + DEPT_DELETE_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53025", "DEPT_DELETE_ERROR", "部门删除异常"), + REPORT_UN_SHELVE_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53026", "REPORT_UN_SHELVE_ERROR", "下架數據为空"), + + REPORT_ID_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53027", "REPORT_ID_NULL", "ID对应数据不存在"), + REPORT_UN_SHELVE_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53028", "REPORT_ID_NULL", "沒有下架數據"), + REPORT_CATEOGRYLV1_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53029", "REPORT_ID_NULL", "一級類目为空"), + REPORT_CATEOGRYLV2_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53030", "REPORT_ID_NULL", "二級類目为空"), + CATEGORY_EXIST(ErrorLevels.ERROR, ErrorTypes.BIZ, "53031", "CATEGORY_EXIST", "类目已存在"), + CATEGORY_EXIST_REPORT(ErrorLevels.ERROR, ErrorTypes.BIZ, "53032", "CATEGORY_EXIST_REPORT", "类目下已挂在数据"), + REPORT_URL_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53033", "REPORT_URL_ERROR", "FR报表地址错误"), + REPORT_OFF_DESC_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53034", "REPORT_URL_ERROR", "下架原因不能为空"), + REPORT_CANCEL_OFF_DESC_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53035", "REPORT_URL_ERROR", "取消下架原因不能为空"), + DEPT_EXIST_REPORT(ErrorLevels.ERROR, ErrorTypes.BIZ, "53036", "DEPT_EXIST_REPORT", "部门下已挂在数据"), + FINE_CREATE_USER_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53037", "FINE_CREATE_USER_ERROR", "创建用户失败"), + FINE_CONNECT_LIST_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53038", "FINE_CONNECT_LIST_ERROR", "获取finebi数据库连接列表错误"), + FINE_CONNECT_TABLE_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53039", "FINE_CONNECT_TABLE_ERROR", "获取finebi数据库对应表列表错误"), + FINE_ADD_GROUP_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53040", "FINE_ADD_GROUP_ERROR", "添加分组报错"), + FINE_ADD_PACK_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53041", "FINE_ADD_PACK_ERROR", "添加业务包报错"), + FINE_DELETE_USER_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53042", "FINE_DELETE_USER_ERROR", "删除用户失败"), + FINE_ADD_DB_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53043", "FINE_ADD_DB_ERROR", "数据集已存在,请不要重复添加"), + FINE_GET_TABLE_INFO_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53044", "FINE_GET_TABLE_INFO_ERROR", "数据集表信息错误"), + LABEL_OBJNAME_IS_CHINESE(ErrorLevels.ERROR, ErrorTypes.BIZ, "53045", "LABEL_OSS_ANALYSIS_FAIL", "名称不能包含特殊字符(下划线,横杠,加号 除外)"), + MEASURE_EXCEL_READ_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53046", "MEASURE_EXCEL_READ_ERROR", "文件读取失败,请按照模板重新上传!(是否有空值或重复数据或数据超过指定长度)"), + MEASURE_UPDATE_STATUS_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53047", "MEASURE_UPDATE_STATUS_ERROR", "当前状态不允许更新指标"), + FINE_ADD_TABLE_ROW_AUTHORITY_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53048", "FINE_ADD_TABLE_ROW_AUTHORITY_ERROR", "数据集添加行权限错误"), + FINE_GET_ENTRY_TREE_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53049", "fine_get_entry_tree_error", "bi获取目录报错"), + FINE_ENTRY_AUTH_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53050", "FINE_ENTRY_AUTH_ERROR", "目录授权失败"), + OAR_ORG_AUTH_LIST_REPEAT(ErrorLevels.ERROR, ErrorTypes.BIZ, "53051", "oar_org_auth_list_repeat", "适用机构重复"), + + ACCOUNT_INFO_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "630005", "ACCOUNT_INFO_BY_ACC_ID_NULL", "调用运营支撑域获取信息为空"), + ROLE_CODE_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "630005", "ACCOUNT_INFO_BY_ACC_ID_NULL", "用户对应角色为空"), + ROLE_ORG_CODE_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "630005", "ACCOUNT_INFO_BY_ACC_ID_NULL", "工作组对应組员为空"), + USER_ROLE_ORG_CODE_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "630008", "ACCOUNT_INFO_BY_ACC_ID_NULL", "角色对应机构为空"), + OSS_ANALYSIS_FAIL(ErrorLevels.ERROR, ErrorTypes.BIZ, "50", "OSS_ANALYSIS_FAIL", "excel不能为空"), + OAR_OFFLINE_CONFIG_NAME_REPEAT(ErrorLevels.ERROR, ErrorTypes.BIZ, "630009", "OAR_OFFLINE_CONFIG_NAME_REPEAT", "名称重复"), + OAR_OFFLINE_CONFIG_DIMENSION_MEASURE_ERROR1(ErrorLevels.ERROR, ErrorTypes.BIZ, "630009", "OAR_OFFLINE_CONFIG_DIMENSION_MEASURE_ERROR1", "统计报表维度和度量不能为空"), + OAR_OFFLINE_CONFIG_DIMENSION_MEASURE_ERROR2(ErrorLevels.ERROR, ErrorTypes.BIZ, "630009", "OAR_OFFLINE_CONFIG_DIMENSION_MEASURE_ERROR2", "清单报表维度和度量至少一个不能为空"), + OAR_OFFLINE_CONFIG_CONDITION_VALUE_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "6300010", "OAR_OFFLINE_CONFIG_CONDITION_VALUE_NULL", "筛选条件值不能为空"), + OAR_OFFLINE_CONFIG_NAME_NOT_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "630006", "OAR_OFFLINE_CONFIG_NAME_NOT_NULL", "任务名称不能为空"), + OAR_OFFLINET_SQL_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "6300013", "OAR_OFFLINET_SQL_ERROR", "离线任务运行报错"), + + OFFLINE_ERRORL(ErrorLevels.ERROR, ErrorTypes.BIZ, "630011", "OFFLINE_ERRORL", "更新失敗"), + SEND_MESSAGE(ErrorLevels.ERROR, ErrorTypes.BIZ, "630012", "SEND_MESSAGE", "获取对应wrapper 异常"), + OAR_OFFLINE_CONFIG_DETAIL_REPEAT(ErrorLevels.ERROR, ErrorTypes.BIZ, "630014", "oar_offline_config_detail_repeat", "该模板所选字段并无更改,请通过原模板 \"离线取数\" 功能提交离线任务!"), + + EXCEL_TYPE_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "100", "EXCEL_TYPE_ERROR", "报表类型不正确"), + EXCEL_DELETE(ErrorLevels.ERROR, ErrorTypes.BIZ, "101", "EXCEL_DELETE", "行业数据删除失败"), + DATA_EXCEL_DELETE(ErrorLevels.ERROR, ErrorTypes.BIZ, "102", "DATA_EXCEL_DELETE", "业务数据删除失败"), + IMPORT_DATA_EXCEL(ErrorLevels.ERROR, ErrorTypes.BIZ, "103", "IMPORT_DATA_EXCEL", "业务数据导入失败"), + UPDATE_DATA_EXCEL(ErrorLevels.ERROR, ErrorTypes.BIZ, "104", "UPDATE_DATA_EXCEL", "业务数据更新失败"), + INSTITUTION_CODE_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "105", "INSTITUTION_CODE_ERROR", "行机构编码错误!"), + DATA_EMPTY(ErrorLevels.ERROR, ErrorTypes.BIZ, "106", "DATA_EMPTY", "模板存在空值,请检查并补充完整;"), + NUMBER_EMPTY(ErrorLevels.ERROR, ErrorTypes.BIZ, "107", "NUMBER_EMPTY", "电融(万元)&网销(万元)&车商(万元)&线下(万元)&中介(万元)&重客(万元)总和不等于该行合计值"), + DATA_EXIST(ErrorLevels.ERROR, ErrorTypes.BIZ, "108", "DATA_EXIST", "模板存在重复项,请检查更新!"), + VELOCITY_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "109", "VELOCITY_ERROR", "模板转换失败"), + PLAN_TYPE_DATE(ErrorLevels.ERROR, ErrorTypes.BIZ, "110", "PLAN_TYPE_DATE", "计划周期格式错误!"), + WEEK_XUN_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "111", "WEEK_XUN_ERROR", "你所传的文件不是周旬报"), + TOPIC_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "112", "TOPIC_ERROR", "主题不匹配"), + CALIBER_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "113", "CALIBER_ERROR", "指标口径不匹配"), + DATA_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "114", "DATA_ERROR", "报表缺失月份数据"), + DATA_IS_EXIST(ErrorLevels.ERROR, ErrorTypes.BIZ, "115", "DATA_IS_EXIST", "数据已存在"), + + DEPT_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53049", "DEPT_NULL", "当前该账户尚未授权,请联系管理员申请权限!"), + MEMBER_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53050", "MEMBER_NULL", "对应组员为空"), + ORG_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53050", "MEMBER_NULL", "用戶对应机构权限为空"), + DATA_AUTHRIZATION(ErrorLevels.ERROR, ErrorTypes.BIZ, "53051", "DATA_AUTHRIZATION", "数据集授权"), + GROUP_FLAG(ErrorLevels.ERROR, ErrorTypes.BIZ, "53052", "DATA_AUTHRIZATION", "工作组失效"), + DATA_USER_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53053", "DATA_AUTHRIZATION", "数据为空"), + DATA_UPDATE_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53054", "DATA_AUTHRIZATION", "数据为空。"), + DATA_COLLECT_AUTH_IS(ErrorLevels.ERROR, ErrorTypes.BIZ, "53055", "DATA_COLLECT_AUTH_IS", "对应数据集和仪表板已经授权完成"), + DATA_COLLECT_AUTH_IS_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53056", "DATA_COLLECT_AUTH_IS_NULL", "对应数据为空"), + DATA_PRODUCT_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53057", "DATA_PRODUCT_NULL", "产品权限为空"), + IMPORT_DATA_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53058", "IMPORT_DATA_NULL", "导入数据为空"), + IMPORT_DATA_IS_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53059", "IMPORT_DATA_IS_NULL", "对应数据为空"), + IMPORT_REPEAT_DATA(ErrorLevels.ERROR, ErrorTypes.BIZ, "53060", "IMPORT_REPEAT_DATA", "重复数据"), + DATA_IS_INVALID(ErrorLevels.ERROR, ErrorTypes.BIZ, "53061", "DATA_IS_INVALID", "对应清单失效,请创建新的模板"), + DATA_AUTH_USER_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53062", "data_auth_user_null", "用户组没有匹配到有权限的数据集"), + FILE_NOT_EXIST(ErrorLevels.ERROR, ErrorTypes.BIZ, "53063", "FILE_NOT_EXIST", "字段文件下载失败"), + EXCEL_FIELD_ANALYTICS_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53066", "EXCEL_FIELD_ANALYTICS_ERROR", "excel解析异常,请检查内容"), + TASK_TIME_ROLE(ErrorLevels.ERROR, ErrorTypes.BIZ, "53067", "TASK_TIME_ROLE", "请设置定时任务日期滚动规则后再提交"), + TASK_TEMPLATE_CREATE(ErrorLevels.ERROR, ErrorTypes.BIZ, "53067", "TASK_TIME_ROLE", "支持1~50个字符!"), + IMPORT_DATA_LENGTH(ErrorLevels.ERROR, ErrorTypes.BIZ, "53068", "IMPORT_DATA_LENGTH", "字段说明长度支持100个字符!"), + FILE_NAME_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53069", "FILE_NAME_ERROR", "文件命名错误"), + FILE_NAME_REPEAT(ErrorLevels.ERROR, ErrorTypes.BIZ, "53070", "FILE_NAME_REPEAT", "存在相同命名的文件,请检查后重更新上传!"), + INDICATORCARD_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53071", "INDICATORCARD_NULL", "指标卡为空!"), + INDICATORCARD_DATA_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53072", "INDICATORCARD_DATA_ERROR", "指标数据请求异常!"), + ANALYSISITEMPLATE_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53073", "ANALYSISITEMPLATE_ERROR", "模板创建DB失败!"), + INDICATORCARD_DB_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53074", "INDICATORCARD_DB_ERROR", "指标卡DB操作异常!"), + INDICATORCARD_WARNING_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53075", "INDICATORCARD_WARNING_NULL", "预警已存在!"), + RESOURCE_NO_GENERATE_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53076", "RESOURCE_NO_GENERATE_ERROR", "业务编码生成异常,请联系管理员"), + INDICATOR_DATASERVICE_NO_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53077", "INDICATOR_DATASERVICE_NO_NULL", "服务编码不能为空!"), + INDICATOR_DT_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53078", "INDICATOR_DT_NULL", "指标数据DT时间为空!"), + INDICATOR_HOST_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53079", "INDICATOR_HOST_NULL", "主指标不能为空!"), + INDICATOR_CARD_NO_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53080", "INDICATOR_CARD_NO_NULL", "指标卡编码不能为空!"), + INDICATOR_CARD_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53081", "INDICATOR_CARD_NULL", "无匹配的指标卡!"), + INDICATOR_DATAFILE_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53082", "INDICATOR_DATAFILE_NULL", "返回数据中没有指标字段!"), + INDICATOR_DT_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53083", "INDICATOR_DT_ERROR", "请选择正确的DT或者服务编码!"), + DRILLINGCONFIG_INDICATOR_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53084", "DRILLINGCONFIG_INDICATOR_NULL", "下钻配置字段未匹配到指标字段!"), + DUTIES_UPDATE_IDS_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53085", "DUTIES_UPDATE_IDS_ERROR", "入参ids不能为空"), + DUTIES_MEASURES_UPDATE_LIST_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53086", "DUTIES_MEASURES_UPDATE_LIST_ERROR", "举措信息不能为空"), + INDICATOR_WARN_CREATE_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53087", "INDICATOR_WARN_CREATE_ERROR", "保存指标预警规则失败"), + INDICATOR_WARN_UPDATE_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53088", "INDICATOR_WARN_UPDATE_ERROR", "指标预警规则更新失败"), + INDICATOR_WARN_RESULT_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53089", "INDICATOR_WARN_RESULT_ERROR", "指标预警结果查询失败"), + INDICATOR_WARN_DEL_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53090", "INDICATOR_WARN_DEL_ERROR", "指标预警删除失败"), + INDICATOR_WARN_NULL_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53091", "INDICATOR_WARN_NULL_ERROR", "请求预警中心参数为空"), + MESSAGE_DING_PUSH_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53092", "MESSAGE_DING_PUSH_ERROR", "钉钉消息推送失败"), + INDICATORCARD_UPDATESTATUSOREFFECT_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53093", "INDICATORCARD_UPDATESTATUSOREFFECT_ERROR", "指标卡状态更新或删除失败"), + INDICATORCARD_INVALID_OPERATION(ErrorLevels.ERROR, ErrorTypes.BIZ, "53094", "INDICATORCARD_INVALID_OPERATION", "指标卡状态更新或删除无效的操作"), + DUTIES_CREATE_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53095", "DUTIES_CREATE_ERROR", "一键通知失败!"), + DUTIES_MEASURES_SOLVETIME_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53096", "DUTIES_MEASURES_SOLVETIME_ERROR", "请选择正确的举措时间"), + USER_INFO_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53097", "USER_INFO_NULL", "用户信息不能为空!"), + EXIST_GOAL_CONFIG(ErrorLevels.ERROR, ErrorTypes.BIZ, "53098", "EXIST_GOAL_CONFIG", "已存在该年度的目标计划!"), + DATASERVICE_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53099", "DATASERVICE_NULL", "数据服务不存在!"), + DATASERVICE_NO_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53100", "DATASERVICE_NO_NULL", "服务编码不存在!"), + ANALYSISTEMPLATE_NO_NULL(ErrorLevels.ERROR, ErrorTypes.BIZ, "53101", "ANALYSISTEMPLATE_NO_NULL", "模板不存在!"), + INDICATORCARWRAINGONE(ErrorLevels.ERROR, ErrorTypes.BIZ, "53102", "INDICATORCARWRAINGONE", "一个指标卡只支持一个预警指标!"), + TESTDRILLINGDATA_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53103", "TESTDRILLINGDATA_ERROR", "下钻服务测试失败!"), + DRILLINGCONFIG_ORGLEVE_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53104", " DRILLINGCONFIG_ORGLEVE_ERROR", "下钻机构权限勾选不正确!"), + BRANCH_ORGANIZATION_ERROR(ErrorLevels.ERROR, ErrorTypes.BIZ, "53105", "BRANCH_ORGANIZATION_ERROR", "获取用户配置机构信息!"), + ; + + + private String codeType; + + private String codeLevel; + + private String code; + + private String errorMessage; + + private String errorDesc; + + /** + * DataplatformLabelErrorEnum + * + * @param codeLevel + * @param codeType + * @param code + * @param errorMessage + * @param errorDesc + */ + ElectromagneticErrorEnum(String codeLevel, String codeType, String code, String errorMessage, String errorDesc) { + + this.codeType = codeType; + this.codeLevel = codeLevel; + this.code = code; + this.errorMessage = errorMessage; + this.errorDesc = errorDesc; + } + + public void setErrorDesc(String errorDesc) { + this.errorDesc = errorDesc; + } + + public ElectromagneticErrorEnum changeErrorDesc(String str) { + this.setErrorDesc(str); + return this; + } +} \ No newline at end of file diff --git a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/enums/ErrorEnum.java b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/enums/ErrorEnum.java new file mode 100644 index 0000000..625cefa --- /dev/null +++ b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/enums/ErrorEnum.java @@ -0,0 +1,14 @@ +package com.electromagnetic.industry.software.common.enums; + +public interface ErrorEnum { + + String getCodeType(); + + String getCodeLevel(); + + String getCode(); + + String getErrorMessage(); + + String getErrorDesc(); +} diff --git a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/enums/ErrorLevels.java b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/enums/ErrorLevels.java new file mode 100644 index 0000000..d323de2 --- /dev/null +++ b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/enums/ErrorLevels.java @@ -0,0 +1,20 @@ +package com.electromagnetic.industry.software.common.enums; + +/** + * @author wsk + * @version $Id: ErrorLevels.java, v 0.1 2024-10-17 17:44 wsk + */ +public interface ErrorLevels { + + /** INFO级别 */ + public static final String INFO = "1"; + + /** WARN级别 */ + public static final String WARN = "3"; + + /** ERROR级别 */ + public static final String ERROR = "5"; + + /** FATAL级别 */ + public static final String FATAL = "7"; +} \ No newline at end of file diff --git a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/enums/ErrorTypes.java b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/enums/ErrorTypes.java new file mode 100644 index 0000000..fc053e7 --- /dev/null +++ b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/enums/ErrorTypes.java @@ -0,0 +1,18 @@ +package com.electromagnetic.industry.software.common.enums; + +public interface ErrorTypes { + + /** 系统错误 */ + public static final String SYSTEM = "0"; + + /** 业务错误 */ + @Deprecated + public static final String BIZ = "1"; + + /** 第三方错误 */ + @Deprecated + public static final String THIRD_PARTY = "2"; + + /** 业务错误,客户感知 */ + public static final String BIZ_CUSTOMER = "9"; +} \ No newline at end of file diff --git a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/enums/PublishEnum.java b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/enums/PublishEnum.java new file mode 100644 index 0000000..2387b32 --- /dev/null +++ b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/enums/PublishEnum.java @@ -0,0 +1,21 @@ +package com.electromagnetic.industry.software.common.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +@Getter +public enum PublishEnum { + /** + * 已发布 + */ + PUBLISHED(1,"已发布"), + /** + * 未发布 + */ + UNPUBLISHED(0,"未发布"), + ; + private Integer code; + private String desc; + +} diff --git a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/pojo/UserLoginInfo.java b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/pojo/UserLoginInfo.java new file mode 100644 index 0000000..549bfeb --- /dev/null +++ b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/pojo/UserLoginInfo.java @@ -0,0 +1,32 @@ +package com.electromagnetic.industry.software.common.pojo; + +import lombok.Data; + +@Data +public class UserLoginInfo { + + /** + * 工号 + */ + private String workNumber; + + /** + * 用户名 + */ + private String username; + + /** + * 用户编号 + */ + private String userId; + + /** + * 用户密码 + */ + private String userPwd; + + /** + * 令牌 + */ + private String token; +} diff --git a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/resp/ElectromagneticResult.java b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/resp/ElectromagneticResult.java new file mode 100644 index 0000000..1e4ac6b --- /dev/null +++ b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/resp/ElectromagneticResult.java @@ -0,0 +1,124 @@ +package com.electromagnetic.industry.software.common.resp; + +import java.io.Serializable; + +public class ElectromagneticResult implements Serializable, Result { + + private static final long serialVersionUID = -6408526187818056594L; + /** + * 请求成功还是失败 + */ + private Boolean success; + + /** + * 错误码 + */ + private String errorCode; + + /** + * 错误消息 + */ + private String errorMessage; + + /** + * 数据对象传给前台的json + */ + private T data; + + public ElectromagneticResult() { + + } + + public ElectromagneticResult(Boolean success, String errorCode, String errorMessage, T data) { + this.success = success; + this.errorCode = errorCode; + this.errorMessage = errorMessage; + this.data = data; + } + + /** + * Getter method for property success. + * + * @return property value of success + */ + public Boolean getSuccess() { + return success; + } + + /** + * Setter method for property success. + * + * @param success value to be assigned to property success + */ + public void setSuccess(Boolean success) { + this.success = success; + } + + + /** + * Getter method for property data. + * + * @return property value of data + */ + public T getData() { + return data; + } + + /** + * Setter method for property data. + * + * @param data value to be assigned to property data + */ + public void setData(T data) { + this.data = data; + } + + @Override + public Integer getStatus() { + return success ? 1 : 0; + } + + /** + * Getter method for property errorCode. + * + * @return property value of errorCode + */ + public String getErrorCode() { + return errorCode; + } + + /** + * Setter method for property errorCode. + * + * @param errorCode value to be assigned to property errorCode + */ + public void setErrorCode(String errorCode) { + this.errorCode = errorCode; + } + + /** + * Getter method for property errorMsg. + * + * @return property value of errorMsg + */ + public String getErrorMessage() { + return errorMessage; + } + + /** + * Setter method for property errorMsg. + * + * @param errorMessage value to be assigned to property errorMsg + */ + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + @Override + public Message getMessage() { + Message msg = new Message(this.getErrorMessage()); + //页面展示时,防止出现null状况 + msg.setCode(""); + return msg; + } +} diff --git a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/resp/ErrorContext.java b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/resp/ErrorContext.java new file mode 100644 index 0000000..a113151 --- /dev/null +++ b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/resp/ErrorContext.java @@ -0,0 +1,122 @@ +package com.electromagnetic.industry.software.common.resp; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ErrorContext implements Serializable { + + /** + * 序列ID + */ + private static final long serialVersionUID = 3939009139641299179L; + + /** + * 默认分隔符 + */ + private static final String SPLIT = "|"; + + /** + * 错误堆栈集合 + */ + private List errorStack = new ArrayList(); + + /** + * 第三方错误原始信息 + */ + private String thirdPartyError; + + /** + * 错误变量映射 + */ + private Map errorVariableMap = new HashMap(); + + /** + * 默认构造方法。 + */ + public ErrorContext() { + // 默认构造方法 + } + + /** + * 获取当前错误对象。 + * + * @return 当前错误码对象 + */ + public ResultCode fetchCurrentError() { + if (errorStack != null && errorStack.size() > 0) { + return errorStack.get(errorStack.size() - 1); + } + + return null; + } + + /** + * 向堆栈中添加错误对象。 + * + * @param error 错误码 + */ + public void addError(ResultCode error) { + if (errorStack == null) { + errorStack = new ArrayList(); + } + + errorStack.add(error); + } + + /** + * 获取字符串形式的错误码堆栈 + * + * @return 错误码堆栈 + */ + @Deprecated + public String fetchErrorCodeStack() { + StringBuffer sb = new StringBuffer(); + for (int i = errorStack.size(); i > 0; i--) { + if (i == errorStack.size()) { + sb.append(errorStack.get(i - 1)); + } else { + sb.append(SPLIT).append(errorStack.get(i - 1)); + } + } + + return sb.toString(); + } + + /** + * 获取字符串形式的错误码堆栈digest + * + * @return 错误码堆栈 + */ + public String fetchErrorCodeStackDigest() { + StringBuffer sb = new StringBuffer(); + for (int i = errorStack.size(); i > 0; i--) { + if (i == errorStack.size()) { + sb.append(errorStack.get(i - 1)); + } else { + sb.append(SPLIT).append(errorStack.get(i - 1)); + } + } + + return sb.toString(); + } + + @Override + public String toString() { + StringBuffer sb = new StringBuffer(); + + //错误堆栈 + sb.append("errorStack=["); + sb.append(fetchErrorCodeStackDigest()); + sb.append("],"); + + //第三方错误 + sb.append("thirdPartyError=["); + sb.append(thirdPartyError); + sb.append("]"); + + return sb.toString(); + } +} diff --git a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/resp/Message.java b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/resp/Message.java new file mode 100644 index 0000000..76dd9b1 --- /dev/null +++ b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/resp/Message.java @@ -0,0 +1,50 @@ +package com.electromagnetic.industry.software.common.resp; + +public class Message { + + /** + * 返回结果码 + */ + private String code; + /** + * 返回结果信息 + */ + private String message; + /** + * 返回错误明细 + */ + private ErrorContext errorContext; + + public Message(String messageStr) { + this.message = messageStr; + } + + public String getCode() { + return code; + } + + public Message setCode(String code) { + this.code = code; + return this; + } + + public String getMessage() { + return message; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("code = "); + builder.append(code); + builder.append(", message = "); + builder.append(message); + builder.append(", "); + builder.append("BaseResult ["); + builder.append("errorContext="); + builder.append(errorContext); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/resp/Result.java b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/resp/Result.java new file mode 100644 index 0000000..027268e --- /dev/null +++ b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/resp/Result.java @@ -0,0 +1,17 @@ +package com.electromagnetic.industry.software.common.resp; + +public interface Result { + /** + * 返回状态 + * + * @return + */ + Integer getStatus(); + + /** + * 返回消息 + * + * @return + */ + Message getMessage(); +} diff --git a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/resp/ResultCode.java b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/resp/ResultCode.java new file mode 100644 index 0000000..ee0e351 --- /dev/null +++ b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/resp/ResultCode.java @@ -0,0 +1,396 @@ +package com.electromagnetic.industry.software.common.resp; + +import java.io.Serializable; + +public class ResultCode implements Serializable { + + /** 序列ID */ + private static final long serialVersionUID = 3951948353107763580L; + + /** 结果码固定前缀 */ + protected static final String PREFIX = "CE"; + + /** 结果码版本 */ + private String version; + + /** 结果码级别[第9位],INFO-1,WARN-3,ERROR-5,FATAL-7,参见ResultCodeLevel定义 */ + private String codeLevel; + + /** 结果码类型[第10位],SUCCESS-0,BIZ_ERROR-1,SYS_ERROR-2,THIRD_ERROR-3,参见ResultCodeType定义 */ + private String codeType; + + /** 系统编号[第11-13位],见SystemCode定义 */ + private String systemCode; + + /** 系统名称 */ + private String systemName; + + /** 具体结果码[第14-17位] */ + private String errorSpecific; + + /** 错误英文简称 */ + private String errorName; + + /** 结果码信息描述,可空 */ + private String description; + + // ~~~ 构造方法 + + /** + * 默认构造方法。 + */ + public ResultCode() { + // 默认构造方法。 + } + + /** + * 构造方法。 + * + * @param resultCode 结果码字符串 + */ + public ResultCode(String resultCode) { + + //结果码长度检查 + checkStringLength(resultCode, 16); + + //拆分结果码 + spliteResultCode(resultCode); + } + + /** + * 构造方法。 + * + * @param resultCode 结果码字符串 + * @param errorName 错误码英文简称 + */ + public ResultCode(String resultCode, String errorName) { + this(resultCode); + this.errorName = errorName; + } + + /** + * 构造方法。 + * + * @param resultCode 结果码字符串 + * @param errorName 错误码英文简称 + * @param description 结果码信息描述 + */ + public ResultCode(String resultCode, String errorName, String description) { + this(resultCode); + this.errorName = errorName; + this.description = description; + } + + /** + * 构造方法。 + * + * @param version 版本 + * @param codeLevel 结果码级别 + * @param codeType 结果码类型 + * @param systemCode 系统编号 + * @param errorSpecific 具体错误码 + */ + public ResultCode(String version, String codeLevel, String codeType, String systemCode, String errorSpecific) { + this.version = version; + this.codeLevel = codeLevel; + this.codeType = codeType; + this.systemCode = systemCode; + this.errorSpecific = errorSpecific; + } + + /** + * 构造方法。 + * + * @param version 版本 + * @param codeLevel 结果码级别 + * @param codeType 结果码类型 + * @param systemCode 系统编号 + * @param errorSpecific 具体错误码 + * @param errorName 错误码英文简称 + */ + public ResultCode(String version, String codeLevel, String codeType, String systemCode, String errorSpecific, + String errorName) { + this(version, codeLevel, codeType, systemCode, errorSpecific); + this.errorName = errorName; + } + + // ~~~ 公有方法 + + /** + * 组装返回码字符串。 + * + * @return 返回码字符串 + */ + public String fetchResultCode() { + StringBuffer sb = new StringBuffer(); + + sb.append(PREFIX); + sb.append(version); + sb.append(codeLevel); + sb.append(codeType); + sb.append(systemCode); + sb.append(errorSpecific); + + return sb.toString(); + } + + /** + * 组装返回码字符串。 解决enum 单利线程安全问题 + * + * @param eventCode + * @return 返回码字符串 + */ + public String fetchResultCode(String eventCode) { + StringBuffer sb = new StringBuffer(); + + sb.append(PREFIX); + sb.append(version); + sb.append(codeLevel); + sb.append(codeType); + sb.append(eventCode); + sb.append(errorSpecific); + + return sb.toString(); + } + + /** + * 构建错误对象digest + * + * @return 错误码摘要日志 + */ +// public String toDigest() { +// +// //组装结果码字符串 +// String resultCode = fetchResultCode(); +// +// if (StringUtils.isNotBlank(errorName)) { +// resultCode = resultCode + "@" + errorName; +// } else { +// resultCode = resultCode + "@"; +// } +// +// if (StringUtils.isNotBlank(systemName)) { +// resultCode = resultCode + "@" + systemName; +// } else { +// resultCode = resultCode + "@"; +// } +// +// return resultCode; +// } + + // ~~~ 重写方法 + + /** + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + //错误完整性检查 + checkStringLength(this.version, 1); + checkStringLength(this.codeLevel, 1); + checkStringLength(this.codeType, 1); + checkStringLength(this.systemCode, 8); + checkStringLength(this.errorSpecific, 3); + + //组装结果码字符串 + String resultCode = fetchResultCode(); + +// if (StringUtils.isNotBlank(errorName)) { +// resultCode = resultCode + "@" + errorName; +// } + + return resultCode; + } + + /** + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return this.fetchResultCode().hashCode(); + } + + /** + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + + if (obj == this) { + return true; + } + + if (obj == null) { + return false; + } + return false; + +// return StringUtils.equals(this.fetchResultCode(), (((ResultCode) obj).fetchResultCode())); + } + + // ~~~ 内部方法 + + /** + * 解析和拆分结果码。 + * + * @param resultCode 结果码字符串 + */ + private void spliteResultCode(String resultCode) { + if (!resultCode.startsWith(PREFIX)) { + throw new IllegalArgumentException(); + } + + char[] chars = resultCode.toCharArray(); + + // 旧:CIC_RS_100000200 + // 新:CE15112000201001 + + this.version = "" + chars[2]; + this.codeLevel = "" + chars[3]; + this.codeType = "" + chars[4]; + this.systemCode = "" + chars[5] + chars[6] + chars[7] + chars[8] + chars[9] + chars[10] + chars[11] + chars[12]; + this.errorSpecific = "" + chars[13] + chars[14] + chars[15]; + } + + /** + * 字符串长度检查。 + * + * @param resultCode 结果码字符串 + * @param length 长度 + */ + private void checkStringLength(String resultCode, int length) { + if (resultCode == null || resultCode.length() != length) { + throw new IllegalArgumentException(); + } + } + + // ~~~ bean方法 + + /** + * Getter method for property codeLevel. + * + * @return property value of codeLevel + */ + public String getCodeLevel() { + return codeLevel; + } + + /** + * Setter method for property codeLevel. + * + * @param codeLevel value to be assigned to property codeLevel + */ + public void setCodeLevel(String codeLevel) { + this.codeLevel = codeLevel; + } + + /** + * Getter method for property codeType. + * + * @return property value of codeType + */ + public String getCodeType() { + return codeType; + } + + /** + * Setter method for property codeType. + * + * @param codeType value to be assigned to property codeType + */ + public void setCodeType(String codeType) { + this.codeType = codeType; + } + + /** + * Getter method for property systemCode. + * + * @return property value of systemCode + */ + public String getSystemCode() { + return systemCode; + } + + /** + * Setter method for property systemCode. + * + * @param systemCode value to be assigned to property systemCode + */ + public void setSystemCode(String systemCode) { + this.systemCode = systemCode; + } + + /** + * Getter method for property errorSpecific. + * + * @return property value of errorSpecific + */ + public String getErrorSpecific() { + return errorSpecific; + } + + /** + * Setter method for property errorSpecific. + * + * @param errorSpecific value to be assigned to property errorSpecific + */ + public void setErrorSpecific(String errorSpecific) { + this.errorSpecific = errorSpecific; + } + + /** + * Getter method for property description. + * + * @return property value of description + */ + public String getDescription() { + return description; + } + + /** + * Setter method for property description. + * + * @param description value to be assigned to property description + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * Getter method for property systemName. + * + * @return property value of systemName + */ + public String getSystemName() { + return systemName; + } + + /** + * Setter method for property systemName. + * + * @param systemName value to be assigned to property systemName + */ + public void setSystemName(String systemName) { + this.systemName = systemName; + } + + /** + * Getter method for property errorName. + * + * @return property value of errorName + */ + public String getErrorName() { + return errorName; + } + + /** + * Setter method for property errorName. + * + * @param errorName value to be assigned to property errorName + */ + public void setErrorName(String errorName) { + this.errorName = errorName; + } + +} \ No newline at end of file diff --git a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/util/AESUtils.java b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/util/AESUtils.java new file mode 100644 index 0000000..5b85bb3 --- /dev/null +++ b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/util/AESUtils.java @@ -0,0 +1,98 @@ +package com.electromagnetic.industry.software.common.util; + + +import cn.hutool.core.codec.Base64; +import org.bouncycastle.jce.provider.BouncyCastleProvider; + + +import javax.crypto.*; +import javax.crypto.spec.SecretKeySpec; +import java.io.UnsupportedEncodingException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.security.Security; + +/** + *

Description: [AES对称加密和解密]

+ * @description: + * @author: + * @create: 2022/07/06 10:52 + */ +public class AESUtils { + + /** + *

Discription:[加密]

+ * Created on 2022/07/06 10:52 + * @param content 明文 用JSON.toJSONString(Map map)转换的json字符串 + * @param key 加解密规则 访客系统提供key + * @return String 密文 + */ + public static String ecodes(String content, String key) { + if (content == null || content.length() < 1) { + return null; + } + try { + KeyGenerator kgen = KeyGenerator.getInstance("AES"); + SecureRandom random= SecureRandom.getInstance("SHA1PRNG"); + random.setSeed(key.getBytes()); + kgen.init(128, random); + SecretKey secretKey = kgen.generateKey(); + byte[] enCodeFormat = secretKey.getEncoded(); + SecretKeySpec secretKeySpec = new SecretKeySpec(enCodeFormat, "AES"); + Cipher cipher = Cipher.getInstance("AES"); + byte[] byteContent = content.getBytes("utf-8"); + cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec); + byte[] byteRresult = cipher.doFinal(byteContent); + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < byteRresult.length; i++) { + String hex = Integer.toHexString(byteRresult[i] & 0xFF); + if (hex.length() == 1) { + hex = '0' + hex; + } + sb.append(hex.toUpperCase()); + } + return sb.toString(); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (NoSuchPaddingException e) { + e.printStackTrace(); + } catch (InvalidKeyException e) { + e.printStackTrace(); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } catch (IllegalBlockSizeException e) { + e.printStackTrace(); + } catch (BadPaddingException e) { + e.printStackTrace(); + } + return null; + } + + + /** + * 前端使用ECB,后端解密方法 + * @param enc + * @param key + * @return + */ + public static String decrypt(String enc, String key) { + try{ + SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(), "AES"); + Security.addProvider(new BouncyCastleProvider()); + Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding"); + cipher.init(Cipher.DECRYPT_MODE, secretKeySpec); + return new String(cipher.doFinal(Base64.decode(enc))); + } catch (NoSuchPaddingException e) { + throw new RuntimeException(e); + } catch (IllegalBlockSizeException e) { + throw new RuntimeException(e); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e); + } catch (BadPaddingException e) { + throw new RuntimeException(e); + } catch (InvalidKeyException e) { + throw new RuntimeException(e); + } + } +} \ No newline at end of file diff --git a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/util/EleCommonUtil.java b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/util/EleCommonUtil.java new file mode 100644 index 0000000..6795ccb --- /dev/null +++ b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/util/EleCommonUtil.java @@ -0,0 +1,40 @@ +package com.electromagnetic.industry.software.common.util; + +import java.util.regex.Pattern; + +public final class EleCommonUtil { + + // 正则表达式模式,匹配中文字符、下划线、连字符、加号、数字和英文字符 + private static final String PATTERN = "^[\\u4e00-\\u9fa5a-zA-Z0-9._\\-+]+$"; + + // 编译正则表达式 + private static final Pattern pattern = Pattern.compile(PATTERN); + + public static String getFileName(String fileFullName) { + if (fileFullName == null) { + return ""; + } + if (!fileFullName.contains(".")) { + return fileFullName; + } + + int index = fileFullName.lastIndexOf("."); + return fileFullName.substring(0, index); + } + + public static String getFileType(String fileFullName) { + if (fileFullName == null || !fileFullName.contains(".")) { + return ""; + } + int index = fileFullName.lastIndexOf("."); + return fileFullName.substring(index + 1); + } + + public static boolean isFileNameValid(String fileFullName) { + if (fileFullName.length() > 32) { + return false; + } + return pattern.matcher(fileFullName).matches(); + } + +} diff --git a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/util/ElectromagneticResultUtil.java b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/util/ElectromagneticResultUtil.java new file mode 100644 index 0000000..8004c77 --- /dev/null +++ b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/util/ElectromagneticResultUtil.java @@ -0,0 +1,31 @@ +package com.electromagnetic.industry.software.common.util; + +import com.electromagnetic.industry.software.common.enums.ErrorEnum; +import com.electromagnetic.industry.software.common.resp.ElectromagneticResult; + +public class ElectromagneticResultUtil { + + public static ElectromagneticResult success(T data){ + ElectromagneticResult electromagneticResult = new ElectromagneticResult<>(); + electromagneticResult.setSuccess(true); + electromagneticResult.setData(data); + return electromagneticResult; + } + + + public static ElectromagneticResult fail(String code , String msg){ + ElectromagneticResult electromagneticResult = new ElectromagneticResult<>(); + electromagneticResult.setSuccess(false); + electromagneticResult.setErrorCode(code); + electromagneticResult.setErrorMessage(msg); + return electromagneticResult; + } + + public static ElectromagneticResult fail(ErrorEnum errorEnum){ + ElectromagneticResult electromagneticResult = new ElectromagneticResult<>(); + electromagneticResult.setSuccess(false); + electromagneticResult.setErrorCode(errorEnum.getCode()); + electromagneticResult.setErrorMessage(errorEnum.getErrorMessage()); + return electromagneticResult; + } +} diff --git a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/util/IdWorker.java b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/util/IdWorker.java new file mode 100644 index 0000000..a0c0c63 --- /dev/null +++ b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/util/IdWorker.java @@ -0,0 +1,154 @@ +package com.electromagnetic.industry.software.common.util; + +import java.lang.management.ManagementFactory; +import java.net.InetAddress; +import java.net.NetworkInterface; + +public class IdWorker { + + private static IdWorker idWorker=new IdWorker(); + + // 时间起始标记点,作为基准,一般取系统的最近时间(一旦确定不能变动) + private final static long twepoch = 1288834974657L; + // 机器标识位数 + private final static long workerIdBits = 5L; + // 数据中心标识位数 + private final static long datacenterIdBits = 5L; + // 机器ID最大值 + private final static long maxWorkerId = -1L ^ (-1L << workerIdBits); + // 数据中心ID最大值 + private final static long maxDatacenterId = -1L ^ (-1L << datacenterIdBits); + // 毫秒内自增位 + private final static long sequenceBits = 12L; + // 机器ID偏左移12位 + private final static long workerIdShift = sequenceBits; + // 数据中心ID左移17位 + private final static long datacenterIdShift = sequenceBits + workerIdBits; + // 时间毫秒左移22位 + private final static long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits; + + private final static long sequenceMask = -1L ^ (-1L << sequenceBits); + /* 上次生产id时间戳 */ + private static long lastTimestamp = -1L; + // 0,并发控制 + private long sequence = 0L; + + private final long workerId; + // 数据标识id部分 + private final long datacenterId; + + public IdWorker(){ + this.datacenterId = getDatacenterId(maxDatacenterId); + this.workerId = getMaxWorkerId(datacenterId, maxWorkerId); + } + /** + * @param workerId + * 工作机器ID + * @param datacenterId + * 序列号 + */ + public IdWorker(long workerId, long datacenterId) { + if (workerId > maxWorkerId || workerId < 0) { + throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId)); + } + if (datacenterId > maxDatacenterId || datacenterId < 0) { + throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId)); + } + this.workerId = workerId; + this.datacenterId = datacenterId; + } + /** + * 获取下一个ID + * + * @return + */ + public synchronized long nextId() { + long timestamp = timeGen(); + if (timestamp < lastTimestamp) { + throw new RuntimeException(String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp)); + } + + if (lastTimestamp == timestamp) { + // 当前毫秒内,则+1 + sequence = (sequence + 1) & sequenceMask; + if (sequence == 0) { + // 当前毫秒内计数满了,则等待下一秒 + timestamp = tilNextMillis(lastTimestamp); + } + } else { + sequence = 0L; + } + lastTimestamp = timestamp; + // ID偏移组合生成最终的ID,并返回ID + long nextId = ((timestamp - twepoch) << timestampLeftShift) + | (datacenterId << datacenterIdShift) + | (workerId << workerIdShift) | sequence; + + return nextId; + } + + private long tilNextMillis(final long lastTimestamp) { + long timestamp = this.timeGen(); + while (timestamp <= lastTimestamp) { + timestamp = this.timeGen(); + } + return timestamp; + } + + private long timeGen() { + return System.currentTimeMillis(); + } + + /** + *

+ * 获取 maxWorkerId + *

+ */ + protected static long getMaxWorkerId(long datacenterId, long maxWorkerId) { + StringBuffer mpid = new StringBuffer(); + mpid.append(datacenterId); + String name = ManagementFactory.getRuntimeMXBean().getName(); + if (!name.isEmpty()) { + /* + * GET jvmPid + */ + mpid.append(name.split("@")[0]); + } + /* + * MAC + PID 的 hashcode 获取16个低位 + */ + return (mpid.toString().hashCode() & 0xffff) % (maxWorkerId + 1); + } + + /** + *

+ * 数据标识id部分 + *

+ */ + protected static long getDatacenterId(long maxDatacenterId) { + long id = 0L; + try { + InetAddress ip = InetAddress.getLocalHost(); + NetworkInterface network = NetworkInterface.getByInetAddress(ip); + if (network == null) { + id = 1L; + } else { + byte[] mac = network.getHardwareAddress(); + id = ((0x000000FF & (long) mac[mac.length - 1]) + | (0x0000FF00 & (((long) mac[mac.length - 2]) << 8))) >> 6; + id = id % (maxDatacenterId + 1); + } + } catch (Exception e) { + System.out.println(" getDatacenterId: " + e.getMessage()); + } + return id; + } + public static long getSnowFlakeId(){ + return idWorker.nextId(); + } + + public static String getSnowFlakeIdString(){ + return String.valueOf(getSnowFlakeId()); + } + +} diff --git a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/util/SignUtils.java b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/util/SignUtils.java new file mode 100644 index 0000000..1e9d137 --- /dev/null +++ b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/util/SignUtils.java @@ -0,0 +1,117 @@ +package com.electromagnetic.industry.software.common.util; + +import java.security.MessageDigest; +import java.util.Map; + +public class SignUtils { + + public static char[] hexDigits = + {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + + public static String md5(String string) { + try { + MessageDigest md5 = MessageDigest.getInstance("MD5"); + byte[] bytes = md5.digest(string.getBytes("utf-8")); + char[] chars = new char[bytes.length * 2]; + + for (int i = 0; i < bytes.length; ++i) { + int b = bytes[i]; + chars[i * 2] = hexDigits[(b & 240) >> 4]; + chars[i * 2 + 1] = hexDigits[b & 15]; + } + + return new String(chars); + } catch (Exception var6) { + var6.printStackTrace(); + return null; + } + } + + /** + * 获取MD5加密后的字符串 + * + * @param str 加密前的字符串 + * @return + */ + public static String MD5(String str) { + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + md.reset(); + md.update(str.getBytes("UTF-8")); + byte[] byteArray = md.digest(); + StringBuffer md5StrBuff = new StringBuffer(); + for (int i = 0; i < byteArray.length; i++) { + if (Integer.toHexString(0xFF & byteArray[i]).length() == 1) { + md5StrBuff.append("0").append(Integer.toHexString(0xFF & byteArray[i])); + } else { + md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i])); + } + } + return md5StrBuff.toString(); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public static Boolean equals(String v1, String v2) { + if (v1 == null && v2 == null) + { + return true; + } + if (v1 != null && v2 != null && v1.equals(v2)) + { + return true; + } + else + { + return false; + } + } + + public static String getString(Map params, String key, String defaultValue){ + String temp = null; + if(params.get(key)==null){ + return defaultValue; + } + + else if(params.get(key).getClass().isArray()) + { + temp = getArray(params,key)[0]; + } + else + { + temp = params.get(key).toString(); + } + if(temp != null){ + temp = temp.replaceAll("%", "\\%"); + } + if(temp==null) + { + return defaultValue; + } + return temp; + } + + public static String[] getArray(Map params, String key) { + return getArray(params, key, null); + } + + public static String[] getArray(Map params, String + key, String[] defaultValue) { + if (params == null) { + return defaultValue; + } + if (params.get(key) == null) { + return defaultValue; + } + try { + String[] values = (String[]) params.get(key); + return values; + } catch (ClassCastException e) { + return defaultValue; + + } + } + +} \ No newline at end of file diff --git a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/util/TokenUtil.java b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/util/TokenUtil.java new file mode 100644 index 0000000..d9a5ab4 --- /dev/null +++ b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/util/TokenUtil.java @@ -0,0 +1,22 @@ +package com.electromagnetic.industry.software.common.util; + +import com.electromagnetic.industry.software.common.cons.UserConstants; +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.Jwts; + +public class TokenUtil { + + /** + * 获取Claim + * + * @param token + * @return + */ + public static Claims getLoginInfo(String token) { + return Jwts.parser() + .setSigningKey(UserConstants.SECRET_KEY) + .parseClaimsJws(token) + .getBody(); + } + +} diff --git a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/util/UserThreadLocal.java b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/util/UserThreadLocal.java new file mode 100644 index 0000000..db9d0dd --- /dev/null +++ b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/util/UserThreadLocal.java @@ -0,0 +1,31 @@ +package com.electromagnetic.industry.software.common.util; + + +import com.electromagnetic.industry.software.common.pojo.UserLoginInfo; + +public class UserThreadLocal { + /** + * 存储用户信息 + */ + private static ThreadLocal userThread = new ThreadLocal<>(); + + public static void set(UserLoginInfo userLoginInfo) { + userThread.set(userLoginInfo); + } + + public static UserLoginInfo getUser() { + return userThread.get(); + } + + public static String getUsername() { + return userThread.get().getUsername(); + } + + public static String getUserId() { + return userThread.get().getUserId(); + } + + public static void remove() { + userThread.remove(); + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..5abb879 --- /dev/null +++ b/pom.xml @@ -0,0 +1,36 @@ + + + 4.0.0 + + com.electromagnetic.data + electromagnetic-data-new + 1.0-SNAPSHOT + pom + + electrmangnetic + electromagnetic-common + + + + 1.8 + 8 + 8 + UTF-8 + 2.6.3 + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring.boot.version} + pom + import + + + + + \ No newline at end of file