|
|
@@ -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,8 +210,101 @@ public class WechatScanLoginController implements WechatScanLoginControllerAPI {
|
|
|
return "redirect:" + HttpParame.FRONT_URI + "/#/login?message=" + URLEncoder.encode("系统异常", "UTF-8");
|
|
|
}
|
|
|
|
|
|
+ /**===============================水电管理=================================**/
|
|
|
+ //凌晨两点:0 0 2 * * ?
|
|
|
+ //每小时执行一次:0 0 */1 * * ?
|
|
|
+ //每分钟执行一次:0 */1 * * * ?
|
|
|
+ //周一到周五早上七点执行:0 0 7 ? * MON-FRI
|
|
|
+ @Async
|
|
|
+ @Scheduled(cron = "0 0 */1 * * ? ")
|
|
|
+ @Transactional(rollbackFor = {Exception.class})
|
|
|
+ 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 "插入完毕";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Async
|
|
|
+ @Scheduled(cron = "0 0 */1 * * ? ")
|
|
|
+ @Transactional(rollbackFor = {Exception.class})
|
|
|
+ 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
|
|
|
+ @Async
|
|
|
+ @Scheduled(cron = "0 0 */6 * * ? ")
|
|
|
+ @Transactional(rollbackFor = {Exception.class})
|
|
|
public String insertMonthMeter(String month) {
|
|
|
if (month == null) {
|
|
|
month = TimeExchange2.getMonth();
|
|
|
@@ -214,6 +315,9 @@ public class WechatScanLoginController implements WechatScanLoginControllerAPI {
|
|
|
|
|
|
@Override
|
|
|
@PassToken
|
|
|
+ @Async
|
|
|
+ @Scheduled(cron = "0 0 */6 * * ? ")
|
|
|
+ @Transactional(rollbackFor = {Exception.class})
|
|
|
public String insertDayMeter(String day) {
|
|
|
if (day == null) {
|
|
|
day = TimeExchange2.getDateStr();
|