10 changed files with 428 additions and 1 deletions
@ -0,0 +1,23 @@ |
|||||
|
package com.epmet.dto.screen.form; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
/** |
||||
|
* desc:初始化客户指标权重参数实体类 |
||||
|
* @author liujianjun |
||||
|
*/ |
||||
|
@Data |
||||
|
public class IndexCalculateForm implements Serializable { |
||||
|
private static final long serialVersionUID = 3280392511156378209L; |
||||
|
/** |
||||
|
* desc:客户id |
||||
|
*/ |
||||
|
private String customerId; |
||||
|
|
||||
|
/** |
||||
|
* desc:月份id |
||||
|
*/ |
||||
|
private String monthId; |
||||
|
} |
@ -0,0 +1,154 @@ |
|||||
|
package com.epmet.controller; |
||||
|
|
||||
|
import com.epmet.commons.extappauth.annotation.ExternalAppRequestAuth; |
||||
|
import com.epmet.commons.extappauth.bean.ExternalAppRequestParam; |
||||
|
import com.epmet.commons.tools.utils.Result; |
||||
|
import com.epmet.dto.screen.form.IndexCalculateForm; |
||||
|
import com.epmet.service.screen.IndexCalculateService; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
/** |
||||
|
* 指标计算controller |
||||
|
* |
||||
|
* @author liujianjun@elink-cn.com |
||||
|
* @date 2020/8/24 14:38 |
||||
|
*/ |
||||
|
@RestController |
||||
|
@RequestMapping("indexcalculate") |
||||
|
public class IndexCalculateController { |
||||
|
|
||||
|
@Autowired |
||||
|
private IndexCalculateService indexCalculateService; |
||||
|
|
||||
|
/** |
||||
|
* 1、党建能力-党员相关指标计算(按照月份) |
||||
|
* |
||||
|
* @param externalAppRequestParam |
||||
|
* @param formDTO |
||||
|
* @return com.epmet.commons.tools.utils.Result |
||||
|
* @Author zhangyong |
||||
|
* @Date 10:52 2020-08-20 |
||||
|
**/ |
||||
|
@ExternalAppRequestAuth |
||||
|
@PostMapping("cpc") |
||||
|
public Result cpcIndexCalculate(ExternalAppRequestParam externalAppRequestParam, @RequestBody IndexCalculateForm formDTO) { |
||||
|
indexCalculateService.cpcIndexCalculate(formDTO); |
||||
|
return new Result(); |
||||
|
} |
||||
|
|
||||
|
/* *//** |
||||
|
* 2、党建能力-网格相关指标上报(按照月份) |
||||
|
* |
||||
|
* @param externalAppRequestParam |
||||
|
* @param formDTO |
||||
|
* @return com.epmet.commons.tools.utils.Result |
||||
|
* @Author zhangyong |
||||
|
* @Date 10:52 2020-08-20 |
||||
|
**//*
|
||||
|
@ExternalAppRequestAuth |
||||
|
@PostMapping("gridpartyability") |
||||
|
public Result gridPartyAbility(ExternalAppRequestParam externalAppRequestParam, @RequestBody List<GridPartyAbilityFormDTO> formDTO) { |
||||
|
factIndexCollectService.insertGridPartyAbility(formDTO, externalAppRequestParam.getCustomerId()); |
||||
|
return new Result(); |
||||
|
} |
||||
|
|
||||
|
*//**
|
||||
|
* 3、党建能力-街道及社区相关指标 |
||||
|
* |
||||
|
* @param externalAppRequestParam |
||||
|
* @param formDTO |
||||
|
* @return com.epmet.commons.tools.utils.Result |
||||
|
* @Author zhangyong |
||||
|
* @Date 10:52 2020-08-20 |
||||
|
**//*
|
||||
|
@ExternalAppRequestAuth |
||||
|
@PostMapping("orgpartyability") |
||||
|
public Result orgPartyAbility(ExternalAppRequestParam externalAppRequestParam, @RequestBody List<OrgPartyAbilityFormDTO> formDTO) { |
||||
|
factIndexCollectService.insertOrgPartyAbility(formDTO, externalAppRequestParam.getCustomerId()); |
||||
|
return new Result(); |
||||
|
} |
||||
|
|
||||
|
*//**
|
||||
|
* 4、服务能力-网格相关指标 |
||||
|
* |
||||
|
* @param externalAppRequestParam |
||||
|
* @param formDTO |
||||
|
* @return com.epmet.commons.tools.utils.Result |
||||
|
* @Author zhangyong |
||||
|
* @Date 10:52 2020-08-20 |
||||
|
**//*
|
||||
|
@ExternalAppRequestAuth |
||||
|
@PostMapping("gridserviceability") |
||||
|
public Result gridServiceAbility(ExternalAppRequestParam externalAppRequestParam, @RequestBody List<GridServiceAbilityFormDTO> formDTO) { |
||||
|
factIndexCollectService.insertGridServiceAbility(formDTO, externalAppRequestParam.getCustomerId()); |
||||
|
return new Result(); |
||||
|
} |
||||
|
|
||||
|
*//**
|
||||
|
* 5、服务能力-组织(街道|社区|全区)相关指标 |
||||
|
* |
||||
|
* @param externalAppRequestParam |
||||
|
* @param formDTO |
||||
|
* @return com.epmet.commons.tools.utils.Result |
||||
|
* @Author zhangyong |
||||
|
* @Date 10:52 2020-08-20 |
||||
|
**//*
|
||||
|
@ExternalAppRequestAuth |
||||
|
@PostMapping("orgserviceability") |
||||
|
public Result orgServiceAbility(ExternalAppRequestParam externalAppRequestParam, @RequestBody List<OrgServiceAbilityFormDTO> formDTO) { |
||||
|
factIndexCollectService.insertOrgServiceAbility(formDTO, externalAppRequestParam.getCustomerId()); |
||||
|
return new Result(); |
||||
|
} |
||||
|
|
||||
|
*//**
|
||||
|
* 6、治理能力-网格相关指标 |
||||
|
* |
||||
|
* @param externalAppRequestParam |
||||
|
* @param formDTO |
||||
|
* @return com.epmet.commons.tools.utils.Result |
||||
|
* @Author zhangyong |
||||
|
* @Date 10:52 2020-08-20 |
||||
|
**//*
|
||||
|
@ExternalAppRequestAuth |
||||
|
@PostMapping("gridgovrnability") |
||||
|
public Result gridGovrnAbility(ExternalAppRequestParam externalAppRequestParam, @RequestBody List<GridGovrnAbilityFormDTO> formDTO) { |
||||
|
factIndexCollectService.insertGridGovrnAbility(formDTO, externalAppRequestParam.getCustomerId()); |
||||
|
return new Result(); |
||||
|
} |
||||
|
|
||||
|
*//**
|
||||
|
* 7、治理能力-街道及社区相关指标 |
||||
|
* |
||||
|
* @param externalAppRequestParam |
||||
|
* @param formDTO |
||||
|
* @return com.epmet.commons.tools.utils.Result |
||||
|
* @Author zhangyong |
||||
|
* @Date 10:52 2020-08-20 |
||||
|
**//*
|
||||
|
@ExternalAppRequestAuth |
||||
|
@PostMapping("orggovrnability") |
||||
|
public Result orgGovrnAbility(ExternalAppRequestParam externalAppRequestParam, @RequestBody List<OrgGovrnAbilityFormDTO> formDTO) { |
||||
|
factIndexCollectService.insertOrgGovrnAbility(formDTO, externalAppRequestParam.getCustomerId()); |
||||
|
return new Result(); |
||||
|
} |
||||
|
|
||||
|
*//**
|
||||
|
* 8、治理能力-部门相关指标 |
||||
|
* |
||||
|
* @param externalAppRequestParam |
||||
|
* @param formDTO |
||||
|
* @return com.epmet.commons.tools.utils.Result |
||||
|
* @Author zhangyong |
||||
|
* @Date 10:52 2020-08-20 |
||||
|
**//*
|
||||
|
@ExternalAppRequestAuth |
||||
|
@PostMapping("deptgovrnability") |
||||
|
public Result deptGovrnAbility(ExternalAppRequestParam externalAppRequestParam, @RequestBody List<DeptGovrnAbilityFormDTO> formDTO) { |
||||
|
factIndexCollectService.insertDeptGovrnAbility(formDTO, externalAppRequestParam.getCustomerId()); |
||||
|
return new Result(); |
||||
|
}*/ |
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
package com.epmet.service.screen; |
||||
|
|
||||
|
import com.epmet.dto.screen.form.IndexCalculateForm; |
||||
|
|
||||
|
/** |
||||
|
* 指标计算service |
||||
|
* |
||||
|
* @author liujianjun@elink-cn.com |
||||
|
* @date 2020/8/18 10:25 |
||||
|
*/ |
||||
|
public interface IndexCalculateService { |
||||
|
/** |
||||
|
* desc:计算党员相关指标 |
||||
|
* @param formDTO |
||||
|
*/ |
||||
|
void cpcIndexCalculate(IndexCalculateForm formDTO); |
||||
|
} |
@ -0,0 +1,14 @@ |
|||||
|
package com.epmet.service.screen.impl; |
||||
|
|
||||
|
import com.epmet.dto.screen.form.IndexCalculateForm; |
||||
|
import com.epmet.service.screen.IndexCalculateService; |
||||
|
|
||||
|
/** |
||||
|
* @author liujianjun |
||||
|
*/ |
||||
|
public class IndexCalculateServiceImpl implements IndexCalculateService { |
||||
|
@Override |
||||
|
public void cpcIndexCalculate(IndexCalculateForm formDTO) { |
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
package com.epmet.support.normalizing; |
||||
|
|
||||
|
/** |
||||
|
* 指标正负相关枚举 |
||||
|
*/ |
||||
|
public enum Correlation { |
||||
|
POSITIVE("positive","正相关"), |
||||
|
NEGATIVE("negative","负相关"), |
||||
|
; |
||||
|
|
||||
|
private String code; |
||||
|
private String desc; |
||||
|
Correlation(String code,String desc){ |
||||
|
this.code = code; |
||||
|
this.desc = desc; |
||||
|
} |
||||
|
} |
@ -0,0 +1,43 @@ |
|||||
|
package com.epmet.support.normalizing; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
|
||||
|
/** |
||||
|
* Double的分值计算 |
||||
|
* 每一种数据类型的计算都要继承ScoreCalculator并且实现其抽象方法,实现数据类型的转换 |
||||
|
*/ |
||||
|
public class DoubleScoreCalculator extends ScoreCalculator { |
||||
|
|
||||
|
/** |
||||
|
* 初始化double类型分值计算 |
||||
|
* ☆☆☆ 务必在该构造方法最后调用父类的prepare()方法 ☆☆☆ |
||||
|
* @param sourceArray 数据所在的数组 |
||||
|
* @param minScore 分值区间的左边界 |
||||
|
* @param maxScore 分值区间的右边界 |
||||
|
* @param correlation 相关性 |
||||
|
*/ |
||||
|
public DoubleScoreCalculator(Double[] sourceArray, BigDecimal minScore, BigDecimal maxScore, Correlation correlation) { |
||||
|
this.sourceArrary = sourceArray; |
||||
|
this.minScore = minScore; |
||||
|
this.maxScore = maxScore; |
||||
|
this.correlation = correlation; |
||||
|
this.prepare(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public BigDecimal getMaxFromSourceArray() { |
||||
|
Double[] doubleSourceArrary = (Double[]) this.sourceArrary; |
||||
|
return new BigDecimal(doubleSourceArrary[doubleSourceArrary.length - 1]); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public BigDecimal getMinFromSourceArray() { |
||||
|
Double[] intSourceArrary = (Double[]) this.sourceArrary; |
||||
|
return new BigDecimal(intSourceArrary[0]); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public BigDecimal convertValue2BigDecimal(Object sourceValue) { |
||||
|
return new BigDecimal((Double) sourceValue); |
||||
|
} |
||||
|
} |
@ -0,0 +1,45 @@ |
|||||
|
package com.epmet.support.normalizing; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
|
||||
|
/** |
||||
|
* Integer的分值计算 |
||||
|
* 每一种数据类型的计算都要继承ScoreCalculator并且实现其抽象方法,实现数据类型的转换 |
||||
|
*/ |
||||
|
public class IntegerScoreCalculator extends ScoreCalculator { |
||||
|
|
||||
|
/** |
||||
|
* 初始化整数分值计算 |
||||
|
* ☆☆☆ 务必在该构造方法最后调用父类的prepare()方法 ☆☆☆ |
||||
|
* @param sourceArray 数据所在的数组 |
||||
|
* @param minScore 分值区间的左边界 |
||||
|
* @param maxScore 分值区间的右边界 |
||||
|
* @param correlation 相关性 |
||||
|
*/ |
||||
|
public IntegerScoreCalculator(Integer[] sourceArray, BigDecimal minScore, BigDecimal maxScore, Correlation correlation) { |
||||
|
this.sourceArrary = sourceArray; |
||||
|
this.minScore = minScore; |
||||
|
this.maxScore = maxScore; |
||||
|
this.correlation = correlation; |
||||
|
this.prepare(); |
||||
|
System.out.println("最小值:"+minScore+";最大值:"+maxScore); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public BigDecimal getMaxFromSourceArray() { |
||||
|
Integer[] intSourceArrary = (Integer[]) this.sourceArrary; |
||||
|
return new BigDecimal(intSourceArrary[intSourceArrary.length - 1]); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public BigDecimal getMinFromSourceArray() { |
||||
|
Integer[] intSourceArrary = (Integer[]) this.sourceArrary; |
||||
|
return new BigDecimal(intSourceArrary[0]); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public BigDecimal convertValue2BigDecimal(Object sourceValue) { |
||||
|
return new BigDecimal((Integer) sourceValue); |
||||
|
} |
||||
|
} |
@ -0,0 +1,114 @@ |
|||||
|
package com.epmet.support.normalizing; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
import java.math.MathContext; |
||||
|
import java.util.Arrays; |
||||
|
|
||||
|
/** |
||||
|
* 所有数据类型计算器的父类,实现算法骨架,数据类型转换方法则由子类实现 |
||||
|
* @param <T> 数据类型泛型 |
||||
|
*/ |
||||
|
public abstract class ScoreCalculator<T> { |
||||
|
|
||||
|
protected T[] sourceArrary; |
||||
|
|
||||
|
protected BigDecimal minScore; |
||||
|
protected BigDecimal maxScore; |
||||
|
|
||||
|
protected Correlation correlation; |
||||
|
|
||||
|
private BigDecimal maxValue; |
||||
|
private BigDecimal minValue; |
||||
|
private BigDecimal coefficient; |
||||
|
|
||||
|
/** |
||||
|
* 计算准备 |
||||
|
*/ |
||||
|
protected void prepare() { |
||||
|
// 校验数组
|
||||
|
if (!validSourceArray(sourceArrary)) { |
||||
|
throw new RuntimeException("入参数组错误:请设置非空数组"); |
||||
|
} |
||||
|
Arrays.sort(sourceArrary); |
||||
|
maxValue = getMaxFromSourceArray(); |
||||
|
minValue = getMinFromSourceArray(); |
||||
|
//计算系数
|
||||
|
System.out.println("最小值:"+minScore+";最大值:"+maxScore); |
||||
|
coefficient = getCoefficient(minValue, maxValue); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 归一算法 |
||||
|
* @return |
||||
|
*/ |
||||
|
public BigDecimal normalize(T sourceValue) { |
||||
|
|
||||
|
if (sourceValue == null) { |
||||
|
throw new RuntimeException("入参数组错误:请设置sourceValue"); |
||||
|
} |
||||
|
|
||||
|
if (!Arrays.asList(sourceArrary).contains(sourceValue)) { |
||||
|
throw new RuntimeException("请确认要计算的数组在数组中存在"); |
||||
|
} |
||||
|
|
||||
|
if (correlation == Correlation.POSITIVE) { |
||||
|
// 正相关
|
||||
|
BigDecimal x = coefficient.multiply(convertValue2BigDecimal(sourceValue).subtract(minValue)); |
||||
|
BigDecimal score = minScore.add(x, MathContext.DECIMAL32); |
||||
|
return score; |
||||
|
} else if (correlation == Correlation.NEGATIVE) { |
||||
|
// 负相关
|
||||
|
BigDecimal x = coefficient.multiply(convertValue2BigDecimal(sourceValue).subtract(minValue)); |
||||
|
BigDecimal score = minScore.add(x); |
||||
|
return maxScore.subtract(score, MathContext.DECIMAL32); |
||||
|
} else { |
||||
|
throw new RuntimeException("错误的相关性"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 校验数组 |
||||
|
* @param sourceArray |
||||
|
* @param <T> |
||||
|
* @return |
||||
|
*/ |
||||
|
protected <T> boolean validSourceArray(T[] sourceArray) { |
||||
|
if (sourceArray == null || sourceArray.length == 0) { |
||||
|
return false; |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 计算系数 |
||||
|
* @return |
||||
|
*/ |
||||
|
protected BigDecimal getCoefficient(BigDecimal min, BigDecimal max) { |
||||
|
BigDecimal fenmu = max.subtract(min); |
||||
|
if (fenmu.toString().equals("0"))return new BigDecimal(0); |
||||
|
BigDecimal fenzi = maxScore.subtract(minScore); |
||||
|
BigDecimal divide = fenzi.divide(fenmu, MathContext.DECIMAL32); |
||||
|
System.out.println("分子:"+fenzi+"分母:"+fenmu+"系数:"+divide.toString()); |
||||
|
return divide; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 从源数组中获取最大值 |
||||
|
* @return |
||||
|
*/ |
||||
|
protected abstract BigDecimal getMaxFromSourceArray(); |
||||
|
|
||||
|
/** |
||||
|
* 从源数组中获取最小值 |
||||
|
* @return |
||||
|
*/ |
||||
|
protected abstract BigDecimal getMinFromSourceArray(); |
||||
|
|
||||
|
/** |
||||
|
* 将值转化为BigDecimal |
||||
|
* @param sourceValue |
||||
|
* @return |
||||
|
*/ |
||||
|
protected abstract BigDecimal convertValue2BigDecimal(T sourceValue); |
||||
|
|
||||
|
} |
Loading…
Reference in new issue