|
@@ -0,0 +1,146 @@
|
|
|
+package cn.cslg.pas.service.business;
|
|
|
+
|
|
|
+import cn.cslg.pas.common.dto.customAnalyse.CustomAnalyseDTO;
|
|
|
+import cn.cslg.pas.common.dto.customAnalyse.SchemaDimensionDTO;
|
|
|
+import cn.cslg.pas.common.dto.customAnalyse.SourceDataDTO;
|
|
|
+import cn.cslg.pas.common.dto.customAnalyse.SourceMinAndMaxDataDTO;
|
|
|
+import cn.cslg.pas.common.model.cronModel.PersonnelVO;
|
|
|
+import cn.cslg.pas.common.utils.CacheUtils;
|
|
|
+import cn.cslg.pas.common.utils.JsonUtils;
|
|
|
+import cn.cslg.pas.common.utils.LoginUtils;
|
|
|
+import cn.cslg.pas.common.utils.StringUtils;
|
|
|
+import cn.cslg.pas.common.vo.customAnalyse.SourceDataVO;
|
|
|
+import cn.cslg.pas.domain.business.CustomAnalysisItem;
|
|
|
+import cn.cslg.pas.domain.business.CustomAnalysisItemSource;
|
|
|
+import cn.cslg.pas.exception.UnLoginException;
|
|
|
+import cn.cslg.pas.mapper.CustomAnalysisItemSourceMapper;
|
|
|
+import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 自定义分析项目数据源 服务实现类
|
|
|
+ * </p>
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class CustomAnalysisItemSourceService extends ServiceImpl<CustomAnalysisItemSourceMapper, CustomAnalysisItemSource> {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CacheUtils cacheUtils;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LoginUtils loginUtils;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CustomAnalysisItemSourceMapper customAnalysisItemSourceMapper;
|
|
|
+
|
|
|
+ public SourceDataDTO getItemSourceData(CustomAnalyseDTO customAnalysisItem) {
|
|
|
+ SourceDataDTO sourceDataDTO = new SourceDataDTO();
|
|
|
+ SchemaDimensionDTO schema = customAnalysisItem.getSchema();
|
|
|
+ sourceDataDTO.setX(this.setReturnData(this.getItemSourceList(customAnalysisItem.getUid(), "x", schema.getX().getField(), schema.getX().getExpand())));
|
|
|
+ sourceDataDTO.setY(this.setReturnData(this.getItemSourceList(customAnalysisItem.getUid(), "y", schema.getY().getField(), schema.getY().getExpand())));
|
|
|
+ return sourceDataDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<CustomAnalysisItemSource> getItemSourceList(String uid, String dimension, Integer fieldId, Integer expandId) {
|
|
|
+ LambdaQueryWrapper<CustomAnalysisItemSource> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(CustomAnalysisItemSource::getUid, uid);
|
|
|
+ queryWrapper.eq(CustomAnalysisItemSource::getDimension, dimension);
|
|
|
+ queryWrapper.eq(CustomAnalysisItemSource::getFieldId, fieldId);
|
|
|
+ queryWrapper.eq(CustomAnalysisItemSource::getExpandId, expandId);
|
|
|
+ return this.list(queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<CustomAnalysisItemSource> setReturnData(List<CustomAnalysisItemSource> list) {
|
|
|
+ list.forEach(item -> {
|
|
|
+ item.setUid(null);
|
|
|
+ item.setDimension(null);
|
|
|
+ item.setFieldId(null);
|
|
|
+ item.setExpandId(null);
|
|
|
+ item.setCreateTime(null);
|
|
|
+ item.setUpdateTime(null);
|
|
|
+ item.setStatus(null);
|
|
|
+ item.setId(null);
|
|
|
+ item.setCreateId(null);
|
|
|
+ item.setCreateName(null);
|
|
|
+ if (StringUtils.isNotEmpty(item.getMaxData())) {
|
|
|
+ item.setMax(JsonUtils.jsonToPojo(item.getMaxData(), SourceMinAndMaxDataDTO.class));
|
|
|
+ item.setMaxData(null);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(item.getMinData())) {
|
|
|
+ item.setMin(JsonUtils.jsonToPojo(item.getMinData(), SourceMinAndMaxDataDTO.class));
|
|
|
+ item.setMinData(null);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void edit(CustomAnalyseDTO vo) {
|
|
|
+ SourceDataVO x = new SourceDataVO();
|
|
|
+ SourceDataVO y = new SourceDataVO();
|
|
|
+ SourceDataDTO sourceDataDTO = vo.getSource();
|
|
|
+ if (vo.getSchema().getX().getPtype().equals(3) || vo.getSchema().getX().getPtype().equals(4)
|
|
|
+ || vo.getSchema().getX().getType().equals(6)) {
|
|
|
+ x.setUid(vo.getUid());
|
|
|
+ x.setDimension("x");
|
|
|
+ x.setFieldId(vo.getSchema().getX().getField());
|
|
|
+ x.setExpandId(vo.getSchema().getX().getExpand());
|
|
|
+ x.setSource(sourceDataDTO.getX());
|
|
|
+ this.updateSource(x);
|
|
|
+ }
|
|
|
+ if (vo.getSchema().getY().getPtype().equals(3) || vo.getSchema().getY().getPtype().equals(4)
|
|
|
+ || vo.getSchema().getY().getType().equals(6)) {
|
|
|
+ y.setUid(vo.getUid());
|
|
|
+ y.setDimension("y");
|
|
|
+ y.setFieldId(vo.getSchema().getY().getField());
|
|
|
+ y.setExpandId(vo.getSchema().getY().getExpand());
|
|
|
+ y.setSource(sourceDataDTO.getY());
|
|
|
+ this.updateSource(y);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void updateSource(SourceDataVO sourceDataVO) {
|
|
|
+ this.remove(Wrappers.<CustomAnalysisItemSource>lambdaQuery().eq(CustomAnalysisItemSource::getUid, sourceDataVO.getUid())
|
|
|
+ .eq(CustomAnalysisItemSource::getDimension, sourceDataVO.getDimension()));
|
|
|
+ //获取登陆人信息 用于设置创建人
|
|
|
+ PersonnelVO personnelVO = new PersonnelVO();
|
|
|
+ try {
|
|
|
+ personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new UnLoginException("未登录");
|
|
|
+ }
|
|
|
+ List<CustomAnalysisItemSource> list = new ArrayList<>();
|
|
|
+ PersonnelVO finalPersonnelVO = personnelVO;
|
|
|
+ sourceDataVO.getSource().forEach(source -> {
|
|
|
+ if (StringUtils.isNotNull(source.getMax())) {
|
|
|
+ source.setMaxData(JsonUtils.objectToJson(source.getMax()));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotNull(source.getMin())) {
|
|
|
+ source.setMinData(JsonUtils.objectToJson(source.getMin()));
|
|
|
+ }
|
|
|
+ source.setFieldId(sourceDataVO.getFieldId());
|
|
|
+ source.setExpandId(sourceDataVO.getExpandId());
|
|
|
+ source.setCreateId(finalPersonnelVO.getId());
|
|
|
+ source.setCreateName(finalPersonnelVO.getName());
|
|
|
+ source.setDimension(sourceDataVO.getDimension());
|
|
|
+ source.setUid(sourceDataVO.getUid());
|
|
|
+ list.add(source);
|
|
|
+ });
|
|
|
+ this.saveOrUpdateBatch(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void deleteByUid(String uid) {
|
|
|
+ this.remove(Wrappers.<CustomAnalysisItemSource>lambdaQuery().eq(CustomAnalysisItemSource::getUid, uid));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|