|
|
@@ -5,6 +5,9 @@ import cn.hutool.core.convert.Convert;
|
|
|
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.commons.entity.dto.SysSystemAddParam;
|
|
|
+import com.jzg.commons.entity.dto.SysSystemEditParam;
|
|
|
+import com.jzg.commons.entity.dto.SysSystemParam;
|
|
|
import com.jzg.commons.entity.enums.YesNoEnum;
|
|
|
import com.jzg.commons.entity.po.*;
|
|
|
import com.jzg.commons.entity.vo.SysSystemPermsVo;
|
|
|
@@ -14,7 +17,6 @@ import com.jzg.commons.util.StringUtils;
|
|
|
import com.jzg.commons.util.idgen.IdGenerate;
|
|
|
import com.jzg.mapper.*;
|
|
|
import com.jzg.service.SysSystemService;
|
|
|
-import com.jzg.commons.util.PasswordUtils;
|
|
|
import com.jzg.util.MinioUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -23,7 +25,6 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -112,28 +113,9 @@ public class SysSystemServiceImpl extends ServiceImpl<SysSystemMapper, SysSystem
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Page<SysSystem> queryPage(Page page, SysSystemVo sysSystemVo) {
|
|
|
- LambdaQueryWrapper<SysSystem> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(StringUtils.isNotEmpty(sysSystemVo.getProvinceId()),
|
|
|
- SysSystem::getProvinceId, sysSystemVo.getProvinceId())
|
|
|
- .eq(StringUtils.isNotEmpty(sysSystemVo.getCityId()),
|
|
|
- SysSystem::getCityId, sysSystemVo.getCityId())
|
|
|
- .eq(StringUtils.isNotEmpty(sysSystemVo.getDistrictId()),
|
|
|
- SysSystem::getDistrictId, sysSystemVo.getDistrictId())
|
|
|
- .eq(StringUtils.isNotNull(sysSystemVo.getSysType()),
|
|
|
- SysSystem::getSysType, sysSystemVo.getSysType())
|
|
|
- .eq(StringUtils.isNotEmpty(sysSystemVo.getSearchValue()),
|
|
|
- SysSystem::getSysName, sysSystemVo.getSearchValue()).or()
|
|
|
- .eq(StringUtils.isNotEmpty(sysSystemVo.getSearchValue()),
|
|
|
- SysSystem::getSysCode, sysSystemVo.getSearchValue())
|
|
|
- .eq(StringUtils.isNotEmpty(sysSystemVo.getContactValue()),
|
|
|
- SysSystem::getContact, sysSystemVo.getContactValue()).or()
|
|
|
- .eq(StringUtils.isNotEmpty(sysSystemVo.getContactValue()),
|
|
|
- SysSystem::getTelephone, sysSystemVo.getContactValue())
|
|
|
- .eq(SysSystem::getIsTenant, 1)
|
|
|
- .ne(SysSystem::getParentId, 0);
|
|
|
- Page<SysSystem> sysPage = page(page, wrapper);
|
|
|
- List<SysSystem> sysSystemList = sysPage.getRecords();
|
|
|
+ public Page<SysSystemVo> queryPage(Page page, SysSystemParam param) {
|
|
|
+ Page<SysSystemVo> sysPage = baseMapper.queryPage(page, param);
|
|
|
+ List<SysSystemVo> sysSystemList = sysPage.getRecords();
|
|
|
if(CollUtil.isNotEmpty(sysSystemList)){
|
|
|
sysSystemList.forEach(sysSystem->{
|
|
|
SysUploadFiles files = sysUploadFilesMapper.selectById(sysSystem.getSysIcon());
|
|
|
@@ -146,38 +128,48 @@ public class SysSystemServiceImpl extends ServiceImpl<SysSystemMapper, SysSystem
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public SysSystem queryById(String sysId) {
|
|
|
+ public SysSystemVo queryById(String sysId) {
|
|
|
SysSystem system = this.getById(sysId);
|
|
|
-
|
|
|
- if(StringUtils.isNotEmpty(system.getSysIcon())){
|
|
|
+ SysSystemVo vo = new SysSystemVo();
|
|
|
+ BeanUtils.copyProperties(system,vo);
|
|
|
+ if(StringUtils.isNotEmpty(vo.getSysIcon())){
|
|
|
SysUploadFiles files = sysUploadFilesMapper.selectById(system.getSysIcon());
|
|
|
if(StringUtils.isNotNull(files)){
|
|
|
- system.setSysIconUrl(minioUtils.getPresignedObjectUrl(bucketName,files.getFileName()));
|
|
|
+ vo.setSysIconUrl(minioUtils.getPresignedObjectUrl(bucketName,files.getFileName()));
|
|
|
}
|
|
|
}
|
|
|
SysUser user = sysUserMapper.selectById(system.getUserId());
|
|
|
- system.setUserName(user.getUsername());
|
|
|
- system.setUserAccount(user.getMobile());
|
|
|
- return system;
|
|
|
+ vo.setUserName(user.getUsername());
|
|
|
+ vo.setUserAccount(user.getMobile());
|
|
|
+ return vo;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void sysAdd(SysSystemVo sysSystemVo) {
|
|
|
+ public void sysAdd(SysSystemAddParam param) {
|
|
|
SysSystem sysSystem = new SysSystem();
|
|
|
- BeanUtils.copyProperties(sysSystemVo, sysSystem);
|
|
|
+ BeanUtils.copyProperties(param, sysSystem);
|
|
|
sysSystem.setIsTenant(1);
|
|
|
sysSystem.setAvailable(1);
|
|
|
sysSystem.setParentId("1");
|
|
|
this.save(sysSystem);
|
|
|
|
|
|
/** 初始化租户管理员信息 */
|
|
|
- // 新增管理员用户
|
|
|
- SysUser user = new SysUser(sysSystemVo);
|
|
|
- sysUserMapper.insert(user);
|
|
|
+ List<SysUser> userList = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
|
|
|
+ .eq(SysUser::getMobile, param.getUserAccount())
|
|
|
+ );
|
|
|
+ String userId = null;
|
|
|
+ if(CollUtil.isNotEmpty(userList)){
|
|
|
+ userId = userList.get(0).getId();
|
|
|
+ }else{
|
|
|
+ // 新增管理员用户
|
|
|
+ SysUser user = new SysUser(param);
|
|
|
+ sysUserMapper.insert(user);
|
|
|
+ userId = user.getId();
|
|
|
+ }
|
|
|
// 新增用户机构关联信息
|
|
|
SysUserJzgInfo info = new SysUserJzgInfo();
|
|
|
- info.setUserId(user.getId());
|
|
|
+ info.setUserId(userId);
|
|
|
info.setDeptId("");// 后期放最顶级的机构
|
|
|
sysUserJzgInfoMapper.insert(info);
|
|
|
// 新增管理员角色
|
|
|
@@ -185,28 +177,41 @@ public class SysSystemServiceImpl extends ServiceImpl<SysSystemMapper, SysSystem
|
|
|
sysRoleMapper.insert(role);
|
|
|
// 关联用户角色
|
|
|
SysUserRole userRole = new SysUserRole();
|
|
|
- userRole.setUserId(user.getId());
|
|
|
+ userRole.setUserId(userId);
|
|
|
userRole.setRoleId(role.getId());
|
|
|
sysUserRoleMapper.insert(userRole);
|
|
|
// 租户绑定管理员信息
|
|
|
- sysSystem.setUserId(user.getId());
|
|
|
+ sysSystem.setUserId(userId);
|
|
|
this.updateById(sysSystem);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void sysEdit(SysSystemVo sysSystemVo) {
|
|
|
+ public void sysEdit(SysSystemEditParam param) {
|
|
|
SysSystem sysSystem = new SysSystem();
|
|
|
- BeanUtils.copyProperties(sysSystemVo, sysSystem);
|
|
|
+ BeanUtils.copyProperties(param, sysSystem);
|
|
|
updateById(sysSystem);
|
|
|
SysSystem system = getById(sysSystem.getId());
|
|
|
// 修改管理员信息
|
|
|
- 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);
|
|
|
+
|
|
|
+ List<SysUser> userList = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>()
|
|
|
+ .eq(SysUser::getMobile, param.getUserAccount())
|
|
|
+ );
|
|
|
+ SysUser sysUser;
|
|
|
+ if(CollUtil.isNotEmpty(userList)){
|
|
|
+ sysUser = userList.get(0);
|
|
|
+ sysUser.setUsername(param.getUserName());
|
|
|
+ sysUserMapper.updateById(sysUser);
|
|
|
+ }else{
|
|
|
+ // 新增管理员用户
|
|
|
+ sysUser = new SysUser(param);
|
|
|
+ sysUserMapper.insert(sysUser);
|
|
|
+ // 新增用户机构关联信息
|
|
|
+ SysUserJzgInfo info = new SysUserJzgInfo();
|
|
|
+ info.setUserId(sysUser.getId());
|
|
|
+ info.setDeptId("");// 后期放最顶级的机构
|
|
|
+ sysUserJzgInfoMapper.insert(info);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -249,12 +254,30 @@ public class SysSystemServiceImpl extends ServiceImpl<SysSystemMapper, SysSystem
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<String> sysDeleteValidDept(SysSystemVo sysSystemVo) {
|
|
|
- List<String> deptIdList = sysDeptMapper.selectList(new LambdaQueryWrapper<SysDept>()
|
|
|
+ public String sysDeleteValid(List<String> ids) {
|
|
|
+ List<SysSystem> systemList = baseMapper.selectBatchIds(ids);
|
|
|
+ String errorStr = null;
|
|
|
+ if(CollUtil.isNotEmpty(systemList)){
|
|
|
+ for (SysSystem sysSystem : systemList) {
|
|
|
+ List<String> deptIdList = sysDeptMapper.selectList(new LambdaQueryWrapper<SysDept>()
|
|
|
.select(SysDept::getId)
|
|
|
- .eq(SysDept::getSystemCode, sysSystemVo.getSysCode())).stream()
|
|
|
- .map(SysDept::getId).collect(Collectors.toList());
|
|
|
- return deptIdList;
|
|
|
+ .eq(SysDept::getSystemCode, sysSystem.getSysCode())).stream()
|
|
|
+ .map(SysDept::getId).collect(Collectors.toList());
|
|
|
+ if (CollUtil.isNotEmpty(deptIdList)) {
|
|
|
+ errorStr = "租户["+sysSystem.getSysName()+"]还有部分子机构,请将这些子机构删除后,再进行删除!";
|
|
|
+ return errorStr;
|
|
|
+ }
|
|
|
+ if(CollUtil.isNotEmpty(deptIdList)){
|
|
|
+ Long count = sysUserJzgInfoMapper.selectCount(new LambdaQueryWrapper<SysUserJzgInfo>()
|
|
|
+ .in(SysUserJzgInfo::getDeptId, deptIdList));
|
|
|
+ if(count > 0){
|
|
|
+ errorStr = "租户["+sysSystem.getSysName()+"]还有部分员工,请将这些员工变更机构或者删除后,再进行删除!";
|
|
|
+ return errorStr;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return errorStr;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -267,6 +290,11 @@ public class SysSystemServiceImpl extends ServiceImpl<SysSystemMapper, SysSystem
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public boolean deleteByIds(List<String> ids) {
|
|
|
+ return baseMapper.deleteByIds(ids) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|