This commit is contained in:
listom
2024-08-16 14:08:28 +08:00
51 changed files with 2206 additions and 463 deletions

View File

@ -6,6 +6,7 @@ fastbee:
demoEnabled: true # 实例演示开关
# 文件路径以uploadPath结尾 示例( Windows配置 D:/uploadPathLinux配置 /uploadPath
profile: /home/soft/hzwmiot/uploadPath
# profile: D:/uploadPath
addressEnabled: true # 获取ip地址开关
captchaType: math # 验证码类型 math 数组计算 char 字符验证

View File

@ -76,7 +76,11 @@
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.73</version>
</dependency>
<!-- 阿里JSON解析器 -->
<dependency>
<groupId>com.alibaba.fastjson2</groupId>

View File

@ -0,0 +1,24 @@
package com.fastbee.common.utils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class DevParamsUtils {
public static Map<String, Object> getDevParams(String evParams) {
Map<String, Object> devData = new HashMap<>();
try{
Object devParams = com.alibaba.fastjson.JSON.parse(evParams); //先转换成Object
List<Map<String, Object>> Params = (List<Map<String, Object>>) devParams;
if (Params != null) {
for (Map<String, Object> param : Params) {
devData.put(param.get("key").toString(), param.get("value").toString());
}
}
}catch (Exception exception){
}
return devData;
}
}

View File

@ -0,0 +1,84 @@
package com.fastbee.common.utils;
import java.text.DecimalFormat;
/**
* 数字工具类
*/
public class NumberUtils {
/**
* 保留两位小数不足补0
* @param number
* @return
*/
public static float formatFloat(float number) {
return (float) (Math.round(number * 100) / 100.0);
}
/**
* 保留两位小数不足补0
* @param number
* @return
*/
public static Double formatDouble(Double number) {
return (Double) (Math.round(number * 100) / 100.0);
}
/**
* 字符串类型保留两位小数不足补0
* @param str
* @return
*/
public static String formatString(String str) {
if (isNumeric(str)) {
float number = Float.parseFloat(str);
DecimalFormat df = new DecimalFormat("0.00");
return df.format(number);
} else {
return str;
}
}
/**
* 字符串类型保留三位小数不足补0
* @param str
* @return
*/
public static String formatThreeString(String str) {
if (isNumeric(str)) {
float number = Float.parseFloat(str);
DecimalFormat df = new DecimalFormat("0.000");
return df.format(number);
} else {
return str;
}
}
/**
* 字符串类型保留三位小数不足补0
* @param str
* @param format 样式例如0.000
* @return
*/
public static String formatStringByFormat(String str,String format) {
if (isNumeric(str)) {
float number = Float.parseFloat(str);
DecimalFormat df = new DecimalFormat(format);
return df.format(number);
} else {
return str;
}
}
/**
* 正则判断是否为数字
* @param str
* @return
*/
public static boolean isNumeric(String str) {
return str.matches("-?\\d+(\\.\\d+)?");
}
}

View File

@ -111,7 +111,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
.antMatchers("/login", "/register", "/captchaImage", "/iot/tool/register", "/iot/tool/ntp", "/iot/tool/download",
"/iot/tool/mqtt/auth", "/iot/tool/mqtt/authv5", "/iot/tool/mqtt/webhook", "/iot/tool/mqtt/webhookv5", "/auth/**/**",
"/wechat/mobileLogin", "/wechat/miniLogin", "/wechat/wxBind/callback").permitAll()
"/wechat/mobileLogin", "/wechat/miniLogin", "/wechat/wxBind/callback","/waterele/rechargerecord/queryUnchargeAmount",
"/waterele/rechargerecord/rechargeReply","/iot/device/**").permitAll()
.antMatchers("/zlmhook/**").permitAll()
.antMatchers("/ruleengine/rulemanager/**").permitAll()
.antMatchers("/goview/sys/login", "/goview/project/getData").permitAll()

View File

@ -14,6 +14,7 @@ import com.fastbee.common.utils.SecurityUtils;
import com.fastbee.common.utils.StringUtils;
import com.fastbee.common.utils.poi.ExcelUtil;
import com.fastbee.iot.domain.Device;
import com.fastbee.iot.domain.JiankongDeviceParam;
import com.fastbee.iot.model.DeviceAssignmentVO;
import com.fastbee.iot.model.DeviceImportVO;
import com.fastbee.iot.model.DeviceRelateUserInput;
@ -48,8 +49,7 @@ import java.util.stream.Collectors;
@Api(tags = "设备管理")
@RestController
@RequestMapping("/iot/device")
public class DeviceController extends BaseController
{
public class DeviceController extends BaseController {
@Autowired
private IDeviceService deviceService;
@ -60,11 +60,10 @@ public class DeviceController extends BaseController
/**
* 查询设备列表
*/
@PreAuthorize("@ss.hasPermi('iot:device:list')")
// @PreAuthorize("@ss.hasPermi('iot:device:list')")
@GetMapping("/list")
@ApiOperation("设备分页列表")
public TableDataInfo list(Device device)
{
public TableDataInfo list(Device device) {
startPage();
// 限制当前用户机构
if (null == device.getDeptId()) {
@ -76,11 +75,10 @@ public class DeviceController extends BaseController
/**
* 查询未分配授权码设备列表
*/
@PreAuthorize("@ss.hasPermi('iot:device:list')")
// @PreAuthorize("@ss.hasPermi('iot:device:list')")
@GetMapping("/unAuthlist")
@ApiOperation("设备分页列表")
public TableDataInfo unAuthlist(Device device)
{
public TableDataInfo unAuthlist(Device device) {
startPage();
if (null == device.getDeptId()) {
device.setDeptId(getLoginUser().getDeptId());
@ -91,11 +89,10 @@ public class DeviceController extends BaseController
/**
* 查询分组可添加设备
*/
@PreAuthorize("@ss.hasPermi('iot:device:list')")
// @PreAuthorize("@ss.hasPermi('iot:device:list')")
@GetMapping("/listByGroup")
@ApiOperation("查询分组可添加设备分页列表")
public TableDataInfo listByGroup(Device device)
{
public TableDataInfo listByGroup(Device device) {
startPage();
LoginUser loginUser = getLoginUser();
if (null == loginUser.getDeptId()) {
@ -111,11 +108,10 @@ public class DeviceController extends BaseController
/**
* 查询设备简短列表,主页列表数据
*/
@PreAuthorize("@ss.hasPermi('iot:device:list')")
// @PreAuthorize("@ss.hasPermi('iot:device:list')")
@GetMapping("/shortList")
@ApiOperation("设备分页简短列表")
public TableDataInfo shortList(Device device)
{
public TableDataInfo shortList(Device device) {
startPage();
LoginUser loginUser = getLoginUser();
if (null == loginUser.getDeptId()) {
@ -126,7 +122,7 @@ public class DeviceController extends BaseController
if (null == device.getDeptId()) {
device.setDeptId(getLoginUser().getDeptId());
}
if (Objects.isNull(device.getTenantId())){
if (Objects.isNull(device.getTenantId())) {
device.setTenantId(getLoginUser().getUserId());
}
if (null == device.getShowChild()) {
@ -138,11 +134,10 @@ public class DeviceController extends BaseController
/**
* 查询所有设备简短列表
*/
@PreAuthorize("@ss.hasPermi('iot:device:list')")
// @PreAuthorize("@ss.hasPermi('iot:device:list')")
@GetMapping("/all")
@ApiOperation("查询所有设备简短列表")
public TableDataInfo allShortList()
{
public TableDataInfo allShortList() {
Device device = new Device();
device.setDeptId(SecurityUtils.getLoginUser().getUser().getDeptId());
device.setShowChild(true);
@ -152,12 +147,11 @@ public class DeviceController extends BaseController
/**
* 导出设备列表
*/
@PreAuthorize("@ss.hasPermi('iot:device:export')")
// @PreAuthorize("@ss.hasPermi('iot:device:export')")
@Log(title = "设备", businessType = BusinessType.EXPORT)
@PostMapping("/export")
@ApiOperation("导出设备")
public void export(HttpServletResponse response, Device device)
{
public void export(HttpServletResponse response, Device device) {
List<Device> list = deviceService.selectDeviceList(device);
ExcelUtil<Device> util = new ExcelUtil<Device>(Device.class);
util.exportExcel(response, list, "设备数据");
@ -166,82 +160,76 @@ public class DeviceController extends BaseController
/**
* 获取设备详细信息
*/
@PreAuthorize("@ss.hasPermi('iot:device:query')")
// @PreAuthorize("@ss.hasPermi('iot:device:query')")
@GetMapping(value = "/{deviceId}")
@ApiOperation("获取设备详情")
public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId)
{
public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId) {
Device device = deviceService.selectDeviceByDeviceId(deviceId);
// 判断当前用户是否有设备分享权限 (设备所属机构管理员和设备所属用户有权限)
LoginUser loginUser = getLoginUser();
List<SysRole> roles = loginUser.getUser().getRoles();
//判断当前用户是否为设备所属机构管理员
if(roles.stream().anyMatch(a-> "admin".equals(a.getRoleKey()))){
device.setIsOwner(1);
} else {
//判断当前用户是否是设备所属用户
if (Objects.equals(device.getTenantId(), loginUser.getUserId())){
device.setIsOwner(1);
}else {
device.setIsOwner(0);
}
}
// LoginUser loginUser = getLoginUser();
// List<SysRole> roles = loginUser.getUser().getRoles();
// //判断当前用户是否为设备所属机构管理员
// if (roles.stream().anyMatch(a -> "admin".equals(a.getRoleKey()))) {
// device.setIsOwner(1);
// } else {
// //判断当前用户是否是设备所属用户
// if (Objects.equals(device.getTenantId(), loginUser.getUserId())) {
// device.setIsOwner(1);
// } else {
// device.setIsOwner(0);
// }
// }
return AjaxResult.success(device);
}
/**
* 设备数据同步
*/
@PreAuthorize("@ss.hasPermi('iot:device:query')")
// @PreAuthorize("@ss.hasPermi('iot:device:query')")
@GetMapping(value = "/synchronization/{serialNumber}")
@ApiOperation("设备数据同步")
public AjaxResult deviceSynchronization(@PathVariable("serialNumber") String serialNumber)
{
public AjaxResult deviceSynchronization(@PathVariable("serialNumber") String serialNumber) {
return AjaxResult.success(messagePublish.deviceSynchronization(serialNumber));
}
/**
* 根据设备编号详细信息
*/
@PreAuthorize("@ss.hasPermi('iot:device:query')")
// @PreAuthorize("@ss.hasPermi('iot:device:query')")
@GetMapping(value = "/getDeviceBySerialNumber/{serialNumber}")
@ApiOperation("根据设备编号获取设备详情")
public AjaxResult getInfoBySerialNumber(@PathVariable("serialNumber") String serialNumber)
{
public AjaxResult getInfoBySerialNumber(@PathVariable("serialNumber") String serialNumber) {
return AjaxResult.success(deviceService.selectDeviceBySerialNumber(serialNumber));
}
/**
* 获取设备统计信息
*/
@PreAuthorize("@ss.hasPermi('iot:device:query')")
// @PreAuthorize("@ss.hasPermi('iot:device:query')")
@GetMapping(value = "/statistic")
@ApiOperation("获取设备统计信息")
public AjaxResult getDeviceStatistic()
{
public AjaxResult getDeviceStatistic() {
return AjaxResult.success(deviceService.selectDeviceStatistic());
}
/**
* 获取设备详细信息
*/
@PreAuthorize("@ss.hasPermi('iot:device:query')")
// @PreAuthorize("@ss.hasPermi('iot:device:query')")
@GetMapping(value = "/runningStatus")
@ApiOperation("获取设备详情和运行状态")
public AjaxResult getRunningStatusInfo(Long deviceId)
{
public AjaxResult getRunningStatusInfo(Long deviceId) {
return AjaxResult.success(deviceService.selectDeviceRunningStatusByDeviceId(deviceId));
}
/**
* 新增设备
*/
@PreAuthorize("@ss.hasPermi('iot:device:add')")
// @PreAuthorize("@ss.hasPermi('iot:device:add')")
@Log(title = "添加设备", businessType = BusinessType.INSERT)
@PostMapping
@ApiOperation("添加设备")
public AjaxResult add(@RequestBody Device device)
{
public AjaxResult add(@RequestBody Device device) {
return AjaxResult.success(deviceService.insertDevice(device));
}
@ -249,16 +237,15 @@ public class DeviceController extends BaseController
* TODO --APP
* 终端用户绑定设备
*/
@PreAuthorize("@ss.hasPermi('iot:device:add')")
// @PreAuthorize("@ss.hasPermi('iot:device:add')")
@Log(title = "设备关联用户", businessType = BusinessType.UPDATE)
@PostMapping("/relateUser")
@ApiOperation("终端-设备关联用户")
public AjaxResult relateUser(@RequestBody DeviceRelateUserInput deviceRelateUserInput)
{
if(deviceRelateUserInput.getUserId()==0 || deviceRelateUserInput.getUserId()==null){
public AjaxResult relateUser(@RequestBody DeviceRelateUserInput deviceRelateUserInput) {
if (deviceRelateUserInput.getUserId() == 0 || deviceRelateUserInput.getUserId() == null) {
return AjaxResult.error(MessageUtils.message("device.user.id.null"));
}
if(deviceRelateUserInput.getDeviceNumberAndProductIds()==null || deviceRelateUserInput.getDeviceNumberAndProductIds().size()==0){
if (deviceRelateUserInput.getDeviceNumberAndProductIds() == null || deviceRelateUserInput.getDeviceNumberAndProductIds().size() == 0) {
return AjaxResult.error(MessageUtils.message("device.product.id.null"));
}
return deviceService.deviceRelateUser(deviceRelateUserInput);
@ -267,25 +254,23 @@ public class DeviceController extends BaseController
/**
* 修改设备
*/
@PreAuthorize("@ss.hasPermi('iot:device:edit')")
// @PreAuthorize("@ss.hasPermi('iot:device:edit')")
@Log(title = "修改设备", businessType = BusinessType.UPDATE)
@PutMapping
@ApiOperation("修改设备")
public AjaxResult edit(@RequestBody Device device)
{
public AjaxResult edit(@RequestBody Device device) {
return deviceService.updateDevice(device);
}
/**
* 重置设备状态
*/
@PreAuthorize("@ss.hasPermi('iot:device:edit')")
// @PreAuthorize("@ss.hasPermi('iot:device:edit')")
@Log(title = "重置设备状态", businessType = BusinessType.UPDATE)
@PutMapping("/reset/{serialNumber}")
@ApiOperation("重置设备状态")
public AjaxResult resetDeviceStatus(@PathVariable String serialNumber)
{
Device device=new Device();
public AjaxResult resetDeviceStatus(@PathVariable String serialNumber) {
Device device = new Device();
device.setSerialNumber(serialNumber);
return toAjax(deviceService.resetDeviceStatus(device.getSerialNumber()));
}
@ -293,7 +278,7 @@ public class DeviceController extends BaseController
/**
* 删除设备
*/
@PreAuthorize("@ss.hasPermi('iot:device:remove')")
// @PreAuthorize("@ss.hasPermi('iot:device:remove')")
@Log(title = "删除设备", businessType = BusinessType.DELETE)
@DeleteMapping("/{deviceIds}")
@ApiOperation("批量删除设备")
@ -304,30 +289,30 @@ public class DeviceController extends BaseController
/**
* 生成设备编号
*/
@PreAuthorize("@ss.hasPermi('iot:device:add')")
// @PreAuthorize("@ss.hasPermi('iot:device:add')")
@GetMapping("/generator")
@ApiOperation("生成设备编号")
public AjaxResult generatorDeviceNum(Integer type){
return AjaxResult.success(MessageUtils.message("operate.success"),deviceService.generationDeviceNum(type));
public AjaxResult generatorDeviceNum(Integer type) {
return AjaxResult.success(MessageUtils.message("operate.success"), deviceService.generationDeviceNum(type));
}
/**
* 获取设备MQTT连接参数
*
* @param deviceId 设备主键id
* @return
*/
@PreAuthorize("@ss.hasPermi('iot:device:query')")
// @PreAuthorize("@ss.hasPermi('iot:device:query')")
@GetMapping("/getMqttConnectData")
@ApiOperation("获取设备MQTT连接参数")
public AjaxResult getMqttConnectData(Long deviceId){
public AjaxResult getMqttConnectData(Long deviceId) {
return AjaxResult.success(deviceService.getMqttConnectData(deviceId));
}
@PreAuthorize("@ss.hasPermi('iot:device:add')")
// @PreAuthorize("@ss.hasPermi('iot:device:add')")
@ApiOperation("下载设备导入模板")
@PostMapping("/uploadTemplate")
public void uploadTemplate(HttpServletResponse response, @RequestParam(name = "type") Integer type)
{
public void uploadTemplate(HttpServletResponse response, @RequestParam(name = "type") Integer type) {
// 1-设备导入2-设备分配
if (1 == type) {
ExcelUtil<DeviceImportVO> util = new ExcelUtil<>(DeviceImportVO.class);
@ -338,12 +323,11 @@ public class DeviceController extends BaseController
}
}
@PreAuthorize("@ss.hasPermi('iot:device:add')")
// @PreAuthorize("@ss.hasPermi('iot:device:add')")
@ApiOperation("批量导入设备")
@Log(title = "用户管理", businessType = BusinessType.IMPORT)
@PostMapping("/importData")
public AjaxResult importData(@RequestParam("file") MultipartFile file, @RequestParam("productId") Long productId) throws Exception
{
public AjaxResult importData(@RequestParam("file") MultipartFile file, @RequestParam("productId") Long productId) throws Exception {
if (null == file) {
return error(MessageUtils.message("import.failed.file.null"));
}
@ -360,14 +344,11 @@ public class DeviceController extends BaseController
return StringUtils.isEmpty(message) ? success(MessageUtils.message("import.success")) : error(message);
}
@PreAuthorize("@ss.hasPermi('iot:device:assignment')")
// @PreAuthorize("@ss.hasPermi('iot:device:assignment')")
@ApiOperation("批量导入分配设备")
@Log(title = "用户管理", businessType = BusinessType.IMPORT)
@PostMapping("/importAssignmentData")
public AjaxResult importAssignmentData(@RequestParam("file") MultipartFile file,
@RequestParam("productId") Long productId,
@RequestParam("deptId") Long deptId) throws Exception
{
public AjaxResult importAssignmentData(@RequestParam("file") MultipartFile file, @RequestParam("productId") Long productId, @RequestParam("deptId") Long deptId) throws Exception {
if (null == file) {
return error(MessageUtils.message("import.failed.file.null"));
}
@ -386,15 +367,15 @@ public class DeviceController extends BaseController
/**
* 分配设备
*
* @param deptId 机构id
* @param: deviceIds 设备id字符串
* @return com.fastbee.common.core.domain.AjaxResult
* @param: deviceIds 设备id字符串
*/
@PreAuthorize("@ss.hasPermi('iot:device:assignment')")
// @PreAuthorize("@ss.hasPermi('iot:device:assignment')")
@ApiOperation("分配设备")
@PostMapping("/assignment")
public AjaxResult assignment(@RequestParam("deptId") Long deptId,
@RequestParam("deviceIds") String deviceIds) {
public AjaxResult assignment(@RequestParam("deptId") Long deptId, @RequestParam("deviceIds") String deviceIds) {
if (null == deptId) {
return error(MessageUtils.message("device.dept.id.null"));
}
@ -406,14 +387,14 @@ public class DeviceController extends BaseController
/**
* 回收设备
* @param: deviceIds 设备id字符串
*
* @return com.fastbee.common.core.domain.AjaxResult
* @param: deviceIds 设备id字符串
*/
@PreAuthorize("@ss.hasPermi('iot:device:recovery')")
// @PreAuthorize("@ss.hasPermi('iot:device:recovery')")
@ApiOperation("回收设备")
@PostMapping("/recovery")
public AjaxResult recovery(@RequestParam("deviceIds") String deviceIds,
@RequestParam("recoveryDeptId") Long recoveryDeptId) {
public AjaxResult recovery(@RequestParam("deviceIds") String deviceIds, @RequestParam("recoveryDeptId") Long recoveryDeptId) {
if (StringUtils.isEmpty(deviceIds)) {
return error("请选择设备");
}
@ -423,11 +404,10 @@ public class DeviceController extends BaseController
/**
* 批量生成设备编号
*/
@PreAuthorize("@ss.hasPermi('iot:device:batchGenerator')")
// @PreAuthorize("@ss.hasPermi('iot:device:batchGenerator')")
@PostMapping("/batchGenerator")
@ApiOperation("批量生成设备编号")
public void batchGeneratorDeviceNum(HttpServletResponse response,
@RequestParam("count") Integer count){
public void batchGeneratorDeviceNum(HttpServletResponse response, @RequestParam("count") Integer count) {
if (count > 200) {
throw new ServiceException("最多只能生成200个");
}
@ -445,11 +425,10 @@ public class DeviceController extends BaseController
/**
* 查询变量概况
*/
@PreAuthorize("@ss.hasPermi('iot:device:query')")
// @PreAuthorize("@ss.hasPermi('iot:device:query')")
@GetMapping("/listThingsModel")
@ApiOperation("查询变量概况")
public TableDataInfo listThingsModel(Integer pageNum, Integer pageSize, Long deviceId, String modelName, Integer type)
{
public TableDataInfo listThingsModel(Integer pageNum, Integer pageSize, Long deviceId, String modelName, Integer type) {
TableDataInfo rspData = new TableDataInfo();
rspData.setCode(HttpStatus.SUCCESS);
rspData.setMsg("查询成功");
@ -497,9 +476,20 @@ public class DeviceController extends BaseController
*/
@GetMapping("/getDeviceLogAllCurves")
@ApiOperation("查询设备历史数据曲线图")
public AjaxResult getDeviceLogAllCurves(Long deviceId,String beginTime ,String endTime) {
ArrayList<Object> data = deviceService.getDeviceLogAllCurves(deviceId,beginTime ,endTime);
public AjaxResult getDeviceLogAllCurves(Long deviceId, String beginTime, String endTime) {
ArrayList<Object> data = deviceService.getDeviceLogAllCurves(deviceId, beginTime, endTime);
return success(data);
}
/**
* 获取视频监控
*
* @param
* @return
*/
@GetMapping("/getvideourl")
public AjaxResult getvideourl(JiankongDeviceParam baseGet) throws Exception {
return AjaxResult.success(deviceService.getvideourl(baseGet));
}
}

View File

@ -1,4 +1,4 @@
package com.fastbee.iot.anfang.controller;
package com.fastbee.data.controller.anfang.controller;
import com.fastbee.common.annotation.Log;
import com.fastbee.common.config.RuoYiConfig;
@ -9,7 +9,7 @@ import com.fastbee.common.enums.BusinessType;
import com.fastbee.common.exception.ServiceException;
import com.fastbee.common.utils.file.FileUploadUtils;
import com.fastbee.common.utils.poi.ExcelUtil;
import com.fastbee.iot.anfang.service.IUploadedPhotosService;
import com.fastbee.data.controller.anfang.service.IUploadedPhotosService;
import com.fastbee.iot.model.anfang.UploadedPhotos;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
@ -110,9 +110,12 @@ public class UploadedPhotosController extends BaseController
// 处理时间戳
long timestamp = Long.parseLong(time + "000");
Date date = new Date(timestamp);
//抓拍监控并返回路径
String monitorPath = uploadedPhotosService.captureMonitorPhoto(sn);
//推送告警短信通知
uploadedPhotosService.sendAlarmMessage(sn, doorState, shakeState);
UploadedPhotos uploadedPhotos = new UploadedPhotos(
null, fileName, imei, sn, latitude, longitude, temperature, doorState, shakeState, date
null, fileName, monitorPath,imei, sn, latitude, longitude, temperature, doorState, shakeState, date
);
return toAjax(uploadedPhotosService.insertUploadedPhotos(uploadedPhotos));
} catch (IOException e) {

View File

@ -1,4 +1,4 @@
package com.fastbee.iot.anfang.service;
package com.fastbee.data.controller.anfang.service;
import com.fastbee.iot.model.anfang.UploadedPhotos;
@ -59,4 +59,19 @@ public interface IUploadedPhotosService
* @return 结果
*/
public int deleteUploadedPhotosById(Long id);
/**
* 抓拍监控照片
* @param sn
* @return
*/
String captureMonitorPhoto(String sn);
/**
* 发送短信通知
* @param sn
* @param doorState
* @param shakeState
*/
void sendAlarmMessage(String sn, String doorState, String shakeState);
}

View File

@ -0,0 +1,275 @@
package com.fastbee.data.controller.anfang.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONObject;
import com.fastbee.common.config.RuoYiConfig;
import com.fastbee.common.utils.DevParamsUtils;
import com.fastbee.common.utils.StringUtils;
import com.fastbee.common.utils.file.FileUploadUtils;
import com.fastbee.data.controller.anfang.service.IUploadedPhotosService;
import com.fastbee.iot.domain.Device;
import com.fastbee.iot.domain.DeviceAlertUser;
import com.fastbee.iot.haikang.HaikangYingshiApi;
import com.fastbee.iot.mapper.DeviceAlertUserMapper;
import com.fastbee.iot.mapper.UploadedPhotosMapper;
import com.fastbee.iot.model.anfang.UploadedPhotos;
import com.fastbee.iot.service.IDeviceService;
import com.fastbee.notify.core.service.NotifySendService;
import com.fastbee.notify.core.vo.SendParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 存储上传的照片信息Service业务层处理
*
* @author kerwincui
* @date 2024-06-20
*/
@Service
public class UploadedPhotosServiceImpl implements IUploadedPhotosService
{
@Resource
private UploadedPhotosMapper uploadedPhotosMapper;
@Autowired
private IDeviceService deviceService;
@Autowired
private NotifySendService notifySendService;
@Autowired
private RuoYiConfig ruoYiConfig;
private HaikangYingshiApi haikangYingshiApi;
@Autowired
private DeviceAlertUserMapper deviceAlertUserMapper;
/**
* 查询存储上传的照片信息
*
* @param id 存储上传的照片信息主键
* @return 存储上传的照片信息
*/
@Override
public UploadedPhotos selectUploadedPhotosById(Long id)
{
return uploadedPhotosMapper.selectUploadedPhotosById(id);
}
/**
* 查询存储上传的照片信息列表
*
* @param uploadedPhotos 存储上传的照片信息
* @return 存储上传的照片信息
*/
@Override
public List<UploadedPhotos> selectUploadedPhotosList(UploadedPhotos uploadedPhotos)
{
return uploadedPhotosMapper.selectUploadedPhotosList(uploadedPhotos);
}
/**
* 新增存储上传的照片信息
*
* @param uploadedPhotos 存储上传的照片信息
* @return 结果
*/
@Override
public int insertUploadedPhotos(UploadedPhotos uploadedPhotos)
{
return uploadedPhotosMapper.insertUploadedPhotos(uploadedPhotos);
}
/**
* 修改存储上传的照片信息
*
* @param uploadedPhotos 存储上传的照片信息
* @return 结果
*/
@Override
public int updateUploadedPhotos(UploadedPhotos uploadedPhotos)
{
return uploadedPhotosMapper.updateUploadedPhotos(uploadedPhotos);
}
/**
* 批量删除存储上传的照片信息
*
* @param ids 需要删除的存储上传的照片信息主键
* @return 结果
*/
@Override
public int deleteUploadedPhotosByIds(Long[] ids)
{
return uploadedPhotosMapper.deleteUploadedPhotosByIds(ids);
}
/**
* 删除存储上传的照片信息信息
*
* @param id 存储上传的照片信息主键
* @return 结果
*/
@Override
public int deleteUploadedPhotosById(Long id)
{
return uploadedPhotosMapper.deleteUploadedPhotosById(id);
}
@Override
public String captureMonitorPhoto(String sn) {
Device device = deviceService.selectDeviceBySerialNumber(sn);
if (device == null) {
return "";
}
Map<String, Object> devParams = DevParamsUtils.getDevParams(device.getDevParams());
if(!devParams.containsKey("jiankongIds")){
return "";
}
String jiankongIds = devParams.get("jiankongIds").toString();
Device jiankongDevice = deviceService.selectDeviceByDeviceId(Long.parseLong(jiankongIds));
if(jiankongDevice == null){
return "";
}
Map devData = DevParamsUtils.getDevParams(jiankongDevice.getDevParams());
if (devData.get("appKey") == null) {
return "";
}
if (devData.get("appSecret") == null) {
return "";
}
if (devData.get("channelNo") == null) {
return "";
}
Map<String, Object> map = new HashMap<>();//存放参数
map.put("appKey", devData.get("appKey"));
map.put("appSecret", devData.get("appSecret"));
cn.hutool.json.JSONObject token = HaikangYingshiApi.getToken(map);
if (token != null && token.get("code").equals("200")) {
Map<String, Object> params = new HashMap<>();
token = (cn.hutool.json.JSONObject) token.get("data");
params.put("accessToken", token.get("accessToken"));
params.put("deviceSerial", jiankongDevice.getSerialNumber());
params.put("channelNo", devData.get("channelNo"));
cn.hutool.json.JSONObject token1 = HaikangYingshiApi.capture(params);
if (token1 != null && token1.get("code").equals("200")) {
String dirs = DateUtil.thisYear() + "/" + (DateUtil.thisMonth() + 1) + "/" + DateUtil.thisDayOfMonth();
File dirfile = new File(RuoYiConfig.getUploadPath() + "/" + dirs);
if (!dirfile.exists()) {
// 目录不存在,创建目录
boolean created = dirfile.mkdirs();
if (created) {
} else {
}
} else {
}
Map data = (JSONObject) token1.get("data");
Map<String, Object> reMap = new HashMap<>();
reMap.put("picUrl", data.get("picUrl"));
if (data.get("picUrl") != null) {
try {
String picUrl = data.get("picUrl").toString();
URL url = new URL(picUrl);
HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
int responseCode = httpConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
InputStream inputStream = httpConnection.getInputStream();
byte[] buffer = new byte[4096];
int bytesRead = -1;
String[] split1 = picUrl.split("\\.");
String filename =
DateUtil.date().toDateStr() + "-" + DateUtil.thisHour(true)
+ DateUtil.thisMinute() +
"-anfangmonitor-" + device.getDeviceId() + "."
+ split1[split1.length - 1].split("\\?")[0];
String pathUrl = RuoYiConfig.getUploadPath() + "/" + dirs + "/" + filename;
OutputStream outputStream = new FileOutputStream(pathUrl);
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
outputStream.close();
inputStream.close();
String httpimg = FileUploadUtils.getPathFileName(RuoYiConfig.getUploadPath(), dirs +
"/" + filename);
return httpimg;
} else {
System.out.println("读取http图片失败!");
return "";
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
return "";
} else {
return "";
}
}
return "";
}
@Override
public void sendAlarmMessage(String sn, String doorState, String shakeState) {
//
boolean notify = false;
SendParams sendParams = new SendParams();
sendParams.setId(14L);
Map<String,String> temp = new HashMap<>();
Device device = deviceService.selectDeviceBySerialNumber(sn);
if (device == null) {
return;
}
Map<String, Object> devParams = DevParamsUtils.getDevParams(device.getDevParams());
Device jijingDevice = null;
if(devParams.containsKey("jijingIds")){
String jijingIds = devParams.get("jijingIds").toString();
jijingDevice = deviceService.selectDeviceByDeviceId(Long.parseLong(jijingIds));
if (jijingDevice == null){
return;
}
temp.put("stationName",jijingDevice.getDeviceName());
}else{
return;
}
if(Integer.parseInt(doorState) == 1){
temp.put("warnInfo","箱门打开");
notify = true;
}else {
if(Integer.parseInt(shakeState) == 1){
temp.put("warnInfo","箱门振动");
notify = true;
}
}
if(notify){
DeviceAlertUser deviceAlertUser = new DeviceAlertUser();
deviceAlertUser.setDeviceId(jijingDevice.getDeviceId());
List<DeviceAlertUser> deviceAlertUsers = deviceAlertUserMapper.selectDeviceAlertUserList(deviceAlertUser);
if(deviceAlertUsers.size() > 0){
String phone = "";
for (int i = 0; i < deviceAlertUsers.size(); i++) {
if(i == 0){
phone = deviceAlertUsers.get(i).getPhoneNumber();
}else {
phone += "," + deviceAlertUsers.get(i).getPhoneNumber();
}
}
if(StringUtils.isEmpty(phone)){
return;
}
sendParams.setSendAccount(phone);
JSONObject jsonObject = new JSONObject(temp);
String jsonString = jsonObject.toString();
sendParams.setVariables(jsonString);
notifySendService.send(sendParams);
}
}
}
}

View File

@ -1,13 +1,13 @@
package com.fastbee.data.controller.devicedetail;
import com.alibaba.fastjson2.JSONObject;
import com.fastbee.common.core.controller.BaseController;
import com.fastbee.common.core.domain.AjaxResult;
import com.fastbee.common.core.domain.CommonResult;
import com.fastbee.common.model.vo.iot.QueryLogVo;
import com.fastbee.common.utils.StringUtils;
import com.fastbee.data.service.devicedetail.IDeviceDetailService;
import com.fastbee.iot.domain.Device;
import com.fastbee.iot.model.DeviceHistoryParam;
import com.fastbee.iot.model.haiwei.CmdHaiWeiVo;
import com.fastbee.iot.model.haiwei.dto.CmdHaiWeiDto;
import com.fastbee.waterele.domain.MaWatereleRecord;
import com.fastbee.waterele.domain.dto.MaGuangaiRecordDto;
import com.fastbee.waterele.domain.dto.MaWatereleRecordDto;
@ -15,10 +15,8 @@ import com.fastbee.xunjian.domain.XjInspectionRecords;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
@Api(tags = "设备详情数据")
@ -47,6 +45,9 @@ public class DeviceDetailController extends BaseController {
}
/**
* 查询灌溉记录
* @param maWatereleRecordDto 传参
@ -88,8 +89,32 @@ public class DeviceDetailController extends BaseController {
if (null == queryLogVo.getDeviceId() || queryLogVo.getDeviceId() == 0L) {
return AjaxResult.error("请选择设备");
}
List<HashMap<String, Object>> list = deviceDetailService.gongdianChart(queryLogVo);
return AjaxResult.success(list);
//设备历史echart数据
List<Object> list = deviceDetailService.gongdianChart(queryLogVo);
AjaxResult ajaxResult = AjaxResult.success();
ajaxResult.put("data", list);
ajaxResult.put("realData", deviceDetailService.gongdianRealData(queryLogVo));
return ajaxResult;
}
/**
* 查询用水数据
* @param queryLogVo 传参
* @return com.fastbee.common.core.domain.AjaxResult
*/
@ApiOperation("查询用水数据")
@GetMapping("/yongshuiChart")
public AjaxResult yongshuiChart(QueryLogVo queryLogVo)
{
if (null == queryLogVo.getDeviceId() || queryLogVo.getDeviceId() == 0L) {
return AjaxResult.error("请选择设备");
}
//设备历史echart数据
List<Object> list = deviceDetailService.yongshuiChart(queryLogVo);
AjaxResult ajaxResult = AjaxResult.success();
ajaxResult.put("data", list);
ajaxResult.put("realData", deviceDetailService.yongshuiRealData(queryLogVo));
return ajaxResult;
}
@ -109,6 +134,29 @@ public class DeviceDetailController extends BaseController {
return AjaxResult.success(list);
}
/**
* 获取安防信息
* @param deviceId 传参
* @return com.fastbee.common.core.domain.AjaxResult
*/
@ApiOperation("获取安防信息")
@GetMapping("/anfangInfo")
public AjaxResult anfangInfo(Long deviceId)
{
if (null == deviceId || deviceId == 0L) {
return AjaxResult.error("请传入设备号");
}
return AjaxResult.success(deviceDetailService.anfangInfo(deviceId));
}
@ApiOperation("箱门打开控制")
@PostMapping("/hwcmd")
public CommonResult<CmdHaiWeiVo> cmdDevices(@RequestBody CmdHaiWeiDto cmdHwDto) {
return deviceDetailService.cmdDevices(cmdHwDto);
}

View File

@ -46,10 +46,10 @@ public class MaGuangaiRecordController extends BaseController
@ApiOperation("查询灌溉记录列表")
public TableDataInfo list(MaGuangaiRecord maGuangaiRecord)
{
startPage();
List<MaGuangaiRecord> list
// startPage();
TableDataInfo tableDataInfo
= maGuangaiRecordService.selectMaGuangaiRecordList(maGuangaiRecord);
return getDataTable(list);
return tableDataInfo;
}
/**
@ -60,7 +60,8 @@ public class MaGuangaiRecordController extends BaseController
@PostMapping("/export")
public void export(HttpServletResponse response, MaGuangaiRecord maGuangaiRecord)
{
List<MaGuangaiRecord> list = maGuangaiRecordService.selectMaGuangaiRecordList(maGuangaiRecord);
TableDataInfo tableDataInfo = maGuangaiRecordService.selectMaGuangaiRecordList(maGuangaiRecord);
List<MaGuangaiRecord> list = (List<MaGuangaiRecord>) tableDataInfo.getRows();
ExcelUtil<MaGuangaiRecord> util = new ExcelUtil<MaGuangaiRecord>(MaGuangaiRecord.class);
util.exportExcel(response, list, "灌溉记录数据");
}

View File

@ -3,6 +3,7 @@ package com.fastbee.data.controller.waterele;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.fastbee.waterele.domain.vo.UnchargeAmountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
@ -33,19 +34,17 @@ import com.fastbee.common.core.page.TableDataInfo;
@RestController
@RequestMapping("/waterele/rechargerecord")
@Api(tags = "充值记录")
public class MaRechargerecordController extends BaseController
{
public class MaRechargerecordController extends BaseController {
@Autowired
private IMaRechargerecordService maRechargerecordService;
/**
/**
* 查询充值记录列表
*/
@PreAuthorize("@ss.hasPermi('waterele:rechargerecord:list')")
@GetMapping("/list")
@ApiOperation("查询充值记录列表")
public TableDataInfo list(MaRechargerecord maRechargerecord)
{
@PreAuthorize("@ss.hasPermi('waterele:rechargerecord:list')")
@GetMapping("/list")
@ApiOperation("查询充值记录列表")
public TableDataInfo list(MaRechargerecord maRechargerecord) {
startPage();
List<MaRechargerecord> list = maRechargerecordService.selectMaRechargerecordList(maRechargerecord);
return getDataTable(list);
@ -57,8 +56,7 @@ public class MaRechargerecordController extends BaseController
@ApiOperation("导出充值记录列表")
@PreAuthorize("@ss.hasPermi('waterele:rechargerecord:export')")
@PostMapping("/export")
public void export(HttpServletResponse response, MaRechargerecord maRechargerecord)
{
public void export(HttpServletResponse response, MaRechargerecord maRechargerecord) {
List<MaRechargerecord> list = maRechargerecordService.selectMaRechargerecordList(maRechargerecord);
ExcelUtil<MaRechargerecord> util = new ExcelUtil<MaRechargerecord>(MaRechargerecord.class);
util.exportExcel(response, list, "充值记录数据");
@ -70,8 +68,7 @@ public class MaRechargerecordController extends BaseController
@PreAuthorize("@ss.hasPermi('waterele:rechargerecord:query')")
@GetMapping(value = "/{id}")
@ApiOperation("获取充值记录详细信息")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
public AjaxResult getInfo(@PathVariable("id") Long id) {
return success(maRechargerecordService.selectMaRechargerecordById(id));
}
@ -81,8 +78,7 @@ public class MaRechargerecordController extends BaseController
@PreAuthorize("@ss.hasPermi('waterele:rechargerecord:add')")
@PostMapping
@ApiOperation("新增充值记录")
public AjaxResult add(@RequestBody MaRechargerecord maRechargerecord)
{
public AjaxResult add(@RequestBody MaRechargerecord maRechargerecord) {
return toAjax(maRechargerecordService.insertMaRechargerecord(maRechargerecord));
}
@ -92,8 +88,7 @@ public class MaRechargerecordController extends BaseController
@PreAuthorize("@ss.hasPermi('waterele:rechargerecord:edit')")
@PutMapping
@ApiOperation("修改充值记录")
public AjaxResult edit(@RequestBody MaRechargerecord maRechargerecord)
{
public AjaxResult edit(@RequestBody MaRechargerecord maRechargerecord) {
return toAjax(maRechargerecordService.updateMaRechargerecord(maRechargerecord));
}
@ -103,8 +98,26 @@ public class MaRechargerecordController extends BaseController
@PreAuthorize("@ss.hasPermi('waterele:rechargerecord:remove')")
@DeleteMapping("/{ids}")
@ApiOperation("删除充值记录")
public AjaxResult remove(@PathVariable Long[] ids)
{
public AjaxResult remove(@PathVariable Long[] ids) {
return toAjax(maRechargerecordService.deleteMaRechargerecordByIds(ids));
}
//通过卡ID和区域号查询未充值的记录返回总充值金额
// @PreAuthorize("@ss.hasPermi('waterele:rechargerecord:queryUnchargeAmount')")
@GetMapping("/queryUnchargeAmount")
@ApiOperation("查询未充值的记录")
public AjaxResult queryUnchargeAmount(MaRechargerecord maRechargerecord) {
UnchargeAmountVo amount = maRechargerecordService.queryUnchargeAmount(maRechargerecord);
return success(amount);
}
//充值成功后提交充值成功接口修改卡ID、区域号对应的未充值记录
// @PreAuthorize("@ss.hasPermi('waterele:rechargerecord:rechargeReply')")
@GetMapping("/rechargeReply")
@ApiOperation("充值成功反馈")
public AjaxResult rechargeReply(MaRechargerecord maRechargerecord) {
String msg = maRechargerecordService.rechargeReply(maRechargerecord);
return success(msg);
}
}

View File

@ -1,6 +1,8 @@
package com.fastbee.data.controller.waterele;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
@ -33,33 +35,43 @@ import com.fastbee.common.core.page.TableDataInfo;
@RestController
@RequestMapping("/waterele/watereleRecord")
@Api(tags = "水电双计数据记录")
public class MaWatereleRecordController extends BaseController
{
public class MaWatereleRecordController extends BaseController {
@Autowired
private IMaWatereleRecordService maWatereleRecordService;
/**
/**
* 查询水电双计数据记录列表
*/
@PreAuthorize("@ss.hasPermi('waterele:watereleRecord:list')")
@GetMapping("/list")
@ApiOperation("查询水电双计数据记录列表")
public TableDataInfo list(MaWatereleRecord maWatereleRecord)
{
startPage();
List<MaWatereleRecord> list = maWatereleRecordService.selectMaWatereleRecordList(maWatereleRecord);
return getDataTable(list);
@PreAuthorize("@ss.hasPermi('waterele:watereleRecord:list')")
@GetMapping("/list")
@ApiOperation("查询水电双计数据记录列表")
public TableDataInfo list(MaWatereleRecord maWatereleRecord) {
// startPage();
TableDataInfo tableDataInfo = maWatereleRecordService.selectMaWatereleRecordList(maWatereleRecord);
return tableDataInfo;
}
/**
* 查询水电双计数据记录echart
*/
@PreAuthorize("@ss.hasPermi('waterele:watereleRecord:echart')")
@GetMapping("/echart")
@ApiOperation("查询水电双计数据记录echart")
public Map<String, Object> echart(MaWatereleRecord maWatereleRecord) {
ArrayList<Object> list = maWatereleRecordService.chartData(maWatereleRecord);
return success(list);
}
/**
* 导出水电双计数据记录列表
*/
@ApiOperation("导出水电双计数据记录列表")
@PreAuthorize("@ss.hasPermi('waterele:watereleRecord:export')")
@PostMapping("/export")
public void export(HttpServletResponse response, MaWatereleRecord maWatereleRecord)
{
List<MaWatereleRecord> list = maWatereleRecordService.selectMaWatereleRecordList(maWatereleRecord);
public void export(HttpServletResponse response, MaWatereleRecord maWatereleRecord) {
TableDataInfo tableDataInfo= maWatereleRecordService.selectMaWatereleRecordList(maWatereleRecord);
List<MaWatereleRecord> list = (List<MaWatereleRecord>) tableDataInfo.getRows();
ExcelUtil<MaWatereleRecord> util = new ExcelUtil<MaWatereleRecord>(MaWatereleRecord.class);
util.exportExcel(response, list, "水电双计数据记录数据");
}
@ -70,8 +82,7 @@ public class MaWatereleRecordController extends BaseController
@PreAuthorize("@ss.hasPermi('waterele:watereleRecord:query')")
@GetMapping(value = "/{id}")
@ApiOperation("获取水电双计数据记录详细信息")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
public AjaxResult getInfo(@PathVariable("id") Long id) {
return success(maWatereleRecordService.selectMaWatereleRecordById(id));
}
@ -81,8 +92,7 @@ public class MaWatereleRecordController extends BaseController
@PreAuthorize("@ss.hasPermi('waterele:watereleRecord:add')")
@PostMapping
@ApiOperation("新增水电双计数据记录")
public AjaxResult add(@RequestBody MaWatereleRecord maWatereleRecord)
{
public AjaxResult add(@RequestBody MaWatereleRecord maWatereleRecord) {
return toAjax(maWatereleRecordService.insertMaWatereleRecord(maWatereleRecord));
}
@ -92,8 +102,7 @@ public class MaWatereleRecordController extends BaseController
@PreAuthorize("@ss.hasPermi('waterele:watereleRecord:edit')")
@PutMapping
@ApiOperation("修改水电双计数据记录")
public AjaxResult edit(@RequestBody MaWatereleRecord maWatereleRecord)
{
public AjaxResult edit(@RequestBody MaWatereleRecord maWatereleRecord) {
return toAjax(maWatereleRecordService.updateMaWatereleRecord(maWatereleRecord));
}
@ -103,8 +112,7 @@ public class MaWatereleRecordController extends BaseController
@PreAuthorize("@ss.hasPermi('waterele:watereleRecord:remove')")
@DeleteMapping("/{ids}")
@ApiOperation("删除水电双计数据记录")
public AjaxResult remove(@PathVariable Long[] ids)
{
public AjaxResult remove(@PathVariable Long[] ids) {
return toAjax(maWatereleRecordService.deleteMaWatereleRecordByIds(ids));
}
}

View File

@ -0,0 +1,24 @@
package com.fastbee.data.domain.vo;
import com.fastbee.iot.domain.Device;
import com.fastbee.iot.model.anfang.UploadedPhotos;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* 安防信息
*/
@Data
public class AnfangInfoVo {
@ApiModelProperty("监控设备")
private Device jiankongDevice;
@ApiModelProperty("门状态:0=正常1=箱门振动2=箱门打开")
private Integer doorStatus;
@ApiModelProperty("柜门ID,控制柜门开启的设备ID")
private String guimenId;
@ApiModelProperty("安防告警列表")
private List<UploadedPhotos>anfangList;
}

View File

@ -1,12 +1,17 @@
package com.fastbee.data.service.devicedetail;
import com.fastbee.common.core.domain.CommonResult;
import com.fastbee.common.model.vo.iot.QueryLogVo;
import com.fastbee.data.domain.vo.AnfangInfoVo;
import com.fastbee.iot.domain.Device;
import com.fastbee.iot.model.haiwei.CmdHaiWeiVo;
import com.fastbee.iot.model.haiwei.dto.CmdHaiWeiDto;
import com.fastbee.waterele.domain.MaWatereleRecord;
import com.fastbee.waterele.domain.dto.MaGuangaiRecordDto;
import com.fastbee.waterele.domain.dto.MaWatereleRecordDto;
import com.fastbee.xunjian.domain.XjInspectionRecords;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -23,7 +28,20 @@ public interface IDeviceDetailService {
List<Device> getBindDevices(String ids);
List<HashMap<String, Object>> gongdianChart(QueryLogVo queryLogVo);
ArrayList<Object> gongdianChart(QueryLogVo queryLogVo);
List<Object> yongshuiChart(QueryLogVo queryLogVo);
List<XjInspectionRecords> xunjianRecord(QueryLogVo queryLogVo);
CommonResult<CmdHaiWeiVo> cmdDevices(CmdHaiWeiDto cmdHaiWeiDto);
AnfangInfoVo anfangInfo(Long deviceId);
/**
* 供电实时数据
* @param queryLogVo
*/
List<HashMap<Object, Object>> gongdianRealData(QueryLogVo queryLogVo);
List<HashMap<Object, Object>> yongshuiRealData(QueryLogVo queryLogVo);
}

View File

@ -1,22 +1,62 @@
package com.fastbee.data.service.devicedetail.impl;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.fastbee.common.core.domain.CommonResult;
import com.fastbee.common.model.vo.iot.QueryLogVo;
import com.fastbee.common.utils.DevParamsUtils;
import com.fastbee.common.utils.StringUtils;
import com.fastbee.data.domain.vo.AnfangInfoVo;
import com.fastbee.data.service.devicedetail.IDeviceDetailService;
import com.fastbee.data.controller.anfang.service.IUploadedPhotosService;
import com.fastbee.iot.domain.Device;
import com.fastbee.iot.domain.DeviceLog;
import com.fastbee.iot.domain.ThingsModel;
import com.fastbee.iot.haiwei.service.HaiWeiService;
import com.fastbee.iot.mapper.DeviceMapper;
import com.fastbee.iot.model.anfang.UploadedPhotos;
import com.fastbee.iot.model.haiwei.CmdHaiWeiVo;
import com.fastbee.iot.model.haiwei.dto.CmdHaiWeiDto;
import com.fastbee.iot.service.IDeviceLogService;
import com.fastbee.iot.service.IDeviceService;
import com.fastbee.iot.service.IThingsModelService;
import com.fastbee.waterele.domain.MaWatereleRecord;
import com.fastbee.waterele.domain.dto.MaGuangaiRecordDto;
import com.fastbee.waterele.domain.dto.MaWatereleRecordDto;
import com.fastbee.xunjian.domain.XjInspectionRecords;
import com.fastbee.xunjian.domain.XjInspectionRoutes;
import com.fastbee.xunjian.mapper.XjInspectionRecordsMapper;
import com.fastbee.xunjian.mapper.XjInspectionRoutesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class DeviceDetailServiceImpl implements IDeviceDetailService {
private final DeviceMapper deviceMapper;
@Autowired
public IDeviceService iDeviceService;
@Autowired
private IThingsModelService thingsModelService;
@Autowired
private XjInspectionRoutesMapper xjInspectionRoutesMapper;
@Autowired
private XjInspectionRecordsMapper xjInspectionRecordsMapper;
@Autowired
private HaiWeiService haiWeiService;
@Autowired
private IUploadedPhotosService uploadedPhotosService;
@Autowired
private IDeviceLogService logService;
public DeviceDetailServiceImpl(DeviceMapper deviceMapper) {
this.deviceMapper = deviceMapper;
}
@ -48,15 +88,304 @@ public class DeviceDetailServiceImpl implements IDeviceDetailService {
}
@Override
public List<HashMap<String, Object>> gongdianChart(QueryLogVo queryLogVo) {
//todo
return Collections.emptyList();
public ArrayList<Object> gongdianChart(QueryLogVo queryLogVo) {
Long deviceId = queryLogVo.getDeviceId();
if (deviceId == null) {
throw new RuntimeException("请上传devicerId");
}
Device device = iDeviceService.selectDeviceByDeviceId(deviceId);
if (device == null) {
throw new RuntimeException("未查到该设备");
}
Map<String, Object> devParams = DevParamsUtils.getDevParams(device.getDevParams());
//太阳能设备
String taiyangnengIds = devParams.get("taiyangnIds").toString();
if (taiyangnengIds == null) {
return new ArrayList<>();
}
ArrayList<Object> deviceLogAllCurves = iDeviceService.getDeviceLogAllCurves(Long.parseLong(taiyangnengIds), queryLogVo.getStartTime(), queryLogVo.getEndTime());
return deviceLogAllCurves;
}
@Override
public List<Object> yongshuiChart(QueryLogVo queryLogVo) {
Long deviceId = queryLogVo.getDeviceId();
if (deviceId == null) {
throw new RuntimeException("请上传devicerId");
}
Device device = iDeviceService.selectDeviceByDeviceId(deviceId);
if (device == null) {
throw new RuntimeException("未查到该设备");
}
Map<String, Object> devParams = DevParamsUtils.getDevParams(device.getDevParams());
//太阳能设备
String liuliangIds = devParams.get("liuliangIds").toString();
if (liuliangIds == null) {
return new ArrayList<>();
}
ArrayList<Object> deviceLogAllCurves =
iDeviceService.getDeviceLogAllCurves(Long.parseLong(liuliangIds), queryLogVo.getStartTime(), queryLogVo.getEndTime());
return deviceLogAllCurves;
}
@Override
public List<XjInspectionRecords> xunjianRecord(QueryLogVo queryLogVo) {
//todo
return Collections.emptyList();
Long deviceId = queryLogVo.getDeviceId();
if (deviceId == null) {
throw new RuntimeException("请上传devicerId");
}
Device device = iDeviceService.selectDeviceByDeviceId(deviceId);
if (device == null) {
throw new RuntimeException("未查到该设备");
}
XjInspectionRoutes xjInspectionRoutes = new XjInspectionRoutes();
xjInspectionRoutes.setEngineeringObjectId(deviceId);
xjInspectionRoutes.setEngineeringObjectType("1");
List<XjInspectionRoutes> xjInspectionRoutes1 = xjInspectionRoutesMapper.selectXjInspectionRoutesList(xjInspectionRoutes);
if (xjInspectionRoutes1.size() > 0) {
List<XjInspectionRecords> xjInspectionRecordsList = new ArrayList<>();
XjInspectionRecords xjInspectionRecords = new XjInspectionRecords();
xjInspectionRecords.setInspectionRouteId(xjInspectionRoutes1.get(0).getId());
xjInspectionRecords.setChaxunBeginTime(queryLogVo.getStartTime());
xjInspectionRecords.setChaxunEndTime(queryLogVo.getEndTime());
xjInspectionRecordsList = xjInspectionRecordsMapper.selectXjInspectionRecordsList(xjInspectionRecords);
return xjInspectionRecordsList;
}
return new ArrayList<>();
}
@Override
public AnfangInfoVo anfangInfo(Long deviceId) {
//获取监控设备信息
Device device = iDeviceService.selectDeviceByDeviceId(deviceId);
if (device == null) {
throw new RuntimeException("未查到该设备");
}
AnfangInfoVo anfangInfoVo = new AnfangInfoVo();
//获取设备参数
Map<String, Object> devParams = DevParamsUtils.getDevParams(device.getDevParams());
//安防设备
String jiankongIds = devParams.get("jiankongIds").toString();
if (StringUtils.isNotEmpty(jiankongIds)) {
Device jiankongDevice = iDeviceService.selectDeviceByDeviceId(Long.parseLong(jiankongIds));
anfangInfoVo.setJiankongDevice(jiankongDevice);
}
//安防设备
String anfangIds = devParams.get("anfangIds").toString();
//获取设备安防状态
if (StringUtils.isNotEmpty(anfangIds)) {
Device anfangDevice = iDeviceService.selectDeviceByDeviceId(Long.parseLong(anfangIds));
//获取当前安防告警状态
UploadedPhotos uploadedPhotos = new UploadedPhotos();
uploadedPhotos.setSn(anfangDevice.getSerialNumber());
List<UploadedPhotos> uploadedPhotos1 = uploadedPhotosService.selectUploadedPhotosList(uploadedPhotos);
int doorStatus = 0;//0=正常1=箱门振动2=箱门打开
if (uploadedPhotos1.size() > 0) {
UploadedPhotos temp = uploadedPhotos1.get(0);
if (new Date().getTime() - temp.getUploadTime().getTime() < 36000000) {
if (temp.getShakeState().equals("1")) {
doorStatus = 1;
}
if (temp.getDoorState().equals("1")) {
doorStatus = 2;
}
}
}
if (uploadedPhotos1.size() > 5) {
uploadedPhotos1 = uploadedPhotos1.subList(0, 5);
}
anfangInfoVo.setDoorStatus(doorStatus);
anfangInfoVo.setAnfangList(uploadedPhotos1);
}
//安防设备
String guimenIds = devParams.get("guimenIds").toString();
if (StringUtils.isNotEmpty(guimenIds)) {
anfangInfoVo.setGuimenId(devParams.get("guimenIds").toString());
}
return anfangInfoVo;
}
@Override
public List<HashMap<Object, Object>> gongdianRealData(QueryLogVo queryLogVo) {
Long deviceId = queryLogVo.getDeviceId();
if (deviceId == null) {
throw new RuntimeException("请上传devicerId");
}
Device device = iDeviceService.selectDeviceByDeviceId(deviceId);
if (device == null) {
throw new RuntimeException("未查到该设备");
}
DateTime dateTime = DateUtil.date(new Date());
Map<String, Object> devParams = DevParamsUtils.getDevParams(device.getDevParams());
//太阳能设备
String taiyangnengIds = devParams.get("taiyangnIds").toString();
ThingsModel thingsModel1 = new ThingsModel();
thingsModel1.setProductId(138L);
List<ThingsModel> taiyangnengModels = thingsModelService.selectThingsModelList(thingsModel1);
taiyangnengModels.sort(Comparator.comparing(ThingsModel::getModelOrder));
List<HashMap<Object, Object>> list = new ArrayList<>();
if (StringUtils.isNotEmpty(taiyangnengIds)) {
Device taiyangnengDevice = deviceMapper.selectDeviceByDeviceId(Long.parseLong(taiyangnengIds));
List<DeviceLog> deviceLogs = logService.selectDeviceLogList(new DeviceLog() {{
setSerialNumber(taiyangnengDevice.getSerialNumber());
setBeginTime(DateUtil.beginOfDay(DateUtil.offsetDay(dateTime, -1)).toString());
setEndTime(DateUtil.endOfDay(dateTime).toString());
}});
Map<String, List<DeviceLog>> taiyangnengCollect = deviceLogs.stream().sorted(Comparator
.comparing(DeviceLog::getCreateTime, Comparator
.nullsFirst(Comparator.naturalOrder())).reversed()).collect(Collectors.groupingBy(t -> t.getIdentity()));
for (ThingsModel thingsModel : taiyangnengModels) {
HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
put("upType", 0);
put("identifier", thingsModel.getIdentifier());
put("unit", "");
put("value", 0);
put("name", thingsModel.getModelName());
}};
if (StringUtils.isNotEmpty(thingsModel.getSpecs())) {
String specs = thingsModel.getSpecs();
JSONObject parse = (JSONObject) JSON.parse(specs);
if (parse.containsKey("unit")) {
hashMap.put("unit", parse.get("unit"));
}
}
if (hashMap.size() > 1) {
List<DeviceLog> deviceLogs1 = taiyangnengCollect.get(thingsModel.getIdentifier());
if (deviceLogs1 != null) {
if (StringUtils.isNotEmpty(deviceLogs1.get(0).getLogValue())) {
if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) == Float.parseFloat(deviceLogs1.get(1).getLogValue())) {
hashMap.put("upType", 1);
} else if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) < Float.parseFloat(deviceLogs1.get(1).getLogValue())) {
hashMap.put("upType", -1);
}
hashMap.put("value", deviceLogs1.get(0).getLogValue());
} else {
hashMap.put("value", "--");
hashMap.put("upType", 0);
}
}
} else if (hashMap.size() > 0) {
List<DeviceLog> deviceLogs2 = taiyangnengCollect.get(thingsModel.getIdentifier());
if (deviceLogs2 != null) {
hashMap.put("value", deviceLogs2.get(0).getLogValue());
}
}
list.add(hashMap);
}
} else {
for (ThingsModel thingsModel : taiyangnengModels) {
HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
put("upType", 0);
put("identifier", thingsModel.getIdentifier());
put("unit", "");
put("value", 0);
put("name", thingsModel.getModelName());
}};
list.add(hashMap);
}
}
return list;
}
@Override
public List<HashMap<Object, Object>> yongshuiRealData(QueryLogVo queryLogVo) {
Long deviceId = queryLogVo.getDeviceId();
if (deviceId == null) {
throw new RuntimeException("请上传devicerId");
}
Device device = iDeviceService.selectDeviceByDeviceId(deviceId);
if (device == null) {
throw new RuntimeException("未查到该设备");
}
DateTime dateTime = DateUtil.date(new Date());
Map<String, Object> devParams = DevParamsUtils.getDevParams(device.getDevParams());
//太阳能设备
String liuliangIds = devParams.get("liuliangIds").toString();
ThingsModel thingsModel1 = new ThingsModel();
thingsModel1.setProductId(139L);
List<ThingsModel> liuliangModels = thingsModelService.selectThingsModelList(thingsModel1);
liuliangModels.sort(Comparator.comparing(ThingsModel::getModelOrder));
List<HashMap<Object, Object>> list = new ArrayList<>();
if (StringUtils.isNotEmpty(liuliangIds)) {
Device taiyangnengDevice = deviceMapper.selectDeviceByDeviceId(Long.parseLong(liuliangIds));
List<DeviceLog> deviceLogs = logService.selectDeviceLogList(new DeviceLog() {{
setSerialNumber(taiyangnengDevice.getSerialNumber());
setBeginTime(DateUtil.beginOfDay(DateUtil.offsetDay(dateTime, -1)).toString());
setEndTime(DateUtil.endOfDay(dateTime).toString());
}});
Map<String, List<DeviceLog>> taiyangnengCollect = deviceLogs.stream().sorted(Comparator
.comparing(DeviceLog::getCreateTime, Comparator
.nullsFirst(Comparator.naturalOrder())).reversed()).collect(Collectors.groupingBy(t -> t.getIdentity()));
for (ThingsModel thingsModel : liuliangModels) {
HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
put("upType", 0);
put("identifier", thingsModel.getIdentifier());
put("unit", "");
put("value", 0);
put("name", thingsModel.getModelName());
}};
if (StringUtils.isNotEmpty(thingsModel.getSpecs())) {
String specs = thingsModel.getSpecs();
JSONObject parse = (JSONObject) JSON.parse(specs);
if (parse.containsKey("unit")) {
hashMap.put("unit", parse.get("unit"));
}
}
if (hashMap.size() > 1) {
List<DeviceLog> deviceLogs1 = taiyangnengCollect.get(thingsModel.getIdentifier());
if (deviceLogs1 != null) {
if (StringUtils.isNotEmpty(deviceLogs1.get(0).getLogValue())) {
if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) == Float.parseFloat(deviceLogs1.get(1).getLogValue())) {
hashMap.put("upType", 1);
} else if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) < Float.parseFloat(deviceLogs1.get(1).getLogValue())) {
hashMap.put("upType", -1);
}
hashMap.put("value", deviceLogs1.get(0).getLogValue());
} else {
hashMap.put("value", "--");
hashMap.put("upType", 0);
}
}
} else if (hashMap.size() > 0) {
List<DeviceLog> deviceLogs2 = taiyangnengCollect.get(thingsModel.getIdentifier());
if (deviceLogs2 != null) {
hashMap.put("value", deviceLogs2.get(0).getLogValue());
}
}
list.add(hashMap);
}
} else {
for (ThingsModel thingsModel : liuliangModels) {
HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
put("upType", 0);
put("identifier", thingsModel.getIdentifier());
put("unit", "");
put("value", 0);
put("name", thingsModel.getModelName());
}};
list.add(hashMap);
}
}
return list;
}
@Override
public CommonResult<CmdHaiWeiVo> cmdDevices(CmdHaiWeiDto cmdHaiWeiDto) {
String url = "https://cloud.haiwell.com/api/project/machine/datagroup/setTagsValue";
Device deviceEntity = deviceMapper.selectDeviceByDeviceId(cmdHaiWeiDto.getDeviceId());
Map<String, Object> devParams1 = DevParamsUtils.getDevParams(deviceEntity.getDevParams());
String guimenIds = devParams1.get("guimenIds").toString();
if (StringUtils.isEmpty(guimenIds)) {
return null;
}
cmdHaiWeiDto.setDeviceId(Long.valueOf(guimenIds));
return haiWeiService.cmdDevices(cmdHaiWeiDto);
}

View File

@ -2,9 +2,11 @@ package com.fastbee.data.service.gis.impl;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.fastbee.common.core.page.TableDataInfo;
import com.fastbee.common.model.vo.TreeItemVo;
import com.fastbee.common.model.vo.iot.GisDeviceListVo;
import com.fastbee.common.utils.DateUtils;
@ -18,6 +20,8 @@ import com.fastbee.iot.domain.ThingsModel;
import com.fastbee.iot.mapper.DeviceMapper;
import com.fastbee.iot.mapper.ProductMapper;
import com.fastbee.iot.service.*;
import com.fastbee.waterele.domain.MaWatereleRecord;
import com.fastbee.waterele.service.IMaWatereleRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
@ -40,13 +44,17 @@ public class GisDeviceServiceImpl implements IGisDeviceService {
@Autowired
private IDeviceLogService logService;
// @Resource
// @Resource
// DeviceInfoCacheService deviceInfoCacheService;
@Autowired
private IAlertService iAlertService;
@Autowired
private IThingsModelService thingsModelService;
@Autowired
private IMaWatereleRecordService watereleRecordService;
public GisDeviceServiceImpl(@Qualifier("deviceMapper") DeviceMapper deviceMapper, @Qualifier("productMapper") ProductMapper productMapper) {
this.deviceMapper = deviceMapper;
this.productMapper = productMapper;
@ -54,7 +62,9 @@ public class GisDeviceServiceImpl implements IGisDeviceService {
@Override
public GisDeviceListVo totalAndList(Device device) {
List<Product> productEntities = productMapper.selectProductList(new Product());
Product product = new Product();
product.setProductId(136L);
List<Product> productEntities = productMapper.selectProductList(product);
Long userId = SecurityUtils.getUserId();
List<TreeItemVo> productContainDeviceListVos = new ArrayList<>();
int count = 0;
@ -81,8 +91,8 @@ public class GisDeviceServiceImpl implements IGisDeviceService {
devItem.setName(deviceEntity1.getDeviceName());
devItem.setId(deviceEntity1.getDeviceId());
devItem.setStatus(deviceEntity1.getStatus());
devItem.setLatitude(deviceEntity1.getLatitude() != null ?deviceEntity1.getLatitude().floatValue():null);
devItem.setLongitude(deviceEntity1.getLongitude()!= null ?deviceEntity1.getLongitude().floatValue():null);
devItem.setLatitude(deviceEntity1.getLatitude() != null ? deviceEntity1.getLatitude().floatValue() : null);
devItem.setLongitude(deviceEntity1.getLongitude() != null ? deviceEntity1.getLongitude().floatValue() : null);
treeItemVoList.add(devItem);
if (deviceEntity1.getStatus() == 3) {
onLineCount++;
@ -108,27 +118,25 @@ public class GisDeviceServiceImpl implements IGisDeviceService {
if (device == null) {
throw new RuntimeException("未查到该设备");
}
ThingsModel thingsModel1 = new ThingsModel();
thingsModel1.setProductId(device.getProductId());
List<ThingsModel> thingsModelEntities = thingsModelService.selectThingsModelList(thingsModel1);
// List<ThingsModelValueItem> thingsModelValueItems = deviceInfoCacheService.getDeviceInfoCache(device.getDeviceId());
// List<ThingsModelValueItem> thingsModelValueItems = deviceInfoCacheService.getCacheDeviceStatus(device.getProductId(),
// device.getSerialNumber());
DateTime dateTime = DateUtil.date(new Date());
List<DeviceLog> deviceLogsAll = new ArrayList<>();
Map<String, Object> devParams = getDevParams(device);
//太阳能设备
String taiyangnengIds = devParams.get("taiyangnIds").toString();
ThingsModel thingsModel1 = new ThingsModel();
thingsModel1.setProductId(138L);
List<ThingsModel> taiyangnengModels = thingsModelService.selectThingsModelList(thingsModel1);
taiyangnengModels.sort(Comparator.comparing(ThingsModel::getModelOrder));
if (StringUtils.isNotEmpty(taiyangnengIds)) {
Device taiyangnengDevice = deviceMapper.selectDeviceByDeviceId(Long.parseLong(taiyangnengIds));
List<DeviceLog> deviceLogs = logService.selectDeviceLogList(new DeviceLog() {{
setSerialNumber(device.getSerialNumber());
setSerialNumber(taiyangnengDevice.getSerialNumber());
setBeginTime(DateUtil.beginOfDay(DateUtil.offsetDay(dateTime, -1)).toString());
setEndTime(DateUtil.endOfDay(dateTime).toString());
}});
if (deviceLogs != null) {
deviceLogsAll.addAll(deviceLogs);
}
Map<String, List<DeviceLog>> collect = deviceLogsAll.stream().sorted(Comparator
Map<String, List<DeviceLog>> taiyangnengCollect = deviceLogs.stream().sorted(Comparator
.comparing(DeviceLog::getCreateTime, Comparator
.nullsFirst(Comparator.naturalOrder())).reversed()).collect(Collectors.groupingBy(t -> t.getIdentity()));
for (ThingsModel thingsModel : thingsModelEntities) {
for (ThingsModel thingsModel : taiyangnengModels) {
HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
put("upType", 0);
put("identifier", thingsModel.getIdentifier());
@ -136,34 +144,250 @@ public class GisDeviceServiceImpl implements IGisDeviceService {
put("value", 0);
put("name", thingsModel.getModelName());
}};
// {"max": 100, "min": 0, "step": 1, "type": "decimal", "unit": "m/s"}
if(StringUtils.isNotEmpty(thingsModel.getSpecs())){
if (StringUtils.isNotEmpty(thingsModel.getSpecs())) {
String specs = thingsModel.getSpecs();
JSONObject parse = (JSONObject) JSON.parse(specs);
if(parse.containsKey("unit")){
if (parse.containsKey("unit")) {
hashMap.put("unit", parse.get("unit"));
}
}
if (hashMap.size() > 1) {
List<DeviceLog> deviceLogs1 = collect.get(thingsModel.getIdentifier());
List<DeviceLog> deviceLogs1 = taiyangnengCollect.get(thingsModel.getIdentifier());
if (deviceLogs1 != null) {
if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) == Float.parseFloat(deviceLogs1.get(1).getLogValue()))
{
if(deviceLogs1.size() > 0){
if (StringUtils.isNotEmpty(deviceLogs1.get(0).getLogValue())) {
if(deviceLogs1.size() > 1){
if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) == Float.parseFloat(deviceLogs1.get(1).getLogValue())) {
hashMap.put("upType", 1);
} else if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) < Float.parseFloat(deviceLogs1.get(1).getLogValue())) {
hashMap.put("upType", -1);
}
}else{
hashMap.put("upType", 0);
}
hashMap.put("value", deviceLogs1.get(0).getLogValue());
} else {
hashMap.put("value", "--");
hashMap.put("upType", 0);
}
}else{
hashMap.put("value", "--");
hashMap.put("upType", 0);
}
}
} else if (hashMap.size() > 0) {
List<DeviceLog> deviceLogs2 = collect.get(thingsModel.getIdentifier());
List<DeviceLog> deviceLogs2 = taiyangnengCollect.get(thingsModel.getIdentifier());
if (deviceLogs2 != null) {
hashMap.put("value", deviceLogs2.get(0).getLogValue());
}
}
rMap.put(thingsModel.getIdentifier(), hashMap);
}
} else {
for (ThingsModel thingsModel : taiyangnengModels) {
HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
put("upType", 0);
put("identifier", thingsModel.getIdentifier());
put("unit", "");
put("value", 0);
put("name", thingsModel.getModelName());
}};
rMap.put(thingsModel.getIdentifier(), hashMap);
}
}
//箱门信息
String guimenIds = devParams.get("guimenIds").toString();
ThingsModel thingsModel3 = new ThingsModel();
thingsModel3.setProductId(140L);
List<ThingsModel> guimenModels = thingsModelService.selectThingsModelList(thingsModel3);
if (StringUtils.isNotEmpty(taiyangnengIds)) {
Device guimenDevice = deviceMapper.selectDeviceByDeviceId(Long.parseLong(guimenIds));
List<DeviceLog> deviceLogs = logService.selectDeviceLogList(new DeviceLog() {{
setSerialNumber(guimenDevice.getSerialNumber());
setBeginTime(DateUtil.beginOfDay(DateUtil.offsetDay(dateTime, -1)).toString());
setEndTime(DateUtil.endOfDay(dateTime).toString());
}});
Map<String, List<DeviceLog>> guimenCollect = deviceLogs.stream().sorted(Comparator
.comparing(DeviceLog::getCreateTime, Comparator
.nullsFirst(Comparator.naturalOrder())).reversed()).collect(Collectors.groupingBy(t -> t.getIdentity()));
for (ThingsModel thingsModel : guimenModels) {
HashMap<Object, Object> hashMap1 = new HashMap<Object, Object>() {{
put("upType", 0);
put("identifier", thingsModel.getIdentifier().equals("三菱FX2N_1_open")?"xiangmen":thingsModel.getIdentifier());
put("unit", "");
put("value", 0);
put("name", thingsModel.getModelName());
}};
if (StringUtils.isNotEmpty(thingsModel.getSpecs())) {
String specs = thingsModel.getSpecs();
JSONObject parse = (JSONObject) JSON.parse(specs);
if (parse.containsKey("unit")) {
hashMap1.put("unit", parse.get("unit"));
}
}
if (hashMap1.size() > 1) {
List<DeviceLog> deviceLogs1 = guimenCollect.get(thingsModel.getIdentifier());
if (deviceLogs1 != null) {
if(deviceLogs1.size() > 0){
if (StringUtils.isNotEmpty(deviceLogs1.get(0).getLogValue())) {
if(deviceLogs1.size() > 1){
if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) == Float.parseFloat(deviceLogs1.get(1).getLogValue())) {
hashMap1.put("upType", 1);
} else if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) < Float.parseFloat(deviceLogs1.get(1).getLogValue())) {
hashMap1.put("upType", -1);
}
}else{
hashMap1.put("upType", 0);
}
hashMap1.put("value", deviceLogs1.get(0).getLogValue());
} else {
hashMap1.put("value", "--");
hashMap1.put("upType", 0);
}
}else{
hashMap1.put("value", "--");
hashMap1.put("upType", 0);
}
}
} else if (hashMap1.size() > 0) {
List<DeviceLog> deviceLogs3 = guimenCollect.get(thingsModel.getIdentifier());
if (deviceLogs3 != null) {
hashMap1.put("value", deviceLogs3.get(0).getLogValue());
}
}
rMap.put(thingsModel.getIdentifier().equals("三菱FX2N_1_open")?"xiangmen":thingsModel.getIdentifier(), hashMap1);
}
} else {
for (ThingsModel thingsModel : taiyangnengModels) {
HashMap<Object, Object> hashMap1 = new HashMap<Object, Object>() {{
put("upType", 0);
put("identifier", thingsModel.getIdentifier().equals("三菱FX2N_1_open")?"xiangmen":thingsModel.getIdentifier());
put("unit", "");
put("value", 0);
put("name", thingsModel.getModelName());
}};
rMap.put(thingsModel.getIdentifier().equals("三菱FX2N_1_open")?"xiangmen":thingsModel.getIdentifier(), hashMap1);
}
}
// HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
// put("upType", 0);
// put("identifier", "xiangmen");
// put("unit", "");
// put("value", 0);//0=正常1=箱门振动2=箱门打开
// put("name", "箱门状态");
// }};
// rMap.put("xiangmen", hashMap);
String liuliangIds = devParams.get("liuliangIds").toString();
ThingsModel thingsModel2 = new ThingsModel();
thingsModel2.setProductId(139L);
List<ThingsModel> liuliangModels = thingsModelService.selectThingsModelList(thingsModel2);
if (StringUtils.isNotEmpty(taiyangnengIds)) {
Device liuliangDevice = deviceMapper.selectDeviceByDeviceId(Long.parseLong(liuliangIds));
List<DeviceLog> deviceLogs = logService.selectDeviceLogList(new DeviceLog() {{
setSerialNumber(liuliangDevice.getSerialNumber());
setBeginTime(DateUtil.beginOfDay(DateUtil.offsetDay(dateTime, -1)).toString());
setEndTime(DateUtil.endOfDay(dateTime).toString());
}});
Map<String, List<DeviceLog>> liuliangCollect = deviceLogs.stream().sorted(Comparator
.comparing(DeviceLog::getCreateTime, Comparator
.nullsFirst(Comparator.naturalOrder())).reversed()).collect(Collectors.groupingBy(t -> t.getIdentity()));
for (ThingsModel thingsModel : liuliangModels) {
HashMap<Object, Object> hashMap1 = new HashMap<Object, Object>() {{
put("upType", 0);
put("identifier", thingsModel.getIdentifier().equals("三菱FX2N_1_sumFlow")?"sumFlow":thingsModel.getIdentifier());
put("unit", "");
put("value", 0);
put("name", thingsModel.getModelName());
}};
if (StringUtils.isNotEmpty(thingsModel.getSpecs())) {
String specs = thingsModel.getSpecs();
JSONObject parse = (JSONObject) JSON.parse(specs);
if (parse.containsKey("unit")) {
hashMap1.put("unit", parse.get("unit"));
}
}
if (hashMap1.size() > 1) {
List<DeviceLog> deviceLogs1 = liuliangCollect.get(thingsModel.getIdentifier());
if (deviceLogs1 != null) {
if(deviceLogs1.size() > 0){
if (StringUtils.isNotEmpty(deviceLogs1.get(0).getLogValue())) {
if(deviceLogs1.size() > 1){
if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) == Float.parseFloat(deviceLogs1.get(1).getLogValue())) {
hashMap1.put("upType", 1);
} else if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) < Float.parseFloat(deviceLogs1.get(1).getLogValue())) {
hashMap1.put("upType", -1);
}
}else{
hashMap1.put("upType", 0);
}
hashMap1.put("value", deviceLogs1.get(0).getLogValue());
} else {
hashMap1.put("value", "--");
hashMap1.put("upType", 0);
}
}else{
hashMap1.put("value", "--");
hashMap1.put("upType", 0);
}
}
} else if (hashMap1.size() > 0) {
List<DeviceLog> deviceLogs2 = liuliangCollect.get(thingsModel.getIdentifier());
if (deviceLogs2 != null) {
hashMap1.put("value", deviceLogs2.get(0).getLogValue());
}
}
rMap.put(thingsModel.getIdentifier().equals("三菱FX2N_1_sumFlow")?"sumFlow":thingsModel.getIdentifier(), hashMap1);
}
} else {
for (ThingsModel thingsModel : taiyangnengModels) {
HashMap<Object, Object> hashMap1 = new HashMap<Object, Object>() {{
put("upType", 0);
put("identifier", thingsModel.getIdentifier().equals("三菱FX2N_1_sumFlow")?"sumFlow":thingsModel.getIdentifier());
put("unit", "");
put("value", 0);
put("name", thingsModel.getModelName());
}};
rMap.put(thingsModel.getIdentifier().equals("三菱FX2N_1_sumFlow")?"sumFlow":thingsModel.getIdentifier(), hashMap1);
}
}
// HashMap<Object, Object> hashMap1 = new HashMap<Object, Object>() {{
// put("upType", 0);
// put("identifier", "sumFlow");
// put("unit", "m³");
// put("value", 0);
// put("name", "累计用水量");
// }};
// rMap.put("sumFlow", hashMap1);
MaWatereleRecord maWatereleRecord = new MaWatereleRecord();
maWatereleRecord.setDevSn(device.getSerialNumber());
TableDataInfo tableDataInfo = watereleRecordService.selectMaWatereleRecordList(maWatereleRecord);
List<MaWatereleRecord> deviceLogs = (List<MaWatereleRecord>) tableDataInfo.getRows();
String sumEle = "0";
if(deviceLogs.size() > 0){
sumEle = NumberUtil.isNumber(deviceLogs.get(0).getSumele())?deviceLogs.get(0).getSumele():
"0";
}
String finalSumEle = sumEle;
HashMap<Object, Object> hashMap2 = new HashMap<Object, Object>() {{
put("upType", 0);
put("identifier", "sumEle");
put("unit", "kwh");
put("value", finalSumEle);
put("name", "累计用电量");
}};
rMap.put("sumEle", hashMap2);
return rMap;
}
@ -177,43 +401,30 @@ public class GisDeviceServiceImpl implements IGisDeviceService {
if (device == null) {
throw new RuntimeException("未查到该设备");
}
// List<AlertEntity> alertList = getAlertListForDevice(deviceId, device.getProductId());
// List<DeviceAlertDto> waterLevelAlert = new ArrayList<>();
// List<DeviceAlertDto> rainfallAlert = new ArrayList<>();
//
// if (!alertList.isEmpty()) {
// alertList.forEach(alert -> parseAlert(alert, waterLevelAlert, rainfallAlert));
// }
Map<String, Object> sumFlow = getDataList(device, "dataSumFlow");
Map<String, Object> insFlow = getDataList(device, "dataInsFlow");
//获取累计水量和累计电量的前20条数据记录
MaWatereleRecord watereleRecord = new MaWatereleRecord();
watereleRecord.setDevSn(device.getSerialNumber());
List<MaWatereleRecord> maWatereleRecords =
(List<MaWatereleRecord>) watereleRecordService.selectMaWatereleRecordList(watereleRecord).getRows();
if (maWatereleRecords.size() > 20) {
maWatereleRecords = maWatereleRecords.subList(0, 20);
}
maWatereleRecords.sort(Comparator.comparing(MaWatereleRecord::getCreateTime));
ArrayList<Object> sumFlow = new ArrayList<>();
ArrayList<Object> sumEle = new ArrayList<>();
ArrayList<Object> time = new ArrayList<>();
for (MaWatereleRecord record : maWatereleRecords) {
time.add(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, record.getCreateTime()));
sumFlow.add(record.getSumflow());
sumEle.add(record.getSumele());
}
Map<String, Object> rMap = new HashMap<>();
rMap.put("time", insFlow.get("time"));
rMap.put("sumFlow", sumFlow.get("data"));
rMap.put("insFlow", insFlow.get("data"));
// rMap.put("sumFlowAlert", waterLevelAlert);
// rMap.put("insFlowAlert", rainfallAlert);
rMap.put("time", time);
rMap.put("sumFlow", sumFlow);
rMap.put("sumEle", sumEle);
return rMap;
}
// private List<AlertEntity> getAlertListForDevice(Long deviceId, Long productId) {
// AlertEntity alert = new AlertEntity();
// alert.setDeviceId(deviceId);
// alert.setProductId(productId);
// return iAlertService.selectAlertList(alert);
// }
// private void parseAlert(AlertEntity alert, List<DeviceAlertDto> waterLevelAlert, List<DeviceAlertDto> rainfallAlert) {
// JSONArray triggers = JSON.parseArray(alert.getTriggers());
// for (Object obj : triggers) {
// Map<String, Object> trigger = (Map<String, Object>) obj;
// Float value = Float.valueOf(trigger.get("value").toString());
// if (alert.getAlertType() == 1) {
// waterLevelAlert.add(new DeviceAlertDto(alert.getAlertName(), "#FF0000", value));
// } else if (alert.getAlertType() == 2) {
// rainfallAlert.add(new DeviceAlertDto(alert.getAlertName(), "#FFFF00", value));
// }
// }
// }
private HashMap<String, Object> getDataList(Device device, String identity) {
HashMap<String, Object> dataListMap = new HashMap<>();
@ -221,11 +432,11 @@ public class GisDeviceServiceImpl implements IGisDeviceService {
kvHashMap.put("identity", identity);
kvHashMap.put("serialNumber", device.getSerialNumber());
Date endTime = new Date();
kvHashMap.put("endTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,endTime));
kvHashMap.put("endTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime));
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.HOUR,-23);
kvHashMap.put("beginTime",DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH,calendar.getTime())+":00:00");
calendar.add(Calendar.HOUR, -23);
kvHashMap.put("beginTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH, calendar.getTime()) + ":00:00");
List<HashMap<String, Object>> reMap = logService.selectDayData(kvHashMap);
Map<String, Map<String, Object>> create_time = new HashMap<>();
if (reMap != null) {
@ -243,10 +454,10 @@ public class GisDeviceServiceImpl implements IGisDeviceService {
time.add(s);
Map<String, Object> map = create_time.get(s);
if (map != null) {
if(identity.equals("dataSumFlow")){
if (identity.equals("dataSumFlow")) {
jiangyvliang.add(Float.parseFloat(create_time.get(s).get("maxLogValue").toString())
- Float.parseFloat(create_time.get(s).get("minLogValue").toString()));
}else{
} else {
jiangyvliang.add(create_time.get(s).get("avgLogValue"));
}
} else {
@ -257,4 +468,20 @@ public class GisDeviceServiceImpl implements IGisDeviceService {
}
public Map<String, Object> getDevParams(Device device) {
Map<String, Object> devData = new HashMap<>();
try {
Object devParams = com.alibaba.fastjson.JSON.parse(device.getDevParams()); //先转换成Object
List<Map<String, Object>> Params = (List<Map<String, Object>>) devParams;
if (Params != null) {
for (Map<String, Object> param : Params) {
devData.put(param.get("key").toString(), param.get("value").toString());
}
}
} catch (Exception exception) {
}
return devData;
}
}

View File

@ -76,11 +76,7 @@
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.73</version>
</dependency>
<!--在线文档 -->
<dependency>

View File

@ -156,6 +156,10 @@
<artifactId>forest-spring-boot-starter</artifactId>
<version>1.5.36</version>
</dependency>
<dependency>
<groupId>com.fastbee</groupId>
<artifactId>fastbee-waterele-service</artifactId>
</dependency>
</dependencies>

View File

@ -1,95 +0,0 @@
package com.fastbee.iot.anfang.service.impl;
import com.fastbee.iot.anfang.service.IUploadedPhotosService;
import com.fastbee.iot.mapper.UploadedPhotosMapper;
import com.fastbee.iot.model.anfang.UploadedPhotos;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* 存储上传的照片信息Service业务层处理
*
* @author kerwincui
* @date 2024-06-20
*/
@Service
public class UploadedPhotosServiceImpl implements IUploadedPhotosService
{
@Resource
private UploadedPhotosMapper uploadedPhotosMapper;
/**
* 查询存储上传的照片信息
*
* @param id 存储上传的照片信息主键
* @return 存储上传的照片信息
*/
@Override
public UploadedPhotos selectUploadedPhotosById(Long id)
{
return uploadedPhotosMapper.selectUploadedPhotosById(id);
}
/**
* 查询存储上传的照片信息列表
*
* @param uploadedPhotos 存储上传的照片信息
* @return 存储上传的照片信息
*/
@Override
public List<UploadedPhotos> selectUploadedPhotosList(UploadedPhotos uploadedPhotos)
{
return uploadedPhotosMapper.selectUploadedPhotosList(uploadedPhotos);
}
/**
* 新增存储上传的照片信息
*
* @param uploadedPhotos 存储上传的照片信息
* @return 结果
*/
@Override
public int insertUploadedPhotos(UploadedPhotos uploadedPhotos)
{
return uploadedPhotosMapper.insertUploadedPhotos(uploadedPhotos);
}
/**
* 修改存储上传的照片信息
*
* @param uploadedPhotos 存储上传的照片信息
* @return 结果
*/
@Override
public int updateUploadedPhotos(UploadedPhotos uploadedPhotos)
{
return uploadedPhotosMapper.updateUploadedPhotos(uploadedPhotos);
}
/**
* 批量删除存储上传的照片信息
*
* @param ids 需要删除的存储上传的照片信息主键
* @return 结果
*/
@Override
public int deleteUploadedPhotosByIds(Long[] ids)
{
return uploadedPhotosMapper.deleteUploadedPhotosByIds(ids);
}
/**
* 删除存储上传的照片信息信息
*
* @param id 存储上传的照片信息主键
* @return 结果
*/
@Override
public int deleteUploadedPhotosById(Long id)
{
return uploadedPhotosMapper.deleteUploadedPhotosById(id);
}
}

View File

@ -178,6 +178,12 @@ public class Device extends BaseEntity
@ApiModelProperty("设备参数")
private String devParams;
@ApiModelProperty("管护人")
private String caretaker;
@ApiModelProperty("管护单位")
private String managementUnit;
@ApiModelProperty("联系电话")
private String tel;
/**
* 关联组态,来源产品

View File

@ -0,0 +1,50 @@
package com.fastbee.iot.domain;
import lombok.Data;
/**
* 设备参数设置对象 device_param_config
*
* @author mafa
* @date 2023-08-22
*/
@Data
public class JiankongDeviceParam
{
private static final long serialVersionUID = 1L;
/** 设备id */
private Long deviceId;
/** ezopen协议地址的本地录像/云存储录像回放开始时间,示例2019-12-01 00:00:00 */
private String startTime;
/** ezopen协议地址的本地录像/云存储录像回放开始时间,示例2019-12-01 00:00:00 */
private String stopTime;
/** ezopen协议地址的类型1-预览2-本地录像回放3-云存储录像回放非必选默认为1 */
private String type;
/** ezopen协议地址的设备的视频加密密码 */
private String code;
/** 流播放协议1-ezopen、2-hls、3-rtmp、4-flv默认为1 */
private String protocol;
/** 视频清晰度1-高清主码流、2-流畅(子码流) */
private String quality;
/** 云台操作命令0-上1-下2-左3-右4-左上5-左下6-右上7-右下8-放大9-缩小10-近焦距11-远焦距 */
private String direction;
/** 云台操作命令:速度 */
private String speed;
/** 云台操作命令:传了一直动 不传移动一格 */
private String notStop;
}

View File

@ -0,0 +1,132 @@
package com.fastbee.iot.haikang;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
/**
* 点点控api界面
*/
public class HaikangYingshiApi {
/**
* @return
*/
public static JSONObject getToken(Map<String, Object> params) {
String url = UrlConstant.getToken;//指定URL
HashMap<String, String> headers = new HashMap<>();//存放请求头,可以存放多个请求头
headers.put("Content-Type", "application/x-www-form-urlencoded");
String result = HttpUtil.createPost(url).addHeaders(headers).form(params).execute().body();
JSONObject jsonObject = new JSONObject(result);
// System.out.println("jsonObject = " + jsonObject);
// Map<String,Object> data =null;
// if (jsonObject.get("code").equals("200")) {
// data= (Map<String,Object>) jsonObject.get("data");
// }
return jsonObject;
}
/**
* @param params accessToken String 授权过程获取的access_token Y
* deviceSerial String 直播源例如427734222均采用英文符号限制50个 Y
* channelNo Integer 通道号,非必选默认为1 N
* code String ezopen协议地址的设备的视频加密密码 N
* expireTime Integer 过期时长单位秒针对hls/rtmp设置有效期相对时间30秒-720天 N
* protocol Integer 流播放协议1-ezopen、2-hls、3-rtmp、4-flv默认为1 N
* quality Integer 视频清晰度1-高清主码流、2-流畅(子码流) N
* startTime String ezopen协议地址的本地录像/云存储录像回放开始时间,示例2019-12-01 00:00:00 N
* stopTime String ezopen协议地址的本地录像/云存储录像回放开始时间,示例2019-12-01 00:00:00 N
* type String ezopen协议地址的类型1-预览2-本地录像回放3-云存储录像回放非必选默认为1 N
* supportH265 Integer 是否要求播放视频为H265编码格式,1表示需要0表示不要求 N
* gbchannel String 国标设备的通道编号视频通道编号ID N
* @return
*/
public static JSONObject getAddress(Map<String, Object> params) {
// accessToken=at.dunwhxt2azk02hcn7phqygsybbw0wv6p&deviceSerial=C78957921&channelNo=1
String url = UrlConstant.address;//指定URL
HashMap<String, String> headers = new HashMap<>();//存放请求头,可以存放多个请求头
headers.put("Content-Type", "application/x-www-form-urlencoded");
String result = HttpUtil.createPost(url).addHeaders(headers).form(params).execute().body();
JSONObject jsonObject = new JSONObject(result);
// System.out.println("result = " + result);
// Map<String,Object> data =(Map<String,Object>) jsonObject.get("data");
return jsonObject;
}
/**
* @param params accessToken String 授权过程获取的access_token Y
* deviceSerial String 设备序列号,存在英文字母的设备序列号,字母需为大写 Y
* channelNo int 通道号 Y
* direction int 操作命令0-上1-下2-左3-右4-左上5-左下6-右上7-右下8-放大9-缩小10-近焦距11-远焦距 Y
* speed int 云台速度0-慢1-适中2-快海康设备参数不可为0
* @return
*/
public static JSONObject startMove(Map<String, Object> params) {
// accessToken=at.dunwhxt2azk02hcn7phqygsybbw0wv6p&deviceSerial=C78957921&channelNo=1
String url = UrlConstant.startyuntai;//指定URL
HashMap<String, String> headers = new HashMap<>();//存放请求头,可以存放多个请求头
headers.put("Content-Type", "application/x-www-form-urlencoded");
String result = HttpUtil.createPost(url).addHeaders(headers).form(params).execute().body();
JSONObject jsonObject = new JSONObject(result);
return jsonObject;
}
/**
* @param params accessToken String 授权过程获取的access_token Y
* deviceSerial String 设备序列号,存在英文字母的设备序列号,字母需为大写 Y
* channelNo int 通道号 Y
* direction int 操作命令0-上1-下2-左3-右4-左上5-左下6-右上7-右下8-放大9-缩小10-近焦距11-远焦距 Y
* @return
*/
public static JSONObject stopMove(Map<String, Object> params) {
// accessToken=at.dunwhxt2azk02hcn7phqygsybbw0wv6p&deviceSerial=C78957921&channelNo=1
String url = UrlConstant.stopyuntai;//指定URL
HashMap<String, String> headers = new HashMap<>();//存放请求头,可以存放多个请求头
headers.put("Content-Type", "application/x-www-form-urlencoded");
String result = HttpUtil.createPost(url).addHeaders(headers).form(params).execute().body();
JSONObject jsonObject = new JSONObject(result);
return jsonObject;
}
/**
* @param params accessToken String 授权过程获取的access_token Y
* deviceSerial String 设备序列号,存在英文字母的设备序列号,字母需为大写 Y
* channelNo int 通道号 Y
* direction int 操作命令0-上1-下2-左3-右4-左上5-左下6-右上7-右下8-放大9-缩小10-近焦距11-远焦距 Y
* @return
*/
public static JSONObject getDeviceInfo(Map<String, Object> params) {
// accessToken=at.dunwhxt2azk02hcn7phqygsybbw0wv6p&deviceSerial=C78957921&channelNo=1
String url = UrlConstant.deviceInfo;//指定URL
HashMap<String, String> headers = new HashMap<>();//存放请求头,可以存放多个请求头
headers.put("Content-Type", "application/x-www-form-urlencoded");
String result = HttpUtil.createPost(url).addHeaders(headers).form(params).execute().body();
JSONObject jsonObject = new JSONObject(result);
return jsonObject;
}
/**
* @param params accessToken String 授权过程获取的access_token Y
* deviceSerial String 直播源例如427734222均采用英文符号限制50个 Y
* channelNo Integer 通道号,非必选默认为1 N
* @return
*/
public static JSONObject capture(Map<String, Object> params) {
// accessToken=at.dunwhxt2azk02hcn7phqygsybbw0wv6p&deviceSerial=C78957921&channelNo=1
String url = UrlConstant.capture;//指定URL
HashMap<String, String> headers = new HashMap<>();//存放请求头,可以存放多个请求头
headers.put("Content-Type", "application/x-www-form-urlencoded");
String result = HttpUtil.createPost(url).addHeaders(headers).form(params).execute().body();
JSONObject jsonObject = new JSONObject(result);
// System.out.println("result = " + result);
// Map<String,Object> data =(Map<String,Object>) jsonObject.get("data");
return jsonObject;
}
}

View File

@ -0,0 +1,28 @@
package com.fastbee.iot.haikang;
/**
* 点点控
*/
public class UrlConstant {
public static String appKey = "be85054cf4504710861fad77ec4e4af9";
public static String appSecret = "104f39e29f9847e5d819a99c1c32fc88";
//获取 token
public static String getToken = "https://open.ys7.com/api/lapp/token/get";
//获取 直播地址
public static String address = "https://open.ys7.com/api/lapp/v2/live/address/get";
//开始云台
public static String startyuntai = "https://open.ys7.com/api/lapp/device/ptz/start";
//停止云台
public static String stopyuntai = "https://open.ys7.com/api/lapp/device/ptz/stop";
//设备信息
public static String deviceInfo = "https://open.ys7.com/api/lapp/device/info";
//设备抓拍图片
public static String capture = "https://open.ys7.com/api/lapp/device/capture";
//关闭设备视频加密
public static String deviceEncryptOff = "https://open.ys7.com/api/lapp/device/encrypt/off";
}

View File

@ -1,6 +1,7 @@
package com.fastbee.iot.model;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import java.math.BigDecimal;
import java.util.Date;
@ -66,6 +67,12 @@ public class DeviceAllShortOutput
private Integer isOwner;
private Integer subDeviceCount;
@ApiModelProperty("管护人")
private String caretaker;
@ApiModelProperty("管护单位")
private String managementUnit;
@ApiModelProperty("联系电话")
private String tel;
public Integer getSubDeviceCount() {
return subDeviceCount;

View File

@ -94,6 +94,13 @@ public class DeviceShortOutput
@Excel(name = "网关设备编号(子设备使用)")
private String gwDevCode;
@ApiModelProperty("管护人")
private String caretaker;
@ApiModelProperty("管护单位")
private String managementUnit;
@ApiModelProperty("联系电话")
private String tel;
/** 是否自定义位置 **/
private Integer locationWay;

View File

@ -28,7 +28,9 @@ public class UploadedPhotos extends BaseEntity
/** 照片存储路径 */
@Excel(name = "照片存储路径")
private String photoPath;
/** 监控抓拍 */
@Excel(name = "监控抓拍")
private String monitorPath;
/** 设备IMEI号 */
@Excel(name = "设备IMEI号")
private String imei;

View File

@ -6,6 +6,7 @@ import com.fastbee.common.core.thingsModel.ThingsModelSimpleItem;
import com.fastbee.common.enums.DeviceStatus;
import com.fastbee.iot.domain.Device;
import com.fastbee.iot.domain.DeviceGroup;
import com.fastbee.iot.domain.JiankongDeviceParam;
import com.fastbee.iot.model.*;
import com.fastbee.iot.model.ThingsModels.ThingsModelShadow;
import com.fastbee.iot.model.ThingsModels.ThingsModelValueItem;
@ -334,5 +335,5 @@ public interface IDeviceService
ArrayList<Object> getDeviceLogAllCurves(Long deviceId, String beginTime, String endTime);
Map<String, Object> getvideourl(JiankongDeviceParam jiankongDeviceParam);
}

View File

@ -10,21 +10,20 @@ import com.fastbee.common.core.domain.AjaxResult;
import com.fastbee.common.core.domain.entity.SysDept;
import com.fastbee.common.core.domain.entity.SysUser;
import com.fastbee.common.core.domain.model.LoginUser;
import com.fastbee.common.core.page.TableDataInfo;
import com.fastbee.common.core.redis.RedisCache;
import com.fastbee.common.core.redis.RedisKeyBuilder;
import com.fastbee.common.core.thingsModel.ThingsModelSimpleItem;
import com.fastbee.common.core.thingsModel.ThingsModelValuesInput;
import com.fastbee.common.enums.*;
import com.fastbee.common.exception.ServiceException;
import com.fastbee.common.utils.CaculateUtils;
import com.fastbee.common.utils.DateUtils;
import com.fastbee.common.utils.SecurityUtils;
import com.fastbee.common.utils.StringUtils;
import com.fastbee.common.utils.*;
import com.fastbee.common.utils.http.HttpUtils;
import com.fastbee.common.utils.ip.IpUtils;
import com.fastbee.common.utils.json.JsonUtils;
import com.fastbee.iot.cache.ITSLCache;
import com.fastbee.iot.domain.*;
import com.fastbee.iot.haikang.HaikangYingshiApi;
import com.fastbee.iot.mapper.*;
import com.fastbee.iot.model.*;
import com.fastbee.iot.model.ThingsModelItem.Datatype;
@ -39,6 +38,8 @@ import com.fastbee.iot.cache.ITSLValueCache;
import com.fastbee.iot.tdengine.service.ILogService;
import com.fastbee.system.mapper.SysDeptMapper;
import com.fastbee.system.service.ISysUserService;
import com.fastbee.waterele.domain.MaWatereleRecord;
import com.fastbee.waterele.service.IMaWatereleRecordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
@ -123,7 +124,8 @@ public class DeviceServiceImpl implements IDeviceService {
private SubGatewayMapper subGatewayMapper;
@Resource
private IOrderControlService orderControlService;
@Resource
private IMaWatereleRecordService watereleRecordService;
/**
* 查询设备
@ -135,6 +137,9 @@ public class DeviceServiceImpl implements IDeviceService {
@Override
public Device selectDeviceByDeviceId(Long deviceId) {
Device device = deviceMapper.selectDeviceByDeviceId(deviceId);
if (device == null) {
return null;
}
List<ValueItem> list = itslValueCache.getCacheDeviceStatus(device.getProductId(), device.getSerialNumber());
if (list != null && list.size() > 0) {
// redis中获取设备状态物模型值
@ -1600,13 +1605,24 @@ public class DeviceServiceImpl implements IDeviceService {
@Override
public List<Map<String, Object>> devicePointInfo(Device devices) {
ArrayList<Map<String, Object>> resultList = new ArrayList<>();
devices.setProductId(136L);
List<Device> deviceList = selectDeviceList(devices);
for (Device device : deviceList) {
// MaWatereleRecord maWatereleRecord = new MaWatereleRecord();
// maWatereleRecord.setDevSn(device.getSerialNumber());
// TableDataInfo tableDataInfo = watereleRecordService.selectMaWatereleRecordList(maWatereleRecord);
// List<MaWatereleRecord> list = (List<MaWatereleRecord>) tableDataInfo.getRows();
// int status = 4;
// if(list.size() > 0){
// MaWatereleRecord record = list.get(0);
// if(new Date().getTime() - record.getCreateTime().getTime() < 3600000){
// status = 3;
// }
// }
// device.setStatus(status);
HashMap<String, Object> itemMap = new HashMap<>();
resultList.add(itemMap);
Integer integer = 0;
itemMap.put("device",device);
if (device.getStatus() != null) {
if (device.getStatus().equals(4)) {
@ -1614,7 +1630,6 @@ public class DeviceServiceImpl implements IDeviceService {
}
}
itemMap.put("online",integer);
}
return resultList;
}
@ -1636,12 +1651,17 @@ public class DeviceServiceImpl implements IDeviceService {
kvHashMap.put("beginTime", beginTime);
kvHashMap.put("endTime", endTime);
List<ThingsModel> thingsModels = thingsModelService.selectThingsModelList(new ThingsModel(device.getProductId()));
thingsModels.sort(Comparator.comparing(ThingsModel::getModelOrder));
List<DeviceLog> deviceLogs= logService.selectDataList(kvHashMap);
Map<String, List<DeviceLog>> collect = deviceLogs != null ? deviceLogs.stream().collect(Collectors.groupingBy(t -> t.getIdentity())): new HashMap();
for (ThingsModel modelDevice : thingsModels) {
if(modelDevice.getIsChart().equals(0)){
continue;
}
HashMap<String, Object> dataListMap = new HashMap<>();
List<DeviceLog> deviceLogs1 = collect.get(modelDevice.getIdentifier());
deviceLogs1.sort(Comparator.comparing(DeviceLog::getCreateTime));
dataListMap.put("name", modelDevice.getModelName());
if (StringUtils.isNotEmpty(modelDevice.getSpecs())) {
cn.hutool.json.JSONObject object = new cn.hutool.json.JSONObject(modelDevice.getSpecs());
@ -1651,7 +1671,7 @@ public class DeviceServiceImpl implements IDeviceService {
}
if (deviceLogs1 != null) {
System.out.println(deviceLogs1);
dataListMap.put("time",deviceLogs1.stream().map(t->t.getCreateTime()).collect(Collectors.toList()));
dataListMap.put("time",deviceLogs1.stream().map(t->DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,t.getCreateTime())).collect(Collectors.toList()));
dataListMap.put("data",deviceLogs1.stream().map(t->t.getLogValue()).collect(Collectors.toList()));
}else{
dataListMap.put("time",new ArrayList<>());
@ -1663,4 +1683,76 @@ public class DeviceServiceImpl implements IDeviceService {
}
@Override
public Map<String, Object> getvideourl(JiankongDeviceParam jiankongDeviceParam) {
if (jiankongDeviceParam.getDeviceId() == null) {
throw new RuntimeException("请上传设备id");
}
Device device = selectDeviceByDeviceId(jiankongDeviceParam.getDeviceId());
if (device == null) {
throw new RuntimeException("设备未找到");
}
Map devData = DevParamsUtils.getDevParams(device.getDevParams());
if (devData.get("appKey") == null) {
throw new RuntimeException("未绑定设备参数appKey");
}
if (devData.get("appSecret") == null) {
throw new RuntimeException("未绑定设备参数appSecret");
}
if (devData.get("channelNo") == null) {
throw new RuntimeException("未绑定设备参数channelNo");
}
Map<String, Object> map = new HashMap<>();//存放参数
map.put("appKey", devData.get("appKey"));
map.put("appSecret", devData.get("appSecret"));
cn.hutool.json.JSONObject token = HaikangYingshiApi.getToken(map);
if (token != null && token.get("code").equals("200")) {
Map<String, Object> params = new HashMap<>();
// accessToken=at.dunwhxt2azk02hcn7phqygsybbw0wv6p&deviceSerial=C78957921&channelNo=1
token = (cn.hutool.json.JSONObject) token.get("data");
params.put("accessToken", token.get("accessToken"));
params.put("deviceSerial", device.getSerialNumber());
if (StringUtils.isNotEmpty(jiankongDeviceParam.getStartTime())) {
params.put("startTime", jiankongDeviceParam.getStartTime());
}
if (StringUtils.isNotEmpty(jiankongDeviceParam.getStopTime())) {
params.put("stopTime", jiankongDeviceParam.getStopTime());
}
if (StringUtils.isNotEmpty(jiankongDeviceParam.getType())) {
params.put("type", jiankongDeviceParam.getType());
}
if (StringUtils.isNotEmpty(jiankongDeviceParam.getCode())) {
params.put("code", jiankongDeviceParam.getCode());
}
if (StringUtils.isNotEmpty(jiankongDeviceParam.getProtocol())) {
params.put("protocol", jiankongDeviceParam.getProtocol());
}
if (StringUtils.isNotEmpty(jiankongDeviceParam.getQuality())) {
params.put("quality", jiankongDeviceParam.getQuality());
}
cn.hutool.json.JSONObject response = HaikangYingshiApi.getAddress(params);
if (response != null && response.get("code").equals("200")) {
Map data = (cn.hutool.json.JSONObject) response.get("data");
Map<String, Object> reMap = new HashMap<>();
reMap.put("url", data.get("url"));
reMap.put("devName", device.getDeviceName());
reMap.put("accessToken", token.get("accessToken"));
reMap.put("id", device.getDeviceId());
reMap.put("status", device.getStatus() == null || device.getStatus() == 4 ? "离线" : "在线");
return reMap;
} else {
throw new RuntimeException(response.get("msg").toString());
}
} else {
}
return null;
}
}

View File

@ -88,7 +88,7 @@ public class ThingsModelServiceImpl implements IThingsModelService {
*/
@Override
public ThingsModel selectSingleThingsModel(ThingsModel model) {
model.setLanguage(SecurityUtils.getLanguage());
// model.setLanguage(SecurityUtils.getLanguage());
return thingsModelMapper.selectSingleThingsModel(model);
}

View File

@ -151,32 +151,36 @@ public class MySqlLogServiceImpl implements ILogService {
@Override
public List<DeviceLog> selectDataList(HashMap<String, Object> kvHashMap) {
if (kvHashMap.get("endTime") != null) {
DateTime endTime = DateUtil.parse(kvHashMap.get("endTime").toString());
String yyyyMM = endTime.toString("yyyyMM");
String yyyyMM2 = DateUtil.offsetMonth(endTime, -1).toString("yyyyMM");
if (tableMapper.getTableByName(tableName + yyyyMM) == null) {
deviceLogMapper.createTableByDate(tableName + yyyyMM);
}
if (tableMapper.getTableByName(tableName + yyyyMM2) == null) {
deviceLogMapper.createTableByDate(tableName + yyyyMM2);
}
kvHashMap.put("tableName", tableName + yyyyMM);
kvHashMap.put("tableName2", tableName + yyyyMM2);
}
if (kvHashMap.get("tableName") == null) {
Date date = new Date();
String ym = DateUtils.parseDateToStr(DateUtils.YYYYMM, date);
String ym2 = DateUtils.parseDateToStr(DateUtils.YYYYMM, DateUtil.offsetMonth(new Date(), -1));
if (tableMapper.getTableByName(tableName + ym) == null) {
deviceLogMapper.createTableByDate(tableName + ym);
}
if (tableMapper.getTableByName(tableName + ym2) == null) {
deviceLogMapper.createTableByDate(tableName + ym2);
}
kvHashMap.put("tableName", tableName + ym);
kvHashMap.put("tableName2", tableName + ym2);
}
return deviceLogMapper.selectDataList(kvHashMap);
DeviceLog deviceLog = new DeviceLog();
deviceLog.setBeginTime(kvHashMap.get("beginTime").toString());
deviceLog.setEndTime(kvHashMap.get("endTime").toString());
deviceLog.setSerialNumber((kvHashMap.get("serialNumber").toString()));
// if (kvHashMap.get("endTime") != null) {
// DateTime endTime = DateUtil.parse(kvHashMap.get("endTime").toString());
// String yyyyMM = endTime.toString("yyyyMM");
// String yyyyMM2 = DateUtil.offsetMonth(endTime, -1).toString("yyyyMM");
// if (tableMapper.getTableByName(tableName + yyyyMM) == null) {
// deviceLogMapper.createTableByDate(tableName + yyyyMM);
// }
// if (tableMapper.getTableByName(tableName + yyyyMM2) == null) {
// deviceLogMapper.createTableByDate(tableName + yyyyMM2);
// }
// kvHashMap.put("tableName", tableName + yyyyMM);
// kvHashMap.put("tableName2", tableName + yyyyMM2);
// }
// if (kvHashMap.get("tableName") == null) {
// Date date = new Date();
// String ym = DateUtils.parseDateToStr(DateUtils.YYYYMM, date);
// String ym2 = DateUtils.parseDateToStr(DateUtils.YYYYMM, DateUtil.offsetMonth(new Date(), -1));
// if (tableMapper.getTableByName(tableName + ym) == null) {
// deviceLogMapper.createTableByDate(tableName + ym);
// }
// if (tableMapper.getTableByName(tableName + ym2) == null) {
// deviceLogMapper.createTableByDate(tableName + ym2);
// }
// kvHashMap.put("tableName", tableName + ym);
// kvHashMap.put("tableName2", tableName + ym2);
// }
return deviceLogMapper.selectDeviceLogList(deviceLog);
}
}

View File

@ -1,5 +1,6 @@
package com.fastbee.iot.timer;//package com.fastbee.farming;
import com.fastbee.common.core.page.TableDataInfo;
import com.fastbee.common.core.redis.RedisCache;
import com.fastbee.common.core.redis.RedisKeyBuilder;
import com.fastbee.common.utils.DateUtils;
@ -17,6 +18,8 @@ import com.fastbee.iot.model.haiwei.HaiWeiPropertyVo;
import com.fastbee.iot.service.IDeviceService;
import com.fastbee.iot.tdengine.service.ILogService;
import com.fastbee.iot.tdengine.service.model.TdLogDto;
import com.fastbee.waterele.domain.MaWatereleRecord;
import com.fastbee.waterele.service.IMaWatereleRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -43,7 +46,8 @@ public class QxtrTask {
private ILogService iLogService;
@Resource
RedisCache redisCache;
@Resource
private IMaWatereleRecordService watereleRecordService;
private static Pattern pattern = Pattern.compile("[-+]?[0-9]+(\\.[0-9]+)?$");
/**
@ -57,6 +61,33 @@ public class QxtrTask {
getDeviceInfo(Long.valueOf(SOLAR_DEVICE.getType()), devices);
}
/**
* 定时任务 更新设备在线状态
*/
public void updateDeviceStatus() throws Exception {
log.info("定时任务,更新设备在线状态");
Device device = new Device();
ArrayList<Map<String, Object>> resultList = new ArrayList<>();
device.setProductId(136L);
List<Device> deviceList = iDeviceService.selectDeviceList(device);
for (Device item : deviceList) {
MaWatereleRecord maWatereleRecord = new MaWatereleRecord();
maWatereleRecord.setDevSn(item.getSerialNumber());
List<MaWatereleRecord> list = watereleRecordService.getList(maWatereleRecord);
int status = 4;
if(list.size() > 0){
MaWatereleRecord record = list.get(0);
if(new Date().getTime() - record.getCreateTime().getTime() < 3600000){
status = 3;
}
}
item.setStatus(status);
iDeviceService.updateDevice(item);
}
}
/**
* 定时任务 流量计设备
*/

View File

@ -36,6 +36,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="transport" column="transport" />
<result property="guid" column="guid" />
<result property="devParams" column="dev_params" />
<result property="tel" column="tel" />
<result property="caretaker" column="caretaker" />
<result property="managementUnit" column="management_unit" />
</resultMap>
<resultMap type="com.fastbee.iot.model.DeviceShortOutput" id="DeviceShortResult">
@ -65,6 +68,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="transport" column="transport" />
<result property="guid" column="guid" />
<result property="devParams" column="dev_params" />
<result property="tel" column="tel" />
<result property="caretaker" column="caretaker" />
<result property="managementUnit" column="management_unit" />
</resultMap>
<resultMap type="com.fastbee.iot.model.DeviceAllShortOutput" id="DeviceAllShortResult">
@ -86,6 +92,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="isOwner" column="is_owner" />
<result property="subDeviceCount" column="sub_device_count"/>
<result property="devParams" column="dev_params" />
<result property="tel" column="tel" />
<result property="caretaker" column="caretaker" />
<result property="managementUnit" column="management_unit" />
</resultMap>
<resultMap type="com.fastbee.iot.model.UserAndTenant" id="UserAndTenantResult">
@ -203,7 +212,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectUnAuthDeviceList" parameterType="com.fastbee.iot.domain.Device" resultMap="DeviceResult">
select d.device_id, d.device_name, d.product_id, d.product_name, d.tenant_id, d.tenant_name,
d.serial_number,d.gw_dev_code,d.dev_params, d.firmware_version, d.status,d.is_shadow,d.is_simulate ,d.location_way,d.active_time, d.img_url,a.device_id as auth_device_id
d.management_unit, d.caretaker, d.tel,
d.serial_number,d.gw_dev_code,d.dev_params, d.firmware_version, d.status,d.is_shadow,d.is_simulate ,
d.location_way,d.active_time, d.img_url,a.device_id as auth_device_id
from iot_device d
left join iot_product_authorize a on a.device_id=d.device_id
<where>
@ -230,7 +241,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectDeviceListByGroup" parameterType="com.fastbee.iot.domain.Device" resultMap="DeviceResult">
select d.device_id, d.device_name, d.dev_params, d.product_name, d.serial_number,d.gw_dev_code, d.firmware_version, d.status,d.rssi,d.is_shadow ,
select d.device_id, d.device_name, d.dev_params, d.product_name,
d.management_unit, d.caretaker, d.tel,
d.serial_number,d.gw_dev_code, d.firmware_version, d.status,d.rssi,d.is_shadow ,
d.location_way, d.active_time,d.network_address,d.longitude,d.latitude
from iot_device d
<where>
@ -257,7 +270,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectAllDeviceShortList" parameterType="com.fastbee.iot.domain.Device" resultMap="DeviceAllShortResult">
select d.device_id, d.device_name,d.dev_params, d.product_name,p.device_type, d.tenant_name, d.serial_number,d.gw_dev_code, d.firmware_version, d.status,d.rssi,d.is_shadow ,
select d.device_id, d.device_name,d.dev_params, d.product_name,p.device_type,
d.management_unit, d.caretaker, d.tel,
d.tenant_name, d.serial_number,d.gw_dev_code, d.firmware_version, d.status,d.rssi,d.is_shadow ,
d.location_way, d.active_time,d.network_address,d.longitude,d.latitude
from iot_device d
left join iot_product p on p.product_id=d.product_id
@ -307,7 +322,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectDeviceShortList" parameterType="com.fastbee.iot.domain.Device" resultMap="DeviceShortResult">
select d.device_id, d.device_name, d.dev_params, p.product_id, p.product_name,p.device_type,
d.tenant_id, d.tenant_name, d.serial_number,d.gw_dev_code,
d.tenant_id, d.tenant_name, d.serial_number,d.gw_dev_code,d.management_unit, d.caretaker, d.tel,
d.firmware_version, d.status,d.rssi,d.is_shadow,d.is_simulate ,d.location_way,
d.things_model_value, d.active_time,d.create_time, if(null = d.img_url or '' = d.img_url, p.img_url, d.img_url) as img_url,
case
@ -352,7 +367,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectDeviceByDeviceId" parameterType="Long" resultMap="DeviceResult">
select d.device_id, d.device_name, d.dev_params, d.product_id, p.product_name,p.device_type, d.tenant_id, d.tenant_name,
d.serial_number, d.firmware_version, d.status, d.rssi,d.is_shadow,d.is_simulate ,d.location_way,d.things_model_value,
d.serial_number, d.management_unit, d.caretaker, d.tel,
d.firmware_version, d.status, d.rssi,d.is_shadow,d.is_simulate ,d.location_way,d.things_model_value,
d.network_address, d.network_ip, d.longitude, d.latitude, d.active_time, d.create_time, d.update_time,
d.img_url,d.summary,d.remark,p.guid from iot_device d
left join iot_product p on p.product_id=d.product_id
@ -518,6 +534,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="isSimulate != null">is_simulate,</if>
<if test="slaveId != null">slave_id,</if>
<if test="devParams != null">dev_params,</if>
<if test="managementUnit != null">management_unit,</if>
<if test="caretaker != null">caretaker,</if>
<if test="tel != null">tel,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="deviceName != null and deviceName != ''">#{deviceName},</if>
@ -549,11 +568,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="isSimulate != null">#{isSimulate},</if>
<if test="slaveId != null">#{slaveId},</if>
<if test="devParams != null">#{devParams},</if>
<if test="managementUnit != null">#{managementUnit},</if>
<if test="caretaker != null">#{caretaker},</if>
<if test="tel != null">#{tel},</if>
</trim>
</insert>
<insert id="insertBatchDevice" parameterType="com.fastbee.iot.domain.Device" useGeneratedKeys="true" keyProperty="deviceId">
insert into iot_device (device_name, product_id, product_name, tenant_id, tenant_name, serial_number, firmware_version, rssi, is_shadow, location_way,dev_params, create_by, create_time)
insert into iot_device (device_name, product_id, product_name, tenant_id, tenant_name, serial_number,
firmware_version, rssi, is_shadow, location_way,dev_params, create_by, create_time)
values
<foreach collection="deviceList" item="device" separator=",">
(#{device.deviceName},
@ -604,6 +627,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="summary != null">summary = #{summary},</if>
<if test="slaveId != null">slave_id = #{slaveId},</if>
<if test="devParams != null">dev_params = #{devParams},</if>
<if test="managementUnit != null">management_unit = #{managementUnit},</if>
<if test="caretaker != null">caretaker = #{caretaker},</if>
<if test="tel != null">tel = #{tel},</if>
</trim>
where device_id = #{deviceId}
</update>
@ -665,6 +691,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="summary != null">summary = #{summary},</if>
<if test="gwDevCode != null">gw_dev_code = #{gwDevCode},</if>
<if test="devParams != null">dev_params = #{devParams},</if>
<if test="managementUnit != null">management_unit = #{managementUnit},</if>
<if test="caretaker != null">caretaker = #{caretaker},</if>
<if test="tel != null">tel = #{tel},</if>
</trim>
where serial_number = #{serialNumber}
</update>
@ -812,6 +841,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="listTerminalUser" parameterType="com.fastbee.iot.domain.Device" resultMap="DeviceShortResult">
select d.device_id, d.device_name, d.product_id, d.product_name,p.device_type,
d.tenant_id, d.tenant_name, d.serial_number,d.gw_dev_code,
d.management_unit, d.caretaker, d.tel,
d.firmware_version, d.status,d.rssi,d.is_shadow,d.is_simulate ,d.location_way,
d.things_model_value, d.active_time,d.create_time,d.img_url,d.dev_params,
(select count(*) from iot_device d1 where d1.gw_dev_code = d.serial_number) as sub_device_count,
@ -879,7 +909,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="listTerminalUserByGroup" resultType="com.fastbee.iot.domain.Device">
select d.device_id, d.device_name, d.product_name, d.serial_number,d.gw_dev_code, d.firmware_version, d.status,d.rssi,d.is_shadow ,
select d.device_id, d.device_name, d.product_name, d.serial_number,d.gw_dev_code,
d.management_unit, d.caretaker, d.tel,d.firmware_version, d.status,d.rssi,d.is_shadow ,
d.location_way, d.active_time,d.dev_params,d.network_address,d.longitude,d.latitude
from (
select device_id, 1 AS is_owner

View File

@ -70,6 +70,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="!showSenior and tenantId != null and tenantId != 0 and !isAdmin">
and p.tenant_id = #{tenantId}
</if>
<if test="productId != null and productId != ''"> and p.product_id = #{productId}</if>
<if test="productName != null and productName != ''"> and p.product_name like concat('%', #{productName}, '%')</if>
<if test="categoryName != null and categoryName != ''"> and p.category_name like concat('%', #{categoryName}, '%')</if>
<if test="status != null "> and p.status = #{status}</if>

View File

@ -409,7 +409,7 @@
specs = #{specs},
</if>
<if test="group != null and group != ''">
group = #{group},
`group` = #{group},
</if>
<if test="isChart != null">
is_chart = #{isChart},

View File

@ -7,6 +7,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="com.fastbee.iot.model.anfang.UploadedPhotos" id="UploadedPhotosResult">
<result property="id" column="id" />
<result property="photoPath" column="photo_path" />
<result property="monitorPath" column="monitor_path" />
<result property="imei" column="imei" />
<result property="sn" column="sn" />
<result property="lat" column="lat" />
@ -18,10 +19,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectUploadedPhotosVo">
select id, photo_path, imei, sn, lat, lng, temp, door_state, shake_state, upload_time from uploaded_photos
select id, photo_path,monitor_path, imei, sn, lat, lng, temp, door_state, shake_state, upload_time from uploaded_photos
</sql>
<select id="selectUploadedPhotosList" parameterType="com.fastbee.iot.model.anfang.UploadedPhotos" resultMap="UploadedPhotosResult">
<select id="selectUploadedPhotosList" parameterType="com.fastbee.iot.model.anfang.UploadedPhotos"
resultMap="UploadedPhotosResult">
<include refid="selectUploadedPhotosVo"/>
<where>
<if test="photoPath != null and photoPath != ''"> and photo_path = #{photoPath}</if>
@ -46,6 +48,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
insert into uploaded_photos
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="photoPath != null and photoPath != ''">photo_path,</if>
<if test="monitorPath != null and monitorPath != ''">monitor_path,</if>
<if test="imei != null and imei != ''">imei,</if>
<if test="sn != null">sn,</if>
<if test="lat != null">lat,</if>
@ -57,6 +60,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="photoPath != null and photoPath != ''">#{photoPath},</if>
<if test="monitorPath != null and monitorPath != ''">#{monitorPath},</if>
<if test="imei != null and imei != ''">#{imei},</if>
<if test="sn != null">#{sn},</if>
<if test="lat != null">#{lat},</if>
@ -72,6 +76,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update uploaded_photos
<trim prefix="SET" suffixOverrides=",">
<if test="photoPath != null and photoPath != ''">photo_path = #{photoPath},</if>
<if test="monitorPath != null and monitorPath != ''">monitor_path = #{monitorPath},</if>
<if test="imei != null and imei != ''">imei = #{imei},</if>
<if test="sn != null">sn = #{sn},</if>
<if test="lat != null">lat = #{lat},</if>

View File

@ -246,7 +246,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
break;
case ZH_CN:
for (SysDictData data : list) {
data.setDictLabel(data.getDictLabel_zh_CN());
data.setDictLabel(data.getDictLabel());
}
break;
}

View File

@ -15,44 +15,64 @@ import com.fastbee.common.core.domain.BaseEntity;
* @author kerwincui
* @date 2024-08-12
*/
@ApiModel(value = "MaRechargerecord",description = "充值记录 ma_rechargerecord")
@ApiModel(value = "MaRechargerecord", description = "充值记录 ma_rechargerecord")
@Data
@EqualsAndHashCode(callSuper = true)
public class MaRechargerecord extends BaseEntity
{
private static final long serialVersionUID = 1L;
public class MaRechargerecord extends BaseEntity {
private static final long serialVersionUID = 1L;
/** 序号 */
/**
* 序号
*/
private Long id;
/** 余额 */
/**
* 余额
*/
@Excel(name = "余额")
@ApiModelProperty("余额")
private String balance;
/** 充值金额 */
/**
* 充值金额
*/
@Excel(name = "充值金额")
@ApiModelProperty("充值金额")
private String investval;
/** 卡编号 */
/**
* 卡编号
*/
@Excel(name = "卡编号")
@ApiModelProperty("卡编号")
private String cardNum;
/** 区域号 */
/**
* 区域号
*/
@Excel(name = "区域号")
@ApiModelProperty("区域号")
private String areaCode;
/** 卡ID */
/**
* 卡ID
*/
@Excel(name = "卡ID")
@ApiModelProperty("卡ID")
private String cardId;
/** mcuSn */
/**
* mcuSn
*/
@Excel(name = "mcuSn")
@ApiModelProperty("mcuSn")
private String mcusn;
/**
* 充值状态
*/
@Excel(name = "充值状态")
@ApiModelProperty("充值状态2=未充值,1=充值成功")
private Integer isRecharge;
}

View File

@ -0,0 +1,15 @@
package com.fastbee.waterele.domain.vo;
import lombok.Data;
@Data
public class UnchargeAmountVo {
//卡编号
private String cardNum;
//区域号
private String areaCode;
//充值金额
private float investVal;
}

View File

@ -58,4 +58,6 @@ public interface MaRechargerecordMapper
* @return 结果
*/
public int deleteMaRechargerecordByIds(Long[] ids);
int updateByCardNumAndAreaCode(MaRechargerecord maRechargerecord);
}

View File

@ -1,6 +1,8 @@
package com.fastbee.waterele.service;
import java.util.List;
import com.fastbee.common.core.page.TableDataInfo;
import com.fastbee.waterele.domain.MaGuangaiRecord;
/**
@ -25,7 +27,7 @@ public interface IMaGuangaiRecordService
* @param maGuangaiRecord 灌溉记录
* @return 灌溉记录集合
*/
public List<MaGuangaiRecord> selectMaGuangaiRecordList(MaGuangaiRecord maGuangaiRecord);
public TableDataInfo selectMaGuangaiRecordList(MaGuangaiRecord maGuangaiRecord);
/**
* 新增灌溉记录

View File

@ -2,6 +2,7 @@ package com.fastbee.waterele.service;
import java.util.List;
import com.fastbee.waterele.domain.MaRechargerecord;
import com.fastbee.waterele.domain.vo.UnchargeAmountVo;
/**
* 充值记录Service接口
@ -58,4 +59,18 @@ public interface IMaRechargerecordService
* @return 结果
*/
public int deleteMaRechargerecordById(Long id);
/**
* 获取未充值的总金额
* @param maRechargerecord
* @return
*/
UnchargeAmountVo queryUnchargeAmount(MaRechargerecord maRechargerecord);
/**
* 充值成功反馈
* @param maRechargerecord
* @return
*/
String rechargeReply(MaRechargerecord maRechargerecord);
}

View File

@ -1,6 +1,10 @@
package com.fastbee.waterele.service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.fastbee.common.core.page.TableDataInfo;
import com.fastbee.waterele.domain.MaWatereleRecord;
/**
@ -25,8 +29,9 @@ public interface IMaWatereleRecordService
* @param maWatereleRecord 水电双计数据记录
* @return 水电双计数据记录集合
*/
public List<MaWatereleRecord> selectMaWatereleRecordList(MaWatereleRecord maWatereleRecord);
public TableDataInfo selectMaWatereleRecordList(MaWatereleRecord maWatereleRecord);
List<MaWatereleRecord> getList(MaWatereleRecord maWatereleRecord);
/**
* 新增水电双计数据记录
*
@ -58,4 +63,8 @@ public interface IMaWatereleRecordService
* @return 结果
*/
public int deleteMaWatereleRecordById(Long id);
ArrayList<Object> chartData(MaWatereleRecord maWatereleRecord);
}

View File

@ -1,13 +1,29 @@
package com.fastbee.waterele.service.impl;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.alibaba.excel.util.NumberUtils;
import com.fastbee.common.core.page.PageDomain;
import com.fastbee.common.core.page.TableDataInfo;
import com.fastbee.common.core.page.TableSupport;
import com.fastbee.common.utils.DateUtils;
import com.fastbee.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fastbee.waterele.mapper.MaGuangaiRecordMapper;
import com.fastbee.waterele.domain.MaGuangaiRecord;
import com.fastbee.waterele.service.IMaGuangaiRecordService;
import static com.fastbee.common.utils.PageUtils.startPage;
/**
* 灌溉记录Service业务层处理
*
@ -39,10 +55,106 @@ public class MaGuangaiRecordServiceImpl implements IMaGuangaiRecordService
* @return 灌溉记录
*/
@Override
public List<MaGuangaiRecord> selectMaGuangaiRecordList(MaGuangaiRecord maGuangaiRecord)
public TableDataInfo selectMaGuangaiRecordList(MaGuangaiRecord maGuangaiRecord)
{
return maGuangaiRecordMapper.selectMaGuangaiRecordList(maGuangaiRecord);
//
Long endTime = 0L;
Long startTime = 0L;
if(null == maGuangaiRecord.getParams()){
endTime = new Date().getTime()/1000;
startTime = endTime - 86400*3;
}else{
if(!maGuangaiRecord.getParams().containsKey("endCreateTime")){
endTime = new Date().getTime()/1000;
}else{
endTime = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,
maGuangaiRecord.getParams().get("endCreateTime").toString()).getTime();
}
if(!maGuangaiRecord.getParams().containsKey("beginCreateTime")){
startTime = endTime - 86400*3;
}else{
startTime = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,
maGuangaiRecord.getParams().get("beginCreateTime").toString()).getTime();
}
}
Date startDate = new Date();
startDate.setTime(startTime*1000);
String startDateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,startDate);
Date endDate = new Date();
endDate.setTime(endTime*1000);
String endDateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,endDate);
String url = "https://zhwly.sdhzwl.cn/api/java/xinjiangup/getGuangaiRecord?devSn="
+maGuangaiRecord.getDevSn()+"&startTime="+startDateStr+"&endTime="+endDateStr;
String result =HttpUtil.get(url);
JSONObject jsonObject = new JSONObject(result);
List<MaGuangaiRecord> list = new ArrayList<>();
if(jsonObject != null){
if(jsonObject.containsKey("code") && Integer.parseInt(jsonObject.get("code").toString()) == 200){
if(jsonObject.containsKey("data") && jsonObject.get("data") != null){
JSONArray dataList = (JSONArray)jsonObject.get("data");
for (Object object : dataList) {
JSONObject item = (JSONObject)object;
MaGuangaiRecord record = new MaGuangaiRecord();
record.setDevSn(item.get("dev_sn").toString());
if(StringUtils.isNotEmpty(item.get("start_time").toString())){
if(NumberUtil.isNumber(item.get("start_time").toString())) {
Date date = new Date(Long.parseLong(item.get("start_time").toString()) * 1000);
record.setStartTime(date);
}
}
if(StringUtils.isNotEmpty(item.get("end_time").toString())){
if(NumberUtil.isNumber(item.get("end_time").toString())){
Date date = new Date(Long.parseLong(item.get("end_time").toString())*1000);
record.setEndTime(date);
}
}
if(StringUtils.isNotEmpty(item.get("last_time").toString())){
if(NumberUtil.isNumber(item.get("last_time").toString())) {
Date date = new Date(Long.parseLong(item.get("last_time").toString()) * 1000);
record.setLastTime(date);
}
}
record.setCurEle(item.get("cur_ele").toString());
record.setCardId(item.get("card_id").toString());
record.setAreaCode(item.get("area_code").toString());
record.setUserBalance(com.fastbee.common.utils.NumberUtils.formatFloat(Float.parseFloat(item.get("user_balance").toString())/100)+"");
record.setCurFlow(item.get("cur_flow").toString());
record.setCurEle(item.get("cur_ele").toString());
record.setStatus(Integer.parseInt(item.get("status").toString()));
if(StringUtils.isNotEmpty(item.get("create_time").toString())){
if(NumberUtil.isNumber(item.get("create_time").toString())) {
Date date = new Date(Long.parseLong(item.get("create_time").toString()) * 1000);
record.setCreateTime(date);
}
}
list.add(record);
}
}
}
}
//
PageDomain pageDomain = TableSupport.buildPageRequest();
Integer pageNum = pageDomain.getPageNum();
Integer pageSize = pageDomain.getPageSize();
List<MaGuangaiRecord> subList = new ArrayList<>();
if(list.size() > (pageNum-1)*pageSize){
if(list.size() < pageNum*pageSize){
subList = list.subList((pageNum-1)*pageSize, list.size());
}else{
subList = list.subList((pageNum-1)*pageSize, pageNum*pageSize);
}
}
TableDataInfo tableDataInfo = new TableDataInfo();
tableDataInfo.setMsg("获取成功");
tableDataInfo.setTotal(list.size());
tableDataInfo.setRows(subList);
tableDataInfo.setCode(200);
return tableDataInfo;
}
/**
* 新增灌溉记录

View File

@ -1,7 +1,13 @@
package com.fastbee.waterele.service.impl;
import java.util.Date;
import java.util.List;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import com.fastbee.common.utils.DateUtils;
import com.fastbee.common.utils.StringUtils;
import com.fastbee.waterele.domain.vo.UnchargeAmountVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fastbee.waterele.mapper.MaRechargerecordMapper;
@ -15,8 +21,7 @@ import com.fastbee.waterele.service.IMaRechargerecordService;
* @date 2024-08-12
*/
@Service
public class MaRechargerecordServiceImpl implements IMaRechargerecordService
{
public class MaRechargerecordServiceImpl implements IMaRechargerecordService {
@Autowired
private MaRechargerecordMapper maRechargerecordMapper;
@ -27,8 +32,7 @@ public class MaRechargerecordServiceImpl implements IMaRechargerecordService
* @return 充值记录
*/
@Override
public MaRechargerecord selectMaRechargerecordById(Long id)
{
public MaRechargerecord selectMaRechargerecordById(Long id) {
return maRechargerecordMapper.selectMaRechargerecordById(id);
}
@ -39,8 +43,7 @@ public class MaRechargerecordServiceImpl implements IMaRechargerecordService
* @return 充值记录
*/
@Override
public List<MaRechargerecord> selectMaRechargerecordList(MaRechargerecord maRechargerecord)
{
public List<MaRechargerecord> selectMaRechargerecordList(MaRechargerecord maRechargerecord) {
return maRechargerecordMapper.selectMaRechargerecordList(maRechargerecord);
}
@ -51,11 +54,21 @@ public class MaRechargerecordServiceImpl implements IMaRechargerecordService
* @return 结果
*/
@Override
public int insertMaRechargerecord(MaRechargerecord maRechargerecord)
{
public int insertMaRechargerecord(MaRechargerecord maRechargerecord) {
maRechargerecord.setCreateTime(DateUtils.getNowDate());
// https://zhwly.sdhzwl.cn/api/java/xinjiangup/recharge?cardNum=1&areaCode=123&jine=20
String url = "https://zhwly.sdhzwl.cn/api/java/xinjiangup/recharge?cardNum="
+ maRechargerecord.getCardNum()+"&areaCode="+maRechargerecord.getAreaCode()+"&jine="+maRechargerecord.getInvestval();
String result = HttpUtil.get(url);
JSONObject jsonObject = new JSONObject(result);
if(jsonObject != null){
if(jsonObject.containsKey("code") && Integer.parseInt(jsonObject.get("code").toString()) == 200){
return maRechargerecordMapper.insertMaRechargerecord(maRechargerecord);
}
}
return 0;
}
/**
* 修改充值记录
@ -64,8 +77,7 @@ public class MaRechargerecordServiceImpl implements IMaRechargerecordService
* @return 结果
*/
@Override
public int updateMaRechargerecord(MaRechargerecord maRechargerecord)
{
public int updateMaRechargerecord(MaRechargerecord maRechargerecord) {
maRechargerecord.setUpdateTime(DateUtils.getNowDate());
return maRechargerecordMapper.updateMaRechargerecord(maRechargerecord);
}
@ -77,8 +89,7 @@ public class MaRechargerecordServiceImpl implements IMaRechargerecordService
* @return 结果
*/
@Override
public int deleteMaRechargerecordByIds(Long[] ids)
{
public int deleteMaRechargerecordByIds(Long[] ids) {
return maRechargerecordMapper.deleteMaRechargerecordByIds(ids);
}
@ -89,8 +100,33 @@ public class MaRechargerecordServiceImpl implements IMaRechargerecordService
* @return 结果
*/
@Override
public int deleteMaRechargerecordById(Long id)
{
public int deleteMaRechargerecordById(Long id) {
return maRechargerecordMapper.deleteMaRechargerecordById(id);
}
@Override
public UnchargeAmountVo queryUnchargeAmount(MaRechargerecord maRechargerecord) {
maRechargerecord.setIsRecharge(2);
List<MaRechargerecord> maRechargerecords = maRechargerecordMapper.selectMaRechargerecordList(maRechargerecord);
float total = 0;
for (MaRechargerecord record : maRechargerecords) {
total += Float.parseFloat(record.getInvestval());
}
UnchargeAmountVo vo = new UnchargeAmountVo();
vo.setInvestVal(total);
vo.setCardNum(maRechargerecord.getCardNum());
vo.setAreaCode(maRechargerecord.getAreaCode());
return vo;
}
@Override
public String rechargeReply(MaRechargerecord maRechargerecord) {
if (StringUtils.isNotEmpty(maRechargerecord.getCardNum()) && StringUtils.isNotEmpty(maRechargerecord.getAreaCode())) {
if (maRechargerecord.getIsRecharge() == 1) {
maRechargerecord.setUpdateTime(new Date());
int count = maRechargerecordMapper.updateByCardNumAndAreaCode(maRechargerecord);
}
}
return "更新成功";
}
}

View File

@ -1,7 +1,18 @@
package com.fastbee.waterele.service.impl;
import java.util.List;
import java.util.*;
import java.util.function.Function;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.fastbee.common.core.page.PageDomain;
import com.fastbee.common.core.page.TableDataInfo;
import com.fastbee.common.core.page.TableSupport;
import com.fastbee.common.utils.DateUtils;
import com.fastbee.common.utils.StringUtils;
import com.fastbee.waterele.domain.MaGuangaiRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fastbee.waterele.mapper.MaWatereleRecordMapper;
@ -39,9 +50,103 @@ public class MaWatereleRecordServiceImpl implements IMaWatereleRecordService
* @return 水电双计数据记录
*/
@Override
public List<MaWatereleRecord> selectMaWatereleRecordList(MaWatereleRecord maWatereleRecord)
public TableDataInfo selectMaWatereleRecordList(MaWatereleRecord maWatereleRecord)
{
return maWatereleRecordMapper.selectMaWatereleRecordList(maWatereleRecord);
List<MaWatereleRecord> list = getList(maWatereleRecord);
PageDomain pageDomain = TableSupport.buildPageRequest();
Integer pageNum = pageDomain.getPageNum();
Integer pageSize = pageDomain.getPageSize();
List<MaWatereleRecord> subList = new ArrayList<>();
if(list.size() > (pageNum-1)*pageSize){
if(list.size() < pageNum*pageSize){
subList = list.subList((pageNum-1)*pageSize, list.size());
}else{
subList = list.subList((pageNum-1)*pageSize, pageNum*pageSize);
}
}
TableDataInfo tableDataInfo = new TableDataInfo();
tableDataInfo.setMsg("获取成功");
tableDataInfo.setTotal(list.size());
tableDataInfo.setRows(subList);
tableDataInfo.setCode(200);
return tableDataInfo;
}
@Override
public List<MaWatereleRecord> getList(MaWatereleRecord maWatereleRecord){
Long endTime = 0L;
Long startTime = 0L;
if(null == maWatereleRecord.getParams()){
endTime = new Date().getTime()/1000;
startTime = endTime - 86400*3;
}else{
if(!maWatereleRecord.getParams().containsKey("endCreateTime")){
endTime = new Date().getTime()/1000;
}else{
endTime = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,
maWatereleRecord.getParams().get("endCreateTime").toString()).getTime();
}
if(!maWatereleRecord.getParams().containsKey("beginCreateTime")){
startTime = endTime - 86400*3;
}else{
startTime = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,
maWatereleRecord.getParams().get("beginCreateTime").toString()).getTime();
}
}
Date startDate = new Date();
startDate.setTime(startTime*1000);
String startDateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,startDate);
Date endDate = new Date();
endDate.setTime(endTime*1000);
String endDateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,endDate);
String url = "https://zhwly.sdhzwl.cn/api/java/xinjiangup/getShuakaRecord?devSn="
+maWatereleRecord.getDevSn()+"&startTime="+startDateStr+"&endTime="+endDateStr;
String result = HttpUtil.get(url);
JSONObject jsonObject = new JSONObject(result);
List<MaWatereleRecord> list = new ArrayList<>();
if(jsonObject != null){
if(jsonObject.containsKey("code") && Integer.parseInt(jsonObject.get("code").toString()) == 200){
if(jsonObject.containsKey("data") && jsonObject.get("data") != null){
JSONArray dataList = (JSONArray)jsonObject.get("data");
for (Object object : dataList) {
JSONObject item = (JSONObject)object;
MaWatereleRecord record = new MaWatereleRecord();
record.setDevSn(item.get("dev_sn").toString());
record.setWorkstate(Integer.parseInt(item.get("workState").toString()));
record.setUsersumflow(item.get("userSumFlow").toString());
record.setUsersumele(item.get("userSumEle").toString());
record.setUserbalance(item.get("userBalance").toString());
record.setSumflow(item.get("sumFlow").toString());
record.setSumele(item.get("sumEle").toString());
record.setMcusn(item.get("mcuSn").toString());
record.setInspower(item.get("insPower").toString());
record.setInsflow(item.get("insFlow").toString());
record.setCurflow(item.get("curFlow").toString());
record.setCurele(item.get("curEle").toString());
record.setMetersum(item.get("meterSum").toString());
record.setMeterins(item.get("meterIns").toString());
record.setCardid(item.get("cardId").toString());
record.setAreacode(item.get("areaCode").toString());
record.setAction(item.get("action").toString());
if(StringUtils.isNotEmpty(item.get("create_time").toString())){
if(NumberUtil.isNumber(item.get("create_time").toString())) {
Date date = new Date(Long.parseLong(item.get("create_time").toString()) * 1000);
record.setCreateTime(date);
}
}
if(StringUtils.isNotEmpty(item.get("update_time").toString())){
if(NumberUtil.isNumber(item.get("update_time").toString())) {
Date date = new Date(Long.parseLong(item.get("update_time").toString()) * 1000);
record.setUpdateTime(date);
}
}
list.add(record);
}
}
}
}
return list;
}
/**
@ -93,4 +198,35 @@ public class MaWatereleRecordServiceImpl implements IMaWatereleRecordService
{
return maWatereleRecordMapper.deleteMaWatereleRecordById(id);
}
@Override
public ArrayList<Object> chartData(MaWatereleRecord maWatereleRecord) {
Map<String, Object> map = new HashMap<String, Object>();
ArrayList<Object> list = new ArrayList<>();
List<MaWatereleRecord> maWatereleRecords = maWatereleRecordMapper.selectMaWatereleRecordList(maWatereleRecord);
List<String> time = new ArrayList<>();
List<String> sumFlow = new ArrayList<>();
List<String> sumEle = new ArrayList<>();
// HashMap<String, Object> sumFlowtMap = new HashMap<>();
// sumFlowtMap.put("name", "累计水量");
// sumFlowtMap.put("unit", "m³");
HashMap<String, Object> sumEletMap = new HashMap<>();
sumEletMap.put("name", "累计电量");
sumEletMap.put("unit", "");
for (MaWatereleRecord record : maWatereleRecords) {
time.add(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, record.getCreateTime()));
sumFlow.add(record.getSumflow());
sumEle.add(record.getSumele());
}
// sumFlowtMap.put("time", time);
// sumFlowtMap.put("data", sumFlow);
sumEletMap.put("time", time);
sumEletMap.put("data", sumEle);
// list.add(sumFlowtMap);
list.add(sumEletMap);
// map.put("time", time);
// map.put("sumFlow", sumFlow);
// map.put("sumEle", sumEle);
return list;
}
}

View File

@ -30,6 +30,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="cardtype != null "> and cardType = #{cardtype}</if>
<if test="mcusn != null and mcusn != ''"> and mcuSn = #{mcusn}</if>
</where>
order by create_time desc
</select>
<select id="selectMaCardinfoById" parameterType="Long" resultMap="MaCardinfoResult">

View File

@ -37,7 +37,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="curFlow != null and curFlow != ''"> and cur_flow = #{curFlow}</if>
<if test="curEle != null and curEle != ''"> and cur_ele = #{curEle}</if>
<if test="status != null "> and status = #{status}</if>
<if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
<if test="params.beginCreateTime != null and params.beginCreateTime != ''
and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
</where>
</select>

View File

@ -12,12 +12,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="areaCode" column="area_code" />
<result property="cardId" column="card_id" />
<result property="mcusn" column="mcuSn" />
<result property="isRecharge" column="is_recharge" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectMaRechargerecordVo">
select id, balance, investVal, card_num, area_code, card_id, mcuSn, create_time, update_time from ma_rechargerecord
select * from ma_rechargerecord
</sql>
<select id="selectMaRechargerecordList" parameterType="MaRechargerecord" resultMap="MaRechargerecordResult">
@ -29,7 +30,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="areaCode != null and areaCode != ''"> and area_code = #{areaCode}</if>
<if test="cardId != null and cardId != ''"> and card_id = #{cardId}</if>
<if test="mcusn != null and mcusn != ''"> and mcuSn = #{mcusn}</if>
<if test="isRecharge != null and isRecharge != ''"> and is_recharge = #{isRecharge}</if>
</where>
order by create_time desc
</select>
<select id="selectMaRechargerecordById" parameterType="Long" resultMap="MaRechargerecordResult">
@ -46,6 +49,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="areaCode != null">area_code,</if>
<if test="cardId != null">card_id,</if>
<if test="mcusn != null">mcuSn,</if>
<if test="isRecharge != null">is_recharge,</if>
<if test="createTime != null">create_time,</if>
<if test="updateTime != null">update_time,</if>
</trim>
@ -56,6 +60,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="areaCode != null">#{areaCode},</if>
<if test="cardId != null">#{cardId},</if>
<if test="mcusn != null">#{mcusn},</if>
<if test="isRecharge != null">#{isRecharge},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
@ -70,11 +75,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="areaCode != null">area_code = #{areaCode},</if>
<if test="cardId != null">card_id = #{cardId},</if>
<if test="mcusn != null">mcuSn = #{mcusn},</if>
<if test="isRecharge != null">is_recharge = #{isRecharge},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where id = #{id}
</update>
<update id="updateByCardNumAndAreaCode">
update ma_rechargerecord
<trim prefix="SET" suffixOverrides=",">
<if test="isRecharge != null">is_recharge = #{isRecharge},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where card_num = #{cardNum} and is_recharge = 0 and area_code = #{areaCode}
</update>
<delete id="deleteMaRechargerecordById" parameterType="Long">
delete from ma_rechargerecord where id = #{id}

View File

@ -51,7 +51,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="cardid != null and cardid != ''"> and cardId = #{cardid}</if>
<if test="areacode != null and areacode != ''"> and areaCode = #{areacode}</if>
<if test="action != null and action != ''"> and action = #{action}</if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
AND date_format(create_time ,'%y%m%d%H%i%s') &gt;= date_format(#{params.beginTime},'%y%m%d%H%i%s')
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
AND date_format(create_time ,'%y%m%d%H%i%s') &lt;= date_format(#{params.endTime},'%y%m%d%H%i%s')
</if>
</where>
order by create_time desc
</select>
<select id="selectMaWatereleRecordById" parameterType="Long" resultMap="MaWatereleRecordResult">

View File

@ -63,6 +63,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
AND date_format(end_time ,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if>
<if test="chaxunBeginTime != null and chaxunBeginTime != ''"><!-- 开始时间检索 -->
AND date_format(end_time ,'%y%m%d%H%i%s') &gt;= date_format(#{chaxunBeginTime},'%y%m%d%H%i%s')
</if>
<if test="chaxunEndTime != null and chaxunEndTime != ''"><!-- 结束时间检索 -->
AND date_format(end_time ,'%y%m%d%H%i%s') &lt;= date_format(#{chaxunEndTime},'%y%m%d%H%i%s')
</if>
</where>
order by id desc
</select>