| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444 |
- 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::getCourseSubjectId, dto.getCourseSubjectId())
- .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();
- }
- }
|