|  |  |  | 
|---|
|  |  |  | import com.vincent.rsf.server.common.utils.JwtUtil; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.*; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.mapper.*; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.AsnOrderItemLogService; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.AsnOrderLogService; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.WarehouseAreasItemService; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.WarehouseAreasService; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.constant.CodeRes; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.vincent.rsf.server.system.service.UserLoginService; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.utils.SerialRuleUtils; | 
|---|
|  |  |  | import org.apache.tika.utils.StringUtils; | 
|---|
|  |  |  | import org.springframework.beans.BeanUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.context.annotation.Bean; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  | import java.math.BigDecimal; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | private PurchaseItemMapper purchaseItemMapper; | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private FieldsMapper fieldsMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AsnOrderLogService asnOrderLogService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AsnOrderItemLogService asnOrderItemLogService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private FieldsItemService fieldsItemService; | 
|---|
|  |  |  | 
|---|
|  |  |  | String asnCode = receipts.stream().findFirst().get().getAsnCode(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AsnOrder asnOrder = asnOrderMapper.selectOne(new LambdaQueryWrapper<AsnOrder>().eq(AsnOrder::getCode, asnCode)); | 
|---|
|  |  |  | if (Objects.isNull(asnOrder)) { | 
|---|
|  |  |  | throw new CoolException("数据错误:主单不存在!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | asnOrder.setQty(receiptQty); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (asnOrderMapper.updateById(asnOrder) < 1) { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | allOrders.add(item); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!warehouseAreasItemService.saveBatch(allOrders)) { | 
|---|
|  |  |  | throw new CoolException("收货失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取采购数量 | 
|---|
|  |  |  | double purQty = receipts.stream().mapToDouble(ReceiptDetlsDto::getPurQty).sum(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BigDecimal subtract = BigDecimal.valueOf(receiptQty).subtract(BigDecimal.valueOf(purQty)); | 
|---|
|  |  |  | //判断已收货数量是否小于等于采购数量 | 
|---|
|  |  |  | if (subtract.compareTo(new BigDecimal("0.0")) <= 0) { | 
|---|
|  |  |  | asnOrder.setRleStatus(Short.valueOf("1")); | 
|---|
|  |  |  | //日志表操作 | 
|---|
|  |  |  | operateOrderLogs(asnOrder); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok("操作成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @description 删除原主单及明细,加入历史档 | 
|---|
|  |  |  | * @param | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | * @time 2025/3/19 19:53 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void operateOrderLogs(AsnOrder asnOrder) { | 
|---|
|  |  |  | if (asnOrderMapper.deleteById(asnOrder.getId()) < 1) { | 
|---|
|  |  |  | throw new CoolException("原单据删除失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AsnOrderLog orderLog = new AsnOrderLog(); | 
|---|
|  |  |  | BeanUtils.copyProperties(asnOrder, orderLog); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!asnOrderLogService.save(orderLog)) { | 
|---|
|  |  |  | throw new CoolException("主单历史档添加失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<AsnOrderItemLog> logs = new ArrayList<>(); | 
|---|
|  |  |  | List<AsnOrderItem> items = asnOrderItemMapper.selectList(new LambdaQueryWrapper<AsnOrderItem>().eq(AsnOrderItem::getAsnId, asnOrder.getId())); | 
|---|
|  |  |  | items.forEach(item -> { | 
|---|
|  |  |  | AsnOrderItemLog itemLog = new AsnOrderItemLog(); | 
|---|
|  |  |  | BeanUtils.copyProperties(item, itemLog); | 
|---|
|  |  |  | logs.add(itemLog); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!asnOrderItemLogService.saveBatch(logs)) { | 
|---|
|  |  |  | throw new CoolException("通知单明细历史档保存失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (asnOrderItemMapper.delete(new LambdaQueryWrapper<AsnOrderItem>().eq(AsnOrderItem::getAsnId, asnOrder.getId())) < 1) { | 
|---|
|  |  |  | throw new CoolException("原单据明细删除失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @description 其它收货 | 
|---|
|  |  |  | * @param params | 
|---|
|  |  |  | * @return | 
|---|