diff --git a/.classpath b/.classpath index fec29fa000ad938b97cb65f31a816bbc8b277467..aa7956c2b14d8f1f5793177e89aec0812215375e 100644 --- a/.classpath +++ b/.classpath @@ -3,55 +3,56 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF index b3bec1a191969a42c1e00653ce39b86d413a6d48..cf66446d01593c0047ea7b6fcce2270c3bead9e0 100644 --- a/META-INF/MANIFEST.MF +++ b/META-INF/MANIFEST.MF @@ -15,7 +15,8 @@ Require-Bundle: org.eclipse.ui, com.ibm.icu Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ActivationPolicy: lazy -Bundle-ClassPath: lib/commons-codec-1.13.jar, +Bundle-ClassPath: ., + lib/commons-codec-1.13.jar, lib/commons-collections4-4.4.jar, lib/commons-lang3-3.9.jar, lib/commons-logging-1.2.jar, @@ -61,8 +62,8 @@ Bundle-ClassPath: lib/commons-codec-1.13.jar, lib/sqlite-jdbc-3.23.1.jar, lib/swtgraphics2d.jar, lib/xmlbeans-3.1.0.jar, - ., lib/mysql-connector-java-5.1.49.jar, lib/shiro-all-1.3.2.jar, lib/slf4j-api-1.6.1.jar, - lib/slf4j-log4j12-1.6.1.jar + lib/slf4j-log4j12-1.6.1.jar, + lib/commons-io-1.3.2.jar diff --git a/build.properties b/build.properties index 5b17300b8cdc092db748105135b9a28f17952cc5..a835bf0ecd0eaf414e4f8205f5ae0fddfaaa8780 100644 --- a/build.properties +++ b/build.properties @@ -52,5 +52,6 @@ bin.includes = plugin.xml,\ lib/mysql-connector-java-5.1.49.jar,\ lib/shiro-all-1.3.2.jar,\ lib/slf4j-api-1.6.1.jar,\ - lib/slf4j-log4j12-1.6.1.jar + lib/slf4j-log4j12-1.6.1.jar,\ + lib/commons-io-1.3.2.jar source.. = src/ diff --git a/lib/commons-io-1.3.2.jar b/lib/commons-io-1.3.2.jar new file mode 100644 index 0000000000000000000000000000000000000000..865c9e41cee5e3f65a734965aa1c2699b069b08e Binary files /dev/null and b/lib/commons-io-1.3.2.jar differ diff --git a/src/cn/edu/hit/education/action/AddCourseAction.java b/src/cn/edu/hit/education/action/AddCourseAction.java new file mode 100644 index 0000000000000000000000000000000000000000..1bc9dccfd2623ac2f58b7faf1c250d2f1c628712 --- /dev/null +++ b/src/cn/edu/hit/education/action/AddCourseAction.java @@ -0,0 +1,47 @@ +package cn.edu.hit.education.action; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +import cn.edu.hit.education.dialog.CourseDialog; +import cn.edu.hit.education.pojo.Course; +import cn.edu.hit.education.service.ICourseService; +import cn.edu.hit.education.view.CourseExploreView; +import educationschedule.Activator; +import educationschedule.Application; + +public class AddCourseAction extends Action { + private CourseExploreView viewPart; + ICourseService courseService = (ICourseService)Application.applicationContext.getBean("courseServiceImpl"); + private int propertyId; + + public AddCourseAction(CourseExploreView viewPart,int propertyId){ + this.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/toolbar/course_code_16px.png")); + this.setToolTipText("增加课程"); + this.setText("增加课程"); + this.viewPart = viewPart; + this.propertyId = propertyId; + } + + @Override + public void run() { + Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + CourseDialog courseDialog = new CourseDialog(parentShell); + Course course = new Course(); + course.setPropertyId(propertyId); + courseDialog.setCourse(course); + if(IDialogConstants.OK_ID == courseDialog.open()){ + int count = courseService.insert(course); + if(count > 0){ + viewPart.refreshNewData(course); + } + } + super.run(); + } + + + +} diff --git a/src/cn/edu/hit/education/action/AddNewCourseAction.java b/src/cn/edu/hit/education/action/AddNewCourseAction.java index 4771ca1ae62c8ba08908bd1727c7a1973e54c36b..2c2cd9144ab25fc1c3a0f92a5d85d023621c00a3 100644 --- a/src/cn/edu/hit/education/action/AddNewCourseAction.java +++ b/src/cn/edu/hit/education/action/AddNewCourseAction.java @@ -7,7 +7,7 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.plugin.AbstractUIPlugin; -import cn.edu.hit.education.dialog.AddNewCourseDialog; +import cn.edu.hit.education.dialog.CourseDialog; import cn.edu.hit.education.service.ICourseService; import cn.edu.hit.education.service.IScheduleService; import educationschedule.Activator; @@ -32,7 +32,7 @@ public class AddNewCourseAction extends Action { public void run() { // TODO Auto-generated method stub Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); - AddNewCourseDialog dlg = new AddNewCourseDialog(parentShell); + CourseDialog dlg = new CourseDialog(parentShell); if(IDialogConstants.OK_ID == dlg.open()){ } diff --git a/src/cn/edu/hit/education/action/AddProcessAction.java b/src/cn/edu/hit/education/action/AddProcessAction.java new file mode 100644 index 0000000000000000000000000000000000000000..58db672ae86ce0725f7244be5e1bf33e7232abfa --- /dev/null +++ b/src/cn/edu/hit/education/action/AddProcessAction.java @@ -0,0 +1,44 @@ +package cn.edu.hit.education.action; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +import cn.edu.hit.education.dialog.ProcessDialog; +import cn.edu.hit.education.pojo.Process; +import cn.edu.hit.education.service.IProcessService; +import cn.edu.hit.education.view.CourseExploreView; +import educationschedule.Activator; +import educationschedule.Application; + +public class AddProcessAction extends Action { + private CourseExploreView viewPart; + IProcessService processService = (IProcessService)Application.applicationContext.getBean("processServiceImpl"); + + public AddProcessAction(CourseExploreView viewPart){ + this.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/toolbar/course_code_16px.png")); + this.setToolTipText("增加平台"); + this.setText("增加平台"); + this.viewPart = viewPart; + } + + @Override + public void run() { + Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + ProcessDialog processDialog = new ProcessDialog(parentShell); + Process process = new Process(); + processDialog.setProcess(process); + if(IDialogConstants.OK_ID == processDialog.open()){ + int count = processService.insert(process); + if(count > 0){ + viewPart.refreshNewData(process); + } + } + super.run(); + } + + + +} diff --git a/src/cn/edu/hit/education/action/AddPropertyAction.java b/src/cn/edu/hit/education/action/AddPropertyAction.java new file mode 100644 index 0000000000000000000000000000000000000000..f229827cec1f60f62b5abc5ca15932455d9dbe93 --- /dev/null +++ b/src/cn/edu/hit/education/action/AddPropertyAction.java @@ -0,0 +1,48 @@ +package cn.edu.hit.education.action; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +import cn.edu.hit.education.dialog.ProcessDialog; +import cn.edu.hit.education.dialog.PropertyDialog; +import cn.edu.hit.education.pojo.Property; +import cn.edu.hit.education.service.IPropertyService; +import cn.edu.hit.education.view.CourseExploreView; +import educationschedule.Activator; +import educationschedule.Application; + +public class AddPropertyAction extends Action { + private CourseExploreView viewPart; + IPropertyService propertyService = (IPropertyService)Application.applicationContext.getBean("propertyServiceImpl"); + private int processId; + + public AddPropertyAction(CourseExploreView viewPart,int processId){ + this.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/toolbar/course_code_16px.png")); + this.setToolTipText("增加课程性质"); + this.setText("增加课程性质"); + this.processId = processId; + this.viewPart = viewPart; + } + + @Override + public void run() { + Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + PropertyDialog propertyDialog = new PropertyDialog(parentShell); + Property property = new Property(); + property.setProcessId(processId); + propertyDialog.setProperty(property); + if(IDialogConstants.OK_ID == propertyDialog.open()){ + int count = propertyService.insert(property); + if(count > 0){ + viewPart.refreshNewData(property); + } + } + super.run(); + } + + + +} diff --git a/src/cn/edu/hit/education/action/ExportAction.java b/src/cn/edu/hit/education/action/ExportAction.java index d8507a21f12744c445588704585ccee692c6107d..e4d3470c1386c19d24565ca92b4c1d1369cb3b6b 100644 --- a/src/cn/edu/hit/education/action/ExportAction.java +++ b/src/cn/edu/hit/education/action/ExportAction.java @@ -6,6 +6,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import org.apache.poi.hssf.usermodel.DVConstraint; import org.apache.poi.hssf.usermodel.HSSFDataValidation; @@ -13,9 +14,12 @@ import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.util.CellRangeAddressList; +import org.apache.shiro.SecurityUtils; +import org.apache.shiro.subject.Subject; import org.eclipse.jface.action.Action; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.plugin.AbstractUIPlugin; @@ -23,14 +27,21 @@ import org.eclipse.ui.plugin.AbstractUIPlugin; import cn.edu.hit.education.pojo.Course; import cn.edu.hit.education.pojo.Property; import cn.edu.hit.education.pojo.Specialty; +import cn.edu.hit.education.pojo.User; import cn.edu.hit.education.service.ICourseService; import cn.edu.hit.education.service.IPropertyService; +import cn.edu.hit.education.service.ISpecialtyService; +import cn.edu.hit.education.service.IUserSpeciatyService; +import cn.edu.hit.education.service.SpecialtyServiceImpl; +import cn.edu.hit.education.service.UserSpeciatyServiceImpl; import educationschedule.Activator; import educationschedule.Application; public class ExportAction extends Action { ICourseService courseService = (ICourseService)Application.applicationContext.getBean("courseServiceImpl"); IPropertyService propertyService = (IPropertyService)Application.applicationContext.getBean("propertyServiceImpl"); + IUserSpeciatyService userSpeciatyService = Application.applicationContext.getBean(UserSpeciatyServiceImpl.class); + ISpecialtyService specialtyService = Application.applicationContext.getBean(SpecialtyServiceImpl.class); public ExportAction(){ this.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/toolbar/export_16px.png")); @@ -42,7 +53,17 @@ public class ExportAction extends Action { public void run() { // TODO Auto-generated method stub Specialty specialty = new Specialty(); - specialty.setName("导出课程"); + List specialties = new ArrayList<>(); + + //根据普通用户的用户Id查询到关联的专业Id + Subject subject = SecurityUtils.getSubject(); + User user = (User) subject.getPrincipal(); + List ids = userSpeciatyService.querySpeciatyIdsByUser(user.getId()); + specialties = specialtyService.queryRelativeSpecialty(ids); + + specialty.setName(specialties.get(0).getName()); + + Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); FileDialog fileDialog = new FileDialog(parentShell,SWT.SAVE); @@ -75,13 +96,21 @@ public class ExportAction extends Action { strClassroom.add("讲座"); List courses = courseService.queryAllCourse(); + Map courserPropertyMap = getMap(courses, properties);//课程与课程属性的映射关系 + try { - test(filename,specialty, + test(courserPropertyMap,filename,specialty, String.join(",", strProperties),String.join(",", strImportant), String.join(",", strUnit), String.join(",",strSelected), String.join(",",strMethod), String.join(",",strClassroom), courses); + + MessageBox messageBox=new MessageBox(parentShell,SWT.OK|SWT.ICON_INFORMATION); + messageBox.setText("提示!"); + messageBox.setMessage("导出成功!"); + messageBox.open(); + } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -91,7 +120,7 @@ public class ExportAction extends Action { super.run(); } - public void test(String filename,Specialty specialty, + public void test(Map courserPropertyMap,String filename,Specialty specialty, String strProperties,String strImportant, String strUnit,String strSelected, String strMethod,String strClassRoom, @@ -165,16 +194,23 @@ public class ExportAction extends Action { sheet.addValidationData(dataValidationClassroom); } /////////////////////////////////////////////////// + for (int i = 0;i < courses.size();i++) { Course theCourse = courses.get(i); HSSFRow newRow = sheet.createRow(i + 1); newRow.createCell(0).setCellValue(specialty.getName()); + newRow.createCell(1).setCellValue(courserPropertyMap.get(theCourse.getName())); newRow.createCell(2).setCellValue(theCourse.getName()); newRow.createCell(3).setCellValue(String.valueOf(theCourse.getCredits())); + newRow.createCell(4).setCellValue(String.valueOf((theCourse.getImportant() == 1?"是":"否"))); newRow.createCell(5).setCellValue(theCourse.getNumber()); newRow.createCell(6).setCellValue(String.valueOf(theCourse.getPeriod())); newRow.createCell(7).setCellValue(String.valueOf(theCourse.getTheoretical())); newRow.createCell(8).setCellValue(String.valueOf(theCourse.getExperiment())); + newRow.createCell(9).setCellValue(String.valueOf(theCourse.getUnit())); + newRow.createCell(10).setCellValue(String.valueOf(theCourse.getSelected())); + newRow.createCell(11).setCellValue(String.valueOf(theCourse.getMethod())); + newRow.createCell(12).setCellValue(String.valueOf(theCourse.getClassroom())); newRow.createCell(13).setCellValue("1"); newRow.createCell(14).setCellValue("16"); newRow.createCell(15).setCellValue(""); @@ -184,6 +220,27 @@ public class ExportAction extends Action { hssfWorkbook.write(out); out.close(); } + + /** + * 获取课程和课程属性的映射关系 + *

Title: getMap

+ *

Description:

+ * @param courses + * @param properties + * @return + */ + public Map getMap(List courses,List properties){ + HashMap coursePropertyMap = new HashMap<>(); + for(Course course : courses){ + for(Property property :properties){ + if(property.getId() == course.getPropertyId()){ + coursePropertyMap.put(course.getName(), property.getName()); + } + } + } + return coursePropertyMap; + + } public HSSFDataValidation createBox(String col, Map boxMap, int firstRow, int lastRow, int firstCol, int lastCol) { diff --git a/src/cn/edu/hit/education/action/ImportAction.java b/src/cn/edu/hit/education/action/ImportAction.java index cc5e1a60efef7e7de0caaef1e259e45223ac5a5d..82e090e940de937911097d784b35be86513b0a7e 100644 --- a/src/cn/edu/hit/education/action/ImportAction.java +++ b/src/cn/edu/hit/education/action/ImportAction.java @@ -1,39 +1,396 @@ package cn.edu.hit.education.action; +import java.io.IOException; +import java.util.List; +import java.util.Map; + +import org.apache.shiro.SecurityUtils; +import org.apache.shiro.subject.Subject; import org.eclipse.jface.action.Action; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.plugin.AbstractUIPlugin; +import cn.edu.hit.education.pojo.Course; +import cn.edu.hit.education.pojo.CourseTo; +import cn.edu.hit.education.pojo.Property; +import cn.edu.hit.education.pojo.Specialty; +import cn.edu.hit.education.pojo.User; import cn.edu.hit.education.service.ICourseService; +import cn.edu.hit.education.service.IPropertyService; +import cn.edu.hit.education.service.ISpecialtyService; +import cn.edu.hit.education.service.IUserSpeciatyService; +import cn.edu.hit.education.service.PropertyServiceImpl; +import cn.edu.hit.education.service.SpecialtyServiceImpl; +import cn.edu.hit.education.service.UserSpeciatyServiceImpl; +import cn.edu.hit.education.utils.ExcelUtil; import educationschedule.Activator; import educationschedule.Application; +/** + * 导入课程,如果重复且更新,则覆盖原有课程,如果重复无更新,不做任何操作!没有则新增一条数据。 + *

+ * Title: ImportAction + *

+ *

+ * Description: + *

+ * + * @author 罗成 + * @date 2021年5月9日 + */ public class ImportAction extends Action { - ICourseService courseService = (ICourseService)Application.applicationContext.getBean("courseServiceImpl"); - - public ImportAction(){ - this.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/toolbar/import_16px.png")); + ICourseService courseService = (ICourseService) Application.applicationContext + .getBean("courseServiceImpl"); + IUserSpeciatyService userSpeciatyService = Application.applicationContext + .getBean(UserSpeciatyServiceImpl.class); + ISpecialtyService specialtyService = Application.applicationContext + .getBean(SpecialtyServiceImpl.class); + IPropertyService propertyService = Application.applicationContext + .getBean(PropertyServiceImpl.class); + + private List speciatyids = null; + + public ImportAction() { + this.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin( + Activator.PLUGIN_ID, "icons/toolbar/import_16px.png")); this.setToolTipText("导入课程"); this.setText("导出课程"); } - + @Override public void run() { // TODO Auto-generated method stub - Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); - FileDialog fileDialog = new FileDialog(parentShell,SWT.OPEN); - fileDialog.setFilterExtensions(new String[]{"*.xls"}); - String filename ; + Shell parentShell = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow().getShell(); + FileDialog fileDialog = new FileDialog(parentShell, SWT.OPEN); + fileDialog.setFilterExtensions(new String[] { "*.xls" }); + String filename; filename = fileDialog.open(); - if(filename != null){ - System.out.println(filename); + if (filename != null) { + try { + read(filename); + MessageBox messageBox=new MessageBox(parentShell,SWT.OK|SWT.ICON_INFORMATION); + messageBox.setText("提示"); + messageBox.setMessage("导入成功!"); + messageBox.open(); + } catch (IOException e) { + MessageBox messageBox=new MessageBox(parentShell,SWT.OK|SWT.ICON_INFORMATION); + messageBox.setText("导入失败!!"); + messageBox.setMessage("原因:导入异常!" ); + messageBox.open(); + } catch(NumberFormatException e ){ + MessageBox messageBox=new MessageBox(parentShell,SWT.OK|SWT.ICON_INFORMATION); + messageBox.setText("部分课程信息未能导入!"); + messageBox.setMessage("原因:课程信息不允许留空!请修改表格后重新导入!" ); + messageBox.open(); + }catch(RuntimeException e){ + MessageBox messageBox=new MessageBox(parentShell,SWT.OK|SWT.ICON_INFORMATION); + messageBox.setText("导入失败!!"); + messageBox.setMessage("原因:" + e.getMessage()); + messageBox.open(); + } } super.run(); } + + /** + * xls表格导入 + *

Title: read

+ *

Description:

+ * @param filename + * @throws IOException + */ + public void read(String filename) throws IOException { + Subject subject = SecurityUtils.getSubject(); + // 根据普通用户的用户Id查询到关联的专业Id (只能操作修改本专业下课程,避免覆盖其他专业同名课程) + User user = (User) subject.getPrincipal(); + speciatyids = userSpeciatyService.querySpeciatyIdsByUser(user.getId()); + List courseFromDb = courseService + .queryAllCourseBySpecityId(speciatyids); + + ExcelUtil excel = new ExcelUtil(); + List> listmap = excel.readExcel(filename); + if (listmap != null) { + for (Map map : listmap) { + boolean hasEquals = false; + for (Course course : courseFromDb) { + String nameFromEx = (String) map.get("课程名称"); + String nameFromDb = course.getName(); + //课程名称相同,再判断其他值是否全部相同 + if (nameFromEx.equals(nameFromDb)) { + + //从Excel获取的数据封装为Course对象, + Course courseFroEx = courseMapToObj(map); + //重写的equals方法,避免多次覆盖数据库数据,造成多次IO导致系统慢 + if(course.equals(courseFroEx)){ + System.out.println("数据一致,不用修改!"); + hasEquals = true; + break; + } + + updateCourse(course.getId(), map); + System.out.println("修改了数据库!"); + hasEquals = true; + break; + } + } + String nameFromEx = (String) map.get("课程名称"); + if("".equals(nameFromEx)){ + return; + } + if(hasEquals == false){ + insertCourse(map); + } + + } + } + + } + + /** + * 增加一门课程 + *

Title: insertCourse

+ *

Description:

+ * @param coursemMap + */ + private void insertCourse(Map coursemMap) { + Course course = new Course(); + Specialty specialty = specialtyService.queryByPrimaryKey(speciatyids + .get(0));// 一个教研主任只负责一个专业的增删改,默认取用户拥有权限的第一个专业id + + // 如果添加课程的专业与用户权限不符,导入失败抛出异常 + String nameFromEx = (String) coursemMap.get("专业名称"); + String nameFromDb = specialty.getName(); + if (!nameFromEx.equals(nameFromDb)) { + throw new RuntimeException("只能为" + specialty.getName() + "添加课程!"); + } else { + + // 设置专业Id + course.setSpecialtyId(speciatyids.get(0)); + + // 设置课程性质Id + Property property = propertyService.queryPropertyByName(String + .valueOf(coursemMap.get("课程性质"))); + if (property != null) { + + course.setPropertyId(property.getId()); + } + + // 设置课程名称 + course.setName(String.valueOf(coursemMap.get("课程名称"))); + + // 设置课程学分 + course.setCredits(Double.valueOf((String) coursemMap.get("课程学分"))); + + // 设置是否核心 + course.setImportant(coursemMap.get("是否核心").equals("是") ? 1 : 0); + + // 设置课程编号 + course.setNumber((String) coursemMap.get("课程编号")); + + // 设置课程学时 + course.setPeriod(Double.valueOf((String) coursemMap.get("课程学时"))); + + // 设置理论学时 + course.setTheoretical(Double.valueOf((String) coursemMap + .get("理论学时"))); + // 设置实验学时 + + course.setExperiment(Double.valueOf((String) coursemMap.get("实验学时"))); + + // 学时单位 + course.setUnit((String) coursemMap.get("实验学时")); + + // 设置课程选修 + + course.setSelected((String) coursemMap.get("课程选修")); + + // 设置授课类型 + + course.setMethod((String) coursemMap.get("授课类型")); + // 设置授课方式 + course.setClassroom((String) coursemMap.get("授课方式")); + // 设置开始时间 + + course.setStart(Integer.valueOf((String) coursemMap.get("开始时间"))); + + // 设置结束时间 + course.setEnd(Integer.valueOf((String) coursemMap.get("结束时间"))); + // 设置课程备注 + course.setNote((String) coursemMap.get("课程备注")); + + int insert = courseService.insert(course); + + System.out.println("插入成功!"); + + } + + } + + /** + * 接受来自Excel的每一个map,封装成CourseTo对象 + *

Title: courseMapToObj

+ *

Description:

+ * @param coursemMap + * @return + */ + public Course courseMapToObj(Map coursemMap){ + Course course = new Course(); + Specialty specialty = specialtyService.queryByPrimaryKey(speciatyids + .get(0));// 一个教研主任只负责一个专业的增删改,默认取用户拥有权限的第一个专业id + + // 如果添加课程的专业与用户权限不符,导入失败抛出异常 + String nameFromEx = (String) coursemMap.get("专业名称"); + String nameFromDb = specialty.getName(); + if (!nameFromEx.equals(nameFromDb)) { + throw new RuntimeException("只能为" + specialty.getName() + "添加课程!"); + } else { + // 设置专业Id + course.setSpecialtyId(speciatyids.get(0)); + + // 设置课程性质Id + Property property = propertyService.queryPropertyByName(String + .valueOf(coursemMap.get("课程性质"))); + if (property != null) { + + course.setPropertyId(property.getId()); + } + // 设置课程名称 + course.setName(String.valueOf(coursemMap.get("课程名称"))); + + // 设置课程学分 + course.setCredits(Double.valueOf((String) coursemMap.get("课程学分"))); + + // 设置是否核心 + course.setImportant(coursemMap.get("是否核心").equals("是") ? 1 : 0); + + // 设置课程编号 + course.setNumber((String) coursemMap.get("课程编号")); + + // 设置课程学时 + course.setPeriod(Double.valueOf((String) coursemMap.get("课程学时"))); + + // 设置理论学时 + course.setTheoretical(Double.valueOf((String) coursemMap + .get("理论学时"))); + // 设置实验学时 + + course.setExperiment(Double.valueOf((String) coursemMap.get("实验学时"))); + + // 学时单位 + course.setUnit((String) coursemMap.get("实验学时")); + + // 设置课程选修 + + course.setSelected((String) coursemMap.get("课程选修")); + + // 设置授课类型 + + course.setMethod((String) coursemMap.get("授课类型")); + // 设置授课方式 + course.setClassroom((String) coursemMap.get("授课方式")); + // 设置开始时间 + + course.setStart(Integer.valueOf((String) coursemMap.get("开始时间"))); + + // 设置结束时间 + course.setEnd(Integer.valueOf((String) coursemMap.get("结束时间"))); + // 设置课程备注 + course.setNote((String) coursemMap.get("课程备注")); + + } + + + return course; + + } + /** + * 更新或覆盖一门课程! + *

Title: updateCourse

+ *

Description:

+ * @param id + * @param coursemMap + */ + private void updateCourse(Integer id, Map coursemMap) { + // TODO Auto-generated method stub + Course course = new Course(); + Specialty specialty = specialtyService.queryByPrimaryKey(speciatyids + .get(0));// 一个教研主任只负责一个专业的增删改,默认取用户拥有权限的第一个专业id + + // 如果添加课程的专业与用户权限不符,导入失败抛出异常 + String nameFromEx = (String) coursemMap.get("专业名称"); + String nameFromDb = specialty.getName(); + if (!nameFromEx.equals(nameFromDb)) { + throw new RuntimeException("只能为" + specialty.getName() + "添加课程!"); + } else { + // 设置专业Id + course.setSpecialtyId(speciatyids.get(0)); + + // 设置课程性质Id + Property property = propertyService.queryPropertyByName(String + .valueOf(coursemMap.get("课程性质"))); + if (property != null) { + + course.setPropertyId(property.getId()); + } + + // 设置课程名称 + course.setName(String.valueOf(coursemMap.get("课程名称"))); + + // 设置课程学分 + course.setCredits(Double.valueOf((String) coursemMap.get("课程学分"))); + + // 设置是否核心 + course.setImportant(coursemMap.get("是否核心").equals("是") ? 1 : 0); + + // 设置课程编号 + course.setNumber((String) coursemMap.get("课程编号")); + + // 设置课程学时 + course.setPeriod(Double.valueOf((String) coursemMap.get("课程学时"))); + + // 设置理论学时 + course.setTheoretical(Double.valueOf((String) coursemMap + .get("理论学时"))); + // 设置实验学时 + + course.setExperiment(Double.valueOf((String) coursemMap.get("实验学时"))); + + // 学时单位 + course.setUnit((String) coursemMap.get("实验学时")); + + // 设置课程选修 + + course.setSelected((String) coursemMap.get("课程选修")); + + // 设置授课类型 + + course.setMethod((String) coursemMap.get("授课类型")); + // 设置授课方式 + course.setClassroom((String) coursemMap.get("授课方式")); + // 设置开始时间 + + course.setStart(Integer.valueOf((String) coursemMap.get("开始时间"))); + + // 设置结束时间 + course.setEnd(Integer.valueOf((String) coursemMap.get("结束时间"))); + // 设置课程备注 + course.setNote((String) coursemMap.get("课程备注")); + + // 设置couseId + course.setId(id); + + int update = courseService.update(course); + System.out.println("修改成功!"); + + } + + } } diff --git a/src/cn/edu/hit/education/action/UpdateCourseAction.java b/src/cn/edu/hit/education/action/UpdateCourseAction.java new file mode 100644 index 0000000000000000000000000000000000000000..645a65d4698a0b586926530ad6933f0688cca0a5 --- /dev/null +++ b/src/cn/edu/hit/education/action/UpdateCourseAction.java @@ -0,0 +1,46 @@ +package cn.edu.hit.education.action; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +import cn.edu.hit.education.dialog.CourseDialog; +import cn.edu.hit.education.pojo.Course; +import cn.edu.hit.education.service.ICourseService; +import cn.edu.hit.education.view.CourseExploreView; +import educationschedule.Activator; +import educationschedule.Application; + +public class UpdateCourseAction extends Action { + private CourseExploreView viewPart; + ICourseService courseService = (ICourseService)Application.applicationContext.getBean("courseServiceImpl"); + private int courseId; + + public UpdateCourseAction(CourseExploreView viewPart,int courseId){ + this.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/toolbar/course_code_16px.png")); + this.setToolTipText("修改课程"); + this.setText("修改课程"); + this.viewPart = viewPart; + this.courseId = courseId; + } + + @Override + public void run() { + Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + CourseDialog courseDialog = new CourseDialog(parentShell); + Course course = courseService.queryCourseByPrimaryKey(courseId); + courseDialog.setCourse(course); + if(IDialogConstants.OK_ID == courseDialog.open()){ + int count = courseService.update(course); + if(count > 0){ + viewPart.refreshUpdateData(course); + } + } + super.run(); + } + + + +} diff --git a/src/cn/edu/hit/education/action/UpdateProcessAction.java b/src/cn/edu/hit/education/action/UpdateProcessAction.java new file mode 100644 index 0000000000000000000000000000000000000000..9654d015b0fc27e96aa59189b75e7dd747811559 --- /dev/null +++ b/src/cn/edu/hit/education/action/UpdateProcessAction.java @@ -0,0 +1,46 @@ +package cn.edu.hit.education.action; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +import cn.edu.hit.education.dialog.ProcessDialog; +import cn.edu.hit.education.pojo.Process; +import cn.edu.hit.education.service.IProcessService; +import cn.edu.hit.education.view.CourseExploreView; +import educationschedule.Activator; +import educationschedule.Application; + +public class UpdateProcessAction extends Action { + private CourseExploreView viewPart; + IProcessService processService = (IProcessService)Application.applicationContext.getBean("processServiceImpl"); + private int processId; + + public UpdateProcessAction(CourseExploreView viewPart,int processId){ + this.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/toolbar/course_code_16px.png")); + this.setToolTipText("修改过程"); + this.setText("修改过程"); + this.viewPart = viewPart; + this.processId = processId; + } + + @Override + public void run() { + Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + ProcessDialog processDialog = new ProcessDialog(parentShell); + Process process = processService.queryProcessByPrimaryKey(processId); + processDialog.setProcess(process); + if(IDialogConstants.OK_ID == processDialog.open()){ + int count = processService.update(process); + if(count > 0){ + viewPart.refreshUpdateData(process); + } + } + super.run(); + } + + + +} diff --git a/src/cn/edu/hit/education/action/UpdatePropertyAction.java b/src/cn/edu/hit/education/action/UpdatePropertyAction.java new file mode 100644 index 0000000000000000000000000000000000000000..faed2640e6d1e44ef3f53097b01afc5f5abb4f94 --- /dev/null +++ b/src/cn/edu/hit/education/action/UpdatePropertyAction.java @@ -0,0 +1,46 @@ +package cn.edu.hit.education.action; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +import cn.edu.hit.education.dialog.PropertyDialog; +import cn.edu.hit.education.pojo.Property; +import cn.edu.hit.education.service.IPropertyService; +import cn.edu.hit.education.view.CourseExploreView; +import educationschedule.Activator; +import educationschedule.Application; + +public class UpdatePropertyAction extends Action { + private CourseExploreView viewPart; + IPropertyService propertyService = (IPropertyService)Application.applicationContext.getBean("propertyServiceImpl"); + private int propertyId; + + public UpdatePropertyAction(CourseExploreView viewPart,int propertyId){ + this.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/toolbar/course_code_16px.png")); + this.setToolTipText("修改性质"); + this.setText("修改性质"); + this.viewPart = viewPart; + this.propertyId = propertyId; + } + + @Override + public void run() { + Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + PropertyDialog propertyDialog = new PropertyDialog(parentShell); + Property property = propertyService.queryPropertyByPrimaryKey(propertyId); + propertyDialog.setProperty(property); + if(IDialogConstants.OK_ID == propertyDialog.open()){ + int count = propertyService.update(property); + if(count > 0){ + viewPart.refreshUpdateData(property); + } + } + super.run(); + } + + + +} diff --git a/src/cn/edu/hit/education/dao/PropertyMapper.java b/src/cn/edu/hit/education/dao/PropertyMapper.java index 6845e067b62f69dbe18804a3e6bbb8f41993314e..adcf55009f1470a26a0b2e9de303176dec09545c 100644 --- a/src/cn/edu/hit/education/dao/PropertyMapper.java +++ b/src/cn/edu/hit/education/dao/PropertyMapper.java @@ -2,8 +2,11 @@ package cn.edu.hit.education.dao; import cn.edu.hit.education.pojo.Property; import cn.edu.hit.education.pojo.PropertyExample; + import java.util.List; + import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; public interface PropertyMapper { /** @@ -93,4 +96,7 @@ public interface PropertyMapper { * @mbggenerated Tue Apr 27 10:55:58 CST 2021 */ int updateByPrimaryKey(Property record); + + @Select("select * from property where name=#{name}") + Property queryPropertyByName(String name); } \ No newline at end of file diff --git a/src/cn/edu/hit/education/dialog/AddNewCourseDialog.java b/src/cn/edu/hit/education/dialog/CourseDialog.java similarity index 82% rename from src/cn/edu/hit/education/dialog/AddNewCourseDialog.java rename to src/cn/edu/hit/education/dialog/CourseDialog.java index edb08ea5aafc3e7b37ccbd7cf77af765f2a87c91..af61beabc8e0b5e55a0c841b2cfba6288ac6a653 100644 --- a/src/cn/edu/hit/education/dialog/AddNewCourseDialog.java +++ b/src/cn/edu/hit/education/dialog/CourseDialog.java @@ -4,19 +4,25 @@ import java.text.DecimalFormat; import org.eclipse.jface.dialogs.TitleAreaDialog; import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import cn.edu.hit.education.pojo.Course; import educationschedule.Activator; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Text; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Combo; +import org.eclipse.core.databinding.DataBindingContext; +import org.eclipse.core.databinding.observable.value.IObservableValue; +import org.eclipse.jface.databinding.swt.WidgetProperties; +import org.eclipse.core.databinding.beans.PojoProperties; -public class AddNewCourseDialog extends TitleAreaDialog { +public class CourseDialog extends TitleAreaDialog { + private DataBindingContext m_bindingContext; IPreferenceStore store = Activator.getDefault().getPreferenceStore(); private DecimalFormat df2 = new DecimalFormat("0.00"); private Text text; @@ -26,8 +32,9 @@ public class AddNewCourseDialog extends TitleAreaDialog { private Text textCoursePeriod; private Text textCourseTheoretical; private Text textCourseExperiment; + private Course course; - public AddNewCourseDialog(Shell parentShell) { + public CourseDialog(Shell parentShell) { super(parentShell); // TODO Auto-generated constructor stub } @@ -117,6 +124,7 @@ public class AddNewCourseDialog extends TitleAreaDialog { text = new Text(composite, SWT.BORDER); text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));*/ + m_bindingContext = initDataBindings(); return composite; } @@ -124,4 +132,21 @@ public class AddNewCourseDialog extends TitleAreaDialog { super.configureShell(newShell); newShell.setText("添加新的课程"); } + + public Course getCourse() { + return course; + } + + public void setCourse(Course course) { + this.course = course; + } + protected DataBindingContext initDataBindings() { + DataBindingContext bindingContext = new DataBindingContext(); + // + IObservableValue observeTextTextCourseNameObserveWidget = WidgetProperties.text(SWT.Modify).observe(textCourseName); + IObservableValue nameCourseObserveValue = PojoProperties.value("name").observe(course); + bindingContext.bindValue(observeTextTextCourseNameObserveWidget, nameCourseObserveValue, null, null); + // + return bindingContext; + } } diff --git a/src/cn/edu/hit/education/dialog/ProcessDialog.java b/src/cn/edu/hit/education/dialog/ProcessDialog.java new file mode 100644 index 0000000000000000000000000000000000000000..4b2047ef01d8a103d2a9d225d7f2ef9588414da0 --- /dev/null +++ b/src/cn/edu/hit/education/dialog/ProcessDialog.java @@ -0,0 +1,92 @@ +package cn.edu.hit.education.dialog; + +import java.text.DecimalFormat; + +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +import cn.edu.hit.education.pojo.Process; +import educationschedule.Activator; +import org.eclipse.core.databinding.DataBindingContext; +import org.eclipse.core.databinding.observable.value.IObservableValue; +import org.eclipse.jface.databinding.swt.WidgetProperties; +import org.eclipse.core.databinding.beans.PojoProperties; + +public class ProcessDialog extends TitleAreaDialog { + private DataBindingContext m_bindingContext; + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + private DecimalFormat df2 = new DecimalFormat("0.00"); + private Text text; + private Text textName; + private Text textNode; + private Process process; + + public ProcessDialog(Shell parentShell) { + super(parentShell); + // TODO Auto-generated constructor stub + } + + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + composite.setLayout(new GridLayout(1, false)); + + Composite composite_1 = new Composite(composite, SWT.NONE); + composite_1.setLayout(new GridLayout(2, false)); + composite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); + + Label label = new Label(composite_1, SWT.NONE); + label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + label.setText("平台名称"); + + textName = new Text(composite_1, SWT.BORDER); + textName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + + Label label_2 = new Label(composite_1, SWT.NONE); + label_2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + label_2.setText("备 注"); + + textNode = new Text(composite_1, SWT.BORDER); + textNode.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + /*if(university != null && university.getNote() != null){ + textNode.setText(university.getNote()); + }*/ + m_bindingContext = initDataBindings(); + + return composite; + } + + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText("教育平台"); + } + + public Process getProcess() { + return process; + } + + public void setProcess(Process process) { + this.process = process; + } + + protected DataBindingContext initDataBindings() { + DataBindingContext bindingContext = new DataBindingContext(); + // + IObservableValue observeTextTextNameObserveWidget = WidgetProperties.text(SWT.Modify).observe(textName); + IObservableValue nameUniversityObserveValue = PojoProperties.value("name").observe(process); + bindingContext.bindValue(observeTextTextNameObserveWidget, nameUniversityObserveValue, null, null); + // + IObservableValue observeTextTextNodeObserveWidget = WidgetProperties.text(SWT.Modify).observe(textNode); + IObservableValue noteUniversityObserveValue = PojoProperties.value("note").observe(process); + bindingContext.bindValue(observeTextTextNodeObserveWidget, noteUniversityObserveValue, null, null); + // + return bindingContext; + } +} diff --git a/src/cn/edu/hit/education/dialog/PropertyDialog.java b/src/cn/edu/hit/education/dialog/PropertyDialog.java new file mode 100644 index 0000000000000000000000000000000000000000..880a3a2ea577d874ae98105338fda7860352473f --- /dev/null +++ b/src/cn/edu/hit/education/dialog/PropertyDialog.java @@ -0,0 +1,121 @@ +package cn.edu.hit.education.dialog; + +import java.text.DecimalFormat; + +import org.eclipse.core.databinding.DataBindingContext; +import org.eclipse.core.databinding.beans.PojoProperties; +import org.eclipse.core.databinding.observable.value.IObservableValue; +import org.eclipse.jface.databinding.swt.WidgetProperties; +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +import cn.edu.hit.education.pojo.Property; +import educationschedule.Activator; + +public class PropertyDialog extends TitleAreaDialog { + private DataBindingContext m_bindingContext; + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + private DecimalFormat df2 = new DecimalFormat("0.00"); + private Text text; + private Text textName; + private Text textCode; + private Text textNode; + private Property property; + private Label label_1; + private Label label_3; + private Combo comboNeed; + + public PropertyDialog(Shell parentShell) { + super(parentShell); + // TODO Auto-generated constructor stub + } + + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + composite.setLayout(new GridLayout(1, false)); + + Composite composite_1 = new Composite(composite, SWT.NONE); + composite_1.setLayout(new GridLayout(2, false)); + composite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); + + Label label = new Label(composite_1, SWT.NONE); + label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + label.setText("性质名称"); + + textName = new Text(composite_1, SWT.BORDER); + textName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + /*if(university != null && university.getName() != null){ + textName.setText(university.getName()); + }*/ + + label_1 = new Label(composite_1, SWT.NONE); + label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + label_1.setText("性质编码"); + + textCode = new Text(composite_1, SWT.BORDER); + textCode.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + /*if(university != null && university.getAddress() != null){ + textAddress.setText(university.getAddress()); + }*/ + + label_3 = new Label(composite_1, SWT.NONE); + label_3.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + label_3.setText("课程性质"); + + comboNeed = new Combo(composite_1, SWT.NONE); + comboNeed.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + + Label label_2 = new Label(composite_1, SWT.NONE); + label_2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + label_2.setText("备 注"); + + textNode = new Text(composite_1, SWT.BORDER); + textNode.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + /*if(university != null && university.getNote() != null){ + textNode.setText(university.getNote()); + }*/ + m_bindingContext = initDataBindings(); + + return composite; + } + + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText("课程性质"); + } + + public Property getProperty() { + return property; + } + + public void setProperty(Property property) { + this.property = property; + } + + protected DataBindingContext initDataBindings() { + DataBindingContext bindingContext = new DataBindingContext(); + // + IObservableValue observeTextTextNameObserveWidget = WidgetProperties.text(SWT.Modify).observe(textName); + IObservableValue nameUniversityObserveValue = PojoProperties.value("name").observe(property); + bindingContext.bindValue(observeTextTextNameObserveWidget, nameUniversityObserveValue, null, null); + // + IObservableValue observeTextTextAddressObserveWidget = WidgetProperties.text(SWT.Modify).observe(textCode); + IObservableValue addressUniversityObserveValue = PojoProperties.value("code").observe(property); + bindingContext.bindValue(observeTextTextAddressObserveWidget, addressUniversityObserveValue, null, null); + // + IObservableValue observeTextTextNodeObserveWidget = WidgetProperties.text(SWT.Modify).observe(textNode); + IObservableValue noteUniversityObserveValue = PojoProperties.value("note").observe(property); + bindingContext.bindValue(observeTextTextNodeObserveWidget, noteUniversityObserveValue, null, null); + // + return bindingContext; + } +} diff --git a/src/cn/edu/hit/education/labelprovider/CourseLabelProvider.java b/src/cn/edu/hit/education/labelprovider/CourseLabelProvider.java index 29ebf0da3c201e1ff6e5fa83529ccd8fc6e6dfd9..8103ebca05b5e51bdd5dff4c402ab7363220e265 100644 --- a/src/cn/edu/hit/education/labelprovider/CourseLabelProvider.java +++ b/src/cn/edu/hit/education/labelprovider/CourseLabelProvider.java @@ -10,11 +10,11 @@ import org.eclipse.swt.graphics.Image; import org.eclipse.ui.plugin.AbstractUIPlugin; import cn.edu.hit.education.model.CourseNode; +import cn.edu.hit.education.model.CourseRootNode; import cn.edu.hit.education.model.ProcessNode; import cn.edu.hit.education.model.PropertyNode; -import cn.edu.hit.education.model.CourseRootNode; +import cn.edu.hit.education.model.ResourceNode; import educationschedule.Activator; -import educationschedule.Application; public class CourseLabelProvider implements ILabelProvider { @@ -25,7 +25,10 @@ public class CourseLabelProvider implements ILabelProvider { public Image getImage(Object element) { ImageDescriptor descriptor = null; // obtain the cached image corresponding to the descriptor - if (element instanceof ProcessNode) { + if (element instanceof ResourceNode) { + descriptor = AbstractUIPlugin.imageDescriptorFromPlugin( + Activator.PLUGIN_ID, "icons/process.png"); + } else if (element instanceof ProcessNode) { descriptor = AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, "icons/process.png"); } else if (element instanceof PropertyNode) { @@ -47,9 +50,11 @@ public class CourseLabelProvider implements ILabelProvider { @Override public String getText(Object element) { String text = ""; - if (element instanceof CourseRootNode) + if (element instanceof CourseRootNode){ text = "root"; - else if (element instanceof ProcessNode) { + }else if (element instanceof ResourceNode) { + text = ((ResourceNode) element).getName(); + }else if (element instanceof ProcessNode) { text = ((ProcessNode) element).getName(); } else if (element instanceof PropertyNode) { text = ((PropertyNode) element).getName(); diff --git a/src/cn/edu/hit/education/listener/MyDragSourceListener.java b/src/cn/edu/hit/education/listener/CourseDragSourceListener.java similarity index 91% rename from src/cn/edu/hit/education/listener/MyDragSourceListener.java rename to src/cn/edu/hit/education/listener/CourseDragSourceListener.java index 54d86eb8d1b828e79d50981acce3ec8fa1def0e6..66beaa26395c3c9a47ff2f28eff5959b9467f43e 100644 --- a/src/cn/edu/hit/education/listener/MyDragSourceListener.java +++ b/src/cn/edu/hit/education/listener/CourseDragSourceListener.java @@ -10,7 +10,7 @@ import cn.edu.hit.education.model.CourseNode; import cn.edu.hit.education.model.Node; import educationschedule.Activator; -public class MyDragSourceListener extends DragSourceAdapter { +public class CourseDragSourceListener extends DragSourceAdapter { private TreeViewer treeViewer; /** @@ -20,7 +20,7 @@ public class MyDragSourceListener extends DragSourceAdapter { * - the drag source * */ - public MyDragSourceListener(TreeViewer treeViewer) { + public CourseDragSourceListener(TreeViewer treeViewer) { this.treeViewer = treeViewer; } diff --git a/src/cn/edu/hit/education/listener/MyDropTargetListener.java b/src/cn/edu/hit/education/listener/CourseDropTargetListener.java similarity index 83% rename from src/cn/edu/hit/education/listener/MyDropTargetListener.java rename to src/cn/edu/hit/education/listener/CourseDropTargetListener.java index a98762068b38488657f5fcad55076d3cec18bae4..5fccae5e4d5fc19287c46ed4705a1138f7a31d38 100644 --- a/src/cn/edu/hit/education/listener/MyDropTargetListener.java +++ b/src/cn/edu/hit/education/listener/CourseDropTargetListener.java @@ -6,7 +6,7 @@ import org.eclipse.swt.dnd.TransferData; import cn.edu.hit.education.view.CourseScheduleView; -public class MyDropTargetListener extends ViewerDropAdapter { +public class CourseDropTargetListener extends ViewerDropAdapter { private CourseScheduleView view; /** * @param parentComposite @@ -14,7 +14,7 @@ public class MyDropTargetListener extends ViewerDropAdapter { * @param target * - the drop target */ - public MyDropTargetListener(TableViewer tableViewer,CourseScheduleView view) { + public CourseDropTargetListener(TableViewer tableViewer,CourseScheduleView view) { super(tableViewer); this.view = view; } diff --git a/src/cn/edu/hit/education/model/CourseRootNode.java b/src/cn/edu/hit/education/model/CourseRootNode.java index 3516a7995dae93a66e2f8129388091bc093c627d..ab5462d81fc242734a3823bedc8f112e16fc549b 100644 --- a/src/cn/edu/hit/education/model/CourseRootNode.java +++ b/src/cn/edu/hit/education/model/CourseRootNode.java @@ -47,9 +47,10 @@ public class CourseRootNode extends Node { public static synchronized CourseRootNode getRootNode() { if (root == null) { root = new CourseRootNode(); - initSpecialties(); + //initSpecialties(); root.setParent(null); - root.initRootNode(getSpecialtiesIds()); + //root.initRootNode(getSpecialtiesIds()); + root.initRootNode(1); } return root; @@ -64,14 +65,12 @@ public class CourseRootNode extends Node { } else if (subject.hasRole("president")) { User user = (User) subject.getPrincipal(); // 根据院长的用户Id查询到关联的专业Id - List ids = userSpeciatyService.querySpeciatyIdsByUser(user - .getId()); + List ids = userSpeciatyService.querySpeciatyIdsByUser(user.getId()); specialties = specialtyService.queryRelativeSpecialty(ids); } else if (subject.hasRole("director")) { User user = (User) subject.getPrincipal(); // 根据普通用户的用户Id查询到关联的专业Id - List ids = userSpeciatyService.querySpeciatyIdsByUser(user - .getId()); + List ids = userSpeciatyService.querySpeciatyIdsByUser(user.getId()); specialties = specialtyService.queryRelativeSpecialty(ids); } @@ -87,24 +86,22 @@ public class CourseRootNode extends Node { } private void initRootNode(List specialtiesIds) { - List universities = universityService.queryAllUniversity(); + ResourceNode resourceNode = new ResourceNode(0,"教育资源"); + root.addChild(resourceNode); + List processes = processService.queryAllProcess(); if (processes != null && processes.size() > 0) { for (Process process : processes) { - ProcessNode processNode = new ProcessNode(process.getId(), - process.getName()); - root.addChild(processNode); + ProcessNode processNode = new ProcessNode(process.getId(),process.getName()); + resourceNode.addChild(processNode); - List properties = propertyService - .queryPropertiesByProcessId(process.getId()); + List properties = propertyService.queryPropertiesByProcessId(process.getId()); if (properties != null && properties.size() > 0) { for (Property property : properties) { - PropertyNode propertyNode = new PropertyNode( - property.getId(), property.getName()); + PropertyNode propertyNode = new PropertyNode(property.getId(), property.getName()); processNode.addChild(propertyNode); - List courses = courseService - .queryCoursesByPropertyId(property.getId()); + List courses = courseService.queryCoursesByPropertyId(property.getId()); courses = courses.stream().filter(item->{ return specialtiesIds.contains(item.getSpecialtyId()); @@ -112,8 +109,7 @@ public class CourseRootNode extends Node { if (courses != null && courses.size() > 0) { for (Course course : courses) { - CourseNode courseNode = new CourseNode( - course.getId(), course.getName()); + CourseNode courseNode = new CourseNode(course.getId(), course.getName()); propertyNode.addChild(courseNode); } } @@ -122,7 +118,36 @@ public class CourseRootNode extends Node { } } + } + + private void initRootNode(int specialtieId) { + ResourceNode resourceNode = new ResourceNode(0,"教育资源"); + root.addChild(resourceNode); + + List processes = processService.queryAllProcess(); + if (processes != null && processes.size() > 0) { + for (Process process : processes) { + ProcessNode processNode = new ProcessNode(process.getId(),process.getName()); + resourceNode.addChild(processNode); + + List properties = propertyService.queryPropertiesByProcessId(process.getId()); + if (properties != null && properties.size() > 0) { + for (Property property : properties) { + PropertyNode propertyNode = new PropertyNode(property.getId(), property.getName()); + processNode.addChild(propertyNode); - System.out.println(universities); + List courses = courseService.queryCoursesBySpecialtyPropertyId(specialtieId, property.getId()); + + if (courses != null && courses.size() > 0) { + for (Course course : courses) { + CourseNode courseNode = new CourseNode(course.getId(), course.getName()); + propertyNode.addChild(courseNode); + } + } + } + } + + } + } } } diff --git a/src/cn/edu/hit/education/model/ResourceNode.java b/src/cn/edu/hit/education/model/ResourceNode.java new file mode 100644 index 0000000000000000000000000000000000000000..ead013240cf5ed1c1a2d5f3b13fca00a3310fb5d --- /dev/null +++ b/src/cn/edu/hit/education/model/ResourceNode.java @@ -0,0 +1,10 @@ +package cn.edu.hit.education.model; + +public class ResourceNode extends Node { + + public ResourceNode(int id, String name) { + super(id, name); + // TODO Auto-generated constructor stub + } + +} diff --git a/src/cn/edu/hit/education/pojo/Course.java b/src/cn/edu/hit/education/pojo/Course.java index 9089329eb96cb914305b1d3f611b864e1173e21b..d9e038db4070350f16480db9e432444ed36e8bc8 100644 --- a/src/cn/edu/hit/education/pojo/Course.java +++ b/src/cn/edu/hit/education/pojo/Course.java @@ -554,4 +554,34 @@ public class Course implements Serializable { public void setNote(String note) { this.note = note == null ? null : note.trim(); } + + @Override + public boolean equals(Object courseFroEx) { + if(courseFroEx instanceof Course){ + Course course = (Course)courseFroEx; + if(course.getSpecialtyId() == this.getSpecialtyId() && + course.getPropertyId() == this.getPropertyId()&& + course.getName().equals(this.getName())&& + course.getCredits().equals(this.getCredits())&& + course.getImportant() == this.getImportant()&& + course.getNumber().equals(this.getNumber())&& + course.getPeriod().equals(this.getPeriod()) && + course.getTheoretical().equals(this.getTheoretical()) && + course.getUnit().equals(this.getUnit()) && + course.getSelected().equals(this.getSelected()) && + course.getMethod().equals(this.getMethod()) && + course.getClassroom().equals(this.getClassroom()) && + course.getStart() == this.getStart() && + course.getEnd() == this.getEnd() && + course.getNote().equals(this.getNote())){ + + return true; + } + } + + + return false; + + } + } \ No newline at end of file diff --git a/src/cn/edu/hit/education/service/CourseServiceImpl.java b/src/cn/edu/hit/education/service/CourseServiceImpl.java index 7dbba77d5e49b4e00cd4133c992dfb92533847a8..770fe4ecee9d1ba995dbd9d74190928a918f0550 100644 --- a/src/cn/edu/hit/education/service/CourseServiceImpl.java +++ b/src/cn/edu/hit/education/service/CourseServiceImpl.java @@ -181,4 +181,12 @@ public class CourseServiceImpl implements ICourseService { return courseMapper.selectByPrimaryKey(id); } + @Override + public List queryAllCourseBySpecityId(List ids) { + CourseExample example = new CourseExample(); + CourseExample.Criteria criteria = example.createCriteria(); + criteria.andSpecialtyIdIn(ids); + return courseMapper.selectByExample(example); + } + } diff --git a/src/cn/edu/hit/education/service/ICourseService.java b/src/cn/edu/hit/education/service/ICourseService.java index ffbfafb42db69188fef21263bda3576837f26fa1..07e936b6d3e5db082f2cb1e28409fd09dadac3b3 100644 --- a/src/cn/edu/hit/education/service/ICourseService.java +++ b/src/cn/edu/hit/education/service/ICourseService.java @@ -1,18 +1,18 @@ /** -*

title ICouserService.java

-*

package cn.edu.hit.education.service

-*

description TODO

-*

copyright ҵѧ(C) 2019

-*

company ҵѧAS&MT

-*

author ѩ jinxuesong@163.com

-*

date 2021421 3:00:15

-*

version v1.0

+*

title �� ICouserService.java

+*

package �� cn.edu.hit.education.service

+*

description ��TODO

+*

copyright �� ��������ҵ��ѧ(C) 2019

+*

company �� ��������ҵ��ѧAS&MT

+*

author �� ��ѩ�� jinxuesong@163.com

+*

date �� 2021��4��21�� ����3:00:15

+*

version �� v1.0

* * Modification History: * Date Author Version Discription * ----------------------------------------------------------------------------------- -* 2021421 ѩ 1.0 1.0 -* Why & What is modified: <޸ԭ> +* 2021��4��21�� ��ѩ�� 1.0 1.0 +* Why & What is modified: <�޸�ԭ������> */ package cn.edu.hit.education.service; @@ -22,10 +22,10 @@ import java.util.Set; import cn.edu.hit.education.pojo.Course; /** - *

classname ICouserService

- *

description TODO

- *

author ѩ jinxuesong@163.com

- *

date 2021421 3:00:15

+ *

classname �� ICouserService

+ *

description ��TODO

+ *

author �� ��ѩ�� jinxuesong@163.com

+ *

date �� 2021��4��21�� ����3:00:15

*/ public interface ICourseService { @@ -44,4 +44,7 @@ public interface ICourseService { List queryCoursesBySpecialtyPropertyId(int specialtyId, int propertyId); List queryCoursesByIds(Set ids); + + List queryAllCourseBySpecityId(List ids); + } diff --git a/src/cn/edu/hit/education/service/IProcessService.java b/src/cn/edu/hit/education/service/IProcessService.java index c3883aefbc66b99602af7ed6cb5ef5bd360871f9..6b5a11e02b66778040a3fc951c447373c25b711a 100644 --- a/src/cn/edu/hit/education/service/IProcessService.java +++ b/src/cn/edu/hit/education/service/IProcessService.java @@ -1,29 +1,24 @@ /** -*

title IProcessService.java

-*

package cn.edu.hit.education.service

-*

description TODO

-*

copyright ҵѧ(C) 2019

-*

company ҵѧAS&MT

-*

author ѩ jinxuesong@163.com

-*

date 2021421 4:22:02

-*

version v1.0

+*

title �� IProcessService.java

+*

package �� cn.edu.hit.education.service

+*

description ��TODO

+*

copyright �� ��������ҵ��ѧ(C) 2019

+*

company �� ��������ҵ��ѧAS&MT

+*

author �� ��ѩ�� jinxuesong@163.com

+*

date �� 2021��4��21�� ����4:22:02

+*

version �� v1.0

* * Modification History: * Date Author Version Discription * ----------------------------------------------------------------------------------- -* 2021421 ѩ 1.0 1.0 -* Why & What is modified: <޸ԭ> +* 2021��4��21�� ��ѩ�� 1.0 1.0 +* Why & What is modified: <�޸�ԭ������> */ package cn.edu.hit.education.service; import java.util.List; import cn.edu.hit.education.pojo.Process; -/** - *

classname IProcessService

- *

description TODO

- *

author ѩ jinxuesong@163.com

- *

date 2021421 4:22:02

- */ + public interface IProcessService { int insert(Process process); @@ -32,6 +27,8 @@ public interface IProcessService { int update(Process process); + Process queryProcessByPrimaryKey(int id); + List queryAllProcess(); List queryProcessesByProcessName(String name); diff --git a/src/cn/edu/hit/education/service/IPropertyService.java b/src/cn/edu/hit/education/service/IPropertyService.java index 9fc0696cc4ef4b400834c81d630a0dc1532f313d..2ec88015a6c1ee865dedb631beb99482baa13e7f 100644 --- a/src/cn/edu/hit/education/service/IPropertyService.java +++ b/src/cn/edu/hit/education/service/IPropertyService.java @@ -1,31 +1,10 @@ -/** -*

title IPropertyService.java

-*

package cn.edu.hit.education.service

-*

description TODO

-*

copyright ҵѧ(C) 2019

-*

company ҵѧAS&MT

-*

author ѩ jinxuesong@163.com

-*

date 2021421 4:22:14

-*

version v1.0

-* -* Modification History: -* Date Author Version Discription -* ----------------------------------------------------------------------------------- -* 2021421 ѩ 1.0 1.0 -* Why & What is modified: <޸ԭ> -*/ + package cn.edu.hit.education.service; import java.util.List; import cn.edu.hit.education.pojo.Property; -/** - *

classname IPropertyService

- *

description TODO

- *

author ѩ jinxuesong@163.com

- *

date 2021421 4:22:14

- */ public interface IPropertyService { int insert(Property property); @@ -34,6 +13,8 @@ public interface IPropertyService { int update(Property property); + Property queryPropertyByPrimaryKey(int id); + Property queryPropertyById(int id); List queryAllProperty(); @@ -41,4 +22,7 @@ public interface IPropertyService { List queryPropertiesByProcessId(int processId); void clearPropertyNum(); + + Property queryPropertyByName(String name); + } diff --git a/src/cn/edu/hit/education/service/ProcessServiceImpl.java b/src/cn/edu/hit/education/service/ProcessServiceImpl.java index 17868d6dd0683a573e06749b23e1034a64e24373..a0460082ce06219ebc07f8253167f31f31b56f6f 100644 --- a/src/cn/edu/hit/education/service/ProcessServiceImpl.java +++ b/src/cn/edu/hit/education/service/ProcessServiceImpl.java @@ -1,18 +1,18 @@ /** -*

title ProcessServiceImpl.java

-*

package cn.edu.hit.education.service

-*

description TODO

-*

copyright ҵѧ(C) 2019

-*

company ҵѧAS&MT

-*

author ѩ jinxuesong@163.com

-*

date 2021421 4:38:37

-*

version v1.0

+*

title �� ProcessServiceImpl.java

+*

package �� cn.edu.hit.education.service

+*

description ��TODO

+*

copyright �� ��������ҵ��ѧ(C) 2019

+*

company �� ��������ҵ��ѧAS&MT

+*

author �� ��ѩ�� jinxuesong@163.com

+*

date �� 2021��4��21�� ����4:38:37

+*

version �� v1.0

* * Modification History: * Date Author Version Discription * ----------------------------------------------------------------------------------- -* 2021421 ѩ 1.0 1.0 -* Why & What is modified: <޸ԭ> +* 2021��4��21�� ��ѩ�� 1.0 1.0 +* Why & What is modified: <�޸�ԭ������> */ package cn.edu.hit.education.service; @@ -25,12 +25,6 @@ import cn.edu.hit.education.dao.ProcessMapper; import cn.edu.hit.education.pojo.Process; import cn.edu.hit.education.pojo.ProcessExample; -/** - *

classname ProcessServiceImpl

- *

description TODO

- *

author ѩ jinxuesong@163.com

- *

date 2021421 4:38:37

- */ @Service public class ProcessServiceImpl implements IProcessService { @@ -39,25 +33,21 @@ public class ProcessServiceImpl implements IProcessService { @Override public int insert(Process process) { - // TODO Զɵķ return processMapper.insert(process); } @Override public int deleteByPrimaryKey(int id) { - // TODO Զɵķ return processMapper.deleteByPrimaryKey(id); } @Override public int update(Process process) { - // TODO Զɵķ return processMapper.updateByPrimaryKey(process); } @Override public List queryAllProcess() { - // TODO Զɵķ ProcessExample example = new ProcessExample(); ProcessExample.Criteria criteria = example.createCriteria(); criteria.andIdGreaterThan(0); @@ -67,7 +57,6 @@ public class ProcessServiceImpl implements IProcessService { @Override public List queryProcessesByProcessName(String name) { - // TODO Զɵķ ProcessExample example = new ProcessExample(); ProcessExample.Criteria criteria = example.createCriteria(); criteria.andNameEqualTo(name.trim()); @@ -75,4 +64,10 @@ public class ProcessServiceImpl implements IProcessService { return processMapper.selectByExample(example); } + @Override + public Process queryProcessByPrimaryKey(int id) { + // TODO 自动生成的方法存根 + return processMapper.selectByPrimaryKey(id); + } + } diff --git a/src/cn/edu/hit/education/service/PropertyServiceImpl.java b/src/cn/edu/hit/education/service/PropertyServiceImpl.java index 1b5ae0da98602b077601a6a8181bae5a1ea83a37..a0bbe5e9d2ea67efef8f0ab92c88ffe50d514d1f 100644 --- a/src/cn/edu/hit/education/service/PropertyServiceImpl.java +++ b/src/cn/edu/hit/education/service/PropertyServiceImpl.java @@ -1,19 +1,4 @@ -/** -*

title PropertyServiceImpl.java

-*

package cn.edu.hit.education.service

-*

description TODO

-*

copyright ҵѧ(C) 2019

-*

company ҵѧAS&MT

-*

author ѩ jinxuesong@163.com

-*

date 2021421 4:39:13

-*

version v1.0

-* -* Modification History: -* Date Author Version Discription -* ----------------------------------------------------------------------------------- -* 2021421 ѩ 1.0 1.0 -* Why & What is modified: <޸ԭ> -*/ + package cn.edu.hit.education.service; import java.util.List; @@ -24,13 +9,8 @@ import org.springframework.stereotype.Service; import cn.edu.hit.education.dao.PropertyMapper; import cn.edu.hit.education.pojo.Property; import cn.edu.hit.education.pojo.PropertyExample; +import cn.edu.hit.education.pojo.PropertyExample.Criteria; -/** - *

classname PropertyServiceImpl

- *

description TODO

- *

author ѩ jinxuesong@163.com

- *

date 2021421 4:39:13

- */ @Service public class PropertyServiceImpl implements IPropertyService { @@ -39,25 +19,21 @@ public class PropertyServiceImpl implements IPropertyService { @Override public int insert(Property property) { - // TODO Զɵķ return propertyMapper.insert(property); } @Override public int deleteByPrimaryKey(int id) { - // TODO Զɵķ return propertyMapper.deleteByPrimaryKey(id); } @Override public int update(Property property) { - // TODO Զɵķ return propertyMapper.updateByPrimaryKey(property); } @Override public List queryAllProperty() { - // TODO Զɵķ PropertyExample example = new PropertyExample(); PropertyExample.Criteria criteria = example.createCriteria(); criteria.andIdGreaterThan(0); @@ -67,7 +43,6 @@ public class PropertyServiceImpl implements IPropertyService { @Override public List queryPropertiesByProcessId(int processId) { - // TODO Զɵķ PropertyExample example = new PropertyExample(); PropertyExample.Criteria criteria = example.createCriteria(); criteria.andProcessIdEqualTo(processId); @@ -77,7 +52,6 @@ public class PropertyServiceImpl implements IPropertyService { @Override public void clearPropertyNum() { - // TODO Զɵķ List properties = queryAllProperty(); if(properties != null && properties.size() > 0){ for (Property property : properties) { @@ -90,8 +64,19 @@ public class PropertyServiceImpl implements IPropertyService { @Override public Property queryPropertyById(int id) { - // TODO Զɵķ return propertyMapper.selectByPrimaryKey(id); } + @Override + public Property queryPropertyByPrimaryKey(int id) { + // TODO 自动生成的方法存根 + return propertyMapper.selectByPrimaryKey(id); + } + + @Override + public Property queryPropertyByName(String name) { + + return propertyMapper.queryPropertyByName(name); + } + } diff --git a/src/cn/edu/hit/education/utils/ExcelUtil.java b/src/cn/edu/hit/education/utils/ExcelUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..c0a50cfb2b2e5062fe546d4a1bd3d5171ac1d437 --- /dev/null +++ b/src/cn/edu/hit/education/utils/ExcelUtil.java @@ -0,0 +1,312 @@ +package cn.edu.hit.education.utils; + + + +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.poi.hssf.usermodel.*; +import org.apache.poi.ss.usermodel.BorderStyle; +import org.apache.poi.ss.usermodel.CellType; +import org.apache.poi.ss.usermodel.HorizontalAlignment; +import org.apache.poi.ss.usermodel.VerticalAlignment; +import org.apache.poi.xssf.usermodel.*; + +import java.io.*; +import java.text.MessageFormat; +import java.text.SimpleDateFormat; +import java.util.*; + +/** + * @program: Demo + * @Date: 2019/2/19 10:50 + * @Author: LiJc + * @Description: + */ +public class ExcelUtil { + + public boolean writeExcel(List> list, String path) throws Exception { + String postfix = path.substring(path.lastIndexOf(".") + 1, path.length()); + if (postfix.equals("xls")) { + writeXls(list, path); + } else if (postfix.equals("xlsx")) { + writeXlsx(list, path); + }else { + System.out.println("文件后缀名不正确!"); + return false; + } + return true; + } + + /** + * read the Excel file + * + * @param path + * the path of the Excel file + * @return + * @throws IOException + */ + public List> readExcel(String path) throws IOException { + String postfix = path.substring(path.lastIndexOf(".") + 1, path.length()); + if (postfix.equals("xls")) { + return readXls(path); + } else if (postfix.equals("xlsx")) { + return readXlsx(path); + } + return null; + } + + /** + * Read the Excel 2010 + * + * @param path + * the path of the excel file + * @return + * @throws IOException + */ + public List> readXlsx(String path) throws IOException { + + InputStream is = new FileInputStream(path); + XSSFWorkbook xssfWorkbook = new XSSFWorkbook(is); + List> list = new ArrayList>(); + // Read the Sheet + for (int numSheet = 0; numSheet < xssfWorkbook.getNumberOfSheets(); numSheet++) { + XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(numSheet); + if (xssfSheet == null) { + continue; + } + // Read the Row + for (int rowNum = 1; rowNum <= xssfSheet.getLastRowNum(); rowNum++) { + XSSFRow xssfRow = xssfSheet.getRow(rowNum); + if (xssfRow != null) { + Map map = new HashMap<>(); + for (int cellNum = 0; cellNum <= xssfRow.getLastCellNum(); cellNum++) { + if(xssfSheet.getRow(0).getCell(cellNum)==null||xssfRow.getCell(cellNum)==null) + continue; + map.put(xssfSheet.getRow(0).getCell(cellNum) + "", getValue(xssfRow.getCell(cellNum))); + } + list.add(map); + } + } + } + xssfWorkbook.close(); + is.close(); + return list; + } + + /** + * Read the Excel 2003-2007 + * + * @param path + * the path of the Excel + * @return + * @throws IOException + */ + public List> readXls(String path) throws IOException { + InputStream is = new FileInputStream(path); + HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is); + List> list = new ArrayList>(); + // Read the Sheet + for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) { + HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet); + if (hssfSheet == null) { + continue; + } + // Read the Row + for (int rowNum = 1; rowNum <= hssfSheet.getLastRowNum(); rowNum++) { + HSSFRow hssfRow = hssfSheet.getRow(rowNum); + if (hssfRow != null) { + Map map = new HashMap<>(); + for (int cellNum = 0; cellNum <= hssfRow.getLastCellNum(); cellNum++) { + if(hssfSheet.getRow(0).getCell(cellNum)==null) + continue; + map.put(hssfSheet.getRow(0).getCell(cellNum) + "", getValue(hssfRow.getCell(cellNum))); + } + list.add(map); + } + } + } + hssfWorkbook.close(); + is.close(); + return list; + } + + + @SuppressWarnings({ "static-access", "deprecation" }) + private String getValue(XSSFCell xssfRow) { + if (xssfRow == null) { + return ""; + } else if (xssfRow.getCellType() == CellType.BOOLEAN) { + return String.valueOf(xssfRow.getBooleanCellValue()).trim(); + } else if (xssfRow.getCellType() == CellType.NUMERIC) { + HSSFDataFormatter dataFormatter = new HSSFDataFormatter(); + return String.valueOf(dataFormatter.formatCellValue(xssfRow)).trim(); + // return String.valueOf(xssfRow.getNumericCellValue()).trim(); + } else { + return String.valueOf(xssfRow.getStringCellValue()).trim(); + } + } + + @SuppressWarnings({ "static-access", "deprecation" }) + private String getValue(HSSFCell hssfCell) { + if (hssfCell == null) { + return ""; + } else if (hssfCell.getCellType() == CellType.BOOLEAN) { + return String.valueOf(hssfCell.getBooleanCellValue()).trim(); + } else if (hssfCell.getCellType() == CellType.NUMERIC) { + HSSFDataFormatter dataFormatter = new HSSFDataFormatter(); + return String.valueOf(dataFormatter.formatCellValue(hssfCell)).trim(); + // return String.valueOf(hssfCell.getNumericCellValue()).trim(); + } else { + return String.valueOf(hssfCell.getStringCellValue()).trim(); + } + } + + public void writeXls(List> list, String path) throws Exception { + if (list == null) { + return; + } + int countColumnNum = list.size(); + HSSFWorkbook book = new HSSFWorkbook(); + // 设置样式start + HSSFCellStyle cellStyle = setStyleXls(book); + // 设置样式end + HSSFSheet sheet = book.createSheet("sheet"); + // option at first row. + HSSFRow firstRow = sheet.createRow(0); + + // Set-->数组 + String[] options = new String[list.get(0).keySet().size()]; + list.get(0).keySet().toArray(options); + + for (int j = 0; j < options.length; j++) { + HSSFCell cell = firstRow.createCell(j); + cell.setCellStyle(cellStyle); + cell.setCellValue(new HSSFRichTextString(options[j])); + } + + for (int i = 0; i < countColumnNum; i++) { + HSSFRow row = sheet.createRow(i + 1); + Map map = list.get(i); + for (int column = 0; column < options.length; column++) { + HSSFCell cell = row.createCell(column); + cell.setCellStyle(cellStyle); + cell.setCellValue((map.get(options[column])==null?"":map.get(options[column])) + ""); + } + } + File file = new File(path); + FileUtils.forceMkdir(file.getParentFile()); + OutputStream os = new FileOutputStream(file); + book.write(os); + os.close(); + } + + public void writeXlsx(List> list, String path) throws Exception { + if (list == null) { + return; + } + // XSSFWorkbook + int countColumnNum = list.size(); + XSSFWorkbook book = new XSSFWorkbook(); + XSSFCellStyle cellStyle = setStyleXlsx(book); + XSSFSheet sheet = book.createSheet("studentSheet"); + + // option at first row. + XSSFRow firstRow = sheet.createRow(0); + // Set-->数组 + String[] options = new String[list.get(0).keySet().size()]; + list.get(0).keySet().toArray(options); + for (int j = 0; j < options.length; j++) { + XSSFCell cell = firstRow.createCell(j); + cell.setCellStyle(cellStyle); + cell.setCellValue(new XSSFRichTextString(options[j])); + } + for (int i = 0; i < countColumnNum; i++) { + XSSFRow row = sheet.createRow(i + 1); + Map map = list.get(i); + for (int column = 0; column < options.length; column++) { + XSSFCell cell = row.createCell(column); + cell.setCellStyle(cellStyle); + cell.setCellValue((map.get(options[column])==null?"":map.get(options[column])) + ""); + } + } + File file = new File(path); + FileUtils.forceMkdir(file.getParentFile()); + OutputStream os = new FileOutputStream(file); + book.write(os); + os.close(); + } + + /** + * 设置样式 + * @param book + * @return + */ + public HSSFCellStyle setStyleXls(HSSFWorkbook book){ + HSSFCellStyle cellStyle = book.createCellStyle(); + cellStyle.setAlignment(HorizontalAlignment.CENTER);// 居中 + cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直 + cellStyle.setBorderBottom(BorderStyle.THIN);//下边框 + cellStyle.setBorderLeft(BorderStyle.THIN);//左边框 + cellStyle.setBorderTop(BorderStyle.THIN);//上边框 + cellStyle.setBorderRight(BorderStyle.THIN);//右边框 + return cellStyle; + } + + /** + * 设置样式 + * @param book + * @return + */ + public XSSFCellStyle setStyleXlsx(XSSFWorkbook book){ + XSSFCellStyle cellStyle = book.createCellStyle(); + cellStyle.setAlignment(HorizontalAlignment.CENTER);// 居中 + cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直 + cellStyle.setBorderBottom(BorderStyle.THIN);//下边框 + cellStyle.setBorderLeft(BorderStyle.THIN);//左边框 + cellStyle.setBorderTop(BorderStyle.THIN);//上边框 + cellStyle.setBorderRight(BorderStyle.THIN);//右边框 + return cellStyle; + } + + /** + * 返回文件绝对路径 + * + * @param subPath + * @param fileName + * @return + */ + public String getSavePath(String subPath, String fileName) { + + // 处理子路径 + if (!StringUtils.isBlank(subPath)) { + subPath += "/"; + } else { + subPath = ""; + } + + // 处理日期路径 + Date date = new Date(); + SimpleDateFormat yyyyFt = new SimpleDateFormat("yyyy"); + SimpleDateFormat MMFt = new SimpleDateFormat("MM"); + SimpleDateFormat ddFt = new SimpleDateFormat("dd"); + SimpleDateFormat HHFt = new SimpleDateFormat("HH"); + String datePath = MessageFormat.format("{0}/{1}/{2}/{3}/", yyyyFt.format(date), MMFt.format(date), ddFt.format(date), + HHFt.format(date)); + + return "/" + subPath + datePath + getNewFileName(fileName); + } + + /** + * 构建新文件名称 + * + * @param fileName + * @return + */ + public String getNewFileName(String fileName) { + String[] names = fileName.split("[\\.]"); + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmSS"); + String dateString = sdf.format(new Date()); + return names[0] + "-" + dateString + "." + names[1]; + } +} + diff --git a/src/cn/edu/hit/education/view/CourseExploreView.java b/src/cn/edu/hit/education/view/CourseExploreView.java index 8fdbc507b05e8015fc2c494881d537ba04eb4133..d4a6baac9619bea129f0ae176a0717343540c78e 100644 --- a/src/cn/edu/hit/education/view/CourseExploreView.java +++ b/src/cn/edu/hit/education/view/CourseExploreView.java @@ -21,72 +21,56 @@ import org.eclipse.ui.part.ViewPart; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import cn.edu.hit.education.action.AddCollegeAction; -import cn.edu.hit.education.action.AddSpecialtyAction; -import cn.edu.hit.education.action.AddUniversityAction; +import cn.edu.hit.education.action.AddCourseAction; +import cn.edu.hit.education.action.AddProcessAction; +import cn.edu.hit.education.action.AddPropertyAction; +import cn.edu.hit.education.action.UpdateCourseAction; +import cn.edu.hit.education.action.UpdateProcessAction; +import cn.edu.hit.education.action.UpdatePropertyAction; import cn.edu.hit.education.contentprovider.CourseContentProvider; import cn.edu.hit.education.labelprovider.CourseLabelProvider; -import cn.edu.hit.education.listener.MyDragSourceListener; -import cn.edu.hit.education.model.CollegeNode; +import cn.edu.hit.education.listener.CourseDragSourceListener; import cn.edu.hit.education.model.CourseNode; import cn.edu.hit.education.model.CourseRootNode; import cn.edu.hit.education.model.Node; -import cn.edu.hit.education.model.OrganizationNode; -import cn.edu.hit.education.model.UniversityNode; -import cn.edu.hit.education.pojo.Semester; -import cn.edu.hit.education.pojo.Specialty; +import cn.edu.hit.education.model.ProcessNode; +import cn.edu.hit.education.model.PropertyNode; +import cn.edu.hit.education.model.ResourceNode; +import cn.edu.hit.education.pojo.Course; +import cn.edu.hit.education.pojo.Process; +import cn.edu.hit.education.pojo.Property; import cn.edu.hit.education.service.ICourseService; +import cn.edu.hit.education.service.IProcessService; import cn.edu.hit.education.service.IScheduleService; import cn.edu.hit.education.service.ISemesterService; -import cn.edu.hit.education.service.ISpecialtyService; -import cn.edu.hit.education.service.IUniversityService; -/** -*@Title: CourseExploreView -*@Description:课程View -*@author:李朝辉 -*@data:2021年4月29日午夜11:54 -* -* -*/ - @Component public class CourseExploreView extends ViewPart { @Autowired - IUniversityService universityService; + IProcessService processService; @Autowired ICourseService courseService; @Autowired IScheduleService scheduleService; @Autowired ISemesterService semesterService; - @Autowired - ISpecialtyService specialtyService; - - public static final String ID = "cn.edu.hit.education.view.CourseExploreView"; final Transfer[] transfer=new Transfer[]{LocalSelectionTransfer.getTransfer()}; final Transfer[] transfer2=new Transfer[] {TextTransfer.getInstance()}; private TreeViewer treeViewer; private Tree tree; - private Semester semester; - private Specialty specialty; - private CourseNode courseNode ; - - - - + private Node currentNode; + public CourseExploreView() { - } public void createPartControl(Composite parent) { treeViewer = new TreeViewer(parent, SWT.BORDER); tree = treeViewer.getTree(); - treeViewer.addDragSupport(DND.DROP_MOVE, transfer2, new MyDragSourceListener(treeViewer)); + treeViewer.addDragSupport(DND.DROP_MOVE, transfer2, new CourseDragSourceListener(treeViewer)); treeViewer.setContentProvider(new CourseContentProvider()); treeViewer.setLabelProvider(new CourseLabelProvider()); @@ -98,8 +82,7 @@ public class CourseExploreView extends ViewPart { TreeItem selections = (TreeItem)e.item; Node node = (Node)selections.getData(); if(node instanceof CourseNode){ - courseNode = (CourseNode)node; - System.out.println("所选课程ID: "+courseNode.getId()); + currentNode = (CourseNode)node; } } }); @@ -135,15 +118,86 @@ public class CourseExploreView extends ViewPart { } });*/ - //createContextMenu(parent); - - + makeContextMenu(); } + private void makeContextMenu() { + MenuManager menuMgr = new MenuManager(); + + Menu menu = menuMgr.createContextMenu(treeViewer.getControl()); + menuMgr.addMenuListener(new IMenuListener() { + @Override + public void menuAboutToShow(IMenuManager manager) { + if (treeViewer.getSelection().isEmpty()) { + return; + } + + if (treeViewer.getSelection() instanceof IStructuredSelection) { + IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection(); + currentNode = (Node)selection.getFirstElement(); + + if(currentNode instanceof ResourceNode){ + menuMgr.add(new AddProcessAction(CourseExploreView.this)); + }else if(currentNode instanceof ProcessNode){ + menuMgr.add(new AddPropertyAction(CourseExploreView.this,currentNode.getId())); + menuMgr.add(new UpdateProcessAction(CourseExploreView.this,currentNode.getId())); + }else if(currentNode instanceof PropertyNode){ + menuMgr.add(new AddCourseAction(CourseExploreView.this,currentNode.getId())); + menuMgr.add(new UpdatePropertyAction(CourseExploreView.this,currentNode.getId())); + }else{ + menuMgr.add(new UpdateCourseAction(CourseExploreView.this,currentNode.getId())); + } + } + } + }); + menuMgr.setRemoveAllWhenShown(true); + treeViewer.getControl().setMenu(menu); + + } + /** * Passing the focus request to the viewer's control. */ public void setFocus() { treeViewer.getControl().setFocus(); } + + public void refreshNewData(Object obj){ + if(obj instanceof Process){ + Process process = (Process)obj; + ProcessNode processNode = new ProcessNode(process.getId(),process.getName()); + currentNode.addChild(processNode); + }else if(obj instanceof Property){ + Property property = (Property)obj; + PropertyNode propertyNode = new PropertyNode(property.getId(),property.getName()); + currentNode.addChild(propertyNode); + }else if(obj instanceof Course){ + Course course = (Course)obj; + CourseNode courseNode = new CourseNode(course.getId(),course.getName()); + currentNode.addChild(courseNode); + }else{ + + } + + treeViewer.refresh(currentNode,true); + treeViewer.setExpandedState(currentNode, true); + } + + public void refreshUpdateData(Object obj){ + if(obj instanceof Process){ + Process process = (Process)obj; + currentNode.setName(process.getName()); + }else if(obj instanceof Property){ + Property property = (Property)obj; + currentNode.setName(property.getName()); + }else if(obj instanceof Course){ + Course course = (Course)obj; + currentNode.setName(course.getName()); + }else{ + + } + + treeViewer.refresh(currentNode,true); + treeViewer.setExpandedState(currentNode, true); + } } diff --git a/src/cn/edu/hit/education/view/CourseScheduleView.java b/src/cn/edu/hit/education/view/CourseScheduleView.java index 96e563c6e7b34e5f83bcdfd25af2003a21ac892f..0d6e14b7ff025b31282e44bba42b6672e65c8e46 100644 --- a/src/cn/edu/hit/education/view/CourseScheduleView.java +++ b/src/cn/edu/hit/education/view/CourseScheduleView.java @@ -42,7 +42,7 @@ import org.springframework.stereotype.Component; import cn.edu.hit.education.contentprovider.CourseScheduleContentProvider; import cn.edu.hit.education.labelprovider.CourseScheduleLabelProvider; -import cn.edu.hit.education.listener.MyDropTargetListener; +import cn.edu.hit.education.listener.CourseDropTargetListener; import cn.edu.hit.education.pojo.Course; import cn.edu.hit.education.pojo.ExCourse; import cn.edu.hit.education.pojo.Schedule; @@ -148,7 +148,7 @@ public class CourseScheduleView extends ViewPart implements ISelectionProvider{ tblclmnNewColumn.setWidth(100); tblclmnNewColumn.setText("\u5B9E\u9A8C\u5B66\u65F6"); tableViewer.addDropSupport(DND.DROP_MOVE, transfer2, - new MyDropTargetListener(tableViewer, this)); + new CourseDropTargetListener(tableViewer, this)); Menu contextMenu = new Menu(table); table.setMenu(contextMenu); diff --git a/src/educationschedule/Perspective.java b/src/educationschedule/Perspective.java index db5635d0aefba69130eb3eac401352c18664304a..4f8dfb4854566c66cb438d0928901e7529173227 100644 --- a/src/educationschedule/Perspective.java +++ b/src/educationschedule/Perspective.java @@ -24,7 +24,7 @@ public class Perspective implements IPerspectiveFactory { IFolderLayout mainArea = layout.createFolder("mainArea", IPageLayout.LEFT, 0.8f, editorArea); mainArea.addView(CourseScheduleView.ID); mainArea.addView(CourseInformationView.ID); - mainArea.addView(MovingBoxView.ID); + //mainArea.addView(MovingBoxView.ID); } }