| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.vincent.rsf.framework.common.Cools; |
| | | import com.vincent.rsf.framework.common.R; |
| | | import com.vincent.rsf.framework.exception.CoolException; |
| | | import com.vincent.rsf.server.api.controller.erp.params.*; |
| | |
| | | private DictDataService dictDataService; |
| | | @Autowired |
| | | private DictTypeService dictTypeService; |
| | | @Autowired |
| | | private LocItemService locItemService; |
| | | |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 基础物料信息变更 |
| | | * @param baseMatParms |
| | | * @return |
| | | * 基础物料信息变更(对接协议 8.2) |
| | | * operateType:1新增 2修改 3禁用 4启用;不传或 1/2 时按有则更新、无则新增。 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | if (StringUtils.isBlank(baseMatParms.getMatnr())) { |
| | | throw new CoolException("物料编码不能为空!!"); |
| | | } |
| | | Integer operateType = baseMatParms.getOperateType(); |
| | | // 3 禁用 / 4 启用:仅更新状态(status 1 正常 0 冻结) |
| | | if (Integer.valueOf(3).equals(operateType) || Integer.valueOf(4).equals(operateType)) { |
| | | Matnr matnr = matnrService.getOne(new LambdaQueryWrapper<Matnr>().eq(Matnr::getCode, baseMatParms.getMatnr())); |
| | | if (matnr == null) { |
| | | throw new CoolException("物料不存在,无法执行禁用/启用!!"); |
| | | } |
| | | int status = Integer.valueOf(4).equals(operateType) ? 1 : 0; // 4 启用=1 正常,3 禁用=0 冻结 |
| | | matnr.setStatus(status); |
| | | if (!matnrService.updateById(matnr)) { |
| | | throw new CoolException(operateType == 4 ? "物料启用失败!!" : "物料禁用失败!!"); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | // 1 新增 / 2 修改 / 不传:有则更新、无则新增 |
| | | Matnr matnr = matnrService.getOne(new LambdaQueryWrapper<Matnr>().eq(Matnr::getCode, baseMatParms.getMatnr())); |
| | | if (Objects.isNull(matnr)) { |
| | | Matnr matnr1 = new Matnr(); |
| | |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | @Override |
| | | public R inventoryDetails(InventoryDetailsParam param) { |
| | | LambdaQueryWrapper<LocItem> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(LocItem::getDeleted, 0); |
| | | if (!Cools.isEmpty(param.getLocId())) { |
| | | wrapper.eq(LocItem::getLocCode, param.getLocId()); |
| | | } |
| | | if (!Cools.isEmpty(param.getMatNr())) { |
| | | wrapper.eq(LocItem::getMatnrCode, param.getMatNr()); |
| | | } |
| | | if (!Cools.isEmpty(param.getBatch())) { |
| | | wrapper.eq(LocItem::getBatch, param.getBatch()); |
| | | } |
| | | if (!Cools.isEmpty(param.getOrderNo())) { |
| | | wrapper.and(w -> w.eq(LocItem::getPlatOrderCode, param.getOrderNo()).or().eq(LocItem::getPlatWorkCode, param.getOrderNo())); |
| | | } |
| | | if (!Cools.isEmpty(param.getPlanNo())) { |
| | | wrapper.eq(LocItem::getPlatWorkCode, param.getPlanNo()); |
| | | } |
| | | if (!Cools.isEmpty(param.getWareHouseId())) { |
| | | Warehouse wh = warehouseService.getOne(new LambdaQueryWrapper<Warehouse>().eq(Warehouse::getCode, param.getWareHouseId())); |
| | | if (wh != null) { |
| | | List<Loc> locs = locService.list(new LambdaQueryWrapper<Loc>().eq(Loc::getWarehouseId, wh.getId())); |
| | | if (!locs.isEmpty()) { |
| | | wrapper.in(LocItem::getLocId, locs.stream().map(Loc::getId).collect(Collectors.toList())); |
| | | } else { |
| | | return R.ok().add(Collections.emptyList()); |
| | | } |
| | | } else { |
| | | return R.ok().add(Collections.emptyList()); |
| | | } |
| | | } |
| | | List<LocItem> list = locItemService.list(wrapper); |
| | | List<Map<String, Object>> result = new ArrayList<>(); |
| | | for (LocItem item : list) { |
| | | Map<String, Object> row = new LinkedHashMap<>(); |
| | | row.put("locId", item.getLocCode()); |
| | | Loc loc = locService.getById(item.getLocId()); |
| | | if (loc != null && loc.getWarehouseId() != null) { |
| | | Warehouse w = warehouseService.getById(loc.getWarehouseId()); |
| | | row.put("wareHouseId", w != null ? w.getCode() : null); |
| | | row.put("wareHouseName", w != null ? w.getName() : null); |
| | | } else { |
| | | row.put("wareHouseId", null); |
| | | row.put("wareHouseName", null); |
| | | } |
| | | row.put("palletId", item.getTrackCode()); |
| | | row.put("matNr", item.getMatnrCode()); |
| | | row.put("makTx", item.getMaktx()); |
| | | row.put("anfme", item.getAnfme() != null ? item.getAnfme() : 0); |
| | | row.put("unit", item.getUnit()); |
| | | row.put("status", item.getStatus() != null ? item.getStatus() : 1); |
| | | row.put("orderType", item.getWkType()); |
| | | row.put("orderNo", item.getPlatOrderCode()); |
| | | row.put("planNo", item.getPlatWorkCode()); |
| | | row.put("batch", item.getBatch()); |
| | | result.add(row); |
| | | } |
| | | return R.ok().add(result); |
| | | } |
| | | |
| | | @Override |
| | | public R inventorySummary(InventorySummaryParam param) { |
| | | LambdaQueryWrapper<LocItem> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(LocItem::getDeleted, 0).select(LocItem::getLocId, LocItem::getMatnrCode, LocItem::getMaktx, LocItem::getAnfme, LocItem::getUnit); |
| | | if (!Cools.isEmpty(param.getWareHouseId())) { |
| | | Warehouse wh = warehouseService.getOne(new LambdaQueryWrapper<Warehouse>().eq(Warehouse::getCode, param.getWareHouseId())); |
| | | if (wh != null) { |
| | | List<Loc> locs = locService.list(new LambdaQueryWrapper<Loc>().eq(Loc::getWarehouseId, wh.getId())); |
| | | if (!locs.isEmpty()) { |
| | | wrapper.in(LocItem::getLocId, locs.stream().map(Loc::getId).collect(Collectors.toList())); |
| | | } else { |
| | | return R.ok().add(Collections.emptyList()); |
| | | } |
| | | } else { |
| | | return R.ok().add(Collections.emptyList()); |
| | | } |
| | | } |
| | | if (!Cools.isEmpty(param.getMatNr())) { |
| | | List<String> matNrs = Arrays.asList(param.getMatNr().split(",")); |
| | | wrapper.in(LocItem::getMatnrCode, matNrs.stream().map(String::trim).collect(Collectors.toList())); |
| | | } |
| | | List<LocItem> list = locItemService.list(wrapper); |
| | | Map<String, Map<String, Object>> sumMap = new LinkedHashMap<>(); |
| | | for (LocItem item : list) { |
| | | Loc loc = locService.getById(item.getLocId()); |
| | | String whId = null; |
| | | String whName = null; |
| | | if (loc != null && loc.getWarehouseId() != null) { |
| | | Warehouse w = warehouseService.getById(loc.getWarehouseId()); |
| | | whId = w != null ? w.getCode() : null; |
| | | whName = w != null ? w.getName() : null; |
| | | } |
| | | String key = (whId != null ? whId : "") + "|" + (item.getMatnrCode() != null ? item.getMatnrCode() : ""); |
| | | final String finalWhId = whId; |
| | | final String finalWhName = whName; |
| | | sumMap.compute(key, (k, v) -> { |
| | | if (v == null) { |
| | | v = new LinkedHashMap<>(); |
| | | v.put("wareHouseId", finalWhId); |
| | | v.put("wareHouseName", finalWhName); |
| | | v.put("matNr", item.getMatnrCode()); |
| | | v.put("matTx", item.getMaktx()); |
| | | v.put("anfme", (item.getAnfme() != null ? item.getAnfme() : 0)); |
| | | v.put("unit", item.getUnit()); |
| | | } else { |
| | | v.put("anfme", ((Number) v.get("anfme")).doubleValue() + (item.getAnfme() != null ? item.getAnfme() : 0)); |
| | | } |
| | | return v; |
| | | }); |
| | | } |
| | | return R.ok().add(new ArrayList<>(sumMap.values())); |
| | | } |
| | | } |