| | |
| | | import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; |
| | | import cn.iocoder.yudao.module.mdm.api.item.MdmItemApi; |
| | | import cn.iocoder.yudao.module.mdm.api.item.dto.MdmItemRespDTO; |
| | | import cn.iocoder.yudao.module.mdm.api.unit.MdmUnitMeasureApi; |
| | | import cn.iocoder.yudao.module.mdm.api.unit.dto.MdmUnitMeasureRespDTO; |
| | | import cn.iocoder.yudao.module.system.api.dept.DeptApi; |
| | | import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; |
| | | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| | |
| | | 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.*; |
| | | import java.util.stream.Stream; |
| | | |
| | | import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; |
| | |
| | | private CrmBusinessStatusService businessStatusService; |
| | | @Resource |
| | | private MdmItemApi mdmItemApi; |
| | | @Resource |
| | | private MdmUnitMeasureApi mdmUnitMeasureApi; |
| | | |
| | | @Resource |
| | | private AdminUserApi adminUserApi; |
| | |
| | | List<CrmBusinessProductDO> businessProducts = businessService.getBusinessProductListByBusinessId(businessVO.getId()); |
| | | Map<Long, MdmItemRespDTO> itemMap = mdmItemApi.getItemMap( |
| | | convertSet(businessProducts, CrmBusinessProductDO::getItemId)); |
| | | // 收集所有需要查询的单位ID(主单位 + 辅单位1 + 辅单位2) |
| | | Set<Long> unitIds = new HashSet<>(); |
| | | unitIds.addAll(convertSet(businessProducts, CrmBusinessProductDO::getItemUnitId)); |
| | | itemMap.values().forEach(item -> { |
| | | if (item.getUnitMeasureId2() != null) { |
| | | unitIds.add(item.getUnitMeasureId2()); |
| | | } |
| | | if (item.getUnitMeasureId3() != null) { |
| | | unitIds.add(item.getUnitMeasureId3()); |
| | | } |
| | | }); |
| | | Map<Long, MdmUnitMeasureRespDTO> unitMap = mdmUnitMeasureApi.getUnitMeasureMap(unitIds); |
| | | businessVO.setProducts(BeanUtils.toBean(businessProducts, CrmBusinessRespVO.Product.class, businessProductVO -> |
| | | MapUtils.findAndThen(itemMap, businessProductVO.getItemId(), |
| | | item -> businessProductVO.setItemName(item.getName()) |
| | | .setItemCode(item.getCode()).setItemUnitId(item.getUnitMeasureId())))); |
| | | .setItemCode(item.getCode()) |
| | | .setBarCode(item.getBarCode()) |
| | | .setItemSpecification(item.getSpecification())))); |
| | | // 填充单位名称(主单位 + 辅单位1 + 辅单位2) |
| | | businessVO.getProducts().forEach(product -> { |
| | | MapUtils.findAndThen(unitMap, product.getItemUnitId(), |
| | | unit -> product.setItemUnitName(unit.getName())); |
| | | // 填充辅单位名称 |
| | | MapUtils.findAndThen(itemMap, product.getItemId(), item -> { |
| | | if (item.getUnitMeasureId2() != null) { |
| | | MapUtils.findAndThen(unitMap, item.getUnitMeasureId2(), |
| | | unit -> product.setItemUnitName2(unit.getName())); |
| | | } |
| | | if (item.getUnitMeasureId3() != null) { |
| | | MapUtils.findAndThen(unitMap, item.getUnitMeasureId3(), |
| | | unit -> product.setItemUnitName3(unit.getName())); |
| | | } |
| | | }); |
| | | }); |
| | | return businessVO; |
| | | } |
| | | |
| | |
| | | buildBusinessDetailList(list)); |
| | | } |
| | | |
| | | @GetMapping("/get-import-template") |
| | | @Operation(summary = "获得导入商机模板") |
| | | public void importTemplate(HttpServletResponse response) throws IOException { |
| | | // 手动创建导出 demo |
| | | List<CrmBusinessImportExcelVO> list = Arrays.asList( |
| | | CrmBusinessImportExcelVO.builder().name("示例商机").customerName("示例客户") |
| | | .dealTime(null).totalProductPrice(null).discountPercent(null).totalPrice(null).remark("").build() |
| | | ); |
| | | // 输出 |
| | | ExcelUtils.write(response, "商机导入模板.xls", "商机列表", CrmBusinessImportExcelVO.class, list); |
| | | } |
| | | |
| | | @PostMapping("/import") |
| | | @Operation(summary = "导入商机") |
| | | @PreAuthorize("@ss.hasPermission('crm:business:import')") |
| | | public CommonResult<CrmBusinessImportRespVO> importExcel(@Valid CrmBusinessImportReqVO importReqVO) |
| | | throws Exception { |
| | | List<CrmBusinessImportExcelVO> list = ExcelUtils.read(importReqVO.getFile(), CrmBusinessImportExcelVO.class); |
| | | return success(businessService.importBusinessList(list, importReqVO)); |
| | | } |
| | | |
| | | public List<CrmBusinessRespVO> buildBusinessDetailList(List<CrmBusinessDO> list) { |
| | | if (CollUtil.isEmpty(list)) { |
| | | return Collections.emptyList(); |