选煤厂生产管理平台后台代码
dongyukun
2024-12-10 3f07ab2e03e501ae55d1d1b0d031daf50c8e13e5
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package com.iailab.module.pms.coalquality.modules.analysis.service.impl;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.iailab.framework.common.service.impl.BaseServiceImpl;
import com.iailab.framework.common.util.object.ConvertUtils;
import com.iailab.framework.tenant.core.aop.TenantIgnore;
import com.iailab.module.pms.coalquality.common.enums.FcfaType;
import com.iailab.module.pms.coalquality.modules.analysis.dao.CoalWashCurvesChartDao;
import com.iailab.module.pms.coalquality.modules.analysis.dto.CoalWashCurvesChartDTO;
import com.iailab.module.pms.coalquality.modules.analysis.entity.CoalWashCurvesChartEntity;
import com.iailab.module.pms.coalquality.modules.analysis.service.CoalWashCurvesChartService;
import com.iailab.module.pms.coalquality.modules.analysis.service.CoalWashCurvesDetService;
import com.mathworks.toolbox.javabuilder.MWCellArray;
import com.mathworks.toolbox.javabuilder.MWNumericArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import washabilityCurve20230915.WashCurve;
 
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 可选性曲线图
 *
 * @author PanZhibao
 * @Description
 * @createTime 2023年01月19日 23:25:00
 */
@Service
public class CoalWashCurvesChartServiceImpl extends BaseServiceImpl<CoalWashCurvesChartDao, CoalWashCurvesChartEntity>
        implements CoalWashCurvesChartService {
 
    @Autowired
    private CoalWashCurvesDetService coalWashCurvesDetService;
 
    private final String CURVES_TYPE_FITTING = "1";
 
    @Override
    @TenantIgnore
    public CoalWashCurvesChartDTO getByCurvesId(String curvesId) {
        CoalWashCurvesChartEntity entity = baseDao.selectOne(new QueryWrapper<CoalWashCurvesChartEntity>().eq("curves_id", curvesId));
        return ConvertUtils.sourceToTarget(entity, CoalWashCurvesChartDTO.class);
    }
 
    @Override
    @TenantIgnore
    public void update(CoalWashCurvesChartDTO dto) {
        baseDao.delete(new QueryWrapper<CoalWashCurvesChartEntity>().eq("curves_id", dto.getCurvesId()));
        CoalWashCurvesChartEntity entity = ConvertUtils.sourceToTarget(dto, CoalWashCurvesChartEntity.class);
        insert(entity);
    }
 
    @Override
    public CoalWashCurvesChartDTO draw(CoalWashCurvesChartDTO dto) {
 
        String curvesType = dto.getCurvesType();
        Map<String, Object> drawParams = coalWashCurvesDetService.getDrawParams(dto.getCurvesId());
 
        try {
            double[] densitySrcData = new double[]{1.3, 1.4, 1.5, 1.6, 1.8};
            if(FcfaType.THREE.getCode().equals(dto.getFcfa())) {
                densitySrcData = new double[]{1.4, 1.8};
            }
 
            double[][] floatSrcData = (double[][]) drawParams.get("floatSrcData");
            double[][] densityScopeSrcData = (double[][]) drawParams.get("densityScopeSrcData");
            double[] coeffSrcData = {};
 
            WashCurve wc = new WashCurve();
            Object[] allResult = wc.washabilityCurve(2, densitySrcData, floatSrcData, densityScopeSrcData, Integer.parseInt(curvesType), coeffSrcData);
            MWNumericArray temp = (MWNumericArray) allResult[0];
            double[][] coefficient = (double[][]) temp.toDoubleArray();
            MWCellArray temp1 = (MWCellArray) allResult[1];
            double[][] test1 = (double[][]) temp1.get(1);
            double[] xAxis1 = test1[0];
            double[][] test2 = (double[][]) temp1.get(2);
            double[] xAxis2 = test2[0];
            double[][] test3 = (double[][]) temp1.get(3);
            //double[] floatVue = test3[0];
            double[][] test4 = (double[][]) temp1.get(4);
            double[] cellVue = test4[0];
            double[][] test5 = (double[][]) temp1.get(5);
            // double[] sinkVue = test5[0];
            double[][] test6 = (double[][]) temp1.get(6);
            double[] densityDataResult = test6[0];
            double[][] test7 = (double[][]) temp1.get(7);
            double[] densityScopeData = test7[0];
            double[][] floatPoint = (double[][]) temp1.get(8);
            double[][] densePoint = (double[][]) temp1.get(9);
            double[][] denseScopePoint = (double[][]) temp1.get(10);
 
            List<Double> xAxis1List = new ArrayList<>();
            for(int i = 0; i < xAxis1.length; i ++) {
                xAxis1List.add(new BigDecimal(xAxis1[i]).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
            }
            List<Double> xAxis2List = new ArrayList<>();
            for(int i = 0; i < xAxis2.length; i ++) {
                xAxis2List.add(new BigDecimal(xAxis2[i]).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
            }
            List<Double> floatVue = new ArrayList<>();
            for(int i = 0; i < test3[0].length; i ++) {
                floatVue.add(new BigDecimal(test3[0][i]).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
            }
            List<Double> sinkVue = new ArrayList<>();
            for(int i = 0; i < test5[0].length; i ++) {
                sinkVue.add(new BigDecimal(test5[0][i]).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
            }
            List<Double> cellVueList = new ArrayList<>();
            for(int i = 0; i < cellVue.length; i ++) {
                cellVueList.add(new BigDecimal(cellVue[i]).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
            }
            List<Double> densityDataList = new ArrayList<>();
            for(int i = 0; i < densityDataResult.length; i ++) {
                densityDataList.add(new BigDecimal(densityDataResult[i]).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
            }
            Map<Integer, Integer> emptyDs =  new HashMap<>();
            if (CURVES_TYPE_FITTING.equals(curvesType)) {
                int k = 0;
                for (int i = 0; i < (densityDataResult.length - 1); i++ ) {
                    if (densityDataResult[i] != 0) {
                        k = i - 1;
                        break;
                    }
                }
                if (k <= 0) {
                    k = 15;
                }
 
                for (int j = 0; j < k + 10; j++) {
                    emptyDs.put(j, j);
                }
            }
 
            List<Double> densityScopeList = new ArrayList<>();
            for(int i = 0; i < densityScopeData.length; i ++) {
                if (emptyDs.containsKey(i)) {
                    densityScopeList.add(null);
                    continue;
                }
                densityScopeList.add(new BigDecimal(densityScopeData[i]).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
            }
            dto.setDensitySrcData(JSONObject.toJSONString(densitySrcData));
            dto.setFloatSrcData(JSONObject.toJSONString(floatSrcData));
            dto.setDensityScopeSrcData(JSONObject.toJSONString(densityScopeSrcData));
            dto.setCoeffSrcData(JSONObject.toJSONString(coeffSrcData));
 
            dto.setXAxisData1(JSONObject.toJSONString(xAxis1List));
            dto.setXAxisData2(JSONObject.toJSONString(xAxis2List));
            dto.setFloatPointData(JSONObject.toJSONString(floatPoint));
            dto.setDensityPointData(JSONObject.toJSONString(densePoint));
            dto.setDensityScopePointData(JSONObject.toJSONString(denseScopePoint));
            dto.setCellData(JSONObject.toJSONString(cellVueList));
            dto.setDensityData(JSONObject.toJSONString(densityDataList));
            dto.setDensityScopeData(JSONObject.toJSONString(densityScopeList));
            dto.setFloatData(JSONObject.toJSONString(floatVue));
            dto.setSinkData(JSONObject.toJSONString(sinkVue));
            this.update(dto);
            return dto;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }
}