package cn.iocoder.yudao.module.crm.controller.admin.customer; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import cn.iocoder.yudao.framework.common.util.number.NumberUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.progress.CrmCustomerProgressRespVO; import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.progress.CrmCustomerProgressSaveReqVO; import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerProgressDO; import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerProgressService; 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.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.List; import java.util.Map; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; @Tag(name = "管理后台 - CRM 客户洽谈进度") @RestController @RequestMapping("/crm/customer-progress") @Validated public class CrmCustomerProgressController { @Resource private CrmCustomerProgressService customerProgressService; @Resource private AdminUserApi adminUserApi; @PostMapping("/create") @Operation(summary = "创建客户洽谈进度") @PreAuthorize("@ss.hasPermission('crm:customer:update')") public CommonResult createProgress(@Valid @RequestBody CrmCustomerProgressSaveReqVO createReqVO) { return success(customerProgressService.createProgress(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新客户洽谈进度") @PreAuthorize("@ss.hasPermission('crm:customer:update')") public CommonResult updateProgress(@Valid @RequestBody CrmCustomerProgressSaveReqVO updateReqVO) { customerProgressService.updateProgress(updateReqVO); return success(true); } @DeleteMapping("/delete") @Operation(summary = "删除客户洽谈进度") @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('crm:customer:update')") public CommonResult deleteProgress(@RequestParam("id") Long id) { customerProgressService.deleteProgress(id); return success(true); } @GetMapping("/list") @Operation(summary = "获得客户洽谈进度列表", description = "按洽谈时间倒序") @Parameter(name = "customerId", description = "客户编号", required = true, example = "1024") public CommonResult> getProgressList(@RequestParam("customerId") Long customerId) { List list = customerProgressService.getProgressListByCustomerId(customerId); // 拼接记录人名称 Map userMap = adminUserApi.getUserMap( convertSet(list, item -> NumberUtils.parseLong(item.getCreator()))); return success(BeanUtils.toBean(list, CrmCustomerProgressRespVO.class, progress -> { MapUtils.findAndThen(userMap, NumberUtils.parseLong(progress.getCreator()), user -> progress.setCreatorName(user.getNickname())); })); } }