Commit 1e77ace11c948fd08cd19d7d59999eb5c5e41e2f
1 parent
71ea4fbe
用户设备关系
Showing
17 changed files
with
840 additions
and
0 deletions
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/deviceuser/DeviceUserController.java
0 → 100644
| 1 | +package com.zteits.urbanops.module.garden.controller.admin.deviceuser; | ||
| 2 | + | ||
| 3 | +import org.springframework.web.bind.annotation.*; | ||
| 4 | +import jakarta.annotation.Resource; | ||
| 5 | +import org.springframework.validation.annotation.Validated; | ||
| 6 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 7 | +import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 8 | +import io.swagger.v3.oas.annotations.Parameter; | ||
| 9 | +import io.swagger.v3.oas.annotations.Operation; | ||
| 10 | + | ||
| 11 | +import jakarta.validation.constraints.*; | ||
| 12 | +import jakarta.validation.*; | ||
| 13 | +import jakarta.servlet.http.*; | ||
| 14 | +import java.util.*; | ||
| 15 | +import java.io.IOException; | ||
| 16 | + | ||
| 17 | +import com.zteits.urbanops.framework.common.pojo.PageParam; | ||
| 18 | +import com.zteits.urbanops.framework.common.pojo.PageResult; | ||
| 19 | +import com.zteits.urbanops.framework.common.pojo.CommonResult; | ||
| 20 | +import com.zteits.urbanops.framework.common.util.object.BeanUtils; | ||
| 21 | +import static com.zteits.urbanops.framework.common.pojo.CommonResult.success; | ||
| 22 | + | ||
| 23 | +import com.zteits.urbanops.framework.excel.core.util.ExcelUtils; | ||
| 24 | + | ||
| 25 | +import com.zteits.urbanops.framework.apilog.core.annotation.ApiAccessLog; | ||
| 26 | +import static com.zteits.urbanops.framework.apilog.core.enums.OperateTypeEnum.*; | ||
| 27 | + | ||
| 28 | +import com.zteits.urbanops.module.garden.controller.admin.deviceuser.vo.*; | ||
| 29 | +import com.zteits.urbanops.module.garden.dal.dataobject.deviceuser.DeviceUserDO; | ||
| 30 | +import com.zteits.urbanops.module.garden.service.deviceuser.DeviceUserService; | ||
| 31 | + | ||
| 32 | +@Tag(name = "管理后台 - 设备用户关系") | ||
| 33 | +@RestController | ||
| 34 | +@RequestMapping("/garden/device-user") | ||
| 35 | +@Validated | ||
| 36 | +public class DeviceUserController { | ||
| 37 | + | ||
| 38 | + @Resource | ||
| 39 | + private DeviceUserService deviceUserService; | ||
| 40 | + | ||
| 41 | + @PostMapping("/create") | ||
| 42 | + @Operation(summary = "创建设备用户关系") | ||
| 43 | + @PreAuthorize("@ss.hasPermission('garden:device-user:create')") | ||
| 44 | + public CommonResult<Long> createDeviceUser(@Valid @RequestBody DeviceUserSaveReqVO createReqVO) { | ||
| 45 | + return success(deviceUserService.createDeviceUser(createReqVO)); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + @PutMapping("/update") | ||
| 49 | + @Operation(summary = "更新设备用户关系") | ||
| 50 | + @PreAuthorize("@ss.hasPermission('garden:device-user:update')") | ||
| 51 | + public CommonResult<Boolean> updateDeviceUser(@Valid @RequestBody DeviceUserSaveReqVO updateReqVO) { | ||
| 52 | + deviceUserService.updateDeviceUser(updateReqVO); | ||
| 53 | + return success(true); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + @DeleteMapping("/delete") | ||
| 57 | + @Operation(summary = "删除设备用户关系") | ||
| 58 | + @Parameter(name = "id", description = "编号", required = true) | ||
| 59 | + @PreAuthorize("@ss.hasPermission('garden:device-user:delete')") | ||
| 60 | + public CommonResult<Boolean> deleteDeviceUser(@RequestParam("id") Long id) { | ||
| 61 | + deviceUserService.deleteDeviceUser(id); | ||
| 62 | + return success(true); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + @DeleteMapping("/delete-list") | ||
| 66 | + @Parameter(name = "ids", description = "编号", required = true) | ||
| 67 | + @Operation(summary = "批量删除设备用户关系") | ||
| 68 | + @PreAuthorize("@ss.hasPermission('garden:device-user:delete')") | ||
| 69 | + public CommonResult<Boolean> deleteDeviceUserList(@RequestParam("ids") List<Long> ids) { | ||
| 70 | + deviceUserService.deleteDeviceUserListByIds(ids); | ||
| 71 | + return success(true); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + @GetMapping("/get") | ||
| 75 | + @Operation(summary = "获得设备用户关系") | ||
| 76 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | ||
| 77 | + @PreAuthorize("@ss.hasPermission('garden:device-user:query')") | ||
| 78 | + public CommonResult<DeviceUserRespVO> getDeviceUser(@RequestParam("id") Long id) { | ||
| 79 | + DeviceUserDO deviceUser = deviceUserService.getDeviceUser(id); | ||
| 80 | + return success(BeanUtils.toBean(deviceUser, DeviceUserRespVO.class)); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + @GetMapping("/page") | ||
| 84 | + @Operation(summary = "获得设备用户关系分页") | ||
| 85 | + @PreAuthorize("@ss.hasPermission('garden:device-user:query')") | ||
| 86 | + public CommonResult<PageResult<DeviceUserRespVO>> getDeviceUserPage(@Valid DeviceUserPageReqVO pageReqVO) { | ||
| 87 | + PageResult<DeviceUserDO> pageResult = deviceUserService.getDeviceUserPage(pageReqVO); | ||
| 88 | + return success(BeanUtils.toBean(pageResult, DeviceUserRespVO.class)); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + @GetMapping("/export-excel") | ||
| 92 | + @Operation(summary = "导出设备用户关系 Excel") | ||
| 93 | + @PreAuthorize("@ss.hasPermission('garden:device-user:export')") | ||
| 94 | + @ApiAccessLog(operateType = EXPORT) | ||
| 95 | + public void exportDeviceUserExcel(@Valid DeviceUserPageReqVO pageReqVO, | ||
| 96 | + HttpServletResponse response) throws IOException { | ||
| 97 | + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | ||
| 98 | + List<DeviceUserDO> list = deviceUserService.getDeviceUserPage(pageReqVO).getList(); | ||
| 99 | + // 导出 Excel | ||
| 100 | + ExcelUtils.write(response, "设备用户关系.xls", "数据", DeviceUserRespVO.class, | ||
| 101 | + BeanUtils.toBean(list, DeviceUserRespVO.class)); | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | +} | ||
| 0 | \ No newline at end of file | 105 | \ No newline at end of file |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/deviceuser/vo/DeviceUserPageReqVO.java
0 → 100644
| 1 | +package com.zteits.urbanops.module.garden.controller.admin.deviceuser.vo; | ||
| 2 | + | ||
| 3 | +import lombok.*; | ||
| 4 | +import java.util.*; | ||
| 5 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 6 | +import com.zteits.urbanops.framework.common.pojo.PageParam; | ||
| 7 | +import org.springframework.format.annotation.DateTimeFormat; | ||
| 8 | +import java.time.LocalDateTime; | ||
| 9 | + | ||
| 10 | +import static com.zteits.urbanops.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | ||
| 11 | + | ||
| 12 | +@Schema(description = "管理后台 - 设备用户关系分页 Request VO") | ||
| 13 | +@Data | ||
| 14 | +public class DeviceUserPageReqVO extends PageParam { | ||
| 15 | + | ||
| 16 | + @Schema(description = "归属(一级部门id)", example = "22641") | ||
| 17 | + private Long companyId; | ||
| 18 | + | ||
| 19 | + @Schema(description = "部门ID(道路负责部门id)", example = "15793") | ||
| 20 | + private Long deptId; | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + @Schema(description = "提交人用户", example = "芋艿") | ||
| 24 | + private String userName; | ||
| 25 | + | ||
| 26 | + @Schema(description = "产品名称", example = "张三") | ||
| 27 | + private String productName; | ||
| 28 | + | ||
| 29 | + @Schema(description = "设备标识") | ||
| 30 | + private String deviceNo; | ||
| 31 | + | ||
| 32 | + @Schema(description = "设备名称", example = "张三") | ||
| 33 | + private String deviceName; | ||
| 34 | + | ||
| 35 | + @Schema(description = "设备状态") | ||
| 36 | + private Integer deviceState; | ||
| 37 | + | ||
| 38 | +} | ||
| 0 | \ No newline at end of file | 39 | \ No newline at end of file |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/deviceuser/vo/DeviceUserRespVO.java
0 → 100644
| 1 | +package com.zteits.urbanops.module.garden.controller.admin.deviceuser.vo; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import lombok.*; | ||
| 5 | +import java.util.*; | ||
| 6 | +import org.springframework.format.annotation.DateTimeFormat; | ||
| 7 | +import java.time.LocalDateTime; | ||
| 8 | +import cn.idev.excel.annotation.*; | ||
| 9 | + | ||
| 10 | +@Schema(description = "管理后台 - 设备用户关系 Response VO") | ||
| 11 | +@Data | ||
| 12 | +@ExcelIgnoreUnannotated | ||
| 13 | +public class DeviceUserRespVO { | ||
| 14 | + | ||
| 15 | + @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "12043") | ||
| 16 | + @ExcelProperty("ID") | ||
| 17 | + private Long id; | ||
| 18 | + | ||
| 19 | + @Schema(description = "归属(一级部门id)", requiredMode = Schema.RequiredMode.REQUIRED, example = "22641") | ||
| 20 | + @ExcelProperty("归属(一级部门id)") | ||
| 21 | + private Long companyId; | ||
| 22 | + | ||
| 23 | + @Schema(description = "部门ID(道路负责部门id)", requiredMode = Schema.RequiredMode.REQUIRED, example = "15793") | ||
| 24 | + @ExcelProperty("部门ID(道路负责部门id)") | ||
| 25 | + private Long deptId; | ||
| 26 | + | ||
| 27 | + @Schema(description = "提交人用户ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "7034") | ||
| 28 | + @ExcelProperty("提交人用户ID") | ||
| 29 | + private Long userId; | ||
| 30 | + | ||
| 31 | + @Schema(description = "提交人用户", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") | ||
| 32 | + @ExcelProperty("提交人用户") | ||
| 33 | + private String userName; | ||
| 34 | + | ||
| 35 | + @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") | ||
| 36 | + @ExcelProperty("产品名称") | ||
| 37 | + private String productName; | ||
| 38 | + | ||
| 39 | + @Schema(description = "设备标识", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 40 | + @ExcelProperty("设备标识") | ||
| 41 | + private String deviceNo; | ||
| 42 | + | ||
| 43 | + @Schema(description = "设备名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") | ||
| 44 | + @ExcelProperty("设备名称") | ||
| 45 | + private String deviceName; | ||
| 46 | + | ||
| 47 | + @Schema(description = "设备状态 1:在线;2:离线;3:未知", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 48 | + @ExcelProperty("设备状态 1:在线;2:离线;3:未知") | ||
| 49 | + private Integer deviceState; | ||
| 50 | + | ||
| 51 | + @Schema(description = "创建人", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") | ||
| 52 | + @ExcelProperty("创建人") | ||
| 53 | + private String creatorName; | ||
| 54 | + | ||
| 55 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 56 | + @ExcelProperty("创建时间") | ||
| 57 | + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | ||
| 58 | + private LocalDateTime createTime; | ||
| 59 | + | ||
| 60 | + | ||
| 61 | +} |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/deviceuser/vo/DeviceUserSaveReqVO.java
0 → 100644
| 1 | +package com.zteits.urbanops.module.garden.controller.admin.deviceuser.vo; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import lombok.*; | ||
| 5 | +import java.util.*; | ||
| 6 | +import jakarta.validation.constraints.*; | ||
| 7 | + | ||
| 8 | +@Schema(description = "管理后台 - 设备用户关系新增/修改 Request VO") | ||
| 9 | +@Data | ||
| 10 | +public class DeviceUserSaveReqVO { | ||
| 11 | + | ||
| 12 | + @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "12043") | ||
| 13 | + private Long id; | ||
| 14 | + | ||
| 15 | + @Schema(description = "归属(一级部门id)", requiredMode = Schema.RequiredMode.REQUIRED, example = "22641") | ||
| 16 | + @NotNull(message = "归属(一级部门id)不能为空") | ||
| 17 | + private Long companyId; | ||
| 18 | + | ||
| 19 | + @Schema(description = "部门ID(道路负责部门id)", requiredMode = Schema.RequiredMode.REQUIRED, example = "15793") | ||
| 20 | + @NotNull(message = "部门ID(道路负责部门id)不能为空") | ||
| 21 | + private Long deptId; | ||
| 22 | + | ||
| 23 | + @Schema(description = "提交人用户ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "7034") | ||
| 24 | + @NotNull(message = "提交人用户ID不能为空") | ||
| 25 | + private Long userId; | ||
| 26 | + | ||
| 27 | + @Schema(description = "提交人用户", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") | ||
| 28 | + @NotEmpty(message = "提交人用户不能为空") | ||
| 29 | + private String userName; | ||
| 30 | + | ||
| 31 | + @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") | ||
| 32 | + @NotEmpty(message = "产品名称不能为空") | ||
| 33 | + private String productName; | ||
| 34 | + | ||
| 35 | + @Schema(description = "设备标识", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 36 | + @NotEmpty(message = "设备标识不能为空") | ||
| 37 | + private String deviceNo; | ||
| 38 | + | ||
| 39 | + @Schema(description = "设备名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") | ||
| 40 | + @NotEmpty(message = "设备名称不能为空") | ||
| 41 | + private String deviceName; | ||
| 42 | + | ||
| 43 | + @Schema(description = "设备状态 1:在线;2:离线;3:未知", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 44 | + @NotEmpty(message = "设备状态不能为空") | ||
| 45 | + private Integer deviceState; | ||
| 46 | + | ||
| 47 | + @Schema(description = "创建人", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") | ||
| 48 | + @NotEmpty(message = "创建人不能为空") | ||
| 49 | + private String creatorName; | ||
| 50 | + | ||
| 51 | + @Schema(description = "更新者", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") | ||
| 52 | + @NotEmpty(message = "更新者不能为空") | ||
| 53 | + private String updaterName; | ||
| 54 | + | ||
| 55 | +} | ||
| 0 | \ No newline at end of file | 56 | \ No newline at end of file |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/dal/dataobject/deviceuser/DeviceUserDO.java
0 → 100644
| 1 | +package com.zteits.urbanops.module.garden.dal.dataobject.deviceuser; | ||
| 2 | + | ||
| 3 | +import lombok.*; | ||
| 4 | +import java.util.*; | ||
| 5 | +import java.time.LocalDateTime; | ||
| 6 | +import java.time.LocalDateTime; | ||
| 7 | +import com.baomidou.mybatisplus.annotation.*; | ||
| 8 | +import com.zteits.urbanops.framework.mybatis.core.dataobject.BaseDO; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * 设备用户关系 DO | ||
| 12 | + * | ||
| 13 | + * @author 超级管理员 | ||
| 14 | + */ | ||
| 15 | +@TableName("garden_device_user") | ||
| 16 | +@KeySequence("garden_device_user_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | ||
| 17 | +@Data | ||
| 18 | +@EqualsAndHashCode(callSuper = true) | ||
| 19 | +@ToString(callSuper = true) | ||
| 20 | +@Builder | ||
| 21 | +@NoArgsConstructor | ||
| 22 | +@AllArgsConstructor | ||
| 23 | +public class DeviceUserDO extends BaseDO { | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * ID | ||
| 27 | + */ | ||
| 28 | + @TableId | ||
| 29 | + private Long id; | ||
| 30 | + /** | ||
| 31 | + * 归属(一级部门id) | ||
| 32 | + */ | ||
| 33 | + private Long companyId; | ||
| 34 | + /** | ||
| 35 | + * 部门ID(道路负责部门id) | ||
| 36 | + */ | ||
| 37 | + private Long deptId; | ||
| 38 | + /** | ||
| 39 | + * 提交人用户ID | ||
| 40 | + */ | ||
| 41 | + private Long userId; | ||
| 42 | + /** | ||
| 43 | + * 提交人用户 | ||
| 44 | + */ | ||
| 45 | + private String userName; | ||
| 46 | + /** | ||
| 47 | + * 产品名称 | ||
| 48 | + */ | ||
| 49 | + private String productName; | ||
| 50 | + /** | ||
| 51 | + * 设备标识 | ||
| 52 | + */ | ||
| 53 | + private String deviceNo; | ||
| 54 | + /** | ||
| 55 | + * 设备名称 | ||
| 56 | + */ | ||
| 57 | + private String deviceName; | ||
| 58 | + /** | ||
| 59 | + * 设备状态 1:在线;2:离线;3:未知 | ||
| 60 | + */ | ||
| 61 | + private Integer deviceState; | ||
| 62 | + /** | ||
| 63 | + * 创建人 | ||
| 64 | + */ | ||
| 65 | + private String creatorName; | ||
| 66 | + /** | ||
| 67 | + * 更新者 | ||
| 68 | + */ | ||
| 69 | + private String updaterName; | ||
| 70 | + | ||
| 71 | + | ||
| 72 | +} |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/dal/mysql/deviceuser/DeviceUserMapper.java
0 → 100644
| 1 | +package com.zteits.urbanops.module.garden.dal.mysql.deviceuser; | ||
| 2 | + | ||
| 3 | +import java.util.*; | ||
| 4 | + | ||
| 5 | +import com.zteits.urbanops.framework.common.pojo.PageResult; | ||
| 6 | +import com.zteits.urbanops.framework.mybatis.core.query.LambdaQueryWrapperX; | ||
| 7 | +import com.zteits.urbanops.framework.mybatis.core.mapper.BaseMapperX; | ||
| 8 | +import com.zteits.urbanops.module.garden.dal.dataobject.deviceuser.DeviceUserDO; | ||
| 9 | +import org.apache.ibatis.annotations.Mapper; | ||
| 10 | +import com.zteits.urbanops.module.garden.controller.admin.deviceuser.vo.*; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * 设备用户关系 Mapper | ||
| 14 | + * | ||
| 15 | + * @author 超级管理员 | ||
| 16 | + */ | ||
| 17 | +@Mapper | ||
| 18 | +public interface DeviceUserMapper extends BaseMapperX<DeviceUserDO> { | ||
| 19 | + | ||
| 20 | + default PageResult<DeviceUserDO> selectPage(DeviceUserPageReqVO reqVO) { | ||
| 21 | + return selectPage(reqVO, new LambdaQueryWrapperX<DeviceUserDO>() | ||
| 22 | + .eqIfPresent(DeviceUserDO::getCompanyId, reqVO.getCompanyId()) | ||
| 23 | + .eqIfPresent(DeviceUserDO::getDeptId, reqVO.getDeptId()) | ||
| 24 | + .likeIfPresent(DeviceUserDO::getUserName, reqVO.getUserName()) | ||
| 25 | + .likeIfPresent(DeviceUserDO::getProductName, reqVO.getProductName()) | ||
| 26 | + .eqIfPresent(DeviceUserDO::getDeviceNo, reqVO.getDeviceNo()) | ||
| 27 | + .likeIfPresent(DeviceUserDO::getDeviceName, reqVO.getDeviceName()) | ||
| 28 | + .eqIfPresent(DeviceUserDO::getDeviceState, reqVO.getDeviceState()) | ||
| 29 | + .orderByDesc(DeviceUserDO::getId)); | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | +} | ||
| 0 | \ No newline at end of file | 33 | \ No newline at end of file |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/deviceuser/DeviceUserService.java
0 → 100644
| 1 | +package com.zteits.urbanops.module.garden.service.deviceuser; | ||
| 2 | + | ||
| 3 | +import java.util.*; | ||
| 4 | +import jakarta.validation.*; | ||
| 5 | +import com.zteits.urbanops.module.garden.controller.admin.deviceuser.vo.*; | ||
| 6 | +import com.zteits.urbanops.module.garden.dal.dataobject.deviceuser.DeviceUserDO; | ||
| 7 | +import com.zteits.urbanops.framework.common.pojo.PageResult; | ||
| 8 | +import com.zteits.urbanops.framework.common.pojo.PageParam; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * 设备用户关系 Service 接口 | ||
| 12 | + * | ||
| 13 | + * @author 超级管理员 | ||
| 14 | + */ | ||
| 15 | +public interface DeviceUserService { | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * 创建设备用户关系 | ||
| 19 | + * | ||
| 20 | + * @param createReqVO 创建信息 | ||
| 21 | + * @return 编号 | ||
| 22 | + */ | ||
| 23 | + Long createDeviceUser(@Valid DeviceUserSaveReqVO createReqVO); | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * 更新设备用户关系 | ||
| 27 | + * | ||
| 28 | + * @param updateReqVO 更新信息 | ||
| 29 | + */ | ||
| 30 | + void updateDeviceUser(@Valid DeviceUserSaveReqVO updateReqVO); | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * 删除设备用户关系 | ||
| 34 | + * | ||
| 35 | + * @param id 编号 | ||
| 36 | + */ | ||
| 37 | + void deleteDeviceUser(Long id); | ||
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * 批量删除设备用户关系 | ||
| 41 | + * | ||
| 42 | + * @param ids 编号 | ||
| 43 | + */ | ||
| 44 | + void deleteDeviceUserListByIds(List<Long> ids); | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * 获得设备用户关系 | ||
| 48 | + * | ||
| 49 | + * @param id 编号 | ||
| 50 | + * @return 设备用户关系 | ||
| 51 | + */ | ||
| 52 | + DeviceUserDO getDeviceUser(Long id); | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * 获得设备用户关系分页 | ||
| 56 | + * | ||
| 57 | + * @param pageReqVO 分页查询 | ||
| 58 | + * @return 设备用户关系分页 | ||
| 59 | + */ | ||
| 60 | + PageResult<DeviceUserDO> getDeviceUserPage(DeviceUserPageReqVO pageReqVO); | ||
| 61 | + | ||
| 62 | +} | ||
| 0 | \ No newline at end of file | 63 | \ No newline at end of file |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/deviceuser/DeviceUserServiceImpl.java
0 → 100644
| 1 | +package com.zteits.urbanops.module.garden.service.deviceuser; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 4 | +import org.springframework.stereotype.Service; | ||
| 5 | +import jakarta.annotation.Resource; | ||
| 6 | +import org.springframework.validation.annotation.Validated; | ||
| 7 | +import org.springframework.transaction.annotation.Transactional; | ||
| 8 | + | ||
| 9 | +import java.util.*; | ||
| 10 | +import com.zteits.urbanops.module.garden.controller.admin.deviceuser.vo.*; | ||
| 11 | +import com.zteits.urbanops.module.garden.dal.dataobject.deviceuser.DeviceUserDO; | ||
| 12 | +import com.zteits.urbanops.framework.common.pojo.PageResult; | ||
| 13 | +import com.zteits.urbanops.framework.common.pojo.PageParam; | ||
| 14 | +import com.zteits.urbanops.framework.common.util.object.BeanUtils; | ||
| 15 | + | ||
| 16 | +import com.zteits.urbanops.module.garden.dal.mysql.deviceuser.DeviceUserMapper; | ||
| 17 | + | ||
| 18 | +import static com.zteits.urbanops.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 19 | +import static com.zteits.urbanops.framework.common.util.collection.CollectionUtils.convertList; | ||
| 20 | +import static com.zteits.urbanops.framework.common.util.collection.CollectionUtils.diffList; | ||
| 21 | +import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.*; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * 设备用户关系 Service 实现类 | ||
| 25 | + * | ||
| 26 | + * @author 超级管理员 | ||
| 27 | + */ | ||
| 28 | +@Service | ||
| 29 | +@Validated | ||
| 30 | +public class DeviceUserServiceImpl implements DeviceUserService { | ||
| 31 | + | ||
| 32 | + @Resource | ||
| 33 | + private DeviceUserMapper deviceUserMapper; | ||
| 34 | + | ||
| 35 | + @Override | ||
| 36 | + public Long createDeviceUser(DeviceUserSaveReqVO createReqVO) { | ||
| 37 | + // 插入 | ||
| 38 | + DeviceUserDO deviceUser = BeanUtils.toBean(createReqVO, DeviceUserDO.class); | ||
| 39 | + deviceUserMapper.insert(deviceUser); | ||
| 40 | + | ||
| 41 | + // 返回 | ||
| 42 | + return deviceUser.getId(); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + @Override | ||
| 46 | + public void updateDeviceUser(DeviceUserSaveReqVO updateReqVO) { | ||
| 47 | + // 校验存在 | ||
| 48 | + validateDeviceUserExists(updateReqVO.getId()); | ||
| 49 | + // 更新 | ||
| 50 | + DeviceUserDO updateObj = BeanUtils.toBean(updateReqVO, DeviceUserDO.class); | ||
| 51 | + deviceUserMapper.updateById(updateObj); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + @Override | ||
| 55 | + public void deleteDeviceUser(Long id) { | ||
| 56 | + // 校验存在 | ||
| 57 | + validateDeviceUserExists(id); | ||
| 58 | + // 删除 | ||
| 59 | + deviceUserMapper.deleteById(id); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + @Override | ||
| 63 | + public void deleteDeviceUserListByIds(List<Long> ids) { | ||
| 64 | + // 删除 | ||
| 65 | + deviceUserMapper.deleteByIds(ids); | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + | ||
| 69 | + private void validateDeviceUserExists(Long id) { | ||
| 70 | + if (deviceUserMapper.selectById(id) == null) { | ||
| 71 | + //throw exception(DEVICE_USER_NOT_EXISTS); | ||
| 72 | + } | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + @Override | ||
| 76 | + public DeviceUserDO getDeviceUser(Long id) { | ||
| 77 | + return deviceUserMapper.selectById(id); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + @Override | ||
| 81 | + public PageResult<DeviceUserDO> getDeviceUserPage(DeviceUserPageReqVO pageReqVO) { | ||
| 82 | + return deviceUserMapper.selectPage(pageReqVO); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | +} | ||
| 0 | \ No newline at end of file | 86 | \ No newline at end of file |
urbanops-module-garden/src/main/resources/mapper/deviceuser/DeviceUserMapper.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
| 3 | +<mapper namespace="com.zteits.urbanops.module.garden.dal.mysql.deviceuser.DeviceUserMapper"> | ||
| 4 | + | ||
| 5 | + <!-- | ||
| 6 | + 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。 | ||
| 7 | + 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。 | ||
| 8 | + 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。 | ||
| 9 | + 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ | ||
| 10 | + --> | ||
| 11 | + | ||
| 12 | +</mapper> | ||
| 0 | \ No newline at end of file | 13 | \ No newline at end of file |
urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/controller/admin/dept/DeptController.java
| @@ -11,6 +11,7 @@ import com.zteits.urbanops.module.system.controller.admin.dept.vo.dept.DeptSaveR | @@ -11,6 +11,7 @@ import com.zteits.urbanops.module.system.controller.admin.dept.vo.dept.DeptSaveR | ||
| 11 | import com.zteits.urbanops.module.system.controller.admin.dept.vo.dept.DeptSimpleRespVO; | 11 | import com.zteits.urbanops.module.system.controller.admin.dept.vo.dept.DeptSimpleRespVO; |
| 12 | import com.zteits.urbanops.module.system.dal.dataobject.dept.DeptDO; | 12 | import com.zteits.urbanops.module.system.dal.dataobject.dept.DeptDO; |
| 13 | import com.zteits.urbanops.module.system.service.dept.DeptService; | 13 | import com.zteits.urbanops.module.system.service.dept.DeptService; |
| 14 | +import com.zteits.urbanops.module.system.util.tree.Dept; | ||
| 14 | import io.swagger.v3.oas.annotations.Operation; | 15 | import io.swagger.v3.oas.annotations.Operation; |
| 15 | import io.swagger.v3.oas.annotations.Parameter; | 16 | import io.swagger.v3.oas.annotations.Parameter; |
| 16 | import io.swagger.v3.oas.annotations.tags.Tag; | 17 | import io.swagger.v3.oas.annotations.tags.Tag; |
| @@ -115,4 +116,13 @@ public class DeptController { | @@ -115,4 +116,13 @@ public class DeptController { | ||
| 115 | List<DeptDO> list = deptService.getSubDeptList(id); | 116 | List<DeptDO> list = deptService.getSubDeptList(id); |
| 116 | return success(BeanUtils.toBean(list, DeptRespVO.class)); | 117 | return success(BeanUtils.toBean(list, DeptRespVO.class)); |
| 117 | } | 118 | } |
| 119 | + | ||
| 120 | + @GetMapping("/dept-user-tree") | ||
| 121 | + @Operation(summary = "获取部门用户tree") | ||
| 122 | + //@PreAuthorize("@ss.hasPermission('system:dept:query')") | ||
| 123 | + public CommonResult<List<Dept>> getDeptAndUserTree() { | ||
| 124 | + List<Dept> list = deptService.getDeptAndUserTree(); | ||
| 125 | + return success(list); | ||
| 126 | + } | ||
| 127 | + | ||
| 118 | } | 128 | } |
urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/dept/DeptService.java
| @@ -4,6 +4,7 @@ import com.zteits.urbanops.framework.common.util.collection.CollectionUtils; | @@ -4,6 +4,7 @@ import com.zteits.urbanops.framework.common.util.collection.CollectionUtils; | ||
| 4 | import com.zteits.urbanops.module.system.controller.admin.dept.vo.dept.DeptListReqVO; | 4 | import com.zteits.urbanops.module.system.controller.admin.dept.vo.dept.DeptListReqVO; |
| 5 | import com.zteits.urbanops.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO; | 5 | import com.zteits.urbanops.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO; |
| 6 | import com.zteits.urbanops.module.system.dal.dataobject.dept.DeptDO; | 6 | import com.zteits.urbanops.module.system.dal.dataobject.dept.DeptDO; |
| 7 | +import com.zteits.urbanops.module.system.util.tree.Dept; | ||
| 7 | 8 | ||
| 8 | import java.util.*; | 9 | import java.util.*; |
| 9 | 10 | ||
| @@ -144,4 +145,10 @@ public interface DeptService { | @@ -144,4 +145,10 @@ public interface DeptService { | ||
| 144 | * @return 末级list | 145 | * @return 末级list |
| 145 | */ | 146 | */ |
| 146 | List<DeptDO> getLastDeptList(Long id); | 147 | List<DeptDO> getLastDeptList(Long id); |
| 148 | + | ||
| 149 | + /** | ||
| 150 | + * 获取部门树 | ||
| 151 | + * @return 部门树 | ||
| 152 | + */ | ||
| 153 | + List<Dept> getDeptAndUserTree(); | ||
| 147 | } | 154 | } |
urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/dept/DeptServiceImpl.java
| 1 | package com.zteits.urbanops.module.system.service.dept; | 1 | package com.zteits.urbanops.module.system.service.dept; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | +import cn.hutool.core.collection.CollectionUtil; | ||
| 4 | import cn.hutool.core.util.ObjectUtil; | 5 | import cn.hutool.core.util.ObjectUtil; |
| 5 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 6 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| 6 | import com.zteits.urbanops.framework.common.enums.CommonStatusEnum; | 7 | import com.zteits.urbanops.framework.common.enums.CommonStatusEnum; |
| 8 | +import com.zteits.urbanops.framework.common.util.collection.CollectionUtils; | ||
| 7 | import com.zteits.urbanops.framework.common.util.object.BeanUtils; | 9 | import com.zteits.urbanops.framework.common.util.object.BeanUtils; |
| 8 | import com.zteits.urbanops.framework.datapermission.core.annotation.DataPermission; | 10 | import com.zteits.urbanops.framework.datapermission.core.annotation.DataPermission; |
| 9 | import com.zteits.urbanops.framework.security.core.util.SecurityFrameworkUtils; | 11 | import com.zteits.urbanops.framework.security.core.util.SecurityFrameworkUtils; |
| 10 | import com.zteits.urbanops.module.system.controller.admin.dept.vo.dept.DeptListReqVO; | 12 | import com.zteits.urbanops.module.system.controller.admin.dept.vo.dept.DeptListReqVO; |
| 11 | import com.zteits.urbanops.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO; | 13 | import com.zteits.urbanops.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO; |
| 12 | import com.zteits.urbanops.module.system.dal.dataobject.dept.DeptDO; | 14 | import com.zteits.urbanops.module.system.dal.dataobject.dept.DeptDO; |
| 15 | +import com.zteits.urbanops.module.system.dal.dataobject.user.AdminUserDO; | ||
| 13 | import com.zteits.urbanops.module.system.dal.mysql.dept.DeptMapper; | 16 | import com.zteits.urbanops.module.system.dal.mysql.dept.DeptMapper; |
| 17 | +import com.zteits.urbanops.module.system.dal.mysql.user.AdminUserMapper; | ||
| 14 | import com.zteits.urbanops.module.system.dal.redis.RedisKeyConstants; | 18 | import com.zteits.urbanops.module.system.dal.redis.RedisKeyConstants; |
| 15 | import com.google.common.annotations.VisibleForTesting; | 19 | import com.google.common.annotations.VisibleForTesting; |
| 16 | import com.zteits.urbanops.module.system.util.DeptTreeUtil; | 20 | import com.zteits.urbanops.module.system.util.DeptTreeUtil; |
| 21 | +import com.zteits.urbanops.module.system.util.tree.Dept; | ||
| 22 | +import com.zteits.urbanops.module.system.util.tree.TreeUtils; | ||
| 23 | +import com.zteits.urbanops.module.system.util.tree.UserDO; | ||
| 17 | import lombok.extern.slf4j.Slf4j; | 24 | import lombok.extern.slf4j.Slf4j; |
| 18 | import org.springframework.cache.annotation.CacheEvict; | 25 | import org.springframework.cache.annotation.CacheEvict; |
| 19 | import org.springframework.cache.annotation.Cacheable; | 26 | import org.springframework.cache.annotation.Cacheable; |
| @@ -41,6 +48,9 @@ public class DeptServiceImpl implements DeptService { | @@ -41,6 +48,9 @@ public class DeptServiceImpl implements DeptService { | ||
| 41 | @Resource | 48 | @Resource |
| 42 | private DeptMapper deptMapper; | 49 | private DeptMapper deptMapper; |
| 43 | 50 | ||
| 51 | + @Resource | ||
| 52 | + private AdminUserMapper userMapper; | ||
| 53 | + | ||
| 44 | @Override | 54 | @Override |
| 45 | @CacheEvict(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST, | 55 | @CacheEvict(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST, |
| 46 | allEntries = true) // allEntries 清空所有缓存,因为操作一个部门,涉及到多个缓存 | 56 | allEntries = true) // allEntries 清空所有缓存,因为操作一个部门,涉及到多个缓存 |
| @@ -270,4 +280,46 @@ public class DeptServiceImpl implements DeptService { | @@ -270,4 +280,46 @@ public class DeptServiceImpl implements DeptService { | ||
| 270 | List<DeptDO> allList = getSubDeptAllList(); | 280 | List<DeptDO> allList = getSubDeptAllList(); |
| 271 | return DeptTreeUtil.findLeafDeptDOs(allList, id); | 281 | return DeptTreeUtil.findLeafDeptDOs(allList, id); |
| 272 | } | 282 | } |
| 283 | + | ||
| 284 | + @Override | ||
| 285 | + public List<Dept> getDeptAndUserTree() { | ||
| 286 | + QueryWrapper<DeptDO> sql = new QueryWrapper<>(); | ||
| 287 | + sql.lambda().eq(DeptDO::getDeleted, 0); | ||
| 288 | + List<DeptDO> deptList = deptMapper.selectList(sql); | ||
| 289 | + List<Dept> deptListT = new ArrayList<>(); | ||
| 290 | + for(DeptDO deptDO : deptList){ | ||
| 291 | + Dept dept = new Dept(); | ||
| 292 | + dept.setId(deptDO.getId()); | ||
| 293 | + dept.setName(deptDO.getName()); | ||
| 294 | + dept.setParentId(deptDO.getParentId()); | ||
| 295 | + deptListT.add(dept); | ||
| 296 | + } | ||
| 297 | + if(CollectionUtil.isEmpty(deptListT)){ | ||
| 298 | + return deptListT; | ||
| 299 | + } | ||
| 300 | + | ||
| 301 | + | ||
| 302 | + /*2.查询用户*/ | ||
| 303 | + QueryWrapper<AdminUserDO> userSql = new QueryWrapper<>(); | ||
| 304 | + userSql.lambda().eq(AdminUserDO::getDeleted, 0); | ||
| 305 | + List<AdminUserDO> userList = userMapper.selectList(userSql); | ||
| 306 | + if(CollectionUtil.isEmpty(userList)){ | ||
| 307 | + return deptListT; | ||
| 308 | + } | ||
| 309 | + List<UserDO> userDOList = new ArrayList<>(); | ||
| 310 | + for(AdminUserDO adminUserDO :userList){ | ||
| 311 | + UserDO userDO = new UserDO(); | ||
| 312 | + userDO.setUserId(adminUserDO.getId()); | ||
| 313 | + userDO.setUsername(adminUserDO.getUsername()); | ||
| 314 | + userDO.setDeptId(adminUserDO.getDeptId()); | ||
| 315 | + userDOList.add(userDO); | ||
| 316 | + } | ||
| 317 | + | ||
| 318 | + | ||
| 319 | + for(Dept dept : deptListT){ | ||
| 320 | + List<UserDO> userR = userDOList.stream().filter(user -> user.getDeptId().equals(dept.getId())).collect(Collectors.toList()); | ||
| 321 | + dept.userList = userR; | ||
| 322 | + } | ||
| 323 | + return TreeUtils.getTreeList(deptListT); | ||
| 324 | + } | ||
| 273 | } | 325 | } |
urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/util/tree/Dept.java
0 → 100644
| 1 | +package com.zteits.urbanops.module.system.util.tree; | ||
| 2 | + | ||
| 3 | +import com.zteits.urbanops.module.system.dal.dataobject.user.AdminUserDO; | ||
| 4 | + | ||
| 5 | +import java.util.List; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * Copyright: Copyright (c) 2017 zteits | ||
| 9 | + * | ||
| 10 | + * @ClassName: Menu.java | ||
| 11 | + * @Description: | ||
| 12 | + * @version: v1.0.0 | ||
| 13 | + * @author: wangfs | ||
| 14 | + * @date: 2019-05-23 12:39 | ||
| 15 | + * Modification History: | ||
| 16 | + * Date Author Version Description | ||
| 17 | + * ---------------------------------------------------------* | ||
| 18 | + * 2019-05-23 wangfs v1.0.0 创建 | ||
| 19 | + */ | ||
| 20 | + | ||
| 21 | +public class Dept implements TreeEntity<Dept> { | ||
| 22 | + public Long id; | ||
| 23 | + public String name; | ||
| 24 | + public Long parentId; | ||
| 25 | + public List<Dept> childList; | ||
| 26 | + | ||
| 27 | + public List<UserDO> userList; | ||
| 28 | + | ||
| 29 | + @Override | ||
| 30 | + public Long getId() { | ||
| 31 | + return id; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + public void setId(Long id) { | ||
| 35 | + this.id = id; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + public String getName() { | ||
| 39 | + return name; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + public void setName(String name) { | ||
| 43 | + this.name = name; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + @Override | ||
| 47 | + public Long getParentId() { | ||
| 48 | + return parentId; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public void setParentId(Long parentId) { | ||
| 52 | + this.parentId = parentId; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public List<Dept> getChildList() { | ||
| 56 | + return childList; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + @Override | ||
| 60 | + public void setChildren(List<Dept> childList) { | ||
| 61 | + this.childList = childList; | ||
| 62 | + } | ||
| 63 | +} | ||
| 64 | + |
urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/util/tree/TreeEntity.java
0 → 100644
urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/util/tree/TreeTest.java
0 → 100644
| 1 | +package com.zteits.urbanops.module.system.util.tree; | ||
| 2 | +import com.alibaba.fastjson.JSONObject; | ||
| 3 | + | ||
| 4 | +import java.util.ArrayList; | ||
| 5 | +import java.util.List; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * Copyright: Copyright (c) 2017 zteits | ||
| 9 | + * | ||
| 10 | + * @ClassName: TreeTest.java | ||
| 11 | + * @Description: | ||
| 12 | + * @version: v1.0.0 | ||
| 13 | + * @author: wangfs | ||
| 14 | + * @date: 2019-05-23 12:41 | ||
| 15 | + * Modification History: | ||
| 16 | + * Date Author Version Description | ||
| 17 | + * ---------------------------------------------------------* | ||
| 18 | + * 2019-05-23 wangfs v1.0.0 创建 | ||
| 19 | + */ | ||
| 20 | + | ||
| 21 | + | ||
| 22 | +public class TreeTest { | ||
| 23 | + public static void main(String[] args) { | ||
| 24 | + List<Dept> list = new ArrayList<>(); | ||
| 25 | +// Menu menu1 = new Menu(); | ||
| 26 | +// menu1.setId(1L); | ||
| 27 | +// menu1.setParentId(0L); | ||
| 28 | +// menu1.setName("菜单1"); | ||
| 29 | +// list.add(menu1); | ||
| 30 | +// | ||
| 31 | +// Menu menu2 = new Menu(); | ||
| 32 | +// menu2.setId(2L); | ||
| 33 | +// menu2.setParentId(0L); | ||
| 34 | +// menu2.setName("菜单2"); | ||
| 35 | +// list.add(menu2); | ||
| 36 | +// | ||
| 37 | +// Menu menu3 = new Menu(); | ||
| 38 | +// menu3.setId(3L); | ||
| 39 | +// menu3.setParentId(1L); | ||
| 40 | +// menu3.setName("菜单11"); | ||
| 41 | +// list.add(menu3); | ||
| 42 | +// | ||
| 43 | +// Menu menu4 = new Menu(); | ||
| 44 | +// menu4.setId(4L); | ||
| 45 | +// menu4.setParentId(3L); | ||
| 46 | +// menu4.setName("菜单111"); | ||
| 47 | +// list.add(menu4);menu4 | ||
| 48 | + Dept menu1 = new Dept(); | ||
| 49 | + menu1.setId(1L); | ||
| 50 | + menu1.setParentId(-1L); | ||
| 51 | + menu1.setName("首页"); | ||
| 52 | + list.add(menu1); | ||
| 53 | + Dept menu2 = new Dept(); | ||
| 54 | + menu2.setId(2L); | ||
| 55 | + menu2.setParentId(-1L); | ||
| 56 | + menu2.setName("系统管理"); | ||
| 57 | + list.add(menu2); | ||
| 58 | + Dept menu3 = new Dept(); | ||
| 59 | + menu3.setId(-1L); | ||
| 60 | + menu3.setParentId(0L); | ||
| 61 | + menu3.setName("根节点"); | ||
| 62 | + list.add(menu3); | ||
| 63 | + List<Dept> menus = TreeUtils.getTreeList(list); | ||
| 64 | + System.out.println(JSONObject.toJSON(menus)); | ||
| 65 | + } | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | + |
urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/util/tree/TreeUtils.java
0 → 100644
| 1 | +package com.zteits.urbanops.module.system.util.tree; | ||
| 2 | + | ||
| 3 | +import org.springframework.util.CollectionUtils; | ||
| 4 | + | ||
| 5 | +import java.util.ArrayList; | ||
| 6 | +import java.util.List; | ||
| 7 | +/** | ||
| 8 | + * Copyright: Copyright (c) 2017 zteits | ||
| 9 | + * | ||
| 10 | + * @ClassName: TreeUtils.java | ||
| 11 | + * @Description: | ||
| 12 | + * @version: v1.0.0 | ||
| 13 | + * @author: wangfs | ||
| 14 | + * @date: 2019-05-23 12:40 | ||
| 15 | + * Modification History: | ||
| 16 | + * Date Author Version Description | ||
| 17 | + * ---------------------------------------------------------* | ||
| 18 | + * 2019-05-23 wangfs v1.0.0 创建 | ||
| 19 | + */ | ||
| 20 | + | ||
| 21 | + | ||
| 22 | +/** | ||
| 23 | + * *解析树形数据工具类 | ||
| 24 | + */ | ||
| 25 | +public class TreeUtils { | ||
| 26 | + /** | ||
| 27 | + * * 解析树形数据 | ||
| 28 | + * | ||
| 29 | + * @param entityList | ||
| 30 | + * @return | ||
| 31 | + */ | ||
| 32 | + public static <E extends TreeEntity<E>> List<E> getTreeList(List<E> entityList) { | ||
| 33 | + List<E> resultList = new ArrayList<>(); | ||
| 34 | + //没有根节点全部加入 | ||
| 35 | + if(CollectionUtils.isEmpty(resultList)){ | ||
| 36 | + for (E entity : entityList) { | ||
| 37 | + resultList.add(entity); | ||
| 38 | + } | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + // 获取每个顶层元素的子数据集合 | ||
| 42 | + List<E> childListAll = new ArrayList<>(); | ||
| 43 | + for (E entity : resultList) { | ||
| 44 | + List<E> childList = getSubList(entity.getId(), entityList); | ||
| 45 | + if(!CollectionUtils.isEmpty(childList)){ | ||
| 46 | + entity.setChildren(childList); | ||
| 47 | + childListAll.addAll(childList); | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + } | ||
| 51 | + /** | ||
| 52 | + * 因为childListAll中的对象都是从resultList添加的,删除掉 | ||
| 53 | + */ | ||
| 54 | + if(!CollectionUtils.isEmpty(childListAll)){ | ||
| 55 | + resultList.removeAll(childListAll); | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + return resultList; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + /** | ||
| 62 | + * * 获取子数据集合 | ||
| 63 | + * | ||
| 64 | + * @param id | ||
| 65 | + * @param entityList | ||
| 66 | + * @return | ||
| 67 | + */ | ||
| 68 | + private static <E extends TreeEntity<E>> List<E> getSubList(Long id, List<E> entityList) { | ||
| 69 | + List<E> childList = new ArrayList<>(); | ||
| 70 | + Long parentId; | ||
| 71 | + //子集的直接子对象 | ||
| 72 | + for (E entity : entityList) { | ||
| 73 | + parentId = entity.getParentId(); | ||
| 74 | + if (id.equals(parentId)) { | ||
| 75 | + childList.add(entity); | ||
| 76 | + } | ||
| 77 | + } | ||
| 78 | + // 子集的间接子对象 | ||
| 79 | + for (E entity : childList) { | ||
| 80 | + entity.setChildren(getSubList(entity.getId(), entityList)); | ||
| 81 | + } | ||
| 82 | + // 递归退出条件 | ||
| 83 | + if (childList.size() == 0) { | ||
| 84 | + return null; | ||
| 85 | + } | ||
| 86 | + return childList; | ||
| 87 | + } | ||
| 88 | +} | ||
| 89 | + | ||
| 90 | + |
urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/util/tree/UserDO.java
0 → 100644