|
|
@@ -27,7 +27,6 @@ import com.xjrsoft.module.student.vo.*;
|
|
|
import com.xjrsoft.module.teacher.entity.XjrUser;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
-import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -40,6 +39,18 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.read.listener.PageReadListener;
|
|
|
+import com.xjrsoft.module.base.entity.BaseGrade;
|
|
|
+import com.xjrsoft.module.base.entity.BaseMajorSet;
|
|
|
+import com.xjrsoft.module.student.entity.BaseMajor;
|
|
|
+import com.xjrsoft.module.student.entity.StudentConsumption;
|
|
|
+import com.xjrsoft.module.student.vo.CafeteriaImportExcelVo;
|
|
|
+import com.xjrsoft.module.student.vo.StudentImportDetailVo;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
/**
|
|
|
* @title:
|
|
|
* @Author dzx
|
|
|
@@ -48,12 +59,15 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
-public class PbVXsxxsfytbServiceImpl extends MPJBaseServiceImpl<PbVXsxxsfytbMapper, PbVXsxxsfytb> implements IPbVXsxxsfytbService {
|
|
|
+public class PbVXsxxsfytbServiceImpl extends MPJBaseServiceImpl<PbVXsxxsfytbMapper, PbVXsxxsfytb>
|
|
|
+ implements IPbVXsxxsfytbService {
|
|
|
|
|
|
private final PbVXsxxsfytbMapper pbVXsxxsfytbMapper;
|
|
|
private final PbSemesterConfigMapper pbSemesterConfigMapper;
|
|
|
|
|
|
private final BaseSemesterMapper baseSemesterMapper;
|
|
|
+ private final com.xjrsoft.module.student.mapper.StudentConsumptionMapper studentConsumptionMapper;
|
|
|
+ private final com.xjrsoft.module.teacher.mapper.XjrUserMapper xjrUserMapper;
|
|
|
|
|
|
@Override
|
|
|
public PersonalPortraitFeeInformationVo listCostInformation(PersonalPortraitFeeInformationDto dto) {
|
|
|
@@ -61,15 +75,15 @@ public class PbVXsxxsfytbServiceImpl extends MPJBaseServiceImpl<PbVXsxxsfytbMapp
|
|
|
|
|
|
// 获取年份
|
|
|
int year = currentDate.getYear();
|
|
|
- if(StringUtils.isEmpty(dto.getYear())){
|
|
|
+ if (StringUtils.isEmpty(dto.getYear())) {
|
|
|
dto.setYear(year + "");
|
|
|
}
|
|
|
|
|
|
LambdaQueryWrapper<BaseSemester> baseSemesterLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
baseSemesterLambdaQueryWrapper
|
|
|
- .select(BaseSemester.class, x -> VoToColumnUtil.fieldsToColumns(BaseSemester.class).contains(x.getProperty()))
|
|
|
- .like(BaseSemester::getName, dto.getYear())
|
|
|
- ;
|
|
|
+ .select(BaseSemester.class,
|
|
|
+ x -> VoToColumnUtil.fieldsToColumns(BaseSemester.class).contains(x.getProperty()))
|
|
|
+ .like(BaseSemester::getName, dto.getYear());
|
|
|
List<BaseSemester> baseSemesters = baseSemesterMapper.selectList(baseSemesterLambdaQueryWrapper);
|
|
|
|
|
|
// 查出所有的消费记录
|
|
|
@@ -77,18 +91,19 @@ public class PbVXsxxsfytbServiceImpl extends MPJBaseServiceImpl<PbVXsxxsfytbMapp
|
|
|
pbVXsxxsfytbMPJLambdaWrapper
|
|
|
.selectAs(BaseSemester::getId, PbVXsxxsfytbPersonal::getBaseSemester)
|
|
|
.selectAs(BaseSemester::getName, PbVXsxxsfytbPersonal::getBaseSemesterCn)
|
|
|
- .select(PbVXsxxsfytb.class, x -> VoToColumnUtil.fieldsToColumns(PbVXsxxsfytbPersonal.class).contains(x.getProperty()))
|
|
|
+ .select(PbVXsxxsfytb.class,
|
|
|
+ x -> VoToColumnUtil.fieldsToColumns(PbVXsxxsfytbPersonal.class).contains(x.getProperty()))
|
|
|
.leftJoin(XjrUser.class, XjrUser::getCredentialNumber, PbVXsxxsfytb::getPersonalid)
|
|
|
.leftJoin(PbSemesterConfig.class, PbSemesterConfig::getBeltcode, PbVXsxxsfytb::getBeltcode)
|
|
|
.leftJoin(BaseSemester.class, BaseSemester::getId, PbSemesterConfig::getBaseSemesterId)
|
|
|
.eq(dto.getUserId() != null && dto.getUserId() > 0, XjrUser::getId, dto.getUserId())
|
|
|
- .like(dto.getYear() != null && !dto.getYear().isEmpty(), PbVXsxxsfytb::getBeltcode, dto.getYear())
|
|
|
- ;
|
|
|
- List<PbVXsxxsfytbPersonal> pbVXsxxsfytbPersonalList = this.selectJoinList(PbVXsxxsfytbPersonal.class, pbVXsxxsfytbMPJLambdaWrapper);
|
|
|
+ .like(dto.getYear() != null && !dto.getYear().isEmpty(), PbVXsxxsfytb::getBeltcode, dto.getYear());
|
|
|
+ List<PbVXsxxsfytbPersonal> pbVXsxxsfytbPersonalList = this.selectJoinList(PbVXsxxsfytbPersonal.class,
|
|
|
+ pbVXsxxsfytbMPJLambdaWrapper);
|
|
|
|
|
|
- if(CollectionUtils.isEmpty(pbVXsxxsfytbPersonalList)){
|
|
|
+ if (CollectionUtils.isEmpty(pbVXsxxsfytbPersonalList)) {
|
|
|
pbVXsxxsfytbPersonalList = new ArrayList<>();
|
|
|
- for (BaseSemester b : baseSemesters){
|
|
|
+ for (BaseSemester b : baseSemesters) {
|
|
|
PbVXsxxsfytbPersonal pbVXsxxsfytbPersonal = new PbVXsxxsfytbPersonal();
|
|
|
pbVXsxxsfytbPersonal.setBaseSemester(b.getId().toString());
|
|
|
pbVXsxxsfytbPersonal.setBaseSemesterCn(b.getName());
|
|
|
@@ -107,7 +122,8 @@ public class PbVXsxxsfytbServiceImpl extends MPJBaseServiceImpl<PbVXsxxsfytbMapp
|
|
|
|
|
|
// 统计总消费金额
|
|
|
BigDecimal totalConsumption = pbVXsxxsfytbPersonalList.stream()
|
|
|
- .map(p -> p.getFactrecarmny().add((p.getArrearagemny() == null ? BigDecimal.ZERO : p.getArrearagemny())))
|
|
|
+ .map(p -> p.getFactrecarmny()
|
|
|
+ .add((p.getArrearagemny() == null ? BigDecimal.ZERO : p.getArrearagemny())))
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
|
// 按学期分组并处理数据
|
|
|
@@ -120,19 +136,23 @@ public class PbVXsxxsfytbServiceImpl extends MPJBaseServiceImpl<PbVXsxxsfytbMapp
|
|
|
|
|
|
// 合并相同缴费项目
|
|
|
Map<String, PbVXsxxsfytbPersonal> pbVXsxxsfytbPersonalByItemMap = pbVXsxxsfytbPersonals.stream()
|
|
|
- .collect(Collectors.toMap(PbVXsxxsfytbPersonal::getFeeitemcode, p -> p, (existing, replacement) -> {
|
|
|
- existing.setFactar(existing.getFactar().add(replacement.getFactar()));
|
|
|
- existing.setFactrecarmny(existing.getFactrecarmny().add(replacement.getFactrecarmny()));
|
|
|
- existing.setAdjustmny(existing.getAdjustmny().add(replacement.getAdjustmny()));
|
|
|
- existing.setArrearagemny(existing.getArrearagemny().add(replacement.getArrearagemny()));
|
|
|
- return existing;
|
|
|
- }));
|
|
|
+ .collect(Collectors.toMap(PbVXsxxsfytbPersonal::getFeeitemcode, p -> p,
|
|
|
+ (existing, replacement) -> {
|
|
|
+ existing.setFactar(existing.getFactar().add(replacement.getFactar()));
|
|
|
+ existing.setFactrecarmny(
|
|
|
+ existing.getFactrecarmny().add(replacement.getFactrecarmny()));
|
|
|
+ existing.setAdjustmny(existing.getAdjustmny().add(replacement.getAdjustmny()));
|
|
|
+ existing.setArrearagemny(
|
|
|
+ existing.getArrearagemny().add(replacement.getArrearagemny()));
|
|
|
+ return existing;
|
|
|
+ }));
|
|
|
|
|
|
// 构建PbVXsxxsfytbPersonalMap对象
|
|
|
PbVXsxxsfytbPersonalMap pbVXsxxsfytbPersonalMap = new PbVXsxxsfytbPersonalMap();
|
|
|
pbVXsxxsfytbPersonalMap.setBaseSemester(baseSemester);
|
|
|
pbVXsxxsfytbPersonalMap.setBaseSemesterCn(pbVXsxxsfytbPersonals.get(0).getBaseSemesterCn());
|
|
|
- pbVXsxxsfytbPersonalMap.setPbVXsxxsfytbPersonalList(new ArrayList<>(pbVXsxxsfytbPersonalByItemMap.values()));
|
|
|
+ pbVXsxxsfytbPersonalMap
|
|
|
+ .setPbVXsxxsfytbPersonalList(new ArrayList<>(pbVXsxxsfytbPersonalByItemMap.values()));
|
|
|
|
|
|
return pbVXsxxsfytbPersonalMap;
|
|
|
})
|
|
|
@@ -156,17 +176,22 @@ public class PbVXsxxsfytbServiceImpl extends MPJBaseServiceImpl<PbVXsxxsfytbMapp
|
|
|
|
|
|
MPJLambdaWrapper<PbVXsxxsfytb> pbVXsxxsfytbMPJLambdaWrapper = new MPJLambdaWrapper<>();
|
|
|
if (dto.getSemesterId() != null && dto.getSemesterId() > 0) {
|
|
|
- pbVXsxxsfytbMPJLambdaWrapper.exists("select 1 from `pb_semester_config` where base_semester_id = " + dto.getSemesterId() + " and beltcode = t.beltcode");
|
|
|
+ pbVXsxxsfytbMPJLambdaWrapper.exists("select 1 from `pb_semester_config` where base_semester_id = "
|
|
|
+ + dto.getSemesterId() + " and beltcode = t.beltcode");
|
|
|
}
|
|
|
|
|
|
pbVXsxxsfytbMPJLambdaWrapper
|
|
|
.disableSubLogicDel()
|
|
|
- .like(dto.getFeeitemname() != null && !dto.getFeeitemname().isEmpty(), PbVXsxxsfytb::getFeeitemname, dto.getFeeitemname())
|
|
|
+ .like(dto.getFeeitemname() != null && !dto.getFeeitemname().isEmpty(), PbVXsxxsfytb::getFeeitemname,
|
|
|
+ dto.getFeeitemname())
|
|
|
.like(StrUtil.isNotEmpty(dto.getName()), PbVXsxxsfytb::getFeeobjname, dto.getName())
|
|
|
.eq(StrUtil.isNotEmpty(dto.getStudentId()), BaseStudent::getStudentId, dto.getStudentId())
|
|
|
- .eq(StrUtil.isNotEmpty(dto.getCredentialNumber()), XjrUser::getCredentialNumber, dto.getCredentialNumber())
|
|
|
- .in(dto.getClassIdList() != null && !dto.getClassIdList().isEmpty(), BaseStudentSchoolRoll::getClassId, dto.getClassIdList())
|
|
|
- .eq(dto.getSemesterId() != null && dto.getSemesterId() > 0, PbSemesterConfig::getBaseSemesterId, dto.getSemesterId())
|
|
|
+ .eq(StrUtil.isNotEmpty(dto.getCredentialNumber()), XjrUser::getCredentialNumber,
|
|
|
+ dto.getCredentialNumber())
|
|
|
+ .in(dto.getClassIdList() != null && !dto.getClassIdList().isEmpty(), BaseStudentSchoolRoll::getClassId,
|
|
|
+ dto.getClassIdList())
|
|
|
+ .eq(dto.getSemesterId() != null && dto.getSemesterId() > 0, PbSemesterConfig::getBaseSemesterId,
|
|
|
+ dto.getSemesterId())
|
|
|
.like(dto.getJfzt() != null && !"".equals(dto.getJfzt()), PbVXsxxsfytb::getJfzt, dto.getJfzt())
|
|
|
.eq(dto.getTeacherId() != null, BaseClass::getTeacherId, dto.getTeacherId())
|
|
|
.eq(BaseStudentSchoolRoll::getArchivesStatus, ArchivesStatusEnum.FB2901.getCode())
|
|
|
@@ -184,8 +209,8 @@ public class PbVXsxxsfytbServiceImpl extends MPJBaseServiceImpl<PbVXsxxsfytbMapp
|
|
|
.selectAs(BaseClass::getName, PbVXsxxsfytbPageVo::getClassname)
|
|
|
.selectAs(PbVXsxxsfytb::getPersonalid, PbVXsxxsfytbPageVo::getCredentialNumber)
|
|
|
.selectAs(BaseSemester::getName, PbVXsxxsfytbPageVo::getBaseSemesterCn)
|
|
|
- .select(PbVXsxxsfytb.class, x -> VoToColumnUtil.fieldsToColumns(PbVXsxxsfytbPageVo.class).contains(x.getProperty()))
|
|
|
- ;
|
|
|
+ .select(PbVXsxxsfytb.class,
|
|
|
+ x -> VoToColumnUtil.fieldsToColumns(PbVXsxxsfytbPageVo.class).contains(x.getProperty()));
|
|
|
if (StrUtil.isNotEmpty(dto.getField()) && StrUtil.isNotEmpty(dto.getOrder())) {
|
|
|
if ("ascend".equals(dto.getOrder())) {
|
|
|
if ("baseSemesterCn".equals(dto.getField())) {
|
|
|
@@ -233,7 +258,8 @@ public class PbVXsxxsfytbServiceImpl extends MPJBaseServiceImpl<PbVXsxxsfytbMapp
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return this.selectJoinListPage(ConventPage.getPageCustomOrder(dto), PbVXsxxsfytbPageVo.class, pbVXsxxsfytbMPJLambdaWrapper);
|
|
|
+ return this.selectJoinListPage(ConventPage.getPageCustomOrder(dto), PbVXsxxsfytbPageVo.class,
|
|
|
+ pbVXsxxsfytbMPJLambdaWrapper);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -242,7 +268,8 @@ public class PbVXsxxsfytbServiceImpl extends MPJBaseServiceImpl<PbVXsxxsfytbMapp
|
|
|
|
|
|
pbVXsxxsfytbMPJLambdaWrapper
|
|
|
.disableSubLogicDel()
|
|
|
- .in(dto.getPksfxxytbs() != null && !dto.getPksfxxytbs().isEmpty(), PbVXsxxsfytb::getPksfxxytb, dto.getPksfxxytbs())
|
|
|
+ .in(dto.getPksfxxytbs() != null && !dto.getPksfxxytbs().isEmpty(), PbVXsxxsfytb::getPksfxxytb,
|
|
|
+ dto.getPksfxxytbs())
|
|
|
.leftJoin(XjrUser.class, XjrUser::getCredentialNumber, PbVXsxxsfytb::getPersonalid)
|
|
|
.leftJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getUserId, XjrUser::getId)
|
|
|
.leftJoin(PbSemesterConfig.class, PbSemesterConfig::getBeltcode, PbVXsxxsfytb::getBeltcode)
|
|
|
@@ -252,11 +279,11 @@ public class PbVXsxxsfytbServiceImpl extends MPJBaseServiceImpl<PbVXsxxsfytbMapp
|
|
|
.selectAs(BaseSemester::getId, PbVXsxxsfytbExcelVo::getBaseSemester)
|
|
|
.selectAs(XjrUser::getId, PbVXsxxsfytbExcelVo::getUserId)
|
|
|
.selectAs(BaseSemester::getName, PbVXsxxsfytbExcelVo::getBaseSemesterCn)
|
|
|
- .select(PbVXsxxsfytb.class, x -> VoToColumnUtil.fieldsToColumns(PbVXsxxsfytbExcelVo.class).contains(x.getProperty()))
|
|
|
- ;
|
|
|
+ .select(PbVXsxxsfytb.class,
|
|
|
+ x -> VoToColumnUtil.fieldsToColumns(PbVXsxxsfytbExcelVo.class).contains(x.getProperty()));
|
|
|
List<PbVXsxxsfytbExcelVo> list = this.selectJoinList(PbVXsxxsfytbExcelVo.class, pbVXsxxsfytbMPJLambdaWrapper);
|
|
|
for (PbVXsxxsfytbExcelVo pbVXsxxsfytbExcelVo : list) {
|
|
|
- if (pbVXsxxsfytbExcelVo.getQfje().compareTo(BigDecimal.ZERO) > 0) {//正数
|
|
|
+ if (pbVXsxxsfytbExcelVo.getQfje().compareTo(BigDecimal.ZERO) > 0) {// 正数
|
|
|
pbVXsxxsfytbExcelVo.setQfje(pbVXsxxsfytbExcelVo.getQfje().abs());
|
|
|
pbVXsxxsfytbExcelVo.setKtje(BigDecimal.ZERO);
|
|
|
} else if (pbVXsxxsfytbExcelVo.getQfje().compareTo(BigDecimal.ZERO) < 0) {
|
|
|
@@ -297,8 +324,7 @@ public class PbVXsxxsfytbServiceImpl extends MPJBaseServiceImpl<PbVXsxxsfytbMapp
|
|
|
Long l = pbVXsxxsfytbMapper.selectCount(
|
|
|
new QueryWrapper<PbVXsxxsfytb>().lambda()
|
|
|
.eq(PbVXsxxsfytb::getPersonalid, credentialNumber)
|
|
|
- .gt(PbVXsxxsfytb::getQfje, 0)
|
|
|
- );
|
|
|
+ .gt(PbVXsxxsfytb::getQfje, 0));
|
|
|
if (l > 1) {
|
|
|
l = 1L;
|
|
|
}
|
|
|
@@ -326,7 +352,8 @@ public class PbVXsxxsfytbServiceImpl extends MPJBaseServiceImpl<PbVXsxxsfytbMapp
|
|
|
+ (result.getPoorCount() == null ? 0 : result.getPoorCount());
|
|
|
BigDecimal divide = BigDecimal.ZERO;
|
|
|
if (allCount != 0) {
|
|
|
- divide = BigDecimal.valueOf(result.getInclusiveCount()).divide(BigDecimal.valueOf(allCount), 4, RoundingMode.HALF_UP);
|
|
|
+ divide = BigDecimal.valueOf(result.getInclusiveCount()).divide(BigDecimal.valueOf(allCount), 4,
|
|
|
+ RoundingMode.HALF_UP);
|
|
|
}
|
|
|
result.setInclusiveRatio(divide.doubleValue());
|
|
|
return result;
|
|
|
@@ -351,7 +378,8 @@ public class PbVXsxxsfytbServiceImpl extends MPJBaseServiceImpl<PbVXsxxsfytbMapp
|
|
|
result.setStayCount(0);
|
|
|
}
|
|
|
if (allCount != 0) {
|
|
|
- divide = BigDecimal.valueOf(result.getStayCount()).divide(BigDecimal.valueOf(allCount), 4, RoundingMode.HALF_UP);
|
|
|
+ divide = BigDecimal.valueOf(result.getStayCount()).divide(BigDecimal.valueOf(allCount), 4,
|
|
|
+ RoundingMode.HALF_UP);
|
|
|
}
|
|
|
result.setStayRatio(divide.doubleValue());
|
|
|
|
|
|
@@ -385,4 +413,110 @@ public class PbVXsxxsfytbServiceImpl extends MPJBaseServiceImpl<PbVXsxxsfytbMapp
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void importCafeteriaData(MultipartFile file) {
|
|
|
+ try {
|
|
|
+ EasyExcel.read(file.getInputStream(), CafeteriaImportExcelVo.class,
|
|
|
+ new PageReadListener<CafeteriaImportExcelVo>(dataList -> {
|
|
|
+ if (CollectionUtils.isEmpty(dataList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 1. 提取所有工号
|
|
|
+ List<String> userNames = dataList.stream()
|
|
|
+ .map(CafeteriaImportExcelVo::getUserName)
|
|
|
+ .filter(StringUtils::isNotBlank)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(userNames)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 查询学生信息
|
|
|
+ MPJLambdaWrapper<XjrUser> wrapper = new MPJLambdaWrapper<>();
|
|
|
+ wrapper.selectAll(XjrUser.class)
|
|
|
+ .selectAs(XjrUser::getId, StudentImportDetailVo::getUserId)
|
|
|
+ .selectAs(XjrUser::getUserName, StudentImportDetailVo::getUserName)
|
|
|
+ .selectAs(XjrUser::getName, StudentImportDetailVo::getStudentName)
|
|
|
+ .selectAs(BaseStudentSchoolRoll::getGradeId, StudentImportDetailVo::getGradeId)
|
|
|
+ .selectAs(BaseStudentSchoolRoll::getClassId, StudentImportDetailVo::getClassId)
|
|
|
+ .selectAs(BaseStudentSchoolRoll::getMajorSetId, StudentImportDetailVo::getMajorSetId)
|
|
|
+ .selectAs(BaseGrade::getName, StudentImportDetailVo::getGradeName)
|
|
|
+ .selectAs(BaseClass::getName, StudentImportDetailVo::getClassName)
|
|
|
+ .selectAs(BaseMajor::getName, StudentImportDetailVo::getMajorName)
|
|
|
+ .selectAs(BaseMajor::getId, StudentImportDetailVo::getMajorId)
|
|
|
+ .innerJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getUserId,
|
|
|
+ XjrUser::getId)
|
|
|
+ .innerJoin(BaseGrade.class, BaseGrade::getId, BaseStudentSchoolRoll::getGradeId)
|
|
|
+ .innerJoin(BaseClass.class, BaseClass::getId, BaseStudentSchoolRoll::getClassId)
|
|
|
+ .innerJoin(BaseMajorSet.class, BaseMajorSet::getId,
|
|
|
+ BaseStudentSchoolRoll::getMajorSetId)
|
|
|
+ .innerJoin(BaseMajor.class, BaseMajor::getId, BaseMajorSet::getMajorId)
|
|
|
+ .in(XjrUser::getUserName, userNames)
|
|
|
+ .eq(XjrUser::getDeleteMark, 0)
|
|
|
+ .eq(XjrUser::getEnabledMark, 1);
|
|
|
+
|
|
|
+ List<StudentImportDetailVo> studentDetails = xjrUserMapper
|
|
|
+ .selectJoinList(StudentImportDetailVo.class, wrapper);
|
|
|
+ Map<String, StudentImportDetailVo> studentMap = studentDetails.stream()
|
|
|
+ .collect(Collectors.toMap(StudentImportDetailVo::getUserName, v -> v, (v1, v2) -> v1));
|
|
|
+
|
|
|
+ // 3. 组装数据
|
|
|
+ List<StudentConsumption> consumptionList = new ArrayList<>();
|
|
|
+ for (CafeteriaImportExcelVo excelVo : dataList) {
|
|
|
+ StudentImportDetailVo student = studentMap.get(excelVo.getUserName());
|
|
|
+ if (student != null) {
|
|
|
+ StudentConsumption consumption = new StudentConsumption();
|
|
|
+ consumption.setStudentId(student.getUserId());
|
|
|
+ consumption.setStudentName(student.getStudentName());
|
|
|
+ consumption.setStudentUserName(student.getUserName());
|
|
|
+ consumption.setClassId(student.getClassId());
|
|
|
+ consumption.setClassName(student.getClassName());
|
|
|
+ consumption.setGradeId(student.getGradeId());
|
|
|
+ consumption.setGradeName(student.getGradeName());
|
|
|
+ consumption.setMajorId(student.getMajorId());
|
|
|
+ consumption.setMajorName(student.getMajorName());
|
|
|
+
|
|
|
+ consumption.setConsumeTime(excelVo.getConsumeTime());
|
|
|
+ consumption.setConsumeMoney(excelVo.getConsumeMoney());
|
|
|
+
|
|
|
+ // 场景处理
|
|
|
+ String consumeType = excelVo.getConsumeType();
|
|
|
+ if ("智慧食堂".equals(consumeType)) {
|
|
|
+ consumption.setConsumeType("consume_type_1");
|
|
|
+ } else {
|
|
|
+ consumption.setConsumeType(consumeType);
|
|
|
+ }
|
|
|
+
|
|
|
+ consumption.setDeleteMark(0);
|
|
|
+ consumption.setEnabledMark(1);
|
|
|
+ consumption.setCreateDate(new Date());
|
|
|
+ // 设置其他默认值或从上下文获取创建人等
|
|
|
+
|
|
|
+ consumptionList.add(consumption);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 批量插入
|
|
|
+ if (CollectionUtils.isNotEmpty(consumptionList)) {
|
|
|
+ // 使用 MyBatis-Plus 的 saveBatch 或者循环插入
|
|
|
+ // 这里假设注入了 StudentConsumptionMapper,但 Mapper 没有 saveBatch 方法(除非继承 IService)
|
|
|
+ // 为了简单,循环插入或者使用 Service。由于没有 StudentConsumptionService,这里循环插入。
|
|
|
+ // 或者更好的是,注入 IStudentConsumptionService 如果有的话。
|
|
|
+ // 既然没有创建 Service,我将在 Mapper 中循环插入,或者直接在这里循环。
|
|
|
+ for (StudentConsumption consumption : consumptionList) {
|
|
|
+ try {
|
|
|
+ studentConsumptionMapper.insert(consumption);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 忽略插入错误,如唯一索引冲突
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ })).sheet().headRowNumber(5).doRead();
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("导入失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|