package com.qxueyou.scc.school.service.impl; import java.awt.Color; import java.awt.Graphics2D; import java.awt.Transparency; import java.awt.geom.AffineTransform; import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.math.BigDecimal; import java.security.GeneralSecurityException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import javax.imageio.ImageIO; import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.poi.hslf.HSLFSlideShow; import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException; import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; import org.apache.poi.poifs.crypt.Decryptor; import org.apache.poi.poifs.crypt.EncryptionInfo; import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem; //import org.jpedal.examples.images.ConvertPagesToImages; //import org.jpedal.exception.PdfException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.stereotype.Service; import com.qxueyou.scc.admin.classes.model.ClsClass; import com.qxueyou.scc.base.dao.CommonDAO; import com.qxueyou.scc.base.model.Pager; import com.qxueyou.scc.base.model.Result; import com.qxueyou.scc.base.model.UserInfoWrapper; import com.qxueyou.scc.base.service.IFileUploadService; import com.qxueyou.scc.base.service.impl.CommonAppService; import com.qxueyou.scc.base.util.ClientUtils; import com.qxueyou.scc.base.util.CollectionUtils; import com.qxueyou.scc.base.util.JacobUtil; import com.qxueyou.scc.base.util.TraceUtils; import com.qxueyou.scc.base.util.UUIDUtils; import com.qxueyou.scc.config.AliOnsConfig; import com.qxueyou.scc.config.SccConfig; import com.qxueyou.scc.org.model.OrgText; import com.qxueyou.scc.org.service.IOrgTextService; import com.qxueyou.scc.school.dao.HandoutDAO; import com.qxueyou.scc.school.model.SchClassSubject; import com.qxueyou.scc.school.model.SchCourseware; import com.qxueyou.scc.school.model.SchHandout; import com.qxueyou.scc.school.model.SchHandoutPage; import com.qxueyou.scc.school.model.SchHandoutPageFavor; import com.qxueyou.scc.school.model.SchHandoutReCourse; import com.qxueyou.scc.school.model.SchHandoutRecord; import com.qxueyou.scc.school.model.SchHandoutRecordDetail; import com.qxueyou.scc.school.model.SchHandoutStatistic; import com.qxueyou.scc.school.service.ICourseWareService; import com.qxueyou.scc.school.service.IDocdealMsgSenderService; import com.qxueyou.scc.school.service.IHandoutService; import com.qxueyou.scc.sys.model.SysFileUploadTrace; import com.qxueyou.scc.sys.service.IOssService; import com.qxueyou.scc.teach.subject.model.SubjectChapter; import com.qxueyou.scc.user.model.User; import com.qxueyou.scc.user.service.IUserService; import com.jacob.activeX.ActiveXComponent; import com.jacob.com.ComFailException; import com.jacob.com.ComThread; import com.jacob.com.Dispatch; import com.jacob.com.Variant; /** * ½²Òå¹ÜÀí·þÎñ * * @author µÂ»¢ 2015-1-4 * */ @Service @EnableConfigurationProperties({ SccConfig.class, AliOnsConfig.class }) public class HandoutService extends CommonAppService implements IHandoutService { private final Logger log = LogManager.getLogger(HandoutService.class); private static final String HANDOUT_ID = "handoutId"; // @Autowired // CommonONSProducer onsProducer; // @Autowired AliOnsConfig aliOnsConfig; @Autowired SccConfig sccConfig; // @Autowired IOssService ossService; @Autowired IFileUploadService fileUploadService; @Autowired IUserService userService; @Autowired IOrgTextService orgTextService; // /** ¼«¹âÍÆËÍÌæ»»ÐŸë */ // @Autowired // IJPushService jpushService; @Autowired IDocdealMsgSenderService docdealMsgSenderService; private HandoutDAO handoutDAO; // // @Autowired // private ICacheService cacheService; @Autowired private ICourseWareService courseWareService; /** * ÒÀÀµ×¢Èë * * @param handoutDAO */ @Autowired(required = false) public void setHandoutDAO(@Qualifier("handoutDAO") HandoutDAO handoutDAO) { this.handoutDAO = handoutDAO; } /** * PPT\PPTX (officeÎļþ²»Ö±½Ó´¦Àí£¬·¢ËÍÏûÏ¢£¬Ê¹ÓÃÌØ¶¨µÄÎĵµ´¦Àí·þÎñÆ÷´¦Àí) PDFÖ±½Ó´¦Àí * * */ @Override public Result insertHandout(String fullPath, String module, SchHandout handout) { File file = null; try { // È¡µÃµ±Ç°ÉÏ´«ÎļþÀàÐÍ£ºoffice(ppt¡¢pptx)»òÕßpdf,Ö±½ÓÓúó׺ÃûÀ´Åжϸñʽ£¨office»¹ÊÇpdf£© String filePart[] = fullPath.split("\\."); String fileType = filePart[filePart.length - 1]; // 1.ÏÂÔØµ½Ó¦Ó÷þÎñÆ÷±¾µØ String uuid = UUIDUtils.generateUUID(); String filePath = HandoutService.class.getClassLoader().getResource("../uploads").getPath() .concat("handout/" + uuid + "/" + uuid + "." + fileType); file = fileUploadService.doGetOssFile(fullPath, filePath, module, ClientUtils.getUserId()); // ÊÇ·ñÊÇoffice boolean pptFlag = false; if ("PPT".equals(fileType.toUpperCase()) || "PPTX".equals(fileType.toUpperCase())) { // Èç¹ûÓÐÃÜÂ룬·µ»ØÇ°Ì¨Ìáʾ 07+ ÎÞ´ò¿ªÃÜÂëÓÐȨÏÞÃÜÂëÎÞ·¨¼ì²â³öÀ´ if (getDecryptFlag(file, fileType.toUpperCase())) { return new Result(false, "µ¼Èëʧ°Ü£ºÄúÌá½»µÄÎļþÓÐÃÜÂ룬ÇëÉÏ´«Ã»ÓÐÃÜÂëµÄÎļþ£¡"); } pptFlag = true; } TraceUtils.setCreateTrace(handout); handout.setHandoutId(null); handout.setStatus(SchHandout.STATUS_PROCESSING); handout.setClassId(ClientUtils.getClassId()); handout.setPlayCount(0); handout.setFullPath(fullPath); handout.setOrigPath(fullPath); handout.setFullLength((int) (file.length() > 0 ? file.length() / 1024 : 0)); handout.setOrgId(ClientUtils.getOrgId()); this.saveHandout(handout); handout.setOriginHandoutId(handout.getHandoutId()); // ±£´æOrgText ¡ª¡ª ½²ÒåÏêÇé orgTextService.doSaveOrgText(handout.getHandoutId(), OrgText.TABLE_NAME_HANDOUT, handout.getRemark()); // ¸üÐÂÉÏ´«ÎļþʹÓù켣 fileUploadService.updateUploadTrace(fullPath, module, SysFileUploadTrace.FILE_USE, handout.getHandoutId()); // ÐòºÅ String hql = "select MAX(c.orderNum) from SchHandout c where c.deleteFlag is false and c.classId = ? "; Integer iMax = this.findUnique(hql, CollectionUtils.newList(ClientUtils.getClassId()), Integer.class); if (iMax == null || iMax == 0) { iMax = 1; } else { iMax = iMax + 1; } handout.setOrderNum(iMax); this.saveHandout(handout); // ±ê¼Ç°à¼¶Óн²Òå ClsClass cls = read(ClsClass.class, ClientUtils.getClassId()); if (cls != null && cls.getHaveHandout() == ClsClass.NOT_HAVE_HANDOUT) { cls.setHaveHandout(ClsClass.HAVE_HANDOUT); save(cls); } Result result = new Result(true); result.addData("pptFlag", pptFlag); return result; } catch (Exception e) { this.log.error("½²ÒåתÂëʧ°Ü" + fullPath, e); } finally { if (file != null) { // ɾ³ýÏÂÔØµ½Ó¦Ó÷þÎñÆ÷µÄÎĵµ fileUploadService.doDeleteTempOssFile(file.getParentFile(), module, ClientUtils.getUserId()); } } return new Result(false); } /** * תÂëPDF·¢ËÍÏûÏ¢ * * @param handoutId * @param fullPath * @param module * @param userId * @return */ public Result sendMsgConvertPDF(String handoutId, String fullPath, String module, String userId) { // ONSMsg msg = new ONSMsg(onsProducer.getTopic()); // // msg.put("msgType", "CONVERT_PDF"); // msg.put(HANDOUT_ID, handoutId); // msg.put("fullPath", fullPath); // msg.put("module", module); // msg.put("userId", userId); // // try { // // onsProducer.sendMsg(msg); // return new Result(true); // // } catch (Exception e) { // log.error("call handoutService fail.handoutId: " + handoutId, e); // } return new Result(false); } @SuppressWarnings("unused") @Override public void doConvertPDF(String handoutId, String fullPath, String module, String userId) { try { insertHandoutPages(fullPath, handoutId, module, userId, "PDF"); } catch (Exception e) { String businessId = aliOnsConfig.getCommonTopic() + "-" + UUIDUtils.generateUUID(); String desp = "handoutId:" + handoutId + ";fullPath:" + fullPath + ";module:" + module; log.error(businessId + " :תÂëPDF½²Òåʧ°Ü:" + e, e); } } @SuppressWarnings("unused") @Override public void doConvertDOC(String docPath, String handoutId, String uploadModule, String userId) { try { insertHandoutPages(docPath, handoutId, uploadModule, userId, "PPT"); } catch (Exception e) { String desp = "handoutId:" + handoutId + ";docPath:" + docPath + ";uploadModule:" + uploadModule; log.error(handoutId + " :ÉÏ´«½²ÒåpptÏûÏ¢·¢ËÍʧ°Ü:" + e, e); } } /** * docdeal ÏûÏ¢¶ÓÁе÷ÓÃ,½«officeÎļþ´ÓossÏÂÔØµ½web serverÉÏ£¬½âÎö³ÉͼƬ£¬½«½âÎöºóµÄͼƬ´«µ½ossÉÏ * 20150915:Õýʽ»·¾³³öÏÖͬһ¸öppt½âÎöÁËÁ½·Ý£¬(ÏûÏ¢¶ÓÁд¦Àíǰɾ³ýÇ°ÃæÄÚÈÝ£¬ÓÃ×îÐÂÄÚÈÝ,ÕâÑù²Ù×÷£¬ÊղصĽ²Òå¿ÉÄÜ»á³öÏÖÎÊÌâ)£¬ÒÑ´¦Àí¹ý²»´¦Àí * ÐÞ¸Äbug£ºpptºÍjpgµ±Ç°²»ÔÚͬһ¸öĿ¼ÏÂÃæ£¬Ð޸ĵ½Í¬Ò»¸öĿ¼ÏÂÃæ * * @param docPath * @param handoutId * @return */ @SuppressWarnings({ "unchecked", "unused" }) @Override public Result insertHandoutPages(String docPath, String handoutId, String uploadModule, String userId, String type) { log.debug("start...docDealMsgReceiveService call insertHandoutPages success: docPath: " + docPath + " ;handoutId: " + handoutId); File objOfficeFile = null; try { // 0. judge String hql = "from SchHandoutPage s where s.handoutId = ? and s.deleteFlag is false "; int iCount = this.findCount(hql, CollectionUtils.newList(handoutId)); if (iCount > 0) { log.debug("end0...docDealMsgReceiveService call insertHandoutPages already: docPath: " + docPath + " ;handoutId: " + handoutId); return new Result(true); } // 1.download File to local web server String uuid = UUIDUtils.generateUUID(); String filePart[] = docPath.split("\\."); String fileType = filePart[filePart.length - 1]; // String directory = // HandoutService.class.getClassLoader().getResource("../uploads").getPath().concat("/handout/" // + uuid + "/" + "downLoadOfficeFile" + // docPath.substring(docPath.lastIndexOf('.'))); // File file = new // File(HandoutService.class.getClassLoader().getResource("../uploads").getPath().concat("/handout/" // + uuid)); // objOfficeFile = fileUploadService.doGetOssFile(docPath, "/temp/uploads/handout/" + UUIDUtils.generateUUID() + "/" + fileType + "." + fileType, uploadModule, ClientUtils.getUserId()); // // file.mkdirs(); // objOfficeFile = fileUploadService.doGetOssFile(docPath, directory, // uploadModule, userId); // 2.deal doc // ʹÓÃз½Ê½½âÎö½²Òå,ÓиöȱÏÝ£ºÉÏ´«img¼°Êý¾Ý¿âÖÐhandoutpageĬÈÏÅÅÐò(15Ò³pptΪÀý)£º1,10,11,12,13£¬14,15,2,3,4,5,6,7,8,9 List lstPages = Collections.EMPTY_LIST; if ("PPT".equals(type)) { lstPages = this.convertPPTToJPG(objOfficeFile, docPath, handoutId); } if ("PDF".equals(type)) { lstPages = this.convertPDFToPNG(objOfficeFile, docPath, handoutId); } // 3.insert pages if (lstPages.isEmpty()) { log.error("ת»»pptΪ¿Õ:" + handoutId + "-" + docPath + "-" + userId + "-" + uploadModule); // 4.modify handout status and pageCount SchHandout objHandout = this.read(SchHandout.class, handoutId); // jgw £¬Ö±½ÓÐÞ¸ÄΪ·¢²¼ objHandout.setStatus(SchHandout.STATUS_FAILURE); this.saveHandout(objHandout); return new Result(false, "office½²Òåת»»Ê§°Ü"); } for (SchHandoutPage page : lstPages) { page.setHandoutId(handoutId); } saveOrUpdateAll(lstPages); // 4.modify handout status and pageCount SchHandout objHandout = this.read(SchHandout.class, handoutId); objHandout.setPageCount(lstPages.size()); // jgw £¬Ö±½ÓÐÞ¸ÄΪ·¢²¼ objHandout.setStatus(SchHandout.STATUS_ISSUED); // Èç¹ûÊ×ҳͼƬΪnull ²¢ÇÒ lstPages²»Îª¿Õ if (StringUtils.isBlank(objHandout.getCoverPageUrl())) { objHandout.setCoverPageUrl(lstPages.get(0).getImgPath()); } this.saveHandout(objHandout); // Èç¹ûÊǹÜÀíÔ±ÉÏ´«£¬´¦ÀíÖ¸¶¨µ½±ð´¦µÄÊý¾Ý doInitClassHandout(objHandout, lstPages); log.debug("end1...docDealMsgReceiveService call insertHandoutPages success: docPath: " + docPath + " ;handoutId: " + handoutId); } catch (Exception e) { log.error("µ÷ÓÃdocdeal·þÎñÆ÷½âÎöpptʧ°Ü£¬Ê§°ÜÔ­Òò£º" + handoutId, e); SchHandout objHandout = this.read(SchHandout.class, handoutId); if (null != objHandout) { objHandout.setStatus(SchHandout.STATUS_FAILURE); this.saveHandout(objHandout); } // throw e; } finally { if (null != objOfficeFile) { fileUploadService.doDeleteTempOssFile(objOfficeFile.getParentFile(), uploadModule, userId); } } return new Result(true); } /** * PPT\PPTX (officeÎļþ²»Ö±½Ó´¦Àí£¬·¢ËÍÏûÏ¢£¬Ê¹ÓÃÌØ¶¨µÄÎĵµ´¦Àí·þÎñÆ÷´¦Àí) PDFÖ±½Ó´¦Àí * * */ @SuppressWarnings("unused") @Override public Result insertOrgHandout(String fullPath, String module, SchHandout handout, String collegeCourseId) { File file = null; try { // È¡µÃµ±Ç°ÉÏ´«ÎļþÀàÐÍ£ºoffice(ppt¡¢pptx)»òÕßpdf,Ö±½ÓÓúó׺ÃûÀ´Åжϸñʽ£¨office»¹ÊÇpdf£© String filePart[] = fullPath.split("\\."); String fileType = filePart[filePart.length - 1]; String rootPath = sccConfig.getResRootPath(); String outputPath = rootPath.concat(filePart[0].substring(1, filePart[0].length())); // 1.ÏÂÔØµ½Ó¦Ó÷þÎñÆ÷±¾µØ file = fileUploadService.doGetOssFile(fullPath, "/temp/uploads/handout/" + UUIDUtils.generateUUID() + "/" + fileType + "." + fileType, module, ClientUtils.getUserId()); // ÊÇ·ñÊÇoffice boolean pptFlag = false; if ("PPT".equals(fileType.toUpperCase()) || "PPTX".equals(fileType.toUpperCase())) { // Èç¹ûÓÐÃÜÂ룬·µ»ØÇ°Ì¨Ìáʾ 07+ ÎÞ´ò¿ªÃÜÂëÓÐȨÏÞÃÜÂëÎÞ·¨¼ì²â³öÀ´ if (getDecryptFlag(file, fileType.toUpperCase())) { return new Result(false, "µ¼Èëʧ°Ü£ºÄúÌá½»µÄÎļþÓÐÃÜÂ룬ÇëÉÏ´«Ã»ÓÐÃÜÂëµÄÎļþ£¡"); } pptFlag = true; } if (!"PDF".equals(fileType.toUpperCase())) { /* * docConverterUtil dcu=new docConverterUtil(file.getPath()); * dcu.setOutputPath(outputPath); dcu.conver(); fullPath=filePart[0]+".pdf"; */ JacobUtil.formatConvert(fileType, rootPath.concat(fullPath.substring(1, fullPath.length()))); fullPath = filePart[0] + ".pdf"; } TraceUtils.setCreateTrace(handout); handout.setPlayCount(0); handout.setStatus(SchHandout.STATUS_PROCESSING); handout.setClassId(ClientUtils.getClassId()); handout.setFullPath(fullPath); handout.setFullLength((int) (file.length() > 0 ? file.length() / 1024 : 0)); handout.setOrgId(ClientUtils.getOrgId()); this.saveHandout(handout); handout.setOriginHandoutId(handout.getHandoutId()); this.saveHandout(handout); // ±£´æOrgText ¡ª¡ª ½²ÒåÏêÇé orgTextService.doSaveOrgText(handout.getHandoutId(), OrgText.TABLE_NAME_HANDOUT, handout.getRemark()); // ¸üÐÂÉÏ´«ÎļþʹÓù켣 fileUploadService.updateUploadTrace(fullPath, module, SysFileUploadTrace.FILE_USE, handout.getHandoutId()); // ½²ÒåºÍ¿ÆÄ¿¹ØÁª this.insertReCourse(collegeCourseId, handout.getHandoutId()); // ɾ³ýpdf pptÔ­Îļþ£¬ÒÑÉÏ´«ÖÁ°¢ÀïÓë·þÎñÆ÷ // FileUtils.deleteQuietly(file); // insertAppointSelfOrg(handout.getHandoutId(),ClientUtils.getOrgId(),collegeCourseId); Result result = new Result(true); result.addData("pptFlag", pptFlag); return result; } catch (Exception e) { this.log.error("½²ÒåתÂëʧ°Ü" + fullPath, e); } finally { if (file != null) { // ɾ³ýÏÂÔØµ½Ó¦Ó÷þÎñÆ÷µÄÎĵµ fileUploadService.doDeleteTempOssFile(file.getParentFile(), module, ClientUtils.getUserId()); } } return new Result(false); } /** * ±à¼­½²Òå */ public Result doEditHandout(SchHandout newhandout, String type) { SchHandout handout = read(SchHandout.class, newhandout.getHandoutId()); handout.setName(newhandout.getName()); // handout.setSubjectId(newhandout.getSubjectId()); // handout.setSubjectName(newhandout.getSubjectName()); handout.setRemark(newhandout.getRemark()); if (StringUtils.isNotBlank(newhandout.getCoverPageUrl())) { handout.setCoverPageUrl(newhandout.getCoverPageUrl()); } TraceUtils.setUpdateTrace(handout); this.saveHandout(handout); // ±£´æOrgText ¡ª¡ª ½²ÒåÏêÇé orgTextService.doSaveOrgText(handout.getHandoutId(), OrgText.TABLE_NAME_HANDOUT, newhandout.getRemark()); // ¸üÐÂͳ¼Æ±í½²ÒåÃû×Ö updateHandoutStatisticName(handout.getHandoutId(), handout.getName()); /* * if ("class".equals(type)) { return new Result(true); } String hql = * " from SchHandout where handoutId != ? and originHandoutId = ?"; * List lstHandout = find(hql, * CollectionUtils.newList(handout.getHandoutId(), handout.getHandoutId()), * SchHandout.class); List classIds = new ArrayList(); * List origSubjectIds = new ArrayList(); List * handoutIds = new ArrayList(); for (SchHandout schHandout : * lstHandout) { classIds.add(schHandout.getClassId()); * origSubjectIds.add(schHandout.getSubjectId()); * handoutIds.add(schHandout.getHandoutId()); } */ /* * if (classIds.isEmpty() || origSubjectIds.isEmpty()) { return new * Result(true); } hql = * " from SchClassSubject where deleteFlag is false and classId in (:classIds) and origSubjectId in (:origSubjectIds)" * ; Map args = new HashMap(); * args.put("classIds", classIds.toArray()); args.put("origSubjectIds", * origSubjectIds.toArray()); List lstSubject = * findByComplexHql(hql, args, SchClassSubject.class); Map map = new HashMap(); for * (SchClassSubject schClassSubject : lstSubject) { * map.put(schClassSubject.getClassId() + schClassSubject.getOrigSubjectId(), * schClassSubject); } for (SchHandout schHandout : lstHandout) { * * SchClassSubject scs = map.get(schHandout.getClassId() + * schHandout.getSubjectId()); if (scs == null) { continue; } * TraceUtils.setUpdateTrace(schHandout); schHandout.setName(handout.getName()); * schHandout.setSubjectId(scs.getClassSubjectId()); * schHandout.setSubjectName(scs.getName()); this.saveHandout(schHandout); } * * // ±£´æOrgText ¡ª¡ª ½²ÒåÏêÇé orgTextService.doSaveOrgTexts(handoutIds, * OrgText.TABLE_NAME_HANDOUT, newhandout.getRemark()); */ return new Result(true); } /** * ¸üÐÂͳ¼Æ±í½²ÒåÃû×Ö * * @param handoutId * @param handoutName */ private void updateHandoutStatisticName(String handoutId, String handoutName) { String hql = " from SchHandoutStatistic where handoutId = ? and deleteFlag is false"; List handoutStatistics = find(hql, CollectionUtils.newList(handoutId), SchHandoutStatistic.class); for (SchHandoutStatistic schHandoutStatistic : handoutStatistics) { schHandoutStatistic.setHandoutName(handoutName); TraceUtils.setUpdateTrace(schHandoutStatistic); save(schHandoutStatistic); } } /** * µÃµ½office ÎĵµÊÇ·ñÓÐÃÜÂë * * @param file * @param fileType * @return */ private boolean getDecryptFlag(File file, String fileType) { if ("PPT".equals(fileType.toUpperCase())) { return getPPTDecryptFlag(file); } else if ("PPTX".equals(fileType.toUpperCase())) { return getPPTXDecryptFlag(file); } return false; } /** * ppt ¼ì²âÊÇ·ñ°üº¬ÃÜÂë * * @param file * @return */ @SuppressWarnings("unused") private boolean getPPTDecryptFlag(File file) { boolean flag = false; Biff8EncryptionKey.setCurrentUserPassword(null); NPOIFSFileSystem fs = null; try { fs = new NPOIFSFileSystem(file, true); HSLFSlideShow hss = new HSLFSlideShow(fs); IOUtils.closeQuietly(fs); } catch (IOException e) { log.error("PPT: getPPTDecryptFlag IOException £º" + e); } catch (EncryptedPowerPointFileException e) { if ("The CurrentUserAtom specifies that the document is encrypted".equals(e.getMessage()) || "Encrypted PowerPoint files are not supported".equals(e.getMessage())) { flag = true; } } catch (Exception e) { log.error("PPT: getPPTDecryptFlag Exception £º" + e); } return flag; } /** * pptx ¼ì²âÊÇ·ñÓÐÃÜÂ룬07+ ÎÞ´ò¿ªÎļþÃÜÂ룬Óб༭ÃÜÂ룬ÔÝʱÅжϲ»³öÀ´ * * @param file * @return */ private boolean getPPTXDecryptFlag(File file) { boolean flag = false; InputStream in = null; POIFSFileSystem fs = null; EncryptionInfo encInfo = null; try { in = new FileInputStream(file); fs = new POIFSFileSystem(in); encInfo = new EncryptionInfo(fs); if (null != encInfo) { Decryptor dec = Decryptor.getInstance(encInfo); if (!dec.verifyPassword(null)) { flag = true; } } } catch (FileNotFoundException e) { log.error("getPPTXDecryptFlag()_»ñÈ¡InputStream Òì³££º" + e); } catch (IOException e) { log.error("getPPTXDecryptFlag()_»ñÈ¡POIFSFileSystem Òì³££º" + e); } catch (NullPointerException e) { log.error("getPPTXDecryptFlag()_»ñÈ¡EncryptionInfo,07+ Òì³££º" + e); } catch (GeneralSecurityException e) { log.error("getPPTXDecryptFlag()_»ñÈ¡verifyPassword Òì³££º" + e); } catch (Exception e) { log.error("PPTX: getPPTXDecryptFlag Exception £º" + e); } return flag; } /** * ʹÓÃjacobÁí´æÎªÍ¼Æ¬,ÐèÒª²âÊÔ¶à¸öÇëÇóͬʱµ÷ÓÃÇé¿ö 1.office2013±¨´í£¬µ«ÊÇÓÃoffice2013Áí´æžéЧ¹û×îºÃ * 2.office2007½âÎö²»ÍêÃÀ£¬×ÖÌ寫´Ö£¬±ßÉÏÓнÏÃ÷ÏÔ¾â³Ý,¿ÉÒÔÓÃjacobÕ{Óà * 3.office2010½âÎö»ù±¾Õý³££¬µ«ÊǽÏÓÚoffice2013£¬´ó×ÖÌåºÍ±ß¿ò»áÓзdz£ÉÙÁ¿¾â³Ý£¨ÍƼöʹÓã© * * info£º·þÎñÆ÷ÍÆ¼öʹÓÃoffice2010£¬jacob.jar°ü¸üкóÈç¹ûÖ§³Öoffice2013£¬²âÊÔÄĸö°æ±¾»áЧ¹û¸üºÃ£¬¿ÉÒÔÌæ»»·þÎñÆ÷office°æ±¾ * * @param file * pptÎļþ * @param docPath * oss ´æ·ÅofficeÎļþµÄ·¾¶ * @return */ @Override public List convertPPTToJPG(File file, String docPath, String handoutId) { ActiveXComponent application = null; Dispatch ppt = null; List results = new ArrayList(30); try { if (!file.exists()) { throw new Exception("Îļþ²»´æÔÚ!"); } // »ñÈ¡Áí´æÎªÍ¼Æ¬Ê±µÄÎļþ File imgFile = getHandoutImgPath(file.getParentFile().getPath()); log.debug("ÏûÏ¢µ÷ÓÃJACOB½âÎöppt³É¹¦£¬½øÈë½âÎö·½·¨£¬¿ªÊ¼³õʼ»¯JACOB×é¼þ£¡"); ComThread.InitSTA(); log.debug("¿ªÊ¼³õʼ»¯JACOB×é¼þ£¬ComThread.InitSTA()µ÷Óóɹ¦£¡"); application = new ActiveXComponent("PowerPoint.Application"); // ĬÈϲ»¿É¼û£¬µ«ÊÇ´óÎļþÁí´æÎªÊ±£¬»á³öÏÖ¡°ESC¿ÉÈ¡Ïû±£´æ¡±µÄ½ø¶È¿ò,ÔÝʱ²»ÖªµÀÈçºÎ²»ÏÔʾ½ø¶ÈÌõ // Dispatch.put(application, "Visible", new Variant(true)); // ´ò¿ªÒ»¸öÏÖÓÐµÄ Presentation ¶ÔÏó Dispatch ppts = application.getProperty("Presentations").toDispatch(); ppt = Dispatch.call(ppts, "Open", file.getPath(), true, // ReadOnly false, // UntitledÖ¸¶¨ÎļþÊÇ·ñÓбêÌâ false// WithWindowÖ¸¶¨ÎļþÊÇ·ñ¿É¼û ).toDispatch(); // Áí´æÎªÍ¼Æ¬ £¨17£©£ºÍ¼Æ¬ÀàÐÍ // ½«web·þÎñÆ÷ÖеÄpptÁí´æÎªÍ¼Æ¬£¬µ÷ÓÃpptµÄÁí´æÎª·½·¨£¬Í¼Æ¬¸ñʽΪ£¨»ÃµÆÆ¬1.JPG,»ÃµÆÆ¬2.JPG...£© Dispatch.call(ppt, "SaveAs", imgFile.getPath(), new Variant(17)); // ÉÏ´«Í¼Æ¬µ½oss·þÎñÆ÷²¢×¼±¸ÐèÒª±£´æµ½Êý¾Ý¿âµÄhandoutpageÊý¾Ý results = uploadImgPrepareData(imgFile, docPath, handoutId); } catch (ComFailException e) { log.error("ComFailException½âÎö±£´æpptÒì³££º" + e, e); } catch (Exception e) { log.error("Exception½âÎö±£´æpptÒì³££º" + e, e); } finally { if (ppt != null) { Dispatch.call(ppt, "Close"); } if (application != null) { application.invoke("Quit"); } ComThread.Release(); ComThread.quitMainSTA(); } return results; } /** * ´´½¨Áí´æÎªÍ¼Æ¬Îļþ·¾¶,ppt½âÎöµÄͼƬ´æÔÚpptͬ¼¶Ä¿Â¼imageÎļþ¼ÐÏ£¬Ä¬ÈÏÃüÃû·½Ê½Îª£º»ÃµÆÆ¬1.JPG * * @param path * pptÉÏ´«µ½web·þÎñÆ÷µÄ·¾¶ * @return */ private File getHandoutImgPath(String path) { File f = new File(path + "/image"); f.mkdirs(); return f; } /** * ½«½âÎöºóµÄͼƬÉÏ´«µ½oss£¬²¢ÇÒ·µ»ØÐèÒª´æ´¢µ½Êý¾Ý¿âµÄhandoutpageÐÅÏ¢ * @param imgFileDir * @param docPath * @param handoutId * @return * @throws IOException */ @SuppressWarnings({ "unchecked", "unused" }) private List uploadImgPrepareData(File imgFileDir, String docPath, String handoutId) throws IOException { List results = Collections.EMPTY_LIST; try { if (imgFileDir != null && imgFileDir.exists()) { String[] filelist = imgFileDir.list(); // ÅжÏÊÇ·ñÓÐÁí´æÎªµÄͼƬ if (null != filelist && filelist.length > 0) { results = new ArrayList(filelist.length); File imgFile; String startPath = ""; int iPosition = docPath.lastIndexOf('/'); if (iPosition != -1) { startPath = docPath.substring(0, iPosition); } int i = 1; for (String strFile : filelist) { // cacheService.set("handout_upload_schedule_"+handoutId, 60, // i*100f/filelist.length); // Ö±½ÓʹÓÃstrPath¹¹ÔìimgFile£¬»áµ¼Ö»ñÈ¡ÊäÈëÁ÷ʱ£¬±¨´í£¬fileÖ»¸øÎļþÃû£¬Ä¬ÈÏΪ¹¤³ÌĿ¼£¬ºÍsrcͬ¼¶£¬ÓÃȫ·¾¶¹¹Ôì imgFile = new File(imgFileDir.getPath() + "/" + strFile); if (imgFile.getName().indexOf(".") != -1) { // ͼƬÎļþÃû String imgFileName = imgFile.getName().split("\\.")[0]; // ͼƬÎļþÀàÐÍ String imgFileType = imgFile.getName().split("\\.")[1]; if (StringUtils.isNotBlank(imgFileName) && imgFileName.length() > 3) { // prepare image data String ossFileName = imgFileName.substring(3, imgFileName.length()); String destPath = startPath + "/" + ossFileName + "." + imgFileType; // upload data ossService.uplpadImage(imgFile, destPath); // prepare DB data results.add(newHandoutPage(destPath, Integer.parseInt(ossFileName))); } } } } else { log.error("jacob½âÎöʧ°Ü£¬ÎÞÁí´æÎªµÄͼƬ£¬imageÎļþ¼ÐΪ¿Õ£º" + imgFileDir.getPath()); return Collections.EMPTY_LIST; } } else { log.error("jacob½âÎöʧ°Ü£¬Î´Éú³ÉimgFileDirÎļþ¼Ð"); return Collections.EMPTY_LIST; } } finally { FileUtils.deleteDirectory(imgFileDir); } return results; } /** * ʹÓÃjpedalת»»pdfΪͼƬ£¬Ä¬ÈϸñʽΪ1.PNG¡¢2.PNG¡¢3.PNG * * @param * * @return */ @SuppressWarnings("unchecked") private List convertPDFToPNG(File file, String module, String handoutId) { // List results = new ArrayList(30); // // µÃµ½×ª»»¶ÔÏó // ConvertPagesToImages objConvert = new ConvertPagesToImages(file.getPath()); // try { // if (objConvert.openPDFFile()) { // int pageCount = objConvert.getPageCount(); // String webPath = HandoutService.class.getClassLoader().getResource("../../web").getPath(); // // for (int iPage = 1; iPage <= pageCount; iPage++) { // // cacheService.set("handout_upload_schedule_"+handoutId, 60, // // iPage*100f/pageCount); // // µÃµ½½âÎöµÄÿһҳͼƬ // BufferedImage img = objConvert.getPageAsImage(iPage, true); // // // ÅжÏͼƬÊÇ·ñ¸ß´óÓÚ¿í // int width = img.getWidth(); // int height = img.getHeight(); // BufferedImage handlerImg = null; // if (width < height) { // handlerImg = rotatePdfImg(img, 270, null); // } // // // ÉÏ´« // String destPath = "/web/res/img/school/handout/" + file.getParentFile().getName() + "/" + iPage // + ".PNG"; // String directory = webPath + "res/img/school/handout/" + file.getParentFile().getName(); // String path = directory + "/" + iPage + ".PNG"; // // ByteArrayOutputStream baos = new ByteArrayOutputStream(); // ImageIO.write(handlerImg == null ? img : handlerImg, "png", baos); // InputStream is = new ByteArrayInputStream(baos.toByteArray()); // // ossService.uplpadImage(is, "PNG", destPath); // // IOUtils.closeQuietly(baos); // // results.add(newHandoutPage(path, iPage)); // } // } // objConvert.closePDFfile(); // } catch (PdfException e) { // log.error("jpedal½âÎöpdfΪͼƬʧ°Ü£º", e); // return Collections.EMPTY_LIST; // } catch (IOException e) { // log.error("pdf½âÎöΪͼƬʧ°Ü£º", e); // return Collections.EMPTY_LIST; // } finally { // // ɾ³ýÏÂÔØµ½Ó¦Ó÷þÎñÆ÷µÄÎĵµ // fileUploadService.doDeleteTempOssFile(file.getParentFile(), module, ClientUtils.getUserId()); // } return null; } private BufferedImage rotatePdfImg(BufferedImage image, int degree, Color bgcolor) { int degree0 = degree; // ԭʼͼÏóµÄ¿í¸ß int iwidth = image.getWidth(); int iheight = image.getHeight(); // ´¦ÀíµÄ¿í¸ß int width = 0; int height = 0; int positionX = 0; int positionY = 0; degree0 = degree0 % 360; if (degree0 < 0) { degree0 = 360 + degree0; } // ½«½Ç¶ÈתΪ»¡¶È double ang = Math.toRadians(degree0); // È·¶¨ÐýתºóµÄͼÏóµÄ¸ß¶ÈºÍ¿í¶È if (degree0 == 180 || degree0 == 0 || degree0 == 360) { width = iwidth; height = iheight; } else if (degree0 == 90 || degree0 == 270) { width = iheight; height = iwidth; } else { double cosVal = Math.abs(Math.cos(ang)); double sinVal = Math.abs(Math.sin(ang)); width = (int) (sinVal * iheight) + (int) (cosVal * iwidth); height = (int) (sinVal * iwidth) + (int) (cosVal * iheight); } // È·¶¨Ô­µã×ø±ê positionX = (width - iwidth) / 2; positionY = (height - iheight) / 2; BufferedImage rotatedImage = new BufferedImage(width, height, image.getType()); Graphics2D gs = (Graphics2D) rotatedImage.getGraphics(); if (bgcolor == null) { rotatedImage = gs.getDeviceConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT); } else { gs.setColor(bgcolor); gs.fillRect(0, 0, width, height); } AffineTransform at = new AffineTransform(); // ÐýתͼÏó at.rotate(ang, width / 2, height / 2); at.translate(positionX, positionY); AffineTransformOp op = new AffineTransformOp(at, AffineTransformOp.TYPE_BICUBIC); op.filter(image, rotatedImage); return rotatedImage; } /** * ÐÂÔöHandoutPage¶ÔÏó * @param path * @param i * @return */ private SchHandoutPage newHandoutPage(String path, int i) { String path0 = path; SchHandoutPage page = new SchHandoutPage(); path0 = path0.replace('\\', '/'); int startIdx = path0.indexOf("/web/"); path0 = path0.substring(startIdx); page.setImgPath(path0); // ¾É°æ±¾convertPPTToPNG ÕâÀïΪ£¨i + 1£© convertPPTToJPG Ϊi page.setPageOrder(i); TraceUtils.setCreateTrace(page); return page; } /* * (non-Javadoc) * * @see com.qxueyou.scc.school.service.IHandoutService#deleteHandouts(java.lang. * String[]) */ @Override public Result deleteHandouts(String[] handoutIds) { if (handoutIds.length == 0) { return new Result(false, "²ÎÊý´íÎó"); } for (String handoutId : handoutIds) { SchHandout interact = read(SchHandout.class, handoutId); interact.setDeleteFlag(true); TraceUtils.setUpdateTrace(interact); this.saveHandout(interact); } return new Result(true); } @Override public Result deleteOrgHandouts(String[] handoutIds, Integer delAll, String orgIds[], String classIds[]) { for (String handoutId : handoutIds) { if ((orgIds != null && orgIds.length != 0) || (classIds != null && classIds.length != 0)) { // ɾ³ýÐèÒª»Ø³·µÄ½²Òå deleteAppoint(handoutId, orgIds, classIds); } else { // ɾ³ý½²Òå String hql = " from SchHandoutReCourse where handoutId = ? and deleteFlag is false and orgId = ?"; SchHandoutReCourse shr = findUnique(hql, CollectionUtils.newList(handoutId, ClientUtils.getOrgId()), SchHandoutReCourse.class); if (shr != null) { TraceUtils.setUpdateTrace(shr); shr.setDeleteFlag(true); save(shr); this.courseWareService.deleteOrgCourseware(shr.getHandoutId(), shr.getOrgId()); } /* * SchHandout handout = this.read(SchHandout.class, handoutId); if(handout != * null){ TraceUtils.setUpdateTrace(handout); handout.setDeleteFlag(true); * this.saveHandout(handout); } */ // Óû§Ñ¡Ôñͬʱɾ³ýϼ¶½²Òå if (delAll == 1) { deleteSub(handoutId, ClientUtils.getOrgId()); } } } return new Result(true); } @SuppressWarnings("unchecked") private void deleteSub(String handoutId, String currOrgId) { // »ú¹¹²ã¼¶ÊÓÆµÊÇûÓÐÖØÐÂnew £¬²éѯ³ö»ú¹¹Ï¼¶IDÔÙɾ¹ØÁª±í String sql = " select oa.organization_id from organization as oa,organization ob " + " where " + " ob.ORGANIZATION_ID = ? " + " and " + " oa.org_code like CONCAT(ob.org_code,'%' ) " + " and oa.delete_flag is false and ob.delete_flag is false " + " order by oa.level,oa.org_code asc "; List orgIds = this.findBySql(sql, CollectionUtils.newList(currOrgId)); String hql = " from SchHandoutReCourse where handoutId = :handoutId and deleteFlag is false and orgId in (:orgIds)"; Map map = new HashMap(); map.put(HANDOUT_ID, handoutId); map.put("orgIds", orgIds.toArray()); List handoutCourses = findByComplexHql(hql, map, SchHandoutReCourse.class); for (SchHandoutReCourse schHandoutReCourse : handoutCourses) { schHandoutReCourse.setDeleteFlag(true); TraceUtils.setUpdateTrace(schHandoutReCourse); save(schHandoutReCourse); } // °àÖ÷ÈβãÃæÊÓÆµÖ¸¶¨¹ýºó¶¼ÊÇnew ³öÀ´µÄ£¬Í¨¹ýoriginVideoId ¿ÉÒÔ²é³öËùÓÐÖ¸¶¨¹ýÈ¥µÄÊÓÆµ hql = "select classId from ClsClass where orgId in (:orgIds) and deleteFlag is false"; map = new HashMap(); map.put("orgIds", orgIds.toArray()); List clsIds = findByComplexHql(hql, map, String.class); if (!clsIds.isEmpty()) { hql = " from SchHandout where originHandoutId = :handoutId and deleteFlag is false and handoutId!=originHandoutId and classId in (:classIds)"; map = new HashMap(); map.put(HANDOUT_ID, handoutId); map.put("classIds", clsIds.toArray()); List lstHandout = findByComplexHql(hql, map, SchHandout.class); for (SchHandout schHandout : lstHandout) { schHandout.setDeleteFlag(true); TraceUtils.setUpdateTrace(schHandout); this.saveHandout(schHandout); } } } private Result deleteAppoint(String handoutId, String orgIds[], String classIds[]) { Map args = new HashMap(); // ɾ³ýÐèÒª»Ø³·µÄ»ú¹¹½²Òå if (orgIds.length != 0) { String hql = " from SchHandoutReCourse where handoutId = :handoutId and deleteFlag is false and orgId in (:orgIds) and orgId != :currOrgId"; args = new HashMap(); args.put(HANDOUT_ID, handoutId); args.put("orgIds", orgIds); args.put("currOrgId", ClientUtils.getOrgId()); List courses = findByComplexHql(hql, args, SchHandoutReCourse.class); for (SchHandoutReCourse course : courses) { TraceUtils.setUpdateTrace(course); course.setDeleteFlag(true); save(course); this.courseWareService.deleteOrgCourseware(course.getHandoutId(), course.getOrgId()); } } // ɾ³ýÐèÒª»Ø³·µÄ°àÖ÷Èν²Òå if (classIds.length != 0) { args = new HashMap(); args.put(HANDOUT_ID, handoutId); args.put("classIds", classIds); String hql = " from SchHandout where originHandoutId = :handoutId and deleteFlag is false and classId in (:classIds)"; List handouts = findByComplexHql(hql, args, SchHandout.class); for (SchHandout handout : handouts) { TraceUtils.setUpdateTrace(handout); handout.setDeleteFlag(true); this.saveHandout(handout); } } return new Result(true); } /** * »ñÈ¡½²ÒåÁбíÊý¾Ý * * @return */ @Override public List> handoutLst(String tid) { User user = read(User.class, ClientUtils.getUserId()); List handoutLst = null; String hql = ""; List agrs = new ArrayList(); agrs.add(ClientUtils.getClassId()); // 1°àÖ÷ÈΣº»ñÈ¡¸Ã°à¼¶£¨class_id£©ÏÂÃæµÄ½²Ê¦¸ºÔð¿Î³ÌϵĽ²Òå; // 2½²Ê¦£º»ñÈ¡¸Ã½²Ê¦£¨teacher_id£©¸ºÔð¿Î³ÌϵĽ²Òå if (user != null && UserInfoWrapper.ROLE_CHARGER.equals(ClientUtils.getCurrentRole())) { hql = "select h.handoutId,h.name,h.pageCount,h.status,h.subjectId,h.subjectName, h.orderNum, h.remark " + " from SchHandout h " + " where h.deleteFlag is false " + " and h.classId = ?"; } else if (user != null && UserInfoWrapper.ROLE_TEACHER.equals(ClientUtils.getCurrentRole())) { hql = "select h.handoutId,h.name,h.pageCount,h.status,h.subjectId,h.subjectName,h.orderNum, h.remark " + " from SchHandout h " + " where h.deleteFlag is false " + " and h.classId = ?"; } if (StringUtils.isNotBlank(tid)) { // ÆäËû if ("-1".equals(tid)) { hql = hql.concat( " and not EXISTS (select 1 from SchClassSubject t where t.deleteFlag is false and t.classSubjectId = h.subjectId) "); } else { hql = hql.concat(" and h.subjectId = ?"); agrs.add(tid); } } hql = hql.concat(" ORDER BY h.orderNum ASC"); handoutLst = findwithRawResult(hql, agrs); List> lstMap = new ArrayList>(handoutLst.size()); Map map = null; for (Object[] obj : handoutLst) { map = new HashMap(6); map.put(HANDOUT_ID, obj[0]); map.put("name", obj[1]); map.put("pageCount", obj[2]); map.put("status", obj[3]); map.put("subjectId", obj[4]); map.put("subjectName", obj[5]); map.put("orderNum", obj[6]); map.put("remark", obj[7]); lstMap.add(map); } return lstMap; } /** * »ñÈ¡»ú¹¹½²ÒåÁбíÊý¾Ý * * @return */ @Override public List> handoutOrgLst(String collegeCourseId, String subjectId) { List handoutLst = null; List args = new ArrayList(); String hql = ""; // ÆäËû if (("-" + collegeCourseId).equals(subjectId)) { hql = "select v.handoutId,v.name,v.pageCount,v.status,'','','',0,v.subjectId from SchHandout v,SchHandoutReCourse r where v.collegeCourseId = ? and v.deleteFlag is false and r.deleteFlag is false and r.handoutId = v.handoutId and r.orgId = ? and" + " not EXISTS (select 1 from SchSubject t where t.deleteFlag is false and t.subjectId = v.subjectId)"; args.add(collegeCourseId); args.add(ClientUtils.getOrgId()); } else { hql = "select h.handoutId,h.name,h.pageCount,h.status,o.courseCategoryName,o.name,h.subjectName,s.orderNum,h.subjectId " + " from SchHandoutReCourse s , SchHandout h,OrgCollegeCourse o" + " where s.deleteFlag is false and h.deleteFlag is false " + " and o.collegeCourseId = s.collegeCourseId" + " and s.orgId = ?" + " and s.handoutId = h.handoutId "; args.add(ClientUtils.getOrgId()); if (StringUtils.isNotBlank(subjectId)) { hql = hql.concat(" and h.subjectId = ?"); args.add(subjectId); } hql = hql.concat(" and s.collegeCourseId = ? ORDER BY s.orderNum ASC"); args.add(collegeCourseId); } handoutLst = find(hql, args, Object[].class); List> lstMap = new ArrayList>(handoutLst.size()); Map map = null; for (Object[] obj : handoutLst) { map = new HashMap(); map.put(HANDOUT_ID, obj[0]); map.put("name", obj[1]); map.put("pageCount", obj[2]); map.put("status", obj[3]); map.put("courseCategoryName", obj[4]); map.put("courseName", obj[5]); map.put("subjectName", obj[6]); map.put("orderNum", obj[7]); map.put("subjectId", obj[8]); // findAlreadyOrg(map,obj); lstMap.add(map); } return lstMap; } /** * Ö¸¶¨»ú¹¹½²Òå * * @return */ @Override public Result insertAppointHandout(String handoutIds[], String orgIds[], String classIds[], String collegeCourseId) { if (null == handoutIds || handoutIds.length == 0) { return new Result(false, "²ÎÊý´íÎó"); } // Ò»´ÎÐÔ²éѯclassId¶ÔÓ¦µÄorgId Map argsMap = new HashMap(); Map classMap = new HashMap(); if (classIds.length > 0) { String hql = " from ClsClass where classId in (:classIds) and deleteFlag is false"; argsMap = new HashMap(); argsMap.put("classIds", classIds); List classList = findByComplexHql(hql, argsMap, ClsClass.class); // ·ÅÈëmapÖÐ KEY:classId VALUE:orgId for (ClsClass orgClass : classList) { classMap.put(orgClass.getClassId(), orgClass.getOrgId()); } } // Ò»´ÎÐÔ²é³öhandoutId¶ÔÓ¦µÄhandoutOrder Map orderMap = new HashMap(); String hql = " from SchHandoutReCourse where handoutId in (:handoutIds) and deleteFlag is false and orgId = :currOrgId"; argsMap = new HashMap(); argsMap.put("handoutIds", handoutIds); argsMap.put("currOrgId", ClientUtils.getOrgId()); List handoutCourse = findByComplexHql(hql, argsMap, SchHandoutReCourse.class); for (SchHandoutReCourse schHandoutReCourse : handoutCourse) { orderMap.put(schHandoutReCourse.getHandoutId(), schHandoutReCourse.getOrderNum()); } for (String handoutId : handoutIds) { if (orgIds.length > 0) { // Ö¸¶¨¸ø»ú¹¹ insertAppointOrg(orgIds, handoutId, collegeCourseId, orderMap); } if (classIds.length > 0) { // Ö¸¶¨¸ø°à¼¶ insertAppointClass(classIds, handoutId, classMap, collegeCourseId, orderMap); } } return new Result(true); } /** * Ö¸¶¨¸ø»ú¹¹ * * @param orgIds * @param handoutId * @param collegeCourseId */ private void insertAppointOrg(String orgIds[], String handoutId, String collegeCourseId, Map orderMap) { String hql = "select orgId from SchHandoutReCourse where handoutId = :handoutId and deleteFlag is false and orgId in (:orgIds)"; Map args = new HashMap(); args.put(HANDOUT_ID, handoutId); args.put("orgIds", orgIds); List strings = findByComplexHql(hql, args, String.class); List orgList = new ArrayList(); for (String orgId : orgIds) { orgList.add(orgId); } // ÌÞ³ýµô²»·ûºÏÌõ¼þµÄorgId orgList.removeAll(strings); if (orgList.isEmpty()) { return; } for (String orgId : orgList) { SchHandoutReCourse shrc = new SchHandoutReCourse(); shrc.setCollegeCourseId(collegeCourseId); shrc.setDeleteFlag(false); shrc.setHandoutId(handoutId); shrc.setOrderNum(orderMap.get(handoutId)); shrc.setOrgId(orgId); TraceUtils.setCreateTrace(shrc); save(shrc); this.courseWareService.insertOrgCourseware(handoutId, ClientUtils.getOrgId(), orgId, collegeCourseId); } } /** * Ö¸¶¨¸ø°à¼¶ * * @param classIds * @param handoutId * @param classMap */ private void insertAppointClass(String classIds[], String handoutId, Map classMap, String collegeCourseId, Map orderMap) { // Õ½Úid Map origChapterMap = new HashMap(); SchHandout handout = read(SchHandout.class, handoutId); String hql = "select classId from SchHandout where deleteFlag is false and originHandoutId = :handoutId and classId in (:classIds)"; Map args = new HashMap(); args.put("classIds", classIds); args.put(HANDOUT_ID, handoutId); List strings = findByComplexHql(hql, args, String.class); List classList = new ArrayList(); for (String classId : classIds) { classList.add(classId); } classList.removeAll(strings); if (classList.isEmpty()) { return; } // Ò»´ÎÐÔ²éѯ°à¼¶ID¶ÔÓ¦µÄclassSubjectId hql = " from SchClassSubject where classId in(:classIds) and origSubjectId = :subjectId and deleteFlag is false"; args = new HashMap(); args.put("classIds", classList.toArray()); args.put("subjectId", handout.getSubjectId()); List lstClassSubject = findByComplexHql(hql, args, SchClassSubject.class); Map subjectMap = new HashMap(); for (SchClassSubject schClassSubject : lstClassSubject) { subjectMap.put(schClassSubject.getClassId(), schClassSubject.getClassSubjectId()); } OrgText oldOrgText = orgTextService.getOrgText(handoutId, OrgText.TABLE_NAME_HANDOUT); for (String classId : classList) { SchHandout sh = new SchHandout(); sh.setDeleteFlag(false); sh.setName(handout.getName()); sh.setPageCount(handout.getPageCount()); sh.setStatus(handout.getStatus()); sh.setTotalCount(handout.getTotalCount()); sh.setPlayCount(0); sh.setClassId(classId); sh.setOriginHandoutId(handoutId); sh.setOrgId(classMap.get(classId)); sh.setFullPath(handout.getFullPath()); sh.setFullLength(handout.getFullLength()); sh.setSubjectId(subjectMap.get(classId)); sh.setSubjectName(handout.getSubjectName()); sh.setCollegeCourseId(collegeCourseId); sh.setOrderNum(1000); sh.setCoverPageUrl(handout.getCoverPageUrl()); sh.setRemark(handout.getRemark()); if (null != origChapterMap.get(classId)) { sh.setChapterId(origChapterMap.get(classId).getChapterId()); } else { sh.setChapterId(null); } TraceUtils.setCreateTrace(sh); this.saveHandout(sh); // ²åÈëOrgText orgTextService.doInsertOrgText(sh.getHandoutId(), OrgText.TABLE_NAME_HANDOUT, oldOrgText == null ? sh.getRemark() : oldOrgText.getContent()); hql = " from SchHandoutPage where handoutId = ? and deleteFlag is false "; List pages = find(hql, CollectionUtils.newList(handoutId), SchHandoutPage.class); for (SchHandoutPage schHandoutPage : pages) { SchHandoutPage page = new SchHandoutPage(); page.setDeleteFlag(false); page.setHandoutId(sh.getHandoutId()); page.setImgPath(schHandoutPage.getImgPath()); page.setPageOrder(schHandoutPage.getPageOrder()); TraceUtils.setCreateTrace(page); save(page); } // ±ê¼Ç°à¼¶Óн²Òå ClsClass cls = read(ClsClass.class, classId); if (cls != null && cls.getHaveHandout() == ClsClass.NOT_HAVE_HANDOUT) { cls.setHaveHandout(ClsClass.HAVE_HANDOUT); save(cls); } } } /* * (non-Javadoc) * * @see * com.qxueyou.scc.school.service.IHandoutService#doStartHandouts(java.lang. * String[]) */ @SuppressWarnings("unused") @Override public Result doStartHandouts(String handoutIds) { if (StringUtils.isEmpty(handoutIds)) { return new Result(false, "²ÎÊý´íÎó"); } String[] handoutIdArray = handoutIds.split(","); // ·¢Ëͽ²Òåϵͳ֪ͨ sendSysMsg(handoutIds); for (String handoutId : handoutIdArray) { SchHandout handout = read(SchHandout.class, handoutId); handout.setStatus(SchHandout.STATUS_ISSUED); TraceUtils.setUpdateTrace(handout); this.saveHandout(handout); // ÍÆËÍÏûÏ¢¸øÑ§Ô± Map extras = new HashMap(1); extras.put("senderId", "sys_msg"); extras.put("type", "SYS_MSG"); List> lstUserIdList = this.queryPushUserIds(handout.getClassScheduleId()); if (lstUserIdList.isEmpty()) { return new Result(true); } for (List userIds : lstUserIdList) { // jpushService.doJpushByUserIds(userIds, extras, "ÓÐн²Òå", "·¢²¼Á˽²Òå:" + // handout.getName(), "·¢²¼Á˽²Òå:" + handout.getName()); } } return new Result(true); } /** * ²ð·Ö³É200ÈËÒ»×é * @param classId * @return */ @SuppressWarnings("null") private List> queryPushUserIds(String classId) { List> result = new ArrayList>(1); // List lstUserIds = userService.getUserLstByClassId(classId); List lstUserIds = null; // СÓÚ200 Ö±½Ó·µ»Ø if (lstUserIds.size() < 200) { result.add(lstUserIds); return result; } // ´óÓÚ200£¬·ÖÅú´¦Àí int iSize = lstUserIds.size() / 200; int iLeft = lstUserIds.size() % 200; iSize = iLeft == 0 ? iSize : iSize + 1; List lstSplitUserIds; for (int i = 0; i < iSize; i++) { lstSplitUserIds = new ArrayList(200); // 200 ¸ö if (i < (iSize - 1)) { lstSplitUserIds.addAll(lstUserIds.subList(i * 200, (i + 1) * 200)); } else { // ×îºóÊ£Ïµģ¬¿ÉÄÜСÓÚ200¸ö lstSplitUserIds.addAll(lstUserIds.subList(i * 200, lstUserIds.size())); } result.add(lstSplitUserIds); } return result; } /** * ·¢Ëͽ²ÒåϵͳÏûÏ¢ * @param handoutIds * @return */ private Result sendSysMsg(String handoutIds) { // boolean allSuccess = true; // // ONSMsg msg = new ONSMsg(onsProducer.getTopic()); // // msg.put("msgType", "SYS_HANDOUT_SAVE"); // msg.put("classId", ClientUtils.getClassId()); // msg.put("handoutIds", handoutIds); // try { // onsProducer.sendMsg(msg); // // Ïû·ÑÀࣺcom.qxueyou.scc.school.service.impl.HandoutSysMsgDealService // // } catch (Exception e) { // log.error("call DocdealMsgSendService fail.userId: " + // ClientUtils.getClassId(), e); // allSuccess = false; // } return new Result(false); } /* * (non-Javadoc) * * @see com.qxueyou.scc.school.service.IHandoutService#doStopHandouts(java.lang. * String[]) */ @Override public Result doStopHandouts(String[] handoutIds) { if (handoutIds.length == 0) { return new Result(false, "²ÎÊý´íÎó"); } for (String handoutId : handoutIds) { SchHandout interact = read(SchHandout.class, handoutId); interact.setStatus(SchHandout.STATUS_DISCARD); TraceUtils.setUpdateTrace(interact); this.saveHandout(interact); } return new Result(true); } /** * ²åÈëÀúÊ·½²Òå * * @param handout * @param oldHandoutId * @return */ @Override public Result insertChooseHandout(SchHandout handout, String oldHandoutId) { SchHandout oldSchHandout = read(SchHandout.class, oldHandoutId); List handoutPages = oldSchHandout.getHandoutPages(); TraceUtils.setCreateTrace(handout); handout.setPageCount(oldSchHandout.getPageCount()); handout.setName(oldSchHandout.getName()); handout.setStatus(SchHandout.STATUS_DRAFT); handout.setClassId(ClientUtils.getClassId()); handout.setOrgId(oldSchHandout.getOrgId()); handout.setOrderNum(oldSchHandout.getOrderNum()); handout.setCoverPageUrl(oldSchHandout.getCoverPageUrl()); handout.setFullPath(oldSchHandout.getFullPath()); handout.setFullLength(oldSchHandout.getFullLength()); handout.setPlayCount(0); handout.setCollegeCourseId(ClientUtils.getCourseId()); this.saveHandout(handout); List newHandoutPages = new ArrayList(); for (SchHandoutPage page : handoutPages) { SchHandoutPage newPage = new SchHandoutPage(); TraceUtils.setCreateTrace(newPage); newPage.setHandoutId(handout.getHandoutId()); newPage.setImgPath(page.getImgPath()); newPage.setPageOrder(page.getPageOrder()); newHandoutPages.add(newPage); } saveOrUpdateAll(newHandoutPages); return new Result(true); } /** * ¿½±´½²Òå * @param oldHandoutId * @param subjectId * @param collegeCourseId * @param chapterId * @param subjectName * @return * @throws IllegalAccessException * @throws InstantiationException * @throws InvocationTargetException * @throws NoSuchMethodException */ @Override public Result doCopyHandout(String oldHandoutId, String subjectId, String collegeCourseId, String chapterId, String subjectName) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException { SchHandout oldSchHandout = read(SchHandout.class, oldHandoutId); List handoutPages = oldSchHandout.getHandoutPages(); oldSchHandout.setHandoutPages(null); SchHandout newHandout = (SchHandout) BeanUtils.cloneBean(oldSchHandout); newHandout.setHandoutId(null); TraceUtils.setCreateTrace(newHandout); newHandout.setChapterId(chapterId); newHandout.setSubjectId(subjectId); newHandout.setSubjectName(subjectName); newHandout.setOrderNum(1000); newHandout.setCollegeCourseId(collegeCourseId); newHandout.setStatus(SchHandout.STATUS_DRAFT); newHandout.setPlayCount(0); this.saveHandout(newHandout); List newHandoutPages = new ArrayList(); if (!handoutPages.isEmpty()) { for (SchHandoutPage page : handoutPages) { SchHandoutPage newPage = (SchHandoutPage) BeanUtils.cloneBean(page); TraceUtils.setCreateTrace(newPage); newPage.setHandoutId(newHandout.getHandoutId()); newPage.setHandoutPageId(null); newHandoutPages.add(newPage); } saveOrUpdateAll(newHandoutPages); } // ·Ç°à¼¶¿½±´ÐèÒª¹ØÁª±íÐÂÔö¼Ç¼ if (StringUtils.isEmpty(ClientUtils.getClassId())) { this.insertReCourse(collegeCourseId, newHandout.getHandoutId()); } return new Result(true); } /** * ²åÈë½²ÒåºÍ¿ÆÄ¿¹ØÁª * * @param collegeCourseId * @param handoutId */ private void insertReCourse(String collegeCourseId, String handoutId) { // ÐòºÅ String hql = "select MAX(c.orderNum) from SchHandoutReCourse c where c.deleteFlag is false and c.collegeCourseId = ? and orgId = ? "; Integer iMax = this.findUnique(hql, CollectionUtils.newList(collegeCourseId, ClientUtils.getOrgId()), Integer.class); if (iMax == null || iMax == 0) { iMax = 1; } else { iMax = iMax + 1; } SchHandoutReCourse course = new SchHandoutReCourse(); course.setCollegeCourseId(collegeCourseId); course.setDeleteFlag(false); course.setHandoutId(handoutId); course.setOrderNum(iMax); course.setOrgId(ClientUtils.getOrgId()); TraceUtils.setCreateTrace(course); save(course); } /** * ²éѯ½²ÒåÁбí * * @param hql * @param args * @return */ @Override public List schHandoutList(int type, String hql, Pager page, List args) { return handoutDAO.schHandoutList(type, hql, page, args); } /** * ÅúÁ¿²Ù×÷½²ÒåÊղؼǼ * * @param lstFavor * @return */ @Override public Result doOperHandoutFavorDataBatch(List lstFavor) { // ÅúÁ¿Ôö¼Ó»òÕ߸üРthis.saveOrUpdateAll(lstFavor); return new Result(true); } /** * ºǫ́»ñÈ¡ÁбíÊý¾Ý * * @param sql * @param args * @return */ @Override public List queryDataList(String sql, List args) { return handoutDAO.queryDataList(sql, args); } /** * ²éѯѡÔñ°à¼¶ÏÂÀúÊ·½²Òå * @param sql * @param args * @return */ @Override public List queryChooseHandoutList(String sql, List args) { return null; // handoutDAO.queryChooseList(sql, args); } private Result doInitClassHandout(SchHandout handout, List lstPages) { String hql = " from SchHandout s where s.originHandoutId = ? and s.originHandoutId <> s.handoutId and deleteFlag is false "; List handouts = this.find(hql, CollectionUtils.newList(handout.getHandoutId()), SchHandout.class); if (null == handouts || handouts.isEmpty()) { return new Result(true, "ÎÞ¹ØÁª½²Òå"); } List allPages = new ArrayList(); // Ñ­»·´¦Àí for (SchHandout ho : handouts) { TraceUtils.setUpdateTrace(ho); ho.setStatus(handout.getStatus()); ho.setPageCount(handout.getPageCount()); allPages.addAll(this.initCurrPages(lstPages, ho.getHandoutId())); this.saveHandout(ho); } // Ã÷ϸ this.saveOrUpdateAll(allPages); return new Result(true); } /** * ¸³ÖµËùÓн²ÒåÃ÷ϸ * * @param lstPages * @param handoutId * @return */ private List initCurrPages(List lstPages, String handoutId) { List currPages = new ArrayList(lstPages.size()); SchHandoutPage page = null; for (SchHandoutPage currPage : lstPages) { page = new SchHandoutPage(); page.setDeleteFlag(false); page.setHandoutId(handoutId); page.setImgPath(currPage.getImgPath()); page.setPageOrder(currPage.getPageOrder()); TraceUtils.setCreateTrace(page); currPages.add(page); } return currPages; } /** * Ðýת½²ÒåͼƬ * * @param angle * @param handoutPageId * @return */ @Override public Result doRotatePic(String angle, String handoutPageId) { SchHandoutPage page = this.read(SchHandoutPage.class, handoutPageId); if (null == page) { return new Result(false, "pageΪ¿Õ"); } String imgPath = page.getImgPath(); int iIndex = imgPath.indexOf('@'); if (iIndex != -1) { imgPath = imgPath.substring(0, iIndex); } if (StringUtils.isBlank(imgPath)) { return new Result(false, "path½âÎö³ö´í"); } imgPath = imgPath.concat("@").concat(angle).concat("r"); page.setImgPath(imgPath); save(page); return new Result(true); } /** * ²éѯ½²Òå,Ä£ºý¿Î³ÌÃû»òÕß½²ÒåÃû * * @param keyWord * ²éѯ¹Ø¼ü×Ö * @return */ @Override public List queryHandoutByKeyWord(String keyWord) { String keyWord0 = keyWord; String sql = "select h.* from sch_handout h,sch_class_schedule l where " + "l.class_schedule_id = h.class_schedule_id and l.delete_flag = 0 and h.delete_flag = 0 " + "and h.class_id = ? " + "and ( h.lesson like ? or h.name like ? ) "; keyWord0 = "%".concat(keyWord0).concat("%"); return handoutDAO.queryDataList(sql, CollectionUtils.newList(ClientUtils.getClassId(), keyWord0, keyWord0)); } /** * ¸üн²Òå¹Û¿´Á¿ */ public Result updatePlayCount(String handoutId) { SchHandout sh = read(SchHandout.class, handoutId); if (null == sh) { return new Result(true); } if (sh.getPlayCount() == null) { bulkUpdateInLoop("update SchHandout set playCount = 1 where handoutId = ?", new String[] { handoutId }); } else { bulkUpdateInLoop("update SchHandout set playCount = (playCount + 1) where handoutId = ?", new String[] { handoutId }); } return new Result(true); } @Override public Result insertplayRecordNew(SchHandoutRecord record, String pageNums) { SchHandout sh = read(SchHandout.class, record.getHandoutId()); if (null == sh) { return new Result(true); } record.setOrgId(ClientUtils.getOrgId()); record.setClassId(ClientUtils.getClassId()); record.setUserId(ClientUtils.getUserId()); String[] nums = pageNums.split(","); record.setPlayCount(nums.length); record.setPageCount(sh.getPageCount()); record.setDeleteFlag(false); TraceUtils.setCreateTrace(record); save(record); List numList = new ArrayList(); for (String num : nums) { numList.add(Integer.parseInt(num)); } String hql = " from SchHandoutPage where pageOrder in (:nums) and handoutId = :handoutId"; Map args = new HashMap(); args.put("nums", numList.toArray()); args.put(HANDOUT_ID, sh.getHandoutId()); List lstPages = findByComplexHql(hql, args, SchHandoutPage.class); Map map = new HashMap(); for (SchHandoutPage schHandoutPage : lstPages) { map.put(schHandoutPage.getPageOrder() + schHandoutPage.getHandoutId(), schHandoutPage); } for (String string : nums) { SchHandoutRecordDetail shrd = new SchHandoutRecordDetail(); shrd.setDeleteFlag(false); shrd.setHandoutRecordId(record.getHandoutRecordId()); shrd.setPageNum(Integer.parseInt(string)); if (null != record.getType()) { shrd.setCollection(record.getType()); } SchHandoutPage shp = map.get(string + sh.getHandoutId()); shrd.setPageId(shp.getHandoutPageId()); TraceUtils.setCreateTrace(shrd); save(shrd); } // ͳ¼Æ±íÔö¼ÓÊý¾Ý hql = " from SchHandoutStatistic where userId=? and classId=? and handoutId=?"; SchHandoutStatistic shs = findUnique(hql, CollectionUtils.newList(ClientUtils.getUserId(), ClientUtils.getClassId(), sh.getHandoutId()), SchHandoutStatistic.class); if (shs == null) { shs = new SchHandoutStatistic(); shs.setClassId(ClientUtils.getClassId()); shs.setCompDegree(new BigDecimal(record.getPlayCount()).divide(new BigDecimal(record.getPageCount()), 2, BigDecimal.ROUND_HALF_UP)); shs.setDeleteFlag(false); shs.setHandoutId(record.getHandoutId()); shs.setHandoutName(sh.getName()); shs.setUserId(ClientUtils.getUserId()); shs.setUserName(ClientUtils.getUserName()); TraceUtils.setCreateTrace(shs); save(shs); } else { hql = "select DISTINCT d.PAGE_NUM from sch_handout_record_detail d where d.HANDOUT_RECORD_ID in " + "( select r.HANDOUT_RECORD_ID from sch_handout_record r where USER_ID=? and CLASS_ID=? and HANDOUT_ID=?)"; List pageLst = handoutDAO.schHandoutPageNum(hql, CollectionUtils.newList(ClientUtils.getUserId(), ClientUtils.getClassId(), record.getHandoutId())); Set set = new HashSet(); // ±¾´Î¹Û¿´ for (String string2 : nums) { set.add(string2); } // Êý¾Ý¿â¹Û¿´¼Ç¼ set.addAll(pageLst); shs.setCompDegree(new BigDecimal(set.size()).divide(new BigDecimal(record.getPageCount()), 2, BigDecimal.ROUND_HALF_UP)); TraceUtils.setUpdateTrace(shs); save(shs); } return new Result(true); } @Override public Result insertplayRecord(SchHandoutRecord record, String pageNums) { return this.insertplayRecordNew(record, pageNums); } /** * ½²ÒåÉÏ´«Öظ´Êý¾Ý´¦Àí * * @param handoutId * @return */ @Override public Result doInitHandoutRepeatData(String handoutId) { String hql = "select max(p.handoutPageId) from SchHandoutPage p where p.deleteFlag is false and p.handoutId = ? group by p.handoutId, p.pageOrder having count(1) > 1 "; List pageIds = this.find(hql, CollectionUtils.newList(handoutId), String.class); if (null == pageIds || pageIds.isEmpty()) { return new Result(true); } List pages = new ArrayList(pageIds.size()); SchHandoutPage page; for (String pageId : pageIds) { page = this.read(SchHandoutPage.class, pageId); page.setDeleteFlag(true); pages.add(page); } this.saveOrUpdateAll(pages); return new Result(true); } /** * ÅÅÐò * * @param ids * ÅÅÐòid * @param index * ÐòºÅ * @return */ public Result doOrder(List ids, List index) { // Ñ­»·ÐÞ¸Äorder CommonDAO commonDAO = this.getCommonDAO(); for (int i = 0; i < ids.size(); i++) { String handoutId = ids.get(i); if (UserInfoWrapper.ROLE_TEACHER.equals(ClientUtils.getCurrentRole()) || UserInfoWrapper.ROLE_CHARGER.equals(ClientUtils.getCurrentRole())) { commonDAO.bulkUpdate("update SchHandout set orderNum = " + index.get(i) + " where handoutId = ?", new Object[] { handoutId }); } else { commonDAO.bulkUpdate( "update SchHandoutReCourse set orderNum = " + index.get(i) + " where handoutId = ?", new Object[] { handoutId }); } commonDAO.bulkUpdate("update SchCourseware set orderNum = " + index.get(i) + " where id = ?", new Object[] { handoutId }); } return new Result(true); } /** * ±£´æ½²Òå½Ó¿Ú * * @param handout * @return */ public Result saveHandout(SchHandout handout) { Result result = new Result(false); result = this.save(handout); String parentChapterId = null; if (StringUtils.isNotEmpty(handout.getChapterId())) { SubjectChapter chapter = this.read(SubjectChapter.class, handout.getChapterId()); parentChapterId = chapter == null ? null : chapter.getParentChapterId(); } boolean isClass = StringUtils.isNotEmpty(ClientUtils.getClassId()) || StringUtils.isNotEmpty(handout.getClassId()); SchCourseware courseware = null; if (isClass) { courseware = this.findUnique("from SchCourseware where id = ? and classId = ? and deleteFlag is false", CollectionUtils.newList(handout.getHandoutId(), handout.getClassId()), SchCourseware.class); } else { courseware = this.findUnique( "from SchCourseware where id = ? and orgId = ? and classId is null and deleteFlag is false", CollectionUtils.newList(handout.getHandoutId(), handout.getOrgId()), SchCourseware.class); this.bulkUpdate("update SchCourseware set name = ? where id = ?", new Object[] { handout.getName(), handout.getHandoutId() }); } if (courseware == null) { courseware = new SchCourseware(); courseware.setChapterId(handout.getChapterId()); courseware.setId(handout.getHandoutId()); courseware.setCollegeCourseId(handout.getCollegeCourseId()); courseware.setcType(-1); courseware.setType(SchCourseware.COURSEWARE_TYPE_HANDOUT); courseware.setName(handout.getName()); courseware.setRemark(String.valueOf(handout.getPageCount())); courseware.setDeleteFlag(handout.getDeleteFlag()); courseware.setOrderNum(1000); courseware.setSubjectId(handout.getSubjectId()); courseware.setStatus(handout.getStatus()); courseware.setOrgId(handout.getOrgId()); courseware.setClassId(handout.getClassId()); courseware.setParentChapterId(parentChapterId); TraceUtils.setCreateTrace(courseware); } else { courseware.setChapterId(handout.getChapterId()); // courseware.setCollegeCourseId(handout.getCollegeCourseId()); courseware.setcType(-1); courseware.setName(handout.getName()); courseware.setRemark(String.valueOf(handout.getPageCount())); courseware.setDeleteFlag(handout.getDeleteFlag()); courseware.setOrderNum(handout.getOrderNum() == null ? 1000 : handout.getOrderNum()); courseware.setSubjectId(handout.getSubjectId()); courseware.setStatus(handout.getStatus()); courseware.setParentChapterId(parentChapterId); TraceUtils.setUpdateTrace(courseware); } this.save(courseware); return result; } }