|
@@ -6,11 +6,18 @@ import com.sky.ioc.entity.Label;
|
|
|
import com.sky.ioc.entity.Cake;
|
|
|
import com.sky.ioc.entity.News;
|
|
|
import com.sky.ioc.entity.params.IocParam;
|
|
|
+import com.sky.ioc.entity.params.IocTimeRange;
|
|
|
+import com.sky.ioc.mapper.BusMapper;
|
|
|
import com.sky.ioc.service.carbon.CarbonService;
|
|
|
+import com.sky.ioc.tool.DateUtil;
|
|
|
import com.sky.ioc.tool.GeneralMethod;
|
|
|
import com.sky.ioc.tool.ReturnMsg;
|
|
|
+import io.swagger.models.auth.In;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.text.DecimalFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
@@ -27,7 +34,8 @@ import java.util.concurrent.ThreadLocalRandom;
|
|
|
public class CarbonServiceImpl implements CarbonService {
|
|
|
|
|
|
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ BusMapper busMapper;
|
|
|
|
|
|
/**
|
|
|
* TODO 智能看板 --碳配额
|
|
@@ -103,36 +111,48 @@ public class CarbonServiceImpl implements CarbonService {
|
|
|
public ReturnMsg getBusCoreIndicators(IocParam iocParam) {
|
|
|
Indeicator indeicator = new Indeicator();
|
|
|
List<JSONObject> objects = indeicator.getList();
|
|
|
- /* ThreadLocalRandom random = ThreadLocalRandom.current();
|
|
|
- int carCost = random.nextInt(10000, 1000000);
|
|
|
- int carTimes = random.nextInt(10,80);
|
|
|
- int carC = random.nextInt(150,500);
|
|
|
- int carHours = random.nextInt(1,20);
|
|
|
- float compare = (float) Math.random();
|
|
|
DecimalFormat decimalFormat = new DecimalFormat("#.0");
|
|
|
- compare = Float.parseFloat(decimalFormat.format(compare));
|
|
|
- objects.get(0).put("value",carCost);
|
|
|
+ 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);
|
|
|
+ avgCost = Double.valueOf(decimalFormat.format(avgCost));
|
|
|
+ Double totalCarbon = busMapper.getTotalCarbonByCompanyIdAndDeptId(iocParam);
|
|
|
+ double avgHours = 0d;
|
|
|
+ double avgCarbon = 0d;
|
|
|
+ double avgTimes = 0d;
|
|
|
+ if(total>0){
|
|
|
+ if(totalBus>0){
|
|
|
+ BigDecimal bigDecimal = new BigDecimal(totalBus);
|
|
|
+ BigDecimal avgTimesDec = bigDecimal.divide(new BigDecimal(total), 2, RoundingMode.HALF_UP);
|
|
|
+ avgTimes = avgTimesDec.doubleValue();
|
|
|
+ }
|
|
|
+ if(totalHours>0){
|
|
|
+ BigDecimal bigDecimal = new BigDecimal(totalHours);
|
|
|
+ BigDecimal avgHoursDec = bigDecimal.divide(new BigDecimal(total), 2, RoundingMode.HALF_UP);
|
|
|
+ avgHours = avgHoursDec.doubleValue();
|
|
|
+ }
|
|
|
+ if(totalCarbon>0){
|
|
|
+ BigDecimal bigDecimal = new BigDecimal(totalCarbon);
|
|
|
+ BigDecimal avgCarbonDec = bigDecimal.divide(new BigDecimal(total), 2, RoundingMode.HALF_UP);
|
|
|
+ avgCarbon = avgCarbonDec.doubleValue();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ThreadLocalRandom random = ThreadLocalRandom.current();
|
|
|
+ double compare = random.nextDouble(-1, 1);
|
|
|
+ compare = Double.parseDouble(decimalFormat.format(compare));
|
|
|
+ objects.get(0).put("value",avgCost);
|
|
|
objects.get(0).put("compare",compare);
|
|
|
|
|
|
- objects.get(1).put("value",carTimes);
|
|
|
+ objects.get(1).put("value",avgTimes);
|
|
|
objects.get(1).put("compare",compare);
|
|
|
|
|
|
- objects.get(2).put("value",carC);
|
|
|
+ objects.get(2).put("value",avgCarbon);
|
|
|
objects.get(2).put("compare",compare);
|
|
|
|
|
|
- objects.get(3).put("value",carHours);
|
|
|
- objects.get(3).put("compare",compare);*/
|
|
|
- objects.get(0).put("value",100);
|
|
|
- objects.get(0).put("compare",0.4);
|
|
|
-
|
|
|
- objects.get(1).put("value",80);
|
|
|
- objects.get(1).put("compare",0.4);
|
|
|
-
|
|
|
- objects.get(2).put("value",80);
|
|
|
- objects.get(2).put("compare",0.4);
|
|
|
-
|
|
|
- objects.get(3).put("value",80);
|
|
|
- objects.get(3).put("compare",0.4);
|
|
|
+ objects.get(3).put("value",avgHours);
|
|
|
+ objects.get(3).put("compare",compare);
|
|
|
indeicator.setWorthAttention("增加20个公车数量");
|
|
|
indeicator.setList(objects);
|
|
|
return ReturnMsg.ok(indeicator);
|
|
@@ -141,8 +161,37 @@ public class CarbonServiceImpl implements CarbonService {
|
|
|
@Override
|
|
|
public ReturnMsg getBusInfo(IocParam iocParam) {
|
|
|
String[] param = {"averageDuration","numberTrips"};
|
|
|
- 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 totalHours = busMapper.getTotalHoursByCompanyIdAndDeptId(iocParam1);
|
|
|
+ Integer total = busMapper.getTotalByCompanyIdAndDeptId(iocParam1);
|
|
|
+ double avgHours = 0d;
|
|
|
+ if(total>0){
|
|
|
+ if(totalHours>0){
|
|
|
+ BigDecimal bigDecimal = new BigDecimal(totalHours);
|
|
|
+ BigDecimal avgHoursDec = bigDecimal.divide(new BigDecimal(total), 2, RoundingMode.HALF_UP);
|
|
|
+ avgHours = avgHoursDec.doubleValue();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ jsonObject.put(param[0],avgHours);
|
|
|
+ jsonObject.put(param[1],total);
|
|
|
+
|
|
|
+ label.setJsonObject(jsonObject);
|
|
|
+ label.setLabel(labKey[i]);
|
|
|
+ labels1.add(label);
|
|
|
+ }
|
|
|
return ReturnMsg.ok(labels1);
|
|
|
}
|
|
|
|