云
2 天以前 657698fd2fb32794932474648dbaee9e284e38c8
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
package cn.iocoder.yudao.module.mes.dal.mysql.qc.oqc;
 
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.mes.controller.admin.qc.oqc.vo.MesQcOqcPageReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.qc.oqc.MesQcOqcDO;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
 
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
 
import static org.junit.jupiter.api.Assertions.*;
 
class MesQcOqcMapperTest extends BaseDbUnitTest {
    @Resource
    private MesQcOqcMapper mapper;
    private final LocalDateTime date = LocalDateTime.of(2026, 10, 12, 0, 0);
 
    @BeforeEach
    void clearOqcRows() {
        mapper.delete(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<MesQcOqcDO>());
    }
 
    private MesQcOqcDO insert(String code, Long clientId) {
        MesQcOqcDO row = new MesQcOqcDO().setCode(code).setName(code).setItemId(10L)
                .setTemplateId(20L).setClientId(clientId).setBatchCode("B001")
                .setOutDate(date).setOutQuantity(BigDecimal.TEN).setStatus(0);
        mapper.insert(row);
        return row;
    }
 
    @Test
    void emptyCustomerPersistsAndHasItsOwnDuplicateKey() {
        insert("OQC-NO-CLIENT", null);
        insert("OQC-CLIENT", 100L);
        assertEquals(1, mapper.selectListByImportKey(10L, null, "B001", date).size());
        assertEquals(1, mapper.selectListByImportKey(10L, 100L, "B001", date).size());
        assertEquals(0, mapper.selectListByImportKey(10L, 200L, "B001", date).size());
    }
 
    @Test
    void unassignedRecordsVisibleWithoutExposingUnauthorizedCustomers() {
        insert("UNASSIGNED", null);
        insert("ALLOWED", 100L);
        insert("FORBIDDEN", 200L);
        assertEquals(1L, mapper.selectPage(new MesQcOqcPageReqVO(), List.of()).getTotal());
        assertEquals(2L, mapper.selectPage(new MesQcOqcPageReqVO(), List.of(100L)).getTotal());
        assertEquals(3L, mapper.selectPage(new MesQcOqcPageReqVO(), (List<Long>) null).getTotal());
        MesQcOqcPageReqVO filtered = new MesQcOqcPageReqVO();
        filtered.setClientId(200L);
        assertEquals(0L, mapper.selectPage(filtered, List.of(100L)).getTotal());
    }
 
    @Test
    void changingInspectionStatusDoesNotClearAnExistingCustomer() {
        MesQcOqcDO row = insert("STATUS-UPDATE", 100L);
        mapper.updateById(new MesQcOqcDO().setId(row.getId()).setStatus(1));
        assertEquals(100L, mapper.selectById(row.getId()).getClientId());
    }
}