|
@@ -3,6 +3,7 @@ package com.jsh.erp.service.impl;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.jsh.erp.datasource.dto.TaskStocktakingDTO;
|
|
|
import com.jsh.erp.datasource.entities.*;
|
|
@@ -23,6 +24,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.Date;
|
|
@@ -140,6 +142,74 @@ public class TaskStocktakingServiceImpl extends ServiceImpl<TaskStocktakingMappe
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 任务详情-修改
|
|
|
+ * @param taskStocktakingDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public boolean detailUpdate(TaskStocktakingDTO taskStocktakingDTO) {
|
|
|
+ try {
|
|
|
+ List<String> collect;
|
|
|
+ List<MaterialExtend> materialExtendList;
|
|
|
+ //全盘,抽盘,处理任务明细
|
|
|
+ if (taskStocktakingDTO.getTaskType() == 1) {
|
|
|
+ materialExtendList = materialExtendMapper.selectList(new LambdaQueryWrapper<MaterialExtend>().ne(MaterialExtend::getInventory, BigDecimal.ZERO).isNotNull(MaterialExtend::getInventory));
|
|
|
+ collect = materialExtendList
|
|
|
+ .stream()
|
|
|
+ .map(MaterialExtend::getPosition)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<Long> materialIdList = materialExtendList.stream().map(MaterialExtend::getMaterialId).distinct().collect(Collectors.toList());
|
|
|
+ List<Material> materialList = materialMapper.selectList(new LambdaQueryWrapperX<Material>().eq(Material::getId, materialIdList));
|
|
|
+ List<Long> categoryIdList = materialList.stream().map(Material::getCategoryId).distinct().collect(Collectors.toList());
|
|
|
+ taskStocktakingDTO.setCategoryCount(categoryIdList.size());
|
|
|
+ taskStocktakingDTO.setMaterialCount(materialExtendList.size());
|
|
|
+ } else {
|
|
|
+ materialExtendList = materialExtendMapper.selectList(new LambdaQueryWrapper<MaterialExtend>().in(MaterialExtend::getBatchNumber, taskStocktakingDTO.getMaterialExtendIdList()));
|
|
|
+ collect = materialExtendList.stream().map(MaterialExtend::getPosition).collect(Collectors.toList());
|
|
|
+ List<Long> materialIdList = materialExtendList.stream().map(MaterialExtend::getMaterialId).collect(Collectors.toList());
|
|
|
+ List<Material> materialList = materialMapper.selectList(new LambdaQueryWrapperX<Material>().in(Material::getId, materialIdList));
|
|
|
+ List<Long> categoryIdList = materialList.stream().map(Material::getCategoryId).distinct().collect(Collectors.toList());
|
|
|
+ taskStocktakingDTO.setCategoryCount(categoryIdList.size());
|
|
|
+ taskStocktakingDTO.setMaterialCount(materialExtendList.size());
|
|
|
+ }
|
|
|
+ //处理商品库位范围处理
|
|
|
+ String positionRange = extractRangePair(collect);
|
|
|
+ taskStocktakingDTO.setPositionRange(positionRange);
|
|
|
+ User currentUser = userService.getCurrentUser();
|
|
|
+ taskStocktakingDTO.setCreateBy(currentUser.getId());
|
|
|
+ taskStocktakingDTO.setCreateTime(new Date());
|
|
|
+ taskStocktakingDTO.setTaskStatus(1);
|
|
|
+ //生成任务
|
|
|
+ this.save(taskStocktakingDTO);
|
|
|
+ List<Long> taskStocktakingItemIdList = taskStocktakingItemMapper.selectList(new LambdaQueryWrapperX<TaskStocktakingItem>().eq(TaskStocktakingItem::getTaskStocktakingId, taskStocktakingDTO.getId())).stream().map(TaskStocktakingItem::getId).collect(Collectors.toList());
|
|
|
+ //生成任务明细
|
|
|
+ List<TaskStocktakingItem> addTaskStocktakingItemList = new ArrayList<>();
|
|
|
+ materialExtendList.forEach(item -> {
|
|
|
+ if (!taskStocktakingItemIdList.contains(item.getId())) {
|
|
|
+ TaskStocktakingItem taskStocktakingItem = new TaskStocktakingItem();
|
|
|
+ taskStocktakingItem.setTaskStocktakingId(taskStocktakingDTO.getId());
|
|
|
+ taskStocktakingItem.setMaterialItemId(item.getId());
|
|
|
+ addTaskStocktakingItemList.add(taskStocktakingItem);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ List<Long> materialExtendIdList = materialExtendList.stream().map(MaterialExtend::getId).collect(Collectors.toList());
|
|
|
+ taskStocktakingItemIdList.forEach(item -> {
|
|
|
+ if (!materialExtendIdList.contains(item)) {
|
|
|
+
|
|
|
+// taskStocktakingItemMapper.updateById();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (addTaskStocktakingItemList.size() > 0) {
|
|
|
+ taskStocktakingItemMapper.insertBatch(addTaskStocktakingItemList);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("创建盘点任务失败", e);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 任务详情-商品明细
|
|
|
* @param taskStocktakingId 盘点任务ID
|
|
|
* @return
|
|
@@ -160,14 +230,40 @@ public class TaskStocktakingServiceImpl extends ServiceImpl<TaskStocktakingMappe
|
|
|
return taskStocktakingMapper.pdaList(number , taskStatus);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * PDA-盘点任务详情
|
|
|
+ * @param id 盘点任务ID
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
@Override
|
|
|
public TaskStocktakingVO pdaDetail(Long id) throws Exception{
|
|
|
TaskStocktakingVO detail = detail(id);
|
|
|
+ List<TaskStocktakingItem> itemList = taskStocktakingItemMapper.selectList(new LambdaQueryWrapper<TaskStocktakingItem>().eq(TaskStocktakingItem::getTaskStocktakingId, id));
|
|
|
//已操作数量
|
|
|
- Long count = taskStocktakingItemMapper.selectCount(new LambdaQueryWrapper<TaskStocktakingItem>()
|
|
|
- .eq(TaskStocktakingItem::getTaskStocktakingId, id)
|
|
|
- .isNotNull(TaskStocktakingItem::getCreator));
|
|
|
- detail.setFinishCount(count);
|
|
|
+ long finishCount = itemList.stream().filter(item -> item.getCreator() != null).count();
|
|
|
+ //商品总数量
|
|
|
+ long itemCount = itemList.size();
|
|
|
+ //商品差异条数
|
|
|
+ long itemDifferenceCount = itemList.stream().filter(item -> item.getCreator() != null
|
|
|
+ && item.getDifferenceCount() != null
|
|
|
+ && item.getDifferenceCount() > 0).count();
|
|
|
+ //差异率
|
|
|
+ double differenceRate = 0;
|
|
|
+ //准确率
|
|
|
+ double accuracyRate = 0;
|
|
|
+ if (itemDifferenceCount > 0) {
|
|
|
+ differenceRate = BigDecimal.valueOf(itemCount)
|
|
|
+ .divide(BigDecimal.valueOf(itemDifferenceCount), 4, RoundingMode.HALF_UP)
|
|
|
+ .doubleValue();
|
|
|
+ accuracyRate = BigDecimal.valueOf(itemCount)
|
|
|
+ .divide(BigDecimal.valueOf(finishCount)
|
|
|
+ .subtract(BigDecimal.valueOf(itemDifferenceCount)), 4, RoundingMode.HALF_UP)
|
|
|
+ .doubleValue();
|
|
|
+ }
|
|
|
+ detail.setDifferenceRate(differenceRate);
|
|
|
+ detail.setAccuracyRate(accuracyRate);
|
|
|
+ detail.setFinishCount(finishCount);
|
|
|
return detail;
|
|
|
}
|
|
|
|