|
@@ -0,0 +1,365 @@
|
|
|
+package org.springblade.business.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.jetbrains.annotations.Nullable;
|
|
|
+import org.springblade.business.entity.InformationQuery;
|
|
|
+import org.springblade.business.entity.RecycleBin;
|
|
|
+import org.springblade.business.entity.RecycleBinInfo;
|
|
|
+import org.springblade.business.mapper.RecycleBinInfoMapper;
|
|
|
+import org.springblade.business.mapper.RecycleBinMapper;
|
|
|
+import org.springblade.business.service.IInformationQueryService;
|
|
|
+import org.springblade.business.service.IRecycleBinInfoService;
|
|
|
+import org.springblade.business.vo.RecycleBinInfoVO;
|
|
|
+import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
+import org.springblade.core.log.exception.ServiceException;
|
|
|
+import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
+import org.springblade.core.mp.support.Condition;
|
|
|
+import org.springblade.core.redis.cache.BladeRedis;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springblade.core.tool.utils.DateUtil;
|
|
|
+import org.springblade.core.tool.utils.StringUtil;
|
|
|
+import org.springblade.manager.entity.ContractInfo;
|
|
|
+import org.springblade.manager.entity.WbsTreeContract;
|
|
|
+import org.springblade.system.user.entity.User;
|
|
|
+import org.springblade.system.user.vo.UserVO2;
|
|
|
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Slf4j
|
|
|
+public class RecycleBinInfoServiceImpl extends BaseServiceImpl<RecycleBinInfoMapper, RecycleBinInfo> implements IRecycleBinInfoService {
|
|
|
+
|
|
|
+ private final RecycleBinInfoMapper recycleBinInfoMapper;
|
|
|
+
|
|
|
+ private final JdbcTemplate jdbcTemplate;
|
|
|
+
|
|
|
+ private final BladeRedis bladeRedis;
|
|
|
+
|
|
|
+ private final IInformationQueryService informationQueryService;
|
|
|
+
|
|
|
+ private final static String BLADE_RECYCLE_USER_CACHE_KEY = "blade:recycle:user:cache:";
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<RecycleBinInfo> selectPage(RecycleBinInfoVO recycleBinInfoVO) {
|
|
|
+ IPage<RecycleBinInfo> iPage = Condition.getPage(recycleBinInfoVO);
|
|
|
+ return this.recycleBinInfoMapper.page(iPage, recycleBinInfoVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Collection<UserVO2> queryUser(Long contractId, Integer isRecycleBin, String name) {
|
|
|
+ String str = bladeRedis.get(BLADE_RECYCLE_USER_CACHE_KEY + contractId);
|
|
|
+ List<UserVO2> userVOs = getUserVOs(str);
|
|
|
+ List<UserVO2> userVOs1;
|
|
|
+ if (isRecycleBin == 1) {
|
|
|
+ userVOs1 = getUpdateUser(contractId);
|
|
|
+ } else {
|
|
|
+ userVOs1 = new ArrayList<>();
|
|
|
+ }
|
|
|
+ if (userVOs.isEmpty()) {
|
|
|
+ List<RecycleBinInfo> list = this.list(Wrappers.<RecycleBinInfo>lambdaQuery()
|
|
|
+ .select(RecycleBinInfo::getCreateUser, RecycleBinInfo::getCreateUserName)
|
|
|
+ .eq(RecycleBinInfo::getContractId, contractId).eq(RecycleBinInfo::getDelType, 2)
|
|
|
+ .groupBy(Arrays.asList(RecycleBinInfo::getCreateUser,RecycleBinInfo::getCreateUserName)));
|
|
|
+ if (list != null && !list.isEmpty()) {
|
|
|
+ list.forEach(item -> {
|
|
|
+ UserVO2 vo2 = new UserVO2();
|
|
|
+ vo2.setId(item.getCreateUser());
|
|
|
+ vo2.setName(item.getCreateUserName());
|
|
|
+ userVOs.add(vo2);
|
|
|
+ });
|
|
|
+ bladeRedis.set(BLADE_RECYCLE_USER_CACHE_KEY + contractId, JSON.toJSONString(userVOs));
|
|
|
+ bladeRedis.expire(BLADE_RECYCLE_USER_CACHE_KEY + contractId, 60 * 60);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!userVOs.isEmpty()) {
|
|
|
+ if (name != null && !name.isEmpty()) {
|
|
|
+ List<UserVO2> collect = userVOs.stream().filter(item -> item.getName() != null && item.getName().contains(name)).collect(Collectors.toList());
|
|
|
+ Set<UserVO2> set = new HashSet<>(collect);
|
|
|
+ set.addAll(userVOs1.stream().filter(item -> item.getName() != null && item.getName().contains(name)).collect(Collectors.toList()));
|
|
|
+ return set;
|
|
|
+ }
|
|
|
+ Set<UserVO2> set = new HashSet<>(userVOs);
|
|
|
+ set.addAll(userVOs1);
|
|
|
+ return set;
|
|
|
+ }
|
|
|
+ return userVOs;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Collection<RecycleBinInfo> queryOperation(Long id) {
|
|
|
+ RecycleBinInfo info = this.getById(id);
|
|
|
+ if (info == null || !StringUtil.hasText(info.getOperationId())) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ return this.list(Wrappers.<RecycleBinInfo>lambdaQuery().eq(RecycleBinInfo::getOperationId, info.getOperationId()).eq(RecycleBinInfo::getDelType, info.getDelType()).eq(RecycleBinInfo::getStatus, info.getStatus()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean saveRecycleBinInfoByWbsTreeContract(String ids, String rootIds) {
|
|
|
+ if (ids == null || ids.isEmpty()) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ List<WbsTreeContract> query = jdbcTemplate.query("select * from m_wbs_tree_contract where p_key_id in ( " + ids + ") and is_deleted = 0 and type = 1", new BeanPropertyRowMapper<>(WbsTreeContract.class));
|
|
|
+ if (query.isEmpty()) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ List<WbsTreeContract> rootContracts = new ArrayList<>();
|
|
|
+ List<String> parentIds = new ArrayList<>();
|
|
|
+ for (WbsTreeContract contract : query) {
|
|
|
+ if (rootIds.contains(contract.getPKeyId() + "")) {
|
|
|
+ rootContracts.add(contract);
|
|
|
+ }
|
|
|
+ String ancestorsPId = contract.getAncestorsPId();
|
|
|
+ if (StringUtil.hasText(ancestorsPId)) {
|
|
|
+ String[] split = ancestorsPId.split(",");
|
|
|
+ for (String s : split) {
|
|
|
+ if (StringUtil.isNumeric(s)) {
|
|
|
+ parentIds.add(s);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<WbsTreeContract> parentContracts;
|
|
|
+ if (!parentIds.isEmpty()) {
|
|
|
+ parentContracts = jdbcTemplate.query("select * from m_wbs_tree_contract where p_key_id in ( " + String.join(",", parentIds) + ") and is_deleted = 0 and type = 1", new BeanPropertyRowMapper<>(WbsTreeContract.class));
|
|
|
+ } else {
|
|
|
+ parentContracts = new ArrayList<>();
|
|
|
+ }
|
|
|
+ Map<Long, WbsTreeContract> rootMap = rootContracts.stream().collect(Collectors.toMap(WbsTreeContract::getPKeyId, item -> item));
|
|
|
+ Map<Long, WbsTreeContract> parentMap = parentContracts.stream().collect(Collectors.toMap(WbsTreeContract::getPKeyId, item -> item));
|
|
|
+ String contractId = query.get(0).getContractId();
|
|
|
+ List<InformationQuery> queries = informationQueryService.list(Wrappers.<InformationQuery>lambdaQuery().select(InformationQuery::getWbsId, InformationQuery::getClassify, InformationQuery::getName)
|
|
|
+ .eq(InformationQuery::getContractId, contractId).in(InformationQuery::getWbsId, ids).in(InformationQuery::getClassify, 1, 2));
|
|
|
+ Map<String, List<InformationQuery>> map = queries.stream().collect(Collectors.groupingBy(item -> item.getWbsId() + "_" + item.getClassify()));
|
|
|
+ List<ContractInfo> contractInfos = jdbcTemplate.query("select * from m_contract_info where id = ( " + contractId + ") and is_deleted = 0", new BeanPropertyRowMapper<>(ContractInfo.class));
|
|
|
+ ContractInfo contractInfo;
|
|
|
+ if (contractInfos.isEmpty()) {
|
|
|
+ contractInfo = new ContractInfo();
|
|
|
+ } else {
|
|
|
+ contractInfo = contractInfos.get(0);
|
|
|
+ }
|
|
|
+ long operationId = SnowFlakeUtil.getId();
|
|
|
+ List<RecycleBinInfo> recycleBinInfos = new ArrayList<>(query.size());
|
|
|
+ for (WbsTreeContract contract : query) {
|
|
|
+ RecycleBinInfo info = new RecycleBinInfo();
|
|
|
+ info.setId(SnowFlakeUtil.getId());
|
|
|
+ info.setContractId(Long.parseLong(contract.getContractId()));
|
|
|
+ info.setProjectId(Long.parseLong(contract.getProjectId()));
|
|
|
+ info.setOperationId(operationId + "");
|
|
|
+ info.setDelType(2);
|
|
|
+ info.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ info.setCreateUser(AuthUtil.getUserId());
|
|
|
+ info.setOperationTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
|
|
+ info.setDelId(contract.getPKeyId());
|
|
|
+
|
|
|
+ WbsTreeContract delRoot = rootMap.get(contract.getPKeyId());
|
|
|
+ if (delRoot != null) {
|
|
|
+ info.setDelRootId(delRoot.getPKeyId());
|
|
|
+ info.setDelRootName(StringUtil.hasText(delRoot.getFullName()) ? delRoot.getFullName() : delRoot.getNodeName());
|
|
|
+ }
|
|
|
+ String ancestorsPId = contract.getAncestorsPId();
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ if (StringUtil.hasText(ancestorsPId)) {
|
|
|
+ String[] split = ancestorsPId.split(",");
|
|
|
+ for (String s : split) {
|
|
|
+ if (StringUtil.isNumeric(s)) {
|
|
|
+ WbsTreeContract parent = parentMap.get(Long.parseLong(s));
|
|
|
+ if (parent != null) {
|
|
|
+ if (parent.getPId() == null || parent.getPId() == 0) {
|
|
|
+ sb.append(contractInfo.getContractName()).append("/");
|
|
|
+ } else {
|
|
|
+ sb.append(StringUtil.hasText(parent.getFullName()) ? parent.getFullName() : parent.getNodeName()).append("/");
|
|
|
+ }
|
|
|
+ if (info.getDelRootId() == null) {
|
|
|
+ WbsTreeContract temp = rootMap.get(parent.getPKeyId());
|
|
|
+ if (temp != null) {
|
|
|
+ info.setDelRootId(temp.getPKeyId());
|
|
|
+ info.setDelRootName(StringUtil.hasText(temp.getFullName()) ? temp.getFullName() : temp.getNodeName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (info.getDelRootId() == null) {
|
|
|
+ info.setDelRootId(info.getDelId());
|
|
|
+ info.setDelRootName(StringUtil.hasText(contract.getFullName()) ? contract.getFullName() : contract.getNodeName());
|
|
|
+ }
|
|
|
+ info.setPosition(sb + (StringUtil.hasText(contract.getFullName()) ? contract.getFullName() : contract.getNodeName()));
|
|
|
+ List<InformationQuery> queryList = map.get(contract.getPKeyId() + "_1");
|
|
|
+ if (queryList != null && !queryList.isEmpty()) {
|
|
|
+ info.setFileName(queryList.get(0).getName());
|
|
|
+ info.setIsData(1);
|
|
|
+ }
|
|
|
+ queryList = map.get(contract.getPKeyId() + "_2");
|
|
|
+ if (queryList != null && !queryList.isEmpty()) {
|
|
|
+ info.setJlFileName(queryList.get(0).getName());
|
|
|
+ info.setIsData(1);
|
|
|
+ }
|
|
|
+ recycleBinInfos.add( info);
|
|
|
+ }
|
|
|
+ this.saveBatch(recycleBinInfos);
|
|
|
+ bladeRedis.del(BLADE_RECYCLE_USER_CACHE_KEY + contractId + "_1", BLADE_RECYCLE_USER_CACHE_KEY + contractId);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<UserVO2> getUpdateUser(Long contractId) {
|
|
|
+ String key = BLADE_RECYCLE_USER_CACHE_KEY + contractId + "_1";
|
|
|
+ String str1 = bladeRedis.get(key);
|
|
|
+ List<UserVO2> userVOs1 = getUserVOs(str1);
|
|
|
+ if (!userVOs1.isEmpty()) {
|
|
|
+ return userVOs1;
|
|
|
+ }
|
|
|
+ List<RecycleBinInfo> list = this.list(Wrappers.<RecycleBinInfo>lambdaQuery()
|
|
|
+ .select(RecycleBinInfo::getUpdateUser, RecycleBinInfo::getUpdateUserName)
|
|
|
+ .eq(RecycleBinInfo::getContractId, contractId).eq(RecycleBinInfo::getDelType, 2).eq(RecycleBinInfo::getStatus, 1)
|
|
|
+ .groupBy(Arrays.asList(RecycleBinInfo::getUpdateUser,RecycleBinInfo::getUpdateUserName)));
|
|
|
+ if (list != null && !list.isEmpty()) {
|
|
|
+ list.forEach(item -> {
|
|
|
+ UserVO2 vo2 = new UserVO2();
|
|
|
+ vo2.setId(item.getUpdateUser());
|
|
|
+ vo2.setName(item.getUpdateUserName());
|
|
|
+ userVOs1.add(vo2);
|
|
|
+ });
|
|
|
+ bladeRedis.set(key, JSON.toJSONString(userVOs1));
|
|
|
+ bladeRedis.expire(key, 60 * 60);
|
|
|
+ }
|
|
|
+ return userVOs1;
|
|
|
+ }
|
|
|
+ private List<UserVO2> getUserVOs(String str) {
|
|
|
+ if (str != null) {
|
|
|
+ try {
|
|
|
+ List<UserVO2> userVO2s = JSON.parseArray(str, UserVO2.class);
|
|
|
+ if (userVO2s != null && !userVO2s.isEmpty()) {
|
|
|
+ return userVO2s;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("从缓存中获取用户信息失败,error msg:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void sync() {
|
|
|
+ List<ContractInfo> contractInfos = jdbcTemplate.query("select id,contract_name from m_contract_info where is_deleted = 0 and p_id in (select id from m_project_info where is_deleted = 0)", new BeanPropertyRowMapper<>(ContractInfo.class));
|
|
|
+ List<User> users = jdbcTemplate.query("select * from blade_user", new BeanPropertyRowMapper<>(User.class));
|
|
|
+ Map<Long, User> userMap = users.stream().collect(Collectors.toMap(User::getId, item -> item));
|
|
|
+ for (ContractInfo contractInfo : contractInfos) {
|
|
|
+ List<RecycleBin> recycleBins = jdbcTemplate.query("select * from u_recycle_bin where del_type = 2 and contract_id = " + contractInfo.getId(), new BeanPropertyRowMapper<>(RecycleBin.class));
|
|
|
+ if (recycleBins.isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Map<Long, WbsTreeContract> treeContractMap = new TreeMap<>();
|
|
|
+ for (RecycleBin recycleBin : recycleBins) {
|
|
|
+ String businessId = recycleBin.getBusinessId();
|
|
|
+ String[] split1 = businessId.split(",");
|
|
|
+ String ids = Arrays.stream(split1).filter(StringUtil::isNumeric).collect(Collectors.joining(","));
|
|
|
+ if (StringUtil.isEmpty(ids)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<WbsTreeContract> query = jdbcTemplate.query("select * from m_wbs_tree_contract where p_key_id in ( " + ids + ") and type = 1", new BeanPropertyRowMapper<>(WbsTreeContract.class));
|
|
|
+ if (query.isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<String> parentIds = new ArrayList<>();
|
|
|
+ for (WbsTreeContract contract : query) {
|
|
|
+ String ancestorsPId = contract.getAncestorsPId();
|
|
|
+ if (StringUtil.hasText(ancestorsPId)) {
|
|
|
+ String[] split = ancestorsPId.split(",");
|
|
|
+ for (String s : split) {
|
|
|
+ if (StringUtil.isNumeric(s)) {
|
|
|
+ long l = Long.parseLong(s);
|
|
|
+ if (treeContractMap.containsKey(l)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ parentIds.add(s);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ treeContractMap.put(contract.getPKeyId(), contract);
|
|
|
+ }
|
|
|
+ List<WbsTreeContract> parentContracts;
|
|
|
+ if (!parentIds.isEmpty()) {
|
|
|
+ parentContracts = jdbcTemplate.query("select * from m_wbs_tree_contract where p_key_id in ( " + String.join(",", parentIds) + ") and is_deleted = 0 and type = 1", new BeanPropertyRowMapper<>(WbsTreeContract.class));
|
|
|
+ } else {
|
|
|
+ parentContracts = new ArrayList<>();
|
|
|
+ }
|
|
|
+ if (!parentContracts.isEmpty()) {
|
|
|
+ parentContracts.forEach(item -> treeContractMap.put(item.getPKeyId(), item));
|
|
|
+ }
|
|
|
+ List<InformationQuery> queries = informationQueryService.list(Wrappers.<InformationQuery>lambdaQuery().select(InformationQuery::getWbsId, InformationQuery::getClassify, InformationQuery::getName)
|
|
|
+ .eq(InformationQuery::getContractId, contractInfo.getId()).in(InformationQuery::getWbsId, ids).in(InformationQuery::getClassify, 1, 2));
|
|
|
+ Map<String, List<InformationQuery>> map = queries.stream().collect(Collectors.groupingBy(item -> item.getWbsId() + "_" + item.getClassify()));
|
|
|
+ long operationId = SnowFlakeUtil.getId();
|
|
|
+ List<RecycleBinInfo> recycleBinInfos = new ArrayList<>(query.size());
|
|
|
+ for (WbsTreeContract contract : query) {
|
|
|
+ RecycleBinInfo info = new RecycleBinInfo();
|
|
|
+ info.setId(SnowFlakeUtil.getId());
|
|
|
+ info.setContractId(Long.parseLong(contract.getContractId()));
|
|
|
+ info.setProjectId(Long.parseLong(contract.getProjectId()));
|
|
|
+ info.setOperationId(operationId + "");
|
|
|
+ info.setDelType(2);
|
|
|
+ info.setCreateUserName(recycleBin.getCreateUserName());
|
|
|
+ info.setCreateUser(recycleBin.getCreateUser());
|
|
|
+ info.setCreateTime(recycleBin.getCreateTime());
|
|
|
+ info.setOperationTime(recycleBin.getOperationTime());
|
|
|
+ info.setDelId(contract.getPKeyId());
|
|
|
+ if (recycleBin.getIsDeleted() == 1) {
|
|
|
+ info.setStatus(1);
|
|
|
+ info.setUpdateUser(recycleBin.getUpdateUser());
|
|
|
+ info.setUpdateTime(recycleBin.getUpdateTime());
|
|
|
+ User user = userMap.get(recycleBin.getUpdateUser());
|
|
|
+ info.setUpdateUserName(user.getName());
|
|
|
+ info.setUpdateTime(recycleBin.getUpdateTime());
|
|
|
+ }
|
|
|
+
|
|
|
+ String ancestorsPId = contract.getAncestorsPId();
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ if (StringUtil.hasText(ancestorsPId)) {
|
|
|
+ String[] split = ancestorsPId.split(",");
|
|
|
+ for (String s : split) {
|
|
|
+ if (StringUtil.isNumeric(s)) {
|
|
|
+ WbsTreeContract parent = treeContractMap.get(Long.parseLong(s));
|
|
|
+ if (parent != null) {
|
|
|
+ if (parent.getPId() == null || parent.getPId() == 0) {
|
|
|
+ sb.append(contractInfo.getContractName()).append("/");
|
|
|
+ } else {
|
|
|
+ sb.append(StringUtil.hasText(parent.getFullName()) ? parent.getFullName() : parent.getNodeName()).append("/");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (info.getDelRootId() == null) {
|
|
|
+ info.setDelRootId(info.getDelId());
|
|
|
+ info.setDelRootName(StringUtil.hasText(contract.getFullName()) ? contract.getFullName() : contract.getNodeName());
|
|
|
+ }
|
|
|
+ info.setPosition(sb + (StringUtil.hasText(contract.getFullName()) ? contract.getFullName() : contract.getNodeName()));
|
|
|
+ List<InformationQuery> queryList = map.get(contract.getPKeyId() + "_1");
|
|
|
+ if (queryList != null && !queryList.isEmpty()) {
|
|
|
+ info.setFileName(queryList.get(0).getName());
|
|
|
+ info.setIsData(1);
|
|
|
+ }
|
|
|
+ queryList = map.get(contract.getPKeyId() + "_2");
|
|
|
+ if (queryList != null && !queryList.isEmpty()) {
|
|
|
+ info.setJlFileName(queryList.get(0).getName());
|
|
|
+ info.setIsData(1);
|
|
|
+ }
|
|
|
+ recycleBinInfos.add( info);
|
|
|
+ }
|
|
|
+ this.saveBatch(recycleBinInfos);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|