Commit deb27883 by zhangkb

添加指标关系表接口

parent 5882640a
......@@ -23,6 +23,8 @@ public class BaseIndDef {
private String indDesc;//说明
private String indSource;//数据项来源 1:excel导入 2:手工填报
private String indFrequency;//数据源频度 0:月度 1:季度 2:年度
private String indFormat;//指标公式
private String indFormatDesc;//指标公式描述
private String creater;
private Date createTime;
private String updater;
......
package com.keymobile.indicators.model.entity.indicators;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.Data;
/**
* author:zhangkb time:2020-6-26 desc:记录指标间的关系表
*/
@Data
@Table(name="ind_relation")
public class IndicatorsRel {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String indId;
private String relIndId;
private String indFormat;//指标公式
private String indFormatDesc;//指标公式描述
}
package com.keymobile.indicators.model.mapper.indmapper;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import com.keymobile.indicators.model.entity.indicators.IndicatorsRel;
import tk.mybatis.mapper.common.BaseMapper;
@Mapper
public interface IndicatorsRelMapper extends BaseMapper<IndicatorsRel>{
public List<IndicatorsRel> findByIndId(@Param("indId")String indId);
public void deleteByIndId(@Param("indId")String indId);
}
package com.keymobile.indicators.service.hytobacco;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.keymobile.indicators.model.entity.indicators.BaseIndDef;
import com.keymobile.indicators.model.entity.indicators.DriveIndDef;
import com.keymobile.indicators.model.entity.indicators.IndicatorsRel;
import com.keymobile.indicators.model.mapper.indicators.BaseIndDefMapper;
import com.keymobile.indicators.model.mapper.indicators.DriveIndDefMapper;
import com.keymobile.indicators.model.mapper.indmapper.IndicatorsRelMapper;
@Service
public class IndicatorsRelService {
private Logger logger = LoggerFactory.getLogger(IndicatorsRelService.class);
private final static Pattern P = Pattern.compile("(\\[[^\\]]*\\])");
@Autowired
private BaseIndDefMapper baseIndDefMapper;
@Autowired
private DriveIndDefMapper driveIndDefMapper;
@Autowired
private IndicatorsRelMapper indicatorsRelMapper;
//type:0 基础指标 1:考核指标
public void saveOrUpdate(String indId,String type) {
String formula = null;
String formulaDesc = null;
//判断该指标有没有保存了关联指标,有的则全部删除,全部新建
List<IndicatorsRel> indRels = indicatorsRelMapper.findByIndId(indId);
if(!indRels.isEmpty()) {
//删除关系
indicatorsRelMapper.deleteByIndId(indId);
}
//根据类型查找指标
if("0".equals(type)) {//基础指标
BaseIndDef baseIndDef = baseIndDefMapper.selectByPrimaryKey(indId);
if(baseIndDef!=null) {
formula = baseIndDef.getIndFormat();
formulaDesc = baseIndDef.getIndFormatDesc();
}
}else {//考核指标
DriveIndDef driveIndDef = driveIndDefMapper.selectByPrimaryKey(indId);
if(driveIndDef!=null) {
formula = driveIndDef.getIndFormat();
formulaDesc = driveIndDef.getIndFormatDesc();
}
}
//解析公式关系
if(StringUtils.isNotBlank(formula)) {
List<String> indIdList = new ArrayList<>();
Matcher m = P.matcher(formula);
while(m.find()){
indIdList.add(m.group().substring(1, m.group().length()-1));
}
for(String relIndId : indIdList) {
IndicatorsRel indRel = new IndicatorsRel();
indRel.setIndId(indId);
indRel.setRelIndId(relIndId);
indRel.setIndFormat(formula);
indRel.setIndFormatDesc(formulaDesc);
indicatorsRelMapper.insert(indRel);
}
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.keymobile.indicators.model.mapper.indmapper.IndicatorsRelMapper">
<select id="findByIndId" resultType="com.keymobile.indicators.model.entity.indicators.IndicatorsRel" >
select *
from ind_relation
where ind_id = #{indId}
</select>
<delete id="deleteByIndId">
delete
from ind_relation
where ind_id = #{indId}
</delete>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment