Commit 92a0ee43 by zhangkb

将单位评分规则数据转移到mysql

parent 201c94f9
......@@ -4,7 +4,6 @@ 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;
......@@ -30,40 +29,40 @@ public class ObjScoreRuleCtrl {
@ApiOperation(value = "新增/修改单位规则目录", notes = "新增/修改单位规则目录")
@PostMapping(value = "/saveOrUpdateCatalog")
public String saveOrUpdateCatalog(@RequestBody ScoreRuleCatalog scoreRuleCatalog)throws Exception{
public Integer 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{
public void deleteCatalog(@RequestParam List<Integer> ids) throws Exception{
scoreRuleCatalogService.recursionDelete(ids);
}
@ApiOperation(value = "获取单位规则目录", notes = "获取单位规则目录")
@PostMapping(value = "/getCatalog")
public List<ScoreRuleCatalog> getCatalog(@RequestParam(required=false) String parentId,
public List<ScoreRuleCatalog> getCatalog(@RequestParam(required=false) Integer parentId,
@RequestParam List<String> codes){
return scoreRuleCatalogService.getCatalog(parentId, codes);
}
@ApiOperation(value = "新增/修改", notes = "新增/修改")
@PostMapping(value = "/saveOrUpdate")
public String saveOrUpdate(@RequestBody ScoreRule scoreRule,@RequestParam String catalogId,
public Integer saveOrUpdate(@RequestBody ScoreRule scoreRule,@RequestParam Integer catalogId,
@RequestParam String catalogIdPath,@RequestParam String user) {
return scoreRuleService.saveOrUpdate(scoreRule,catalogId,catalogIdPath,user);
}
@ApiOperation(value = "删除", notes = "删除")
@PostMapping(value = "/delete")
public void delete(@RequestParam String id) {
public void delete(@RequestParam Integer id) {
scoreRuleService.delete(id);
}
@ApiOperation(value = "根据单位评分规则目录获取单位评分规则", notes = "根据单位评分规则目录获取单位评分规则")
@PostMapping(value = "/getByCatalogId")
public Page<ScoreRule> getByCatalogId(@RequestParam String catalogId,
public Map<String,Object> getByCatalogId(@RequestParam Integer 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);
......@@ -71,7 +70,7 @@ public class ObjScoreRuleCtrl {
@ApiOperation(value = "根据id获取单位评分规则", notes = "根据id获取单位评分规则")
@PostMapping(value = "/findById")
public ScoreRule findById(@RequestParam String id) {
public ScoreRule findById(@RequestParam Integer id) {
return scoreRuleService.getById(id);
}
......@@ -80,7 +79,7 @@ public class ObjScoreRuleCtrl {
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){
@RequestParam Integer 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.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -29,40 +29,40 @@ public class ShortboardRuleCtrl {
@ApiOperation(value = "新增/修改短板筛选规则目录", notes = "新增/修改短板筛选规则目录")
@PostMapping(value = "/saveOrUpdateCatalog")
public String saveOrUpdateCatalog(@RequestBody ShortboardCatalog shortboardCatalog)throws Exception{
public Integer saveOrUpdateCatalog(@RequestBody ShortboardCatalog shortboardCatalog)throws Exception{
shortboardCatalog = shortboardCatalogService.saveOrUpdate(shortboardCatalog);
return shortboardCatalog.getId();
}
@ApiOperation(value = "批量级联删除短板筛选规则目录", notes = "批量级联删除短板筛选规则目录")
@PostMapping(value = "/deleteCatalog")
public void deleteCatalog(@RequestParam List<String> ids) throws Exception{
public void deleteCatalog(@RequestParam List<Integer> ids) throws Exception{
shortboardCatalogService.recursionDelete(ids);
}
@ApiOperation(value = "获取短板筛选规则目录", notes = "获取短板筛选规则目录")
@PostMapping(value = "/getCatalog")
public List<ShortboardCatalog> getCatalog(@RequestParam(required=false) String parentId,
public List<ShortboardCatalog> getCatalog(@RequestParam(required=false) Integer parentId,
@RequestParam List<String> codes){
return shortboardCatalogService.getCatalog(parentId, codes);
}
@ApiOperation(value = "新增/修改", notes = "新增/修改")
@PostMapping(value = "/saveOrUpdate")
public String saveOrUpdate(@RequestBody ShortboardRule shortboardRule,@RequestParam String catalogId,
public Integer saveOrUpdate(@RequestBody ShortboardRule shortboardRule,@RequestParam Integer catalogId,
@RequestParam String catalogIdPath,@RequestParam String user) {
return shortboardRuleService.saveOrUpdate(shortboardRule,catalogId,catalogIdPath,user);
}
@ApiOperation(value = "删除", notes = "删除")
@PostMapping(value = "/delete")
public void delete(@RequestParam String id) {
public void delete(@RequestParam Integer id) {
shortboardRuleService.delete(id);
}
@ApiOperation(value = "根据短板筛选规则目录获取短板筛选规则", notes = "根据短板筛选规则目录获取短板筛选规则")
@PostMapping(value = "/getByCatalogId")
public Page<ShortboardRule> getByCatalogId(@RequestParam String catalogId,
public Map<String,Object> getByCatalogId(@RequestParam Integer catalogId,
@RequestParam(value = "page", required = false, defaultValue = "1") int page,
@RequestParam(value = "rows", required = false, defaultValue = "10") int rows){
return shortboardRuleService.getByCatalogId(catalogId,page,rows);
......@@ -70,7 +70,7 @@ public class ShortboardRuleCtrl {
@ApiOperation(value = "根据id获取短板筛选规则", notes = "根据id获取短板筛选规则")
@PostMapping(value = "/findById")
public ShortboardRule findById(@RequestParam String id) {
public ShortboardRule findById(@RequestParam Integer id) {
return shortboardRuleService.getById(id);
}
}
package com.keymobile.indicators.model.entity.objscorerule;
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 javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import com.keymobile.indicators.utils.DateUtils;
import lombok.Data;
......@@ -16,34 +16,26 @@ import lombok.Data;
*author:zhangkb time:2020-6-2 desc:单位评分规则实体
*/
@Data
@Document(collection="obj_score_rule")
public class ScoreRule implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Table(name ="obj_score_rule")
public class ScoreRule {
@Id
private String id;
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String ruleName;//规则名称
private String scoreType;//得分类型:0 指标值直接参与计算 1 指标得分分数参与计算(综合评分和改善提升分开算) 2指标得分分数参与计算(指标分数=综合+改善)
private String calType;//计算类型:0 计算组内所有考核指标平均数 1 根据目录类别分类算平均分后根据权重计算考核指标 2单个指标权重计算
private String indTypeWeightsJson;
private List<IndTypeWeight> indTypeWeights = new ArrayList<>();//目录类别权重数据
private String calFormula;//当计算类型是2单个指标权重计算的时候,需要给出指标权重计算公式
private String calFormulaDesc;//单个指标权重计算公式描述
private String catalogId;//单位得分计算目录id
private Integer catalogId;//单位得分计算目录id
private String catalogIdPath;//单位得分计算目录idPath
private String code;//标识编码
private String desc;//规则描述
private String scoreRuleDesc;//规则描述
private String lastUpdateTime = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
private String lastUpdater;
public List<IndTypeWeight> getIndTypeWeights(){
return indTypeWeights;
}
public void setIndTypeWeights(List<IndTypeWeight> indTypeWeights){
this.indTypeWeights.addAll(indTypeWeights);
}
}
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 javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import com.keymobile.indicators.utils.DateUtils;
import lombok.Data;
......@@ -14,18 +14,14 @@ 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;
@Table(name="obj_score_rule_catalog")
public class ScoreRuleCatalog{
@Id
private String id;
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String catalogName;
private String catalogType;
private String parentId;//顶层节点parentId为0
private Integer parentId;//顶层节点parentId为0
private String idPath;
private String code;//目录编码
private String lastUpdater;
......
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 javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import com.keymobile.indicators.utils.DateUtils;
import lombok.Data;
......@@ -14,18 +14,15 @@ 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;
@Table(name ="ind_short_board_catalog")
public class ShortboardCatalog{
@Id
private String id;
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String catalogName;
private String catalogType;
private String parentId;//顶层节点parentId为0
private Integer parentId;//顶层节点parentId为0
private String idPath;
private String code;//目录编码
private String lastUpdater;
......
package com.keymobile.indicators.model.entity.shortboard;
import java.io.Serializable;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.Data;
......@@ -11,19 +11,16 @@ import lombok.Data;
* author:zhangkb time:2020-6-11 desc:新增短板筛选规则和考核指标关系中间表
*/
@Data
@Document(collection="short_board_drive_ind_rel")
public class ShortboardDriveIndRel implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Table(name ="short_board_drive_ind_rel")
public class ShortboardDriveIndRel{
@Id
private String id;
private String shortboardRuleId;//短板规则id
private String driveIndDefId;//考核指标id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private Integer shortboardRuleId;//短板规则id
private Integer driveIndDefId;//考核指标id
public ShortboardDriveIndRel(String driveIndDefId,String shortboardRuleId) {
public ShortboardDriveIndRel(Integer driveIndDefId,Integer shortboardRuleId) {
this.driveIndDefId = driveIndDefId;
this.shortboardRuleId = shortboardRuleId;
}
......
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 javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import com.keymobile.indicators.utils.DateUtils;
......@@ -16,30 +17,22 @@ 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;
@Table(name ="short_board_rule")
public class ShortboardRule{
@Id
private String id;
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String ruleName;//规则名称
private String ruleDesc;//规则描述
private String shortboardItemJson;
private List<ShortboardItem> shortboardItem = new ArrayList<>();//短板规则选项
private String code;//编码
private String catalogId;
private Integer 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);
}
}
package com.keymobile.indicators.model.mapper.indmapper;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Mapper;
import com.keymobile.indicators.model.entity.objscorerule.ScoreRuleCatalog;
import feign.Param;
import tk.mybatis.mapper.common.BaseMapper;
@Mapper
public interface ScoreRuleCatalogMapper extends BaseMapper<ScoreRuleCatalog>{
public void deleteByIdIn(List<Integer> ids);
public List<ScoreRuleCatalog> findByParentIdAndCodeInOrderByLastUpdateTimeDesc(Map<String,Object> params);
public List<ScoreRuleCatalog> findByParentId(@Param("pid") Integer pid);
}
package com.keymobile.indicators.model.mapper.indmapper;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import com.keymobile.indicators.model.entity.objscorerule.ScoreRule;
import feign.Param;
import tk.mybatis.mapper.common.BaseMapper;
@Mapper
public interface ScoreRuleMapper extends BaseMapper<ScoreRule>{
public List<ScoreRule> findByCode(@Param("code")String code);
public void deleteByCatalogIdIn(List<Integer> ids);
public List<ScoreRule> findByCatalogId(@Param("catalogId")Integer catalogId,
@Param("start") int start,@Param("end") int end);
public int countByCatalogId(@Param("catalogId")Integer catalogId);
}
package com.keymobile.indicators.model.mapper.indmapper;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Mapper;
import com.keymobile.indicators.model.entity.shortboard.ShortboardCatalog;
import feign.Param;
import tk.mybatis.mapper.common.BaseMapper;
@Mapper
public interface ShortboardCatalogMapper extends BaseMapper<ShortboardCatalog>{
public void deleteByIdIn(List<Integer> ids);
public List<ShortboardCatalog> findByParentIdAndCodeInOrderByLastUpdateTimeDesc(Map<String,Object> params);
public List<ShortboardCatalog> findByParentId(@Param("pid") Integer pid);
}
package com.keymobile.indicators.model.mapper.indmapper;
import java.util.List;
import com.keymobile.indicators.model.entity.shortboard.ShortboardDriveIndRel;
import feign.Param;
import tk.mybatis.mapper.common.BaseMapper;
public interface ShortboardDriveIndRelMapper extends BaseMapper<ShortboardDriveIndRel>{
List<ShortboardDriveIndRel> findByDriveIndDefId(@Param("driveIndDefId")String driveIndDefId);
}
package com.keymobile.indicators.model.mapper.indmapper;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import com.keymobile.indicators.model.entity.shortboard.ShortboardRule;
import feign.Param;
import tk.mybatis.mapper.common.BaseMapper;
@Mapper
public interface ShortboardRuleMapper extends BaseMapper<ShortboardRule>{
public void deleteByCatalogIdIn(List<Integer> ids);
public List<ShortboardRule> findByCatalogId(@Param("catalogId")Integer catalogId,
@Param("start") int start,@Param("end") int end);
public int countByCatalogId(@Param("catalogId")Integer 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);
}
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;
public interface ScoreRuleRepository extends MongoRepository<ScoreRule,String>{
public List<ScoreRule> findByCode(String code);
public void deleteByCatalogIdIn(List<String> ids);
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.mongodb.repository.MongoRepository;
import com.keymobile.indicators.model.entity.shortboard.ShortboardDriveIndRel;
public interface ShortboardDriveIndRelRepository extends MongoRepository<ShortboardDriveIndRel,String>{
List<ShortboardDriveIndRel> findByDriveIndDefId(String driveIndDefId);
}
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);
}
package com.keymobile.indicators.service.hytobacco;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
......@@ -14,6 +15,7 @@ import org.springframework.stereotype.Service;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.googlecode.aviator.AviatorEvaluator;
import com.keymobile.indicators.model.entity.indicators.DriveIndCalResultDef;
import com.keymobile.indicators.model.entity.indicators.DriveIndDef;
......@@ -91,6 +93,7 @@ public class IndScorecardService {
public Map<String,String> calculateIndiScore(String indId,int date,String compareObj,
Integer indScorecardId,String compareId,List<String> compareObjs) throws Exception{
Map<String,String> result = new HashMap<>();
Gson gson = new Gson();
String indScoreValue = "0.0";
String indImproveScoreValue = "0.0";
result.put("score",indScoreValue);
......@@ -155,8 +158,9 @@ public class IndScorecardService {
int rank = currentCompareObjResult.getRank();//获取排位
//加分项
if(!scoreCard.getAddScoreItem().isEmpty()) {
List<RankScoreDef> addScoreItem = scoreCard.getAddScoreItem();
if(StringUtils.isNotBlank(scoreCard.getAddScoreItemJson())) {
List<RankScoreDef> addScoreItem = gson.
fromJson(scoreCard.getAddScoreItemJson(), new TypeToken<List<RankScoreDef>>(){}.getType());
for(RankScoreDef scoreDef : addScoreItem) {
if(scoreDef.getRank()==rank) {
baseScoreValue += scoreDef.getScore();
......@@ -165,8 +169,9 @@ public class IndScorecardService {
}
}
//减分项
if(!scoreCard.getMinusScoreItem().isEmpty()) {
List<RankScoreDef> minusScoreItem = scoreCard.getMinusScoreItem();
if(StringUtils.isNotBlank(scoreCard.getMinusScoreItemJson())) {
List<RankScoreDef> minusScoreItem = gson.
fromJson(scoreCard.getMinusScoreItemJson(), new TypeToken<List<RankScoreDef>>(){}.getType());
rank = currentDriveResultSize-rank+1;
for(RankScoreDef scoreDef : minusScoreItem) {
if(scoreDef.getRank()==rank) {
......@@ -197,8 +202,14 @@ public class IndScorecardService {
DriveIndCalResultDef sameCompareObjResult = driveIndCalResultDefMapper
.findByIndIdAndDateAndCompareObj(indId, (date-100), compareObj);
if(sameCompareObjResult!=null) {
List<ImproveScoreDef> importScoreDefList = new ArrayList<>();
if(StringUtils.isNotBlank(scoreCard.getImproveScoreItemJson())) {
importScoreDefList = gson.
fromJson(scoreCard.getImproveScoreItemJson(),
new TypeToken<List<ImproveScoreDef>>(){}.getType());
}
double improveScore = this.calImproveValue(acsType, unit,
scoreCard.getImproveScoreItem(), currentCompareObjResult,
importScoreDefList, currentCompareObjResult,
sameCompareObjResult,compareObjs);
if(scoreCard.getLimitScore()!=0) {
if(improveScore>scoreCard.getLimitScore()) {
......
package com.keymobile.indicators.service.hytobacco;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import java.util.Map;
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;
import com.keymobile.indicators.model.mapper.indmapper.ScoreRuleCatalogMapper;
import com.keymobile.indicators.model.mapper.indmapper.ScoreRuleMapper;
@Service
public class ScoreRuleCatalogService {
private Logger logger = LoggerFactory.getLogger(ScoreRuleCatalogService.class);
@Autowired
private ScoreRuleCatalogRepository scoreRuleCatalogRepo;
private ScoreRuleCatalogMapper scoreRuleCatalogMapper;
@Autowired
private ScoreRuleRepository scoreRuleRepo;
private ScoreRuleMapper scoreRuleMapper;
public ScoreRuleCatalog saveOrUpdate(ScoreRuleCatalog scoreRuleCatalog) throws Exception{
if(StringUtils.isBlank(scoreRuleCatalog.getId())) {//新增
if(scoreRuleCatalog.getId()==null) {//新增
//保存
scoreRuleCatalog = scoreRuleCatalogRepo.save(scoreRuleCatalog);
scoreRuleCatalogMapper.insert(scoreRuleCatalog);
}
//获取parentId拼接idPath
String parentId = scoreRuleCatalog.getParentId();
if(StringUtils.isBlank(parentId) || "0".equals(parentId)) {//顶层节点
scoreRuleCatalog.setIdPath(scoreRuleCatalog.getId());
Integer parentId = scoreRuleCatalog.getParentId();
if(parentId==0) {//顶层节点
scoreRuleCatalog.setIdPath(String.valueOf(scoreRuleCatalog.getId()));
}else {
Optional<ScoreRuleCatalog> parentScoreRuleCatalog = scoreRuleCatalogRepo.
findById(scoreRuleCatalog.getParentId());
if(!parentScoreRuleCatalog.isPresent()) {
ScoreRuleCatalog parentScoreRuleCatalog = scoreRuleCatalogMapper.
selectByPrimaryKey(scoreRuleCatalog.getParentId());
if(parentScoreRuleCatalog==null) {
throw new Exception("父节点不存在:parent catalog is not exist");
}else {
scoreRuleCatalog.setIdPath(parentScoreRuleCatalog.get().getIdPath()+";"+scoreRuleCatalog.getId());
scoreRuleCatalog.setIdPath(parentScoreRuleCatalog.getIdPath()+";"+scoreRuleCatalog.getId());
}
}
//保存
scoreRuleCatalog = scoreRuleCatalogRepo.save(scoreRuleCatalog);
scoreRuleCatalogMapper.updateByPrimaryKey(scoreRuleCatalog);
return scoreRuleCatalog;
}
public void delete(List<String> ids) {
scoreRuleCatalogRepo.deleteByIdIn(ids);
public void delete(List<Integer> ids) {
scoreRuleCatalogMapper.deleteByIdIn(ids);
}
//递归查找父目录下的子目录
public List<String> getDeleteCatalogId(String id){
List<String> result = new ArrayList<>();
public List<Integer> getDeleteCatalogId(Integer id){
List<Integer> result = new ArrayList<>();
result.add(id);
//根据id获取子节点
List<ScoreRuleCatalog> children = scoreRuleCatalogRepo.findByParentId(id);
List<ScoreRuleCatalog> children = scoreRuleCatalogMapper.findByParentId(id);
if(!children.isEmpty()) {
for(ScoreRuleCatalog child : children) {
result.addAll(getDeleteCatalogId(child.getId()));
......@@ -65,20 +65,20 @@ public class ScoreRuleCatalogService {
}
//递归删除
public void recursionDelete(List<String> ids) {
for(String id : ids) {
List<String> result = this.getDeleteCatalogId(id);
public void recursionDelete(List<Integer> ids) {
for(Integer id : ids) {
List<Integer> result = this.getDeleteCatalogId(id);
this.delete(result);
//删除目录关联的单位评分规则
scoreRuleRepo.deleteByCatalogIdIn(result);
scoreRuleMapper.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);
public List<ScoreRuleCatalog> getCatalog(Integer parentId,List<String> codes){
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("pid", parentId);
paramMap.put("codes", codes);
return scoreRuleCatalogMapper.findByParentIdAndCodeInOrderByLastUpdateTimeDesc(paramMap);
}
}
......@@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -12,11 +11,10 @@ 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.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.googlecode.aviator.AviatorEvaluator;
import com.keymobile.indicators.model.entity.indicators.DriveIndCalResultDef;
import com.keymobile.indicators.model.entity.indicators.DriveIndDef;
......@@ -24,7 +22,7 @@ import com.keymobile.indicators.model.entity.objscorerule.IndTypeWeight;
import com.keymobile.indicators.model.entity.objscorerule.ScoreRule;
import com.keymobile.indicators.model.mapper.indicators.DriveIndDefMapper;
import com.keymobile.indicators.model.mapper.indmapper.DriveIndCalResultDefMapper;
import com.keymobile.indicators.persistence.hyindicators.ScoreRuleRepository;
import com.keymobile.indicators.model.mapper.indmapper.ScoreRuleMapper;
import com.keymobile.indicators.utils.CalculateUtils;
@Service
......@@ -32,7 +30,7 @@ public class ScoreRuleService {
private Logger logger = LoggerFactory.getLogger(ScoreRuleService.class);
@Autowired
private ScoreRuleRepository scoreRuleRepo;
private ScoreRuleMapper scoreRuleMapper;
@Autowired
private DriveIndDefMapper driveIndDefMapper;
@Autowired
......@@ -40,31 +38,43 @@ public class ScoreRuleService {
private static final Pattern P = Pattern.compile("(\\[[^\\]]*\\])");
public String saveOrUpdate(ScoreRule scoreRule,String catalogId,String catalogIdPath,String user) {
public Integer saveOrUpdate(ScoreRule scoreRule,Integer catalogId,String catalogIdPath,String user) {
Gson gson = new Gson();
if(!scoreRule.getIndTypeWeights().isEmpty()) {
String indTypeWeightsJson = gson.toJson(scoreRule.getIndTypeWeights());
scoreRule.setIndTypeWeightsJson(indTypeWeightsJson);
}
scoreRule.setCatalogId(catalogId);
scoreRule.setCatalogIdPath(catalogIdPath);
scoreRule.setLastUpdater(user);
scoreRule = scoreRuleRepo.save(scoreRule);
scoreRuleMapper.insert(scoreRule);
return scoreRule.getId();
}
public void delete(String id) {
scoreRuleRepo.deleteById(id);
public void delete(Integer id) {
scoreRuleMapper.deleteByPrimaryKey(id);
}
public List<ScoreRule> getAll(String code){
return scoreRuleRepo.findByCode(code);
return scoreRuleMapper.findByCode(code);
}
public Page<ScoreRule> getByCatalogId(String catalogId,int page,int rows){
Pageable pageable = PageRequest.of(page - 1, rows);
return scoreRuleRepo.findByCatalogId(catalogId,pageable);
public Map<String,Object> getByCatalogId(Integer catalogId,int page,int rows){
Map<String,Object> result = new HashMap<>();
int count = 0;
//计算start
int start = (page-1)*rows;
count = scoreRuleMapper.countByCatalogId(catalogId);
List<ScoreRule> datas = scoreRuleMapper.findByCatalogId(catalogId, start, rows);
result.put("count", count);
result.put("data", datas);
return result;
}
public ScoreRule getById(String id) {
Optional<ScoreRule> scoreRule = scoreRuleRepo.findById(id);
if(scoreRule.isPresent()) {
return scoreRule.get();
public ScoreRule getById(Integer id) {
ScoreRule scoreRule = scoreRuleMapper.selectByPrimaryKey(id);
if(scoreRule!=null) {
return scoreRule;
}
return null;
}
......@@ -212,6 +222,7 @@ public class ScoreRuleService {
private Map<String,String> calIndCatalogTypeAverage(ScoreRule scoreRule,
String compareObj,int date){
Map<String,String> result = new HashMap<>();
Gson gson = new Gson();
result.put("compareObj", compareObj);
result.put("scoreValue", "0.0");
result.put("improveValue", "0.0");
......@@ -222,8 +233,10 @@ public class ScoreRuleService {
findByCompareObjAndDate(compareObj, date);
double scoreValue = 0.0;
double improveValue = 0.0;
if(!scoreRule.getIndTypeWeights().isEmpty()) {
for(IndTypeWeight indTypeWeight : scoreRule.getIndTypeWeights()) {
if(StringUtils.isNotBlank(scoreRule.getIndTypeWeightsJson())) {
List<IndTypeWeight> indTypeWeights = gson.
fromJson(scoreRule.getIndTypeWeightsJson(), new TypeToken<List<IndTypeWeight>>(){}.getType());
for(IndTypeWeight indTypeWeight : indTypeWeights) {
Map<String,Double> calScores = this.calIndTypeScore(scoreRule, indTypeWeight, calResults);
scoreValue += (calScores.get("score")*Double.parseDouble(indTypeWeight.getWeight()));
improveValue += (calScores.get("improve")*Double.parseDouble(indTypeWeight.getWeight()));
......@@ -291,7 +304,7 @@ public class ScoreRuleService {
//根据单位评分规则计算单位分数
public List<Map<String,String>> calObjScore(String reportId,String compareId,List<String> indIds,
List<String> compareObjs,int date,String scoreRuleId) {
List<String> compareObjs,int date,Integer scoreRuleId) {
List<Map<String,String>> results = new ArrayList<>();
//根据单位得分评分卡id获取评分卡详情
ScoreRule scoreRule = this.getById(scoreRuleId);
......
package com.keymobile.indicators.service.hytobacco;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import org.apache.commons.lang.StringUtils;
import java.util.Map;
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;
import com.keymobile.indicators.model.mapper.indmapper.ShortboardCatalogMapper;
import com.keymobile.indicators.model.mapper.indmapper.ShortboardRuleMapper;
@Service
public class ShortboardCatalogService {
private Logger logger = LoggerFactory.getLogger(ShortboardCatalogService.class);
@Autowired
private ShortboardCatalogRepository shortboardCatalogRepo;
private ShortboardCatalogMapper shortboardCatalogMapper;
@Autowired
private ShortboardRuleRepository shortboardRuleRepo;
private ShortboardRuleMapper shortboardRuleMapper;
public ShortboardCatalog saveOrUpdate(ShortboardCatalog shortboardCatalog) throws Exception{
if(StringUtils.isBlank(shortboardCatalog.getId())) {//新增
if(shortboardCatalog.getId()==null) {//新增
//保存
shortboardCatalog = shortboardCatalogRepo.save(shortboardCatalog);
shortboardCatalogMapper.insert(shortboardCatalog);
}
//获取parentId拼接idPath
String parentId = shortboardCatalog.getParentId();
if(StringUtils.isBlank(parentId) || "0".equals(parentId)) {//顶层节点
shortboardCatalog.setIdPath(shortboardCatalog.getId());
Integer parentId = shortboardCatalog.getParentId();
if(parentId==0) {//顶层节点
shortboardCatalog.setIdPath(String.valueOf(shortboardCatalog.getId()));
}else {
Optional<ShortboardCatalog> parentShortboardCatalog = shortboardCatalogRepo.
findById(shortboardCatalog.getParentId());
if(!parentShortboardCatalog.isPresent()) {
ShortboardCatalog parentShortboardCatalog = shortboardCatalogMapper.
selectByPrimaryKey(shortboardCatalog.getParentId());
if(parentShortboardCatalog==null) {
throw new Exception("父节点不存在:parent catalog is not exist");
}else {
shortboardCatalog.setIdPath(parentShortboardCatalog.get().getIdPath()+";"+shortboardCatalog.getId());
shortboardCatalog.setIdPath(parentShortboardCatalog.getIdPath()+";"+shortboardCatalog.getId());
}
}
//保存
shortboardCatalog = shortboardCatalogRepo.save(shortboardCatalog);
shortboardCatalogMapper.updateByPrimaryKey(shortboardCatalog);
return shortboardCatalog;
}
public void delete(List<String> ids) {
shortboardCatalogRepo.deleteByIdIn(ids);
public void delete(List<Integer> ids) {
shortboardCatalogMapper.deleteByIdIn(ids);
}
//递归查找父目录下的子目录
public List<String> getDeleteCatalogId(String id){
List<String> result = new ArrayList<>();
public List<Integer> getDeleteCatalogId(Integer id){
List<Integer> result = new ArrayList<>();
result.add(id);
//根据id获取子节点
List<ShortboardCatalog> children = shortboardCatalogRepo.findByParentId(id);
List<ShortboardCatalog> children = shortboardCatalogMapper.findByParentId(id);
if(!children.isEmpty()) {
for(ShortboardCatalog child : children) {
result.addAll(getDeleteCatalogId(child.getId()));
......@@ -65,20 +64,20 @@ public class ShortboardCatalogService {
}
//递归删除
public void recursionDelete(List<String> ids) {
for(String id : ids) {
List<String> result = this.getDeleteCatalogId(id);
public void recursionDelete(List<Integer> ids) {
for(Integer id : ids) {
List<Integer> result = this.getDeleteCatalogId(id);
this.delete(result);
//删除目录关联的短板筛选规则
shortboardRuleRepo.deleteByCatalogIdIn(result);
shortboardRuleMapper.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);
public List<ShortboardCatalog> getCatalog(Integer parentId,List<String> codes){
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("pid", parentId);
paramMap.put("codes", codes);
return shortboardCatalogMapper.findByParentIdAndCodeInOrderByLastUpdateTimeDesc(paramMap);
}
}
......@@ -4,23 +4,19 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.google.gson.Gson;
import com.keymobile.indicators.model.entity.indicators.DriveIndCalResultDef;
import com.keymobile.indicators.model.entity.shortboard.ShortboardDriveIndRel;
import com.keymobile.indicators.model.entity.shortboard.ShortboardItem;
import com.keymobile.indicators.model.entity.shortboard.ShortboardRule;
import com.keymobile.indicators.model.mapper.indmapper.DriveIndCalResultDefMapper;
import com.keymobile.indicators.persistence.hyindicators.ShortboardDriveIndRelRepository;
import com.keymobile.indicators.persistence.hyindicators.ShortboardRuleRepository;
import com.keymobile.indicators.model.mapper.indmapper.ShortboardDriveIndRelMapper;
import com.keymobile.indicators.model.mapper.indmapper.ShortboardRuleMapper;
import com.keymobile.indicators.utils.CalculateUtils;
@Service
......@@ -28,34 +24,46 @@ public class ShortboardRuleService {
private Logger logger = LoggerFactory.getLogger(ShortboardRuleService.class);
@Autowired
private ShortboardRuleRepository shortboardRuleRepo;
private ShortboardRuleMapper shortboardRuleMapper;
@Autowired
private ShortboardDriveIndRelRepository shortboardDriveIndRelRepo;
private ShortboardDriveIndRelMapper shortboardDriveIndRelMapper;
@Autowired
private DriveIndCalResultDefMapper driveIndCalResultDefMapper;
public String saveOrUpdate(ShortboardRule shortboardRule,String catalogId,
public Integer saveOrUpdate(ShortboardRule shortboardRule,Integer catalogId,
String catalogIdPath,String user) {
Gson gson = new Gson();
if(!shortboardRule.getShortboardItem().isEmpty()) {
String shortboardItemJson = gson.toJson(shortboardRule.getShortboardItem());
shortboardRule.setShortboardItemJson(shortboardItemJson);
}
shortboardRule.setCatalogId(catalogId);
shortboardRule.setCatalogIdPath(catalogIdPath);
shortboardRule.setLastUpdater(user);
shortboardRule = shortboardRuleRepo.save(shortboardRule);
shortboardRuleMapper.insert(shortboardRule);
return shortboardRule.getId();
}
public void delete(String id) {
shortboardRuleRepo.deleteById(id);
public void delete(Integer id) {
shortboardRuleMapper.deleteByPrimaryKey(id);
}
public Page<ShortboardRule> getByCatalogId(String catalogId,int page,int rows){
Pageable pageable = PageRequest.of(page - 1, rows);
return shortboardRuleRepo.findByCatalogId(catalogId,pageable);
public Map<String,Object> getByCatalogId(Integer catalogId,int page,int rows){
Map<String,Object> result = new HashMap<>();
int count = 0;
//计算start
int start = (page-1)*rows;
count = shortboardRuleMapper.countByCatalogId(catalogId);
List<ShortboardRule> datas = shortboardRuleMapper.findByCatalogId(catalogId, start, rows);
result.put("count", count);
result.put("data", datas);
return result;
}
public ShortboardRule getById(String id) {
Optional<ShortboardRule> shortboardRule = shortboardRuleRepo.findById(id);
if(shortboardRule.isPresent()) {
return shortboardRule.get();
public ShortboardRule getById(Integer id) {
ShortboardRule shortboardRule = shortboardRuleMapper.selectByPrimaryKey(id);
if(shortboardRule!=null) {
return shortboardRule;
}
return null;
}
......@@ -66,7 +74,7 @@ public class ShortboardRuleService {
List<Map<String,String>> result = new ArrayList<>();
for(String driveId : driveIds) {
//根据考核指标id获取关联的短板筛选规则id
List<ShortboardDriveIndRel> relations = shortboardDriveIndRelRepo.
List<ShortboardDriveIndRel> relations = shortboardDriveIndRelMapper.
findByDriveIndDefId(driveId);
for(ShortboardDriveIndRel rel : relations) {
ShortboardRule shortboardRule = this.getById(rel.getShortboardRuleId());
......
<?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.ScoreRuleCatalogMapper">
<delete id="deleteByIdIn" parameterType="java.util.List">
delete
from obj_score_rule_catalog
where id in
<foreach item="id" collection="ids" open="(" close=")" separator=",">
#{id}
</foreach>
</delete>
<select id="findByParentIdAndCodeInOrderByLastUpdateTimeDesc" parameterType="map" resultType="com.keymobile.indicators.model.entity.objscorerule.ScoreRuleCatalog" >
select *
from obj_score_rule_catalog
where parent_id = #{pid} and
code in
<foreach item="id" collection="codes" open="(" close=")" separator=",">
#{id}
</foreach>
order by last_update_time desc
</select>
<select id="findByParentId" resultType="com.keymobile.indicators.model.entity.objscorerule.ScoreRuleCatalog" >
select *
from obj_score_rule_catalog
where parent_id = #{pid}
</select>
</mapper>
\ No newline at end of file
<?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.ScoreRuleMapper">
<select id="findByCode" resultType="com.keymobile.indicators.model.entity.objscorerule.ScoreRule" >
select *
from obj_score_rule
where code = #{code}
</select>
<select id="findByCatalogId" resultType="com.keymobile.indicators.model.entity.objscorerule.ScoreRule" >
select *
from obj_score_rule
where catalog_id = #{catalogId}
limit #{start},#{end}
</select>
<select id="countByCatalogId" resultType="java.lang.Integer">
select count(1)
from obj_score_rule
where catalog_id = #{catalogId}
</select>
<delete id="deleteByCatalogIdIn" parameterType="java.util.List">
delete
from obj_score_rule
where catalog_id in
<foreach item="id" collection="catalogIds" open="(" close=")" separator=",">
#{id}
</foreach>
</delete>
</mapper>
\ No newline at end of file
<?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.ShortboardCatalogMapper">
<delete id="deleteByIdIn" parameterType="java.util.List">
delete
from ind_short_board_catalog
where id in
<foreach item="id" collection="ids" open="(" close=")" separator=",">
#{id}
</foreach>
</delete>
<select id="findByParentIdAndCodeInOrderByLastUpdateTimeDesc" parameterType="map" resultType="com.keymobile.indicators.model.entity.shortboard.ShortboardCatalog" >
select *
from ind_short_board_catalog
where parent_id = #{pid} and
code in
<foreach item="id" collection="codes" open="(" close=")" separator=",">
#{id}
</foreach>
order by last_update_time desc
</select>
<select id="findByParentId" resultType="com.keymobile.indicators.model.entity.shortboard.ShortboardCatalog" >
select *
from ind_short_board_catalog
where parent_id = #{pid}
</select>
</mapper>
\ No newline at end of file
<?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.ShortboardDriveIndRelMapper">
<select id="findByDriveIndDefId" resultType="com.keymobile.indicators.model.entity.shortboard.ShortboardDriveIndRel" >
select *
from short_board_drive_ind_rel
where drive_ind_def_id = #{driveIndDefId}
</select>
</mapper>
\ No newline at end of file
<?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.ShortboardRuleMapper">
<select id="findByCatalogId" resultType="com.keymobile.indicators.model.entity.shortboard.ShortboardRule" >
select *
from short_board_rule
where catalog_id = #{catalogId}
limit #{start},#{end}
</select>
<select id="countByCatalogId" resultType="java.lang.Integer">
select count(1)
from short_board_rule
where catalog_id = #{catalogId}
</select>
<delete id="deleteByCatalogIdIn" parameterType="java.util.List">
delete
from short_board_rule
where catalog_id in
<foreach item="id" collection="catalogIds" open="(" close=")" separator=",">
#{id}
</foreach>
</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