修复用户管理中未查询部门名称的问题

master
toesbieya 6 years ago
parent 8432312e29
commit da98f52718
  1. 2
      java/cloud/schedule/src/main/java/cn/toesbieya/jxc/schedule/task/StatisticTask.java
  2. 2
      java/cloud/web/web-modules/system/src/main/java/cn/toesbieya/jxc/system/service/CustomerService.java
  3. 2
      java/cloud/web/web-modules/system/src/main/java/cn/toesbieya/jxc/system/service/SupplierService.java
  4. 34
      java/cloud/web/web-modules/system/src/main/java/cn/toesbieya/jxc/system/service/UserService.java
  5. 4
      java/cloud/web/web-modules/system/src/main/resources/mapper/SysDepartment.xml
  6. 2
      java/local/src/main/java/cn/toesbieya/jxc/schedule/StatisticTask.java
  7. 2
      java/local/src/main/java/cn/toesbieya/jxc/service/sys/SysCustomerService.java
  8. 6
      java/local/src/main/java/cn/toesbieya/jxc/service/sys/SysSupplierService.java
  9. 34
      java/local/src/main/java/cn/toesbieya/jxc/service/sys/SysUserService.java
  10. 4
      java/local/src/main/resources/mapper/SysDepartment.xml

@ -106,7 +106,7 @@ public class StatisticTask implements CommandLineRunner {
mapper.insertProfitTotal(statProfitTotal);
if (purchaseProfitGoods.size() > 0) {
if (!purchaseProfitGoods.isEmpty()) {
mapper.insertProfitGoodsBatch(purchaseProfitGoods);
}
}

@ -73,7 +73,7 @@ public class CustomerService {
});
//获取关联的行政区域的名称
List<SysRegion> regions = regionIds.size() > 0 ? regionMapper.selectBatchIds(regionIds) : Collections.emptyList();
List<SysRegion> regions = regionIds.isEmpty() ? Collections.emptyList() : regionMapper.selectBatchIds(regionIds);
list.forEach(customerVo -> {
SysRegion matched = Util.find(regions, item -> customerVo.getRegion().equals(item.getId()));

@ -74,7 +74,7 @@ public class SupplierService {
});
//获取关联的行政区域的名称
List<SysRegion> regions = regionIds.size() > 0 ? regionMapper.selectBatchIds(regionIds) : Collections.emptyList();
List<SysRegion> regions = regionIds.isEmpty() ? Collections.emptyList() : regionMapper.selectBatchIds(regionIds);
list.forEach(supplierVo -> {
SysRegion matched = Util.find(regions, item -> supplierVo.getRegion().equals(item.getId()));
if (matched != null) {

@ -2,6 +2,7 @@ package cn.toesbieya.jxc.system.service;
import cn.toesbieya.jxc.common.model.entity.SysRole;
import cn.toesbieya.jxc.common.model.entity.SysUser;
import cn.toesbieya.jxc.common.model.vo.DepartmentVo;
import cn.toesbieya.jxc.common.model.vo.Result;
import cn.toesbieya.jxc.common.model.vo.UserVo;
import cn.toesbieya.jxc.common.util.Util;
@ -30,6 +31,8 @@ public class UserService {
private SysUserMapper userMapper;
@Resource
private SysRoleMapper roleMapper;
@Resource
private DepartmentService departmentService;
public PageResult<UserVo> search(UserSearch vo) {
Integer id = vo.getId();
@ -56,35 +59,49 @@ public class UserService {
int userNum = users.size();
//当前在线的用户id
Set<Integer> onlineUserIds = WebSocketUtil.getOnlineUserIds();
//传递给前端的结果集
List<UserVo> result = new ArrayList<>(userNum);
//当前在线的用户id
Set<Integer> onlineUserIds = WebSocketUtil.getOnlineUserIds();
//查询得到的用户的角色id
Set<Integer> userRoleIds = new HashSet<>(userNum);
//查询得到的用户的部门id
Set<Integer> userDeptIds = new HashSet<>(userNum);
users.forEach(user -> {
result.add(new UserVo(user));
Integer rid = user.getRole();
Integer deptId = user.getDept();
if (rid != null) userRoleIds.add(rid);
if (deptId != null) userDeptIds.add(deptId);
});
List<SysRole> roles = userRoleIds.size() > 0 ? roleMapper.selectBatchIds(userRoleIds) : Collections.emptyList();
List<SysRole> roles = userRoleIds.isEmpty() ? Collections.emptyList() : roleMapper.selectBatchIds(userRoleIds);
List<DepartmentVo> depts = userDeptIds.isEmpty() ? Collections.emptyList() : departmentService.getAll();
result.forEach(userVo -> {
//设置在线情况
userVo.setOnline(Util.some(onlineUserIds, i -> userVo.getId().equals(i)));
Integer userRoleId = userVo.getRole();
if (userRoleId != null) {
//设置用户的角色名称
SysRole matched = Util.find(roles, i -> i.getId().equals(userRoleId));
//设置用户的角色名称
Integer roleId = userVo.getRole();
if (roleId != null) {
SysRole matched = Util.find(roles, i -> i.getId().equals(roleId));
if (matched != null) {
userVo.setRoleName(matched.getName());
}
}
//设置部门名称
Integer deptId = userVo.getDept();
if (deptId != null) {
DepartmentVo matched = Util.find(depts, i -> i.getId().equals(deptId));
if (matched != null) {
userVo.setDeptName(matched.getFullname());
}
}
});
return new PageResult<>(pageResult.getTotal(), result);
@ -162,6 +179,7 @@ public class UserService {
return rows > 0 ? Result.success() : Result.fail("重置失败,未匹配到用户");
}
//用户名重复时返回true
private boolean isNameExist(String name, Integer id) {
Integer num = userMapper.selectCount(
Wrappers.lambdaQuery(SysUser.class)

@ -15,7 +15,7 @@
where c.pid = t.id
)
select *
from t;
from t
</select>
<select id="selectParentsById" resultType="cn.toesbieya.jxc.common.model.vo.DepartmentVo">
@ -32,6 +32,6 @@
where c.id = t.pid
)
select *
from t;
from t
</select>
</mapper>

@ -106,7 +106,7 @@ public class StatisticTask {
mapper.insertProfitTotal(statProfitTotal);
if (purchaseProfitGoods.size() > 0) {
if (!purchaseProfitGoods.isEmpty()) {
mapper.insertProfitGoodsBatch(purchaseProfitGoods);
}
}

@ -74,7 +74,7 @@ public class SysCustomerService {
});
//获取关联的行政区域的名称
List<SysRegion> regions = regionIds.size() > 0 ? regionMapper.selectBatchIds(regionIds) : Collections.emptyList();
List<SysRegion> regions = regionIds.isEmpty() ? Collections.emptyList():regionMapper.selectBatchIds(regionIds);
list.forEach(customerVo -> {
SysRegion matched = Util.find(regions, item -> customerVo.getRegion().equals(item.getId()));

@ -74,7 +74,7 @@ public class SysSupplierService {
});
//获取关联的行政区域的名称
List<SysRegion> regions = regionIds.size() > 0 ? regionMapper.selectBatchIds(regionIds) : Collections.emptyList();
List<SysRegion> regions = regionIds.isEmpty() ? Collections.emptyList() : regionMapper.selectBatchIds(regionIds);
list.forEach(supplierVo -> {
SysRegion matched = Util.find(regions, item -> supplierVo.getRegion().equals(item.getId()));
if (matched != null) {
@ -88,7 +88,7 @@ public class SysSupplierService {
@UserAction("'添加供应商:'+ #supplier.name")
public Result add(SysSupplier supplier) {
if (isNameExist(supplier.getName(), null)) {
return Result.fail(String.format("添加失败,供应商【%s】已存在",supplier.getName()));
return Result.fail(String.format("添加失败,供应商【%s】已存在", supplier.getName()));
}
int rows = supplierMapper.insert(supplier);
return rows > 0 ? Result.success("添加成功") : Result.fail("添加失败");
@ -100,7 +100,7 @@ public class SysSupplierService {
String name = supplier.getName();
if (isNameExist(name, id)) {
return Result.fail(String.format("修改失败,供应商【%s】已存在",name));
return Result.fail(String.format("修改失败,供应商【%s】已存在", name));
}
supplierMapper.update(

@ -5,6 +5,7 @@ import cn.toesbieya.jxc.mapper.SysRoleMapper;
import cn.toesbieya.jxc.mapper.SysUserMapper;
import cn.toesbieya.jxc.model.entity.SysRole;
import cn.toesbieya.jxc.model.entity.SysUser;
import cn.toesbieya.jxc.model.vo.DepartmentVo;
import cn.toesbieya.jxc.model.vo.Result;
import cn.toesbieya.jxc.model.vo.UserVo;
import cn.toesbieya.jxc.model.vo.result.PageResult;
@ -30,6 +31,8 @@ public class SysUserService {
private SysUserMapper userMapper;
@Resource
private SysRoleMapper roleMapper;
@Resource
private SysDepartmentService departmentService;
public PageResult<UserVo> search(UserSearch vo) {
Integer id = vo.getId();
@ -56,35 +59,49 @@ public class SysUserService {
int userNum = users.size();
//当前在线的用户id
Set<Integer> onlineUserIds = WebSocketUtil.getOnlineUserIds();
//传递给前端的结果集
List<UserVo> result = new ArrayList<>(userNum);
//当前在线的用户id
Set<Integer> onlineUserIds = WebSocketUtil.getOnlineUserIds();
//查询得到的用户的角色id
Set<Integer> userRoleIds = new HashSet<>(userNum);
//查询得到的用户的部门id
Set<Integer> userDeptIds = new HashSet<>(userNum);
users.forEach(user -> {
result.add(new UserVo(user));
Integer rid = user.getRole();
Integer deptId = user.getDept();
if (rid != null) userRoleIds.add(rid);
if (deptId != null) userDeptIds.add(deptId);
});
List<SysRole> roles = userRoleIds.size() > 0 ? roleMapper.selectBatchIds(userRoleIds) : Collections.emptyList();
List<SysRole> roles = userRoleIds.isEmpty() ? Collections.emptyList() : roleMapper.selectBatchIds(userRoleIds);
List<DepartmentVo> depts = userDeptIds.isEmpty() ? Collections.emptyList() : departmentService.getAll();
result.forEach(userVo -> {
//设置在线情况
userVo.setOnline(Util.some(onlineUserIds, i -> userVo.getId().equals(i)));
Integer userRoleId = userVo.getRole();
if (userRoleId != null) {
//设置用户的角色名称
SysRole matched = Util.find(roles, i -> i.getId().equals(userRoleId));
//设置用户的角色名称
Integer roleId = userVo.getRole();
if (roleId != null) {
SysRole matched = Util.find(roles, i -> i.getId().equals(roleId));
if (matched != null) {
userVo.setRoleName(matched.getName());
}
}
//设置部门名称
Integer deptId = userVo.getDept();
if (deptId != null) {
DepartmentVo matched = Util.find(depts, i -> i.getId().equals(deptId));
if (matched != null) {
userVo.setDeptName(matched.getFullname());
}
}
});
return new PageResult<>(pageResult.getTotal(), result);
@ -162,6 +179,7 @@ public class SysUserService {
return rows > 0 ? Result.success() : Result.fail("重置失败,未匹配到用户");
}
//用户名重复时返回true
private boolean isNameExist(String name, Integer id) {
Integer num = userMapper.selectCount(
Wrappers.lambdaQuery(SysUser.class)

@ -15,7 +15,7 @@
where c.pid = t.id
)
select *
from t;
from t
</select>
<select id="selectParentsById" resultType="cn.toesbieya.jxc.model.vo.DepartmentVo">
@ -32,6 +32,6 @@
where c.id = t.pid
)
select *
from t;
from t
</select>
</mapper>
Loading…
Cancel
Save