Commit 2f051856 authored by cq990612's avatar cq990612

优化代码结构

parent bafc6208
package cn.wisenergy.mapper; package cn.wisenergy.mapper;
import cn.wisenergy.model.app.WorkRole;
import cn.wisenergy.model.app.WorkUser; import cn.wisenergy.model.app.WorkUser;
import cn.wisenergy.model.dto.StatisticsTableDto; import cn.wisenergy.model.dto.StatisticsTableDto;
import cn.wisenergy.model.dto.UserRoleDto; import cn.wisenergy.model.dto.UserRoleDto;
...@@ -38,4 +39,8 @@ public interface WorkUserMapper extends BaseMapper<WorkUser> { ...@@ -38,4 +39,8 @@ public interface WorkUserMapper extends BaseMapper<WorkUser> {
List<UserRoleDto> getUserRoleDto(); List<UserRoleDto> getUserRoleDto();
List<WorkRole> getUserRole(Integer id);
} }
...@@ -21,15 +21,7 @@ ...@@ -21,15 +21,7 @@
<result column="modify_time" property="modifyTime" /> <result column="modify_time" property="modifyTime" />
</resultMap> </resultMap>
<resultMap id="UserRoleMap" type="cn.wisenergy.model.dto.UserRoleDto">
<id column="id" property="id"/>
<result column="name" property="name"/>
<result column="status" property="status"/>
<collection property="workRoles" ofType="cn.wisenergy.model.app.WorkRole">
<id column="role_id" property="id"/>
<result column="role_name" property="name"/>
</collection>
</resultMap>
<sql id="table"> <sql id="table">
work_user work_user
...@@ -112,7 +104,13 @@ ...@@ -112,7 +104,13 @@
</update> </update>
<resultMap id="UserRoleMap" type="cn.wisenergy.model.dto.UserRoleDto">
<id column="id" property="id"/>
<result column="name" property="name"/>
<result column="status" property="status"/>
<collection property="workRoles" column="id" javaType="List" select="getUserRole" ofType="cn.wisenergy.model.app.WorkRole"/>
</resultMap>
<select id="getUserRoleDto" resultMap="UserRoleMap"> <select id="getUserRoleDto" resultMap="UserRoleMap">
select u.id as 'id',u.name as 'name',u.status as 'status',r.id as 'role_id',r.name as 'role_name' select u.id as 'id',u.name as 'name',u.status as 'status',r.id as 'role_id',r.name as 'role_name'
...@@ -120,4 +118,12 @@ from work_user u LEFT JOIN work_user_role ur ON u.id = ur.user_id ...@@ -120,4 +118,12 @@ from work_user u LEFT JOIN work_user_role ur ON u.id = ur.user_id
LEFT JOIN work_role r on ur.role_id = r.id LEFT JOIN work_role r on ur.role_id = r.id
</select> </select>
<select id="getUserRole" resultType="cn.wisenergy.model.app.WorkRole">
SELECT r.id ,r.name
FROM work_user_role ur LEFT JOIN work_role r
ON ur.role_id = r.id
WHERE ur.user_id = #{id}
</select>
</mapper> </mapper>
package cn.wisenergy.model.app;
import lombok.Data;
import java.util.List;
/**
* @Authotr:陈奇
* @QQ1799796883
*/
@Data
public class UserLevelDto {
private Integer userId;
private List<WorkLevel> workLevels;
}
package cn.wisenergy.model.dto; package cn.wisenergy.model.dto;
import cn.wisenergy.model.app.WorkRole; import cn.wisenergy.model.app.WorkRole;
import com.github.pagehelper.PageInfo;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;
...@@ -11,7 +12,7 @@ import java.util.List; ...@@ -11,7 +12,7 @@ import java.util.List;
*/ */
@Data @Data
public class AllRoleAndUserRoleDto { public class AllRoleAndUserRoleDto {
List<UserRoleDto> userRoleDtos; PageInfo pageInfo;
List<WorkRole> workRoles; List<WorkRole> workRoles;
} }
package cn.wisenergy.model.dto; package cn.wisenergy.model.dto;
import cn.wisenergy.model.app.WorkLevel;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
/** /**
* @description: 用户信息返回结果 * @description: 用户信息返回结果
...@@ -48,4 +50,7 @@ public class ResultUser implements Serializable { ...@@ -48,4 +50,7 @@ public class ResultUser implements Serializable {
@ApiModelProperty(name = "day", value = "限制审核的天数") @ApiModelProperty(name = "day", value = "限制审核的天数")
private Integer day; private Integer day;
private List<WorkLevel> workLevels;
} }
...@@ -55,7 +55,7 @@ public interface WorkUserService { ...@@ -55,7 +55,7 @@ public interface WorkUserService {
*/ */
List<OrganizationStructureDto> getOrganizationStructure(); List<OrganizationStructureDto> getOrganizationStructure();
AllRoleAndUserRoleDto getUserRoleDto(); AllRoleAndUserRoleDto getUserRoleDto(Integer page, Integer pageSize);
Boolean modifyRole(Integer userId, List<Integer> roleIds); Boolean modifyRole(Integer userId, List<Integer> roleIds);
} }
...@@ -71,6 +71,7 @@ public class WorkHolidayServiceImpl implements WorkHolidayService { ...@@ -71,6 +71,7 @@ public class WorkHolidayServiceImpl implements WorkHolidayService {
if (isItRedundant(workHoliday, null)) { if (isItRedundant(workHoliday, null)) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.REPEAT_WITH_OLDTIME); throw new BaseCustomException(BASE_RESP_CODE_ENUM.REPEAT_WITH_OLDTIME);
} }
workHoliday.setDayType(1);
int insert = workHolidayMapper.insert(workHoliday); int insert = workHolidayMapper.insert(workHoliday);
return insert > 0; return insert > 0;
} }
...@@ -113,7 +114,9 @@ public class WorkHolidayServiceImpl implements WorkHolidayService { ...@@ -113,7 +114,9 @@ public class WorkHolidayServiceImpl implements WorkHolidayService {
public HolidayAndAutoDto getHolidayAll() { public HolidayAndAutoDto getHolidayAll() {
log.info("WorkHolidayServiceImpl[]getHolidayAll[]"); log.info("WorkHolidayServiceImpl[]getHolidayAll[]");
HolidayAndAutoDto holidayAndAutoDto = new HolidayAndAutoDto(); HolidayAndAutoDto holidayAndAutoDto = new HolidayAndAutoDto();
List<WorkHoliday> workHolidays = workHolidayMapper.selectList(new QueryWrapper<>()); QueryWrapper<WorkHoliday> wrapper = new QueryWrapper<>();
wrapper.eq("day_type", 1);
List<WorkHoliday> workHolidays = workHolidayMapper.selectList(wrapper);
WorkSubmitAdopt submitAdopt = workSubmitAdoptService.getById(1); WorkSubmitAdopt submitAdopt = workSubmitAdoptService.getById(1);
holidayAndAutoDto.setWorkHolidays(workHolidays).setWorkSubmitAdopt(submitAdopt); holidayAndAutoDto.setWorkHolidays(workHolidays).setWorkSubmitAdopt(submitAdopt);
return holidayAndAutoDto; return holidayAndAutoDto;
......
...@@ -17,6 +17,9 @@ import cn.wisenergy.service.WorkSubmitAdoptService; ...@@ -17,6 +17,9 @@ import cn.wisenergy.service.WorkSubmitAdoptService;
import cn.wisenergy.service.WorkUserService; import cn.wisenergy.service.WorkUserService;
import cn.wisenergy.service.utils.UserRoleLevelUtils; import cn.wisenergy.service.utils.UserRoleLevelUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -126,7 +129,7 @@ public class WorkUserServiceImpl implements WorkUserService { ...@@ -126,7 +129,7 @@ public class WorkUserServiceImpl implements WorkUserService {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.DEPT_NOT_HAVE_USER); throw new BaseCustomException(BASE_RESP_CODE_ENUM.DEPT_NOT_HAVE_USER);
} }
ResultUser resultUser ; ResultUser resultUser;
for (OrganizationStructureDto organizationStructureDto : allDeptByAllCentreId) { for (OrganizationStructureDto organizationStructureDto : allDeptByAllCentreId) {
List<DeptUserDto> deptUserDtos = organizationStructureDto.getDeptUserDtos(); List<DeptUserDto> deptUserDtos = organizationStructureDto.getDeptUserDtos();
for (DeptUserDto deptUserDto : deptUserDtos) { for (DeptUserDto deptUserDto : deptUserDtos) {
...@@ -144,8 +147,11 @@ public class WorkUserServiceImpl implements WorkUserService { ...@@ -144,8 +147,11 @@ public class WorkUserServiceImpl implements WorkUserService {
} }
@Override @Override
public AllRoleAndUserRoleDto getUserRoleDto() { public AllRoleAndUserRoleDto getUserRoleDto(Integer page, Integer pageSize) {
log.info("WorkUserServiceImpl[]getUserRoleDto[]"); log.info("WorkUserServiceImpl[]getUserRoleDto[]");
page = page == null ? 1 : page;
pageSize = pageSize == null ? 10 : pageSize;
Page<UserRoleDto> startPage = PageHelper.startPage(page, pageSize);
List<UserRoleDto> userRoleDtos = workUserMapper.getUserRoleDto(); List<UserRoleDto> userRoleDtos = workUserMapper.getUserRoleDto();
if (CollectionUtils.isEmpty(userRoleDtos)) { if (CollectionUtils.isEmpty(userRoleDtos)) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.QUERY_DATA_IS_NULL); throw new BaseCustomException(BASE_RESP_CODE_ENUM.QUERY_DATA_IS_NULL);
...@@ -158,12 +164,16 @@ public class WorkUserServiceImpl implements WorkUserService { ...@@ -158,12 +164,16 @@ public class WorkUserServiceImpl implements WorkUserService {
userRoleDto.setWorkRoles(workRoles); userRoleDto.setWorkRoles(workRoles);
} }
} }
PageInfo<UserRoleDto> pageInfo = startPage.toPageInfo();
pageInfo.setList(userRoleDtos);
List<WorkRole> allWorkRole = UserRoleLevelUtils.getAllWorkRole(); List<WorkRole> allWorkRole = UserRoleLevelUtils.getAllWorkRole();
if (CollectionUtils.isEmpty(allWorkRole)) { if (CollectionUtils.isEmpty(allWorkRole)) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.QUERY_DATA_IS_NULL); throw new BaseCustomException(BASE_RESP_CODE_ENUM.QUERY_DATA_IS_NULL);
} }
PageHelper.startPage(page, pageSize);
AllRoleAndUserRoleDto allRoleAndUserRoleDto = new AllRoleAndUserRoleDto(); AllRoleAndUserRoleDto allRoleAndUserRoleDto = new AllRoleAndUserRoleDto();
allRoleAndUserRoleDto.setUserRoleDtos(userRoleDtos); allRoleAndUserRoleDto.setPageInfo(pageInfo);
allRoleAndUserRoleDto.setWorkRoles(allWorkRole); allRoleAndUserRoleDto.setWorkRoles(allWorkRole);
return allRoleAndUserRoleDto; return allRoleAndUserRoleDto;
} }
...@@ -171,7 +181,7 @@ public class WorkUserServiceImpl implements WorkUserService { ...@@ -171,7 +181,7 @@ public class WorkUserServiceImpl implements WorkUserService {
@Transactional @Transactional
@Override @Override
public Boolean modifyRole(Integer userId, List<Integer> roleIds) { public Boolean modifyRole(Integer userId, List<Integer> roleIds) {
log.info("WorkUserServiceImpl[]modifyRole[].input.param.userId:{},roleIds:{}" + userId,roleIds); log.info("WorkUserServiceImpl[]modifyRole[].input.param.userId:{},roleIds:{}" + userId, roleIds);
WorkUser workUser = workUserMapper.selectById(userId); WorkUser workUser = workUserMapper.selectById(userId);
if (null == workUser) { if (null == workUser) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.QUERY_DATA_IS_NULL); throw new BaseCustomException(BASE_RESP_CODE_ENUM.QUERY_DATA_IS_NULL);
...@@ -229,6 +239,9 @@ public class WorkUserServiceImpl implements WorkUserService { ...@@ -229,6 +239,9 @@ public class WorkUserServiceImpl implements WorkUserService {
//将用户对象转换为dto //将用户对象转换为dto
ResultUser resultUser = getResultUser(user); ResultUser resultUser = getResultUser(user);
resultUser.setDay(byId.getSubmitTime()); resultUser.setDay(byId.getSubmitTime());
List<Integer> roles = UserRoleLevelUtils.getRole(user.getId());
List<Integer> levelIds = UserRoleLevelUtils.getlevelIds(roles);
resultUser.setWorkLevels(UserRoleLevelUtils.getlevelByIds(levelIds));
return resultUser; return resultUser;
} }
...@@ -253,7 +266,7 @@ public class WorkUserServiceImpl implements WorkUserService { ...@@ -253,7 +266,7 @@ public class WorkUserServiceImpl implements WorkUserService {
log.info("WorkUSerServiceImpl[]getResultUser[]input.method"); log.info("WorkUSerServiceImpl[]getResultUser[]input.method");
ResultUser resultUser = new ResultUser(); ResultUser resultUser = new ResultUser();
try { try {
BeanUtils.copyProperties(resultUser,workUser); BeanUtils.copyProperties(resultUser, workUser);
} catch (Exception e) { } catch (Exception e) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.QUERY_USER_INFO_FAIL); throw new BaseCustomException(BASE_RESP_CODE_ENUM.QUERY_USER_INFO_FAIL);
} }
......
...@@ -87,10 +87,14 @@ public class SystemController extends BaseController { ...@@ -87,10 +87,14 @@ public class SystemController extends BaseController {
} }
@ApiOperation(value = "获取账号列表", notes = "获取账号列表", httpMethod = "GET") @ApiOperation(value = "获取账号列表", notes = "获取账号列表", httpMethod = "GET")
@ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "当前页", dataType = "int",required = true),
@ApiImplicitParam(name = "pageSize",value = "记录数",dataType = "int",required = true)
})
@GetMapping("/getAllRole") @GetMapping("/getAllRole")
public Result<AllRoleAndUserRoleDto> getAllRole() { public Result<AllRoleAndUserRoleDto> getAllRole(Integer page,Integer pageSize) {
log.info("SystemController[]getAllRole[]"); log.info("SystemController[]getAllRole[]");
AllRoleAndUserRoleDto allRoleAndUserRoleDto = workUserService.getUserRoleDto(); AllRoleAndUserRoleDto allRoleAndUserRoleDto = workUserService.getUserRoleDto(page,pageSize);
return getResult(allRoleAndUserRoleDto); return getResult(allRoleAndUserRoleDto);
} }
......
package cn.wisenergy.web.admin.controller.app; package cn.wisenergy.web.admin.controller.app;
import cn.wisenergy.common.utils.exception.*; import cn.wisenergy.common.utils.exception.*;
import cn.wisenergy.model.app.UserLevelDto;
import cn.wisenergy.model.app.WorkLevel;
import cn.wisenergy.model.dto.OrganizationStructureDto; import cn.wisenergy.model.dto.OrganizationStructureDto;
import cn.wisenergy.model.dto.ResultUser; import cn.wisenergy.model.dto.ResultUser;
import cn.wisenergy.service.WorkUserService; import cn.wisenergy.service.WorkUserService;
import cn.wisenergy.service.utils.UserRoleLevelUtils;
import cn.wisenergy.web.admin.controller.common.BaseController; import cn.wisenergy.web.admin.controller.common.BaseController;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
...@@ -83,4 +86,17 @@ public class WorkUserController extends BaseController { ...@@ -83,4 +86,17 @@ public class WorkUserController extends BaseController {
return getResult(organizationStructure); return getResult(organizationStructure);
} }
@ApiOperation(value = "权限", notes = "权限", httpMethod = "GET")
@ApiImplicitParam(name = "userId", value = "用户id", dataType = "int")
@GetMapping(value = "/getLevel")
public Result<UserLevelDto> getLevel(Integer userId) {
List<Integer> roles = UserRoleLevelUtils.getRole(userId);
UserLevelDto userLevelDto = new UserLevelDto();
List<Integer> levelIds = UserRoleLevelUtils.getlevelIds(roles);
List<WorkLevel> workLevels = UserRoleLevelUtils.getlevelByIds(levelIds);
userLevelDto.setUserId(userId);
userLevelDto.setWorkLevels(workLevels);
return getResult(userLevelDto);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment