优化代码

pull/43/head
smallbun 1 year ago
parent 7720cc377d
commit e974422086

@ -59,7 +59,7 @@ import static cn.topiam.employee.common.constant.AppConstants.APP_PATH;
@Tag(name = "应用分组管理")
@RestController
@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 {
/**

@ -96,21 +96,7 @@ public interface AppGroupConverter {
* @param entity {@link AppGroupEntity}
* @return {@link AppGroupListResult}
*/
default 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;
}
AppGroupListResult entityConvertToAppGroupListResult(AppGroupEntity entity);
/**
*
@ -118,20 +104,7 @@ public interface AppGroupConverter {
* @param entity {@link AppGroupEntity}
* @return {@link AppGroupGetResult}
*/
default 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;
}
AppGroupGetResult entityConvertToAppGroupResult(AppGroupEntity entity);
/**
* entity
@ -139,12 +112,12 @@ public interface AppGroupConverter {
* @param param {@link AppGroupUpdateParam}
* @return {@link AppGroupEntity}
*/
@Mapping(target = "enabled", ignore = true)
@Mapping(target = "deleted", ignore = true)
@Mapping(target = "updateTime", ignore = true)
@Mapping(target = "updateBy", ignore = true)
@Mapping(target = "createTime", ignore = true)
@Mapping(target = "createBy", ignore = true)
@Mapping(target = "enabled", ignore = false)
AppGroupEntity appGroupUpdateParamConverterToEntity(AppGroupUpdateParam param);
/**
@ -153,6 +126,7 @@ public interface AppGroupConverter {
* @param param {@link AppAccountCreateParam}
* @return {@link AppAccountEntity}
*/
@Mapping(target = "enabled", expression = "java(Boolean.TRUE)")
@Mapping(target = "deleted", ignore = true)
@Mapping(target = "id", ignore = true)
@Mapping(target = "updateTime", ignore = true)

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

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

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

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

Loading…
Cancel
Save