潘志宝
2024-08-20 92d87eda945d68346475e6766673a3cdccf3d41c
提交 | 用户 | 时间
a6de49 1 package com.iailab.module.mcs.service.impl;
H 2
3 import com.alibaba.fastjson.JSONArray;
4 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
5 import com.iailab.framework.common.service.impl.CrudServiceImpl;
6 import com.iailab.module.mcs.dao.StModelSettingDao;
7 import com.iailab.module.mcs.dto.StModelSettingDTO;
8 import com.iailab.module.mcs.entity.StModelSettingEntity;
9 import com.iailab.module.mcs.service.StModelSettingService;
10 import org.apache.commons.lang3.StringUtils;
11 import javax.annotation.Resource;
12 import org.springframework.stereotype.Service;
13 import org.springframework.util.CollectionUtils;
14
15 import java.util.HashMap;
16 import java.util.List;
17 import java.util.Map;
18
19 /**
20  * @author lirm 1343021927@qq.com
21  * @since 1.0.0 2023-05-10
22  */
23 @Service
24 public class StModelSettingServiceImpl extends CrudServiceImpl<StModelSettingDao, StModelSettingEntity, StModelSettingDTO>
25         implements StModelSettingService {
26
27     @Resource
28     private StModelSettingDao StModelSettingDao;
29
30     @Override
31     public List<StModelSettingDTO> getAll(Map<String, Object> params) {
32         return StModelSettingDao.getAll(params);
33     }
34
35     @Override
36     public QueryWrapper<StModelSettingEntity> getWrapper(Map<String, Object> params) {
37         String id = (String) params.get("id");
38
39         QueryWrapper<StModelSettingEntity> wrapper = new QueryWrapper<>();
40         wrapper.eq(StringUtils.isNotBlank(id), "id", id);
41
42         return wrapper;
43     }
44
45     @Override
46     public void deleteByModelId(String modelId) {
47         StModelSettingDao.deleteByModelId(modelId);
48     }
49
50     @Override
51     public Map<String, Object> getByModelId(String modelId) {
52         Map<String, Object> result = new HashMap<>();
53         List<StModelSettingEntity> list = baseDao.selectList(new QueryWrapper<StModelSettingEntity>().eq("model_id", modelId));
54         if (!CollectionUtils.isEmpty(list)) {
55             list.forEach(item -> {
56                 if ("int".equals(item.getValueType())) {
57                     int value = Integer.parseInt(item.getSettingValue());
58                     result.put(item.getSettingKey(), value);
59                 } else if ("double".equals(item.getValueType())) {
60                     double value = Double.parseDouble(item.getSettingValue());
61                     result.put(item.getSettingKey(), value);
62                 } else if ("string".equals(item.getValueType())) {
63                     String value = item.getSettingValue();
64                     result.put(item.getSettingKey(), value);
65                 } else if ("decimalArray".equals(item.getValueType())) {
66                     JSONArray valueArray = JSONArray.parseArray(item.getSettingValue());
67                     double[] value = new double[valueArray.size()];
68                     for(int i = 0; i < valueArray.size(); i ++) {
69                         value[i] = Double.parseDouble(valueArray.get(i).toString());
70                     }
71                 } else {
72                     result.put(item.getSettingKey(), item.getSettingValue());
73                 }
74             });
75         }
76         return result;
77     }
78
79 }