houzhongjian
2024-07-23 a6de490948278991e47952e90671ddba4555e9a2
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
package com.iailab.module.mcs.service.impl;
 
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.iailab.framework.common.service.impl.CrudServiceImpl;
import com.iailab.module.mcs.dao.StModelSettingDao;
import com.iailab.module.mcs.dto.StModelSettingDTO;
import com.iailab.module.mcs.entity.StModelSettingEntity;
import com.iailab.module.mcs.service.StModelSettingService;
import org.apache.commons.lang3.StringUtils;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * @author lirm 1343021927@qq.com
 * @since 1.0.0 2023-05-10
 */
@Service
public class StModelSettingServiceImpl extends CrudServiceImpl<StModelSettingDao, StModelSettingEntity, StModelSettingDTO>
        implements StModelSettingService {
 
    @Resource
    private StModelSettingDao StModelSettingDao;
 
    @Override
    public List<StModelSettingDTO> getAll(Map<String, Object> params) {
        return StModelSettingDao.getAll(params);
    }
 
    @Override
    public QueryWrapper<StModelSettingEntity> getWrapper(Map<String, Object> params) {
        String id = (String) params.get("id");
 
        QueryWrapper<StModelSettingEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);
 
        return wrapper;
    }
 
    @Override
    public void deleteByModelId(String modelId) {
        StModelSettingDao.deleteByModelId(modelId);
    }
 
    @Override
    public Map<String, Object> getByModelId(String modelId) {
        Map<String, Object> result = new HashMap<>();
        List<StModelSettingEntity> list = baseDao.selectList(new QueryWrapper<StModelSettingEntity>().eq("model_id", modelId));
        if (!CollectionUtils.isEmpty(list)) {
            list.forEach(item -> {
                if ("int".equals(item.getValueType())) {
                    int value = Integer.parseInt(item.getSettingValue());
                    result.put(item.getSettingKey(), value);
                } else if ("double".equals(item.getValueType())) {
                    double value = Double.parseDouble(item.getSettingValue());
                    result.put(item.getSettingKey(), value);
                } else if ("string".equals(item.getValueType())) {
                    String value = item.getSettingValue();
                    result.put(item.getSettingKey(), value);
                } else if ("decimalArray".equals(item.getValueType())) {
                    JSONArray valueArray = JSONArray.parseArray(item.getSettingValue());
                    double[] value = new double[valueArray.size()];
                    for(int i = 0; i < valueArray.size(); i ++) {
                        value[i] = Double.parseDouble(valueArray.get(i).toString());
                    }
                } else {
                    result.put(item.getSettingKey(), item.getSettingValue());
                }
            });
        }
        return result;
    }
 
}