Commit f0afbbdc authored by zengtianlai3's avatar zengtianlai3

增加修改功能

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