Commit 99aa7bce authored by AfirSraftGarrier's avatar AfirSraftGarrier

Merge remote-tracking branch 'origin/master'

parents b6b9cabd 45537ae0
......@@ -5,7 +5,11 @@ import io.swagger.annotations.ApiOperation;
import iot.sixiang.license.entity.ReportType;
import iot.sixiang.license.log.BusinessType;
import iot.sixiang.license.log.MyLog;
import iot.sixiang.license.model.PageResult;
import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.dto.ReportDTO;
import iot.sixiang.license.model.vo.ReportVO;
import iot.sixiang.license.service.ReportService;
import iot.sixiang.license.service.ReportTypeService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -26,17 +30,27 @@ public class ReportController {
@Resource
ReportTypeService reportTypeService;
@Resource
ReportService reportService;
/**
* 查询所有报警类型
*
* @return
*/
@ApiOperation(value = "获取报警类型列表接口", notes = "用于获取报警类型列表")
@ApiOperation(value = "获取报警类型接口", notes = "用于获取报警类型")
@GetMapping("report_type/list")
@MyLog(title = "获取报警类型列表", businessType = BusinessType.SELECT)
@MyLog(title = "获取报警类型", businessType = BusinessType.SELECT)
public ResResult getReportTypeList() {
List<ReportType> reportTypes = reportTypeService.getReportTypeList();
return ResResult.success().goRecord(reportTypes);
}
@ApiOperation(value = "获取报警列表接口", notes = "用于获取报警列表")
@GetMapping("list")
@MyLog(title = "获取报警列表", optParam = "#{reportDTO.pageNo},#{reportDTO.pageSize},#{reportDTO.type},#{reportDTO.sn},#{reportDTO.startTime},#{reportDTO.endTime}", businessType = BusinessType.SELECT)
public PageResult<ReportVO> getReportList(ReportDTO reportDTO) {
return reportService.getReportList(reportDTO);
}
}
......@@ -32,6 +32,7 @@ import iot.sixiang.license.service.UserPermissionService;
import iot.sixiang.license.service.UserService;
import iot.sixiang.license.util.CommonUtil;
import iot.sixiang.license.util.EmailUtils;
import iot.sixiang.license.util.TreeUtil;
import iot.sixiang.license.xss.XssUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -41,6 +42,7 @@ import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -267,13 +269,17 @@ public class UserController {
userName = XssUtil.checkXSS(userName);
company = XssUtil.checkXSS(company);
String userId = UserUtils.getLoginUserId();
PageInfoModel<UserVo> records;
if (!StringUtils.isEmpty(userId)) {
records = userService.getUserList(pageNo, pageSize, userName, company, Integer.parseInt(userId));
} else {
return null;
if (StringUtils.isEmpty(userId)) {
throw new IotLicenseException(403, "请重新登录");
}
List<Integer> userIds = new ArrayList<>();
List<Integer> userChildIds = TreeUtil.getUserChildIds(Integer.parseInt(userId), userIds);
userChildIds.add(Integer.parseInt(userId));
PageInfoModel<UserVo> records = userService.getUserList(pageNo, pageSize, userName, company, userChildIds);
int total = records.getTotal();
if (total <= 0) {
return new PageResult(200, "查找成功", pageNo, 0, 0, null);
}
int pages = total / pageSize;//pages为总页数
int mod = total % pageSize;
if (mod != 0) {
......
......@@ -2,6 +2,9 @@ package iot.sixiang.license.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import iot.sixiang.license.entity.Report;
import iot.sixiang.license.model.vo.ReportVO;
import java.util.List;
/**
* Created by m33
......@@ -9,4 +12,5 @@ import iot.sixiang.license.entity.Report;
* Description
*/
public interface ReportMapper extends BaseMapper<Report> {
List<ReportVO> getReportList(Integer type, String sn, String startTime, String endTime, List<Integer> userChildIds);
}
......@@ -2,6 +2,7 @@ package iot.sixiang.license.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import iot.sixiang.license.entity.User;
import iot.sixiang.license.model.vo.UserChildIdVO;
import iot.sixiang.license.model.vo.UserVo;
import java.util.List;
......@@ -23,9 +24,11 @@ public interface UserMapper extends BaseMapper<User> {
boolean updateUser(int userId, String password);
List<UserVo> getUserList(String userName, String company, int userId);
List<UserVo> getUserList(String userName, String company, List<Integer> userIds);
User getUserByUserName(String userName);
User getUserById(int userId);
List<UserChildIdVO> getChildUser(int userId);
}
package iot.sixiang.license.model.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* Created by m33
* Date 2023/2/1 13:57
* Description
*/
@Data
public class ReportDTO {
@ApiModelProperty("当前页")
private Integer pageNo;
@ApiModelProperty("每页条数")
private Integer pageSize;
@ApiModelProperty("报警事件类型")
private Integer type;
@ApiModelProperty("设备编码")
private String sn;
@ApiModelProperty("开始时间")
private String startTime;
@ApiModelProperty("结束时间")
private String endTime;
}
package iot.sixiang.license.model.vo;
import io.swagger.annotations.ApiModelProperty;
import iot.sixiang.license.entity.Report;
import lombok.Data;
/**
* Created by m33
* Date 2023/2/1 14:06
* Description
*/
@Data
public class ReportVO extends Report {
@ApiModelProperty("报警事件")
private String reportTypeStr;
}
package iot.sixiang.license.model.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* Created by m33
* Date 2023/2/1 14:52
* Description
*/
@Data
public class UserChildIdVO {
@ApiModelProperty("用户Id")
private Integer userId;
@ApiModelProperty("父Id")
private Integer parent;
@ApiModelProperty("账号级别")
private Integer level;
}
package iot.sixiang.license.service;
import iot.sixiang.license.entity.ReportType;
import java.util.List;
import iot.sixiang.license.model.PageResult;
import iot.sixiang.license.model.dto.ReportDTO;
import iot.sixiang.license.model.vo.ReportVO;
/**
* Created by M=54G
......@@ -11,4 +11,5 @@ import java.util.List;
*/
public interface ReportService {
PageResult<ReportVO> getReportList(ReportDTO reportDTO);
}
......@@ -4,8 +4,11 @@ import iot.sixiang.license.entity.User;
import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.dto.UpdateNotifyDTO;
import iot.sixiang.license.model.vo.UserChildIdVO;
import iot.sixiang.license.model.vo.UserVo;
import java.util.List;
/**
* <p>
* 服务类
......@@ -22,11 +25,13 @@ public interface UserService {
boolean updateUser(User user);
PageInfoModel<UserVo> getUserList(int pageNo, int pageSize, String userName, String company, int userId);
PageInfoModel<UserVo> getUserList(int pageNo, int pageSize, String userName, String company, List<Integer> userIds);
User getUserById(int userId);
User getUserByName(String root);
BaseResult updateNotify(UpdateNotifyDTO updateNotifyDTO);
List<UserChildIdVO> getChildUser(int userId);
}
package iot.sixiang.license.service.impl;
import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.jwt.UserUtils;
import iot.sixiang.license.mapper.ReportMapper;
import iot.sixiang.license.model.PageResult;
import iot.sixiang.license.model.dto.ReportDTO;
import iot.sixiang.license.model.vo.ReportVO;
import iot.sixiang.license.service.ReportService;
import iot.sixiang.license.util.TreeUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* Created by m33
......@@ -16,4 +26,36 @@ public class ReportServiceImpl implements ReportService {
@Resource
ReportMapper reportMapper;
@Override
public PageResult<ReportVO> getReportList(ReportDTO reportDTO) {
int pageNo = reportDTO.getPageNo();
int pageSize = reportDTO.getPageSize();
Integer type = reportDTO.getType();
String sn = reportDTO.getSn();
String startTime = reportDTO.getStartTime();
String endTime = reportDTO.getEndTime();
String userId = UserUtils.getLoginUserId();
if (StringUtils.isEmpty(userId)) {
throw new IotLicenseException(403, "请重新登录");
}
List<Integer> userIds = new ArrayList<>();
List<Integer> userChildIds = TreeUtil.getUserChildIds(Integer.parseInt(userId), userIds);
userChildIds.add(Integer.parseInt(userId));
List<ReportVO> reportList = reportMapper.getReportList(type, sn, startTime, endTime, userChildIds);
int total = reportList.size();
List<ReportVO> result;
int begin = (pageNo - 1) * pageSize;
if (begin >= 0 && total > 0) {
result = reportList.stream().skip(begin).limit(pageSize).collect(Collectors.toList());
} else {
return new PageResult<>(200, "查找成功", pageNo, 0, 0, null);
}
// pages为总页数
int pages = total / pageSize;
int mod = total % pageSize;
if (mod != 0) {
pages = pages + 1;
}
return new PageResult(200, "查找成功", pageNo, pages, total, result);
}
}
......@@ -12,9 +12,9 @@ import iot.sixiang.license.mapper.UserMapper;
import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.dto.UpdateNotifyDTO;
import iot.sixiang.license.model.vo.UserChildIdVO;
import iot.sixiang.license.model.vo.UserVo;
import iot.sixiang.license.service.UserService;
import iot.sixiang.license.util.CommonUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
......@@ -40,11 +40,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
UserMapper userMapper;
@Override
public PageInfoModel<UserVo> getUserList(int pageNo, int pageSize, String userName, String company, int userId) {
public PageInfoModel<UserVo> getUserList(int pageNo, int pageSize, String userName, String company, List<Integer> userIds) {
if (pageNo == 0 || pageSize == 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
}
List<UserVo> records = userMapper.getUserList(userName, company, userId);
List<UserVo> records = userMapper.getUserList(userName, company, userIds);
records = records.stream().sorted(Comparator.comparing(UserVo::getCreateTime, Comparator.reverseOrder())).collect(Collectors.toList());
List<UserVo> result = new ArrayList<>();
int begin = (pageNo - 1) * pageSize;
......@@ -124,4 +124,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
}
}
@Override
public List<UserChildIdVO> getChildUser(int userId) {
return userMapper.getChildUser(userId);
}
}
package iot.sixiang.license.util;
import iot.sixiang.license.model.vo.UserChildIdVO;
import iot.sixiang.license.service.UserService;
import java.util.List;
/**
* Created by m33
* Date 2023/2/1 14:49
* Description
*/
public class TreeUtil {
/**
* 获取所有子账号userId
*
* @param userId
* @param res
* @return
*/
public static List<Integer> getUserChildIds(int userId, List<Integer> res) {
UserService userService = SpringUtil.getBean(UserService.class);
List<UserChildIdVO> userChildIdVOS = userService.getChildUser(userId);
if (userChildIdVOS.isEmpty()) {
return res;
}
for (UserChildIdVO userChildIdVO : userChildIdVOS) {
if (userChildIdVO.getLevel() < 3) {
getUserChildIds(userChildIdVO.getUserId(), res);
}
res.add(userChildIdVO.getUserId());
}
return res;
}
}
<?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.ReportMapper">
<select id="getReportList" resultType="iot.sixiang.license.model.vo.ReportVO">
SELECT
report.*,
report_type.description
FROM
`report`
LEFT JOIN `user` ON user.user_name = report.user_name
LEFT JOIN report_type ON report.type = report_type.id
where 1=1
<if test="userChildIds != null">
AND user.user_id IN
<foreach collection="userChildIds" open="(" separator="," close=")" item="userId">
#{userId}
</foreach>
</if>
<if test="null != type">
AND report.type = #{type}
</if>
<if test="null != sn and '' != sn">
AND report.sn like concat('%',#{sn},'%')
</if>
<if test="startTime != null and startTime != ''">
AND report.create_time &gt; #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND report.create_time &lt; #{endTime}
</if>
AND report.deleted = 0
AND report_type.deleted = 0
ORDER BY report.create_time DESC
</select>
</mapper>
......@@ -25,8 +25,11 @@
LEFT JOIN apply ON user.user_id = apply.user_id
LEFT JOIN device ON apply.app_id = device.app_id
where 1=1
<if test="userId != null">
and (user.user_id = #{userId} or parent = #{userId})
<if test="userIds != null">
and user.user_id in
<foreach collection="userIds" open="(" separator="," close=")" item="userId">
#{userId}
</foreach>
</if>
<if test="null != userName and '' != userName">
and user_name like concat('%',#{userName},'%')
......@@ -45,4 +48,8 @@
select * from user where user_id = #{userId} limit 1
</select>
<select id="getChildUser" resultType="iot.sixiang.license.model.vo.UserChildIdVO">
select user_id, parent, `level` from `user` where parent = #{userId}
</select>
</mapper>
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