Commit 6f24a6d1 by zhangkb

新增指标评分卡目录接口和单位评分规则目录接口

parent bd88399b
......@@ -11,8 +11,9 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.keymobile.indicators.model.entity.scorecard.IndScorecard;
import com.keymobile.indicators.model.entity.scorecard.ScorecardCatalog;
import com.keymobile.indicators.service.hytobacco.IndScorecardService;
import com.keymobile.indicators.service.hytobacco.ScoreRuleService;
import com.keymobile.indicators.service.hytobacco.ScorecardCatalogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -24,7 +25,27 @@ public class IndScorecardCtrl {
@Autowired
private IndScorecardService indScorecardService;
@Autowired
private ScoreRuleService scoreRuleService;
private ScorecardCatalogService scorecardCatalogService;
@ApiOperation(value = "新增/修改评分卡目录", notes = "新增/修改评分卡目录")
@PostMapping(value = "/saveOrUpdateCatalog")
public String saveOrUpdateCatalog(@RequestBody ScorecardCatalog scorecardCatalog)throws Exception{
scorecardCatalog = scorecardCatalogService.saveOrUpdate(scorecardCatalog);
return scorecardCatalog.getId();
}
@ApiOperation(value = "批量级联删除评分卡目录", notes = "批量级联删除评分卡目录")
@PostMapping(value = "/deleteCatalog")
public void deleteCatalog(@RequestParam List<String> ids) throws Exception{
scorecardCatalogService.recursionDelete(ids);
}
@ApiOperation(value = "获取评分卡目录", notes = "获取评分卡目录")
@PostMapping(value = "/getCatalog")
public List<ScorecardCatalog> getCatalog(@RequestParam(required=false) String parentId,
@RequestParam List<String> codes){
return scorecardCatalogService.getCatalog(parentId, codes);
}
@ApiOperation(value = "新增/修改", notes = "新增/修改")
@PostMapping(value = "/saveOrUpdate")
......@@ -44,6 +65,12 @@ public class IndScorecardCtrl {
return indScorecardService.getAll();
}
@ApiOperation(value = "根据评分卡目录获取评分卡", notes = "根据评分卡目录获取评分卡")
@PostMapping(value = "/getByCatalogId")
public List<IndScorecard> getByCatalogId(@RequestParam String catalogId){
return indScorecardService.getByCatalogId(catalogId);
}
@ApiOperation(value = "根据id获取评分卡", notes = "根据id获取评分卡")
@PostMapping(value = "/findById")
public IndScorecard findById(@RequestParam String id) {
......@@ -58,13 +85,4 @@ public class IndScorecardCtrl {
return indScorecardService.calculateIndiScore(indId, date, compareObj,
indScorecardId,compareId,compareObjs);
}
@ApiOperation(value = "根据单位评分规则计算单位评分", notes = "根据单位评分规则计算单位评分")
@PostMapping(value = "/calculateObjectScore")
public List<Map<String,String>> calculateObjectScore(@RequestParam String reportId,
@RequestParam String compareId,@RequestParam List<String> indIds,
@RequestParam List<String> compareObjs,@RequestParam int date,
@RequestParam String scoreRuleId){
return scoreRuleService.calObjScore(reportId, compareId, indIds, compareObjs, date, scoreRuleId);
};
}
package com.keymobile.indicators.api.hytobacco;
import java.util.List;
import java.util.Map;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.keymobile.indicators.model.entity.objscorerule.ScoreRule;
import com.keymobile.indicators.model.entity.objscorerule.ScoreRuleCatalog;
import com.keymobile.indicators.service.hytobacco.ScoreRuleCatalogService;
import com.keymobile.indicators.service.hytobacco.ScoreRuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@Api(tags={"单位评分规则CRUD"})
@RestController
@RequestMapping(value = "/objScoreRule")
public class ObjScoreRuleCtrl {
@Autowired
private ScoreRuleService scoreRuleService;
@Autowired
private ScoreRuleCatalogService scoreRuleCatalogService;
@ApiOperation(value = "新增/修改单位规则目录", notes = "新增/修改单位规则目录")
@PostMapping(value = "/saveOrUpdateCatalog")
public String saveOrUpdateCatalog(@RequestBody ScoreRuleCatalog scoreRuleCatalog)throws Exception{
scoreRuleCatalog = scoreRuleCatalogService.saveOrUpdate(scoreRuleCatalog);
return scoreRuleCatalog.getId();
}
@ApiOperation(value = "批量级联删除单位规则目录", notes = "批量级联删除单位规则目录")
@PostMapping(value = "/deleteCatalog")
public void deleteCatalog(@RequestParam List<String> ids) throws Exception{
scoreRuleCatalogService.recursionDelete(ids);
}
@ApiOperation(value = "获取单位规则目录", notes = "获取单位规则目录")
@PostMapping(value = "/getCatalog")
public List<ScoreRuleCatalog> getCatalog(@RequestParam(required=false) String parentId,
@RequestParam List<String> codes){
return scoreRuleCatalogService.getCatalog(parentId, codes);
}
@ApiOperation(value = "新增/修改", notes = "新增/修改")
@PostMapping(value = "/saveOrUpdate")
public String saveOrUpdate(@RequestBody ScoreRule scoreRule) {
return scoreRuleService.save(scoreRule);
}
@ApiOperation(value = "删除", notes = "删除")
@PostMapping(value = "/delete")
public void delete(@RequestParam String id) {
scoreRuleService.delete(id);
}
@ApiOperation(value = "根据单位评分规则目录获取单位评分规则", notes = "根据单位评分规则目录获取单位评分规则")
@PostMapping(value = "/getByCatalogId")
public List<ScoreRule> getByCatalogId(@RequestParam String catalogId){
return scoreRuleService.getByCatalogId(catalogId);
}
@ApiOperation(value = "根据id获取单位评分规则", notes = "根据id获取单位评分规则")
@PostMapping(value = "/findById")
public ScoreRule findById(@RequestParam String id) {
return scoreRuleService.getById(id);
}
@ApiOperation(value = "根据单位评分规则计算单位评分", notes = "根据单位评分规则计算单位评分")
@PostMapping(value = "/calculateObjectScore")
public List<Map<String,String>> calculateObjectScore(@RequestParam String reportId,
@RequestParam String compareId,@RequestParam List<String> indIds,
@RequestParam List<String> compareObjs,@RequestParam int date,
@RequestParam String scoreRuleId){
return scoreRuleService.calObjScore(reportId, compareId, indIds, compareObjs, date, scoreRuleId);
}
}
......@@ -28,6 +28,8 @@ public class ScoreRule implements Serializable{
private List<IndTypeWeight> indTypeWeights = new ArrayList<>();//目录类别权重数据
private String calFormula;//当计算类型是2单个指标权重计算的时候,需要给出指标权重计算公式
private String calFormulaDesc;//单个指标权重计算公式描述
private String catalogId;//单位得分计算目录id
private String catalogIdPath;//单位得分计算目录idPath
private String code;//标识编码
public List<IndTypeWeight> getIndTypeWeights(){
......
package com.keymobile.indicators.model.entity.objscorerule;
import java.io.Serializable;
import java.util.Date;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import com.keymobile.indicators.utils.DateUtils;
import lombok.Data;
/**
*author:zhangkb time:2020-6-9 desc:单位评分规则目录实体
*/
@Data
@Document(collection="obj_score_rule_catalog")
public class ScoreRuleCatalog implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
private String id;
private String catalogName;
private String catalogType;
private String parentId;//顶层节点parentId为0
private String idPath;
private String code;//目录编码
private String lastUpdater;
private String lastUpdateTime = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
}
......@@ -43,6 +43,9 @@ public class IndScorecard implements Serializable{
private double limitScore;//上限分数
private List<ImproveScoreDef> improveScoreItem = new ArrayList<>();//改善提升分数
private String catalogId;//评分卡目录id
private String catalogIdPath;//评分卡目录idPath
private String lastUpdateTime = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
private String lastUpdater;
......
package com.keymobile.indicators.model.entity.scorecard;
import java.io.Serializable;
import java.util.Date;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import com.keymobile.indicators.utils.DateUtils;
import lombok.Data;
/**
*author:zhangkb time:2020-6-9 desc:指标评分卡目录实体
*/
@Data
@Document(collection="score_card_catalog")
public class ScorecardCatalog implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
private String id;
private String catalogName;
private String catalogType;
private String parentId;//顶层节点parentId为0
private String idPath;
private String code;//目录编码
private String lastUpdater;
private String lastUpdateTime = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
}
package com.keymobile.indicators.persistence.hyindicators;
import java.util.List;
import org.springframework.data.mongodb.repository.MongoRepository;
import com.keymobile.indicators.model.entity.scorecard.IndScorecard;
public interface IndScorecardRepository extends MongoRepository<IndScorecard,String>{
public void deleteByCatalogIdIn(List<String> catalogIds);
public List<IndScorecard> findByCatalogId(String catalogId);
}
package com.keymobile.indicators.persistence.hyindicators;
import java.util.List;
import org.springframework.data.mongodb.repository.MongoRepository;
import com.keymobile.indicators.model.entity.objscorerule.ScoreRuleCatalog;
public interface ScoreRuleCatalogRepository extends MongoRepository<ScoreRuleCatalog,String>{
public void deleteByIdIn(List<String> ids);
public List<ScoreRuleCatalog> findByParentIdAndCodeInOrderByLastUpdateTimeDesc(String pid,List<String> codes);
public List<ScoreRuleCatalog> findByParentId(String pid);
}
......@@ -7,5 +7,9 @@ import org.springframework.data.mongodb.repository.MongoRepository;
import com.keymobile.indicators.model.entity.objscorerule.ScoreRule;
public interface ScoreRuleRepository extends MongoRepository<ScoreRule,String>{
List<ScoreRule> findByCode(String code);
public List<ScoreRule> findByCode(String code);
public void deleteByCatalogIdIn(List<String> ids);
public List<ScoreRule> findByCatalogId(String catalogId);
}
package com.keymobile.indicators.persistence.hyindicators;
import java.util.List;
import org.springframework.data.mongodb.repository.MongoRepository;
import com.keymobile.indicators.model.entity.scorecard.ScorecardCatalog;
public interface ScorecardCatalogRepository extends MongoRepository<ScorecardCatalog,String>{
public void deleteByIdIn(List<String> ids);
public List<ScorecardCatalog> findByParentIdAndCodeInOrderByLastUpdateTimeDesc(String pid,List<String> codes);
public List<ScorecardCatalog> findByParentId(String pid);
}
......@@ -60,6 +60,10 @@ public class IndScorecardService {
return null;
}
public List<IndScorecard> getByCatalogId(String catalogId){
return indScorecardRepo.findByCatalogId(catalogId);
}
public Map<String,String> calculateIndiScore(String indId,int date,String compareObj,
String indScorecardId,String compareId,List<String> compareObjs) throws Exception{
Map<String,String> result = new HashMap<>();
......
package com.keymobile.indicators.service.hytobacco;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
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.objscorerule.ScoreRuleCatalog;
import com.keymobile.indicators.persistence.hyindicators.ScoreRuleCatalogRepository;
import com.keymobile.indicators.persistence.hyindicators.ScoreRuleRepository;
@Service
public class ScoreRuleCatalogService {
private Logger logger = LoggerFactory.getLogger(ScoreRuleCatalogService.class);
@Autowired
private ScoreRuleCatalogRepository scoreRuleCatalogRepo;
@Autowired
private ScoreRuleRepository scoreRuleRepo;
public ScoreRuleCatalog saveOrUpdate(ScoreRuleCatalog scoreRuleCatalog) throws Exception{
if(StringUtils.isBlank(scoreRuleCatalog.getId())) {//新增
//保存
scoreRuleCatalog = scoreRuleCatalogRepo.save(scoreRuleCatalog);
}
//获取parentId拼接idPath
String parentId = scoreRuleCatalog.getParentId();
if(StringUtils.isBlank(parentId) || "0".equals(parentId)) {//顶层节点
scoreRuleCatalog.setIdPath(scoreRuleCatalog.getId());
}else {
Optional<ScoreRuleCatalog> parentScoreRuleCatalog = scoreRuleCatalogRepo.
findById(scoreRuleCatalog.getParentId());
if(!parentScoreRuleCatalog.isPresent()) {
throw new Exception("父节点不存在:parent catalog is not exist");
}else {
scoreRuleCatalog.setIdPath(parentScoreRuleCatalog.get().getIdPath()+";"+scoreRuleCatalog.getId());
}
}
//保存
scoreRuleCatalog = scoreRuleCatalogRepo.save(scoreRuleCatalog);
return scoreRuleCatalog;
}
public void delete(List<String> ids) {
scoreRuleCatalogRepo.deleteByIdIn(ids);
}
//递归查找父目录下的子目录
public List<String> getDeleteCatalogId(String id){
List<String> result = new ArrayList<>();
result.add(id);
//根据id获取子节点
List<ScoreRuleCatalog> children = scoreRuleCatalogRepo.findByParentId(id);
if(!children.isEmpty()) {
for(ScoreRuleCatalog child : children) {
result.addAll(getDeleteCatalogId(child.getId()));
}
}
return result;
}
//递归删除
public void recursionDelete(List<String> ids) {
for(String id : ids) {
List<String> result = this.getDeleteCatalogId(id);
this.delete(result);
//删除目录关联的单位评分规则
scoreRuleRepo.deleteByCatalogIdIn(result);
}
}
//获取目录树
public List<ScoreRuleCatalog> getCatalog(String parentId,List<String> codes){
if(StringUtils.isBlank(parentId) || "0".equals(parentId)) {
return scoreRuleCatalogRepo.findByParentIdAndCodeInOrderByLastUpdateTimeDesc("0", codes);
}
return scoreRuleCatalogRepo.findByParentIdAndCodeInOrderByLastUpdateTimeDesc(parentId, codes);
}
}
......@@ -50,6 +50,10 @@ public class ScoreRuleService {
return scoreRuleRepo.findByCode(code);
}
public List<ScoreRule> getByCatalogId(String catalogId){
return scoreRuleRepo.findByCatalogId(catalogId);
}
public ScoreRule getById(String id) {
Optional<ScoreRule> scoreRule = scoreRuleRepo.findById(id);
if(scoreRule.isPresent()) {
......@@ -77,7 +81,8 @@ public class ScoreRuleService {
DriveIndDef driveIndDef = driveIndDefMapper.selectByPrimaryKey(calResult.getIndId());
if(driveIndDef!=null) {
//如果考核指标是参与单位计分的
if("1".equals(driveIndDef.getIsUnitCalScore())) {
if(StringUtils.isBlank(driveIndDef.getIsUnitCalScore()) ||
"1".equals(driveIndDef.getIsUnitCalScore())) {
//得分类型:0 指标值直接参与计算
if("0".equals(scoreRule.getScoreType())) {
values.add(calResult.getValue());
......@@ -219,7 +224,8 @@ public class ScoreRuleService {
DriveIndDef driveIndDef = driveIndDefMapper.selectByPrimaryKey(calResult.getIndId());
if(driveIndDef!=null) {
//如果考核指标是参与单位计分的
if("1".equals(driveIndDef.getIsUnitCalScore())) {
if(StringUtils.isBlank(driveIndDef.getIsUnitCalScore()) ||
"1".equals(driveIndDef.getIsUnitCalScore())) {
//如果指标是该指标分类下的
if(indTypeWeight.getCatalogIdPath().indexOf(catalogIdPath)>=0) {
//得分类型:0 指标值直接参与计算
......
package com.keymobile.indicators.service.hytobacco;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
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.scorecard.ScorecardCatalog;
import com.keymobile.indicators.persistence.hyindicators.IndScorecardRepository;
import com.keymobile.indicators.persistence.hyindicators.ScorecardCatalogRepository;
@Service
public class ScorecardCatalogService {
private Logger logger = LoggerFactory.getLogger(ScorecardCatalogService.class);
@Autowired
private ScorecardCatalogRepository scorecardCatalogRepo;
@Autowired
private IndScorecardRepository indScorecardRepo;
public ScorecardCatalog saveOrUpdate(ScorecardCatalog scorecardCatalog) throws Exception{
if(StringUtils.isBlank(scorecardCatalog.getId())) {//新增
//保存
scorecardCatalog = scorecardCatalogRepo.save(scorecardCatalog);
}
//获取parentId拼接idPath
String parentId = scorecardCatalog.getParentId();
if(StringUtils.isBlank(parentId) || "0".equals(parentId)) {//顶层节点
scorecardCatalog.setIdPath(scorecardCatalog.getId());
}else {
Optional<ScorecardCatalog> parentScorecardCatalog = scorecardCatalogRepo.
findById(scorecardCatalog.getParentId());
if(!parentScorecardCatalog.isPresent()) {
throw new Exception("父节点不存在:parent catalog is not exist");
}else {
scorecardCatalog.setIdPath(parentScorecardCatalog.get().getIdPath()+";"+scorecardCatalog.getId());
}
}
//保存
scorecardCatalog = scorecardCatalogRepo.save(scorecardCatalog);
return scorecardCatalog;
}
public void delete(List<String> ids) {
scorecardCatalogRepo.deleteByIdIn(ids);
}
//递归查找父目录下的子目录
public List<String> getDeleteCatalogId(String id){
List<String> result = new ArrayList<>();
result.add(id);
//根据id获取子节点
List<ScorecardCatalog> children = scorecardCatalogRepo.findByParentId(id);
if(!children.isEmpty()) {
for(ScorecardCatalog child : children) {
result.addAll(getDeleteCatalogId(child.getId()));
}
}
return result;
}
//递归删除
public void recursionDelete(List<String> ids) {
for(String id : ids) {
List<String> result = this.getDeleteCatalogId(id);
this.delete(result);
//删除目录关联的评分卡
indScorecardRepo.deleteByCatalogIdIn(result);
}
}
//获取目录树
public List<ScorecardCatalog> getCatalog(String parentId,List<String> codes){
if(StringUtils.isBlank(parentId) || "0".equals(parentId)) {
return scorecardCatalogRepo.findByParentIdAndCodeInOrderByLastUpdateTimeDesc("0", codes);
}
return scorecardCatalogRepo.findByParentIdAndCodeInOrderByLastUpdateTimeDesc(parentId, codes);
}
}
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