package com.iailab.module.data.point.service.impl;
|
|
import com.alibaba.fastjson.JSONArray;
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.iailab.framework.common.pojo.PageResult;
|
import com.iailab.framework.common.util.object.ConvertUtils;
|
import com.iailab.module.data.common.enums.CommonConstant;
|
import com.iailab.module.data.common.enums.IsEnableEnum;
|
import com.iailab.module.data.point.common.IncreaseCodeEnum;
|
import com.iailab.module.data.point.common.PointTypeEnum;
|
import com.iailab.module.data.point.dao.DaPointDao;
|
import com.iailab.module.data.point.dto.DaMeasurePointDTO;
|
import com.iailab.module.data.point.dto.DaPointDTO;
|
import com.iailab.module.data.point.entity.DaPointEntity;
|
import com.iailab.module.data.point.service.DaMathPointService;
|
import com.iailab.module.data.point.service.DaMeasurePointService;
|
import com.iailab.module.data.point.service.DaPointService;
|
import com.iailab.module.data.point.service.DaSequenceNumService;
|
import com.iailab.module.data.point.vo.DaPointPageReqVO;
|
import org.apache.commons.lang3.ObjectUtils;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.CollectionUtils;
|
|
import javax.annotation.Resource;
|
import java.util.*;
|
|
/**
|
* @author lirm
|
* @Description
|
* @createTime 2024年09月2日
|
*/
|
@Service
|
public class DaPointServiceImpl extends ServiceImpl<DaPointDao, DaPointEntity> implements DaPointService {
|
|
@Resource
|
private DaMeasurePointService daMeasurePointService;
|
|
@Resource
|
private DaMathPointService daMathPointService;
|
|
@Resource
|
private DaSequenceNumService daSequenceNumService;
|
|
@Resource
|
private DaPointDao daPointDao;
|
|
|
@Override
|
public PageResult<DaPointDTO> queryPage(DaPointPageReqVO reqVO) {
|
IPage<DaPointDTO> page = daPointDao.selectPage(reqVO);
|
return new PageResult<DaPointDTO>(page.getRecords(), page.getTotal());
|
}
|
|
@Override
|
public DaPointDTO info(String id) {
|
DaPointEntity entity = daPointDao.selectById(id);
|
DaPointDTO result = ConvertUtils.sourceToTarget(entity, DaPointDTO.class);
|
if (PointTypeEnum.MEASURE_POINT.getCode().equals(result.getPointType())) {
|
DaMeasurePointDTO measurePoint = daMeasurePointService.getByPoint(id);
|
result.setMeasurePoint(measurePoint);
|
List<String> sourceOption = new ArrayList<>();
|
sourceOption.add(measurePoint.getSourceType());
|
sourceOption.add(measurePoint.getSourceId());
|
sourceOption.add(measurePoint.getTagNo());
|
result.setSourceOption(sourceOption);
|
} else if (PointTypeEnum.CALCULATE_POINT.getCode().equals(result.getPointType())) {
|
result.setMathPoint(daMathPointService.getByPoint(id));
|
}
|
return result;
|
}
|
|
@Override
|
public List<DaPointDTO> list(Map<String, Object> params) {
|
Object pointType = params.get("pointType");
|
List<String> pointNos = new ArrayList<>();
|
if (params.get("pointNos") != null) {
|
pointNos = JSONArray.parseArray(JSONArray.toJSONString(params.get("pointNos")), String.class);
|
}
|
Object pointNoLike = params.get("pointNoLike");
|
QueryWrapper<DaPointEntity> queryWrapper = new QueryWrapper();
|
queryWrapper.eq(!ObjectUtils.isEmpty(pointType), "point_type", pointType);
|
queryWrapper.in(pointNos.size() != 0,"point_no", pointNos);
|
queryWrapper.like(!ObjectUtils.isEmpty(pointNoLike), "point_no", pointNoLike);
|
List<DaPointEntity> list = daPointDao.selectList(queryWrapper);
|
return ConvertUtils.sourceToTarget(list, DaPointDTO.class);
|
}
|
|
@Override
|
@DSTransactional(rollbackFor = Exception.class)
|
public void add(DaPointDTO dataPoint) {
|
DaPointEntity daPointEntity = ConvertUtils.sourceToTarget(dataPoint, DaPointEntity.class);
|
daPointEntity.setId(UUID.randomUUID().toString());
|
if (PointTypeEnum.MEASURE_POINT.getName().equals(dataPoint.getPointType())) {
|
DaMeasurePointDTO measurePoint = new DaMeasurePointDTO();
|
measurePoint.setSourceType(dataPoint.getSourceOption().get(0));
|
measurePoint.setSourceId(dataPoint.getSourceOption().get(1));
|
measurePoint.setTagNo(dataPoint.getSourceOption().get(2));
|
daMeasurePointService.add(measurePoint, daPointEntity.getId());
|
daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_M.name()));
|
} else if (PointTypeEnum.CALCULATE_POINT.getName().equals(dataPoint.getPointType())) {
|
daMathPointService.add(dataPoint.getMathPoint(), daPointEntity.getId());
|
daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_C.name()));
|
} else if (PointTypeEnum.CONSTANT.getName().equals(dataPoint.getPointType())) {
|
daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_F.name()));
|
}
|
daPointEntity.setIsEnable(CommonConstant.IS_ENABLE);
|
daPointEntity.setCreateTime(new Date());
|
daPointDao.insert(daPointEntity);
|
}
|
|
@Override
|
@DSTransactional(rollbackFor = Exception.class)
|
public void update(DaPointDTO dataPoint) {
|
DaPointEntity daPointEntity = ConvertUtils.sourceToTarget(dataPoint, DaPointEntity.class);
|
daPointEntity.setUpdateTime(new Date());
|
daPointDao.updateById(daPointEntity);
|
if (PointTypeEnum.MEASURE_POINT.getName().equals(dataPoint.getPointType())) {
|
DaMeasurePointDTO measurePoint = dataPoint.getMeasurePoint();
|
measurePoint.setSourceType(dataPoint.getSourceOption().get(0));
|
measurePoint.setSourceId(dataPoint.getSourceOption().get(1));
|
measurePoint.setTagNo(dataPoint.getSourceOption().get(2));
|
daMeasurePointService.update(measurePoint);
|
} else if (PointTypeEnum.CALCULATE_POINT.getName().equals(dataPoint.getPointType())) {
|
daMathPointService.update(dataPoint.getMathPoint());
|
}
|
}
|
|
@Override
|
@DSTransactional(rollbackFor = Exception.class)
|
public void delete(String[] id) {
|
daPointDao.deleteBatchIds(Arrays.asList(id));
|
daMeasurePointService.deleteByPoint(id);
|
daMathPointService.deleteByPoint(id);
|
}
|
|
@Override
|
public List<DaPointDTO> getConstantPoint(String freq) {
|
Map<String, Object> params = new HashMap<>();
|
params.put("pointType", PointTypeEnum.CONSTANT.getCode());
|
params.put("isEnable", CommonConstant.IS_ENABLE);
|
params.put("minfreqid", freq);
|
return daPointDao.getConstantPoint(params);
|
}
|
|
@Override
|
public List<DaPointDTO> getConstantPoint(List<String> pointNos) {
|
Map<String, Object> params = new HashMap<>();
|
params.put("pointType", PointTypeEnum.CONSTANT.getCode());
|
params.put("isEnable", CommonConstant.IS_ENABLE);
|
params.put("pointNos", pointNos);
|
return daPointDao.getConstantPoint(params);
|
}
|
|
@Override
|
public List<DaPointDTO> getMeasurePoint(String freq) {
|
Map<String, Object> params = new HashMap<>();
|
params.put("pointType", PointTypeEnum.MEASURE_POINT.getCode());
|
params.put("isEnable", CommonConstant.IS_ENABLE);
|
params.put("minfreqid", freq);
|
return daPointDao.getMeasurePoint(params);
|
}
|
|
@Override
|
public List<DaPointDTO> getMeasurePoint(List<String> pointNos) {
|
Map<String, Object> params = new HashMap<>();
|
params.put("pointType", PointTypeEnum.MEASURE_POINT.getCode());
|
params.put("isEnable", CommonConstant.IS_ENABLE);
|
params.put("pointNos", pointNos);
|
return daPointDao.getMeasurePoint(params);
|
}
|
|
@Override
|
public DaPointDTO getMeasurePointByNo(String pointNo) {
|
Map<String, Object> params = new HashMap<>();
|
params.put("pointType", PointTypeEnum.MEASURE_POINT.getCode());
|
params.put("pointNo", pointNo);
|
List<DaPointDTO> list = daPointDao.getMeasurePoint(params);
|
if (CollectionUtils.isEmpty(list)) {
|
return null;
|
}
|
return list.get(0);
|
}
|
|
@Override
|
public List<DaPointDTO> getMathPoint(String freq) {
|
Map<String, Object> params = new HashMap<>();
|
params.put("pointType", PointTypeEnum.CALCULATE_POINT.getCode());
|
params.put("isEnable", CommonConstant.IS_ENABLE);
|
params.put("minfreqid", freq);
|
return daPointDao.getMathPoint(params);
|
}
|
|
@Override
|
public List<DaPointDTO> getMathPoint(List<String> pointNos) {
|
Map<String, Object> params = new HashMap<>();
|
params.put("pointType", PointTypeEnum.CALCULATE_POINT.getCode());
|
params.put("isEnable", CommonConstant.IS_ENABLE);
|
params.put("pointNos", pointNos);
|
return daPointDao.getMathPoint(params);
|
}
|
|
@Override
|
public DaPointDTO getByNo(String pointNo) {
|
QueryWrapper<DaPointEntity> wrapper = new QueryWrapper<>();
|
wrapper.eq("point_no", pointNo);
|
DaPointEntity entity = daPointDao.selectOne(wrapper);
|
return ConvertUtils.sourceToTarget(entity, DaPointDTO.class);
|
}
|
|
@Override
|
public List<DaPointDTO> getByNos(List<String> pointNos) {
|
QueryWrapper<DaPointEntity> wrapper = new QueryWrapper<>();
|
wrapper.in("point_no", pointNos);
|
List<DaPointEntity> list = daPointDao.selectList(wrapper);
|
return ConvertUtils.sourceToTarget(list, DaPointDTO.class);
|
}
|
|
@Override
|
public void updateDefaultValue(DaPointDTO dto) {
|
QueryWrapper<DaPointEntity> wrapper = new QueryWrapper<>();
|
wrapper.eq("point_no", dto.getPointNo());
|
DaPointEntity entity = new DaPointEntity();
|
entity.setDefaultValue(dto.getDefaultValue());
|
daPointDao.update(entity, wrapper);
|
}
|
|
@Override
|
public void enableByIds(String[] ids) {
|
if (CollectionUtils.isEmpty(Arrays.asList(ids))) {
|
return;
|
}
|
Arrays.asList(ids).forEach(item -> {
|
DaPointEntity entity = new DaPointEntity();
|
entity.setId(item);
|
entity.setIsEnable(IsEnableEnum.ENABLE.value());
|
daPointDao.updateById(entity);
|
});
|
}
|
|
@Override
|
public void disableByIds(String[] ids) {
|
if (CollectionUtils.isEmpty(Arrays.asList(ids))) {
|
return;
|
}
|
Arrays.asList(ids).forEach(item -> {
|
DaPointEntity entity = new DaPointEntity();
|
entity.setId(item);
|
entity.setIsEnable(IsEnableEnum.DISABLE.value());
|
daPointDao.updateById(entity);
|
});
|
}
|
}
|