Procházet zdrojové kódy

Merge branch 'master' of https://e.coding.net/chuanghaikeji/smartCampus/backend_code

夏文涛 před 2 roky
rodič
revize
2a7b7bf8a2

+ 8 - 0
src/main/java/com/template/api/WechatScanLoginControllerAPI.java

@@ -33,6 +33,14 @@ public interface WechatScanLoginControllerAPI {
     @ApiOperation(value = "绑定微信回调url", httpMethod = "GET")
     public String bindcallback(String code, String state, String phone,String messageCode) throws UnsupportedEncodingException;
 
+    @RequestMapping(value = "/insertElecMeterDetail")
+    @ResponseBody
+    public String insertElecMeterDetail() throws Exception;
+
+    @RequestMapping(value = "/insertWatMeterDetail")
+    @ResponseBody
+    public String insertWatMeterDetail() throws Exception;
+
     @RequestMapping(value = "/insertMonthMeter")
     @ResponseBody
     public String insertMonthMeter(String month);

+ 92 - 0
src/main/java/com/template/controller/WechatScanLoginController.java

@@ -27,12 +27,16 @@ import com.template.model.vo.AffiliateParentVo;
 import com.template.model.vo.LoginVO;
 import com.template.model.vo.WechatUserVo;
 import com.template.model.weixin.AccessToken;
+import com.template.model.weixin.AuthorAndGroup;
 import com.template.model.weixin.HttpParame;
 import com.template.model.weixin.WechatUserUnionID;
 import com.template.services.*;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Controller;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -72,6 +76,10 @@ public class WechatScanLoginController implements WechatScanLoginControllerAPI {
     public SmartGradeService smartGradeService;
     @Autowired
     public SmartClassService smartClassService;
+    @Autowired
+    public SmartMeterService smartMeterService;
+    @Autowired
+    public SmartMeterDetailService smartMeterDetailService;
 
     /**
      * Title: list
@@ -202,6 +210,90 @@ public class WechatScanLoginController implements WechatScanLoginControllerAPI {
         return "redirect:" + HttpParame.FRONT_URI + "/#/login?message=" + URLEncoder.encode("系统异常", "UTF-8");
     }
 
+    /**===============================水电管理=================================**/
+    @Override
+    @PassToken
+    public String insertElecMeterDetail() throws Exception {
+        QueryWrapper<SmartMeter> queryWrapper1 = new QueryWrapper<>();
+        queryWrapper1.eq("deleted", 0);
+        queryWrapper1.eq("meter_type", 1);
+        List<SmartMeter> list = smartMeterService.list(queryWrapper1);
+        if (!list.isEmpty()){
+            for (int i = 0; i < list.size(); i++) {
+                String msg = HttpsClient.get("http://iot.czrxdzonline.cn/api/dtu/find?deviceNum="+list.get(i).getMeterNo());
+                JSONObject result = JSONObject.parseObject(msg);
+                Integer state = result.getInteger("Status");
+                if (state==1){
+                    Double lastRecord = 0.00;
+                    QueryWrapper<SmartMeterDetail> queryWrapper2 = new QueryWrapper<>();
+                    queryWrapper2.eq("deleted", 0);
+                    queryWrapper2.eq("meter_type", 1);
+                    queryWrapper2.eq("meter_id", list.get(i).getId());
+                    queryWrapper2.orderByDesc("id");
+                    List<SmartMeterDetail> detailList = smartMeterDetailService.list(queryWrapper2);
+                    if (!detailList.isEmpty()){
+                        lastRecord = detailList.get(0).getMeterPowerRecord();
+                    }
+                    JSONObject data = result.getJSONObject("Data");
+                    ElecData elecData = JSONObject.parseObject(data.toString(), ElecData.class);
+                    SmartMeterDetail smartMeterDetail = new SmartMeterDetail();
+                    smartMeterDetail.setMeterId(list.get(i).getId());
+                    smartMeterDetail.setMeterType(1);
+                    String display = elecData.getDisplay();
+                    smartMeterDetail.setMeterPowerRecord(Double.parseDouble(display)/Double.parseDouble("100"));
+                    smartMeterDetail.setMeterPower(Double.parseDouble(display)/Double.parseDouble("100")-lastRecord);
+                    smartMeterDetail.setCreateTime(TimeExchange.StringToDate(elecData.getCommunication(), "yyyy-MM-dd HH:mm:ss"));
+                    System.out.println("====="+smartMeterDetail.getMeterPowerRecord());
+                    smartMeterDetailService.insertSmartMeterDetail(smartMeterDetail);
+                }
+            }
+        }
+        return "插入完毕";
+    }
+
+    @Override
+    @PassToken
+    public String insertWatMeterDetail() throws Exception {
+        QueryWrapper<SmartMeter> queryWrapper1 = new QueryWrapper<>();
+        queryWrapper1.eq("deleted", 0);
+        queryWrapper1.eq("meter_type", 0);
+        List<SmartMeter> list = smartMeterService.list(queryWrapper1);
+        if (!list.isEmpty()){
+            for (int i = 0; i < list.size(); i++) {
+                JSONObject jsonObject = new JSONObject();
+                jsonObject.put("type", "5");
+                jsonObject.put("address", list.get(i).getMeterNo());
+                String msg = HttpsClient.sendJson("http://iot.czrxdzonline.cn/api/wat/find", jsonObject);
+                JSONObject result = JSONObject.parseObject(msg);
+                Integer state = result.getInteger("Status");
+                if (state==1){
+                    Double lastRecord = 0.00;
+                    QueryWrapper<SmartMeterDetail> queryWrapper2 = new QueryWrapper<>();
+                    queryWrapper2.eq("deleted", 0);
+                    queryWrapper2.eq("meter_type", 0);
+                    queryWrapper2.eq("meter_id", list.get(i).getId());
+                    queryWrapper2.orderByDesc("id");
+                    List<SmartMeterDetail> detailList = smartMeterDetailService.list(queryWrapper2);
+                    if (!detailList.isEmpty()){
+                        lastRecord = detailList.get(0).getMeterPowerRecord();
+                    }
+                    JSONObject data = result.getJSONObject("Data");
+                    WatData watData = JSONObject.parseObject(data.toString(), WatData.class);
+                    SmartMeterDetail smartMeterDetail = new SmartMeterDetail();
+                    smartMeterDetail.setMeterId(list.get(i).getId());
+                    smartMeterDetail.setMeterType(0);
+                    String display = watData.getQuantity();
+                    smartMeterDetail.setMeterPowerRecord(Double.parseDouble(display)/Double.parseDouble("100"));
+                    smartMeterDetail.setMeterPower(Double.parseDouble(display)/Double.parseDouble("100")-lastRecord);
+                    smartMeterDetail.setCreateTime(TimeExchange.StringToDate(watData.getLastUpdate(), "yyyy-MM-dd HH:mm:ss"));
+                    System.out.println("====="+smartMeterDetail.getMeterPowerRecord());
+                    smartMeterDetailService.insertSmartMeterDetail(smartMeterDetail);
+                }
+            }
+        }
+        return "插入完毕";
+    }
+
     @Override
     @PassToken
     public String insertMonthMeter(String month) {

+ 12 - 0
src/main/java/com/template/model/tongji/ElecData.java

@@ -0,0 +1,12 @@
+package com.template.model.tongji;
+
+import lombok.Data;
+
+@Data
+public class ElecData {
+
+    public String DeviceID; // 表号
+    public String Display; // 当前示数(2位小数,需缩小100倍)
+    public Integer Relay; // 继电器状态 7 分闸 8 合闸
+    public String Communication;
+}

+ 25 - 0
src/main/java/com/template/model/tongji/TjFloat.java

@@ -0,0 +1,25 @@
+package com.template.model.tongji;
+
+import com.template.common.utils.DataBliu;
+
+public class TjFloat {
+
+    public String name;
+    public Double num;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Double getNum() {
+        return DataBliu.getTwo(num);
+    }
+
+    public void setNum(Double num) {
+        this.num = num;
+    }
+}

+ 14 - 0
src/main/java/com/template/model/tongji/WatData.java

@@ -0,0 +1,14 @@
+package com.template.model.tongji;
+
+import lombok.Data;
+
+@Data
+public class WatData {
+
+    public String Address;
+    public String Quantity;
+    public String Valve;
+    public String Voltage;
+    public Integer CSQ;
+    public String LastUpdate;
+}

+ 18 - 2
src/main/java/com/template/services/impl/SmartFaceDiscernServiceImpl.java

@@ -51,9 +51,10 @@ public class SmartFaceDiscernServiceImpl extends ServiceImpl<SmartFaceDiscernMap
     static String schoolCode = "SL1704880825203963";
 
     private Integer page = 1;
-    private Integer size = 20;
+    private Integer size = 50;
 
-    @Scheduled(cron = "0 0/50 * * * ? ")
+//    @Scheduled(cron = "0 0/50 * * * ? ")
+    @Scheduled(cron = "0 0/20 * * * ? ")
     public void baiS() {
         try {
             getFaceDiscern(page, size);
@@ -213,6 +214,21 @@ public class SmartFaceDiscernServiceImpl extends ServiceImpl<SmartFaceDiscernMap
 
                         }
 
+                    }else {
+
+                        smartFaceDiscern.setUserId(0);
+
+//                    判断是否已经添加
+                        LambdaQueryWrapper<SmartFaceDiscern> wrapperFD = new LambdaQueryWrapper<>();
+                        wrapperFD.eq(SmartFaceDiscern::getDateTime, recordAddtime)
+                                .eq(SmartFaceDiscern::getName, student_name)
+                                .eq(SmartFaceDiscern::getType,deviceName );
+                        SmartFaceDiscern one = this.getOne(wrapperFD);
+
+                        if (ObjectUtils.isEmpty(one)) {
+                            this.save(smartFaceDiscern);
+                        }
+
                     }
 
                 }