Commit dcda0114 authored by ma's avatar ma

完善删除用户逻辑

parent 47d59500
......@@ -13,14 +13,12 @@ import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import iot.sixiang.license.entity.Permission;
import iot.sixiang.license.entity.Report;
import iot.sixiang.license.entity.User;
import iot.sixiang.license.entity.UserPermission;
import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.jwt.UserUtils;
import iot.sixiang.license.log.BusinessType;
import iot.sixiang.license.log.MyLog;
import iot.sixiang.license.mapper.UserMapper;
import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.PageResult;
......@@ -28,16 +26,12 @@ import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.dto.AssignUserPermissionDTO;
import iot.sixiang.license.model.dto.UpdateNotifyDTO;
import iot.sixiang.license.model.vo.*;
import iot.sixiang.license.service.PermissionService;
import iot.sixiang.license.service.ReportService;
import iot.sixiang.license.service.UserPermissionService;
import iot.sixiang.license.service.UserService;
import iot.sixiang.license.service.*;
import iot.sixiang.license.util.CommonUtil;
import iot.sixiang.license.util.EmailUtils;
import iot.sixiang.license.util.TreeUtil;
import iot.sixiang.license.xss.XssUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.WebDataBinder;
......@@ -45,7 +39,6 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
......@@ -63,12 +56,16 @@ public class UserController {
@Resource
EmailUtils emailUtils;
@Autowired
@Resource
private UserService userService;
@Resource
private PermissionService permissionService;
@Resource
private UserPermissionService userPermissionService;
@Resource
private ApplyService applyService;
@Resource
private DeviceService deviceService;
@Value("${rsa.private_key}")
private String PRIVATE_KRY;
......@@ -147,6 +144,12 @@ public class UserController {
if (!CommonUtil.checkPermission(userPermissions, 2)) {
throw new IotLicenseException(403, "您无删除用户权限!");
}
List<UserChildIdVO> childUser = userService.getChildUser(Integer.parseInt(userId));
if (!childUser.isEmpty()) {
throw new IotLicenseException(403, "该账户存在子账号,请先删除所有子账号!");
}
deviceService.deleteByUserId(Integer.parseInt(userId));
applyService.deleteByUserId(Integer.parseInt(userId));
boolean res = userService.deleteUser(Integer.parseInt(userId));
userPermissionService.deleteUserPermission(Integer.parseInt(userId));
UserUtils.removeToken(userId);
......
......@@ -21,4 +21,6 @@ public interface ApplyMapper extends BaseMapper<Apply> {
List<AppVo> getAppList(String appName, List<Integer> userChildIds);
Apply getApplyByAppName(String appName);
void deleteByUserId(Integer userId);
}
......@@ -18,4 +18,6 @@ public interface DeviceMapper extends BaseMapper<Device> {
boolean addDevice(String sn, String appId);
int updateDeviceById(Device device);
void deleteByUserId(int userId);
}
......@@ -20,4 +20,6 @@ public interface ApplyService extends IService<Apply> {
boolean addApply(String appName, String appKey, int userId);
PageInfoModel<AppVo> getAppList(int pageNo, int pageSize, String appName, List<Integer> userChildIds);
void deleteByUserId(Integer userId);
}
......@@ -30,4 +30,6 @@ public interface DeviceService extends IService<Device> {
ResResult getBindStatus(TerminalDevieUnBindDTO terminalDevieUnBindDTO);
BaseResult platFormBind(PlatFormBindDTO platFormBindDTO);
void deleteByUserId(int userId);
}
......@@ -71,4 +71,9 @@ public class ApplyServiceImpl extends ServiceImpl<ApplyMapper, Apply> implements
objectPageInfoModel.setResult(result);
return objectPageInfoModel;
}
@Override
public void deleteByUserId(Integer userId) {
applyMapper.deleteByUserId(userId);
}
}
......@@ -180,4 +180,9 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
return BaseResult.failed();
}
}
@Override
public void deleteByUserId(int userId) {
deviceMapper.deleteByUserId(userId);
}
}
......@@ -6,9 +6,15 @@
app.app_id, app.app_name, app.app_key, app.create_time, app.update_time, us.user_id,
COUNT(sn) AS deviceCount, us.user_name, us.company
</sql>
<insert id="addApply" parameterType="iot.sixiang.license.entity.Apply">
insert into apply(app_id,app_name, app_key, user_id, create_time, update_time) values (#{appId}, #{appName}, #{appKey}, #{userId}, now(), now())
</insert>
<delete id="deleteByUserId">
delete from `apply` where user_id = #{userId}
</delete>
<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
......
<?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">
<delete id="deleteByUserId">
delete device from device,apply,`user` WHERE device.app_id = apply.app_id
and user.user_id = apply.user_id and user.user_id = #{userId}
</delete>
<select id="getDeviceList" resultType="iot.sixiang.license.model.vo.DeviceVo">
SELECT de.device_id, de.app_id, app_name,user_name,sn,sn_bind,de.status,de.create_time,de.update_time,de.device_id IN (select
......
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