闸阀调节时生成操作日志;闸阀操作日志分页查询及导出

master
wany 2024-07-24 14:57:10 +08:00
parent f4f5109398
commit d683fa2792
6 changed files with 244 additions and 7 deletions

View File

@ -1,7 +1,10 @@
package com.gunshi.project.xyt.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gunshi.core.result.R;
import com.gunshi.project.xyt.entity.so.GateHisPageSo;
import com.gunshi.project.xyt.entity.vo.GateStautsVo;
import com.gunshi.project.xyt.entity.vo.GateValveOplogVo;
import com.gunshi.project.xyt.model.GateValveKey;
import com.gunshi.project.xyt.model.GateValveReal;
import com.gunshi.project.xyt.service.GateValveRealService;
@ -11,6 +14,7 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@ -70,12 +74,16 @@ public class GateValveRealController {
return R.ok(service.control(gateValveKey));
}
// @Operation(summary = "分页")
// @PostMapping("/page")
public R<List<GateValveReal>> page() {
return R.ok(service.page(null,null));
@Operation(summary = "闸阀操作日志-分页")
@PostMapping("/log/page")
public R<Page<GateValveOplogVo>> logPage(@RequestBody GateHisPageSo so) {
return R.ok(service.logPage(so));
}
@Operation(summary = "闸阀操作日志-导出")
@PostMapping("/log/export")
public void logExport(@RequestBody GateHisPageSo so, HttpServletResponse response) {
service.logExport(so,response);
}
}

View File

@ -0,0 +1,64 @@
package com.gunshi.project.xyt.entity.vo;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.gunshi.core.dateformat.DateFormatString;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.Date;
/**
* Description:
* Created by wanyan on 2024/7/19
*
* @author wanyan
* @version 1.0
*/
@Data
public class GateValveOplogVo {
@Schema(description="闸阀ID")
@ExcelIgnore
private String valveCode;
/**
*
*/
@Schema(description="闸阀名称")
@ExcelProperty({"闸阀名称"})
@ColumnWidth(20)
private String valveName;
/**
*
*/
@Schema(description="操作人")
@ExcelProperty({"操作人"})
private String opUserName;
/**
*
*/
@Schema(description="操作时间")
@ExcelProperty({"操作时间"})
@ColumnWidth(25)
@JsonFormat(pattern = DateFormatString.YYYY_MM_DD_HH_MM_SS, timezone = "GMT+8")
private Date tm;
@Schema(description="操作内容")
@ExcelProperty({"操作内容"})
@ColumnWidth(20)
private String opContent;
@Schema(description="设定开度")
@ExcelProperty({"设定开度"})
private String status;
@Schema(description="操作前开度")
@ExcelProperty({"操作前开度"})
private String beforeStatus;
}

View File

@ -1,7 +1,10 @@
package com.gunshi.project.xyt.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gunshi.project.xyt.entity.so.GateHisPageSo;
import com.gunshi.project.xyt.entity.vo.GateStautsVo;
import com.gunshi.project.xyt.entity.vo.GateValveOplogVo;
import com.gunshi.project.xyt.model.GateValveReal;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -35,4 +38,42 @@ public interface GateValveRealMapper extends BaseMapper<GateValveReal> {
</script>
""")
BigDecimal realQ(@Param("valveCode") String valveCode);
@Select("""
<script>
select t.valve_code,t.tm,t.op_content,t.op_user_name,
s.valve_name,case when t.status = '100%' then '' when t.status = '0%' then '关' else t.status end as status,
case when t.before_status = '100%' then '' when t.before_status = '0%' then '关' else t.before_status end as beforeStatus
from public.gate_valve_oplog t
left join public.att_gate_valve s on t.valve_code = s.valve_code
where t.valve_code = #{obj.valveCode}
<if test="obj.dateTimeRangeSo != null and obj.dateTimeRangeSo.start != null">
and t.tm <![CDATA[>=]]> #{obj.dateTimeRangeSo.start}
</if>
<if test="obj.dateTimeRangeSo != null and obj.dateTimeRangeSo.end != null">
and t.tm <![CDATA[<=]]> #{obj.dateTimeRangeSo.end}
</if>
order by t.tm desc nulls last
</script>
""")
Page<GateValveOplogVo> logPage(Page<GateValveOplogVo> page,@Param("obj") GateHisPageSo so);
@Select("""
<script>
select t.valve_code,t.tm,t.op_content,t.op_user_name,
s.valve_name,case when t.status = '100%' then '' when t.status = '0%' then '关' else t.status end as status,
case when t.before_status = '100%' then '' when t.before_status = '0%' then '关' else t.before_status end as beforeStatus
from public.gate_valve_oplog t
left join public.att_gate_valve s on t.valve_code = s.valve_code
where t.valve_code = #{obj.valveCode}
<if test="obj.dateTimeRangeSo != null and obj.dateTimeRangeSo.start != null">
and t.tm <![CDATA[>=]]> #{obj.dateTimeRangeSo.start}
</if>
<if test="obj.dateTimeRangeSo != null and obj.dateTimeRangeSo.end != null">
and t.tm <![CDATA[<=]]> #{obj.dateTimeRangeSo.end}
</if>
order by t.tm desc nulls last
</script>
""")
List<GateValveOplogVo> logList(@Param("obj") GateHisPageSo so);
}

View File

@ -0,0 +1,91 @@
package com.gunshi.project.xyt.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.gunshi.core.dateformat.DateFormatString;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* :
* author: xusan
* date: 2024-07-08 17:34:26
*/
@Schema(description="闸阀操作日志表")
@Data
@TableName("public.gate_valve_oplog")
public class GateValveOplog implements Serializable {
private static final long serialVersionUID = 1L;
/**
*
*/
@TableId(value="id", type= IdType.AUTO)
@Schema(description="主键")
@NotNull(message = "主键不能为空")
@JsonSerialize(using = ToStringSerializer.class)
private Long id;
/**
* ID
*/
@TableField(value="valve_code")
@Schema(description="闸阀ID")
private String valveCode;
/**
*
*/
@TableField(value="status")
@Schema(description="设定开度")
private String status;
/**
*
*/
@TableField(value="before_status")
@Schema(description="操作前开度")
private String beforeStatus;
/**
*
*/
@TableField(value="op_content")
@Schema(description="操作内容")
private String opContent;
/**
* id
*/
@TableField(value="op_user_id")
@Schema(description="操作人id")
private Long opUserId;
/**
*
*/
@TableField(value="op_user_name")
@Schema(description="操作人")
private String opUserName;
/**
*
*/
@TableField(value="tm")
@Schema(description="操作时间")
@JsonFormat(pattern = DateFormatString.YYYY_MM_DD_HH_MM_SS, timezone = "GMT+8")
private Date tm;
}

View File

@ -31,7 +31,7 @@ public class GateValveRService extends ServiceImpl<GateValveRMapper, GateValveR>
public void export(GateHisPageSo so, HttpServletResponse response) {
List<GateStautsVo> list = baseMapper.hisList(so);
ExcelUtil.exportExcel(list,"闸阀历史记录",GateStautsVo.class,response,"闸阀历史记录");
ExcelUtil.exportExcel(list,"闸阀开度历史",GateStautsVo.class,response,"闸阀开度历史");
}
}

View File

@ -1,14 +1,22 @@
package com.gunshi.project.xyt.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gunshi.project.xyt.entity.so.GateHisPageSo;
import com.gunshi.project.xyt.entity.vo.GateStautsVo;
import com.gunshi.project.xyt.entity.vo.GateValveOplogVo;
import com.gunshi.project.xyt.mapper.GateValveRMapper;
import com.gunshi.project.xyt.mapper.GateValveRealMapper;
import com.gunshi.project.xyt.model.GateValveKey;
import com.gunshi.project.xyt.model.GateValveKeyAutoDao;
import com.gunshi.project.xyt.model.GateValveOplog;
import com.gunshi.project.xyt.model.GateValveReal;
import com.gunshi.project.xyt.util.DateUtil;
import com.gunshi.project.xyt.util.ExcelUtil;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -30,6 +38,9 @@ public class GateValveRealService extends ServiceImpl<GateValveRealMapper, GateV
@Resource
private GateValveKeyAutoDao gateValveKeyAutoDao;
@Resource
private com.gunshi.project.xyt.model.GateValveOplogAutoDao gateValveOplogAutoDao;
@Resource
private GateValveRMapper gateValveRMapper;
@ -55,6 +66,19 @@ public class GateValveRealService extends ServiceImpl<GateValveRealMapper, GateV
if(valveKey == null || !key.equals(valveKey.getKey())){
throw new IllegalArgumentException("密码不正确");
}
//生成闸阀操作日志
GateValveOplog oplog = new GateValveOplog();
oplog.setId(IdWorker.getId());
oplog.setStatus(gateValveKey.getStatus());
oplog.setOpContent("设置闸阀开度为"+gateValveKey.getStatus());
oplog.setValveCode(valveCode);
oplog.setTm(new Date());
oplog.setOpUserId(1L);
oplog.setOpUserName("胡兵");
GateValveReal valveReal = this.getOne(new QueryWrapper<GateValveReal>().eq("valve_code", valveCode));
oplog.setBeforeStatus(valveReal == null ? "-" : valveReal.getStatus());
gateValveOplogAutoDao.save(oplog);
//todo 给闸阀下发调节指令
// GateValveR gateValveR = new GateValveR();
// BeanUtils.copyProperties(gateValveKey,gateValveR);
@ -66,7 +90,16 @@ public class GateValveRealService extends ServiceImpl<GateValveRealMapper, GateV
// real.setTm(new Date());
// this.remove(new QueryWrapper<GateValveReal>().eq("valve_code",valveCode));
// this.save(real);
return "调节闸阀指令已下发";
return "调节闸阀成功";
}
public Page<GateValveOplogVo> logPage(GateHisPageSo so) {
return baseMapper.logPage(so.getPageSo().toPage(),so);
}
public void logExport(GateHisPageSo so, HttpServletResponse response) {
List<GateValveOplogVo> logList = baseMapper.logList(so);
ExcelUtil.exportExcel(logList,"闸阀操作日志",GateValveOplogVo.class,response,"闸阀操作日志");
}
}