Commit f0afbbdc authored by zengtianlai3's avatar zengtianlai3

增加修改功能

parent 02387dcd
......@@ -32,11 +32,11 @@ public class LicenseController {
*/
@PostMapping("add")
public RespResult addLicense(@RequestBody JSONObject jsonObject){
String appId = (String) jsonObject.get("app_id");
String appKey = (String) jsonObject.get("app_key");
String userId = (String) jsonObject.get("user_id");
boolean save = licenseService.addLicense(appId,appKey,userId);
if (save) {
String appId = jsonObject.getString("app_id");
String appKey = jsonObject.getString("app_key");
String userId = jsonObject.getString("user_id");
boolean res = licenseService.addLicense(appId,appKey,userId);
if (res) {
return RespResult.success();
} else {
return RespResult.fail();
......@@ -50,8 +50,26 @@ public class LicenseController {
*/
@PostMapping("delete")
public RespResult deleteLicense(@RequestParam("app_id") String appId) {
boolean flag = licenseService.deleteLicense(appId);
if (flag) {
boolean res = licenseService.deleteLicense(appId);
if (res) {
return RespResult.success();
} else {
return RespResult.fail();
}
}
/**
* 修改license
* @param jsonObject
* @return
*/
@PostMapping("update")
public RespResult updateLicense(@RequestBody JSONObject jsonObject){
String appId = jsonObject.getString("app_id");
String appKey = jsonObject.getString("app_key");
String userId = jsonObject.getString("user_id");
boolean res = licenseService.updateLicense(appId,appKey,userId);
if (res) {
return RespResult.success();
} else {
return RespResult.fail();
......@@ -64,7 +82,7 @@ public class LicenseController {
* @param pageSize
* @return
*/
@GetMapping("get_license_list")
@GetMapping("list")
public RespResult getLicenseList(@RequestParam("page_no") int pageNo, @RequestParam("page_size") int pageSize) {
List<License> records = licenseService.getLicenseList(pageNo,pageSize);
return RespResult.success().record(records);
......
......@@ -24,6 +24,7 @@ public class ServerController {
@Autowired
private ServerService serverService;
/**
* 添加server
* @param jsonObject
......@@ -31,10 +32,10 @@ public class ServerController {
*/
@PostMapping("add")
public RespResult addServer(@RequestBody JSONObject jsonObject) {
String serverIp = (String) jsonObject.get("server_ip");
int port = (int)jsonObject.get("port");
boolean save = serverService.addServer(serverIp,port);
if (save) {
String serverIp = jsonObject.getString("server_ip");
int port = jsonObject.getInteger("port");
boolean res = serverService.addServer(serverIp,port);
if (res) {
return RespResult.success();
} else {
return RespResult.fail();
......@@ -48,21 +49,39 @@ public class ServerController {
*/
@PostMapping("delete")
public RespResult deleteServer(@RequestParam("server_ip") String serverIp) {
boolean flag = serverService.deleteServer(serverIp);
if (flag) {
boolean res = serverService.deleteServer(serverIp);
if (res) {
return RespResult.success();
} else {
return RespResult.fail();
}
}
/**
* 修改server
* @param jsonObject
* @return
*/
@PostMapping("update")
public RespResult updateServer(@RequestBody JSONObject jsonObject) {
String serverIp = jsonObject.getString("server_ip");
int port = jsonObject.getInteger("port");
boolean res = serverService.updateServer(serverIp,port);
if (res) {
return RespResult.success();
} else {
return RespResult.fail();
}
}
/**
* 分页查询所有的server
* @param pageNo
* @param pageSize
* @return
*/
@GetMapping("get_server_list")
@GetMapping("list")
public RespResult getServerList(@RequestParam("page_no") int pageNo, @RequestParam("page_size") int pageSize) {
List<Server> records = serverService.getServerList(pageNo,pageSize);
return RespResult.success().record(records);
......
......@@ -35,8 +35,8 @@ public class UserController {
public RespResult addUser(@RequestBody JSONObject jsonObject) {
String userId = (String) jsonObject.get("user_id");
String password = (String) jsonObject.get("password");
boolean save = userService.addUser(userId, password);
if (save) {
boolean res = userService.addUser(userId, password);
if (res) {
return RespResult.success();
} else {
return RespResult.fail();
......@@ -50,21 +50,39 @@ public class UserController {
*/
@PostMapping("delete")
public RespResult deleteUser(@RequestParam("user_id") String userId) {
boolean flag = userService.deleteUser(userId);
if (flag) {
boolean res = userService.deleteUser(userId);
if (res) {
return RespResult.success();
} else {
return RespResult.fail();
}
}
/**
* 修改user
* @param jsonObject
* @return
*/
@PostMapping("update")
public RespResult updateUser(@RequestBody JSONObject jsonObject) {
String userId = jsonObject.getString("user_id");
String password = jsonObject.getString("password");
boolean res = userService.updateUser(userId, password);
if (res) {
return RespResult.success();
} else {
return RespResult.fail();
}
}
/**
* 分页查询所有的user
* @param pageNo
* @param pageSize
* @return
*/
@GetMapping("get_user_list")
@GetMapping("list")
public RespResult getUserList(@RequestParam("page_no") int pageNo, @RequestParam("page_size") int pageSize) {
List<User> records = userService.getUserList(pageNo,pageSize);
return RespResult.success().record(records);
......
......@@ -16,4 +16,6 @@ public interface LicenseMapper extends BaseMapper<License> {
boolean deleteLicense(String appId);
boolean addLicense(String appId, String appKey, String userId);
boolean updateLicense(String appId, String appKey, String userId);
}
......@@ -16,4 +16,6 @@ public interface ServerMapper extends BaseMapper<Server> {
boolean deleteServer(String serverIp);
boolean addServer(String serverIp, int port);
boolean updateServer(String serverIp, int port);
}
......@@ -17,4 +17,6 @@ public interface UserMapper extends BaseMapper<User> {
boolean deleteUser(String user);
boolean addUser(String userId, String password);
boolean updateUser(String userId, String password);
}
......@@ -20,4 +20,6 @@ public interface LicenseService extends IService<License> {
boolean deleteLicense(String appId);
boolean addLicense(String appId, String appKey, String userId);
boolean updateLicense(String appId, String appKey, String userId);
}
......@@ -20,4 +20,6 @@ public interface ServerService extends IService<Server> {
boolean deleteServer(String serverIp);
boolean addServer(String serverIp, int port);
boolean updateServer(String serverIp, int port);
}
......@@ -17,7 +17,9 @@ public interface UserService extends IService<User> {
List<User> getUserList(int pageNo, int pageSize);
boolean deleteUser(String user);
boolean deleteUser(String userId);
boolean addUser(String userId, String password);
boolean updateUser(String userId, String password);
}
......@@ -5,6 +5,7 @@ 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 iot.sixiang.license.util.JsonUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
......@@ -34,12 +35,26 @@ public class LicenseServiceImpl extends ServiceImpl<LicenseMapper, License> impl
@Override
public boolean deleteLicense(String appId) {
if(JsonUtil.isNull(appId)) {
return false;
}
return licenseMapper.deleteLicense(appId);
}
@Override
public boolean addLicense(String appId, String appKey, String userId) {
if(JsonUtil.isNull(appId) || JsonUtil.isNull(appKey) || JsonUtil.isNull(userId)) {
return false;
}
return licenseMapper.addLicense(appId,appKey,userId);
}
@Override
public boolean updateLicense(String appId, String appKey, String userId) {
if(JsonUtil.isNull(appId) || JsonUtil.isNull(appKey) || JsonUtil.isNull(userId)) {
return false;
}
return licenseMapper.updateLicense(appId,appKey,userId);
}
}
......@@ -5,6 +5,7 @@ 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 iot.sixiang.license.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -35,11 +36,25 @@ public class ServerServiceImpl extends ServiceImpl<ServerMapper, Server> impleme
@Override
public boolean deleteServer(String serverIp) {
if (JsonUtil.isNull(serverIp)) {
return false;
}
return serverMapper.deleteServer(serverIp);
}
@Override
public boolean addServer(String serverIp, int port) {
return baseMapper.addServer(serverIp,port);
if (JsonUtil.isNull(serverIp) || JsonUtil.isNull(String.valueOf(port))) {
return false;
}
return serverMapper.addServer(serverIp,port);
}
@Override
public boolean updateServer(String serverIp, int port) {
if (JsonUtil.isNull(serverIp) || JsonUtil.isNull(String.valueOf(port))) {
return false;
}
return serverMapper.updateServer(serverIp,port);
}
}
......@@ -6,6 +6,7 @@ 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 iot.sixiang.license.util.JsonUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
......@@ -34,12 +35,26 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
}
@Override
public boolean deleteUser(String user) {
return userMapper.deleteUser(user);
public boolean deleteUser(String userId) {
if (JsonUtil.isNull(userId)) {
return false;
}
return userMapper.deleteUser(userId);
}
@Override
public boolean addUser(String userId, String password) {
if (JsonUtil.isNull(userId) || JsonUtil.isNull(password)) {
return false;
}
return userMapper.addUser(userId,password);
}
@Override
public boolean updateUser(String userId, String password) {
if (JsonUtil.isNull(userId) || JsonUtil.isNull(password)) {
return false;
}
return userMapper.updateUser(userId,password);
}
}
......@@ -8,4 +8,8 @@
<delete id="deleteLicense" parameterType="iot.sixiang.license.entity.License">
delete from license where app_id = #{appId}
</delete>
<update id="updateLicense" parameterType="iot.sixiang.license.entity.License">
update license set app_key = #{appKey} , user_id = #{userId} where app_id = #{appId}
</update>
</mapper>
......@@ -8,4 +8,8 @@
<delete id="deleteServer" parameterType="iot.sixiang.license.entity.Server">
delete from server where server_ip = #{serverIp}
</delete>
<update id="updateServer" parameterType="iot.sixiang.license.entity.Server">
update server set port = #{port} where server_ip = #{serverIp}
</update>
</mapper>
......@@ -9,4 +9,8 @@
<delete id="deleteUser" parameterType="iot.sixiang.license.entity.User">
delete from user where user_id = #{userId}
</delete>
<update id="updateUser" parameterType="iot.sixiang.license.entity.User">
update user set password = #{password} where user_id = #{userId}
</update>
</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