中扬CRM客户关系管理系统
#
luxiaotao1123
2023-07-31 1fca851e22aa4dbac3ac3d4b20e68bbda3f9b94c
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
package com.zy.crm.common.web;
 
import com.core.common.Cools;
import com.core.common.R;
import com.zy.crm.common.service.DbSqlServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
 
/**
 * Created by vincent on 2023/7/25
 */
@RestController
@SuppressWarnings("all")
public class DatavController {
 
    private String 生产订单;
    private String 销售订单;
 
    {
        try {
            this.生产订单 = read(new ClassPathResource("datav/sql/生产订单.sql").getInputStream());
            this.销售订单 = read(new ClassPathResource("datav/sql/销售订单.sql").getInputStream());
        } catch (IOException ignore) {}
    }
 
    @Autowired
    private DbSqlServer dbSqlServer;
 
    @GetMapping("/data1")
    public R data1() {
        List<Map<String, Object>> res = dbSqlServer.select(this.生产订单);
        if (Cools.isEmpty(res)) {
            return R.ok();
        }
        int limit = 30;
        if (res.size() > limit) {
            res = res.subList(0, limit);
        }
        return R.ok().add(res);
    }
 
    @GetMapping("/data3")
    public R data3() {
        List<Map<String, Object>> res = dbSqlServer.select(this.销售订单);
        if (Cools.isEmpty(res)) {
            return R.ok();
        }
        return R.ok().add(res);
    }
 
    private static String read(InputStream inputStream) {
        StringBuilder stringBuilder = new StringBuilder();
        byte[] buffer = new byte[1024];
        try {
            int bytesRead;
            while ((bytesRead = inputStream.read(buffer)) != -1) {
                stringBuilder.append(new String(buffer, 0, bytesRead));
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                inputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return stringBuilder.toString();
    }
 
}