提交 | 用户 | 时间
|
a6de49
|
1 |
package com.iailab.module.data.ind.service.impl; |
H |
2 |
|
|
3 |
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
4 |
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
5 |
import com.iailab.framework.common.constant.Constant; |
|
6 |
import com.iailab.module.data.common.enums.CommonConstant; |
|
7 |
import com.iailab.module.data.common.enums.IsEnableEnum; |
|
8 |
import com.iailab.framework.common.page.PageData; |
|
9 |
import com.iailab.framework.common.service.impl.BaseServiceImpl; |
|
10 |
import com.iailab.framework.common.util.object.ConvertUtils; |
|
11 |
import com.iailab.module.data.ind.dto.IndItemAtomDTO; |
|
12 |
import com.iailab.module.data.ind.service.IndItemCalService; |
|
13 |
import com.iailab.module.data.ind.service.IndItemService; |
|
14 |
import com.iailab.module.data.ind.common.IndItemTypeEnum; |
|
15 |
import com.iailab.module.data.ind.dao.IndItemDao; |
|
16 |
import com.iailab.module.data.ind.dto.IndItemCalDTO; |
|
17 |
import com.iailab.module.data.ind.dto.IndItemDTO; |
|
18 |
import com.iailab.module.data.ind.entity.IndItemEntity; |
|
19 |
import com.iailab.module.data.ind.service.IndItemAtomService; |
|
20 |
import org.apache.commons.lang3.StringUtils; |
|
21 |
import javax.annotation.Resource; |
|
22 |
import org.springframework.stereotype.Service; |
|
23 |
import org.springframework.transaction.annotation.Transactional; |
|
24 |
import org.springframework.util.CollectionUtils; |
|
25 |
|
|
26 |
import java.util.*; |
|
27 |
|
|
28 |
/** |
|
29 |
* @author PanZhibao |
|
30 |
* @Description |
|
31 |
* @createTime 2024年05月25日 |
|
32 |
*/ |
|
33 |
@Service |
|
34 |
public class IndItemServiceImpl extends BaseServiceImpl<IndItemDao, IndItemEntity> implements IndItemService { |
|
35 |
|
|
36 |
@Resource |
|
37 |
private IndItemAtomService indItemAtomService; |
|
38 |
|
|
39 |
@Resource |
|
40 |
private IndItemCalService indItemCalService; |
|
41 |
|
|
42 |
@Override |
|
43 |
public PageData<IndItemDTO> page(Map<String, Object> params) { |
|
44 |
IPage<IndItemEntity> page = baseDao.selectPage( |
|
45 |
getPage(params, Constant.CREATE_TIME, false), |
|
46 |
getWrapper(params) |
|
47 |
); |
|
48 |
return getPageData(page, IndItemDTO.class); |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public List<IndItemDTO> getList(Map<String, Object> params) { |
|
53 |
List<IndItemEntity> list = baseDao.selectList(getWrapper(params)); |
|
54 |
return ConvertUtils.sourceToTarget(list, IndItemDTO.class); |
|
55 |
} |
|
56 |
|
|
57 |
@Override |
|
58 |
public void enableByIds(String[] ids) { |
|
59 |
if (CollectionUtils.isEmpty(Arrays.asList(ids))) { |
|
60 |
return; |
|
61 |
} |
|
62 |
Arrays.asList(ids).forEach(item -> { |
|
63 |
IndItemEntity entity = new IndItemEntity(); |
|
64 |
entity.setId(item); |
|
65 |
entity.setIsEnable(IsEnableEnum.ENABLE.value()); |
|
66 |
baseDao.updateById(entity); |
|
67 |
}); |
|
68 |
} |
|
69 |
|
|
70 |
@Override |
|
71 |
public void disableByIds(String[] ids) { |
|
72 |
if (CollectionUtils.isEmpty(Arrays.asList(ids))) { |
|
73 |
return; |
|
74 |
} |
|
75 |
Arrays.asList(ids).forEach(item -> { |
|
76 |
IndItemEntity entity = new IndItemEntity(); |
|
77 |
entity.setId(item); |
|
78 |
entity.setIsEnable(IsEnableEnum.DISABLE.value()); |
|
79 |
baseDao.updateById(entity); |
|
80 |
}); |
|
81 |
} |
|
82 |
|
|
83 |
@Override |
|
84 |
public IndItemDTO getItemByItemNo(String itemNo) { |
|
85 |
QueryWrapper<IndItemEntity> wrapper = new QueryWrapper<>(); |
|
86 |
wrapper.eq("item_no", itemNo); |
|
87 |
return ConvertUtils.sourceToTarget(baseDao.selectOne(wrapper),IndItemDTO.class); |
|
88 |
} |
|
89 |
|
|
90 |
private QueryWrapper<IndItemEntity> getWrapper(Map<String, Object> params){ |
|
91 |
String itemNo = (String)params.get("itemNo"); |
|
92 |
|
|
93 |
QueryWrapper<IndItemEntity> wrapper = new QueryWrapper<>(); |
|
94 |
wrapper.like(StringUtils.isNotBlank(itemNo), "item_no", itemNo); |
|
95 |
|
|
96 |
return wrapper; |
|
97 |
} |
|
98 |
|
|
99 |
@Override |
|
100 |
public IndItemDTO get(String id) { |
|
101 |
IndItemEntity entity = baseDao.selectById(id); |
|
102 |
if (entity == null) { |
|
103 |
return null; |
|
104 |
} |
|
105 |
IndItemDTO result = ConvertUtils.sourceToTarget(entity, IndItemDTO.class); |
|
106 |
if (IndItemTypeEnum.ATOM_ITEM.getCode().equals(result.getItemType())) { |
|
107 |
IndItemAtomDTO dto = indItemAtomService.getItemId(id); |
|
108 |
result.setIndItemAtom(dto); |
|
109 |
} else if (IndItemTypeEnum.CAL_ITEM.getCode().equals(result.getItemType())) { |
|
110 |
IndItemCalDTO dto = indItemCalService.getItemId(id); |
|
111 |
result.setIndItemCal(dto); |
|
112 |
} |
|
113 |
return result; |
|
114 |
} |
|
115 |
|
|
116 |
@Override |
|
117 |
public void save(IndItemDTO dto) { |
|
118 |
IndItemEntity entity = ConvertUtils.sourceToTarget(dto, IndItemEntity.class); |
|
119 |
entity.setId(UUID.randomUUID().toString()); |
|
120 |
if (IndItemTypeEnum.ATOM_ITEM.getName().equals(entity.getItemType())) { |
|
121 |
IndItemAtomDTO indItemAtomDTO = new IndItemAtomDTO(); |
|
122 |
indItemAtomDTO.setId(UUID.randomUUID().toString()); |
|
123 |
indItemAtomDTO.setItemId(entity.getId()); |
|
124 |
indItemAtomDTO.setDataSource(dto.getDataSource()); |
|
125 |
indItemAtomDTO.setQuerySql(dto.getQuerySql()); |
|
126 |
indItemAtomService.save(indItemAtomDTO); |
|
127 |
}else if (IndItemTypeEnum.CAL_ITEM.getName().equals(entity.getItemType())){ |
|
128 |
IndItemCalDTO indItemCalDTO = new IndItemCalDTO(); |
|
129 |
indItemCalDTO.setId(UUID.randomUUID().toString()); |
|
130 |
indItemCalDTO.setItemId(entity.getId()); |
|
131 |
indItemCalDTO.setExpression(dto.getExpression()); |
|
132 |
indItemCalService.save(indItemCalDTO); |
|
133 |
} |
|
134 |
entity.setIsEnable(CommonConstant.IS_ENABLE); |
|
135 |
entity.setCreateTime(new Date()); |
|
136 |
insert(entity); |
|
137 |
} |
|
138 |
|
|
139 |
@Override |
|
140 |
public void update(IndItemDTO dto) { |
|
141 |
IndItemEntity entity = ConvertUtils.sourceToTarget(dto, IndItemEntity.class); |
|
142 |
entity.setUpdateTime(new Date()); |
|
143 |
updateById(entity); |
|
144 |
System.out.println(IndItemTypeEnum.ATOM_ITEM.getName()+IndItemTypeEnum.CAL_ITEM.getName()); |
|
145 |
if (IndItemTypeEnum.ATOM_ITEM.getName().equals(entity.getItemType())) { |
|
146 |
dto.getIndItemAtom().setDataSource(dto.getDataSource()); |
|
147 |
dto.getIndItemAtom().setQuerySql(dto.getQuerySql()); |
|
148 |
indItemAtomService.update(dto.getIndItemAtom()); |
|
149 |
}else if (IndItemTypeEnum.CAL_ITEM.getName().equals(entity.getItemType())){ |
|
150 |
dto.getIndItemCal().setExpression(dto.getExpression()); |
|
151 |
indItemCalService.update(dto.getIndItemCal()); |
|
152 |
} |
|
153 |
} |
|
154 |
|
|
155 |
@Override |
|
156 |
@Transactional(rollbackFor = Exception.class) |
|
157 |
public void delete(String[] ids) { |
|
158 |
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|
159 |
indItemAtomService.deleteByItemId(ids); |
|
160 |
indItemCalService.deleteByItemId(ids); |
|
161 |
} |
|
162 |
|
|
163 |
@Override |
|
164 |
public List<IndItemDTO> getItemAtom(List<String> itemNos) { |
|
165 |
Map<String, Object> params = new HashMap<>(); |
|
166 |
params.put("itemType", IndItemTypeEnum.ATOM_ITEM.getCode()); |
|
167 |
params.put("isEnable", CommonConstant.IS_ENABLE); |
|
168 |
params.put("itemNos", itemNos); |
|
169 |
return baseDao.getItemAtom(params); |
|
170 |
} |
|
171 |
|
|
172 |
@Override |
|
173 |
public IndItemDTO getItemAtom(String itemNo) { |
|
174 |
IndItemDTO result = null; |
|
175 |
Map<String, Object> params = new HashMap<>(); |
|
176 |
params.put("itemType", IndItemTypeEnum.ATOM_ITEM.getCode()); |
|
177 |
params.put("isEnable", CommonConstant.IS_ENABLE); |
|
178 |
params.put("itemNo", itemNo); |
|
179 |
List<IndItemDTO> list = baseDao.getItemAtom(params); |
|
180 |
if (!CollectionUtils.isEmpty(list)) { |
|
181 |
result = list.get(0); |
|
182 |
} |
|
183 |
return result; |
|
184 |
} |
|
185 |
|
|
186 |
@Override |
|
187 |
public List<IndItemDTO> getItemCal(List<String> itemNos) { |
|
188 |
Map<String, Object> params = new HashMap<>(); |
|
189 |
params.put("itemType", IndItemTypeEnum.CAL_ITEM.getCode()); |
|
190 |
params.put("isEnable", CommonConstant.IS_ENABLE); |
|
191 |
params.put("itemNos", itemNos); |
|
192 |
return baseDao.getItemCal(params); |
|
193 |
} |
|
194 |
|
|
195 |
@Override |
|
196 |
public IndItemDTO getItemCal(String itemNo) { |
|
197 |
IndItemDTO result = null; |
|
198 |
Map<String, Object> params = new HashMap<>(); |
|
199 |
params.put("itemType", IndItemTypeEnum.CAL_ITEM.getCode()); |
|
200 |
params.put("isEnable", CommonConstant.IS_ENABLE); |
|
201 |
params.put("itemNo", itemNo); |
|
202 |
List<IndItemDTO> list = baseDao.getItemCal(params); |
|
203 |
if (!CollectionUtils.isEmpty(list)) { |
|
204 |
result = list.get(0); |
|
205 |
} |
|
206 |
return result; |
|
207 |
} |
|
208 |
} |