Merge remote-tracking branch 'origin/master'

master
魔神煜修罗皇 2 years ago
commit 8990f9aacd
  1. 6
      psdc-business/src/main/java/com/psdc/mapper/PsdcTimerMapper.java
  2. 4
      psdc-business/src/main/java/com/psdc/service/impl/PsdcControlLogServiceImpl.java
  3. 124
      psdc-business/src/main/java/com/psdc/service/impl/PsdcTimerServiceImpl.java
  4. 2
      psdc-business/src/main/resources/mapper/business/PsdcTimerMapper.xml
  5. 134
      psdc-ui/src/views/analyse/nhfx/index.vue
  6. 1
      psdc-ui/src/views/control/timer/index.vue

@ -21,7 +21,7 @@ public interface PsdcTimerMapper{
* @param timerId 主键
* @return 实例对象
*/
PsdcTimer queryById(Integer timerId);
PsdcTimer queryById(@Param("timerId") Integer timerId);
/**
* 通过ID查询单条数据
@ -29,7 +29,7 @@ public interface PsdcTimerMapper{
* @param timerId 主键
* @return 实例对象
*/
PsdcTimerVo queryById2(Integer timerId);
PsdcTimerVo queryById2(@Param("timerId") Integer timerId);
/**
* 分页查询指定行数据
*
@ -71,5 +71,5 @@ public interface PsdcTimerMapper{
* @param timerId 主键
* @return 影响行数
*/
int deleteById(Integer timerId);
int deleteById(@Param("timerId") Integer timerId);
}

@ -23,6 +23,7 @@ public class PsdcControlLogServiceImpl implements IPsdcControlLogService {
* @param controlLogId 主键
* @return 实例对象
*/
@Override
public PsdcControlLog queryById(Integer controlLogId){
return psdcControlLogMapper.queryById(controlLogId);
}
@ -35,6 +36,7 @@ public class PsdcControlLogServiceImpl implements IPsdcControlLogService {
* @param psdcControlLog 实例对象
* @return 实例对象
*/
@Override
public PsdcControlLog insert(PsdcControlLog psdcControlLog){
psdcControlLogMapper.insert(psdcControlLog);
return psdcControlLog;
@ -46,6 +48,7 @@ public class PsdcControlLogServiceImpl implements IPsdcControlLogService {
* @param psdcControlLog 实例对象
* @return 实例对象
*/
@Override
public PsdcControlLog update(PsdcControlLog psdcControlLog){
psdcControlLogMapper.update(psdcControlLog);
return queryById(psdcControlLog.getControlLogId());
@ -57,6 +60,7 @@ public class PsdcControlLogServiceImpl implements IPsdcControlLogService {
* @param controlLogId 主键
* @return 是否成功
*/
@Override
public boolean deleteById(Integer controlLogId){
int total = psdcControlLogMapper.deleteById(controlLogId);
return total > 0;

@ -25,10 +25,13 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
/**
* 定时控制任务表;(psdc_timer)表服务实现类
*
* @date : 2023-5-10
*/
@Service
@ -50,19 +53,20 @@ public class PsdcTimerServiceImpl implements IPsdcTimerService {
* @param timerId 主键
* @return 实例对象
*/
public PsdcTimerVo queryById(Integer timerId){
@Override
public PsdcTimerVo queryById(Integer timerId) {
return psdcTimerMapper.queryById2(timerId);
}
/**
* 新增数据
*
* @param psdcTimer 实例对象
* @return 实例对象
*/
public PsdcTimer insert(PsdcTimer psdcTimer){
@Override
public PsdcTimer insert(PsdcTimer psdcTimer) {
psdcTimerMapper.insert(psdcTimer);
return psdcTimer;
}
@ -73,7 +77,8 @@ public class PsdcTimerServiceImpl implements IPsdcTimerService {
* @param psdcTimer 实例对象
* @return 实例对象
*/
public PsdcTimerVo update(PsdcTimer psdcTimer){
@Override
public PsdcTimerVo update(PsdcTimer psdcTimer) {
psdcTimerMapper.update(psdcTimer);
return queryById(psdcTimer.getTimerId());
}
@ -84,7 +89,8 @@ public class PsdcTimerServiceImpl implements IPsdcTimerService {
* @param timerId 主键
* @return 是否成功
*/
public boolean deleteById(Integer timerId){
@Override
public boolean deleteById(Integer timerId) {
int total = psdcTimerMapper.deleteById(timerId);
return total > 0;
}
@ -92,124 +98,135 @@ public class PsdcTimerServiceImpl implements IPsdcTimerService {
@Override
public List<PsdcTimerVo> query(PsdcTimerRequest psdcTimerRequest) {
psdcTimerRequest.setUserId(SecurityUtils.getUserId());
return psdcTimerMapper.queryAllByLimit(psdcTimerRequest);
List<PsdcTimerVo> psdcTimerVos = psdcTimerMapper.queryAllByLimit(psdcTimerRequest);
for (PsdcTimerVo psdcTimerVo : psdcTimerVos) {
if ("startandstop".equals(psdcTimerVo.getControlKey())) {
if ("1".equals(psdcTimerVo.getControlValue())) {
psdcTimerVo.setControlValue("开启");
} else {
psdcTimerVo.setControlValue("关闭");
}
}
}
return psdcTimerVos;
}
/**
* 创建定时任务
*
* @param psdcTimerRunTimeRequest 请求类
* @return int
*/
@Override
@Transactional
public Integer addTimer(PsdcTimerRunTimeRequest psdcTimerRunTimeRequest) {
//获取psdcTimerRunTimeRequest中的timeList数组,根据内容拼出cron表达式
// 获取psdcTimerRunTimeRequest中的timeList数组,根据内容拼出cron表达式
String runDay = psdcTimerRunTimeRequest.getRunday();
String runtime = psdcTimerRunTimeRequest.getRuntime();
//设置cron表达式
// 设置cron表达式
String[] cronArr = new String[7];
//秒,默认为每分钟的0秒
if (runtime == null || !runtime.contains(":") ){
throw new ServiceException("设定执行时间错误,创建定时任务失败,设定时间为:"+runtime);
// 秒,默认为每分钟的0秒
if (runtime == null || !runtime.contains(":")) {
throw new ServiceException("设定执行时间错误,创建定时任务失败,设定时间为:" + runtime);
}
if (runDay == null || "".equals(runDay)) {
throw new ServiceException("设定日期错误,创建定时任务失败,设定日期为:" + runDay);
}
Integer deviceId = psdcTimerRunTimeRequest.getDeviceId();
PsdcDevice psdcDevice = psdcDeviceService.queryById(deviceId);
if(psdcDevice == null){
if (psdcDevice == null) {
throw new ServiceException("创建定时任务失败,未找到该设备");
}
if (psdcDevice.getIsControl() != 2 ){
if (psdcDevice.getIsControl() != 2) {
throw new ControlException("该设备无法控制,请联系管理员");
}
String[] split1 = runtime.split(":");
cronArr[0] = "0";
//分
//
cronArr[1] = split1[1];
//时
//
cronArr[2] = split1[0];
/*
接下来拼装日月或周只有三种情况
*/
if(runDay.equals("0")){
//每天的情况
//日
if (runDay.equals("0")) {
// 每天的情况
//
cronArr[3] = "*";
//月
//
cronArr[4] = "*";
//周
//
cronArr[5] = "?";
} else if (runDay.length() == 10 && (runDay.contains("-"))) {
//设定日期情况,就是一次的情况
// 设定日期情况,就是一次的情况
String[] split = runDay.split("-");
//日
//
cronArr[3] = split[2];
//月
//
cronArr[4] = split[1];
//周
//
cronArr[5] = "?";
} else if (runDay.contains(",")) {
//设定星期情况
// 设定星期情况
String[] split = runDay.split("-");
//日
//
cronArr[3] = "?";
//月
//
cronArr[4] = "*";
//周
cronArr[5] = StringUtils.join(split,",");
//
cronArr[5] = StringUtils.join(split, ",");
} else {
throw new ServiceException("设定日期错误,创建定时任务失败,设定日期为:" + runDay);
}
//年,。暂时不用
// 年,。暂时不用
// cronArr[6] =
String cron = StringUtils.join(cronArr, " ");
log.info("cron表达式:{}",cron);
log.info("cron表达式:{}", cron);
try {
/*
创建job对象往quartz中插入执行的任务拿到jobId
*/
SysJob job = new SysJob();
//设备id + 控制键 + 控制值 + 控制日期 + 控制时间 +
// 设备id + 控制键 + 控制值 + 控制日期 + 控制时间 +
String jobName = psdcTimerRunTimeRequest.getDeviceId() + "+" + ControlKeyEnum.getControlContext(psdcTimerRunTimeRequest.getControlKey()) + "-" +
psdcTimerRunTimeRequest.getControlValue() + "+" + psdcTimerRunTimeRequest.getRunday() + "+" + psdcTimerRunTimeRequest.getRuntime() + "+" + System.currentTimeMillis();
job.setJobName(jobName);
//默认
// 默认
job.setJobGroup("psdc");
String controlKey = psdcTimerRunTimeRequest.getControlKey();
String jobClassName = "";
//判断控制指令
if (controlKey.equals( "startandstop")){
//控制启停
// 判断控制指令
if (controlKey.equals("startandstop")) {
// 控制启停
log.info("控制设备启停");
jobClassName = String.format("psdcDeviceServiceImpl.controlDeviceStartAndStop(%d,%d,'%s',%d))",psdcTimerRunTimeRequest.getDeviceId(),Integer.valueOf(psdcTimerRunTimeRequest.getControlValue()),SecurityUtils.getUsername(),2);
} else if (controlKey.equals( "intemp") || controlKey.equals( "outtemp") || controlKey.equals( "temp") ) {
//控制温度
jobClassName = String.format("psdcDeviceServiceImpl.setTemperature(%d,'%s','%s','%s',%d))",psdcTimerRunTimeRequest.getDeviceId(),controlKey,psdcTimerRunTimeRequest.getControlValue(),SecurityUtils.getUsername(),2);
jobClassName = String.format("psdcDeviceServiceImpl.controlDeviceStartAndStop(%d,%d,'%s',%d))", psdcTimerRunTimeRequest.getDeviceId(), Integer.valueOf(psdcTimerRunTimeRequest.getControlValue()), SecurityUtils.getUsername(), 2);
} else if (controlKey.equals("intemp") || controlKey.equals("outtemp") || controlKey.equals("temp")) {
// 控制温度
jobClassName = String.format("psdcDeviceServiceImpl.setTemperature(%d,'%s','%s','%s',%d))", psdcTimerRunTimeRequest.getDeviceId(), controlKey, psdcTimerRunTimeRequest.getControlValue(), SecurityUtils.getUsername(), 2);
}
job.setInvokeTarget(jobClassName);
//cron表达式
// cron表达式
job.setCronExpression(cron);
//执行错误放弃执行
// 执行错误放弃执行
job.setMisfirePolicy("3");
//是否并发,不并发
// 是否并发,不并发
job.setConcurrent("1");
job.setCreateBy(SecurityUtils.getUsername());
int i = jobService.insertJob(job);
SysJob job1 = null;
if( i > 0){
if (i > 0) {
job1 = jobService.selectJobByName(jobName);
} else {
throw new ServiceException("创建定时任务失败,请联系管理员");
}
//将创建的任务插入psdcTimer表
// 将创建的任务插入psdcTimer表
PsdcTimer psdcTimer = new PsdcTimer();
BeanUtils.copyProperties(psdcTimerRunTimeRequest,psdcTimer);
BeanUtils.copyProperties(psdcTimerRunTimeRequest, psdcTimer);
psdcTimer.setUserId(SecurityUtils.getUserId().intValue());
psdcTimer.setControlContext( ControlKeyEnum.getControlContext(psdcTimerRunTimeRequest.getControlKey()));
psdcTimer.setControlContext(ControlKeyEnum.getControlContext(psdcTimerRunTimeRequest.getControlKey()));
psdcTimer.setCronText(cron);
psdcTimer.setJobId(job1.getJobId().intValue());
psdcTimer.setTimerStatus(Integer.valueOf(job1.getStatus()));
@ -222,21 +239,20 @@ public class PsdcTimerServiceImpl implements IPsdcTimerService {
}
}
@Override
@Transactional
public int updateStatus(Integer timerId, Integer status) throws SchedulerException {
//获取jobId
// 获取jobId
PsdcTimer psdcTimer = psdcTimerMapper.queryById(timerId);
//修改quartz状态
// 修改quartz状态
SysJob job = new SysJob();
job.setStatus(status.toString());
job.setJobId(psdcTimer.getJobId().longValue());
job.setJobGroup("psdc");
int i = jobService.changeStatus(job);
if (i > 0){
if (i > 0) {
return psdcTimerMapper.updateStatus(timerId, status);
} else {
throw new ServiceException("修改定时任务状态失败");
@ -246,14 +262,14 @@ public class PsdcTimerServiceImpl implements IPsdcTimerService {
@Override
@Transactional
public Integer delete(Integer timerId) throws SchedulerException {
//获取jobId
// 获取jobId
PsdcTimer psdcTimer = psdcTimerMapper.queryById(timerId);
//删除quartz任务
// 删除quartz任务
SysJob job = new SysJob();
job.setJobId(psdcTimer.getJobId().longValue());
job.setJobGroup("psdc");
int i = jobService.deleteJob(job);
if (i > 0){
if (i > 0) {
return psdcTimerMapper.deleteById(timerId);
} else {
throw new ServiceException("删除定时任务失败");

@ -54,7 +54,7 @@
</select>
<!--分页查询指定行数据-->
<select id="queryAllByLimit" resultMap="PsdcTimerMap">
<select id="queryAllByLimit" resultMap="PsdcTimerVoMap">
select
pt.timer_id,pt.device_id,pd.device_name,pt.user_id,pt.runday,pt.runtime,pt.control_key,pt.control_context,pt.control_value,pt.cron_text,pt.job_id,pt.timer_status,pt.create_by,pt.create_time,pt.update_by,pt.update_time
from psdc_timer pt left join psdc_device pd on pt.device_id = pd.device_id

@ -15,8 +15,8 @@
<el-form-item><el-button type="primary" icon="Search" @click="handleQuery1">查询</el-button></el-form-item>
</el-form>
<div class="chartBox" ref="container">
<div v-show="isShow1" id="tongbiChart" ref="div"></div>
<el-empty v-show="isShow2" description="暂无数据" ref="el-empty"/>
<div v-show="isShow1" id="tongbiChart"></div>
<el-empty v-show="isShow2" description="暂无数据"/>
</div>
<div class="tableBox1">
<el-table :data="tbfxDataTable" height="345px">
@ -49,7 +49,7 @@
<el-table-column label="环比(%)" align="center" prop="compute"/>
<el-table-column label="操作" align="center">
<template v-slot="scope">
<el-button type="primary" size="small" :icon="Histogram" @click="handleChart">图表</el-button>
<el-button type="primary" size="small" :icon="Histogram" @click="handleChart(scope)">图表</el-button>
</template>
</el-table-column>
</el-table>
@ -79,6 +79,8 @@
</template>
<script setup name="Index">
import {Histogram} from '@element-plus/icons-vue'
import {ref, reactive, onMounted, nextTick, onBeforeUnmount} from "vue";
import { getHuanbiFx,getTongbiFx } from "@/api/analyse/nhfx/nhfx"
@ -209,8 +211,6 @@ function getTongbiFxFun(){
}
let tongbiChart;
function tongbiChartFun(){
console.log('echart数据本期:',tongbiBenqi.value)
console.log('echart数据同期:',tongbiTongqi.value)
const chartDom = document.getElementById('tongbiChart')
tongbiChart = echarts.init(chartDom);
const option = {
@ -230,7 +230,7 @@ function tongbiChartFun(){
show: true,
top: '20%',
bottom:'6%',
left:'2%',
left:'3%',
right:'2%',
borderWidth: 1,
borderColor: '#767da1',
@ -413,6 +413,7 @@ const dateType = ref('date')
const format = ref('YYYY-MM-DD')
const valueFormat = ref('YYYY-MM-DD')
const timeType = ref(1)
const echartLegend = ref([])
//
function handleDaily(){
activeIndex.value = 0;
@ -425,6 +426,7 @@ function handleDaily(){
valueFormat.value = 'YYYY-MM-DD'
timeType.value = 1
dateValue2.value = `${year}-${month}-${day}`
echartLegend.value = ['当日','上日']
console.log(dateValue2.value)
getHuanbiFxFun()
}
@ -440,6 +442,7 @@ function handleMonthly(){
valueFormat.value = 'YYYY-MM'
timeType.value = 2
dateValue2.value = `${year}-${month}`
echartLegend.value = ['本月','上月']
console.log(dateValue2.value)
getHuanbiFxFun()
}
@ -481,9 +484,16 @@ function getHuanbiFxFun(){
/** 生成图表按鈕操作*/
const title = ref()
const open = ref(false)
function handleChart(){
//
const lastMonthData = ref([])
const thisMonthData = ref([])
function handleChart(scope){
open.value = true;
lastMonthData.value = scope.row.lastMonthTotal
thisMonthData.value = scope.row.thisMonthTotal
setTimeout(()=>{
huanbiChartFun()
},100)
};
//
@ -491,13 +501,115 @@ function close(){
open.value = false;
}
/** echart处理*/
let huanbiChart;
function huanbiChartFun(){
dateValue2.value = dateValue2.value.toString()
console.log('X轴:',dateValue2.value)
console.log('本月:',thisMonthData.value,'上月:',lastMonthData.value)
const chartDom = document.getElementById('huanbiChart')
tongbiChart = echarts.init(chartDom);
const option = {
legend: {
data: echartLegend.value,
// selectedMode: 'single',
textStyle: {
color: "#333"
}
},
tooltip: {
trigger: "axis",
// borderColor: '#00fcff',
borderWidth: 1
},
grid:{
show: true,
top: '20%',
bottom:'6%',
left:'4%',
right:'3%',
borderWidth: 1,
borderColor: '#767da1',
},
xAxis: {
type: 'category',
name:'',
data: [dateValue2.value],
nameTextStyle: {
color: "#333",
nameLocation: "start"
},
axisLabel: {
textStyle: {
color: "#333"
}
},
axisLine: {
lineStyle: {
color: '#767da1' // x线
}
},
axisTick: {
show: false // x
},
splitArea: {
show: true,
interval:0,
areaStyle: {
color: ['rgb(54,68,148,.8)', 'rgb(37,51,133,.8)'] //
//
}
}
},
yAxis: {
type: 'value',
name:'kWh',
nameTextStyle: {
color: "#333",
nameLocation: "start"
},
axisLabel: {
textStyle: {
color: "#333"
}
},
splitLine: {
show: true,
lineStyle: {color: "#767da1", type: "solid"} //dashed
} //s线
},
series: [
{
name: echartLegend.value[0],
data: thisMonthData.value,
type: 'bar',
smooth: true,
symbol: "none", //
itemStyle: { //线
color: 'rgba(51,221,223)',
},
},
{
name: echartLegend.value[1],
data: lastMonthData.value,
type: 'bar',
smooth: true,
symbol: "none", //
itemStyle: { //线
color: 'rgba(182,162,222)',
},
},
],
};
option && tongbiChart.setOption(option);
}
/** 页面销毁时*/
onBeforeUnmount(() => {
tongbiChart.dispose(); //
// huanbiChart.dispose();
huanbiChart.dispose();
});
</script>
@ -561,7 +673,9 @@ onBeforeUnmount(() => {
.floatRight{
margin-left: 90%;
}
::v-deep .el-dialog{
background-color: rgba(47,61,138) !important;
}
::v-deep .el-tabs__item{
color: #fff;

@ -55,6 +55,7 @@
<el-table-column label="执行日期" align="center" prop="runday"/>
<el-table-column label="执行时间" align="center" prop="runtime"/>
<el-table-column label="创建时间" align="center" prop="createTime"/>
<el-table-column label="创建者" align="center" prop="createBy"/>
<el-table-column label="操作" align="center" prop="handle">
<template v-slot="scope">
<el-button type="danger" size="small" :icon="Delete" @click="getDeleteTimerFun(scope)">删除</el-button>

Loading…
Cancel
Save