|
@@ -7,17 +7,22 @@ import com.sky.ioc.entity.Cake;
|
|
|
import com.sky.ioc.entity.Indeicator;
|
|
|
import com.sky.ioc.entity.Label;
|
|
|
import com.sky.ioc.entity.News;
|
|
|
+import com.sky.ioc.entity.domain.carbon.Carbon;
|
|
|
import com.sky.ioc.entity.domain.carbon.CarbonNotice;
|
|
|
import com.sky.ioc.entity.domain.carbon.CarbonQuota;
|
|
|
+import com.sky.ioc.entity.domain.space.Company;
|
|
|
import com.sky.ioc.entity.params.IocParam;
|
|
|
import com.sky.ioc.entity.params.IocTimeRange;
|
|
|
import com.sky.ioc.mapper.BusMapper;
|
|
|
import com.sky.ioc.mapper.PrintMapper;
|
|
|
+import com.sky.ioc.mapper.carbon.CarbonMapper;
|
|
|
import com.sky.ioc.mapper.carbon.CarbonNoticeMapper;
|
|
|
import com.sky.ioc.mapper.carbon.CarbonQuotaMapper;
|
|
|
+import com.sky.ioc.mapper.space.CompanyMapper;
|
|
|
import com.sky.ioc.service.carbon.CarbonService;
|
|
|
import com.sky.ioc.tool.DateUtil;
|
|
|
import com.sky.ioc.tool.GeneralMethod;
|
|
|
+import com.sky.ioc.tool.MathUtils;
|
|
|
import com.sky.ioc.tool.ReturnMsg;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -33,6 +38,7 @@ import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.ThreadLocalRandom;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* TODO 双碳
|
|
@@ -64,7 +70,8 @@ public class CarbonServiceImpl implements CarbonService {
|
|
|
@Autowired
|
|
|
CarbonNoticeMapper carbonNoticeMapper;
|
|
|
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ CarbonMapper carbonMapper;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -296,33 +303,28 @@ public class CarbonServiceImpl implements CarbonService {
|
|
|
Indeicator indeicator = new Indeicator();
|
|
|
List<JSONObject> objects = indeicator.getList();
|
|
|
ThreadLocalRandom random = ThreadLocalRandom.current();
|
|
|
- int stockCarbon = random.nextInt(10, 100);
|
|
|
- int totalCarbon = random.nextInt(100,8000);
|
|
|
- int areaCarbon = random.nextInt(10,800);
|
|
|
- int personCarbon = random.nextInt(10,80);
|
|
|
- while (areaCarbon>totalCarbon){
|
|
|
- areaCarbon = random.nextInt(10,800);
|
|
|
- }
|
|
|
- while (personCarbon>totalCarbon){
|
|
|
- personCarbon = random.nextInt(10,80);
|
|
|
- }
|
|
|
- int derCarbon = random.nextInt(10,80);
|
|
|
- float compare = (float) Math.random();
|
|
|
+ String year = iocParam.getTimeRange().getStartDate().substring(0,4);
|
|
|
+ Long quota = carbonQuotaMapper.getQuotaByCompany("",year);
|
|
|
+ Long expend = carbonQuotaMapper.getExpendByCompany("",year);
|
|
|
+ long discharge = carbonMapper.getDischargeByTime(iocParam);
|
|
|
+ long deEmission = carbonMapper.getDeEmissionByTime(iocParam);
|
|
|
+ long area =0;//总面积 暂无数据
|
|
|
+ long person = 0;//总人数 暂无数据
|
|
|
+ Double compare = random.nextDouble(-1,1);
|
|
|
DecimalFormat decimalFormat = new DecimalFormat("#.0");
|
|
|
- compare = Float.parseFloat(decimalFormat.format(compare));
|
|
|
+ compare = Double.valueOf(decimalFormat.format(compare));
|
|
|
+ objects.get(0).put("value",MathUtils.division(quota-expend,quota,2)*100);
|
|
|
|
|
|
- objects.get(0).put("value",stockCarbon);
|
|
|
-
|
|
|
- objects.get(1).put("value",totalCarbon);
|
|
|
+ objects.get(1).put("value",discharge);
|
|
|
objects.get(1).put("compare",compare);
|
|
|
|
|
|
- objects.get(2).put("value",areaCarbon);
|
|
|
+ objects.get(2).put("value",MathUtils.division(discharge,area,2));
|
|
|
objects.get(2).put("compare",compare);
|
|
|
|
|
|
- objects.get(3).put("value",personCarbon);
|
|
|
+ objects.get(3).put("value",MathUtils.division(discharge,person,2));
|
|
|
objects.get(3).put("compare",compare);
|
|
|
objects.add(new JSONObject());
|
|
|
- objects.get(4).put("value",derCarbon);
|
|
|
+ objects.get(4).put("value",deEmission);
|
|
|
objects.get(4).put("compare",compare);
|
|
|
|
|
|
indeicator.setWorthAttention("节能减排绿色出行");
|
|
@@ -330,15 +332,37 @@ public class CarbonServiceImpl implements CarbonService {
|
|
|
return ReturnMsg.ok(indeicator);
|
|
|
}
|
|
|
|
|
|
+ @Autowired
|
|
|
+ CompanyMapper companyMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public ReturnMsg getCarbonInfo(IocParam iocParam) {
|
|
|
- String[] param = {"zhongxun","guihuayuanBJ","zhengfen","guangfen","shangfen","chengfen"};
|
|
|
+ List<Company> companies = companyMapper.selectList(null);
|
|
|
+ List<String> params = companies.stream().map(Company::getCompanyName).collect(Collectors.toList());
|
|
|
+ String[] param = params.toArray(new String[0]);
|
|
|
String startStr = iocParam.getTimeRange().getStartDate();
|
|
|
String endStr = iocParam.getTimeRange().getEndDate();
|
|
|
List<String> lists = DateUtil.getBetweenDays(startStr, endStr);
|
|
|
String[] labKey = lists.toArray(new String[0]);
|
|
|
- List<Label> labels1 = GeneralMethod.getInstance().dataGeneration(param, labKey);
|
|
|
- return ReturnMsg.ok(labels1);
|
|
|
+ List<Label> list = new ArrayList<>();
|
|
|
+ for (int i = 0; i < labKey.length; i++) {
|
|
|
+ Label label = new Label();
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ for (int j = 0; j < companies.size(); j++) {
|
|
|
+ IocParam iocParam1 = new IocParam();
|
|
|
+ iocParam1.setDeptId(companies.get(j).getId());
|
|
|
+ IocTimeRange iocTimeRange = new IocTimeRange();
|
|
|
+ iocTimeRange.setStartDate(labKey[i]+" 00:00:00");
|
|
|
+ iocTimeRange.setEndDate(labKey[i]+" 23:59:00");
|
|
|
+ iocParam1.setTimeRange(iocTimeRange);
|
|
|
+ long i1 = carbonMapper.getDischargeByTime(iocParam1);
|
|
|
+ jsonObject.put(param[j],i1);
|
|
|
+ }
|
|
|
+ label.setJsonObject(jsonObject);
|
|
|
+ label.setLabel(labKey[i]);
|
|
|
+ list.add(label);
|
|
|
+ }
|
|
|
+ return ReturnMsg.ok(list);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -350,8 +374,8 @@ public class CarbonServiceImpl implements CarbonService {
|
|
|
labKey = lists.toArray(new String[0]);
|
|
|
List<Label> list = new ArrayList<>();
|
|
|
for (int i = 0; i < labKey.length; i++) {
|
|
|
- Integer quota = carbonQuotaMapper.getQuotaByCompany(labKey[i],year);
|
|
|
- Integer expend = carbonQuotaMapper.getExpendByCompany(labKey[i],year);
|
|
|
+ Long quota = carbonQuotaMapper.getQuotaByCompany(labKey[i],year);
|
|
|
+ Long expend = carbonQuotaMapper.getExpendByCompany(labKey[i],year);
|
|
|
Label label = new Label();
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put(param[0],quota-expend);
|
|
@@ -383,12 +407,14 @@ public class CarbonServiceImpl implements CarbonService {
|
|
|
@Override
|
|
|
public ReturnMsg getCarbonProportion(IocParam iocParam) {
|
|
|
List<Cake> list = new ArrayList<>();
|
|
|
- list.add(new Cake("汽油"));
|
|
|
- list.add(new Cake("柴油"));
|
|
|
- list.add(new Cake("电力"));
|
|
|
- list.add(new Cake("热力"));
|
|
|
- list.add(new Cake("天然气"));
|
|
|
- list.add(new Cake("其他"));
|
|
|
+ String[] names = {"汽油","柴油","电力","热力","天然气","其他"};
|
|
|
+ for(String name:names){
|
|
|
+ Long value = carbonMapper.getDischargeBySourceType(iocParam,name);
|
|
|
+ Cake cake = new Cake();
|
|
|
+ cake.setName(name);
|
|
|
+ cake.setValue(value);
|
|
|
+ list.add(cake);
|
|
|
+ }
|
|
|
return ReturnMsg.ok(list);
|
|
|
}
|
|
|
|
|
@@ -962,4 +988,6 @@ public class CarbonServiceImpl implements CarbonService {
|
|
|
//return null;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
}
|