物资类型API--优化业务代码至service层

This commit is contained in:
syruan 2024-10-21 15:37:44 +08:00
parent ed83f77055
commit e48ddb3d85
4 changed files with 64 additions and 63 deletions

View File

@ -38,9 +38,6 @@ public class TypeController extends BaseController {
@Resource
private ITypeService typeService;
@Resource
private IWhHouseSetService houseSetService;
/**
* 查询物资类型管理列表
*/
@ -82,32 +79,12 @@ public class TypeController extends BaseController {
*/
@ApiOperation(value = "获取物资类型连动式下拉框")
@GetMapping("/equipmentType")
public AjaxResult equipmentType(@RequestParam(required = false) Long typeId,
@RequestParam(required = false) String typeName) {
public AjaxResult equipmentType(@RequestParam(required = false) Long typeId, @RequestParam(required = false) String typeName) {
List<Type> listByMaType = typeService.getEquipmentType(typeId, typeName);
return success(listByMaType);
}
/**
* 根据左列表类型id查询右表格 --- 暂未启用代码有问题!!
* TODO: 待完善
* @param typeId 左列表类型id
*/
@ApiOperation(value = "根据左列表类型id查询右表格")
@GetMapping("/getListByMaType")
public AjaxResult getListByMaType(Long typeId, @RequestParam(required = false) String typeName, Integer level) {
List<Integer> parentIds = typeService.selectParentId(typeId, level);
List<Type> listByMaType = new ArrayList<>();
for (Integer parentId : parentIds) {
listByMaType.addAll(typeService.getListByParentId(parentId.longValue(), typeName));
}
// Integer pageIndex = Convert.toInt(ServletUtils.getParameter(PAGE_NUM), 1);
// Integer pageSize = Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 10);
// return AjaxResult.success(ListPagingUtil.paging(pageIndex, pageSize, listByMaType));
return null;
}
/**
* TODO : 后续优化代码逻辑
* 物资类型下拉树
@ -115,32 +92,9 @@ public class TypeController extends BaseController {
@ApiOperation(value = "物资类型下拉树")
@RequiresPermissions("ma:type:list")
@GetMapping("/getMaTypeTreeSelect")
public AjaxResult getMaTypeTreeSelect(@RequestParam(required = false, defaultValue = "", value = "typeName") String typeName, @RequestParam(required = false, defaultValue = "", value = "parentId") String parentId) {
// 1.顶级节点及子节点数据全部查询完毕
List<TreeSelect> maTypeList = typeService.getMaTypeTree(typeName, parentId);
// 2.查询所有的仓库配置
List<WhHouseSet> whHouseSets = houseSetService.selectListByMaType(null);
// 2.1 定义最终接口返回集合
List<TreeSelect> treeSelectResultList = new ArrayList<>();
// 3.遍历所有配置关联
for (WhHouseSet whHouseSet : whHouseSets) {
Long typeId = whHouseSet.getTypeId();
if (typeId == null) {continue;}
// 构造函数定义0级Tree对象
TreeSelect thisTree = new TreeSelect(whHouseSet.getId(),whHouseSet.getHouseName(),0,null);
// 定义1级列表并循环push相应的1级节点
List<TreeSelect> oneLevelTreeList = new ArrayList<>();
for (TreeSelect treeSelect : maTypeList) {
if (treeSelect.getId().equals(typeId)) {
oneLevelTreeList.add(treeSelect);
}
}
// 把处理后对应上的1级列表当作child存入0级Tree对象中
thisTree.setChildren(!oneLevelTreeList.isEmpty() ? oneLevelTreeList : null);
// 最后把0级Tree对象存入Result返回集合中返回给前端
treeSelectResultList.add(thisTree);
}
return AjaxResult.success(treeSelectResultList);
public AjaxResult getMaTypeTreeSelect(@RequestParam(required = false, defaultValue = "", value = "typeName") String typeName,
@RequestParam(required = false, defaultValue = "", value = "parentId") String parentId) {
return typeService.getMaTypeTreeSelect(typeName, parentId);
}
/**
@ -213,4 +167,21 @@ public class TypeController extends BaseController {
// 调用service处理业务逻辑
return typeService.getMaTypeConfigList(maTypeConfigDto);
}
/**
* 根据左列表类型id查询右表格 --- 暂未启用代码有问题!!
* TODO: 待完善
* @param typeId 左列表类型id
@ApiOperation(value = "根据左列表类型id查询右表格")
@GetMapping("/getListByMaType")
public AjaxResult getListByMaType(Long typeId, @RequestParam(required = false) String typeName, Integer level) {
List<Integer> parentIds = typeService.selectParentId(typeId, level);
List<Type> listByMaType = new ArrayList<>();
for (Integer parentId : parentIds) {
listByMaType.addAll(typeService.getListByParentId(parentId.longValue(), typeName));
}
return null;
}*/
}

View File

@ -88,6 +88,8 @@ public interface ITypeService {
List<TreeSelect> getMaTypeTree(String typeName, String parentId);
AjaxResult getMaTypeTreeSelect(String typeName,String parentId);
/**
* 构建前端所需要树结构
*

View File

@ -17,6 +17,8 @@ import com.bonus.material.ma.service.ITypeRepairService;
import com.bonus.material.ma.vo.MaTypeConfigVo;
import com.bonus.material.ma.vo.MaTypeListVo;
import com.bonus.material.ma.vo.MaTypeSelectVo;
import com.bonus.material.warehouse.domain.WhHouseSet;
import com.bonus.material.warehouse.service.IWhHouseSetService;
import org.springframework.stereotype.Service;
import com.bonus.material.ma.mapper.TypeMapper;
import com.bonus.material.ma.domain.Type;
@ -45,6 +47,9 @@ public class TypeServiceImpl implements ITypeService {
@Resource
private ITypeRepairService typeRepairService;
@Resource
private IWhHouseSetService houseSetService;
/**
* 查询物资类型 -- 根据id
*
@ -83,8 +88,6 @@ public class TypeServiceImpl implements ITypeService {
}
@Override
public List<MaTypeSelectVo> selectMaTypeListByHouseId(Long houseId) {
return typeMapper.selectMaTypeListByHouseId(houseId);
@ -115,7 +118,7 @@ public class TypeServiceImpl implements ITypeService {
@Override
public List<Type> selectTypeList(Type type) {
if (type != null ) {
if (type.getDelFlag() == null || type.getDelFlag().isEmpty()) {
if (StringUtils.isEmpty(type.getDelFlag())) {
// 如果没赋值则默认查询正常数据状态
type.setDelFlag(String.valueOf(DataCodeEnum.NORMAL.getCode()));
}
@ -286,15 +289,44 @@ public class TypeServiceImpl implements ITypeService {
List<Type> maTypes = typeMapper.selectMaTypeTree(TYPE_MIN_LEVEL);
List<Type> builtMaTypeList = buildMaTypeTree(maTypes);
List<TreeSelect> treeSelectList = builtMaTypeList.stream()
.filter(Objects::nonNull)
.map(this::convertToTreeSelect)
.collect(Collectors.toList());
// 查询顶级节点的仓库配置信息
// 如果没有查询到那么返回空
return treeSelectList;
return builtMaTypeList.stream()
.filter(Objects::nonNull)
.map(this::convertToTreeSelect)
.collect(Collectors.toList());
}
@Override
public AjaxResult getMaTypeTreeSelect(String typeName, String parentId) {
// 1.顶级节点及子节点数据全部查询完毕
List<TreeSelect> maTypeList = this.getMaTypeTree(typeName, parentId);
// 2.查询所有的仓库配置
List<WhHouseSet> whHouseSets = houseSetService.selectListByMaType(null);
// 2.1 定义最终接口返回集合
List<TreeSelect> treeSelectResultList = new ArrayList<>();
// 使用HashMap来存储maTypeList以便快速查找
Map<Long, TreeSelect> maTypeMap = new HashMap<>();
for (TreeSelect treeSelect : maTypeList) {
maTypeMap.put(treeSelect.getId(), treeSelect);
}
// 3.遍历所有配置关联
for (WhHouseSet whHouseSet : whHouseSets) {
// --- 数据校验 ----
if (whHouseSet == null || whHouseSet.getTypeId() == null) { continue; }
// 构造函数定义0级Tree对象
TreeSelect thisTree = new TreeSelect(whHouseSet.getId(),whHouseSet.getHouseName(),0,null);
// 从Map中直接获取对应的1级节点
TreeSelect oneLevelTree = maTypeMap.get(whHouseSet.getTypeId());
// 转换为集合存入0级Tree对象中
thisTree.setChildren(oneLevelTree != null ? Collections.singletonList(oneLevelTree) : null);
// 最后把0级Tree对象存入Result结果集合返回给前端
treeSelectResultList.add(thisTree);
}
return AjaxResult.success(treeSelectResultList);
}
/**

View File

@ -26,10 +26,6 @@ public class PurchaseNoticePersonServiceImpl implements IPurchaseNoticePersonSer
@Resource
private PurchaseNoticePersonMapper purchaseNoticePersonMapper;
@Resource
private SmsUtils smsUtils;
/**
* 查询新购短信通知人员
*