diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/controller/admin/DlRepairSoController.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/controller/admin/DlRepairSoController.java index 26cf5395..1ba3deef 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/controller/admin/DlRepairSoController.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/controller/admin/DlRepairSoController.java @@ -120,15 +120,15 @@ public class DlRepairSoController { /** * 采购入库 * - * @param repairSoReqVO DlRepairSoReqVO实体 + * @param repairSoRespVO DlRepairSoReqVO实体 * @return cn.iocoder.yudao.framework.common.pojo.CommonResult * @author PQZ * @date 10:43 2024/10/25 **/ @PostMapping("/inWare") @Operation(summary = "采购入库") - public CommonResult inWare(@RequestBody DlRepairSoReqVO repairSoReqVO) { - dlRepairSoService.inWare(repairSoReqVO); + public CommonResult inWare(@RequestBody DlRepairSoRespVO repairSoRespVO) { + dlRepairSoService.inWare(repairSoRespVO); return CommonResult.ok(); } } diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/controller/admin/DlRepairSoiController.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/controller/admin/DlRepairSoiController.java index 81b72808..5377cc1a 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/controller/admin/DlRepairSoiController.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/controller/admin/DlRepairSoiController.java @@ -75,5 +75,18 @@ public class DlRepairSoiController{ public CommonResult getRepairSoiBySoId(@RequestParam(value = "soId") String soId){ return success(dlRepairSoiService.getRepairSoiBySoId(soId)); } + + /** + * 根据主表的ID得到子表的所有数据,按类型区分的map,支持条件查询 + * + * @author 小李 + * @date 15:51 2024/11/19 + * @param id id + **/ + @GetMapping("/getMapBySoIdAndQuery") + @Operation(summary = "根据主表的ID得到子表的所有数据,按类型区分的map,支持条件查询") + public CommonResult getMapBySoIdAndQuery(@RequestParam("id") String id, @RequestParam("query") String query) { + return success(dlRepairSoiService.getMapBySoIdAndQuery(id, query)); + } } diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/entity/DlRepairSoi.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/entity/DlRepairSoi.java index f4978b01..6c7f55b6 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/entity/DlRepairSoi.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/entity/DlRepairSoi.java @@ -11,10 +11,6 @@ import lombok.EqualsAndHashCode; import java.math.BigDecimal; -/** - * 采购单领料单子表 - * @TableName dl_repair_soi - */ /** * 采购单/领料单子表 * @author 小李 diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/mapper/DlRepairSoMapper.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/mapper/DlRepairSoMapper.java index 9e39cf10..ed9ded4a 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/mapper/DlRepairSoMapper.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/mapper/DlRepairSoMapper.java @@ -8,6 +8,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import java.util.List; + /** * 针对表【dl_repair_so(采购单领料单)】的数据库操作Mapper * @author 小李 diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/mapper/DlRepairSoiMapper.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/mapper/DlRepairSoiMapper.java index 4551b233..2868f656 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/mapper/DlRepairSoiMapper.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/mapper/DlRepairSoiMapper.java @@ -2,12 +2,15 @@ package cn.iocoder.yudao.module.stockOperate.mapper; import cn.iocoder.yudao.module.stockOperate.entity.DlRepairSoi; import cn.iocoder.yudao.module.stockOperate.vo.DlRepairSoiReqVO; +import cn.iocoder.yudao.module.stockOperate.vo.DlRepairSoiRespVO; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import java.util.List; + /** * 针对表【dl_repair_soi(采购单领料单子表)】的数据库操作Mapper * @author 小李 @@ -24,6 +27,15 @@ public interface DlRepairSoiMapper extends BaseMapper { * @param repairSoiReqVO 查询对象 **/ IPage getRepairSoiPage(@Param("map") DlRepairSoiReqVO repairSoiReqVO, Page page); + + /** + * 根据主表的ID得到子表的所有数据,按类型区分的map,支持条件查询 + * + * @author 小李 + * @date 15:51 2024/11/19 + * @param id id + **/ + List getMapBySoIdAndQuery(@Param("id") String id, @Param("query") String query); } diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/service/DlRepairSoService.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/service/DlRepairSoService.java index 09e8f8c1..91abf4fd 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/service/DlRepairSoService.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/service/DlRepairSoService.java @@ -7,6 +7,9 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; +import java.util.List; +import java.util.Map; + /** * 针对表【dl_repair_so(采购单领料单)】的数据库操作Service * @@ -72,9 +75,9 @@ public interface DlRepairSoService extends IService { /** * 采购入库 * - * @param reqVO (接参实体中需传入:采购单id,子表中商品id,子表中入库数量inCount) + * @param repairSoRespVO (接参实体中需传入:采购单id,子表中商品id,子表中入库数量inCount) * @author PQZ * @date 14:32 2024/10/24 **/ - void inWare(DlRepairSoReqVO reqVO); + void inWare(DlRepairSoRespVO repairSoRespVO); } diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/service/DlRepairSoiService.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/service/DlRepairSoiService.java index 2169096a..6111b3b9 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/service/DlRepairSoiService.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/service/DlRepairSoiService.java @@ -3,11 +3,13 @@ package cn.iocoder.yudao.module.stockOperate.service; import cn.iocoder.yudao.module.stockOperate.entity.DlRepairSoi; import cn.iocoder.yudao.module.stockOperate.vo.DlRepairSoiQueryRespVO; import cn.iocoder.yudao.module.stockOperate.vo.DlRepairSoiReqVO; +import cn.iocoder.yudao.module.stockOperate.vo.DlRepairSoiRespVO; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import java.util.List; +import java.util.Map; /** * 针对表【dl_repair_soi(采购单领料单子表)】的数据库操作Service @@ -53,4 +55,13 @@ public interface DlRepairSoiService extends IService { * @date 14:39 2024/10/24 **/ List listByIds(List ids); + + /** + * 根据主表的ID得到子表的所有数据,按类型区分的map,支持条件查询 + * + * @author 小李 + * @date 15:51 2024/11/19 + * @param id id + **/ + Map> getMapBySoIdAndQuery(String id, String query); } diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/service/impl/DlRepairSoServiceImpl.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/service/impl/DlRepairSoServiceImpl.java index 39eefd48..2e8124cb 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/service/impl/DlRepairSoServiceImpl.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/service/impl/DlRepairSoServiceImpl.java @@ -402,7 +402,7 @@ public class DlRepairSoServiceImpl extends ServiceImpl sois = repairSoiService.list(new LambdaQueryWrapper().eq(DlRepairSoi::getSoId, reqVO.getId())); // 过滤出入库数量大于等于采购数量的数据 (入库数量可以大于采购的数量) - List allInSois = sois.stream().filter(item -> item.getInCount() >= item.getGoodsCount()).collect(Collectors.toList()); + List allInSois = sois.stream() + .filter(item -> (ObjectUtil.isNotEmpty(item.getInCount()) && item.getInCount() >= item.getGoodsCount())) + .collect(Collectors.toList()); // 如果allInSois的size就是sois的size,那就是全部都入库了 if (CollectionUtil.isNotEmpty(allInSois) && allInSois.size() == sois.size()) { // 更新采购单的状态为已入库 @@ -489,6 +491,22 @@ public class DlRepairSoServiceImpl extends ServiceImpl reqVOWaresList = reqVO.getWaresList(); + List ids = reqVOWaresList.stream().map(item -> item.getId()).collect(Collectors.toList()); + List oldWares = waresService.listByIds(ids); + // 这里是因为传过来的库存不是最新的,但其他字段可能变了,所以用最新的库存替换传回来的,在用传回来的+最新库存构成最新数据 + List newWares = reqVOWaresList.stream().map(item -> { + RepairWares wares = BeanUtil.toBean(item, RepairWares.class); + RepairWares findWares = oldWares.stream().filter(i -> i.getId().equals(wares.getId())).findFirst().orElse(null); + if (findWares != null) { + wares.setStock(findWares.getStock()); + } + return wares; + }).collect(Collectors.toList()); + waresService.updateBatchById(newWares); } } diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/service/impl/DlRepairSoiServiceImpl.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/service/impl/DlRepairSoiServiceImpl.java index c6ee1e14..ed0ad7d2 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/service/impl/DlRepairSoiServiceImpl.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/service/impl/DlRepairSoiServiceImpl.java @@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.stockOperate.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollectionUtil; +import cn.iocoder.yudao.module.conf.entity.BaseType; +import cn.iocoder.yudao.module.conf.service.BaseTypeService; import cn.iocoder.yudao.module.project.entity.RepairWares; import cn.iocoder.yudao.module.project.service.RepairWaresService; import cn.iocoder.yudao.module.stockOperate.entity.DlRepairSo; @@ -11,6 +13,7 @@ import cn.iocoder.yudao.module.stockOperate.service.DlRepairSoService; import cn.iocoder.yudao.module.stockOperate.service.DlRepairSoiService; import cn.iocoder.yudao.module.stockOperate.vo.DlRepairSoiQueryRespVO; import cn.iocoder.yudao.module.stockOperate.vo.DlRepairSoiReqVO; +import cn.iocoder.yudao.module.stockOperate.vo.DlRepairSoiRespVO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -19,7 +22,9 @@ import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -40,6 +45,9 @@ public class DlRepairSoiServiceImpl extends ServiceImpl listByIds(List ids) { return baseMapper.selectBatchIds(ids); } + + /** + * 根据主表的ID得到子表的所有数据,按类型区分的map,支持条件查询 + * + * @author 小李 + * @date 15:51 2024/11/19 + * @param id id + **/ + @Override + public Map> getMapBySoIdAndQuery(String id, String query){ + // 查出该单据的子项和其对应的配件信息 + List respVOList = baseMapper.getMapBySoIdAndQuery(id, query); + if (CollectionUtil.isEmpty(respVOList)){ + return null; + } + // 按配件信息的type进行分组 + Map> map = respVOList.stream().collect(Collectors.groupingBy(item -> { + String key = item.getWares().getType(); + if (key == null || key.isEmpty()) { + key = "default"; + } + return key; + })); + // 查分类的信息 + List baseTypes = typeService.listByIds(map.keySet()); + Map typeMap = baseTypes.stream().collect(Collectors.toMap(BaseType::getId, BaseType::getName)); + // 映射 + Map> result = new HashMap<>(); + for (Map.Entry> entry : map.entrySet()) { + String key = entry.getKey(); + String newKey = typeMap.get(key); + if (newKey == null || newKey.isEmpty()) { + newKey = "未分类"; + } + result.put(newKey, entry.getValue()); + } + return result; + } } diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/vo/DlRepairSoRespVO.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/vo/DlRepairSoRespVO.java index ef28aff8..1d6b25ce 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/vo/DlRepairSoRespVO.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/vo/DlRepairSoRespVO.java @@ -21,4 +21,7 @@ public class DlRepairSoRespVO extends DlRepairSo { // 配件List private List waresList; + + /**关联商品*/ + List soiList; } diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/vo/DlRepairSoiRespVO.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/vo/DlRepairSoiRespVO.java index 59bfc3de..6c420e9d 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/vo/DlRepairSoiRespVO.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/vo/DlRepairSoiRespVO.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.stockOperate.vo; +import cn.iocoder.yudao.module.project.entity.RepairWares; import cn.iocoder.yudao.module.stockOperate.entity.DlRepairSoi; import lombok.Data; @@ -10,4 +11,7 @@ import lombok.Data; **/ @Data public class DlRepairSoiRespVO extends DlRepairSoi { + + /** 对应的配件信息 */ + private RepairWares wares; } diff --git a/dl-module-repair/src/main/resources/mapper/stockOperate/DlRepairSoiMapper.xml b/dl-module-repair/src/main/resources/mapper/stockOperate/DlRepairSoiMapper.xml index a6f22bad..b67e1c73 100644 --- a/dl-module-repair/src/main/resources/mapper/stockOperate/DlRepairSoiMapper.xml +++ b/dl-module-repair/src/main/resources/mapper/stockOperate/DlRepairSoiMapper.xml @@ -69,4 +69,83 @@ ) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +