Commit 1758b45e authored by ma's avatar ma

完善列表查询

parent 0f376084
......@@ -18,6 +18,7 @@ import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.PageResult;
import iot.sixiang.license.model.vo.AppVo;
import iot.sixiang.license.service.ApplyService;
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;
......@@ -25,6 +26,7 @@ import org.springframework.util.DigestUtils;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -97,7 +99,10 @@ public class ApplyController {
if (StringUtils.isEmpty(userId)) {
throw new IotLicenseException(403, "请重新登录");
}
PageInfoModel<AppVo> records = applyService.getAppList(pageNo, pageSize, Integer.parseInt(userId), appName);
List<Integer> userIds = new ArrayList<>();
List<Integer> userChildIds = TreeUtil.getUserChildIds(Integer.parseInt(userId), userIds);
userChildIds.add(Integer.parseInt(userId));
PageInfoModel<AppVo> records = applyService.getAppList(pageNo, pageSize, appName, userChildIds);
int total = records.getTotal();
int pages = total / pageSize;//pages为总页数
int mod = total % pageSize;
......
......@@ -22,6 +22,7 @@ import iot.sixiang.license.model.vo.DeviceDetailVo;
import iot.sixiang.license.model.vo.DeviceVo;
import iot.sixiang.license.service.DeviceBlackService;
import iot.sixiang.license.service.DeviceService;
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;
......@@ -34,6 +35,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -115,7 +117,10 @@ public class DeviceController {
if (StringUtils.isEmpty(userId)) {
throw new IotLicenseException(403, "请重新登录");
}
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(pageNo, pageSize, Integer.parseInt(userId), appName, userName, sn, status);
List<Integer> userIds = new ArrayList<>();
List<Integer> userChildIds = TreeUtil.getUserChildIds(Integer.parseInt(userId), userIds);
userChildIds.add(Integer.parseInt(userId));
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(pageNo, pageSize, appName, userName, sn, status, userChildIds);
int total = records.getTotal();
int pages = total / pageSize;//pages为总页数
int mod = total % pageSize;
......
......@@ -5,12 +5,15 @@ 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.handler.IotLicenseException;
import iot.sixiang.license.jwt.UserUtils;
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.service.PmsUseService;
import iot.sixiang.license.util.CommonUtil;
import iot.sixiang.license.util.TreeUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -20,6 +23,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -56,12 +60,19 @@ public class PmsUseLogController {
@RequestParam(value = "endTime", required = false) String endTime,
@RequestParam(value = "sn", required = false) String sn,
@RequestParam(value = "status", required = false) Integer status) throws ParseException {
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));
if (StringUtils.isEmpty(endTime)) {
endTime = CommonUtil.getDayByNum(1, CommonUtil.dateToString(new Date(), "yyyy-MM-dd"));
} else {
endTime = CommonUtil.getDayByNum(1, endTime);
}
PageInfoModel<PmsUseLog> records = pmsUseService.getPmsUseLogList(pageNo, pageSize, sn, status, startTime, endTime);
PageInfoModel<PmsUseLog> records = pmsUseService.getPmsUseLogList(pageNo, pageSize, sn, status, startTime, endTime, userChildIds);
int total = records.getTotal();
int pages = total / pageSize;//pages为总页数
int mod = total % pageSize;
......
......@@ -69,10 +69,6 @@ public class UserController {
private PermissionService permissionService;
@Resource
private UserPermissionService userPermissionService;
@Resource
ReportService reportService;
@Resource
UserMapper userMapper;
@Value("${rsa.private_key}")
private String PRIVATE_KRY;
......
......@@ -18,7 +18,7 @@ public interface ApplyMapper extends BaseMapper<Apply> {
boolean addApply(String appId, String appName, String appKey, int userId);
List<AppVo> getAppList(Integer userId, String appName);
List<AppVo> getAppList(String appName, List<Integer> userChildIds);
Apply getApplyByAppName(String appName);
}
......@@ -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, Integer userId, String sn, Integer status);
List<DeviceVo> getDeviceList(String appName, String userName, List<Integer> userChildIds, String sn, Integer status);
boolean addDevice(String sn, String appId);
......
......@@ -12,5 +12,5 @@ import java.util.List;
* Description
*/
public interface PmsUseLogMapper extends BaseMapper<PmsUseLog> {
List<PmsUseLog> getPmsUseLogList(String sn, Integer status, String startTime, String endTime);
List<PmsUseLog> getPmsUseLogList(String sn, Integer status, String startTime, String endTime, List<Integer> userChildIds);
}
......@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.vo.AppVo;
import java.util.List;
/**
* <p>
* 服务类
......@@ -17,5 +19,5 @@ public interface ApplyService extends IService<Apply> {
boolean addApply(String appName, String appKey, int userId);
PageInfoModel<AppVo> getAppList(int pageNo, int pageSize, Integer userId, String appName);
PageInfoModel<AppVo> getAppList(int pageNo, int pageSize, String appName, List<Integer> userChildIds);
}
......@@ -10,6 +10,8 @@ import iot.sixiang.license.model.dto.TerminalDevieBindDTO;
import iot.sixiang.license.model.dto.TerminalDevieUnBindDTO;
import iot.sixiang.license.model.vo.DeviceVo;
import java.util.List;
/**
* 服务类
*
......@@ -17,7 +19,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, Integer userId, String appName, String userName, String sn, Integer status);
PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName, String sn, Integer status, List<Integer> userChildIds);
boolean addDevice(String appId, int count);
......
......@@ -4,6 +4,8 @@ import iot.sixiang.license.entity.PmsUseLog;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.dto.ReportErrorMsgDTO;
import java.util.List;
/**
* Created by M=54G
* Date 11/23/22 3:09 PM
......@@ -16,7 +18,7 @@ public interface PmsUseService {
void success(ReportErrorMsgDTO reportErrorMsgDTO);
PageInfoModel<PmsUseLog> getPmsUseLogList(int pageNo, int pageSize, String sn, Integer status, String startTime, String endTime);
PageInfoModel<PmsUseLog> getPmsUseLogList(int pageNo, int pageSize, String sn, Integer status, String startTime, String endTime, List<Integer> userChildIds);
boolean reportErrorMsg(ReportErrorMsgDTO reportErrorMsgDTO);
......
......@@ -33,11 +33,12 @@ public class ApplyServiceImpl extends ServiceImpl<ApplyMapper, Apply> implements
@Resource
ApplyMapper applyMapper;
@Override
public boolean addApply(String appName, String appKey, int userId) {
if(StringUtils.isEmpty(appName) || StringUtils.isEmpty(appKey)
if (StringUtils.isEmpty(appName) || StringUtils.isEmpty(appKey)
|| userId == 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(),ResultCode.VALIDATE_FAILED.getMsg());
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
}
Apply res = applyMapper.getApplyByAppName(appName);
if (res != null) {
......@@ -54,11 +55,11 @@ public class ApplyServiceImpl extends ServiceImpl<ApplyMapper, Apply> implements
}
@Override
public PageInfoModel<AppVo> getAppList(int pageNo, int pageSize, Integer userId, String appName) {
if(pageNo == 0 || pageSize == 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(),ResultCode.VALIDATE_FAILED.getMsg());
public PageInfoModel<AppVo> getAppList(int pageNo, int pageSize, String appName, List<Integer> userChildIds) {
if (pageNo == 0 || pageSize == 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
}
List<AppVo> records = applyMapper.getAppList(userId, appName);
List<AppVo> records = applyMapper.getAppList(appName, userChildIds);
records = records.stream().sorted(Comparator.comparing(AppVo::getCreateTime, Comparator.reverseOrder())).collect(Collectors.toList());
List<AppVo> result = new ArrayList<>();
int begin = (pageNo - 1) * pageSize;
......
......@@ -40,11 +40,11 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
private DeviceMapper deviceMapper;
@Override
public PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, Integer userId, String appName, String userName, String sn, Integer status) {
public PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName, String sn, Integer status, List<Integer> userChildIds) {
if (pageNo == 0 || pageSize == 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
}
List<DeviceVo> deviceTypes = deviceMapper.getDeviceList(appName, userName, userId, sn, status);
List<DeviceVo> deviceTypes = deviceMapper.getDeviceList(appName, userName, userChildIds, sn, status);
deviceTypes = deviceTypes.stream().sorted(Comparator.comparing(DeviceVo::getCreateTime, Comparator.reverseOrder())).collect(Collectors.toList());
List<DeviceVo> result = new ArrayList<>();
int begin = (pageNo - 1) * pageSize;
......
......@@ -65,11 +65,11 @@ public class PmsUseServiceImpl implements PmsUseService {
}
@Override
public PageInfoModel<PmsUseLog> getPmsUseLogList(int pageNo, int pageSize, String sn, Integer status, String startTime, String endTime) {
public PageInfoModel<PmsUseLog> getPmsUseLogList(int pageNo, int pageSize, String sn, Integer status, String startTime, String endTime, List<Integer> userChildIds) {
if (pageNo == 0 || pageSize == 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
}
List<PmsUseLog> pmsUseLogs = pmsUseLogMapper.getPmsUseLogList(sn, status, startTime, endTime);
List<PmsUseLog> pmsUseLogs = pmsUseLogMapper.getPmsUseLogList(sn, status, startTime, endTime, userChildIds);
List<PmsUseLog> result = new ArrayList<>();
int begin = (pageNo - 1) * pageSize;
if (begin >= 0 && pmsUseLogs.size() > 0) {
......
......@@ -14,8 +14,11 @@
FROM apply AS app LEFT JOIN device AS de ON app.app_id = de.app_id
LEFT JOIN user AS us ON us.user_id = app.user_id
where 1=1
<if test="null != userId">
and us.user_id = #{userId}
<if test="userChildIds != null">
AND us.user_id IN
<foreach collection="userChildIds" open="(" separator="," close=")" item="userId">
#{userId}
</foreach>
</if>
<if test="null != appName and '' != appName">
and app_name like concat('%',#{appName},'%')
......
......@@ -8,8 +8,11 @@
JOIN apply AS app ON de.app_id = app.app_id
JOIN `user` AS us ON us.user_id = app.user_id
where 1=1
<if test="null != userId">
and us.user_id = #{userId}
<if test="userChildIds != null">
AND us.user_id IN
<foreach collection="userChildIds" open="(" separator="," close=")" item="userId">
#{userId}
</foreach>
</if>
<if test="null != appName and '' != appName">
and app_name like concat('%',#{appName},'%')
......
......@@ -2,8 +2,17 @@
<!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
SELECT * FROM `pms_use_log`
INNER JOIN device ON device.sn = pms_use_log.sn
INNER JOIN apply ON device.app_id = apply.app_id
INNER JOIN `user` ON `user`.user_id = apply.user_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="startTime != null and startTime != ''">
AND create_time &gt; #{startTime}
</if>
......
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