提交 | 用户 | 时间
|
7fd198
|
1 |
package com.iailab.module.model.mcs.pre.service.impl; |
潘 |
2 |
|
|
3 |
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
5c6007
|
4 |
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
7fd198
|
5 |
import com.iailab.module.model.mcs.pre.dao.MmPredictModelDao; |
潘 |
6 |
import com.iailab.module.model.mcs.pre.entity.MmPredictModelEntity; |
|
7 |
import com.iailab.module.model.mcs.pre.service.MmPredictModelService; |
5c6007
|
8 |
import org.springframework.beans.factory.annotation.Autowired; |
7fd198
|
9 |
import org.springframework.stereotype.Service; |
潘 |
10 |
import org.springframework.util.CollectionUtils; |
45520a
|
11 |
import org.springframework.util.ObjectUtils; |
7fd198
|
12 |
|
潘 |
13 |
import java.math.BigDecimal; |
|
14 |
import java.util.List; |
|
15 |
import java.util.Map; |
|
16 |
import java.util.UUID; |
91343d
|
17 |
import java.util.concurrent.ConcurrentHashMap; |
7fd198
|
18 |
|
潘 |
19 |
/** |
|
20 |
* @author PanZhibao |
|
21 |
* @date 2021年04月27日 11:30 |
|
22 |
*/ |
5c6007
|
23 |
@Service |
L |
24 |
public class MmPredictModelServiceImpl extends ServiceImpl<MmPredictModelDao, MmPredictModelEntity> implements MmPredictModelService { |
7fd198
|
25 |
|
5c6007
|
26 |
@Autowired |
L |
27 |
private MmPredictModelDao mmPredictModelDao; |
91343d
|
28 |
|
潘 |
29 |
private static Map<String, MmPredictModelEntity> modelEntityMap = new ConcurrentHashMap<>(); |
373ab1
|
30 |
|
潘 |
31 |
private static Map<String, MmPredictModelEntity> activeModelMap = new ConcurrentHashMap<>(); |
91343d
|
32 |
|
7fd198
|
33 |
@Override |
潘 |
34 |
public void savePredictModel(MmPredictModelEntity predictModel) { |
|
35 |
predictModel.setId(UUID.randomUUID().toString()); |
5c6007
|
36 |
mmPredictModelDao.insert(predictModel); |
91343d
|
37 |
clearCache(); |
7fd198
|
38 |
} |
潘 |
39 |
|
|
40 |
@Override |
|
41 |
public void update(MmPredictModelEntity predictModel) { |
|
42 |
this.updateById(predictModel); |
91343d
|
43 |
clearCache(); |
潘 |
44 |
} |
|
45 |
|
|
46 |
@Override |
|
47 |
public MmPredictModelEntity getInfoFromCatch(String id) { |
|
48 |
if (!modelEntityMap.containsKey(id)) { |
|
49 |
MmPredictModelEntity modelEntity = getInfo(id); |
|
50 |
if (modelEntity != null) { |
|
51 |
modelEntityMap.put(id, modelEntity); |
|
52 |
} |
|
53 |
} |
|
54 |
return modelEntityMap.get(id); |
|
55 |
} |
|
56 |
|
|
57 |
@Override |
|
58 |
public void clearCache() { |
|
59 |
modelEntityMap.clear(); |
373ab1
|
60 |
activeModelMap.clear(); |
7fd198
|
61 |
} |
潘 |
62 |
|
|
63 |
@Override |
|
64 |
public MmPredictModelEntity getInfo(String id) { |
5c6007
|
65 |
return mmPredictModelDao.selectById(id); |
7fd198
|
66 |
} |
潘 |
67 |
|
|
68 |
@Override |
|
69 |
public BigDecimal getSampleLength(String id) { |
|
70 |
BigDecimal result = BigDecimal.ZERO; |
45520a
|
71 |
MmPredictModelEntity entity = mmPredictModelDao.getSampleLength(id); |
D |
72 |
if (ObjectUtils.isEmpty(entity)) { |
7fd198
|
73 |
return result; |
潘 |
74 |
} |
45520a
|
75 |
result = entity.getPredictsamplength(); |
7fd198
|
76 |
|
潘 |
77 |
return result; |
|
78 |
} |
|
79 |
|
|
80 |
public void deleteBatch(String[] itemIds) { |
|
81 |
QueryWrapper<MmPredictModelEntity> queryWrapper = new QueryWrapper<>(); |
|
82 |
queryWrapper.in("itemid", itemIds); |
5c6007
|
83 |
mmPredictModelDao.delete(queryWrapper); |
91343d
|
84 |
clearCache(); |
7fd198
|
85 |
} |
潘 |
86 |
|
|
87 |
public MmPredictModelEntity getByItemid(String itemid) { |
|
88 |
QueryWrapper<MmPredictModelEntity> queryWrapper = new QueryWrapper<>(); |
|
89 |
queryWrapper.eq("itemid", itemid); |
5c6007
|
90 |
List<MmPredictModelEntity> list = mmPredictModelDao.selectList(queryWrapper); |
7fd198
|
91 |
if (CollectionUtils.isEmpty(list)) { |
潘 |
92 |
return new MmPredictModelEntity(); |
|
93 |
} |
|
94 |
return list.get(0); |
|
95 |
} |
|
96 |
|
|
97 |
@Override |
|
98 |
public List<MmPredictModelEntity> getNoSettingmapPredictModel(Map<String, Object> params) { |
5c6007
|
99 |
return mmPredictModelDao.getNoSettingmapPredictModel(params); |
7fd198
|
100 |
} |
潘 |
101 |
|
|
102 |
@Override |
373ab1
|
103 |
public MmPredictModelEntity getActiveModelByItemId(String itemId) { |
潘 |
104 |
if (activeModelMap.containsKey(itemId)) { |
|
105 |
return activeModelMap.get(itemId); |
|
106 |
} |
|
107 |
List<MmPredictModelEntity> list = mmPredictModelDao.getActiveModelByItemId(itemId); |
|
108 |
if (CollectionUtils.isEmpty(list)) { |
|
109 |
return null; |
|
110 |
} |
|
111 |
activeModelMap.put(itemId, list.get(0)); |
|
112 |
return activeModelMap.get(itemId); |
7fd198
|
113 |
} |
潘 |
114 |
} |