ustcyc
2025-01-07 de5d55508afd27fb2b47e6d4d6fd9984525c222c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.zhitan.model.service.impl;
 
import com.zhitan.common.utils.StringUtils;
import com.zhitan.common.utils.uuid.UUID;
import com.zhitan.model.domain.IndexFormula;
import com.zhitan.model.domain.IndexFormulaParam;
import com.zhitan.model.mapper.IndexFormulaMapper;
import com.zhitan.model.service.IndexFormulaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
/**
 * @author fanxinfu
 */
@Service
public class IndexFormulaServiceImpl implements IndexFormulaService {
 
  @Autowired
  private IndexFormulaMapper indexFormulaMapper;
 
  @Override
  public void saveIndexFormula(IndexFormula indexFormula) {
    if (StringUtils.isEmpty(indexFormula.getId())) {
      indexFormula.setId(UUID.fastUUID().toString());
      indexFormulaMapper.insertIndexFormula(indexFormula);
    } else {
      indexFormulaMapper.updateIndexFormula(indexFormula);
    }
 
    indexFormula.getIndexFormulaParams().forEach(param -> {
      param.setId(UUID.fastUUID().toString());
      param.setFormulaId(indexFormula.getId());
      param.setIndexId(indexFormula.getIndexId());
    });
    indexFormulaMapper
        .saveIndexFormulaParam(indexFormula.getIndexId(), indexFormula.getIndexFormulaParams());
  }
 
  @Override
  public IndexFormula getIndexFormula(String indexId) {
    IndexFormula indexFormula = indexFormulaMapper.getFormula(indexId);
    if (indexFormula != null) {
      List<IndexFormulaParam> indexFormulaParams = indexFormulaMapper.getFormulaParam(indexId);
      if (!indexFormulaParams.isEmpty()) {
        indexFormula.setIndexFormulaParams(indexFormulaParams);
      }
    } else {
      indexFormula = new IndexFormula();
    }
 
    return indexFormula;
  }
 
}