From 388bd216d4eb70b367ada95118d1087b45f07ae3 Mon Sep 17 00:00:00 2001 From: liding <756868258@qq.com> Date: 星期一, 09 六月 2025 17:53:48 +0800 Subject: [PATCH] 1.煤质部分 2.代入库部分 --- main-business/src/main/java/com/ruoyi/business/service/impl/PurchaseRegistrationServiceImpl.java | 83 ++++++++++++++++++++++++++++++++++++++++- 1 files changed, 81 insertions(+), 2 deletions(-) diff --git a/main-business/src/main/java/com/ruoyi/business/service/impl/PurchaseRegistrationServiceImpl.java b/main-business/src/main/java/com/ruoyi/business/service/impl/PurchaseRegistrationServiceImpl.java index d8b297a..54b2b7b 100644 --- a/main-business/src/main/java/com/ruoyi/business/service/impl/PurchaseRegistrationServiceImpl.java +++ b/main-business/src/main/java/com/ruoyi/business/service/impl/PurchaseRegistrationServiceImpl.java @@ -1,11 +1,23 @@ package com.ruoyi.business.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ruoyi.business.dto.PurchaseRegistrationDto; +import com.ruoyi.business.entity.PendingInventory; import com.ruoyi.business.entity.PurchaseRegistration; +import com.ruoyi.business.mapper.PendingInventoryMapper; import com.ruoyi.business.mapper.PurchaseRegistrationMapper; import com.ruoyi.business.service.PurchaseRegistrationService; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import org.springframework.stereotype.Service; +import com.ruoyi.common.utils.bean.BeanUtils; import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.Assert; + +import java.util.Objects; /** * <p> @@ -19,4 +31,71 @@ @RequiredArgsConstructor public class PurchaseRegistrationServiceImpl extends ServiceImpl<PurchaseRegistrationMapper, PurchaseRegistration> implements PurchaseRegistrationService { + + private final PurchaseRegistrationMapper purchaseRegistrationMapper; + + private final PendingInventoryMapper pendingInventoryMapper; + + @Override + public IPage<PurchaseRegistration> selectPurchaseRegistrationList(Page page, PurchaseRegistrationDto purchaseRegistrationDto) { + LambdaQueryWrapper<PurchaseRegistration> queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.orderByDesc(PurchaseRegistration::getCreateTime); + return purchaseRegistrationMapper.selectPage(page, queryWrapper); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public int addOrEditPR(PurchaseRegistrationDto purchaseRegistrationDto) { + // 鍙傛暟鏍¢獙 + Assert.notNull(purchaseRegistrationDto, "閲囪喘鐧昏淇℃伅涓嶈兘涓虹┖"); + + // 鍒涘缓閲囪喘鐧昏瀹炰綋骞跺鍒跺睘鎬� + PurchaseRegistration purchaseRegistration = new PurchaseRegistration(); + BeanUtils.copyProperties(purchaseRegistrationDto, purchaseRegistration); + + if (Objects.isNull(purchaseRegistrationDto.getId())) { + // 鏂板閲囪喘鐧昏 + int insertCount = purchaseRegistrationMapper.insert(purchaseRegistration); + if (insertCount > 0) { + // 閲囪喘鐧昏鎴愬姛锛屽悓姝ュ垱寤哄緟鍏ュ簱璁板綍 + PendingInventory pendingInventory = createPendingInventory(purchaseRegistration); + return pendingInventoryMapper.insert(pendingInventory); + } + return insertCount; + } else { + // 鏇存柊閲囪喘鐧昏 + return purchaseRegistrationMapper.updateById(purchaseRegistration); + } + } + + /** + * 鏍规嵁閲囪喘鐧昏淇℃伅鍒涘缓寰呭叆搴撹褰� + * @param purchaseRegistration 閲囪喘鐧昏瀹炰綋 + * @return 寰呭叆搴撳疄浣� + */ + private PendingInventory createPendingInventory(PurchaseRegistration purchaseRegistration) { + PendingInventory pendingInventory = new PendingInventory(); + // 澶嶅埗鍩烘湰灞炴�� + BeanUtils.copyProperties(purchaseRegistration, pendingInventory); + + // 璁剧疆寰呭叆搴撹褰曠壒鏈夌殑灞炴�э紙濡傛灉鏈夛級 + // pendingInventory.setStatus(InventoryStatus.PENDING); + // pendingInventory.setCreateTime(LocalDateTime.now()); + + return pendingInventory; + } + + @Override + public int delByIds(Long[] ids) { + // 妫�鏌ュ弬鏁� + if (ids == null || ids.length == 0) { + return 0; + } + // 鏋勯�犳洿鏂版潯浠� + UpdateWrapper<PurchaseRegistration> updateWrapper = new UpdateWrapper<>(); + updateWrapper.in("id", ids) + .set("deleted", 1); // 璁剧疆 deleted 涓� 1 琛ㄧず宸插垹闄� + // 鎵ц鎵归噺閫昏緫鍒犻櫎 + return purchaseRegistrationMapper.update(null, updateWrapper); + } } -- Gitblit v1.9.3