package com.ruoyi.base.service.impl; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.ruoyi.base.constant.Constant; import com.ruoyi.base.domain.BaseLocationInfo; import com.ruoyi.base.domain.vo.BasLocationTreeSelectVO; import com.ruoyi.base.domain.vo.TreeSelectVO; import com.ruoyi.common.utils.DateUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.base.mapper.BaseLocationZoneMapper; import com.ruoyi.base.domain.BaseLocationZone; import com.ruoyi.base.service.IBaseLocationZoneService; /** * 库区Service业务层处理 * * @author andy * @date 2022-02-15 */ @Service public class BaseLocationZoneServiceImpl implements IBaseLocationZoneService { @Autowired private BaseLocationZoneMapper baseLocationZoneMapper; /** * 查询库区 * * @param zoneId 库区主键 * @return 库区 */ @Override public BaseLocationZone selectBaseLocationZoneByZoneId(Long zoneId) { return baseLocationZoneMapper.selectBaseLocationZoneByZoneId(zoneId); } /** * 查询库区列表 * * @param baseLocationZone 库区 * @return 库区 */ @Override public List selectBaseLocationZoneList(BaseLocationZone baseLocationZone) { return baseLocationZoneMapper.selectBaseLocationZoneList(baseLocationZone); } @Override public List selectBaseLocationZoneList() { return baseLocationZoneMapper.selectList(Wrappers.lambdaQuery() .eq(BaseLocationZone::getStatus, Constant.ZoneStatus.ENABLE.getCode())); } /** * pda查询库区列表 * * @param baseLocationZone 库区 * @return 库区 */ @Override public List selectBaseLocationZoneList1(BaseLocationZone baseLocationZone) { return baseLocationZoneMapper.selectBaseLocationZoneList1(baseLocationZone); } /** * 新增库区 * * @param baseLocationZone 库区 * @return 结果 */ @Override public int insertBaseLocationZone(BaseLocationZone baseLocationZone) { baseLocationZone.setCreateTime(DateUtils.getNowDate()); return baseLocationZoneMapper.insertBaseLocationZone(baseLocationZone); } /** * 修改库区 * * @param baseLocationZone 库区 * @return 结果 */ @Override public int updateBaseLocationZone(BaseLocationZone baseLocationZone) { baseLocationZone.setUpdateTime(DateUtils.getNowDate()); return baseLocationZoneMapper.updateBaseLocationZone(baseLocationZone); } /** * 批量删除库区 * * @param zoneIds 需要删除的库区主键 * @return 结果 */ @Override public int deleteBaseLocationZoneByZoneIds(Long[] zoneIds) { return baseLocationZoneMapper.deleteBaseLocationZoneByZoneIds(zoneIds); } /** * 删除库区信息 * * @param zoneId 库区主键 * @return 结果 */ @Override public int deleteBaseLocationZoneByZoneId(Long zoneId) { return baseLocationZoneMapper.deleteBaseLocationZoneByZoneId(zoneId); } @Override public List buildLocationTreeSelect() { List locationTrees = buildLocationTree(0L); return locationTrees.stream().map(TreeSelectVO::new).collect(Collectors.toList()); } @Override public List buildLocationTree(Long zoneId) { // 查询区域,库位树把区域也组装进去 BaseLocationZone queryZone = new BaseLocationZone(); queryZone.setStatus("0"); List zoneList = baseLocationZoneMapper.selectBaseLocationZoneList(queryZone); List locationTreeSelectVOList = new ArrayList<>(); //循环遍历每个区域的库位 for (BaseLocationZone zone : zoneList) { BasLocationTreeSelectVO parent = new BasLocationTreeSelectVO(); List children = new ArrayList<>(); BaseLocationInfo query = new BaseLocationInfo(); query.setZoneId(zone.getZoneId()); parent.setId(zone.getZoneId()); parent.setTreeName(zone.getZoneName()); parent.setChildren(children); locationTreeSelectVOList.add(parent); } return locationTreeSelectVOList; } }