New file |
| | |
| | | //package com.whyc.aop; |
| | | // |
| | | //import com.whyc.service.OperationLogService; |
| | | //import org.aspectj.lang.JoinPoint; |
| | | //import org.aspectj.lang.annotation.AfterReturning; |
| | | //import org.aspectj.lang.annotation.Aspect; |
| | | //import org.aspectj.lang.annotation.Pointcut; |
| | | //import org.aspectj.lang.reflect.MethodSignature; |
| | | //import org.springframework.beans.factory.annotation.Autowired; |
| | | //import org.springframework.stereotype.Component; |
| | | //import org.springframework.web.context.request.RequestAttributes; |
| | | //import org.springframework.web.context.request.RequestContextHolder; |
| | | //import org.springframework.web.context.request.ServletRequestAttributes; |
| | | // |
| | | //import javax.servlet.http.HttpServletRequest; |
| | | //import java.util.HashMap; |
| | | // |
| | | ///** |
| | | // * spring aop,面向切面; |
| | | // * 切面为Controller |
| | | // * 切点为本类中@PointCut的表达式 |
| | | // * 具体连接点为JoinPoint |
| | | // * 通知方式选用 捕捉异常 |
| | | // */ |
| | | // |
| | | //@Aspect |
| | | //@Component |
| | | //public class ExceptionLogAspect { |
| | | // |
| | | // @Autowired |
| | | // private OperationLogService operationLogService; |
| | | // |
| | | // /** |
| | | // * aop表达式解释: |
| | | // * 第一个*:返回类型,所有类型 |
| | | // * 第二个*:类名,所有类名 |
| | | // * 第三个*:方法名,所有方法 |
| | | // * 第一个..:whyc当前包和子包 |
| | | // */ |
| | | // @Pointcut("execution(public * com.whyc..controller.*.add*(..)) " + |
| | | // "|| execution(public * com.whyc..controller.*.delete*(..)) " + |
| | | // "|| execution(public * com.whyc..controller.*.update*(..))") |
| | | // private void operation(){} |
| | | // |
| | | // @AfterReturning(pointcut = "operation()",returning = "response") |
| | | // public void doAfterReturningOperation(JoinPoint joinPoint,Object response){ |
| | | // |
| | | // ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes(); |
| | | // HttpServletRequest request = requestAttributes.getRequest(); |
| | | // //获取当前Session用户名 |
| | | // String userName = (String) requestAttributes.getAttribute("user", RequestAttributes.SCOPE_SESSION); |
| | | // //获取当前用户ip |
| | | // String currentUserTerminalIp = request.getRemoteAddr(); |
| | | // //执行的类全名 |
| | | // String fullClassName = joinPoint.getSignature().getDeclaringTypeName().toString(); |
| | | // //获取类型 |
| | | // String[] fullClassNameSplit = fullClassName.split("\\."); |
| | | // String className = fullClassNameSplit[fullClassNameSplit.length-1].replace("Controller","模块"); |
| | | // if(fullClassName.contains("app")){ |
| | | // className+="-安卓端"; |
| | | // } |
| | | // //执行的方法 |
| | | // String methodName = joinPoint.getSignature().getName(); |
| | | // String methodType = ""; |
| | | // if(methodName.contains("update")){ |
| | | // methodType = "修改"; |
| | | // }else if(methodName.contains("add")){ |
| | | // methodType ="新增"; |
| | | // }else{ |
| | | // methodType="删除"; |
| | | // } |
| | | // //获取方法的参数 |
| | | // String[] parameterNames = ((MethodSignature) joinPoint.getSignature()).getParameterNames(); |
| | | // Object[] args = joinPoint.getArgs(); |
| | | // |
| | | // HashMap<String, Object> map = new HashMap<>(); |
| | | // for (int i = 0; i < parameterNames.length; i++) { |
| | | // map.put(parameterNames[i],args[i]); |
| | | // } |
| | | // |
| | | // //拼接成操作日志内容 |
| | | // String content = "执行了"+className+"的"+methodType+"操作," + |
| | | // "具体调用方法为:"+methodName+","+ |
| | | // "参数信息为:"+map; |
| | | // operationLogService.record(methodType,content,userName,currentUserTerminalIp); |
| | | // |
| | | // } |
| | | // |
| | | //} |
| | |
| | | |
| | | //拼接成操作日志内容 |
| | | String content = "执行了"+className+"的"+methodType+"操作," + |
| | | "具体调用方法为:"+methodName+","+ |
| | | "参数信息为:"+map; |
| | | operationLogService.record(methodType,content,userName,currentUserTerminalIp); |
| | | "具体调用方法为:"+methodName; |
| | | |
| | | operationLogService.record(methodType,content,map.toString(),userName,currentUserTerminalIp); |
| | | |
| | | } |
| | | |
| | |
| | | public Response delete(@RequestParam int id){ |
| | | return service.delete(id); |
| | | } |
| | | |
| | | /** |
| | | * 检查限制阈值的范围 |
| | | * @return |
| | | */ |
| | | @GetMapping("thresholdValue") |
| | | @ApiOperation(value="查询阈值范围,======接口待完成======") |
| | | public Response getThresholdValueByLevel(@RequestBody AlarmRule alarmRule){ |
| | | return service.getThresholdValueByLevel(alarmRule); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.whyc.controller; |
| | | |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.pojo.AFEInverterControl; |
| | | import com.whyc.pojo.TorqueSensor; |
| | | import com.whyc.service.AFECtrlService; |
| | | import com.whyc.service.TorqueSensorService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | @RestController |
| | | @RequestMapping("torqueSensor") |
| | | @Api(tags = "扭矩传感器") |
| | | public class TorqueSensorController { |
| | | |
| | | @Autowired |
| | | private TorqueSensorService service; |
| | | |
| | | @GetMapping |
| | | @ApiOperation(value = "查询信息-根据设备id") |
| | | public Response<TorqueSensor> getByDevId(@RequestParam Integer devId){ |
| | | return service.getByDevId(devId); |
| | | } |
| | | } |
| | |
| | | |
| | | import com.whyc.pojo.AlarmRule; |
| | | |
| | | import java.util.List; |
| | | |
| | | public interface AlarmRuleMapper extends CustomMapper<AlarmRule> { |
| | | |
| | | List<AlarmRule> getListWithSameThreshold(AlarmRule alarmRule); |
| | | } |
New file |
| | |
| | | package com.whyc.mapper; |
| | | |
| | | public interface TableMapper{ |
| | | |
| | | } |
New file |
| | |
| | | package com.whyc.mapper; |
| | | |
| | | import com.whyc.pojo.TorqueSensor; |
| | | |
| | | public interface TorqueSensorMapper extends CustomMapper<TorqueSensor> { |
| | | } |
| | |
| | | private String type; |
| | | @ApiModelProperty("操作内容") |
| | | private String content; |
| | | @ApiModelProperty("接口传入参数") |
| | | private String param; |
| | | @ApiModelProperty("操作时间") |
| | | @JsonFormat(pattern = "yyyy-MM-dd",timezone = "Asia/Shanghai") |
| | | private Date createTime; |
| | |
| | | private String terminalIp; |
| | | private String userName; |
| | | |
| | | public OperationLog(String type,String content,String terminalIp, String userName) { |
| | | public OperationLog(String type,String content,String param,String terminalIp, String userName) { |
| | | this.type = type; |
| | | this.content = content; |
| | | this.param = param; |
| | | this.createTime = new Date(); |
| | | this.terminalIp = terminalIp; |
| | | this.userName = userName; |
| | |
| | | this.type = type; |
| | | } |
| | | |
| | | public String getParam() { |
| | | return param; |
| | | } |
| | | |
| | | public void setParam(String param) { |
| | | this.param = param; |
| | | } |
| | | |
| | | public String getContent() { |
| | | return content; |
| | | } |
New file |
| | |
| | | package com.whyc.pojo; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import org.apache.ibatis.type.Alias; |
| | | |
| | | import java.util.Date; |
| | | |
| | | @ApiModel(value = "TorqueSensor") |
| | | @Alias("TorqueSensor") |
| | | @TableName( schema = "`db_3.5mw_motor`",value = "tb_torque_senor_rt") |
| | | public class TorqueSensor { |
| | | private Long num; |
| | | private Integer devId; |
| | | private Date recordTime; |
| | | @ApiModelProperty("转矩") |
| | | private Float torque; |
| | | @ApiModelProperty("转速") |
| | | private Float speed; |
| | | private String note; |
| | | |
| | | public Long getNum() { |
| | | return num; |
| | | } |
| | | |
| | | public void setNum(Long num) { |
| | | this.num = num; |
| | | } |
| | | |
| | | public Integer getDevId() { |
| | | return devId; |
| | | } |
| | | |
| | | public void setDevId(Integer devId) { |
| | | this.devId = devId; |
| | | } |
| | | |
| | | public Date getRecordTime() { |
| | | return recordTime; |
| | | } |
| | | |
| | | public void setRecordTime(Date recordTime) { |
| | | this.recordTime = recordTime; |
| | | } |
| | | |
| | | public Float getTorque() { |
| | | return torque; |
| | | } |
| | | |
| | | public void setTorque(Float torque) { |
| | | this.torque = torque; |
| | | } |
| | | |
| | | public Float getSpeed() { |
| | | return speed; |
| | | } |
| | | |
| | | public void setSpeed(Float speed) { |
| | | this.speed = speed; |
| | | } |
| | | |
| | | public String getNote() { |
| | | return note; |
| | | } |
| | | |
| | | public void setNote(String note) { |
| | | this.note = note; |
| | | } |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | public Response add(AlarmRule alarmRule) { |
| | | //查询同一字段,同一个under(过高)或者over(过低),是否已经存在记录 |
| | | //如果存在了记录,则按照 一般,重要,严重区分:一般1,严重2,... |
| | | |
| | | mapper.insert(alarmRule); |
| | | return new Response().setMsg(1,"新增成功"); |
| | | } |
| | |
| | | mapper.deleteById(id); |
| | | return new Response().set(1,"删除成功"); |
| | | } |
| | | |
| | | /** |
| | | * 提前校验,如果库中存在 同 设备&字段&阈值标识 |
| | | * 的数据,则需要根据当前选择的级别,给出阈值 |
| | | * @param alarmRule |
| | | * @return |
| | | */ |
| | | public Response getThresholdValueByLevel(AlarmRule alarmRule) { |
| | | List<AlarmRule> listWithSameThreshold = mapper.getListWithSameThreshold(alarmRule); |
| | | //处理 |
| | | return null; |
| | | } |
| | | } |
| | |
| | | * @param userName |
| | | * @param terminalIp 通过request.getRemoteAddr()获取 |
| | | */ |
| | | public void record(String type,String content,String userName,String terminalIp){ |
| | | OperationLog operationLog = new OperationLog(type,content, terminalIp, userName); |
| | | public void record(String type,String content,String param,String userName,String terminalIp){ |
| | | OperationLog operationLog = new OperationLog(type,content,param,terminalIp, userName); |
| | | mapper.insert(operationLog); |
| | | } |
| | | |
New file |
| | |
| | | package com.whyc.service; |
| | | |
| | | import com.whyc.mapper.TableMapper; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | | * 查询数据库中表相关 |
| | | */ |
| | | @Resource |
| | | public class TableService { |
| | | |
| | | @Resource |
| | | private TableMapper mapper; |
| | | |
| | | } |
New file |
| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.TorqueSensorMapper; |
| | | import com.whyc.pojo.TorqueSensor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | @Service |
| | | public class TorqueSensorService { |
| | | |
| | | @Resource |
| | | private TorqueSensorMapper mapper; |
| | | |
| | | public Response<TorqueSensor> getByDevId(Integer devId) { |
| | | QueryWrapper<TorqueSensor> wrapper = Wrappers.query(); |
| | | wrapper.eq("dev_id",devId); |
| | | TorqueSensor torqueSensor = mapper.selectOne(wrapper); |
| | | return new Response<TorqueSensor>().set(1,torqueSensor); |
| | | } |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.whyc.mapper.AlarmRuleMapper" > |
| | | |
| | | <select id="getListWithSameThreshold" resultType="com.whyc.pojo.AlarmRule"> |
| | | select * from `db_3.5mw_web`.tb_alarm_rule |
| | | where device_flag = #{deviceFlag} |
| | | and field = #{field} |
| | | and threshold_flag = #{thresholdFlag} |
| | | </select> |
| | | </mapper> |
| | |
| | | and create_time <![CDATA[<=]]> #{endTime} |
| | | </if> |
| | | </where> |
| | | order by create_time desc |
| | | </select> |
| | | </mapper> |