refactor(delivery): 优化发货清单物料代码项查询逻辑
- 在 DeliveryController 中替换原有的复杂查询为简化的 getItemsVO 方法调用 - 添加 ShipmentMaterialCodeItemVO 类型导入到相关接口和服务实现 - 在 IWmsShipmentDeliveryItemService 接口中新增 getItemsVO 方法定义 - 在 WmsShipmentDeliveryItemMapper 接口中新增 getItemsVO 查询方法 - 实现 MyBatis XML 查询映射,使用 SQL JOIN 和聚合函数优化数据获取 - 在 WmsShipmentDeliveryItemServiceImpl 中实现 getItemsVO 业务逻辑 - 移除控制器中被注释的原始查询代码以提高代码整洁性
This commit is contained in:
parent
a68763e1b4
commit
17c1ed20f4
|
|
@ -1,8 +1,11 @@
|
|||
package com.nflg.wms.repository.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nflg.wms.common.pojo.vo.ShipmentMaterialCodeItemVO;
|
||||
import com.nflg.wms.repository.entity.WmsShipmentDeliveryItem;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
|
|
@ -13,4 +16,5 @@ import com.nflg.wms.repository.entity.WmsShipmentDeliveryItem;
|
|||
*/
|
||||
public interface WmsShipmentDeliveryItemMapper extends BaseMapper<WmsShipmentDeliveryItem> {
|
||||
|
||||
List<ShipmentMaterialCodeItemVO> getItemsVO(Long id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
package com.nflg.wms.repository.service;
|
||||
|
||||
import com.nflg.wms.common.pojo.vo.ShipmentMaterialCodeItemVO;
|
||||
import com.nflg.wms.repository.entity.WmsShipmentDeliveryItem;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
|
|
@ -13,4 +16,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||
*/
|
||||
public interface IWmsShipmentDeliveryItemService extends IService<WmsShipmentDeliveryItem> {
|
||||
|
||||
List<ShipmentMaterialCodeItemVO> getItemsVO(Long id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
package com.nflg.wms.repository.service.impl;
|
||||
|
||||
import com.nflg.wms.common.pojo.vo.ShipmentMaterialCodeItemVO;
|
||||
import com.nflg.wms.repository.entity.WmsShipmentDeliveryItem;
|
||||
import com.nflg.wms.repository.mapper.WmsShipmentDeliveryItemMapper;
|
||||
import com.nflg.wms.repository.service.IWmsShipmentDeliveryItemService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
|
|
@ -17,4 +20,8 @@ import org.springframework.stereotype.Service;
|
|||
@Service
|
||||
public class WmsShipmentDeliveryItemServiceImpl extends ServiceImpl<WmsShipmentDeliveryItemMapper, WmsShipmentDeliveryItem> implements IWmsShipmentDeliveryItemService {
|
||||
|
||||
@Override
|
||||
public List<ShipmentMaterialCodeItemVO> getItemsVO(Long id) {
|
||||
return baseMapper.getItemsVO(id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,4 +2,13 @@
|
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nflg.wms.repository.mapper.WmsShipmentDeliveryItemMapper">
|
||||
|
||||
<select id="getItemsVO" resultType="com.nflg.wms.common.pojo.vo.ShipmentMaterialCodeItemVO">
|
||||
SELECT ROW_NUMBER() OVER (ORDER BY smdiq.item_id DESC) as "index",smdi.material_no,smdi.material_describe,SUM(smdi.num) as num,SUM(smdiq.num) as actualNum,smdi.unit
|
||||
FROM wms_shipment_delivery_item sdi
|
||||
INNER JOIN wms_shipment_packaging_code_item spci ON sdi.packaging_code_id=spci.packaging_code_id
|
||||
INNER JOIN wms_shipment_material_code_item_qr smdiq ON smdiq.id=spci.material_code_item_qr_id
|
||||
INNER JOIN wms_shipment_material_code_item smdi ON smdiq.item_id=smdi."id"
|
||||
WHERE sdi.delivery_id = #{id}
|
||||
GROUP BY smdiq.item_id,smdi.material_no,smdi.material_describe,smdi.unit
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
|
|
@ -203,15 +203,16 @@ public class DeliveryController extends BaseController {
|
|||
WmsShipmentDelivery delivery = deliveryService.getById(id);
|
||||
VUtil.trueThrowBusinessError(Objects.isNull(delivery)).throwMessage("清单不存在");
|
||||
AtomicInteger index = new AtomicInteger(1);
|
||||
List<ShipmentMaterialCodeItemVO> list = deliveryItemService.lambdaQuery()
|
||||
.eq(WmsShipmentDeliveryItem::getDeliveryId, id)
|
||||
.orderByAsc(WmsShipmentDeliveryItem::getId)
|
||||
.list()
|
||||
.stream().map(item -> {
|
||||
ShipmentMaterialCodeItemVO vo = Convert.convert(ShipmentMaterialCodeItemVO.class, item);
|
||||
vo.setIndex(index.getAndIncrement());
|
||||
return vo;
|
||||
}).toList();
|
||||
// List<ShipmentMaterialCodeItemVO> list = deliveryItemService.lambdaQuery()
|
||||
// .eq(WmsShipmentDeliveryItem::getDeliveryId, id)
|
||||
// .orderByAsc(WmsShipmentDeliveryItem::getId)
|
||||
// .list()
|
||||
// .stream().map(item -> {
|
||||
// ShipmentMaterialCodeItemVO vo = Convert.convert(ShipmentMaterialCodeItemVO.class, item);
|
||||
// vo.setIndex(index.getAndIncrement());
|
||||
// return vo;
|
||||
// }).toList();
|
||||
List<ShipmentMaterialCodeItemVO> list = deliveryItemService.getItemsVO(id);
|
||||
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
||||
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("发货清单-" + delivery.getNo() + ".xlsx", StandardCharsets.UTF_8));
|
||||
new Workbook()
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in New Issue