| | |
| | | import com.vincent.rsf.server.api.entity.dto.PoItemsDto; |
| | | import com.vincent.rsf.server.api.service.ReceiveMsgService; |
| | | import com.vincent.rsf.server.api.service.ReportMsgService; |
| | | import com.vincent.rsf.server.common.utils.DateUtils; |
| | | import com.vincent.rsf.server.manager.controller.dto.DashboardDto; |
| | | import com.vincent.rsf.server.manager.controller.dto.StockTrandDto; |
| | | import com.vincent.rsf.server.manager.controller.dto.StockTransItemDto; |
| | | import com.vincent.rsf.server.manager.controller.params.AsnOrderAndItemsParams; |
| | | import com.vincent.rsf.server.manager.controller.params.BatchUpdateParam; |
| | | import com.vincent.rsf.server.manager.entity.*; |
| | | import com.vincent.rsf.server.manager.enums.AsnExceStatus; |
| | | import com.vincent.rsf.server.manager.enums.POExceStatus; |
| | | import com.vincent.rsf.server.manager.enums.*; |
| | | import com.vincent.rsf.server.manager.mapper.AsnOrderMapper; |
| | | import com.vincent.rsf.server.manager.service.*; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.text.DateFormat; |
| | | import java.text.ParsePosition; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | private PurchaseService purchaseService; |
| | | @Autowired |
| | | private PurchaseItemService purchaseItemService; |
| | | @Autowired |
| | | private AsnOrderService asnOrderService; |
| | | @Autowired |
| | | private TaskService taskService; |
| | | |
| | | @Override |
| | | public boolean notifyInspect(List<WkOrder> orders) { |
| | |
| | | * @param loginUserId |
| | | * @return |
| | | */ |
| | | /** 入库单业务类型:拣料入库、盘点入库等不可修改明细,此处为字典 value,按实际配置补充 */ |
| | | private static final Set<String> ASN_WKTYPE_NO_EDIT = Collections.unmodifiableSet(new HashSet<>( |
| | | Arrays.asList("53", "57"))); // 53=拣料再入库 57=盘点再入库(与 TaskType 一致,若字典不同请改为实际 value) |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R updateOrderItem(AsnOrderAndItemsParams params, Long loginUserId) throws Exception { |
| | |
| | | if (Objects.isNull(orders.getId())) { |
| | | throw new CoolException("数据错误:单据ID不能为空!!"); |
| | | } |
| | | if (!this.updateById(orders)) { |
| | | throw new CoolException("主单修改失败!!"); |
| | | WkOrder currentOrder = this.getById(orders.getId()); |
| | | if (Objects.isNull(currentOrder)) { |
| | | throw new CoolException("单据不存在!!"); |
| | | } |
| | | // 仅未执行状态可修改 |
| | | if (!Objects.equals(currentOrder.getExceStatus(), AsnExceStatus.ASN_EXCE_STATUS_UN_EXCE.val)) { |
| | | throw new CoolException("当前单据状态不允许修改,仅未执行状态可修改"); |
| | | } |
| | | // 拣料入库、盘点入库类型不可修改 |
| | | if (StringUtils.isNotBlank(currentOrder.getWkType()) && ASN_WKTYPE_NO_EDIT.contains(currentOrder.getWkType())) { |
| | | throw new CoolException("拣料入库、盘点入库类型的单据不能修改"); |
| | | } |
| | | if (Objects.isNull(params.getItems()) || params.getItems().isEmpty()) { |
| | | return R.ok("明细参数不能为空!!"); |
| | | throw new CoolException("明细参数不能为空!!"); |
| | | } |
| | | if (!this.updateById(orders)) { |
| | | throw new CoolException("主单修改失败!!"); |
| | | } |
| | | |
| | | svaeOrUpdateOrderItem(params, loginUserId); |
| | |
| | | } |
| | | |
| | | PurchaseItem service = purchaseItemService.getById(item.getId()); |
| | | Double qty = Math.round((service.getQty() + item.getAnfme()) * 10000) / 10000.0; |
| | | Double qty = Math.round((service.getQty() + item.getAnfme()) * 1000000) / 1000000.0; |
| | | if (qty.compareTo(service.getAnfme()) > 0) { |
| | | throw new CoolException("新建单据数量不能大于计划数量!!"); |
| | | } |
| | |
| | | throw new CoolException("单据不存在!!"); |
| | | } |
| | | |
| | | Double toQty = Math.round((purchaseItem.getQty() + item.getAnfme()) * 10000) / 10000.0; |
| | | Double toQty = Math.round((purchaseItem.getQty() + item.getAnfme()) * 1000000) / 1000000.0; |
| | | purchaseItem.setQty(toQty); |
| | | if (!purchaseItemService.updateById(purchaseItem)) { |
| | | throw new CoolException("PO单明细修改失败!!"); |
| | |
| | | throw new CoolException(("Asn单据明细保存失败!!")); |
| | | } |
| | | //任务执行完成,修改已完成数量和PO单执行状态 |
| | | Double qty = Math.round((sum + purchase.getQty()) * 10000) / 10000.0; |
| | | Double qty = Math.round((sum + purchase.getQty()) * 1000000) / 1000000.0; |
| | | purchase.setQty(qty) |
| | | .setExceStatus(POExceStatus.PO_EXCE_STATUS_EXCE_ING.val); |
| | | |
| | |
| | | list.forEach(item -> { |
| | | PurchaseItem purchaseItem = purchaseItemService.getById(item.getPoDetlId()); |
| | | if (!Objects.isNull(purchaseItem)) { |
| | | Double minusQty = Math.round((purchaseItem.getQty() - item.getAnfme()) * 10000) / 10000.0; |
| | | Double minusQty = Math.round((purchaseItem.getQty() - item.getAnfme()) * 1000000) / 1000000.0; |
| | | purchaseItem.setQty(minusQty); |
| | | if (!purchaseItemService.updateById(purchaseItem)) { |
| | | throw new CoolException("PO单明细更新失败!!"); |
| | |
| | | Purchase purchase = purchaseService.getOne(new LambdaQueryWrapper<Purchase>() |
| | | .eq(Purchase::getCode, list.stream().findFirst().get().getPoCode())); |
| | | if (!Objects.isNull(purchase)) { |
| | | Double qty = Math.round((purchase.getQty() - sum) * 10000) / 10000.0; |
| | | Double qty = Math.round((purchase.getQty() - sum) * 1000000) / 1000000.0; |
| | | purchase.setQty(qty) |
| | | .setExceStatus(POExceStatus.PO_EXCE_STATUS_EXCE_ING.val); |
| | | |
| | |
| | | throw new CoolException("任务中单据不可删除!!"); |
| | | } |
| | | |
| | | |
| | | if (!asnOrderItemService.remove(new LambdaQueryWrapper<WkOrderItem>() |
| | | .in(WkOrderItem::getOrderId, ids))) { |
| | | // throw new CoolException("Details Delete Fail"); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取首页表头数据 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R getDashbord() { |
| | | DashboardDto dto = new DashboardDto(); |
| | | //获取入库数量 |
| | | DashboardDto trandDto = this.baseMapper.getDashbord(OrderType.ORDER_IN.type, TaskType.TASK_TYPE_IN.type + ""); |
| | | dto.setInAnf(trandDto.getAnfme()).setTaskIn(trandDto.getRealAnfme()).setTotalIn(trandDto.getAnfme() + trandDto.getRealAnfme()); |
| | | |
| | | //获取出库单数量 |
| | | DashboardDto outTrand = this.baseMapper.getDashbord(OrderType.ORDER_OUT.type, TaskType.TASK_TYPE_OUT.type + ""); |
| | | dto.setOutAnf(outTrand.getAnfme()).setTaskOut(outTrand.getRealAnfme()).setTotalOut(outTrand.getAnfme() + outTrand.getRealAnfme()); |
| | | |
| | | //获取执行中任务数量 |
| | | List<Task> tasks = taskService.list(new LambdaQueryWrapper<>()); |
| | | if (!tasks.isEmpty()) { |
| | | dto.setTaskQty(tasks.size()); |
| | | } |
| | | return R.ok().add(dto); |
| | | } |
| | | |
| | | /** |
| | | * 获取出入库趋势 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R getStockTrand() { |
| | | List<String> days = DateUtils.getLastMonthDays("yyyy-MM-dd"); |
| | | LambdaQueryWrapper<StockStatistic> queryWrapper = new LambdaQueryWrapper<StockStatistic>() |
| | | .in(StockStatistic::getTaskType, Arrays.asList(TaskType.TASK_TYPE_IN.type, TaskType.TASK_TYPE_OUT.type)); |
| | | List<StockTransItemDto> items = this.baseMapper.getStockTrand(queryWrapper); |
| | | if (items.isEmpty()) { |
| | | return R.ok(); |
| | | } |
| | | List<StockTransItemDto> stockDtos = new ArrayList<>(); |
| | | days.forEach(day -> { |
| | | StockTransItemDto itemDto = new StockTransItemDto(); |
| | | itemDto.setInQty(0).setOutQty(0).setOutAnfme(0).setOutAnfme(0); |
| | | items.forEach(item -> { |
| | | if (item.getOrderTime().equals(day)) { |
| | | BeanUtils.copyProperties(item, itemDto); |
| | | } |
| | | }); |
| | | itemDto.setOrderTime(day); |
| | | stockDtos.add(itemDto); |
| | | }); |
| | | |
| | | //获取最大值 |
| | | Optional<Integer> max = stockDtos.stream().map(StockTransItemDto::getInQty).filter(Objects::nonNull).max(Comparator.naturalOrder()); |
| | | Optional<Integer> maxOut = stockDtos.stream().map(StockTransItemDto::getOutQty).filter(Objects::nonNull).max(Comparator.naturalOrder()); |
| | | int maxed = Math.max(max.orElse(Integer.MIN_VALUE), maxOut.orElse(Integer.MIN_VALUE)); |
| | | |
| | | StockTrandDto trandDto = new StockTrandDto(); |
| | | trandDto.setMaxQty(maxed).setTrandItem(stockDtos); |
| | | return R.ok().add(trandDto); |
| | | } |
| | | |
| | | /** |
| | | * @param |
| | | * @return |
| | | * @author Ryan |