|
|
@@ -1,29 +1,27 @@
|
|
|
package com.jzg.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.jzg.core.page.HttpResult;
|
|
|
-import com.jzg.entity.po.SysSystem;
|
|
|
-import com.jzg.entity.po.SysSystemPerms;
|
|
|
+import com.jzg.entity.po.*;
|
|
|
import com.jzg.entity.vo.SysSystemPermsVo;
|
|
|
import com.jzg.entity.vo.SysSystemVo;
|
|
|
-import com.jzg.mapper.SysSystemMapper;
|
|
|
-import com.jzg.mapper.SysSystemPermsMapper;
|
|
|
+import com.jzg.exception.SystemException;
|
|
|
+import com.jzg.mapper.*;
|
|
|
import com.jzg.service.SysSystemService;
|
|
|
+import com.jzg.util.PasswordUtils;
|
|
|
import com.jzg.util.StringUtils;
|
|
|
import com.jzg.util.idgen.IdGenerate;
|
|
|
-import jakarta.validation.constraints.NotEmpty;
|
|
|
-import jodd.util.StringUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
/**
|
|
|
* 租户管理表 服务层处理 sys_system
|
|
|
*
|
|
|
@@ -35,6 +33,16 @@ public class SysSystemServiceImpl extends ServiceImpl<SysSystemMapper, SysSystem
|
|
|
|
|
|
@Autowired
|
|
|
private SysSystemPermsMapper sysSystemPermsMapper;
|
|
|
+ @Autowired
|
|
|
+ private SysUploadFilesMapper sysUploadFilesMapper;
|
|
|
+ @Autowired
|
|
|
+ private SysUserMapper sysUserMapper;
|
|
|
+ @Autowired
|
|
|
+ private SysRoleMapper sysRoleMapper;
|
|
|
+ @Autowired
|
|
|
+ private SysUserRoleMapper sysUserRoleMapper;
|
|
|
+ @Value("${minio.download-url}")
|
|
|
+ private String downloadUrl;
|
|
|
|
|
|
@Override
|
|
|
public boolean updatePerms(SysSystemPermsVo sysSystemPermsVo) {
|
|
|
@@ -113,49 +121,75 @@ public class SysSystemServiceImpl extends ServiceImpl<SysSystemMapper, SysSystem
|
|
|
SysSystem::getTelephone, sysSystemVo.getContactValue())
|
|
|
.eq(SysSystem::getIsTenant, 1);
|
|
|
Page<SysSystem> sysPage = page(page, wrapper);
|
|
|
+ List<SysSystem> sysSystemList = sysPage.getRecords();
|
|
|
+ if(CollUtil.isNotEmpty(sysSystemList)){
|
|
|
+ sysSystemList.forEach(sysSystem->{
|
|
|
+ SysUploadFiles files = sysUploadFilesMapper.selectById(sysSystem.getSysIcon());
|
|
|
+ if(StringUtils.isNotNull(files)){
|
|
|
+ sysSystem.setSysIconUrl(downloadUrl + files.getFileName());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
return sysPage;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public SysSystem queryById(String sysId) {
|
|
|
- return this.baseMapper.selectById(sysId);
|
|
|
+ SysSystem system = this.getById(sysId);
|
|
|
+ if(StringUtils.isNotEmpty(system.getSysIcon())){
|
|
|
+ SysUploadFiles files = sysUploadFilesMapper.selectById(system.getSysIcon());
|
|
|
+ if(StringUtils.isNotNull(files)){
|
|
|
+ system.setSysIconUrl(downloadUrl + files.getFileName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SysUser user = sysUserMapper.selectById(system.getUserId());
|
|
|
+ SysSystemVo sysSystemVo = new SysSystemVo();
|
|
|
+ BeanUtils.copyProperties(system, sysSystemVo);
|
|
|
+ sysSystemVo.setUserName(user.getUsername());
|
|
|
+ sysSystemVo.setUserAccount(user.getMobile());
|
|
|
+ return system;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean sysAdd(SysSystemVo sysSystemVo) {
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void sysAdd(SysSystemVo sysSystemVo) {
|
|
|
SysSystem sysSystem = new SysSystem();
|
|
|
BeanUtils.copyProperties(sysSystemVo, sysSystem);
|
|
|
sysSystem.setIsTenant(1);
|
|
|
sysSystem.setAvailable(1);
|
|
|
this.save(sysSystem);
|
|
|
- /** 初始化租户管理员信息 */
|
|
|
- return this.initAdmin(sysSystem);
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 初始化租户管理员信息
|
|
|
- * @param sysSystem
|
|
|
- * @return
|
|
|
- */
|
|
|
- private boolean initAdmin(SysSystem sysSystem) {
|
|
|
- boolean flag = false;
|
|
|
+ /** 初始化租户管理员信息 */
|
|
|
// 新增管理员用户
|
|
|
-
|
|
|
+ SysUser user = new SysUser(sysSystem, sysSystemVo);
|
|
|
+ sysUserMapper.insert(user);
|
|
|
// 新增管理员角色
|
|
|
-
|
|
|
+ SysRole role = new SysRole(sysSystem.getSysCode());
|
|
|
+ sysRoleMapper.insert(role);
|
|
|
// 关联用户角色
|
|
|
- return flag;
|
|
|
+ SysUserRole userRole = new SysUserRole();
|
|
|
+ userRole.setUserId(user.getId());
|
|
|
+ userRole.setRoleId(role.getId());
|
|
|
+ sysUserRoleMapper.insert(userRole);
|
|
|
+ // 租户绑定管理员信息
|
|
|
+ sysSystem.setUserId(user.getId());
|
|
|
+ this.updateById(sysSystem);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean sysEdit(SysSystemVo sysSystemVo) {
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void sysEdit(SysSystemVo sysSystemVo) {
|
|
|
SysSystem sysSystem = new SysSystem();
|
|
|
BeanUtils.copyProperties(sysSystemVo, sysSystem);
|
|
|
-
|
|
|
+ updateById(sysSystem);
|
|
|
+ SysSystem system = getById(sysSystem.getId());
|
|
|
// 修改管理员信息
|
|
|
-
|
|
|
- // 初始化租户基本信息
|
|
|
- return updateById(sysSystem);
|
|
|
+ SysUser user = sysUserMapper.selectById(system.getUserId());
|
|
|
+ user.setUsername(sysSystemVo.getUserName());
|
|
|
+ String encryptedPassword = PasswordUtils.encode(sysSystemVo.getPassword(),user.getSalt());
|
|
|
+ user.setPassword(encryptedPassword);
|
|
|
+ user.setMobile(sysSystemVo.getUserAccount());
|
|
|
+ sysUserMapper.updateById(user);
|
|
|
}
|
|
|
|
|
|
@Override
|