Index: forgon-knowledge/src/main/java/com/forgon/knowledge/service/KnowledgeFileManagerImpl.java =================================================================== diff -u -r25574 -r28827 --- forgon-knowledge/src/main/java/com/forgon/knowledge/service/KnowledgeFileManagerImpl.java (.../KnowledgeFileManagerImpl.java) (revision 25574) +++ forgon-knowledge/src/main/java/com/forgon/knowledge/service/KnowledgeFileManagerImpl.java (.../KnowledgeFileManagerImpl.java) (revision 28827) @@ -2,42 +2,57 @@ import java.io.File; import java.io.UnsupportedEncodingException; +import java.lang.reflect.InvocationTargetException; import java.net.URLEncoder; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.collections.map.HashedMap; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; +import org.hibernate.Query; +import org.hibernate.Session; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import com.beust.jcommander.ParameterException; import com.forgon.attachfile.enums.AttachFileSaveType; import com.forgon.attachfile.service.AttachFileManager; +import com.forgon.directory.acegi.tools.AcegiHelper; +import com.forgon.directory.vo.LoginUserData; import com.forgon.disinfectsystem.basedatamanager.supplyroomconfig.service.SupplyRoomConfigManager; import com.forgon.disinfectsystem.entity.basedatamanager.supplyroomconfig.SupplyRoomConfig; +import com.forgon.exception.SystemException; import com.forgon.exception.UploadException; import com.forgon.exception.exceptionDTO.AbstractExceptionDTO; import com.forgon.exception.exceptionDTO.UploadExceptionDTO; import com.forgon.exception.exceptionHandler.UploadExceptionHandler; import com.forgon.knowledge.model.KnowledgeFile; import com.forgon.knowledge.model.KnowledgeFolder; +import com.forgon.knowledge.model.ReadRecord; +import com.forgon.knowledge.model.Vo.ReadRecordVo; import com.forgon.knowledge.xml.service.KnowledgeModuleManager; import com.forgon.knowledge.xmlbean.ModuleXmlBean; +import com.forgon.security.model.User; import com.forgon.security.service.AclManager; import com.forgon.security.service.AclTools; import com.forgon.tools.Constants; import com.forgon.tools.db.DatabaseUtil; import com.forgon.tools.hibernate.ObjectDao; import com.forgon.tools.util.ObjectUtil; +import com.forgon.tools.util.SqlUtils; import com.forgon.treenode.service.THTreeNodeManager; +import edu.emory.mathcs.backport.java.util.Arrays; + /** * @author yuanbin */ @@ -83,19 +98,47 @@ objectDao.delete(po); } - @Override + @SuppressWarnings("unchecked") + @Override public void deleteFileNodeByIds(String moduleId, List ids) { for (Long id : ids) { KnowledgeFile fileNode = getById(moduleId, id.toString()); objectDao.delete(fileNode); } + // 删除文件对应的阅读记录 + String hql = String.format(" from %s po where %s ", ReadRecord.class.getSimpleName(), SqlUtils.getNonStringFieldInLargeCollectionsPredicate("po.knowledgeFileId", ids)); + List readRecords = objectDao.findByHql(hql); + if(CollectionUtils.isNotEmpty(readRecords)){ + objectDao.deleteAll(readRecords); + } } - @Override + @SuppressWarnings("unchecked") + @Override public KnowledgeFile getById(String moduleId, String id) { ModuleXmlBean moduleXmlBean = knowledgeModuleManager.getModuleXmlBeanById(moduleId); KnowledgeFile knowledgeFile = (KnowledgeFile) objectDao.getByProperty(moduleXmlBean.getFileClassName(), "id", Long.valueOf(id)); // aclManager.setAclFieldsObjectDisplayValue(knowledgeFile); + String readers = knowledgeFile.getReaders(); + if(StringUtils.isNotBlank(readers)){ + String[] nameArr = readers.split(";"); + List nameList = Arrays.asList(nameArr); + String hql = String.format(" from %s po where %s", User.class.getSimpleName(), + SqlUtils.getStringFieldInLargeCollectionsPredicate("po.name", nameList)); + List userList = objectDao.findByHql(hql); + if(CollectionUtils.isNotEmpty(userList)){ + String readersForDisplay = ""; + for (int i=0;i readRecords = objectDao.findByHql(hql); + ReadRecord readRecord = null; + if(CollectionUtils.isEmpty(readRecords)){ + readRecord = new ReadRecord(); + readRecord.setUserId(loginUser.getUserId()); + readRecord.setKnowledgeFileId(fileId); + readRecord.setReadAmount(1l); + readRecord.setLastReadTime(new Date()); + } else { + readRecord = readRecords.get(0); + readRecord.setReadAmount(readRecord.getReadAmount() + 1); + readRecord.setLastReadTime(new Date()); + } + + objectDao.saveOrUpdate(readRecord); + } + + @SuppressWarnings({"rawtypes"}) + @Override + public List getReadRecordByknowledgeFileId(String knowledgeFileId){ + if(!DatabaseUtil.isPoIdValid(knowledgeFileId)){ + return new ArrayList(); + } + List readRecordVos = new ArrayList(); + Session session = objectDao.getHibernateSession(); + String hql = String.format("select rr, u from %s rr, %s u where u.id = rr.userId and rr.knowledgeFileId = %s order by rr.id desc ", ReadRecord.class.getSimpleName(), User.class.getSimpleName(), knowledgeFileId); + Query query = session.createQuery(hql); + List list = query.list(); + if(CollectionUtils.isEmpty(list)){ + return readRecordVos; + } + for (int i=0; i + + + + + + + + Index: forgon-knowledge/src/main/java/com/forgon/knowledge/model/TrainingParticipant.java =================================================================== diff -u --- forgon-knowledge/src/main/java/com/forgon/knowledge/model/TrainingParticipant.java (revision 0) +++ forgon-knowledge/src/main/java/com/forgon/knowledge/model/TrainingParticipant.java (revision 28827) @@ -0,0 +1,59 @@ +package com.forgon.knowledge.model; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + +/** + * 培训参与人员和培训记录关联表(JMSZXYY-86) + * @author ZhouPeiMian + * @since 2020-08-21 + */ +@Entity +@DynamicInsert(false) +@DynamicUpdate(true) +public class TrainingParticipant { + + private Long id; + + /** + * 培训参与人员Id + */ + private Long userId; + + /** + * 培训记录 + */ + private Long trainingRecordId; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public Long getTrainingRecordId() { + return trainingRecordId; + } + + public void setTrainingRecordId(Long trainingRecordId) { + this.trainingRecordId = trainingRecordId; + } + +} Index: forgon-knowledge/src/main/java/com/forgon/knowledge/service/KnowledgeFileManager.java =================================================================== diff -u -r17419 -r28827 --- forgon-knowledge/src/main/java/com/forgon/knowledge/service/KnowledgeFileManager.java (.../KnowledgeFileManager.java) (revision 17419) +++ forgon-knowledge/src/main/java/com/forgon/knowledge/service/KnowledgeFileManager.java (.../KnowledgeFileManager.java) (revision 28827) @@ -3,6 +3,7 @@ import com.forgon.exception.exceptionDTO.AbstractExceptionDTO; import com.forgon.exception.exceptionDTO.UploadExceptionDTO; import com.forgon.knowledge.model.KnowledgeFile; +import com.forgon.knowledge.model.Vo.ReadRecordVo; import javax.servlet.http.HttpServletRequest; import java.io.UnsupportedEncodingException; @@ -41,6 +42,19 @@ * @return {@link UploadExceptionDTO} */ AbstractExceptionDTO handleException(HttpServletRequest request, KnowledgeFile command, Exception ex) throws UnsupportedEncodingException; + + /** + * 在培训管理里中,勾选文件点击修改时,增加该文件的阅读记录(JMSZXYY-86) + * @param knowledgeFileId 文件id + */ + public void accumulateReadRecord(KnowledgeFile knowledgeFileId); + + /** + * 获取培训文件的阅读记录 + * @param knowledgeFileId + * @return + */ + List getReadRecordByknowledgeFileId(String knowledgeFileId); } Index: forgon-knowledge/src/main/java/com/forgon/knowledge/model/ReadRecord.java =================================================================== diff -u --- forgon-knowledge/src/main/java/com/forgon/knowledge/model/ReadRecord.java (revision 0) +++ forgon-knowledge/src/main/java/com/forgon/knowledge/model/ReadRecord.java (revision 28827) @@ -0,0 +1,100 @@ +package com.forgon.knowledge.model; + +import java.util.Date; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Transient; + +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + +import com.forgon.security.model.User; +import com.forgon.tools.hibernate.ObjectDao; + +/** + * 培训管理文件的阅读记录(JMSZXYY-86) + * @author ZhouPeiMian + * @since 2020-08-21 + * + */ +@Entity +@DynamicInsert(false) +@DynamicUpdate(true) +public class ReadRecord { + + private Long id; + + /** + * 培训文件ID + */ + private Long knowledgeFileId; + + /** + * 打开文件的用户ID(取值打开文件时的登录用户) + */ + private Long userId; + + /** + * 累计阅读次数 + */ + private Long readAmount; + + /** + * 最后打开时间 + */ + private Date lastReadTime; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getKnowledgeFileId() { + return knowledgeFileId; + } + + public void setKnowledgeFileId(Long knowledgeFileId) { + this.knowledgeFileId = knowledgeFileId; + } + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public Long getReadAmount() { + return readAmount; + } + + public void setReadAmount(Long readAmount) { + this.readAmount = readAmount; + } + + public Date getLastReadTime() { + return lastReadTime; + } + + public void setLastReadTime(Date lastReadTime) { + this.lastReadTime = lastReadTime; + } + + @Transient + public User getUser(ObjectDao objectDao){ + if(userId == null || userId.intValue() == 0){ + return null; + } + return (User) objectDao.getById(User.class.getSimpleName(), userId); + } + +} Index: forgon-knowledge/src/main/java/com/forgon/knowledge/service/TrainingRecordManagerImpl.java =================================================================== diff -u --- forgon-knowledge/src/main/java/com/forgon/knowledge/service/TrainingRecordManagerImpl.java (revision 0) +++ forgon-knowledge/src/main/java/com/forgon/knowledge/service/TrainingRecordManagerImpl.java (revision 28827) @@ -0,0 +1,172 @@ +package com.forgon.knowledge.service; + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.hibernate.Query; +import org.hibernate.Session; + +import com.forgon.directory.acegi.tools.AcegiHelper; +import com.forgon.exception.SystemException; +import com.forgon.knowledge.model.TrainingParticipant; +import com.forgon.knowledge.model.TrainingRecord; +import com.forgon.knowledge.model.Vo.TrainingRecordVo; +import com.forgon.security.model.User; +import com.forgon.tools.db.DatabaseUtil; +import com.forgon.tools.hibernate.BasePoManagerImpl; +import com.forgon.tools.util.SqlUtils; + +import edu.emory.mathcs.backport.java.util.Arrays; + +/** + * + * @author ZhouPeiMian + * @since 2020-08-21 + * + */ +public class TrainingRecordManagerImpl extends BasePoManagerImpl implements TrainingRecordManager{ + + @SuppressWarnings("unchecked") + @Override + public void saveOrUpdateTrainingRecord(TrainingRecord trainingRecord, String userCodes) { + if(!DatabaseUtil.isPoIdValid(trainingRecord.getId())){ + // 新增培训记录时,登记人默认取当前登录用户 + trainingRecord.setRegistrantId(AcegiHelper.getLoginUser().getUserId()); + } + this.save(trainingRecord); + if(StringUtils.isNotBlank(userCodes)){ + // 查询参与培训人员信息 + String[] userCodeArr = userCodes.split(","); + List userCodeList = new ArrayList(); + for (String code : userCodeArr) { + userCodeList.add(code.replaceAll("USERID_", "")); + } + String userHql = String.format(" from %s po where %s ", User.class.getSimpleName(), SqlUtils.getStringFieldInLargeCollectionsPredicate("po.name", userCodeList)); + List userList = objectDao.findByHql(userHql); + + List userIdList = new ArrayList(); + if(CollectionUtils.isEmpty(userList)){ + throw new SystemException("用户不存在!"); + } + for (User user : userList) { + userIdList.add(user.getId()); + } + + // 原来已经保存的培训人员信息 + List oldUserIdList = new ArrayList(); + String hql = String.format(" from %s po where po.trainingRecordId = %s", TrainingParticipant.class.getSimpleName(), trainingRecord.getId().toString()); + List trainingParticipants = objectDao.findByHql(hql); + if(CollectionUtils.isNotEmpty(trainingParticipants)){ + for (TrainingParticipant trainingParticipant : trainingParticipants) { + oldUserIdList.add(trainingParticipant.getUserId()); + } + } + if(CollectionUtils.isEqualCollection(userIdList, oldUserIdList)){ + return; + } + + // 删除旧的培训参与人员信息 + objectDao.deleteAll(trainingParticipants); + List newTrainingParticipants = new ArrayList(); + for(Long userId: userIdList){ + TrainingParticipant trainingParticipant = new TrainingParticipant(); + trainingParticipant.setTrainingRecordId(trainingRecord.getId()); + trainingParticipant.setUserId(userId); + newTrainingParticipants.add(trainingParticipant); + } + objectDao.batchSaveOrUpdate(newTrainingParticipants); + } + } + + @SuppressWarnings("unchecked") + @Override + public void deleteTrainingRecords(String trainingRecordIds) { + if(StringUtils.isBlank(trainingRecordIds)){ + throw new SystemException("培训记录Id不能为空!"); + } + // 删除培训参与人员 + String[] trainingRecordIdArr = trainingRecordIds.split(","); + List trainingRecordIdList = Arrays.asList(trainingRecordIdArr); + String hql = String.format(" from %s po where %s ", TrainingParticipant.class.getSimpleName(), + SqlUtils.getNonStringFieldInLargeCollectionsPredicate("po.trainingRecordId", trainingRecordIdList)); + List trainingParticipants = objectDao.findByHql(hql); + objectDao.deleteAll(trainingParticipants); + // 删除培训记录 + this.delete(trainingRecordIds, ","); + } + + @SuppressWarnings("rawtypes") + @Override + public List findTrainingRecordList(int firstIndex, int maxResults) { + Session session = objectDao.getHibernateSession(); + List trainingRecordVos = new ArrayList(); + String hql = String.format("select tr, u2 from %s tr, %s u2 where u2.id = tr.registrantId order by tr.id desc ", TrainingRecord.class.getSimpleName(), User.class.getSimpleName()); + Query query = session.createQuery(hql); + if (maxResults >0){ + query.setFirstResult(firstIndex); + query.setMaxResults(maxResults); + } + List list = query.list(); + if(CollectionUtils.isEmpty(list)){ + return trainingRecordVos; + } + for (int i=0;i participants = trainingRecord.getTrainingParticipants(objectDao); + User registrant = trainingRecord.getRegistrant(objectDao); + TrainingRecordVo vo = new TrainingRecordVo(); + try { + BeanUtils.copyProperties(vo, trainingRecord); + } catch (IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + String userCodes = ""; + String userNames = ""; + if(CollectionUtils.isNotEmpty(participants)){ + for(int i=0;i{ + + /** + * 保存培训记录 + * @param trainingRecord 培训记录 + * @param userCodes 培训参与人员编码(多个编码用","分割:1,2,3) + */ + public void saveOrUpdateTrainingRecord(TrainingRecord trainingRecord, String userCodes); + + /** + * 删除培训记录 + * @param trainingRecordIds 培训记录id(多个id用","分割:1,2,3) + */ + public void deleteTrainingRecords(String trainingRecordIds); + + /** + * 查询所有培训记录Vo + * @return + */ + public List findTrainingRecordList(int firstIndex, int maxResults); + + /** + * 查询培训记录 + * @param id + * @return + */ + public TrainingRecordVo getTrainingRecordVoById(Long id); + +} Index: forgon-knowledge/src/main/java/com/forgon/knowledge/model/TrainingRecord.java =================================================================== diff -u --- forgon-knowledge/src/main/java/com/forgon/knowledge/model/TrainingRecord.java (revision 0) +++ forgon-knowledge/src/main/java/com/forgon/knowledge/model/TrainingRecord.java (revision 28827) @@ -0,0 +1,155 @@ +package com.forgon.knowledge.model; + +import java.util.Date; +import java.util.List; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Transient; + +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + +import com.forgon.security.model.User; +import com.forgon.tools.hibernate.ObjectDao; + +/** + * 培训记录(JMSZXYY-86) + * @author ZhouPeiMian + * @since 2020-08-21 + */ +@Entity +@DynamicInsert(false) +@DynamicUpdate(true) +public class TrainingRecord { + + private Long id; + + /** + * 培训主题 + */ + private String trainingTopic; + + /** + * 培训人(页面输入,可以取不是追溯系统上的用户) + */ + private String trainer; + + /** + * 培训地点 + */ + private String trainingPlace; + + /** + * 培训时间 + */ + private Date trainingTime; + + /** + * 登记人ID(默认取当前登录用户) + */ + private Long registrantId; + + /** + * 培训内容 + */ + private String trainingContent; + + /** + * 备注 + */ + private String remark; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getTrainingTopic() { + return trainingTopic; + } + + public void setTrainingTopic(String trainingTopic) { + this.trainingTopic = trainingTopic; + } + + public String getTrainer() { + return trainer; + } + + public void setTrainer(String trainer) { + this.trainer = trainer; + } + + public String getTrainingPlace() { + return trainingPlace; + } + + public void setTrainingPlace(String trainingPlace) { + this.trainingPlace = trainingPlace; + } + + public Date getTrainingTime() { + return trainingTime; + } + + public void setTrainingTime(Date trainingTime) { + this.trainingTime = trainingTime; + } + + public Long getRegistrantId() { + return registrantId; + } + + public void setRegistrantId(Long registrantId) { + this.registrantId = registrantId; + } + + public String getTrainingContent() { + return trainingContent; + } + + public void setTrainingContent(String trainingContent) { + this.trainingContent = trainingContent; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } + + /** + * 获取培训参与人员 + * @return + */ + @SuppressWarnings("unchecked") + @Transient + public List getTrainingParticipants(ObjectDao objectDao){ + String hql = String.format(" from %s po where po.id in ( select userId from %s where trainingRecordId = %s)", + User.class.getSimpleName(), TrainingParticipant.class.getSimpleName(), id); + return objectDao.findByHql(hql); + } + + /** + * 获取登记人 + * @param objectDao + * @return + */ + public User getRegistrant(ObjectDao objectDao){ + if(registrantId == null){ + return null; + } + return (User) objectDao.getById(User.class.getSimpleName(), registrantId); + } + +} Index: forgon-knowledge/src/main/java/com/forgon/knowledge/model/Vo/ReadRecordVo.java =================================================================== diff -u --- forgon-knowledge/src/main/java/com/forgon/knowledge/model/Vo/ReadRecordVo.java (revision 0) +++ forgon-knowledge/src/main/java/com/forgon/knowledge/model/Vo/ReadRecordVo.java (revision 28827) @@ -0,0 +1,105 @@ +package com.forgon.knowledge.model.Vo; + +import java.util.Date; + +import com.forgon.security.model.User; +import com.forgon.tools.date.DateTools; +import com.forgon.tools.hibernate.ObjectDao; + +/** + * 培训管理文件的阅读记录VO(JMSZXYY-86) + * @author ZhouPeiMian + * @since 2020-08-21 + * + */ +public class ReadRecordVo { + + /** + * 培训文件ID + */ + private Long knowledgeFileId; + + /** + * 当前登录用户ID + */ + private Long userId; + + /** + * 用户名称 + */ + private String userName; + + /** + * 累计阅读次数 + */ + private Long readAmount; + + /** + * 最后打开时间 + */ + private Date lastReadTime; + + /** + * 最后打开时间(yyyy-MM-dd HH:mm) + */ + private String lastReadTimeStr; + + public Long getKnowledgeFileId() { + return knowledgeFileId; + } + + public void setKnowledgeFileId(Long knowledgeFileId) { + this.knowledgeFileId = knowledgeFileId; + } + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public Long getReadAmount() { + return readAmount; + } + + public void setReadAmount(Long readAmount) { + this.readAmount = readAmount; + } + + public Date getLastReadTime() { + return lastReadTime; + } + + public void setLastReadTime(Date lastReadTime) { + this.lastReadTime = lastReadTime; + } + + public String getLastReadTimeStr() { + if(lastReadTime == null){ + return lastReadTimeStr; + } + return DateTools.getFormatDateStr(lastReadTime, DateTools.COMMON_DATE_HM); + } + + public void setLastReadTimeStr(String lastReadTimeStr) { + this.lastReadTimeStr = lastReadTimeStr; + } + + public User getUser(ObjectDao objectDao){ + if(userId == null || userId.intValue() == 0){ + return null; + } + return (User) objectDao.getById(User.class.getSimpleName(), userId); + } + +} Index: forgon-knowledge/src/main/java/com/forgon/knowledge/controller/KnowledgeFileController.java =================================================================== diff -u -r17872 -r28827 --- forgon-knowledge/src/main/java/com/forgon/knowledge/controller/KnowledgeFileController.java (.../KnowledgeFileController.java) (revision 17872) +++ forgon-knowledge/src/main/java/com/forgon/knowledge/controller/KnowledgeFileController.java (.../KnowledgeFileController.java) (revision 28827) @@ -10,6 +10,7 @@ import com.forgon.exception.exceptionDTO.UploadExceptionDTO; import com.forgon.knowledge.model.KnowledgeFile; import com.forgon.knowledge.model.KnowledgeFolder; +import com.forgon.knowledge.model.Vo.ReadRecordVo; import com.forgon.knowledge.service.KnowledgeFileManager; import com.forgon.knowledge.xml.service.KnowledgeModuleManager; import com.forgon.knowledge.xmlbean.ModuleXmlBean; @@ -122,6 +123,12 @@ try { logger.debug("entering 'onSubmit' method..."); String moduleId = request.getParameter("moduleId"); + // 读者编码 + String readers = command.getReaders(); + if(StringUtils.isNotBlank(readers)){ + readers = readers.replace("USERID_", ""); + command.setReaders(readers); + } knowledgeFileManager.handleUpLoadFile(command, moduleId, request); request.setAttribute(AppKeys.TipMsgKey, command.getId() != null ? "修改文件成功!":"添加文件成功!"); request.setAttribute(AppKeys.RedirectTo, request.getContextPath() + "/knowledge/view.do?moduleId=" + moduleId); @@ -166,12 +173,17 @@ if (StringUtils.isNotEmpty(id) && !id.equals("0")) { po = knowledgeFileManager.getById(moduleId, id); + + // 查询当前文件的阅读记录 + List readRecordVoList = knowledgeFileManager.getReadRecordByknowledgeFileId(id); folderKeyId = po.getFolder().getId() + ""; request.setAttribute("folderKeyId", folderKeyId); // 需要设置值,在页面取到 TODO request.setAttribute(ATTACH_FILE_IDS, po.getAttachFiles()); + + model.addAttribute("readRecords",readRecordVoList); } else { Long folderId = Long.valueOf(0); Index: forgon-knowledge/src/main/java/com/forgon/knowledge/model/Vo/TrainingRecordVo.java =================================================================== diff -u --- forgon-knowledge/src/main/java/com/forgon/knowledge/model/Vo/TrainingRecordVo.java (revision 0) +++ forgon-knowledge/src/main/java/com/forgon/knowledge/model/Vo/TrainingRecordVo.java (revision 28827) @@ -0,0 +1,165 @@ +package com.forgon.knowledge.model.Vo; + +import java.util.Date; + +import com.forgon.tools.date.DateTools; + +/** + * 培训记录Vo(JMSZXYY-86) + * @author ZhouPeiMian + * @since 2020-08-21 + */ +public class TrainingRecordVo { + + private Long id; + + /** + * 培训主题 + */ + private String trainingTopic; + + /** + * 培训人 + */ + private String trainer; + + /** + * 培训地点 + */ + private String trainingPlace; + + /** + * 培训时间 + */ + private Date trainingTime; + + /** + * 登记人 + */ + private Long registrantId; + + /** + * 登记人姓名 + */ + private String registrant; + + /** + * 培训内容 + */ + private String trainingContent; + + /** + * 备注 + */ + private String remark; + + /** + * 培训参与人员编码,多个编码用","分割(1,2,3) + */ + private String userCodes; + + /** + * 培训参与人员姓名,多个姓名用"、"分割(张三,李四,李六) + */ + private String userNames; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getTrainingTopic() { + return trainingTopic; + } + + public void setTrainingTopic(String trainingTopic) { + this.trainingTopic = trainingTopic; + } + + public String getTrainer() { + return trainer; + } + + public void setTrainer(String trainer) { + this.trainer = trainer; + } + + public String getTrainingPlace() { + return trainingPlace; + } + + public void setTrainingPlace(String trainingPlace) { + this.trainingPlace = trainingPlace; + } + + public Date getTrainingTime() { + return trainingTime; + } + + public void setTrainingTime(Date trainingTime) { + this.trainingTime = trainingTime; + } + + public Long getRegistrantId() { + return registrantId; + } + + public void setRegistrantId(Long registrantId) { + this.registrantId = registrantId; + } + + public String getRegistrant() { + return registrant; + } + + public void setRegistrant(String registrant) { + this.registrant = registrant; + } + + public String getTrainingContent() { + return trainingContent; + } + + public void setTrainingContent(String trainingContent) { + this.trainingContent = trainingContent; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } + + public String getUserCodes() { + return userCodes; + } + + public void setUserCodes(String userCodes) { + this.userCodes = userCodes; + } + + public String getUserNames() { + return userNames; + } + + public void setUserNames(String userName) { + this.userNames = userName; + } + + /** + * 格式化培训时间(yyyy-MM-dd HH:mm) + * @return + */ + public String getTrainingTimeStr(){ + if(trainingTime == null){ + return ""; + } + return DateTools.getFormatDateStr(trainingTime, DateTools.COMMON_DATE_HM); + } + +} Index: forgon-knowledge/src/main/java/com/forgon/knowledge/action/TrainingRecordAction.java =================================================================== diff -u --- forgon-knowledge/src/main/java/com/forgon/knowledge/action/TrainingRecordAction.java (revision 0) +++ forgon-knowledge/src/main/java/com/forgon/knowledge/action/TrainingRecordAction.java (revision 28827) @@ -0,0 +1,128 @@ +package com.forgon.knowledge.action; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.sf.json.JSONObject; + +import org.apache.struts2.convention.annotation.Action; +import org.apache.struts2.convention.annotation.Namespace; +import org.apache.struts2.convention.annotation.ParentPackage; + +import com.forgon.knowledge.model.TrainingRecord; +import com.forgon.knowledge.model.Vo.TrainingRecordVo; +import com.forgon.knowledge.service.TrainingRecordManager; +import com.forgon.tools.StrutsParamUtils; +import com.forgon.tools.StrutsResponseUtils; +import com.forgon.tools.db.DatabaseUtil; +import com.forgon.tools.json.JSONUtil; +import com.opensymphony.xwork2.ModelDriven; +import com.opensymphony.xwork2.Preparable; + +@ParentPackage(value = "default") +@Namespace(value = "/disinfectSystem/baseData") +@Action(value = "trainingRecordAction") +public class TrainingRecordAction implements ModelDriven, Preparable { + + private TrainingRecord trainingRecord; + + private TrainingRecordManager trainingRecordManager; + + public void setTrainingRecordManager(TrainingRecordManager trainingRecordManager) { + this.trainingRecordManager = trainingRecordManager; + } + + /** + * 保存培训记录 + */ + public void saveTrainingRecord(){ + JSONObject json = new JSONObject(); + JSONUtil.addSuccess(json, true); + JSONUtil.addMessage(json, "保存成功!"); + try { + String userCodes = StrutsParamUtils.getPraramValue("userCodes", ""); + trainingRecordManager.saveOrUpdateTrainingRecord(trainingRecord, userCodes); + } catch (Exception e) { + JSONUtil.addSuccess(json, false); + JSONUtil.addMessage(json, e.getMessage()); + } + StrutsResponseUtils.output(json); + } + + /** + * 删除培训记录 + */ + public void deleteTrainingRecord(){ + JSONObject json = new JSONObject(); + JSONUtil.addSuccess(json, true); + JSONUtil.addMessage(json, "删除成功!"); + try { + String trainingRecordIds = StrutsParamUtils.getPraramValue("trainingRecordIds", ""); + trainingRecordManager.deleteTrainingRecords(trainingRecordIds); + } catch (Exception e) { + JSONUtil.addSuccess(json, true); + JSONUtil.addMessage(json, e.getMessage()); + } + StrutsResponseUtils.output(json); + } + + /** + * 加载培训记录列表 + */ + public void findTrainingRecordList(){ + String firstIndex = StrutsParamUtils.getPraramValue("firstIndex", ""); + String maxResults = StrutsParamUtils.getPraramValue("maxResults", ""); + int firstIndexInt = 0; + int maxResultsInt = 0; + if(DatabaseUtil.isPoIdValid(firstIndex) && DatabaseUtil.isPoIdValid(maxResults)){ + firstIndexInt = Integer.parseInt(firstIndex); + maxResultsInt = Integer.parseInt(maxResults); + } + List trainingRecordVos = trainingRecordManager.findTrainingRecordList(firstIndexInt, maxResultsInt); + Map map = new HashMap(); + map.put("success", true); + map.put("data", trainingRecordVos); + JSONObject jsonObject = JSONObject.fromObject(map); + StrutsParamUtils.getResponse().setCharacterEncoding("UTF-8"); + StrutsResponseUtils.output(jsonObject); + } + + /** + * 加载培训记录 + */ + public void getTrainingRecord(){ + JSONObject jsonObject = new JSONObject(); + Map map = new HashMap(); + try { + TrainingRecordVo trainingRecordVo = trainingRecordManager.getTrainingRecordVoById(trainingRecord.getId()); + map.put("success", true); + map.put("data", trainingRecordVo); + jsonObject = JSONObject.fromObject(map); + StrutsParamUtils.getResponse().setCharacterEncoding("UTF-8"); + StrutsResponseUtils.output(jsonObject); + } catch (Exception e) { + e.printStackTrace(); + JSONUtil.addSuccess(jsonObject, false); + JSONUtil.addMessage(jsonObject, e.getMessage()); + } + StrutsResponseUtils.output(jsonObject); + } + + @Override + public void prepare() throws Exception { + String id = StrutsParamUtils.getPraramValue("id", ""); + trainingRecord = new TrainingRecord(); + if(DatabaseUtil.isPoIdValid(id)){ + trainingRecord = trainingRecordManager.get(id); + } else { + trainingRecord = new TrainingRecord(); + } + } + + @Override + public TrainingRecord getModel() { + return trainingRecord; + } + +} Index: forgon-knowledge/src/main/java/com/forgon/knowledge/action/ReadRecordAction.java =================================================================== diff -u --- forgon-knowledge/src/main/java/com/forgon/knowledge/action/ReadRecordAction.java (revision 0) +++ forgon-knowledge/src/main/java/com/forgon/knowledge/action/ReadRecordAction.java (revision 28827) @@ -0,0 +1,44 @@ +package com.forgon.knowledge.action; + +import net.sf.json.JSONObject; + +import org.apache.struts2.convention.annotation.Action; +import org.apache.struts2.convention.annotation.Namespace; +import org.apache.struts2.convention.annotation.ParentPackage; + +import com.forgon.knowledge.model.KnowledgeFile; +import com.forgon.knowledge.service.KnowledgeFileManager; +import com.forgon.tools.StrutsParamUtils; +import com.forgon.tools.StrutsResponseUtils; +import com.forgon.tools.json.JSONUtil; + +@ParentPackage(value = "default") +@Namespace(value = "/disinfectSystem/baseData") +@Action(value = "readRecordAction") +public class ReadRecordAction { + + private KnowledgeFileManager knowledgeFileManager; + + public void setKnowledgeFileManager(KnowledgeFileManager knowledgeFileManager) { + this.knowledgeFileManager = knowledgeFileManager; + } + + /** + * 增加阅读记录 + */ + public void accumulateReadRecord(){ + String moduleId = StrutsParamUtils.getPraramValue("moduleId", "0"); + String knowledgeFileId = StrutsParamUtils.getPraramValue("id", "0"); + JSONObject jsonObject = new JSONObject(); + try { + KnowledgeFile knowledgeFile = knowledgeFileManager.getById(moduleId, knowledgeFileId); + knowledgeFileManager.accumulateReadRecord(knowledgeFile); + JSONUtil.addSuccess(jsonObject, true); + JSONUtil.addMessage(jsonObject, "更新成功!"); + } catch (Exception e) { + JSONUtil.addSuccess(jsonObject, false); + JSONUtil.addMessage(jsonObject, e.getMessage()); + } + StrutsResponseUtils.output(jsonObject); + } +}