简单登录

This commit is contained in:
Raod 2021-06-24 13:58:52 +08:00
parent 18fb98fd37
commit 1a086a5259
42 changed files with 510 additions and 1298 deletions

View File

@ -0,0 +1,13 @@
----------------------------------------------------------------
Thu Jun 24 13:44:40 CST 2021:
Booting Derby version The Apache Software Foundation - Apache Derby - 10.14.2.0 - (1828579): instance a816c00e-017a-3c8c-7997-00000fdd7788
on database directory memory:D:\anji-code\gitee\aj-report\55b30257-1477-453c-b5b1-a9bbd7a931a7 with class loader sun.misc.Launcher$AppClassLoader@18b4aac2
Loaded from file:/C:/Users/raodeming/.m2/repository/org/apache/derby/derby/10.14.2.0/derby-10.14.2.0.jar
java.vendor=Oracle Corporation
java.runtime.version=1.8.0_191-b12
user.dir=D:\anji-code\gitee\aj-report
os.name=Windows 10
os.arch=amd64
os.version=10.0
derby.system.home=null
Database Class Loader started - derby.database.classpath=''

View File

@ -14,17 +14,13 @@
<dependencies>
<dependency>
<groupId>com.anjiplus.template.gaea</groupId>
<artifactId>template-gaea-common</artifactId>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.anji-plus</groupId>
<artifactId>spring-boot-gaea</artifactId>
<exclusions>
<!-- <exclusion>-->
<!-- <groupId>com.alibaba.cloud</groupId>-->
<!-- <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>-->
<!-- </exclusion>-->
<!-- <exclusion>-->
<!-- <groupId>com.alibaba.cloud</groupId>-->
<!-- <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>-->
<!-- </exclusion>-->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
@ -33,10 +29,32 @@
</dependency>
<dependency>
<groupId>com.anjiplus.template.gaea</groupId>
<artifactId>template-gaea-generator</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
</dependency>
<!--模板引擎-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.anjiplus.template.gaea</groupId>-->
<!-- <artifactId>template-gaea-generator</artifactId>-->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-data-redis</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- </dependency>-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
@ -64,15 +82,6 @@
<version>2.10.6</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.alibaba.cloud</groupId>-->
<!-- <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.alibaba.cloud</groupId>-->
<!-- <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>com.anji-plus</groupId>
<artifactId>spring-boot-starter-gaea-export</artifactId>

View File

@ -4,6 +4,7 @@ import com.anji.plus.gaea.annotation.enabled.EnabledGaeaConfiguration;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScans;
/**
* 业务模板
@ -11,7 +12,10 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* @since 2021-02-03
*/
@EnabledGaeaConfiguration
@SpringBootApplication
@SpringBootApplication(scanBasePackages = {
"com.anjiplus.template.gaea",
"com.anji.plus"
})
@MapperScan(basePackages = {
"com.anjiplus.template.gaea.business.modules.*.dao",
"com.anjiplus.template.gaea.business.modules.*.**.dao",

View File

@ -13,7 +13,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
public class ReportCacheHelper implements CacheHelper, ApplicationContextAware {
@ -24,7 +23,7 @@ public class ReportCacheHelper implements CacheHelper, ApplicationContextAware {
public String stringGet(String key) {
Cache.ValueWrapper valueWrapper = cache.get(key);
if (valueWrapper != null) {
return (String)valueWrapper.get();
return (String) valueWrapper.get();
}
return CacheHelper.super.stringGet(key);
}
@ -38,7 +37,15 @@ public class ReportCacheHelper implements CacheHelper, ApplicationContextAware {
@Override
public boolean exist(String key) {
return cache.get(key)!=null;
String cacheHoldTime = stringGet(key + "_HoldTime");
if (cacheHoldTime != null && Long.parseLong(cacheHoldTime) > 0) {
if (Long.parseLong(cacheHoldTime) < System.currentTimeMillis()) {
delete(key + "_HoldTime");
delete(key);
return false;
}
}
return cache.get(key) != null;
}
@ -47,10 +54,6 @@ public class ReportCacheHelper implements CacheHelper, ApplicationContextAware {
cache.put(key, value);
}
@Override
public void stringSetExpire(String key, String value, long time, TimeUnit timeUnit) {
CacheHelper.super.stringSetExpire(key, value, time, timeUnit);
}
@Override
public String regKey(String key) {
@ -59,7 +62,11 @@ public class ReportCacheHelper implements CacheHelper, ApplicationContextAware {
@Override
public void stringSetExpire(String key, String value, long seconds) {
CacheHelper.super.stringSetExpire(key, value, seconds);
stringSet(key, value);
if (seconds > 0) {
//缓存失效时间
stringSet(key + "_HoldTime", String.valueOf(System.currentTimeMillis() + seconds * 1000));
}
}
@Override
@ -122,7 +129,9 @@ public class ReportCacheHelper implements CacheHelper, ApplicationContextAware {
@Override
public boolean delete(String key) {
cache.evict(key);
if (exist(key)) {
cache.evict(key);
}
return true;
}
@ -136,6 +145,6 @@ public class ReportCacheHelper implements CacheHelper, ApplicationContextAware {
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
/*基于内存的本地缓存*/
cache = (Cache)applicationContext.getBean("ehCacheCache");
cache = (Cache) applicationContext.getBean("ehCacheCache");
}
}

View File

@ -6,6 +6,15 @@ package com.anjiplus.template.gaea.business.code;
* @since 2021-02-22
*/
public interface ResponseCode {
/**
* 用户名或者密码不正确
*/
String LOGIN_ERROR = "login.error";
/**
* 用户token过期
*/
String USER_TOKEN_EXPIRED = "User.token.expired";
/**
* 字典项重复
@ -98,4 +107,5 @@ public interface ResponseCode {
String SET_CODE_ISEXIST = "4008";
String SOURCE_CODE_ISEXIST = "4009";
String CLASS_NOT_FOUND = "4010";
}

View File

@ -30,7 +30,7 @@ public class BusinessAutoConfiguration {
return new ApplicationInitRunner();
}
@Bean("gaeaCacheHelper")
@Bean
public CacheHelper gaeaCacheHelper(){
return new ReportCacheHelper();
}

View File

@ -0,0 +1,75 @@
package com.anjiplus.template.gaea.business.filter;
import com.alibaba.fastjson.JSONObject;
import com.anji.plus.gaea.bean.ResponseBean;
import com.anji.plus.gaea.cache.CacheHelper;
import com.anji.plus.gaea.utils.JwtBean;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* 简单的鉴权
* Created by raodeming on 2021/6/24.
*/
@Component
public class TokenFilter implements Filter {
@Autowired
private CacheHelper cacheHelper;
@Autowired
private JwtBean jwtBean;
@Override
public void init(FilterConfig filterConfig) throws ServletException {
Filter.super.init(filterConfig);
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
String uri = request.getRequestURI();
if (!uri.startsWith("/login")) {
//获取token
String authorization = request.getHeader("Authorization");
if (StringUtils.isBlank(authorization)) {
error(response);
return;
}
String username = jwtBean.getUsername(authorization);
// String uuid = jwtBean.getUUID(authorization);
if (!cacheHelper.exist(username)) {
error(response);
return;
}
//延长有效期
cacheHelper.stringSetExpire(username, authorization, 3600);
}
//执行
filterChain.doFilter(request, response);
}
@Override
public void destroy() {
Filter.super.destroy();
}
private void error(HttpServletResponse response) throws IOException {
ResponseBean responseBean = ResponseBean.builder().code("500").message("The Token has expired").build();
response.getWriter().print(JSONObject.toJSONString(responseBean));
response.getOutputStream().flush();
}
}

View File

@ -1,74 +0,0 @@
package com.anjiplus.template.gaea.business.modules.export.controller;
import com.anji.plus.gaea.annotation.log.GaeaAuditLog;
import com.anji.plus.gaea.bean.ResponseBean;
import com.anji.plus.gaea.curd.controller.GaeaBaseController;
import com.anji.plus.gaea.curd.service.GaeaBaseService;
import com.anji.plus.gaea.utils.GaeaBeanUtils;
import com.anjiplus.template.gaea.business.modules.export.controller.dto.GaeaExportDTO;
import com.anjiplus.template.gaea.business.modules.export.controller.param.GaeaExportParam;
import com.anjiplus.template.gaea.business.modules.export.controller.param.GaeaExportQueryParam;
import com.anjiplus.template.gaea.business.modules.export.dao.entity.GaeaExport;
import com.anjiplus.template.gaea.business.modules.export.service.GaeaExportService;
import com.anji.plus.gaea.export.vo.ExportOperation;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.stream.Collectors;
/**
* 导出中心(GaeaExport)实体类
*
* @author makejava
* @since 2021-02-07 17:12:31
*/
@RestController
@RequestMapping("/export")
@Api(value = "/export", tags = "导出中心")
public class GaeaExportController extends GaeaBaseController<GaeaExportParam, GaeaExport, GaeaExportDTO> {
@Autowired
private GaeaExportService gaeaExportService;
@Override
public GaeaBaseService<GaeaExportParam, GaeaExport> getService() {
return gaeaExportService;
}
@Override
public GaeaExport getEntity() {
return new GaeaExport();
}
@Override
public GaeaExportDTO getDTO() {
return new GaeaExportDTO();
}
@PostMapping("/queryAdvanceExport")
@GaeaAuditLog(pageTitle = "高级查询")
public ResponseBean queryExportInfo(@RequestBody GaeaExportQueryParam param) {
Page<GaeaExport> exportList=gaeaExportService.getExportListPage(param);
List<GaeaExportDTO> list = exportList.getRecords().stream()
.map(entity -> GaeaBeanUtils.copyAndFormatter(entity, getDTO()))
.collect(Collectors.toList());
Page<GaeaExportDTO> pageDto = new Page<>();
pageDto.setCurrent(exportList.getCurrent());
pageDto.setRecords(list);
pageDto.setPages(exportList.getPages());
pageDto.setTotal(exportList.getTotal());
pageDto.setSize(exportList.getSize());
return responseSuccessWithData(pageDto);
}
@PostMapping("/saveExportLog")
public Boolean export(@RequestBody ExportOperation exportOperation) {
return gaeaExportService.saveExportLog(exportOperation);
}
}

View File

@ -1,144 +0,0 @@
package com.anjiplus.template.gaea.business.modules.export.controller.dto;
import com.anji.plus.gaea.curd.dto.GaeaBaseDTO;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.time.LocalDateTime;
import java.util.Date;
/**
* 导出中心(GaeaExport)实体类
*
* @author makejava
* @since 2021-02-07 17:12:25
*/
@ApiModel(value = "导出中心")
public class GaeaExportDTO extends GaeaBaseDTO {
/**
* 文件在t_file中的id前端传它来读流接口显示http://auth/file/download/fileId
*/
@ApiModelProperty(value = "文件在t_file中的id前端传它来读流接口显示http://auth/file/download/fileId")
private String fileId;
/**
* 文件标题比如:对账单报表6月份报表
*/
@ApiModelProperty(value = "文件标题,比如:对账单报表6月份报表")
private String fileTitle;
/**
* 导出前查询的数据开始时间
*/
@ApiModelProperty(value = "导出前,查询的数据开始时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private LocalDateTime resultStartTime;
/**
* 导出前查询的数据结束时间
*/
@ApiModelProperty(value = "导出前,查询的数据结束时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private LocalDateTime resultEndTime;
/**
* 导出查询结果数据总条数
*/
@ApiModelProperty(value = "导出查询结果,数据总条数")
private Long resultSize;
/**
* 文件导出触发时间
*/
@ApiModelProperty(value = "文件导出触发时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private LocalDateTime fileCreateTime;
/**
* 文件生成完成时间
*/
@ApiModelProperty(value = "文件生成完成时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private LocalDateTime fileFinishTime;
/**
* 文件状态creating生成中success生成成功,failed生成失败
*/
@ApiModelProperty(value = "文件状态creating生成中success生成成功,failed生成失败")
private String fileStatus;
/**
* 备注
*/
@ApiModelProperty(value = "备注")
private String remark;
public String getFileId() {
return fileId;
}
public void setFileId(String fileId) {
this.fileId = fileId;
}
public String getFileTitle() {
return fileTitle;
}
public void setFileTitle(String fileTitle) {
this.fileTitle = fileTitle;
}
public Long getResultSize() {
return resultSize;
}
public void setResultSize(Long resultSize) {
this.resultSize = resultSize;
}
public LocalDateTime getResultStartTime() {
return resultStartTime;
}
public void setResultStartTime(LocalDateTime resultStartTime) {
this.resultStartTime = resultStartTime;
}
public LocalDateTime getResultEndTime() {
return resultEndTime;
}
public void setResultEndTime(LocalDateTime resultEndTime) {
this.resultEndTime = resultEndTime;
}
public LocalDateTime getFileCreateTime() {
return fileCreateTime;
}
public void setFileCreateTime(LocalDateTime fileCreateTime) {
this.fileCreateTime = fileCreateTime;
}
public LocalDateTime getFileFinishTime() {
return fileFinishTime;
}
public void setFileFinishTime(LocalDateTime fileFinishTime) {
this.fileFinishTime = fileFinishTime;
}
public String getFileStatus() {
return fileStatus;
}
public void setFileStatus(String fileStatus) {
this.fileStatus = fileStatus;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
}

View File

@ -1,26 +0,0 @@
package com.anjiplus.template.gaea.business.modules.export.controller.param;
import com.anji.plus.gaea.annotation.Query;
import com.anji.plus.gaea.constant.QueryEnum;
import com.anji.plus.gaea.curd.params.PageParam;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
/**
* 导出中心(GaeaExport)param
*
* @author makejava
* @since 2021-02-07 17:12:26
*/
@Getter
@Setter
public class GaeaExportParam extends PageParam implements Serializable {
/**
* 文件标题
*/
@Query(QueryEnum.LIKE)
private String fileTitle;
}

View File

@ -1,23 +0,0 @@
package com.anjiplus.template.gaea.business.modules.export.controller.param;
import com.anjiplus.template.gaea.common.dto.BaseQueryBO;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
/**
* 功能描述
*
* @Author: peiyanni
* @Date: 2021/2/20 12:49
*/
@Setter
@Getter
public class GaeaExportQueryParam extends BaseQueryBO implements Serializable{
/**
* 文件标题
*/
private String fileTitle;
}

View File

@ -1,30 +0,0 @@
package com.anjiplus.template.gaea.business.modules.export.dao;
import com.anjiplus.template.gaea.business.modules.export.controller.param.GaeaExportQueryParam;
import com.anjiplus.template.gaea.business.modules.export.dao.entity.GaeaExport;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 导出中心(GaeaExport)Mapper
*
* @author makejava
* @since 2021-02-07 17:12:16
*/
@Mapper
public interface GaeaExportMapper extends GaeaBaseMapper<GaeaExport> {
/**
* 导出信息的高级查询
* @param page
* @param bo
* @param wrapper
* @return
*/
List<GaeaExport> queryExportInfo(Page<GaeaExport> page, @Param("bo") GaeaExportQueryParam bo, @Param(Constants.WRAPPER) QueryWrapper wrapper);
}

View File

@ -1,126 +0,0 @@
package com.anjiplus.template.gaea.business.modules.export.dao.entity;
import com.anji.plus.gaea.annotation.Formatter;
import com.baomidou.mybatisplus.annotation.TableName;
import com.anji.plus.gaea.curd.entity.GaeaBaseEntity;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* 导出中心(GaeaExport)实体类
*
* @author peiyanni
* @since 2021-02-07 17:12:14
*/
@TableName("gaea_export")
public class GaeaExport extends GaeaBaseEntity implements Serializable {
/**
* 文件在t_file中的id前端传它来读流接口显示http://auth/file/download/fileId
*/
private String fileId;
/**
* 文件标题比如:对账单报表6月份报表
*/
private String fileTitle;
/**
* 导出前查询的数据开始时间
*/
private LocalDateTime resultStartTime;
/**
* 导出前查询的数据结束时间
*/
private LocalDateTime resultEndTime;
/**
* 导出查询结果数据总条数
*/
private Long resultSize;
/** 文件导出触发时间 */
private LocalDateTime fileCreateTime;
/** 文件生成完成时间 */
private LocalDateTime fileFinishTime;
/**
* 文件状态creating生成中success生成成功,failed生成失败
*/
@Formatter(dictCode="FILE_STATUS",targetField = "fileStatus")
private String fileStatus;
/**
* 备注
*/
private String remark;
public String getFileId() {
return fileId;
}
public void setFileId(String fileId) {
this.fileId = fileId;
}
public String getFileTitle() {
return fileTitle;
}
public void setFileTitle(String fileTitle) {
this.fileTitle = fileTitle;
}
public LocalDateTime getResultStartTime() {
return resultStartTime;
}
public LocalDateTime getResultEndTime() {
return resultEndTime;
}
public LocalDateTime getFileFinishTime() {
return fileFinishTime;
}
public void setFileFinishTime(LocalDateTime fileFinishTime) {
this.fileFinishTime = fileFinishTime;
}
public Long getResultSize() {
return resultSize;
}
public void setResultSize(Long resultSize) {
this.resultSize = resultSize;
}
public void setResultStartTime(LocalDateTime resultStartTime) {
this.resultStartTime = resultStartTime;
}
public void setResultEndTime(LocalDateTime resultEndTime) {
this.resultEndTime = resultEndTime;
}
public LocalDateTime getFileCreateTime() {
return fileCreateTime;
}
public void setFileCreateTime(LocalDateTime fileCreateTime) {
this.fileCreateTime = fileCreateTime;
}
public String getFileStatus() {
return fileStatus;
}
public void setFileStatus(String fileStatus) {
this.fileStatus = fileStatus;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
}

View File

@ -1,32 +0,0 @@
package com.anjiplus.template.gaea.business.modules.export.service;
import com.anjiplus.template.gaea.business.modules.export.dao.entity.GaeaExport;
import com.anji.plus.gaea.export.vo.ExportOperation;
import com.anjiplus.template.gaea.business.modules.export.controller.param.GaeaExportParam;
import com.anjiplus.template.gaea.business.modules.export.controller.param.GaeaExportQueryParam;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.anji.plus.gaea.curd.service.GaeaBaseService;
/**
* 导出中心(GaeaExport)Service
*
* @author peiyanni
* @since 2021-02-07 17:12:22
*/
public interface GaeaExportService extends GaeaBaseService<GaeaExportParam, GaeaExport> {
/**
* 导出中心-高级查询
* 需要 QueryWrapper 类型的动态参数用来进行获取组装好的QueryWrapper对象
* @param queryParam
* @return
*/
Page<GaeaExport> getExportListPage(GaeaExportQueryParam queryParam, QueryWrapper ...qe);
/**
* 导出操作保存导出日志信息到表Gaea_export
* @param exportOperation
* @return
*/
Boolean saveExportLog(ExportOperation exportOperation);
}

View File

@ -1,73 +0,0 @@
package com.anjiplus.template.gaea.business.modules.export.service.impl;
import com.anjiplus.template.gaea.business.modules.export.dao.GaeaExportMapper;
import com.anjiplus.template.gaea.business.modules.export.dao.entity.GaeaExport;
import com.anjiplus.template.gaea.business.modules.export.service.GaeaExportService;
import com.anjiplus.template.gaea.business.modules.file.dao.GaeaFileMapper;
import com.anjiplus.template.gaea.business.modules.file.entity.GaeaFile;
import com.anji.plus.gaea.export.vo.ExportOperation;
import com.anjiplus.template.gaea.business.modules.export.controller.param.GaeaExportQueryParam;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.anjiplus.template.gaea.common.aop.GaeaQuery;
import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
/**
* 导出中心(GaeaExport)ServiceImpl
*
* @author makejava
* @since 2021-02-07 17:12:24
*/
@Service
public class GaeaExportServiceImpl implements GaeaExportService {
@Autowired
private GaeaExportMapper gaeaExportMapper;
@Autowired
private GaeaFileMapper gaeaFileMapper;
@Override
public GaeaBaseMapper<GaeaExport> getMapper() {
return gaeaExportMapper;
}
@Override
@GaeaQuery
public Page<GaeaExport> getExportListPage(GaeaExportQueryParam queryParam, QueryWrapper... qe) {
Page<GaeaExport> page = new Page<>(queryParam.getPageNumber(), queryParam.getPageSize());
QueryWrapper queryWrapper = (null != qe && qe.length > 0) ? qe[0] : null;
List<GaeaExport> gaeaExports = gaeaExportMapper.queryExportInfo(page, queryParam, queryWrapper);
page.setRecords(gaeaExports);
return page;
}
@Override
@Transactional
public Boolean saveExportLog(ExportOperation exportOperation) {
//需要保存两张表数据 gaea_file ,gaea_export数据
Date nowDate = new Date();
GaeaFile gaeaFile = new GaeaFile();
gaeaFile.setFileId(exportOperation.getFileId());
gaeaFile.setFilePath(exportOperation.getFilePath());
gaeaFile.setCreateBy(exportOperation.getCreaterUsername());
gaeaFile.setCreateTime(nowDate);
gaeaFile.setUpdateBy(exportOperation.getCreaterUsername());
gaeaFile.setUpdateTime(nowDate);
gaeaFileMapper.insert(gaeaFile);
GaeaExport export = new GaeaExport();
BeanUtils.copyProperties(exportOperation, export);
export.setCreateBy(exportOperation.getCreaterUsername());
export.setCreateTime(nowDate);
export.setUpdateBy(exportOperation.getCreaterUsername());
export.setUpdateTime(nowDate);
gaeaExportMapper.insert(export);
return true;
}
}

View File

@ -3,6 +3,7 @@ package com.anjiplus.template.gaea.business.modules.file.controller.dto;
import com.anji.plus.gaea.curd.dto.GaeaBaseDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* (GaeaFile)实体类
@ -10,58 +11,21 @@ import io.swagger.annotations.ApiModelProperty;
* @author peiyanni
* @since 2021-02-18 14:48:27
*/
@ApiModel(value = "")
@Data
public class GaeaFileDTO extends GaeaBaseDTO {
/**
* 文件uuid
*/
/** 文件标识 */
private String fileId;
/**
* 文件在linux中的完整目录比如/app/dist/export/excel/${fileid}.xlsx
*/
@ApiModelProperty(value = "文件在linux中的完整目录比如/app/dist/export/excel/${fileid}.xlsx")
/** 文件类型 */
private String fileType;
/** 文件路径 */
private String filePath;
/**
* 通过接口的下载完整http路径
*/
@ApiModelProperty(value = "通过接口的下载完整http路径")
/** url路径 */
private String urlPath;
/**
* 文件内容说明比如 对账单(202001~202012)
*/
@ApiModelProperty(value = "文件内容说明,比如 对账单(202001~202012)")
/** 内容说明 */
private String fileInstruction;
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
public String getUrlPath() {
return urlPath;
}
public void setUrlPath(String urlPath) {
this.urlPath = urlPath;
}
public String getFileInstruction() {
return fileInstruction;
}
public void setFileInstruction(String fileInstruction) {
this.fileInstruction = fileInstruction;
}
public String getFileId() {
return fileId;
}
public void setFileId(String fileId) {
this.fileId = fileId;
}
}

View File

@ -15,17 +15,11 @@ import java.io.Serializable;
*/
public class GaeaFileParam extends PageParam implements Serializable {
/**
* 文件在linux中的完整目录比如/app/dist/export/excel/${fileid}.xlsx
*/
@Query(QueryEnum.LIKE)
/** 模糊查询 */
@Query(value = QueryEnum.LIKE)
private String filePath;
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
/** 模糊查询 */
@Query(value = QueryEnum.EQ)
private String fileType;
}

View File

@ -2,6 +2,8 @@ package com.anjiplus.template.gaea.business.modules.file.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.anji.plus.gaea.curd.entity.GaeaBaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@ -12,54 +14,21 @@ import java.io.Serializable;
* @since 2021-02-18 14:48:20
*/
@TableName("gaea_file")
@Data
public class GaeaFile extends GaeaBaseEntity implements Serializable {
/**
* 文件uuid
*/
@ApiModelProperty(value = "文件标识")
private String fileId;
/**
* 文件在linux中的完整目录比如/app/dist/export/excel/${fileid}.xlsx
*/
@ApiModelProperty(value = "文件类型")
private String fileType;
@ApiModelProperty(value = "文件路径")
private String filePath;
/**
* 通过接口的下载完整http路径
*/
@ApiModelProperty(value = "url路径")
private String urlPath;
/**
* 文件内容说明比如 对账单(202001~202012)
*/
@ApiModelProperty(value = "内容说明")
private String fileInstruction;
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
public String getUrlPath() {
return urlPath;
}
public void setUrlPath(String urlPath) {
this.urlPath = urlPath;
}
public String getFileInstruction() {
return fileInstruction;
}
public void setFileInstruction(String fileInstruction) {
this.fileInstruction = fileInstruction;
}
public String getFileId() {
return fileId;
}
public void setFileId(String fileId) {
this.fileId = fileId;
}
}

View File

@ -24,7 +24,7 @@ public interface GaeaFileService extends GaeaBaseService<GaeaFileParam, GaeaFile
* @param file
* @return 文件访问路径
*/
String upload(MultipartFile file);
GaeaFile upload(MultipartFile file);
/**
* 根据fileId显示图片或者下载文件

View File

@ -1,20 +1,18 @@
package com.anjiplus.template.gaea.business.modules.file.service.impl;
import com.alibaba.excel.util.FileUtils;
import com.anji.plus.gaea.constant.BaseOperationEnum;
import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper;
import com.anji.plus.gaea.exception.BusinessException;
import com.anji.plus.gaea.exception.BusinessExceptionBuilder;
import com.anjiplus.template.gaea.business.modules.file.util.StringPatternUtil;
import com.anjiplus.template.gaea.business.code.ResponseCode;
import com.anjiplus.template.gaea.business.modules.file.dao.GaeaFileMapper;
import com.anjiplus.template.gaea.business.modules.file.entity.GaeaFile;
import com.anjiplus.template.gaea.business.modules.file.service.GaeaFileService;
import com.anjiplus.template.gaea.business.modules.export.dao.GaeaExportMapper;
import com.anjiplus.template.gaea.business.modules.export.dao.entity.GaeaExport;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.anjiplus.template.gaea.business.code.ResponseCode;
import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper;
import com.anji.plus.gaea.exception.BusinessExceptionBuilder;
import com.anjiplus.template.gaea.common.util.StringPatternUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@ -60,8 +58,6 @@ public class GaeaFileServiceImpl implements GaeaFileService {
@Autowired
private GaeaFileMapper gaeaFileMapper;
@Autowired
private GaeaExportMapper gaeaExportMapper;
@Override
public GaeaBaseMapper<GaeaFile> getMapper() {
@ -70,15 +66,17 @@ public class GaeaFileServiceImpl implements GaeaFileService {
@Override
@Transactional(rollbackFor = Exception.class)
public String upload(MultipartFile file) {
public GaeaFile upload(MultipartFile file) {
try {
String fileName = file.getOriginalFilename();
if (StringUtils.isBlank(fileName)) {
throw BusinessExceptionBuilder.build(ResponseCode.FILE_EMPTY_FILENAME);
}
String suffixName = fileName.substring(fileName.lastIndexOf("."));
String fileInstruction = fileName.substring(0, fileName.lastIndexOf("."));
//白名单校验(不区分大小写)
List<String> list = new ArrayList<String>(Arrays.asList(whiteList.split("\\|")));
List<String> list = new ArrayList<>(Arrays.asList(whiteList.split("\\|")));
list.addAll(list.stream().map(String::toUpperCase).collect(Collectors.toList()));
if (!list.contains(suffixName)) {
throw BusinessExceptionBuilder.build(ResponseCode.FILE_SUFFIX_UNSUPPORTED);
@ -88,19 +86,25 @@ public class GaeaFileServiceImpl implements GaeaFileService {
String newFileName = fileId + suffixName;
// 本地文件保存路径
String filePath = dictPath + newFileName;
String urlPath = fileDownloadPath + File.separator + fileId;
String urlPath = fileDownloadPath + java.io.File.separator + fileId;
GaeaFile gaeaFile = new GaeaFile();
gaeaFile.setFilePath(filePath);
gaeaFile.setFileId(fileId);
gaeaFile.setUrlPath(urlPath);
gaeaFile.setFileType(suffixName.replace(".", ""));
gaeaFile.setFileInstruction(fileInstruction);
gaeaFileMapper.insert(gaeaFile);
//写文件 将文件保存/app/dictPath/upload/
File dest = new File(dictPath + newFileName);
java.io.File dest = new java.io.File(dictPath + newFileName);
java.io.File parentFile = dest.getParentFile();
if (!parentFile.exists()) {
parentFile.mkdirs();
}
file.transferTo(dest);
// 将完整的http访问路径返回
return urlPath;
return gaeaFile;
} catch (Exception e) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
log.error("file upload error: {}", e);
@ -127,16 +131,7 @@ public class GaeaFileServiceImpl implements GaeaFileService {
}
String filename = filePath.substring(filePath.lastIndexOf(File.separator));
String fileSuffix = filename.substring(filename.lastIndexOf("."));
//特殊处理如果是excel文件则从t_export表中查询文件名
List list = Arrays.asList(excelSuffix.split("\\|"));
if (list.contains(fileSuffix)) {
LambdaQueryWrapper<GaeaExport> exportWrapper = Wrappers.lambdaQuery();
exportWrapper.eq(GaeaExport::getFileId, fileId);
GaeaExport exportPO = gaeaExportMapper.selectOne(exportWrapper);
if (null != exportPO) {
filename = exportPO.getFileTitle() + fileSuffix;
}
}
//根据文件后缀来判断是显示图片\视频\音频还是下载文件
File file = new File(filePath);
ResponseEntity.BodyBuilder builder = ResponseEntity.ok();

View File

@ -0,0 +1,98 @@
package com.anjiplus.template.gaea.business.modules.file.util;
import org.apache.commons.lang3.StringUtils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class StringPatternUtil {
/**
*
* <p>Discription:[查找源sourceStr中是否包含pattern返回boolean]</p>
* @author
* @update:[日期YYYY-MM-DD] [更改人姓名]
* @param sourceStr
* @param pattern
* @return
*/
public static boolean StringMatch(String sourceStr,String pattern){
boolean result=false;
try{
if(StringUtils.isBlank(sourceStr)|| StringUtils.isBlank(pattern)){
return result;
}
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(sourceStr);
while (m.find()) {
//String aa=m.group(0);
result=true;
break ;
}
}catch(Exception e){
result=false;
}
return result;
}
public static boolean StringMatchIgnoreCase(String sourceStr,String pattern){
boolean result=false;
try{
if(StringUtils.isBlank(sourceStr)|| StringUtils.isBlank(pattern)){
return result;
}
sourceStr=sourceStr.toLowerCase();
pattern=pattern.toLowerCase();
result=StringMatch(sourceStr,pattern);
}catch(Exception e){
result=false;
}
return result;
}
/**
* <p>Discription:[查找源sourceStr中是否包含pattern返回找到的字符串未找到就返回空字符串]</p>
* @author
* @update:[日期YYYY-MM-DD] [更改人姓名]
* @param sourceStr
* @param pattern
* @return
*/
public static String StringFind(String sourceStr,String pattern){
String result="";
try{
if(StringUtils.isBlank(sourceStr)|| StringUtils.isBlank(pattern)){
return result;
}
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(sourceStr);
while (m.find()) {
result = m.group(0);
break;
}
}catch(Exception e){
result="";
}
return result;
}
public static String replace(String sourceStr, String pattern, String replaceStr){
String result="";
try{
if(StringUtils.isBlank(sourceStr)|| StringUtils.isBlank(pattern)){
return result;
}
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(sourceStr);
result = m.replaceAll(replaceStr);
}catch(Exception e){
result="";
}
return result;
}
}

View File

@ -1,100 +0,0 @@
package com.anjiplus.template.gaea.business.modules.gaeaUiI18n.controller;
import com.anji.plus.gaea.annotation.AccessKey;
import com.anji.plus.gaea.bean.ResponseBean;
import com.anji.plus.gaea.curd.service.GaeaBaseService;
import com.anji.plus.gaea.utils.GaeaBeanUtils;
import com.anji.plus.gaea.utils.GaeaUtils;
import com.anjiplus.template.gaea.business.base.BaseController;
import com.anjiplus.template.gaea.business.modules.gaeaUiI18n.controller.dto.GaeaUiI18nDto;
import com.anjiplus.template.gaea.business.modules.gaeaUiI18n.controller.param.GaeaUiI18nParam;
import com.anjiplus.template.gaea.business.modules.gaeaUiI18n.dao.entity.GaeaUiI18n;
import com.anjiplus.template.gaea.business.modules.gaeaUiI18n.service.GaeaUiI18nService;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @desc ui文字国际化处理 controller
* @website https://gitee.com/anji-plus/gaea
* @author 王斌
* @date 2021-03-25 15:30:59.286
**/
@RestController
@Api(tags = "ui文字国际化处理管理")
@RequestMapping("/gaeaUiI18n")
public class GaeaUiI18nController extends BaseController<GaeaUiI18nParam, GaeaUiI18n, GaeaUiI18nDto> {
@Autowired
private GaeaUiI18nService gaeaUiI18nService;
@Override
public GaeaBaseService<GaeaUiI18nParam, GaeaUiI18n> getService() {
return gaeaUiI18nService;
}
@Override
public GaeaUiI18n getEntity() {
return new GaeaUiI18n();
}
@Override
public GaeaUiI18nDto getDTO() {
return new GaeaUiI18nDto();
}
@GetMapping({"/{id}"})
@AccessKey
@Override
public ResponseBean detail(@PathVariable("id") Long id) {
this.logger.info("{}根据ID查询服务开始id为{}", this.getClass().getSimpleName(), id);
GaeaUiI18n result = gaeaUiI18nService.getDetail(id);
GaeaUiI18nDto dto = this.getDTO();
GaeaBeanUtils.copyAndFormatter(result, dto);
ResponseBean responseBean = this.responseSuccessWithData(this.resultDtoHandle(dto));
this.logger.info("{}根据ID查询结束结果{}", this.getClass().getSimpleName(), GaeaUtils.toJSONString(responseBean));
return responseBean;
}
@PostMapping(value = "/scan")
public ResponseBean scan(@RequestParam String table){
gaeaUiI18nService.scan(table);
return responseSuccess();
}
@GetMapping(value = "/getTables")
public ResponseBean getTables(){
List<String> t = gaeaUiI18nService.getUi18nTables();
return responseSuccessWithData(t);
}
@PostMapping(value = "/listI18nFields")
public ResponseBean getI18nFields(@RequestBody GaeaUiI18nDto q){
GaeaUiI18n qry = new GaeaUiI18n();
GaeaBeanUtils.copyAndFormatter(q,qry);
// 客户端测试时以前端参数为准
if(StringUtils.isEmpty(qry.getLocale())) {
qry.setLocale(getI18nLang());
}
Map ret = new HashMap();
for(String table : q.getRefer().split(",")) {
qry.setRefer(table);
Map t = gaeaUiI18nService.getI18nFields(qry);
ret.putIfAbsent(qry.getModule(),new HashMap<>());
// 合并module子节点
((Map)ret.get(qry.getModule())).putAll((Map)t.get(qry.getModule()));
}
ret.put("locale",q.getLocale());
return responseSuccessWithData(ret);
}
}

View File

@ -1,50 +0,0 @@
package com.anjiplus.template.gaea.business.modules.gaeaUiI18n.controller.dto;
import java.io.Serializable;
import com.anji.plus.gaea.curd.dto.GaeaBaseDTO;
import com.anji.plus.gaea.annotation.Formatter;
import lombok.Data;
import java.sql.Timestamp;
/**
*
* @description ui文字国际化处理 dto
* @author 王斌
* @date 2021-03-25 15:30:59.286
**/
@Data
public class GaeaUiI18nDto extends GaeaBaseDTO implements Serializable {
/** 语言标识 */
@Formatter(dictCode = "LOCALE",targetField = "localeCn")
private String locale;
private String localeCn;
/** 行业标识 */
@Formatter(dictCode = "SYS_CATA_TYPE",targetField = "cataTypeCn")
private String cataType;
private String cataTypeCn;
/** 所属系统 */
private String system;
/** 所属菜单编号 */
private String module;
/** 字段编码 */
private String code;
/** 字段名称 */
private String name;
/** 业务描述 */
private String remark;
private String refer;
/** 启用状态 */
@Formatter(dictCode = "ENABLE_FLAG",targetField = "enabledCn")
private Integer enabled;
private String enabledCn;
}

View File

@ -1,54 +0,0 @@
/**/
package com.anjiplus.template.gaea.business.modules.gaeaUiI18n.controller.param;
import lombok.Data;
import java.io.Serializable;
import com.anji.plus.gaea.annotation.Query;
import com.anji.plus.gaea.constant.QueryEnum;
import com.anji.plus.gaea.curd.params.PageParam;
import java.util.List;
/**
* @desc GaeaUiI18n ui文字国际化处理查询输入类
* @author 王斌
* @date 2021-03-25 15:30:59.286
**/
@Data
public class GaeaUiI18nParam extends PageParam implements Serializable{
/** 精确查询 */
@Query
private String locale;
/** 精确查询 */
@Query
private String cataType;
/** 精确查询 */
@Query
private String system;
/** 模糊查询 */
@Query(value = QueryEnum.LIKE)
private String code;
/** 模糊查询 */
@Query(value = QueryEnum.LIKE)
private String name;
/** 模糊查询 */
@Query(value = QueryEnum.LIKE)
private String remark;
@Query(value = QueryEnum.EQ)
private String refer;
@Query(value = QueryEnum.EQ)
private String module;
/** 精确查询 */
@Query
private Integer enabled;
}

View File

@ -1,33 +0,0 @@
package com.anjiplus.template.gaea.business.modules.gaeaUiI18n.dao;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper;
import com.anjiplus.template.gaea.business.modules.gaeaUiI18n.dao.entity.GaeaUiI18n;
import com.anjiplus.template.gaea.business.modules.gaeaUiI18n.service.impl.ColumnDesc;
/**
* GaeaUiI18n Mapper
* @author 王斌
* @date 2021-03-25 15:30:59.286
**/
@Mapper
public interface GaeaUiI18nMapper extends GaeaBaseMapper<GaeaUiI18n> {
/**
* 查询表的定义字段中文描述等信息
* @param tableName
* @return
*/
List<ColumnDesc> queryColumns(@Param(value = "tableName") String tableName);
/**
* 查询项目所有的表名
* @param s
* @return
*/
List<String> queryTables(@Param(value = "tableName") String s);
}

View File

@ -1,46 +0,0 @@
package com.anjiplus.template.gaea.business.modules.gaeaUiI18n.dao.entity;
import lombok.Data;
import io.swagger.annotations.ApiModelProperty;
import com.anji.plus.gaea.curd.entity.GaeaBaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
/**
* @description ui文字国际化处理 entity
* @author 王斌
* @date 2021-03-25 15:30:59.286
**/
@TableName(value="gaea_ui_i18n")
@Data
public class GaeaUiI18n extends GaeaBaseEntity {
@ApiModelProperty(value = "语言标识")
private String locale;
@ApiModelProperty(value = "行业标识")
private String cataType;
@ApiModelProperty(value = "所属系统")
private String system;
@ApiModelProperty(value = "所属模块")
private String module;
@ApiModelProperty(value = "字段编码")
private String code;
@ApiModelProperty(value = "字段名称")
private String name;
@ApiModelProperty(value = "业务描述")
private String remark;
@ApiModelProperty(value = "关联表名")
private String refer;
@ApiModelProperty(value = "启用状态")
private Integer enabled;
}

View File

@ -1,46 +0,0 @@
package com.anjiplus.template.gaea.business.modules.gaeaUiI18n.service;
import com.anjiplus.template.gaea.business.base.BaseService;
import com.anjiplus.template.gaea.business.modules.gaeaUiI18n.dao.entity.GaeaUiI18n;
import com.anjiplus.template.gaea.business.modules.gaeaUiI18n.controller.param.GaeaUiI18nParam;
import java.util.List;
import java.util.Map;
/**
* @desc GaeaUiI18n ui文字国际化处理服务接口
* @author 王斌
* @date 2021-03-25 15:30:59.286
**/
public interface GaeaUiI18nService extends BaseService<GaeaUiI18nParam, GaeaUiI18n> {
/***
* 查询详情
*
* @param id
* @return
*/
GaeaUiI18n getDetail(Long id);
/**
* 新加功能菜单时i18n同步初始化,以单表为单位处理
* 优先从 自动生成处理表查询没有则从源表查询减少重复维护
*
* @param table 表名称
*/
void scan(String table);
/**
* 查询项目所有的表
* @return
*/
List<String> getUi18nTables();
/**
* 菜单初始化时查询该菜单需要的国际化列表
* @param initQry
* @return map
*/
Map getI18nFields(GaeaUiI18n initQry);
}

View File

@ -1,11 +0,0 @@
package com.anjiplus.template.gaea.business.modules.gaeaUiI18n.service.impl;
import com.anjiplus.template.gaea.generator.domain.Column;
/**
* @author WongBin
* @date 2021/3/26
*/
public class ColumnDesc extends Column {
}

View File

@ -1,162 +0,0 @@
package com.anjiplus.template.gaea.business.modules.gaeaUiI18n.service.impl;
import cn.hutool.core.util.StrUtil;
import com.anji.plus.gaea.constant.BaseOperationEnum;
import com.anji.plus.gaea.constant.Enabled;
import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper;
import com.anji.plus.gaea.exception.BusinessException;
import com.anjiplus.template.gaea.generator.domain.Column;
import com.anjiplus.template.gaea.generator.service.GeneratorService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import com.anjiplus.template.gaea.business.modules.gaeaUiI18n.dao.entity.GaeaUiI18n;
import com.anjiplus.template.gaea.business.modules.gaeaUiI18n.service.GaeaUiI18nService;
import com.anjiplus.template.gaea.business.modules.gaeaUiI18n.dao.GaeaUiI18nMapper;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* @desc GaeaUiI18n ui文字国际化处理服务实现
* @author 王斌
* @date 2021-03-25 15:30:59.286
**/
@Service
@Slf4j
public class GaeaUiI18nServiceImpl implements GaeaUiI18nService {
@Autowired
private GaeaUiI18nMapper gaeaUiI18nMapper;
@Override
public GaeaBaseMapper<GaeaUiI18n> getMapper() {
return gaeaUiI18nMapper;
}
@Override
public GaeaUiI18n getDetail(Long id) {
GaeaUiI18n gaeaUiI18n = this.selectOne(id);
return gaeaUiI18n;
}
@Autowired(required = false)
GeneratorService generatorService;
@Value("${spring.application.name}")
private String applicationName;
@Override
public void processBeforeOperation(GaeaUiI18n entity,
BaseOperationEnum type) throws BusinessException {
if(BaseOperationEnum.INSERT.equals(type)){
entity.setSystem(applicationName);
//entity.setCataType("");
}
}
@Override
public void scan(String table) {
assert table!=null;
LambdaQueryWrapper<GaeaUiI18n> wrapper = Wrappers.lambdaQuery();
wrapper.eq(GaeaUiI18n::getRefer,table);
if(gaeaUiI18nMapper.selectCount(wrapper) > 0){
log.warn("{} exist,ignore",table);
throw new BusinessException("6001",new String[]{"该表的字段已维护国际化配置"});
}
List<Column> columnDescList = generatorService.getColumns(table);
//List<ColumnDesc> columnDescList = gaeaUiI18nMapper.queryColumns(table);
if(!CollectionUtils.isEmpty(columnDescList)){
List<GaeaUiI18n> list = columnDescList.stream().map(item->{
if(item.getRemark()!=null && item.getRemark().length()>20){
item.setRemark(item.getRemark().substring(0,20));
}
GaeaUiI18n it = new GaeaUiI18n();
it.setCode(StrUtil.toCamelCase(item.getColumnName()));
it.setName(item.getRemark());
it.setLocale(getI18nLang());
it.setSystem(applicationName);
it.setRemark(item.getRemark());
it.setEnabled(Enabled.YES.getValue());
it.setRefer(item.getTableName());
return it;
}).collect(Collectors.toList());
int ret = gaeaUiI18nMapper.insertBatch(list);
log.info("insert-batch-for:{},size:{}",table,ret);
}
}
private String getI18nLang(){
return LocaleContextHolder.getLocale().getLanguage();
}
@Override
public List<String> getUi18nTables() {
return gaeaUiI18nMapper.queryTables("");
}
@Override
public Map getI18nFields(GaeaUiI18n q) {
String table = q.getRefer();
String tableAlias = "";
// 提取表名称和别名
if(q.getRefer().contains(":")) {
table = q.getRefer().split(":")[0];
tableAlias = Optional.ofNullable(q.getRefer().substring(table.length() + 1)).orElse("");
q.setRefer(table);
}
LambdaQueryWrapper<GaeaUiI18n> qry = Wrappers.lambdaQuery();
qry.eq(GaeaUiI18n::getLocale,q.getLocale())
.and(t->t.eq(GaeaUiI18n::getEnabled,Enabled.YES.getValue()))
// 所属行业
.and(t->t.eq(GaeaUiI18n::getCataType,q.getCataType()).or().isNull(GaeaUiI18n::getCataType))
// 同一个表 或同一个菜单
.and(t->t.eq(GaeaUiI18n::getRefer,q.getRefer()).or().eq(GaeaUiI18n::getModule,q.getModule()))
;
List<GaeaUiI18n> list = gaeaUiI18nMapper.selectList(qry);
HashMap kv = new HashMap();
// 表级别 字段默认设置
list.stream().filter(i->i.getRefer()!=null && i.getCataType()==null).forEach(i->{
kv.put(i.getCode(),i.getName());
});
// 表级别 字段行业属性,覆盖默认设置
list.stream().filter(i->i.getRefer()!=null && i.getCataType()!=null).forEach(i->{
kv.put(i.getCode(),i.getName());
});
Map result = new HashMap();
// 挂载在module根节点
if(tableAlias.length()<1) {
result.put(q.getModule(), kv);
}else {
// 作为module的子节点
result.putIfAbsent(q.getModule(),new HashMap<>());
((Map)result.get(q.getModule())).put(tableAlias,kv);
}
// 设置模块级别的字段配置
HashMap m = new HashMap();
list.stream().filter(i->i.getRefer()==null && i.getModule().equals(q.getModule())).forEach(item->{
m.put(item.getCode(),item.getName());
});
if(!m.isEmpty()) {
((Map)result.get(q.getModule())).putAll(m);
}
return result;
}
}

View File

@ -49,7 +49,7 @@ public class ReportExcelServiceImpl implements ReportExcelService {
@Autowired
private ReportMapper reportMapper;
@Value("${file.dist-path}")
@Value("${file.dist-path:''}")
private String dictPath;
@Autowired

View File

@ -0,0 +1,34 @@
package com.anjiplus.template.gaea.business.modules.user.controller;
import com.anji.plus.gaea.bean.ResponseBean;
import com.anjiplus.template.gaea.business.modules.user.dto.GaeaUserDTO;
import com.anjiplus.template.gaea.business.modules.user.service.UserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
/**
* 简单登录
* Created by raodeming on 2021/6/23.
*/
@RestController
@Api(tags = "用户管理")
public class LoginController {
@Autowired
private UserService userService;
/**
* 简单实现登录
* @param dto
* @return
*/
@PostMapping({"/login"})
public ResponseBean login(@RequestBody @Validated GaeaUserDTO dto) {
return ResponseBean.builder().data(userService.login(dto)).build();
}
}

View File

@ -0,0 +1,12 @@
package com.anjiplus.template.gaea.business.modules.user.dao;
import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper;
import com.anjiplus.template.gaea.business.modules.user.dao.entity.GaeaUser;
import org.apache.ibatis.annotations.Mapper;
/**
* Created by raodeming on 2021/6/23.
*/
@Mapper
public interface GaeaUserMapper extends GaeaBaseMapper<GaeaUser> {
}

View File

@ -0,0 +1,23 @@
package com.anjiplus.template.gaea.business.modules.user.dao.entity;
import com.anji.plus.gaea.annotation.Unique;
import com.anji.plus.gaea.curd.entity.GaeaBaseEntity;
import lombok.Data;
import java.io.Serializable;
/**
* Created by raodeming on 2021/6/23.
*/
@Data
public class GaeaUser extends GaeaBaseEntity implements Serializable {
/**
* 用户名
*/
private String username;
/**
* 密码
*/
private String password;
}

View File

@ -0,0 +1,23 @@
package com.anjiplus.template.gaea.business.modules.user.dto;
import com.anji.plus.gaea.annotation.Unique;
import com.anji.plus.gaea.curd.dto.GaeaBaseDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
@ApiModel(value = "用户表")
@Data
public class GaeaUserDTO extends GaeaBaseDTO {
@ApiModelProperty(value = "用户登录名")
@NotBlank
private String username;
@ApiModelProperty(value = "用户密码")
@NotBlank
private String password;
}

View File

@ -0,0 +1,10 @@
package com.anjiplus.template.gaea.business.modules.user.service;
import com.anjiplus.template.gaea.business.modules.user.dto.GaeaUserDTO;
/**
* Created by raodeming on 2021/6/23.
*/
public interface UserService {
Object login(GaeaUserDTO dto);
}

View File

@ -0,0 +1,86 @@
package com.anjiplus.template.gaea.business.modules.user.service.impl;
import com.anji.plus.gaea.cache.CacheHelper;
import com.anji.plus.gaea.exception.BusinessExceptionBuilder;
import com.anji.plus.gaea.utils.GaeaUtils;
import com.anji.plus.gaea.utils.JwtBean;
import com.anjiplus.template.gaea.business.code.ResponseCode;
import com.anjiplus.template.gaea.business.modules.user.dao.GaeaUserMapper;
import com.anjiplus.template.gaea.business.modules.user.dao.entity.GaeaUser;
import com.anjiplus.template.gaea.business.modules.user.dto.GaeaUserDTO;
import com.anjiplus.template.gaea.business.modules.user.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.security.MessageDigest;
import java.util.HashMap;
import java.util.Map;
/**
* Created by raodeming on 2021/6/23.
*/
@Service
public class UserServiceImpl implements UserService {
@Autowired
private JwtBean jwtBean;
@Autowired
private GaeaUserMapper gaeaUserMapper;
@Autowired
private CacheHelper cacheHelper;
@Override
public Object login(GaeaUserDTO dto) {
String username = dto.getUsername();
String password = dto.getPassword();
//1.判断用户是否存在
LambdaQueryWrapper<GaeaUser> wrapper = Wrappers.lambdaQuery();
wrapper.eq(GaeaUser::getUsername, username);
GaeaUser gaeaUser = gaeaUserMapper.selectOne(wrapper);
if (null == gaeaUser || !gaeaUser.getPassword().equals(encrypt(password))) {
throw BusinessExceptionBuilder.build(ResponseCode.LOGIN_ERROR);
}
Map<String, String> map = Maps.newHashMap();
//将登录信息缓存,默认一小时
if (cacheHelper.exist(username)) {
map.put("token", cacheHelper.stringGet(username));
} else {
String uuid = GaeaUtils.UUID();
String token = jwtBean.createToken(username, uuid);
cacheHelper.stringSetExpire(username, token, 3600);
map.put("token", token);
}
return map;
}
/**
* 获取指定字符串的md5值
* @param dataStr 明文
* @return String
*/
public static String encrypt(String dataStr) {
try {
MessageDigest m = MessageDigest.getInstance("MD5");
m.update(dataStr.getBytes("UTF8"));
byte[] s = m.digest();
StringBuilder result = new StringBuilder();
for (int i = 0; i < s.length; i++) {
result.append(Integer.toHexString((0x000000FF & s[i]) | 0xFFFFFF00).substring(6));
}
return result.toString();
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
}

View File

@ -1,16 +1,16 @@
spring:
application:
name: gaea-business
cloud:
nacos:
server-addr: 10.108.26.121:8848,10.108.26.145:8848
username: gaea
password: p@ss1234
# cloud:
# nacos:
# server-addr: 10.108.26.121:8848,10.108.26.145:8848
# username: gaea
# password: p@ss1234
# config:
# namespace: 5c6b6687-ad43-450f-88b6-e704ff78d83f
# file-extension: yaml
discovery:
namespace: 5c6b6687-ad43-450f-88b6-e704ff78d83f
# discovery:
# namespace: 5c6b6687-ad43-450f-88b6-e704ff78d83f
jackson:
date-format: yyyy-MM-dd HH:mm:ss
messages:
@ -39,6 +39,11 @@ generator:
templatePath: template
server:
port: 9092
servlet:
encoding:
charset: UTF-8
force: true
enabled: true
# servlet:
# context-path: /business
mybatis-plus:

View File

@ -6,4 +6,4 @@ logging:
config: classpath:logback.xml
generator:
tableExclude:
mysql: "AND table_name not like 'gaea_%' AND table_name not like 'ACT_%'"
mysql: "AND table_name not like 'gaea_%' AND table_name not like 'ACT_%'"

View File

@ -6,6 +6,9 @@
2003=File upload failed
2004=File does not exist
login.error=username or password error
User.token.expired=User token has expired
3001=Template code does not allow duplication
3002=The receiver is not allowed to be empty
Insert.failure=Insert failure

View File

@ -6,6 +6,10 @@
2003=\u6587\u4EF6\u4E0A\u4F20\u5931\u8D25
2004=\u6587\u4EF6\u4E0D\u5B58\u5728
login.error=\u7528\u6237\u540D\u6216\u8005\u5BC6\u7801\u4E0D\u6B63\u786E
User.token.expired=\u7528\u6237\u672A\u767B\u5F55\u6216\u767B\u5F55\u4FE1\u606F\u8FC7\u671F
3001=\u6A21\u677F\u4EE3\u7801\u4E0D\u5141\u8BB8\u91CD\u590D
3002=\u63A5\u6536\u4EBA\u4E0D\u5141\u8BB8\u4E3A\u7A7A
Dict.item.code.exist=\u6570\u636E\u5B57\u5178\u9879\u503C\u5DF2\u5B58\u5728

View File

@ -1,48 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.anjiplus.template.gaea.business.modules.export.dao.GaeaExportMapper">
<resultMap type="com.anjiplus.template.gaea.business.modules.export.dao.entity.GaeaExport" id="GaeaExportMap">
<result property="id" column="id" jdbcType="INTEGER"/>
<result property="fileId" column="file_id" jdbcType="VARCHAR"/>
<result property="fileTitle" column="file_title" jdbcType="VARCHAR"/>
<result property="resultStartTime" column="result_start_time" jdbcType="TIMESTAMP"/>
<result property="resultEndTime" column="result_end_time" jdbcType="TIMESTAMP"/>
<result property="resultSize" column="result_size" jdbcType="INTEGER"/>
<result property="fileCreateTime" column="file_create_time" jdbcType="TIMESTAMP"/>
<result property="fileFinishTime" column="file_finish_time" jdbcType="TIMESTAMP"/>
<result property="fileStatus" column="file_status" jdbcType="VARCHAR"/>
<result property="createBy" column="create_by" jdbcType="VARCHAR"/>
<result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
<result property="version" column="version" jdbcType="INTEGER"/>
<result property="remark" column="remark" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Base_Column_List">
id, file_id, file_title, result_start_time, result_end_time, result_size, file_create_time, file_finish_time,
file_status, create_by, update_by, create_time, update_time, version, remark
</sql>
<select id="queryExportInfo" resultMap="GaeaExportMap">
SELECT
<include refid="Base_Column_List"></include>
FROM gaea_export ge
WHERE 1=1
<if test="bo.fileTitle!=null and bo.fileTitle!=''">
and ge.file_title=#{bo.fileTitle}
</if>
<if test="ew == null or ew.sqlSegment == null or ew.sqlSegment == '' ">
ORDER BY
ge.create_time DESC
</if>
<if test="ew != null and ew.sqlSegment != null and ew.sqlSegment != '' ">
<if test="ew.paramNameValuePairs != null and ew.paramNameValuePairs.size > 0">
and
</if>
${ew.sqlSegment}
</if>
</select>
</mapper>

View File

@ -1,50 +0,0 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.anjiplus.template.gaea.business.modules.gaeaUiI18n.dao.GaeaUiI18nMapper">
<resultMap type="com.anjiplus.template.gaea.business.modules.gaeaUiI18n.dao.entity.GaeaUiI18n" id="GaeaUiI18nMap">
<!--jdbcType="{column.columnType}"-->
<result property="id" column="id" />
<result property="locale" column="locale" />
<result property="cataType" column="cata_type" />
<result property="system" column="system" />
<result property="code" column="code" />
<result property="name" column="name" />
<result property="remark" column="remark" />
<result property="enabled" column="enabled" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="version" column="version" />
</resultMap>
<sql id="Base_Column_List">
id,locale,cata_type,system,code,name,remark,enabled,create_by,create_time,update_by,update_time,version
</sql>
<!--自定义sql -->
<select id="queryColumns" resultType="com.anjiplus.template.gaea.business.modules.gaeaUiI18n.service.impl.ColumnDesc" parameterType="java.lang.String">
select table_name as tableName,column_name as columnName,
column_type as columnType,data_type as dataType,character_maximum_length as maxLength,
column_comment as remark,column_default as defaultValue
from information_schema.columns
where table_schema=(select database())
and table_name not like 'ACT%'
<if test="tableName!=null">
and table_name like CONCAT('%', #{tableName})
</if>
</select>
<select id="queryTables" resultType="java.lang.String" parameterType="java.lang.String">
select concat(table_comment,':',table_name) as tableName
from information_schema.tables
where table_schema=(select database())
and table_name not like 'ACT%'
<if test="tableName!=null">
and table_name like CONCAT('%', #{tableName})
</if>
order by update_time desc
limit 100
</select>
<!--,table_comment as comment-->
</mapper>