liriming
2024-09-26 2070c06b8cc7b370c3a149669017f4f183f0f172
提交 | 用户 | 时间
a6de49 1 package com.iailab.module.data.point.service.impl;
H 2
3 import com.alibaba.fastjson.JSONArray;
cfbd83 4 import com.baomidou.dynamic.datasource.annotation.DSTransactional;
a6de49 5 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
250190 6 import com.baomidou.mybatisplus.core.metadata.IPage;
6bf63b 7 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
L 8 import com.iailab.framework.common.pojo.PageResult;
9 import com.iailab.framework.common.util.object.ConvertUtils;
a6de49 10 import com.iailab.module.data.common.enums.CommonConstant;
H 11 import com.iailab.module.data.common.enums.IsEnableEnum;
12 import com.iailab.module.data.point.common.IncreaseCodeEnum;
13 import com.iailab.module.data.point.common.PointTypeEnum;
6bf63b 14 import com.iailab.module.data.point.dao.DaPointDao;
a6de49 15 import com.iailab.module.data.point.dto.DaMeasurePointDTO;
H 16 import com.iailab.module.data.point.dto.DaPointDTO;
17 import com.iailab.module.data.point.entity.DaPointEntity;
18 import com.iailab.module.data.point.service.DaMathPointService;
6bf63b 19 import com.iailab.module.data.point.service.DaMeasurePointService;
a6de49 20 import com.iailab.module.data.point.service.DaPointService;
H 21 import com.iailab.module.data.point.service.DaSequenceNumService;
6bf63b 22 import com.iailab.module.data.point.vo.DaPointPageReqVO;
48c57b 23 import org.apache.commons.lang3.ObjectUtils;
a6de49 24 import org.springframework.stereotype.Service;
H 25 import org.springframework.util.CollectionUtils;
26
6bf63b 27 import javax.annotation.Resource;
a6de49 28 import java.util.*;
H 29
30 /**
6bf63b 31  * @author lirm
a6de49 32  * @Description
6bf63b 33  * @createTime 2024年09月2日
a6de49 34  */
H 35 @Service
6bf63b 36 public class DaPointServiceImpl extends ServiceImpl<DaPointDao, DaPointEntity> implements DaPointService {
a6de49 37
H 38     @Resource
39     private DaMeasurePointService daMeasurePointService;
40
41     @Resource
42     private DaMathPointService daMathPointService;
43
44     @Resource
45     private DaSequenceNumService daSequenceNumService;
6bf63b 46     
L 47     @Resource
48     private DaPointDao daPointDao;
49
a6de49 50
H 51     @Override
250190 52     public PageResult<DaPointDTO> queryPage(DaPointPageReqVO reqVO) {
53         IPage<DaPointDTO> page = daPointDao.selectPage(reqVO);
54         return new PageResult<DaPointDTO>(page.getRecords(), page.getTotal());
a6de49 55     }
H 56
57     @Override
6bf63b 58     public DaPointDTO info(String id) {
L 59         DaPointEntity entity = daPointDao.selectById(id);
a6de49 60         DaPointDTO result = ConvertUtils.sourceToTarget(entity, DaPointDTO.class);
H 61         if (PointTypeEnum.MEASURE_POINT.getCode().equals(result.getPointType())) {
62             DaMeasurePointDTO measurePoint = daMeasurePointService.getByPoint(id);
63             result.setMeasurePoint(measurePoint);
64             List<String> sourceOption = new ArrayList<>();
65             sourceOption.add(measurePoint.getSourceType());
66             sourceOption.add(measurePoint.getSourceId());
67             sourceOption.add(measurePoint.getTagNo());
68             result.setSourceOption(sourceOption);
69         } else if (PointTypeEnum.CALCULATE_POINT.getCode().equals(result.getPointType())) {
70             result.setMathPoint(daMathPointService.getByPoint(id));
71         }
72         return result;
73     }
74
75     @Override
76     public List<DaPointDTO> list(Map<String, Object> params) {
48c57b 77         Object page = params.get("page");
L 78         Object limit =  params.get("limit");
79         Object pointType = params.get("pointType");
a6de49 80         List<String> pointNos = new ArrayList<>();
H 81         if (params.get("pointNos") != null) {
82             pointNos = JSONArray.parseArray(JSONArray.toJSONString(params.get("pointNos")), String.class);
83         }
48c57b 84         Object pointNoLike = params.get("pointNoLike");
a6de49 85         QueryWrapper<DaPointEntity> queryWrapper = new QueryWrapper();
48c57b 86         queryWrapper.eq(!ObjectUtils.isEmpty(pointType), "point_type", pointType);
L 87         queryWrapper.in(pointNos.size() != 0,"point_no", pointNos);
88         queryWrapper.like(!ObjectUtils.isEmpty(pointNoLike), "point_no", pointNoLike);
6bf63b 89         List<DaPointEntity> list = daPointDao.selectList(queryWrapper);
a6de49 90         return ConvertUtils.sourceToTarget(list, DaPointDTO.class);
H 91     }
92
93     @Override
cfbd83 94     @DSTransactional(rollbackFor = Exception.class)
a6de49 95     public void add(DaPointDTO dataPoint) {
H 96         DaPointEntity daPointEntity = ConvertUtils.sourceToTarget(dataPoint, DaPointEntity.class);
97         daPointEntity.setId(UUID.randomUUID().toString());
98         if (PointTypeEnum.MEASURE_POINT.getName().equals(dataPoint.getPointType())) {
99             DaMeasurePointDTO measurePoint = new DaMeasurePointDTO();
100             measurePoint.setSourceType(dataPoint.getSourceOption().get(0));
101             measurePoint.setSourceId(dataPoint.getSourceOption().get(1));
102             measurePoint.setTagNo(dataPoint.getSourceOption().get(2));
103             daMeasurePointService.add(measurePoint, daPointEntity.getId());
104             daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_M.name()));
105         } else if (PointTypeEnum.CALCULATE_POINT.getName().equals(dataPoint.getPointType())) {
106             daMathPointService.add(dataPoint.getMathPoint(), daPointEntity.getId());
107             daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_C.name()));
108         } else if (PointTypeEnum.CONSTANT.getName().equals(dataPoint.getPointType())) {
109             daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_F.name()));
110         }
111         daPointEntity.setIsEnable(CommonConstant.IS_ENABLE);
112         daPointEntity.setCreateTime(new Date());
6bf63b 113         daPointDao.insert(daPointEntity);
a6de49 114     }
H 115
116     @Override
cfbd83 117     @DSTransactional(rollbackFor = Exception.class)
a6de49 118     public void update(DaPointDTO dataPoint) {
H 119         DaPointEntity daPointEntity = ConvertUtils.sourceToTarget(dataPoint, DaPointEntity.class);
120         daPointEntity.setUpdateTime(new Date());
6bf63b 121         daPointDao.updateById(daPointEntity);
a6de49 122         if (PointTypeEnum.MEASURE_POINT.getName().equals(dataPoint.getPointType())) {
H 123             DaMeasurePointDTO measurePoint = dataPoint.getMeasurePoint();
124             measurePoint.setSourceType(dataPoint.getSourceOption().get(0));
125             measurePoint.setSourceId(dataPoint.getSourceOption().get(1));
126             measurePoint.setTagNo(dataPoint.getSourceOption().get(2));
127             daMeasurePointService.update(measurePoint);
2070c0 128         } else if (PointTypeEnum.CALCULATE_POINT.getName().equals(dataPoint.getPointType())) {
a6de49 129             daMathPointService.update(dataPoint.getMathPoint());
H 130         }
131     }
132
133     @Override
cfbd83 134     @DSTransactional(rollbackFor = Exception.class)
2070c0 135     public void delete(String[] id) {
L 136         daPointDao.deleteBatchIds(Arrays.asList(id));
137         daMeasurePointService.deleteByPoint(id);
138         daMathPointService.deleteByPoint(id);
a6de49 139     }
H 140
141     @Override
142     public List<DaPointDTO> getConstantPoint(String freq) {
143         Map<String, Object> params = new HashMap<>();
144         params.put("pointType", PointTypeEnum.CONSTANT.getCode());
145         params.put("isEnable", CommonConstant.IS_ENABLE);
146         params.put("minfreqid", freq);
6bf63b 147         return daPointDao.getConstantPoint(params);
a6de49 148     }
H 149
150     @Override
151     public List<DaPointDTO> getConstantPoint(List<String> pointNos) {
152         Map<String, Object> params = new HashMap<>();
153         params.put("pointType", PointTypeEnum.CONSTANT.getCode());
154         params.put("isEnable", CommonConstant.IS_ENABLE);
155         params.put("pointNos", pointNos);
6bf63b 156         return daPointDao.getConstantPoint(params);
a6de49 157     }
H 158
159     @Override
160     public List<DaPointDTO> getMeasurePoint(String freq) {
161         Map<String, Object> params = new HashMap<>();
162         params.put("pointType", PointTypeEnum.MEASURE_POINT.getCode());
163         params.put("isEnable", CommonConstant.IS_ENABLE);
164         params.put("minfreqid", freq);
6bf63b 165         return daPointDao.getMeasurePoint(params);
a6de49 166     }
H 167
168     @Override
169     public List<DaPointDTO> getMeasurePoint(List<String> pointNos) {
170         Map<String, Object> params = new HashMap<>();
171         params.put("pointType", PointTypeEnum.MEASURE_POINT.getCode());
172         params.put("isEnable", CommonConstant.IS_ENABLE);
173         params.put("pointNos", pointNos);
6bf63b 174         return daPointDao.getMeasurePoint(params);
a6de49 175     }
H 176
177     @Override
178     public DaPointDTO getMeasurePointByNo(String pointNo) {
179         Map<String, Object> params = new HashMap<>();
180         params.put("pointType", PointTypeEnum.MEASURE_POINT.getCode());
181         params.put("pointNo", pointNo);
6bf63b 182         List<DaPointDTO> list = daPointDao.getMeasurePoint(params);
a6de49 183         if (CollectionUtils.isEmpty(list)) {
H 184             return null;
185         }
186         return list.get(0);
187     }
188
189     @Override
190     public List<DaPointDTO> getMathPoint(String freq) {
191         Map<String, Object> params = new HashMap<>();
192         params.put("pointType", PointTypeEnum.CALCULATE_POINT.getCode());
193         params.put("isEnable", CommonConstant.IS_ENABLE);
194         params.put("minfreqid", freq);
6bf63b 195         return daPointDao.getMathPoint(params);
a6de49 196     }
H 197
198     @Override
199     public List<DaPointDTO> getMathPoint(List<String> pointNos) {
200         Map<String, Object> params = new HashMap<>();
201         params.put("pointType", PointTypeEnum.CALCULATE_POINT.getCode());
202         params.put("isEnable", CommonConstant.IS_ENABLE);
203         params.put("pointNos", pointNos);
6bf63b 204         return daPointDao.getMathPoint(params);
a6de49 205     }
H 206
207     @Override
208     public DaPointDTO getByNo(String pointNo) {
209         QueryWrapper<DaPointEntity> wrapper = new QueryWrapper<>();
210         wrapper.eq("point_no", pointNo);
6bf63b 211         DaPointEntity entity = daPointDao.selectOne(wrapper);
a6de49 212         return ConvertUtils.sourceToTarget(entity, DaPointDTO.class);
H 213     }
214
215     @Override
216     public List<DaPointDTO> getByNos(List<String> pointNos) {
217         QueryWrapper<DaPointEntity> wrapper = new QueryWrapper<>();
218         wrapper.in("point_no", pointNos);
6bf63b 219         List<DaPointEntity> list = daPointDao.selectList(wrapper);
a6de49 220         return ConvertUtils.sourceToTarget(list, DaPointDTO.class);
H 221     }
222
223     @Override
224     public void updateDefaultValue(DaPointDTO dto) {
225         QueryWrapper<DaPointEntity> wrapper = new QueryWrapper<>();
226         wrapper.eq("point_no", dto.getPointNo());
227         DaPointEntity entity = new DaPointEntity();
228         entity.setDefaultValue(dto.getDefaultValue());
6bf63b 229         daPointDao.update(entity, wrapper);
a6de49 230     }
H 231
232     @Override
233     public void enableByIds(String[] ids) {
234         if (CollectionUtils.isEmpty(Arrays.asList(ids))) {
235             return;
236         }
237         Arrays.asList(ids).forEach(item -> {
238             DaPointEntity entity = new DaPointEntity();
239             entity.setId(item);
240             entity.setIsEnable(IsEnableEnum.ENABLE.value());
6bf63b 241             daPointDao.updateById(entity);
a6de49 242         });
H 243     }
244
245     @Override
246     public void disableByIds(String[] ids) {
247         if (CollectionUtils.isEmpty(Arrays.asList(ids))) {
248             return;
249         }
250         Arrays.asList(ids).forEach(item -> {
251             DaPointEntity entity = new DaPointEntity();
252             entity.setId(item);
253             entity.setIsEnable(IsEnableEnum.DISABLE.value());
6bf63b 254             daPointDao.updateById(entity);
a6de49 255         });
H 256     }
257 }