Commit 9d8be15d authored by 马33's avatar 马33

新增使用记录模块

parent 49684035
......@@ -90,7 +90,7 @@ public class DeviceController {
@RequestParam(value = "pageSize", defaultValue = "0") int pageSize,
@RequestParam(value = "appName", required = false) String appName,
@RequestParam(value = "userName", required = false) String userName,
@RequestParam(value = "status", required = false) int status) {
@RequestParam(value = "status", required = false) Integer status) {
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(pageNo, pageSize, appName, userName, status);
int total = records.getTotal();
int pages = total / pageSize;//pages为总页数
......
package iot.sixiang.license.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import iot.sixiang.license.entity.PmsUseLog;
import iot.sixiang.license.entity.SysOperLog;
import iot.sixiang.license.log.BusinessType;
import iot.sixiang.license.log.MyLog;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.PageResult;
import iot.sixiang.license.model.vo.DeviceVo;
import iot.sixiang.license.service.PmsUseService;
import iot.sixiang.license.service.SysOperLogService;
import lombok.extern.slf4j.Slf4j;
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;
import java.util.Date;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/iot_license/pms_use_log")
@Api(value = "使用记录模块", tags = {"使用记录模块"})
public class PmsUseLogController {
@Autowired
private PmsUseService pmsUseService;
/**
* 分页查询使用记录
*
* @param pageNo
* @param pageSize
* @return
*/
@ApiOperation(value = "获取使用记录列表接口", notes = "用于获取使用记录列表")
@GetMapping("list")
@MyLog(title = "获取使用记录列表", optParam = "#{pageNo},#{pageSize},#{sn},#{status}", businessType = BusinessType.SELECT)
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNo", value = "当前在第几页", required = true, dataType = "int"),
@ApiImplicitParam(name = "pageSize", value = "每页显示多少条", required = true, dataType = "int"),
@ApiImplicitParam(name = "sn", value = "设备编号"),
@ApiImplicitParam(name = "status", value = "状态 1:成功,0:失败", dataType = "int")
})
public PageResult<PmsUseLog> getPmsUseLogList(@RequestParam(value = "pageNo", defaultValue = "0") int pageNo,
@RequestParam(value = "pageSize", defaultValue = "0") int pageSize,
@RequestParam(value = "sn", required = false) String sn,
@RequestParam(value = "status", required = false) Integer status) {
PageInfoModel<PmsUseLog> records = pmsUseService.getPmsUseLogList(pageNo, pageSize, sn, status);
int total = records.getTotal();
int pages = total / pageSize;//pages为总页数
int mod = total % pageSize;
if (mod != 0) {
pages = pages + 1;
}
List<PmsUseLog> result = records.getResult();
return new PageResult(200, "查找成功", pageNo, pages, total, result);
}
}
......@@ -13,11 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.*;
@Component
......@@ -55,7 +51,7 @@ public class DeviceManager {
public void initDevices() {
allDevice = new HashMap<>();
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(1, 10000, "", "");
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(1, 10000, "", "", null);
List<DeviceVo> deviceList = records.getResult();
for (DeviceVo deviceVo : deviceList) {
......@@ -153,7 +149,7 @@ public class DeviceManager {
}
public PageInfoModel<DeviceDetailVo> getDeviceDetailList(int pageNo, int pageSize, String appName, String userName) {
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(pageNo, pageSize, appName, userName);
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(pageNo, pageSize, appName, userName, null);
List<DeviceVo> deviceVos = records.getResult();
PageInfoModel<DeviceDetailVo> detailVoPageInfoModel = new PageInfoModel<>();
List<DeviceDetailVo> detailVos = new ArrayList<>();
......@@ -172,7 +168,7 @@ public class DeviceManager {
int status = session.getStatus();
String online = session.getOnline();
String offline = session.getOffline();
detailVo.setStatus(status);
detailVo.setCurStatus(status);
detailVo.setOnline(online);
detailVo.setOffline(offline);
......
......@@ -37,6 +37,9 @@ public class Device implements Serializable {
@ApiModelProperty("应用Id")
private String appId;
@ApiModelProperty("应用Id")
private Integer status;
@ApiModelProperty("创建时间")
private Date createTime;
......
......@@ -13,7 +13,7 @@ import java.util.List;
* @since 2022-06-08
*/
public interface DeviceMapper extends BaseMapper<Device> {
List<DeviceVo> getDeviceList(String appName, String userName, int status);
List<DeviceVo> getDeviceList(String appName, String userName, Integer status);
boolean addDevice(String sn, String appId);
}
......@@ -2,6 +2,9 @@ package iot.sixiang.license.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import iot.sixiang.license.entity.PmsUseLog;
import iot.sixiang.license.model.vo.DeviceVo;
import java.util.List;
/**
* Created by M=54G
......@@ -9,4 +12,5 @@ import iot.sixiang.license.entity.PmsUseLog;
* Description
*/
public interface PmsUseLogMapper extends BaseMapper<PmsUseLog> {
List<PmsUseLog> getPmsUseLogList(String sn, Integer status);
}
......@@ -8,7 +8,7 @@ import lombok.Data;
public class DeviceDetailVo extends DeviceVo {
@ApiModelProperty("当前状态,0 offline,1 online")
private int status;
private int curStatus;
@ApiModelProperty("上线时间")
private String online;
......
......@@ -29,7 +29,7 @@ public class DeviceVo implements Serializable {
private String snBind;
@ApiModelProperty("状态 0:未使用,1:已使用,2:失效")
private String status;
private Integer status;
@ApiModelProperty("设备状态 0:正常 1:禁用")
private int blackFlag;
......
......@@ -12,7 +12,7 @@ import iot.sixiang.license.model.vo.DeviceVo;
* @since 2022-06-08
*/
public interface DeviceService extends IService<Device> {
PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName, int status);
PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName, Integer status);
boolean addDevice(String appId, int count);
}
package iot.sixiang.license.service;
import iot.sixiang.license.entity.PmsUseLog;
import iot.sixiang.license.model.PageInfoModel;
/**
* Created by M=54G
* Date 11/23/22 3:09 PM
......@@ -11,4 +14,6 @@ public interface PmsUseService {
void createFailUseLog(String sn, String message);
void success(int useLogId);
PageInfoModel<PmsUseLog> getPmsUseLogList(int pageNo, int pageSize, String sn, Integer status);
}
......@@ -32,7 +32,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
private DeviceMapper deviceMapper;
@Override
public PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName, int status) {
public PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName, Integer status) {
if (pageNo == 0 || pageSize == 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
}
......
package iot.sixiang.license.service.impl;
import iot.sixiang.license.consts.ResultCode;
import iot.sixiang.license.entity.PmsUseLog;
import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.mapper.PmsUseLogMapper;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.vo.DeviceVo;
import iot.sixiang.license.service.PmsUseService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* Created by M=54G
......@@ -40,6 +48,23 @@ public class PmsUseServiceImpl implements PmsUseService {
pmsUseLogMapper.updateById(pmsUseLog);
}
@Override
public PageInfoModel<PmsUseLog> getPmsUseLogList(int pageNo, int pageSize, String sn, Integer status) {
if (pageNo == 0 || pageSize == 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
}
List<PmsUseLog> pmsUseLogs = pmsUseLogMapper.getPmsUseLogList(sn, status);
List<PmsUseLog> result = new ArrayList<>();
int begin = (pageNo - 1) * pageSize;
if (begin >= 0 && pmsUseLogs.size() > 0) {
result = pmsUseLogs.stream().skip(begin).limit(pageSize).collect(Collectors.toList());
}
PageInfoModel<PmsUseLog> pmsUseLogPageInfoModel = new PageInfoModel<>();
pmsUseLogPageInfoModel.setTotal(pmsUseLogs.size());
pmsUseLogPageInfoModel.setResult(result);
return pmsUseLogPageInfoModel;
}
private PmsUseLog getPmsUseLog(String sn) {
PmsUseLog pmsUseLog = new PmsUseLog();
Date date = new Date();
......
<?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="iot.sixiang.license.mapper.PmsUseLogMapper">
<select id="getPmsUseLogList" resultType="iot.sixiang.license.entity.PmsUseLog">
SELECT * FROM pms_use_log
where 1=1
<if test="null != sn and '' != sn">
and sn = #{sn}
</if>
<if test="null != status">
and status = #{status}
</if>
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment