liyong
4 天以前 1125327095d325c9b248b3b72be7bc167e0b31d0
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
package com.ruoyi.production.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.basic.mapper.ProductModelMapper;
import com.ruoyi.production.controller.ProductWorkOrderController;
import com.ruoyi.production.dto.ProcessRouteItemDto;
import com.ruoyi.production.dto.ProductOrderDto;
import com.ruoyi.production.dto.ProductionProductMainDto;
import com.ruoyi.production.mapper.*;
import com.ruoyi.production.pojo.*;
import com.ruoyi.production.service.ProductionProductMainService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
 
@Service
@AllArgsConstructor
public class ProductionProductMainServiceImpl extends ServiceImpl<ProductionProductMainMapper, ProductionProductMain> implements ProductionProductMainService {
    @Autowired
    private ProductionProductMainMapper productionProductMainMapper;
    @Autowired
    private ProductWorkOrderController productWorkOrderController;
    @Autowired
    private ProductWorkOrderMapper productWorkOrderMapper;
    @Autowired
    private ProductProcessRouteItemMapper productProcessRouteItemMapper;
    @Autowired
    private ProductionProductOutputMapper productionProductOutputMapper;
    @Autowired
    private ProcessRouteItemMapper processRouteItemMapper;
    @Autowired
    private ProductModelMapper productModelMapper;
 
 
    @Override
    public IPage<ProductionProductMainDto> listPageProductionProductMainDto(Page page, ProductionProductMainDto productionProductMainDto) {
        return productionProductMainMapper.listPageProductionProductMainDto(page, productionProductMainDto);
    }
 
    @Override
    public Boolean addProductMain(ProductionProductMainDto productionProductMainDto) {
        ProductionProductMain productionProductMain = new ProductionProductMain();
        ProductProcessRouteItem productProcessRouteItem = productProcessRouteItemMapper.selectById(productionProductMainDto.getProductProcessRouteItemId());
        String datePrefix = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
        // 查询今日已存在的最大工单号
        QueryWrapper<ProductionProductMain> queryWrapper = new QueryWrapper<>();
        queryWrapper.likeRight("work_order_no", datePrefix)
                .orderByDesc("work_order_no")
                .last("LIMIT 1");
 
        ProductionProductMain lastWorkOrder = productionProductMainMapper.selectOne(queryWrapper);
 
        int sequenceNumber = 1; // 默认序号
        if (lastWorkOrder != null && lastWorkOrder.getProductNo() != null) {
            String lastNo = lastWorkOrder.getProductNo().toString();
            if (lastNo.startsWith(datePrefix)) {
                String seqStr = lastNo.substring(datePrefix.length());
                try {
                    sequenceNumber = Integer.parseInt(seqStr) + 1;
                } catch (NumberFormatException e) {
                    sequenceNumber = 1;
                }
            }
        }
        String workOrderNoStr = String.format("%s%03d", datePrefix, sequenceNumber);
        productionProductMain.setProductNo(workOrderNoStr);
        productionProductMain.setUserId(productionProductMainDto.getUserId());
        productionProductMain.setProductProcessRouteItemId(productionProductMainDto.getProductProcessRouteItemId());
        productionProductMain.setStatus(0);
        //添加报工主表
        productionProductMainMapper.insert(productionProductMain);
        ProductionProductOutput productionProductOutput = new ProductionProductOutput();
        productionProductOutput.setProductMainId(productionProductMain.getId());
        productionProductOutput.setProductModelId(productProcessRouteItem.getProductModelId());
        productionProductOutput.setQuantity(productionProductMainDto.getQuantity());
        //添加产出
        productionProductOutputMapper.insert(productionProductOutput);
        return true;
    }
}