|
@@ -8,33 +8,45 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.dromara.backstage.cardCenter.domain.PtSubsidyitem;
|
|
import org.dromara.backstage.cardCenter.domain.PtSubsidyitem;
|
|
|
|
|
+import org.dromara.backstage.cardCenter.domain.RsSubsidyData;
|
|
|
import org.dromara.backstage.cardCenter.domain.bo.PtSubsidyBo;
|
|
import org.dromara.backstage.cardCenter.domain.bo.PtSubsidyBo;
|
|
|
import org.dromara.backstage.cardCenter.domain.bo.PtSubsidyReportBo;
|
|
import org.dromara.backstage.cardCenter.domain.bo.PtSubsidyReportBo;
|
|
|
import org.dromara.backstage.cardCenter.domain.bo.PtSubsidyitemBo;
|
|
import org.dromara.backstage.cardCenter.domain.bo.PtSubsidyitemBo;
|
|
|
|
|
+import org.dromara.backstage.cardCenter.domain.bo.RsSubsidyDataBo;
|
|
|
import org.dromara.backstage.cardCenter.domain.vo.PtSubsidyFirstPageVo;
|
|
import org.dromara.backstage.cardCenter.domain.vo.PtSubsidyFirstPageVo;
|
|
|
import org.dromara.backstage.cardCenter.domain.vo.PtSubsidyReportVo;
|
|
import org.dromara.backstage.cardCenter.domain.vo.PtSubsidyReportVo;
|
|
|
import org.dromara.backstage.cardCenter.domain.vo.PtSubsidyitemVo;
|
|
import org.dromara.backstage.cardCenter.domain.vo.PtSubsidyitemVo;
|
|
|
|
|
+import org.dromara.backstage.cardCenter.domain.vo.RsSubsidyDataVo;
|
|
|
import org.dromara.backstage.cardCenter.mapper.PtSubsidyitemMapper;
|
|
import org.dromara.backstage.cardCenter.mapper.PtSubsidyitemMapper;
|
|
|
|
|
+import org.dromara.backstage.cardCenter.mapper.RsSubsidyDataMapper;
|
|
|
import org.dromara.backstage.cardCenter.service.IPtSubsidyitemService;
|
|
import org.dromara.backstage.cardCenter.service.IPtSubsidyitemService;
|
|
|
|
|
+import org.dromara.backstage.consumption.domain.bo.HandImportExcelConsumeBo;
|
|
|
import org.dromara.backstage.payment.domain.PtUserAccount;
|
|
import org.dromara.backstage.payment.domain.PtUserAccount;
|
|
|
|
|
+import org.dromara.backstage.payment.domain.PtUserAccount4SelectVo;
|
|
|
import org.dromara.backstage.payment.domain.vo.PtUserAccountVo;
|
|
import org.dromara.backstage.payment.domain.vo.PtUserAccountVo;
|
|
|
import org.dromara.backstage.payment.mapper.PtUserAccountMapper;
|
|
import org.dromara.backstage.payment.mapper.PtUserAccountMapper;
|
|
|
|
|
+import org.dromara.common.core.domain.R;
|
|
|
import org.dromara.common.core.service.DictService;
|
|
import org.dromara.common.core.service.DictService;
|
|
|
import org.dromara.common.core.utils.DateUtils;
|
|
import org.dromara.common.core.utils.DateUtils;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
|
|
+import org.dromara.common.excel.core.ExcelResult;
|
|
|
|
|
+import org.dromara.common.excel.utils.ExcelUtil;
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
import org.dromara.system.api.model.LoginUser;
|
|
import org.dromara.system.api.model.LoginUser;
|
|
|
import org.dromara.system.api.model.RoleDTO;
|
|
import org.dromara.system.api.model.RoleDTO;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import static java.util.stream.Collectors.toMap;
|
|
import static java.util.stream.Collectors.toMap;
|
|
|
import static java.util.stream.Collectors.toSet;
|
|
import static java.util.stream.Collectors.toSet;
|
|
|
|
|
+import static org.dromara.common.excel.utils.ExcelUtil.importExcel;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 补助明细Service业务层处理
|
|
* 补助明细Service业务层处理
|
|
@@ -48,6 +60,7 @@ public class PtSubsidyitemServiceImpl implements IPtSubsidyitemService {
|
|
|
|
|
|
|
|
private final PtSubsidyitemMapper baseMapper;
|
|
private final PtSubsidyitemMapper baseMapper;
|
|
|
private final PtUserAccountMapper userAccountMapper;
|
|
private final PtUserAccountMapper userAccountMapper;
|
|
|
|
|
+ private final RsSubsidyDataMapper rsSubsidyDataMapper;
|
|
|
|
|
|
|
|
private final DictService dictService;
|
|
private final DictService dictService;
|
|
|
|
|
|
|
@@ -280,4 +293,86 @@ public class PtSubsidyitemServiceImpl implements IPtSubsidyitemService {
|
|
|
return rs;
|
|
return rs;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R<List<PtSubsidyitemVo>> importSubsidyDetail(MultipartFile file) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 读取Excel文件,将数据转换为Vo对象列表
|
|
|
|
|
+ List<RsSubsidyDataVo> importList = ExcelUtil.importExcel(file.getInputStream(), RsSubsidyDataVo.class);
|
|
|
|
|
+ if (CollectionUtil.isEmpty(importList)) {
|
|
|
|
|
+ return R.fail("导入的Excel文件为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 根据otherId查询数据库中是否存在该数据
|
|
|
|
|
+ List<String> otherIds = importList.stream().map(RsSubsidyDataVo::getOtherId).collect(Collectors.toList());
|
|
|
|
|
+ List<PtUserAccount4SelectVo> accountVos = userAccountMapper.getByOtherIdList(otherIds);
|
|
|
|
|
+
|
|
|
|
|
+ // 使用Map存储已存在的otherId,提高查询效率
|
|
|
|
|
+ Map<String, PtUserAccount4SelectVo> accountMap = accountVos.stream()
|
|
|
|
|
+ .collect(Collectors.toMap(PtUserAccount4SelectVo::getOtherId, account -> account, (existing, replacement) -> existing));
|
|
|
|
|
+
|
|
|
|
|
+ // 获取当前时间和登录用户
|
|
|
|
|
+ Date now = new Date();
|
|
|
|
|
+ LoginUser loginUser = LoginHelper.getLoginUser();
|
|
|
|
|
+
|
|
|
|
|
+ // 处理导入数据并准备保存
|
|
|
|
|
+ List<RsSubsidyData> saveList = new ArrayList<>();
|
|
|
|
|
+ List<PtSubsidyitemVo> resultList = new ArrayList<>();
|
|
|
|
|
+ Long userId = 0L;
|
|
|
|
|
+ for (RsSubsidyDataVo item : importList) {
|
|
|
|
|
+ RsSubsidyData data = MapstructUtils.convert(item, RsSubsidyData.class);
|
|
|
|
|
+ data.setCreateBy(loginUser.getNickname());
|
|
|
|
|
+ data.setCreateTime(now);
|
|
|
|
|
+
|
|
|
|
|
+ PtUserAccount4SelectVo accountVo = accountMap.get(item.getOtherId());
|
|
|
|
|
+ PtSubsidyitemVo subsidyItemVo = new PtSubsidyitemVo();
|
|
|
|
|
+
|
|
|
|
|
+ if (accountVo != null) {
|
|
|
|
|
+ // 匹配成功
|
|
|
|
|
+ data.setCheckResults("匹配成功");
|
|
|
|
|
+
|
|
|
|
|
+ // 设置补助明细信息
|
|
|
|
|
+ subsidyItemVo.setUserId(accountVo.getUserId());
|
|
|
|
|
+ subsidyItemVo.setRealName(accountVo.getRealName());
|
|
|
|
|
+ subsidyItemVo.setUserNumb(accountVo.getUserNumb());
|
|
|
|
|
+ subsidyItemVo.setDeptName(accountVo.getDeptName());
|
|
|
|
|
+ subsidyItemVo.setRemark("匹配成功");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 匹配失败
|
|
|
|
|
+ data.setCheckResults("匹配失败");
|
|
|
|
|
+
|
|
|
|
|
+ // 设置补助明细信息
|
|
|
|
|
+ //给userId设默认值
|
|
|
|
|
+ subsidyItemVo.setUserId(userId++);
|
|
|
|
|
+ subsidyItemVo.setRealName(item.getName());
|
|
|
|
|
+ subsidyItemVo.setUserNumb(item.getUserNo());
|
|
|
|
|
+ subsidyItemVo.setDeptName(item.getDeptName());
|
|
|
|
|
+ subsidyItemVo.setRemark("匹配失败,otherId:" + item.getOtherId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ saveList.add(data);
|
|
|
|
|
+ resultList.add(subsidyItemVo);
|
|
|
|
|
+ }
|
|
|
|
|
+ //将resultList中匹配失败的放在最前面
|
|
|
|
|
+ resultList.sort(Comparator.comparing(PtSubsidyitemVo::getRemark));
|
|
|
|
|
+ // 保存人事系统导入名单
|
|
|
|
|
+ if (!CollectionUtil.isEmpty(saveList)) {
|
|
|
|
|
+ rsSubsidyDataMapper.batchInsert(saveList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 构建返回结果
|
|
|
|
|
+ String msg = "导入成功";
|
|
|
|
|
+ long successCount = accountMap.size();
|
|
|
|
|
+ long totalCount = importList.size();
|
|
|
|
|
+
|
|
|
|
|
+ if (successCount < totalCount) {
|
|
|
|
|
+ long failCount = totalCount - successCount;
|
|
|
|
|
+ msg = String.format("导入成功,共导入%d条数据,其中%d条匹配成功,%d条匹配失败", totalCount, successCount, failCount);
|
|
|
|
|
+ }
|
|
|
|
|
+ R<List<PtSubsidyitemVo>> result = R.ok(resultList);
|
|
|
|
|
+ result.setMsg(msg);
|
|
|
|
|
+ return result;
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ throw new RuntimeException("导入Excel文件失败: " + e.getMessage(), e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|