package cn.iocoder.yudao.module.aftersales.controller.admin.problem;
|
|
import cn.hutool.core.collection.CollUtil;
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.module.aftersales.controller.admin.problem.vo.AfterSaleProblemPageReqVO;
|
import cn.iocoder.yudao.module.aftersales.controller.admin.problem.vo.AfterSaleProblemRespVO;
|
import cn.iocoder.yudao.module.aftersales.controller.admin.problem.vo.AfterSaleProblemSaveReqVO;
|
import cn.iocoder.yudao.module.aftersales.dal.dataobject.problem.AfterSaleProblemDO;
|
import cn.iocoder.yudao.module.aftersales.service.problem.AfterSaleProblemService;
|
import cn.iocoder.yudao.module.crm.api.customer.CrmCustomerApi;
|
import cn.iocoder.yudao.module.crm.api.customer.dto.CrmCustomerRespDTO;
|
import cn.iocoder.yudao.module.system.api.storage.StorageAttachmentApi;
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
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.validation.Valid;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.*;
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
|
@Tag(name = "管理后台 - 售后问题库")
|
@RestController
|
@RequestMapping("/aftersales/problem")
|
@Validated
|
public class AfterSaleProblemController {
|
|
@Resource
|
private AfterSaleProblemService problemService;
|
|
@Resource
|
private CrmCustomerApi customerApi;
|
@Resource
|
private AdminUserApi adminUserApi;
|
@Resource
|
private StorageAttachmentApi storageAttachmentApi;
|
|
@PostMapping("/create")
|
@Operation(summary = "创建售后问题")
|
@PreAuthorize("@ss.hasPermission('aftersales:problem:create')")
|
public CommonResult<Long> createProblem(@Valid @RequestBody AfterSaleProblemSaveReqVO createReqVO) {
|
return success(problemService.createProblem(createReqVO, getLoginUserId()));
|
}
|
|
@PutMapping("/update")
|
@Operation(summary = "更新售后问题")
|
@PreAuthorize("@ss.hasPermission('aftersales:problem:update')")
|
public CommonResult<Boolean> updateProblem(@Valid @RequestBody AfterSaleProblemSaveReqVO updateReqVO) {
|
problemService.updateProblem(updateReqVO);
|
return success(true);
|
}
|
|
@DeleteMapping("/delete")
|
@Operation(summary = "删除售后问题")
|
@Parameter(name = "id", description = "问题编号", required = true, example = "1")
|
@PreAuthorize("@ss.hasPermission('aftersales:problem:delete')")
|
public CommonResult<Boolean> deleteProblem(@RequestParam("id") Long id) {
|
problemService.deleteProblem(id);
|
return success(true);
|
}
|
|
@GetMapping("/get")
|
@Operation(summary = "获得售后问题")
|
@Parameter(name = "id", description = "问题编号", required = true, example = "1")
|
@PreAuthorize("@ss.hasPermission('aftersales:problem:query')")
|
public CommonResult<AfterSaleProblemRespVO> getProblem(@RequestParam("id") Long id) {
|
AfterSaleProblemDO problemDO = problemService.getProblem(id);
|
AfterSaleProblemRespVO respVO = buildProblemDetailList(List.of(problemDO)).get(0);
|
respVO.setAttachmentList(storageAttachmentApi.listAttachments("aftersales_after_sale_problem", id));
|
return success(respVO);
|
}
|
|
@GetMapping("/page")
|
@Operation(summary = "获得售后问题分页")
|
@PreAuthorize("@ss.hasPermission('aftersales:problem:query')")
|
public CommonResult<PageResult<AfterSaleProblemRespVO>> getProblemPage(@Valid AfterSaleProblemPageReqVO pageReqVO) {
|
PageResult<AfterSaleProblemDO> pageResult = problemService.getProblemPage(pageReqVO);
|
return success(new PageResult<>(buildProblemDetailList(pageResult.getList()), pageResult.getTotal()));
|
}
|
|
@PutMapping("/publish")
|
@Operation(summary = "发布售后问题")
|
@Parameter(name = "id", description = "问题编号", required = true, example = "1")
|
@PreAuthorize("@ss.hasPermission('aftersales:problem:publish')")
|
public CommonResult<Boolean> publishProblem(@RequestParam("id") Long id) {
|
problemService.publishProblem(id);
|
return success(true);
|
}
|
|
@PutMapping("/disable")
|
@Operation(summary = "停用售后问题")
|
@Parameter(name = "id", description = "问题编号", required = true, example = "1")
|
@PreAuthorize("@ss.hasPermission('aftersales:problem:disable')")
|
public CommonResult<Boolean> disableProblem(@RequestParam("id") Long id) {
|
problemService.disableProblem(id);
|
return success(true);
|
}
|
|
@GetMapping("/reference")
|
@Operation(summary = "新工单受理参考检索(已发布问题)")
|
@PreAuthorize("@ss.hasPermission('aftersales:problem:query')")
|
public CommonResult<List<AfterSaleProblemRespVO>> getReferenceList(@Valid AfterSaleProblemPageReqVO pageReqVO) {
|
return success(buildProblemDetailList(problemService.getReferenceList(pageReqVO)));
|
}
|
|
// ========== 内部方法:批量拼装关联名称 ==========
|
|
private List<AfterSaleProblemRespVO> buildProblemDetailList(List<AfterSaleProblemDO> problemList) {
|
if (CollUtil.isEmpty(problemList)) {
|
return Collections.emptyList();
|
}
|
// 1. 批量加载客户名称
|
Set<Long> customerIds = convertSet(problemList, AfterSaleProblemDO::getCustomerId);
|
Map<Long, CrmCustomerRespDTO> customerMap = customerApi.getCustomerMap(customerIds);
|
// 2. 批量加载沉淀人名称
|
Set<Long> userIds = convertSet(problemList, AfterSaleProblemDO::getOwnerUserId);
|
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds);
|
// 3. 拼装名称字段
|
return BeanUtils.toBean(problemList, AfterSaleProblemRespVO.class, vo -> {
|
CrmCustomerRespDTO customer = customerMap.get(vo.getCustomerId());
|
if (customer != null) {
|
vo.setCustomerName(customer.getName());
|
}
|
AdminUserRespDTO ownerUser = userMap.get(vo.getOwnerUserId());
|
if (ownerUser != null) {
|
vo.setOwnerUserName(ownerUser.getNickname());
|
}
|
});
|
}
|
|
}
|