Commit fa006437 by 李小龙

组织角色

parent 35e57c70
package com.makeit.controller.plat;
import com.makeit.common.dto.BaseBatchIdDTO;
import com.makeit.common.dto.BaseIdDTO;
import com.makeit.common.dto.StatusDTO;
import com.makeit.common.page.PageReqDTO;
import com.makeit.common.page.PageVO;
import com.makeit.common.response.ApiResponseEntity;
import com.makeit.common.response.ApiResponseUtils;
import com.makeit.common.vo.ExcelImportVo;
import com.makeit.exception.BusinessException;
import com.makeit.global.annotation.Action;
import com.makeit.module.admin.dto.plat.PlatUserDTOVO;
import com.makeit.module.admin.dto.plat.PlatUserQueryDTO;
......@@ -20,7 +23,9 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
......@@ -111,6 +116,14 @@ public class PlatUserController {
return ApiResponseUtils.success();
}
@Action(module = "平台端-人员", name = "批量删除", code = "plat:user:del")
@ApiOperation("批量删除")
@PostMapping("delBatch")
public ApiResponseEntity<Void> delBatch(@RequestBody BaseBatchIdDTO dto) {
platUserService.delBatch(dto.getIdList());
return ApiResponseUtils.success();
}
@Action(module = "平台端-人员", name = "改变状态", code = "plat:user:changeStatus")
@ApiOperation("改变状态")
@PostMapping("changeStatus")
......@@ -143,5 +156,15 @@ public class PlatUserController {
return ApiResponseUtils.success(platUserService.getUserDetail());
}
@Action(module = "平台端-人员", name = "批量导入", code = "plat:user:import")
@ApiOperation("批量导入")
@PostMapping("import")
public ApiResponseEntity<ExcelImportVo> importExcel(@RequestParam(value = "excelFile", required = false) MultipartFile excelFile) throws Exception {
if(excelFile == null ){
throw new BusinessException("请上传excel");
}
ExcelImportVo excelImportVo = platUserService.importExcel(excelFile);
return ApiResponseUtils.success(excelImportVo);
}
}
......@@ -46,7 +46,7 @@ public class SaasUserController {
return ApiResponseUtils.success(saasUserService.page(page));
}
@ApiOperation("分页列表")
@ApiOperation("分页列表-免登录")
@PostMapping("pageAuthIgnore")
public ApiResponseEntity<PageVO<SaasUserDTOVO>> pageAuthIgnore(@RequestBody PageReqDTO<SaasUserQueryDTO> page){
return ApiResponseUtils.success(saasUserService.page(page));
......
......@@ -4,8 +4,11 @@ import com.makeit.utils.data.locale.LocaleUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
@Data
@ApiModel("excel导入错误信息VO")
......@@ -41,4 +44,17 @@ public class ExcelErrorVo implements Serializable {
public ExcelErrorVo() {
}
public static void isNotNull(String value,List<ExcelErrorVo> errorVoList, int i, String title) {
if(StringUtils.isBlank(value)) {
errorVoList.add(new ExcelErrorVo(i, title, "数据不为空"));
}
}
public static void notExists(Object object,List<ExcelErrorVo> errorVoList,int i,String title){
if(Objects.isNull(object)){
errorVoList.add(new ExcelErrorVo(i,title,"数据库数据不存在"));
}
}
}
......@@ -32,20 +32,20 @@ public class PlatUserQueryDTO extends BaseOrgDTO {
@ApiModelProperty(value = "要排除的角色id roleId和notRoleId只能用一个")
private String notRoleId;
@ApiModelProperty(value = "关键词 用来搜姓名或者工号")
private String keyword;
@ApiModelProperty(value = "职级")
private Integer postLevel;
@ApiModelProperty(value = "是否从酒店开始 0否 1是")
private String fromHotel;
@ApiModelProperty(value = "是否常用人员 0否 1是")
private String isFrequent;
@ApiModelProperty(value = "标签id")
private String labelId;
// @ApiModelProperty(value = "关键词 用来搜姓名或者工号")
// private String keyword;
//
// @ApiModelProperty(value = "职级")
// private Integer postLevel;
//
// @ApiModelProperty(value = "是否从酒店开始 0否 1是")
// private String fromHotel;
//
// @ApiModelProperty(value = "是否常用人员 0否 1是")
// private String isFrequent;
//
// @ApiModelProperty(value = "标签id")
// private String labelId;
@ApiModelProperty(value = "用户工号集合")
private List<String> accountList;
......
package com.makeit.dto.platform.auth;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
@Data
public class PlatUserImportDTO {
private static final String headDesc = "导入说明:\n" +
"\n" +
"1.带*号为必填项\n" +
"\n" +
"2.手机号和邮箱不可重复\n" +
"\n" +
"3.角色必须为【角色管理】处维护的角色名称\n" +
"\n" +
"4.导入人员默认登录密码为:888888";
@ExcelProperty(value = "姓名*")
private String username;
@ExcelProperty(value = "手机号*")
private String mobile;
@ExcelProperty(value = "邮箱")
private String email;
@ExcelProperty(value = "所属组织*")
private String orgName;
@ExcelProperty(value = "角色*")
private String roleName;
@ExcelProperty(value = "备注")
private String remark;
@ExcelIgnore
private String password = "888888";
}
......@@ -6,6 +6,7 @@ import com.makeit.common.dto.LoginDTO;
import com.makeit.common.dto.StatusDTO;
import com.makeit.common.page.PageReqDTO;
import com.makeit.common.page.PageVO;
import com.makeit.common.vo.ExcelImportVo;
import com.makeit.entity.platform.auth.PlatOrg;
import com.makeit.entity.platform.auth.PlatRole;
import com.makeit.entity.platform.auth.PlatUser;
......@@ -16,6 +17,7 @@ import com.makeit.module.admin.dto.plat.PlatUserQueryDTO;
import com.makeit.module.admin.vo.plat.PlatUserLoginVO;
import com.makeit.vo.platform.auth.PlatPersonDTOVO;
import com.makeit.vo.platform.auth.PlatUserCountVO;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Map;
......@@ -137,4 +139,8 @@ public interface PlatUserService extends IService<PlatUser> {
* @param platUserId
*/
void updatePlatUserTenantId(String tenantId,String platUserId);
void delBatch(List<String> idList);
ExcelImportVo importExcel(MultipartFile excelFile) throws Exception;
}
......@@ -13,6 +13,9 @@ import com.makeit.common.entity.BaseBusEntity;
import com.makeit.common.entity.BaseEntity;
import com.makeit.common.page.PageReqDTO;
import com.makeit.common.page.PageVO;
import com.makeit.common.vo.ExcelErrorVo;
import com.makeit.common.vo.ExcelImportVo;
import com.makeit.dto.platform.auth.PlatUserImportDTO;
import com.makeit.entity.platform.auth.PlatOrg;
import com.makeit.entity.platform.auth.PlatRole;
import com.makeit.entity.platform.auth.PlatRoleMenu;
......@@ -52,6 +55,8 @@ import com.makeit.utils.data.convert.BeanDtoVoUtils;
import com.makeit.utils.data.convert.JsonUtil;
import com.makeit.utils.data.convert.PageUtil;
import com.makeit.utils.data.convert.StreamUtil;
import com.makeit.utils.data.excel.ExcelUtil;
import com.makeit.utils.data.excel.ExcelValidatorUtil;
import com.makeit.utils.data.id.IdGen;
import com.makeit.utils.sql.groupby.DynamicQuery;
import com.makeit.utils.sql.groupby.SqlUtil;
......@@ -70,6 +75,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList;
import java.util.Arrays;
......@@ -247,7 +253,7 @@ public class PlatUserServiceImpl extends ServiceImpl<PlatUserMapper, PlatUser>
throw new BusinessException(CodeMessageEnum.SYSTEM_ERROR_USER_PASSWORD_NOT_BLANK);
}
setPassword(user);
user.setAccount(dto.getMobile());
save(user);
dto.setId(user.getId());
}
......@@ -686,11 +692,7 @@ public class PlatUserServiceImpl extends ServiceImpl<PlatUserMapper, PlatUser>
.like(StringUtils.isNotBlank(dto.getMobile()), PlatUser::getMobile, dto.getMobile())
.eq(StringUtils.isNotBlank(dto.getStatus()), PlatUser::getStatus, dto.getStatus())
.eq(PlatUser::getTenantId, TenantIdUtil.getTenantId())
.and(StringUtils.isNotBlank(dto.getKeyword()), qw -> {
qw.like(StringUtils.isNotBlank(dto.getKeyword()), PlatUser::getUsername, dto.getKeyword())
.or()
.like(StringUtils.isNotBlank(dto.getKeyword()), PlatUser::getAccount, dto.getKeyword());
});
;
roleIdFilter(lambdaQueryWrapper, dto);
......@@ -781,24 +783,24 @@ public class PlatUserServiceImpl extends ServiceImpl<PlatUserMapper, PlatUser>
return PageUtil.toPageVO(tntUserDTOVOList, pageList);
}
private void frequentUser(LambdaQueryWrapper<PlatUser> lambdaQueryWrapper, PlatUserQueryDTO dto) {
if (CommonEnum.YES.getValue().equals(dto.getIsFrequent())) {
List<String> frequentUserIdList = new ArrayList<>(10);
frequentUserIdList.add(-1 + "");
// frequentUserIdList.addAll(
// StreamUtil.map(
// tntFrequentUserService.list(new QueryWrapper<PlatFrequentUser>().lambda()
// .eq(PlatFrequentUser::getPlatUserId, PlatUserUtil.getUserId())
// ),
// PlatFrequentUser::getFrequentUserId)
// );
lambdaQueryWrapper.in(CommonEnum.YES.getValue().equals(dto.getIsFrequent()), PlatUser::getId, frequentUserIdList);
}
}
// private void frequentUser(LambdaQueryWrapper<PlatUser> lambdaQueryWrapper, PlatUserQueryDTO dto) {
// if (CommonEnum.YES.getValue().equals(dto.getIsFrequent())) {
//
// List<String> frequentUserIdList = new ArrayList<>(10);
// frequentUserIdList.add(-1 + "");
//
//// frequentUserIdList.addAll(
//// StreamUtil.map(
//// tntFrequentUserService.list(new QueryWrapper<PlatFrequentUser>().lambda()
//// .eq(PlatFrequentUser::getPlatUserId, PlatUserUtil.getUserId())
//// ),
//// PlatFrequentUser::getFrequentUserId)
//// );
//
// lambdaQueryWrapper.in(CommonEnum.YES.getValue().equals(dto.getIsFrequent()), PlatUser::getId, frequentUserIdList);
//
// }
// }
private void roleIdList(LambdaQueryWrapper<PlatUser> lambdaQueryWrapper, PlatUserQueryDTO dto) {
if (CollectionUtils.isNotEmpty(dto.getRoleIdList())) {
......@@ -825,7 +827,7 @@ public class PlatUserServiceImpl extends ServiceImpl<PlatUserMapper, PlatUser>
//.eq(dto.getPostLevel() != null, PlatUser::getPostLevel, dto.getPostLevel())
.eq(PlatUser::getTenantId, TenantIdUtil.getTenantId());
frequentUser(lambdaQueryWrapper, dto);
//frequentUser(lambdaQueryWrapper, dto);
roleIdList(lambdaQueryWrapper, dto);
......@@ -870,7 +872,7 @@ public class PlatUserServiceImpl extends ServiceImpl<PlatUserMapper, PlatUser>
user.setStatus(CommonEnum.YES.getValue());
//user.setEmpStatus(CommonEnum.YES.getValue());
user.setAccount(dto.getMobile());
save(user);
dto.setId(user.getId());
setRoleList(dto);
......@@ -1224,4 +1226,64 @@ public class PlatUserServiceImpl extends ServiceImpl<PlatUserMapper, PlatUser>
.eq(BaseEntity::getId, platUserId);
this.update(updateWrapper);
}
@Override
@Transactional
public void delBatch(List<String> idList) {
this.removeByIds(idList);
}
/**
* 导入人员
* @param excelFile
*/
@Override
public ExcelImportVo importExcel(MultipartFile excelFile) throws Exception {
List<PlatUserImportDTO> platUserImportDTOS = ExcelUtil.importExcel(null, 3, excelFile, PlatUserImportDTO.class);
LambdaQueryWrapper<PlatOrg> orgLambdaQueryWrapper = new LambdaQueryWrapper<>();
orgLambdaQueryWrapper.select(BaseEntity::getId,PlatOrg::getName);
List<PlatOrg> orgList = platOrgService.list(orgLambdaQueryWrapper);
LambdaQueryWrapper<PlatRole> roleLambdaQueryWrapper = new LambdaQueryWrapper<>();
roleLambdaQueryWrapper.select(BaseEntity::getId,PlatRole::getName);
List<PlatRole> roleList = platRoleService.list(roleLambdaQueryWrapper);
Map<String, String> orgNameMap = orgList.stream().collect(Collectors.toMap(PlatOrg::getName, BaseEntity::getId, (a, b) -> a));
Map<String, String> roleNameMap = roleList.stream().collect(Collectors.toMap(PlatRole::getName, BaseEntity::getId, (a, b) -> a));
LambdaQueryWrapper<PlatUser> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
userLambdaQueryWrapper.select(PlatUser::getMobile,PlatUser::getEmail,BaseEntity::getId);
List<PlatUser> userList = this.list(userLambdaQueryWrapper);
Map<String, String> mobileMap = userList.stream().collect(Collectors.toMap(PlatUser::getMobile, BaseEntity::getId, (a, b) -> a));
Map<String, String> emailMap = userList.stream().collect(Collectors.toMap(PlatUser::getEmail, BaseEntity::getId, (a, b) -> a));
return ExcelValidatorUtil.validate( platUserImportDTOS, list -> {
List<ExcelErrorVo> errorVoList = new ArrayList<>();
int start = 3;
for (int i = 0; i < list.size(); i++) {
PlatUserImportDTO dto = list.get(i);
ExcelErrorVo.isNotNull(dto.getUsername(),errorVoList, start+i,"姓名*");
ExcelErrorVo.isNotNull(dto.getMobile(),errorVoList,start+i,"手机号*");
ExcelErrorVo.isNotNull(dto.getRoleName(),errorVoList,start+i,"角色*");
ExcelErrorVo.isNotNull(dto.getRoleName(),errorVoList,start+i,"所属组织*");
ExcelErrorVo.notExists(orgNameMap.get(dto.getOrgName()),errorVoList,start+i,"所属组织*");
ExcelErrorVo.notExists(roleNameMap.get(dto.getRoleName()),errorVoList,start+i,"角色*");
ExcelErrorVo.notExists(mobileMap.get(dto.getMobile()),errorVoList,start+i,"手机号*");
ExcelErrorVo.notExists(emailMap.get(dto.getEmail()),errorVoList,start+i,"邮箱");
}
if(errorVoList.isEmpty()){
List<PlatUser> platUsers = new ArrayList<>();
list.forEach(vo->{
PlatUser platUser = BeanDtoVoUtils.convert(vo, PlatUser.class);
setPassword(platUser);
platUsers.add(platUser);
});
saveBatch(platUsers);
}
return errorVoList;
},null);
}
}
......@@ -128,7 +128,7 @@ implements PlatTenantService {
TntUserJoinUtil.join(platUserService,voList,qw->qw.eq(PlatUser::getIsTenant, IsTenantAccountEnum.YES.getValue()),
PlatTenantVO::getTntUserId,(t, u) -> {
t.setUserAccount(u.getAccount());
t.setUserAccount(u.getMobile());
t.setUserName(u.getUsername());
}, BaseEntity::getId);
......
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 sign in to comment