潘志宝
2024-10-09 c0b8cf32504dd1a42780bb1ee06ae8a7b0d7b120
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java
@@ -1,39 +1,39 @@
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.iailab.framework.common.constant.Constant;
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.framework.common.page.PageData;
import com.iailab.framework.common.service.impl.BaseServiceImpl;
import com.iailab.framework.common.util.object.ConvertUtils;
import com.iailab.module.data.point.common.IncreaseCodeEnum;
import com.iailab.module.data.point.dao.DaPointDao;
import com.iailab.module.data.point.service.DaMeasurePointService;
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 org.apache.commons.lang3.StringUtils;
import javax.annotation.Resource;
import com.iailab.module.data.point.vo.DaPointPageReqVO;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.*;
/**
 * @author PanZhibao
 * @author lirm
 * @Description
 * @createTime 2024年05月12日
 * @createTime 2024年09月2日
 */
@Service
public class DaPointServiceImpl extends BaseServiceImpl<DaPointDao, DaPointEntity> implements DaPointService {
public class DaPointServiceImpl extends ServiceImpl<DaPointDao, DaPointEntity> implements DaPointService {
    @Resource
    private DaMeasurePointService daMeasurePointService;
@@ -43,19 +43,20 @@
    @Resource
    private DaSequenceNumService daSequenceNumService;
    @Resource
    private DaPointDao daPointDao;
    @Override
    public PageData<DaPointDTO> page(Map<String, Object> params) {
        IPage<DaPointDTO> page = baseDao.getPageList(
                getPage(params, Constant.CREATE_TIME, false),
                params
        );
        return getPageData(page, DaPointDTO.class);
    public PageResult<DaPointDTO> queryPage(DaPointPageReqVO reqVO) {
        IPage<DaPointDTO> page = daPointDao.selectPage(reqVO);
        return new PageResult<DaPointDTO>(page.getRecords(), page.getTotal());
    }
    @Override
    public DaPointDTO get(String id) {
        DaPointEntity entity = baseDao.selectById(id);
    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);
@@ -72,26 +73,35 @@
    }
    @Override
    public DaPointDTO getSimpleInfoById(String id) {
        return ConvertUtils.sourceToTarget(daPointDao.selectById(id), DaPointDTO.class);
    }
    @Override
    public DaPointDTO getSimpleInfoByNo(String no) {
        QueryWrapper<DaPointEntity> queryWrapper = new QueryWrapper();
        queryWrapper.eq("pointNo", no);
        return ConvertUtils.sourceToTarget(daPointDao.selectOne(queryWrapper), DaPointDTO.class);
    }
    @Override
    public List<DaPointDTO> list(Map<String, Object> params) {
        String page = (String) params.get("page");
        String limit = (String) params.get("limit");
        String pointType = (String)params.get("pointType");
        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);
        }
        String pointNoLike = (String)params.get("pointNoLike");
        Object pointNoLike = params.get("pointNoLike");
        QueryWrapper<DaPointEntity> queryWrapper = new QueryWrapper();
        queryWrapper.eq(StringUtils.isNotBlank(pointType), "point_type", pointType)
        .in(!CollectionUtils.isEmpty(pointNos),"point_no", pointNos)
        .like(StringUtils.isNotBlank(pointNoLike), "point_no", pointNoLike)
                .last("limit 1, 10");
        List<DaPointEntity> list = baseDao.selectList(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
    @Transactional(rollbackFor = Exception.class)
    @DSTransactional(rollbackFor = Exception.class)
    public void add(DaPointDTO dataPoint) {
        DaPointEntity daPointEntity = ConvertUtils.sourceToTarget(dataPoint, DaPointEntity.class);
        daPointEntity.setId(UUID.randomUUID().toString());
@@ -110,32 +120,32 @@
        }
        daPointEntity.setIsEnable(CommonConstant.IS_ENABLE);
        daPointEntity.setCreateTime(new Date());
        baseDao.insert(daPointEntity);
        daPointDao.insert(daPointEntity);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    @DSTransactional(rollbackFor = Exception.class)
    public void update(DaPointDTO dataPoint) {
        DaPointEntity daPointEntity = ConvertUtils.sourceToTarget(dataPoint, DaPointEntity.class);
        daPointEntity.setUpdateTime(new Date());
        baseDao.updateById(daPointEntity);
        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.equals(dataPoint.getPointType())) {
        } else if (PointTypeEnum.CALCULATE_POINT.getName().equals(dataPoint.getPointType())) {
            daMathPointService.update(dataPoint.getMathPoint());
        }
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(String[] ids) {
        baseDao.deleteBatchIds(Arrays.asList(ids));
        daMeasurePointService.deleteByPoint(ids);
        daMathPointService.deleteByPoint(ids);
    @DSTransactional(rollbackFor = Exception.class)
    public void delete(String[] id) {
        daPointDao.deleteBatchIds(Arrays.asList(id));
        daMeasurePointService.deleteByPoint(id);
        daMathPointService.deleteByPoint(id);
    }
    @Override
@@ -144,7 +154,7 @@
        params.put("pointType", PointTypeEnum.CONSTANT.getCode());
        params.put("isEnable", CommonConstant.IS_ENABLE);
        params.put("minfreqid", freq);
        return baseDao.getConstantPoint(params);
        return daPointDao.getConstantPoint(params);
    }
    @Override
@@ -153,7 +163,7 @@
        params.put("pointType", PointTypeEnum.CONSTANT.getCode());
        params.put("isEnable", CommonConstant.IS_ENABLE);
        params.put("pointNos", pointNos);
        return baseDao.getConstantPoint(params);
        return daPointDao.getConstantPoint(params);
    }
    @Override
@@ -162,7 +172,7 @@
        params.put("pointType", PointTypeEnum.MEASURE_POINT.getCode());
        params.put("isEnable", CommonConstant.IS_ENABLE);
        params.put("minfreqid", freq);
        return baseDao.getMeasurePoint(params);
        return daPointDao.getMeasurePoint(params);
    }
    @Override
@@ -171,7 +181,7 @@
        params.put("pointType", PointTypeEnum.MEASURE_POINT.getCode());
        params.put("isEnable", CommonConstant.IS_ENABLE);
        params.put("pointNos", pointNos);
        return baseDao.getMeasurePoint(params);
        return daPointDao.getMeasurePoint(params);
    }
    @Override
@@ -179,7 +189,7 @@
        Map<String, Object> params = new HashMap<>();
        params.put("pointType", PointTypeEnum.MEASURE_POINT.getCode());
        params.put("pointNo", pointNo);
        List<DaPointDTO> list = baseDao.getMeasurePoint(params);
        List<DaPointDTO> list = daPointDao.getMeasurePoint(params);
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
@@ -192,7 +202,7 @@
        params.put("pointType", PointTypeEnum.CALCULATE_POINT.getCode());
        params.put("isEnable", CommonConstant.IS_ENABLE);
        params.put("minfreqid", freq);
        return baseDao.getMathPoint(params);
        return daPointDao.getMathPoint(params);
    }
    @Override
@@ -201,14 +211,14 @@
        params.put("pointType", PointTypeEnum.CALCULATE_POINT.getCode());
        params.put("isEnable", CommonConstant.IS_ENABLE);
        params.put("pointNos", pointNos);
        return baseDao.getMathPoint(params);
        return daPointDao.getMathPoint(params);
    }
    @Override
    public DaPointDTO getByNo(String pointNo) {
        QueryWrapper<DaPointEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("point_no", pointNo);
        DaPointEntity entity = baseDao.selectOne(wrapper);
        DaPointEntity entity = daPointDao.selectOne(wrapper);
        return ConvertUtils.sourceToTarget(entity, DaPointDTO.class);
    }
@@ -216,7 +226,7 @@
    public List<DaPointDTO> getByNos(List<String> pointNos) {
        QueryWrapper<DaPointEntity> wrapper = new QueryWrapper<>();
        wrapper.in("point_no", pointNos);
        List<DaPointEntity> list = baseDao.selectList(wrapper);
        List<DaPointEntity> list = daPointDao.selectList(wrapper);
        return ConvertUtils.sourceToTarget(list, DaPointDTO.class);
    }
@@ -226,7 +236,7 @@
        wrapper.eq("point_no", dto.getPointNo());
        DaPointEntity entity = new DaPointEntity();
        entity.setDefaultValue(dto.getDefaultValue());
        baseDao.update(entity, wrapper);
        daPointDao.update(entity, wrapper);
    }
    @Override
@@ -238,7 +248,7 @@
            DaPointEntity entity = new DaPointEntity();
            entity.setId(item);
            entity.setIsEnable(IsEnableEnum.ENABLE.value());
            baseDao.updateById(entity);
            daPointDao.updateById(entity);
        });
    }
@@ -251,7 +261,7 @@
            DaPointEntity entity = new DaPointEntity();
            entity.setId(item);
            entity.setIsEnable(IsEnableEnum.DISABLE.value());
            baseDao.updateById(entity);
            daPointDao.updateById(entity);
        });
    }
}