| | |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.module.aftersales.controller.admin.ticket.vo.ticket.AfterSaleTicketFlowRespVO; |
| | | import cn.iocoder.yudao.module.aftersales.controller.admin.ticket.vo.ticket.AfterSaleTicketPageReqVO; |
| | | import cn.iocoder.yudao.module.aftersales.controller.admin.ticket.vo.ticket.AfterSaleTicketRespVO; |
| | | import cn.iocoder.yudao.module.aftersales.controller.admin.ticket.vo.ticket.AfterSaleTicketSaveReqVO; |
| | | import cn.iocoder.yudao.module.aftersales.dal.dataobject.ticket.AfterSaleTicketDO; |
| | | import cn.iocoder.yudao.module.aftersales.dal.dataobject.ticket.AfterSaleTicketFlowDO; |
| | | import cn.iocoder.yudao.module.aftersales.dal.dataobject.ticket.AfterSaleTicketItemDO; |
| | | import cn.iocoder.yudao.module.aftersales.enums.AfterSaleTicketStatusEnum; |
| | | import cn.iocoder.yudao.module.aftersales.service.ticket.AfterSaleTicketFlowService; |
| | | import cn.iocoder.yudao.module.aftersales.service.ticket.AfterSaleTicketService; |
| | | import cn.iocoder.yudao.module.crm.api.customer.CrmCustomerApi; |
| | | import cn.iocoder.yudao.module.crm.api.customer.dto.CrmCustomerRespDTO; |
| | |
| | | |
| | | @Resource |
| | | private AfterSaleTicketService ticketService; |
| | | @Resource |
| | | private AfterSaleTicketFlowService ticketFlowService; |
| | | |
| | | @Resource |
| | | private CrmCustomerApi customerApi; |
| | |
| | | @GetMapping("/get") |
| | | @Operation(summary = "获得售后工单") |
| | | @Parameter(name = "id", description = "工单编号", required = true, example = "1") |
| | | @PreAuthorize("@ss.hasPermission('aftersales:ticket:query')") |
| | | public CommonResult<AfterSaleTicketRespVO> getTicket(@RequestParam("id") Long id) { |
| | | AfterSaleTicketDO ticket = ticketService.getTicket(id); |
| | | List<AfterSaleTicketItemDO> items = ticketService.getTicketItemListByTicketId(id); |
| | |
| | | List<AfterSaleTicketRespVO> enrichedList = buildTicketDetailList(List.of(ticket)); |
| | | AfterSaleTicketRespVO respVO = enrichedList.get(0); |
| | | respVO.setItems(BeanUtils.toBean(items, AfterSaleTicketRespVO.Item.class)); |
| | | respVO.setFeedbackAttachmentList( |
| | | storageAttachmentApi.listAttachments("aftersales_after_sale_ticket_feedback", id)); |
| | | respVO.setResultAttachmentList( |
| | | storageAttachmentApi.listAttachments("aftersales_after_sale_ticket_result", id)); |
| | | respVO.setAttachmentList(storageAttachmentApi.listAttachments("aftersales_after_sale_ticket", id)); |
| | | respVO.setFlowList(buildFlowList(id)); |
| | | return success(respVO); |
| | | } |
| | | |
| | | @GetMapping("/flow-list") |
| | | @Operation(summary = "获得售后工单流转记录") |
| | | @Parameter(name = "ticketId", description = "工单编号", required = true, example = "1") |
| | | public CommonResult<List<AfterSaleTicketFlowRespVO>> getTicketFlowList(@RequestParam("ticketId") Long ticketId) { |
| | | return success(buildFlowList(ticketId)); |
| | | } |
| | | |
| | | @GetMapping("/page") |
| | | @Operation(summary = "获得售后工单分页") |
| | | @PreAuthorize("@ss.hasPermission('aftersales:ticket:query')") |
| | | public CommonResult<PageResult<AfterSaleTicketRespVO>> getTicketPage(@Valid AfterSaleTicketPageReqVO pageReqVO) { |
| | | PageResult<AfterSaleTicketDO> pageResult = ticketService.getTicketPage(pageReqVO, getLoginUserId()); |
| | | List<AfterSaleTicketRespVO> list = buildTicketDetailList(pageResult.getList()); |
| | | return success(new PageResult<>(list, pageResult.getTotal())); |
| | | } |
| | | |
| | | @PostMapping("/assign") |
| | | @Operation(summary = "分配处理人") |
| | | @PreAuthorize("@ss.hasPermission('aftersales:ticket:update')") |
| | | public CommonResult<Boolean> assignTicket(@RequestParam("id") Long id, |
| | | @RequestParam("handlerUserId") Long handlerUserId) { |
| | | ticketService.assignTicket(id, handlerUserId); |
| | | return success(true); |
| | | } |
| | | |
| | | @PostMapping("/classify") |
| | |
| | | return success(true); |
| | | } |
| | | |
| | | // ========== 内部方法:批量拼装关联名称 ========== |
| | | // ========== 内部方法:流转记录 / 批量拼装关联名称 ========== |
| | | |
| | | private List<AfterSaleTicketFlowRespVO> buildFlowList(Long ticketId) { |
| | | List<AfterSaleTicketFlowDO> flowList = ticketFlowService.getFlowList(ticketId); |
| | | if (CollUtil.isEmpty(flowList)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | Set<Long> operatorIds = convertSet(flowList, AfterSaleTicketFlowDO::getOperatorId); |
| | | Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(operatorIds); |
| | | return BeanUtils.toBean(flowList, AfterSaleTicketFlowRespVO.class, vo -> { |
| | | vo.setFromStatusName(getStatusName(vo.getFromStatus())); |
| | | vo.setToStatusName(getStatusName(vo.getToStatus())); |
| | | AdminUserRespDTO operator = userMap.get(vo.getOperatorId()); |
| | | if (operator != null) { |
| | | vo.setOperatorName(operator.getNickname()); |
| | | } else if (vo.getOperatorId() != null) { |
| | | vo.setOperatorName("用户(ID=" + vo.getOperatorId() + ")"); |
| | | } else { |
| | | vo.setOperatorName("系统"); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private String getStatusName(Integer status) { |
| | | if (status == null) { |
| | | return null; |
| | | } |
| | | for (AfterSaleTicketStatusEnum item : AfterSaleTicketStatusEnum.values()) { |
| | | if (item.getStatus().equals(status)) { |
| | | return item.getName(); |
| | | } |
| | | } |
| | | return "未知状态(ID=" + status + ")"; |
| | | } |
| | | |
| | | private List<AfterSaleTicketRespVO> buildTicketDetailList(List<AfterSaleTicketDO> ticketList) { |
| | | if (CollUtil.isEmpty(ticketList)) { |