Merge remote-tracking branch 'origin/fix/hsy/20260811' into dev_business
| | |
| | | .apply("YEAR(create_time) = {0}", year)); |
| | | |
| | | long totalTenderCount = projects.size(); |
| | | //ææ æ»éé¢(é¢ç®éé¢) |
| | | BigDecimal totalTenderAmount = projects.stream() |
| | | .map(p -> p.getBudgetAmount() != null ? p.getBudgetAmount() : BigDecimal.ZERO) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | //宿 æ»éé¢(䏿 éé¢) |
| | | BigDecimal totalAwardAmount = awards.stream() |
| | | .map(a -> a.getAwardAmount() != null ? a.getAwardAmount() : BigDecimal.ZERO) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | //è约éé¢(é¢ç®éé¢-䏿 éé¢) |
| | | BigDecimal savedAmount = totalTenderAmount.subtract(totalAwardAmount); |
| | | long supplierCount = bids.stream() |
| | | .map(SrmTenderBidDO::getSupplierId) |
| | |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptRespVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSimpleRespVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptImportExcelVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptImportRespVO; |
| | | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| | | import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; |
| | | import cn.iocoder.yudao.module.system.service.dept.DeptService; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.Parameters; |
| | | 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 org.springframework.web.multipart.MultipartFile; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | |
| | | import jakarta.annotation.Resource; |
| | | import jakarta.validation.Valid; |
| | | import java.io.IOException; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| | |
| | | return success(BeanUtils.toBean(dept, DeptRespVO.class)); |
| | | } |
| | | |
| | | @GetMapping("/get-import-template") |
| | | @Operation(summary = "è·å¾å¯¼å
¥é¨é¨æ¨¡æ¿") |
| | | public void importTemplate(HttpServletResponse response) throws IOException { |
| | | List<DeptImportExcelVO> list = Arrays.asList( |
| | | DeptImportExcelVO.builder().name("ç åé¨").parentPath("æ»å
¬å¸").sort(1).status(CommonStatusEnum.ENABLE.getStatus()).build(), |
| | | DeptImportExcelVO.builder().name("è´¢å¡é¨").parentPath("æ»å
¬å¸").sort(2).status(CommonStatusEnum.ENABLE.getStatus()).build() |
| | | ); |
| | | ExcelUtils.write(response, "é¨é¨å¯¼å
¥æ¨¡æ¿.xls", "é¨é¨å表", DeptImportExcelVO.class, list); |
| | | } |
| | | |
| | | @PostMapping("/import") |
| | | @Operation(summary = "导å
¥é¨é¨") |
| | | @Parameters({ |
| | | @Parameter(name = "file", description = "Excel æä»¶", required = true), |
| | | @Parameter(name = "updateSupport", description = "æ¯å¦æ¯ææ´æ°ï¼é»è®¤ä¸º false", example = "true") |
| | | }) |
| | | @PreAuthorize("@ss.hasPermission('system:dept:import')") |
| | | public CommonResult<DeptImportRespVO> importExcel(@RequestParam("file") MultipartFile file, |
| | | @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception { |
| | | List<DeptImportExcelVO> list = ExcelUtils.read(file, DeptImportExcelVO.class); |
| | | return success(deptService.importDeptList(list, updateSupport)); |
| | | } |
| | | |
| | | } |
| | |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostRespVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSaveReqVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSimpleRespVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostImportExcelVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostImportRespVO; |
| | | import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; |
| | | import cn.iocoder.yudao.module.system.service.dept.PostService; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import io.swagger.v3.oas.annotations.Parameters; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.Comparator; |
| | | import java.util.List; |
| | |
| | | } |
| | | |
| | | @GetMapping("/export-excel") |
| | | @Operation(summary = "å²ä½ç®¡ç") |
| | | @Operation(summary = "导åºå²ä½ Excel") |
| | | @PreAuthorize("@ss.hasPermission('system:post:export')") |
| | | @ApiAccessLog(operateType = EXPORT) |
| | | public void export(HttpServletResponse response, @Validated PostPageReqVO reqVO) throws IOException { |
| | |
| | | BeanUtils.toBean(list, PostRespVO.class)); |
| | | } |
| | | |
| | | @GetMapping("/get-import-template") |
| | | @Operation(summary = "è·å¾å¯¼å
¥å²ä½æ¨¡æ¿") |
| | | public void importTemplate(HttpServletResponse response) throws IOException { |
| | | // æå¨åå»ºå¯¼åº demo |
| | | List<PostImportExcelVO> list = Arrays.asList( |
| | | PostImportExcelVO.builder().name("å
¨æ å¼å").code("fullstack").sort(1) |
| | | .status(CommonStatusEnum.ENABLE.getStatus()).remark("å
¨æ å¼åå·¥ç¨å¸").build(), |
| | | PostImportExcelVO.builder().name("å端å¼å").code("frontend").sort(2) |
| | | .status(CommonStatusEnum.ENABLE.getStatus()).remark("å端å¼åå·¥ç¨å¸").build() |
| | | ); |
| | | // è¾åº |
| | | ExcelUtils.write(response, "å²ä½å¯¼å
¥æ¨¡æ¿.xls", "å²ä½å表", PostImportExcelVO.class, list); |
| | | } |
| | | |
| | | @PostMapping("/import") |
| | | @Operation(summary = "导å
¥å²ä½") |
| | | @Parameters({ |
| | | @Parameter(name = "file", description = "Excel æä»¶", required = true), |
| | | @Parameter(name = "updateSupport", description = "æ¯å¦æ¯ææ´æ°ï¼é»è®¤ä¸º false", example = "true") |
| | | }) |
| | | @PreAuthorize("@ss.hasPermission('system:post:import')") |
| | | public CommonResult<PostImportRespVO> importExcel(@RequestParam("file") MultipartFile file, |
| | | @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception { |
| | | List<PostImportExcelVO> list = ExcelUtils.read(file, PostImportExcelVO.class); |
| | | return success(postService.importPostList(list, updateSupport)); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept; |
| | | |
| | | import cn.idev.excel.annotation.ExcelProperty; |
| | | import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; |
| | | import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; |
| | | import cn.iocoder.yudao.module.system.enums.DictTypeConstants; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Builder; |
| | | import lombok.Data; |
| | | import lombok.NoArgsConstructor; |
| | | |
| | | @Data |
| | | @Builder |
| | | @AllArgsConstructor |
| | | @NoArgsConstructor |
| | | public class DeptImportExcelVO { |
| | | |
| | | @ExcelProperty("é¨é¨åç§°") |
| | | private String name; |
| | | |
| | | @ExcelProperty("ä¸çº§é¨é¨å
¨è·¯å¾") |
| | | private String parentPath; |
| | | |
| | | @ExcelProperty("æ¾ç¤ºé¡ºåº") |
| | | private Integer sort; |
| | | |
| | | @ExcelProperty("èç³»çµè¯") |
| | | private String phone; |
| | | |
| | | @ExcelProperty("é®ç®±") |
| | | private String email; |
| | | |
| | | @ExcelProperty(value = "ç¶æ", converter = DictConvert.class) |
| | | @DictFormat(DictTypeConstants.COMMON_STATUS) |
| | | private Integer status; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept; |
| | | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Builder; |
| | | import lombok.Data; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Schema(description = "管çåå° - é¨é¨å¯¼å
¥ Response VO") |
| | | @Data |
| | | @Builder |
| | | public class DeptImportRespVO { |
| | | |
| | | @Schema(description = "å建æåçé¨é¨æ°ç»", requiredMode = Schema.RequiredMode.REQUIRED) |
| | | private List<String> createDeptNames; |
| | | |
| | | @Schema(description = "æ´æ°æåçé¨é¨æ°ç»", requiredMode = Schema.RequiredMode.REQUIRED) |
| | | private List<String> updateDeptNames; |
| | | |
| | | @Schema(description = "导å
¥å¤±è´¥çé¨é¨éå key 为é¨é¨åï¼value 为失败åå ", requiredMode = Schema.RequiredMode.REQUIRED) |
| | | private Map<String, String> failureDeptNames; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.system.controller.admin.dept.vo.post; |
| | | |
| | | import cn.idev.excel.annotation.ExcelProperty; |
| | | import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; |
| | | import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; |
| | | import cn.iocoder.yudao.module.system.enums.DictTypeConstants; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Builder; |
| | | import lombok.Data; |
| | | import lombok.NoArgsConstructor; |
| | | |
| | | @Data |
| | | @Builder |
| | | @AllArgsConstructor |
| | | @NoArgsConstructor |
| | | public class PostImportExcelVO { |
| | | |
| | | @ExcelProperty("å²ä½åç§°") |
| | | private String name; |
| | | |
| | | @ExcelProperty("å²ä½ç¼ç ") |
| | | private String code; |
| | | |
| | | @ExcelProperty("å²ä½æåº") |
| | | private Integer sort; |
| | | |
| | | @ExcelProperty(value = "ç¶æ", converter = DictConvert.class) |
| | | @DictFormat(DictTypeConstants.COMMON_STATUS) |
| | | private Integer status; |
| | | |
| | | @ExcelProperty("夿³¨") |
| | | private String remark; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.system.controller.admin.dept.vo.post; |
| | | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Builder; |
| | | import lombok.Data; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Schema(description = "管çåå° - å²ä½å¯¼å
¥ Response VO") |
| | | @Data |
| | | @Builder |
| | | public class PostImportRespVO { |
| | | |
| | | @Schema(description = "å建æåçå²ä½æ°ç»", requiredMode = Schema.RequiredMode.REQUIRED) |
| | | private List<String> createPostNames; |
| | | |
| | | @Schema(description = "æ´æ°æåçå²ä½æ°ç»", requiredMode = Schema.RequiredMode.REQUIRED) |
| | | private List<String> updatePostNames; |
| | | |
| | | @Schema(description = "导å
¥å¤±è´¥çå²ä½éå key 为å²ä½åç§°ï¼value 为失败åå ", requiredMode = Schema.RequiredMode.REQUIRED) |
| | | private Map<String, String> failurePostNames; |
| | | |
| | | } |
| | |
| | | ErrorCode DEPT_PARENT_ERROR = new ErrorCode(1_002_004_004, "ä¸è½è®¾ç½®èªå·±ä¸ºç¶é¨é¨"); |
| | | ErrorCode DEPT_NOT_ENABLE = new ErrorCode(1_002_004_006, "é¨é¨({})ä¸å¤äºå¼å¯ç¶æï¼ä¸å
è®¸éæ©"); |
| | | ErrorCode DEPT_PARENT_IS_CHILD = new ErrorCode(1_002_004_007, "ä¸è½è®¾ç½®èªå·±çåé¨é¨ä¸ºç¶é¨é¨"); |
| | | ErrorCode DEPT_IMPORT_LIST_IS_EMPTY = new ErrorCode(1_002_004_008, "导å
¥é¨é¨æ°æ®ä¸è½ä¸ºç©ºï¼"); |
| | | |
| | | // ========== å²ä½æ¨¡å 1-002-005-000 ========== |
| | | ErrorCode POST_NOT_FOUND = new ErrorCode(1_002_005_000, "å½åå²ä½ä¸åå¨"); |
| | | ErrorCode POST_NOT_ENABLE = new ErrorCode(1_002_005_001, "å²ä½({}) ä¸å¤äºå¼å¯ç¶æï¼ä¸å
è®¸éæ©"); |
| | | ErrorCode POST_NAME_DUPLICATE = new ErrorCode(1_002_005_002, "å·²ç»åå¨è¯¥ååçå²ä½"); |
| | | ErrorCode POST_CODE_DUPLICATE = new ErrorCode(1_002_005_003, "å·²ç»åå¨è¯¥æ è¯çå²ä½"); |
| | | ErrorCode POST_IMPORT_LIST_IS_EMPTY = new ErrorCode(1_002_005_004, "导å
¥å²ä½æ°æ®ä¸è½ä¸ºç©ºï¼"); |
| | | |
| | | // ========== åå
¸ç±»å 1-002-006-000 ========== |
| | | ErrorCode DICT_TYPE_NOT_EXISTS = new ErrorCode(1_002_006_001, "å½ååå
¸ç±»åä¸åå¨"); |
| | |
| | | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptImportExcelVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptImportRespVO; |
| | | import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; |
| | | |
| | | import java.util.*; |
| | |
| | | */ |
| | | void validateDeptList(Collection<Long> ids); |
| | | |
| | | /** |
| | | * 导å
¥é¨é¨å表 |
| | | * |
| | | * @param importDepts 导å
¥é¨é¨å表 |
| | | * @param isUpdateSupport æ¯å¦æ¯ææ´æ° |
| | | * @return 导å
¥ç»æ |
| | | */ |
| | | DeptImportRespVO importDeptList(List<DeptImportExcelVO> importDepts, boolean isUpdateSupport); |
| | | |
| | | } |
| | |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| | | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptImportExcelVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptImportRespVO; |
| | | import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; |
| | | import cn.iocoder.yudao.module.system.dal.mysql.dept.DeptMapper; |
| | | import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; |
| | |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public DeptImportRespVO importDeptList(List<DeptImportExcelVO> importDepts, boolean isUpdateSupport) { |
| | | if (CollUtil.isEmpty(importDepts)) { |
| | | throw exception(DEPT_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | DeptImportRespVO respVO = DeptImportRespVO.builder().createDeptNames(new ArrayList<>()) |
| | | .updateDeptNames(new ArrayList<>()).failureDeptNames(new LinkedHashMap<>()).build(); |
| | | |
| | | // 1. åå§åç°æçå
¨è·¯å¾ä¸é¨é¨IDæ å° |
| | | List<DeptDO> allDepts = getDeptList(new DeptListReqVO()); |
| | | Map<Long, DeptDO> idDeptMap = cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap(allDepts, DeptDO::getId); |
| | | Map<String, Long> fullPathDeptIdMap = new HashMap<>(); |
| | | for (DeptDO dept : allDepts) { |
| | | fullPathDeptIdMap.put(getFullPath(dept, idDeptMap), dept.getId()); |
| | | } |
| | | |
| | | // 2. å°å¯¼å
¥çé¨é¨æç
§ç¶é¨é¨è·¯å¾æ·±åº¦æåºï¼ç¡®ä¿å
å¤çç¶é¨é¨ |
| | | importDepts.sort(Comparator.comparingInt(dept -> StrUtil.isEmpty(dept.getParentPath()) ? 0 : dept.getParentPath().split("/").length)); |
| | | |
| | | // 3. éå导å
¥ |
| | | for (DeptImportExcelVO importDept : importDepts) { |
| | | // 3.1 è·åç¶é¨é¨ ID |
| | | Long parentId = DeptDO.PARENT_ID_ROOT; |
| | | if (StrUtil.isNotEmpty(importDept.getParentPath())) { |
| | | parentId = fullPathDeptIdMap.get(importDept.getParentPath()); |
| | | if (parentId == null) { |
| | | respVO.getFailureDeptNames().put(importDept.getName(), "ä¸çº§é¨é¨ä¸åå¨: " + importDept.getParentPath()); |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | // 3.2 æ ¡éªé¨é¨åç§°æ¯å¦å¯ä¸ |
| | | try { |
| | | validateDeptNameUnique(null, parentId, importDept.getName()); |
| | | } catch (ServiceException ex) { |
| | | if (!isUpdateSupport) { |
| | | respVO.getFailureDeptNames().put(importDept.getName(), ex.getMessage()); |
| | | continue; |
| | | } |
| | | // æ¯ææ´æ°ï¼æ§è¡æ´æ° |
| | | DeptDO existDept = deptMapper.selectByParentIdAndName(parentId, importDept.getName()); |
| | | DeptDO updateDept = BeanUtils.toBean(importDept, DeptDO.class); |
| | | updateDept.setId(existDept.getId()); |
| | | updateDept.setParentId(parentId); |
| | | deptMapper.updateById(updateDept); |
| | | respVO.getUpdateDeptNames().add(importDept.getName()); |
| | | |
| | | String myFullPath = StrUtil.isEmpty(importDept.getParentPath()) ? importDept.getName() : importDept.getParentPath() + "/" + importDept.getName(); |
| | | fullPathDeptIdMap.put(myFullPath, existDept.getId()); |
| | | continue; |
| | | } |
| | | |
| | | // 3.3 æ°å¢é¨é¨ |
| | | DeptDO newDept = BeanUtils.toBean(importDept, DeptDO.class); |
| | | newDept.setParentId(parentId); |
| | | deptMapper.insert(newDept); |
| | | respVO.getCreateDeptNames().add(importDept.getName()); |
| | | |
| | | // æ´æ°ç¼åï¼ä¾åç»åé¨é¨ä½¿ç¨ |
| | | String myFullPath = StrUtil.isEmpty(importDept.getParentPath()) ? importDept.getName() : importDept.getParentPath() + "/" + importDept.getName(); |
| | | fullPathDeptIdMap.put(myFullPath, newDept.getId()); |
| | | } |
| | | |
| | | return respVO; |
| | | } |
| | | |
| | | private String getFullPath(DeptDO dept, Map<Long, DeptDO> idDeptMap) { |
| | | StringBuilder path = new StringBuilder(dept.getName()); |
| | | Long parentId = dept.getParentId(); |
| | | while (parentId != null && !DeptDO.PARENT_ID_ROOT.equals(parentId)) { |
| | | DeptDO parent = idDeptMap.get(parentId); |
| | | if (parent == null) { |
| | | break; |
| | | } |
| | | path.insert(0, parent.getName() + "/"); |
| | | parentId = parent.getParentId(); |
| | | } |
| | | return path.toString(); |
| | | } |
| | | } |
| | |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSaveReqVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostImportExcelVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostImportRespVO; |
| | | import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; |
| | | import org.jspecify.annotations.Nullable; |
| | | |
| | |
| | | */ |
| | | void validatePostList(Collection<Long> ids); |
| | | |
| | | /** |
| | | * 导å
¥å²ä½å表 |
| | | * |
| | | * @param importPosts 导å
¥å²ä½å表 |
| | | * @param isUpdateSupport æ¯å¦æ¯ææ´æ° |
| | | * @return 导å
¥ç»æ |
| | | */ |
| | | PostImportRespVO importPostList(List<PostImportExcelVO> importPosts, boolean isUpdateSupport); |
| | | |
| | | } |
| | |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | |
| | | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostImportExcelVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostImportRespVO; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; |
| | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public PostImportRespVO importPostList(List<PostImportExcelVO> importPosts, boolean isUpdateSupport) { |
| | | if (CollUtil.isEmpty(importPosts)) { |
| | | throw exception(POST_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | PostImportRespVO respVO = PostImportRespVO.builder().createPostNames(new ArrayList<>()) |
| | | .updatePostNames(new ArrayList<>()).failurePostNames(new LinkedHashMap<>()).build(); |
| | | importPosts.forEach(importPost -> { |
| | | // æ ¡éªï¼å¤ææ¯å¦æä¸ç¬¦åçåå |
| | | try { |
| | | validatePostForCreateOrUpdate(null, importPost.getName(), importPost.getCode()); |
| | | } catch (ServiceException ex) { |
| | | // 妿æ¯éå¤å¼å¸¸ï¼è䏿¯ææ´æ° |
| | | if (isUpdateSupport && (POST_NAME_DUPLICATE.getCode().equals(ex.getCode()) || POST_CODE_DUPLICATE.getCode().equals(ex.getCode()))) { |
| | | // ignore |
| | | } else { |
| | | respVO.getFailurePostNames().put(importPost.getName(), ex.getMessage()); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | // 夿妿åå¨ï¼å¨è¿è¡æ´æ° |
| | | PostDO existPost = postMapper.selectByName(importPost.getName()); |
| | | if (existPost == null) { |
| | | existPost = postMapper.selectByCode(importPost.getCode()); |
| | | } |
| | | if (existPost == null) { |
| | | PostDO post = BeanUtils.toBean(importPost, PostDO.class); |
| | | postMapper.insert(post); |
| | | respVO.getCreatePostNames().add(importPost.getName()); |
| | | return; |
| | | } |
| | | |
| | | // 妿åå¨ï¼å¤ææ¯å¦å
è®¸æ´æ° |
| | | if (!isUpdateSupport) { |
| | | respVO.getFailurePostNames().put(importPost.getName(), "å²ä½åæç¼ç å·²ç»åå¨"); |
| | | return; |
| | | } |
| | | |
| | | // æ´æ°å²ä½ |
| | | PostDO updatePost = BeanUtils.toBean(importPost, PostDO.class); |
| | | updatePost.setId(existPost.getId()); |
| | | postMapper.updateById(updatePost); |
| | | respVO.getUpdatePostNames().add(importPost.getName()); |
| | | }); |
| | | return respVO; |
| | | } |
| | | } |