diff --git a/src/main/java/com/cm/serviceusercenter/controller/resources/system/user/UserImResourceController.java b/src/main/java/com/cm/serviceusercenter/controller/resources/system/user/UserImResourceController.java new file mode 100644 index 0000000..607a7a9 --- /dev/null +++ b/src/main/java/com/cm/serviceusercenter/controller/resources/system/user/UserImResourceController.java @@ -0,0 +1,42 @@ +package com.cm.serviceusercenter.controller.resources.system.user; + +import com.cm.common.constants.ISystemConstant; +import com.cm.common.exception.SearchException; +import com.cm.common.result.ErrorResult; +import com.cm.common.result.SuccessResultLayImData; +import com.cm.serviceusercenter.controller.BaseController; +import com.cm.serviceusercenter.service.system.user.IUserImService; +import io.swagger.annotations.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.Map; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: UserImResourceController + * @Description: 用户即时消息 + * @Author: wanggeng + * @Date: 2021/1/15 10:53 上午 + * @Version: 1.0 + */ +@Api(tags = ISystemConstant.API_TAGS_RESOURCE_PREFIX + "用户信息管理") +@RestController +@RequestMapping(ISystemConstant.RESOURCE_PREFIX + "/user/im") +public class UserImResourceController extends BaseController { + + @Autowired + private IUserImService userImService; + + @ApiOperation(value = "获取部门用户信息", notes = "获取部门用户信息接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("listdepartmentuser") + public List listDepartmentUser() throws SearchException { + Map params = requestParams(); + return userImService.listDepartmentUser(params); + } + +} diff --git a/src/main/java/com/cm/serviceusercenter/controller/resources/system/user/UserResourceController.java b/src/main/java/com/cm/serviceusercenter/controller/resources/system/user/UserResourceController.java index b268665..b633dc6 100644 --- a/src/main/java/com/cm/serviceusercenter/controller/resources/system/user/UserResourceController.java +++ b/src/main/java/com/cm/serviceusercenter/controller/resources/system/user/UserResourceController.java @@ -74,7 +74,7 @@ public class UserResourceController extends BaseController { }) @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @PostMapping("listdepartmentusers/{departmentId}") - public List listdepartmentusers(@PathVariable("departmentId") String departmentId) throws SearchException { + public List listDepartmentUsers(@PathVariable("departmentId") String departmentId) throws SearchException { Map params = getParams(); params.put("departmentId", departmentId); return userService.listSelectDepartmentUser(params); diff --git a/src/main/java/com/cm/serviceusercenter/service/system/department/IDepartmentService.java b/src/main/java/com/cm/serviceusercenter/service/system/department/IDepartmentService.java index 4874f10..d5f01fc 100644 --- a/src/main/java/com/cm/serviceusercenter/service/system/department/IDepartmentService.java +++ b/src/main/java/com/cm/serviceusercenter/service/system/department/IDepartmentService.java @@ -370,4 +370,12 @@ public interface IDepartmentService { * @throws SearchException */ List listDepartmentResourceByUserIds(List userIds) throws SearchException; + + /** + * 部门列表 + * @param params + * @return + * @throws SearchException + */ + List listDepartmentSimple(Map params) throws SearchException; } diff --git a/src/main/java/com/cm/serviceusercenter/service/system/department/impl/DepartmentServiceImpl.java b/src/main/java/com/cm/serviceusercenter/service/system/department/impl/DepartmentServiceImpl.java index 4f8e8e3..0aa5a5c 100644 --- a/src/main/java/com/cm/serviceusercenter/service/system/department/impl/DepartmentServiceImpl.java +++ b/src/main/java/com/cm/serviceusercenter/service/system/department/impl/DepartmentServiceImpl.java @@ -587,6 +587,11 @@ public class DepartmentServiceImpl extends BaseService implements IDepartmentSer return departmentDao.listDepartmentResource(params); } + @Override + public List listDepartmentSimple(Map params) throws SearchException { + return departmentDao.listDepartmentSimple(params); + } + /** * 合并组织到指定组织 * diff --git a/src/main/java/com/cm/serviceusercenter/service/system/user/IUserImService.java b/src/main/java/com/cm/serviceusercenter/service/system/user/IUserImService.java new file mode 100644 index 0000000..cf11712 --- /dev/null +++ b/src/main/java/com/cm/serviceusercenter/service/system/user/IUserImService.java @@ -0,0 +1,29 @@ +package com.cm.serviceusercenter.service.system.user; + +import com.cm.common.exception.SearchException; +import com.cm.common.result.SuccessResultLayImData; + +import java.util.List; +import java.util.Map; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: IUserImService + * @Description: 即使消息 + * @Author: wanggeng + * @Date: 2021/1/15 10:55 上午 + * @Version: 1.0 + */ +public interface IUserImService { + + /** + * 获取部门用户信息 + * + * @param params + * @return + * @throws SearchException + */ + List listDepartmentUser(Map params) throws SearchException; +} diff --git a/src/main/java/com/cm/serviceusercenter/service/system/user/impl/UserImService.java b/src/main/java/com/cm/serviceusercenter/service/system/user/impl/UserImService.java new file mode 100644 index 0000000..4c42672 --- /dev/null +++ b/src/main/java/com/cm/serviceusercenter/service/system/user/impl/UserImService.java @@ -0,0 +1,82 @@ +package com.cm.serviceusercenter.service.system.user.impl; + +import com.alibaba.druid.util.StringUtils; +import com.cm.common.exception.SearchException; +import com.cm.common.plugin.pojo.bos.department.DepartmentResourceBO; +import com.cm.common.result.SuccessResultLayImData; +import com.cm.serviceusercenter.pojo.dtos.DepartmentUserDTO; +import com.cm.serviceusercenter.pojo.dtos.department.DepartmentSimpleDTO; +import com.cm.serviceusercenter.service.BaseService; +import com.cm.serviceusercenter.service.system.department.IDepartmentService; +import com.cm.serviceusercenter.service.system.user.IUserImService; +import com.cm.serviceusercenter.service.system.user.IUserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: UserImService + * @Description: 即使消息 + * @Author: wanggeng + * @Date: 2021/1/15 10:55 上午 + * @Version: 1.0 + */ +@Service +public class UserImService extends BaseService implements IUserImService { + + @Autowired + private IDepartmentService departmentService; + @Autowired + private IUserService userService; + + @Override + public List listDepartmentUser(Map params) throws SearchException { + params.put("orderByCode", "orderByCode"); + // 所有部门 + List departmentSimpleDTOs = departmentService.listDepartmentSimple(params); + // 所有部门用户 + List departmentUserDTOs = userService.listDepartmentUsers(params); + // 组装 + List friends = new ArrayList<>(); + for (int i = 0; i < departmentSimpleDTOs.size(); i++) { + DepartmentSimpleDTO departmentSimpleDTO = departmentSimpleDTOs.get(i); + Map departmentUserDTOMap = new HashMap<>(16); + for (int j = 0; j < departmentUserDTOs.size(); j++) { + DepartmentUserDTO departmentUserDTO = departmentUserDTOs.get(j); + if (!StringUtils.equals(departmentSimpleDTO.getDepartmentId(), departmentUserDTO.getDepartmentId())) { + continue; + } + departmentUserDTOMap.put(departmentUserDTO.getDepartmentId(), departmentUserDTO); + departmentUserDTOs.remove(j); + j--; + } + if (departmentUserDTOMap.isEmpty()) { + departmentSimpleDTOs.remove(i); + i--; + continue; + } + SuccessResultLayImData.Friend friend = new SuccessResultLayImData.Friend(); + friend.setId(departmentSimpleDTO.getDepartmentId()); + friend.setGroupname(departmentSimpleDTO.getDepartmentName()); + List users = new ArrayList<>(); + friend.setList(users); + for (Map.Entry kv : departmentUserDTOMap.entrySet()) { + DepartmentUserDTO departmentUserDTO = kv.getValue(); + SuccessResultLayImData.User user = new SuccessResultLayImData.User(); + user.setId(departmentUserDTO.getUserId()); + user.setUsername(departmentUserDTO.getUserName()); + user.setAvatar(departmentUserDTO.getUserAvatar()); + users.add(user); + } + friends.add(friend); + } + return friends; + } +} diff --git a/src/main/java/com/cm/serviceusercenter/service/system/user/impl/UserServiceImpl.java b/src/main/java/com/cm/serviceusercenter/service/system/user/impl/UserServiceImpl.java index 7794a98..2d2afa7 100644 --- a/src/main/java/com/cm/serviceusercenter/service/system/user/impl/UserServiceImpl.java +++ b/src/main/java/com/cm/serviceusercenter/service/system/user/impl/UserServiceImpl.java @@ -802,7 +802,10 @@ public class UserServiceImpl extends BaseService implements IUserService { @Override public List listDepartmentUsers(Map params) throws SearchException { - return userDao.listDepartmentUsers(params); + List departmentUserDTOs = userDao.listDepartmentUsers(params); + List destDepartmentUserDTOs = Arrays.asList(new DepartmentUserDTO[departmentUserDTOs.size()]); + Collections.copy(destDepartmentUserDTOs, departmentUserDTOs); + return new ArrayList<>(destDepartmentUserDTOs); } @Override diff --git a/src/main/resources/mybatis/mapper/system/department/department-mapper.xml b/src/main/resources/mybatis/mapper/system/department/department-mapper.xml index c4275a4..343777c 100644 --- a/src/main/resources/mybatis/mapper/system/department/department-mapper.xml +++ b/src/main/resources/mybatis/mapper/system/department/department-mapper.xml @@ -827,6 +827,10 @@ AND gmt_modified = ]]> #{updateDate} + + ORDER BY + department_code +