优化代码

pull/43/head
smallbun 2023-09-08 18:56:14 +08:00
parent 7720cc377d
commit e974422086
6 changed files with 25 additions and 49 deletions

View File

@ -59,7 +59,7 @@ import static cn.topiam.employee.common.constant.AppConstants.APP_PATH;
@Tag(name = "应用分组管理") @Tag(name = "应用分组管理")
@RestController @RestController
@AllArgsConstructor @AllArgsConstructor
@RequestMapping(value = APP_PATH + "/app_group", produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = APP_PATH + "/group", produces = MediaType.APPLICATION_JSON_VALUE)
public class AppGroupController { public class AppGroupController {
/** /**

View File

@ -96,21 +96,7 @@ public interface AppGroupConverter {
* @param entity {@link AppGroupEntity} * @param entity {@link AppGroupEntity}
* @return {@link AppGroupListResult} * @return {@link AppGroupListResult}
*/ */
default AppGroupListResult entityConvertToAppGroupListResult(AppGroupEntity entity) { AppGroupListResult entityConvertToAppGroupListResult(AppGroupEntity entity);
if (entity == null) {
return null;
}
AppGroupListResult appGroupListResult = new AppGroupListResult();
if (entity.getId() != null) {
appGroupListResult.setId(String.valueOf(entity.getId()));
}
appGroupListResult.setName(entity.getName());
appGroupListResult.setCode(entity.getCode());
appGroupListResult.setEnabled(entity.getEnabled());
appGroupListResult.setRemark(entity.getRemark());
return appGroupListResult;
}
/** /**
* *
@ -118,20 +104,7 @@ public interface AppGroupConverter {
* @param entity {@link AppGroupEntity} * @param entity {@link AppGroupEntity}
* @return {@link AppGroupGetResult} * @return {@link AppGroupGetResult}
*/ */
default AppGroupGetResult entityConvertToAppGroupResult(AppGroupEntity entity) { AppGroupGetResult entityConvertToAppGroupResult(AppGroupEntity entity);
if (entity == null) {
return null;
}
AppGroupGetResult appGroupGetResult = new AppGroupGetResult();
if (entity.getId() != null) {
appGroupGetResult.setId(String.valueOf(entity.getId()));
}
appGroupGetResult.setName(entity.getName());
appGroupGetResult.setEnabled(entity.getEnabled());
appGroupGetResult.setCreateTime(entity.getCreateTime());
return appGroupGetResult;
}
/** /**
* entity * entity
@ -139,12 +112,12 @@ public interface AppGroupConverter {
* @param param {@link AppGroupUpdateParam} * @param param {@link AppGroupUpdateParam}
* @return {@link AppGroupEntity} * @return {@link AppGroupEntity}
*/ */
@Mapping(target = "enabled", ignore = true)
@Mapping(target = "deleted", ignore = true) @Mapping(target = "deleted", ignore = true)
@Mapping(target = "updateTime", ignore = true) @Mapping(target = "updateTime", ignore = true)
@Mapping(target = "updateBy", ignore = true) @Mapping(target = "updateBy", ignore = true)
@Mapping(target = "createTime", ignore = true) @Mapping(target = "createTime", ignore = true)
@Mapping(target = "createBy", ignore = true) @Mapping(target = "createBy", ignore = true)
@Mapping(target = "enabled", ignore = false)
AppGroupEntity appGroupUpdateParamConverterToEntity(AppGroupUpdateParam param); AppGroupEntity appGroupUpdateParamConverterToEntity(AppGroupUpdateParam param);
/** /**
@ -153,6 +126,7 @@ public interface AppGroupConverter {
* @param param {@link AppAccountCreateParam} * @param param {@link AppAccountCreateParam}
* @return {@link AppAccountEntity} * @return {@link AppAccountEntity}
*/ */
@Mapping(target = "enabled", expression = "java(Boolean.TRUE)")
@Mapping(target = "deleted", ignore = true) @Mapping(target = "deleted", ignore = true)
@Mapping(target = "id", ignore = true) @Mapping(target = "id", ignore = true)
@Mapping(target = "updateTime", ignore = true) @Mapping(target = "updateTime", ignore = true)

View File

@ -18,6 +18,7 @@
package cn.topiam.employee.console.pojo.result.app; package cn.topiam.employee.console.pojo.result.app;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.Data; import lombok.Data;
@ -58,6 +59,12 @@ public class AppGroupListResult implements Serializable {
@Parameter(description = "是否启用") @Parameter(description = "是否启用")
private Boolean enabled; private Boolean enabled;
/**
*
*/
@Parameter(description = "创建时间")
private LocalDateTime createTime;
/** /**
* *
*/ */

View File

@ -31,7 +31,7 @@ import jakarta.validation.constraints.NotBlank;
* Created by support@topiam.cn on 2023/8/31 23:26 * Created by support@topiam.cn on 2023/8/31 23:26
*/ */
@Data @Data
@Schema(description = "分组保存入参") @Schema(description = "应用分组保存入参")
public class AppGroupCreateParam implements Serializable { public class AppGroupCreateParam implements Serializable {
/** /**
@ -41,16 +41,17 @@ public class AppGroupCreateParam implements Serializable {
@Schema(description = "分组名称") @Schema(description = "分组名称")
private String name; private String name;
/**
*
*/
@NotBlank(message = "分组编码不能为空")
@Schema(description = "分组编码")
private String code;
/** /**
* *
*/ */
@Schema(description = "备注") @Schema(description = "备注")
private String remark; private String remark;
/**
*
*/
@Schema(description = "分组编码")
private String code;
} }

View File

@ -53,12 +53,6 @@ public class AppGroupUpdateParam implements Serializable {
@Schema(description = "分组编码") @Schema(description = "分组编码")
private String code; private String code;
/**
*
*/
@Schema(description = "分组是否启用")
private Boolean enabled;
/** /**
* *
*/ */

View File

@ -30,6 +30,7 @@ import cn.topiam.employee.common.entity.app.AppGroupEntity;
import cn.topiam.employee.common.entity.app.QAppGroupAssociationEntity; import cn.topiam.employee.common.entity.app.QAppGroupAssociationEntity;
import cn.topiam.employee.common.entity.app.QAppGroupEntity; import cn.topiam.employee.common.entity.app.QAppGroupEntity;
import cn.topiam.employee.portal.pojo.result.AppGroupListResult; import cn.topiam.employee.portal.pojo.result.AppGroupListResult;
import org.mapstruct.Mapping;
/** /**
* *
@ -61,9 +62,7 @@ public interface AppGroupConverter {
*/ */
default Predicate queryAppGroupAssociationPredicate() { default Predicate queryAppGroupAssociationPredicate() {
QAppGroupAssociationEntity appGroupAssociation = QAppGroupAssociationEntity.appGroupAssociationEntity; QAppGroupAssociationEntity appGroupAssociation = QAppGroupAssociationEntity.appGroupAssociationEntity;
Predicate predicate = appGroupAssociation.deleted.eq(Boolean.FALSE); return appGroupAssociation.deleted.eq(Boolean.FALSE);
//@formatter:on
return predicate;
} }
/** /**
@ -78,9 +77,9 @@ public interface AppGroupConverter {
List<AppGroupListResult> results = new ArrayList<>(); List<AppGroupListResult> results = new ArrayList<>();
for (AppGroupEntity entity : list) { for (AppGroupEntity entity : list) {
AppGroupListResult result = appGroupEntityConverterToResult(entity); AppGroupListResult result = appGroupEntityConverterToResult(entity);
Long count = appGroupAssociationList.stream() long count = appGroupAssociationList.stream()
.filter(t -> t.getGroupId().equals(entity.getId())).count(); .filter(t -> t.getGroupId().equals(entity.getId())).count();
result.setAppCount(Integer.valueOf(count.toString())); result.setAppCount(Integer.valueOf(Long.toString(count)));
results.add(result); results.add(result);
} }
return results; return results;
@ -92,6 +91,7 @@ public interface AppGroupConverter {
* @param entity {@link AppGroupEntity} * @param entity {@link AppGroupEntity}
* @return {@link AppGroupEntity} * @return {@link AppGroupEntity}
*/ */
@Mapping(target = "appCount", ignore = true)
AppGroupListResult appGroupEntityConverterToResult(AppGroupEntity entity); AppGroupListResult appGroupEntityConverterToResult(AppGroupEntity entity);
} }