| | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | import com.ruoyi.production.pojo.ProcessRoute; |
| | | import com.ruoyi.production.pojo.ProcessRouteItem; |
| | | import com.ruoyi.production.service.ProductionProductMainService; |
| | | import com.ruoyi.project.system.domain.SysDept; |
| | | |
| | | import com.ruoyi.project.system.domain.SysUser; |
| | | import com.ruoyi.project.system.mapper.SysDeptMapper; |
| | | import com.ruoyi.project.system.mapper.SysUserMapper; |
| | |
| | | throw new ServiceException("ç»å®å¤±è´¥,å·¥èºè·¯çº¿ä¸åå¨"); |
| | | } |
| | | // æ¸
é¤å·²ç»å®çæ°æ® |
| | | salesLedgerProcessRouteService.remove(new LambdaQueryWrapper<SalesLedgerProcessRoute>().eq(SalesLedgerProcessRoute::getSalesLedgerId, salesLedger.getId()).eq(SalesLedgerProcessRoute::getProcessRouteId, processRoute.getId())); |
| | | salesLedgerProcessRouteService.remove(new LambdaQueryWrapper<SalesLedgerProcessRoute>().eq(SalesLedgerProcessRoute::getSalesLedgerId, salesLedger.getId())); |
| | | |
| | | // å°æ°æ®è¿ç§»å°sales_ledger_process_route |
| | | List<ProcessRouteItem> routeItems = processRouteItemMapper.selectList(new LambdaQueryWrapper<ProcessRouteItem>().eq(ProcessRouteItem::getRouteId, processRoute.getId())); |
| | |
| | | ledgerProcessRoute.setProcessRouteId(processRoute.getId()); |
| | | ledgerProcessRoute.setSalesLedgerId(salesLedger.getId()); |
| | | ledgerProcessRoute.setProcessRouteItemId(routeItem.getId()); |
| | | ledgerProcessRoute.setDragSort(routeItem.getDragSort()); |
| | | salesLedgerProcessRouteList.add(ledgerProcessRoute); |
| | | } |
| | | salesLedgerProcessRouteService.saveBatch(salesLedgerProcessRouteList); |
| | |
| | | } |
| | | } |
| | | |
| | | if (!redisTemplate.hasKey(lockKey)) { |
| | | if (Boolean.FALSE.equals(redisTemplate.hasKey(lockKey))) { |
| | | throw new RuntimeException("è·åååç¼å·çæé失败ï¼è¶
æ¶"); |
| | | } |
| | | |
| | | // 2. æ¥è¯¢å½å¤©/å
¬å¸å·²åå¨çåºåå·ï¼ä¸åé»è¾ä¸è´ï¼ |
| | | Long tenantId = SecurityUtils.getLoginUser().getTenantId(); |
| | | if (null != tenantId) { |
| | | //è·åå
¬å¸ç¼å· |
| | | SysDept sysDept = sysDeptMapper.selectDeptById(tenantId.longValue()); |
| | | if (!ObjectUtils.isEmpty(sysDept)) { |
| | | datePart = (StringUtils.isEmpty(sysDept.getDeptNick()) ? "" : sysDept.getDeptNick()) + datePart; |
| | | } |
| | | } |
| | | // Long tenantId = SecurityUtils.getLoginUser().getTenantId(); |
| | | // if (null != tenantId) { |
| | | // //è·åå
¬å¸ç¼å· |
| | | // SysDept sysDept = sysDeptMapper.selectDeptById(tenantId); |
| | | // if (!ObjectUtils.isEmpty(sysDept)) { |
| | | // datePart = (StringUtils.isEmpty(sysDept.getDeptNick()) ? "" : sysDept.getDeptNick()) + datePart; |
| | | // } |
| | | // } |
| | | datePart = "D" + datePart; |
| | | List<Integer> existingSequences = salesLedgerMapper.selectSequencesByDate(datePart); |
| | | int nextSequence = findFirstMissingSequence(existingSequences); |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public SalesLedgerProcessRouteDto salesProcess(Long salesLedgerId) { |
| | | SalesLedgerProcessRouteDto dto = new SalesLedgerProcessRouteDto(); |
| | | List<SalesLedgerProcessRoute> list = baseMapper.selectSalesProcess(salesLedgerId); |
| | | if (CollectionUtils.isNotEmpty(list)) { |
| | | Long processRouteId = list.get(0).getProcessRouteId(); |
| | | ProcessRoute processRoute = processRouteMapper.selectById(processRouteId); |
| | | if (processRoute != null) { |
| | | dto.setRouteId(processRoute.getId()); |
| | | dto.setRouteName(processRoute.getProcessRouteName()); |
| | | } |
| | | } else { |
| | | // è¦æ¯listæ¥è¯¢ä¸ºç©ºçè¯ï¼å°±æ¥è¯¢é»è®¤çå·¥èºè·¯çº¿è¿å |
| | | ProcessRoute defaultRoute = processRouteMapper.selectOne(new LambdaQueryWrapper<ProcessRoute>().eq(ProcessRoute::getIsDefault, 1).last("limit 1")); |
| | | if (defaultRoute != null) { |
| | | dto.setRouteId(defaultRoute.getId()); |
| | | dto.setRouteName(defaultRoute.getProcessRouteName()); |
| | | List<ProcessRouteItem> routeItems = processRouteItemMapper.selectList(new LambdaQueryWrapper<ProcessRouteItem>().eq(ProcessRouteItem::getRouteId, defaultRoute.getId()).orderByAsc(ProcessRouteItem::getDragSort)); |
| | | list = routeItems.stream().map(item -> { |
| | | SalesLedgerProcessRoute salesLedgerProcessRoute = new SalesLedgerProcessRoute(); |
| | | salesLedgerProcessRoute.setProcessRouteId(defaultRoute.getId()); |
| | | salesLedgerProcessRoute.setSalesLedgerId(salesLedgerId); |
| | | salesLedgerProcessRoute.setProcessRouteItemId(item.getId()); |
| | | salesLedgerProcessRoute.setProcessName(item.getProcessName()); |
| | | salesLedgerProcessRoute.setDragSort(item.getDragSort()); |
| | | return salesLedgerProcessRoute; |
| | | }).collect(Collectors.toList()); |
| | | } |
| | | } |
| | | dto.setList(list); |
| | | return dto; |
| | | } |
| | | |
| | | @Override |
| | | public SalesProcessCardDto processCard(Long salesLedgerId) { |
| | | if (salesLedgerId == null) { |
| | | throw new ServiceException("æµç¨å¡æå°å¤±è´¥,æå°éå®è®¢åä¸è½ä¸ºç©º"); |
| | | } |
| | | // æ¥è¯¢éå®è®¢å |
| | | SalesLedger salesLedger = baseMapper.selectById(salesLedgerId); |
| | | if (salesLedger == null) { |
| | | throw new ServiceException("æµç¨å¡æå°å¤±è´¥,éå®è®¢åä¸åå¨"); |
| | | } |
| | | |
| | | SalesProcessCardDto dto = new SalesProcessCardDto(); |
| | | dto.setSalesContractNo(salesLedger.getSalesContractNo()); |
| | | dto.setCustomerName(salesLedger.getCustomerName()); |
| | | dto.setDeliveryDate(salesLedger.getDeliveryDate()); |
| | | dto.setRegister(SecurityUtils.getLoginUser().getUser().getNickName()); |
| | | dto.setRegisterDate(LocalDateTime.now()); |
| | | dto.setOrderProcessRequirement(salesLedger.getRemarks()); |
| | | |
| | | // æ¥è¯¢äº§åå表 |
| | | List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList( |
| | | new LambdaQueryWrapper<SalesLedgerProduct>().eq(SalesLedgerProduct::getSalesLedgerId, salesLedgerId)); |
| | | |
| | | BigDecimal totalQuantity = BigDecimal.ZERO; |
| | | BigDecimal totalArea = BigDecimal.ZERO; |
| | | List<SalesProcessCardDto.ProcessCardItemDto> itemDtos = new ArrayList<>(); |
| | | |
| | | for (SalesLedgerProduct p : products) { |
| | | SalesProcessCardDto.ProcessCardItemDto itemDto = new SalesProcessCardDto.ProcessCardItemDto(); |
| | | itemDto.setFloorCode(p.getFloorCode()); |
| | | // ç»è£
产åæè¿°ï¼å¤§ç±» + (è§æ ¼) |
| | | String desc = (p.getProductCategory() != null ? p.getProductCategory() : "") + |
| | | (StringUtils.isNotBlank(p.getSpecificationModel()) ? " " + p.getSpecificationModel() : ""); |
| | | itemDto.setProductDescription(desc.trim()); |
| | | itemDto.setWidth(p.getWidth()); |
| | | itemDto.setHeight(p.getHeight()); |
| | | itemDto.setQuantity(p.getQuantity()); |
| | | |
| | | // é¢ç§¯è®¡ç®(平米) |
| | | BigDecimal area = p.getActualPieceArea() != null ? p.getActualPieceArea() : p.getSettlePieceArea(); |
| | | if (area == null && p.getWidth() != null && p.getHeight() != null) { |
| | | area = p.getWidth().multiply(p.getHeight()).divide(new BigDecimal(1000000), 2, RoundingMode.HALF_UP); |
| | | } |
| | | itemDto.setArea(area); |
| | | itemDto.setProcessRequirement(p.getProcessRequirement()); |
| | | |
| | | BigDecimal qty = p.getQuantity() != null ? p.getQuantity() : BigDecimal.ZERO; |
| | | totalQuantity = totalQuantity.add(qty); |
| | | if (area != null) { |
| | | totalArea = totalArea.add(area.multiply(qty)); |
| | | } |
| | | |
| | | itemDtos.add(itemDto); |
| | | } |
| | | dto.setItems(itemDtos); |
| | | dto.setTotalQuantity(totalQuantity); |
| | | dto.setTotalArea(totalArea.setScale(2, RoundingMode.HALF_UP)); |
| | | |
| | | // å·¥èºè·¯çº¿ |
| | | List<SalesLedgerProcessRoute> salesLedgerProcessRoutes = salesLedgerProcessRouteService.list( |
| | | new LambdaQueryWrapper<SalesLedgerProcessRoute>() |
| | | .eq(SalesLedgerProcessRoute::getSalesLedgerId, salesLedgerId) |
| | | .orderByAsc(SalesLedgerProcessRoute::getDragSort)); |
| | | |
| | | List<SalesProcessCardDto.ProcessNodeDto> nodeDtos = new ArrayList<>(); |
| | | |
| | | if (CollectionUtils.isEmpty(salesLedgerProcessRoutes)) { |
| | | // æ èªå®ä¹è·¯çº¿ï¼åé»è®¤è·¯çº¿ |
| | | ProcessRoute defaultRoute = processRouteMapper.selectOne( |
| | | new LambdaQueryWrapper<ProcessRoute>().eq(ProcessRoute::getIsDefault, 1).last("LIMIT 1")); |
| | | if (defaultRoute != null) { |
| | | List<ProcessRouteItem> routeItems = processRouteItemMapper.selectList( |
| | | new LambdaQueryWrapper<ProcessRouteItem>() |
| | | .eq(ProcessRouteItem::getRouteId, defaultRoute.getId()) |
| | | .orderByAsc(ProcessRouteItem::getDragSort)); |
| | | for (ProcessRouteItem i : routeItems) { |
| | | SalesProcessCardDto.ProcessNodeDto node = new SalesProcessCardDto.ProcessNodeDto(); |
| | | node.setProcessRouteItemId(i.getId()); |
| | | node.setProcessRouteItemName(i.getProcessName()); |
| | | node.setDragSort(i.getDragSort()); |
| | | nodeDtos.add(node); |
| | | } |
| | | } |
| | | } else { |
| | | // 使ç¨èªå®ä¹è·¯çº¿ç»å®çèç¹ |
| | | List<Long> itemIds = salesLedgerProcessRoutes.stream() |
| | | .map(SalesLedgerProcessRoute::getProcessRouteItemId) |
| | | .collect(Collectors.toList()); |
| | | List<ProcessRouteItem> rawItems = processRouteItemMapper.selectBatchIds(itemIds); |
| | | Map<Long, ProcessRouteItem> itemMap = rawItems.stream() |
| | | .collect(Collectors.toMap(ProcessRouteItem::getId, i -> i, (a, b) -> a)); |
| | | |
| | | for (SalesLedgerProcessRoute r : salesLedgerProcessRoutes) { |
| | | ProcessRouteItem pi = itemMap.get(r.getProcessRouteItemId()); |
| | | if (pi != null) { |
| | | SalesProcessCardDto.ProcessNodeDto node = new SalesProcessCardDto.ProcessNodeDto(); |
| | | node.setProcessRouteItemId(pi.getId()); |
| | | node.setProcessRouteItemName(pi.getProcessName()); |
| | | node.setDragSort(r.getDragSort() != null ? r.getDragSort() : pi.getDragSort()); |
| | | node.setRemark(r.getRemark()); |
| | | nodeDtos.add(node); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (!nodeDtos.isEmpty()) { |
| | | // dragSort è¿è¡ååºæåº |
| | | nodeDtos.sort(Comparator.comparing( |
| | | SalesProcessCardDto.ProcessNodeDto::getDragSort, |
| | | Comparator.nullsLast(Comparator.naturalOrder()) |
| | | )); |
| | | // éæ°çææåºåçè·¯å¾åç§°å表 |
| | | List<String> sortedPathNames = nodeDtos.stream() |
| | | .map(SalesProcessCardDto.ProcessNodeDto::getProcessRouteItemName) |
| | | .collect(Collectors.toList()); |
| | | // æ¼æ¥å符串 |
| | | dto.setProcessPathDisplay(String.join(" -> ", sortedPathNames)); |
| | | // 设置顶å±èç¹çå·¥èºè·¯çº¿ |
| | | dto.setRouteNodes(nodeDtos); |
| | | } |
| | | |
| | | return dto; |
| | | } |
| | | |
| | | private int findFirstMissingSequence(List<Integer> sequences) { |
| | | if (sequences.isEmpty()) { |
| | | return 1; |