fix: 企标列表权限和批量删除权限不对应问题

This commit is contained in:
2023-11-30 08:58:36 +08:00
parent 4cbf399b15
commit 823e167cd0
4 changed files with 233 additions and 28 deletions
@@ -1187,14 +1187,6 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
**/
@Override
public String deleteByIdsAndModule(String ids, String module) {
// 如果是企标的话 校验删除的ids是否有权限
if (TableNameEnum.ENTERPRISE_STANDARDS.getValue().equals(module)) {
boolean auth = esAuthUserService.verifyESDeleteAuth(ids, UserUtils.getUserId());
if (!auth) {
throw new JeroBootException(MessageUtils.getMessage(ResultCommon.NO_AUTH));
}
}
// 获取要操作的表名
String tableName = TableNameEnum.getTableName(module);
// 获取要删除的id集合
@@ -585,21 +585,16 @@ public class EnterpriseStandardAuthUserServiceImpl extends ServiceImpl<Enterpris
if (StringUtils.isBlank(ids)) {
throw new JeroBootException(ResultCommon.EMPTY_COMMON, "ids不能为空");
}
List<String> idList = Arrays.asList(ids.split(","));
// 管理员有所有权限
SysUser currentUser = sysUserService.getById(userId);
String username = currentUser.getUsername();
// 获取当前用户的角色roleCode
List<String> roleList = sysUserRoleService.getRole(currentUser.getUsername());
if (roleList != null && roleList.stream().anyMatch(adminRoleCodeList :: contains)) {
return true;
String[] idList = ids.split(",");
List<Map<String, Object>> records = new ArrayList<>();
for (String id : idList) {
Map<String, Object> map = new HashMap<>();
map.put(FieldCommon.ID, id);
records.add(map);
}
// 创建人可以删除
List<LawsEnterpriseStandard> list = enterpriseStandardService.list(new LambdaQueryWrapper<LawsEnterpriseStandard>().in(LawsEnterpriseStandard::getId, idList));
// 如果不是创建人,则直接返回false
for (LawsEnterpriseStandard es : list) {
if (!es.getCreateBy().equals(username)) {
this.delFlagSet(records);
for (Map<String, Object> map : records) {
if (!(boolean) map.get(FieldCommon.DEL_FLAG)) {
return false;
}
}
@@ -150,7 +150,12 @@ public class LawsEnterpriseController {
@PostMapping(value = "deleteByIdsAndModule")
@ApiOperationSupport(order = 8)
@RequiresPermissions("enterpriseStandard:search")
public Result<String> deleteByIdsAndModule(@RequestBody Map<String,Object> parameterMap) {
public Result<String> deleteByIdsAndModule(@RequestBody Map<String, Object> parameterMap) {
// 如果是企标的话 校验删除的ids是否有权限
boolean auth = esAuthUserService.verifyESDeleteAuth((String) parameterMap.get("ids"), UserUtils.getUserId());
if (!auth) {
throw new JeroBootException(MessageUtils.getMessage(ResultCommon.NO_AUTH));
}
//删除标准时同步删除这个标准的收藏数据
lawsStandardCollectionService.deleteByStandardId((String) parameterMap.get("ids"));
lawsStandardSharingService.deleteByStandardId((String) parameterMap.get("ids"));
@@ -14,11 +14,17 @@ import com.jero.common.util.MessageUtils;
import com.jero.common.util.MinioUtil;
import com.jero.modules.activiti.util.ExcelUtils;
import com.jero.modules.laws.common.constant.FieldCommon;
import com.jero.modules.laws.enterprise.entity.EnterpriseStandardAuthUser;
import com.jero.modules.laws.enterprise.entity.OldSystemImportDTO;
import com.jero.modules.laws.enterprise.service.ESSequenceNumberProvider;
import com.jero.modules.laws.enterprise.service.EnterpriseStandardAuthDeptService;
import com.jero.modules.laws.enterprise.service.EnterpriseStandardAuthUserService;
import com.jero.modules.laws.enterprise.util.EnterpriseStandardUtil;
import com.jero.modules.laws.home.common.LawsHomeSearchCommon;
import com.jero.modules.laws.home.service.ILawsHomeSearchService;
import com.jero.modules.laws.oldSystem.entity.ESAuthAll;
import com.jero.modules.laws.oldSystem.entity.ESAuthDept;
import com.jero.modules.laws.oldSystem.entity.ESAuthUser;
import com.jero.modules.laws.oldSystem.entity.OldSystemDepartRelation;
import com.jero.modules.laws.oldSystem.service.OldSystemDepartRelationService;
import com.jero.modules.laws.standard.entity.LawsDomesticStandard;
@@ -99,6 +105,12 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
@Resource
private IOSSFileService ossFileService;
@Resource
private EnterpriseStandardAuthUserService esAuthUserService;
@Resource
private EnterpriseStandardAuthDeptService esAuthDeptService;
@Resource
private ILawsHomeSearchService lawsHomeSearchService;
@@ -203,18 +215,218 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
this.oldSysGBImport(gbDatalist, errImportList);
}
}
this.exportWithExcel(response, errImportList);
this.exportWithExcel(response, errImportList, "OldSystemStandardErrorData.xls");
}
public void exportWithExcel(HttpServletResponse response, List<OldSystemImportDTO> dtoList) {
@Override
public void importOldESAuthAllExcel(MultipartFile file, HttpServletResponse response) {
// 验证文件是否为压缩格式file.getContentType()).contains("xls")
if (!Objects.requireNonNull(file.getOriginalFilename()).contains("xls")) {
throw new JeroBootException("文件格式不正确,请上传Excel。");
}
ImportParams params = new ImportParams();
params.setTitleRows(0);
params.setNeedSave(true);
// 获取数据
List<ESAuthAll> datalist;
try {
// 获取当前时间戳(毫秒)
long startTime = System.currentTimeMillis();
@Cleanup
InputStream inputStream = file.getInputStream();
datalist = ExcelImportUtil.importExcel(inputStream, ESAuthAll.class, params);
// 删除空行
for (int i = 0; i < datalist.size(); i++) {
ESAuthAll data = datalist.get(i);
if (data.isEmptyRow()) {
datalist.remove(i);
i--;
}
}
log.info("获取数据成功,数据条数:{}", datalist.size());
// 获取当前时间戳(毫秒)
long endTime = System.currentTimeMillis();
// 计算执行时间(毫秒)
long executionTime = endTime - startTime;
log.info("数据转换执行时间:" + executionTime + " 毫秒");
// 筛选有oldSystemId的数据
LambdaQueryWrapper<LawsEnterpriseStandard> esWrapper = new LambdaQueryWrapper<>();
List<LawsEnterpriseStandard> esList = this.list(esWrapper.isNotNull(LawsEnterpriseStandard::getOldSystemId));
Map<String, LawsEnterpriseStandard> esMap = esList.stream().collect(Collectors.toMap(LawsEnterpriseStandard::getOldSystemId, o -> o));
// 遍历dataList 并且构造Update语句
List<LawsEnterpriseStandard> updateList = new ArrayList<>();
for (ESAuthAll data : datalist) {
LawsEnterpriseStandard es = esMap.get(data.getStandardId());
if (es != null) {
es.setGradeClassification("1");
updateList.add(es);
}
}
// 批量更新
this.updateBatchById(updateList, updateList.size());
log.info("企标所有人权限导入成功");
} catch (Exception e) {
log.error("导入失败;{}", e.getMessage());
}
}
@Override
public void importOldESAuthUserExcel(MultipartFile file, HttpServletResponse response) {
// 验证文件是否为压缩格式file.getContentType()).contains("xls")
if (!Objects.requireNonNull(file.getOriginalFilename()).contains("xls")) {
throw new JeroBootException("文件格式不正确,请上传Excel。");
}
ImportParams params = new ImportParams();
params.setTitleRows(0);
params.setNeedSave(true);
// 获取数据
List<ESAuthUser> datalist;
try {
// 获取当前时间戳(毫秒)
long startTime = System.currentTimeMillis();
@Cleanup
InputStream inputStream = file.getInputStream();
datalist = ExcelImportUtil.importExcel(inputStream, ESAuthUser.class, params);
// 删除空行
for (int i = 0; i < datalist.size(); i++) {
ESAuthUser data = datalist.get(i);
if (data.isEmptyRow()) {
datalist.remove(i);
i--;
}
}
log.info("获取数据成功,数据条数:{}", datalist.size());
// 获取当前时间戳(毫秒)
long endTime = System.currentTimeMillis();
// 计算执行时间(毫秒)
long executionTime = endTime - startTime;
log.info("数据转换执行时间:" + executionTime + " 毫秒");
// 筛选有oldSystemId的数据
LambdaQueryWrapper<LawsEnterpriseStandard> esWrapper = new LambdaQueryWrapper<>();
List<LawsEnterpriseStandard> esList = this.list(esWrapper.isNotNull(LawsEnterpriseStandard::getOldSystemId));
Map<String, LawsEnterpriseStandard> esMap = esList.stream().collect(Collectors.toMap(LawsEnterpriseStandard::getOldSystemId, o -> o));
Map<String, List<ESAuthUser>> auMap = datalist.stream().collect(Collectors.groupingBy(ESAuthUser::getStandardId));
List<SysUser> userlist = sysUserService.list();
Map<String, SysUser> userMap = userlist.stream().collect(Collectors.toMap(SysUser::getUsername, o -> o));
// 构造一个2099-12-31的Date时间
Calendar calendar = Calendar.getInstance();
// 设置日期为2099年12月31日
calendar.set(Calendar.YEAR, 2099);
calendar.set(Calendar.MONTH, Calendar.DECEMBER); // 12月,注意月份是从0开始的,所以12表示12月
calendar.set(Calendar.DAY_OF_MONTH, 31);
calendar.set(Calendar.HOUR_OF_DAY, 23); // 设置小时为23(表示23:59:59
calendar.set(Calendar.MINUTE, 59); // 设置分钟为59
calendar.set(Calendar.SECOND, 59); // 设置秒钟为59
// 获取Date对象
Date date = calendar.getTime();
List<EnterpriseStandardAuthUser> authUserList = new ArrayList<>();
// 遍历esMap
for (Map.Entry<String, LawsEnterpriseStandard> entry : esMap.entrySet()) {
LawsEnterpriseStandard es = entry.getValue();
String standardId = es.getId();
List<ESAuthUser> auList = auMap.get(standardId);
if (auList != null) {
for (ESAuthUser au : auList) {
EnterpriseStandardAuthUser authUser = new EnterpriseStandardAuthUser();
authUser.setStandardId(es.getId());
String userId = userMap.get(au.getWorkNumber()).getId();
authUser.setAuthUser(userId);
authUser.setAuthExpireDate(date);
authUserList.add(authUser);
}
}
}
esAuthUserService.saveBatch(authUserList, authUserList.size());
log.info("企标个人权限导入成功");
} catch (Exception e) {
log.error("导入失败;{}", e.getMessage());
}
}
@Override
public void importOldESAuthDeptExcel(MultipartFile file, HttpServletResponse response) {
// 验证文件是否为压缩格式file.getContentType()).contains("xls")
if (!Objects.requireNonNull(file.getOriginalFilename()).contains("xls")) {
throw new JeroBootException("文件格式不正确,请上传Excel。");
}
ImportParams params = new ImportParams();
params.setTitleRows(0);
params.setNeedSave(true);
// 获取数据
List<ESAuthDept> datalist;
try {
// 获取当前时间戳(毫秒)
long startTime = System.currentTimeMillis();
@Cleanup
InputStream inputStream = file.getInputStream();
datalist = ExcelImportUtil.importExcel(inputStream, ESAuthDept.class, params);
// 删除空行
for (int i = 0; i < datalist.size(); i++) {
ESAuthDept data = datalist.get(i);
if (data.isEmptyRow()) {
datalist.remove(i);
i--;
}
}
log.info("获取数据成功,数据条数:{}", datalist.size());
// 获取当前时间戳(毫秒)
long endTime = System.currentTimeMillis();
// 计算执行时间(毫秒)
long executionTime = endTime - startTime;
log.info("数据转换执行时间:" + executionTime + " 毫秒");
// 筛选有oldSystemId的数据
LambdaQueryWrapper<LawsEnterpriseStandard> esWrapper = new LambdaQueryWrapper<>();
List<LawsEnterpriseStandard> esList = this.list(esWrapper.isNotNull(LawsEnterpriseStandard::getOldSystemId));
Map<String, LawsEnterpriseStandard> esMap = esList.stream().collect(Collectors.toMap(LawsEnterpriseStandard::getOldSystemId, o -> o));
Map<String, List<ESAuthDept>> auMap = datalist.stream().collect(Collectors.groupingBy(ESAuthDept::getStandardId));
List<SysDepart> deptlist = departService.list();
// Map<String, SysDepart> deptMap = deptlist.stream().collect(Collectors.toMap(SysDepart::getUsername, o -> o));
//
// List<EnterpriseStandardAuthUser> authUserList = new ArrayList<>();
// // 遍历esMap
// for (Map.Entry<String, LawsEnterpriseStandard> entry : esMap.entrySet()) {
// LawsEnterpriseStandard es = entry.getValue();
// String standardId = es.getId();
// List<ESAuthUser> auList = auMap.get(standardId);
// if (auList != null) {
// for (ESAuthUser au : auList) {
// EnterpriseStandardAuthUser authUser = new EnterpriseStandardAuthUser();
// authUser.setStandardId(es.getId());
// String userId = userMap.get(au.getWorkNumber()).getId();
// authUser.setAuthUser(userId);
// authUser.setAuthExpireDate(date);
// authUserList.add(authUser);
// }
// }
// }
// esAuthUserService.saveBatch(authUserList, authUserList.size());
log.info("企标所有人权限导入成功");
} catch (Exception e) {
log.error("导入失败;{}", e.getMessage());
}
}
public <T> void exportWithExcel(HttpServletResponse response, List<T> dtoList, String fileName) {
try {
// 设置导出参数
ExportParams exportParams = new ExportParams(null, "ProblemOldStandard.xls"); // 可以为标题添加更多的配置
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, OldSystemImportDTO.class, dtoList);
ExportParams exportParams = new ExportParams(null, fileName); // 可以为标题添加更多的配置
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, dtoList.get(0).getClass(), dtoList);
// 设置响应头和内容类型
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=ProblemOldStandard.xls");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
// 写出到响应流
workbook.write(response.getOutputStream());
@@ -225,6 +437,7 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
}
}
private void oldSysGBImport(List<OldSystemImportDTO> gbDatalist, List<OldSystemImportDTO> errImportList) {
// 找到所有人 并且用 姓名加工号做key
Map<String, SysUser> allUserMap = sysUserService.list().stream().collect(Collectors.toMap(o -> o.getRealname() + o.getUsername(), o -> o));