Browse Source

开发公厕数据对接接口

master
yingsl 3 years ago
parent
commit
749a800033
  1. 3
      src/main/java/com/example/modular/energyconsumption/service/impl/ToiletElectricityConsumptionServiceImpl.java
  2. 110
      src/main/java/com/example/modular/shangyudata/controller/IntelligenceCityController.java
  3. 6
      src/main/java/com/example/modular/shangyudata/controller/ShangyuToiletDataController.java
  4. 46
      src/main/java/com/example/modular/shangyudata/service/IntelligenceCityService.java
  5. 172
      src/main/java/com/example/modular/shangyudata/service/impl/IntelligenceCityServiceImpl.java
  6. 31
      src/main/java/com/example/modular/shangyudata/vo/GetToiletStatusVO.java

3
src/main/java/com/example/modular/energyconsumption/service/impl/ToiletElectricityConsumptionServiceImpl.java

@ -351,7 +351,8 @@ public class ToiletElectricityConsumptionServiceImpl extends ServiceImpl<ToiletE
DecimalFormat df = new DecimalFormat("0.00");
for (ToiletElectricityConsumption toiletElectricityConsumption : toiletElectricityConsumptionList) {
if (toiletElectricityConsumption.getUseElectricity() == null || toiletElectricityConsumption.getUseElectricity().equals(0d)
|| toiletIdToPassengerMap.get(toiletElectricityConsumption.getToiletId()) == null || toiletIdToPassengerMap.get(toiletElectricityConsumption.getToiletId()).get("passenger_num_hour") == null) {
|| toiletIdToPassengerMap.get(toiletElectricityConsumption.getToiletId()) == null || toiletIdToPassengerMap.get(toiletElectricityConsumption.getToiletId()).get("passenger_num_hour") == null
|| toiletIdToPassengerMap.get(toiletElectricityConsumption.getToiletId()).get("passenger_num_hour").toString().equals("0")) {
continue;
}
Integer passengerNum = Integer.parseInt(toiletIdToPassengerMap.get(toiletElectricityConsumption.getToiletId()).get("passenger_num_hour").toString());

110
src/main/java/com/example/modular/shangyudata/controller/IntelligenceCityController.java

@ -0,0 +1,110 @@
package com.example.modular.shangyudata.controller;
import com.example.common.controller.BaseSupport;
import com.example.common.excepiton.BusinessException;
import com.example.modular.shangyudata.service.IntelligenceCityService;
import com.example.modular.shangyudata.vo.GetToiletStatusVO;
import com.haidapu.core.common.msg.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 上虞公厕数据对接 controller
* @Author ysl
* @date Created in 2022/04/12 18:09
*/
@RestController
public class IntelligenceCityController extends BaseSupport {
@Autowired
private IntelligenceCityService intelligenceCityService;
/**
* 获取公厕厕位状态数据接口
* @return
* @Author ysl
*/
@PostMapping("getToiletStatus")
public R getToiletStatus() {
GetToiletStatusVO getToiletStatusVO = getInputObject(GetToiletStatusVO.class);
R r;
try {
r = intelligenceCityService.getToiletStatus(getToiletStatusVO);
} catch (Exception e) {
throw new BusinessException("系统错误",500);
}
return r;
}
/**
* 获取公厕人流量数据接口
* @return
* @Author ysl
*/
@PostMapping("getToiletPedeVolume")
public R getToiletPedeVolume() {
GetToiletStatusVO getToiletStatusVO = getInputObject(GetToiletStatusVO.class);
R r;
try {
r = intelligenceCityService.getToiletPedeVolume(getToiletStatusVO);
} catch (Exception e) {
throw new BusinessException("系统错误",500);
}
return r;
}
/**
* 获取公厕空气质量数据接口
* @return
* @Author ysl
*/
@PostMapping("getToiletAir")
public R getToiletAir() {
GetToiletStatusVO getToiletStatusVO = getInputObject(GetToiletStatusVO.class);
R r;
try {
r = intelligenceCityService.getToiletAir(getToiletStatusVO);
} catch (Exception e) {
throw new BusinessException("系统错误",500);
}
return r;
}
/**
* 获取公厕用电量数据接口
* @return
* @Author ysl
*/
@PostMapping("getToiletElectricity")
public R getToiletElectricity() {
GetToiletStatusVO getToiletStatusVO = getInputObject(GetToiletStatusVO.class);
R r;
try {
r = intelligenceCityService.getToiletElectricity(getToiletStatusVO);
} catch (Exception e) {
throw new BusinessException("系统错误",500);
}
return r;
}
/**
* 获取公厕用水量数据接口
* @return
* @Author ysl
*/
@PostMapping("getToiletWater")
public R getToiletWater() {
GetToiletStatusVO getToiletStatusVO = getInputObject(GetToiletStatusVO.class);
R r;
try {
r = intelligenceCityService.getToiletWater(getToiletStatusVO);
} catch (Exception e) {
throw new BusinessException("系统错误",500);
}
return r;
}
}

6
src/main/java/com/example/modular/shangyudata/controller/ShangyuToiletDataController.java

@ -6,12 +6,10 @@ import com.example.common.excepiton.BusinessException;
import com.example.modular.shangyudata.service.ShangyuToiletDataService;
import com.example.modular.shangyudata.vo.*;
import com.example.util.HttpRequestUtils;
import com.example.util.Result;
import com.haidapu.core.common.msg.R;
import com.haidapu.core.common.utils.MD5Sign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;
@ -85,7 +83,7 @@ public class ShangyuToiletDataController extends BaseSupport {
public static void main (String[] args) {
Map<String,Object> map = new HashMap<>();
map.put("appid","f890e766810cc612dafbc1fe501f46fc");
map.put("method","pushToiletPedeVolume");
map.put("method","pushToiletAir");
map.put("timeStamp",System.currentTimeMillis());
Map<String,Object> dataMap = new HashMap<>();
dataMap.put("toiletCode","123");
@ -93,6 +91,8 @@ public class ShangyuToiletDataController extends BaseSupport {
dataMap.put("passengerNumToday",123);
dataMap.put("passengerNumHour",13);
dataMap.put("createTime","2021-12-29 12:12:12");
String dataJsonStr = JSON.toJSONString(dataMap);
map.put("data",dataJsonStr);
StringBuilder stringBuilder = new StringBuilder();

46
src/main/java/com/example/modular/shangyudata/service/IntelligenceCityService.java

@ -0,0 +1,46 @@
package com.example.modular.shangyudata.service;
import com.example.modular.shangyudata.vo.GetToiletStatusVO;
import com.example.modular.shangyudata.vo.ToiletInfoVO;
import com.haidapu.core.common.msg.R;
public interface IntelligenceCityService {
/**
* 获取公厕厕位状态数据接口
* @return
* @Author ysl
*/
R getToiletStatus(GetToiletStatusVO getToiletStatusVO);
/**
* 获取公厕人流量数据接口
* @return
* @Author ysl
*/
R getToiletPedeVolume(GetToiletStatusVO getToiletStatusVO);
/**
* 获取公厕空气质量数据接口
* @return
* @Author ysl
*/
R getToiletAir(GetToiletStatusVO getToiletStatusVO);
/**
* 获取公厕用电量数据接口
* @return
* @Author ysl
*/
R getToiletElectricity(GetToiletStatusVO getToiletStatusVO);
/**
* 获取公厕用水量数据接口
* @return
* @Author ysl
*/
R getToiletWater(GetToiletStatusVO getToiletStatusVO);
}

172
src/main/java/com/example/modular/shangyudata/service/impl/IntelligenceCityServiceImpl.java

@ -0,0 +1,172 @@
package com.example.modular.shangyudata.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.common.Constant;
import com.example.common.excepiton.BusinessException;
import com.example.modular.energyconsumption.po.ToiletElectricityConsumption;
import com.example.modular.energyconsumption.po.ToiletWaterConsumption;
import com.example.modular.energyconsumption.service.IToiletElectricityConsumptionService;
import com.example.modular.energyconsumption.service.IToiletWaterConsumptionService;
import com.example.modular.monitoringdata.po.ToiletAirIndexAverage;
import com.example.modular.monitoringdata.po.ToiletNearInfo;
import com.example.modular.monitoringdata.po.ToiletPassengerFlow;
import com.example.modular.monitoringdata.service.IToiletAirIndexAverageService;
import com.example.modular.monitoringdata.service.IToiletNearInfoService;
import com.example.modular.monitoringdata.service.IToiletPassengerFlowService;
import com.example.modular.shangyudata.service.IntelligenceCityService;
import com.example.modular.shangyudata.vo.GetToiletStatusVO;
import com.example.modular.toilet.po.Toilet;
import com.example.modular.toilet.service.IToiletService;
import com.haidapu.core.common.msg.R;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
@Service
public class IntelligenceCityServiceImpl implements IntelligenceCityService {
@Autowired
private IToiletService toiletService;
@Autowired
private IToiletNearInfoService toiletNearInfoService;
@Autowired
private IToiletPassengerFlowService toiletPassengerFlowService;
@Autowired
private IToiletAirIndexAverageService toiletAirIndexAverageService;
@Autowired
private IToiletElectricityConsumptionService toiletElectricityConsumptionService;
@Autowired
private IToiletWaterConsumptionService toiletWaterConsumptionService;
@Override
public R getToiletStatus(GetToiletStatusVO getToiletStatusVO) {
//校验参数是否存在
if (getToiletStatusVO == null || StringUtils.isBlank(getToiletStatusVO.getToiletCode()) || getToiletStatusVO.getToiletNearType() == null
|| StringUtils.isBlank(getToiletStatusVO.getStartTime()) || StringUtils.isBlank(getToiletStatusVO.getEndTime())) {
throw new BusinessException("必填项不能为空!",201);
}
//校验公厕是否存在
QueryWrapper<Toilet> toiletQueryWrapper = new QueryWrapper<>();
toiletQueryWrapper.eq("toilet_code",getToiletStatusVO.getToiletCode());
toiletQueryWrapper.eq("delete_status", Constant.TOILET_DEL_STATUS_NO);
List<Toilet> toiletList = toiletService.list(toiletQueryWrapper);
if (CollectionUtils.isEmpty(toiletList)) {
throw new BusinessException("公厕信息不存在!",202);
}
Long toiletId = toiletList.get(0).getId();
//查询公厕厕位状态数据
QueryWrapper<ToiletNearInfo> toiletNearInfoQueryWrapper = new QueryWrapper<>();
toiletNearInfoQueryWrapper.eq("toilet_id",toiletId);
toiletNearInfoQueryWrapper.eq("toilet_near_type",getToiletStatusVO.getToiletNearType());
toiletNearInfoQueryWrapper.ge("create_time",getToiletStatusVO.getStartTime());
toiletNearInfoQueryWrapper.le("create_time",getToiletStatusVO.getEndTime());
List<ToiletNearInfo> toiletNearInfoList = toiletNearInfoService.list(toiletNearInfoQueryWrapper);
return R.ok().put("data",toiletNearInfoList);
}
@Override
public R getToiletPedeVolume(GetToiletStatusVO getToiletStatusVO) {
//校验参数是否存在
if (getToiletStatusVO == null || StringUtils.isBlank(getToiletStatusVO.getToiletCode()) || getToiletStatusVO.getToiletNearType() == null
|| StringUtils.isBlank(getToiletStatusVO.getStartTime()) || StringUtils.isBlank(getToiletStatusVO.getEndTime())) {
throw new BusinessException("必填项不能为空!",201);
}
//校验公厕是否存在
QueryWrapper<Toilet> toiletQueryWrapper = new QueryWrapper<>();
toiletQueryWrapper.eq("toilet_code",getToiletStatusVO.getToiletCode());
toiletQueryWrapper.eq("delete_status", Constant.TOILET_DEL_STATUS_NO);
List<Toilet> toiletList = toiletService.list(toiletQueryWrapper);
if (CollectionUtils.isEmpty(toiletList)) {
throw new BusinessException("公厕信息不存在!",202);
}
Long toiletId = toiletList.get(0).getId();
//查询公厕厕位状态数据
QueryWrapper<ToiletPassengerFlow> toiletPassengerFlowQueryWrapper = new QueryWrapper<>();
toiletPassengerFlowQueryWrapper.eq("toilet_id",toiletId);
toiletPassengerFlowQueryWrapper.eq("toilet_near_type",getToiletStatusVO.getToiletNearType());
toiletPassengerFlowQueryWrapper.ge("create_time",getToiletStatusVO.getStartTime());
toiletPassengerFlowQueryWrapper.le("create_time",getToiletStatusVO.getEndTime());
List<ToiletPassengerFlow> toiletPassengerFlowList = toiletPassengerFlowService.list(toiletPassengerFlowQueryWrapper);
return R.ok().put("data",toiletPassengerFlowList);
}
@Override
public R getToiletAir(GetToiletStatusVO getToiletStatusVO) {
//校验参数是否存在
if (getToiletStatusVO == null || StringUtils.isBlank(getToiletStatusVO.getToiletCode()) || getToiletStatusVO.getToiletNearType() == null
|| StringUtils.isBlank(getToiletStatusVO.getStartTime()) || StringUtils.isBlank(getToiletStatusVO.getEndTime())) {
throw new BusinessException("必填项不能为空!",201);
}
//校验公厕是否存在
QueryWrapper<Toilet> toiletQueryWrapper = new QueryWrapper<>();
toiletQueryWrapper.eq("toilet_code",getToiletStatusVO.getToiletCode());
toiletQueryWrapper.eq("delete_status", Constant.TOILET_DEL_STATUS_NO);
List<Toilet> toiletList = toiletService.list(toiletQueryWrapper);
if (CollectionUtils.isEmpty(toiletList)) {
throw new BusinessException("公厕信息不存在!",202);
}
Long toiletId = toiletList.get(0).getId();
//查询公厕厕位状态数据
QueryWrapper<ToiletAirIndexAverage> toiletAirIndexAverageQueryWrapper = new QueryWrapper<>();
toiletAirIndexAverageQueryWrapper.eq("toilet_id",toiletId);
toiletAirIndexAverageQueryWrapper.eq("toilet_near_type",getToiletStatusVO.getToiletNearType());
toiletAirIndexAverageQueryWrapper.ge("create_time",getToiletStatusVO.getStartTime());
toiletAirIndexAverageQueryWrapper.le("create_time",getToiletStatusVO.getEndTime());
List<ToiletAirIndexAverage> toiletAirIndexAverageList = toiletAirIndexAverageService.list(toiletAirIndexAverageQueryWrapper);
return R.ok().put("data",toiletAirIndexAverageList);
}
@Override
public R getToiletElectricity(GetToiletStatusVO getToiletStatusVO) {
//校验参数是否存在
if (getToiletStatusVO == null || StringUtils.isBlank(getToiletStatusVO.getToiletCode())
|| StringUtils.isBlank(getToiletStatusVO.getStartTime()) || StringUtils.isBlank(getToiletStatusVO.getEndTime())) {
throw new BusinessException("必填项不能为空!",201);
}
//校验公厕是否存在
QueryWrapper<Toilet> toiletQueryWrapper = new QueryWrapper<>();
toiletQueryWrapper.eq("toilet_code",getToiletStatusVO.getToiletCode());
toiletQueryWrapper.eq("delete_status", Constant.TOILET_DEL_STATUS_NO);
List<Toilet> toiletList = toiletService.list(toiletQueryWrapper);
if (CollectionUtils.isEmpty(toiletList)) {
throw new BusinessException("公厕信息不存在!",202);
}
Long toiletId = toiletList.get(0).getId();
//查询公厕厕位状态数据
QueryWrapper<ToiletElectricityConsumption> toiletElectricityConsumptionQueryWrapper = new QueryWrapper<>();
toiletElectricityConsumptionQueryWrapper.eq("toilet_id",toiletId);
toiletElectricityConsumptionQueryWrapper.ge("create_time",getToiletStatusVO.getStartTime());
toiletElectricityConsumptionQueryWrapper.le("create_time",getToiletStatusVO.getEndTime());
List<ToiletElectricityConsumption> toiletElectricityConsumptionList = toiletElectricityConsumptionService.list(toiletElectricityConsumptionQueryWrapper);
return R.ok().put("data",toiletElectricityConsumptionList);
}
@Override
public R getToiletWater(GetToiletStatusVO getToiletStatusVO) {
//校验参数是否存在
if (getToiletStatusVO == null || StringUtils.isBlank(getToiletStatusVO.getToiletCode())
|| StringUtils.isBlank(getToiletStatusVO.getStartTime()) || StringUtils.isBlank(getToiletStatusVO.getEndTime())) {
throw new BusinessException("必填项不能为空!",201);
}
//校验公厕是否存在
QueryWrapper<Toilet> toiletQueryWrapper = new QueryWrapper<>();
toiletQueryWrapper.eq("toilet_code",getToiletStatusVO.getToiletCode());
toiletQueryWrapper.eq("delete_status", Constant.TOILET_DEL_STATUS_NO);
List<Toilet> toiletList = toiletService.list(toiletQueryWrapper);
if (CollectionUtils.isEmpty(toiletList)) {
throw new BusinessException("公厕信息不存在!",202);
}
Long toiletId = toiletList.get(0).getId();
//查询公厕厕位状态数据
QueryWrapper<ToiletWaterConsumption> toiletWaterConsumptionQueryWrapper = new QueryWrapper<>();
toiletWaterConsumptionQueryWrapper.eq("toilet_id",toiletId);
toiletWaterConsumptionQueryWrapper.ge("create_time",getToiletStatusVO.getStartTime());
toiletWaterConsumptionQueryWrapper.le("create_time",getToiletStatusVO.getEndTime());
List<ToiletWaterConsumption> toiletWaterConsumptionList = toiletWaterConsumptionService.list(toiletWaterConsumptionQueryWrapper);
return R.ok().put("data",toiletWaterConsumptionList);
}
}

31
src/main/java/com/example/modular/shangyudata/vo/GetToiletStatusVO.java

@ -0,0 +1,31 @@
package com.example.modular.shangyudata.vo;
import lombok.Data;
/**
* 获取公厕厕位状态数据参数类
*/
@Data
public class GetToiletStatusVO {
public GetToiletStatusVO () {
}
/**
* 公厕编码
*/
private String toiletCode;
/**
* 公厕厕位 1男厕 2女厕
*/
private Integer toiletNearType;
/**
* 开始时间格式yyyy-MM-dd HH:mm:ss
*/
private String startTime;
/**
* 结束时间格式yyyy-MM-dd HH:mm:ss
*/
private String endTime;
}
Loading…
Cancel
Save