z8018
8 天以前 d5317aef1dbb595923af02ede8bfa33ba37d6eb6
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
import {
    insert,
    query
} from "../common/sqlite";
 
export default {
    async saveMaterialContent(orderNo, materialName, originalContent, contents) {
        const reference = {
            reference_content_index: '',
            reference_content: ''
        }
        for (var index = 0; index < contents.length; index++) {
            var element = contents[index];
            if (index > 0) {
                reference.reference_content += '@#@'
                reference.reference_content_index += '@#@'
            }
            reference.reference_content += element.text;
 
            reference.reference_content_index += JSON.stringify(element.indexes);
        }
 
        let counts = await query("select count(*) AS count from materials_content where reference_content like '%" +
            reference.reference_content + "%' and orderNo = ?", [orderNo]);
        if (counts[0].count === 0) {
            await insert('materials_content', {
                orderNo: orderNo,
                material_name: materialName,
                reference_content_index: reference.reference_content_index,
                original_content: originalContent,
                reference_content: reference.reference_content
            })
        }
    },
 
    async getMaterialContent(orderNo, materialName) {
        try {
            const contents = await query(
                'select reference_content from materials_content where orderNo = ? and material_name = ?',
                [orderNo, materialName]);
            return contents;
        } catch (e) {
            console.error('getMaterialContent', e)
        }
    },
 
    async getAMaterialContent(orderNo, materialName) {
        try {
            const contents = await query(
                'select * from materials_content where orderNo = ? and material_name = ?',
                [orderNo, materialName]);
            return contents;
        } catch (e) {
            console.error('getAMaterialContent', e)
        }
    },
}