From 183ddd5f7d60bf299255904e95a66992a9e1f29d Mon Sep 17 00:00:00 2001 From: wangqian <1406304305@qq.com> Date: Wed, 17 Dec 2025 00:07:00 +0800 Subject: [PATCH] 工单管理分页图片名称转换 --- urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/admin/maininfo/MainInfoController.java | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------ urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/admin/maininfo/vo/MainInfoRespVO.java | 6 ++++-- urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/convert/maininfo/MainInfoConvert.java | 35 +++++++++++++++++++++++++++++++++++ urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/attachment/AttachmentService.java | 8 +++++++- urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/attachment/AttachmentServiceImpl.java | 11 +++++++++++ urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/materialdetail/MaterialDetailServiceImpl.java | 7 +++++++ 6 files changed, 124 insertions(+), 27 deletions(-) create mode 100644 urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/convert/maininfo/MainInfoConvert.java diff --git a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/admin/maininfo/MainInfoController.java b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/admin/maininfo/MainInfoController.java index 32806fc..1a91283 100644 --- a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/admin/maininfo/MainInfoController.java +++ b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/admin/maininfo/MainInfoController.java @@ -1,33 +1,39 @@ package com.zteits.urbanops.module.workorder.controller.admin.maininfo; -import org.springframework.web.bind.annotation.*; -import jakarta.annotation.Resource; -import org.springframework.validation.annotation.Validated; -import org.springframework.security.access.prepost.PreAuthorize; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.Operation; - -import jakarta.validation.constraints.*; -import jakarta.validation.*; -import jakarta.servlet.http.*; -import java.util.*; -import java.io.IOException; - +import com.zteits.urbanops.framework.apilog.core.annotation.ApiAccessLog; +import com.zteits.urbanops.framework.common.pojo.CommonResult; import com.zteits.urbanops.framework.common.pojo.PageParam; import com.zteits.urbanops.framework.common.pojo.PageResult; -import com.zteits.urbanops.framework.common.pojo.CommonResult; import com.zteits.urbanops.framework.common.util.object.BeanUtils; -import static com.zteits.urbanops.framework.common.pojo.CommonResult.success; - import com.zteits.urbanops.framework.excel.core.util.ExcelUtils; - -import com.zteits.urbanops.framework.apilog.core.annotation.ApiAccessLog; -import static com.zteits.urbanops.framework.apilog.core.enums.OperateTypeEnum.*; - -import com.zteits.urbanops.module.workorder.controller.admin.maininfo.vo.*; +import com.zteits.urbanops.module.workorder.controller.admin.attachment.vo.AttachmentReqVO; +import com.zteits.urbanops.module.workorder.controller.admin.maininfo.vo.MainInfoPageReqVO; +import com.zteits.urbanops.module.workorder.controller.admin.maininfo.vo.MainInfoRespVO; +import com.zteits.urbanops.module.workorder.controller.admin.maininfo.vo.MainInfoSaveReqVO; +import com.zteits.urbanops.module.workorder.convert.maininfo.MainInfoConvert; +import com.zteits.urbanops.module.workorder.dal.dataobject.attachment.AttachmentDO; import com.zteits.urbanops.module.workorder.dal.dataobject.maininfo.MainInfoDO; +import com.zteits.urbanops.module.workorder.service.attachment.AttachmentService; import com.zteits.urbanops.module.workorder.service.maininfo.MainInfoService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.Valid; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static com.zteits.urbanops.framework.apilog.core.enums.OperateTypeEnum.EXPORT; +import static com.zteits.urbanops.framework.common.pojo.CommonResult.success; @Tag(name = "管理后台 - 工单信息") @RestController @@ -38,6 +44,9 @@ public class MainInfoController { @Resource private MainInfoService mainInfoService; + @Resource + private AttachmentService attachmentService; + @PostMapping("/create") @Operation(summary = "创建工单信息") @PreAuthorize("@ss.hasPermission('workorder:main-info:create')") @@ -85,7 +94,34 @@ public class MainInfoController { @PreAuthorize("@ss.hasPermission('workorder:main-info:query')") public CommonResult> getMainInfoPage(@Valid MainInfoPageReqVO pageReqVO) { PageResult pageResult = mainInfoService.getMainInfoPage(pageReqVO); - return success(BeanUtils.toBean(pageResult, MainInfoRespVO.class)); + // 2. 初始化附件映射(默认空Map,避免后续空指针) + Map attachmentMap = Collections.emptyMap(); + + // 3. 空值防护:分页结果非空且列表非空时,才查询附件 + if (pageResult != null && !CollectionUtils.isEmpty(pageResult.getList())) { + // 提取订单号列表 + List orderNoList = pageResult.getList().stream() + .map(MainInfoDO::getOrderNo) + .filter(orderNo -> orderNo != null && !orderNo.isBlank()) + .collect(Collectors.toList()); + + // 若订单号列表非空,查询附件;否则跳过 + if (!CollectionUtils.isEmpty(orderNoList)) { + List attachmentDOList = attachmentService.getAttachmentByOrderNo(orderNoList); + // 构建订单号→附件对象的映射(处理重复key,取第一个对象) + if (!CollectionUtils.isEmpty(attachmentDOList)) { + attachmentMap = attachmentDOList.stream() + .filter(attachmentDO -> "01".equals(attachmentDO.getBusiType())) + .collect(Collectors.toMap( + AttachmentDO::getOrderNo, // key:订单号 + attachmentDO -> attachmentDO, // value:附件对象 + (existing, replacement) -> existing // 重复key时保留已有值 + )); + } + } + } + // 4. 转换并返回结果 + return success(MainInfoConvert.INSTANCE.buildMainInfoPage(pageResult, attachmentMap)); } @GetMapping("/export-excel") @@ -101,4 +137,4 @@ public class MainInfoController { BeanUtils.toBean(list, MainInfoRespVO.class)); } -} \ No newline at end of file +} diff --git a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/admin/maininfo/vo/MainInfoRespVO.java b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/admin/maininfo/vo/MainInfoRespVO.java index 55166ed..4eef52b 100644 --- a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/admin/maininfo/vo/MainInfoRespVO.java +++ b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/admin/maininfo/vo/MainInfoRespVO.java @@ -32,7 +32,7 @@ public class MainInfoRespVO { private String orderName; @Schema(description = "来源ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1828") - @ExcelProperty("来源ID") + @ExcelProperty("来源ID 问题来源 1、巡查,2、游客居民,3、12345,4、网格 5、大区经理") private Integer sourceId; @Schema(description = "来源名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") @@ -135,4 +135,6 @@ public class MainInfoRespVO { @ExcelProperty("创建时间") private LocalDateTime createTime; -} \ No newline at end of file + @Schema(description = "文件名称") + private String fileNames; +} diff --git a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/convert/maininfo/MainInfoConvert.java b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/convert/maininfo/MainInfoConvert.java new file mode 100644 index 0000000..aa9ea4f --- /dev/null +++ b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/convert/maininfo/MainInfoConvert.java @@ -0,0 +1,35 @@ +package com.zteits.urbanops.module.workorder.convert.maininfo; + +import com.zteits.urbanops.framework.common.pojo.PageResult; +import com.zteits.urbanops.framework.common.util.collection.CollectionUtils; +import com.zteits.urbanops.framework.common.util.object.BeanUtils; +import com.zteits.urbanops.module.workorder.controller.admin.maininfo.vo.MainInfoRespVO; +import com.zteits.urbanops.module.workorder.dal.dataobject.attachment.AttachmentDO; +import com.zteits.urbanops.module.workorder.dal.dataobject.maininfo.MainInfoDO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; +import java.util.Map; + +/** + * @Classname MainInfoConvert + * @Description 工单转换 + * @Date 2025/12/16 22:57 + * @Created by wangqian + */ +@Mapper +public interface MainInfoConvert { + + MainInfoConvert INSTANCE = Mappers.getMapper(MainInfoConvert.class); + + default PageResult buildMainInfoPage(PageResult pageResult, Map attachmentMap) { + List mainInfoVOList = CollectionUtils.convertList(pageResult.getList(), mainInfoDO -> { + MainInfoRespVO mainInfoVo = BeanUtils.toBean(mainInfoDO, MainInfoRespVO.class); + AttachmentDO attachmentDO = attachmentMap.get(mainInfoDO.getOrderNo()); + mainInfoVo.setFileNames(attachmentDO.getFileNames()); + return mainInfoVo; + }); + return new PageResult<>(mainInfoVOList, pageResult.getTotal()); + } +} diff --git a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/attachment/AttachmentService.java b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/attachment/AttachmentService.java index bba13aa..d05411b 100644 --- a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/attachment/AttachmentService.java +++ b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/attachment/AttachmentService.java @@ -66,5 +66,11 @@ public interface AttachmentService { * @return 工单附件信息 */ List getAttachmentByCondition(AttachmentReqVO reqVO); - + /** + * 获得工单附件信息 + * + * @param orderNolist 编号 + * @return 工单附件信息 + */ + List getAttachmentByOrderNo(List orderNolist); } diff --git a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/attachment/AttachmentServiceImpl.java b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/attachment/AttachmentServiceImpl.java index e2194a8..620acc0 100644 --- a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/attachment/AttachmentServiceImpl.java +++ b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/attachment/AttachmentServiceImpl.java @@ -3,6 +3,7 @@ package com.zteits.urbanops.module.workorder.service.attachment; import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Service; import jakarta.annotation.Resource; import org.springframework.validation.annotation.Validated; @@ -98,4 +99,14 @@ public class AttachmentServiceImpl implements AttachmentService { } return attachmentMapper.selectList(queryWrapper); } + + @Override + public List getAttachmentByOrderNo(List orderNolist) { + if (CollectionUtils.isEmpty(orderNolist)) { + throw exception0(BAD_REQUEST.getCode(),"工单号不能为空"); + } + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.in(AttachmentDO::getOrderNo, orderNolist); + return attachmentMapper.selectList(queryWrapper); + } } diff --git a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/materialdetail/MaterialDetailServiceImpl.java b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/materialdetail/MaterialDetailServiceImpl.java index 065f25f..b67bae8 100644 --- a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/materialdetail/MaterialDetailServiceImpl.java +++ b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/materialdetail/MaterialDetailServiceImpl.java @@ -119,6 +119,13 @@ public class MaterialDetailServiceImpl implements MaterialDetailService { throw exception0(BAD_REQUEST.getCode(),"订单号"+materialDetailDO.getOrderNo()+"不存在"); } } + //已登记 + for (MaterialDetailDO materialDetailDO : materialDetailList) { + MaterialDetailDO materialDetailDO1 = materialDetailMapper.selectOne(MaterialDetailDO::getMaterialId, materialDetailDO.getMaterialId()); + if (materialDetailDO1 != null) { + throw exception0(BAD_REQUEST.getCode(),materialDetailDO.getMaterialName()+"已登记"); + } + } //耗材出库 for (MaterialDetailDO materialDetailDO : materialDetailList) { MaterialInventoryOutDto outDto = new MaterialInventoryOutDto(); -- libgit2 0.21.4