|  |  |  | 
|---|
|  |  |  | import com.vincent.rsf.framework.common.R; | 
|---|
|  |  |  | import com.vincent.rsf.framework.exception.CoolException; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.controller.params.LocAreaMatsParam; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.LocTypeRela; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.Matnr; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.*; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.mapper.LocAreaMatRelaMapper; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.LocAreaMatRela; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.LocAreaMatRelaService; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.*; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.LocService; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.LocTypeRelaService; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.MatnrService; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | private LocService locService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private MatnrGroupService matnrGroupService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocTypeRelaService locTypeRelaService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocTypeService locTypeService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | for (Matnr matnrId : matnrIds) { | 
|---|
|  |  |  | LocAreaMatRela locAreaMatRela = new LocAreaMatRela(); | 
|---|
|  |  |  | locAreaMatRela | 
|---|
|  |  |  | .setAreaId(param.getAreaId()) | 
|---|
|  |  |  | .setAreaMatId(param.getAreaMatId()) | 
|---|
|  |  |  | //                                .setAreaId(param.getAreaId()) | 
|---|
|  |  |  | .setLocId(locId) | 
|---|
|  |  |  | .setLocTypeId(typeId) | 
|---|
|  |  |  | .setMatnrId(matnrId.getId()) | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!Objects.isNull(param.getLocId()) && !param.getLocId().isEmpty()) { | 
|---|
|  |  |  | List<LocTypeRela> list = locTypeRelaService.list(new LambdaQueryWrapper<LocTypeRela>().in(LocTypeRela::getLocId, param.getLocId()).select(LocTypeRela::getTypeId, LocTypeRela::getLocId)); | 
|---|
|  |  |  | List<LocTypeRela> list = locTypeRelaService.list(new LambdaQueryWrapper<LocTypeRela>() | 
|---|
|  |  |  | .in(LocTypeRela::getLocId, param.getLocId()) | 
|---|
|  |  |  | .select(LocTypeRela::getTypeId, LocTypeRela::getLocId)); | 
|---|
|  |  |  | if (list.isEmpty()) { | 
|---|
|  |  |  | throw new CoolException("数据错误:库位未绑定库位类型!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | LocAreaMatRela locAreaMatRela = new LocAreaMatRela(); | 
|---|
|  |  |  | locAreaMatRela | 
|---|
|  |  |  | .setAreaId(param.getAreaId()) | 
|---|
|  |  |  | .setAreaMatId(param.getAreaMatId()) | 
|---|
|  |  |  | .setLocId(locTypeRela.getLocId()) | 
|---|
|  |  |  | .setLocTypeId(locTypeRela.getTypeId()) | 
|---|
|  |  |  | .setMatnrId(matnr.getId()) | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("绑定成功!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @description 移除物料分组下绑定关系 | 
|---|
|  |  |  | * @param | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | * @time 2025/3/24 13:33 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Boolean removeByGroupId(Map<String, Object> param) { | 
|---|
|  |  |  | if (Objects.isNull(param)) { | 
|---|
|  |  |  | throw new CoolException("物料分组ID不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!StringUtils.isBlank(param.get("groupId").toString())) { | 
|---|
|  |  |  | throw new CoolException("物料分类不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!StringUtils.isBlank(param.get("areaMatId").toString())) { | 
|---|
|  |  |  | throw new CoolException("主单ID不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!this.remove(new LambdaQueryWrapper<LocAreaMatRela>() | 
|---|
|  |  |  | .eq(LocAreaMatRela::getAreaMatId, Long.parseLong(param.get("areaMatId").toString())) | 
|---|
|  |  |  | .eq(LocAreaMatRela::getGroupId, Long.parseLong(param.get("groupId").toString())))) { | 
|---|
|  |  |  | throw new CoolException("删除失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @description 移除库位类型绑定关系 | 
|---|
|  |  |  | * @param | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | * @time 2025/3/24 13:32 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public boolean removeByLocType(Map<String, Object> param) { | 
|---|
|  |  |  | if (Objects.isNull(param)) { | 
|---|
|  |  |  | throw new CoolException("库位类型ID不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!this.remove(new LambdaQueryWrapper<LocAreaMatRela>() | 
|---|
|  |  |  | .eq(LocAreaMatRela::getAreaMatId, Long.parseLong(param.get("areaMatId").toString())) | 
|---|
|  |  |  | .eq(LocAreaMatRela::getLocTypeId, Long.parseLong(param.get("typeId").toString())))) { | 
|---|
|  |  |  | throw new CoolException("删除失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @description 获取物料分组 | 
|---|
|  |  |  | * @param | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | * @time 2025/3/24 13:32 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<MatnrGroup> getAllGroups(Long id) { | 
|---|
|  |  |  | if (Objects.isNull(id)) { | 
|---|
|  |  |  | throw new CoolException("主单ID不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<LocAreaMatRela> locAreaMatRelas = this.list(new LambdaQueryWrapper<LocAreaMatRela>().eq(LocAreaMatRela::getAreaMatId, id)); | 
|---|
|  |  |  | if (locAreaMatRelas.isEmpty()) { | 
|---|
|  |  |  | return new ArrayList<>(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Long> longList = locAreaMatRelas.stream().map(LocAreaMatRela::getGroupId).collect(Collectors.toList()); | 
|---|
|  |  |  | List<MatnrGroup> groups = matnrGroupService.list(new LambdaQueryWrapper<MatnrGroup>().in(MatnrGroup::getId, longList)); | 
|---|
|  |  |  | if (groups.isEmpty()) { | 
|---|
|  |  |  | return new ArrayList<>(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return groups; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @description 获取绑定库位物料 | 
|---|
|  |  |  | * @param | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | * @time 2025/3/24 13:36 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<LocType> getAllLocType(Long id) { | 
|---|
|  |  |  | if (Objects.isNull(id)) { | 
|---|
|  |  |  | throw new CoolException("主单ID不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<LocAreaMatRela> locAreaMatRelas = this.list(new LambdaQueryWrapper<LocAreaMatRela>().eq(LocAreaMatRela::getAreaMatId, id)); | 
|---|
|  |  |  | if (locAreaMatRelas.isEmpty()) { | 
|---|
|  |  |  | return new ArrayList<>(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Long> longList = locAreaMatRelas.stream().map(LocAreaMatRela::getLocTypeId).collect(Collectors.toList()); | 
|---|
|  |  |  | List<LocType> list = locTypeService.list(new LambdaQueryWrapper<LocType>().in(LocType::getId, longList)); | 
|---|
|  |  |  | if (list.isEmpty()) { | 
|---|
|  |  |  | return new ArrayList<>(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return list; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|