| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443 |
- package com.xjrsoft.module.textbook.service.impl;
- import cn.hutool.core.util.StrUtil;
- import com.alibaba.excel.EasyExcel;
- import com.alibaba.excel.ExcelWriter;
- import com.alibaba.excel.support.ExcelTypeEnum;
- import com.alibaba.excel.write.metadata.WriteSheet;
- import com.alibaba.excel.write.metadata.WriteTable;
- import com.alibaba.excel.write.metadata.style.WriteCellStyle;
- import com.alibaba.excel.write.metadata.style.WriteFont;
- import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.core.toolkit.Wrappers;
- import com.github.yulichang.base.MPJBaseServiceImpl;
- import com.github.yulichang.wrapper.MPJLambdaWrapper;
- import com.xjrsoft.common.enums.*;
- import com.xjrsoft.common.exception.MyException;
- import com.xjrsoft.common.page.ConventPage;
- import com.xjrsoft.common.utils.VoToColumnUtil;
- import com.xjrsoft.common.utils.excel.ExcelFillCellMergePrevColUtil;
- import com.xjrsoft.common.utils.excel.ExcelMergeUtil;
- import com.xjrsoft.module.base.entity.*;
- import com.xjrsoft.module.base.mapper.BaseClassCourseMapper;
- import com.xjrsoft.module.base.mapper.BaseCourseSubjectMapper;
- import com.xjrsoft.module.base.mapper.BaseSemesterMapper;
- import com.xjrsoft.module.base.service.IBaseClassService;
- import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
- import com.xjrsoft.module.system.entity.DictionaryDetail;
- import com.xjrsoft.module.system.mapper.DictionarydetailMapper;
- import com.xjrsoft.module.system.mapper.DictionaryitemMapper;
- import com.xjrsoft.module.teacher.entity.XjrUser;
- import com.xjrsoft.module.textbook.dto.*;
- import com.xjrsoft.module.textbook.entity.*;
- import com.xjrsoft.module.textbook.mapper.*;
- import com.xjrsoft.module.textbook.service.ITextbookService;
- import com.xjrsoft.module.textbook.service.IWfExerciseBookService;
- import com.xjrsoft.module.textbook.vo.*;
- import com.xjrsoft.module.veb.util.ImportExcelUtil;
- import lombok.AllArgsConstructor;
- import org.apache.commons.lang3.ObjectUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.poi.ss.usermodel.BorderStyle;
- import org.apache.poi.ss.usermodel.HorizontalAlignment;
- import org.apache.poi.ss.usermodel.VerticalAlignment;
- import org.springframework.beans.BeanUtils;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.web.multipart.MultipartFile;
- import java.io.ByteArrayOutputStream;
- import java.io.IOException;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.util.*;
- import java.util.stream.Collectors;
- import static com.xjrsoft.module.veb.util.ImportExcelUtil.*;
- /**
- * @title: 教材管理
- * @Author szs
- * @Date: 2023-12-25
- * @Version 1.0
- */
- @Service
- @AllArgsConstructor
- public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Textbook> implements ITextbookService {
- private final TextbookMapper textbookTextbookMapper;
- private final TextbookClassRelationMapper textbookTextbookClassRelationMapper;
- private final TextbookSubscriptionRecordMapper textbookTextbookSubscriptionRecordMapper;
- private final IWfExerciseBookService wfExerciseBookService;
- private final IBaseClassService baseClassService;
- private final TextbookIssueRecordMapper textbookIssueRecordMapper;
- private final TextbookStudentClaimMapper textbookStudentClaimMapper;
- private final BaseSemesterMapper baseSemesterMapper;
- private final BaseClassCourseMapper baseClassCourseMapper;
- private final DictionaryitemMapper dictionaryitemMapper;
- private final DictionarydetailMapper dictionarydetailMapper;
- private final SubjectGroupMapper subjectGroupMapper;
- private final BaseCourseSubjectMapper baseCourseSubjectMapper;
- private final TextbookSubscriptionItemMapper textbookSubscriptionItemMapper;
- @Override
- @Transactional(rollbackFor = Exception.class)
- public Boolean addRubAndHand(Textbook textbook) {
- // 判断isbn的唯一性
- if (StringUtils.isBlank(textbook.getIssn())
- || ObjectUtils.isEmpty(textbook.getSubjectGroupId())
- || ObjectUtils.isEmpty(textbook.getCourseSubjectId())) {
- throw new MyException("issn,学科组,课程为必填字段");
- }
- textbook.setIsbn(textbook.getIssn());
- if (ObjectUtils.isNotEmpty(textbook.getDiscount()) && ObjectUtils.isNotEmpty(textbook.getPrice())) {
- BigDecimal discount = BigDecimal.valueOf(textbook.getDiscount()).divide(BigDecimal.valueOf(10));
- textbook.setDiscountPrice(textbook.getPrice().multiply(discount));
- }
- // 判断导入的教材是否已经存在,根据教材的 ISSN 码和使用的学科组和课程判断
- LambdaQueryWrapper<Textbook> textbookLambdaQueryWrapper = new LambdaQueryWrapper<>();
- textbookLambdaQueryWrapper
- .eq(Textbook::getIssn, textbook.getIssn())
- .eq(Textbook::getDeleteMark, DeleteMark.NODELETE.getCode())
- ;
- Textbook verifyTextbook = textbookTextbookMapper.selectOne(textbookLambdaQueryWrapper);
- int num;
- if (ObjectUtils.isNotEmpty(verifyTextbook)) {
- textbook.setId(verifyTextbook.getId());
- num = textbookTextbookMapper.updateById(textbook);
- } else {
- num = textbookTextbookMapper.insert(textbook);
- }
- return num > 0;
- }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public Boolean updateRubAndHand(Textbook textbook) {
- Textbook old = textbookTextbookMapper.selectById(textbook.getId());
- if (ObjectUtils.isEmpty(old)) {
- throw new MyException("教材信息已经被修改,请刷新重试。");
- }
- // 折扣修改,定价未修改
- if (ObjectUtils.isNotEmpty(textbook.getDiscount()) && ObjectUtils.isEmpty(textbook.getPrice())) {
- BigDecimal discount = BigDecimal.valueOf(textbook.getDiscount()).divide(BigDecimal.valueOf(10), 2, RoundingMode.DOWN);
- textbook.setDiscountPrice(old.getPrice().multiply(discount));
- }
- // 折扣未修改,定价修改
- if (ObjectUtils.isEmpty(textbook.getDiscount()) && ObjectUtils.isNotEmpty(textbook.getPrice())) {
- BigDecimal discount = BigDecimal.valueOf(old.getDiscount()).divide(BigDecimal.valueOf(10), 2, RoundingMode.DOWN);
- textbook.setDiscountPrice(textbook.getPrice().multiply(discount));
- }
- // 折扣修改,定价修改
- if (ObjectUtils.isNotEmpty(textbook.getDiscount()) && ObjectUtils.isNotEmpty(textbook.getPrice())) {
- BigDecimal discount = BigDecimal.valueOf(textbook.getDiscount()).divide(BigDecimal.valueOf(10), 2, RoundingMode.DOWN);
- textbook.setDiscountPrice(textbook.getPrice().multiply(discount));
- }
- int num = textbookTextbookMapper.updateById(textbook);
- return num > 0;
- }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public Boolean delete(List<Long> ids) {
- // 删除教材前应判断教材是否被班级课程使用,一旦被使用不能删除
- MPJLambdaWrapper<Textbook> baseClassCourse = new MPJLambdaWrapper<>();
- baseClassCourse
- .select(Textbook::getId)
- .select(Textbook.class, x -> VoToColumnUtil.fieldsToColumns(Textbook.class).contains(x.getProperty()))
- .innerJoin(BaseClassCourse.class, BaseClassCourse::getTextbookId, Textbook::getId)
- .in(Textbook::getId, ids)
- ;
- List<Textbook> baseClassCourseTextbooks = this.selectJoinList(Textbook.class, baseClassCourse);
- if (!baseClassCourseTextbooks.isEmpty()) {
- throw new MyException(baseClassCourseTextbooks.get(0).getBookName() + "教材在课程中被使用,请先从课程中移除!");
- }
- // 删除教材前应判断教材是否存在教材征订记录,如果存在征订记录,不应该删除
- MPJLambdaWrapper<Textbook> textbookSubscriptionItem = new MPJLambdaWrapper<>();
- textbookSubscriptionItem
- .select(Textbook::getId)
- .select(Textbook.class, x -> VoToColumnUtil.fieldsToColumns(Textbook.class).contains(x.getProperty()))
- .innerJoin(TextbookSubscriptionItem.class, TextbookSubscriptionItem::getTextbookId, Textbook::getId)
- .in(Textbook::getId, ids)
- ;
- List<Textbook> textbookSubscriptionItemTextbooks = this.selectJoinList(Textbook.class, textbookSubscriptionItem);
- if (!textbookSubscriptionItemTextbooks.isEmpty()) {
- throw new MyException(textbookSubscriptionItemTextbooks.get(0).getBookName() + "教材在证订中被使用,请先从证订中移除!");
- }
- textbookTextbookMapper.deleteBatchIds(ids);
- return true;
- }
- @Override
- public IPage<TextbookPageVo> pageRubAndHand(TextbookPageDto dto) {
- MPJLambdaWrapper<Textbook> textbookMPJLambdaWrapper = new MPJLambdaWrapper<>();
- textbookMPJLambdaWrapper
- .select(Textbook::getId)
- .select(Textbook.class, x -> VoToColumnUtil.fieldsToColumns(TextbookPageVo.class).contains(x.getProperty()))
- .leftJoin(SubjectGroup.class, SubjectGroup::getId, Textbook::getSubjectGroupId,
- wrapper -> wrapper
- .selectAs(SubjectGroup::getGroupName, TextbookPageVo::getGroupName)
- .like(StringUtils.isNotBlank(dto.getGroupName()), SubjectGroup::getGroupName, dto.getGroupName())
- )
- .leftJoin(BaseCourseSubject.class, BaseCourseSubject::getId, Textbook::getCourseSubjectId,
- wrapper -> wrapper
- .selectAs(BaseCourseSubject::getName, TextbookPageVo::getCourseName)
- .like(StringUtils.isNotBlank(dto.getCourseName()), BaseCourseSubject::getName, dto.getCourseName())
- )
- .leftJoin(DictionaryDetail.class, DictionaryDetail::getCode, Textbook::getTextbookType,
- wrapper -> wrapper
- .selectAs(DictionaryDetail::getName, TextbookPageVo::getTextbookTypeCn)
- )
- .eq(ObjectUtils.isNotEmpty(dto.getUseType()), Textbook::getUseType, dto.getUseType())
- .like(StringUtils.isNotBlank(dto.getIssn()), Textbook::getIssn, dto.getIssn())
- .like(StringUtils.isNotBlank(dto.getIsbn()), Textbook::getIsbn, dto.getIsbn())
- .like(StringUtils.isNotBlank(dto.getBookName()), Textbook::getBookName, dto.getBookName())
- .like(StringUtils.isNotBlank(dto.getPublishingHouse()), Textbook::getPublishingHouse, dto.getPublishingHouse())
- .like(StringUtils.isNotBlank(dto.getEditorInChief()), Textbook::getEditorInChief, dto.getEditorInChief())
- .eq(StringUtils.isNotBlank(dto.getVersion()), Textbook::getVersion, dto.getVersion())
- .eq(ObjectUtils.isNotEmpty(dto.getCourseSubjectId()), Textbook::getCourseSubjectId, dto.getCourseSubjectId())
- .eq(ObjectUtils.isNotEmpty(dto.getSubjectGroupId()), Textbook::getSubjectGroupId, dto.getSubjectGroupId())
- .eq(ObjectUtils.isNotEmpty(dto.getIsTextbookPlan()), Textbook::getIsTextbookPlan, dto.getIsTextbookPlan())
- .eq(StringUtils.isNotBlank(dto.getTextbookType()), Textbook::getTextbookType, dto.getTextbookType())
- .eq(StringUtils.isNotBlank(dto.getSpecificationsModels()), Textbook::getSpecificationsModels, dto.getSpecificationsModels())
- .eq(ObjectUtils.isNotEmpty(dto.getIsSecd()), Textbook::getIsSecd, dto.getIsSecd())
- .eq(StringUtils.isNotBlank(dto.getCategory()), Textbook::getCategory, dto.getCategory())
- .eq(StringUtils.isNotBlank(dto.getPlanBatch()), Textbook::getPlanBatch, dto.getPlanBatch())
- .eq(ObjectUtils.isNotEmpty(dto.getWorkTotalCount()), Textbook::getWorkTotalCount, dto.getWorkTotalCount())
- .eq(StringUtils.isNotBlank(dto.getTextbookCategory()), Textbook::getTextbookCategory, dto.getTextbookCategory())
- .eq(ObjectUtils.isNotEmpty(dto.getPrice()), Textbook::getPrice, dto.getPrice())
- .eq(ObjectUtils.isNotEmpty(dto.getDiscount()), Textbook::getDiscount, dto.getDiscount())
- .orderByDesc(Textbook::getId)
- ;
- return textbookTextbookMapper.selectJoinPage(ConventPage.getPage(dto), TextbookPageVo.class, textbookMPJLambdaWrapper);
- }
- @Override
- public List<TextbookListVo> listRubAndHand(TextbookListDto dto) {
- MPJLambdaWrapper<Textbook> textbookMPJLambdaWrapper = new MPJLambdaWrapper<>();
- textbookMPJLambdaWrapper
- .select(Textbook::getId)
- .select(Textbook.class, x -> VoToColumnUtil.fieldsToColumns(TextbookListVo.class).contains(x.getProperty()))
- .leftJoin(SubjectGroup.class, SubjectGroup::getId, Textbook::getSubjectGroupId,
- wrapper -> wrapper
- .selectAs(SubjectGroup::getGroupName, TextbookListVo::getGroupName)
- .like(StringUtils.isNotBlank(dto.getGroupName()), SubjectGroup::getGroupName, dto.getGroupName())
- )
- .leftJoin(BaseCourseSubject.class, BaseCourseSubject::getId, Textbook::getCourseSubjectId,
- wrapper -> wrapper
- .selectAs(BaseCourseSubject::getName, TextbookListVo::getCourseName)
- .like(StringUtils.isNotBlank(dto.getCourseName()), BaseCourseSubject::getName, dto.getCourseName())
- )
- .leftJoin(DictionaryDetail.class, DictionaryDetail::getCode, Textbook::getTextbookType,
- wrapper -> wrapper
- .selectAs(DictionaryDetail::getName, TextbookListVo::getTextbookTypeCn)
- )
- .eq(ObjectUtils.isNotEmpty(dto.getUseType()), Textbook::getUseType, dto.getUseType())
- .like(StringUtils.isNotBlank(dto.getIssn()), Textbook::getIssn, dto.getIssn())
- .like(StringUtils.isNotBlank(dto.getIsbn()), Textbook::getIsbn, dto.getIsbn())
- .like(StringUtils.isNotBlank(dto.getBookName()), Textbook::getBookName, dto.getBookName())
- .like(StringUtils.isNotBlank(dto.getPublishingHouse()), Textbook::getPublishingHouse, dto.getPublishingHouse())
- .like(StringUtils.isNotBlank(dto.getEditorInChief()), Textbook::getEditorInChief, dto.getEditorInChief())
- .eq(StringUtils.isNotBlank(dto.getVersion()), Textbook::getVersion, dto.getVersion())
- .eq(ObjectUtils.isNotEmpty(dto.getIsTextbookPlan()), Textbook::getIsTextbookPlan, dto.getIsTextbookPlan())
- .eq(StringUtils.isNotBlank(dto.getTextbookType()), Textbook::getTextbookType, dto.getTextbookType())
- .eq(StringUtils.isNotBlank(dto.getSpecificationsModels()), Textbook::getSpecificationsModels, dto.getSpecificationsModels())
- .eq(ObjectUtils.isNotEmpty(dto.getIsSecd()), Textbook::getIsSecd, dto.getIsSecd())
- .eq(StringUtils.isNotBlank(dto.getCategory()), Textbook::getCategory, dto.getCategory())
- .eq(StringUtils.isNotBlank(dto.getPlanBatch()), Textbook::getPlanBatch, dto.getPlanBatch())
- .eq(ObjectUtils.isNotEmpty(dto.getWorkTotalCount()), Textbook::getWorkTotalCount, dto.getWorkTotalCount())
- .eq(StringUtils.isNotBlank(dto.getTextbookCategory()), Textbook::getTextbookCategory, dto.getTextbookCategory())
- .eq(ObjectUtils.isNotEmpty(dto.getPrice()), Textbook::getPrice, dto.getPrice())
- .eq(ObjectUtils.isNotEmpty(dto.getDiscount()), Textbook::getDiscount, dto.getDiscount())
- ;
- return textbookTextbookMapper.selectJoinList(TextbookListVo.class, textbookMPJLambdaWrapper);
- }
- /* @Override
- @Transactional
- public Boolean dataHandleAddTextbookNode(Long dataId) {
- WfTextbookSubscription wfTextbookSubscription = iWfTextbookSubscriptionService.selectById(dataId);
- if (ObjectUtil.isNotNull(wfTextbookSubscription) && ObjectUtil.isNotNull(wfTextbookSubscription.getWfTextbookSubscriptionItemList()) && wfTextbookSubscription.getWfTextbookSubscriptionItemList().size() > 0) {
- //遍历征订项
- for (WfTextbookSubscriptionItem wfTextbookSubscriptionItem : wfTextbookSubscription.getWfTextbookSubscriptionItemList()) {
- Long semesterId = wfTextbookSubscription.getBaseSemesterId();
- String issn = wfTextbookSubscriptionItem.getIssn();
- LambdaQueryWrapper<Textbook> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper
- .eq(Textbook::getIssn, issn)
- .eq(Textbook::getBaseSemesterId, semesterId);
- List<Textbook> textbookList = this.list(queryWrapper);
- //征订的教材没有在教材管理
- if (ObjectUtil.isNull(textbookList) || textbookList.size() == 0) {
- Textbook textbook = new Textbook() {{
- setIssn((ObjectUtil.isNull(wfTextbookSubscriptionItem.getIssn()) || StringUtils.isBlank(wfTextbookSubscriptionItem.getIssn())) ? "/" : wfTextbookSubscriptionItem.getIssn());
- setIsbn((ObjectUtil.isNull(wfTextbookSubscriptionItem.getIsbn()) || StringUtils.isBlank(wfTextbookSubscriptionItem.getIsbn())) ? "/" : wfTextbookSubscriptionItem.getIsbn());
- setBookName((ObjectUtil.isNull(wfTextbookSubscriptionItem.getBookName()) || StringUtils.isBlank(wfTextbookSubscriptionItem.getBookName())) ? "/" : wfTextbookSubscriptionItem.getBookName());
- setPublishingHouse((ObjectUtil.isNull(wfTextbookSubscriptionItem.getPublishingHouse()) || StringUtils.isBlank(wfTextbookSubscriptionItem.getPublishingHouse())) ? "/" : wfTextbookSubscriptionItem.getPublishingHouse());
- setEditorInChief((ObjectUtil.isNull(wfTextbookSubscriptionItem.getEditorInChief()) || StringUtils.isBlank(wfTextbookSubscriptionItem.getEditorInChief())) ? "/" : wfTextbookSubscriptionItem.getEditorInChief());
- setSubjectGroupId((ObjectUtil.isNull(wfTextbookSubscription.getSubjectGroupId())) ? 0 : wfTextbookSubscription.getSubjectGroupId());
- setBaseSemesterId(wfTextbookSubscription.getBaseSemesterId());
- setCourseSubjectId((ObjectUtil.isNull(wfTextbookSubscriptionItem.getCourseSubjectId())) ? 0 : wfTextbookSubscriptionItem.getCourseSubjectId());
- setVersion((ObjectUtil.isNull(wfTextbookSubscriptionItem.getVersion()) || StringUtils.isBlank(wfTextbookSubscriptionItem.getVersion())) ? "/" : wfTextbookSubscriptionItem.getVersion());
- setIsTextbookPlan((ObjectUtil.isNull(wfTextbookSubscriptionItem.getIsTextbookPlan()) || StringUtils.isBlank(wfTextbookSubscriptionItem.getIsTextbookPlan())) ? "/" : wfTextbookSubscriptionItem.getIsTextbookPlan());
- if (ObjectUtil.isNotNull(wfTextbookSubscriptionItem.getSubscriptionType()) && wfTextbookSubscriptionItem.getSubscriptionType().equals(SubscriptionTypeEnum.STextbook.getCode())) {
- setTextbookType(TextbookTypeEnum.TTextbook.getCode());
- }
- if (ObjectUtil.isNotNull(wfTextbookSubscriptionItem.getSubscriptionType()) && wfTextbookSubscriptionItem.getSubscriptionType().equals(SubscriptionTypeEnum.SMaterials.getCode())) {
- setTextbookType(TextbookTypeEnum.TMaterials.getCode());
- }
- setSpecificationsModels("/");
- setAppraisalPrice((ObjectUtil.isNull(wfTextbookSubscriptionItem.getAppraisalPrice())) ? new BigDecimal(0) : wfTextbookSubscriptionItem.getAppraisalPrice());
- setPrice(new BigDecimal(0));
- setDiscount(10D);
- setSubtotal(new BigDecimal(0));
- setStock(0);
- }};
- //班级不为空
- List<Long> classIdList = new ArrayList<>();
- if (ObjectUtil.isNotNull(wfTextbookSubscriptionItem.getClassIds()) && !wfTextbookSubscriptionItem.getClassIds().equals("")) {
- //将班级ids转换为List
- String classIds = wfTextbookSubscriptionItem.getClassIds();
- String[] classIdStrs = classIds.split(",");
- for (String classIdStr : classIdStrs) {
- classIdList.add(Long.parseLong(classIdStr));
- }
- //查询年级,如果添加的班级只存在一个年级,添加年级字段值
- LambdaQueryWrapper<BaseClass> queryWrapper1 = new LambdaQueryWrapper<>();
- queryWrapper1
- .select(BaseClass::getGradeId)
- .in(BaseClass::getId, classIdList)
- .groupBy(BaseClass::getGradeId);
- List<BaseClass> baseClassList = baseClassService.list(queryWrapper1);
- if (ObjectUtil.isNotNull(baseClassList) && baseClassList.size() == 1) {
- textbook.setGradeId(baseClassList.get(0).getGradeId());
- }
- }
- //插入教材数据
- textbook.setCreateDate(new Date());
- textbookTextbookMapper.insert(textbook);
- //插入班级和教材关系
- for (Long classId : classIdList) {
- textbookTextbookClassRelationMapper.insert(new TextbookClassRelation() {{
- setCreateDate(new Date());
- setTextbookId(textbook.getId());
- setClassId(classId);
- }});
- }
- //添加教材征订记录
- textbookTextbookSubscriptionRecordMapper.insert(new TextbookSubscriptionRecord() {{
- setCreateDate(new Date());
- setTextbookId(textbook.getId());
- setWfTextbookSubscriptionId(wfTextbookSubscription.getId());
- setWfTextbookSubscriptionItemId(wfTextbookSubscriptionItem.getId());//该字段存入征订项的id,征订项中有所属征订记录
- }});
- } else {
- //征订的教材在教材管理,进行班级的和记录的管理
- Textbook textbook = textbookList.get(0);
- //班级不为空
- if (ObjectUtil.isNotNull(wfTextbookSubscriptionItem.getClassIds()) && !wfTextbookSubscriptionItem.getClassIds().equals("")) {
- //将班级ids转换为List
- String classIds = wfTextbookSubscriptionItem.getClassIds();
- String[] classIdStrs = classIds.split(",");
- for (String classIdStr : classIdStrs) {
- textbookTextbookClassRelationMapper.insert(new TextbookClassRelation() {{
- setCreateDate(new Date());
- setTextbookId(textbook.getId());
- setClassId(Long.parseLong(classIdStr));
- }});
- }
- }
- //添加教材征订记录
- textbookTextbookSubscriptionRecordMapper.insert(new TextbookSubscriptionRecord() {{
- setCreateDate(new Date());
- setTextbookId(textbook.getId());
- setWfTextbookSubscriptionId(wfTextbookSubscription.getId());
- setWfTextbookSubscriptionItemId(wfTextbookSubscriptionItem.getId());//该字段存入正定项的id,征订项中有所属征订记录
- }});
- }
- }
- }
- return true;
- }*/
- /**
- * 添加作业本规则
- *
- * @param dataId
- * @return
- */
- @Override
- @Transactional
- public Boolean dataHandleAddExerciseBookNode(Long dataId) {
- WfExerciseBook wfExerciseBook = wfExerciseBookService.selectById(dataId);
- if (ObjectUtils.isNotEmpty(wfExerciseBook) && ObjectUtils.isNotEmpty(wfExerciseBook.getWfExerciseBookItemList()) && wfExerciseBook.getWfExerciseBookItemList().size() > 0) {
- for (WfExerciseBookItem wfExerciseBookItem : wfExerciseBook.getWfExerciseBookItemList()) {
- Long semesterId = wfExerciseBook.getBaseSemesterId();
- String bookName = wfExerciseBookItem.getSubscriptionType();//作业本的选择类型对应教材管理的书名
- LambdaQueryWrapper<Textbook> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper
- .eq(Textbook::getBookName, bookName)
- ;
- List<Textbook> textbookList = this.list(queryWrapper);
- //征订的作业本没有在教材管理
- if (ObjectUtils.isEmpty(textbookList) || textbookList.size() == 0) {
- Textbook textbook = new Textbook() {{
- setIssn("/");
- setIsbn("/");
- if (ObjectUtils.isNotEmpty(wfExerciseBookItem.getSubscriptionType()) && wfExerciseBookItem.getSubscriptionType().equals(ExerciseBookeTypeEnum.ExerciseBook1.getCode())) {
- setBookName(ExerciseBookeTypeEnum.ExerciseBook1.getValue());
- }
- if (ObjectUtils.isNotEmpty(wfExerciseBookItem.getSubscriptionType()) && wfExerciseBookItem.getSubscriptionType().equals(ExerciseBookeTypeEnum.ExerciseBook2.getCode())) {
- setBookName(ExerciseBookeTypeEnum.ExerciseBook2.getValue());
- }
- setPublishingHouse("/");
- setEditorInChief("/");
- setVersion("/");
- setTextbookType(TextbookTypeEnum.TExerciseBook.getCode());
- setSpecificationsModels((ObjectUtils.isEmpty(wfExerciseBookItem.getSpecificationsModels()) || StringUtils.isBlank(wfExerciseBookItem.getSpecificationsModels())) ? "/" : wfExerciseBookItem.getSpecificationsModels());
- //年级id
- if (ObjectUtils.isNotEmpty(wfExerciseBook.getClassId()) && wfExerciseBook.getClassId() > 0) {
- LambdaQueryWrapper<BaseClass> queryWrapper1 = new LambdaQueryWrapper<>();
- queryWrapper1
- .eq(BaseClass::getId, wfExerciseBook.getClassId());
- BaseClass baseClass = baseClassService.getOne(queryWrapper1);
- }
- setPrice(new BigDecimal(0));
- setDiscount(10D);
- }};
- //插入教材数据
- textbook.setCreateDate(new Date());
- textbookTextbookMapper.insert(textbook);
- //插入班级和教材关系
- if (ObjectUtils.isNotEmpty(wfExerciseBook.getClassId()) && wfExerciseBook.getClassId() > 0) {
- textbookTextbookClassRelationMapper.insert(new TextbookClassRelation() {{
- setCreateDate(new Date());
- setTextbookId(textbook.getId());
- setClassId(wfExerciseBook.getClassId());
- }});
- }
- //添加教材征订记录
- textbookTextbookSubscriptionRecordMapper.insert(new TextbookSubscriptionRecord() {{
- setCreateDate(new Date());
- setTextbookId(textbook.getId());
- setWfTextbookSubscriptionId(wfExerciseBook.getId());
- }});
- } else {
- //征订的教材在教材管理,进行班级的和记录的管理
- Textbook textbook = textbookList.get(0);
- //班级不为空
- if (ObjectUtils.isNotEmpty(wfExerciseBook.getClassId()) && wfExerciseBook.getClassId() > 0) {
- textbookTextbookClassRelationMapper.insert(new TextbookClassRelation() {{
- setCreateDate(new Date());
- setTextbookId(textbook.getId());
- setClassId(wfExerciseBook.getClassId());
- }});
- }
- //添加教材征订记录
- textbookTextbookSubscriptionRecordMapper.insert(new TextbookSubscriptionRecord() {{
- setCreateDate(new Date());
- setTextbookId(textbook.getId());
- setWfTextbookSubscriptionId(wfExerciseBook.getId());
- }});
- }
- }
- }
- return true;
- }
- @Override
- public List<TextbookSubscriptionRecordVo> subscriptionList(Long id) {
- Textbook textbook = this.getById(id);
- List<TextbookSubscriptionRecordVo> recordVos = new ArrayList<>();
- //是作业本
- if (textbook.getTextbookType().equals(TextbookTypeEnum.TExerciseBook.getCode())) {
- recordVos = textbookTextbookMapper.exerciseBookSubscriptionList(id);
- for (TextbookSubscriptionRecordVo recordVo : recordVos) {
- recordVo.setIssn("/");
- recordVo.setPublishingHouse("/");
- recordVo.setEditorInChief("/");
- recordVo.setIsTextbookPlanCn("/");
- recordVo.setCourseName("/");
- recordVo.setGradeName("/");
- recordVo.setTeacherSubscriptionNumber(0);
- recordVo.setTeacherReferenceNumber(0);
- }
- }
- //是教材或者教辅
- if (textbook.getTextbookType().equals(TextbookTypeEnum.TTextbook.getCode()) || textbook.getTextbookType().equals(TextbookTypeEnum.TMaterials.getCode())) {
- recordVos = textbookTextbookMapper.subscriptionList(id);
- for (TextbookSubscriptionRecordVo recordVo : recordVos) {
- if (ObjectUtils.isEmpty(recordVo) || StrUtil.isEmpty(recordVo.getClassIds())) {
- // recordVos.remove(recordVo);
- // if (recordVos.isEmpty()) {
- // break;
- // }
- continue;
- }
- String[] split = recordVo.getClassIds().split(",");
- List<String> ids = new ArrayList<>();
- for (String classId : split) {
- ids.add(classId.trim());
- }
- List<TextbookSubscriptionClassVo> classInfo = textbookTextbookMapper.getClassInfo(ids);
- String useClass = "";
- for (int i = 0; i < classInfo.size(); i++) {
- if (i >= 1) {
- useClass += ",";
- }
- TextbookSubscriptionClassVo classVo = classInfo.get(i);
- useClass += classVo.getName();
- }
- recordVo.setUseClass(useClass);
- }
- }
- return recordVos;
- }
- @Override
- public TextbookVo getInfoByissn(String issn) {
- TextbookVo infoByissn = textbookTextbookMapper.getInfoByissn(issn);
- if (infoByissn == null) {
- return null;
- }
- List<TextbookClassRelation> classRelationList = textbookTextbookClassRelationMapper.selectList(
- new QueryWrapper<TextbookClassRelation>().lambda().eq(TextbookClassRelation::getTextbookId, infoByissn.getId())
- );
- return infoByissn;
- }
- @Override
- public List<TextbookWarehouseRecordListVo> warehouseList(Long id) {
- List<TextbookWarehouseRecordListVo> result = textbookTextbookMapper.warehouseList(id);
- if (!result.isEmpty()) {
- return result;
- }
- return new ArrayList<>();
- }
- @Override
- public List<TextbookClassRelation> getClassRelation(Long id) {
- List<TextbookClassRelation> classRelation = textbookTextbookMapper.getClassRelation(id);
- if (!classRelation.isEmpty()) {
- return classRelation;
- }
- return new ArrayList<>();
- }
- @Override
- public List<TextbookIssueRecordListVo> issueList(Long id) {
- List<TextbookIssueRecordListVo> result = textbookTextbookMapper.issueList(id);
- if (!result.isEmpty()) {
- return result;
- }
- return new ArrayList<>();
- }
- @Override
- public List<WfTextbookClaimListVo> claimList(Long id) {
- List<WfTextbookClaimListVo> result = new ArrayList<>();
- //教材领取分为两种
- //教师领取
- MPJLambdaWrapper<TextbookIssueRecord> queryIssueRecord = new MPJLambdaWrapper<>();
- queryIssueRecord
- .eq(TextbookIssueRecord::getTextbookId, id)
- .eq(TextbookIssueRecord::getIssueMode, "im_teacher");
- List<TextbookIssueRecord> textbookIssueRecordList = textbookIssueRecordMapper.selectJoinList(TextbookIssueRecord.class, queryIssueRecord);
- for (TextbookIssueRecord t : textbookIssueRecordList) {
- MPJLambdaWrapper<TextbookIssueRecord> queryTeaClaimVo = new MPJLambdaWrapper<>();
- queryTeaClaimVo
- .selectAs(BaseSemester::getName, WfTextbookClaimListVo::getSemesterName)
- .selectAs(XjrUser::getName, WfTextbookClaimListVo::getName)
- .selectAs(XjrUser::getUserName, WfTextbookClaimListVo::getUserName)
- .selectAs(TextbookIssueRecord::getCreateDate, WfTextbookClaimListVo::getClaimDate)
- .leftJoin(XjrUser.class, XjrUser::getId, TextbookIssueRecord::getReceiveUserId)
- .leftJoin(WfTextbookClaim.class, WfTextbookClaim::getId, TextbookIssueRecord::getDataId)
- .leftJoin(BaseSemester.class, BaseSemester::getId, WfTextbookClaim::getBaseSemesterId)
- .eq(TextbookIssueRecord::getId, t.getId());
- WfTextbookClaimListVo wfTextbookClaimListVo = textbookIssueRecordMapper.selectJoinOne(WfTextbookClaimListVo.class, queryTeaClaimVo);
- for (int j = 0; j < t.getIssueNumber(); j++) {
- wfTextbookClaimListVo.setClaimIdentity("教师");
- wfTextbookClaimListVo.setClassName("/");
- result.add(wfTextbookClaimListVo);
- }
- }
- //学生领取
- MPJLambdaWrapper<TextbookStudentClaim> queryStuClaimVo = new MPJLambdaWrapper<>();
- queryStuClaimVo
- .select("'学生' as claimIdentity")
- .selectAs(BaseClass::getName, WfTextbookClaimListVo::getClassName)
- .selectAs(BaseSemester::getName, WfTextbookClaimListVo::getSemesterName)
- .selectAs(XjrUser::getName, WfTextbookClaimListVo::getName)
- .selectAs(XjrUser::getUserName, WfTextbookClaimListVo::getUserName)
- .selectAs(TextbookStudentClaim::getCreateDate, WfTextbookClaimListVo::getClaimDate)
- .leftJoin(XjrUser.class, XjrUser::getId, TextbookStudentClaim::getStudentUserId)
- .leftJoin(BaseSemester.class, BaseSemester::getId, TextbookStudentClaim::getBaseSemesterId)
- .leftJoin(BaseClass.class, BaseClass::getId, TextbookStudentClaim::getClassId)
- .eq(TextbookStudentClaim::getTextbookId, id)
- .eq(TextbookStudentClaim::getIsClaim, 1);
- List<WfTextbookClaimListVo> wfTextbookClaimListVoList = textbookStudentClaimMapper.selectJoinList(WfTextbookClaimListVo.class, queryStuClaimVo);
- result.addAll(wfTextbookClaimListVoList);
- return result;
- }
- @Override
- public List<TextbookStandingExportQueryVo> listTextbookStandingExportQuery(TextbookStandingExportQuerytDto dto) {
- return textbookTextbookMapper.listTextbookStandingExportQuery(dto);
- }
- @Override
- public ByteArrayOutputStream listTextbookSubscriptionExportQuery(TextbookSubscriptionExportQueryDto dto) {
- List<TextbookSubscriptionExportQueryVo> result = textbookTextbookMapper.listTextbookSubscriptionExportQuery(dto);
- //将班级转换为中文
- for (TextbookSubscriptionExportQueryVo to : result) {
- if (to != null && to.getClassIds() != null && !("").equals(to.getClassIds())) {
- List<Long> classIdList = new ArrayList<>();
- String[] classIdStrs = to.getClassIds().split(",");
- for (String classIdStr : classIdStrs) {
- classIdList.add(Long.parseLong(classIdStr.trim()));
- }
- LambdaQueryWrapper<BaseClass> baseClassLambdaQueryWrapper = new LambdaQueryWrapper<>();
- baseClassLambdaQueryWrapper
- .in(BaseClass::getId, classIdList);
- List<BaseClass> baseClassList = baseClassService.list(baseClassLambdaQueryWrapper);
- if (baseClassList.size() > 0) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < baseClassList.size(); i++) {
- sb.append(baseClassList.get(i).getName());
- if (i != baseClassList.size() - 1) {
- sb.append(",");
- }
- }
- to.setUseClass(sb.toString());
- }
- }
- }
- ByteArrayOutputStream bot = new ByteArrayOutputStream();
- // 设置动态头
- String baseSemesterCn = "";
- if (dto.getBaseSemesterId() != null) {
- LambdaQueryWrapper<BaseSemester> baseSemesterLambdaQueryWrapper = new LambdaQueryWrapper<>();
- baseSemesterLambdaQueryWrapper
- .eq(BaseSemester::getId, dto.getBaseSemesterId());
- BaseSemester baseSemester = baseSemesterMapper.selectOne(baseSemesterLambdaQueryWrapper);
- if (baseSemester != null) {
- baseSemesterCn = baseSemester.getName();
- }
- }
- String headTitle = "重庆市铜梁职业教育中心" + baseSemesterCn + "教材征订表";
- List<List<String>> headList = new ArrayList<>();
- // List<String> head0 = new ArrayList<>();
- // head0.add("个人信息");
- // head0.add("用户名");
- // List<String> head1 = new ArrayList<>();
- // head1.add("个人信息");
- // head1.add("年龄");
- // List<String> head2 = new ArrayList<>();
- // head2.add("个人信息");
- // head2.add("地址");
- headList.add(new ArrayList<String>() {{
- add(headTitle);
- add("国际标准刊号");
- }});
- headList.add(new ArrayList<String>() {{
- add(headTitle);
- add("书名");
- }});
- headList.add(new ArrayList<String>() {{
- add(headTitle);
- add("出版社");
- }});
- headList.add(new ArrayList<String>() {{
- add(headTitle);
- add("主编");
- }});
- headList.add(new ArrayList<String>() {{
- add(headTitle);
- add("估价(元)");
- }});
- headList.add(new ArrayList<String>() {{
- add(headTitle);
- add("是否为规划教材");
- }});
- headList.add(new ArrayList<String>() {{
- add(headTitle);
- add("对应课程");
- }});
- headList.add(new ArrayList<String>() {{
- add(headTitle);
- add("使用年级");
- }});
- headList.add(new ArrayList<String>() {{
- add(headTitle);
- add("使用班级");
- }});
- headList.add(new ArrayList<String>() {{
- add(headTitle);
- add("学生用书征订数量");
- }});
- headList.add(new ArrayList<String>() {{
- add(headTitle);
- add("教师教材用书征订数量");
- }});
- headList.add(new ArrayList<String>() {{
- add(headTitle);
- add("教师教参用书征订数量");
- }});
- headList.add(new ArrayList<String>() {{
- add(headTitle);
- add("学科组名称");
- }});
- headList.add(new ArrayList<String>() {{
- add(headTitle);
- add("有无配套教学资源");
- }});
- headList.add(new ArrayList<String>() {{
- add(headTitle);
- add("备注");
- }});
- EasyExcel.write(bot, TextbookSubscriptionExportQueryVo.class).automaticMergeHead(true).excelType(ExcelTypeEnum.XLSX).head(headList).sheet().doWrite(result);
- return bot;
- }
- @Override
- public ByteArrayOutputStream listTextbookClaimExportQuery(TextbookClaimExportQueryDto dto) {
- List<TextbookClaimExportQueryVo> customerList = textbookTextbookMapper.listTextbookClaimExportQuery(dto);
- ByteArrayOutputStream bot = new ByteArrayOutputStream();
- //内容样式
- WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
- //设计内容居中
- contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);// 水平居中
- contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);// 垂直居中
- contentWriteCellStyle.setWrapped(true); //设置自动换行;
- // 设置字体
- WriteFont contentWriteFont = new WriteFont();
- contentWriteFont.setFontHeightInPoints((short) 12);//设置字体大小
- contentWriteFont.setFontName("宋体"); //设置字体名字
- contentWriteCellStyle.setWriteFont(contentWriteFont);//在样式用应用设置的字体;
- //设置样式;
- contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);//设置底边框;
- contentWriteCellStyle.setBottomBorderColor((short) 0);//设置底边框颜色;
- contentWriteCellStyle.setBorderLeft(BorderStyle.THIN); //设置左边框;
- contentWriteCellStyle.setLeftBorderColor((short) 0);//设置左边框颜色;
- contentWriteCellStyle.setBorderRight(BorderStyle.THIN);//设置右边框;
- contentWriteCellStyle.setRightBorderColor((short) 0);//设置右边框颜色;
- contentWriteCellStyle.setBorderTop(BorderStyle.THIN);//设置顶边框;
- contentWriteCellStyle.setTopBorderColor((short) 0); ///设置顶边框颜色;
- //设置头部样式
- WriteCellStyle headWriteCellStyle = new WriteCellStyle();
- // 背景颜色
- // headWriteCellStyle.setFillForegroundColor(IndexedColors.LIGHT_TURQUOISE1.getIndex());
- // headWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
- // 字体
- WriteFont headWriteFont = new WriteFont();
- headWriteFont.setFontName("宋体");//设置字体名字
- headWriteFont.setFontHeightInPoints((short) 14);//设置字体大小
- headWriteFont.setBold(true);//字体加粗
- headWriteCellStyle.setWriteFont(headWriteFont); //在样式用应用设置的字体;
- // 样式
- headWriteCellStyle.setBorderBottom(BorderStyle.THIN);//设置底边框;
- headWriteCellStyle.setBottomBorderColor((short) 0);//设置底边框颜色;
- headWriteCellStyle.setBorderLeft(BorderStyle.THIN); //设置左边框;
- headWriteCellStyle.setLeftBorderColor((short) 0);//设置左边框颜色;
- headWriteCellStyle.setBorderRight(BorderStyle.THIN);//设置右边框;
- headWriteCellStyle.setRightBorderColor((short) 0);//设置右边框颜色;
- headWriteCellStyle.setBorderTop(BorderStyle.THIN);//设置顶边框;
- headWriteCellStyle.setTopBorderColor((short) 0); //设置顶边框颜色;
- headWriteCellStyle.setWrapped(true); //设置自动换行;
- //设置头部标题居中
- headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);//设置水平对齐的样式为居中对齐;
- headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐的样式为居中对齐;
- headWriteCellStyle.setShrinkToFit(true);//设置文本收缩至合适
- // 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现
- HorizontalCellStyleStrategy horizontalCellStyleStrategy =
- new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
- try (ExcelWriter excelWriter = EasyExcel.write(bot, TextbookClaimExportQueryVo.class).registerWriteHandler(horizontalCellStyleStrategy).build()) {
- //已经写入的行
- int rowIndex = 0;
- //已经写入的表
- int tableIndex = 0;
- // 把sheet设置为不需要头 不然会输出sheet的头 这样看起来第一个table 就有2个头了
- WriteSheet writeSheet = EasyExcel.writerSheet("模板").needHead(Boolean.FALSE).build();
- //sheet的表头
- List<List<String>> sheetHeadList = new ArrayList<List<String>>();
- sheetHeadList.add(new ArrayList<String>() {{
- add("铜梁执教中心班级教材教辅发放情况表");
- }});
- //sheet的表头合并策略
- ExcelFillCellMergePrevColUtil sheetHeadColumn = new ExcelFillCellMergePrevColUtil();
- sheetHeadColumn.add(rowIndex, 0, 12);
- //这是一个sheet表头的table
- WriteTable writeSheetHeadTable = EasyExcel.writerTable(tableIndex).needHead(Boolean.TRUE).head(sheetHeadList).registerWriteHandler(sheetHeadColumn).build();
- excelWriter.write(new ArrayList<>(), writeSheet, writeSheetHeadTable);
- //对返回的集合进行处理
- //现针对学期进行分组
- Map<Long, List<TextbookClaimExportQueryVo>> groupedBySemester = customerList.stream()
- .collect(Collectors.groupingBy(TextbookClaimExportQueryVo::getBaseSemesterId));
- Iterator<Map.Entry<Long, List<TextbookClaimExportQueryVo>>> groupedBySemesterIterator = groupedBySemester.entrySet().iterator();
- while (groupedBySemesterIterator.hasNext()) {
- Map.Entry<Long, List<TextbookClaimExportQueryVo>> groupedBySemesterEntry = groupedBySemesterIterator.next();
- Long key = groupedBySemesterEntry.getKey();
- List<TextbookClaimExportQueryVo> value = groupedBySemesterEntry.getValue();
- Map<Long, List<TextbookClaimExportQueryVo>> groupedBySemesterByClass = value.stream()
- .collect(Collectors.groupingBy(TextbookClaimExportQueryVo::getClassId));
- Iterator<Map.Entry<Long, List<TextbookClaimExportQueryVo>>> groupedBySemesterByClassIdIterator = groupedBySemesterByClass.entrySet().iterator();
- while (groupedBySemesterByClassIdIterator.hasNext()) {
- Map.Entry<Long, List<TextbookClaimExportQueryVo>> groupedBySemesterByClassIdEntry = groupedBySemesterByClassIdIterator.next();
- Long k = groupedBySemesterByClassIdEntry.getKey();
- List<TextbookClaimExportQueryVo> v = groupedBySemesterByClassIdEntry.getValue();
- //这是一个table的表头
- List<List<String>> tableHeadList = new ArrayList<List<String>>();
- tableHeadList.add(new ArrayList<String>() {{
- add("日期:" + v.get(0).getBaseSemesterIdCn() + " 班级:" + v.get(0).getClassIdCn() + " 班主任:" + v.get(0).getHeadTeacherName() + " 教室:" + v.get(0).getClassRoomName() + " ");
- }});
- //table的表头合并策略
- ExcelFillCellMergePrevColUtil tableHeadColumn = new ExcelFillCellMergePrevColUtil();
- tableHeadColumn.add(++rowIndex, 0, 9);
- //这是一个table表头的table
- WriteTable writeTableHeadTable = EasyExcel.writerTable(++tableIndex).needHead(Boolean.TRUE).head(tableHeadList).registerWriteHandler(tableHeadColumn).build();
- excelWriter.write(new ArrayList<>(), writeSheet, writeTableHeadTable);
- Map<String, List<TextbookClaimExportQueryVo>> groupedByTextbookType = v.stream()
- .collect(Collectors.groupingBy(TextbookClaimExportQueryVo::getTextbookTypeCn));
- Iterator<Map.Entry<String, List<TextbookClaimExportQueryVo>>> groupedByTextbookTypeIterator = groupedByTextbookType.entrySet().iterator();
- int index = 1;
- BigDecimal total = new BigDecimal("0");
- while (groupedByTextbookTypeIterator.hasNext()) {
- Map.Entry<String, List<TextbookClaimExportQueryVo>> groupedByTextbookTypeEntry = groupedByTextbookTypeIterator.next();
- String kk = groupedByTextbookTypeEntry.getKey();
- List<TextbookClaimExportQueryVo> vv = groupedByTextbookTypeEntry.getValue();
- if (index == 1) {
- //添加小计
- ExcelFillCellMergePrevColUtil subtotalColumn = new ExcelFillCellMergePrevColUtil();
- subtotalColumn.add(rowIndex + vv.size() + 2, 1, 4);
- BigDecimal subtotal = new BigDecimal("0");
- for (TextbookClaimExportQueryVo tv : vv) {
- subtotal = subtotal.add(tv.getSubtotal() == null ? new BigDecimal("0") : tv.getSubtotal());
- }
- BigDecimal finalSubtotal = subtotal;
- vv.add(new TextbookClaimExportQueryVo() {{
- setTextbookTypeCn(vv.get(0).getTextbookTypeCn());
- setBookName("小计");
- setSubtotal(finalSubtotal);
- }});
- total = total.add(finalSubtotal);
- // 调用合并单元格工具类,此工具类是根据工程名称相同则合并后面数据
- int mergeRowIndex = rowIndex + 1;
- int[] mergeColumeIndex = {0};
- ExcelMergeUtil excelFillCellMergeStrategy = new ExcelMergeUtil(mergeRowIndex, mergeColumeIndex);
- // 第一次必须指定需要头,table 会继承sheet的配置,sheet配置了不需要,table 默认也是不需要
- WriteTable writeContentTable = EasyExcel.writerTable(++tableIndex).needHead(Boolean.TRUE).registerWriteHandler(subtotalColumn).registerWriteHandler(excelFillCellMergeStrategy).build();
- // 第一次写入会创建头
- excelWriter.write(vv, writeSheet, writeContentTable);
- rowIndex += (1 + vv.size());
- } else {
- //添加小计
- ExcelFillCellMergePrevColUtil subtotalColumn = new ExcelFillCellMergePrevColUtil();
- subtotalColumn.add(rowIndex + vv.size() + 1, 1, 4);
- BigDecimal subtotal = new BigDecimal("0");
- for (TextbookClaimExportQueryVo tv : vv) {
- subtotal = subtotal.add(tv.getSubtotal());
- }
- BigDecimal finalSubtotal = subtotal;
- vv.add(new TextbookClaimExportQueryVo() {{
- setTextbookTypeCn(vv.get(0).getTextbookTypeCn());
- setBookName("小计");
- setSubtotal(finalSubtotal);
- }});
- total = total.add(finalSubtotal);
- // 调用合并单元格工具类,此工具类是根据工程名称相同则合并后面数据
- int mergeRowIndex = rowIndex;
- int[] mergeColumeIndex = {0};
- ExcelMergeUtil excelFillCellMergeStrategy = new ExcelMergeUtil(mergeRowIndex, mergeColumeIndex);
- // 不需要头
- WriteTable writeContentTable = EasyExcel.writerTable(++tableIndex).needHead(Boolean.FALSE).registerWriteHandler(subtotalColumn).registerWriteHandler(excelFillCellMergeStrategy).build();
- excelWriter.write(vv, writeSheet, writeContentTable);
- rowIndex += (vv.size());
- }
- index++;
- }
- //添加合计
- BigDecimal finalTotal = total;
- List<TextbookClaimExportQueryVo> totalList = new ArrayList<>();
- totalList.add(new TextbookClaimExportQueryVo() {{
- setTextbookTypeCn("合计");
- setSubtotal(finalTotal);
- }});
- //-合并策略
- ExcelFillCellMergePrevColUtil totaColumn = new ExcelFillCellMergePrevColUtil();
- totaColumn.add(++rowIndex, 0, 5);
- //这是一个合计的table
- WriteTable writeTotalTable = EasyExcel.writerTable(++tableIndex).needHead(Boolean.FALSE).registerWriteHandler(totaColumn).build();
- excelWriter.write(totalList, writeSheet, writeTotalTable);
- }
- }
- }
- return bot;
- }
- // @Override
- // @Transactional
- // public Boolean excelImport(InputStream inputStream) {
- // EasyExcel.read(inputStream, TextbookImportDto.class, new PageReadListener<TextbookImportDto>(dataList -> {
- // if (dataList.isEmpty()) {
- // throw new MyException("导入数据为空");
- // }
- // saveData(dataList);
- // })).sheet().headRowNumber(3).doRead();
- //
- // return true;
- // }
- // @Override
- // public IPage<TextbookSubscriptionListVo> getSubscriptionPageByClass(TextbookSubscriptionListDto dto) {
- // if(StringUtils.isBlank(dto.getClassIds())){
- // throw new MyException("请选择需要征订教材的班级");
- // }
- // String[] classIdArr = dto.getClassIds().split(",");
- // List<String> classIdList = Arrays.asList(classIdArr);
- // if(ObjectUtils.isEmpty(classIdList)){
- // throw new MyException("请选择需要征订教材的班级");
- // }
- //
- // // 找到可以使用多个学期且已经征订的教材
- // // 找到可以使用多个学期且已经征订的教材
- // MPJLambdaWrapper<TextbookSubscriptionItem> subscribedTextbook = new MPJLambdaWrapper<>();
- // subscribedTextbook
- // .distinct()
- // .select(BaseClassCourse::getId)
- // .innerJoin(TextbookSubscriptionItemClass.class,
- // wrapper -> wrapper
- // .eq(TextbookSubscriptionItemClass::getTextbookSubscriptionItemId, TextbookSubscriptionItem::getId)
- // .in(TextbookSubscriptionItemClass::getBaseClassId, classIdList)
- // )
- //
- // .innerJoin(BaseClassAdminCourse.class, BaseClassAdminCourse::getClassId, TextbookSubscriptionItemClass::getBaseClassId)
- // .innerJoin(BaseClassCourse.class,
- // wrapper -> wrapper
- // .eq(BaseClassCourse::getClassId, BaseClassAdminCourse::getId)
- // .eq(BaseClassCourse::getTextbookId, TextbookSubscriptionItem::getTextbookId)
- // )
- //
- // .innerJoin(Textbook.class, Textbook::getId, TextbookSubscriptionItem::getTextbookId)
- // .gt(Textbook::getUseType, 1)
- // ;
- // List<BaseClassCourse> baseClassCourses = textbookSubscriptionItemMapper.selectJoinList(BaseClassCourse.class, subscribedTextbook);
- //
- // List<Long> baseClassCourseIds = baseClassCourses.stream()
- // .map(BaseClassCourse::getId)
- // .collect(Collectors.toList());
- //
- // MPJLambdaWrapper<BaseClassCourse> baseClassCourseMPJLambdaWrapper = new MPJLambdaWrapper<>();
- // baseClassCourseMPJLambdaWrapper
- // .disableSubLogicDel()
- // .distinct()
- // .selectAs(BaseClassCourse::getCourseId, TextbookSubscriptionListVo::getCourseSubjectId)
- // .selectAs(BaseClassCourse::getTextbookId, TextbookSubscriptionListVo::getTextbookId)
- // .selectAs(BaseCourseSubject::getName, TextbookSubscriptionListVo::getCourseName)
- // .select(Textbook.class, x -> VoToColumnUtil.fieldsToColumns(TextbookSubscriptionListVo.class).contains(x.getProperty()))
- // .innerJoin(Textbook.class, Textbook::getId, BaseClassCourse::getTextbookId)
- // .leftJoin(BaseCourseSubject.class, BaseCourseSubject::getId, BaseClassCourse::getCourseId)
- // .leftJoin(DictionaryDetail.class, DictionaryDetail::getCode, Textbook::getTextbookType,
- // wrapper -> wrapper
- // .selectAs(DictionaryDetail::getName, TextbookSubscriptionListVo::getTextbookTypeCn)
- // )
- // .eq(BaseClassCourse::getBaseSemesterId, dto.getBaseSemesterId())
- // .in(BaseClassCourse::getClassId, classIdList)
- // .notIn(!baseClassCourseIds.isEmpty(), BaseClassCourse::getId, baseClassCourseIds)
- // .eq(BaseClassCourse::getDeleteMark, DeleteMark.NODELETE.getCode())
- // .eq(Textbook::getDeleteMark, DeleteMark.NODELETE.getCode())
- // ;
- // IPage<TextbookSubscriptionListVo> textbookSubscriptionListVoIPage = baseClassCourseMapper.selectJoinPage(ConventPage.getPage(dto), TextbookSubscriptionListVo.class, baseClassCourseMPJLambdaWrapper);
- /// / IPage<TextbookSubscriptionListVo> page = this.baseMapper.getSubscriptionPageByClass(new Page<>(dto.getLimit(), dto.getSize()), dto);
- //
- // // 处理每本教材使用的人数
- // if(!classIdList.isEmpty()) {
- // for(TextbookSubscriptionListVo t : textbookSubscriptionListVoIPage.getRecords()){
- // MPJLambdaWrapper<BaseClassCourse> countNum = new MPJLambdaWrapper<>();
- // countNum
- // .innerJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getClassId, BaseClassCourse::getClassId)
- // .eq(BaseStudentSchoolRoll::getArchivesStatus, ArchivesStatusEnum.FB2901.getCode())
- // .eq(BaseClassCourse::getTextbookId, t.getTextbookId())
- // .eq(BaseClassCourse::getBaseSemesterId, dto.getBaseSemesterId())
- // .in(BaseClassCourse::getClassId, classIdList)
- // .notIn(!baseClassCourseIds.isEmpty(), BaseClassCourse::getId, baseClassCourseIds)
- // .eq(BaseClassCourse::getDeleteMark, DeleteMark.NODELETE.getCode())
- // ;
- // Long num = baseClassCourseMapper.selectCount(countNum);
- // t.setStudentSubscriptionNumber(num.intValue());
- //
- // t.setClassIds(dto.getClassIds());
- // }
- // }
- //
- // return textbookSubscriptionListVoIPage;
- // }
- @Override
- public List<TextbookSubscriptionListVo> getSubscriptionListByClass(TextbookSubscriptionListDto dto) {
- if (StringUtils.isBlank(dto.getClassIds())) {
- throw new MyException("请选择需要征订教材的班级");
- }
- String[] classIdArr = dto.getClassIds().split(",");
- List<String> classIdList = Arrays.asList(classIdArr);
- if (ObjectUtils.isEmpty(classIdList)) {
- throw new MyException("请选择需要征订教材的班级");
- }
- // 找到可以使用多个学期且已经征订的教材
- MPJLambdaWrapper<TextbookSubscriptionItem> subscribedTextbook = new MPJLambdaWrapper<>();
- subscribedTextbook
- .distinct()
- .select(BaseClassCourse::getId)
- .innerJoin(TextbookSubscription.class, TextbookSubscription::getId, TextbookSubscriptionItem::getTextbookSubscriptionId,
- wrapper -> wrapper
- .ne(TextbookSubscription::getStatus, 0)
- )
- .innerJoin(TextbookSubscriptionItemClass.class,
- wrapper -> wrapper
- .eq(TextbookSubscriptionItemClass::getTextbookSubscriptionItemId, TextbookSubscriptionItem::getId)
- .in(TextbookSubscriptionItemClass::getBaseClassId, classIdList)
- )
- .innerJoin(BaseClassAdminCourse.class, BaseClassAdminCourse::getClassId, TextbookSubscriptionItemClass::getBaseClassId)
- .innerJoin(BaseClassCourse.class,
- wrapper -> wrapper
- .eq(BaseClassCourse::getClassId, BaseClassAdminCourse::getId)
- .eq(BaseClassCourse::getTextbookId, TextbookSubscriptionItem::getTextbookId)
- )
- .innerJoin(Textbook.class, Textbook::getId, TextbookSubscriptionItem::getTextbookId)
- .ne(ObjectUtils.isNotEmpty(dto.getTextbookSubscriptionId()), TextbookSubscriptionItem::getTextbookSubscriptionId, dto.getTextbookSubscriptionId())
- .gt(Textbook::getUseType, 1)
- ;
- List<BaseClassCourse> baseClassCourses = textbookSubscriptionItemMapper.selectJoinList(BaseClassCourse.class, subscribedTextbook);
- List<Long> baseClassCourseIds = baseClassCourses.stream()
- .map(BaseClassCourse::getId)
- .collect(Collectors.toList());
- // 需要征订的教材
- MPJLambdaWrapper<BaseClassCourse> baseClassCourseMPJLambdaWrapper = new MPJLambdaWrapper<>();
- baseClassCourseMPJLambdaWrapper
- .disableSubLogicDel()
- .distinct()
- .selectAs(BaseClassCourse::getCourseId, TextbookSubscriptionListVo::getCourseSubjectId)
- .selectAs(BaseClassCourse::getTextbookId, TextbookSubscriptionListVo::getTextbookId)
- .selectAs(BaseCourseSubject::getName, TextbookSubscriptionListVo::getCourseName)
- .select(Textbook.class, x -> VoToColumnUtil.fieldsToColumns(TextbookSubscriptionListVo.class).contains(x.getProperty()))
- .innerJoin(BaseClassAdminCourse.class, BaseClassAdminCourse::getId, BaseClassCourse::getClassId)
- .innerJoin(Textbook.class, Textbook::getId, BaseClassCourse::getTextbookId)
- .leftJoin(BaseCourseSubject.class, BaseCourseSubject::getId, BaseClassCourse::getCourseId)
- .leftJoin(DictionaryDetail.class, DictionaryDetail::getCode, Textbook::getTextbookType,
- wrapper -> wrapper
- .selectAs(DictionaryDetail::getName, TextbookSubscriptionListVo::getTextbookTypeCn)
- )
- .eq(BaseClassAdminCourse::getBaseSemesterId, dto.getBaseSemesterId())
- .in(BaseClassAdminCourse::getClassId, classIdList)
- .notIn(!baseClassCourseIds.isEmpty(), BaseClassCourse::getId, baseClassCourseIds)
- .eq(BaseClassAdminCourse::getDeleteMark, DeleteMark.NODELETE.getCode())
- .eq(Textbook::getDeleteMark, DeleteMark.NODELETE.getCode())
- ;
- List<TextbookSubscriptionListVo> textbookSubscriptionListVoList = baseClassCourseMapper.selectJoinList(TextbookSubscriptionListVo.class, baseClassCourseMPJLambdaWrapper);
- List<String> textbookIds = textbookSubscriptionListVoList.stream()
- .map(TextbookSubscriptionListVo::getTextbookId)
- .distinct() // 去重操作
- .collect(Collectors.toList());
- // 处理每本教材使用的人数
- if (ObjectUtils.isNotEmpty(textbookIds)) {
- MPJLambdaWrapper<BaseClassCourse> countNum = new MPJLambdaWrapper<>();
- countNum
- .selectAs(BaseClassCourse::getTextbookId, TextbookSubscriptionListVo::getTextbookId)
- .selectAs(BaseClassAdminCourse::getClassId, TextbookSubscriptionListVo::getClassIds)
- .selectCount(BaseStudentSchoolRoll::getId, TextbookSubscriptionListVo::getStudentSubscriptionNumber)
- .innerJoin(BaseClassAdminCourse.class, BaseClassAdminCourse::getId, BaseClassCourse::getClassId)
- .innerJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getClassId, BaseClassAdminCourse::getClassId)
- .eq(BaseStudentSchoolRoll::getArchivesStatus, ArchivesStatusEnum.FB2901.getCode())
- .in(BaseClassCourse::getTextbookId, textbookIds)
- .eq(BaseClassAdminCourse::getBaseSemesterId, dto.getBaseSemesterId())
- .in(BaseClassAdminCourse::getClassId, classIdList)
- .notIn(!baseClassCourseIds.isEmpty(), BaseClassCourse::getId, baseClassCourseIds)
- .eq(BaseClassCourse::getDeleteMark, DeleteMark.NODELETE.getCode())
- .groupBy(BaseClassCourse::getTextbookId)
- .groupBy(BaseClassAdminCourse::getClassId)
- ;
- List<TextbookSubscriptionListVo> countStuNumList = baseClassCourseMapper.selectJoinList(TextbookSubscriptionListVo.class, countNum);
- Map<String, List<TextbookSubscriptionListVo>> countStuNumMap = countStuNumList.stream()
- .collect(Collectors.groupingBy(TextbookSubscriptionListVo::getTextbookId));
- if (ObjectUtils.isNotEmpty(countStuNumMap)) {
- StringBuilder classIds;
- int sum;
- for (TextbookSubscriptionListVo t : textbookSubscriptionListVoList) {
- List<TextbookSubscriptionListVo> textbookSubscriptionListVos = countStuNumMap.get(t.getTextbookId());
- if (ObjectUtils.isNotEmpty(textbookSubscriptionListVos)) {
- sum = 0;
- classIds = new StringBuilder();
- for (TextbookSubscriptionListVo textbookSubscriptionListVo : textbookSubscriptionListVos) {
- sum += ObjectUtils.isNotEmpty(textbookSubscriptionListVo.getStudentSubscriptionNumber()) ? textbookSubscriptionListVo.getStudentSubscriptionNumber() : 0;
- if (ObjectUtils.isNotEmpty(textbookSubscriptionListVo.getClassIds())) {
- classIds.append(textbookSubscriptionListVo.getClassIds());
- classIds.append(",");
- }
- }
- if (classIds.length() > 0) { // 确保 StringBuilder 不为空,以避免 StringIndexOutOfBoundsException
- classIds.deleteCharAt(classIds.length() - 1);
- }
- t.setStudentSubscriptionNumber(sum);
- t.setUseClassNum(textbookSubscriptionListVos.size());
- t.setClassIds(classIds.toString());
- }
- }
- }
- // for(TextbookSubscriptionListVo t : textbookSubscriptionListVoList){
- // MPJLambdaWrapper<BaseClassAdminCourse> countNum = new MPJLambdaWrapper<>();
- // countNum
- // .innerJoin(BaseClassCourse.class, BaseClassCourse::getClassId, BaseClassAdminCourse::getId)
- //
- // .innerJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getClassId, BaseClassAdminCourse::getClassId)
- //
- // .eq(BaseStudentSchoolRoll::getArchivesStatus, ArchivesStatusEnum.FB2901.getCode())
- // .eq(BaseClassCourse::getTextbookId, t.getTextbookId())
- // .eq(BaseClassAdminCourse::getBaseSemesterId, dto.getBaseSemesterId())
- // .in(BaseClassAdminCourse::getClassId, dto.getClassIdList())
- // .notIn(!baseClassCourseIds.isEmpty(), BaseClassCourse::getId, baseClassCourseIds)
- // .eq(BaseClassCourse::getDeleteMark, DeleteMark.NODELETE.getCode())
- // ;
- // Long num = baseClassCourseMapper.selectCount(countNum);
- // t.setStudentSubscriptionNumber(num.intValue());
- //
- // t.setClassIds(dto.getClassIds());
- }
- return textbookSubscriptionListVoList;
- }
- // private void saveData(List<TextbookImportDto> dataList) {
- // //查询所有需要的数据
- // //学科组
- // List<SubjectGroup> subjectGroupList = subjectGroupMapper.selectList(new LambdaQueryWrapper<>());
- // Map<String, Long> subjectGroupNameAndIdMap = subjectGroupList.stream().collect(Collectors.toMap(SubjectGroup::getGroupName, SubjectGroup::getId, (k1, k2) -> k1));
- //
- // //使用课程
- // List<BaseCourseSubject> baseCourseSubjectList = baseCourseSubjectMapper.selectList(new LambdaQueryWrapper<>());
- // Map<String, Long> baseCourseSubjectNameAndIdMap = baseCourseSubjectList.stream().collect(Collectors.toMap(BaseCourseSubject::getName, BaseCourseSubject::getId, (k1, k2) -> k1));
- //
- // //批量插入或更新数据
- // for (TextbookImportDto textbookImportDto : dataList) {
- // TextbookCoreAttribute textbookCoreAttribute = new TextbookCoreAttribute();
- // BeanUtils.copyProperties(textbookImportDto, textbookCoreAttribute);
- //
- // Textbook textbook = new Textbook();
- // BeanUtils.copyProperties(textbookImportDto, textbook);
- //
- // // 处理学科组映射
- // String groupName = textbookImportDto.getGroupName();
- // Long subjectGroupId = Optional.ofNullable(groupName)
- // .map(subjectGroupNameAndIdMap::get)
- // .orElse(null);
- // textbook.setSubjectGroupId(subjectGroupId);
- //
- // // 处理课程映射
- // String courseName = textbookImportDto.getCourseName();
- // Long courseSubjectId = Optional.ofNullable(courseName)
- // .map(baseCourseSubjectNameAndIdMap::get)
- // .orElse(null);
- // textbook.setCourseSubjectId(courseSubjectId);
- //
- // // 处理是否教材计划字段
- // String isTextbookPlanCn = textbookImportDto.getIsTextbookPlanCn();
- // String isTextbookPlan = Optional.ofNullable(isTextbookPlanCn)
- // .filter("是"::equals)
- // .map(s -> "yes")
- // .orElse("no");
- // textbook.setIsTextbookPlan(isTextbookPlan);
- //
- // String isSecd = textbookImportDto.getIsSecd();
- // Integer isSecdI = Optional.ofNullable(isSecd)
- // .filter("是"::equals)
- // .map(s -> 1)
- // .orElse(0);
- // textbook.setIsSecd(isSecdI);
- //
- // // 处理教材类型映射
- // String textbookTypeCn = textbookImportDto.getTextbookTypeCn();
- // String textbookTypeCode = Optional.ofNullable(textbookTypeCn)
- // .map(TextbookTypeEnum::getCode)
- // .orElse(null);
- // textbook.setTextbookType(textbookTypeCode);
- //
- // //处理使用类型
- // textbook.setUseType(UseSemesterTypeEnum.getCode(textbookImportDto.getUseTypeCn()));
- // Double discount = 1d;
- // if(textbook.getDiscount() != null){
- // discount = textbook.getDiscount();
- // }
- // //处理小计
- // textbook.setSubtotal(textbook.getPrice().multiply(BigDecimal.valueOf(discount / 10)));
- //
- // // 判断导入的教材是否已经存在,根据教材的 ISBN 码和使用的学期判断
- // LambdaQueryWrapper<Textbook> textbookLambdaQueryWrapper = new LambdaQueryWrapper<>();
- // textbookLambdaQueryWrapper
- // .eq(Textbook::getIssn, textbook.getIssn())
- // ;
- //
- // Textbook oldTextbook = this.getOne(textbookLambdaQueryWrapper);
- //
- // Date now = new Date();
- // Long loginId = StpUtil.getLoginIdAsLong();
- // // 已经存在,更新数据
- // if (oldTextbook != null) {
- // // 更新教材数据
- // textbookCoreAttribute.setId(oldTextbook.getTextbookCoreAttributeId());
- // textbookCoreAttribute.setModifyDate(now);
- // textbookCoreAttribute.setModifyUserId(loginId);
- // textbookCoreAttributeService.updateById(textbookCoreAttribute);
- //
- // textbook.setId(oldTextbook.getId());
- // textbook.setModifyDate(now);
- // textbook.setModifyUserId(loginId);
- // textbookTextbookMapper.updateById(textbook);
- // } else {
- // textbookCoreAttribute.setCreateDate(now);
- // textbookCoreAttribute.setCreateUserId(loginId);
- // textbookCoreAttributeService.save(textbookCoreAttribute);
- //
- // // 插入教材数据
- // textbook.setCreateDate(now);
- // textbook.setCreateUserId(loginId);
- // textbook.setTextbookCoreAttributeId(textbookCoreAttribute.getId());
- // textbookTextbookMapper.insert(textbook);
- // }
- // }
- // }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public String textbookImport(MultipartFile file) throws IOException, IllegalAccessException {
- List<TextbookImportDto> excelDataList = EasyExcel.read(file.getInputStream()).headRowNumber(3).head(TextbookImportDto.class).sheet().doReadSync();
- StringBuilder sb = new StringBuilder();
- List<String> codeList = new ArrayList<>();
- codeList.add("textbook_type");
- codeList.add("textbook_category");
- Map<String, String> dictionary = ImportExcelUtil.initDictionary(codeList, dictionaryitemMapper, dictionarydetailMapper);
- //查询所有需要的数据
- //学科组
- List<SubjectGroup> subjectGroupList = subjectGroupMapper.selectList(
- Wrappers
- .lambdaQuery(SubjectGroup.class)
- .eq(SubjectGroup::getDeleteMark, DeleteMark.NODELETE.getCode()));
- Map<String, Long> subjectGroupNameAndIdMap = subjectGroupList.stream().collect(Collectors.toMap(SubjectGroup::getGroupName, SubjectGroup::getId, (k1, k2) -> k1));
- //使用课程
- List<BaseCourseSubject> baseCourseSubjectList = baseCourseSubjectMapper.selectList(
- Wrappers
- .lambdaQuery(BaseCourseSubject.class)
- .eq(BaseCourseSubject::getDeleteMark, DeleteMark.NODELETE.getCode())
- );
- Map<String, Long> baseCourseSubjectNameAndIdMap = baseCourseSubjectList.stream().collect(Collectors.toMap(BaseCourseSubject::getName, BaseCourseSubject::getId, (k1, k2) -> k1));
- List<Textbook> insertTextbooks = new ArrayList<>();
- List<Textbook> updateTextbooks = new ArrayList<>();
- for (int i = 0; i < excelDataList.size(); i++) {
- TextbookImportDto dto = excelDataList.get(i);
- if (isRequiredFieldsFilled(dto,
- sb,
- i + 3)) {
- return sb.toString();
- }
- Textbook textbook = new Textbook();
- BeanUtils.copyProperties(dto, textbook);
- // 验证字段的合理性
- // 字典类型
- if (validateAndSetDictionaryField(dto::getTextbookTypeCn,
- "textbook_type",
- "教材分类(教材、辅材、作业本)",
- dictionary,
- textbook::setTextbookType,
- sb,
- i + 3)) {
- return sb.toString();
- }
- if (validateAndSetDictionaryField(dto::getTextbookCategory,
- "textbook_category",
- "教材类型(纸质教材、数字教材、纸质与数字资源结合教材)",
- dictionary,
- textbook::setTextbookCategory,
- sb,
- i + 3)) {
- return sb.toString();
- }
- // 关联表
- if (validateAndSetString2LongField(dto::getGroupName,
- "学科组(必须是系统中已有的学科组名称)",
- subjectGroupNameAndIdMap,
- textbook::setSubjectGroupId,
- sb,
- i + 3
- )) {
- return sb.toString();
- }
- if (validateAndSetString2LongField(dto::getCourseName,
- "对应课程(必须是系统中已有的课程名称)",
- baseCourseSubjectNameAndIdMap,
- textbook::setCourseSubjectId,
- sb,
- i + 3
- )) {
- return sb.toString();
- }
- // 处理是否字段
- if (validateAndSetBooleanField(dto::getIsTextbookPlanCn,
- "规划教材(是或否)",
- textbook::setIsTextbookPlan,
- sb,
- i + 3
- )) {
- return sb.toString();
- }
- if (validateAndSetBooleanField(dto::getIsSecd,
- "是否为校企合作教材(是或否)",
- textbook::setIsSecd,
- sb,
- i + 3
- )) {
- return sb.toString();
- }
- // 处理枚举字段
- Map<String, Integer> useTypeMap = new HashMap<>();
- for (UseSemesterTypeEnum useSemesterTypeEnum : UseSemesterTypeEnum.values()) {
- useTypeMap.put(useSemesterTypeEnum.getValue(), useSemesterTypeEnum.getCode());
- }
- if (validateAndSetEnumField(dto::getUseTypeCn,
- "使用时长(一学期~六学期)",
- useTypeMap,
- textbook::setUseType,
- sb,
- i + 3
- )) {
- return sb.toString();
- }
- // 判断导入的教材是否已经存在,根据教材的 ISSN 码和使用的学科组和课程判断
- LambdaQueryWrapper<Textbook> textbookLambdaQueryWrapper = new LambdaQueryWrapper<>();
- textbookLambdaQueryWrapper
- .eq(Textbook::getIssn, textbook.getIssn())
- .eq(Textbook::getDeleteMark, DeleteMark.NODELETE.getCode())
- ;
- Textbook verifyTextbook = this.getOne(textbookLambdaQueryWrapper);
- textbook.setIsbn(textbook.getIssn());
- BigDecimal discount = BigDecimal.valueOf(textbook.getDiscount()).divide(BigDecimal.valueOf(10));
- textbook.setDiscountPrice(textbook.getPrice().multiply(discount));
- if (ObjectUtils.isNotEmpty(verifyTextbook)) {
- textbook.setId(verifyTextbook.getId());
- updateTextbooks.add(textbook);
- } else {
- insertTextbooks.add(textbook);
- }
- }
- //批量新增
- if (!insertTextbooks.isEmpty()) {
- for (Textbook textbook : insertTextbooks) {
- this.save(textbook);
- }
- }
- //批量修改
- if (!updateTextbooks.isEmpty()) {
- for (Textbook textbook : updateTextbooks) {
- this.updateById(textbook);
- }
- }
- return sb.toString();
- }
- }
|