Преглед изворни кода

智慧双碳 双碳新闻、碳配额构成

ZhangManMan пре 2 година
родитељ
комит
621d7ad169

+ 1 - 6
src/main/java/com/sky/ioc/entity/News.java

@@ -25,10 +25,5 @@ public class News {
 
     /**内容*/
     private String content;
-    public News(){
-        tital = "xxxxxxxxxx";
-        writer = "章峰";
-        date = new Date(System.currentTimeMillis())+"";
-        content = "中华人民共和国第十四届全国人民代表大会第一次会议,在圆满完成各项议程,产生新一届国家机构组成人员后,13日上午在北京人民大会堂闭幕。中共中央总书记、国家主席、中央军委主席习近平在会上发表重要讲话。";
-    }
+
 }

+ 11 - 0
src/main/java/com/sky/ioc/mapper/carbon/CarbonQuotaMapper.java

@@ -3,7 +3,18 @@ package com.sky.ioc.mapper.carbon;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.sky.ioc.entity.domain.carbon.CarbonQuota;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
 
 @Mapper
 public interface CarbonQuotaMapper extends BaseMapper<CarbonQuota> {
+    @Select("SELECT company from carbon_quota where year = #{year} GROUP BY company")
+    List<String> getCompanys(@Param("year") String year);
+    @Select("select coalesce(sum(quota),0) from carbon_quota where company=#{company} and year = #{year}")
+    Integer getQuotaByCompany(@Param("company") String company,@Param("year") String year);
+
+    @Select("select coalesce(sum(expend),0) from carbon_quota where company=#{company} and year = #{year}")
+    Integer getExpendByCompany(@Param("company") String company,@Param("year") String year);
 }

+ 28 - 5
src/main/java/com/sky/ioc/service/carbon/impl/CarbonServiceImpl.java

@@ -1,6 +1,7 @@
 package com.sky.ioc.service.carbon.impl;
 
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.sky.ioc.entity.Indeicator;
 import com.sky.ioc.entity.Label;
 import com.sky.ioc.entity.Cake;
@@ -351,18 +352,40 @@ public class CarbonServiceImpl implements CarbonService {
 
     @Override
     public ReturnMsg getCarbonQuotaComposition(IocParam iocParam) {
+        String year = iocParam.getTimeRange().getStartDate().substring(0,4);
         String[] param = {"stock","consume"};
         String[] labKey = {"中旬","规划院","成分","上分","广分","郑分"};
-        List<Label> labels1 = GeneralMethod.getInstance().dataGeneration(param, labKey);
-        return ReturnMsg.ok(labels1);
+        List<String> lists = carbonQuotaMapper.getCompanys(year);
+        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);
+            Label label = new Label();
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put(param[0],quota-expend);
+            jsonObject.put(param[1],expend);
+            label.setJsonObject(jsonObject);
+            label.setLabel(labKey[i]);
+            list.add(label);
+        }
+        return ReturnMsg.ok(list);
     }
 
     @Override
     public ReturnMsg getCarbonNews(IocParam iocParam) {
         List<News> newsList = new ArrayList<>();
-        newsList.add(new News());
-        newsList.add(new News());
-        newsList.add(new News());
+        List<CarbonNotice> lists = carbonNoticeMapper.selectList(new LambdaQueryWrapper<CarbonNotice>()
+                .gt(CarbonNotice::getCreateTime,iocParam.getTimeRange().getStartDate())
+                .le(CarbonNotice::getCreateTime,iocParam.getTimeRange().getEndDate()));
+        for (CarbonNotice carbonNotice : lists) {
+           News news =  new News();
+           news.setContent(carbonNotice.getContent());
+           news.setTital(carbonNotice.getTitle());
+           news.setWriter(carbonNotice.getCreateByName());
+           news.setDate(carbonNotice.getCreateTime());
+           newsList.add(news);
+        }
         return ReturnMsg.ok(newsList);
     }