| | |
| | | package cn.iocoder.yudao.module.hrm.controller.admin.salary; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.module.hrm.controller.admin.salary.vo.HrmSocialSecuritySchemeRespVO; |
| | | import cn.iocoder.yudao.module.hrm.controller.admin.salary.vo.HrmSocialSecuritySchemeSaveReqVO; |
| | | import cn.iocoder.yudao.module.hrm.dal.dataobject.salary.HrmSocialSecuritySchemeDO; |
| | | import cn.iocoder.yudao.module.hrm.service.salary.HrmSocialSecuritySchemeService; |
| | | import cn.iocoder.yudao.module.system.api.dept.DeptApi; |
| | | import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; |
| | | 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.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| | | |
| | |
| | | @Resource |
| | | private HrmSocialSecuritySchemeService schemeService; |
| | | |
| | | @Resource |
| | | private DeptApi deptApi; |
| | | |
| | | @PostMapping("/create") |
| | | @Operation(summary = "创建社保公积金方案") |
| | | @PreAuthorize("@ss.hasPermission('hrm:social-security:create')") |
| | | @PreAuthorize("@ss.hasPermission('hrm:social-security-scheme:create')") |
| | | public CommonResult<Long> createScheme(@Valid @RequestBody HrmSocialSecuritySchemeSaveReqVO createReqVO) { |
| | | HrmSocialSecuritySchemeDO scheme = BeanUtils.toBean(createReqVO, HrmSocialSecuritySchemeDO.class); |
| | | return success(schemeService.createScheme(scheme)); |
| | | return success(schemeService.createScheme(createReqVO)); |
| | | } |
| | | |
| | | @PutMapping("/update") |
| | | @Operation(summary = "更新社保公积金方案") |
| | | @PreAuthorize("@ss.hasPermission('hrm:social-security:update')") |
| | | @PreAuthorize("@ss.hasPermission('hrm:social-security-scheme:update')") |
| | | public CommonResult<Boolean> updateScheme(@Valid @RequestBody HrmSocialSecuritySchemeSaveReqVO updateReqVO) { |
| | | HrmSocialSecuritySchemeDO scheme = BeanUtils.toBean(updateReqVO, HrmSocialSecuritySchemeDO.class); |
| | | schemeService.updateScheme(scheme); |
| | | schemeService.updateScheme(updateReqVO); |
| | | return success(true); |
| | | } |
| | | |
| | | @DeleteMapping("/delete") |
| | | @Operation(summary = "删除社保公积金方案") |
| | | @Parameter(name = "id", description = "方案ID", required = true) |
| | | @PreAuthorize("@ss.hasPermission('hrm:social-security:delete')") |
| | | @PreAuthorize("@ss.hasPermission('hrm:social-security-scheme:delete')") |
| | | public CommonResult<Boolean> deleteScheme(@RequestParam("id") Long id) { |
| | | schemeService.deleteScheme(id); |
| | | return success(true); |
| | |
| | | @GetMapping("/get") |
| | | @Operation(summary = "获取社保公积金方案") |
| | | @Parameter(name = "id", description = "方案ID", required = true) |
| | | @PreAuthorize("@ss.hasPermission('hrm:social-security:query')") |
| | | @PreAuthorize("@ss.hasPermission('hrm:social-security-scheme:query')") |
| | | public CommonResult<HrmSocialSecuritySchemeRespVO> getScheme(@RequestParam("id") Long id) { |
| | | HrmSocialSecuritySchemeDO scheme = schemeService.getScheme(id); |
| | | return success(BeanUtils.toBean(scheme, HrmSocialSecuritySchemeRespVO.class)); |
| | | if (scheme == null) { |
| | | return success(null); |
| | | } |
| | | HrmSocialSecuritySchemeRespVO respVO = BeanUtils.toBean(scheme, HrmSocialSecuritySchemeRespVO.class); |
| | | // 填充适用部门 |
| | | fillDeptInfo(List.of(respVO)); |
| | | return success(respVO); |
| | | } |
| | | |
| | | @GetMapping("/list") |
| | | @Operation(summary = "获取社保公积金方案列表") |
| | | @Parameter(name = "status", description = "状态") |
| | | @PreAuthorize("@ss.hasPermission('hrm:social-security:query')") |
| | | @PreAuthorize("@ss.hasPermission('hrm:social-security-scheme:query')") |
| | | public CommonResult<List<HrmSocialSecuritySchemeRespVO>> getSchemeList( |
| | | @RequestParam(value = "status", required = false) Integer status) { |
| | | List<HrmSocialSecuritySchemeDO> list = schemeService.getSchemeList(status); |
| | | return success(BeanUtils.toBean(list, HrmSocialSecuritySchemeRespVO.class)); |
| | | List<HrmSocialSecuritySchemeRespVO> respList = BeanUtils.toBean(list, HrmSocialSecuritySchemeRespVO.class); |
| | | // 填充适用部门 |
| | | fillDeptInfo(respList); |
| | | return success(respList); |
| | | } |
| | | |
| | | /** |
| | | * 填充方案的适用部门ID与部门名称 |
| | | */ |
| | | private void fillDeptInfo(List<HrmSocialSecuritySchemeRespVO> list) { |
| | | if (CollUtil.isEmpty(list)) { |
| | | return; |
| | | } |
| | | List<Long> schemeIds = list.stream().map(HrmSocialSecuritySchemeRespVO::getId).toList(); |
| | | Map<Long, List<Long>> schemeDeptIdMap = schemeService.getSchemeDeptIdMap(schemeIds); |
| | | List<Long> allDeptIds = schemeDeptIdMap.values().stream().flatMap(List::stream).distinct().toList(); |
| | | Map<Long, DeptRespDTO> deptMap = CollUtil.isEmpty(allDeptIds) |
| | | ? Collections.emptyMap() : deptApi.getDeptMap(allDeptIds); |
| | | for (HrmSocialSecuritySchemeRespVO respVO : list) { |
| | | List<Long> deptIds = schemeDeptIdMap.getOrDefault(respVO.getId(), Collections.emptyList()); |
| | | respVO.setDeptIds(deptIds); |
| | | respVO.setDeptNames(deptIds.stream() |
| | | .map(deptId -> { |
| | | DeptRespDTO dept = deptMap.get(deptId); |
| | | return dept != null ? dept.getName() : "ID=" + deptId; |
| | | }) |
| | | .collect(Collectors.joining("、"))); |
| | | } |
| | | } |
| | | |
| | | } |