Commit 5b998d08 by zhangkb

提交对标系统基础指标和考核指标库表修改

parent 25eeac76
...@@ -163,6 +163,11 @@ ...@@ -163,6 +163,11 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- akka --> <!-- akka -->
<!-- gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
......
package com.keymobile.indicators.api.hytobacco;
import java.util.List;
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.indicators.DriveIndCatalog;
import com.keymobile.indicators.model.entity.indicators.IndCatalog;
import com.keymobile.indicators.service.hytobacco.DriveIndCatalogService;
import com.keymobile.indicators.service.hytobacco.IndCatalogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@Api(tags={"指标目录定义接口"})
@RestController
@RequestMapping(value = "/indCatalog")
public class IndCatalogCtrl {
@Autowired
private IndCatalogService indCatalogService;
@Autowired
private DriveIndCatalogService driveIndCatalogService;
@ApiOperation(value = "新建基础指标目录", notes = "新建基础指标目录")
@PostMapping(value = "/createBaseIndCatalog")
public String createBaseIndCatalog(@RequestBody IndCatalog indCatalog) throws Exception{
indCatalog = indCatalogService.saveOrUpdate(indCatalog);
return indCatalog.getId();
}
@ApiOperation(value = "批量级联删除基础指标目录", notes = "批量级联删除基础指标目录")
@PostMapping(value = "/deleteBaseIndCatalog")
public void deleteBaseIndCatalog(@RequestParam List<String> ids) throws Exception{
indCatalogService.recursionDelete(ids);
}
@ApiOperation(value = "获取基础指标目录", notes = "获取基础指标目录")
@PostMapping(value = "/getBaseIndCatalog")
public List<IndCatalog> getBaseIndCatalog(@RequestParam String parentId,@RequestParam String type){
return indCatalogService.getCatalog(parentId, type);
}
//考核指标目录
@ApiOperation(value = "新建考核指标目录", notes = "新建考核指标目录")
@PostMapping(value = "/createDriveIndCatalog")
public String createDriveIndCatalog(@RequestBody DriveIndCatalog driveIndCatalog) throws Exception{
driveIndCatalog = driveIndCatalogService.saveOrUpdate(driveIndCatalog);
return driveIndCatalog.getId();
}
@ApiOperation(value = "批量级联删除考核指标目录", notes = "批量级联删除考核指标目录")
@PostMapping(value = "/deleteDriveIndCatalog")
public void deleteDriveIndCatalog(@RequestParam List<String> ids) throws Exception{
driveIndCatalogService.recursionDelete(ids);
}
@ApiOperation(value = "获取考核指标目录", notes = "获取考核指标目录")
@PostMapping(value = "/getDriveIndCatalog")
public List<DriveIndCatalog> getDriveIndCatalog(@RequestParam String parentId,@RequestParam String type){
return driveIndCatalogService.getCatalog(parentId, type);
}
}
package com.keymobile.indicators.api.hytobacco; package com.keymobile.indicators.api.hytobacco;
import java.util.Date; import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; 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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.keymobile.indicators.model.entity.IndAcsDef; import com.keymobile.indicators.model.entity.indicators.BaseIndDef;
import com.keymobile.indicators.model.entity.IndAcsScoreInfo; import com.keymobile.indicators.model.entity.indicators.DriveIndDef;
import com.keymobile.indicators.model.entity.IndAnaDef; import com.keymobile.indicators.service.hytobacco.BaseIndDefService;
import com.keymobile.indicators.service.cmbkpi.IndAcsDefService;
import com.keymobile.indicators.service.cmbkpi.IndAcsScoreInfoService;
import com.keymobile.indicators.service.cmbkpi.IndAnaDefService;
import com.keymobile.indicators.service.hytobacco.DriveIndCalResultService; import com.keymobile.indicators.service.hytobacco.DriveIndCalResultService;
import com.keymobile.indicators.service.hytobacco.DriveIndDefService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -26,55 +24,50 @@ import io.swagger.annotations.ApiOperation; ...@@ -26,55 +24,50 @@ import io.swagger.annotations.ApiOperation;
public class IndicatorsDefCtrl { public class IndicatorsDefCtrl {
@Autowired @Autowired
private IndAnaDefService indAnaDefService; private BaseIndDefService baseIndDefService;
@Autowired @Autowired
private IndAcsDefService indAcsDefService; private DriveIndDefService driveIndDefService;
@Autowired
private IndAcsScoreInfoService indAscScoreService;
@Autowired @Autowired
private DriveIndCalResultService driveIndCalResultService; private DriveIndCalResultService driveIndCalResultService;
@ApiOperation(value = "新建基础指标", notes = "新建基础指标") @ApiOperation(value = "新建基础指标", notes = "新建基础指标")
@PostMapping(value = "/createAnaInd") @PostMapping(value = "/createBaseInd")
public void createAnaInd(@RequestParam String indId,@RequestParam String indName, public void createBaseInd(@RequestBody BaseIndDef baseIndDef,@RequestParam String catalogId,
@RequestParam(required=false) String unt) throws Exception{ @RequestParam String user) throws Exception{
IndAnaDef indAnaDef = new IndAnaDef(); baseIndDefService.saveOrUpdate(baseIndDef, catalogId, user);
indAnaDef.setIndId(indId); }
indAnaDef.setIndName(indName);
indAnaDef.setUnt(unt); @ApiOperation(value = "删除基础指标", notes = "删除基础指标")
indAnaDef.setDefTime(new Date()); @PostMapping(value = "/deleteBaseInd")
indAnaDef.setUpdTime(new Date()); public void deleteBaseInd(@RequestParam String indId) throws Exception{
indAnaDef.setDefStaTime(202004); baseIndDefService.delete(indId);
indAnaDef.setDefEndTime(999904); }
indAnaDefService.saveOrUpdate(indAnaDef); @ApiOperation(value = "根据关键字查询基础指标", notes = "根据关键字查询基础指标")
@PostMapping(value = "/getByPageAndKeyword")
public Map<String,Object> getByPageAndKeyword(@RequestParam String catalogId,@RequestParam String keyword,
@RequestParam int page,@RequestParam int rows) throws Exception{
return baseIndDefService.getByPageAndKeyword(catalogId, keyword, page, rows);
} }
@ApiOperation(value = "新建考核指标", notes = "新建考核指标") @ApiOperation(value = "新建考核指标", notes = "新建考核指标")
@PostMapping(value = "/createAcsInd") @PostMapping(value = "/createDriveInd")
public void createAcsInd(@RequestParam String indId,@RequestParam String indName, public void createDriveInd(@RequestBody DriveIndDef driveIndDef,@RequestParam String catalogId,
@RequestParam(required=false) String unt,@RequestParam(required=false) String indType, @RequestParam String user) throws Exception{
@RequestParam String formula) throws Exception{ driveIndDefService.saveOrUpdate(driveIndDef, catalogId, user);
IndAcsDef indAcsDef = new IndAcsDef(); }
indAcsDef.setIndId(indId);
indAcsDef.setIndName(indName); @ApiOperation(value = "删除考核指标", notes = "删除考核指标")
indAcsDef.setUnt(unt); @PostMapping(value = "/deleteDriveInd")
if(StringUtils.isNotBlank(indType)) { public void deleteDriveInd(@RequestParam String indId) throws Exception{
indAcsDef.setIndType(indType);//0:正向 1:反向 driveIndDefService.delete(indId);
} }
indAcsDef.setWeight(1.0);
indAcsDef.setDefTime(new Date()); @ApiOperation(value = "根据关键字查询考核指标", notes = "根据关键字查询考核指标")
indAcsDef.setUpdTime(new Date()); @PostMapping(value = "/getDriveByPageAndKeyword")
indAcsDefService.saveOrUpdate(indAcsDef); public Map<String,Object> getDriveByPageAndKeyword(@RequestParam String catalogId,@RequestParam String keyword,
@RequestParam int page,@RequestParam int rows) throws Exception{
IndAcsScoreInfo indAcsScoreInfo = new IndAcsScoreInfo(); return driveIndDefService.getByPageAndKeyword(catalogId, keyword, page, rows);
indAcsScoreInfo.setAppraisalsDate(202004);
indAcsScoreInfo.setIndexId(indId);
indAcsScoreInfo.setScoreFormula(formula);
indAcsScoreInfo.setWeight(1.0);
indAcsScoreInfo.setUpdateTime(new Date());
indAscScoreService.save(indAcsScoreInfo);
} }
@ApiOperation(value = "对标计算", notes = "对标计算") @ApiOperation(value = "对标计算", notes = "对标计算")
......
package com.keymobile.indicators.model.entity.indicators;
import java.util.Date;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.Data;
/**
* author:zhangkb time:2020-5-20 desc:基础项指标
*/
@Data
@Table(name="base_ind_def")
public class BaseIndDef {
@Id
private String indId;//数据项编码
private String indName;//数据项名称
private String indLevel;//数据项级别
private String indType;//数据项类别
private String indDept;//数据项归属部门
private String indUnit;//数据项单位
private String indDesc;//说明
private String indSource;//数据项来源
private String indFrequency;//数据源频度
private String creater;
private Date createTime;
private String updater;
private Date updateTime;
private Integer defStaTime;
private Integer defEndTime;
private String version;//版本号
private String catalogId;//挂靠目录id
}
package com.keymobile.indicators.model.entity.indicators;
import java.io.Serializable;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import lombok.Data;
/**
*author:zhangkb time:2020-5-20 desc:基础项数据版本数据
*/
@Data
@Document(collection="base_ind_def_version_data")
public class BaseIndDefVersionData implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
private String id;
private String indId;
private String indName;
private String version;
private String dataJson;
}
package com.keymobile.indicators.model.entity.indicators;
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-5-18 desc:考核指标目录
*/
@Data
@Document(collection="drive_ind_catalog")
public class DriveIndCatalog implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
private String id;
private String catalogName;
private String type;
private String catalogType;//分为数据项级别和数据项类别 0:数据项级别 1:数据项类别
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.indicators;
import java.util.Date;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.Data;
/**
* author:zhangkb time:2020-5-21 desc:考核指标
*/
@Data
@Table(name="drive_ind_def")
public class DriveIndDef {
@Id
private String indId;//指标编码
private String indName;//指标名称
private String indLevel;//指标级别
private String indType;//指标类别
private String indDept;//指标归属部门
private String indUnit;//指标单位
private String indDesc;//说明
private String indFormat;//指标公式
private String indFormatDesc;//指标公式描述
private String isCalScore;//是否计分 是:1 否:0
private String indRule;//指标正负属性:正向指标0 反向指标1
private String indCalScoreRule;//计分规则
private String indCalScoreRuleDesc;//计分规则描述
private String isUnitCalScore;//是否参与单位得分计算 是:1 否:0
private String indFrequency;//指标频度
private String version;//版本号
private String catalogId;//挂靠目录id
private String creater;
private Date createTime;
private String updater;
private Date updateTime;
private Integer defStaTime;
private Integer defEndTime;
}
package com.keymobile.indicators.model.entity.indicators;
import java.io.Serializable;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import lombok.Data;
/**
*author:zhangkb time:2020-5-21 desc:考核指标数据版本数据
*/
@Data
@Document(collection="drive_ind_def_version_data")
public class DriveIndDefVersionData implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
private String id;
private String indId;
private String indName;
private String version;
private String dataJson;
}
package com.keymobile.indicators.model.entity.indicators;
import java.io.Serializable;
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-5-18 desc:基础项目录
*/
@Data
@Document(collection="ind_catalog")
public class IndCatalog implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
private String id;
private String catalogName;
private String type;
private String catalogType;//分为数据项级别和数据项类别 0:数据项级别 1:数据项类别
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.mapper.indicators;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Mapper;
import com.keymobile.indicators.model.entity.indicators.BaseIndDef;
import tk.mybatis.mapper.common.BaseMapper;
@Mapper
public interface BaseIndDefMapper extends BaseMapper<BaseIndDef>{
public List<BaseIndDef> getPageByKeyword(Map<String,Object> param);
public int getByKeywordCount(Map<String,Object> param);
public void deleteByCatalogIdIn(List<String> catalogIds);
}
package com.keymobile.indicators.model.mapper.indicators;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Mapper;
import com.keymobile.indicators.model.entity.indicators.DriveIndDef;
import tk.mybatis.mapper.common.BaseMapper;
@Mapper
public interface DriveIndDefMapper extends BaseMapper<DriveIndDef>{
public List<DriveIndDef> getPageByKeyword(Map<String,Object> param);
public int getByKeywordCount(Map<String,Object> param);
public void deleteByCatalogIdIn(List<String> catalogIds);
}
package com.keymobile.indicators.persistence.hyindicators;
import org.springframework.data.mongodb.repository.MongoRepository;
import com.keymobile.indicators.model.entity.indicators.BaseIndDefVersionData;
public interface BaseIndDefVersionRepository extends MongoRepository<BaseIndDefVersionData,String>{
}
package com.keymobile.indicators.persistence.hyindicators;
import java.util.List;
import org.springframework.data.mongodb.repository.MongoRepository;
import com.keymobile.indicators.model.entity.indicators.DriveIndCatalog;
public interface DriveIndCatalogRepository extends MongoRepository<DriveIndCatalog,String>{
public void deleteByIdIn(List<String> ids);
public List<DriveIndCatalog> findByParentIdAndTypeOrderByLastUpdateTimeDesc(String pid,String type);
public List<DriveIndCatalog> findByParentId(String pid);
}
package com.keymobile.indicators.persistence.hyindicators;
import org.springframework.data.mongodb.repository.MongoRepository;
import com.keymobile.indicators.model.entity.indicators.DriveIndDefVersionData;
public interface DriveIndDefVersionRepository extends MongoRepository<DriveIndDefVersionData,String>{
}
package com.keymobile.indicators.persistence.hyindicators;
import java.util.List;
import org.springframework.data.mongodb.repository.MongoRepository;
import com.keymobile.indicators.model.entity.indicators.IndCatalog;
public interface IndCatalogRepository extends MongoRepository<IndCatalog,String>{
public void deleteByIdIn(List<String> ids);
public List<IndCatalog> findByParentIdAndTypeOrderByLastUpdateTimeDesc(String pid,String type);
public List<IndCatalog> findByParentId(String pid);
}
...@@ -3,7 +3,6 @@ package com.keymobile.indicators.service.hytobacco; ...@@ -3,7 +3,6 @@ package com.keymobile.indicators.service.hytobacco;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
......
package com.keymobile.indicators.service.hytobacco;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
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.mapper.indicators.BaseIndDefMapper;
@Service
public class BaseIndDefService {
@Autowired
private BaseIndDefMapper baseIndDefMapper;
@Autowired
private BaseIndDefVersionService baseIndDefVersionService;
public String saveOrUpdate(BaseIndDef baseIndDef,String catalogId,String user)
throws Exception{
if(StringUtils.isBlank(baseIndDef.getIndId())) {
return "indId can not be null";
}
BaseIndDef dbBaseIndDef = this.getById(baseIndDef.getIndId());
if(dbBaseIndDef==null) {
baseIndDef.setCreater(user);
baseIndDef.setCreateTime(new Date());
baseIndDef.setUpdater(user);
baseIndDef.setUpdateTime(new Date());
baseIndDef.setVersion("1.0");
baseIndDef.setCatalogId(catalogId);
baseIndDefMapper.insert(baseIndDef);
}else {
//生成版本
if(baseIndDefVersionService.save(baseIndDef)) {
String oldVersion = baseIndDef.getVersion();
String newVersion = String.valueOf(Double.valueOf(oldVersion)+1);//旧版本+1
baseIndDef.setUpdater(user);
baseIndDef.setUpdateTime(new Date());
baseIndDef.setVersion(newVersion);
baseIndDef.setCatalogId(catalogId);
baseIndDefMapper.updateByPrimaryKey(baseIndDef);
}
}
return "success;indId:"+baseIndDef.getIndId();
}
public BaseIndDef getById(String indId) throws Exception{
BaseIndDef baseIndDef = new BaseIndDef();
baseIndDef.setIndId(indId);
return baseIndDefMapper.selectOne(baseIndDef);
}
public void delete(String indId) throws Exception{
baseIndDefMapper.deleteByPrimaryKey(indId);
}
public Map<String,Object> getByPageAndKeyword(String catalogId,String keyword,
int page,int rows)throws Exception{
Map<String,Object> paramMap = new HashMap<>();
Map<String,Object> resultMap = new HashMap<>();
if(StringUtils.isBlank(catalogId)) {
paramMap.put("catalogId", null);
}else {
paramMap.put("catalogId", catalogId);
}
if(StringUtils.isBlank(keyword)) {
paramMap.put("keyword", null);
}else {
paramMap.put("keyword", "%"+keyword+"%");
}
//计算总数
int count = baseIndDefMapper.getByKeywordCount(paramMap);
//计算start
int start = page*rows;
paramMap.put("start", start);
paramMap.put("end", rows);
List<BaseIndDef> resultList = baseIndDefMapper.getPageByKeyword(paramMap);
resultMap.put("resultList", resultList);
resultMap.put("total", count);
return resultMap;
}
}
package com.keymobile.indicators.service.hytobacco;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.keymobile.indicators.model.entity.indicators.BaseIndDef;
import com.keymobile.indicators.model.entity.indicators.BaseIndDefVersionData;
import com.keymobile.indicators.persistence.hyindicators.BaseIndDefVersionRepository;
@Service
public class BaseIndDefVersionService {
private Logger logger = LoggerFactory.getLogger(BaseIndDefVersionService.class);
@Autowired
private BaseIndDefVersionRepository baseIndDefVersionRepo;
public boolean save(BaseIndDef baseIndDef) throws Exception{
BaseIndDefVersionData baseIndDefVersionData = new BaseIndDefVersionData();
baseIndDefVersionData.setIndId(baseIndDef.getIndId());
baseIndDefVersionData.setIndName(baseIndDef.getIndName());
baseIndDefVersionData.setVersion(baseIndDef.getVersion());
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.setPrettyPrinting();
Gson gson = gsonBuilder.create();
baseIndDefVersionData.setDataJson(gson.toJson(baseIndDef));
baseIndDefVersionRepo.save(baseIndDefVersionData);
return true;
}
}
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.indicators.DriveIndCatalog;
import com.keymobile.indicators.model.mapper.indicators.DriveIndDefMapper;
import com.keymobile.indicators.persistence.hyindicators.DriveIndCatalogRepository;
@Service
public class DriveIndCatalogService {
private Logger logger = LoggerFactory.getLogger(DriveIndCatalogService.class);
@Autowired
private DriveIndCatalogRepository driveIndCatalogRepo;
@Autowired
private DriveIndDefMapper driveIndDefMapper;
public DriveIndCatalog saveOrUpdate(DriveIndCatalog driveIndCatalog) throws Exception{
if(StringUtils.isBlank(driveIndCatalog.getId())) {//新增
//保存
driveIndCatalog = driveIndCatalogRepo.save(driveIndCatalog);
}
//获取parentId拼接idPath
String parentId = driveIndCatalog.getParentId();
if(StringUtils.isBlank(parentId) || "0".equals(parentId)) {//顶层节点
driveIndCatalog.setIdPath(driveIndCatalog.getId());
}else {
Optional<DriveIndCatalog> parentDriveIndCatalog = driveIndCatalogRepo.findById(driveIndCatalog.getParentId());
if(!parentDriveIndCatalog.isPresent()) {
throw new Exception("父节点不存在:parent catalog is not exist");
}else {
driveIndCatalog.setIdPath(parentDriveIndCatalog.get().getIdPath()+";"+
driveIndCatalog.getId());
}
}
//保存
driveIndCatalog = driveIndCatalogRepo.save(driveIndCatalog);
return driveIndCatalog;
}
public void delete(List<String> ids) {
driveIndCatalogRepo.deleteByIdIn(ids);
}
//递归查找父目录下的子目录
public List<String> getDeleteCatalogId(String id){
List<String> result = new ArrayList<>();
result.add(id);
//根据id获取子节点
List<DriveIndCatalog> children = driveIndCatalogRepo.findByParentId(id);
if(!children.isEmpty()) {
for(DriveIndCatalog 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);
//删除目录关联的指标
driveIndDefMapper.deleteByCatalogIdIn(result);
}
}
//获取目录树
public List<DriveIndCatalog> getCatalog(String parentId,String type){
if(StringUtils.isBlank(parentId) || "0".equals(parentId)) {
return driveIndCatalogRepo.findByParentIdAndTypeOrderByLastUpdateTimeDesc("0", type);
}
return driveIndCatalogRepo.findByParentIdAndTypeOrderByLastUpdateTimeDesc(parentId, type);
}
}
package com.keymobile.indicators.service.hytobacco;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.keymobile.indicators.model.entity.indicators.DriveIndDef;
import com.keymobile.indicators.model.mapper.indicators.DriveIndDefMapper;
@Service
public class DriveIndDefService {
@Autowired
private DriveIndDefMapper driveIndDefMapper;
@Autowired
private DriveIndDefVersionService driveIndDefVersionService;
public String saveOrUpdate(DriveIndDef driveIndDef,String catalogId,String user)
throws Exception{
if(StringUtils.isBlank(driveIndDef.getIndId())) {
return "indId can not be null";
}
DriveIndDef dbBaseIndDef = this.getById(driveIndDef.getIndId());
if(dbBaseIndDef==null) {
driveIndDef.setCreater(user);
driveIndDef.setCreateTime(new Date());
driveIndDef.setUpdater(user);
driveIndDef.setUpdateTime(new Date());
driveIndDef.setVersion("1.0");
driveIndDef.setCatalogId(catalogId);
driveIndDefMapper.insert(driveIndDef);
}else {
//生成版本
if(driveIndDefVersionService.save(driveIndDef)) {
String oldVersion = driveIndDef.getVersion();
String newVersion = String.valueOf(Double.valueOf(oldVersion)+1);//旧版本+1
driveIndDef.setUpdater(user);
driveIndDef.setUpdateTime(new Date());
driveIndDef.setVersion(newVersion);
driveIndDef.setCatalogId(catalogId);
driveIndDefMapper.updateByPrimaryKey(driveIndDef);
}
}
return "success;driveIndId:"+driveIndDef.getIndId();
}
public DriveIndDef getById(String indId) throws Exception{
DriveIndDef driveIndDef = new DriveIndDef();
driveIndDef.setIndId(indId);
return driveIndDefMapper.selectOne(driveIndDef);
}
public void delete(String indId) throws Exception{
driveIndDefMapper.deleteByPrimaryKey(indId);
}
public Map<String,Object> getByPageAndKeyword(String catalogId,String keyword,
int page,int rows)throws Exception{
Map<String,Object> paramMap = new HashMap<>();
Map<String,Object> resultMap = new HashMap<>();
if(StringUtils.isBlank(catalogId)) {
paramMap.put("catalogId", null);
}else {
paramMap.put("catalogId", catalogId);
}
if(StringUtils.isBlank(keyword)) {
paramMap.put("keyword", null);
}else {
paramMap.put("keyword", "%"+keyword+"%");
}
//计算总数
int count = driveIndDefMapper.getByKeywordCount(paramMap);
//计算start
int start = page*rows;
paramMap.put("start", start);
paramMap.put("end", rows);
List<DriveIndDef> resultList = driveIndDefMapper.getPageByKeyword(paramMap);
resultMap.put("resultList", resultList);
resultMap.put("total", count);
return resultMap;
}
}
package com.keymobile.indicators.service.hytobacco;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.keymobile.indicators.model.entity.indicators.DriveIndDef;
import com.keymobile.indicators.model.entity.indicators.DriveIndDefVersionData;
import com.keymobile.indicators.persistence.hyindicators.DriveIndDefVersionRepository;
@Service
public class DriveIndDefVersionService {
private Logger logger = LoggerFactory.getLogger(DriveIndDefVersionService.class);
@Autowired
private DriveIndDefVersionRepository driveIndDefVersionRepo;
public boolean save(DriveIndDef driveIndDef) throws Exception{
DriveIndDefVersionData driveIndDefVersionData = new DriveIndDefVersionData();
driveIndDefVersionData.setIndId(driveIndDef.getIndId());
driveIndDefVersionData.setIndName(driveIndDef.getIndName());
driveIndDefVersionData.setVersion(driveIndDef.getVersion());
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.setPrettyPrinting();
Gson gson = gsonBuilder.create();
driveIndDefVersionData.setDataJson(gson.toJson(driveIndDef));
driveIndDefVersionRepo.save(driveIndDefVersionData);
return true;
}
}
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.indicators.IndCatalog;
import com.keymobile.indicators.model.mapper.indicators.BaseIndDefMapper;
import com.keymobile.indicators.persistence.hyindicators.IndCatalogRepository;
@Service
public class IndCatalogService {
private Logger logger = LoggerFactory.getLogger(IndCatalogService.class);
@Autowired
private IndCatalogRepository indCatalogRepo;
@Autowired
private BaseIndDefMapper baseIndDefMapper;
public IndCatalog saveOrUpdate(IndCatalog indCatalog) throws Exception{
if(StringUtils.isBlank(indCatalog.getId())) {//新增
//保存
indCatalog = indCatalogRepo.save(indCatalog);
}
//获取parentId拼接idPath
String parentId = indCatalog.getParentId();
if(StringUtils.isBlank(parentId) || "0".equals(parentId)) {//顶层节点
indCatalog.setIdPath(indCatalog.getId());
}else {
Optional<IndCatalog> parentIndCatalog = indCatalogRepo.findById(indCatalog.getParentId());
if(!parentIndCatalog.isPresent()) {
throw new Exception("父节点不存在:parent catalog is not exist");
}else {
indCatalog.setIdPath(parentIndCatalog.get().getIdPath()+";"+indCatalog.getId());
}
}
//保存
indCatalog = indCatalogRepo.save(indCatalog);
return indCatalog;
}
public void delete(List<String> ids) {
indCatalogRepo.deleteByIdIn(ids);
}
//递归查找父目录下的子目录
public List<String> getDeleteCatalogId(String id){
List<String> result = new ArrayList<>();
result.add(id);
//根据id获取子节点
List<IndCatalog> children = indCatalogRepo.findByParentId(id);
if(!children.isEmpty()) {
for(IndCatalog 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);
//删除目录关联的指标
baseIndDefMapper.deleteByCatalogIdIn(result);
}
}
//获取目录树
public List<IndCatalog> getCatalog(String parentId,String type){
if(StringUtils.isBlank(parentId) || "0".equals(parentId)) {
return indCatalogRepo.findByParentIdAndTypeOrderByLastUpdateTimeDesc("0", type);
}
return indCatalogRepo.findByParentIdAndTypeOrderByLastUpdateTimeDesc(parentId, type);
}
}
...@@ -8,6 +8,7 @@ import java.util.HashMap; ...@@ -8,6 +8,7 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional; import java.util.Optional;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -56,6 +57,58 @@ public class IndicatorsValueService { ...@@ -56,6 +57,58 @@ public class IndicatorsValueService {
@Value("${mongodb.database}") @Value("${mongodb.database}")
private String database; private String database;
//填充县级对标卷烟销量分组表excel
public void fillExcelXianJuanYanGroup(List<String> indIds,int date,String compareObjString) throws Exception{
String[] compareObjs = compareObjString.split(";");
Map<String,Object> result = new HashMap<>();
for(String indId : indIds) {
IndAcsDef indAcsDef = indAcsDefService.getById(indId);
//计算同期排名
Map<String,String> valueMap = new HashMap<>();
//计算增幅排名
Map<String,String> gowthMap = new HashMap<>();
Map<String,Object> allComObjDataMap = new HashMap<>();
for(String compareObj : compareObjs) {
Map<String,String> dataMap = new HashMap<>();
//获取本期值
Optional<DriveIndCalResult> driveIndCalResult = driveIndResultRepo
.findByIndIdAndDateAndCompareObj(indId, date, compareObj);
//获取同期值
Optional<DriveIndCalResult> sameDriveIndCalResult = driveIndResultRepo
.findByIndIdAndDateAndCompareObj(indId, (date-100), compareObj);
if(sameDriveIndCalResult.isPresent()) {//存在
valueMap.put(compareObj, sameDriveIndCalResult.get().getValue());
}else {
valueMap.put(compareObj, "0");
}
dataMap.put("currentValue",driveIndCalResult.get().getValue());
dataMap.put("currentRank", String.valueOf(driveIndCalResult.get().getRank()));
dataMap.put("sameValue", sameDriveIndCalResult.get().getValue());
String calGowth = CalculateUtils.calGowth(indAcsDef.getUnt(),
driveIndCalResult.get().getValue(), sameDriveIndCalResult.get().getValue(), "1");
dataMap.put("calGowth", calGowth);
gowthMap.put(compareObj, calGowth);
allComObjDataMap.put(compareObj, dataMap);
}
//排列同期指标值
Map<String,Integer> sameValueRank = CalculateUtils.rankValue(valueMap, indAcsDef.getIndType());
//排名增幅排名
Map<String,Integer> gowthValueRank = CalculateUtils.rankValue(gowthMap, indAcsDef.getIndType());
for(Entry<String,Object> entry: allComObjDataMap.entrySet()) {
Map<String,String> dataMap = (Map<String,String>)entry.getValue();
Integer sameRank = sameValueRank.get(entry.getKey());
Integer gowthRank = gowthValueRank.get(entry.getKey());
dataMap.put("sameRank", String.valueOf(sameRank));
dataMap.put("gowthRank", String.valueOf(gowthRank));
allComObjDataMap.put(entry.getKey(), dataMap);
}
result.put(indId, allComObjDataMap);
}
}
//填充市对标通报一览表 //填充市对标通报一览表
public void fillExcelFileFive(List<String> indIds,int date,String type,String compareIdString)throws Exception{ public void fillExcelFileFive(List<String> indIds,int date,String type,String compareIdString)throws Exception{
FileInputStream fs=new FileInputStream("D://indicatorsFile/file5.xlsx"); FileInputStream fs=new FileInputStream("D://indicatorsFile/file5.xlsx");
......
...@@ -202,14 +202,14 @@ public class CalculateUtils { ...@@ -202,14 +202,14 @@ public class CalculateUtils {
// // 输出的是6.333333333333333 // // 输出的是6.333333333333333
// System.out.println(AviatorEvaluator.execute("F004/F002*100", env)); // System.out.println(AviatorEvaluator.execute("F004/F002*100", env));
List<String> values = new ArrayList<>(); // List<String> values = new ArrayList<>();
values.add("0"); // values.add("0");
values.add("18"); // values.add("18");
values.add("18"); // values.add("18");
values.add("17.2837"); // values.add("17.2837");
CalculateUtils cal = new CalculateUtils(); // CalculateUtils cal = new CalculateUtils();
String average = cal.sumValue(values); // String average = cal.sumValue(values);
System.out.println(average); // System.out.println(average);
// Map<String,String> map = new HashMap<>(); // Map<String,String> map = new HashMap<>();
// map.put("1", "NaN"); // map.put("1", "NaN");
...@@ -223,5 +223,9 @@ public class CalculateUtils { ...@@ -223,5 +223,9 @@ public class CalculateUtils {
// CalculateUtils cal = new CalculateUtils(); // CalculateUtils cal = new CalculateUtils();
// Map<String,Integer> result = cal.rankValue(map, "1"); // Map<String,Integer> result = cal.rankValue(map, "1");
// System.out.println(result); // System.out.println(result);
String version = "1.0";
double anoterVersion = Double.valueOf(version)+1;
System.out.println(String.valueOf(anoterVersion));
} }
} }
<?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.indicators.BaseIndDefMapper">
<select id="getPageByKeyword" parameterType="map" resultType="com.keymobile.indicators.model.entity.indicators.BaseIndDef" >
select *
from base_ind_def
where 1=1
<if test="catalogId!=null">
and catalog_id = #{catalogId}
</if>
<if test="keyword!=null">
and (ind_name like #{keyword} or ind_id like #{keyword})
</if>
limit #{start},#{end}
</select>
<select id="getByKeywordCount" parameterType="map" resultType="java.lang.Integer">
select count(1)
from base_ind_def
where 1=1
<if test="catalogId!=null">
and catalog_id = #{catalogId}
</if>
<if test="keyword!=null">
and (ind_name like #{keyword} or ind_id like #{keyword})
</if>
</select>
<delete id="deleteByCatalogIdIn" parameterType="java.util.List">
delete
from base_ind_def t
where t.catalog_id in
<foreach item="id" collection="list" 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.indicators.DriveIndDefMapper">
<select id="getPageByKeyword" parameterType="map" resultType="com.keymobile.indicators.model.entity.indicators.DriveIndDef" >
select *
from drive_ind_def
where 1=1
<if test="catalogId!=null">
and catalog_id = #{catalogId}
</if>
<if test="keyword!=null">
and (ind_name like #{keyword} or ind_id like #{keyword})
</if>
limit #{start},#{end}
</select>
<select id="getByKeywordCount" parameterType="map" resultType="java.lang.Integer">
select count(1)
from drive_ind_def
where 1=1
<if test="catalogId!=null">
and catalog_id = #{catalogId}
</if>
<if test="keyword!=null">
and (ind_name like #{keyword} or ind_id like #{keyword})
</if>
</select>
<delete id="deleteByCatalogIdIn" parameterType="java.util.List">
delete
from drive_ind_def t
where t.catalog_id in
<foreach item="id" collection="list" 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