潘志宝
2024-10-09 c0b8cf32504dd1a42780bb1ee06ae8a7b0d7b120
提交 | 用户 | 时间
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
b8b8cb 76     public DaPointDTO getSimpleInfoById(String id) {
77         return ConvertUtils.sourceToTarget(daPointDao.selectById(id), DaPointDTO.class);
78     }
79
80     @Override
81     public DaPointDTO getSimpleInfoByNo(String no) {
82         QueryWrapper<DaPointEntity> queryWrapper = new QueryWrapper();
83         queryWrapper.eq("pointNo", no);
84         return ConvertUtils.sourceToTarget(daPointDao.selectOne(queryWrapper), DaPointDTO.class);
85     }
86
87     @Override
a6de49 88     public List<DaPointDTO> list(Map<String, Object> params) {
48c57b 89         Object pointType = params.get("pointType");
a6de49 90         List<String> pointNos = new ArrayList<>();
H 91         if (params.get("pointNos") != null) {
92             pointNos = JSONArray.parseArray(JSONArray.toJSONString(params.get("pointNos")), String.class);
93         }
48c57b 94         Object pointNoLike = params.get("pointNoLike");
a6de49 95         QueryWrapper<DaPointEntity> queryWrapper = new QueryWrapper();
48c57b 96         queryWrapper.eq(!ObjectUtils.isEmpty(pointType), "point_type", pointType);
L 97         queryWrapper.in(pointNos.size() != 0,"point_no", pointNos);
98         queryWrapper.like(!ObjectUtils.isEmpty(pointNoLike), "point_no", pointNoLike);
6bf63b 99         List<DaPointEntity> list = daPointDao.selectList(queryWrapper);
a6de49 100         return ConvertUtils.sourceToTarget(list, DaPointDTO.class);
H 101     }
102
103     @Override
cfbd83 104     @DSTransactional(rollbackFor = Exception.class)
a6de49 105     public void add(DaPointDTO dataPoint) {
H 106         DaPointEntity daPointEntity = ConvertUtils.sourceToTarget(dataPoint, DaPointEntity.class);
107         daPointEntity.setId(UUID.randomUUID().toString());
108         if (PointTypeEnum.MEASURE_POINT.getName().equals(dataPoint.getPointType())) {
109             DaMeasurePointDTO measurePoint = new DaMeasurePointDTO();
110             measurePoint.setSourceType(dataPoint.getSourceOption().get(0));
111             measurePoint.setSourceId(dataPoint.getSourceOption().get(1));
112             measurePoint.setTagNo(dataPoint.getSourceOption().get(2));
113             daMeasurePointService.add(measurePoint, daPointEntity.getId());
114             daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_M.name()));
115         } else if (PointTypeEnum.CALCULATE_POINT.getName().equals(dataPoint.getPointType())) {
116             daMathPointService.add(dataPoint.getMathPoint(), daPointEntity.getId());
117             daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_C.name()));
118         } else if (PointTypeEnum.CONSTANT.getName().equals(dataPoint.getPointType())) {
119             daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_F.name()));
120         }
121         daPointEntity.setIsEnable(CommonConstant.IS_ENABLE);
122         daPointEntity.setCreateTime(new Date());
6bf63b 123         daPointDao.insert(daPointEntity);
a6de49 124     }
H 125
126     @Override
cfbd83 127     @DSTransactional(rollbackFor = Exception.class)
a6de49 128     public void update(DaPointDTO dataPoint) {
H 129         DaPointEntity daPointEntity = ConvertUtils.sourceToTarget(dataPoint, DaPointEntity.class);
130         daPointEntity.setUpdateTime(new Date());
6bf63b 131         daPointDao.updateById(daPointEntity);
a6de49 132         if (PointTypeEnum.MEASURE_POINT.getName().equals(dataPoint.getPointType())) {
H 133             DaMeasurePointDTO measurePoint = dataPoint.getMeasurePoint();
134             measurePoint.setSourceType(dataPoint.getSourceOption().get(0));
135             measurePoint.setSourceId(dataPoint.getSourceOption().get(1));
136             measurePoint.setTagNo(dataPoint.getSourceOption().get(2));
137             daMeasurePointService.update(measurePoint);
2070c0 138         } else if (PointTypeEnum.CALCULATE_POINT.getName().equals(dataPoint.getPointType())) {
a6de49 139             daMathPointService.update(dataPoint.getMathPoint());
H 140         }
141     }
142
143     @Override
cfbd83 144     @DSTransactional(rollbackFor = Exception.class)
2070c0 145     public void delete(String[] id) {
L 146         daPointDao.deleteBatchIds(Arrays.asList(id));
147         daMeasurePointService.deleteByPoint(id);
148         daMathPointService.deleteByPoint(id);
a6de49 149     }
H 150
151     @Override
152     public List<DaPointDTO> getConstantPoint(String freq) {
153         Map<String, Object> params = new HashMap<>();
154         params.put("pointType", PointTypeEnum.CONSTANT.getCode());
155         params.put("isEnable", CommonConstant.IS_ENABLE);
156         params.put("minfreqid", freq);
6bf63b 157         return daPointDao.getConstantPoint(params);
a6de49 158     }
H 159
160     @Override
161     public List<DaPointDTO> getConstantPoint(List<String> pointNos) {
162         Map<String, Object> params = new HashMap<>();
163         params.put("pointType", PointTypeEnum.CONSTANT.getCode());
164         params.put("isEnable", CommonConstant.IS_ENABLE);
165         params.put("pointNos", pointNos);
6bf63b 166         return daPointDao.getConstantPoint(params);
a6de49 167     }
H 168
169     @Override
170     public List<DaPointDTO> getMeasurePoint(String freq) {
171         Map<String, Object> params = new HashMap<>();
172         params.put("pointType", PointTypeEnum.MEASURE_POINT.getCode());
173         params.put("isEnable", CommonConstant.IS_ENABLE);
174         params.put("minfreqid", freq);
6bf63b 175         return daPointDao.getMeasurePoint(params);
a6de49 176     }
H 177
178     @Override
179     public List<DaPointDTO> getMeasurePoint(List<String> pointNos) {
180         Map<String, Object> params = new HashMap<>();
181         params.put("pointType", PointTypeEnum.MEASURE_POINT.getCode());
182         params.put("isEnable", CommonConstant.IS_ENABLE);
183         params.put("pointNos", pointNos);
6bf63b 184         return daPointDao.getMeasurePoint(params);
a6de49 185     }
H 186
187     @Override
188     public DaPointDTO getMeasurePointByNo(String pointNo) {
189         Map<String, Object> params = new HashMap<>();
190         params.put("pointType", PointTypeEnum.MEASURE_POINT.getCode());
191         params.put("pointNo", pointNo);
6bf63b 192         List<DaPointDTO> list = daPointDao.getMeasurePoint(params);
a6de49 193         if (CollectionUtils.isEmpty(list)) {
H 194             return null;
195         }
196         return list.get(0);
197     }
198
199     @Override
200     public List<DaPointDTO> getMathPoint(String freq) {
201         Map<String, Object> params = new HashMap<>();
202         params.put("pointType", PointTypeEnum.CALCULATE_POINT.getCode());
203         params.put("isEnable", CommonConstant.IS_ENABLE);
204         params.put("minfreqid", freq);
6bf63b 205         return daPointDao.getMathPoint(params);
a6de49 206     }
H 207
208     @Override
209     public List<DaPointDTO> getMathPoint(List<String> pointNos) {
210         Map<String, Object> params = new HashMap<>();
211         params.put("pointType", PointTypeEnum.CALCULATE_POINT.getCode());
212         params.put("isEnable", CommonConstant.IS_ENABLE);
213         params.put("pointNos", pointNos);
6bf63b 214         return daPointDao.getMathPoint(params);
a6de49 215     }
H 216
217     @Override
218     public DaPointDTO getByNo(String pointNo) {
219         QueryWrapper<DaPointEntity> wrapper = new QueryWrapper<>();
220         wrapper.eq("point_no", pointNo);
6bf63b 221         DaPointEntity entity = daPointDao.selectOne(wrapper);
a6de49 222         return ConvertUtils.sourceToTarget(entity, DaPointDTO.class);
H 223     }
224
225     @Override
226     public List<DaPointDTO> getByNos(List<String> pointNos) {
227         QueryWrapper<DaPointEntity> wrapper = new QueryWrapper<>();
228         wrapper.in("point_no", pointNos);
6bf63b 229         List<DaPointEntity> list = daPointDao.selectList(wrapper);
a6de49 230         return ConvertUtils.sourceToTarget(list, DaPointDTO.class);
H 231     }
232
233     @Override
234     public void updateDefaultValue(DaPointDTO dto) {
235         QueryWrapper<DaPointEntity> wrapper = new QueryWrapper<>();
236         wrapper.eq("point_no", dto.getPointNo());
237         DaPointEntity entity = new DaPointEntity();
238         entity.setDefaultValue(dto.getDefaultValue());
6bf63b 239         daPointDao.update(entity, wrapper);
a6de49 240     }
H 241
242     @Override
243     public void enableByIds(String[] ids) {
244         if (CollectionUtils.isEmpty(Arrays.asList(ids))) {
245             return;
246         }
247         Arrays.asList(ids).forEach(item -> {
248             DaPointEntity entity = new DaPointEntity();
249             entity.setId(item);
250             entity.setIsEnable(IsEnableEnum.ENABLE.value());
6bf63b 251             daPointDao.updateById(entity);
a6de49 252         });
H 253     }
254
255     @Override
256     public void disableByIds(String[] ids) {
257         if (CollectionUtils.isEmpty(Arrays.asList(ids))) {
258             return;
259         }
260         Arrays.asList(ids).forEach(item -> {
261             DaPointEntity entity = new DaPointEntity();
262             entity.setId(item);
263             entity.setIsEnable(IsEnableEnum.DISABLE.value());
6bf63b 264             daPointDao.updateById(entity);
a6de49 265         });
H 266     }
267 }