package org.jeecg.modules.cms.service.impl;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import io.micrometer.core.annotation.Timed;
|
import lombok.extern.slf4j.Slf4j;
|
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.modules.cms.entity.CuttingReceive;
|
import org.jeecg.modules.cms.entity.CuttingReceiveDetail;
|
import org.jeecg.modules.cms.mapper.CuttingReceiveMapper;
|
import org.jeecg.modules.cms.service.ICuttingInventoryService;
|
import org.jeecg.modules.cms.service.ICuttingReceiveDetailService;
|
import org.jeecg.modules.cms.service.ICuttingReceiveService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @Description: 刀具领用单
|
* @Author: jeecg-boot
|
* @Date: 2025-07-28
|
* @Version: V1.0
|
*/
|
@Slf4j
|
@Service
|
public class CuttingReceiveServiceImpl extends ServiceImpl<CuttingReceiveMapper, CuttingReceive> implements ICuttingReceiveService {
|
@Autowired
|
private ICuttingInventoryService cuttingInventoryService;
|
@Autowired
|
private ICuttingReceiveDetailService cuttingReceiveDetailService;
|
@Override
|
public IPage<Map<String, Object>> getInventoryToolList(Integer pageNo, Integer pageSize, Map<String, Object> params) {
|
IPage<Map> pageData = new Page<Map>(pageNo, pageSize);
|
return super.getBaseMapper().getInventoryToolList(pageData,params);
|
}
|
@Override
|
@Timed(value = "cutting.receive.submit", description = "刀具领用提交耗时")
|
public synchronized Result<?> submit(String orderId) {
|
long startTime = System.currentTimeMillis();
|
try {
|
// 1. 更新领用单状态
|
CuttingReceive cuttingReceive = this.getById(orderId);
|
if (cuttingReceive == null) {
|
return Result.error("未找到对应的领用单");
|
}
|
|
// 检查领用单状态,只允许状态为"1"的领用单提交
|
if (!"1".equals(cuttingReceive.getOrderStatus())) {
|
return Result.error("只有状态为未提交的领用单才能执行提交操作");
|
}
|
|
cuttingReceive.setOrderStatus("2"); // 设置为已领用状态
|
boolean updateResult = this.updateById(cuttingReceive);
|
if (!updateResult) {
|
return Result.error("更新领用单状态失败,可能已被其他用户处理");
|
}
|
|
// 2. 获取领用明细
|
List<CuttingReceiveDetail> detailList = cuttingReceiveDetailService.lambdaQuery()
|
.eq(CuttingReceiveDetail::getOrderId, orderId)
|
.list();
|
|
// 3. 收集所有需要更新状态的库存ID
|
List<String> inventoryIds = new ArrayList<>();
|
for (CuttingReceiveDetail detail : detailList) {
|
if (detail.getInventoryId() != null && !detail.getInventoryId().isEmpty()) {
|
inventoryIds.add(detail.getInventoryId());
|
}
|
}
|
|
// 4. 批量更新库存状态为"已出库"
|
if (!inventoryIds.isEmpty()) {
|
cuttingInventoryService.updateStatus(inventoryIds, "已出库");
|
}
|
|
long endTime = System.currentTimeMillis();
|
log.info("刀具领用提交完成,耗时: {} ms", (endTime - startTime));
|
return Result.ok("提交成功");
|
|
} catch (Exception e) {
|
long endTime = System.currentTimeMillis();
|
log.error("提交领用单失败,orderId: " + orderId + ",耗时: " + (endTime - startTime) + " ms", e);
|
return Result.error("提交失败: " + e.getMessage());
|
}
|
}
|
}
|