diff --git a/.classpath b/.classpath index 39cd5e70c89d4a58fdb0ea46a9ee8c487030c05f..0e71af278c999d75ad2ab5e2f62f1bd989776cd0 100644 --- a/.classpath +++ b/.classpath @@ -3,56 +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/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/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/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/IPropertyService.java b/src/cn/edu/hit/education/service/IPropertyService.java index 9fc0696cc4ef4b400834c81d630a0dc1532f313d..11706d0a72cd2692139cc1ab9378bf903c2cc5ad 100644 --- a/src/cn/edu/hit/education/service/IPropertyService.java +++ b/src/cn/edu/hit/education/service/IPropertyService.java @@ -1,18 +1,18 @@ /** -*

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

+*

title �� IPropertyService.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:14

+*

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; @@ -21,10 +21,10 @@ import java.util.List; import cn.edu.hit.education.pojo.Property; /** - *

classname IPropertyService

- *

description TODO

- *

author ѩ jinxuesong@163.com

- *

date 2021421 4:22:14

+ *

classname �� IPropertyService

+ *

description ��TODO

+ *

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

+ *

date �� 2021��4��21�� ����4:22:14

*/ public interface IPropertyService { @@ -41,4 +41,7 @@ public interface IPropertyService { List queryPropertiesByProcessId(int processId); void clearPropertyNum(); + + Property queryPropertyByName(String name); + } diff --git a/src/cn/edu/hit/education/service/PropertyServiceImpl.java b/src/cn/edu/hit/education/service/PropertyServiceImpl.java index 1b5ae0da98602b077601a6a8181bae5a1ea83a37..f1bf24324f055d9e38e47d0756fc2ad80972e6d7 100644 --- a/src/cn/edu/hit/education/service/PropertyServiceImpl.java +++ b/src/cn/edu/hit/education/service/PropertyServiceImpl.java @@ -1,18 +1,18 @@ /** -*

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

+*

title �� PropertyServiceImpl.java

+*

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

+*

description ��TODO

+*

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

+*

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

+*

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

+*

date �� 2021��4��21�� ����4:39:13

+*

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; @@ -24,12 +24,13 @@ 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

+ *

classname �� PropertyServiceImpl

+ *

description ��TODO

+ *

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

+ *

date �� 2021��4��21�� ����4:39:13

*/ @Service public class PropertyServiceImpl implements IPropertyService { @@ -39,25 +40,25 @@ public class PropertyServiceImpl implements IPropertyService { @Override public int insert(Property property) { - // TODO Զɵķ + // TODO �Զ����ɵķ������ return propertyMapper.insert(property); } @Override public int deleteByPrimaryKey(int id) { - // TODO Զɵķ + // TODO �Զ����ɵķ������ return propertyMapper.deleteByPrimaryKey(id); } @Override public int update(Property property) { - // TODO Զɵķ + // TODO �Զ����ɵķ������ return propertyMapper.updateByPrimaryKey(property); } @Override public List queryAllProperty() { - // TODO Զɵķ + // TODO �Զ����ɵķ������ PropertyExample example = new PropertyExample(); PropertyExample.Criteria criteria = example.createCriteria(); criteria.andIdGreaterThan(0); @@ -67,7 +68,7 @@ public class PropertyServiceImpl implements IPropertyService { @Override public List queryPropertiesByProcessId(int processId) { - // TODO Զɵķ + // TODO �Զ����ɵķ������ PropertyExample example = new PropertyExample(); PropertyExample.Criteria criteria = example.createCriteria(); criteria.andProcessIdEqualTo(processId); @@ -77,7 +78,7 @@ public class PropertyServiceImpl implements IPropertyService { @Override public void clearPropertyNum() { - // TODO Զɵķ + // TODO �Զ����ɵķ������ List properties = queryAllProperty(); if(properties != null && properties.size() > 0){ for (Property property : properties) { @@ -90,8 +91,14 @@ public class PropertyServiceImpl implements IPropertyService { @Override public Property queryPropertyById(int id) { - // TODO Զɵķ + // 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]; + } +} +