package com.epmet.controller; import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.dto.form.GovStaffRoleFormDTO; import com.epmet.dto.result.GovStaffRoleResultDTO; import com.epmet.dto.result.GovStaffRoleTemplateDTO; import com.epmet.dto.result.ResiGovRoleListResultDTO; import com.epmet.dto.result.RoleInfoResultDTO; import com.epmet.service.GovStaffRoleService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @RequestMapping("govstaffrole") @RestController public class GovStaffRoleController { @Autowired private GovStaffRoleService govStaffRoleService; /** * 根据客户ID查询该客户的角色列表 * @param customerId * @return */ @PostMapping("rolesbycustomer/{customerId}") public Result listGovStaffRolesByCustomer(@PathVariable("customerId") String customerId) { List roleEntities = govStaffRoleService.listRolesByCustomer(customerId); return new Result().ok(roleEntities); } /** * 查询角色模板列表 * @return */ @PostMapping("roletemplates") public Result listGovStaffRoleTemplates() { List roleTemplates = govStaffRoleService.listRoleTemplates(); return new Result().ok(roleTemplates); } /** * 使用id列表查询角色列表 * @param form * @return */ @PostMapping("getbyids") public Result> getByIds(@RequestBody GovStaffRoleFormDTO form) { List roleDTOS = new ArrayList<>(); List roleIdList = form.getRoleIdList(); if (!CollectionUtils.isEmpty(roleIdList)) { roleDTOS = roleIdList.stream().map(roleId -> govStaffRoleService.getDTOById(roleId)).collect(Collectors.toList()); } return new Result>().ok(roleDTOS); } /** * @param tokenDTO * @return ResiGovRoleListResultDTO * @author sun * @Description 获取居民端、工作端人员角色列表 */ @PostMapping("resigovrolelist") public Result resiGovRoleList(@LoginUser TokenDto tokenDTO){ return new Result().ok(govStaffRoleService.resiGovRoleList()); } /** * 更新客户的指定角色 * @param form * @return */ @PostMapping("update-role") public Result updateRole(@RequestBody GovStaffRoleFormDTO form) { ValidatorUtils.validateEntity(form, GovStaffRoleFormDTO.UpdateRoleGroup.class); if (govStaffRoleService.updateRole(form.getRoleId(), form.getRoleName()) == 0) { throw new RenException("修改角色信息失败"); } return new Result(); } /** * 更新排序序号 * @param form * @return */ @PostMapping("save-sortorder") public Result saveSortOrder(@RequestBody GovStaffRoleFormDTO form) { ValidatorUtils.validateEntity(form, GovStaffRoleFormDTO.SaveRoleOrderGroup.class); List roleIdList = form.getRoleIdList(); govStaffRoleService.saveSortOrder(roleIdList); return new Result(); } /** * @Description 根据角色key查询具有该key的所有角色列表 * @return * @author wxz * @date 2020.11.17 16:20 */ @PostMapping("list-roles-by-rolekey/{role-key}") public Result> listRolesByRoleKey(@PathVariable("role-key") String roleKey) { List roles = govStaffRoleService.listRolesByRoleKey(roleKey); return new Result>().ok(roles); } /** * @return com.epmet.commons.tools.utils.Result> * @param customerId * @author yinzuomei * @description 获取当前客户下-工作端角色列表 * @Date 2021/3/29 15:37 **/ @GetMapping("querycustomergovrolelist/{customerId}") Result> queryCustomerGovRoleList(@PathVariable("customerId") String customerId){ return new Result>().ok(govStaffRoleService.queryCustomerGovRoleList(customerId)); } }