yujian
2020-05-09 7e7db2fa55a9a3af46d4fd8ede0dee147f101d64
fanli/src/main/java/com/yeshi/fanli/controller/admin/utils/AdminUtils.java
@@ -5,13 +5,14 @@
import java.util.List;
import java.util.Map;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.yeshi.utils.DateUtil;
import com.google.gson.Gson;
import com.yeshi.fanli.dto.ChartTDO;
import com.yeshi.fanli.util.StringUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public class AdminUtils {
@@ -59,27 +60,28 @@
         for (int i = 1; i <= 12; i++) {
            dateList.add(i + ""); // 12个月
         }
      } else if (dateType == 3) {
         for (int i = 2018; i <= 2030; i++) {
            dateList.add(i + ""); // 10年
         }
      }
      
      return dateList;                   
   }
   
   
   public static Map<String, Object> yearsDataFactory(List<Map<String, Object>> list) {
   public static Map<String, Object> yearsDataFactory(List<ChartTDO> list) {
      List<Object> resultList = new ArrayList<Object>();
      List<Object> listDate = new ArrayList<Object>();
      
      if (list != null && list.size() > 0) {
         for (int i = 0; i < list.size(); i++) {
            Map<String, Object> map = list.get(i);
            Object showValue = map.get("showValue");
            Object showDate = map.get("showDate");
         for (ChartTDO chart: list) {
            String showDate = chart.getShowDate();
            String showValue = chart.getShowValue();
            if (showValue == null) {
               showValue = 0;
               showValue = "0";
            }
            resultList.add(showValue);
            listDate.add(showDate);
         }
@@ -94,36 +96,31 @@
   
   
   public static List<Object> dayOrMonthDataFactory(List<String> listDate , List<Map<String, Object>> list) throws Exception {
   public static List<Object> dayOrMonthDataFactory(Integer dateType, List<String> listDate ,
         List<ChartTDO> list) throws Exception {
      List<Object> resultList = new ArrayList<Object>();
      if (list != null && list.size() > 0) {
         for (int i = 0; i < listDate.size(); i++) {
            Object showValue = null;
            if (list != null && list.size() > 0) {
               // 日期匹配赋值
               for (int j = 0; j < list.size(); j++) {
                  Map<String, Object> map = list.get(j);
                  String showDate = listDate.get(i);
                  Object reslutDate = map.get("showDate");
                  String month = reslutDate.toString();
                  if (showDate.equalsIgnoreCase(month)) {
                     showValue = map.get("showValue");
                     break;
                  }
            String showValue = null;
            // 日期匹配赋值
            for (ChartTDO chart: list) {
               String showDate = listDate.get(i);
               if (dateType == 2 && Integer.parseInt(showDate) < 10 ) {
                  showDate = "0" + showDate;
               }
               String reslutTime = chart.getShowDate();
               if (showDate.equalsIgnoreCase(reslutTime)) {
                  showValue = chart.getShowValue();
                  break;
               }
            }
            
            if (showValue == null) {
               showValue = 0;
               showValue = "0";
            }
            resultList.add(showValue);
         }
      }
      return resultList;
   }
   
@@ -138,7 +135,7 @@
    * @throws Exception
    */
   public static JSONObject chartDataFactory(Integer dateType, String year, String startTime, String endTime, 
         List<Map<String, Object>> list) throws Exception{
         List<ChartTDO> list) throws Exception{
      Object objectDate = null;
      List<String> dateList = getDateList(dateType, startTime, endTime, year);
@@ -150,7 +147,7 @@
      innerList.put("name", "总计");
      if (dateType != 3) {
         innerList.put("data", gson.toJson(AdminUtils.dayOrMonthDataFactory(dateList, list)));
         innerList.put("data", gson.toJson(AdminUtils.dayOrMonthDataFactory(dateType, dateList, list)));
      } else {
         // 年视图
         Map<String, Object> map = yearsDataFactory(list);