| | |
| | | package com.vincent.rsf.server.api.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.vincent.rsf.framework.common.Cools; |
| | | import com.vincent.rsf.framework.common.R; |
| | |
| | | import com.vincent.rsf.server.common.enums.WarehouseAreaType; |
| | | import com.vincent.rsf.server.common.security.JwtSubject; |
| | | import com.vincent.rsf.server.common.utils.CommonUtil; |
| | | import com.vincent.rsf.server.common.utils.FieldsUtils; |
| | | import com.vincent.rsf.server.common.utils.JSONUtil; |
| | | import com.vincent.rsf.server.common.utils.JwtUtil; |
| | | import com.vincent.rsf.server.manager.controller.params.IsptItemsParams; |
| | | import com.vincent.rsf.server.manager.controller.params.WaitPakinParam; |
| | | import com.vincent.rsf.server.manager.entity.*; |
| | | import com.vincent.rsf.server.manager.enums.AsnExceStatus; |
| | | import com.vincent.rsf.server.manager.mapper.*; |
| | | import com.vincent.rsf.server.manager.service.*; |
| | | import com.vincent.rsf.server.system.constant.CodeRes; |
| | |
| | | import com.vincent.rsf.server.system.mapper.UserMapper; |
| | | import com.vincent.rsf.server.system.service.FieldsItemService; |
| | | import com.vincent.rsf.server.system.service.UserLoginService; |
| | | import com.vincent.rsf.server.system.utils.ExtendFieldsUtils; |
| | | import com.vincent.rsf.server.system.utils.SerialRuleUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R receiptToWarehouse(ReceiptParams params) { |
| | | if (params.getReceipts().isEmpty()) { |
| | | public R receiptToWarehouse(Map<String, Object> params) { |
| | | if (Objects.isNull(params)) { |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | | ReceiptParams receiptParam = JSONObject.parseObject(JSONObject.toJSONString(params), ReceiptParams.class); |
| | | if (receiptParam.getReceipts().isEmpty()) { |
| | | throw new CoolException("收货明细不能为空!!"); |
| | | } |
| | | if (Objects.isNull(params.getWhAreaId())) { |
| | | if (Objects.isNull(receiptParam.getWhAreaId())) { |
| | | throw new CoolException("库区标识不能为空!!"); |
| | | } |
| | | |
| | | WarehouseAreas areasItem = warehouseAreasService.getOne(new LambdaQueryWrapper<WarehouseAreas>() |
| | | .eq(WarehouseAreas::getId, params.getWhAreaId())); |
| | | .eq(WarehouseAreas::getId, receiptParam.getWhAreaId())); |
| | | if (Objects.isNull(areasItem)) { |
| | | throw new CoolException("数据错误:当前库区不存在!!"); |
| | | } |
| | | //获取已启用的动态扩展字 |
| | | List<Fields> fields = fieldsMapper.selectList(new LambdaQueryWrapper<Fields>() |
| | | .eq(Fields::getFlagEnable, 1) |
| | | .eq(Fields::getStatus, 1)); |
| | | |
| | | List<ReceiptDetlsDto> receipts = params.getReceipts(); |
| | | List<ReceiptDetlsDto> receipts = receiptParam.getReceipts(); |
| | | List<WarehouseAreasItem> allOrders = new ArrayList<>(); |
| | | |
| | | Double receiptQty = receipts.stream().mapToDouble(ReceiptDetlsDto::getReceiptQty).sum(); |
| | |
| | | if (Objects.isNull(asnOrder)) { |
| | | throw new CoolException("数据错误:主单不存在!!"); |
| | | } |
| | | /**收货数量累加,1. 会出超收情况 2. 会有收货不足情况*/ |
| | | //TODO /**收货数量累加,1. 会出超收情况 2. 会有收货不足情况*/ |
| | | Double rcptedQty = asnOrder.getQty() + receiptQty; |
| | | asnOrder.setQty(rcptedQty); |
| | | asnOrder.setQty(rcptedQty).setExceStatus(Short.parseShort(AsnExceStatus.ASN_EXCE_STATUS_EXCE_ING.val)); |
| | | |
| | | if (!asnOrderMapper.updateById(asnOrder)) { |
| | | throw new CoolException("已收货数量修改失败!!"); |
| | | } |
| | | |
| | | receipts.forEach(dto -> { |
| | | List<Map<String, Object>> receipts1 = (List<Map<String, Object>>) params.get("receipts"); |
| | | for (Map<String, Object> rcpt : receipts1) { |
| | | if (Objects.isNull(rcpt)) {continue;} |
| | | ReceiptDetlsDto dto = JSONObject.parseObject(JSONObject.toJSONString(rcpt), ReceiptDetlsDto.class); |
| | | Matnr matnr = matnrMapper.selectById(dto.getMatnrId()); |
| | | if (Objects.isNull(matnr)) { |
| | | throw new CoolException("数据错误:当前物料不存在!!"); |
| | |
| | | if (Objects.isNull(dto.getReceiptQty())) { |
| | | throw new CoolException("收货数据不能为空!!"); |
| | | } |
| | | if (dto.getReceiptQty().compareTo(dto.getAnfme()) > 0) { |
| | | throw new CoolException("收货数量不能大于采购数量!!"); |
| | | } |
| | | |
| | | // if (dto.getReceiptQty().compareTo(dto.getAnfme()) > 0) { |
| | | // throw new CoolException("收货数量不能大于采购数量!!"); |
| | | // } |
| | | AsnOrderItem orderItem = asnOrderItemMapper.selectOne(new LambdaQueryWrapper<AsnOrderItem>() |
| | | .eq(AsnOrderItem::getAsnCode, asnCode) |
| | | .eq(AsnOrderItem::getMatnrId, dto.getMatnrId())); |
| | | if (Objects.isNull(orderItem)) { |
| | | throw new CoolException("通知单明细不存在!!"); |
| | | } |
| | | // if (Objects.isNull(dto.getReceiptQty()) || Double.compare(dto.getReceiptQty(), 0.0) == 0) { |
| | | // throw new CoolException("收货数量不能为零!!"); |
| | | // } |
| | | if (Objects.isNull(dto.getReceiptQty()) || Double.compare(dto.getReceiptQty(), 0.0) == 0) { |
| | | throw new CoolException("收货数量不能为零!!"); |
| | | } |
| | | Double itemRcptQty = dto.getReceiptQty() + orderItem.getQty(); |
| | | orderItem.setQty(itemRcptQty) |
| | | .setSplrBatch(dto.getSplrBatch()) |
| | | .setStockUnit(dto.getStockUnit()) |
| | | .setProdTime(dto.getProdTime()); |
| | | |
| | | if (!Objects.isNull(fields)) { |
| | | if (!Objects.isNull(dto.getExtendFields())) { |
| | | //获取16位uuid |
| | | String uuid16 = CommonUtil.randomUUID16(); |
| | | Map<String, Object> extendFields = dto.getExtendFields(); |
| | | //字段集合申明 |
| | | List<FieldsItem> fieldsItems = new ArrayList<>(); |
| | | extendFields.keySet().forEach(key -> { |
| | | fields.forEach(obj -> { |
| | | //判断key值与fields表字段是否相同 |
| | | if (obj.getFields().equals(key)) { |
| | | FieldsItem fieldsItem = new FieldsItem(); |
| | | fieldsItem.setMatnrId(matnr.getId()).setFieldsId(obj.getId()) |
| | | .setShiperId(matnr.getShipperId()) |
| | | .setValue(extendFields.get(key).toString()) |
| | | .setUuid(uuid16); |
| | | fieldsItems.add(fieldsItem); |
| | | } |
| | | }); |
| | | }); |
| | | if (!fieldsItemService.saveBatch(fieldsItems)) { |
| | | throw new CoolException("扩展字段保存失败!!"); |
| | | if (!Objects.isNull(rcpt)) { |
| | | try { |
| | | if (Objects.isNull(rcpt.get("fieldsindex")) || StringUtils.isBlank(rcpt.get("fieldsindex").toString())) { |
| | | //获取16位uuid |
| | | String uuid16 = CommonUtil.randomUUID16(); |
| | | rcpt.put("index", uuid16); |
| | | orderItem.setFieldsIndex(uuid16); |
| | | } |
| | | orderItem.setFieldsIndex(uuid16); |
| | | //保存或更新扩展字段 |
| | | FieldsUtils.updateFieldsValue(rcpt); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | |
| | | // if (Objects.isNull(dto.getProdTime())) { |
| | | // format = dateFormat.format(dto.getProdTime()); |
| | | // } |
| | | item.setBarcode(dto.getBarcode()) |
| | | item.setTrackCode(dto.getBarcode()) |
| | | .setAreaName(areasItem.getName()) |
| | | .setAreaId(areasItem.getId()) |
| | | .setAsnItemId(orderItem.getId()) |
| | | .setAsnCode(asnOrder.getCode()) |
| | | .setAsnId(asnOrder.getId()) |
| | | .setProdTime(dto.getProdTime()) |
| | | .setWeight(dto.getWeigth()) |
| | | .setStockUnit(dto.getStockUnit()) |
| | | .setBatch(SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_RECEIPT_BATCH, dto)) |
| | | .setAnfme(itemRcptQty) |
| | | .setSplrBtch(dto.getSplrBatch()) |
| | | .setSplrBatch(dto.getSplrBatch()) |
| | | .setMatnrCode(matnr.getCode()) |
| | | .setMatnrId(matnr.getId()) |
| | | .setMatnrName(matnr.getName()) |
| | |
| | | .setWeight(matnr.getWeight()) |
| | | .setFieldsIndex(orderItem.getFieldsIndex()) |
| | | .setShipperId(matnr.getShipperId()); |
| | | //TODO 供应商标识未设置,标识由PO单供应商编码转换 |
| | | |
| | | //TODO 供应商标识未设置,标识由PO单供应商编码转换 |
| | | |
| | | allOrders.add(item); |
| | | }); |
| | | } |
| | | |
| | | if (!warehouseAreasItemService.saveBatch(allOrders)) { |
| | | throw new CoolException("收货失败!!"); |
| | |
| | | |
| | | @Override |
| | | public R getDeltByCode(String code) { |
| | | return R.ok(asnOrderItemMapper.selectOne(new LambdaQueryWrapper<AsnOrderItem>().eq(AsnOrderItem::getTrackCode, code))); |
| | | return R.ok(warehouseAreasItemService.getOne(new LambdaQueryWrapper<WarehouseAreasItem>().eq(WarehouseAreasItem::getTrackCode, code))); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | detlsDto.setAsnCode(asnOrderItem.getAsnCode()) |
| | | .setMaktx(asnOrderItem.getMaktx()) |
| | | .setFieldsIndex(asnOrderItem.getFieldsIndex()) |
| | | .setBarcode(asnOrderItem.getTrackCode()) |
| | | .setQty(asnOrderItem.getQty()) |
| | | .setPoCode(asnOrderItem.getPoCode()) |
| | |
| | | detlsDto.setPlatformId(purchaseItem.getPlatItemId()); |
| | | } |
| | | } |
| | | |
| | | detlsDtos.add(detlsDto); |
| | | }); |
| | | |