yujian
2019-01-14 9aa8e6cc3deec513d046b5fc90f9672cc1c6ec7b
丢失订单曲线图
2个文件已修改
359 ■■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/controller/admin/LostOrderAdminController.java 219 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/LostOrderServiceImpl.java 140 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/admin/LostOrderAdminController.java
@@ -16,6 +16,8 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.yeshi.fanli.controller.admin.utils.AdminUtils;
import com.yeshi.fanli.entity.bus.user.LostOrder;
import com.yeshi.fanli.entity.bus.user.Order;
import com.yeshi.fanli.entity.bus.user.UserInfo;
@@ -219,34 +221,6 @@
    }
    
    
    /**
     * 验证统计信息参数
     * @param shwoType
     * @param startTime
     * @param endTime
     * @return
     */
    public String validateParams(Integer shwoType, String startTime, String endTime) {
        if (shwoType == null) {
            return "请选择视图类型";
        }
        if (shwoType == 1 && (StringUtil.isNullOrEmpty(startTime) && StringUtil.isNullOrEmpty(endTime))) {
            return "请选择时间区间";
        }
        if (!StringUtil.isNullOrEmpty(startTime) && StringUtil.isNullOrEmpty(endTime)) {
            return "请选结束日期";
        }
        if (StringUtil.isNullOrEmpty(startTime) && !StringUtil.isNullOrEmpty(endTime)) {
            return "请选起始日期";
        }
        return null;
    }
    /**
     * 统计提现申请总次数
@@ -259,45 +233,107 @@
     * @param out
     */
    @RequestMapping(value = "getLostNum")
    public void getLostNum(String callback, Integer dateType, Integer state, String year, String startTime,
            String endTime, PrintWriter out) {
    public void getLostNum(String callback, Integer dateType, String stateArray, String year,
            String startTime, String endTime, PrintWriter out) {
        String validateMsg = validateParams(dateType, startTime, endTime);
        String validateMsg = AdminUtils.validateParams(dateType, startTime, endTime);
        if (validateMsg != null) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(validateMsg));
            return;
        }
        if (dateType != 1 && (!StringUtil.isNullOrEmpty(startTime) || !StringUtil.isNullOrEmpty(endTime))) {
            startTime = null;
            endTime = null;
        }
        List<Integer> channelList = null;
        if (stateArray != null && stateArray.trim().length() > 0) {
            Gson gson = new Gson();
            channelList = gson.fromJson(stateArray, new TypeToken<ArrayList<Integer>>() {}.getType());
        }
        if (dateType == 1 && year != null) {
            year = null; // 设置为空
        } else if (dateType == 2) {
            if (startTime != null)
                startTime = null;
            if (endTime != null)
                endTime = null;
        } else if (dateType == 3) {
            if (year != null)
                year = null;
            if (startTime != null)
                startTime = null;
            if (endTime != null)
                endTime = null;
        }
        Gson gson = new Gson();
        Object objectDate = null;
        List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
        try {
            
            if (dateType != 1 && (!StringUtil.isNullOrEmpty(startTime) || !StringUtil.isNullOrEmpty(endTime))) {
                startTime = null;
                endTime = null;
            JSONArray line_list = new JSONArray();
            if (channelList == null || channelList.size() == 0) {
            } else {
                for (Integer state : channelList) {
                    List<Map<String, Object>> list = lostOrderService.countLostNum(dateType, state, year,
                            startTime, endTime);
                    JSONObject innerList = new JSONObject();
                    if (state == 1) {
                        innerList.put("name", "未处理");
                    } else if (state == 2) {
                        innerList.put("name", "成功");
                    } else if (state == 3) {
                        innerList.put("name", "失败");
                    }
                    if (dateType != 3) {
                        innerList.put("data", gson.toJson(AdminUtils.dayOrMonthDataFactory(dateType, dateList, list)));
                    } else {
                        // 年视图
                        Map<String, Object> map = AdminUtils.yearsDataFactory(list);
                        if (objectDate == null) {
                            objectDate = map.get("date");
                        }
                        innerList.put("data", gson.toJson(map.get("value")));
                    }
                    line_list.add(innerList);
                }
            }
            List<Map<String, Object>> resultList =lostOrderService.countLostNum(dateType, state, year,
                    startTime, endTime);
            if (resultList == null) {
                resultList = new ArrayList<Map<String,Object>>();
            }
            JSONObject innerList = new JSONObject();
            innerList.put("name", "数量");
            innerList.put("data_list", resultList);
            JSONArray outList = new JSONArray();
            outList.add(innerList);
            JSONObject data = new JSONObject();
            data.put("result_list", outList);
            if (objectDate != null) {
                data.put("xAxis_list", gson.toJson(objectDate));
            } else {
                data.put("xAxis_list", gson.toJson(dateList));
            }
            data.put("line_list", line_list);
            
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("系统异常"));
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
            e.printStackTrace();
        }
    }
    
    /**
@@ -313,38 +349,81 @@
    public void getAppealMoney(String callback, Integer dateType, String year, String startTime, String endTime,
            PrintWriter out) {
        String validateMsg = validateParams(dateType, startTime, endTime);
        String validateMsg = AdminUtils.validateParams(dateType, startTime, endTime);
        if (validateMsg != null) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(validateMsg));
            return;
        }
        if (dateType != 1 && (!StringUtil.isNullOrEmpty(startTime) || !StringUtil.isNullOrEmpty(endTime))) {
            startTime = null;
            endTime = null;
        }
        if (dateType == 1 && year != null) {
            year = null; // 设置为空
        } else if (dateType == 2) {
            if (startTime != null)
                startTime = null;
            if (endTime != null)
                endTime = null;
        } else if (dateType == 3) {
            if (year != null)
                year = null;
            if (startTime != null)
                startTime = null;
            if (endTime != null)
                endTime = null;
        }
        Gson gson = new Gson();
        Object objectDate = null;
        List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
        try {
            if (dateType != 1 && (!StringUtil.isNullOrEmpty(startTime) || !StringUtil.isNullOrEmpty(endTime))) {
                startTime = null;
                endTime = null;
            }
            List<Map<String, Object>> resultList =lostOrderService.countAppealMoney(dateType, year, startTime, endTime);
            if (resultList == null) {
                resultList = new ArrayList<Map<String,Object>>();
            JSONArray line_list = new JSONArray();
            List<Map<String, Object>> list = lostOrderService.countAppealMoney(dateType, year, startTime, endTime);
            JSONObject innerList = new JSONObject();
                innerList.put("name", "总计");
            if (dateType != 3) {
                innerList.put("data", gson.toJson(AdminUtils.dayOrMonthDataFactory(dateType, dateList, list)));
            } else {
                // 年视图
                Map<String, Object> map = AdminUtils.yearsDataFactory(list);
                if (objectDate == null) {
                    objectDate = map.get("date");
                }
                innerList.put("data", gson.toJson(map.get("value")));
            }
            
            JSONObject innerList = new JSONObject();
            innerList.put("name", "金额");
            innerList.put("data_list", resultList);
            JSONArray outList = new JSONArray();
            outList.add(innerList);
            line_list.add(innerList);
            JSONObject data = new JSONObject();
            data.put("result_list", outList);
            if (objectDate != null) {
                data.put("xAxis_list", gson.toJson(objectDate));
            } else {
                data.put("xAxis_list", gson.toJson(dateList));
            }
            data.put("line_list", line_list);
            
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("系统异常"));
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
            e.printStackTrace();
        }
    }
fanli/src/main/java/com/yeshi/fanli/service/impl/order/LostOrderServiceImpl.java
@@ -287,23 +287,7 @@
    @Override
    public List<Map<String, Object>> countLostNum( Integer dateType, Integer resultCode, 
            String year, String startTime, String endTime) throws Exception {
        List<Map<String, Object>> list = lostOrderMapper.countLostNum(dateType, resultCode, year, startTime, endTime);
        if (list == null || list.size() == 0) {
            return null;
        }
        switch (dateType){
            case 1: // 按天处理
                return dayFactory(startTime, endTime, list);
            case 2: // 按月处理
                return monthFactory(list);
            case 3:
                return yearFactory(list);
            default:
                return null;
        }
        return lostOrderMapper.countLostNum(dateType, resultCode, year, startTime, endTime);
    }
    
    
@@ -311,127 +295,7 @@
    public List<Map<String, Object>> countAppealMoney( Integer dateType, String year, String startTime, 
            String endTime) throws Exception {
        
        List<Map<String, Object>> list = lostOrderMapper.countAppealMoney(dateType, year, startTime, endTime);
        if (list == null || list.size() == 0) {
            return null;
        }
        switch (dateType){
            case 1: // 按天处理
                return dayFactory(startTime, endTime, list);
            case 2: // 按月处理
                return monthFactory(list);
            case 3:
                return yearFactory(list);
            default:
                return null;
        }
        return lostOrderMapper.countAppealMoney(dateType, year, startTime, endTime);
    }
    
    public List<Map<String, Object>> dayFactory(String startTime, String endTime, List<Map<String, Object>> list) throws Exception {
        List<Map<String, Object>> listObject = new ArrayList<Map<String, Object>>();
        if (startTime.equals(endTime)) {
            Map<String, Object> map = list.get(0);
            Object total = map.get("showValue");
            if (total == null) {
                map.put("showValue", 0);
            }
            listObject.add(map);
            return listObject;
        }
        String plusDay = "";
        for (int i = 0; i < 1000; i++) {
            if (i == 0) {
                plusDay = startTime;
            } else {
                plusDay = DateUtil.plusDay(i, startTime);
            }
            Map<String, Object> mapObject = new HashMap<String, Object>();
            Object total = null;
            for (int j = 0; j < list.size(); j++) {
                Map<String, Object> map = list.get(j);
                Object createDate = map.get("showDate");
                String month = createDate.toString();
                if (plusDay.equalsIgnoreCase(month)) {
                    total = map.get("showValue");
                    break;
                }
            }
            if (total == null) {
                total = 0;
            }
            mapObject.put("showValue", total);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/MM/dd");
            Date parseDate = sdf.parse(plusDay.toString());
            mapObject.put("showDate", sdf2.format(parseDate));
            listObject.add(mapObject);
            if (plusDay.equals(endTime)) {
                break; // 时间结束
            }
        }
        return listObject;
    }
    public List<Map<String, Object>> monthFactory(List<Map<String, Object>> list) {
        List<Map<String, Object>> listObject = new ArrayList<Map<String, Object>>();
        // 12 个月处理
        for (int i = 1; i <= 12; i++) {
            Map<String, Object> mapObject = new HashMap<String, Object>();
            Object total = null;
            for (int j = 0; j < list.size(); j++) {
                Map<String, Object> map = list.get(j);
                Object createDate = map.get("showDate");
                String month = createDate.toString();
                if ((i + "").equalsIgnoreCase(month) || i == Integer.parseInt(month)) {
                    total = map.get("total");
                    break;
                }
            }
            if (total == null) {
                total = 0;
            }
            mapObject.put("total", total);
            mapObject.put("showDate", i + "月");
            listObject.add(mapObject);
        }
        return listObject;
    }
    public List<Map<String, Object>> yearFactory(List<Map<String, Object>> list) {
        List<Map<String, Object>> listObject = new ArrayList<Map<String, Object>>();
        for (int i = 0; i < list.size(); i++) {
            Map<String, Object> map = list.get(i);
            Object total = map.get("total");
            if (total == null) {
                total = 0;
            }
            map.put("total", total);
            listObject.add(map);
        }
        return listObject;
    }
}