| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import io.micrometer.core.annotation.Timed; |
| | | import liquibase.pro.packaged.C; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.modules.cms.entity.CuttingInventory; |
| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public synchronized Result<?> handleBack(String orderId) { |
| | | //FIXME:刀具归还 目前设计的是以领用单为维度进行还库;若是需要以刀具为维度进行归还的则需要另行设计 |
| | | long startTime = System.currentTimeMillis(); |
| | | try { |
| | | // 1. 更新领用单状态为已归还 |
| | |
| | | } |
| | | } |
| | | |
| | | // 4. 批量更新库存状态为"正常" |
| | | if (!inventoryIds.isEmpty()) { |
| | | cuttingInventoryService.updateStatus(inventoryIds, "正常"); |
| | | } |
| | | // 5. 寿命扣减 |
| | | // 4. 寿命扣减 |
| | | for (CuttingReceiveDetail detail : detailList) { |
| | | if (detail.getInventoryId() != null && !detail.getInventoryId().isEmpty()) { |
| | | CuttingReceiveDetail cuttingReceiveDetail = cuttingReceiveDetailService.getById(detail.getInventoryId()); |
| | | CuttingInventory inventory = cuttingInventoryService.getById(detail.getInventoryId()); |
| | | //FIXME:ratedLife空指针 |
| | | RatedLife ratedLife = ratedLifeService.lambdaQuery() //额定寿命 |
| | | .eq(RatedLife::getCuttingId, inventory.getCuttingId()) |
| | | .eq(RatedLife::getWorkpieceMaterial, inventory.getWorkpieceMaterial()) |
| | | .one(); |
| | | |
| | | BigDecimal currentLife = inventory.getCurrentLife().divide(BigDecimal.valueOf(100),java.math.RoundingMode.HALF_UP);//当前寿命百分比 |
| | | RatedLife ratedLife = ratedLifeService.lambdaQuery() |
| | | .eq(RatedLife::getCuttingId, detail.getCuttingId()) |
| | | .eq(RatedLife::getWorkpieceMaterial, detail.getWorkpieceMaterial()) |
| | | .one();//额定寿命 |
| | | |
| | | Integer useLife = detail.getUsedLife();//使用寿命 |
| | | //计算公式: (ratedLife * currentLife - useLife) * 100 |
| | | BigDecimal newLife = ratedLife.getRatedLife() |
| | | .multiply(currentLife) |
| | | .subtract(BigDecimal.valueOf(useLife)) |
| | | .multiply(BigDecimal.valueOf(100)); |
| | | //优化:(1-使用寿命/额定寿命)*100 |
| | | BigDecimal usageRatio = BigDecimal.valueOf(useLife).divide(ratedLife.getRatedLife(), 4, RoundingMode.HALF_UP); |
| | | BigDecimal newLife = BigDecimal.valueOf(1) |
| | | .subtract(usageRatio) |
| | | .multiply(BigDecimal.valueOf(100)) |
| | | .setScale(2, RoundingMode.HALF_UP); |
| | | // 更新库存寿命 |
| | | inventory.setCurrentLife(newLife); |
| | | cuttingInventoryService.updateById(inventory); |
| | | } |
| | | } |
| | | |
| | | // 5. 批量更新库存状态为"正常" |
| | | if (!inventoryIds.isEmpty()) { |
| | | cuttingInventoryService.updateStatus(inventoryIds, "在库"); |
| | | } |
| | | |
| | | long endTime = System.currentTimeMillis(); |
| | | log.info("刀具归还处理完成,耗时: {} ms", (endTime - startTime)); |
| | | return Result.ok("归还成功"); |