package com.iailab.module.bpm.controller.admin.definition; import com.iailab.framework.common.enums.CommonStatusEnum; import com.iailab.framework.common.pojo.CommonResult; import com.iailab.framework.common.pojo.PageResult; import com.iailab.framework.common.util.object.BeanUtils; import com.iailab.module.bpm.controller.admin.definition.vo.group.BpmUserGroupPageReqVO; import com.iailab.module.bpm.controller.admin.definition.vo.group.BpmUserGroupRespVO; import com.iailab.module.bpm.controller.admin.definition.vo.group.BpmUserGroupSaveReqVO; import com.iailab.module.bpm.dal.dataobject.definition.BpmUserGroupDO; import com.iailab.module.bpm.service.definition.BpmUserGroupService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; import java.util.List; import static com.iailab.framework.common.pojo.CommonResult.success; import static com.iailab.framework.common.util.collection.CollectionUtils.convertList; @Tag(name = "管理后台 - 用户组") @RestController @RequestMapping("/bpm/user-group") @Validated public class BpmUserGroupController { @Resource private BpmUserGroupService userGroupService; @PostMapping("/create") @Operation(summary = "创建用户组") @PreAuthorize("@ss.hasPermission('bpm:user-group:create')") public CommonResult createUserGroup(@Valid @RequestBody BpmUserGroupSaveReqVO createReqVO) { return success(userGroupService.createUserGroup(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新用户组") @PreAuthorize("@ss.hasPermission('bpm:user-group:update')") public CommonResult updateUserGroup(@Valid @RequestBody BpmUserGroupSaveReqVO updateReqVO) { userGroupService.updateUserGroup(updateReqVO); return success(true); } @DeleteMapping("/delete") @Operation(summary = "删除用户组") @Parameter(name = "id", description = "编号", required = true) @PreAuthorize("@ss.hasPermission('bpm:user-group:delete')") public CommonResult deleteUserGroup(@RequestParam("id") Long id) { userGroupService.deleteUserGroup(id); return success(true); } @GetMapping("/get") @Operation(summary = "获得用户组") @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('bpm:user-group:query')") public CommonResult getUserGroup(@RequestParam("id") Long id) { BpmUserGroupDO userGroup = userGroupService.getUserGroup(id); return success(BeanUtils.toBean(userGroup, BpmUserGroupRespVO.class)); } @GetMapping("/page") @Operation(summary = "获得用户组分页") @PreAuthorize("@ss.hasPermission('bpm:user-group:query')") public CommonResult> getUserGroupPage(@Valid BpmUserGroupPageReqVO pageVO) { PageResult pageResult = userGroupService.getUserGroupPage(pageVO); return success(BeanUtils.toBean(pageResult, BpmUserGroupRespVO.class)); } @GetMapping("/simple-list") @Operation(summary = "获取用户组精简信息列表", description = "只包含被开启的用户组,主要用于前端的下拉选项") public CommonResult> getUserGroupSimpleList() { List list = userGroupService.getUserGroupListByStatus(CommonStatusEnum.ENABLE.getStatus()); return success(convertList(list, group -> new BpmUserGroupRespVO().setId(group.getId()).setName(group.getName()))); } }