diff --git a/nladmin-system/nlsso-server/pom.xml b/nladmin-system/nlsso-server/pom.xml index 244d963..c39fc8a 100644 --- a/nladmin-system/nlsso-server/pom.xml +++ b/nladmin-system/nlsso-server/pom.xml @@ -41,9 +41,15 @@ ${hutool.version} - + + + + org.springframework + spring-jdbc + 5.2.9.RELEASE @@ -385,6 +391,16 @@ httpclient 4.5.13 + + jakarta.transaction + jakarta.transaction-api + 1.3.3 + + + jakarta.persistence + jakarta.persistence-api + 2.2.3 + diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/AppRun.java b/nladmin-system/nlsso-server/src/main/java/org/nl/AppRun.java index 055d52c..230144d 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/AppRun.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/AppRun.java @@ -13,7 +13,6 @@ import org.springframework.boot.web.servlet.server.ServletWebServerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.FilterType; -import org.springframework.data.jpa.repository.config.EnableJpaAuditing; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.web.bind.annotation.GetMapping; @@ -34,7 +33,6 @@ import org.springframework.web.bind.annotation.RestController; }) @ServletComponentScan //https://blog.csdn.net/qq_36850813/article/details/101194250 @EnableTransactionManagement -@EnableJpaAuditing(auditorAwareRef = "auditorAware") @EnableMethodCache(basePackages = "org.nl") @EnableCreateCacheAnnotation @ComponentScan( diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/common/base/BaseEntity.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/common/base/BaseEntity.java deleted file mode 100644 index 08fc74e..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/common/base/BaseEntity.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.common.base; - -import com.alibaba.fastjson.annotation.JSONField; -import com.fasterxml.jackson.annotation.JsonFormat; -import io.swagger.annotations.ApiModelProperty; -import lombok.Getter; -import lombok.Setter; -import org.springframework.data.annotation.CreatedBy; -import org.springframework.data.annotation.LastModifiedBy; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import org.springframework.format.annotation.DateTimeFormat; - -import javax.persistence.Column; -import javax.persistence.EntityListeners; -import javax.persistence.MappedSuperclass; -import java.io.Serializable; -import java.util.Date; - -/** - * 通用字段, is_del 根据需求自行添加 - * @author Zheng Jie - * @Date 2019年10月24日20:46:32 - */ -@Getter -@Setter -@MappedSuperclass -@EntityListeners(AuditingEntityListener.class) -public class BaseEntity implements Serializable { - - @CreatedBy - @Column(name = "create_name", updatable = false) - @ApiModelProperty(value = "创建人", hidden = true) - private String create_name; - - private Long create_id; - - @LastModifiedBy - @Column(name = "update_optname") - @ApiModelProperty(value = "更新人", hidden = true) - private String update_optname; - - private Long update_optid; - - @Column(name = "create_time", updatable = false) - @ApiModelProperty(value = "创建时间", hidden = true) - @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") - @JSONField(format="yyyy-MM-dd HH:mm:ss") - private Date create_time; - - @Column(name = "update_time") - @ApiModelProperty(value = "更新时间", hidden = true) - @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") - @JSONField(format="yyyy-MM-dd HH:mm:ss") - private Date update_time; - - /* 分组校验 */ - public @interface Create {} - - /* 分组校验 */ - public @interface Update {} - - /*@Override - public String toString() { - ToStringBuilder builder = new ToStringBuilder(this); - Field[] fields = this.getClass().getDeclaredFields(); - try { - for (Field f : fields) { - f.setAccessible(true); - builder.append(f.getName(), f.get(this)).append("\n"); - } - } catch (Exception e) { - builder.append("toString builder encounter an error"); - } - return builder.toString(); - }*/ -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/common/utils/QueryHelp.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/common/utils/QueryHelp.java deleted file mode 100644 index 3403048..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/common/utils/QueryHelp.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.common.utils; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.collection.CollectionUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; -import lombok.extern.slf4j.Slf4j; -import org.nl.modules.common.annotation.DataPermission; -import org.nl.modules.common.annotation.Query; - -import javax.persistence.criteria.*; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -/** - * @author Zheng Jie - * @date 2019-6-4 14:59:48 - */ -@Slf4j -@SuppressWarnings({"unchecked","all"}) -public class QueryHelp { - - public static Predicate getPredicate(Root root, Q query, CriteriaBuilder cb) { - List list = new ArrayList<>(); - if(query == null){ - return cb.and(list.toArray(new Predicate[0])); - } - // 数据权限验证 - DataPermission permission = query.getClass().getAnnotation(DataPermission.class); - if(permission != null){ - // 获取数据权限 -// List dataScopes = SecurityUtils.getCurrentUserDataScope(); - List dataScopes = new ArrayList<>(); - if(CollectionUtil.isNotEmpty(dataScopes)){ - if(StrUtil.isNotEmpty(permission.joinName()) && StrUtil.isNotEmpty(permission.fieldName())) { - Join join = root.join(permission.joinName(), JoinType.LEFT); - list.add(getExpression(permission.fieldName(),join, root).in(dataScopes)); - } else if (StrUtil.isEmpty(permission.joinName()) && StrUtil.isNotEmpty(permission.fieldName())) { - list.add(getExpression(permission.fieldName(),null, root).in(dataScopes)); - } - } - } - try { - List fields = getAllFields(query.getClass(), new ArrayList<>()); - for (Field field : fields) { - boolean accessible = field.isAccessible(); - // 设置对象的访问权限,保证对private的属性的访 - field.setAccessible(true); - Query q = field.getAnnotation(Query.class); - if (q != null) { - String propName = q.propName(); - String joinName = q.joinName(); - String blurry = q.blurry(); - String attributeName = isBlank(propName) ? field.getName() : propName; - Class fieldType = field.getType(); - Object val = field.get(query); - if (ObjectUtil.isNull(val) || "".equals(val)) { - continue; - } - Join join = null; - // 模糊多字段 - if (ObjectUtil.isNotEmpty(blurry)) { - String[] blurrys = blurry.split(","); - List orPredicate = new ArrayList<>(); - for (String s : blurrys) { - orPredicate.add(cb.like(root.get(s) - .as(String.class), "%" + val.toString() + "%")); - } - Predicate[] p = new Predicate[orPredicate.size()]; - list.add(cb.or(orPredicate.toArray(p))); - continue; - } - if (ObjectUtil.isNotEmpty(joinName)) { - String[] joinNames = joinName.split(">"); - for (String name : joinNames) { - switch (q.join()) { - case LEFT: - if(ObjectUtil.isNotNull(join) && ObjectUtil.isNotNull(val)){ - join = join.join(name, JoinType.LEFT); - } else { - join = root.join(name, JoinType.LEFT); - } - break; - case RIGHT: - if(ObjectUtil.isNotNull(join) && ObjectUtil.isNotNull(val)){ - join = join.join(name, JoinType.RIGHT); - } else { - join = root.join(name, JoinType.RIGHT); - } - break; - case INNER: - if(ObjectUtil.isNotNull(join) && ObjectUtil.isNotNull(val)){ - join = join.join(name, JoinType.INNER); - } else { - join = root.join(name, JoinType.INNER); - } - break; - default: break; - } - } - } - switch (q.type()) { - case EQUAL: - list.add(cb.equal(getExpression(attributeName,join,root) - .as((Class) fieldType),val)); - break; - case GREATER_THAN: - list.add(cb.greaterThanOrEqualTo(getExpression(attributeName,join,root) - .as((Class) fieldType), (Comparable) val)); - break; - case LESS_THAN: - list.add(cb.lessThanOrEqualTo(getExpression(attributeName,join,root) - .as((Class) fieldType), (Comparable) val)); - break; - case LESS_THAN_NQ: - list.add(cb.lessThan(getExpression(attributeName,join,root) - .as((Class) fieldType), (Comparable) val)); - break; - case INNER_LIKE: - list.add(cb.like(getExpression(attributeName,join,root) - .as(String.class), "%" + val.toString() + "%")); - break; - case LEFT_LIKE: - list.add(cb.like(getExpression(attributeName,join,root) - .as(String.class), "%" + val.toString())); - break; - case RIGHT_LIKE: - list.add(cb.like(getExpression(attributeName,join,root) - .as(String.class), val.toString() + "%")); - break; - case IN: - if (CollUtil.isNotEmpty((Collection)val)) { - list.add(getExpression(attributeName,join,root).in((Collection) val)); - } - break; - case NOT_EQUAL: - list.add(cb.notEqual(getExpression(attributeName,join,root), val)); - break; - case NOT_NULL: - list.add(cb.isNotNull(getExpression(attributeName,join,root))); - break; - case IS_NULL: - list.add(cb.isNull(getExpression(attributeName,join,root))); - break; - case BETWEEN: - List between = new ArrayList<>((List)val); - list.add(cb.between(getExpression(attributeName, join, root).as((Class) between.get(0).getClass()), - (Comparable) between.get(0), (Comparable) between.get(1))); - break; - default: break; - } - } - field.setAccessible(accessible); - } - } catch (Exception e) { - log.error(e.getMessage(), e); - } - int size = list.size(); - return cb.and(list.toArray(new Predicate[size])); - } - - @SuppressWarnings("unchecked") - private static Expression getExpression(String attributeName, Join join, Root root) { - if (ObjectUtil.isNotEmpty(join)) { - return join.get(attributeName); - } else { - return root.get(attributeName); - } - } - - private static boolean isBlank(final CharSequence cs) { - int strLen; - if (cs == null || (strLen = cs.length()) == 0) { - return true; - } - for (int i = 0; i < strLen; i++) { - if (!Character.isWhitespace(cs.charAt(i))) { - return false; - } - } - return true; - } - - public static List getAllFields(Class clazz, List fields) { - if (clazz != null) { - fields.addAll(Arrays.asList(clazz.getDeclaredFields())); - getAllFields(clazz.getSuperclass(), fields); - } - return fields; - } -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/common/utils/dto/CurrentUser.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/common/utils/dto/CurrentUser.java index f490abc..178cb44 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/common/utils/dto/CurrentUser.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/common/utils/dto/CurrentUser.java @@ -3,7 +3,6 @@ package org.nl.modules.common.utils.dto; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import lombok.Data; -import org.nl.modules.system.domain.User; import org.nl.modules.system.service.dto.UserDto; import java.io.Serializable; diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/domain/ColumnInfo.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/domain/ColumnInfo.java deleted file mode 100644 index cc23dd5..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/domain/ColumnInfo.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.generator.domain; - -import io.swagger.annotations.ApiModelProperty; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import org.nl.modules.generator.utils.GenUtil; - -import javax.persistence.*; -import java.io.Serializable; - -/** - * 列的数据信息 - * @author Zheng Jie - * @date 2019-01-02 - */ -@Getter -@Setter -@Entity -@NoArgsConstructor -@Table(name = "code_column_config") -public class ColumnInfo implements Serializable { - - @Id - @Column(name = "column_id") - @ApiModelProperty(value = "ID", hidden = true) - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @ApiModelProperty(value = "表名") - private String tableName; - - @ApiModelProperty(value = "数据库字段名称") - private String columnName; - - @ApiModelProperty(value = "数据库字段类型") - private String columnType; - - @ApiModelProperty(value = "数据库字段键类型") - private String keyType; - - @ApiModelProperty(value = "字段额外的参数") - private String extra; - - @ApiModelProperty(value = "数据库字段描述") - private String remark; - - @ApiModelProperty(value = "是否必填") - private Boolean notNull; - - @ApiModelProperty(value = "是否在列表显示") - private Boolean listShow; - - @ApiModelProperty(value = "是否表单显示") - private Boolean formShow; - - @ApiModelProperty(value = "表单类型") - private String formType; - - @ApiModelProperty(value = "查询 1:模糊 2:精确") - private String queryType; - - @ApiModelProperty(value = "字典名称") - private String dictName; - - @ApiModelProperty(value = "日期注解") - private String dateAnnotation; - - public ColumnInfo(String tableName, String columnName, Boolean notNull, String columnType, String remark, String keyType, String extra) { - this.tableName = tableName; - this.columnName = columnName; - this.columnType = columnType; - this.keyType = keyType; - this.extra = extra; - this.notNull = notNull; - if(GenUtil.PK.equalsIgnoreCase(keyType) && GenUtil.EXTRA.equalsIgnoreCase(extra)){ - this.notNull = false; - } - this.remark = remark; - this.listShow = true; - this.formShow = true; - } -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/domain/GenConfig.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/domain/GenConfig.java deleted file mode 100644 index 454b1e9..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/domain/GenConfig.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.generator.domain; - -import io.swagger.annotations.ApiModelProperty; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -import javax.persistence.*; -import javax.validation.constraints.NotBlank; -import java.io.Serializable; - -/** - * 代码生成配置 - * @author Zheng Jie - * @date 2019-01-03 - */ -@Getter -@Setter -@Entity -@NoArgsConstructor -@Table(name = "code_gen_config") -public class GenConfig implements Serializable { - - public GenConfig(String tableName) { - this.tableName = tableName; - } - - @Id - @Column(name = "config_id") - @ApiModelProperty(value = "ID", hidden = true) - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @NotBlank - @ApiModelProperty(value = "表名") - private String tableName; - - @ApiModelProperty(value = "接口名称") - private String apiAlias; - - @NotBlank - @ApiModelProperty(value = "包路径") - private String pack; - - @NotBlank - @ApiModelProperty(value = "模块名") - private String moduleName; - - @NotBlank - @ApiModelProperty(value = "前端文件路径") - private String path; - - @ApiModelProperty(value = "前端文件路径") - private String apiPath; - - @ApiModelProperty(value = "作者") - private String author; - - @ApiModelProperty(value = "表前缀") - private String prefix; - - @ApiModelProperty(value = "是否覆盖") - private Boolean cover = false; -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/domain/vo/TableInfo.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/domain/vo/TableInfo.java deleted file mode 100644 index ddf3388..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/domain/vo/TableInfo.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.generator.domain.vo; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * 表的数据信息 - * @author Zheng Jie - * @date 2019-01-02 - */ -@Data -@AllArgsConstructor -@NoArgsConstructor -public class TableInfo { - - /** 表名称 */ - private Object tableName; - - /** 创建日期 */ - private Object createTime; - - /** 数据库引擎 */ - private Object engine; - - /** 编码集 */ - private Object coding; - - /** 备注 */ - private Object remark; - - -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/repository/ColumnInfoRepository.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/repository/ColumnInfoRepository.java deleted file mode 100644 index 8af5fbb..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/repository/ColumnInfoRepository.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.generator.repository; - -import org.nl.modules.generator.domain.ColumnInfo; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.List; - -/** - * @author Zheng Jie - * @date 2019-01-14 - */ -public interface ColumnInfoRepository extends JpaRepository { - - /** - * 查询表信息 - * @param tableName 表格名 - * @return 表信息 - */ - List findByTableNameOrderByIdAsc(String tableName); -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/repository/GenConfigRepository.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/repository/GenConfigRepository.java deleted file mode 100644 index c6afcef..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/repository/GenConfigRepository.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.generator.repository; - -import org.nl.modules.generator.domain.GenConfig; -import org.springframework.data.jpa.repository.JpaRepository; - -/** - * @author Zheng Jie - * @date 2019-01-14 - */ -public interface GenConfigRepository extends JpaRepository { - - /** - * 查询表配置 - * @param tableName 表名 - * @return / - */ - GenConfig findByTableName(String tableName); -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/rest/GenConfigController.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/rest/GenConfigController.java deleted file mode 100644 index 75ee5b5..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/rest/GenConfigController.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.generator.rest; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.RequiredArgsConstructor; -import org.nl.modules.generator.domain.GenConfig; -import org.nl.modules.generator.service.GenConfigService; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -/** - * @author Zheng Jie - * @date 2019-01-14 - */ -@RestController -@RequiredArgsConstructor -@RequestMapping("/api/genConfig") -@Api(tags = "系统:代码生成器配置管理") -public class GenConfigController { - - private final GenConfigService genConfigService; - - @ApiOperation("查询") - @GetMapping(value = "/{tableName}") - public ResponseEntity query(@PathVariable String tableName){ - return new ResponseEntity<>(genConfigService.find(tableName), HttpStatus.OK); - } - - @ApiOperation("修改") - @PutMapping - public ResponseEntity update(@Validated @RequestBody GenConfig genConfig){ - return new ResponseEntity<>(genConfigService.update(genConfig.getTableName(), genConfig),HttpStatus.OK); - } -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/rest/GeneratorController.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/rest/GeneratorController.java deleted file mode 100644 index 1023843..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/rest/GeneratorController.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.generator.rest; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.RequiredArgsConstructor; -import org.nl.modules.common.exception.BadRequestException; -import org.nl.modules.common.utils.PageUtil; -import org.nl.modules.generator.domain.ColumnInfo; -import org.nl.modules.generator.service.GenConfigService; -import org.nl.modules.generator.service.GeneratorService; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.List; - -/** - * @author Zheng Jie - * @date 2019-01-02 - */ -@RestController -@RequiredArgsConstructor -@RequestMapping("/api/generator") -@Api(tags = "系统:代码生成管理") -public class GeneratorController { - - private final GeneratorService generatorService; - private final GenConfigService genConfigService; - - @Value("${generator.enabled}") - private Boolean generatorEnabled; - - @ApiOperation("查询数据库数据") - @GetMapping(value = "/tables/all") - public ResponseEntity queryTables(){ - return new ResponseEntity<>(generatorService.getTables(), HttpStatus.OK); - } - - @ApiOperation("查询数据库数据") - @GetMapping(value = "/tables") - public ResponseEntity queryTables(@RequestParam(defaultValue = "") String name, - @RequestParam(defaultValue = "0")Integer page, - @RequestParam(defaultValue = "10")Integer size){ - int[] startEnd = PageUtil.transToStartEnd(page, size); - return new ResponseEntity<>(generatorService.getTables(name,startEnd), HttpStatus.OK); - } - - @ApiOperation("查询字段数据") - @GetMapping(value = "/columns") - public ResponseEntity queryColumns(@RequestParam String tableName){ - List columnInfos = generatorService.getColumns(tableName); - return new ResponseEntity<>(PageUtil.toPage(columnInfos,columnInfos.size()), HttpStatus.OK); - } - - @ApiOperation("保存字段数据") - @PutMapping - public ResponseEntity save(@RequestBody List columnInfos){ - generatorService.save(columnInfos); - return new ResponseEntity<>(HttpStatus.OK); - } - - @ApiOperation("同步字段数据") - @PostMapping(value = "sync") - public ResponseEntity sync(@RequestBody List tables){ - for (String table : tables) { - generatorService.sync(generatorService.getColumns(table), generatorService.query(table)); - } - return new ResponseEntity<>(HttpStatus.OK); - } - - @ApiOperation("生成代码") - @PostMapping(value = "/{tableName}/{type}") - public ResponseEntity generator(@PathVariable String tableName, @PathVariable Integer type, HttpServletRequest request, HttpServletResponse response){ - if(!generatorEnabled && type == 0){ - throw new BadRequestException("此环境不允许生成代码,请选择预览或者下载查看!"); - } - switch (type){ - // 生成代码 - case 0: generatorService.generator(genConfigService.find(tableName), generatorService.getColumns(tableName)); - break; - // 预览 - case 1: return generatorService.preview(genConfigService.find(tableName), generatorService.getColumns(tableName)); - // 打包 - case 2: generatorService.download(genConfigService.find(tableName), generatorService.getColumns(tableName), request, response); - break; - default: throw new BadRequestException("没有这个选项"); - } - return new ResponseEntity<>(HttpStatus.OK); - } -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/service/GenConfigService.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/service/GenConfigService.java deleted file mode 100644 index 43d9ab3..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/service/GenConfigService.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.generator.service; - -import org.nl.modules.generator.domain.GenConfig; - -/** - * @author Zheng Jie - * @date 2019-01-14 - */ -public interface GenConfigService { - - /** - * 查询表配置 - * @param tableName 表名 - * @return 表配置 - */ - GenConfig find(String tableName); - - /** - * 更新表配置 - * @param tableName 表名 - * @param genConfig 表配置 - * @return 表配置 - */ - GenConfig update(String tableName, GenConfig genConfig); -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/service/GeneratorService.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/service/GeneratorService.java deleted file mode 100644 index 0e749f3..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/service/GeneratorService.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.generator.service; - -import org.nl.modules.generator.domain.ColumnInfo; -import org.nl.modules.generator.domain.GenConfig; -import org.springframework.http.ResponseEntity; -import org.springframework.scheduling.annotation.Async; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.List; - -/** - * @author Zheng Jie - * @date 2019-01-02 - */ -public interface GeneratorService { - - /** - * 查询数据库元数据 - * @param name 表名 - * @param startEnd 分页参数 - * @return / - */ - Object getTables(String name, int[] startEnd); - - /** - * 得到数据表的元数据 - * @param name 表名 - * @return / - */ - List getColumns(String name); - - /** - * 同步表数据 - * @param columnInfos / - * @param columnInfoList / - */ - @Async - void sync(List columnInfos, List columnInfoList); - - /** - * 保持数据 - * @param columnInfos / - */ - void save(List columnInfos); - - /** - * 获取所有table - * @return / - */ - Object getTables(); - - /** - * 代码生成 - * @param genConfig 配置信息 - * @param columns 字段信息 - */ - void generator(GenConfig genConfig, List columns); - - /** - * 预览 - * @param genConfig 配置信息 - * @param columns 字段信息 - * @return / - */ - ResponseEntity preview(GenConfig genConfig, List columns); - - /** - * 打包下载 - * @param genConfig 配置信息 - * @param columns 字段信息 - * @param request / - * @param response / - */ - void download(GenConfig genConfig, List columns, HttpServletRequest request, HttpServletResponse response); - - /** - * 查询数据库的表字段数据数据 - * @param table / - * @return / - */ - List query(String table); -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/service/impl/GenConfigServiceImpl.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/service/impl/GenConfigServiceImpl.java deleted file mode 100644 index 1795164..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/service/impl/GenConfigServiceImpl.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.generator.service.impl; - -import cn.hutool.core.util.StrUtil; -import lombok.RequiredArgsConstructor; -import org.nl.modules.generator.domain.GenConfig; -import org.nl.modules.generator.repository.GenConfigRepository; -import org.nl.modules.generator.service.GenConfigService; -import org.springframework.stereotype.Service; - -import java.io.File; - -/** - * @author Zheng Jie - * @date 2019-01-14 - */ -@Service -@RequiredArgsConstructor -public class GenConfigServiceImpl implements GenConfigService { - - private final GenConfigRepository genConfigRepository; - - @Override - public GenConfig find(String tableName) { - GenConfig genConfig = genConfigRepository.findByTableName(tableName); - if(genConfig == null){ - return new GenConfig(tableName); - } - return genConfig; - } - - @Override - public GenConfig update(String tableName, GenConfig genConfig) { - // 如果 api 路径为空,则自动生成路径 - if(StrUtil.isEmpty(genConfig.getApiPath())){ - String separator = File.separator; - String[] paths; - String symbol = "\\"; - if (symbol.equals(separator)) { - paths = genConfig.getPath().split("\\\\"); - } else { - paths = genConfig.getPath().split(File.separator); - } - StringBuilder api = new StringBuilder(); - for (String path : paths) { - api.append(path); - api.append(separator); - if ("src".equals(path)) { - api.append("api"); - break; - } - } - genConfig.setApiPath(api.toString()); - } - return genConfigRepository.save(genConfig); - } -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/service/impl/GeneratorServiceImpl.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/service/impl/GeneratorServiceImpl.java deleted file mode 100644 index 3fea2a9..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/service/impl/GeneratorServiceImpl.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.generator.service.impl; - -import cn.hutool.core.collection.CollectionUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; -import cn.hutool.core.util.ZipUtil; -import lombok.RequiredArgsConstructor; -import org.nl.modules.common.exception.BadRequestException; -import org.nl.modules.common.utils.FileUtil; -import org.nl.modules.common.utils.PageUtil; -import org.nl.modules.generator.domain.ColumnInfo; -import org.nl.modules.generator.domain.GenConfig; -import org.nl.modules.generator.domain.vo.TableInfo; -import org.nl.modules.generator.repository.ColumnInfoRepository; -import org.nl.modules.generator.service.GeneratorService; -import org.nl.modules.generator.utils.GenUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Service; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.Query; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * @author Zheng Jie - * @date 2019-01-02 - */ -@Service -@RequiredArgsConstructor -public class GeneratorServiceImpl implements GeneratorService { - private static final Logger log = LoggerFactory.getLogger(GeneratorServiceImpl.class); - @PersistenceContext - private EntityManager em; - - private final ColumnInfoRepository columnInfoRepository; - - @Override - public Object getTables() { - // 使用预编译防止sql注入 - String sql = "select table_name ,create_time , engine, table_collation, table_comment from information_schema.tables " + - "where table_schema = (select database()) " + - "order by create_time desc"; - Query query = em.createNativeQuery(sql); - return query.getResultList(); - } - - @Override - public Object getTables(String name, int[] startEnd) { - // 使用预编译防止sql注入 - String sql = "select table_name ,create_time , engine, table_collation, table_comment from information_schema.tables " + - "where table_schema = (select database()) " + - "and table_name like ? order by create_time desc"; - Query query = em.createNativeQuery(sql); - query.setFirstResult(startEnd[0]); - query.setMaxResults(startEnd[1] - startEnd[0]); - query.setParameter(1, StrUtil.isNotEmpty(name) ? ("%" + name + "%") : "%%"); - List result = query.getResultList(); - List tableInfos = new ArrayList<>(); - for (Object obj : result) { - Object[] arr = (Object[]) obj; - tableInfos.add(new TableInfo(arr[0], arr[1], arr[2], arr[3], ObjectUtil.isNotEmpty(arr[4]) ? arr[4] : "-")); - } - Query query1 = em.createNativeQuery("SELECT COUNT(*) from information_schema.tables where table_schema = (select database())"); - Object totalElements = query1.getSingleResult(); - return PageUtil.toPage(tableInfos, totalElements); - } - - @Override - public List getColumns(String tableName) { - List columnInfos = columnInfoRepository.findByTableNameOrderByIdAsc(tableName); - if (CollectionUtil.isNotEmpty(columnInfos)) { - return columnInfos; - } else { - columnInfos = query(tableName); - return columnInfoRepository.saveAll(columnInfos); - } - } - - @Override - public List query(String tableName) { - // 使用预编译防止sql注入 - String sql = "select column_name, is_nullable, data_type, column_comment, column_key, extra from information_schema.columns " + - "where table_name = ? and table_schema = (select database()) order by ordinal_position"; - Query query = em.createNativeQuery(sql); - query.setParameter(1, tableName); - List result = query.getResultList(); - List columnInfos = new ArrayList<>(); - for (Object obj : result) { - Object[] arr = (Object[]) obj; - columnInfos.add( - new ColumnInfo( - tableName, - arr[0].toString(), - "NO".equals(arr[1]), - arr[2].toString(), - ObjectUtil.isNotNull(arr[3]) ? arr[3].toString() : null, - ObjectUtil.isNotNull(arr[4]) ? arr[4].toString() : null, - ObjectUtil.isNotNull(arr[5]) ? arr[5].toString() : null) - ); - } - return columnInfos; - } - - @Override - public void sync(List columnInfos, List columnInfoList) { - // 第一种情况,数据库类字段改变或者新增字段 - for (ColumnInfo columnInfo : columnInfoList) { - // 根据字段名称查找 - List columns = columnInfos.stream().filter(c -> c.getColumnName().equals(columnInfo.getColumnName())).collect(Collectors.toList()); - // 如果能找到,就修改部分可能被字段 - if (CollectionUtil.isNotEmpty(columns)) { - ColumnInfo column = columns.get(0); - column.setColumnType(columnInfo.getColumnType()); - column.setExtra(columnInfo.getExtra()); - column.setKeyType(columnInfo.getKeyType()); - if (StrUtil.isEmpty(column.getRemark())) { - column.setRemark(columnInfo.getRemark()); - } - columnInfoRepository.save(column); - } else { - // 如果找不到,则保存新字段信息 - columnInfoRepository.save(columnInfo); - } - } - // 第二种情况,数据库字段删除了 - for (ColumnInfo columnInfo : columnInfos) { - // 根据字段名称查找 - List columns = columnInfoList.stream().filter(c -> c.getColumnName().equals(columnInfo.getColumnName())).collect(Collectors.toList()); - // 如果找不到,就代表字段被删除了,则需要删除该字段 - if (CollectionUtil.isEmpty(columns)) { - columnInfoRepository.delete(columnInfo); - } - } - } - - @Override - public void save(List columnInfos) { - columnInfoRepository.saveAll(columnInfos); - } - - @Override - public void generator(GenConfig genConfig, List columns) { - if (genConfig.getId() == null) { - throw new BadRequestException("请先配置生成器"); - } - try { - GenUtil.generatorCode(columns, genConfig); - } catch (IOException e) { - log.error(e.getMessage(), e); - throw new BadRequestException("生成失败,请手动处理已生成的文件"); - } - } - - @Override - public ResponseEntity preview(GenConfig genConfig, List columns) { - if (genConfig.getId() == null) { - throw new BadRequestException("请先配置生成器"); - } - List> genList = GenUtil.preview(columns, genConfig); - return new ResponseEntity<>(genList, HttpStatus.OK); - } - - @Override - public void download(GenConfig genConfig, List columns, HttpServletRequest request, HttpServletResponse response) { - if (genConfig.getId() == null) { - throw new BadRequestException("请先配置生成器"); - } - try { - File file = new File(GenUtil.download(columns, genConfig)); - String zipPath = file.getPath() + ".zip"; - ZipUtil.zip(file.getPath(), zipPath); - FileUtil.downloadFile(request, response, new File(zipPath), true); - } catch (IOException e) { - throw new BadRequestException("打包失败"); - } - } -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/utils/ColUtil.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/utils/ColUtil.java deleted file mode 100644 index ff5a971..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/utils/ColUtil.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.generator.utils; - -import org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.PropertiesConfiguration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * sql字段转java - * - * @author Zheng Jie - * @date 2019-01-03 - */ -public class ColUtil { - private static final Logger log = LoggerFactory.getLogger(ColUtil.class); - - /** - * 转换mysql数据类型为java数据类型 - * - * @param type 数据库字段类型 - * @return String - */ - static String cloToJava(String type) { - Configuration config = getConfig(); - assert config != null; - return config.getString(type, "unknowType"); - } - - /** - * 获取配置信息 - */ - public static PropertiesConfiguration getConfig() { - try { - return new PropertiesConfiguration("generator.properties"); - } catch (ConfigurationException e) { - log.error(e.getMessage(), e); - } - return null; - } -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/utils/GenUtil.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/utils/GenUtil.java deleted file mode 100644 index 974f224..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/generator/utils/GenUtil.java +++ /dev/null @@ -1,429 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.generator.utils; - -import cn.hutool.core.util.StrUtil; -import cn.hutool.extra.template.*; -import lombok.extern.slf4j.Slf4j; -import org.nl.modules.common.utils.FileUtil; -import org.nl.modules.common.utils.StringUtils; -import org.nl.modules.generator.domain.ColumnInfo; -import org.nl.modules.generator.domain.GenConfig; -import org.springframework.util.ObjectUtils; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.Writer; -import java.time.LocalDate; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.nl.modules.common.utils.FileUtil.SYS_TEM_DIR; - - -/** - * 代码生成 - * - * @author Zheng Jie - * @date 2019-01-02 - */ -@Slf4j -@SuppressWarnings({"unchecked", "all"}) -public class GenUtil { - - private static final String Date = "Date"; - - private static final String BIGDECIMAL = "BigDecimal"; - - public static final String PK = "PRI"; - - public static final String EXTRA = "auto_increment"; - - /** - * 获取后端代码模板名称 - * - * @return List - */ - private static List getAdminTemplateNames() { - List templateNames = new ArrayList<>(); - // templateNames.add("Entity"); - templateNames.add("Dto"); - // templateNames.add("Mapper"); - templateNames.add("Controller"); - //templateNames.add("QueryCriteria"); - templateNames.add("Service"); - templateNames.add("ServiceImpl"); - // templateNames.add("Repository"); - return templateNames; - } - - /** - * 获取前端代码模板名称 - * - * @return List - */ - private static List getFrontTemplateNames() { - List templateNames = new ArrayList<>(); - templateNames.add("index"); - templateNames.add("api"); - return templateNames; - } - - public static List> preview(List columns, GenConfig genConfig) { - Map genMap = getGenMap(columns, genConfig); - List> genList = new ArrayList<>(); - // 获取后端模版 - List templates = getAdminTemplateNames(); - TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH)); - for (String templateName : templates) { - Map map = new HashMap<>(1); - Template template = engine.getTemplate("generator/admin/" + templateName + ".ftl"); - map.put("content", template.render(genMap)); - map.put("name", templateName); - genList.add(map); - } - // 获取前端模版 - templates = getFrontTemplateNames(); - for (String templateName : templates) { - Map map = new HashMap<>(1); - Template template = engine.getTemplate("generator/front/" + templateName + ".ftl"); - map.put(templateName, template.render(genMap)); - map.put("content", template.render(genMap)); - map.put("name", templateName); - genList.add(map); - } - return genList; - } - - public static String download(List columns, GenConfig genConfig) throws IOException { - // 拼接的路径:/tmpnladmin-gen-temp/,这个路径在Linux下需要root用户才有权限创建,非root用户会权限错误而失败,更改为: /tmp/nladmin-gen-temp/ - // String tempPath =SYS_TEM_DIR + "nladmin-gen-temp" + File.separator + genConfig.getTableName() + File.separator; - String tempPath = SYS_TEM_DIR + "nladmin-gen-temp" + File.separator + genConfig.getTableName() + File.separator; - Map genMap = getGenMap(columns, genConfig); - TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH)); - // 生成后端代码 - List templates = getAdminTemplateNames(); - for (String templateName : templates) { - Template template = engine.getTemplate("generator/admin/" + templateName + ".ftl"); - String filePath = getAdminFilePath(templateName, genConfig, genMap.get("className").toString(), tempPath + "eladmin" + File.separator); - assert filePath != null; - File file = new File(filePath); - // 如果非覆盖生成 - if (!genConfig.getCover() && FileUtil.exist(file)) { - continue; - } - // 生成代码 - genFile(file, template, genMap); - } - // 生成前端代码 - templates = getFrontTemplateNames(); - for (String templateName : templates) { - Template template = engine.getTemplate("generator/front/" + templateName + ".ftl"); - String path = tempPath + "nladmin-web" + File.separator; - String apiPath = path + "src" + File.separator + "api" + File.separator; - String srcPath = path + "src" + File.separator + "views" + File.separator + genMap.get("changeClassName").toString() + File.separator; - String filePath = getFrontFilePath(templateName, apiPath, srcPath, genMap.get("changeClassName").toString()); - assert filePath != null; - File file = new File(filePath); - // 如果非覆盖生成 - if (!genConfig.getCover() && FileUtil.exist(file)) { - continue; - } - // 生成代码 - genFile(file, template, genMap); - } - return tempPath; - } - - public static void generatorCode(List columnInfos, GenConfig genConfig) throws IOException { - Map genMap = getGenMap(columnInfos, genConfig); - TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH)); - // 生成后端代码 - List templates = getAdminTemplateNames(); - for (String templateName : templates) { - Template template = engine.getTemplate("generator/admin/" + templateName + ".ftl"); - String filePath = getAdminFilePath(templateName, genConfig, genMap.get("className").toString(), System.getProperty("user.dir")); - - assert filePath != null; - File file = new File(filePath); - - // 如果非覆盖生成 - if (!genConfig.getCover() && FileUtil.exist(file)) { - continue; - } - // 生成代码 - genFile(file, template, genMap); - } - - // 生成前端代码 - templates = getFrontTemplateNames(); - for (String templateName : templates) { - Template template = engine.getTemplate("generator/front/" + templateName + ".ftl"); - String filePath = getFrontFilePath(templateName, genConfig.getApiPath(), genConfig.getPath(), genMap.get("changeClassName").toString()); - - assert filePath != null; - File file = new File(filePath); - - // 如果非覆盖生成 - if (!genConfig.getCover() && FileUtil.exist(file)) { - continue; - } - // 生成代码 - genFile(file, template, genMap); - } - } - - // 获取模版数据 - private static Map getGenMap(List columnInfos, GenConfig genConfig) { - // 存储模版字段数据 - Map genMap = new HashMap<>(16); - // 接口别名 - genMap.put("apiAlias", genConfig.getApiAlias()); - // 包名称 - genMap.put("package", genConfig.getPack()); - // 模块名称 - genMap.put("moduleName", genConfig.getModuleName()); - // 作者 - genMap.put("author", genConfig.getAuthor()); - // 创建日期 - genMap.put("date", LocalDate.now().toString()); - // 表名 - genMap.put("tableName", genConfig.getTableName()); - // 大写开头的类名 - String className = StringUtils.toCapitalizeCamelCase(genConfig.getTableName()); - // 小写开头的类名 - String changeClassName = StringUtils.toCamelCase(genConfig.getTableName()); - // 判断是否去除表前缀 - if (StrUtil.isNotEmpty(genConfig.getPrefix())) { - className = StringUtils.toCapitalizeCamelCase(StrUtil.removePrefix(genConfig.getTableName(), genConfig.getPrefix())); - changeClassName = StringUtils.toCamelCase(StrUtil.removePrefix(genConfig.getTableName(), genConfig.getPrefix())); - } - // 保存类名 - genMap.put("className", className); - // 保存小写开头的类名 - genMap.put("changeClassName", changeClassName); - // 存在 Date 字段 - genMap.put("hasDate", false); - // 查询类中存在 Date 字段 - genMap.put("queryHasDate", false); - // 存在 BigDecimal 字段 - genMap.put("hasBigDecimal", false); - // 查询类中存在 BigDecimal 字段 - genMap.put("queryHasBigDecimal", false); - // 是否需要创建查询 - genMap.put("hasQuery", false); - // 自增主键 - genMap.put("auto", false); - // 存在字典 - genMap.put("hasDict", false); - // 存在日期注解 - genMap.put("hasDateAnnotation", false); - // 保存字段信息 - List> columns = new ArrayList<>(); - // 保存查询字段的信息 - List> queryColumns = new ArrayList<>(); - // 存储字典信息 - List dicts = new ArrayList<>(); - // 存储 between 信息 - List> betweens = new ArrayList<>(); - // 存储不为空的字段信息 - List> isNotNullColumns = new ArrayList<>(); - - for (ColumnInfo column : columnInfos) { - Map listMap = new HashMap<>(16); - // 字段描述 - listMap.put("remark", column.getRemark()); - // 字段类型 - listMap.put("columnKey", column.getKeyType()); - // 主键类型 - String colType = ColUtil.cloToJava(column.getColumnType()); - // 小写开头的字段名 - //String changeColumnName = StringUtils.toCamelCase(column.getColumnName()); - String changeColumnName = column.getColumnName(); - // 大写开头的字段名 - String capitalColumnName = StringUtils.toCapitalizeCamelCase(column.getColumnName()); - if (PK.equals(column.getKeyType())) { - // 存储主键类型 - genMap.put("pkColumnType", colType); - // 存储小写开头的字段名 - genMap.put("pkChangeColName", changeColumnName); - // 存储大写开头的字段名 - genMap.put("pkCapitalColName", capitalColumnName); - } - // 是否存在 Date 类型的字段 - if (Date.equals(colType)) { - genMap.put("hasDate", true); - } - // 是否存在 BigDecimal 类型的字段 - if (BIGDECIMAL.equals(colType)) { - genMap.put("hasBigDecimal", true); - } - // 主键是否自增 - if (EXTRA.equals(column.getExtra())) { - genMap.put("auto", true); - } - // 主键存在字典 - if (StrUtil.isNotEmpty(column.getDictName())) { - genMap.put("hasDict", true); - dicts.add(column.getDictName()); - } - - // 存储字段类型 - listMap.put("columnType", colType); - // 存储字原始段名称 - listMap.put("columnName", column.getColumnName()); - // 不为空 - listMap.put("istNotNull", column.getNotNull()); - // 字段列表显示 - listMap.put("columnShow", column.getListShow()); - // 表单显示 - listMap.put("formShow", column.getFormShow()); - // 表单组件类型 - listMap.put("formType", StrUtil.isNotEmpty(column.getFormType()) ? column.getFormType() : "Input"); - // 小写开头的字段名称 - listMap.put("changeColumnName", changeColumnName); - //大写开头的字段名称 - listMap.put("capitalColumnName", capitalColumnName); - // 字典名称 - listMap.put("dictName", column.getDictName()); - // 日期注解 - listMap.put("dateAnnotation", column.getDateAnnotation()); - if (StrUtil.isNotEmpty(column.getDateAnnotation())) { - genMap.put("hasDateAnnotation", true); - } - // 添加非空字段信息 - if (column.getNotNull()) { - isNotNullColumns.add(listMap); - } - // 判断是否有查询,如有则把查询的字段set进columnQuery - if (!StrUtil.isEmpty(column.getQueryType())) { - // 查询类型 - listMap.put("queryType", column.getQueryType()); - // 是否存在查询 - genMap.put("hasQuery", true); - if (Date.equals(colType)) { - // 查询中存储 Date 类型 - genMap.put("queryHasDate", true); - } - if (BIGDECIMAL.equals(colType)) { - // 查询中存储 BigDecimal 类型 - genMap.put("queryHasBigDecimal", true); - } - if ("between".equalsIgnoreCase(column.getQueryType())) { - betweens.add(listMap); - } else { - // 添加到查询列表中 - queryColumns.add(listMap); - } - } - // 添加到字段列表中 - columns.add(listMap); - } - // 保存字段列表 - genMap.put("columns", columns); - // 保存查询列表 - genMap.put("queryColumns", queryColumns); - // 保存字段列表 - genMap.put("dicts", dicts); - // 保存查询列表 - genMap.put("betweens", betweens); - // 保存非空字段信息 - genMap.put("isNotNullColumns", isNotNullColumns); - return genMap; - } - - /** - * 定义后端文件路径以及名称 - */ - private static String getAdminFilePath(String templateName, GenConfig genConfig, String className, String rootPath) { - String projectPath = rootPath + File.separator + genConfig.getModuleName(); - String packagePath = projectPath + File.separator + "src" + File.separator + "main" + File.separator + "java" + File.separator; - if (!ObjectUtils.isEmpty(genConfig.getPack())) { - packagePath += genConfig.getPack().replace(".", File.separator) + File.separator; - } - - if ("Entity".equals(templateName)) { - return packagePath + "domain" + File.separator + className + ".java"; - } - - if ("Controller".equals(templateName)) { - return packagePath + "rest" + File.separator + className + "Controller.java"; - } - - if ("Service".equals(templateName)) { - return packagePath + "service" + File.separator + className + "Service.java"; - } - - if ("ServiceImpl".equals(templateName)) { - return packagePath + "service" + File.separator + "impl" + File.separator + className + "ServiceImpl.java"; - } - - if ("Dto".equals(templateName)) { - return packagePath + "service" + File.separator + "dto" + File.separator + className + "Dto.java"; - } - - if ("QueryCriteria".equals(templateName)) { - return packagePath + "service" + File.separator + "dto" + File.separator + className + "QueryCriteria.java"; - } - - if ("Mapper".equals(templateName)) { - return packagePath + "service" + File.separator + "mapstruct" + File.separator + className + "Mapper.java"; - } - - if ("Repository".equals(templateName)) { - return packagePath + "repository" + File.separator + className + "Repository.java"; - } - - return null; - } - - /** - * 定义前端文件路径以及名称 - */ - private static String getFrontFilePath(String templateName, String apiPath, String path, String apiName) { - - if ("api".equals(templateName)) { -// return apiPath + File.separator + apiName + ".js"; - //和vue同文件夹 - return path + File.separator + ".js"; - - } - - if ("index".equals(templateName)) { - return path + File.separator + "index.vue"; - } - - return null; - } - - private static void genFile(File file, Template template, Map map) throws IOException { - // 生成目标文件 - Writer writer = null; - try { - FileUtil.touch(file); - writer = new FileWriter(file); - template.render(map, writer); - } catch (TemplateException | IOException e) { - throw new RuntimeException(e); - } finally { - assert writer != null; - writer.close(); - } - } -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/aspect/LogAspect.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/aspect/LogAspect.java index bd0965a..0e45788 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/aspect/LogAspect.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/aspect/LogAspect.java @@ -12,7 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ + *//* + package org.nl.modules.logging.aspect; import cn.hutool.core.util.StrUtil; @@ -30,7 +31,6 @@ import org.nl.modules.common.utils.SecurityUtils; import org.nl.modules.common.utils.StringUtils; import org.nl.modules.common.utils.ThrowableUtil; import org.nl.modules.logging.domain.Log; -import org.nl.modules.logging.service.LogService; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; @@ -46,10 +46,12 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +*/ /** * @author Zheng Jie * @date 2018-11-24 - */ + *//* + @Component @Aspect @Slf4j @@ -63,19 +65,23 @@ public class LogAspect { this.logService = logService; } - /** + */ +/** * 配置切入点 - */ + *//* + @Pointcut("@annotation(org.nl.modules.logging.annotation.Log)") public void logPointcut() { // 该方法无方法体,主要为了让同类中其他方法使用此切入点 } - /** + */ +/** * 配置环绕通知,使用在方法logPointcut()上注册的切入点 * * @param joinPoint join point for advice - */ + *//* + @Around("logPointcut()") public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable { ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); @@ -104,9 +110,11 @@ public class LogAspect { return result; } - /** + */ +/** * 根据方法和传入的参数获取请求参数 - */ + *//* + private String getParameter(Method method, Object[] args) { List argList = new ArrayList<>(); Parameter[] parameters = method.getParameters(); @@ -134,12 +142,14 @@ public class LogAspect { return argList.size() == 1 ? JSONUtil.toJsonStr(argList.get(0)) : JSONUtil.toJsonStr(argList); } - /** + */ +/** * 配置异常通知 * * @param joinPoint join point for advice * @param e exception - */ + *//* + @AfterThrowing(pointcut = "logPointcut()", throwing = "e") public void logAfterThrowing(JoinPoint joinPoint, Throwable e) { Log log = new Log("ERROR",System.currentTimeMillis() - currentTime.get()); @@ -157,3 +167,4 @@ public class LogAspect { } } } +*/ diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/domain/Log.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/domain/Log.java index 3d828df..cd0afaf 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/domain/Log.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/domain/Log.java @@ -19,7 +19,6 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import javax.persistence.*; import java.io.Serializable; import java.util.Date; @@ -27,16 +26,11 @@ import java.util.Date; * @author Zheng Jie * @date 2018-11-24 */ -@Entity @Getter @Setter -@Table(name = "sys_log") + @NoArgsConstructor public class Log implements Serializable { - - @Id - @Column(name = "log_id") - @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; /** 操作用户 */ diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/repository/LogRepository.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/repository/LogRepository.java deleted file mode 100644 index fae4022..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/repository/LogRepository.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.logging.repository; - -import org.nl.modules.logging.domain.Log; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; -import org.springframework.stereotype.Repository; - -/** - * @author Zheng Jie - * @date 2018-11-24 - */ -@Repository -public interface LogRepository extends JpaRepository, JpaSpecificationExecutor { - - /** - * 根据日志类型删除信息 - * @param logType 日志类型 - */ - @Modifying - @Query(value = "delete from sys_log where log_type = ?1", nativeQuery = true) - void deleteByLogType(String logType); -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/rest/LogController.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/rest/LogController.java deleted file mode 100644 index 27e5d2d..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/rest/LogController.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.logging.rest; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.RequiredArgsConstructor; -import org.nl.modules.common.utils.SecurityUtils; -import org.nl.modules.logging.annotation.Log; -import org.nl.modules.logging.service.LogService; -import org.nl.modules.logging.service.dto.LogQueryCriteria; -import org.springframework.data.domain.Pageable; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -/** - * @author Zheng Jie - * @date 2018-11-24 - */ -@RestController -@RequiredArgsConstructor -@RequestMapping("/api/logs") -@Api(tags = "系统:日志管理") -public class LogController { - - private final LogService logService; - @GetMapping - @ApiOperation("日志查询") - //@SaCheckPermission("@el.check()") - public ResponseEntity query(LogQueryCriteria criteria, Pageable pageable){ - criteria.setLogType("INFO"); - return new ResponseEntity<>(logService.queryAll(criteria,pageable), HttpStatus.OK); - } - - @GetMapping(value = "/user") - // @ApiOperation("用户日志查询") - public ResponseEntity queryUserLog(LogQueryCriteria criteria, Pageable pageable){ - criteria.setLogType("INFO"); - criteria.setBlurry(SecurityUtils.getCurrentUsername()); - return new ResponseEntity<>(logService.queryAllByUser(criteria,pageable), HttpStatus.OK); - } - - @GetMapping(value = "/error") - @ApiOperation("错误日志查询") - // @SaCheckPermission("@el.check()") - public ResponseEntity queryErrorLog(LogQueryCriteria criteria, Pageable pageable){ - criteria.setLogType("ERROR"); - return new ResponseEntity<>(logService.queryAll(criteria,pageable), HttpStatus.OK); - } - - @GetMapping(value = "/error/{id}") - @ApiOperation("日志异常详情查询") - // @SaCheckPermission("@el.check()") - public ResponseEntity queryErrorLogs(@PathVariable Long id){ - return new ResponseEntity<>(logService.findByErrDetail(id), HttpStatus.OK); - } - @DeleteMapping(value = "/del/error") - @Log("删除所有ERROR日志") - @ApiOperation("删除所有ERROR日志") - // @SaCheckPermission("@el.check()") - public ResponseEntity delAllErrorLog(){ - logService.delAllByError(); - return new ResponseEntity<>(HttpStatus.OK); - } - - @DeleteMapping(value = "/del/info") - @Log("删除所有INFO日志") - @ApiOperation("删除所有INFO日志") - // @SaCheckPermission("@el.check()") - public ResponseEntity delAllInfoLog(){ - logService.delAllByInfo(); - return new ResponseEntity<>(HttpStatus.OK); - } -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/service/LogService.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/service/LogService.java deleted file mode 100644 index e9fadd0..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/service/LogService.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.logging.service; - -import org.aspectj.lang.ProceedingJoinPoint; -import org.nl.modules.logging.domain.Log; -import org.nl.modules.logging.service.dto.LogQueryCriteria; -import org.springframework.data.domain.Pageable; -import org.springframework.scheduling.annotation.Async; - -import java.util.List; - -/** - * @author Zheng Jie - * @date 2018-11-24 - */ -public interface LogService { - - /** - * 分页查询 - * @param criteria 查询条件 - * @param pageable 分页参数 - * @return / - */ - Object queryAll(LogQueryCriteria criteria, Pageable pageable); - - /** - * 查询全部数据 - * @param criteria 查询条件 - * @return / - */ - List queryAll(LogQueryCriteria criteria); - - /** - * 查询用户日志 - * @param criteria 查询条件 - * @param pageable 分页参数 - * @return - - */ - Object queryAllByUser(LogQueryCriteria criteria, Pageable pageable); - - /** - * 保存日志数据 - * @param username 用户 - * @param browser 浏览器 - * @param ip 请求IP - * @param joinPoint / - * @param log 日志实体 - */ - @Async - void save(String username, String browser, String ip, ProceedingJoinPoint joinPoint, Log log); - - /** - * 查询异常详情 - * @param id 日志ID - * @return Object - */ - Object findByErrDetail(Long id); - - /** - * 删除所有错误日志 - */ - void delAllByError(); - - /** - * 删除所有INFO日志 - */ - void delAllByInfo(); -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/service/dto/LogErrorDTO.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/service/dto/LogErrorDTO.java deleted file mode 100644 index fdaa7c7..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/service/dto/LogErrorDTO.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.logging.service.dto; - -import lombok.Data; - -import java.io.Serializable; -import java.util.Date; - -/** -* @author Zheng Jie -* @date 2019-5-22 -*/ -@Data -public class LogErrorDTO implements Serializable { - - private Long id; - - private String username; - - private String description; - - private String method; - - private String params; - - private String browser; - - private String requestIp; - - private String address; - - private Date createTime; -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/service/dto/LogQueryCriteria.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/service/dto/LogQueryCriteria.java deleted file mode 100644 index 79ae492..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/service/dto/LogQueryCriteria.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.logging.service.dto; - -import lombok.Data; -import org.nl.modules.common.annotation.Query; - -import java.util.Date; -import java.util.List; - -/** - * 日志查询类 - * @author Zheng Jie - * @date 2019-6-4 09:23:07 - */ -@Data -public class LogQueryCriteria { - - @Query(blurry = "username,description,address,requestIp,method,params") - private String blurry; - - @Query - private String logType; - - @Query(type = Query.Type.BETWEEN) - private List createTime; -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/service/dto/LogSmallDTO.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/service/dto/LogSmallDTO.java deleted file mode 100644 index 92ec542..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/service/dto/LogSmallDTO.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.logging.service.dto; - -import lombok.Data; - -import java.io.Serializable; -import java.util.Date; - -/** - * @author Zheng Jie - * @date 2019-5-22 - */ -@Data -public class LogSmallDTO implements Serializable { - - private String description; - - private String requestIp; - - private Long time; - - private String address; - - private String browser; - - private Date createTime; -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/service/impl/LogServiceImpl.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/service/impl/LogServiceImpl.java deleted file mode 100644 index caaffdd..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/service/impl/LogServiceImpl.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.logging.service.impl; - -import cn.hutool.core.lang.Dict; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; -import cn.hutool.json.JSONUtil; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.reflect.MethodSignature; -import org.nl.modules.common.utils.PageUtil; -import org.nl.modules.common.utils.QueryHelp; -import org.nl.modules.common.utils.StringUtils; -import org.nl.modules.common.utils.ValidationUtil; -import org.nl.modules.logging.domain.Log; -import org.nl.modules.logging.repository.LogRepository; -import org.nl.modules.logging.service.LogService; -import org.nl.modules.logging.service.dto.LogQueryCriteria; -import org.nl.modules.logging.service.mapstruct.LogErrorMapper; -import org.nl.modules.logging.service.mapstruct.LogSmallMapper; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; - -import java.lang.reflect.Method; -import java.lang.reflect.Parameter; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @author Zheng Jie - * @date 2018-11-24 - */ -@Service -@RequiredArgsConstructor -@Slf4j -public class LogServiceImpl implements LogService { - private final LogRepository logRepository; - private final LogErrorMapper logErrorMapper; - private final LogSmallMapper logSmallMapper; - - @Override - public Object queryAll(LogQueryCriteria criteria, Pageable pageable) { - Page page = logRepository.findAll(((root, criteriaQuery, cb) -> QueryHelp.getPredicate(root, criteria, cb)), pageable); - String status = "ERROR"; - if (status.equals(criteria.getLogType())) { - return PageUtil.toPage(page.map(logErrorMapper::toDto)); - } - return page; - } - - @Override - public List queryAll(LogQueryCriteria criteria) { - return logRepository.findAll(((root, criteriaQuery, cb) -> QueryHelp.getPredicate(root, criteria, cb))); - } - - @Override - public Object queryAllByUser(LogQueryCriteria criteria, Pageable pageable) { - Page page = logRepository.findAll(((root, criteriaQuery, cb) -> QueryHelp.getPredicate(root, criteria, cb)), pageable); - return PageUtil.toPage(page.map(logSmallMapper::toDto)); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void save(String username, String browser, String ip, ProceedingJoinPoint joinPoint, Log logDto) { - - MethodSignature signature = (MethodSignature) joinPoint.getSignature(); - Method method = signature.getMethod(); - org.nl.modules.logging.annotation.Log aopLog = method.getAnnotation(org.nl.modules.logging.annotation.Log.class); - - // 方法路径 - String methodName = joinPoint.getTarget().getClass().getName() + "." + signature.getName() + "()"; - - // 描述 - if (logDto != null) { - logDto.setDescription(aopLog.value()); - } - assert logDto != null; - logDto.setRequestIp(ip); - - logDto.setAddress(StringUtils.getCityInfo(logDto.getRequestIp())); - logDto.setMethod(methodName); - logDto.setUsername(username); - logDto.setParams(getParameter(method, joinPoint.getArgs())); - logDto.setBrowser(browser); - logRepository.save(logDto); - } - - /** - * 根据方法和传入的参数获取请求参数 - */ - private String getParameter(Method method, Object[] args) { - List argList = new ArrayList<>(); - Parameter[] parameters = method.getParameters(); - for (int i = 0; i < parameters.length; i++) { - //将RequestBody注解修饰的参数作为请求参数 - RequestBody requestBody = parameters[i].getAnnotation(RequestBody.class); - if (requestBody != null) { - argList.add(args[i]); - } - //将RequestParam注解修饰的参数作为请求参数 - RequestParam requestParam = parameters[i].getAnnotation(RequestParam.class); - if (requestParam != null) { - Map map = new HashMap<>(); - String key = parameters[i].getName(); - if (!StrUtil.isEmpty(requestParam.value())) { - key = requestParam.value(); - } - map.put(key, args[i]); - argList.add(map); - } - } - if (argList.size() == 0) { - return ""; - } - return argList.size() == 1 ? JSONUtil.toJsonStr(argList.get(0)) : JSONUtil.toJsonStr(argList); - } - - @Override - public Object findByErrDetail(Long id) { - Log log = logRepository.findById(id).orElseGet(Log::new); - ValidationUtil.isNull(log.getId(), "Log", "id", id); - byte[] details = log.getExceptionDetail(); - return Dict.create().set("exception", new String(ObjectUtil.isNotNull(details) ? details : "".getBytes())); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void delAllByError() { - logRepository.deleteByLogType("ERROR"); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void delAllByInfo() { - logRepository.deleteByLogType("INFO"); - } -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/service/mapstruct/LogErrorMapper.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/service/mapstruct/LogErrorMapper.java deleted file mode 100644 index 6be8206..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/service/mapstruct/LogErrorMapper.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.logging.service.mapstruct; - -import org.mapstruct.Mapper; -import org.mapstruct.ReportingPolicy; -import org.nl.modules.common.base.BaseMapper; -import org.nl.modules.logging.domain.Log; -import org.nl.modules.logging.service.dto.LogErrorDTO; - -/** - * @author Zheng Jie - * @date 2019-5-22 - */ -@Mapper(componentModel = "spring",unmappedTargetPolicy = ReportingPolicy.IGNORE) -public interface LogErrorMapper extends BaseMapper { - -} \ No newline at end of file diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/service/mapstruct/LogSmallMapper.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/service/mapstruct/LogSmallMapper.java deleted file mode 100644 index 64f0a3e..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/logging/service/mapstruct/LogSmallMapper.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.logging.service.mapstruct; - -import org.mapstruct.Mapper; -import org.mapstruct.ReportingPolicy; -import org.nl.modules.common.base.BaseMapper; -import org.nl.modules.logging.domain.Log; -import org.nl.modules.logging.service.dto.LogSmallDTO; - -/** - * @author Zheng Jie - * @date 2019-5-22 - */ -@Mapper(componentModel = "spring",unmappedTargetPolicy = ReportingPolicy.IGNORE) -public interface LogSmallMapper extends BaseMapper { - -} \ No newline at end of file diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/config/JobRunner.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/config/JobRunner.java deleted file mode 100644 index 85f1b8b..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/config/JobRunner.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.quartz.config; - -import lombok.RequiredArgsConstructor; -import org.nl.modules.quartz.domain.QuartzJob; -import org.nl.modules.quartz.repository.QuartzJobRepository; -import org.nl.modules.quartz.utils.QuartzManage; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.ApplicationArguments; -import org.springframework.boot.ApplicationRunner; -import org.springframework.core.annotation.Order; -import org.springframework.stereotype.Component; - -import java.util.List; - -/** - * @author Zheng Jie - * @date 2019-01-07 - */ -@Component -@RequiredArgsConstructor -@Order(100) -public class JobRunner implements ApplicationRunner { - private static final Logger log = LoggerFactory.getLogger(JobRunner.class); - private final QuartzJobRepository quartzJobRepository; - private final QuartzManage quartzManage; - - /** - * 项目启动时重新激活启用的定时任务 - * - * @param applicationArguments / - */ - @Override - public void run(ApplicationArguments applicationArguments) { - log.info("--------------------注入定时任务---------------------"); - List quartzJobs = quartzJobRepository.findByIsPauseIsFalse(); - quartzJobs.forEach(quartzManage::addJob); - log.info("--------------------定时任务注入完成---------------------"); - } -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/config/QuartzConfig.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/config/QuartzConfig.java deleted file mode 100644 index 27baea9..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/config/QuartzConfig.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.quartz.config; - -import org.quartz.Scheduler; -import org.quartz.spi.TriggerFiredBundle; -import org.springframework.beans.factory.config.AutowireCapableBeanFactory; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.scheduling.quartz.AdaptableJobFactory; -import org.springframework.scheduling.quartz.SchedulerFactoryBean; -import org.springframework.stereotype.Component; - -/** - * 定时任务配置 - * @author / - * @date 2019-01-07 - */ -@Configuration -public class QuartzConfig { - - /** - * 解决Job中注入Spring Bean为null的问题 - */ - @Component("quartzJobFactory") - public static class QuartzJobFactory extends AdaptableJobFactory { - - private final AutowireCapableBeanFactory capableBeanFactory; - - public QuartzJobFactory(AutowireCapableBeanFactory capableBeanFactory) { - this.capableBeanFactory = capableBeanFactory; - } - - @Override - protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception { - - //调用父类的方法 - Object jobInstance = super.createJobInstance(bundle); - capableBeanFactory.autowireBean(jobInstance); - return jobInstance; - } - } - - /** - * 注入scheduler到spring - * @param quartzJobFactory / - * @return Scheduler - * @throws Exception / - */ - @Bean(name = "scheduler") - public Scheduler scheduler(QuartzJobFactory quartzJobFactory) throws Exception { - SchedulerFactoryBean factoryBean=new SchedulerFactoryBean(); - factoryBean.setJobFactory(quartzJobFactory); - factoryBean.afterPropertiesSet(); - Scheduler scheduler=factoryBean.getScheduler(); - scheduler.start(); - return scheduler; - } -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/domain/QuartzJob.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/domain/QuartzJob.java deleted file mode 100644 index bce1604..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/domain/QuartzJob.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.quartz.domain; - -import io.swagger.annotations.ApiModelProperty; -import lombok.Getter; -import lombok.Setter; -import org.nl.modules.common.base.BaseEntity; - -import javax.persistence.*; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; -import java.io.Serializable; - -/** - * @author Zheng Jie - * @date 2019-01-07 - */ -@Getter -@Setter -@Entity -@Table(name = "sys_quartz_job") -public class QuartzJob extends BaseEntity implements Serializable { - - public static final String JOB_KEY = "JOB_KEY"; - - @Id - @Column(name = "job_id") - @NotNull(groups = {Update.class}) - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @Transient - @ApiModelProperty(value = "用于子任务唯一标识", hidden = true) - private String uuid; - - @ApiModelProperty(value = "定时器名称") - private String jobName; - - @NotBlank - @ApiModelProperty(value = "Bean名称") - private String beanName; - - @NotBlank - @ApiModelProperty(value = "方法名称") - private String methodName; - - @ApiModelProperty(value = "参数") - private String params; - - @NotBlank - @ApiModelProperty(value = "cron表达式") - private String cronExpression; - - @ApiModelProperty(value = "状态,暂时或启动") - private Boolean isPause = false; - - @ApiModelProperty(value = "负责人") - private String personInCharge; - - @ApiModelProperty(value = "报警邮箱") - private String email; - - @ApiModelProperty(value = "子任务") - private String subTask; - - @ApiModelProperty(value = "失败后暂停") - private Boolean pauseAfterFailure; - - @NotBlank - @ApiModelProperty(value = "备注") - private String description; -} \ No newline at end of file diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/domain/QuartzLog.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/domain/QuartzLog.java deleted file mode 100644 index 7a42a71..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/domain/QuartzLog.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.quartz.domain; - -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; - -import javax.persistence.*; -import java.io.Serializable; -import java.util.Date; - -/** - * @author Zheng Jie - * @date 2019-01-07 - */ -@Entity -@Data -@Table(name = "sys_quartz_log") -public class QuartzLog implements Serializable { - - @Id - @Column(name = "log_id") - @ApiModelProperty(value = "ID", hidden = true) - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @ApiModelProperty(value = "任务名称", hidden = true) - private String jobName; - - @ApiModelProperty(value = "bean名称", hidden = true) - private String beanName; - - @ApiModelProperty(value = "方法名称", hidden = true) - private String methodName; - - @ApiModelProperty(value = "参数", hidden = true) - private String params; - - @ApiModelProperty(value = "cron表达式", hidden = true) - private String cronExpression; - - @ApiModelProperty(value = "状态", hidden = true) - private Boolean isSuccess; - - @ApiModelProperty(value = "异常详情", hidden = true) - private String exceptionDetail; - - @ApiModelProperty(value = "执行耗时", hidden = true) - private Long time; - - - @ApiModelProperty(value = "创建时间", hidden = true) - private Date createTime; -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/repository/QuartzJobRepository.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/repository/QuartzJobRepository.java deleted file mode 100644 index a63fcf2..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/repository/QuartzJobRepository.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.quartz.repository; - -import org.nl.modules.quartz.domain.QuartzJob; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; - -import java.util.List; - -/** - * @author Zheng Jie - * @date 2019-01-07 - */ -public interface QuartzJobRepository extends JpaRepository, JpaSpecificationExecutor { - - /** - * 查询启用的任务 - * @return List - */ - List findByIsPauseIsFalse(); -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/repository/QuartzLogRepository.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/repository/QuartzLogRepository.java deleted file mode 100644 index 54c5101..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/repository/QuartzLogRepository.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.quartz.repository; - -import org.nl.modules.quartz.domain.QuartzLog; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; - -/** - * @author Zheng Jie - * @date 2019-01-07 - */ -public interface QuartzLogRepository extends JpaRepository, JpaSpecificationExecutor { - -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/rest/QuartzJobController.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/rest/QuartzJobController.java deleted file mode 100644 index f84511b..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/rest/QuartzJobController.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.quartz.rest; - -import cn.dev33.satoken.annotation.SaCheckPermission; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.nl.modules.common.exception.BadRequestException; -import org.nl.modules.logging.annotation.Log; -import org.nl.modules.quartz.domain.QuartzJob; -import org.nl.modules.quartz.service.QuartzJobService; -import org.nl.modules.quartz.service.dto.JobQueryCriteria; -import org.springframework.data.domain.Pageable; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import java.util.Set; - -/** - * @author Zheng Jie - * @date 2019-01-07 - */ -@Slf4j -@RestController -@RequiredArgsConstructor -@RequestMapping("/api/jobs") -@Api(tags = "系统:定时任务管理") -public class QuartzJobController { - - private static final String ENTITY_NAME = "quartzJob"; - private final QuartzJobService quartzJobService; - - @ApiOperation("查询定时任务") - @GetMapping - @SaCheckPermission("timing:list") - public ResponseEntity query(JobQueryCriteria criteria, Pageable pageable) { - return new ResponseEntity<>(quartzJobService.queryAll(criteria, pageable), HttpStatus.OK); - } - - @ApiOperation("查询任务执行日志") - @GetMapping(value = "/logs") - @SaCheckPermission("timing:list") - public ResponseEntity queryJobLog(JobQueryCriteria criteria, Pageable pageable) { - return new ResponseEntity<>(quartzJobService.queryAllLog(criteria, pageable), HttpStatus.OK); - } - - @Log("新增定时任务") - @ApiOperation("新增定时任务") - @PostMapping - @SaCheckPermission("timing:add") - public ResponseEntity create(@Validated @RequestBody QuartzJob resources) { - if (resources.getId() != null) { - throw new BadRequestException("A new " + ENTITY_NAME + " cannot already have an ID"); - } - quartzJobService.create(resources); - return new ResponseEntity<>(HttpStatus.CREATED); - } - - @Log("修改定时任务") - @ApiOperation("修改定时任务") - @PutMapping - @SaCheckPermission("timing:edit") - public ResponseEntity update(@Validated(QuartzJob.Update.class) @RequestBody QuartzJob resources) { - quartzJobService.update(resources); - return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } - - @Log("更改定时任务状态") - @ApiOperation("更改定时任务状态") - @PutMapping(value = "/{id}") - @SaCheckPermission("timing:edit") - public ResponseEntity update(@PathVariable Long id) { - quartzJobService.updateIsPause(quartzJobService.findById(id)); - return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } - - @Log("执行定时任务") - @ApiOperation("执行定时任务") - @PutMapping(value = "/exec/{id}") - @SaCheckPermission("timing:edit") - public ResponseEntity execution(@PathVariable Long id) { - quartzJobService.execution(quartzJobService.findById(id)); - return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } - - @Log("删除定时任务") - @ApiOperation("删除定时任务") - @DeleteMapping - @SaCheckPermission("timing:del") - public ResponseEntity delete(@RequestBody Set ids) { - quartzJobService.delete(ids); - return new ResponseEntity<>(HttpStatus.OK); - } -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/service/QuartzJobService.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/service/QuartzJobService.java deleted file mode 100644 index 74ec177..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/service/QuartzJobService.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.quartz.service; - -import org.nl.modules.quartz.domain.QuartzJob; -import org.nl.modules.quartz.domain.QuartzLog; -import org.nl.modules.quartz.service.dto.JobQueryCriteria; -import org.springframework.data.domain.Pageable; - -import java.util.List; -import java.util.Set; - -/** - * @author Zheng Jie - * @date 2019-01-07 - */ -public interface QuartzJobService { - - /** - * 分页查询 - * - * @param criteria 条件 - * @param pageable 分页参数 - * @return / - */ - Object queryAll(JobQueryCriteria criteria, Pageable pageable); - - /** - * 查询全部 - * - * @param criteria 条件 - * @return / - */ - List queryAll(JobQueryCriteria criteria); - - /** - * 分页查询日志 - * - * @param criteria 条件 - * @param pageable 分页参数 - * @return / - */ - Object queryAllLog(JobQueryCriteria criteria, Pageable pageable); - - /** - * 查询全部 - * - * @param criteria 条件 - * @return / - */ - List queryAllLog(JobQueryCriteria criteria); - - /** - * 创建 - * - * @param resources / - */ - void create(QuartzJob resources); - - /** - * 编辑 - * - * @param resources / - */ - void update(QuartzJob resources); - - /** - * 删除任务 - * - * @param ids / - */ - void delete(Set ids); - - /** - * 根据ID查询 - * - * @param id ID - * @return / - */ - QuartzJob findById(Long id); - - /** - * 更改定时任务状态 - * - * @param quartzJob / - */ - void updateIsPause(QuartzJob quartzJob); - - /** - * 立即执行定时任务 - * - * @param quartzJob / - */ - void execution(QuartzJob quartzJob); - - - /** - * 执行子任务 - * - * @param tasks / - * @throws InterruptedException / - */ - void executionSubJob(String[] tasks) throws InterruptedException; -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/service/dto/JobQueryCriteria.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/service/dto/JobQueryCriteria.java deleted file mode 100644 index c6fbcf4..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/service/dto/JobQueryCriteria.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.quartz.service.dto; - -import lombok.Data; -import org.nl.modules.common.annotation.Query; - -import java.util.Date; -import java.util.List; - -/** - * @author Zheng Jie - * @date 2019-6-4 10:33:02 - */ -@Data -public class JobQueryCriteria { - - @Query(type = Query.Type.INNER_LIKE) - private String jobName; - - @Query - private Boolean isSuccess; - - @Query(type = Query.Type.BETWEEN) - private List createTime; -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/service/impl/QuartzJobServiceImpl.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/service/impl/QuartzJobServiceImpl.java deleted file mode 100644 index edc15b6..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/service/impl/QuartzJobServiceImpl.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.quartz.service.impl; - -import cn.hutool.core.util.IdUtil; -import cn.hutool.core.util.StrUtil; -import lombok.RequiredArgsConstructor; -import org.nl.modules.common.exception.BadRequestException; -import org.nl.modules.common.utils.PageUtil; -import org.nl.modules.common.utils.QueryHelp; -import org.nl.modules.common.utils.RedisUtils; -import org.nl.modules.common.utils.ValidationUtil; -import org.nl.modules.quartz.domain.QuartzJob; -import org.nl.modules.quartz.domain.QuartzLog; -import org.nl.modules.quartz.repository.QuartzJobRepository; -import org.nl.modules.quartz.repository.QuartzLogRepository; -import org.nl.modules.quartz.service.QuartzJobService; -import org.nl.modules.quartz.service.dto.JobQueryCriteria; -import org.nl.modules.quartz.utils.QuartzManage; -import org.quartz.CronExpression; -import org.springframework.data.domain.Pageable; -import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.Arrays; -import java.util.List; -import java.util.Set; - -/** - * @author Zheng Jie - * @date 2019-01-07 - */ -@RequiredArgsConstructor -@Service(value = "quartzJobService") -public class QuartzJobServiceImpl implements QuartzJobService { - - private final QuartzJobRepository quartzJobRepository; - private final QuartzLogRepository quartzLogRepository; - private final QuartzManage quartzManage; - private final RedisUtils redisUtils; - - @Override - public Object queryAll(JobQueryCriteria criteria, Pageable pageable) { - return PageUtil.toPage(quartzJobRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable)); - } - - @Override - public Object queryAllLog(JobQueryCriteria criteria, Pageable pageable) { - return PageUtil.toPage(quartzLogRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable)); - } - - @Override - public List queryAll(JobQueryCriteria criteria) { - return quartzJobRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)); - } - - @Override - public List queryAllLog(JobQueryCriteria criteria) { - return quartzLogRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)); - } - - @Override - public QuartzJob findById(Long id) { - QuartzJob quartzJob = quartzJobRepository.findById(id).orElseGet(QuartzJob::new); - ValidationUtil.isNull(quartzJob.getId(), "QuartzJob", "id", id); - return quartzJob; - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void create(QuartzJob resources) { - if (!CronExpression.isValidExpression(resources.getCronExpression())) { - throw new BadRequestException("cron表达式格式错误"); - } - resources = quartzJobRepository.save(resources); - quartzManage.addJob(resources); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void update(QuartzJob resources) { - if (!CronExpression.isValidExpression(resources.getCronExpression())) { - throw new BadRequestException("cron表达式格式错误"); - } - if (StrUtil.isNotEmpty(resources.getSubTask())) { - List tasks = Arrays.asList(resources.getSubTask().split("[,,]")); - if (tasks.contains(resources.getId().toString())) { - throw new BadRequestException("子任务中不能添加当前任务ID"); - } - } - resources = quartzJobRepository.save(resources); - quartzManage.updateJobCron(resources); - } - - @Override - public void updateIsPause(QuartzJob quartzJob) { - if (quartzJob.getIsPause()) { - quartzManage.resumeJob(quartzJob); - quartzJob.setIsPause(false); - } else { - quartzManage.pauseJob(quartzJob); - quartzJob.setIsPause(true); - } - quartzJobRepository.save(quartzJob); - } - - @Override - public void execution(QuartzJob quartzJob) { - quartzManage.runJobNow(quartzJob); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void delete(Set ids) { - for (Long id : ids) { - QuartzJob quartzJob = findById(id); - quartzManage.deleteJob(quartzJob); - quartzJobRepository.delete(quartzJob); - } - } - - @Async - @Override - @Transactional(rollbackFor = Exception.class) - public void executionSubJob(String[] tasks) throws InterruptedException { - for (String id : tasks) { - QuartzJob quartzJob = findById(Long.parseLong(id)); - // 执行任务 - String uuid = IdUtil.simpleUUID(); - quartzJob.setUuid(uuid); - // 执行任务 - execution(quartzJob); - // 获取执行状态,如果执行失败则停止后面的子任务执行 - Boolean result = (Boolean) redisUtils.get(uuid); - while (result == null) { - // 休眠5秒,再次获取子任务执行情况 - Thread.sleep(5000); - result = (Boolean) redisUtils.get(uuid); - } - if (!result) { - redisUtils.del(uuid); - break; - } - } - } - -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/task/TestTask.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/task/TestTask.java deleted file mode 100644 index 0d67ce0..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/task/TestTask.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.quartz.task; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; - -/** - * 测试用 - * @author Zheng Jie - * @date 2019-01-08 - */ -@Slf4j -@Component -public class TestTask { - - public void run(){ - log.info("run 执行成功"); - } - - public void run1(String str){ - log.info("run1 执行成功,参数为: {}" + str); - } - - public void run2(){ - log.info("run2 执行成功"); - } -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/utils/ExecutionJob.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/utils/ExecutionJob.java deleted file mode 100644 index ee4f685..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/utils/ExecutionJob.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.quartz.utils; - -import cn.hutool.core.util.StrUtil; -import lombok.extern.slf4j.Slf4j; -import org.nl.config.thread.ThreadPoolExecutorUtil; -import org.nl.modules.common.utils.RedisUtils; -import org.nl.modules.common.utils.ThrowableUtil; -import org.nl.modules.quartz.domain.QuartzJob; -import org.nl.modules.quartz.domain.QuartzLog; -import org.nl.modules.quartz.repository.QuartzLogRepository; -import org.nl.modules.quartz.service.QuartzJobService; -import org.nl.modules.wql.util.SpringContextHolder; -import org.quartz.JobExecutionContext; -import org.springframework.scheduling.annotation.Async; -import org.springframework.scheduling.quartz.QuartzJobBean; - -import java.util.concurrent.Future; -import java.util.concurrent.ThreadPoolExecutor; - -/** - * 参考人人开源,https://gitee.com/renrenio/renren-security - * - * @author / - * @date 2019-01-07 - */ -@Async -@SuppressWarnings({"unchecked", "all"}) -@Slf4j -public class ExecutionJob extends QuartzJobBean { - - /** - * 该处仅供参考 - */ - private final static ThreadPoolExecutor EXECUTOR = ThreadPoolExecutorUtil.getPoll(); - - @Override - public void executeInternal(JobExecutionContext context) { - QuartzJob quartzJob = (QuartzJob) context.getMergedJobDataMap().get(QuartzJob.JOB_KEY); - // 获取spring bean - QuartzLogRepository quartzLogRepository = SpringContextHolder.getBean(QuartzLogRepository.class); - QuartzJobService quartzJobService = SpringContextHolder.getBean(QuartzJobService.class); - RedisUtils redisUtils = SpringContextHolder.getBean(RedisUtils.class); - - String uuid = quartzJob.getUuid(); - - QuartzLog logDto = new QuartzLog(); - logDto.setJobName(quartzJob.getJobName()); - logDto.setBeanName(quartzJob.getBeanName()); - logDto.setMethodName(quartzJob.getMethodName()); - logDto.setParams(quartzJob.getParams()); - long startTime = System.currentTimeMillis(); - logDto.setCronExpression(quartzJob.getCronExpression()); - try { - // 执行任务 - System.out.println("--------------------------------------------------------------"); - System.out.println("任务开始执行,任务名称:" + quartzJob.getJobName()); - QuartzRunnable task = new QuartzRunnable(quartzJob.getBeanName(), quartzJob.getMethodName(), - quartzJob.getParams()); - Future future = EXECUTOR.submit(task); - future.get(); - long times = System.currentTimeMillis() - startTime; - logDto.setTime(times); - if (StrUtil.isNotEmpty(uuid)) { - redisUtils.set(uuid, true); - } - // 任务状态 - logDto.setIsSuccess(true); - System.out.println("任务执行完毕,任务名称:" + quartzJob.getJobName() + ", 执行时间:" + times + "毫秒"); - System.out.println("--------------------------------------------------------------"); - // 判断是否存在子任务 - if (StrUtil.isNotEmpty(quartzJob.getSubTask())) { - String[] tasks = quartzJob.getSubTask().split("[,,]"); - // 执行子任务 - quartzJobService.executionSubJob(tasks); - } - } catch (Exception e) { - if (StrUtil.isNotEmpty(uuid)) { - redisUtils.set(uuid, false); - } - System.out.println("任务执行失败,任务名称:" + quartzJob.getJobName()); - System.out.println("--------------------------------------------------------------"); - long times = System.currentTimeMillis() - startTime; - logDto.setTime(times); - // 任务状态 0:成功 1:失败 - logDto.setIsSuccess(false); - logDto.setExceptionDetail(ThrowableUtil.getStackTrace(e)); - // 任务如果失败了则暂停 - if (quartzJob.getPauseAfterFailure() != null && quartzJob.getPauseAfterFailure()) { - quartzJob.setIsPause(false); - //更新状态 - quartzJobService.updateIsPause(quartzJob); - } - //异常时候打印日志 - log.info(logDto.toString()); - quartzLogRepository.save(logDto); - } finally { - - } - } - -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/utils/QuartzManage.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/utils/QuartzManage.java deleted file mode 100644 index ac20ccf..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/utils/QuartzManage.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.quartz.utils; - -import lombok.extern.slf4j.Slf4j; -import org.nl.modules.common.exception.BadRequestException; -import org.nl.modules.quartz.domain.QuartzJob; -import org.quartz.*; -import org.quartz.impl.triggers.CronTriggerImpl; -import org.springframework.stereotype.Component; - -import javax.annotation.Resource; -import java.util.Date; - -import static org.quartz.TriggerBuilder.newTrigger; - -/** - * @author Zheng Jie - * @date 2019-01-07 - */ -@Slf4j -@Component -public class QuartzManage { - - private static final String JOB_NAME = "TASK_"; - - @Resource(name = "scheduler") - private Scheduler scheduler; - - public void addJob(QuartzJob quartzJob){ - try { - // 构建job信息 - JobDetail jobDetail = JobBuilder.newJob(ExecutionJob.class). - withIdentity(JOB_NAME + quartzJob.getId()).build(); - - //通过触发器名和cron 表达式创建 Trigger - Trigger cronTrigger = newTrigger() - .withIdentity(JOB_NAME + quartzJob.getId()) - .startNow() - .withSchedule(CronScheduleBuilder.cronSchedule(quartzJob.getCronExpression())) - .build(); - - cronTrigger.getJobDataMap().put(QuartzJob.JOB_KEY, quartzJob); - - //重置启动时间 - ((CronTriggerImpl)cronTrigger).setStartTime(new Date()); - - //执行定时任务 - scheduler.scheduleJob(jobDetail,cronTrigger); - - // 暂停任务 - if (quartzJob.getIsPause()) { - pauseJob(quartzJob); - } - } catch (Exception e){ - log.error("创建定时任务失败", e); - throw new BadRequestException("创建定时任务失败"); - } - } - - /** - * 更新job cron表达式 - * @param quartzJob / - */ - public void updateJobCron(QuartzJob quartzJob){ - try { - TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId()); - CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); - // 如果不存在则创建一个定时任务 - if(trigger == null){ - addJob(quartzJob); - trigger = (CronTrigger) scheduler.getTrigger(triggerKey); - } - CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(quartzJob.getCronExpression()); - trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build(); - //重置启动时间 - ((CronTriggerImpl)trigger).setStartTime(new Date()); - trigger.getJobDataMap().put(QuartzJob.JOB_KEY,quartzJob); - - scheduler.rescheduleJob(triggerKey, trigger); - // 暂停任务 - if (quartzJob.getIsPause()) { - pauseJob(quartzJob); - } - } catch (Exception e){ - log.error("更新定时任务失败", e); - throw new BadRequestException("更新定时任务失败"); - } - - } - - /** - * 删除一个job - * @param quartzJob / - */ - public void deleteJob(QuartzJob quartzJob){ - try { - JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId()); - scheduler.pauseJob(jobKey); - scheduler.deleteJob(jobKey); - } catch (Exception e){ - log.error("删除定时任务失败", e); - throw new BadRequestException("删除定时任务失败"); - } - } - - /** - * 恢复一个job - * @param quartzJob / - */ - public void resumeJob(QuartzJob quartzJob){ - try { - TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId()); - CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); - // 如果不存在则创建一个定时任务 - if(trigger == null) { - addJob(quartzJob); - } - JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId()); - scheduler.resumeJob(jobKey); - } catch (Exception e){ - log.error("恢复定时任务失败", e); - throw new BadRequestException("恢复定时任务失败"); - } - } - - /** - * 立即执行job - * @param quartzJob / - */ - public void runJobNow(QuartzJob quartzJob){ - try { - TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId()); - CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); - // 如果不存在则创建一个定时任务 - if(trigger == null) { - addJob(quartzJob); - } - JobDataMap dataMap = new JobDataMap(); - dataMap.put(QuartzJob.JOB_KEY, quartzJob); - JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId()); - scheduler.triggerJob(jobKey,dataMap); - } catch (Exception e){ - log.error("定时任务执行失败", e); - throw new BadRequestException("定时任务执行失败"); - } - } - - /** - * 暂停一个job - * @param quartzJob / - */ - public void pauseJob(QuartzJob quartzJob){ - try { - JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId()); - scheduler.pauseJob(jobKey); - } catch (Exception e){ - log.error("定时任务暂停失败", e); - throw new BadRequestException("定时任务暂停失败"); - } - } -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/utils/QuartzRunnable.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/utils/QuartzRunnable.java deleted file mode 100644 index e2ef49b..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/quartz/utils/QuartzRunnable.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.quartz.utils; - -import cn.hutool.core.util.StrUtil; -import lombok.extern.slf4j.Slf4j; -import org.nl.modules.wql.util.SpringContextHolder; -import org.springframework.util.ReflectionUtils; - -import java.lang.reflect.Method; -import java.util.concurrent.Callable; - -/** - * 执行定时任务 - * @author / - */ -@Slf4j -public class QuartzRunnable implements Callable { - - private final Object target; - private final Method method; - private final String params; - - QuartzRunnable(String beanName, String methodName, String params) - throws NoSuchMethodException, SecurityException { - this.target = SpringContextHolder.getBean(beanName); - this.params = params; - - if (StrUtil.isNotEmpty(params)) { - this.method = target.getClass().getDeclaredMethod(methodName, String.class); - } else { - this.method = target.getClass().getDeclaredMethod(methodName); - } - } - - @Override - public Object call() throws Exception { - ReflectionUtils.makeAccessible(method); - if (StrUtil.isNotEmpty(params)) { - method.invoke(target, params); - } else { - method.invoke(target); - } - return null; - } -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/Dept.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/Dept.java index 420b577..a4684fa 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/Dept.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/Dept.java @@ -19,9 +19,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; import lombok.Setter; -import org.nl.modules.common.base.BaseEntity; -import javax.persistence.*; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import java.io.Serializable; @@ -34,14 +32,9 @@ import java.util.Set; */ @Getter @Setter -@Entity -public class Dept extends BaseEntity implements Serializable { +public class Dept implements Serializable { + - @Id - @Column(name = "role_id") - @NotNull(groups = {Update.class}) - @GeneratedValue(strategy = GenerationType.IDENTITY) - @ApiModelProperty(value = "ID", hidden = true) private Long id; private Long dept_id; diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/Dict.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/Dict.java index 59839f0..d4f38c3 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/Dict.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/Dict.java @@ -19,10 +19,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import org.nl.modules.common.base.BaseEntity; -import javax.persistence.*; -import javax.validation.constraints.NotNull; import java.io.Serializable; /** @@ -30,13 +27,8 @@ import java.io.Serializable; * @date 2019-04-10 */ @Data -@Entity -public class Dict extends BaseEntity implements Serializable { +public class Dict implements Serializable { - @Id - @Column(name = "role_id") - @NotNull(groups = {Update.class}) - @GeneratedValue(strategy = GenerationType.IDENTITY) @ApiModelProperty(value = "ID", hidden = true) private Long id; // 字典标识 diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/DictDetail.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/DictDetail.java index 763271c..d9198c1 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/DictDetail.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/DictDetail.java @@ -18,27 +18,19 @@ package org.nl.modules.system.domain; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; import lombok.Setter; -import org.nl.modules.common.base.BaseEntity; -import javax.persistence.*; -import javax.validation.constraints.NotNull; import java.io.Serializable; /** * @author Zheng Jie * @date 2019-04-10 */ -@Entity @Getter @Setter -@Table(name="sys_dict_detail") -public class DictDetail extends BaseEntity implements Serializable { +public class DictDetail implements Serializable { + - @Id - @Column(name = "detail_id") - @NotNull(groups = Update.class) @ApiModelProperty(value = "ID", hidden = true) - @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private Dict dict; diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/Menu.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/Menu.java index c7510e6..23669f7 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/Menu.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/Menu.java @@ -19,10 +19,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; import lombok.Setter; -import org.nl.modules.common.base.BaseEntity; -import javax.persistence.*; -import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.Objects; import java.util.Set; @@ -31,28 +28,21 @@ import java.util.Set; * @author Zheng Jie * @date 2018-12-17 */ -@Entity @Getter @Setter -@Table(name = "sys_menu") -public class Menu extends BaseEntity implements Serializable { +public class Menu implements Serializable { + - @Id - @Column(name = "menu_id") - @NotNull(groups = {Update.class}) @ApiModelProperty(value = "ID", hidden = true) - @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @JsonIgnore - @ManyToMany(mappedBy = "menus") @ApiModelProperty(value = "菜单角色") private Set roles; @ApiModelProperty(value = "菜单标题") private String title; - @Column(name = "name") @ApiModelProperty(value = "菜单组件名称") private String componentName; @@ -74,13 +64,11 @@ public class Menu extends BaseEntity implements Serializable { @ApiModelProperty(value = "菜单图标") private String icon; - @Column(columnDefinition = "bit(1) default 0") @ApiModelProperty(value = "缓存") private Boolean cache; - @Column(columnDefinition = "bit(1) default 0") @ApiModelProperty(value = "是否隐藏") private Boolean hidden; diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/Param.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/Param.java deleted file mode 100644 index b40e2fa..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/Param.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.nl.modules.system.domain; - -import cn.hutool.core.bean.BeanUtil; -import cn.hutool.core.bean.copier.CopyOptions; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import org.nl.modules.common.base.BaseEntity; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import javax.validation.constraints.NotBlank; -import java.io.Serializable; - -/** - * @description / - * @author ldjun - * @date 2021-01-14 - **/ -@Entity -@Data -@Table(name="sys_param") -public class Param extends BaseEntity implements Serializable { - - @Id - @Column(name = "id") - @ApiModelProperty(value = "id") - private String id; - - @Column(name = "code",nullable = false) - @NotBlank - @ApiModelProperty(value = "code") - private String code; - - @Column(name = "name",nullable = false) - @NotBlank - @ApiModelProperty(value = "name") - private String name; - - @Column(name = "value",nullable = false) - @NotBlank - @ApiModelProperty(value = "value") - private String value; - - @Column(name = "remark") - @ApiModelProperty(value = "remark") - private String remark; - - @Column(name = "is_active",nullable = false) - @NotBlank - @ApiModelProperty(value = "is_active") - private String is_active; - - @Column(name = "is_delete",nullable = false) - @NotBlank - @ApiModelProperty(value = "is_delete") - private String is_delete; - - public void copy(Param source){ - BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); - } -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/Role.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/Role.java index ee94af9..b7733f1 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/Role.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/Role.java @@ -15,16 +15,11 @@ */ package org.nl.modules.system.domain; -import com.fasterxml.jackson.annotation.JsonIgnore; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; import lombok.Setter; -import org.nl.modules.common.base.BaseEntity; -import org.nl.modules.common.utils.enums.DataScopeEnum; -import javax.persistence.*; import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.Objects; import java.util.Set; @@ -36,24 +31,14 @@ import java.util.Set; */ @Getter @Setter -@Entity -@Table(name = "sys_role") -public class Role extends BaseEntity implements Serializable { +public class Role implements Serializable { + - @Id - @Column(name = "role_id") - @NotNull(groups = {Update.class}) - @GeneratedValue(strategy = GenerationType.IDENTITY) @ApiModelProperty(value = "ID", hidden = true) private Long id; - @Transient private Set users; - @ManyToMany - @JoinTable(name = "sys_roles_menus", - joinColumns = {@JoinColumn(name = "role_id",referencedColumnName = "role_id")}, - inverseJoinColumns = {@JoinColumn(name = "menu_id",referencedColumnName = "menu_id")}) @ApiModelProperty(value = "菜单", hidden = true) private Set menus; @@ -62,7 +47,6 @@ public class Role extends BaseEntity implements Serializable { @ApiModelProperty(value = "名称", hidden = true) private String name; - @Column(name = "level") @ApiModelProperty(value = "级别,数值越小,级别越大") private Integer level = 3; diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/User.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/User.java index 01f16be..7604568 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/User.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/User.java @@ -18,17 +18,10 @@ package org.nl.modules.system.domain; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; import lombok.Setter; -import org.hibernate.annotations.NotFound; -import org.hibernate.annotations.NotFoundAction; -import org.nl.modules.common.base.BaseEntity; -import javax.persistence.*; -import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.Date; -import java.util.Objects; -import java.util.Set; /** * @author Zheng Jie @@ -36,12 +29,9 @@ import java.util.Set; */ @Getter @Setter -@Entity -public class User extends BaseEntity implements Serializable { +public class User implements Serializable { + - @Id - @Column(name = "role_id") - @GeneratedValue(strategy = GenerationType.IDENTITY) @ApiModelProperty(value = "ID", hidden = true) private Long id; @@ -83,7 +73,6 @@ public class User extends BaseEntity implements Serializable { @ApiModelProperty(value = "是否为admin账号", hidden = true) private Boolean isAdmin = false; - @Column(name = "pwd_reset_time") @ApiModelProperty(value = "最后修改密码的时间", hidden = true) private Date pwdResetTime; diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/repository/DeptRepository.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/repository/DeptRepository.java deleted file mode 100644 index 65c58c8..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/repository/DeptRepository.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.system.repository; - -import org.nl.modules.system.domain.Dept; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; -import java.util.Set; - -/** -* @author Zheng Jie -* @date 2019-03-25 -*/ -public interface DeptRepository extends JpaRepository, JpaSpecificationExecutor { - - /** - * 根据 PID 查询 - * @param id pid - * @return / - */ - List findByPid(Long id); - - /** - * 获取顶级部门 - * @return / - */ - List findByPidIsNull(); - - /** - * 根据角色ID 查询 - * @param roleId 角色ID - * @return / - */ - @Query(value = "select d.* from sys_dept d, sys_roles_depts r where " + - "d.dept_id = r.dept_id and r.role_id = ?1", nativeQuery = true) - Set findByRoleId(Long roleId); - - /** - * 判断是否存在子节点 - * @param pid / - * @return / - */ - int countByPid(Long pid); - - /** - * 根据ID更新sub_count - * @param count / - * @param id / - */ - @Modifying - @Query(value = " update sys_dept set sub_count = ?1 where dept_id = ?2 ",nativeQuery = true) - void updateSubCntById(Integer count, Long id); -} \ No newline at end of file diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/repository/DictDetailRepository.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/repository/DictDetailRepository.java deleted file mode 100644 index 02c670e..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/repository/DictDetailRepository.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.system.repository; - -import org.nl.modules.system.domain.DictDetail; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; - -import java.util.List; - -/** -* @author Zheng Jie -* @date 2019-04-10 -*/ -public interface DictDetailRepository extends JpaRepository, JpaSpecificationExecutor { - - /** - * 根据字典名称查询 - * @param name / - * @return / - */ -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/repository/DictRepository.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/repository/DictRepository.java deleted file mode 100644 index 059278c..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/repository/DictRepository.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.system.repository; - -import org.nl.modules.system.domain.Dict; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; - -import java.util.List; -import java.util.Set; - -/** -* @author Zheng Jie -* @date 2019-04-10 -*/ -public interface DictRepository extends JpaRepository, JpaSpecificationExecutor { - - /** - * 删除 - * @param ids / - */ - void deleteByIdIn(Set ids); - - /** - * 查询 - * @param ids / - * @return / - */ - List findByIdIn(Set ids); -} \ No newline at end of file diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/repository/MenuRepository.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/repository/MenuRepository.java deleted file mode 100644 index 22d3e4b..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/repository/MenuRepository.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.system.repository; - -import org.nl.modules.system.domain.Menu; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; - -/** - * @author Zheng Jie - * @date 2018-12-17 - */ -public interface MenuRepository extends JpaRepository, JpaSpecificationExecutor { - - /** - * 根据菜单标题查询 - * - * @param title 菜单标题 - * @return / - */ - Menu findByTitle(String title); - - /** - * 根据组件名称查询 - * - * @param name 组件名称 - * @return / - */ - Menu findByComponentName(String name); - - /** - * 根据菜单的 PID 查询 - * - * @param pid / - * @return / - */ - List findByPid(long pid); - - /** - * 查询顶级菜单 - * - * @return / - */ - List findByPidIsNull(); - - /** - * 根据角色ID与菜单类型查询菜单 - * - * @param roleIds roleIDs - * @param type 类型 - * @return / - */ - @Query(value = "SELECT m.* FROM sys_menu m, sys_roles_menus r WHERE " + - "m.menu_id = r.menu_id and r.role_id IN ?1 AND type != ?2 order by m.menu_sort asc", nativeQuery = true) - LinkedHashSet findByRoleIdsAndTypeNot(Set roleIds, int type); - - /** - * 获取节点数量 - * - * @param id / - * @return / - */ - int countByPid(Long id); - - /** - * 更新节点数目 - * - * @param count / - * @param menuId / - */ - @Modifying - @Query(value = " update sys_menu set sub_count = ?1 where menu_id = ?2 ", nativeQuery = true) - void updateSubCntById(int count, Long menuId); -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/repository/ParamRepository.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/repository/ParamRepository.java deleted file mode 100644 index 619d3a1..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/repository/ParamRepository.java +++ /dev/null @@ -1,13 +0,0 @@ - -package org.nl.modules.system.repository; - -import org.nl.modules.system.domain.Param; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; - -/** -* @author ldjun -* @date 2021-01-13 -**/ -public interface ParamRepository extends JpaRepository, JpaSpecificationExecutor { -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/repository/RoleRepository.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/repository/RoleRepository.java deleted file mode 100644 index d199a64..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/repository/RoleRepository.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.system.repository; - -import org.nl.modules.system.domain.Role; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; -import java.util.Set; - -/** - * @author Zheng Jie - * @date 2018-12-03 - */ -public interface RoleRepository extends JpaRepository, JpaSpecificationExecutor { - - /** - * 根据名称查询 - * @param name / - * @return / - */ - Role findByName(String name); - - /** - * 删除多个角色 - * @param ids / - */ - void deleteAllByIdIn(Set ids); - - /** - * 根据用户ID查询 - * @param id 用户ID - * @return / - */ - @Query(value = "SELECT r.* FROM sys_role r, sys_users_roles u WHERE " + - "r.role_id = u.role_id AND u.user_id = ?1",nativeQuery = true) - List findByUserId(Long id); - - /** - * 解绑角色菜单 - * @param id 菜单ID - */ - @Modifying - @Query(value = "delete from sys_roles_menus where menu_id = ?1",nativeQuery = true) - void untiedMenu(Long id); - - /** - * 根据部门查询 - * @param deptIds / - * @return / - */ - @Query(value = "select count(1) from sys_role r, sys_roles_depts d where " + - "r.role_id = d.role_id and d.dept_id in ?1",nativeQuery = true) - int countByDepts(Set deptIds); - - /** - * 根据菜单Id查询 - * @param menuIds / - * @return / - */ - @Query(value = "SELECT r.* FROM sys_role r, sys_roles_menus m WHERE " + - "r.role_id = m.role_id AND m.menu_id in ?1",nativeQuery = true) - List findInMenuId(List menuIds); -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/repository/UserRepository.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/repository/UserRepository.java deleted file mode 100644 index cf873aa..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/repository/UserRepository.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.system.repository; - -import org.nl.modules.system.domain.User; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -import java.util.Date; -import java.util.List; -import java.util.Set; - -/** - * @author Zheng Jie - * @date 2018-11-22 - */ -public interface UserRepository extends JpaRepository, JpaSpecificationExecutor { - - /** - * 根据用户名查询 - * @param username 用户名 - * @return / - */ - User findByUsername(String username); - - /** - * 根据角色中的部门查询 - * @param deptId / - * @return / - */ - @Query(value = "SELECT u.* FROM sys_user u, sys_users_roles r, sys_roles_depts d WHERE " + - "u.user_id = r.user_id AND r.role_id = d.role_id AND d.dept_id = ?1 group by u.user_id", nativeQuery = true) - List findByRoleDeptId(Long deptId); - - /** - * 根据邮箱查询 - * @param email 邮箱 - * @return / - */ - User findByEmail(String email); - - /** - * 修改密码 - * @param username 用户名 - * @param pass 密码 - * @param lastPasswordResetTime / - */ - @Modifying - @Query(value = "update sys_user set password = ?2 , pwd_reset_time = ?3 where username = ?1",nativeQuery = true) - void updatePass(String username, String pass, Date lastPasswordResetTime); - - /** - * 修改邮箱 - * @param username 用户名 - * @param email 邮箱 - */ - @Modifying - @Query(value = "update sys_user set email = ?2 where username = ?1",nativeQuery = true) - void updateEmail(String username, String email); - - /** - * 根据角色查询用户 - * @param roleId / - * @return / - */ - @Query(value = "SELECT u.* FROM sys_user u, sys_users_roles r WHERE" + - " u.user_id = r.user_id AND r.role_id = ?1", nativeQuery = true) - List findByRoleId(Long roleId); - - /** - * 根据角色中的部门查询 - * @param id / - * @return / - */ - @Query(value = "SELECT u.* FROM sys_user u, sys_users_roles r, sys_roles_depts d WHERE " + - "u.user_id = r.user_id AND r.role_id = d.role_id AND r.role_id = ?1 group by u.user_id", nativeQuery = true) - List findByDeptRoleId(Long id); - - /** - * 根据菜单查询 - * @param id 菜单ID - * @return / - */ - @Query(value = "SELECT u.* FROM sys_user u, sys_users_roles ur, sys_roles_menus rm WHERE\n" + - "u.user_id = ur.user_id AND ur.role_id = rm.role_id AND rm.menu_id = ?1 group by u.user_id", nativeQuery = true) - List findByMenuId(Long id); - - /** - * 根据Id删除 - * @param ids / - */ - void deleteAllByIdIn(Set ids); - - /** - * 根据岗位查询 - * @param ids / - * @return / - */ - @Query(value = "SELECT count(1) FROM sys_user u, sys_users_jobs j WHERE u.user_id = j.user_id AND j.job_id IN ?1", nativeQuery = true) - int countByJobs(Set ids); - - /** - * 根据部门查询 - * @param deptIds / - * @return / - */ - @Query(value = "SELECT count(1) FROM sys_user u WHERE u.dept_id IN ?1", nativeQuery = true) - int countByDepts(Set deptIds); - - /** - * 根据角色查询 - * @param ids / - * @return / - */ - @Query(value = "SELECT count(1) FROM sys_user u, sys_users_roles r WHERE " + - "u.user_id = r.user_id AND r.role_id in ?1", nativeQuery = true) - int countByRoles(Set ids); -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/DeptController.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/DeptController.java index 7aa3024..f94c0ea 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/DeptController.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/DeptController.java @@ -99,7 +99,7 @@ public class DeptController { @ApiOperation("修改部门") @PutMapping @SaCheckPermission("dept:edit") - public ResponseEntity update(@Validated(Dept.Update.class) @RequestBody Dept resources){ + public ResponseEntity update(@RequestBody Dept resources){ deptService.update(resources); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/DictDetailController.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/DictDetailController.java index cd36122..9358738 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/DictDetailController.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/DictDetailController.java @@ -15,15 +15,10 @@ */ package org.nl.modules.system.rest; -import cn.dev33.satoken.annotation.SaCheckPermission; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; -import org.nl.modules.common.exception.BadRequestException; import org.nl.modules.logging.annotation.Log; -import org.nl.modules.system.domain.Dict; -import org.nl.modules.system.domain.DictDetail; -import org.nl.modules.system.repository.DictRepository; import org.nl.modules.system.service.DictDetailService; import org.nl.modules.system.service.dto.DictDetailDto; import org.nl.modules.system.service.dto.DictDetailQueryCriteria; @@ -33,13 +28,11 @@ import org.springframework.data.domain.Sort; import org.springframework.data.web.PageableDefault; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Optional; /** * @author Zheng Jie diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/MenuController.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/MenuController.java index 0c1a4fc..c7eb176 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/MenuController.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/MenuController.java @@ -17,7 +17,6 @@ package org.nl.modules.system.rest; import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaMode; -import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; @@ -131,7 +130,7 @@ public class MenuController { @ApiOperation("修改菜单") @PutMapping @SaCheckPermission("menu:edit") - public ResponseEntity update(@Validated(Menu.Update.class) @RequestBody JSONObject form) { + public ResponseEntity update( @RequestBody JSONObject form) { menuService.update(form); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/RoleController.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/RoleController.java index c9a03cc..0563c84 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/RoleController.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/RoleController.java @@ -92,7 +92,7 @@ public class RoleController { return new ResponseEntity<>(HttpStatus.CREATED); } - @Log("修改角色") + /* @Log("修改角色") @ApiOperation("修改角色") @PutMapping @SaCheckPermission("roles:edit") @@ -101,7 +101,7 @@ public class RoleController { roleService.update(resources); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } - +*/ @Log("修改角色菜单") @ApiOperation("修改角色菜单") @PutMapping(value = "/menu") diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/UserController.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/UserController.java index 592f25c..fc48eec 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/UserController.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/UserController.java @@ -17,46 +17,27 @@ package org.nl.modules.system.rest; import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.secure.SaSecureUtil; -import cn.dev33.satoken.stp.StpUtil; -import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ObjectUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import org.nl.modules.common.config.RsaProperties; import org.nl.modules.common.exception.BadRequestException; -import org.nl.modules.common.utils.PageUtil; import org.nl.modules.common.utils.RedisUtils; import org.nl.modules.common.utils.RsaUtils; import org.nl.modules.common.utils.SecurityUtils; import org.nl.modules.logging.annotation.Log; -import org.nl.modules.system.domain.Role; import org.nl.modules.system.domain.User; -import org.nl.modules.system.domain.vo.UserPassVo; -import org.nl.modules.system.service.DataService; -import org.nl.modules.system.service.DeptService; -import org.nl.modules.system.service.RoleService; import org.nl.modules.system.service.UserService; -import org.nl.modules.system.service.dto.RoleSmallDto; -import org.nl.modules.system.service.dto.UserDto; import org.nl.modules.system.service.dto.UserQueryCriteria; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Pageable; -import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.util.CollectionUtils; -import org.springframework.util.ObjectUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.Collections; -import java.util.List; import java.util.Set; -import java.util.stream.Collectors; /** * @author Zheng Jie @@ -67,20 +48,9 @@ import java.util.stream.Collectors; @RequestMapping("/api/users") @RequiredArgsConstructor public class UserController { - private final UserService userService; - private final DataService dataService; - private final DeptService deptService; - private final RoleService roleService; private final RedisUtils redisUtils; - @ApiOperation("导出用户数据") - @GetMapping(value = "/download") - @SaCheckPermission("user:list") - public void download(HttpServletResponse response, UserQueryCriteria criteria) throws IOException { - userService.download(userService.queryAll(criteria), response); - } - @ApiOperation("查询用户") @GetMapping @SaCheckPermission("user:list") @@ -104,7 +74,7 @@ public class UserController { return new ResponseEntity<>(HttpStatus.CREATED); } - @Log("修改用户") + /* @Log("修改用户") @ApiOperation("修改用户") @PutMapping @SaCheckPermission("user:edit") @@ -112,9 +82,9 @@ public class UserController { checkLevel(resources); userService.update(resources); return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } + }*/ - @Log("修改用户:个人中心") + /* @Log("修改用户:个人中心") @ApiOperation("修改用户:个人中心") @PutMapping(value = "center") public ResponseEntity center(@Validated(User.Update.class) @RequestBody User resources){ @@ -123,7 +93,7 @@ public class UserController { } userService.updateCenter(resources); return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } + }*/ @Log("删除用户") @ApiOperation("删除用户") @@ -147,7 +117,7 @@ public class UserController { return new ResponseEntity<>(HttpStatus.OK); } - @ApiOperation("修改密码") + /* @ApiOperation("修改密码") @PostMapping(value = "/updatePass") public ResponseEntity updatePass(@RequestBody UserPassVo passVo) throws Exception { // 解密,得到字符密码 @@ -162,7 +132,7 @@ public class UserController { } userService.updatePass(user.getUsername(),SaSecureUtil.md5BySalt(newPass, "salt")); return new ResponseEntity<>(HttpStatus.OK); - } + }*/ @ApiOperation("修改头像") @PostMapping(value = "/updateAvatar") diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/RoleService.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/RoleService.java index 405845a..8c77570 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/RoleService.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/RoleService.java @@ -116,16 +116,6 @@ public interface RoleService { */ List getPermissionList(JSONObject userDto); - /** - * 验证是否被用户关联 - * @param ids / - */ - void verification(Set ids); - /** - * 根据菜单Id查询 - * @param menuIds / - * @return / - */ - List findInMenuId(List menuIds); + } diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/UserService.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/UserService.java index 11e55ab..1ac258a 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/UserService.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/UserService.java @@ -101,13 +101,6 @@ public interface UserService { */ List queryAll(UserQueryCriteria criteria); - /** - * 导出数据 - * @param queryAll 待导出的数据 - * @param response / - * @throws IOException / - */ - void download(List queryAll, HttpServletResponse response) throws IOException; /** * 用户自助修改资料 diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/dto/UserDetail.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/dto/UserDetail.java index c1d07c8..265ac7e 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/dto/UserDetail.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/dto/UserDetail.java @@ -18,11 +18,9 @@ package org.nl.modules.system.service.dto; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; import lombok.Setter; -import org.nl.modules.common.base.BaseEntity; import org.nl.modules.system.domain.Dept; import org.nl.modules.system.domain.Role; -import javax.persistence.Column; import javax.validation.constraints.NotBlank; import java.io.Serializable; import java.util.Date; @@ -34,7 +32,7 @@ import java.util.List; */ @Getter @Setter -public class UserDetail extends BaseEntity implements Serializable { +public class UserDetail implements Serializable { private Long user_id; @@ -71,10 +69,8 @@ public class UserDetail extends BaseEntity implements Serializable { @ApiModelProperty(value = "是否为admin账号", hidden = true) private Boolean isAdmin = false; - @Column(name = "pwd_reset_time") @ApiModelProperty(value = "最后修改密码的时间", hidden = true) private Date pwd_reset_time; - @Column(name = "pwd_reset_time") @ApiModelProperty(value = "最后修改密码的时间", hidden = true) private Long pwd_reset_user_id; diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DeptServiceImpl.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DeptServiceImpl.java index e783a80..adb74cf 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DeptServiceImpl.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DeptServiceImpl.java @@ -39,17 +39,13 @@ import org.nl.modules.wql.core.bean.ResultBean; import org.nl.modules.wql.core.bean.WQLObject; import org.nl.modules.wql.util.SpringContextHolder; import org.springframework.cache.annotation.CacheConfig; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import javax.sql.DataSource; -import java.lang.reflect.Field; import java.sql.SQLException; import java.util.*; -import java.util.function.Function; import java.util.stream.Collectors; /** diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DictDetailServiceImpl.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DictDetailServiceImpl.java index 96932d4..7fca473 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DictDetailServiceImpl.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DictDetailServiceImpl.java @@ -22,22 +22,17 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; import org.nl.modules.common.exception.BadRequestException; -import org.nl.modules.common.utils.*; -import org.nl.modules.system.domain.Dict; -import org.nl.modules.system.domain.DictDetail; -import org.nl.modules.system.repository.DictDetailRepository; -import org.nl.modules.system.repository.DictRepository; +import org.nl.modules.common.utils.RedisUtils; +import org.nl.modules.common.utils.SecurityUtils; import org.nl.modules.system.service.DictDetailService; import org.nl.modules.system.service.dto.DictDetailDto; import org.nl.modules.system.service.dto.DictDetailQueryCriteria; import org.nl.modules.system.service.dto.DictDto; -import org.nl.modules.system.service.mapstruct.DictDetailMapper; import org.nl.modules.wql.WQL; import org.nl.modules.wql.core.bean.WQLObject; import org.nl.modules.wql.util.WqlUtil; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.Cacheable; -import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DictServiceImpl.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DictServiceImpl.java index 846957d..e989621 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DictServiceImpl.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DictServiceImpl.java @@ -23,13 +23,12 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; import org.nl.modules.common.exception.BadRequestException; -import org.nl.modules.common.utils.*; -import org.nl.modules.system.domain.Dict; -import org.nl.modules.system.repository.DictRepository; +import org.nl.modules.common.utils.FileUtil; +import org.nl.modules.common.utils.RedisUtils; +import org.nl.modules.common.utils.SecurityUtils; import org.nl.modules.system.service.DictService; import org.nl.modules.system.service.dto.DictDto; import org.nl.modules.system.service.dto.DictQueryCriteria; -import org.nl.modules.system.service.mapstruct.DictMapper; import org.nl.modules.wql.WQL; import org.nl.modules.wql.core.bean.WQLObject; import org.nl.modules.wql.util.WqlUtil; @@ -40,8 +39,10 @@ import org.springframework.transaction.annotation.Transactional; import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import java.math.BigDecimal; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * @author Zheng Jie diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/MenuServiceImpl.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/MenuServiceImpl.java index bd090c3..cb40e66 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/MenuServiceImpl.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/MenuServiceImpl.java @@ -7,16 +7,10 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; import org.nl.modules.common.exception.BadRequestException; -import org.nl.modules.common.exception.EntityExistException; -import org.nl.modules.common.utils.RedisUtils; import org.nl.modules.common.utils.SecurityUtils; -import org.nl.modules.common.utils.ValidationUtil; -import org.nl.modules.system.domain.Menu; import org.nl.modules.system.domain.vo.MenuMetaVo; import org.nl.modules.system.domain.vo.MenuVo; -import org.nl.modules.system.repository.UserRepository; import org.nl.modules.system.service.MenuService; -import org.nl.modules.system.service.RoleService; import org.nl.modules.system.service.dto.MenuDto; import org.nl.modules.wql.WQL; import org.nl.modules.wql.core.bean.WQLObject; @@ -38,9 +32,6 @@ import java.util.stream.Collectors; @CacheConfig(cacheNames = "menu") public class MenuServiceImpl implements MenuService { - private final UserRepository userRepository; - private final RoleService roleService; - private final RedisUtils redisUtils; @Override public JSONObject queryAll(JSONObject param, Pageable page) throws Exception { diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/RoleServiceImpl.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/RoleServiceImpl.java index 05ca64c..dc5614e 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/RoleServiceImpl.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/RoleServiceImpl.java @@ -17,40 +17,29 @@ package org.nl.modules.system.service.impl; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.date.DateUtil; -import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; -import org.nl.modules.common.exception.BadRequestException; -import org.nl.modules.common.exception.EntityExistException; -import org.nl.modules.common.utils.*; +import org.nl.modules.common.utils.CacheKey; +import org.nl.modules.common.utils.RedisUtils; +import org.nl.modules.common.utils.SecurityUtils; import org.nl.modules.system.domain.Role; import org.nl.modules.system.domain.User; -import org.nl.modules.system.repository.RoleRepository; -import org.nl.modules.system.repository.UserRepository; import org.nl.modules.system.service.RoleService; import org.nl.modules.system.service.dto.RoleDto; import org.nl.modules.system.service.dto.RoleQueryCriteria; import org.nl.modules.system.service.dto.RoleSmallDto; -import org.nl.modules.system.service.dto.UserDto; -import org.nl.modules.system.service.mapstruct.RoleMapper; -import org.nl.modules.system.service.mapstruct.RoleSmallMapper; import org.nl.modules.wql.WQL; import org.nl.modules.wql.core.bean.ResultBean; import org.nl.modules.wql.core.bean.WQLObject; import org.nl.modules.wql.util.WqlUtil; -import org.nl.wms.sch.service.dto.RegionDto; import org.nl.wms.util.IdUtil; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.Cacheable; -import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; import java.util.*; import java.util.stream.Collectors; @@ -63,12 +52,7 @@ import java.util.stream.Collectors; @CacheConfig(cacheNames = "role") public class RoleServiceImpl implements RoleService { - private final RoleRepository roleRepository; - private final RoleMapper roleMapper; - private final RoleSmallMapper roleSmallMapper; private final RedisUtils redisUtils; - private final UserRepository userRepository; -// private final UserCacheClean userCacheClean; @Override public JSONObject queryAll(Map whereJson, Pageable page) { @@ -96,9 +80,7 @@ public class RoleServiceImpl implements RoleService { @Cacheable(key = "'id:' + #p0") @Transactional(rollbackFor = Exception.class) public RoleDto findById(long id) { - Role role = roleRepository.findById(id).orElseGet(Role::new); - ValidationUtil.isNull(role.getId(), "Role", "id", id); - return roleMapper.toDto(role); + return null; } @Override @@ -122,39 +104,18 @@ public class RoleServiceImpl implements RoleService { @Override @Transactional(rollbackFor = Exception.class) public void update(Role resources) { - Role role = roleRepository.findById(resources.getId()).orElseGet(Role::new); - ValidationUtil.isNull(role.getId(), "Role", "id", resources.getId()); - Role role1 = roleRepository.findByName(resources.getName()); - - if (role1 != null && !role1.getId().equals(role.getId())) { - throw new EntityExistException(Role.class, "username", resources.getName()); - } - role.setName(resources.getName()); - /* role.setDescription(resources.getDescription()); - role.setDataScope(resources.getDataScope()); - role.setDepts(resources.getDepts());*/ - role.setLevel(resources.getLevel()); - roleRepository.save(role); - // 更新相关缓存 - delCaches(role.getId(), null); } @Override public void updateMenu(Role resources, RoleDto roleDTO) { - Role role = roleMapper.toEntity(roleDTO); - List users = userRepository.findByRoleId(role.getId()); - // 更新菜单 - role.setMenus(resources.getMenus()); - delCaches(resources.getId(), users); - roleRepository.save(role); + } @Override @Transactional(rollbackFor = Exception.class) public void untiedMenu(Long menuId) { - // 更新菜单 - roleRepository.untiedMenu(menuId); + } @Override @@ -170,7 +131,7 @@ public class RoleServiceImpl implements RoleService { @Override public List findByUsersId(Long id) { - return roleSmallMapper.toDto(new ArrayList<>(roleRepository.findByUserId(id))); + return null; } @Override @@ -199,17 +160,6 @@ public class RoleServiceImpl implements RoleService { return permission; } - @Override - public void verification(Set ids) { - if (userRepository.countByRoles(ids) > 0) { - throw new BadRequestException("所选角色存在用户关联,请解除关联再试!"); - } - } - - @Override - public List findInMenuId(List menuIds) { - return roleRepository.findInMenuId(menuIds); - } /** * 清理缓存 @@ -217,7 +167,7 @@ public class RoleServiceImpl implements RoleService { * @param id / */ public void delCaches(Long id, List users) { - users = CollectionUtil.isEmpty(users) ? userRepository.findByRoleId(id) : users; +// users = CollectionUtil.isEmpty(users) ? userRepository.findByRoleId(id) : users; if (CollectionUtil.isNotEmpty(users)) { // users.forEach(item -> userCacheClean.cleanUserCache(item.getUsername())); Set userIds = users.stream().map(User::getId).collect(Collectors.toSet()); diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/UserServiceImpl.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/UserServiceImpl.java index dc0951a..abdc2f9 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/UserServiceImpl.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/UserServiceImpl.java @@ -133,8 +133,8 @@ public class UserServiceImpl implements UserService { throw new EntityExistException(User.class, "username", resources.getUsername()); } CurrentUser user = SecurityUtils.getCurrentUser(); - resources.setCreate_id(user.getId()); - resources.setCreate_name(user.getUsername()); + /* resources.setCreate_id(user.getId()); + resources.setCreate_name(user.getUsername());*/ WQLObject.getWQLObject("sys_user").insert((JSONObject)JSON.toJSON(resources)); } @@ -227,23 +227,6 @@ public class UserServiceImpl implements UserService { WQLObject.getWQLObject("sys_user").update(MapOf.of("email",email),"username ='"+username+"'"); } - @Override - public void download(List queryAll, HttpServletResponse response) throws IOException { - List> list = new ArrayList<>(); - for (User userDTO : queryAll) { - Map map = new LinkedHashMap<>(); - map.put("用户名", userDTO.getUsername()); - map.put("角色", userDTO.getRoles()); - map.put("邮箱", userDTO.getEmail()); - map.put("状态", "1".equals(userDTO.getIs_used()) ? "启用" : "禁用"); - map.put("手机号码", userDTO.getPhone()); - map.put("修改密码的时间", userDTO.getPwdResetTime()); - map.put("创建日期", userDTO.getCreate_time()); - list.add(map); - } - FileUtil.downloadExcel(list, response); - } - /** * 清理缓存 * diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/wql/sys.xls b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/wql/sys.xls index e61fa7f..353ca79 100644 Binary files a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/wql/sys.xls and b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/wql/sys.xls differ diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/config/MultipartConfig.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/config/MultipartConfig.java deleted file mode 100644 index 853d7f8..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/config/MultipartConfig.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.tools.config; - -import org.springframework.boot.web.servlet.MultipartConfigFactory; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import javax.servlet.MultipartConfigElement; -import java.io.File; - -/** - * @date 2018-12-28 - * @author https://blog.csdn.net/llibin1024530411/article/details/79474953 - */ -@Configuration -public class MultipartConfig { - - /** - * 文件上传临时路径 - */ - @Bean - MultipartConfigElement multipartConfigElement() { - MultipartConfigFactory factory = new MultipartConfigFactory(); - String location = System.getProperty("user.home") + "/.eladmin/file/tmp"; - File tmpFile = new File(location); - if (!tmpFile.exists()) { - if (!tmpFile.mkdirs()) { - System.out.println("create was not successful."); - } - } - factory.setLocation(location); - return factory.createMultipartConfig(); - } -} \ No newline at end of file diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/domain/LocalStorage.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/domain/LocalStorage.java deleted file mode 100644 index b9e535e..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/domain/LocalStorage.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.tools.domain; - -import cn.hutool.core.bean.BeanUtil; -import cn.hutool.core.bean.copier.CopyOptions; -import io.swagger.annotations.ApiModelProperty; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import org.nl.modules.common.base.BaseEntity; - -import javax.persistence.*; -import java.io.Serializable; - -/** -* @author Zheng Jie -* @date 2019-09-05 -*/ -@Getter -@Setter -@Entity -@Table(name="tool_local_storage") -@NoArgsConstructor -public class LocalStorage extends BaseEntity implements Serializable { - - @Id - @Column(name = "storage_id") - @ApiModelProperty(value = "ID", hidden = true) - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @ApiModelProperty(value = "真实文件名") - private String realName; - - @ApiModelProperty(value = "文件名") - private String name; - - @ApiModelProperty(value = "后缀") - private String suffix; - - @ApiModelProperty(value = "路径") - private String path; - - @ApiModelProperty(value = "类型") - private String type; - - @ApiModelProperty(value = "大小") - private String size; - - public LocalStorage(String realName,String name, String suffix, String path, String type, String size) { - this.realName = realName; - this.name = name; - this.suffix = suffix; - this.path = path; - this.type = type; - this.size = size; - } - - public void copy(LocalStorage source){ - BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); - } -} \ No newline at end of file diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/repository/LocalStorageRepository.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/repository/LocalStorageRepository.java deleted file mode 100644 index 3278bdc..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/repository/LocalStorageRepository.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.tools.repository; - -import org.nl.modules.tools.domain.LocalStorage; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; - -/** -* @author Zheng Jie -* @date 2019-09-05 -*/ -public interface LocalStorageRepository extends JpaRepository, JpaSpecificationExecutor { -} \ No newline at end of file diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/rest/LocalStorageController.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/rest/LocalStorageController.java deleted file mode 100644 index 475274e..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/rest/LocalStorageController.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.tools.rest; - -import cn.dev33.satoken.annotation.SaCheckPermission; -import cn.dev33.satoken.annotation.SaIgnore; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.RequiredArgsConstructor; -import org.nl.modules.common.exception.BadRequestException; -import org.nl.modules.common.utils.FileUtil; -import org.nl.modules.logging.annotation.Log; -import org.nl.modules.tools.domain.LocalStorage; -import org.nl.modules.tools.service.LocalStorageService; -import org.nl.modules.tools.service.dto.LocalStorageQueryCriteria; -import org.springframework.data.domain.Pageable; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; - -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -/** - * @author Zheng Jie - * @date 2019-09-05 - */ -@RestController -@RequiredArgsConstructor -@Api(tags = "工具:本地存储管理") -@RequestMapping("/api/localStorage") -public class LocalStorageController { - - private final LocalStorageService localStorageService; - - @ApiOperation("查询文件") - @GetMapping - @SaCheckPermission("storage:list") - public ResponseEntity query(LocalStorageQueryCriteria criteria, Pageable pageable) { - return new ResponseEntity<>(localStorageService.queryAll(criteria, pageable), HttpStatus.OK); - } - - @ApiOperation("导出数据") - @GetMapping(value = "/download") - @SaCheckPermission("storage:list") - public void download(HttpServletResponse response, LocalStorageQueryCriteria criteria) throws IOException { - localStorageService.download(localStorageService.queryAll(criteria), response); - } - - @ApiOperation("上传文件") - @PostMapping - @SaCheckPermission("storage:add") - public ResponseEntity create(@RequestParam String name, @RequestParam("file") MultipartFile file) { - LocalStorage localStorage = localStorageService.create(name, file); - return new ResponseEntity<>(localStorage, HttpStatus.CREATED); - } - - @PostMapping("/pictures") - @ApiOperation("上传图片") - public ResponseEntity upload(@RequestParam MultipartFile file) { - // 判断文件是否为图片 - String suffix = FileUtil.getExtensionName(file.getOriginalFilename()); - if (!FileUtil.IMAGE.equals(FileUtil.getFileType(suffix))) { - throw new BadRequestException("只能上传图片"); - } - LocalStorage localStorage = localStorageService.create(null, file); - return new ResponseEntity<>(localStorage, HttpStatus.OK); - } - - @Log("修改文件") - @ApiOperation("修改文件") - @PutMapping - @SaCheckPermission("storage:edit") - public ResponseEntity update(@Validated @RequestBody LocalStorage resources) { - localStorageService.update(resources); - return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } - - @Log("删除文件") - @DeleteMapping - @ApiOperation("多选删除") - public ResponseEntity delete(@RequestBody Long[] ids) { - localStorageService.deleteAll(ids); - return new ResponseEntity<>(HttpStatus.OK); - } - - @ApiOperation("导入数据") - @PostMapping("/importExcel") - @SaIgnore - public ResponseEntity importExcel(@RequestBody String path) { - localStorageService.importExcel(path); - return new ResponseEntity<>(HttpStatus.OK); - } -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/service/LocalStorageService.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/service/LocalStorageService.java deleted file mode 100644 index ea1cbba..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/service/LocalStorageService.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.tools.service; - - -import org.nl.modules.tools.domain.LocalStorage; -import org.nl.modules.tools.service.dto.LocalStorageDto; -import org.nl.modules.tools.service.dto.LocalStorageQueryCriteria; -import org.springframework.data.domain.Pageable; -import org.springframework.web.multipart.MultipartFile; - -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.List; - -/** -* @author Zheng Jie -* @date 2019-09-05 -*/ -public interface LocalStorageService { - - /** - * 分页查询 - * @param criteria 条件 - * @param pageable 分页参数 - * @return / - */ - Object queryAll(LocalStorageQueryCriteria criteria, Pageable pageable); - - /** - * 查询全部数据 - * @param criteria 条件 - * @return / - */ - List queryAll(LocalStorageQueryCriteria criteria); - - /** - * 根据ID查询 - * @param id / - * @return / - */ - LocalStorageDto findById(Long id); - - /** - * 上传 - * @param name 文件名称 - * @param file 文件 - * @return - */ - LocalStorage create(String name, MultipartFile file); - - /** - * 编辑 - * @param resources 文件信息 - */ - void update(LocalStorage resources); - - /** - * 多选删除 - * @param ids / - */ - void deleteAll(Long[] ids); - - /** - * 导出数据 - * @param localStorageDtos 待导出的数据 - * @param response / - * @throws IOException / - */ - void download(List localStorageDtos, HttpServletResponse response) throws IOException; - - /** - * 导入数据 - * @param path - */ - void importExcel(String path); -} \ No newline at end of file diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/service/dto/LocalStorageDto.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/service/dto/LocalStorageDto.java deleted file mode 100644 index 264a284..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/service/dto/LocalStorageDto.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.tools.service.dto; - -import lombok.Getter; -import lombok.Setter; -import org.nl.modules.common.base.BaseDTO; - -import java.io.Serializable; - -/** -* @author Zheng Jie -* @date 2019-09-05 -*/ -@Getter -@Setter -public class LocalStorageDto extends BaseDTO implements Serializable { - - private Long id; - - private String realName; - - private String name; - - private String suffix; - - private String type; - - private String size; -} \ No newline at end of file diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/service/dto/LocalStorageQueryCriteria.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/service/dto/LocalStorageQueryCriteria.java deleted file mode 100644 index 8ed2ee3..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/service/dto/LocalStorageQueryCriteria.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.tools.service.dto; - -import lombok.Data; -import org.nl.modules.common.annotation.Query; - -import java.util.Date; -import java.util.List; - - -/** -* @author Zheng Jie -* @date 2019-09-05 -*/ -@Data -public class LocalStorageQueryCriteria{ - - @Query(blurry = "name,suffix,type,createBy,size") - private String blurry; - - @Query(type = Query.Type.BETWEEN) - private List createTime; -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/service/impl/LocalStorageServiceImpl.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/service/impl/LocalStorageServiceImpl.java deleted file mode 100644 index 550360b..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/service/impl/LocalStorageServiceImpl.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.tools.service.impl; - -import cn.hutool.core.date.DateUtil; -import cn.hutool.core.util.IdUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; -import com.alibaba.excel.EasyExcel; -import com.alibaba.fastjson.JSONObject; -import lombok.RequiredArgsConstructor; -import org.nl.modules.common.config.FileProperties; -import org.nl.modules.common.exception.BadRequestException; -import org.nl.modules.common.utils.*; -import org.nl.modules.tools.domain.LocalStorage; -import org.nl.modules.tools.repository.LocalStorageRepository; -import org.nl.modules.tools.service.LocalStorageService; -import org.nl.modules.tools.service.dto.LocalStorageDto; -import org.nl.modules.tools.service.dto.LocalStorageQueryCriteria; -import org.nl.modules.tools.service.mapstruct.LocalStorageMapper; -import org.nl.modules.wql.core.bean.WQLObject; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.multipart.MultipartFile; - -import javax.servlet.http.HttpServletResponse; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -/** -* @author Zheng Jie -* @date 2019-09-05 -*/ -@Service -@RequiredArgsConstructor -public class LocalStorageServiceImpl implements LocalStorageService { - - private final LocalStorageRepository localStorageRepository; - private final LocalStorageMapper localStorageMapper; - private final FileProperties properties; - - @Override - public Object queryAll(LocalStorageQueryCriteria criteria, Pageable pageable){ - Page page = localStorageRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); - return PageUtil.toPage(page.map(localStorageMapper::toDto)); - } - - @Override - public List queryAll(LocalStorageQueryCriteria criteria){ - return localStorageMapper.toDto(localStorageRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); - } - - @Override - public LocalStorageDto findById(Long id){ - LocalStorage localStorage = localStorageRepository.findById(id).orElseGet(LocalStorage::new); - ValidationUtil.isNull(localStorage.getId(),"LocalStorage","id",id); - return localStorageMapper.toDto(localStorage); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public LocalStorage create(String name, MultipartFile multipartFile) { - FileUtil.checkSize(properties.getMaxSize(), multipartFile.getSize()); - String suffix = FileUtil.getExtensionName(multipartFile.getOriginalFilename()); - String type = FileUtil.getFileType(suffix); - File file = FileUtil.upload(multipartFile, properties.getPath().getPath() + type + File.separator); - if(ObjectUtil.isNull(file)){ - throw new BadRequestException("上传失败"); - } - try { - name = StrUtil.isEmpty(name) ? FileUtil.getFileNameNoEx(multipartFile.getOriginalFilename()) : name; - LocalStorage localStorage = new LocalStorage( - file.getName(), - name, - suffix, - file.getPath(), - type, - FileUtil.getSize(multipartFile.getSize()) - ); - return localStorageRepository.save(localStorage); - }catch (Exception e){ - FileUtil.del(file); - throw e; - } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void update(LocalStorage resources) { - LocalStorage localStorage = localStorageRepository.findById(resources.getId()).orElseGet(LocalStorage::new); - ValidationUtil.isNull( localStorage.getId(),"LocalStorage","id",resources.getId()); - localStorage.copy(resources); - localStorageRepository.save(localStorage); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void deleteAll(Long[] ids) { - for (Long id : ids) { - LocalStorage storage = localStorageRepository.findById(id).orElseGet(LocalStorage::new); - FileUtil.del(storage.getPath()); - localStorageRepository.delete(storage); - } - } - - @Override - public void download(List queryAll, HttpServletResponse response) throws IOException { - List> list = new ArrayList<>(); - for (LocalStorageDto localStorageDTO : queryAll) { - Map map = new LinkedHashMap<>(); - map.put("文件名", localStorageDTO.getRealName()); - map.put("备注名", localStorageDTO.getName()); - map.put("文件类型", localStorageDTO.getType()); - map.put("文件大小", localStorageDTO.getSize()); - map.put("创建者", localStorageDTO.getCreate_name()); - map.put("创建日期", localStorageDTO.getCreate_time()); - list.add(map); - } - FileUtil.downloadExcel(list, response); - } - - /** - * 导入数据 - * - * @param path: 文件地址 - */ - @Override - @Transactional(rollbackFor = Exception.class) - public void importExcel(String path) { - WQLObject measureunitTab = WQLObject.getWQLObject("md_pb_measureunit"); - Long currentUserId = SecurityUtils.getCurrentUserId(); - String nickName = SecurityUtils.getCurrentNickName(); - String now = DateUtil.now(); - List> listMap = EasyExcel.read(path).sheet().doReadSync(); - listMap.remove(0); - for (int i = 0; i < listMap.size(); i++) { - Map map = listMap.get(i); - String unit_code = String.valueOf(map.get(1)); - String unit_name = String.valueOf(map.get(2)); - JSONObject unit = new JSONObject(); - unit.put("measure_unit_id", IdUtil.getSnowflake(1, 1).nextId()); - unit.put("unit_code", unit_code); - unit.put("unit_name", unit_name); - unit.put("qty_precision", 2); - unit.put("is_used", 1); - unit.put("is_delete", 0); - unit.put("create_id", currentUserId); - unit.put("create_name", nickName); - unit.put("create_time", now); - unit.put("update_optid", currentUserId); - unit.put("update_optname", nickName); - unit.put("update_time", now); - measureunitTab.insert(unit); - } - } -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/service/mapstruct/LocalStorageMapper.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/service/mapstruct/LocalStorageMapper.java deleted file mode 100644 index 9336bea..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/tools/service/mapstruct/LocalStorageMapper.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.nl.modules.tools.service.mapstruct; - - -import org.mapstruct.Mapper; -import org.mapstruct.ReportingPolicy; -import org.nl.modules.common.base.BaseMapper; -import org.nl.modules.tools.domain.LocalStorage; -import org.nl.modules.tools.service.dto.LocalStorageDto; - -/** -* @author Zheng Jie -* @date 2019-09-05 -*/ -@Mapper(componentModel = "spring",unmappedTargetPolicy = ReportingPolicy.IGNORE) -public interface LocalStorageMapper extends BaseMapper { - -} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/wql/util/WqlUtil.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/wql/util/WqlUtil.java index 3835e4d..2143ab4 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/wql/util/WqlUtil.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/wql/util/WqlUtil.java @@ -5,8 +5,7 @@ import lombok.extern.slf4j.Slf4j; import org.nl.modules.wql.core.content.HttpContext; import org.springframework.data.domain.Pageable; -import javax.persistence.Column; -import javax.persistence.Table; + import java.io.*; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -17,6 +16,8 @@ import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.persistence.Column; +import javax.persistence.Table; @Slf4j public class WqlUtil {