物资下拉框出现重复问题

This commit is contained in:
sxu 2024-11-06 18:49:38 +08:00
parent 7d18c5641b
commit 2e3516d110
6 changed files with 100 additions and 7 deletions

View File

@ -1,12 +1,21 @@
package com.bonus.material.ma.controller;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import cn.hutool.core.convert.Convert;
import com.bonus.common.biz.config.ListPagingUtil;
import com.bonus.common.core.utils.ServletUtils;
import com.bonus.common.log.enums.OperaType;
import com.bonus.material.common.annotation.PreventRepeatSubmit;
import com.bonus.material.ma.domain.vo.MaTypeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
@ -48,6 +57,28 @@ public class PartTypeController extends BaseController
return partTypeService.selectPartTypeList(partType);
}
/**
* 根据左列表类型id查询右表格
*
* @param partType
* @return
*/
@ApiOperation(value = "根据左列表类型id查询右表格")
@GetMapping("/getListByPartType")
public AjaxResult getListByPartType(PartType partType) {
List<Integer> parentIds = partTypeService.selectParentId(partType);
if (CollectionUtils.isEmpty(parentIds)) {
return AjaxResult.success(new ArrayList<>());
}
List<PartType> maTypeVos = new ArrayList<>();
Integer pageIndex = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
Integer pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
for (Integer parentId : parentIds) {
maTypeVos.addAll(partTypeService.getListByParentId(parentId.longValue(), partType));
}
return AjaxResult.success(ListPagingUtil.paging(pageIndex, pageSize, maTypeVos));
}
@ApiOperation(value = "配件类型所属上级树")
@RequiresPermissions("ma:type:query")
@GetMapping("/getPartTree")

View File

@ -79,16 +79,11 @@ public class TypeController extends BaseController {
for (Integer parentId : parentIds) {
maTypeVos.addAll(typeService.getListByParentId(parentId.longValue(), maTypeVo));
}
List<MaTypeVo> updatedMaTypeVos = maTypeVos.stream()
.map(obj -> {
obj.setHouseId(maTypeVo.getHouseId());
return obj;
}).collect(Collectors.toList());
if (BooleanUtils.isTrue(maTypeVo.getDisplayBindRelationship())) {
List<MaTypeVo> finalMaTypeVos = typeService.getMyTypeAndBindUsers(updatedMaTypeVos);
List<MaTypeVo> finalMaTypeVos = typeService.getMyTypeAndBindUsers(maTypeVos);
return AjaxResult.success(ListPagingUtil.paging(pageIndex, pageSize, finalMaTypeVos));
} else {
return AjaxResult.success(ListPagingUtil.paging(pageIndex, pageSize, updatedMaTypeVos));
return AjaxResult.success(ListPagingUtil.paging(pageIndex, pageSize, maTypeVos));
}
}

View File

@ -4,6 +4,8 @@ import java.util.List;
import com.bonus.common.biz.domain.TreeNode;
import com.bonus.material.ma.domain.PartType;
import com.bonus.material.ma.domain.vo.MaTypeVo;
import org.apache.ibatis.annotations.Param;
/**
* 配件类型管理Mapper接口
@ -87,4 +89,12 @@ public interface PartTypeMapper
* @return
*/
int selectPart(Long id);
/**
* 根据level层级和typeID 查询父级ID
* @param partType
*/
List<Integer> selectParentId(PartType partType);
List<PartType> getListByTypeName(@Param("paId") Long id, @Param("type") PartType partType);
}

View File

@ -4,6 +4,7 @@ import java.util.List;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.material.ma.domain.PartType;
import com.bonus.material.ma.domain.vo.MaTypeVo;
/**
* 配件类型管理Service接口
@ -66,4 +67,8 @@ public interface IPartTypeService
* @return
*/
List<PartType> getTypeList(PartType partType);
List<Integer> selectParentId(PartType partType);
List<PartType> getListByParentId(Long id, PartType type);
}

View File

@ -10,6 +10,7 @@ import com.bonus.common.biz.enums.HttpCodeEnum;
import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.security.utils.SecurityUtils;
import com.bonus.material.ma.domain.vo.MaTypeVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -183,4 +184,13 @@ public class PartTypeServiceImpl implements IPartTypeService
return partTypeMapper.getTypeList(partType);
}
@Override
public List<Integer> selectParentId(PartType partType) {
return partTypeMapper.selectParentId(partType);
}
@Override
public List<PartType> getListByParentId(Long id, PartType type) {
return partTypeMapper.getListByTypeName(id, type);
}
}

View File

@ -151,4 +151,46 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update ma_part_type set del_flag = '2' where pa_id = #{id}
</delete>
<select id="selectParentId" resultType="java.lang.Integer">
SELECT DISTINCT
mt2.pa_id
FROM
ma_part_type mt
LEFT JOIN ma_part_type mt2 ON mt.parent_id = mt2.pa_id
LEFT JOIN ma_part_type mt3 ON mt2.parent_id = mt3.pa_id
<where>
<if test="level == 0">
and mt.level = 4
</if>
<if test="level == 1">
and mt3.pa_id = #{id}
</if>
<if test="level == 2">
and mt2.pa_id = #{id}
</if>
and mt2.pa_id is not null
</where>
</select>
<select id="getListByTypeName" resultType="com.bonus.material.ma.domain.PartType">
SELECT DISTINCT
m.pa_id AS id,
m.pa_name AS paName,
m.parent_id as parentId,
m.LEVEL as level,
m.remark as remark
FROM
ma_part_type m
LEFT JOIN ma_part_type m1 ON m.parent_id = m1.pa_id
and m1.del_flag = '0'
LEFT JOIN ma_part_type m2 ON m1.parent_id = m2.pa_id
and m2.del_flag = '0'
WHERE m.parent_id = #{paId} and m.del_flag = '0'
<if test="type.keyword != null and type.keyword !=''">
AND (m.pa_name like concat('%',#{type.keyword},'%')
or m1.pa_name like concat('%',#{type.keyword},'%')
or m2.pa_name like concat('%',#{type.keyword},'%')
)
</if>
</select>
</mapper>