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

智慧办公--楼层概览数据接口

ZhangManMan пре 2 година
родитељ
комит
9b172439e3

+ 3 - 6
src/main/java/com/sky/ioc/controller/work/FloorController.java

@@ -7,10 +7,7 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 /**
  * TODO
@@ -32,8 +29,8 @@ public class FloorController {
 
     @ApiOperation("核心指标")
     @PostMapping("/getFloorCoreIndicators")
-    public ReturnMsg getFloorCoreIndicators(@RequestBody IocParam iocParam){
-        return spaceService.getFloorCoreIndicators(iocParam);
+    public ReturnMsg getFloorCoreIndicators(@RequestParam(value = "tier", required=false,defaultValue = "")  String tier){
+        return spaceService.getFloorCoreIndicators(tier);
     }
 
 

+ 1 - 1
src/main/java/com/sky/ioc/entity/domain/print/Print.java

@@ -21,7 +21,7 @@ public class Print {
     private Double inkbox;
 
     /**楼层*/
-    private Integer flootId;
+    private Integer floorId;
 
     /**成本*/
     private Double cost;

+ 5 - 3
src/main/java/com/sky/ioc/entity/domain/space/BuildingSpace.java

@@ -20,14 +20,16 @@ public class BuildingSpace {
     /**会议室面积*/
     private Double meetingArea;
     /**工作区面积*/
-    private Double wordArea;
+    private Double workArea;
     /**打印区面积*/
     private Double printArea;
     /**其他区域面积*/
-    private Double restArea;
+    private Double otherArea;
+    /**工位使用*/
+    private Integer usedStation;
 
     /**楼层*/
-    private Integer tier;
+    private String  tier;
 
     /**工位总数*/
     private Integer stationCount;

+ 7 - 8
src/main/java/com/sky/ioc/mapper/BuildingSpaceMapper.java

@@ -1,5 +1,6 @@
 package com.sky.ioc.mapper;
 
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.sky.ioc.entity.domain.space.BuildingSpace;
 import com.sky.ioc.entity.params.IocParam;
 import org.apache.ibatis.annotations.Mapper;
@@ -7,16 +8,14 @@ import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 
 @Mapper
-public interface BuildingSpaceMapper {
+public interface BuildingSpaceMapper extends BaseMapper<BuildingSpace> {
 
     @Select("<script>" +
-            "SELECT * FROM fitnes where 1=1 " +
-            "<if test='iocParam!=null and iocParam.companyId != null '>" +
-            " and company_id=#{iocParam.companyId} " +
-            "</if>"+
-            "<if test='iocParam!=null and iocParam.floorId != null '>" +
-            " and tier = #{iocParam.floorId} " +
+            "SELECT used_station as usedStation,lead_area as leadArea,meeting_area as meetingArea," +
+            "work_area as workArea,print_area as printArea,other_area as otherArea,station_count as stationCount FROM building_space where 1=1 " +
+            "<if test='tier!=null  '>" +
+            " and tier=#{tier} " +
             "</if>"+
             "</script>")
-    BuildingSpace getByCompanyIdAndTier(@Param("iocParam") IocParam iocParam);
+    BuildingSpace getByTier(@Param("tier")String tier);
 }

+ 60 - 0
src/main/java/com/sky/ioc/mapper/PrintMapper.java

@@ -0,0 +1,60 @@
+package com.sky.ioc.mapper;
+
+import com.sky.ioc.entity.params.IocParam;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+@Mapper
+public interface PrintMapper {
+
+    @Select("<script>" +
+            "SELECT avg(cost)  from print where 1=1 " +
+            "<if test='iocParam!=null and iocParam.timeRange != null '>" +
+            "<![CDATA[ and print_time >= #{iocParam.timeRange.startDate} AND print_time <= #{iocParam.timeRange.endDate} ]]> " +
+            "</if>"+
+            "</script>")
+    Double getAvgCost(@Param("iocParam") IocParam iocParam);
+
+    @Select("<script>" +
+            "SELECT avg(paper)  from print where 1=1 " +
+            "<if test='iocParam!=null and iocParam.timeRange != null '>" +
+            "<![CDATA[ and print_time >= #{iocParam.timeRange.startDate} AND print_time <= #{iocParam.timeRange.endDate} ]]> " +
+            "</if>"+
+            "</script>")
+    Double getAvgPaper(@Param("iocParam") IocParam iocParam);
+
+    @Select("<script>" +
+            "SELECT avg(carbon)  from print where 1=1 " +
+            "<if test='iocParam!=null and iocParam.timeRange != null '>" +
+            "<![CDATA[ and print_time >= #{iocParam.timeRange.startDate} AND print_time <= #{iocParam.timeRange.endDate} ]]> " +
+            "</if>"+
+            "</script>")
+    Double getAvgCarbon(@Param("iocParam") IocParam iocParam);
+
+    @Select("<script> " +
+            "SELECT count(1) FROM print  where 1=1 " +
+            "<if test='iocParam!=null and iocParam.timeRange != null '>" +
+            "<![CDATA[ and print_time >= #{iocParam.timeRange.startDate} AND print_time <= #{iocParam.timeRange.endDate} ]]> " +
+            "</if>" +
+            "</script>")
+    Integer getTotal(@Param("iocParam") IocParam iocParam);
+
+    @Select("<script> " +
+            "SELECT sum(paper) FROM print  where 1=1 " +
+            "<if test='iocParam!=null and iocParam.timeRange != null '>" +
+            "<![CDATA[ and print_time >= #{iocParam.timeRange.startDate} AND print_time <= #{iocParam.timeRange.endDate} ]]> " +
+            "</if>" +
+            "</script>")
+    Integer getTotalPaper(@Param("iocParam") IocParam iocParam);
+
+    @Select("<script>" +
+            "SELECT sum(inkbox)  from print where 1=1 " +
+            "<if test='iocParam!=null and iocParam.timeRange != null '>" +
+            "<![CDATA[ and print_time >= #{iocParam.timeRange.startDate} AND print_time <= #{iocParam.timeRange.endDate} ]]> " +
+            "</if>"+
+            "</script>")
+    Double getTotalInkbox(@Param("iocParam") IocParam iocParam);
+
+
+}

+ 44 - 23
src/main/java/com/sky/ioc/service/carbon/impl/CarbonServiceImpl.java

@@ -8,6 +8,7 @@ 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.mapper.PrintMapper;
 import com.sky.ioc.service.carbon.CarbonService;
 import com.sky.ioc.tool.DateUtil;
 import com.sky.ioc.tool.GeneralMethod;
@@ -37,6 +38,9 @@ public class CarbonServiceImpl implements CarbonService {
     @Autowired
     BusMapper busMapper;
 
+    @Autowired
+    PrintMapper printMapper;
+
     /**
      * TODO  智能看板 --碳配额
      * @Description
@@ -56,36 +60,30 @@ public class CarbonServiceImpl implements CarbonService {
     public ReturnMsg getPrintingCoreIndicators(IocParam iocParam) {
         Indeicator indeicator = new Indeicator();
         List<JSONObject> objects = indeicator.getList();
-        /*ThreadLocalRandom random = ThreadLocalRandom.current();
-        int personCost = random.nextInt(10, 100);
-        int personPaper = random.nextInt(10,20);
-        int personC = random.nextInt(15,100);
-        int personNum = 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",personCost);
+        Double avgCost = printMapper.getAvgCost(iocParam);
+        Double avgPaper = printMapper.getAvgPaper(iocParam);
+        Double avgCarbon = printMapper.getAvgCarbon(iocParam);
+        avgCost = avgCost==null?0: Double.valueOf(decimalFormat.format(avgCost));
+        avgPaper = avgPaper==null?0:Double.valueOf(decimalFormat.format(avgPaper));
+        avgCarbon = avgCarbon==null?0:Double.valueOf(decimalFormat.format(avgCarbon));
+        Integer total = printMapper.getTotal(iocParam);
+        total= total==null?0:total;
+
+        objects.get(0).put("value",avgCost);
         objects.get(0).put("compare",compare);
 
-        objects.get(1).put("value",personPaper);
+        objects.get(1).put("value",avgPaper);
         objects.get(1).put("compare",compare);
 
-        objects.get(2).put("value",personC);
+        objects.get(2).put("value",avgCarbon);
         objects.get(2).put("compare",compare);
 
-        objects.get(3).put("value",personNum);
-        objects.get(3).put("compare",compare);*/
-        objects.get(0).put("value",10);
-        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",total);
+        objects.get(3).put("compare",compare);
         indeicator.setWorthAttention("今日人流高峰在9:00/17:00,记得提前做好应对喔");
         indeicator.setList(objects);
         return ReturnMsg.ok(indeicator);
@@ -102,8 +100,31 @@ public class CarbonServiceImpl implements CarbonService {
     @Override
     public ReturnMsg getConferenceRoomInfo(IocParam iocParam) {
         String[] param = {"print","inkCartridge"};
-        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);
+            Integer totalPaper = printMapper.getTotalPaper(iocParam1);
+            Double totalInkbox = printMapper.getTotalInkbox(iocParam1);
+            totalInkbox= totalInkbox==null?0: Double.valueOf(decimalFormat.format(totalInkbox));
+            totalPaper = totalPaper==null?0:totalPaper;
+            jsonObject.put(param[0],totalPaper);
+            jsonObject.put(param[1],totalInkbox);
+
+            label.setJsonObject(jsonObject);
+            label.setLabel(labKey[i]);
+            labels1.add(label);
+        }
         return ReturnMsg.ok(labels1);
     }
 

+ 1 - 1
src/main/java/com/sky/ioc/service/space/SpaceService.java

@@ -13,7 +13,7 @@ public interface SpaceService {
 
     ReturnMsg getBuildingSituation();
 
-    ReturnMsg getFloorCoreIndicators(IocParam iocParam);
+    ReturnMsg getFloorCoreIndicators(String tier);
 
     ReturnMsg getAccessPersonnel(IocParam iocParam);
 

+ 29 - 35
src/main/java/com/sky/ioc/service/space/impl/SpaceServiceImpl.java

@@ -4,11 +4,14 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.sky.ioc.entity.Indeicator;
 import com.sky.ioc.entity.Label;
+import com.sky.ioc.entity.domain.space.BuildingSpace;
 import com.sky.ioc.entity.params.IocParam;
+import com.sky.ioc.mapper.BuildingSpaceMapper;
 import com.sky.ioc.service.space.SpaceService;
 import com.sky.ioc.tool.FalseData;
 import com.sky.ioc.tool.GeneralMethod;
 import com.sky.ioc.tool.ReturnMsg;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.text.DecimalFormat;
@@ -24,6 +27,9 @@ import java.util.concurrent.ThreadLocalRandom;
 @Service
 public class SpaceServiceImpl implements SpaceService {
 
+    @Autowired
+    BuildingSpaceMapper buildingSpaceMapper;
+
     /**
      * TODO  智能看板 -- 楼宇态势
      * @Description
@@ -42,55 +48,43 @@ public class SpaceServiceImpl implements SpaceService {
     }
 
     @Override
-    public ReturnMsg getFloorCoreIndicators(IocParam iocParam) {
+    public ReturnMsg getFloorCoreIndicators(String tier) {
         Indeicator indeicator = new Indeicator();
         List<JSONObject> objects = indeicator.getList();
-       /* ThreadLocalRandom random = ThreadLocalRandom.current();
-        int totalSite = random.nextInt(100, 800);
-        int total = random.nextInt(500,2000);
-        while (totalSite>total){
-            totalSite = random.nextInt(100, 800);
-        }
-        int meetting = random.nextInt(150,500);
-        while (meetting>total){
-            meetting = random.nextInt(150,500);
-        }
-        int leader = random.nextInt(15,300);
-        while (leader>total){
-            leader = random.nextInt(15,300);
+        BuildingSpace buildingSpace = buildingSpaceMapper.getByTier(tier);
+        if(buildingSpace!=null){
+            objects.get(0).put("value",buildingSpace.getUsedStation());
+            objects.get(1).put("value",buildingSpace.getStationCount());
+            objects.get(2).put("value",buildingSpace.getWorkArea());
+            objects.get(3).put("value",buildingSpace.getMeetingArea());
+            objects.add(new JSONObject());
+            objects.add(new JSONObject());
+            objects.get(4).put("value",buildingSpace.getLeadArea());
+            objects.get(5).put("value",buildingSpace.getOtherArea());
+        }else {
+            objects.get(0).put("value",0);
+            objects.get(1).put("value",0);
+            objects.get(2).put("value",0);
+            objects.get(3).put("value",0);
+            objects.add(new JSONObject());
+            objects.add(new JSONObject());
+            objects.get(4).put("value",0);
+            objects.get(5).put("value",0);
         }
-        int other = random.nextInt(15,200);
-        while (other>total){
-            other = random.nextInt(15,200);
-        }
-        int percent = random.nextInt(30,100);
-        objects.get(0).put("value",percent);
-        objects.get(1).put("value",totalSite);
-        objects.get(2).put("value",total);
-        objects.get(3).put("value",meetting);
-        objects.add(new JSONObject());
-        objects.add(new JSONObject());
-        objects.get(4).put("value",leader);
-        objects.get(5).put("value",other);*/
-        objects.get(0).put("value",90);
-        objects.get(1).put("value",500);
-        objects.get(2).put("value",380);
-        objects.get(3).put("value",80);
-        objects.add(new JSONObject());
-        objects.add(new JSONObject());
-        objects.get(4).put("value",40);
-        objects.get(5).put("value",20);
+
         indeicator.setList(objects);
         return ReturnMsg.ok(indeicator);
     }
 
     @Override
     public ReturnMsg getAccessPersonnel(IocParam iocParam) {
+
         return ReturnMsg.ok(FalseData.ACCESSLIST);
     }
 
     @Override
     public ReturnMsg getFloorList(IocParam iocParam) {
+
         return null;
     }