| | |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import org.jeecg.modules.cms.entity.CuttingScrap; |
| | | import io.micrometer.core.annotation.Timed; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.modules.cms.entity.*; |
| | | import org.jeecg.modules.cms.mapper.CuttingScrapMapper; |
| | | import org.jeecg.modules.cms.service.ICuttingInventoryService; |
| | | import org.jeecg.modules.cms.service.ICuttingScrapDetailService; |
| | | import org.jeecg.modules.cms.service.ICuttingScrapService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | * @Date: 2025-07-28 |
| | | * @Version: V1.0 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class CuttingScrapServiceImpl extends ServiceImpl<CuttingScrapMapper, CuttingScrap> implements ICuttingScrapService { |
| | | |
| | | @Autowired |
| | | private ICuttingScrapDetailService cuttingScarpDetailService; |
| | | @Autowired |
| | | private ICuttingInventoryService cuttingInventoryService; |
| | | |
| | | @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.scrap.submit", description = "刀具领用提交耗时") |
| | | public synchronized Result<?> submit(String orderId) { |
| | | long startTime = System.currentTimeMillis(); |
| | | try { |
| | | // 1. 更新领用单状态 |
| | | CuttingScrap cuttingScrap = this.getById(orderId); |
| | | if (cuttingScrap == null) { |
| | | return Result.error("未找到对应的领用单"); |
| | | } |
| | | |
| | | // 检查领用单状态,只允许状态为"1"的领用单提交 |
| | | if (!"1".equals(cuttingScrap.getOrderStatus())) { |
| | | return Result.error("只有状态为未提交的领用单才能执行提交操作"); |
| | | } |
| | | |
| | | cuttingScrap.setOrderStatus("2"); // 报废申请单变为 已提交 状态 |
| | | boolean updateResult = this.updateById(cuttingScrap); |
| | | if (!updateResult) { |
| | | return Result.error("更新领用单状态失败,可能已被其他用户处理"); |
| | | } |
| | | |
| | | // 2. 获取领用明细 |
| | | List<CuttingScrapDetail> detailList = cuttingScarpDetailService.lambdaQuery() |
| | | .eq(CuttingScrapDetail::getOrderId, orderId) |
| | | .list(); |
| | | |
| | | // 3. 收集所有需要更新状态的库存ID |
| | | List<String> inventoryIds = new ArrayList<>(); |
| | | for (CuttingScrapDetail 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()); |
| | | } |
| | | } |
| | | |
| | | } |