Browse Source

修改bug 如果有小数 就保留2位小数(包括0) 没有小数的就只显示整数部分

wangxingwang 6 years ago
parent
commit
341513ae5c

+ 8 - 16
src/main/java/com/yihu/quota/controller/QuotaReportController.java

@ -37,7 +37,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.*;
@ -69,6 +68,8 @@ public class QuotaReportController extends BaseController {
    @Autowired
    private DeviceService deviceService;
    private BasesicUtil basesicUtil = new BasesicUtil();
    public static String orgHealthCategoryCode = "orgHealthCategoryCode";
    @RequestMapping(value = ServiceApi.TJ.GetYearDropdownList, method = RequestMethod.GET)
@ -145,9 +146,6 @@ public class QuotaReportController extends BaseController {
            @ApiParam(name = "top", value = "获取前几条数据")
            @RequestParam(value = "top", required = false) String top
    ) {
        NumberFormat nf = NumberFormat.getInstance();
        nf.setGroupingUsed(false);
        nf.setMaximumFractionDigits(2);
        List<Map<String, Object>> dataList = new ArrayList<>();
        Map<String, List<Map<String, Object>>> quotaViewResult = new HashMap<>();
        List<String> quotaCodes = Arrays.asList(quotaCodeStr.split(","));
@ -170,13 +168,13 @@ public class QuotaReportController extends BaseController {
            }
            //以查询结果数据最多的指标为主,其他指标对应维度没有数据的补充0
            for (Map<String, Object> vMap : quotaViewResult.get(maxQuotaCode)) {
                vMap.put(maxQuotaCode, vMap.get("result")==null ? 0 : ("--".equals(vMap.get("result")) ? vMap.get("result") : nf.format(Double.valueOf(vMap.get("result").toString()))));
                vMap.put(maxQuotaCode, vMap.get("result")==null ? 0 : ("--".equals(vMap.get("result")) ? vMap.get("result") : basesicUtil.decimalPointHandle(Double.valueOf(vMap.get("result").toString()))));
                for (String viewQuotaCode : otherQuotaViewResult.keySet()) {
                    if(otherQuotaViewResult != null && otherQuotaViewResult.get(viewQuotaCode) != null && otherQuotaViewResult.get(viewQuotaCode).size()>0 ){
                        for (Map<String, Object> quotaResultMap : otherQuotaViewResult.get(viewQuotaCode)) {
                            if (quotaResultMap.get(dimension) != null && vMap.get(dimension) != null ) {
                                if (vMap.get(dimension).toString().trim().equals(quotaResultMap.get(dimension).toString().trim())) {
                                    vMap.put(viewQuotaCode, quotaResultMap.get("result")==null ? 0 : ("--".equals(quotaResultMap.get("result")) ? quotaResultMap.get("result") : nf.format(Double.valueOf(quotaResultMap.get("result").toString()))));
                                    vMap.put(viewQuotaCode, quotaResultMap.get("result")==null ? 0 : ("--".equals(quotaResultMap.get("result")) ? quotaResultMap.get("result") : basesicUtil.decimalPointHandle(Double.valueOf(quotaResultMap.get("result").toString()))));
                                    break;
                                } else {
                                    if( !vMap.get(dimension).toString().equals("合计")){
@ -243,9 +241,9 @@ public class QuotaReportController extends BaseController {
                if( total.equals("false") || total.equals("--")){
                    double sum = 0;
                    sum = calculateSum(sum,code,dataList);
                    sumMap.put(code, nf.format(sum));
                    sumMap.put(code, basesicUtil.decimalPointHandle(sum));
                }else {
                    sumMap.put(code, nf.format(Double.valueOf(total)));
                    sumMap.put(code, basesicUtil.decimalPointHandle(Double.valueOf(total)));
                }
            }
            dataList.add(0,sumMap);
@ -910,16 +908,13 @@ public class QuotaReportController extends BaseController {
                lineNames.add(tjQuota.getName());
                i++;
            }
            NumberFormat nf = NumberFormat.getInstance();
            nf.setGroupingUsed(false);
            nf.setMaximumFractionDigits(2);
            Set<String> hashSet = new HashSet<>(lineNames);
            Map<String, Object> newMap = new HashMap<>();
            for (Map<String, Object> data : lineData.values()) {
                for (Map.Entry<String, Object> lastMap : data.entrySet()) {
                    if (newMap.containsKey(lastMap.getKey())) {
                        double v = Double.parseDouble(newMap.get(lastMap.getKey()) + "") + Double.parseDouble(lastMap.getValue() + "");
                        newMap.put(lastMap.getKey() + "", nf.format(v));
                        newMap.put(lastMap.getKey() + "", basesicUtil.decimalPointHandle(v));
                    } else {
                        newMap.put(lastMap.getKey(), lastMap.getValue());
                    }
@ -1034,16 +1029,13 @@ public class QuotaReportController extends BaseController {
     */
    public List<List<Object>> discountByMeasurement(List<List<Object>> optionData, String dataMeasurement) {
        if (!StringUtils.isEmpty(dataMeasurement)) {
            NumberFormat nf = NumberFormat.getInstance();
            nf.setGroupingUsed(false);
            nf.setMaximumFractionDigits(2);
            List<List<Object>> handleList = new ArrayList<>();
            double v = Double.parseDouble(dataMeasurement);
            optionData.forEach(one -> {
                List<Object> list = new ArrayList<>();
                one.forEach(item -> {
                    if(item != null && !item.toString().equals("--")){
                        item = nf.format(Double.parseDouble(item.toString()) / v);
                        item = basesicUtil.decimalPointHandle(Double.parseDouble(item.toString()) / v);
                        list.add(item);
                    }else {
                        list.add(0);

+ 0 - 8
src/main/java/com/yihu/quota/service/medicalInsurance/MedicalInsuranceService.java

@ -210,14 +210,6 @@ public class MedicalInsuranceService {
        list = list.subList((page - 1) * size, ((page - 1) * size + size) > list.size() ? list.size() : (page - 1) * size + size);
        // 判断solr中获取的家庭地址是否有值,没有的话到hbase中查询
        list.forEach(one -> {
            Object address = one.get("EHR_001211");
            if (null == address) {
                Map<String, Object> resultMap = hBaseDao.getResultMap(ResourceCore.MasterTable, one.get("rowkey") + "");
                one.put("address", null != resultMap.get("EHR_001211") ? resultMap.get("EHR_001211") + "" : "");
            }
        });
        envelop.setCurrPage(page);
        envelop.setPageSize(size);
        envelop.setTotalCount(totalCount);

+ 22 - 66
src/main/java/com/yihu/quota/service/quota/BaseStatistsService.java

@ -31,7 +31,6 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.*;
@ -68,6 +67,8 @@ public class BaseStatistsService {
    @Autowired
    private TjDataSaveService dataSaveService;
    private BasesicUtil basesicUtil = new BasesicUtil();
    private static String orgHealthCategory = "orgHealthCategory";
    public static String orgHealthCategoryCode = "orgHealthCategoryCode";
    public static String resultField = "result";
@ -145,9 +146,6 @@ public class BaseStatistsService {
    public List<Map<String, Object>> addition(String dimension, List<Map<String, Object>> firstList, List<Map<String, Object>> secondList,int operation){
        List<Map<String, Object>> addResultList = new ArrayList<>();
        NumberFormat nf = NumberFormat.getInstance();
        nf.setGroupingUsed(false);
        nf.setMaximumFractionDigits(2);
        List<Map<String, Object>> otherList = new ArrayList<>();
        otherList = secondList;
        String [] moleDimensions = dimension.split(";");
@ -191,7 +189,7 @@ public class BaseStatistsService {
                        }else if(operation == 2){ //2 减法
                            point = first.subtract(second).doubleValue();
                        }
                        map.put(resultField,nf.format(point));
                        map.put(resultField, basesicUtil.decimalPointHandle(point));
                        addResultList.add(map);
                        pflag = false;
                        otherList.remove(secondMap);
@ -199,7 +197,7 @@ public class BaseStatistsService {
                    }
                }
                if(pflag){
                    map.put(resultField, nf.format(firstResultVal));
                    map.put(resultField, basesicUtil.decimalPointHandle(firstResultVal));
                    addResultList.add(map);
                }
            }
@ -221,7 +219,7 @@ public class BaseStatistsService {
                        point = -secondResultVal;
                    }
                }
                map.put(resultField, nf.format(point));
                map.put(resultField, basesicUtil.decimalPointHandle(point));
                addResultList.add(map);
            }
        }
@ -382,15 +380,12 @@ public class BaseStatistsService {
                divisionResultList.add(map);
            } else {
                double point = 0;
                NumberFormat df = NumberFormat.getInstance();
                df.setGroupingUsed(false);
                df.setMaximumFractionDigits(2);
                if (operation == 1) {
                    point = (moleResultVal / denominatorVal) * operationValue;
                } else if (operation == 2) {
                    point =  (moleResultVal / denominatorVal) / operationValue;
                }
                map.put(resultField, df.format(point));
                map.put(resultField, basesicUtil.decimalPointHandle(point));
                divisionResultList.add(map);
            }
        }
@ -447,9 +442,6 @@ public class BaseStatistsService {
                        }
                        if(moleKeyVal.equals(dimenKeyVal)){
                            double point = 0;
                            NumberFormat df = NumberFormat.getInstance();
                            df.setGroupingUsed(false);
                            df.setMaximumFractionDigits(2);
                            float dimeResultVal = Float.valueOf(denoMap.get(resultField).toString());
                            if(dimeResultVal != 0){
                                if(operation == 1){
@ -458,7 +450,7 @@ public class BaseStatistsService {
                                    point = (moleResultVal/dimeResultVal) / operationValue;
                                }
                            }
                            map.put(resultField,df.format(point));
                            map.put(resultField, basesicUtil.decimalPointHandle(point));
                            divisionResultList.add(map);
                            break;
                        }
@ -622,9 +614,6 @@ public class BaseStatistsService {
    //获取该节点下所有末节点的结果和
    public   Map<String,Object> getParentAllChildren(List<String> quotaCodes, Map<String,Object> mapCategory,Map<String,Object> returnMap, List<Map<String, Object>> dimenListResult, double parentResult ){
        try {
                NumberFormat df = NumberFormat.getInstance();
                df.setGroupingUsed(false);
                df.setMaximumFractionDigits(2);
                boolean childrenFlag = false;
                if(mapCategory.get("children") != null){
                    List<Map<String,Object>> childrenOrgHealthCategoryList = (List<Map<String, Object>>) mapCategory.get("children");
@ -647,14 +636,14 @@ public class BaseStatistsService {
                                if(returnMap.get(resultField) != null){
                                    oldResult = Double.parseDouble(returnMap.get(resultField).toString());
                                }
                                returnMap.put(resultField,df.format(result + oldResult));
                                returnMap.put(resultField, basesicUtil.decimalPointHandle(result + oldResult));
                                for(String quotaCode : quotaCodes){
                                    double quotaResult = Double.parseDouble(dimenMap.get(quotaCode).toString());
                                    double oldQuotaResult = 0;
                                    if( returnMap.get(quotaCode) != null ){
                                        oldQuotaResult = Double.parseDouble(returnMap.get(quotaCode).toString());
                                    }
                                    returnMap.put(quotaCode,df.format(quotaResult + oldQuotaResult));
                                    returnMap.put(quotaCode, basesicUtil.decimalPointHandle(quotaResult + oldQuotaResult));
                                }
                                break;
                            }
@ -743,10 +732,7 @@ public class BaseStatistsService {
                    dataMap.put(firstColumnField,map.get("text"));
                }
                if(key.equals("SUM(result)")){
                    NumberFormat nf = NumberFormat.getInstance();
                    nf.setGroupingUsed(false);
                    nf.setMaximumFractionDigits(2);
                    dataMap.put(resultField,  nf.format(map.get(key)));
                    dataMap.put(resultField, basesicUtil.decimalPointHandle(map.get(key)));
                }
            }
             resultList.add(dataMap);
@ -792,10 +778,7 @@ public class BaseStatistsService {
                    dataMap.put(map.get(orgHealthCategoryCode).toString(),map.get(orgHealthCategoryCode));
                }
                if(key.equals("SUM(result)")){
                    NumberFormat nf = NumberFormat.getInstance();
                    nf.setGroupingUsed(false);
                    nf.setMaximumFractionDigits(2);
                    dataMap.put(resultField,  nf.format(map.get(key)));
                    dataMap.put(resultField, basesicUtil.decimalPointHandle(map.get(key)));
                }
                if(key.equals(quotaDateField)){
                    SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM-dd");
@ -868,10 +851,7 @@ public class BaseStatistsService {
                    dataMap.put(firstColumnField,map.get("text"));
                }
                if(key.equals("SUM(result)")){
                    NumberFormat nf = NumberFormat.getInstance();
                    nf.setGroupingUsed(false);
                    nf.setMaximumFractionDigits(2);
                    dataMap.put(resultField,  nf.format(map.get(key)));
                    dataMap.put(resultField, basesicUtil.decimalPointHandle(map.get(key)));
                }
            }
            resultList.add(dataMap);
@ -1221,9 +1201,6 @@ public class BaseStatistsService {
                    }
                }
                double point = 0;
                NumberFormat df = NumberFormat.getInstance();
                df.setGroupingUsed(false);
                df.setMaximumFractionDigits(2);
                int operation = Integer.valueOf(esConfig.getPercentOperation());
                int operationValue = Integer.valueOf(esConfig.getPercentOperationValue());
                if(denoTotal - 0 != 0){
@ -1236,7 +1213,7 @@ public class BaseStatistsService {
                    }
                }
                Map<String, Object> totalMap = new HashMap<>();
                totalMap.put(resultField,df.format(point));
                totalMap.put(resultField, basesicUtil.decimalPointHandle(point));
                totalMap.put(dimension,"合计");
                totalMap.put(firstColumnField,"合计");
                result.add(totalMap);
@ -1326,12 +1303,9 @@ public class BaseStatistsService {
        String sum = "0";
        String sql = "select sum(result) from medical_service_index where quotaCode='HC041047'";
        List<Map<String, Object>> listData = elasticsearchUtil.excuteDataModel(sql);
        NumberFormat nf = NumberFormat.getInstance();
        nf.setGroupingUsed(false);
        nf.setMaximumFractionDigits(2);
        if (null != listData && listData.size() > 0 && listData.get(0).size() > 0) {
            for (Map<String, Object> map : listData) {
                sum = nf.format(map.get("SUM(result)"));
                sum = basesicUtil.decimalPointHandle(map.get("SUM(result)"));
            }
        }
        return sum;
@ -1345,12 +1319,9 @@ public class BaseStatistsService {
        int sum = 0;
        String sql = "select sum(result) from medical_service_index where quotaCode='HC041008'";
        List<Map<String, Object>> listData = singleDiseaseService.parseIntegerValue(sql);
        NumberFormat nf = NumberFormat.getInstance();
        nf.setGroupingUsed(false);
        nf.setMaximumFractionDigits(2);
        if (null != listData && listData.size() > 0 && listData.get(0).size() > 0) {
            for (Map<String, Object> map : listData) {
                String value = nf.format(map.get("SUM(result)"));
                String value = basesicUtil.decimalPointHandle(map.get("SUM(result)"));
                sum += Integer.parseInt(value);
            }
        }
@ -1365,12 +1336,9 @@ public class BaseStatistsService {
        String sum = "0";
        String sql = "select sum(result) from medical_service_index where quotaCode='HC041068'";
        List<Map<String, Object>> listData = elasticsearchUtil.excuteDataModel(sql);
        NumberFormat nf = NumberFormat.getInstance();
        nf.setGroupingUsed(false);
        nf.setMaximumFractionDigits(2);
        if (null != listData && listData.size() > 0 && listData.get(0).size() > 0) {
            for (Map<String, Object> map : listData) {
                sum = nf.format(map.get("SUM(result)"));
                sum = basesicUtil.decimalPointHandle(map.get("SUM(result)"));
            }
        }
        return sum;
@ -1384,12 +1352,9 @@ public class BaseStatistsService {
        int sum = 0;
        String sql = "select sum(result) from medical_service_index where quotaCode='HC041000'";
        List<Map<String, Object>> listData = singleDiseaseService.parseIntegerValue(sql);
        NumberFormat nf = NumberFormat.getInstance();
        nf.setGroupingUsed(false);
        nf.setMaximumFractionDigits(2);
        if (null != listData && listData.size() > 0 && listData.get(0).size() > 0) {
            for (Map<String, Object> map : listData) {
                String value = nf.format(map.get("SUM(result)"));
                String value = basesicUtil.decimalPointHandle(map.get("SUM(result)"));
                sum += Integer.parseInt(value);
            }
        }
@ -1397,16 +1362,13 @@ public class BaseStatistsService {
    }
    public String getCostOfMedicalMonitor() {
        NumberFormat nf = NumberFormat.getInstance();
        nf.setGroupingUsed(false);
        nf.setMaximumFractionDigits(2);
        // 获取门急诊费用
        Double costOfOutPatient = Double.parseDouble(getCostOfOutPatient());
        // 获取入院费用
        Double costOfInPatient = Double.parseDouble(getCostOfInPatient());
        // 医疗费用监测 = 获取门急诊费用 + 获取入院费用
        Double costOfMedicalMonitor = costOfInPatient + costOfOutPatient;
        return nf.format(costOfMedicalMonitor);
        return basesicUtil.decimalPointHandle(costOfMedicalMonitor);
    }
@ -1519,12 +1481,9 @@ public class BaseStatistsService {
                            }
                            if(denoKeyVal.equals(moleKeyVal)){
                                double point = 0;
                                NumberFormat nf = NumberFormat.getInstance();
                                nf.setGroupingUsed(false);
                                nf.setMaximumFractionDigits(2);
                                float moleResultVal = Float.valueOf(moleMap.get(resultField).toString());
                                point = ((moleResultVal - denoResultVal)/denoResultVal) * operationValue;
                                map.put(resultField, nf.format(point));
                                map.put(resultField, basesicUtil.decimalPointHandle(point));
                                divisionResultList.add(map);
                                break;
                            }
@ -1735,9 +1694,6 @@ public class BaseStatistsService {
            }
            dimension = dateType;
            List<Map<String, Object>> dataList = getSimpleQuotaReport(esConfig.getMolecular(), filters,dimension ,false , null);
            NumberFormat df = NumberFormat.getInstance();
            df.setGroupingUsed(false);
            df.setMaximumFractionDigits(2);
            if(dataList != null && dataList.size() > 0){
                if(dateType.toLowerCase().equals("year")){
                    for(int i = nowYear ; i > beforeYear ;i--){
@ -1759,7 +1715,7 @@ public class BaseStatistsService {
                            map.put(resultField,"--");
                        }else {
                            double precent = (current - last)/last*100;
                            map.put(resultField,precent-0 ==0 ? 0 : df.format(precent));
                            map.put(resultField,precent-0 ==0 ? 0 : basesicUtil.decimalPointHandle(precent));
                        }
                        resultList.add(map);
                        if(i-beforeYear <= 0){
@ -1830,7 +1786,7 @@ public class BaseStatistsService {
                            if(precent == 0){
                                map.put(resultField,0);
                            }else {
                                map.put(resultField,precent-0 ==0 ? 0 : df.format(precent));
                                map.put(resultField,precent-0 ==0 ? 0 : basesicUtil.decimalPointHandle(precent));
                            }
                        }
                        resultList.add(map);
@ -1874,7 +1830,7 @@ public class BaseStatistsService {
                            if(precent == 0){
                                map.put(resultField,0);
                            }else {
                                map.put(resultField,precent-0 ==0 ? 0 : df.format(precent));
                                map.put(resultField,precent-0 ==0 ? 0 : basesicUtil.decimalPointHandle(precent));
                            }
                        }
                        resultList.add(map);

+ 19 - 0
src/main/java/com/yihu/quota/util/BasesicUtil.java

@ -2,6 +2,8 @@ package com.yihu.quota.util;
import java.lang.reflect.Method;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
@ -50,4 +52,21 @@ public class BasesicUtil {
        }
        return 0;
    }
    /**
     * 保留2位小数,如果有小数则保留2位小数
     * @param data
     * @return
     */
    public String decimalPointHandle(Object data) {
        DecimalFormat df = new DecimalFormat("#0.00");
        NumberFormat nf = NumberFormat.getInstance();
        nf.setGroupingUsed(false);
        nf.setMaximumFractionDigits(2);
        String format = nf.format(data);
        if (format.indexOf(".") != -1) {
            format = df.format(Double.parseDouble(format));
        }
        return format;
    }
}