新火炬后端单体项目初始化代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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());
        }
    }
}