Commit 68b96dd7 authored by ma's avatar ma

整合后台接口

parent 200b89e1
...@@ -39,6 +39,24 @@ ...@@ -39,6 +39,24 @@
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>1.16.10</version> <version>1.16.10</version>
</dependency> </dependency>
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.29</version>
</dependency>
<!--mybatis-plus-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.0.5</version>
</dependency>
<!-- velocity 模板引擎, Mybatis Plus 代码生成器需要 -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.0</version>
</dependency>
</dependencies> </dependencies>
......
package iot.sixiang.license; package iot.sixiang.license;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
@MapperScan(basePackages = "iot.sixiang.license.mapper")
public class LicenseApplication { public class LicenseApplication {
public static void main(String[] args) { public static void main(String[] args) {
......
package iot.sixiang.license.config;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Created by m33 on 2022/6/7 15:08
*/
@Configuration
public class MyBatisPlusConfig {
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
}
package iot.sixiang.license.controller;
import iot.sixiang.license.entity.License;
import iot.sixiang.license.model.RespResult;
import iot.sixiang.license.service.LicenseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* <p>
* 前端控制器
* </p>
*
* @author m33
* @since 2022-06-06
*/
@RestController
@RequestMapping("/iot_sixiang_license/license")
public class LicenseController {
@Autowired
private LicenseService licenseService;
/**
* 添加license
* @param license
* @return
*/
@PostMapping("add")
public RespResult addLicense(@RequestBody License license){
boolean save = licenseService.addLicense(license);
if (save) {
return RespResult.success();
} else {
return RespResult.fail();
}
}
/**
* 删除license
* @param appId
* @return
*/
@PostMapping("delete")
public RespResult deleteLicense(@RequestParam("appId") String appId) {
boolean flag = licenseService.deleteLicense(appId);
if (flag) {
return RespResult.success();
} else {
return RespResult.fail();
}
}
/**
* 分页查询所有的license
* @param pageNo
* @param pageSize
* @return
*/
@GetMapping("get_license_list")
public RespResult getLicenseList(@RequestParam("pageNo") int pageNo, @RequestParam("pageSize") int pageSize) {
List<License> records = licenseService.getLicenseList(pageNo,pageSize);
return RespResult.success().record(records);
}
}
package iot.sixiang.license.controller;
import iot.sixiang.license.entity.Server;
import iot.sixiang.license.model.RespResult;
import iot.sixiang.license.service.ServerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* <p>
* 前端控制器
* </p>
*
* @author m33
* @since 2022-06-06
*/
@RestController
@RequestMapping("/iot_sixiang_license/server")
public class ServerController {
@Autowired
private ServerService serverService;
/**
* 添加server
* @param server
* @return
*/
@PostMapping("add")
public RespResult addServer(@RequestBody Server server) {
boolean save = serverService.addServer(server);
if (save) {
return RespResult.success();
} else {
return RespResult.fail();
}
}
/**
* 删除server
* @param serverIp
* @return
*/
@PostMapping("delete")
public RespResult deleteServer(@RequestParam("serverIp") String serverIp) {
boolean flag = serverService.deleteServer(serverIp);
if (flag) {
return RespResult.success();
} else {
return RespResult.fail();
}
}
/**
* 分页查询所有的server
* @param pageNo
* @param pageSize
* @return
*/
@GetMapping("get_server_list")
public RespResult getServerList(@RequestParam("pageNo") int pageNo, @RequestParam("pageSize") int pageSize) {
List<Server> records = serverService.getServerList(pageNo,pageSize);
return RespResult.success().record(records);
}
}
package iot.sixiang.license.controller;
import iot.sixiang.license.entity.User;
import iot.sixiang.license.model.RespResult;
import iot.sixiang.license.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* <p>
* 前端控制器
* </p>
*
* @author m33
* @since 2022-06-06
*/
@RestController
@RequestMapping("/iot_sixiang_license/user")
public class UserController {
@Autowired
private UserService userService;
/**
* 添加user
* @param user
* @return
*/
@PostMapping("add")
public RespResult addUser(@RequestBody User user) {
boolean save = userService.addUser(user);
if (save) {
return RespResult.success();
} else {
return RespResult.fail();
}
}
/**
* 删除user
* @param userId
* @return
*/
@PostMapping("delete")
public RespResult deleteUser(@RequestParam("userId") String userId) {
boolean flag = userService.deleteUser(userId);
if (flag) {
return RespResult.success();
} else {
return RespResult.fail();
}
}
/**
* 分页查询所有的user
* @param pageNo
* @param pageSize
* @return
*/
@GetMapping("get_user_list")
public RespResult getUserList(@RequestParam("pageNo") int pageNo, @RequestParam("pageSize") int pageSize) {
List<User> records = userService.getUserList(pageNo,pageSize);
return RespResult.success().record(records);
}
}
package iot.sixiang.license.entity;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* <p>
*
* </p>
*
* @author m33
* @since 2022-06-06
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class License implements Serializable {
private static final long serialVersionUID = 1L;
private String appId;
private String appKey;
private String userId;
}
package iot.sixiang.license.entity;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* <p>
*
* </p>
*
* @author m33
* @since 2022-06-06
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class Server implements Serializable {
private static final long serialVersionUID = 1L;
private String serverIp;
private Integer port;
}
package iot.sixiang.license.entity;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* <p>
*
* </p>
*
* @author m33
* @since 2022-06-06
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class User implements Serializable {
private static final long serialVersionUID = 1L;
private String userId;
private String password;
}
package iot.sixiang.license.mapper;
import iot.sixiang.license.entity.License;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* Mapper 接口
* </p>
*
* @author m33
* @since 2022-06-06
*/
public interface LicenseMapper extends BaseMapper<License> {
boolean addLicense(License license);
boolean deleteLicense(String appId);
}
package iot.sixiang.license.mapper;
import iot.sixiang.license.entity.Server;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* Mapper 接口
* </p>
*
* @author m33
* @since 2022-06-06
*/
public interface ServerMapper extends BaseMapper<Server> {
boolean addServer(Server server);
boolean deleteServer(String serverIp);
}
package iot.sixiang.license.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import iot.sixiang.license.entity.User;
/**
* <p>
* Mapper 接口
* </p>
*
* @author m33
* @since 2022-06-06
*/
public interface UserMapper extends BaseMapper<User> {
boolean addUser(User user);
boolean deleteUser(String user);
}
package iot.sixiang.license.model;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RespResult {
private int code;
private String msg;
private Object data;
public static RespResult success() {
RespResult respResult = new RespResult();
respResult.setCode(200);
respResult.setMsg("success");
return respResult;
}
public static RespResult fail() {
RespResult respResult = new RespResult();
respResult.setCode(400);
respResult.setMsg("fail");
return respResult;
}
public RespResult msg(String message) {
this.msg = message;
return this;
}
public RespResult record(Object data){
this.data = data;
return this;
}
}
package iot.sixiang.license.service;
import com.baomidou.mybatisplus.extension.service.IService;
import iot.sixiang.license.entity.License;
import java.util.List;
/**
* <p>
* 服务类
* </p>
*
* @author m33
* @since 2022-06-06
*/
public interface LicenseService extends IService<License> {
boolean addLicense(License license);
List<License> getLicenseList(int pageNo, int pageSize);
boolean deleteLicense(String appId);
}
package iot.sixiang.license.service;
import com.baomidou.mybatisplus.extension.service.IService;
import iot.sixiang.license.entity.Server;
import java.util.List;
/**
* <p>
* 服务类
* </p>
*
* @author m33
* @since 2022-06-06
*/
public interface ServerService extends IService<Server> {
boolean addServer(Server server);
List<Server> getServerList(int pageNo, int pageSize);
boolean deleteServer(String serverIp);
}
package iot.sixiang.license.service;
import com.baomidou.mybatisplus.extension.service.IService;
import iot.sixiang.license.entity.User;
import java.util.List;
/**
* <p>
* 服务类
* </p>
*
* @author m33
* @since 2022-06-06
*/
public interface UserService extends IService<User> {
boolean addUser(User user);
List<User> getUserList(int pageNo, int pageSize);
boolean deleteUser(String user);
}
package iot.sixiang.license.service.impl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import iot.sixiang.license.entity.License;
import iot.sixiang.license.mapper.LicenseMapper;
import iot.sixiang.license.service.LicenseService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* <p>
* 服务实现类
* </p>
*
* @author m33
* @since 2022-06-06
*/
@Service
public class LicenseServiceImpl extends ServiceImpl<LicenseMapper, License> implements LicenseService {
@Resource
LicenseMapper licenseMapper;
@Override
public boolean addLicense(License license) {
return licenseMapper.addLicense(license);
}
@Override
public List<License> getLicenseList(int pageNo, int pageSize) {
Page<License> page = new Page<>(pageNo,pageSize);
baseMapper.selectPage(page,null);
List<License> records = page.getRecords();
return records;
}
@Override
public boolean deleteLicense(String appId) {
return licenseMapper.deleteLicense(appId);
}
}
package iot.sixiang.license.service.impl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import iot.sixiang.license.entity.Server;
import iot.sixiang.license.mapper.ServerMapper;
import iot.sixiang.license.service.ServerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* <p>
* 服务实现类
* </p>
*
* @author m33
* @since 2022-06-06
*/
@Service
public class ServerServiceImpl extends ServiceImpl<ServerMapper, Server> implements ServerService {
@Resource
ServerMapper serverMapper;
@Override
public boolean addServer(Server server) {
return serverMapper.addServer(server);
}
@Override
public List<Server> getServerList(int pageNo, int pageSize) {
Page<Server> page = new Page<>(pageNo,pageSize);
baseMapper.selectPage(page,null);
List<Server> records = page.getRecords();
return records;
}
@Override
public boolean deleteServer(String serverIp) {
return serverMapper.deleteServer(serverIp);
}
}
package iot.sixiang.license.service.impl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import iot.sixiang.license.entity.User;
import iot.sixiang.license.mapper.UserMapper;
import iot.sixiang.license.service.UserService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* <p>
* 服务实现类
* </p>
*
* @author m33
* @since 2022-06-06
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
@Resource
UserMapper userMapper;
@Override
public boolean addUser(User user) {
return userMapper.addUser(user);
}
@Override
public List<User> getUserList(int pageNo, int pageSize) {
Page<User> page = new Page<>(pageNo,pageSize);
baseMapper.selectPage(page,null);
List<User> records = page.getRecords();
return records;
}
@Override
public boolean deleteUser(String user) {
return userMapper.deleteUser(user);
}
}
server.port=8868 server.port=8868
logging.level.root=debug logging.level.root=debug
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/firstwork?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
<?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.LicenseMapper">
<insert id="addLicense" parameterType="iot.sixiang.license.entity.License">
insert into license(app_id, app_key, user_id) values (#{appId},#{appKey},#{userId})
</insert>
<delete id="deleteLicense" parameterType="iot.sixiang.license.entity.License">
delete from license where app_id = #{appId}
</delete>
</mapper>
<?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.ServerMapper">
<insert id="addServer" parameterType="iot.sixiang.license.entity.Server">
insert into server(server_ip, port) values (#{serverIp},#{port})
</insert>
<delete id="deleteServer" parameterType="iot.sixiang.license.entity.Server">
delete from server where server_ip = #{serverIp}
</delete>
</mapper>
<?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.UserMapper">
<insert id="addUser" parameterType="iot.sixiang.license.entity.User">
insert into user(user_id, password) values (#{userId},#{password})
</insert>
<delete id="deleteUser" parameterType="iot.sixiang.license.entity.User">
delete from user where user_id = #{userId}
</delete>
</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