查询调整
This commit is contained in:
parent
1aa13ece77
commit
72151cb3eb
|
|
@ -10,8 +10,10 @@ package com.nflg.product.bomnew.mapper.master;
|
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.nflg.product.bomnew.pojo.entity.OptionalEbomMainEntity;
|
||||
import com.nflg.product.bomnew.pojo.entity.OptionalMbomMaterialEntity;
|
||||
import com.nflg.product.bomnew.pojo.query.BomNewMbomParentQuery;
|
||||
import com.nflg.product.bomnew.pojo.query.OptionalEbomMainListQuery;
|
||||
import com.nflg.product.bomnew.pojo.query.OptionalMbomMaterialListQuery;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomNewMbomMiddleVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.OptionalEbomMainVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.OptionalMbomMaterialListVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.OptionalMbomMaterialVO;
|
||||
|
|
@ -32,5 +34,16 @@ public interface OptionalMbomMaterialMapper extends BaseMapper<OptionalMbomMater
|
|||
Page<OptionalMbomMaterialListVO> getListPage(Page page, @Param("query") OptionalMbomMaterialListQuery query);
|
||||
public List<OptionalMbomMaterialListVO> getChild(@Param("rowId") Long rowId);
|
||||
|
||||
|
||||
|
||||
Page<OptionalMbomMaterialListVO> indexListPage(Page<OptionalMbomMaterialListVO> page, @Param("query") OptionalMbomMaterialListQuery query );
|
||||
|
||||
/**
|
||||
* 递归向上查找所有数据
|
||||
* @param rowId 当前行
|
||||
* @return
|
||||
*/
|
||||
List<OptionalMbomMaterialListVO> searchList(@Param("rowId") Long rowId );
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@ import io.swagger.annotations.ApiModelProperty;
|
|||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ApiModel("mbom发布生成的物料信息")
|
||||
|
|
@ -26,7 +28,7 @@ public class OptionalMbomMaterialListVO extends BaseMaterialVO {
|
|||
* 上层id
|
||||
*/
|
||||
@ApiModelProperty(value = "根id")
|
||||
private Long rootRowId;;
|
||||
private Long rootRowId;
|
||||
/**
|
||||
* 物料编码
|
||||
*/
|
||||
|
|
@ -95,4 +97,8 @@ public class OptionalMbomMaterialListVO extends BaseMaterialVO {
|
|||
*/
|
||||
@ApiModelProperty(value = "操作人姓名")
|
||||
private String realName;
|
||||
|
||||
|
||||
private List<OptionalMbomMaterialListVO> childNodes = Collections.emptyList();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package com.nflg.product.bomnew.service;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
|
@ -11,13 +13,18 @@ import com.nflg.product.bomnew.pojo.entity.OptionalMbomMaterialEntity;
|
|||
|
||||
import com.nflg.product.bomnew.pojo.query.OptionalMbomMaterialListQuery;
|
||||
|
||||
import com.nflg.product.bomnew.pojo.vo.BomNewMbomMiddleVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.OptionalMbomMaterialListVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.OptionalMbomMaterialVO;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* mbom发布生成的物料信息(OptionalMbomMaterial)表服务实现类
|
||||
|
|
@ -31,11 +38,60 @@ public class OptionalMbomMaterialService extends ServiceImpl<OptionalMbomMateria
|
|||
@Resource
|
||||
MaterialMainService materialMainService;
|
||||
public Page<OptionalMbomMaterialListVO> getListPage(OptionalMbomMaterialListQuery query) {
|
||||
Page<OptionalMbomMaterialListVO> list = this.getBaseMapper().getListPage(new Page<>(query.getPage(), query.getPageSize()), query);
|
||||
materialMainService.intiMaterialInfo(list.getRecords());
|
||||
return list;
|
||||
// Page<OptionalMbomMaterialListVO> list = this.getBaseMapper().getListPage(new Page<>(query.getPage(), query.getPageSize()), query);
|
||||
|
||||
Page<OptionalMbomMaterialListVO> page;
|
||||
if (StrUtil.isNotBlank(query.getMaterialNo()) || StrUtil.isNotBlank(query.getDrawingNo())) {
|
||||
page = this.getBaseMapper().indexListPage(new Page<>(query.getPage(), query.getPageSize()), query);
|
||||
if (CollectionUtil.isNotEmpty(page.getRecords())) {
|
||||
List<OptionalMbomMaterialListVO> indexList = page.getRecords().stream().collect(Collectors.toList());
|
||||
page.getRecords().clear();
|
||||
|
||||
for(OptionalMbomMaterialListVO item :
|
||||
indexList) {
|
||||
List<OptionalMbomMaterialListVO> childList = this.getBaseMapper().searchList(item.getRowId());
|
||||
OptionalMbomMaterialListVO parent=listToTree(childList);
|
||||
if(Objects.nonNull(parent)){
|
||||
page.getRecords().add(parent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// materialMainService.intiMaterialInfo(list.getRecords());
|
||||
//不是通过物料或图号搜索
|
||||
page = this.getBaseMapper().getListPage(new Page<>(query.getPage(), query.getPageSize()), query);
|
||||
materialMainService.intiMaterialInfo(page.getRecords());
|
||||
return page;
|
||||
|
||||
}
|
||||
|
||||
private OptionalMbomMaterialListVO listToTree(List<OptionalMbomMaterialListVO> childs) {
|
||||
|
||||
if(CollectionUtil.isEmpty(childs)){
|
||||
return null;
|
||||
}
|
||||
|
||||
materialMainService.intiMaterialInfo(childs);
|
||||
Map<Long, List<OptionalMbomMaterialListVO>> groupMap = childs.stream().collect(Collectors.groupingBy(OptionalMbomMaterialListVO::getParentRowId));
|
||||
childs.forEach(child -> {
|
||||
child.setChildNodes(groupMap.get(child.getRowId()));
|
||||
|
||||
});
|
||||
//筛选出根
|
||||
List<OptionalMbomMaterialListVO> collect = childs.stream().filter(item -> Objects.isNull(item.getParentRowId()) || item.getParentRowId().longValue()==0).collect(Collectors.toList());
|
||||
return collect.get(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public List<OptionalMbomMaterialListVO> getChild(Long rowId) {
|
||||
List<OptionalMbomMaterialListVO> list= this.getBaseMapper().getChild(rowId);
|
||||
|
||||
|
|
|
|||
|
|
@ -58,17 +58,17 @@ row_id,parent_row_id,level_row_id,material_no,material_name,material_desc,drawin
|
|||
left join t_optional_ebom_config as t2
|
||||
on t1.root_row_id=t2.row_id
|
||||
|
||||
<where>
|
||||
t1.parent_row_id is null
|
||||
where
|
||||
t1.parent_row_id=0
|
||||
and t1.created_by=#{query.createdBy}
|
||||
|
||||
<if test="query.materialNo != null and query.materialNo != ''">
|
||||
and t1.material_no like concat('%', '${query.materialNo}', '%')
|
||||
and t1.material_no=#{query.materialNo}
|
||||
</if>
|
||||
|
||||
|
||||
<if test="query.drawingNo != null and query.drawingNo != '' ">
|
||||
and t1.drawing_no like concat('%', '${query.drawingNo}', '%')
|
||||
and t1.drawing_no like concat('', #{query.drawingNo} , '%')
|
||||
</if>
|
||||
|
||||
<if test="query.startDate != null and query.startDate != '' and query.endDate != null and query.endDate != null">
|
||||
|
|
@ -76,7 +76,7 @@ row_id,parent_row_id,level_row_id,material_no,material_name,material_desc,drawin
|
|||
</if>
|
||||
|
||||
|
||||
</where>
|
||||
|
||||
|
||||
order by t1.created_time DESC
|
||||
</select>
|
||||
|
|
@ -99,6 +99,45 @@ row_id,parent_row_id,level_row_id,material_no,material_name,material_desc,drawin
|
|||
</select>
|
||||
|
||||
|
||||
<select id="indexListPage" resultType="com.nflg.product.bomnew.pojo.vo.OptionalMbomMaterialListVO">
|
||||
SELECT max(t1.row_id) as row_id ,t1.root_row_id from t_optional_mbom_material t1
|
||||
where t1.created_by=#{query.createdBy}
|
||||
|
||||
<if test="query.drawingNo!=null and query.drawingNo!=''">
|
||||
and t1.drawing_no like concat ('',#{query.drawingNo},'%')
|
||||
</if>
|
||||
<if test="query.materialNo!=null and query.materialNo!=''">
|
||||
and t1.material_no=#{query.materialNo}
|
||||
</if>
|
||||
|
||||
GROUP BY t1.root_row_id
|
||||
</select>
|
||||
|
||||
<select id="searchList" resultType="com.nflg.product.bomnew.pojo.vo.OptionalMbomMaterialListVO">
|
||||
<![CDATA[
|
||||
select T1.*,
|
||||
T2.device_name,
|
||||
T2.device_no,
|
||||
T2.upload_sap_status,
|
||||
T2.dept_name,
|
||||
T2.real_name
|
||||
|
||||
from (SELECT t2.*
|
||||
FROM (SELECT @r AS _row_id,
|
||||
(SELECT @r := parent_row_id
|
||||
FROM t_optional_mbom_material
|
||||
WHERE row_id = _row_id) AS parent_row_id
|
||||
FROM
|
||||
(SELECT @r := #{rowId}) vars
|
||||
, t_optional_mbom_material AS h
|
||||
WHERE @r <> 0) t1
|
||||
JOIN t_optional_mbom_material t2
|
||||
ON t1._row_id = t2.row_id
|
||||
)as T1
|
||||
left join t_optional_ebom_config as T2
|
||||
on T1.root_row_id=T2.row_id
|
||||
]]>
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue