Commit a076db8b authored by zengtianlai3's avatar zengtianlai3

查询设备列表

parent f0afbbdc
package iot.sixiang.license.controller;
import com.alibaba.fastjson.JSONObject;
import iot.sixiang.license.model.RespResult;
import iot.sixiang.license.model.vo.DeviceTypeVo;
import iot.sixiang.license.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* <p>
* 前端控制器
* </p>
*
* @author m33
* @since 2022-06-08
*/
@RestController
@RequestMapping("/iot_license/device")
public class DeviceController {
@Autowired
private DeviceService deviceService;
/**
* 可按条件分页查询所有的user
* @param jsonObject
* @return
*/
@GetMapping("list")
public RespResult getDeviceList(@RequestBody JSONObject jsonObject) {
int pageNo = (int)jsonObject.get("page_no");
int pageSize = (int)jsonObject.get("page_size");
String typeName = jsonObject.getString("type_name");
String userId = jsonObject.getString("user_id");
List<DeviceTypeVo> records = deviceService.getDeviceList(pageNo,pageSize,typeName,userId);
return RespResult.success().record(records);
}
}
package iot.sixiang.license.controller;
import com.alibaba.fastjson.JSONObject;
import iot.sixiang.license.model.RespResult;
import iot.sixiang.license.model.vo.DeviceTypeVo;
import iot.sixiang.license.service.DeviceTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* <p>
* 前端控制器
* </p>
*
* @author m33
* @since 2022-06-08
*/
@RestController
@RequestMapping("/iot_license/device_type")
public class DeviceTypeController {
@Autowired
private DeviceTypeService deviceTypeService;
/**
* 可按条件分页查询所有的user
* @param jsonObject
* @return
*/
@GetMapping("list")
public RespResult getDeviceTypeList(@RequestBody JSONObject jsonObject) {
int pageNo = (int)jsonObject.get("page_no");
int pageSize = (int)jsonObject.get("page_size");
String typeName = jsonObject.getString("type_name");
String userId = jsonObject.getString("user_id");
List<DeviceTypeVo> records = deviceTypeService.getDeviceTypeList(pageNo,pageSize,typeName,userId);
return RespResult.success().record(records);
}
}
package iot.sixiang.license.entity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* <p>
*
* </p>
*
* @author m33
* @since 2022-06-08
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class Device implements Serializable {
private static final long serialVersionUID = 1L;
private String sn;
private String typeId;
private Long userId;
}
package iot.sixiang.license.entity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* <p>
*
* </p>
*
* @author m33
* @since 2022-06-08
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class DeviceType implements Serializable {
private static final long serialVersionUID = 1L;
private Long typeId;
private String typeName;
}
package iot.sixiang.license.entity;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* <p>
*
......@@ -24,7 +25,7 @@ public class License implements Serializable {
private String appKey;
private String userId;
private Long userId;
}
package iot.sixiang.license.entity;
import java.io.Serializable;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* <p>
*
......@@ -20,9 +23,12 @@ public class User implements Serializable {
private static final long serialVersionUID = 1L;
private String userId;
@TableId(type = IdType.AUTO)
private Long userId;
private String password;
private String userName;
private String company;
}
package iot.sixiang.license.mapper;
import iot.sixiang.license.entity.Device;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import iot.sixiang.license.model.vo.DeviceTypeVo;
import java.util.List;
/**
* <p>
* Mapper 接口
* </p>
*
* @author m33
* @since 2022-06-08
*/
public interface DeviceMapper extends BaseMapper<Device> {
List<DeviceTypeVo> getDeviceList(int pageNo, int pageSize, String typeName, String userId);
}
package iot.sixiang.license.mapper;
import iot.sixiang.license.entity.DeviceType;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import iot.sixiang.license.model.vo.DeviceTypeVo;
import java.util.List;
/**
* <p>
* Mapper 接口
* </p>
*
* @author m33
* @since 2022-06-08
*/
public interface DeviceTypeMapper extends BaseMapper<DeviceType> {
List<DeviceTypeVo> getAllList();
List<DeviceTypeVo> getDeviceTypeList(int pageNo, int pageSize, String typeName, String userId);
}
package iot.sixiang.license.model.vo;
import iot.sixiang.license.entity.Device;
import lombok.Data;
import java.io.Serializable;
/**
* Created by m33 on 2022/6/8 13:35
*/
@Data
public class DeviceTypeVo extends Device implements Serializable {
private static final long serialVersionUID = 1L;
private String typeName;
private String password;
private String userName;
private String company;
}
package iot.sixiang.license.service;
import iot.sixiang.license.entity.Device;
import com.baomidou.mybatisplus.extension.service.IService;
import iot.sixiang.license.model.vo.DeviceTypeVo;
import java.util.List;
/**
* <p>
* 服务类
* </p>
*
* @author m33
* @since 2022-06-08
*/
public interface DeviceService extends IService<Device> {
List<DeviceTypeVo> getDeviceList(int pageNo, int pageSize, String typeName, String userId);
}
package iot.sixiang.license.service;
import iot.sixiang.license.model.vo.DeviceTypeVo;
import java.util.List;
/**
* <p>
* 服务类
* </p>
*
* @author m33
* @since 2022-06-08
*/
public interface DeviceTypeService {
List<DeviceTypeVo> getDeviceTypeList(int pageNo, int pageSize, String typeName, String userId);
}
package iot.sixiang.license.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import iot.sixiang.license.entity.Device;
import iot.sixiang.license.mapper.DeviceMapper;
import iot.sixiang.license.model.vo.DeviceTypeVo;
import iot.sixiang.license.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 服务实现类
* </p>
*
* @author m33
* @since 2022-06-08
*/
@Service
public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements DeviceService {
@Autowired
private DeviceMapper deviceMapper;
@Override
public List<DeviceTypeVo> getDeviceList(int pageNo, int pageSize, String typeName, String userId) {
List<DeviceTypeVo> deviceTypes = deviceMapper.getDeviceList(pageNo,pageSize,typeName,userId);
return deviceTypes;
}
}
package iot.sixiang.license.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import iot.sixiang.license.entity.DeviceType;
import iot.sixiang.license.mapper.DeviceTypeMapper;
import iot.sixiang.license.model.vo.DeviceTypeVo;
import iot.sixiang.license.service.DeviceTypeService;
import iot.sixiang.license.util.JsonUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* <p>
* 服务实现类
* </p>
*
* @author m33
* @since 2022-06-08
*/
@Service
public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceType> implements DeviceTypeService {
@Resource
private DeviceTypeMapper deviceTypeMapper;
@Override
public List<DeviceTypeVo> getDeviceTypeList(int pageNo, int pageSize, String typeName, String userId) {
if (JsonUtil.isNull(String.valueOf(pageNo)) || JsonUtil.isNull(String.valueOf(pageSize))) {
List<DeviceTypeVo> deviceTypes = deviceTypeMapper.getAllList();
return deviceTypes;
} else {
List<DeviceTypeVo> deviceTypes = deviceTypeMapper.getDeviceTypeList(pageNo,pageSize,typeName,userId);
return deviceTypes;
}
}
}
package iot.sixiang.license.util;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
/**
* @author
* @since 2018/12/13
*/
public class CodeGenerator {
public static void main(String[] args) {
// 1、创建代码生成器
AutoGenerator mpg = new AutoGenerator();
// 2、全局配置
GlobalConfig gc = new GlobalConfig();
// String projectPath = System.getProperty("user.dir");
gc.setOutputDir("C:\\Users\\Administrator\\IdeaProjects\\ioc_sixiang_license\\license" + "/src/main/java");
gc.setAuthor("m33");
gc.setOpen(false); //生成后是否打开资源管理器
gc.setFileOverride(false); //重新生成时文件是否覆盖
gc.setServiceName("%sService"); //去掉Service接口的首字母I
mpg.setGlobalConfig(gc);
// 3、数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://localhost:3306/iot_license?serverTimezone=GMT%2B8");
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUsername("root");
dsc.setPassword("123456");
dsc.setDbType(DbType.MYSQL);
mpg.setDataSource(dsc);
// 4、包配置
PackageConfig pc = new PackageConfig();
pc.setModuleName("license"); //模块名
pc.setParent("iot.sixiang");
pc.setController("controller");
pc.setEntity("entity");
pc.setService("service");
pc.setMapper("mapper");
mpg.setPackageInfo(pc);
// 5、策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setInclude("device_type");
strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略
strategy.setTablePrefix(pc.getModuleName() + "_"); //生成实体时去掉表前缀
strategy.setColumnNaming(NamingStrategy.underline_to_camel);//数据库表字段映射到实体的命名策略
strategy.setEntityLombokModel(true); // lombok 模型 @Accessors(chain = true) setter链式操作
strategy.setRestControllerStyle(true); //restful api风格控制器
strategy.setControllerMappingHyphenStyle(true); //url中驼峰转连字符
mpg.setStrategy(strategy);
// 6、执行
mpg.execute();
}
}
<?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.DeviceMapper">
<select id="getDeviceList" resultType="iot.sixiang.license.model.vo.DeviceTypeVo">
SELECT <include refid="DeviceVoColumn"/> FROM device_type AS dt
JOIN device AS de ON dt.type_id = de.type_id
JOIN USER AS us ON de.user_id = us.user_id
where 1=1
<if test="null != typeName and '' != typeName">
and type_name = #{typeName}
</if>
<if test="null != userId and '' != userId">
and us.user_id = #{userId}
</if>
LIMIT #{pageNo}*#{pageSize} - 1,#{pageSize}
</select>
<sql id="DeviceVoColumn">
dt.type_id,dt.type_name,de.sn,us.user_id,us.user_name,us.password,us.company
</sql>
</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