Browse Source

定时报

master
blankk 2 years ago
parent
commit
493299cffd
  1. 39
      ruoyi-api/src/main/java/com/ruoyi/api/app/RegularTimeController.java
  2. 66
      ruoyi-api/src/main/java/com/ruoyi/api/domain/RegularTime.java
  3. 17
      ruoyi-api/src/main/java/com/ruoyi/api/mapper/RegularTimeMapper.java
  4. 22
      ruoyi-api/src/main/java/com/ruoyi/api/service/IRegularTimeService.java
  5. 34
      ruoyi-api/src/main/java/com/ruoyi/api/service/impl/RegularTimeServiceImpl.java
  6. 53
      ruoyi-api/src/main/java/com/ruoyi/api/util/RegularTimeUtil.java

39
ruoyi-api/src/main/java/com/ruoyi/api/app/RegularTimeController.java

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
package com.ruoyi.api.app;
import com.ruoyi.api.domain.RegularTime;
import com.ruoyi.api.service.IRegularTimeService;
import com.ruoyi.api.util.RegularTimeUtil;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.R;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* 定时报Controller
*
* @author ruoyi
* @date 2022-09-23
*/
@RestController
@RequestMapping("/api/regular/time")
public class RegularTimeController extends BaseController
{
@Resource
private IRegularTimeService regularTimeService;
/**
* 新增
*/
@RequestMapping("/add")
public R add(String asciiCode){
if (StringUtils.isEmpty(asciiCode)){
return R.error("asciiCode不能为空!");
}
RegularTime regularTime = RegularTimeUtil.hourlyReportASCII(asciiCode);
regularTimeService.save(regularTime);
return R.ok();
}
}

66
ruoyi-api/src/main/java/com/ruoyi/api/domain/RegularTime.java

@ -0,0 +1,66 @@ @@ -0,0 +1,66 @@
package com.ruoyi.api.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
/**
* 定时报对象 regular_time
*
* @author ruoyi
* @date 2022-09-23
*/
@Data
@TableName("regular_time")
public class RegularTime implements Serializable
{
private static final long serialVersionUID = 1L;
/** id */
@TableId(type = IdType.INPUT)
private Long id;
/** 中心站地址 */
private String centralStationAddr;
/** 遥测站地址 */
private String stationAddr;
/** 密码 */
private String password;
/** 功能码 */
private String code;
/** 报文上下行标识和长度 */
private String msgIdAndLength;
/** 流水号 */
private String serialNum;
/** 发报时间 */
private String dispatchTime;
/** 遥测站分类码 */
private String stationTypeCode;
/** 观测时间 */
private String observationTime;
/** 瞬时水位 */
private String waterLevel;
/** 电压 */
private String voltage;
/** 温度 */
private String temperature;
/** 校验 */
private String checkCode;
}

17
ruoyi-api/src/main/java/com/ruoyi/api/mapper/RegularTimeMapper.java

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
package com.ruoyi.api.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import com.ruoyi.api.domain.RegularTime;
/**
* Mapper接口
*
* @author ruoyi
* @date 2022-09-23
*/
@Mapper
public interface RegularTimeMapper extends BaseMapper<RegularTime>
{
}

22
ruoyi-api/src/main/java/com/ruoyi/api/service/IRegularTimeService.java

@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
package com.ruoyi.api.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.api.domain.RegularTime;
import com.ruoyi.common.core.page.R;
import java.util.Map;
/**
* Service接口
*
* @author ruoyi
* @date 2022-09-23
*/
public interface IRegularTimeService extends IService<RegularTime>
{
/**
* 查询
*/
R queryPage(Map<String, Object> params);
}

34
ruoyi-api/src/main/java/com/ruoyi/api/service/impl/RegularTimeServiceImpl.java

@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
package com.ruoyi.api.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.api.domain.RegularTime;
import com.ruoyi.api.mapper.RegularTimeMapper;
import com.ruoyi.api.service.IRegularTimeService;
import com.ruoyi.common.core.page.R;
import com.ruoyi.common.utils.Query;
import org.springframework.stereotype.Service;
import java.util.Map;
/**
* Service业务层处理
*
* @author ruoyi
* @date 2022-09-23
*/
@Service("regularTimeService")
public class RegularTimeServiceImpl extends ServiceImpl<RegularTimeMapper, RegularTime> implements IRegularTimeService
{
@Override
public R queryPage(Map<String, Object> params) {
IPage<RegularTime> page = this.page(
new Query<RegularTime>().getPage(params),
new QueryWrapper<RegularTime>()
);
return R.ok().put("count", page.getTotal()).put("data", page.getRecords());
}
}

53
ruoyi-api/src/main/java/com/ruoyi/api/util/RegularTimeUtil.java

@ -0,0 +1,53 @@ @@ -0,0 +1,53 @@
package com.ruoyi.api.util;
import com.ruoyi.api.domain.RegularTime;
public class RegularTimeUtil {
// 每天整点报 整点 ASCII
public static RegularTime hourlyReportASCII(String asciiCode) {
RegularTime regularTime = new RegularTime();
String[] strArr = asciiCode.split(" ");
String s1 = strArr[0];
// 中心站地址
String centralStationAddr = s1.substring(0, 2);
regularTime.setCentralStationAddr(centralStationAddr);
// 遥测站地址
String stationAddr = s1.substring(2, 12);
regularTime.setStationAddr(stationAddr);
// 密码
String password = s1.substring(12, 16);
regularTime.setPassword(password);
//功能码
String code = s1.substring(16, 18);
regularTime.setCode(code);
//报文上下行标识和长度 报文标识和长度
String msgIDAndLength = s1.substring(18, 22);
regularTime.setMsgIdAndLength(msgIDAndLength);
// 流水号
String serialNum = s1.substring(22, 26);
regularTime.setSerialNum(serialNum);
// 发报时间
String dispatchTime = s1.substring(26, 38);
regularTime.setDispatchTime(dispatchTime);
// 遥测站分类码
String stationTypeCode = strArr[2];
regularTime.setStationTypeCode(stationTypeCode);
// 观测时间
String observationTime = strArr[4];
regularTime.setObservationTime(observationTime);
// 瞬时水位
String waterLevel = strArr[6];
regularTime.setWaterLevel(waterLevel);
// 电压
String voltage = strArr[8];
regularTime.setVoltage(voltage);
// 温度
String temperature = strArr[10];
regularTime.setTemperature(temperature);
// 校验
String checkCode = strArr[11];
regularTime.setCheckCode(checkCode);
return regularTime;
}
}
Loading…
Cancel
Save