Commit 02dc3069 authored by zengtianlai3's avatar zengtianlai3

完善apply等接口

parent c91046a0
package iot.sixiang.license.controller;
import com.alibaba.fastjson.JSONObject;
import iot.sixiang.license.model.BaseResult;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* <p>
* 前端控制器
* </p>
*
* @author m33
* @since 2022-06-09
*/
@RestController
@RequestMapping("/iot_license/apply")
public class ApplyController {
@Autowired
private ApplyService applyService;
/**
* 添加apply
* @param jsonObject
* @return
*/
@PostMapping("add")
public BaseResult addUser(@RequestBody JSONObject jsonObject) {
String appName = jsonObject.getString("appName");
String appKey = jsonObject.getString("appKey");
int userId = jsonObject.getInteger("userId");
boolean res = applyService.addApply(appName, appKey, userId);
if (res) {
return BaseResult.success();
} else {
return BaseResult.fail();
}
}
/**
* 分页查询所有的apply
* @param pageNo
* @param pageSize
* @return
*/
@GetMapping("list")
public PageResult getUserList(@RequestParam("pageNo") int pageNo, @RequestParam("pageSize") int pageSize,
@RequestParam(value = "appName",required = false) String appName) {
PageInfoModel<AppVo> records = applyService.getAppList(pageNo,pageSize,appName);
int total = records.getTotal();
int pages = total/pageSize;//pages为总页数
int mod = total%pageSize;
if(mod!=0){
pages = pages +1;
}
List<AppVo> result = records.getResult();
return new PageResult(200,"查找成功",pageNo,pages,total,result);
}
}
\ No newline at end of file
...@@ -5,7 +5,7 @@ import com.alibaba.fastjson.JSONObject; ...@@ -5,7 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import iot.sixiang.license.model.BaseResult; import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.PageInfoModel; import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.PageResult; import iot.sixiang.license.model.PageResult;
import iot.sixiang.license.model.vo.DeviceTypeVo; import iot.sixiang.license.model.vo.DeviceVo;
import iot.sixiang.license.service.DeviceService; import iot.sixiang.license.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -34,10 +34,9 @@ public class DeviceController { ...@@ -34,10 +34,9 @@ public class DeviceController {
*/ */
@PostMapping("add") @PostMapping("add")
public BaseResult addDevice(@RequestBody JSONObject jsonObject) { public BaseResult addDevice(@RequestBody JSONObject jsonObject) {
int userId = jsonObject.getInteger("userId"); int appId = jsonObject.getInteger("appId");
int typeId = jsonObject.getInteger("typeId");
int count = jsonObject.getInteger("count"); int count = jsonObject.getInteger("count");
boolean res = deviceService.addDevice(userId, typeId,count); boolean res = deviceService.addDevice(appId,count);
if (res) { if (res) {
return BaseResult.success(); return BaseResult.success();
} else { } else {
...@@ -49,23 +48,23 @@ public class DeviceController { ...@@ -49,23 +48,23 @@ public class DeviceController {
* 可按条件分页查询所有的user * 可按条件分页查询所有的user
* @param pageNo * @param pageNo
* @param pageSize * @param pageSize
* @param typeName * @param appName
* @param userName * @param userName
* @return * @return
*/ */
@GetMapping("list") @GetMapping("list")
public PageResult getDeviceList(@RequestParam("pageNo") int pageNo, public PageResult getDeviceList(@RequestParam("pageNo") int pageNo,
@RequestParam("pageSize") int pageSize, @RequestParam("pageSize") int pageSize,
@RequestParam(value = "typeName",required = false) String typeName, @RequestParam(value = "appName",required = false) String appName,
@RequestParam(value = "userName",required = false) String userName) { @RequestParam(value = "userName",required = false) String userName) {
PageInfoModel<DeviceTypeVo> records = deviceService.getDeviceList(pageNo,pageSize,typeName,userName); PageInfoModel<DeviceVo> records = deviceService.getDeviceList(pageNo,pageSize,appName,userName);
int total = records.getTotal(); int total = records.getTotal();
int pages = total/pageSize;//pages为总页数 int pages = total/pageSize;//pages为总页数
int mod = total%pageSize; int mod = total%pageSize;
if(mod!=0){ if(mod!=0){
pages = pages +1; pages = pages +1;
} }
List<DeviceTypeVo> pageResult = records.getResult(); List<DeviceVo> pageResult = records.getResult();
return new PageResult(200,"查找成功",pageNo,pages,total,pageResult); return new PageResult(200,"查找成功",pageNo,pages,total,pageResult);
} }
} }
......
package iot.sixiang.license.entity; package iot.sixiang.license.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
...@@ -12,18 +14,22 @@ import java.io.Serializable; ...@@ -12,18 +14,22 @@ import java.io.Serializable;
* </p> * </p>
* *
* @author m33 * @author m33
* @since 2022-06-08 * @since 2022-06-09
*/ */
@Data @Data
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
@Accessors(chain = true) @Accessors(chain = true)
public class DeviceType implements Serializable { public class Apply implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private Integer typeId; @TableId(type = IdType.AUTO)
private Integer appId;
private String typeName; private String appName;
private String appKey;
private Integer userId;
} }
...@@ -28,9 +28,6 @@ public class Device implements Serializable { ...@@ -28,9 +28,6 @@ public class Device implements Serializable {
private String sn; private String sn;
private Integer typeId; private Integer applyId;
private Integer userId;
} }
...@@ -7,14 +7,13 @@ import iot.sixiang.license.model.ResResult; ...@@ -7,14 +7,13 @@ import iot.sixiang.license.model.ResResult;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import javax.servlet.*; import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
@Slf4j @Slf4j
@WebFilter(filterName = "jwtFilter", urlPatterns = "/iot_license/*") //@WebFilter(filterName = "jwtFilter", urlPatterns = "/iot_license/*")
public class JwtFilter implements Filter { public class JwtFilter implements Filter {
......
package iot.sixiang.license.jwt; package iot.sixiang.license.jwt;
import com.auth0.jwt.JWT; import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier; import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm; import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.Claim;
import com.auth0.jwt.interfaces.DecodedJWT; import com.auth0.jwt.interfaces.DecodedJWT;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -20,7 +20,7 @@ public class JwtUtil { ...@@ -20,7 +20,7 @@ public class JwtUtil {
/** /**
* 过期时间 * 过期时间
**/ **/
private static final long EXPIRATION = 1800L;//单位为秒 private static final long EXPIRATION = 3600L;//单位为秒
private static HashMap<String,String> tokens = new HashMap<>(); private static HashMap<String,String> tokens = new HashMap<>();
/** /**
......
package iot.sixiang.license.mapper; package iot.sixiang.license.mapper;
import iot.sixiang.license.entity.Apply;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import iot.sixiang.license.entity.DeviceType; import iot.sixiang.license.model.vo.AppVo;
import java.util.List; import java.util.List;
...@@ -11,9 +12,13 @@ import java.util.List; ...@@ -11,9 +12,13 @@ import java.util.List;
* </p> * </p>
* *
* @author m33 * @author m33
* @since 2022-06-08 * @since 2022-06-09
*/ */
public interface DeviceTypeMapper extends BaseMapper<DeviceType> { public interface ApplyMapper extends BaseMapper<Apply> {
List<DeviceType> getDeviceTypeList(); boolean addApply(String appName, String appKey, int userId);
List<AppVo> getAppList(String appName);
Apply getApplyByAppName(String appName);
} }
...@@ -2,7 +2,7 @@ package iot.sixiang.license.mapper; ...@@ -2,7 +2,7 @@ package iot.sixiang.license.mapper;
import iot.sixiang.license.entity.Device; import iot.sixiang.license.entity.Device;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import iot.sixiang.license.model.vo.DeviceTypeVo; import iot.sixiang.license.model.vo.DeviceVo;
import java.util.List; import java.util.List;
...@@ -16,7 +16,7 @@ import java.util.List; ...@@ -16,7 +16,7 @@ import java.util.List;
*/ */
public interface DeviceMapper extends BaseMapper<Device> { public interface DeviceMapper extends BaseMapper<Device> {
List<DeviceTypeVo> getDeviceList(String typeName, String userName); List<DeviceVo> getDeviceList(String appName, String userName);
boolean addDevice(String sn, int userId, int typeId); boolean addDevice(String sn, int appId);
} }
package iot.sixiang.license.model.vo;
import iot.sixiang.license.entity.Apply;
import lombok.Data;
/**
* Created by m33 on 2022/6/9 16:50
*/
@Data
public class AppVo extends Apply {
public int deviceCount;
public String userName;
public String company;
public String sn;
public int deviceId;
}
package iot.sixiang.license.model.vo; package iot.sixiang.license.model.vo;
import iot.sixiang.license.entity.Device;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
...@@ -9,16 +8,16 @@ import java.io.Serializable; ...@@ -9,16 +8,16 @@ import java.io.Serializable;
* Created by m33 on 2022/6/8 13:35 * Created by m33 on 2022/6/8 13:35
*/ */
@Data @Data
public class DeviceTypeVo extends Device implements Serializable { public class DeviceVo implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private String typeName; private int deviceId;
private String password; private String appName;
private String userName; private String userName;
private String company; private String sn;
} }
...@@ -8,5 +8,5 @@ import lombok.Data; ...@@ -8,5 +8,5 @@ import lombok.Data;
*/ */
@Data @Data
public class UserVo extends User { public class UserVo extends User {
public int deviceCount; public int appCount;
} }
package iot.sixiang.license.service;
import iot.sixiang.license.entity.Apply;
import com.baomidou.mybatisplus.extension.service.IService;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.vo.AppVo;
/**
* <p>
* 服务类
* </p>
*
* @author m33
* @since 2022-06-09
*/
public interface ApplyService extends IService<Apply> {
boolean addApply(String appName, String appKey, int userId);
PageInfoModel<AppVo> getAppList(int pageNo, int pageSize, String appName);
}
...@@ -3,7 +3,7 @@ package iot.sixiang.license.service; ...@@ -3,7 +3,7 @@ package iot.sixiang.license.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import iot.sixiang.license.entity.Device; import iot.sixiang.license.entity.Device;
import iot.sixiang.license.model.PageInfoModel; import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.vo.DeviceTypeVo; import iot.sixiang.license.model.vo.DeviceVo;
/** /**
* <p> * <p>
...@@ -15,7 +15,7 @@ import iot.sixiang.license.model.vo.DeviceTypeVo; ...@@ -15,7 +15,7 @@ import iot.sixiang.license.model.vo.DeviceTypeVo;
*/ */
public interface DeviceService extends IService<Device> { public interface DeviceService extends IService<Device> {
PageInfoModel<DeviceTypeVo> getDeviceList(int pageNo, int pageSize, String typeName, String userName); PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName);
boolean addDevice(int userId, int typeId, int count); boolean addDevice(int appId, int count);
} }
package iot.sixiang.license.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import iot.sixiang.license.entity.Apply;
import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.mapper.ApplyMapper;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.vo.AppVo;
import iot.sixiang.license.service.ApplyService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
/**
* <p>
* 服务实现类
* </p>
*
* @author m33
* @since 2022-06-09
*/
@Service
public class ApplyServiceImpl extends ServiceImpl<ApplyMapper, Apply> implements ApplyService {
@Resource
ApplyMapper applyMapper;
@Override
public boolean addApply(String appName, String appKey, int userId) {
Apply res = applyMapper.getApplyByAppName(appName);
if (res != null) {
throw new IotLicenseException(400,"应用名已存在");
}
return applyMapper.addApply(appName,appKey,userId);
}
@Override
public PageInfoModel<AppVo> getAppList(int pageNo, int pageSize, String appName) {
List<AppVo> records = applyMapper.getAppList(appName);
records = records.stream().sorted(Comparator.comparing(AppVo::getAppId)).collect(Collectors.toList());
List<AppVo> result = new ArrayList<>();
int begin = (pageNo - 1) * pageSize;
if (begin >= 0 && records.size() > 0) {
result = records.stream().skip(begin).limit(pageSize).collect(Collectors.toList());
}
PageInfoModel<AppVo> objectPageInfoModel = new PageInfoModel<>();
objectPageInfoModel.setTotal(records.size());
objectPageInfoModel.setResult(result);
return objectPageInfoModel;
}
}
...@@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; ...@@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import iot.sixiang.license.entity.Device; import iot.sixiang.license.entity.Device;
import iot.sixiang.license.mapper.DeviceMapper; import iot.sixiang.license.mapper.DeviceMapper;
import iot.sixiang.license.model.PageInfoModel; import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.vo.DeviceTypeVo; import iot.sixiang.license.model.vo.DeviceVo;
import iot.sixiang.license.service.DeviceService; import iot.sixiang.license.service.DeviceService;
import iot.sixiang.license.util.CommonUtil; import iot.sixiang.license.util.CommonUtil;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -30,25 +30,25 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme ...@@ -30,25 +30,25 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
private DeviceMapper deviceMapper; private DeviceMapper deviceMapper;
@Override @Override
public PageInfoModel<DeviceTypeVo> getDeviceList(int pageNo, int pageSize, String typeName, String userName) { public PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName) {
List<DeviceTypeVo> deviceTypes = deviceMapper.getDeviceList(typeName,userName); List<DeviceVo> deviceTypes = deviceMapper.getDeviceList(appName,userName);
deviceTypes = deviceTypes.stream().sorted(Comparator.comparing(DeviceTypeVo::getDeviceId)).collect(Collectors.toList()); deviceTypes = deviceTypes.stream().sorted(Comparator.comparing(DeviceVo::getDeviceId)).collect(Collectors.toList());
List<DeviceTypeVo> result = new ArrayList<>(); List<DeviceVo> result = new ArrayList<>();
int begin = (pageNo - 1) * pageSize; int begin = (pageNo - 1) * pageSize;
if (begin >= 0 && deviceTypes.size() > 0) { if (begin >= 0 && deviceTypes.size() > 0) {
result = deviceTypes.stream().skip(begin).limit(pageSize).collect(Collectors.toList()); result = deviceTypes.stream().skip(begin).limit(pageSize).collect(Collectors.toList());
} }
PageInfoModel<DeviceTypeVo> objectPageInfoModel = new PageInfoModel<>(); PageInfoModel<DeviceVo> objectPageInfoModel = new PageInfoModel<>();
objectPageInfoModel.setTotal(deviceTypes.size()); objectPageInfoModel.setTotal(deviceTypes.size());
objectPageInfoModel.setResult(result); objectPageInfoModel.setResult(result);
return objectPageInfoModel; return objectPageInfoModel;
} }
@Override @Override
public boolean addDevice(int userId, int typeId, int count) { public boolean addDevice(int appId, int count) {
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
String sn = CommonUtil.genRandomNum(18); String sn = CommonUtil.genRandomNum(18);
boolean res = deviceMapper.addDevice(sn,userId,typeId); boolean res = deviceMapper.addDevice(sn,appId);
if (!res) { if (!res) {
return false; return false;
} }
......
...@@ -10,11 +10,6 @@ import com.baomidou.mybatisplus.generator.config.StrategyConfig; ...@@ -10,11 +10,6 @@ import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
/**
* @author
* @since 2018/12/13
*/
public class CodeGenerator { public class CodeGenerator {
public static void main(String[] args) { public static void main(String[] args) {
// 1、创建代码生成器 // 1、创建代码生成器
...@@ -52,7 +47,7 @@ public class CodeGenerator { ...@@ -52,7 +47,7 @@ public class CodeGenerator {
// 5、策略配置 // 5、策略配置
StrategyConfig strategy = new StrategyConfig(); StrategyConfig strategy = new StrategyConfig();
strategy.setInclude("device_type"); strategy.setInclude("apply");
strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略 strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略
strategy.setTablePrefix(pc.getModuleName() + "_"); //生成实体时去掉表前缀 strategy.setTablePrefix(pc.getModuleName() + "_"); //生成实体时去掉表前缀
......
package iot.sixiang.license.util; package iot.sixiang.license.util;
import com.alibaba.fastjson.JSONObject;
/** /**
* Created by m33 on 2022/6/8 9:57 * Created by m33 on 2022/6/8 9:57
......
server:
port: 8868
logging:
level:
root: info
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/iot_license?serverTimezone=GMT%2B8
username: root
password: 123456
mybatis-plus:
mapper-locations: classpath:/mapper/**.xml
type-aliases-package: iot.sixiang.license.entity
\ No newline at end of file
server:
port: 8868
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/iot_license?serverTimezone=GMT%2B8
username: root
password: 123456
mybatis-plus:
mapper-locations: classpath:/mapper/**.xml
type-aliases-package: iot.sixiang.license.entity
\ No newline at end of file
server:
port: 8868
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.1.19:3306/iot_license?serverTimezone=GMT%2B8
username: root
password: 123456
mybatis-plus:
mapper-locations: classpath:/mapper/**.xml
type-aliases-package: iot.sixiang.license.entity
\ No newline at end of file
server.port=8868
logging.level.root=debug
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/iot_license?serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=123456
mybatis-plus.mapper-locations=classpath:/mapper/**.xml
mybatis-plus.type-aliases-package=iot.sixiang.license.entity
\ No newline at end of file
spring:
profiles:
active: prod
application:
name: iot_license #当前服务的名称
\ No newline at end of file
<?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.ApplyMapper">
<sql id="AppVoColumn">
app.app_id, app.app_name, app.app_key, us.user_id,
COUNT(sn) AS deviceCount, us.user_name, us.company,
sn, de.device_id
</sql>
<insert id="addApply" parameterType="iot.sixiang.license.entity.Apply">
insert into apply(app_name, app_key, user_id) values (#{appName}, #{appKey}, #{userId})
</insert>
<select id="getAppList" resultType="iot.sixiang.license.model.vo.AppVo">
SELECT <include refid="AppVoColumn"/>
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 != _parameter and '' != _parameter">
and app_name like concat('%',#{_parameter},'%')
</if>
GROUP BY app.app_id
</select>
<select id="getApplyByAppName" resultType="iot.sixiang.license.entity.Apply">
select app_id from apply where app_name = #{appName}
</select>
</mapper>
...@@ -2,25 +2,21 @@ ...@@ -2,25 +2,21 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!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"> <mapper namespace="iot.sixiang.license.mapper.DeviceMapper">
<sql id="DeviceVoColumn"> <select id="getDeviceList" resultType="iot.sixiang.license.model.vo.DeviceVo">
dt.type_id,dt.type_name,de.device_id,de.sn,us.user_id,us.user_name,us.password,us.company SELECT de.device_id,app_name,user_name,sn FROM device AS de
</sql> JOIN apply AS app ON de.app_id = app.app_id
JOIN USER AS us ON us.user_id = app.user_id
<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 where 1=1
<if test="null != typeName and '' != typeName"> <if test="null != appName and '' != appName">
and type_name like concat('%',#{typeName},'%') and app_name like concat('%',#{appName},'%')
</if> </if>
<if test="null != userName and '' != userName"> <if test="null != userName and '' != userName">
and us.user_name like concat('%',#{userName},'%') and user_name like concat('%',#{userName},'%')
</if> </if>
</select> </select>
<insert id="addDevice" parameterType="iot.sixiang.license.entity.Device"> <insert id="addDevice" parameterType="iot.sixiang.license.entity.Device">
insert into device(sn, type_id, user_id) values (#{sn},#{typeId}, #{userId}) insert into device(sn, app_id) values (#{sn},#{appId})
</insert> </insert>
</mapper> </mapper>
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
</update> </update>
<select id="getUserList" resultType="iot.sixiang.license.model.vo.UserVo"> <select id="getUserList" resultType="iot.sixiang.license.model.vo.UserVo">
SELECT user.user_id, user_name, password, company, COUNT(sn) AS deviceCount SELECT user.user_id, user_name, password, company, COUNT(app_name) AS appCount
FROM USER LEFT JOIN device ON user.user_id = device.user_id FROM USER LEFT JOIN apply ON user.user_id = apply.user_id
where 1=1 where 1=1
<if test="null != userName and '' != userName"> <if test="null != userName and '' != userName">
and user_name like concat('%',#{userName},'%') and user_name like concat('%',#{userName},'%')
......
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