Commit 3543c5b1 by zhangkb

添加子首页获取特定指标信息接口

parent b738861d
package com.keymobile.indicators.api.report;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.keymobile.indicators.service.report.IndexReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@Api(tags={"子首页-数据接口"})
@RestController
@RequestMapping(value = "/indexReport")
public class IndexReportCtrl {
@Autowired
private IndexReportService indexReportService;
@ApiOperation(value = "获取特定指标信息", notes = "获取特定指标信息")
@PostMapping(value = "/getIndicatorInfo")
public List<Map<String, Object>> dealReportOne(@RequestBody Map<String,Integer> indIdMap,@RequestParam String compareObj) {
return indexReportService.getLatestIndiInfo(indIdMap, compareObj);
}
}
......@@ -59,4 +59,8 @@ public interface DriveIndCalResultDefMapper extends BaseMapper<DriveIndCalResult
public void batchSave(@Param("datas")List<DriveIndCalResultDef> datas);
//批量修改
public void batchUpdate(@Param("datas")List<DriveIndCalResultDef> datas);
//根据指标编号和对标单位根据对标时间降序获取指标考核结果
public List<DriveIndCalResultDef> findByIndIdAndCompareObjOrderByDateDesc(@Param("indId") String indId,
@Param("compareObj") String compareObj);
}
package com.keymobile.indicators.service.report;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
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.DriveIndCalResultDef;
import com.keymobile.indicators.model.entity.indicators.DriveIndDef;
import com.keymobile.indicators.model.mapper.indicators.DriveIndDefMapper;
import com.keymobile.indicators.model.mapper.indmapper.DriveIndCalResultDefMapper;
import com.keymobile.indicators.utils.CalculateUtils;
/**
* author:zhangkb time:2020-8-3 desc:提供子首页数据接口服务
*/
@Service
public class IndexReportService {
@Autowired
private DriveIndCalResultDefMapper driveIndCalResultDefMapper;
@Autowired
private DriveIndDefMapper driveIndDefMapper;
//获取省指标信息
public List<Map<String,Object>> getLatestIndiInfo(Map<String,Integer> indIdMap,String compareObj){
List<Map<String,Object>> result = new ArrayList<>();
if(!indIdMap.isEmpty()) {
for(Map.Entry<String, Integer> entry : indIdMap.entrySet()) {
Map<String,Object> indMap = new HashMap<>();
//根据指标id获取指标信息
DriveIndDef driveIndDef = driveIndDefMapper.selectByPrimaryKey(entry.getKey());
if(driveIndDef!=null) {
indMap.put("indId",driveIndDef.getIndId());
indMap.put("indName", driveIndDef.getIndName());
indMap.put("indUnit", driveIndDef.getIndUnit());
//根据指标编号和对标对象获取最新的对标考核数据
List<DriveIndCalResultDef> calResults = driveIndCalResultDefMapper.
findByIndIdAndCompareObjOrderByDateDesc(entry.getKey(), compareObj);
int date = 0;
if(!calResults.isEmpty()) {
indMap.put("value", calResults.get(0).getValue());
date = calResults.get(0).getDate();
//获取同期值
DriveIndCalResultDef sameResult = driveIndCalResultDefMapper.
findByIndIdAndDateAndCompareObj(entry.getKey(), date, compareObj);
if(sameResult!=null) {
//获取指标的同比类型以及指标的正反向类型
String growCalType = driveIndDef.getGrowCalType();
String indRule = driveIndDef.getIndRule();
String rate = CalculateUtils.calGowth(calResults.get(0).getValue(),
sameResult.getValue(), growCalType);
indMap.put("rate", rate);
if(StringUtils.isNotBlank(indRule) && StringUtils.isNotBlank(rate)) {
if("0".equals(indRule)) {//正向
indMap.put("trend", "0");//趋差
if(Double.parseDouble(rate)>0) {
indMap.put("trend", "1");//趋好
}
}else {//反向
indMap.put("trend", "0");//趋差
if(Double.parseDouble(rate)<0) {
indMap.put("trend", "1");//趋好
}
}
}else {
indMap.put("trend", "");
}
}else {
indMap.put("rate", "");
indMap.put("trend", "");
}
}else {
indMap.put("value", "");
indMap.put("rate", "");
indMap.put("trend", "");
}
indMap.put("index", entry.getValue());
result.add(indMap);
}
}
//对list根据map中的index进行排序
Collections.sort(result, new Comparator<Map<String, Object>>() {
@Override
public int compare(Map<String, Object> o1, Map<String, Object> o2) {
int map1value = (Integer) o1.get("index");
int map2value = (Integer) o2.get("index");
return map1value - map2value;
}
});
}
return result;
}
}
......@@ -221,4 +221,13 @@
where id = ${val.id}
</foreach>
</update>
<select id="findByIndIdAndCompareObjOrderByDateDesc" resultType="com.keymobile.indicators.model.entity.indicators.DriveIndCalResultDef" >
select *
from drive_ind_cal_result_def
where
ind_id=#{indId} and
compare_obj=#{compareObj}
ORDER BY date desc
</select>
</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