|
@@ -20,6 +20,8 @@ import com.szwl.model.bo.ResponseModel;
|
|
|
import com.szwl.model.bo.UserDetailBO;
|
|
|
import com.szwl.model.entity.*;
|
|
|
import com.szwl.model.param.AddLoginUserParam;
|
|
|
+import com.szwl.model.param.UpdateLoginUserParam;
|
|
|
+import com.szwl.model.param.UpdateSysRoleParam;
|
|
|
import com.szwl.service.*;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -78,11 +80,17 @@ public class TAdminController {
|
|
|
param.setAdminId(null);
|
|
|
TAdmin entity = BeanUtil.copyProperties(param,TAdmin.class);
|
|
|
entity.setParentId(parentId);
|
|
|
+ if(parentId.toString().equals("1")){
|
|
|
+ entity.setType(1);
|
|
|
+ }else {
|
|
|
+ entity.setType(3);
|
|
|
+ }
|
|
|
// entity.setParentId(34l);
|
|
|
entity.setIsAdmined(false);
|
|
|
entity.setCreateDate(now);
|
|
|
entity.setModifyDate(now);
|
|
|
entity.setIsLocked(false);
|
|
|
+ entity.setIsEnabled(true);
|
|
|
entity.setLoginFailureCount(0);
|
|
|
entity.setEmail(param.getEmail());
|
|
|
entity.setPhone(param.getPhone());
|
|
@@ -120,11 +128,143 @@ public class TAdminController {
|
|
|
}
|
|
|
return R.ok(entity);
|
|
|
}
|
|
|
+ @ApiOperation(value = "修改子账号")
|
|
|
+ @PostMapping("/updateLoginUser")
|
|
|
+ @Transactional
|
|
|
+ @Audit(type = AuditEnum.UPDATE,content = "#loginUser.name + '修改账号'")
|
|
|
+ public ResponseModel<?> updateLoginUser(@RequestBody @Valid UpdateLoginUserParam param) {
|
|
|
+// public ResponseModel<?> addLoginUser(@RequestBody AddLoginUserParam param) {
|
|
|
+ //获取当前操作人员
|
|
|
+ UserDetailBO loginUser = tokenManager.getLoginUserDetails();
|
|
|
+ // 保存用户实体
|
|
|
+ Date now = new Date();
|
|
|
+ Long parentId = param.getAdminId();
|
|
|
+ if(parentId==null){
|
|
|
+ return R.fail(ResponseCodesEnum.A0001);
|
|
|
+ }
|
|
|
+ param.setAdminId(null);
|
|
|
+// TAdmin entity = BeanUtil.copyProperties(param,TAdmin.class);
|
|
|
+// entity.setParentId(parentId);
|
|
|
+//// entity.setParentId(34l);
|
|
|
+// entity.setIsAdmined(false);
|
|
|
+// entity.setCreateDate(now);
|
|
|
+// entity.setModifyDate(now);
|
|
|
+// entity.setIsLocked(false);
|
|
|
+// entity.setIsEnabled(true);
|
|
|
+// entity.setLoginFailureCount(0);
|
|
|
+// entity.setEmail(param.getEmail());
|
|
|
+// entity.setPhone(param.getPhone());
|
|
|
+// tAdminService.save(entity);
|
|
|
+ LambdaQueryWrapper<TAdmin> query = Wrappers.lambdaQuery();
|
|
|
+ query.eq(TAdmin::getParentId,parentId);
|
|
|
+ query.eq(TAdmin::getId,param.getId());
|
|
|
+ List<TAdmin> list = tAdminService.list(query);
|
|
|
+ if(list.size()>0){
|
|
|
+ TAdmin admin = list.get(0);
|
|
|
+ // 管理的机器 需要再建立一个关系表 type区分全部还是部分
|
|
|
+ String equipmentIds = param.getEquipmentIds();
|
|
|
+ if(StringUtils.isNotEmpty(equipmentIds)){
|
|
|
+ LambdaQueryWrapper<TAdminEquipment> query1 = Wrappers.lambdaQuery();
|
|
|
+ query1.eq(TAdminEquipment::getAdminId,admin.getId());
|
|
|
+ List<TAdminEquipment> list1 = tAdminEquipmentService.list(query1);
|
|
|
+ if(list1.size()>0){
|
|
|
+ TAdminEquipment tAdminEquipment1 = list1.get(0);
|
|
|
+ if(equipmentIds.equals("all")){
|
|
|
+ //管理全部机器
|
|
|
+ //0:全部机器,1:部分机器
|
|
|
+ tAdminEquipment1.setType("0");
|
|
|
+ tAdminEquipment1.setEquipmentIds(null);
|
|
|
+ }else {
|
|
|
+ //部分机器
|
|
|
+ //0:全部机器,1:部分机器
|
|
|
+ tAdminEquipment1.setType("1");
|
|
|
+ tAdminEquipment1.setEquipmentIds(param.getEquipmentIds());
|
|
|
+ }
|
|
|
+ tAdminEquipmentService.updateById(tAdminEquipment1);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<SysUserRole> query1 = Wrappers.lambdaQuery();
|
|
|
+ query1.eq(SysUserRole::getUserId,admin.getId());
|
|
|
+ List<SysUserRole> list1 = sysUserRoleService.list(query1);
|
|
|
+ if(list1.size()>0){
|
|
|
+ for(SysUserRole sysUserRole:list1){
|
|
|
+ sysUserRoleService.removeById(sysUserRole.getId());
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
+ // 保存用户角色关系
|
|
|
+ List<SysUserRole> userRoleList = param.getRoleList()
|
|
|
+ .stream()
|
|
|
+ .map(e -> new SysUserRole().setRoleId(e).setUserId(String.valueOf(admin.getId())) )
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if(CollUtil.isNotEmpty(userRoleList)){
|
|
|
+ sysUserRoleService.saveBatch(userRoleList);
|
|
|
+ }
|
|
|
+ admin.setIsEnabled(param.getIsEnabled());
|
|
|
+ admin.setPhone(param.getPhone());
|
|
|
+ admin.setEmail(param.getEmail());
|
|
|
+ admin.setIsEnabled(param.getIsEnabled());
|
|
|
+ if(StringUtils.isNotEmpty(param.getPassword())){
|
|
|
+ admin.setPassword(param.getPassword());
|
|
|
+ }
|
|
|
+ tAdminService.updateById(admin);
|
|
|
+ log.debug("修改账号 id:{},TAdmin:{}",admin.getId(),admin);
|
|
|
+ return R.ok(admin);
|
|
|
+ }
|
|
|
+ return R.fail(ResponseCodesEnum.A0100);
|
|
|
+ }
|
|
|
+ @ApiOperation(value = "删除子账号")
|
|
|
+ @PostMapping("/deleteLoginUser")
|
|
|
+ @Transactional
|
|
|
+ @Audit(type = AuditEnum.DELETE,content = "#loginUser.name + '删除账号'")
|
|
|
+ public ResponseModel<?> deleteLoginUser(@RequestBody @Valid UpdateLoginUserParam param) {
|
|
|
+// public ResponseModel<?> addLoginUser(@RequestBody AddLoginUserParam param) {
|
|
|
+ //获取当前操作人员
|
|
|
+ UserDetailBO loginUser = tokenManager.getLoginUserDetails();
|
|
|
+ // 保存用户实体
|
|
|
+ Date now = new Date();
|
|
|
+ Long parentId = param.getAdminId();
|
|
|
+ if(parentId==null){
|
|
|
+ return R.fail(ResponseCodesEnum.A0001);
|
|
|
+ }
|
|
|
+ param.setAdminId(null);
|
|
|
+ LambdaQueryWrapper<TAdmin> query = Wrappers.lambdaQuery();
|
|
|
+ query.like(TAdmin::getParentId,parentId);
|
|
|
+ query.like(TAdmin::getId,param.getId());
|
|
|
+ List<TAdmin> list = tAdminService.list(query);
|
|
|
+ if(list.size()>0){
|
|
|
+ TAdmin admin = list.get(0);
|
|
|
+ // 管理的机器 需要再建立一个关系表 type区分全部还是部分
|
|
|
+ String equipmentIds = param.getEquipmentIds();
|
|
|
+ if(StringUtils.isNotEmpty(equipmentIds)){
|
|
|
+ LambdaQueryWrapper<TAdminEquipment> query1 = Wrappers.lambdaQuery();
|
|
|
+ query1.eq(TAdminEquipment::getAdminId,admin.getId());
|
|
|
+ List<TAdminEquipment> list1 = tAdminEquipmentService.list(query1);
|
|
|
+ if(list1.size()>0){
|
|
|
+ TAdminEquipment tAdminEquipment1 = list1.get(0);
|
|
|
+ tAdminEquipmentService.removeById(tAdminEquipment1.getAdminId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 用户角色关系
|
|
|
+ LambdaQueryWrapper<SysUserRole> query2 = Wrappers.lambdaQuery();
|
|
|
+ query2.eq(SysUserRole::getUserId,admin.getId());
|
|
|
+ List<SysUserRole> list2 = sysUserRoleService.list(query2);
|
|
|
+ if(list2.size()>0){
|
|
|
+ SysUserRole sysUserRole = list2.get(0);
|
|
|
+ sysUserRoleService.removeById(sysUserRole.getId());
|
|
|
+ }
|
|
|
+ tAdminService.removeById(admin.getId());
|
|
|
+ log.debug("删除账号 id:{},TAdmin:{}",admin.getId(),admin);
|
|
|
+ return R.ok(admin);
|
|
|
+ }
|
|
|
+ return R.fail(ResponseCodesEnum.A0100);
|
|
|
+ }
|
|
|
@ApiOperation(value = "获取所有子账号信息")
|
|
|
@GetMapping("/getChildDrenAdminList")
|
|
|
public ResponseModel<?> getChildDrenAdminList(String adminId,String userName,String name) {
|
|
|
- List<String> returnList = new ArrayList<>();
|
|
|
+ List<AddLoginUserParam> returnList = new ArrayList<>();
|
|
|
LambdaQueryWrapper<TAdmin> query = Wrappers.lambdaQuery();
|
|
|
query.eq(TAdmin::getParentId,adminId);
|
|
|
if(StringUtils.isNotEmpty(userName)){
|
|
@@ -133,25 +273,71 @@ public class TAdminController {
|
|
|
if(StringUtils.isNotEmpty(name)){
|
|
|
query.eq(TAdmin::getName,name);
|
|
|
}
|
|
|
+ if(StringUtils.isNotEmpty(adminId)){
|
|
|
+ if(adminId.equals("1")){
|
|
|
+// query.in(TAdmin::getType,"1","3");
|
|
|
+ query.eq(TAdmin::getType,"1");
|
|
|
+ }else {
|
|
|
+ query.eq(TAdmin::getType,"3");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ return R.fail(ResponseCodesEnum.A0100);
|
|
|
+ }
|
|
|
query.eq(TAdmin::getIsAdmined,false);
|
|
|
List<TAdmin> list = tAdminService.list(query);
|
|
|
if(list.size()>0){
|
|
|
+
|
|
|
for(TAdmin admin:list){
|
|
|
+ AddLoginUserParam addLoginUserParam = new AddLoginUserParam();
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ addLoginUserParam.setUsername(admin.getUsername());
|
|
|
+ addLoginUserParam.setName(admin.getName());
|
|
|
+ addLoginUserParam.setEmail(admin.getEmail());
|
|
|
+ addLoginUserParam.setPhone(admin.getPhone());
|
|
|
+ addLoginUserParam.setIsEnabled(admin.getIsEnabled());
|
|
|
+ addLoginUserParam.setId(admin.getId());
|
|
|
+ LambdaQueryWrapper<TAdminEquipment> query2 = Wrappers.lambdaQuery();
|
|
|
+ query2.eq(TAdminEquipment::getAdminId,admin.getId());
|
|
|
+ List<TAdminEquipment> list1 = tAdminEquipmentService.list(query2);
|
|
|
+ if(list1.size()>0){
|
|
|
+ TAdminEquipment tAdminEquipment1 = list1.get(0);
|
|
|
+ if(tAdminEquipment1.getType().equals("0")){
|
|
|
+ //管理全部机器
|
|
|
+ //0:全部机器,1:部分机器
|
|
|
+ tAdminEquipment1.setType("0");
|
|
|
+ tAdminEquipment1.setEquipmentIds(null);
|
|
|
+ addLoginUserParam.setEquipmentIds("all");
|
|
|
+ }else {
|
|
|
+ //部分机器
|
|
|
+ //0:全部机器,1:部分机器
|
|
|
+ tAdminEquipment1.setType("1");
|
|
|
+ addLoginUserParam.setEquipmentIds(tAdminEquipment1.getEquipmentIds());
|
|
|
+ }
|
|
|
+ }
|
|
|
LambdaQueryWrapper<SysUserRole> query1 = Wrappers.lambdaQuery();
|
|
|
query1.eq(SysUserRole::getUserId,admin.getId());
|
|
|
List<SysUserRole> roleList = sysUserRoleService.list(query1);
|
|
|
+ List<String> ids = new ArrayList<>();
|
|
|
+ StringBuilder roleName = new StringBuilder();
|
|
|
if(roleList.size()>0){
|
|
|
- SysUserRole sysUserRole = roleList.get(0);
|
|
|
- SysRole sysRole = sysRoleService.getById(sysUserRole.getRoleId());
|
|
|
- String roleName = sysRole.getRoleName();
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.put("roleName", roleName);
|
|
|
- jsonObject.put("userName", admin.getUsername());
|
|
|
- jsonObject.put("name", admin.getName());
|
|
|
- jsonObject.put("email", admin.getEmail());
|
|
|
- jsonObject.put("phone", admin.getPhone());
|
|
|
- returnList.add(jsonObject.toJSONString());
|
|
|
+ for(int i=0;i<roleList.size();i++){
|
|
|
+ SysUserRole sysUserRole = roleList.get(0);
|
|
|
+ ids.add(sysUserRole.getRoleId());
|
|
|
+ SysRole sysRole = sysRoleService.getById(sysUserRole.getRoleId());
|
|
|
+ if(i<roleList.size()-1){
|
|
|
+ roleName.append(sysRole.getRoleName()).append(",");
|
|
|
+ }else {
|
|
|
+ roleName.append(sysRole.getRoleName());
|
|
|
+ }
|
|
|
+// addLoginUserParam.setRoleName(roleName);
|
|
|
+// List<String> list2 = Arrays.asList(sysRole.getMenuCodesJson().split(","));
|
|
|
+// addLoginUserParam.setRoleList(list2);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+ addLoginUserParam.setRoleName(roleName.toString());
|
|
|
+ addLoginUserParam.setRoleList(ids);
|
|
|
+ returnList.add(addLoginUserParam);
|
|
|
}
|
|
|
|
|
|
}
|