TextbookServiceImpl.java 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444
  1. package com.xjrsoft.module.textbook.service.impl;
  2. import cn.hutool.core.util.StrUtil;
  3. import com.alibaba.excel.EasyExcel;
  4. import com.alibaba.excel.ExcelWriter;
  5. import com.alibaba.excel.support.ExcelTypeEnum;
  6. import com.alibaba.excel.write.metadata.WriteSheet;
  7. import com.alibaba.excel.write.metadata.WriteTable;
  8. import com.alibaba.excel.write.metadata.style.WriteCellStyle;
  9. import com.alibaba.excel.write.metadata.style.WriteFont;
  10. import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
  11. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  12. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  13. import com.baomidou.mybatisplus.core.metadata.IPage;
  14. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  15. import com.github.yulichang.base.MPJBaseServiceImpl;
  16. import com.github.yulichang.wrapper.MPJLambdaWrapper;
  17. import com.xjrsoft.common.enums.*;
  18. import com.xjrsoft.common.exception.MyException;
  19. import com.xjrsoft.common.page.ConventPage;
  20. import com.xjrsoft.common.utils.VoToColumnUtil;
  21. import com.xjrsoft.common.utils.excel.ExcelFillCellMergePrevColUtil;
  22. import com.xjrsoft.common.utils.excel.ExcelMergeUtil;
  23. import com.xjrsoft.module.base.entity.*;
  24. import com.xjrsoft.module.base.mapper.BaseClassCourseMapper;
  25. import com.xjrsoft.module.base.mapper.BaseCourseSubjectMapper;
  26. import com.xjrsoft.module.base.mapper.BaseSemesterMapper;
  27. import com.xjrsoft.module.base.service.IBaseClassService;
  28. import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
  29. import com.xjrsoft.module.system.entity.DictionaryDetail;
  30. import com.xjrsoft.module.system.mapper.DictionarydetailMapper;
  31. import com.xjrsoft.module.system.mapper.DictionaryitemMapper;
  32. import com.xjrsoft.module.teacher.entity.XjrUser;
  33. import com.xjrsoft.module.textbook.dto.*;
  34. import com.xjrsoft.module.textbook.entity.*;
  35. import com.xjrsoft.module.textbook.mapper.*;
  36. import com.xjrsoft.module.textbook.service.ITextbookService;
  37. import com.xjrsoft.module.textbook.service.IWfExerciseBookService;
  38. import com.xjrsoft.module.textbook.vo.*;
  39. import com.xjrsoft.module.veb.util.ImportExcelUtil;
  40. import lombok.AllArgsConstructor;
  41. import org.apache.commons.lang3.ObjectUtils;
  42. import org.apache.commons.lang3.StringUtils;
  43. import org.apache.poi.ss.usermodel.BorderStyle;
  44. import org.apache.poi.ss.usermodel.HorizontalAlignment;
  45. import org.apache.poi.ss.usermodel.VerticalAlignment;
  46. import org.springframework.beans.BeanUtils;
  47. import org.springframework.stereotype.Service;
  48. import org.springframework.transaction.annotation.Transactional;
  49. import org.springframework.web.multipart.MultipartFile;
  50. import java.io.ByteArrayOutputStream;
  51. import java.io.IOException;
  52. import java.math.BigDecimal;
  53. import java.math.RoundingMode;
  54. import java.util.*;
  55. import java.util.stream.Collectors;
  56. import static com.xjrsoft.module.veb.util.ImportExcelUtil.*;
  57. /**
  58. * @title: 教材管理
  59. * @Author szs
  60. * @Date: 2023-12-25
  61. * @Version 1.0
  62. */
  63. @Service
  64. @AllArgsConstructor
  65. public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Textbook> implements ITextbookService {
  66. private final TextbookMapper textbookTextbookMapper;
  67. private final TextbookClassRelationMapper textbookTextbookClassRelationMapper;
  68. private final TextbookSubscriptionRecordMapper textbookTextbookSubscriptionRecordMapper;
  69. private final IWfExerciseBookService wfExerciseBookService;
  70. private final IBaseClassService baseClassService;
  71. private final TextbookIssueRecordMapper textbookIssueRecordMapper;
  72. private final TextbookStudentClaimMapper textbookStudentClaimMapper;
  73. private final BaseSemesterMapper baseSemesterMapper;
  74. private final BaseClassCourseMapper baseClassCourseMapper;
  75. private final DictionaryitemMapper dictionaryitemMapper;
  76. private final DictionarydetailMapper dictionarydetailMapper;
  77. private final SubjectGroupMapper subjectGroupMapper;
  78. private final BaseCourseSubjectMapper baseCourseSubjectMapper;
  79. private final TextbookSubscriptionItemMapper textbookSubscriptionItemMapper;
  80. @Override
  81. @Transactional(rollbackFor = Exception.class)
  82. public Boolean addRubAndHand(Textbook textbook) {
  83. // 判断isbn的唯一性
  84. if(StringUtils.isBlank(textbook.getIssn())
  85. || ObjectUtils.isEmpty(textbook.getSubjectGroupId())
  86. || ObjectUtils.isEmpty(textbook.getCourseSubjectId()) ){
  87. throw new MyException("issn,学科组,课程为必填字段");
  88. }
  89. textbook.setIsbn(textbook.getIssn());
  90. if(ObjectUtils.isNotEmpty(textbook.getDiscount()) && ObjectUtils.isNotEmpty(textbook.getPrice())){
  91. BigDecimal discount = BigDecimal.valueOf(textbook.getDiscount()).divide( BigDecimal.valueOf(10));
  92. textbook.setDiscountPrice(textbook.getPrice().multiply(discount));
  93. }
  94. // 判断导入的教材是否已经存在,根据教材的 ISSN 码和使用的学科组和课程判断
  95. LambdaQueryWrapper<Textbook> textbookLambdaQueryWrapper = new LambdaQueryWrapper<>();
  96. textbookLambdaQueryWrapper
  97. .eq(Textbook::getIssn, textbook.getIssn())
  98. .eq(Textbook::getDeleteMark, DeleteMark.NODELETE.getCode())
  99. ;
  100. Textbook verifyTextbook = textbookTextbookMapper.selectOne(textbookLambdaQueryWrapper);
  101. int num;
  102. if(ObjectUtils.isNotEmpty(verifyTextbook)){
  103. textbook.setId(verifyTextbook.getId());
  104. num = textbookTextbookMapper.updateById(textbook);
  105. }else {
  106. num = textbookTextbookMapper.insert(textbook);
  107. }
  108. return num > 0;
  109. }
  110. @Override
  111. @Transactional(rollbackFor = Exception.class)
  112. public Boolean updateRubAndHand(Textbook textbook) {
  113. Textbook old = textbookTextbookMapper.selectById(textbook.getId());
  114. if(ObjectUtils.isEmpty(old)){
  115. throw new MyException("教材信息已经被修改,请刷新重试。");
  116. }
  117. // 折扣修改,定价未修改
  118. if(ObjectUtils.isNotEmpty(textbook.getDiscount()) && ObjectUtils.isEmpty(textbook.getPrice())){
  119. BigDecimal discount = BigDecimal.valueOf(textbook.getDiscount()).divide(BigDecimal.valueOf(10), 2, RoundingMode.DOWN);
  120. textbook.setDiscountPrice(old.getPrice().multiply(discount));
  121. }
  122. // 折扣未修改,定价修改
  123. if(ObjectUtils.isEmpty(textbook.getDiscount()) && ObjectUtils.isNotEmpty(textbook.getPrice())){
  124. BigDecimal discount = BigDecimal.valueOf(old.getDiscount()).divide(BigDecimal.valueOf(10), 2, RoundingMode.DOWN);
  125. textbook.setDiscountPrice(textbook.getPrice().multiply(discount));
  126. }
  127. // 折扣修改,定价修改
  128. if(ObjectUtils.isNotEmpty(textbook.getDiscount()) && ObjectUtils.isNotEmpty(textbook.getPrice())){
  129. BigDecimal discount = BigDecimal.valueOf(textbook.getDiscount()).divide(BigDecimal.valueOf(10), 2, RoundingMode.DOWN);
  130. textbook.setDiscountPrice(textbook.getPrice().multiply(discount));
  131. }
  132. int num = textbookTextbookMapper.updateById(textbook);
  133. return num > 0;
  134. }
  135. @Override
  136. @Transactional(rollbackFor = Exception.class)
  137. public Boolean delete(List<Long> ids) {
  138. // 删除教材前应判断教材是否被班级课程使用,一旦被使用不能删除
  139. MPJLambdaWrapper<Textbook> baseClassCourse = new MPJLambdaWrapper<>();
  140. baseClassCourse
  141. .select(Textbook::getId)
  142. .select(Textbook.class, x -> VoToColumnUtil.fieldsToColumns(Textbook.class).contains(x.getProperty()))
  143. .innerJoin(BaseClassCourse.class, BaseClassCourse::getTextbookId, Textbook::getId)
  144. .in(Textbook::getId, ids)
  145. ;
  146. List<Textbook> baseClassCourseTextbooks = this.selectJoinList(Textbook.class, baseClassCourse);
  147. if(!baseClassCourseTextbooks.isEmpty()){
  148. throw new MyException(baseClassCourseTextbooks.get(0).getBookName() + "教材在课程中被使用,请先从课程中移除!");
  149. }
  150. // 删除教材前应判断教材是否存在教材征订记录,如果存在征订记录,不应该删除
  151. MPJLambdaWrapper<Textbook> textbookSubscriptionItem = new MPJLambdaWrapper<>();
  152. textbookSubscriptionItem
  153. .select(Textbook::getId)
  154. .select(Textbook.class, x -> VoToColumnUtil.fieldsToColumns(Textbook.class).contains(x.getProperty()))
  155. .innerJoin(TextbookSubscriptionItem.class, TextbookSubscriptionItem::getTextbookId, Textbook::getId)
  156. .in(Textbook::getId, ids)
  157. ;
  158. List<Textbook> textbookSubscriptionItemTextbooks = this.selectJoinList(Textbook.class, textbookSubscriptionItem);
  159. if(!textbookSubscriptionItemTextbooks.isEmpty()){
  160. throw new MyException(textbookSubscriptionItemTextbooks.get(0).getBookName() + "教材在证订中被使用,请先从证订中移除!");
  161. }
  162. textbookTextbookMapper.deleteBatchIds(ids);
  163. return true;
  164. }
  165. @Override
  166. public IPage<TextbookPageVo> pageRubAndHand(TextbookPageDto dto) {
  167. MPJLambdaWrapper<Textbook> textbookMPJLambdaWrapper = new MPJLambdaWrapper<>();
  168. textbookMPJLambdaWrapper
  169. .select(Textbook::getId)
  170. .select(Textbook.class, x -> VoToColumnUtil.fieldsToColumns(TextbookPageVo.class).contains(x.getProperty()))
  171. .leftJoin(SubjectGroup.class, SubjectGroup::getId, Textbook::getSubjectGroupId,
  172. wrapper -> wrapper
  173. .selectAs(SubjectGroup::getGroupName, TextbookPageVo::getGroupName)
  174. .like(StringUtils.isNotBlank(dto.getGroupName()), SubjectGroup::getGroupName, dto.getGroupName())
  175. )
  176. .leftJoin(BaseCourseSubject.class, BaseCourseSubject::getId, Textbook::getCourseSubjectId,
  177. wrapper -> wrapper
  178. .selectAs(BaseCourseSubject::getName, TextbookPageVo::getCourseName)
  179. .like(StringUtils.isNotBlank(dto.getCourseName()), BaseCourseSubject::getName, dto.getCourseName())
  180. )
  181. .leftJoin(DictionaryDetail.class, DictionaryDetail::getCode, Textbook::getTextbookType,
  182. wrapper -> wrapper
  183. .selectAs(DictionaryDetail::getName, TextbookPageVo::getTextbookTypeCn)
  184. )
  185. .eq(ObjectUtils.isNotEmpty(dto.getUseType()), Textbook::getUseType, dto.getUseType())
  186. .like(StringUtils.isNotBlank(dto.getIssn()), Textbook::getIssn, dto.getIssn())
  187. .like(StringUtils.isNotBlank(dto.getIsbn()), Textbook::getIsbn, dto.getIsbn())
  188. .like(StringUtils.isNotBlank(dto.getBookName()), Textbook::getBookName, dto.getBookName())
  189. .like(StringUtils.isNotBlank(dto.getPublishingHouse()), Textbook::getPublishingHouse, dto.getPublishingHouse())
  190. .like(StringUtils.isNotBlank(dto.getEditorInChief()), Textbook::getEditorInChief, dto.getEditorInChief())
  191. .eq(StringUtils.isNotBlank(dto.getVersion()), Textbook::getVersion, dto.getVersion())
  192. .eq(ObjectUtils.isNotEmpty(dto.getCourseSubjectId()), Textbook::getCourseSubjectId, dto.getCourseSubjectId())
  193. .eq(ObjectUtils.isNotEmpty(dto.getSubjectGroupId()), Textbook::getCourseSubjectId, dto.getCourseSubjectId())
  194. .eq(ObjectUtils.isNotEmpty(dto.getIsTextbookPlan()), Textbook::getIsTextbookPlan, dto.getIsTextbookPlan())
  195. .eq(StringUtils.isNotBlank(dto.getTextbookType()), Textbook::getTextbookType, dto.getTextbookType())
  196. .eq(StringUtils.isNotBlank(dto.getSpecificationsModels()), Textbook::getSpecificationsModels, dto.getSpecificationsModels())
  197. .eq(ObjectUtils.isNotEmpty(dto.getIsSecd()), Textbook::getIsSecd, dto.getIsSecd())
  198. .eq(StringUtils.isNotBlank(dto.getCategory()), Textbook::getCategory, dto.getCategory())
  199. .eq(StringUtils.isNotBlank(dto.getPlanBatch()), Textbook::getPlanBatch, dto.getPlanBatch())
  200. .eq(ObjectUtils.isNotEmpty(dto.getWorkTotalCount()), Textbook::getWorkTotalCount, dto.getWorkTotalCount())
  201. .eq(StringUtils.isNotBlank(dto.getTextbookCategory()), Textbook::getTextbookCategory, dto.getTextbookCategory())
  202. .eq(ObjectUtils.isNotEmpty(dto.getPrice()), Textbook::getPrice, dto.getPrice())
  203. .eq(ObjectUtils.isNotEmpty(dto.getDiscount()), Textbook::getDiscount, dto.getDiscount())
  204. .orderByDesc(Textbook::getId)
  205. ;
  206. return textbookTextbookMapper.selectJoinPage(ConventPage.getPage(dto), TextbookPageVo.class, textbookMPJLambdaWrapper);
  207. }
  208. @Override
  209. public List<TextbookListVo> listRubAndHand(TextbookListDto dto) {
  210. MPJLambdaWrapper<Textbook> textbookMPJLambdaWrapper = new MPJLambdaWrapper<>();
  211. textbookMPJLambdaWrapper
  212. .select(Textbook::getId)
  213. .select(Textbook.class, x -> VoToColumnUtil.fieldsToColumns(TextbookListVo.class).contains(x.getProperty()))
  214. .leftJoin(SubjectGroup.class, SubjectGroup::getId, Textbook::getSubjectGroupId,
  215. wrapper -> wrapper
  216. .selectAs(SubjectGroup::getGroupName, TextbookListVo::getGroupName)
  217. .like(StringUtils.isNotBlank(dto.getGroupName()), SubjectGroup::getGroupName, dto.getGroupName())
  218. )
  219. .leftJoin(BaseCourseSubject.class, BaseCourseSubject::getId, Textbook::getCourseSubjectId,
  220. wrapper -> wrapper
  221. .selectAs(BaseCourseSubject::getName, TextbookListVo::getCourseName)
  222. .like(StringUtils.isNotBlank(dto.getCourseName()), BaseCourseSubject::getName, dto.getCourseName())
  223. )
  224. .leftJoin(DictionaryDetail.class, DictionaryDetail::getCode, Textbook::getTextbookType,
  225. wrapper -> wrapper
  226. .selectAs(DictionaryDetail::getName, TextbookListVo::getTextbookTypeCn)
  227. )
  228. .eq(ObjectUtils.isNotEmpty(dto.getUseType()), Textbook::getUseType, dto.getUseType())
  229. .like(StringUtils.isNotBlank(dto.getIssn()), Textbook::getIssn, dto.getIssn())
  230. .like(StringUtils.isNotBlank(dto.getIsbn()), Textbook::getIsbn, dto.getIsbn())
  231. .like(StringUtils.isNotBlank(dto.getBookName()), Textbook::getBookName, dto.getBookName())
  232. .like(StringUtils.isNotBlank(dto.getPublishingHouse()), Textbook::getPublishingHouse, dto.getPublishingHouse())
  233. .like(StringUtils.isNotBlank(dto.getEditorInChief()), Textbook::getEditorInChief, dto.getEditorInChief())
  234. .eq(StringUtils.isNotBlank(dto.getVersion()), Textbook::getVersion, dto.getVersion())
  235. .eq(ObjectUtils.isNotEmpty(dto.getIsTextbookPlan()), Textbook::getIsTextbookPlan, dto.getIsTextbookPlan())
  236. .eq(StringUtils.isNotBlank(dto.getTextbookType()), Textbook::getTextbookType, dto.getTextbookType())
  237. .eq(StringUtils.isNotBlank(dto.getSpecificationsModels()), Textbook::getSpecificationsModels, dto.getSpecificationsModels())
  238. .eq(ObjectUtils.isNotEmpty(dto.getIsSecd()), Textbook::getIsSecd, dto.getIsSecd())
  239. .eq(StringUtils.isNotBlank(dto.getCategory()), Textbook::getCategory, dto.getCategory())
  240. .eq(StringUtils.isNotBlank(dto.getPlanBatch()), Textbook::getPlanBatch, dto.getPlanBatch())
  241. .eq(ObjectUtils.isNotEmpty(dto.getWorkTotalCount()), Textbook::getWorkTotalCount, dto.getWorkTotalCount())
  242. .eq(StringUtils.isNotBlank(dto.getTextbookCategory()), Textbook::getTextbookCategory, dto.getTextbookCategory())
  243. .eq(ObjectUtils.isNotEmpty(dto.getPrice()), Textbook::getPrice, dto.getPrice())
  244. .eq(ObjectUtils.isNotEmpty(dto.getDiscount()), Textbook::getDiscount, dto.getDiscount())
  245. ;
  246. return textbookTextbookMapper.selectJoinList(TextbookListVo.class, textbookMPJLambdaWrapper);
  247. }
  248. /* @Override
  249. @Transactional
  250. public Boolean dataHandleAddTextbookNode(Long dataId) {
  251. WfTextbookSubscription wfTextbookSubscription = iWfTextbookSubscriptionService.selectById(dataId);
  252. if (ObjectUtil.isNotNull(wfTextbookSubscription) && ObjectUtil.isNotNull(wfTextbookSubscription.getWfTextbookSubscriptionItemList()) && wfTextbookSubscription.getWfTextbookSubscriptionItemList().size() > 0) {
  253. //遍历征订项
  254. for (WfTextbookSubscriptionItem wfTextbookSubscriptionItem : wfTextbookSubscription.getWfTextbookSubscriptionItemList()) {
  255. Long semesterId = wfTextbookSubscription.getBaseSemesterId();
  256. String issn = wfTextbookSubscriptionItem.getIssn();
  257. LambdaQueryWrapper<Textbook> queryWrapper = new LambdaQueryWrapper<>();
  258. queryWrapper
  259. .eq(Textbook::getIssn, issn)
  260. .eq(Textbook::getBaseSemesterId, semesterId);
  261. List<Textbook> textbookList = this.list(queryWrapper);
  262. //征订的教材没有在教材管理
  263. if (ObjectUtil.isNull(textbookList) || textbookList.size() == 0) {
  264. Textbook textbook = new Textbook() {{
  265. setIssn((ObjectUtil.isNull(wfTextbookSubscriptionItem.getIssn()) || StringUtils.isBlank(wfTextbookSubscriptionItem.getIssn())) ? "/" : wfTextbookSubscriptionItem.getIssn());
  266. setIsbn((ObjectUtil.isNull(wfTextbookSubscriptionItem.getIsbn()) || StringUtils.isBlank(wfTextbookSubscriptionItem.getIsbn())) ? "/" : wfTextbookSubscriptionItem.getIsbn());
  267. setBookName((ObjectUtil.isNull(wfTextbookSubscriptionItem.getBookName()) || StringUtils.isBlank(wfTextbookSubscriptionItem.getBookName())) ? "/" : wfTextbookSubscriptionItem.getBookName());
  268. setPublishingHouse((ObjectUtil.isNull(wfTextbookSubscriptionItem.getPublishingHouse()) || StringUtils.isBlank(wfTextbookSubscriptionItem.getPublishingHouse())) ? "/" : wfTextbookSubscriptionItem.getPublishingHouse());
  269. setEditorInChief((ObjectUtil.isNull(wfTextbookSubscriptionItem.getEditorInChief()) || StringUtils.isBlank(wfTextbookSubscriptionItem.getEditorInChief())) ? "/" : wfTextbookSubscriptionItem.getEditorInChief());
  270. setSubjectGroupId((ObjectUtil.isNull(wfTextbookSubscription.getSubjectGroupId())) ? 0 : wfTextbookSubscription.getSubjectGroupId());
  271. setBaseSemesterId(wfTextbookSubscription.getBaseSemesterId());
  272. setCourseSubjectId((ObjectUtil.isNull(wfTextbookSubscriptionItem.getCourseSubjectId())) ? 0 : wfTextbookSubscriptionItem.getCourseSubjectId());
  273. setVersion((ObjectUtil.isNull(wfTextbookSubscriptionItem.getVersion()) || StringUtils.isBlank(wfTextbookSubscriptionItem.getVersion())) ? "/" : wfTextbookSubscriptionItem.getVersion());
  274. setIsTextbookPlan((ObjectUtil.isNull(wfTextbookSubscriptionItem.getIsTextbookPlan()) || StringUtils.isBlank(wfTextbookSubscriptionItem.getIsTextbookPlan())) ? "/" : wfTextbookSubscriptionItem.getIsTextbookPlan());
  275. if (ObjectUtil.isNotNull(wfTextbookSubscriptionItem.getSubscriptionType()) && wfTextbookSubscriptionItem.getSubscriptionType().equals(SubscriptionTypeEnum.STextbook.getCode())) {
  276. setTextbookType(TextbookTypeEnum.TTextbook.getCode());
  277. }
  278. if (ObjectUtil.isNotNull(wfTextbookSubscriptionItem.getSubscriptionType()) && wfTextbookSubscriptionItem.getSubscriptionType().equals(SubscriptionTypeEnum.SMaterials.getCode())) {
  279. setTextbookType(TextbookTypeEnum.TMaterials.getCode());
  280. }
  281. setSpecificationsModels("/");
  282. setAppraisalPrice((ObjectUtil.isNull(wfTextbookSubscriptionItem.getAppraisalPrice())) ? new BigDecimal(0) : wfTextbookSubscriptionItem.getAppraisalPrice());
  283. setPrice(new BigDecimal(0));
  284. setDiscount(10D);
  285. setSubtotal(new BigDecimal(0));
  286. setStock(0);
  287. }};
  288. //班级不为空
  289. List<Long> classIdList = new ArrayList<>();
  290. if (ObjectUtil.isNotNull(wfTextbookSubscriptionItem.getClassIds()) && !wfTextbookSubscriptionItem.getClassIds().equals("")) {
  291. //将班级ids转换为List
  292. String classIds = wfTextbookSubscriptionItem.getClassIds();
  293. String[] classIdStrs = classIds.split(",");
  294. for (String classIdStr : classIdStrs) {
  295. classIdList.add(Long.parseLong(classIdStr));
  296. }
  297. //查询年级,如果添加的班级只存在一个年级,添加年级字段值
  298. LambdaQueryWrapper<BaseClass> queryWrapper1 = new LambdaQueryWrapper<>();
  299. queryWrapper1
  300. .select(BaseClass::getGradeId)
  301. .in(BaseClass::getId, classIdList)
  302. .groupBy(BaseClass::getGradeId);
  303. List<BaseClass> baseClassList = baseClassService.list(queryWrapper1);
  304. if (ObjectUtil.isNotNull(baseClassList) && baseClassList.size() == 1) {
  305. textbook.setGradeId(baseClassList.get(0).getGradeId());
  306. }
  307. }
  308. //插入教材数据
  309. textbook.setCreateDate(new Date());
  310. textbookTextbookMapper.insert(textbook);
  311. //插入班级和教材关系
  312. for (Long classId : classIdList) {
  313. textbookTextbookClassRelationMapper.insert(new TextbookClassRelation() {{
  314. setCreateDate(new Date());
  315. setTextbookId(textbook.getId());
  316. setClassId(classId);
  317. }});
  318. }
  319. //添加教材征订记录
  320. textbookTextbookSubscriptionRecordMapper.insert(new TextbookSubscriptionRecord() {{
  321. setCreateDate(new Date());
  322. setTextbookId(textbook.getId());
  323. setWfTextbookSubscriptionId(wfTextbookSubscription.getId());
  324. setWfTextbookSubscriptionItemId(wfTextbookSubscriptionItem.getId());//该字段存入征订项的id,征订项中有所属征订记录
  325. }});
  326. } else {
  327. //征订的教材在教材管理,进行班级的和记录的管理
  328. Textbook textbook = textbookList.get(0);
  329. //班级不为空
  330. if (ObjectUtil.isNotNull(wfTextbookSubscriptionItem.getClassIds()) && !wfTextbookSubscriptionItem.getClassIds().equals("")) {
  331. //将班级ids转换为List
  332. String classIds = wfTextbookSubscriptionItem.getClassIds();
  333. String[] classIdStrs = classIds.split(",");
  334. for (String classIdStr : classIdStrs) {
  335. textbookTextbookClassRelationMapper.insert(new TextbookClassRelation() {{
  336. setCreateDate(new Date());
  337. setTextbookId(textbook.getId());
  338. setClassId(Long.parseLong(classIdStr));
  339. }});
  340. }
  341. }
  342. //添加教材征订记录
  343. textbookTextbookSubscriptionRecordMapper.insert(new TextbookSubscriptionRecord() {{
  344. setCreateDate(new Date());
  345. setTextbookId(textbook.getId());
  346. setWfTextbookSubscriptionId(wfTextbookSubscription.getId());
  347. setWfTextbookSubscriptionItemId(wfTextbookSubscriptionItem.getId());//该字段存入正定项的id,征订项中有所属征订记录
  348. }});
  349. }
  350. }
  351. }
  352. return true;
  353. }*/
  354. /**
  355. * 添加作业本规则
  356. *
  357. * @param dataId
  358. * @return
  359. */
  360. @Override
  361. @Transactional
  362. public Boolean dataHandleAddExerciseBookNode(Long dataId) {
  363. WfExerciseBook wfExerciseBook = wfExerciseBookService.selectById(dataId);
  364. if (ObjectUtils.isNotEmpty(wfExerciseBook) && ObjectUtils.isNotEmpty(wfExerciseBook.getWfExerciseBookItemList()) && wfExerciseBook.getWfExerciseBookItemList().size() > 0) {
  365. for (WfExerciseBookItem wfExerciseBookItem : wfExerciseBook.getWfExerciseBookItemList()) {
  366. Long semesterId = wfExerciseBook.getBaseSemesterId();
  367. String bookName = wfExerciseBookItem.getSubscriptionType();//作业本的选择类型对应教材管理的书名
  368. LambdaQueryWrapper<Textbook> queryWrapper = new LambdaQueryWrapper<>();
  369. queryWrapper
  370. .eq(Textbook::getBookName, bookName)
  371. ;
  372. List<Textbook> textbookList = this.list(queryWrapper);
  373. //征订的作业本没有在教材管理
  374. if (ObjectUtils.isEmpty(textbookList) || textbookList.size() == 0) {
  375. Textbook textbook = new Textbook() {{
  376. setIssn("/");
  377. setIsbn("/");
  378. if (ObjectUtils.isNotEmpty(wfExerciseBookItem.getSubscriptionType()) && wfExerciseBookItem.getSubscriptionType().equals(ExerciseBookeTypeEnum.ExerciseBook1.getCode())) {
  379. setBookName(ExerciseBookeTypeEnum.ExerciseBook1.getValue());
  380. }
  381. if (ObjectUtils.isNotEmpty(wfExerciseBookItem.getSubscriptionType()) && wfExerciseBookItem.getSubscriptionType().equals(ExerciseBookeTypeEnum.ExerciseBook2.getCode())) {
  382. setBookName(ExerciseBookeTypeEnum.ExerciseBook2.getValue());
  383. }
  384. setPublishingHouse("/");
  385. setEditorInChief("/");
  386. setVersion("/");
  387. setTextbookType(TextbookTypeEnum.TExerciseBook.getCode());
  388. setSpecificationsModels((ObjectUtils.isEmpty(wfExerciseBookItem.getSpecificationsModels()) || StringUtils.isBlank(wfExerciseBookItem.getSpecificationsModels())) ? "/" : wfExerciseBookItem.getSpecificationsModels());
  389. //年级id
  390. if (ObjectUtils.isNotEmpty(wfExerciseBook.getClassId()) && wfExerciseBook.getClassId() > 0) {
  391. LambdaQueryWrapper<BaseClass> queryWrapper1 = new LambdaQueryWrapper<>();
  392. queryWrapper1
  393. .eq(BaseClass::getId, wfExerciseBook.getClassId());
  394. BaseClass baseClass = baseClassService.getOne(queryWrapper1);
  395. }
  396. setPrice(new BigDecimal(0));
  397. setDiscount(10D);
  398. }};
  399. //插入教材数据
  400. textbook.setCreateDate(new Date());
  401. textbookTextbookMapper.insert(textbook);
  402. //插入班级和教材关系
  403. if (ObjectUtils.isNotEmpty(wfExerciseBook.getClassId()) && wfExerciseBook.getClassId() > 0) {
  404. textbookTextbookClassRelationMapper.insert(new TextbookClassRelation() {{
  405. setCreateDate(new Date());
  406. setTextbookId(textbook.getId());
  407. setClassId(wfExerciseBook.getClassId());
  408. }});
  409. }
  410. //添加教材征订记录
  411. textbookTextbookSubscriptionRecordMapper.insert(new TextbookSubscriptionRecord() {{
  412. setCreateDate(new Date());
  413. setTextbookId(textbook.getId());
  414. setWfTextbookSubscriptionId(wfExerciseBook.getId());
  415. }});
  416. } else {
  417. //征订的教材在教材管理,进行班级的和记录的管理
  418. Textbook textbook = textbookList.get(0);
  419. //班级不为空
  420. if (ObjectUtils.isNotEmpty(wfExerciseBook.getClassId()) && wfExerciseBook.getClassId() > 0) {
  421. textbookTextbookClassRelationMapper.insert(new TextbookClassRelation() {{
  422. setCreateDate(new Date());
  423. setTextbookId(textbook.getId());
  424. setClassId(wfExerciseBook.getClassId());
  425. }});
  426. }
  427. //添加教材征订记录
  428. textbookTextbookSubscriptionRecordMapper.insert(new TextbookSubscriptionRecord() {{
  429. setCreateDate(new Date());
  430. setTextbookId(textbook.getId());
  431. setWfTextbookSubscriptionId(wfExerciseBook.getId());
  432. }});
  433. }
  434. }
  435. }
  436. return true;
  437. }
  438. @Override
  439. public List<TextbookSubscriptionRecordVo> subscriptionList(Long id) {
  440. Textbook textbook = this.getById(id);
  441. List<TextbookSubscriptionRecordVo> recordVos = new ArrayList<>();
  442. //是作业本
  443. if (textbook.getTextbookType().equals(TextbookTypeEnum.TExerciseBook.getCode())) {
  444. recordVos = textbookTextbookMapper.exerciseBookSubscriptionList(id);
  445. for (TextbookSubscriptionRecordVo recordVo : recordVos) {
  446. recordVo.setIssn("/");
  447. recordVo.setPublishingHouse("/");
  448. recordVo.setEditorInChief("/");
  449. recordVo.setIsTextbookPlanCn("/");
  450. recordVo.setCourseName("/");
  451. recordVo.setGradeName("/");
  452. recordVo.setTeacherSubscriptionNumber(0);
  453. recordVo.setTeacherReferenceNumber(0);
  454. }
  455. }
  456. //是教材或者教辅
  457. if (textbook.getTextbookType().equals(TextbookTypeEnum.TTextbook.getCode()) || textbook.getTextbookType().equals(TextbookTypeEnum.TMaterials.getCode())) {
  458. recordVos = textbookTextbookMapper.subscriptionList(id);
  459. for (TextbookSubscriptionRecordVo recordVo : recordVos) {
  460. if (ObjectUtils.isEmpty(recordVo) || StrUtil.isEmpty(recordVo.getClassIds())) {
  461. // recordVos.remove(recordVo);
  462. // if (recordVos.isEmpty()) {
  463. // break;
  464. // }
  465. continue;
  466. }
  467. String[] split = recordVo.getClassIds().split(",");
  468. List<String> ids = new ArrayList<>();
  469. for (String classId : split) {
  470. ids.add(classId.trim());
  471. }
  472. List<TextbookSubscriptionClassVo> classInfo = textbookTextbookMapper.getClassInfo(ids);
  473. String useClass = "";
  474. for (int i = 0; i < classInfo.size(); i++) {
  475. if (i >= 1) {
  476. useClass += ",";
  477. }
  478. TextbookSubscriptionClassVo classVo = classInfo.get(i);
  479. useClass += classVo.getName();
  480. }
  481. recordVo.setUseClass(useClass);
  482. }
  483. }
  484. return recordVos;
  485. }
  486. @Override
  487. public TextbookVo getInfoByissn(String issn) {
  488. TextbookVo infoByissn = textbookTextbookMapper.getInfoByissn(issn);
  489. if (infoByissn == null) {
  490. return null;
  491. }
  492. List<TextbookClassRelation> classRelationList = textbookTextbookClassRelationMapper.selectList(
  493. new QueryWrapper<TextbookClassRelation>().lambda().eq(TextbookClassRelation::getTextbookId, infoByissn.getId())
  494. );
  495. return infoByissn;
  496. }
  497. @Override
  498. public List<TextbookWarehouseRecordListVo> warehouseList(Long id) {
  499. List<TextbookWarehouseRecordListVo> result = textbookTextbookMapper.warehouseList(id);
  500. if (!result.isEmpty()) {
  501. return result;
  502. }
  503. return new ArrayList<>();
  504. }
  505. @Override
  506. public List<TextbookClassRelation> getClassRelation(Long id) {
  507. List<TextbookClassRelation> classRelation = textbookTextbookMapper.getClassRelation(id);
  508. if (!classRelation.isEmpty()) {
  509. return classRelation;
  510. }
  511. return new ArrayList<>();
  512. }
  513. @Override
  514. public List<TextbookIssueRecordListVo> issueList(Long id) {
  515. List<TextbookIssueRecordListVo> result = textbookTextbookMapper.issueList(id);
  516. if (!result.isEmpty()) {
  517. return result;
  518. }
  519. return new ArrayList<>();
  520. }
  521. @Override
  522. public List<WfTextbookClaimListVo> claimList(Long id) {
  523. List<WfTextbookClaimListVo> result = new ArrayList<>();
  524. //教材领取分为两种
  525. //教师领取
  526. MPJLambdaWrapper<TextbookIssueRecord> queryIssueRecord = new MPJLambdaWrapper<>();
  527. queryIssueRecord
  528. .eq(TextbookIssueRecord::getTextbookId, id)
  529. .eq(TextbookIssueRecord::getIssueMode, "im_teacher");
  530. List<TextbookIssueRecord> textbookIssueRecordList = textbookIssueRecordMapper.selectJoinList(TextbookIssueRecord.class, queryIssueRecord);
  531. for (TextbookIssueRecord t : textbookIssueRecordList) {
  532. MPJLambdaWrapper<TextbookIssueRecord> queryTeaClaimVo = new MPJLambdaWrapper<>();
  533. queryTeaClaimVo
  534. .selectAs(BaseSemester::getName, WfTextbookClaimListVo::getSemesterName)
  535. .selectAs(XjrUser::getName, WfTextbookClaimListVo::getName)
  536. .selectAs(XjrUser::getUserName, WfTextbookClaimListVo::getUserName)
  537. .selectAs(TextbookIssueRecord::getCreateDate, WfTextbookClaimListVo::getClaimDate)
  538. .leftJoin(XjrUser.class, XjrUser::getId, TextbookIssueRecord::getReceiveUserId)
  539. .leftJoin(WfTextbookClaim.class, WfTextbookClaim::getId, TextbookIssueRecord::getDataId)
  540. .leftJoin(BaseSemester.class, BaseSemester::getId, WfTextbookClaim::getBaseSemesterId)
  541. .eq(TextbookIssueRecord::getId, t.getId());
  542. WfTextbookClaimListVo wfTextbookClaimListVo = textbookIssueRecordMapper.selectJoinOne(WfTextbookClaimListVo.class, queryTeaClaimVo);
  543. for (int j = 0; j < t.getIssueNumber(); j++) {
  544. wfTextbookClaimListVo.setClaimIdentity("教师");
  545. wfTextbookClaimListVo.setClassName("/");
  546. result.add(wfTextbookClaimListVo);
  547. }
  548. }
  549. //学生领取
  550. MPJLambdaWrapper<TextbookStudentClaim> queryStuClaimVo = new MPJLambdaWrapper<>();
  551. queryStuClaimVo
  552. .select("'学生' as claimIdentity")
  553. .selectAs(BaseClass::getName, WfTextbookClaimListVo::getClassName)
  554. .selectAs(BaseSemester::getName, WfTextbookClaimListVo::getSemesterName)
  555. .selectAs(XjrUser::getName, WfTextbookClaimListVo::getName)
  556. .selectAs(XjrUser::getUserName, WfTextbookClaimListVo::getUserName)
  557. .selectAs(TextbookStudentClaim::getCreateDate, WfTextbookClaimListVo::getClaimDate)
  558. .leftJoin(XjrUser.class, XjrUser::getId, TextbookStudentClaim::getStudentUserId)
  559. .leftJoin(BaseSemester.class, BaseSemester::getId, TextbookStudentClaim::getBaseSemesterId)
  560. .leftJoin(BaseClass.class, BaseClass::getId, TextbookStudentClaim::getClassId)
  561. .eq(TextbookStudentClaim::getTextbookId, id)
  562. .eq(TextbookStudentClaim::getIsClaim, 1);
  563. List<WfTextbookClaimListVo> wfTextbookClaimListVoList = textbookStudentClaimMapper.selectJoinList(WfTextbookClaimListVo.class, queryStuClaimVo);
  564. result.addAll(wfTextbookClaimListVoList);
  565. return result;
  566. }
  567. @Override
  568. public List<TextbookStandingExportQueryVo> listTextbookStandingExportQuery(TextbookStandingExportQuerytDto dto) {
  569. return textbookTextbookMapper.listTextbookStandingExportQuery(dto);
  570. }
  571. @Override
  572. public ByteArrayOutputStream listTextbookSubscriptionExportQuery(TextbookSubscriptionExportQueryDto dto) {
  573. List<TextbookSubscriptionExportQueryVo> result = textbookTextbookMapper.listTextbookSubscriptionExportQuery(dto);
  574. //将班级转换为中文
  575. for (TextbookSubscriptionExportQueryVo to : result) {
  576. if (to != null && to.getClassIds() != null && !("").equals(to.getClassIds())) {
  577. List<Long> classIdList = new ArrayList<>();
  578. String[] classIdStrs = to.getClassIds().split(",");
  579. for (String classIdStr : classIdStrs) {
  580. classIdList.add(Long.parseLong(classIdStr.trim()));
  581. }
  582. LambdaQueryWrapper<BaseClass> baseClassLambdaQueryWrapper = new LambdaQueryWrapper<>();
  583. baseClassLambdaQueryWrapper
  584. .in(BaseClass::getId, classIdList);
  585. List<BaseClass> baseClassList = baseClassService.list(baseClassLambdaQueryWrapper);
  586. if (baseClassList.size() > 0) {
  587. StringBuilder sb = new StringBuilder();
  588. for (int i = 0; i < baseClassList.size(); i++) {
  589. sb.append(baseClassList.get(i).getName());
  590. if (i != baseClassList.size() - 1) {
  591. sb.append(",");
  592. }
  593. }
  594. to.setUseClass(sb.toString());
  595. }
  596. }
  597. }
  598. ByteArrayOutputStream bot = new ByteArrayOutputStream();
  599. // 设置动态头
  600. String baseSemesterCn = "";
  601. if(dto.getBaseSemesterId() != null){
  602. LambdaQueryWrapper<BaseSemester> baseSemesterLambdaQueryWrapper = new LambdaQueryWrapper<>();
  603. baseSemesterLambdaQueryWrapper
  604. .eq(BaseSemester::getId, dto.getBaseSemesterId());
  605. BaseSemester baseSemester = baseSemesterMapper.selectOne(baseSemesterLambdaQueryWrapper);
  606. if(baseSemester != null){
  607. baseSemesterCn = baseSemester.getName();
  608. }
  609. }
  610. String headTitle = "重庆市铜梁职业教育中心" + baseSemesterCn + "教材征订表";
  611. List<List<String>> headList = new ArrayList<>();
  612. // List<String> head0 = new ArrayList<>();
  613. // head0.add("个人信息");
  614. // head0.add("用户名");
  615. // List<String> head1 = new ArrayList<>();
  616. // head1.add("个人信息");
  617. // head1.add("年龄");
  618. // List<String> head2 = new ArrayList<>();
  619. // head2.add("个人信息");
  620. // head2.add("地址");
  621. headList.add(new ArrayList<String>(){{
  622. add(headTitle);
  623. add("国际标准刊号");
  624. }});
  625. headList.add(new ArrayList<String>(){{
  626. add(headTitle);
  627. add("书名");
  628. }});
  629. headList.add(new ArrayList<String>(){{
  630. add(headTitle);
  631. add("出版社");
  632. }});
  633. headList.add(new ArrayList<String>(){{
  634. add(headTitle);
  635. add("主编");
  636. }});
  637. headList.add(new ArrayList<String>(){{
  638. add(headTitle);
  639. add("估价(元)");
  640. }});
  641. headList.add(new ArrayList<String>(){{
  642. add(headTitle);
  643. add("是否为规划教材");
  644. }});
  645. headList.add(new ArrayList<String>(){{
  646. add(headTitle);
  647. add("对应课程");
  648. }});
  649. headList.add(new ArrayList<String>(){{
  650. add(headTitle);
  651. add("使用年级");
  652. }});
  653. headList.add(new ArrayList<String>(){{
  654. add(headTitle);
  655. add("使用班级");
  656. }});
  657. headList.add(new ArrayList<String>(){{
  658. add(headTitle);
  659. add("学生用书征订数量");
  660. }});
  661. headList.add(new ArrayList<String>(){{
  662. add(headTitle);
  663. add("教师教材用书征订数量");
  664. }});
  665. headList.add(new ArrayList<String>(){{
  666. add(headTitle);
  667. add("教师教参用书征订数量");
  668. }});
  669. headList.add(new ArrayList<String>(){{
  670. add(headTitle);
  671. add("学科组名称");
  672. }});
  673. headList.add(new ArrayList<String>(){{
  674. add(headTitle);
  675. add("有无配套教学资源");
  676. }});
  677. headList.add(new ArrayList<String>(){{
  678. add(headTitle);
  679. add("备注");
  680. }});
  681. EasyExcel.write(bot, TextbookSubscriptionExportQueryVo.class).automaticMergeHead(true).excelType(ExcelTypeEnum.XLSX).head(headList).sheet().doWrite(result);
  682. return bot;
  683. }
  684. @Override
  685. public ByteArrayOutputStream listTextbookClaimExportQuery(TextbookClaimExportQueryDto dto) {
  686. List<TextbookClaimExportQueryVo> customerList = textbookTextbookMapper.listTextbookClaimExportQuery(dto);
  687. ByteArrayOutputStream bot = new ByteArrayOutputStream();
  688. //内容样式
  689. WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
  690. //设计内容居中
  691. contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);// 水平居中
  692. contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);// 垂直居中
  693. contentWriteCellStyle.setWrapped(true); //设置自动换行;
  694. // 设置字体
  695. WriteFont contentWriteFont = new WriteFont();
  696. contentWriteFont.setFontHeightInPoints((short) 12);//设置字体大小
  697. contentWriteFont.setFontName("宋体"); //设置字体名字
  698. contentWriteCellStyle.setWriteFont(contentWriteFont);//在样式用应用设置的字体;
  699. //设置样式;
  700. contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);//设置底边框;
  701. contentWriteCellStyle.setBottomBorderColor((short) 0);//设置底边框颜色;
  702. contentWriteCellStyle.setBorderLeft(BorderStyle.THIN); //设置左边框;
  703. contentWriteCellStyle.setLeftBorderColor((short) 0);//设置左边框颜色;
  704. contentWriteCellStyle.setBorderRight(BorderStyle.THIN);//设置右边框;
  705. contentWriteCellStyle.setRightBorderColor((short) 0);//设置右边框颜色;
  706. contentWriteCellStyle.setBorderTop(BorderStyle.THIN);//设置顶边框;
  707. contentWriteCellStyle.setTopBorderColor((short) 0); ///设置顶边框颜色;
  708. //设置头部样式
  709. WriteCellStyle headWriteCellStyle = new WriteCellStyle();
  710. // 背景颜色
  711. // headWriteCellStyle.setFillForegroundColor(IndexedColors.LIGHT_TURQUOISE1.getIndex());
  712. // headWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
  713. // 字体
  714. WriteFont headWriteFont = new WriteFont();
  715. headWriteFont.setFontName("宋体");//设置字体名字
  716. headWriteFont.setFontHeightInPoints((short) 14);//设置字体大小
  717. headWriteFont.setBold(true);//字体加粗
  718. headWriteCellStyle.setWriteFont(headWriteFont); //在样式用应用设置的字体;
  719. // 样式
  720. headWriteCellStyle.setBorderBottom(BorderStyle.THIN);//设置底边框;
  721. headWriteCellStyle.setBottomBorderColor((short) 0);//设置底边框颜色;
  722. headWriteCellStyle.setBorderLeft(BorderStyle.THIN); //设置左边框;
  723. headWriteCellStyle.setLeftBorderColor((short) 0);//设置左边框颜色;
  724. headWriteCellStyle.setBorderRight(BorderStyle.THIN);//设置右边框;
  725. headWriteCellStyle.setRightBorderColor((short) 0);//设置右边框颜色;
  726. headWriteCellStyle.setBorderTop(BorderStyle.THIN);//设置顶边框;
  727. headWriteCellStyle.setTopBorderColor((short) 0); //设置顶边框颜色;
  728. headWriteCellStyle.setWrapped(true); //设置自动换行;
  729. //设置头部标题居中
  730. headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);//设置水平对齐的样式为居中对齐;
  731. headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐的样式为居中对齐;
  732. headWriteCellStyle.setShrinkToFit(true);//设置文本收缩至合适
  733. // 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现
  734. HorizontalCellStyleStrategy horizontalCellStyleStrategy =
  735. new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
  736. try (ExcelWriter excelWriter = EasyExcel.write(bot, TextbookClaimExportQueryVo.class).registerWriteHandler(horizontalCellStyleStrategy).build()) {
  737. //已经写入的行
  738. int rowIndex = 0;
  739. //已经写入的表
  740. int tableIndex = 0;
  741. // 把sheet设置为不需要头 不然会输出sheet的头 这样看起来第一个table 就有2个头了
  742. WriteSheet writeSheet = EasyExcel.writerSheet("模板").needHead(Boolean.FALSE).build();
  743. //sheet的表头
  744. List<List<String>> sheetHeadList = new ArrayList<List<String>>();
  745. sheetHeadList.add(new ArrayList<String>() {{
  746. add("铜梁执教中心班级教材教辅发放情况表");
  747. }});
  748. //sheet的表头合并策略
  749. ExcelFillCellMergePrevColUtil sheetHeadColumn = new ExcelFillCellMergePrevColUtil();
  750. sheetHeadColumn.add(rowIndex, 0, 12);
  751. //这是一个sheet表头的table
  752. WriteTable writeSheetHeadTable = EasyExcel.writerTable(tableIndex).needHead(Boolean.TRUE).head(sheetHeadList).registerWriteHandler(sheetHeadColumn).build();
  753. excelWriter.write(new ArrayList<>(), writeSheet, writeSheetHeadTable);
  754. //对返回的集合进行处理
  755. //现针对学期进行分组
  756. Map<Long, List<TextbookClaimExportQueryVo>> groupedBySemester = customerList.stream()
  757. .collect(Collectors.groupingBy(TextbookClaimExportQueryVo::getBaseSemesterId));
  758. Iterator<Map.Entry<Long, List<TextbookClaimExportQueryVo>>> groupedBySemesterIterator = groupedBySemester.entrySet().iterator();
  759. while (groupedBySemesterIterator.hasNext()) {
  760. Map.Entry<Long, List<TextbookClaimExportQueryVo>> groupedBySemesterEntry = groupedBySemesterIterator.next();
  761. Long key = groupedBySemesterEntry.getKey();
  762. List<TextbookClaimExportQueryVo> value = groupedBySemesterEntry.getValue();
  763. Map<Long, List<TextbookClaimExportQueryVo>> groupedBySemesterByClass = value.stream()
  764. .collect(Collectors.groupingBy(TextbookClaimExportQueryVo::getClassId));
  765. Iterator<Map.Entry<Long, List<TextbookClaimExportQueryVo>>> groupedBySemesterByClassIdIterator = groupedBySemesterByClass.entrySet().iterator();
  766. while (groupedBySemesterByClassIdIterator.hasNext()) {
  767. Map.Entry<Long, List<TextbookClaimExportQueryVo>> groupedBySemesterByClassIdEntry = groupedBySemesterByClassIdIterator.next();
  768. Long k = groupedBySemesterByClassIdEntry.getKey();
  769. List<TextbookClaimExportQueryVo> v = groupedBySemesterByClassIdEntry.getValue();
  770. //这是一个table的表头
  771. List<List<String>> tableHeadList = new ArrayList<List<String>>();
  772. tableHeadList.add(new ArrayList<String>() {{
  773. add("日期:" + v.get(0).getBaseSemesterIdCn() + " 班级:" + v.get(0).getClassIdCn() + " 班主任:" + v.get(0).getHeadTeacherName() + " 教室:" + v.get(0).getClassRoomName() + " ");
  774. }});
  775. //table的表头合并策略
  776. ExcelFillCellMergePrevColUtil tableHeadColumn = new ExcelFillCellMergePrevColUtil();
  777. tableHeadColumn.add(++rowIndex, 0, 9);
  778. //这是一个table表头的table
  779. WriteTable writeTableHeadTable = EasyExcel.writerTable(++tableIndex).needHead(Boolean.TRUE).head(tableHeadList).registerWriteHandler(tableHeadColumn).build();
  780. excelWriter.write(new ArrayList<>(), writeSheet, writeTableHeadTable);
  781. Map<String, List<TextbookClaimExportQueryVo>> groupedByTextbookType = v.stream()
  782. .collect(Collectors.groupingBy(TextbookClaimExportQueryVo::getTextbookTypeCn));
  783. Iterator<Map.Entry<String, List<TextbookClaimExportQueryVo>>> groupedByTextbookTypeIterator = groupedByTextbookType.entrySet().iterator();
  784. int index = 1;
  785. BigDecimal total = new BigDecimal("0");
  786. while (groupedByTextbookTypeIterator.hasNext()) {
  787. Map.Entry<String, List<TextbookClaimExportQueryVo>> groupedByTextbookTypeEntry = groupedByTextbookTypeIterator.next();
  788. String kk = groupedByTextbookTypeEntry.getKey();
  789. List<TextbookClaimExportQueryVo> vv = groupedByTextbookTypeEntry.getValue();
  790. if (index == 1) {
  791. //添加小计
  792. ExcelFillCellMergePrevColUtil subtotalColumn = new ExcelFillCellMergePrevColUtil();
  793. subtotalColumn.add(rowIndex + vv.size() + 2, 1, 4);
  794. BigDecimal subtotal = new BigDecimal("0");
  795. for (TextbookClaimExportQueryVo tv : vv) {
  796. subtotal = subtotal.add(tv.getSubtotal() == null ? new BigDecimal("0") : tv.getSubtotal());
  797. }
  798. BigDecimal finalSubtotal = subtotal;
  799. vv.add(new TextbookClaimExportQueryVo() {{
  800. setTextbookTypeCn(vv.get(0).getTextbookTypeCn());
  801. setBookName("小计");
  802. setSubtotal(finalSubtotal);
  803. }});
  804. total = total.add(finalSubtotal);
  805. // 调用合并单元格工具类,此工具类是根据工程名称相同则合并后面数据
  806. int mergeRowIndex = rowIndex + 1;
  807. int[] mergeColumeIndex = {0};
  808. ExcelMergeUtil excelFillCellMergeStrategy = new ExcelMergeUtil(mergeRowIndex, mergeColumeIndex);
  809. // 第一次必须指定需要头,table 会继承sheet的配置,sheet配置了不需要,table 默认也是不需要
  810. WriteTable writeContentTable = EasyExcel.writerTable(++tableIndex).needHead(Boolean.TRUE).registerWriteHandler(subtotalColumn).registerWriteHandler(excelFillCellMergeStrategy).build();
  811. // 第一次写入会创建头
  812. excelWriter.write(vv, writeSheet, writeContentTable);
  813. rowIndex += (1 + vv.size());
  814. } else {
  815. //添加小计
  816. ExcelFillCellMergePrevColUtil subtotalColumn = new ExcelFillCellMergePrevColUtil();
  817. subtotalColumn.add(rowIndex + vv.size() + 1, 1, 4);
  818. BigDecimal subtotal = new BigDecimal("0");
  819. for (TextbookClaimExportQueryVo tv : vv) {
  820. subtotal = subtotal.add(tv.getSubtotal());
  821. }
  822. BigDecimal finalSubtotal = subtotal;
  823. vv.add(new TextbookClaimExportQueryVo() {{
  824. setTextbookTypeCn(vv.get(0).getTextbookTypeCn());
  825. setBookName("小计");
  826. setSubtotal(finalSubtotal);
  827. }});
  828. total = total.add(finalSubtotal);
  829. // 调用合并单元格工具类,此工具类是根据工程名称相同则合并后面数据
  830. int mergeRowIndex = rowIndex;
  831. int[] mergeColumeIndex = {0};
  832. ExcelMergeUtil excelFillCellMergeStrategy = new ExcelMergeUtil(mergeRowIndex, mergeColumeIndex);
  833. // 不需要头
  834. WriteTable writeContentTable = EasyExcel.writerTable(++tableIndex).needHead(Boolean.FALSE).registerWriteHandler(subtotalColumn).registerWriteHandler(excelFillCellMergeStrategy).build();
  835. excelWriter.write(vv, writeSheet, writeContentTable);
  836. rowIndex += (vv.size());
  837. }
  838. index++;
  839. }
  840. //添加合计
  841. BigDecimal finalTotal = total;
  842. List<TextbookClaimExportQueryVo> totalList = new ArrayList<>();
  843. totalList.add(new TextbookClaimExportQueryVo() {{
  844. setTextbookTypeCn("合计");
  845. setSubtotal(finalTotal);
  846. }});
  847. //-合并策略
  848. ExcelFillCellMergePrevColUtil totaColumn = new ExcelFillCellMergePrevColUtil();
  849. totaColumn.add(++rowIndex, 0, 5);
  850. //这是一个合计的table
  851. WriteTable writeTotalTable = EasyExcel.writerTable(++tableIndex).needHead(Boolean.FALSE).registerWriteHandler(totaColumn).build();
  852. excelWriter.write(totalList, writeSheet, writeTotalTable);
  853. }
  854. }
  855. }
  856. return bot;
  857. }
  858. // @Override
  859. // @Transactional
  860. // public Boolean excelImport(InputStream inputStream) {
  861. // EasyExcel.read(inputStream, TextbookImportDto.class, new PageReadListener<TextbookImportDto>(dataList -> {
  862. // if (dataList.isEmpty()) {
  863. // throw new MyException("导入数据为空");
  864. // }
  865. // saveData(dataList);
  866. // })).sheet().headRowNumber(3).doRead();
  867. //
  868. // return true;
  869. // }
  870. // @Override
  871. // public IPage<TextbookSubscriptionListVo> getSubscriptionPageByClass(TextbookSubscriptionListDto dto) {
  872. // if(StringUtils.isBlank(dto.getClassIds())){
  873. // throw new MyException("请选择需要征订教材的班级");
  874. // }
  875. // String[] classIdArr = dto.getClassIds().split(",");
  876. // List<String> classIdList = Arrays.asList(classIdArr);
  877. // if(ObjectUtils.isEmpty(classIdList)){
  878. // throw new MyException("请选择需要征订教材的班级");
  879. // }
  880. //
  881. // // 找到可以使用多个学期且已经征订的教材
  882. // // 找到可以使用多个学期且已经征订的教材
  883. // MPJLambdaWrapper<TextbookSubscriptionItem> subscribedTextbook = new MPJLambdaWrapper<>();
  884. // subscribedTextbook
  885. // .distinct()
  886. // .select(BaseClassCourse::getId)
  887. // .innerJoin(TextbookSubscriptionItemClass.class,
  888. // wrapper -> wrapper
  889. // .eq(TextbookSubscriptionItemClass::getTextbookSubscriptionItemId, TextbookSubscriptionItem::getId)
  890. // .in(TextbookSubscriptionItemClass::getBaseClassId, classIdList)
  891. // )
  892. //
  893. // .innerJoin(BaseClassAdminCourse.class, BaseClassAdminCourse::getClassId, TextbookSubscriptionItemClass::getBaseClassId)
  894. // .innerJoin(BaseClassCourse.class,
  895. // wrapper -> wrapper
  896. // .eq(BaseClassCourse::getClassId, BaseClassAdminCourse::getId)
  897. // .eq(BaseClassCourse::getTextbookId, TextbookSubscriptionItem::getTextbookId)
  898. // )
  899. //
  900. // .innerJoin(Textbook.class, Textbook::getId, TextbookSubscriptionItem::getTextbookId)
  901. // .gt(Textbook::getUseType, 1)
  902. // ;
  903. // List<BaseClassCourse> baseClassCourses = textbookSubscriptionItemMapper.selectJoinList(BaseClassCourse.class, subscribedTextbook);
  904. //
  905. // List<Long> baseClassCourseIds = baseClassCourses.stream()
  906. // .map(BaseClassCourse::getId)
  907. // .collect(Collectors.toList());
  908. //
  909. // MPJLambdaWrapper<BaseClassCourse> baseClassCourseMPJLambdaWrapper = new MPJLambdaWrapper<>();
  910. // baseClassCourseMPJLambdaWrapper
  911. // .disableSubLogicDel()
  912. // .distinct()
  913. // .selectAs(BaseClassCourse::getCourseId, TextbookSubscriptionListVo::getCourseSubjectId)
  914. // .selectAs(BaseClassCourse::getTextbookId, TextbookSubscriptionListVo::getTextbookId)
  915. // .selectAs(BaseCourseSubject::getName, TextbookSubscriptionListVo::getCourseName)
  916. // .select(Textbook.class, x -> VoToColumnUtil.fieldsToColumns(TextbookSubscriptionListVo.class).contains(x.getProperty()))
  917. // .innerJoin(Textbook.class, Textbook::getId, BaseClassCourse::getTextbookId)
  918. // .leftJoin(BaseCourseSubject.class, BaseCourseSubject::getId, BaseClassCourse::getCourseId)
  919. // .leftJoin(DictionaryDetail.class, DictionaryDetail::getCode, Textbook::getTextbookType,
  920. // wrapper -> wrapper
  921. // .selectAs(DictionaryDetail::getName, TextbookSubscriptionListVo::getTextbookTypeCn)
  922. // )
  923. // .eq(BaseClassCourse::getBaseSemesterId, dto.getBaseSemesterId())
  924. // .in(BaseClassCourse::getClassId, classIdList)
  925. // .notIn(!baseClassCourseIds.isEmpty(), BaseClassCourse::getId, baseClassCourseIds)
  926. // .eq(BaseClassCourse::getDeleteMark, DeleteMark.NODELETE.getCode())
  927. // .eq(Textbook::getDeleteMark, DeleteMark.NODELETE.getCode())
  928. // ;
  929. // IPage<TextbookSubscriptionListVo> textbookSubscriptionListVoIPage = baseClassCourseMapper.selectJoinPage(ConventPage.getPage(dto), TextbookSubscriptionListVo.class, baseClassCourseMPJLambdaWrapper);
  930. //// IPage<TextbookSubscriptionListVo> page = this.baseMapper.getSubscriptionPageByClass(new Page<>(dto.getLimit(), dto.getSize()), dto);
  931. //
  932. // // 处理每本教材使用的人数
  933. // if(!classIdList.isEmpty()) {
  934. // for(TextbookSubscriptionListVo t : textbookSubscriptionListVoIPage.getRecords()){
  935. // MPJLambdaWrapper<BaseClassCourse> countNum = new MPJLambdaWrapper<>();
  936. // countNum
  937. // .innerJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getClassId, BaseClassCourse::getClassId)
  938. // .eq(BaseStudentSchoolRoll::getArchivesStatus, ArchivesStatusEnum.FB2901.getCode())
  939. // .eq(BaseClassCourse::getTextbookId, t.getTextbookId())
  940. // .eq(BaseClassCourse::getBaseSemesterId, dto.getBaseSemesterId())
  941. // .in(BaseClassCourse::getClassId, classIdList)
  942. // .notIn(!baseClassCourseIds.isEmpty(), BaseClassCourse::getId, baseClassCourseIds)
  943. // .eq(BaseClassCourse::getDeleteMark, DeleteMark.NODELETE.getCode())
  944. // ;
  945. // Long num = baseClassCourseMapper.selectCount(countNum);
  946. // t.setStudentSubscriptionNumber(num.intValue());
  947. //
  948. // t.setClassIds(dto.getClassIds());
  949. // }
  950. // }
  951. //
  952. // return textbookSubscriptionListVoIPage;
  953. // }
  954. @Override
  955. public List<TextbookSubscriptionListVo> getSubscriptionListByClass(TextbookSubscriptionListDto dto) {
  956. if(StringUtils.isBlank(dto.getClassIds())){
  957. throw new MyException("请选择需要征订教材的班级");
  958. }
  959. String[] classIdArr = dto.getClassIds().split(",");
  960. List<String> classIdList = Arrays.asList(classIdArr);
  961. if(ObjectUtils.isEmpty(classIdList)){
  962. throw new MyException("请选择需要征订教材的班级");
  963. }
  964. // 找到可以使用多个学期且已经征订的教材
  965. MPJLambdaWrapper<TextbookSubscriptionItem> subscribedTextbook = new MPJLambdaWrapper<>();
  966. subscribedTextbook
  967. .distinct()
  968. .select(BaseClassCourse::getId)
  969. .innerJoin(TextbookSubscription.class, TextbookSubscription::getId, TextbookSubscriptionItem::getTextbookSubscriptionId,
  970. wrapper -> wrapper
  971. .ne(TextbookSubscription::getStatus, 0)
  972. )
  973. .innerJoin(TextbookSubscriptionItemClass.class,
  974. wrapper -> wrapper
  975. .eq(TextbookSubscriptionItemClass::getTextbookSubscriptionItemId, TextbookSubscriptionItem::getId)
  976. .in(TextbookSubscriptionItemClass::getBaseClassId, classIdList)
  977. )
  978. .innerJoin(BaseClassAdminCourse.class, BaseClassAdminCourse::getClassId, TextbookSubscriptionItemClass::getBaseClassId)
  979. .innerJoin(BaseClassCourse.class,
  980. wrapper -> wrapper
  981. .eq(BaseClassCourse::getClassId, BaseClassAdminCourse::getId)
  982. .eq(BaseClassCourse::getTextbookId, TextbookSubscriptionItem::getTextbookId)
  983. )
  984. .innerJoin(Textbook.class, Textbook::getId, TextbookSubscriptionItem::getTextbookId)
  985. .ne(ObjectUtils.isNotEmpty(dto.getTextbookSubscriptionId()), TextbookSubscriptionItem::getTextbookSubscriptionId, dto.getTextbookSubscriptionId())
  986. .gt(Textbook::getUseType, 1)
  987. ;
  988. List<BaseClassCourse> baseClassCourses = textbookSubscriptionItemMapper.selectJoinList(BaseClassCourse.class, subscribedTextbook);
  989. List<Long> baseClassCourseIds = baseClassCourses.stream()
  990. .map(BaseClassCourse::getId)
  991. .collect(Collectors.toList());
  992. // 需要征订的教材
  993. MPJLambdaWrapper<BaseClassCourse> baseClassCourseMPJLambdaWrapper = new MPJLambdaWrapper<>();
  994. baseClassCourseMPJLambdaWrapper
  995. .disableSubLogicDel()
  996. .distinct()
  997. .selectAs(BaseClassCourse::getCourseId, TextbookSubscriptionListVo::getCourseSubjectId)
  998. .selectAs(BaseClassCourse::getTextbookId, TextbookSubscriptionListVo::getTextbookId)
  999. .selectAs(BaseCourseSubject::getName, TextbookSubscriptionListVo::getCourseName)
  1000. .select(Textbook.class, x -> VoToColumnUtil.fieldsToColumns(TextbookSubscriptionListVo.class).contains(x.getProperty()))
  1001. .innerJoin(BaseClassAdminCourse.class, BaseClassAdminCourse::getId, BaseClassCourse::getClassId)
  1002. .innerJoin(Textbook.class, Textbook::getId, BaseClassCourse::getTextbookId)
  1003. .leftJoin(BaseCourseSubject.class, BaseCourseSubject::getId, BaseClassCourse::getCourseId)
  1004. .leftJoin(DictionaryDetail.class, DictionaryDetail::getCode, Textbook::getTextbookType,
  1005. wrapper -> wrapper
  1006. .selectAs(DictionaryDetail::getName, TextbookSubscriptionListVo::getTextbookTypeCn)
  1007. )
  1008. .eq(BaseClassAdminCourse::getBaseSemesterId, dto.getBaseSemesterId())
  1009. .in(BaseClassAdminCourse::getClassId, classIdList)
  1010. .notIn(!baseClassCourseIds.isEmpty(), BaseClassCourse::getId, baseClassCourseIds)
  1011. .eq(BaseClassAdminCourse::getDeleteMark, DeleteMark.NODELETE.getCode())
  1012. .eq(Textbook::getDeleteMark, DeleteMark.NODELETE.getCode())
  1013. ;
  1014. List<TextbookSubscriptionListVo> textbookSubscriptionListVoList = baseClassCourseMapper.selectJoinList(TextbookSubscriptionListVo.class, baseClassCourseMPJLambdaWrapper);
  1015. List<String> textbookIds = textbookSubscriptionListVoList.stream()
  1016. .map(TextbookSubscriptionListVo::getTextbookId)
  1017. .distinct() // 去重操作
  1018. .collect(Collectors.toList());
  1019. // 处理每本教材使用的人数
  1020. if(ObjectUtils.isNotEmpty(textbookIds)){
  1021. MPJLambdaWrapper<BaseClassCourse> countNum = new MPJLambdaWrapper<>();
  1022. countNum
  1023. .selectAs(BaseClassCourse::getTextbookId, TextbookSubscriptionListVo::getTextbookId)
  1024. .selectAs(BaseClassAdminCourse::getClassId, TextbookSubscriptionListVo::getClassIds)
  1025. .selectCount(BaseStudentSchoolRoll::getId, TextbookSubscriptionListVo::getStudentSubscriptionNumber)
  1026. .innerJoin(BaseClassAdminCourse.class, BaseClassAdminCourse::getId, BaseClassCourse::getClassId)
  1027. .innerJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getClassId, BaseClassAdminCourse::getClassId)
  1028. .eq(BaseStudentSchoolRoll::getArchivesStatus, ArchivesStatusEnum.FB2901.getCode())
  1029. .in(BaseClassCourse::getTextbookId, textbookIds)
  1030. .eq(BaseClassAdminCourse::getBaseSemesterId, dto.getBaseSemesterId())
  1031. .in(BaseClassAdminCourse::getClassId, classIdList)
  1032. .notIn(!baseClassCourseIds.isEmpty(), BaseClassCourse::getId, baseClassCourseIds)
  1033. .eq(BaseClassCourse::getDeleteMark, DeleteMark.NODELETE.getCode())
  1034. .groupBy(BaseClassCourse::getTextbookId)
  1035. .groupBy(BaseClassAdminCourse::getClassId)
  1036. ;
  1037. List<TextbookSubscriptionListVo> countStuNumList = baseClassCourseMapper.selectJoinList(TextbookSubscriptionListVo.class, countNum);
  1038. Map<String, List<TextbookSubscriptionListVo>> countStuNumMap = countStuNumList.stream()
  1039. .collect(Collectors.groupingBy(TextbookSubscriptionListVo::getTextbookId));
  1040. if(ObjectUtils.isNotEmpty(countStuNumMap)){
  1041. StringBuilder classIds;
  1042. int sum;
  1043. for(TextbookSubscriptionListVo t : textbookSubscriptionListVoList){
  1044. List<TextbookSubscriptionListVo> textbookSubscriptionListVos = countStuNumMap.get(t.getTextbookId());
  1045. if(ObjectUtils.isNotEmpty(textbookSubscriptionListVos)){
  1046. sum = 0;
  1047. classIds = new StringBuilder();
  1048. for (TextbookSubscriptionListVo textbookSubscriptionListVo : textbookSubscriptionListVos){
  1049. sum += ObjectUtils.isNotEmpty(textbookSubscriptionListVo.getStudentSubscriptionNumber()) ? textbookSubscriptionListVo.getStudentSubscriptionNumber() : 0;
  1050. if(ObjectUtils.isNotEmpty(textbookSubscriptionListVo.getClassIds())){
  1051. classIds.append(textbookSubscriptionListVo.getClassIds());
  1052. classIds.append(",");
  1053. }
  1054. }
  1055. if (classIds.length() > 0) { // 确保 StringBuilder 不为空,以避免 StringIndexOutOfBoundsException
  1056. classIds.deleteCharAt(classIds.length() - 1);
  1057. }
  1058. t.setStudentSubscriptionNumber(sum);
  1059. t.setUseClassNum(textbookSubscriptionListVos.size());
  1060. t.setClassIds(classIds.toString());
  1061. }
  1062. }
  1063. }
  1064. // for(TextbookSubscriptionListVo t : textbookSubscriptionListVoList){
  1065. // MPJLambdaWrapper<BaseClassAdminCourse> countNum = new MPJLambdaWrapper<>();
  1066. // countNum
  1067. // .innerJoin(BaseClassCourse.class, BaseClassCourse::getClassId, BaseClassAdminCourse::getId)
  1068. //
  1069. // .innerJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getClassId, BaseClassAdminCourse::getClassId)
  1070. //
  1071. // .eq(BaseStudentSchoolRoll::getArchivesStatus, ArchivesStatusEnum.FB2901.getCode())
  1072. // .eq(BaseClassCourse::getTextbookId, t.getTextbookId())
  1073. // .eq(BaseClassAdminCourse::getBaseSemesterId, dto.getBaseSemesterId())
  1074. // .in(BaseClassAdminCourse::getClassId, dto.getClassIdList())
  1075. // .notIn(!baseClassCourseIds.isEmpty(), BaseClassCourse::getId, baseClassCourseIds)
  1076. // .eq(BaseClassCourse::getDeleteMark, DeleteMark.NODELETE.getCode())
  1077. // ;
  1078. // Long num = baseClassCourseMapper.selectCount(countNum);
  1079. // t.setStudentSubscriptionNumber(num.intValue());
  1080. //
  1081. // t.setClassIds(dto.getClassIds());
  1082. //
  1083. }
  1084. return textbookSubscriptionListVoList;
  1085. }
  1086. // private void saveData(List<TextbookImportDto> dataList) {
  1087. // //查询所有需要的数据
  1088. // //学科组
  1089. // List<SubjectGroup> subjectGroupList = subjectGroupMapper.selectList(new LambdaQueryWrapper<>());
  1090. // Map<String, Long> subjectGroupNameAndIdMap = subjectGroupList.stream().collect(Collectors.toMap(SubjectGroup::getGroupName, SubjectGroup::getId, (k1, k2) -> k1));
  1091. //
  1092. // //使用课程
  1093. // List<BaseCourseSubject> baseCourseSubjectList = baseCourseSubjectMapper.selectList(new LambdaQueryWrapper<>());
  1094. // Map<String, Long> baseCourseSubjectNameAndIdMap = baseCourseSubjectList.stream().collect(Collectors.toMap(BaseCourseSubject::getName, BaseCourseSubject::getId, (k1, k2) -> k1));
  1095. //
  1096. // //批量插入或更新数据
  1097. // for (TextbookImportDto textbookImportDto : dataList) {
  1098. // TextbookCoreAttribute textbookCoreAttribute = new TextbookCoreAttribute();
  1099. // BeanUtils.copyProperties(textbookImportDto, textbookCoreAttribute);
  1100. //
  1101. // Textbook textbook = new Textbook();
  1102. // BeanUtils.copyProperties(textbookImportDto, textbook);
  1103. //
  1104. // // 处理学科组映射
  1105. // String groupName = textbookImportDto.getGroupName();
  1106. // Long subjectGroupId = Optional.ofNullable(groupName)
  1107. // .map(subjectGroupNameAndIdMap::get)
  1108. // .orElse(null);
  1109. // textbook.setSubjectGroupId(subjectGroupId);
  1110. //
  1111. // // 处理课程映射
  1112. // String courseName = textbookImportDto.getCourseName();
  1113. // Long courseSubjectId = Optional.ofNullable(courseName)
  1114. // .map(baseCourseSubjectNameAndIdMap::get)
  1115. // .orElse(null);
  1116. // textbook.setCourseSubjectId(courseSubjectId);
  1117. //
  1118. // // 处理是否教材计划字段
  1119. // String isTextbookPlanCn = textbookImportDto.getIsTextbookPlanCn();
  1120. // String isTextbookPlan = Optional.ofNullable(isTextbookPlanCn)
  1121. // .filter("是"::equals)
  1122. // .map(s -> "yes")
  1123. // .orElse("no");
  1124. // textbook.setIsTextbookPlan(isTextbookPlan);
  1125. //
  1126. // String isSecd = textbookImportDto.getIsSecd();
  1127. // Integer isSecdI = Optional.ofNullable(isSecd)
  1128. // .filter("是"::equals)
  1129. // .map(s -> 1)
  1130. // .orElse(0);
  1131. // textbook.setIsSecd(isSecdI);
  1132. //
  1133. // // 处理教材类型映射
  1134. // String textbookTypeCn = textbookImportDto.getTextbookTypeCn();
  1135. // String textbookTypeCode = Optional.ofNullable(textbookTypeCn)
  1136. // .map(TextbookTypeEnum::getCode)
  1137. // .orElse(null);
  1138. // textbook.setTextbookType(textbookTypeCode);
  1139. //
  1140. // //处理使用类型
  1141. // textbook.setUseType(UseSemesterTypeEnum.getCode(textbookImportDto.getUseTypeCn()));
  1142. // Double discount = 1d;
  1143. // if(textbook.getDiscount() != null){
  1144. // discount = textbook.getDiscount();
  1145. // }
  1146. // //处理小计
  1147. // textbook.setSubtotal(textbook.getPrice().multiply(BigDecimal.valueOf(discount / 10)));
  1148. //
  1149. // // 判断导入的教材是否已经存在,根据教材的 ISBN 码和使用的学期判断
  1150. // LambdaQueryWrapper<Textbook> textbookLambdaQueryWrapper = new LambdaQueryWrapper<>();
  1151. // textbookLambdaQueryWrapper
  1152. // .eq(Textbook::getIssn, textbook.getIssn())
  1153. // ;
  1154. //
  1155. // Textbook oldTextbook = this.getOne(textbookLambdaQueryWrapper);
  1156. //
  1157. // Date now = new Date();
  1158. // Long loginId = StpUtil.getLoginIdAsLong();
  1159. // // 已经存在,更新数据
  1160. // if (oldTextbook != null) {
  1161. // // 更新教材数据
  1162. // textbookCoreAttribute.setId(oldTextbook.getTextbookCoreAttributeId());
  1163. // textbookCoreAttribute.setModifyDate(now);
  1164. // textbookCoreAttribute.setModifyUserId(loginId);
  1165. // textbookCoreAttributeService.updateById(textbookCoreAttribute);
  1166. //
  1167. // textbook.setId(oldTextbook.getId());
  1168. // textbook.setModifyDate(now);
  1169. // textbook.setModifyUserId(loginId);
  1170. // textbookTextbookMapper.updateById(textbook);
  1171. // } else {
  1172. // textbookCoreAttribute.setCreateDate(now);
  1173. // textbookCoreAttribute.setCreateUserId(loginId);
  1174. // textbookCoreAttributeService.save(textbookCoreAttribute);
  1175. //
  1176. // // 插入教材数据
  1177. // textbook.setCreateDate(now);
  1178. // textbook.setCreateUserId(loginId);
  1179. // textbook.setTextbookCoreAttributeId(textbookCoreAttribute.getId());
  1180. // textbookTextbookMapper.insert(textbook);
  1181. // }
  1182. // }
  1183. // }
  1184. @Override
  1185. @Transactional(rollbackFor = Exception.class)
  1186. public String textbookImport(MultipartFile file) throws IOException, IllegalAccessException {
  1187. List<TextbookImportDto> excelDataList = EasyExcel.read(file.getInputStream()).headRowNumber(3).head(TextbookImportDto.class).sheet().doReadSync();
  1188. StringBuilder sb = new StringBuilder();
  1189. List<String> codeList = new ArrayList<>();
  1190. codeList.add("textbook_type");
  1191. codeList.add("textbook_category");
  1192. Map<String, String> dictionary = ImportExcelUtil.initDictionary(codeList, dictionaryitemMapper, dictionarydetailMapper);
  1193. //查询所有需要的数据
  1194. //学科组
  1195. List<SubjectGroup> subjectGroupList = subjectGroupMapper.selectList(
  1196. Wrappers
  1197. .lambdaQuery(SubjectGroup.class)
  1198. .eq(SubjectGroup::getDeleteMark, DeleteMark.NODELETE.getCode()));
  1199. Map<String, Long> subjectGroupNameAndIdMap = subjectGroupList.stream().collect(Collectors.toMap(SubjectGroup::getGroupName, SubjectGroup::getId, (k1, k2) -> k1));
  1200. //使用课程
  1201. List<BaseCourseSubject> baseCourseSubjectList = baseCourseSubjectMapper.selectList(
  1202. Wrappers
  1203. .lambdaQuery(BaseCourseSubject.class)
  1204. .eq(BaseCourseSubject::getDeleteMark, DeleteMark.NODELETE.getCode())
  1205. );
  1206. Map<String, Long> baseCourseSubjectNameAndIdMap = baseCourseSubjectList.stream().collect(Collectors.toMap(BaseCourseSubject::getName, BaseCourseSubject::getId, (k1, k2) -> k1));
  1207. List<Textbook> insertTextbooks = new ArrayList<>();
  1208. List<Textbook> updateTextbooks = new ArrayList<>();
  1209. for (int i = 0; i < excelDataList.size(); i++) {
  1210. TextbookImportDto dto = excelDataList.get(i);
  1211. if (isRequiredFieldsFilled(dto,
  1212. sb,
  1213. i+3)) {
  1214. return sb.toString();
  1215. }
  1216. Textbook textbook = new Textbook();
  1217. BeanUtils.copyProperties(dto, textbook);
  1218. // 验证字段的合理性
  1219. // 字典类型
  1220. if (validateAndSetDictionaryField(dto::getTextbookTypeCn,
  1221. "textbook_type",
  1222. "教材分类(教材、辅材、作业本)",
  1223. dictionary,
  1224. textbook::setTextbookType,
  1225. sb,
  1226. i+3)) {
  1227. return sb.toString();
  1228. }
  1229. if (validateAndSetDictionaryField(dto::getTextbookCategory,
  1230. "textbook_category",
  1231. "教材类型(纸质教材、数字教材、纸质与数字资源结合教材)",
  1232. dictionary,
  1233. textbook::setTextbookCategory,
  1234. sb,
  1235. i+3)) {
  1236. return sb.toString();
  1237. }
  1238. // 关联表
  1239. if (validateAndSetString2LongField(dto::getGroupName,
  1240. "学科组(必须是系统中已有的学科组名称)",
  1241. subjectGroupNameAndIdMap,
  1242. textbook::setSubjectGroupId,
  1243. sb,
  1244. i+3
  1245. )) {
  1246. return sb.toString();
  1247. }
  1248. if (validateAndSetString2LongField(dto::getCourseName,
  1249. "对应课程(必须是系统中已有的课程名称)",
  1250. baseCourseSubjectNameAndIdMap,
  1251. textbook::setCourseSubjectId,
  1252. sb,
  1253. i+3
  1254. )) {
  1255. return sb.toString();
  1256. }
  1257. // 处理是否字段
  1258. if(validateAndSetBooleanField(dto::getIsTextbookPlanCn,
  1259. "规划教材(是或否)",
  1260. textbook::setIsTextbookPlan,
  1261. sb,
  1262. i + 3
  1263. )){
  1264. return sb.toString();
  1265. }
  1266. if(validateAndSetBooleanField(dto::getIsSecd,
  1267. "是否为校企合作教材(是或否)",
  1268. textbook::setIsSecd,
  1269. sb,
  1270. i + 3
  1271. )){
  1272. return sb.toString();
  1273. }
  1274. // 处理枚举字段
  1275. Map<String, Integer> useTypeMap = new HashMap<>();
  1276. for (UseSemesterTypeEnum useSemesterTypeEnum : UseSemesterTypeEnum.values()) {
  1277. useTypeMap.put(useSemesterTypeEnum.getValue(), useSemesterTypeEnum.getCode());
  1278. }
  1279. if(validateAndSetEnumField(dto::getUseTypeCn,
  1280. "使用时长(一学期~六学期)",
  1281. useTypeMap,
  1282. textbook::setUseType,
  1283. sb,
  1284. i + 3
  1285. )){
  1286. return sb.toString();
  1287. }
  1288. // 判断导入的教材是否已经存在,根据教材的 ISSN 码和使用的学科组和课程判断
  1289. LambdaQueryWrapper<Textbook> textbookLambdaQueryWrapper = new LambdaQueryWrapper<>();
  1290. textbookLambdaQueryWrapper
  1291. .eq(Textbook::getIssn, textbook.getIssn())
  1292. .eq(Textbook::getDeleteMark, DeleteMark.NODELETE.getCode())
  1293. ;
  1294. Textbook verifyTextbook = this.getOne(textbookLambdaQueryWrapper);
  1295. textbook.setIsbn(textbook.getIssn());
  1296. BigDecimal discount = BigDecimal.valueOf(textbook.getDiscount()).divide( BigDecimal.valueOf(10));
  1297. textbook.setDiscountPrice(textbook.getPrice().multiply(discount));
  1298. if(ObjectUtils.isNotEmpty(verifyTextbook)){
  1299. textbook.setId(verifyTextbook.getId());
  1300. updateTextbooks.add(textbook);
  1301. }else {
  1302. insertTextbooks.add(textbook);
  1303. }
  1304. }
  1305. //批量新增
  1306. if (!insertTextbooks.isEmpty()) {
  1307. for (Textbook textbook : insertTextbooks) {
  1308. this.save(textbook);
  1309. }
  1310. }
  1311. //批量修改
  1312. if (!updateTextbooks.isEmpty()) {
  1313. for (Textbook textbook : updateTextbooks) {
  1314. this.updateById(textbook);
  1315. }
  1316. }
  1317. return sb.toString();
  1318. }
  1319. }