diff --git a/pom.xml b/pom.xml index f0a5ce2..1295029 100644 --- a/pom.xml +++ b/pom.xml @@ -159,6 +159,7 @@ psdc-common psdc-admin psdc-business + psdc-quartz pom diff --git a/psdc-admin/src/main/resources/logback.xml b/psdc-admin/src/main/resources/logback.xml index 2ab75e9..cb6f77e 100644 --- a/psdc-admin/src/main/resources/logback.xml +++ b/psdc-admin/src/main/resources/logback.xml @@ -72,7 +72,7 @@ - + diff --git a/psdc-business/src/main/java/com/psdc/entity/PsdcControlLog.java b/psdc-business/src/main/java/com/psdc/entity/PsdcControlLog.java index d86fda4..0664793 100644 --- a/psdc-business/src/main/java/com/psdc/entity/PsdcControlLog.java +++ b/psdc-business/src/main/java/com/psdc/entity/PsdcControlLog.java @@ -48,6 +48,10 @@ public class PsdcControlLog implements Serializable { * 控制结果:1-控制中,2-控制成功,3-控制失败 */ private Integer controlResult; + /** + * 控制结果描述 + */ + private String controlContext; /** * 创建者 */ @@ -64,4 +68,15 @@ public class PsdcControlLog implements Serializable { * 更新时间 */ private String updateTime; + + public PsdcControlLog(Integer deviceId, String deviceName, String deviceSn, String controlKey, String controlValue, Integer controlResult,String controlContext, String createBy) { + this.deviceId = deviceId; + this.deviceName = deviceName; + this.deviceSn = deviceSn; + this.controlKey = controlKey; + this.controlValue = controlValue; + this.controlResult = controlResult; + this.controlContext = controlContext; + this.createBy = createBy; + } } \ No newline at end of file diff --git a/psdc-business/src/main/java/com/psdc/entity/vo/DeviceStatusVo.java b/psdc-business/src/main/java/com/psdc/entity/vo/DeviceStatusVo.java new file mode 100644 index 0000000..259902c --- /dev/null +++ b/psdc-business/src/main/java/com/psdc/entity/vo/DeviceStatusVo.java @@ -0,0 +1,36 @@ +package com.psdc.entity.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.stereotype.Component; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Component +public class DeviceStatusVo { + + /** + * 设备id + */ + private Integer deviceId; + + /** + * 设备类型:1-监测设备,2-运行设备 + */ + private Integer deviceType; + /** + * 设备名称 + */ + private String deviceName; + /** + * 设备sn + */ + private String deviceSn; + /** 图片地址 */ + private String photoUrl ; + /** 设备运行状态:1-开启,2-关闭 */ + private Integer deviceRunstatus ; + +} diff --git a/psdc-business/src/main/java/com/psdc/mapper/PsdcControlLogMapper.java b/psdc-business/src/main/java/com/psdc/mapper/PsdcControlLogMapper.java index 4fb398e..47e0cb1 100644 --- a/psdc-business/src/main/java/com/psdc/mapper/PsdcControlLogMapper.java +++ b/psdc-business/src/main/java/com/psdc/mapper/PsdcControlLogMapper.java @@ -1,10 +1,12 @@ package com.psdc.mapper; import com.psdc.entity.PsdcControlLog; +import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.util.List; +@Mapper public interface PsdcControlLogMapper{ /** * 通过ID查询单条数据 @@ -13,14 +15,13 @@ public interface PsdcControlLogMapper{ * @return 实例对象 */ PsdcControlLog queryById(Integer controlLogId); - /** - * 分页查询指定行数据 - * - * @param psdcControlLog 查询条件 - * @param pageable 分页对象 - * @return 对象列表 + + /** + * 分页查询控制日志 + * @param psdcControlLog */ - List queryAllByLimit(PsdcControlLog psdcControlLog, @Param("pageable") Pageable pageable); + List queryControlLogList(PsdcControlLog psdcControlLog); + /** * 统计总行数 * @@ -49,4 +50,6 @@ public interface PsdcControlLogMapper{ * @return 影响行数 */ int deleteById(Integer controlLogId); + + } \ No newline at end of file diff --git a/psdc-business/src/main/java/com/psdc/mapper/PsdcDeviceMapper.java b/psdc-business/src/main/java/com/psdc/mapper/PsdcDeviceMapper.java index 3359a61..383f656 100644 --- a/psdc-business/src/main/java/com/psdc/mapper/PsdcDeviceMapper.java +++ b/psdc-business/src/main/java/com/psdc/mapper/PsdcDeviceMapper.java @@ -6,9 +6,10 @@ import com.psdc.entity.PsdcDevice; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.springframework.data.domain.Pageable; +import org.springframework.security.access.method.P; - /** +/** * 设备信息表;(psdc_device)表数据库访问层 * @author : http://www.chiner.pro * @date : 2023-4-23 @@ -58,4 +59,19 @@ public interface PsdcDeviceMapper{ * @return 影响行数 */ int deleteById(Integer deviceId); -} \ No newline at end of file + + /** + * 根据用户id查询设备 + * @param userId + * @return + */ + List queryByUserId(Long userId); + + /** + * 根据设备id修改设备状态 + * @param deviceId + * @return + */ + int updateDevRunStatusByDevId(@Param(value = "deviceId") Integer deviceId, + @Param(value = "runStatus") Integer runStatus); + } \ No newline at end of file diff --git a/psdc-business/src/main/java/com/psdc/service/IPsdcControlLogService.java b/psdc-business/src/main/java/com/psdc/service/IPsdcControlLogService.java new file mode 100644 index 0000000..932c2d2 --- /dev/null +++ b/psdc-business/src/main/java/com/psdc/service/IPsdcControlLogService.java @@ -0,0 +1,47 @@ +package com.psdc.service; + +import com.psdc.entity.PsdcControlLog; + +import java.util.List; + +/** + * 控制日志;(psdc_control_log)表服务接口 + * @date : 2023-5-9 + */ +public interface IPsdcControlLogService { + /** + * 通过ID查询单条数据 + * + * @param controlLogId 主键 + * @return 实例对象 + */ + PsdcControlLog queryById(Integer controlLogId); + + /** + * 新增数据 + * + * @param psdcControlLog 实例对象 + * @return 实例对象 + */ + PsdcControlLog insert(PsdcControlLog psdcControlLog); + /** + * 更新数据 + * + * @param psdcControlLog 实例对象 + * @return 实例对象 + */ + PsdcControlLog update(PsdcControlLog psdcControlLog); + /** + * 通过主键删除数据 + * + * @param controlLogId 主键 + * @return 是否成功 + */ + boolean deleteById(Integer controlLogId); + + /** + * 分页查询控制日志 + * @param psdcControlLog + */ + List query(PsdcControlLog psdcControlLog); +} \ No newline at end of file diff --git a/psdc-business/src/main/java/com/psdc/service/IPsdcDeviceService.java b/psdc-business/src/main/java/com/psdc/service/IPsdcDeviceService.java index 9d0d9e0..a12ed53 100644 --- a/psdc-business/src/main/java/com/psdc/service/IPsdcDeviceService.java +++ b/psdc-business/src/main/java/com/psdc/service/IPsdcDeviceService.java @@ -1,7 +1,9 @@ package com.psdc.service; import com.psdc.entity.PsdcDevice; -import org.springframework.data.domain.PageRequest; +import com.psdc.entity.vo.DeviceStatusVo; + +import java.util.List; public interface IPsdcDeviceService { @@ -13,6 +15,18 @@ public interface IPsdcDeviceService { */ PsdcDevice queryById(Integer deviceId); + /** + * 根据用户id查询设备列表 + * @return + */ + List queryByUserId(); + + /** + * 查询所有设备状态 + * @return + */ + List queryDeviceStatus(); + /** * 新增数据 * @@ -20,6 +34,7 @@ public interface IPsdcDeviceService { * @return 实例对象 */ PsdcDevice insert(PsdcDevice psdcDevice); + /** * 更新数据 * @@ -35,4 +50,20 @@ public interface IPsdcDeviceService { */ boolean deleteById(Integer deviceId); + /** + * 更新设备状态 + * @param deviceId + * @param runStatus + * @return + */ + int updateDeviceRunStatus(Integer deviceId,Integer runStatus); + + /** + * 控制设备启动停止 + * @param deviceId + * @param runStatus + * @return + */ + int controlDeviceStartAndStop(Integer deviceId,Integer runStatus); + } diff --git a/psdc-business/src/main/java/com/psdc/service/impl/PsdcControlLogServiceImpl.java b/psdc-business/src/main/java/com/psdc/service/impl/PsdcControlLogServiceImpl.java new file mode 100644 index 0000000..1998696 --- /dev/null +++ b/psdc-business/src/main/java/com/psdc/service/impl/PsdcControlLogServiceImpl.java @@ -0,0 +1,69 @@ +package com.psdc.service.impl; + +import com.psdc.entity.PsdcControlLog; +import com.psdc.mapper.PsdcControlLogMapper; +import com.psdc.service.IPsdcControlLogService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 控制日志;(psdc_control_log)表服务实现类 + * @date : 2023-5-9 + */ +@Service +public class PsdcControlLogServiceImpl implements IPsdcControlLogService { + @Autowired + private PsdcControlLogMapper psdcControlLogMapper; + + /** + * 通过ID查询单条数据 + * + * @param controlLogId 主键 + * @return 实例对象 + */ + public PsdcControlLog queryById(Integer controlLogId){ + return psdcControlLogMapper.queryById(controlLogId); + } + + + + /** + * 新增数据 + * + * @param psdcControlLog 实例对象 + * @return 实例对象 + */ + public PsdcControlLog insert(PsdcControlLog psdcControlLog){ + psdcControlLogMapper.insert(psdcControlLog); + return psdcControlLog; + } + + /** + * 更新数据 + * + * @param psdcControlLog 实例对象 + * @return 实例对象 + */ + public PsdcControlLog update(PsdcControlLog psdcControlLog){ + psdcControlLogMapper.update(psdcControlLog); + return queryById(psdcControlLog.getControlLogId()); + } + + /** + * 通过主键删除数据 + * + * @param controlLogId 主键 + * @return 是否成功 + */ + public boolean deleteById(Integer controlLogId){ + int total = psdcControlLogMapper.deleteById(controlLogId); + return total > 0; + } + + @Override + public List query(PsdcControlLog psdcControlLog) { + return psdcControlLogMapper.queryControlLogList(psdcControlLog); + } + } \ No newline at end of file diff --git a/psdc-business/src/main/java/com/psdc/service/impl/PsdcDeviceServiceImpl.java b/psdc-business/src/main/java/com/psdc/service/impl/PsdcDeviceServiceImpl.java index b9203d3..e820ae7 100644 --- a/psdc-business/src/main/java/com/psdc/service/impl/PsdcDeviceServiceImpl.java +++ b/psdc-business/src/main/java/com/psdc/service/impl/PsdcDeviceServiceImpl.java @@ -1,18 +1,31 @@ package com.psdc.service.impl; +import com.psdc.entity.PsdcControlLog; import com.psdc.entity.PsdcDevice; +import com.psdc.entity.vo.DeviceStatusVo; +import com.psdc.exception.ControlException; +import com.psdc.mapper.PsdcControlLogMapper; import com.psdc.mapper.PsdcDeviceMapper; import com.psdc.service.IPsdcDeviceService; +import com.psdc.utils.SecurityUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.PageImpl; -import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; +import java.util.List; +import java.util.stream.Collectors; + @Service +@Slf4j public class PsdcDeviceServiceImpl implements IPsdcDeviceService{ + @Autowired private PsdcDeviceMapper psdcDeviceMapper; + @Autowired + private PsdcControlLogMapper psdcControlLogMapper; + /** * 通过ID查询单条数据 * @@ -23,6 +36,23 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService{ return psdcDeviceMapper.queryById(deviceId); } + /** + * 根据用户id查询设备列表 + * @return + */ + public List queryByUserId(){ + return psdcDeviceMapper.queryByUserId(SecurityUtils.getUserId()); + } + + public List queryDeviceStatus(){ + List psdcDevices = psdcDeviceMapper.queryByUserId(SecurityUtils.getUserId()); + return psdcDevices.stream().map(psdcDevice -> { + DeviceStatusVo deviceStatusVo = new DeviceStatusVo(); + BeanUtils.copyProperties(psdcDevice, deviceStatusVo); + return deviceStatusVo; + }).collect(Collectors.toList()); + } + /** * 新增数据 * @@ -55,4 +85,48 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService{ int total = psdcDeviceMapper.deleteById(deviceId); return total > 0; } + + /** + * 更新设备状态 + * @param deviceId + * @param runStatus + * @return + */ + @Override + public int updateDeviceRunStatus(Integer deviceId, Integer runStatus) { + return psdcDeviceMapper.updateDevRunStatusByDevId(deviceId,runStatus); + } + + /** + * 控制设备启动停止 + * @param deviceId + * @param runStatus + * @return + */ + @Override + public int controlDeviceStartAndStop(Integer deviceId, Integer runStatus) { + + String s = ""; + if(runStatus == 1){ + s = "启动"; + } else if ( runStatus == 2 ) { + s = "停止"; + } + log.info("设备id:{}",deviceId); + + PsdcDevice psdcDevice = psdcDeviceMapper.queryById(deviceId); + if(psdcDevice == null){ + psdcControlLogMapper.insert(new PsdcControlLog(deviceId,null,null,"设备启停",s,2,"未找到该设备",SecurityUtils.getUsername())); + throw new ControlException("控制失败,未找到该设备"); + } + + //TODO 发送MQTT指令 + // psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),"设备启停",s,2,"等待终端响应超时",SecurityUtils.getUsername())); + + //发送成功 + psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),"设备启停",s,2,"控制成功",SecurityUtils.getUsername())); + return psdcDeviceMapper.updateDevRunStatusByDevId(deviceId,runStatus); + } + + } \ No newline at end of file diff --git a/psdc-business/src/main/resources/mapper/business/PsdcControlLogMapper.xml b/psdc-business/src/main/resources/mapper/business/PsdcControlLogMapper.xml index 77ccea6..9798048 100644 --- a/psdc-business/src/main/resources/mapper/business/PsdcControlLogMapper.xml +++ b/psdc-business/src/main/resources/mapper/business/PsdcControlLogMapper.xml @@ -2,31 +2,42 @@ - - - - - - - - - - - + + + + + + + + + + + + - select - control_log_id,device_id,device_name,device_sn,control_key,control_value,control_result,create_by,create_time,update_by,update_time + control_log_id,device_id,device_name,device_sn,control_key,control_value,control_result,control_context,create_by,create_time,update_by,update_time from psdc_control_log @@ -50,6 +61,9 @@ and control_result = #{controlResult} + + and control_context = #{controlContext} + and create_by = #{createBy} @@ -63,7 +77,6 @@ and update_time = #{updateTime} - limit #{pageable.offset}, #{pageable.pageSize} @@ -92,6 +105,9 @@ and control_result = #{controlResult} + + and control_context = #{controlContext} + and create_by = #{createBy} @@ -108,18 +124,11 @@ - - insert into psdc_control_log(control_log_id,device_id,device_name,device_sn,control_key,control_value,control_result,create_by,create_time,update_by,update_time) - values (#{controlLogId},#{deviceId},#{deviceName},#{deviceSn},#{controlKey},#{controlValue},#{controlResult},#{createBy},#{createTime},#{updateBy},#{updateTime}) - - - - - insert into psdc_control_log(control_log_id,device_id,device_name,device_sn,control_key,control_value,control_result,create_by,create_time,update_by,update_time) - values - - (#{entity.controlLogId},#{entity.deviceId},#{entity.deviceName},#{entity.deviceSn},#{entity.controlKey},#{entity.controlValue},#{entity.controlResult},#{entity.createBy},#{entity.createTime},#{entity.updateBy},#{entity.updateTime}) - + + insert into psdc_control_log(device_id, device_name, device_sn, control_key, control_value, control_result,control_context, + create_by, create_time, update_by, update_time) + values (#{deviceId}, #{deviceName}, #{deviceSn}, #{controlKey}, #{controlValue}, #{controlResult},#{controlContext}, #{createBy}, + sysdate(), #{updateBy}, #{updateTime}) @@ -148,6 +157,9 @@ control_result = #{controlResult}, + + and control_context = #{controlContext} + create_by = #{createBy}, @@ -166,6 +178,8 @@ - delete from psdc_control_log where control_log_id = #{controlLogId} + delete + from psdc_control_log + where control_log_id = #{controlLogId} \ No newline at end of file diff --git a/psdc-business/src/main/resources/mapper/business/PsdcDeviceMapper.xml b/psdc-business/src/main/resources/mapper/business/PsdcDeviceMapper.xml index 629f0bf..3178cbc 100644 --- a/psdc-business/src/main/resources/mapper/business/PsdcDeviceMapper.xml +++ b/psdc-business/src/main/resources/mapper/business/PsdcDeviceMapper.xml @@ -2,36 +2,71 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - + + - - insert into psdc_device(user_id,device_type,device_sn,device_name,hard_version,soft_version,device_address,start_time,device_status,photo_url,create_by,create_time,update_by,update_time) - values (#{userId},#{deviceType},#{deviceSn},#{deviceName},#{hardVersion},#{softVersion},#{deviceAddress},#{startTime},#{deviceStatus},#{photoUrl},#{createBy},#{createTime},#{updateBy},#{updateTime}) + + insert into psdc_device(user_id, device_type, device_sn, device_name, hard_version, soft_version, + device_address, start_time, device_status, device_runstatus, photo_url, create_by, + create_time, update_by, update_time) + values (#{userId}, #{deviceType}, #{deviceSn}, #{deviceName}, #{hardVersion}, #{softVersion}, #{deviceAddress}, + #{startTime}, #{deviceStatus}, #{deviceRunstatus}, #{photoUrl}, #{createBy}, #{createTime}, #{updateBy}, + #{updateTime}) @@ -176,6 +221,9 @@ device_status = #{deviceStatus}, + + and device_runstatus = #{deviceRunstatus} + photo_url = #{photoUrl}, @@ -197,6 +245,14 @@ - delete from psdc_device where device_id = #{deviceId} + delete + from psdc_device + where device_id = #{deviceId} + + + + update psdc_device set device_runstatus = #{runStatus} where device_id = #{deviceId} + + \ No newline at end of file diff --git a/psdc-common/src/main/java/com/psdc/exception/ControlException.java b/psdc-common/src/main/java/com/psdc/exception/ControlException.java new file mode 100644 index 0000000..3a6470b --- /dev/null +++ b/psdc-common/src/main/java/com/psdc/exception/ControlException.java @@ -0,0 +1,25 @@ +package com.psdc.exception; + +public class ControlException extends RuntimeException{ + private static final long serialVersionUID = 1L; + + public ControlException() { + super(); + } + + public ControlException(String message) { + super(message); + } + + public ControlException(String message, Throwable cause) { + super(message, cause); + } + + public ControlException(Throwable cause) { + super(cause); + } + + protected ControlException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/psdc-quartz/pom.xml b/psdc-quartz/pom.xml index 27fd9b7..66af52b 100644 --- a/psdc-quartz/pom.xml +++ b/psdc-quartz/pom.xml @@ -3,20 +3,23 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - psdc com.psdc + psdc 0.0.1 - 4.0.0 + 4.0.0 + jar psdc-quartz quartz定时任务 + + org.quartz-scheduler diff --git a/psdc-ui/src/api/control/timer.js b/psdc-ui/src/api/control/timer.js new file mode 100644 index 0000000..e69de29 diff --git a/psdc-web/pom.xml b/psdc-web/pom.xml index 999295a..7192c06 100644 --- a/psdc-web/pom.xml +++ b/psdc-web/pom.xml @@ -32,6 +32,11 @@ 0.0.1 + + com.psdc + psdc-business + 0.0.1 + diff --git a/psdc-web/src/main/java/com/psdc/controller/control/ManualControl.java b/psdc-web/src/main/java/com/psdc/controller/control/ManualControl.java index 0d1d086..b5acbf5 100644 --- a/psdc-web/src/main/java/com/psdc/controller/control/ManualControl.java +++ b/psdc-web/src/main/java/com/psdc/controller/control/ManualControl.java @@ -1,32 +1,70 @@ package com.psdc.controller.control; +import com.alibaba.fastjson2.JSONObject; +import com.psdc.core.controller.BaseController; import com.psdc.core.domain.AjaxResult; -import com.psdc.core.domain.R; -import com.psdc.core.domain.entity.SysRole; import com.psdc.core.domain.entity.SysUser; -import com.psdc.utils.StringUtils; +import com.psdc.core.page.TableDataInfo; +import com.psdc.domain.SysConfig; +import com.psdc.entity.PsdcControlLog; +import com.psdc.entity.vo.DeviceStatusVo; +import com.psdc.service.IPsdcControlLogService; +import com.psdc.service.IPsdcDeviceService; +import org.aspectj.weaver.loadtime.Aj; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; -import java.util.stream.Collectors; +import java.util.Map; + @RestController @RequestMapping("/control/manual") -public class ManualControl { +public class ManualControl extends BaseController { + @Autowired + private IPsdcDeviceService psdcDeviceService; - @PreAuthorize("@ss.hasPermi('control:user:query')") - @GetMapping("/deviceList") - public AjaxResult getControlDeviceList() { + @Autowired + private IPsdcControlLogService psdcControlLogService; - return ajax; + /** + * 查询设备状态列表 + * @return + */ + @PreAuthorize("@ss.hasPermi('control:manual:devlist')") + @GetMapping("/deviceStatusList") + public AjaxResult getControlDeviceList() { + List deviceStatusVos = psdcDeviceService.queryDeviceStatus(); + return AjaxResult.success("设备状态列表",deviceStatusVos); } + /** + * 控制设备启停 + * @param jsonObject + * @return + */ + @PreAuthorize("@ss.hasPermi('control:manual:startstop')") + @PostMapping("/startAndStop") + public AjaxResult deviceStartAndStop(@RequestBody JSONObject jsonObject){ + int i = psdcDeviceService.controlDeviceStartAndStop(jsonObject.getInteger("deviceId"), jsonObject.getInteger("runStatus")); + if ( i == 1){ + return AjaxResult.success("控制成功"); + } else { + return AjaxResult.error("控制失败,请联系管理员"); + } + } - + /** + * 获取调控日志列表 + */ + @PreAuthorize("@ss.hasPermi('control:timer:controlLogList')") + @GetMapping("/controlLogList") + public TableDataInfo controlLogList(PsdcControlLog psdcControlLog) { + startPage(); + List list = psdcControlLogService.query(psdcControlLog); + return getDataTable(list); + } }