TextbookServiceImpl.java 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081
  1. package com.xjrsoft.module.textbook.service.impl;
  2. import camundajar.impl.scala.concurrent.impl.FutureConvertersImpl;
  3. import cn.dev33.satoken.stp.StpUtil;
  4. import cn.hutool.core.bean.BeanUtil;
  5. import cn.hutool.core.util.ObjectUtil;
  6. import cn.hutool.core.util.StrUtil;
  7. import com.alibaba.excel.EasyExcel;
  8. import com.alibaba.excel.ExcelWriter;
  9. import com.alibaba.excel.read.listener.PageReadListener;
  10. import com.alibaba.excel.support.ExcelTypeEnum;
  11. import com.alibaba.excel.write.metadata.WriteSheet;
  12. import com.alibaba.excel.write.metadata.WriteTable;
  13. import com.alibaba.excel.write.metadata.style.WriteCellStyle;
  14. import com.alibaba.excel.write.metadata.style.WriteFont;
  15. import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
  16. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  17. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  18. import com.baomidou.mybatisplus.core.metadata.IPage;
  19. import com.baomidou.mybatisplus.core.toolkit.StringUtils;
  20. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  21. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  22. import com.github.yulichang.base.MPJBaseServiceImpl;
  23. import com.github.yulichang.wrapper.MPJLambdaWrapper;
  24. import com.xjrsoft.common.enums.*;
  25. import com.xjrsoft.common.exception.MyException;
  26. import com.xjrsoft.common.utils.excel.ExcelFillCellMergePrevColUtil;
  27. import com.xjrsoft.common.utils.excel.ExcelMergeUtil;
  28. import com.xjrsoft.module.base.entity.BaseClass;
  29. import com.xjrsoft.module.base.entity.BaseClassCourse;
  30. import com.xjrsoft.module.base.entity.BaseCourseSubject;
  31. import com.xjrsoft.module.base.entity.BaseSemester;
  32. import com.xjrsoft.module.base.mapper.BaseClassCourseMapper;
  33. import com.xjrsoft.module.base.mapper.BaseCourseSubjectMapper;
  34. import com.xjrsoft.module.base.mapper.BaseMajorSetMapper;
  35. import com.xjrsoft.module.base.mapper.BaseSemesterMapper;
  36. import com.xjrsoft.module.base.service.IBaseClassService;
  37. import com.xjrsoft.module.student.entity.BaseClassMajorSet;
  38. import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
  39. import com.xjrsoft.module.student.mapper.BaseClassMajorSetMapper;
  40. import com.xjrsoft.module.teacher.entity.XjrUser;
  41. import com.xjrsoft.module.textbook.dto.*;
  42. import com.xjrsoft.module.textbook.entity.*;
  43. import com.xjrsoft.module.textbook.mapper.*;
  44. import com.xjrsoft.module.textbook.service.ITextbookCoreAttributeService;
  45. import com.xjrsoft.module.textbook.service.ITextbookService;
  46. import com.xjrsoft.module.textbook.service.ITextbookWarehouseRecordService;
  47. import com.xjrsoft.module.textbook.service.IWfExerciseBookService;
  48. import com.xjrsoft.module.textbook.vo.*;
  49. import lombok.AllArgsConstructor;
  50. import org.apache.poi.ss.usermodel.BorderStyle;
  51. import org.apache.poi.ss.usermodel.HorizontalAlignment;
  52. import org.apache.poi.ss.usermodel.VerticalAlignment;
  53. import org.springframework.beans.BeanUtils;
  54. import org.springframework.stereotype.Service;
  55. import org.springframework.transaction.annotation.Transactional;
  56. import java.io.ByteArrayOutputStream;
  57. import java.io.InputStream;
  58. import java.math.BigDecimal;
  59. import java.util.*;
  60. import java.util.stream.Collectors;
  61. /**
  62. * @title: 教材管理
  63. * @Author szs
  64. * @Date: 2023-12-25
  65. * @Version 1.0
  66. */
  67. @Service
  68. @AllArgsConstructor
  69. public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Textbook> implements ITextbookService {
  70. private final TextbookMapper textbookTextbookMapper;
  71. private final TextbookClassRelationMapper textbookTextbookClassRelationMapper;
  72. private final TextbookSubscriptionRecordMapper textbookTextbookSubscriptionRecordMapper;
  73. private final IWfExerciseBookService wfExerciseBookService;
  74. private final IBaseClassService baseClassService;
  75. private final ITextbookWarehouseRecordService textbookClassWarehouseService;
  76. private final TextbookIssueRecordMapper textbookIssueRecordMapper;
  77. private final TextbookStudentClaimMapper textbookStudentClaimMapper;
  78. private final SubjectGroupMapper subjectGroupMapper;
  79. private final BaseSemesterMapper baseSemesterMapper;
  80. private final BaseCourseSubjectMapper baseCourseSubjectMapper;
  81. private final ITextbookCoreAttributeService textbookCoreAttributeService;
  82. private final TextbookCoreAttributeMapper textbookCoreAttributeMapper;
  83. private final BaseClassMajorSetMapper baseClassMajorSetMapper;
  84. private final BaseClassCourseMapper baseClassCourseMapper;
  85. @Override
  86. @Transactional(rollbackFor = Exception.class)
  87. public Boolean add(Textbook textbook) {
  88. textbook.setCreateDate(new Date());
  89. TextbookCoreAttribute textbookCoreAttribute = new TextbookCoreAttribute();
  90. BeanUtils.copyProperties(textbook, textbookCoreAttribute);
  91. textbookCoreAttributeMapper.insert(textbookCoreAttribute);
  92. textbook.setTextbookCoreAttributeId(textbookCoreAttribute.getId());
  93. textbook.setSubtotal(textbook.getPrice().multiply(BigDecimal.valueOf(textbook.getDiscount()/10)));
  94. textbookTextbookMapper.insert(textbook);
  95. for (TextbookClassRelation textbookClassRelation : textbook.getTextbookClassRelationList()) {
  96. textbookClassRelation.setTextbookId(textbook.getId());
  97. textbookClassRelation.setCreateDate(new Date());
  98. textbookTextbookClassRelationMapper.insert(textbookClassRelation);
  99. }
  100. if (textbook.getTextbookSubscriptionRecordList() != null) {
  101. for (TextbookSubscriptionRecord textbookSubscriptionRecord : textbook.getTextbookSubscriptionRecordList()) {
  102. textbookSubscriptionRecord.setTextbookId(textbook.getId());
  103. textbookSubscriptionRecord.setCreateDate(new Date());
  104. textbookTextbookSubscriptionRecordMapper.insert(textbookSubscriptionRecord);
  105. }
  106. }
  107. return true;
  108. }
  109. @Override
  110. @Transactional(rollbackFor = Exception.class)
  111. public Boolean update(Textbook textbook) {
  112. textbookTextbookMapper.updateById(textbook);
  113. //********************************* TextbookClassRelation 增删改 开始 *******************************************/
  114. {
  115. // 查出所有子级的id
  116. List<TextbookClassRelation> textbookClassRelationList = textbookTextbookClassRelationMapper.selectList(Wrappers.lambdaQuery(TextbookClassRelation.class).eq(TextbookClassRelation::getTextbookId, textbook.getId()).select(TextbookClassRelation::getId));
  117. List<Long> textbookClassRelationIds = textbookClassRelationList.stream().map(TextbookClassRelation::getId).collect(Collectors.toList());
  118. //原有子表单 没有被删除的主键
  119. List<Long> textbookClassRelationOldIds = textbook.getTextbookClassRelationList().stream().map(TextbookClassRelation::getId).filter(Objects::nonNull).collect(Collectors.toList());
  120. //找到需要删除的id
  121. List<Long> textbookClassRelationRemoveIds = textbookClassRelationIds.stream().filter(item -> !textbookClassRelationOldIds.contains(item)).collect(Collectors.toList());
  122. for (TextbookClassRelation textbookClassRelation : textbook.getTextbookClassRelationList()) {
  123. //如果不等于空则修改
  124. if (textbookClassRelation.getId() != null) {
  125. textbookTextbookClassRelationMapper.updateById(textbookClassRelation);
  126. }
  127. //如果等于空 则新增
  128. else {
  129. //已经不存在的id 删除
  130. textbookClassRelation.setTextbookId(textbook.getId());
  131. textbookTextbookClassRelationMapper.insert(textbookClassRelation);
  132. }
  133. }
  134. //已经不存在的id 删除
  135. if (textbookClassRelationRemoveIds.size() > 0) {
  136. textbookTextbookClassRelationMapper.deleteBatchIds(textbookClassRelationRemoveIds);
  137. }
  138. }
  139. //********************************* TextbookClassRelation 增删改 结束 *******************************************/
  140. //********************************* TextbookSubscriptionRecord 增删改 开始 *******************************************/
  141. {
  142. // 查出所有子级的id
  143. List<TextbookSubscriptionRecord> textbookSubscriptionRecordList = textbookTextbookSubscriptionRecordMapper.selectList(Wrappers.lambdaQuery(TextbookSubscriptionRecord.class).eq(TextbookSubscriptionRecord::getWfTextbookSubscriptionId, textbook.getId()).select(TextbookSubscriptionRecord::getId));
  144. List<Long> textbookSubscriptionRecordIds = textbookSubscriptionRecordList.stream().map(TextbookSubscriptionRecord::getId).collect(Collectors.toList());
  145. //原有子表单 没有被删除的主键
  146. if (!textbookSubscriptionRecordIds.isEmpty()) {
  147. List<Long> textbookSubscriptionRecordOldIds = textbook.getTextbookSubscriptionRecordList().stream().map(TextbookSubscriptionRecord::getId).filter(Objects::nonNull).collect(Collectors.toList());
  148. //找到需要删除的id
  149. List<Long> textbookSubscriptionRecordRemoveIds = textbookSubscriptionRecordIds.stream().filter(item -> !textbookSubscriptionRecordOldIds.contains(item)).collect(Collectors.toList());
  150. for (TextbookSubscriptionRecord textbookSubscriptionRecord : textbook.getTextbookSubscriptionRecordList()) {
  151. //如果不等于空则修改
  152. if (textbookSubscriptionRecord.getId() != null) {
  153. textbookTextbookSubscriptionRecordMapper.updateById(textbookSubscriptionRecord);
  154. }
  155. //如果等于空 则新增
  156. else {
  157. //已经不存在的id 删除
  158. textbookSubscriptionRecord.setWfTextbookSubscriptionId(textbook.getId());
  159. textbookTextbookSubscriptionRecordMapper.insert(textbookSubscriptionRecord);
  160. }
  161. }
  162. //已经不存在的id 删除
  163. if (textbookSubscriptionRecordRemoveIds.size() > 0) {
  164. textbookTextbookSubscriptionRecordMapper.deleteBatchIds(textbookSubscriptionRecordRemoveIds);
  165. }
  166. for (TextbookSubscriptionRecord textbookSubscriptionRecord : textbook.getTextbookSubscriptionRecordList()) {
  167. //如果不等于空则修改
  168. if (textbookSubscriptionRecord.getId() != null) {
  169. textbookTextbookSubscriptionRecordMapper.updateById(textbookSubscriptionRecord);
  170. }
  171. //如果等于空 则新增
  172. else {
  173. //已经不存在的id 删除
  174. textbookSubscriptionRecord.setWfTextbookSubscriptionId(textbook.getId());
  175. textbookTextbookSubscriptionRecordMapper.insert(textbookSubscriptionRecord);
  176. }
  177. }
  178. //已经不存在的id 删除
  179. if (textbookSubscriptionRecordRemoveIds.size() > 0) {
  180. textbookTextbookSubscriptionRecordMapper.deleteBatchIds(textbookSubscriptionRecordRemoveIds);
  181. }
  182. }
  183. //********************************* TextbookSubscriptionRecord 增删改 结束 *******************************************/
  184. return true;
  185. }
  186. }
  187. @Override
  188. @Transactional(rollbackFor = Exception.class)
  189. public Boolean delete(List<Long> ids) {
  190. textbookTextbookMapper.deleteBatchIds(ids);
  191. textbookTextbookClassRelationMapper.delete(Wrappers.lambdaQuery(TextbookClassRelation.class).in(TextbookClassRelation::getTextbookId, ids));
  192. textbookTextbookSubscriptionRecordMapper.delete(Wrappers.lambdaQuery(TextbookSubscriptionRecord.class).in(TextbookSubscriptionRecord::getWfTextbookSubscriptionId, ids));
  193. return true;
  194. }
  195. @Override
  196. public Page<TextbookPageVo> getPage(Page<TextbookPageDto> page, TextbookPageDto dto) {
  197. return textbookTextbookMapper.getPage(page, dto);
  198. }
  199. /* @Override
  200. @Transactional
  201. public Boolean dataHandleAddTextbookNode(Long dataId) {
  202. WfTextbookSubscription wfTextbookSubscription = iWfTextbookSubscriptionService.selectById(dataId);
  203. if (ObjectUtil.isNotNull(wfTextbookSubscription) && ObjectUtil.isNotNull(wfTextbookSubscription.getWfTextbookSubscriptionItemList()) && wfTextbookSubscription.getWfTextbookSubscriptionItemList().size() > 0) {
  204. //遍历征订项
  205. for (WfTextbookSubscriptionItem wfTextbookSubscriptionItem : wfTextbookSubscription.getWfTextbookSubscriptionItemList()) {
  206. Long semesterId = wfTextbookSubscription.getBaseSemesterId();
  207. String issn = wfTextbookSubscriptionItem.getIssn();
  208. LambdaQueryWrapper<Textbook> queryWrapper = new LambdaQueryWrapper<>();
  209. queryWrapper
  210. .eq(Textbook::getIssn, issn)
  211. .eq(Textbook::getBaseSemesterId, semesterId);
  212. List<Textbook> textbookList = this.list(queryWrapper);
  213. //征订的教材没有在教材管理
  214. if (ObjectUtil.isNull(textbookList) || textbookList.size() == 0) {
  215. Textbook textbook = new Textbook() {{
  216. setIssn((ObjectUtil.isNull(wfTextbookSubscriptionItem.getIssn()) || StringUtils.isBlank(wfTextbookSubscriptionItem.getIssn())) ? "/" : wfTextbookSubscriptionItem.getIssn());
  217. setIsbn((ObjectUtil.isNull(wfTextbookSubscriptionItem.getIsbn()) || StringUtils.isBlank(wfTextbookSubscriptionItem.getIsbn())) ? "/" : wfTextbookSubscriptionItem.getIsbn());
  218. setBookName((ObjectUtil.isNull(wfTextbookSubscriptionItem.getBookName()) || StringUtils.isBlank(wfTextbookSubscriptionItem.getBookName())) ? "/" : wfTextbookSubscriptionItem.getBookName());
  219. setPublishingHouse((ObjectUtil.isNull(wfTextbookSubscriptionItem.getPublishingHouse()) || StringUtils.isBlank(wfTextbookSubscriptionItem.getPublishingHouse())) ? "/" : wfTextbookSubscriptionItem.getPublishingHouse());
  220. setEditorInChief((ObjectUtil.isNull(wfTextbookSubscriptionItem.getEditorInChief()) || StringUtils.isBlank(wfTextbookSubscriptionItem.getEditorInChief())) ? "/" : wfTextbookSubscriptionItem.getEditorInChief());
  221. setSubjectGroupId((ObjectUtil.isNull(wfTextbookSubscription.getSubjectGroupId())) ? 0 : wfTextbookSubscription.getSubjectGroupId());
  222. setBaseSemesterId(wfTextbookSubscription.getBaseSemesterId());
  223. setCourseSubjectId((ObjectUtil.isNull(wfTextbookSubscriptionItem.getCourseSubjectId())) ? 0 : wfTextbookSubscriptionItem.getCourseSubjectId());
  224. setVersion((ObjectUtil.isNull(wfTextbookSubscriptionItem.getVersion()) || StringUtils.isBlank(wfTextbookSubscriptionItem.getVersion())) ? "/" : wfTextbookSubscriptionItem.getVersion());
  225. setIsTextbookPlan((ObjectUtil.isNull(wfTextbookSubscriptionItem.getIsTextbookPlan()) || StringUtils.isBlank(wfTextbookSubscriptionItem.getIsTextbookPlan())) ? "/" : wfTextbookSubscriptionItem.getIsTextbookPlan());
  226. if (ObjectUtil.isNotNull(wfTextbookSubscriptionItem.getSubscriptionType()) && wfTextbookSubscriptionItem.getSubscriptionType().equals(SubscriptionTypeEnum.STextbook.getCode())) {
  227. setTextbookType(TextbookTypeEnum.TTextbook.getCode());
  228. }
  229. if (ObjectUtil.isNotNull(wfTextbookSubscriptionItem.getSubscriptionType()) && wfTextbookSubscriptionItem.getSubscriptionType().equals(SubscriptionTypeEnum.SMaterials.getCode())) {
  230. setTextbookType(TextbookTypeEnum.TMaterials.getCode());
  231. }
  232. setSpecificationsModels("/");
  233. setAppraisalPrice((ObjectUtil.isNull(wfTextbookSubscriptionItem.getAppraisalPrice())) ? new BigDecimal(0) : wfTextbookSubscriptionItem.getAppraisalPrice());
  234. setPrice(new BigDecimal(0));
  235. setDiscount(10D);
  236. setSubtotal(new BigDecimal(0));
  237. setStock(0);
  238. }};
  239. //班级不为空
  240. List<Long> classIdList = new ArrayList<>();
  241. if (ObjectUtil.isNotNull(wfTextbookSubscriptionItem.getClassIds()) && !wfTextbookSubscriptionItem.getClassIds().equals("")) {
  242. //将班级ids转换为List
  243. String classIds = wfTextbookSubscriptionItem.getClassIds();
  244. String[] classIdStrs = classIds.split(",");
  245. for (String classIdStr : classIdStrs) {
  246. classIdList.add(Long.parseLong(classIdStr));
  247. }
  248. //查询年级,如果添加的班级只存在一个年级,添加年级字段值
  249. LambdaQueryWrapper<BaseClass> queryWrapper1 = new LambdaQueryWrapper<>();
  250. queryWrapper1
  251. .select(BaseClass::getGradeId)
  252. .in(BaseClass::getId, classIdList)
  253. .groupBy(BaseClass::getGradeId);
  254. List<BaseClass> baseClassList = baseClassService.list(queryWrapper1);
  255. if (ObjectUtil.isNotNull(baseClassList) && baseClassList.size() == 1) {
  256. textbook.setGradeId(baseClassList.get(0).getGradeId());
  257. }
  258. }
  259. //插入教材数据
  260. textbook.setCreateDate(new Date());
  261. textbookTextbookMapper.insert(textbook);
  262. //插入班级和教材关系
  263. for (Long classId : classIdList) {
  264. textbookTextbookClassRelationMapper.insert(new TextbookClassRelation() {{
  265. setCreateDate(new Date());
  266. setTextbookId(textbook.getId());
  267. setClassId(classId);
  268. }});
  269. }
  270. //添加教材征订记录
  271. textbookTextbookSubscriptionRecordMapper.insert(new TextbookSubscriptionRecord() {{
  272. setCreateDate(new Date());
  273. setTextbookId(textbook.getId());
  274. setWfTextbookSubscriptionId(wfTextbookSubscription.getId());
  275. setWfTextbookSubscriptionItemId(wfTextbookSubscriptionItem.getId());//该字段存入征订项的id,征订项中有所属征订记录
  276. }});
  277. } else {
  278. //征订的教材在教材管理,进行班级的和记录的管理
  279. Textbook textbook = textbookList.get(0);
  280. //班级不为空
  281. if (ObjectUtil.isNotNull(wfTextbookSubscriptionItem.getClassIds()) && !wfTextbookSubscriptionItem.getClassIds().equals("")) {
  282. //将班级ids转换为List
  283. String classIds = wfTextbookSubscriptionItem.getClassIds();
  284. String[] classIdStrs = classIds.split(",");
  285. for (String classIdStr : classIdStrs) {
  286. textbookTextbookClassRelationMapper.insert(new TextbookClassRelation() {{
  287. setCreateDate(new Date());
  288. setTextbookId(textbook.getId());
  289. setClassId(Long.parseLong(classIdStr));
  290. }});
  291. }
  292. }
  293. //添加教材征订记录
  294. textbookTextbookSubscriptionRecordMapper.insert(new TextbookSubscriptionRecord() {{
  295. setCreateDate(new Date());
  296. setTextbookId(textbook.getId());
  297. setWfTextbookSubscriptionId(wfTextbookSubscription.getId());
  298. setWfTextbookSubscriptionItemId(wfTextbookSubscriptionItem.getId());//该字段存入正定项的id,征订项中有所属征订记录
  299. }});
  300. }
  301. }
  302. }
  303. return true;
  304. }*/
  305. /**
  306. * 添加作业本规则
  307. *
  308. * @param dataId
  309. * @return
  310. */
  311. @Override
  312. @Transactional
  313. public Boolean dataHandleAddExerciseBookNode(Long dataId) {
  314. WfExerciseBook wfExerciseBook = wfExerciseBookService.selectById(dataId);
  315. if (ObjectUtil.isNotNull(wfExerciseBook) && ObjectUtil.isNotNull(wfExerciseBook.getWfExerciseBookItemList()) && wfExerciseBook.getWfExerciseBookItemList().size() > 0) {
  316. for (WfExerciseBookItem wfExerciseBookItem : wfExerciseBook.getWfExerciseBookItemList()) {
  317. Long semesterId = wfExerciseBook.getBaseSemesterId();
  318. String bookName = wfExerciseBookItem.getSubscriptionType();//作业本的选择类型对应教材管理的书名
  319. LambdaQueryWrapper<Textbook> queryWrapper = new LambdaQueryWrapper<>();
  320. queryWrapper
  321. .eq(Textbook::getBookName, bookName)
  322. .eq(Textbook::getBaseSemesterId, semesterId);
  323. List<Textbook> textbookList = this.list(queryWrapper);
  324. //征订的作业本没有在教材管理
  325. if (ObjectUtil.isNull(textbookList) || textbookList.size() == 0) {
  326. Textbook textbook = new Textbook() {{
  327. setIssn("/");
  328. setIsbn("/");
  329. if (ObjectUtil.isNotNull(wfExerciseBookItem.getSubscriptionType()) && wfExerciseBookItem.getSubscriptionType().equals(ExerciseBookeTypeEnum.ExerciseBook1.getCode())) {
  330. setBookName(ExerciseBookeTypeEnum.ExerciseBook1.getValue());
  331. }
  332. if (ObjectUtil.isNotNull(wfExerciseBookItem.getSubscriptionType()) && wfExerciseBookItem.getSubscriptionType().equals(ExerciseBookeTypeEnum.ExerciseBook2.getCode())) {
  333. setBookName(ExerciseBookeTypeEnum.ExerciseBook2.getValue());
  334. }
  335. setPublishingHouse("/");
  336. setEditorInChief("/");
  337. setBaseSemesterId(wfExerciseBook.getBaseSemesterId());
  338. setVersion("/");
  339. setIsTextbookPlan("/");
  340. setTextbookType(TextbookTypeEnum.TExerciseBook.getCode());
  341. setSpecificationsModels((ObjectUtil.isNull(wfExerciseBookItem.getSpecificationsModels()) || StringUtils.isBlank(wfExerciseBookItem.getSpecificationsModels())) ? "/" : wfExerciseBookItem.getSpecificationsModels());
  342. //年级id
  343. if (ObjectUtil.isNotNull(wfExerciseBook.getClassId()) && wfExerciseBook.getClassId() > 0) {
  344. LambdaQueryWrapper<BaseClass> queryWrapper1 = new LambdaQueryWrapper<>();
  345. queryWrapper1
  346. .eq(BaseClass::getId, wfExerciseBook.getClassId());
  347. BaseClass baseClass = baseClassService.getOne(queryWrapper1);
  348. if (ObjectUtil.isNotNull(baseClass)) {
  349. setGradeId(baseClass.getGradeId());
  350. }
  351. }
  352. setAppraisalPrice((ObjectUtil.isNull(wfExerciseBookItem.getAppraisalPrice())) ? new BigDecimal(0) : wfExerciseBookItem.getAppraisalPrice());
  353. setPrice(new BigDecimal(0));
  354. setDiscount(10D);
  355. setSubtotal(new BigDecimal(0));
  356. setStock(0);
  357. }};
  358. //插入教材数据
  359. textbook.setCreateDate(new Date());
  360. textbookTextbookMapper.insert(textbook);
  361. //插入班级和教材关系
  362. if (ObjectUtil.isNotNull(wfExerciseBook.getClassId()) && wfExerciseBook.getClassId() > 0) {
  363. textbookTextbookClassRelationMapper.insert(new TextbookClassRelation() {{
  364. setCreateDate(new Date());
  365. setTextbookId(textbook.getId());
  366. setClassId(wfExerciseBook.getClassId());
  367. }});
  368. }
  369. //添加教材征订记录
  370. textbookTextbookSubscriptionRecordMapper.insert(new TextbookSubscriptionRecord() {{
  371. setCreateDate(new Date());
  372. setTextbookId(textbook.getId());
  373. setWfTextbookSubscriptionId(wfExerciseBook.getId());
  374. }});
  375. } else {
  376. //征订的教材在教材管理,进行班级的和记录的管理
  377. Textbook textbook = textbookList.get(0);
  378. //班级不为空
  379. if (ObjectUtil.isNotNull(wfExerciseBook.getClassId()) && wfExerciseBook.getClassId() > 0) {
  380. textbookTextbookClassRelationMapper.insert(new TextbookClassRelation() {{
  381. setCreateDate(new Date());
  382. setTextbookId(textbook.getId());
  383. setClassId(wfExerciseBook.getClassId());
  384. }});
  385. }
  386. //添加教材征订记录
  387. textbookTextbookSubscriptionRecordMapper.insert(new TextbookSubscriptionRecord() {{
  388. setCreateDate(new Date());
  389. setTextbookId(textbook.getId());
  390. setWfTextbookSubscriptionId(wfExerciseBook.getId());
  391. }});
  392. }
  393. }
  394. }
  395. return true;
  396. }
  397. @Override
  398. public List<TextbookSubscriptionRecordVo> subscriptionList(Long id) {
  399. Textbook textbook = this.getById(id);
  400. List<TextbookSubscriptionRecordVo> recordVos = new ArrayList<>();
  401. //是作业本
  402. if (textbook.getTextbookType().equals(TextbookTypeEnum.TExerciseBook.getCode())) {
  403. recordVos = textbookTextbookMapper.exerciseBookSubscriptionList(id);
  404. for (TextbookSubscriptionRecordVo recordVo : recordVos) {
  405. recordVo.setIssn("/");
  406. recordVo.setPublishingHouse("/");
  407. recordVo.setEditorInChief("/");
  408. recordVo.setIsTextbookPlanCn("/");
  409. recordVo.setCourseName("/");
  410. recordVo.setGradeName("/");
  411. recordVo.setTeacherSubscriptionNumber(0);
  412. recordVo.setTeacherReferenceNumber(0);
  413. }
  414. }
  415. //是教材或者教辅
  416. if (textbook.getTextbookType().equals(TextbookTypeEnum.TTextbook.getCode()) || textbook.getTextbookType().equals(TextbookTypeEnum.TMaterials.getCode())) {
  417. recordVos = textbookTextbookMapper.subscriptionList(id);
  418. for (TextbookSubscriptionRecordVo recordVo : recordVos) {
  419. if (ObjectUtil.isNull(recordVo) || StrUtil.isEmpty(recordVo.getClassIds())) {
  420. // recordVos.remove(recordVo);
  421. // if (recordVos.isEmpty()) {
  422. // break;
  423. // }
  424. continue;
  425. }
  426. String[] split = recordVo.getClassIds().split(",");
  427. List<String> ids = new ArrayList<>();
  428. for (String classId : split) {
  429. ids.add(classId.trim());
  430. }
  431. List<TextbookSubscriptionClassVo> classInfo = textbookTextbookMapper.getClassInfo(ids);
  432. String useClass = "";
  433. for (int i = 0; i < classInfo.size(); i++) {
  434. if (i >= 1) {
  435. useClass += ",";
  436. }
  437. TextbookSubscriptionClassVo classVo = classInfo.get(i);
  438. useClass += classVo.getName();
  439. }
  440. recordVo.setUseClass(useClass);
  441. }
  442. }
  443. return recordVos;
  444. }
  445. @Override
  446. public TextbookVo getInfoByissn(String issn) {
  447. TextbookVo infoByissn = textbookTextbookMapper.getInfoByissn(issn);
  448. if (infoByissn == null) {
  449. return null;
  450. }
  451. List<TextbookClassRelation> classRelationList = textbookTextbookClassRelationMapper.selectList(
  452. new QueryWrapper<TextbookClassRelation>().lambda().eq(TextbookClassRelation::getTextbookId, infoByissn.getId())
  453. );
  454. infoByissn.setTextbookClassRelationList(BeanUtil.copyToList(classRelationList, TextbookClassRelationVo.class));
  455. return infoByissn;
  456. }
  457. @Override
  458. public List<TextbookWarehouseRecordListVo> warehouseList(Long id) {
  459. List<TextbookWarehouseRecordListVo> result = textbookTextbookMapper.warehouseList(id);
  460. if (!result.isEmpty()) {
  461. return result;
  462. }
  463. return new ArrayList<>();
  464. }
  465. @Override
  466. public List<TextbookClassRelation> getClassRelation(Long id) {
  467. List<TextbookClassRelation> classRelation = textbookTextbookMapper.getClassRelation(id);
  468. if (!classRelation.isEmpty()) {
  469. return classRelation;
  470. }
  471. return new ArrayList<>();
  472. }
  473. @Override
  474. public List<TextbookIssueRecordListVo> issueList(Long id) {
  475. List<TextbookIssueRecordListVo> result = textbookTextbookMapper.issueList(id);
  476. if (!result.isEmpty()) {
  477. return result;
  478. }
  479. return new ArrayList<>();
  480. }
  481. @Override
  482. public List<WfTextbookClaimListVo> claimList(Long id) {
  483. List<WfTextbookClaimListVo> result = new ArrayList<>();
  484. //教材领取分为两种
  485. //教师领取
  486. MPJLambdaWrapper<TextbookIssueRecord> queryIssueRecord = new MPJLambdaWrapper<>();
  487. queryIssueRecord
  488. .eq(TextbookIssueRecord::getTextbookId, id)
  489. .eq(TextbookIssueRecord::getIssueMode, "im_teacher");
  490. List<TextbookIssueRecord> textbookIssueRecordList = textbookIssueRecordMapper.selectJoinList(TextbookIssueRecord.class, queryIssueRecord);
  491. for (TextbookIssueRecord t : textbookIssueRecordList) {
  492. MPJLambdaWrapper<TextbookIssueRecord> queryTeaClaimVo = new MPJLambdaWrapper<>();
  493. queryTeaClaimVo
  494. .selectAs(BaseSemester::getName, WfTextbookClaimListVo::getSemesterName)
  495. .selectAs(XjrUser::getName, WfTextbookClaimListVo::getName)
  496. .selectAs(XjrUser::getUserName, WfTextbookClaimListVo::getUserName)
  497. .selectAs(TextbookIssueRecord::getCreateDate, WfTextbookClaimListVo::getClaimDate)
  498. .leftJoin(XjrUser.class, XjrUser::getId, TextbookIssueRecord::getReceiveUserId)
  499. .leftJoin(WfTextbookClaim.class, WfTextbookClaim::getId, TextbookIssueRecord::getDataId)
  500. .leftJoin(BaseSemester.class, BaseSemester::getId, WfTextbookClaim::getBaseSemesterId)
  501. .eq(TextbookIssueRecord::getId, t.getId());
  502. WfTextbookClaimListVo wfTextbookClaimListVo = textbookIssueRecordMapper.selectJoinOne(WfTextbookClaimListVo.class, queryTeaClaimVo);
  503. for (int j = 0; j < t.getIssueNumber(); j++) {
  504. wfTextbookClaimListVo.setClaimIdentity("教师");
  505. wfTextbookClaimListVo.setClassName("/");
  506. result.add(wfTextbookClaimListVo);
  507. }
  508. }
  509. //学生领取
  510. MPJLambdaWrapper<TextbookStudentClaim> queryStuClaimVo = new MPJLambdaWrapper<>();
  511. queryStuClaimVo
  512. .select("'学生' as claimIdentity")
  513. .selectAs(BaseClass::getName, WfTextbookClaimListVo::getClassName)
  514. .selectAs(BaseSemester::getName, WfTextbookClaimListVo::getSemesterName)
  515. .selectAs(XjrUser::getName, WfTextbookClaimListVo::getName)
  516. .selectAs(XjrUser::getUserName, WfTextbookClaimListVo::getUserName)
  517. .selectAs(TextbookStudentClaim::getCreateDate, WfTextbookClaimListVo::getClaimDate)
  518. .leftJoin(XjrUser.class, XjrUser::getId, TextbookStudentClaim::getStudentUserId)
  519. .leftJoin(BaseSemester.class, BaseSemester::getId, TextbookStudentClaim::getBaseSemesterId)
  520. .leftJoin(BaseClass.class, BaseClass::getId, TextbookStudentClaim::getClassId)
  521. .eq(TextbookStudentClaim::getTextbookId, id)
  522. .eq(TextbookStudentClaim::getIsClaim, 1);
  523. List<WfTextbookClaimListVo> wfTextbookClaimListVoList = textbookStudentClaimMapper.selectJoinList(WfTextbookClaimListVo.class, queryStuClaimVo);
  524. result.addAll(wfTextbookClaimListVoList);
  525. return result;
  526. }
  527. @Override
  528. public List<TextbookStandingExportQueryVo> listTextbookStandingExportQuery(TextbookStandingExportQuerytDto dto) {
  529. return textbookTextbookMapper.listTextbookStandingExportQuery(dto);
  530. }
  531. @Override
  532. public ByteArrayOutputStream listTextbookSubscriptionExportQuery(TextbookSubscriptionExportQueryDto dto) {
  533. List<TextbookSubscriptionExportQueryVo> result = textbookTextbookMapper.listTextbookSubscriptionExportQuery(dto);
  534. //将班级转换为中文
  535. for (TextbookSubscriptionExportQueryVo to : result) {
  536. if (to != null && to.getClassIds() != null && !("").equals(to.getClassIds())) {
  537. List<Long> classIdList = new ArrayList<>();
  538. String[] classIdStrs = to.getClassIds().split(",");
  539. for (String classIdStr : classIdStrs) {
  540. classIdList.add(Long.parseLong(classIdStr.trim()));
  541. }
  542. LambdaQueryWrapper<BaseClass> baseClassLambdaQueryWrapper = new LambdaQueryWrapper<>();
  543. baseClassLambdaQueryWrapper
  544. .in(BaseClass::getId, classIdList);
  545. List<BaseClass> baseClassList = baseClassService.list(baseClassLambdaQueryWrapper);
  546. if (baseClassList.size() > 0) {
  547. StringBuilder sb = new StringBuilder();
  548. for (int i = 0; i < baseClassList.size(); i++) {
  549. sb.append(baseClassList.get(i).getName());
  550. if (i != baseClassList.size() - 1) {
  551. sb.append(",");
  552. }
  553. }
  554. to.setUseClass(sb.toString());
  555. }
  556. }
  557. }
  558. ByteArrayOutputStream bot = new ByteArrayOutputStream();
  559. // 设置动态头
  560. String baseSemesterCn = "";
  561. if(dto.getBaseSemesterId() != null){
  562. LambdaQueryWrapper<BaseSemester> baseSemesterLambdaQueryWrapper = new LambdaQueryWrapper<>();
  563. baseSemesterLambdaQueryWrapper
  564. .eq(BaseSemester::getId, dto.getBaseSemesterId());
  565. BaseSemester baseSemester = baseSemesterMapper.selectOne(baseSemesterLambdaQueryWrapper);
  566. if(baseSemester != null){
  567. baseSemesterCn = baseSemester.getName();
  568. }
  569. }
  570. String headTitle = "重庆市铜梁职业教育中心" + baseSemesterCn + "教材征订表";
  571. List<List<String>> headList = new ArrayList<>();
  572. // List<String> head0 = new ArrayList<>();
  573. // head0.add("个人信息");
  574. // head0.add("用户名");
  575. // List<String> head1 = new ArrayList<>();
  576. // head1.add("个人信息");
  577. // head1.add("年龄");
  578. // List<String> head2 = new ArrayList<>();
  579. // head2.add("个人信息");
  580. // head2.add("地址");
  581. headList.add(new ArrayList<String>(){{
  582. add(headTitle);
  583. add("国际标准刊号");
  584. }});
  585. headList.add(new ArrayList<String>(){{
  586. add(headTitle);
  587. add("书名");
  588. }});
  589. headList.add(new ArrayList<String>(){{
  590. add(headTitle);
  591. add("出版社");
  592. }});
  593. headList.add(new ArrayList<String>(){{
  594. add(headTitle);
  595. add("主编");
  596. }});
  597. headList.add(new ArrayList<String>(){{
  598. add(headTitle);
  599. add("估价(元)");
  600. }});
  601. headList.add(new ArrayList<String>(){{
  602. add(headTitle);
  603. add("是否为规划教材");
  604. }});
  605. headList.add(new ArrayList<String>(){{
  606. add(headTitle);
  607. add("对应课程");
  608. }});
  609. headList.add(new ArrayList<String>(){{
  610. add(headTitle);
  611. add("使用年级");
  612. }});
  613. headList.add(new ArrayList<String>(){{
  614. add(headTitle);
  615. add("使用班级");
  616. }});
  617. headList.add(new ArrayList<String>(){{
  618. add(headTitle);
  619. add("学生用书征订数量");
  620. }});
  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. EasyExcel.write(bot, TextbookSubscriptionExportQueryVo.class).automaticMergeHead(true).excelType(ExcelTypeEnum.XLSX).head(headList).sheet().doWrite(result);
  642. return bot;
  643. }
  644. @Override
  645. public ByteArrayOutputStream listTextbookClaimExportQuery(TextbookClaimExportQueryDto dto) {
  646. List<TextbookClaimExportQueryVo> customerList = textbookTextbookMapper.listTextbookClaimExportQuery(dto);
  647. ByteArrayOutputStream bot = new ByteArrayOutputStream();
  648. //内容样式
  649. WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
  650. //设计内容居中
  651. contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);// 水平居中
  652. contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);// 垂直居中
  653. contentWriteCellStyle.setWrapped(true); //设置自动换行;
  654. // 设置字体
  655. WriteFont contentWriteFont = new WriteFont();
  656. contentWriteFont.setFontHeightInPoints((short) 12);//设置字体大小
  657. contentWriteFont.setFontName("宋体"); //设置字体名字
  658. contentWriteCellStyle.setWriteFont(contentWriteFont);//在样式用应用设置的字体;
  659. //设置样式;
  660. contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);//设置底边框;
  661. contentWriteCellStyle.setBottomBorderColor((short) 0);//设置底边框颜色;
  662. contentWriteCellStyle.setBorderLeft(BorderStyle.THIN); //设置左边框;
  663. contentWriteCellStyle.setLeftBorderColor((short) 0);//设置左边框颜色;
  664. contentWriteCellStyle.setBorderRight(BorderStyle.THIN);//设置右边框;
  665. contentWriteCellStyle.setRightBorderColor((short) 0);//设置右边框颜色;
  666. contentWriteCellStyle.setBorderTop(BorderStyle.THIN);//设置顶边框;
  667. contentWriteCellStyle.setTopBorderColor((short) 0); ///设置顶边框颜色;
  668. //设置头部样式
  669. WriteCellStyle headWriteCellStyle = new WriteCellStyle();
  670. // 背景颜色
  671. // headWriteCellStyle.setFillForegroundColor(IndexedColors.LIGHT_TURQUOISE1.getIndex());
  672. // headWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
  673. // 字体
  674. WriteFont headWriteFont = new WriteFont();
  675. headWriteFont.setFontName("宋体");//设置字体名字
  676. headWriteFont.setFontHeightInPoints((short) 14);//设置字体大小
  677. headWriteFont.setBold(true);//字体加粗
  678. headWriteCellStyle.setWriteFont(headWriteFont); //在样式用应用设置的字体;
  679. // 样式
  680. headWriteCellStyle.setBorderBottom(BorderStyle.THIN);//设置底边框;
  681. headWriteCellStyle.setBottomBorderColor((short) 0);//设置底边框颜色;
  682. headWriteCellStyle.setBorderLeft(BorderStyle.THIN); //设置左边框;
  683. headWriteCellStyle.setLeftBorderColor((short) 0);//设置左边框颜色;
  684. headWriteCellStyle.setBorderRight(BorderStyle.THIN);//设置右边框;
  685. headWriteCellStyle.setRightBorderColor((short) 0);//设置右边框颜色;
  686. headWriteCellStyle.setBorderTop(BorderStyle.THIN);//设置顶边框;
  687. headWriteCellStyle.setTopBorderColor((short) 0); //设置顶边框颜色;
  688. headWriteCellStyle.setWrapped(true); //设置自动换行;
  689. //设置头部标题居中
  690. headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);//设置水平对齐的样式为居中对齐;
  691. headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐的样式为居中对齐;
  692. headWriteCellStyle.setShrinkToFit(true);//设置文本收缩至合适
  693. // 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现
  694. HorizontalCellStyleStrategy horizontalCellStyleStrategy =
  695. new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
  696. try (ExcelWriter excelWriter = EasyExcel.write(bot, TextbookClaimExportQueryVo.class).registerWriteHandler(horizontalCellStyleStrategy).build()) {
  697. //已经写入的行
  698. int rowIndex = 0;
  699. //已经写入的表
  700. int tableIndex = 0;
  701. // 把sheet设置为不需要头 不然会输出sheet的头 这样看起来第一个table 就有2个头了
  702. WriteSheet writeSheet = EasyExcel.writerSheet("模板").needHead(Boolean.FALSE).build();
  703. //sheet的表头
  704. List<List<String>> sheetHeadList = new ArrayList<List<String>>();
  705. sheetHeadList.add(new ArrayList<String>() {{
  706. add("铜梁执教中心班级教材教辅发放情况表");
  707. }});
  708. //sheet的表头合并策略
  709. ExcelFillCellMergePrevColUtil sheetHeadColumn = new ExcelFillCellMergePrevColUtil();
  710. sheetHeadColumn.add(rowIndex, 0, 12);
  711. //这是一个sheet表头的table
  712. WriteTable writeSheetHeadTable = EasyExcel.writerTable(tableIndex).needHead(Boolean.TRUE).head(sheetHeadList).registerWriteHandler(sheetHeadColumn).build();
  713. excelWriter.write(new ArrayList<>(), writeSheet, writeSheetHeadTable);
  714. //对返回的集合进行处理
  715. //现针对学期进行分组
  716. Map<Long, List<TextbookClaimExportQueryVo>> groupedBySemester = customerList.stream()
  717. .collect(Collectors.groupingBy(TextbookClaimExportQueryVo::getBaseSemesterId));
  718. Iterator<Map.Entry<Long, List<TextbookClaimExportQueryVo>>> groupedBySemesterIterator = groupedBySemester.entrySet().iterator();
  719. while (groupedBySemesterIterator.hasNext()) {
  720. Map.Entry<Long, List<TextbookClaimExportQueryVo>> groupedBySemesterEntry = groupedBySemesterIterator.next();
  721. Long key = groupedBySemesterEntry.getKey();
  722. List<TextbookClaimExportQueryVo> value = groupedBySemesterEntry.getValue();
  723. Map<Long, List<TextbookClaimExportQueryVo>> groupedBySemesterByClass = value.stream()
  724. .collect(Collectors.groupingBy(TextbookClaimExportQueryVo::getClassId));
  725. Iterator<Map.Entry<Long, List<TextbookClaimExportQueryVo>>> groupedBySemesterByClassIdIterator = groupedBySemesterByClass.entrySet().iterator();
  726. while (groupedBySemesterByClassIdIterator.hasNext()) {
  727. Map.Entry<Long, List<TextbookClaimExportQueryVo>> groupedBySemesterByClassIdEntry = groupedBySemesterByClassIdIterator.next();
  728. Long k = groupedBySemesterByClassIdEntry.getKey();
  729. List<TextbookClaimExportQueryVo> v = groupedBySemesterByClassIdEntry.getValue();
  730. //这是一个table的表头
  731. List<List<String>> tableHeadList = new ArrayList<List<String>>();
  732. tableHeadList.add(new ArrayList<String>() {{
  733. add("日期:" + v.get(0).getBaseSemesterIdCn() + " 班级:" + v.get(0).getClassIdCn() + " 班主任:" + v.get(0).getHeadTeacherName() + " 教室:" + v.get(0).getClassRoomName() + " ");
  734. }});
  735. //table的表头合并策略
  736. ExcelFillCellMergePrevColUtil tableHeadColumn = new ExcelFillCellMergePrevColUtil();
  737. tableHeadColumn.add(++rowIndex, 0, 9);
  738. //这是一个table表头的table
  739. WriteTable writeTableHeadTable = EasyExcel.writerTable(++tableIndex).needHead(Boolean.TRUE).head(tableHeadList).registerWriteHandler(tableHeadColumn).build();
  740. excelWriter.write(new ArrayList<>(), writeSheet, writeTableHeadTable);
  741. Map<String, List<TextbookClaimExportQueryVo>> groupedByTextbookType = v.stream()
  742. .collect(Collectors.groupingBy(TextbookClaimExportQueryVo::getTextbookTypeCn));
  743. Iterator<Map.Entry<String, List<TextbookClaimExportQueryVo>>> groupedByTextbookTypeIterator = groupedByTextbookType.entrySet().iterator();
  744. int index = 1;
  745. BigDecimal total = new BigDecimal("0");
  746. while (groupedByTextbookTypeIterator.hasNext()) {
  747. Map.Entry<String, List<TextbookClaimExportQueryVo>> groupedByTextbookTypeEntry = groupedByTextbookTypeIterator.next();
  748. String kk = groupedByTextbookTypeEntry.getKey();
  749. List<TextbookClaimExportQueryVo> vv = groupedByTextbookTypeEntry.getValue();
  750. if (index == 1) {
  751. //添加小计
  752. ExcelFillCellMergePrevColUtil subtotalColumn = new ExcelFillCellMergePrevColUtil();
  753. subtotalColumn.add(rowIndex + vv.size() + 2, 1, 4);
  754. BigDecimal subtotal = new BigDecimal("0");
  755. for (TextbookClaimExportQueryVo tv : vv) {
  756. subtotal = subtotal.add(tv.getSubtotal() == null ? new BigDecimal("0") : tv.getSubtotal());
  757. }
  758. BigDecimal finalSubtotal = subtotal;
  759. vv.add(new TextbookClaimExportQueryVo() {{
  760. setTextbookTypeCn(vv.get(0).getTextbookTypeCn());
  761. setBookName("小计");
  762. setSubtotal(finalSubtotal);
  763. }});
  764. total = total.add(finalSubtotal);
  765. // 调用合并单元格工具类,此工具类是根据工程名称相同则合并后面数据
  766. int mergeRowIndex = rowIndex + 1;
  767. int[] mergeColumeIndex = {0};
  768. ExcelMergeUtil excelFillCellMergeStrategy = new ExcelMergeUtil(mergeRowIndex, mergeColumeIndex);
  769. // 第一次必须指定需要头,table 会继承sheet的配置,sheet配置了不需要,table 默认也是不需要
  770. WriteTable writeContentTable = EasyExcel.writerTable(++tableIndex).needHead(Boolean.TRUE).registerWriteHandler(subtotalColumn).registerWriteHandler(excelFillCellMergeStrategy).build();
  771. // 第一次写入会创建头
  772. excelWriter.write(vv, writeSheet, writeContentTable);
  773. rowIndex += (1 + vv.size());
  774. } else {
  775. //添加小计
  776. ExcelFillCellMergePrevColUtil subtotalColumn = new ExcelFillCellMergePrevColUtil();
  777. subtotalColumn.add(rowIndex + vv.size() + 1, 1, 4);
  778. BigDecimal subtotal = new BigDecimal("0");
  779. for (TextbookClaimExportQueryVo tv : vv) {
  780. subtotal = subtotal.add(tv.getSubtotal());
  781. }
  782. BigDecimal finalSubtotal = subtotal;
  783. vv.add(new TextbookClaimExportQueryVo() {{
  784. setTextbookTypeCn(vv.get(0).getTextbookTypeCn());
  785. setBookName("小计");
  786. setSubtotal(finalSubtotal);
  787. }});
  788. total = total.add(finalSubtotal);
  789. // 调用合并单元格工具类,此工具类是根据工程名称相同则合并后面数据
  790. int mergeRowIndex = rowIndex;
  791. int[] mergeColumeIndex = {0};
  792. ExcelMergeUtil excelFillCellMergeStrategy = new ExcelMergeUtil(mergeRowIndex, mergeColumeIndex);
  793. // 不需要头
  794. WriteTable writeContentTable = EasyExcel.writerTable(++tableIndex).needHead(Boolean.FALSE).registerWriteHandler(subtotalColumn).registerWriteHandler(excelFillCellMergeStrategy).build();
  795. excelWriter.write(vv, writeSheet, writeContentTable);
  796. rowIndex += (vv.size());
  797. }
  798. index++;
  799. }
  800. //添加合计
  801. BigDecimal finalTotal = total;
  802. List<TextbookClaimExportQueryVo> totalList = new ArrayList<>();
  803. totalList.add(new TextbookClaimExportQueryVo() {{
  804. setTextbookTypeCn("合计");
  805. setSubtotal(finalTotal);
  806. }});
  807. //-合并策略
  808. ExcelFillCellMergePrevColUtil totaColumn = new ExcelFillCellMergePrevColUtil();
  809. totaColumn.add(++rowIndex, 0, 5);
  810. //这是一个合计的table
  811. WriteTable writeTotalTable = EasyExcel.writerTable(++tableIndex).needHead(Boolean.FALSE).registerWriteHandler(totaColumn).build();
  812. excelWriter.write(totalList, writeSheet, writeTotalTable);
  813. }
  814. }
  815. }
  816. return bot;
  817. }
  818. @Override
  819. @Transactional
  820. public Boolean excelImport(InputStream inputStream) {
  821. EasyExcel.read(inputStream, TextbookImportDto.class, new PageReadListener<TextbookImportDto>(dataList -> {
  822. if (dataList.isEmpty()) {
  823. throw new MyException("导入数据为空");
  824. }
  825. saveData(dataList);
  826. })).sheet().headRowNumber(3).doRead();
  827. return true;
  828. }
  829. @Override
  830. public IPage<TextbookSubscriptionListVo> getSubscriptionPageByClass(TextbookSubscriptionListDto dto) {
  831. List<String> classIdList = new ArrayList<>();
  832. if(dto.getClassIds() != null && !"".equals(dto.getClassIds())){
  833. String[] classIdArr = dto.getClassIds().split(",");
  834. classIdList = Arrays.asList(classIdArr);
  835. }
  836. dto.setClassIdList(classIdList);
  837. IPage<TextbookSubscriptionListVo> page = this.baseMapper.getSubscriptionPageByClass(new Page<>(dto.getLimit(), dto.getSize()), dto);
  838. // 处理每本教材使用的人数
  839. if(!classIdList.isEmpty()) {
  840. for(TextbookSubscriptionListVo t : page.getRecords()){
  841. MPJLambdaWrapper<BaseClassCourse> baseClassCourseMPJLambdaWrapper = new MPJLambdaWrapper<>();
  842. baseClassCourseMPJLambdaWrapper
  843. .innerJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getClassId, BaseClassCourse::getClassId)
  844. .in(BaseClassCourse::getClassId, classIdList)
  845. .eq(BaseClassCourse::getTextbookId, t.getId())
  846. .eq(BaseClassCourse::getBaseSemesterId, dto.getBaseSemesterId())
  847. .eq(BaseStudentSchoolRoll::getArchivesStatus, ArchivesStatusEnum.FB2901.getCode())
  848. ;
  849. Long num = baseClassCourseMapper.selectCount(baseClassCourseMPJLambdaWrapper);
  850. t.setStudentSubscriptionNumber(num.intValue());
  851. t.setClassIds(dto.getClassIds());
  852. if(t.getTextbookType() != null && !t.getTextbookType().isEmpty()){
  853. t.setTextbookTypeCn(TextbookTypeEnum.getValue(t.getTextbookType()));
  854. }
  855. }
  856. }
  857. return page;
  858. }
  859. private void saveData(List<TextbookImportDto> dataList) {
  860. //查询所有需要的数据
  861. //学科组
  862. List<SubjectGroup> subjectGroupList = subjectGroupMapper.selectList(new LambdaQueryWrapper<>());
  863. Map<String, Long> subjectGroupNameAndIdMap = subjectGroupList.stream().collect(Collectors.toMap(SubjectGroup::getGroupName, SubjectGroup::getId, (k1, k2) -> k1));
  864. //使用课程
  865. List<BaseCourseSubject> baseCourseSubjectList = baseCourseSubjectMapper.selectList(new LambdaQueryWrapper<>());
  866. Map<String, Long> baseCourseSubjectNameAndIdMap = baseCourseSubjectList.stream().collect(Collectors.toMap(BaseCourseSubject::getName, BaseCourseSubject::getId, (k1, k2) -> k1));
  867. //批量插入或更新数据
  868. for (TextbookImportDto textbookImportDto : dataList) {
  869. TextbookCoreAttribute textbookCoreAttribute = new TextbookCoreAttribute();
  870. BeanUtils.copyProperties(textbookImportDto, textbookCoreAttribute);
  871. Textbook textbook = new Textbook();
  872. BeanUtils.copyProperties(textbookImportDto, textbook);
  873. // 处理学科组映射
  874. String groupName = textbookImportDto.getGroupName();
  875. Long subjectGroupId = Optional.ofNullable(groupName)
  876. .map(subjectGroupNameAndIdMap::get)
  877. .orElse(null);
  878. textbook.setSubjectGroupId(subjectGroupId);
  879. // 处理课程映射
  880. String courseName = textbookImportDto.getCourseName();
  881. Long courseSubjectId = Optional.ofNullable(courseName)
  882. .map(baseCourseSubjectNameAndIdMap::get)
  883. .orElse(null);
  884. textbook.setCourseSubjectId(courseSubjectId);
  885. // 处理是否教材计划字段
  886. String isTextbookPlanCn = textbookImportDto.getIsTextbookPlanCn();
  887. String isTextbookPlan = Optional.ofNullable(isTextbookPlanCn)
  888. .filter("是"::equals)
  889. .map(s -> "yes")
  890. .orElse("no");
  891. textbook.setIsTextbookPlan(isTextbookPlan);
  892. String isSecd = textbookImportDto.getIsSecd();
  893. Integer isSecdI = Optional.ofNullable(isSecd)
  894. .filter("是"::equals)
  895. .map(s -> 1)
  896. .orElse(0);
  897. textbook.setIsSecd(isSecdI);
  898. // 处理教材类型映射
  899. String textbookTypeCn = textbookImportDto.getTextbookTypeCn();
  900. String textbookTypeCode = Optional.ofNullable(textbookTypeCn)
  901. .map(TextbookTypeEnum::getCode)
  902. .orElse(null);
  903. textbook.setTextbookType(textbookTypeCode);
  904. //处理使用类型
  905. textbook.setUseType(UseSemesterTypeEnum.getCode(textbookImportDto.getUseTypeCn()));
  906. Double discount = 1d;
  907. if(textbook.getDiscount() != null){
  908. discount = textbook.getDiscount();
  909. }
  910. //处理小计
  911. textbook.setSubtotal(textbook.getPrice().multiply(BigDecimal.valueOf(discount / 10)));
  912. // 判断导入的教材是否已经存在,根据教材的 ISBN 码和使用的学期判断
  913. LambdaQueryWrapper<Textbook> textbookLambdaQueryWrapper = new LambdaQueryWrapper<>();
  914. textbookLambdaQueryWrapper
  915. .eq(Textbook::getIssn, textbook.getIssn())
  916. ;
  917. Textbook oldTextbook = this.getOne(textbookLambdaQueryWrapper);
  918. Date now = new Date();
  919. Long loginId = StpUtil.getLoginIdAsLong();
  920. // 已经存在,更新数据
  921. if (oldTextbook != null) {
  922. // 更新教材数据
  923. textbookCoreAttribute.setId(oldTextbook.getTextbookCoreAttributeId());
  924. textbookCoreAttribute.setModifyDate(now);
  925. textbookCoreAttribute.setModifyUserId(loginId);
  926. textbookCoreAttributeService.updateById(textbookCoreAttribute);
  927. textbook.setId(oldTextbook.getId());
  928. textbook.setModifyDate(now);
  929. textbook.setModifyUserId(loginId);
  930. textbookTextbookMapper.updateById(textbook);
  931. } else {
  932. textbookCoreAttribute.setCreateDate(now);
  933. textbookCoreAttribute.setCreateUserId(loginId);
  934. textbookCoreAttributeService.save(textbookCoreAttribute);
  935. // 插入教材数据
  936. textbook.setCreateDate(now);
  937. textbook.setCreateUserId(loginId);
  938. textbook.setTextbookCoreAttributeId(textbookCoreAttribute.getId());
  939. textbookTextbookMapper.insert(textbook);
  940. }
  941. }
  942. }
  943. @Override
  944. @Transactional
  945. public Boolean deliverWarehouse(AddTextbookWarehouseRecordDto dto) {
  946. //根据id获取教材管理记录
  947. Textbook textbook = this.getById(dto.getTextbookId());
  948. if (ObjectUtil.isNull(textbook)) {
  949. throw new MyException("入库失败,该教材不存在");
  950. }
  951. // BigDecimal price = ObjectUtil.isNull(dto.getPrice()) ? new BigDecimal(0) : dto.getPrice();
  952. // double discount = ObjectUtil.isNull(dto.getDiscount()) ? 10 : dto.getDiscount();
  953. // BigDecimal subtotal = price.multiply(new BigDecimal(discount / 10));
  954. //更新总的库存数量
  955. this.updateById(new Textbook() {
  956. {
  957. setId(textbook.getId());
  958. Integer oldStock = ObjectUtil.isNull(textbook.getStock()) ? 0 : textbook.getStock();
  959. setStock(oldStock + (ObjectUtil.isNull(dto.getWarehouseNumber()) ? 0 : dto.getWarehouseNumber()));
  960. // setPrice(price);
  961. // setDiscount(discount);
  962. // setSubtotal(subtotal);
  963. setModifyDate(new Date());
  964. }
  965. });
  966. //添加入库记录
  967. TextbookWarehouseRecord textbookWarehouseRecord = BeanUtil.toBean(dto, TextbookWarehouseRecord.class);
  968. textbookWarehouseRecord.setWarehouseMode(WarehouseModeEnum.WmManual.getCode());
  969. textbookWarehouseRecord.setDiscount(textbook.getDiscount());
  970. textbookWarehouseRecord.setSubtotal(textbook.getSubtotal());
  971. textbookWarehouseRecord.setCreateDate(new Date());
  972. QueryWrapper<TextbookWarehouseRecord> queryWrapperSortcode = new QueryWrapper<>();
  973. queryWrapperSortcode.select("IFNULL(MAX(sort_code),0) as sortCode");
  974. TextbookWarehouseRecord t = textbookClassWarehouseService.getOne(queryWrapperSortcode);
  975. textbookWarehouseRecord.setSortCode(t.getSortCode() + 1);
  976. textbookClassWarehouseService.save(textbookWarehouseRecord);
  977. return true;
  978. }
  979. }