Commit c9b14481 by zhangkb

提交获取指标评分规则,单位计分规则和短板筛选规则分页接口

parent 91d82021
......@@ -4,6 +4,7 @@ import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -68,8 +69,10 @@ public class IndScorecardCtrl {
@ApiOperation(value = "根据评分卡目录获取评分卡", notes = "根据评分卡目录获取评分卡")
@PostMapping(value = "/getByCatalogId")
public List<IndScorecard> getByCatalogId(@RequestParam String catalogId){
return indScorecardService.getByCatalogId(catalogId);
public Page<IndScorecard> getByCatalogId(@RequestParam String catalogId,
@RequestParam(value = "page", required = false, defaultValue = "1") int page,
@RequestParam(value = "rows", required = false, defaultValue = "10") int rows){
return indScorecardService.getByCatalogId(catalogId,page,rows);
}
@ApiOperation(value = "根据id获取评分卡", notes = "根据id获取评分卡")
......
......@@ -4,6 +4,7 @@ import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -62,8 +63,10 @@ public class ObjScoreRuleCtrl {
@ApiOperation(value = "根据单位评分规则目录获取单位评分规则", notes = "根据单位评分规则目录获取单位评分规则")
@PostMapping(value = "/getByCatalogId")
public List<ScoreRule> getByCatalogId(@RequestParam String catalogId){
return scoreRuleService.getByCatalogId(catalogId);
public Page<ScoreRule> getByCatalogId(@RequestParam String catalogId,
@RequestParam(value = "page", required = false, defaultValue = "1") int page,
@RequestParam(value = "rows", required = false, defaultValue = "10") int rows){
return scoreRuleService.getByCatalogId(catalogId,page,rows);
}
@ApiOperation(value = "根据id获取单位评分规则", notes = "根据id获取单位评分规则")
......
package com.keymobile.indicators.model.entity.shortboard;
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-10 desc:短板筛选规则目录实体
*/
@Data
@Document(collection="ind_short_board_catalog")
public class ShortboardCatalog 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.model.entity.shortboard;
import java.io.Serializable;
import lombok.Data;
/**
* author:zhangkb time:2020-6-10 desc:短板筛选规则选项
*/
@Data
public class ShortboardItem implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private String calType;//0:大于 1:小于
private String type;//0:均值 1:最大值 2:最小值 3:排名 4:历史同期
private String name;
private String value;
private String analysisType;//分析类型 0:绝对值 1:百分比
}
package com.keymobile.indicators.model.entity.shortboard;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
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-10 desc:短板筛选规则实体
*/
@Data
@Document(collection="short_board_rule")
public class ShortboardRule implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
private String id;
private String ruleName;//规则名称
private String ruleDesc;//规则描述
private List<ShortboardItem> shortboardItem = new ArrayList<>();//短板规则选项
private String code;//编码
private String catalogId;
private String catalogIdPath;
private String lastUpdateTime = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
private String lastUpdater;
public List<ShortboardItem> getShortboardItem(){
return shortboardItem;
}
public void setShortboardItem(List<ShortboardItem> shortboardItem){
this.shortboardItem.addAll(shortboardItem);
}
}
......@@ -2,6 +2,8 @@ package com.keymobile.indicators.persistence.hyindicators;
import java.util.List;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
import com.keymobile.indicators.model.entity.scorecard.IndScorecard;
......@@ -9,5 +11,5 @@ 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);
public Page<IndScorecard> findByCatalogId(String catalogId,Pageable page);
}
......@@ -2,6 +2,8 @@ package com.keymobile.indicators.persistence.hyindicators;
import java.util.List;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
import com.keymobile.indicators.model.entity.objscorerule.ScoreRule;
......@@ -11,5 +13,5 @@ public interface ScoreRuleRepository extends MongoRepository<ScoreRule,String>{
public void deleteByCatalogIdIn(List<String> ids);
public List<ScoreRule> findByCatalogId(String catalogId);
public Page<ScoreRule> findByCatalogId(String catalogId,Pageable page);
}
package com.keymobile.indicators.persistence.hyindicators;
import java.util.List;
import org.springframework.data.mongodb.repository.MongoRepository;
import com.keymobile.indicators.model.entity.shortboard.ShortboardCatalog;
public interface ShortboardCatalogRepository extends MongoRepository<ShortboardCatalog,String>{
public void deleteByIdIn(List<String> ids);
public List<ShortboardCatalog> findByParentIdAndCodeInOrderByLastUpdateTimeDesc(String pid,List<String> codes);
public List<ShortboardCatalog> findByParentId(String pid);
}
package com.keymobile.indicators.persistence.hyindicators;
import java.util.List;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
import com.keymobile.indicators.model.entity.shortboard.ShortboardRule;
public interface ShortboardRuleRepository extends MongoRepository<ShortboardRule,String>{
public void deleteByCatalogIdIn(List<String> ids);
public Page<ShortboardRule> findByCatalogId(String catalogId,Pageable page);
}
......@@ -11,6 +11,9 @@ import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
......@@ -64,8 +67,9 @@ public class IndScorecardService {
return null;
}
public List<IndScorecard> getByCatalogId(String catalogId){
return indScorecardRepo.findByCatalogId(catalogId);
public Page<IndScorecard> getByCatalogId(String catalogId,int page,int rows){
Pageable pageable = PageRequest.of(page - 1, rows);
return indScorecardRepo.findByCatalogId(catalogId,pageable);
}
public Map<String,String> calculateIndiScore(String indId,int date,String compareObj,
......
......@@ -12,6 +12,9 @@ import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import com.googlecode.aviator.AviatorEvaluator;
......@@ -53,8 +56,9 @@ public class ScoreRuleService {
return scoreRuleRepo.findByCode(code);
}
public List<ScoreRule> getByCatalogId(String catalogId){
return scoreRuleRepo.findByCatalogId(catalogId);
public Page<ScoreRule> getByCatalogId(String catalogId,int page,int rows){
Pageable pageable = PageRequest.of(page - 1, rows);
return scoreRuleRepo.findByCatalogId(catalogId,pageable);
}
public ScoreRule getById(String id) {
......
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.shortboard.ShortboardCatalog;
import com.keymobile.indicators.persistence.hyindicators.ShortboardCatalogRepository;
import com.keymobile.indicators.persistence.hyindicators.ShortboardRuleRepository;
@Service
public class ShortboardCatalogService {
private Logger logger = LoggerFactory.getLogger(ShortboardCatalogService.class);
@Autowired
private ShortboardCatalogRepository shortboardCatalogRepo;
@Autowired
private ShortboardRuleRepository shortboardRuleRepo;
public ShortboardCatalog saveOrUpdate(ShortboardCatalog shortboardCatalog) throws Exception{
if(StringUtils.isBlank(shortboardCatalog.getId())) {//新增
//保存
shortboardCatalog = shortboardCatalogRepo.save(shortboardCatalog);
}
//获取parentId拼接idPath
String parentId = shortboardCatalog.getParentId();
if(StringUtils.isBlank(parentId) || "0".equals(parentId)) {//顶层节点
shortboardCatalog.setIdPath(shortboardCatalog.getId());
}else {
Optional<ShortboardCatalog> parentShortboardCatalog = shortboardCatalogRepo.
findById(shortboardCatalog.getParentId());
if(!parentShortboardCatalog.isPresent()) {
throw new Exception("父节点不存在:parent catalog is not exist");
}else {
shortboardCatalog.setIdPath(parentShortboardCatalog.get().getIdPath()+";"+shortboardCatalog.getId());
}
}
//保存
shortboardCatalog = shortboardCatalogRepo.save(shortboardCatalog);
return shortboardCatalog;
}
public void delete(List<String> ids) {
shortboardCatalogRepo.deleteByIdIn(ids);
}
//递归查找父目录下的子目录
public List<String> getDeleteCatalogId(String id){
List<String> result = new ArrayList<>();
result.add(id);
//根据id获取子节点
List<ShortboardCatalog> children = shortboardCatalogRepo.findByParentId(id);
if(!children.isEmpty()) {
for(ShortboardCatalog 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);
//删除目录关联的短板筛选规则
shortboardRuleRepo.deleteByCatalogIdIn(result);
}
}
//获取目录树
public List<ShortboardCatalog> getCatalog(String parentId,List<String> codes){
if(StringUtils.isBlank(parentId) || "0".equals(parentId)) {
return shortboardCatalogRepo.findByParentIdAndCodeInOrderByLastUpdateTimeDesc("0", codes);
}
return shortboardCatalogRepo.findByParentIdAndCodeInOrderByLastUpdateTimeDesc(parentId, codes);
}
}
package com.keymobile.indicators.service.hytobacco;
import java.util.List;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import com.keymobile.indicators.model.entity.shortboard.ShortboardRule;
import com.keymobile.indicators.persistence.hyindicators.ShortboardRuleRepository;
@Service
public class ShortboardRuleService {
private Logger logger = LoggerFactory.getLogger(ShortboardRuleService.class);
@Autowired
private ShortboardRuleRepository shortboardRuleRepo;
public String saveOrUpdate(ShortboardRule shortboardRule,String catalogId,
String catalogIdPath,String user) {
shortboardRule.setCatalogId(catalogId);
shortboardRule.setCatalogIdPath(catalogIdPath);
shortboardRule.setLastUpdater(user);
shortboardRule = shortboardRuleRepo.save(shortboardRule);
return shortboardRule.getId();
}
public void delete(String id) {
shortboardRuleRepo.deleteById(id);
}
public Page<ShortboardRule> getByCatalogId(String catalogId,int page,int rows){
Pageable pageable = PageRequest.of(page - 1, rows);
return shortboardRuleRepo.findByCatalogId(catalogId,pageable);
}
public ShortboardRule getById(String id) {
Optional<ShortboardRule> shortboardRule = shortboardRuleRepo.findById(id);
if(shortboardRule.isPresent()) {
return shortboardRule.get();
}
return null;
}
}
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