Pārlūkot izejas kodu

智慧办公公车管理成本趋势

ZhangManMan 2 gadi atpakaļ
vecāks
revīzija
7e3b78c3de

+ 3 - 3
src/main/java/com/sky/ioc/mapper/BusMapper.java

@@ -9,7 +9,7 @@ import org.apache.ibatis.annotations.Select;
 public interface BusMapper {
 
     @Select("<script>" +
-            "SELECT avg(cost)  from bus where 1=1 " +
+            "SELECT  coalesce(avg(cost),0)  from bus where 1=1 " +
             "<if test='iocParam!=null and iocParam.timeRange != null '>" +
             "<![CDATA[ and time >= #{iocParam.timeRange.startDate} AND time <= #{iocParam.timeRange.endDate} ]]> " +
             "</if>"+
@@ -33,7 +33,7 @@ public interface BusMapper {
     Integer getTotalByCompanyIdAndDeptId(@Param("iocParam") IocParam iocParam);
 
     @Select("<script>" +
-            "SELECT sum(hours)  from bus where 1=1 " +
+            "SELECT  coalesce(sum(hours),0)  from bus where 1=1 " +
             "<if test='iocParam!=null and iocParam.timeRange != null '>" +
             "<![CDATA[ and time >= #{iocParam.timeRange.startDate} AND time <= #{iocParam.timeRange.endDate} ]]> " +
             "</if>"+
@@ -41,7 +41,7 @@ public interface BusMapper {
     Double getTotalHoursByCompanyIdAndDeptId(@Param("iocParam") IocParam iocParam);
 
     @Select("<script>" +
-            "SELECT sum(carbon)  from bus where 1=1 " +
+            "SELECT  coalesce(sum(carbon),0)  from bus where 1=1 " +
             "<if test='iocParam!=null and iocParam.timeRange != null '>" +
             "<![CDATA[ and time >= #{iocParam.timeRange.startDate} AND time <= #{iocParam.timeRange.endDate} ]]> " +
             "</if>"+

+ 21 - 3
src/main/java/com/sky/ioc/service/carbon/impl/CarbonServiceImpl.java

@@ -152,7 +152,6 @@ public class CarbonServiceImpl implements CarbonService {
         List<JSONObject> objects = indeicator.getList();
         DecimalFormat decimalFormat = new DecimalFormat("#.0");
         Double avgCost = busMapper.getAvgCostByCompanyIdAndDeptId(iocParam);
-        avgCost = avgCost==null?0:avgCost;
         Double totalHours = busMapper.getTotalHoursByCompanyIdAndDeptId(iocParam);
         Integer totalBus = busMapper.getTotalBusByCompanyIdAndDeptId(iocParam);
         Integer total = busMapper.getTotalByCompanyIdAndDeptId(iocParam);
@@ -237,8 +236,27 @@ public class CarbonServiceImpl implements CarbonService {
     @Override
     public ReturnMsg getBusCostTrend(IocParam iocParam) {
         String[] param = {"cost"};
-        String[] labKey = {"1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"};
-        List<Label> labels1 = GeneralMethod.getInstance().dataGeneration(param, labKey);
+        String startStr = iocParam.getTimeRange().getStartDate();
+        String endStr = iocParam.getTimeRange().getEndDate();
+        List<String> list = DateUtil.getBetweenDays(startStr, endStr);
+        String[] labKey = list.toArray(new String[0]);
+        List<Label> labels1 = new ArrayList<>();
+        DecimalFormat decimalFormat = new DecimalFormat("#.0");
+        for (int i = 0; i < labKey.length; i++) {
+            Label label = new Label();
+            JSONObject jsonObject = new JSONObject();
+            IocParam iocParam1 = new IocParam();
+            IocTimeRange iocTimeRange = new IocTimeRange();
+            iocTimeRange.setStartDate(labKey[i]+" 00:00:00");
+            iocTimeRange.setEndDate(labKey[i]+" 23:59:00");
+            iocParam1.setTimeRange(iocTimeRange);
+            Double avgCost = busMapper.getAvgCostByCompanyIdAndDeptId(iocParam1);
+            avgCost = Double.valueOf(decimalFormat.format(avgCost));
+            jsonObject.put(param[0],avgCost);
+            label.setJsonObject(jsonObject);
+            label.setLabel(labKey[i]);
+            labels1.add(label);
+        }
         return ReturnMsg.ok(labels1);
     }